sinatra.dev 0.5.2 → 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 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
- In a script, pipe the token in and name the default workspace with `-w`. Piped input always reads a
49
- token, without `--token`:
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
@@ -127,6 +131,14 @@ sinatra logout # end the sign-in (or revoke the
127
131
  | `sinatra connectors [list]` | `-w`, `--json` |
128
132
  | `sinatra connectors connect <connector>` | Owner/admin only; `--project <ref>`, `--name <label>`, `--token` (hidden prompt or stdin only), `--accept`, `-w`, `--json` |
129
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` |
130
142
  | `sinatra model [get]` | `-w`, `--json` |
131
143
  | `sinatra model set <model>` | `--engine <engine>` (required), `--effort <effort>` (optional), `-w`, `--json` |
132
144
  | `sinatra model clear` | `-w`, `--json`, `--yes` / `-y` |
@@ -288,6 +300,33 @@ at the provider.
288
300
  it at the provider too; the CLI says when something stays authorized there.
289
301
  See [Connectors](https://docs.sinatra.dev/docs/configuration/connectors) for each service.
290
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
+
291
330
  ### Workspace access
292
331
 
293
332
  Owners can manage workspace access with the same permissions as the dashboard:
package/dist/commands.js CHANGED
@@ -132,6 +132,24 @@ export const USAGE = `Usage:
132
132
  sinatra connectors disconnect <connection-id> [--yes]
133
133
  Disconnect a service (owner/admin; confirmation required)
134
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
135
153
  sinatra members list [--json] List members, pending invites and access requests
136
154
  sinatra invite <email> --role <role> Invite a member or admin
137
155
  sinatra invite resend <invite-id> Resend an invitation
@@ -145,7 +163,8 @@ export const USAGE = `Usage:
145
163
  sinatra workspace leave Leave the workspace (confirmation required)
146
164
  --role <member|admin> Role to grant; owner is never a grantable role
147
165
  --yes, -y Skip confirmation for destructive access actions, model clear,
148
- keys remove, repo override clear, repo secrets delete or request dismissal;
166
+ keys remove, repo override clear, repo secrets delete, request dismissal,
167
+ connectors disconnect or recurring delete;
149
168
  never pass keys or secret values in argv
150
169
  Access commands take -w and --json; owner-only except leave
151
170
  sinatra workspace create "<name>" [--json]
@@ -159,7 +178,7 @@ export const USAGE = `Usage:
159
178
  sinatra -v, --version Print the CLI's version
160
179
 
161
180
  -w, --workspace <id> Workspace for task, access, subscription, workspace settings,
162
- model, keys, repos, repo, billing or connectors commands, or default to save at login
181
+ model, keys, repos, repo, billing, connectors or recurring commands, or default to save at login
163
182
  (default: yours from login or \`sinatra workspace\`)
164
183
  Account and email preferences need no workspace membership or default workspace.
165
184
 
@@ -621,16 +640,19 @@ function describeRepoResponse(value, indent = "") {
621
640
  return String(value);
622
641
  }
623
642
  /**
624
- * How `sinatra login` gets its credential. Asked for explicitly, that way; otherwise the browser
625
- * at a terminal, and a pasted token when stdin is piped (`sinatra login < token-file`), which
626
- * holds the token and nothing else.
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.
627
649
  */
628
- export function loginMode(inv, stdinIsTTY) {
650
+ export function loginMode(inv, stdin) {
629
651
  if (inv.pasteToken)
630
652
  return "paste";
631
653
  if (inv.noBrowser)
632
654
  return "browser";
633
- return stdinIsTTY ? "browser" : "paste";
655
+ return stdin === "token" || stdin === "ci" ? "paste" : "browser";
634
656
  }
635
657
  /** The command line, read and checked; anything it can't run is a UsageError. */
636
658
  export function parseInvocation(argv) {
@@ -964,7 +986,7 @@ function subscriptionFailure(status) {
964
986
  return new UsageError("Subscription authorization was denied. Run connect again to try again.");
965
987
  if (status === "expired")
966
988
  return new UsageError("Subscription authorization expired. Run connect again.");
967
- return new UsageError("Subscription connection failed. Run connect again, or reconnect on your Sinatra Account page.");
989
+ return new UsageError("Subscription connection failed. Run connect again, or reconnect on Settings → Models in Sinatra.");
968
990
  }
969
991
  /** Never print provider errors or response bodies: they can contain authorization credentials. */
970
992
  function subscriptionApiFailure(error) {
@@ -992,7 +1014,7 @@ function subscriptionApiFailure(error) {
992
1014
  if (error.status === 429)
993
1015
  return new UsageError("Too many subscription requests. Try again later.");
994
1016
  }
995
- return new UsageError("The subscription request couldn't be completed. Try again, or use your Sinatra Account page.");
1017
+ return new UsageError("The subscription request couldn't be completed. Try again, or use Settings → Models in Sinatra.");
996
1018
  }
997
1019
  /** Subscription commands have their own failure boundary, so no raw API or transport error escapes. */
998
1020
  export async function subscriptions(command, deps) {
@@ -1436,6 +1458,7 @@ export const CONNECT_LINK_REFERENCE_PATTERNS = {
1436
1458
  supabase: /^[a-z0-9]{20}$/,
1437
1459
  posthog: /^[0-9]{1,12}$/,
1438
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}$/,
1439
1462
  };
1440
1463
  export const CONNECT_LINK_CREDENTIAL_PATTERNS = [
1441
1464
  /^napi_/, /^sbp_/, /^phx_/, /^sntry[su]_/, /^pscale_tkn_/, /^cfk_/, /^ntn_/,
@@ -1492,7 +1515,10 @@ function connectionLine(connection, projectRefLabel) {
1492
1515
  ...(connection.projectRef ? [`${projectRefLabel} ${connection.projectRef}`] : []),
1493
1516
  readOnly,
1494
1517
  ...(connection.status === "needs_reconnect"
1495
- ? [`needs sign-in again (run: ${signInAgainCommand(connection)})`]
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)})`]
1496
1522
  : connection.status !== "active" ? [connection.status] : []),
