sinatra.dev 0.2.0 → 0.3.1

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
@@ -26,8 +26,8 @@ stops waiting after 5 minutes.
26
26
  The sign-in is saved in `~/.config/sinatra/config.json` (`$XDG_CONFIG_HOME/sinatra` if set,
27
27
  `%APPDATA%\sinatra` on Windows), readable only by you. Its access token lasts an hour, and the CLI
28
28
  renews it as it goes. It stays signed in for up to 90 days, or until it goes 30 days unused; after
29
- that, or if you disconnect **Sinatra CLI** under **Connected apps** on the dashboard's Access
30
- tokens page (<https://app.sinatra.dev/tokens>), the CLI asks you to run `sinatra login` again.
29
+ that, or if you disconnect **Sinatra CLI** under **Connected apps** on the dashboard's **CLI & API**
30
+ page (<https://app.sinatra.dev/tokens>), the CLI asks you to run `sinatra login` again.
31
31
 
32
32
  If the browser doesn't open, `sinatra login --no-browser` prints the URL to open instead. The
33
33
  browser must run on the same computer as the CLI, because Sinatra sends it back to a port the CLI
@@ -38,7 +38,7 @@ access token instead:
38
38
  sinatra login --token
39
39
  ```
40
40
 
41
- Create a token on the Access tokens page and paste it in; it isn't echoed.
41
+ Create a token on the same **CLI & API** page and paste it in; it isn't echoed.
42
42
 
43
43
  In a script, pipe the token in and name the default workspace with `-w`. Piped input always reads a
44
44
  token, without `--token`:
@@ -59,6 +59,8 @@ sinatra reply <task-id> "also update the docs" # follow up, then follow it
59
59
  sinatra show <task-id> # a task and its conversation
60
60
  sinatra tasks # recent tasks in your workspace
61
61
  sinatra stop <task-id> # stop a running turn
62
+ sinatra tickets -q "flaky login" # open Linear and GitHub issues you could delegate
63
+ sinatra delegate ENG-123 # hand Sinatra a Linear or GitHub issue (owner/name#12, or its URL) as you
62
64
  sinatra whoami # who you're logged in as, and your workspaces
63
65
  sinatra workspace [<id>] # list workspaces, or set the default
64
66
  sinatra logout # end the sign-in (or revoke the token) and forget it
@@ -72,6 +74,8 @@ sinatra logout # end the sign-in (or revoke the
72
74
  | `sinatra show <task-id>` | `-w`, `--json` |
73
75
  | `sinatra tasks` | `--status <status>`, `-n, --limit <n>` (1 to 100, default 20), `-w`, `--json` |
74
76
  | `sinatra stop <task-id>` | `-w` |
77
+ | `sinatra tickets` | `-q, --query <text>`, `-r, --repo <owner/name>` (searched first), `-w`, `--json` |
78
+ | `sinatra delegate <ticket>` | `-w` |
75
79
  | `sinatra whoami` | `--json` |
76
80
  | `sinatra workspace [<id>]` | none |
77
81
  | `sinatra logout` | none |
@@ -90,8 +94,9 @@ An option a command doesn't use is an error, not silently ignored.
90
94
  - **Attachments:** `-f` attaches text files to a new task or a reply, up to 80KB together. Binary
91
95
  files are refused.
92
96
  - **Following:** after `start` or `reply`, the CLI prints what Sinatra posts until the turn is
93
- done: Sinatra replied, or the task finished, failed, was cancelled, or paused. While the task waits
94
- for a free slot in your workspace's plan, it says so. It stops waiting after `--timeout` minutes
97
+ done: Sinatra replied, or the task finished, failed, was cancelled, or paused. If the task is
98
+ queued because your workspace is running as many tasks at a time as its plan allows, the CLI
99
+ says so. It stops waiting after `--timeout` minutes
95
100
  (30 by default); the task keeps going. Ctrl-C stops waiting too. After a `reply` to a task that
96
101
  had already stopped, if Sinatra hasn't picked the message up within two minutes, the CLI says so
97
102
  (exit 3) instead of reporting the previous turn's result.
@@ -105,8 +110,8 @@ An option a command doesn't use is an error, not silently ignored.
105
110
  has exactly that command's shape. `sinatra start "..."` always starts one.
106
111
  - **Logout:** `sinatra logout` ends the browser sign-in on Sinatra (or revokes the token you
107
112
  pasted), then deletes the local file. If Sinatra can't be reached, the file is still deleted and
108
- the CLI warns that the sign-in or token may still be active: disconnect or revoke it on the Access
109
- tokens page.
113
+ the CLI warns that the sign-in or token may still be active: disconnect or revoke it on the
114
+ **CLI & API** page.
110
115
  - **Retries:** every request that changes something carries an idempotency key, so a retry after a
111
116
  dropped connection never starts a second task or sends a message twice.
112
117
 
package/dist/client.js CHANGED
@@ -92,5 +92,15 @@ export function createClient(options) {
92
92
  followUp: (workspaceId, taskId, text) => request("POST", `/v1/workspaces/${workspaceId}/tasks/${taskId}/messages`, { text }),
93
93
  messages: (workspaceId, taskId, after) => request("GET", `/v1/workspaces/${workspaceId}/tasks/${taskId}/messages${after ? `?after=${encodeURIComponent(after)}` : ""}`),
94
94
  stopTask: (workspaceId, taskId) => request("POST", `/v1/workspaces/${workspaceId}/tasks/${taskId}/stop`),
95
+ searchTickets: (workspaceId, query = {}) => {
96
+ const params = new URLSearchParams();
97
+ if (query.q)
98
+ params.set("q", query.q);
99
+ if (query.repo)
100
+ params.set("repo", query.repo);
101
+ const qs = params.toString();
102
+ return request("GET", `/v1/workspaces/${workspaceId}/tickets${qs ? `?${qs}` : ""}`);
103
+ },
104
+ delegateTicket: (workspaceId, ticket) => request("POST", `/v1/workspaces/${workspaceId}/tickets/delegate`, ticket),
95
105
  };
96
106
  }
package/dist/commands.js CHANGED
@@ -4,6 +4,17 @@ import { ApiError, createClient } from "./client.js";
4
4
  import { ConfigError, DEFAULT_API_URL, DEFAULT_APP_URL } from "./config.js";
5
5
  import { DEFAULT_FOLLOW_TIMEOUT_MS } from "./follow.js";
6
6
  import { revokeSignIn } from "./oauth.js";
7
+ /**
8
+ * A ticket reference as a person pastes it: `ENG-123`, a Linear issue URL, `owner/name#12` or a
9
+ * GitHub issue URL. Null for anything else.
10
+ */
11
+ export function parseTicket(ref) {
12
+ const github = ref.match(/^(?:https:\/\/github\.com\/)?([\w.-]+\/[\w.-]+)(?:#|\/issues\/)(\d+)\/?$/i);
13
+ if (github)
14
+ return { source: "github", repo: github[1], number: Number(github[2]) };
15
+ const linear = ref.match(/^(?:https:\/\/linear\.app\/[^/]+\/issue\/)?([a-z][a-z0-9]*-\d+)(?:\/[^/]*)?$/i);
16
+ return linear ? { source: "linear", id: linear[1].toUpperCase() } : null;
17
+ }
7
18
  /** A mistake in how the CLI was called, or anything else to say before exiting with 1. */
8
19
  export class UsageError extends Error {
9
20
  }
@@ -38,6 +49,7 @@ export function parseCommand(positionals) {
38
49
  case "logout":
39
50
  case "whoami":
40
51
  case "tasks":
52
+ case "tickets":
41
53
  if (rest.length === 0)
42
54
  return { name: first };
43
55
  if (first === "login" && rest.some((word) => word.startsWith("sntr_"))) {
@@ -66,11 +78,20 @@ export function parseCommand(positionals) {
66
78
  if (!prose || TASK_ID.test(rest[0]))
67
79
  return usage('Usage: sinatra reply <task-id> "<message>"');
68
80
  break;
81
+ case "delegate": {
82
+ const ticket = rest.length === 1 ? parseTicket(rest[0]) : null;
83
+ if (ticket)
84
+ return { name: "delegate", ticket };
85
+ if (!prose)
86
+ return usage("Usage: sinatra delegate <ticket> (ENG-123, owner/name#12, or the issue's URL)");
87
+ break;
88
+ }
69
89
  }
70
90
  return { name: "start", prompt: positionals.join(" ").trim() };
71
91
  }
72
92
  const OPTIONS = {
73
93
  repo: { type: "string", short: "r" },
94
+ query: { type: "string", short: "q" },
74
95
  file: { type: "string", short: "f", multiple: true },
75
96
  title: { type: "string", short: "t" },
76
97
  workspace: { type: "string", short: "w" },
@@ -87,13 +108,14 @@ const OPTIONS = {
87
108
  };
88
109
  /** The commands each option means something to; given to any other, it's a mistake. */
89
110
  const APPLIES_TO = {
90
- repo: ["start"],
111
+ repo: ["start", "tickets"],
112
+ query: ["tickets"],
91
113
  file: ["start", "reply"],
92
114
  title: ["start"],
93
- workspace: ["start", "reply", "show", "tasks", "stop", "login"],
115
+ workspace: ["start", "reply", "show", "tasks", "stop", "tickets", "delegate", "login"],
94
116
  "no-wait": ["start", "reply"],
95
117
  timeout: ["start", "reply"],
96
- json: ["whoami", "tasks", "show", "start", "reply"],
118
+ json: ["whoami", "tasks", "show", "start", "reply", "tickets"],
97
119
  status: ["tasks"],
98
120
  limit: ["tasks"],
99
121
  "api-url": ["login"],
@@ -172,6 +194,7 @@ export function parseInvocation(argv) {
172
194
  pasteToken: values.token ?? false,
173
195
  noBrowser: values["no-browser"] ?? false,
174
196
  ...(values.repo !== undefined ? { repo: values.repo } : {}),
197
+ ...(values.query !== undefined ? { query: values.query } : {}),
175
198
  ...(values.title !== undefined ? { title: values.title } : {}),
176
199
  ...(values.workspace !== undefined ? { workspace: values.workspace } : {}),
177
200
  ...(values.status !== undefined ? { status: values.status } : {}),
@@ -223,8 +246,9 @@ export function repoChoices(named, detected) {
223
246
  * Starts the task on the first repository the workspace accepts, and says which that was. One
224
247
  * the person named is never second-guessed: its refusal is the answer. Detected ones are tried in
225
248
  * order (a fork's `origin`, then the `upstream` it came from), and when none is connected the
226
- * agent picks, which is said first. Every attempt is its own request with its own idempotency
227
- * key: the server refuses an unconnected repository before creating anything.
249
+ * agent picks, which is said first. In a workspace without GitHub no detected repository can be
250
+ * connected, so the task goes ahead without one. Every attempt is its own request with its own
251
+ * idempotency key: the server refuses an unconnected repository before creating anything.
228
252
  */
229
253
  export async function startTask(client, workspaceId, body, repos, notice) {
230
254
  const label = (repo) => (repo.explicit ? repo.name : `${repo.name} (this checkout's ${repo.remote} remote)`);
@@ -233,7 +257,14 @@ export async function startTask(client, workspaceId, body, repos, notice) {
233
257
  return { started: await client.startTask(workspaceId, { ...body, repo: repo.name }), repo };
234
258
  }
235
259
  catch (error) {
236
- if (repo.explicit || !(error instanceof ApiError && error.code === "invalid_repo"))
260
+ if (repo.explicit || !(error instanceof ApiError))
261
+ throw error;
262
+ if (error.code === "github_not_connected" && error.detail.refusal === "missing") {
263
+ notice("This workspace isn't connected to GitHub, so Sinatra will answer without a repository. " +
264
+ "Connect GitHub on the dashboard to have it change code.");
265
+ break;
266
+ }
267
+ if (error.code !== "invalid_repo")
237
268
  throw error;
238
269
  const next = repos[i + 1];
239
270
  notice(next
@@ -248,7 +279,7 @@ async function pastedToken(deps) {
248
279
  // The sign-in page sends a signed-in visitor straight on, and a signed-out one there after signing in.
249
280
  deps.out(deps.apiUrl === DEFAULT_API_URL
250
281
  ? `Create a personal access token at ${DEFAULT_APP_URL}/login?returnTo=%2Ftokens, then paste it here.\n`
251
- : "Create a personal access token on your Sinatra dashboard's Access tokens page, then paste it here.\n");
282
+ : "Create a personal access token under CLI & API in your Sinatra dashboard, then paste it here.\n");
252
283
  const token = await deps.askSecret("Token (hidden): ");
253
284
  if (!token)
254
285
  throw new UsageError("No token given.");
@@ -280,7 +311,7 @@ export async function login(deps) {
280
311
  ...(signedIn.oauth ? { oauth: signedIn.oauth } : {}),
281
312
  ...(workspaceId ? { workspaceId } : {}),
282
313
  });
283
- const name = me.user.githubLogin ? `@${me.user.githubLogin}` : me.user.name ?? me.user.id;
314
+ const name = me.user.githubLogin ? `@${me.user.githubLogin}` : me.user.email;
284
315
  const workspace = me.workspaces.find((w) => w.id === workspaceId)?.name;
285
316
  out(printable(`Logged in as ${name}${workspace ? `, workspace ${workspace}` : ""}.\n`));
286
317
  }
@@ -315,7 +346,7 @@ async function loginWorkspace(workspaces, deps) {
315
346
  }
316
347
  /** Where to make (or revoke) a token, and disconnect a sign-in, for the API a config points at. */
317
348
  export function tokensPage(apiUrl) {
318
- return apiUrl === DEFAULT_API_URL ? `${DEFAULT_APP_URL}/tokens` : "your Sinatra dashboard's Access tokens page";
349
+ return apiUrl === DEFAULT_API_URL ? `${DEFAULT_APP_URL}/tokens` : "your Sinatra dashboard's CLI & API page";
319
350
  }
320
351
  /**
321
352
  * Revoking the saved credential at logout: one attempt, bounded, so an unreachable server can't
@@ -344,7 +375,7 @@ export async function logout(deps) {
344
375
  await deps.forget();
345
376
  return {
346
377
  message: "Removed the damaged config.",
347
- warning: `If it held a token or a sign-in, revoke or disconnect it on ${tokensPage(DEFAULT_API_URL)} (or your dashboard's Access tokens page).`,
378
+ warning: `If it held a token or a sign-in, revoke or disconnect it on ${tokensPage(DEFAULT_API_URL)} (or your dashboard's CLI & API page).`,
348
379
  };
349
380
  }
350
381
  if (!config) {
@@ -383,19 +414,12 @@ export function printable(text) {
383
414
  // and bidirectional overrides, which can make printed text read differently than it is.
384
415
  return text.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f‪-‮⁦-⁩]/g, "");
385
416
  }
386
- /** The running-task cap when the server doesn't say. */
387
- const DEFAULT_RUNNING_CAP = "5";
388
417
  export function classifyRefusal(error, context = {}) {
389
418
  switch (error.code) {
390
419
  case "invalid_token":
391
420
  return { kind: context.during === "login" ? "token_rejected_at_login" : "token_invalid" };
392
421
  case "not_found":
393
422
  return { kind: context.during ? "task_api_off" : "not_found" };
394
- case "too_many_running": {
395
- const raw = error.detail.limit;
396
- const limit = (typeof raw === "string" || typeof raw === "number") && /^\d+$/.test(String(raw)) ? String(raw) : DEFAULT_RUNNING_CAP;
397
- return { kind: "too_many_running", limit };
398
- }
399
423
  case "unavailable":
400
424
  if (typeof error.detail.taskId === "string")
401
425
  return { kind: "created_not_started", taskId: error.detail.taskId };
@@ -416,13 +440,15 @@ export function explain(error, context = {}) {
416
440
  case "task_api_off":
417
441
  return "The task API isn't available for this account. Write to contact@sinatra.dev if you think it should be.";
418
442
  case "not_found": return "No such task or workspace, or you're not a member of it.";
419
- case "too_many_running": return `You already have ${refusal.limit} CLI, MCP or API tasks starting, running or queued in this workspace; wait for one to finish its turn.`;
420
443
  case "created_not_started":
421
444
  return `Task ${refusal.taskId} was created but Sinatra couldn't start it yet. Run \`sinatra reply ${refusal.taskId} "go"\` to start it (your prompt goes first).`;
422
445
  case "message_saved_not_sent":
423
446
  return "Sinatra saved your message but couldn't hand it over yet. Don't send it again: it goes out first with your next message to this task.";
424
447
  case "unreachable": return "Sinatra couldn't be reached; try again shortly.";
425
448
  }
449
+ // A refusal the server explained itself (delegation's are the dashboard's own words).
450
+ if (typeof error.detail.reason === "string")
451
+ return printable(error.detail.reason);
426
452
  switch (refusal.code) {
427
453
  case "invalid_prompt": return "The message is empty or too long.";
428
454
  case "invalid_repo": return "That repository isn't connected to this workspace (see the dashboard's Repositories page).";
package/dist/index.js CHANGED
@@ -5,6 +5,8 @@
5
5
  * sinatra login sign in through the browser (--token: paste a token)
6
6
  * sinatra "fix the flaky test" start a task and follow it until its turn is done
7
7
  * sinatra reply <task> "also docs" follow up on a task
8
+ * sinatra tickets -q "login" find open Linear and GitHub issues you could delegate
9
+ * sinatra delegate ENG-123 hand Sinatra an existing Linear or GitHub issue
8
10
  * sinatra tasks | show <task> | stop <task> | whoami | workspace [id] | logout
9
11
  */
10
12
  import { readFileSync } from "node:fs";
@@ -36,6 +38,11 @@ const USAGE = `Usage:
36
38
  sinatra tasks [--status <status>] [-n, --limit <n>] [--json]
37
39
  List the workspace's recent tasks (20 unless -n)
38
40
  sinatra stop <task-id> Stop a task's running turn
41
+ sinatra tickets [-q <text>] [-r <owner/name>] [--json]
42
+ Open Linear and GitHub issues you could delegate: yours,
43
+ then the team's unassigned (-q: search, -r: repo first)
44
+ sinatra delegate <ticket> Hand Sinatra a Linear or GitHub issue as you: ENG-123,
45
+ owner/name#12, or the issue's URL
39
46
  sinatra whoami [--json] Who you're logged in as, and your workspaces
40
47
  sinatra workspace [<id>] List your workspaces, or make one the default
41
48
  sinatra logout Revoke the saved sign-in or token and forget it
@@ -119,7 +126,7 @@ async function follow(client, workspaceId, taskId, options) {
119
126
  taskId,
120
127
  ...options,
121
128
  print,
122
- onQueued: () => out("Queued: waiting for a free slot in this workspace's plan.\n"),
129
+ onQueued: () => out("Queued: this workspace is running as many tasks at a time as its plan allows.\n"),
123
130
  });
124
131
  const { task } = result;
125
132
  if (task.pullRequest)
@@ -232,7 +239,7 @@ async function main(argv) {
232
239
  const me = await whoAmI(client, config.apiUrl, "me");
233
240
  if (inv.json)
234
241
  return printJson({ ...me, defaultWorkspaceId: config.workspaceId ?? null });
235
- out(printable(`${me.user.githubLogin ? `@${me.user.githubLogin}` : me.user.id}\n`));
242
+ out(printable(`${me.user.githubLogin ? `@${me.user.githubLogin}` : me.user.email}\n`));
236
243
  for (const w of me.workspaces) {
237
244
  out(printable(` ${w.id === config.workspaceId ? "*" : " "} ${w.name} (${w.id}, ${w.role})\n`));
238
245
  }
@@ -291,6 +298,31 @@ async function main(argv) {
291
298
  await client.stopTask(workspaceOf(config, inv.workspace), command.taskId);
292
299
  out("Stop requested.\n");
293
300
  return;
301
+ case "tickets": {
302
+ const result = await client.searchTickets(workspaceOf(config, inv.workspace), {
303
+ ...(inv.query ? { q: inv.query } : {}),
304
+ ...(inv.repo ? { repo: inv.repo } : {}),
305
+ });
306
+ if (inv.json)
307
+ return printJson(result);
308
+ for (const t of result.tickets) {
309
+ out(printable(`${t.identifier.padEnd(24)} ${t.title}${t.yours ? " (yours)" : ""}\n`));
310
+ }
311
+ if (!result.linear.connected)
312
+ out("Linear isn't connected to this workspace.\n");
313
+ else if (!result.linear.identityLinked)
314
+ out("Link your Linear account in Settings to see Linear issues.\n");
315
+ if (!result.github.connected)
316
+ out("GitHub isn't connected to this workspace.\n");
317
+ out(result.tickets.length === 0
318
+ ? (inv.query ? "No open issues match.\n" : "No open issues to delegate.\n")
319
+ : "Delegate one with: sinatra delegate <ticket>\n");
320
+ return;
321
+ }
322
+ case "delegate":
323
+ await client.delegateTicket(workspaceOf(config, inv.workspace), command.ticket);
324
+ out("Delegated. Sinatra answers on the issue; follow it there or with `sinatra tasks`.\n");
325
+ return;
294
326
  case "reply": {
295
327
  const workspaceId = workspaceOf(config, inv.workspace);
296
328
  const text = composePrompt(command.text, await readAttachments(inv.files));
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "sinatra.dev",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Hand coding tasks to Sinatra from your terminal.",
5
5
  "keywords": [
6
6
  "sinatra",
7
+ "sinatra.dev",
7
8
  "cli",
9
+ "terminal",
8
10
  "coding-agent",
11
+ "background-agent",
12
+ "ai-coding-agent",
9
13
  "ai",
10
14
  "github",
11
15
  "pull-request",
16
+ "developer-tools",
12
17
  "automation"
13
18
  ],
14
19
  "homepage": "https://docs.sinatra.dev/docs/cli-and-api",