sinatra.dev 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +245 -13
- package/dist/client.js +79 -10
- package/dist/commands.js +1081 -8
- package/dist/index.js +233 -48
- package/dist/oauth.js +6 -2
- package/dist/prompt.js +10 -6
- package/dist/version.js +4 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,56 +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
|
|
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, runConnectors, runRepo, runWorkspaceCreate, startTask, subscriptions, USAGE, 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";
|
|
21
|
-
|
|
22
|
-
sinatra login [--api-url <url>] [-w <id>] [--no-browser | --token]
|
|
23
|
-
Sign in through your browser (-w: the default workspace)
|
|
24
|
-
--no-browser Print the sign-in URL instead of opening it (the browser
|
|
25
|
-
must still be on this computer)
|
|
26
|
-
--token Paste a personal access token instead (also when stdin
|
|
27
|
-
is piped: sinatra login < token-file)
|
|
28
|
-
sinatra [start] "<what to do>" Start a task and follow it
|
|
29
|
-
-r, --repo <owner/name> Repository (default: this checkout's GitHub remote)
|
|
30
|
-
-f, --file <path> Attach a text file (repeatable, 80KB total)
|
|
31
|
-
-t, --title <title> Task title (default: the prompt's first line)
|
|
32
|
-
--timeout <minutes> Stop following after this long (default 30)
|
|
33
|
-
--no-wait Start it and return
|
|
34
|
-
--json With --no-wait: print the started task as JSON
|
|
35
|
-
sinatra reply <task-id> "<message>" Follow up on a task, then follow it
|
|
36
|
-
(takes -f, --timeout, --no-wait, --json like start)
|
|
37
|
-
sinatra show <task-id> [--json] Print a task and its conversation
|
|
38
|
-
sinatra tasks [--status <status>] [-n, --limit <n>] [--json]
|
|
39
|
-
List the workspace's recent tasks (20 unless -n)
|
|
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
|
|
46
|
-
sinatra whoami [--json] Who you're logged in as, and your workspaces
|
|
47
|
-
sinatra workspace [<id>] List your workspaces, or make one the default
|
|
48
|
-
sinatra logout Revoke the saved sign-in or token and forget it
|
|
49
|
-
sinatra -v, --version Print the CLI's version
|
|
50
|
-
|
|
51
|
-
-w, --workspace <id> Workspace for any task command (default: yours from
|
|
52
|
-
login or \`sinatra workspace\`)
|
|
53
|
-
|
|
54
|
-
Exit codes: 0 done, 1 error, 2 the task failed, was cancelled or is paused,
|
|
55
|
-
3 still working (or your reply not picked up yet) when the CLI stopped waiting.`;
|
|
20
|
+
import { CLI_VERSION } from "./version.js";
|
|
56
21
|
/** How a follow ended, for a task that stopped rather than waiting on you. */
|
|
57
22
|
const ENDINGS = {
|
|
58
23
|
completed: "Task completed.",
|
|
@@ -61,11 +26,6 @@ const ENDINGS = {
|
|
|
61
26
|
payment_required: "Paused: the workspace's plan or model access needs attention on the dashboard.",
|
|
62
27
|
auth_required: "Paused: Sinatra needs access granted on the dashboard before it can go on.",
|
|
63
28
|
};
|
|
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
29
|
function out(text) {
|
|
70
30
|
process.stdout.write(text);
|
|
71
31
|
}
|
|
@@ -77,10 +37,13 @@ function print(message) {
|
|
|
77
37
|
out(`\n${who}:\n${printable(message.body)}\n`);
|
|
78
38
|
}
|
|
79
39
|
function describe(task) {
|
|
80
|
-
const status = task.queued ? `${task.status} (
|
|
40
|
+
const status = task.queued ? `${task.status} (waiting)` : task.status;
|
|
81
41
|
const pr = task.pullRequest ? ` ${task.pullRequest.url}${task.pullRequest.merged ? " (merged)" : ""}` : "";
|
|
82
42
|
return printable(`${task.id} ${status.padEnd(14)} ${task.title ?? "(untitled)"}${pr}`);
|
|
83
43
|
}
|
|
44
|
+
function accessPersonName(person) {
|
|
45
|
+
return person.name || (person.githubLogin ? `@${person.githubLogin}` : person.id);
|
|
46
|
+
}
|
|
84
47
|
async function loggedIn() {
|
|
85
48
|
const config = await readConfig();
|
|
86
49
|
if (!config)
|
|
@@ -126,7 +89,7 @@ async function follow(client, workspaceId, taskId, options) {
|
|
|
126
89
|
taskId,
|
|
127
90
|
...options,
|
|
128
91
|
print,
|
|
129
|
-
onQueued: () => out("
|
|
92
|
+
onQueued: () => out("Waiting: this workspace is running as many agents at a time as its plan allows.\n"),
|
|
130
93
|
});
|
|
131
94
|
const { task } = result;
|
|
132
95
|
if (task.pullRequest)
|
|
@@ -186,7 +149,7 @@ async function main(argv) {
|
|
|
186
149
|
out(`${USAGE}\n`);
|
|
187
150
|
return;
|
|
188
151
|
case "version":
|
|
189
|
-
out(`${
|
|
152
|
+
out(`${CLI_VERSION}\n`);
|
|
190
153
|
return;
|
|
191
154
|
case "login": {
|
|
192
155
|
const apiUrl = checkApiUrl(inv.apiUrl ?? DEFAULT_API_URL);
|
|
@@ -233,8 +196,176 @@ async function main(argv) {
|
|
|
233
196
|
token: credentialsFor(config, {
|
|
234
197
|
store: { read: readConfig, write: (c) => writeConfig(c), forget: deleteConfig, lock: (fn) => withConfigLock(fn) },
|
|
235
198
|
}),
|
|
199
|
+
...(command.name === "subscriptions" ? { timeoutMs: 30_000 } : {}),
|
|
200
|
+
...(command.name === "connect" ? { timeoutMs: Math.min(inv.timeoutMs, 30_000) } : {}),
|
|
236
201
|
});
|
|
237
202
|
switch (command.name) {
|
|
203
|
+
case "repos":
|
|
204
|
+
case "repo":
|
|
205
|
+
await runRepo(client, workspaceOf(config, inv.workspace), { ...inv, command }, {
|
|
206
|
+
out,
|
|
207
|
+
ask: (question) => ask(question, process.stdin, process.stderr),
|
|
208
|
+
askSecret: (question) => askSecret(question, process.stdin, process.stderr, "value"),
|
|
209
|
+
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
210
|
+
});
|
|
211
|
+
return;
|
|
212
|
+
case "model": {
|
|
213
|
+
const workspaceId = workspaceOf(config, inv.workspace);
|
|
214
|
+
await confirmWorkspaceMutation(command, {
|
|
215
|
+
yes: inv.yes ?? false,
|
|
216
|
+
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
217
|
+
workspaceId,
|
|
218
|
+
ask: (question) => ask(question, process.stdin, process.stderr),
|
|
219
|
+
});
|
|
220
|
+
const result = command.action === "set"
|
|
221
|
+
? await client.setModelDefault(workspaceId, {
|
|
222
|
+
engine: inv.engine, model: command.model,
|
|
223
|
+
...(inv.effort !== undefined ? { effort: inv.effort } : {}),
|
|
224
|
+
})
|
|
225
|
+
: command.action === "clear"
|
|
226
|
+
? await client.clearModelDefault(workspaceId)
|
|
227
|
+
: await client.getModelDefault(workspaceId);
|
|
228
|
+
if (inv.json)
|
|
229
|
+
return printJson(result);
|
|
230
|
+
if (command.action === "clear")
|
|
231
|
+
out("Workspace model default cleared; automatic selection restored.\n");
|
|
232
|
+
else if (result.selection) {
|
|
233
|
+
const { engine, model, effort } = result.selection;
|
|
234
|
+
out(printable(`Workspace model default: ${engine} / ${model}${effort ? ` (effort: ${effort})` : ""}\n`));
|
|
235
|
+
}
|
|
236
|
+
else
|
|
237
|
+
out("No workspace model default saved; automatic selection is enabled.\n");
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
case "keys": {
|
|
241
|
+
const workspaceId = workspaceOf(config, inv.workspace);
|
|
242
|
+
await confirmWorkspaceMutation(command, {
|
|
243
|
+
yes: inv.yes ?? false,
|
|
244
|
+
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
245
|
+
workspaceId,
|
|
246
|
+
ask: (question) => ask(question, process.stdin, process.stderr),
|
|
247
|
+
});
|
|
248
|
+
if (command.action === "list") {
|
|
249
|
+
const result = await client.listModelKeys(workspaceId);
|
|
250
|
+
if (inv.json)
|
|
251
|
+
return printJson(result);
|
|
252
|
+
if (result.credentials.length === 0)
|
|
253
|
+
out("No workspace model keys configured.\n");
|
|
254
|
+
for (const credential of result.credentials)
|
|
255
|
+
out(printable(`${credential.provider} ${credential.status}\n`));
|
|
256
|
+
}
|
|
257
|
+
else if (command.action === "add") {
|
|
258
|
+
const result = await addWorkspaceModelKey(client, workspaceId, command.provider, (question) => askSecret(question, process.stdin, process.stderr));
|
|
259
|
+
if (inv.json)
|
|
260
|
+
return printJson(result);
|
|
261
|
+
out(`${result.provider} key configured.\n`);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
const { result, message } = await removeWorkspaceModelKey(client, workspaceId, command.provider);
|
|
265
|
+
if (inv.json)
|
|
266
|
+
return printJson(result);
|
|
267
|
+
out(`${message}\n`);
|
|
268
|
+
}
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
case "access": {
|
|
272
|
+
const workspaceId = workspaceOf(config, inv.workspace);
|
|
273
|
+
await confirmWorkspaceMutation(command, {
|
|
274
|
+
yes: inv.yes ?? false,
|
|
275
|
+
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
276
|
+
workspaceId,
|
|
277
|
+
ask: (question) => ask(question, process.stdin, process.stderr),
|
|
278
|
+
});
|
|
279
|
+
const before = !inv.json && ["role", "remove", "transfer", "approve", "deny"].includes(command.action)
|
|
280
|
+
? await client.workspaceAccess(workspaceId, "list")
|
|
281
|
+
: undefined;
|
|
282
|
+
const result = await client.workspaceAccess(workspaceId, command.action, command.target, inv.role);
|
|
283
|
+
if (inv.json)
|
|
284
|
+
return printJson(result);
|
|
285
|
+
if (command.action === "list") {
|
|
286
|
+
out("Members:\n");
|
|
287
|
+
for (const member of result.memberships ?? []) {
|
|
288
|
+
out(printable(` ${accessPersonName(member.user)} ${member.role} (membership ${member.id})\n`));
|
|
289
|
+
}
|
|
290
|
+
const invites = (result.invites ?? []).filter((invite) => invite.status === "active");
|
|
291
|
+
out("\nPending invitations:\n");
|
|
292
|
+
if (invites.length === 0)
|
|
293
|
+
out(" None\n");
|
|
294
|
+
for (const invite of invites) {
|
|
295
|
+
out(printable(` ${invite.email} ${invite.role} ${invite.status} (invite ${invite.id})\n`));
|
|
296
|
+
}
|
|
297
|
+
const requests = (result.accessRequests ?? []).filter((request) => request.state === "pending");
|
|
298
|
+
out("\nPending access requests:\n");
|
|
299
|
+
if (requests.length === 0)
|
|
300
|
+
out(" None\n");
|
|
301
|
+
for (const request of requests) {
|
|
302
|
+
out(printable(` ${accessPersonName(request.requester)} (request ${request.id})\n`));
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const member = before?.memberships?.find((row) => row.id === command.target);
|
|
307
|
+
const request = before?.accessRequests?.find((row) => row.id === command.target);
|
|
308
|
+
const memberName = member ? accessPersonName(member.user) : `membership ${command.target}`;
|
|
309
|
+
const requester = request ? accessPersonName(request.requester) : `request ${command.target}`;
|
|
310
|
+
switch (command.action) {
|
|
311
|
+
case "invite":
|
|
312
|
+
out(printable(`Invited ${result.invite.email} as ${result.invite.role} (invite ${result.invite.id}).\n`));
|
|
313
|
+
break;
|
|
314
|
+
case "resend":
|
|
315
|
+
out(printable(`Resent invitation to ${result.invite.email} as ${result.invite.role} (invite ${result.invite.id}).\n`));
|
|
316
|
+
break;
|
|
317
|
+
case "revoke":
|
|
318
|
+
out(printable(`Revoked invite ${command.target} in workspace ${workspaceId}.\n`));
|
|
319
|
+
break;
|
|
320
|
+
case "approve":
|
|
321
|
+
out(printable(`Approved ${requester} as ${result.membership.role} (membership ${result.membership.id}).\n`));
|
|
322
|
+
break;
|
|
323
|
+
case "deny":
|
|
324
|
+
out(printable(`Denied access for ${requester} (request ${command.target}).\n`));
|
|
325
|
+
break;
|
|
326
|
+
case "role":
|
|
327
|
+
out(printable(`Changed ${memberName} to ${result.membership.role} (membership ${result.membership.id}).\n`));
|
|
328
|
+
break;
|
|
329
|
+
case "remove":
|
|
330
|
+
out(printable(`Removed ${memberName} from workspace ${workspaceId} (membership ${command.target}).\n`));
|
|
331
|
+
break;
|
|
332
|
+
case "transfer":
|
|
333
|
+
out(printable(`Transferred workspace ${workspaceId} ownership to ${memberName} (membership ${result.to.id}); your role is now ${result.from.role}.\n`));
|
|
334
|
+
break;
|
|
335
|
+
case "leave":
|
|
336
|
+
out(printable(`Left workspace ${workspaceId}.\n`));
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
case "subscriptions": {
|
|
342
|
+
const progress = inv.json ? process.stderr : process.stdout;
|
|
343
|
+
return subscriptions(command, {
|
|
344
|
+
client,
|
|
345
|
+
workspaceId: workspaceOf(config, inv.workspace),
|
|
346
|
+
json: inv.json,
|
|
347
|
+
out,
|
|
348
|
+
notice: (text) => { progress.write(text); },
|
|
349
|
+
openBrowser: inv.noBrowser ? null : openBrowser,
|
|
350
|
+
askSecret: (question) => askSecret(question, process.stdin, progress),
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
case "billing":
|
|
354
|
+
await runBilling(client, workspaceOf(config, inv.workspace), { ...inv, command }, { out, openBrowser });
|
|
355
|
+
return;
|
|
356
|
+
case "connect":
|
|
357
|
+
await runConnect(client, workspaceOf(config, inv.workspace), { ...inv, command }, { out, openBrowser });
|
|
358
|
+
return;
|
|
359
|
+
case "connectors":
|
|
360
|
+
await runConnectors(client, workspaceOf(config, inv.workspace), { ...inv, command }, {
|
|
361
|
+
out,
|
|
362
|
+
notice: (text) => { process.stderr.write(text); },
|
|
363
|
+
ask: (question) => ask(question, process.stdin, process.stderr),
|
|
364
|
+
askSecret: (question) => askSecret(question, process.stdin, process.stderr, "value"),
|
|
365
|
+
interactive: Boolean(process.stdin.isTTY && process.stderr.isTTY),
|
|
366
|
+
openBrowser,
|
|
367
|
+
});
|
|
368
|
+
return;
|
|
238
369
|
case "whoami": {
|
|
239
370
|
const me = await whoAmI(client, config.apiUrl, "me");
|
|
240
371
|
if (inv.json)
|
|
@@ -268,6 +399,56 @@ async function main(argv) {
|
|
|
268
399
|
out("Set the default with: sinatra workspace <id>\n");
|
|
269
400
|
return;
|
|
270
401
|
}
|
|
402
|
+
case "workspace-pr-review": {
|
|
403
|
+
const workspaceId = workspaceOf(config, inv.workspace);
|
|
404
|
+
const settings = command.value === undefined
|
|
405
|
+
? await client.getWorkspacePrReviewSettings(workspaceId)
|
|
406
|
+
: await client.setWorkspacePrReviewSettings(workspaceId, command.value);
|
|
407
|
+
if (inv.json)
|
|
408
|
+
return printJson(settings);
|
|
409
|
+
out(`External PR reviews: ${settings.reviewExternalPrs ? "on" : "off"}\n`);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
case "workspace-create":
|
|
413
|
+
return runWorkspaceCreate(client, { ...inv, command }, { read: readConfig, write: (c) => writeConfig(c), fallback: config, out });
|
|
414
|
+
case "workspace-show": {
|
|
415
|
+
const workspace = await client.getWorkspace(workspaceOf(config, inv.workspace));
|
|
416
|
+
if (inv.json)
|
|
417
|
+
return printJson(workspace);
|
|
418
|
+
const { github, linear, slack, telegram, buzz, planStatus, defaultModel } = workspace;
|
|
419
|
+
out(printable(`${workspace.name} (${workspace.id})\nRole: ${workspace.role}\n`));
|
|
420
|
+
out(printable(`GitHub: ${github.status}${github.accountLogin ? ` (${github.accountLogin})` : ""}\n`));
|
|
421
|
+
out(printable(`Linear: ${linear.status}${linear.organizationName ? ` (${linear.organizationName})` : ""}\n`));
|
|
422
|
+
out(printable(`Slack: ${slack.available ? slack.status : "unavailable"}${slack.teamName ? ` (${slack.teamName})` : ""}\n`));
|
|
423
|
+
out(`Telegram: ${!telegram.available ? "unavailable" : telegram.enabled ? "enabled" : "disabled"}\n`);
|
|
424
|
+
if (buzz?.available)
|
|
425
|
+
out(printable(`Buzz: ${buzz.status ?? "not connected"}${buzz.host ? ` (${buzz.host})` : ""}\n`));
|
|
426
|
+
if (workspace.connectors?.available)
|
|
427
|
+
out("Connectors: available\n");
|
|
428
|
+
out(printable(`Plan: ${planStatus.capacity?.plan ?? planStatus.plan}${planStatus.subscription ? ` (${planStatus.subscription.status})` : ""}\n`));
|
|
429
|
+
if (planStatus.capacity)
|
|
430
|
+
out(`Capacity limits: ${planStatus.capacity.running} running, ${planStatus.capacity.queued} queued\n`);
|
|
431
|
+
out(printable(`Default model: ${defaultModel ? `${defaultModel.model} (${defaultModel.engine}${defaultModel.effort ? `, ${defaultModel.effort}` : ""})` : "not configured"}\n`));
|
|
432
|
+
out(printable(`Repositories (${workspace.repoCatalog}): ${workspace.repos.length}\n`));
|
|
433
|
+
for (const repo of workspace.repos) {
|
|
434
|
+
out(printable(` ${repo.name}${repo.shortDescription ? ` — ${repo.shortDescription}` : ""}\n`));
|
|
435
|
+
}
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
case "account": {
|
|
439
|
+
const account = await client.account();
|
|
440
|
+
if (inv.json)
|
|
441
|
+
return printJson(account);
|
|
442
|
+
out(`Your account:\n${printable(JSON.stringify(account, null, 2))}\n`);
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
case "email-preferences": {
|
|
446
|
+
const preferences = await client.emailPreferences(inv.emailPreferences);
|
|
447
|
+
if (inv.json)
|
|
448
|
+
return printJson(preferences);
|
|
449
|
+
out(`Setup reminders: ${preferences.setupReminders ? "on" : "off"}\nTask alerts: ${preferences.taskAlerts ? "on" : "off"}\n`);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
271
452
|
case "tasks": {
|
|
272
453
|
const result = await client.listTasks(workspaceOf(config, inv.workspace), {
|
|
273
454
|
limit: inv.limit ?? 20,
|
|
@@ -311,7 +492,7 @@ async function main(argv) {
|
|
|
311
492
|
if (!result.linear.connected)
|
|
312
493
|
out("Linear isn't connected to this workspace.\n");
|
|
313
494
|
else if (!result.linear.identityLinked)
|
|
314
|
-
out("
|
|
495
|
+
out("Connect your Linear account in Settings to see Linear issues.\n");
|
|
315
496
|
if (!result.github.connected)
|
|
316
497
|
out("GitHub isn't connected to this workspace.\n");
|
|
317
498
|
out(result.tickets.length === 0
|
|
@@ -343,7 +524,11 @@ async function main(argv) {
|
|
|
343
524
|
const workspaceId = workspaceOf(config, inv.workspace);
|
|
344
525
|
const attachments = await readAttachments(inv.files);
|
|
345
526
|
const repos = repoChoices(inv.repo, inv.repo ? [] : await detectRepos());
|
|
346
|
-
const body = {
|
|
527
|
+
const body = {
|
|
528
|
+
prompt: composePrompt(command.prompt, attachments),
|
|
529
|
+
...(inv.title ? { title: inv.title } : {}),
|
|
530
|
+
...(inv.model ? { model: inv.model } : {}),
|
|
531
|
+
};
|
|
347
532
|
// With --json, stdout is only the JSON: notices go to stderr.
|
|
348
533
|
const notice = (text) => (inv.json ? process.stderr : process.stdout).write(`${printable(text)}\n`);
|
|
349
534
|
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, {
|
|
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
|
-
|
|
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
|
};
|
package/dist/version.js
ADDED