@vtriv/cli 0.1.0 → 0.1.2

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.
Files changed (3) hide show
  1. package/README.md +237 -30
  2. package/index.ts +601 -403
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # vtriv CLI
2
2
 
3
- Command-line interface for vtriv backend services.
3
+ Command-line interface for vtriv backend services. Uses account-based authentication to manage projects.
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,53 +16,260 @@ bun link
16
16
  vtriv --help
17
17
  ```
18
18
 
19
+ ## Authentication Model
20
+
21
+ The CLI uses a two-tier authentication system:
22
+
23
+ 1. **Account Key** (`vtriv_ak_...`) - Used to create and manage projects
24
+ 2. **API Keys** (`vtriv_sk_...`) - Per-project, used to mint JWTs for service calls
25
+
26
+ Configuration is stored in `~/.config/vtriv/config.json` with `0600` permissions.
27
+
28
+ ### How It Works
29
+
30
+ 1. Run `vtriv config` to set up your account key
31
+ 2. Run `vtriv init <name>` to create a project and API key
32
+ 3. CLI uses the API key to mint short-lived JWTs
33
+ 4. JWTs are cached for 55 minutes (tokens valid for 60)
34
+
35
+ Project names are automatically prefixed with your account slug (e.g., `a1b2c3d4-my-app`), but you work with short names in the CLI.
36
+
19
37
  ## Setup
20
38
 
39
+ ### Configure Account
40
+
21
41
  ```bash
22
- # Initialize configuration
23
- vtriv init
42
+ vtriv config
24
43
  ```
25
44
 
26
- This creates `~/.vtrivrc` with your API gateway URL and bootstrap key.
45
+ You'll be prompted for:
46
+ - Base URL (default: `http://localhost:3000`)
47
+ - Account key (`vtriv_ak_...`)
48
+
49
+ The CLI verifies the account key and fetches your account slug.
27
50
 
28
- ## Quick Start
51
+ ### Create a Project
29
52
 
30
53
  ```bash
31
- # List projects
32
- vtriv auth project:list
54
+ vtriv init my-app
55
+ ```
33
56
 
34
- # Create a project
35
- vtriv auth project:create my-app
57
+ This:
58
+ 1. Creates project `{slug}-my-app` on the server
59
+ 2. Creates an API key for the project
60
+ 3. Saves the profile locally
36
61
 
37
- # Create a user
38
- vtriv auth user:create my-app admin@example.com secretpass
62
+ ### Multiple Projects
39
63
 
40
- # List documents
41
- vtriv db ls my-app posts
64
+ ```bash
65
+ # Create another project
66
+ vtriv init staging --default
42
67
 
43
- # Create a document
44
- echo '{"title":"Hello"}' | vtriv db put my-app posts
68
+ # Use a specific profile
69
+ vtriv --profile my-app db ls posts
70
+ ```
71
+
72
+ ### View Status
45
73
 
46
- # Search
47
- vtriv search query my-app posts "hello world"
74
+ ```bash
75
+ vtriv status
76
+ ```
77
+
78
+ Shows your account, configured profiles, and which is default.
79
+
80
+ ### Manage Projects
81
+
82
+ ```bash
83
+ # List all projects
84
+ vtriv project ls
85
+
86
+ # Delete a project
87
+ vtriv project rm my-app
48
88
  ```
49
89
 
50
90
  ## Commands
51
91
 
