Compare commits

..

16 Commits

Author SHA1 Message Date
Max Kless c6bf6414ce feat(graph): write nx-console e2e tests for the new tooltip functionality 2023-08-09 16:45:58 +02:00
Max Kless 395c3562d0 cleanup(graph): remove unused var 2023-08-09 10:26:15 +02:00
Max Kless 5a2ea09d9b cleanup(graph): improve graph e2e test 2023-08-09 10:02:41 +02:00
Max Kless 9c5873c9fa fix(graph): adjust implementation to upstream changes 2023-08-09 09:50:19 +02:00
Max Kless 47d4eb8eb8 feat(graph): add e2e test to test expanded task inputs 2023-08-09 09:29:23 +02:00
Max Kless ad9344152f feat(graph): add task tooltip e2e test 2023-08-09 09:29:23 +02:00
Max Kless 491966b6e3 feat(graph): expand task inputs and display them in the UI 2023-08-09 09:29:20 +02:00
Jonathan Cammisuli cda123802f fix(core): update test to use ProjectGraphBuilder + createTaskGraph 2023-08-08 20:59:17 -04:00
Jonathan Cammisuli 9690aea0a8 fix(core): change the way we gather inputs for the graph view 2023-08-08 14:55:09 -04:00
FrozenPandaz 6a1164f7ae chore(core): update unit tests 2023-08-08 14:50:13 -04:00
Jonathan Cammisuli 0ce7acdf77 fix(core): change the way we gather inputs for the graph view 2023-08-08 14:16:59 -04:00
Jonathan Cammisuli 137ba06499 fix(core): revert changes to run-command 2023-08-08 11:27:07 -04:00
Jonathan Cammisuli 5df932b108 fix(core): review changes 2023-08-07 14:11:40 -04:00
Jonathan Cammisuli 62e75edd24 fix(core): update unit test 2023-08-07 14:11:40 -04:00
Jonathan Cammisuli 2145117b24 feat(core): add task inputs to task graph for graph view 2023-08-07 14:11:40 -04:00
Jonathan Cammisuli a42cabccf9 feat(core): gather task inputs 2023-08-07 14:11:39 -04:00
11986 changed files with 401884 additions and 1114263 deletions
+1 -4
View File
@@ -1,8 +1,5 @@
[env]
JEMALLOC_SYS_WITH_MALLOC_CONF = "dirty_decay_ms:1000,muzzy_decay_ms:0"
[build]
target-dir = 'dist/target'
target-dir = 'build/target'
[target.x86_64-unknown-linux-musl]
rustflags = [
+223 -3
View File
@@ -1,5 +1,13 @@
version: 2.1
# -------------------------
# ORBS
# -------------------------
orbs:
nx: nrwl/nx@1.6.1
rust: circleci/rust@1.6.0
browser-tools: circleci/browser-tools@1.4.0
# -------------------------
# EXECUTORS
# -------------------------
@@ -11,20 +19,214 @@ executors:
linux:
<<: *defaults
docker:
- image: cimg/rust:1.84.0-browsers
resource_class: small
- image: cimg/rust:1.70.0-browsers
resource_class: medium+
macos:
<<: *defaults
resource_class: macos.x86.medium.gen2
macos:
xcode: '14.2.0'
# -------------------------
# COMMANDS
# -------------------------
commands:
run-pnpm-install:
parameters:
os:
type: string
steps:
- restore_cache:
name: Restore pnpm Package Cache
keys:
- node-deps-{{ arch }}-v3-{{ checksum "pnpm-lock.yaml" }}
- when:
condition:
equal: [<< parameters.os >>, linux]
steps:
- run:
name: Install pnpm package manager (linux)
command: |
npm install --prefix=$HOME/.local -g @pnpm/exe@8.3.1
- when:
condition:
equal: [<< parameters.os >>, macos]
steps:
- run:
name: Install pnpm package manager (macos)
command: |
npm install -g @pnpm/exe@8.3.1
- run:
name: Install Dependencies
command: |
pnpm install --frozen-lockfile
- save_cache:
name: Save pnpm Package Cache
key: node-deps-{{ arch }}-v3-{{ checksum "pnpm-lock.yaml" }}
paths:
- ~/.pnpm-store
- ~/.cache/Cypress
- node_modules
setup:
parameters:
os:
type: string
steps:
- checkout
- when:
condition:
equal: [<< parameters.os >>, macos]
steps:
- restore_cache:
name: Restore Homebrew packages
keys:
- nrwl-nx-homebrew-packages
- run:
name: Configure Detox Environment, Install applesimutils
command: |
HOMEBREW_NO_AUTO_UPDATE=1 brew tap wix/brew >/dev/null
HOMEBREW_NO_AUTO_UPDATE=1 brew install applesimutils >/dev/null
xcrun simctl shutdown all && xcrun simctl erase all
no_output_timeout: 20m
- save_cache:
name: Save Homebrew Cache
key: nrwl-nx-homebrew-packages
paths:
- /usr/local/Homebrew
- ~/Library/Caches/Homebrew
- when:
condition:
equal: [<< parameters.os >>, linux]
steps:
- run:
command: |
sudo apt-get update
sudo apt-get install -y ca-certificates lsof
- browser-tools/install-chrome
- browser-tools/install-chromedriver
- run-pnpm-install:
os: << parameters.os >>
# -------------------------
# JOBS
# -------------------------
jobs:
# -------------------------
# JOBS: Agent
# -------------------------
agent:
parameters:
os:
type: string
default: 'linux'
pm:
type: string
default: 'pnpm'
executor: << parameters.os >>
environment:
GIT_AUTHOR_EMAIL: test@test.com
GIT_AUTHOR_NAME: Test
GIT_COMMITTER_EMAIL: test@test.com
GIT_COMMITTER_NAME: Test
NX_E2E_CI_CACHE_KEY: e2e-circleci-<< parameters.os >>
SELECTED_PM: << parameters.pm >>
NX_E2E_RUN_E2E: 'true'
NX_VERBOSE_LOGGING: 'false'
NX_NATIVE_LOGGING: 'false'
NX_PERF_LOGGING: 'false'
steps:
- run:
name: Configure git metadata (needed for lerna smoke tests)
command: |
git config --global user.email test@test.com
git config --global user.name "Test Test"
- run:
name: Set dynamic nx run variable
command: |
echo "export NX_CI_EXECUTION_ENV=\"<< parameters.os >>\";" >> $BASH_ENV
- setup:
os: << parameters.os >>
- run:
name: Agent
command: pnpm nx-cloud start-agent
no_output_timeout: 60m
# -------------------------
# JOBS: Main Linux
# -------------------------
main-linux:
executor: linux
environment:
NX_E2E_CI_CACHE_KEY: e2e-circleci-linux
NX_VERBOSE_LOGGING: 'false'
NX_DAEMON: 'true'
NX_PERF_LOGGING: 'false'
NX_NATIVE_LOGGING: 'false'
steps:
- run: echo "We are in the process of transitioning from Circle CI to GitHub Actions. For details about your build results, consult github actions build logs."
- run:
name: Set dynamic nx run variable
command: |
echo "export NX_CI_EXECUTION_ENV=\"linux\";" >> $BASH_ENV
- setup:
os: linux
- nx/set-shas:
main-branch-name: 'master'
- run: pnpm nx-cloud start-ci-run --stop-agents-after="e2e"
- run:
name: Check Documentation
command: pnpm nx documentation --no-dte
no_output_timeout: 20m
- run:
name: Run Checks/Lint/Test/Build
no_output_timeout: 60m
command: |
pids=()
pnpm nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD &
pids+=($!)
pnpm nx run-many -t check-imports check-commit check-lock-files check-codeowners documentation --parallel=1 --no-dte &
pids+=($!)
pnpm nx affected --target=lint --base=$NX_BASE --head=$NX_HEAD --parallel=3 &
pids+=($!)
pnpm nx affected --target=test --base=$NX_BASE --head=$NX_HEAD --parallel=1 &
pids+=($!)
(pnpm nx affected --target=build --base=$NX_BASE --head=$NX_HEAD --parallel=3 &&
pnpm nx affected --target=e2e --base=$NX_BASE --head=$NX_HEAD --parallel=1) &
pids+=($!)
for pid in "${pids[@]}"; do
wait "$pid"
done
# -------------------------
# JOBS: Main-MacOS
# -------------------------
mainmacos:
executor: macos
environment:
NX_E2E_CI_CACHE_KEY: e2e-circleci-macos
NX_DAEMON: 'false' # TODO: set to true after #18410
NX_PERF_LOGGING: 'false'
SELECTED_PM: 'npm' # explicitly define npm for macOS tests
NX_SKIP_NX_CACHE: 'true' # TODO: Remove after #18410
steps:
- run:
name: Set dynamic nx run variable
command: |
echo "export NX_CI_EXECUTION_ENV=\"macos\";" >> $BASH_ENV
- setup:
os: macos
- rust/install
- nx/set-shas:
main-branch-name: 'master'
- run:
name: Run E2E Tests for macOS
command: |
pnpm nx affected -t e2e-macos --parallel=1 --base=$NX_BASE --head=$NX_HEAD
no_output_timeout: 45m
# -------------------------
# WORKFLOWS(JOBS)
@@ -34,4 +236,22 @@ workflows:
build:
jobs:
- agent:
name: 'agent1'
- agent:
name: 'agent2'
- agent:
name: 'agent3'
- agent:
name: 'agent4'
- agent:
name: 'agent5'
- agent:
name: 'agent6'
- agent:
name: 'agent7'
- agent:
name: 'agent8'
- main-linux
- mainmacos:
name: main-macos-e2e
-47
View File
@@ -1,47 +0,0 @@
# Commit Command
## Description
Create a git commit following Nx repository standards and validation requirements.
## Usage
```bash
/commit [message]
```
## What this command does:
1. **Pre-commit validation**: Runs the full validation suite (`pnpm nx prepush`) to ensure code quality
2. **Formatting**: Automatically formats changed files with Prettier
3. **Testing**: Runs tests on affected projects to validate changes
4. **Commit creation**: Creates a well-formed commit with proper message formatting (without co-author attribution)
5. **Status reporting**: Provides clear feedback on the commit process
## Workflow:
1. Format any modified files with Prettier
2. Run the prepush validation suite
3. If validation passes, stage relevant changes
4. Create commit with descriptive message
5. Provide summary of what was committed
## Commit Message Format:
- Use conventional commit format when appropriate
- Include scope (e.g., `feat(core):`, `fix(angular):`, `docs(nx):`)
- Keep first line under 72 characters
- Include detailed description if needed
## Examples:
- `/commit "feat(core): add new project graph visualization"`
- `/commit "fix(react): resolve build issues with webpack config"`
- `/commit "docs(nx): update getting started guide"`
## Validation Requirements:
- All tests must pass
- Code must be properly formatted
- No linting errors
- E2E tests for affected areas should pass
-155
View File
@@ -1,155 +0,0 @@
# GitHub Issue Planning and Resolution
This command provides guidance for both automated and manual GitHub issue workflows.
## Automated Workflow (GitHub Actions)
The automated workflow consists of two phases:
### Phase 1: Planning (`@claude plan` or `claude:plan` label)
- Claude analyzes the issue and creates a detailed implementation plan
- Plan is posted as a comment on the issue
- Issue is labeled with `claude:planned`
### Phase 2: Implementation (`@claude implement` or `claude:implement` label)
- Claude implements the solution based on the plan
- Runs validation tests and creates a feature branch
- Suggests opening a PR with proper formatting
## Planning Phase Template
When creating a plan (either automated or manual), include these sections:
### Problem Analysis
- Root cause identification
- Impact assessment
- Related components or systems affected
### Proposed Solution
- High-level approach
- Alternative solutions considered
- Trade-offs and rationale
### Implementation Details
- Files that need to be modified
- Key changes required
- Dependencies or prerequisites
### Testing Strategy
- Unit tests to add/modify
- Integration tests needed
- E2E test considerations
### Validation Steps
```bash
# Test specific affected projects
nx run-many -t test,build,lint -p PROJECT_NAME
# Test all affected projects
nx affected -t build,test,lint
# Run affected e2e tests
nx affected -t e2e-local
# Format code
npx nx prettier -- FILES
# Final validation
pnpm nx prepush
```
### Risks and Considerations
- Breaking changes
- Performance implications
- Migration requirements
## Manual Workflow
When working on a GitHub issue manually, follow this systematic approach:
## 1. Get Issue Details
```bash
# Get issue details using GitHub CLI (replace ISSUE_NUMBER with actual number)
gh issue view ISSUE_NUMBER
```
When cloning reproduction repos, please clone within `./tmp/claude/repro-ISSUE_NUMBER`
## 2. Analyze the Plan
- Look for a plan or implementation details in the issue description
- Check comments for additional context or clarification
- Identify affected projects and components
## 3. Implement the Solution
- Follow the plan outlined in the issue
- Make focused changes that address the specific problem
- Ensure code follows existing patterns and conventions
## 4. Run Full Validation
```bash
# Test specific affected projects first
nx run-many -t test,build,lint -p PROJECT_NAME
# Test all affected projects
nx affected -t build,test,lint
# Run affected e2e tests
nx affected -t e2e-local
# Final pre-push validation
pnpm nx prepush
```
## 5. Submit Pull Request
- Create a descriptive PR title that references the issue
- Include "Fixes #ISSUE_NUMBER" in the PR description
- Provide a clear summary of changes made
- Request appropriate reviewers
## Pull Request Template
When creating a pull request, follow the template found in `.github/PULL_REQUEST_TEMPLATE.md`. The template includes:
### Required Sections
1. **Current Behavior**: Describe the behavior we have today
2. **Expected Behavior**: Describe the behavior we should expect with the changes in this PR
3. **Related Issue(s)**: Link the issue being fixed so it gets closed when the PR is merged
### Template Format
```markdown
## Current Behavior
<!-- This is the behavior we have today -->
## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR -->
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is merged. -->
Fixes #ISSUE_NUMBER
```
### Guidelines
- Ensure your commit message follows the conventional commit format (use `pnpm commit`)
- Read the submission guidelines in CONTRIBUTING.md before posting
- For complex changes, you can request a dedicated Nx release by mentioning the Nx team
- Always link the related issue using "Fixes #ISSUE_NUMBER" to automatically close it when merged
-30
View File
@@ -1,30 +0,0 @@
# Claude Issue Workflow Usage Guide
## Quick Start
## Expected Outputs
### Planning Phase
- Detailed analysis comment posted to issue
- Implementation plan with steps and file changes
- Testing strategy and validation steps
- Risk assessment
### Implementation Phase
- Code changes made according to plan
- Tests run and validated
- Feature branch created: `fix/issue-{number}`
- PR suggestion with proper title format
## Manual Override
If you need to work on an issue manually, use the `/gh-issue-plan` command for structured guidance following the same workflow patterns.
## Troubleshooting
- Ensure you're on the authorized users list
- Check that the issue has sufficient detail for analysis
- For implementation, ensure a plan comment exists from the planning phase
- If workflows fail, check the Actions tab for detailed logs
-46
View File
@@ -1,46 +0,0 @@
{
"permissions": {
"allow": [
"Bash(find:*)",
"Bash(ls:*)",
"Bash(mkdir:*)",
"WebFetch(domain:github.com)",
"WebFetch(domain:www.typescriptlang.org)",
"Bash(git log:*)",
"Bash(gh issue list:*)",
"Bash(gh issue view:*)",
"Bash(npx prettier:*)",
"Bash(nx prepush:*)",
"Bash(pnpm commit:*)",
"Bash(rg:*)",
"mcp__nx__nx_docs",
"mcp__nx__nx_workspace",
"mcp__nx__nx_project_details",
"Bash(nx show projects:*)",
"Bash(nx run-many:*)",
"Bash(nx run:*)",
"Bash(nx affected:*)",
"Bash(nx lint:*)",
"Bash(nx test:*)",
"Bash(nx build:*)",
"Bash(nx documentation:*)"
],
"deny": []
},
"enableAllProjectMcpServers": true,
"env": {
"BASH_MAX_TIMEOUT_MS": "1800000"
},
"extraKnownMarketplaces": {
"nx-claude-plugins": {
"source": {
"source": "github",
"repo": "nrwl/nx-ai-agents-config",
"ref": "experimental"
}
}
},
"enabledPlugins": {
"nx@nx-claude-plugins": true
}
}
@@ -1,301 +0,0 @@
---
name: diagnose-sandbox-report
description: >
Diagnose Nx sandbox violations from a sandbox report. Use when asked to
"diagnose sandbox", "analyze sandbox report", "investigate sandbox violations",
"check violations", when given a sandbox report JSON file or URL to investigate,
or when the user pastes a staging.nx.app sandbox-report URL. Also trigger when
discussing unexpected reads/writes in Nx task execution. Guides structured
investigation of why tasks read/write undeclared files, determines root causes,
and recommends fixes.
argument-hint: '<sandbox-report.json or URL> [--filter <file|pattern|list>]'
allowed-tools: Bash, Read, Grep, Glob
---
# Diagnose Sandbox Report
## Overview
Sandbox violations occur when an Nx task reads files not declared as inputs or writes files not declared as outputs.
**Unexpected reads** are one of:
1. **Missing input** (most likely) — the process legitimately needs this file. Understand what the process does and why the access makes sense, then declare it as an input.
2. **Potential sandboxing gap** (last resort) — the access is irrelevant to correctness and should be filtered/ignored by the sandbox. Only conclude this after exhausting every possibility for it being a missing input.
**Unexpected writes** follow the same logic:
1. **Missing output** (most likely) — the process legitimately produces this file.
2. **Potential sandboxing gap** (last resort) — same as above.
The default assumption is that an unexpected access IS a missing declaration. The investigation's job is to understand WHY the process accesses the file — not to find reasons it shouldn't.
## Critical Rules
1. **NEVER read the sandbox report JSON directly** — these files are too large for the Read tool (50K+ tokens). Do NOT use `Read`, `cat`, `head`, `python3`, or `jq` on the raw report. All report parsing is handled by the script.
2. **ALWAYS run the context-gathering script as the very first step** — no manual parsing, no ad-hoc python/jq on the report file. The script does everything deterministically.
3. If the script fails, **report the error and stop**. Do not attempt manual parsing as a fallback.
4. **Identify the inferring plugin BEFORE proposing any fix** — check `inference.plugin` in the script output or run `jq '.targets.<target>.metadata' <detail-file>`. Fixing the wrong plugin wastes entire investigation rounds.
5. **Verify hypotheses empirically before committing to them** — see Principle 4 and the Phase 2 instrumentation guidance.
## Workflow
### Phase 0: Input
User provides one of:
- Path to a sandbox report JSON file
- A URL to a sandbox report — pass it directly to the script, it handles downloading
- A task ID + CIPE URL (fetch report via MCP if available)
- Inline violation data
If a task ID is provided but no report, ask the user for the report file.
**Filtering**: Most invocations will focus on specific files, not the entire report. The user may specify:
- A single file: `e2e.log`
- A comma-separated list: `apps/nx-cloud/e2e.log,apps/nx-cloud/build/client/assets/main.js`
- A glob pattern: `*.tsbuildinfo`, `apps/nx-cloud/build/**`
- A directory prefix: `apps/nx-cloud/build/client/assets`
When the user specifies files to focus on, pass them via `--filter` to the script. When they don't specify a filter and the report has many violations, summarize the groupings (by directory, extension) and ask which group(s) to investigate first rather than trying to investigate everything at once.
### Phase 1: Deterministic Pre-Processing
Run the context-gathering script **immediately** — this is the first tool call after reading the user's input.
Call it exactly as shown — do NOT append `2>&1` or `2>/dev/null` (the script manages its own stderr internally). Run in the **foreground** (no `run_in_background`) with a **3-minute timeout** — reports can be large and the script runs the task + multiple nx commands:
```bash
npx tsx ${CLAUDE_SKILL_DIR}/scripts/gather-sandbox-context.ts <report.json or URL> [--filter <pattern>] [--workspace <path>]
```
Pass `--filter` when the user wants to focus on specific files or patterns. The script filters violations before all downstream processing (grouping, validation, classification), so the output only contains relevant data.
The script produces two outputs:
**stdout** (~3-5KB compact brief) — everything needed to start investigating:
- `summary`: violation counts (total, filtered, confirmed vs undeclared)
- `undeclaredFiles`: the actual file paths that are true violations
- `grouping`: violations grouped by directory and extension
- `commands`: processes with violations (pid, cmd, executable, arguments, counts) — no full file lists
- `classificationSummary`: counts per category (cross-project, build artifacts, config files, etc.)
- `crossProjectDependencyCheck`: whether cross-project file owners are in the task's dependency chain
- `staleDeclarations`: grouped analysis of expectedInputsNotRead / expectedOutputsNotWritten
- `dependentTasksOutputFiles`: extracted from target inputs config and named inputs — shows what dep output globs are declared (critical for cross-project violations)
- `executorInfo`: executor name and resolved source path in `node_modules` — read this file to understand how the tool is invoked
- `checkSample`: results of `--check` on up to 5 undeclared files (catches false positives early)
- `inference` + `pluginRegistration`: plugin metadata
- `verificationCommands`: pre-built `--check` commands with the correct task ref
- `detailFile`: path to the full detail JSON
**detail file** (`/tmp/sandbox-diagnosis-detail-<project>-<target>.json`) — full data for drill-down. Structure:
- `processTree.processTree`: array of `{pid, cmd, parentPid}` entries
- `processTree.processPidToCmd`: `{ "pid": "command string" }` map
- `processTree.readsByPid`: `{ "pid": ["file1", "file2"] }` — violated reads grouped by PID
- `processTree.writesByPid`: `{ "pid": ["file1", "file2"] }` — violated writes grouped by PID
- `targetConfig`: full target configuration (executor, options, inputs, outputs, dependsOn)
- `projectConfig`: full project configuration
- `resolvedInputs`: `{ files: [...], depOutputs: [...], runtime: [...], environment: [...] }`
- `resolvedOutputs`: `{ outputPaths: [...], expandedOutputs: [...] }`
- `validation`: `{ reads: { confirmed: [...], undeclared: [...] }, writes: { ... } }`
- `classification`: `{ reads: { crossProject, buildArtifacts, configFiles, ... }, writes: { ... } }`
Read the brief output — it has everything to start. Use `jq` on the detail file only when you need to drill into specific sections. When querying the detail file, use the structure above — do not guess the schema. Do NOT use Python, ad-hoc scripts, or the Read tool on the detail file — only `jq`.
For reports with many violations, use `--filter` to narrow scope. When investigating without a filter, use the `grouping` data to identify patterns and prioritize — don't try to trace every file individually.
If `summary.undeclaredReads` and `summary.undeclaredWrites` are both 0, all violations were resolved by the script's validation against resolved inputs/outputs. Report this to the user — no further investigation needed.
The `commands` array pre-parses each process — use `executable` and `arguments` to identify the tool without re-parsing `cmd`. When many files share the same root cause, group them under one finding using a glob pattern or count (e.g., "88 `.d.ts` files matching `packages/nx/dist/**/*.d.ts`").
### Phase 2: Command Analysis — the core investigation
**This is the most important phase.** The goal is to determine with 100% certainty why each process reads or writes each violated file. Do not classify violations from file names or paths alone — trace the actual causal chain from command → config → file access.
#### Step 1: Understand the command
The brief's `commands` array pre-parses each process. Use the `executable` and `arguments` fields directly — don't re-parse `cmd`. Identify:
- The tool (from `executable`)
- The arguments (target files/dirs, config flags, extensions — from `arguments`)
- The working directory (from executor options or project root)
#### Step 2: Trace why the command accesses each violated file
For each violated file, establish the **exact causal chain** that leads the command to read or write it. The approach is the same regardless of tool:
1. Identify the tool's config file (usually in the project root or workspace root)
2. Read the config and trace file references: `includes`, `extends`, `presets`, entry points, plugins
3. Follow the reference chain until you can explain exactly why the violated file is accessed
Common causal patterns:
- **Config chain walk-up**: tool reads config, config extends another, chain reaches the violated file (e.g., tsconfig `extends`, eslint config chain, jest preset chain)
- **Directory traversal**: tool scans a directory for matching files and reads everything, including files it won't process (e.g., jest-haste-map scanning `.next/`, eslint reading `.d.ts` alongside `.ts`)
- **Dependency resolution**: tool resolves imports/requires and follows the dependency graph to files outside the project (e.g., esbuild/vite/webpack resolving workspace packages to their dist outputs)
- **Plugin/transformer loading**: tool loads plugins or transformers that read additional files (e.g., ts-jest loading tsconfig for TypeScript compilation)
For any tool, read its source code in `node_modules` to understand its file discovery behavior. Don't assume — trace the actual code.
**You must be able to explain the full path:** e.g., "eslint loads `.eslintrc.json` → configures `@typescript-eslint/parser` → parser resolves `parserOptions.project` → walks up to find `tsconfig.json` → reads it." If you can't trace the full path, keep investigating — do not guess.
**When theoretical analysis is inconclusive, verify empirically.** For difficult cases, instrument `node_modules` with interceptors to capture real stack traces. For example, patch `fs.readFileSync` in the tool's entry point to log stack traces when the violated file is accessed. A confirmed stack trace is worth more than multiple rounds of code reading.
#### Step 3: Confirm the violation with `--check`
**This step is mandatory — do not skip it.** The script already runs `--check` on a sample of up to 5 undeclared files (see `checkSample` in the brief). Review those results first — if the sample files are confirmed as inputs/outputs, the corresponding violations are false positives.
For files not in the sample, use the pre-generated commands from `verificationCommands` in the brief:
```bash
npx nx show target inputs <project>:<target> --check <violated-read-files>
npx nx show target outputs <project>:<target> --check <violated-write-files>
```
If the commands fail because output files don't exist (e.g., the script's task run timed out), run the task first with `verificationCommands.runTask`.
If `--check` shows the file IS already an input/output, the violation is a false positive from the script's static analysis. If it confirms the file is NOT an input/output, proceed to classification.
#### Step 4: Classify
With the causal chain established and the violation confirmed, classify into one of these categories:
1. **Missing input/output** (most common) — the process legitimately needs this file. Understand why:
- **Direct dependency** — the tool needs this file to do its job (e.g., tsc reads referenced tsconfigs, eslint loads config chain)
- **Transitive dependency** — a config file references another file that references this one (e.g., jest preset → resolver → module). Trace the full chain.
- **Directory traversal side effect** — the tool reads all files in a directory even if it only processes some (e.g., eslint reads `.d.ts` files while linting `.ts`). Still a legitimate access from the tool's perspective.
2. **Bad tool configuration** — the tool accesses a file it shouldn't because its scope is too broad. The fix is fixing the tool's config, NOT adding an input. Investigate:
- Is the command targeting too broad a directory? (e.g., `eslint .` instead of `eslint src/`)
- Is a config file missing ignore/exclude rules? (e.g., eslint processing a file type it should skip)
- Is a plugin inferring a target for a project that doesn't match? (e.g., eslint target on a non-JS project)
- Is an env var causing the tool to behave differently?
3. **Potential sandboxing gap** (last resort) — the access is genuinely irrelevant to correctness (PID files, temp sockets, dev server logs that no task consumes). Only conclude this after exhausting categories 1 and 2.
### Phase 3: Deep Investigation
For violations that aren't immediately obvious, investigate further:
#### If the target is inferred by a plugin
1. Identify which plugin from `inference.plugin` in the brief output, or `nx show project --json` metadata
2. Read the plugin's `createNodesV2` implementation to understand inference logic
3. Determine if this project should have this target at all
4. Check if the plugin has `include`/`exclude` patterns in `nx.json` that should filter this project
5. **Check for input override layers**`project.json`, `package.json`, or `nx.json` `targetDefaults` may override plugin-inferred inputs, rendering plugin-level fixes invisible. Check all three before concluding a plugin fix is sufficient.
#### If violations come from a subprocess
1. Trace the process tree: which parent spawned the subprocess?
2. Why does the subprocess exist? (dev server for e2e, worker thread, build tool subprocess)
3. What environment does the subprocess inherit? (env vars, cwd)
4. Does the subprocess access files in a different project's directory?
#### If violations involve config file reference chains
1. Read the config file (jest.config, tsconfig, .eslintrc)
2. Trace all file references: `preset`, `extends`, `references`, `setupFiles`, `resolver`, `moduleNameMapper`, `transform`, etc.
3. Recursively resolve references (preset → preset → files)
4. Determine which referenced files are not declared as task inputs
#### If violations involve dependency task outputs
1. Check `dependsOn` to understand task dependency chain
2. Check `dependentTasksOutputFiles` glob pattern — is it too narrow?
3. Compare the glob against actual file types the tool reads from dependencies (e.g., `**/*.d.ts` missing `.tsbuildinfo`)
#### Generalizability analysis
After diagnosing the root cause, determine scope:
1. Is this violation specific to this project, or does it affect all projects using this tool/plugin?
2. What conditions trigger it? (specific config, specific tool version, specific project structure)
3. Should the fix be per-project (declarative input) or systemic (plugin improvement)?
4. If the plugin can be made smarter to infer the correct inputs, that's preferable to manual declarations.
### Phase 4: Output
**You MUST present findings using the structured format below before proceeding to any implementation discussion.** Do not use free-form narrative — the structure ensures completeness and makes findings reviewable.
Present findings grouped by category:
```
=== Sandbox Violation Diagnosis: {project}:{target} ===
## Summary
Unexpected reads: N total → M validated as declared → K true violations
Unexpected writes: N total → M validated as declared → K true violations
## Findings
### [MISSING INPUT] {short description}
Files: {file list or pattern}
Process: PID {pid} — {command}
Why: {why the process legitimately needs this file}
Scope: {project-specific or affects all projects using this tool/plugin}
Fix: {where/how to add the input declaration — consider both declarative (add input) and systemic (improve plugin inference) options}
### [MISSING OUTPUT] {short description}
Files: {file list or pattern}
Process: PID {pid} — {command}
Why: {why the process produces this file}
Scope: {project-specific or affects all projects using this tool/plugin}
Fix: {where/how to add the output declaration}
### [BAD TOOL CONFIG] {short description}
Files: {file list or pattern}
Process: PID {pid} — {command}
Why: {why the tool accesses files it shouldn't — config too broad, missing ignore, etc.}
Fix: {specific tool config change}
### [POTENTIAL SANDBOXING GAP] {short description}
Files: {file list or pattern}
Process: PID {pid} — {command}
Why: {why this access is irrelevant to correctness}
Evidence: {proof that categories 1-2 were exhausted}
### [INVESTIGATE] {short description}
Files: {file list or pattern}
Notes: {what's known, what needs more info}
Question: {what to ask the user or team}
## Stale Declarations
expectedInputsNotRead: {count and details if relevant}
expectedOutputsNotWritten: {count and details if relevant}
## Verification Plan
For each fix, provide the exact commands to verify:
1. Run the task so output files exist on disk: `npx nx <target> <project> --skip-nx-cache`
2. Check each violation file is now an input: `npx nx show target <project>:<target> inputs --check <space-separated files>`
3. For plugin-level fixes: build the plugin, patch node_modules, then verify with steps 1-2
```
## Principles
1. **Missing declaration is the default.** Most unexpected accesses are legitimate — the process needs the file, it just wasn't declared. Start from this assumption and investigate to understand WHY the access happens.
2. **The command is the unit of analysis.** Don't classify files in isolation. Understand what the command does and whether each file access makes sense given that command's purpose.
3. **Trace the full chain.** Plugin inference → target config → executor → command → file access. The root cause is often several layers removed from the symptom.
4. **Empirical over theoretical.** When code analysis produces a hypothesis, verify it before acting. Instrument `node_modules`, capture stack traces, run with debug flags. Wrong theories waste entire investigation rounds.
5. **Be thorough.** Read plugin source code, config files, executor implementations. Don't guess based on file names alone.
6. **Potential sandboxing gaps are last resort.** Only conclude this after exhausting missing declaration and bad tool config. The access must be genuinely irrelevant to correctness.
7. **Verify claims about Nx behavior in source code.** Any assertion about how Nx works must be traced to the actual implementation. Do not reason from theory or assumptions.
8. **Prefer systemic fixes over per-project declarations.** If a plugin can be improved to infer correct inputs for all projects, that's better than adding manual input declarations to each project.
## Delegating to Subagents
When the investigation is complex and requires parallel research, you can delegate to subagents. Follow this pattern:
1. **Run the context-gathering script yourself first.** The brief output (~3-5KB) is the shared context all subagents need.
2. **Include the brief output in each subagent prompt** along with the specific question to investigate. Subagents should NOT run the script again or try to parse the raw report.
3. **Give subagents the detail file path** so they can `jq` specific sections (process tree, resolved inputs, etc.) without re-running the script.
4. **Each subagent should answer one focused question**, e.g., "Why does PID 12345 (eslint) read `tsconfig.base.json`? Trace the full causal chain from the eslint config."
5. **Subagents must still follow the skill principles** — trace full causal chains, verify empirically, use `--check`, don't guess from file names. Include these instructions in the subagent prompt.
6. **Synthesize subagent results yourself** using the structured Phase 4 output format. Do not delegate the final classification.
## Reference
For the sandbox report data model and field definitions, see `references/data-model.md`.
@@ -1,92 +0,0 @@
# Sandbox Report Data Model
## Raw Report Structure (JSON)
```typescript
interface SandboxReport {
taskId: string; // "project:target" or "project:target:configuration"
sandboxReportId: string;
inputs: string[]; // declared input patterns (globs or paths)
outputs: string[]; // declared output patterns
filesRead: FileAccessEntry[]; // all files actually read
filesWritten: FileAccessEntry[]; // all files actually written
unexpectedReads?: FileAccessEntry[]; // reads not matching any input pattern
unexpectedWrites?: FileAccessEntry[]; // writes not matching any output pattern
expectedInputsNotRead?: string[]; // declared inputs never accessed
expectedOutputsNotWritten?: string[]; // declared outputs never written
processTree?: ProcessTreeEntry[]; // process hierarchy with commands
}
interface FileAccessEntry {
path: string; // workspace-relative file path
pid: number; // process ID that accessed the file
}
interface ProcessTreeEntry {
pid: number;
cmd: string; // full command string
parentPid?: number; // parent process (absent for root)
}
```
## Violation Computation
Violations are computed by `findUnexpectedFiles()` using `minimatch`:
- A file is "unexpected" if it does NOT match any declared pattern
- Patterns without wildcards also match as directory prefixes (`pattern + '/'`)
- If `unexpectedReads`/`unexpectedWrites` are pre-computed in the report, those are used directly
## Nx CLI Commands for Context
### `nx show target <project:target> --json`
Returns: executor, command, options (merged with configuration), inputs (configured, not resolved), outputs, dependsOn, cache, parallelism, configurations, metadata.
### `nx show target inputs <project:target> --json`
Returns resolved input files (requires files to exist on disk — task must have run):
```json
{
"files": ["workspace-relative paths..."],
"runtime": ["node version checks..."],
"environment": ["ENV_VAR_NAMES..."],
"depOutputs": ["dependency output paths..."],
"external": ["external package names..."]
}
```
### `nx show target inputs <project:target> --check <files...>`
Validates specific files against declared inputs. Exit code 0 = match, 1 = no match.
Categories: `files`, `environment`, `runtime`, `external`, `depOutputs`.
Also detects directory matches (directory containing N input files).
### `nx show target outputs <project:target> --json`
Returns:
```json
{
"outputPaths": ["configured output paths..."],
"expandedOutputs": ["glob-expanded actual paths..."],
"unresolvedOutputs": ["{options.key} patterns that couldn't resolve..."]
}
```
### `nx show target outputs <project:target> --check <files...>`
Validates specific files against declared outputs. Same exit code behavior as inputs.
### `nx show project <project> --json`
Returns full project config. Key fields for sandbox analysis:
- `targets[name].metadata.plugin` — which plugin inferred the target
- `targets[name].metadata.technologies` — what tech the target uses
- `root` — project root directory
### `nx graph --view=tasks --targets=<target> --focus=<project> --print --file=stdout`
Returns task dependency graph with task IDs, dependencies, and roots.
@@ -1,846 +0,0 @@
#!/usr/bin/env npx tsx
/**
* gather-sandbox-context: Parse sandbox report + gather Nx task context
* Produces structured JSON for the diagnose-sandbox-report skill
*
* Usage: npx tsx gather-sandbox-context.ts <report.json or URL> [--filter <pattern>] [--workspace <path>]
*/
import { readFileSync, writeFileSync, existsSync } from 'fs';
import { resolve, basename, extname, dirname } from 'path';
import { execSync, execFileSync } from 'child_process';
import { minimatch } from 'minimatch';
// --- CLI argument parsing ---
interface Args {
reportFile: string;
filter: string | null;
workspaceRoot: string;
}
function parseArgs(): Args {
const args = process.argv.slice(2);
let reportFile = '';
let filter: string | null = null;
let workspaceRoot = process.cwd();
for (let i = 0; i < args.length; i++) {
switch (args[i]) {
case '--filter':
filter = args[++i];
break;
case '--workspace':
workspaceRoot = args[++i];
break;
case '--help':
case '-h':
console.error(
'Usage: gather-sandbox-context <report.json or URL> [--filter <pattern>] [--workspace <path>]'
);
process.exit(1);
default:
if (args[i].startsWith('-')) {
console.error(`Unknown option: ${args[i]}`);
process.exit(1);
}
reportFile = args[i];
}
}
if (!reportFile) {
console.error(
'Usage: gather-sandbox-context <report.json or URL> [--filter <pattern>] [--workspace <path>]'
);
process.exit(1);
}
return { reportFile, filter, workspaceRoot };
}
// --- Types ---
interface FileAccessEntry {
path: string;
pid: number;
}
interface ProcessTreeEntry {
pid: number;
cmd: string;
parentPid?: number;
}
interface SandboxReport {
taskId: string;
unexpectedReads?: FileAccessEntry[];
unexpectedWrites?: FileAccessEntry[];
expectedInputsNotRead?: string[];
expectedOutputsNotWritten?: string[];
filesRead?: FileAccessEntry[];
filesWritten?: FileAccessEntry[];
processTree?: ProcessTreeEntry[];
}
// --- Helpers ---
function downloadUrl(url: string): string {
const tmpPath = `/tmp/sandbox-report-${Date.now()}.json`;
try {
execFileSync('curl', ['-sL', '-o', tmpPath, url], { stdio: 'pipe' });
} catch {
console.error(`Error: Failed to download report from URL: ${url}`);
process.exit(1);
}
return tmpPath;
}
function runNxCommand(
args: string[],
workspaceRoot: string,
timeoutMs = 30000
): string | null {
try {
return execFileSync('npx', ['nx', ...args], {
cwd: workspaceRoot,
timeout: timeoutMs,
stdio: ['pipe', 'pipe', 'pipe'],
encoding: 'utf-8',
});
} catch {
return null;
}
}
function safeJsonParse<T>(str: string | null, fallback: T): T {
if (!str) return fallback;
try {
return JSON.parse(str);
} catch {
return fallback;
}
}
function filterEntries(
entries: FileAccessEntry[],
filterStr: string | null
): FileAccessEntry[] {
if (!filterStr) return entries;
const patterns = filterStr.split(',').map((p) => p.trim());
return entries.filter((entry) =>
patterns.some((pattern) => {
if (
pattern.includes('*') ||
pattern.includes('?') ||
pattern.includes('[')
) {
// Glob pattern — if no slashes, match against basename
if (!pattern.includes('/')) {
return minimatch(basename(entry.path), pattern);
}
return minimatch(entry.path, pattern);
}
// Literal: exact match or directory prefix
return entry.path === pattern || entry.path.startsWith(pattern + '/');
})
);
}
function groupByDirPrefix(
paths: string[],
depth = 3
): { prefix: string; count: number }[] {
const groups: Record<string, number> = {};
for (const p of paths) {
const prefix = p.split('/').slice(0, depth).join('/');
groups[prefix] = (groups[prefix] || 0) + 1;
}
return Object.entries(groups)
.map(([prefix, count]) => ({ prefix, count }))
.sort((a, b) => b.count - a.count);
}
function groupByExtension(paths: string[]): { ext: string; count: number }[] {
const groups: Record<string, number> = {};
for (const p of paths) {
const ext = extname(p) || '(no ext)';
groups[ext] = (groups[ext] || 0) + 1;
}
return Object.entries(groups)
.map(([ext, count]) => ({ ext, count }))
.sort((a, b) => b.count - a.count);
}
function classifyFiles(
undeclared: string[],
projectRoot: string,
projectRoots: Record<string, string>
) {
const projects = Object.entries(projectRoots).map(([project, root]) => ({
project,
root,
}));
const isBuildArtifact = (f: string) =>
f.startsWith('dist/') ||
f.startsWith('build/') ||
f.startsWith('out-tsc/') ||
f.startsWith('.next/') ||
f.includes('/node_modules/.cache/') ||
f.endsWith('.tsbuildinfo') ||
f.includes('/dist/') ||
f.includes('/build/output/');
const configBasenames = new Set(['nx.json', 'project.json', 'package.json']);
const configPrefixes = [
'tsconfig',
'jest.config',
'jest.preset',
'.eslintrc',
'eslint.config',
'playwright.config',
'webpack.config',
'vite.config',
'babel.config',
'.babelrc',
'rollup.config',
];
const isConfigFile = (f: string) => {
const b = basename(f);
return (
configBasenames.has(b) ||
configPrefixes.some((prefix) => b.startsWith(prefix))
);
};
const isEnvFile = (f: string) => {
const b = basename(f);
return b === '.env' || b.startsWith('.env.');
};
const classified = undeclared.map((f) => {
const inProjectRoot = projectRoot !== '' && f.startsWith(projectRoot + '/');
const owner = projects.find((p) => f.startsWith(p.root + '/'));
return {
path: f,
inProjectRoot,
ownerProject: owner?.project ?? null,
isBuildArtifact: isBuildArtifact(f),
isConfigFile: isConfigFile(f),
isEnvFile: isEnvFile(f),
};
});
return {
crossProject: classified
.filter((c) => !c.inProjectRoot)
.map((c) => ({ path: c.path, owner: c.ownerProject })),
buildArtifacts: classified
.filter((c) => c.isBuildArtifact)
.map((c) => c.path),
configFiles: classified.filter((c) => c.isConfigFile).map((c) => c.path),
envFiles: classified.filter((c) => c.isEnvFile).map((c) => c.path),
inProjectRoot: classified.filter((c) => c.inProjectRoot).map((c) => c.path),
outsideProjectRoot: classified
.filter((c) => !c.inProjectRoot)
.map((c) => c.path),
total: undeclared.length,
};
}
function validateViolations(
violations: string[],
resolvedFiles: Set<string>
): { confirmed: string[]; undeclared: string[] } {
const confirmed: string[] = [];
const undeclared: string[] = [];
const seen = new Set<string>();
for (const f of violations) {
if (seen.has(f)) continue;
seen.add(f);
if (resolvedFiles.has(f)) {
confirmed.push(f);
} else {
undeclared.push(f);
}
}
return { confirmed, undeclared };
}
function validateOutputViolations(
violations: string[],
resolvedOutputs: string[]
): { confirmed: string[]; undeclared: string[] } {
const outputSet = new Set(resolvedOutputs);
const outputDirs = resolvedOutputs.map((o) => o + '/');
const confirmed: string[] = [];
const undeclared: string[] = [];
const seen = new Set<string>();
for (const f of violations) {
if (seen.has(f)) continue;
seen.add(f);
if (outputSet.has(f) || outputDirs.some((d) => f.startsWith(d))) {
confirmed.push(f);
} else {
undeclared.push(f);
}
}
return { confirmed, undeclared };
}
function extractCommands(
processTree: ProcessTreeEntry[],
readsByPid: Record<string, string[]>,
writesByPid: Record<string, string[]>
) {
const pidToCmd: Record<string, string> = {};
for (const entry of processTree) {
pidToCmd[String(entry.pid)] = entry.cmd;
}
return processTree
.filter(
(entry) =>
(readsByPid[String(entry.pid)]?.length ?? 0) > 0 ||
(writesByPid[String(entry.pid)]?.length ?? 0) > 0
)
.map((entry) => {
const parts = entry.cmd.split(' ');
const exe = parts[0].split('/').pop() ?? parts[0];
return {
pid: entry.pid,
cmd: entry.cmd,
parentPid: entry.parentPid ?? null,
parentCmd: entry.parentPid
? (pidToCmd[String(entry.parentPid)] ?? null)
: null,
unexpectedReadCount: readsByPid[String(entry.pid)]?.length ?? 0,
unexpectedWriteCount: writesByPid[String(entry.pid)]?.length ?? 0,
unexpectedReads: readsByPid[String(entry.pid)] ?? [],
unexpectedWrites: writesByPid[String(entry.pid)] ?? [],
executable: exe,
arguments: parts.slice(1).join(' '),
};
})
.sort(
(a, b) =>
b.unexpectedReadCount +
b.unexpectedWriteCount -
(a.unexpectedReadCount + a.unexpectedWriteCount)
);
}
function resolveExecutorSource(
executor: string | undefined,
workspaceRoot: string
): { executor: string; sourcePath: string } {
if (
!executor ||
executor === 'null' ||
executor.includes('nx:run-commands')
) {
return { executor: executor ?? '', sourcePath: '' };
}
const lastColon = executor.lastIndexOf(':');
const pkg = executor.substring(0, lastColon);
const name = executor.substring(lastColon + 1);
try {
const result = execFileSync(
'node',
[
'-e',
`
try {
const pkg = require('${pkg}/package.json');
const executors = pkg.executors || pkg.builders;
if (executors) {
const p = require.resolve('${pkg}/' + executors);
const dir = require('path').dirname(p);
const json = require(p);
const impl = json.executors?.['${name}']?.implementation ||
json.builders?.['${name}']?.implementation;
if (impl) console.log(require.resolve(dir + '/' + impl));
}
} catch(e) {}
`,
],
{
cwd: workspaceRoot,
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 10000,
}
).trim();
return { executor, sourcePath: result };
} catch {
return { executor, sourcePath: '' };
}
}
function extractDepTaskOutputFiles(
targetConfig: any,
workspaceRoot: string
): { dependentTasksOutputFiles: any[]; namedInputs: string[] } {
const inputs: any[] = targetConfig?.inputs ?? [];
const depOutputs: any[] = [];
const namedInputs: string[] = [];
for (const input of inputs) {
if (
typeof input === 'object' &&
input !== null &&
'dependentTasksOutputFiles' in input
) {
depOutputs.push({
glob: input.dependentTasksOutputFiles,
transitive: input.transitive ?? false,
});
} else if (
typeof input === 'string' &&
!input.startsWith('{') &&
!input.startsWith('^') &&
!input.includes('/') &&
!input.includes('.')
) {
namedInputs.push(input);
}
}
// Resolve named inputs from nx.json
const nxJsonPath = resolve(workspaceRoot, 'nx.json');
if (existsSync(nxJsonPath) && namedInputs.length > 0) {
try {
const nxJson = JSON.parse(readFileSync(nxJsonPath, 'utf-8'));
for (const name of namedInputs) {
const namedDef = nxJson.namedInputs?.[name] ?? [];
for (const entry of namedDef) {
if (
typeof entry === 'object' &&
entry !== null &&
'dependentTasksOutputFiles' in entry
) {
depOutputs.push({
glob: entry.dependentTasksOutputFiles,
transitive: entry.transitive ?? false,
fromNamedInput: name,
});
}
}
}
} catch {
// ignore nx.json parse errors
}
}
return { dependentTasksOutputFiles: depOutputs, namedInputs };
}
function analyzeStaleDeclarations(
expectedInputsNotRead: string[],
expectedOutputsNotWritten: string[]
) {
const classifyPattern = (value: string) => {
if (/[*{]/.test(value)) return 'glob';
if (value.startsWith('^')) return 'depOutput';
return 'file';
};
const groupByType = (items: string[]) => {
const groups: Record<string, string[]> = {};
for (const item of items) {
const type = classifyPattern(item);
(groups[type] ??= []).push(item);
}
return Object.entries(groups).map(([type, values]) => ({
type,
count: values.length,
samples: values.slice(0, 3),
}));
};
return {
expectedInputsNotRead: expectedInputsNotRead.length,
expectedOutputsNotWritten: expectedOutputsNotWritten.length,
staleInputsByType: groupByType(expectedInputsNotRead),
staleOutputsByType: groupByType(expectedOutputsNotWritten),
};
}
// --- Main ---
async function main() {
const args = parseArgs();
let reportPath = args.reportFile;
// Handle URL inputs
if (reportPath.startsWith('http')) {
reportPath = downloadUrl(reportPath);
}
if (!existsSync(reportPath)) {
console.error(`Error: Report file not found: ${reportPath}`);
process.exit(1);
}
reportPath = resolve(reportPath);
process.chdir(args.workspaceRoot);
// Phase 1: Parse report (single read)
let report: SandboxReport;
try {
report = JSON.parse(readFileSync(reportPath, 'utf-8'));
} catch {
console.error(`Error: Report file is not valid JSON: ${reportPath}`);
process.exit(1);
}
if (!report.taskId) {
console.error('Error: Report file has no .taskId field');
process.exit(1);
}
const [project, target, config] = report.taskId.split(':');
const taskRef = config
? `${project}:${target}:${config}`
: `${project}:${target}`;
const unexpectedReads = report.unexpectedReads ?? [];
const unexpectedWrites = report.unexpectedWrites ?? [];
// Apply filter
const filteredReads = filterEntries(unexpectedReads, args.filter);
const filteredWrites = filterEntries(unexpectedWrites, args.filter);
const readPaths = filteredReads.map((e) => e.path);
const writePaths = filteredWrites.map((e) => e.path);
// Build pid → files maps
const readsByPid: Record<string, string[]> = {};
const writesByPid: Record<string, string[]> = {};
for (const entry of filteredReads) {
(readsByPid[String(entry.pid)] ??= []).push(entry.path);
}
for (const entry of filteredWrites) {
(writesByPid[String(entry.pid)] ??= []).push(entry.path);
}
// Phase 2: Gather Nx task context (run task + parallel nx commands)
runNxCommand(['run', taskRef], args.workspaceRoot, 120000);
const [
targetConfigStr,
projectConfigStr,
resolvedInputsStr,
resolvedOutputsStr,
graphResult,
] = await Promise.all([
runNxCommand(['show', 'target', taskRef, '--json'], args.workspaceRoot),
runNxCommand(['show', 'project', project, '--json'], args.workspaceRoot),
runNxCommand(
['show', 'target', 'inputs', taskRef, '--json'],
args.workspaceRoot
),
runNxCommand(
['show', 'target', 'outputs', taskRef, '--json'],
args.workspaceRoot
),
(() => {
const graphPath = `/tmp/sandbox-project-graph-${Date.now()}.json`;
runNxCommand(['graph', '--file', graphPath], args.workspaceRoot);
try {
return readFileSync(graphPath, 'utf-8');
} catch {
return '{"graph":{"nodes":{}}}';
}
})(),
]);
const targetConfig = safeJsonParse(targetConfigStr, {} as any);
const projectConfig = safeJsonParse(projectConfigStr, {} as any);
const resolvedInputs = safeJsonParse(resolvedInputsStr, {} as any);
const resolvedOutputs = safeJsonParse(resolvedOutputsStr, {} as any);
const projectGraph = safeJsonParse(graphResult, {
graph: { nodes: {} },
} as any);
// Phase 3: Validate violations
const resolvedInputFiles = new Set([
...(resolvedInputs.files ?? []),
...(resolvedInputs.depOutputs ?? []),
]);
const resolvedOutputFiles = [
...(resolvedOutputs.outputPaths ?? []),
...(resolvedOutputs.expandedOutputs ?? []),
];
const checkInputs = validateViolations(readPaths, resolvedInputFiles);
const checkOutputs = validateOutputViolations(
writePaths,
resolvedOutputFiles
);
// Phase 3.5: Sample --check verification
let checkSampleInputs: any = {};
let checkSampleOutputs: any = {};
const sampleReadFiles = checkInputs.undeclared.slice(0, 5);
if (sampleReadFiles.length > 0) {
const result = runNxCommand(
[
'show',
'target',
'inputs',
taskRef,
'--check',
...sampleReadFiles,
'--json',
],
args.workspaceRoot
);
checkSampleInputs = safeJsonParse(result, {});
}
const sampleWriteFiles = checkOutputs.undeclared.slice(0, 5);
if (sampleWriteFiles.length > 0) {
const result = runNxCommand(
[
'show',
'target',
'outputs',
taskRef,
'--check',
...sampleWriteFiles,
'--json',
],
args.workspaceRoot
);
checkSampleOutputs = safeJsonParse(result, {});
}
// Phase 4: File classification
const projectRoots: Record<string, string> = {};
for (const [name, node] of Object.entries(projectGraph.graph?.nodes ?? {})) {
projectRoots[name] = (node as any).data?.root ?? name;
}
const taskProjectRoot = projectRoots[project] ?? '';
const readClassification = classifyFiles(
checkInputs.undeclared,
taskProjectRoot,
projectRoots
);
const writeClassification = classifyFiles(
checkOutputs.undeclared,
taskProjectRoot,
projectRoots
);
// Phase 5: Command extraction
const processTree = report.processTree ?? [];
const commands = extractCommands(processTree, readsByPid, writesByPid);
// Phase 6: Inference detection
const targetMeta = projectConfig.targets?.[target]?.metadata ?? {};
const inference = {
isInferred: 'plugin' in targetMeta || 'technologies' in targetMeta,
plugin: targetMeta.plugin ?? null,
technologies: targetMeta.technologies ?? null,
description: targetMeta.description ?? null,
};
let pluginRegistration: any = {};
const nxJsonPath = resolve(args.workspaceRoot, 'nx.json');
if (inference.plugin && existsSync(nxJsonPath)) {
try {
const nxJson = JSON.parse(readFileSync(nxJsonPath, 'utf-8'));
const plugins = (nxJson.plugins ?? []).map((p: any) =>
typeof p === 'string' ? { plugin: p, options: {} } : p
);
pluginRegistration =
plugins.find((p: any) => p.plugin === inference.plugin) ?? {};
} catch {
// ignore
}
}
// Phase 6.5: dependentTasksOutputFiles + executor resolution
const depTaskOutputs = extractDepTaskOutputFiles(
targetConfig,
args.workspaceRoot
);
const executorInfo = resolveExecutorSource(
targetConfig.executor ?? targetConfig.command,
args.workspaceRoot
);
// Phase 7: Cross-project dependency check
const dependsOn = (targetConfig.dependsOn ?? []).map((d: any) =>
typeof d === 'string' ? d : (d.target ?? '')
);
const checkCrossProject = (classification: typeof readClassification) => {
const owners = [
...new Set(
classification.crossProject
.map((c) => c.owner)
.filter((o): o is string => o !== null)
),
];
return owners.map((owner) => ({
project: owner,
isDependency: dependsOn.some(
(d: string) =>
d === owner ||
d === `${owner}:build` ||
d === `^${owner}:build` ||
d.includes(`^${owner}`)
),
files: classification.crossProject
.filter((c) => c.owner === owner)
.map((c) => c.path),
}));
};
const crossProjectDeps = {
reads: checkCrossProject(readClassification),
writes: checkCrossProject(writeClassification),
};
// Phase 8: Stale declarations
const staleDeclarations = analyzeStaleDeclarations(
report.expectedInputsNotRead ?? [],
report.expectedOutputsNotWritten ?? []
);
// Assemble outputs
const detailFile = `/tmp/sandbox-diagnosis-detail-${taskRef.replace(/[/:@]/g, '-')}.json`;
const detail = {
processTree: {
processTree,
processPidToCmd: Object.fromEntries(
processTree.map((e) => [String(e.pid), e.cmd])
),
readsByPid,
writesByPid,
},
targetConfig,
projectConfig,
resolvedInputs,
resolvedOutputs,
validation: { reads: checkInputs, writes: checkOutputs },
classification: { reads: readClassification, writes: writeClassification },
report: {
taskId: report.taskId,
totalFilesRead: report.filesRead?.length ?? 0,
totalFilesWritten: report.filesWritten?.length ?? 0,
totalUnexpectedReads: unexpectedReads.length,
totalUnexpectedWrites: unexpectedWrites.length,
expectedInputsNotRead: report.expectedInputsNotRead ?? [],
expectedOutputsNotWritten: report.expectedOutputsNotWritten ?? [],
},
commands,
crossProjectDependencyCheck: crossProjectDeps,
staleDeclarations,
inference,
pluginRegistration,
dependentTasksOutputFiles: depTaskOutputs,
executorInfo,
};
writeFileSync(detailFile, JSON.stringify(detail, null, 2));
// Brief to stdout
const brief = {
task: {
ref: taskRef,
project,
target,
configuration: config ?? null,
projectRoot: taskProjectRoot,
},
summary: {
unexpectedReads: unexpectedReads.length,
unexpectedWrites: unexpectedWrites.length,
filteredReads: filteredReads.length,
filteredWrites: filteredWrites.length,
filterApplied: args.filter !== null,
filterPattern: args.filter,
confirmedReads: checkInputs.confirmed.length,
undeclaredReads: checkInputs.undeclared.length,
confirmedWrites: checkOutputs.confirmed.length,
undeclaredWrites: checkOutputs.undeclared.length,
},
undeclaredFiles: {
reads: checkInputs.undeclared,
writes: checkOutputs.undeclared,
},
grouping: {
readsByDirectory: groupByDirPrefix(readPaths),
writesByDirectory: groupByDirPrefix(writePaths),
byExtension: {
readsByExt: groupByExtension(readPaths),
writesByExt: groupByExtension(writePaths),
},
},
commands: commands.map(
({
pid,
cmd,
parentCmd,
executable,
arguments: args,
unexpectedReadCount,
unexpectedWriteCount,
}) => ({
pid,
cmd,
parentCmd,
executable,
arguments: args,
unexpectedReadCount,
unexpectedWriteCount,
})
),
checkSample: {
inputs: checkSampleInputs,
outputs: checkSampleOutputs,
},
classificationSummary: {
reads: {
crossProject: readClassification.crossProject.length,
buildArtifacts: readClassification.buildArtifacts.length,
configFiles: readClassification.configFiles.length,
envFiles: readClassification.envFiles.length,
inProjectRoot: readClassification.inProjectRoot.length,
outsideProjectRoot: readClassification.outsideProjectRoot.length,
},
writes: {
crossProject: writeClassification.crossProject.length,
buildArtifacts: writeClassification.buildArtifacts.length,
configFiles: writeClassification.configFiles.length,
envFiles: writeClassification.envFiles.length,
inProjectRoot: writeClassification.inProjectRoot.length,
outsideProjectRoot: writeClassification.outsideProjectRoot.length,
},
},
crossProjectDependencyCheck: crossProjectDeps,
staleDeclarations,
dependentTasksOutputFiles: depTaskOutputs.dependentTasksOutputFiles,
executorInfo,
inference,
pluginRegistration,
verificationCommands: {
checkInputs: `npx nx show target inputs ${taskRef} --check <files...>`,
checkOutputs: `npx nx show target outputs ${taskRef} --check <files...>`,
runTask: `npx nx run ${taskRef} --skip-nx-cache`,
},
detailFile,
};
console.log(JSON.stringify(brief, null, 2));
}
main().catch((err) => {
console.error(`Script failed: ${err.message}`);
process.exit(1);
});
@@ -1,334 +0,0 @@
---
name: dist-build-migration
description: Migrate an Nx package to build to a local dist/ directory with nodenext module resolution, exports map, and @nx/nx-source condition.
allowed-tools: Bash, Read, Glob, Grep, Agent, Edit, Write
---
# Migrate Package to Local Dist Build
You are migrating an Nx monorepo package from building to `../../dist/packages/<name>` to building locally to `packages/<name>/dist/`. This matches the pattern already used by `nx` and `devkit`.
## Argument
The user provides a package name (e.g., `js`, `webpack`, `angular`). The package lives at `packages/<name>/`.
## Steps
### 0. Preflight: check `workspace:*` deps for unmigrated packages
Read `packages/<name>/package.json` and list every `workspace:*` dep (in `dependencies`, `devDependencies`, `peerDependencies`).
For each such dep, look at the target package's `project.json`. If it does **not** override `release.version.manifestRootsToUpdate` to `["packages/{projectName}"]`, that target package is still on the old layout. You **must** migrate those packages too (apply this skill to each), in the same PR.
**Why:** With `preserveLocalDependencyProtocols: true` (the new pattern), `nx release version` does not substitute `workspace:*` in your manifest. At publish time, pnpm resolves `workspace:*` by reading the target's _source_ `packages/<dep>/package.json`. The default `manifestRootsToUpdate: ["dist/packages/{projectName}"]` only bumps the dist copy, so pnpm picks up the unbumped source `0.0.1` and publishes your package with a dep on a version that does not exist in the registry. Local registry installs then fail with `ERR_PNPM_NO_MATCHING_VERSION`.
A `workspace:*` dep on a still-on-old-layout package is a hard blocker — migrate it before continuing.
### 1. Read current state
Read these files for the target package:
- `packages/<name>/package.json`
- `packages/<name>/project.json`
- `packages/<name>/tsconfig.lib.json`
- `packages/<name>/tsconfig.spec.json` (if exists)
- `packages/<name>/.eslintrc.json` (if exists)
- `packages/<name>/assets.json` (if exists)
- `packages/<name>/.npmignore` (if exists)
- `packages/<name>/.gitignore` (if exists)
Also read the reference implementations:
- `packages/devkit/tsconfig.lib.json`
- `packages/devkit/package.json`
- `packages/devkit/project.json`
- `packages/devkit/.npmignore`
Run `pnpm nx show target <name>:build-base` to see the inferred build target.
Run `pnpm nx show target <name>:build` to see the full build target.
### 2. Identify entry points
Look at the package's root `.ts` files and any existing `exports` field. Common entry points:
- `index.ts` (main)
- `testing.ts`
- `internal.ts`
- `ngcli-adapter.ts`
- Any other `.ts` files at the package root that re-export from `src/`
Also check for `migrations.json` and `generators.json`/`executors.json` — these need exports entries too.
### 3. Update `tsconfig.lib.json`
Transform from the old pattern to the new pattern:
**Before:**
```json
{
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/packages/<name>",
"tsBuildInfoFile": "../../dist/packages/<name>/tsconfig.tsbuildinfo"
}
}
```
**After:**
```json
{
"compilerOptions": {
"outDir": "dist",
"rootDir": ".",
"declarationDir": "dist",
"declarationMap": false,
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo",
"types": ["node"],
"composite": true,
"module": "nodenext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"exclude": ["node_modules", "dist", ...existing excludes, ".eslintrc.json"],
"include": ["*.ts", "src/**/*.ts"]
}
```
**Important**: Adjust `include` based on the package's actual structure. If the package has directories like `bin/`, `plugins/`, etc. at the root level (like `nx` does), include those too.
### 4. Update `tsconfig.spec.json` (if exists)
Change `outDir` from `../../dist/packages/<name>/spec` to `dist/spec`.
### 5. Update `package.json`
Key changes:
- Add `"type": "commonjs"` near the top (after `private`)
- Change `"main"` to `"./dist/index.js"`
- Change `"types"` to `"./dist/index.d.ts"`
- Add `"typesVersions"` for backwards compatibility with `moduleResolution: "node"` consumers
- Add `"exports"` map with entries for each entry point
Each export entry follows this pattern:
```json
"./entry-name": {
"@nx/nx-source": "./entry-name.ts",
"types": "./entry-name.d.ts",
"default": "./dist/entry-name.js"
}
```
The main entry (`.`) uses `./index.ts`, `./index.d.ts`, `./dist/index.js`.
Always include:
```json
"./package.json": "./package.json"
```
Include `"./migrations.json": "./migrations.json"` if the package has migrations.
**Note**: The `@nx/nx-source` condition is a custom condition used for source-level resolution within the workspace (so other packages import from source, not dist).
Add a `typesVersions` field for consumers using `moduleResolution: "node"` (which doesn't read `exports`):
```json
"typesVersions": {
"*": {
"testing": ["dist/testing.d.ts"],
"ngcli-adapter": ["dist/ngcli-adapter.d.ts"]
}
}
```
Add an entry for each subpath export (excluding `.`, `./package.json`, and `./migrations.json`).
### 6. Update `project.json`
Add these sections:
```json
{
"release": {
"version": {
"generator": "@nx/js:release-version",
"preserveLocalDependencyProtocols": true,
"manifestRootsToUpdate": ["packages/{projectName}"]
}
},
"targets": {
"nx-release-publish": {
"options": {
"packageRoot": "packages/{projectName}"
}
}
}
}
```
Do **not** override `build-base.outputs` in `project.json`. The `@nx/js/typescript` plugin reads `outDir` and `tsBuildInfoFile` from `tsconfig.lib.json` and infers the correct outputs (including the tsbuildinfo and the full set of file extensions). A hand-written override is almost always less complete than the inferred set.
Update the existing `build` target's `outputs` if they reference `{workspaceRoot}/dist/packages/<name>` — they should now reference `{projectRoot}/dist/`.
Also update `dependsOn` in the `build` target: replace `"^build"` with `"^build"` if it isn't already, and make sure `"build-base"` is listed.
### 7. Update eslint config
Add `dist` to the ignores. For flat config (`eslint.config.mjs`):
```js
{ ignores: ['**/__fixtures__/**', 'dist'] },
```
For legacy `.eslintrc.json`:
```json
"ignorePatterns": ["!**/*", "node_modules", "dist"]
```
Do **not** add `*.d.ts` or `**/*.d.ts` — the base config already ignores `**/dist`, and `tsconfig.lib.json` (Step 4) sends all generated `.d.ts` files into `dist`, so they're already out of scope. Hand-authored `.d.ts` files in `src/` (e.g. `schema.d.ts`) generally don't need ignoring.
### 8. Update `assets.json` (if exists)
Change `outDir` from `"dist/packages/<name>"` to `"packages/<name>/dist"`.
### 9. Add `files` field to `package.json`
Instead of using `.npmignore`, add a `"files"` field to `package.json` (matching the `nx` package pattern). Remove `.npmignore` if it exists.
```json
"files": [
"dist",
"!dist/tsconfig.tsbuildinfo",
"migrations.json"
]
```
Adjust based on the package's needs:
- Add `"executors.json"` and/or `"generators.json"` if the package has them
- Add any other non-TS files that need to be published
- npm always includes `package.json` and `README.md` automatically — no need to list them
### 10. Rename README.md and update build command
If the package has a `README.md` at its root and uses the `copy-readme.js` script in its build target:
1. Rename `README.md` to `readme-template.md` (`git mv`)
2. Update the build command to pass explicit paths:
```
node ./scripts/copy-readme.js <name> packages/<name>/readme-template.md packages/<name>/README.md
```
3. Update the build target `outputs` to `["{projectRoot}/README.md"]`
The script's default behavior reads `packages/<name>/README.md` and writes to `dist/packages/<name>/README.md` — both wrong for the new layout. Passing explicit args fixes both.
### 11. Update root `.gitignore`
Under the section that lists generated README files (look for `packages/nx/README.md`), add:
```
packages/<name>/README.md
```
The generated README is written next to source (not into `dist/`), so it needs its own ignore.
Do **not** add a `packages/<name>/**/*.d.ts` rule. The root `.gitignore` already has a top-level `dist` entry that ignores every `dist/` directory in the repo — and `tsconfig.lib.json` (Step 4) sets `declarationDir: "dist"`, so all generated `.d.ts` files land there. Adding a package-wide `**/*.d.ts` rule plus `!` re-includes for hand-authored `.d.ts` files (like committed `schema.d.ts` source files) is redundant defense-in-depth.
### 12. Update docs generation paths
Check `astro-docs/src/plugins/utils/` for any code that references `.d.ts` files from the package. The docs generation reads `.d.ts` entry points to build API reference pages. Paths that previously pointed to `dist/packages/<name>/foo.d.ts` (workspace root dist) or `packages/<name>/foo.d.ts` (package root) now need to point to `packages/<name>/dist/foo.d.ts`.
For example, `devkit-generation.ts` had to be updated to look for `packages/devkit/dist/index.d.ts` instead of `packages/devkit/index.d.ts`.
### 13. Update `scripts/nx-release.ts`
Two things to do here:
1. **Add the package to `packagesToReset`.** That array (around `scripts/nx-release.ts:76`) is the snapshot/restore list — every package whose source `package.json` gets mutated by `nx release` (because it now publishes from `packages/<name>/` directly, not `dist/packages/<name>/`) must be in this list. Otherwise the release will leave `packages/<name>/package.json` dirty in the working tree after running. **Easy to forget — and there is no test that catches it.**
2. **Update any package-specific paths.** If the package has special release handling (like devkit's `hackFixForDevkitPeerDependencies`), update any paths from `./dist/packages/<name>/` to `./packages/<name>/`.
### 14. Update imports across the workspace
Search for imports from `@nx/<name>/src/` across all other packages. These internal imports need to be updated:
- If the imported thing is re-exported through a public entry point (index.ts, internal.ts, etc.), update the import to use that entry point
- If not, consider adding it to `internal.ts` or the appropriate entry point
Use: `grep -r "from '@nx/<name>/src/" packages/ --include="*.ts" -l` to find affected files.
Also check for imports in:
- `e2e/` tests
- `scripts/`
- `tools/workspace-plugin/`
- `astro-docs/`
- `examples/`
### 15. Audit `require('../../package.json')` (or similar relative paths to the package.json)
Search for `require\(['"]\.\..*package\.json` inside `packages/<name>/src/`. Any TS source file that reads the package's own `package.json` via a relative path is a **layout-fragility bug** that this migration triggers:
- Before migration: source `packages/<name>/src/utils/versions.ts` → built `dist/packages/<name>/src/utils/versions.js`. `'../../package.json'` resolves to `dist/packages/<name>/package.json` (which the old build path copied there).
- After migration: source unchanged → built `packages/<name>/dist/src/utils/versions.js`. `'../../package.json'` now resolves to `packages/<name>/dist/package.json` — **doesn't exist**. Every consumer that pulls in `nxVersion`/`NX_VERSION`/etc. crashes at module-load time with `Cannot find module '../../package.json'`. This breaks e2e tests broadly because most generators load `versions.ts`.
**Fix**: replace the relative path with a **package-name self-reference**, using the dynamic `join()` form so eslint's `@nx/enforce-module-boundaries` doesn't trip on it:
```ts
// Before
export const nxVersion = require('../../package.json').version;
// After
import { join } from 'path';
export const nxVersion = require(join('@nx/<name>', 'package.json')).version;
```
A literal `require('@nx/<name>/package.json')` works at runtime but trips `enforce-module-boundaries`'s `noSelfCircularDependencies` check — the rule statically pattern-matches self-imports and fires before checking whether the import resolves to a non-main entry. The dynamic `join()` form is opaque to the static check, matches `@nx/devkit`'s established pattern, and resolves to the same path at runtime.
Node resolves `@nx/<name>/package.json` via `node_modules` (workspace symlink in dev, real install in published), and the package.json's `exports` map already declares `./package.json` (you ensured this in Step 5). Works identically in source and dist contexts.
Reference implementations:
- `packages/nx/src/utils/versions.ts` — `require('nx/package.json').version` (works because `nx` is the project's own name; the static rule's entry-point check is lenient for the top-level `nx` package specifically)
- `packages/devkit/src/utils/package-json.ts` — `NX_VERSION = require(join('nx', 'package.json')).version` (dynamic form)
This was the source of the workspace-migration e2e regressions (PR #35643) and is one of the most-failure-prone steps to forget. Audit aggressively.
### 16. Preserve `add-extra-dependencies` if the package has one
`scripts/add-dependency-to-build.js` is a release-time hack that injects an extra dep into the **published** `package.json` (e.g., it adds `nx` to `@nx/workspace`'s `dependencies`). It is **not dead code** — without it the transitive resolution chain breaks for downstream consumers.
Concretely: created workspaces depend on `@nx/js`, which transitively depends on `@nx/workspace`. When the fork in `generate-preset.ts` runs `nx g @nx/workspace:preset`, Node's `require.resolve('@nx/workspace/package.json')` only finds the transitively-installed package because pnpm hoists `nx` along with `@nx/workspace` into `.pnpm/node_modules/` — and `nx` is hoisted there only because the **published** `@nx/workspace/package.json` declares it as a regular dependency. Drop that injection and the fork in the new workspace fails with `Unable to resolve @nx/workspace:preset` → `unable to find tsconfig.base.json`.
When migrating a package that has the `add-extra-dependencies` target:
1. **Keep** the target in `packages/<name>/project.json`.
2. **Update** `scripts/add-dependency-to-build.js`: change the `pkgPath` from `../dist/packages/<package>/package.json` to `../packages/<package>/package.json` (the source manifest is now the published manifest under the local-dist layout).
3. **Keep** the `pnpm nx run-many -t add-extra-dependencies --parallel 8` invocations in `scripts/nx-release.ts` (both the GitHub-release path and the local-publish path) — they fire between `runNxReleaseVersion` and `nx run nx:expand-deps`.
4. Confirm the snapshot/reset list (`packagesToReset`) covers this package so the injection is undone after publish.
If the package does not have the target, leave the script and the run-many calls alone — they no-op for any project without the target.
### 17. Verify
Run:
```bash
pnpm nx run-many -t test,build,lint -p <name>
```
Then:
```bash
pnpm nx affected -t build,test,lint
```
### Summary of the pattern
The core idea is simple: instead of building to a shared `dist/packages/<name>/` at the workspace root, each package builds to its own `packages/<name>/dist/`. The `exports` map with `@nx/nx-source` condition lets workspace packages resolve to `.ts` source files during development, while external consumers get the built `.js` from `dist/`. This is like giving each package its own "output mailbox" instead of sharing one big mailbox.
@@ -1,399 +0,0 @@
---
name: multi-version-compliance
description: >
Apply or review multi-version support compliance for first-party Nx
plugins. Primary entry point: a Linear task ID (NXC-XXXX) from the
"Multi-version supported across plugins" milestone — the task carries the
resolved support window, findings, and "Needs human decision" items. Falls
back to self-discovery when no task exists. Use when asked to "fix
multi-version compliance for @nx/X", "do NXC-XXXX", "review this
compliance PR", or when working on a branch / PR titled "multi-version
support compliance for @nx/X". Covers the canonical shape
(assertSupportedPackageVersion, all-generators-enforce-floor.spec.ts,
peer dep alignment, requires-gate auditing, user-pin preservation,
executor / inferred-plugin feature gating).
argument-hint: '[<NXC-XXXX> | @nx/<plugin> | review #<PR>]'
allowed-tools: Bash, Read, Edit, Write, Glob, Grep, Agent, mcp__linear-server__get_issue, mcp__linear-server__list_comments, mcp__linear-server__get_milestone, mcp__linear-server__list_issues
---
# Multi-version compliance for Nx plugins
## What this is
The `nx migrate --first-party-only` flag lets users upgrade Nx without
dragging the managed third-party ecosystems (Angular, Cypress, Playwright,
Jest, Vitest, ESLint, etc.) along. For that to be safe, every first-party
plugin must keep working across its declared support window — not silently
fall through to the latest install constants on older workspaces, not
silently break on newer ones.
**Source-of-truth split:**
| Source | Owns |
| ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| Linear milestone "Multi-version supported across plugins" (project NXC-4072) | What's wrong per plugin, the resolved support window, open human decisions. Per-plugin tasks NXC-4381..NXC-4410 (P1P29). |
| This skill | How to implement the canonical shape, code-level anti-patterns, gotchas, findings doc shape (no-task case). |
The skill is the gap-closer: it accepts a Linear task, parses it, drives
the fix. When no task exists for the plugin, fix mode runs discovery in
Phase 12 and produces a findings doc that mirrors a Linear task body —
so the user can file it as a new task before proceeding.
**Reference PRs (the canonical shape):**
- `#35587``@nx/angular` — merged. Set the precedent. Introduced
`throwForUnsupportedVersion`.
- `#35642``@nx/playwright` — merged. Generalized the shared helpers
into `@nx/devkit/internal`. Established executor / runtime feature-
gating.
- `#35670``@nx/cypress` — merged. Added `excludeGenerators` to the
parameterized test helper.
- `#35671``@nx/vitest` — open at time of writing. Demonstrates
"drop phantom peer-range claim" and "declared floor < effective floor"
patterns.
Before citing any PR by number, verify state — these go stale:
`gh pr view <N> --repo nrwl/nx --json state`. Verify any unmerged PR's
contents via `gh pr diff <N> --repo nrwl/nx`.
## Entry points
| Invocation | Mode | Behavior |
| ----------------------------------------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `multi-version-compliance <NXC-XXXX>` | Fix (primary) | Fetch task, surface findings + decisions in Phase 2, wait for user OK before Phase 3 edits. |
| `multi-version-compliance` (no arg) | Ask for task ID | Prompt for NXC-XXXX. |
| `multi-version-compliance @nx/<plugin>` (bare plugin) | Fix (task lookup) | Look up the per-plugin task in milestone NXC-4072. If found, confirm with user and enter fix mode. If not found, run discovery in Phase 12 (rubric against code), present findings, suggest filing as a new task before any edits. |
| `multi-version-compliance review #<N>` | Review | Fetch PR, derive Linear task from branch name if possible, compare diff vs. task findings (or run pure code-level review if no task). |
**Stop-after-Phase-2 (audit-equivalent):** if you want findings without
edits, decline to approve at the end of Phase 2. The skill stops, no
branch, no commits.
**On a branch matching `nxc-NNNN` with no explicit arg:** before
asking the user, suggest "Use NXC-NNNN?" inferred from the branch name.
## Linear-fetching protocol
Before any code-level work in Linear-driven mode, the skill MUST:
1. **Check Linear MCP availability.** If `mcp__linear-server__get_issue`
isn't available (MCP server not installed / not connected), tell the
user and fall through to the no-task discovery path (fix mode Phase 1
step 2). Don't pretend to fetch.
2. **Fetch the task.** `mcp__linear-server__get_issue id="NXC-XXXX"`.
If the call errors (invalid ID, network), halt and ask the user to
verify the ID.
3. **Verify shape.** Confirm:
- Title matches `[multi-version][P##] \`@nx/<plugin>\` — multi-version support compliance`(per-plugin) or`[multi-version][W#] ...` (cross-cutting). If the pattern doesn't match, halt and ask the user to confirm this is the right task.
- Status. `Done` → ask whether re-audit or follow-up. `Canceled` → halt and ask.
4. **Read description sections.** Every per-plugin task has:
- **Plugin:** — path, upstream support, peerDep declarations, per-major install map, paired secondaries.
- **Needs human decision** — open items blocking implementation.
- **Findings** — `(high|medium|low)` items with `[file:line]` and a suggested fix per item.
- **Verification checklist** — Sections A (Support window declarations) / B (Generator inputs) / C (Generator outputs) / D (Migrations) / E (Runtime) / F (Out-of-window UX).
5. **Fetch comments.** `mcp__linear-server__list_comments issueId="..."`.
Audits attached as files / linked uploads may carry additional
context.
6. **Surface "Needs human decision" as a batch.** Restate every decision
item in chat. The user can resolve all, defer some, or override.
Block until the user has acknowledged the set — don't proceed silently.
7. **Translate findings → code changes.** Map each finding to a canonical
pattern in `references/canonical-shape.md`. The Linear task's
suggested fix is the authoritative scope; the skill verifies it
conforms to the canonical shape and flags any deviation.
8. **Run the AF checklist** against the final code state. The task's
checklist is the agreed scope. The skill verifies code-level
conformance.
**Default to the task's resolved support window.** Don't re-derive it
from code unless the user explicitly overrides. If the user overrides:
restate the new window and confirm before applying.
**Don't expand scope beyond the task's Findings without asking.** If you
spot a new issue mid-fix: stop, present it, ask whether to (a) add it to
this PR, (b) defer as a follow-up, or (c) update the Linear task as a
comment.
## Mode workflows
### Fix mode (primary)
**Phase 1 — Read.**
1. If a Linear task ID was provided, fetch it per the Linear-fetching
protocol. If only a plugin name was provided, look up the per-plugin
task in milestone NXC-4072.
2. **No task case.** If no task exists for this plugin: run discovery
instead — apply the policy ladder for the support window
(Rule 1: upstream LTS for Angular/React/ESLint/Next/Expo; Rule 2:
N & N-1; widen to existing supported set if larger), inventory the
plugin's code against the AF rubric, find the effective floor by
walking imports, classify all results as new findings. The skill is
producing audit-quality output for a plugin that wasn't ticketed.
3. If on a branch matching `nxc-NNNN`, read recent commits to understand
prior scope decisions.
4. Read `references/canonical-shape.md` and `references/anti-patterns.md`.
**Phase 2 — Align.**
5. **(task case)** Surface every "Needs human decision" item from the
task as a batch. Wait for resolutions.
6. **(task case)** Restate the Findings list with severity tags. Confirm
scope.
7. **(no-task case)** Surface findings discovered from the rubric
inventory + decisions the rubric surfaces (floor raise/drop, peer
declarations, optional-vs-required peer, one-sided gates, etc.).
Suggest filing them as a new Linear task in milestone NXC-4072
before proceeding to Phase 3.
8. **User OK gate.** Wait for explicit "proceed" before Phase 3.
Declining stops the skill — no branch, no edits. (This is the
audit-equivalent.)
**Phase 3 — Implement** (per `canonical-shape.md`).
9. Branch from `master` if needed using the repo's `nxc-NNNN` convention.
10. Order: any shared-helper extension lands first; plugin changes land
after. Commit/PR titling defers to the user's conventions.
11. For each Finding category, apply the canonical pattern:
- Section A → peer ranges + version map + install constants. Every
third-party package the plugin **invokes at runtime** (TS import,
executor spawning the CLI binary, or inferred-plugin emitting a
target with `command: '<bin>'`) gets a peer entry. Default to
`optional: true` via `peerDependenciesMeta` for gated surfaces
(executor opt-in, inferred plugin gated on config file presence).
Non-optional peers are reserved for packages every workspace using
the plugin needs.
- Section B → generator entry asserts, `keepExistingVersions`,
fresh-install branch.
- Section C → templates, schema stubs with runtime throws,
version-map coverage.
- Section D → `requires` gates per package per AND-semantics; split
mixed entries; retain intentional pre-floor entries. **Default to
bilateral bounds** (`>=N <M`) when writing a cross-major gate.
One-sided gates (`<N` with no lower, `>=N` with no upper) need a
justified reason (legacy cleanup, undefined source, v0→v1 bridge)
— record the reason in the findings doc or as a code comment.
- Section E → executor and inferred-plugin feature gates.
- Section F → below-floor throw via shared util.
- **Cross-cutting:** if the fix changes runtime behavior, update any
in-codebase docs (`astro-docs/`, `docs/`, inline `.md`) that
describe the changed behavior. Docs that contradict the code are a
correctness bug, not a PR-body concern.
12. If during implementation you spot something not in the task's
Findings: stop, surface it, ask whether to (a) add to this PR, (b)
defer as a follow-up, or (c) update the Linear task as a comment.
**Phase 4 — Tests** (same commit as Phase 3 usually).
13. Add `all-generators-enforce-floor.spec.ts` — parameterized via
`assertGeneratorsEnforceVersionFloor`. This exercises every
generator's floor assert and is the high-value spec.
14. Footgun: assert calls must be in place in every generator BEFORE
running the parameterized spec, or every untouched generator fails
and you'll restart.
15. Optional: a per-plugin `assert-supported-<pkg>-version.spec.ts`
with the 5 canonical cases. The shared `assertSupportedPackageVersion`
already has full coverage in devkit, so this is mostly symmetry
across the PR series — skip unless the user asks.
**Phase 5 — Verify locally.**
16. `npx nx test <plugin> --testPathPattern="all-generators-enforce-floor"`
(add `assert-supported-` if you added the optional wrapper spec).
17. `npx nx test <plugin> --testPathPattern="<modified-generator>"` per
touched generator.
18. `npx nx format`.
**Phase 6 — Hand off.** Code changes complete. The user drives
commit/push/PR per their own conventions (loaded globally from
`~/.claude/memory/workflow/git/`). This skill does not enforce PR title,
body, commit shape, or related-issues format.
### Review mode
1. **Fetch PR.** `gh pr view <N> --repo nrwl/nx` and
`gh pr diff <N> --repo nrwl/nx`. For a local branch:
`git diff master...HEAD`.
2. **Derive the Linear task.** Branch name `nxc-NNNN``NXC-NNNN`. If
no match: ask the user.
3. **Fetch the task** (if derivable). Compare diff vs. task Findings:
every Finding addressed; nothing extra without justification. Flag
scope drift.
**If no task and the user has none:** skip task-comparison; run pure
code-level review against `canonical-shape.md` and `anti-patterns.md`.
4. **Code-level checks.** Run the "Code-level verification (review-mode
lens)" section of `canonical-shape.md`. Cross-reference
`anti-patterns.md`. For each finding, anchor at `file:line` and cite
which reference PR / file demonstrates the correct pattern.
**Scope:** code, configs, migrations, and in-codebase docs that claim
runtime behavior. NOT PR title / body / commit shape — those defer to
the user's PR conventions.
5. **Classify each finding.**
- **Only two inline categories:** `[blocker]` and `[non-blocker]`. No
"open question," "ask," or other inline tags. Questions for the
author surface in the closing "Open questions for author" block,
drawn from non-blocker findings — list each question once.
- **Severity is independent of scope-drift.** A finding can be both a
blocker AND not in the Linear task. Flag it as a blocker in the
code-level section AND list it under "in PR but not in Linear task"
in scope drift. Don't hedge with "in this PR or follow-up?" — if
it's a blocker, the answer is "this PR."
- **Group related non-blockers.** When multiple non-blockers describe
symptoms of one blocker (e.g., five symptoms of a single
`version-utils.ts` duplication), list them as sub-bullets under
the blocker with "(resolved when §X is fixed)" rather than as N
separate top-level non-blockers.
- **Be terse on passes.** A section with no findings gets a single
summary line ("Pass — all 7 generator entries assert at first
statement"), not a per-file enumeration. Detail is reserved for
blockers and non-blockers. The reviewer's audience skims for
actionable items; passing checks should not eat reading budget.
6. **Output.** Markdown checklist of blockers / non-blockers anchored at
`file:line`, followed by the structured verdict block from
`canonical-shape.md` §"Verdict template". The verdict block is the
skimmable index — produce it, don't substitute a free-form prose
summary. Do not post via `gh pr review` unless the user explicitly
asks.
## Which references to load (context hygiene)
| Mode | Required | Optional |
| ---------------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Fix | `canonical-shape.md`, `anti-patterns.md` | `gotchas.md` (effective floor, ecosystem lockstep, cypress inline tree), `examples.md` (when copying a pattern) |
| Review | `anti-patterns.md`, `canonical-shape.md` (especially the "Code-level verification" section) | `gotchas.md` (cross-plugin coordination, lockstep), `examples.md` (when citing) |
| "What is compliance?" answer | none | answer from SKILL.md alone |
References are ~100500 lines each. Don't pull all of them just because
you're invoked. Match the load to the mode.
## Critical rules (apply in every mode)
1. **Linear task is the source of truth for scope** (ratified decisions
and Findings).
- (a) Don't produce a parallel scope document. The task IS the scope.
Fix mode runs against the task as input — drift checks, new
findings, and decisions feed back to the task (via comments or as
deferred items), not into a competing source of truth.
- (b) Don't expand a fix beyond the task's Findings without
surfacing the new issue.
- (c) Don't second-guess the task's resolved support window without
an explicit user override.
2. **Do not create or duplicate shared helpers.** They live in
`@nx/devkit/internal` (`assertSupportedPackageVersion`,
`getInstalledPackageVersion`, `getDeclaredPackageVersion`,
`throwForUnsupportedVersion`, `normalizeSemver`, `isNonSemverDistTag`)
and `@nx/devkit/internal-testing-utils`
(`assertGeneratorsEnforceVersionFloor`). Reject any local
re-implementation (`cleanVersion`, `getInstalled<Pkg>VersionRuntime`,
private `throwBelowFloor`, etc.). See `canonical-shape.md`.
3. **Above-ceiling is silent fallthrough.** Do not warn, do not throw,
do not branch. Reject `throwAboveWindow`, `warnAboveCeiling`,
`versions()` with `switch + throw default:`. The only throw is below
the declared floor.
4. **`keepExistingVersions: true` is for generators only.** Migration
generators (`src/migrations/`) are exempt — their job is to bump.
Do not flag missing flags in migration code.
5. **Floor assert is the first statement in the function doing the
actual work.** Wrapper/internal split (cypress, playwright): in
`*Internal`. Single-function generators (angular): in the function
itself. Not conditional, not inside an install branch, not after a
tree read.
6. **Phase 12 never writes, never branches.** Discovery, finding
classification, and decision-surfacing happen on the current branch
with no edits. Any working artifact (e.g., a findings doc for a
no-task case, multi-plugin scratch notes) goes in `tmp/` (gitignored)
and stays uncommitted. No `TRIAGE-REPORT.md` / `AUDIT.md` at repo
root. Branch creation and edits start at Phase 3, after the user OK.
7. **PR / commit conventions are out of scope.** Title format, body shape,
commit-message structure, related-issues handling, push flags, etc.
are governed by the user's global memory (`pr-creation-shorthand.md`,
`push-conventions.md`, `explain-before-committing.md`,
`chore-not-fix-non-prod.md`). Don't enforce or flag these from this
skill — defer to whatever the user's conventions resolve to at PR time.
## Findings doc template (Phase 2 output, used when no Linear task exists)
When fix mode hits the no-task case (Phase 1 step 2), produce
`tmp/<plugin>-findings.md` shaped to mirror a Linear task body so the
user can file it as a new task in milestone NXC-4072 before proceeding
to Phase 3.
For plugins managing multiple primary packages, repeat the install-map
/ decisions / findings bullets per primary.
```md
# @nx/<plugin> — multi-version support compliance findings
> No Linear task in milestone NXC-4072. This doc is filing-ready —
> create the task with this body before proceeding to fix.
## Plugin
- Path: packages/<plugin>
- Upstream support: <official policy if any, else "no formal LTS">
- peerDep declarations: <list>
- Per-major install (`<file>` branches on installed `<package>` major):
- v<N-1>: <constants>
- v<N>: <constants> (default)
- Paired secondaries: <list of ecosystem-locked siblings>
## Needs human decision
1. <decision 1 — e.g., raise floor to vN.0.0 vs keep current>
2. <decision 2 — e.g., drop ^1.0.0 from peer (no v1 install lane)>
## Findings
- **(high) <one-line summary>** [file:line]
_Suggested fix_: <one-line>
- **(medium) ...**
- **(low) ...**
## Verification checklist (AF)
### A. Support window declarations
- [ ] peerDep ranges match the support window
- [ ] Version map / runtime branching covers every supported major
- [ ] Every third-party package the plugin **invokes at runtime** has a peerDep entry. "Invokes" = TS import/`require` OR executor spawns its CLI binary OR inferred plugin emits a target whose `command` invokes its CLI (look for `externalDependencies: ['<pkg>']` in emitted target inputs). Packages the generator installs for the user to consume independently (ESLint plugins loaded by the user's eslintrc, `@types/*`) don't need peer-declaration.
- [ ] Peers needed only when a user opts into a specific surface (executor opt-in, inferred plugin gated on config file presence, opt-in preset) are declared **optional** via `peerDependenciesMeta: { "<pkg>": { "optional": true } }`. Required-non-optional peers are reserved for packages every workspace using the plugin needs.
### B. Generator inputs
- [ ] Generators don't overwrite installed third-party versions
- [ ] `addDependenciesToPackageJson` passes `keepExistingVersions=true` or branches on detected version
- [ ] Fresh-install path installs the latest supported version
### C. Generator outputs
- [ ] Templates compile and run on every supported version
- [ ] Generated `project.json` target shape valid on every major
- [ ] Default option values valid on every major
- [ ] Version map covers every managed third-party dep — no gaps
- [ ] Schema accepts union of options; runtime throws when inapplicable
### D. Migrations (migrations.json + packageJsonUpdates)
- [ ] Cross-major `packageJsonUpdates` declare `requires` per bumped package
- [ ] `requires` ranges are bilateral (`>=N <M`) by default. One-sided ranges (`<N` with no lower, `>=N` with no upper) are intentional (legacy cleanup, undefined source major, v0→v1 bridge) — flagged in "Needs human decision" or noted in the Findings.
- [ ] Every migration declares `requires` against the touched package
- [ ] Nx-only migrations have no third-party `requires`
- [ ] No silent gap in `packageJsonUpdates` across the support window
### E. Runtime
- [ ] Executors branch on installed version where behavior diverges
- [ ] Inferred plugin (createNodes/V2) parses configs across every major
### F. Out-of-window UX
- [ ] Below-floor: throws via shared util naming package + installed + floor; no silent fall-through
## Out-of-scope (deferred follow-ups)
- <e.g., consolidate ... across plugins — separate PR>
```
## References
See "Which references to load" near the top. Don't pull all of them.
@@ -1,315 +0,0 @@
# Anti-patterns
Patterns to reject in your own work and flag in reviews. Each entry: what it looks like, why it's wrong, what to do instead, and a reference.
## 1. Local re-implementation of the shared helpers
**Looks like:** A new file in the plugin defining any of:
- `throwBelowFloor` / `throwAboveWindow` / `assertVersion` / `checkMinimumVersion` — duplicates `throwForUnsupportedVersion` / `assertSupportedPackageVersion`.
- `function cleanVersion(v) { return clean(v) ?? coerce(v)?.version ?? undefined; }` — duplicates `normalizeSemver`.
- `getInstalledRsbuildVersionRuntime` / `getInstalled<X>FromFs` reading `require('<pkg>/package.json')` directly — duplicates `getInstalledPackageVersion`.
- Inline `clean(declared) ?? coerce(declared)` chain at a generator entry point — duplicates `getDeclaredPackageVersion`.
**Why wrong:** The shared helpers in `@nx/devkit/internal` and `@nx/devkit/internal-testing-utils` already exist. Duplicates create drift — one will get the `latest`/`next` handling, the other won't; one will use `getNxRequirePaths()` for pnpm-strict resolution, the other won't.
**Do instead:** Call `assertSupportedPackageVersion(tree, pkg, floor)` via the per-plugin wrapper (`assertSupportedXVersion`). For executor-side reads: `getInstalledPackageVersion(pkg)`. For tree-side normalization: `getDeclaredPackageVersion(tree, pkg, latestKnown)`. For raw semver cleaning: `normalizeSemver(v)`.
**Reference:** Compliant — `packages/cypress/src/utils/assert-supported-cypress-version.ts` (7 lines). Concrete anti-pattern — PR `#35676` introduces `function cleanVersion` (`packages/rsbuild/src/utils/versions.ts`) and `getInstalledRsbuildVersionRuntime` reading `require('@rsbuild/core/package.json')`. Both should call the shared helpers instead.
## 2. Above-ceiling throw or warn
**Looks like:** `if (major > maxKnown) throw …`, `if (major > maxKnown) logger.warn …`, `versions()` with a `switch + throw default:`, any `warnAboveCeiling` / `throwAboveWindow` helper.
**Why wrong:** Explicit policy. Above-ceiling falls through silently to `latestVersions`. Throwing breaks users on newer versions of third-party packages, which is the opposite of the initiative's intent. The angular reference implementation does not warn or branch above the highest known major, and every subsequent plugin compliance PR follows that convention.
**Do instead:** `versionMap[major] ?? latestVersions`. Below-floor is caught by the generator-level assert; the `versions()` function is just a lookup.
**Reference:** Compliant — `packages/cypress/src/utils/versions.ts` after `#35670` rewrite. Anti-pattern (before fix) — same file before `#35670` had `switch + throw default:`.
## 3. Hardcoded third-party version in generator body
**Looks like:**
```ts
addDependenciesToPackageJson(tree, {}, { rspack: '^1.1.10' });
```
in a generator.
**Why wrong:** Bypasses the `versions(tree)` routing and the install-lane logic. New majors will not be picked up; older workspaces get the wrong version.
**Do instead:** Route through `versions(tree)` and reference the per-major entry. If you genuinely have a version that's the same across all majors, still put it in the map for consistency.
## 4. Init generator overwriting pinned versions
**Looks like:** `addDependenciesToPackageJson(tree, …, …, undefined, options.keepExistingVersions)` where the schema default is `false`. Or no fifth argument at all (defaults to `false`).
**Known-incomplete reference:** `@nx/angular`'s `init/schema.json` currently has `default: false` and `init.ts` passes `options.keepExistingVersions` directly — PR `#35587` did not fix this. The angular init generator therefore still has this bug. Flagging it in a non-angular compliance PR is correct; fixing it in passing during another angular PR is also appropriate.
**Why wrong:** Generators bump packages = the user's pinned version is silently overwritten on re-run. Bumping is the job of migrations, not generators.
**Do instead:** Pass `keepExistingVersions: true` (positional 5th arg) or `options.keepExistingVersions ?? true`. Flip the schema default to `true`.
**Reference:** Compliant — `packages/cypress/src/generators/init/init.ts` and `init/schema.json` after `#35670`. Anti-pattern — the same files before `#35670` had schema default `false`.
## 5. `requires` gate on an Nx-only migration
**Looks like:**
```json
{
"update-unit-test-runner-option": {
"requires": { "@angular/core": ">=21.0.0" },
"description": "Update 'vitest' unit test runner option to 'vitest-analog' in generator defaults."
}
}
```
when the migration only writes to `nx.json`.
**Why wrong:** The migration applies regardless of third-party version — it's rewriting an Nx-owned generator default. The gate causes pre-v21 workspaces with the stale default to silently skip the migration and stay broken.
**Do instead:** Remove the `requires` entry entirely. Nx-only migrations have no third-party gate.
**Reference:** Anti-pattern (before fix) — `packages/angular/migrations.json` `update-unit-test-runner-option`. Fix — `#35587` removed the gate.
## 6. Cross-major `packageJsonUpdates` with no `requires`
**Looks like:**
```json
{
"21.3.0": {
"packages": {
"jest": { "version": "^30.0.0" }
}
}
}
```
with no `requires` gate, when this is a v29 → v30 bump.
**Why wrong:** The bump fires for every workspace — including workspaces already on v30 (idempotent best case) or workspaces on v28 or below (which would silently land on v30 without going through any v29 → v30 codemods). Source-major gate ensures the bump only fires for workspaces actually in the source range.
**Do instead:**
```json
{
"21.3.0": {
"requires": { "jest": ">=29.0.0 <30.0.0" },
"packages": { "jest": { "version": "^30.0.0" } }
}
}
```
**Reference:** Compliant — `packages/angular/migrations.json` MF entries after `#35587`. Anti-pattern examples on master at time of writing — `@nx/jest` `21.3.0`, `@nx/eslint` `20.7.0`, `@nx/vite` `20.5.0` (verify by inspecting each plugin's `migrations.json` for cross-major `packageJsonUpdates` entries lacking `requires`).
## 7. Gating ecosystem-locked siblings on the primary's major alone
**Looks like:** A migration that bumps `@ngrx/store` from v18 to v19 with `requires: { "@angular/core": ">=19.0.0" }` only — no `@ngrx/store` entry.
**Why wrong:** `@ngrx/store` is independent of `@angular/core` versioning. A workspace can be on `@angular/core: 19` without having `@ngrx/store: 18` (might not use ngrx at all, or might be on v17). Gating on `@angular/core` fires the migration in workspaces where it has nothing to do.
**Do instead:** Add the sibling to `requires`: `{ "@angular/core": ">=19.0.0", "@ngrx/store": ">=18.0.0 <19.0.0" }`. For Angular ecosystem siblings: `@angular/cli`, `@angular/ssr`, `@angular-devkit/build-angular` (v20+) are peer-locked via `@angular/core` and don't need their own gate. `@ngrx/*`, `@angular-eslint/*`, `zone.js`, `jest-preset-angular` are independent and do.
**How to verify pairing:** read the sibling package's `peerDependencies` at the version range being bumped from. If it pins the primary's major, the primary's `requires` covers it. If it doesn't, the sibling is independent and needs its own gate.
## 8. Peer dep claiming a major with no install branch (phantom claim)
**Looks like:**
```json
{
"peerDependencies": {
"vitest": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0"
}
}
```
when `versions.ts` has no v1 entry and no `isVitestV1` branch anywhere.
**Why wrong:** The plugin advertises support for a version it doesn't honor. v1 workspaces silently fall through to v4 install constants.
**Do instead:** Drop the unsupported major from the peer. `vitest: "^2.0.0 || ^3.0.0 || ^4.0.0"`. If the support is desired, add the install lane.
**Reference:** Pattern demonstrated in open PR `#35671` (`@nx/vitest`) — drops `^1.0.0` from the `vitest` peer because there's no v1 install lane in the plugin's `versions.ts`. Inspect via `gh pr diff 35671 --repo nrwl/nx -- packages/vitest/package.json`. Verify state first.
**Related — drop EOL major (different reasoning, same action):** the major HAS an install lane but is EOL upstream (e.g., Storybook's official policy is "top 3 majors only"; v7 is EOL). Drop it from the peer because it's upstream-unsupported, not because the plugin doesn't honor it. Concrete example: NXC-4406 calls out dropping Storybook v7 from `@nx/storybook`'s peer per Storybook's top-3-majors policy.
## 8a. PeerDep range wider than the runtime dep pin
**Looks like:**
```json
{
"peerDependencies": {
"@typescript-eslint/parser": "^6.0.0 || ^7.0.0 || ^8.0.0"
},
"dependencies": {
"@typescript-eslint/parser": "^8.0.0"
}
}
```
The plugin's own runtime dep pins ^8, but the peer claims ^6/^7/^8.
**Why wrong:** Distinct from §8 — here the install lane exists (in `dependencies`), but the lane only ships one major. The peer is over-promising relative to what the plugin actually runs against. A workspace on ^6 will satisfy the peer but won't get a compatible runtime once `@typescript-eslint/parser@^8` resolves.
**Do instead:** Tighten the peer to the actually-supported runtime range, or widen the runtime dep + add the install/branch lanes for the additional majors.
**Reference:** NXC-4388 (`@nx/eslint-plugin`).
## 9. Top-level `require()` of an optional peer in an executor
**Looks like:**
```ts
// at the top of executor.impl.ts
const cypress = require('cypress');
```
**Why wrong:** When cypress is absent (not yet installed, peer mismatch, etc.), the executor throws `MODULE_NOT_FOUND` at module load time, before any user-friendly error. Especially bad for deprecated executors that should fail with a deprecation message.
**Do instead:** `require` inside the function body, after the version detection / clear error.
## 10. Anything-but-`requires` as substitute for `requires`
**Looks like (variant A — `incompatibleWith` standing in):**
```json
{
"21.0.0-source-bump": {
"incompatibleWith": { "@angular-devkit/build-angular": "<21.0.0" },
"packages": { "...": { "version": "..." } }
}
}
```
to "gate" a bump to v21+ source workspaces.
**Looks like (variant B — runtime per-package guard):**
```ts
// inside the migration function body
const installed = getInstalledVersion('@typescript-eslint/parser');
if (gte(installed, '8.0.0') && lt(installed, '8.13.0')) {
// run the migration
}
return; // otherwise skip
```
with no `requires` block on the migration entry in `migrations.json`.
**Why wrong:** Neither approach is a source-major gate.
- `incompatibleWith` blocks running on workspaces that have the matching version — it doesn't gate to a source-major range. A workspace on `@angular-devkit/build-angular: 22.0.0` will still pass the `incompatibleWith` check.
- A runtime per-package guard runs the migration _body_ on every workspace and skips internally. The migration record still appears as "executed" to the migrate runner, and any side effects (logging, partial work) leak. The `nx migrate` runner uses `requires` as the source-major filter; bypassing it means the migration isn't filtered at the right layer.
**Do instead:** `requires: { "<pkg>": ">=N.0.0 <(N+1).0.0" }` — the actual source-major gate at the migration-entry level. Drop the in-body guard once the `requires` is in place.
**Reference:** Anti-pattern (variant B) — `@nx/eslint` `update-typescript-eslint-v8.13.0` (NXC-4387) has runtime `gte('8.0.0') + lt('8.13.0')` per-package guards but no `requires` block. `@nx/jest` similar with `incompatibleWith` (NXC-4391).
## 11. Naming a specific plugin in shared helper docstrings
**Looks like:** A JSDoc in `assert-generators-enforce-version-floor.ts` referencing `migrate-to-cypress-11` as the example use case for `excludeGenerators`.
**Why wrong:** The helper is shared across plugins. Naming one plugin in its docstring is leaky.
**Do instead:** Generic phrasing — "generators that must run below the floor by design (e.g., migrators that lift sub-floor workspaces onto a supported version)".
**Reference:** an early draft of `#35670`'s test helper had the plugin-specific JSDoc; the merged version uses generic phrasing.
## 12. Both schema `"default": true` AND `options.keepExistingVersions ?? true`
**Looks like:**
```json
{ "keepExistingVersions": { "default": true } }
```
combined with
```ts
addDependenciesToPackageJson(tree, , , undefined, options.keepExistingVersions ?? true);
```
**Why wrong:** Two sources of truth. Either the schema default does the job (and `options.keepExistingVersions` will always be `true`) or the `?? true` fallback handles it (and the schema default is redundant).
**Do instead:** Pick one. Schema default is sufficient when the call site uses `options.keepExistingVersions` directly. The `?? true` fallback is only needed if the schema can be bypassed (programmatic invocation without schema validation).
## 13. Manual `RegExp` matching in tests instead of substring `toThrow`
**Looks like:**
```ts
.rejects.toThrow(new RegExp(`Unsupported version of \\\`${packageName}\\\` detected`));
```
**Why wrong:** Escape bugs. The backtick and the `${}` are easy to get wrong. The shared helper uses substring matching for a reason.
**Do instead:**
```ts
.rejects.toThrow(`Unsupported version of \`${packageName}\` detected`);
```
**Reference:** see how `assertGeneratorsEnforceVersionFloor` itself does the match in `packages/nx/src/internal-testing-utils/assert-generators-enforce-version-floor.ts` (grep for `Unsupported version of`).
## 14. Validating only at install sites instead of generator entry
**Looks like:** A `if (installedVersion < floor) throw …` check guarding only the `addDependenciesToPackageJson` call inside a generator, while the rest of the generator runs unconditionally.
**Why wrong:** The generator may write configuration or templates incompatible with the sub-floor third-party version before reaching the install branch. The assert must be at the entry point so nothing else runs.
**Do instead:** `assertSupportedXVersion(tree)` as the first statement in the generator's working function (`*Internal` for plugins with the wrapper/internal split; the function itself for single-function generators). The install branch can then assume the floor is met.
## 15. Per-major version aliases alongside the bundle map
**Looks like:**
```ts
export const vitestV4Version = '~4.1.0';
export const vitestV3Version = '^3.0.0';
export const vitestV2Version = '^2.1.8';
export const vitestVersion = vitestV4Version;
export const vitestV4CoverageV8Version = '~4.1.0';
export const vitestV3CoverageV8Version = '^3.0.5';
// ...etc
const versionMap = {
3: { vitestVersion: '^3.0.0', vitestCoverageV8Version: '^3.0.5' },
4: { vitestVersion: '~4.1.0', vitestCoverageV8Version: '~4.1.0' },
};
```
**Why wrong:** The aliases (`vitestV3Version`, `vitestV3CoverageV8Version`, etc.) duplicate the `versionMap` entries. They drift over time — someone bumps the map but forgets the alias (or vice versa), and the plugin starts installing one version via generators and another via tests/runtime. Also: every dropped major (e.g., when raising the floor) becomes three or four delete lines instead of one map entry.
**Do instead:** Keep the bundle pattern — the per-major `versionMap` is the only place those values live. Stable (cross-version-identical) deps stay as top-level `export const`s; varying deps are accessed via `versions(tree).<key>` or directly from the top-level `latestVersions` bundle.
**Reference:** Open PR `#35671` initially carried `vitestV2Version` / `vitestV3Version` / `vitestV4Version` aliases. A follow-up commit (`chore(testing): adopt cypress version-resolution pattern in @nx/vitest`) dropped them in favor of the bundle pattern. Inspect via `gh pr view 35671 --repo nrwl/nx --json commits`.
## 16. Declared floor below the effective floor
**Looks like:** `peerDependencies` lists `"vitest": "^2.0.0 || ^3.0.0 || ^4.0.0"` and `versions.ts` has a `versionMap` entry for `2`, but somewhere in the plugin's executor / runtime / plugin code there's an import of a third-party API that only exists in v3+:
```ts
// In a runtime helper used by the executor:
import { getRelevantTestSpecifications } from 'vitest/node';
// ^ This API only exists in vitest >= 3.0.0.
```
**Why wrong:** A workspace on v2 will pass the floor assert (peer + versionMap claim support), then crash at runtime with `getRelevantTestSpecifications is not a function`. The peer is lying.
**Do instead:** Raise the floor to the lowest major where every called third-party API exists. Drop the now-unsupported entries from `versionMap`, `peerDependencies`, and the per-major version aliases (if any). The `assert-supported-<pkg>-version.spec.ts` sub-floor test now covers the dropped major.
**Reference:** Open PR `#35671`'s second commit (`fix(testing): drop vitest v2 support from @nx/vitest`) — originally proposed a v2 floor matching the lowest install lane, then raised to v3 after audit caught the `getRelevantTestSpecifications` usage. Inspect via `gh pr view 35671 --repo nrwl/nx --json commits`.
## 17. Creating a branch during Phase 12 (discovery / read-only)
**Looks like:** `git checkout -b <some-branch>` before the user has approved Phase 3 edits.
**Why wrong:** Phase 12 produces findings, not commits. Creating a branch creates pressure to commit something. Any working artifact (e.g., `tmp/<plugin>-findings.md` for the no-task case) goes in `tmp/` (gitignored) — for the user to read and scope from, not to commit.
**Do instead:** Run Phase 12 on the current branch (typically `master`). Output to `tmp/<plugin>-findings.md` if you wrote one. Branch creation belongs in Phase 3, after explicit user approval to proceed with edits.
@@ -1,646 +0,0 @@
# Canonical shape
What a compliant plugin looks like. Don't deviate without a documented reason.
The first half of this file ("How to write") describes the canonical structure
you produce in fix mode. The tail section ("Code-level verification") is the
review-mode lens — markers to look for in a diff.
## Shared helpers (already merged — use, don't duplicate)
### `@nx/devkit/internal`
Source: `packages/devkit/src/utils/version-floor.ts` and `packages/devkit/src/utils/installed-version.ts`.
```ts
// version-floor.ts
function throwForUnsupportedVersion(
packageName: string,
installedVersion: string,
floor: string
): never;
function assertSupportedPackageVersion(
tree: Tree,
packageName: string,
minSupportedVersion: string
): void;
```
```ts
// installed-version.ts
function getInstalledPackageVersion(packageName: string): string | null;
function getDeclaredPackageVersion(
tree: Tree,
packageName: string,
latestKnownVersion?: string
): string | null;
const NON_SEMVER_DIST_TAGS = ['latest', 'next'] as const;
function isNonSemverDistTag(version: string): version is NonSemverDistTag;
function normalizeSemver(version: string): string | null;
```
When to use which:
| Context | Function |
| -------------------------------- | ----------------------------------------------------------------------------------- |
| Generator entry (assert floor) | `assertSupportedPackageVersion(tree, pkg, floor)` |
| Generator-time version branching | `getDeclaredPackageVersion(tree, pkg, latestKnownVersion)` |
| Executor / runtime / preset | `getInstalledPackageVersion(pkg)` |
| Anywhere | `isNonSemverDistTag`, `normalizeSemver` |
| Never | `throwForUnsupportedVersion` directly — it's an implementation detail of the assert |
### `@nx/devkit/internal-testing-utils`
Source: `packages/nx/src/internal-testing-utils/assert-generators-enforce-version-floor.ts`.
```ts
function assertGeneratorsEnforceVersionFloor(options: {
packageRoot: string;
packageName: string;
subFloorVersion: string;
excludeGenerators?: string[];
}): void;
```
Behavior: reads `generators.json` from `packageRoot`, iterates every entry, loads its factory, calls it against a tree with `{ [packageName]: subFloorVersion }` in `package.json`, expects a throw matching `Unsupported version of \`${packageName}\` detected`.
`excludeGenerators` is only for intentional sub-floor migrators (e.g., `migrate-to-cypress-11`). Comment the reason next to the array.
## Finding the existing floor (audit input)
When auditing a plugin you haven't touched before, the floor may not be declared in one place. Check, in order of authority:
1. **`minSupported<Pkg>Version` constant in `versions.ts`** — if it exists, that's the declared floor.
2. **`peerDependencies` lowest range in `package.json`** — what the plugin advertises supporting.
3. **Lowest major in `versionMap` / `backwardCompatibleVersions` / `supportedVersions`** — what the plugin has install lanes for.
4. **Lowest `packageJsonUpdates` entry that touches the third-party package** — historical evidence of the supported range.
5. **Highest API requirement in the plugin's own code (the _effective_ floor).** Grep for every `import` / `require` from the third-party package and identify which APIs are called. Cross-reference each against the third-party's changelog. The plugin's effective floor is the lowest major where **all** called APIs exist. **This trumps the declared floor** — if `versions.ts` claims v2 but the plugin imports an API only available in v3+, the declared floor is wrong.
These should agree. When they don't, the disagreement is the finding (phantom peer claim, drifted versionMap, declared floor below effective floor).
**Worked example:** During open PR `#35671`, the audit initially landed on a `v2.0.0` floor (matching the lowest install lane). Then a follow-up commit dropped the floor to `v3.0.0` after noticing the plugin's atomization code calls `getRelevantTestSpecifications`, which is a vitest v3+ API. Lesson: step 5 above is not optional. Always check what APIs the plugin's own runtime code uses — `versions()` having a v2 lane doesn't mean the plugin actually works on v2.
## The plugin wrapper (one per plugin)
Path: `packages/<plugin>/src/utils/assert-supported-<pkg>-version.ts`.
Two canonical shapes:
### Single-major floor (most plugins)
```ts
import { type Tree } from '@nx/devkit';
import { assertSupportedPackageVersion } from '@nx/devkit/internal';
import { minSupportedCypressVersion } from './versions';
export function assertSupportedCypressVersion(tree: Tree): void {
assertSupportedPackageVersion(tree, 'cypress', minSupportedCypressVersion);
}
```
Reference: `packages/cypress/src/utils/assert-supported-cypress-version.ts`, `packages/playwright/src/utils/assert-supported-playwright-version.ts`.
### Floor derived from supported-versions list (angular)
```ts
import { type Tree } from '@nx/devkit';
import { assertSupportedPackageVersion } from '@nx/devkit/internal';
import { supportedVersions } from './backward-compatible-versions';
const minSupportedAngularMajor = Math.min(...supportedVersions);
export function assertSupportedAngularVersion(tree: Tree): void {
assertSupportedPackageVersion(
tree,
'@angular/core',
`${minSupportedAngularMajor}.0.0`
);
}
```
Reference: `packages/angular/src/utils/assert-supported-angular-version.ts`.
Pick the shape that matches whether the plugin already has a `supportedVersions` list (angular does; cypress/playwright/vitest don't).
### Plugins managing multiple primary packages
`@nx/jest` manages `jest`, `ts-jest`, `@types/jest`. `@nx/eslint` manages `eslint`, `@typescript-eslint/parser`, `@typescript-eslint/eslint-plugin`, `eslint-config-prettier`. The canonical wrapper signature takes one package; with multiple, decisions are needed:
- **Gate on the primary only** when the others are peer-locked (e.g., angular's strategy with `@angular/core` covering `@angular/cli`, `@angular/ssr`, etc.). This is sufficient when the siblings' peer-deps tie them to the primary's major.
- **Gate on each independently** when the siblings can be installed at any major regardless of the primary (typescript-eslint pair vs eslint; ts-jest vs jest). In that case, the wrapper makes multiple `assertSupportedPackageVersion` calls in sequence:
```ts
export function assertSupportedJestVersion(tree: Tree): void {
assertSupportedPackageVersion(tree, 'jest', minSupportedJestVersion);
// ts-jest is independent — declare and assert it separately.
assertSupportedPackageVersion(tree, 'ts-jest', minSupportedTsJestVersion);
}
```
When in doubt: read each sibling's `peerDependencies` block at the version range being supported. If it pins the primary, it's covered by the primary's gate. If it doesn't (or pins something else), it needs its own.
## Skip writing the install constant when the package is already detected
Init generators that add the third-party package to `package.json` should NOT overwrite an already-installed minor/patch. The `keepExistingVersions: true` flag handles this at the `addDependenciesToPackageJson` level. But for code paths that compute the version to write (e.g., picking the major-specific value from `versionMap`), the rule is the same: read what's installed first; only write the fresh-install constant when nothing is detected.
Reference: `packages/cypress/src/generators/init/init.ts` `updateDependencies` — calls `getInstalledCypressVersion(tree)` first, then routes through `versions(tree)` which short-circuits to existing-version paths. The `keepExistingVersions ?? true` flag at the `addDependenciesToPackageJson` call site is the final safety net.
## The versions module
Path: `packages/<plugin>/src/utils/versions.ts`.
### Required exports
```ts
// Plain string, no caret. Used as the floor for assertSupportedPackageVersion.
export const minSupportedCypressVersion = '13.0.0';
// Fresh-install constants — may be HIGHER than minSupported when the feature
// surface at the floor is incomplete. Playwright peer is ^1.36.0 but
// fresh-install is ^1.37.0 so blob reporter + merge-reports work out of the
// box.
export const playwrightVersion = '^1.37.0';
// Optional: feature-gate thresholds for runtime/executor code.
export const minPlaywrightVersionForBlobReports = '1.37.0';
```
### Stable deps stay top-level; per-major-varying deps go in the bundle
A plugin typically manages one primary package whose version map drives several siblings. Deps that vary per major go into a typed bundle; deps that are version-stable stay as plain `export const`s.
```ts
// Stable across all supported majors of the primary → plain exports.
export const viteVersion = '^8.0.0';
export const jsdomVersion = '^27.1.0';
export const vitePluginReactVersion = '^6.0.0';
// Vary with the primary's major → bundle.
export const vitestVersion = '~4.1.0';
export const vitestCoverageV8Version = '~4.1.0';
export const vitestCoverageIstanbulVersion = '~4.1.0';
type VitestVersions = {
vitestVersion: string;
vitestCoverageV8Version: string;
vitestCoverageIstanbulVersion: string;
};
// latestVersions reuses the top-level exports so import { vitestVersion }
// stays valid for the fresh-install path while versions(tree).vitestVersion
// is the route-aware version.
const latestVersions: VitestVersions = {
vitestVersion,
vitestCoverageV8Version,
vitestCoverageIstanbulVersion,
};
type CompatVersions = 3;
const versionMap: Record<CompatVersions, VitestVersions> = {
3: {
vitestVersion: '^3.0.0',
vitestCoverageV8Version: '^3.0.5',
vitestCoverageIstanbulVersion: '^3.0.5',
},
};
```
**Do not** keep per-major aliases like `vitestV3Version = '^3.0.0'` alongside the bundle — they duplicate the map entries and drift over time. See `anti-patterns.md` §15.
### The `versions(tree)` function
Falls through to latest on unknown majors — no `switch + throw default:`.
```ts
export function versions(tree: Tree): VitestVersions {
const installedVitestVersion = getInstalledVitestVersion(tree);
if (!installedVitestVersion) {
return latestVersions;
}
const vitestMajorVersion = major(installedVitestVersion);
return versionMap[vitestMajorVersion as CompatVersions] ?? latestVersions;
}
```
### The `getInstalled<Pkg>Version(tree?)` helper
Optional `tree` parameter — with tree, reads declared from `package.json` (normalizing `latest`/`next` to the fresh-install constant); without tree, routes through the shared `getInstalledPackageVersion` from `@nx/devkit/internal` (FS resolution via `getNxRequirePaths()`).
```ts
export function getInstalledVitestVersion(tree?: Tree): string | null {
if (!tree) {
return getInstalledPackageVersion('vitest');
}
const installedVersion = getDependencyVersionFromPackageJson(tree, 'vitest');
if (!installedVersion) {
return null;
}
if (installedVersion === 'latest' || installedVersion === 'next') {
return clean(vitestVersion) ?? coerce(vitestVersion)?.version ?? null;
}
return clean(installedVersion) ?? coerce(installedVersion)?.version ?? null;
}
export function getInstalledVitestMajorVersion(tree?: Tree): number | null {
const installedVitestVersion = getInstalledVitestVersion(tree);
return installedVitestVersion ? major(installedVitestVersion) : null;
}
```
This is the cypress/playwright/vitest pattern. Reference: `packages/cypress/src/utils/versions.ts`.
## Generator entry points
The assert goes in the function that does the actual work — first statement of the function body, before any other tree access or sub-generator call. (The assert itself reads the tree, of course; the rule is that nothing else in the generator runs against an unsupported version.)
### Plugins with a `<gen>` / `<gen>Internal` split (cypress, playwright)
The public wrapper merges defaults and delegates. Assert lives in `*Internal`:
```ts
// Public wrapper — no assert, just default merging.
export async function cypressInitGenerator(tree: Tree, options: Schema) {
return cypressInitGeneratorInternal(tree, { addPlugin: false, ...options });
}
// Working function — assert is the first statement.
export async function cypressInitGeneratorInternal(
tree: Tree,
options: Schema
) {
assertSupportedCypressVersion(tree);
updateProductionFileset(tree);
// ...
}
```
Reference: `packages/cypress/src/generators/init/init.ts`, `packages/playwright/src/generators/init/init.ts`.
### Plugins with a single-function generator (angular)
No wrapper/internal split. The function itself asserts:
```ts
export async function angularInitGenerator(tree: Tree, options: Schema) {
assertSupportedAngularVersion(tree);
// ...
}
```
Reference: `packages/angular/src/generators/init/init.ts`.
### Double-asserts are established convention, not an edge case
When `configurationGenerator` calls `initGenerator` internally, both call their respective `assertSupportedXVersion`. This is the angular precedent (29 `generators.json` entries → 58 assert call sites). The assert is idempotent (one tree read + one semver comparison) and the parameterized floor spec treats every entry point as independent — both must throw on sub-floor. Don't refactor away.
## User-pin preservation
### `addDependenciesToPackageJson` call sites
Every call from a generator (NOT a migration) must pass `keepExistingVersions: true` as the fifth positional argument or via the `?? true` pattern.
```ts
// Pattern A — explicit at the call site
addDependenciesToPackageJson(
tree,
{},
{ 'eslint-plugin-cypress': pkgVersions.eslintPluginCypressVersion },
undefined,
true
);
// Pattern B — driven by schema (init generators only)
addDependenciesToPackageJson(
tree,
{},
devDependencies,
undefined,
options.keepExistingVersions ?? true
);
```
Reference: `packages/cypress/src/generators/init/init.ts`, `packages/cypress/src/utils/add-linter.ts`, `packages/angular/src/generators/add-linting/lib/add-angular-eslint-dependencies.ts`.
### init schema
```json
{
"keepExistingVersions": {
"type": "boolean",
"x-priority": "internal",
"description": "Keep existing dependencies versions",
"default": true
}
}
```
Reference (on master): `packages/cypress/src/generators/init/schema.json`, `packages/playwright/src/generators/init/schema.json`. (`@nx/vitest` follows the same pattern in its open PR — verify via `gh pr diff 35671`.)
## Migrations.json gates
Three categories of migration:
| Category | Touches | `requires` |
| -------------------------------- | ------------------------------------------------- | --------------------------------------------------------------------------- |
| Nx-only | `nx.json`, executor options, generator defaults | none |
| Codemod | source files / config tied to a third-party major | `{ "<pkg>": ">=N <N+1" }` (or open upper bound for legacy-cleanup codemods) |
| `packageJsonUpdates` cross-major | bumps `<pkg>` from major N to N+1 | `{ "<pkg>": ">=N.0.0 <(N+1).0.0" }` (source-major gate) |
| `packageJsonUpdates` same-major | bumps minor/patch | none required |
### Sibling packages
Ecosystem-locked siblings whose peer-on-the-primary covers them: no separate `requires`. Examples in Angular: `@angular/cli`, `@angular/ssr`, `@angular-devkit/build-angular` (from v20+, NOT v19).
Independent siblings: each needs its own `requires` entry. Examples in Angular: `@ngrx/*`, `@angular-eslint/*`, `zone.js`, `jest-preset-angular`.
### Reference examples
- `packages/angular/migrations.json` `20.2.0-module-federation`, `22.2.0`, `22.6.0-module-federation` — Module Federation entries gating on `@module-federation/enhanced` source range. Added in `#35587`.
- `@nx/vitest`'s `update-22-1-0` and `update-22-3-2` migrations gating on `vitest: ">=4.0.0"` (Vitest-4-specific AI-instructions) — pattern proposed in open PR `#35671`. Inspect via `gh pr diff 35671 --repo nrwl/nx -- packages/vitest/migrations.json`.
- `packages/angular/migrations.json` `update-unit-test-runner-option` — Nx-only migration with the over-gating `@angular/core` `requires` **removed** in `#35587`.
## Test specs
### Parameterized floor spec (one per plugin)
Path: `packages/<plugin>/src/utils/all-generators-enforce-floor.spec.ts`.
```ts
import { assertGeneratorsEnforceVersionFloor } from '@nx/devkit/internal-testing-utils';
import { join } from 'node:path';
describe('@nx/<plugin> generators enforce supported version floor', () => {
assertGeneratorsEnforceVersionFloor({
packageRoot: join(__dirname, '..', '..'),
packageName: '<pkg>',
subFloorVersion: '~<floor-minus-one>',
// Required only when a generator must run below the floor by design.
// excludeGenerators: ['migrate-to-cypress-11'],
});
});
```
Pick `subFloorVersion` such that `lt(coerce(it).version, floor)` is true. No pre-release identifiers. Reference values used in the repo: `~18.2.0` (angular, v19 floor), `~12.17.0` (cypress, v13 floor), `~1.35.0` (playwright, v1.36 floor).
### Plugin assert spec (optional, one per plugin)
Path: `packages/<plugin>/src/utils/assert-supported-<pkg>-version.spec.ts`.
`assertSupportedPackageVersion` is already fully tested in `@nx/devkit`,
so a per-plugin spec mostly re-tests the shared helper. The early
compliance PRs (`#35587` angular onward) ship one for symmetry, but it
isn't required. If you add one, five canonical cases is the shape used:
```ts
describe('assertSupportedCypressVersion', () => {
it('throws when cypress is below the supported floor');
it('does not throw when cypress is not installed (fresh-install path)');
it('does not throw when cypress is `latest`');
it('does not throw when cypress is `next`');
it('does not throw when cypress is within the supported window');
});
```
Reference: `packages/angular/src/utils/assert-supported-angular-version.spec.ts` (originally landed in `#35587`).
### Test message matching
Use substring match on the error message:
```ts
.rejects.toThrow(`Unsupported version of \`${packageName}\` detected`)
```
Not a hand-rolled RegExp (avoid escape bugs). Reference: see how the shared `assertGeneratorsEnforceVersionFloor` itself does the match — search for `Unsupported version of` in `packages/nx/src/internal-testing-utils/assert-generators-enforce-version-floor.ts`.
## Standardized error format
```
Unsupported version of `<pkg>` detected.
Installed: <declared-range-as-written-in-package.json>
Supported: >= <floor>
Update `<pkg>` to <floor> or higher.
```
Two notes:
- The `Installed:` line preserves the **original declared range** (e.g., `~18.2.0`), not the cleaned semver. `assertSupportedPackageVersion` passes `declared` through to `throwForUnsupportedVersion`.
- Do not add an "above ceiling" branch to this message. Above-ceiling is silent fallthrough.
## Peer dep alignment
### What belongs in `peerDependencies`
The test: _would the plugin still work if this package were absent from the workspace, with the plugin's code paths unchanged?_
A package is required-peer if **any** of these is true:
- The plugin's TypeScript imports / `require`s it (executor, preset, runtime helper).
- The plugin's executor spawns its CLI binary (`spawn('cypress')`, etc.).
- The plugin's inferred plugin (`createNodes`/`createNodesV2`) **emits a target whose `command` invokes the package's CLI** (e.g., `command: 'rspack build'` → `@rspack/cli` is required). The `externalDependencies: ['<pkg>']` declaration in such targets is itself an admission of the runtime dependency.
A package is **not** required-peer when:
- The plugin's generator installs it into the user's workspace for the user to consume independently, and no plugin code (TypeScript, executor binary spawn, or inferred-plugin emitted command) ever invokes it. Example: ESLint plugins written into the user's eslintrc — `@nx/cypress` installs `eslint-plugin-cypress`, but its lint executor uses generic ESLint loading; the cypress plugin is loaded by ESLint per the user's config, not by `@nx/cypress`. Example: `@types/*` packages installed for the user's TS compilation but never imported by plugin code.
**Ecosystem-signal peer** (Angular's full `@angular/*` peer list) → judgment call, not a compliance requirement. Documents lockstep compatibility but isn't enforced by the multi-version rules.
### Required vs. optional peer
Most Nx plugin peers should be **optional** (`peerDependenciesMeta: { "<pkg>": { "optional": true } }`):
- Required peer: every user of the plugin needs this package, regardless of which surface they use. Example: `@angular-devkit/core`, `rxjs` in `@nx/angular` — every Angular Nx workspace uses them.
- **Optional peer (the common case for inferred-plugin / executor surfaces):** the package is only needed when the user opts into a specific surface — an executor they have to write into `project.json`, an inferred plugin gated on the presence of a config file, a preset that auto-injects. Users who don't use that surface shouldn't see an unmet-peer warning. Examples: `@playwright/test` in `@nx/playwright`, `cypress` in `@nx/cypress`, `vitest` / `vite` in `@nx/vitest`, `@angular/build` / `@angular-devkit/build-angular` / `ng-packagr` in `@nx/angular`.
For `@rspack/cli` / `@rspack/core` in `@nx/rspack`: both surfaces (executor, inferred plugin) are gated — executor opt-in via `project.json`, inferred plugin gated on `rspack.config.{ts,js}` presence. Compliance fix should peer-declare both with `optional: true`.
Concrete examples:
| Package | Plugin | Plugin invokes? | Peer? | Optional? |
| ----------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ----------------------------------------------------- |
| `cypress` | `@nx/cypress` | yes (executor spawns binary; inferred plugin emits `cypress run` commands) | **yes** | optional (executor + inferred plugin are both opt-in) |
| `@playwright/test` | `@nx/playwright` | yes (executor + preset + inferred plugin) | **yes** | optional |
| `vitest` | `@nx/vitest` | yes (executor + inferred plugin emits `vitest` commands) | **yes** | optional |
| `@rspack/cli` | `@nx/rspack` | yes — inferred plugin emits `command: 'rspack build'` (`packages/rspack/src/plugins/plugin.ts:182,196`). Not imported in TS, but invoked via emitted CLI target. | **yes** | optional (both surfaces gated) |
| `@angular-devkit/core` | `@nx/angular` | yes (used by every Angular Nx workspace) | **yes** | **not optional** |
| `@angular/build` | `@nx/angular` | yes (only when user uses the @angular/build builder) | **yes** | optional |
| `eslint-plugin-cypress` | `@nx/cypress` | no (generator writes it into user's eslintrc; ESLint loads it, not the plugin) | **no** | n/a |
| `@types/node` | various | no (generator install only; types are build-time) | **no** | n/a |
### Range / version alignment
For packages that ARE peer-declared: the range must match the install lanes the code ships. If the code has no `isV1Installed` branch and no v1 entry in `versionMap`, do not list `^1.0.0` in the peer range.
Reference: open PR `#35671` (`@nx/vitest`) drops `^1.0.0` from the `vitest` peer range because there is no v1 install lane. Inspect via `gh pr diff 35671 --repo nrwl/nx -- packages/vitest/package.json`. Verify state — may have merged or closed since.
## Executor / runtime feature gating
Features introduced after the floor must gate at call time on the installed version, not on the floor. Use `getInstalledPackageVersion` + `lt` from `semver`.
```ts
import { getInstalledPackageVersion } from '@nx/devkit/internal';
import { lt } from 'semver';
import { minPlaywrightVersionForBlobReports } from './versions';
const installed = getInstalledPackageVersion('@playwright/test');
if (installed && lt(installed, minPlaywrightVersionForBlobReports)) {
throw new Error(
`The "@nx/playwright:merge-reports" executor requires "@playwright/test" version ${minPlaywrightVersionForBlobReports} or greater (the version that introduced the "blob" reporter and the "merge-reports" CLI). You are currently using version ${installed}.`
);
}
```
Reference: `packages/playwright/src/executors/merge-reports/merge-reports.impl.ts`, `packages/playwright/src/utils/preset.ts`. Both added in `#35642`.
Two distinct cases:
- **Auto-injected feature** (preset's auto-blob in CI): skip injection silently when installed < threshold. Only throw when the user explicitly opted in (`generateBlobReports: true`) on an unsupported version.
- **Direct invocation** (executor CLI subcommand): throw immediately with a clear "requires >= X.Y.Z (the version that introduced …)" message.
## File-layout summary
For plugin `@nx/<plugin>` managing `<pkg>` with floor `X.Y.Z`:
```
packages/<plugin>/
src/
utils/
versions.ts # add minSupportedXVersion
assert-supported-<pkg>-version.ts # NEW — 7-line wrapper
assert-supported-<pkg>-version.spec.ts # OPTIONAL — 5 cases (mostly re-tests shared helper)
all-generators-enforce-floor.spec.ts # NEW — parameterized
generators/
<each>/
<each>.ts # assert as first statement
init/
schema.json # keepExistingVersions default: true
init.ts # keepExistingVersions ?? true
executors/ # feature-gate via getInstalledPackageVersion
plugins/ # same
migrations.json # tighten / remove `requires` gates per audit
package.json # align peer; add "semver": "catalog:" if newly used
```
---
# Code-level verification (review-mode lens)
In review mode, walk these markers against the diff.
Output rules:
- **Inline categories are `[blocker]` and `[non-blocker]` only.** No "open question," "ask," or other ad-hoc tags. Author-directed questions emerge from non-blocker findings and surface in the closing "Open questions for author" block.
- **For each blocker / non-blocker:** anchor at `file:line` and cite which reference PR / file demonstrates the correct pattern. Cross-reference `anti-patterns.md` when the finding matches a numbered pattern.
- **Sections without findings get a single summary line**, not a per-file enumeration. `"Pass — all 7 generator entries assert at first statement"` is right; listing seven file:lines is wrong. Reviewer time is spent on actionable items; passing checks should not eat reading budget.
- **Produce the verdict block** at the end (see §"Verdict template"). The block is the skimmable index — produce it, don't substitute a free-form summary.
Scope:
- **In scope:** the diff's code, configs, schemas, migrations, and **in-codebase documentation that describes runtime behavior** (e.g., `.mdoc` / `.md` files under `astro-docs/` or `docs/` that claim how the plugin behaves). A docs claim that contradicts the code is a correctness issue and belongs here.
- **Out of scope:** PR title, PR body shape, commit message format, related-issues section, branch naming. Defer to the user's PR/commit conventions (loaded globally from `~/.claude/memory/workflow/git/`). Don't flag PR/commit shape in this skill's review output.
## 1. Peer dep & install constants
- [blocker] `package.json` peer dep range matches the install lanes implemented in `versions.ts`. No phantom version claims. → If `versionMap` has no v1 entry, peer must not list `^1.0.0`. Reference correction: `#35671` (`@nx/vitest`). Anti-pattern: §8.
- [blocker] **Declared floor matches the effective floor.** Grep every `import` / `require` from the third-party package in plugin code. If any imported API only exists at version >N, the declared floor must be >=N. Anti-pattern: §16. Reference correction: `#35671` second commit raised vitest from v2 to v3 after catching a `getRelevantTestSpecifications` import (v3+ only).
- [blocker] Fresh-install constant exposes the **full feature surface**, not just the peer floor. → Playwright peer stayed `^1.36.0` but fresh-install moved to `^1.37.0` because blob reporter + `merge-reports` CLI both require 1.37. Reference: `#35642` `packages/playwright/src/utils/versions.ts`.
- [blocker] No per-major version aliases (`<pkg>V3Version`, `<pkg>V4Version`, etc.) alongside a `versionMap` — pick one source of truth. Anti-pattern: §15. Reference: `#35671`'s third commit dropped these aliases.
- [blocker] `versions.ts` exports `minSupportedXVersion = 'X.Y.Z'` as a plain string (no caret, no range markers). The wrapper passes this verbatim to `assertSupportedPackageVersion`.
- [blocker] `versionMap[major]` lookup is `versionMap[major] ?? latestVersions`. No `switch + throw default:` or other above-ceiling throw. Anti-pattern: §2. Reference correction: `#35670` (`@nx/cypress` `versions()` rewrite).
- [blocker] Every third-party package the **plugin invokes at runtime** has a `peerDependencies` entry. "Invokes" covers: (a) TypeScript `import`/`require`, (b) executor spawning the package's CLI binary, (c) inferred-plugin (`createNodes`/`createNodesV2`) emitting a target whose `command` invokes the package's CLI (the `externalDependencies: ['<pkg>']` field on such targets confirms the dependency). See §"Peer dep alignment" for the full categorization.
- **Don't flag** packages the plugin's generator installs into the user's workspace for the user to consume independently, with no plugin codepath invoking them (e.g., ESLint plugins like `eslint-plugin-cypress` that ESLint loads from the user's eslintrc; `@types/*` packages).
- Plugins flagged at time of writing for actually-invoked packages without a peer entry: `@nx/webpack`, `@nx/rollup`, `@nx/angular-rspack-compiler` (primary listed under `dependencies`); `@nx/jest`, `@nx/nest`, `@nx/module-federation`, `@nx/react`, `@nx/vue`, `@nx/expo`, `@nx/react-native`, `@nx/node`, `@nx/js` (verify per plugin — TS imports, binary spawns, AND inferred-plugin emitted commands all count).
- [blocker] Peers that are only used when the user opts into a specific surface (executor opt-in, inferred plugin gated on config file presence, opt-in preset) are declared **optional** via `peerDependenciesMeta: { "<pkg>": { "optional": true } }`. Pattern is established across reference plugins — `@playwright/test`, `cypress`, `vitest`, `vite`, `@angular/build`, `ng-packagr` are all optional. Required-non-optional peers (`@angular-devkit/core`, `rxjs` in `@nx/angular`) are reserved for packages every workspace using the plugin needs. See §"Required vs. optional peer".
- [non-blocker] If the PR introduces `semver` usage in the plugin, `package.json` `dependencies` lists `"semver": "catalog:"`. Reference: `#35642` added it to `packages/playwright/package.json`.
## 2. Generator entry points
- [blocker] **Every** entry in `generators.json` has its working function calling `assertSupported<Pkg>Version(tree)` as the **first statement** — before any tree reads, writes, or sub-generator calls. For wrapper/internal-split plugins (cypress, playwright): assert is in `*Internal`. For single-function generators (angular): in the function itself. Anti-pattern: §14.
- [blocker] Plugin wrapper file `assert-supported-<pkg>-version.ts` imports `assertSupportedPackageVersion` from `@nx/devkit/internal`. No direct call to `throwForUnsupportedVersion`. No bespoke `throwBelowFloor` / `throwAboveWindow` / `assertVersion` / local `cleanVersion = clean(v) ?? coerce(v)?.version` helpers (use `normalizeSemver` / `getInstalledPackageVersion` / `getDeclaredPackageVersion`). Anti-pattern: §1. Concrete example: PR `#35676` introduces a local `cleanVersion` and `getInstalledRsbuildVersionRuntime` — both already exist as shared helpers.
- [blocker] If `all-generators-enforce-floor.spec.ts` uses `excludeGenerators`, each excluded name has a code comment explaining why the generator must run sub-floor (e.g., `migrate-to-cypress-11` lifts v8v10 workspaces onto v11).
- [non-blocker] Double-assert chains (`configurationInternal` calls `initInternal`, both assert) are OK. Idempotent. Don't refactor away.
## 3. Generator outputs
- [blocker] Templates the generator writes (project files, configs, schemas) compile and run on every major in the support window. Verify with a quick mental walk: for each template referenced from the generator, identify any per-major-version conditional and confirm it's accurate.
- [blocker] Generated `project.json` target shape (executor, options, schema) is valid on every supported major. If the executor's option schema differs across the support window, the generator branches or uses the union shape.
- [blocker] Default option values are valid on every supported major. A default that's only valid above a specific major must be conditional.
- [blocker] Version map covers every managed third-party dep. If the runtime later branches on a sibling's version (e.g., `@vitest/ui`), the version map must have an entry for that sibling per major — no gaps where the generator picks a constant the runtime then can't reconcile.
- [blocker] Generator schema accepts the **union of options across the support window**. Options removed in a newer major still validate at schema level (with description-notice); runtime throws when inapplicable on the installed major. See `gotchas.md` §"Schema-level deprecated-option stubs with runtime throws".
## 4. `keepExistingVersions` (user-pin preservation)
- [blocker] Every `addDependenciesToPackageJson` call from a **generator** passes `keepExistingVersions: true` (positionally as the 5th arg) or `options.keepExistingVersions ?? true`.
- [blocker] `init/schema.json` has `"keepExistingVersions": { "default": true }`. Not `false`. Not absent. **Known gap:** `@nx/angular`'s init schema currently has `default: false` and was NOT addressed in `#35587` — flagging in a non-angular PR is correct; fixing in passing in an angular PR is also correct. Anti-pattern: §4.
- [blocker] Linter / sub-generator helpers (`add-linter.ts`, `add-angular-eslint-dependencies.ts`, equivalents) also pass `true`.
- [non-blocker] If both schema `"default": true` AND `options.keepExistingVersions ?? true` are present, that's two sources of truth. Anti-pattern: §12.
- **Migration generators are exempt.** Do not flag missing flags in code under `src/migrations/`.
## 5. `migrations.json` gates
- [blocker] Every `packageJsonUpdates` entry that bumps across a major version has `requires: { "<pkg>": ">=N.0.0 <(N+1).0.0" }`. Source-major gate, not target. Anti-pattern: §6. Reference: `#35587` Module Federation entries.
- **Read the actual range strings; don't tick this by counting split entries.**
- [non-blocker / ask author] One-sided gates (`<X` with no lower bound, or `>=Y` with no upper bound) may be intentional or accidental. Legitimate cases: legacy-cleanup codemods that should apply on every source major below the target; a v0→v1 bridge where every v0.x workspace should migrate; bumping a package introduced at vN from `undefined`. Illegitimate cases: a v1→v2 bump expressed as `<2.x` would fire for v0 workspaces too; a `>=N` with no upper bound would fire for future majors. **When you see a one-sided gate, ask the author to confirm intent** — don't auto-flag as blocker.
- [blocker] Codemod migrations that only make sense at/above a specific third-party major have a `requires` entry. Open upper bound is intentional when the codemod cleans up legacy flags. Runtime per-package guards (`gte`/`lt` inside the migration body) are NOT a substitute for `requires`.
- [blocker] **Nx-only migrations have NO `requires` gate.** A migration that only writes to `nx.json`, executor options, or generator defaults applies regardless of third-party version. Anti-pattern: §5. Reference correction: `#35587` removed the over-gating `@angular/core: >=21.0.0` from `update-unit-test-runner-option`.
- [blocker] For independent siblings (Angular: `@ngrx/*`, `@angular-eslint/*`, `zone.js`, `jest-preset-angular`), gating on the primary's major is **not sufficient** — each needs its own `requires` entry. Anti-pattern: §7. Verify pairing by reading the sibling's `peerDependencies` at the version range being bumped from.
- [blocker] A single `packageJsonUpdates` entry must not mix mutually-exclusive cross-major bumps under one `requires` (AND-semantics). Split into separate entries each with its own gate. Concrete example: React PR's `22.3.4` entry mixed `react-router 7.12.0` (cross-major) with `react-router-dom 6.30.3` (v6 patch) — must split.
- [non-blocker] `incompatibleWith` is not a substitute for `requires`. Anti-pattern: §10. If you see `incompatibleWith` standing in for a source-major gate, ask for a `requires` instead.
- [non-blocker] Sibling `packageJsonUpdates` entries within the same block that depend on a peer's post-bump version are fine — tier-1 chaining evaluates against post-bump state. Reference: Storybook 21.2.0 chains on the prior 21.1.0 bump.
- [non-blocker] Pre-floor `packageJsonUpdates` entries targeting source majors below the current support floor are intentionally retained for users on older Nx versions. Don't _add_ a bridge entry without explicit decision, and don't _remove_ a legitimately-pre-floor entry mid-audit.
## 6. Executor / runtime / inferred-plugin feature gating
- [blocker] Executor code that invokes a CLI subcommand or uses an API introduced after the floor calls `getInstalledPackageVersion('<pkg>')` + `lt(installed, threshold)` from `semver` and throws a clear "requires >= X.Y.Z (the version that introduced …)" message. Reference: `packages/playwright/src/executors/merge-reports/merge-reports.impl.ts` (`#35642`).
- [blocker] Preset / config builders that auto-inject feature-version-coupled config skip injection silently when installed < threshold, and only throw when the user **explicitly** opted in on an unsupported version. Reference: `packages/playwright/src/utils/preset.ts` (`#35642` — `generateBlobReports` logic).
- [blocker] **Inferred plugins** (`createNodes`/`createNodesV2`) parse configs across every major in the support window. The plugin emits the same target shape regardless of the installed major (or branches if shapes diverge). Don't hardcode helper imports against one major.
- [blocker] **Above-ceiling is silent fallthrough.** No warn, no throw, no branch. Anti-pattern: §2.
- [non-blocker] Executors don't enforce the plugin floor. Floor enforcement is generator-only. Don't suggest adding an executor-level floor assert unless the user asks.
- [non-blocker] `require('<pkg>')` for optional peers should live inside the function body, after version detection. Anti-pattern: §9.
## 7. Tests
- [blocker] `all-generators-enforce-floor.spec.ts` exists at `packages/<plugin>/src/utils/all-generators-enforce-floor.spec.ts`, calls `assertGeneratorsEnforceVersionFloor` from `@nx/devkit/internal-testing-utils`. This is the parameterized spec that exercises every generator's floor assert.
- [blocker] `subFloorVersion` is a semver range where `lt(coerce(it).version, floor)` is true. No pre-release identifiers. Reference values: `~18.2.0` (angular, v19 floor), `~12.17.0` (cypress, v13 floor), `~1.35.0` (playwright, v1.36 floor).
- [non-blocker] Plugins establishing the pattern (`#35587` angular) ship a `assert-supported-<pkg>-version.spec.ts` with the 5 canonical cases (sub-floor / fresh-install / `latest` / `next` / in-range). The underlying `assertSupportedPackageVersion` already has full coverage in `@nx/devkit`, so the per-plugin spec largely re-tests the shared helper. Useful for symmetry across the PR series but not required — don't block on missing.
- [non-blocker] Runtime/executor feature-gate throw tests are nice-to-have, not required — reference PRs (`#35587`, `#35642`, `#35670`) do not have them today.
- [non-blocker] Error message matching uses substring (`toThrow('Unsupported version of \`<pkg>\` detected')`) instead of hand-rolled `RegExp`. Anti-pattern: §13.
- [non-blocker] FS-side helper migrated to `getInstalledPackageVersion`; tree-side helper may stay inline. The two helpers' `null` vs. fallback semantics differ. Reference: `#35670` `packages/cypress/src/utils/versions.ts` rewrite.
## Open questions to raise (when missing from the PR / Linear task)
1. **Floor:** deliberate raise from the previous declared peer, or matching the existing peer? If raise: do sub-floor users get a `packageJsonUpdates` bridge or manual bump?
2. **Peer-range tightening:** dropping a major because there's no install lane (legitimate, `#35671` pattern) or because tests fail (regression risk — investigate)?
3. **`requires` removals on Nx-only migrations:** genuinely Nx-only, or sneaking through a third-party-touching change?
4. **Pruned migrations gaps:** if floor is being raised by N+ majors and prior `packageJsonUpdates` entries were removed, do sub-floor users have any auto-bump path? `git log --all -- packages/<plugin>/migrations.json`.
5. **Runtime feature gates:** threshold verified against third-party release notes, or guessed?
6. **Sibling classification:** ecosystem-locked vs. independent. Read the sibling's `peerDependencies` at the bumped-from range. `@angular-devkit/build-angular` is the gotcha — peer-locked from v20+, NOT v19.
7. **Cross-plugin coordination:** if the plugin pins a third-party that another plugin also manages (e.g., `@nx/cypress` pinning vite for cypress v13/v14+; `@nx/vite` supporting vite v5v8), confirm the windows stay aligned. If `@nx/vite` drops v5, `@nx/cypress` carries an orphaned install lane.
## Verdict template
```
Blockers: <N>
Non-blockers: <N>
1. Peer dep & install constants: [pass | <findings>]
2. Generator entry points: [pass | <findings>]
3. Generator outputs: [pass | <findings>]
4. keepExistingVersions: [pass | <findings>]
5. Migration gates: [pass | <findings>]
6. Executor / runtime / inferred-plugin: [pass | <findings>]
7. Tests: [pass | <findings>]
Open questions for author: [list]
Scope drift vs. Linear task (if applicable):
- Findings in task NOT addressed: <list>
- Changes in PR NOT in task: <list>
```
@@ -1,115 +0,0 @@
# Examples & references
Concrete files, commits, and PRs to grep when you need a model.
## Reference PRs (in order of arrival)
| PR | Plugin | Branch | State | Why notable |
| -------- | ---------------- | ---------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `#35587` | `@nx/angular` | `nxc-4381` | merged | First compliance PR. Established `throwForUnsupportedVersion`, the `assertSupported*Version` wrapper pattern, the `all-generators-enforce-floor.spec.ts` shape, the MF `requires`-gate pattern, the Nx-only-migration over-gate removal pattern. |
| `#35642` | `@nx/playwright` | `nxc-4398` | merged | Generalized the helpers into `version-floor.ts`/`installed-version.ts`. Added `assertGeneratorsEnforceVersionFloor` in `internal-testing-utils`. Established executor/runtime feature-gating pattern (blob reporter / `merge-reports`). Demonstrated the "fresh-install constant higher than peer floor" pattern. |
| `#35670` | `@nx/cypress` | `nxc-4384` | merged | Established `excludeGenerators` in the shared test helper for intentional sub-floor migrators (`migrate-to-cypress-11`). Demonstrated `versions()` switch-to-fallthrough rewrite. Demonstrated keeping the tree-side inline helper while migrating only the FS side to the shared helper. |
| `#35671` | `@nx/vitest` | `nxc-4408` | open at time of writing | Three commits. (1) Establishes "drop phantom peer-range claim" (removes `^1.0.0` from peer); migration `requires` tightening for Vitest-4-only AI-instructions migrations. (2) Raises floor v2 → v3 after audit catches `getRelevantTestSpecifications` import (v3+ API) — establishes the **effective-floor-vs-declared-floor** pattern (see `anti-patterns.md` §16). (3) Adopts the cypress version-resolution pattern (bundle-of-varying-deps `versions(tree)`, `getInstalled<Pkg>Version(tree?)`, no per-major aliases — see `anti-patterns.md` §15). To inspect: `gh pr view 35671 --repo nrwl/nx --json commits` then `gh pr diff 35671`. Verify state — may have merged or closed. |
Always verify state with `gh pr view <N> --repo nrwl/nx --json state` before citing — this table goes stale.
## Reference commits (for `git show` inspection)
When the same change exists as both a pre-squash branch commit AND a merged squash on master, prefer the merged squash — it's the authoritative final state. Pre-squash SHAs are listed because they're easier to read in isolation (smaller diffs) when investigating one specific aspect.
**Merged on master (authoritative):**
| SHA | Subject |
| ------------ | ---------------------------------------------------------------------------- |
| `75578724fa` | `cleanup(core): add throwForUnsupportedVersion util to @nx/devkit/internal` |
| `484ce6e5d5` | `fix(angular): multi-version support compliance (#35587)` |
| `78f908d015` | `cleanup(angular): adopt shared version-floor helpers` |
| `e2ef134645` | `fix(testing): multi-version support compliance for @nx/playwright (#35642)` |
| `5d8b1bab7e` | `cleanup(devkit): allow excluding generators from version floor test helper` |
| `bc35b484e3` | `fix(testing): multi-version support compliance for @nx/cypress (#35670)` |
Pre-squash branch SHAs are available via `gh pr view <N> --json commits` even after the branch is deleted; useful when inspecting one specific aspect of a merged PR in isolation. Example:
```bash
gh pr view 35642 --repo nrwl/nx --json commits | jq -r '.commits[] | "\(.oid[:10]) \(.messageHeadline)"'
```
## Shared helpers — current locations
| File | Exports |
| ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `packages/devkit/src/utils/version-floor.ts` | `throwForUnsupportedVersion` (internal-only), `assertSupportedPackageVersion` |
| `packages/devkit/src/utils/installed-version.ts` | `getInstalledPackageVersion`, `getDeclaredPackageVersion`, `isNonSemverDistTag`, `normalizeSemver`, `NON_SEMVER_DIST_TAGS` |
| `packages/devkit/internal.ts` | re-exports from above (this is `@nx/devkit/internal`) |
| `packages/nx/src/internal-testing-utils/assert-generators-enforce-version-floor.ts` | `assertGeneratorsEnforceVersionFloor` |
| `packages/devkit/internal-testing-utils.ts` | re-exports `assertGeneratorsEnforceVersionFloor` (this is `@nx/devkit/internal-testing-utils`) |
## Per-plugin compliant files (grep for the pattern)
### `@nx/angular` (most extensive — has the `supportedVersions` list pattern)
- `packages/angular/src/utils/assert-supported-angular-version.ts` — wrapper using `Math.min(...supportedVersions)`
- `packages/angular/src/utils/assert-supported-angular-version.spec.ts` — the canonical 5-case spec
- `packages/angular/src/utils/all-generators-enforce-floor.spec.ts` — the parameterized floor spec
- `packages/angular/src/generators/add-linting/lib/add-angular-eslint-dependencies.ts``keepExistingVersions: true` pattern
- `packages/angular/migrations.json` — MF `requires` gates and the over-gate removal
### `@nx/playwright` (the helpers were generalized here)
- `packages/playwright/src/utils/assert-supported-playwright-version.ts` — wrapper using a `minSupportedPlaywrightVersion` constant
- `packages/playwright/src/utils/all-generators-enforce-floor.spec.ts`
- `packages/playwright/src/utils/preset.ts` — runtime feature gating (blob reporter)
- `packages/playwright/src/executors/merge-reports/merge-reports.impl.ts` — executor feature gating
- `packages/playwright/src/utils/versions.ts``minSupportedPlaywrightVersion`, `minPlaywrightVersionForBlobReports`, `playwrightVersion = '^1.37.0'` (fresh install higher than peer)
- `packages/playwright/src/utils/add-linter.ts``keepExistingVersions: true` in linter helper
- `packages/playwright/package.json` — peer `^1.36.0` (unchanged), added `"semver": "catalog:"`
### `@nx/cypress` (excludeGenerators + versions() rewrite)
- `packages/cypress/src/utils/assert-supported-cypress-version.ts`
- `packages/cypress/src/utils/all-generators-enforce-floor.spec.ts` — uses `excludeGenerators: ['migrate-to-cypress-11']` with code comment
- `packages/cypress/src/utils/versions.ts``versions()` rewritten to `versionMap[major] ?? latestVersions`; `getInstalledCypressVersion` FS-path migrated to shared helper, tree-path kept inline
## Finding current work-in-progress
To enumerate all compliance PRs (merged + open) without relying on out-of-tree tracking docs:
```bash
# Open + merged compliance PRs
gh pr list --repo nrwl/nx --search "multi-version compliance" --state all --limit 30 \
--json number,title,state,headRefName,author
# Just open ones
gh pr list --repo nrwl/nx --search "multi-version compliance" --state open
```
This is the authoritative list. Plugins covered to date can be derived by inspecting which packages each merged PR touched.
To check which plugins still have known anti-patterns (e.g., phantom peer claims, missing floor assert), grep on master:
```bash
# Plugins WITHOUT an assert-supported-<pkg>-version wrapper
for d in packages/*/src/utils; do
pkg=$(dirname "$d" | xargs basename)
if [ ! -f "$d/assert-supported-$pkg-version.ts" ] && \
[ ! -f "$d/assert-supported-${pkg/_/-}-version.ts" ]; then
echo "$pkg: no assert-supported wrapper"
fi
done
# Plugins missing the parameterized floor spec
find packages -name "all-generators-enforce-floor.spec.ts" -not -path "*/dist/*"
```
Cross-reference with the third-party packages each plugin manages (peer deps in `package.json`).
## How to use these examples
When auditing a new plugin, before writing anything:
1. Read the PR body of `#35642` (`@nx/playwright`) — it's the most comprehensive description of the canonical shape.
2. Read the four files from `@nx/playwright`: `versions.ts`, `assert-supported-playwright-version.ts`, `all-generators-enforce-floor.spec.ts`, and `preset.ts`. Five minutes.
3. If your plugin has a `migrations.json` of any complexity, also read `packages/angular/migrations.json` MF entries and the `update-unit-test-runner-option` entry for the gate patterns.
4. If the plugin has runtime feature gates, also read `packages/playwright/src/executors/merge-reports/merge-reports.impl.ts`.
When reviewing a compliance PR, the diff should look very similar to one of these reference PRs. Differences should be justifiable by the plugin's specifics (different floor, different feature gates, different migration shape) — not by departing from the canonical patterns.
@@ -1,241 +0,0 @@
# Gotchas & edge cases
Non-obvious behavior. Load these into your model before auditing or reviewing.
## `latest` / `next` dist-tags
When a workspace declares `"<pkg>": "latest"` or `"next"` in its `package.json`:
- `assertSupportedPackageVersion` no-ops via `isNonSemverDistTag` (NON_SEMVER_DIST_TAGS = `['latest', 'next']`). The floor check is skipped entirely.
- `getDeclaredPackageVersion` falls back to the cleaned `latestKnownVersion` argument (if provided) or returns `null`.
- `versions(tree)` returns `latestVersions` (the fresh-install path).
Tests must include `latest` and `next` cases. Both are no-ops; neither throws.
## pnpm `catalog:` references
Declared versions may be `"catalog:default"`, `"catalog:typescript"`, etc. (since pnpm 9.5):
- `getDependencyVersionFromPackageJson` (via the catalog manager in devkit) resolves these before the helper sees them. Don't call `clean`/`coerce` on raw values.
- `normalizeSemver` behavior on a raw `catalog:` string is not explicitly tested (open question — verify if you encounter it).
Reference: PR `#35459` (`fix(misc): resolve pnpm catalog: refs in version lookups`) — landed catalog ref handling.
## Fresh-install path (package not declared)
When `<pkg>` is missing from the workspace's `package.json` entirely:
- `assertSupportedPackageVersion` no-ops.
- `versions(tree)` returns `latestVersions`.
- The generator proceeds with the fresh-install constant (e.g., `playwrightVersion = '^1.37.0'`).
This is intentional — the generator is being run on a new workspace or one that's adding this package for the first time.
## Error message preserves declared range, not cleaned semver
```
Installed: ~18.2.0
Supported: >= 19.0.0
```
`Installed:` shows what's in `package.json` verbatim. Don't try to normalize it in the error message — it tells the user exactly what they typed, which helps them find it.
The argument flow: `assertSupportedPackageVersion` calls `throwForUnsupportedVersion(packageName, declared, minSupportedVersion)` with the raw `declared` value.
## Cypress's `getCypressVersionFromTree` stays inline
The shared `getDeclaredPackageVersion` falls back to `latestKnownVersion` when the declared value is `latest`/`next` or missing. Cypress's tree path returns `null` on missing. These semantics differ enough that the helper can't be consolidated without changing behavior.
The FS path (`getCypressVersionFromFileSystem`) was migrated to `getInstalledPackageVersion` (better resolution for pnpm strict / nested installs). The tree path stayed inline.
Reference: `packages/cypress/src/utils/versions.ts` after `#35670`.
## Double-asserts are fine
When `configurationInternal` calls `initInternal` (or any generator chain), both call their respective `assertSupportedXVersion(tree)`. The assert is idempotent and cheap (one tree read + one semver comparison). Don't refactor away.
The `assertGeneratorsEnforceVersionFloor` test treats both entry points as separate generators and asserts each throws — which is what we want.
## Angular ecosystem lockstep — what `@angular/core >=N` covers
Peer-locked to `@angular/core` (one `requires` on the primary is sufficient):
- `@angular/cli`
- `@angular/ssr`
- `@angular-devkit/build-angular` **from v20+** (NOT v19 — `@angular-devkit/build-angular@19` does not peer-on `@angular/core`)
- `@angular/material`, `@angular/cdk`, all `@angular/*` framework packages
- `@schematics/angular`
Independent (need their own `requires`):
- `@ngrx/*`
- `@angular-eslint/*`
- `zone.js`
- `jest-preset-angular`
- `karma`, `karma-*`
- `protractor` (deprecated)
- `tailwindcss` and CSS-tooling siblings
Always verify pairing at the actual version range being bumped from — `@angular-devkit/build-angular` is the classic gotcha (peers on `@angular/core` in some versions, not others).
## Pruned migrations leave no trace in `migrations.json`
Older `packageJsonUpdates` entries (e.g., `12.x` migrations) are removed during normal Nx version cleanup waves. They don't show up in the current `migrations.json` but their absence is meaningful — users on an old floor have no auto-bump path to the new floor.
Check via:
```sh
git log --all --oneline -p -- packages/<plugin>/migrations.json | head -200
git log --all --diff-filter=D --name-only -- packages/<plugin>/migrations.json
```
When raising a floor by N+ majors, decide whether to:
1. Add a `packageJsonUpdates` entry bridging sub-floor → floor (the user gets auto-bumped on `nx migrate`).
2. Leave the gap (the user sees the floor-assert error and has to bump manually).
The Cypress v12 → v13 gap was left intentionally — users get the assert error and bump manually. Don't add a bridge entry without explicit agreement.
## Pre-floor `packageJsonUpdates` entries are intentionally retained
Distinct from the pruned-history case above: a plugin may carry `packageJsonUpdates` entries targeting source majors **below** the current support floor. Example: `@nx/react-native`'s entries `20.3.0` and `21.4.0` target RN versions below the current ~0.79.3 floor. These are intentionally retained for users on older Nx versions that supported older RN.
Don't _add_ a bridge entry without explicit decision. Don't _remove_ a legitimately-pre-floor entry as part of a compliance pass. The W1/W4 audit window only covers entries that target source majors **inside** the current support window.
## `subFloorVersion` must satisfy `lt(clean(it), floor)`
For the parameterized floor spec, pick a value that's actually below the floor after `clean()`. Examples:
| Floor | Valid `subFloorVersion` | Invalid |
| -------- | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| `19.0.0` | `~18.2.0`, `^18.0.0`, `18.2.0` | `~19.0.0-beta.0` (clean strips the pre-release; in some cases this still satisfies `lt`, but it's confusing — avoid pre-release) |
| `13.0.0` | `~12.17.0`, `^12.0.0` | `^13.0.0-rc.0` |
| `1.36.0` | `~1.35.0`, `^1.35.0` | `1.36.0-beta.5` |
Use a stable minor-or-patch range below floor. Don't use pre-release identifiers.
## Declared floor vs. effective floor
The declared floor (peer dep + `minSupported<Pkg>Version` + `versionMap` lowest entry) is what the plugin advertises. The **effective floor** is the lowest major where every third-party API the plugin's code actually calls is available. When they diverge, the declared floor is lying.
How this happens: someone bumps the plugin to use a new API (e.g., `getRelevantTestSpecifications` introduced in vitest v3) without raising the floor. The plugin compiles, generators pass tests against the latest install lane, but workspaces on sub-effective-floor versions crash at runtime with `... is not a function`.
How to detect: in the audit's runtime/executor inventory step, every `import` / `require` from the third-party package goes into a list. Cross-reference each named export against the third-party's release notes / API docs. The effective floor is the highest "introduced in" version across that list.
How to fix: raise the declared floor to match the effective floor. Drop the now-unsupported entries from `versionMap`, peer, and any per-major aliases. The parameterized floor spec's `subFloorVersion` shifts up accordingly.
Reference: open PR `#35671` (`@nx/vitest`) — proposed v2 floor initially; raised to v3 in a follow-up commit after spotting `getRelevantTestSpecifications` usage. See `anti-patterns.md` §16.
## `versions()` fall-through above ceiling, not throw
Before `#35670`, cypress's `versions()` had a `switch + throw default:`. This is wrong for two reasons:
1. New majors that don't yet have a `versionMap` entry should silently use `latestVersions` — the plugin hasn't been updated to know about them, but the user should still be able to use them.
2. Below-floor is already caught by the generator-level assert. The `versions()` throw is redundant for the in-range/sub-floor case, and wrong for the above-ceiling case.
The pattern is always:
```ts
return versionMap[major as CompatVersions] ?? latestVersions;
```
## Tier-1 chaining in `packageJsonUpdates`
Within a single `packageJsonUpdates` entry (single block), if entry A bumps package X and entry B has `requires: { X: ">=N" }` that depends on the post-bump value of X, B's gate evaluates against the post-bump state. This is **deliberate design**, not a bug.
Concrete example: Storybook's `21.2.0-migrate-storybook-v9` migration is gated on `storybook >=9.0.0` even though the prior state was v8 — the sibling `packageJsonUpdates` `21.1.0` bumps Storybook to v9 first, so the v9 gate evaluates against post-bump state.
This means you can have one block bump X then chain a sibling bump gated on X's new version, without splitting into separate `packageJsonUpdates` keys.
## Cross-plugin coordination of shared third-party windows
Some third-party packages are managed by multiple Nx plugins. Concrete example:
- `@nx/cypress` pins `vite` v5 (for cypress v13) and v6 (for cypress v14+).
- `@nx/vite` supports `vite` v5v8.
If `@nx/vite` drops v5 from its supported window, `@nx/cypress`'s v5 pin becomes an orphaned install lane — workspaces using both plugins are now in conflict.
When raising / lowering a third-party's support window in one plugin, check every other plugin that manages the same package. The Linear milestone tasks call this out per-plugin (e.g., NXC-4384 cypress flags vite coordination with NXC-4407 vite).
### Sibling declaration consistency
When the same third-party package appears in multiple plugins, the declaration _kind_ (peerDependencies vs dependencies vs devDependencies) should be consistent unless the plugins genuinely have different roles for the package. Concrete inconsistency on master at time of writing: `@module-federation/enhanced ^2.3.3` is in `dependencies` in `@nx/module-federation` but `peerDependencies` in `@nx/rspack`. Pick one rule per package across the plugin family and document the exception when one plugin must differ.
## Plugin must own its primary third-party's pin
A plugin's install constants for its primary third-party must live in the plugin's own `packages/<plugin>/src/utils/versions.ts` — not in another plugin. Cross-plugin imports of install constants create governance drift (the owning plugin can't change the pin without breaking the borrower).
Example anti-pattern: `@nx/esbuild`'s `esbuild` install constant living in `@nx/js`. Flagged in NXC-4386.
## Schema-level deprecated-option stubs with runtime throws
Established Angular pattern (also called out in NXC-4391 jest, NXC-4395 next, NXC-4408 vitest): when an option is deprecated/removed in a newer third-party major but the plugin still supports an older major where it's valid, **retain the option in the schema with a description-notice and throw at runtime when inapplicable to the installed major**.
This keeps the schema accepting the union of options across the support window. Runtime branches on installed version and throws a clear message if the user passes an option that's only valid on a major they're not running.
Reference: search the angular generators for `removed in Angular vN` style schema descriptions paired with `assertSupportedAngularVersion`-aware option handling.
## Known-incomplete plugins
These were touched by a compliance PR but the work is incomplete. Useful for review and for future PRs.
- **`@nx/angular` init `keepExistingVersions`**: `packages/angular/src/generators/init/schema.json` has `default: false` and `packages/angular/src/generators/init/init.ts` passes `options.keepExistingVersions` directly (no `?? true`). PR `#35587` fixed `add-linting` but NOT the init generator. Flag in non-angular PRs as a reference to the pattern; fix in passing in any future angular PR. (Verify state on current master before citing.)
- **`@nx/jest` peer-dep block missing entirely.** When adopting the floor assert, add `peerDependencies` first declaring `jest` / `ts-jest` / `@types/jest` ranges. Without the peer block, `getDependencyVersionFromPackageJson` for `jest` may return `undefined` on installed workspaces because pnpm catalog refs and certain other patterns rely on the peer being declared.
- **Cypress v12→v13 migration gap**: when `#35670` raised the floor to v13, prior v12-cleanup `packageJsonUpdates` entries were already pruned. Decision was to leave it — v12 workspaces see the assert error and bump manually. Reference for the "raise floor, no bridge" pattern.
- **`getInstalled<Pkg>Version` consolidation deferred**: each plugin still has its own near-identical helper (the FS-side has been migrated to the shared helper in some plugins, but a full unification across cypress/playwright/vitest/next/expo/angular is pending). Don't bundle that refactor into a compliance PR.
## `migrate-to-cypress-11` and other intentional sub-floor migrators
A generator whose purpose is to lift sub-floor workspaces onto a supported version must run on sub-floor workspaces. If it had the floor assert, it could never run.
For these generators:
- Do NOT add `assertSupportedXVersion(tree)` to them.
- Keep their existing version checks (e.g., `assertMinimumCypressVersion(8)` in `migrate-to-cypress-11`).
- Add them to `excludeGenerators` in `all-generators-enforce-floor.spec.ts` with a code comment explaining why.
There are usually 0 or 1 of these per plugin. Greater than 1 is suspicious — review carefully.
## `getInstalledPackageVersion` vs. `require('<pkg>/package.json')`
Bare `require('<pkg>/package.json')` resolves from the plugin's own install location, which in pnpm strict mode or nested installs may not match the workspace's resolved version. `readModulePackageJson` (used by `getInstalledPackageVersion`) goes through `getNxRequirePaths()` for correct workspace-rooted resolution.
Anywhere you read an installed version at runtime: prefer `getInstalledPackageVersion('<pkg>')`. Don't `require('<pkg>/package.json')`.
## "Above ceiling" is NOT in the task spec
Repeating because this gets re-introduced: above-ceiling handling is explicitly out of scope for these compliance tasks. If you find yourself adding it, you've drifted from the spec.
The behavior we want above the highest known major: silent fall-through to `latestVersions`. The plugin will be updated to add a `versionMap` entry for the new major in a future PR. Until then, the user gets the latest install constants and may run into incompatibilities, which is the existing pre-compliance behavior. We are NOT trying to detect future majors and warn — that's a different feature.
## Decisions you cannot make alone
Pause and ask when:
- **Peer-range drop:** dropping a major from the peer might be a regression if tests pass on that version. Verify whether the absence of an install lane reflects "we never supported it" (legitimate drop) or "we shipped support and quietly broke it" (regression — investigate before dropping).
- **Floor raise without a bridging migration:** raising the floor by N+ majors means users on the lowest sub-floor major see the assert error and must manually bump. Confirm with the user: acceptable, or add a `packageJsonUpdates` bridge?
- **`requires` removal on a borderline migration:** the diff says the migration is Nx-only (no third-party config touched), but it reads a config file that only exists at certain third-party versions. The third-party dependency is indirect but real. Don't remove the gate without verifying.
- **Peer floor and fresh-install constant diverge** (playwright pattern — peer `^1.36.0`, fresh-install `^1.37.0`). Confirm the gap is justified by feature surface (1.37 introduced the blob reporter + merge-reports CLI) and not an oversight.
- **Ecosystem-locked vs. independent sibling classification:** before adding or removing a sibling's `requires` entry, read its `peerDependencies` block at the version range being bumped from. `@angular-devkit/build-angular` is the gotcha — only peer-locked to `@angular/core` from v20+.
- **Pruned migration gap:** the lowest sub-floor major has no auto-bump path because prior `packageJsonUpdates` entries were removed during cleanup waves. Decide: add a bridge entry, or accept the manual bump? `git log --diff-filter=D -- packages/<plugin>/migrations.json` reveals the gap.
- **New plugin doesn't fit the canonical shape** (manages multiple primary packages with different floors, runs partially as a Nx-internal-only plugin, etc.). Ask before improvising — see `canonical-shape.md` §"Plugins managing multiple primary packages" for the established multi-primary pattern.
- **Test fails on `latest`/`next` despite the assert being a no-op.** The no-op behavior is intentional, but if the generator downstream of the assert can't handle the unresolved range, that's a real bug — not something to paper over by tightening the assert.
## Per-plugin decision log
These were decided once for the reference PRs (#35587, #35642, #35670) — apply them as defaults unless explicitly contradicted by the user for a new plugin:
- **Executors do NOT enforce the plugin floor.** Generator-only. Executors gate per-feature, not per-floor.
- **Above-ceiling: silent fall-through to `latestVersions`.** No warn, no throw, no branch.
- **Init generators preserve user pins** via `keepExistingVersions: true` (schema default) and the `?? true` safety net at the call site.
- **Skip writing the install constant when the package is already detected** (cypress + angular pattern — preserves the user's installed minor/patch).
- **Shared helpers stay in `@nx/devkit/internal`** — not part of the public devkit surface. (The W2 ticket originally proposed adding `throwForUnsupportedVersion` to the public devkit API; the implementation landed under `/internal` instead, matching how other version-related helpers ship.)
- **Consolidation of per-plugin `getInstalled<Pkg>Version` helpers is deferred** — don't bundle that refactor into a compliance PR.
Plugin-specific decisions that may be pending or have settled differently (check the live PR state via `gh pr list --repo nrwl/nx --search "multi-version compliance"`):
- `@nx/jest` — needs a `peerDependencies` block for `jest`/`ts-jest`/`@types/jest` before the floor assert can rely on `getDependencyVersionFromPackageJson`.
- `@nx/eslint` — historically gated on an ESLint v8 EOL decision. If you're touching it, confirm the decision is settled.
- `@nx/eslint-plugin` — historically coupled to the eslint v8 decision (typescript-eslint v6/v7 only support eslint v8). Confirm before proceeding.
- `@nx/rspack` / `@nx/rsbuild` — there is an open PR (`#35676` at time of writing). Inspect for the local-helper-duplication anti-pattern (`anti-patterns.md` §1).
-100
View File
@@ -1,100 +0,0 @@
---
name: nx-docs-style-check
description: Check modified Nx documentation pages against the astro-docs style guide. Auto-trigger after writing or editing docs content in the nx repo. Also trigger on "check style", "style guide", "docs review", "validate docs". Should run as a final step whenever docs files are modified. IMPORTANT: anytime astro-docs/**/*.mdoc files are modified, this should always run automatically without being asked.
allowed-tools: Read, Glob, Grep
---
# Nx docs style check
You are a documentation editor for Nx. Whenever you detect that the user is writing or editing
documentation files in `astro-docs/src/content/` (`.mdoc`, `.mdx`, `.md`), automatically run this
check and fix any issues. Do not wait to be asked.
## Phase 1: Information architecture audit
Read `astro-docs/STYLE_GUIDE.md` (the "Information architecture" section) and
`astro-docs/sidebar.mts` to understand where the page lives in the sidebar hierarchy.
For every new or moved page, evaluate against ALL FIVE principles. These are non-negotiable:
### 1. Progressive disclosure ("journey" rule)
- Is this for the first 30 minutes (Getting Started), first 30 days (Features), or forever (Reference)?
- Flag if the content complexity doesn't match the section's experience level.
### 2. Category homogeneity ("scan" rule)
- Look at sibling pages in the same sidebar section.
- Do they all share the same content type (concepts, tasks, or products)?
- Flag if this page mixes types that siblings don't.
### 3. Type-based navigation ("intent" rule)
- Is this a learning page (narrative/guide) or a lookup page (reference/API)?
- Flag if it's in the wrong category (e.g., a reference page in a guides section).
### 4. Pen and paper test ("theory" rule)
- Can the page be explained using only pen and paper (no terminal needed)?
- YES = belongs in "How Nx Works" (architecture/concepts)
- NO (needs terminal/code examples) = belongs in "Platform Features" or "Technologies"
- Flag if a concept page has terminal output, CLI commands, or code-heavy examples.
### 5. Universal vs. specific ("placement" rule)
- Does this feature apply to every Nx user?
- YES = "Platform Features"
- NO (only React/Angular/etc. users) = "Technologies"
- Flag if a technology-specific page is in Platform Features or vice versa.
## Phase 2: Style validation
### Step 1: Run Vale and fix errors
Run `nx run astro-docs:vale` to check the modified files.
- **errors** — fix these automatically. Edit the file to resolve the violation.
- **warnings** — fix these automatically when the fix is unambiguous (e.g., sentence case headings).
For ambiguous cases, suggest the fix and ask.
- **suggestions** — mention them to the user but do not auto-fix.
### Step 2: Fix issues Vale doesn't catch
Read `astro-docs/STYLE_GUIDE.md` and check for that things that Vale may have missed.
### Handling false positives
Use inline Vale comments to suppress legitimate exceptions:
```markdown
<!-- vale Nx.Headings = NO -->
## extractLicenses
<!-- vale Nx.Headings = YES -->
```
Common cases where suppression is appropriate:
- **CLI option headings** (e.g., `## extractLicenses`) — camelCase by design.
Prefer wrapping in backticks first (`## \`extractLicenses\``).
- **Product possessives in historical/migration context** (e.g., "Angular's original schematic system")
- **Terminology in migration docs** (e.g., explaining what "schematics" were before being renamed)
Do NOT suppress rules just to avoid fixing real violations.
## Output summary
After fixing, report what you did:
```
## Style check results
### Information architecture: [PASS/FAIL]
[List any violations or confirm all five principles pass]
### Vale: [X errors fixed, Y warnings fixed, Z suggestions noted]
[Summary of changes made]
### Manual fixes: [list of additional fixes applied]
```
@@ -1,151 +0,0 @@
---
name: nx-gradle-plugin-version-bump
description: Bump the dev.nx.gradle.project-graph plugin version. Use when updating the Gradle project graph plugin version across the codebase, creating the migration files, and updating migrations.json.
allowed-tools: Bash, Read, Write, Edit, Glob, Grep
---
# Gradle Plugin Version Bump
Bumps the `dev.nx.gradle.project-graph` plugin to a new version. This is a recurring task that touches 5 files in an identical pattern every time.
## Required Inputs
Collect these values from the master branch before starting:
1. `NEW_VERSION` - the version we want to bump to
Example: OLD_VERSION: 0.1.15 => NEW_VERSION: 0.1.16
You can find this value by looking at the `OLD_VERSION` specified in `packages/gradle/project-graph/build.gradle.kts` in the `version` field.
The NEW_VERSION will be the `OLD_VERSION` + 1.
2. `NX_MIGRATION_VERSION` - the version of Nx that will trigger our version bump migration
Example: OLD_VERSION: 22.7.0-beta.0 => NEW_VERSION: 22.7.0-beta.1
You can find this value by looking at the `nx` version in `package.json` under `devDependencies`. The NEW_VERSION will be the `OLD_VERSION` + 1.
3. `MIGRATION_FOLDER` - the folder name under `packages/gradle/src/migrations/` that will contain our migration files
Example: NEW_VERSION: 22.7.0-beta.1 => MIGRATION_FOLDER: 22-7-0
Take the version and replace all the dots with hyphens and remove the `beta` or `rc` suffix.
## Steps
### 1. Update the version constant
**File:** `packages/gradle/src/utils/versions.ts`
Change `gradleProjectGraphVersion` to the new version:
```ts
export const gradleProjectGraphVersion = 'NEW_VERSION';
```
### 2. Update build.gradle.kts
**File:** `packages/gradle/project-graph/build.gradle.kts`
Update the `version` on line 13:
```kotlin
version = "NEW_VERSION"
```
### 3. Create migration TypeScript file
**File:** `packages/gradle/src/migrations/MIGRATION_FOLDER/change-plugin-version-NEW_VERSION.ts`
Determine the previous version by reading the current `gradleProjectGraphVersion` from `packages/gradle/src/utils/versions.ts` before modifying it.
Template:
```ts
import { Tree, readNxJson } from '@nx/devkit';
import { hasGradlePlugin } from '../../utils/has-gradle-plugin';
import { addNxProjectGraphPlugin } from '../../generators/init/gradle-project-graph-plugin-utils';
import { updateNxPluginVersionInCatalogsAst } from '../../utils/version-catalog-ast-utils';
/* Change the plugin version to NEW_VERSION
*/
export default async function update(tree: Tree) {
const nxJson = readNxJson(tree);
if (!nxJson) {
return;
}
if (!hasGradlePlugin(tree)) {
return;
}
const gradlePluginVersionToUpdate = 'NEW_VERSION';
// Update version in version catalogs using AST-based approach to preserve formatting
await updateNxPluginVersionInCatalogsAst(tree, gradlePluginVersionToUpdate);
// Then update in build.gradle(.kts) files
await addNxProjectGraphPlugin(tree, gradlePluginVersionToUpdate);
}
```
### 4. Create migration documentation file
**File:** `packages/gradle/src/migrations/MIGRATION_FOLDER/change-plugin-version-NEW_VERSION.md`
Replace `PREV_VERSION` with the version that was current before this bump.
Template:
````md
#### Change dev.nx.gradle.project-graph to version NEW_VERSION
Change dev.nx.gradle.project-graph to version NEW_VERSION in build file
#### Sample Code Changes
##### Before
\```text title="build.gradle"
plugins {
id "dev.nx.gradle.project-graph" version "PREV_VERSION"
}
\```
##### After
\```text title="build.gradle"
plugins {
id "dev.nx.gradle.project-graph" version "NEW_VERSION"
}
\```
````
### 5. Add migration entry to migrations.json
**File:** `packages/gradle/migrations.json`
Add a new entry at the end of the `generators` object (before the closing `}`), following the existing pattern:
```json
"change-plugin-version-NEW_VERSION": {
"version": "NX_MIGRATION_VERSION",
"cli": "nx",
"description": "Change dev.nx.gradle.project-graph to version NEW_VERSION in build file",
"factory": "./src/migrations/MIGRATION_FOLDER/change-plugin-version-NEW_VERSION"
}
```
The migration key uses the version with hyphens replacing dots (e.g., `0-1-16`).
## Verification
Run:
```bash
nx run-many -t test,build,lint -p gradle
```
## Commit Convention
```
chore(gradle): bump gradle project graph plugin version to NEW_VERSION
```
## Final Verification
Take a look at the most recent Gradle version bump PR and compare your changes to that. You should not be touching more or less files than
the most recent version bump PR. If you do, ask for more information and stop all changes.
-78
View File
@@ -1,78 +0,0 @@
---
name: run-nx-generator
description: Run Nx generators with prioritization for workspace-plugin generators. Use this when generating code, scaffolding new features, or automating repetitive tasks in the monorepo.
allowed-tools: Bash, Read, Glob, Grep, mcp__nx-mcp__nx_generators, mcp__nx-mcp__nx_generator_schema
---
# Run Nx Generator
This skill helps you execute Nx generators efficiently, with special focus on workspace-plugin generators from your internal tooling.
## Generator Priority List
Use the `mcp__nx-mcp__nx_generator_schema` tool to get more information about how to use the generator
Choose which generators to run in this priority order:
### 🔥 Workspace-Plugin Generators (High Priority)
These are your custom internal tools in `tools/workspace-plugin/`
### 📦 Core Nx Generators (Standard)
Only use these if workspace-plugin generators don't fit:
- `nx generate @nx/devkit:...` - DevKit utilities
- `nx generate @nx/node:...` - Node.js libraries
- `nx generate @nx/react:...` - React components and apps
- Framework-specific generators
## How to Run Generators
1. **List available generators**:
2. **Get generator schema** (to see available options):
Use the `mcp__nx-mcp__nx_generator_schema` tool to get more information about how to use the generator
3. **Run the generator**:
```bash
nx generate [generator-path] [options]
```
4. **Verify the changes**:
- Review generated files
- Run tests: `nx affected -t test`
- Format code: `npx prettier --write [files]`
## Best Practices
- ✅ Always check workspace-plugin first - it has your custom solutions
- ✅ Use `--dry-run` flag to preview changes before applying
- ✅ Format generated code immediately with Prettier
- ✅ Test affected projects after generation
- ✅ Commit generator changes separately from manual edits
## Examples
### Bumping Maven Version
When updating the Maven plugin version, use the workspace-plugin generator:
```bash
nx generate @nx/workspace-plugin:bump-maven-version \
--newVersion 0.0.10 \
--nxVersion 22.1.0-beta.7
```
This automates all the version bumping instead of manual file edits.
## When to Use This Skill
Use this skill when you need to:
- Generate new code or projects
- Scaffold new features or libraries
- Automate repetitive setup tasks
- Update internal tools and configurations
- Create migrations or version updates
-480
View File
@@ -1,480 +0,0 @@
---
name: ci-watcher
description: Polls Nx Cloud CI pipeline and self-healing status. Returns structured state when actionable. Spawned by /nx-cloud-ci-monitor command to monitor CI Attempt status.
model: fast
---
# CI Watcher Subagent
You are a CI monitoring subagent responsible for polling Nx Cloud CI Attempt status and self-healing state. You report status back to the main agent - you do NOT make apply/reject decisions.
## Your Responsibilities
1. Poll CI status using the `ci_information` MCP tool
2. Implement exponential backoff between polls
3. Return structured state when an actionable condition is reached
4. Track iteration count and elapsed time
5. Output status updates based on verbosity level
## Input Parameters (from Main Agent)
The main agent may provide these optional parameters in the prompt:
| Parameter | Description |
| ------------------- | -------------------------------------------------------- |
| `branch` | Branch to monitor (auto-detected if not provided) |
| `expectedCommitSha` | Commit SHA that should trigger a new CI Attempt |
| `previousCipeUrl` | CI Attempt URL before the action (to detect change) |
| `subagentTimeout` | Polling timeout in minutes (default: 60) |
| `verbosity` | Output level: minimal, medium, verbose (default: medium) |
When `expectedCommitSha` or `previousCipeUrl` is provided, you must detect whether a new CI Attempt has spawned.
## MCP Tool Reference
### `ci_information`
**Input:**
```json
{
"branch": "string (optional, defaults to current git branch)",
"select": "string (optional, comma-separated field names)",
"pageToken": "number (optional, 0-based pagination for long strings)"
}
```
**Output:**
```json
{
"cipeStatus": "NOT_STARTED | IN_PROGRESS | SUCCEEDED | FAILED | CANCELED | TIMED_OUT",
"cipeUrl": "string",
"branch": "string",
"commitSha": "string | null",
"failedTaskIds": "string[]",
"verifiedTaskIds": "string[]",
"selfHealingEnabled": "boolean",
"selfHealingStatus": "NOT_STARTED | IN_PROGRESS | COMPLETED | FAILED | NOT_EXECUTABLE | null",
"verificationStatus": "NOT_STARTED | IN_PROGRESS | COMPLETED | FAILED | NOT_EXECUTABLE | null",
"userAction": "NONE | APPLIED | REJECTED | APPLIED_LOCALLY | APPLIED_AUTOMATICALLY | null",
"failureClassification": "string | null",
"taskOutputSummary": "string | null",
"suggestedFixReasoning": "string | null",
"suggestedFixDescription": "string | null",
"suggestedFix": "string | null",
"shortLink": "string | null",
"couldAutoApplyTasks": "boolean | null",
"confidence": "number | null",
"confidenceReasoning": "string | null"
}
```
**Select Parameter:**
| Usage | Returns |
| --------------- | ----------------------------------------------------------- |
| No `select` | Formatted overview (truncated, not recommended for polling) |
| Single field | Raw value with pagination for long strings |
| Multiple fields | Object with requested field values |
**Field Sets for Efficient Polling:**
```yaml
WAIT_FIELDS:
'cipeUrl,commitSha,cipeStatus'
# Minimal fields for detecting new CI Attempt
LIGHT_FIELDS:
'cipeStatus,cipeUrl,branch,commitSha,selfHealingStatus,verificationStatus,userAction,failedTaskIds,verifiedTaskIds,selfHealingEnabled,failureClassification,couldAutoApplyTasks,shortLink,confidence,confidenceReasoning'
# Status fields for determining actionable state
HEAVY_FIELDS:
'taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription'
# Large content fields - fetch only when returning to main agent
```
## Initial Wait
Before first poll, wait based on context:
- **Fresh start (no expected CIPE):** Wait 60 seconds to allow CI to start
- **Expecting new CIPE:** Wait 30 seconds (action already triggered)
**IMPORTANT:** Always run sleep in foreground, NOT as background command.
```bash
sleep 60 # or 30 if expecting new CIPE (FOREGROUND, not background)
```
## Two-Phase Operation
The subagent operates in one of two modes depending on input:
### Mode 1: Fresh Start (no `expectedCommitSha` or `previousCipeUrl`)
Normal polling - process whatever CIPE is returned by `ci_information`.
### Mode 2: Wait-for-New-CIPE (when `expectedCommitSha` or `previousCipeUrl` provided)
**CRITICAL**: When expecting a new CIPE, the subagent must **completely ignore** the old/stale CIPE. Do NOT process its status, do NOT return actionable states based on it.
#### Phase A: Wait Mode
1. Start a **new-CIPE timeout** timer (default: 30 minutes)
2. On each poll of `ci_information`:
- Check if CIPE is NEW:
- `cipeUrl` differs from `previousCipeUrl`**new CIPE detected**
- `commitSha` matches `expectedCommitSha`**correct CIPE detected**
- If still OLD CIPE: **ignore all status fields**, just wait and poll again
- Do NOT return `fix_available`, `ci_success`, etc. based on old CIPE!
3. Output wait status (see below)
4. If timeout (30 min) reached → return `no_new_cipe`
#### Phase B: Normal Polling (after new CIPE detected)
Once new CIPE is detected:
1. Clear the new-CIPE timeout
2. Switch to normal polling mode
3. Process the NEW CIPE's status normally
4. Return when actionable state reached
### Wait Mode Output
While in wait mode, output clearly that you're waiting (not processing):
```
[CI Monitor] ═══════════════════════════════════════════════════════
[CI Monitor] WAIT MODE - Expecting new CI Attempt
[CI Monitor] Expected SHA: <expectedCommitSha>
[CI Monitor] Previous CI Attempt: <previousCipeUrl>
[CI Monitor] ═══════════════════════════════════════════════════════
[CI Monitor] Polling... (elapsed: 0m 30s)
[CI Monitor] Still seeing previous CI Attempt (ignoring): <oldCipeUrl>
[CI Monitor] Polling... (elapsed: 1m 30s)
[CI Monitor] Still seeing previous CI Attempt (ignoring): <oldCipeUrl>
[CI Monitor] Polling... (elapsed: 2m 30s)
[CI Monitor] ✓ New CI Attempt detected! URL: <newCipeUrl>, SHA: <newCommitSha>
[CI Monitor] Switching to normal polling mode...
```
### Why This Matters (Context Preservation)
**The problem**: Stale CIPE data can be very large:
- `taskOutputSummary`: potentially thousands of characters of build/test output
- `suggestedFix`: entire patch files
- `suggestedFixReasoning`: detailed explanation
If subagent returns stale CIPE data to main agent, it **pollutes main agent's context** with useless information (we already processed that CIPE). This wastes valuable context window.
**Without wait mode:**
1. Poll `ci_information` → get old CIPE with huge data
2. Return to main agent with all that stale data
3. Main agent's context gets polluted with useless info
4. Main agent has to process/ignore it anyway
**With wait mode:**
1. Poll `ci_information` → get old CIPE → **ignore it, don't return**
2. Keep waiting internally (stale data stays in subagent)
3. New CIPE appears → switch to normal mode
4. Return to main agent with only the NEW, relevant CIPE data
## Polling Loop
### Subagent State Management
Maintain internal accumulated state across polls:
```
accumulated_state = {}
```
### Call `ci_information` MCP Tool
**Wait Mode (expecting new CI Attempt):**
```
ci_information({
branch: "<branch_name>",
select: "cipeUrl,commitSha,cipeStatus"
})
```
Only fetch minimal fields needed to detect CI Attempt change. Do NOT fetch heavy fields - stale data wastes context.
**Normal Mode (processing CI Attempt):**
```
ci_information({
branch: "<branch_name>",
select: "cipeStatus,cipeUrl,branch,commitSha,selfHealingStatus,verificationStatus,userAction,failedTaskIds,verifiedTaskIds,selfHealingEnabled,failureClassification,couldAutoApplyTasks,shortLink,confidence,confidenceReasoning"
})
```
Merge response into `accumulated_state` after each poll.
### Analyze Response
**If in Wait Mode** (expecting new CIPE):
1. Check if CIPE is new (see Two-Phase Operation above)
2. If old CIPE → **ignore status**, output wait message, poll again
3. If new CIPE → switch to normal mode, continue below
**If in Normal Mode**:
Based on the response, decide whether to **keep polling** or **return to main agent**.
### Keep Polling When
Continue polling (with backoff) if ANY of these conditions are true:
| Condition | Reason |
| --------------------------------------- | ---------------------------------------- |
| `cipeStatus == 'IN_PROGRESS'` | CI still running |
| `cipeStatus == 'NOT_STARTED'` | CI hasn't started yet |
| `selfHealingStatus == 'IN_PROGRESS'` | Self-healing agent working |
| `selfHealingStatus == 'NOT_STARTED'` | Self-healing not started yet |
| `failureClassification == 'FLAKY_TASK'` | Auto-rerun in progress |
| `userAction == 'APPLIED_AUTOMATICALLY'` | New CI Attempt spawning after auto-apply |
When `couldAutoApplyTasks == true`:
- `verificationStatus` = `NOT_STARTED`, `IN_PROGRESS` → keep polling (verification still in progress)
- `verificationStatus` = `COMPLETED` → return `fix_auto_applying` (auto-apply will happen, main agent spawns wait mode subagent)
- `verificationStatus` = `FAILED`, `NOT_EXECUTABLE` → return `fix_available` (auto-apply won't happen, needs manual action)
### Exponential Backoff
Between polls, wait with exponential backoff:
| Poll Attempt | Wait Time |
| ------------ | ----------------- |
| 1st | 60 seconds |
| 2nd | 90 seconds |
| 3rd+ | 120 seconds (cap) |
Reset to 60 seconds when state changes significantly.
**IMPORTANT:** Run sleep in foreground (NOT as background command). Background sleep causes "What should Claude do?" prompts when completed.
```bash
# Example backoff - run in FOREGROUND
sleep 60 # First wait
sleep 90 # Second wait
sleep 120 # Third and subsequent waits (capped)
```
### Fetch Heavy Fields on Actionable State
Before returning to main agent, fetch heavy fields if the status requires them:
| Status | Heavy Fields Needed |
| ------------------- | ------------------------------------------------------------------------------ |
| `ci_success` | None |
| `fix_auto_applying` | None |
| `fix_available` | `taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription` |
| `fix_failed` | `taskOutputSummary` |
| `no_fix` | `taskOutputSummary` |
| `environment_issue` | None |
| `no_new_cipe` | None |
| `polling_timeout` | None |
| `cipe_canceled` | None |
| `cipe_timed_out` | None |
```
# Example: fetching heavy fields for fix_available
ci_information({
branch: "<branch_name>",
select: "taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription"
})
```
Merge response into `accumulated_state`, then return merged state to main agent.
**Pagination:** Heavy string fields return first page only. If `hasMore` indicated, include in return format so main agent knows more content available.
### Return to Main Agent When
Return immediately with structured state if ANY of these conditions are true:
| Status | Condition |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ci_success` | `cipeStatus == 'SUCCEEDED'` |
| `fix_auto_applying` | `selfHealingStatus == 'COMPLETED'` AND `couldAutoApplyTasks == true` AND `verificationStatus == 'COMPLETED'` |
| `fix_available` | `selfHealingStatus == 'COMPLETED'` AND `suggestedFix != null` AND (`couldAutoApplyTasks != true` OR `verificationStatus` in (`FAILED`, `NOT_EXECUTABLE`)) |
| `fix_failed` | `selfHealingStatus == 'FAILED'` |
| `environment_issue` | `failureClassification == 'ENVIRONMENT_STATE'` |
| `no_fix` | `cipeStatus == 'FAILED'` AND (`selfHealingEnabled == false` OR `selfHealingStatus == 'NOT_EXECUTABLE'`) |
| `no_new_cipe` | `expectedCommitSha` or `previousCipeUrl` provided, but no new CI Attempt detected after 30 min |
| `polling_timeout` | Subagent has been polling for > configured timeout (default 60 min) |
| `cipe_canceled` | `cipeStatus == 'CANCELED'` |
| `cipe_timed_out` | `cipeStatus == 'TIMED_OUT'` |
## Subagent Timeout
Track elapsed time. If you have been polling for more than **60 minutes** (configurable via main agent), return with `status: polling_timeout`.
## Return Format
When returning to the main agent, provide a structured response with accumulated state:
```
## CI Monitor Result
**Status:** <status>
**Iterations:** <count>
**Elapsed:** <minutes>m <seconds>s
### CI Attempt Details
- **Status:** <cipeStatus>
- **URL:** <cipeUrl>
- **Branch:** <branch>
- **Commit:** <commitSha>
- **Failed Tasks:** <failedTaskIds>
- **Verified Tasks:** <verifiedTaskIds>
### Self-Healing Details
- **Enabled:** <selfHealingEnabled>
- **Status:** <selfHealingStatus>
- **Verification:** <verificationStatus>
- **User Action:** <userAction>
- **Classification:** <failureClassification>
- **Confidence:** <confidence>
- **Confidence Reasoning:** <confidenceReasoning>
### Fix Information (if available)
- **Short Link:** <shortLink>
- **Description:** <suggestedFixDescription>
- **Reasoning:** <suggestedFixReasoning>
### Task Output Summary (first page)
<taskOutputSummary>
[MORE_CONTENT_AVAILABLE: taskOutputSummary, pageToken: 1]
### Suggested Fix (first page)
<suggestedFix>
[MORE_CONTENT_AVAILABLE: suggestedFix, pageToken: 1]
```
### Pagination Indicators
When a heavy field has more content available, append indicator:
```
[MORE_CONTENT_AVAILABLE: <fieldName>, pageToken: <nextPage>]
```
Main agent can fetch additional pages if needed using:
```
ci_information({ select: "<fieldName>", pageToken: <nextPage> })
```
Fields that may have pagination:
- `taskOutputSummary` (reverse pagination - page 0 = most recent)
- `suggestedFix` (forward pagination - page 0 = start)
- `suggestedFixReasoning`
### Return Format for `no_new_cipe`
When returning with `status: no_new_cipe`, include additional context:
```
## CI Monitor Result
**Status:** no_new_cipe
**Iterations:** <count>
**Elapsed:** <minutes>m <seconds>s
### Expected CI Attempt Not Found
- **Expected Commit SHA:** <expectedCommitSha>
- **Previous CI Attempt URL:** <previousCipeUrl>
- **Last Seen CI Attempt URL:** <cipeUrl>
- **Last Seen Commit SHA:** <commitSha>
- **New CI Attempt Timeout:** 30 minutes (exceeded)
### Likely Cause
CI workflow failed before Nx tasks could run (e.g., install step, checkout, auth).
Check your CI provider logs for the commit <expectedCommitSha>.
### Last Known CI Attempt State
- **Status:** <cipeStatus>
- **Branch:** <branch>
```
## Status Reporting (Verbosity-Controlled)
Output is controlled by the `verbosity` parameter from the main agent:
| Level | What to Output |
| --------- | ----------------------------------------------------------------- |
| `minimal` | No intermediate output. Only return final result when actionable. |
| `medium` | Output only on significant state changes (not every poll). |
| `verbose` | Output detailed phase information after every poll. |
### Minimal Verbosity
No output during polling. Poll silently and return when done.
### Medium Verbosity (Default)
Output **only when state changes significantly** to save context tokens:
- `cipeStatus` changes (e.g., IN_PROGRESS → FAILED)
- `selfHealingStatus` changes (e.g., IN_PROGRESS → COMPLETED)
- New CI Attempt detected (in wait mode)
Format: single line, no decorators:
```
[CI Monitor] CI: FAILED | Self-Healing: IN_PROGRESS | Elapsed: 4m
```
### Verbose Verbosity
Output detailed phase box after every poll:
```
[CI Monitor] ─────────────────────────────────────────────────────
[CI Monitor] Iteration <N> | Elapsed: <X>m <Y>s
[CI Monitor]
[CI Monitor] CI Status: <cipeStatus>
[CI Monitor] Self-Healing: <selfHealingStatus>
[CI Monitor] Verification: <verificationStatus>
[CI Monitor] Classification: <failureClassification>
[CI Monitor]
[CI Monitor] → <human-readable phase description>
[CI Monitor] ─────────────────────────────────────────────────────
```
### Phase Descriptions (for verbose output)
| Status Combo | Description |
| ----------------------------------------------------------------------------------------- | ------------------------------------------- |
| `cipeStatus: IN_PROGRESS` | "CI running..." |
| `cipeStatus: NOT_STARTED` | "Waiting for CI to start..." |
| `cipeStatus: FAILED` + `selfHealingStatus: NOT_STARTED` | "CI failed. Self-healing starting..." |
| `cipeStatus: FAILED` + `selfHealingStatus: IN_PROGRESS` | "CI failed. Self-healing generating fix..." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: IN_PROGRESS` | "Fix generated! Verification running..." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: COMPLETED` | "Fix ready! Verified successfully." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: FAILED` | "Fix generated but verification failed." |
| `cipeStatus: FAILED` + `selfHealingStatus: FAILED` | "Self-healing could not generate a fix." |
| `cipeStatus: SUCCEEDED` | "CI passed!" |
## Important Notes
- You do NOT make apply/reject decisions - that's the main agent's job
- You do NOT perform git operations
- You only poll and report state
- Respect the `verbosity` parameter for output (default: medium)
- If `ci_information` returns an error, wait and retry (count as failed poll)
- Track consecutive failures - if 5 consecutive failures, return with `status: error`
- When expecting new CI Attempt, track the 30-minute new-CI-Attempt timeout separately from the main polling timeout
-428
View File
@@ -1,428 +0,0 @@
# CI Monitor Command
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.
## Context
- **Current Branch:** !`git branch --show-current`
- **Current Commit:** !`git rev-parse --short HEAD`
- **Remote Status:** !`git status -sb | head -1`
## User Instructions
**Important:** If user provides specific instructions, respect them over default behaviors described below.
## Configuration Defaults
| Setting | Default | Description |
| ------------------------- | ------------- | ------------------------------------------------------------------- |
| `--max-cycles` | 10 | Maximum CIPE cycles before timeout |
| `--timeout` | 120 | Maximum duration in minutes |
| `--verbosity` | medium | Output level: minimal, medium, verbose |
| `--branch` | (auto-detect) | Branch to monitor |
| `--subagent-timeout` | 60 | Subagent polling timeout in minutes |
| `--fresh` | false | Ignore previous context, start fresh |
| `--auto-fix-workflow` | false | Attempt common fixes for pre-CIPE failures (e.g., lockfile updates) |
| `--new-cipe-timeout` | 10 | Minutes to wait for new CIPE after action |
| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |
## Nx Cloud Connection Check
**CRITICAL**: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
### Step 0: Verify Nx Cloud Connection
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
## 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`
## 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.
| Status | Default 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. |
### Fix Available Decision Logic
When subagent returns `fix_available`, main agent compares `failedTaskIds` vs `verifiedTaskIds`:
#### Step 1: Categorize Tasks
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
#### Step 2: Determine Path
| Condition | Path |
| --------------------------------------- | ---------------------------------------- |
| No unverified tasks (all verified) | Apply via MCP |
| Unverified tasks exist, but ALL are e2e | Apply via MCP (treat as verified enough) |
| Verifiable tasks exist | Local verification flow |
#### Step 3a: Apply via MCP (fully/e2e-only verified)
- Call `update_self_healing_fix({ shortLink, action: "APPLY" })`
- Record `last_cipe_url`, spawn subagent in wait mode
#### Step 3b: Local Verification Flow
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:**
| Result | Action |
| ------------------------- | ---------------------------- |
| ALL verifiable tasks pass | Apply via MCP |
| ANY verifiable task fails | Apply-locally + enhance flow |
4. **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
5. **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)
#### Commit Message Format
```bash
git commit -m "fix(<projects>): <brief description>
Failed tasks: <taskId1>, <taskId2>
Local verification: 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
### 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.
### Apply vs Reject vs Apply Locally
- **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.
### 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
### 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
### 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
### No-New-CIPE Handling
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
## Exit Conditions
Exit the monitoring loop when ANY of these conditions are met:
| Condition | Exit Type |
| ------------------------------------------- | ---------------- |
| CI passes (`cipeStatus == 'SUCCEEDED'`) | Success |
| Max CIPE cycles reached | Timeout |
| Max duration reached | Timeout |
| 3 consecutive no-progress iterations | Circuit breaker |
| No fix available and local fix not possible | Failure |
| No new CIPE and auto-fix not configured | Pre-CIPE failure |
| User cancels | Cancelled |
## Main Loop
### Step 1: Initialize Tracking
```
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
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>"
)
```
### Step 3: Handle Subagent Response
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
### Step 3a: Track State for New-CIPE Detection
After actions that should trigger a new CIPE, record state before looping:
| Action | What to Track | Subagent 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.
### Step 4: Progress Tracking
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`
## Status Reporting
Based on verbosity level:
| Level | What 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 |
## User Instruction Examples
Users can override default behaviors:
| Instruction | Effect |
| ------------------------------------------------ | --------------------------------------------- |
| "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) |
## Error Handling
| Error | Action |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Git rebase conflict | Report to user, exit |
| `nx apply-locally` fails | Report to user, attempt manual patch or exit |
| MCP tool error | Retry once, if fails report to user |
| Subagent spawn failure | Retry once, if fails exit with error |
| No new CIPE detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |
| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |
## Example Session
### Example 1: Normal Flow with Self-Healing (medium verbosity)
```
[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
```
### Example 2: Pre-CI Failure (medium verbosity)
```
[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
```
-437
View File
@@ -1,437 +0,0 @@
---
name: ci-monitor
description: Monitor Nx Cloud CI pipeline and handle self-healing fixes automatically. Checks for Nx Cloud connection before starting.
---
# CI Monitor Command
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.
## Context
- **Current Branch:** !`git branch --show-current`
- **Current Commit:** !`git rev-parse --short HEAD`
- **Remote Status:** !`git status -sb | head -1`
## User Instructions
$ARGUMENTS
**Important:** If user provides specific instructions, respect them over default behaviors described below.
## Configuration Defaults
| Setting | Default | Description |
| ------------------------- | ------------- | ------------------------------------------------------------------- |
| `--max-cycles` | 10 | Maximum CIPE cycles before timeout |
| `--timeout` | 120 | Maximum duration in minutes |
| `--verbosity` | medium | Output level: minimal, medium, verbose |
| `--branch` | (auto-detect) | Branch to monitor |
| `--subagent-timeout` | 60 | Subagent polling timeout in minutes |
| `--fresh` | false | Ignore previous context, start fresh |
| `--auto-fix-workflow` | false | Attempt common fixes for pre-CIPE failures (e.g., lockfile updates) |
| `--new-cipe-timeout` | 10 | Minutes to wait for new CIPE after action |
| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |
Parse any overrides from `$ARGUMENTS` and merge with defaults.
## Nx Cloud Connection Check
**CRITICAL**: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
### Step 0: Verify Nx Cloud Connection
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
## 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`
## 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.
| Status | Default 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. |
### Fix Available Decision Logic
When subagent returns `fix_available`, main agent compares `failedTaskIds` vs `verifiedTaskIds`:
#### Step 1: Categorize Tasks
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
#### Step 2: Determine Path
| Condition | Path |
| --------------------------------------- | ---------------------------------------- |
| No unverified tasks (all verified) | Apply via MCP |
| Unverified tasks exist, but ALL are e2e | Apply via MCP (treat as verified enough) |
| Verifiable tasks exist | Local verification flow |
#### Step 3a: Apply via MCP (fully/e2e-only verified)
- Call `update_self_healing_fix({ shortLink, action: "APPLY" })`
- Record `last_cipe_url`, spawn subagent in wait mode
#### Step 3b: Local Verification Flow
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:**
| Result | Action |
| ------------------------- | ---------------------------- |
| ALL verifiable tasks pass | Apply via MCP |
| ANY verifiable task fails | Apply-locally + enhance flow |
4. **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
5. **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)
#### Commit Message Format
```bash
git commit -m "fix(<projects>): <brief description>
Failed tasks: <taskId1>, <taskId2>
Local verification: 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
### 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.
### Apply vs Reject vs Apply Locally
- **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.
### 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
### 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
### 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
### No-New-CIPE Handling
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
## Exit Conditions
Exit the monitoring loop when ANY of these conditions are met:
| Condition | Exit Type |
| ------------------------------------------- | ---------------- |
| CI passes (`cipeStatus == 'SUCCEEDED'`) | Success |
| Max CIPE cycles reached | Timeout |
| Max duration reached | Timeout |
| 3 consecutive no-progress iterations | Circuit breaker |
| No fix available and local fix not possible | Failure |
| No new CIPE and auto-fix not configured | Pre-CIPE failure |
| User cancels | Cancelled |
## Main Loop
### Step 1: Initialize Tracking
```
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
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>"
)
```
### Step 3: Handle Subagent Response
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
### Step 3a: Track State for New-CIPE Detection
After actions that should trigger a new CIPE, record state before looping:
| Action | What to Track | Subagent 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.
### Step 4: Progress Tracking
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`
## Status Reporting
Based on verbosity level:
| Level | What 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 |
## User Instruction Examples
Users can override default behaviors:
| Instruction | Effect |
| ------------------------------------------------ | --------------------------------------------- |
| "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) |
## Error Handling
| Error | Action |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Git rebase conflict | Report to user, exit |
| `nx apply-locally` fails | Report to user, attempt manual patch or exit |
| MCP tool error | Retry once, if fails report to user |
| Subagent spawn failure | Retry once, if fails exit with error |
| No new CIPE detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |
| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |
## Example Session
### Example 1: Normal Flow with Self-Healing (medium verbosity)
```
[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
```
### Example 2: Pre-CI Failure (medium verbosity)
```
[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
```
-228
View File
@@ -1,228 +0,0 @@
---
name: nx-generate
description: Generate code using nx generators. USE WHEN scaffolding code or transforming existing code - for example creating libraries or applications, or anything else that is boilerplate code or automates repetitive tasks. ALWAYS use this first when generating code with Nx instead of calling MCP tools or running nx generate immediately.
---
# Run Nx Generator
Nx generators are powerful tools that scaffold projects, make automated code migrations or automate repetitive tasks in a monorepo. They ensure consistency across the codebase and reduce boilerplate work.
This skill applies when the user wants to:
- Create new projects like libraries or applications
- Scaffold features or boilerplate code
- Run workspace-specific or custom generators
- Do anything else that an nx generator exists for
## Generator Discovery Flow
### Step 1: List Available Generators
Use the Nx CLI to discover available generators:
- List all generators for a plugin: `npx nx list @nx/react`
- View available plugins: `npx nx list`
This includes:
- Plugin generators (e.g., `@nx/react:library`, `@nx/js:library`)
- Local workspace generators (defined in the repo's own plugins)
### Step 2: Match Generator to User Request
Based on the user's request, identify which generator(s) could fulfill their needs. Consider:
- What artifact type they want to create (library, application, etc.)
- Which framework or technology stack is relevant
- Whether they mentioned specific generator names
**IMPORTANT**: When both a local workspace generator and an external plugin generator could satisfy the request, **always prefer the local workspace generator**. Local generators are customized for the specific repo's patterns and conventions.
It's possible that the user request is something that no Nx generator exists for whatsoever. In this case, you can stop using this skill and try to help the user another way. HOWEVER, the burden of proof for this is high. Before aborting, carefully consider each and every generator that's available. Look into details for any that could be related in any way before making this decision.
## Pre-Execution Checklist
Before running any generator, complete these steps:
### 1. Fetch Generator Schema
Use the `--help` flag to understand all available options:
```bash
npx nx g @nx/react:library --help
```
Pay attention to:
- Required options that must be provided
- Optional options that may be relevant to the user's request
- Default values that might need to be overridden
### 2. Read Generator Source Code
Understanding what the generator actually does helps you:
- Know what files will be created/modified
- Understand any side effects (updating configs, installing deps, etc.)
- Identify options that might not be obvious from the schema
To find generator source code:
- For plugin generators: Use `node -e "console.log(require.resolve('@nx/<plugin>/generators.json'));"` to find the generators.json, then locate the source from there
- If that fails, read directly from `node_modules/<plugin>/generators.json`
- For local generators: They are typically in `tools/generators/` or a local plugin directory. You can search the repo for the generator name to find it.
### 2.5 Reevaluate if the generator is right
Once you have built up an understanding of what the selected generator does, reconsider: Is this the right generator to service the user request?
If not, it's okay to go back to the Generator Discovery Flow and select a different generator before proceeding. If you do, make sure to go through the entire pre-execution checklist once more.
### 3. Understand Repo Context
Before generating, examine the target area of the codebase:
- Look at similar existing artifacts (other libraries, applications, etc.)
- Identify patterns and conventions used in the repo
- Note naming conventions, file structures, and configuration patterns
- Try to match these patterns when configuring the generator
For example, if similar libraries are using a specific test runner, build tool or linter, try to match that if possible.
If projects or other artifacts are organized with a specific naming convention, try to match it.
### 4. Validate Required Options
Ensure all required options have values:
- Map the user's request to generator options
- Infer values from context where possible
- Ask the user for any critical missing information
## Execution
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally.
Many generators will behave differently based on where they are executed. For example, first-party nx library generators use the cwd to determine the directory that the library should be placed in. This is highly important.
### Consider Dry-Run (Optional)
Running with `--dry-run` first is strongly encouraged but not mandatory. Use your judgment:
- For complex generators or unfamiliar territory: do a dry-run first
- For simple, well-understood generators: may proceed directly
- Dry-run shows file names and created/deleted/modified markers, but not content
- There are cases where a generator does not support dry-run (for example if it had to install an npm package) - in that case --dry-run might fail. Don't be discouraged but simply move on to running the generator for real and iterating from there.
### Running the Generator
Execute the generator with:
```bash
nx generate <generator-name> <options> --no-interactive
```
**CRITICAL**: Always include `--no-interactive` to prevent prompts that would hang the execution.
Example:
```bash
nx generate @nx/react:library --name=my-utils --no-interactive
```
### Handling Generator Failures
If the generator fails:
1. **Diagnose the error** - Read the error message carefully
2. **Identify the cause** - Missing options, invalid values, conflicts, etc.
3. **Attempt automatic fix** - Adjust options or resolve conflicts
4. **Retry** - Run the generator again with corrected options
Common failure reasons:
- Missing required options
- Invalid option values
- Conflicting with existing files
- Missing dependencies
- Generator doesn't support certain flag combinations
## Post-Generation
### 1. Modify Generated Code (If Needed)
Generators provide a starting point, but the output may need adjustment to match the user's specific requirements:
- Add or modify functionality as requested
- Adjust imports, exports, or configurations
- Integrate with existing code patterns in the repo
### 2. Format Code
Run formatting on all generated/modified files:
```bash
nx format --fix
```
Languages other than javascript/typescript might need other formatting invocations too.
### 3. Run Verification
Verify that the generated code works correctly. What this looks like will vary depending on the type of generator and the targets available.
If the generator created a new project, run its targets directly
Use your best judgement to determine what needs to be verified.
Example:
```bash
nx lint <new-project>
nx test <new-project>
nx build <new-project>
```
### 4. Handle Verification Failures
When verification fails:
**If scope is manageable** (a few lint errors, minor type issues):
- Fix the issues
- Re-run verification to confirm
**If issues are extensive** (many errors, complex problems):
- Attempt simple, obvious fixes first
- If still failing, escalate to the user with:
- Description of what was generated
- What verification is failing
- What you've attempted to fix
- Remaining issues that need user input
## Error Handling
### Generator Failures
- Check the error message for specific causes
- Verify all required options are provided
- Check for conflicts with existing files
- Ensure the generator name and options are correct
### Missing Options
- Consult the generator schema for required fields
- Infer values from context when reasonable
- Ask the user for values that cannot be inferred
## Key Principles
1. **Local generators first** - Always prefer workspace/local generators over external plugin generators when both could work
2. **Understand before running** - Read both the schema AND the source code to fully understand what will happen
3. **No prompts** - Always use `--no-interactive` to prevent hanging
4. **Generators are starting points** - Modify the output as needed to fully satisfy the user's requirements
5. **Verify changes work** - Don't just generate; ensure the code builds, lints, and tests pass
6. **Be proactive about fixes** - Don't just report errors; attempt to resolve them automatically when possible
7. **Match repo patterns** - Study existing similar code in the repo and match its conventions
-9
View File
@@ -1,9 +0,0 @@
---
name: nx-plugins
description: Find and add Nx plugins. USE WHEN user wants to discover available plugins, install a new plugin, or add support for a specific framework or technology to the workspace.
---
## Finding and Installing new plugins
- List plugins: `pnpm nx list`
- Install plugins `pnpm nx add <plugin>`. Example: `pnpm nx add @nx/react`.
-58
View File
@@ -1,58 +0,0 @@
---
name: nx-run-tasks
description: Helps with running tasks in an Nx workspace. USE WHEN the user wants to execute build, test, lint, serve, or run any other tasks defined in the workspace.
---
You can run tasks with Nx in the following way.
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Look at the package.json or lockfile to determine which package manager is in use.
For more details on any command, run it with `--help` (e.g. `nx run-many --help`, `nx affected --help`).
## Understand which tasks can be run
You can check those via `nx show project <projectname> --json`, for example `nx show project myapp --json`. It contains a `targets` section which has information about targets that can be run. You can also just look at the `package.json` scripts or `project.json` targets, but you might miss out on inferred tasks by Nx plugins.
## Run a single task
```
nx run <project>:<task>
```
where `project` is the project name defined in `package.json` or `project.json` (if present).
## Run multiple tasks
```
nx run-many -t build test lint typecheck
```
You can pass a `-p` flag to filter to specific projects, otherwise it runs on all projects. You can also use `--exclude` to exclude projects, and `--parallel` to control the number of parallel processes (default is 3).
Examples:
- `nx run-many -t test -p proj1 proj2` — test specific projects
- `nx run-many -t test --projects=*-app --exclude=excluded-app` — test projects matching a pattern
- `nx run-many -t test --projects=tag:api-*` — test projects by tag
## Run tasks for affected projects
Use `nx affected` to only run tasks on projects that have been changed and projects that depend on changed projects. This is especially useful in CI and for large workspaces.
```
nx affected -t build test lint
```
By default it compares against the base branch. You can customize this:
- `nx affected -t test --base=main --head=HEAD` — compare against a specific base and head
- `nx affected -t test --files=libs/mylib/src/index.ts` — specify changed files directly
## Useful flags
These flags work with `run`, `run-many`, and `affected`:
- `--skipNxCache` — rerun tasks even when results are cached
- `--verbose` — print additional information such as stack traces
- `--nxBail` — stop execution after the first failed task
- `--configuration=<name>` — use a specific configuration (e.g. `production`)
-186
View File
@@ -1,186 +0,0 @@
---
name: nx-workspace
description: "Explore and understand Nx workspaces. USE WHEN answering any questions about the nx workspace, the projects in it or tasks to run. EXAMPLES: 'What projects are in this workspace?', 'How is project X configured?', 'What targets can I run?', 'What's affected by my changes?', 'Which projects depend on library Y?', or any questions about Nx workspace structure, project configuration, or available tasks."
---
# Nx Workspace Exploration
This skill provides read-only exploration of Nx workspaces. Use it to understand workspace structure, project configuration, available targets, and dependencies.
Keep in mind that you might have to prefix commands with `npx`/`pnpx`/`yarn` if nx isn't installed globally. Check the lockfile to determine the package manager in use.
## Listing Projects
Use `nx show projects` to list projects in the workspace.
```bash
# List all projects
nx show projects
# Filter by pattern (glob)
nx show projects --projects "apps/*"
nx show projects --projects "shared-*"
# Filter by project type
nx show projects --type app
nx show projects --type lib
nx show projects --type e2e
# Filter by target (projects that have a specific target)
nx show projects --withTarget build
nx show projects --withTarget e2e
# Find affected projects (changed since base branch)
nx show projects --affected
nx show projects --affected --base=main
nx show projects --affected --type app
# Combine filters
nx show projects --type lib --withTarget test
nx show projects --affected --exclude="*-e2e"
# Output as JSON
nx show projects --json
```
## Project Configuration
Use `nx show project <name> --json` to get the full resolved configuration for a project.
**Important**: Do NOT read `project.json` directly - it only contains partial configuration. The `nx show project` command returns the full resolved config including inferred targets from plugins.
You can read the full project schema at `node_modules/nx/schemas/project-schema.json` to understand nx project configuration options.
```bash
# Get full project configuration
nx show project my-app --json
# Extract specific parts from the JSON
nx show project my-app --json | jq '.targets'
nx show project my-app --json | jq '.targets.build'
nx show project my-app --json | jq '.targets | keys'
# Check project metadata
nx show project my-app --json | jq '{name, root, sourceRoot, projectType, tags}'
```
## Target Information
Targets define what tasks can be run on a project.
```bash
# List all targets for a project
nx show project my-app --json | jq '.targets | keys'
# Get full target configuration
nx show project my-app --json | jq '.targets.build'
# Check target executor/command
nx show project my-app --json | jq '.targets.build.executor'
nx show project my-app --json | jq '.targets.build.command'
# View target options
nx show project my-app --json | jq '.targets.build.options'
# Check target inputs/outputs (for caching)
nx show project my-app --json | jq '.targets.build.inputs'
nx show project my-app --json | jq '.targets.build.outputs'
# Find projects with a specific target
nx show projects --withTarget serve
nx show projects --withTarget e2e
```
## Workspace Configuration
Read `nx.json` directly for workspace-level configuration.
You can read the full project schema at `node_modules/nx/schemas/nx-schema.json` to understand nx project configuration options.
```bash
# Read the full nx.json
cat nx.json
# Or use jq for specific sections
cat nx.json | jq '.targetDefaults'
cat nx.json | jq '.namedInputs'
cat nx.json | jq '.plugins'
cat nx.json | jq '.generators'
```
Key nx.json sections:
- `targetDefaults` - Default configuration applied to all targets of a given name
- `namedInputs` - Reusable input definitions for caching
- `plugins` - Nx plugins and their configuration
- ...and much more, read the schema or nx.json for details
## Affected Projects
Find projects affected by changes in the current branch.
```bash
# Affected since base branch (auto-detected)
nx show projects --affected
# Affected with explicit base
nx show projects --affected --base=main
nx show projects --affected --base=origin/main
# Affected between two commits
nx show projects --affected --base=abc123 --head=def456
# Affected apps only
nx show projects --affected --type app
# Affected excluding e2e projects
nx show projects --affected --exclude="*-e2e"
# Affected by uncommitted changes
nx show projects --affected --uncommitted
# Affected by untracked files
nx show projects --affected --untracked
```
## Common Exploration Patterns
### "What's in this workspace?"
```bash
nx show projects
nx show projects --type app
nx show projects --type lib
```
### "How do I build/test/lint project X?"
```bash
nx show project X --json | jq '.targets | keys'
nx show project X --json | jq '.targets.build'
```
### "What depends on library Y?"
```bash
# Find projects that may depend on Y by searching for imports
# (Nx doesn't have a direct "dependents" command via CLI)
grep -r "from '@myorg/Y'" --include="*.ts" --include="*.tsx" apps/ libs/
```
### "What configuration options are available?"
```bash
cat node_modules/nx/schemas/nx-schema.json | jq '.properties | keys'
cat node_modules/nx/schemas/project-schema.json | jq '.properties | keys'
```
### "Why is project X affected?"
```bash
# Check what files changed
git diff --name-only main
# See which project owns those files
nx show project X --json | jq '.root'
```
+12 -32
View File
@@ -3,46 +3,26 @@
{
"name": "NxDevContainer",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
// Starting from a base image that already contains GLIBC v2.33 or higher (required by Nx)
// Try a more recent distribution, if your are having build issues related to GLIBC version
// Here we use 'bookworm', which is based on `Debian-12`, which comes with `GLIBC v2.36`
// (Nx tools currenlty requires `GLIBC v2.33` or higher)
// Note: Using base debian image instead of typescript-node since mise will manage all tools
"image": "mcr.microsoft.com/devcontainers/base:bookworm",
// All tools (Node, Java, Rust, Dotnet) are managed by mise via mise.toml
"features": {},
"image": "mcr.microsoft.com/devcontainers/typescript-node:0-18",
"features": {
"ghcr.io/devcontainers/features/rust:1": {}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// 4211 = nx graph port
// 4873 = verdaccio (local npm registry) port
"forwardPorts": [4211, 4873],
"forwardPorts": [4211],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
// Configure tool-specific properties.
"postCreateCommand": "pnpm install",
"customizations": {
"vscode": {
"extensions": [
"nrwl.angular-console",
"firsttris.vscode-jest-runner",
"eamodio.gitlens",
"mhutchie.git-graph",
"mutantdino.resourcemonitor" // to monitor cpu, memory usage from the dev container
],
"settings": {
"debug.javascript.autoAttachFilter": "disabled" // workaround for that issue: https://github.com/microsoft/vscode-js-debug/issues/374#issuecomment-622239998
}
"extensions": ["nrwl.angular-console"]
}
},
}
// Configure tool-specific properties.
// "customizations": {},
// To improve disk performances when installing node modules
// See https://code.visualstudio.com/remote/advancedcontainers/improve-performance
"mounts": [
"source=${localWorkspaceFolderBasename}-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume"
],
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
// "remoteUser": "root"
}
-41
View File
@@ -1,41 +0,0 @@
#!/bin/bash
# Update the underlying (Debian) OS, to make sure we have the latest security patches and libraries like 'GLIBC'
echo "⚙️ Updating the underlying OS..."
sudo apt-get update && sudo apt-get -y upgrade
# Install mise for managing development tools (Node, Java, Rust, Dotnet)
echo "⚙️ Installing mise..."
curl https://mise.run | sh
# Add mise to PATH
export PATH="$HOME/.local/bin:$PATH"
# Trust the mise.toml configuration file
echo "⚙️ Trusting mise.toml configuration..."
mise trust
# Install all tools from mise.toml (node, java, rust, dotnet)
echo "⚙️ Installing tools via mise (node, java, rust, dotnet)..."
mise install
# Activate mise to make tools available in current shell
eval "$(mise activate bash)"
# Add mise activation to bashrc for future shell sessions
echo "⚙️ Configuring mise activation in shell..."
echo 'eval "$(~/.local/bin/mise activate bash)"' >> ~/.bashrc
# Prevent corepack from prompting user before downloading PNPM
export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
# Enable corepack
corepack enable
# Install the PNPM version defined in the root package.json
echo "⚙️ Installing required PNPM version..."
corepack prepare --activate
# Install NPM dependencies
echo "⚙️ Installing NPM dependencies..."
pnpm install --frozen-lockfile
+1 -1
View File
@@ -9,7 +9,7 @@ end_of_line = lf
insert_final_newline = true
# 4 space indentation
[*.{kts,kt,js,ts,jsx,tsx}]
[*.{js,ts,jsx,tsx}]
indent_style = space
indent_size = 2
+1
View File
@@ -0,0 +1 @@
node_modules
+63
View File
@@ -0,0 +1,63 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"env": {
"node": true
},
"ignorePatterns": ["**/*.ts"],
"plugins": ["@typescript-eslint", "@nx"],
"extends": ["plugin:storybook/recommended"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"no-restricted-imports": ["error", "create-nx-workspace"],
"@typescript-eslint/no-restricted-imports": [
"error",
{
"patterns": [
{
"group": ["nx/src/plugins/js*"],
"message": "Imports from 'nx/src/plugins/js' are not allowed. Use '@nx/js' instead"
}
]
}
],
"storybook/no-uninstalled-addons": [
"error",
{
"ignore": ["@nx/react/plugins/storybook"]
}
]
},
"overrides": [
{
"files": ["*.json"],
"parser": "jsonc-eslint-parser",
"rules": {}
},
{
"files": ["**/executors/**/schema.json", "**/generators/**/schema.json"],
"rules": {
"@nx/workspace/valid-schema-description": "error"
}
},
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"checkDynamicDependenciesExceptions": [".*"],
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
}
]
}
-438
View File
@@ -1,438 +0,0 @@
description = "Monitor Nx Cloud CI pipeline and handle self-healing fixes automatically. Checks for Nx Cloud connection before starting."
prompt = """
# CI Monitor Command
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.
## Context
- **Current Branch:** !`git branch --show-current`
- **Current Commit:** !`git rev-parse --short HEAD`
- **Remote Status:** !`git status -sb | head -1`
## User Instructions
{{args}}
**Important:** If user provides specific instructions, respect them over default behaviors described below.
## Configuration Defaults
| Setting | Default | Description |
| ------------------------- | ------------- | ------------------------------------------------------------------- |
| `--max-cycles` | 10 | Maximum CIPE cycles before timeout |
| `--timeout` | 120 | Maximum duration in minutes |
| `--verbosity` | medium | Output level: minimal, medium, verbose |
| `--branch` | (auto-detect) | Branch to monitor |
| `--subagent-timeout` | 60 | Subagent polling timeout in minutes |
| `--fresh` | false | Ignore previous context, start fresh |
| `--auto-fix-workflow` | false | Attempt common fixes for pre-CIPE failures (e.g., lockfile updates) |
| `--new-cipe-timeout` | 10 | Minutes to wait for new CIPE after action |
| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |
Parse any overrides from `{{args}}` and merge with defaults.
## Nx Cloud Connection Check
**CRITICAL**: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
### Step 0: Verify Nx Cloud Connection
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
## 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`
## 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.
| Status | Default 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. |
### Fix Available Decision Logic
When subagent returns `fix_available`, main agent compares `failedTaskIds` vs `verifiedTaskIds`:
#### Step 1: Categorize Tasks
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
#### Step 2: Determine Path
| Condition | Path |
| --------------------------------------- | ---------------------------------------- |
| No unverified tasks (all verified) | Apply via MCP |
| Unverified tasks exist, but ALL are e2e | Apply via MCP (treat as verified enough) |
| Verifiable tasks exist | Local verification flow |
#### Step 3a: Apply via MCP (fully/e2e-only verified)
- Call `update_self_healing_fix({ shortLink, action: "APPLY" })`
- Record `last_cipe_url`, spawn subagent in wait mode
#### Step 3b: Local Verification Flow
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:**
| Result | Action |
| ------------------------- | ---------------------------- |
| ALL verifiable tasks pass | Apply via MCP |
| ANY verifiable task fails | Apply-locally + enhance flow |
4. **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
5. **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)
#### Commit Message Format
```bash
git commit -m "fix(<projects>): <brief description>
Failed tasks: <taskId1>, <taskId2>
Local verification: 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
### 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.
### Apply vs Reject vs Apply Locally
- **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.
### 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
### 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
### 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
### No-New-CIPE Handling
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
## Exit Conditions
Exit the monitoring loop when ANY of these conditions are met:
| Condition | Exit Type |
| ------------------------------------------- | ---------------- |
| CI passes (`cipeStatus == 'SUCCEEDED'`) | Success |
| Max CIPE cycles reached | Timeout |
| Max duration reached | Timeout |
| 3 consecutive no-progress iterations | Circuit breaker |
| No fix available and local fix not possible | Failure |
| No new CIPE and auto-fix not configured | Pre-CIPE failure |
| User cancels | Cancelled |
## Main Loop
### Step 1: Initialize Tracking
```
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
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>"
)
```
### Step 3: Handle Subagent Response
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
### Step 3a: Track State for New-CIPE Detection
After actions that should trigger a new CIPE, record state before looping:
| Action | What to Track | Subagent 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.
### Step 4: Progress Tracking
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`
## Status Reporting
Based on verbosity level:
| Level | What 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 |
## User Instruction Examples
Users can override default behaviors:
| Instruction | Effect |
| ------------------------------------------------ | --------------------------------------------- |
| "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) |
## Error Handling
| Error | Action |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Git rebase conflict | Report to user, exit |
| `nx apply-locally` fails | Report to user, attempt manual patch or exit |
| MCP tool error | Retry once, if fails report to user |
| Subagent spawn failure | Retry once, if fails exit with error |
| No new CIPE detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |
| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |
## Example Session
### Example 1: Normal Flow with Self-Healing (medium verbosity)
```
[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
```
### Example 2: Pre-CI Failure (medium verbosity)
```
[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
```"""
-10
View File
@@ -1,10 +0,0 @@
{
"mcpServers": {
"nx-mcp": {
"type": "stdio",
"command": "npx",
"args": ["nx", "mcp"]
}
},
"contextFileName": "AGENTS.md"
}
-437
View File
@@ -1,437 +0,0 @@
---
name: ci-monitor
description: Monitor Nx Cloud CI pipeline and handle self-healing fixes automatically. Checks for Nx Cloud connection before starting.
---
# CI Monitor Command
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.
## Context
- **Current Branch:** !`git branch --show-current`
- **Current Commit:** !`git rev-parse --short HEAD`
- **Remote Status:** !`git status -sb | head -1`
## User Instructions
$ARGUMENTS
**Important:** If user provides specific instructions, respect them over default behaviors described below.
## Configuration Defaults
| Setting | Default | Description |
| ------------------------- | ------------- | ------------------------------------------------------------------- |
| `--max-cycles` | 10 | Maximum CIPE cycles before timeout |
| `--timeout` | 120 | Maximum duration in minutes |
| `--verbosity` | medium | Output level: minimal, medium, verbose |
| `--branch` | (auto-detect) | Branch to monitor |
| `--subagent-timeout` | 60 | Subagent polling timeout in minutes |
| `--fresh` | false | Ignore previous context, start fresh |
| `--auto-fix-workflow` | false | Attempt common fixes for pre-CIPE failures (e.g., lockfile updates) |
| `--new-cipe-timeout` | 10 | Minutes to wait for new CIPE after action |
| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |
Parse any overrides from `$ARGUMENTS` and merge with defaults.
## Nx Cloud Connection Check
**CRITICAL**: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
### Step 0: Verify Nx Cloud Connection
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
## 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`
## 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.
| Status | Default 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. |
### Fix Available Decision Logic
When subagent returns `fix_available`, main agent compares `failedTaskIds` vs `verifiedTaskIds`:
#### Step 1: Categorize Tasks
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
#### Step 2: Determine Path
| Condition | Path |
| --------------------------------------- | ---------------------------------------- |
| No unverified tasks (all verified) | Apply via MCP |
| Unverified tasks exist, but ALL are e2e | Apply via MCP (treat as verified enough) |
| Verifiable tasks exist | Local verification flow |
#### Step 3a: Apply via MCP (fully/e2e-only verified)
- Call `update_self_healing_fix({ shortLink, action: "APPLY" })`
- Record `last_cipe_url`, spawn subagent in wait mode
#### Step 3b: Local Verification Flow
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:**
| Result | Action |
| ------------------------- | ---------------------------- |
| ALL verifiable tasks pass | Apply via MCP |
| ANY verifiable task fails | Apply-locally + enhance flow |
4. **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
5. **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)
#### Commit Message Format
```bash
git commit -m "fix(<projects>): <brief description>
Failed tasks: <taskId1>, <taskId2>
Local verification: 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
### 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.
### Apply vs Reject vs Apply Locally
- **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.
### 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
### 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
### 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
### No-New-CIPE Handling
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
## Exit Conditions
Exit the monitoring loop when ANY of these conditions are met:
| Condition | Exit Type |
| ------------------------------------------- | ---------------- |
| CI passes (`cipeStatus == 'SUCCEEDED'`) | Success |
| Max CIPE cycles reached | Timeout |
| Max duration reached | Timeout |
| 3 consecutive no-progress iterations | Circuit breaker |
| No fix available and local fix not possible | Failure |
| No new CIPE and auto-fix not configured | Pre-CIPE failure |
| User cancels | Cancelled |
## Main Loop
### Step 1: Initialize Tracking
```
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
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>"
)
```
### Step 3: Handle Subagent Response
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
### Step 3a: Track State for New-CIPE Detection
After actions that should trigger a new CIPE, record state before looping:
| Action | What to Track | Subagent 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.
### Step 4: Progress Tracking
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`
## Status Reporting
Based on verbosity level:
| Level | What 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 |
## User Instruction Examples
Users can override default behaviors:
| Instruction | Effect |
| ------------------------------------------------ | --------------------------------------------- |
| "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) |
## Error Handling
| Error | Action |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Git rebase conflict | Report to user, exit |
| `nx apply-locally` fails | Report to user, attempt manual patch or exit |
| MCP tool error | Retry once, if fails report to user |
| Subagent spawn failure | Retry once, if fails exit with error |
| No new CIPE detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |
| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |
## Example Session
### Example 1: Normal Flow with Self-Healing (medium verbosity)
```
[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
```
### Example 2: Pre-CI Failure (medium verbosity)
```
[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
```
-228
View File
@@ -1,228 +0,0 @@
---
name: nx-generate
description: Generate code using nx generators. USE WHEN scaffolding code or transforming existing code - for example creating libraries or applications, or anything else that is boilerplate code or automates repetitive tasks. ALWAYS use this first when generating code with Nx instead of calling MCP tools or running nx generate immediately.
---
# Run Nx Generator
Nx generators are powerful tools that scaffold projects, make automated code migrations or automate repetitive tasks in a monorepo. They ensure consistency across the codebase and reduce boilerplate work.
This skill applies when the user wants to:
- Create new projects like libraries or applications
- Scaffold features or boilerplate code
- Run workspace-specific or custom generators
- Do anything else that an nx generator exists for
## Generator Discovery Flow
### Step 1: List Available Generators
Use the Nx CLI to discover available generators:
- List all generators for a plugin: `npx nx list @nx/react`
- View available plugins: `npx nx list`
This includes:
- Plugin generators (e.g., `@nx/react:library`, `@nx/js:library`)
- Local workspace generators (defined in the repo's own plugins)
### Step 2: Match Generator to User Request
Based on the user's request, identify which generator(s) could fulfill their needs. Consider:
- What artifact type they want to create (library, application, etc.)
- Which framework or technology stack is relevant
- Whether they mentioned specific generator names
**IMPORTANT**: When both a local workspace generator and an external plugin generator could satisfy the request, **always prefer the local workspace generator**. Local generators are customized for the specific repo's patterns and conventions.
It's possible that the user request is something that no Nx generator exists for whatsoever. In this case, you can stop using this skill and try to help the user another way. HOWEVER, the burden of proof for this is high. Before aborting, carefully consider each and every generator that's available. Look into details for any that could be related in any way before making this decision.
## Pre-Execution Checklist
Before running any generator, complete these steps:
### 1. Fetch Generator Schema
Use the `--help` flag to understand all available options:
```bash
npx nx g @nx/react:library --help
```
Pay attention to:
- Required options that must be provided
- Optional options that may be relevant to the user's request
- Default values that might need to be overridden
### 2. Read Generator Source Code
Understanding what the generator actually does helps you:
- Know what files will be created/modified
- Understand any side effects (updating configs, installing deps, etc.)
- Identify options that might not be obvious from the schema
To find generator source code:
- For plugin generators: Use `node -e "console.log(require.resolve('@nx/<plugin>/generators.json'));"` to find the generators.json, then locate the source from there
- If that fails, read directly from `node_modules/<plugin>/generators.json`
- For local generators: They are typically in `tools/generators/` or a local plugin directory. You can search the repo for the generator name to find it.
### 2.5 Reevaluate if the generator is right
Once you have built up an understanding of what the selected generator does, reconsider: Is this the right generator to service the user request?
If not, it's okay to go back to the Generator Discovery Flow and select a different generator before proceeding. If you do, make sure to go through the entire pre-execution checklist once more.
### 3. Understand Repo Context
Before generating, examine the target area of the codebase:
- Look at similar existing artifacts (other libraries, applications, etc.)
- Identify patterns and conventions used in the repo
- Note naming conventions, file structures, and configuration patterns
- Try to match these patterns when configuring the generator
For example, if similar libraries are using a specific test runner, build tool or linter, try to match that if possible.
If projects or other artifacts are organized with a specific naming convention, try to match it.
### 4. Validate Required Options
Ensure all required options have values:
- Map the user's request to generator options
- Infer values from context where possible
- Ask the user for any critical missing information
## Execution
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally.
Many generators will behave differently based on where they are executed. For example, first-party nx library generators use the cwd to determine the directory that the library should be placed in. This is highly important.
### Consider Dry-Run (Optional)
Running with `--dry-run` first is strongly encouraged but not mandatory. Use your judgment:
- For complex generators or unfamiliar territory: do a dry-run first
- For simple, well-understood generators: may proceed directly
- Dry-run shows file names and created/deleted/modified markers, but not content
- There are cases where a generator does not support dry-run (for example if it had to install an npm package) - in that case --dry-run might fail. Don't be discouraged but simply move on to running the generator for real and iterating from there.
### Running the Generator
Execute the generator with:
```bash
nx generate <generator-name> <options> --no-interactive
```
**CRITICAL**: Always include `--no-interactive` to prevent prompts that would hang the execution.
Example:
```bash
nx generate @nx/react:library --name=my-utils --no-interactive
```
### Handling Generator Failures
If the generator fails:
1. **Diagnose the error** - Read the error message carefully
2. **Identify the cause** - Missing options, invalid values, conflicts, etc.
3. **Attempt automatic fix** - Adjust options or resolve conflicts
4. **Retry** - Run the generator again with corrected options
Common failure reasons:
- Missing required options
- Invalid option values
- Conflicting with existing files
- Missing dependencies
- Generator doesn't support certain flag combinations
## Post-Generation
### 1. Modify Generated Code (If Needed)
Generators provide a starting point, but the output may need adjustment to match the user's specific requirements:
- Add or modify functionality as requested
- Adjust imports, exports, or configurations
- Integrate with existing code patterns in the repo
### 2. Format Code
Run formatting on all generated/modified files:
```bash
nx format --fix
```
Languages other than javascript/typescript might need other formatting invocations too.
### 3. Run Verification
Verify that the generated code works correctly. What this looks like will vary depending on the type of generator and the targets available.
If the generator created a new project, run its targets directly
Use your best judgement to determine what needs to be verified.
Example:
```bash
nx lint <new-project>
nx test <new-project>
nx build <new-project>
```
### 4. Handle Verification Failures
When verification fails:
**If scope is manageable** (a few lint errors, minor type issues):
- Fix the issues
- Re-run verification to confirm
**If issues are extensive** (many errors, complex problems):
- Attempt simple, obvious fixes first
- If still failing, escalate to the user with:
- Description of what was generated
- What verification is failing
- What you've attempted to fix
- Remaining issues that need user input
## Error Handling
### Generator Failures
- Check the error message for specific causes
- Verify all required options are provided
- Check for conflicts with existing files
- Ensure the generator name and options are correct
### Missing Options
- Consult the generator schema for required fields
- Infer values from context when reasonable
- Ask the user for values that cannot be inferred
## Key Principles
1. **Local generators first** - Always prefer workspace/local generators over external plugin generators when both could work
2. **Understand before running** - Read both the schema AND the source code to fully understand what will happen
3. **No prompts** - Always use `--no-interactive` to prevent hanging
4. **Generators are starting points** - Modify the output as needed to fully satisfy the user's requirements
5. **Verify changes work** - Don't just generate; ensure the code builds, lints, and tests pass
6. **Be proactive about fixes** - Don't just report errors; attempt to resolve them automatically when possible
7. **Match repo patterns** - Study existing similar code in the repo and match its conventions
-9
View File
@@ -1,9 +0,0 @@
---
name: nx-plugins
description: Find and add Nx plugins. USE WHEN user wants to discover available plugins, install a new plugin, or add support for a specific framework or technology to the workspace.
---
## Finding and Installing new plugins
- List plugins: `pnpm nx list`
- Install plugins `pnpm nx add <plugin>`. Example: `pnpm nx add @nx/react`.
-58
View File
@@ -1,58 +0,0 @@
---
name: nx-run-tasks
description: Helps with running tasks in an Nx workspace. USE WHEN the user wants to execute build, test, lint, serve, or run any other tasks defined in the workspace.
---
You can run tasks with Nx in the following way.
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Look at the package.json or lockfile to determine which package manager is in use.
For more details on any command, run it with `--help` (e.g. `nx run-many --help`, `nx affected --help`).
## Understand which tasks can be run
You can check those via `nx show project <projectname> --json`, for example `nx show project myapp --json`. It contains a `targets` section which has information about targets that can be run. You can also just look at the `package.json` scripts or `project.json` targets, but you might miss out on inferred tasks by Nx plugins.
## Run a single task
```
nx run <project>:<task>
```
where `project` is the project name defined in `package.json` or `project.json` (if present).
## Run multiple tasks
```
nx run-many -t build test lint typecheck
```
You can pass a `-p` flag to filter to specific projects, otherwise it runs on all projects. You can also use `--exclude` to exclude projects, and `--parallel` to control the number of parallel processes (default is 3).
Examples:
- `nx run-many -t test -p proj1 proj2` — test specific projects
- `nx run-many -t test --projects=*-app --exclude=excluded-app` — test projects matching a pattern
- `nx run-many -t test --projects=tag:api-*` — test projects by tag
## Run tasks for affected projects
Use `nx affected` to only run tasks on projects that have been changed and projects that depend on changed projects. This is especially useful in CI and for large workspaces.
```
nx affected -t build test lint
```
By default it compares against the base branch. You can customize this:
- `nx affected -t test --base=main --head=HEAD` — compare against a specific base and head
- `nx affected -t test --files=libs/mylib/src/index.ts` — specify changed files directly
## Useful flags
These flags work with `run`, `run-many`, and `affected`:
- `--skipNxCache` — rerun tasks even when results are cached
- `--verbose` — print additional information such as stack traces
- `--nxBail` — stop execution after the first failed task
- `--configuration=<name>` — use a specific configuration (e.g. `production`)
-186
View File
@@ -1,186 +0,0 @@
---
name: nx-workspace
description: "Explore and understand Nx workspaces. USE WHEN answering any questions about the nx workspace, the projects in it or tasks to run. EXAMPLES: 'What projects are in this workspace?', 'How is project X configured?', 'What targets can I run?', 'What's affected by my changes?', 'Which projects depend on library Y?', or any questions about Nx workspace structure, project configuration, or available tasks."
---
# Nx Workspace Exploration
This skill provides read-only exploration of Nx workspaces. Use it to understand workspace structure, project configuration, available targets, and dependencies.
Keep in mind that you might have to prefix commands with `npx`/`pnpx`/`yarn` if nx isn't installed globally. Check the lockfile to determine the package manager in use.
## Listing Projects
Use `nx show projects` to list projects in the workspace.
```bash
# List all projects
nx show projects
# Filter by pattern (glob)
nx show projects --projects "apps/*"
nx show projects --projects "shared-*"
# Filter by project type
nx show projects --type app
nx show projects --type lib
nx show projects --type e2e
# Filter by target (projects that have a specific target)
nx show projects --withTarget build
nx show projects --withTarget e2e
# Find affected projects (changed since base branch)
nx show projects --affected
nx show projects --affected --base=main
nx show projects --affected --type app
# Combine filters
nx show projects --type lib --withTarget test
nx show projects --affected --exclude="*-e2e"
# Output as JSON
nx show projects --json
```
## Project Configuration
Use `nx show project <name> --json` to get the full resolved configuration for a project.
**Important**: Do NOT read `project.json` directly - it only contains partial configuration. The `nx show project` command returns the full resolved config including inferred targets from plugins.
You can read the full project schema at `node_modules/nx/schemas/project-schema.json` to understand nx project configuration options.
```bash
# Get full project configuration
nx show project my-app --json
# Extract specific parts from the JSON
nx show project my-app --json | jq '.targets'
nx show project my-app --json | jq '.targets.build'
nx show project my-app --json | jq '.targets | keys'
# Check project metadata
nx show project my-app --json | jq '{name, root, sourceRoot, projectType, tags}'
```
## Target Information
Targets define what tasks can be run on a project.
```bash
# List all targets for a project
nx show project my-app --json | jq '.targets | keys'
# Get full target configuration
nx show project my-app --json | jq '.targets.build'
# Check target executor/command
nx show project my-app --json | jq '.targets.build.executor'
nx show project my-app --json | jq '.targets.build.command'
# View target options
nx show project my-app --json | jq '.targets.build.options'
# Check target inputs/outputs (for caching)
nx show project my-app --json | jq '.targets.build.inputs'
nx show project my-app --json | jq '.targets.build.outputs'
# Find projects with a specific target
nx show projects --withTarget serve
nx show projects --withTarget e2e
```
## Workspace Configuration
Read `nx.json` directly for workspace-level configuration.
You can read the full project schema at `node_modules/nx/schemas/nx-schema.json` to understand nx project configuration options.
```bash
# Read the full nx.json
cat nx.json
# Or use jq for specific sections
cat nx.json | jq '.targetDefaults'
cat nx.json | jq '.namedInputs'
cat nx.json | jq '.plugins'
cat nx.json | jq '.generators'
```
Key nx.json sections:
- `targetDefaults` - Default configuration applied to all targets of a given name
- `namedInputs` - Reusable input definitions for caching
- `plugins` - Nx plugins and their configuration
- ...and much more, read the schema or nx.json for details
## Affected Projects
Find projects affected by changes in the current branch.
```bash
# Affected since base branch (auto-detected)
nx show projects --affected
# Affected with explicit base
nx show projects --affected --base=main
nx show projects --affected --base=origin/main
# Affected between two commits
nx show projects --affected --base=abc123 --head=def456
# Affected apps only
nx show projects --affected --type app
# Affected excluding e2e projects
nx show projects --affected --exclude="*-e2e"
# Affected by uncommitted changes
nx show projects --affected --uncommitted
# Affected by untracked files
nx show projects --affected --untracked
```
## Common Exploration Patterns
### "What's in this workspace?"
```bash
nx show projects
nx show projects --type app
nx show projects --type lib
```
### "How do I build/test/lint project X?"
```bash
nx show project X --json | jq '.targets | keys'
nx show project X --json | jq '.targets.build'
```
### "What depends on library Y?"
```bash
# Find projects that may depend on Y by searching for imports
# (Nx doesn't have a direct "dependents" command via CLI)
grep -r "from '@myorg/Y'" --include="*.ts" --include="*.tsx" apps/ libs/
```
### "What configuration options are available?"
```bash
cat node_modules/nx/schemas/nx-schema.json | jq '.properties | keys'
cat node_modules/nx/schemas/project-schema.json | jq '.properties | keys'
```
### "Why is project X affected?"
```bash
# Check what files changed
git diff --name-only main
# See which project owns those files
nx show project X --json | jq '.root'
```
-10
View File
@@ -1,10 +0,0 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf
# These are Windows script files and should use crlf
*.bat text eol=crlf
# Exclude files from Graphite reviews
docs/generated/* linguist-generated=true
*.pdf,*.gif,*.mp4,*.webp,*.avif,*.png,*.jpeg,*.jpg,*.tiff filter=lfs diff=lfs merge=lfs -text
+1 -9
View File
@@ -1,7 +1,6 @@
name: 🐞 Bug Report
description: This form is to report unexpected behavior in Nx.
labels: ["type: bug"]
type: Bug
labels: [ "type: bug" ]
body:
- type: markdown
attributes:
@@ -54,13 +53,6 @@ body:
label: Failure Logs
description: Please include any relevant log snippets or files here. This will be automatically formatted into code, so no need for backticks.
render: shell
- type: input
id: pm
attributes:
label: Package Manager Version
description: |
If `nx report` doesn't work, please provide the name and the version of your package manager.
You can get version information by running `PACKAGE_MANAGER --version`, where PACKAGE_MANAGER is any of `yarn`, `pnpm`, `bun` or `npm`, depending on the package manager used.
- type: checkboxes
id: os
attributes:
+23
View File
@@ -0,0 +1,23 @@
---
name: "\U0001F680 Feature Request"
about: Suggest a new feature.
labels: "type: feature"
---
<!-- Please do your best to fill out all of the sections below! -->
<!-- Use this issue type for concrete suggestions, otherwise, open a discussion type issue instead. -->
- [ ] I'd be willing to implement this feature ([contributing guide](https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md))
## Description
<!-- What is the behavior that you would like to see introduced? -->
## Motivation
<!-- Why do you believe this behavior would be beneficial? -->
## Suggested Implementation
<!-- How do you imagine this might work? -->
## Alternate Implementations
<!-- How else do you imagine this might work? -->
+9 -12
View File
@@ -1,17 +1,14 @@
blank_issues_enabled: false
contact_links:
- name: "\U0001F680 Feature Request"
about: "Suggest a new feature to make Nx better"
url: https://github.com/nrwl/nx/discussions/new?category=feature-requests
- name: Start a Discussion
about: "Start a discussion to share your experience with Nx"
url: https://github.com/nrwl/nx/discussions/new/choose
- name: Join the Discord
url: https://go.nx.dev/community
about: "The Nx Official Discord Server is a great place for questions to be asked and answered. Please use the #forum if you need help with your workspace!"
- name: Are you looking for integration with a new tool?
url: https://nx.dev/community
about: "There are a lot of awesome Plugins for Nx provided by the community! Check here to see if there is a community plugin to integrate your tool."
- name: Read the community guidelines
about: "Please make sure you have read the submission guidelines before posting an issue"
url: https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-an-issue
- name: Want to start a discussion?
about: "Want to start a thread to discuss an idea? Use the discussions feature provided by GitHub."
url: https://github.com/nrwl/nx/discussions
- name: Have a question?
url: https://go.nrwl.io/join-slack
about: "The Community Slack is a great place for questions to be asked and answered. Please use the #support channel if you need help with your workspace!"
- name: Are you looking for integration with a new tool?
url: https://nx.dev/community
about: "There are a lot of awesome Plugins for Nx provided by the community! Check here to see if there is a community plugin to integrate your tool."
-2
View File
@@ -4,8 +4,6 @@
<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->
<!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. -->
## Current Behavior
<!-- This is the behavior we have today -->
@@ -28,12 +28,12 @@ Note: We reserve the right to remove unmaintained plugins from the registry. If
## Steps to Submit Your Plugin
- Use the following commit message template: `chore(core): nx plugin submission [PLUGIN_NAME]`
- Update the `astro-docs/src/content/approved-community-plugins.json` file with a new entry for your plugin that includes `name`, `url`, `description`:
- Update the `community/approved-plugins.json` file with a new entry for your plugin that includes `name`, `url`, `description`:
Example:
```json
// astro-docs/src/content/approved-community-plugins.json
// community/approved-plugins.json
[{
"name": "@community/plugin",
@@ -42,7 +42,7 @@ Example:
}]
```
Once merged, your plugin will be available when running the `nx list` command, and will also be available in the Plugin Registry on [nx.dev](https://nx.dev/docs/plugin-registry)
Once merged, your plugin will be available when running the `nx list` command, and will also be available in the Plugin Registry on [nx.dev](https://nx.dev/extending-nx/registry)
-->
# Community Plugin Submission
-478
View File
@@ -1,478 +0,0 @@
---
description: Polls Nx Cloud CI pipeline and self-healing status. Returns structured state when actionable. Spawned by /nx-cloud-ci-monitor command to monitor CI Attempt status.
---
# CI Watcher Subagent
You are a CI monitoring subagent responsible for polling Nx Cloud CI Attempt status and self-healing state. You report status back to the main agent - you do NOT make apply/reject decisions.
## Your Responsibilities
1. Poll CI status using the `ci_information` MCP tool
2. Implement exponential backoff between polls
3. Return structured state when an actionable condition is reached
4. Track iteration count and elapsed time
5. Output status updates based on verbosity level
## Input Parameters (from Main Agent)
The main agent may provide these optional parameters in the prompt:
| Parameter | Description |
| ------------------- | -------------------------------------------------------- |
| `branch` | Branch to monitor (auto-detected if not provided) |
| `expectedCommitSha` | Commit SHA that should trigger a new CI Attempt |
| `previousCipeUrl` | CI Attempt URL before the action (to detect change) |
| `subagentTimeout` | Polling timeout in minutes (default: 60) |
| `verbosity` | Output level: minimal, medium, verbose (default: medium) |
When `expectedCommitSha` or `previousCipeUrl` is provided, you must detect whether a new CI Attempt has spawned.
## MCP Tool Reference
### `ci_information`
**Input:**
```json
{
"branch": "string (optional, defaults to current git branch)",
"select": "string (optional, comma-separated field names)",
"pageToken": "number (optional, 0-based pagination for long strings)"
}
```
**Output:**
```json
{
"cipeStatus": "NOT_STARTED | IN_PROGRESS | SUCCEEDED | FAILED | CANCELED | TIMED_OUT",
"cipeUrl": "string",
"branch": "string",
"commitSha": "string | null",
"failedTaskIds": "string[]",
"verifiedTaskIds": "string[]",
"selfHealingEnabled": "boolean",
"selfHealingStatus": "NOT_STARTED | IN_PROGRESS | COMPLETED | FAILED | NOT_EXECUTABLE | null",
"verificationStatus": "NOT_STARTED | IN_PROGRESS | COMPLETED | FAILED | NOT_EXECUTABLE | null",
"userAction": "NONE | APPLIED | REJECTED | APPLIED_LOCALLY | APPLIED_AUTOMATICALLY | null",
"failureClassification": "string | null",
"taskOutputSummary": "string | null",
"suggestedFixReasoning": "string | null",
"suggestedFixDescription": "string | null",
"suggestedFix": "string | null",
"shortLink": "string | null",
"couldAutoApplyTasks": "boolean | null",
"confidence": "number | null",
"confidenceReasoning": "string | null"
}
```
**Select Parameter:**
| Usage | Returns |
| --------------- | ----------------------------------------------------------- |
| No `select` | Formatted overview (truncated, not recommended for polling) |
| Single field | Raw value with pagination for long strings |
| Multiple fields | Object with requested field values |
**Field Sets for Efficient Polling:**
```yaml
WAIT_FIELDS:
'cipeUrl,commitSha,cipeStatus'
# Minimal fields for detecting new CI Attempt
LIGHT_FIELDS:
'cipeStatus,cipeUrl,branch,commitSha,selfHealingStatus,verificationStatus,userAction,failedTaskIds,verifiedTaskIds,selfHealingEnabled,failureClassification,couldAutoApplyTasks,shortLink,confidence,confidenceReasoning'
# Status fields for determining actionable state
HEAVY_FIELDS:
'taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription'
# Large content fields - fetch only when returning to main agent
```
## Initial Wait
Before first poll, wait based on context:
- **Fresh start (no expected CIPE):** Wait 60 seconds to allow CI to start
- **Expecting new CIPE:** Wait 30 seconds (action already triggered)
**IMPORTANT:** Always run sleep in foreground, NOT as background command.
```bash
sleep 60 # or 30 if expecting new CIPE (FOREGROUND, not background)
```
## Two-Phase Operation
The subagent operates in one of two modes depending on input:
### Mode 1: Fresh Start (no `expectedCommitSha` or `previousCipeUrl`)
Normal polling - process whatever CIPE is returned by `ci_information`.
### Mode 2: Wait-for-New-CIPE (when `expectedCommitSha` or `previousCipeUrl` provided)
**CRITICAL**: When expecting a new CIPE, the subagent must **completely ignore** the old/stale CIPE. Do NOT process its status, do NOT return actionable states based on it.
#### Phase A: Wait Mode
1. Start a **new-CIPE timeout** timer (default: 30 minutes)
2. On each poll of `ci_information`:
- Check if CIPE is NEW:
- `cipeUrl` differs from `previousCipeUrl`**new CIPE detected**
- `commitSha` matches `expectedCommitSha`**correct CIPE detected**
- If still OLD CIPE: **ignore all status fields**, just wait and poll again
- Do NOT return `fix_available`, `ci_success`, etc. based on old CIPE!
3. Output wait status (see below)
4. If timeout (30 min) reached → return `no_new_cipe`
#### Phase B: Normal Polling (after new CIPE detected)
Once new CIPE is detected:
1. Clear the new-CIPE timeout
2. Switch to normal polling mode
3. Process the NEW CIPE's status normally
4. Return when actionable state reached
### Wait Mode Output
While in wait mode, output clearly that you're waiting (not processing):
```
[CI Monitor] ═══════════════════════════════════════════════════════
[CI Monitor] WAIT MODE - Expecting new CI Attempt
[CI Monitor] Expected SHA: <expectedCommitSha>
[CI Monitor] Previous CI Attempt: <previousCipeUrl>
[CI Monitor] ═══════════════════════════════════════════════════════
[CI Monitor] Polling... (elapsed: 0m 30s)
[CI Monitor] Still seeing previous CI Attempt (ignoring): <oldCipeUrl>
[CI Monitor] Polling... (elapsed: 1m 30s)
[CI Monitor] Still seeing previous CI Attempt (ignoring): <oldCipeUrl>
[CI Monitor] Polling... (elapsed: 2m 30s)
[CI Monitor] ✓ New CI Attempt detected! URL: <newCipeUrl>, SHA: <newCommitSha>
[CI Monitor] Switching to normal polling mode...
```
### Why This Matters (Context Preservation)
**The problem**: Stale CIPE data can be very large:
- `taskOutputSummary`: potentially thousands of characters of build/test output
- `suggestedFix`: entire patch files
- `suggestedFixReasoning`: detailed explanation
If subagent returns stale CIPE data to main agent, it **pollutes main agent's context** with useless information (we already processed that CIPE). This wastes valuable context window.
**Without wait mode:**
1. Poll `ci_information` → get old CIPE with huge data
2. Return to main agent with all that stale data
3. Main agent's context gets polluted with useless info
4. Main agent has to process/ignore it anyway
**With wait mode:**
1. Poll `ci_information` → get old CIPE → **ignore it, don't return**
2. Keep waiting internally (stale data stays in subagent)
3. New CIPE appears → switch to normal mode
4. Return to main agent with only the NEW, relevant CIPE data
## Polling Loop
### Subagent State Management
Maintain internal accumulated state across polls:
```
accumulated_state = {}
```
### Call `ci_information` MCP Tool
**Wait Mode (expecting new CI Attempt):**
```
ci_information({
branch: "<branch_name>",
select: "cipeUrl,commitSha,cipeStatus"
})
```
Only fetch minimal fields needed to detect CI Attempt change. Do NOT fetch heavy fields - stale data wastes context.
**Normal Mode (processing CI Attempt):**
```
ci_information({
branch: "<branch_name>",
select: "cipeStatus,cipeUrl,branch,commitSha,selfHealingStatus,verificationStatus,userAction,failedTaskIds,verifiedTaskIds,selfHealingEnabled,failureClassification,couldAutoApplyTasks,shortLink,confidence,confidenceReasoning"
})
```
Merge response into `accumulated_state` after each poll.
### Analyze Response
**If in Wait Mode** (expecting new CIPE):
1. Check if CIPE is new (see Two-Phase Operation above)
2. If old CIPE → **ignore status**, output wait message, poll again
3. If new CIPE → switch to normal mode, continue below
**If in Normal Mode**:
Based on the response, decide whether to **keep polling** or **return to main agent**.
### Keep Polling When
Continue polling (with backoff) if ANY of these conditions are true:
| Condition | Reason |
| --------------------------------------- | ---------------------------------------- |
| `cipeStatus == 'IN_PROGRESS'` | CI still running |
| `cipeStatus == 'NOT_STARTED'` | CI hasn't started yet |
| `selfHealingStatus == 'IN_PROGRESS'` | Self-healing agent working |
| `selfHealingStatus == 'NOT_STARTED'` | Self-healing not started yet |
| `failureClassification == 'FLAKY_TASK'` | Auto-rerun in progress |
| `userAction == 'APPLIED_AUTOMATICALLY'` | New CI Attempt spawning after auto-apply |
When `couldAutoApplyTasks == true`:
- `verificationStatus` = `NOT_STARTED`, `IN_PROGRESS` → keep polling (verification still in progress)
- `verificationStatus` = `COMPLETED` → return `fix_auto_applying` (auto-apply will happen, main agent spawns wait mode subagent)
- `verificationStatus` = `FAILED`, `NOT_EXECUTABLE` → return `fix_available` (auto-apply won't happen, needs manual action)
### Exponential Backoff
Between polls, wait with exponential backoff:
| Poll Attempt | Wait Time |
| ------------ | ----------------- |
| 1st | 60 seconds |
| 2nd | 90 seconds |
| 3rd+ | 120 seconds (cap) |
Reset to 60 seconds when state changes significantly.
**IMPORTANT:** Run sleep in foreground (NOT as background command). Background sleep causes "What should Claude do?" prompts when completed.
```bash
# Example backoff - run in FOREGROUND
sleep 60 # First wait
sleep 90 # Second wait
sleep 120 # Third and subsequent waits (capped)
```
### Fetch Heavy Fields on Actionable State
Before returning to main agent, fetch heavy fields if the status requires them:
| Status | Heavy Fields Needed |
| ------------------- | ------------------------------------------------------------------------------ |
| `ci_success` | None |
| `fix_auto_applying` | None |
| `fix_available` | `taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription` |
| `fix_failed` | `taskOutputSummary` |
| `no_fix` | `taskOutputSummary` |
| `environment_issue` | None |
| `no_new_cipe` | None |
| `polling_timeout` | None |
| `cipe_canceled` | None |
| `cipe_timed_out` | None |
```
# Example: fetching heavy fields for fix_available
ci_information({
branch: "<branch_name>",
select: "taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription"
})
```
Merge response into `accumulated_state`, then return merged state to main agent.
**Pagination:** Heavy string fields return first page only. If `hasMore` indicated, include in return format so main agent knows more content available.
### Return to Main Agent When
Return immediately with structured state if ANY of these conditions are true:
| Status | Condition |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ci_success` | `cipeStatus == 'SUCCEEDED'` |
| `fix_auto_applying` | `selfHealingStatus == 'COMPLETED'` AND `couldAutoApplyTasks == true` AND `verificationStatus == 'COMPLETED'` |
| `fix_available` | `selfHealingStatus == 'COMPLETED'` AND `suggestedFix != null` AND (`couldAutoApplyTasks != true` OR `verificationStatus` in (`FAILED`, `NOT_EXECUTABLE`)) |
| `fix_failed` | `selfHealingStatus == 'FAILED'` |
| `environment_issue` | `failureClassification == 'ENVIRONMENT_STATE'` |
| `no_fix` | `cipeStatus == 'FAILED'` AND (`selfHealingEnabled == false` OR `selfHealingStatus == 'NOT_EXECUTABLE'`) |
| `no_new_cipe` | `expectedCommitSha` or `previousCipeUrl` provided, but no new CI Attempt detected after 30 min |
| `polling_timeout` | Subagent has been polling for > configured timeout (default 60 min) |
| `cipe_canceled` | `cipeStatus == 'CANCELED'` |
| `cipe_timed_out` | `cipeStatus == 'TIMED_OUT'` |
## Subagent Timeout
Track elapsed time. If you have been polling for more than **60 minutes** (configurable via main agent), return with `status: polling_timeout`.
## Return Format
When returning to the main agent, provide a structured response with accumulated state:
```
## CI Monitor Result
**Status:** <status>
**Iterations:** <count>
**Elapsed:** <minutes>m <seconds>s
### CI Attempt Details
- **Status:** <cipeStatus>
- **URL:** <cipeUrl>
- **Branch:** <branch>
- **Commit:** <commitSha>
- **Failed Tasks:** <failedTaskIds>
- **Verified Tasks:** <verifiedTaskIds>
### Self-Healing Details
- **Enabled:** <selfHealingEnabled>
- **Status:** <selfHealingStatus>
- **Verification:** <verificationStatus>
- **User Action:** <userAction>
- **Classification:** <failureClassification>
- **Confidence:** <confidence>
- **Confidence Reasoning:** <confidenceReasoning>
### Fix Information (if available)
- **Short Link:** <shortLink>
- **Description:** <suggestedFixDescription>
- **Reasoning:** <suggestedFixReasoning>
### Task Output Summary (first page)
<taskOutputSummary>
[MORE_CONTENT_AVAILABLE: taskOutputSummary, pageToken: 1]
### Suggested Fix (first page)
<suggestedFix>
[MORE_CONTENT_AVAILABLE: suggestedFix, pageToken: 1]
```
### Pagination Indicators
When a heavy field has more content available, append indicator:
```
[MORE_CONTENT_AVAILABLE: <fieldName>, pageToken: <nextPage>]
```
Main agent can fetch additional pages if needed using:
```
ci_information({ select: "<fieldName>", pageToken: <nextPage> })
```
Fields that may have pagination:
- `taskOutputSummary` (reverse pagination - page 0 = most recent)
- `suggestedFix` (forward pagination - page 0 = start)
- `suggestedFixReasoning`
### Return Format for `no_new_cipe`
When returning with `status: no_new_cipe`, include additional context:
```
## CI Monitor Result
**Status:** no_new_cipe
**Iterations:** <count>
**Elapsed:** <minutes>m <seconds>s
### Expected CI Attempt Not Found
- **Expected Commit SHA:** <expectedCommitSha>
- **Previous CI Attempt URL:** <previousCipeUrl>
- **Last Seen CI Attempt URL:** <cipeUrl>
- **Last Seen Commit SHA:** <commitSha>
- **New CI Attempt Timeout:** 30 minutes (exceeded)
### Likely Cause
CI workflow failed before Nx tasks could run (e.g., install step, checkout, auth).
Check your CI provider logs for the commit <expectedCommitSha>.
### Last Known CI Attempt State
- **Status:** <cipeStatus>
- **Branch:** <branch>
```
## Status Reporting (Verbosity-Controlled)
Output is controlled by the `verbosity` parameter from the main agent:
| Level | What to Output |
| --------- | ----------------------------------------------------------------- |
| `minimal` | No intermediate output. Only return final result when actionable. |
| `medium` | Output only on significant state changes (not every poll). |
| `verbose` | Output detailed phase information after every poll. |
### Minimal Verbosity
No output during polling. Poll silently and return when done.
### Medium Verbosity (Default)
Output **only when state changes significantly** to save context tokens:
- `cipeStatus` changes (e.g., IN_PROGRESS → FAILED)
- `selfHealingStatus` changes (e.g., IN_PROGRESS → COMPLETED)
- New CI Attempt detected (in wait mode)
Format: single line, no decorators:
```
[CI Monitor] CI: FAILED | Self-Healing: IN_PROGRESS | Elapsed: 4m
```
### Verbose Verbosity
Output detailed phase box after every poll:
```
[CI Monitor] ─────────────────────────────────────────────────────
[CI Monitor] Iteration <N> | Elapsed: <X>m <Y>s
[CI Monitor]
[CI Monitor] CI Status: <cipeStatus>
[CI Monitor] Self-Healing: <selfHealingStatus>
[CI Monitor] Verification: <verificationStatus>
[CI Monitor] Classification: <failureClassification>
[CI Monitor]
[CI Monitor] → <human-readable phase description>
[CI Monitor] ─────────────────────────────────────────────────────
```
### Phase Descriptions (for verbose output)
| Status Combo | Description |
| ----------------------------------------------------------------------------------------- | ------------------------------------------- |
| `cipeStatus: IN_PROGRESS` | "CI running..." |
| `cipeStatus: NOT_STARTED` | "Waiting for CI to start..." |
| `cipeStatus: FAILED` + `selfHealingStatus: NOT_STARTED` | "CI failed. Self-healing starting..." |
| `cipeStatus: FAILED` + `selfHealingStatus: IN_PROGRESS` | "CI failed. Self-healing generating fix..." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: IN_PROGRESS` | "Fix generated! Verification running..." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: COMPLETED` | "Fix ready! Verified successfully." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: FAILED` | "Fix generated but verification failed." |
| `cipeStatus: FAILED` + `selfHealingStatus: FAILED` | "Self-healing could not generate a fix." |
| `cipeStatus: SUCCEEDED` | "CI passed!" |
## Important Notes
- You do NOT make apply/reject decisions - that's the main agent's job
- You do NOT perform git operations
- You only poll and report state
- Respect the `verbosity` parameter for output (default: medium)
- If `ci_information` returns an error, wait and retry (count as failed poll)
- Track consecutive failures - if 5 consecutive failures, return with `status: error`
- When expecting new CI Attempt, track the 30-minute new-CI-Attempt timeout separately from the main polling timeout
-18
View File
@@ -1,18 +0,0 @@
# This configuration is here to prevent false positive alerts for __fixtures__.
# We are intentionally disabling the PR opening feature.
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'weekly'
open-pull-requests-limit: 0
exclude-paths:
- '**/__fixtures__/**'
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
open-pull-requests-limit: 0
-437
View File
@@ -1,437 +0,0 @@
---
description: Monitor Nx Cloud CI pipeline and handle self-healing fixes automatically. Checks for Nx Cloud connection before starting.
argument-hint: '[instructions] [--max-cycles N] [--timeout MINUTES] [--verbosity minimal|medium|verbose] [--branch BRANCH] [--fresh] [--auto-fix-workflow] [--new-cipe-timeout MINUTES]'
---
# CI Monitor Command
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.
## Context
- **Current Branch:** !`git branch --show-current`
- **Current Commit:** !`git rev-parse --short HEAD`
- **Remote Status:** !`git status -sb | head -1`
## User Instructions
${input:args}
**Important:** If user provides specific instructions, respect them over default behaviors described below.
## Configuration Defaults
| Setting | Default | Description |
| ------------------------- | ------------- | ------------------------------------------------------------------- |
| `--max-cycles` | 10 | Maximum CIPE cycles before timeout |
| `--timeout` | 120 | Maximum duration in minutes |
| `--verbosity` | medium | Output level: minimal, medium, verbose |
| `--branch` | (auto-detect) | Branch to monitor |
| `--subagent-timeout` | 60 | Subagent polling timeout in minutes |
| `--fresh` | false | Ignore previous context, start fresh |
| `--auto-fix-workflow` | false | Attempt common fixes for pre-CIPE failures (e.g., lockfile updates) |
| `--new-cipe-timeout` | 10 | Minutes to wait for new CIPE after action |
| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |
Parse any overrides from `${input:args}` and merge with defaults.
## Nx Cloud Connection Check
**CRITICAL**: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
### Step 0: Verify Nx Cloud Connection
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
## 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`
## 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.
| Status | Default 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. |
### Fix Available Decision Logic
When subagent returns `fix_available`, main agent compares `failedTaskIds` vs `verifiedTaskIds`:
#### Step 1: Categorize Tasks
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
#### Step 2: Determine Path
| Condition | Path |
| --------------------------------------- | ---------------------------------------- |
| No unverified tasks (all verified) | Apply via MCP |
| Unverified tasks exist, but ALL are e2e | Apply via MCP (treat as verified enough) |
| Verifiable tasks exist | Local verification flow |
#### Step 3a: Apply via MCP (fully/e2e-only verified)
- Call `update_self_healing_fix({ shortLink, action: "APPLY" })`
- Record `last_cipe_url`, spawn subagent in wait mode
#### Step 3b: Local Verification Flow
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:**
| Result | Action |
| ------------------------- | ---------------------------- |
| ALL verifiable tasks pass | Apply via MCP |
| ANY verifiable task fails | Apply-locally + enhance flow |
4. **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
5. **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)
#### Commit Message Format
```bash
git commit -m "fix(<projects>): <brief description>
Failed tasks: <taskId1>, <taskId2>
Local verification: 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
### 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.
### Apply vs Reject vs Apply Locally
- **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.
### 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
### 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
### 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
### No-New-CIPE Handling
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
## Exit Conditions
Exit the monitoring loop when ANY of these conditions are met:
| Condition | Exit Type |
| ------------------------------------------- | ---------------- |
| CI passes (`cipeStatus == 'SUCCEEDED'`) | Success |
| Max CIPE cycles reached | Timeout |
| Max duration reached | Timeout |
| 3 consecutive no-progress iterations | Circuit breaker |
| No fix available and local fix not possible | Failure |
| No new CIPE and auto-fix not configured | Pre-CIPE failure |
| User cancels | Cancelled |
## Main Loop
### Step 1: Initialize Tracking
```
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
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>"
)
```
### Step 3: Handle Subagent Response
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
### Step 3a: Track State for New-CIPE Detection
After actions that should trigger a new CIPE, record state before looping:
| Action | What to Track | Subagent 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.
### Step 4: Progress Tracking
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`
## Status Reporting
Based on verbosity level:
| Level | What 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 |
## User Instruction Examples
Users can override default behaviors:
| Instruction | Effect |
| ------------------------------------------------ | --------------------------------------------- |
| "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) |
## Error Handling
| Error | Action |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Git rebase conflict | Report to user, exit |
| `nx apply-locally` fails | Report to user, attempt manual patch or exit |
| MCP tool error | Retry once, if fails report to user |
| Subagent spawn failure | Retry once, if fails exit with error |
| No new CIPE detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |
| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |
## Example Session
### Example 1: Normal Flow with Self-Healing (medium verbosity)
```
[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
```
### Example 2: Pre-CI Failure (medium verbosity)
```
[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
```
-437
View File
@@ -1,437 +0,0 @@
---
name: ci-monitor
description: Monitor Nx Cloud CI pipeline and handle self-healing fixes automatically. Checks for Nx Cloud connection before starting.
---
# CI Monitor Command
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.
## Context
- **Current Branch:** !`git branch --show-current`
- **Current Commit:** !`git rev-parse --short HEAD`
- **Remote Status:** !`git status -sb | head -1`
## User Instructions
$ARGUMENTS
**Important:** If user provides specific instructions, respect them over default behaviors described below.
## Configuration Defaults
| Setting | Default | Description |
| ------------------------- | ------------- | ------------------------------------------------------------------- |
| `--max-cycles` | 10 | Maximum CIPE cycles before timeout |
| `--timeout` | 120 | Maximum duration in minutes |
| `--verbosity` | medium | Output level: minimal, medium, verbose |
| `--branch` | (auto-detect) | Branch to monitor |
| `--subagent-timeout` | 60 | Subagent polling timeout in minutes |
| `--fresh` | false | Ignore previous context, start fresh |
| `--auto-fix-workflow` | false | Attempt common fixes for pre-CIPE failures (e.g., lockfile updates) |
| `--new-cipe-timeout` | 10 | Minutes to wait for new CIPE after action |
| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |
Parse any overrides from `$ARGUMENTS` and merge with defaults.
## Nx Cloud Connection Check
**CRITICAL**: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
### Step 0: Verify Nx Cloud Connection
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
## 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`
## 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.
| Status | Default 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. |
### Fix Available Decision Logic
When subagent returns `fix_available`, main agent compares `failedTaskIds` vs `verifiedTaskIds`:
#### Step 1: Categorize Tasks
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
#### Step 2: Determine Path
| Condition | Path |
| --------------------------------------- | ---------------------------------------- |
| No unverified tasks (all verified) | Apply via MCP |
| Unverified tasks exist, but ALL are e2e | Apply via MCP (treat as verified enough) |
| Verifiable tasks exist | Local verification flow |
#### Step 3a: Apply via MCP (fully/e2e-only verified)
- Call `update_self_healing_fix({ shortLink, action: "APPLY" })`
- Record `last_cipe_url`, spawn subagent in wait mode
#### Step 3b: Local Verification Flow
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:**
| Result | Action |
| ------------------------- | ---------------------------- |
| ALL verifiable tasks pass | Apply via MCP |
| ANY verifiable task fails | Apply-locally + enhance flow |
4. **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
5. **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)
#### Commit Message Format
```bash
git commit -m "fix(<projects>): <brief description>
Failed tasks: <taskId1>, <taskId2>
Local verification: 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
### 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.
### Apply vs Reject vs Apply Locally
- **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.
### 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
### 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
### 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
### No-New-CIPE Handling
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
## Exit Conditions
Exit the monitoring loop when ANY of these conditions are met:
| Condition | Exit Type |
| ------------------------------------------- | ---------------- |
| CI passes (`cipeStatus == 'SUCCEEDED'`) | Success |
| Max CIPE cycles reached | Timeout |
| Max duration reached | Timeout |
| 3 consecutive no-progress iterations | Circuit breaker |
| No fix available and local fix not possible | Failure |
| No new CIPE and auto-fix not configured | Pre-CIPE failure |
| User cancels | Cancelled |
## Main Loop
### Step 1: Initialize Tracking
```
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
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>"
)
```
### Step 3: Handle Subagent Response
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
### Step 3a: Track State for New-CIPE Detection
After actions that should trigger a new CIPE, record state before looping:
| Action | What to Track | Subagent 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.
### Step 4: Progress Tracking
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`
## Status Reporting
Based on verbosity level:
| Level | What 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 |
## User Instruction Examples
Users can override default behaviors:
| Instruction | Effect |
| ------------------------------------------------ | --------------------------------------------- |
| "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) |
## Error Handling
| Error | Action |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Git rebase conflict | Report to user, exit |
| `nx apply-locally` fails | Report to user, attempt manual patch or exit |
| MCP tool error | Retry once, if fails report to user |
| Subagent spawn failure | Retry once, if fails exit with error |
| No new CIPE detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |
| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |
## Example Session
### Example 1: Normal Flow with Self-Healing (medium verbosity)
```
[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
```
### Example 2: Pre-CI Failure (medium verbosity)
```
[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
```
-228
View File
@@ -1,228 +0,0 @@
---
name: nx-generate
description: Generate code using nx generators. USE WHEN scaffolding code or transforming existing code - for example creating libraries or applications, or anything else that is boilerplate code or automates repetitive tasks. ALWAYS use this first when generating code with Nx instead of calling MCP tools or running nx generate immediately.
---
# Run Nx Generator
Nx generators are powerful tools that scaffold projects, make automated code migrations or automate repetitive tasks in a monorepo. They ensure consistency across the codebase and reduce boilerplate work.
This skill applies when the user wants to:
- Create new projects like libraries or applications
- Scaffold features or boilerplate code
- Run workspace-specific or custom generators
- Do anything else that an nx generator exists for
## Generator Discovery Flow
### Step 1: List Available Generators
Use the Nx CLI to discover available generators:
- List all generators for a plugin: `npx nx list @nx/react`
- View available plugins: `npx nx list`
This includes:
- Plugin generators (e.g., `@nx/react:library`, `@nx/js:library`)
- Local workspace generators (defined in the repo's own plugins)
### Step 2: Match Generator to User Request
Based on the user's request, identify which generator(s) could fulfill their needs. Consider:
- What artifact type they want to create (library, application, etc.)
- Which framework or technology stack is relevant
- Whether they mentioned specific generator names
**IMPORTANT**: When both a local workspace generator and an external plugin generator could satisfy the request, **always prefer the local workspace generator**. Local generators are customized for the specific repo's patterns and conventions.
It's possible that the user request is something that no Nx generator exists for whatsoever. In this case, you can stop using this skill and try to help the user another way. HOWEVER, the burden of proof for this is high. Before aborting, carefully consider each and every generator that's available. Look into details for any that could be related in any way before making this decision.
## Pre-Execution Checklist
Before running any generator, complete these steps:
### 1. Fetch Generator Schema
Use the `--help` flag to understand all available options:
```bash
npx nx g @nx/react:library --help
```
Pay attention to:
- Required options that must be provided
- Optional options that may be relevant to the user's request
- Default values that might need to be overridden
### 2. Read Generator Source Code
Understanding what the generator actually does helps you:
- Know what files will be created/modified
- Understand any side effects (updating configs, installing deps, etc.)
- Identify options that might not be obvious from the schema
To find generator source code:
- For plugin generators: Use `node -e "console.log(require.resolve('@nx/<plugin>/generators.json'));"` to find the generators.json, then locate the source from there
- If that fails, read directly from `node_modules/<plugin>/generators.json`
- For local generators: They are typically in `tools/generators/` or a local plugin directory. You can search the repo for the generator name to find it.
### 2.5 Reevaluate if the generator is right
Once you have built up an understanding of what the selected generator does, reconsider: Is this the right generator to service the user request?
If not, it's okay to go back to the Generator Discovery Flow and select a different generator before proceeding. If you do, make sure to go through the entire pre-execution checklist once more.
### 3. Understand Repo Context
Before generating, examine the target area of the codebase:
- Look at similar existing artifacts (other libraries, applications, etc.)
- Identify patterns and conventions used in the repo
- Note naming conventions, file structures, and configuration patterns
- Try to match these patterns when configuring the generator
For example, if similar libraries are using a specific test runner, build tool or linter, try to match that if possible.
If projects or other artifacts are organized with a specific naming convention, try to match it.
### 4. Validate Required Options
Ensure all required options have values:
- Map the user's request to generator options
- Infer values from context where possible
- Ask the user for any critical missing information
## Execution
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally.
Many generators will behave differently based on where they are executed. For example, first-party nx library generators use the cwd to determine the directory that the library should be placed in. This is highly important.
### Consider Dry-Run (Optional)
Running with `--dry-run` first is strongly encouraged but not mandatory. Use your judgment:
- For complex generators or unfamiliar territory: do a dry-run first
- For simple, well-understood generators: may proceed directly
- Dry-run shows file names and created/deleted/modified markers, but not content
- There are cases where a generator does not support dry-run (for example if it had to install an npm package) - in that case --dry-run might fail. Don't be discouraged but simply move on to running the generator for real and iterating from there.
### Running the Generator
Execute the generator with:
```bash
nx generate <generator-name> <options> --no-interactive
```
**CRITICAL**: Always include `--no-interactive` to prevent prompts that would hang the execution.
Example:
```bash
nx generate @nx/react:library --name=my-utils --no-interactive
```
### Handling Generator Failures
If the generator fails:
1. **Diagnose the error** - Read the error message carefully
2. **Identify the cause** - Missing options, invalid values, conflicts, etc.
3. **Attempt automatic fix** - Adjust options or resolve conflicts
4. **Retry** - Run the generator again with corrected options
Common failure reasons:
- Missing required options
- Invalid option values
- Conflicting with existing files
- Missing dependencies
- Generator doesn't support certain flag combinations
## Post-Generation
### 1. Modify Generated Code (If Needed)
Generators provide a starting point, but the output may need adjustment to match the user's specific requirements:
- Add or modify functionality as requested
- Adjust imports, exports, or configurations
- Integrate with existing code patterns in the repo
### 2. Format Code
Run formatting on all generated/modified files:
```bash
nx format --fix
```
Languages other than javascript/typescript might need other formatting invocations too.
### 3. Run Verification
Verify that the generated code works correctly. What this looks like will vary depending on the type of generator and the targets available.
If the generator created a new project, run its targets directly
Use your best judgement to determine what needs to be verified.
Example:
```bash
nx lint <new-project>
nx test <new-project>
nx build <new-project>
```
### 4. Handle Verification Failures
When verification fails:
**If scope is manageable** (a few lint errors, minor type issues):
- Fix the issues
- Re-run verification to confirm
**If issues are extensive** (many errors, complex problems):
- Attempt simple, obvious fixes first
- If still failing, escalate to the user with:
- Description of what was generated
- What verification is failing
- What you've attempted to fix
- Remaining issues that need user input
## Error Handling
### Generator Failures
- Check the error message for specific causes
- Verify all required options are provided
- Check for conflicts with existing files
- Ensure the generator name and options are correct
### Missing Options
- Consult the generator schema for required fields
- Infer values from context when reasonable
- Ask the user for values that cannot be inferred
## Key Principles
1. **Local generators first** - Always prefer workspace/local generators over external plugin generators when both could work
2. **Understand before running** - Read both the schema AND the source code to fully understand what will happen
3. **No prompts** - Always use `--no-interactive` to prevent hanging
4. **Generators are starting points** - Modify the output as needed to fully satisfy the user's requirements
5. **Verify changes work** - Don't just generate; ensure the code builds, lints, and tests pass
6. **Be proactive about fixes** - Don't just report errors; attempt to resolve them automatically when possible
7. **Match repo patterns** - Study existing similar code in the repo and match its conventions
-9
View File
@@ -1,9 +0,0 @@
---
name: nx-plugins
description: Find and add Nx plugins. USE WHEN user wants to discover available plugins, install a new plugin, or add support for a specific framework or technology to the workspace.
---
## Finding and Installing new plugins
- List plugins: `pnpm nx list`
- Install plugins `pnpm nx add <plugin>`. Example: `pnpm nx add @nx/react`.
-58
View File
@@ -1,58 +0,0 @@
---
name: nx-run-tasks
description: Helps with running tasks in an Nx workspace. USE WHEN the user wants to execute build, test, lint, serve, or run any other tasks defined in the workspace.
---
You can run tasks with Nx in the following way.
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Look at the package.json or lockfile to determine which package manager is in use.
For more details on any command, run it with `--help` (e.g. `nx run-many --help`, `nx affected --help`).
## Understand which tasks can be run
You can check those via `nx show project <projectname> --json`, for example `nx show project myapp --json`. It contains a `targets` section which has information about targets that can be run. You can also just look at the `package.json` scripts or `project.json` targets, but you might miss out on inferred tasks by Nx plugins.
## Run a single task
```
nx run <project>:<task>
```
where `project` is the project name defined in `package.json` or `project.json` (if present).
## Run multiple tasks
```
nx run-many -t build test lint typecheck
```
You can pass a `-p` flag to filter to specific projects, otherwise it runs on all projects. You can also use `--exclude` to exclude projects, and `--parallel` to control the number of parallel processes (default is 3).
Examples:
- `nx run-many -t test -p proj1 proj2` — test specific projects
- `nx run-many -t test --projects=*-app --exclude=excluded-app` — test projects matching a pattern
- `nx run-many -t test --projects=tag:api-*` — test projects by tag
## Run tasks for affected projects
Use `nx affected` to only run tasks on projects that have been changed and projects that depend on changed projects. This is especially useful in CI and for large workspaces.
```
nx affected -t build test lint
```
By default it compares against the base branch. You can customize this:
- `nx affected -t test --base=main --head=HEAD` — compare against a specific base and head
- `nx affected -t test --files=libs/mylib/src/index.ts` — specify changed files directly
## Useful flags
These flags work with `run`, `run-many`, and `affected`:
- `--skipNxCache` — rerun tasks even when results are cached
- `--verbose` — print additional information such as stack traces
- `--nxBail` — stop execution after the first failed task
- `--configuration=<name>` — use a specific configuration (e.g. `production`)
-186
View File
@@ -1,186 +0,0 @@
---
name: nx-workspace
description: "Explore and understand Nx workspaces. USE WHEN answering any questions about the nx workspace, the projects in it or tasks to run. EXAMPLES: 'What projects are in this workspace?', 'How is project X configured?', 'What targets can I run?', 'What's affected by my changes?', 'Which projects depend on library Y?', or any questions about Nx workspace structure, project configuration, or available tasks."
---
# Nx Workspace Exploration
This skill provides read-only exploration of Nx workspaces. Use it to understand workspace structure, project configuration, available targets, and dependencies.
Keep in mind that you might have to prefix commands with `npx`/`pnpx`/`yarn` if nx isn't installed globally. Check the lockfile to determine the package manager in use.
## Listing Projects
Use `nx show projects` to list projects in the workspace.
```bash
# List all projects
nx show projects
# Filter by pattern (glob)
nx show projects --projects "apps/*"
nx show projects --projects "shared-*"
# Filter by project type
nx show projects --type app
nx show projects --type lib
nx show projects --type e2e
# Filter by target (projects that have a specific target)
nx show projects --withTarget build
nx show projects --withTarget e2e
# Find affected projects (changed since base branch)
nx show projects --affected
nx show projects --affected --base=main
nx show projects --affected --type app
# Combine filters
nx show projects --type lib --withTarget test
nx show projects --affected --exclude="*-e2e"
# Output as JSON
nx show projects --json
```
## Project Configuration
Use `nx show project <name> --json` to get the full resolved configuration for a project.
**Important**: Do NOT read `project.json` directly - it only contains partial configuration. The `nx show project` command returns the full resolved config including inferred targets from plugins.
You can read the full project schema at `node_modules/nx/schemas/project-schema.json` to understand nx project configuration options.
```bash
# Get full project configuration
nx show project my-app --json
# Extract specific parts from the JSON
nx show project my-app --json | jq '.targets'
nx show project my-app --json | jq '.targets.build'
nx show project my-app --json | jq '.targets | keys'
# Check project metadata
nx show project my-app --json | jq '{name, root, sourceRoot, projectType, tags}'
```
## Target Information
Targets define what tasks can be run on a project.
```bash
# List all targets for a project
nx show project my-app --json | jq '.targets | keys'
# Get full target configuration
nx show project my-app --json | jq '.targets.build'
# Check target executor/command
nx show project my-app --json | jq '.targets.build.executor'
nx show project my-app --json | jq '.targets.build.command'
# View target options
nx show project my-app --json | jq '.targets.build.options'
# Check target inputs/outputs (for caching)
nx show project my-app --json | jq '.targets.build.inputs'
nx show project my-app --json | jq '.targets.build.outputs'
# Find projects with a specific target
nx show projects --withTarget serve
nx show projects --withTarget e2e
```
## Workspace Configuration
Read `nx.json` directly for workspace-level configuration.
You can read the full project schema at `node_modules/nx/schemas/nx-schema.json` to understand nx project configuration options.
```bash
# Read the full nx.json
cat nx.json
# Or use jq for specific sections
cat nx.json | jq '.targetDefaults'
cat nx.json | jq '.namedInputs'
cat nx.json | jq '.plugins'
cat nx.json | jq '.generators'
```
Key nx.json sections:
- `targetDefaults` - Default configuration applied to all targets of a given name
- `namedInputs` - Reusable input definitions for caching
- `plugins` - Nx plugins and their configuration
- ...and much more, read the schema or nx.json for details
## Affected Projects
Find projects affected by changes in the current branch.
```bash
# Affected since base branch (auto-detected)
nx show projects --affected
# Affected with explicit base
nx show projects --affected --base=main
nx show projects --affected --base=origin/main
# Affected between two commits
nx show projects --affected --base=abc123 --head=def456
# Affected apps only
nx show projects --affected --type app
# Affected excluding e2e projects
nx show projects --affected --exclude="*-e2e"
# Affected by uncommitted changes
nx show projects --affected --uncommitted
# Affected by untracked files
nx show projects --affected --untracked
```
## Common Exploration Patterns
### "What's in this workspace?"
```bash
nx show projects
nx show projects --type app
nx show projects --type lib
```
### "How do I build/test/lint project X?"
```bash
nx show project X --json | jq '.targets | keys'
nx show project X --json | jq '.targets.build'
```
### "What depends on library Y?"
```bash
# Find projects that may depend on Y by searching for imports
# (Nx doesn't have a direct "dependents" command via CLI)
grep -r "from '@myorg/Y'" --include="*.ts" --include="*.tsx" apps/ libs/
```
### "What configuration options are available?"
```bash
cat node_modules/nx/schemas/nx-schema.json | jq '.properties | keys'
cat node_modules/nx/schemas/project-schema.json | jq '.properties | keys'
```
### "Why is project X affected?"
```bash
# Check what files changed
git diff --name-only main
# See which project owns those files
nx show project X --json | jq '.root'
```
-101
View File
@@ -1,101 +0,0 @@
name: Banner Content Monitor
on:
schedule:
- cron: '*/15 * * * *'
workflow_dispatch: # Allow manual trigger
permissions: {}
env:
BANNER_URL: ${{ vars.BANNER_URL }}
jobs:
check-and-deploy:
if: ${{ github.repository_owner == 'nrwl' }}
runs-on: ubuntu-latest
steps:
- name: Fetch banner content and compute hash
id: banner
run: |
if [ -z "$BANNER_URL" ]; then
echo "BANNER_URL is not set"
exit 1
fi
# Fetch content and compute hash
CONTENT_HASH=$(curl -sf "$BANNER_URL" | sha256sum | cut -d' ' -f1)
if [ -z "$CONTENT_HASH" ]; then
echo "Failed to fetch banner content"
exit 1
fi
echo "current_hash=$CONTENT_HASH" >> $GITHUB_OUTPUT
echo "Current banner hash: $CONTENT_HASH"
- name: Restore cached hash
id: cache
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: .banner-hash
key: banner-content-hash-
restore-keys: |
banner-content-hash-
- name: Compare hashes
id: compare
run: |
CURRENT_HASH="${{ steps.banner.outputs.current_hash }}"
if [ -f .banner-hash ]; then
CACHED_HASH=$(cat .banner-hash)
echo "Cached hash: $CACHED_HASH"
else
CACHED_HASH=""
echo "No cached hash found"
fi
if [ "$CURRENT_HASH" != "$CACHED_HASH" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Banner content has changed!"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Banner content unchanged"
fi
- name: Setup Node
if: steps.compare.outputs.changed == 'true'
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: '24'
- name: Trigger Netlify deploys
if: steps.compare.outputs.changed == 'true'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
run: |
npm install -g netlify-cli
echo "Triggering nx-docs deploy..."
netlify deploy --trigger --prod -s nx-docs
echo "Triggering nx-dev deploy..."
netlify deploy --trigger --prod -s nx-dev
echo "Triggering nrwl-blog deploy..."
netlify deploy --trigger --prod -s nrwl-blog
echo "All deploys triggered successfully"
- name: Save new hash to cache
if: steps.compare.outputs.changed == 'true'
run: |
echo "${{ steps.banner.outputs.current_hash }}" > .banner-hash
- name: Update cache
if: steps.compare.outputs.changed == 'true'
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: .banner-hash
key: banner-content-hash-${{ github.run_id }}
-318
View File
@@ -1,318 +0,0 @@
name: CI
on:
push:
branches:
- master
- '[0-9]+.[0-9]+.x'
pull_request:
branches:
- "**"
env:
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_CLOUD_ENABLE_METRICS_COLLECTION: 'true'
PNPM_HOME: ~/.pnpm
jobs:
main-linux:
runs-on: ubuntu-latest
env:
NX_BATCH_MODE: 'true'
NX_E2E_CI_CACHE_KEY: e2e-github-linux
NX_DAEMON: 'true'
NX_PERF_LOGGING: 'false'
NX_VERBOSE_LOGGING: 'false'
NX_NATIVE_LOGGING: 'false'
NX_E2E_RUN_E2E: 'true'
NX_CI_EXECUTION_ENV: 'linux'
NX_CLOUD_NO_TIMEOUTS: 'true'
NX_ALLOW_NON_CACHEABLE_DTE: 'true'
NX_CLOUD_EXPERIMENTAL_POLLING: 'true'
NX_CLOUD_CONTINUOUS_ASSIGNMENT: 'false'
NX_CLOUD_VERBOSE_LOGGING: 'true'
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
filter: tree:0
- name: Set verbose logging from debug mode
if: runner.debug == '1'
run: echo "NX_VERBOSE_LOGGING=true" >> "$GITHUB_ENV"
- name: Fetch Master
run: git fetch origin master:master
if: ${{ github.event_name == 'pull_request' }}
- name: Set SHAs
uses: nrwl/nx-set-shas@310288c04d90696f9f1bc27c5e3caea6642b53d4 # v5.0.0
with:
main-branch-name: 'master'
- name: Start CI Run
run: npx nx-cloud@next start-ci-run --distribute-on="./.nx/workflows/dynamic-changesets.yaml" --stop-agents-after="e2e"
- name: Setup dev tools with mise
uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 # v3
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare --activate
- name: Get pnpm store directory
id: pnpm-cache
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache pnpm store
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Setup Gradle
uses: gradle/actions/setup-gradle@48b5f213c81028ace310571dc5ec0fbbca0b2947 # v4.4.3
- name: Install project dependencies
run: pnpm install --frozen-lockfile
- name: Restore .NET analyzer projects
run: dotnet restore nx.sln
- name: Nx Report
run:
pnpm nx report
- name: Run Checks/Lint/Test/Build
run: |
pids=()
pnpm nx record -- nx format:check &
pids+=($!)
pnpm nx record -- nx sync:check
pids+=($!)
pnpm nx build workspace-plugin && pnpm nx record -- pnpm nx-cloud conformance:check
pids+=($!)
pnpm nx run-many -t check-imports check-lock-files check-codeowners --parallel=1 --no-dte &
pids+=($!)
pnpm nx affected --targets=lint,test,build,e2e,e2e-ci,format-native,lint-native,gradle:build-ci,vale,run &
pids+=($!)
for pid in "${pids[@]}"; do
wait "$pid"
done
timeout-minutes: 100
- name: Fix CI
run: pnpm nx fix-ci
if: failure()
main-macos:
runs-on: macos-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}${{ contains(github.event_name, 'push') && format('-{0}', github.sha) || '' }}
cancel-in-progress: true
env:
NX_E2E_CI_CACHE_KEY: e2e-github-macos
NX_PERF_LOGGING: 'false'
NX_CI_EXECUTION_ENV: 'macos'
SELECTED_PM: 'npm'
steps:
- name: Log concurrency info
run: |
echo "Concurrency group: ${{ github.workflow }}-${{ github.ref }}${{ contains(github.event_name, 'push') && format('-{0}', github.sha) || '' }}"
echo "Concurrency cancel-in-progress: ${{ !contains(github.event_name, 'push') }}"
echo "Concurrency cancel-event-name: ${{ github.event_name }}"
if: always()
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
filter: tree:0
- name: Set verbose logging from debug mode
if: runner.debug == '1'
run: echo "NX_VERBOSE_LOGGING=true" >> "$GITHUB_ENV"
- name: Fetch Master
run: git fetch origin master:master
if: ${{ github.event_name == 'pull_request' }}
- name: Setup dev tools with mise
uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 # v3
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare --activate
- name: Set SHAs
uses: nrwl/nx-set-shas@310288c04d90696f9f1bc27c5e3caea6642b53d4 # v5.0.0
with:
main-branch-name: 'master'
- name: Check for React Native changes
id: check-changes
run: |
HAS_CHANGED=$(node ./scripts/check-react-native-changes.js $NX_BASE $NX_HEAD);
if $HAS_CHANGED; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "React Native projects are affected, will run macOS tests"
else
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No React Native projects affected, skipping macOS tests"
fi
- name: Restore Homebrew packages
if: steps.check-changes.outputs.has_changes == 'true'
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: |
/opt/homebrew
~/Library/Caches/Homebrew
key: nrwl-nx-homebrew-packages
- name: Configure Detox Environment, Install applesimutils
if: steps.check-changes.outputs.has_changes == 'true'
run: |
# Ensure Xcode command line tools are installed and configured
xcode-select --print-path || sudo xcode-select --reset
sudo xcode-select -s /Applications/Xcode.app
# Install or update applesimutils with error handling
if ! brew list applesimutils &>/dev/null; then
echo "Installing applesimutils..."
HOMEBREW_NO_AUTO_UPDATE=1 brew tap wix/brew >/dev/null
HOMEBREW_NO_AUTO_UPDATE=1 brew install applesimutils >/dev/null || {
echo "Failed to install applesimutils, retrying with update..."
brew update
HOMEBREW_NO_AUTO_UPDATE=1 brew install applesimutils
}
else
echo "Updating applesimutils..."
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade applesimutils || true
fi
# Verify applesimutils installation
applesimutils --version || (echo "applesimutils installation failed" && exit 1)
# Configure environment for M-series Mac
echo "DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer" >> $GITHUB_ENV
echo "PLATFORM_NAME=iOS Simulator" >> $GITHUB_ENV
# Set additional environment variables for better debugging
echo "DETOX_DISABLE_TELEMETRY=1" >> $GITHUB_ENV
echo "DETOX_LOG_LEVEL=trace" >> $GITHUB_ENV
# Verify Xcode installation
xcodebuild -version
# List available simulators
xcrun simctl list devices available
timeout-minutes: 10
continue-on-error: false
- name: Reset iOS Simulators
if: steps.check-changes.outputs.has_changes == 'true'
id: reset-simulators
run: |
echo "Resetting iOS Simulators..."
# Kill simulator processes
sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService 2>/dev/null || true
killall "Simulator" 2>/dev/null || true
killall "iOS Simulator" 2>/dev/null || true
# Wait for processes to terminate
sleep 3
# Shutdown and erase all simulators (ignore failures)
xcrun simctl shutdown all 2>/dev/null || true
sleep 5
xcrun simctl erase all 2>/dev/null || true
# If erase failed, try the nuclear option
if xcrun simctl list devices | grep -q "Booted" 2>/dev/null; then
echo "Standard reset failed, using nuclear option..."
rm -rf ~/Library/Developer/CoreSimulator/Devices/* 2>/dev/null || true
launchctl remove com.apple.CoreSimulator.CoreSimulatorService 2>/dev/null || true
sleep 3
fi
# Clean up additional directories
rm -rf ~/Library/Developer/CoreSimulator/Caches/* 2>/dev/null || true
rm -rf ~/Library/Logs/CoreSimulator/* 2>/dev/null || true
rm -rf ~/Library/Developer/Xcode/DerivedData/* 2>/dev/null || true
echo "Simulator reset completed"
timeout-minutes: 5
continue-on-error: true
- name: Verify Simulator Reset
if: steps.check-changes.outputs.has_changes == 'true' && steps.reset-simulators.outcome == 'success'
run: |
# Verify CoreSimulator service restarted
pgrep -fl "CoreSimulator" || (echo "CoreSimulator service not running" && exit 1)
# Check simulator list is clean
xcrun simctl list devices
# Verify simulator runtime paths exist and are writable
test -d ~/Library/Developer/CoreSimulator/Devices || (echo "Simulator devices directory missing" && exit 1)
touch ~/Library/Developer/CoreSimulator/Devices/test || (echo "Simulator devices directory not writable" && exit 1)
rm ~/Library/Developer/CoreSimulator/Devices/test
timeout-minutes: 5
- name: Diagnose Simulator Reset Failure
if: steps.check-changes.outputs.has_changes == 'true' && steps.reset-simulators.outcome == 'failure'
run: |
echo "Simulator reset failed. Collecting diagnostic information..."
xcrun simctl list
echo "Checking simulator logs..."
ls -la ~/Library/Logs/CoreSimulator/ || echo "No simulator logs found"
- name: Save Homebrew Cache
if: steps.check-changes.outputs.has_changes == 'true'
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: |
/opt/homebrew
~/Library/Caches/Homebrew
key: nrwl-nx-homebrew-packages
- name: Get pnpm store directory
if: steps.check-changes.outputs.has_changes == 'true'
id: pnpm-cache-macos
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache pnpm store
if: steps.check-changes.outputs.has_changes == 'true'
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
with:
path: ${{ steps.pnpm-cache-macos.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install project dependencies
if: steps.check-changes.outputs.has_changes == 'true'
run: |
pnpm install --frozen-lockfile
pnpm playwright install --with-deps
- name: Run E2E Tests for macOS
if: steps.check-changes.outputs.has_changes == 'true'
run: |
pnpm nx affected -t e2e-macos-local --parallel=1 --base=$NX_BASE --head=$NX_HEAD
-114
View File
@@ -1,114 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ "master" ]
schedule:
- cron: '20 14 * * 6'
jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write
# required to fetch internal or private CodeQL packs
packages: read
# only required for workflows in private repositories
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
# We would like to test our Java / Kotlin... but its currently failing. We can follow up.
# - language: java-kotlin
# build-mode: autobuild
- language: javascript-typescript
build-mode: none
- language: rust
build-mode: none
- language: csharp
build-mode: autobuild
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup Language Tooling
uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 # v3
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare --activate
# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
# - name: Setup runtime (example)
# uses: actions/setup-example@v1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@15403aac29bd91419968e066cded66bde56b0283 # v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@15403aac29bd91419968e066cded66bde56b0283 # v3
with:
category: "/language:${{matrix.language}}"
-111
View File
@@ -1,111 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
pull_request:
branches: [ "**" ]
jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required to fetch internal or private CodeQL packs
packages: read
# only required for workflows in private repositories
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
# See comment in @./codeql-master.yml about Java / Kotlin
# - language: java-kotlin
# build-mode: autobuild
- language: javascript-typescript
build-mode: none
- language: rust
build-mode: none
- language: csharp
build-mode: autobuild
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup Language Tooling
uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 # v3
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare --activate
# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
# - name: Setup runtime (example)
# uses: actions/setup-example@v1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@15403aac29bd91419968e066cded66bde56b0283 # v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@15403aac29bd91419968e066cded66bde56b0283 # v3
with:
category: "/language:${{matrix.language}}"
upload: 'never'
upload-database: false
+1 -1
View File
@@ -1,4 +1,4 @@
name: Unmergeable Labels Check
name: Unmergable Labels Check
on:
pull_request:
+449 -279
View File
@@ -2,7 +2,7 @@ name: E2E matrix
on:
schedule:
- cron: '0 5 * * *'
- cron: "0 0 * * *"
workflow_dispatch:
inputs:
debug_enabled:
@@ -17,69 +17,49 @@ env:
permissions: {}
jobs:
preinstall:
if: ${{ github.repository_owner == 'nrwl' }}
runs-on: ${{ matrix.os }}
timeout-minutes: 20
env:
NODE_VERSION: ${{ matrix.node_version }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
# - windows-latest Windows fails to build gradle wrapper which always runs when we build nx.
## https://staging.nx.app/runs/LgD4vxGn8w?utm_source=pull-request&utm_medium=comment
node_version:
- 22
- 24
# TODO: re-enable once playwright ships the yauzl fix for node 26 extract hang.
# See https://github.com/microsoft/playwright/issues/40724
# - 26
- 19
- 18
- 16
exclude:
# macos skips the oldest node to keep the macos matrix slim
# run just node v18 on macos
- os: macos-latest
node_version: 22
# - os: windows-latest TODO(Jack): Windows fails to build gradle wrapper which always runs when we build nx. Re-enable when we fix this.
# node_version: 22
node_version: 19
- os: macos-latest
node_version: 16
name: Cache install (${{ matrix.os }}, node v${{ matrix.node_version }})
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
filter: tree:0
uses: actions/checkout@v3
- name: Setup dev tools with mise
uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 # v3
- name: Enable corepack and install pnpm
- name: Install PNPM
run: |
npm install -g corepack@latest
corepack enable
corepack prepare --activate
npm install -g @pnpm/exe@8.3.1
- name: Get pnpm store directory
id: pnpm-cache
run: echo "path=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache pnpm store
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
- name: Set node
uses: actions/setup-node@v3
with:
path: ${{ steps.pnpm-cache.outputs.path }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
node-version: ${{ matrix.node_version }}
cache: 'pnpm'
- name: Ensure Python setuptools Installed on Macos
if: ${{ matrix.os == 'macos-latest' }}
id: brew-install-python-setuptools
run: brew install python-setuptools
- name: Cache node_modules
id: cache-modules
uses: actions/cache@v3
with:
lookup-only: true
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ matrix.node_version }}-${{ github.run_id }}
- name: Install packages
run: |
pnpm install --frozen-lockfile
pnpm playwright install --with-deps
if: steps.cache-modules.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile
- name: Homebrew cache directory path
if: ${{ matrix.os == 'macos-latest' }}
@@ -88,7 +68,7 @@ jobs:
- name: Cache Homebrew
if: ${{ matrix.os == 'macos-latest' }}
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
uses: actions/cache@v3
with:
lookup-only: true
path: ${{ steps.homebrew-cache-dir-path.outputs.dir }}
@@ -98,7 +78,7 @@ jobs:
- name: Cache Cypress
id: cache-cypress
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
uses: actions/cache@v3
with:
lookup-only: true
path: '${{ github.workspace }}/.cypress'
@@ -108,63 +88,262 @@ jobs:
if: steps.cache-cypress.outputs.cache-hit != 'true'
run: npx cypress install
prepare-matrix:
name: Prepare matrix combinations
if: ${{ github.repository_owner == 'nrwl' }}
timeout-minutes: 5
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.process-json.outputs.MATRIX }}
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
filter: tree:0
- name: Process matrix data
id: process-json
run: echo "MATRIX=$(npx tsx .github/workflows/nightly/process-matrix.ts | jq -c .)" >> $GITHUB_OUTPUT
e2e:
if: ${{ github.repository_owner == 'nrwl' }}
needs:
- preinstall
- prepare-matrix
needs: preinstall
permissions:
contents: read
runs-on: ${{ matrix.os }}
timeout-minutes: 200 # <- cap each job to 200 minutes
env:
NODE_VERSION: ${{ matrix.node_version }}
timeout-minutes: 90
strategy:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}} # Load matrix from previous job
matrix:
os:
- ubuntu-latest
- macos-latest
node_version:
- 19
- 18
- 16
package_manager:
- npm
- yarn
- pnpm
project:
- e2e-angular-core
- e2e-angular-extensions
- e2e-cypress
- e2e-detox
- e2e-esbuild
- e2e-expo
- e2e-jest
- e2e-js
- e2e-lerna-smoke-tests
- e2e-linter
- e2e-next
- e2e-node
- e2e-nx-init
- e2e-nx-misc
- e2e-nx-plugin
- e2e-nx-run
- e2e-react-core
- e2e-react-extensions
- e2e-react-native
- e2e-web
- e2e-rollup
- e2e-storybook
- e2e-storybook-angular
- e2e-vite
- e2e-webpack
- e2e-workspace-create
- e2e-workspace-create-npm
include:
# os short names
- os: ubuntu-latest
os_name: 'Linux'
- os: macos-latest
os_name: 'MacOS'
# test timeouts
- os: ubuntu-latest
os_timeout: 60
- os: macos-latest
os_timeout: 90
# codeowner groups
- project: e2e-angular-core
codeowners: 'S04SS457V38'
- project: e2e-angular-extensions
codeowners: 'S04SS457V38'
- project: e2e-cypress
codeowners: 'S04T16BTJJY'
- project: e2e-detox
codeowners: 'S04TNCNJG5N'
- project: e2e-esbuild
codeowners: 'S04SJ6HHP0X'
- project: e2e-expo
codeowners: 'S04TNCNJG5N'
- project: e2e-jest
codeowners: 'S04T16BTJJY'
- project: e2e-js
codeowners: 'S04SJ6HHP0X'
- project: e2e-lerna-smoke-tests
codeowners: 'S04TNCVEETS'
- project: e2e-linter
codeowners: 'S04SYJGKSCT'
- project: e2e-next
codeowners: 'S04TNCNJG5N'
- project: e2e-node
codeowners: 'S04SJ6HHP0X'
- project: e2e-nx-init
codeowners: 'S04SYHYKGNP'
- project: e2e-nx-misc
codeowners: 'S04SYHYKGNP'
- project: e2e-nx-plugin
codeowners: 'S04SYHYKGNP'
- project: e2e-nx-run
codeowners: 'S04SYHYKGNP'
- project: e2e-react-core
codeowners: 'S04TNCNJG5N'
- project: e2e-react-extensions
codeowners: 'S04TNCNJG5N'
- project: e2e-react-native
codeowners: 'S04TNCNJG5N'
- project: e2e-web
codeowners: 'S04SJ6PL98X'
- project: e2e-rollup
codeowners: 'S04SJ6PL98X'
- project: e2e-storybook
codeowners: 'S04SVQ8H0G5'
- project: e2e-storybook-angular
codeowners: 'S04SVQ8H0G5'
- project: e2e-vite
codeowners: 'S04SJ6PL98X'
- project: e2e-webpack
codeowners: 'S04SJ6PL98X'
- project: e2e-workspace-create
codeowners: 'S04SYHYKGNP'
- project: e2e-workspace-create-npm
codeowners: 'S04SYHYKGNP'
exclude:
# exclude react-native tests from ubuntu
- os: ubuntu-latest
project: e2e-react-native
- os: ubuntu-latest
project: e2e-detox
- os: ubuntu-latest
project: e2e-expo
# exclude non-CNW/Lerna tests from non-LTS node versions
- node_version: 16
project: e2e-angular-core
- node_version: 16
project: e2e-angular-extensions
- node_version: 16
project: e2e-cypress
- node_version: 16
project: e2e-detox
- node_version: 16
project: e2e-esbuild
- node_version: 16
project: e2e-expo
- node_version: 16
project: e2e-jest
- node_version: 16
project: e2e-js
- node_version: 16
project: e2e-linter
- node_version: 16
project: e2e-next
- node_version: 16
project: e2e-node
- node_version: 16
project: e2e-nx-init
- node_version: 16
project: e2e-nx-misc
- node_version: 16
project: e2e-nx-plugin
- node_version: 16
project: e2e-lerna-smoke-tests
- node_version: 16
project: e2e-react-core
- node_version: 16
project: e2e-react-extensions
- node_version: 16
project: e2e-react-native
- node_version: 16
project: e2e-web
- node_version: 16
project: e2e-rollup
- node_version: 16
project: e2e-storybook
- node_version: 16
project: e2e-storybook-angular
- node_version: 16
project: e2e-vite
- node_version: 16
project: e2e-webpack
- node_version: 19
project: e2e-angular-core
- node_version: 19
project: e2e-angular-extensions
- node_version: 19
project: e2e-cypress
- node_version: 19
project: e2e-detox
- node_version: 19
project: e2e-esbuild
- node_version: 19
project: e2e-expo
- node_version: 19
project: e2e-jest
- node_version: 19
project: e2e-js
- node_version: 19
project: e2e-linter
- node_version: 19
project: e2e-next
- node_version: 19
project: e2e-node
- node_version: 19
project: e2e-nx-init
- node_version: 19
project: e2e-nx-misc
- node_version: 19
project: e2e-nx-plugin
- node_version: 19
project: e2e-lerna-smoke-tests
- node_version: 19
project: e2e-react-core
- node_version: 19
project: e2e-react-extensions
- node_version: 19
project: e2e-react-native
- node_version: 19
project: e2e-web
- node_version: 19
project: e2e-rollup
- node_version: 19
project: e2e-storybook
- node_version: 19
project: e2e-storybook-angular
- node_version: 19
project: e2e-vite
- node_version: 19
project: e2e-webpack
# run just npm v18 on macos
- os: macos-latest
package_manager: yarn
- os: macos-latest
package_manager: pnpm
- os: macos-latest
node_version: 16
- os: macos-latest
node_version: 19
fail-fast: false
name: ${{ matrix.os_name }}/${{ matrix.package_manager }}/${{ matrix.node_version }} ${{ join(matrix.project) }}
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
filter: tree:0
uses: actions/checkout@v3
- name: Prepare dir for output
run: mkdir -p outputs
- name: Setup dev tools with mise
uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 # v3
- name: Enable corepack and install pnpm
- name: Install PNPM
run: |
npm install -g corepack@latest
corepack enable
corepack prepare --activate
npm install -g @pnpm/exe@8.3.1
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
cache: 'pnpm'
- name: Cache node_modules
id: cache-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ matrix.node_version }}-${{ github.run_id }}
- name: Install packages
run: |
pnpm install --frozen-lockfile
pnpm playwright install --with-deps
run: pnpm install --frozen-lockfile
- name: Cleanup
if: ${{ matrix.os == 'ubuntu-latest' }}
@@ -173,7 +352,7 @@ jobs:
# https://github.com/actions/virtual-environments/issues/2840
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf '/usr/local/share/boost'
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get install lsof
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
@@ -185,7 +364,7 @@ jobs:
- name: Cache Homebrew
if: ${{ matrix.os == 'macos-latest' }}
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
uses: actions/cache@v3
with:
path: ${{ steps.homebrew-cache-dir-path.outputs.dir }}
key: brew-${{ matrix.node_version }}
@@ -194,7 +373,7 @@ jobs:
- name: Cache Cypress
id: cache-cypress
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
uses: actions/cache@v3
with:
path: '${{ github.workspace }}/.cypress'
key: ${{ runner.os }}-cypress
@@ -203,159 +382,43 @@ jobs:
if: steps.cache-cypress.outputs.cache-hit != 'true'
run: npx cypress install
- name: Configure Detox Environment, Install applesimutils
- name: Install applesimutils, reset ios simulators
if: ${{ matrix.os == 'macos-latest' }}
run: |
# Ensure Xcode command line tools are installed and configured
xcode-select --print-path || sudo xcode-select --reset
sudo xcode-select -s /Applications/Xcode.app
# Install or update applesimutils with error handling
if ! brew list applesimutils &>/dev/null; then
echo 'Installing applesimutils...'
HOMEBREW_NO_AUTO_UPDATE=1 brew tap wix/brew >/dev/null
HOMEBREW_NO_AUTO_UPDATE=1 brew install applesimutils >/dev/null || {
echo 'Failed to install applesimutils, retrying with update...'
brew update
HOMEBREW_NO_AUTO_UPDATE=1 brew install applesimutils
}
else
echo 'Updating applesimutils...'
HOMEBREW_NO_AUTO_UPDATE=1 brew upgrade applesimutils || true
fi
# Verify applesimutils installation
applesimutils --version || (echo 'applesimutils installation failed' && exit 1)
# Configure environment for M-series Mac
echo 'DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer' >> $GITHUB_ENV
echo 'PLATFORM_NAME=iOS Simulator' >> $GITHUB_ENV
# Set additional environment variables for better debugging
echo 'DETOX_DISABLE_TELEMETRY=1' >> $GITHUB_ENV
echo 'DETOX_LOG_LEVEL=trace' >> $GITHUB_ENV
# Verify Xcode installation
xcodebuild -version
timeout-minutes: 10
continue-on-error: false
- name: Reset iOS Simulators
if: ${{ matrix.os == 'macos-latest' }}
id: reset-simulators
run: |
echo 'Resetting iOS Simulators...'
# Kill simulator processes
sudo killall -9 com.apple.CoreSimulator.CoreSimulatorService 2>/dev/null || true
killall 'Simulator' 2>/dev/null || true
killall 'iOS Simulator' 2>/dev/null || true
# Wait for processes to terminate
sleep 3
# Shutdown and erase all simulators (ignore failures)
xcrun simctl shutdown all 2>/dev/null || true
sleep 5
xcrun simctl erase all 2>/dev/null || true
# If erase failed, try the nuclear option
if xcrun simctl list devices | grep -q 'Booted' 2>/dev/null; then
echo 'Standard reset failed, using nuclear option...'
rm -rf ~/Library/Developer/CoreSimulator/Devices/* 2>/dev/null || true
launchctl remove com.apple.CoreSimulator.CoreSimulatorService 2>/dev/null || true
sleep 3
fi
# Clean up additional directories
rm -rf ~/Library/Developer/CoreSimulator/Caches/* 2>/dev/null || true
rm -rf ~/Library/Logs/CoreSimulator/* 2>/dev/null || true
rm -rf ~/Library/Developer/Xcode/DerivedData/* 2>/dev/null || true
echo 'Simulator reset completed'
timeout-minutes: 5
continue-on-error: true
- name: Verify Simulator Reset
if: ${{ matrix.os == 'macos-latest' && steps.reset-simulators.outcome == 'success' }}
run: |
# Verify CoreSimulator service restarted
pgrep -fl 'CoreSimulator' || (echo 'CoreSimulator service not running' && exit 1)
# Verify simulator runtime paths exist and are writable
test -d ~/Library/Developer/CoreSimulator/Devices || (echo 'Simulator devices directory missing' && exit 1)
touch ~/Library/Developer/CoreSimulator/Devices/test || (echo 'Simulator devices directory not writable' && exit 1)
rm ~/Library/Developer/CoreSimulator/Devices/test
timeout-minutes: 5
- name: Diagnose Simulator Reset Failure
if: ${{ matrix.os == 'macos-latest' && steps.reset-simulators.outcome == 'failure' }}
run: |
echo 'Simulator reset failed. Collecting diagnostic information...'
xcrun simctl list
echo 'Checking simulator logs...'
ls -la ~/Library/Logs/CoreSimulator/ || echo 'No simulator logs found'
HOMEBREW_NO_AUTO_UPDATE=1 brew tap wix/brew >/dev/null
HOMEBREW_NO_AUTO_UPDATE=1 brew install applesimutils >/dev/null
xcrun simctl shutdown all && xcrun simctl erase all
- name: Configure git metadata (needed for lerna smoke tests)
if: ${{ (matrix.os != 'macos-latest') || (matrix.os == 'macos-latest' && steps.reset-simulators.outcome == 'success') }}
run: |
git config --global user.email test@test.com
git config --global user.name 'Test Test'
git config --global user.name "Test Test"
- name: Set starting timestamp
if: ${{ (matrix.os != 'macos-latest') || (matrix.os == 'macos-latest' && steps.reset-simulators.outcome == 'success') }}
id: before-e2e
shell: bash
run: |
echo "timestamp=$(date +%s)" >> $GITHUB_OUTPUT
- name: Run e2e tests with pnpm (Linux/Windows)
id: e2e-run-pnpm
if: ${{ matrix.os != 'macos-latest' }}
run: pnpm nx run ${{ matrix.project }}:e2e-local
shell: bash
- name: Run e2e tests
id: e2e-run
run: pnpm nx run-many -t e2e,e2e-macos -p ${{ matrix.project }}
timeout-minutes: ${{ matrix.os_timeout }}
env:
GIT_AUTHOR_EMAIL: test@test.com
GIT_AUTHOR_NAME: Test
GIT_COMMITTER_EMAIL: test@test.com
GIT_COMMITTER_NAME: Test
NX_E2E_CI_CACHE_KEY: e2e-gha-${{ matrix.os }}-${{ matrix.node_version }}-${{ matrix.package_manager }}
NX_DAEMON: 'true'
NX_PERF_LOGGING: 'false'
NX_E2E_VERBOSE_LOGGING: 'true'
NX_NATIVE_LOGGING: 'false'
NX_E2E_RUN_E2E: 'true'
NX_CLOUD_NO_TIMEOUTS: 'true'
NX_E2E_SKIP_GLOBAL_CLEANUP: 'true'
NODE_OPTIONS: --max_old_space_size=8192
SELECTED_PM: ${{ matrix.package_manager }}
npm_config_registry: http://localhost:4872
YARN_REGISTRY: http://localhost:4872
CI: true
- name: Run e2e tests with npm (macOS)
id: e2e-run-npm
if: ${{ matrix.os == 'macos-latest' && steps.reset-simulators.outcome == 'success' }}
run: |
# Run the tests
if [[ '${{ matrix.project }}' == 'e2e-detox' ]] || [[ '${{ matrix.project }}' == 'e2e-react-native' ]] || [[ '${{ matrix.project }}' == 'e2e-expo' ]]; then
NX_E2E_VERBOSE_DEBUG=1 pnpm nx run ${{ matrix.project }}:e2e-macos-local
else
NX_E2E_VERBOSE_DEBUG=1 pnpm nx run ${{ matrix.project }}:e2e-local
fi
env:
NX_E2E_CI_CACHE_KEY: e2e-gha-${{ matrix.os }}-${{ matrix.node_version }}-${{ matrix.package_manager }}
NX_PERF_LOGGING: 'false'
NX_CI_EXECUTION_ENV: 'macos'
NX_E2E_VERBOSE_LOGGING: 'true'
NX_NATIVE_LOGGING: 'false'
NX_CACHE_DIRECTORY: 'tmp'
NX_E2E_SKIP_BUILD_CLEANUP: 'true'
NX_E2E_RUN_E2E: 'true'
NX_E2E_SKIP_GLOBAL_CLEANUP: 'true'
NODE_OPTIONS: --max_old_space_size=8192
SELECTED_PM: 'npm'
npm_config_registry: http://localhost:4872
YARN_REGISTRY: http://localhost:4872
DEVELOPER_DIR: '/Applications/Xcode.app/Contents/Developer'
CI: true
NX_E2E_VERBOSE_LOGGING: 'true'
NX_PERF_LOGGING: 'false'
NX_DAEMON: 'true'
- name: Save matrix config in file
if: ${{ always() }}
@@ -365,101 +428,210 @@ jobs:
before=${{ steps.before-e2e.outputs.timestamp }}
now=$(date +%s)
delta=$(($now - $before))
# Determine the outcome based on which step ran
outcome='${{ matrix.os == 'macos-latest' && steps.e2e-run-npm.outcome || steps.e2e-run-pnpm.outcome }}'
matrix=$((
echo '${{ toJSON(matrix) }}'
) | jq --argjson delta $delta -c '. + { "status": "'"$outcome"'", "duration": $delta }')
echo "$matrix" > 'outputs/matrix.json'
) | jq --argjson delta $delta -c '. + { "status": "${{ steps.e2e-run.outcome}}", "duration": $delta }')
echo "$matrix" > matrix
path=outputs/${{ matrix.os_name}}-${{ matrix.node_version}}-${{ matrix.package_manager}}-${{ matrix.project }}
echo "path=$path" >> $GITHUB_OUTPUT
echo "$matrix" > $path
- name: Upload matrix config
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: ${{ matrix.os_name}}-${{ matrix.node_version}}-${{ matrix.package_manager}}-${{ matrix.project }}
overwrite: true
if-no-files-found: 'ignore'
path: 'outputs/matrix.json'
name: outputs
path: ${{ steps.save-matrix.outputs.path }}
- name: Setup tmate session
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled && failure() }}
uses: mxschmitt/action-tmate@1fb8b1023602bf1fd0e2994d7f1e93015cb5bbec # v3.22
uses: mxschmitt/action-tmate@v3.8
timeout-minutes: 15
with:
sudo: ${{ matrix.os != 'windows-latest' }} # disable sudo for windows debugging
process-result:
if: ${{ always() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
if: ${{ always() }}
runs-on: ubuntu-latest
needs: e2e
timeout-minutes: 15
outputs:
message: ${{ steps.process-json.outputs.slack_message }}
proj_duration: ${{ steps.process-json.outputs.slack_proj_duration }}
pm_duration: ${{ steps.process-json.outputs.slack_pm_duration }}
codeowners: ${{ steps.process-json.outputs.codeowners }}
has_golden_failures: ${{ steps.process-json.outputs.has_golden_failures }}
message: ${{ steps.process-json.outputs.SLACK_MESSAGE }}
proj-duration: ${{ steps.process-json.outputs.SLACK_PROJ_DURATION }}
pm-duration: ${{ steps.process-json.outputs.SLACK_PM_DURATION }}
codeowners: ${{ steps.process-json.outputs.CODEOWNERS }}
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
filter: tree:0
- name: Prepare dir for output
run: mkdir -p outputs
- name: Load outputs
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
uses: actions/download-artifact@v3
with:
name: outputs
path: outputs
- name: Join and stringify matrix configs
id: combine-json
run: |
combined=$(jq -sc . outputs/*/matrix.json)
combined=$((jq -s . outputs/*) | jq tostring)
echo "combined=$combined" >> $GITHUB_OUTPUT
- name: Process results and collect failure details
- name: Make slack outputs
id: process-json
uses: actions/github-script@v6
env:
GH_TOKEN: ${{ github.token }}
run: |
echo '${{ steps.combine-json.outputs.combined }}' | npx tsx .github/workflows/nightly/process-result.ts
GITHUB_TOKEN: ${{ github.token }}
with:
script: |
const combined = JSON.parse(${{ steps.combine-json.outputs.combined }});
const failedProjects = combined.filter(c => c.status === 'failure').sort((a, b) => a.project.localeCompare(b.project));
// codeowners
const codeowners = new Set();
failedProjects.forEach(c => {
codeowners.add(c.codeowners);
});
core.setOutput('CODEOWNERS', Array.from(codeowners).join(','));
function trimSpace(res) {
return res.split('\n').map((l) => l.trim()).join('\n');
}
// failed message
let lastProject;
let result = `
\`\`\`
| Failed project | PM | OS | Node |
|--------------------------------|------|-------|------|`;
failedProjects.forEach(matrix => {
const project = matrix.project !== lastProject ? matrix.project : '...';
result += `\n| ${project.padEnd(30)} | ${matrix.package_manager.padEnd(4)} | ${matrix.os_name} | v${matrix.node_version.toString().padEnd(3)} |`
lastProject = matrix.project;
});
result += `\`\`\``;
core.setOutput('SLACK_MESSAGE', trimSpace(result));
function humanizeDuration(num) {
let res = '';
const hours = Math.floor(num / 3600);
if (hours) {
res += `${hours}h `;
}
const mins = Math.floor((num % 3600) / 60);
if (mins) {
res += `${mins}m `;
}
const sec = num % 60;
if (sec) {
res += `${sec}s`
}
return res;
}
// duration message
const timeReport = {};
const pmReport = {
npm: 0,
yarn: 0,
pnpm: 0
};
const macosProjects = ['e2e-detox', 'e2e-expo', 'e2e-react-native'];
combined.forEach((matrix) => {
if (matrix.os_name === 'Linux' && matrix.node_version === 18) {
pmReport[matrix.package_manager] += matrix.duration;
}
if (matrix.os_name === 'Linux' || macosProjects.includes(matrix.project)) {
if (timeReport[matrix.project]) {
if (matrix.duration > timeReport[matrix.project].max) {
timeReport[matrix.project].max = matrix.duration;
timeReport[
matrix.project
].maxEnv = `${matrix.os_name}, ${matrix.package_manager}`;
}
if (matrix.duration < timeReport[matrix.project].min) {
timeReport[matrix.project].min = matrix.duration;
timeReport[
matrix.project
].minEnv = `${matrix.os_name}, ${matrix.package_manager}`;
}
} else {
timeReport[matrix.project] = {
min: matrix.duration,
max: matrix.duration,
minEnv: `${matrix.os_name}, ${matrix.package_manager}`,
maxEnv: `${matrix.os_name}, ${matrix.package_manager}`,
};
}
}
});
// project time report
let resultPkg = `
\`\`\`
| Project | Time |
|--------------------------------|---------------------------|`;
function mapProjectTime(proj, section) {
let res = '';
res += `${humanizeDuration(timeReport[proj][section])}`;
res += ` (${timeReport[proj][section + 'Env']})`
return res;
}
function durationIcon(proj, section) {
if (timeReport[proj][section] < 12 * 60) {
return `${section} ✅`;
}
if (timeReport[proj][section] < 15 * 60) {
return `${section} ❗`;
}
return `${section} ❌`;
}
Object.keys(timeReport).forEach(proj => {
resultPkg += `\n| ${proj.padEnd(30)} | |`;
resultPkg += `\n| ${durationIcon(proj, 'min').padStart(29)} | ${mapProjectTime(proj, 'min').padEnd(25)} |`;
resultPkg += `\n| ${durationIcon(proj, 'max').padStart(29)} | ${mapProjectTime(proj, 'max').padEnd(25)} |`;
});
resultPkg += `\`\`\``;
core.setOutput('SLACK_PROJ_DURATION', trimSpace(resultPkg));
// Print project duration report inline to allow reviewing on manual runs (when no slack message will be sent)
console.log(trimSpace(resultPkg));
let resultPm = `
\`\`\`
| PM | Total time |
|------|-------------|`;
Object.keys(pmReport).forEach(pm => {
resultPm += `\n| ${pm.padEnd(4)} | ${humanizeDuration(pmReport[pm]).padEnd(11)} |`
});
resultPm += `\`\`\``;
core.setOutput('SLACK_PM_DURATION', trimSpace(resultPm));
// Print package manager duration report inline to allow reviewing on manual runs (when no slack message will be sent)
console.log(trimSpace(resultPm));
report-failure:
if: ${{ always() && needs.process-result.outputs.has_golden_failures == 'true' && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
if: ${{ failure() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
needs: process-result
runs-on: ubuntu-latest
name: Report failure
timeout-minutes: 10
steps:
- name: Send notification
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v11
uses: ravsamhq/notify-slack-action@v2
with:
status: 'failure'
message_format: '${{ needs.process-result.outputs.message }}'
notification_title: 'Golden Test Failure'
message_format: '{emoji} Workflow has {status_message} ${{ needs.process-result.outputs.message }}'
notification_title: '{workflow}'
footer: '<{run_url}|View Run> / Last commit <{commit_url}|{commit_sha}>'
mention_groups: ${{ needs.process-result.outputs.codeowners }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
report-success:
if: ${{ always() && needs.process-result.outputs.has_golden_failures == 'false' && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
needs: process-result
if: ${{ success() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
needs: e2e
runs-on: ubuntu-latest
name: Report status
timeout-minutes: 10
steps:
- name: Send notification
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v11
uses: ravsamhq/notify-slack-action@v2
with:
status: 'success'
message_format: '${{ needs.process-result.outputs.message }}'
notification_title: '✅ Golden Tests: All Passed!'
status: ${{ needs.e2e.result }}
message_format: '{emoji} Workflow has {status_message}'
notification_title: '{workflow}'
footer: '<{run_url}|View Run> / Last commit <{commit_url}|{commit_sha}>'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
@@ -468,15 +640,14 @@ jobs:
if: ${{ always() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
needs: process-result
runs-on: ubuntu-latest
timeout-minutes: 10
name: Report duration per package manager
steps:
- name: Send notification
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v11
uses: ravsamhq/notify-slack-action@v2
with:
status: 'skipped'
message_format: '${{ needs.process-result.outputs.pm_duration }}'
notification_title: 'Total duration per package manager (ubuntu only)'
message_format: '${{ needs.process-result.outputs.pm-duration }}'
notification_title: 'Total duration per package manager (ubuntu only)'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
@@ -484,14 +655,13 @@ jobs:
if: ${{ always() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
needs: process-result
runs-on: ubuntu-latest
timeout-minutes: 10
name: Report duration per project
name: Report duration per package manager
steps:
- name: Send notification
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v11
uses: ravsamhq/notify-slack-action@v2
with:
status: 'skipped'
message_format: '${{ needs.process-result.outputs.proj_duration }}'
notification_title: 'E2E Project duration stats'
message_format: '${{ needs.process-result.outputs.proj-duration }}'
notification_title: 'E2E Project duration stats'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
+421
View File
@@ -0,0 +1,421 @@
name: E2E matrix (Windows)
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
required: false
default: false
env:
CYPRESS_CACHE_FOLDER: ${{ github.workspace }}/.cypress
permissions: {}
jobs:
preinstall:
runs-on: windows-latest
strategy:
matrix:
node_version:
- 19
- 18
- 16
name: Cache install (node v${{ matrix.node_version }})
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8.3.1
run_install: false
- name: Set node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
cache: 'pnpm'
- name: Cache node_modules
id: cache-modules
uses: actions/cache@v3
with:
lookup-only: true
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ matrix.node_version }}-${{ github.run_id }}
- name: Install packages
run: pnpm install --frozen-lockfile
- name: Cache Cypress
id: cache-cypress
uses: actions/cache@v3
with:
lookup-only: true
path: '${{ github.workspace }}/.cypress'
key: windows-cypress
- name: Install Cypress
if: steps.cache-cypress.outputs.cache-hit != 'true'
run: npx cypress install
e2e:
needs: preinstall
permissions:
contents: read
runs-on: windows-latest
strategy:
matrix:
node_version:
- 19
- 18
- 16
package_manager:
- npm
project:
- e2e-angular-core
- e2e-angular-extensions
- e2e-cypress
- e2e-esbuild
- e2e-jest
- e2e-js
- e2e-lerna-smoke-tests
- e2e-linter
- e2e-next
- e2e-node
- e2e-nx-init
- e2e-nx-misc
- e2e-plugin
- e2e-nx-run
- e2e-react-core
- e2e-react-extensions
- e2e-web
- e2e-rollup
- e2e-storybook
- e2e-storybook-angular
- e2e-vite
- e2e-webpack
- e2e-workspace-create
- e2e-workspace-create-npm
include:
# codeowner groups
- project: e2e-angular-core
codeowners: 'S04SS457V38'
- project: e2e-angular-extensions
codeowners: 'S04SS457V38'
- project: e2e-cypress
codeowners: 'S04T16BTJJY'
- project: e2e-esbuild
codeowners: 'S04SJ6HHP0X'
- project: e2e-jest
codeowners: 'S04T16BTJJY'
- project: e2e-js
codeowners: 'S04SJ6HHP0X'
- project: e2e-lerna-smoke-tests
codeowners: 'S04TNCVEETS'
- project: e2e-linter
codeowners: 'S04SYJGKSCT'
- project: e2e-next
codeowners: 'S04TNCNJG5N'
- project: e2e-node
codeowners: 'S04SJ6HHP0X'
- project: e2e-nx-init
codeowners: 'S04SYHYKGNP'
- project: e2e-nx-misc
codeowners: 'S04SYHYKGNP'
- project: e2e-plugin
codeowners: 'S04SYHYKGNP'
- project: e2e-nx-run
codeowners: 'S04SYHYKGNP'
- project: e2e-react-core
codeowners: 'S04TNCNJG5N'
- project: e2e-react-extensions
codeowners: 'S04TNCNJG5N'
- project: e2e-web
codeowners: 'S04SJ6PL98X'
- project: e2e-rollup
codeowners: 'S04SJ6PL98X'
- project: e2e-storybook
codeowners: 'S04SVQ8H0G5'
- project: e2e-storybook-angular
codeowners: 'S04SVQ8H0G5'
- project: e2e-vite
codeowners: 'S04SJ6PL98X'
- project: e2e-webpack
codeowners: 'S04SJ6PL98X'
- project: e2e-workspace-create
codeowners: 'S04SYHYKGNP'
- project: e2e-workspace-create-npm
codeowners: 'S04SYHYKGNP'
exclude:
# exclude non-CNW/Lerna tests from non-LTS node versions
- node_version: 16
project: e2e-angular-core
- node_version: 16
project: e2e-angular-extensions
- node_version: 16
project: e2e-cypress
- node_version: 16
project: e2e-esbuild
- node_version: 16
project: e2e-jest
- node_version: 16
project: e2e-js
- node_version: 16
project: e2e-linter
- node_version: 16
project: e2e-next
- node_version: 16
project: e2e-node
- node_version: 16
project: e2e-nx-init
- node_version: 16
project: e2e-nx-misc
- node_version: 16
project: e2e-plugin
- node_version: 16
project: e2e-lerna-smoke-tests
- node_version: 16
project: e2e-react-core
- node_version: 16
project: e2e-react-extensions
- node_version: 16
project: e2e-web
- node_version: 16
project: e2e-rollup
- node_version: 16
project: e2e-storybook
- node_version: 16
project: e2e-storybook-angular
- node_version: 16
project: e2e-vite
- node_version: 16
project: e2e-webpack
- node_version: 19
project: e2e-angular-core
- node_version: 19
project: e2e-angular-extensions
- node_version: 19
project: e2e-cypress
- node_version: 19
project: e2e-esbuild
- node_version: 19
project: e2e-jest
- node_version: 19
project: e2e-js
- node_version: 19
project: e2e-linter
- node_version: 19
project: e2e-next
- node_version: 19
project: e2e-node
- node_version: 19
project: e2e-nx-init
- node_version: 19
project: e2e-nx-misc
- node_version: 19
project: e2e-plugin
- node_version: 19
project: e2e-lerna-smoke-tests
- node_version: 19
project: e2e-react-core
- node_version: 19
project: e2e-react-extensions
- node_version: 19
project: e2e-web
- node_version: 19
project: e2e-rollup
- node_version: 19
project: e2e-storybook
- node_version: 19
project: e2e-storybook-angular
- node_version: 19
project: e2e-vite
- node_version: 19
project: e2e-webpack
fail-fast: false
name: ${{ matrix.project }} (v${{ matrix.node_version }})
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Prepare dir for output
run: mkdir -p outputs
- uses: pnpm/action-setup@v2
name: Install pnpm
with:
version: 8.3.1
run_install: false
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
cache: 'pnpm'
- name: Cache node_modules
id: cache-modules
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ matrix.node_version }}-${{ github.run_id }}
- name: Install packages
run: pnpm install --frozen-lockfile
- name: Cache Cypress
id: cache-cypress
uses: actions/cache@v3
with:
path: '${{ github.workspace }}/.cypress'
key: ${{ runner.os }}-cypress
- name: Install Cypress
if: steps.cache-cypress.outputs.cache-hit != 'true'
run: npx cypress install
- name: Configure git metadata (needed for lerna smoke tests)
run: |
git config --global user.email test@test.com
git config --global user.name "Test Test"
- name: Run e2e tests
id: e2e-run
run: pnpm nx run ${{ matrix.project }}:e2e
shell: bash
timeout-minutes: 120
env:
GIT_AUTHOR_EMAIL: test@test.com
GIT_AUTHOR_NAME: Test
GIT_COMMITTER_EMAIL: test@test.com
GIT_COMMITTER_NAME: Test
NX_E2E_CI_CACHE_KEY: e2e-gha-windows-${{ matrix.node_version }}-${{ matrix.package_manager }}
NODE_OPTIONS: --max_old_space_size=8192
SELECTED_PM: ${{ matrix.package_manager }}
npm_config_registry: http://localhost:4872
NX_CACHE_DIRECTORY: 'tmp'
NX_E2E_SKIP_BUILD_CLEANUP: 'true'
NX_E2E_RUN_E2E: 'true'
NX_E2E_VERBOSE_LOGGING: 'true'
NX_PERF_LOGGING: 'false'
NX_DAEMON: 'true'
- name: Save matrix config in file
if: ${{ always() }}
id: save-matrix
shell: bash
run: |
matrix=$((
echo '${{ toJSON(matrix) }}'
) | jq -c '. + { "status": "${{ steps.e2e-run.outcome}}" }')
echo "$matrix" > matrix
path=outputs/windows-${{ matrix.node_version}}-${{ matrix.package_manager}}-${{ matrix.project }}
echo "path=$path" >> $GITHUB_OUTPUT
echo "$matrix" > $path
- name: Upload matrix config
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: outputs
path: ${{ steps.save-matrix.outputs.path }}
- name: Setup tmate session
if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled && failure() }}
uses: mxschmitt/action-tmate@v3.8
timeout-minutes: 15
with:
sudo: false # disable sudo for windows debugging
process-result:
if: ${{ always() }}
runs-on: ubuntu-latest
needs: e2e
outputs:
message: ${{ steps.process-json.outputs.SLACK_MESSAGE }}
codeowners: ${{ steps.process-json.outputs.CODEOWNERS }}
steps:
- name: Load outputs
uses: actions/download-artifact@v3
with:
name: outputs
path: outputs
- name: Join and stringify matrix configs
id: combine-json
shell: bash
run: |
combined=$((jq -s . outputs/*) | jq tostring)
echo "combined=$combined" >> $GITHUB_OUTPUT
- name: Make slack outputs
id: process-json
uses: actions/github-script@v6
env:
GITHUB_TOKEN: ${{ github.token }}
with:
script: |
const combined = JSON.parse(${{ steps.combine-json.outputs.combined }});
const failedProjects = combined.filter(c => c.status === 'failure').sort((a, b) => a.project.localeCompare(b.project));
// codeowners
const codeowners = new Set();
failedProjects.forEach(c => {
codeowners.add(c.codeowners);
});
core.setOutput('CODEOWNERS', Array.from(codeowners).join(','));
// message
let result = `
*OS* Windows
*Package manager* npm
\`\`\`
| Failed project | Node |
|--------------------------------|------|`;
failedProjects.forEach(matrix => {
result += `\n| ${matrix.project.padEnd(30)} | v${matrix.node_version.toString().padEnd(3)} |`
});
result += `\`\`\``;
const message = result.split('\n').map(l => l.trim()).join('\n');
core.setOutput('SLACK_MESSAGE', message);
report-failure:
if: ${{ failure() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
needs: process-result
runs-on: ubuntu-latest
name: Report failure
steps:
- name: Send notification
uses: ravsamhq/notify-slack-action@v2
with:
status: 'failure'
message_format: '{emoji} Workflow has {status_message} ${{ needs.process-result.outputs.message }}'
notification_title: '{workflow}'
footer: '<{run_url}|View Run> / Last commit <{commit_url}|{commit_sha}>'
mention_groups: ${{ needs.process-result.outputs.codeowners }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
report-success:
if: ${{ success() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
needs: e2e
runs-on: ubuntu-latest
name: Report success
steps:
- name: Send notification
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ needs.e2e.result }}
message_format: '{emoji} Workflow has {status_message}'
notification_title: '{workflow}'
footer: '<{run_url}|View Run> / Last commit <{commit_url}|{commit_sha}>'
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
+11 -15
View File
@@ -3,30 +3,29 @@ name: Generate embeddings
on:
schedule:
- cron: "0 5 * * 0,4" # sunday, thursday 5AM
workflow_dispatch:
jobs:
cache-and-install:
if: github.repository == 'nrwl/nx'
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['24']
node-version: [18]
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
uses: actions/setup-node@v3
with:
node-version: '24'
package-manager-cache: false
node-version: 18
- name: Install pnpm
uses: pnpm/action-setup@7088e561eb65bb68695d245aa206f005ef30921d # v4.1.0
uses: pnpm/action-setup@v2
id: pnpm-install
with:
version: 10.28.2
version: 7
run_install: false
- name: Get pnpm store directory
@@ -36,7 +35,7 @@ jobs:
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
@@ -46,12 +45,9 @@ jobs:
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- name: Build docs
run: npx nx build astro-docs
- name: Run embeddings script
run: node --import tsx tools/documentation/create-embeddings/src/main.mts --mode=astro
run: pnpm exec nx run tools-documentation-create-embeddings:run-node
env:
NX_NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NX_NEXT_PUBLIC_SUPABASE_URL }}
NX_SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.NX_SUPABASE_SERVICE_ROLE_KEY }}
NX_OPENAI_KEY: ${{ secrets.NX_OPENAI_KEY }}
NX_OPENAI_KEY: ${{ secrets.NX_OPENAI_KEY }}
+13 -13
View File
@@ -16,21 +16,21 @@ jobs:
name: Report status
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@v3
- uses: pnpm/action-setup@7088e561eb65bb68695d245aa206f005ef30921d # v4.1.0
- uses: pnpm/action-setup@v2
with:
version: 10.28.2
version: 8.2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
uses: actions/setup-node@v3
with:
node-version: '24'
node-version: '18'
cache: 'pnpm'
- name: Cache node_modules
id: cache-modules
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
uses: actions/cache@v3
with:
lookup-only: true
path: '**/node_modules'
@@ -41,29 +41,29 @@ jobs:
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e # v2 # Needed since we are downloading artifact from a different workflow run, official actions/download-artifact doesn't support this.
uses: dawidd6/action-download-artifact@v2 # Needed since we are downloading artifact from a different workflow run, official actions/download-artifact doesn't support this.
with:
name: cached-issue-data
path: ${{ github.workspace }}/scripts/issues-scraper/cached
search_artifacts: true
allow_forks: false
continue-on-error: true
- name: Collect Issue Data
id: collect
run: npx tsx ./scripts/issues-scraper/index.ts
run: npx ts-node ./scripts/issues-scraper/index.ts
env:
GITHUB_TOKEN: ${{ github.token }}
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
- uses: actions/upload-artifact@v3
with:
name: cached-issue-data
path: ./scripts/issues-scraper/cached/data.json
- name: Send GitHub Action trigger data to Slack workflow
id: slack
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a # v2.1.1
uses: slackapi/slack-github-action@v1.23.0
with:
webhook: ${{ secrets.SLACK_ISSUES_REPORT_URL }}
webhook-type: incoming-webhook
payload: ${{ steps.collect.outputs.SLACK_MESSAGE }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_ISSUES_REPORT_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
+1 -2
View File
@@ -17,10 +17,9 @@ jobs:
if: ${{ github.repository_owner == 'nrwl' }}
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@6548363a2d763e3a4a3a0dc04ca4a10481d8e536 # v6.0.0
- uses: dessant/lock-threads@v4
id: lockthreads
with:
process-only: 'issues, prs'
github-token: ${{ github.token }}
issue-inactive-days: "30" # Lock issues after 30 days of being closed
pr-inactive-days: "5" # Lock closed PRs after 5 days. This ensures that issues that stem from a PR are opened as issues, rather than comments on the recently merged PR.
@@ -1,674 +0,0 @@
import { exec } from 'child_process';
import { execSync } from 'child_process';
const MAX_CONCURRENCY = 8;
interface MatrixResult {
project: string;
codeowners: string;
node_version: number | string;
package_manager: string;
os: string;
os_name: string;
os_timeout: number;
is_golden?: boolean;
status: 'success' | 'failure' | 'cancelled';
duration: number;
}
interface Streak {
consecutive_failures: number;
failing_since: string | null;
last_passing: string | null;
}
interface HistoryEntry {
date: string;
failed: string[];
}
interface ErrorDate {
testFile: string;
startDate: string;
days: number;
}
const REPO = process.env.GITHUB_REPOSITORY || 'nrwl/nx';
const RUN_ID = process.env.GITHUB_RUN_ID || '0';
function gh(args: string): string {
try {
return execSync(`gh ${args}`, {
encoding: 'utf-8',
timeout: 60_000,
maxBuffer: 10 * 1024 * 1024,
stdio: ['pipe', 'pipe', 'pipe'],
}).trim();
} catch {
return '';
}
}
function ghAsync(args: string): Promise<string> {
return new Promise((resolve) => {
exec(
`gh ${args}`,
{ encoding: 'utf-8', timeout: 60_000, maxBuffer: 10 * 1024 * 1024 },
(err, stdout) => resolve(err ? '' : (stdout || '').trim())
);
});
}
async function ghParallel<T>(
items: T[],
fn: (item: T) => string,
concurrency = MAX_CONCURRENCY
): Promise<Map<T, string>> {
const results = new Map<T, string>();
const queue = [...items];
async function worker() {
while (queue.length > 0) {
const item = queue.shift()!;
results.set(item, await ghAsync(fn(item)));
}
}
await Promise.all(
Array.from({ length: Math.min(concurrency, items.length) }, () => worker())
);
return results;
}
function extractJestBlocks(raw: string): string {
const lines = raw
.replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z /gm, '')
.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '')
.split('\n');
const blocks: string[] = [];
let capturing = false;
for (const line of lines) {
if (line.startsWith(' FAIL ')) capturing = true;
if (capturing) blocks.push(line);
if (line.startsWith('Ran all test suites')) capturing = false;
}
return blocks.slice(0, 50).join('\n');
}
function extractTestFiles(block: string): string[] {
const matches = block.match(/FAIL\s+\S+\s+(src\/[^\s]+\.test\.ts)/g) || [];
return [...new Set(matches.map((m) => m.replace(/FAIL\s+\S+\s+/, '')))];
}
// Extract a normalized error signature for a test file from a Jest block.
// Used to distinguish different root causes for the same test file across runs.
function extractErrorSignature(block: string, testFile: string): string {
const lines = block.split('\n');
let afterBullet = false;
let inFile = false;
for (const l of lines) {
if (l.includes('FAIL') && l.includes(testFile)) { inFile = true; continue; }
if (inFile && /●/.test(l)) { afterBullet = true; continue; }
if (!inFile || !afterBullet) continue;
const trimmed = l.trim();
if (!trimmed) continue;
// Skip generic "Command failed" and warnings — find the actual error
if (/^Command failed:|^warning /i.test(trimmed)) continue;
// Normalize dynamic parts
return trimmed
.replace(/\/tmp\/[^\s]+/g, '<tmpdir>')
.replace(/\/Users\/[^\s]+/g, '<path>')
.replace(/\/home\/[^\s]+/g, '<path>')
.replace(/[a-z]+\d{5,}/gi, '<id>')
.replace(/\d{4}-\d{2}-\d{2}T[\d:._Z-]+/g, '<ts>')
.replace(/\d+\.\d+\.\d+/g, '<ver>')
.trim();
}
return '';
}
// Extract signatures for all test files in a block
function extractSignatures(
block: string,
testFiles: string[]
): Map<string, string> {
const sigs = new Map<string, string>();
for (const tf of testFiles) {
sigs.set(tf, extractErrorSignature(block, tf));
}
return sigs;
}
function extractBlockForFile(fullBlock: string, testFile: string): string {
const lines = fullBlock.split('\n');
const result: string[] = [];
let capturing = false;
for (const line of lines) {
if (line.includes('FAIL') && line.includes(testFile)) capturing = true;
else if (capturing && line.match(/^ FAIL /)) capturing = false;
if (capturing) result.push(line);
}
return result.slice(0, 20).join('\n');
}
export interface JobLink {
combo: string;
url: string;
}
export interface FailureDetailsResult {
report: string;
goldenJobLinks: Map<string, JobLink[]>; // project -> [{combo, url}]
}
/**
* Collects detailed failure information for golden projects.
* Called by process-result.ts when golden failures exist.
* Returns Slack mrkdwn report + job links for the summary section.
*/
export async function collectFailureDetails(
combined: MatrixResult[],
failedGoldenProjectNames: string[]
): Promise<FailureDetailsResult> {
const projectNames = failedGoldenProjectNames;
if (projectNames.length === 0) {
return { report: '', goldenJobLinks: new Map() };
}
// Group failures by project for combo info
const failuresByProject = new Map<string, MatrixResult[]>();
for (const r of combined) {
if (r.is_golden && (r.status === 'failure' || r.status === 'cancelled')) {
if (!failuresByProject.has(r.project))
failuresByProject.set(r.project, []);
failuresByProject.get(r.project)!.push(r);
}
}
// Step 1: 30-day failure history
const histRunsRaw = gh(
`run list --workflow=e2e-matrix.yml --repo ${REPO} --limit 40 --json databaseId,createdAt,event --jq '[.[] | select(.event == "schedule" and .databaseId != ${RUN_ID})] | .[0:30]'`
);
const histRuns: Array<{ databaseId: number; createdAt: string }> =
histRunsRaw ? JSON.parse(histRunsRaw) : [];
const histResults = await ghParallel(
histRuns.map((r) => r.databaseId),
(rid) =>
`run view ${rid} --repo ${REPO} --json jobs --jq '[.jobs[] | select(.conclusion == "failure") | .name | split(" ") | last] | unique'`
);
const history: HistoryEntry[] = histRuns.map((run) => {
const raw = histResults.get(run.databaseId) || '[]';
try {
return { date: run.createdAt, failed: JSON.parse(raw) };
} catch {
return { date: run.createdAt, failed: [] };
}
});
// Compute streaks
const streaks = new Map<string, Streak>();
for (const project of projectNames) {
let streak = 0,
firstSeen: string | null = null,
lastPassing: string | null = null,
broken = false;
for (const entry of history) {
if (broken) break;
if (entry.failed.includes(project)) {
streak++;
firstSeen = entry.date;
} else {
broken = true;
lastPassing = entry.date;
}
}
streaks.set(project, {
consecutive_failures: streak,
failing_since: firstSeen ? firstSeen.split('T')[0] : null,
last_passing: lastPassing ? lastPassing.split('T')[0] : null,
});
}
// Step 2: Fetch failure logs (one per OS/PM combo per project)
const failedJobsRaw = gh(
`run view ${RUN_ID} --repo ${REPO} --json jobs --jq '[.jobs[] | select(.conclusion == "failure") | {id: .databaseId, name: .name, project: (.name | split(" ") | last), combo: (.name | split(" ")[0])}]'`
);
const failedJobs: Array<{
id: number;
name: string;
project: string;
combo: string;
}> = failedJobsRaw ? JSON.parse(failedJobsRaw) : [];
const jobsToFetch: Array<{ id: number; project: string }> = [];
for (const project of projectNames) {
const seen = new Set<string>();
for (const job of failedJobs.filter((j) => j.project === project)) {
const key = job.combo.split('/').slice(0, 2).join('/');
if (!seen.has(key)) {
seen.add(key);
jobsToFetch.push({ id: job.id, project: job.project });
}
}
}
const logResults = await ghParallel(
jobsToFetch,
(job) => `api repos/${REPO}/actions/jobs/${job.id}/logs`
);
// Keep per-combo logs separate AND a merged block per project
interface ComboLog {
combo: string;
block: string;
testFiles: string[];
signatures: Map<string, string>; // testFile -> error signature
}
const projectComboLogs = new Map<string, ComboLog[]>();
const projectLogs = new Map<string, string>(); // merged block for backwards compat
for (const [job, raw] of logResults) {
if (!raw) continue;
const cleaned = raw
.replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z /gm, '')
.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
const block = extractJestBlocks(raw);
const testFiles = extractTestFiles(cleaned);
const sigs = extractSignatures(cleaned, testFiles);
const combo =
failedJobs.find((j) => j.id === job.id)?.combo || 'unknown';
if (!projectComboLogs.has(job.project))
projectComboLogs.set(job.project, []);
projectComboLogs.get(job.project)!.push({
combo,
block,
testFiles,
signatures: sigs,
});
projectLogs.set(
job.project,
(projectLogs.get(job.project) || '') + '\n' + block
);
}
// Step 3: Build distinct failures per project — each (testFile, signature, combos) is a "failure"
interface DistinctFailure {
testFile: string;
signature: string;
combos: string[];
block: string; // the Jest block from the first combo that has this signature
}
const projectDistinctFailures = new Map<string, DistinctFailure[]>();
for (const project of projectNames) {
const comboLogs = projectComboLogs.get(project) || [];
const seen = new Map<string, DistinctFailure>(); // "testFile|signature" -> failure
for (const cl of comboLogs) {
for (const tf of cl.testFiles) {
const sig = cl.signatures.get(tf) || '';
const key = `${tf}|${sig}`;
if (seen.has(key)) {
seen.get(key)!.combos.push(cl.combo);
} else {
seen.set(key, {
testFile: tf,
signature: sig,
combos: [cl.combo],
block: extractBlockForFile(cl.block, tf),
});
}
}
}
projectDistinctFailures.set(project, [...seen.values()]);
}
// Step 3b: Validate each distinct failure against the first-failing run
interface FailureValidation {
status: 'new' | 'confirmed' | 'different' | 'unknown';
startDate?: string;
days?: number;
}
// Key: "project|testFile|signature"
const failureValidations = new Map<string, FailureValidation>();
for (const project of projectNames) {
const streak = streaks.get(project)!;
const failures = projectDistinctFailures.get(project) || [];
if (streak.consecutive_failures <= 1 || !streak.failing_since) {
for (const f of failures) {
failureValidations.set(`${project}|${f.testFile}|${f.signature}`, {
status: 'new',
startDate: streak.failing_since || undefined,
days: streak.consecutive_failures || 1,
});
}
continue;
}
// Fetch first-failing run's signatures across all combos
const firstRun = histRuns.find(
(r) => r.createdAt.split('T')[0] === streak.failing_since
);
if (!firstRun) {
for (const f of failures) {
failureValidations.set(`${project}|${f.testFile}|${f.signature}`, {
status: 'unknown',
});
}
continue;
}
const firstJobIdsRaw = gh(
`run view ${firstRun.databaseId} --repo ${REPO} --json jobs --jq '[.jobs[] | select(.conclusion == "failure" and (.name | split(" ") | last) == "${project}")] | group_by(.name | split("/")[0:2] | join("/")) | map(.[0].databaseId) | .[]'`
);
const firstJobIds = firstJobIdsRaw
.split('\n')
.filter((id) => id && id !== 'null');
// Collect ALL signatures from the first run
const firstRunSigs = new Set<string>(); // "testFile|signature"
for (const jobId of firstJobIds) {
const log = gh(`api repos/${REPO}/actions/jobs/${jobId}/logs`);
if (!log) continue;
const cleanedLog = log
.replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z /gm, '')
.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
const files = extractTestFiles(cleanedLog);
for (const f of files) {
const sig = extractErrorSignature(cleanedLog, f);
firstRunSigs.add(`${f}|${sig}`);
}
}
// Validate each current failure
for (const f of failures) {
const key = `${f.testFile}|${f.signature}`;
const fullKey = `${project}|${key}`;
if (firstRunSigs.has(key)) {
failureValidations.set(fullKey, {
status: 'confirmed',
startDate: streak.failing_since!,
days: streak.consecutive_failures,
});
} else {
failureValidations.set(fullKey, {
status: 'different',
});
}
}
}
// Step 4: Binary search for start date of each "different" failure
for (const project of projectNames) {
const streak = streaks.get(project)!;
const failures = projectDistinctFailures.get(project) || [];
const different = failures.filter((f) => {
const v = failureValidations.get(
`${project}|${f.testFile}|${f.signature}`
);
return v?.status === 'different';
});
if (!different.length) continue;
const projRunIds = histRuns
.slice(0, streak.consecutive_failures)
.map((r) => r.databaseId);
if (projRunIds.length <= 1) continue;
for (const failure of different) {
const targetSig = failure.signature;
if (!targetSig) continue;
function runHasSignature(runId: number): boolean {
const jobIdsRaw = gh(
`run view ${runId} --repo ${REPO} --json jobs --jq '[.jobs[] | select(.conclusion == "failure" and (.name | split(" ") | last) == "${project}")] | group_by(.name | split("/")[0:2] | join("/")) | map(.[0].databaseId) | .[]'`
);
for (const jid of jobIdsRaw.split('\n').filter(Boolean)) {
const log = gh(`api repos/${REPO}/actions/jobs/${jid}/logs`);
if (!log) continue;
const cleaned = log
.replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z /gm, '')
.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
const sig = extractErrorSignature(cleaned, failure.testFile);
if (sig === targetSig) return true;
}
return false;
}
let low = 0,
high = projRunIds.length - 1;
// Check oldest run
const fullKey = `${project}|${failure.testFile}|${failure.signature}`;
const oldestHas = runHasSignature(projRunIds[high]);
if (oldestHas) {
const run = histRuns.find((r) => r.databaseId === projRunIds[high]);
failureValidations.set(fullKey, {
status: 'different',
startDate: run?.createdAt.split('T')[0] || 'unknown',
days: projRunIds.length,
});
continue;
}
// Binary search
while (high - low > 1) {
const mid = Math.floor((low + high) / 2);
if (runHasSignature(projRunIds[mid])) low = mid;
else high = mid;
}
const foundRun = histRuns.find((r) => r.databaseId === projRunIds[low]);
failureValidations.set(fullKey, {
status: 'different',
startDate: foundRun?.createdAt.split('T')[0] || 'unknown',
days: low + 1,
});
}
}
// Step 5: Recent commits
let commitCount = 0;
if (histRuns[0]?.createdAt) {
try {
const commits = execSync(
`git log origin/master --after="${histRuns[0].createdAt}" --format="%h" --no-merges 2>/dev/null | head -30`,
{ encoding: 'utf-8', timeout: 10_000 }
).trim();
commitCount = commits ? commits.split('\n').length : 0;
} catch {
/* git not available */
}
}
// Step 6: Format report
const lines: string[] = ['', '🔍 *Failure Details*', ''];
const sorted = [...projectNames].sort((a, b) => {
const sa = streaks.get(a)?.consecutive_failures || 0;
const sb = streaks.get(b)?.consecutive_failures || 0;
return (
sa - sb ||
(failuresByProject.get(b)?.length || 0) -
(failuresByProject.get(a)?.length || 0)
);
});
for (const project of sorted) {
const streak = streaks.get(project)!;
const projResults = failuresByProject.get(project) || [];
const distinctFailures = projectDistinctFailures.get(project) || [];
const block = projectLogs.get(project) || '';
const pms = [...new Set(projResults.map((r) => r.package_manager))];
const pattern =
pms.length === 1
? `${pms[0]}-only`
: pms.length >= 3
? 'all PMs'
: pms.join('+');
const since = streak.failing_since || 'today (new)';
const lastPass = streak.last_passing || '—';
const uniqueCombos = [
...new Set(
failedJobs.filter((j) => j.project === project).map((j) => j.combo)
),
];
lines.push('———————————————————————————');
lines.push(`*${project}* — ${projResults.length} combos (${pattern})`);
lines.push(
`Project failing since ${since} | Last fully passing: ${lastPass}`
);
lines.push('');
if (distinctFailures.length > 0) {
for (const failure of distinctFailures) {
const fullKey = `${project}|${failure.testFile}|${failure.signature}`;
const val = failureValidations.get(fullKey);
let errorDate = since;
let errorDays: number | string = streak.consecutive_failures || 1;
let label = '';
if (val?.startDate) {
errorDate = val.startDate;
errorDays = val.days || 1;
}
if (val?.status === 'different') {
label = ' ⚠️ error changed mid-streak';
}
if (errorDays === 1 || errorDays === '1') {
label = ' 🆕 NEW';
}
const comboStr = failure.combos.join(', ');
lines.push(
`📋 \`${failure.testFile}\` (${comboStr}) — failing since ${errorDate} (${errorDays} ${errorDays === 1 || errorDays === '1' ? 'day' : 'days'})${label}`
);
if (failure.block) {
lines.push('```');
lines.push(failure.block);
lines.push('```');
}
}
const summaryMatch = block.match(/^Test Suites:.*$/m);
if (summaryMatch) lines.push(`_${summaryMatch[0]}_`);
} else {
// No Jest blocks — find which step failed and extract its error output
const firstJob = failedJobs.find((j) => j.project === project);
if (firstJob) {
// Get the failed step name from the jobs API
const stepsRaw = gh(
`run view ${RUN_ID} --repo ${REPO} --json jobs --jq '[.jobs[] | select(.databaseId == ${firstJob.id})][0].steps[] | select(.conclusion == "failure") | .name'`
);
const failedStep = stepsRaw || 'unknown step';
// Get the log and extract error lines
const raw = gh(`api repos/${REPO}/actions/jobs/${firstJob.id}/logs`);
const cleaned = raw
.split('\n')
.map((l) => l.replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z /, ''))
.map((l) => l.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, ''));
// Extract the failed Nx task output block (❌ > nx run <task> ... until next ##[group] or NX summary)
const failedTaskBlock: string[] = [];
let capturingTask = false;
for (const l of cleaned) {
if (/❌.*> nx run /i.test(l)) {
capturingTask = true;
failedTaskBlock.push(l);
continue;
}
if (capturingTask) {
if (/^##\[group\]|NX.*Running target/i.test(l) || failedTaskBlock.length >= 15) {
capturingTask = false;
} else {
failedTaskBlock.push(l);
}
}
}
// Extract the Nx failure summary block ("Running target...failed" + "Failed tasks:" + task list)
const nxFailureBlock: string[] = [];
let capturingNx = false;
for (const l of cleaned) {
if (/NX.*Running target.*failed/i.test(l)) capturingNx = true;
if (capturingNx) {
nxFailureBlock.push(l);
if (/^Hint:/i.test(l.trim()) || nxFailureBlock.length >= 10) {
capturingNx = false;
}
}
}
// Fallback: if no Nx blocks or task blocks found, extract generic error lines
let fallbackErrors: string[] = [];
if (nxFailureBlock.length === 0 && failedTaskBlock.length === 0) {
fallbackErrors = cleaned.filter((l) => {
const t = l.trim();
if (t.length < 10) return false;
if (/warning|warn\b|deprecated|orphan|Node\.js 20|FORCE_JAVASCRIPT|\* \[new branch\]|\* \[new tag\]/i.test(t)) return false;
return (
/error TS\d+:|^Error:|^\s*error\b[:\s]|ERR!|ERESOLVE|##\[error\]/i.test(t) ||
/Cannot find module|ENOENT|EACCES|permission denied/i.test(t) ||
/Segmentation fault|killed|OOM|out of memory/i.test(t) ||
/command not found|No such file or directory/i.test(t) ||
/Process completed with exit code [^0]/i.test(t)
);
}).slice(0, 5);
}
// Combine: Nx summary first, then task output, then fallback errors
const relevantErrors = [
...nxFailureBlock,
...(failedTaskBlock.length > 0 ? ['', ...failedTaskBlock] : []),
...(fallbackErrors.length > 0 ? ['', ...fallbackErrors] : []),
];
lines.push(`⚠️ Tests did not run — failed at step: *${failedStep}*`);
if (relevantErrors.length > 0) {
lines.push('```');
lines.push(relevantErrors.join('\n'));
lines.push('```');
}
lines.push(`Failing combos: ${uniqueCombos.join(', ')}`);
} else {
lines.push('⏱️ No job data available');
}
}
lines.push('');
}
if (commitCount > 0) {
lines.push(`_${commitCount} commits since last nightly_`);
}
// Build job links for the summary section
const runUrl = `https://github.com/${REPO}/actions/runs/${RUN_ID}`;
const goldenJobLinks = new Map<string, JobLink[]>();
for (const project of projectNames) {
const projectJobs = failedJobs.filter((j) => j.project === project);
goldenJobLinks.set(
project,
projectJobs.map((j) => ({
combo: j.combo,
url: `${runUrl}/job/${j.id}`,
}))
);
}
return { report: lines.join('\n'), goldenJobLinks };
}
-140
View File
@@ -1,140 +0,0 @@
type MatrixDataProject = {
name: string,
codeowners: string,
is_golden?: boolean, // true if this is a golden project, false otherwise
};
type MatrixDataOS = {
os: string, // GH runner machine name: e.g. ubuntu-latest
os_name: string, // short name that will be printed in the report and on the action
os_timeout: number, // 60
package_managers: string[], // package managers to run on this OS
node_versions: Array<number | string>, // node versions to run on this OS
excluded?: string[], // projects to exclude from running on this OS
};
type MatrixData = {
coreProjects: MatrixDataProject[],
projects: MatrixDataProject[],
lowestNodeLTS: number,
setup: MatrixDataOS[],
}
export type MatrixItem = {
project: string,
codeowners: string,
node_version: number | string,
package_manager: string,
os: string,
os_name: string,
os_timeout: number,
is_golden?: boolean,
};
// TODO: Extract Slack groups into named groups for easier maintenance
const matrixData: MatrixData = {
coreProjects: [
{ name: 'e2e-lerna-smoke-tests', codeowners: 'S04TNCVEETS', is_golden: true },
{ name: 'e2e-js', codeowners: 'S04SJ6HHP0X', is_golden: true },
{ name: 'e2e-nx-init', codeowners: 'S04SYHYKGNP', is_golden: true },
{ name: 'e2e-nx', codeowners: 'S04SYHYKGNP' },
{ name: 'e2e-release', codeowners: 'S04SYHYKGNP' },
{ name: 'e2e-workspace-create', codeowners: 'S04SYHYKGNP' }
],
projects: [
{ name: 'e2e-cypress', codeowners: 'S04T16BTJJY', is_golden: true },
{ name: 'e2e-docker', codeowners: 'S04SJ6HHP0X', is_golden: true },
{ name: 'e2e-detox', codeowners: 'S04TNCNJG5N', is_golden: true },
{ name: 'e2e-esbuild', codeowners: 'S04SJ6HHP0X', is_golden: true },
{ name: 'e2e-gradle', codeowners: 'S04TNCNJG5N', is_golden: true },
{ name: 'e2e-eslint', codeowners: 'S04SYJGKSCT', is_golden: true },
{ name: 'e2e-node', codeowners: 'S04SJ6HHP0X', is_golden: true },
{ name: 'e2e-playwright', codeowners: 'S04SVQ8H0G5', is_golden: true },
{ name: 'e2e-remix', codeowners: 'S04SVQ8H0G5', is_golden: true },
{ name: 'e2e-rspack', codeowners: 'S04SJ6HHP0X', is_golden: true },
{ name: 'e2e-vite', codeowners: 'S04SJ6PL98X', is_golden: true },
{ name: 'e2e-vue', codeowners: 'S04SJ6PL98X', is_golden: true },
{ name: 'e2e-web', codeowners: 'S04SJ6PL98X', is_golden: true },
{ name: 'e2e-webpack', codeowners: 'S04SJ6PL98X', is_golden: true },
{ name: 'e2e-jest', codeowners: 'S04T16BTJJY', is_golden: true },
{ name: 'e2e-expo', codeowners: 'S04TNCNJG5N', is_golden: true },
{ name: 'e2e-react-native', codeowners: 'S04TNCNJG5N', is_golden: true },
{ name: 'e2e-angular', codeowners: 'S04SS457V38' },
{ name: 'e2e-next', codeowners: 'S04TNCNJG5N' },
{ name: 'e2e-plugin', codeowners: 'S04SYHYKGNP' },
{ name: 'e2e-react', codeowners: 'S04TNCNJG5N' },
{ name: 'e2e-rollup', codeowners: 'S04SJ6PL98X' },
{ name: 'e2e-storybook', codeowners: 'S04SVQ8H0G5' },
{ name: 'e2e-nuxt', codeowners: 'S04SJ6PL98X' }
],
// Non-core plugins only run on the lowest LTS. Plugin-level changes are
// less Node-version-sensitive than core, so single-version coverage is enough.
lowestNodeLTS: 22,
setup: [
{
os: 'ubuntu-latest',
os_name: 'Linux',
os_timeout: 60,
package_managers: ['npm', 'pnpm', 'yarn'],
// TODO: re-add '26.0.0' once playwright ships the yauzl fix for node 26 extract hang.
// See https://github.com/microsoft/playwright/issues/40724
node_versions: ['22.13.0', '24.0.0'],
excluded: ['e2e-detox', 'e2e-react-native', 'e2e-expo']
},
// Docker is not supported on ARM-based macOS runners (no nested virtualization)
// See: https://github.com/docker/setup-docker-action and https://github.com/douglascamata/setup-docker-macos-action
// We may want to look into adding intel only for this docker case, at least until vm-in-vm works on latest macos
// TODO: re-add '26.0.0' once playwright ships the yauzl fix for node 26 extract hang.
// See https://github.com/microsoft/playwright/issues/40724
{ os: 'macos-latest', os_name: 'MacOS', os_timeout: 90, package_managers: ['npm'], node_versions: ['24.0.0'], excluded: ['e2e-docker'] }
// TODO (Jack): Fix Windows support as gradle fails when running nx build https://staging.nx.app/runs/LgD4vxGn8w?utm_source=pull-request&utm_medium=comment
// { os: 'windows-latest', os_name: 'WinOS', os_timeout: 180, package_managers: ['npm'], node_versions: ['24.0.0'], excluded: ['e2e-detox', 'e2e-react-native', 'e2e-expo'] }
]
};
const matrix: Array<MatrixItem> = [];
function addMatrixCombo(project: MatrixDataProject, nodeVersion: number | string, pm: number, os: number) {
matrix.push({
project: project.name,
codeowners: project.codeowners,
node_version: nodeVersion,
package_manager: matrixData.setup[os].package_managers[pm],
os: matrixData.setup[os].os,
os_name: matrixData.setup[os].os_name,
os_timeout: matrixData.setup[os].os_timeout,
is_golden: !!project.is_golden // Mark golden projects as true, others as false
});
}
function processProject(project: MatrixDataProject, nodeVersion?: number) {
for (let os = 0; os < matrixData.setup.length; os++) {
for (let pm = 0; pm < matrixData.setup[os].package_managers.length; pm++) {
if (!matrixData.setup[os].excluded || !matrixData.setup[os].excluded?.includes(project.name)) {
if (nodeVersion) {
addMatrixCombo(project, nodeVersion, pm, os);
} else {
for (let n = 0; n < matrixData.setup[os].node_versions.length; n++) {
addMatrixCombo(project, matrixData.setup[os].node_versions[n], pm, os);
}
}
}
}
}
}
// process core projects
for (let p = 0; p < matrixData.coreProjects.length; p++) {
processProject(matrixData.coreProjects[p]);
}
// process other projects
for (let p = 0; p < matrixData.projects.length; p++) {
processProject(matrixData.projects[p], matrixData.lowestNodeLTS);
}
if (matrix.length > 256) {
throw new Error('You have exceeded the size of the matrix. GitHub allows only 256 jobs in a matrix. Found ${matrix.length} jobs.');
}
// print result to stdout for pipeline to consume
process.stdout.write(JSON.stringify({ include: matrix }, null, 0));
-229
View File
@@ -1,229 +0,0 @@
import * as fs from 'fs';
import { MatrixItem } from './process-matrix';
import { collectFailureDetails, JobLink } from './analyze-failures';
interface MatrixResult extends MatrixItem {
status: 'success' | 'failure' | 'cancelled';
duration: number;
}
interface ProcessedResults {
codeowners: string;
slack_message: string;
slack_proj_duration: string;
slack_pm_duration: string;
has_golden_failures: string;
}
function trimSpace(res: string): string {
return res.split('\n').map((l) => l.trim()).join('\n');
}
function humanizeDuration(num: number): string {
let res = '';
const hours = Math.floor(num / 3600);
if (hours) res += `${hours}h `;
const mins = Math.floor((num % 3600) / 60);
if (mins) res += `${mins}m `;
const sec = num % 60;
if (sec) res += `${sec}s`;
return res;
}
function processResults(combined: MatrixResult[]): ProcessedResults {
const failedProjects = combined.filter(c => c.status === 'failure' || c.status === 'cancelled').sort((a, b) => a.project.localeCompare(b.project));
const failedGoldenProjects = failedProjects.filter(c => c.is_golden);
const hasGoldenFailures = failedGoldenProjects.length > 0;
const codeowners = new Set<string>();
failedGoldenProjects.forEach(c => codeowners.add(c.codeowners));
let result = '';
const allGoldenProjects = combined.filter(c => c.is_golden);
const uniqueGoldenProjects = new Set(allGoldenProjects.map(c => c.project));
const uniqueFailedGoldenProjects = new Set(failedGoldenProjects.map(c => c.project));
const goldenPassingCount = uniqueGoldenProjects.size - uniqueFailedGoldenProjects.size;
const goldenFailingCount = uniqueFailedGoldenProjects.size;
const allOtherProjects = combined.filter(c => !c.is_golden);
const uniqueOtherProjects = new Set(allOtherProjects.map(c => c.project));
const failedRegularProjects = failedProjects.filter(c => !c.is_golden);
const uniqueFailedOtherProjects = new Set(failedRegularProjects.map(c => c.project));
const otherPassingCount = uniqueOtherProjects.size - uniqueFailedOtherProjects.size;
const otherFailingCount = uniqueFailedOtherProjects.size;
result += `\n🌟 *Golden Projects*`;
result += `\n✅ Passing: ${goldenPassingCount} | ❌ Failing: ${goldenFailingCount}`;
if (failedGoldenProjects.length > 0) {
result += `\n\n🚨 *Failed Golden Projects*`;
// Project names listed here — combo links added later by main() with job data
const seenProjects = new Set<string>();
failedGoldenProjects.forEach(matrix => {
if (!seenProjects.has(matrix.project)) {
seenProjects.add(matrix.project);
result += `\n\n*${matrix.project}*`;
// Placeholder — main() will replace with linked combos
result += `\n {{COMBOS:${matrix.project}}}`;
}
});
}
if (otherFailingCount > 0) {
const otherProjectCounts = new Map<string, number>();
failedRegularProjects.forEach(m => {
otherProjectCounts.set(m.project, (otherProjectCounts.get(m.project) || 0) + 1);
});
const otherSummary = [...otherProjectCounts.entries()]
.map(([p, c]) => `${p} (${c})`)
.join(', ');
result += `\n\n⚠️ *Failed Other Projects:* ${otherSummary}`;
}
if (failedProjects.length === 0) {
result = '🎉 *No test failures detected!* All systems green! 🟢';
}
const timeReport: Record<string, { min: number; max: number; minEnv: string; maxEnv: string }> = {};
const pmReport = { npm: 0, yarn: 0, pnpm: 0 };
const macosProjects = ['e2e-detox', 'e2e-expo', 'e2e-react-native'];
combined.forEach(matrix => {
const nodeVersion = parseInt(matrix.node_version.toString());
if (matrix.os_name === 'Linux' && nodeVersion === 20 && matrix.package_manager in pmReport) {
pmReport[matrix.package_manager as keyof typeof pmReport] += matrix.duration;
}
if (matrix.os_name === 'Linux' || macosProjects.includes(matrix.project)) {
if (timeReport[matrix.project]) {
if (matrix.duration > timeReport[matrix.project].max) {
timeReport[matrix.project].max = matrix.duration;
timeReport[matrix.project].maxEnv = `${matrix.os_name}, ${matrix.package_manager}`;
}
if (matrix.duration < timeReport[matrix.project].min) {
timeReport[matrix.project].min = matrix.duration;
timeReport[matrix.project].minEnv = `${matrix.os_name}, ${matrix.package_manager}`;
}
} else {
timeReport[matrix.project] = {
min: matrix.duration,
max: matrix.duration,
minEnv: `${matrix.os_name}, ${matrix.package_manager}`,
maxEnv: `${matrix.os_name}, ${matrix.package_manager}`,
};
}
}
});
let resultPkg = `
\`\`\`
| Project | Time |
|--------------------------------|---------------------------|`;
function mapProjectTime(proj: string, section: 'min' | 'max'): string {
return `${humanizeDuration(timeReport[proj][section])} (${timeReport[proj][`${section}Env`]})`;
}
function durationIcon(proj: string, section: 'min' | 'max'): string {
const duration = timeReport[proj][section];
if (duration < 12 * 60) return `${section}`;
if (duration < 15 * 60) return `${section}`;
return `${section}`;
}
Object.keys(timeReport).forEach(proj => {
resultPkg += `\n| ${proj.padEnd(30)} | |`;
resultPkg += `\n| ${durationIcon(proj, 'min').padStart(29)} | ${mapProjectTime(proj, 'min').padEnd(25)} |`;
resultPkg += `\n| ${durationIcon(proj, 'max').padStart(29)} | ${mapProjectTime(proj, 'max').padEnd(25)} |`;
});
resultPkg += `\`\`\``;
let resultPm = `
\`\`\`
| PM | Total time |
|------|-------------|`;
Object.keys(pmReport).forEach(pm => {
resultPm += `\n| ${pm.padEnd(4)} | ${humanizeDuration(pmReport[pm as keyof typeof pmReport]).padEnd(11)} |`;
});
resultPm += `\`\`\``;
return {
codeowners: Array.from(codeowners).join(','),
slack_message: trimSpace(result),
slack_proj_duration: trimSpace(resultPkg),
slack_pm_duration: trimSpace(resultPm),
has_golden_failures: hasGoldenFailures.toString(),
};
}
function setOutput(key: string, value: string) {
const outputPath = process.env.GITHUB_OUTPUT;
if (!outputPath) {
console.warn(`GITHUB_OUTPUT not set. Skipping output for "${key}".`);
return;
}
if (value.includes('\n')) {
const delimiter = `EOF_${key}_${Date.now()}`;
fs.appendFileSync(outputPath, `${key}<<${delimiter}\n${value}\n${delimiter}\n`);
} else {
fs.appendFileSync(outputPath, `${key}=${value}\n`);
}
}
async function main() {
const combinedInput = process.argv[2]
? process.argv[2]
: fs.readFileSync(0, 'utf-8').trim();
const combined: MatrixResult[] = JSON.parse(combinedInput);
const results = processResults(combined);
// Collect detailed failure info if golden failures exist
if (results.has_golden_failures === 'true') {
try {
const failedProjects = [
...new Set(
combined
.filter((c) => c.is_golden && (c.status === 'failure' || c.status === 'cancelled'))
.map((c) => c.project)
),
];
const { report, goldenJobLinks } = await collectFailureDetails(combined, failedProjects);
// Replace combo placeholders in the summary with linked combos
for (const [project, links] of goldenJobLinks) {
const placeholder = `{{COMBOS:${project}}}`;
const linkedCombos =
links.length > 0
? links.map((l) => ` · <${l.url}|${l.combo}>`).join('\n')
: ' (no job data)';
results.slack_message = results.slack_message.replace(
placeholder,
linkedCombos
);
}
// Remove any unreplaced placeholders (if collectFailureDetails didn't have data for a project)
results.slack_message = results.slack_message.replace(
/ \{\{COMBOS:[^}]+\}\}/g,
' (no job data)'
);
if (report) {
results.slack_message += '\n\n' + report;
}
} catch (e) {
console.error('Failed to collect failure details (brief report will still be posted):', e);
results.slack_message += '\n\n⚠️ _Failed to collect detailed failure information_';
}
}
Object.entries(results).forEach(([key, value]) => {
setOutput(key, value);
});
}
main().catch((error) => {
console.error('Error processing results:', error);
process.exit(1);
});
+10 -6
View File
@@ -8,21 +8,25 @@ on:
permissions: {}
jobs:
audit:
if: ${{ github.repository_owner == 'nrwl' }}
permissions:
contents: read # to fetch code (actions/checkout)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
uses: actions/checkout@v3
- uses: pnpm/action-setup@7088e561eb65bb68695d245aa206f005ef30921d # v4.1.0
with:
version: 10.28.2 # Aligned with root package.json (pnpm/action-setup will helpfully error if out of sync)
- name: Install PNPM
run: |
npm install -g @pnpm/exe@8.3.1
- name: Run a security audit
run: pnpm dlx audit-ci --critical --report-type summary
# - name: Run Dependency confusion supply chain check
# run: npx snync -d .
report:
if: ${{ always() && github.repository_owner == 'nrwl' && github.event_name != 'workflow_dispatch' }}
needs: audit
@@ -30,7 +34,7 @@ jobs:
name: Report status
steps:
- name: Send notification
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v11
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ needs.audit.result }}
message_format: '{emoji} Audit has {status_message}'
-30
View File
@@ -1,30 +0,0 @@
name: PR Title Validation
on:
pull_request:
types: [opened, edited, synchronize, reopened]
permissions: read-all
jobs:
validate-pr-title:
name: Validate PR Title
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
# Ensure's validate-pr-title.js is the copy from master
ref: master
- name: Setup Node.js
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: 24
package-manager-cache: false
- name: Validate PR title
env:
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
run: node ./scripts/validate-pr-title.js
+115 -587
View File
@@ -1,142 +1,25 @@
name: publish
on:
# Automated schedule - canary releases from master
schedule:
- cron: "0 19 * * 1-5" # Monday - Friday, at 19:00 UTC (7pm UTC)
# Manual trigger - PR releases or dry-runs (based on workflow inputs)
workflow_dispatch:
inputs:
pr:
description: "PR Number - If set, a real release will be created for the branch associated with the given PR number. If blank, a dry-run of the currently selected branch will be performed."
required: false
type: number
release:
types: [ published ]
# Dynamically generate the display name for the GitHub UI based on the event type and inputs
run-name: ${{ github.event.inputs.pr && format('PR Release for {0}', github.event.inputs.pr) || github.event_name == 'schedule' && 'Canary Release' || github.event_name == 'workflow_dispatch' && !github.event.inputs.pr && 'Release Dry-Run' || github.ref_name }}
env:
DEBUG: napi:*
NX_RUN_GROUP: ${{ github.run_id }}-${{ github.run_attempt }}
CYPRESS_INSTALL_BINARY: 0
NODE_VERSION: 22.16.0
PNPM_VERSION: 10.28.2 # Aligned with root package.json (pnpm/action-setup will helpfully error if out of sync)
NX_GRADLE_PROJECT_GRAPH_TIMEOUT: 600
NPM_CONFIG_PROVENANCE: true
on:
workflow_dispatch:
release:
types: [published]
jobs:
# We first need to determine the version we are releasing, and if we need a custom repo or ref to use for the git checkout in subsequent steps.
# These values depend upon the event type that triggered the workflow:
#
# - schedule:
# - We are running a canary release which always comes from the master branch, we can use default ref resolution
# in actions/checkout. The exact version will be generated within scripts/nx-release.ts.
#
# - release:
# - We are running a full release which is based on the tag that triggered the release event, we can use default
# ref resolution in actions/checkout. The exact version will be generated within scripts/nx-release.ts.
#
# - workflow_dispatch:
# - We are either running a dry-run on the current branch, in which case the version will be static and we can use
# default ref resolution in actions/checkout, or we are creating a PR release for the given PR number, in which case
# we should generate an applicable version number within publish-resolve-data.js and use a custom ref of the PR branch name.
resolve-required-data:
name: Resolve Required Data
if: ${{ github.repository_owner == 'nrwl' }}
runs-on: ubuntu-latest
outputs:
version: ${{ steps.script.outputs.version }}
dry_run_flag: ${{ steps.script.outputs.dry_run_flag }}
success_comment: ${{ steps.script.outputs.success_comment }}
publish_branch: ${{ steps.script.outputs.publish_branch }}
ref: ${{ steps.script.outputs.ref }}
repo: ${{ steps.script.outputs.repo }}
pr_number: ${{ steps.script.outputs.pr_number }}
pr_author: ${{ steps.script.outputs.pr_author }}
steps:
# Default checkout on the triggering branch so that the latest publish-resolve-data.js script is available
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Setup node
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'
check-latest: true
package-manager-cache: false
- name: Resolve and set checkout and version data to use for release
id: script
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
PR_NUMBER: ${{ github.event.inputs.pr }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const script = require('${{ github.workspace }}/scripts/publish-resolve-data.js');
await script({ github, context, core });
- name: (PR Release Only) Check out latest master
if: ${{ steps.script.outputs.ref != '' }}
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
# Check out the latest master branch to get its copy of nx-release.ts
repository: nrwl/nx
ref: master
path: latest-master-checkout
- name: (PR Release Only) Check out PR branch
if: ${{ steps.script.outputs.ref != '' }}
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
# Check out the PR branch to get its copy of nx-release.ts
repository: ${{ steps.script.outputs.repo }}
ref: ${{ steps.script.outputs.ref }}
path: pr-branch-checkout
- name: (PR Release Only) Ensure that release scripts have not changed in the PR being released
if: ${{ steps.script.outputs.ref != '' }}
run: |
# List of files that must not change in PR releases
FILES_TO_CHECK=(
"scripts/nx-release.ts"
"scripts/publish-resolve-data.js"
)
for FILE in "${FILES_TO_CHECK[@]}"; do
if ! cmp -s "latest-master-checkout/$FILE" "pr-branch-checkout/$FILE"; then
echo "🛑 Error: The file $FILE is different on the ${{ steps.script.outputs.ref }} branch on ${{ steps.script.outputs.repo }} vs latest master on nrwl/nx, cancelling workflow."
echo "If you did not modify the file, then you likely just need to rebase/merge latest master."
exit 1
else
echo "✅ The file $FILE is identical between the ${{ steps.script.outputs.ref }} branch on ${{ steps.script.outputs.repo }} and latest master on nrwl/nx."
fi
done
build:
needs: [ resolve-required-data ]
if: ${{ github.repository_owner == 'nrwl' }}
if: "!contains(github.event.head_commit.message, 'skip ci')"
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
setup: |-
rustup target add x86_64-apple-darwin
build: |
pnpm nx run-many --target=build-native -- --target=x86_64-apple-darwin
- host: windows-latest
setup: |-
choco install openjdk --version=21.0.0 -y
choco install dotnet-9.0-sdk -y
rustup target add aarch64-pc-windows-msvc
build: |
export JAVA_HOME="C:\Program Files\OpenJDK\jdk-21"
export PATH="$JAVA_HOME\bin:$PATH"
java -version
pnpm nx run-many --target=build-native -- --target=x86_64-pc-windows-msvc
build: pnpm nx run-many --target=build-native -- --target=x86_64-pc-windows-msvc
target: x86_64-pc-windows-msvc
# Windows 32bit (not needed)
# - host: windows-latest
@@ -146,70 +29,16 @@ jobs:
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: |
set -e
apt-get update
apt-get install -y curl ca-certificates git xz-utils gpg
# Install mise from the signed apt repo
install -dm 755 /etc/apt/keyrings
curl -fsSL https://mise.jdx.dev/gpg-key.pub | gpg --dearmor -o /etc/apt/keyrings/mise-archive-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/mise-archive-keyring.gpg arch=$(dpkg --print-architecture)] https://mise.jdx.dev/deb stable main" > /etc/apt/sources.list.d/mise.list
apt-get update
apt-get install -y mise
# Provision Node, Java, .NET, Maven, corepack from mise.toml
cd /build
mise trust mise.toml
mise install
eval "$(mise env -s bash)"
corepack enable
corepack prepare --activate
pnpm install --frozen-lockfile
rustup target add x86_64-unknown-linux-gnu
pnpm nx run-many --verbose --target=build-native -- --target=x86_64-unknown-linux-gnu
build: |-
set -e &&
pnpm --version &&
pnpm nx run-many --target=build-native -- --target=x86_64-unknown-linux-gnu
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: |
bash -c "
set -e
# mise's core node/java backends don't ship musl binaries and fall back to
# compile-from-source on Alpine, which fails. Install via apk + tarball instead.
echo 'https://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
apk add --no-cache curl xz openjdk21 build-base lld dotnet9-sdk
# Java 21
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk
export PATH=\"\$JAVA_HOME/bin:\$PATH\"
java --version
# .NET 9 SDK (needed by @nx/dotnet plugin)
dotnet --version
# Node.js musl build from unofficial-builds.nodejs.org
curl -fsSL https://unofficial-builds.nodejs.org/download/release/v22.16.0/node-v22.16.0-linux-x64-musl.tar.xz -o node.tar.xz
tar -xJf node.tar.xz
mv node-v22.16.0-linux-x64-musl /usr/local/node
export PATH=\"/usr/local/node/bin:\$PATH\"
node --version
npm i -g pnpm@\${PNPM_VERSION} --force
# Help clang find GCC runtime (crtbeginS.o, libgcc) and use lld for jemalloc build
GCC_DIR=\$(dirname \$(find /usr/lib/gcc -name crtbeginS.o | head -1))
export CFLAGS=\"\${CFLAGS} -fuse-ld=lld --gcc-install-dir=\${GCC_DIR}\"
pnpm install --frozen-lockfile
rustup target add x86_64-unknown-linux-musl
pnpm nx run-many --verbose --target=build-native -- --target=x86_64-unknown-linux-musl
"
build: set -e && pnpm nx run-many --target=build-native -- --target=x86_64-unknown-linux-musl
- host: macos-latest
target: aarch64-apple-darwin
setup: |-
rustup target add aarch64-apple-darwin
build: |
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
export CC=$(xcrun -f clang);
@@ -220,45 +49,17 @@ jobs:
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: |
set -e
apt-get update
apt-get install -y curl ca-certificates git xz-utils gpg
# Install mise from the signed apt repo
install -dm 755 /etc/apt/keyrings
curl -fsSL https://mise.jdx.dev/gpg-key.pub | gpg --dearmor -o /etc/apt/keyrings/mise-archive-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/mise-archive-keyring.gpg arch=$(dpkg --print-architecture)] https://mise.jdx.dev/deb stable main" > /etc/apt/sources.list.d/mise.list
apt-get update
apt-get install -y mise
# Provision Node, Java, .NET, Maven, corepack from mise.toml
cd /build
mise trust mise.toml
mise install
eval "$(mise env -s bash)"
# Help clang find GCC runtime (crtbeginS.o, libgcc) and use lld for jemalloc build
export CFLAGS="${CFLAGS} -fuse-ld=lld --gcc-toolchain=/usr/aarch64-unknown-linux-gnu"
# Build jemalloc with 64 KiB allocator page so the binary works on aarch64
# Linux kernels with 4K/16K/64K pages (Asahi, Ampere, Graviton, etc.).
export JEMALLOC_SYS_WITH_LG_PAGE=16
corepack enable
corepack prepare --activate
pnpm install --frozen-lockfile
rustup target add aarch64-unknown-linux-gnu
pnpm nx run-many --verbose --target=build-native -- --target=aarch64-unknown-linux-gnu
build: |-
set -e &&
pnpm --version &&
pnpm nx run-many --target=build-native -- --target=aarch64-unknown-linux-gnu
- host: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
setup: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf -y
rustup target add armv7-unknown-linux-gnueabihf
build: |
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=/usr/bin/arm-linux-gnueabihf-gcc pnpm nx run-many --target=build-native -- --target=armv7-unknown-linux-gnueabihf
pnpm nx run-many --target=build-native -- --target=armv7-unknown-linux-gnueabihf
# Android (not needed)
# - host: ubuntu-latest
# target: aarch64-linux-android
@@ -271,80 +72,38 @@ jobs:
- host: ubuntu-latest
target: aarch64-unknown-linux-musl
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: |
bash -c "
set -e
# mise's core node/java backends don't ship musl binaries and fall back to
# compile-from-source on Alpine, which fails. Install via apk + tarball instead.
echo 'https://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories
apk add --no-cache curl xz openjdk21 build-base lld dotnet9-sdk
# Java 21
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk
export PATH=\"\$JAVA_HOME/bin:\$PATH\"
java --version
# .NET 9 SDK (needed by @nx/dotnet plugin)
dotnet --version
# Node.js musl build from unofficial-builds.nodejs.org. Container is x64;
# rust cross-compiles to aarch64-unknown-linux-musl, so the host node binary
# is x64-musl regardless of the build target.
curl -fsSL https://unofficial-builds.nodejs.org/download/release/v22.16.0/node-v22.16.0-linux-x64-musl.tar.xz -o node.tar.xz
tar -xJf node.tar.xz
mv node-v22.16.0-linux-x64-musl /usr/local/node
export PATH=\"/usr/local/node/bin:\$PATH\"
node --version
npm i -g pnpm@\${PNPM_VERSION} --force
# Help clang find GCC runtime (crtbeginS.o, libgcc) and use lld for jemalloc build
GCC_DIR=\$(dirname \$(find /aarch64-linux-musl-cross/lib/gcc -name crtbeginS.o | head -1))
export CFLAGS=\"\${CFLAGS} -fuse-ld=lld --gcc-install-dir=\${GCC_DIR}\"
# Build jemalloc with 64 KiB allocator page so the binary works on aarch64
# Linux kernels with 4K/16K/64K pages (Asahi, Ampere, Graviton, etc.).
export JEMALLOC_SYS_WITH_LG_PAGE=16
pnpm install --frozen-lockfile
rustup target add aarch64-unknown-linux-musl
pnpm nx run-many --verbose --target=build-native -- --target=aarch64-unknown-linux-musl
"
build: |-
set -e &&
rustup target add aarch64-unknown-linux-musl &&
pnpm nx run-many --target=build-native -- --target=aarch64-unknown-linux-musl
- host: windows-latest
target: aarch64-pc-windows-msvc
setup: |-
choco install openjdk --version=21.0.0 -y
choco install dotnet-9.0-sdk -y
rustup target add aarch64-pc-windows-msvc
build: |
export JAVA_HOME="C:\Program Files\OpenJDK\jdk-21"
export PATH="$JAVA_HOME\bin:$PATH"
java -version
pnpm nx run-many --target=build-native -- --target=aarch64-pc-windows-msvc
name: stable - ${{ matrix.settings.target }} - node@22.16.0
build: pnpm nx run-many --target=build-native -- --target=aarch64-pc-windows-msvc
name: stable - ${{ matrix.settings.target }} - node@18
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
repository: ${{ needs.resolve-required-data.outputs.repo || github.repository }}
ref: ${{ needs.resolve-required-data.outputs.ref || github.ref }}
version: 8.2
- name: Set verbose logging from debug mode
if: runner.debug == '1'
run: echo "NX_VERBOSE_LOGGING=true" >> "$GITHUB_ENV"
- name: Setup dev tools with mise
uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 # v3
- name: Setup node
uses: actions/setup-node@v3
if: ${{ !matrix.settings.docker }}
with:
node-version: 18
check-latest: true
cache: 'pnpm'
- name: Enable corepack and install pnpm
- name: Install
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.docker }}
run: |
corepack enable
corepack prepare --activate
with:
targets: ${{ matrix.settings.target }}
- name: Cache cargo
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
uses: actions/cache@v3
with:
path: |
~/.cargo/registry/index/
@@ -353,359 +112,128 @@ jobs:
.cargo-cache
target/
key: ${{ matrix.settings.target }}-cargo-registry
- uses: goto-bus-stop/setup-zig@v2
if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' }}
with:
version: 0.10.0
- name: Setup toolchain
run: ${{ matrix.settings.setup }}
if: ${{ matrix.settings.setup }}
shell: bash
- name: Setup node x86
if: matrix.settings.target == 'i686-pc-windows-msvc'
run: yarn config set supportedArchitectures.cpu "ia32"
shell: bash
- name: Install dependencies
if: ${{ !matrix.settings.docker }}
run: pnpm install --frozen-lockfile
timeout-minutes: 30
- name: Setup node x86
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
uses: actions/setup-node@v3
if: matrix.settings.target == 'i686-pc-windows-msvc'
with:
node-version: ${{ env.NODE_VERSION }}
node-version: 18
check-latest: true
cache: pnpm
architecture: x86
- name: Build in docker
uses: addnab/docker-run-action@v3
if: ${{ matrix.settings.docker }}
shell: bash
env:
BUILD_SCRIPT: ${{ matrix.settings.build }}
run: |
SCRIPT_FILE=$(mktemp)
echo "$BUILD_SCRIPT" > "$SCRIPT_FILE"
docker run --rm \
--user 0:0 \
-e NODE_VERSION \
-e PNPM_VERSION \
-e NX_GRADLE_PROJECT_GRAPH_TIMEOUT \
-e NX_VERBOSE_LOGGING \
-v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db \
-v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache \
-v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index \
-v ${{ github.workspace }}:/build \
-v "$SCRIPT_FILE:/build-script.sh" \
-w /build \
${{ matrix.settings.docker }} \
bash /build-script.sh
with:
image: ${{ matrix.settings.docker }}
options: --user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build
run: ${{ matrix.settings.build }}
- name: Build
run: ${{ matrix.settings.build }}
if: ${{ !matrix.settings.docker }}
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
uses: actions/upload-artifact@v3
with:
name: bindings-${{ matrix.settings.target }}
path: |
packages/nx/src/native/*.node
packages/nx/src/native/*.wasm
path: packages/**/*.node
if-no-files-found: error
build-freebsd:
needs: [ resolve-required-data ]
if: ${{ github.repository_owner == 'nrwl' }}
runs-on: ubuntu-latest
name: Build FreeBSD
timeout-minutes: 45
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
repository: ${{ needs.resolve-required-data.outputs.repo || github.repository }}
ref: ${{ needs.resolve-required-data.outputs.ref || github.ref }}
- name: Build
id: build
uses: cross-platform-actions/action@462ed697694d2ac9aa49e1225f395f7bb6dd49fe # v0.29.0
env:
DEBUG: napi:*
RUSTUP_IO_THREADS: 1
NX_PREFER_TS_NODE: true
PLAYWRIGHT_BROWSERS_PATH: 0
NODE_VERSION: 22.16.0
NX_GRADLE_DISABLE: 'true'
NX_DOTNET_DISABLE: 'true'
NODE_OPTIONS: '--max-old-space-size=4096'
with:
operating_system: freebsd
version: '14.0'
architecture: x86-64
environment_variables: DEBUG RUSTUP_IO_THREADS CI NX_PREFER_TS_NODE PLAYWRIGHT_BROWSERS_PATH NODE_VERSION NX_GRADLE_DISABLE NX_DOTNET_DISABLE NODE_OPTIONS
shell: bash
run: |
env
whoami
sudo pkg install -y -f node libnghttp2 www/npm git ca_root_nss
sudo npm install --location=global --ignore-scripts pnpm@10.28.2
curl https://sh.rustup.rs -sSf --output rustup.sh
sh rustup.sh -y --profile minimal --default-toolchain stable
source "$HOME/.cargo/env"
echo "~~~~ rustc --version ~~~~"
rustc --version
echo "~~~~ node -v ~~~~"
node -v
echo "~~~~ pnpm --version ~~~~"
pnpm --version
pwd
ls -lah
whoami
env
freebsd-version
echo "Installing dependencies"
pnpm install --frozen-lockfile --ignore-scripts
echo "Checking disk space before cleanup"
df -h
echo "Removing unnecessary preinstalled packages"
# List all packages first to see what's installed
sudo pkg info -a
echo "Cleaning up to free disk space"
# Clean package caches
sudo pkg clean -a -y
sudo pkg autoremove -y
# Remove unnecessary system files
sudo rm -rf /usr/local/lib/*.a
sudo rm -rf /usr/local/share/doc/*
sudo rm -rf /usr/local/share/man/*
sudo rm -rf /usr/local/share/examples/*
sudo rm -rf /usr/local/share/locale/*
sudo rm -rf /usr/local/share/gtk-doc/*
sudo rm -rf /usr/local/share/info/*
sudo rm -rf /usr/src/*
sudo rm -rf /usr/obj/*
sudo rm -rf /usr/tests/*
sudo rm -rf /usr/lib/debug/*
# Clean var directories
sudo rm -rf /var/cache/pkg/*
sudo rm -rf /var/db/pkg/*.tbz
sudo rm -rf /var/log/*.log
sudo rm -rf /var/log/*.old
# Clean temporary files
sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*
# Remove Python cache if present
sudo find /usr/local -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
sudo find /usr/local -name "*.pyc" -delete 2>/dev/null || true
sudo find /usr/local -name "*.pyo" -delete 2>/dev/null || true
# Clean npm/pnpm caches
npm cache clean --force || true
pnpm store prune || true
rm -rf ~/.npm || true
rm -rf ~/.pnpm-store || true
# Clean Rust extras but keep registry/git (needed for cargo to resolve deps)
rm -rf ~/.rustup/toolchains/*/share || true
# Remove other development tool caches
rm -rf ~/.cache/* || true
# Remove unnecessary workspace directories
rm -rf docs astro-docs nx-dev || true
echo "Checking disk space after cleanup"
df -h
# Disable core dumps - OOM'd Node processes write multi-GB core files that fill the disk
ulimit -c 0
echo "Building FreeBSD bindings"
BUILD_EXIT=0
pnpm nx run-many --verbose --outputStyle stream --target=build-native -- --target=x86_64-unknown-freebsd || BUILD_EXIT=$?
echo "=== Disk usage after build ==="
df -h
if [ "$BUILD_EXIT" -ne 0 ]; then
echo "Build failed with exit code $BUILD_EXIT"
echo "=== Disk usage by top-level directories ==="
du -sh /* 2>/dev/null | sort -rh | head -20
echo "=== Disk usage in home directory ==="
du -sh ~/* 2>/dev/null | sort -rh | head -20
echo "=== Disk usage in workspace ==="
du -sh /home/runner/work/nx/nx/* 2>/dev/null | sort -rh | head -20
echo "=== Disk usage in .nx ==="
du -sh /home/runner/work/nx/nx/.nx/* 2>/dev/null | sort -rh | head -20
echo "=== Disk usage in cargo/rustup ==="
du -sh ~/.cargo/* ~/.rustup/* 2>/dev/null | sort -rh | head -20
echo "=== Core dumps ==="
find / -name "*.core" -o -name "core.*" -o -name "core" 2>/dev/null | head -10
exit $BUILD_EXIT
fi
echo "Build succeeded"
echo "Cleaning up"
pnpm nx reset
rm -rf node_modules
rm -rf dist
echo "KILL ALL NODE PROCESSES"
killall node || true
echo "COMPLETE"
- name: Upload artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: bindings-freebsd
path: |
packages/nx/src/native/*.node
if-no-files-found: error
runs-on: macos-12
name: Build FreeBSD
steps:
- uses: actions/checkout@v3
- name: Build
id: build
uses: vmactions/freebsd-vm@v0
env:
DEBUG: napi:*
RUSTUP_HOME: /usr/local/rustup
CARGO_HOME: /usr/local/cargo
RUSTUP_IO_THREADS: 1
with:
envs: DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS
usesh: true
mem: 4096
prepare: |
pkg install -y -f curl node libnghttp2 npm
npm install --location=global --ignore-scripts pnpm
curl https://sh.rustup.rs -sSf --output rustup.sh
sh rustup.sh -y --profile minimal --default-toolchain stable
export PATH="/usr/local/cargo/bin:$PATH"
echo "~~~~ rustc --version ~~~~"
rustc --version
echo "~~~~ node -v ~~~~"
node -v
echo "~~~~ pnpm --version ~~~~"
pnpm --version
run: |
export PATH="/usr/local/cargo/bin:$PATH"
pwd
ls -lah
whoami
env
freebsd-version
mkdir -p /Users/runner/work/_temp/_github_workflow
echo "{}" > /Users/runner/work/_temp/_github_workflow/event.json
pnpm install --frozen-lockfile --ignore-scripts
pnpm nx run-many --target=build-native -- --target=x86_64-unknown-freebsd
rm -rf node_modules
rm -rf dist
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bindings-freebsd
path: packages/**/*.node
if-no-files-found: error
publish:
if: ${{ github.repository_owner == 'nrwl' }}
if: ${{ github.event_name == 'release' && github.repository_owner == 'nrwl' }}
name: Publish
runs-on: ubuntu-latest
environment: npm-registry
permissions:
id-token: write
contents: write
pull-requests: write
needs:
- resolve-required-data
- build-freebsd
- build
env:
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
repository: ${{ needs.resolve-required-data.outputs.repo || github.repository }}
ref: ${{ needs.resolve-required-data.outputs.ref || github.ref }}
- name: Set verbose logging from debug mode
if: runner.debug == '1'
run: echo "NX_VERBOSE_LOGGING=true" >> "$GITHUB_ENV"
- name: Setup dev tools with mise
uses: jdx/mise-action@146a28175021df8ca24f8ee1828cc2a60f980bd5 # v3
- name: Enable corepack and install pnpm
run: |
corepack enable
corepack prepare --activate
- name: Use npm 11.5.2
run: npm install -g npm@11.5.2
version: 8.2
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Download all artifacts
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
uses: actions/download-artifact@v3
with:
path: artifacts
# This command will appropriately fail if no artifacts are available
- name: List artifacts
run: ls -R artifacts
shell: bash
- name: Build Wasm
run: |
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-23/wasi-sdk-23.0-x86_64-linux.tar.gz
tar -xvf wasi-sdk-23.0-x86_64-linux.tar.gz
rustup toolchain install nightly-2025-05-09
pnpm build:wasm
- name: Publish
env:
VERSION: ${{ needs.resolve-required-data.outputs.version }}
DRY_RUN: ${{ needs.resolve-required-data.outputs.dry_run_flag }}
PUBLISH_BRANCH: ${{ needs.resolve-required-data.outputs.publish_branch }}
run: |
echo ""
# Create and check out the publish branch
git checkout -b $PUBLISH_BRANCH
echo ""
echo "Version set to: $VERSION"
echo "DRY_RUN set to: $DRY_RUN"
echo ""
pnpm nx-release --local=false $VERSION $DRY_RUN
- name: (Stable Release Only) Trigger Docs Release
# Publish docs only on a full release
if: ${{ !github.event.release.prerelease && github.event_name == 'release' }}
run: npx ts-node -P ./scripts/tsconfig.scripts.json ./scripts/release-docs.ts
- name: (PR Release Only) Create comment for successful PR release
if: success() && github.event.inputs.pr
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
SUCCESS_COMMENT: ${{ needs.resolve-required-data.outputs.success_comment }}
with:
# github-token defaults to ${{ github.token }} so we don't need to specify it
script: |
const successComment = JSON.parse(process.env.SUCCESS_COMMENT);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.pr }},
body: successComment
});
report-pending-publish:
name: Report Pending Publish to Slack
if: ${{ github.repository_owner == 'nrwl' }}
needs:
- resolve-required-data
- build-freebsd
- build
runs-on: ubuntu-latest
timeout-minutes: 10
continue-on-error: true # Don't fail the workflow if notification fails
steps:
- name: Send Slack notification
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v11
with:
status: ${{ job.status }}
notification_title: >-
${{ needs.resolve-required-data.outputs.pr_number &&
format('📦 PR #{0} Publish Pending Review', needs.resolve-required-data.outputs.pr_number) ||
'📦 Publish Pending Review' }}
message_format: >-
${{ needs.resolve-required-data.outputs.pr_number &&
format('Version {0} from PR #{1} by @{2} is being published to NPM - manual review is required',
needs.resolve-required-data.outputs.version,
needs.resolve-required-data.outputs.pr_number,
needs.resolve-required-data.outputs.pr_author) ||
format('Version {0} is being published to NPM - manual review is required',
needs.resolve-required-data.outputs.version) }}
footer: '<{run_url}|View Workflow Run>'
mention_users: 'U9NPA6C90' # Jason
env:
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }}
pr_failure_comment:
# Run this job if it is a PR release, running on the nrwl origin, and any of the required jobs failed
if: ${{ github.repository_owner == 'nrwl' && github.event.inputs.pr && always() && contains(needs.*.result, 'failure') }}
needs: [ resolve-required-data, build, build-freebsd, publish ]
name: (PR Release Failure Only) Create comment for failed PR release
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Create comment for failed PR release
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
# This script is intentionally kept inline (and e.g. not generated in publish-resolve-data.js)
# to ensure that an error within the data generation itself is not missed.
script: |
const message = `
Failed to publish a PR release of this pull request, triggered by @${{ github.triggering_actor }}.
See the failed workflow run at: https://github.com/nrwl/nx/actions/runs/${{ github.run_id }}
`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.inputs.pr }},
body: message
});
git checkout -b publish/$GITHUB_REF_NAME
npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
pnpm nx-release --local=false $GITHUB_REF_NAME
env:
GH_TOKEN: ${{ github.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
+106 -39
View File
@@ -4,7 +4,7 @@ on:
name: Stale Bot workflow
permissions: { }
permissions: {}
jobs:
build:
@@ -16,96 +16,163 @@ jobs:
name: stale
runs-on: ubuntu-latest
steps:
# This handles issues that need more info
- name: stale-more-info-needed
id: stale-more-info-needed
uses: actions/stale@3a9db7e6a41a89f618792c92c0e97cc736e1b13f # v10.0.0
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 7
days-before-close: 21
days-before-stale: 14
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "blocked: more info needed"
stale-issue-message: |
This issue has been automatically marked as stale because more information has not been provided within 7 days.
It will be closed in 21 days if no information is provided.
If information has been provided, please reply to keep it active.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
# This handles PRs that need to be rebased
- name: stale-needs-rebase
id: stale-needs-rebase
uses: actions/stale@3a9db7e6a41a89f618792c92c0e97cc736e1b13f # v10.0.0
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 7
days-before-close: 21
days-before-stale: 14
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "blocked: needs rebased"
stale-issue-message: |
This PR has been automatically marked as stale because it has not been rebased in 7 days.
It will be closed in 21 days if it is not rebased.
If the PR has been rebased or you are working on rebasing it, please reply to keep it active.
If you do not have time, please let us know and we can rebase it.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
# This handles issues that do not have a repro
- name: stale-repro-needed
id: stale-repro-needed
uses: actions/stale@3a9db7e6a41a89f618792c92c0e97cc736e1b13f # v10.0.0
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 7
days-before-close: 21
days-before-stale: 14
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "blocked: repro needed"
stale-issue-message: |
This issue has been automatically marked as stale because no reproduction was provided within 7 days.
Please help us help you. Providing a repository exhibiting the issue helps us diagnose and fix the issue.
Any time that we spend reproducing this issue is time taken away from addressing this issue and other issues.
This issue will be closed in 21 days if a reproduction is not provided.
If a reproduction has been provided, please reply to keep it active.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
- name: stale-retry-with-latest
id: stale-retry-with-latest
uses: actions/stale@3a9db7e6a41a89f618792c92c0e97cc736e1b13f # v10.0.0
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 7
days-before-close: 21
days-before-stale: 14
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "blocked: retry with latest"
stale-issue-message: |
This issue has been automatically marked as stale because no results of retrying on the latest version of Nx was provided within 7 days.
It will be closed in 21 days if no results are provided.
If the issue is still present, please reply to keep it active.
If the issue was not present, please close this issue.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
# This handles issues are really old and were made with a previous major
- name: stale-bug
id: stale-bug
uses: actions/stale@3a9db7e6a41a89f618792c92c0e97cc736e1b13f # v10.0.0
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 180
days-before-close: 21
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "type: bug"
stale-issue-message: |
This issue has been automatically marked as stale because it hasn't had any activity for 6 months.
Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore.
If at this point, this is still an issue, please respond with updated information.
It will be closed in 21 days if no further activity occurs.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
- name: stale-cleanup
id: stale-cleanup
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 180
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "type: cleanup"
stale-issue-message: |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
- name: stale-docs
id: stale-docs
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 180
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "type: docs"
stale-issue-message: |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
- name: stale-enhancement
id: stale-enhancement
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 250
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "type: enhancement"
stale-issue-message: |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
- name: stale-feature
id: stale-feature
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 250
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "type: feature"
stale-issue-message: |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
- name: stale-question
id: stale-question
uses: actions/stale@v3.0.13
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 45
days-before-close: 14
stale-issue-label: "stale"
operations-per-run: 300
remove-stale-when-updated: true
only-labels: "type: question / discussion"
stale-issue-message: |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏
+2 -123
View File
@@ -3,7 +3,6 @@ node_modules
/.fleet
/.vscode
dist
out-tsc
/build
/coverage
./test
@@ -13,145 +12,25 @@ tmp
jest.debug.config.js
.tool-versions
/.nx-cache
/.nx/cache
/.nx/workspace-data
/.verdaccio/build/local-registry
/graph/client/src/assets/environment.js
/graph/client/src/assets/dev/environment.js
/graph/client/src/assets/generated-project-graphs
/graph/client/src/assets/generated-task-graphs
/graph/client/src/assets/generated-task-inputs
/graph/client/src/assets/generated-source-maps
/nx-dev/nx-dev/public/documentation
/nx-dev/nx-dev/public/tutorials
/nx-dev/nx-dev/public/images/open-graph
/nx-dev/nx-dev/public/robots.txt
/nx-dev/nx-dev/public/sitemap-0.xml
/nx-dev/nx-dev/public/sitemap.xml
# Banner JSON files are generated during static builds
/nx-dev/nx-dev/lib/banner.json
/astro-docs/src/content/banner.json
**/tests/temp-db*
# Issues scraper creates these files, stored by github's cache
/scripts/issues-scraper/cached
# We don't commit a CHANELGELOG.md file to the repo, we only create Github releases
# Lerna creates this
CHANGELOG.md
# Next.js
.next
out
# Angular Cache
.angular
# Astro Cache
.astro
# Local dev files
.env.local
.env
.bashrc
*.node
# Fix for issue when working on the repo in a dev container
.pnpm-store
.cargo/.package-cache
.cargo/bin/
.cargo/env
.cargo/registry/
.local/
.npm/
.profile
.rustup/
target
.flattened-pom.xml
dependency-reduced-pom.xml
*.wasm
/wasi-sdk*
*.config.timestamp*
storybook-static
# Ignore Gradle project-specific cache directory
.gradle
.kotlin
.claude/settings.local.json
.claude/scheduled_tasks.lock
CLAUDE.local.md
.cursor/mcp.json
# Added by Claude Task Master
# Logs
logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
dev-debug.log
# Dependency directories
node_modules/
# Environment variables
.env
!e2e/dotnet/.env
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
!/nx.sln
*.sw?
.specstory/**
.cursorindexingignore
# OS specific
# Task files
/tasks.json
/tasks
# Upstream docs local configuration (machine-specific)
.upstreamdocs.local.json
# Netlify build artifacts
.netlify
coverage
# Angular Rspack Specific Options
packages/angular-rspack/coverage
packages/angular-rspack-compiler/coverage
# Some Packages use a template to generate the correct README
packages/angular-rspack/README.md
packages/angular-rspack-compiler/README.md
packages/dotnet/README.md
packages/maven/README.md
packages/nx/README.md
packages/devkit/README.md
packages/workspace/README.md
test-output
test-results
# TypeScript build info files
*.tsbuildinfo
# .NET build output
/packages/dotnet/analyzer/bin
/packages/dotnet/analyzer/obj
/packages/dotnet/analyzer.Tests/bin
/packages/dotnet/analyzer.Tests/obj
/*.deb
.nx/polygraph
.claude/worktrees
.nx/self-healing
e2e/**/*.d.ts
e2e/**/*.d.ts.map
-1
View File
@@ -1 +0,0 @@
node ./scripts/commit-lint.js "$1"
+1 -10
View File
@@ -1,12 +1,3 @@
# Skip if this is a worktree creation (previous ref is null)
if [ "$1" = "0000000000000000000000000000000000000000" ]; then
exit 0
fi
# Skip if this is a file checkout (not branch switch) - $3 would be 0
if [ "$3" = "0" ]; then
exit 0
fi
#!/bin/sh
changedFiles="$(git diff-tree -r --name-only --no-commit-id $1 $2)"
node ./scripts/notify-lockfile-changes.js $changedFiles
+2 -1
View File
@@ -1,2 +1,3 @@
#!/bin/sh
changedFiles="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
node ./scripts/notify-lockfile-changes.js $changedFiles
node ./scripts/notify-lockfile-changes.js $changedFiles
+6 -1
View File
@@ -1 +1,6 @@
pnpm nx prepush --parallel 8 --tuiAutoExit 0
#!/usr/bin/env sh
pnpm check-lock-files &&
pnpm check-commit &&
pnpm documentation &&
pnpm pretty-quick --check
-1
View File
@@ -1 +0,0 @@
NX_USE_V8_SERIALIZER=false
-3
View File
@@ -1,3 +0,0 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/4.0.0-rc-5/apache-maven-4.0.0-rc-5-bin.zip
-3
View File
@@ -1,3 +0,0 @@
{
"experimentalPolygraph": true
}
-95
View File
@@ -1,95 +0,0 @@
common-env-vars: &common-env-vars
GIT_AUTHOR_EMAIL: test@test.com
GIT_AUTHOR_NAME: Test
GIT_COMMITTER_EMAIL: test@test.com
GIT_COMMITTER_NAME: Test
SELECTED_PM: 'pnpm'
NX_NATIVE_LOGGING: 'nx::native::db'
# These are need for build and link validation for next.js and astro apps
NEXT_PUBLIC_ASTRO_URL: 'https://master--nx-docs.netlify.app'
NX_DEV_URL: 'https://canary.nx.dev'
common-init-steps: &common-init-steps
- name: Checkout
uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/checkout/main.yaml'
- name: Cache restore
uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/cache/main.yaml'
inputs:
key: 'pnpm-lock.yaml'
paths: ~/.local/share/pnpm/store
base-branch: 'master'
# reads mise.toml and installs toolchains needed for repo
- name: Setup toolchains
uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/install-mise/main.yaml'
- name: Verify toolchain versions
script: |
echo "mise: $(mise --version)"
echo "node: $(node --version)"
echo "pnpm: $(pnpm --version)"
echo "bun: $(bun --version)"
echo "rust: $(rustc --version) - $(cargo --version)"
echo "dotnet: $(dotnet --version)"
echo "java: $(javac --version)"
- name: Install system deps
script: |
# apt mirror+file failover: tab-separated; printf preserves \t (YAML heredocs don't).
printf 'https://archive.ubuntu.com/ubuntu/\tpriority:1\n' | sudo tee /etc/apt/apt-mirrors.txt > /dev/null
printf 'https://security.ubuntu.com/ubuntu/\tpriority:2\n' | sudo tee -a /etc/apt/apt-mirrors.txt > /dev/null
printf 'http://azure.archive.ubuntu.com/ubuntu/\tpriority:3\n' | sudo tee -a /etc/apt/apt-mirrors.txt > /dev/null
# Retries=0: mirror+file already retries via failover; apt-level retries multiply stall on a dead mirror.
sudo tee /etc/apt/apt.conf.d/80-nx-mirror-failover > /dev/null <<'EOF'
Acquire::http::Timeout "5";
Acquire::https::Timeout "5";
Acquire::Retries "0";
EOF
sudo sed -i 's|http://archive.ubuntu.com/ubuntu|mirror+file:/etc/apt/apt-mirrors.txt|g; s|http://security.ubuntu.com/ubuntu|mirror+file:/etc/apt/apt-mirrors.txt|g' /etc/apt/sources.list
sudo apt-get update
sudo apt-get install -y ca-certificates lsof libvips-dev libglib2.0-dev libgirepository1.0-dev zip unzip
- name: Pnpm Install from lockfile
script: |
pnpm install --frozen-lockfile
- name: Install browsers
script: |
pnpm exec cypress install
pnpm exec playwright install --with-deps
- name: Install rust deps
script: |
cargo fetch
- name: Install hyperfine
script: |
cargo install hyperfine
- name: Setup gradle
script: |
./gradlew wrapper
./gradlew --version
- name: Restore .NET analyzer projects
script: |
dotnet restore packages/dotnet/analyzer.Tests/MsbuildAnalyzer.Tests.csproj
- name: Configure git metadata (needed for lerna smoke tests)
script: |
git config --global user.email test@test.com
git config --global user.name "Test Test"
launch-templates:
linux-large:
resource-class: 'docker_linux_amd64/large'
image: 'us-east1-docker.pkg.dev/nxcloudoperations/nx-cloud/nx-agents-base-images:ubuntu22.04-node20.19-v1'
env: *common-env-vars
init-steps: *common-init-steps
linux-extra-large:
resource-class: 'docker_linux_amd64/extra_large'
image: 'us-east1-docker.pkg.dev/nxcloudoperations/nx-cloud/nx-agents-base-images:ubuntu22.04-node20.19-v1'
env: *common-env-vars
init-steps: *common-init-steps
-68
View File
@@ -1,68 +0,0 @@
distribute-on:
extra-small-changeset: 6 linux-large, 3 linux-extra-large
small-changeset: 6 linux-large, 4 linux-extra-large
medium-changeset: 6 linux-large, 5 linux-extra-large
large-changeset: 6 linux-large, 6 linux-extra-large
extra-large-changeset: 8 linux-large, 8 linux-extra-large
assignment-rules:
- projects:
- nx
- workspace
- remix
- nx-maven-plugin
targets:
- install
- test
run-on:
- agent: linux-large
parallelism: 1
- agent: linux-extra-large
parallelism: 1
- targets:
- e2e-ci**
run-on:
- agent: linux-large
parallelism: 2
- agent: linux-extra-large
parallelism: 4
- targets:
- bench:*
run-on:
- agent: linux-large
parallelism: 1
# These projects should not need to be isolated.
- projects:
- nx-dev
- astro-docs
targets:
- build*
run-on:
- agent: linux-extra-large
parallelism: 1
- projects:
- angular
- react
targets:
- test
run-on:
- agent: linux-extra-large
parallelism: 1
- targets:
- lint
run-on:
- agent: linux-large
parallelism: 6
- agent: linux-extra-large
parallelism: 6
- targets:
- "*"
run-on:
- agent: linux-large
parallelism: 3
- agent: linux-extra-large
parallelism: 3
-28
View File
@@ -1,28 +0,0 @@
exclude-reads:
- packages/nx/src/native/*.node
- packages/nx/dist/src/native/*.node
- 'dist/target/**'
exclude-writes:
- '**/.swc/**'
- 'dist/target/**'
task-exclusions:
- target: lint
exclude-reads:
- '**/dist/**/*.json'
# TODO: populate-local-registry-storage is doing too much — it reads all build
# outputs and writes version-bumped packages across the entire workspace during
# nx-release. We're reworking this task to have more focused I/O and will fix
# the inputs/outputs properly after that.
- project: '@nx/nx-source'
target: populate-local-registry-storage
exclude-reads:
- '**'
exclude-writes:
- '**'
- project: graph-client
target: build-client
exclude-reads:
- '**/*.stories.{js,jsx,ts,tsx,mdx}'
- '**/*.{spec,test}.{js,jsx,ts,tsx}'
-4
View File
@@ -1,6 +1,2 @@
benchmarks/packages
nx-dev/**/jest.config.js
.next
_files
_solution
nx-dev/tutorial/**/templates
-479
View File
@@ -1,479 +0,0 @@
---
description: Polls Nx Cloud CI pipeline and self-healing status. Returns structured state when actionable. Spawned by /nx-cloud-ci-monitor command to monitor CI Attempt status.
mode: subagent
---
# CI Watcher Subagent
You are a CI monitoring subagent responsible for polling Nx Cloud CI Attempt status and self-healing state. You report status back to the main agent - you do NOT make apply/reject decisions.
## Your Responsibilities
1. Poll CI status using the `ci_information` MCP tool
2. Implement exponential backoff between polls
3. Return structured state when an actionable condition is reached
4. Track iteration count and elapsed time
5. Output status updates based on verbosity level
## Input Parameters (from Main Agent)
The main agent may provide these optional parameters in the prompt:
| Parameter | Description |
| ------------------- | -------------------------------------------------------- |
| `branch` | Branch to monitor (auto-detected if not provided) |
| `expectedCommitSha` | Commit SHA that should trigger a new CI Attempt |
| `previousCipeUrl` | CI Attempt URL before the action (to detect change) |
| `subagentTimeout` | Polling timeout in minutes (default: 60) |
| `verbosity` | Output level: minimal, medium, verbose (default: medium) |
When `expectedCommitSha` or `previousCipeUrl` is provided, you must detect whether a new CI Attempt has spawned.
## MCP Tool Reference
### `ci_information`
**Input:**
```json
{
"branch": "string (optional, defaults to current git branch)",
"select": "string (optional, comma-separated field names)",
"pageToken": "number (optional, 0-based pagination for long strings)"
}
```
**Output:**
```json
{
"cipeStatus": "NOT_STARTED | IN_PROGRESS | SUCCEEDED | FAILED | CANCELED | TIMED_OUT",
"cipeUrl": "string",
"branch": "string",
"commitSha": "string | null",
"failedTaskIds": "string[]",
"verifiedTaskIds": "string[]",
"selfHealingEnabled": "boolean",
"selfHealingStatus": "NOT_STARTED | IN_PROGRESS | COMPLETED | FAILED | NOT_EXECUTABLE | null",
"verificationStatus": "NOT_STARTED | IN_PROGRESS | COMPLETED | FAILED | NOT_EXECUTABLE | null",
"userAction": "NONE | APPLIED | REJECTED | APPLIED_LOCALLY | APPLIED_AUTOMATICALLY | null",
"failureClassification": "string | null",
"taskOutputSummary": "string | null",
"suggestedFixReasoning": "string | null",
"suggestedFixDescription": "string | null",
"suggestedFix": "string | null",
"shortLink": "string | null",
"couldAutoApplyTasks": "boolean | null",
"confidence": "number | null",
"confidenceReasoning": "string | null"
}
```
**Select Parameter:**
| Usage | Returns |
| --------------- | ----------------------------------------------------------- |
| No `select` | Formatted overview (truncated, not recommended for polling) |
| Single field | Raw value with pagination for long strings |
| Multiple fields | Object with requested field values |
**Field Sets for Efficient Polling:**
```yaml
WAIT_FIELDS:
'cipeUrl,commitSha,cipeStatus'
# Minimal fields for detecting new CI Attempt
LIGHT_FIELDS:
'cipeStatus,cipeUrl,branch,commitSha,selfHealingStatus,verificationStatus,userAction,failedTaskIds,verifiedTaskIds,selfHealingEnabled,failureClassification,couldAutoApplyTasks,shortLink,confidence,confidenceReasoning'
# Status fields for determining actionable state
HEAVY_FIELDS:
'taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription'
# Large content fields - fetch only when returning to main agent
```
## Initial Wait
Before first poll, wait based on context:
- **Fresh start (no expected CIPE):** Wait 60 seconds to allow CI to start
- **Expecting new CIPE:** Wait 30 seconds (action already triggered)
**IMPORTANT:** Always run sleep in foreground, NOT as background command.
```bash
sleep 60 # or 30 if expecting new CIPE (FOREGROUND, not background)
```
## Two-Phase Operation
The subagent operates in one of two modes depending on input:
### Mode 1: Fresh Start (no `expectedCommitSha` or `previousCipeUrl`)
Normal polling - process whatever CIPE is returned by `ci_information`.
### Mode 2: Wait-for-New-CIPE (when `expectedCommitSha` or `previousCipeUrl` provided)
**CRITICAL**: When expecting a new CIPE, the subagent must **completely ignore** the old/stale CIPE. Do NOT process its status, do NOT return actionable states based on it.
#### Phase A: Wait Mode
1. Start a **new-CIPE timeout** timer (default: 30 minutes)
2. On each poll of `ci_information`:
- Check if CIPE is NEW:
- `cipeUrl` differs from `previousCipeUrl`**new CIPE detected**
- `commitSha` matches `expectedCommitSha`**correct CIPE detected**
- If still OLD CIPE: **ignore all status fields**, just wait and poll again
- Do NOT return `fix_available`, `ci_success`, etc. based on old CIPE!
3. Output wait status (see below)
4. If timeout (30 min) reached → return `no_new_cipe`
#### Phase B: Normal Polling (after new CIPE detected)
Once new CIPE is detected:
1. Clear the new-CIPE timeout
2. Switch to normal polling mode
3. Process the NEW CIPE's status normally
4. Return when actionable state reached
### Wait Mode Output
While in wait mode, output clearly that you're waiting (not processing):
```
[CI Monitor] ═══════════════════════════════════════════════════════
[CI Monitor] WAIT MODE - Expecting new CI Attempt
[CI Monitor] Expected SHA: <expectedCommitSha>
[CI Monitor] Previous CI Attempt: <previousCipeUrl>
[CI Monitor] ═══════════════════════════════════════════════════════
[CI Monitor] Polling... (elapsed: 0m 30s)
[CI Monitor] Still seeing previous CI Attempt (ignoring): <oldCipeUrl>
[CI Monitor] Polling... (elapsed: 1m 30s)
[CI Monitor] Still seeing previous CI Attempt (ignoring): <oldCipeUrl>
[CI Monitor] Polling... (elapsed: 2m 30s)
[CI Monitor] ✓ New CI Attempt detected! URL: <newCipeUrl>, SHA: <newCommitSha>
[CI Monitor] Switching to normal polling mode...
```
### Why This Matters (Context Preservation)
**The problem**: Stale CIPE data can be very large:
- `taskOutputSummary`: potentially thousands of characters of build/test output
- `suggestedFix`: entire patch files
- `suggestedFixReasoning`: detailed explanation
If subagent returns stale CIPE data to main agent, it **pollutes main agent's context** with useless information (we already processed that CIPE). This wastes valuable context window.
**Without wait mode:**
1. Poll `ci_information` → get old CIPE with huge data
2. Return to main agent with all that stale data
3. Main agent's context gets polluted with useless info
4. Main agent has to process/ignore it anyway
**With wait mode:**
1. Poll `ci_information` → get old CIPE → **ignore it, don't return**
2. Keep waiting internally (stale data stays in subagent)
3. New CIPE appears → switch to normal mode
4. Return to main agent with only the NEW, relevant CIPE data
## Polling Loop
### Subagent State Management
Maintain internal accumulated state across polls:
```
accumulated_state = {}
```
### Call `ci_information` MCP Tool
**Wait Mode (expecting new CI Attempt):**
```
ci_information({
branch: "<branch_name>",
select: "cipeUrl,commitSha,cipeStatus"
})
```
Only fetch minimal fields needed to detect CI Attempt change. Do NOT fetch heavy fields - stale data wastes context.
**Normal Mode (processing CI Attempt):**
```
ci_information({
branch: "<branch_name>",
select: "cipeStatus,cipeUrl,branch,commitSha,selfHealingStatus,verificationStatus,userAction,failedTaskIds,verifiedTaskIds,selfHealingEnabled,failureClassification,couldAutoApplyTasks,shortLink,confidence,confidenceReasoning"
})
```
Merge response into `accumulated_state` after each poll.
### Analyze Response
**If in Wait Mode** (expecting new CIPE):
1. Check if CIPE is new (see Two-Phase Operation above)
2. If old CIPE → **ignore status**, output wait message, poll again
3. If new CIPE → switch to normal mode, continue below
**If in Normal Mode**:
Based on the response, decide whether to **keep polling** or **return to main agent**.
### Keep Polling When
Continue polling (with backoff) if ANY of these conditions are true:
| Condition | Reason |
| --------------------------------------- | ---------------------------------------- |
| `cipeStatus == 'IN_PROGRESS'` | CI still running |
| `cipeStatus == 'NOT_STARTED'` | CI hasn't started yet |
| `selfHealingStatus == 'IN_PROGRESS'` | Self-healing agent working |
| `selfHealingStatus == 'NOT_STARTED'` | Self-healing not started yet |
| `failureClassification == 'FLAKY_TASK'` | Auto-rerun in progress |
| `userAction == 'APPLIED_AUTOMATICALLY'` | New CI Attempt spawning after auto-apply |
When `couldAutoApplyTasks == true`:
- `verificationStatus` = `NOT_STARTED`, `IN_PROGRESS` → keep polling (verification still in progress)
- `verificationStatus` = `COMPLETED` → return `fix_auto_applying` (auto-apply will happen, main agent spawns wait mode subagent)
- `verificationStatus` = `FAILED`, `NOT_EXECUTABLE` → return `fix_available` (auto-apply won't happen, needs manual action)
### Exponential Backoff
Between polls, wait with exponential backoff:
| Poll Attempt | Wait Time |
| ------------ | ----------------- |
| 1st | 60 seconds |
| 2nd | 90 seconds |
| 3rd+ | 120 seconds (cap) |
Reset to 60 seconds when state changes significantly.
**IMPORTANT:** Run sleep in foreground (NOT as background command). Background sleep causes "What should Claude do?" prompts when completed.
```bash
# Example backoff - run in FOREGROUND
sleep 60 # First wait
sleep 90 # Second wait
sleep 120 # Third and subsequent waits (capped)
```
### Fetch Heavy Fields on Actionable State
Before returning to main agent, fetch heavy fields if the status requires them:
| Status | Heavy Fields Needed |
| ------------------- | ------------------------------------------------------------------------------ |
| `ci_success` | None |
| `fix_auto_applying` | None |
| `fix_available` | `taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription` |
| `fix_failed` | `taskOutputSummary` |
| `no_fix` | `taskOutputSummary` |
| `environment_issue` | None |
| `no_new_cipe` | None |
| `polling_timeout` | None |
| `cipe_canceled` | None |
| `cipe_timed_out` | None |
```
# Example: fetching heavy fields for fix_available
ci_information({
branch: "<branch_name>",
select: "taskOutputSummary,suggestedFix,suggestedFixReasoning,suggestedFixDescription"
})
```
Merge response into `accumulated_state`, then return merged state to main agent.
**Pagination:** Heavy string fields return first page only. If `hasMore` indicated, include in return format so main agent knows more content available.
### Return to Main Agent When
Return immediately with structured state if ANY of these conditions are true:
| Status | Condition |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ci_success` | `cipeStatus == 'SUCCEEDED'` |
| `fix_auto_applying` | `selfHealingStatus == 'COMPLETED'` AND `couldAutoApplyTasks == true` AND `verificationStatus == 'COMPLETED'` |
| `fix_available` | `selfHealingStatus == 'COMPLETED'` AND `suggestedFix != null` AND (`couldAutoApplyTasks != true` OR `verificationStatus` in (`FAILED`, `NOT_EXECUTABLE`)) |
| `fix_failed` | `selfHealingStatus == 'FAILED'` |
| `environment_issue` | `failureClassification == 'ENVIRONMENT_STATE'` |
| `no_fix` | `cipeStatus == 'FAILED'` AND (`selfHealingEnabled == false` OR `selfHealingStatus == 'NOT_EXECUTABLE'`) |
| `no_new_cipe` | `expectedCommitSha` or `previousCipeUrl` provided, but no new CI Attempt detected after 30 min |
| `polling_timeout` | Subagent has been polling for > configured timeout (default 60 min) |
| `cipe_canceled` | `cipeStatus == 'CANCELED'` |
| `cipe_timed_out` | `cipeStatus == 'TIMED_OUT'` |
## Subagent Timeout
Track elapsed time. If you have been polling for more than **60 minutes** (configurable via main agent), return with `status: polling_timeout`.
## Return Format
When returning to the main agent, provide a structured response with accumulated state:
```
## CI Monitor Result
**Status:** <status>
**Iterations:** <count>
**Elapsed:** <minutes>m <seconds>s
### CI Attempt Details
- **Status:** <cipeStatus>
- **URL:** <cipeUrl>
- **Branch:** <branch>
- **Commit:** <commitSha>
- **Failed Tasks:** <failedTaskIds>
- **Verified Tasks:** <verifiedTaskIds>
### Self-Healing Details
- **Enabled:** <selfHealingEnabled>
- **Status:** <selfHealingStatus>
- **Verification:** <verificationStatus>
- **User Action:** <userAction>
- **Classification:** <failureClassification>
- **Confidence:** <confidence>
- **Confidence Reasoning:** <confidenceReasoning>
### Fix Information (if available)
- **Short Link:** <shortLink>
- **Description:** <suggestedFixDescription>
- **Reasoning:** <suggestedFixReasoning>
### Task Output Summary (first page)
<taskOutputSummary>
[MORE_CONTENT_AVAILABLE: taskOutputSummary, pageToken: 1]
### Suggested Fix (first page)
<suggestedFix>
[MORE_CONTENT_AVAILABLE: suggestedFix, pageToken: 1]
```
### Pagination Indicators
When a heavy field has more content available, append indicator:
```
[MORE_CONTENT_AVAILABLE: <fieldName>, pageToken: <nextPage>]
```
Main agent can fetch additional pages if needed using:
```
ci_information({ select: "<fieldName>", pageToken: <nextPage> })
```
Fields that may have pagination:
- `taskOutputSummary` (reverse pagination - page 0 = most recent)
- `suggestedFix` (forward pagination - page 0 = start)
- `suggestedFixReasoning`
### Return Format for `no_new_cipe`
When returning with `status: no_new_cipe`, include additional context:
```
## CI Monitor Result
**Status:** no_new_cipe
**Iterations:** <count>
**Elapsed:** <minutes>m <seconds>s
### Expected CI Attempt Not Found
- **Expected Commit SHA:** <expectedCommitSha>
- **Previous CI Attempt URL:** <previousCipeUrl>
- **Last Seen CI Attempt URL:** <cipeUrl>
- **Last Seen Commit SHA:** <commitSha>
- **New CI Attempt Timeout:** 30 minutes (exceeded)
### Likely Cause
CI workflow failed before Nx tasks could run (e.g., install step, checkout, auth).
Check your CI provider logs for the commit <expectedCommitSha>.
### Last Known CI Attempt State
- **Status:** <cipeStatus>
- **Branch:** <branch>
```
## Status Reporting (Verbosity-Controlled)
Output is controlled by the `verbosity` parameter from the main agent:
| Level | What to Output |
| --------- | ----------------------------------------------------------------- |
| `minimal` | No intermediate output. Only return final result when actionable. |
| `medium` | Output only on significant state changes (not every poll). |
| `verbose` | Output detailed phase information after every poll. |
### Minimal Verbosity
No output during polling. Poll silently and return when done.
### Medium Verbosity (Default)
Output **only when state changes significantly** to save context tokens:
- `cipeStatus` changes (e.g., IN_PROGRESS → FAILED)
- `selfHealingStatus` changes (e.g., IN_PROGRESS → COMPLETED)
- New CI Attempt detected (in wait mode)
Format: single line, no decorators:
```
[CI Monitor] CI: FAILED | Self-Healing: IN_PROGRESS | Elapsed: 4m
```
### Verbose Verbosity
Output detailed phase box after every poll:
```
[CI Monitor] ─────────────────────────────────────────────────────
[CI Monitor] Iteration <N> | Elapsed: <X>m <Y>s
[CI Monitor]
[CI Monitor] CI Status: <cipeStatus>
[CI Monitor] Self-Healing: <selfHealingStatus>
[CI Monitor] Verification: <verificationStatus>
[CI Monitor] Classification: <failureClassification>
[CI Monitor]
[CI Monitor] → <human-readable phase description>
[CI Monitor] ─────────────────────────────────────────────────────
```
### Phase Descriptions (for verbose output)
| Status Combo | Description |
| ----------------------------------------------------------------------------------------- | ------------------------------------------- |
| `cipeStatus: IN_PROGRESS` | "CI running..." |
| `cipeStatus: NOT_STARTED` | "Waiting for CI to start..." |
| `cipeStatus: FAILED` + `selfHealingStatus: NOT_STARTED` | "CI failed. Self-healing starting..." |
| `cipeStatus: FAILED` + `selfHealingStatus: IN_PROGRESS` | "CI failed. Self-healing generating fix..." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: IN_PROGRESS` | "Fix generated! Verification running..." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: COMPLETED` | "Fix ready! Verified successfully." |
| `cipeStatus: FAILED` + `selfHealingStatus: COMPLETED` + `verificationStatus: FAILED` | "Fix generated but verification failed." |
| `cipeStatus: FAILED` + `selfHealingStatus: FAILED` | "Self-healing could not generate a fix." |
| `cipeStatus: SUCCEEDED` | "CI passed!" |
## Important Notes
- You do NOT make apply/reject decisions - that's the main agent's job
- You do NOT perform git operations
- You only poll and report state
- Respect the `verbosity` parameter for output (default: medium)
- If `ci_information` returns an error, wait and retry (count as failed poll)
- Track consecutive failures - if 5 consecutive failures, return with `status: error`
- When expecting new CI Attempt, track the 30-minute new-CI-Attempt timeout separately from the main polling timeout
-437
View File
@@ -1,437 +0,0 @@
---
description: Monitor Nx Cloud CI pipeline and handle self-healing fixes automatically. Checks for Nx Cloud connection before starting.
argument-hint: '[instructions] [--max-cycles N] [--timeout MINUTES] [--verbosity minimal|medium|verbose] [--branch BRANCH] [--fresh] [--auto-fix-workflow] [--new-cipe-timeout MINUTES]'
---
# CI Monitor Command
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.
## Context
- **Current Branch:** !`git branch --show-current`
- **Current Commit:** !`git rev-parse --short HEAD`
- **Remote Status:** !`git status -sb | head -1`
## User Instructions
$ARGUMENTS
**Important:** If user provides specific instructions, respect them over default behaviors described below.
## Configuration Defaults
| Setting | Default | Description |
| ------------------------- | ------------- | ------------------------------------------------------------------- |
| `--max-cycles` | 10 | Maximum CIPE cycles before timeout |
| `--timeout` | 120 | Maximum duration in minutes |
| `--verbosity` | medium | Output level: minimal, medium, verbose |
| `--branch` | (auto-detect) | Branch to monitor |
| `--subagent-timeout` | 60 | Subagent polling timeout in minutes |
| `--fresh` | false | Ignore previous context, start fresh |
| `--auto-fix-workflow` | false | Attempt common fixes for pre-CIPE failures (e.g., lockfile updates) |
| `--new-cipe-timeout` | 10 | Minutes to wait for new CIPE after action |
| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |
Parse any overrides from `$ARGUMENTS` and merge with defaults.
## Nx Cloud Connection Check
**CRITICAL**: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
### Step 0: Verify Nx Cloud Connection
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
## 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`
## 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.
| Status | Default 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. |
### Fix Available Decision Logic
When subagent returns `fix_available`, main agent compares `failedTaskIds` vs `verifiedTaskIds`:
#### Step 1: Categorize Tasks
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
#### Step 2: Determine Path
| Condition | Path |
| --------------------------------------- | ---------------------------------------- |
| No unverified tasks (all verified) | Apply via MCP |
| Unverified tasks exist, but ALL are e2e | Apply via MCP (treat as verified enough) |
| Verifiable tasks exist | Local verification flow |
#### Step 3a: Apply via MCP (fully/e2e-only verified)
- Call `update_self_healing_fix({ shortLink, action: "APPLY" })`
- Record `last_cipe_url`, spawn subagent in wait mode
#### Step 3b: Local Verification Flow
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:**
| Result | Action |
| ------------------------- | ---------------------------- |
| ALL verifiable tasks pass | Apply via MCP |
| ANY verifiable task fails | Apply-locally + enhance flow |
4. **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
5. **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)
#### Commit Message Format
```bash
git commit -m "fix(<projects>): <brief description>
Failed tasks: <taskId1>, <taskId2>
Local verification: 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
### 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.
### Apply vs Reject vs Apply Locally
- **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.
### 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
### 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
### 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
### No-New-CIPE Handling
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
## Exit Conditions
Exit the monitoring loop when ANY of these conditions are met:
| Condition | Exit Type |
| ------------------------------------------- | ---------------- |
| CI passes (`cipeStatus == 'SUCCEEDED'`) | Success |
| Max CIPE cycles reached | Timeout |
| Max duration reached | Timeout |
| 3 consecutive no-progress iterations | Circuit breaker |
| No fix available and local fix not possible | Failure |
| No new CIPE and auto-fix not configured | Pre-CIPE failure |
| User cancels | Cancelled |
## Main Loop
### Step 1: Initialize Tracking
```
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
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>"
)
```
### Step 3: Handle Subagent Response
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
### Step 3a: Track State for New-CIPE Detection
After actions that should trigger a new CIPE, record state before looping:
| Action | What to Track | Subagent 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.
### Step 4: Progress Tracking
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`
## Status Reporting
Based on verbosity level:
| Level | What 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 |
## User Instruction Examples
Users can override default behaviors:
| Instruction | Effect |
| ------------------------------------------------ | --------------------------------------------- |
| "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) |
## Error Handling
| Error | Action |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Git rebase conflict | Report to user, exit |
| `nx apply-locally` fails | Report to user, attempt manual patch or exit |
| MCP tool error | Retry once, if fails report to user |
| Subagent spawn failure | Retry once, if fails exit with error |
| No new CIPE detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |
| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |
## Example Session
### Example 1: Normal Flow with Self-Healing (medium verbosity)
```
[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
```
### Example 2: Pre-CI Failure (medium verbosity)
```
[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
```
-437
View File
@@ -1,437 +0,0 @@
---
name: ci-monitor
description: Monitor Nx Cloud CI pipeline and handle self-healing fixes automatically. Checks for Nx Cloud connection before starting.
---
# CI Monitor Command
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.
## Context
- **Current Branch:** !`git branch --show-current`
- **Current Commit:** !`git rev-parse --short HEAD`
- **Remote Status:** !`git status -sb | head -1`
## User Instructions
$ARGUMENTS
**Important:** If user provides specific instructions, respect them over default behaviors described below.
## Configuration Defaults
| Setting | Default | Description |
| ------------------------- | ------------- | ------------------------------------------------------------------- |
| `--max-cycles` | 10 | Maximum CIPE cycles before timeout |
| `--timeout` | 120 | Maximum duration in minutes |
| `--verbosity` | medium | Output level: minimal, medium, verbose |
| `--branch` | (auto-detect) | Branch to monitor |
| `--subagent-timeout` | 60 | Subagent polling timeout in minutes |
| `--fresh` | false | Ignore previous context, start fresh |
| `--auto-fix-workflow` | false | Attempt common fixes for pre-CIPE failures (e.g., lockfile updates) |
| `--new-cipe-timeout` | 10 | Minutes to wait for new CIPE after action |
| `--local-verify-attempts` | 3 | Max local verification + enhance cycles before pushing to CI |
Parse any overrides from `$ARGUMENTS` and merge with defaults.
## Nx Cloud Connection Check
**CRITICAL**: Before starting the monitoring loop, verify the workspace is connected to Nx Cloud.
### Step 0: Verify Nx Cloud Connection
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
## 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`
## 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.
| Status | Default 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. |
### Fix Available Decision Logic
When subagent returns `fix_available`, main agent compares `failedTaskIds` vs `verifiedTaskIds`:
#### Step 1: Categorize Tasks
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
#### Step 2: Determine Path
| Condition | Path |
| --------------------------------------- | ---------------------------------------- |
| No unverified tasks (all verified) | Apply via MCP |
| Unverified tasks exist, but ALL are e2e | Apply via MCP (treat as verified enough) |
| Verifiable tasks exist | Local verification flow |
#### Step 3a: Apply via MCP (fully/e2e-only verified)
- Call `update_self_healing_fix({ shortLink, action: "APPLY" })`
- Record `last_cipe_url`, spawn subagent in wait mode
#### Step 3b: Local Verification Flow
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:**
| Result | Action |
| ------------------------- | ---------------------------- |
| ALL verifiable tasks pass | Apply via MCP |
| ANY verifiable task fails | Apply-locally + enhance flow |
4. **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
5. **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)
#### Commit Message Format
```bash
git commit -m "fix(<projects>): <brief description>
Failed tasks: <taskId1>, <taskId2>
Local verification: 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
### 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.
### Apply vs Reject vs Apply Locally
- **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.
### 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
### 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
### 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
### No-New-CIPE Handling
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
## Exit Conditions
Exit the monitoring loop when ANY of these conditions are met:
| Condition | Exit Type |
| ------------------------------------------- | ---------------- |
| CI passes (`cipeStatus == 'SUCCEEDED'`) | Success |
| Max CIPE cycles reached | Timeout |
| Max duration reached | Timeout |
| 3 consecutive no-progress iterations | Circuit breaker |
| No fix available and local fix not possible | Failure |
| No new CIPE and auto-fix not configured | Pre-CIPE failure |
| User cancels | Cancelled |
## Main Loop
### Step 1: Initialize Tracking
```
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
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>"
)
```
### Step 3: Handle Subagent Response
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
### Step 3a: Track State for New-CIPE Detection
After actions that should trigger a new CIPE, record state before looping:
| Action | What to Track | Subagent 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.
### Step 4: Progress Tracking
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`
## Status Reporting
Based on verbosity level:
| Level | What 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 |
## User Instruction Examples
Users can override default behaviors:
| Instruction | Effect |
| ------------------------------------------------ | --------------------------------------------- |
| "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) |
## Error Handling
| Error | Action |
| ------------------------ | ------------------------------------------------------------------------------------- |
| Git rebase conflict | Report to user, exit |
| `nx apply-locally` fails | Report to user, attempt manual patch or exit |
| MCP tool error | Retry once, if fails report to user |
| Subagent spawn failure | Retry once, if fails exit with error |
| No new CIPE detected | If `--auto-fix-workflow`, try lockfile update; otherwise report to user with guidance |
| Lockfile auto-fix fails | Report to user, exit with guidance to check CI logs |
## Example Session
### Example 1: Normal Flow with Self-Healing (medium verbosity)
```
[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
```
### Example 2: Pre-CI Failure (medium verbosity)
```
[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
```
-228
View File
@@ -1,228 +0,0 @@
---
name: nx-generate
description: Generate code using nx generators. USE WHEN scaffolding code or transforming existing code - for example creating libraries or applications, or anything else that is boilerplate code or automates repetitive tasks. ALWAYS use this first when generating code with Nx instead of calling MCP tools or running nx generate immediately.
---
# Run Nx Generator
Nx generators are powerful tools that scaffold projects, make automated code migrations or automate repetitive tasks in a monorepo. They ensure consistency across the codebase and reduce boilerplate work.
This skill applies when the user wants to:
- Create new projects like libraries or applications
- Scaffold features or boilerplate code
- Run workspace-specific or custom generators
- Do anything else that an nx generator exists for
## Generator Discovery Flow
### Step 1: List Available Generators
Use the Nx CLI to discover available generators:
- List all generators for a plugin: `npx nx list @nx/react`
- View available plugins: `npx nx list`
This includes:
- Plugin generators (e.g., `@nx/react:library`, `@nx/js:library`)
- Local workspace generators (defined in the repo's own plugins)
### Step 2: Match Generator to User Request
Based on the user's request, identify which generator(s) could fulfill their needs. Consider:
- What artifact type they want to create (library, application, etc.)
- Which framework or technology stack is relevant
- Whether they mentioned specific generator names
**IMPORTANT**: When both a local workspace generator and an external plugin generator could satisfy the request, **always prefer the local workspace generator**. Local generators are customized for the specific repo's patterns and conventions.
It's possible that the user request is something that no Nx generator exists for whatsoever. In this case, you can stop using this skill and try to help the user another way. HOWEVER, the burden of proof for this is high. Before aborting, carefully consider each and every generator that's available. Look into details for any that could be related in any way before making this decision.
## Pre-Execution Checklist
Before running any generator, complete these steps:
### 1. Fetch Generator Schema
Use the `--help` flag to understand all available options:
```bash
npx nx g @nx/react:library --help
```
Pay attention to:
- Required options that must be provided
- Optional options that may be relevant to the user's request
- Default values that might need to be overridden
### 2. Read Generator Source Code
Understanding what the generator actually does helps you:
- Know what files will be created/modified
- Understand any side effects (updating configs, installing deps, etc.)
- Identify options that might not be obvious from the schema
To find generator source code:
- For plugin generators: Use `node -e "console.log(require.resolve('@nx/<plugin>/generators.json'));"` to find the generators.json, then locate the source from there
- If that fails, read directly from `node_modules/<plugin>/generators.json`
- For local generators: They are typically in `tools/generators/` or a local plugin directory. You can search the repo for the generator name to find it.
### 2.5 Reevaluate if the generator is right
Once you have built up an understanding of what the selected generator does, reconsider: Is this the right generator to service the user request?
If not, it's okay to go back to the Generator Discovery Flow and select a different generator before proceeding. If you do, make sure to go through the entire pre-execution checklist once more.
### 3. Understand Repo Context
Before generating, examine the target area of the codebase:
- Look at similar existing artifacts (other libraries, applications, etc.)
- Identify patterns and conventions used in the repo
- Note naming conventions, file structures, and configuration patterns
- Try to match these patterns when configuring the generator
For example, if similar libraries are using a specific test runner, build tool or linter, try to match that if possible.
If projects or other artifacts are organized with a specific naming convention, try to match it.
### 4. Validate Required Options
Ensure all required options have values:
- Map the user's request to generator options
- Infer values from context where possible
- Ask the user for any critical missing information
## Execution
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally.
Many generators will behave differently based on where they are executed. For example, first-party nx library generators use the cwd to determine the directory that the library should be placed in. This is highly important.
### Consider Dry-Run (Optional)
Running with `--dry-run` first is strongly encouraged but not mandatory. Use your judgment:
- For complex generators or unfamiliar territory: do a dry-run first
- For simple, well-understood generators: may proceed directly
- Dry-run shows file names and created/deleted/modified markers, but not content
- There are cases where a generator does not support dry-run (for example if it had to install an npm package) - in that case --dry-run might fail. Don't be discouraged but simply move on to running the generator for real and iterating from there.
### Running the Generator
Execute the generator with:
```bash
nx generate <generator-name> <options> --no-interactive
```
**CRITICAL**: Always include `--no-interactive` to prevent prompts that would hang the execution.
Example:
```bash
nx generate @nx/react:library --name=my-utils --no-interactive
```
### Handling Generator Failures
If the generator fails:
1. **Diagnose the error** - Read the error message carefully
2. **Identify the cause** - Missing options, invalid values, conflicts, etc.
3. **Attempt automatic fix** - Adjust options or resolve conflicts
4. **Retry** - Run the generator again with corrected options
Common failure reasons:
- Missing required options
- Invalid option values
- Conflicting with existing files
- Missing dependencies
- Generator doesn't support certain flag combinations
## Post-Generation
### 1. Modify Generated Code (If Needed)
Generators provide a starting point, but the output may need adjustment to match the user's specific requirements:
- Add or modify functionality as requested
- Adjust imports, exports, or configurations
- Integrate with existing code patterns in the repo
### 2. Format Code
Run formatting on all generated/modified files:
```bash
nx format --fix
```
Languages other than javascript/typescript might need other formatting invocations too.
### 3. Run Verification
Verify that the generated code works correctly. What this looks like will vary depending on the type of generator and the targets available.
If the generator created a new project, run its targets directly
Use your best judgement to determine what needs to be verified.
Example:
```bash
nx lint <new-project>
nx test <new-project>
nx build <new-project>
```
### 4. Handle Verification Failures
When verification fails:
**If scope is manageable** (a few lint errors, minor type issues):
- Fix the issues
- Re-run verification to confirm
**If issues are extensive** (many errors, complex problems):
- Attempt simple, obvious fixes first
- If still failing, escalate to the user with:
- Description of what was generated
- What verification is failing
- What you've attempted to fix
- Remaining issues that need user input
## Error Handling
### Generator Failures
- Check the error message for specific causes
- Verify all required options are provided
- Check for conflicts with existing files
- Ensure the generator name and options are correct
### Missing Options
- Consult the generator schema for required fields
- Infer values from context when reasonable
- Ask the user for values that cannot be inferred
## Key Principles
1. **Local generators first** - Always prefer workspace/local generators over external plugin generators when both could work
2. **Understand before running** - Read both the schema AND the source code to fully understand what will happen
3. **No prompts** - Always use `--no-interactive` to prevent hanging
4. **Generators are starting points** - Modify the output as needed to fully satisfy the user's requirements
5. **Verify changes work** - Don't just generate; ensure the code builds, lints, and tests pass
6. **Be proactive about fixes** - Don't just report errors; attempt to resolve them automatically when possible
7. **Match repo patterns** - Study existing similar code in the repo and match its conventions
-9
View File
@@ -1,9 +0,0 @@
---
name: nx-plugins
description: Find and add Nx plugins. USE WHEN user wants to discover available plugins, install a new plugin, or add support for a specific framework or technology to the workspace.
---
## Finding and Installing new plugins
- List plugins: `pnpm nx list`
- Install plugins `pnpm nx add <plugin>`. Example: `pnpm nx add @nx/react`.
-58
View File
@@ -1,58 +0,0 @@
---
name: nx-run-tasks
description: Helps with running tasks in an Nx workspace. USE WHEN the user wants to execute build, test, lint, serve, or run any other tasks defined in the workspace.
---
You can run tasks with Nx in the following way.
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Look at the package.json or lockfile to determine which package manager is in use.
For more details on any command, run it with `--help` (e.g. `nx run-many --help`, `nx affected --help`).
## Understand which tasks can be run
You can check those via `nx show project <projectname> --json`, for example `nx show project myapp --json`. It contains a `targets` section which has information about targets that can be run. You can also just look at the `package.json` scripts or `project.json` targets, but you might miss out on inferred tasks by Nx plugins.
## Run a single task
```
nx run <project>:<task>
```
where `project` is the project name defined in `package.json` or `project.json` (if present).
## Run multiple tasks
```
nx run-many -t build test lint typecheck
```
You can pass a `-p` flag to filter to specific projects, otherwise it runs on all projects. You can also use `--exclude` to exclude projects, and `--parallel` to control the number of parallel processes (default is 3).
Examples:
- `nx run-many -t test -p proj1 proj2` — test specific projects
- `nx run-many -t test --projects=*-app --exclude=excluded-app` — test projects matching a pattern
- `nx run-many -t test --projects=tag:api-*` — test projects by tag
## Run tasks for affected projects
Use `nx affected` to only run tasks on projects that have been changed and projects that depend on changed projects. This is especially useful in CI and for large workspaces.
```
nx affected -t build test lint
```
By default it compares against the base branch. You can customize this:
- `nx affected -t test --base=main --head=HEAD` — compare against a specific base and head
- `nx affected -t test --files=libs/mylib/src/index.ts` — specify changed files directly
## Useful flags
These flags work with `run`, `run-many`, and `affected`:
- `--skipNxCache` — rerun tasks even when results are cached
- `--verbose` — print additional information such as stack traces
- `--nxBail` — stop execution after the first failed task
- `--configuration=<name>` — use a specific configuration (e.g. `production`)
-186
View File
@@ -1,186 +0,0 @@
---
name: nx-workspace
description: "Explore and understand Nx workspaces. USE WHEN answering any questions about the nx workspace, the projects in it or tasks to run. EXAMPLES: 'What projects are in this workspace?', 'How is project X configured?', 'What targets can I run?', 'What's affected by my changes?', 'Which projects depend on library Y?', or any questions about Nx workspace structure, project configuration, or available tasks."
---
# Nx Workspace Exploration
This skill provides read-only exploration of Nx workspaces. Use it to understand workspace structure, project configuration, available targets, and dependencies.
Keep in mind that you might have to prefix commands with `npx`/`pnpx`/`yarn` if nx isn't installed globally. Check the lockfile to determine the package manager in use.
## Listing Projects
Use `nx show projects` to list projects in the workspace.
```bash
# List all projects
nx show projects
# Filter by pattern (glob)
nx show projects --projects "apps/*"
nx show projects --projects "shared-*"
# Filter by project type
nx show projects --type app
nx show projects --type lib
nx show projects --type e2e
# Filter by target (projects that have a specific target)
nx show projects --withTarget build
nx show projects --withTarget e2e
# Find affected projects (changed since base branch)
nx show projects --affected
nx show projects --affected --base=main
nx show projects --affected --type app
# Combine filters
nx show projects --type lib --withTarget test
nx show projects --affected --exclude="*-e2e"
# Output as JSON
nx show projects --json
```
## Project Configuration
Use `nx show project <name> --json` to get the full resolved configuration for a project.
**Important**: Do NOT read `project.json` directly - it only contains partial configuration. The `nx show project` command returns the full resolved config including inferred targets from plugins.
You can read the full project schema at `node_modules/nx/schemas/project-schema.json` to understand nx project configuration options.
```bash
# Get full project configuration
nx show project my-app --json
# Extract specific parts from the JSON
nx show project my-app --json | jq '.targets'
nx show project my-app --json | jq '.targets.build'
nx show project my-app --json | jq '.targets | keys'
# Check project metadata
nx show project my-app --json | jq '{name, root, sourceRoot, projectType, tags}'
```
## Target Information
Targets define what tasks can be run on a project.
```bash
# List all targets for a project
nx show project my-app --json | jq '.targets | keys'
# Get full target configuration
nx show project my-app --json | jq '.targets.build'
# Check target executor/command
nx show project my-app --json | jq '.targets.build.executor'
nx show project my-app --json | jq '.targets.build.command'
# View target options
nx show project my-app --json | jq '.targets.build.options'
# Check target inputs/outputs (for caching)
nx show project my-app --json | jq '.targets.build.inputs'
nx show project my-app --json | jq '.targets.build.outputs'
# Find projects with a specific target
nx show projects --withTarget serve
nx show projects --withTarget e2e
```
## Workspace Configuration
Read `nx.json` directly for workspace-level configuration.
You can read the full project schema at `node_modules/nx/schemas/nx-schema.json` to understand nx project configuration options.
```bash
# Read the full nx.json
cat nx.json
# Or use jq for specific sections
cat nx.json | jq '.targetDefaults'
cat nx.json | jq '.namedInputs'
cat nx.json | jq '.plugins'
cat nx.json | jq '.generators'
```
Key nx.json sections:
- `targetDefaults` - Default configuration applied to all targets of a given name
- `namedInputs` - Reusable input definitions for caching
- `plugins` - Nx plugins and their configuration
- ...and much more, read the schema or nx.json for details
## Affected Projects
Find projects affected by changes in the current branch.
```bash
# Affected since base branch (auto-detected)
nx show projects --affected
# Affected with explicit base
nx show projects --affected --base=main
nx show projects --affected --base=origin/main
# Affected between two commits
nx show projects --affected --base=abc123 --head=def456
# Affected apps only
nx show projects --affected --type app
# Affected excluding e2e projects
nx show projects --affected --exclude="*-e2e"
# Affected by uncommitted changes
nx show projects --affected --uncommitted
# Affected by untracked files
nx show projects --affected --untracked
```
## Common Exploration Patterns
### "What's in this workspace?"
```bash
nx show projects
nx show projects --type app
nx show projects --type lib
```
### "How do I build/test/lint project X?"
```bash
nx show project X --json | jq '.targets | keys'
nx show project X --json | jq '.targets.build'
```
### "What depends on library Y?"
```bash
# Find projects that may depend on Y by searching for imports
# (Nx doesn't have a direct "dependents" command via CLI)
grep -r "from '@myorg/Y'" --include="*.ts" --include="*.tsx" apps/ libs/
```
### "What configuration options are available?"
```bash
cat node_modules/nx/schemas/nx-schema.json | jq '.properties | keys'
cat node_modules/nx/schemas/project-schema.json | jq '.properties | keys'
```
### "Why is project X affected?"
```bash
# Check what files changed
git diff --name-only main
# See which project owns those files
nx show project X --json | jq '.root'
```
-13
View File
@@ -1,13 +0,0 @@
# Enable pre/post-install which are disabled by default. Installing peer deps which is also disabled by default
auto-install-peers=true
enable-pre-post-scripts=true
# Enable lifecycle scripts for specific packages that require them (like post-install)
enable-scripts=@napi-rs/canvas,sharp,@swc/core,@swc/cli,@swc-node/register,esbuild
# Compatibility
strict-peer-dependencies=false
lockfile-version-strict=false
# Consistency across environments
use-node-version=20.19.0
+1 -26
View File
@@ -13,18 +13,10 @@ packages/express/src/schematics/**/files/**/*.json
packages/nest/src/schematics/**/files/**/*.json
packages/react/src/schematics/**/files/**/*.json
packages/jest/src/schematics/**/files/**/*.json
packages/gradle/project-graph/build/**/*.*
packages/nx/src/plugins/js/lock-file/__fixtures__/**/*.*
packages/**/schematics/**/files/**/*.html
packages/**/generators/**/files/**/*.html
packages/nx/src/native/**/*.rs
packages/nx/src/native/browser.js
packages/nx/src/native/nx.wasi-browser.js
packages/nx/src/native/nx.wasi.cjs
packages/nx/src/native/wasi-worker-browser.mjs
packages/nx/src/native/wasi-worker.mjs
packages/nx/src/native/native-bindings.js
packages/nx/src/native/index.d.ts
packages/nx/src/native/
nx-dev/nx-dev/.next/
nx-dev/nx-dev/public/documentation
graph/client/src/assets/environment.js
@@ -42,20 +34,3 @@ graph/client/src/assets/generated-task-graphs
/dist
/.env
CODEOWNERS
/.nx/cache
.pnpm-store
/.nx/workspace-data
/.nx/workflows/dynamic-changesets.yaml
_files
_solution
# this file uses TS import attributes which the current prettier version does not support
tools/documentation/create-embeddings/src/main.mts
.nx/self-healing
# Inlined from `@yarnpkg/parser` keep as is
packages/nx/src/utils/yarn-syml/syml-grammar.js
+1 -11
View File
@@ -1,14 +1,4 @@
{
"singleQuote": true,
"endOfLine": "lf",
"trailingComma": "es5",
"plugins": ["prettier-plugin-tailwindcss"],
"overrides": [
{
"files": "*.mdoc",
"options": {
"parser": "markdown"
}
}
]
"endOfLine": "lf"
}
-10
View File
@@ -1,10 +0,0 @@
{
"include": ["apps/**/*", "libs/**/*", "packages/**/*"],
"exclude": [
"**/*.spec.*",
"**/test/**/*",
"**/__tests__/**/*",
"**/*.test.*",
"node_modules/**/*"
]
}
-2
View File
@@ -5,8 +5,6 @@ auth:
htpasswd:
file: ./htpasswd
max_body_size: 20mb
# a list of other known repositories we can talk to
uplinks:
npmjs:
-234
View File
@@ -1,234 +0,0 @@
When responding to queries about this repository:
1. Suggest relevant commands from the "Essential Commands" section when applicable
2. Highlight Nx's focus on monorepos and its key features like smart task execution, code generation, and project graph
analysis
3. Mention the plugin ecosystem and support for various frameworks when relevant
4. Emphasize the importance of running the full validation suite before committing changes
Always strive to provide accurate, helpful responses that align with the best practices and workflows described in this
file.
## Documentation Contributions
When working on Nx documentation, all documentation content lives in the `astro-docs/` folder. This is the new Astro-based documentation site built with Starlight.
**Important**: Before making any documentation changes, read the `astro-docs/README.md` file for detailed guidance on:
- Project structure and architecture
- Content types (regular docs, dynamic plugin docs, CLI docs)
- Available Markdoc tags for rich content
- Development workflow and commands
- Sidebar management
### Quick Reference
- Documentation content: `astro-docs/src/content/docs/`
- Use `.mdoc` (Markdoc) or `.mdx` format for documentation files
- Run `nx serve astro-docs` to start the local dev server
- Sidebar structure is defined in `astro-docs/sidebar.mts`
## GitHub Issue Response Mode
When responding to GitHub issues, determine your approach based on how the request is phrased:
### Plan-First Mode (Default)
Use this approach when users ask you to:
- "analyze", "investigate", "assess", "review", "examine", or "plan"
- Or when the request is ambiguous
In this mode:
1. Provide a detailed analysis of the issue
2. Create a comprehensive implementation plan
3. Break down the solution into clear steps
4. Then please post the plan as a comment on the issue
### Immediate Implementation Mode
Use this approach when users ask you to:
- "fix", "implement", "solve", "build", "create", "update", or "add"
- Or when they explicitly request immediate action
In this mode:
1. Analyze the issue quickly
2. Implement the complete solution immediately
3. Make all necessary code changes. Please make multiple commits so that the changes are easier to review.
4. Run appropriate tests and validation
5. If the tests, are not passing, please fix the issues and continue doing this up to 3 more times until the tests pass
6. Once the tests pass, push a branch and then suggest opening a PR which has a description of the changes made, and
that
it make sure that it explicitly says "Fixes #ISSUE_NUMBER" to automatically close the issue when the PR is merged.
## Avoid making changes to generated files
Files under `generated` directories are generated based on a different source file and should not be modified directly.
Find the underlying source and modify that instead.
## Essential Commands
### Code Formatting
After code changes are made, please make sure to format the files with prettier via `npx prettier -- FILE_NAME`
### Pre-push Validation
```bash
# Full validation suite - run before committing
nx prepush
```
If the prepush validation suite fails, please fix the issues before proceeding with your work. This ensures that all
code adheres to the project's standards and passes all tests. DO NOT make a new commit to fix these issues. Instead,
amend the current commit.
### Testing Changes in Other Repos
To test a locally built Nx package in another repository (e.g., to verify a fix end-to-end):
```bash
pnpm copy-built-package --package nx --repo ../path/to/test-repo
```
This builds the package and copies it into the target repo's `node_modules`. It works for all packages including native Rust code.
### Testing Changes
After code changes are made, first test the specific project where the changes were made:
```bash
nx run-many -t test,build,lint -p PROJECT_NAME
```
After verifying the individual project, validate that the changes in projects which have been affected:
```bash
# Test only affected projects (recommended for development)
nx affected -t build,test,lint
```
As the last step, run the e2e tests to fully ensure that changes are valid:
```bash
# Run affected e2e tests (recommended for development)
nx affected -t e2e-local
```
## Fixing GitHub Issues
When working on a GitHub issue, follow this systematic approach:
### 1. Get Issue Details
```bash
# Get issue details using GitHub CLI (replace ISSUE_NUMBER with actual number)
gh issue view ISSUE_NUMBER
# View multiple issues efficiently in one command
gh issue list --limit 50 --json number,title,state,labels,assignees,updatedAt,body --jq '.[] | select(.number == 123 or .number == 456 or .number == 789)'
# Or filter by specific criteria to get multiple related issues
gh issue list --label "bug" --state "open" --json number,title,body,labels --jq '.[]'
gh issue list --assignee "@me" --json number,title,body,state --jq '.[]'
```
**Tip**: Instead of running `gh issue view` multiple times, use `gh issue list` with JSON output and filtering to gather
information about multiple issues in a single command. This is much more efficient than viewing issues one at a time.
**Always provide clickable links**: When discussing GitHub issues or PRs, always include the full GitHub URL so the user
can easily open them in their browser. For example:
- Issue #12345: https://github.com/nrwl/nx/issues/12345
- PR #67890: https://github.com/nrwl/nx/pull/67890
When cloning reproduction repos, please clone within `./tmp/claude/repro-ISSUE_NUMBER`
### 2. Analyze the Plan
- Look for a plan or implementation details in the issue description
- Check comments for additional context or clarification
- Identify affected projects and components
### 3. Implement the Solution
- Follow the plan outlined in the issue
- Make focused changes that address the specific problem
- Ensure code follows existing patterns and conventions
### 4. Run Full Validation
Use the testing workflow from the "Essential Commands" section.
### 5. Submit Pull Request
- Create a descriptive PR title that references the issue
- **Always fill in the PR template** - don't leave it empty
- Include "Fixes #ISSUE_NUMBER" in the PR description
- Provide a clear summary of changes made
- Request appropriate reviewers
## Pull Request Template
**IMPORTANT**: When creating a pull request, you MUST fill in the template found in `.github/PULL_REQUEST_TEMPLATE.md`.
Do not leave the template sections empty. The template includes:
### Required Sections
1. **Current Behavior**: Describe the behavior we have today
2. **Expected Behavior**: Describe the behavior we should expect with the changes in this PR
3. **Related Issue(s)**: Link the issue being fixed so it gets closed when the PR is merged
### Template Format
```markdown
## Current Behavior
<!-- This is the behavior we have today -->
## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR -->
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is merged. -->
Fixes #ISSUE_NUMBER
```
### Guidelines
- Ensure your commit message follows the conventional commit format (use `pnpm commit`)
- Use `fix:`, `feat:`, `chore:`, etc. as appropriate types.
- Scope is **required** for all commits. Possible scopes are listed in `scripts/commitizen.js`.
- Read the submission guidelines in CONTRIBUTING.md before posting
- For complex changes, you can request a dedicated Nx release by mentioning the Nx team
- Always link the related issue using "Fixes #ISSUE_NUMBER" to automatically close it when merged
<!-- nx configuration start-->
<!-- Leave the start & end comments to automatically receive updates. -->
## General Guidelines for working with Nx
- For navigating/exploring the workspace, invoke the `nx-workspace` skill first - it has patterns for querying projects, targets, and dependencies
- When running tasks (for example build, lint, test, e2e, etc.), always prefer running the task through `nx` (i.e. `nx run`, `nx run-many`, `nx affected`) instead of using the underlying tooling directly
- Prefix nx commands with the workspace's package manager (e.g., `pnpm nx build`, `npm exec nx test`) - avoids using globally installed CLI
- You have access to the Nx MCP server and its tools, use them to help the user
- For Nx plugin best practices, check `node_modules/@nx/<plugin>/PLUGIN.md`. Not all plugins have this file - proceed without it if unavailable.
- NEVER guess CLI flags - always check nx_docs or `--help` first when unsure
## Scaffolding & Generators
- For scaffolding tasks (creating apps, libs, project structure, setup), ALWAYS invoke the `nx-generate` skill FIRST before exploring or calling MCP tools
## When to use nx_docs
- USE for: advanced config options, unfamiliar flags, migration guides, plugin configuration, edge cases
- DON'T USE for: basic generator syntax (`nx g @nx/react:app`), standard commands, things you already know
- The `nx-generate` skill handles generator discovery internally - don't call nx_docs just to look up generator syntax
<!-- nx configuration end-->
-226
View File
@@ -1,226 +0,0 @@
When responding to queries about this repository:
1. Suggest relevant commands from the "Essential Commands" section when applicable
2. Highlight Nx's focus on monorepos and its key features like smart task execution, code generation, and project graph
analysis
3. Mention the plugin ecosystem and support for various frameworks when relevant
4. Emphasize the importance of running the full validation suite before committing changes
Always strive to provide accurate, helpful responses that align with the best practices and workflows described in this
file.
## Documentation Contributions
When working on Nx documentation, all documentation content lives in the `astro-docs/` folder. This is the new Astro-based documentation site built with Starlight.
**Important**: Before making any documentation changes, read the `astro-docs/README.md` file for detailed guidance on:
- Project structure and architecture
- Content types (regular docs, dynamic plugin docs, CLI docs)
- Available Markdoc tags for rich content
- Development workflow and commands
- Sidebar management
**MANDATORY**: After editing any file in `astro-docs/src/content/`, run the `nx-docs-style-check` skill. No exceptions.
### Quick Reference
- Documentation content: `astro-docs/src/content/docs/`
- Use `.mdoc` (Markdoc) or `.mdx` format for documentation files
- Run `nx serve astro-docs` to start the local dev server
- Sidebar structure is defined in `astro-docs/sidebar.mts`
## GitHub Issue Response Mode
When responding to GitHub issues, determine your approach based on how the request is phrased:
### Plan-First Mode (Default)
Use this approach when users ask you to:
- "analyze", "investigate", "assess", "review", "examine", or "plan"
- Or when the request is ambiguous
In this mode:
1. Provide a detailed analysis of the issue
2. Create a comprehensive implementation plan
3. Break down the solution into clear steps
4. Then please post the plan as a comment on the issue
### Immediate Implementation Mode
Use this approach when users ask you to:
- "fix", "implement", "solve", "build", "create", "update", or "add"
- Or when they explicitly request immediate action
In this mode:
1. Analyze the issue quickly
2. Implement the complete solution immediately
3. Make all necessary code changes. Please make multiple commits so that the changes are easier to review.
4. Run appropriate tests and validation
5. If the tests, are not passing, please fix the issues and continue doing this up to 3 more times until the tests pass
6. Once the tests pass, push a branch and then suggest opening a PR which has a description of the changes made, and
that
it make sure that it explicitly says "Fixes #ISSUE_NUMBER" to automatically close the issue when the PR is merged.
## Avoid making changes to generated files
Files under `generated` directories are generated based on a different source file and should not be modified directly.
Find the underlying source and modify that instead.
## Essential Commands
### Code Formatting
After code changes are made, please make sure to format the files with prettier via `npx prettier -- FILE_NAME`
### Pre-push Validation
```bash
# Full validation suite - run before committing
nx prepush
```
If the prepush validation suite fails, please fix the issues before proceeding with your work. This ensures that all
code adheres to the project's standards and passes all tests. DO NOT make a new commit to fix these issues. Instead,
amend the current commit.
### Testing Changes
After code changes are made, first test the specific project where the changes were made:
```bash
nx run-many -t test,build,lint -p PROJECT_NAME
```
After verifying the individual project, validate that the changes in projects which have been affected:
```bash
# Test only affected projects (recommended for development)
nx affected -t build,test,lint
```
As the last step, run the e2e tests to fully ensure that changes are valid:
```bash
# Run affected e2e tests (recommended for development)
nx affected -t e2e-local
```
## Fixing GitHub Issues
When working on a GitHub issue, follow this systematic approach:
### 1. Get Issue Details
```bash
# Get issue details using GitHub CLI (replace ISSUE_NUMBER with actual number)
gh issue view ISSUE_NUMBER
# View multiple issues efficiently in one command
gh issue list --limit 50 --json number,title,state,labels,assignees,updatedAt,body --jq '.[] | select(.number == 123 or .number == 456 or .number == 789)'
# Or filter by specific criteria to get multiple related issues
gh issue list --label "bug" --state "open" --json number,title,body,labels --jq '.[]'
gh issue list --assignee "@me" --json number,title,body,state --jq '.[]'
```
**Tip**: Instead of running `gh issue view` multiple times, use `gh issue list` with JSON output and filtering to gather
information about multiple issues in a single command. This is much more efficient than viewing issues one at a time.
**Always provide clickable links**: When discussing GitHub issues or PRs, always include the full GitHub URL so the user
can easily open them in their browser. For example:
- Issue #12345: https://github.com/nrwl/nx/issues/12345
- PR #67890: https://github.com/nrwl/nx/pull/67890
When cloning reproduction repos, please clone within `./tmp/claude/repro-ISSUE_NUMBER`
### 2. Analyze the Plan
- Look for a plan or implementation details in the issue description
- Check comments for additional context or clarification
- Identify affected projects and components
### 3. Implement the Solution
- Follow the plan outlined in the issue
- Make focused changes that address the specific problem
- Ensure code follows existing patterns and conventions
### 4. Run Full Validation
Use the testing workflow from the "Essential Commands" section.
### 5. Submit Pull Request
- Create a descriptive PR title that references the issue
- **Always fill in the PR template** - don't leave it empty
- Include "Fixes #ISSUE_NUMBER" in the PR description
- Provide a clear summary of changes made
- Request appropriate reviewers
## Pull Request Template
**IMPORTANT**: When creating a pull request, you MUST fill in the template found in `.github/PULL_REQUEST_TEMPLATE.md`.
Do not leave the template sections empty. The template includes:
### Required Sections
1. **Current Behavior**: Describe the behavior we have today
2. **Expected Behavior**: Describe the behavior we should expect with the changes in this PR
3. **Related Issue(s)**: Link the issue being fixed so it gets closed when the PR is merged
### Template Format
```markdown
## Current Behavior
<!-- This is the behavior we have today -->
## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR -->
## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is merged. -->
Fixes #ISSUE_NUMBER
```
### Guidelines
- Ensure your commit message follows the conventional commit format (use `pnpm commit`)
- Use `fix:`, `feat:`, `chore:`, etc. as appropriate types.
- Scope is **required** for all commits. Possible scopes are listed in `scripts/commitizen.js`.
- Read the submission guidelines in CONTRIBUTING.md before posting
- For complex changes, you can request a dedicated Nx release by mentioning the Nx team
- Always link the related issue using "Fixes #ISSUE_NUMBER" to automatically close it when merged
<!-- nx configuration start-->
<!-- Leave the start & end comments to automatically receive updates. -->
## General Guidelines for working with Nx
- For navigating/exploring the workspace, invoke the `nx-workspace` skill first - it has patterns for querying projects, targets, and dependencies
- When running tasks (for example build, lint, test, e2e, etc.), always prefer running the task through `nx` (i.e. `nx run`, `nx run-many`, `nx affected`) instead of using the underlying tooling directly
- Prefix nx commands with the workspace's package manager (e.g., `pnpm nx build`, `npm exec nx test`) - avoids using globally installed CLI
- You have access to the Nx MCP server and its tools, use them to help the user
- For Nx plugin best practices, check `node_modules/@nx/<plugin>/PLUGIN.md`. Not all plugins have this file - proceed without it if unavailable.
- NEVER guess CLI flags - always check nx_docs or `--help` first when unsure
## Scaffolding & Generators
- For scaffolding tasks (creating apps, libs, project structure, setup), ALWAYS invoke the `nx-generate` skill FIRST before exploring or calling MCP tools
## When to use nx_docs
- USE for: advanced config options, unfamiliar flags, migration guides, plugin configuration, edge cases
- DON'T USE for: basic generator syntax (`nx g @nx/react:app`), standard commands, things you already know
- The `nx-generate` skill handles generator discovery internally - don't call nx_docs just to look up generator syntax
<!-- nx configuration end-->
+179 -1
View File
@@ -1,2 +1,180 @@
# Any file not covered by a rule below, will default to Jason + Victor and a few select others.
* @nrwl/nx-cli-reviewers
* @FrozenPandaz @vsavkin
/packages/**/* @FrozenPandaz @vsavkin @AgentEnder @jaysoo @JamesHenry
/e2e/**/* @FrozenPandaz @vsavkin @AgentEnder @jaysoo @JamesHenry
/scripts/**/* @FrozenPandaz @vsavkin @AgentEnder @jaysoo @JamesHenry
/tools/**/* @FrozenPandaz @vsavkin @AgentEnder @jaysoo @JamesHenry
package.json @nrwl/nx-core-reviewers
pnpm-lock.yaml @nrwl/nx-core-reviewers
# Docs Site + Graph
/docs @nrwl/nx-docs-reviewers
/docs/nx-cloud @StalkAltan @rarmatei @nrwl/nx-docs-reviewers
/graph/** @philipjfulcher @FrozenPandaz @bcabanes
/images @nrwl/nx-docs-reviewers
/nx-dev/** @nrwl/nx-docs-reviewers
/typedoc-theme @nrwl/nx-docs-reviewers
# Plugin Verticals
## Angular
/docs/generated/packages/angular/** @nrwl/nx-angular-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/angular/** @nrwl/nx-angular-reviewers @nrwl/nx-docs-reviewers
/packages/angular/** @nrwl/nx-angular-reviewers
/e2e/angular-core/** @nrwl/nx-angular-reviewers
/e2e/angular-extensions/** @nrwl/nx-angular-reviewers
/packages/angular/plugins/component-testing.ts @nrwl/nx-angular-reviewers @nrwl/nx-testing-tools-reviewers
/packages/angular/src/generators/cypress-component-configuration/** @nrwl/nx-angular-reviewers @nrwl/nx-testing-tools-reviewers
/packages/angular/src/generators/component-test/** @nrwl/nx-angular-reviewers @nrwl/nx-testing-tools-reviewers
## React
/docs/generated/packages/react/** @nrwl/nx-react-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/next/** @nrwl/nx-react-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/react/** @nrwl/nx-react-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/next/** @nrwl/nx-react-reviewers @nrwl/nx-docs-reviewers
/packages/react/** @nrwl/nx-react-reviewers
/e2e/react-core/** @nrwl/nx-react-reviewers
/e2e/react-extensions/** @nrwl/nx-react-reviewers
/packages/next/** @nrwl/nx-react-reviewers
/e2e/next/** @nrwl/nx-react-reviewers
/packages/react/plugins/component-testing/** @nrwl/nx-react-reviewers @nrwl/nx-testing-tools-reviewers
/packages/react/src/generators/cypress-component-configuration/** @nrwl/nx-react-reviewers @nrwl/nx-testing-tools-reviewers
/packages/react/src/generators/component-test/** @nrwl/nx-react-reviewers @nrwl/nx-testing-tools-reviewers
# React Native
/docs/generated/packages/detox/** @nrwl/nx-react-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/expo/** @nrwl/nx-react-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/react-native/** @nrwl/nx-react-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/react-native/** @nrwl/nx-react-reviewers @nrwl/nx-docs-reviewers
/packages/detox/** @nrwl/nx-react-reviewers
/e2e/detox/** @nrwl/nx-react-reviewers
/packages/expo/** @nrwl/nx-react-reviewers
/e2e/expo/** @nrwl/nx-react-reviewers
/packages/react-native/** @nrwl/nx-react-reviewers
/e2e/react-native/** @nrwl/nx-react-reviewers
## Node
/docs/generated/packages/node/** @nrwl/nx-node-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/nest/** @nrwl/nx-node-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/express/** @nrwl/nx-node-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/node/** @nrwl/nx-node-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/express/** @nrwl/nx-node-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/nest/** @nrwl/nx-node-reviewers @FrozenPandaz @nrwl/nx-docs-reviewers
/packages/node/** @nrwl/nx-node-reviewers
/packages/express/** @nrwl/nx-node-reviewers
/packages/nest/** @nrwl/nx-node-reviewers
/e2e/node/** @nrwl/nx-node-reviewers
## JS
/docs/generated/packages/js/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/web/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/webpack/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/esbuild/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/rollup/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/vite/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/js/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/web/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/webpack/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/esbuild/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/vite/** @nrwl/nx-js-reviewers @nrwl/nx-docs-reviewers
/packages/js/** @nrwl/nx-js-reviewers
/e2e/js/** @nrwl/nx-js-reviewers
/packages/web/** @nrwl/nx-js-reviewers
/e2e/web/** @nrwl/nx-js-reviewers
/packages/webpack/** @nrwl/nx-js-reviewers
/e2e/webpack/** @nrwl/nx-js-reviewers
/packages/esbuild/** @nrwl/nx-js-reviewers
/e2e/esbuild/** @nrwl/nx-js-reviewers
/packages/rollup/** @nrwl/nx-js-reviewers
/e2e/rollup/** @nrwl/nx-js-reviewers
/packages/vite/** @nrwl/nx-js-reviewers
/e2e/vite/** @nrwl/nx-js-reviewers
## Tools
/docs/generated/packages/cypress/** @nrwl/nx-testing-tools-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/jest/** @nrwl/nx-testing-tools-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/jest/** @nrwl/nx-testing-tools-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/cypress/** @nrwl/nx-testing-tools-reviewers @nrwl/nx-docs-reviewers
/packages/cypress/** @nrwl/nx-testing-tools-reviewers
/e2e/cypress/** @nrwl/nx-testing-tools-reviewers
/packages/jest/** @nrwl/nx-testing-tools-reviewers
/e2e/jest/** @nrwl/nx-testing-tools-reviewers
/packages/playwright/** @nrwl/nx-testing-tools-reviewers
/e2e/playwright/** @nrwl/nx-testing-tools-reviewers
# Linter
/docs/generated/packages/eslint-plugin/** @nrwl/nx-linter-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/linter/** @nrwl/nx-linter-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/linter/** @nrwl/nx-linter-reviewers @nrwl/nx-docs-reviewers
/packages/eslint-plugin/** @nrwl/nx-linter-reviewers
/packages/linter/** @nrwl/nx-linter-reviewers
/e2e/linter/** @nrwl/nx-linter-reviewers
.eslint* @nrwl/nx-linter-reviewers
# Storybook
/docs/generated/packages/storybook/** @nrwl/nx-storybook-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/storybook/** @nrwl/nx-storybook-reviewers @nrwl/nx-docs-reviewers
/packages/storybook/** @nrwl/nx-storybook-reviewers
/e2e/storybook/** @nrwl/nx-storybook-reviewers
/e2e/storybook-angular/** @nrwl/nx-storybook-reviewers
## Devkit
/docs/generated/devkit/** @nrwl/nx-devkit-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/devkit/** @nrwl/nx-devkit-reviewers @nrwl/nx-docs-reviewers
/packages/devkit/** @nrwl/nx-devkit-reviewers
/packages/devkit/index.js @FrozenPandaz @vsavkin
/packages/devkit/index.d.ts @FrozenPandaz @vsavkin
/packages/devkit/public-api.ts @FrozenPandaz @vsavkin
/packages/devkit/nx.ts @FrozenPandaz @vsavkin
/packages/devkit/src/utils/module-federation @jaysoo @Coly010
# Nx-Plugin
/docs/generated/packages/plugin/** @nrwl/nx-devkit-reviewers @nrwl/nx-docs-reviewers
/docs/shared/packages/plugin/** @nrwl/nx-devkit-reviewers @nrwl/nx-docs-reviewers
/packages/plugin/** @nrwl/nx-devkit-reviewers
/e2e/plugin/** @nrwl/nx-devkit-reviewers
## Core
/docs/generated/cli/** @nrwl/nx-core-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/nx/** @nrwl/nx-core-reviewers @nrwl/nx-docs-reviewers
/docs/generated/packages/workspace/** @nrwl/nx-core-reviewers @nrwl/nx-docs-reviewers
/packages/nx/** @nrwl/nx-core-reviewers
/packages/nx/src/adapter @nrwl/nx-core-reviewers @leosvelperez
/packages/nx/src/native @nrwl/nx-core-reviewers @nrwl/nx-native-reviewers
/packages/nx/src/plugins/js/lock-file @nrwl/nx-core-reviewers @meeroslav
/packages/nx/src/command-line/init/implementation/angular/** @nrwl/nx-angular-reviewers @nrwl/nx-core-reviewers
/e2e/nx-init/src/nx-init-angular.test.ts @nrwl/nx-angular-reviewers
/packages/nx/src/command-line/init/implementation/react/** @nrwl/nx-react-reviewers
/e2e/nx-init/src/nx-init-react.test.ts @nrwl/nx-react-reviewers
/e2e/nx-init/src/files/cra/** @nrwl/nx-react-reviewers
/e2e/nx*/** @nrwl/nx-core-reviewers
/packages/workspace/** @nrwl/nx-core-reviewers
/e2e/workspace-create/** @nrwl/nx-core-reviewers
/e2e/workspace-create-npm/** @nrwl/nx-core-reviewers
# Misc
/e2e/lerna-smoke-tests/** @vsavkin @JamesHenry
/e2e/utils/** @meeroslav @nrwl/nx-testing-tools-reviewers @vsavkin @mandarini
/community @nrwl/nx-devkit-reviewers
/CONTRIBUTING.md @FrozenPandaz @isaacplmann
/CODE_OF_CONDUCT.md @FrozenPandaz @isaacplmann
/CODEOWNERS @FrozenPandaz @AgentEnder
# Scripts
/scripts/documentation @nrwl/nx-docs-reviewers
/scripts/angular-support-upgrades @nrwl/nx-angular-reviewers
# CI
/.circleci/** @nrwl/nx-pipelines-reviewers
/.github/** @nrwl/nx-pipelines-reviewers
/.husky/** @nrwl/nx-pipelines-reviewers
/packages/workspace/src/generators/ci-workflow/** @nrwl/nx-pipelines-reviewers
# Global Files
project.json @FrozenPandaz @vsavkin
jest.config.ts @nrwl/nx-testing-tools-reviewers @FrozenPandaz
jest.preset.js @nrwl/nx-testing-tools-reviewers @FrozenPandaz
# Overrides - These are applied last, so override any matches above.
docs/generated/manifests/* @nrwl/nrwlians
docs/generated/packages-metadata.json @FrozenPandaz @jaysoo @AgentEnder @nrwl/nx-docs-reviewers
+1 -1
View File
@@ -2,7 +2,7 @@
As contributors and maintainers of the Nx project, we pledge to respect everyone who contributes by posting issues, updating documentation, submitting pull requests, providing feedback in comments, and any other activities.
Communication through any of Nx's channels (GitHub, Gitter, Discord, IRC, mailing lists, Twitter, etc.) must be constructive and never resort to personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
Communication through any of Nx's channels (GitHub, Gitter, Slack, IRC, mailing lists, Twitter, etc.) must be constructive and never resort to personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
We promise to extend courtesy and respect to everyone involved in this project regardless of gender, gender identity, sexual orientation, disability, age, race, ethnicity, religion, or level of experience. We expect anyone contributing to the Nx project to do the same.
+62 -137
View File
@@ -2,10 +2,19 @@
We would love for you to contribute to Nx! Read this document to see how to do it.
## How to Get Started Video
Watch this 5-minute video:
<a href="https://www.youtube.com/watch?v=8LCA_4qxc08" target="_blank" rel="noreferrer">
<p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/how-to-contribute.png" width="600" alt="Nx - How to contribute"></p>
</a>
## Got a Question?
We are trying to keep GitHub issues for bug reports and feature requests.
You can join our [Discord](https://go.nx.dev/community) for general questions and seeking help from others.
We are trying to keep GitHub issues for bug reports and feature requests. Using the `nrwl` tag
on [Stack Overflow](https://stackoverflow.com/questions/tagged/nrwl) is a much better place to ask general questions
about how to use Nx.
## Found an Issue?
@@ -18,25 +27,14 @@ can [submit a Pull Request](https://github.com/nrwl/nx/blob/master/CONTRIBUTING.
Source code and documentation are included in the top-level folders listed below.
- `packages` - Source code for Nx packages such as Angular, React, Web, NestJS, Next and others including generators and
executors (or builders).
- `e2e` - E2E tests for the Nx packages
- `graph` - Source code for the Nx Graph application which shows the project graph, task graph, project details, and more in the browser.
- `docs` - Markdown and configuration files for documentation including tutorials, guides for each supported platform,
and API docs.
- `nx-dev` - Source code for the Nx documentation site which displays the markdown in `docs` and more.
- `tools` - Workspace-specific tooling and plugins
- `e2e` - E2E tests.
- `packages` - Source code for Nx packages such as Angular, React, Web, NestJS, Next and others including generators and
executors (or builders).
- `scripts` - Miscellaneous scripts for project tasks such as building documentation, testing, and code formatting.
- `tmp` - Folder used by e2e tests. If you are a WebStorm user, make sure to mark this folder as excluded.
## Technologies
This repo contains a mix of different technologies, including:
- **Rust**: The core of Nx is written in Rust, which provides performance and safety.
- **TypeScript**: The primary language for Nx packages and the Nx DevKit.
- **Kotlin**: Used for the Gradle and Java plugins.
## Development Workstation Setup
If you are using `VSCode`, and provided you have [Docker](https://docker.com) installed on your machine, then you can leverage [Dev Containers](https://containers.dev) through this [VSCode extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers), to easily setup your development environment, with everything needed to contribute to Nx, already installed (namely `NodeJS`, `Yarn`, `Rust`, `Cargo`, plus some useful extensions like `Nx Console`).
@@ -51,33 +49,15 @@ The repo comes with a preconfigured `devcontainer.json` file (located in `.devco
If you open the repo in [Github Codespace](https://github.com/features/codespaces), it will also leverage this config file, to setup the codespace, with the same required tools.
> 💡 **Troubleshooting**
>
> If you are having issues when running Nx commands like `build`, `test`... related to the version of `GLIBC`,
> it probably means the version that is installed on the devcontainer, **is outdated** compare to the minimum version required by Nx tools.
>
> You can check currently installed version by running the following command, in a terminal within the container:
>
> `ldd --version`
>
> Then, try updating the base image used in [devcontainer.json](.devcontainer/devcontainer.json) and rebuild it, to see if it solved the issue.
>
> Current base image is `"mcr.microsoft.com/devcontainers/typescript-node:20-bookworm"` which is based on `Debian-12 (bookworm)`,
> which comes with `GLIBC v2.36` pre-installed (Nx tools currenlty requires `GLIBC v2.33` or higher).
## Building the Project
> 💡 Nx uses `Rust` to build native bindings for Node. Please make sure that you have Rust installed via [rustup.rs](https://rustup.rs)
> If you have `VSCode` + `Docker`, this can be automated for you, see [section](#development-workstation-setup) above
> Nx uses Rust to build native bindings for Node. Please make sure that you have Rust installed via [rustup.rs](https://rustup.rs)
> If you have VSCode + Docker, this can be automated for you, see [section](#development-workstation-setup) above
After cloning the project to your machine, to install the dependencies, run:
```bash
pnpm install
// or prefer...
pnpm install --frozen-lockfile // if you haven't changed any dependency
pnpm i
```
To build all the packages, run:
@@ -96,13 +76,13 @@ Check out [this video for a live walkthrough](https://youtu.be/Tx257WpNsxc) or f
- Run `pnpm local-registry` in Terminal 1 (keep it running)
- Run `npm adduser --registry http://localhost:4873` in Terminal 2 (real credentials are not required, you just need to
be logged in. You can use test/test/test@test.io.)
- Run `pnpm nx-release 20.0.0 --local` in Terminal 2 - you can choose any nonexistent version number here, but it's recommended to use the next major
- Run `pnpm nx-release 17.0.0 --local` in Terminal 2 - you can choose any nonexistent version number here, but it's recommended to use the next major
- Run `cd ./tmp` in Terminal 2
- Run `npx create-nx-workspace@20.0.0` in Terminal 2
- Run `npx create-nx-workspace@17.0.0` in Terminal 2
If you have problems publishing, make sure you use Node 18 and NPM 8.
**NOTE:** To use this newly published local version, you need to make a new workspace, run `nx migrate` or change all of your target packages to this new version, eg: `"nx": "^20.0.0",` and re-run `pnpm i` in your testing project.
**NOTE:** To use this newly published local version, you need to make a new workspace or change all of your target packages to this new version, eg: `"nx": "^17.0.0",` and re-run `pnpm i` in your testing project.
### Publishing for Yarn 2+ (Berry)
@@ -132,7 +112,9 @@ Yarn Berry operates slightly differently than Yarn Classic. In order to publish
- localhost
```
- Run `pnpm nx-release minor --local` in Terminal 2 to publish next minor version. The output will report the version of published packages.
- Run `pnpm nx-release --local` in Terminal 2 to publish next minor version. If this version already exists, you can
bump the minor version in `lerna.json` to toggle the next minor. The output will report the version of published
packages.
- Go to your target folder (e.g. `cd ./tmp`) in Terminal 2
- Run `yarn dlx create-nx-workspace@123.4.5` in Terminal 2 (replace `123.4.5` with the version that got published).
@@ -185,73 +167,74 @@ To build Nx on Windows, you need to use WSL.
## Documentation Contributions
We would love for you to contribute to our documentation as well! Please feel welcome to submit fixes or enhancements to
our existing documentation pages, `astro-docs` and the `nx-dev` application in this repo.
our existing documentation pages and the `nx-dev` application in this repo.
### Documentation Structure
#### Documentation Pages
Our documentation pages can be found within this repo under the `astro-docs/src/content/docs` directory.
Our documentation pages can be found within this repo under the `docs` directory.
Documentation is written in `.mdoc` (Markdoc) or `.mdx` (MDX) format and supports custom Markdoc tags for rich content
such as videos, graphs, interactive components, and more. See the `astro-docs/README.md` for a full list of available
custom tags and their usage.
The sidebar structure is defined in `astro-docs/sidebar.mts` and should be updated when adding new sections or pages
to ensure proper navigation.
#### Astro-Docs Application
Our public `nx.dev/docs` documentation site is built with [Astro](https://astro.build) and [Starlight](https://starlight.astro.build),
and can be found in the `astro-docs` directory of this repo. See [docs README for more details](./astro-docs/README.md)
The `docs/map.json` file is considered our source of truth for our site's structure, and should be updated when adding a
new page to our documentation to ensure that it is included in the documentation site. We also run automated scripts
based on this `map.json` data to safeguard against common human errors that could break our site.
#### Nx-Dev Application
The `nx-dev` directory contains a [Next.js](https://nextjs.org/) application used for blog posts and landing pages.
Our public `nx.dev` documentation site is a [Next.js](https://nextjs.org/) application, that can be found in
the `nx-dev` directory of this repo.
The documentation site is consuming the `docs/` directly by copy-ing its content while deploying, so the website is
always in sync and reflects the latest version of `docs/`.
Jump to [Running the Documentation Site Locally](#running-the-documentation-site-locally) to see how to preview your
changes while serving.
### Changing Generated API documentation
API documentation for CLI commands, executors, and generators is automatically generated during the build process from
the corresponding `schema.json` files in each package.
`.md` files documenting the API for our CLI (including executor and generator API docs) are generated via the
corresponding `schema.json` file for the given command.
The documentation is generated using content loaders in the `astro-docs` application and requires a rebuild to reflect
changes. After adjusting a `schema.json` file:
After adjusting the `schema.json` file, `.md` files for these commands can be generated by running:
1. Restart the development server with `nx serve astro-docs` to see the changes
2. Or run `nx preview astro-docs` to view the built site locally
```bash
pnpm documentation
```
This will update the corresponding contents of the `docs` directory. These are generated automatically on push (via
husky) as well.
Note that adjusting the `schema.json` files will also affect the CLI manuals and Nx Console behavior, in addition to
the generated documentation.
adjusting the docs.
### Running the Documentation Site Locally
To run the documentation site locally, run the command:
```shell
nx serve astro-docs
```
You can then access the application locally at `localhost:4321`. Changes to markdoc files should reflect automatically in the browser on save.
#### Working with Plugin Registry
To view plugin registry statistics (GitHub stars, npm downloads, etc.) during local development:
To run `nx-dev` locally, run the command:
```bash
NX_DOCS_PLUGIN_STATS=true nx serve astro-docs
npx nx serve nx-dev
```
Note: Plugin stats are disabled by default in development to improve performance.
You can then access the application locally at `localhost:4200`.
#### Troubleshooting: `JavaScript heap out of memory`
If you see an error that states: `FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory`,
you need
to [increase the max memory size of V8's old memory section](https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-megabytes):
```bash
export NODE_OPTIONS="--max-old-space-size=4096"
```
After configuring this, try to run `npx nx serve nx-dev` again.
### PR Preview
When submitting a PR, this repo will automatically generate a preview of the documentation site based on the contents
When submitting a PR, this repo will automatically generate a preview of the `nx-dev` application based on the contents
of your pull request.
Once the preview site is launched, a comment will automatically be added to your PR with the link to your PR's preview.
Once the preview site is launched, a comment will automatically be added to your PR with the link your PR's preview. To
check your docs changes, make sure to select `Preview` from the version selection box of the site.
## Submission Guidelines
@@ -332,21 +315,18 @@ The scope must be one of the following:
- express - anything Express specific
- js - anything related to @nx/js package or general js/ts support
- linter - anything Linter specific
- module-federation - anything Nx Module Federation specific
- nest - anything Nest specific
- nextjs - anything Next specific
- node - anything Node specific
- nx-cloud - anything Nx Cloud specific
- nx-cloud - anything NxCloud specific
- nx-plugin - anything Nx Plugin specific
- nx-dev - anything related to docs infrastructure
- react - anything React specific
- react-native - anything React Native specific
- release - anything related to nx release
- repo - anything related to managing the Nx repo itself
- storybook - anything Storybook specific
- testing - anything testing specific (e.g., Jest or Cypress)
- vite - anything Vite specific
- vue - anything Vue specific
- web - anything Web specific
- webpack - anything Webpack specific
- misc - misc stuff
@@ -363,7 +343,7 @@ Including the issue number that the PR relates to also helps with tracking.
```plain
feat(angular): add an option to generate lazy-loadable modules
`nx generate lib libs/mylib --lazy` provisions the mylib project in .eslintrc.json
`nx generate lib mylib --lazy` provisions the mylib project in tslint.json
Closes #157
```
@@ -373,58 +353,3 @@ Closes #157
To simplify and automate the process of committing with this format,
**Nx is a [Commitizen](https://github.com/commitizen/cz-cli) friendly repository**, just do `git add` and
execute `pnpm commit`.
##### Using the Interactive Commit Tool
Instead of `git commit`, use:
```bash
pnpm commit
```
This will launch an interactive prompt that will:
1. Ask you to select the type of change (feat, fix, docs, cleanup, chore)
2. Let you choose the appropriate scope from the predefined list
3. Guide you through writing a clear, descriptive commit message
4. Ensure your commit follows the conventional commit format
##### Available Commit Types
- **feat**: A new feature
- **fix**: A bug fix
- **docs**: Documentation only changes
- **cleanup**: A code change that neither fixes a bug nor adds a feature
- **chore**: Other changes that don't modify src or test files
##### Available Scopes
The repository includes many predefined scopes. Use the one which is most specific to the changes being committed
- **core**: anything Nx core specific
- **angular**: anything Angular specific
- **react**: anything React specific
- **nextjs**: anything Next specific
- **node**: anything Node specific
- **devkit**: devkit-related changes
- **graph**: anything graph app specific
- **testing**: anything testing specific (e.g. jest or cypress)
- **misc**: misc stuff
- **repo**: anything related to managing the repo itself
- **nx-dev**: anything related to docs infrastructure
For the complete list of available scopes, see `/scripts/commitizen.js`.
##### Example Commits
```bash
feat(core): add new project graph visualization
fix(angular): resolve build issues with standalone components
docs(misc): update contributing guidelines
chore(repo): bump dependencies
cleanup(devkit): refactor utility functions for better readability
```
#### PR releases
If you are working on a particularly complex change or feature addition, you can request a dedicated Nx release for the associated pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate.
Generated
+1069 -4163
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -1,8 +1,7 @@
[workspace]
resolver = '2'
members = [
'packages/nx',
'packages/nx'
]
[profile.release]

Some files were not shown because too many files have changed in this diff Show More