Skip to content

feat(misc): hint agents at nx-cloud onboard from nx connect#35520

Open
jaysoo wants to merge 14 commits intomasterfrom
NXC-4401
Open

feat(misc): hint agents at nx-cloud onboard from nx connect#35520
jaysoo wants to merge 14 commits intomasterfrom
NXC-4401

Conversation

@jaysoo
Copy link
Copy Markdown
Member

@jaysoo jaysoo commented Apr 30, 2026

Current Behavior

`nx connect` always runs the legacy browser-claim flow regardless of caller. Agents have no way to know that `nx-cloud onboard connect-workspace` is the canonical agentic entry point. CNW's preset path also forcibly overrides `--nxCloud` to `'skip'`, ignoring whatever the user passed.

Expected Behavior

When `nx connect` runs under an AI agent, emit a `needs_input` payload that points the agent at `npx nx-cloud onboard connect-workspace` (which now emits canonical NDJSON — see nrwl/ocean#11097). Humans keep the existing browser-claim flow. `--browser` forces the browser flow even under an agent. CNW respects `--nxCloud` verbatim on the preset path.

Related Issue(s)

NXC-4401

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 30, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 03c5591
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69f8de3aa68b570009fc4acf
😎 Deploy Preview https://deploy-preview-35520--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
Copy Markdown

netlify Bot commented Apr 30, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 03c5591
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69f8de3ab0f257000822391f
😎 Deploy Preview https://deploy-preview-35520--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.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Apr 30, 2026

View your CI Pipeline Execution ↗ for commit 03c5591

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 51m 16s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 17s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 23s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-04 18:53:19 UTC

…nd CNW

In agent mode (CLAUDECODE / CURSOR / etc.), `nx connect`, `nx init` with cloud opt-in, and `create-nx-workspace` end the cloud step by opening a browser. Breaks the terminal-only loop agents need.

Route cloud setup through `nx-cloud onboard connect-workspace --json` and stream NDJSON. Translator handles ocean's actual payload shapes: object-form `actionRequired` (github_oauth, github_app_install), nested `workspace.nxCloudId`, multi-line pretty-printed JSON, mixed human/JSON output, 409 already-exists. Splices `deviceCode` into the poll command. Connected payload includes `verifyCommand` (`npx nx-cloud onboard status`) and structured `nextSteps` so the agent can demo cache replay on an existing project. Pre-check short-circuits when `nx.json` already has `nxCloudId`. Human flows untouched.

Linear: NXC-4401
nx-cloud[bot]

This comment was marked as outdated.

## Current Behavior

CNW translator spec asserts stale shapes: `toEqual` on connected payloads (now carries `verifyCommand` + `nextSteps`), and a `github_auth_needed` action that no longer exists (renamed to `github_oauth` to match ocean).

## Expected Behavior

Tests use `toMatchObject` and cover the real ocean shapes (`github_oauth` with deviceCode splice, nested `workspace.nxCloudId` success). nx-side `runAgenticOnboard` wraps `resolveNxCloudBin` in try/catch for parity with CNW (returns `BIN_NOT_FOUND` instead of throwing). TODO marker added to the github_oauth hint pointing at CLOUD-4501.

## Related Issue(s)

NXC-4401
nx-cloud[bot]

This comment was marked as outdated.

Specs carry comments that just restate what the test name already conveys.

Test names are the documentation. Drop redundant prose, fold message/hint substring checks into `toMatchObject` where it's clean.

NXC-4401
jaysoo added 4 commits May 1, 2026 15:18
## Current Behavior
nx connect always opens a browser to claim the workspace, even when the user already has an Nx Cloud PAT and a connected GitHub App.

## Expected Behavior
With a PAT and git remote, nx connect drives nx-cloud onboard connect-workspace --json directly: auto-pick the org (single) or prompt (multi), write nxCloudId, no browser. Browser still opens as fallback for github_oauth / github_app_install.

## Related Issue(s)
NXC-4401
## Current Behavior
For template + agent + PAT, CNW spawns nx-cloud onboard connect-workspace twice: once inside the template block (before git init) and once in the post-git "Auto-open Cloud setup" branch. cloneTemplate strips .git, so the first spawn either fails (no remote) or 409s the second; the agent sees a confusing payload after success.

## Expected Behavior
The template block defers Nx Cloud onboarding for agent flows. The post-git block — where the user's repo is initialized and (optionally) pushed — is the single point that fires runAgenticOnboard.

## Related Issue(s)
NXC-4401
## Current Behavior
On success, nx connect prints a "Verify remote caching" note instructing the user to run a cacheable target twice. This reads like the connection may have failed and the user must verify.

## Expected Behavior
Print "Logged in as <email>" before the spinner and just "Connected. Workspace → <url>" on success. No verify note.

## Related Issue(s)
NXC-4401
## Current Behavior
Human nx connect calls onboard status as a pre-flight before connect-workspace. With two back-to-back status calls (ours, then the bin's internal one), the bin's repo lookup misses on the first attempt for freshly cloned/renamed repos and only succeeds on the second nx connect.

## Expected Behavior
Drop the pre-flight and mirror the agent path's bin invocation. connect-workspace runs cold and one-shots fresh repos consistently. Multi-org pick and "Logged in as" line removed for now — they relied on the pre-flight; can be re-added via different mechanisms (e.g., have the bin emit user info).

## Related Issue(s)
NXC-4401
@jaysoo jaysoo marked this pull request as ready for review May 1, 2026 20:38
@jaysoo jaysoo requested a review from a team as a code owner May 1, 2026 20:39
@jaysoo jaysoo requested a review from JamesHenry May 1, 2026 20:39
jaysoo added 2 commits May 1, 2026 16:53
…ot fails

## Current Behavior
When the bin one-shot can't complete (needs GitHub OAuth, App install, etc.) the human nx connect prints an "Action required" note and stops. The user has to follow the prompt and re-run.

## Expected Behavior
On any non-connected outcome, silently stop the spinner and fall through to the legacy browser-claim flow. The browser-claim flow always works; the user is no worse off than before the one-shot attempt.

## Related Issue(s)
NXC-4401
## Current Behavior
Comments across the agentic onboard surface explain mechanics already visible in code (what, not why). extractJsonObject hand-walks brace depth string-aware, which is more complex than the use case requires.

## Expected Behavior
Comments retain the WHY (CLOUD-4496 workaround marker, cache-warming rationale, intentional no-browser behavior) and drop restated WHAT. extractJsonObject slices first { to last } and trial-parses — covers the actual bin output and is one read away from being deletable once CLOUD-4496 lands.

## Related Issue(s)
NXC-4401
Comment thread packages/nx/src/command-line/nx-cloud/connect/agentic-onboard.ts Outdated
nx-cloud[bot]

This comment was marked as outdated.

…isy buffers

extractJsonObject only finds one pretty-printed multi-line JSON blob and uses lastIndexOf('}'), missing NDJSON-with-noise streams that the bin will emit once CLOUD-4496 lands.

extractJsonPayloads parses all top-level JSON objects from a stdout buffer — handles NDJSON, pretty-printed multi-line, mixed shapes, and interleaved non-JSON noise. Top-level boundary = `{` or `}` at column 0; indented inner braces stay part of their parent object. Spec covers all shapes plus malformed and truncated input.

NXC-4401
## Current Behavior
nx init and CNW spawn the agentic onboard bin from their own flows when an agent picks "yes" to Nx Cloud. CNW also pushes a connect URL into the workspace README and a "run nx connect" banner whenever the user picks "Maybe later" or "Skip" on the cloud prompt.

## Expected Behavior
Only nx connect drives the agentic onboard — agents typically reach connect after init/CNW anyway. nx init reverts to the original initCloud("nx-init") path; CNW reverts to openCloudSetupUrl in the post-git block. CNW only generates the connect URL / README banner when the user explicitly opts in (matches nx init). "Maybe later", "Skip", and "Never" leave the workspace clean — user (or agent) runs nx connect on their own. The onboard helper moves under nx-cloud/connect/ since connect is its only caller, and the duplicated CNW copy is deleted.

## Related Issue(s)
NXC-4401
nx-cloud[bot]

This comment was marked as outdated.

nx connect carries a 600+ line wrapper (agentic-onboard.ts) that translates the bin's --json output into a typed contract, drives a one-shot path for authed humans, and emits its own NDJSON for agents. Two contracts in two places.

The bin (nrwl/ocean #11097) emits the canonical NDJSON contract directly. nx connect collapses to a hand-off:
- agent mode → emit a needs_input pointing at npx nx-cloud onboard connect-workspace so the agent invokes the bin directly and gets its NDJSON without a translation layer
- human mode (default) → spawn npx nx-cloud onboard connect-workspace with inherited stdio so the bin's spinner / human output is what the user sees
- --browser flag → keeps the legacy claim-URL flow for users who want it

agentic-onboard.ts and its spec are deleted. --browser is documented in the connect command-object.

NXC-4401
…er flow

## Current Behavior
nx connect spawns the nx-cloud bin for humans (inheriting stdio) and emits a hint for agents. Humans don't actually need a different terminal flow — the legacy browser-claim flow has worked for years.

## Expected Behavior
Agents get a needs_input pointing at npx nx-cloud onboard connect-workspace (the canonical agentic entry point). Humans keep the legacy browser-claim flow. --browser forces the browser flow even under an agent. CNW no longer forces nxCloud: 'skip' on the preset path — pass the user's choice through verbatim.

## Related Issue(s)
NXC-4401
@jaysoo jaysoo changed the title feat(misc): wire agentic Nx Cloud onboard into nx connect, nx init, and CNW feat(misc): hint agents at nx-cloud onboard from nx connect May 4, 2026
Copy link
Copy Markdown
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.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

We ran nx format to fix a trailing blank line in packages/create-nx-workspace/src/utils/nx/messages.ts that was introduced by the PR's changes. This caused the nx format:check task to fail since Prettier expects exactly one trailing newline. Applying nx format resolves the formatting violation and restores CI compliance.

Tip

We verified this fix by re-running nx-cloud record -- nx format:check.

Warning

The suggested diff is too large to display here, but you can view it on Nx Cloud ↗


Warning

⚠️ Apply was attempted but failed: No response received from commit operation

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally 11FI-8S1W

Apply fix locally with your editor ↗   View interactive diff ↗



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

…d=skip

After dropping CNW's forced normalization to the connect flow, the post-creation banner that suggests "Run nx connect" was also removed. Users who explicitly pass --nxCloud=skip lose the (still useful) hint.

Restore getSkippedCloudMessage / getSkippedNxCloudInfo. When the user picks "skip" we still show the "Next steps: nx connect" banner. When they pick "never" we stay quiet (matches the original intent).

NXC-4401
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.

1 participant