@h1r-ai/croche-cli 0.5.5 → 0.6.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.
Files changed (44) hide show
  1. package/README.md +267 -148
  2. package/THIRD-PARTY-NOTICES +7 -8
  3. package/dist/bin.js +29 -25
  4. package/dist/chunk-66EUX7EL.js +165 -0
  5. package/dist/chunk-DKT5HHSB.js +532 -0
  6. package/dist/chunk-K3UDT4EM.js +3110 -0
  7. package/dist/collector-credential.d.ts +9 -0
  8. package/dist/config-authoring.d.ts +19 -0
  9. package/dist/config-bases.d.ts +17 -0
  10. package/dist/config-push-base-35HX67AJ.js +2254 -0
  11. package/dist/config-push-base.d.ts +7 -0
  12. package/dist/control-address.d.ts +2 -0
  13. package/dist/control-server.d.ts +12 -15
  14. package/dist/control-server.js +9 -288
  15. package/dist/control-v2-auth.d.ts +24 -0
  16. package/dist/control-v2-capture.d.ts +34 -0
  17. package/dist/control-v2-json.d.ts +15 -0
  18. package/dist/control-v2-state.d.ts +90 -0
  19. package/dist/credentials.d.ts +2 -2
  20. package/dist/debugger/public/index.html +1 -0
  21. package/dist/debugger/public/stage-control.js +84 -0
  22. package/dist/debugger/public/stage-manifest.js +45 -0
  23. package/dist/debugger/public/stage-model.js +103 -0
  24. package/dist/debugger/public/stage-targets.js +18 -0
  25. package/dist/debugger/public/stage.css +459 -0
  26. package/dist/debugger/public/stage.html +17 -0
  27. package/dist/debugger/public/stage.js +113 -0
  28. package/dist/debugger/server/collector.js +42 -26
  29. package/dist/debugger/server/control-bridge.js +113 -0
  30. package/dist/debugger/server/server.js +10 -1
  31. package/dist/debugger/server/viewer-security.js +12 -0
  32. package/dist/debugger.d.ts +16 -6
  33. package/dist/index.d.ts +8 -1
  34. package/dist/index.js +17 -321
  35. package/dist/json-result.d.ts +2 -0
  36. package/package.json +2 -1
  37. package/dist/config.js +0 -100
  38. package/dist/control-client.js +0 -65
  39. package/dist/core-defaults.js +0 -2
  40. package/dist/credentials.js +0 -136
  41. package/dist/debug-keys.js +0 -141
  42. package/dist/debugger.js +0 -469
  43. package/dist/help.js +0 -158
  44. package/dist/text-file.js +0 -15
package/README.md CHANGED
@@ -10,106 +10,107 @@ croche projects --help
10
10
 
11
11
  ## Debug a running app
12
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
- account 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:
13
+ Run the backend on the runtime's device (Node 22+):
29
14
 
30
15
  ```sh
16
+ croche debug start
31
17
  croche debug runtimes
32
- croche debug connect --runtime-id RUNTIME_ID
33
- croche debug disconnect --runtime-id RUNTIME_ID
34
- croche debug status
18
+ croche debug connect --attachment-id ATTACHMENT_ID
35
19
  ```
36
20
 
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.
21
+ The backend binds loopback by default: collector on 8790, v2 control broker on
22
+ 8791. The app must explicitly grant debugger consent:
41
23
 
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.
24
+ ```ts
25
+ await croche.debugger.attach({ url: 'http://127.0.0.1:8791', token: ingestToken })
26
+ // Revoke from the app:
27
+ await croche.debugger.detach()
28
+ ```
47
29
 
48
- Supporting commands:
30
+ Retrieve one credential explicitly (these commands print secrets; never paste
31
+ their output into logs, screenshots, source, or a shared terminal):
49
32
 
50
33
  ```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
34
+ croche debug token --role ingest --json
35
+ croche debug token --role observe --json
36
+ croche debug token --role controller --json
55
37
  ```
