@griffin-app/griffin-cli 1.0.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.
Files changed (2) hide show
  1. package/README.md +509 -0
  2. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,509 @@
1
+ # Griffin CLI
2
+
3
+ Command-line interface for managing API monitoring tests as code.
4
+
5
+ ## Overview
6
+
7
+ Griffin CLI enables monitoring-as-code with support for both local test execution and hub-based orchestration. It provides a declarative workflow:
8
+
9
+ 1. Write test plans in TypeScript/JavaScript
10
+ 2. Run tests locally against configured targets
11
+ 3. Preview changes with `griffin hub plan`
12
+ 4. Apply changes to hub with `griffin hub apply`
13
+ 5. Monitor execution with `griffin hub runs`
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install -g griffin-cli
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### 1. Initialize
24
+
25
+ ```bash
26
+ griffin init
27
+ ```
28
+
29
+ This creates `.griffin/state.json` which tracks:
30
+
31
+ - Project ID (auto-detected from package.json or directory name)
32
+ - Environment configurations with their targets
33
+ - Synced plan state
34
+ - Hub connection settings (optional)
35
+
36
+ Override project ID with `--project <name>`.
37
+
38
+ ### 2. Configure Targets
39
+
40
+ Add targets to your local environment:
41
+
42
+ ```bash
43
+ griffin local config add-target --env local --key api --url http://localhost:3000
44
+ ```
45
+
46
+ View configured environments:
47
+
48
+ ```bash
49
+ griffin local config list
50
+ ```
51
+
52
+ ### 3. Create Test Plans
53
+
54
+ Create test files in `__griffin__/` directories. These files export test plans that can be run locally or synced to the hub.
55
+
56
+ ### 4. Run Tests Locally
57
+
58
+ ```bash
59
+ griffin local run --env local
60
+ ```
61
+
62
+ Executes tests locally against configured targets.
63
+
64
+ ### 5. Connect to Hub (Optional)
65
+
66
+ ```bash
67
+ griffin hub connect --url https://hub.example.com --token <token>
68
+ ```
69
+
70
+ ### 6. Preview Hub Changes
71
+
72
+ ```bash
73
+ griffin hub plan
74
+ ```
75
+
76
+ Shows what will be created, updated, or deleted on the hub.
77
+
78
+ ### 7. Apply to Hub
79
+
80
+ ```bash
81
+ griffin hub apply
82
+ ```
83
+
84
+ Syncs plans to the hub.
85
+
86
+ ### 8. Trigger Hub Run
87
+
88
+ ```bash
89
+ griffin hub run --plan <name> --env production
90
+ ```
91
+
92
+ Triggers a plan execution on the hub.
93
+
94
+ ## Commands
95
+
96
+ Commands are organized into three groups:
97
+
98
+ - **Top-level**: Project initialization and utilities
99
+ - **local**: Local test execution and configuration
100
+ - **hub**: Hub operations (plan sync, remote execution)
101
+
102
+ ### Top-Level Commands
103
+
104
+ #### `griffin init`
105
+
106
+ Initialize Griffin in the current directory.
107
+
108
+ **Options:**
109
+
110
+ - `--project <name>` - Project ID (defaults to package.json name or directory name)
111
+
112
+ **Example:**
113
+
114
+ ```bash
115
+ griffin init
116
+ griffin init --project my-service
117
+ ```
118
+
119
+ #### `griffin validate`
120
+
121
+ Validate test plan files without syncing.
122
+
123
+ **Example:**
124
+
125
+ ```bash
126
+ griffin validate
127
+ ```
128
+
129
+ #### `griffin generate-key`
130
+
131
+ Generate a cryptographically secure API key for authentication.
132
+
133
+ **Example:**
134
+
135
+ ```bash
136
+ griffin generate-key
137
+ ```
138
+
139
+ ### Local Commands
140
+
141
+ #### `griffin local run`
142
+
143
+ Run tests locally against configured targets.
144
+
145
+ **Options:**
146
+
147
+ - `--env <name>` - Environment to run against (uses default if not specified)
148
+
149
+ **Example:**
150
+
151
+ ```bash
152
+ griffin local run
153
+ griffin local run --env staging
154
+ ```
155
+
156
+ #### `griffin local config list`
157
+
158
+ List all local environments and their targets.
159
+
160
+ **Example:**
161
+
162
+ ```bash
163
+ griffin local config list
164
+ ```
165
+
166
+ #### `griffin local config add-target`
167
+
168
+ Add a target to a local environment.
169
+
170
+ **Options:**
171
+
172
+ - `--env <name>` - Environment name (required)
173
+ - `--key <key>` - Target key (required)
174
+ - `--url <url>` - Target URL (required)
175
+
176
+ **Example:**
177
+
178
+ ```bash
179
+ griffin local config add-target --env local --key api --url http://localhost:3000
180
+ griffin local config add-target --env staging --key billing --url http://localhost:3001
181
+ ```
182
+
183
+ #### `griffin local config remove-target`
184
+
185
+ Remove a target from a local environment.
186
+
187
+ **Options:**
188
+
189
+ - `--env <name>` - Environment name (required)
190
+ - `--key <key>` - Target key (required)
191
+
192
+ **Example:**
193
+
194
+ ```bash
195
+ griffin local config remove-target --env local --key api
196
+ ```
197
+
198
+ #### `griffin local config set-default-env`
199
+
200
+ Set the default environment for local runs.
201
+
202
+ **Options:**
203
+
204
+ - `--env <name>` - Environment name (required)
205
+
206
+ **Example:**
207
+
208
+ ```bash
209
+ griffin local config set-default-env --env local
210
+ ```
211
+
212
+ ### Hub Commands
213
+
214
+ #### `griffin hub connect`
215
+
216
+ Configure hub connection settings.
217
+
218
+ **Options:**
219
+
220
+ - `--url <url>` - Hub URL (required)
221
+ - `--token <token>` - API authentication token
222
+
223
+ **Example:**
224
+
225
+ ```bash
226
+ griffin hub connect --url https://hub.example.com --token abc123
227
+ ```
228
+
229
+ #### `griffin hub status`
230
+
231
+ Show hub connection status.
232
+
233
+ **Example:**
234
+
235
+ ```bash
236
+ griffin hub status
237
+ ```
238
+
239
+ #### `griffin hub runs`
240
+
241
+ Show recent runs from the hub.
242
+
243
+ **Options:**
244
+
245
+ - `--plan <name>` - Filter by plan name
246
+ - `--limit <number>` - Number of runs to show (default: 10)
247
+
248
+ **Example:**
249
+
250
+ ```bash
251
+ griffin hub runs
252
+ griffin hub runs --plan health-check --limit 5
253
+ ```
254
+
255
+ #### `griffin hub plan`
256
+
257
+ Show what changes would be applied to the hub.
258
+
259
+ **Options:**
260
+
261
+ - `--env <name>` - Environment to plan for (uses default if not specified)
262
+ - `--json` - Output in JSON format
263
+
264
+ **Example:**
265
+
266
+ ```bash
267
+ griffin hub plan
268
+ griffin hub plan --env production --json
269
+ ```
270
+
271
+ **Exit codes:**
272
+
273
+ - `0` - No changes
274
+ - `1` - Error
275
+ - `2` - Changes pending
276
+
277
+ #### `griffin hub apply`
278
+
279
+ Apply changes to the hub.
280
+
281
+ **Options:**
282
+
283
+ - `--env <name>` - Environment to apply to (uses default if not specified)
284
+ - `--auto-approve` - Skip confirmation prompt
285
+ - `--dry-run` - Show what would be done without making changes
286
+
287
+ **Example:**
288
+
289
+ ```bash
290
+ griffin hub apply
291
+ griffin hub apply --env production --auto-approve
292
+ griffin hub apply --dry-run
293
+ ```
294
+
295
+ #### `griffin hub run`
296
+
297
+ Trigger a plan run on the hub.
298
+
299
+ **Options:**
300
+
301
+ - `--plan <name>` - Plan name to run (required)
302
+ - `--env <name>` - Target environment (required)
303
+ - `--wait` - Wait for run to complete
304
+
305
+ **Example:**
306
+
307
+ ```bash
308
+ griffin hub run --plan health-check --env production
309
+ griffin hub run --plan health-check --env staging --wait
310
+ ```
311
+
312
+ #### `griffin hub config list`
313
+
314
+ List all hub target configurations.
315
+
316
+ **Options:**
317
+
318
+ - `--org <id>` - Filter by organization ID
319
+ - `--env <name>` - Filter by environment name
320
+
321
+ **Example:**
322
+
323
+ ```bash
324
+ griffin hub config list
325
+ griffin hub config list --org acme --env production
326
+ ```
327
+
328
+ #### `griffin hub config add-target`
329
+
330
+ Add a target to hub configuration.
331
+
332
+ **Options:**
333
+
334
+ - `--org <id>` - Organization ID (required)
335
+ - `--env <name>` - Environment name (required)
336
+ - `--key <key>` - Target key (required)
337
+ - `--url <url>` - Target URL (required)
338
+
339
+ **Example:**
340
+
341
+ ```bash
342
+ griffin hub config add-target --org acme --env production --key api --url https://api.example.com
343
+ ```
344
+
345
+ #### `griffin hub config remove-target`
346
+
347
+ Remove a target from hub configuration.
348
+
349
+ **Options:**
350
+
351
+ - `--org <id>` - Organization ID (required)
352
+ - `--env <name>` - Environment name (required)
353
+ - `--key <key>` - Target key (required)
354
+
355
+ **Example:**
356
+
357
+ ```bash
358
+ griffin hub config remove-target --org acme --env production --key api
359
+ ```
360
+
361
+ ## Configuration
362
+
363
+ ### Environment Variables
364
+
365
+ - `GRIFFIN_ENV` - Default environment to use for commands
366
+
367
+ ### State File
368
+
369
+ Griffin stores configuration in `.griffin/state.json`:
370
+
371
+ ```json
372
+ {
373
+ "stateVersion": 3,
374
+ "projectId": "my-project",
375
+ "environments": {
376
+ "local": {
377
+ "targets": {
378
+ "api": "http://localhost:3000",
379
+ "billing": "http://localhost:3001"
380
+ }
381
+ }
382
+ },
383
+ "defaultEnvironment": "local",
384
+ "runner": {
385
+ "baseUrl": "https://hub.example.com",
386
+ "apiToken": "..."
387
+ },
388
+ "discovery": {
389
+ "pattern": "**/__griffin__/*.{ts,js}",
390
+ "ignore": ["node_modules/**", "dist/**"]
391
+ },
392
+ "plans": {
393
+ "local": []
394
+ }
395
+ }
396
+ ```
397
+
398
+ **Important:** Add `.griffin/` to `.gitignore` as it contains local state and potentially sensitive tokens.
399
+
400
+ ## Environments and Targets
401
+
402
+ Griffin uses environments to organize target configurations. Each environment contains multiple named targets (key-value pairs of target keys to URLs).
403
+
404
+ **Local environments:**
405
+
406
+ - Defined in `.griffin/state.json`
407
+ - Used for local test execution
408
+ - Managed via `griffin local config` commands
409
+
410
+ **Example workflow:**
411
+
412
+ ```bash
413
+ # Create local environment with targets
414
+ griffin local config add-target --env local --key api --url http://localhost:3000
415
+ griffin local config add-target --env local --key billing --url http://localhost:3001
416
+
417
+ # Set default environment
418
+ griffin local config set-default-env --env local
419
+
420
+ # Run tests using default environment
421
+ griffin local run
422
+ ```
423
+
424
+ ## Test Plan Discovery
425
+
426
+ By default, Griffin discovers test plans from files in `__griffin__/` directories matching `**/__griffin__/*.{ts,js}`.
427
+
428
+ Test files should be TypeScript or JavaScript files that export test plan objects.
429
+
430
+ ## Diff Rules
431
+
432
+ Griffin computes changes using:
433
+
434
+ - **CREATE**: Plan exists locally but not in state
435
+ - **UPDATE**: Plan exists in both, but hash differs
436
+ - **DELETE**: Plan exists in state but not locally
437
+ - **NOOP**: Plan exists in both with same hash
438
+
439
+ Change detection uses a SHA-256 hash of the normalized plan payload.
440
+
441
+ ## Hub API Compatibility
442
+
443
+ Griffin CLI is compatible with Griffin Hub API v1.
444
+
445
+ Required endpoints:
446
+
447
+ - `POST /plan` - Create/update plan
448
+ - `GET /plan` - List plans
449
+ - `GET /runs` - List runs
450
+ - `GET /runs/:id` - Get run details
451
+ - `POST /runs/trigger/:id` - Trigger run
452
+ - `GET /config` - List configurations
453
+ - `PUT /config/:org/:env/targets/:key` - Set target
454
+ - `DELETE /config/:org/:env/targets/:key` - Delete target
455
+
456
+ ## Development
457
+
458
+ ```bash
459
+ # Install dependencies
460
+ npm install
461
+
462
+ # Build
463
+ npm run build
464
+
465
+ # Run in development
466
+ npm run dev -- <command>
467
+
468
+ # Example
469
+ npm run dev -- validate
470
+ ```
471
+
472
+ ## Architecture
473
+
474
+ ```
475
+ griffin-cli/
476
+ ├── src/
477
+ │ ├── commands/ # Command implementations
478
+ │ │ ├── local/ # Local execution commands
479
+ │ │ │ ├── run.ts
480
+ │ │ │ └── config.ts
481
+ │ │ ├── hub/ # Hub operation commands
482
+ │ │ │ ├── connect.ts
483
+ │ │ │ ├── status.ts
484
+ │ │ │ ├── runs.ts
485
+ │ │ │ ├── plan.ts
486
+ │ │ │ ├── apply.ts
487
+ │ │ │ ├── run.ts
488
+ │ │ │ └── config.ts
489
+ │ │ ├── init.ts
490
+ │ │ ├── validate.ts
491
+ │ │ └── generate-key.ts
492
+ │ ├── core/ # Core logic
493
+ │ │ ├── sdk.ts # Hub SDK client
494
+ │ │ ├── apply.ts # Apply engine
495
+ │ │ ├── diff.ts # Diff computation
496
+ │ │ ├── discovery.ts # Plan discovery
497
+ │ │ ├── state.ts # State management
498
+ │ │ └── project.ts # Project detection
499
+ │ ├── schemas/ # Type definitions
500
+ │ │ ├── payload.ts # Plan payload schemas
501
+ │ │ └── state.ts # State file schemas
502
+ │ ├── cli.ts # CLI entry point
503
+ │ └── index.ts # Public API exports
504
+ └── package.json
505
+ ```
506
+
507
+ ## License
508
+
509
+ MIT
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@griffin-app/griffin-cli",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool for running and managing griffin API tests",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "griffin": "./dist/cli.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsx src/cli.ts",
13
+ "start": "node dist/cli.js",
14
+ "test": "vitest run"
15
+ },
16
+ "keywords": [
17
+ "griffin",
18
+ "api",
19
+ "testing",
20
+ "cli",
21
+ "monitoring"
22
+ ],
23
+ "author": "",
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "commander": "^12.1.0",
27
+ "glob": "^11.0.0",
28
+ "griffin": "file:../griffin-ts",
29
+ "griffin-hub-sdk": "file:../griffin-hub-sdk",
30
+ "griffin-plan-executor": "file:../griffin-plan-executor",
31
+ "object-hash": "^3.0.0",
32
+ "typebox": "^1.0.78"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^22.10.5",
36
+ "@types/object-hash": "^3.0.6",
37
+ "tsx": "^4.19.2",
38
+ "typescript": "^5.7.2",
39
+ "vitest": "^4.0.17"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "README.md"
44
+ ]
45
+ }