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/dist/index.js CHANGED
@@ -3,21 +3,21 @@
3
3
  * `sinatra`: hand coding tasks to Sinatra from your terminal (SIN-1258).
4
4
  *
5
5
  * sinatra login sign in through the browser (--token: paste a token)
6
- * sinatra "fix the flaky test" start a task and follow it until its turn is done
6
+ * sinatra "fix the flaky test" start a task and follow it until its agent hands back
7
7
  * sinatra reply <task> "also docs" follow up on a task
8
8
  * sinatra tickets -q "login" find open Linear and GitHub issues you could delegate
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 { readFileSync } from "node:fs";
13
12
  import { ApiError, createClient } from "./client.js";
14
- import { explain, login, loginMode, logout, parseInvocation, printable, repoChoices, revokeSavedToken, startTask, UsageError, } from "./commands.js";
13
+ import { addWorkspaceModelKey, confirmWorkspaceMutation, explain, login, loginMode, logout, parseInvocation, printable, removeWorkspaceModelKey, repoChoices, revokeSavedToken, runBilling, runConnect, runRepo, runWorkspaceCreate, startTask, subscriptions, UsageError, } from "./commands.js";
15
14
  import { ConfigError, DEFAULT_API_URL, deleteConfig, readConfig, withConfigLock, writeConfig } from "./config.js";
16
15
  import { AttachmentError, composePrompt, detectRepos, readAttachments } from "./context.js";
17
16
  import { EXIT, followOutcome, followTask } from "./follow.js";
18
17
  import { browserSignIn, openBrowser, revokeSignIn, SignInError } from "./oauth.js";
19
18
  import { ask, askSecret } from "./prompt.js";
20
19
  import { credentialsFor } from "./session.js";
