sinatra.dev 0.3.0 → 0.4.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 +245 -13
- package/dist/client.js +75 -10
- package/dist/commands.js +625 -10
- package/dist/index.js +309 -17
- package/dist/oauth.js +6 -2
- package/dist/prompt.js +10 -6
- package/dist/version.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,11 @@ npm i -g sinatra.dev
|
|
|
12
12
|
sinatra --version
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
Requests made by the CLI include `x-sinatra-cli-version` with the installed package version
|
|
16
|
+
(the same value as `sinatra --version`). This identifies CLI traffic separately from direct API
|
|
17
|
+
calls, including task requests, retries, and OAuth discovery, token exchange/refresh, and revocation.
|
|
18
|
+
Browser navigation is not tagged with this header.
|
|
19
|
+
|
|
15
20
|
## Log in
|
|
16
21
|
|
|
17
22
|
```sh
|
|
@@ -50,6 +55,18 @@ sinatra login -w <workspace-id> < token-file
|
|
|
50
55
|
Without `-w`, piped input isn't asked for a workspace: set one later with `sinatra workspace <id>`.
|
|
51
56
|
A `-w` that isn't one of your workspaces is an error, and nothing is saved.
|
|
52
57
|
|
|
58
|
+
No workspace yet? Create one, then connect GitHub to it:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
sinatra workspace create "Acme"
|
|
62
|
+
sinatra connect github
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`workspace create` makes you the new workspace's owner, and your first workspace becomes the
|
|
66
|
+
default. Each person can create one workspace this way; installing the Sinatra GitHub App on
|
|
67
|
+
another account or organization makes more. If you already created one without GitHub, even one
|
|
68
|
+
since connected to GitHub, the CLI says so and nothing is created.
|
|
69
|
+
|
|
53
70
|
## Commands
|
|
54
71
|
|
|
55
72
|
```sh
|
|
@@ -58,31 +75,218 @@ sinatra "explain this" -f notes.md -f err.log # attach text files (80KB total)
|
|
|
58
75
|
sinatra reply <task-id> "also update the docs" # follow up, then follow it
|
|
59
76
|
sinatra show <task-id> # a task and its conversation
|
|
60
77
|
sinatra tasks # recent tasks in your workspace
|
|
61
|
-
sinatra stop <task-id> # stop
|
|
78
|
+
sinatra stop <task-id> # stop the running agent
|
|
62
79
|
sinatra tickets -q "flaky login" # open Linear and GitHub issues you could delegate
|
|
63
80
|
sinatra delegate ENG-123 # hand Sinatra a Linear or GitHub issue (owner/name#12, or its URL) as you
|
|
81
|
+
sinatra subscriptions # your personal model subscription connections
|
|
82
|
+
sinatra subscriptions connect codex # connect ChatGPT (also claude, xai, cursor)
|
|
83
|
+
sinatra subscriptions remove <connection-id> # disconnect one of your accounts
|
|
64
84
|
sinatra whoami # who you're logged in as, and your workspaces
|
|
85
|
+
sinatra account --json # your dashboard-visible account and linked identities
|
|
86
|
+
sinatra email-preferences # your current email preferences
|
|
87
|
+
sinatra email-preferences --setup-reminders off --task-alerts on
|
|
65
88
|
sinatra workspace [<id>] # list workspaces, or set the default
|
|
89
|
+
sinatra workspace create "<name>" # create a workspace you own
|
|
90
|
+
sinatra workspace show # connected repos, integrations, plan, model and your role
|
|
66
91
|
sinatra logout # end the sign-in (or revoke the token) and forget it
|
|
67
92
|
```
|
|
68
93
|
|
|
69
94
|
| Command | Options |
|
|
70
95
|
| --- | --- |
|
|
71
96
|
| `sinatra login` | `--no-browser`: print the sign-in URL instead of opening a browser; `--token`: paste a personal access token instead; `--api-url <url>`: another Sinatra API (https; plain http only for localhost); `-w, --workspace <id>`: the default workspace |
|
|
72
|
-
| `sinatra [start] "<what to do>"` | `-r, --repo <owner/name>`, `-f, --file <path>` (repeatable), `-t, --title <title>`, `-w, --workspace <id>`, `--timeout <minutes>`, `--no-wait`, `--json` (with `--no-wait`) |
|
|
97
|
+
| `sinatra [start] "<what to do>"` | `-r, --repo <owner/name>`, `-f, --file <path>` (repeatable), `-t, --title <title>`, `-m, --model <model>`, `-w, --workspace <id>`, `--timeout <minutes>`, `--no-wait`, `--json` (with `--no-wait`) |
|
|
73
98
|
| `sinatra reply <task-id> "<message>"` | `-f, --file <path>` (repeatable), `-w`, `--timeout <minutes>`, `--no-wait`, `--json` (with `--no-wait`) |
|
|
74
99
|
| `sinatra show <task-id>` | `-w`, `--json` |
|
|
75
100
|
| `sinatra tasks` | `--status <status>`, `-n, --limit <n>` (1 to 100, default 20), `-w`, `--json` |
|
|
76
101
|
| `sinatra stop <task-id>` | `-w` |
|
|
77
102
|
| `sinatra tickets` | `-q, --query <text>`, `-r, --repo <owner/name>` (searched first), `-w`, `--json` |
|
|
78
103
|
| `sinatra delegate <ticket>` | `-w` |
|
|
104
|
+
| `sinatra subscriptions` | `-w`, `--json` |
|
|
105
|
+
| `sinatra subscriptions connect <codex\|claude\|xai\|cursor>` | `-w`, `--json`, `--no-browser` |
|
|
106
|
+
| `sinatra subscriptions remove <connection-id>` | `-w`, `--json` |
|
|
79
107
|
| `sinatra whoami` | `--json` |
|
|
108
|
+
| `sinatra account` | `--json` |
|
|
109
|
+
| `sinatra email-preferences` | `--setup-reminders on\|off`, `--task-alerts on\|off`, `--json` |
|
|
80
110
|
| `sinatra workspace [<id>]` | none |
|
|
111
|
+
| `sinatra workspace create "<name>"` | `--json` |
|
|
112
|
+
| `sinatra workspace show` | `-w, --workspace <id>`, `--json` |
|
|
113
|
+
| `sinatra repos` | `-w`, `--json`: connected repositories from the workspace overview |
|
|
114
|
+
| `sinatra repo <owner/name> config` | `-w`, `--json`: your effective `.sinatrarc` and provenance |
|
|
115
|
+
| `sinatra repo <owner/name> config preflight` | `--file <json>` (required), `-w`, `--json` |
|
|
116
|
+
| `sinatra repo <owner/name> override set` | `--file <json>` (required), `-w`, `--json` |
|
|
117
|
+
| `sinatra repo <owner/name> override clear` | `-w`, `--json`, `--yes` / `-y` |
|
|
118
|
+
| `sinatra repo <owner/name> secrets [list]` | `-w`, `--json`: names and metadata, never values or suffixes |
|
|
119
|
+
| `sinatra repo <owner/name> secrets set <name>` | `--host <host>` (required, repeatable), `--header`, `--prefix`, `--capability-request <id>`, `-w`, `--json`; hidden prompt or stdin only |
|
|
120
|
+
| `sinatra repo <owner/name> secrets rotate <name>` | `--host <host>` (repeatable), `--header`, `--prefix`, `--capability-request <id>`, `-w`, `--json`; hidden prompt or stdin only |
|
|
121
|
+
| `sinatra repo <owner/name> secrets update <name>` | At least one of `--host <host>` (repeatable), `--header <header>`, `--prefix <prefix>`; `-w`, `--json` |
|
|
122
|
+
| `sinatra repo <owner/name> secrets delete <name>` | `-w`, `--json`, `--yes` / `-y` |
|
|
123
|
+
| `sinatra repo <owner/name> env` | `-w`, `--json`: feature-gated environment status and updates |
|
|
124
|
+
| `sinatra repo <owner/name> capability-requests` | `-w`, `--json`: feature-gated access requests |
|
|
125
|
+
| `sinatra connect <github\|linear\|slack\|telegram>` | `-w`, `--json`, `--timeout <minutes>` |
|
|
126
|
+
| `sinatra model [get]` | `-w`, `--json` |
|
|
127
|
+
| `sinatra model set <model>` | `--engine <engine>` (required), `--effort <effort>` (optional), `-w`, `--json` |
|
|
128
|
+
| `sinatra model clear` | `-w`, `--json`, `--yes` / `-y` |
|
|
129
|
+
| `sinatra keys [list]` | `-w`, `--json` |
|
|
130
|
+
| `sinatra keys add <provider>` | hidden prompt or stdin only; `-w`, `--json` |
|
|
131
|
+
| `sinatra keys remove <provider>` | `-w`, `--json`, `--yes` / `-y` |
|
|
132
|
+
| `sinatra billing` | `-w`, `--json`: plan, capacity and subscription status |
|
|
133
|
+
| `sinatra billing upgrade --plan <pro\|team\|scale>` | `-w`, `--json`: owner-only checkout |
|
|
134
|
+
| `sinatra billing portal` | `-w`, `--json`: owner-only billing management |
|
|
81
135
|
| `sinatra logout` | none |
|
|
82
136
|
| `sinatra --version`, `-v` / `sinatra --help`, `-h` | none |
|
|
83
137
|
|
|
138
|
+
### Repository settings
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
sinatra repos
|
|
142
|
+
sinatra repo acme/widget config
|
|
143
|
+
sinatra repo acme/widget config preflight --file override.json
|
|
144
|
+
sinatra repo acme/widget override set --file override.json
|
|
145
|
+
sinatra repo acme/widget override clear --yes
|
|
146
|
+
sinatra repo acme/widget secrets set REGISTRY_TOKEN --host registry.example.com
|
|
147
|
+
sinatra repo acme/widget secrets rotate REGISTRY_TOKEN < secret-file
|
|
148
|
+
sinatra repo acme/widget secrets update REGISTRY_TOKEN --header Authorization --prefix "Bearer "
|
|
149
|
+
sinatra repo acme/widget secrets delete REGISTRY_TOKEN --yes
|
|
150
|
+
sinatra repo acme/widget env --json
|
|
151
|
+
sinatra repo acme/widget capability-requests
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Repository names resolve within the selected workspace; `repos` prints the same connected
|
|
155
|
+
repository data as `workspace show`, not a second catalog. Every command accepts `-w` and
|
|
156
|
+
`--json`. Human output is readable text; JSON mode prints raw responses.
|
|
157
|
+
|
|
158
|
+
The fragment file is a JSON object directly, for example `{ "agent": { "max_turns": 42 } }`.
|
|
159
|
+
Preflight checks it without saving; override set/clear affects only your own preferences.
|
|
160
|
+
Engine and model overrides are not accepted here: use Models settings.
|
|
161
|
+
|
|
162
|
+
Members can read config, secret metadata, environment status and capability requests, and
|
|
163
|
+
manage their own overrides. Secret set, rotate, metadata update and delete require an admin
|
|
164
|
+
or owner. Secret values come only from a hidden prompt or one line on stdin, never argv or
|
|
165
|
+
flags. Set needs at least one `--host`; rotate preserves omitted metadata. Update changes
|
|
166
|
+
hosts/header/prefix without reading a value. Environment reads retain the workspace feature gate.
|
|
167
|
+
Repository secret input preserves spaces and Unicode; stdin consumes one line without its line delimiter.
|
|
168
|
+
|
|
169
|
+
Clear and delete ask for terminal confirmation; scripts require `--yes` (or `-y`).
|
|
170
|
+
Declining or running noninteractively without explicit consent sends no mutation. Prompts
|
|
171
|
+
go to stderr, including with `--json`, and piped secret input never counts as confirmation.
|
|
172
|
+
|
|
173
|
+
### Workspace models and keys
|
|
174
|
+
|
|
175
|
+
```sh
|
|
176
|
+
sinatra model # same as model get
|
|
177
|
+
sinatra model set openai-codex/gpt-6.1-sol --engine oh-my-pi
|
|
178
|
+
sinatra model clear # restore automatic selection
|
|
179
|
+
sinatra keys # same as keys list
|
|
180
|
+
sinatra keys add anthropic # hidden terminal prompt
|
|
181
|
+
sinatra keys add openrouter < key-file # one key on stdin, never argv
|
|
182
|
+
sinatra keys remove anthropic
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Members can read the saved workspace default and configured provider statuses. Only the
|
|
186
|
+
workspace owner can set or clear its default; owners and admins can add or remove workspace
|
|
187
|
+
keys. These commands use the selected workspace (`-w` overrides it) and accept `--json` for
|
|
188
|
+
the raw API response, without human-readable stdout or secret prompts mixed in.
|
|
189
|
+
|
|
190
|
+
`model clear` and `keys remove` require the same terminal confirmation as destructive access
|
|
191
|
+
commands. In scripts pass `--yes` (or `-y`); piped input is never treated as consent. Declining
|
|
192
|
+
or running noninteractively without `--yes` sends no mutation. Prompts go to stderr, including
|
|
193
|
+
with `--json`. The flag is rejected on model get/set and keys list/add.
|
|
194
|
+
|
|
195
|
+
Removing an unconfigured provider reports `No <provider> key is configured in this workspace.`
|
|
196
|
+
without error (`{}` with `--json`). A missing or inaccessible workspace is still an error,
|
|
197
|
+
not an absent-key success.
|
|
198
|
+
|
|
199
|
+
`model set` requires `--engine` so the engine/model pairing is explicit rather than guessed.
|
|
200
|
+
Choose the engine/model pairing from the dashboard's model catalog.
|
|
201
|
+
`--effort <effort>` optionally pins one of that pairing's supported effort levels; omit it to
|
|
202
|
+
leave effort automatic. The API validates the complete catalog selection, just as the
|
|
203
|
+
dashboard does. `model get` shows the saved default, not a task's effective model.
|
|
204
|
+
|
|
205
|
+
Key providers are `anthropic` and `openrouter`. Keys are read with the same hidden-input
|
|
206
|
+
mechanism as `login --token`, or as one line on stdin. Never put a key in a positional
|
|
207
|
+
argument, command flag, or shell history. Extra positionals and unknown flags are refused
|
|
208
|
+
without printing their values. Listing returns only provider and configured status; adding
|
|
209
|
+
never prints the key, and provider/network failure details are not echoed.
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
### Billing
|
|
213
|
+
|
|
214
|
+
```sh
|
|
215
|
+
sinatra billing
|
|
216
|
+
sinatra billing -w <workspace-id> --json
|
|
217
|
+
sinatra billing upgrade --plan team
|
|
218
|
+
sinatra billing portal
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Billing uses your default workspace unless you select one with `-w`. Members and admins can
|
|
222
|
+
read its status; only the workspace owner can start checkout or open the billing portal.
|
|
223
|
+
Status includes the effective capacity plan, running and queued limits, and subscription
|
|
224
|
+
state, including trial, cancellation and payment-action information when present.
|
|
225
|
+
|
|
226
|
+
Upgrade and portal commands print the billing URL before opening your system browser, so you
|
|
227
|
+
can still copy it if no browser opens (including over SSH). With `--json`, all billing commands
|
|
228
|
+
print only the raw API response and do not open a browser. If the workspace has no billing
|
|
229
|
+
account, start with `billing upgrade --plan pro` (or `team` / `scale`) rather than the portal.
|
|
230
|
+
Invalid billing commands and unsupported options fail without starting a task.
|
|
231
|
+
|
|
232
|
+
### Connect integrations
|
|
233
|
+
|
|
234
|
+
```sh
|
|
235
|
+
sinatra connect linear
|
|
236
|
+
sinatra connect github -w <workspace-id>
|
|
237
|
+
sinatra connect slack --timeout 10
|
|
238
|
+
sinatra connect telegram
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The CLI prints the URL before opening your browser, then polls `workspace show`'s
|
|
242
|
+
overview until the integration is connected or the timeout expires. Complete authorization
|
|
243
|
+
in a signed-in browser; never paste OAuth codes, tokens or cookies into CLI arguments.
|
|
244
|
+
GitHub, Linear and Slack require a workspace admin or owner. Telegram links your
|
|
245
|
+
personal account where available, independently of whether the workspace enables requests.
|
|
246
|
+
|
|
247
|
+
If no browser opens, open the printed URL manually. `--json` prints only the raw
|
|
248
|
+
`{ "url": "…" }` response, without opening a browser or polling. Check status separately
|
|
249
|
+
with `sinatra workspace show --json`.
|
|
250
|
+
|
|
251
|
+
### Workspace access
|
|
252
|
+
|
|
253
|
+
Owners can manage workspace access with the same permissions as the dashboard:
|
|
254
|
+
|
|
255
|
+
```sh
|
|
256
|
+
sinatra members list --json
|
|
257
|
+
sinatra invite colleague@example.com --role member
|
|
258
|
+
sinatra invite resend <invite-id>
|
|
259
|
+
sinatra invite revoke <invite-id>
|
|
260
|
+
sinatra requests approve <request-id> --role admin
|
|
261
|
+
sinatra requests deny <request-id>
|
|
262
|
+
sinatra members role <membership-id> --role member
|
|
263
|
+
sinatra members remove <membership-id>
|
|
264
|
+
sinatra members transfer <membership-id>
|
|
265
|
+
sinatra workspace leave
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
All these commands accept `-w <workspace-id>` and `--json`. Without `--json`, `members list`
|
|
269
|
+
shows readable sections for members, pending invitations and pending access requests, with
|
|
270
|
+
names or logins, roles and the IDs used by mutation commands. Write commands identify what
|
|
271
|
+
changed. With `--json`, responses retain the complete API data, including invitation and request history.
|
|
272
|
+
Roles granted by invites, approvals, or role changes must be `member` or `admin`; ownership
|
|
273
|
+
changes only through `members transfer`. All access commands are owner-only except
|
|
274
|
+
`workspace leave`, which members can use. Owners must transfer ownership before leaving.
|
|
275
|
+
|
|
276
|
+
Revoking an invitation, removing a member, transferring ownership, and leaving require an
|
|
277
|
+
interactive terminal confirmation. In scripts pass `--yes` (or `-y`) explicitly; without it
|
|
278
|
+
noninteractive commands fail without sending the mutation. A declined confirmation also
|
|
279
|
+
sends no mutation. Confirmation prompts go to stderr, keeping `--json` stdout machine-readable.
|
|
280
|
+
|
|
84
281
|
An option a command doesn't use is an error, not silently ignored.
|
|
85
282
|
|
|
283
|
+
`account` returns your dashboard-visible `user`, `memberships` and `linkedAccounts`, without
|
|
284
|
+
credentials or dashboard-hidden fields. `email-preferences` without flags reads your
|
|
285
|
+
`setupReminders` and `taskAlerts` booleans; flags update only the supplied preferences.
|
|
286
|
+
Values must be `on` or `off`. These are your personal preferences, shared with the email
|
|
287
|
+
preferences page linked from Sinatra emails, not workspace-wide settings. Neither command requires
|
|
288
|
+
a workspace membership or a configured default workspace, accepts `-w`, or can target another user.
|
|
289
|
+
|
|
86
290
|
- **Repository:** inside a git checkout, the task runs on its GitHub repository: the `origin`
|
|
87
291
|
remote, then `upstream`; another GitHub remote counts only when neither is on GitHub. SSH host
|
|
88
292
|
aliases from `~/.ssh/config` (like `git@github-work:owner/repo.git`) count when they point at
|
|
@@ -93,33 +297,61 @@ An option a command doesn't use is an error, not silently ignored.
|
|
|
93
297
|
second-guessed.
|
|
94
298
|
- **Attachments:** `-f` attaches text files to a new task or a reply, up to 80KB together. Binary
|
|
95
299
|
files are refused.
|
|
96
|
-
- **Following:** after `start` or `reply`, the CLI prints what Sinatra posts until the
|
|
97
|
-
|
|
98
|
-
|
|
300
|
+
- **Following:** after `start` or `reply`, the CLI prints what Sinatra posts until the agent hands
|
|
301
|
+
back: Sinatra replied, or the task finished, failed, was cancelled, or paused. If the task is
|
|
302
|
+
waiting because your workspace is running as many agents at a time as its plan allows, the CLI
|
|
99
303
|
says so. It stops waiting after `--timeout` minutes
|
|
100
304
|
(30 by default); the task keeps going. Ctrl-C stops waiting too. After a `reply` to a task that
|
|
101
305
|
had already stopped, if Sinatra hasn't picked the message up within two minutes, the CLI says so
|
|
102
|
-
(exit 3) instead of reporting the previous
|
|
306
|
+
(exit 3) instead of reporting the previous agent's result.
|
|
103
307
|
- **Prompts that start with `-`:** put them after `--`: `sinatra -- "-v is broken"`. A title that
|
|
104
308
|
starts with `-` takes the `=` form: `--title="-x title"`.
|
|
105
|
-
- **Workspace:** commands use the default workspace from login.
|
|
106
|
-
without logging in again; `-w <id>` overrides it for one command.
|
|
107
|
-
- **
|
|
108
|
-
|
|
309
|
+
- **Workspace:** task, workspace overview, access, subscription, model and keys commands use the default workspace from login.
|
|
310
|
+
`sinatra workspace <id>` changes it without logging in again; `-w <id>` overrides it for one command.
|
|
311
|
+
- **Workspace overview:** `sinatra workspace show` reads connected repositories, GitHub, Linear,
|
|
312
|
+
Slack and Telegram connection status, plan status, model default and your role. It never changes
|
|
313
|
+
settings. Any member can read it; non-members get a not-found refusal.
|
|
314
|
+
- **JSON:** `--json` prints the API's objects and nothing else, for scripts: `whoami`, `account`,
|
|
315
|
+
`email-preferences`, `tickets`, `tasks`, `show`, `workspace show`, `workspace create`, workspace access, subscription,
|
|
316
|
+
model and keys commands, and `start` or `reply` with `--no-wait`.
|
|
109
317
|
- **Prompts vs commands:** a prompt that starts with a command word still starts a task, unless it
|
|
110
318
|
has exactly that command's shape. `sinatra start "..."` always starts one.
|
|
111
319
|
- **Logout:** `sinatra logout` ends the browser sign-in on Sinatra (or revokes the token you
|
|
112
320
|
pasted), then deletes the local file. If Sinatra can't be reached, the file is still deleted and
|
|
113
321
|
the CLI warns that the sign-in or token may still be active: disconnect or revoke it on the
|
|
114
322
|
**CLI & API** page.
|
|
115
|
-
- **Retries:**
|
|
116
|
-
|
|
323
|
+
- **Retries:** task mutations carry an idempotency key, so a retry after a dropped connection
|
|
324
|
+
never starts a second task or sends a message twice. Workspace access, model default and key mutations are not
|
|
325
|
+
automatically retried after network or server failures: they may already have taken effect.
|
|
326
|
+
Check `members list` before trying again. Subscription starts and authorization-code
|
|
327
|
+
completions are also sent only once after network or server failures. Subscription polls
|
|
328
|
+
and read requests use the default retry policy (up to three attempts); a pre-action 401
|
|
329
|
+
can renew the sign-in once before sending the request again.
|
|
330
|
+
|
|
331
|
+
## Personal model subscriptions
|
|
332
|
+
|
|
333
|
+
Any workspace member can list, connect and remove their own model subscriptions. These commands
|
|
334
|
+
never expose or change another member's connections, even if you are a workspace owner.
|
|
335
|
+
|
|
336
|
+
Connecting prints the provider's URL and any device code, opens your browser, and waits for
|
|
337
|
+
approval. When the provider needs a pasted authorization code, the CLI reads it from a hidden
|
|
338
|
+
prompt or stdin, never from an argument. Keep authorization codes out of shell history and MCP
|
|
339
|
+
conversations. With `--json`, the final result is JSON on stdout; browser instructions use stderr.
|
|
340
|
+
|
|
341
|
+
Use `sinatra subscriptions --json` to get connection ids, then
|
|
342
|
+
`sinatra subscriptions remove <connection-id> --json` to disconnect one. `-w <id>` selects the
|
|
343
|
+
workspace for either command or for connecting.
|
|
344
|
+
|
|
345
|
+
The connection wait is bounded to 15 minutes. Pass `--no-browser` to open the printed URL
|
|
346
|
+
yourself; if approval expires or is denied, start a new connection flow. If ChatGPT refuses
|
|
347
|
+
device authorization, enable device-code login in its security settings at the URL printed
|
|
348
|
+
by the CLI, then connect Codex again.
|
|
117
349
|
|
|
118
350
|
## Exit codes
|
|
119
351
|
|
|
120
352
|
| Code | Meaning |
|
|
121
353
|
| --- | --- |
|
|
122
|
-
| 0 | Done: the
|
|
354
|
+
| 0 | Done: the agent handed back, or the command succeeded |
|
|
123
355
|
| 1 | Error: bad usage, not logged in, or Sinatra refused the request |
|
|
124
356
|
| 2 | The task failed, was cancelled, or is paused (billing or access) |
|
|
125
357
|
| 3 | Still working when the CLI stopped waiting (`--timeout`), or your reply wasn't picked up yet |
|
package/dist/client.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The task API (`/v1`) as the CLI uses it.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* The task API (`/v1`) as the CLI uses it. Task mutations carry an Idempotency-Key so retries
|
|
3
|
+
* cannot start duplicate tasks or messages. Workspace access mutations have no server
|
|
4
|
+
* idempotency contract and are never automatically retried after network or server failures.
|
|
5
5
|
*/
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { CLI_VERSION } from "./version.js";
|
|
8
|
+
import { ConfigError } from "./config.js";
|
|
9
|
+
import { SignInError } from "./oauth.js";
|
|
7
10
|
export class ApiError extends Error {
|
|
8
11
|
status;
|
|
9
12
|
code;
|
|
@@ -24,10 +27,9 @@ export function createClient(options) {
|
|
|
24
27
|
const attempts = options.attempts ?? RETRIES;
|
|
25
28
|
const fixed = options.token;
|
|
26
29
|
const credentials = typeof fixed === "string" ? { token: async () => fixed } : fixed;
|
|
27
|
-
async function request(method, path, body) {
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
const key = method === "GET" ? undefined : randomUUID();
|
|
30
|
+
async function request(method, path, body, retry = true) {
|
|
31
|
+
// Only retry-safe mutations rely on server-side idempotency.
|
|
32
|
+
const key = method === "GET" || !retry ? undefined : randomUUID();
|
|
31
33
|
let bearer = await credentials.token();
|
|
32
34
|
let renewed = false;
|
|
33
35
|
for (let attempt = 1;; attempt++) {
|
|
@@ -38,6 +40,7 @@ export function createClient(options) {
|
|
|
38
40
|
headers: {
|
|
39
41
|
authorization: `Bearer ${bearer}`,
|
|
40
42
|
accept: "application/json",
|
|
43
|
+
"x-sinatra-cli-version": CLI_VERSION,
|
|
41
44
|
...(body !== undefined ? { "content-type": "application/json" } : {}),
|
|
42
45
|
...(key ? { "idempotency-key": key } : {}),
|
|
43
46
|
},
|
|
@@ -46,7 +49,7 @@ export function createClient(options) {
|
|
|
46
49
|
});
|
|
47
50
|
}
|
|
48
51
|
catch (error) {
|
|
49
|
-
if (attempt < attempts) {
|
|
52
|
+
if (retry && attempt < attempts) {
|
|
50
53
|
await sleep(RETRY_DELAY_MS * attempt);
|
|
51
54
|
continue;
|
|
52
55
|
}
|
|
@@ -56,7 +59,7 @@ export function createClient(options) {
|
|
|
56
59
|
if (response.ok)
|
|
57
60
|
return payload;
|
|
58
61
|
// A token refused before it expired (revoked, or the clock is off): renew once and resend.
|
|
59
|
-
// A 401 means the server did nothing, so resending
|
|
62
|
+
// A 401 means the server did nothing, so renewing and resending is safe even without retry support.
|
|
60
63
|
if (response.status === 401 && !renewed && credentials.renew) {
|
|
61
64
|
renewed = true;
|
|
62
65
|
const next = await credentials.renew(bearer);
|
|
@@ -66,7 +69,7 @@ export function createClient(options) {
|
|
|
66
69
|
continue;
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
|
-
if (response.status >= 500 && attempt < attempts) {
|
|
72
|
+
if (retry && response.status >= 500 && attempt < attempts) {
|
|
70
73
|
await sleep(RETRY_DELAY_MS * attempt);
|
|
71
74
|
continue;
|
|
72
75
|
}
|
|
@@ -74,10 +77,67 @@ export function createClient(options) {
|
|
|
74
77
|
throw new ApiError(response.status, error ?? "request_failed", detail);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
// Provider errors can contain submitted credentials, including in their code or network cause.
|
|
81
|
+
// Keep only our public refusal vocabulary and never retain provider detail on key requests.
|
|
82
|
+
async function keyRequest(method, path, body) {
|
|
83
|
+
try {
|
|
84
|
+
return await request(method, path, body, false);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error instanceof SignInError || error instanceof ConfigError)
|
|
88
|
+
throw error;
|
|
89
|
+
const codes = ["invalid_token", "unauthorized", "not_found", "repo_not_found", "secret_not_found", "model_key_not_found", "actor_not_authorized", "unsupported_provider", "key_validation_failed", "provider_unreachable", "invalid_body", "invalid_secret_hosts", "invalid_secret_header", "invalid_secret_prefix", "invalid_secret_name", "invalid_secret_value", "secret_cap_exceeded", "capability_request_not_found", "capability_target_not_authorized", "repo_environments_not_enabled", "internal_error", "unavailable", "request_failed"];
|
|
90
|
+
if (error instanceof ApiError)
|
|
91
|
+
throw new ApiError(error.status, codes.includes(error.code) ? error.code : "request_failed");
|
|
92
|
+
throw new ApiError(503, "unavailable");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
77
95
|
return {
|
|
96
|
+
repoRequest: (workspaceId, repoId, resource, method = "GET", body) => {
|
|
97
|
+
const path = `/v1/workspaces/${encodeURIComponent(workspaceId)}/repos/${encodeURIComponent(repoId)}/${resource}`;
|
|
98
|
+
return resource === "secrets" || resource.startsWith("secrets/")
|
|
99
|
+
? keyRequest(method, path, body)
|
|
100
|
+
: request(method, path, body, method === "GET");
|
|
101
|
+
},
|
|
102
|
+
getWorkspacePrReviewSettings: (workspaceId) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/review-external-prs`),
|
|
103
|
+
setWorkspacePrReviewSettings: (workspaceId, reviewExternalPrs) => request("PUT", `/v1/workspaces/${encodeURIComponent(workspaceId)}/review-external-prs`, { reviewExternalPrs }, false),
|
|
104
|
+
integrationConnect: (workspaceId, integration) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/integrations/${integration}/connect`),
|
|
105
|
+
getModelDefault: (workspaceId) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-default`),
|
|
106
|
+
setModelDefault: (workspaceId, selection) => request("PUT", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-default`, selection, false),
|
|
107
|
+
clearModelDefault: (workspaceId) => request("DELETE", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-default`, undefined, false),
|
|
108
|
+
listModelKeys: (workspaceId) => keyRequest("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-credentials`),
|
|
109
|
+
addModelKey: (workspaceId, provider, apiKey) => keyRequest("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-credentials`, { provider, apiKey }),
|
|
110
|
+
removeModelKey: (workspaceId, provider) => keyRequest("DELETE", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-credentials/${encodeURIComponent(provider)}`),
|
|
111
|
+
planStatus: (workspaceId) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/plan-status`),
|
|
112
|
+
billingCheckout: (workspaceId, plan) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/billing/checkout`, { plan }, false),
|
|
113
|
+
billingPortal: (workspaceId) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/billing/portal`, {}, false),
|
|
114
|
+
workspaceAccess: (workspaceId, action, target, role) => {
|
|
115
|
+
const root = `/v1/workspaces/${encodeURIComponent(workspaceId)}`;
|
|
116
|
+
const id = encodeURIComponent(target ?? "");
|
|
117
|
+
const mutate = (method, path, body) => request(method, path, body, false);
|
|
118
|
+
switch (action) {
|
|
119
|
+
case "list": return request("GET", `${root}/access`);
|
|
120
|
+
case "invite": return mutate("POST", `${root}/invites`, { email: target, role });
|
|
121
|
+
case "resend": return mutate("POST", `${root}/invites/${id}/resend`);
|
|
122
|
+
case "revoke": return mutate("DELETE", `${root}/invites/${id}`);
|
|
123
|
+
case "approve": return mutate("POST", `${root}/access-requests/${id}/approve`, { role });
|
|
124
|
+
case "deny": return mutate("POST", `${root}/access-requests/${id}/deny`);
|
|
125
|
+
case "role": return mutate("PATCH", `${root}/memberships/${id}`, { role });
|
|
126
|
+
case "remove": return mutate("DELETE", `${root}/memberships/${id}`);
|
|
127
|
+
case "transfer": return mutate("POST", `${root}/memberships/${id}/transfer`);
|
|
128
|
+
case "leave": return mutate("POST", `${root}/leave`);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
78
131
|
me: () => request("GET", "/v1/me"),
|
|
132
|
+
/** Not retried: the server has no idempotency for it, and a resend after a lost reply would be refused. */
|
|
133
|
+
createWorkspace: (name) => request("POST", "/v1/workspaces", { name }, false),
|
|
134
|
+
getWorkspace: (workspaceId) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}`),
|
|
79
135
|
/** Revokes the token this client authenticates with. */
|
|
80
136
|
revokeToken: () => request("DELETE", "/v1/me/token"),
|
|
137
|
+
account: () => request("GET", "/v1/me/account"),
|
|
138
|
+
emailPreferences: (changes = {}) => Object.keys(changes).length === 0
|
|
139
|
+
? request("GET", "/v1/me/email-preferences")
|
|
140
|
+
: request("PATCH", "/v1/me/email-preferences", changes),
|
|
81
141
|
listTasks: (workspaceId, query = {}) => {
|
|
82
142
|
const params = new URLSearchParams();
|
|
83
143
|
if (query.status)
|
|
@@ -102,5 +162,10 @@ export function createClient(options) {
|
|
|
102
162
|
return request("GET", `/v1/workspaces/${workspaceId}/tickets${qs ? `?${qs}` : ""}`);
|
|
103
163
|
},
|
|
104
164
|
delegateTicket: (workspaceId, ticket) => request("POST", `/v1/workspaces/${workspaceId}/tickets/delegate`, ticket),
|
|
165
|
+
listSubscriptions: (workspaceId) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/subscriptions`),
|
|
166
|
+
removeSubscription: (workspaceId, connectionId) => request("DELETE", `/v1/workspaces/${encodeURIComponent(workspaceId)}/subscriptions/${encodeURIComponent(connectionId)}`),
|
|
167
|
+
startSubscription: (workspaceId, provider) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/subscriptions/${provider}/start`, undefined, false),
|
|
168
|
+
pollSubscription: (workspaceId, provider, body) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/subscriptions/${provider}/poll`, body),
|
|
169
|
+
completeSubscription: (workspaceId, body) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/subscriptions/claude/complete`, body, false),
|
|
105
170
|
};
|
|
106
171
|
}
|