56
38
 
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.
39
+ The JSON result identifies the role, broker URL and token. Give only the ingest
40
+ token to your app for local development; never bundle it. Observe is read-only;
41
+ controller permits commands. `croche debug token` (or `--role pairing`) reveals
42
+ only the collector pairing token. Ordinary start/status/connect output never
43
+ prints any of these reusable credentials; connect prints a token-free viewer URL.
44
+ It can only register, poll, submit captures/results, and unregister. The distinct
45
+ controller token can read/control; scoped observe grants can only read.
46
+ Neither credential works on the other's paths. There is no remote attach command,
47
+ per-agent attach, visibility upgrade, or v1 fallback. A 15-second poll lease
48
+ determines liveness; saved captures are not evidence an agent is connected.
49
+
50
+ Bare `croche debug` lists attachments in automation and offers a TTY selection.
51
+ The viewer lists every declared/open agent and exact instance. Send/cancel target
52
+ the selected open row, including its reopen fence; reopening requires explicit
53
+ reselection. The viewer forgets control credentials on reload/navigation.
54
+ No model request bodies or private prompts appear in the public viewer.
55
+ The input-kind picker enables App event/App state only when the live Runtime
56
+ advertises both `send` and its `send.kind` modifier. Otherwise it sends user text
57
+ without a kind field. The modifier is not a separate command; inputs follow the
58
+ same content admission and limits as the App API.
59
+
60
+ `start` starts/reuses both services without clearing live captures. The collector
61
+ bridge receives only the broker's observe credential, never controller or ingest.
62
+ Imported broker files must provide a distinct observe token to start the bridge;
63
+ there is no controller fallback. `status` only reads.
64
+ `stop` authenticates shutdown to the collector, preserves its token, and only
65
+ terminates a recorded PID when the collector itself proves that PID. It does not
66
+ detach the app or stop the broker. The app owns consent.
78
67
 
79
68
  ### Observing from Studio
80
69
 
81
70
  ```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
71
+ croche debug start
72
+ croche debug --studio-link
73
+ croche debug start --studio-origin http://localhost:5173
85
74
  ```
86
75
 
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.
76
+ The one-time Studio link grants observation only. It never contains the broker
77
+ ingest/controller tokens, never grants control, and expires after ten minutes.
94
78
 
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:
79
+ ### Remote viewers (explicit opt-in)
100
80
 
101
81
  ```sh
102
- croche debug connect --runtime-id RUNTIME_ID --visibility runtime # or: croche debug --visibility runtime
82
+ croche debug start --remote 192.168.1.20 --allow-origin http://127.0.0.1:8793
103
83
  ```
104
84
 
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:
85
+ Use an IP actually assigned to the runtime device, not a wildcard bind.
86
+ Here `192.168.1.20` is the runtime device's IP; `http://127.0.0.1:8793` is
87
+ the origin serving the viewer on the OTHER machine (as seen by its browser),
88
+ not the broker destination. Replace it with the viewer's exact HTTP(S) origin.
89
+ IPv6 spellings are normalized; unspecified, loopback and mapped-loopback
90
+ addresses are refused. `--remote`/`--allow-origin` apply to `debug start` or
91
+ `control serve`, not `debug connect` or the interactive picker.
92
+ This adds a **viewer-only** broker listener at that IP on port 8791; the runtime
93
+ ingest listener stays on 127.0.0.1. A remote frontend must match the origin
94
+ allowlist and supply a separate observe/controller token. In the viewer's
95
+ connection settings, explicitly enable Remote viewer connection and enter the
96
+ broker URL and token. Captures are read through the same scoped v2 API.
97
+ HTTP is not encrypted: use a trusted network or an authenticated encrypted tunnel.
98
+ There is no anonymous remote read, token-role fallback, or remote ingest.
99
+ Changing a running broker's bind settings requires an explicit restart/new
100
+ connection file; startup never silently changes them.
101
+
102
+ For a separately served viewer, set the frontend backend's
103
+ `CROCHE_DEBUGGER_REMOTE_CONTROL_ORIGINS=http://192.168.1.20:8791` before it
104
+ starts. This is an exact IP-origin CSP allowlist; a checkbox cannot widen it.
105
+ The bundled frontend gets the matching origin automatically with `--remote`.
106
+
107
+ Simulator connections use loopback. For a real Android device, use
108
+ `adb reverse tcp:8791 tcp:8791` for the approved loopback path. Real-iOS LAN
109
+ ingest/debug-key verification is a separate opt-in and is **not implemented by
110
+ this remote-viewer option**.
111
+
112
+ The CLI stores private credentials in mode-0600 files under the OS user state
113
+ directory:
113
114
 
114
115
  - `${XDG_STATE_HOME:-~/.local/state}/croche/debugger/connection.json`
115
116
  - `${XDG_STATE_HOME:-~/.local/state}/croche/control/connection.json`
@@ -128,10 +129,15 @@ Windows retain their native defaults when `CROCHE_STATE_DIR` is unset.
128
129
  Nondefault ports use `connection-PORT.json`. `--connection-file`
129
130
  selects a debugger file; `--control-connection-file` or
130
131
  `CROCHE_CONTROL_CONNECTION_FILE` selects a broker file. Existing legacy debugger
