zeitzeuge 0.6.6 → 0.7.1

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 (58) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +22 -160
  3. package/dist/cli.js +2685 -2296
  4. package/package.json +9 -28
  5. package/dist/analysis/agent.d.ts +0 -33
  6. package/dist/analysis/agent.d.ts.map +0 -1
  7. package/dist/analysis/parser.d.ts +0 -3
  8. package/dist/analysis/parser.d.ts.map +0 -1
  9. package/dist/analysis/prompts.d.ts +0 -2
  10. package/dist/analysis/prompts.d.ts.map +0 -1
  11. package/dist/browser/capture.d.ts +0 -14
  12. package/dist/browser/capture.d.ts.map +0 -1
  13. package/dist/browser/launch.d.ts +0 -6
  14. package/dist/browser/launch.d.ts.map +0 -1
  15. package/dist/browser/runtime-trace.d.ts +0 -52
  16. package/dist/browser/runtime-trace.d.ts.map +0 -1
  17. package/dist/browser/trace.d.ts +0 -8
  18. package/dist/browser/trace.d.ts.map +0 -1
  19. package/dist/cli.d.ts +0 -3
  20. package/dist/cli.d.ts.map +0 -1
  21. package/dist/models/init.d.ts +0 -3
  22. package/dist/models/init.d.ts.map +0 -1
  23. package/dist/output/progress.d.ts +0 -30
  24. package/dist/output/progress.d.ts.map +0 -1
  25. package/dist/output/report.d.ts +0 -40
  26. package/dist/output/report.d.ts.map +0 -1
  27. package/dist/output/terminal.d.ts +0 -40
  28. package/dist/output/terminal.d.ts.map +0 -1
  29. package/dist/sandbox/workspace.d.ts +0 -33
  30. package/dist/sandbox/workspace.d.ts.map +0 -1
  31. package/dist/schema.d.ts +0 -86
  32. package/dist/schema.d.ts.map +0 -1
  33. package/dist/types.d.ts +0 -245
  34. package/dist/types.d.ts.map +0 -1
  35. package/dist/vitest/classify.d.ts +0 -19
  36. package/dist/vitest/classify.d.ts.map +0 -1
  37. package/dist/vitest/heap-profile-parser.d.ts +0 -12
  38. package/dist/vitest/heap-profile-parser.d.ts.map +0 -1
  39. package/dist/vitest/index.d.ts +0 -19
  40. package/dist/vitest/index.d.ts.map +0 -1
  41. package/dist/vitest/index.js +0 -3014
  42. package/dist/vitest/listener-tracker.d.ts +0 -110
  43. package/dist/vitest/listener-tracker.d.ts.map +0 -1
  44. package/dist/vitest/metrics.d.ts +0 -91
  45. package/dist/vitest/metrics.d.ts.map +0 -1
  46. package/dist/vitest/plugin.d.ts +0 -17
  47. package/dist/vitest/plugin.d.ts.map +0 -1
  48. package/dist/vitest/profile-parser.d.ts +0 -13
  49. package/dist/vitest/profile-parser.d.ts.map +0 -1
  50. package/dist/vitest/prompts.d.ts +0 -10
  51. package/dist/vitest/prompts.d.ts.map +0 -1
  52. package/dist/vitest/reporter.d.ts +0 -94
  53. package/dist/vitest/reporter.d.ts.map +0 -1
  54. package/dist/vitest/types.d.ts +0 -249
  55. package/dist/vitest/types.d.ts.map +0 -1
  56. package/dist/vitest/workspace.d.ts +0 -25
  57. package/dist/vitest/workspace.d.ts.map +0 -1
  58. package/vitest.d.ts +0 -1
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) Christian Bromann
3
+ Copyright (c) LangChain, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,168 +1,46 @@
1
- <p align="center">
2
- <img src=".github/assets/zeitzeuge.png" alt="ZeitZeuge mascot: a detective stopwatch with a magnifying glass witnessing slowdowns" width="220" />
3
- </p>
4
-
5
1
  # zeitzeuge
6
2
 
