@zeitzeuge/node 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.
- package/README.md +106 -0
- package/dist/agent.d.ts +5 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/classify.d.ts +5 -0
- package/dist/classify.d.ts.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3873 -0
- package/dist/metrics.d.ts +5 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/profile-parser.d.ts +5 -0
- package/dist/profile-parser.d.ts.map +1 -0
- package/dist/prompts.d.ts +5 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/reporter.d.ts +57 -0
- package/dist/reporter.d.ts.map +1 -0
- package/dist/reporter.js +3866 -0
- package/dist/types.d.ts +68 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workspace.d.ts +5 -0
- package/dist/workspace.d.ts.map +1 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @zeitzeuge/node
|
|
2
|
+
|
|
3
|
+
Custom reporter for the Node.js built-in test runner (`node --test`) that collects V8 CPU profiles and runs AI-powered performance analysis on your application code.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @zeitzeuge/node
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
Run your tests with CPU profiling enabled and the zeitzeuge reporter:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
node --test \
|
|
17
|
+
--cpu-prof --cpu-prof-dir=.zeitzeuge-profiles \
|
|
18
|
+
--test-reporter @zeitzeuge/node/reporter \
|
|
19
|
+
--test-reporter-destination stdout \
|
|
20
|
+
tests/*.test.js
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
A Markdown report is written to `zeitzeuge-report.md` with findings and suggested fixes.
|
|
24
|
+
|
|
25
|
+
> **Heads-up — cost & runtime impact**
|
|
26
|
+
>
|
|
27
|
+
> Zeitzeuge profiles every test file, analyzes the results with an LLM, and
|
|
28
|
+
> produces a report. Depending on the size of your project this can add **60 seconds
|
|
29
|
+
> or more** to each test run and **consumes API tokens**. It is designed as an
|
|
30
|
+
> investigation tool, not something you run on every commit.
|
|
31
|
+
|
|
32
|
+
### Recommended: on-demand profiling
|
|
33
|
+
|
|
34
|
+
Create a script in `package.json` so profiling only runs when you explicitly opt in:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "node --test tests/*.test.js",
|
|
40
|
+
"test:profile": "node --test --cpu-prof --cpu-prof-dir=.zeitzeuge-profiles --test-reporter @zeitzeuge/node/reporter --test-reporter-destination stdout tests/*.test.js"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm test # regular run — no profiling, no LLM cost
|
|
47
|
+
npm run test:profile # profiles tests + generates AI report
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Configuration
|
|
51
|
+
|
|
52
|
+
The reporter is configured via environment variables:
|
|
53
|
+
|
|
54
|
+
| Variable | Default | Description |
|
|
55
|
+
| ------------------------ | --------------------- | ------------------------------------------- |
|
|
56
|
+
| `ZEITZEUGE_PROFILE_DIR` | `.zeitzeuge-profiles` | Directory for temporary `.cpuprofile` files |
|
|
57
|
+
| `ZEITZEUGE_OUTPUT` | `zeitzeuge-report.md` | Path for the Markdown report |
|
|
58
|
+
| `ZEITZEUGE_PROJECT_ROOT` | `process.cwd()` | Project root for classifying code |
|
|
59
|
+
| `ZEITZEUGE_VERBOSE` | `false` | Enable debug logging (`"true"` to enable) |
|
|
60
|
+
| `ZEITZEUGE_ANALYZE` | `true` | Run AI analysis (`"false"` to disable) |
|
|
61
|
+
|
|
62
|
+
## How It Works
|
|
63
|
+
|
|
64
|
+
1. **Instruments the test runner** — `--cpu-prof` tells Node.js to write V8 CPU profiles for each forked test process
|
|
65
|
+
2. **Custom reporter collects timing** — the reporter consumes `test:pass`, `test:fail`, and `test:summary` events to extract per-test timing data
|
|
66
|
+
3. **Correlates profiles with test files** — `.cpuprofile` files are matched to test files by execution order
|
|
67
|
+
4. **Classifies hot functions** — every profiled function is categorized as `application`, `dependency`, `test`, or `framework`
|
|
68
|
+
5. **Deep Agent analyzes your application code** — focuses on bottlenecks in the code you wrote, not test infrastructure overhead
|
|
69
|
+
|
|
70
|
+
## Programmatic API
|
|
71
|
+
|
|
72
|
+
You can use the analysis pipeline programmatically:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import {
|
|
76
|
+
parseCpuProfile,
|
|
77
|
+
classifyScript,
|
|
78
|
+
computeMetrics,
|
|
79
|
+
createNodeTestWorkspace,
|
|
80
|
+
analyzeTestPerformance,
|
|
81
|
+
} from '@zeitzeuge/node';
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Exports
|
|
85
|
+
|
|
86
|
+
| Export | Description |
|
|
87
|
+
| ------------------------- | -------------------------------------------------------------------- |
|
|
88
|
+
| `zeitZeugeReporter` | Async generator reporter for `node --test` |
|
|
89
|
+
| `analyzeTestPerformance` | Run the Deep Agent analysis pipeline |
|
|
90
|
+
| `NODE_TEST_SYSTEM_PROMPT` | System prompt used for the Node.js test analysis |
|
|
91
|
+
| `computeMetrics` | Compute performance metrics from test timing and profile data |
|
|
92
|
+
| `parseCpuProfile` | Parse a V8 `.cpuprofile` file into a structured summary |
|
|
93
|
+
| `createNodeTestWorkspace` | Build the workspace context sent to the analysis agent |
|
|
94
|
+
| `mergeHotFunctions` | Merge and deduplicate hot functions across profiles |
|
|
95
|
+
| `classifyScript` | Classify a script URL as application, dependency, test, or framework |
|
|
96
|
+
|
|
97
|
+
## Requirements
|
|
98
|
+
|
|
99
|
+
- Node.js >= 22 (for stable `node:test` with process isolation)
|
|
100
|
+
- An LLM API key (`OPENAI_API_KEY` or `ANTHROPIC_API_KEY`)
|
|
101
|
+
|
|
102
|
+
## Related packages
|
|
103
|
+
|
|
104
|
+
- [`zeitzeuge`](../cli/) — CLI for page-load performance analysis
|
|
105
|
+
- [`@zeitzeuge/vitest`](../vitest/) — Vitest plugin for test suite performance analysis
|
|
106
|
+
- [`@zeitzeuge/utils`](../utils/) — Shared internal utilities
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,sBAAsB,EACtB,KAAK,mBAAmB,IAAI,uBAAuB,GACpD,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classify.d.ts","sourceRoot":"","sources":["../src/classify.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry point for the @zeitzeuge/node integration.
|
|
3
|
+
*
|
|
4
|
+
* Usage with Node.js test runner:
|
|
5
|
+
*
|
|
6
|
+
* ```bash
|
|
7
|
+
* node --test \
|
|
8
|
+
* --cpu-prof --cpu-prof-dir=.zeitzeuge-profiles \
|
|
9
|
+
* --test-reporter @zeitzeuge/node/reporter \
|
|
10
|
+
* --test-reporter-destination stdout \
|
|
11
|
+
* tests/*.test.js
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export { default as zeitZeugeReporter } from './reporter.js';
|
|
15
|
+
export { analyzeTestPerformance, type NodeTestAnalysisContext } from './agent.js';
|
|
16
|
+
export { NODE_TEST_SYSTEM_PROMPT } from './prompts.js';
|
|
17
|
+
export type { ZeitZeugeNodeTestOptions } from './types.js';
|
|
18
|
+
export { computeMetrics } from './metrics.js';
|
|
19
|
+
export { parseCpuProfile } from './profile-parser.js';
|
|
20
|
+
export { createNodeTestWorkspace, mergeHotFunctions } from './workspace.js';
|
|
21
|
+
export { classifyScript } from './classify.js';
|
|
22
|
+
export type { SourceCategory, PerformanceMetrics, CpuProfileSummary, HotFunction, TestFileTiming, CorrelatedProfile, } from '@zeitzeuge/utils';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,KAAK,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,iBAAiB,GAClB,MAAM,kBAAkB,CAAC"}
|