1497
1523
  ...(connection.connectedByName ? [`connected by ${connection.connectedByName}`] : []),
1498
1524
  // Disconnect takes the id, so the list has to show it.
@@ -1519,9 +1545,11 @@ export async function runConnectors(client, workspaceId, inv, deps) {
1519
1545
  * the dashboard link that opens the dialog filled in. At a terminal it opens the link and watches
1520
1546
  * the list for the new connection; otherwise it prints the link and returns.
1521
1547
  */
1522
- 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") => {
1523
1551
  if (!entry.connectUrl)
1524
- throw new UsageError(printable(`Sign in to ${entry.name} from the Connectors page of your Sinatra dashboard.`));
1552
+ throw new UsageError(printable(`Connect ${entry.name} from the Connectors page of your Sinatra dashboard.`));
1525
1553
  const url = new URL(entry.connectUrl);
1526
1554
  if (url.protocol !== "https:" && url.protocol !== "http:")
1527
1555
  throw new UsageError("Sinatra returned an invalid connect link.");
@@ -1529,16 +1557,18 @@ export async function runConnectors(client, workspaceId, inv, deps) {
1529
1557
  url.searchParams.set("project", connection.projectRef);
1530
1558
  if (connection.label !== undefined)
1531
1559
  url.searchParams.set("name", connection.label);
1532
- url.searchParams.set("method", "oauth");
1560
+ if (kind === "sign_in")
1561
+ url.searchParams.set("method", "oauth");
1533
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`;
1534
1564
  if (inv.json || !deps.interactive) {
1535
1565
  return emit({
1536
1566
  connector: entry.id,
1537
1567
  url: link,
1538
- next: `Have a workspace admin or owner open this link in a browser, sign in to ${entry.name} and accept the warning there. Then run \`sinatra connectors -w ${workspaceId} --json\` to check that the connection appears.`,
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.`,
1539
1569
  });
1540
1570
  }
1541
- 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`));
1542
1572
  await deps.openBrowser?.(link).catch(() => false);
1543
1573
  // Only the caller's own new connection counts: another admin may connect the same service meanwhile.
1544
1574
  const { user } = await client.me();
@@ -1619,9 +1649,16 @@ export async function runConnectors(client, workspaceId, inv, deps) {
1619
1649
  }
1620
1650
  const offersSignIn = entry.methods.includes("oauth");
1621
1651
  const takesToken = entry.methods.includes("token");
1652
+ const setUpInDashboard = !offersSignIn && !takesToken && entry.methods.includes("wif");
1622
1653
  if ((connection.token || connection.accept) && !takesToken) {
1623
1654
  const flags = [connection.token ? "--token" : "", connection.accept ? "--accept" : ""].filter(Boolean).join(" and ");
1624
- throw new UsageError(printable(`${entry.name} connects only by signing in, in the browser: leave out ${flags}.`));
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");
1625
1662
  }
1626
1663
  // Signing in is the default only when nothing asks for a token: `--accept` keeps pasting one, as
1627
1664
  // it did before sign-in existed (`echo "$KEY" | sinatra connectors connect neon --project p --accept`).
package/dist/index.js CHANGED
@@ -9,13 +9,14 @@
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";
20
21
  import { runRecurring } from "./recurring.js";
21
22
  import { CLI_VERSION } from "./version.js";
@@ -57,6 +58,22 @@ function workspaceOf(config, flag) {
57
58
  throw new UsageError("Which workspace? Pass -w <id>, or set a default with `sinatra workspace <id>`.");
58
59
  return id;
59
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
+ }
60
77
  /** `/v1/me`, its refusals explained for where they happen (a 404 there isn't a missing task). */
61
78
  async function whoAmI(client, apiUrl, during) {
62
79
  try {
@@ -154,7 +171,13 @@ async function main(argv) {
154
171
  return;
155
172
  case "login": {
156
173
  const apiUrl = checkApiUrl(inv.apiUrl ?? DEFAULT_API_URL);
157
- const browser = loginMode(inv, Boolean(process.stdin.isTTY)) === "browser";
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";
158
181
  return login({
159
182
  apiUrl,
160
183
  ...(inv.workspace !== undefined ? { workspace: inv.workspace } : {}),
@@ -167,7 +190,9 @@ async function main(argv) {
167
190
  },
168
191
  }
169
192
  : {}),
170
- askSecret: (question) => askSecret(question),
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)),
171
196
  ask: (question) => ask(question),
172
197
  me: (token) => whoAmI(createClient({ apiUrl, token }), apiUrl, "login"),
173
198
  discardPrevious: async () => {
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinatra.dev",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Hand coding tasks to Sinatra from your terminal.",
5
5
  "keywords": [
6
6
  "sinatra",