Skip to content

Menu

Playbooks

Have an agent upgrade a dependency

Upgrade a dependency on an isolated branch with Antigravity CLI while reviewing network access, install scripts, the lockfile, tests, and rollback.

min read
18
Level
Advanced
Last verified

This playbook uses Antigravity CLI for dependency maintainers and reviewers. Its outputs are an upgrade plan, a manifest-and-lockfile diff, and a test and rollback record.

The example upgrades a small library in the fictional demo-notes project from 2.3.1 to 2.4.0. Names, versions, outputs, and release notes are synthetic, and commands were not run. This guidebook does not document package-manager syntax, install scripts, lockfiles, caches, or registry domains. Follow official package-manager and project documentation.

This is an independent project and is not affiliated with Google.

In plain English: A dependency upgrade is more than a version edit

Section titled “In plain English: A dependency upgrade is more than a version edit”

A dependency upgrade can change four kinds of state at the same time: the version range in the manifest, resolutions in the lockfile, a local installation directory or cache, and scripts that may run during installation. The first two are usually visible in a Git diff; the other two may not be. Asking an agent to “upgrade it and test it” compresses fetching, script execution, lockfile changes, and testing into one action, leaving no useful pause before the risky part.

A safer sequence is to establish a baseline on a new branch; have the agent identify the package manager, target version, possible network domain, and expected files without making changes; approve network access and commands one at a time; and independently inspect the manifest, lockfile, tests, and Git state. For the general methods of understanding before editing and keeping the change minimal, see Understand a codebase and Perform a small refactor with tests as a safety net.

Weak prompt:

Upgrade tiny-slug to the latest version, handle everything you can automatically, and commit it if the tests pass.

This prompt does not pin the target version, restrict the files, make network access and install scripts separate approval points, or keep the commit under human control. Even if the final tests pass, you still do not know why the lockfile changed, what ran during installation, or how to return to the baseline.

Better prompt:

Inspect the repository in read-only mode first. Do not edit files, access the network, or run commands.
The goal is to upgrade the fictional dependency @demo-notes/tiny-slug from 2.3.1 to 2.4.0.
Report the package manager, manifest, lockfile, expected changes, exact network domain,
install-script risk, before-and-after tests, and both rollback paths. Wait for my approval before
requesting permissions. Do not commit, push, edit CI or tests, or upgrade other dependencies.

In CLI plan mode, the agent investigates with read-only search and viewing tools and presents a plan before implementation begins. See Your first agent task: Use execution modes and permissions as guardrails for the exact behavior and ways to change modes.

Complete example: Upgrade one small library in demo-notes

Section titled “Complete example: Upgrade one small library in demo-notes”

The fictional repository contains package.json, dependency.lock, a dependency policy, local release notes, src/make-note-id.js, and its test.

The synthetic package.json pins @demo-notes/tiny-slug to 2.3.1. The local release notes say that 2.4.0 is the target minor version and requires no call-site changes. The dependency policy says to upgrade one direct dependency at a time and preserve existing tests. This exercise permits changes only to package.json and dependency.lock. In a real project, you must still check real release notes, security notices, and repository policies. Pages elsewhere in this guidebook do not explain how to obtain and verify those materials. Follow the official pages of the dependency project, package manager, and your organization.

Below, <UPGRADE_COMMAND> means the verified command that upgrades only the target dependency, and <REGISTRY_DOMAIN> means the exact registry domain that command needs to access.

Step 0: Establish a Git baseline outside the CLI

Section titled “Step 0: Establish a Git baseline outside the CLI”

Have a person inspect the worktree and create the branch, rather than delegating isolation itself to the agent:

终端窗口
git status --short
git switch -c chore/upgrade-tiny-slug-2-4
git rev-parse --short HEAD

Expected record (fictional, not run): the status is empty, the branch is correct, and the baseline commit is a1b2c3d. If the first command produces output, stop and isolate the existing work instead of mixing it into the upgrade diff.

Step 1: Inventory the change in read-only plan mode

Section titled “Step 1: Inventory the change in read-only plan mode”

Start in plan mode without expanding permissions; see Your first agent task: Use execution modes and permissions as guardrails for the command:

