sekura 0.2.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/README.md +49 -11
- package/dist/api.js +4 -2
- package/dist/auth.js +46 -19
- package/dist/catalogue.js +21 -1
- package/dist/cli.js +12 -7
- package/dist/commands/billing.js +60 -0
- package/dist/commands/init.js +137 -55
- package/dist/commands/login.js +11 -10
- package/dist/commands/pay.js +84 -0
- package/dist/device.js +87 -0
- package/dist/guide.js +150 -102
- package/dist/payment.js +37 -0
- package/dist/skill.js +6 -4
- package/dist/ui.js +60 -0
- package/dist/writers.js +5 -1
- package/package.json +2 -2
- package/skills/sekura/SKILL.md +117 -40
package/dist/guide.js
CHANGED
|
@@ -1,53 +1,65 @@
|
|
|
1
1
|
// The steps after the install that used to happen inside the coding tool:
|
|
2
|
-
// signing in, the GitHub App
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
|
|
2
|
+
// signing in, the Terms, the GitHub App and a repository. Shared by `init`
|
|
3
|
+
// and `login`. Nothing here starts a scan or charges anything: every scan is
|
|
4
|
+
// quoted and agreed in the coding tool. Where the person has to finish
|
|
5
|
+
// something in the browser, the terminal asks Sekura until it is done
|
|
6
|
+
// rather than waiting for Enter.
|
|
7
|
+
import { confirm, select } from '@inquirer/prompts';
|
|
7
8
|
import { spawnSync } from 'node:child_process';
|
|
8
9
|
import { forgetKey, openBrowser, readKey, redact, saveKey, signIn } from './auth.js';
|
|
9
10
|
import { getAccount, listRepositories, SignedOut } from './api.js';
|
|
10
|
-
import { carriesKey, onPath, SERVER_NAME } from './catalogue.js';
|
|
11
|
+
import { carriesKey, nextStep, onPath, SERVER_NAME } from './catalogue.js';
|
|
11
12
|
import { currentGithubRepo } from './repo.js';
|
|
12
|
-
import { cross, dot, say, tick } from './ui.js';
|
|
13
|
+
import { cross, dot, say, tick, waitFor } from './ui.js';
|
|
13
14
|
const START = 'https://sekura.ai/app/start';
|
|
14
15
|
const DASHBOARD = 'https://sekura.ai/app';
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* then sign in on their own, as they always could.
|
|
17
|
+
* The key already here: SEKURA_API_KEY or the stored one, when Sekura still
|
|
18
|
+
* takes it. A revoked stored key is forgotten. Null when there is none.
|
|
19
19
|
*/
|
|
20
|
-
export async function
|
|
20
|
+
export async function existingSession() {
|
|
21
21
|
const fromEnv = !!process.env.SEKURA_API_KEY?.trim();
|
|
22
22
|
const existing = readKey();
|
|
23
|
-
if (existing)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
if (!existing)
|
|
24
|
+
return null;
|
|
25
|
+
try {
|
|
26
|
+
const account = await getAccount(existing);
|
|
27
|
+
say(`${tick} Signed in to Sekura as ${account.email ?? account.name ?? redact(existing)}${fromEnv ? ' (SEKURA_API_KEY)' : ''}`);
|
|
28
|
+
return { key: existing, account };
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (!(e instanceof SignedOut)) {
|
|
32
|
+
// Offline, or Sekura did not answer: the key is likely fine, and
|
|
33
|
+
// writing it now saves the person a sign-in later.
|
|
34
|
+
say(`${dot} Using your saved Sekura key ${redact(existing)}; Sekura could not be asked who it belongs to (${e.message}).`);
|
|
35
|
+
return { key: existing, account: null };
|
|
28
36
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// writing it now saves the person a sign-in later.
|
|
33
|
-
say(`${dot} Using your saved Sekura key ${redact(existing)}; Sekura could not be asked who it belongs to (${e.message}).`);
|
|
34
|
-
return { key: existing, account: null };
|
|
35
|
-
}
|
|
36
|
-
if (fromEnv) {
|
|
37
|
-
say(`${cross} SEKURA_API_KEY is not a valid Sekura key (${e.message}); it was not used.`);
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
forgetKey();
|
|
41
|
-
say(`${dot} Your saved Sekura key no longer works (${e.message}); sign in again.`);
|
|
37
|
+
if (fromEnv) {
|
|
38
|
+
say(`${cross} SEKURA_API_KEY is not a valid Sekura key (${e.message}); it was not used.`);
|
|
39
|
+
return null;
|
|
42
40
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
if (opts.ask !== false && !(await confirm({ message: 'Sign in to Sekura now, so your tools do not have to? (opens your browser)', default: true })))
|
|
41
|
+
forgetKey();
|
|
42
|
+
say(`${dot} Your saved Sekura key no longer works (${e.message}); sign in again.`);
|
|
47
43
|
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** A fresh sign-in, in this machine's browser or with a code on another
|
|
47
|
+
* device. Null when it did not finish; the tools then sign in on their own. */
|
|
48
|
+
export async function signInHere(opts = {}) {
|
|
49
|
+
say();
|
|
48
50
|
try {
|
|
49
51
|
const key = await signIn({
|
|
50
|
-
|
|
52
|
+
device: opts.device,
|
|
53
|
+
onUrl: (url) => { say(' Opening your browser to sign in to Sekura with GitHub. If it does not open, go to:'); say(` ${url}`); say(); },
|
|
54
|
+
onDevice: (why) => say(` Signing in with a code, because ${why}.`),
|
|
55
|
+
onCode: (c) => {
|
|
56
|
+
say();
|
|
57
|
+
say(` On any device, open ${c.uri} and enter ${c.userCode}`);
|
|
58
|
+
if (c.complete)
|
|
59
|
+
say(` Or open ${c.complete}`);
|
|
60
|
+
say();
|
|
61
|
+
say(' Waiting for you to approve on sekura.ai…');
|
|
62
|
+
},
|
|
51
63
|
});
|
|
52
64
|
let account = null;
|
|
53
65
|
try {
|
|
@@ -60,12 +72,28 @@ export async function obtainKey(opts) {
|
|
|
60
72
|
}
|
|
61
73
|
catch (e) {
|
|
62
74
|
say(`${cross} ${e.message}`);
|
|
63
|
-
say(' Your tools will ask you to sign in the first time they use Sekura instead.');
|
|
64
75
|
return null;
|
|
65
76
|
}
|
|
66
77
|
}
|
|
78
|
+
/** The key here, or a sign-in when the person can give one. */
|
|
79
|
+
export async function obtainKey(opts) {
|
|
80
|
+
const s = await existingSession();
|
|
81
|
+
if (s || !opts.interactive)
|
|
82
|
+
return s;
|
|
83
|
+
return signInHere({ device: opts.device });
|
|
84
|
+
}
|
|
85
|
+
const accountReady = (a) => a.termsAccepted !== false && a.emailVerified !== false;
|
|
86
|
+
/** Asks Sekura until the Terms are accepted and the email verified. */
|
|
87
|
+
export async function waitForAccount(s, wait = {}) {
|
|
88
|
+
const r = await waitFor('Waiting for the Terms and your email on sekura.ai… press Enter to skip', async () => {
|
|
89
|
+
const a = await getAccount(s.key);
|
|
90
|
+
s.account = a;
|
|
91
|
+
return accountReady(a);
|
|
92
|
+
}, wait);
|
|
93
|
+
return r === 'done';
|
|
94
|
+
}
|
|
67
95
|
/** What the account still needs before a scan can start, with the page for it. */
|
|
68
|
-
export async function checkAccount(s, interactive) {
|
|
96
|
+
export async function checkAccount(s, interactive, wait = {}) {
|
|
69
97
|
const a = s.account;
|
|
70
98
|
if (!a)
|
|
71
99
|
return;
|
|
@@ -78,61 +106,82 @@ export async function checkAccount(s, interactive) {
|
|
|
78
106
|
return;
|
|
79
107
|
const page = a.links?.dashboard ?? DASHBOARD;
|
|
80
108
|
say(`${dot} Before a scan can start, ${todo.join(' and ')} on sekura.ai: ${page}`);
|
|
81
|
-
if (interactive
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
109
|
+
if (!interactive || !(await confirm({ message: 'Open sekura.ai to do that now?', default: true })))
|
|
110
|
+
return;
|
|
111
|
+
openBrowser(page);
|
|
112
|
+
if (await waitForAccount(s, wait))
|
|
113
|
+
say(`${tick} Your Sekura account is ready`);
|
|
114
|
+
else
|
|
115
|
+
say(`${dot} Not done yet; finish it at ${page} before your first scan.`);
|
|
85
116
|
}
|
|
86
117
|
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
* nothing to scan, or when this folder's repository is not covered.
|
|
91
|
-
*/
|
|
92
|
-
export async function pickRepository(s, cwd, interactive) {
|
|
93
|
-
const here = currentGithubRepo(cwd);
|
|
94
|
-
const start = s.account?.links?.start ?? START;
|
|
95
|
-
let repos = [];
|
|
96
|
-
for (let attempt = 0;; attempt++) {
|
|
97
|
-
let list;
|
|
98
|
-
try {
|
|
99
|
-
list = await listRepositories(s.key);
|
|
100
|
-
}
|
|
101
|
-
catch (e) {
|
|
102
|
-
say(`${cross} Could not list your repositories: ${e.message}`);
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
118
|
+
async function listAll(key, quiet = false) {
|
|
119
|
+
const list = await listRepositories(key);
|
|
120
|
+
if (!quiet)
|
|
105
121
|
for (const i of list.installations) {
|
|
106
122
|
if (i.error === 'github_sign_in_expired')
|
|
107
123
|
say(`${dot} ${i.account}: GitHub access has expired; sign in at ${DASHBOARD} again to refresh it.`);
|
|
108
124
|
else if (i.error === 'installation_gone')
|
|
109
125
|
say(`${dot} ${i.account}: the Sekura GitHub App is no longer installed there.`);
|
|
110
126
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
127
|
+
return { repos: list.installations.flatMap((i) => i.repositories) };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Asks Sekura until `want` can be scanned, or, with no `want`, until any
|
|
131
|
+
* repository can. Returns the repositories as last listed.
|
|
132
|
+
*/
|
|
133
|
+
export async function waitForRepository(s, want, wait = {}) {
|
|
134
|
+
let repos = [];
|
|
135
|
+
const r = await waitFor('Waiting for the GitHub App install… press Enter to skip', async () => {
|
|
136
|
+
repos = (await listAll(s.key, true)).repos;
|
|
137
|
+
return want ? repos.some((x) => same(x.fullName, want)) : repos.length > 0;
|
|
138
|
+
}, wait);
|
|
139
|
+
return { found: r === 'done', repos };
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The repository to scan first: the one in this folder when Sekura can scan
|
|
143
|
+
* it, else the person's choice. Offers the GitHub App install when there is
|
|
144
|
+
* nothing to scan, or when this folder's repository is not covered, and
|
|
145
|
+
* carries on by itself once the install shows up.
|
|
146
|
+
*/
|
|
147
|
+
export async function pickRepository(s, cwd, interactive, wait = {}) {
|
|
148
|
+
const here = currentGithubRepo(cwd);
|
|
149
|
+
const start = s.account?.links?.start ?? START;
|
|
150
|
+
let repos;
|
|
151
|
+
try {
|
|
152
|
+
repos = (await listAll(s.key)).repos;
|
|
153
|
+
}
|
|
154
|
+
catch (e) {
|
|
155
|
+
say(`${cross} Could not list your repositories: ${e.message}`);
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
const covered = !!here && repos.some((r) => same(r.fullName, here));
|
|
159
|
+
if (!repos.length || (here && !covered)) {
|
|
115
160
|
say(repos.length
|
|
116
161
|
? `${dot} ${here} (this folder) is not one Sekura can scan yet: the Sekura GitHub App needs access to it.`
|
|
117
162
|
: `${dot} The Sekura GitHub App is not installed on any of your GitHub accounts yet, so there is nothing to scan.`);
|
|
118
|
-
if (!interactive)
|
|
163
|
+
if (!interactive)
|
|
119
164
|
say(` Install it and choose repositories at ${start}`);
|
|
120
|
-
|
|
165
|
+
else {
|
|
166
|
+
const go = await select({
|
|
167
|
+
message: repos.length ? `Give Sekura access to ${here}?` : 'Install the Sekura GitHub App?',
|
|
168
|
+
choices: [
|
|
169
|
+
{ name: 'Yes, open sekura.ai (the GitHub App asks which repositories)', value: true },
|
|
170
|
+
{ name: repos.length ? 'No, pick from the repositories Sekura can already scan' : 'Not now', value: false },
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
if (go) {
|
|
174
|
+
openBrowser(start);
|
|
175
|
+
say(` Opened ${start}`);
|
|
176
|
+
// With nothing there yet, any repository is progress; otherwise the
|
|
177
|
+
// one this folder holds is what was asked for.
|
|
178
|
+
const want = repos.length ? here : null;
|
|
179
|
+
const w = await waitForRepository(s, want, wait);
|
|
180
|
+
if (w.repos.length)
|
|
181
|
+
repos = w.repos;
|
|
182
|
+
say(w.found ? `${tick} ${want ? `Sekura can scan ${want}` : 'The Sekura GitHub App is installed'}` : `${dot} Not there yet; you can finish the install later at ${start}`);
|
|
183
|
+
}
|
|
121
184
|
}
|
|
122
|
-
if (attempt >= 3)
|
|
123
|
-
break;
|
|
124
|
-
const go = await select({
|
|
125
|
-
message: repos.length ? `Give Sekura access to ${here}?` : 'Install the Sekura GitHub App?',
|
|
126
|
-
choices: [
|
|
127
|
-
{ name: 'Yes, open sekura.ai (the GitHub App asks which repositories)', value: true },
|
|
128
|
-
{ name: repos.length ? 'No, pick from the repositories Sekura can already scan' : 'Not now', value: false },
|
|
129
|
-
],
|
|
130
|
-
});
|
|
131
|
-
if (!go)
|
|
132
|
-
break;
|
|
133
|
-
openBrowser(start);
|
|
134
|
-
say(` Opened ${start}`);
|
|
135
|
-
await input({ message: 'Press Enter once the GitHub App is installed' });
|
|
136
185
|
}
|
|
137
186
|
const scannable = repos.filter((r) => !r.empty);
|
|
138
187
|
if (!scannable.length)
|
|
@@ -159,40 +208,33 @@ export async function pickRepository(s, cwd, interactive) {
|
|
|
159
208
|
});
|
|
160
209
|
return picked || null;
|
|
161
210
|
}
|
|
162
|
-
/** The
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (interactive && (await confirm({ message: `Open sekura.ai to start your free scan${repo ? ` of ${repo}` : ''}?`, default: true }))) {
|
|
170
|
-
openBrowser(start);
|
|
171
|
-
say(`${tick} Opened ${start}`);
|
|
172
|
-
return true;
|
|
173
|
-
}
|
|
174
|
-
say(` Start it any time at ${start}`);
|
|
175
|
-
return false;
|
|
211
|
+
/** The tool's own sign-in command for a step whose entry cannot carry the
|
|
212
|
+
* key (Codex, Devin), when its binary is here. */
|
|
213
|
+
export function toolLogin(s) {
|
|
214
|
+
if (s.kind !== 'tool' || !s.tool.login || carriesKey(s.target))
|
|
215
|
+
return null;
|
|
216
|
+
const bin = s.target.kind === 'command' ? s.target.bin : null;
|
|
217
|
+
return bin && onPath(bin) ? `${bin} ${s.tool.login.join(' ')}` : null;
|
|
176
218
|
}
|
|
177
219
|
/**
|
|
178
220
|
* Runs the tool's own sign-in for each written entry that could not carry
|
|
179
|
-
* the key
|
|
180
|
-
*
|
|
221
|
+
* the key. The browser is already signed in to sekura.ai, so each is one
|
|
222
|
+
* Approve. `ask: false` when the person already agreed to sign in (init's
|
|
223
|
+
* one question). Returns the names of the tools signed in.
|
|
181
224
|
*/
|
|
182
|
-
export async function runToolLogins(steps, interactive) {
|
|
225
|
+
export async function runToolLogins(steps, interactive, ask = true) {
|
|
183
226
|
const done = new Set();
|
|
184
227
|
if (!interactive)
|
|
185
228
|
return done;
|
|
186
229
|
for (const s of steps) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const bin = s.target.kind === 'command' ? s.target.bin : null;
|
|
190
|
-
if (!bin || !onPath(bin))
|
|
230
|
+
const cmd = toolLogin(s);
|
|
231
|
+
if (!cmd || s.kind !== 'tool')
|
|
191
232
|
continue;
|
|
192
|
-
|
|
193
|
-
if (!(await confirm({ message: `Sign ${s.tool.name} in to Sekura now? (runs ${cmd}; approve in the browser)`, default: true })))
|
|
233
|
+
if (ask && !(await confirm({ message: `Sign ${s.tool.name} in to Sekura now? (runs ${cmd}; approve in the browser)`, default: true })))
|
|
194
234
|
continue;
|
|
195
|
-
|
|
235
|
+
if (!ask)
|
|
236
|
+
say(` ${s.tool.name}: running ${cmd}; approve in the browser`);
|
|
237
|
+
const r = spawnSync(s.target.bin, s.tool.login, { stdio: 'inherit' });
|
|
196
238
|
if (r.status === 0) {
|
|
197
239
|
done.add(s.tool.name);
|
|
198
240
|
say(`${tick} ${s.tool.name} signed in`);
|
|
@@ -202,6 +244,12 @@ export async function runToolLogins(steps, interactive) {
|
|
|
202
244
|
}
|
|
203
245
|
return done;
|
|
204
246
|
}
|
|
247
|
+
/** What to do in each tool now, so it loads the server. */
|
|
248
|
+
export function nextSteps(tools) {
|
|
249
|
+
say(' Next, in each tool:');
|
|
250
|
+
for (const t of tools)
|
|
251
|
+
say(`${dot} ${t.name}: ${nextStep(t)}`);
|
|
252
|
+
}
|
|
205
253
|
/** How to ask for a scan from each connected tool. */
|
|
206
254
|
export function howToScan(tools, repo) {
|
|
207
255
|
const target = repo ?? 'owner/repo';
|
package/dist/payment.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ENDPOINT } from './catalogue.js';
|
|
2
|
+
export const SEKURA_ORIGIN = new URL(ENDPOINT).origin;
|
|
3
|
+
const OPENABLE_HOSTS = new Set(['checkout.stripe.com', 'billing.stripe.com', new URL(ENDPOINT).host]);
|
|
4
|
+
export function openableLink(raw) {
|
|
5
|
+
let url;
|
|
6
|
+
try {
|
|
7
|
+
url = new URL(raw);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const local = url.hostname === '127.0.0.1' || url.hostname === 'localhost';
|
|
13
|
+
if (url.protocol !== 'https:' && !(local && url.protocol === 'http:'))
|
|
14
|
+
return null;
|
|
15
|
+
return OPENABLE_HOSTS.has(url.host) ? url : null;
|
|
16
|
+
}
|
|
17
|
+
export const paymentMethodsLink = () => `${SEKURA_ORIGIN}/app/payment-methods`;
|
|
18
|
+
export const scanLink = (scanId) => `${SEKURA_ORIGIN}/app/scans/${encodeURIComponent(scanId.startsWith('ss-') ? scanId : `ss-${scanId}`)}`;
|
|
19
|
+
const newScanOf = (start, now) => now.lastScan && now.lastScan.id !== start?.lastScan?.id ? now.lastScan : null;
|
|
20
|
+
export function paymentState(start, now) {
|
|
21
|
+
if (!now)
|
|
22
|
+
return start ? { kind: 'cancelled' } : { kind: 'waiting' };
|
|
23
|
+
if (now.status === 'active') {
|
|
24
|
+
const scan = newScanOf(start, now);
|
|
25
|
+
if (scan)
|
|
26
|
+
return { kind: 'started', scanId: scan.id, scanStatus: scan.status };
|
|
27
|
+
const backAsItWas = start?.status === 'pending' && (start.pendingFrom === 'rerun' || start.pendingFrom === 'upgrade') && !now.nextRunAt && !now.pendingFrom;
|
|
28
|
+
return backAsItWas && start.plan === now.plan ? { kind: 'cancelled' } : { kind: 'paid' };
|
|
29
|
+
}
|
|
30
|
+
if (now.status === 'pending' && start?.selected && !now.selected)
|
|
31
|
+
return { kind: 'cancelled' };
|
|
32
|
+
if (now.status === 'canceled')
|
|
33
|
+
return { kind: 'cancelled' };
|
|
34
|
+
return { kind: 'waiting' };
|
|
35
|
+
}
|
|
36
|
+
export const cardLines = (b) => (b.cards ?? []).map((c) => `${c.masked}${c.isDefault ? ' (default)' : ''}`);
|
|
37
|
+
export const cardsFingerprint = (b) => (b.cards ?? []).map((c) => `${c.masked}:${c.isDefault ? 1 : 0}`).join('|');
|
package/dist/skill.js
CHANGED
|
@@ -45,10 +45,12 @@ export const GUIDANCE = `${START}
|
|
|
45
45
|
## Sekura
|
|
46
46
|
|
|
47
47
|
Sekura (the \`${SERVER_NAME}\` MCP server, ${ENDPOINT}) scans a GitHub repository for
|
|
48
|
-
vulnerabilities and proves each finding. Every scan or plan is quoted first
|
|
49
|
-
the user the
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
vulnerabilities and proves each finding. Every scan or plan is quoted first
|
|
49
|
+
(quoteScan, quoteAlways): show the user the quote as it stands, with the price and
|
|
50
|
+
the authorization wording, and call startScan or startAlways with the arguments
|
|
51
|
+
the quote names only after they have agreed in the conversation. Cancelling is
|
|
52
|
+
previewed first the same way. The \`${SERVER_NAME}\` skill
|
|
53
|
+
(.agents/skills/${SERVER_NAME}/SKILL.md) has the tool names and the rules.
|
|
52
54
|
Documentation: ${DOCS}
|
|
53
55
|
${END}
|
|
54
56
|
`;
|
package/dist/ui.js
CHANGED
|
@@ -12,3 +12,63 @@ export function banner() {
|
|
|
12
12
|
say(' Sign in once here, and your tools will not ask again.');
|
|
13
13
|
say();
|
|
14
14
|
}
|
|
15
|
+
/** How often a wait asks, and for how long. Tests make both short. */
|
|
16
|
+
export const WAIT = { intervalMs: 2500, timeoutMs: 300_000 };
|
|
17
|
+
const FRAMES = '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏';
|
|
18
|
+
/**
|
|
19
|
+
* Asks `check` until it says yes, the person presses Enter, or the time is
|
|
20
|
+
* up, with a one-line spinner on a terminal. Replaces "press Enter when you
|
|
21
|
+
* are done": the person is in the browser, and the terminal should notice
|
|
22
|
+
* by itself when they have finished.
|
|
23
|
+
*/
|
|
24
|
+
export async function waitFor(message, check, opts = {}) {
|
|
25
|
+
const interval = opts.intervalMs ?? WAIT.intervalMs;
|
|
26
|
+
const deadline = Date.now() + (opts.timeoutMs ?? WAIT.timeoutMs);
|
|
27
|
+
const tty = !!process.stderr.isTTY;
|
|
28
|
+
const enter = opts.skipOnEnter ?? !!process.stdin.isTTY;
|
|
29
|
+
let skipped = false;
|
|
30
|
+
let wake = () => { };
|
|
31
|
+
const onData = (b) => { if (/[\r\n]/.test(String(b))) {
|
|
32
|
+
skipped = true;
|
|
33
|
+
wake();
|
|
34
|
+
} };
|
|
35
|
+
if (enter) {
|
|
36
|
+
process.stdin.on('data', onData);
|
|
37
|
+
process.stdin.resume();
|
|
38
|
+
}
|
|
39
|
+
let f = 0;
|
|
40
|
+
const draw = () => { process.stderr.write(`\r ${FRAMES[f++ % FRAMES.length]} ${message}`); };
|
|
41
|
+
const spin = tty ? setInterval(draw, 120) : null;
|
|
42
|
+
if (tty)
|
|
43
|
+
draw();
|
|
44
|
+
else
|
|
45
|
+
say(` ${message}`);
|
|
46
|
+
const pause = (ms) => new Promise((r) => { const t = setTimeout(r, ms); wake = () => { clearTimeout(t); r(); }; });
|
|
47
|
+
try {
|
|
48
|
+
for (;;) {
|
|
49
|
+
try {
|
|
50
|
+
if (await check())
|
|
51
|
+
return 'done';
|
|
52
|
+
}
|
|
53
|
+
catch { /* a blip; ask again */ }
|
|
54
|
+
if (skipped)
|
|
55
|
+
return 'skipped';
|
|
56
|
+
const left = deadline - Date.now();
|
|
57
|
+
if (left <= 0)
|
|
58
|
+
return 'timeout';
|
|
59
|
+
await pause(Math.min(interval, left));
|
|
60
|
+
if (skipped)
|
|
61
|
+
return 'skipped';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
if (spin)
|
|
66
|
+
clearInterval(spin);
|
|
67
|
+
if (tty)
|
|
68
|
+
process.stderr.write('\r\x1b[2K');
|
|
69
|
+
if (enter) {
|
|
70
|
+
process.stdin.off('data', onData);
|
|
71
|
+
process.stdin.pause();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
package/dist/writers.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
15
15
|
import { dirname } from 'node:path';
|
|
16
16
|
import { spawnSync } from 'node:child_process';
|
|
17
|
-
import { ENDPOINT, SERVER_NAME } from './catalogue.js';
|
|
17
|
+
import { ENDPOINT, PENDING_KEY, SERVER_NAME } from './catalogue.js';
|
|
18
18
|
import { redactAll } from './auth.js';
|
|
19
19
|
// What is shown never carries a key: the review, the lines to add by hand
|
|
20
20
|
// and a failed command all print it as sek_live_…abcd. Lines to add by hand
|
|
@@ -274,6 +274,10 @@ export function applyCommand(t) {
|
|
|
274
274
|
}
|
|
275
275
|
// ── one door for every kind ────────────────────────────────────────────
|
|
276
276
|
export function apply(t) {
|
|
277
|
+
// The plan shown before the sign-in stands in for the key; it is rebuilt
|
|
278
|
+
// with the real one (or none) before anything is applied.
|
|
279
|
+
if (JSON.stringify(t).includes(PENDING_KEY))
|
|
280
|
+
return { status: 'failed', where: describe(t), why: 'the key is not there yet; nothing was written' };
|
|
277
281
|
switch (t.kind) {
|
|
278
282
|
case 'json': return applyJson(t);
|
|
279
283
|
case 'toml': return applyToml(t);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sekura",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Connect your coding tool to Sekura in one command: npx sekura@latest init",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc -p tsconfig.json && node -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
|
|
40
|
-
"test": "npm run build && node --test test/init.test.mjs test/login.test.mjs",
|
|
40
|
+
"test": "npm run build && node --test test/init.test.mjs test/login.test.mjs test/guide.test.mjs test/device.test.mjs test/skill.test.mjs test/pay.test.mjs",
|
|
41
41
|
"prepack": "npm run build"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|