sekura 0.5.0 → 0.5.2
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/commands/init.js +43 -14
- package/dist/commands/shared.js +17 -4
- package/dist/commands/uninstall.js +2 -3
- package/dist/flow.js +3 -3
- package/dist/steps.js +47 -25
- package/dist/terms.js +3 -3
- package/dist/ui.js +38 -0
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
// they have seen what will be written. Nothing is written before the review
|
|
7
7
|
// is agreed (unless --yes).
|
|
8
8
|
import { Command } from 'commander';
|
|
9
|
-
import { checkbox,
|
|
9
|
+
import { checkbox, select } from '@inquirer/prompts';
|
|
10
10
|
import { realpathSync } from 'node:fs';
|
|
11
11
|
import { homedir } from 'node:os';
|
|
12
12
|
import { dirname, resolve } from 'node:path';
|
|
13
13
|
import { DOCS, ENDPOINT, PENDING_KEY, TOOLS, carriesKey, home, link, serverNote, toolById } from '../catalogue.js';
|
|
14
14
|
import { applyStep, buildPlan, describeStep, detectTools } from '../plan.js';
|
|
15
15
|
import { verifyEndpoint } from '../verify.js';
|
|
16
|
+
import { openLink } from '../open.js';
|
|
16
17
|
import { credentialsPath, readKey, readToolKey, savedCredentials } from '../auth.js';
|
|
17
18
|
import { tools as sekura } from '../api.js';
|
|
18
19
|
import { EXIT, Exit, exitCodeFor, messageFor } from '../exit.js';
|
|
@@ -20,7 +21,7 @@ import { howToScan, nextSteps } from '../guide.js';
|
|
|
20
21
|
import { currentSession, signInFresh, toolKeyFor, toolKeyName } from '../session.js';
|
|
21
22
|
import { ensureRepository, ensureTerms } from '../steps.js';
|
|
22
23
|
import { runScan } from './scan.js';
|
|
23
|
-
import { banner, cross, dot, say, tick } from '../ui.js';
|
|
24
|
+
import { ask, banner, cross, dot, say, tick } from '../ui.js';
|
|
24
25
|
/** The home folder (or the top of the disk) is no project: project scope
|
|
25
26
|
* there would put AGENTS.md and .mcp.json in it for every tool to find. */
|
|
26
27
|
export function isProjectDir(cwd) {
|
|
@@ -65,9 +66,40 @@ async function noScanYet(key) {
|
|
|
65
66
|
return false;
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Whether this key can start the account's first scan, which the server says
|
|
71
|
+
* is free (freeScanAvailable). Only a key from
|
|
72
|
+
* the GitHub-code sign-in carries the cli scope; a key from the older browser
|
|
73
|
+
* sign-in is an ordinary connector key, and the server quotes it a paid $10
|
|
74
|
+
* scan with the account's first scan still unused (29 November 2026: dev's GitHub-code
|
|
75
|
+
* sign-in answered 404, the CLI fell back, and a person told "your first scan
|
|
76
|
+
* is free" was shown $10). So when that scan is still unused but this key cannot
|
|
77
|
+
* take it, the first-scan step sends the person to the website's first scan
|
|
78
|
+
* and never shows a price. The words come from the server's own answer, so the
|
|
79
|
+
* CLI still never calls a scan free on its own (guide.test.mjs).
|
|
80
|
+
*/
|
|
81
|
+
async function freeScanElsewhere(key) {
|
|
82
|
+
try {
|
|
83
|
+
const a = (await sekura.getAccount(key)).data;
|
|
84
|
+
return a.freeScanAvailable === true && a.freeScanDoor !== 'cli';
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function firstScan(repo, opts, cwd, key) {
|
|
69
91
|
say();
|
|
70
|
-
|
|
92
|
+
if (await freeScanElsewhere(key)) {
|
|
93
|
+
const url = link('/app/start');
|
|
94
|
+
say(` Your first scan is free. Start it on the website: ${url}`);
|
|
95
|
+
if (await ask('Open it in your browser?', { default: true, short: 'Open it in your browser?' })) {
|
|
96
|
+
const o = openLink(url, { browser: opts.browser });
|
|
97
|
+
if (!o.opened)
|
|
98
|
+
say(` Open ${url} in your browser.`);
|
|
99
|
+
}
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
const go = await ask(`See the quote for a first scan of ${repo}? Nothing starts and nothing is charged unless you then agree.`, { default: true, short: 'See the quote?' });
|
|
71
103
|
if (!go) {
|
|
72
104
|
say(` No scan started. When you are ready: npx sekura@latest scan ${repo}`);
|
|
73
105
|
return undefined;
|
|
@@ -179,20 +211,17 @@ export async function runInit(opts) {
|
|
|
179
211
|
});
|
|
180
212
|
}
|
|
181
213
|
if (open.skill)
|
|
182
|
-
skill = await
|
|
214
|
+
skill = await ask('Also install the sekura skill, which teaches the agent the quote-then-confirm rule?', { default: true, short: 'Install the skill?' });
|
|
183
215
|
if (open.login) {
|
|
184
|
-
login = await
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
: 'Sign in to Sekura once you have reviewed the plan, so your tools do not have to and your account is set up here?',
|
|
188
|
-
default: true,
|
|
189
|
-
});
|
|
216
|
+
login = await ask(hasKey
|
|
217
|
+
? 'Use your saved Sekura sign-in, so your tools do not ask and your account is set up here?'
|
|
218
|
+
: 'Sign in to Sekura once you have reviewed the plan, so your tools do not have to and your account is set up here?', { default: true, short: hasKey ? 'Use the saved sign-in?' : 'Sign in to Sekura?' });
|
|
190
219
|
}
|
|
191
220
|
}
|
|
192
221
|
}
|
|
193
222
|
}
|
|
194
223
|
else if (interactive && opts.login === undefined) {
|
|
195
|
-
const go = await
|
|
224
|
+
const go = await ask('Set up your Sekura account here: sign in, the Terms, the Sekura GitHub App and a first scan?', { default: true, short: 'Set up your account?' });
|
|
196
225
|
if (!go) {
|
|
197
226
|
say(' Nothing was changed.');
|
|
198
227
|
return { written: 0, byHand: 0, failed: 0 };
|
|
@@ -234,7 +263,7 @@ export async function runInit(opts) {
|
|
|
234
263
|
say();
|
|
235
264
|
return { written: 0, byHand: 0, failed: 0 };
|
|
236
265
|
}
|
|
237
|
-
if (interactive && shown.steps.length && !(await
|
|
266
|
+
if (interactive && shown.steps.length && !(await ask('Apply?', { default: true, short: 'Apply?' }))) {
|
|
238
267
|
say(' Nothing was changed.');
|
|
239
268
|
return { written: 0, byHand: 0, failed: 0 };
|
|
240
269
|
}
|
|
@@ -329,7 +358,7 @@ export async function runInit(opts) {
|
|
|
329
358
|
say(`${dot} Your email address is not verified yet, and a scan cannot start before that: ${session.account?.links?.dashboard ?? link('/app')}`);
|
|
330
359
|
const accountReady = (terms === 'current' || terms === 'accepted') && !unverified;
|
|
331
360
|
if (repo && accountReady && opts.scan !== false && interactive && await noScanYet(session.key))
|
|
332
|
-
exit = await firstScan(repo, opts, cwd);
|
|
361
|
+
exit = await firstScan(repo, opts, cwd, session.key);
|
|
333
362
|
}
|
|
334
363
|
// 9. What is left, per tool.
|
|
335
364
|
say();
|
package/dist/commands/shared.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { confirm } from '@inquirer/prompts';
|
|
2
1
|
import { writeFileSync } from 'node:fs';
|
|
3
2
|
import { resolve } from 'node:path';
|
|
4
3
|
import { CLI_API, ToolError, cliApi, cliFetch, isMissingRoute, isToolError, tools } from '../api.js';
|
|
@@ -7,7 +6,7 @@ import { exitCodeOfStart, scanFinished, watchScan } from '../flow.js';
|
|
|
7
6
|
import { scanLink } from '../payment.js';
|
|
8
7
|
import { currentGithubRepo } from '../repo.js';
|
|
9
8
|
import { defaultRepository } from '../state.js';
|
|
10
|
-
import { cross, dot, interactive, say, tick } from '../ui.js';
|
|
9
|
+
import { ask, cross, dot, interactive, say, tick } from '../ui.js';
|
|
11
10
|
export const DOCTOR_HINT = 'Run npx sekura@latest doctor to see what is left to set up.';
|
|
12
11
|
export function withQuoteOptions(cmd) {
|
|
13
12
|
return cmd
|
|
@@ -56,12 +55,26 @@ export function resolveRepository(given, cwd = process.cwd()) {
|
|
|
56
55
|
const AGENT_LINE = /^If the person agrees, call |payment: \{ sharedPaymentToken|^nextStep:/;
|
|
57
56
|
const CONFIRM_WITH = /; confirm with payment: \{ savedCard: (?:true|\{ card: "[^"]*" \}) \}/g;
|
|
58
57
|
const CHECKOUT_HOW = /: leave payment out; the answer is 402 with a Stripe Checkout link to open in the person's browser/;
|
|
58
|
+
// The server writes a quote for an agent that shows it to a person ("the
|
|
59
|
+
// person must read ... Show it to them as it stands"). Printed as it is in a
|
|
60
|
+
// terminal, it talks about the reader in the third person and tells them to
|
|
61
|
+
// show themselves the price (29 November 2026). These turn the agent's
|
|
62
|
+
// sentences into the reader's; anything they do not match is printed as sent.
|
|
63
|
+
const PERSON_REWRITES = [
|
|
64
|
+
[/, the person must read and agree to the authorization below\. Show it to them as it stands, with [^.]*?, and ask whether they agree\./g, ': read the authorization below, and agree only if it is right.'],
|
|
65
|
+
[/Before Sekura (brings forward|starts) (.+?), show the person what it does below and ask whether they agree\./g, (_m, verb, what) => `Sekura ${verb === 'starts' ? 'would start' : 'would bring forward'} ${what}. Here is what it does.`],
|
|
66
|
+
[/This account's free[ ]first[ ]scan is still available(?:, on sekura\.ai only)?: the person starts it themselves (?:by running `[^`]+` in a terminal, or )?at (\S+?)\. It is not started through a connected tool, and confirming here buys a one-time scan at (\$[\d.,]+) instead\./g,
|
|
67
|
+
(_m, url, price) => `Your first scan is still free, at ${url}. Agreeing here buys a one-time scan at ${price} instead.`],
|
|
68
|
+
];
|
|
59
69
|
export function personText(text) {
|
|
60
70
|
const out = [];
|
|
61
71
|
for (const raw of text.split('\n')) {
|
|
62
72
|
if (AGENT_LINE.test(raw.replace(/^- /, '')))
|
|
63
73
|
continue;
|
|
64
|
-
|
|
74
|
+
let line = raw.replace(CONFIRM_WITH, '').replace(CHECKOUT_HOW, ': a Stripe Checkout page in your browser');
|
|
75
|
+
for (const [re, to] of PERSON_REWRITES)
|
|
76
|
+
line = line.replace(re, to);
|
|
77
|
+
out.push(line);
|
|
65
78
|
}
|
|
66
79
|
while (out.length && !out[out.length - 1].trim())
|
|
67
80
|
out.pop();
|
|
@@ -106,7 +119,7 @@ export function sayAbandoned(result) {
|
|
|
106
119
|
export async function offerAbandon(key, planId) {
|
|
107
120
|
if (!planId || !interactive())
|
|
108
121
|
return null;
|
|
109
|
-
const yes = await
|
|
122
|
+
const yes = await ask('Cancel this payment? Nothing is charged, and the Checkout link stops working.', { default: false, short: 'Cancel this payment?' });
|
|
110
123
|
if (!yes)
|
|
111
124
|
return null;
|
|
112
125
|
const result = await abandonPayment(key, planId);
|
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
// a tool keeps in its own store (Codex, Devin) are keys the CLI never sees;
|
|
7
7
|
// the person is pointed at Settings → Agents and API keys for those.
|
|
8
8
|
import { Command } from 'commander';
|
|
9
|
-
import { confirm } from '@inquirer/prompts';
|
|
10
9
|
import { buildPlan, detectTools, removalLabel, removeStep } from '../plan.js';
|
|
11
10
|
import { credentialsPath, forgetAllKeys, hostOf, keyName, revokeKey, savedKeys } from '../auth.js';
|
|
12
11
|
import { revokeSessionKey, toolKeyName } from '../session.js';
|
|
13
12
|
import { KEYS_PAGE, serverNote } from '../catalogue.js';
|
|
14
|
-
import { cross, dot, say, tick } from '../ui.js';
|
|
13
|
+
import { ask, cross, dot, say, tick } from '../ui.js';
|
|
15
14
|
/** The Settings page on the server a key belongs to. */
|
|
16
15
|
const keysPageOf = (endpoint) => `${new URL(endpoint).origin}/app/settings → Agents and API keys`;
|
|
17
16
|
export async function runUninstall(opts) {
|
|
@@ -39,7 +38,7 @@ export async function runUninstall(opts) {
|
|
|
39
38
|
say();
|
|
40
39
|
return 0;
|
|
41
40
|
}
|
|
42
|
-
if (interactive && !(await
|
|
41
|
+
if (interactive && !(await ask('Remove?', { default: false, short: 'Remove?' }))) {
|
|
43
42
|
say(' Nothing was changed.');
|
|
44
43
|
return 0;
|
|
45
44
|
}
|
package/dist/flow.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { select } from '@inquirer/prompts';
|
|
2
2
|
import { randomBytes } from 'node:crypto';
|
|
3
3
|
import { readKey } from './auth.js';
|
|
4
4
|
import { call, getPlans, paymentRequiredOf, tools } from './api.js';
|
|
@@ -6,7 +6,7 @@ import { EXIT, Exit, SIGN_IN_HINT } from './exit.js';
|
|
|
6
6
|
import { openLink } from './open.js';
|
|
7
7
|
import { openableLink, paymentState } from './payment.js';
|
|
8
8
|
import { dropQuote, findQuote, saveQuote } from './state.js';
|
|
9
|
-
import { dot, interactive, printJson, say, tick, waitFor } from './ui.js';
|
|
9
|
+
import { ask, dot, interactive, printJson, say, tick, waitFor } from './ui.js';
|
|
10
10
|
export function requireKey() {
|
|
11
11
|
const key = readKey();
|
|
12
12
|
if (!key)
|
|
@@ -119,7 +119,7 @@ export async function confirmQuote(req) {
|
|
|
119
119
|
if (!interactive())
|
|
120
120
|
throw new Exit(EXIT.agreementRequired, `There is no terminal to agree in, so nothing was started. Run ${again}, show the quote to the person, then --confirm <quoteId>.`);
|
|
121
121
|
const payment = await askPayment(q, flags.card);
|
|
122
|
-
const agreed = await
|
|
122
|
+
const agreed = await ask(req.question ?? 'Do you agree?', { default: false, short: 'Do you agree?' });
|
|
123
123
|
if (!agreed)
|
|
124
124
|
throw new Exit(EXIT.declined, 'Nothing was started or charged.');
|
|
125
125
|
return { kind: 'agreed', how: 'asked', confirmOperation: q.confirmOperation, confirmArguments: withPayment(q.confirmArguments, payment), amountCents: amount, quoteId: null, quote: q };
|
package/dist/steps.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { select } from '@inquirer/prompts';
|
|
2
2
|
import { readKey, readToolKey, redact } from './auth.js';
|
|
3
3
|
import { getAccount, getBilling, getPlans, isMissingRoute, isToolError, listRepositories, SignedOut } from './api.js';
|
|
4
4
|
import { ENDPOINT, HOST, carriesKey, link } from './catalogue.js';
|
|
@@ -10,7 +10,7 @@ import { currentGithubRepo } from './repo.js';
|
|
|
10
10
|
import { obtainSession } from './session.js';
|
|
11
11
|
import { defaultRepository, setDefaultRepository } from './state.js';
|
|
12
12
|
import { termsFlow } from './terms.js';
|
|
13
|
-
import { cross, dot, say, tick, waitFor } from './ui.js';
|
|
13
|
+
import { ask, cross, dot, say, tick, waitFor } from './ui.js';
|
|
14
14
|
const isInteractive = (f) => f.interactive ?? (!f.yes && !f.json && !!process.stdin.isTTY && !!process.stderr.isTTY);
|
|
15
15
|
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
16
16
|
export function localConnections(opts = {}) {
|
|
@@ -189,7 +189,7 @@ export async function ensureTerms(s, flags = {}) {
|
|
|
189
189
|
}
|
|
190
190
|
const page = a?.links?.dashboard ?? link('/app');
|
|
191
191
|
say(`${dot} Before a scan can start, accept the Terms on ${HOST}: ${page}`);
|
|
192
|
-
if (interactive && await
|
|
192
|
+
if (interactive && await ask(`Open ${HOST} to do that now?`, { default: true, short: 'Open it now?' })) {
|
|
193
193
|
const o = openLink(page, { browser: flags.browser });
|
|
194
194
|
if (!o.opened)
|
|
195
195
|
say(` Open ${page}`);
|
|
@@ -222,6 +222,8 @@ export function sayInstallWarnings(list) {
|
|
|
222
222
|
}
|
|
223
223
|
export const repositoriesOf = (list) => (list.installations ?? []).flatMap((i) => i.repositories);
|
|
224
224
|
export const installLink = (s, list) => s.account?.links?.installGithubApp ?? list?.installUrl ?? s.account?.links?.start ?? link('/app/start');
|
|
225
|
+
/** The GitHub accounts the App is installed on, as GitHub names them. */
|
|
226
|
+
const accountsOf = (list) => [...new Set((list.installations ?? []).map((i) => i.account).filter((a) => !!a))];
|
|
225
227
|
export async function ensureApp(s, flags = {}) {
|
|
226
228
|
const interactive = isInteractive(flags);
|
|
227
229
|
const want = flags.want ?? null;
|
|
@@ -234,7 +236,7 @@ export async function ensureApp(s, flags = {}) {
|
|
|
234
236
|
const covered = () => (want ? repos.some((r) => same(r.fullName, want)) : repos.length > 0);
|
|
235
237
|
const url = installLink(s, list);
|
|
236
238
|
if (covered() && !flags.add)
|
|
237
|
-
return { installed: true, found: true, repositories: repos, link: url };
|
|
239
|
+
return { installed: true, found: true, repositories: repos, link: url, accounts: accountsOf(list) };
|
|
238
240
|
const onGithub = /^https:\/\/github\.com\//.test(url);
|
|
239
241
|
say(repos.length
|
|
240
242
|
? want && !covered() ? `${dot} ${want} is not one Sekura can scan yet: the Sekura GitHub App needs access to it.` : `${dot} To give Sekura more repositories, change the Sekura GitHub App's access.`
|
|
@@ -242,7 +244,7 @@ export async function ensureApp(s, flags = {}) {
|
|
|
242
244
|
if (!interactive) {
|
|
243
245
|
say(` Install it and choose repositories at ${url}`);
|
|
244
246
|
if (flags.soft || covered())
|
|
245
|
-
return { installed: repos.length > 0, found: covered(), repositories: repos, link: url };
|
|
247
|
+
return { installed: repos.length > 0, found: covered(), repositories: repos, link: url, accounts: accountsOf(list) };
|
|
246
248
|
throw new Exit(EXIT.accountNotReady, `Sekura cannot scan ${want ?? 'any repository'} yet. Install the Sekura GitHub App at the link above, then run the command again.`, { installUrl: url });
|
|
247
249
|
}
|
|
248
250
|
if (!flags.add) {
|
|
@@ -254,7 +256,7 @@ export async function ensureApp(s, flags = {}) {
|
|
|
254
256
|
],
|
|
255
257
|
});
|
|
256
258
|
if (!go)
|
|
257
|
-
return { installed: repos.length > 0, found: false, repositories: repos, link: url };
|
|
259
|
+
return { installed: repos.length > 0, found: false, repositories: repos, link: url, accounts: accountsOf(list) };
|
|
258
260
|
}
|
|
259
261
|
const opened = openLink(url, { browser: flags.browser });
|
|
260
262
|
say(opened.opened ? ` Opened ${url}` : ` Open ${url}`);
|
|
@@ -270,7 +272,7 @@ export async function ensureApp(s, flags = {}) {
|
|
|
270
272
|
say(found
|
|
271
273
|
? `${tick} ${want ? `Sekura can scan ${want}` : before.size ? 'Sekura can scan more repositories now' : 'The Sekura GitHub App is installed'}`
|
|
272
274
|
: `${dot} Not there yet; you can finish the install later with npx sekura@latest repos --add`);
|
|
273
|
-
return { installed: repos.length > 0, found, repositories: repos, link: url };
|
|
275
|
+
return { installed: repos.length > 0, found, repositories: repos, link: url, accounts: accountsOf(list) };
|
|
274
276
|
}
|
|
275
277
|
export async function ensureRepository(s, flags = {}) {
|
|
276
278
|
const interactive = isInteractive(flags);
|
|
@@ -308,23 +310,43 @@ export async function ensureRepository(s, flags = {}) {
|
|
|
308
310
|
return null;
|
|
309
311
|
throw new Exit(EXIT.error, `Name the repository: Sekura can scan ${scannable.length}, and this folder is not one of them. Run npx sekura@latest repos to list them.`);
|
|
310
312
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
313
|
+
// Always asked, even with one repository (Sudhir, 29 November 2026: "why
|
|
314
|
+
// did it pick nagiclaw?"). With one, the CLI used to choose it and print a
|
|
315
|
+
// tick: the person saw a repository they had not named, from an account
|
|
316
|
+
// they had forgotten the App was on, with no way to pick another. Nothing
|
|
317
|
+
// about which repository is scanned happens without the person choosing it,
|
|
318
|
+
// and the list always offers giving Sekura another one.
|
|
319
|
+
let repos = app.repositories;
|
|
320
|
+
let accounts = app.accounts ?? [];
|
|
321
|
+
for (;;) {
|
|
322
|
+
// Say where the list comes from: an installation the person made long
|
|
323
|
+
// ago, or one on another account they collaborate on, otherwise looks
|
|
324
|
+
// like Sekura found repositories by itself (29 November 2026: the App was
|
|
325
|
+
// still on sekura-ai, and findsekura saw sekura-ai/nagiclaw).
|
|
326
|
+
if (accounts.length)
|
|
327
|
+
say(`${dot} The Sekura GitHub App is installed on ${accounts.join(', ')}; these are the repositories it can reach.`);
|
|
328
|
+
const hereNow = find(here) ? repos.find((r) => same(r.fullName, here)) : undefined;
|
|
329
|
+
const savedNow = repos.find((r) => same(r.fullName, defaultRepository() ?? ''));
|
|
330
|
+
const first = hereNow ?? savedNow;
|
|
331
|
+
const ordered = first ? [first, ...repos.filter((r) => r !== first)] : repos;
|
|
332
|
+
const picked = await select({
|
|
333
|
+
message: 'Which repository should Sekura scan?',
|
|
334
|
+
pageSize: 12,
|
|
335
|
+
choices: [
|
|
336
|
+
...ordered.map((r) => ({
|
|
337
|
+
name: `${r.fullName}${r === hereNow ? ' (this folder)' : r === savedNow ? ' (your default)' : ''}${r.private ? ' (private)' : ''}`,
|
|
338
|
+
value: r.fullName,
|
|
339
|
+
disabled: r.empty ? '(empty, nothing to scan)' : false,
|
|
340
|
+
})),
|
|
341
|
+
{ name: 'Another repository: give Sekura access on GitHub', value: ADD_REPOSITORY },
|
|
342
|
+
{ name: 'Skip for now', value: '' },
|
|
343
|
+
],
|
|
344
|
+
});
|
|
345
|
+
if (picked !== ADD_REPOSITORY)
|
|
346
|
+
return picked ? keep(picked) : null;
|
|
347
|
+
const again = await ensureApp(s, { ...flags, add: true });
|
|
348
|
+
repos = again.repositories;
|
|
349
|
+
accounts = again.accounts ?? accounts;
|
|
314
350
|
}
|
|
315
|
-
const first = hereRepo ?? saved;
|
|
316
|
-
const ordered = first ? [first, ...app.repositories.filter((r) => r !== first)] : app.repositories;
|
|
317
|
-
const picked = await select({
|
|
318
|
-
message: 'Which repository?',
|
|
319
|
-
pageSize: 12,
|
|
320
|
-
choices: [
|
|
321
|
-
...ordered.map((r) => ({
|
|
322
|
-
name: `${r.fullName}${r === hereRepo ? ' (this folder)' : r === saved ? ' (your default)' : ''}${r.private ? ' (private)' : ''}`,
|
|
323
|
-
value: r.fullName,
|
|
324
|
-
disabled: r.empty ? '(empty, nothing to scan)' : false,
|
|
325
|
-
})),
|
|
326
|
-
{ name: 'Skip for now', value: '' },
|
|
327
|
-
],
|
|
328
|
-
});
|
|
329
|
-
return picked ? keep(picked) : null;
|
|
330
351
|
}
|
|
352
|
+
const ADD_REPOSITORY = '\u0000add';
|
package/dist/terms.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { select } from '@inquirer/prompts';
|
|
2
2
|
import { cliApi, isToolError } from './api.js';
|
|
3
3
|
import { EXIT, Exit } from './exit.js';
|
|
4
|
-
import { dot, say, tick } from './ui.js';
|
|
4
|
+
import { ask, dot, say, tick } from './ui.js';
|
|
5
5
|
export const termsCurrent = (t) => t.state === 'current';
|
|
6
6
|
export async function getTerms(key) {
|
|
7
7
|
const t = await cliApi(key, 'GET', '/terms');
|
|
@@ -62,7 +62,7 @@ export async function termsFlow(key, opts) {
|
|
|
62
62
|
return 'declined';
|
|
63
63
|
let marketing = opts.marketing === true;
|
|
64
64
|
if (opts.marketing === undefined && terms.marketingText)
|
|
65
|
-
marketing = await
|
|
65
|
+
marketing = await ask(terms.marketingText, { default: false, short: 'Send me product news?' });
|
|
66
66
|
try {
|
|
67
67
|
await acceptTerms(key, { version: terms.version, textHash: terms.textHash }, marketing);
|
|
68
68
|
say(`${tick} Terms accepted (version ${terms.version})`);
|
package/dist/ui.js
CHANGED
|
@@ -109,3 +109,41 @@ export async function waitFor(message, check, opts = {}) {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* A yes/no question that never wraps. The prompt library word-wraps a long
|
|
114
|
+
* question but places the cursor as if the line were cut at the terminal's
|
|
115
|
+
* edge, so any question wider than the window leaves the cursor in the middle
|
|
116
|
+
* of a word ("rule", 29 November 2026; "here?", the same evening, in 0.5.0).
|
|
117
|
+
* A question that fits is asked as it is; a longer one is printed above,
|
|
118
|
+
* wrapped by us, and the prompt itself is the short form.
|
|
119
|
+
*/
|
|
120
|
+
/** "(y/n)" in lower case, both letters (Sudhir, 29 November 2026: "keep both
|
|
121
|
+
* small case"). The library writes the default in capitals, "(Y/n)"; Enter
|
|
122
|
+
* still takes the default. Dim, as the library draws it. */
|
|
123
|
+
const YES_NO = { style: { defaultAnswer: (text) => `\x1b[2m(${text.toLowerCase()})\x1b[22m` } };
|
|
124
|
+
export async function ask(message, opts) {
|
|
125
|
+
const { confirm } = await import('@inquirer/prompts');
|
|
126
|
+
const cols = Math.max(40, process.stderr.columns || process.stdout.columns || 80);
|
|
127
|
+
// "? " before it and " (Y/n) " after it.
|
|
128
|
+
if (message.length + 10 <= cols)
|
|
129
|
+
return confirm({ message, default: opts.default, theme: YES_NO });
|
|
130
|
+
for (const line of wrapWords(message, cols - 4))
|
|
131
|
+
say(` ${line}`);
|
|
132
|
+
return confirm({ message: opts.short, default: opts.default, theme: YES_NO });
|
|
133
|
+
}
|
|
134
|
+
/** Plain word wrap at `width` characters; a single longer word keeps its own line. */
|
|
135
|
+
export function wrapWords(text, width) {
|
|
136
|
+
const out = [];
|
|
137
|
+
let line = '';
|
|
138
|
+
for (const word of text.split(/\s+/).filter(Boolean)) {
|
|
139
|
+
if (line && line.length + 1 + word.length > width) {
|
|
140
|
+
out.push(line);
|
|
141
|
+
line = word;
|
|
142
|
+
}
|
|
143
|
+
else
|
|
144
|
+
line = line ? `${line} ${word}` : word;
|
|
145
|
+
}
|
|
146
|
+
if (line)
|
|
147
|
+
out.push(line);
|
|
148
|
+
return out;
|
|
149
|
+
}
|
package/package.json
CHANGED