终端窗口
agy --mode=plan
This is the synthetic demo-notes repository. The goal is to upgrade @demo-notes/tiny-slug
from 2.3.1 to 2.4.0.
[Allowed scope]
Only package.json and dependency.lock may be changed by the end.
[Forbidden]
Do not edit files, access the network, or run shell commands yet.
Throughout the task, do not modify src/, test/, scripts, CI, or other dependencies.
Do not commit or push.
[Plan first]
1. Identify the package manager, manifest, lockfile, and upgrade policy.
2. Check the local release notes and decide whether call-site changes are needed.
3. Show the command, exact domain, and install-script risk for approval, but do not run it.
4. List before-and-after tests, diff checks, and rollback.
5. Separate known facts from package-manager behavior that still needs verification.

An acceptable plan names only the two allowed files, separates network and install-script approval, and runs node --test before and after. Use Artifacts and plans: kinds, surface differences, and how to judge a plan to return plans containing extra dependencies, automatic test edits, or a commit.

Step 2: Run the baseline test before editing

Section titled “Step 2: Run the baseline test before editing”

After approving the plan, switch to default mode and keep commands subject to individual review. In default, the CLI shows a diff before an edit and, under the default tool permission, asks before running a command. Confirm the actual mode and permission in the status and configuration rather than assuming them; see Your first agent task: Use execution modes and permissions as guardrails.

Approve only the baseline test:

终端窗口
node --test

Require the exact command, output summary, and exit status. The synthetic expected result (fictional, not run) is tests 4; pass 4; fail 0; exit status 0.

If the baseline already fails, stop the upgrade. Record the failure as an existing issue rather than letting the agent “fix it along the way” by changing tests or implementation. See Locate and fix a bug for the general debugging sequence.

Step 3: Narrow network access to one explicit request

Section titled “Step 3: Narrow network access to one explicit request”

The terminal sandbox has no network by default. Allowing read_url(domain) adds the domain to its outbound allowlist, after which sandboxed commands can connect to it. Allow only the verified <REGISTRY_DOMAIN>, never read_url(*), and remove the rule afterward. See Permissions and sandbox: what presets, rules, and the sandbox each control for the boundaries.

Before approval, confirm that the domain matches repository configuration, the command targets only the dependency at 2.4.0, the agent has described install-script risk, and the approval will not become a broad persistent rule.

Sources cited elsewhere in this guidebook do not document registry domains, redirects, proxies, or package-manager network behavior. Follow official package-manager documentation, repository configuration, and organizational network policy. If the domain or command effect is uncertain, do not begin installation.

Step 4: Treat install scripts as a separate risk

Section titled “Step 4: Treat install scripts as a separate risk”

Continue in default. When the agent requests <UPGRADE_COMMAND>, first require the complete command and an explanation of whether dependency install scripts will run, where they come from, and whether official documentation provides an inspection or suppression mechanism. Do not invent a flag from memory. Pages elsewhere in this guidebook do not document this behavior, so follow the corresponding package manager’s official documentation.

The sandbox limits files and network available to shell commands, but the worktree remains writable. An allow rule may permit a matching command inside and outside the sandbox. Read the full command, approve this occurrence only, and do not allow all package-manager commands or use --dangerously-skip-permissions. See Permissions and sandbox: what presets, rules, and the sandbox each control for these boundaries. If policy forbids install scripts and you cannot verify a control, stop.

Step 5: Inspect the file set before the lockfile details

Section titled “Step 5: Inspect the file set before the lockfile details”

After the command finishes, remain in default mode and do not let the agent continue into implementation fixes. First ask it to report git status --short, then run these commands yourself:

终端窗口
git status --short
git diff --stat
git diff -- package.json dependency.lock

Confirm that only the two allowed files changed, the direct dependency moved only from 2.3.1 to 2.4.0, the lockfile has no unrelated drift, and no configuration, log, or temporary file appeared. Tests must remain unchanged.

A lockfile may have different structures depending on the resolver, platform, or package-manager version. Sources cited elsewhere in this guidebook do not define which differences are “normal.” Follow the tool version pinned by the project, official package-manager documentation, and repository review rules. Reject lockfile changes you do not understand instead of accepting the whole file merely because it is generated.

In the CLI, /diff shows all changes or per-turn changes. Review the file list first, each diff second, and then cross-check with Git and tests that you run yourself. See Review agent changes before you accept them for that product behavior and review sequence.

