@r4-sdk/cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +213 -0
- package/bin/r4.js +5 -0
- package/lib/index.js +5608 -0
- package/lib/index.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# @r4-sdk/cli
|
|
2
|
+
|
|
3
|
+
Official R4 CLI -- manage vaults, projects, machine routes, and secrets from the terminal using the zero-trust Node SDK path.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @r4-sdk/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Node.js >= 18.0.0.
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
### `r4 configure`
|
|
16
|
+
Guided setup for a named CLI profile.
|
|
17
|
+
- create a brand-new agent runtime through `POST /api/v1/auth/auth/register-agent`
|
|
18
|
+
- or manually save an existing access key, secret, and private key
|
|
19
|
+
|
|
20
|
+
### `r4 agent`
|
|
21
|
+
Manage machine agents and bootstrap the local runtime.
|
|
22
|
+
- `r4 agent list` -- List visible agents
|
|
23
|
+
- `r4 agent get <id>` -- Show agent details including budget and security-group state
|
|
24
|
+
- `r4 agent create` -- Create an agent, optionally with inline permissions and a per-agent budget
|
|
25
|
+
- `r4 agent update <id>` -- Update agent name, budget, and security-group memberships
|
|
26
|
+
- `r4 agent get-tenant-roles <id>` -- Show the explicit and inherited tenant roles for an agent
|
|
27
|
+
- `r4 agent set-tenant-roles <id>` -- Replace the explicit tenant roles for an agent
|
|
28
|
+
- `r4 agent init` -- Read credentials, generate/reuse a private key, register the public key, save the profile, and run a health check
|
|
29
|
+
|
|
30
|
+
### `r4 auth`
|
|
31
|
+
Manage API key authentication.
|
|
32
|
+
- `r4 auth login` -- Save API key credentials to a named profile
|
|
33
|
+
- `r4 auth logout` -- Remove saved credentials
|
|
34
|
+
- `r4 auth register-agent` -- Public self-registration path that creates a fresh agent-only org/runtime and saves it into the selected profile
|
|
35
|
+
- `r4 auth status` -- Show current authentication state
|
|
36
|
+
- `r4 auth whoami` -- Show the current profile identity, remote machine scope/context, and policy summary via `GET /api/v1/machine/me`
|
|
37
|
+
- `r4 auth diagnose` -- Alias for `r4 doctor`
|
|
38
|
+
|
|
39
|
+
### `r4 budget`
|
|
40
|
+
Inspect and manage budgets.
|
|
41
|
+
- `r4 budget list` -- List visible budgets and their active windows
|
|
42
|
+
- `r4 budget create` -- Create a budget from inline JSON or `--body-file`
|
|
43
|
+
|
|
44
|
+
### `r4 billing`
|
|
45
|
+
Inspect billing readiness.
|
|
46
|
+
- `r4 billing readiness` -- Show whether the org has a verified domain and positive credit balance
|
|
47
|
+
|
|
48
|
+
### `r4 doctor`
|
|
49
|
+
Verify API key auth, remote machine identity, public-key registration, visible vaults, wrapped keys, and zero-trust health.
|
|
50
|
+
|
|
51
|
+
### `r4 domain`
|
|
52
|
+
Manage external domains.
|
|
53
|
+
- `r4 domain list` -- List visible external domains
|
|
54
|
+
- `r4 domain add <domain>` -- Register a new external domain and print TXT verification instructions
|
|
55
|
+
- `r4 domain verify <id>` -- Trigger TXT verification for a domain
|
|
56
|
+
|
|
57
|
+
### `r4 machine`
|
|
58
|
+
Call the headless machine API directly.
|
|
59
|
+
- `r4 machine request <method> <path> [--body <json> | --body-file <path>]` -- Send an authenticated request to any machine API route
|
|
60
|
+
|
|
61
|
+
### `r4 monitoring`
|
|
62
|
+
Inspect scoped machine monitoring summaries.
|
|
63
|
+
- `r4 monitoring entity-counts` -- Show the visible tenant/user/security-group/vault/domain/agent/project counts
|
|
64
|
+
|
|
65
|
+
### `r4 profile`
|
|
66
|
+
Manage saved CLI profiles.
|
|
67
|
+
- `r4 profile list` -- List saved profiles
|
|
68
|
+
- `r4 profile show` -- Show the active profile, identity, and managed storage paths
|
|
69
|
+
- `r4 profile use <name>` -- Switch the active profile
|
|
70
|
+
|
|
71
|
+
### `r4 space`
|
|
72
|
+
Inspect the active runtime context.
|
|
73
|
+
- `r4 space info` -- Show who the current profile is authenticated as, plus the managed storage paths
|
|
74
|
+
|
|
75
|
+
### `r4 vault`
|
|
76
|
+
Manage vault secrets.
|
|
77
|
+
- `r4 vault create` -- Create a checkpoint-signed vault from inline JSON or `--body-file`
|
|
78
|
+
- `r4 vault create-item <vaultId>` -- Create a checkpoint-signed vault item from inline JSON or `--body-file`
|
|
79
|
+
- `r4 vault list` -- List locally decrypted environment variables
|
|
80
|
+
- `r4 vault get <name>` -- Get a specific locally decrypted secret
|
|
81
|
+
- `r4 vault list-items` -- List vault item metadata without local decryption
|
|
82
|
+
- `r4 vault items --metadata-only` -- Metadata-only alias when decryption is failing
|
|
83
|
+
|
|
84
|
+
### `r4 project`
|
|
85
|
+
Manage projects.
|
|
86
|
+
- `r4 project list` -- List all projects
|
|
87
|
+
- `r4 project get <id>` -- Get project details
|
|
88
|
+
- `r4 project create` -- Create a new project
|
|
89
|
+
- `r4 project add-vault` -- Associate a vault with a project
|
|
90
|
+
- `r4 project set-agents <projectId>` -- Replace explicit project agent membership
|
|
91
|
+
|
|
92
|
+
### `r4 security-group`
|
|
93
|
+
Manage tenant security groups.
|
|
94
|
+
- `r4 security-group create` -- Create a tenant security group with delegated tenant roles
|
|
95
|
+
|
|
96
|
+
### `r4 permissions`
|
|
97
|
+
Manage asset permissions.
|
|
98
|
+
- `r4 permissions security-groups` -- List visible security groups from the permissions surface
|
|
99
|
+
- `r4 permissions set <assetType> <id>` -- Replace permissions for an asset from inline JSON or `--body-file`
|
|
100
|
+
|
|
101
|
+
### `r4 feedback`
|
|
102
|
+
Submit structured product feedback.
|
|
103
|
+
- `r4 feedback submit` -- Store AGENT feedback about missing CLI, SDK, MCP, or machine-API capability
|
|
104
|
+
|
|
105
|
+
### `r4 run <command...>`
|
|
106
|
+
Execute a command with vault secrets injected as environment variables.
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
r4 run --project-id abc123 node deploy.js
|
|
110
|
+
r4 run --prefix R4 -- docker compose up
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Global Options
|
|
114
|
+
|
|
115
|
+
| Flag | Description |
|
|
116
|
+
|--------------------|---------------------------------------------------|
|
|
117
|
+
| `--api-key <key>` | API key (overrides `R4_API_KEY` env var and config)|
|
|
118
|
+
| `--profile <name>` | CLI profile name (overrides `R4_PROFILE`) |
|
|
119
|
+
| `--project-id <id>`| Optional project filter (overrides `R4_PROJECT_ID` env var) |
|
|
120
|
+
| `--base-url <url>` | API base URL (default: `https://r4.dev`) |
|
|
121
|
+
| `--private-key-path <path>` | Path to the local agent private key PEM |
|
|
122
|
+
| `--trust-store-path <path>` | Path to the local signer trust-store JSON |
|
|
123
|
+
| `--json` | Output as JSON for scripting and piping |
|
|
124
|
+
|
|
125
|
+
## First Run
|
|
126
|
+
|
|
127
|
+
The simplest bootstrap path is:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
r4 configure
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
That guided flow can:
|
|
134
|
+
- bootstrap a brand-new agent-only org and runtime keypair
|
|
135
|
+
- or save an existing access key, secret, and private-key path
|
|
136
|
+
- write split credentials to `~/.r4/profiles/<profile>/credentials.json`
|
|
137
|
+
- default the managed key path to `~/.r4/profiles/<profile>/private-key.pem`
|
|
138
|
+
- default the trust store to `~/.r4/profiles/<profile>/trust-store.json`
|
|
139
|
+
- cache the resolved identity so `r4 profile show` / `r4 space info` can answer "who am I?" quickly
|
|
140
|
+
|
|
141
|
+
If you already have a handoff bundle and want the one-shot bootstrap path, you can still use:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
r4 agent init --credentials-file ./agent-creds.csv
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
That flow can read a CSV, `.env`, JSON, or plain-text credentials handoff, accept either a full `apiKey` or split `accessKey` + `secretKey`, register the matching public key with the machine API, save the resolved settings into the active profile, and run `r4 doctor` to confirm the runtime is healthy.
|
|
148
|
+
|
|
149
|
+
The CLI supports either `R4_API_KEY` or split `R4_ACCESS_KEY` +
|
|
150
|
+
`R4_SECRET_KEY` environment variables. Saved credentials now live in named
|
|
151
|
+
profiles, so you can switch with `r4 profile use <name>`.
|
|
152
|
+
|
|
153
|
+
The zero-trust runtime path still needs an AGENT-scoped API key plus a local
|
|
154
|
+
private key. Provide the key path via `--private-key-path`,
|
|
155
|
+
`R4_PRIVATE_KEY_PATH`, or let `r4 configure` / `r4 agent init` create the
|
|
156
|
+
default managed profile key.
|
|
157
|
+
Use `--base-url` or `R4_BASE_URL` when you need to point the CLI at a
|
|
158
|
+
non-default environment.
|
|
159
|
+
Operators should let the runtime complete that first public-key registration
|
|
160
|
+
before they assign security-group, project, or direct vault access to the
|
|
161
|
+
agent. Re-registering the same key is safe, and rotating to a different key is
|
|
162
|
+
supported when the caller submits the replacement `rewrappedVaultKeys` batch for
|
|
163
|
+
the active vault DEKs that key can reach.
|
|
164
|
+
|
|
165
|
+
When decryption is failing but API access is otherwise correct, use
|
|
166
|
+
`r4 doctor`, `r4 vault list-items`, or `r4 vault items --metadata-only` to
|
|
167
|
+
separate metadata/access problems from local key or trust issues.
|
|
168
|
+
`r4 auth whoami` is the fastest way to confirm the current machine scope,
|
|
169
|
+
tenant binding, and policy summary without exercising vault reads.
|
|
170
|
+
`r4 space info` and `r4 profile show` expose the same identity view together
|
|
171
|
+
with the credential, trust-store, and profile-directory paths.
|
|
172
|
+
`r4 machine request` is the escape hatch when the raw machine API already has a
|
|
173
|
+
route that the higher-level CLI has not wrapped yet. Common orchestration flows
|
|
174
|
+
now have first-class helpers under `budget`, `domain`, `billing`, `monitoring`,
|
|
175
|
+
and the checkpoint-signed `vault create` / `vault create-item` wrappers, but
|
|
176
|
+
use `--body-file` for large signed checkpoint or permission payloads when you
|
|
177
|
+
do drop down to the generic surface.
|
|
178
|
+
|
|
179
|
+
## Profile Storage
|
|
180
|
+
|
|
181
|
+
The CLI now keeps profile state under one consistent root:
|
|
182
|
+
|
|
183
|
+
```text
|
|
184
|
+
~/.r4/
|
|
185
|
+
config.json
|
|
186
|
+
profiles/
|
|
187
|
+
<profile>/
|
|
188
|
+
credentials.json
|
|
189
|
+
private-key.pem
|
|
190
|
+
trust-store.json
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
- `config.json` stores non-secret profile settings and cached identity metadata
|
|
194
|
+
- `credentials.json` stores split `accessKey` / `secretKey` values with owner-only permissions
|
|
195
|
+
- the default managed private key and trust store live beside those credentials
|
|
196
|
+
|
|
197
|
+
## Dependencies
|
|
198
|
+
|
|
199
|
+
Uses the published `@r4-sdk/sdk` package under the hood for API communication. Built with Commander, Chalk, ora, and cli-table3.
|
|
200
|
+
|
|
201
|
+
## Development
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
pnpm run build # Build with tsup
|
|
205
|
+
pnpm run dev # Watch mode
|
|
206
|
+
pnpm run test # Run CLI unit tests from test/
|
|
207
|
+
pnpm run test:pack # Verify npm publish excludes src/ and test/
|
|
208
|
+
pnpm run clean # Remove lib/
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
The published CLI only ships the allowlisted `lib/` and `bin/` outputs from
|
|
212
|
+
`package.json#files`. Source files under `src/` and package-local tests under
|
|
213
|
+
`test/` stay out of the npm tarball.
|