131
- files `{url,pairedUrl,pairingToken}` and broker files `{url,token}` are accepted
132
- when private and owned by the current user. Pairing links are rebuilt from the
133
- validated URL/token; arbitrary saved links are not followed. State directory
132
+ files `{url,pairedUrl,pairingToken}` remain readable when private and owned by
133
+ the current user. Broker files require `{controlVersion:2,url,token,ingest_token}`
134
+ with distinct credentials; a legacy single-token file is refused. Token retrieval
135
+ uses validated fields only; arbitrary saved pairing links are not followed. State directory
134
136
  components must not be symlinks or writable by other users.
137
+ New files also carry a distinct `observe_token`, for explicit owner-authorized
138
+ read-only access to this backend's attachments. Never substitute `token` (control)
139
+ or `ingest_token` for it. Scoped embedding grants can restrict individual attachment
140
+ IDs. Existing Studio pairing grants remain observe-only and are not broker controls.
135
141
 
136
142
  On Windows, file modes do not exist: Node reports every writable file and
137
143
  directory as `0666`, and `0600`/`0700` are not applied. The CLI therefore skips
@@ -140,7 +146,8 @@ refused), and the connection file relies on the ACL of the user profile
140
146
  (`LOCALAPPDATA` is under it by default). A `--connection-file` or
141
147
  `CROCHE_CONTROL_CONNECTION_FILE` outside the profile gets only that folder's ACL.
142
148
 
143
- An existing `CROCHE_CONTROL_TOKEN`/`CROCHE_CONTROL_URL` may identify the same broker;
149
+ An existing `CROCHE_CONTROL_TOKEN`/`CROCHE_CONTROL_URL` plus a distinct
150
+ `CROCHE_CONTROL_INGEST_TOKEN` may identify the same broker;
144
151
  conflicting saved credentials are refused. When importing a previously running
145
152
  collector or broker, copy its existing connection file to the selected private
146
153
  path with mode 0600 before starting. An occupied port with an unknown token is
@@ -167,10 +174,25 @@ croche projects get PROJECT_ID
167
174
  croche projects update PROJECT_ID --name "New name" --policy-file policy.json
168
175
  croche projects operations PROJECT_ID --limit 100
169
176
  croche projects cost PROJECT_ID
170
- croche runtimes list --project-id PROJECT_ID
177
+ croche runtimes list --project PROJECT_ID
171
178
  ```
172
179
 
173
- New projects have a $10 monthly production budget and app access enabled.
180
+ ### Project selection
181
+
182
+ Use `--project PROJECT_ID` for project-scoped commands, or set `CROCHE_PROJECT`
183
+ as their default. These selectors do not apply to account-wide `projects list`
184
+ and `projects create`, or to offline `config build` and `config split`.
185
+
186
+ Commands that already accept a positional project id retain it as shorthand.
187
+ If both the positional id and `--project` are supplied, they must agree;
188
+ a conflict is `invalid_argument`. Other positional arguments keep their meaning:
189
+ `croche config save FILE` takes a file, not a project id. The retired
190
+ `--project-id` option is refused with a message naming `--project`.
191
+
192
+ Server-key ids use `svk_`; server-key secrets use `csk_`. An id identifies a key
193
+ for management and is not a credential. Existing stored ids remain revocable.
194
+
195
+ New projects have a 10-credit monthly production budget and app access enabled.
174
196
  Change production budgets in web Studio. Use web Studio for server-key issuance/revocation/rotation, security and attestation
175
197
  settings, allowances, project pause/archive, Runtime blocking and production promotion.
176
198
  The CLI uses only a `dk_` account key for Cloud requests; Cloud enforces its agent scope.
@@ -180,8 +202,9 @@ account; an account key does not imply a paid subscription.
180
202
  `projects update --policy-file` accepts only a JSON object with a `routing` field, for
181
203
  example `{"routing":{"mode":"preferred","providers":["openai"]}}`; `{"routing":null}` clears that override.
182
204
  Allowance, host budget control, attestation and other policy fields are refused before
183
- HTTP. Routing's provider order and quantizations remain agent-editable until they move
184
- into the snapshot. Cloud validates the routing contents and applies its fixed data policy.
205
+ HTTP. Routing's provider order remains agent-editable until it moves
206
+ into the snapshot; it is always a preference with fallback (quantizations were
207
+ retired on 2026-10-25 because OpenRouter applies them as a hard filter). Cloud validates the routing contents and applies its fixed data policy.
185
208
 
186
209
  Read-only commands still show project usage, key metadata and attestation settings.
187
210
  The all-time cost endpoint reports known cost and unresolved operation count;
@@ -197,7 +220,7 @@ The coding agent can issue and revoke debug keys with the CLI. Server credential
197
220
  # Simulators, emulators and your own devices: a debug key, used as `debugKey` in debug
198
221
  # builds only. Calls use your weekly development allowance, never Runtime Credit.
199
222
  croche debug-keys create --project PROJECT_ID
200
- # Writes CROCHE_DEBUG_KEY to ./.env without printing it. Use --env-file PATH to choose
223
+ # Writes CROCHE_DEBUG_KEY to ./.env without printing it. Use --dotenv-file PATH to choose
201
224
  # the destination. Existing values require --force; tracked files are refused.
202
225
  croche debug-keys list --project PROJECT_ID
203
226
  croche debug-keys revoke --project PROJECT_ID KEY_ID
@@ -212,6 +235,9 @@ croche attestation get PROJECT_ID
212
235
  croche projects usage PROJECT_ID --period week # week | month (default) | all
213
236
  ```
