Commit 7e6329b
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | | - | |
| 122 | + | |
| 123 | + | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| |||
0 commit comments