viagen 0.0.2 → 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,58 +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
28
+
29
+ ```bash
30
+ npx viagen setup
31
+ ```
32
+
33
+ The setup wizard authenticates with Claude then uses GitHub and Vercel to write your local `.env`.
34
+
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.
36
+
37
+ ## Step 3 — Sandbox
38
+
39
+ ```bash
40
+ npx viagen sandbox
41
+ ```
42
+
43
+ Deploys your dev server to a remote Vercel Sandbox — an isolated VM-like environment where Claude can read, write, and push code.
44
+
45
+ ```bash
46
+ # Deploy on a specific branch
47
+ npx viagen sandbox --branch feature/my-thing
48
+
49
+ # Set a longer timeout (default: 30 min)
50
+ npx viagen sandbox --timeout 60
51
+
52
+ # Stop a running sandbox
53
+ npx viagen sandbox stop <sandboxId>
54
+ ```
24
55
 
25
- ## Options
56
+ ## Vite Plugin Options
26
57
 
27
58
  ```ts
28
59
  viagen({
29
- position: 'bottom-right', // toggle button: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
60
+ position: 'bottom-right', // toggle button position
30
61
  model: 'sonnet', // claude model
31
62
  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
63
+ overlay: true, // fix button on error overlay
64
+ ui: true, // inject chat panel into pages
65
+ systemPrompt: '...', // custom system prompt (see below)
34
66
  })
35
67
  ```
36
68
 
37
- All options are optional. Defaults shown above.
69
+ The default system prompt:
38
70
 
39
- ## 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
+ ```
40
77
 
41
- **`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:
42
79
 
43
- ```bash
44
- curl -N -X POST http://localhost:5173/via/chat \
45
- -H "Content-Type: application/json" \
46
- -d '{"message": "add a dark mode toggle"}'
47
- ```
80
+ ```ts
81
+ import { viagen, DEFAULT_SYSTEM_PROMPT } from 'viagen'
48
82
 
49
- Response is SSE with `data:` lines containing JSON:
83
+ viagen({
84
+ // Replace entirely
85
+ systemPrompt: 'You are a React expert. Only use TypeScript.',
50
86
 
51
- ```
52
- data: {"type":"text","text":"I'll add a dark mode toggle..."}
53
- data: {"type":"tool_use","name":"Edit","input":{"file_path":"src/App.tsx"}}
54
- data: {"type":"text","text":"Done! The toggle is in the header."}
55
- event: done
56
- data: {}
87
+ // Or extend the default
88
+ systemPrompt: DEFAULT_SYSTEM_PROMPT + '\nAlways use Tailwind for styling.',
89
+ })
57
90
  ```
58
91
 
59
- **`POST /via/chat/reset`** — Clear conversation history.
92
+ ## API
60
93
 
61
- **`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.
62
95
 
63
- **`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
+ ```
64
103
 
65
- ## UI
104
+ When `VIAGEN_AUTH_TOKEN` is set (always on in sandboxes), pass the token as a `Bearer` header or `?token=` query param.
66
105
 
67
- 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"}'
68
112
 
69
- 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
+ ```
70
116
 
71
117
  ## Development
72
118
 
73
119
  ```bash
74
120
  npm install
75
- npm run dev # Playground dev server
121
+ npm run dev # Dev server (site)
76
122
  npm run build # Build with tsup
123
+ npm run test # Run tests
124
+ npm run typecheck # Type check
77
125
  ```
126
+
127
+ ## License
128
+
129
+ [MIT](LICENSE)