Commit 86564347 authored by Jude Gao's avatar Jude Gao

Revert "[agents-md] Add `agentRules` next.config option to opt out"

This reverts commit 3b1105b1.
parent 3b1105b1
...@@ -77,20 +77,6 @@ This version has breaking changes — APIs, conventions, and file structure may ...@@ -77,20 +77,6 @@ This version has breaking changes — APIs, conventions, and file structure may
You can also add the block by hand with the exact content above. You can also add the block by hand with the exact content above.
### Opting out
To disable the auto-generation, delete the files and set `agentRules` to `false` in your config:
```ts filename="next.config.ts"
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
agentRules: false,
}
export default nextConfig
```
<details> <details>
<summary>For earlier versions</summary> <summary>For earlier versions</summary>
......
...@@ -428,7 +428,6 @@ export const experimentalSchema = { ...@@ -428,7 +428,6 @@ export const experimentalSchema = {
export const configSchema: zod.ZodType<NextConfig> = z.lazy(() => export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
z.strictObject({ z.strictObject({
adapterPath: z.string().optional(), adapterPath: z.string().optional(),
agentRules: z.boolean().optional(),
allowedDevOrigins: z.array(z.string()).optional(), allowedDevOrigins: z.array(z.string()).optional(),
assetPrefix: z.string().optional(), assetPrefix: z.string().optional(),
basePath: z.string().optional(), basePath: z.string().optional(),
......
...@@ -1650,17 +1650,6 @@ export interface NextConfig { ...@@ -1650,17 +1650,6 @@ export interface NextConfig {
*/ */
expireTime?: number expireTime?: number
/**
* When `next dev` detects an AI coding agent and no managed
* agent-rules block is present, Next.js auto-generates `AGENTS.md`
* and `CLAUDE.md` at the project root so the agent reads
* version-matched docs from `node_modules/next/dist/docs/` instead
* of stale training data. Set to `false` to disable this behavior.
*
* @default true
*/
agentRules?: boolean
/** /**
* Enable experimental features. Note that all experimental features are subject to breaking changes in the future. * Enable experimental features. Note that all experimental features are subject to breaking changes in the future.
*/ */
......
...@@ -125,10 +125,6 @@ export function logExperimentalInfo({ ...@@ -125,10 +125,6 @@ export function logExperimentalInfo({
* auto-generate the files so the agent has access to version-matched * auto-generate the files so the agent has access to version-matched
* docs. Returns the write result when files were generated, or `null` * docs. Returns the write result when files were generated, or `null`
* when no action was needed. * when no action was needed.
*
* Callers gate this on `config.agentRules !== false` — disabling is
* done via `agentRules: false` in next.config, not inside this
* function, so the check point stays declarative at the config level.
*/ */
export function ensureAgentRulesForDev(dir: string): AgentFilesResult | null { export function ensureAgentRulesForDev(dir: string): AgentFilesResult | null {
if (detectAgent() === null) return null if (detectAgent() === null) return null
......
...@@ -930,6 +930,5 @@ export async function initialize(opts: { ...@@ -930,6 +930,5 @@ export async function initialize(opts: {
distDir: config.distDir, distDir: config.distDir,
experimentalFeatures, experimentalFeatures,
cacheComponents: config.cacheComponents, cacheComponents: config.cacheComponents,
agentRules: config.agentRules,
} }
} }
...@@ -374,6 +374,32 @@ export async function startServer( ...@@ -374,6 +374,32 @@ export async function startServer(
// Get env info first (fast, doesn't require config) // Get env info first (fast, doesn't require config)
const envInfo = isDev ? getEnvInfo(dir) : undefined const envInfo = isDev ? getEnvInfo(dir) : undefined
// Auto-generate AGENTS.md / CLAUDE.md when an AI coding agent
// is detected but the managed agent-rules block is missing.
if (isDev) {
const agentFilesResult = ensureAgentRulesForDev(dir)
if (agentFilesResult) {
const generated: string[] = []
if (
agentFilesResult.agentsMd === 'created' ||
agentFilesResult.agentsMd === 'updated'
) {
generated.push('AGENTS.md')
}
if (
agentFilesResult.claudeMd === 'created' ||
agentFilesResult.claudeMd === 'updated'
) {
generated.push('CLAUDE.md')
}
if (generated.length > 0) {
Log.info(
`Generated ${generated.join(' and ')} with Next.js agent rules`
)
}
}
}
// Log basic startup info immediately (before loading config) // Log basic startup info immediately (before loading config)
logStartInfo({ logStartInfo({
networkUrl, networkUrl,
...@@ -507,36 +533,6 @@ export async function startServer( ...@@ -507,36 +533,6 @@ export async function startServer(
experimentalFeatures: initResult.experimentalFeatures, experimentalFeatures: initResult.experimentalFeatures,
cacheComponents: initResult.cacheComponents, cacheComponents: initResult.cacheComponents,
}) })
// Auto-generate AGENTS.md / CLAUDE.md when an AI coding agent
// is detected but the managed agent-rules block is missing.
// Gated on `agentRules` in next.config (default true). Runs
// after config load so the flag is respected.
if (initResult.agentRules !== false) {
const agentFilesResult = ensureAgentRulesForDev(dir)
if (agentFilesResult) {
const generated: string[] = []
if (
agentFilesResult.agentsMd === 'created' ||
agentFilesResult.agentsMd === 'updated'
) {
generated.push('AGENTS.md')
}
if (
agentFilesResult.claudeMd === 'created' ||
agentFilesResult.claudeMd === 'updated'
) {
generated.push('CLAUDE.md')
}
if (generated.length > 0) {
Log.info(
`Generated ${generated.join(' and ')} so AI agents use version-matched Next.js docs. ` +
`We think this is a good default. If you'd rather not have these files, delete them and ` +
`set \`agentRules: false\` in next.config.`
)
}
}
}
} }
handlersReady() handlersReady()
......
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