@newrelic/preflight 1.0.2 → 1.0.4

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 CHANGED
@@ -1,498 +1,209 @@
1
- # NR AI Coding Observability: Preflight
1
+ <div align="center">
2
+ <img src="demo/preflight-logo.svg" alt="Preflight" width="96" height="96" />
3
+ <h1>Preflight</h1>
4
+ <p><strong>Observability for AI Coding Assistants</strong></p>
2
5
 
3
- **Observability for AI coding assistants.** Captures every action your AI coding tool takes — file reads, edits, commands, searches — and sends the data to New Relic so you can see exactly what's happening, how much it costs, and where it's wasting time.
6
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue)](LICENSE)
7
+ [![Node 22+](https://img.shields.io/badge/Node-22%2B-brightgreen)](.nvmrc)
8
+ [![Local First](https://img.shields.io/badge/Local%20First-Offline%20by%20default-brightgreen)](#quick-start)
9
+ [![Dashboards Included](https://img.shields.io/badge/Dashboards-7%20Included-blue)](#dashboards)
4
10
 
5
- Think of it like Google Analytics for your AI pair programmer.
11
+ [**Docs**](docs/ADVANCED.md) [**Examples**](examples/) [**Community**](https://support.newrelic.com/s/) [**Contributing**](CONTRIBUTING.md)
6
12
 
7
- ## What It Does
8
-
9
- - **Tracks every action** — sees every file the AI reads, every command it runs, every edit it makes
10
- - **Tracks costs** — calculates USD spend per session, day, and week, broken down by model
11
- - **Detects waste** — catches inefficiencies like re-reading the same file repeatedly, making edits without reading first, or running the same failing command in a loop
12
- - **Measures efficiency** — computes a 0-100 score per task based on how directly the AI worked toward the goal
13
- - **Sends to New Relic** — all data lands in your NR account as queryable events and metrics, ready for dashboards and alerts
13
+ </div>
14
14
 
15
15
  ---
16
16
 
17
- ## Before You Start
17
+ ## Why Your AI Tool Needs Observability
18
18
 
19
- Two things are always required. A New Relic account is optional the tool works in [local mode](#local-mode) without one.
19
+ Your AI coding assistant makes hundreds of decisions every session — what to read, what to edit, when to run commands. But you can't see any of it. You know it was fast, but was it _efficient_? You got a PR merged, but how much did it cost? You fixed a bug, but did it get stuck in a loop first?
20
20
 
21
- ### 1. An AI coding tool
21
+ **Preflight is observability for agentic coding** — the actions, cost, and efficiency of your AI coding assistant as it works. See exactly what's happening, how much it costs, and where your AI is wasting time.
22
22
 
23
- This works with **Claude Code**, Cursor, Windsurf, GitHub Copilot, Zed, Continue.dev, or Amazon Q Developer. The examples below use Claude Code, which has the deepest integration.
23
+ **Local-first by design.** Preflight runs entirely on your machine and sends your data nowhere by default. A live dashboard at `localhost:7777` shows your sessions in real time, fully offline. Connect a New Relic account only when you want more — team rollups, alerting, and cross-session history. You choose: **local-only**, **New Relic**, or **both**.
24
24
 
25
- ### 2. Node.js v22 or higher (v24 recommended)
25
+ ---
26
26
 
27
- Open a terminal and run:
27
+ ## Demo
28
28
 
29
- ```bash
30
- node --version
31
- ```
29
+ ![Preflight dashboard animation](demo/preflight-readme.gif)
32
30
 
33
- If it shows `v22.x.x` or higher, you're set. v24 is recommended (and what the project uses for development). If you need to upgrade, install it from [nodejs.org](https://nodejs.org) or via nvm:
31
+ See cost breakdown, efficiency scoring, anti-patterns, and live session tracking in action.
34
32
 
35
- ```bash
36
- nvm install 24 && nvm use 24
37
- ```
33
+ ---
34
+
35
+ ## What You Get
36
+
37
+ ### Visibility
38
38
 
39
- ### 3. A New Relic account (optional)
39
+ - **Every action captured** file reads, edits, commands, searches
40
+ - **Live session dashboard** — see what's happening right now
41
+ - **Historical trends** — analyze patterns over weeks and months
40
42
 
41
- > Skip this section if you plan to use [local mode](#local-mode) — no NR account needed.
43
+ ### Cost Control
42
44
 
43
- To send telemetry to New Relic, you need two keys:
45
+ - **USD spend tracking** per session, day, and week
46
+ - **Per-model breakdown** — know which models cost most
47
+ - **Budget alerts** — get notified before you overspend
48
+ - **Forecasting** — project monthly burn rate
44
49
 
45
- | Key | What it does | Where to find it |
46
- | ---------------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
47
- | **License key** | Sends telemetry data _into_ NR (ingest) | NR One → top-right menu → API keys → create a key of type **License**. Long hex string ending in `NRAL`. Not `NRAK-`. |
48
- | **User API key** | Deploys dashboards and alerts _into_ NR | NR One → top-right menu → API keys → create a key of type **User**. Starts with `NRAK-`. Only needed for the deploy commands. |
50
+ ### Efficiency Insights
49
51
 
50
- You'll also need your **Account ID** — a number visible in the URL when you're logged into NR One: `https://one.newrelic.com/nr1-core?account=`**`12345`**.
52
+ - **Efficiency score** — 0–100 score per task, based on how directly the AI worked
53
+ - **Anti-pattern detection** — catches re-reads, blind edits, stuck loops
54
+ - **Personalized recommendations** — optimize your AI workflow
55
+ - **Weekly coaching reports** — narrative analysis vs. your historical baseline
51
56
 
52
- **Data ingest:** this tool is free and open source, but the telemetry it sends counts against your NR data ingest. Standard ingest rates apply on paid plans. Monitor your usage in **NR One → Data Management → Data Ingestion**.
57
+ ### Dashboards
58
+
59
+ - **Local dashboard** — live session view at `localhost:7777`, no account required
60
+ - **7 pre-built New Relic dashboards** — deploy in seconds _(New Relic mode)_:
61
+ - **Overview** — session stats, cost summary, top tools
62
+ - **Personal** — 30-day self-reflection scoped to you
63
+ - **Session Detail** — deep-dive into a single session's tool calls
64
+ - **Team View** — aggregated cost and efficiency across developers
65
+ - **Manager View** — high-level team metrics, no tool-call content
66
+ - **Platform Comparison** — Claude Code vs. Cursor vs. Windsurf, etc.
67
+ - **Security Audit** — audit trail of sensitive file access
53
68
 
54
69
  ---
55
70
 
56
71
  ## Quick Start
57
72
 
58
- **Step 1 Install**
73
+ ### 1. Install
59
74
 
60
75
  ```bash
61
76
  npm install -g @newrelic/preflight
62
77
  ```
63
78
 
64
- **Step 2 Run the interactive setup wizard**
79
+ ### 2. Run setup
65
80
 
66
81
  ```bash
67
82
  preflight setup
68
83
  ```
69
84
 
70
- The wizard first asks for a mode: choose **cloud** to send telemetry to New Relic, or **local** for offline dashboard-only use. In cloud mode it then asks for your license key, account ID, region (US, EU, FedRAMP), and optionally a user API key. It validates keys live before continuing and pre-fills your developer name from the email on the API key. Most people are running in under 5 minutes.
85
+ The wizard defaults to **local mode** press Enter through the prompts and you're set. It wires Preflight into your AI tool (hooks + MCP server) and writes config to `~/.newrelic-preflight/`. Takes under a minute, no account required.
71
86
 
72
- If `NEW_RELIC_LICENSE_KEY`, `NEW_RELIC_ACCOUNT_ID`, or `NEW_RELIC_API_KEY` are already set in your shell environment, the wizard detects them and lets you press Enter to accept — no copy-paste needed.
87
+ When prompted, pick a mode:
73
88
 
74
- Prefer non-interactive? Skip the wizard and run:
89
+ | Mode | What it does | New Relic account? |
90
+ | --------------------- | -------------------------------------------------------------------- | ------------------ |
91
+ | **local** _(default)_ | Everything stays on your machine; live dashboard at `localhost:7777` | Not needed |
92
+ | **cloud** | Ships telemetry to New Relic | Required |
93
+ | **both** | Local dashboard **and** New Relic | Required |
75
94
 
76
- ```bash
77
- preflight install \
78
- --license-key YOUR_LICENSE_KEY \
79
- --account-id YOUR_ACCOUNT_ID
80
- ```
81
-
82
- This installs the hook scripts in your Claude Code settings and registers the MCP server in `~/.mcp.json`, so every tool call is captured and the `nr_observe_*` tools are available in Claude Code. You only run this once.
95
+ ### 3. Start coding
83
96
 
84
- **Step 3Deploy dashboards** _(optional but recommended)_
85
-
86
- Replace `NRAK-...` with your user API key and `12345` with your account ID:
87
-
88
- ```bash
89
- NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
90
- preflight deploy-dashboards --all
91
- ```
92
-
93
- This creates 7 dashboards in your NR account. Find them under **Dashboards** → search "AI Coding". The deploy commands ship with the package — both `preflight deploy-dashboards` and `preflight deploy-alerts` are available immediately after `npm install -g`.
94
-
95
- > **Region:** Use your account's license key and account ID for your environment. Add `--eu` for EU region accounts or `--gov` for FedRAMP accounts. Omit both flags for standard production (`one.newrelic.com`).
96
-
97
- **Step 4 — Restart Claude Code and verify**
98
-
99
- Restart Claude Code, then verify the MCP server connected:
100
-
101
- > _Can you call the `nr_observe_health` tool and show me the result?_
102
-
103
- You should see `"status": "ok"` with a version and uptime. Then make any request to Claude Code (triggering at least one tool call), and check session tracking:
104
-
105
- > _Can you call the `nr_observe_get_session_stats` tool and show me the result?_
106
-
107
- If you get back tool call counts and timing data, it's working.
97
+ Restart your AI tool hooks and the MCP server load at session start. Every tool call is captured automatically. Open **http://localhost:7777** to watch your session live.
108
98
 
109
99
  ---
110
100
 
111
- ## From source / contributing
112
-
113
- This is also the current install path until the npm package is published. Use it to develop the project, deploy dashboards/alerts, or stay on the latest unreleased changes:
101
+ ## Works With
114
102
 
115
- ```bash
116
- git clone https://github.com/newrelic-experimental/preflight
117
- cd preflight
118
- nvm use # Switch to the right Node version (24+)
119
- npm install # Install all dependencies
120
- npm run build # Compile TypeScript
121
- npm link # Register preflight binary on PATH (required for hooks)
122
- ```
123
-
124
- Then run `preflight setup` exactly as in the Quick Start.
125
-
126
- > **`npm link` permission error?** If you see `EACCES: permission denied` pointing at `/usr/local/lib/node_modules`, your system Node.js is installed in a root-owned directory. Pick one fix:
127
- >
128
- > _Quick fix — set a user-writable npm prefix (keeps your existing Node.js):_
129
- >
130
- > ```bash
131
- > npm config set prefix ~/.npm-global
132
- > export PATH="$HOME/.npm-global/bin:$PATH" # also add to ~/.zshrc or ~/.bash_profile
133
- > npm link
134
- > ```
135
- >
136
- > _Recommended — use nvm (better if you switch Node versions):_
137
- >
138
- > ```bash
139
- > curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
140
- > # restart your shell, then:
141
- > nvm install 24 && nvm use 24
142
- > npm install && npm run build && npm link
143
- > ```
144
- >
145
- > Do not use `sudo npm link` — it creates root-owned files that break future `npm install` runs.
103
+ **Claude Code** • **Cursor** • **Windsurf** • **GitHub Copilot** • **Zed** • **Continue.dev** • **Amazon Q Developer**
146
104
 
147
105
  ---
148
106
 
149
- ## Talking to Preflight
150
-
151
- Once installed, Claude Code can query live session data on your behalf. Just ask it in plain English — or use the tool names directly:
152
-
153
- | What to ask | What you get back |
154
- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
155
- | _"Show me my session stats"_ → `nr_observe_get_session_stats` | Tool call counts, success rate, total duration |
156
- | _"What's my efficiency score?"_ → `nr_observe_get_efficiency_score` | A 0-100 score with a breakdown of where points were lost |
157
- | _"How much has this session cost?"_ → `nr_observe_get_cost_breakdown` | USD cost broken down by tool type and AI model |
158
- | _"Any budget warnings?"_ → `nr_observe_get_budget_status` | Current spend vs. your configured caps (if set) |
159
- | _"Any wasteful patterns?"_ → `nr_observe_get_anti_patterns` | Detected inefficiencies — repeated reads, blind edits, stuck loops |
160
- | _"Any recommendations?"_ → `nr_observe_get_recommendations` | Personalized suggestions for this session |
161
- | _"How am I doing this week?"_ → `nr_observe_get_personal_insights` | A narrative coaching report vs. your own historical baseline (requires 2+ weeks of history) |
162
-
163
- Everything also flows into your New Relic dashboards automatically — you don't have to ask Claude to see it there.
164
-
165
- ---
107
+ ## Connect New Relic (optional)
166
108
 
167
- ## Dashboards
109
+ Local mode is fully featured on its own. Connect a New Relic account to unlock:
168
110
 
169
- After deploying, you'll have seven dashboards in NR One:
111
+ - **Team & manager dashboards** across multiple developers
112
+ - **Alerting** on cost spikes, low efficiency, and stuck loops
113
+ - **Cross-session history**, trends, and weekly coaching reports
170
114
 
171
- | Dashboard | What it shows |
172
- | ----------------------- | --------------------------------------------------------------- |
173
- | **Overview** | Session stats, efficiency score, cost summary, top tools |
174
- | **Session Detail** | Every tool call in a specific session, in order |
175
- | **Personal** | 30-day self-reflection view scoped to one developer |
176
- | **Team View** | Aggregated cost and efficiency across multiple developers |
177
- | **Manager View** | Team-level cost by developer with no tool-call content visible |
178
- | **Platform Comparison** | Side-by-side metrics across Claude Code, Cursor, Windsurf, etc. |
179
- | **Security Audit** | Audit trail of sensitive file access and destructive commands |
180
-
181
- ### Personal dashboard
182
-
183
- Deploy a dashboard pre-filtered to your name (it opens already showing your data):
115
+ Re-run `preflight setup` and choose **cloud** or **both**, or configure it non-interactively:
184
116
 
185
117
  ```bash
186
- NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
187
- preflight deploy-dashboards \
188
- ai-coding-assistant-personal.json --developer your-name
118
+ preflight install \
119
+ --mode cloud \
120
+ --license-key YOUR_LICENSE_KEY \
121
+ --account-id YOUR_ACCOUNT_ID
189
122
  ```
190
123
 
191
- ### Updating or removing dashboards
192
-
193
- To replace existing dashboards in place after pulling new fixes (preserves the dashboard's GUID and URL), add `--update`:
194
-
195
- ```bash
196
- NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
197
- preflight deploy-dashboards --all --update
198
- ```
124
+ EU accounts add `--eu`. FedRAMP accounts add `--fedramp`.
199
125
 
200
- To delete the deployed dashboards, add `--teardown`. Dashboards are matched by name; missing ones are skipped:
126
+ Then deploy the prebuilt dashboards:
201
127
 
202
128
  ```bash
203
129
  NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
204
- preflight deploy-dashboards --all --teardown
130
+ preflight deploy-dashboards --all
205
131
  ```
206
132
 
207
- ### Terraform (IaC alternative)
133
+ You'll need a **license key** (telemetry ingest) and your **account ID**, plus a **user API key** (`NRAK-…`) to deploy dashboards and alerts. See [ADVANCED.md](docs/ADVANCED.md) for alerts, OTLP export to other backends, and Terraform.
208
134
 
209
- A Terraform module in `terraform/` deploys all 7 dashboards and the full alert policy as an alternative to the deploy scripts useful for GitOps workflows or when you want state tracking. See [ADVANCED.md — Terraform Deployment](./docs/ADVANCED.md#terraform-deployment) for usage.
135
+ > **Data ingest note:** Telemetry sent to New Relic counts against your account's data ingest. On paid plans, standard ingest rates apply. Monitor your usage under **NR One Data Management Data Ingestion**.
210
136
 
211
137
  ---
212
138
 
213
- ## Alert Conditions
214
-
215
- Optional: get notified in NR when something goes wrong.
216
-
217
- ```bash
218
- NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
219
- preflight deploy-alerts
220
- ```
221
-
222
- Add `--eu` for EU region accounts or `--gov` for FedRAMP accounts. This creates five alert conditions: daily cost spike, low efficiency score, stuck loop rate, anti-pattern rate, and session cost budget. To remove them, add `--teardown`.
139
+ ## Requirements
223
140
 
224
- To apply changes to alert JSONs without losing the existing policy, add `--update`. This syncs conditions in place (matched by name): updates existing ones, creates new ones, and deletes any that have been removed locally:
141
+ ### Required
225
142
 
226
- ```bash
227
- NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
228
- preflight deploy-alerts --update
229
- ```
143
+ - **Node.js v22 or higher** ([get it](https://nodejs.org) or use [nvm](https://github.com/nvm-sh/nvm))
144
+ - **An AI coding tool** (Claude Code recommended for deepest integration)
230
145
 
231
- For personal alerts scoped to your developer name:
146
+ ### Optional
232
147
 
233
- ```bash
234
- NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
235
- preflight deploy-alerts --developer your-name
236
- ```
148
+ - **New Relic account** — only for `cloud`/`both` mode. Skip it to run local-only (the default).
149
+ - **User API key** (`NRAK-…`) only needed to deploy dashboards and alerts
237
150
 
238
151
  ---
239
152
 
240
- ## Configuration
241
-
242
- The easiest way to configure is through the setup wizard (`preflight setup`). To edit manually, open `~/.newrelic-preflight/config.json`:
243
-
244
- ```json
245
- {
246
- "licenseKey": "aabbccdd...",
247
- "accountId": "12345",
248
- "developer": "your-name",
249
- "sessionBudgetUsd": 1.0,
250
- "dailyBudgetUsd": 5.0,
251
- "weeklyBudgetUsd": 20.0
252
- }
253
- ```
254
-
255
- ### Key settings
256
-
257
- | Setting | What it does | Default |
258
- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
259
- | `developer` | Your identifier on all NR events. Automatically normalized to lowercase with underscores — e.g., "John Doe" → "john_doe". Falls back to `$USER` or your git name if not set. | Inferred |
260
- | `collectorHost` | Region override: `null` = US (default), `'eu'` = EU, `'gov'` = FedRAMP/GovCloud. The wizard auto-detects from your license key prefix and lets you confirm. | `null` (US) |
261
- | `nrApiKey` | User API key (`NRAK-...`) for NerdGraph queries (team summaries, dashboard/alert deploy). The wizard prompts for it and validates it live. | Not set |
262
- | `sessionBudgetUsd` | Emits a warning event at 50%, 80%, 100% of this amount per session | No limit |
263
- | `dailyBudgetUsd` | Emits a warning event at 50%, 80%, 100% of this amount per day | No limit |
264
- | `weeklyBudgetUsd` | Emits a warning event at 50%, 80%, 100% of this amount per week | No limit |
265
- | `retainSessionsDays` | Auto-deletes local session files older than N days | Keep forever |
266
- | `teamId` | A label **you define** (e.g. `"platform-eng"`, `"my-team"`) stamped on all NR events as `team_id`, enabling cross-developer queries like `WHERE team_id = 'platform-eng'`. This is **not** your NR account ID — it's a free-form slug you choose to identify your team. | Not set |
267
- | `projectId` | Tags all events with a project name (auto-derived from your git remote URL if not set) | Auto-derived |
268
- | `digestWebhookUrl` | Slack webhook URL for weekly cost and efficiency summaries | Not set |
269
-
270
- All settings can also be set via environment variables — see [example.config.js](./example.config.js) for the full annotated reference.
271
-
272
- ### Validating your config
273
-
274
- If the MCP server fails to connect, run:
153
+ ## Other Commands
275
154
 
276
155
  ```bash
277
- preflight validate
278
- ```
279
-
280
- This checks your config file for JSON syntax errors, invalid field types, and misspelled or unknown keys — and suggests corrections:
281
-
282
- ```
283
- ✗ Error: mode: Invalid enum value. Expected 'cloud' | 'local' | 'both', received 'clod'
284
- ⚠ Warning: Unknown key "licensekey" — did you mean "licenseKey"?
156
+ preflight validate # Check config for syntax errors and unknown keys
157
+ preflight update # Pull latest version and rebuild
158
+ preflight uninstall # Remove hooks and MCP config from your AI tool
285
159
  ```
286
160
 
287
- Pass `--config <path>` to check a file at a non-default location.
288
-
289
- ### OTLP Transport
290
-
291
- To export telemetry to other OpenTelemetry-compatible backends (Datadog, Grafana Cloud, Honeycomb, or New Relic's OTLP endpoint), or to enable an inbound OTLP receiver in proxy mode, see [ADVANCED.md](./docs/ADVANCED.md#otlp-transport).
292
-
293
- ---
294
-
295
- ## Updating
296
-
297
- To pull the latest changes and rebuild in one step:
161
+ Add `--project` to `install`/`uninstall` to scope changes to the current directory only.
298
162
 
299
- ```bash
300
- preflight update
301
- ```
163
+ **WSL users:** `preflight setup` will ask which Claude Code you're running. You can also set it explicitly:
302
164
 
303
- This runs `git pull` followed by `npm run build` in the repo directory. Restart Claude Code afterwards to pick up the new version.
165
+ - `--windows-cc` Windows Claude Code (the desktop app); uses `wsl.exe` hooks and Windows paths
166
+ - `--linux-cc` — Linux Claude Code installed via npm inside WSL
304
167
 
305
168
  ---
306
169
 
307
- ## Uninstalling
308
-
309
- To remove the Preflight hooks and MCP server from Claude Code:
310
-
311
- ```bash
312
- preflight uninstall
313
- ```
314
-
315
- This removes the hooks from your user-level Claude Code settings and deregisters the MCP server. A timestamped backup of your settings is saved automatically before any changes are made.
316
-
317
- If you installed at the project level, add `--project`:
318
-
319
- ```bash
320
- preflight uninstall --project
321
- ```
322
-
323
- Restart Claude Code after uninstalling for the changes to take effect.
324
-
325
- ### Removing dashboards and alerts
326
-
327
- If you deployed dashboards or alerts, tear them down separately:
328
-
329
- ```bash
330
- NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
331
- preflight deploy-dashboards --all --teardown
332
-
333
- NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 \
334
- preflight deploy-alerts --teardown
335
- ```
336
-
337
- ### Removing local data
338
-
339
- Session history and configuration are stored in `~/.newrelic-preflight/`. To remove everything:
340
-
341
- ```bash
342
- rm -rf ~/.newrelic-preflight
343
- ```
344
-
345
- ### Unlinking the binary
346
-
347
- If you registered the CLI globally via `npm link`, remove it with:
170
+ ## Documentation
348
171
 
349
- ```bash
350
- npm unlink -g @newrelic/preflight
351
- ```
172
+ - [**ADVANCED.md**](docs/ADVANCED.md) — Configuration, dashboards, alerts, Terraform
173
+ - [**CONTRIBUTING.md**](CONTRIBUTING.md) Development, testing, submitting PRs
174
+ - [**SECURITY.md**](docs/SECURITY.md) — Security guidelines and best practices
352
175
 
353
176
  ---
354
177
 
355
- ## Local mode
356
-
357
- If you'd rather not ship telemetry to New Relic, set `mode: 'local'` in your config:
358
-
359
- ```json
360
- {
361
- "mode": "local"
362
- }
363
- ```
364
-
365
- In local mode:
366
-
367
- - The MCP server does **not** construct `NrIngestManager` and never makes outbound HTTP calls to NR.
368
- - An embedded dashboard boots at **http://127.0.0.1:7777** (configurable via `dashboard.port` or `NR_AI_DASHBOARD_PORT`).
369
- - All telemetry stays in `~/.newrelic-preflight/` on your machine.
370
- - `licenseKey` and `accountId` are not required.
371
-
372
- **With Claude Code** (default): the server runs via the MCP connection (`--stdio`). You don't launch it manually — Claude Code starts it automatically when you open a session, because `preflight install` registered it as an MCP server. The dashboard stays alive as long as your Claude Code session is open.
178
+ ## From Source
373
179
 
374
- **Standalone** (no Claude Code required): pass `--local` to run the dashboard server directly, without an MCP transport. Use this to browse the dashboard when Claude Code isn't running, or to observe non-Claude-Code sources that hit the hooks (e.g. scripts using the Anthropic SDK). If the per-session MCP is also installed, only one process owns the dashboard at a time — whichever started first — and the other runs headless.
180
+ Develop, test, or run the latest unreleased version:
375
181
 
376
182
  ```bash
377
- npm run build # build once
378
- node dist/index.js --local
379
- # or:
380
- npm run dev # shortcut: assumes dist/ already built
381
- npm run dev:all # build + start in one step
382
- npm run start:local # alias for npm run dev
183
+ git clone https://github.com/newrelic-experimental/preflight
184
+ cd preflight
185
+ nvm use # Switch to Node v24
186
+ npm install # Install dependencies
187
+ npm run build # Compile TypeScript
188
+ npm link # Register preflight on PATH
383
189
  ```
384
190
 
385
- Open `http://127.0.0.1:7777` in your browser. The process stays alive until you press Ctrl+C.
386
-
387
- The dashboard has six views:
388
-
389
- - **Today** — live KPIs, sparkline of tool latencies, recent calls, anti-pattern alerts.
390
- - **Sessions** — list of past sessions with a per-session timeline of every tool call.
391
- - **History** — weekly efficiency and daily spend trends.
392
- - **Audit** — every classified tool call (sensitive file access, destructive commands, external network), with a JSONL export button.
393
- - **Settings** — edit developer name, team ID, budget caps, and session retention from the browser (no config file editing required).
394
- - **Alerts** — live budget spend vs. caps, editable personal alert thresholds, and Slack digest configuration.
395
-
396
- Run `preflight setup` to choose a mode interactively.
397
-
398
- ---
399
-
400
- ## Local Alerts
401
-
402
- Local-mode users get threshold alerting evaluated in-process — no New Relic dependency. Rules live at `~/.newrelic-preflight/alerts/rules.json`; a starter set is copied into place by the setup wizard.
403
-
404
- For the full list of rule types, channel options, alert log configuration, and live reload behavior, see [ADVANCED.md](./docs/ADVANCED.md#local-alerts).
405
-
406
- ---
407
-
408
- ## Weekly Digest
409
-
410
- Register a Slack webhook to receive a weekly summary every Monday morning:
411
-
412
- In Claude Code, ask: _"Call `nr_observe_subscribe_digest` with this webhook URL: `https://hooks.slack.com/services/...`"_
413
-
414
- Or set it in your config file as `digestWebhookUrl`, or configure it directly from the **Alerts** tab in the local dashboard.
415
-
416
- ---
417
-
418
- ## Supported Platforms
419
-
420
- | Platform | How to enable |
421
- | ------------------ | ------------------------------------------------------ |
422
- | Claude Code | `preflight install` (automatic) |
423
- | Cursor | Set `NEW_RELIC_AI_PLATFORM=cursor` in your environment |
424
- | Windsurf | Set `NEW_RELIC_AI_PLATFORM=windsurf` |
425
- | GitHub Copilot | Set `NEW_RELIC_AI_PLATFORM=copilot` |
426
- | Zed | Set `NEW_RELIC_AI_PLATFORM=zed` |
427
- | Continue.dev | Set `NEW_RELIC_AI_PLATFORM=continue` |
428
- | Amazon Q Developer | Set `NEW_RELIC_AI_PLATFORM=amazonq` |
429
-
430
- ---
431
-
432
- ## Glossary
433
-
434
- **MCP (Model Context Protocol)** — A standard that lets AI assistants like Claude Code discover and call external tools. Preflight registers itself as an MCP server so Claude Code can call it directly.
435
-
436
- **License key** — A NR credential for _sending_ data into New Relic. Looks like a long hex string ending in `NRAL`. Found under API Keys in NR One.
437
-
438
- **User API key** — A NR credential for _reading_ data and managing resources (dashboards, alerts). Starts with `NRAK-`. Create one under API Keys in NR One.
439
-
440
- **Anti-pattern** — A detected waste pattern. Examples: re-reading the same file multiple times without making changes between reads (the AI lost context and is reloading it), making edits to a file without reading it first (blind edit), running the same failing command in a loop (stuck loop).
441
-
442
- **Efficiency score** — A 0-100 number per task. High means the AI worked directly toward the goal. Low means wasted tool calls — repeated reads, blind edits, unnecessary backtracking.
443
-
444
- **Token** — The unit AI models use to measure text length for billing. Roughly 3-4 characters per token. One page of text ≈ 500 tokens.
445
-
446
- **Hook** — A script that Claude Code calls automatically before and after every tool call. Preflight uses this to capture tool call data without interrupting your workflow.
447
-
448
- ---
449
-
450
- ## Requirements
451
-
452
- - **Node.js**: v22 or higher (`.nvmrc` pins v24 for development)
453
- - **New Relic account**: free tier works; you need a license key (a user API key is optional — only needed for deploying dashboards and alerts)
454
- - **An AI coding tool**: Claude Code, Cursor, Windsurf, GitHub Copilot, Zed, Continue.dev, or Amazon Q
191
+ Then run `preflight setup` as usual.
455
192
 
456
193
  ---
457
194
 
458
- ## Documentation
195
+ ## License
459
196
 
460
- - **[CONTRIBUTING.md](./CONTRIBUTING.md)** Development setup, architecture, conventions, testing, and end-to-end verification
461
- - **[ADVANCED.md](./docs/ADVANCED.md)** — OTLP export, local alerts, per-developer alerts, session backfill, Terraform deployment
462
- - **[COMMANDS_TABLE.md](./docs/COMMANDS_TABLE.md)** — All MCP tools with parameters and return values
463
- - **[METRICS_TABLE.md](./docs/METRICS_TABLE.md)** — Every event and metric sent to New Relic
464
- - **[SECURITY.md](./docs/SECURITY.md)** — Security practices and audit trail
197
+ Preflight is open source under the [Apache License 2.0](LICENSE).
465
198
 
466
199
  ---
467
200
 
468
- ## For Contributors
469
-
470
- ### Development setup
471
-
472
- ```bash
473
- nvm install && nvm use
474
- npm install
475
- npm run build
476
- npm test
477
- ```
478
-
479
- ### Common tasks
480
-
481
- | Command | Purpose |
482
- | ---------------------- | ---------------------------------------------------------- |
483
- | `npm run build` | Build TypeScript server + Vite web dashboard |
484
- | `npm run build:server` | Build only the TypeScript server (`tsc --build`) |
485
- | `npm run build:web` | Build only the Vite web dashboard (output: `dist/web/`) |
486
- | `npm test` | Run all tests |
487
- | `npm run lint` | Check code style |
488
- | `npm run format` | Auto-format code |
489
- | `npm run dev` | Start local dashboard (assumes pre-built `dist/`) |
490
- | `npm run dev:all` | Build then start local dashboard |
491
- | `npm run dev:full` | Build backend, then run backend + Vite dev server together |
492
- | `npm run start:local` | Alias for `npm run dev` |
201
+ ## Contributing
493
202
 
494
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for the full development guide, conventions, and architecture.
203
+ We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for how to get started. Join the [New Relic Community](https://support.newrelic.com/s/) to share ideas, ask questions, or discuss features.
495
204
 
496
205
  ---
497
206
 
498
- **Questions?** Start with [CONTRIBUTING.md](./CONTRIBUTING.md) or [open an issue](https://github.com/newrelic-experimental/preflight/issues).
207
+ <div align="center">
208
+ <p><strong>Built by New Relic • Designed for developers who use AI</strong></p>
209
+ </div>
package/dist/config.d.ts CHANGED
@@ -38,6 +38,7 @@ export interface McpServerConfig {
38
38
  readonly otlpHeaders: Readonly<Record<string, string>>;
39
39
  readonly transport: 'nr-events-api' | 'otlp' | 'both';
40
40
  readonly mode: 'cloud' | 'local' | 'both';
41
+ readonly platformTarget?: PlatformTarget;
41
42
  /** Enable the local OTLP/HTTP receiver. Default: false. */
42
43
  readonly otlpReceiverEnabled: boolean;
43
44
  /** Port for the local OTLP/HTTP receiver. Default: 4318. */
@@ -75,6 +76,7 @@ export interface McpServerConfig {
75
76
  };
76
77
  }
77
78
  export declare const DEFAULT_STORAGE_PATH: string;
79
+ export type PlatformTarget = 'native' | 'wsl-windows-cc' | 'wsl-linux-cc';
78
80
  export declare const ConfigFileSchema: z.ZodObject<{
79
81
  licenseKey: z.ZodOptional<z.ZodString>;
80
82
  accountId: z.ZodOptional<z.ZodString>;
@@ -119,6 +121,11 @@ export declare const ConfigFileSchema: z.ZodObject<{
119
121
  cloud: "cloud";
120
122
  local: "local";
121
123
  }>>;
124
+ platformTarget: z.ZodOptional<z.ZodEnum<{
125
+ native: "native";
126
+ "wsl-windows-cc": "wsl-windows-cc";
127
+ "wsl-linux-cc": "wsl-linux-cc";
128
+ }>>;
122
129
  otlpReceiverEnabled: z.ZodOptional<z.ZodBoolean>;
123
130
  otlpReceiverPort: z.ZodOptional<z.ZodNumber>;
124
131
  otlpReceiverBindAddress: z.ZodOptional<z.ZodString>;