cursor-companion-ai 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 +21 -0
- package/README.md +132 -0
- package/dist/companion.js +253 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
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
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# cursor-companion-ai
|
|
2
|
+
|
|
3
|
+
An AI cursor that reads any web page and guides users by pointing at the exact element to interact with, with a short caption. Drop into any HTML page with one `<script>` tag.
|
|
4
|
+
|
|
5
|
+
- Right-click anywhere → type a goal in plain English → the cursor flies to each step.
|
|
6
|
+
- Two modes per goal: **Teach me** (highlight, you click) and **Do it for me** (autonomous, fills inputs + clicks through).
|
|
7
|
+
- Works on any DOM-driven app — no `data-*` tags required (auto-labels elements from text / aria-label / nearby context).
|
|
8
|
+
- BYOK: ship your own Anthropic API key and the library calls `api.anthropic.com` directly from the browser. No backend to host.
|
|
9
|
+
|
|
10
|
+
## Quick start
|
|
11
|
+
|
|
12
|
+
```html
|
|
13
|
+
<script
|
|
14
|
+
src="https://cdn.jsdelivr.net/npm/cursor-companion-ai@latest/dist/companion.js"
|
|
15
|
+
data-anthropic-key="sk-ant-..."
|
|
16
|
+
data-context="This is My App. The 'Reports' tab is at the top. When users say 'export', they mean the download button in the toolbar."
|
|
17
|
+
></script>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
That's it. Reload the page → right-click anywhere → companion panel appears at the cursor → type a goal.
|
|
21
|
+
|
|
22
|
+
## Configuration
|
|
23
|
+
|
|
24
|
+
All config is via `data-*` attributes on the `<script>` tag.
|
|
25
|
+
|
|
26
|
+
| Attribute | Required | What it does |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| `data-anthropic-key` | Yes (for direct mode) | Your Anthropic API key (`sk-ant-...`). The library calls Anthropic from the browser with this key. **Visible in page source** — see the security note below. |
|
|
29
|
+
| `data-context` | Recommended | Plain-English description of your app: page names, terminology, conventions, edge cases. Prepended to every model call so the AI sounds like it knows your product. |
|
|
30
|
+
| `data-endpoint` | Optional | If set, requests go to your own backend at this URL instead of direct Anthropic. Use this in production where the key shouldn't be in the browser. The backend just relays to Anthropic with a server-held key. |
|
|
31
|
+
|
|
32
|
+
## Security note
|
|
33
|
+
|
|
34
|
+
`data-anthropic-key` puts the key in your page's HTML and JS bundle. Anyone who views the page source can read it.
|
|
35
|
+
|
|
36
|
+
- ✅ **Safe inside an authenticated dashboard** where only logged-in users see the script tag. They're trusted to not abuse the key, or each user supplies their own.
|
|
37
|
+
- ✅ **Safe in dev environments** where you control who has access.
|
|
38
|
+
- ❌ **NOT safe on a public marketing page** where any visitor can grab the key.
|
|
39
|
+
|
|
40
|
+
For production / public deployments, run your own thin proxy at `/api/chat` and point `data-endpoint` at it. The proxy holds the key server-side and forwards requests. See [examples/proxy](#run-your-own-proxy-optional) below.
|
|
41
|
+
|
|
42
|
+
## Programmatic API
|
|
43
|
+
|
|
44
|
+
The script also exposes setters on the global window for runtime updates:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
// Update the context as the user navigates between pages
|
|
48
|
+
window.companion.setContext("Now on /reports — exports go via the toolbar Download button.");
|
|
49
|
+
|
|
50
|
+
// Replace the API key
|
|
51
|
+
window.companion.setAnthropicKey("sk-ant-new-key");
|
|
52
|
+
|
|
53
|
+
// Point at a different proxy
|
|
54
|
+
window.companion.setEndpoint("https://my-proxy.example.com/api/chat");
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
(Programmatic setters are coming in 0.2; for now use the `data-*` attributes.)
|
|
58
|
+
|
|
59
|
+
## Run your own proxy (optional)
|
|
60
|
+
|
|
61
|
+
If you don't want the key in the browser, run a tiny proxy that forwards requests to Anthropic. The minimal Next.js route looks like:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
// app/api/chat/route.ts
|
|
65
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
66
|
+
|
|
67
|
+
export const runtime = "nodejs";
|
|
68
|
+
|
|
69
|
+
export async function POST(req: NextRequest) {
|
|
70
|
+
const body = await req.json();
|
|
71
|
+
// Inject the server-side key — overrides anything the browser sent
|
|
72
|
+
body.anthropicKey = process.env.ANTHROPIC_API_KEY;
|
|
73
|
+
// Forward to your own /api/chat implementation or call Anthropic here.
|
|
74
|
+
// For a full reference, see the source repo: lib/guide.ts + app/api/chat/route.ts
|
|
75
|
+
const r = await fetch("https://api.anthropic.com/v1/messages", {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: {
|
|
78
|
+
"x-api-key": process.env.ANTHROPIC_API_KEY!,
|
|
79
|
+
"anthropic-version": "2023-06-01",
|
|
80
|
+
"content-type": "application/json",
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify(body),
|
|
83
|
+
});
|
|
84
|
+
return NextResponse.json(await r.json());
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Then on the script tag:
|
|
89
|
+
|
|
90
|
+
```html
|
|
91
|
+
<script
|
|
92
|
+
src="https://cdn.jsdelivr.net/npm/cursor-companion-ai@latest/dist/companion.js"
|
|
93
|
+
data-endpoint="/api/chat"
|
|
94
|
+
data-context="..."
|
|
95
|
+
></script>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## How it works
|
|
99
|
+
|
|
100
|
+
Each step:
|
|
101
|
+
|
|
102
|
+
1. The companion serializes every visible interactive element on the page (auto-labeled from `text`, `aria-label`, nearby headings/labels, etc.).
|
|
103
|
+
2. Sends `{ goal, elements, history, context }` to Claude (direct from browser, or via your proxy).
|
|
104
|
+
3. Claude returns one JSON object: which element to point at next + what to say.
|
|
105
|
+
4. Cursor springs to the element, draws a highlight ring, shows the caption.
|
|
106
|
+
5. After the user clicks (Teach mode) or after the auto-action (Do it for me), waits for the DOM to settle, then asks for the next step.
|
|
107
|
+
6. Loops until done.
|
|
108
|
+
|
|
109
|
+
If Claude can't tell what to do from text alone, it can ask for a screenshot via a `request_screenshot` tool — captured client-side via `html2canvas`, sent back as an image.
|
|
110
|
+
|
|
111
|
+
## Bundle
|
|
112
|
+
|
|
113
|
+
- ~970 KB minified, ~250 KB gzipped over the wire.
|
|
114
|
+
- Includes: React + ReactDOM, framer-motion (cursor + ring animations), html2canvas (screenshot tool), the bundled Anthropic SDK, the companion components, and a Tailwind CSS slice scoped to the companion's UI.
|
|
115
|
+
|
|
116
|
+
## Build from source
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
git clone https://github.com/your-handle/cursor-companion.git
|
|
120
|
+
cd cursor-companion
|
|
121
|
+
npm install
|
|
122
|
+
npm run build:embed # produces dist/companion.js
|
|
123
|
+
npm run dev # Next.js demo at http://localhost:3000
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The demo at `/dashboard-complex` shows the companion guiding through a construction-supply-chain CRM with 9 pages of inputs, modals, tabs, and a kanban board.
|
|
127
|
+
|
|
128
|
+
The demo at `/embed-demo.html` shows the same companion mounted on a plain HTML page via the `<script>` tag — no React or Tailwind on the host.
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT. Use it, fork it, ship it.
|