Skip to content

Comments

feat(core): add agentic mode to nx init#34418

Merged
MaxKless merged 1 commit intomasterfrom
NXA-921
Feb 17, 2026
Merged

feat(core): add agentic mode to nx init#34418
MaxKless merged 1 commit intomasterfrom
NXA-921

Conversation

@jaysoo
Copy link
Member

@jaysoo jaysoo commented Feb 12, 2026

Current Behavior

When AI agents (Claude Code, Cursor, Windsurf, etc.) run nx init, the command works but:

  • Uses interactive prompts that AI agents can't handle
  • Outputs human-readable text that AI agents must parse
  • Doesn't provide structured progress or error information

Expected Behavior

When nx init detects an AI agent (via environment variables like CLAUDE_CODE=1), it should:

  • Skip interactive prompts and use sensible defaults
  • Output structured NDJSON for progress updates, success, and errors
  • Include detailed context for AI agents to understand and fix issues

Changes

This PR adds agentic mode to nx init:

nx init Changes

  • Detect AI agents via isAiAgent() native function
  • Auto-defaults: interactive=false, nxCloud=false, auto-detect .nx installation
  • NDJSON output with type: progress|success|error
  • Error logs written to .nx/ai-errors/ with full context
  • Cursor restoration escape sequence skipped for AI agents (prevents NDJSON corruption)

Output Format

{"type":"progress","step":"starting","message":"Initializing Nx..."}
{"type":"success","nxVersion":"22.5.0","projectsDetected":1,"pluginsInstalled":["@nx/vite"]}

Or on error:

{"type":"error","message":"Failed to install","code":"INSTALL_ERROR","errorLogPath":".nx/ai-errors/nx-init-error-2025-01-15T10-30-00.log"}

Related Issue(s)

Part of NXA-921 (agentic mode initiative)

@jaysoo jaysoo requested a review from a team as a code owner February 12, 2026 04:15
@jaysoo jaysoo requested a review from FrozenPandaz February 12, 2026 04:15
@nx-cloud
Copy link
Contributor

nx-cloud bot commented Feb 12, 2026

View your CI Pipeline Execution ↗ for commit 2aa1d81

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 47m 4s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 4m 11s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-17 16:47:41 UTC

@netlify
Copy link

netlify bot commented Feb 12, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 2aa1d81
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69948f59831ad500079cf5ff
😎 Deploy Preview https://deploy-preview-34418--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Feb 12, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 2aa1d81
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69948f598ee3520008878ac5
😎 Deploy Preview https://deploy-preview-34418--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@jaysoo jaysoo force-pushed the NXA-921 branch 3 times, most recently from 6d81822 to 9357cfd Compare February 12, 2026 12:59
nx-cloud[bot]

This comment was marked as outdated.

@jaysoo jaysoo force-pushed the NXA-921 branch 7 times, most recently from 6b03e96 to fefe727 Compare February 12, 2026 17:02
@jaysoo jaysoo changed the title feat(core): add agentic mode to nx init feat(core): add agentic mode to nx init and nx connect Feb 12, 2026
Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ The fix from Nx Cloud was applied automatically

These changes fix the ESLint linting errors in the agentic mode implementation by adding periods to command descriptions in ai-output.ts. The @nx/workspace/valid-command-object rule requires all command descriptions to end with a period for consistency across the codebase.

Tip

We verified this fix by re-running nx:lint.

Suggested Fix changes
diff --git a/packages/nx/src/command-line/nx-cloud/connect/ai-output.ts b/packages/nx/src/command-line/nx-cloud/connect/ai-output.ts
index 153c8fb5c5..729460de4b 100644
--- a/packages/nx/src/command-line/nx-cloud/connect/ai-output.ts
+++ b/packages/nx/src/command-line/nx-cloud/connect/ai-output.ts
@@ -175,11 +175,11 @@ export function buildMissingVcsResult(): NeedsInputResult {
       {
         command: 'gh repo create --source=. --push',
         description:
-          'Create a GitHub repo and push (requires GitHub CLI: brew install gh)',
+          'Create a GitHub repo and push (requires GitHub CLI: brew install gh).',
       },
       {
         command: 'git remote add origin <url> && git push -u origin main',
-        description: 'Manual: Add remote and push to existing repo',
+        description: 'Manual: Add remote and push to existing repo.',
       },
     ],
     recommendedOption: 'gh repo create --source=. --push',

Revert fix via Nx Cloud  

View interactive diff ↗

🎓 Learn more about Self-Healing CI on nx.dev

writeAiOutput(
buildSuccessResult({
nxVersion: version,
projectsDetected: 1, // Simplified for Phase 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this fully implemented? or is phase 2 the NEXT_STEPS.md stuff we were talking about?

);
}

printFinalMessage({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to include this in a JSON in ai mode?

@jaysoo jaysoo changed the title feat(core): add agentic mode to nx init and nx connect feat(core): add agentic mode to nx init Feb 17, 2026
## Current Behavior
`nx init` always uses human-readable output with interactive prompts.
When run by AI agents, it doesn't provide structured output.

## Expected Behavior
When an AI agent runs `nx init`:
- Outputs NDJSON for structured parsing
- Applies sensible defaults (non-interactive, skip nx cloud)
- Returns `needs_input` with plugin selection options when plugins detected
- Returns structured success/error results with user next steps

## Related Issue(s)
Related to NXA-921
@MaxKless MaxKless merged commit 2fa93af into master Feb 17, 2026
24 checks passed
@MaxKless MaxKless deleted the NXA-921 branch February 17, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants