I don’t usually pay much attention to the frontend build chain. It wasn’t until I saw that 57MB cli.js.map that I realized a single config file can put an entire project’s source code as-is into a public registry, with no attack required.
The facts are simple: when a certain command-line tool shipped a release, the map files in its build output weren’t excluded, so they went public along with the npm package. Anyone who downloads it and unpacks the JSON gets over 1,900 source files and more than 500,000 lines of TypeScript.
Why map files contain source code
Code in modern frontend and Node projects goes through bundling, minification, and obfuscation. The final js output has variables named a, b, c, with all the logic crammed onto one line. It runs fast, but when something breaks in production the stack trace only points to “line one, column umpteen-thousand,” which is useless for debugging.
Source maps exist for exactly this: a JSON file that records the correspondence between minified positions and original positions. When the browser devtools read it, they can restore the minified code into a readable directory structure.
The most basic one only needs the mappings field. But most build tools offer an extra option called inline sources. Turn it on, and the tool stuffs the full original content of every file into the sourcesContent array, matched one-to-one with the paths in sources. The design makes sense: when debugging you don’t have to fetch the original files again—with the map in hand, you can read the code.
The problem is that this option sits right next to the minification config, so it’s easy to flip on as “debug-related” and then forget to turn off in the production build.
There’s also a more basic reason: npm packages are public by default. Whatever is in the tarball you push is what the whole world can download—no auth, no “internal only” option. So filtering files before a release isn’t bundle-size optimization; it’s a security boundary. Once that line gets treated as “packaging config,” someone will cut corners and drop the entire output directory in.
Restoring it takes no real skill
1 | const map = JSON.parse(fs.readFileSync('cli.js.map', 'utf8')); |
The real work is paths: build tools write webpack:// prefixes, node: protocols, and relative paths starting with ../../ into sources. Without sanitizing them, you can end up writing outside the project directory. That’s an engineering detail of the script, not “cracking.” What people call a source leak is often just someone bundling text that was never meant to be public into a public archive.
The only thing to watch is the final check: after resolve, confirm the target path is still inside the output directory. Without that step, a single record starting with ../../ can write files into system directories, turning the extraction tool into an arbitrary-write tool.
One easy-to-misread point along the way: the total file count isn’t the same as “your own code.” The thousands of entries in sources include dependencies, runtime patches, and type declarations for wrapper layers; only about 1,900 source files actually belong to the tool itself. That difference doesn’t change the conclusion, but it shows how heavily this kind of project depends on third-party code.
What leaked isn’t mainly about the model
I’d assumed the core of an AI tool like this would be prompts and API calls. After reading the structure, I changed my mind: the part that calls the model is a small fraction, and the code volume is concentrated outside the model.
Session state is held by a dedicated engine: message history, abort controllers, permission-denial records, token usage, file-state caches, dynamically discovered skill names. Each item looks trivial on its own, but together they describe a long-running process that can be killed at any moment and has to track usage—not a question-and-answer chat box.
My first reaction on seeing these fields was: a chat box doesn’t need these. An abort controller means someone might hit stop at any time; permission-denial records mean it gets blocked often, and once blocked it has to remember, so it doesn’t keep hitting the same wall; token accounting kept separately means cost is managed as a primary metric.
Tool execution is streaming. The traditional approach waits for the model to finish emitting the full tool-call JSON, parses it, then executes. This one chooses to start running the tool as soon as the complete arguments arrive in the streaming response, overlapping local I/O with the model’s remaining output. Over forty tools, each with an input schema and tiered permissions; independent calls get split into parallel batches.
Permissions aren’t a boolean. The same set of tools behaves differently across default, auto, skip, and fully-allowed modes, and behind that design are two very different usage scenarios: someone casually asking questions in a terminal, and someone wiring it into a pipeline to batch-modify repos. Covering both with one permission model is either too noisy or too dangerous.
When context approaches the threshold, compaction kicks in, folding early long outputs into summaries. On long tasks this is mandatory, or the window will definitely blow up. Compaction loses information by nature, so the trigger threshold and retention policy are worth tuning more than the compaction algorithm itself.
Prompts aren’t one static block either. General instructions are cached across sessions; things like the working directory and Git status get reassembled every time. There’s even a bluntly named function in the source that marks “don’t cache this section,” to keep dynamic content from polluting the hit rate. It’s a small detail, but it explains why this kind of tool keeps its time-to-first-token down.
What’s worth taking from this source
The terminal UI uses React and a Zustand-like state management setup. At first it seemed heavy, but on reflection it makes sense: streaming replies, showing progress for multiple tools, and preparing diff previews all at once—maintaining those partial updates with imperative cursor control would rot the code fast.
There’s another decision in the UI layer worth noting: it doesn’t drive the whole tree from global state. Instead, the high-frequency part updates on its own, and the rest only re-renders when session state changes. That split holds for any real-time interface, terminal or not. I once wrote a batch-task panel with a progress bar, and the first version refreshed everything—the fan spun louder than the tasks themselves.
Putting it all together, my judgment is this: the differentiation in these products increasingly lies in the harness—the scheduling and state management wrapped around the model—not in the prompts. Prompts determine style; the harness determines whether it can run for an hour in a repo with tens of thousands of lines without breaking. The former can be copied; the latter has to be fed bug by bug.
Eighty percent of an Agent’s difficulty lies outside the model.
That’s not a defense of anyone. Reading this as a “wrapper” misjudges both its engineering effort and your own cost to replicate it.
The little Agent I wrote myself was missing exactly these “outside the model” things. No abort control—after the user hits Ctrl-C, the tool keeps running in the background. No permission-denial records—a blocked call gets retried next time. No file-state cache—the same file gets read five times in ten minutes. None of these show up in a demo; use it for two hours straight and they all surface.
So I treat this source as a checklist, not a template. What can be copied is those few fields and state transitions; what can’t is the layer upon layer of trade-offs behind them—that only grows out of hitting real problems in real projects a few times.
The cost of a default value
Files like this usually enter the repository through very ordinary paths: someone runs git add . after a local build; CI caches dist and passes it to downstream jobs; or a “backup artifacts” directory that nobody cleans up. They don’t throw errors, and tests don’t catch them—they just get shipped along with some release.
What they have in common is that the default favors “bundle everything.”
This isn’t one person’s oversight either; it’s the result of long-term toolchain evolution. In TypeScript, inlineSources is off by default, but once someone turns it on for debugging, the config stays in the repository; bundlers generate maps by default in production mode, and build scripts written to troubleshoot problems often just copy the dev config. Each choice is reasonable on its own; stacked together, the production package ships with full source code.
Also, a version published to npm can’t be taken back. Deleting the package or bumping the version number only hides it from later users—the copies already downloaded, synced to mirrors, and sitting in other people’s caches are all still there. There’s no after-the-fact fix for this kind of problem; you can only check before publishing.
The problem with the blacklist approach (.npmignore) isn’t that it’s hard to use—it’s that it misses things. Directories added during iteration, temporary artifacts, test scripts—anything not explicitly added gets pushed to the public registry. A whitelist (the package.json files field) works the other way: anything not listed is never published. New files won’t be covered and it needs maintenance, but it’s the only boundary that can be mechanically verified.
The ten minutes before publishing
Size itself is the first signal. A minified command-line tool should normally be a few hundred KB to a few MB; if a package is absurdly large, something probably wasn’t excluded. My habit now is to check the package size before a release and compare it with the previous version—if it grew for no good reason, open the file list and investigate.
More direct is npm pack --dry-run, which lists every file about to go into the tarball; a single grep line in CI can block .map. When taking over an old project, I like to save the current file list as a baseline first, then diff against it on every release—configs go stale, but what actually gets packed doesn’t. To be safer, have the script decide directly: fail if .map, .ts, .env appear, or if the size is abnormal. It costs ten minutes each time, plus half an hour to write the script—compared with one incident, it’s not a hard call.
On the monitoring side, there’s a more thorough approach: generate hidden map files at build time (without writing the sourceMappingURL comment at the end of the artifact), upload them to the error monitoring platform in CI, delete the local maps immediately after a successful upload, and then publish the clean artifact. Production errors can still be traced to the original line and column, while nothing external contains a single character of source. This workflow requires a few extra lines of pipeline script; I think it’s worth it.
There’s another exit that’s easy to overlook: dependencies. Not publishing your own maps doesn’t mean the packages in node_modules don’t publish theirs; if they contain inline source, it will still end up in the artifact. I’ve seen a third-party component library’s maps get bundled into dist in a project because the build config treated node_modules the same way. When checking what gets published, it’s best to look at dependencies too.
My own projects are much smaller, but I changed two things: I filled out the files whitelist completely, and added a packaging preview step to the release script. It was a bit annoying at first—every new directory meant going back to add a line. Once I thought clearly about the difference between “deny by default” and “allow by default,” it stopped being annoying.
If I could only do one thing, I’d add that grep line in CI. It doesn’t depend on anyone remembering, and it doesn’t depend on verbal reminders during handover.
The most absurd part of this is that there’s no attack, no zero-day vulnerability—just a default value that wasn’t changed. I treat it as a reminder about my own process: anything included by default deserves a second look.
Comments