Step 6: Run the same test set and record the result

Section titled “Step 6: Run the same test set and record the result”

Once the file set is correct, approve the same command used for the baseline:

终端窗口
node --test

The synthetic expected post-upgrade result (fictional, not run) remains tests 4; pass 4; fail 0; exit status 0.

Passing tests show only that this set found no regression; they do not prove security or compatibility on every platform. Put other repository-required checks in the plan, and do not edit tests to manufacture a pass. See Add tests for an existing function for adding coverage.

Step 7: Produce the review record without committing

Section titled “Step 7: Produce the review record without committing”

Ask the agent to stop editing and only organize the record:

Stop modifying files. Separate observations from unknowns and record the baseline branch and commit,
version change, actual files, commands and network authorization, install-script status and evidence,
tests before and after, unknowns, and rollback both before and after a commit.
Do not commit, push, or continue fixing anything.

The record must match the terminal, Git diff, and test output. Independently follow Review agent changes before you accept them before acceptance.

Anti-pattern 1: Use auto to finish everything in one pass

Section titled “Anti-pattern 1: Use auto to finish everything in one pass”
Enter auto, upgrade this dependency to 2.4.0, fix every compatibility issue, and commit if the tests pass.

Problem: auto automatically accepts worktree edits and lets the system evaluate commands that leave the sandbox, making it easy to mix several change types in one turn. It is not individual human review. See Before enabling auto or Turbo: risks, acceptable cases, and reversal for the product behavior and risks.

Rewrite: use plan first to list files, domains, commands, and script risk. Return to default, then separately approve the baseline test, precise network scope, one upgrade command, and post-upgrade test. Leave committing to a person.

Anti-pattern 2: Accept the agent’s summary without reviewing

Section titled “Anti-pattern 2: Accept the agent’s summary without reviewing”
The agent says it upgraded one package and all tests are green, so I do not need to inspect the lockfile.

Problem: the summary may omit transitive drift, new files, or weakened tests. Rewrite: inspect the file set with git status --short and git diff --stat, read the actual manifest and lockfile diff, and rerun the tests yourself. See Review agent changes before you accept them for review entry points and sequence.

  • The worktree was clean, and the task runs on an isolated branch or worktree.
  • The dependency and versions are pinned; the task does not say “latest.”
  • The plan stage was read-only, and only package.json and dependency.lock were listed as writable files.
  • The baseline test actually ran and was recorded before the upgrade.
  • Network permission covers one exact domain, not read_url(*).
  • The complete command was read, and install-script risk was considered separately.
  • No permissive mode or dangerous flag bypassed review.
  • Git status and file diffs contain only explainable expected changes.
  • The same tests ran afterward, without edits that manufacture a pass.
  • Temporary rules were removed, rollback and unknowns were recorded, and a person decides on committing.

When you decide to abandon this upgrade, save the status and diff first. If this task’s uncommitted changes are limited to the two allowed files, inspect them and then run:

终端窗口
git restore -- package.json dependency.lock

If other tracked files have changes, determine the owner of each change and restore them individually instead of including them in the command above. Inspect untracked files individually before deleting them; do not use a broad cleanup command. For an isolated commit, use a reversing commit that preserves history:

终端窗口
git revert <UPGRADE_COMMIT>

These are general Git commands and were not run for this page. /rewind rolls back conversation history; the official page does not say that it restores files on disk, so use Git for file recovery. See Your first agent task: Use execution modes and permissions as guardrails for the distinction between conversation and file rollback.

When network access or an install script causes side effects, Git can restore only tracked files. This guidebook provides no unified cleanup for caches, installation directories, user configuration, external requests, or files outside the worktree. Follow official documentation for the package manager, dependency project, and operating system. Preserve the command and output, and do not let the agent clean automatically before the impact is understood.

When tests fail, do not broaden the task. Preserve the upgrade diff and failure output and decide whether the target version caused the failure. If it cannot be explained within the original scope, roll back the upgrade and open a separate task using Locate and fix a bug rather than letting the agent upgrade a dependency, edit implementation, and edit tests at the same time.

Confirm permission boundaries and review each file. Split defects, coverage, and call-site changes into separate bug-fix, testing, or refactoring tasks.