depkill 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +179 -3
  3. package/data/module-replacements.LICENSE +21 -0
  4. package/data/module-replacements.json +947 -0
  5. package/dist/src/anticheat/constants.js +105 -0
  6. package/dist/src/anticheat/imports.js +419 -0
  7. package/dist/src/anticheat/tokens.js +177 -0
  8. package/dist/src/anticheat.js +189 -0
  9. package/dist/src/card/format.js +113 -0
  10. package/dist/src/card/svg.js +137 -0
  11. package/dist/src/card.js +364 -0
  12. package/dist/src/check.js +139 -0
  13. package/dist/src/cli.js +333 -0
  14. package/dist/src/gate/holdout.js +78 -0
  15. package/dist/src/gate/process.js +78 -0
  16. package/dist/src/gate.js +532 -0
  17. package/dist/src/graph.js +148 -0
  18. package/dist/src/holdout/perturb.js +108 -0
  19. package/dist/src/holdout/snapshot.js +113 -0
  20. package/dist/src/init.js +76 -0
  21. package/dist/src/inputs/generate.js +282 -0
  22. package/dist/src/inputs.js +273 -0
  23. package/dist/src/measure.js +149 -0
  24. package/dist/src/project.js +72 -0
  25. package/dist/src/record.js +180 -0
  26. package/dist/src/registry.js +78 -0
  27. package/dist/src/replacement.js +146 -0
  28. package/dist/src/runner.js +227 -0
  29. package/dist/src/runtime/agent-inputs.js +36 -0
  30. package/dist/src/runtime/child.js +260 -0
  31. package/dist/src/runtime/esm-hooks.js +44 -0
  32. package/dist/src/runtime/fsguard.js +264 -0
  33. package/dist/src/runtime/inspect.js +115 -0
  34. package/dist/src/runtime/lockdown.js +157 -0
  35. package/dist/src/runtime/protocol.js +16 -0
  36. package/dist/src/scan.js +210 -0
  37. package/dist/src/serialize.js +399 -0
  38. package/dist/src/tooling.js +88 -0
  39. package/dist/src/types.js +9 -0
  40. package/dist/src/usage/common.js +36 -0
  41. package/dist/src/usage/fallback.js +227 -0
  42. package/dist/src/usage/ts.js +142 -0
  43. package/dist/src/usage.js +97 -0
  44. package/dist/src/util/exports.js +86 -0
  45. package/dist/src/util/fs.js +64 -0
  46. package/dist/src/util/term.js +61 -0
  47. package/package.json +54 -6
  48. package/skills/AGENTS.section.md +52 -0
  49. package/skills/depkill/SKILL.md +148 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 depkill contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,179 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # depkill
