@h1r-ai/croche-cli 0.5.0 → 0.5.1

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 CHANGED
@@ -5,7 +5,7 @@
5
5
  ```sh
6
6
  npm install --global @h1r-ai/croche-cli
7
7
  croche --help
8
- croche projects --help --json
8
+ croche projects --help
9
9
  ```
10
10
 
11
11
  ## Debug a running app
@@ -22,16 +22,16 @@ Runtime by number. The CLI starts or reuses the bundled debugger, attaches that
22
22
  Runtime through its advertised `debug.attach` capability, and prints a viewer
23
23
  link filtered to that Runtime. It preserves the existing conversation and any
24
24
  captures already held by the running debugger. This requires no Cloud account,
25
- developer key, provider key, or separate debugger installation.
25
+ account key, provider key, or separate debugger installation.
26
26
 
27
27
  For automation, the bare command returns the available Runtime list without
28
28
  prompting or choosing automatically. Use an explicit ID to connect:
29
29
 
30
30
  ```sh
31
- croche debug runtimes --json
31
+ croche debug runtimes
32
32
  croche debug connect --runtime-id RUNTIME_ID
33
33
  croche debug disconnect --runtime-id RUNTIME_ID
34
- croche debug status --json
34
+ croche debug status
35
35
  ```
36
36
 
37
37
  `connect` attaches the selected Runtime before returning the standalone server's
@@ -152,25 +152,25 @@ collector; no command stops the broker or rotates a token.
152
152
 
153
153
  ## Account and project commands
154
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.
155
+ Create an account 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_ACCOUNT_KEY` remains an optional environment override. The CLI connects to Croche automatically. Credentials are never command arguments or URL parameters.
156
156
 
157
157
  ```sh
158
- croche auth whoami --json
158
+ croche auth whoami
159
159
  croche projects list
160
160
  croche projects create --name "Story companion"
161
161
  croche projects get PROJECT_ID
162
162
  croche projects update PROJECT_ID --name "New name" --policy-file policy.json
163
163
  croche projects operations PROJECT_ID --limit 100
164
- croche projects cost PROJECT_ID --json
164
+ croche projects cost PROJECT_ID
165
165
  croche runtimes list --project-id PROJECT_ID
166
166
  ```
167
167
 
168
168
  New projects have a $10 monthly production budget and app access enabled.
169
169
  Change production budgets in web Studio. Use web Studio for server-key issuance/revocation/rotation, security and attestation
170
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.
171
+ The CLI uses only a `dk_` account key for Cloud requests; Cloud enforces its agent scope.
172
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.
173
+ account; an account key does not imply a paid subscription.
174
174
 
175
175
  `projects update --policy-file` accepts only a JSON object with a `routing` field, for
176
176
  example `{"routing":{"mode":"preferred","providers":["openai"]}}`; `{"routing":null}` clears that override.
@@ -185,7 +185,7 @@ issuance and revocation are available only in web Studio.
185
185
 
186
186
  ## App credentials, attestation and usage
187
187
 
188
- Inspect credential metadata, attestation and usage with the developer key.
188
+ Inspect credential metadata, attestation and usage with the account key.
189
189
  The coding agent can issue and revoke debug keys with the CLI. Server credentials and attestation changes stay in web Studio.
190
190
 
191
191
  ```sh
@@ -256,7 +256,7 @@ For a browser reload, pass `registrationTimeoutMs: 20000` to wait for the old at
256
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
257
 
258
258
  ```sh
259
- croche runtime list --json
259
+ croche runtime list
260
260
  croche runtime status --runtime-id RUNTIME_ID
261
261
  croche runtime tools --runtime-id RUNTIME_ID
262
262
  croche runtime history --runtime-id RUNTIME_ID --offset 0 --limit 50
@@ -265,10 +265,10 @@ croche runtime cancel --runtime-id RUNTIME_ID
265
265
  croche runtime sync --runtime-id RUNTIME_ID
266
266
  croche runtime budget get --runtime-id RUNTIME_ID
267
267
  croche runtime budget set --runtime-id RUNTIME_ID --amount 1
268
- croche runtime result --request-id REQUEST_ID --json
268
+ croche runtime result --request-id REQUEST_ID
269
269
  ```
270
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.
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 keys do not authenticate local control.
272
272
 
273
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
274
 
