viagen 0.0.3 → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ben Ipsen
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,15 +1,19 @@
1
- # Viagen (Vite Agent)
1
+ # viagen
2
2
 
3
- A Vite plugin that embeds Claude Code into any Vite dev server.
3
+ A Vite plugin and CLI tool that enables you to use Claude Code in a sandbox instantly.
4
4
 
5
- ## Install
5
+ ## Prerequisites
6
+
7
+ - [Claude](https://claude.ai/signup) — Max, Pro, or API plan. The setup wizard handles auth.
8
+ - [Vercel](https://vercel.com/signup) — Free plan works. Sandboxes last 45 min on Hobby, 5 hours on Pro.
9
+ - [GitHub CLI](https://cli.github.com) — Enables git clone and push from sandboxes.
10
+
11
+ ## Step 1 — Add viagen to your app
6
12
 
7
13
  ```bash
8
14
  npm install viagen
9
15
  ```
10
16
 
11
- ## Setup
12
-
13
17
  ```ts
14
18
  // vite.config.ts
15
19
  import { defineConfig } from 'vite'
@@ -20,87 +24,106 @@ export default defineConfig({
20
24
  })
21
25
  ```
22
26
 
23
- Set `ANTHROPIC_API_KEY` in your `.env`, start the dev server.
27
+ ## Step 2 Setup
24
28
 
25
- ## Options
26
-
27
- ```ts
28
- viagen({
29
- position: 'bottom-right', // toggle button: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
30
- model: 'sonnet', // claude model
31
- panelWidth: 420, // chat panel width in px
32
- overlay: true, // "Fix This Error" button on Vite error overlay
33
- ui: true, // inject toggle button + chat panel into pages
34
- })
29
+ ```bash
30
+ npx viagen setup
35
31
  ```
36
32
 
37
- All options are optional. Defaults shown above.
33
+ The setup wizard authenticates with Claude then uses GitHub and Vercel to write your local `.env`.
38
34
 
39
- ## Sandbox
35
+ You can now run `npm run dev` to start the local dev server. At this point you can launch viagen and chat with Claude to make changes to your app.
40
36
 
41
- Deploy your dev server to a remote Vercel Sandbox:
37
+ ## Step 3 Sandbox
42
38
 
43
39
  ```bash
44
40
  npx viagen sandbox
45
41
  ```
46
42
 
47
- This creates an isolated microVM, uploads your project, installs dependencies, and starts the dev server. All endpoints are protected with token-based auth.
48
-
49
- **Prerequisites:** `ANTHROPIC_API_KEY` in `.env` + Vercel auth (`vercel link && vercel env pull` or set `VERCEL_TOKEN`, `VERCEL_TEAM_ID`, `VERCEL_PROJECT_ID`).
43
+ Deploys your dev server to a remote Vercel Sandbox an isolated VM-like environment where Claude can read, write, and push code.
50
44
 
51
45
  ```bash
52
- npx viagen sandbox stop <sandboxId> # Stop a running sandbox
53
- ```
46
+ # Deploy on a specific branch
47
+ npx viagen sandbox --branch feature/my-thing
54
48
 
55
- ## CLI (coming soon)
49
+ # Set a longer timeout (default: 30 min)
50
+ npx viagen sandbox --timeout 60
56
51
 
57
- `npx viagen setup` — interactive setup that uses the Vercel CLI under the hood to log in, pick a team, link a project, and write all the credentials to `.env` so `npx viagen sandbox` just works.
58
-
59
- ## Auth
52
+ # Stop a running sandbox
53
+ npx viagen sandbox stop <sandboxId>
54
+ ```
60
55
 
61
- Set `VIAGEN_AUTH_TOKEN` in `.env` to protect all endpoints. When set:
56
+ ## Vite Plugin Options
62
57
 
63
- - Browser: visit `?token=<token>` to set a session cookie
64
- - API: use `Authorization: Bearer <token>` header
58
+ ```ts
59
+ viagen({
60
+ position: 'bottom-right', // toggle button position
61
+ model: 'sonnet', // claude model
62
+ panelWidth: 420, // chat panel width in px
63
+ overlay: true, // fix button on error overlay
64
+ ui: true, // inject chat panel into pages
65
+ systemPrompt: '...', // custom system prompt (see below)
66
+ })
67
+ ```
65
68
 
66
- Auth is automatic when deploying via `npx viagen sandbox`.
69
+ The default system prompt:
67
70
 
68
- ## Endpoints
71
+ ```
72
+ You are embedded in a Vite dev server as the "viagen" plugin. Your job is to
73
+ help build and modify the app. Files you edit will trigger Vite HMR
74
+ automatically. You can read .viagen/server.log to check recent Vite dev server
75
+ output (compile errors, HMR updates, warnings). Be concise.
76
+ ```
69
77
 
70
- **`POST /via/chat`** Send a message, get a streamed response.
78
+ Recent build errors are automatically appended to give Claude context about what went wrong. To customize the prompt, you can replace it entirely or extend the default:
71
79
 
72
- ```bash
73
- curl -N -X POST http://localhost:5173/via/chat \
74
- -H "Content-Type: application/json" \
75
- -d '{"message": "add a dark mode toggle"}'
76
- ```
80
+ ```ts
81
+ import { viagen, DEFAULT_SYSTEM_PROMPT } from 'viagen'
77
82
 
78
- Response is SSE with `data:` lines containing JSON:
83
+ viagen({
84
+ // Replace entirely
85
+ systemPrompt: 'You are a React expert. Only use TypeScript.',
79
86
 
80
- ```
81
- data: {"type":"text","text":"I'll add a dark mode toggle..."}
82
- data: {"type":"tool_use","name":"Edit","input":{"file_path":"src/App.tsx"}}
83
- data: {"type":"text","text":"Done! The toggle is in the header."}
84
- event: done
85
- data: {}
87
+ // Or extend the default
88
+ systemPrompt: DEFAULT_SYSTEM_PROMPT + '\nAlways use Tailwind for styling.',
89
+ })
86
90
  ```
87
91
 
88
- **`POST /via/chat/reset`** — Clear conversation history.
92
+ ## API
89
93
 
90
- **`GET /via/health`** Check if `ANTHROPIC_API_KEY` is configured.
94
+ Every viagen endpoint is available as an API. Build your own UI, integrate with CI, or script Claude from the command line.
91
95
 
92
- **`GET /via/error`** — Get the latest Vite build error (if any).
96
+ ```
97
+ POST /via/chat — send a message, streamed SSE response
98
+ POST /via/chat/reset — clear conversation history
99
+ GET /via/health — check API key status
100
+ GET /via/error — latest build error (if any)
101
+ GET /via/ui — standalone chat interface
102
+ ```
93
103
 
94
- ## UI
104
+ When `VIAGEN_AUTH_TOKEN` is set (always on in sandboxes), pass the token as a `Bearer` header or `?token=` query param.
95
105
 
96
- The plugin injects a `via` toggle button into your page. Click it to open the chat panel. Build errors get a "Fix This Error" button on the Vite error overlay.
106
+ ```bash
107
+ # With curl
108
+ curl -X POST http://localhost:5173/via/chat \
109
+ -H "Authorization: Bearer $VIAGEN_AUTH_TOKEN" \
110
+ -H "Content-Type: application/json" \
111
+ -d '{"message": "add a hello world route"}'
97
112
 
98
- You can also open the chat UI directly at `http://localhost:5173/via/ui`.
113
+ # Or pass the token as a query param (sets a session cookie)
114
+ open "http://localhost:5173/via/ui?token=$VIAGEN_AUTH_TOKEN"
115
+ ```
99
116
 
100
117
  ## Development
101
118
 
102
119
  ```bash
103
120
  npm install
104
- npm run dev # Dev server
121
+ npm run dev # Dev server (site)
105
122
  npm run build # Build with tsup
123
+ npm run test # Run tests
124
+ npm run typecheck # Type check
106
125
  ```
126
+
127
+ ## License
128
+
129
+ [MIT](LICENSE)