sinatra.dev 0.1.0 → 0.1.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 +10 -1
- package/dist/commands.js +50 -1
- package/dist/follow.js +10 -3
- package/dist/index.js +17 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,15 @@ Create a personal access token on the **Access tokens** page of the Sinatra dash
|
|
|
23
23
|
workspace, pick the default one. The token is saved in `~/.config/sinatra/config.json`
|
|
24
24
|
(`$XDG_CONFIG_HOME/sinatra` if set, `%APPDATA%\sinatra` on Windows), readable only by you.
|
|
25
25
|
|
|
26
|
+
In a script, pipe the token in and name the default workspace with `-w`:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
sinatra login -w <workspace-id> < token-file
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Without `-w`, piped input isn't asked for a workspace: set one later with `sinatra workspace <id>`.
|
|
33
|
+
A `-w` that isn't one of the token's workspaces is an error, and nothing is saved.
|
|
34
|
+
|
|
26
35
|
## Commands
|
|
27
36
|
|
|
28
37
|
```sh
|
|
@@ -39,7 +48,7 @@ sinatra logout # revoke the token and forget it
|
|
|
39
48
|
|
|
40
49
|
| Command | Options |
|
|
41
50
|
| --- | --- |
|
|
42
|
-
| `sinatra login` | `--api-url <url>`: another Sinatra API (https; plain http only for localhost) |
|
|
51
|
+
| `sinatra login` | `--api-url <url>`: another Sinatra API (https; plain http only for localhost); `-w, --workspace <id>`: the default workspace |
|
|
43
52
|
| `sinatra [start] "<what to do>"` | `-r, --repo <owner/name>`, `-f, --file <path>` (repeatable), `-t, --title <title>`, `-w, --workspace <id>`, `--timeout <minutes>`, `--no-wait`, `--json` (with `--no-wait`) |
|
|
44
53
|
| `sinatra reply <task-id> "<message>"` | `-f, --file <path>` (repeatable), `-w`, `--timeout <minutes>`, `--no-wait`, `--json` (with `--no-wait`) |
|
|
45
54
|
| `sinatra show <task-id>` | `-w`, `--json` |
|
package/dist/commands.js
CHANGED
|
@@ -84,7 +84,7 @@ const APPLIES_TO = {
|
|
|
84
84
|
repo: ["start"],
|
|
85
85
|
file: ["start", "reply"],
|
|
86
86
|
title: ["start"],
|
|
87
|
-
workspace: ["start", "reply", "show", "tasks", "stop"],
|
|
87
|
+
workspace: ["start", "reply", "show", "tasks", "stop", "login"],
|
|
88
88
|
"no-wait": ["start", "reply"],
|
|
89
89
|
timeout: ["start", "reply"],
|
|
90
90
|
json: ["whoami", "tasks", "show", "start", "reply"],
|
|
@@ -219,6 +219,55 @@ export async function startTask(client, workspaceId, body, repos, notice) {
|
|
|
219
219
|
}
|
|
220
220
|
return { started: await client.startTask(workspaceId, body), repo: null };
|
|
221
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* `sinatra login`: read a token, check it, pick the default workspace, save. A `--workspace`
|
|
224
|
+
* that isn't one of the token's workspaces is refused before anything is saved, so a script's
|
|
225
|
+
* typo leaves the previous login as it was.
|
|
226
|
+
*/
|
|
227
|
+
export async function login(deps) {
|
|
228
|
+
const { out } = deps;
|
|
229
|
+
// The sign-in page sends a signed-in visitor straight on, and a signed-out one there after signing in.
|
|
230
|
+
out(deps.apiUrl === DEFAULT_API_URL
|
|
231
|
+
? `Create a personal access token at ${DEFAULT_APP_URL}/login?returnTo=%2Ftokens, then paste it here.\n`
|
|
232
|
+
: "Create a personal access token on your Sinatra dashboard's Access tokens page, then paste it here.\n");
|
|
233
|
+
const token = await deps.askSecret("Token (hidden): ");
|
|
234
|
+
if (!token)
|
|
235
|
+
throw new UsageError("No token given.");
|
|
236
|
+
const me = await deps.me(token);
|
|
237
|
+
const workspaceId = await loginWorkspace(me.workspaces, deps);
|
|
238
|
+
await deps.save({ apiUrl: deps.apiUrl, token, ...(workspaceId ? { workspaceId } : {}) });
|
|
239
|
+
const name = me.user.githubLogin ? `@${me.user.githubLogin}` : me.user.name ?? me.user.id;
|
|
240
|
+
const workspace = me.workspaces.find((w) => w.id === workspaceId)?.name;
|
|
241
|
+
out(printable(`Logged in as ${name}${workspace ? `, workspace ${workspace}` : ""}.\n`));
|
|
242
|
+
}
|
|
243
|
+
/** The default workspace to save at login, if any. */
|
|
244
|
+
async function loginWorkspace(workspaces, deps) {
|
|
245
|
+
const { out } = deps;
|
|
246
|
+
if (deps.workspace !== undefined) {
|
|
247
|
+
const chosen = workspaces.find((w) => w.id === deps.workspace);
|
|
248
|
+
if (chosen)
|
|
249
|
+
return chosen.id;
|
|
250
|
+
const yours = workspaces.map((w) => `${w.name} (${w.id})`).join(", ");
|
|
251
|
+
throw new UsageError(printable(`${deps.workspace} isn't one of this token's workspaces${yours ? ` (${yours})` : ""}. Nothing was saved.`));
|
|
252
|
+
}
|
|
253
|
+
if (workspaces.length === 1)
|
|
254
|
+
return workspaces[0].id;
|
|
255
|
+
if (workspaces.length === 0)
|
|
256
|
+
return undefined;
|
|
257
|
+
if (!deps.interactive) {
|
|
258
|
+
// Piped stdin has nothing left after the token: asking would only read end-of-input.
|
|
259
|
+
out("No default workspace saved: you belong to more than one. Set one with `sinatra workspace <id>`, or log in with --workspace <id>.\n");
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
workspaces.forEach((w, i) => out(printable(` ${i + 1}. ${w.name} (${w.id})\n`)));
|
|
263
|
+
for (let tries = 0; tries < 3; tries++) {
|
|
264
|
+
const id = workspaces[Number(await deps.ask("Default workspace number: ")) - 1]?.id;
|
|
265
|
+
if (id)
|
|
266
|
+
return id;
|
|
267
|
+
}
|
|
268
|
+
out("No default workspace saved; pass -w <id> to commands, or set one with `sinatra workspace <id>`.\n");
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
222
271
|
/** Where to make (or revoke) a token, for the API a config points at. */
|
|
223
272
|
export function tokensPage(apiUrl) {
|
|
224
273
|
return apiUrl === DEFAULT_API_URL ? `${DEFAULT_APP_URL}/tokens` : "your Sinatra dashboard's Access tokens page";
|
package/dist/follow.js
CHANGED
|
@@ -6,10 +6,17 @@
|
|
|
6
6
|
* The workstream statuses (`TRANSITIONS` in packages/shared/src/lib/workstream-state.ts), split by
|
|
7
7
|
* what following does with them. A task in one of these is still working on its turn.
|
|
8
8
|
*/
|
|
9
|
-
const WORKING =
|
|
9
|
+
const WORKING = {
|
|
10
|
+
pending: true,
|
|
11
|
+
investigating: true,
|
|
12
|
+
brainstorming: true,
|
|
13
|
+
planning: true,
|
|
14
|
+
implementing: true,
|
|
15
|
+
rework: true,
|
|
16
|
+
};
|
|
10
17
|
/**
|
|
11
18
|
* Finished, or paused until someone acts (billing, access, or a retired review gate): nothing
|
|
12
|
-
* more happens on its own. The rest (`
|
|
19
|
+
* more happens on its own. The rest (`replied`, `pr_open`) wait on your next message.
|
|
13
20
|
*/
|
|
14
21
|
const STOPPED = new Set(["completed", "cancelled", "failed", "payment_required", "auth_required", "brainstorm_review", "plan_review"]);
|
|
15
22
|
/** Of those, the ones where the work didn't get done. */
|
|
@@ -25,7 +32,7 @@ export const DEFAULT_FOLLOW_TIMEOUT_MS = 30 * 60_000;
|
|
|
25
32
|
/** Exit codes a script can tell apart. */
|
|
26
33
|
export const EXIT = { ok: 0, error: 1, taskFailed: 2, stillWorking: 3 };
|
|
27
34
|
export function turnDone(task) {
|
|
28
|
-
return !
|
|
35
|
+
return !Object.hasOwn(WORKING, task.status);
|
|
29
36
|
}
|
|
30
37
|
/** The task ended up failed, cancelled, or paused on access or billing. */
|
|
31
38
|
export function turnFailed(task) {
|
package/dist/index.js
CHANGED
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { readFileSync } from "node:fs";
|
|
11
11
|
import { ApiError, createClient } from "./client.js";
|
|
12
|
-
import { explain, logout, parseInvocation, printable, repoChoices, revokeSavedToken, startTask, UsageError } from "./commands.js";
|
|
13
|
-
import { ConfigError, DEFAULT_API_URL,
|
|
12
|
+
import { explain, login, logout, parseInvocation, printable, repoChoices, revokeSavedToken, startTask, UsageError } from "./commands.js";
|
|
13
|
+
import { ConfigError, DEFAULT_API_URL, deleteConfig, readConfig, writeConfig } from "./config.js";
|
|
14
14
|
import { AttachmentError, composePrompt, detectRepos, readAttachments } from "./context.js";
|
|
15
15
|
import { EXIT, followOutcome, followTask } from "./follow.js";
|
|
16
16
|
import { ask, askSecret } from "./prompt.js";
|
|
17
17
|
const USAGE = `Usage:
|
|
18
|
-
sinatra login [--api-url <url>]
|
|
18
|
+
sinatra login [--api-url <url>] [-w <id>]
|
|
19
|
+
Save a personal access token (-w: its default workspace)
|
|
19
20
|
sinatra [start] "<what to do>" Start a task and follow it
|
|
20
21
|
-r, --repo <owner/name> Repository (default: this checkout's GitHub remote)
|
|
21
22
|
-f, --file <path> Attach a text file (repeatable, 80KB total)
|
|
@@ -105,32 +106,6 @@ function checkApiUrl(raw) {
|
|
|
105
106
|
}
|
|
106
107
|
return url.href.replace(/\/+$/, "");
|
|
107
108
|
}
|
|
108
|
-
async function login(apiUrl) {
|
|
109
|
-
// The sign-in page sends a signed-in visitor straight on, and a signed-out one there after signing in.
|
|
110
|
-
out(apiUrl === DEFAULT_API_URL
|
|
111
|
-
? `Create a personal access token at ${DEFAULT_APP_URL}/login?returnTo=%2Ftokens, then paste it here.\n`
|
|
112
|
-
: "Create a personal access token on your Sinatra dashboard's Access tokens page, then paste it here.\n");
|
|
113
|
-
const token = await askSecret("Token (hidden): ");
|
|
114
|
-
if (!token)
|
|
115
|
-
throw new UsageError("No token given.");
|
|
116
|
-
const me = await whoAmI(createClient({ apiUrl, token }), apiUrl, "login");
|
|
117
|
-
let workspaceId;
|
|
118
|
-
if (me.workspaces.length === 1) {
|
|
119
|
-
workspaceId = me.workspaces[0].id;
|
|
120
|
-
}
|
|
121
|
-
else if (me.workspaces.length > 1) {
|
|
122
|
-
me.workspaces.forEach((w, i) => out(printable(` ${i + 1}. ${w.name} (${w.id})\n`)));
|
|
123
|
-
for (let tries = 0; tries < 3 && !workspaceId; tries++) {
|
|
124
|
-
workspaceId = me.workspaces[Number(await ask("Default workspace number: ")) - 1]?.id;
|
|
125
|
-
}
|
|
126
|
-
if (!workspaceId)
|
|
127
|
-
out("No default workspace saved; pass -w <id> to commands, or set one with `sinatra workspace <id>`.\n");
|
|
128
|
-
}
|
|
129
|
-
await writeConfig({ apiUrl, token, ...(workspaceId ? { workspaceId } : {}) });
|
|
130
|
-
const name = me.user.githubLogin ? `@${me.user.githubLogin}` : me.user.name ?? me.user.id;
|
|
131
|
-
const workspace = me.workspaces.find((w) => w.id === workspaceId)?.name;
|
|
132
|
-
out(printable(`Logged in as ${name}${workspace ? `, workspace ${workspace}` : ""}.\n`));
|
|
133
|
-
}
|
|
134
109
|
async function follow(client, workspaceId, taskId, options) {
|
|
135
110
|
out("Waiting for Sinatra (Ctrl-C stops waiting; the task keeps going)...\n");
|
|
136
111
|
const result = await followTask(client, {
|
|
@@ -200,8 +175,19 @@ async function main(argv) {
|
|
|
200
175
|
case "version":
|
|
201
176
|
out(`${version()}\n`);
|
|
202
177
|
return;
|
|
203
|
-
case "login":
|
|
204
|
-
|
|
178
|
+
case "login": {
|
|
179
|
+
const apiUrl = checkApiUrl(inv.apiUrl ?? DEFAULT_API_URL);
|
|
180
|
+
return login({
|
|
181
|
+
apiUrl,
|
|
182
|
+
...(inv.workspace !== undefined ? { workspace: inv.workspace } : {}),
|
|
183
|
+
interactive: Boolean(process.stdin.isTTY),
|
|
184
|
+
askSecret: (question) => askSecret(question),
|
|
185
|
+
ask: (question) => ask(question),
|
|
186
|
+
me: (token) => whoAmI(createClient({ apiUrl, token }), apiUrl, "login"),
|
|
187
|
+
save: (config) => writeConfig(config),
|
|
188
|
+
out,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
205
191
|
case "logout": {
|
|
206
192
|
const result = await logout({
|
|
207
193
|
read: readConfig,
|