unpeek 1.0.0 → 1.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 (104) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +278 -246
  3. package/README.tr.md +260 -0
  4. package/bin/unpeek.mjs +7 -7
  5. package/dist/ast/index.cjs +802 -0
  6. package/dist/ast/index.cjs.map +1 -0
  7. package/dist/ast/index.d.cts +9 -0
  8. package/dist/ast/index.d.ts +9 -4
  9. package/dist/ast/index.js +762 -52
  10. package/dist/ast/index.js.map +1 -0
  11. package/dist/browser.cjs +816 -0
  12. package/dist/browser.cjs.map +1 -0
  13. package/dist/browser.d.cts +3 -0
  14. package/dist/browser.d.ts +3 -0
  15. package/dist/browser.js +773 -0
  16. package/dist/browser.js.map +1 -0
  17. package/dist/bundler/detector.cjs +180 -0
  18. package/dist/bundler/detector.cjs.map +1 -0
  19. package/dist/bundler/detector.d.cts +9 -0
  20. package/dist/bundler/detector.d.ts +6 -3
  21. package/dist/bundler/detector.js +130 -135
  22. package/dist/bundler/detector.js.map +1 -0
  23. package/dist/bundler/sourcemap-vault.cjs +210 -0
  24. package/dist/bundler/sourcemap-vault.cjs.map +1 -0
  25. package/dist/bundler/sourcemap-vault.d.cts +6 -0
  26. package/dist/bundler/sourcemap-vault.d.ts +6 -2
  27. package/dist/bundler/sourcemap-vault.js +161 -85
  28. package/dist/bundler/sourcemap-vault.js.map +1 -0
  29. package/dist/bundler/unplugin.cjs +848 -0
  30. package/dist/bundler/unplugin.cjs.map +1 -0
  31. package/dist/bundler/unplugin.d.cts +14 -0
  32. package/dist/bundler/unplugin.d.ts +14 -7
  33. package/dist/bundler/unplugin.js +805 -51
  34. package/dist/bundler/unplugin.js.map +1 -0
  35. package/dist/cli/index.cjs +1361 -0
  36. package/dist/cli/index.cjs.map +1 -0
  37. package/dist/cli/index.d.cts +3 -0
  38. package/dist/cli/index.d.ts +3 -1
  39. package/dist/cli/index.js +1300 -85
  40. package/dist/cli/index.js.map +1 -0
  41. package/dist/cli/init.cjs +200 -0
  42. package/dist/cli/init.cjs.map +1 -0
  43. package/dist/cli/init.d.cts +13 -0
  44. package/dist/cli/init.d.ts +10 -2
  45. package/dist/cli/init.js +162 -46
  46. package/dist/cli/init.js.map +1 -0
  47. package/dist/cli/protect.cjs +1147 -0
  48. package/dist/cli/protect.cjs.map +1 -0
  49. package/dist/cli/protect.d.cts +5 -0
  50. package/dist/cli/protect.d.ts +5 -2
  51. package/dist/cli/protect.js +1107 -83
  52. package/dist/cli/protect.js.map +1 -0
  53. package/dist/esbuild.cjs +844 -0
  54. package/dist/esbuild.cjs.map +1 -0
  55. package/dist/esbuild.d.cts +11 -0
  56. package/dist/esbuild.d.ts +11 -0
  57. package/dist/esbuild.js +807 -0
  58. package/dist/esbuild.js.map +1 -0
  59. package/dist/index.cjs +1453 -0
  60. package/dist/index.cjs.map +1 -0
  61. package/dist/index.d.cts +14 -0
  62. package/dist/index.d.ts +9 -4
  63. package/dist/index.js +1395 -8
  64. package/dist/index.js.map +1 -0
  65. package/dist/rollup.cjs +844 -0
  66. package/dist/rollup.cjs.map +1 -0
  67. package/dist/rollup.d.cts +11 -0
  68. package/dist/rollup.d.ts +11 -0
  69. package/dist/rollup.js +807 -0
  70. package/dist/rollup.js.map +1 -0
  71. package/dist/runtime/index.cjs +88 -0
  72. package/dist/runtime/index.cjs.map +1 -0
  73. package/dist/runtime/index.d.cts +23 -0
  74. package/dist/runtime/index.d.ts +23 -4
  75. package/dist/runtime/index.js +57 -15
  76. package/dist/runtime/index.js.map +1 -0
  77. package/dist/{types.d.ts → types-BTMkXmVE.d.cts} +14 -12
  78. package/dist/types-BTMkXmVE.d.ts +73 -0
  79. package/dist/vite.cjs +844 -0
  80. package/dist/vite.cjs.map +1 -0
  81. package/dist/vite.d.cts +11 -0
  82. package/dist/vite.d.ts +11 -0
  83. package/dist/vite.js +807 -0
  84. package/dist/vite.js.map +1 -0
  85. package/dist/webpack.cjs +844 -0
  86. package/dist/webpack.cjs.map +1 -0
  87. package/dist/webpack.d.cts +11 -0
  88. package/dist/webpack.d.ts +11 -0
  89. package/dist/webpack.js +807 -0
  90. package/dist/webpack.js.map +1 -0
  91. package/package.json +164 -67
  92. package/dist/ast/cold-flow-guard.d.ts +0 -2
  93. package/dist/ast/cold-flow-guard.js +0 -39
  94. package/dist/ast/hot-path-detector.d.ts +0 -10
  95. package/dist/ast/hot-path-detector.js +0 -235
  96. package/dist/ast/polymorphic-mangler.d.ts +0 -2
  97. package/dist/ast/polymorphic-mangler.js +0 -270
  98. package/dist/ast/string-vault.d.ts +0 -7
  99. package/dist/ast/string-vault.js +0 -139
  100. package/dist/runtime/devtools-deterrent.d.ts +0 -7
  101. package/dist/runtime/devtools-deterrent.js +0 -27
  102. package/dist/runtime/integrity-guard.d.ts +0 -11
  103. package/dist/runtime/integrity-guard.js +0 -25
  104. package/dist/types.js +0 -1
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Efe Arabacı & unpeek 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.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Efe Arabacı & unpeek 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,246 +1,278 @@
1
- # unpeek
2
-
3
- **Zero-config, call-graph-aware polymorphic JavaScript protection and runtime anti-tamper toolkit with <2% CPU overhead.**
4
-
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-emerald.svg)](LICENSE)
6
- [![CPU Overhead](https://img.shields.io/badge/CPU_Overhead-%3C2%25-10b981.svg)](packages/unpeek/benchmarks/overhead.bench.ts)
7
- [![Gzip Delta](https://img.shields.io/badge/Gzip_Delta-%3C15%25-06b6d4.svg)](packages/unpeek/benchmarks/overhead.bench.ts)
8
- [![Interactive Playground](https://img.shields.io/badge/Playground-Live_Demo-6366f1.svg)](https://woffluon.github.io/unpeek)
9
-
10
- English | [Türkçe](./README.tr.md) · [Live Interactive Playground](https://woffluon.github.io/unpeek) · [Agent Architecture Guide](./AGENTS.md) · [AI Skill](./skills/unpeek/SKILL.md)
11
-
12
- ---
13
-
14
- <baglam>
15
-
16
- ## Why unpeek?
17
-
18
- Shipping a modern web application in Next.js, Vite, or Webpack exposes client-side business logic, internal API endpoints, feature flags, and proprietary algorithms to anyone who opens Chrome DevTools or runs an automated AST deobfuscator (`webcrack`, `synchrony`).
19
-
20
- Existing tools force an uncomfortable trade-off:
21
- - **Standard minifiers (`esbuild`, `SWC`, `Terser`)** compress whitespace and shorten variable names, leaving string literals, endpoint URLs, and control flow readable after a single click on the DevTools Pretty-Print (`{}`) button.
22
- - **Legacy AST obfuscators (`javascript-obfuscator`)** apply indiscriminate control-flow flattening, `eval` traps, and eager string-array rotation to every function in the bundle. This inflates bundle sizes by 40–300%, breaks V8 TurboFan JIT inlining inside 60fps UI rendering loops, and triggers false-positive browser freezes.
23
-
24
- `unpeek` resolves this trade-off by combining static call-graph analysis with polymorphic compile-time encryption:
25
-
26
- | Capability | Standard Minifiers (`Terser` / `SWC`) | Legacy AST Obfuscators | `unpeek` |
27
- | :--- | :--- | :--- | :--- |
28
- | **Runtime CPU Overhead** | ~0% | 15% – 85% (throttles UI loops) | **< 2.0%** (Call-Graph Hot-Path Exemption) |
29
- | **Gzip Bundle Growth** | 0% (Baseline) | +45% – +300% | **< 15%** (O(1) Lazy String Vault) |
30
- | **String & Endpoint Encryption** | Plaintext in bundle | Eager array rotation (high CPU) | **Polymorphic XOR + O(1) Memoized Vault** |
31
- | **DevTools Pretty-Print (`{}`) Defense** | None | `debugger` infinite loops (easily bypassed) | **`Function.prototype.toString()` FNV-1a Integrity** |
32
- | **Source Map Isolation** | Manual CI scripts | Manual configuration | **Automatic `.unpeek-maps/` Vault + Comment Strip** |
33
- | **Static Deobfuscator Resistance** | None | Fixed templates (fingerprinted by `webcrack`) | **Per-Build Polymorphic AST Seed** |
34
- | **SSR / Next.js Compatibility** | Native | Frequently breaks server hydration | **Client-Only Auto-Detection + SSR Guard** |
35
-
36
- ### Core Architecture
37
-
38
- 1. **Call-Graph Hot-Path Exemption (`<2%` CPU Budget)**
39
- Before modifying a single AST node, [`detectHotPaths`](packages/unpeek/src/ast/index.ts) traverses the file's call graph. Functions containing loops (`for`, `while`, `do-while`, `for-of`), array higher-order callbacks (`.map`, `.filter`, `.reduce`, `.forEach`), `requestAnimationFrame` tickers, and React/UI render components (`useState`, `useEffect`, `createElement`) are flagged as hot paths. `unpeek` mangles identifiers and encrypts string constants across the entire bundle, while injecting opaque control-flow predicates exclusively into cold functions (such as license checks, request signers, and auth validators). V8 JIT optimization inside hot loops remains untouched.
40
- 2. **O(1) Lazy String Vault (`<15%` Gzip Budget)**
41
- Plaintext string literals (`minStringLength >= 4`) are encrypted at build time with a polymorphic XOR stream cipher keyed by a per-build 32-bit seed. Instead of decrypting every string on page startup, the injected vault helper decodes each string lazily on its first access and caches the plaintext result in its array slot. Subsequent reads resolve in O(1) time via direct array indexing.
42
- 3. **Self-Defending `Function.prototype.toString()` Integrity & Passive Deterrent**
43
- When an analyst formats a protected chunk using DevTools Pretty-Print (`{}`) or edits a branch instruction in the Sources panel, the formatted source alters `Function.prototype.toString()`. [`verifyCodeIntegrity`](packages/unpeek/src/runtime/index.ts) validates a seeded 32-bit FNV-1a checksum against the function's source representation with zero false positives on untouched minified code, triggering gradual state degradation (`deterrentMode: 'gradual'`) rather than an obvious crash point that attackers can patch out.
44
- 4. **Automatic Source Map Vault (`.unpeek-maps/`)**
45
- Leaving `.js.map` files in a public build directory reconstructs your original TypeScript project tree inside DevTools. [`protectDirectory`](packages/unpeek/src/cli/index.ts) automatically extracts `.map` files from your public build directory into a private `.unpeek-maps/` folder and strips `//# sourceMappingURL=` comments from every client bundle so you can upload maps to Sentry or Datadog without serving them to end users.
46
-
47
- </baglam>
48
-
49
- ---
50
-
51
- <talimat>
52
-
53
- ## Quick Start
54
-
55
- ### 1. One-Command Project Setup (`npx unpeek init`)
56
-
57
- Run the initializer from your project root (Next.js, Vite, Webpack, or vanilla):
58
-
59
- ```bash
60
- npx unpeek init
61
- ```
62
-
63
- This command performs three non-destructive setup actions:
64
- 1. Detects your framework (`nextjs`, `vite`, `webpack`, or `vanilla`) from `package.json` and build config files.
65
- 2. Adds `"postbuild": "unpeek protect"` to your `package.json` scripts so every production build is automatically protected.
66
- 3. Appends `.unpeek-maps/` to `.gitignore` so extracted source maps stay out of version control.
67
-
68
- ### 2. CLI Usage (`unpeek protect`)
69
-
70
- You can also install `unpeek` as a development dependency and run it directly in CI/CD or local builds:
71
-
72
- ```bash
73
- npm install -D unpeek
74
- npx unpeek protect
75
- ```
76
-
77
- #### CLI Options
78
-
79
- | Flag | Description | Default |
80
- | :--- | :--- | :--- |
81
- | `--dir <path>` | Explicit client output directory override (e.g., `dist/assets`, `.next/static/chunks`) | Auto-detected |
82
- | `--seed <number>` | Deterministic 32-bit polymorphic build seed | Random per build |
83
- | `--mode <gradual\|passive>` | Runtime anti-tamper deterrent mode | `gradual` |
84
- | `--min-str <number>` | Minimum character length for O(1) lazy string vault encryption | `4` |
85
- | `--no-shield` | Skip injecting the runtime integrity and DevTools telemetry preamble | Shield enabled |
86
- | `--delete-maps` | Permanently delete `.map` files instead of moving them to `.unpeek-maps/` | Moves to `.unpeek-maps/` |
87
-
88
- ### 3. Universal Bundler Plugin (`unpeek/unplugin`)
89
-
90
- If you prefer in-memory chunk transformations during the bundler lifecycle rather than a post-build CLI pass, use [`unpeek/unplugin`](packages/unpeek/src/bundler/unplugin.ts):
91
-
92
- #### Vite (`vite.config.ts`)
93
-
94
- ```ts
95
- import { defineConfig } from 'vite';
96
- import unpeek from 'unpeek/unplugin';
97
-
98
- export default defineConfig({
99
- build: {
100
- sourcemap: true, // Extracted into .unpeek-maps/ automatically
101
- },
102
- plugins: [
103
- unpeek.vite({
104
- deterrentMode: 'gradual',
105
- keepPrivateMaps: true,
106
- }),
107
- ],
108
- });
109
- ```
110
-
111
- #### Next.js (`next.config.mjs`)
112
-
113
- Scope the plugin to client bundles (`!isServer`) so Node.js server chunks keep their native stack traces:
114
-
115
- ```js
116
- import unpeek from 'unpeek/unplugin';
117
-
118
- /** @type {import('next').NextConfig} */
119
- const nextConfig = {
120
- webpack(config, { dev, isServer }) {
121
- if (!dev && !isServer) {
122
- config.plugins.push(
123
- unpeek.webpack({
124
- deterrentMode: 'gradual',
125
- keepPrivateMaps: true,
126
- })
127
- );
128
- }
129
- return config;
130
- },
131
- };
132
-
133
- export default nextConfig;
134
- ```
135
-
136
- #### Programmatic API
137
-
138
- ```ts
139
- import { transformJavaScript, protectDirectory } from 'unpeek';
140
-
141
- // Transform an individual JavaScript string in memory
142
- const result = transformJavaScript(sourceCode, {
143
- seed: 0x7f3a91,
144
- minStringLength: 4,
145
- injectRuntimeShield: true,
146
- deterrentMode: 'gradual',
147
- });
148
-
149
- console.log(result.hotPathReport);
150
- // { totalFunctions: 12, hotFunctionsSkipped: ['renderLoop'], coldFunctionsProtected: ['signRequest'] }
151
-
152
- // Or protect an entire build directory
153
- const summary = await protectDirectory({
154
- cwd: process.cwd(),
155
- keepPrivateMaps: true,
156
- privateMapsDir: '.unpeek-maps',
157
- });
158
- ```
159
-
160
- ---
161
-
162
- ## `.unpeek-maps/` Source Map Vault & Sentry Workflow
163
-
164
- When `keepPrivateMaps` is enabled (the default), `unpeek` relocates all `.js.map` files from your public output directory into `.unpeek-maps/` while preserving their relative filenames, and strips `//# sourceMappingURL=` directives from the public `.js` chunks.
165
-
166
- To retain full stack-trace symbolication in production error trackers:
167
-
168
- ```bash
169
- # 1. Build your app and run unpeek (automatically triggered if wired via postbuild)
170
- npm run build
171
-
172
- # 2. Upload the private source maps from .unpeek-maps/ to Sentry or Datadog
173
- npx @sentry/cli sourcemaps upload .unpeek-maps --release="$GIT_COMMIT_SHA"
174
-
175
- # 3. Deploy your public build folder (.next/, dist/, or build/)
176
- ```
177
-
178
- ---
179
-
180
- ## Official AI Agent Skill Installation
181
-
182
- `unpeek` ships with an official, token-optimized AI Agent Skill ([`skills/unpeek/SKILL.md`](skills/unpeek/SKILL.md)) following Agent Skills Discovery Optimization (SDO) standards. Installing this skill teaches your coding agent (Claude Code, Cursor, Antigravity, OpenAI Codex, or Gemini CLI) how to configure `unpeek`, guard SSR chunks, and wire `.unpeek-maps/` into CI/CD pipelines.
183
-
184
- ### Project-Scoped Installation (Shared with Team via Git)
185
-
186
- Copy the skill into your repository's `.agents/skills/unpeek/` directory:
187
-
188
- ```bash
189
- mkdir -p .agents/skills/unpeek
190
- curl -fsSL https://raw.githubusercontent.com/Woffluon/unpeek/main/skills/unpeek/SKILL.md \
191
- -o .agents/skills/unpeek/SKILL.md
192
- ```
193
-
194
- ### Global Machine Installation (Antigravity / Gemini CLI / Claude Code)
195
-
196
- ```bash
197
- # Antigravity & Gemini CLI
198
- mkdir -p ~/.gemini/config/skills/unpeek
199
- curl -fsSL https://raw.githubusercontent.com/Woffluon/unpeek/main/skills/unpeek/SKILL.md \
200
- -o ~/.gemini/config/skills/unpeek/SKILL.md
201
-
202
- # Cross-agent standard (~/.agents/skills)
203
- mkdir -p ~/.agents/skills/unpeek
204
- curl -fsSL https://raw.githubusercontent.com/Woffluon/unpeek/main/skills/unpeek/SKILL.md \
205
- -o ~/.agents/skills/unpeek/SKILL.md
206
- ```
207
-
208
- </talimat>
209
-
210
- ---
211
-
212
- <dogrulama>
213
-
214
- ## Verification, Testing & Benchmarks
215
-
216
- This monorepo is managed with `pnpm` and verified against strict semantic equivalence, deobfuscation resistance, and runtime overhead budgets:
217
-
218
- ```bash
219
- # Install workspace dependencies
220
- pnpm install
221
-
222
- # Run unit & reverse-engineering resistance test suites (Vitest)
223
- pnpm test
224
-
225
- # Run the V8 VM CPU overhead (<2%) & Gzip delta (<15%) benchmark
226
- pnpm bench
227
-
228
- # Run strict TypeScript typechecking across packages/unpeek and apps/web
229
- pnpm typecheck
230
-
231
- # Build the core package and static interactive web playground
232
- pnpm build
233
- ```
234
-
235
- ### Benchmark Output Reference ([`packages/unpeek/benchmarks/overhead.bench.ts`](packages/unpeek/benchmarks/overhead.bench.ts))
236
-
237
- - **Build / Transform Time**: `< 3000 ms`
238
- - **Gzip Size Delta**: `< 15%` on production application bundles
239
- - **Runtime CPU Overhead**: `< 2.00%` (interleaved multi-round V8 JIT benchmark)
240
- - **Plaintext Leak Rate**: `0%` for string literals meeting `minStringLength`
241
-
242
- </dogrulama>
243
-
244
- ## License
245
-
246
- Released under the [MIT License](./LICENSE).
1
+ # unpeek
2
+
3
+ **Zero-config, call-graph-aware polymorphic JavaScript protection and runtime anti-tamper toolkit with <2% CPU overhead.**
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-emerald.svg)](LICENSE)
6
+ [![CPU Overhead](https://img.shields.io/badge/CPU_Overhead-%3C2%25-10b981.svg)](packages/unpeek/benchmarks/overhead.bench.ts)
7
+ [![Gzip Delta](https://img.shields.io/badge/Gzip_Delta-%3C15%25-06b6d4.svg)](packages/unpeek/benchmarks/overhead.bench.ts)
8
+ [![Interactive Playground](https://img.shields.io/badge/Playground-Live_Demo-6366f1.svg)](https://woffluon.github.io/unpeek)
9
+
10
+ English | [Türkçe](./README.tr.md) · [Live Interactive Playground](https://woffluon.github.io/unpeek) · [Agent Architecture Guide](./AGENTS.md) · [AI Skill](./skills/unpeek/SKILL.md)
11
+
12
+ ---
13
+
14
+ ## Why unpeek?
15
+
16
+ Deploying a web application built with Next.js, Vite, or Webpack exposes client-side business logic, internal API endpoints, feature flags, and proprietary algorithms to anyone who opens browser developer tools or runs automated AST deobfuscators like `webcrack` or `synchrony`.
17
+
18
+ Existing tools force an uncomfortable trade-off:
19
+ - **Standard minifiers (`esbuild`, `SWC`, `Terser`):** Compress whitespace and shorten variable names, leaving string literals, endpoint URLs, and control flow readable after a single click on the DevTools Pretty-Print (`{}`) button.
20
+ - **Legacy AST obfuscators (`javascript-obfuscator`):** Apply indiscriminate control-flow flattening, `eval` traps, and eager string-array rotation across every function in the bundle. This inflates bundle sizes by 40% to 300%, degrades V8 TurboFan JIT inlining in 60fps UI rendering loops, and triggers browser freezes.
21
+
22
+ `unpeek` resolves this trade-off by combining static call-graph analysis with polymorphic compile-time encryption:
23
+
24
+ | Capability | Standard Minifiers (`Terser` / `SWC`) | Legacy AST Obfuscators | `unpeek` |
25
+ | :--- | :--- | :--- | :--- |
26
+ | **Runtime CPU Overhead** | ~0% | 15% to 85% (throttles UI loops) | **< 2.0%** (Call-Graph Hot-Path Exemption) |
27
+ | **Gzip Bundle Growth** | 0% (Baseline) | +45% to +300% | **< 15%** (O(1) Lazy String Vault) |
28
+ | **String & Endpoint Encryption** | Plaintext in bundle | Eager array rotation (high CPU) | **Polymorphic XOR + O(1) Memoized Vault** |
29
+ | **DevTools Pretty-Print (`{}`) Defense** | None | `debugger` infinite loops (easily bypassed) | **`Function.prototype.toString()` FNV-1a Integrity** |
30
+ | **Source Map Isolation** | Manual CI scripts | Manual configuration | **Automatic `.unpeek-maps/` Vault + Comment Strip** |
31
+ | **Static Deobfuscator Resistance** | None | Fixed templates (fingerprinted by deobfuscators) | **Per-Build Polymorphic AST Seed** |
32
+ | **SSR / Next.js Compatibility** | Native | Frequently breaks server hydration | **Client-Only Auto-Detection + SSR Guard** |
33
+
34
+ ### Core Architecture
35
+
36
+ ```mermaid
37
+ flowchart TD
38
+ A["Client Build Output (.next/static, dist/assets, build/static)"] --> B["Framework Detector (detectTargetFramework)"]
39
+ B --> C["Source Map Vault (relocateSourceMaps)"]
40
+ C -->|Extract .map and strip sourceMappingURL| D[".unpeek-maps/ (Private Vault)"]
41
+ C --> E["Client JS Bundles (.js, .mjs)"]
42
+ E --> F["AST Hot-Path Traversal (detectHotPaths)"]
43
+ F -->|Loops, Array Callbacks, UI Renders| G["Hot Path: 0% Tax (Skip Opaque Predicates)"]
44
+ F -->|Cold Functions: Auth, Licensing, Signers| H["Cold Path: Opaque Control-Flow Predicates"]
45
+ G --> I["Polymorphic String Vault (O(1) Lazy XOR)"]
46
+ H --> I
47
+ I --> J["Identifier and Symbol Mangling"]
48
+ J --> K["Runtime Integrity Shield (FNV-1a Checksum)"]
49
+ K --> L["Hardened Production Bundles"]
50
+ ```
51
+
52
+ 1. **Call-Graph Hot-Path Exemption (`<2%` CPU Budget)**
53
+ Before modifying an AST node, [`detectHotPaths`](packages/unpeek/src/ast/index.ts) traverses the file call graph. Functions containing loops (`for`, `while`, `do-while`, `for-of`), array higher-order callbacks (`.map`, `.filter`, `.reduce`, `.forEach`), `requestAnimationFrame` tickers, and React/UI render components (`useState`, `useEffect`, `createElement`) are flagged as hot paths. `unpeek` mangles identifiers and encrypts string constants across the entire bundle, while injecting opaque control-flow predicates exclusively into cold functions (such as license checks, request signers, and auth validators). V8 JIT optimization inside hot loops remains untouched.
54
+ 2. **O(1) Lazy String Vault (`<15%` Gzip Budget)**
55
+ Plaintext string literals (`minStringLength >= 4`) are encrypted at build time with a polymorphic XOR stream cipher keyed by a per-build 32-bit seed. Instead of decrypting every string on page startup, the injected vault helper decodes each string lazily on its first access and caches the plaintext result in its array slot. Subsequent reads resolve in O(1) time through direct array indexing.
56
+ 3. **Self-Defending `Function.prototype.toString()` Integrity and Passive Deterrent**
57
+ When an analyst formats a protected chunk using DevTools Pretty-Print (`{}`) or edits a branch instruction in the Sources panel, the formatted source alters `Function.prototype.toString()`. [`verifyCodeIntegrity`](packages/unpeek/src/runtime/index.ts) validates a seeded 32-bit FNV-1a checksum against the function source representation with zero false positives on untouched minified code, triggering gradual state degradation (`deterrentMode: 'gradual'`) rather than an obvious crash point that attackers can patch out.
58
+ 4. **Automatic Source Map Vault (`.unpeek-maps/`)**
59
+ Leaving `.js.map` files in a public build directory reconstructs your original TypeScript project tree inside DevTools. [`protectProject`](packages/unpeek/src/cli/protect.ts) extracts `.map` files from your public build directory into a private `.unpeek-maps/` folder and strips `//# sourceMappingURL=` comments from every client bundle so you can upload maps to Sentry or Datadog without serving them to end users.
60
+
61
+ ---
62
+
63
+ ## Quick Start
64
+
65
+ ### 1. Project Setup (`npx unpeek init`)
66
+
67
+ Run the initializer from your project root (Next.js, Vite, Webpack, or vanilla JS):
68
+
69
+ ```bash
70
+ npx unpeek init
71
+ ```
72
+
73
+ This command performs three setup actions:
74
+ 1. Detects your framework (`nextjs`, `vite`, `webpack`, or `vanilla`) from `package.json` and build config files.
75
+ 2. Adds `"postbuild": "unpeek protect"` to your `package.json` scripts so every production build is automatically protected.
76
+ 3. Appends `.unpeek-maps/` to `.gitignore` so extracted source maps stay out of version control.
77
+
78
+ ### 2. CLI Usage (`unpeek protect`)
79
+
80
+ Install `unpeek` as a development dependency and run it directly in CI/CD or local builds:
81
+
82
+ ```bash
83
+ npm install -D unpeek
84
+ npx unpeek protect
85
+ ```
86
+
87
+ #### CLI Commands & Options
88
+
89
+ | Command / Flag | Description | Default |
90
+ | :--- | :--- | :--- |
91
+ | `init [--dry-run]` | Automatically detect project framework, configure `postbuild` script, and create `.unpeek-maps/` vault | |
92
+ | `protect` | Protect production client bundles in-place (default command) | |
93
+ | `--out-dir <path>` | Explicit client output directory override (e.g., `dist/assets`, `.next/static/chunks`) | Auto-detected from project framework |
94
+ | `--seed <number>` | Deterministic 32-bit polymorphic build seed | Random per build |
95
+ | `--passive` | Use passive deterrent mode instead of gradual state degradation | Default: gradual degradation |
96
+ | `--no-maps` | Permanently delete `.map` files instead of moving them to `.unpeek-maps/` | Moves to `.unpeek-maps/` |
97
+ | `--min-string-length <num>` | Minimum string length for lazy encryption vault | `4` |
98
+ | `--private-maps-dir <dir>` | Directory to store vaulted private source maps | `.unpeek-maps` |
99
+ | `--no-shield` | Do not inject runtime anti-tamper deterrent shield | Shield injected into entry chunks |
100
+ | `-h, --help` | Show CLI help message | |
101
+ | `-v, --version` | Show CLI version number | |
102
+
103
+ > [!NOTE]
104
+ > Programmatic execution through `protectProject(options)` supports additional fine-grained options, including `minStringLength`, `privateMapsDir`, `injectRuntimeShield`, and `cwd`.
105
+
106
+ > [!IMPORTANT]
107
+ > **CommonJS Users (Dynamic `import()`):**
108
+ > Because `unpeek` is distributed with native ECMAScript Modules (`"type": "module"`), in CommonJS environments (`.cjs` files or `require()` scripts) load `unpeek` using dynamic `import()`:
109
+ > ```javascript
110
+ > // CommonJS (next.config.js / webpack.config.js / scripts)
111
+ > const unpeek = (await import('unpeek/unplugin')).default;
112
+ > const { protectProject, transformJavaScript } = await import('unpeek');
113
+ > ```
114
+
115
+ ### 3. Universal Bundler Plugin (`unpeek/unplugin`)
116
+
117
+ For in-memory chunk transformations during the bundler build lifecycle rather than a post-build CLI pass, use [`unpeek/unplugin`](packages/unpeek/src/bundler/unplugin.ts):
118
+
119
+ #### Vite (`vite.config.ts`)
120
+
121
+ ```ts
122
+ import { defineConfig } from 'vite';
123
+ import unpeek from 'unpeek/unplugin';
124
+
125
+ export default defineConfig({
126
+ plugins: [
127
+ unpeek.vite({
128
+ deterrentMode: 'gradual',
129
+ }),
130
+ ],
131
+ });
132
+ ```
133
+
134
+ #### Next.js (`next.config.mjs`)
135
+
136
+ Scope the plugin to client bundles (`!isServer`) so Node.js server chunks keep their native stack traces:
137
+
138
+ ```js
139
+ import unpeek from 'unpeek/unplugin';
140
+
141
+ /** @type {import('next').NextConfig} */
142
+ const nextConfig = {
143
+ webpack(config, { dev, isServer }) {
144
+ if (!dev && !isServer) {
145
+ config.plugins.push(
146
+ unpeek.webpack({
147
+ deterrentMode: 'gradual',
148
+ })
149
+ );
150
+ }
151
+ return config;
152
+ },
153
+ };
154
+
155
+ export default nextConfig;
156
+ ```
157
+
158
+ #### Programmatic API
159
+
160
+ ```ts
161
+ import { transformJavaScript, protectProject } from 'unpeek';
162
+
163
+ // Transform an individual JavaScript string in memory
164
+ const result = transformJavaScript(sourceCode, {
165
+ seed: 0x7f3a91,
166
+ minStringLength: 4,
167
+ injectRuntimeShield: true,
168
+ deterrentMode: 'gradual',
169
+ });
170
+
171
+ console.log(result.hotPathReport);
172
+ // { totalFunctions: 12, hotFunctionsSkipped: ['renderLoop'], coldFunctionsProtected: ['signRequest'] }
173
+
174
+ // Or protect an entire build directory
175
+ const summary = await protectProject({
176
+ cwd: process.cwd(),
177
+ keepPrivateMaps: true,
178
+ privateMapsDir: '.unpeek-maps',
179
+ });
180
+ ```
181
+
182
+ ---
183
+
184
+ ## `.unpeek-maps/` Source Map Vault & Sentry Workflow
185
+
186
+ When `keepPrivateMaps` is enabled (the default), `unpeek` relocates all `.js.map` files from your public output directory into `.unpeek-maps/` while preserving relative filenames, and strips `//# sourceMappingURL=` directives from public `.js` chunks.
187
+
188
+ To retain full stack-trace symbolication in production error trackers:
189
+
190
+ ```bash
191
+ # 1. Build your app and run unpeek (automatically triggered if wired via postbuild)
192
+ npm run build
193
+
194
+ # 2. Upload the private source maps from .unpeek-maps/ to Sentry or Datadog
195
+ npx @sentry/cli sourcemaps upload .unpeek-maps --release="$GIT_COMMIT_SHA"
196
+
197
+ # 3. Deploy your public build folder (.next/, dist/, or build/)
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Official AI Agent Skill Installation
203
+
204
+ `unpeek` ships with an official, token-optimized AI Agent Skill ([`skills/unpeek/SKILL.md`](skills/unpeek/SKILL.md)) following Agent Skills Discovery Optimization (SDO) standards. Installing this skill teaches your coding agent (Claude Code, Cursor, Antigravity, OpenAI Codex, or Gemini CLI) how to configure `unpeek`, guard SSR chunks, and wire `.unpeek-maps/` into CI/CD pipelines.
205
+
206
+ ### Project-Scoped Installation (Shared with Team via Git)
207
+
208
+ Copy the skill into your repository `.agents/skills/unpeek/` directory:
209
+
210
+ ```bash
211
+ mkdir -p .agents/skills/unpeek
212
+ curl -fsSL https://raw.githubusercontent.com/Woffluon/unpeek/main/skills/unpeek/SKILL.md \
213
+ -o .agents/skills/unpeek/SKILL.md
214
+ ```
215
+
216
+ ### Global Machine Installation (Antigravity / Gemini CLI / Claude Code)
217
+
218
+ ```bash
219
+ # Antigravity & Gemini CLI
220
+ mkdir -p ~/.gemini/config/skills/unpeek
221
+ curl -fsSL https://raw.githubusercontent.com/Woffluon/unpeek/main/skills/unpeek/SKILL.md \
222
+ -o ~/.gemini/config/skills/unpeek/SKILL.md
223
+
224
+ # Cross-agent standard (~/.agents/skills)
225
+ mkdir -p ~/.agents/skills/unpeek
226
+ curl -fsSL https://raw.githubusercontent.com/Woffluon/unpeek/main/skills/unpeek/SKILL.md \
227
+ -o ~/.agents/skills/unpeek/SKILL.md
228
+ ```
229
+
230
+ ---
231
+
232
+ ## Verification, Testing & Benchmarks
233
+
234
+ This monorepo is managed with `pnpm` and verified against strict semantic equivalence, deobfuscation resistance, and runtime overhead budgets:
235
+
236
+ ```bash
237
+ # Install workspace dependencies
238
+ pnpm install
239
+
240
+ # Run unit and reverse-engineering resistance test suites (Vitest)
241
+ pnpm test
242
+
243
+ # Run unit tests with V8 code coverage report
244
+ pnpm --filter unpeek run test:coverage
245
+
246
+ # Run the V8 VM CPU overhead (<2%) and Gzip delta (<15%) benchmark
247
+ pnpm bench
248
+
249
+ # Run strict TypeScript typechecking across packages/unpeek and apps/web
250
+ pnpm typecheck
251
+
252
+ # Build the core package and static interactive web playground
253
+ pnpm build
254
+ ```
255
+
256
+ ### Monorepo Scripts & Release Integrity
257
+
258
+ ```bash
259
+ # Verify Conventional Commit version calculation
260
+ powershell -File scripts/test-versioning.ps1
261
+
262
+ # Validate release readiness against planned commit message
263
+ powershell -File scripts/validate-version.ps1 -Message "fix: description"
264
+
265
+ # Stage release artifacts and compute SHA-256 manifests
266
+ powershell -File scripts/stage-release.ps1
267
+ ```
268
+
269
+ ### Benchmark Output Reference ([`packages/unpeek/benchmarks/overhead.bench.ts`](packages/unpeek/benchmarks/overhead.bench.ts))
270
+
271
+ - **Build / Transform Time:** `< 3000 ms`
272
+ - **Gzip Size Delta:** `< 15%` on production application bundles
273
+ - **Runtime CPU Overhead:** `< 2.00%` (interleaved multi-round V8 JIT benchmark)
274
+ - **Plaintext Leak Rate:** `0%` for string literals meeting `minStringLength`
275
+
276
+ ## License
277
+
278
+ Released under the [MIT License](./LICENSE).