20
+ import { CLI_VERSION } from "./version.js";
21
21
  const USAGE = `Usage:
22
22
  sinatra login [--api-url <url>] [-w <id>] [--no-browser | --token]
23
23
  Sign in through your browser (-w: the default workspace)
@@ -29,6 +29,8 @@ const USAGE = `Usage:
29
29
  -r, --repo <owner/name> Repository (default: this checkout's GitHub remote)
30
30
  -f, --file <path> Attach a text file (repeatable, 80KB total)
31
31
  -t, --title <title> Task title (default: the prompt's first line)
32
+ -m, --model <model> Model for every agent, such as openai-codex/gpt-6.1-sol
33
+ (default: the repository's or workspace's model)
32
34
  --timeout <minutes> Stop following after this long (default 30)
33
35
  --no-wait Start it and return
34
36
  --json With --no-wait: print the started task as JSON
@@ -37,19 +39,103 @@ const USAGE = `Usage:
37
39
  sinatra show <task-id> [--json] Print a task and its conversation
38
40
  sinatra tasks [--status <status>] [-n, --limit <n>] [--json]
39
41
  List the workspace's recent tasks (20 unless -n)
40
- sinatra stop <task-id> Stop a task's running turn
42
+ sinatra stop <task-id> Stop a task's running agent
41
43
  sinatra tickets [-q <text>] [-r <owner/name>] [--json]
42
44
  Open Linear and GitHub issues you could delegate: yours,
43
45
  then the team's unassigned (-q: search, -r: repo first)
44
46
  sinatra delegate <ticket> Hand Sinatra a Linear or GitHub issue as you: ENG-123,
45
47
  owner/name#12, or the issue's URL
48
+ sinatra subscriptions [list] [--json] List your subscription connections in this workspace
49
+ sinatra subscriptions connect <codex|claude|xai|cursor> [--json] [--no-browser]
50
+ Print the verification URL/code and open your browser;
51
+ wait up to 15 minutes for device approval. Claude asks
52
+ for a hidden authorization code (or reads it from stdin).
53
+ Never pass an authorization code on the command line.
54
+ With --json, handoff and prompts go to stderr.
55
+ sinatra subscriptions remove <id> [--json]
56
+ Remove one of your subscription connections
46
57
  sinatra whoami [--json] Who you're logged in as, and your workspaces
58
+ sinatra account [--json] Your account, memberships and linked identities
59
+ sinatra email-preferences [--json] Read your email preferences
60
+ --setup-reminders <on|off> Change setup reminder emails
61
+ --task-alerts <on|off> Change task alert emails (omitted flags stay unchanged)
47
62
  sinatra workspace [<id>] List your workspaces, or make one the default
63
+ sinatra repos [-w <id>] [--json] List the workspace's accessible repositories
64
+ sinatra repo <owner/name> config Read effective repository config and provenance
65
+ sinatra repo <owner/name> config preflight --file <json>
66
+ Preflight a draft override fragment from a JSON file
67
+ sinatra repo <owner/name> override set --file <json>
68
+ Save your repository override fragment
69
+ sinatra repo <owner/name> override clear [--yes]
70
+ Clear your override (confirmation required)
71
+ sinatra repo <owner/name> secrets [list]
72
+ List secret metadata, never plaintext values
73
+ sinatra repo <owner/name> secrets set <name> --host <host>
74
+ sinatra repo <owner/name> secrets rotate <name>
75
+ Read a value at a hidden prompt or from stdin;
76
+ never pass secret values in arguments or flags
77
+ sinatra repo <owner/name> secrets update <name>
78
+ PATCH metadata without changing the secret value
79
+ --host <host> Allowed host (repeatable; replaces hosts on update)
80
+ --header <header> --prefix <prefix> Optional proxy metadata for set, rotate or update
81
+ --capability-request <id> Fulfill a capability request with set or rotate
82
+ sinatra repo <owner/name> secrets delete <name> [--yes]
83
+ Delete a secret (confirmation required)
84
+ sinatra repo <owner/name> env Read the feature-gated repository environment
85
+ sinatra repo <owner/name> capability-requests
86
+ Read repository capability requests
87
+ sinatra repo <owner/name> review-external-prs [inherit|on|off]
88
+ Read or set external PR reviews (writes: owner/admin)
89
+ All repos/repo commands take -w and --json
90
+ sinatra model [get] [--json] Show the workspace's saved default (members)
91
+ sinatra model set <model> --engine <engine> [--effort <effort>]
92
+ Save a catalog engine/model/effort pairing (owner only)
93
+ sinatra model clear [--yes] Restore automatic selection (owner only; confirmation required)
94
+ sinatra keys [list] [--json] List configured providers, never key values (members)
95
+ sinatra keys add <anthropic|openrouter> Paste a key at a hidden prompt, or pipe stdin
96
+ sinatra keys remove <anthropic|openrouter> [--yes]
97
+ Remove a key (owners/admins; confirmation required)
98
+ Model and keys commands take -w and --json
99
+ sinatra billing [-w <id>] [--json] Show plan, capacity and subscription status
100
+ sinatra billing upgrade --plan <pro|team|scale> [-w <id>] [--json]
101
+ Open checkout (workspace owner only)
102
+ sinatra billing portal [-w <id>] [--json]
103
+ Open billing management (workspace owner only)
104
+ sinatra connect <github|linear|slack|telegram> [-w <id>] [--timeout <minutes>] [--json]
105
+ Print the authorization URL, open your browser and wait
106
+ for connection (--json returns only the URL response)
107
+ Browser commands always print the URL; --json returns
108
+ only the response without opening a browser
109
+ sinatra members list [--json] List members, pending invites and access requests
110
+ sinatra invite <email> --role <role> Invite a member or admin
111
+ sinatra invite resend <invite-id> Resend an invitation
112
+ sinatra invite revoke <invite-id> Revoke an invitation (confirmation required)
113
+ sinatra requests approve <request-id> --role <role>
114
+ sinatra requests deny <request-id> Resolve an access request
115
+ sinatra members role <membership-id> --role <role>
116
+ sinatra members remove <membership-id> Remove a member (confirmation required)
117
+ sinatra members transfer <membership-id>
118
+ Transfer ownership (confirmation required)
119
+ sinatra workspace leave Leave the workspace (confirmation required)
120
+ --role <member|admin> Role to grant; owner is never a grantable role
121
+ --yes, -y Skip confirmation for destructive access actions, model clear,
122
+ keys remove, repo override clear or repo secrets delete;
123
+ never pass keys or secret values in argv
124
+ Access commands take -w and --json; owner-only except leave
125
+ sinatra workspace create "<name>" [--json]
126
+ Create a workspace you own (one per person without
127
+ GitHub); the first becomes your default
128
+ sinatra workspace show [-w <id>] [--json]
129
+ Read repositories, integrations, plan and default model
130
+ sinatra workspace review-external-prs [on|off] [-w <id>] [--json]
131
+ Read or set external PR reviews (writes: owner/admin)
48
132
  sinatra logout Revoke the saved sign-in or token and forget it
49
133
  sinatra -v, --version Print the CLI's version
50
134
 
51
- -w, --workspace <id> Workspace for any task command (default: yours from
52
- login or \`sinatra workspace\`)
135
+ -w, --workspace <id> Workspace for task, access, subscription, workspace settings,
136
+ model, keys, repos, repo or billing commands, or default to save at login
137
+ (default: yours from login or \`sinatra workspace\`)
138
+ Account and email preferences need no workspace membership or default workspace.
53
139
 
54
140
  Exit codes: 0 done, 1 error, 2 the task failed, was cancelled or is paused,
55
141
  3 still working (or your reply not picked up yet) when the CLI stopped waiting.`;
@@ -61,11 +147,6 @@ const ENDINGS = {
61
147
  payment_required: "Paused: the workspace's plan or model access needs attention on the dashboard.",
62
148
  auth_required: "Paused: Sinatra needs access granted on the dashboard before it can go on.",
63
149
  };
64
- function version() {
65
- // package.json sits next to dist/ (and src/), in the installed package too.
66
- const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
67
- return pkg.version ?? "unknown";
68
- }
69
150
  function out(text) {
70
151
  process.stdout.write(text);
71
152
  }
@@ -77,10 +158,13 @@ function print(message) {
77
158
  out(`\n${who}:\n${printable(message.body)}\n`);
78
159
  }
79
160
  function describe(task) {
80
- const status = task.queued ? `${task.status} (queued)` : task.status;
161
+ const status = task.queued ? `${task.status} (waiting)` : task.status;
81
162
  const pr = task.pullRequest ? ` ${task.pullRequest.url}${task.pullRequest.merged ? " (merged)" : ""}` : "";
82
163
  return printable(`${task.id} ${status.padEnd(14)} ${task.title ?? "(untitled)"}${pr}`);
83
164
  }
165
+ function accessPersonName(person) {
166
+ return person.name || (person.githubLogin ? `@${person.githubLogin}` : person.id);
167
+ }
84
168
  async function loggedIn() {
85
169
  const config = await readConfig();
86
170
  if (!config)
@@ -126,7 +210,7 @@ async function follow(client, workspaceId, taskId, options) {
126
210
  taskId,
127
211
  ...options,
128
212
  print,
129
- onQueued: () => out("Queued: this workspace is running as many tasks at a time as its plan allows.\n"),
213
+ onQueued: () => out("Waiting: this workspace is running as many agents at a time as its plan allows.\n"),
130
214
  });
131
215
  const { task } = result;
132
216
  if (task.pullRequest)
@@ -186,7 +270,7 @@ async function main(argv) {
186
270
  out(`${USAGE}\n`);
187
271
  return;
188
272
  case "version":
189
- out(`${version()}\n`);
273
+ out(`${CLI_VERSION}\n`);
190
274
  return;
191
275
  case "login": {
192
276
  const apiUrl = checkApiUrl(inv.apiUrl ?? DEFAULT_API_URL);
@@ -233,13 +317,171 @@ async function main(argv) {
233
317
  token: credentialsFor(config, {
234
318
  store: { read: readConfig, write: (c) => writeConfig(c), forget: deleteConfig, lock: (fn) => withConfigLock(fn) },
235
319
  }),
320
+ ...(command.name === "subscriptions" ? { timeoutMs: 30_000 } : {}),
321
+ ...(command.name === "connect" ? { timeoutMs: Math.min(inv.timeoutMs, 30_000) } : {}),
236
322
  });
237
323
  switch (command.name) {
324
+ case "repos":
325
+ case "repo":
326
+ await runRepo(client, workspaceOf(config, inv.workspace), { ...inv, command }, {
327
+ out,
328
+ ask: (question) => ask(question, process.stdin, process.stderr),
329
+ askSecret: (question) => askSecret(question, process.stdin, process.stderr, "value"),
330
+ interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
331
+ });
332
+ return;
333
+ case "model": {
334
+ const workspaceId = workspaceOf(config, inv.workspace);
335
+ await confirmWorkspaceMutation(command, {
336
+ yes: inv.yes ?? false,
337
+ interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
338
+ workspaceId,
339
+ ask: (question) => ask(question, process.stdin, process.stderr),
340
+ });
341
+ const result = command.action === "set"
342
+ ? await client.setModelDefault(workspaceId, {
343
+ engine: inv.engine, model: command.model,
344
+ ...(inv.effort !== undefined ? { effort: inv.effort } : {}),
345
+ })
346
+ : command.action === "clear"
347
+ ? await client.clearModelDefault(workspaceId)
348
+ : await client.getModelDefault(workspaceId);
349
+ if (inv.json)
350
+ return printJson(result);
351
+ if (command.action === "clear")
352
+ out("Workspace model default cleared; automatic selection restored.\n");
353
+ else if (result.selection) {
354
+ const { engine, model, effort } = result.selection;
355
+ out(printable(`Workspace model default: ${engine} / ${model}${effort ? ` (effort: ${effort})` : ""}\n`));
356
+ }
357
+ else
358
+ out("No workspace model default saved; automatic selection is enabled.\n");
359
+ return;
360
+ }
361
+ case "keys": {
362
+ const workspaceId = workspaceOf(config, inv.workspace);
363
+ await confirmWorkspaceMutation(command, {
364
+ yes: inv.yes ?? false,
365
+ interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
366
+ workspaceId,
367
+ ask: (question) => ask(question, process.stdin, process.stderr),
368
+ });
369
+ if (command.action === "list") {
370
+ const result = await client.listModelKeys(workspaceId);
371
+ if (inv.json)
372
+ return printJson(result);
373
+ if (result.credentials.length === 0)
374
+ out("No workspace model keys configured.\n");
375
+ for (const credential of result.credentials)
376
+ out(printable(`${credential.provider} ${credential.status}\n`));
377
+ }
378
+ else if (command.action === "add") {
379
+ const result = await addWorkspaceModelKey(client, workspaceId, command.provider, (question) => askSecret(question, process.stdin, process.stderr));
380
+ if (inv.json)
381
+ return printJson(result);
382
+ out(`${result.provider} key configured.\n`);
383
+ }
384
+ else {
385
+ const { result, message } = await removeWorkspaceModelKey(client, workspaceId, command.provider);
386
+ if (inv.json)
387
+ return printJson(result);
388
+ out(`${message}\n`);
389
+ }
390
+ return;
391
+ }
392
+ case "access": {
393
+ const workspaceId = workspaceOf(config, inv.workspace);
394
+ await confirmWorkspaceMutation(command, {
395
+ yes: inv.yes ?? false,
396
+ interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
397
+ workspaceId,
398
+ ask: (question) => ask(question, process.stdin, process.stderr),
399
+ });
400
+ const before = !inv.json && ["role", "remove", "transfer", "approve", "deny"].includes(command.action)
401
+ ? await client.workspaceAccess(workspaceId, "list")
402
+ : undefined;
403
+ const result = await client.workspaceAccess(workspaceId, command.action, command.target, inv.role);
404
+ if (inv.json)
405
+ return printJson(result);
406
+ if (command.action === "list") {
407
+ out("Members:\n");
408
+ for (const member of result.memberships ?? []) {
409
+ out(printable(` ${accessPersonName(member.user)} ${member.role} (membership ${member.id})\n`));
410
+ }
411
+ const invites = (result.invites ?? []).filter((invite) => invite.status === "active");
412
+ out("\nPending invitations:\n");
413
+ if (invites.length === 0)
414
+ out(" None\n");
415
+ for (const invite of invites) {
416
+ out(printable(` ${invite.email} ${invite.role} ${invite.status} (invite ${invite.id})\n`));
417
+ }
418
+ const requests = (result.accessRequests ?? []).filter((request) => request.state === "pending");
419
+ out("\nPending access requests:\n");
420
+ if (requests.length === 0)
421
+ out(" None\n");
422
+ for (const request of requests) {
423
+ out(printable(` ${accessPersonName(request.requester)} (request ${request.id})\n`));
424
+ }
425
+ return;
426
+ }
427
+ const member = before?.memberships?.find((row) => row.id === command.target);
428
+ const request = before?.accessRequests?.find((row) => row.id === command.target);
429
+ const memberName = member ? accessPersonName(member.user) : `membership ${command.target}`;
430
+ const requester = request ? accessPersonName(request.requester) : `request ${command.target}`;
431
+ switch (command.action) {
432
+ case "invite":
433
+ out(printable(`Invited ${result.invite.email} as ${result.invite.role} (invite ${result.invite.id}).\n`));
434
+ break;
435
+ case "resend":
436
+ out(printable(`Resent invitation to ${result.invite.email} as ${result.invite.role} (invite ${result.invite.id}).\n`));
437
+ break;
438
+ case "revoke":
439
+ out(printable(`Revoked invite ${command.target} in workspace ${workspaceId}.\n`));
440
+ break;
441
+ case "approve":
442
+ out(printable(`Approved ${requester} as ${result.membership.role} (membership ${result.membership.id}).\n`));
443
+ break;
444
+ case "deny":
445
+ out(printable(`Denied access for ${requester} (request ${command.target}).\n`));
446
+ break;
447
+ case "role":
448
+ out(printable(`Changed ${memberName} to ${result.membership.role} (membership ${result.membership.id}).\n`));
449
+ break;
450
+ case "remove":
451
+ out(printable(`Removed ${memberName} from workspace ${workspaceId} (membership ${command.target}).\n`));
452
+ break;
453
+ case "transfer":
454
+ out(printable(`Transferred workspace ${workspaceId} ownership to ${memberName} (membership ${result.to.id}); your role is now ${result.from.role}.\n`));
455
+ break;
456
+ case "leave":
457
+ out(printable(`Left workspace ${workspaceId}.\n`));
458
+ break;
459
+ }
460
+ return;
461
+ }
462
+ case "subscriptions": {
463
+ const progress = inv.json ? process.stderr : process.stdout;
464
+ return subscriptions(command, {
465
+ client,
466
+ workspaceId: workspaceOf(config, inv.workspace),
467
+ json: inv.json,
468
+ out,
469
+ notice: (text) => { progress.write(text); },
470
+ openBrowser: inv.noBrowser ? null : openBrowser,
471
+ askSecret: (question) => askSecret(question, process.stdin, progress),
472
+ });
473
+ }
474
+ case "billing":
475
+ await runBilling(client, workspaceOf(config, inv.workspace), { ...inv, command }, { out, openBrowser });
476
+ return;
477
+ case "connect":
478
+ await runConnect(client, workspaceOf(config, inv.workspace), { ...inv, command }, { out, openBrowser });
479
+ return;
238
480
  case "whoami": {
239
481
  const me = await whoAmI(client, config.apiUrl, "me");
240
482
  if (inv.json)
241
483
  return printJson({ ...me, defaultWorkspaceId: config.workspaceId ?? null });
242
- out(printable(`${me.user.githubLogin ? `@${me.user.githubLogin}` : me.user.id}\n`));
484
+ out(printable(`${me.user.githubLogin ? `@${me.user.githubLogin}` : me.user.email}\n`));
243
485
  for (const w of me.workspaces) {
244
486
  out(printable(` ${w.id === config.workspaceId ? "*" : " "} ${w.name} (${w.id}, ${w.role})\n`));
245
487
  }
@@ -268,6 +510,52 @@ async function main(argv) {
268
510
  out("Set the default with: sinatra workspace <id>\n");
269
511
  return;
270
512
  }
513
+ case "workspace-pr-review": {
514
+ const workspaceId = workspaceOf(config, inv.workspace);
515
+ const settings = command.value === undefined
516
+ ? await client.getWorkspacePrReviewSettings(workspaceId)
517
+ : await client.setWorkspacePrReviewSettings(workspaceId, command.value);
518
+ if (inv.json)
519
+ return printJson(settings);
520
+ out(`External PR reviews: ${settings.reviewExternalPrs ? "on" : "off"}\n`);
521
+ return;
522
+ }
523
+ case "workspace-create":
524
+ return runWorkspaceCreate(client, { ...inv, command }, { read: readConfig, write: (c) => writeConfig(c), fallback: config, out });
525
+ case "workspace-show": {
526
+ const workspace = await client.getWorkspace(workspaceOf(config, inv.workspace));
527
+ if (inv.json)
528
+ return printJson(workspace);
529
+ const { github, linear, slack, telegram, planStatus, defaultModel } = workspace;
530
+ out(printable(`${workspace.name} (${workspace.id})\nRole: ${workspace.role}\n`));
531
+ out(printable(`GitHub: ${github.status}${github.accountLogin ? ` (${github.accountLogin})` : ""}\n`));
532
+ out(printable(`Linear: ${linear.status}${linear.organizationName ? ` (${linear.organizationName})` : ""}\n`));
533
+ out(printable(`Slack: ${slack.available ? slack.status : "unavailable"}${slack.teamName ? ` (${slack.teamName})` : ""}\n`));
534
+ out(`Telegram: ${!telegram.available ? "unavailable" : telegram.enabled ? "enabled" : "disabled"}\n`);
535
+ out(printable(`Plan: ${planStatus.capacity?.plan ?? planStatus.plan}${planStatus.subscription ? ` (${planStatus.subscription.status})` : ""}\n`));
536
+ if (planStatus.capacity)
537
+ out(`Capacity limits: ${planStatus.capacity.running} running, ${planStatus.capacity.queued} queued\n`);
538
+ out(printable(`Default model: ${defaultModel ? `${defaultModel.model} (${defaultModel.engine}${defaultModel.effort ? `, ${defaultModel.effort}` : ""})` : "not configured"}\n`));
539
+ out(printable(`Repositories (${workspace.repoCatalog}): ${workspace.repos.length}\n`));
540
+ for (const repo of workspace.repos) {
541
+ out(printable(` ${repo.name}${repo.shortDescription ? ` — ${repo.shortDescription}` : ""}\n`));
542
+ }
543
+ return;
544
+ }
545
+ case "account": {
546
+ const account = await client.account();
547
+ if (inv.json)
548
+ return printJson(account);
549
+ out(`Your account:\n${printable(JSON.stringify(account, null, 2))}\n`);
550
+ return;
551
+ }
552
+ case "email-preferences": {
553
+ const preferences = await client.emailPreferences(inv.emailPreferences);
554
+ if (inv.json)
555
+ return printJson(preferences);
556
+ out(`Setup reminders: ${preferences.setupReminders ? "on" : "off"}\nTask alerts: ${preferences.taskAlerts ? "on" : "off"}\n`);
557
+ return;
558
+ }
271
559
  case "tasks": {
272
560
  const result = await client.listTasks(workspaceOf(config, inv.workspace), {
273
561
  limit: inv.limit ?? 20,
@@ -311,7 +599,7 @@ async function main(argv) {
311
599
  if (!result.linear.connected)
312
600
  out("Linear isn't connected to this workspace.\n");
313
601
  else if (!result.linear.identityLinked)
314
- out("Link your Linear account in Settings to see Linear issues.\n");
602
+ out("Connect your Linear account in Settings to see Linear issues.\n");
315
603
  if (!result.github.connected)
316
604
  out("GitHub isn't connected to this workspace.\n");
317
605
  out(result.tickets.length === 0
@@ -343,7 +631,11 @@ async function main(argv) {
343
631
  const workspaceId = workspaceOf(config, inv.workspace);
344
632
  const attachments = await readAttachments(inv.files);
345
633
  const repos = repoChoices(inv.repo, inv.repo ? [] : await detectRepos());
346
- const body = { prompt: composePrompt(command.prompt, attachments), ...(inv.title ? { title: inv.title } : {}) };
634
+ const body = {
635
+ prompt: composePrompt(command.prompt, attachments),
636
+ ...(inv.title ? { title: inv.title } : {}),
637
+ ...(inv.model ? { model: inv.model } : {}),
638
+ };
347
639
  // With --json, stdout is only the JSON: notices go to stderr.
348
640
  const notice = (text) => (inv.json ? process.stderr : process.stdout).write(`${printable(text)}\n`);
349
641
  const { started, repo } = await startTask(client, workspaceId, body, repos, notice);
package/dist/oauth.js CHANGED
@@ -10,6 +10,7 @@
10
10
  import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
11
11
  import { spawn } from "node:child_process";
12
12
  import { createServer } from "node:http";
13
+ import { CLI_VERSION } from "./version.js";
13
14
  /** A sign-in that can't go on, said for the person: nothing to retry in place. */
14
15
  export class SignInError extends Error {
15
16
  }
@@ -66,7 +67,7 @@ export function openBrowser(url, platform = process.platform) {
66
67
  async function postForm(fetchFn, url, params, timeoutMs = REQUEST_TIMEOUT_MS) {
67
68
  const response = await fetchFn(url, {
68
69
  method: "POST",
69
- headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
70
+ headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json", "x-sinatra-cli-version": CLI_VERSION },
70
71
  body: new URLSearchParams(params).toString(),
71
72
  signal: AbortSignal.timeout(timeoutMs),
72
73
  });
@@ -118,7 +119,10 @@ function refusal(code) {
118
119
  }
119
120
  /** Checks the server has an authorization server, and that it is the one this API URL names. */
120
121
  async function checkAuthorizationServer(fetchFn, endpoints) {
121
- const response = await fetchFn(endpoints.metadata, { headers: { accept: "application/json" }, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
122
+ const response = await fetchFn(endpoints.metadata, {
123
+ headers: { accept: "application/json", "x-sinatra-cli-version": CLI_VERSION },
124
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
125
+ });
122
126
  if (response.status === 404)
123
127
  throw new SignInError(`This Sinatra API doesn't offer browser sign-in. ${PASTE_INSTEAD}`);
124
128
  const metadata = (await response.json().catch(() => null));
package/dist/prompt.js CHANGED
@@ -8,13 +8,13 @@ import { createInterface } from "node:readline";
8
8
  * the first swallow the lines meant for the next.
9
9
  */
10
10
  let piped = null;
11
- async function nextPipedLine(input) {
11
+ async function nextPipedLine(input, trim = true) {
12
12
  piped ??= (() => {
13
13
  const rl = createInterface({ input, terminal: false });
14
14
  return { rl, lines: rl[Symbol.asyncIterator]() };
15
15
  })();
16
16
  const next = await piped.lines.next();
17
- return next.done ? "" : String(next.value).trim();
17
+ return next.done ? "" : trim ? String(next.value).trim() : String(next.value);
18
18
  }
19
19
  /** One line from the person. */
20
20
  export async function ask(question, input = process.stdin, output = process.stdout) {
@@ -36,9 +36,13 @@ const ESCAPE_SEQUENCE = /\u001b\[[0-9;?]*[ -/]*[@-~]/g;
36
36
  * deletes, Ctrl-C aborts) and keeps only printable characters, so a bracketed paste or an arrow
37
37
  * key can't end up in it; piped input isn't echoed anyway, so that's read as a line.
38
38
  */
39
- export async function askSecret(question, input = process.stdin, output = process.stdout) {
40
- if (!input.isTTY || !input.setRawMode)
41
- return ask(question, input, output);
39
+ export async function askSecret(question, input = process.stdin, output = process.stdout, mode = "token") {
40
+ if (!input.isTTY || !input.setRawMode) {
41
+ if (mode === "token")
42
+ return ask(question, input, output);
43
+ output.write(question);
44
+ return nextPipedLine(input, false);
45
+ }
42
46
  output.write(question);
43
47
  input.setRawMode(true);
44
48
  input.setEncoding?.("utf8");
@@ -60,7 +64,7 @@ export async function askSecret(question, input = process.stdin, output = proces
60
64
  }
61
65
  if (char === "\u007f" || char === "\b")
62
66
  value = value.slice(0, -1);
63
- else if (char >= "!" && char <= "~")
67
+ else if (mode === "value" ? !/[\u0000-\u001f\u007f-\u009f]/u.test(char) : char >= "!" && char <= "~")
64
68
  value += char;
65
69
  }
66
70
  };
@@ -0,0 +1,4 @@
1
+ import { readFileSync } from "node:fs";
2
+ // package.json sits next to dist/ (and src/), in the installed package too.
3
+ const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
4
+ export const CLI_VERSION = pkg.version ?? "unknown";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sinatra.dev",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Hand coding tasks to Sinatra from your terminal.",
5
5
  "keywords": [
6
6
  "sinatra",