Commit 694d0ab8 authored by Jude Gao's avatar Jude Gao

[agents-md] Drop `next build` agent-rules gate

Reverts the build-side hard-fail. `next build` no longer checks for
the managed agent-rules block — failing a build mid-pipeline feels
wrong even when an agent is driving, and the dev-server gate already
catches agent-driven projects at the first iteration. `checkAgentRules`
collapses back to `checkAgentRulesForDev` with the `Dev Server exited.`
label hardcoded.
parent bd2383f6
...@@ -4,8 +4,7 @@ import { saveCpuProfile } from '../server/lib/cpu-profile' ...@@ -4,8 +4,7 @@ import { saveCpuProfile } from '../server/lib/cpu-profile'
import { existsSync } from 'fs' import { existsSync } from 'fs'
import { italic } from '../lib/picocolors' import { italic } from '../lib/picocolors'
import build from '../build' import build from '../build'
import { warn, error as logError } from '../build/output/log' import { warn } from '../build/output/log'
import { checkAgentRules } from '../server/lib/app-info-log'
import { printAndExit } from '../server/lib/utils' import { printAndExit } from '../server/lib/utils'
import isError from '../lib/is-error' import isError from '../lib/is-error'
import { getProjectDir } from '../lib/get-project-dir' import { getProjectDir } from '../lib/get-project-dir'
...@@ -104,19 +103,6 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => { ...@@ -104,19 +103,6 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => {
printAndExit(`> No such directory exists as the project root: ${dir}`) printAndExit(`> No such directory exists as the project root: ${dir}`)
} }
// Agent-rules gate: hard-fail `next build` when an AI coding agent
// is driving the build and the managed block isn't installed in
// AGENTS.md/CLAUDE.md. Fires before any bundling work so the
// developer doesn't burn minutes on a build they're about to throw
// away. Safe to fail hard here because `detectAgent()` only
// inspects env vars set by AI coding tools — CI pipelines don't
// set them, so this gate never fires on a real build server.
const agentRulesError = checkAgentRules(dir, 'build')
if (agentRulesError !== null) {
logError(agentRulesError)
process.exit(1)
}
// Resolve selective build paths // Resolve selective build paths
let resolvedBuildPaths: { app: string[]; pages: string[] } | undefined let resolvedBuildPaths: { app: string[]; pages: string[] } | undefined
......
...@@ -171,7 +171,7 @@ const BYPASS_ENV_VAR = 'NEXT_DISABLE_AGENT_RULE_CHECK' ...@@ -171,7 +171,7 @@ const BYPASS_ENV_VAR = 'NEXT_DISABLE_AGENT_RULE_CHECK'
const AGENTS_MD_INSTALL_COMMAND = 'npx @next/codemod@canary upgrade agents-md' const AGENTS_MD_INSTALL_COMMAND = 'npx @next/codemod@canary upgrade agents-md'
/** /**
* Check the Next.js agent-rules gate for `next dev` and `next build`. * Check the Next.js agent-rules gate for `next dev`.
* *
* Returns `null` when the caller should proceed normally: no AI * Returns `null` when the caller should proceed normally: no AI
* coding agent is driving, OR the managed agent-rules block is * coding agent is driving, OR the managed agent-rules block is
...@@ -183,11 +183,13 @@ const AGENTS_MD_INSTALL_COMMAND = 'npx @next/codemod@canary upgrade agents-md' ...@@ -183,11 +183,13 @@ const AGENTS_MD_INSTALL_COMMAND = 'npx @next/codemod@canary upgrade agents-md'
* none of the above apply. The caller should print the message and * none of the above apply. The caller should print the message and
* `process.exit(1)` — warnings attached to a successful process are * `process.exit(1)` — warnings attached to a successful process are
* empirically ignored by agents, so the only reliable way to make * empirically ignored by agents, so the only reliable way to make
* them act on this is to prevent the success signal from firing at * them act on this is to prevent the `Ready` / success signal from
* all. Build is safe to hard-fail alongside dev because CI * firing at all.
* environments don't set the env vars that `detectAgent()` inspects, *
* so this gate never fires in automated pipelines — only when a * Only `next dev` runs this gate. `next build` deliberately does
* developer is running `next build` from inside an agent session. * nothing: failing a build mid-pipeline feels wrong even when an
* agent is driving, and the dev-server gate already catches
* agent-driven projects at the first iteration.
* *
* The message is deliberately long and rationale-heavy. Agents * The message is deliberately long and rationale-heavy. Agents
* processing tool output weigh concrete negative consequences ("will * processing tool output weigh concrete negative consequences ("will
...@@ -198,26 +200,17 @@ const AGENTS_MD_INSTALL_COMMAND = 'npx @next/codemod@canary upgrade agents-md' ...@@ -198,26 +200,17 @@ const AGENTS_MD_INSTALL_COMMAND = 'npx @next/codemod@canary upgrade agents-md'
* is disclosed, but framed as a last resort with a concrete negative * is disclosed, but framed as a last resort with a concrete negative
* consequence attached ("agents will continue producing broken code * consequence attached ("agents will continue producing broken code
* that takes more time to fix than the codemod takes to run"). * that takes more time to fix than the codemod takes to run").
*
* `mode` picks the "Fatal: X" label so the lead sentence matches the
* command the user invoked. `Dev Server exited.` and `Build aborted.`
* are both pattern-matched by agents as terminal failures, which is
* exactly the framing we want.
*/ */
export function checkAgentRules( export function checkAgentRulesForDev(dir: string): string | null {
dir: string,
mode: 'dev' | 'build'
): string | null {
if (detectAgent() === null) return null if (detectAgent() === null) return null
if (hasAgentRulesInstalled(dir)) return null if (hasAgentRulesInstalled(dir)) return null
if (process.env[BYPASS_ENV_VAR]) return null if (process.env[BYPASS_ENV_VAR]) return null
const command = cyan(AGENTS_MD_INSTALL_COMMAND) const command = cyan(AGENTS_MD_INSTALL_COMMAND)
const bypass = cyan(`${BYPASS_ENV_VAR}=1`) const bypass = cyan(`${BYPASS_ENV_VAR}=1`)
const exitLabel = mode === 'dev' ? 'Dev Server exited.' : 'Build aborted.'
return ( return (
`Fatal: ${exitLabel} We detected you're running Next.js ` + `Fatal: Dev Server exited. We detected you're running Next.js ` +
`inside an AI coding agent but the managed agent-rules block is ` + `inside an AI coding agent but the managed agent-rules block is ` +
`not installed in AGENTS.md or CLAUDE.md.\n\n` + `not installed in AGENTS.md or CLAUDE.md.\n\n` +
`Why this matters: AI coding agents are trained on older Next.js ` + `Why this matters: AI coding agents are trained on older Next.js ` +
......
...@@ -27,7 +27,7 @@ import { ...@@ -27,7 +27,7 @@ import {
PHASE_DEVELOPMENT_SERVER, PHASE_DEVELOPMENT_SERVER,
} from '../../shared/lib/constants' } from '../../shared/lib/constants'
import { import {
checkAgentRules, checkAgentRulesForDev,
getEnvInfo, getEnvInfo,
logExperimentalInfo, logExperimentalInfo,
logStartInfo, logStartInfo,
...@@ -384,7 +384,7 @@ export async function startServer( ...@@ -384,7 +384,7 @@ export async function startServer(
// length and surfaces a last-resort `NEXT_DISABLE_AGENT_RULE_CHECK` // length and surfaces a last-resort `NEXT_DISABLE_AGENT_RULE_CHECK`
// env var for locked-down environments. // env var for locked-down environments.
if (isDev) { if (isDev) {
const agentRulesError = checkAgentRules(dir, 'dev') const agentRulesError = checkAgentRulesForDev(dir)
if (agentRulesError !== null) { if (agentRulesError !== null) {
Log.error(agentRulesError) Log.error(agentRulesError)
process.exit(1) process.exit(1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment