sinatra.dev 0.5.1 → 0.5.4
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 +84 -5
- package/dist/client.js +10 -2
- package/dist/commands.js +228 -36
- package/dist/index.js +36 -3
- package/dist/prompt.js +34 -0
- package/dist/recurring.js +132 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,8 +45,12 @@ sinatra login --token
|
|
|
45
45
|
|
|
46
46
|
Create a token on the same **CLI & API** page and paste it in; it isn't echoed.
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
With no terminal and nothing piped in, as when a coding agent runs `sinatra login` for you, it
|
|
49
|
+
signs in through the browser and prints the link. In CI (`CI` set) it asks for a token instead.
|
|
50
|
+
|
|
51
|
+
In a script, pipe the token in and name the default workspace with `-w`. Piped input reads a token
|
|
52
|
+
without `--token` when it starts within 2 seconds; for a slower source, such as a password manager
|
|
53
|
+
that asks for Touch ID, pass `--token`:
|
|
50
54
|
|
|
51
55
|
```sh
|
|
52
56
|
sinatra login -w <workspace-id> < token-file
|
|
@@ -122,7 +126,19 @@ sinatra logout # end the sign-in (or revoke the
|
|
|
122
126
|
| `sinatra repo <owner/name> secrets delete <name>` | `-w`, `--json`, `--yes` / `-y` |
|
|
123
127
|
| `sinatra repo <owner/name> env` | `-w`, `--json`: feature-gated environment status and updates |
|
|
124
128
|
| `sinatra repo <owner/name> capability-requests` | `-w`, `--json`: feature-gated access requests |
|
|
129
|
+
| `sinatra repo <owner/name> capability-requests dismiss <request-id>` | Owner/admin only; `-w`, `--json`, `--yes` / `-y` |
|
|
125
130
|
| `sinatra connect <github\|linear\|slack\|telegram>` | `-w`, `--json`, `--timeout <minutes>` |
|
|
131
|
+
| `sinatra connectors [list]` | `-w`, `--json` |
|
|
132
|
+
| `sinatra connectors connect <connector>` | Owner/admin only; `--project <ref>`, `--name <label>`, `--token` (hidden prompt or stdin only), `--accept`, `-w`, `--json` |
|
|
133
|
+
| `sinatra connectors disconnect <connection-id>` | Owner/admin only; `-w`, `--json`, `--yes` / `-y` |
|
|
134
|
+
| `sinatra recurring [list]` | `-w`, `--json` |
|
|
135
|
+
| `sinatra recurring show <id>` | `-w`, `--json`: the prompt and recent runs |
|
|
136
|
+
| `sinatra recurring create "<prompt>"` | `--at <HH:MM>` (required, repeatable up to 4), `--weekdays <mon,wed>` or `--day-of-month <1-28>`, `--timezone <zone>`, `--name <name>`, `--no-email`, `-w`, `--json` |
|
|
137
|
+
| `sinatra recurring edit <id>` | Owner only; at least one of `--prompt <prompt>` and the create flags; `-w`, `--json` |
|
|
138
|
+
| `sinatra recurring pause <id>` | Owner, or workspace owner/admin; `-w`, `--json` |
|
|
139
|
+
| `sinatra recurring resume <id>` | Owner only; `-w`, `--json` |
|
|
140
|
+
| `sinatra recurring run <id>` | Owner only; `-w`, `--json` |
|
|
141
|
+
| `sinatra recurring delete <id>` | Owner, or workspace owner/admin; `-w`, `--json`, `--yes` / `-y` |
|
|
126
142
|
| `sinatra model [get]` | `-w`, `--json` |
|
|
127
143
|
| `sinatra model set <model>` | `--engine <engine>` (required), `--effort <effort>` (optional), `-w`, `--json` |
|
|
128
144
|
| `sinatra model clear` | `-w`, `--json`, `--yes` / `-y` |
|
|
@@ -149,6 +165,7 @@ sinatra repo acme/widget secrets update REGISTRY_TOKEN --header Authorization --
|
|
|
149
165
|
sinatra repo acme/widget secrets delete REGISTRY_TOKEN --yes
|
|
150
166
|
sinatra repo acme/widget env --json
|
|
151
167
|
sinatra repo acme/widget capability-requests
|
|
168
|
+
sinatra repo acme/widget capability-requests dismiss <request-id> --yes
|
|
152
169
|
```
|
|
153
170
|
|
|
154
171
|
Repository names resolve within the selected workspace; `repos` prints the same connected
|
|
@@ -159,13 +176,22 @@ The fragment file is a JSON object directly, for example `{ "agent": { "max_turn
|
|
|
159
176
|
Preflight checks it without saving; override set/clear affects only your own preferences.
|
|
160
177
|
Engine and model overrides are not accepted here: use Models settings.
|
|
161
178
|
|
|
162
|
-
Members can read config, secret metadata, environment status and
|
|
163
|
-
manage their own overrides. Secret set, rotate, metadata update and delete
|
|
164
|
-
|
|
179
|
+
Members can read config, secret metadata, environment status and access requests, and
|
|
180
|
+
manage their own overrides. Secret set, rotate, metadata update and delete, and access request
|
|
181
|
+
dismissal require an admin or owner. Dismissal requires confirmation (or `--yes`) and keeps the
|
|
182
|
+
request dismissed on later reports of the same need. Secret values come only from a hidden
|
|
183
|
+
prompt or one line on stdin, never argv or
|
|
165
184
|
flags. Set needs at least one `--host`; rotate preserves omitted metadata. Update changes
|
|
166
185
|
hosts/header/prefix without reading a value. Environment reads retain the workspace feature gate.
|
|
167
186
|
Repository secret input preserves spaces and Unicode; stdin consumes one line without its line delimiter.
|
|
168
187
|
|
|
188
|
+
For each open or repair-needed access request, human output shows the summary, the agent's
|
|
189
|
+
reason, the command that adds the secret (when a secret can satisfy the request) and the
|
|
190
|
+
command that dismisses the request. Run the command in your own terminal; enter the secret at
|
|
191
|
+
the hidden prompt or pipe it on stdin from your secret manager. Never send the value through a
|
|
192
|
+
model, chat, command argument or flag. Tasks keep running without the secret; a saved secret is
|
|
193
|
+
used from the next agent run. A dismissed request does not come back.
|
|
194
|
+
|
|
169
195
|
Clear and delete ask for terminal confirmation; scripts require `--yes` (or `-y`).
|
|
170
196
|
Declining or running noninteractively without explicit consent sends no mutation. Prompts
|
|
171
197
|
go to stderr, including with `--json`, and piped secret input never counts as confirmation.
|
|
@@ -248,6 +274,59 @@ If no browser opens, open the printed URL manually. `--json` prints only the raw
|
|
|
248
274
|
`{ "url": "…" }` response, without opening a browser or polling. Check status separately
|
|
249
275
|
with `sinatra workspace show --json`.
|
|
250
276
|
|
|
277
|
+
### Connectors
|
|
278
|
+
|
|
279
|
+
```sh
|
|
280
|
+
sinatra connectors
|
|
281
|
+
sinatra connectors connect neon --project <project-id>
|
|
282
|
+
echo "$POSTHOG_KEY" | sinatra connectors connect posthog --token --accept
|
|
283
|
+
sinatra connectors disconnect <connection-id>
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Connectors give the workspace's agents read access to services you already use, such as Neon,
|
|
287
|
+
Supabase, PostHog, Sentry, PlanetScale, Cloudflare, Notion and Vercel, through each provider's
|
|
288
|
+
hosted MCP server. `sinatra connectors` lists the services and the workspace's connections; any
|
|
289
|
+
member can read it, and no token is ever shown.
|
|
290
|
+
|
|
291
|
+
For a service you sign in to, `connectors connect` prints a dashboard link. A workspace owner or
|
|
292
|
+
admin opens it, signs in at the provider and accepts the warning there; at a terminal the CLI
|
|
293
|
+
then waits up to 10 minutes for the connection to appear. For a service that takes a token,
|
|
294
|
+
`--token` reads it at a hidden prompt or from stdin, shows the warning and asks you to accept it;
|
|
295
|
+
`--accept` accepts it without a prompt. Never put a token on the command line. Sinatra does not
|
|
296
|
+
guarantee read-only access: what an agent can do is limited by the token or by what you approve
|
|
297
|
+
at the provider.
|
|
298
|
+
|
|
299
|
+
`connectors disconnect` removes the connection and its stored token. For a pasted token, revoke
|
|
300
|
+
it at the provider too; the CLI says when something stays authorized there.
|
|
301
|
+
See [Connectors](https://docs.sinatra.dev/docs/configuration/connectors) for each service.
|
|
302
|
+
|
|
303
|
+
### Recurring tasks
|
|
304
|
+
|
|
305
|
+
```sh
|
|
306
|
+
sinatra recurring
|
|
307
|
+
sinatra recurring create "Summarize what merged to main yesterday" --at 09:00 --weekdays mon,tue,wed,thu,fri
|
|
308
|
+
sinatra recurring create "Check dependency updates" --at 08:30 --day-of-month 1 --timezone Europe/Berlin
|
|
309
|
+
sinatra recurring edit <id> --at 10:00 --at 16:00
|
|
310
|
+
sinatra recurring run <id>
|
|
311
|
+
sinatra recurring pause <id>
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
A recurring task starts a task with the same prompt on a schedule, as the member who created it,
|
|
315
|
+
until someone pauses or deletes it. Any member can list and create them. Only the owner can edit,
|
|
316
|
+
resume or run one; the owner or a workspace owner or admin can pause or delete it. Each member can
|
|
317
|
+
have up to 10 that aren't paused in a workspace.
|
|
318
|
+
|
|
319
|
+
`create` runs every day unless you pass `--weekdays` (`sun` to `sat`, comma-separated) or
|
|
320
|
+
`--day-of-month` (1 to 28). `--at` takes a 24-hour time and can be repeated up to four times. Times
|
|
321
|
+
are in `--timezone`, an IANA zone that defaults to this computer's. The name defaults to the
|
|
322
|
+
prompt's first line. You get an email when each run's agent finishes or needs a reply; `--no-email` turns
|
|
323
|
+
that off.
|
|
324
|
+
|
|
325
|
+
`edit` changes only the flags you pass, and `--prompt` replaces the prompt. `--at` replaces the times
|
|
326
|
+
and keeps the days. `run` starts one run now without changing the schedule, even while the
|
|
327
|
+
recurring task is paused. `delete` asks for confirmation in a terminal; scripts must pass `--yes`.
|
|
328
|
+
See [Recurring tasks](https://docs.sinatra.dev/docs/configuration/recurring-tasks).
|
|
329
|
+
|
|
251
330
|
### Workspace access
|
|
252
331
|
|
|
253
332
|
Owners can manage workspace access with the same permissions as the dashboard:
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
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
|
|
4
|
-
* idempotency contract and are never
|
|
3
|
+
* cannot start duplicate tasks or messages. Workspace access and recurring-task mutations have
|
|
4
|
+
* no server idempotency contract and are never retried after network or server failures.
|
|
5
5
|
*/
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { CLI_VERSION } from "./version.js";
|
|
@@ -106,6 +106,14 @@ export function createClient(options) {
|
|
|
106
106
|
/** Carries a provider token: only in the body, and through the path that keeps no server detail. */
|
|
107
107
|
connectConnector: (workspaceId, body) => keyRequest("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/connectors`, body),
|
|
108
108
|
disconnectConnector: (workspaceId, connectionId) => request("DELETE", `/v1/workspaces/${encodeURIComponent(workspaceId)}/connectors/${encodeURIComponent(connectionId)}`, undefined, false),
|
|
109
|
+
listRecurringTasks: (workspaceId) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/recurring-tasks`),
|
|
110
|
+
getRecurringTask: (workspaceId, taskId) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/recurring-tasks/${encodeURIComponent(taskId)}`),
|
|
111
|
+
createRecurringTask: (workspaceId, body) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/recurring-tasks`, body, false),
|
|
112
|
+
updateRecurringTask: (workspaceId, taskId, body) => request("PATCH", `/v1/workspaces/${encodeURIComponent(workspaceId)}/recurring-tasks/${encodeURIComponent(taskId)}`, body, false),
|
|
113
|
+
pauseRecurringTask: (workspaceId, taskId) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/recurring-tasks/${encodeURIComponent(taskId)}/pause`, undefined, false),
|
|
114
|
+
resumeRecurringTask: (workspaceId, taskId) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/recurring-tasks/${encodeURIComponent(taskId)}/resume`, undefined, false),
|
|
115
|
+
runRecurringTask: (workspaceId, taskId) => request("POST", `/v1/workspaces/${encodeURIComponent(workspaceId)}/recurring-tasks/${encodeURIComponent(taskId)}/run`, undefined, false),
|
|
116
|
+
deleteRecurringTask: (workspaceId, taskId) => request("DELETE", `/v1/workspaces/${encodeURIComponent(workspaceId)}/recurring-tasks/${encodeURIComponent(taskId)}`, undefined, false),
|
|
109
117
|
getModelDefault: (workspaceId) => request("GET", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-default`),
|
|
110
118
|
setModelDefault: (workspaceId, selection) => request("PUT", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-default`, selection, false),
|
|
111
119
|
clearModelDefault: (workspaceId) => request("DELETE", `/v1/workspaces/${encodeURIComponent(workspaceId)}/model-default`, undefined, false),
|
package/dist/commands.js
CHANGED
|
@@ -26,10 +26,10 @@ export class UsageError extends Error {
|
|
|
26
26
|
const TASK_ID = /^[a-z0-9][a-z0-9_-]{19,63}$/;
|
|
27
27
|
const SUBSCRIPTIONS_USAGE = "Usage: sinatra subscriptions [list | connect <codex|claude|xai|cursor> | remove <id>] [--json] [-w <id>]. Paste Claude's authorization code at the hidden prompt or through stdin, never on the command line.";
|
|
28
28
|
const CONNECT_USAGE = "Usage: sinatra connect <github|linear|slack|telegram> [-w <id>] [--timeout <minutes>] [--json]. Authorization happens in your browser; never supply secrets on the command line.";
|
|
29
|
-
// Connectors are unlisted: this is the only place the group's usage is said, and USAGE never names it.
|
|
30
29
|
const CONNECTORS_USAGE = "Usage: sinatra connectors [list | connect <connector> [--project <ref>] [--name <label>] [--token] [--accept] | disconnect <connection-id> [--yes]] [-w <id>] [--json]. --project is needed only by services that take a project reference. Without --token or --accept, a service you can sign in to gives a link to the dashboard, where a workspace owner or admin signs in and accepts the warning; --token, or --accept to accept the terms without a prompt, pastes a token instead, for a service that takes one. Paste a token at the hidden prompt or pipe it on stdin, never on the command line.";
|
|
31
30
|
const WORKSPACE_CREATE_USAGE = 'Usage: sinatra workspace create "<name>" [--json]. Quote a name with spaces.';
|
|
32
|
-
const REPO_USAGE = "Usage: sinatra repo <owner/name> config [preflight --file <json>] | override set --file <json> | override clear [--yes] | secrets [list | set <name> --host <host> | rotate <name> | update <name> | delete <name> --yes] | env | capability-requests | review-external-prs [inherit|on|off] [-w <id>] [--json]. Secret values belong only at the hidden prompt or on stdin, never in arguments or flags.";
|
|
31
|
+
const REPO_USAGE = "Usage: sinatra repo <owner/name> config [preflight --file <json>] | override set --file <json> | override clear [--yes] | secrets [list | set <name> --host <host> | rotate <name> | update <name> | delete <name> --yes] | env | capability-requests [dismiss <request-id> [--yes]] | review-external-prs [inherit|on|off] [-w <id>] [--json]. Secret values belong only at the hidden prompt or on stdin, never in arguments or flags.";
|
|
32
|
+
const RECURRING_USAGE = 'Usage: sinatra recurring [list | show <id> | create "<prompt>" --at <HH:MM> [--at <HH:MM> …] | edit <id> [--prompt <prompt>] | pause <id> | resume <id> | run <id> | delete <id> [--yes]] [--weekdays mon,wed | --day-of-month <1-28>] [--timezone <IANA zone>] [--name <name>] [--no-email] [-w <id>] [--json].';
|
|
33
33
|
/** The help text. Unlisted command groups stay out of it. */
|
|
34
34
|
export const USAGE = `Usage:
|
|
35
35
|
sinatra login [--api-url <url>] [-w <id>] [--no-browser | --token]
|
|
@@ -43,7 +43,7 @@ export const USAGE = `Usage:
|
|
|
43
43
|
-f, --file <path> Attach a text file (repeatable, 80KB total)
|
|
44
44
|
-t, --title <title> Task title (default: the prompt's first line)
|
|
45
45
|
-m, --model <model> Model for every agent, such as openai-codex/gpt-6.1-sol
|
|
46
|
-
(default:
|
|
46
|
+
(default: your default or the workspace default)
|
|
47
47
|
--timeout <minutes> Stop following after this long (default 30)
|
|
48
48
|
--no-wait Start it and return
|
|
49
49
|
--json With --no-wait: print the started task as JSON
|
|
@@ -91,12 +91,14 @@ export const USAGE = `Usage:
|
|
|
91
91
|
PATCH metadata without changing the secret value
|
|
92
92
|
--host <host> Allowed host (repeatable; replaces hosts on update)
|
|
93
93
|
--header <header> --prefix <prefix> Optional proxy metadata for set, rotate or update
|
|
94
|
-
--capability-request <id> Fulfill
|
|
94
|
+
--capability-request <id> Fulfill an access request with set or rotate
|
|
95
95
|
sinatra repo <owner/name> secrets delete <name> [--yes]
|
|
96
96
|
Delete a secret (confirmation required)
|
|
97
97
|
sinatra repo <owner/name> env Read the feature-gated repository environment
|
|
98
98
|
sinatra repo <owner/name> capability-requests
|
|
99
|
-
|
|
99
|
+
List access requests
|
|
100
|
+
sinatra repo <owner/name> capability-requests dismiss <request-id> [--yes]
|
|
101
|
+
Dismiss an access request (owner/admin; confirmation required)
|
|
100
102
|
sinatra repo <owner/name> review-external-prs [inherit|on|off]
|
|
101
103
|
Read or set external PR reviews (writes: owner/admin)
|
|
102
104
|
All repos/repo commands take -w and --json
|
|
@@ -119,6 +121,35 @@ export const USAGE = `Usage:
|
|
|
119
121
|
for connection (--json returns only the URL response)
|
|
120
122
|
Browser commands always print the URL; --json returns
|
|
121
123
|
only the response without opening a browser
|
|
124
|
+
sinatra connectors [list] [--json] List the services agents can read through (Neon, Supabase,
|
|
125
|
+
PostHog and more) and the workspace's connections
|
|
126
|
+
sinatra connectors connect <connector> [--project <ref>] [--name <label>]
|
|
127
|
+
Print the dashboard link where you sign in at the provider
|
|
128
|
+
and accept the warning (owner/admin)
|
|
129
|
+
--token Paste a provider token instead, at a hidden prompt or from
|
|
130
|
+
stdin (owner/admin; never on the command line)
|
|
131
|
+
--accept Paste a token and accept the warning without a prompt
|
|
132
|
+
sinatra connectors disconnect <connection-id> [--yes]
|
|
133
|
+
Disconnect a service (owner/admin; confirmation required)
|
|
134
|
+
Connectors commands take -w and --json
|
|
135
|
+
sinatra recurring [list] [--json] List the workspace's recurring tasks and their next runs
|
|
136
|
+
sinatra recurring show <id> Read a recurring task, its prompt and recent runs
|
|
137
|
+
sinatra recurring create "<prompt>" --at <HH:MM>
|
|
138
|
+
Start a task on a schedule, as you (daily by default)
|
|
139
|
+
--at <HH:MM> A 24-hour time; repeat for up to four a day
|
|
140
|
+
--weekdays <mon,wed> Only on these days (sun to sat)
|
|
141
|
+
--day-of-month <1-28> Monthly on this day instead
|
|
142
|
+
--timezone <IANA zone> Time zone for --at (default: this computer's)
|
|
143
|
+
--name <name> Name (default: the prompt's first line)
|
|
144
|
+
--no-email Don't email you when each run's agent finishes
|
|
145
|
+
sinatra recurring edit <id> [--prompt <prompt>]
|
|
146
|
+
Change any of the create flags (owner only)
|
|
147
|
+
sinatra recurring pause <id> Stop scheduled runs (owner, or workspace owner/admin)
|
|
148
|
+
sinatra recurring resume <id> Turn scheduled runs back on (owner only)
|
|
149
|
+
sinatra recurring run <id> Start one run now, paused or not (owner only)
|
|
150
|
+
sinatra recurring delete <id> [--yes] Delete it (owner, or workspace owner/admin;
|
|
151
|
+
confirmation required)
|
|
152
|
+
Recurring commands take -w and --json
|
|
122
153
|
sinatra members list [--json] List members, pending invites and access requests
|
|
123
154
|
sinatra invite <email> --role <role> Invite a member or admin
|
|
124
155
|
sinatra invite resend <invite-id> Resend an invitation
|
|
@@ -132,7 +163,8 @@ export const USAGE = `Usage:
|
|
|
132
163
|
sinatra workspace leave Leave the workspace (confirmation required)
|
|
133
164
|
--role <member|admin> Role to grant; owner is never a grantable role
|
|
134
165
|
--yes, -y Skip confirmation for destructive access actions, model clear,
|
|
135
|
-
keys remove, repo override clear
|
|
166
|
+
keys remove, repo override clear, repo secrets delete, request dismissal,
|
|
167
|
+
connectors disconnect or recurring delete;
|
|
136
168
|
never pass keys or secret values in argv
|
|
137
169
|
Access commands take -w and --json; owner-only except leave
|
|
138
170
|
sinatra workspace create "<name>" [--json]
|
|
@@ -146,7 +178,7 @@ export const USAGE = `Usage:
|
|
|
146
178
|
sinatra -v, --version Print the CLI's version
|
|
147
179
|
|
|
148
180
|
-w, --workspace <id> Workspace for task, access, subscription, workspace settings,
|
|
149
|
-
model, keys, repos, repo or
|
|
181
|
+
model, keys, repos, repo, billing, connectors or recurring commands, or default to save at login
|
|
150
182
|
(default: yours from login or \`sinatra workspace\`)
|
|
151
183
|
Account and email preferences need no workspace membership or default workspace.
|
|
152
184
|
|
|
@@ -172,6 +204,19 @@ export function parseCommand(positionals) {
|
|
|
172
204
|
}
|
|
173
205
|
return usage("Usage: sinatra workspace review-external-prs [on|off] [-w <id>] [--json]");
|
|
174
206
|
}
|
|
207
|
+
if (first === "recurring") {
|
|
208
|
+
if (rest.length === 0 || (rest.length === 1 && rest[0] === "list"))
|
|
209
|
+
return { name: "recurring", action: "list" };
|
|
210
|
+
const [action, target] = rest;
|
|
211
|
+
if (rest.length === 2 && target?.trim()) {
|
|
212
|
+
if (action === "create")
|
|
213
|
+
return { name: "recurring", action, prompt: target };
|
|
214
|
+
if (action === "show" || action === "edit" || action === "pause" || action === "resume" || action === "run" || action === "delete") {
|
|
215
|
+
return { name: "recurring", action, taskId: target };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return usage(RECURRING_USAGE);
|
|
219
|
+
}
|
|
175
220
|
// Only the group's own shapes count (`sinatra connectors keep timing out` is still a task), but a
|
|
176
221
|
// malformed connect or disconnect is its usage, never a task: a mistyped connect could carry a token.
|
|
177
222
|
if (first === "connectors" && connectorsShape(rest)) {
|
|
@@ -200,6 +245,9 @@ export function parseCommand(positionals) {
|
|
|
200
245
|
if (rest.length === 2 && ["config", "env", "capability-requests"].includes(section)) {
|
|
201
246
|
return { name: "repo", repoName, action: section };
|
|
202
247
|
}
|
|
248
|
+
if (section === "capability-requests" && action === "dismiss" && rest.length === 4 && secretName?.trim()) {
|
|
249
|
+
return { name: "repo", repoName, action: "capability-dismiss", requestId: secretName };
|
|
250
|
+
}
|
|
203
251
|
if (rest.length === 3 && section === "config" && action === "preflight")
|
|
204
252
|
return { name: "repo", repoName, action: "preflight" };
|
|
205
253
|
if (rest.length === 3 && section === "override" && (action === "set" || action === "clear"))
|
|
@@ -360,7 +408,7 @@ const OPTIONS = {
|
|
|
360
408
|
help: { type: "boolean", short: "h" },
|
|
361
409
|
};
|
|
362
410
|
/**
|
|
363
|
-
* Options only `sinatra connectors` reads. They are parsed only for that
|
|
411
|
+
* Options only `sinatra connectors` reads. They are parsed only for that group, so every
|
|
364
412
|
* other command answers them exactly as it did before (`Unknown option --project.`).
|
|
365
413
|
*/
|
|
366
414
|
const CONNECTOR_OPTIONS = {
|
|
@@ -368,6 +416,15 @@ const CONNECTOR_OPTIONS = {
|
|
|
368
416
|
name: { type: "string" },
|
|
369
417
|
accept: { type: "boolean" },
|
|
370
418
|
};
|
|
419
|
+
const RECURRING_OPTIONS = {
|
|
420
|
+
at: { type: "string", multiple: true },
|
|
421
|
+
weekdays: { type: "string" },
|
|
422
|
+
"day-of-month": { type: "string" },
|
|
423
|
+
timezone: { type: "string" },
|
|
424
|
+
name: { type: "string" },
|
|
425
|
+
prompt: { type: "string" },
|
|
426
|
+
"no-email": { type: "boolean" },
|
|
427
|
+
};
|
|
371
428
|
/** The commands each option means something to; given to any other, it's a mistake. */
|
|
372
429
|
const APPLIES_TO = {
|
|
373
430
|
repo: ["start", "tickets"],
|
|
@@ -375,10 +432,10 @@ const APPLIES_TO = {
|
|
|
375
432
|
file: ["start", "reply", "repo"],
|
|
376
433
|
title: ["start"],
|
|
377
434
|
model: ["start"],
|
|
378
|
-
workspace: ["start", "reply", "show", "workspace-show", "workspace-pr-review", "tasks", "stop", "tickets", "delegate", "login", "access", "subscriptions", "model", "keys", "billing", "connect", "connectors", "repos", "repo"],
|
|
435
|
+
workspace: ["start", "reply", "show", "workspace-show", "workspace-pr-review", "tasks", "stop", "tickets", "delegate", "login", "access", "subscriptions", "model", "keys", "billing", "connect", "connectors", "repos", "repo", "recurring"],
|
|
379
436
|
"no-wait": ["start", "reply"],
|
|
380
437
|
timeout: ["start", "reply", "connect"],
|
|
381
|
-
json: ["whoami", "account", "email-preferences", "tasks", "show", "workspace-show", "workspace-create", "workspace-pr-review", "start", "reply", "tickets", "access", "subscriptions", "model", "keys", "billing", "connect", "connectors", "repos", "repo"],
|
|
438
|
+
json: ["whoami", "account", "email-preferences", "tasks", "show", "workspace-show", "workspace-create", "workspace-pr-review", "start", "reply", "tickets", "access", "subscriptions", "model", "keys", "billing", "connect", "connectors", "repos", "repo", "recurring"],
|
|
382
439
|
"setup-reminders": ["email-preferences"],
|
|
383
440
|
"task-alerts": ["email-preferences"],
|
|
384
441
|
status: ["tasks"],
|
|
@@ -387,7 +444,7 @@ const APPLIES_TO = {
|
|
|
387
444
|
token: ["login", "connectors"],
|
|
388
445
|
"no-browser": ["login", "subscriptions"],
|
|
389
446
|
role: ["access"],
|
|
390
|
-
yes: ["access", "model", "keys", "repo", "connectors"],
|
|
447
|
+
yes: ["access", "model", "keys", "repo", "connectors", "recurring"],
|
|
391
448
|
engine: ["model"],
|
|
392
449
|
effort: ["model"],
|
|
393
450
|
plan: ["billing"],
|
|
@@ -396,15 +453,22 @@ const APPLIES_TO = {
|
|
|
396
453
|
prefix: ["repo"],
|
|
397
454
|
"capability-request": ["repo"],
|
|
398
455
|
project: ["connectors"],
|
|
399
|
-
name: ["connectors"],
|
|
456
|
+
name: ["connectors", "recurring"],
|
|
400
457
|
accept: ["connectors"],
|
|
458
|
+
at: ["recurring"],
|
|
459
|
+
weekdays: ["recurring"],
|
|
460
|
+
"day-of-month": ["recurring"],
|
|
461
|
+
timezone: ["recurring"],
|
|
462
|
+
prompt: ["recurring"],
|
|
463
|
+
"no-email": ["recurring"],
|
|
401
464
|
};
|
|
402
465
|
function requiresConfirmation(command) {
|
|
403
466
|
return (command.name === "access" && ["revoke", "remove", "transfer", "leave"].includes(command.action))
|
|
404
467
|
|| (command.name === "model" && command.action === "clear")
|
|
405
468
|
|| (command.name === "keys" && command.action === "remove")
|
|
406
|
-
|| (command.name === "repo" && (command.action === "override-clear" || command.action === "secrets-delete"))
|
|
407
|
-
|| (command.name === "connectors" && command.action === "disconnect")
|
|
469
|
+
|| (command.name === "repo" && (command.action === "override-clear" || command.action === "secrets-delete" || command.action === "capability-dismiss"))
|
|
470
|
+
|| (command.name === "connectors" && command.action === "disconnect")
|
|
471
|
+
|| (command.name === "recurring" && command.action === "delete");
|
|
408
472
|
}
|
|
409
473
|
/** Refusals fail closed before the caller sends a workspace mutation. */
|
|
410
474
|
export async function confirmWorkspaceMutation(command, options) {
|
|
@@ -420,7 +484,9 @@ export async function confirmWorkspaceMutation(command, options) {
|
|
|
420
484
|
? `${command.action} in ${command.repoName}${"secretName" in command ? ` (${command.secretName})` : ""}`
|
|
421
485
|
: command.name === "connectors"
|
|
422
486
|
? `disconnect connection${"connectionId" in command ? ` ${command.connectionId}` : ""}`
|
|
423
|
-
:
|
|
487
|
+
: command.name === "recurring"
|
|
488
|
+
? `delete recurring task ${command.taskId}`
|
|
489
|
+
: "clear model default";
|
|
424
490
|
const answer = await options.ask(printable(`Confirm ${action} in workspace ${options.workspaceId}? [y/N] `));
|
|
425
491
|
if (!/^(y|yes)$/i.test(answer.trim()))
|
|
426
492
|
throw new UsageError("Cancelled. Nothing changed.");
|
|
@@ -528,15 +594,40 @@ export async function runRepo(client, workspaceId, inv, io) {
|
|
|
528
594
|
case "capability-requests":
|
|
529
595
|
result = await client.repoRequest(workspaceId, repo.id, "capability-requests");
|
|
530
596
|
break;
|
|
597
|
+
case "capability-dismiss":
|
|
598
|
+
result = await client.repoRequest(workspaceId, repo.id, `capability-requests/${encodeURIComponent(command.requestId)}/dismiss`, "POST");
|
|
599
|
+
break;
|
|
531
600
|
}
|
|
532
601
|
if (inv.json)
|
|
533
602
|
io.out(`${JSON.stringify(result, null, 2)}\n`);
|
|
534
|
-
else if (command.action === "override-clear" || command.action === "secrets-delete") {
|
|
535
|
-
io.out(
|
|
603
|
+
else if (command.action === "override-clear" || command.action === "secrets-delete" || command.action === "capability-dismiss") {
|
|
604
|
+
io.out({ "override-clear": "Repository override cleared.\n", "secrets-delete": "Repository secret deleted.\n", "capability-dismiss": "Access request dismissed.\n" }[command.action]);
|
|
605
|
+
}
|
|
606
|
+
else if (command.action === "capability-requests") {
|
|
607
|
+
io.out(printable(`${describeCapabilityRequests(result)}\n`));
|
|
536
608
|
}
|
|
537
609
|
else
|
|
538
610
|
io.out(printable(`${describeRepoResponse(result)}\n`));
|
|
539
611
|
}
|
|
612
|
+
function describeCapabilityRequests(value) {
|
|
613
|
+
if (!value || typeof value !== "object" || !("requests" in value) || !Array.isArray(value.requests)) {
|
|
614
|
+
return describeRepoResponse(value);
|
|
615
|
+
}
|
|
616
|
+
return value.requests.map((request) => {
|
|
617
|
+
if (!request || typeof request !== "object" || !("remediation" in request))
|
|
618
|
+
return describeRepoResponse(request);
|
|
619
|
+
const { remediation } = request;
|
|
620
|
+
if (!remediation || typeof remediation !== "object")
|
|
621
|
+
return describeRepoResponse(request);
|
|
622
|
+
const guidance = remediation;
|
|
623
|
+
const lines = [guidance.summary];
|
|
624
|
+
for (const line of ["reason" in request ? request.reason : null, guidance.supplyCommand, guidance.note, guidance.dismissCommand]) {
|
|
625
|
+
if (typeof line === "string")
|
|
626
|
+
lines.push(` ${line}`);
|
|
627
|
+
}
|
|
628
|
+
return lines.join("\n");
|
|
629
|
+
}).join("\n\n") || "No access requests.";
|
|
630
|
+
}
|
|
540
631
|
/** Keep nested config/environment responses readable without dropping server-owned fields. */
|
|
541
632
|
function describeRepoResponse(value, indent = "") {
|
|
542
633
|
if (value === null)
|
|
@@ -549,16 +640,19 @@ function describeRepoResponse(value, indent = "") {
|
|
|
549
640
|
return String(value);
|
|
550
641
|
}
|
|
551
642
|
/**
|
|
552
|
-
* How `sinatra login` gets its credential.
|
|
553
|
-
*
|
|
554
|
-
*
|
|
643
|
+
* How `sinatra login` gets its credential. `stdin` is "tty" at a terminal, "token" when a token was
|
|
644
|
+
* piped or redirected in (`sinatra login < token-file`), and "empty" when stdin isn't a terminal but
|
|
645
|
+
* carried nothing: a coding agent's shell, where a person told their agent to set Sinatra up. That
|
|
646
|
+
* case signs in through the browser too; reading it as a paste ended the agent's login with "No
|
|
647
|
+
* token given." "ci" is the same with CI set: no person will open a link there, so it still fails
|
|
648
|
+
* fast and asks for a token.
|
|
555
649
|
*/
|
|
556
|
-
export function loginMode(inv,
|
|
650
|
+
export function loginMode(inv, stdin) {
|
|
557
651
|
if (inv.pasteToken)
|
|
558
652
|
return "paste";
|
|
559
653
|
if (inv.noBrowser)
|
|
560
654
|
return "browser";
|
|
561
|
-
return
|
|
655
|
+
return stdin === "token" || stdin === "ci" ? "paste" : "browser";
|
|
562
656
|
}
|
|
563
657
|
/** The command line, read and checked; anything it can't run is a UsageError. */
|
|
564
658
|
export function parseInvocation(argv) {
|
|
@@ -567,7 +661,23 @@ export function parseInvocation(argv) {
|
|
|
567
661
|
return parseArgs({ args: argv, allowPositionals: true, options: OPTIONS });
|
|
568
662
|
}
|
|
569
663
|
catch (error) {
|
|
570
|
-
|
|
664
|
+
let first;
|
|
665
|
+
try {
|
|
666
|
+
[first] = parseArgs({ args: argv, allowPositionals: true, strict: false, options: { ...OPTIONS, ...RECURRING_OPTIONS } }).positionals;
|
|
667
|
+
}
|
|
668
|
+
catch {
|
|
669
|
+
if (argv.includes("recurring"))
|
|
670
|
+
throw new UsageError(RECURRING_USAGE);
|
|
671
|
+
}
|
|
672
|
+
if (first === "recurring") {
|
|
673
|
+
try {
|
|
674
|
+
return parseArgs({ args: argv, allowPositionals: true, options: { ...OPTIONS, ...RECURRING_OPTIONS } });
|
|
675
|
+
}
|
|
676
|
+
catch {
|
|
677
|
+
throw new UsageError(RECURRING_USAGE);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
// The connectors group reads its own options; any other command never sees them.
|
|
571
681
|
if (connectorsInvocation(argv)) {
|
|
572
682
|
try {
|
|
573
683
|
return parseArgs({ args: argv, allowPositionals: true, options: { ...OPTIONS, ...CONNECTOR_OPTIONS } });
|
|
@@ -686,6 +796,7 @@ export function parseInvocation(argv) {
|
|
|
686
796
|
else if (values.plan !== undefined)
|
|
687
797
|
throw new UsageError("--plan only applies to billing upgrade.");
|
|
688
798
|
}
|
|
799
|
+
const recurring = command.name === "recurring" ? recurringInput(command, values) : undefined;
|
|
689
800
|
return {
|
|
690
801
|
command,
|
|
691
802
|
files: values.file ?? [],
|
|
@@ -695,6 +806,7 @@ export function parseInvocation(argv) {
|
|
|
695
806
|
emailPreferences,
|
|
696
807
|
pasteToken: values.token ?? false,
|
|
697
808
|
noBrowser: values["no-browser"] ?? false,
|
|
809
|
+
...(recurring ? { recurring } : {}),
|
|
698
810
|
...(command.name === "repo" ? { secretMetadata: {
|
|
699
811
|
...(values.host !== undefined ? { hosts: values.host } : {}),
|
|
700
812
|
...(values.header !== undefined ? { header: values.header } : {}),
|
|
@@ -722,6 +834,71 @@ export function parseInvocation(argv) {
|
|
|
722
834
|
...(values["api-url"] !== undefined ? { apiUrl: values["api-url"] } : {}),
|
|
723
835
|
};
|
|
724
836
|
}
|
|
837
|
+
function recurringInput(command, values) {
|
|
838
|
+
const fail = (message) => { throw new UsageError(`${message}\n${RECURRING_USAGE}`); };
|
|
839
|
+
const supplied = Object.keys(RECURRING_OPTIONS).some((key) => values[key] !== undefined);
|
|
840
|
+
if (command.action !== "create" && command.action !== "edit") {
|
|
841
|
+
if (supplied)
|
|
842
|
+
fail("Schedule flags only apply to recurring create or edit.");
|
|
843
|
+
return undefined;
|
|
844
|
+
}
|
|
845
|
+
if (values.weekdays !== undefined && values["day-of-month"] !== undefined)
|
|
846
|
+
fail("Choose --weekdays or --day-of-month, not both.");
|
|
847
|
+
if (command.action === "create" && values.prompt !== undefined)
|
|
848
|
+
fail("Supply the create prompt as the quoted argument, not --prompt.");
|
|
849
|
+
const input = {};
|
|
850
|
+
const times = values.at;
|
|
851
|
+
if (command.action === "create" && !times)
|
|
852
|
+
fail("Create requires --at <HH:MM>.");
|
|
853
|
+
if (times && (times.length > 4 || new Set(times).size !== times.length || times.some((time) => !/^(?:[01]\d|2[0-3]):[0-5]\d$/.test(time)))) {
|
|
854
|
+
fail("--at takes one to four distinct times in HH:MM format.");
|
|
855
|
+
}
|
|
856
|
+
const schedule = times ? { times } : {};
|
|
857
|
+
if (values.weekdays !== undefined) {
|
|
858
|
+
const days = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
859
|
+
const weekdays = values.weekdays.toLowerCase().split(",").map((day) => days.indexOf(day.trim()));
|
|
860
|
+
if (weekdays.some((day) => day < 0) || new Set(weekdays).size !== weekdays.length)
|
|
861
|
+
fail("--weekdays takes distinct days such as mon,wed.");
|
|
862
|
+
schedule.weekdays = weekdays;
|
|
863
|
+
}
|
|
864
|
+
else if (values["day-of-month"] !== undefined) {
|
|
865
|
+
const day = values["day-of-month"];
|
|
866
|
+
if (!/^(?:[1-9]|1\d|2[0-8])$/.test(day))
|
|
867
|
+
fail("--day-of-month takes a whole number from 1 to 28.");
|
|
868
|
+
schedule.dayOfMonth = Number(day);
|
|
869
|
+
}
|
|
870
|
+
else if (command.action === "create")
|
|
871
|
+
schedule.weekdays = [0, 1, 2, 3, 4, 5, 6];
|
|
872
|
+
if (Object.keys(schedule).length)
|
|
873
|
+
input.cadence = schedule;
|
|
874
|
+
const timezone = values.timezone ?? (command.action === "create" ? Intl.DateTimeFormat().resolvedOptions().timeZone : undefined);
|
|
875
|
+
if (timezone !== undefined) {
|
|
876
|
+
try {
|
|
877
|
+
if (!timezone || /^[+-]/.test(timezone))
|
|
878
|
+
throw new RangeError();
|
|
879
|
+
new Intl.DateTimeFormat("en-US", { timeZone: timezone });
|
|
880
|
+
}
|
|
881
|
+
catch {
|
|
882
|
+
fail("--timezone takes an IANA time zone.");
|
|
883
|
+
}
|
|
884
|
+
input.timezone = timezone;
|
|
885
|
+
}
|
|
886
|
+
if (values.name !== undefined) {
|
|
887
|
+
if (!values.name.trim())
|
|
888
|
+
fail("--name must not be empty.");
|
|
889
|
+
input.name = values.name;
|
|
890
|
+
}
|
|
891
|
+
if (values.prompt !== undefined) {
|
|
892
|
+
if (!values.prompt.trim())
|
|
893
|
+
fail("--prompt must not be empty.");
|
|
894
|
+
input.prompt = values.prompt;
|
|
895
|
+
}
|
|
896
|
+
if (values["no-email"] !== undefined)
|
|
897
|
+
input.notifyByEmail = false;
|
|
898
|
+
if (command.action === "edit" && !Object.keys(input).length)
|
|
899
|
+
fail("Edit requires at least one change.");
|
|
900
|
+
return input;
|
|
901
|
+
}
|
|
725
902
|
/** The words after `connectors` that make it the group: none, `list`, or a connect or disconnect. */
|
|
726
903
|
function connectorsShape(rest) {
|
|
727
904
|
return rest.length === 0 || (rest.length === 1 && rest[0] === "list") || rest[0] === "connect" || rest[0] === "disconnect";
|
|
@@ -809,7 +986,7 @@ function subscriptionFailure(status) {
|
|
|
809
986
|
return new UsageError("Subscription authorization was denied. Run connect again to try again.");
|
|
810
987
|
if (status === "expired")
|
|
811
988
|
return new UsageError("Subscription authorization expired. Run connect again.");
|
|
812
|
-
return new UsageError("Subscription connection failed. Run connect again, or reconnect on
|
|
989
|
+
return new UsageError("Subscription connection failed. Run connect again, or reconnect on Settings → Models in Sinatra.");
|
|
813
990
|
}
|
|
814
991
|
/** Never print provider errors or response bodies: they can contain authorization credentials. */
|
|
815
992
|
function subscriptionApiFailure(error) {
|
|
@@ -837,7 +1014,7 @@ function subscriptionApiFailure(error) {
|
|
|
837
1014
|
if (error.status === 429)
|
|
838
1015
|
return new UsageError("Too many subscription requests. Try again later.");
|
|
839
1016
|
}
|
|
840
|
-
return new UsageError("The subscription request couldn't be completed. Try again, or use
|
|
1017
|
+
return new UsageError("The subscription request couldn't be completed. Try again, or use Settings → Models in Sinatra.");
|
|
841
1018
|
}
|
|
842
1019
|
/** Subscription commands have their own failure boundary, so no raw API or transport error escapes. */
|
|
843
1020
|
export async function subscriptions(command, deps) {
|
|
@@ -1145,8 +1322,8 @@ export function explain(error, context = {}) {
|
|
|
1145
1322
|
case "invalid_secret_name": return "That secret name isn't valid. Use the naming rules shown in the dashboard.";
|
|
1146
1323
|
case "invalid_secret_value": return "That secret value isn't valid. Enter a nonempty value through the hidden prompt or stdin.";
|
|
1147
1324
|
case "secret_cap_exceeded": return "This repository has reached its secret limit.";
|
|
1148
|
-
case "capability_request_not_found": return "That
|
|
1149
|
-
case "capability_target_not_authorized": return "The allowed hosts don't
|
|
1325
|
+
case "capability_request_not_found": return "That access request isn't available for this repository.";
|
|
1326
|
+
case "capability_target_not_authorized": return "The allowed hosts don't include the access request's target. Update --host.";
|
|
1150
1327
|
case "repo_environments_not_enabled": return "Repository environments aren't enabled for this workspace.";
|
|
1151
1328
|
case "invalid_model": return "Sinatra doesn't offer that model (see docs.sinatra.dev/docs/configuration/models).";
|
|
1152
1329
|
case "invalid_status": return "That isn't a task status (some are: pending, implementing, replied, pr_open, completed, failed).";
|
|
@@ -1281,6 +1458,7 @@ export const CONNECT_LINK_REFERENCE_PATTERNS = {
|
|
|
1281
1458
|
supabase: /^[a-z0-9]{20}$/,
|
|
1282
1459
|
posthog: /^[0-9]{1,12}$/,
|
|
1283
1460
|
sentry: /^[a-z0-9][a-z0-9_-]{0,63}$/,
|
|
1461
|
+
cloudsql: /^(?:[a-z0-9.-]+:)?[a-z][a-z0-9-]{4,28}[a-z0-9]:[a-z0-9-]+:[a-z][a-z0-9-]{0,97}$/,
|
|
1284
1462
|
};
|
|
1285
1463
|
export const CONNECT_LINK_CREDENTIAL_PATTERNS = [
|
|
1286
1464
|
/^napi_/, /^sbp_/, /^phx_/, /^sntry[su]_/, /^pscale_tkn_/, /^cfk_/, /^ntn_/,
|
|
@@ -1337,7 +1515,10 @@ function connectionLine(connection, projectRefLabel) {
|
|
|
1337
1515
|
...(connection.projectRef ? [`${projectRefLabel} ${connection.projectRef}`] : []),
|
|
1338
1516
|
readOnly,
|
|
1339
1517
|
...(connection.status === "needs_reconnect"
|
|
1340
|
-
|
|
1518
|
+
// A workload identity connection has nothing to sign in to: that command prints its dashboard link.
|
|
1519
|
+
? [connection.method === "wif"
|
|
1520
|
+
? `needs reconnecting from the dashboard (run: ${signInAgainCommand(connection)} for the link)`
|
|
1521
|
+
: `needs sign-in again (run: ${signInAgainCommand(connection)})`]
|
|
1341
1522
|
: connection.status !== "active" ? [connection.status] : []),
|
|
1342
1523
|
...(connection.connectedByName ? [`connected by ${connection.connectedByName}`] : []),
|
|
1343
1524
|
// Disconnect takes the id, so the list has to show it.
|
|
@@ -1345,7 +1526,7 @@ function connectionLine(connection, projectRefLabel) {
|
|
|
1345
1526
|
].join(" ");
|
|
1346
1527
|
}
|
|
1347
1528
|
/**
|
|
1348
|
-
* `sinatra connectors
|
|
1529
|
+
* `sinatra connectors`. A token is read only through the hidden reader and sent only
|
|
1349
1530
|
* in the connect request's body, through the client path that keeps no server detail.
|
|
1350
1531
|
*/
|
|
1351
1532
|
export async function runConnectors(client, workspaceId, inv, deps) {
|
|
@@ -1364,9 +1545,11 @@ export async function runConnectors(client, workspaceId, inv, deps) {
|
|
|
1364
1545
|
* the dashboard link that opens the dialog filled in. At a terminal it opens the link and watches
|
|
1365
1546
|
* the list for the new connection; otherwise it prints the link and returns.
|
|
1366
1547
|
*/
|
|
1367
|
-
const signInByLink = async (entry, connection, before
|
|
1548
|
+
const signInByLink = async (entry, connection, before,
|
|
1549
|
+
// `setup`: a connector set up in the dashboard itself (Google Cloud SQL), with no provider sign-in.
|
|
1550
|
+
kind = "sign_in") => {
|
|
1368
1551
|
if (!entry.connectUrl)
|
|
1369
|
-
throw new UsageError(printable(`
|
|
1552
|
+
throw new UsageError(printable(`Connect ${entry.name} from the Connectors page of your Sinatra dashboard.`));
|
|
1370
1553
|
const url = new URL(entry.connectUrl);
|
|
1371
1554
|
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
1372
1555
|
throw new UsageError("Sinatra returned an invalid connect link.");
|
|
@@ -1374,16 +1557,18 @@ export async function runConnectors(client, workspaceId, inv, deps) {
|
|
|
1374
1557
|
url.searchParams.set("project", connection.projectRef);
|
|
1375
1558
|
if (connection.label !== undefined)
|
|
1376
1559
|
url.searchParams.set("name", connection.label);
|
|
1377
|
-
|
|
1560
|
+
if (kind === "sign_in")
|
|
1561
|
+
url.searchParams.set("method", "oauth");
|
|
1378
1562
|
const link = url.toString();
|
|
1563
|
+
const steps = kind === "sign_in" ? `sign in to ${entry.name} and accept the warning there` : `follow the ${entry.name} setup and accept the warning there`;
|
|
1379
1564
|
if (inv.json || !deps.interactive) {
|
|
1380
1565
|
return emit({
|
|
1381
1566
|
connector: entry.id,
|
|
1382
1567
|
url: link,
|
|
1383
|
-
next: `Have a workspace admin or owner open this link in a browser,
|
|
1568
|
+
next: `Have a workspace admin or owner open this link in a browser, ${steps}. Then run \`sinatra connectors -w ${workspaceId} --json\` to check that the connection appears.`,
|
|
1384
1569
|
});
|
|
1385
1570
|
}
|
|
1386
|
-
deps.out(printable(`${entry.name}'s warning and sign-in happen in your browser:\n${link}\n`));
|
|
1571
|
+
deps.out(printable(`${entry.name}'s warning and ${kind === "sign_in" ? "sign-in" : "setup"} happen in your browser:\n${link}\n`));
|
|
1387
1572
|
await deps.openBrowser?.(link).catch(() => false);
|
|
1388
1573
|
// Only the caller's own new connection counts: another admin may connect the same service meanwhile.
|
|
1389
1574
|
const { user } = await client.me();
|
|
@@ -1451,7 +1636,7 @@ export async function runConnectors(client, workspaceId, inv, deps) {
|
|
|
1451
1636
|
if (!connection)
|
|
1452
1637
|
throw new UsageError(CONNECTORS_USAGE);
|
|
1453
1638
|
const listed = await client.listConnectors(workspaceId);
|
|
1454
|
-
// Off for this workspace
|
|
1639
|
+
// Off for this workspace, the list still answers while connections remain: nothing can be connected.
|
|
1455
1640
|
if (!listed.enabled)
|
|
1456
1641
|
throw new ApiError(404, "not_found");
|
|
1457
1642
|
const entry = listed.catalog.find((row) => row.id === command.connector);
|
|
@@ -1464,9 +1649,16 @@ export async function runConnectors(client, workspaceId, inv, deps) {
|
|
|
1464
1649
|
}
|
|
1465
1650
|
const offersSignIn = entry.methods.includes("oauth");
|
|
1466
1651
|
const takesToken = entry.methods.includes("token");
|
|
1652
|
+
const setUpInDashboard = !offersSignIn && !takesToken && entry.methods.includes("wif");
|
|
1467
1653
|
if ((connection.token || connection.accept) && !takesToken) {
|
|
1468
1654
|
const flags = [connection.token ? "--token" : "", connection.accept ? "--accept" : ""].filter(Boolean).join(" and ");
|
|
1469
|
-
|
|
1655
|
+
const how = setUpInDashboard ? "from the dashboard" : "by signing in, in the browser";
|
|
1656
|
+
throw new UsageError(printable(`${entry.name} connects only ${how}: leave out ${flags}.`));
|
|
1657
|
+
}
|
|
1658
|
+
if (setUpInDashboard) {
|
|
1659
|
+
checkConnectLinkValues(entry, connection);
|
|
1660
|
+
await requireAdmin();
|
|
1661
|
+
return await signInByLink(entry, connection, listed.connections.map((row) => row.id), "setup");
|
|
1470
1662
|
}
|
|
1471
1663
|
// Signing in is the default only when nothing asks for a token: `--accept` keeps pasting one, as
|
|
1472
1664
|
// it did before sign-in existed (`echo "$KEY" | sinatra connectors connect neon --project p --accept`).
|
package/dist/index.js
CHANGED
|
@@ -9,14 +9,16 @@
|
|
|
9
9
|
* sinatra delegate ENG-123 hand Sinatra an existing Linear or GitHub issue
|
|
10
10
|
* sinatra tasks | show <task> | stop <task> | whoami | workspace [id] | logout
|
|
11
11
|
*/
|
|
12
|
+
import { fstatSync } from "node:fs";
|
|
12
13
|
import { ApiError, createClient } from "./client.js";
|
|
13
14
|
import { addWorkspaceModelKey, confirmWorkspaceMutation, explain, login, loginMode, logout, parseInvocation, printable, removeWorkspaceModelKey, repoChoices, revokeSavedToken, runBilling, runConnect, runConnectors, runRepo, runWorkspaceCreate, startTask, subscriptions, USAGE, UsageError, } from "./commands.js";
|
|
14
15
|
import { ConfigError, DEFAULT_API_URL, deleteConfig, readConfig, withConfigLock, writeConfig } from "./config.js";
|
|
15
16
|
import { AttachmentError, composePrompt, detectRepos, readAttachments } from "./context.js";
|
|
16
17
|
import { EXIT, followOutcome, followTask } from "./follow.js";
|
|
17
18
|
import { browserSignIn, openBrowser, revokeSignIn, SignInError } from "./oauth.js";
|
|
18
|
-
import { ask, askSecret } from "./prompt.js";
|
|
19
|
+
import { ask, askSecret, readPipedInput } from "./prompt.js";
|
|
19
20
|
import { credentialsFor } from "./session.js";
|
|
21
|
+
import { runRecurring } from "./recurring.js";
|
|
20
22
|
import { CLI_VERSION } from "./version.js";
|
|
21
23
|
/** How a follow ended, for a task that stopped rather than waiting on you. */
|
|
22
24
|
const ENDINGS = {
|
|
@@ -56,6 +58,22 @@ function workspaceOf(config, flag) {
|
|
|
56
58
|
throw new UsageError("Which workspace? Pass -w <id>, or set a default with `sinatra workspace <id>`.");
|
|
57
59
|
return id;
|
|
58
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* What came in on stdin when it isn't a terminal. A pipe or file may carry a slowly produced token,
|
|
63
|
+
* so it gets 2 seconds to start; anything else, half a second. A slower source needs --token.
|
|
64
|
+
*/
|
|
65
|
+
async function pipedInput() {
|
|
66
|
+
let firstWaitMs = 500;
|
|
67
|
+
try {
|
|
68
|
+
const stat = fstatSync(0);
|
|
69
|
+
if (stat.isFIFO() || stat.isFile())
|
|
70
|
+
firstWaitMs = 2000;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return ""; // stdin is closed
|
|
74
|
+
}
|
|
75
|
+
return readPipedInput(process.stdin, firstWaitMs);
|
|
76
|
+
}
|
|
59
77
|
/** `/v1/me`, its refusals explained for where they happen (a 404 there isn't a missing task). */
|
|
60
78
|
async function whoAmI(client, apiUrl, during) {
|
|
61
79
|
try {
|
|
@@ -153,7 +171,13 @@ async function main(argv) {
|
|
|
153
171
|
return;
|
|
154
172
|
case "login": {
|
|
155
173
|
const apiUrl = checkApiUrl(inv.apiUrl ?? DEFAULT_API_URL);
|
|
156
|
-
|
|
174
|
+
// Off a terminal, read what came in first: a piped token, or nothing at all (an agent's shell).
|
|
175
|
+
// --token waits for its token however long the source takes, as it always did.
|
|
176
|
+
const readFirst = !process.stdin.isTTY && !inv.noBrowser && !inv.pasteToken;
|
|
177
|
+
const piped = readFirst ? await pipedInput() : "";
|
|
178
|
+
const inCI = Boolean(process.env.CI) && !["false", "0"].includes(process.env.CI.toLowerCase());
|
|
179
|
+
const stdin = process.stdin.isTTY ? "tty" : piped ? "token" : inCI ? "ci" : "empty";
|
|
180
|
+
const browser = loginMode(inv, stdin) === "browser";
|
|
157
181
|
return login({
|
|
158
182
|
apiUrl,
|
|
159
183
|
...(inv.workspace !== undefined ? { workspace: inv.workspace } : {}),
|
|
@@ -166,7 +190,9 @@ async function main(argv) {
|
|
|
166
190
|
},
|
|
167
191
|
}
|
|
168
192
|
: {}),
|
|
169
|
-
|
|
193
|
+
// Once stdin was read above, the paste is whatever came in (empty means "No token given.");
|
|
194
|
+
// reading it again would wait on a stream that has ended.
|
|
195
|
+
askSecret: (question) => (readFirst ? Promise.resolve(piped) : askSecret(question)),
|
|
170
196
|
ask: (question) => ask(question),
|
|
171
197
|
me: (token) => whoAmI(createClient({ apiUrl, token }), apiUrl, "login"),
|
|
172
198
|
discardPrevious: async () => {
|
|
@@ -356,6 +382,13 @@ async function main(argv) {
|
|
|
356
382
|
case "connect":
|
|
357
383
|
await runConnect(client, workspaceOf(config, inv.workspace), { ...inv, command }, { out, openBrowser });
|
|
358
384
|
return;
|
|
385
|
+
case "recurring":
|
|
386
|
+
await runRecurring(client, workspaceOf(config, inv.workspace), { ...inv, command }, {
|
|
387
|
+
out,
|
|
388
|
+
ask: (question) => ask(question, process.stdin, process.stderr),
|
|
389
|
+
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
390
|
+
});
|
|
391
|
+
return;
|
|
359
392
|
case "connectors":
|
|
360
393
|
await runConnectors(client, workspaceOf(config, inv.workspace), { ...inv, command }, {
|
|
361
394
|
out,
|
package/dist/prompt.js
CHANGED
|
@@ -16,6 +16,40 @@ async function nextPipedLine(input, trim = true) {
|
|
|
16
16
|
const next = await piped.lines.next();
|
|
17
17
|
return next.done ? "" : trim ? String(next.value).trim() : String(next.value);
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Input piped to a command that isn't at a terminal. Coding agents run commands with a stdin they
|
|
21
|
+
* may never write to or close (a Rust or Python harness's pipe looks like a shell pipe), so the read
|
|
22
|
+
* is always bounded: nothing within `firstWaitMs` means nothing was sent; after that it ends at the
|
|
23
|
+
* first newline, at end of input, or after `idleMs` with no more, so a token sent without a newline
|
|
24
|
+
* on a pipe left open still arrives.
|
|
25
|
+
*/
|
|
26
|
+
export function readPipedInput(input, firstWaitMs, idleMs = 1000) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
let text = "";
|
|
29
|
+
let timer;
|
|
30
|
+
const finish = () => {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
input.off("data", onData);
|
|
33
|
+
input.off("end", finish);
|
|
34
|
+
input.off("error", finish);
|
|
35
|
+
input.pause();
|
|
36
|
+
resolve(text.trim().split(/\r?\n/)[0] ?? "");
|
|
37
|
+
};
|
|
38
|
+
const onData = (chunk) => {
|
|
39
|
+
text += String(chunk);
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
if (text.trimStart().includes("\n"))
|
|
42
|
+
finish();
|
|
43
|
+
else
|
|
44
|
+
timer = setTimeout(finish, idleMs);
|
|
45
|
+
};
|
|
46
|
+
timer = setTimeout(finish, firstWaitMs);
|
|
47
|
+
input.on("data", onData);
|
|
48
|
+
input.once("end", finish);
|
|
49
|
+
input.once("error", finish);
|
|
50
|
+
input.resume();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
19
53
|
/** One line from the person. */
|
|
20
54
|
export async function ask(question, input = process.stdin, output = process.stdout) {
|
|
21
55
|
output.write(question);
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { ApiError } from "./client.js";
|
|
2
|
+
import { confirmWorkspaceMutation, printable, UsageError } from "./commands.js";
|
|
3
|
+
const WEEKDAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
4
|
+
const list = new Intl.ListFormat("en-US", { style: "long", type: "conjunction" });
|
|
5
|
+
/** Keep the dependency-free CLI's schedule description in local wall-clock time. */
|
|
6
|
+
function cadenceSentence(cadence) {
|
|
7
|
+
const weekdays = [...new Set(cadence.weekdays)].sort((a, b) => a - b);
|
|
8
|
+
const frequency = cadence.dayOfMonth !== undefined
|
|
9
|
+
? `Monthly on day ${cadence.dayOfMonth}`
|
|
10
|
+
: weekdays.length === 7
|
|
11
|
+
? "Daily"
|
|
12
|
+
: weekdays.join(",") === "1,2,3,4,5"
|
|
13
|
+
? "Weekdays"
|
|
14
|
+
: list.format(weekdays.map((day) => WEEKDAYS[day]));
|
|
15
|
+
return `${frequency} at ${list.format([...cadence.times].sort())}`;
|
|
16
|
+
}
|
|
17
|
+
export async function runRecurring(client, workspaceId, inv, io) {
|
|
18
|
+
const { command } = inv;
|
|
19
|
+
const emit = (value) => io.out(`${JSON.stringify(value, null, 2)}\n`);
|
|
20
|
+
const printTask = (task) => io.out(printable(`${task.id} ${task.name}${task.pausedAt ? " (paused)" : ""}\n ${cadenceSentence(task.cadence)}; timezone: ${task.timezone}\n Next run: ${task.nextRunAt ?? (task.pausedAt ? "none (paused)" : "none")}\n`));
|
|
21
|
+
try {
|
|
22
|
+
switch (command.action) {
|
|
23
|
+
case "list": {
|
|
24
|
+
const result = await client.listRecurringTasks(workspaceId);
|
|
25
|
+
if (inv.json)
|
|
26
|
+
return emit(result);
|
|
27
|
+
if (result.tasks.length === 0)
|
|
28
|
+
io.out("No recurring tasks.\n");
|
|
29
|
+
for (const task of result.tasks)
|
|
30
|
+
printTask(task);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
case "show": {
|
|
34
|
+
const result = await client.getRecurringTask(workspaceId, command.taskId);
|
|
35
|
+
if (inv.json)
|
|
36
|
+
return emit(result);
|
|
37
|
+
printTask(result.task);
|
|
38
|
+
io.out(printable(`\nPrompt:\n${result.task.prompt}\n\nRecent runs:\n`));
|
|
39
|
+
if (result.runs.length === 0)
|
|
40
|
+
io.out(" None\n");
|
|
41
|
+
for (const run of result.runs) {
|
|
42
|
+
const task = run.workstreamId ? `; task: ${run.workstreamId}` : "";
|
|
43
|
+
const reason = run.reasonText ?? run.reason;
|
|
44
|
+
io.out(printable(` ${run.id} ${run.scheduledFor} ${run.trigger} ${run.outcome}${task}${reason ? `; ${reason}` : ""}\n`));
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
case "create": {
|
|
49
|
+
const changes = inv.recurring;
|
|
50
|
+
const prompt = command.prompt ?? changes?.prompt;
|
|
51
|
+
if (prompt === undefined || !changes?.cadence?.times || !changes.timezone) {
|
|
52
|
+
throw new UsageError("Creating a recurring task requires a prompt, cadence and timezone.");
|
|
53
|
+
}
|
|
54
|
+
const result = await client.createRecurringTask(workspaceId, {
|
|
55
|
+
prompt,
|
|
56
|
+
cadence: { ...changes.cadence, times: changes.cadence.times },
|
|
57
|
+
timezone: changes.timezone,
|
|
58
|
+
...(changes.name !== undefined ? { name: changes.name } : {}),
|
|
59
|
+
...(changes.notifyByEmail !== undefined ? { notifyByEmail: changes.notifyByEmail } : {}),
|
|
60
|
+
});
|
|
61
|
+
if (inv.json)
|
|
62
|
+
return emit(result);
|
|
63
|
+
io.out("Created recurring task:\n");
|
|
64
|
+
printTask(result.task);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
case "edit": {
|
|
68
|
+
const changes = inv.recurring ?? {};
|
|
69
|
+
const prompt = command.prompt ?? changes.prompt;
|
|
70
|
+
const body = {
|
|
71
|
+
...(changes.name !== undefined ? { name: changes.name } : {}),
|
|
72
|
+
...(prompt !== undefined ? { prompt } : {}),
|
|
73
|
+
...(changes.timezone !== undefined ? { timezone: changes.timezone } : {}),
|
|
74
|
+
...(changes.notifyByEmail !== undefined ? { notifyByEmail: changes.notifyByEmail } : {}),
|
|
75
|
+
};
|
|
76
|
+
if (changes.cadence !== undefined) {
|
|
77
|
+
const { task } = await client.getRecurringTask(workspaceId, command.taskId);
|
|
78
|
+
const cadence = { ...task.cadence, ...changes.cadence };
|
|
79
|
+
if (changes.cadence.dayOfMonth !== undefined)
|
|
80
|
+
delete cadence.weekdays;
|
|
81
|
+
else if (changes.cadence.weekdays !== undefined)
|
|
82
|
+
delete cadence.dayOfMonth;
|
|
83
|
+
body.cadence = cadence;
|
|
84
|
+
}
|
|
85
|
+
const result = await client.updateRecurringTask(workspaceId, command.taskId, body);
|
|
86
|
+
if (inv.json)
|
|
87
|
+
return emit(result);
|
|
88
|
+
io.out("Updated recurring task:\n");
|
|
89
|
+
printTask(result.task);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
case "pause": {
|
|
93
|
+
const result = await client.pauseRecurringTask(workspaceId, command.taskId);
|
|
94
|
+
if (inv.json)
|
|
95
|
+
return emit(result);
|
|
96
|
+
io.out(printable(`Paused recurring task ${command.taskId}.\n`));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
case "resume": {
|
|
100
|
+
const result = await client.resumeRecurringTask(workspaceId, command.taskId);
|
|
101
|
+
if (inv.json)
|
|
102
|
+
return emit(result);
|
|
103
|
+
io.out("Resumed recurring task:\n");
|
|
104
|
+
printTask(result.task);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
case "run": {
|
|
108
|
+
const result = await client.runRecurringTask(workspaceId, command.taskId);
|
|
109
|
+
if (inv.json)
|
|
110
|
+
return emit(result);
|
|
111
|
+
io.out(printable(`Started task ${result.taskId} from recurring task ${command.taskId}${result.run ? ` (run ${result.run.id})` : ""}.\n`));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
case "delete": {
|
|
115
|
+
await confirmWorkspaceMutation(command, { yes: inv.yes ?? false, interactive: io.interactive, workspaceId, ask: io.ask });
|
|
116
|
+
const result = await client.deleteRecurringTask(workspaceId, command.taskId);
|
|
117
|
+
if (inv.json)
|
|
118
|
+
return emit(result);
|
|
119
|
+
io.out(printable(`Deleted recurring task ${command.taskId}.\n`));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (error instanceof ApiError && error.status === 404) {
|
|
126
|
+
throw new UsageError(command.taskId
|
|
127
|
+
? `No recurring task ${command.taskId} in this workspace. Run \`sinatra recurring\` to list them.`
|
|
128
|
+
: "Recurring tasks are not available in this workspace.");
|
|
129
|
+
}
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|