214
237
 
238
+ If `croche ... --env-file ...` exits 9, use `--dotenv-file` for the CLI destination. Node’s own `node --env-file=.env app.mjs` still loads the file into your app.
239
+
240
+
215
241
  These commands run unchanged in PowerShell: `#` starts a comment there too, so the `|` in
216
242
  the last comment is not a pipe.
217
243
 
@@ -233,62 +259,60 @@ Set-Content -Path policy.json -Value $json -Encoding UTF8
233
259
 
234
260
  ## Opt-in local Runtime control
235
261
 
236
- Set a separate `CROCHE_CONTROL_TOKEN` containing 24–4096 URL-safe characters, then start the loopback broker:
237
-
238
- ```sh
239
- croche control serve
240
- ```
241
-
242
- 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:
243
-
244
- ```ts
245
- import { attachRuntimeControl } from '@h1r-ai/croche/control';
246
-
247
- const connection = await attachRuntimeControl({
248
- runtime,
249
- token: localControlToken,
250
- tools: () => runtime.tools(),
251
- // Route through your app's normal send path to retain transcript/context rules.
252
- send: (input, { signal }) => appSend(input, { signal }),
253
- cancel: () => appCancel(),
254
- });
255
- // On app teardown:
256
- await connection.close();
257
- ```
258
-
259
- 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.
260
-
261
- 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.
262
+ Set distinct `CROCHE_CONTROL_TOKEN` and `CROCHE_CONTROL_INGEST_TOKEN` values
263
+ (24–4096 URL-safe characters), then run `croche control serve`.
264
+ App consent uses the ingest credential only. Reads/commands use the controller
265
+ credential; account keys cannot authenticate local control.
262
266
 
263
267
  ```sh
264
268
  croche runtime list
265
- croche runtime status --runtime-id RUNTIME_ID
266
- croche runtime tools --runtime-id RUNTIME_ID
267
- croche runtime history --runtime-id RUNTIME_ID --offset 0 --limit 50
268
- croche runtime send --runtime-id RUNTIME_ID --id INPUT_ID --text "Continue the story" --request-id REQUEST_ID
269
- croche runtime cancel --runtime-id RUNTIME_ID
270
- croche runtime sync --runtime-id RUNTIME_ID
271
- croche runtime budget get --runtime-id RUNTIME_ID
272
- croche runtime budget set --runtime-id RUNTIME_ID --amount 1
269
+ croche runtime agents list --attachment-id ATTACHMENT_ID
270
+ croche runtime status --attachment-id ATTACHMENT_ID --agent-id main --open-sequence 1
271
+ croche runtime history --attachment-id ATTACHMENT_ID --agent-id main --open-sequence 1 --limit 50
272
+ croche runtime send --attachment-id ATTACHMENT_ID --agent-id main --open-sequence 1 --id INPUT_ID --text "Continue"
273
+ croche runtime cancel --attachment-id ATTACHMENT_ID --agent-id main --open-sequence 1
273
274
  croche runtime result --request-id REQUEST_ID
274
275
  ```
275
276
 
276
- `--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 keys do not authenticate local control.
277
-
278
- 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.
279
-
280
- 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.
277
+ Use the exact coordinates from the current roster, including `--instance KEY`
278
+ for named instances. Omitted instance means null, never an inferred instance.
279
+ `--text-file PATH` replaces `--text`. No automatic command resend or retargeting
280
+ occurs; after uncertainty inspect the original request ID before acting.
281
+ Optional `--kind user|app_event|app_state` requires `send.kind` alongside `send`
282
+ in the live roster. Omitting it sends the original `{id,text}` payload (user).
283
+ `send.kind` is never a callable command. The CLI/broker validate shape only;
284
+ Core's canonical App API admission decides empty/oversized content refusals.
285
+ Queued work at lease expiry is known undispatched; dispatched work is uncertain.
286
+ Finished broker receipts remain in memory for 30 minutes. A broker request ID
287
+ is distinct from the SDK's durable input ID.
288
+
289
+ The CLI's local control URL precedence is `--control-url`, then
290
+ `CROCHE_CONTROL_URL`, then `http://127.0.0.1:8791`. Browser origins must be
291
+ explicitly allowed, comma-separated (quote the list in PowerShell).
292
+ Remote viewer listeners require `--remote IP --allow-origin ORIGIN`;
293
+ runtime ingest never moves to that listener.
281
294
 
