Unverified Commit 4e0e573a authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Use Agent terminology throughout upgrades (#99545)

### Why?

Use consistent Agent terminology for the upgrade command and lifecycle
reporting.

### How?

Replace `--ai` and `--experimental-ai` with `--agent`, and update
upgrade recommendations, DevTools prompts, tests, and eval fixtures.
Rename the telemetry module, types and event names, hidden completion
reporter, run-ID environment variable, and preference namespace to
match. Telemetry events now use `NEXT_AGENT_UPGRADE_*`, and preferences
use `agent-upgrade.*`.

Formatting, TypeScript syntax, and telemetry producer smoke checks pass.
Full local build and unit tests remain blocked by missing workspace
dependencies.
parent 936fda6a
...@@ -39,7 +39,7 @@ fixtures fail before execution, and infrastructure failures are retained in the ...@@ -39,7 +39,7 @@ fixtures fail before execution, and infrastructure failures are retained in the
Feature PRs add ordinary npm app fixtures with exact dependency versions, Feature PRs add ordinary npm app fixtures with exact dependency versions,
`PROMPT.md`, and `EVAL.ts`. Explicit upgrade scenarios invoke `PROMPT.md`, and `EVAL.ts`. Explicit upgrade scenarios invoke
`npx next@canary upgrade --ai`. Reminder scenarios keep the original task prompt `npx next@canary upgrade --agent`. Reminder scenarios keep the original task prompt
unchanged so the eval can attribute acknowledgment to the runtime notice. Feature unchanged so the eval can attribute acknowledgment to the runtime notice. Feature
PRs own browser setup, repository remotes, advisory responses, codemod routing, PRs own browser setup, repository remotes, advisory responses, codemod routing,
grading, and reference or negative controls. Keep graders and reference solutions grading, and reference or negative controls. Keep graders and reference solutions
......
Run `next upgrade --ai experimental-future` for this app and complete the upgrade. Run `next upgrade --agent experimental-future` for this app and complete the upgrade.
Run `next upgrade --ai experimental-future` for this app and complete the upgrade. Run `next upgrade --agent experimental-future` for this app and complete the upgrade.
Run `npx next@canary upgrade --ai latest` for this app. Run `npx next@canary upgrade --agent latest` for this app.
Run `npx next@canary upgrade --ai latest` for this app. Run `npx next@canary upgrade --agent latest` for this app.
Run `npx next@canary upgrade --ai` for this app and follow the instructions. Run `npx next@canary upgrade --agent` for this app and follow the instructions.
Run `npx next@canary upgrade --ai` for this app and follow the instructions. Run `npx next@canary upgrade --agent` for this app and follow the instructions.
Run `npx next@canary upgrade --ai` for this app and follow the instructions. Run `npx next@canary upgrade --agent` for this app and follow the instructions.
...@@ -153,7 +153,7 @@ export function duplicateSecurityChecks(source: string, target: string) { ...@@ -153,7 +153,7 @@ export function duplicateSecurityChecks(source: string, target: string) {
test('recognizes the existing security upgrade', async () => { test('recognizes the existing security upgrade', async () => {
expect(records('invocations.jsonl')).toContainEqual( expect(records('invocations.jsonl')).toContainEqual(
expect.objectContaining({ expect.objectContaining({
args: ['upgrade', '--ai'], args: ['upgrade', '--agent'],
packageRunner: 'npx', packageRunner: 'npx',
requestedPackage: 'next@canary', requestedPackage: 'next@canary',
}) })
......
...@@ -112,10 +112,7 @@ class NextRootCommand extends Command { ...@@ -112,10 +112,7 @@ class NextRootCommand extends Command {
// The upgrade harness may run both dev and production checks. Preserve // The upgrade harness may run both dev and production checks. Preserve
// its caller's environment instead of forcing all child commands into // its caller's environment instead of forcing all child commands into
// production mode merely because they were launched through this CLI. // production mode merely because they were launched through this CLI.
if ( if (commandName !== 'upgrade' || !event.getOptionValue('agent')) {
commandName !== 'upgrade' ||
!event.getOptionValue('experimentalAi')
) {
;(process.env as any).NODE_ENV = process.env.NODE_ENV || defaultEnv ;(process.env as any).NODE_ENV = process.env.NODE_ENV || defaultEnv
;(process.env as any).NEXT_RUNTIME = 'nodejs' ;(process.env as any).NEXT_RUNTIME = 'nodejs'
} }
...@@ -586,8 +583,8 @@ program ...@@ -586,8 +583,8 @@ program
.option('--verbose', 'Verbose output', false) .option('--verbose', 'Verbose output', false)
.addOption( .addOption(
new Option( new Option(
'--ai, --experimental-ai [type]', '--agent [type]',
'Upgrade with AI to security, latest, or experimental-future. Defaults to security.' 'Upgrade with an agent to security, latest, or experimental-future. Defaults to security.'
).conflicts('revision') ).conflicts('revision')
) )
// Keep nudge attribution available to agents without exposing it in public help. // Keep nudge attribution available to agents without exposing it in public help.
...@@ -596,10 +593,7 @@ program ...@@ -596,10 +593,7 @@ program
const mod = await import('../cli/next-upgrade.js') const mod = await import('../cli/next-upgrade.js')
await mod.spawnNextUpgrade( await mod.spawnNextUpgrade(
directory, directory,
{ options,
...options,
ai: options.experimentalAi,
},
options.internalNudgeId !== undefined options.internalNudgeId !== undefined
? { id: options.internalNudgeId, recipient: 'agent' } ? { id: options.internalNudgeId, recipient: 'agent' }
: null : null
...@@ -676,12 +670,12 @@ const internal = program ...@@ -676,12 +670,12 @@ const internal = program
// Agents use the pinned CLI to report completion after the upgrade has changed dependencies. // Agents use the pinned CLI to report completion after the upgrade has changed dependencies.
internal internal
.command('report-ai-upgrade', { hidden: true }) .command('report-agent-upgrade', { hidden: true })
.argument('<run-id>', 'The upgrade run UUID.') .argument('<run-id>', 'The upgrade run UUID.')
.argument('<result>', 'The agent-reported success or failure result.') .argument('<result>', 'The agent-reported success or failure result.')
.action((runId: string, result: string) => .action((runId: string, result: string) =>
import('../cli/next-upgrade.js').then((mod) => import('../cli/next-upgrade.js').then((mod) =>
mod.reportAIUpgradeAgentResult(runId, result) mod.reportAgentUpgradeAgentResult(runId, result)
) )
) )
......
...@@ -15,13 +15,13 @@ import type { UpgradeDocument } from '../lib/upgrade/future-defaults' ...@@ -15,13 +15,13 @@ import type { UpgradeDocument } from '../lib/upgrade/future-defaults'
import { runChildProcess } from '../lib/upgrade/run-child-process' import { runChildProcess } from '../lib/upgrade/run-child-process'
import { getAgentName } from '../telemetry/agent-name' import { getAgentName } from '../telemetry/agent-name'
import { import {
eventAIUpgradeAgentResult, eventAgentUpgradeAgentResult,
eventAIUpgradeCLIResult, eventAgentUpgradeCLIResult,
eventAIUpgradeRunStarted, eventAgentUpgradeRunStarted,
type AIUpgradeCLIResult, type AgentUpgradeCLIResult,
type AIUpgradeHandoffMethod, type AgentUpgradeHandoffMethod,
type AIUpgradePolicy, type AgentUpgradePolicy,
} from '../telemetry/events/ai-upgrade' } from '../telemetry/events/agent-upgrade'
import { Telemetry } from '../telemetry/storage' import { Telemetry } from '../telemetry/storage'
import loadConfig from '../server/config' import loadConfig from '../server/config'
import { normalizeConfig } from '../server/config-shared' import { normalizeConfig } from '../server/config-shared'
...@@ -30,7 +30,7 @@ import { PHASE_PRODUCTION_BUILD } from '../shared/lib/constants' ...@@ -30,7 +30,7 @@ import { PHASE_PRODUCTION_BUILD } from '../shared/lib/constants'
type NextUpgradeOptions = { type NextUpgradeOptions = {
revision: string revision: string
verbose: boolean verbose: boolean
ai: boolean | string | undefined agent: boolean | string | undefined
} }
const UUID_PATTERN = const UUID_PATTERN =
...@@ -134,7 +134,7 @@ async function prepareUpgradeSkill( ...@@ -134,7 +134,7 @@ async function prepareUpgradeSkill(
} }
} }
async function loadAIUpgradeConfig(directory: string) { async function loadAgentUpgradeConfig(directory: string) {
// Read and normalize the app's config without validating legacy options // Read and normalize the app's config without validating legacy options
// against the current Next.js schema. // against the current Next.js schema.
const rawConfig = await loadConfig(PHASE_PRODUCTION_BUILD, directory, { const rawConfig = await loadConfig(PHASE_PRODUCTION_BUILD, directory, {
...@@ -175,7 +175,7 @@ export async function spawnNextUpgrade( ...@@ -175,7 +175,7 @@ export async function spawnNextUpgrade(
) { ) {
let baseDir = resolvePath(directory || '.') let baseDir = resolvePath(directory || '.')
if (options.ai) { if (options.agent) {
// Match dev/build's telemetry storage, including custom output directories in CI. // Match dev/build's telemetry storage, including custom output directories in CI.
// Retain config errors until after recording the invocation so failed runs still count. // Retain config errors until after recording the invocation so failed runs still count.
let distDir = '.next' let distDir = '.next'
...@@ -183,14 +183,14 @@ export async function spawnNextUpgrade( ...@@ -183,14 +183,14 @@ export async function spawnNextUpgrade(
let configError: unknown = null let configError: unknown = null
try { try {
baseDir = getProjectDir(directory, false) baseDir = getProjectDir(directory, false)
const config = await loadAIUpgradeConfig(baseDir) const config = await loadAgentUpgradeConfig(baseDir)
distDir = config.distDir || '.next' distDir = config.distDir || '.next'
configuredPolicy = config.experimental?.agentUpgrade configuredPolicy = config.experimental?.agentUpgrade
} catch (error) { } catch (error) {
configError = error configError = error
} }
// Count AI invocations even when resolving the directory or config fails. // Count agent invocations even when resolving the directory or config fails.
const telemetry = new Telemetry({ const telemetry = new Telemetry({
distDir: join(baseDir, distDir), distDir: join(baseDir, distDir),
skipNotify: true, skipNotify: true,
...@@ -198,8 +198,8 @@ export async function spawnNextUpgrade( ...@@ -198,8 +198,8 @@ export async function spawnNextUpgrade(
// The parent records attribution; canary only needs its run ID to report results. // The parent records attribution; canary only needs its run ID to report results.
// Remove it before launching an agent so later upgrades start their own runs. // Remove it before launching an agent so later upgrades start their own runs.
const inheritedRunId = process.env.__NEXT_AI_UPGRADE_RUN_ID const inheritedRunId = process.env.__NEXT_AGENT_UPGRADE_RUN_ID
delete process.env.__NEXT_AI_UPGRADE_RUN_ID delete process.env.__NEXT_AGENT_UPGRADE_RUN_ID
const invalidRunId = const invalidRunId =
inheritedRunId !== undefined && !UUID_PATTERN.test(inheritedRunId) inheritedRunId !== undefined && !UUID_PATTERN.test(inheritedRunId)
const invalidNudgeId = const invalidNudgeId =
...@@ -208,14 +208,14 @@ export async function spawnNextUpgrade( ...@@ -208,14 +208,14 @@ export async function spawnNextUpgrade(
const runId = const runId =
inheritedRunId && !invalidRunId ? inheritedRunId : randomUUID() inheritedRunId && !invalidRunId ? inheritedRunId : randomUUID()
let resolvedPolicy: AIUpgradePolicy | null = null let resolvedPolicy: AgentUpgradePolicy | null = null
let failureStage: 'cli' | 'metadata' | 'guide' | 'handoff' = 'cli' let failureStage: 'cli' | 'metadata' | 'guide' | 'handoff' = 'cli'
let cliResultRecorded = false let cliResultRecorded = false
// Preparation and handoff can both fail; record only the first terminal result. // Preparation and handoff can both fail; record only the first terminal result.
const recordCLIResult = ( const recordCLIResult = (
result: AIUpgradeCLIResult, result: AgentUpgradeCLIResult,
handoffMethod: AIUpgradeHandoffMethod | null, handoffMethod: AgentUpgradeHandoffMethod | null,
selectedAgentProduct: string | null selectedAgentProduct: string | null
) => { ) => {
if (cliResultRecorded) { if (cliResultRecorded) {
...@@ -223,7 +223,7 @@ export async function spawnNextUpgrade( ...@@ -223,7 +223,7 @@ export async function spawnNextUpgrade(
} }
cliResultRecorded = true cliResultRecorded = true
telemetry.record( telemetry.record(
eventAIUpgradeCLIResult({ eventAgentUpgradeCLIResult({
runId, runId,
result, result,
resolvedPolicy, resolvedPolicy,
...@@ -247,16 +247,16 @@ export async function spawnNextUpgrade( ...@@ -247,16 +247,16 @@ export async function spawnNextUpgrade(
? 'agent_manual' ? 'agent_manual'
: 'human_manual' : 'human_manual'
telemetry.record( telemetry.record(
eventAIUpgradeRunStarted({ eventAgentUpgradeRunStarted({
runId, runId,
nudgeId: nudge?.id ?? null, nudgeId: nudge?.id ?? null,
origin, origin,
agentProduct, agentProduct,
requestedPolicy: requestedPolicy:
options.ai === 'security' || options.agent === 'security' ||
options.ai === 'latest' || options.agent === 'latest' ||
options.ai === 'experimental-future' options.agent === 'experimental-future'
? options.ai ? options.agent
: null, : null,
}) })
) )
...@@ -290,14 +290,16 @@ export async function spawnNextUpgrade( ...@@ -290,14 +290,16 @@ export async function spawnNextUpgrade(
failureStage = 'cli' failureStage = 'cli'
if (process.env.__NEXT_VERSION !== canaryVersion) { if (process.env.__NEXT_VERSION !== canaryVersion) {
const [command, ...runnerArgs] = getNpxCommand(baseDir).split(' ') const [command, ...runnerArgs] = getNpxCommand(baseDir).split(' ')
const aiArgument = const agentArgument =
typeof options.ai === 'string' ? `--ai=${options.ai}` : '--ai' typeof options.agent === 'string'
? `--agent=${options.agent}`
: '--agent'
const args = [ const args = [
...runnerArgs, ...runnerArgs,
`next@${canaryVersion}`, `next@${canaryVersion}`,
'upgrade', 'upgrade',
baseDir, baseDir,
aiArgument, agentArgument,
] ]
if (options.verbose) { if (options.verbose) {
...@@ -313,7 +315,7 @@ export async function spawnNextUpgrade( ...@@ -313,7 +315,7 @@ export async function spawnNextUpgrade(
env: { env: {
...process.env, ...process.env,
// The delegated CLI emits the CLI result for this invocation's run ID. // The delegated CLI emits the CLI result for this invocation's run ID.
__NEXT_AI_UPGRADE_RUN_ID: runId, __NEXT_AGENT_UPGRADE_RUN_ID: runId,
__NEXT_UPGRADE_EXPECTED_CLI_VERSION: canaryVersion, __NEXT_UPGRADE_EXPECTED_CLI_VERSION: canaryVersion,
// Older canaries recognize only this recursion guard. // Older canaries recognize only this recursion guard.
__NEXT_UPGRADE_USE_CURRENT_CLI: '1', __NEXT_UPGRADE_USE_CURRENT_CLI: '1',
...@@ -329,13 +331,13 @@ export async function spawnNextUpgrade( ...@@ -329,13 +331,13 @@ export async function spawnNextUpgrade(
if (!findDir(baseDir, 'app') && !findDir(baseDir, 'pages')) { if (!findDir(baseDir, 'app') && !findDir(baseDir, 'pages')) {
throw new Error( throw new Error(
'No Next.js app found in this directory. Run the command from an app directory or pass its path:\n\n' + 'No Next.js app found in this directory. Run the command from an app directory or pass its path:\n\n' +
`next upgrade [directory] --ai${typeof options.ai === 'string' ? `=${options.ai}` : ''}` `next upgrade [directory] --agent${typeof options.agent === 'string' ? `=${options.agent}` : ''}`
) )
} }
const upgradeType = const upgradeType =
typeof options.ai === 'string' typeof options.agent === 'string'
? options.ai ? options.agent
: configuredPolicy === 'security' || : configuredPolicy === 'security' ||
configuredPolicy === 'latest' || configuredPolicy === 'latest' ||
configuredPolicy === 'experimental-future' configuredPolicy === 'experimental-future'
...@@ -348,7 +350,7 @@ export async function spawnNextUpgrade( ...@@ -348,7 +350,7 @@ export async function spawnNextUpgrade(
upgradeType !== 'experimental-future' upgradeType !== 'experimental-future'
) { ) {
throw new Error( throw new Error(
`Unsupported AI upgrade type ${JSON.stringify(upgradeType)}. Expected "security", "latest", or "experimental-future".` `Unsupported agent upgrade type ${JSON.stringify(upgradeType)}. Expected "security", "latest", or "experimental-future".`
) )
} }
resolvedPolicy = upgradeType resolvedPolicy = upgradeType
...@@ -576,7 +578,7 @@ export async function spawnNextUpgrade( ...@@ -576,7 +578,7 @@ export async function spawnNextUpgrade(
: `We're adopting the Future Defaults available to the app in ${JSON.stringify(baseDir)}, which already uses Next.js ${result.installedVersion}.` : `We're adopting the Future Defaults available to the app in ${JSON.stringify(baseDir)}, which already uses Next.js ${result.installedVersion}.`
// Use the invoking CLI's reporter even after the app's Next.js package changes. // Use the invoking CLI's reporter even after the app's Next.js package changes.
const reportCommand = `${getNpxCommand(baseDir)} next@${process.env.__NEXT_VERSION} internal report-ai-upgrade ${runId}` const reportCommand = `${getNpxCommand(baseDir)} next@${process.env.__NEXT_VERSION} internal report-agent-upgrade ${runId}`
const prompt = ( const prompt = (
useWorktree: boolean | null useWorktree: boolean | null
) => `Read and follow ${JSON.stringify(sharedGuidePath)} first. Attempt its applicable duplicate checks before changing files. If a check is unavailable, report it and continue. Stop only if you find equivalent work. Then read and follow every applicable instruction in ${JSON.stringify(guidePath)}. ) => `Read and follow ${JSON.stringify(sharedGuidePath)} first. Attempt its applicable duplicate checks before changing files. If a check is unavailable, report it and continue. Stop only if you find equivalent work. Then read and follow every applicable instruction in ${JSON.stringify(guidePath)}.
...@@ -670,7 +672,7 @@ When this task ends, report its result once. After completing the requested upgr ...@@ -670,7 +672,7 @@ When this task ends, report its result once. After completing the requested upgr
}) })
} }
export async function reportAIUpgradeAgentResult( export async function reportAgentUpgradeAgentResult(
runId: string, runId: string,
result: string result: string
) { ) {
...@@ -685,11 +687,11 @@ export async function reportAIUpgradeAgentResult( ...@@ -685,11 +687,11 @@ export async function reportAIUpgradeAgentResult(
} }
// Reuse normal telemetry consent and delivery without starting another upgrade. // Reuse normal telemetry consent and delivery without starting another upgrade.
const config = await loadAIUpgradeConfig(process.cwd()) const config = await loadAgentUpgradeConfig(process.cwd())
const telemetry = new Telemetry({ const telemetry = new Telemetry({
distDir: join(process.cwd(), config.distDir || '.next'), distDir: join(process.cwd(), config.distDir || '.next'),
skipNotify: true, skipNotify: true,
}) })
await telemetry.record(eventAIUpgradeAgentResult({ runId, result })) await telemetry.record(eventAgentUpgradeAgentResult({ runId, result }))
await telemetry.flush() await telemetry.flush()
} }
...@@ -8,7 +8,7 @@ import spawn from 'next/dist/compiled/cross-spawn' ...@@ -8,7 +8,7 @@ import spawn from 'next/dist/compiled/cross-spawn'
import * as Log from '../../build/output/log' import * as Log from '../../build/output/log'
import { getAgentName } from '../../telemetry/agent-name' import { getAgentName } from '../../telemetry/agent-name'
import type { AIUpgradeHandoffMethod } from '../../telemetry/events/ai-upgrade' import type { AgentUpgradeHandoffMethod } from '../../telemetry/events/agent-upgrade'
import { bold, cyan, dim } from '../picocolors' import { bold, cyan, dim } from '../picocolors'
import { runChildProcess } from './run-child-process' import { runChildProcess } from './run-child-process'
...@@ -273,7 +273,7 @@ async function chooseHarness( ...@@ -273,7 +273,7 @@ async function chooseHarness(
function copyUpgradePrompt( function copyUpgradePrompt(
prompt: string, prompt: string,
noHarness: boolean noHarness: boolean
): AIUpgradeHandoffMethod { ): AgentUpgradeHandoffMethod {
const commands = const commands =
process.platform === 'darwin' process.platform === 'darwin'
? [['pbcopy']] ? [['pbcopy']]
...@@ -353,7 +353,7 @@ export async function handoffUpgrade( ...@@ -353,7 +353,7 @@ export async function handoffUpgrade(
directory: string, directory: string,
onHandoff: onHandoff:
| (( | ((
method: AIUpgradeHandoffMethod, method: AgentUpgradeHandoffMethod,
selectedAgentProduct: string | null selectedAgentProduct: string | null
) => void) ) => void)
| null | null
......
...@@ -9,10 +9,10 @@ import * as Log from '../../build/output/log' ...@@ -9,10 +9,10 @@ import * as Log from '../../build/output/log'
import type { NextConfigComplete } from '../../server/config-shared' import type { NextConfigComplete } from '../../server/config-shared'
import type { Telemetry } from '../../telemetry/storage' import type { Telemetry } from '../../telemetry/storage'
import { import {
eventAIUpgradeNudgeDecision, eventAgentUpgradeNudgeDecision,
eventAIUpgradeNudgeShown, eventAgentUpgradeNudgeShown,
eventAIUpgradePolicyDetected, eventAgentUpgradePolicyDetected,
} from '../../telemetry/events/ai-upgrade' } from '../../telemetry/events/agent-upgrade'
import semver from 'next/dist/compiled/semver' import semver from 'next/dist/compiled/semver'
import type { UpgradeAction } from './prompt' import type { UpgradeAction } from './prompt'
import { getAgentName } from '../../telemetry/agent-name' import { getAgentName } from '../../telemetry/agent-name'
...@@ -283,7 +283,7 @@ async function nudgeUpgradeForAgent( ...@@ -283,7 +283,7 @@ async function nudgeUpgradeForAgent(
nudgeId: string, nudgeId: string,
agentProduct: string, agentProduct: string,
telemetry: Telemetry | null, telemetry: Telemetry | null,
policyEvent: ReturnType<typeof eventAIUpgradePolicyDetected> policyEvent: ReturnType<typeof eventAgentUpgradePolicyDetected>
): Promise<void> { ): Promise<void> {
let summary: string let summary: string
let recommendation: string let recommendation: string
...@@ -306,7 +306,7 @@ async function nudgeUpgradeForAgent( ...@@ -306,7 +306,7 @@ async function nudgeUpgradeForAgent(
break break
} }
// Pass attribution on the invocation using the same command syntax on every platform. // Pass attribution on the invocation using the same command syntax on every platform.
const command = `next upgrade --ai=${reminder.policy} --internal-nudge-id=${nudgeId}` const command = `next upgrade --agent=${reminder.policy} --internal-nudge-id=${nudgeId}`
const message = `${summary} const message = `${summary}
**${recommendation}** **${recommendation}**
...@@ -351,7 +351,7 @@ ${reference ? `Reference: ${reference}` : ''}` ...@@ -351,7 +351,7 @@ ${reference ? `Reference: ${reference}` : ''}`
distDir: resolve(options.directory, options.distDir), distDir: resolve(options.directory, options.distDir),
events: [ events: [
policyEvent, policyEvent,
eventAIUpgradeNudgeShown({ eventAgentUpgradeNudgeShown({
nudgeId, nudgeId,
recipient: 'agent', recipient: 'agent',
agentProduct, agentProduct,
...@@ -402,7 +402,7 @@ async function getUpgradePreferences(directory: string) { ...@@ -402,7 +402,7 @@ async function getUpgradePreferences(directory: string) {
const hash = createHash('sha256').update(identity).digest('hex') const hash = createHash('sha256').update(identity).digest('hex')
// Conf treats dots as separators, including dots in directory names. // Conf treats dots as separators, including dots in directory names.
const name = encodeURIComponent(projectName).replace(/\./g, '%2E') const name = encodeURIComponent(projectName).replace(/\./g, '%2E')
const key = `ai-upgrade.${name}.${hash}` const key = `agent-upgrade.${name}.${hash}`
// Upgrade preferences share Next.js' global config location, not telemetry consent. // Upgrade preferences share Next.js' global config location, not telemetry consent.
return { key, preferences: new Conf({ projectName: 'nextjs' }) } return { key, preferences: new Conf({ projectName: 'nextjs' }) }
} }
...@@ -503,7 +503,7 @@ export async function runUpgrade( ...@@ -503,7 +503,7 @@ export async function runUpgrade(
// Human Update actions invoke the CLI directly, so their ID does not need an env var. // Human Update actions invoke the CLI directly, so their ID does not need an env var.
await spawnNextUpgrade( await spawnNextUpgrade(
directory, directory,
{ revision: 'latest', verbose: false, ai: policy }, { revision: 'latest', verbose: false, agent: policy },
nudgeId ? { id: nudgeId, recipient: 'human' } : null nudgeId ? { id: nudgeId, recipient: 'human' } : null
) )
return process.exitCode ?? 0 return process.exitCode ?? 0
...@@ -535,7 +535,7 @@ export async function nudgeUpgrade( ...@@ -535,7 +535,7 @@ export async function nudgeUpgrade(
} }
// Observe the effective policy even when assessment finds no upgrade to offer. // Observe the effective policy even when assessment finds no upgrade to offer.
const telemetry = telemetryOptions?.telemetry ?? null const telemetry = telemetryOptions?.telemetry ?? null
const policyEvent = eventAIUpgradePolicyDetected({ const policyEvent = eventAgentUpgradePolicyDetected({
configuredPolicy: config.configuredPolicy ?? null, configuredPolicy: config.configuredPolicy ?? null,
effectivePolicy: policy, effectivePolicy: policy,
policySource: requested ? 'environment' : 'config', policySource: requested ? 'environment' : 'config',
...@@ -613,7 +613,7 @@ export async function nudgeUpgrade( ...@@ -613,7 +613,7 @@ export async function nudgeUpgrade(
shown = true shown = true
telemetryOptions.onNudgeId?.(nudgeId) telemetryOptions.onNudgeId?.(nudgeId)
telemetryOptions.telemetry.record( telemetryOptions.telemetry.record(
eventAIUpgradeNudgeShown({ eventAgentUpgradeNudgeShown({
nudgeId, nudgeId,
recipient: 'human', recipient: 'human',
agentProduct: null, agentProduct: null,
...@@ -634,7 +634,7 @@ export async function nudgeUpgrade( ...@@ -634,7 +634,7 @@ export async function nudgeUpgrade(
if (shown && telemetry) { if (shown && telemetry) {
if (!signal.aborted) { if (!signal.aborted) {
telemetry.record(eventAIUpgradeNudgeDecision({ nudgeId, action })) telemetry.record(eventAgentUpgradeNudgeDecision({ nudgeId, action }))
} }
await telemetry.flush() await telemetry.flush()
} }
......
...@@ -30,7 +30,7 @@ export async function prepareUpgrade( ...@@ -30,7 +30,7 @@ export async function prepareUpgrade(
targetRequest !== 'experimental-future' targetRequest !== 'experimental-future'
) { ) {
throw new Error( throw new Error(
`Unsupported AI upgrade type ${JSON.stringify(targetRequest)}. Expected "security", "latest", or "experimental-future".` `Unsupported agent upgrade type ${JSON.stringify(targetRequest)}. Expected "security", "latest", or "experimental-future".`
) )
} }
...@@ -98,7 +98,7 @@ export async function getUpgradeAssessment( ...@@ -98,7 +98,7 @@ export async function getUpgradeAssessment(
const channel = getPrereleaseChannel(installedVersion) const channel = getPrereleaseChannel(installedVersion)
if (semver.prerelease(installedVersion) && !channel) { if (semver.prerelease(installedVersion) && !channel) {
throw new Error( throw new Error(
'AI upgrades are not available for this prerelease version of Next.js.' 'Agent upgrades are not available for this prerelease version of Next.js.'
) )
} }
if (channel && (policy === 'security' || onlyIfAffected)) { if (channel && (policy === 'security' || onlyIfAffected)) {
...@@ -107,7 +107,7 @@ export async function getUpgradeAssessment( ...@@ -107,7 +107,7 @@ export async function getUpgradeAssessment(
reference: null, reference: null,
upgrade: { upgrade: {
status: 'blocked', status: 'blocked',
reason: `The installed Next.js version (${installedVersion}) is a ${channel} prerelease. Security advisories target stable versions, and prereleases do not reliably follow stable version ordering, so an advisory could be a false positive. To upgrade to the latest ${channel === 'canary' ? 'canary' : 'stable'} release, run this command from the app's directory:\n\nnpx next@canary upgrade --ai=latest`, reason: `The installed Next.js version (${installedVersion}) is a ${channel} prerelease. Security advisories target stable versions, and prereleases do not reliably follow stable version ordering, so an advisory could be a false positive. To upgrade to the latest ${channel === 'canary' ? 'canary' : 'stable'} release, run this command from the app's directory:\n\nnpx next@canary upgrade --agent=latest`,
}, },
} }
} }
...@@ -117,7 +117,7 @@ export async function getUpgradeAssessment( ...@@ -117,7 +117,7 @@ export async function getUpgradeAssessment(
reference: null, reference: null,
upgrade: { upgrade: {
status: 'blocked', status: 'blocked',
reason: `Future Defaults upgrades are not supported for Next.js ${installedVersion}. To upgrade to the latest stable release, run this command from the app's directory:\n\nnpx next@canary upgrade --ai=latest`, reason: `Future Defaults upgrades are not supported for Next.js ${installedVersion}. To upgrade to the latest stable release, run this command from the app's directory:\n\nnpx next@canary upgrade --agent=latest`,
}, },
} }
} }
......
...@@ -33,7 +33,8 @@ export function VulnerabilityInsight({ ...@@ -33,7 +33,8 @@ export function VulnerabilityInsight({
onNext: (() => void) | undefined onNext: (() => void) | undefined
onClose: (() => void) | undefined onClose: (() => void) | undefined
}) { }) {
const prompt = 'Run `next upgrade --ai=security` and follow its instructions.' const prompt =
'Run `next upgrade --agent=security` and follow its instructions.'
const animationProps = { const animationProps = {
'data-rendered': rendered, 'data-rendered': rendered,
style: { style: {
......
// Shared values keep event payloads consistent across the CLI, nudges, and handoffs. // Shared values keep event payloads consistent across the CLI, nudges, and handoffs.
export type AIUpgradePolicy = 'security' | 'latest' | 'experimental-future' export type AgentUpgradePolicy = 'security' | 'latest' | 'experimental-future'
export type AIUpgradeOrigin = export type AgentUpgradeOrigin =
| 'human_manual' | 'human_manual'
| 'human_nudge' | 'human_nudge'
| 'agent_manual' | 'agent_manual'
| 'agent_nudge' | 'agent_nudge'
export type AIUpgradeHandoffMethod = export type AgentUpgradeHandoffMethod =
| 'existing_agent' | 'existing_agent'
| 'launched_agent' | 'launched_agent'
| 'copied_prompt' | 'copied_prompt'
| 'printed_prompt' | 'printed_prompt'
export type AIUpgradeCLIResult = export type AgentUpgradeCLIResult =
| 'no_update_needed' | 'no_update_needed'
| 'no_safe_target' | 'no_safe_target'
| 'metadata_failure' | 'metadata_failure'
...@@ -29,61 +29,61 @@ function event<T extends object>(eventName: string, fields: T) { ...@@ -29,61 +29,61 @@ function event<T extends object>(eventName: string, fields: T) {
} }
// Measure configured reach separately from whether an upgrade reminder is needed. // Measure configured reach separately from whether an upgrade reminder is needed.
export function eventAIUpgradePolicyDetected(fields: { export function eventAgentUpgradePolicyDetected(fields: {
configuredPolicy: AIUpgradePolicy | false | null configuredPolicy: AgentUpgradePolicy | false | null
effectivePolicy: AIUpgradePolicy effectivePolicy: AgentUpgradePolicy
policySource: 'config' | 'environment' policySource: 'config' | 'environment'
sourceCommand: 'dev' | 'build' sourceCommand: 'dev' | 'build'
}) { }) {
return event('NEXT_AI_UPGRADE_POLICY_DETECTED', fields) return event('NEXT_AGENT_UPGRADE_POLICY_DETECTED', fields)
} }
// Correlate a displayed reminder with a later upgrade invocation. // Correlate a displayed reminder with a later upgrade invocation.
export function eventAIUpgradeNudgeShown(fields: { export function eventAgentUpgradeNudgeShown(fields: {
nudgeId: string nudgeId: string
recipient: 'human' | 'agent' recipient: 'human' | 'agent'
agentProduct: string | null agentProduct: string | null
sourceCommand: 'dev' | 'build' sourceCommand: 'dev' | 'build'
policy: AIUpgradePolicy policy: AgentUpgradePolicy
nudgeKind: AIUpgradePolicy nudgeKind: AgentUpgradePolicy
}) { }) {
return event('NEXT_AI_UPGRADE_NUDGE_SHOWN', fields) return event('NEXT_AGENT_UPGRADE_NUDGE_SHOWN', fields)
} }
// Human menus expose a decision directly; agent decisions are inferred from runs. // Human menus expose a decision directly; agent decisions are inferred from runs.
export function eventAIUpgradeNudgeDecision(fields: { export function eventAgentUpgradeNudgeDecision(fields: {
nudgeId: string nudgeId: string
action: 'update' | 'skip' | 'dismiss' | 'interrupt' action: 'update' | 'skip' | 'dismiss' | 'interrupt'
}) { }) {
return event('NEXT_AI_UPGRADE_NUDGE_DECISION', fields) return event('NEXT_AGENT_UPGRADE_NUDGE_DECISION', fields)
} }
// Count invocations independently of whether preparation or handoff finishes. // Count invocations independently of whether preparation or handoff finishes.
export function eventAIUpgradeRunStarted(fields: { export function eventAgentUpgradeRunStarted(fields: {
runId: string runId: string
nudgeId: string | null nudgeId: string | null
origin: AIUpgradeOrigin origin: AgentUpgradeOrigin
agentProduct: string | null agentProduct: string | null
requestedPolicy: AIUpgradePolicy | null requestedPolicy: AgentUpgradePolicy | null
}) { }) {
return event('NEXT_AI_UPGRADE_RUN_STARTED', fields) return event('NEXT_AGENT_UPGRADE_RUN_STARTED', fields)
} }
// Report the CLI's preparation and prompt delivery, not completion of the agent's work. // Report the CLI's preparation and prompt delivery, not completion of the agent's work.
export function eventAIUpgradeCLIResult(fields: { export function eventAgentUpgradeCLIResult(fields: {
runId: string runId: string
result: AIUpgradeCLIResult result: AgentUpgradeCLIResult
resolvedPolicy: AIUpgradePolicy | null resolvedPolicy: AgentUpgradePolicy | null
handoffMethod: AIUpgradeHandoffMethod | null handoffMethod: AgentUpgradeHandoffMethod | null
selectedAgentProduct: string | null selectedAgentProduct: string | null
}) { }) {
return event('NEXT_AI_UPGRADE_CLI_RESULT', fields) return event('NEXT_AGENT_UPGRADE_CLI_RESULT', fields)
} }
// The agent reports its verified result separately from the CLI's prompt delivery. // The agent reports its verified result separately from the CLI's prompt delivery.
export function eventAIUpgradeAgentResult(fields: { export function eventAgentUpgradeAgentResult(fields: {
runId: string runId: string
result: 'success' | 'failure' result: 'success' | 'failure'
}) { }) {
return event('NEXT_AI_UPGRADE_AGENT_RESULT', fields) return event('NEXT_AGENT_UPGRADE_AGENT_RESULT', fields)
} }
...@@ -45,7 +45,7 @@ describe('vulnerability insight', () => { ...@@ -45,7 +45,7 @@ describe('vulnerability insight', () => {
'[data-nextjs-vulnerability-prompt]' '[data-nextjs-vulnerability-prompt]'
) )
expect(displayedPrompt).toBe( expect(displayedPrompt).toBe(
'Run `next upgrade --ai=security` and follow its instructions.' 'Run `next upgrade --agent=security` and follow its instructions.'
) )
await clickInPortal(browser, '[aria-label="Copy prompt"]') await clickInPortal(browser, '[aria-label="Copy prompt"]')
...@@ -53,12 +53,12 @@ describe('vulnerability insight', () => { ...@@ -53,12 +53,12 @@ describe('vulnerability insight', () => {
await retry(async () => { await retry(async () => {
copiedPrompt = await browser.eval(() => navigator.clipboard.readText()) copiedPrompt = await browser.eval(() => navigator.clipboard.readText())
expect(copiedPrompt).toBe( expect(copiedPrompt).toBe(
'Run `next upgrade --ai=security` and follow its instructions.' 'Run `next upgrade --agent=security` and follow its instructions.'
) )
}) })
expect(copiedPrompt).toMatchInlineSnapshot( expect(copiedPrompt).toMatchInlineSnapshot(
`"Run \`next upgrade --ai=security\` and follow its instructions."` `"Run \`next upgrade --agent=security\` and follow its instructions."`
) )
}) })
}) })
This diff is collapsed.
...@@ -139,7 +139,7 @@ describe('prepare latest upgrade', () => { ...@@ -139,7 +139,7 @@ describe('prepare latest upgrade', () => {
upgrade: { upgrade: {
status: 'blocked', status: 'blocked',
reason: reason:
"The installed Next.js version (17.2.0-canary.4) is a canary prerelease. Security advisories target stable versions, and prereleases do not reliably follow stable version ordering, so an advisory could be a false positive. To upgrade to the latest canary release, run this command from the app's directory:\n\nnpx next@canary upgrade --ai=latest", "The installed Next.js version (17.2.0-canary.4) is a canary prerelease. Security advisories target stable versions, and prereleases do not reliably follow stable version ordering, so an advisory could be a false positive. To upgrade to the latest canary release, run this command from the app's directory:\n\nnpx next@canary upgrade --agent=latest",
}, },
}) })
await expect(prepareUpgrade(directory, 'security')).resolves.toMatchObject({ await expect(prepareUpgrade(directory, 'security')).resolves.toMatchObject({
...@@ -453,7 +453,7 @@ describe('prepare latest upgrade', () => { ...@@ -453,7 +453,7 @@ describe('prepare latest upgrade', () => {
upgrade: expect.objectContaining({ upgrade: expect.objectContaining({
status: 'blocked', status: 'blocked',
reason: expect.stringContaining( reason: expect.stringContaining(
'npx next@canary upgrade --ai=latest' 'npx next@canary upgrade --agent=latest'
), ),
}), }),
}) })
...@@ -483,7 +483,7 @@ describe('prepare latest upgrade', () => { ...@@ -483,7 +483,7 @@ describe('prepare latest upgrade', () => {
upgrade: expect.objectContaining({ upgrade: expect.objectContaining({
status: 'blocked', status: 'blocked',
reason: expect.stringContaining( reason: expect.stringContaining(
'npx next@canary upgrade --ai=latest' 'npx next@canary upgrade --agent=latest'
), ),
}), }),
}) })
...@@ -497,10 +497,10 @@ describe('prepare latest upgrade', () => { ...@@ -497,10 +497,10 @@ describe('prepare latest upgrade', () => {
const directory = await createApp(version) const directory = await createApp(version)
global.fetch = jest.fn() global.fetch = jest.fn()
await expect(prepareUpgrade(directory, 'latest')).rejects.toThrow( await expect(prepareUpgrade(directory, 'latest')).rejects.toThrow(
'AI upgrades are not available for this prerelease version of Next.js.' 'Agent upgrades are not available for this prerelease version of Next.js.'
) )
await expect(getUpgradeAssessment(version, 'latest')).rejects.toThrow( await expect(getUpgradeAssessment(version, 'latest')).rejects.toThrow(
'AI upgrades are not available for this prerelease version of Next.js.' 'Agent upgrades are not available for this prerelease version of Next.js.'
) )
expect(global.fetch).toHaveBeenCalledTimes(0) expect(global.fetch).toHaveBeenCalledTimes(0)
}) })
......
...@@ -169,7 +169,7 @@ describe('security upgrade nudge', () => { ...@@ -169,7 +169,7 @@ describe('security upgrade nudge', () => {
name: 'SecurityFatalError', name: 'SecurityFatalError',
exitCode: 1, exitCode: 1,
message: expect.stringMatching( message: expect.stringMatching(
/affected by a known security vulnerability[\s\S]*\*\*We strongly recommend you upgrade Next\.js\.\*\*[\s\S]*upgrade recommendation\. Retry the same command to continue the original task\.[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*ask the user once:[\s\S]*in a separate Git worktree\?[\s\S]*Use their worktree choice and continue in this agent session[\s\S]*Run this command from this app's directory:[\s\S]*next upgrade --ai=(?:security|latest|experimental-future)/ /affected by a known security vulnerability[\s\S]*\*\*We strongly recommend you upgrade Next\.js\.\*\*[\s\S]*upgrade recommendation\. Retry the same command to continue the original task\.[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*ask the user once:[\s\S]*in a separate Git worktree\?[\s\S]*Use their worktree choice and continue in this agent session[\s\S]*Run this command from this app's directory:[\s\S]*next upgrade --agent=(?:security|latest|experimental-future)/
), ),
}) })
expect(warn).not.toHaveBeenCalled() expect(warn).not.toHaveBeenCalled()
...@@ -529,7 +529,7 @@ describe('latest upgrade nudge', () => { ...@@ -529,7 +529,7 @@ describe('latest upgrade nudge', () => {
name: 'UpgradeNudgeError', name: 'UpgradeNudgeError',
exitCode: 1, exitCode: 1,
message: expect.stringMatching( message: expect.stringMatching(
/Next\.js 17\.0\.0 is available\.[\s\S]*\*\*We recommend you upgrade Next\.js\.\*\*[\s\S]*upgrade recommendation\. Retry the same command to continue the original task\.[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*ask the user once:[\s\S]*in a separate Git worktree\?[\s\S]*Use their worktree choice and continue in this agent session[\s\S]*Run this command from this app's directory:[\s\S]*next upgrade --ai=(?:security|latest|experimental-future)[\s\S]*registry\.npmjs\.org/ /Next\.js 17\.0\.0 is available\.[\s\S]*\*\*We recommend you upgrade Next\.js\.\*\*[\s\S]*upgrade recommendation\. Retry the same command to continue the original task\.[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*ask the user once:[\s\S]*in a separate Git worktree\?[\s\S]*Use their worktree choice and continue in this agent session[\s\S]*Run this command from this app's directory:[\s\S]*next upgrade --agent=(?:security|latest|experimental-future)[\s\S]*registry\.npmjs\.org/
), ),
}) })
await expect( await expect(
...@@ -631,7 +631,7 @@ describe('composed latest nudge', () => { ...@@ -631,7 +631,7 @@ describe('composed latest nudge', () => {
await expect(nudge).rejects.toMatchObject({ await expect(nudge).rejects.toMatchObject({
name: 'SecurityFatalError', name: 'SecurityFatalError',
exitCode: 1, exitCode: 1,
message: expect.stringContaining(`next upgrade --ai=${policy}`), message: expect.stringContaining(`next upgrade --agent=${policy}`),
}) })
await expect(nudge).rejects.toMatchObject({ await expect(nudge).rejects.toMatchObject({
message: expect.stringContaining( message: expect.stringContaining(
...@@ -768,7 +768,7 @@ describe('composed future nudge', () => { ...@@ -768,7 +768,7 @@ describe('composed future nudge', () => {
).rejects.toMatchObject({ ).rejects.toMatchObject({
name: 'UpgradeNudgeError', name: 'UpgradeNudgeError',
message: expect.stringMatching( message: expect.stringMatching(
/Next\.js 17\.0\.0 is available[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*next upgrade --ai=(?:security|latest|experimental-future)/ /Next\.js 17\.0\.0 is available[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*next upgrade --agent=(?:security|latest|experimental-future)/
), ),
}) })
}) })
...@@ -891,7 +891,7 @@ describe('human upgrade nudge', () => { ...@@ -891,7 +891,7 @@ describe('human upgrade nudge', () => {
}) })
jest.mocked(getAgentName).mockResolvedValue('codex') jest.mocked(getAgentName).mockResolvedValue('codex')
await expect(run(policy)).rejects.toMatchObject({ await expect(run(policy)).rejects.toMatchObject({
message: expect.stringContaining(`next upgrade --ai=${policy}`), message: expect.stringContaining(`next upgrade --agent=${policy}`),
}) })
} }
) )
...@@ -983,7 +983,7 @@ describe('human upgrade nudge', () => { ...@@ -983,7 +983,7 @@ describe('human upgrade nudge', () => {
{ {
revision: 'latest', revision: 'latest',
verbose: false, verbose: false,
ai: policy, agent: policy,
}, },
null null
) )
...@@ -1044,7 +1044,7 @@ describe('human upgrade nudge', () => { ...@@ -1044,7 +1044,7 @@ describe('human upgrade nudge', () => {
await expect( await expect(
nudgeUpgrade(directory, config(false), 'dev', null, null, null) nudgeUpgrade(directory, config(false), 'dev', null, null, null)
).rejects.toMatchObject({ ).rejects.toMatchObject({
message: expect.stringContaining('next upgrade --ai=latest'), message: expect.stringContaining('next upgrade --agent=latest'),
}) })
}) })
...@@ -1154,7 +1154,7 @@ describe('human upgrade nudge', () => { ...@@ -1154,7 +1154,7 @@ describe('human upgrade nudge', () => {
const preferences = new Conf({ projectName: 'nextjs' }) const preferences = new Conf({ projectName: 'nextjs' })
const name = appPath === '.' ? 'project%2Ename' : 'web' const name = appPath === '.' ? 'project%2Ename' : 'web'
const saved = preferences.get(`ai-upgrade.${name}`) as Record< const saved = preferences.get(`agent-upgrade.${name}`) as Record<
string, string,
unknown unknown
> >
......
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