Currently, there’s a family member of mine who absolutely despises AI. Removed from the tech world, AI’s only benefit to this person is limited to lukewarm answers about Google search results. AI’s costs abound, however: white collar work opportunities are dwindling, power costs are rising, smog is thickening, noise is invading, temperatures are climbing, literal relics are disappearing, IQs are sinking, oligarchy is ____, etc. etc.
The rain clouds of AI are dark and gloomy, and agents still aren’t solving all of our legacy codebase problems; however, with more powerful models, and some judicious human intervention, AI paired with me is resulting in some real progress.
Legacy Codebase
I’ve been working in a challenging codebase for a couple of years now. On the business side of things, the public facing web app has been valuable for users across the world, having handled incredibly spiky workloads. The app itself is a tool for conducting in-person events that happen simultaneously around the world. Our stakeholders appreciate, perhaps even unguardedly, how the simple tasks orchestrate complex connections across our company. What they are guarded against, however, is making changes to prod. Some production problems in the past have severely limited their appetite for change. So, deployments are allowed twice a year, with strict, manual processes to ensure an unremarkable release day.
The codebase itself is challenging because, given that precedent, the Javascript code beginning in 2018 has not been modernized except against stiff resistance. When modernization has happened, it’s been in spurts – things like the monorepo pattern, single-table database design, vite, vitest, and Typescript to a degree. Feature work has squeezed out much of our remaining tech debt focus – proving the idea that the last 20% of work seems to take 80% of the time.
Furthermore, there are around a million lines of source code that encompass the app’s frontend, backends, serverless architecture, cli, test data, and scripting. There have been some hurried decisions, and it’s evident that the codebase does not have the melodic flow of those owned by dedicated engineers. Front end form state is handled one way in one page, and then another elsewhere. Observability logs are regimented strictly in one microservice, but are scant in another. One group of AWS resources is deployed with CloudFormation, and another with custom scripting. Needless to say, the small things were this way too: Imports, prettier, linting compliance, for-loops, pure/impure functions, and the like.
Please don’t get me wrong, though, I’m not here to shame the previous engineers – I don’t know what their requirements were at the time, or how thinly they were stretched. I only hope this paints a picture for the seemingly simple, yet underlying change I’m about to make: getting AI to replace the package manager.
Package Managers
Javascript is so massively popular because it’s so well plugged into the open source community. It’s effortless to stand on someone else’s shoulders and spin up a server, run a smartwatch, write a desktop app, go 3D, or even do object detection. The package manager is the secret sauce gluing it all up for you to build off of. It puts together a bill of materials for code to go fetch from the internet, so practically all you have to do in your code is drop in some if-statements, a couple loops, and maybe a piece of art, and viola, you’ve got a 3D teaching tool for flight instruction. If those “shoulders” your code stood on needs other code, and that code needs someone else’s code, it builds a tree with all of that, and then fetches it all in one go. Do you want to get your “materials” from a better “shop,” like from a private space for just your company? Package managers can do that. Need to override where a package comes from, regardless of whatever package needed it (all the way down the tree)? A package manager can do that. Want to combine multiple projects into one big “monorepo?” A package manager can do that gracefully.
pnpm and why it’s cool
npm can do all that, but pnpm is cooler for a number of reasons. Version 12 is rewritten in rust, making it faster. It is disk-space efficient by caching packages locally, so many projects using something common, like core-js, can point to a local copy. This is a big deal because of that javascript-open-source-community thing. Javascript is notorious for needing oodles of code from across the web.
Another big win, especially over npm, is the built-in security.
You know that the tree of packages from the internet? Each one in the x-thousand-line lock file is a
stranger you’re trusting. In npm, any package can include a prepare hook that is
automatically triggered when you install it, often invisibly. There have been
actual hacks (“Shai Hulud” attacks) just from doing
npm install on this code. Fortunately, pnpm blocks this by default, letting you include a whitelist if you actually
needed such a service. pnpm can even do this on a time basis, rejecting ultra-fresh versions to accommodate for code
that hasn’t been vetted by the public yet. pnpm can check for signatures too, cryptographic proof that code wasn’t
tampered with.
The Migration
Despite the security benefits, I was captivated by a faster install (and perhaps shiny syndrome), so off I went in an attempt to modernize my team’s repo. My company grants us Claude access, so I figured, surely I could do this without too much hangup. I can always bump up to a larger model!
The first thing that Claude failed to understand was the need for overrides in our repo. We are on a popular package that switched from free to paid and have been running on a branched version ever since. Given its use in two of the monorepo project overrides solved that. When Claude made its first conversion from npm to pnpm, it simply ignored that part of our configuration. This was only discovered by building in our pipeline, so this became a multi-day effort.
The next hurdle was compiling javascript into the various outputs. In one subproject, we test with jest, in another with
vitest, and to make things more interesting, in another we use jest but compile with swc (to make
Jeremy Clarkson proud!). Did you know that pnpm sticks packages (as
aliases) inside node_modules/.pnpm/? I didn’t. As I began running test scripts, I started to discover that some test
configurations looked into node_modules. It took AI (and myself) several additional attempts to figure out the correct
new paths for those configs.
Trouble Along the Way
I should back up for a moment. One thing I failed to do correctly was feed AI better context. AI had a concept in mind
that matched mine, of what we were trying to do. We wanted to see pnpm as the declared package manager, and assumed
that find-and-replace could just make npm -> pnpm and npx -> pnpm exec. But it was probably as surprised as I was to
see test scripts failing. If I was AI, I would’ve complained about the goal posts moving. That wasn’t part of the job
description!
At one point, it did another very human thing, it came across an error reported by aws-sdk. It reasoned that we should
just upgrade it to solve the problem. This was a fundamental dependency in our projects, so that was immediately
rejected by me. And, as it turns out, of course that had nothing to do with the problem at hand.
The Antidote
If I were to convert an npm project today, I would tell AI what my goals were explicitly: “make sure tests, linting, and build scripts pass for each project in the repo.” Then I would specify where to find them. Often it incorrectly assumed that partial passes were not its own fault, so I would tell AI to get a baseline first.
I would also clarify what expectations I need to comply with. Often, builds would pass in the pipeline, but then in an attempt to fix some configuration locally, it would change something to break the pipeline again. Had I said, “builds must pass in the CI/CD pipeline. Report to me when you are ready for that,” then AI could’ve added my work to its criteria.
Success and Earned Epiphanies
I won’t bore you with the rest of the details. It took some retries, even from a reset branch, to get the project converted. I should’ve spent more time writing agent skills so that it knew where to look for env vars, or how to deal with some tech debt in our tests (gratuitous logs).
I will highlight some impressive feats, though. AI hopped right over our longstanding CommonJS javascript to EJS
typescript conversion – meaning that it knew exactly how to configure their own, and their downstream dependents’ own
package.json files. I really appreciate this because, being so risk-averse, little changes are best. It hopped right
over some broken project bounds (cross-project imports) too.
If I were to tackle this on my own, honestly, I would probably have failed without unlimited time. The amount of variables that went into this, as well as the amount of dead ends I would’ve hit would have been huge. Just as much as AI needed me for context and steering, I needed it so I could maintain hope across the dead ends we did discover.
If attention is all you need then share with AI what you do, and what you don’t, pay attention to. Just because AI is pointed at your 1M line codebase, doesn’t mean it has a grasp of even the most frequently viewed lines of code.
Before the Hurricane Hits (Conclusion)
Legacy codebases are difficult for AI for a few reasons. There is a long history of decisions that natural neural networks pick up on through prior experience, chatting with fellow engineers, and perhaps a little lingering “judgy disapproval” (is this our last, unconquerable human trait, calibrated “judgy disapproval?”). Legacy codebases are larger by nature too, so making a change to shared code is harder than for a greenfield project. It’s easy to vibe-code a trading dashboard, but it’s hard to vibe-code a bank.
Along with legacy codebases come real-world constraints too, like timelines, risk profiles, and change tolerances. AI cannot solve these. They are rooted in human emotions.
For these reasons, if the AI storm is on the horizon to take our jobs, I’m not so convinced it’s headed our way. In fact, the rising water has helped us loosen some deeply seated tech debt. AI used to have a hard time with large changes like that. I’m no weatherman, so I can’t speak to the trajectory of AI, but I can point out to the other run-aground boats out there: there’s a good chance the tide will lift you free.