2
+
3
+ [![CI](https://github.com/feritcemkahraman/depkill/actions/workflows/ci.yml/badge.svg)](https://github.com/feritcemkahraman/depkill/actions/workflows/ci.yml)
4
+ [![Node >=20](https://img.shields.io/badge/node-%3E%3D20-339933.svg)](package.json)
5
+ [![Zero dependencies](https://img.shields.io/badge/dependencies-0-brightgreen.svg)](package.json)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
7
+
8
+ **Delete your dependencies. Prove nothing broke.**
9
+
10
+ Every dependency is code you run but did not write, as the 2026 npm supply-chain attacks on axios, TanStack
11
+ (Mini Shai-Hulud) and keyv (CHAINDROP) showed. depkill lets your coding agent rewrite small dependencies as a few
12
+ lines of your own code, then checks the replacement against your real usage, plus fresh nearby inputs answered by
13
+ a recorded copy of the original, and fails if any compared output differs.
14
+
15
+ ![depkill card from a local run on expressjs/express (not an upstream change)](.github/card-example.svg)
16
+
17
+ depkill does not call an LLM and never sends your code anywhere. Your own agent (Claude Code, Codex, Cursor, ...)
18
+ writes the replacement; depkill measures, records, replays and decides whether the removal passes. The only data
19
+ that leaves your machine is package names and versions, sent to the npm registry for maintainer counts (`scan`,
20
+ `card`), plus the installs your package manager runs for `card`; `--offline` turns the registry requests off.
21
+
22
+ ## 60-second quickstart
23
+
24
+ In a project with its dependencies installed (Node 20 or newer):
25
+
26
+ ```sh
27
+ npx depkill init
28
+ ```
29
+
30
+ This installs the agent instructions: a Claude Code skill in `.claude/skills/depkill/SKILL.md` and a marked
31
+ section in `AGENTS.md` (`--agent claude|agents|all`, default `all`; re-running replaces the section instead of
32
+ duplicating it). Then ask your agent:
33
+
34
+ > use depkill to remove my smallest dependencies
35
+
36
+ It will scan, pick a candidate, record it, write a replacement, and loop on `check` and `gate` until the removal
37
+ passes, then render the card.
38
+
39
+ ### Doing it by hand
40
+
41
+ ```sh
42
+ npx depkill scan # rank direct dependencies by payoff / effort
43
+ npx depkill record <pkg> # record how <pkg> behaves in this project
44
+ # write src/vendor/<pkg-safe>.ts and .depkill/<pkg-safe>/config.json: { "replacement": "src/vendor/<pkg-safe>.ts" }
45
+ npx depkill check <pkg> # replay the recorded cases against your replacement
46
+ # rewire the imports, npm uninstall <pkg>
47
+ npx depkill gate <pkg> # the done rule: every check below must pass
48
+ npx depkill card # measured before/after card, badge and report
49
+ ```
50
+
51
+ | Command | Options |
52
+ |---|---|
53
+ | `init` | `--agent claude\|agents\|all` |
54
+ | `scan` | |
55
+ | `record <pkg>` | `--max-generated N` (type-generated cases per export, default 200) |
56
+ | `check <pkg>` | `--replacement <path>` (instead of `config.json`) |
57
+ | `gate <pkg>` | `--test-cmd "<cmd>"`, `--skip-tests` |
58
+ | `card` | |
59
+
60
+ Global options: `--cwd <dir>`, `--json` (machine-readable stdout), `--offline` (no npm registry requests; the
61
+ card's installs use the package manager's offline mode). Exit codes: `0` ok, `1` check or gate failed, `2` usage
62
+ or configuration error. Scoped packages use `@scope__name` as their `.depkill/` directory name.
63
+
64
+ ## How the proof works
65
+
66
+ **record** runs the original package in an isolated Node child process (independent of your test runner) on
67
+ inputs from three sources: literal arguments at your call sites, argument lists your agent writes to
68
+ `.depkill/<pkg-safe>/inputs.mjs`, and inputs generated from the package's type declarations. It records the return
69
+ value, the thrown error and any mutation of the arguments; timeouts, nondeterministic results and values it cannot
70
+ compare are marked unsupported and never count as evidence. It also keeps the original `package.json` and lockfile
71
+ (`.depkill/baseline/`, on the first record), the original source (for copy detection) and a runnable copy of the
72
+ package with its dependency closure (for the holdout check after the package is gone).
73
+
74
+ **replace**: your agent writes one self-contained file, for example `src/vendor/<pkg-safe>.ts`, and points
75
+ `.depkill/<pkg-safe>/config.json` at it.
76
+
77
+ **check** replays every comparable case against the replacement in the same runtime. Exports are looked up
78
+ strictly (`#default` must be the default export), a run with zero comparable cases fails ("nothing was proven"),
79
+ and the replacement must be a project file (not under `node_modules` or `.depkill`).
80
+
81
+ **gate** is the done rule. Every check must pass or be legitimately skipped (the reason is listed, and the card
82
+ discloses a skipped `tests` or `holdout` check):
83
+
84
+ - `cases-real`: every real-usage case (call sites and `inputs.mjs`) matches, and every used export has evidence: at
85
+ least one comparable real case, and no more uncomparable real cases than comparable ones (a plain-value export
86
+ needs one comparable case of any source). An export that cannot be proven fails the gate.
87
+ - `cases-generated`: every mismatching generated case is listed in `accepted.json` with a reason; at most 10% of the compared generated cases.
88
+ - `holdout`: up to 60 fresh inputs near real usage (one argument nudged), answered by the original snapshot and the replacement, must match.
89
+ - `removed`: the package is gone from every dependency field of `package.json`.
90
+ - `no-new-deps`: no dependency was added since the baseline.
91
+ - `no-imports-left`: no source file imports or requires the package any more.
92
+ - `wired`: at least one project source file imports or requires each configured replacement file.
93
+ - `ships`: when `package.json` declares `files`, any replacement imported by a shipped file is also covered by `files`.
94
+ - `self-contained`: the replacement imports only allowlisted Node builtins, no `eval`, no references to `.depkill` or `node_modules`.
95
+ - `not-copied`: the replacement shares under 60% of its 5-token sequences with the original source, raw and with local names normalized.
96
+ - `no-embedded-outputs`: recorded string outputs are not pasted into the replacement in bulk.
97
+ - `typecheck`: `tsc --noEmit` passes (skipped without a `tsconfig.json` or TypeScript).
98
+ - `tests`: the project's test script, or `--test-cmd`, passes (skipped when there is no test script, or with `--skip-tests`).
99
+
100
+ The holdout inputs are derived from a hash of the replacement and the recorded cases: the same code always gets
101
+ the same verdict, and changing the code draws new inputs, so special-casing them does not help. Holdout is skipped
102
+ (and shown as skipped) when no argument can be varied, when every nearby input is already recorded, or when the
103
+ original could not be snapshotted (for example, over 50 MB).
104
+
105
+ Replacements only ever run inside a locked-down child: `--disallow-code-generation-from-strings`, a builtin
106
+ allowlist (`assert`, `buffer`, `crypto`, `events`, `fs`, `os`, `path`, `punycode`, `querystring`, `stream`,
107
+ `string_decoder`, `timers`, `url`, `util`, `zlib` and their subpaths), blocked module loading, network globals and
108
+ `process.binding`, and an `fs` guard that refuses paths under `.depkill`, `node_modules` or outside the project. On
109
+ Node versions with the stable permission model (`--permission`, Node 22.13+ or 23.5+) file reads are also confined
110
+ by Node itself; elsewhere the gate prints `runtime sandbox: off` and the card says `unsandboxed run`.
111
+
112
+ ## What the numbers mean
113
+
114
+ - A package counts only when its gate passed and `gate.json` still matches the replacement files and recorded
115
+ cases it judged, and the package is still out of `package.json` and every import. Stale or failed gates are
116
+ skipped and named.
117
+ - Before and after are measured with clean installs in temporary directories (install scripts off) of
118
+ `.depkill/baseline/` and of the current `package.json` and lockfile, with your package manager. Nothing is
119
+ estimated from your own `node_modules`.
120
+ - A removed package that another dependency still pulls in is marked `still via <dep>` (dev-only pulls are marked
121
+ `(dev)`, and differing versions are shown); the savings are what the installs measured, which can be zero.
122
+ - Maintainer counts come from the npm registry and are left out with `--offline`. The report adds
123
+ production-only numbers next to the totals.
124
+ - The card footer states the evidence: `Proven by N real-usage cases (N call-site, N agent-written) + N generated + N fresh holdout cases`,
125
+ plus `N accepted mismatches`, `unsandboxed run`, `tests skipped`, `holdout skipped` and `typecheck skipped` whenever they apply.
126
+ - Dependencies removed after the first `record` without a gate (for example unused ones you simply uninstalled)
127
+ are included in the totals and named in a caveat line on the card and in the report.
128
+ - Any package additions, upgrades or removals between the baseline and current graphs outside the removed packages'
129
+ closures (lockfile drift) are disclosed in a caveat line on the card and listed in the report.
130
+
131
+ `depkill card` needs at least one package whose gate passed. It writes `.depkill/card.svg`, `.depkill/badge.svg`
132
+ and `.depkill/report.md`.
133
+
134
+ ## What to commit
135
+
136
+ `depkill record` creates `.depkill/.gitignore` (if missing) to ignore `*/original/`, `*/runtime/`, `.build/` and
137
+ `*/check.json`. Commit your replacement files, `package.json`, lockfile, and — if you want the proof and
138
+ evidence checked into the repo — `.depkill/baseline/`, `cases.jsonl`, `meta.json`, `inputs.mjs`, `accepted.json`,
139
+ `config.json`, `gate.json` and the generated card/report. If your linter or test runner scans dot-folders (such as
140
+ ESLint flat config), add `.depkill/` to its ignores.
141
+
142
+ ## Limits
143
+
144
+ - A gate pass means outputs matched on the recorded and holdout inputs, not on every possible input.
145
+ - Values are compared by their own string properties (including non-enumerable properties), property descriptors
146
+ (`writable`, `enumerable`, `configurable`, getter/setter presence and read value), and null prototypes; symbol
147
+ properties, getter side effects, and class prototype chains are not compared (class instances compare by class name
148
+ and own properties/descriptors).
149
+ - v1 covers pure synchronous and async functions and constants. Streams, event emitters, stateful class
150
+ instances, timers, I/O, callbacks passed in or functions returned, and nondeterministic output are detected at
151
+ record time and marked unsupported. Native modules, packages over 5 MB exclusive, more than 8 used exports, and
152
+ packages used only by tooling, CLIs or types are flagged unsupported by `scan`. Large frameworks, browser-specific
153
+ behavior and non-JS languages are out of scope.
154
+ - Single-package projects only: npm/yarn `workspaces` and `pnpm-workspace.yaml` are refused.
155
+ - Call-site and type-generated inputs need the project's own `typescript`; without it only `inputs.mjs` is used.
156
+ - `.vue`, `.svelte` and `.astro` files are scanned with the regex fallback scanner only; `dist/`, `build/`,
157
+ `coverage/` and dot-folders are not scanned, so `no-imports-left` cannot see imports there.
158
+ - The holdout snapshot does not include peer dependencies, pnpm aliases or symlinked files; a package relying on
159
+ them may not run from the snapshot.
160
+ - The baseline is taken at the first `record`; a dependency added after that fails `no-new-deps`.
161
+ - The anti-cheat checks stop shortcuts (copying, importing the original, reading the recorded cases, lookup
162
+ tables of outputs). They are not tamper-proof against a person who edits `.depkill/` by hand (cases, baseline,
163
+ `accepted.json`); review those diffs like any other code.
164
+ - The full runtime sandbox needs Node 22.13+ or 23.5+; on other versions the replay is reported as unsandboxed.
165
+
166
+ ## Zero dependencies
167
+
168
+ depkill has zero runtime dependencies. It uses your project's own TypeScript when it is installed.
169
+
170
+ ## Credits
171
+
172
+ - Inspired by [erkamyaman/rust-anything](https://github.com/erkamyaman/rust-anything): record behavior, let an
173
+ agent port it, replay and gate. depkill applies the idea to deleting npm dependencies.
174
+ - Alternative hints in `scan` come from [e18e module-replacements](https://github.com/e18e/module-replacements)
175
+ ([MIT License](data/module-replacements.LICENSE), Copyright (c) 2024 James Garbutt), bundled in `data/module-replacements.json`.
176
+
177
+ ## License
178
+
179
+ MIT
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 James Garbutt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.