@h1r-ai/croche-cli 0.0.0-stage β†’ 0.5.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/LICENSE ADDED
@@ -0,0 +1,32 @@
1
+ **Croche SDK License** (version 1, beta)
2
+
3
+ Applies to `@h1r-ai/croche`, `@h1r-ai/croche-react-native`, `@h1r-ai/croche-cli`,
4
+ the Croche Android library (AAR), and the `CrocheRuntime` Swift package.
5
+
6
+ Copyright (c) 2026 H1R AI. All rights reserved.
7
+
8
+ 1. **Grant.** H1R AI grants you a non-exclusive, worldwide, royalty-free licence to install and use
9
+ this software (the "SDK"), unmodified, to build and run applications that use the Croche
10
+ service (croche.ai, "Croche Cloud"), and to distribute the SDK only as part of such an
11
+ application.
12
+ 2. **Restrictions.** You may not:
13
+ (a) use the SDK, or any part of it, with a service other than Croche Cloud;
14
+ (b) distribute the SDK on its own, or as part of a library, SDK or service for others;
15
+ (c) reverse engineer, decompile or disassemble the SDK, or extract its prompts, instructions,
16
+ prompt templates or other model-facing text, except to the extent applicable law expressly
17
+ permits this despite this restriction;
18
+ (d) remove or alter this notice or the third-party notices.
19
+ 3. **Croche Cloud.** Use of Croche Cloud is governed by its own terms of service. The SDK does
20
+ nothing without it.
21
+ 4. **Third-party components.** The SDK contains open-source components under their own licences
22
+ (listed in `THIRD-PARTY-NOTICES`). Those licences govern those components, and nothing here
23
+ limits them.
24
+ 5. **Ownership.** H1R AI keeps all rights not expressly granted.
25
+ 6. **Termination.** This licence ends automatically if you breach it, or when your access to Croche
26
+ Cloud ends. Sections 2 to 8 survive.
27
+ 7. **No warranty.** The SDK is provided "as is", without warranty of any kind.
28
+ 8. **Limitation of liability.** To the extent the law allows, H1R AI is not liable for any
29
+ indirect, incidental or consequential damages arising from the SDK. Its total liability is
30
+ limited to the greater of the fees you paid in the 12 months before the claim or KRW 100,000.
31
+ 9. **Governing law.** This licence is governed by the laws of the Republic of Korea.
32
+ The Suwon District Court has exclusive jurisdiction.
package/README.md CHANGED
@@ -1,3 +1,469 @@
1
- # Temporary Holding Version
1
+ # Croche CLI
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@h1r-ai/croche-cli` is an independently installable Node 22+ CLI for Croche Cloud accounts and explicitly attached local Runtimes. It has no production npm dependencies and never needs a model provider key.
4
+
5
+ ```sh
6
+ npm install --global @h1r-ai/croche-cli
7
+ croche --help
8
+ croche projects --help --json
9
+ ```
10
+
11
+ ## Debug a running app
12
+
13
+ Keep the development app open, then run:
14
+
15
+ ```sh
16
+ croche debug
17
+ ```
18
+
19
+ The CLI starts or reuses the local control broker, waits briefly for apps to
20
+ advertise themselves, and lists available Runtimes. In a terminal, choose a
21
+ Runtime by number. The CLI starts or reuses the bundled debugger, attaches that
22
+ Runtime through its advertised `debug.attach` capability, and prints a viewer
23
+ link filtered to that Runtime. It preserves the existing conversation and any
24
+ captures already held by the running debugger. This requires no Cloud account,
25
+ developer key, provider key, or separate debugger installation.
26
+
27
+ For automation, the bare command returns the available Runtime list without
28
+ prompting or choosing automatically. Use an explicit ID to connect:
29
+
30
+ ```sh
31
+ croche debug runtimes --json
32
+ croche debug connect --runtime-id RUNTIME_ID
33
+ croche debug disconnect --runtime-id RUNTIME_ID
34
+ croche debug status --json
35
+ ```
36
+
37
+ `connect` attaches the selected Runtime before returning the standalone server's
38
+ viewer URL. Open that URL in your browser to inspect the app. `disconnect`
39
+ acknowledges detachment from the selected Runtime; it leaves the debugger server
40
+ and retained captures available and does not cancel an active app turn.
41
+
42
+ The normal Croche Chat development app advertises its debugger capability through
43
+ an authenticated development relay. Other apps must attach their existing Runtime
44
+ to the local broker with the SDK's debugger adapter. A Runtime without that
45
+ capability is listed as unavailable for debugger attachment. Captures begin when
46
+ the observer attaches; attaching during a turn can yield an incomplete capture.
47
+
48
+ Supporting commands:
49
+
50
+ ```sh
51
+ croche debug start
52
+ croche debug token
53
+ croche debug connect --runtime-id RUNTIME_ID --port 8792 --connection-file /private/path/debugger.json
54
+ croche debug stop
55
+ ```
56
+
57
+ `start` starts or reuses the collector without selecting a Runtime. `status`
58
+ never starts a service or prints a token. `connect` explicitly prints the complete
59
+ `http://127.0.0.1:8790/#token=...&runtime=...` pairing link; `token` explicitly
60
+ reveals the saved pairing token. Treat those two outputs as local credentials.
61
+ The standalone viewer can also authenticate an unpaired browser using the token
62
+ from `croche debug token`. Chat's development relay currently supports the default
63
+ debugger port 8790; other ports require an
64
+ app adapter that supports that destination.
65
+
66
+ `stop` stops the collector `start` launched, selected the same way (`--port`,
67
+ `--connection-file`). It asks the collector to shut down with the saved pairing token
68
+ (`POST /api/shutdown`), and waits until the port is closed. Its captures are discarded. The
69
+ connection file and its pairing token are kept, so the next `start` reuses the token. `start`
70
+ also records the collector's process id beside the connection file (`connection.json.pid`); only
71
+ if the collector is still running after the request, and itself reports that same process id,
72
+ is that process terminated (`method: "terminated"`). A process id it cannot tie to the running
73
+ collector is never killed: a port that is closed means "not running", and a port that answers
74
+ without the pairing token is refused. Not running is success (exit 0, `stopped: false`); a
75
+ collector that could not be stopped is exit 4 (`local_port_occupied` or `debug_stop_failed`).
76
+ A collector started by an older CLI has no shutdown request and recorded no process id; stop it
77
+ from its terminal or task manager.
78
+
79
+ ### Observing from Studio
80
+
81
+ ```sh
82
+ croche debug start # also prints a one-time Studio link
83
+ croche debug --studio-link # a fresh link while the collector runs
84
+ croche debug start --studio-origin http://localhost:5173 # a dev Studio, set when the collector starts
85
+ ```
86
+
87
+ A Studio link looks like
88
+ `https://studio.croche.ai/studio#pair=CODE&broker=http://127.0.0.1:8790`. Its code
89
+ works once, for 10 minutes, and only from the Studio origin; at most 8 are
90
+ outstanding. Studio exchanges it for an observe-only token (6 hours, memory only) and
91
+ streams the collector's events over `GET /api/debug/events`
92
+ (`docs/DEBUG-PAIRING.md` in croche-runtime). That token cannot send
93
+ events, pause or clear, and the link never reveals the pairing token.
94
+
95
+ Studio receives only events a Runtime stamped `visibility: "runtime"`: the app's own
96
+ traffic, without model request bodies, Croche instructions or private facts. Events
97
+ stamped `full`, or unstamped (Runtimes before 0.9), are counted but withheld.
98
+
99
+ To watch an app from Studio, attach its Runtime in the public view:
100
+
101
+ ```sh
102
+ croche debug connect --runtime-id RUNTIME_ID --visibility runtime # or: croche debug --visibility runtime
103
+ ```
104
+
105
+ This prints the local viewer link and a one-time Studio link. Without
106
+ `--visibility`, `connect` defaults to `runtime`. Public builds refuse `full` even
107
+ with a debug key. Explicit `--visibility full` is for owner-only Core builds
108
+ with `internal-debug`; never publish those artifacts. Studio withholds those
109
+ private entries. See [private builds](../../docs/INTERNAL-DEBUG.md).
110
+
111
+ The CLI generates credentials once and stores them in private mode-0600 JSON
112
+ files under the OS user state directory. On Linux, the default paths are:
113
+
114
+ - `${XDG_STATE_HOME:-~/.local/state}/croche/debugger/connection.json`
115
+ - `${XDG_STATE_HOME:-~/.local/state}/croche/control/connection.json`
116
+
117
+ On macOS the base is `~/Library/Application Support`; on Windows it is
118
+ `LOCALAPPDATA`. In PowerShell the Windows defaults are:
119
+
120
+ - `$env:LOCALAPPDATA\croche\debugger\connection.json`
121
+ - `$env:LOCALAPPDATA\croche\control\connection.json`
122
+
123
+ Nondefault ports use `connection-PORT.json`. `--connection-file`
124
+ selects a debugger file; `--control-connection-file` or
125
+ `CROCHE_CONTROL_CONNECTION_FILE` selects a broker file. Existing legacy debugger
126
+ files `{url,pairedUrl,pairingToken}` and broker files `{url,token}` are accepted
127
+ when private and owned by the current user. Pairing links are rebuilt from the
128
+ validated URL/token; arbitrary saved links are not followed. State directory
129
+ components must not be symlinks or writable by other users.
130
+
131
+ On Windows, file modes do not exist: Node reports every writable file and
132
+ directory as `0666`, and `0600`/`0700` are not applied. The CLI therefore skips
133
+ the owner, mode-0600 and other-writable checks there (symlinks are still
134
+ refused), and the connection file relies on the ACL of the user profile
135
+ (`LOCALAPPDATA` is under it by default). A `--connection-file` or
136
+ `CROCHE_CONTROL_CONNECTION_FILE` outside the profile gets only that folder's ACL.
137
+
138
+ An existing `CROCHE_CONTROL_TOKEN`/`CROCHE_CONTROL_URL` may identify the same broker;
139
+ conflicting saved credentials are refused. When importing a previously running
140
+ collector or broker, copy its existing connection file to the selected private
141
+ path with mode 0600 before starting. An occupied port with an unknown token is
142
+ refused; the CLI never overwrites a service's token or clears captures, and stops only the
143
+ collector that answers with the saved pairing token (`croche debug stop`).
144
+ Concurrent starts use an exclusive lock. If a process dies while holding that
145
+ lock, verify that startup has ended before manually removing the `.lock` file.
146
+
147
+ Detached child processes receive their token in the environment, never in argv.
148
+ They continue running after the CLI exits. Collector captures and broker request
149
+ queues remain bounded in-memory data; the private connection file preserves the
150
+ credential, not captures across a server restart. `croche debug stop` stops the
151
+ collector; no command stops the broker or rotates a token.
152
+
153
+ ## Account and project commands
154
+
155
+ Create a developer key in an authenticated Studio session. Cloud returns its secret once, stores only a SHA-256 hash, and supports revocation. Run `croche login` yourself once in your terminal; enter the key in its hidden prompt. Coding agents must never run login or ask for the key in chat. `CROCHE_DEVELOPER_KEY` remains an optional environment override. The CLI connects to Croche automatically. Credentials are never command arguments or URL parameters.
156
+
157
+ ```sh
158
+ croche auth whoami --json
159
+ croche projects list
160
+ croche projects create --name "Story companion"
161
+ croche projects get PROJECT_ID
162
+ croche projects update PROJECT_ID --name "New name" --policy-file policy.json
163
+ croche projects operations PROJECT_ID --limit 100
164
+ croche projects cost PROJECT_ID --json
165
+ croche runtimes list --project-id PROJECT_ID
166
+ ```
167
+
168
+ New projects have a $10 monthly production budget and app access enabled.
169
+ Change production budgets in web Studio. Use web Studio for server-key issuance/revocation/rotation, security and attestation
170
+ settings, allowances, project pause/archive, Runtime blocking and production promotion.
171
+ The CLI uses only a `dk_` developer key for Cloud requests; Cloud enforces its agent scope.
172
+ An explicit bearer never falls back to a browser cookie. The account remains an evaluation
173
+ account; a developer key does not imply a paid subscription.
174
+
175
+ `projects update --policy-file` accepts only a JSON object with a `routing` field, for
176
+ example `{"routing":{"mode":"preferred","providers":["openai"]}}`; `{"routing":null}` clears that override.
177
+ Allowance, host budget control, attestation and other policy fields are refused before
178
+ HTTP. Routing's provider order and quantizations remain agent-editable until they move
179
+ into the snapshot. Cloud validates the routing contents and applies its fixed data policy.
180
+
181
+ Read-only commands still show project usage, key metadata and attestation settings.
182
+ The all-time cost endpoint reports known cost and unresolved operation count;
183
+ `charged_cost_usd: null` means a final total is unknown. Developer-key metadata,
184
+ issuance and revocation are available only in web Studio.
185
+
186
+ ## App credentials, attestation and usage
187
+
188
+ Inspect credential metadata, attestation and usage with the developer key.
189
+ The coding agent can issue and revoke debug keys with the CLI. Server credentials and attestation changes stay in web Studio.
190
+
191
+ ```sh
192
+ # Simulators, emulators and your own devices: a debug key, used as `debugKey` in debug
193
+ # builds only. Calls use your weekly development allowance, never Runtime Credit.
194
+ croche debug-keys create --project PROJECT_ID
195
+ # Writes CROCHE_DEBUG_KEY to ./.env without printing it. Use --env-file PATH to choose
196
+ # the destination. Existing values require --force; tracked files are refused.
197
+ croche debug-keys list --project PROJECT_ID
198
+ croche debug-keys revoke --project PROJECT_ID KEY_ID
199
+
200
+ # A web app's own backend (one Runtime per end user): a server key, kept on the server.
201
+ croche keys server list PROJECT_ID
202
+
203
+ # Release builds on real devices: App Attest / Play Integrity settings.
204
+ croche attestation get PROJECT_ID
205
+
206
+ # What each end user and each agent cost, and what is left to spend.
207
+ croche projects usage PROJECT_ID --period week # week | month (default) | all
208
+ ```
209
+
210
+ These commands run unchanged in PowerShell: `#` starts a comment there too, so the `|` in
211
+ the last comment is not a pipe.
212
+
213
+ Files the CLI reads (`--policy-file`, `--text-file` and the connection
214
+ files) are UTF-8, with or without a leading byte order mark (BOM), so a file saved by Windows
215
+ PowerShell with `-Encoding UTF8` works as-is. A UTF-16 file, which Windows PowerShell 5.1
216
+ writes with `>` or `Out-File`, is refused with `unsupported_encoding` (exit 2): save it as
217
+ UTF-8. In PowerShell, keep the JSON in a single-quoted here-string:
218
+
219
+ ```powershell
220
+ $json = @'
221
+ {"routing":{"mode":"preferred","providers":["openai"]}}
222
+ '@
223
+ # pwsh 7: Set-Content (and >) write UTF-8.
224
+ Set-Content -Path policy.json -Value $json
225
+ # Windows PowerShell 5.1: > and Out-File write UTF-16, which is refused. Use -Encoding UTF8:
226
+ Set-Content -Path policy.json -Value $json -Encoding UTF8
227
+ ```
228
+
229
+ ## Opt-in local Runtime control
230
+
231
+ Set a separate `CROCHE_CONTROL_TOKEN` containing 24–4096 URL-safe characters, then start the loopback broker:
232
+
233
+ ```sh
234
+ croche control serve
235
+ ```
236
+
237
+ The broker binds `127.0.0.1:8791`. It does not open Runtime storage. Apps explicitly attach an existing Runtime through the SDK and advertise supported capabilities:
238
+
239
+ ```ts
240
+ import { attachRuntimeControl } from '@h1r-ai/croche/control';
241
+
242
+ const connection = await attachRuntimeControl({
243
+ runtime,
244
+ token: localControlToken,
245
+ tools: () => runtime.tools(),
246
+ // Route through your app's normal send path to retain transcript/context rules.
247
+ send: (input, { signal }) => appSend(input, { signal }),
248
+ cancel: () => appCancel(),
249
+ });
250
+ // On app teardown:
251
+ await connection.close();
252
+ ```
253
+
254
+ For a browser reload, pass `registrationTimeoutMs: 20000` to wait for the old attachment’s 15-second lease to expire. By default, duplicate attachment fails immediately. This wait only repeats registration; it never repeats a dispatched command.
255
+
256
+ The helper preserves the existing Runtime identity. A host adapter receives only `{id, text}` and an abort signal. Control cannot inject system context or change a send's kind. Without adapters, send uses public `runtime.send`, and cancellation affects sends initiated by that attachment. Supply app-owned adapters when other application work must also be cancellable. Cancellation never implies that an already executed effect was rolled back.
257
+
258
+ ```sh
259
+ croche runtime list --json
260
+ croche runtime status --runtime-id RUNTIME_ID
261
+ croche runtime tools --runtime-id RUNTIME_ID
262
+ croche runtime history --runtime-id RUNTIME_ID --offset 0 --limit 50
263
+ croche runtime send --runtime-id RUNTIME_ID --id INPUT_ID --text "Continue the story" --request-id REQUEST_ID
264
+ croche runtime cancel --runtime-id RUNTIME_ID
265
+ croche runtime sync --runtime-id RUNTIME_ID
266
+ croche runtime budget get --runtime-id RUNTIME_ID
267
+ croche runtime budget set --runtime-id RUNTIME_ID --amount 1
268
+ croche runtime result --request-id REQUEST_ID --json
269
+ ```
270
+
271
+ `--text-file PATH` replaces `--text` for multiline input. Local URL precedence is `--control-url`, then `CROCHE_CONTROL_URL`, then `http://127.0.0.1:8791`; only loopback HTTP origins are accepted. Account developer keys do not authenticate local control.
272
+
273
+ The broker authenticates every request, bounds request/response memory, and disables CORS by default. Browser apps must explicitly allow their exact origin with `croche control serve --allow-origin https://your-development-origin.example`; several origins are comma-separated, and in PowerShell the list must be quoted (`--allow-origin 'https://a.example,https://b.example'`), because an unquoted `a,b` is an array that PowerShell passes as two arguments. Alternatively, use a trusted same-origin development relay with the helper's injected `fetch`. An HTTPS page cannot directly fetch plain HTTP loopback in every browser. Do not add control transport to production automatically or embed the token in a public bundle.
274
+
275
+ The broker's queue and result receipts are in memory, bounded to 1,000 requests and 8 MiB. Finished receipts expire after 30 minutes. A disconnected in-flight action is reported as uncertain and is never automatically delivered again. Use `runtime result` after a CLI timeout. If the broker restarts, use the same durable **input ID** when deliberately resubmitting; the SDK and app's normal persisted receipt rules determine replay. Reusing an input ID with changed input is rejected. A broker request ID is distinct from that durable input ID.
276
+
277
+ ## Automation and development
278
+
279
+ `--json` emits one object: `{ok:true,data}` or `{ok:false,error:{code,message,details?}}`. Help works without credentials. Errors never silently retry an action. Exit codes are 0 success, 1 remote failure, 2 usage/configuration, 3 authentication/authorization, and 4 transport/timeout (a timed-out control request may still be running).
280
+
281
+ <!-- studio-cli-json:start -->
282
+ ### Frozen Cloud JSON fields
283
+
284
+ The hackathon CLI freezes the field paths and JSON types below, from
285
+ [studio-cli-json.json](../../vectors/studio-cli-json.json). Additions are free;
286
+ renames/removals require a new path alongside the old one. `[]` means every
287
+ array member; `|null` marks a nullable value. Empty lists have no members.
288
+ Config content follows the project-config grammar, so its application fields
289
+ are not required on every document. Local `debug`, `control` and `runtime`
290
+ commands use their separate local protocols and are outside this Cloud freeze.
291
+ Human-only `login` and `logout` are also outside the agent-callable freeze.
292
+
293
+ Success is `{ok:true,data}`; refusal is `{ok:false,error:{code,message,details?}}`.
294
+ Exit classes stay 0 success, 1 remote failure, 2 usage/configuration,
295
+ 3 authentication/authorization and 4 transport/timeout. Cloud human-only
296
+ operations continue to refuse agent authority with `human_session_required`.
297
+ Default agent-callable Cloud output never contains a one-time secret. Credential metadata
298
+ uses `prefix`; project `public_key` is returned only in project views.
299
+ `decryption_key` must never appear, even when attestation is configured.
300
+
301
+ | Shape | Relative paths and JSON types |
302
+ | --- | --- |
303
+ | `project` | `id`: string; `name`: string; `created_at`: string; `public_key`: string; `status`: string; `app_access_enabled`: boolean; `budget`: object; `budget.limit_usd`: number; `budget.period`: string; `budget.used_usd`: number; `runtime_policy`: object; `runtime_policy.default_user_allowance_usd`: number; `runtime_policy.host_budget_control_enabled`: boolean; `runtime_policy.max_user_allowance_usd`: number; `runtime_policy.max_single_adjustment_usd`: number; `runtime_policy.attestation`: string; `allowed_models`: array; `allowed_models[]`: string |
304
+ | `account` | `access`: string; `id`: string; `name`: string; `email`: string; `admin`: boolean; `plan`: object\|null; `credit_balance_usd`: number; `outstanding_key_limits_usd`: number; `spent_usd`: number |
305
+ | `plan` | `plan_id`: string; `name`: string; `ends_at`: string |
306
+ | `routing` | `mode`: string; `providers`: array; `providers[]`: string; `quantizations`: array; `quantizations[]`: string |
307
+ | `key_metadata` | `id`: string; `name`: string; `prefix`: string; `created_at`: string; `last_used_at`: string\|null; `revoked_at`: string\|null; `installations`: number |
308
+ | `development_key` | `follow_draft`: boolean; `warning`: string\|null |
309
+ | `server_key` | `spent_usd`: number |
310
+ | `cost` | `project_id`: string; `currency`: string; `period`: string; `scope`: string; `charged_cost_usd`: number\|null; `known_charged_cost_usd`: number; `unknown_operations`: number; `operations`: number |
311
+ | `development_usage` | `scope`: string; `week_start`: string; `calls`: number; `unknown_calls`: number; `known_percent`: number\|null; `used_percent`: number\|null; `remaining_percent`: number\|null |
312
+ | `usage` | `project_id`: string; `period`: string; `since`: string\|null; `project`: object; `project.limit_usd`: number; `project.used_usd`: number; `project.remaining_usd`: number; `project.period_start`: string; `development`: object; `by_user`: array; `by_agent`: array |
313
+ | `usage_row` | `calls`: number; `runtime_usd`: number; `subscription_calls`: number; `subscription_percent`: number\|null; `unsettled_calls`: number; `prompt_tokens`: number; `cached_tokens`: number; `completion_tokens`: number; `last_call_at`: string |
314
+ | `operation` | `agent_instance_id`: string\|null; `operation_id`: string; `project_id`: string; `operation_type`: string; `name`: string; `status`: string; `model`: string\|null; `provider`: string\|null; `error_code`: string\|null; `parent_operation_id`: string\|null; `cost_status`: string; `duration_ms`: number; `started_at`: string; `user_id`: string; `agent_id`: string; `runtime_instance_id`: string; `session_id`: string; `turn_id`: string; `generation_id`: string\|null; `billed_to`: string; `access_path`: string; `charged_cost_usd`: number\|null; `installation_id`: string\|null |
315
+ | `operation_metadata` | `prompt_tokens`: number; `cached_tokens`: number; `completion_tokens`: number; `ttft_ms`: number; `gateway_status`: number; `streamed`: boolean; `purpose`: string; `finish_reason`: string |
316
+ | `runtime` | `runtime_instance_id`: string; `user_id`: string; `user`: string; `attested_by`: string; `access_path`: string; `attestation_outcome`: string\|null; `attestation_reason`: string\|null; `attestation_platform`: string\|null; `app_version`: string\|null; `sdk`: string; `sdk_version`: string; `status`: string; `last_seen_at`: string; `spent_usd`: number |
317
+ | `ios` | `team_id`: string; `bundle_id`: string; `allow_development`: boolean |
318
+ | `android` | `package_name`: string; `certificate_sha256`: array; `certificate_sha256[]`: string; `verification_key`: string; `decryption_key_set`: boolean; `recent_failures`: array; `recent_failures[].reason`: string; `recent_failures[].installs`: number; `recent_failures[].last_at`: string |
319
+ | `unverified_path` | `enabled`: boolean; `limit_usd`: number; `key_status`: string; `spent_usd`: number; `spent_this_period_usd`: number; `remaining_usd`: number; `installs`: number; `unknown_cost_calls`: number |
320
+ | `draft` | `revision_id`: string; `schema`: number; `document`: object; `document.schema`: number; `document.config`: object; `updated_by`: string; `updated_at`: string |
321
+ | `version` | `project_id`: string; `version`: number; `revision_id`: string; `kind`: string; `from_version`: number\|null; `note`: string\|null; `released_by`: string; `released_at`: string; `applied_7d`: number |
322
+ | `unverified_install` | `installation_id`: string; `attestation_outcome`: string\|null; `attestation_reason`: string\|null; `platform`: string\|null; `sdk`: string; `sdk_version`: string; `app_version`: string\|null |
323
+ | `debug_key` | `warning`: string\|null |
324
+
325
+ | Command / variant | Frozen paths (relative to the JSON envelope) |
326
+ | --- | --- |
327
+ | `auth whoami` / account | `ok`: boolean; `data`: object; `data.account`: object; `data.credential.source`: string; `data.credential.prefix`: string; `data.account` β†’ `account`; `data.account.plan` β†’ `plan` |
328
+ | `projects list` / projects-list | `ok`: boolean; `data`: object; `data.projects`: array; `data.projects[]` β†’ `project` |
329
+ | `projects create` / project-create | `ok`: boolean; `data`: object; `data.project`: object; `data.project` β†’ `project` |
330
+ | `projects get` / project-get | `ok`: boolean; `data`: object; `data.project`: object; `data.project` β†’ `project` |
331
+ | `projects update` / project-update | `ok`: boolean; `data`: object; `data.project`: object; `data.project.runtime_policy.routing`: object; `data.project` β†’ `project`; `data.project.runtime_policy.routing` β†’ `routing` |
332
+ | `projects operations` / operations | `ok`: boolean; `data`: object; `data.operations`: array; `data.has_more`: boolean; `data.next_cursor`: object\|null; `data.operations[]` β†’ `operation`; `data.operations[]` β†’ `operation_metadata` |
333
+ | `projects operations` / operations-pagination | `ok`: boolean; `data`: object; `data.operations`: array; `data.has_more`: boolean; `data.next_cursor`: object; `data.next_cursor.started_at`: string; `data.next_cursor.operation_id`: string; `data.operations[]` β†’ `operation`; `data.operations[]` β†’ `operation_metadata` |
334
+ | `projects operations` / operation-production-cost | `ok`: boolean; `data`: object; `data.operations`: array; `data.has_more`: boolean; `data.next_cursor`: object\|null; `data.operations[].provider_cost_usd`: number\|null; `data.operations[]` β†’ `operation`; `data.operations[]` β†’ `operation_metadata` |
335
+ | `projects operations` / operations-unverified-failure | `ok`: boolean; `data`: object; `data.operations`: array; `data.has_more`: boolean; `data.next_cursor`: object\|null; `data.operations[].unverified`: object\|null; `data.operations[].error_detail_code`: string; `data.operations[]` β†’ `operation`; `data.operations[]` β†’ `operation_metadata`; `data.operations[].unverified` β†’ `unverified_install` |
336
+ | `projects cost` / cost-unresolved | `ok`: boolean; `data`: object; `data.cost`: object; `data.cost.charged_cost_usd`: null; `data.cost` β†’ `cost` |
337
+ | `keys development list` / development-keys | `ok`: boolean; `data`: object; `data.debug_tokens`: array; `data.debug_tokens[]` β†’ `key_metadata`; `data.debug_tokens[]` β†’ `development_key` |
338
+ | `keys server list` / server-keys | `ok`: boolean; `data`: object; `data.server_keys`: array; `data.server_keys[]` β†’ `key_metadata`; `data.server_keys[]` β†’ `server_key` |
339
+ | `projects usage` / usage-week | `ok`: boolean; `data`: object; `data.usage`: object; `data.usage.by_user[].user_id`: string; `data.usage.by_user[].user`: string; `data.usage.by_agent[].agent_id`: string; `data.usage` β†’ `usage`; `data.usage.development` β†’ `development_usage`; `data.usage.by_user[]` β†’ `usage_row`; `data.usage.by_agent[]` β†’ `usage_row` |
340
+ | `projects usage` / usage-month | `ok`: boolean; `data`: object; `data.usage`: object; `data.usage.by_user[].user_id`: string; `data.usage.by_user[].user`: string; `data.usage.by_agent[].agent_id`: string; `data.usage` β†’ `usage`; `data.usage.development` β†’ `development_usage`; `data.usage.by_user[]` β†’ `usage_row`; `data.usage.by_agent[]` β†’ `usage_row` |
341
+ | `projects usage` / usage-all | `ok`: boolean; `data`: object; `data.usage`: object; `data.usage.by_user[].user_id`: string; `data.usage.by_user[].user`: string; `data.usage.by_agent[].agent_id`: string; `data.usage` β†’ `usage`; `data.usage.development` β†’ `development_usage`; `data.usage.by_user[]` β†’ `usage_row`; `data.usage.by_agent[]` β†’ `usage_row` |
342
+ | `attestation get` / attestation | `ok`: boolean; `data`: object; `data.attestation`: object; `data.attestation.ios`: object\|null; `data.attestation.android`: object\|null; `data.attestation.unverified_path`: object; `data.attestation.ios` β†’ `ios`; `data.attestation.android` β†’ `android`; `data.attestation.unverified_path` β†’ `unverified_path` |
343
+ | `runtimes list` / runtimes | `ok`: boolean; `data`: object; `data.runtimes`: array; `data.runtimes[]` β†’ `runtime` |
344
+ | `config get` / config-get-draft | `ok`: boolean; `data`: object; `data.schema`: number; `data.config`: object |
345
+ | `config get` / config-get-revision | `ok`: boolean; `data`: object; `data.schema`: number; `data.config`: object |
346
+ | `config get` / config-get-version | `ok`: boolean; `data`: object; `data.version`: number; `data.revision`: string; `data.config`: object |
347
+ | `config get` / config-get-output | `ok`: boolean; `data`: object; `data.file`: string; `data.revision_id`: string\|null |
348
+ | `config get` / config-get-version-output | `ok`: boolean; `data`: object; `data.file`: string; `data.revision_id`: string\|null; `data.version`: number |
349
+ | `config save` / config-save | `ok`: boolean; `data`: object; `data.revision_id`: string; `data.created`: boolean |
350
+ | `config list` / config-list | `ok`: boolean; `data`: object; `data.versions`: array; `data.draft`: object\|null; `data.versions[]` β†’ `version`; `data.draft` β†’ `draft` |
351
+ | `auth whoami` / account-no-plan | `ok`: boolean; `data`: object; `data.account`: object; `data.account.plan`: null; `data.credential.source`: string; `data.credential.prefix`: string; `data.account` β†’ `account` |
352
+ | `projects operations` / empty-operations | `ok`: boolean; `data`: object; `data.operations`: array; `data.has_more`: boolean; `data.next_cursor`: null |
353
+ | `keys development list` / empty-development-keys | `ok`: boolean; `data`: object; `data.debug_tokens`: array |
354
+ | `keys server list` / empty-server-keys | `ok`: boolean; `data`: object; `data.server_keys`: array |
355
+ | `runtimes list` / empty-runtimes | `ok`: boolean; `data`: object; `data.runtimes`: array |
356
+ | `projects cost` / cost-known | `ok`: boolean; `data`: object; `data.cost`: object; `data.cost.charged_cost_usd`: number; `data.cost` β†’ `cost` |
357
+ | `projects usage` / empty-usage | `ok`: boolean; `data`: object; `data.usage`: object; `data.usage` β†’ `usage`; `data.usage.development` β†’ `development_usage` |
358
+ | `attestation get` / empty-attestation | `ok`: boolean; `data`: object; `data.attestation`: object; `data.attestation.ios`: null; `data.attestation.android`: null; `data.attestation.unverified_path`: object; `data.attestation.unverified_path` β†’ `unverified_path` |
359
+ | `config get` / empty-config-get | `ok`: boolean; `data`: null |
360
+ | `config get` / empty-config-output | `ok`: boolean; `data`: object; `data.file`: string; `data.revision_id`: null |
361
+ | `config list` / empty-config-list | `ok`: boolean; `data`: object; `data.versions`: array; `data.draft`: null |
362
+ | `projects list` / empty-projects-list | `ok`: boolean; `data`: object; `data.projects`: array |
363
+ | `debug-keys create` / debug-keys-create | `ok`: boolean; `data`: object; `data.debug_key`: object; `data.env_file`: string; `data.debug_key` β†’ `key_metadata`; `data.debug_key` β†’ `debug_key` |
364
+ | `debug-keys list` / debug-keys-list | `ok`: boolean; `data`: object; `data.debug_keys`: array; `data.debug_keys[]` β†’ `key_metadata`; `data.debug_keys[]` β†’ `debug_key` |
365
+ | `debug-keys revoke` / debug-keys-revoke | `ok`: boolean; `data`: object; `data.debug_key`: object; `data.debug_key` β†’ `key_metadata`; `data.debug_key` β†’ `debug_key` |
366
+
367
+ | Refusal / exit class | Frozen paths |
368
+ | --- | --- |
369
+ | remote / 1 | `ok`: boolean; `error`: object; `error.code`: string; `error.message`: string |
370
+ | draft-conflict / 1 | `ok`: boolean; `error`: object; `error.code`: string; `error.message`: string; `error.details`: object; `error.details.head`: string |
371
+ | usage / 2 | `ok`: boolean; `error`: object; `error.code`: string; `error.message`: string |
372
+ | authentication / 3 | `ok`: boolean; `error`: object; `error.code`: string; `error.message`: string |
373
+ | transport / 4 | `ok`: boolean; `error`: object; `error.code`: string; `error.message`: string |
374
+
375
+ <!-- studio-cli-json:end -->
376
+
377
+ ### PowerShell (Windows)
378
+
379
+ Coding agents on Windows usually call the CLI through PowerShell. The forms below follow
380
+ PowerShell's documented rules; they have not yet been run on Windows.
381
+
382
+ ```powershell
383
+ # Configuration is process environment, as with export in sh. Take secrets from your secret
384
+ # manager rather than typing them on the command line.
385
+
386
+ # Exit status of the last native command (0-4, see above). $? is only true or false.
387
+ croche projects list --json
388
+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
389
+
390
+ # Parse --json output. Set UTF-8 first: PowerShell decodes native output with the console
391
+ # code page, which garbles non-ASCII names such as Korean project names.
392
+ [Console]::OutputEncoding = [Text.UTF8Encoding]::new()
393
+ $result = croche projects list --json | ConvertFrom-Json
394
+ $result.data
395
+
396
+ # A Windows path for --connection-file.
397
+ croche debug connect --runtime-id RUNTIME_ID --port 8792 --connection-file "$env:LOCALAPPDATA\croche\debugger\connection-8792.json"
398
+
399
+ # Stop the local debugger. Not running is also exit 0; check stopped in the output.
400
+ $stop = croche debug stop --json | ConvertFrom-Json
401
+ if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
402
+ $stop.data.stopped
403
+ croche debug stop --port 8792 --connection-file "$env:LOCALAPPDATA\croche\debugger\connection-8792.json"
404
+ ```
405
+
406
+ - **Quoting.** Single quotes are literal strings and double quotes expand `$`.
407
+ `--name "Story companion"` works unchanged. No flag takes JSON on the command line; JSON
408
+ input is always a file (`--policy-file`), written as shown above.
409
+ - **Text that contains `"`.** In pwsh 7.3 and later, `--text 'She said "go"'` reaches the
410
+ CLI intact. Windows PowerShell 5.1 and pwsh 7.2 or earlier
411
+ (`$PSNativeCommandArgumentPassing` is `Legacy`) do not escape embedded double quotes. There, write
412
+ `\"` (`--text 'She said \"go\"'`), or better, put the text in a file and pass `--text-file PATH`.
413
+ Prefer `--text-file` for any text with quotes, line breaks or `& | < > ^ %`.
414
+ - **`croche.cmd`.** npm installs `croche.ps1` and `croche.cmd`. If the execution policy blocks
415
+ `croche.ps1`, calling `croche.cmd` works, but its arguments then pass through `cmd.exe`,
416
+ which interprets `& | < > ^ %` and `"`. Use `--text-file` for free text.
417
+ - **Chaining.** pwsh 7 supports `a && b`. Windows PowerShell 5.1 does not; use
418
+ `a; if ($LASTEXITCODE -eq 0) { b }`.
419
+ - **Stopping on Windows.** `debug stop` sends the same authenticated request as on Linux and
420
+ macOS. Its fallback, for a collector that does not exit and reports the recorded process id,
421
+ uses Node's `process.kill`, which on Windows ends the process at once (no signal handler
422
+ runs). This path has been tested only with `process.platform` stubbed on Linux.
423
+ - **Paths in output.** `connectionFile` in `debug status --json`, `debug start --json` and `debug stop --json` is a
424
+ native path (`C:\...\connection.json` on Windows). JSON escapes each backslash, and
425
+ `ConvertFrom-Json` restores it.
426
+
427
+ From this repository, run `npm run test --workspace @h1r-ai/croche-cli`, `npm run typecheck --workspace @h1r-ai/croche-cli`, and `npm run build --workspace @h1r-ai/croche-cli`. Build/prepack compiles the current standalone debugger sources into `dist/debugger/server` and copies its static viewer into `dist/debugger/public`. The installed tarball has no production npm dependencies or monorepo lookup. Cloud key isolation tests are in `apps/cloud/tests/developer-keys.test.ts`. They use only in-memory accounts and never contact a provider.
428
+
429
+ ## Project configuration
430
+
431
+ Set `CROCHE_DEVELOPER_KEY` and `CROCHE_PROJECT` (or pass `--project ID`).
432
+
433
+ ```sh
434
+ croche config get -o draft.json
435
+ croche config save draft.json --note "Update instructions"
436
+ croche config list
437
+ croche config get --version 1 -o bundled.json
438
+ ```
439
+
440
+ Each save creates a content-addressed draft revision. `get` remembers the draft
441
+ head in the local CLI state directory, separately for each project and Cloud
442
+ origin; `save` uses that base unless `--base REVISION` is supplied. A conflicting
443
+ save names the new head and stops. Read the draft again and reconcile your edit.
444
+ The state contains revision ids only, and `CROCHE_CLI_STATE_DIR` may select an
445
+ absolute directory. `--base null` explicitly starts from an empty draft.
446
+
447
+ `get --revision REVISION` reads historical content. `get --version N` exports
448
+ `{version, revision, config}` for bundling and preserves the saved draft base.
449
+ Production versions are immutable and numbered. Release a candidate or roll back
450
+ by releasing older content as a new higher version in web Studio; these approvals
451
+ are human-only. Drafts are delivered only to development-key
452
+ Runtimes whose key follows drafts. Other Runtimes receive the highest compatible
453
+ released version above their bundled version, at their next open.
454
+
455
+ ### Human credential setup
456
+
457
+ Sign up in Studio, create a developer key, then run `croche login` once in
458
+ your terminal. The prompt hides the key; redirected stdin is also supported.
459
+ Never put a key in command arguments or a chat conversation. Coding agents
460
+ must ask the user to run login themselves; agents must never run login.
461
+ The CLI validates the key against Cloud before saving it.
462
+
463
+ Saved credentials live in `croche/credentials.json` beneath `$XDG_CONFIG_HOME`
464
+ (or `~/.config`) on Linux, `~/Library/Application Support` on macOS, and
465
+ `%APPDATA%` inside your user profile on Windows. POSIX directories are 0700
466
+ and credential files are created 0600, with atomic replacement.
467
+ `CROCHE_DEVELOPER_KEY` overrides the saved key. `croche auth whoami --json`
468
+ shows the account, credential source (`env` or `stored`), and prefix only.
469
+ `croche logout` removes the saved credential; an environment key remains set.