282
295
  ## Automation and development
283
296
 
284
297
  `--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).
285
298
 
299
+ JSON lists use a plural noun, with metadata alongside it in `data`: for example,
300
+ `{operations: [...], has_more, next_cursor}` or `{versions: [...], draft}`.
301
+ Single results use the singular noun wrapper in `data`, including commands that
302
+ previously returned a bare object. List metadata is not moved inside that wrapper.
303
+
304
+ Local broker control commands keep `data.request`, including `request_id` and
305
+ `status`. Their list results follow the noun rule inside that record:
306
+ `data.request.result.agents`, `.history`, or `.tools`. `runtime result` uses the
307
+ same shape when inspecting that request; it does not flatten correlation fields.
308
+
286
309
  <!-- studio-cli-json:start -->
287
310
  ### Frozen Cloud JSON fields
288
311
 
289
312
  The hackathon CLI freezes the field paths and JSON types below, from
290
313
  [studio-cli-json.json](../../vectors/studio-cli-json.json). Additions are free;
291
- renames/removals require a new path alongside the old one. `[]` means every
314
+ renames/removals require a new path alongside the old one, except a retirement the founder
315
+ approves before 1.0 (2026-10-25: `routing.quantizations`, removed directly). `[]` means every
292
316
  array member; `|null` marks a nullable value. Empty lists have no members.
293
317
  Config content follows the project-config grammar, so its application fields
294
318
  are not required on every document. Local `debug`, `control` and `runtime`
@@ -308,11 +332,11 @@ uses `prefix`; project `public_key` is returned only in project views.
308
332
  | `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 |
309
333
  | `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 |
310
334
  | `plan` | `plan_id`: string; `name`: string; `ends_at`: string |
311
- | `routing` | `mode`: string; `providers`: array; `providers[]`: string; `quantizations`: array; `quantizations[]`: string |
335
+ | `routing` | `mode`: string; `providers`: array; `providers[]`: string |
312
336
  | `key_metadata` | `id`: string; `name`: string; `prefix`: string; `created_at`: string; `last_used_at`: string\|null; `revoked_at`: string\|null; `installations`: number |
313
337
  | `development_key` | `follow_draft`: boolean; `warning`: string\|null |
314
338
  | `server_key` | `spent_usd`: number |
315
- | `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 |
339
+ | `cost` | `project_id`: string; `currency`: string; `period`: string; `purpose`: string; `charged_cost_usd`: number\|null; `known_charged_cost_usd`: number; `unknown_operations`: number; `operations`: number |
316
340
  | `development_usage` | `scope`: string; `week_start`: string; `calls`: number; `unknown_calls`: number; `known_percent`: number\|null; `used_percent`: number\|null; `remaining_percent`: number\|null |
317
341
  | `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 |
318
342
  | `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 |
@@ -322,7 +346,7 @@ uses `prefix`; project `public_key` is returned only in project views.
322
346
  | `ios` | `team_id`: string; `bundle_id`: string; `allow_development`: boolean |
323
347
  | `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 |
324
348
  | `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 |
325
- | `draft` | `revision_id`: string; `schema`: number; `document`: object; `document.schema`: number; `document.config`: object; `updated_by`: string; `updated_at`: string |
349
+ | `draft` | `revision_id`: string; `schema`: number; `document`: object; `document.schema`: number; `updated_by`: string; `updated_at`: string; `document.base`: string; `document.set`: object; `document.unset`: array |
326
350
  | `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 |
327
351
  | `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 |
328
352
  | `debug_key` | `warning`: string\|null |
@@ -339,33 +363,33 @@ uses `prefix`; project `public_key` is returned only in project views.
339
363
  | `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` |
340
364
  | `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` |
341
365
  | `projects cost` / cost-unresolved | `ok`: boolean; `data`: object; `data.cost`: object; `data.cost.charged_cost_usd`: null; `data.cost` → `cost` |