7
- AI-powered performance analysis for frontend page loads and Vitest test suites. Captures V8 heap snapshots, performance traces, Chrome runtime traces, and CPU profiles — stores everything in a virtual filesystem and hands it to a Deep Agent that investigates bottlenecks and provides code-level fixes.
8
-
9
- > _"Zeuge" = witness — the tool "witnesses" slowdowns in your page loads and test runs._
3
+ AI-powered performance analysis for frontend page loads. Launches Chrome, captures V8 heap snapshots, performance traces, and Chrome runtime traces in a single page load, then hands everything to a Deep Agent that investigates bottlenecks and provides code-level fixes.
10
4
 
11
- ## Quick start
5
+ > _"Zeuge" = witness -- the tool "witnesses" slowdowns in your page loads._
12
6
 
13
- ### Page-load analysis
7
+ ## Install
14
8
 
15
9
  ```bash
16
- # Set your API key
17
- export OPENAI_API_KEY=sk-... # or ANTHROPIC_API_KEY
18
-
19
- # Analyze any URL
20
- npx zeitzeuge http://localhost:3000
10
+ npm install -g zeitzeuge
21
11
  ```
22
12
 
23
- ### Vitest integration
24
-
25
- Add the plugin to your `vitest.config.ts` to profile your test suite and get AI-powered analysis of your **application code** performance:
26
-
27
- ```ts
28
- import { defineConfig } from 'vitest/config';
29
- import { zeitzeuge } from 'zeitzeuge/vitest';
13
+ Requires an LLM API key:
30
14
 
31
- export default defineConfig({
32
- plugins: [zeitzeuge()],
33
- });
15
+ ```bash
16
+ export OPENAI_API_KEY=sk-... # or ANTHROPIC_API_KEY
34
17
  ```
35
18
 
36
- Run your tests as usual — zeitzeuge instruments the run with V8 CPU profiling, collects the profiles, and runs a Deep Agent analysis after tests complete:
19
+ ## Usage
37
20
 
38
21
  ```bash