@@ -428,7 +428,7 @@ From this repository, run `npm run test --workspace @h1r-ai/croche-cli`, `npm ru
428
428
 
429
429
  ## Project configuration
430
430
 
431
- Set `CROCHE_DEVELOPER_KEY` and `CROCHE_PROJECT` (or pass `--project ID`).
431
+ Set `CROCHE_ACCOUNT_KEY` and `CROCHE_PROJECT` (or pass `--project ID`).
432
432
 
433
433
  ```sh
434
434
  croche config get -o draft.json
@@ -454,7 +454,7 @@ released version above their bundled version, at their next open.
454
454
 
455
455
  ### Human credential setup
456
456
 
457
- Sign up in Studio, create a developer key, then run `croche login` once in
457
+ Sign up in Studio, create an account key, then run `croche login` once in
458
458
  your terminal. The prompt hides the key; redirected stdin is also supported.
459
459
  Never put a key in command arguments or a chat conversation. Coding agents
460
460
  must ask the user to run login themselves; agents must never run login.
@@ -464,6 +464,6 @@ Saved credentials live in `croche/credentials.json` beneath `$XDG_CONFIG_HOME`
464
464
  (or `~/.config`) on Linux, `~/Library/Application Support` on macOS, and
465
465
  `%APPDATA%` inside your user profile on Windows. POSIX directories are 0700
466
466
  and credential files are created 0600, with atomic replacement.
467
- `CROCHE_DEVELOPER_KEY` overrides the saved key. `croche auth whoami --json`
467
+ `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`
468
468
  shows the account, credential source (`env` or `stored`), and prefix only.
469
469
  `croche logout` removes the saved credential; an environment key remains set.
@@ -1,6 +1,10 @@
1
1
  export type CredentialEnv = Record<string, string | undefined>;
2
2
  export declare const validCredential: (key: string) => boolean;
3
3
  export declare function credentialPath(env: CredentialEnv, platform?: NodeJS.Platform, home?: string): string;