342
- | `keys development list` / development-keys | `ok`: boolean; `data`: object; `data.debug_tokens`: array; `data.debug_tokens[]` → `key_metadata`; `data.debug_tokens[]` → `development_key` |
366
+ | `keys development list` / development-keys | `ok`: boolean; `data`: object; `data.debug_keys`: array; `data.debug_keys[]` → `key_metadata`; `data.debug_keys[]` → `development_key` |
343
367
  | `keys server list` / server-keys | `ok`: boolean; `data`: object; `data.server_keys`: array; `data.server_keys[]` → `key_metadata`; `data.server_keys[]` → `server_key` |
344
368
  | `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` |
345
369
  | `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` |
346
370
  | `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` |
347
371
  | `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` |
348
372
  | `runtimes list` / runtimes | `ok`: boolean; `data`: object; `data.runtimes`: array; `data.runtimes[]` → `runtime` |
349
- | `config get` / config-get-draft | `ok`: boolean; `data`: object; `data.schema`: number; `data.config`: object |
350
- | `config get` / config-get-revision | `ok`: boolean; `data`: object; `data.schema`: number; `data.config`: object |
373
+ | `config get` / config-get-draft | `ok`: boolean; `data`: object; `data.config.schema`: number; `data.config.base`: string; `data.config.set`: object; `data.config.unset`: array; `data.config`: object |
374
+ | `config get` / config-get-revision | `ok`: boolean; `data`: object; `data.config.schema`: number; `data.config.base`: string; `data.config.set`: object; `data.config.unset`: array; `data.config`: object |
351
375
  | `config get` / config-get-version | `ok`: boolean; `data`: object; `data.version`: number; `data.revision`: string; `data.config`: object |
352
- | `config get` / config-get-output | `ok`: boolean; `data`: object; `data.file`: string; `data.revision_id`: string\|null |
353
- | `config get` / config-get-version-output | `ok`: boolean; `data`: object; `data.file`: string; `data.revision_id`: string\|null; `data.version`: number |
354
- | `config save` / config-save | `ok`: boolean; `data`: object; `data.revision_id`: string; `data.created`: boolean |
376
+ | `config get` / config-get-output | `ok`: boolean; `data`: object; `data.config.file`: string; `data.config.revision_id`: string\|null; `data.config`: object |
377
+ | `config get` / config-get-version-output | `ok`: boolean; `data`: object; `data.config.file`: string; `data.config.revision_id`: string\|null; `data.config.version`: number; `data.config`: object |
378
+ | `config save` / config-save | `ok`: boolean; `data`: object; `data.config.revision_id`: string; `data.config.created`: boolean; `data.config`: object |
355
379
  | `config list` / config-list | `ok`: boolean; `data`: object; `data.versions`: array; `data.draft`: object\|null; `data.versions[]` → `version`; `data.draft` → `draft` |
356
380
  | `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` |
357
381
  | `projects operations` / empty-operations | `ok`: boolean; `data`: object; `data.operations`: array; `data.has_more`: boolean; `data.next_cursor`: null |
358
- | `keys development list` / empty-development-keys | `ok`: boolean; `data`: object; `data.debug_tokens`: array |
382
+ | `keys development list` / empty-development-keys | `ok`: boolean; `data`: object; `data.debug_keys`: array |
359
383
  | `keys server list` / empty-server-keys | `ok`: boolean; `data`: object; `data.server_keys`: array |
360
384
  | `runtimes list` / empty-runtimes | `ok`: boolean; `data`: object; `data.runtimes`: array |
361
385
  | `projects cost` / cost-known | `ok`: boolean; `data`: object; `data.cost`: object; `data.cost.charged_cost_usd`: number; `data.cost` → `cost` |
362
386
  | `projects usage` / empty-usage | `ok`: boolean; `data`: object; `data.usage`: object; `data.usage` → `usage`; `data.usage.development` → `development_usage` |
363
387
  | `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` |
364
- | `config get` / empty-config-get | `ok`: boolean; `data`: null |
365
- | `config get` / empty-config-output | `ok`: boolean; `data`: object; `data.file`: string; `data.revision_id`: null |
388
+ | `config get` / empty-config-get | `ok`: boolean; `data`: object; `data.config`: null |
389
+ | `config get` / empty-config-output | `ok`: boolean; `data`: object; `data.config.file`: string; `data.config.revision_id`: null; `data.config`: object |
366
390
  | `config list` / empty-config-list | `ok`: boolean; `data`: object; `data.versions`: array; `data.draft`: null |
367
391
  | `projects list` / empty-projects-list | `ok`: boolean; `data`: object; `data.projects`: array |
