Skip to content

Commit 7e6329b

Browse files
hiroTamadamasnwilliamsclaude
authored
feat(cli): add projects support with --project flag and name resolution (#147)
## Summary - Adds a global `--project` persistent flag (and `KERNEL_PROJECT_ID` env var) that injects the `X-Kernel-Project-Id` header to scope all API requests to a specific project - The flag accepts **either a project ID or a project name** — names are resolved via the projects list endpoint with case-insensitive matching - Adds `kernel projects` subcommands: `list`, `create`, `get`, `delete`, `get-limits`, `set-limits` - Upgrades `kernel-go-sdk` to v0.48.0 for project endpoint support (also fixes `ProxyService.Check` signature change) ## How it works When `--project` is provided: 1. If the value looks like a cuid2 ID (24 lowercase alphanumeric chars), it's used directly as the project ID header 2. Otherwise, the CLI authenticates first, calls `GET /projects` to list all projects, finds a case-insensitive name match, and injects the resolved ID 3. Clear errors for: no match found, multiple matches (ambiguous name) ## Test plan Tested against staging with a project-scoped API key: - [x] `--project "cli-test-project"` (by name) — resolves correctly - [x] `--project "CLI-TEST-PROJECT"` (case-insensitive) — resolves correctly - [x] `--project "g9vcya6unur84k70n0u8s9p9"` (by ID) — works directly - [x] `--project "nonexistent-project"` — clear error message - [x] `KERNEL_PROJECT_ID="cli-test-project"` env var with name — resolves correctly - [x] No `--project` with scoped API key — auto-scopes via server middleware - [x] `kernel projects list/create/get/delete/get-limits/set-limits` — all functional Made with [Cursor](https://cursor.com) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Introduces a new global request-scoping mechanism via the `X-Kernel-Project-Id` header and adds project CRUD/limits commands, which can affect all API calls when enabled. Also bumps the Kernel SDK and adjusts proxy health-check calls to match the new SDK signature. > > **Overview** > Adds first-class **project management** to the CLI via a new `projects` command group (`list`, `create`, `get`, `delete`, plus `limits get/set` with optional `--output json`) and validation for limit updates (rejects negative values, treats unset vs set via `Int64Flag`). > > Introduces a global `--project` flag (or `KERNEL_PROJECT` env var) that injects `X-Kernel-Project-Id` into all authenticated requests, plus project *name → ID* resolution via paginated project listing with clear errors for no/ambiguous matches. > > Updates CUID2 validation to require a leading letter, upgrades `github.com/kernel/kernel-go-sdk` to `v0.48.0`, and adapts proxy health-check wiring/tests to the SDK’s updated `Check` signature. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 748bef4. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Mason Williams <43387599+masnwilliams@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 202394c commit 7e6329b

11 files changed

Lines changed: 727 additions & 13 deletions

File tree

cmd/browsers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ type Int64Flag struct {
119119
Value int64
120120
}
121121

122-
// Regular expression to validate CUID2 identifiers (24 lowercase alphanumeric characters).
123-
var cuidRegex = regexp.MustCompile(`^[a-z0-9]{24}$`)
122+
// Regular expression to validate CUID2 identifiers (starts with a letter, 24 lowercase alphanumeric characters).
123+
var cuidRegex = regexp.MustCompile(`^[a-z][a-z0-9]{23}$`)
124124

125125
// getAvailableViewports returns the list of supported viewport configurations.
126126
func getAvailableViewports() []string {

0 commit comments

Comments
 (0)