52
- - `vtriv init` - Setup configuration
53
- - `vtriv auth` - Auth service (projects, users, tokens, API keys)
54
- - `vtriv db` - Database service (ls, get, put, rm, schema)
55
- - `vtriv blob` - Blob storage (put, get, rm)
56
- - `vtriv cron` - Cron jobs (ls, runs, trigger, script:cat)
57
- - `vtriv ai` - AI service (stats, chat)
58
- - `vtriv search` - Search service (config, query)
92
+ ### Global Options
93
+
94
+ | Option | Description |
95
+ |--------|-------------|
96
+ | `--json` | Output raw JSON (for scripts/agents) |
97
+ | `--profile <name>` | Use a specific profile |
98
+ | `--debug` | Show HTTP curl equivalents |
99
+
100
+ ### Token Commands
101
+
102
+ ```bash
103
+ # Mint and display a JWT
104
+ vtriv token
105
+
106
+ # Mint with specific template
107
+ vtriv token --template ai-enabled
108
+ ```
109
+
110
+ ### Template Commands
111
+
112
+ Manage token templates for your project.
113
+
114
+ ```bash
115
+ # List all templates
116
+ vtriv template ls
117
+
118
+ # Get a specific template
119
+ vtriv template get default
120
+
121
+ # Create/update a template (reads JSON from stdin)
122
+ vtriv template set ai-enabled <<< '{"x-db": true, "x-blob": true, "x-ai": true}'
123
+
124
+ # Delete a template (cannot delete 'default')
125
+ vtriv template rm ai-enabled
126
+ ```
127
+
128
+ ### Database Commands
129
+
130
+ ```bash
131
+ # List documents
132
+ vtriv db ls posts
133
+ vtriv db ls posts --filter '{"status":"published"}' --limit 10 --sort -_created_at
134
+
135
+ # Get a document
136
+ vtriv db get posts abc-123
137
+
138
+ # Create a document (reads JSON from stdin)
139
+ echo '{"title":"Hello","body":"World"}' | vtriv db put posts
140
+
141
+ # Update a document
142
+ echo '{"title":"Updated"}' | vtriv db put posts abc-123
143
+
144
+ # Delete a document
145
+ vtriv db rm posts abc-123
146
+
147
+ # Get/set collection schema
148
+ vtriv db schema posts
149
+ echo '{"indexes":["status"],"unique":["slug"]}' | vtriv db schema posts --set
150
+ ```
151
+
152
+ ### Blob Commands
153
+
154
+ ```bash
155
+ # Upload a file
156
+ vtriv blob put images/photo.jpg ./local-photo.jpg
157
+
158
+ # Download a file (outputs to stdout)
159
+ vtriv blob get images/photo.jpg > downloaded.jpg
160
+
161
+ # Delete a file
162
+ vtriv blob rm images/photo.jpg
163
+ ```
164
+
165
+ ### Cron Commands
166
+
167
+ ```bash
168
+ # List jobs
169
+ vtriv cron ls
170
+
171
+ # View run history
172
+ vtriv cron runs
173
+ vtriv cron runs --limit 50 --job daily-backup
174
+
175
+ # Manually trigger a job
176
+ vtriv cron trigger daily-backup
177
+
178
+ # View a script
179
+ vtriv cron script:cat backup.ts
180
+ ```
181
+
182
+ ### AI Commands
183
+
184
+ ```bash
185
+ # Simple chat
186
+ vtriv ai chat "What is the capital of France?"
187
+
188
+ # With specific model
189
+ vtriv ai chat "Explain quantum computing" --model anthropic/claude-3.5-sonnet
190
+
191
+ # View usage statistics
192
+ vtriv ai stats
193
+ vtriv ai stats --period 7
194
+
195
+ # Get/set AI config
196
+ vtriv ai config
197
+ vtriv ai config --model openai/gpt-4o --rate-limit 10.0
198
+ ```
199
+
200
+ ### Search Commands
201
+
202
+ ```bash
203
+ # Get index configuration
204
+ vtriv search config posts
205
+
206
+ # Set index configuration (reads JSON from stdin)
207
+ echo '{"model":"openai/text-embedding-3-small","dimensions":1536,"input_fields":["title","body"],"store_fields":["id","title","slug"]}' | vtriv search config posts --set
208
+
209
+ # Search an index
210
+ vtriv search query posts "semantic search" --limit 20
211
+ ```
212
+
213
+ ## Output Formats
214
+
215
+ By default, the CLI formats output as tables:
216
+
217
+ ```
218
+ $ vtriv db ls posts
219
+ id title status
220
+ -----------------------------------------
221
+ abc-123 Hello World published
222
+ def-456 Draft Post draft
223
+ ```
224
+
225
+ Use `--json` for machine-readable output:
226
+
227
+ ```bash
228
+ $ vtriv db ls posts --json
229
+ [
230
+ {"id": "abc-123", "title": "Hello World", "status": "published"},
231
+ {"id": "def-456", "title": "Draft Post", "status": "draft"}
232
+ ]
233
+ ```
234
+
235
+ ## Debugging
236
+
237
+ Use `--debug` to see the curl equivalent of each request:
238
+
239
+ ```bash
240
+ $ vtriv --debug db ls posts
241
+ curl -X GET "http://localhost:3000/db/a1b2c3d4-my-app/posts" -H "Authorization: Bearer <token>"
242
+ ```
243
+
244
+ ## Configuration File
245
+
246
+ The config file at `~/.config/vtriv/config.json`:
247
+
248
+ ```json
249
+ {
250
+ "baseUrl": "http://localhost:3000",
251
+ "accountKey": "vtriv_ak_...",
252
+ "accountSlug": "a1b2c3d4",
253
+ "default": "my-app",
254
+ "profiles": {
255
+ "my-app": {
256
+ "apiKey": "vtriv_sk_..."
257
+ },
258
+ "staging": {
259
+ "apiKey": "vtriv_sk_..."
260
+ }
261
+ }
262
+ }
263
+ ```
264
+
265
+ ## Migration from Old Config
59
266
 
60
- ## Options
267
+ If you have an old `~/.vtrivrc` file, you'll need to:
268
+ 1. Run `vtriv config` with your account key
269
+ 2. Run `vtriv init <name>` for each project
61
270
 
62
- - `--json` - Output raw JSON for scripts/agents
63
- - `--profile <name>` - Use a specific profile
64
- - `--debug` - Show HTTP curl equivalents
271
+ The old config format is not compatible with the new account-based system.
65
272
 
66
- ## Documentation
273
+ ## License
67
274
 
68
- See [~/grit/skills/vtriv/cli.md](../../grit/skills/vtriv/cli.md) for full documentation.
275
+ Private - Part of vtriv meta-project