What the agent does
The agent first reads what the lock file says, because that is where the notice lives. In a Vite and React app like adrianocola/spyfall, package.json pins "shortid": "2.2.16" exactly, and package-lock.json records that version as deprecated with the text Package no longer supported. The same entry shows what it drags along: nanoid ^2.1.0, locked at 2.1.11. So the app already ships an old copy of the library it is about to adopt. The agent lists the calls, and there are two, both shortid.generate(): one in app/reducers/config.js, where the CREATE_CUSTOM_LOCATION case makes a locationId, and one in app/containers/Game/GameManager.jsx, which sends a fresh matchId with each new game.
Before changing the generator it traces where each id goes, since an id is a value other code may have opinions about. The locationId becomes a key of customLocations in the Redux state, which this app persists in the browser and can export and import. The matchId goes through updateGame into the room record that other players read, and Locations.jsx uses it as an effect dependency to reset which locations a player has crossed out. Nothing parses either id, checks its length or validates it in database.rules.json. They are opaque strings, so ids made last year by shortid keep working beside new ones.
Then it compares the two generators on the properties that could matter. Both draw from the same 64 characters: letters, digits, _ and -. None of those is a character Firebase Realtime Database forbids in a key. The length differs: shortid ids are short and vary, and nanoid() always returns 21 characters. The agent keeps the default length and notes the one-argument form, nanoid(10), in the pull request for anyone who wants shorter keys. It replaces import shortid from 'shortid' with import { nanoid } from 'nanoid' and the two calls with nanoid().
Choosing the version is the step people get wrong. This repository pins Node 20 in .nvmrc and in the engines field. The newest nanoid major declares ^22 || ^24 || >=26 in its own engines, so installing it on this project's Node produces an engine warning, or a failed install where engine-strict is set. The agent reads both fields and installs the 5.x line, whose range is ^18 || >=20. After npm install it confirms that shortid and the nested nanoid 2.1.11 are gone from the lock file, runs npm run lint, and builds with vite build. The repository has no test script, so it adds none unless asked and says so.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "Replace the shortid package with nanoid in this JavaScript app. Read package.json, the lock file entry for shortid including any deprecated field and its own dependencies, .nvmrc and the engines field. List every use of shortid: generate, isValid, characters, seed and worker. If anything other than generate is used, stop and report it, because nanoid has no equivalent for those. For each generated id, trace where the value goes: state, local storage, a database key or path, a URL, a React key or effect dependency. Report anything that parses the id, checks its length or pattern, or validates it in database rules. Write a script that generates ids with both libraries and prints the set of characters and the range of lengths each produces, and check those characters against the rules of every place the ids are stored. Choose the newest nanoid major whose engines range includes the project's Node version and say which range excluded the newer one. Keep nanoid's default length unless a consumer needs the old length; say how to shorten it. Make the change, run npm install, and show that shortid and any nanoid copy it pulled in are no longer in the lock file. Do not move id generation to a different place in the code, even if it sits in a reducer; report that separately. Run the lint script and a production build and include their output. Open a pull request.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
- Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
- Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.
What comes back
A pull request touching app/reducers/config.js, app/containers/Game/GameManager.jsx, package.json and package-lock.json. The description contains the trace of both ids, the character and length comparison from the script, the two engines ranges that decided the version, and the lint and build output. It states plainly that existing ids are not migrated and do not need to be: a custom location saved under a shortid key last year loads the same way after the change.
The reviewer's attention goes to two notes. One is the alternative the agent did not take: shortid 2.2.17 exists, is not flagged deprecated on npm and depends on nanoid 3, so raising the pin by one patch would also clear the notice with no code change. The pull request says why it went further, which is that the app then depends on one id library directly instead of on a wrapper around an older copy of it. The other is an observation left unfixed: CREATE_CUSTOM_LOCATION generates its id inside the reducer, so replaying that action produces a different key each time. Moving the call into the action creator is a behaviour change and belongs in its own pull request.
Run it on every Linear issue moved to a workflow state
For a change that touches stored ids, a team may want to read the plan before any code moves. A linear trigger supports that with its states setting, which maps a state name to plan or exec. Add an automation to the Project with the prompt above and a trigger on linear.issue.state_changed. Map your triage state to plan and your in-progress state to exec. Connect Linear first, in the console under Settings → Connections.
Moving an issue into the plan state starts a read-only run that posts its plan as a comment on the issue: the trace of each id and the version it would choose. Moving it on to the exec state starts an ordinary run that opens the pull request. Only a move made by someone in your Rush org fires the trigger.
The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.
Why run it on Rush?
The risky part of swapping an id generator is not the two lines that call it. It is every place an old id is already stored and every rule a new id has to satisfy. The agent reads those consumers in the repository, then measures the generators in its own sandbox instead of quoting their documentation, and the script and its output travel with the pull request.
The version choice is also checked, not assumed. Installing the newest major on the project's pinned Node and reading what npm prints takes a clean environment with exactly that Node, and the sandbox provides one for the length of the run. A reviewer sees the engines ranges, the install output and the build result in the session's record.
Frequently asked questions
Do I need to regenerate ids that shortid already created?
No. Both libraries produce plain strings from the same URL-safe characters, and nothing in the id says which library made it. Old and new ids coexist as long as your code treats them as opaque keys. The agent verifies that by searching for anything that parses or validates the id.
Can I keep ids as short as shortid's?
Yes: pass a size, as in nanoid(10). A shorter id has a higher chance of collision at a given volume, so pick the length from how many ids you expect to create. The agent keeps the 21-character default unless a consumer in your code requires the old length.
Why not the newest nanoid?
Each nanoid major narrows the Node versions it supports, and the newest one's engines field starts at Node 22. A project pinned to Node 20 gets a warning or a failed install from it. The 5.x line supports Node 18 and 20 and has the same nanoid() call.
Is nanoid safe to use for tokens?
It draws from the platform's cryptographic random source, crypto.getRandomValues in a browser, so its ids are not predictable from earlier ones. Whether 21 characters is enough for a secret depends on your threat model. This migration only replaces identifiers and adds no new use.
More jobs like this: Turn a Linear label into a PR
- Migrate a Blazor App from SQL Server to PostgreSQL (Blazor)
- Migrate a Streamlit App to the Anthropic Messages API from a Linear Issue (Streamlit)
- Migrate a Go CLI From urfave/cli v1 to v2 (urfave/cli)
- Migrate a Vue 3 App From Vuex to Pinia (Vuex)
- Migrate From Winston to Pino in a Node.js Service (Winston)
- Move JWTs From localStorage to httpOnly Cookies in an Express API (jsonwebtoken)