Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .changeset/rename-packages.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
"@kidd-cli/core": patch
"@kidd-cli/cli": patch
"@kidd-cli/bundler": patch
"@kidd-cli/config": patch
"@kidd-cli/utils": patch
'@kidd-cli/core': patch
'@kidd-cli/cli': patch
'@kidd-cli/bundler': patch
'@kidd-cli/config': patch
'@kidd-cli/utils': patch
---

Rename `kidd` to `@kidd-cli/core` and `kidd-cli` to `@kidd-cli/cli` to comply with npm's package naming policy. All imports, docs, and references updated.
5 changes: 5 additions & 0 deletions .changeset/scaffold-kidd-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kidd-cli/cli': patch
---

scaffold `kidd.config.ts` instead of `tsdown.config.ts` in init templates
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#873e99"
}
}
4 changes: 2 additions & 2 deletions contributing/concepts/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ packages/
└── cli/ # CLI entrypoint and DX tooling (init, dev, build, compile)
```

| Package | Purpose |
| ----------- | ------------------------------------------------------------- |
| Package | Purpose |
| ---------------- | ------------------------------------------------------------- |
| `@kidd-cli/core` | Core framework: `cli()`, `command()`, `middleware()`, context |
| `@kidd-cli/cli` | DX companion CLI: scaffolding, dev mode, build, compile |

Expand Down
14 changes: 7 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ flowchart LR

## Packages

| Package | Purpose | Runtime |
| ---------------------------------------- | -------------------------------------------------------- | -------- |
| [`@kidd-cli/core`](./reference/kidd.md) | Core CLI framework (commands, middleware, config, store) | CLI |
| [`@kidd-cli/cli`](./reference/cli.md) | DX companion CLI (init, build, doctor, add) | CLI |
| `@kidd-cli/config` | Configuration loading, validation, and schema (internal) | Library |
| `@kidd-cli/utils` | Shared functional utilities (internal) | Library |
| `@kidd-cli/bundler` | tsdown bundling and binary compilation (internal) | CLI |
| Package | Purpose | Runtime |
| --------------------------------------- | -------------------------------------------------------- | ------- |
| [`@kidd-cli/core`](./reference/kidd.md) | Core CLI framework (commands, middleware, config, store) | CLI |
| [`@kidd-cli/cli`](./reference/cli.md) | DX companion CLI (init, build, doctor, add) | CLI |
| `@kidd-cli/config` | Configuration loading, validation, and schema (internal) | Library |
| `@kidd-cli/utils` | Shared functional utilities (internal) | Library |
| `@kidd-cli/bundler` | tsdown bundling and binary compilation (internal) | CLI |

## Concepts

Expand Down
82 changes: 41 additions & 41 deletions docs/concepts/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ This split allows commands to work without auth when no credential is found, and

All credentials use a discriminated union on the `type` field:

| Type | Interface | HTTP Header |
| --------- | ------------------- | --------------------------------------- |
| `bearer` | `BearerCredential` | `Authorization: Bearer <token>` |
| `basic` | `BasicCredential` | `Authorization: Basic base64(user:pass)` |
| `api-key` | `ApiKeyCredential` | `<headerName>: <key>` |
| `custom` | `CustomCredential` | Arbitrary `headers` record |
| Type | Interface | HTTP Header |
| --------- | ------------------ | ---------------------------------------- |
| `bearer` | `BearerCredential` | `Authorization: Bearer <token>` |
| `basic` | `BasicCredential` | `Authorization: Basic base64(user:pass)` |
| `api-key` | `ApiKeyCredential` | `<headerName>: <key>` |
| `custom` | `CustomCredential` | Arbitrary `headers` record |

```ts
interface BearerCredential {
Expand Down Expand Up @@ -54,10 +54,10 @@ interface CustomCredential {

Credentials are persisted as JSON files using kidd's file store system.

| Location | Path | Resolution order |
| -------- | ------------------------------- | ---------------- |
| Local | `./<cli-name>/auth.json` | Checked first |
| Global | `~/<cli-name>/auth.json` | Checked second |
| Location | Path | Resolution order |
| -------- | ------------------------ | ---------------- |
| Local | `./<cli-name>/auth.json` | Checked first |
| Global | `~/<cli-name>/auth.json` | Checked second |

The file contains the raw credential object:

Expand All @@ -80,9 +80,9 @@ Reads a bearer token from `process.env`.
{ source: 'env', tokenVar: 'GITHUB_TOKEN' }
```

| Option | Type | Default | Description |
| ---------- | -------- | --------------------- | ------------------------------- |
| `tokenVar` | `string` | `<CLI_NAME>_TOKEN` | Environment variable name |
| Option | Type | Default | Description |
| ---------- | -------- | ------------------ | ------------------------- |
| `tokenVar` | `string` | `<CLI_NAME>_TOKEN` | Environment variable name |

The default variable name is derived from the CLI name: `my-app` becomes `MY_APP_TOKEN`.

Expand All @@ -94,10 +94,10 @@ Reads a bearer token from a `.env` file without mutating `process.env`.
{ source: 'dotenv', tokenVar: 'API_TOKEN', path: './.env.local' }
```

| Option | Type | Default | Description |
| ---------- | -------- | ------------------ | ------------------------------- |
| `tokenVar` | `string` | `<CLI_NAME>_TOKEN` | Variable name within the file |
| `path` | `string` | `$CWD/.env` | Path to the dotenv file |
| Option | Type | Default | Description |
| ---------- | -------- | ------------------ | ----------------------------- |
| `tokenVar` | `string` | `<CLI_NAME>_TOKEN` | Variable name within the file |
| `path` | `string` | `$CWD/.env` | Path to the dotenv file |

### `file` -- JSON File

Expand All @@ -107,10 +107,10 @@ Reads any credential type from a JSON file on disk via kidd's store system.
{ source: 'file', filename: 'auth.json', dirName: '.my-app' }
```

| Option | Type | Default | Description |
| ---------- | -------- | ----------------- | --------------------------------- |
| `filename` | `string` | `'auth.json'` | Filename within the store dir |
| `dirName` | `string` | `.<cli-name>` | Store directory name |
| Option | Type | Default | Description |
| ---------- | -------- | ------------- | ----------------------------- |
| `filename` | `string` | `'auth.json'` | Filename within the store dir |
| `dirName` | `string` | `.<cli-name>` | Store directory name |

### `oauth` -- OAuth Browser Flow

Expand All @@ -120,12 +120,12 @@ Opens the user's browser to an auth URL, starts a local HTTP server to receive t
{ source: 'oauth', authUrl: 'https://example.com/auth', port: 0, timeout: 120_000 }
```

| Option | Type | Default | Description |
| -------------- | -------- | -------------- | -------------------------------------------- |
| `authUrl` | `string` | -- | Authorization URL (required) |
| `port` | `number` | `0` (random) | Local server port |
| `callbackPath` | `string` | `'/callback'` | Callback endpoint path |
| `timeout` | `number` | `120_000` | Timeout in milliseconds |
| Option | Type | Default | Description |
| -------------- | -------- | ------------- | ---------------------------- |
| `authUrl` | `string` | -- | Authorization URL (required) |
| `port` | `number` | `0` (random) | Local server port |
| `callbackPath` | `string` | `'/callback'` | Callback endpoint path |
| `timeout` | `number` | `120_000` | Timeout in milliseconds |

The auth URL receives a `callback_url` query parameter pointing to the local server. The OAuth provider must POST a JSON body `{ "token": "<value>" }` to this URL on success.

Expand All @@ -137,9 +137,9 @@ Prompts the user for a token via a masked password input.
{ source: 'prompt', message: 'Enter your API token:' }
```

| Option | Type | Default | Description |
| --------- | -------- | ------------------------ | --------------------- |
| `message` | `string` | `'Enter your API key'` | Prompt message |
| Option | Type | Default | Description |
| --------- | -------- | ---------------------- | -------------- |
| `message` | `string` | `'Enter your API key'` | Prompt message |

### `custom` -- User-Provided Function

Expand All @@ -155,19 +155,19 @@ Calls a user-supplied function that returns a credential or null.
}
```

| Option | Type | Description |
| ---------- | -------------------------------------------------------- | ------------------- |
| Option | Type | Description |
| ---------- | ----------------------------------------------------------------- | ----------------- |
| `resolver` | `() => Promise<AuthCredential \| null> \| AuthCredential \| null` | Resolver function |

## AuthContext

The auth middleware decorates `ctx.auth` with an `AuthContext`:

| Property | Type | Description |
| ----------------- | --------------------------------------------- | ---------------------------------------------- |
| `credential()` | `AuthCredential \| null` | Passively resolved credential (file, env) |
| `authenticated()` | `boolean` | Whether a passive credential exists |
| `authenticate()` | `AsyncResult<AuthCredential, LoginError>` | Run interactive resolvers, persist, and return |
| Property | Type | Description |
| ----------------- | ----------------------------------------- | ---------------------------------------------- |
| `credential()` | `AuthCredential \| null` | Passively resolved credential (file, env) |
| `authenticated()` | `boolean` | Whether a passive credential exists |
| `authenticate()` | `AsyncResult<AuthCredential, LoginError>` | Run interactive resolvers, persist, and return |

### `ctx.auth.authenticate()`

Expand All @@ -180,10 +180,10 @@ if (error) {
}
```

| LoginError `type` | Description |
| ------------------- | ---------------------------------------------- |
| `'no_credential'` | No resolver produced a credential |
| `'save_failed'` | Credential resolved but failed to persist |
| LoginError `type` | Description |
| ----------------- | ----------------------------------------- |
| `'no_credential'` | No resolver produced a credential |
| `'save_failed'` | Credential resolved but failed to persist |

## HTTP Integration

Expand Down
40 changes: 20 additions & 20 deletions docs/concepts/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ The configuration system for kidd CLIs. Supports multiple file formats, automati

## Supported Formats

| Format | Extensions | Notes |
| ------ | ------------------ | ----------------------- |
| JSONC | `.jsonc` | JSON with comments |
| JSON | `.json` | Standard JSON |
| YAML | `.yaml` | YAML format |
| Format | Extensions | Notes |
| ------ | ---------- | ------------------ |
| JSONC | `.jsonc` | JSON with comments |
| JSON | `.json` | Standard JSON |
| YAML | `.yaml` | YAML format |

Config files are named `.<name>.jsonc`, `.<name>.json`, or `.<name>.yaml`, where `<name>` is the CLI name passed to `cli({ name })` or `createConfigClient({ name })`.

Expand Down Expand Up @@ -51,10 +51,10 @@ cli({
})
```

| Field | Type | Default | Description |
| -------- | --------- | ------------------- | -------------------------------------------------------- |
| Field | Type | Default | Description |
| -------- | --------- | ------------------- | ------------------------------------------------------------------- |
| `schema` | `ZodType` | -- | Zod schema to validate the loaded config. Infers `ctx.config` type. |
| `name` | `string` | Derived from `name` | Override the config file name for file discovery |
| `name` | `string` | Derived from `name` | Override the config file name for file discovery |

## Config Client

Expand All @@ -72,11 +72,11 @@ const config = createConfigClient({

### `ConfigOptions`

| Field | Type | Description |
| ------------- | ---------- | ---------------------------------------------- |
| Field | Type | Description |
| ------------- | ---------- | -------------------------------------------------------------- |
| `name` | `string` | Config file name (e.g. `'my-app'` resolves to `.my-app.jsonc`) |
| `schema` | `ZodType` | Zod schema for validation |
| `searchPaths` | `string[]` | Additional directories to search |
| `schema` | `ZodType` | Zod schema for validation |
| `searchPaths` | `string[]` | Additional directories to search |

### `config.find(cwd?)`

Expand All @@ -96,11 +96,11 @@ Load and validate a config file. Returns a Result tuple.
const result = await config.load()
```

| Return value | Meaning |
| ---------------------------------- | ------------------------------------ |
| `[error, null]` | Load or validation failed |
| Return value | Meaning |
| -------------------------------------- | --------------------------------- |
| `[error, null]` | Load or validation failed |
| `[null, { config, filePath, format }]` | Successfully loaded and validated |
| `[null, null]` | No config file found |
| `[null, null]` | No config file found |

### `config.write(data, options?)`

Expand All @@ -113,11 +113,11 @@ const [error, result] = await config.write(
)
```

| Option | Type | Description |
| ---------- | -------------- | ---------------------------------------- |
| `dir` | `string` | Target directory (defaults to cwd) |
| Option | Type | Description |
| ---------- | -------------- | --------------------------------------------- |
| `dir` | `string` | Target directory (defaults to cwd) |
| `format` | `ConfigFormat` | Output format (`'jsonc'`, `'json'`, `'yaml'`) |
| `filePath` | `string` | Explicit output path (overrides `dir`) |
| `filePath` | `string` | Explicit output path (overrides `dir`) |

## Discovery Order

Expand Down
Loading