react-detective 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hy Phan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,136 @@
1
- # Temporary Holding Version
1
+ # React Detective
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Understand a React codebase by pointing at it. Click any part of your running app and get an explanation of the component behind it: what it's for, what its props and state do, and where it's used, alongside the live values from the page you're looking at.
4
+
5
+ Useful when you're new to a codebase, or when the code was written by AI and nobody has read it closely.
6
+
7
+ Works with **Vite** and **Next.js**. Runs only in development.
8
+
9
+ ## Setup
10
+
11
+ ### Automatic
12
+
13
+ Run this in your project:
14
+
15
+ ```bash
16
+ npx react-detective init
17
+ ```
18
+
19
+ It installs the package, adds it to your Vite or Next.js config, and offers to save your API key. You'll see every change before it's made.
20
+
21
+ ### Manual
22
+
23
+ ```bash
24
+ npm i -D react-detective
25
+ ```
26
+
27
+ **Vite**
28
+
29
+ ```ts
30
+ // vite.config.ts
31
+ import react from "@vitejs/plugin-react";
32
+ import detective from "react-detective/vite";
33
+
34
+ export default defineConfig({
35
+ plugins: [detective(), react()],
36
+ });
37
+ ```
38
+
39
+ **Next.js**
40
+
41
+ ```js
42
+ // next.config.mjs
43
+ import { withDetective } from "react-detective/next";
44
+
45
+ export default withDetective({
46
+ /* your config */
47
+ });
48
+ ```
49
+
50
+ ```tsx
51
+ // app/layout.tsx
52
+ import { Detective } from "react-detective/react";
53
+
54
+ export default function RootLayout({ children }) {
55
+ return (
56
+ <html>
57
+ <body>
58
+ {children}
59
+ <Detective />
60
+ </body>
61
+ </html>
62
+ );
63
+ }
64
+ ```
65
+
66
+ Start your dev server as usual. A **Detective** badge appears in the corner of the page.
67
+
68
+ ### Options
69
+
70
+ ```ts
71
+ detective({ model: "opus" }); // Vite
72
+ withDetective(config, { model: "opus" }); // Next.js
73
+ ```
74
+
75
+ | Option | Default | |
76
+ | --- | --- | --- |
77
+ | `model` | `"sonnet"` | Model for explanations and follow-up questions: `"haiku"`, `"sonnet"`, `"opus"` or a full model ID. |
78
+ | `storeDir` | `".react-detective"` | Where explanations are saved. |
79
+ | `showLauncher` | `true` | Show the **Detective** badge. You can still press **Alt** without it. |
80
+ | `port` (Next.js) | `5899` | Port for the local server. `<Detective />` picks it up automatically. |
81
+
82
+ ### API key
83
+
84
+ Explanations are written by Claude, using your own [Anthropic API key](https://console.anthropic.com/settings/keys). You can add it any time: without one, everything works except writing new explanations and answers. Add it to `.env.local` in your project (make sure that file is in `.gitignore`):
85
+
86
+ ```bash
87
+ ANTHROPIC_API_KEY=sk-ant-...
88
+ ```
89
+
90
+ An `ANTHROPIC_API_KEY` set in your environment works too. No restart needed.
91
+
92
+ ## Usage
93
+
94
+ 1. Press **Alt** (or click the badge) to start inspecting.
95
+ 2. Hover to see each component's name and file.
96
+ 3. Click one to open its explanation.
97
+
98
+ Then:
99
+
100
+ - Expand items in the outline to see what they do and their current values.
101
+ - Hover a highlighted name or type to preview it; click to jump to it.
102
+ - Click a file or line to open it in your editor.
103
+ - Use the breadcrumbs at the top to move to a parent component.
104
+ - Ask follow-up questions in the box at the bottom.
105
+ - Press **Esc** to stop inspecting or close the panel.
106
+
107
+ ## What it costs
108
+
109
+ You'll see an outline of the component immediately, read straight from your code at no cost. The full explanation follows within about 20 seconds and typically costs a few cents.
110
+
111
+ You only pay once per explanation. They're saved in a `.react-detective/` folder in your project and opened instantly next time, until the code changes. **Commit this folder** so your team gets them for free too.
112
+
113
+ ## Privacy and safety
114
+
115
+ - The AI can read files in your project but can't change anything or run commands.
116
+ - Your API key stays in the local dev server. It's never sent to the browser or saved with the explanations.
117
+ - Code is sent to Anthropic only when a new explanation or answer is generated; saved ones are served from disk.
118
+ - Nothing is added to production builds.
119
+
120
+ ## Limitations
121
+
122
+ - Works with Vite and Next.js. Frameworks built on Vite, like React Router, use the Vite setup. Using something else? Open an issue.
123
+ - Components that render no HTML of their own (wrappers, providers) can't be clicked directly. Reach them through the breadcrumbs.
124
+ - Live values are available for client components only.
125
+
126
+ ## Contributing
127
+
128
+ ```bash
129
+ npm install
130
+ npm run build # build the library
131
+ npm test # run tests
132
+ npm run dev:vite # Vite demo on http://localhost:5173
133
+ npm run dev:next # Next.js demo on http://localhost:3000
134
+ ```
135
+
136
+ The library is in `packages/react-detective`; demo apps are in `examples/`.