368
- | `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` |
392
+ | `debug-keys create` / debug-keys-create | `ok`: boolean; `data`: object; `data.debug_key`: object; `data.dotenv_file`: string; `data.debug_key` → `key_metadata`; `data.debug_key` → `debug_key` |
369
393
  | `debug-keys list` / debug-keys-list | `ok`: boolean; `data`: object; `data.debug_keys`: array; `data.debug_keys[]` → `key_metadata`; `data.debug_keys[]` → `debug_key` |
370
394
  | `debug-keys revoke` / debug-keys-revoke | `ok`: boolean; `data`: object; `data.debug_key`: object; `data.debug_key` → `key_metadata`; `data.debug_key` → `debug_key` |
371
395
 
@@ -399,7 +423,7 @@ $result = croche projects list --json | ConvertFrom-Json
399
423
  $result.data
400
424
 
401
425
  # A Windows path for --connection-file.
402
- croche debug connect --runtime-id RUNTIME_ID --port 8792 --connection-file "$env:LOCALAPPDATA\croche\debugger\connection-8792.json"
426
+ croche debug connect --attachment-id ATTACHMENT_ID --port 8792 --connection-file "$env:LOCALAPPDATA\croche\debugger\connection-8792.json"
403
427
 
404
428
  # Stop the local debugger. Not running is also exit 0; check stopped in the output.
405
429
  $stop = croche debug stop --json | ConvertFrom-Json
@@ -431,26 +455,99 @@ croche debug stop --port 8792 --connection-file "$env:LOCALAPPDATA\croche\debugg
431
455
 
432
456
  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.
433
457
 
458
+ ## Author configuration as files
459
+
460
+ Build and split configuration offline, without credentials or a Cloud request:
461
+
462
+ ```sh
463
+ croche config build ./config --output snapshot.json
464
+ croche config split snapshot.json --output ./config-copy
465
+ croche config save snapshot.json
466
+ ```
467
+
468
+ The authoring root contains `project.json`, using the same `{schema, config}`
469
+ document envelope as a saved snapshot. Agent layers can be inline or explicit
470
+ file references:
471
+
472
+ ```json
473
+ {
474
+ "schema": 6,
475
+ "config": {
476
+ "instructions": {"$file": "text/en/instructions.txt"},
477
+ "languages": {"fr": {"instructions": {"$file": "text/fr/instructions.txt"}}},
478
+ "agents": {"helper": {"$file": "agents/helper.json"}}
479
+ }
480
+ }
481
+ ```
482
+
483
+ `agents/helper.json` contains one config layer. References in agent files are
484
+ relative to the authoring root too. Text references work in `instructions`,
485
+ `markerGuide`, `toolGuide`, and `memory.policy`, including their agent/language
486
+ layers and mode `toolGuide`. Each reference object contains only `$file`.
487
+ References must remain inside the root: absolute paths, `.`/`..` segments,
488
+ backslashes, and symlinks that escape the root are refused. Text is UTF-8;
489
+ line endings, a text BOM and final newlines are preserved.
490
+
491
+ Only referenced files are read; application code and unreferenced files are
492
+ never scanned or executed. Configuration still follows Cloud's existing schema:
493
+ unknown fields are refused with a source file and JSON-pointer error, never
494
+ silently dropped. Opaque JSON is preserved only where today's closed grammar
495
+ explicitly permits it. Application-layer override fields are not part of the snapshot.
496
+ Errors identify the source file and JSON pointer.
497
+
498
+ The compiler owns `requires`; do not write it in authoring files. It infers any
499
+ required capabilities from the shared registry, omitting the field when empty.
500
+ Split/build and numbered version exports preserve the snapshot requirements.
501
+
502
+ Build writes the canonical snapshot document without adding release metadata or
503
+ an id field. Its `revision_id` result is `sha256:` plus the hash of those UTF-8
504
+ bytes, identical to Cloud's revision id. Split produces `project.json`, agent
505
+ files and text files; rebuilding them preserves that id. Generated filenames are
506
+ bounded numbered names (`agents/000001.json`, `text/000001.txt`), independent of
507
+ agent, mode and language ids. `manifest.json` maps these names to config pointers
508
+ and agent ids for navigation. Agent files emitted by split contain `{id, config}`;
509
+ build reads their ids from JSON and checks them against the `project.json` keys,
510
+ never deriving an id from a filename. Hand-authored plain agent layers are also
511
+ accepted. Split requires a new
512
+ output directory, and build requires a new output file; neither overwrites an
513
+ existing destination.
514
+
434
515
  ## Project configuration
435
516
 
436
517
  Set `CROCHE_ACCOUNT_KEY` and `CROCHE_PROJECT` (or pass `--project ID`).
437
518
 