4
+ /** The account key from CROCHE_ACCOUNT_KEY, or from its older name CROCHE_DEVELOPER_KEY. Both set to different values is refused. */
5
+ export declare function environmentCredential(env: CredentialEnv): string | undefined;
6
+ /** The environment variables that currently hold an account key, newest name first. */
7
+ export declare function environmentCredentialNames(env: CredentialEnv): string[];
4
8
  export declare function resolveCredential(env: CredentialEnv): Promise<{
5
9
  key: string;
6
10
  source: 'env' | 'stored';
@@ -19,12 +19,24 @@ export function credentialPath(env, platform = process.platform, home = env.HOME
19
19
  throw new CliError('invalid_configuration', 'The configuration directory must be absolute.');
20
20
  return path.join(root, 'croche', 'credentials.json');
21
21
  }
22
+ /** The account key from CROCHE_ACCOUNT_KEY, or from its older name CROCHE_DEVELOPER_KEY. Both set to different values is refused. */
23
+ export function environmentCredential(env) {
24
+ const current = env.CROCHE_ACCOUNT_KEY, older = env.CROCHE_DEVELOPER_KEY;
25
+ if (current !== undefined && older !== undefined && current !== older)
26
+ throw new CliError('invalid_configuration', 'CROCHE_ACCOUNT_KEY and CROCHE_DEVELOPER_KEY are both set and differ; unset one.');
27
+ return current ?? older;
28
+ }
29
+ /** The environment variables that currently hold an account key, newest name first. */
30
+ export function environmentCredentialNames(env) {
31
+ return ['CROCHE_ACCOUNT_KEY', 'CROCHE_DEVELOPER_KEY'].filter(name => env[name] !== undefined);
32
+ }
22
33
  export async function resolveCredential(env) {
23
34
  // An explicit environment credential always takes precedence over disk.
24
- if (env.CROCHE_DEVELOPER_KEY !== undefined) {
25
- if (!validCredential(env.CROCHE_DEVELOPER_KEY))
26
- throw new CliError('missing_credentials', 'Supply a valid developer credential.', 3);
27
- return { key: env.CROCHE_DEVELOPER_KEY, source: 'env' };
35
+ const fromEnv = environmentCredential(env);
36
+ if (fromEnv !== undefined) {
37
+ if (!validCredential(fromEnv))
38
+ throw new CliError('missing_credentials', 'Supply a valid account key.', 3);
39
+ return { key: fromEnv, source: 'env' };
28
40
  }
29
41
  const file = credentialPath(env);
30
42
  try {
@@ -89,7 +101,7 @@ export async function readCredentialInput(input = process.stdin, prompt = text =
89
101
  }
90
102
  return text.replace(/\r?\n$/, '');
91
103
  }
92
- prompt('Developer key (hidden): ');
104
+ prompt('Account key (hidden): ');
93
105
  const wasRaw = input.isRaw, wasFlowing = input.readableFlowing;
94
106
  return new Promise((resolve, reject) => {
95
107
  let text = '';
package/dist/help.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ export type HelpCommand = {
2
+ path: string;
3
+ summary: string;
4
+ positionals?: string[];
5
+ flags?: string[];
6
+ switches?: string[];
7
+ };
8
+ type Row = {
9
+ label: string;
10
+ brief: string;
11
+ paths: string[];
12
+ };
13
+ /** Every command appears in exactly one row (the help tests census this). */
14
+ export declare const sections: readonly {
15
+ title: string;
16
+ rows: readonly Row[];
17
+ }[];
18
+ /** `croche --help`: every section, one aligned line per command. */
19
+ export declare function overview(): string;
20
+ /** `croche <command> --help`: usage, what it does, one line per option. */
21
+ export declare function commandHelp(command: HelpCommand): string;
22
+ /** `croche <group> --help`, such as `croche debug --help`: the group's commands. */
23
+ export declare function groupHelp(prefix: string, group: readonly HelpCommand[]): string;
24
+ export {};
package/dist/help.js ADDED
@@ -0,0 +1,158 @@
1
+ // Help text for people: plain text within 80 columns, no colour. Command names and flags
2
+ // come from the command table in index.ts; this file only groups and words them.
3
+ const runtimeActions = ['list', 'status', 'history', 'send', 'cancel', 'sync', 'tools', 'budget get', 'budget set', 'result'];
4
+ const row = (path, brief) => ({ label: path, brief, paths: [path] });
5
+ /** Every command appears in exactly one row (the help tests census this). */
6
+ export const sections = [
7
+ { title: 'Getting started', rows: [
8
+ row('login', 'Save your account key (typed at a hidden prompt)'),
9
+ row('logout', 'Remove the saved account key'),
10
+ row('auth whoami', 'Show your account and where the key comes from'),
11
+ ] },
12
+ { title: 'Projects', rows: [
13
+ row('projects list', 'List your projects'),
14
+ row('projects create', 'Create a project with a $10 monthly budget'),
15
+ row('projects get', 'Show one project'),
16
+ row('projects update', 'Rename a project or change its model routing'),
17
+ row('projects usage', 'Usage per user and agent, and budget left'),
18
+ row('projects cost', 'All-time known cost'),
19
+ row('projects operations', 'Recent operations'),
20
+ row('runtimes list', 'Runtimes enrolled with Cloud for a project'),
21
+ ] },
22
+ { title: 'Keys', rows: [
23
+ row('debug-keys create', 'Issue a debug key and write it to .env'),
24
+ row('debug-keys list', 'List debug keys (no secrets)'),
25
+ row('debug-keys revoke', 'Revoke a debug key'),
26
+ row('keys development list', 'Debug keys with installs, last use, warnings'),
27
+ row('keys server list', 'Server keys with installs, last use, spend'),
28
+ row('attestation get', 'App Attest and Play Integrity settings'),
29
+ ] },
30
+ { title: 'Config', rows: [
31
+ row('config get', 'Read the draft, a revision or a version'),
32
+ row('config save', 'Save a draft over the version you last read'),
33
+ row('config list', 'Released versions and the draft'),
34
+ ] },
35
+ { title: 'Debugger (development only)', rows: [
36
+ row('debug start', 'Start the local debugger; prints a Studio link'),
37
+ row('debug', 'Pick a running app to watch (--studio-link)'),
38
+ row('debug status', 'Is the local debugger running?'),
39
+ row('debug runtimes', 'Running apps the debugger can see'),
40
+ row('debug connect', 'Attach one app and print its viewer link'),
41
+ row('debug disconnect', 'Detach the debugger from one app'),
42
+ row('debug token', 'Reveal the local pairing token'),
43
+ row('debug stop', 'Stop the local debugger'),
44
+ ] },
45
+ { title: 'Local Runtime control (advanced)', rows: [
46
+ row('control serve', 'Start the local control broker'),
47
+ { label: 'runtime <action>', brief: 'Drive a local Runtime: croche runtime --help', paths: runtimeActions.map(action => `runtime ${action}`) },
48
+ ] },
49
+ ];
50
+ const width = 24;
51
+ const line = (label, text) => ` ${label.padEnd(Math.max(width, label.length + 2))}${text}`.trimEnd();
52
+ const footer = [
53
+ 'Options',
54
+ line('-h, --help', 'Help; croche <command> --help for one command'),
55
+ line('--json', 'Machine-readable output for scripts and agents'),
56
+ line('--version', 'Print the CLI version'),
57
+ '',
58
+ 'Environment',
59
+ line('CROCHE_ACCOUNT_KEY', 'Account key, instead of croche login'),
60
+ line('CROCHE_CONTROL_TOKEN', 'Token for the local control broker'),
61
+ line('CROCHE_CONTROL_URL', 'Control broker (default http://127.0.0.1:8791)'),
62
+ '',
63
+ 'Examples',
64
+ ' croche login',
65
+ ' croche projects create --name "My app"',
66
+ ' croche debug-keys create --project <project-id>',
67
+ '',
68
+ 'Exit codes: 0 ok, 1 remote error, 2 usage or config, 3 auth, 4 network/timeout',
69
+ ];
70
+ /** `croche --help`: every section, one aligned line per command. */
71
+ export function overview() {
72
+ const body = sections.map(s => [s.title, ...s.rows.map(r => line(r.label, r.brief))].join('\n')).join('\n\n');
73
+ return ['Croche CLI: build apps on Croche from your terminal.', '', 'Usage: croche <command> [options]', '', body, '', ...footer].join('\n') + '\n';
74
+ }
75
+ const runtimeBriefs = {
76
+ 'runtime list': 'Runtimes attached to the control broker',
77
+ 'runtime status': 'Status of a local Runtime',
78
+ 'runtime history': 'Read a local Runtime\'s messages',
79
+ 'runtime send': 'Send a message to a local Runtime',
80
+ 'runtime cancel': 'Cancel a local Runtime\'s turn',
81
+ 'runtime sync': 'Sync a local Runtime with Cloud',
82
+ 'runtime tools': 'List a local Runtime\'s tools',
83
+ 'runtime budget get': 'Read a local Runtime\'s budget',
84
+ 'runtime budget set': 'Set a local Runtime\'s budget',
85
+ 'runtime result': 'Look up an earlier control request',
86
+ };
87
+ const briefs = { ...Object.fromEntries(sections.flatMap(s => s.rows.filter(r => r.paths.length === 1).map(r => [r.label, r.brief]))), ...runtimeBriefs };
88
+ // One line per flag: [value name, description]. `<path> <flag>` entries override for one command.
89
+ const flagHelp = {
90
+ project: ['ID', 'Project id'],
91
+ 'config project': ['ID', 'Project id (or set CROCHE_PROJECT)'],
92
+ 'project-id': ['ID', 'Project id'],
93
+ name: ['NAME', 'A name for the key'],
94
+ 'projects create name': ['NAME', 'Project name (required)'],
95
+ 'projects update name': ['NAME', 'New project name'],
96
+ 'env-file': ['PATH', 'Where to write CROCHE_DEBUG_KEY (default ./.env)'],
97
+ force: ['', 'Replace an existing CROCHE_DEBUG_KEY value'],
98
+ print: ['', 'Also print the key (hidden by default)'],
99
+ port: ['PORT', 'Debugger port (default 8790)'],
100
+ 'control serve port': ['PORT', 'Broker port (default 8791)'],
101
+ 'connection-file': ['PATH', 'Debugger connection file (default per OS)'],
102
+ 'control-connection-file': ['PATH', 'Control broker connection file'],
103
+ 'studio-origin': ['ORIGIN', 'A development Studio, e.g. http://localhost:5173'],
104
+ visibility: ['runtime', 'The view to attach (runtime)'],
105
+ 'studio-link': ['', 'Print a fresh one-time Studio link instead'],
106
+ 'runtime-id': ['ID', 'The Runtime to act on'],
107
+ revision: ['ID', 'Read this draft revision'],
108
+ version: ['N', 'Export released version N for bundling'],
109
+ output: ['PATH', 'Write to this file (-o PATH)'],
110
+ base: ['REVISION', 'Save over this revision (null: an empty draft)'],
111
+ note: ['TEXT', 'A note for this revision'],
112
+ 'policy-file': ['PATH', 'JSON runtime policy file'],
113
+ limit: ['N', 'How many to return (server limit 500)'],
114
+ 'runtime history limit': ['N', 'How many messages to return'],
115
+ status: ['STATUS', 'Only operations with this status'],
116
+ type: ['TYPE', 'Only operations of this type'],
117
+ query: ['TEXT', 'Only operations matching this text'],
118
+ period: ['PERIOD', 'week, month (default) or all'],
119
+ 'allow-origin': ['ORIGIN', 'Allow this browser origin (CORS is off otherwise)'],
120
+ 'control-url': ['URL', 'Broker URL (default CROCHE_CONTROL_URL, then :8791)'],
121
+ 'request-id': ['ID', 'Request id, so a retry is not sent twice'],
122
+ 'runtime result request-id': ['ID', 'The request to look up'],
123
+ 'wait-ms': ['MS', 'How long to wait (send 120000, others 15000)'],
124
+ offset: ['N', 'Skip this many messages'],
125
+ id: ['ID', 'Input id for this message'],
126
+ text: ['TEXT', 'Message text'],
127
+ 'text-file': ['PATH', 'Read the message text from a UTF-8 file'],
128
+ amount: ['AMOUNT', 'The new budget'],
129
+ };
130
+ function flagLine(path, flag) {
131
+ const [value, text] = flagHelp[`${path} ${flag}`] ?? flagHelp[`${path.split(' ')[0]} ${flag}`] ?? flagHelp[flag] ?? ['VALUE', ''];
132
+ return line(`--${flag}${value ? ' ' + value : ''}`, text);
133
+ }
134
+ function wrap(text, max = 80) {
135
+ const lines = [];
136
+ let current = '';
137
+ for (const word of text.split(' ')) {
138
+ if (current && current.length + 1 + word.length > max) {
139
+ lines.push(current);
140
+ current = word;
141
+ }
142
+ else
143
+ current = current ? current + ' ' + word : word;
144
+ }
145
+ return [...lines, current].join('\n');
146
+ }
147
+ /** `croche <command> --help`: usage, what it does, one line per option. */
148
+ export function commandHelp(command) {
149
+ const flags = [...(command.flags ?? []).filter(f => f !== 'cloud-url'), ...(command.switches ?? [])];
150
+ const usage = `Usage: croche ${command.path}${(command.positionals ?? []).map(p => ` <${p}>`).join('')}${flags.length ? ' [options]' : ''}`;
151
+ const options = flags.length ? ['', 'Options', ...flags.map(f => flagLine(command.path, f))] : [];
152
+ return [usage, '', wrap(command.summary), ...options, '', 'All commands: croche --help'].join('\n') + '\n';
153
+ }
154
+ /** `croche <group> --help`, such as `croche debug --help`: the group's commands. */
155
+ export function groupHelp(prefix, group) {
156
+ const rows = group.map(c => line(c.path, briefs[c.path] ?? ''));
157
+ return [`Commands under croche ${prefix}`, '', ...rows, '', 'Options for one command: croche <command> --help'].join('\n') + '\n';
158
+ }
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import { resolveCredential, storeCredential, removeCredential, readCredentialInput, validCredential } from './credentials.js';
1
+ import { commandHelp, groupHelp, overview } from './help.js';
2
+ import { resolveCredential, storeCredential, removeCredential, readCredentialInput, validCredential, environmentCredentialNames } from './credentials.js';
2
3
  import { configCommand } from './config.js';
3
4
  import { DEFAULT_CLOUD_URL } from './core-defaults.js';
4
5
  import { debugKeys } from './debug-keys.js';
@@ -31,21 +32,21 @@ function projectBody(args) { return args.name !== undefined ? { name: args.name
31
32
  const localCommands = ['status', 'history', 'send', 'cancel', 'sync', 'budget get', 'budget set', 'tools'];
32
33
  /** Declarative command tree: future Studio features add one descriptor. */
33
34
  export const commands = [
34
- ...['create', 'list', 'revoke'].map(action => ({ path: `debug-keys ${action}`, summary: { create: 'Issue a development key and safely write CROCHE_DEBUG_KEY to .env; the secret is hidden unless --print is explicit.', list: 'List development-key metadata without secrets.', revoke: 'Revoke a development key.' }[action], positionals: action === 'revoke' ? ['key-id'] : [], flags: ['project', ...(action === 'create' ? ['name', 'env-file'] : [])], switches: action === 'create' ? ['force', 'print'] : [], run: (a, c) => debugKeys(action, a, c) })),
35
+ ...['create', 'list', 'revoke'].map(action => ({ path: `debug-keys ${action}`, summary: { create: 'Issue a debug key and safely write CROCHE_DEBUG_KEY to .env; the secret is hidden unless --print is explicit.', list: 'List debug-key metadata without secrets.', revoke: 'Revoke a debug key.' }[action], positionals: action === 'revoke' ? ['key-id'] : [], flags: ['project', ...(action === 'create' ? ['name', 'env-file'] : [])], switches: action === 'create' ? ['force', 'print'] : [], run: (a, c) => debugKeys(action, a, c) })),
35
36
  ...['choose', 'start', 'stop', 'status', 'connect', 'disconnect', 'token', 'runtimes'].map(action => ({ path: action === 'choose' ? 'debug' : `debug ${action}`, summary: { choose: 'Discover local Runtimes and select one interactively; automation gets a list. --studio-link prints a fresh one-time Studio link instead.', start: 'Start or reuse the bundled local debugger without clearing captures, and print a one-time Studio link.', stop: 'Stop the local debugger that debug start launched (its captures are discarded); the pairing token is kept. Not running is success.', status: 'Inspect local debugger availability without printing credentials.', connect: 'Attach one Runtime and print its authenticated viewer link. --visibility runtime attaches the public view and prints a Studio link.', disconnect: 'Detach the debugger from one Runtime while retaining server captures.', token: 'Explicitly reveal the saved local debugger pairing token.', runtimes: 'List local Runtimes and their debugger capability.' }[action], flags: ['port', 'connection-file', ...(action === 'stop' ? [] : ['control-connection-file']), ...(['connect', 'disconnect'].includes(action) ? ['runtime-id'] : []), ...(['choose', 'start', 'connect'].includes(action) ? ['studio-origin'] : []), ...(['choose', 'connect'].includes(action) ? ['visibility'] : [])], switches: action === 'choose' ? ['studio-link'] : [], run: (a, c) => debugCommand(action, a, { env: c.env, fetch: c.context.fetch, selectRuntime: c.context.selectRuntime, launch: c.context.launchDebuggerService }) })),
36
37
  ...['get', 'save', 'list'].map(action => ({ path: `config ${action}`, summary: { get: 'Read the draft or one revision/version. Version exports carry their bundled version.', save: 'Save a draft against its last read base; a conflict never retries over another editor.', list: 'List released versions, applied counts, and the draft head.' }[action], positionals: action === 'save' ? ['file'] : [], flags: ['project', 'cloud-url', ...{ get: ['revision', 'version', 'output'], save: ['base', 'note'], list: [] }[action]], run: (a, c) => configCommand(action, a, { ...c, writeFile: c.context.writeFile, stderr: c.context.stderr ?? (text => process.stderr.write(text)) }) })),
37
- { path: 'login', summary: 'Human-only: validate and save a developer key from hidden terminal input or stdin. Never pass a key as an argument.', run: async (_, c) => {
38
+ { path: 'login', summary: 'Human-only: validate and save an account key from hidden terminal input or stdin. Never pass a key as an argument.', run: async (_, c) => {
38
39
  const key = await (c.context.readCredential ?? readCredentialInput)();
39
40
  if (!validCredential(key))
40
- throw new CliError('invalid_credentials', 'Supply a valid developer credential.', 3);
41
+ throw new CliError('invalid_credentials', 'Supply a valid account key.', 3);
41
42
  const account = await c.request('/api/studio/account', 'GET', undefined, key);
42
43
  const file = await storeCredential(c.env, key);
43
44
  return { account: account.account, stored_in: file };
44
45
  } },
45
- { path: 'logout', summary: 'Remove the saved developer credential; an environment credential remains set.', run: async (_, c) => {
46
+ { path: 'logout', summary: 'Remove the saved account key; a key in the environment remains set.', run: async (_, c) => {
46
47
  await removeCredential(c.env);
47
- const active = c.env.CROCHE_DEVELOPER_KEY !== undefined;
48
- return { logged_out: true, ...(active ? { notice: 'CROCHE_DEVELOPER_KEY remains set in your environment.' } : {}) };
48
+ const active = environmentCredentialNames(c.env);
49
+ return { logged_out: true, ...(active.length ? { notice: `${active.join(' and ')} ${active.length > 1 ? 'remain' : 'remains'} set in your environment.` } : {}) };
49
50
  } },
50
51
  { path: 'auth whoami', summary: 'Show your account and credential source with a prefix only.', run: async (_, c) => {
51
52
  const credential = await c.credential();
@@ -72,7 +73,7 @@ export const commands = [
72
73
  if (a[flag] !== undefined)
73
74
  query.set(flag === 'query' ? 'q' : flag, flag === 'limit' ? String(integer(a[flag], flag, 1, 500)) : a[flag]); return c.request(`${project(a)}/operations?${query}`); } },
74
75
  { path: 'projects cost', summary: 'Show all-time known cost and explicitly unresolved operations.', positionals: ['project-id'], run: (a, c) => c.request(`${project(a)}/cost`) },
75
- // Key metadata is readable with a developer key; issuance and revocation belong to web Studio.
76
+ // Key metadata is readable with an account key; issuance and revocation belong to web Studio.
76
77
  ...[['development', 'debug-tokens', 'debug key (cdt_) for simulators and your own devices'], ['server', 'server-keys', 'server key (csk_) for a web app\'s own backend']].flatMap(([kind, route]) => [
77
78
  { path: `keys ${kind} list`, summary: `List a project's ${kind === 'development' ? 'debug' : kind} keys with installations, last use${kind === 'server' ? ' and Runtime Credit spent' : ' and misuse warnings'}.`, positionals: ['project-id'], run: (a, c) => c.request(`${project(a)}/${route}`) },
78
79
  ]),
@@ -106,10 +107,16 @@ export const commands = [
106
107
  } })),
107
108
  ];
108
109
  export function help(prefix = '') {
109
- const visible = commands.filter(command => !prefix || command.path === prefix || command.path.startsWith(prefix + ' '));
110
+ if (!prefix)
111
+ return overview();
112
+ const visible = commands.filter(command => command.path === prefix || command.path.startsWith(prefix + ' '));
110
113
  if (!visible.length)
111
114
  throw new CliError('unknown_command', 'Unknown command. Run croche --help.');
112
- return `Croche CLI\n\n${visible.map(c => ` croche ${c.path}${c.positionals?.map(p => ` <${p}>`).join('') ?? ''}${c.flags?.filter(f => f !== 'cloud-url').map(f => ` [--${f} VALUE]`).join('') ?? ''}${c.switches?.map(f => ` [--${f}]`).join('') ?? ''}\n ${c.summary}`).join('\n')}\n\nGlobal: --help, --version, --json\nCloud: CROCHE_DEVELOPER_KEY\nLocal control: CROCHE_CONTROL_TOKEN; CROCHE_CONTROL_URL defaults to http://127.0.0.1:8791\nExit codes: 0 success, 1 remote failure, 2 usage/configuration, 3 authentication, 4 transport/timeout.\n`;
115
+ const exact = visible.find(command => command.path === prefix);
116
+ if (visible.length === 1 && exact)
117
+ return commandHelp(exact);
118
+ // `croche debug` is a command and a group: its own usage follows the group's list.
119
+ return groupHelp(prefix, visible) + (exact ? '\n' + commandHelp(exact) : '');
113
120
  }
114
121
  // Global flags are recognized only outside option values. Literal message text
115
122
  // such as --help or --json must reach the Runtime unchanged.
@@ -206,7 +213,7 @@ function cloudUrl(value) {
206
213
  export async function runCli(argv, context = {}) {
207
214
  const env = context.env ?? process.env, stdout = context.stdout ?? (text => process.stdout.write(text)), stderr = context.stderr ?? (text => process.stderr.write(text));
208
215
  const jsonMode = globalOptions(argv).json;
209
- const secrets = new Set([env.CROCHE_DEVELOPER_KEY, env.CROCHE_CONTROL_TOKEN].filter((value) => Boolean(value)));
216
+ const secrets = new Set([env.CROCHE_ACCOUNT_KEY, env.CROCHE_DEVELOPER_KEY, env.CROCHE_CONTROL_TOKEN].filter((value) => Boolean(value)));
210
217
  try {
211
218
  const parsed = parse(argv);
212
219
  if (parsed.help) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h1r-ai/croche-cli",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },