Unverified Commit 27bd0415 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Allow agentic upgrades without Git (#99217)

### Why?

Apps without a Git repository should still be able to use agentic
upgrades, including upgrades started from a configured reminder.

### How?

Check for duplicate work using the repository and provider capabilities
available to the app. Direct the agent to upgrade in place when Git is
absent, and use Git worktrees, commits, and pull requests when
available.

<!-- NEXT_JS_LLM -->
parent 98b6fd86
......@@ -6,13 +6,14 @@ version: draft
## Before changing files: check for duplicates
- [ ] Identify the repository provider from `git remote -v`, then use its CLI or
API to list every open pull request. For GitHub, run
- [ ] Check the app for an equivalent upgrade or Future Defaults adoption already
in progress.
- [ ] If the app is in a Git repository, check local branches and commits. If it
has a remote, also check remote branches and commits.
- [ ] If the repository has a provider remote, use its CLI or API to look for
open pull requests with equivalent work. For GitHub, run
`gh pr list --state open --limit 100 --json number,title,body,url,headRefName`.
- [ ] Inspect the body and diff of likely matches. For GitHub, run
`gh pr diff <number>`.
- [ ] Check local and remote branches and commits for an equivalent upgrade or
Future Defaults adoption.
Inspect the body and diff of likely matches with `gh pr diff <number>`.
Look for unmarked work and these markers:
......@@ -21,27 +22,35 @@ Look for unmarked work and these markers:
<!-- next-upgrade: <type>; path="apps/web" -->
```
Do not substitute Git history for the provider lookup. If any check is
unavailable, fails, or finds existing work, stop before changing files and
report it. Continue only when every check finds no equivalent work.
Do not require Git to upgrade an app. Attempt each check that applies to the
app's repository and remote. Do not substitute Git history for an available
provider lookup. If a check is unavailable or fails, report which work could
not be checked and continue the upgrade. Stop before changing files only if
you find equivalent work.
## After all upgrade and adoption steps: commit and deliver
- [ ] Commit the verified version update before Future Defaults adoption. For a
different-major update, use one commit for each crossed major, containing
- [ ] If the app is in a Git repository, commit the verified version update
before Future Defaults adoption. For a different-major update, use one
commit for each crossed major, containing
that major's surviving final-target changes. Do not add transitional
changes solely to make an intermediate version work. Include source and
target versions in each commit message and explain why and how.
- [ ] Group Future Defaults changes by the default adopted. Explain why and how
in each commit message.
- [ ] With permission, recheck open pull requests for duplicates and publish one
draft PR with the app marker:
- [ ] Group Future Defaults changes by the default adopted. If the app is in a
Git repository, explain why and how in each commit message.
- [ ] If the repository has a provider remote, with permission, recheck open
pull requests for duplicates. If you find equivalent work, report it and
do not publish another PR. If the recheck is unavailable, report that and
deliver the verified local changes. Otherwise, publish one draft PR with
the app marker:
```md
<!-- next-upgrade: <type>; path="." -->
<!-- next-upgrade: <type>; path="apps/web" -->
```
- [ ] If permission to open a PR has not been granted, ask the user whether to
open one when reporting the completed work.
- [ ] If the app has no Git repository or provider remote, deliver the verified
local changes and report that a PR requires a repository and remote.
- [ ] If a PR is possible but permission has not been granted, ask the user
whether to open one when reporting the completed work.
- [ ] If work is incomplete, report completed work, the blocker, and how to resume.
......@@ -449,11 +449,11 @@ export async function spawnNextUpgrade(
const taskSummary = needsVersionUpdate
? `We're upgrading the app in ${JSON.stringify(baseDir)} from Next.js ${result.installedVersion} to ${result.targetVersion} because ${reason}.`
: `We're adopting the Future Defaults available to the app in ${JSON.stringify(baseDir)}, which already uses Next.js ${result.installedVersion}.`
const prompt = `Read and follow ${JSON.stringify(sharedGuidePath)} first. Complete its duplicate checks before changing files. Then read and follow every applicable instruction in ${JSON.stringify(guidePath)}.
const prompt = `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)}.
${taskSummary}
Unless the user explicitly requests otherwise, perform the upgrade in a separate Git worktree. Run upgrade commands from this app's corresponding directory in that worktree.
If the app is in a Git repository, perform the upgrade in a separate Git worktree unless the user explicitly requests otherwise. Run upgrade commands from this app's corresponding directory in that worktree. If the app is not in a Git repository, upgrade it in place.
Set \`experimental.agenticAutoUpgrade\` to ${JSON.stringify(upgradeType)} in the app's Next.js config as part of this upgrade. Preserve unrelated configuration. If the target Next.js version does not support this option, skip the setting and report why.
......
......@@ -284,7 +284,7 @@ When you report back to the user, include this upgrade recommendation even if th
${
command
? `At the end of the task, ask the user whether they want you to run the upgrade using the configured '${reminder.policy}' policy in the background in a separate Git worktree unless they request otherwise. Run this command from this app's directory:
? `At the end of the task, ask the user whether they want you to run the upgrade using the configured '${reminder.policy}' policy in the background. If the app is in a Git repository, use a separate Git worktree unless they request otherwise. If the app is not in a Git repository, upgrade it in place. Run this command from this app's directory:
\`\`\`
${command}
......
......@@ -470,11 +470,11 @@ describe('agentic upgrade prompts', () => {
expect(normalizedBootstrapCalls()).toMatchInlineSnapshot(`
[
[
"Read and follow "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/shared.md" first. Complete its duplicate checks before changing files. Then read and follow every applicable instruction in "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/different-major.md".
"Read and follow "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/shared.md" 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 "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/different-major.md".
We're upgrading the app in "/workspace/app" from Next.js 14.1.1 to 16.3.5 because the installed version is affected by a published security advisory.
Unless the user explicitly requests otherwise, perform the upgrade in a separate Git worktree. Run upgrade commands from this app's corresponding directory in that worktree.
If the app is in a Git repository, perform the upgrade in a separate Git worktree unless the user explicitly requests otherwise. Run upgrade commands from this app's corresponding directory in that worktree. If the app is not in a Git repository, upgrade it in place.
Set \`experimental.agenticAutoUpgrade\` to "security" in the app's Next.js config as part of this upgrade. Preserve unrelated configuration. If the target Next.js version does not support this option, skip the setting and report why.
......@@ -567,11 +567,11 @@ describe('agentic upgrade prompts', () => {
expect(normalizedBootstrapCalls()).toMatchInlineSnapshot(`
[
[
"Read and follow "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/shared.md" first. Complete its duplicate checks before changing files. Then read and follow every applicable instruction in "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/same-major.md".
"Read and follow "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/shared.md" 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 "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/same-major.md".
We're upgrading the app in "/workspace/app" from Next.js 16.2.12 to 16.3.5 because a newer stable Next.js release is available.
Unless the user explicitly requests otherwise, perform the upgrade in a separate Git worktree. Run upgrade commands from this app's corresponding directory in that worktree.
If the app is in a Git repository, perform the upgrade in a separate Git worktree unless the user explicitly requests otherwise. Run upgrade commands from this app's corresponding directory in that worktree. If the app is not in a Git repository, upgrade it in place.
Set \`experimental.agenticAutoUpgrade\` to "latest" in the app's Next.js config as part of this upgrade. Preserve unrelated configuration. If the target Next.js version does not support this option, skip the setting and report why.
......@@ -755,11 +755,11 @@ describe('agentic upgrade prompts', () => {
{
"prompt": [
[
"Read and follow "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/shared.md" first. Complete its duplicate checks before changing files. Then read and follow every applicable instruction in "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/same-major.md".
"Read and follow "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/shared.md" 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 "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/same-major.md".
We're upgrading the app in "/workspace/app" from Next.js 16.2.0 to 16.4.0 because the Future policy applies the latest stable release and adopts its Future Defaults.
Unless the user explicitly requests otherwise, perform the upgrade in a separate Git worktree. Run upgrade commands from this app's corresponding directory in that worktree.
If the app is in a Git repository, perform the upgrade in a separate Git worktree unless the user explicitly requests otherwise. Run upgrade commands from this app's corresponding directory in that worktree. If the app is not in a Git repository, upgrade it in place.
Set \`experimental.agenticAutoUpgrade\` to "future" in the app's Next.js config as part of this upgrade. Preserve unrelated configuration. If the target Next.js version does not support this option, skip the setting and report why.
......@@ -854,11 +854,11 @@ describe('agentic upgrade prompts', () => {
expect(normalizedBootstrapCalls()).toMatchInlineSnapshot(`
[
[
"Read and follow "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/shared.md" first. Complete its duplicate checks before changing files. Then read and follow every applicable instruction in "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/future-defaults.md".
"Read and follow "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/shared.md" 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 "/tmp/next-upgrade-test/docs/01-app/02-guides/upgrading/agentic-upgrade/future-defaults.md".
We're adopting the Future Defaults available to the app in "/workspace/app", which already uses Next.js 16.4.0.
Unless the user explicitly requests otherwise, perform the upgrade in a separate Git worktree. Run upgrade commands from this app's corresponding directory in that worktree.
If the app is in a Git repository, perform the upgrade in a separate Git worktree unless the user explicitly requests otherwise. Run upgrade commands from this app's corresponding directory in that worktree. If the app is not in a Git repository, upgrade it in place.
Set \`experimental.agenticAutoUpgrade\` to "future" in the app's Next.js config as part of this upgrade. Preserve unrelated configuration. If the target Next.js version does not support this option, skip the setting and report why.
......
......@@ -159,7 +159,7 @@ describe('security upgrade nudge', () => {
name: 'SecurityFatalError',
exitCode: 1,
message: expect.stringMatching(
/affected by a published security advisory[\s\S]*\*\*We strongly recommend you upgrade Next\.js\.\*\*[\s\S]*reminder you configured is not missed\. Retry the same command to continue the original task\.[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*At the end of the task, ask the user whether they want you to run the upgrade using the configured 'security' policy in the background in a separate Git worktree unless they request otherwise\. Run this command from this app's directory:[\s\S]*```\nnext upgrade --ai=(?:security|latest|future)\n```/
/affected by a published security advisory[\s\S]*\*\*We strongly recommend you upgrade Next\.js\.\*\*[\s\S]*reminder you configured is not missed\. Retry the same command to continue the original task\.[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*If the app is in a Git repository, use a separate Git worktree unless they request otherwise\.[\s\S]*If the app is not in a Git repository, upgrade it in place\. Run this command from this app's directory:[\s\S]*```\nnext upgrade --ai=(?:security|latest|future)\n```/
),
})
expect(warn).not.toHaveBeenCalled()
......@@ -397,7 +397,7 @@ describe('latest upgrade nudge', () => {
name: 'UpgradeNudgeError',
exitCode: 1,
message: expect.stringMatching(
/Next\.js 17\.0\.0 is available\.[\s\S]*\*\*We recommend you upgrade Next\.js\.\*\*[\s\S]*reminder you configured is not missed\. Retry the same command to continue the original task\.[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*At the end of the task, ask the user whether they want you to run the upgrade using the configured 'latest' policy in the background in a separate Git worktree unless they request otherwise\. Run this command from this app's directory:[\s\S]*```\nnext upgrade --ai=(?:security|latest|future)\n```[\s\S]*registry\.npmjs\.org[\s\S]*agenticAutoUpgrade: 'latest'/
/Next\.js 17\.0\.0 is available\.[\s\S]*\*\*We recommend you upgrade Next\.js\.\*\*[\s\S]*reminder you configured is not missed\. Retry the same command to continue the original task\.[\s\S]*include this upgrade recommendation even if the retry succeeds\.[\s\S]*If the app is in a Git repository, use a separate Git worktree unless they request otherwise\.[\s\S]*If the app is not in a Git repository, upgrade it in place\. Run this command from this app's directory:[\s\S]*```\nnext upgrade --ai=(?:security|latest|future)\n```[\s\S]*registry\.npmjs\.org[\s\S]*agenticAutoUpgrade: 'latest'/
),
})
await expect(
......
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