39
- vitest run
22
+ zeitzeuge http://localhost:3000
40
23
  ```
41
24
 
42
25
  A Markdown report is written to `zeitzeuge-report.md` with findings and suggested fixes.
43
26
 
44
27
  ## How it works
45
28
 
46
- ### Page-load mode (`npx zeitzeuge <url>`)
47
-
48
29
  1. **Launches Chrome** via WebdriverIO with DevTools Protocol access
49
30
  2. **Captures everything in one page load:**
50
31
  - V8 heap snapshot (memory analysis)
51
32
  - Performance trace (network waterfall, long tasks, paint timing)
52
- - **Chrome runtime trace** via the [Tracing domain](https://chromedevtools.github.io/devtools-protocol/tot/Tracing/) every function call, event dispatch, layout, paint, and GC event on the main thread
33
+ - Chrome runtime trace via the [Tracing domain](https://chromedevtools.github.io/devtools-protocol/tot/Tracing/) -- every function call, event dispatch, layout, paint, and GC event on the main thread
53
34
  - All network assets (scripts, CSS, HTML source code)
54
- 3. **Builds a VFS workspace** using `@langchain/node-vfs` an in-memory virtual filesystem containing:
55
- - `/heap/summary.json` parsed heap snapshot data
56
- - `/trace/summary.json` page load timing & metrics
57
- - `/trace/runtime/blocking-functions.json` — functions blocking the main thread > 50ms
58
- - `/trace/runtime/event-listeners.json` — event listener add/remove imbalances
59
- - `/trace/runtime/frame-breakdown.json` — time breakdown: scripting vs layout vs paint vs GC
60
- - `/scripts/`, `/styles/`, `/html/` — actual source files
61
- 4. **Deep Agent explores** — a LangChain Deep Agent (`deepagents`) autonomously browses the workspace, reads actual source code, greps for patterns, and correlates heap data with trace data and runtime analysis
62
- 5. **Reports findings** — memory leaks, frame-blocking functions, listener leaks, render-blocking scripts, GC pressure — with code-level fixes
63
-
64
- ### Vitest mode (`zeitzeuge/vitest` plugin)
65
-
66
- 1. **Instruments Vitest** — injects `--cpu-prof` into worker process args, forces `pool: 'forks'` for reliable profiling, disables file parallelism for clean per-file profiles
67
- 2. **Captures V8 CPU profiles** for each test file during the test run
68
- 3. **Classifies hot functions** — every profiled function is categorized as `application`, `dependency`, `test`, or `framework` based on its file path relative to your project root
69
- 4. **Builds a VFS workspace** containing:
70
- - `/hot-functions/application.json` — hotspots in **your** code (primary focus)
71
- - `/hot-functions/dependencies.json` — hotspots in third-party code
72
- - `/scripts/application.json` — per-file CPU time for your source files
73
- - `/scripts/dependencies.json` — per-file CPU time for dependencies
74
- - `/profiles/*.json` — full CPU profile summaries with call trees
75
- - `/timing/overview.json` — per-test timing data
76
- - `/src/`, `/tests/` — actual source files referenced by hot functions
77
- 5. **Deep Agent analyzes your application code** — focuses on bottlenecks in the code you wrote, not test infrastructure overhead. Reports dependency issues when your code makes expensive calls into libraries.
35
+ 3. **Builds a VFS workspace** using `@langchain/node-vfs` containing parsed heap data, trace summaries, runtime analysis, and actual source files
36
+ 4. **Deep Agent explores** -- a LangChain Deep Agent autonomously browses the workspace, reads source code, and correlates heap data with trace and runtime data
37
+ 5. **Reports findings** -- memory leaks, frame-blocking functions, listener leaks, render-blocking scripts, GC pressure -- with code-level fixes
78
38
 
79
39
  ## What it finds
80
40
 
81
- ### Page-load findings
82
-
83
- **Memory issues:**
84
-
85
- - Memory leaks (unbounded caches, growing arrays/maps)
86
- - Detached DOM nodes still referenced in JavaScript
87
- - Large retained objects and closure leaks
88
-
89
- **Page-load issues:**
90
-
91
- - Render-blocking scripts (`<script>` without `async`/`defer`)
92
- - Render-blocking stylesheets
93
- - Long main-thread tasks (> 50ms)
94
- - Oversized bundles and unused code
95
- - Sequential waterfall bottlenecks
96
-
97
- **Runtime issues:**
98
-
99
- - **Frame-blocking functions** — exact function name, script URL, line number, and call stack for any function blocking the main thread > 50ms
100
- - **Event listener leaks** — `addEventListener` calls without matching `removeEventListener`, growing listener counts
101
- - **GC pressure** — frequent or long garbage collection pauses indicating memory churn
102
- - **Layout thrashing** — forced synchronous layouts from reading layout properties after DOM mutations
103
-
104
- ### Vitest analysis
105
-
106
- **Application code bottlenecks:**
107
-
108
- - Hot functions with high self time in your source code
109
- - Expensive algorithms (O(n^2) loops, redundant computation, unnecessary sorting)
110
- - Object allocation hotspots driving GC pressure
111
- - Synchronous blocking in hot paths (file I/O, crypto, JSON serialization)
112
-
113
- **Dependency bottlenecks:**
114
-
115
- - Third-party libraries consuming disproportionate CPU
116
- - Unnecessary calls to expensive dependency APIs in hot paths
117
- - Suggestions for alternative libraries or configuration changes
118
-
119
- **GC pressure:**
120
-
121
- - Functions creating many short-lived objects in tight loops
122
- - Large allocations that could be pooled or reused
123
-
124
- ## Vitest plugin options
125
-
126
- ```ts
127
- zeitzeuge({
128
- // Enable/disable the plugin (default: true)
129
- enabled: true,
130
-
131
- // Path for the Markdown report (default: 'zeitzeuge-report.md')
132
- output: 'zeitzeuge-report.md',
133
-
134
- // Directory for temporary .cpuprofile files (default: '.zeitzeuge-profiles')
135
- profileDir: '.zeitzeuge-profiles',
136
-
137
- // Also write V8 heap profiles (.heapprofile) for workers (default: false)
138
- // Uses: --heap-prof + --heap-prof-dir=<profileDir>
139
- heapProf: false,
140
-
141
- // Run Deep Agent analysis after tests finish (default: true)
142
- analyzeOnFinish: true,
143
-
144
- // Project root for classifying application vs dependency code (default: process.cwd())
145
- projectRoot: process.cwd(),
146
-
147
- // Enable debug logging (default: false)
148
- verbose: false,
149
- });
150
- ```
151
-
152
- ### Heap profiling (`heapProf`) — when to enable it
153
-
154
- `heapProf` captures **allocation sampling** (written as `.heapprofile` files) and can help you find:
155
-
156
- - Allocation hotspots (functions / modules allocating lots of bytes)
157
- - High GC pressure caused by excessive short-lived objects
158
-
159
- It defaults to **`false`** because it can be a net negative for everyday runs:
160
-
161
- - **Overhead**: allocation sampling adds runtime overhead and can skew timings/CPU profiles
162
- - **Artifact size / IO**: `.heapprofile` files can be large, increasing IO and CI flakiness
163
- - **Noise**: test runners allocate a lot in setup/framework code; heap data can be less actionable unless you’re specifically chasing allocations/GC
164
-
165
- Recommendation: keep it off by default and enable it when you suspect **allocation/GC issues** or when CPU hotspots alone aren’t explaining slow tests.
41
+ - **Memory issues** -- leaks, detached DOM nodes, large retained objects, closure leaks
42
+ - **Page-load issues** -- render-blocking scripts/stylesheets, long tasks, oversized bundles, sequential waterfalls
43
+ - **Runtime issues** -- frame-blocking functions (with exact source location and call stack), event listener leaks, GC pressure, layout thrashing
166
44
 
167
45
  ## CLI options
168
46
 
@@ -173,6 +51,7 @@ Options:
173
51
  --verbose, -v Enable verbose/debug logging [boolean] [default: false]
174
52
  --headless Run Chrome in headless mode [boolean] [default: true]
175
53
  --timeout Page load timeout in milliseconds [number] [default: 30000]
54
+ --output, -o Output path for the Markdown report [string] [default: "zeitzeuge-report.md"]
176
55
  --help, -h Show help [boolean]
177
56
  --version Show version number [boolean]
178
57
  ```
@@ -185,28 +64,11 @@ Options:
185
64
  | `ANTHROPIC_API_KEY` | Anthropic API key (fallback) |
186
65
  | `ZEITZEUGE_MODEL` | Override model name (e.g. `gpt-4o`, `claude-sonnet-4-20250514`) |
187
66
 
188
- ## Development
67
+ ## Related packages
189
68
 
190
- ```bash
191
- # Install dependencies
192
- bun install
193
-
194
- # Run in development
195
- bun run dev -- http://localhost:3000
196
-
197
- # Run tests
198
- bun test
199
-
200
- # Build for distribution
201
- bun run build
202
- ```
69
+ - [`@zeitzeuge/vitest`](../vitest/) -- Vitest plugin for test suite performance analysis
70
+ - [`@zeitzeuge/utils`](../utils/) -- Shared internals (private, not published)
203
71
 
204
- ## Tech stack
72
+ ## License
205
73
 
206
- - **Runtime:** [Bun](https://bun.sh) (works across JS runtimes)
207
- - **Browser automation:** [WebdriverIO](https://webdriver.io) + Chrome DevTools Protocol
208
- - **Runtime tracing:** [CDP Tracing domain](https://chromedevtools.github.io/devtools-protocol/tot/Tracing/) for function-level main-thread analysis
209
- - **V8 CPU profiling:** `--cpu-prof` for per-function timing in test suites
210
- - **AI analysis:** [Deep Agents](https://docs.langchain.com/oss/javascript/deepagents/overview) + [LangChain](https://langchain.com)
211
- - **Virtual filesystem:** [@langchain/node-vfs](https://docs.langchain.com/oss/javascript/integrations/providers/node-vfs) — in-memory VFS sandbox
212
- - **LLM providers:** OpenAI, Anthropic (auto-detected from environment)
74
+ MIT