@kizenapps/cli 1.15.0 → 1.16.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.
- package/README.md +122 -24
- package/dist/index.js +192 -76
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,13 +47,13 @@ appbuilder create
|
|
|
47
47
|
|
|
48
48
|
The wizard first asks where the plugin should live (the current directory, or a new sub-directory named after the API name), then collects five fields:
|
|
49
49
|
|
|
50
|
-
| Field | Required | Notes
|
|
51
|
-
| ------------- | -------- |
|
|
52
|
-
| Name | yes | Human-readable plugin name.
|
|
53
|
-
| API name | yes | Defaults to a snake_cased version of the name. Hyphens are rejected by the platform.
|
|
54
|
-
| External link | no | Documentation or marketing URL for the plugin.
|
|
55
|
-
| Description | no\* | See the note below.
|
|
56
|
-
| Business ID | no\* | Prefilled from your
|
|
50
|
+
| Field | Required | Notes |
|
|
51
|
+
| ------------- | -------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
52
|
+
| Name | yes | Human-readable plugin name. |
|
|
53
|
+
| API name | yes | Defaults to a snake_cased version of the name. Hyphens are rejected by the platform. |
|
|
54
|
+
| External link | no | Documentation or marketing URL for the plugin. |
|
|
55
|
+
| Description | no\* | See the note below. |
|
|
56
|
+
| Business ID | no\* | Prefilled from your `appbuilder login` session's business when you're signed in, else from your stored API-key credentials. |
|
|
57
57
|
|
|
58
58
|
> **Fill in Description and Business ID.** Both are labelled optional in the wizard, but `create` writes them into `kizen.json` as empty strings and the bundler rejects an empty `description` or `developer_business_id` — so a plugin created with those fields skipped fails `appbuilder build` until you edit `kizen.json` by hand. This is tracked internally (KZN-17594); until that fix lands, treat both as required.
|
|
59
59
|
|
|
@@ -63,6 +63,8 @@ It then asks which artifacts to scaffold — Floating frame, Block, Data adornme
|
|
|
63
63
|
|
|
64
64
|
### 2. Set up credentials
|
|
65
65
|
|
|
66
|
+
> **API-key credentials are deprecated for block commands.** `appbuilder block push` and `appbuilder block targets` use your [`appbuilder login`](#appbuilder-login-logout-whoami-and-auth-header) session by default. `appbuilder dev` and `appbuilder encrypt` still use API keys: `encrypt` until Plugin Wizard accepts sign-in sessions, and OAuth for `dev` is planned. The rest of this section applies to them.
|
|
67
|
+
|
|
66
68
|
`appbuilder dev` talks to a real Kizen environment on your behalf, so it needs four things:
|
|
67
69
|
|
|
68
70
|
| Field | Where it comes from |
|
|
@@ -104,7 +106,7 @@ Writes `.kizenapp/bundle.json` — the same artifact `dev` serves — after runn
|
|
|
104
106
|
|
|
105
107
|
### `appbuilder create`
|
|
106
108
|
|
|
107
|
-
Scaffolds a new Kizen plugin project. Interactive by default; passing any flag other than `--include-lib` switches it to a non-interactive run, including `--artifacts` to choose the artifact templates up front (`appbuilder create --help` lists them all). Pass `--include-lib` to also write the Kizen data helper library to `src/lib/kizenData.js`; without it, no library is written. See [Quickstart](#1-scaffold-a-plugin) for the fields it collects, the artifact picker, and everything it writes.
|
|
109
|
+
Scaffolds a new Kizen plugin project. Interactive by default; passing any flag other than `--include-lib` switches it to a non-interactive run, including `--artifacts` to choose the artifact templates up front (`appbuilder create --help` lists them all). Pass `--include-lib` to also write the Kizen data helper library to `src/lib/kizenData.js`; without it, no library is written. `--business-id` and `--environment` default from your `appbuilder login` session: the environment is `-e`, else the only environment you're signed in to, else `go`, and the business is that environment's session business. Only when you're signed out entirely does it fall back to `~/.kizenappbuilder/credentials.json`. See [Quickstart](#1-scaffold-a-plugin) for the fields it collects, the artifact picker, and everything it writes.
|
|
108
110
|
|
|
109
111
|
The scaffold also includes `.github/copilot-instructions.md`, two path-scoped instruction files under `.github/instructions/`, and `.github/workflows/copilot-code-review.yml`. That workflow fetches the Kizen plugin docs from `kizen/app-engine` into `.copilot-docs/` before Copilot code review runs, so reviews cite the current documentation instead of rules copied into the plugin repo. It only takes effect once it is on the repository's default branch, and `.copilot-docs/` is gitignored. Plugins scaffolded before this setup existed can pick it up with `appbuilder setup-copilot`.
|
|
110
112
|
|
|
@@ -123,13 +125,18 @@ As with `create`, the workflow only runs once it has reached the repository's de
|
|
|
123
125
|
Installs or refreshes the Claude Code skill for building custom blocks (`.claude/skills/kizen-custom-block/SKILL.md`) in the plugin in the current directory. `appbuilder create` writes the skill once; run `setup-claude` in an existing plugin to add it, or after upgrading the CLI to pick up the bundled version.
|
|
124
126
|
|
|
125
127
|
```sh
|
|
126
|
-
appbuilder setup-claude [--dry-run] [--include-lib]
|
|
128
|
+
appbuilder setup-claude [--dry-run] [--include-lib] [--mcp [--env <env>] [--force]]
|
|
127
129
|
```
|
|
128
130
|
|
|
129
131
|
| Flag | Default | Purpose |
|
|
130
132
|
| --------------- | ------- | ------------------------------------------------------------ |
|
|
131
133
|
| `--dry-run` | off | Report what would change without writing files. |
|
|
132
134
|
| `--include-lib` | off | Also install the Kizen data helper library (`kizenData.js`). |
|
|
135
|
+
| `--mcp` | off | Also register the Kizen MCP server in Claude Code. |
|
|
136
|
+
| `--env <env>` | `go` | Environment of the MCP server to register. |
|
|
137
|
+
| `--force` | off | Replace an existing registration of that server. |
|
|
138
|
+
|
|
139
|
+
`--env` and `--force` only apply with `--mcp`; see [Using the session from Claude Code](#using-the-session-from-claude-code-mcp).
|
|
133
140
|
|
|
134
141
|
It also installs the skill's design guide (`.claude/skills/kizen-custom-block/design.md`), which tells the agent how to make blocks match native dashlets. With `--include-lib`, it installs the Kizen data helper library that block scripts import to read records and apply the dashboard's date and team filters. The library goes under the `entry` directory from `kizen.json` (`<entry>/lib/kizenData.js`, one per entry in a multi-plugin `kizen.json`), and under `src/` when `kizen.json` has no usable `entry`. Without the flag, it refreshes only the libraries that already exist. `appbuilder create --include-lib` writes it to `src/lib/kizenData.js`.
|
|
135
142
|
|
|
@@ -168,7 +175,7 @@ Encrypts a secret against a plugin's encryption keys and prints the envelope you
|
|
|
168
175
|
{ "encrypted": true, "value": "<base64>" }
|
|
169
176
|
```
|
|
170
177
|
|
|
171
|
-
The command talks to the Plugin Wizard host directly — `appbuilder dev` does **not** need to be running.
|
|
178
|
+
The command talks to the Plugin Wizard host directly — `appbuilder dev` does **not** need to be running. It still uses API-key credentials (deprecated for block commands) until Plugin Wizard accepts sign-in sessions.
|
|
172
179
|
|
|
173
180
|
| Flag | Default | Purpose |
|
|
174
181
|
| -------------------------- | --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
@@ -232,15 +239,15 @@ Packages the plugin in the current directory (same validation as `block export`)
|
|
|
232
239
|
appbuilder block push [api_name] [flags]
|
|
233
240
|
```
|
|
234
241
|
|
|
235
|
-
Interactive by default: pick
|
|
242
|
+
Interactive by default: pick the environment (only when you're signed in to several and pass no `--env`), the block, the surface (dashboard, homepage or chart group), the dashboard, then whether to update an existing custom code dashlet or create a new one, and confirm. Pushing to a production environment (`go`, `fmo`) asks you to type `y`. In a TTY, `--yes` skips the confirm prompt only when the headless write gate would apply, so `go` and `fmo` still ask for a typed `y` unless `--allow-production` is also passed; `--dry-run` shows the plan without writing. A dashlet edited in Kizen since the last push still prompts before overwriting unless `--force` is passed.
|
|
236
243
|
|
|
237
244
|
It runs headless when stdin or stdout is not a TTY, or when `--json` is passed. `--yes` never selects the mode. Headless runs never prompt: anything that would be a question fails with `needs_choice` and lists the choices.
|
|
238
245
|
|
|
239
246
|
| Argument / flag | Default | Purpose |
|
|
240
247
|
| -------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
241
248
|
| `[api_name]` | the plugin's only block | Block to push. Required when the plugin has more than one block. |
|
|
242
|
-
| `-c, --credentials <path>` |
|
|
243
|
-
| `--profile <name>` |
|
|
249
|
+
| `-c, --credentials <path>` | the sign-in session | API key (deprecated): credentials JSON file to use instead of the session |
|
|
250
|
+
| `--profile <name>` | the sign-in session | API key (deprecated): stored credential profile to use instead of the session |
|
|
244
251
|
| `--dashboard <id>` | the remembered target | Dashboard, homepage or chart group to push to |
|
|
245
252
|
| `--dashlet <id>` | matched by push history or name | Existing custom code dashlet to update. Needs `--dashboard`; can't be used with `--create`. |
|
|
246
253
|
| `--create` | off | Create a new dashlet instead of updating one |
|
|
@@ -250,8 +257,9 @@ It runs headless when stdin or stdout is not a TTY, or when `--json` is passed.
|
|
|
250
257
|
| `--force` | off | Overwrite a dashlet that was edited in Kizen since the last push |
|
|
251
258
|
| `--forget` | off | Clear the remembered target for this block before resolving |
|
|
252
259
|
| `--json` | off | Print a JSON result to stdout (forces headless); the human summary goes to stderr |
|
|
260
|
+
| `--env <env>` | the only signed-in environment | Environment of the session to use. Not with `-c` or `--profile`. |
|
|
253
261
|
|
|
254
|
-
**Credentials
|
|
262
|
+
**Credentials.** Without `-c` or `--profile`, the push uses your [`appbuilder login`](#appbuilder-login-logout-whoami-and-auth-header) session for `--env`, or for the only environment you're signed in to. If you're signed in to several environments and pass no `--env`, the run is `needs_choice` with `choice: "environment"`. If you're signed out, it fails with `credentials_invalid` and tells you to run `appbuilder login`; it never falls back to an API key. API keys (deprecated) are used only with `-c <path>` or `--profile <name>`, and never touch the session; `--env` with either is a `usage_error`. The credentials file must name a valid `environment` (`go`, `fmo`, `staging`, `integration`, `test1`); a missing or invalid one is refused with `credentials_invalid` rather than defaulting to production. Empty `apiKey`, `userId` or `businessId` are refused the same way. A `.kizenapp/config.json` `activeCredentialProfile` no longer selects an API key: the push uses the session and prints a one-line notice to stderr, so `--json` output stays clean. `credentialMode: "local"` doesn't affect block commands.
|
|
255
263
|
|
|
256
264
|
**Write gating (headless).** `--dry-run` is always a dry run. Without `--yes` the run is a dry run too, and stderr says `Dry run only: pass --yes to write.` With `--yes`, `go` and `fmo` also need `--allow-production` (else `production_requires_flag`). If the target dashlet was pushed from here before and its content has since been changed in Kizen, both dry runs and writes stop with `drift_detected` unless `--force` is passed.
|
|
257
265
|
|
|
@@ -349,14 +357,14 @@ A failure exits 1:
|
|
|
349
357
|
}
|
|
350
358
|
```
|
|
351
359
|
|
|
352
|
-
Optional failure fields: `choice` (`
|
|
360
|
+
Optional failure fields: `choice` (`environment`, `block`, `dashboard` or `target`) and `choices` with `needs_choice`, `remembered_target_missing` and a `--dashlet` that is `not_found`; `issues` (the packager's validation issues) with `validation_failed`; `field` with `invalid_block`; `hint` with `auth_failed` and `forbidden`. Each choice's `args` are the exact CLI arguments that select it, to be appended to the command (dashboard choices also carry `surface` and `canEdit`).
|
|
353
361
|
|
|
354
362
|
| Code | Meaning |
|
|
355
363
|
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
356
|
-
| `needs_choice` |
|
|
364
|
+
| `needs_choice` | An environment, block, dashboard or target must be chosen; see `choice` and `choices` |
|
|
357
365
|
| `validation_failed` | The plugin failed validation |
|
|
358
366
|
| `invalid_block` | The plugin has no blocks, or the block would be rejected (`field` names the problem) |
|
|
359
|
-
| `credentials_invalid` |
|
|
367
|
+
| `credentials_invalid` | Not signed in (run `appbuilder login`), or the `-c`/`--profile` file's `environment` is missing or invalid |
|
|
360
368
|
| `auth_failed` | Kizen rejected the credentials |
|
|
361
369
|
| `forbidden` | The credentials can't access the dashboard |
|
|
362
370
|
| `not_found` | The dashboard, or the `--dashlet` on it, doesn't exist |
|
|
@@ -368,6 +376,8 @@ Optional failure fields: `choice` (`profile`, `block`, `dashboard` or `target`)
|
|
|
368
376
|
| `api_error` | Any other Kizen API failure |
|
|
369
377
|
| `local_error` | A local failure that isn't a validation error: no `kizen.json`, packaging, reading `.kizenapp/pushes.json`, or writing it for `--forget` |
|
|
370
378
|
|
|
379
|
+
Sign-in sessions add these cases: not being signed in is `credentials_invalid`; several signed-in environments and no `--env` is `needs_choice` (`choice: "environment"`, each choice `{ value, label, args: ["--env", <env>] }`); a session that needs a new `appbuilder login` (expired, rejected or unreadable) is `auth_failed`; `--env` with `-c` or `--profile`, or an unknown `--env`, is `usage_error`; an unreachable token endpoint is `network_error`; and any other failure to refresh the session is `api_error`.
|
|
380
|
+
|
|
371
381
|
### `appbuilder block targets`
|
|
372
382
|
|
|
373
383
|
Lists where a block can be pushed: the business's dashboards and homepages plus its custom objects, or with `--object` one custom object's chart groups. Always headless.
|
|
@@ -376,12 +386,15 @@ The CLI honors `HTTP_PROXY`/`HTTPS_PROXY` and `NO_PROXY` on Node versions that s
|
|
|
376
386
|
|
|
377
387
|
`customObjects` is sorted by name and ends with Contacts (`"fetchUrl": "client"`) when the CLI can look up the business's contacts object; Kizen doesn't list Contacts with the other custom objects, so if that lookup fails the row is silently left out. `--object <contacts id>` lists Contacts' chart groups like any other object's.
|
|
378
388
|
|
|
379
|
-
| Flag | Default | Purpose
|
|
380
|
-
| -------------------------- | ------------------- |
|
|
381
|
-
| `-c, --credentials <path>` |
|
|
382
|
-
| `--profile <name>` |
|
|
383
|
-
| `--object <id>` | — | List the chart groups of this custom object (or Contacts)
|
|
384
|
-
| `--json` | off | Print JSON instead of tables
|
|
389
|
+
| Flag | Default | Purpose |
|
|
390
|
+
| -------------------------- | ------------------- | ------------------------------------------------------------- |
|
|
391
|
+
| `-c, --credentials <path>` | the sign-in session | API key (deprecated): credentials JSON file to use |
|
|
392
|
+
| `--profile <name>` | the sign-in session | API key (deprecated): stored credential profile to use |
|
|
393
|
+
| `--object <id>` | — | List the chart groups of this custom object (or Contacts) |
|
|
394
|
+
| `--json` | off | Print JSON instead of tables |
|
|
395
|
+
| `--env <env>` | as for `block push` | Environment of the session to use. Not with `-c`/`--profile`. |
|
|
396
|
+
|
|
397
|
+
Credentials and `--env` work as for `block push` (see [`appbuilder login`](#appbuilder-login-logout-whoami-and-auth-header)).
|
|
385
398
|
|
|
386
399
|
```json
|
|
387
400
|
{
|
|
@@ -435,11 +448,94 @@ Guardrails:
|
|
|
435
448
|
- On `needs_choice`, ask the user using `choices` (labels to show, `args` to append).
|
|
436
449
|
- On `remembered_target_missing`, ask whether to `--create` a new block rather than creating one.
|
|
437
450
|
|
|
451
|
+
### `appbuilder login`, `logout`, `whoami` and `auth-header`
|
|
452
|
+
|
|
453
|
+
Browser sign-in, the default for `block push` and `block targets`. API keys are deprecated for these commands and are used only when you pass `-c` or `--profile`.
|
|
454
|
+
|
|
455
|
+
```sh
|
|
456
|
+
appbuilder login [--env <env>] [--business <id or name> [--user <user id>]]
|
|
457
|
+
appbuilder login [--env <env>] --list [--json]
|
|
458
|
+
appbuilder whoami [--env <env>]
|
|
459
|
+
appbuilder logout [--env <env>] [--all | --business <id or name> [--user <user id>]]
|
|
460
|
+
appbuilder auth-header [--env <env>]
|
|
461
|
+
appbuilder block push [api_name] [--env <env>] [flags]
|
|
462
|
+
appbuilder block targets [--env <env>] [flags]
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
`login` opens Kizen's consent page in your browser and prints the URL in case the browser doesn't open. There, you pick the business the session is for. The CLI waits up to 5 minutes for the browser to return to `http://127.0.0.1:<port>/callback`. It uses OAuth 2.0 authorization code with PKCE (S256). It only trusts the server's OAuth metadata when its `issuer` is exactly the environment's origin (for example `https://staging.kizen.com`). It registers itself with the server on first use (dynamic client registration), so you don't need an API key or a client secret. A request to the callback with the wrong `state` gets a `400` and is otherwise ignored, so the sign-in keeps waiting for the real callback. Each session belongs to one user and one business, which the CLI looks up with `/auth/bootstrap` right after sign-in. If that lookup fails, nothing is saved. Signing in again to the same account replaces its session. A `block push` or `block targets` that's already running, or `auth-header`, keeps to the account it started with: if you switch to another account meanwhile, it stops and asks you to run it again. Signing in again to the same account doesn't stop it. If the browser shows an error instead of the consent page, the saved app registration is probably stale. The sign-in then times out and clears that app registration, so running `appbuilder login` again registers afresh.
|
|
466
|
+
|
|
467
|
+
#### Saved accounts
|
|
468
|
+
|
|
469
|
+
Every account you sign in to stays saved on this machine, and one of them is current for each environment. `whoami`, `auth-header`, `block push` and `block targets` always use the current one. To switch without the browser, which is how scripts and agents should do it:
|
|
470
|
+
|
|
471
|
+
```sh
|
|
472
|
+
appbuilder login --env staging --list # one line per saved account; the current one is marked
|
|
473
|
+
appbuilder login --env staging --list --json # [{ businessId, userId, businessName, fullName, email, current, readable }]
|
|
474
|
+
appbuilder login --env staging --business <business id or name>
|
|
475
|
+
appbuilder login --env staging --business <business id> --user <user id> # two users of one business
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
`--business` picks the saved account whose business id is exactly the value, or else whose business name matches it, ignoring case. `--user` narrows that to the account with exactly this user id, for when two users of one business are saved; it only works together with `--business`. Before switching, the CLI checks that the saved session still works by calling `/auth/bootstrap` with it, refreshing the token first if it's about to expire. On success it prints the same output as a browser sign-in. If the value matches several saved accounts, the command fails and lists them with their business ids, so you can retry with an exact id. When the matches are users of the same business, the error lists their user ids and suggests `--business <id> --user <user id>`. Commands the CLI prints for you to run leave plain values bare and single-quote the rest, so they're safe to paste into a shell. A network or server error leaves the current account as it was and exits with an error. Neither form of `--list` ever prints a token.
|
|
479
|
+
|
|
480
|
+
Two cases fall back to the browser: the saved account's refresh token has expired or been rejected (the CLI deletes that saved account first), or no saved account matches `--business` (and `--user`), whatever else is saved. Before the browser opens, `login` prints a short explanation to stderr: why it needs the browser, that a sign-in window is opening, which business to choose on Kizen's consent page, and the URL to open by hand if no window appears. At a terminal it addresses you; otherwise it addresses the agent or script running the command, which should pass it on to the person who signs in. Because the URL and instructions print before the sign-in finishes, an agent should run `appbuilder login` as a background command and relay its stderr to the user while it waits. After the sign-in, the CLI checks the account: after an expired saved account it must be exactly that account, and with no saved match it must match `--business` by business id or name, and `--user` by user id when given. If it does, it becomes current as usual. If the person signed in to another business, or as another user, the new account is saved but not made current, the command prints which account it got and the commands to use it or to try again, and it exits with code 1. If that account is already the current one, it says so instead.
|
|
481
|
+
|
|
482
|
+
When both stdin and stdout are terminals and you pass neither `--business` nor `--list`, `login` shows a picker of the saved accounts, labeled by business name, business id and email, with "Sign in with the browser" as the last option. In every other case, `login` never prompts: without `--business` it runs the browser sign-in, and if accounts are saved it first prints a hint about `--business` and `--list` to stderr.
|
|
483
|
+
|
|
484
|
+
`logout` removes the current account's session and leaves the other saved accounts. `logout --business <id or name>` removes one saved account, matched the same way as for `login`; if it's the current account, you're signed out too. `logout --all` removes every saved account for the environment. When no environment has a current account, both `--business` and `--all` need `--env`.
|
|
485
|
+
|
|
486
|
+
| Command | `--env` default | What it does |
|
|
487
|
+
| ------------- | ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
488
|
+
| `login` | `go` | Signs in with the browser, or switches to a saved account, and stores the session |
|
|
489
|
+
| `whoami` | the only environment you're signed in to | Calls `/auth/bootstrap` with the session and prints the user and business. Tokens are never printed. |
|
|
490
|
+
| `logout` | the only environment you're signed in to | Deletes the current account's session, one saved account (`--business`), or all of them (`--all`). Local only: the refresh tokens stay valid on Kizen. |
|
|
491
|
+
| `auth-header` | from the MCP server URL ([see below](#using-the-session-from-claude-code-mcp)) | Prints `{"Authorization":"Bearer <access token>"}` for a Claude Code MCP `headersHelper` |
|
|
492
|
+
|
|
493
|
+
The production write gate (`--allow-production`) and every other flag of `block push` and `block targets` work the same with a session as with an API key.
|
|
494
|
+
|
|
495
|
+
Sessions are stored in `~/.kizenappbuilder/oauth/` (directory `0700`, files `0600`), separate from API-key profiles. Each saved account has its own file, `<env>.<business id>.<user id>.json`, and `<env>.json` names the current account. Access tokens last an hour and refresh automatically: when less than a minute is left, or once after a `401`. Refresh tokens rotate on each use. Each process makes one refresh at a time, and every file is written atomically. Concurrent `appbuilder` processes may each refresh, which is safe because Kizen returns the same token pair when a refresh token is reused within 5 minutes. Before saving, a refresh re-reads the session: it keeps the newer tokens if another process already refreshed or you signed in again to the same account, and it fails with a sign-in error if you signed out or switched to another account meanwhile. If the refresh token is rejected, the CLI keeps the tokens another process already refreshed to; otherwise it deletes that account's file, and the command asks you to run `appbuilder login` again (with `--env <env>` for an environment other than `go`). A refresh only ever writes or deletes its own account's file, and only `login` and `logout` change which account is current, so a refresh that finishes late can't undo a logout or a switch. One that finishes just after you sign out can leave that account saved, though not current; `logout --all` removes it.
|
|
496
|
+
|
|
497
|
+
A session file that is corrupt or can't be read isn't treated as "not signed in". Commands that use it report the file's path and ask you to run `appbuilder login` (with `--env <env>` for an environment other than `go`). `appbuilder logout --env <env>` signs you out either way. If the session file is the problem, logout removes it. If `<env>.json` is the problem, logout removes that and leaves the saved accounts, and `logout --all` removes those too. `login --list` still lists a saved account whose file can't be read, by its ids.
|
|
498
|
+
|
|
499
|
+
#### Using the session from Claude Code (MCP)
|
|
500
|
+
|
|
501
|
+
Kizen's MCP server at `/api/mcp` accepts the same session. As a Claude Code `headersHelper`, `appbuilder auth-header` prints `{"Authorization":"Bearer <access token>"}` as one line on stdout, refreshing the token first if it's about to expire.
|
|
502
|
+
|
|
503
|
+
To set it up, run these from a plugin directory:
|
|
504
|
+
|
|
505
|
+
```sh
|
|
506
|
+
npx @kizenapps/cli setup-claude --mcp --env staging
|
|
507
|
+
npx @kizenapps/cli login --env staging
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
`setup-claude --mcp` installs the skill files as usual, then registers the server `kizen-<env>` at user scope by running `claude mcp add-json` (`--dry-run` only prints that command). The helper is pinned to the version of the CLI you ran it with. For CLI version 1.16.0, for example, it's equivalent to this POSIX-shell command:
|
|
511
|
+
|
|
512
|
+
```sh
|
|
513
|
+
claude mcp add-json --scope user kizen-staging '{"type":"http","url":"https://staging.kizen.com/api/mcp","headersHelper":"npx -y @kizenapps/cli@1.16.0 auth-header"}'
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
- An existing server with that name is left unchanged unless you pass `--force`. After upgrading the CLI, run `setup-claude --mcp --force` to pin the helper to the new version.
|
|
517
|
+
- `--force` only replaces the user-scope server. A server with the same name at local or project scope (for example, one you added by hand without `--scope user`) takes precedence over it in that project. Remove that one with `claude mcp remove kizen-<env>` (run in the project) if you want the user-scope server there.
|
|
518
|
+
- If the `claude` command isn't installed, it prints this command for you to run instead, and still succeeds.
|
|
519
|
+
- If you aren't signed in to that environment yet, it reminds you to run `appbuilder login` (with `--env <env>` for an environment other than `go`). If the saved session can't be read, it prints that error, with the file's path, instead. Either way the server is still registered.
|
|
520
|
+
- If registering fails, the skill files stay installed and the command exits with code 1.
|
|
521
|
+
|
|
522
|
+
The helper runs through `npx`, which reuses its cached copy of the CLI (running `setup-claude` through `npx` fills that cache), so it starts in about a second. That works when Claude Code was started from a shell with `node` on `PATH`. If it wasn't (for example, with nvm and Claude Code launched outside a terminal), use absolute paths instead, from `which node` and `which appbuilder`: `"headersHelper":"/absolute/path/to/node /absolute/path/to/appbuilder auth-header"`. `appbuilder` starts with `#!/usr/bin/env node`, so the path to `appbuilder` alone isn't enough. Use the absolute paths too when testing a local or `pnpm link` build whose version isn't published, because `npx` can't fetch that version.
|
|
523
|
+
|
|
524
|
+
User scope is recommended: Claude Code then passes the helper its environment variables and doesn't wait for project trust before running it.
|
|
525
|
+
|
|
526
|
+
The helper picks the environment from the MCP server URL that Claude Code passes it in `CLAUDE_CODE_MCP_SERVER_URL`: the environment whose API origin (scheme, host and port) matches that URL's origin. A URL that matches no environment is an error, so a token is never sent to a server it doesn't belong to. If you also pass `--env`, it must name that same environment, or the helper fails without printing a token. When the variable isn't set (for example, when you run the command yourself), it uses `--env`, or the only environment you're signed in to.
|
|
527
|
+
|
|
528
|
+
Claude Code gives the helper 10 seconds, so `auth-header` uses shorter timeouts than the other commands: 5s in total for token requests, including a retry after another process's refresh. On failure, it prints one line to stderr, such as a reminder to run `appbuilder login` (with `--env <env>` for an environment other than `go`), and nothing to stdout.
|
|
529
|
+
|
|
530
|
+
`auth-header` prints a live access token by design: treat its output like a password. The token acts as you, in the one business you chose when signing in, until it expires (up to an hour).
|
|
531
|
+
|
|
532
|
+
Known limitation: the CLI only refreshes a token when less than a minute is left, so if Kizen revokes a token with more time left, `auth-header` keeps returning it until it expires or you run `appbuilder login` again.
|
|
533
|
+
|
|
438
534
|
## Reference
|
|
439
535
|
|
|
440
536
|
### Environment variables
|
|
441
537
|
|
|
442
|
-
|
|
538
|
+
Four environment variables point the CLI at a different Plugin Wizard (encryption API) host. Precedence for the `dev` target:
|
|
443
539
|
|
|
444
540
|
1. **`PLUGIN_WIZARD_URL`** — forces a single host for **all** targets, dev and prod alike.
|
|
445
541
|
2. **`PLUGIN_WIZARD_URL_DEV`** — explicit dev host.
|
|
@@ -448,6 +544,8 @@ The CLI reads four environment variables, all of which point it at a different P
|
|
|
448
544
|
|
|
449
545
|
Prod follows the same order minus step 3: `PLUGIN_WIZARD_URL`, then **`PLUGIN_WIZARD_URL_PROD`**, then the default `https://plugin-wizard.kizen.com`. An empty-string value is treated as unset at every level.
|
|
450
546
|
|
|
547
|
+
**`CLAUDE_CODE_MCP_SERVER_URL`** is set by Claude Code when it runs `appbuilder auth-header`, which uses it to pick the environment (see [Using the session from Claude Code](#using-the-session-from-claude-code-mcp)).
|
|
548
|
+
|
|
451
549
|
### The `.kizenapp/` directory
|
|
452
550
|
|
|
453
551
|
`build` and `dev` create `.kizenapp/` next to your `kizen.json` and add it to `.gitignore` automatically. It holds machine-local state only — **keep it gitignored**:
|