438
519
  ```sh
439
- croche config get -o draft.json
520
+ croche config get --bundled-base sha256:<build-hash> -o draft.json
440
521
  croche config save draft.json --note "Update instructions"
441
- croche config list
442
- croche config get --version 1 -o bundled.json
522
+ croche config list --bundled-base sha256:<build-hash>
523
+ croche config effective --bundled-base sha256:<build-hash>
524
+ croche config get --bundled-base sha256:<build-hash> --version 1 -o patch.json
443
525
  ```
444
526
 
527
+ `effective` reads Cloud’s preview of the latest released patch applied to the selected
528
+ bundled base (or the bundle itself when no release exists). It prints the base,
529
+ patch revision, effective revision and document unchanged. Drafts and individual
530
+ runtime capability selection are outside this preview. It uses the same account
531
+ auth as `config bases` and does not save, release or update local draft state.
532
+
445
533
  Each save creates a content-addressed draft revision. `get` remembers the draft
446
- head in the local CLI state directory, separately for each project and Cloud
447
- origin; `save` uses that base unless `--base REVISION` is supplied. A conflicting
534
+ head in the local CLI state directory, separately for each project, Cloud origin
535
+ and bundled base. `--base REVISION` is the draft revision you last read (CAS);
536
+ `--bundled-base REVISION` is the build base, also selectable with `CROCHE_CONFIG_BASE`.
537
+ Without a selected build base, get/list/effective select and print the sole known base, or
538
+ refuse with the base list when there are zero or multiple known bases.
539
+ Save takes the build base only from the schema-7 patch’s `document.base`; a
540
+ conflicting flag or environment value is refused. A save uses the remembered CAS
541
+ revision unless `--base REVISION` is supplied. A conflicting
448
542
  save names the new head and stops. Read the draft again and reconcile your edit.
449
543
  The state contains revision ids only, and `CROCHE_CLI_STATE_DIR` may select an
450
544
  absolute directory. `--base null` explicitly starts from an empty draft.
451
545
 
452
546
  `get --revision REVISION` reads historical content. `get --version N` exports
453
- `{version, revision, config}` for bundling and preserves the saved draft base.
547
+ `{version, revision, config}` with the exact schema-7 patch in `config`, and
548
+ preserves the saved draft CAS revision. This is a patch export, not a bundled config;
549
+ saving that export unwraps the patch unchanged.
550
+ To make the next build, inspect `croche config effective --bundled-base <id>`, carry the released changes into your local schema-7 bundled config, and run `croche config push-base <file> --project <id>`.
454
551
  Production versions are immutable and numbered. Release a candidate or roll back
455
552
  by releasing older content as a new higher version in web Studio; these approvals
456
553
  are human-only. Drafts are delivered only to development-key
@@ -469,6 +566,28 @@ Saved credentials live in `croche/credentials.json` beneath `$XDG_CONFIG_HOME`
469
566
  (or `~/.config`) on Linux, `~/Library/Application Support` on macOS, and
470
567
  `%APPDATA%` inside your user profile on Windows. POSIX directories are 0700
471
568
  and credential files are created 0600, with atomic replacement.
472
- `CROCHE_ACCOUNT_KEY` overrides the saved key. The older name `CROCHE_DEVELOPER_KEY` is still read; if both are set to different values the CLI refuses with `invalid_configuration`. `croche auth whoami --json`
569
+ `CROCHE_ACCOUNT_KEY` overrides the saved key. The retired `CROCHE_DEVELOPER_KEY` name is ignored; use `CROCHE_ACCOUNT_KEY` or the saved login. `croche auth whoami --json`
473
570
  shows the account, credential source (`env` or `stored`), and prefix only.
474
571
  `croche logout` removes the saved credential; an environment key remains set.
572
+
573
+ Upload a bundled config as an immutable Cloud base using your account credential:
574
+
575
+ ```sh
576
+ croche config push-base ./croche.config.json --project <project-id>
577
+ ```
578
+
579
+ Core validates the bundle and its identity before upload. Repeating an exact upload is safe. This command does not publish a release or upload from a runtime. A failed upload exits nonzero and can be retried.
580
+
581
+ Inspect Cloud's bundled bases with the same account credential (including a saved
582
+ `croche login` credential):
583
+
584
+ ```sh
585
+ croche config bases --project <project-id>
586
+ croche config bases --project <project-id> --json
587
+ ```
588
+
589
+ Each base reports `revision_id`, `document_known`, `installs_7d` and
590
+ `unknown_count`. An unknown document includes a `push_base_hint` with the next
591
+ upload command. No bases is a successful empty list. JSON uses the usual CLI
592
+ success envelope with `data: {version: 1, bases: [...]}`; Cloud refusals exit
593
+ nonzero with a typed error. Debug, runtime and server keys are refused.