sekura 0.5.9 → 0.5.11
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 +8 -5
- package/dist/catalogue.js +22 -1
- package/dist/commands/billing.js +12 -6
- package/dist/commands/init.js +35 -5
- package/dist/commands/login.js +18 -10
- package/dist/commands/pay.js +8 -6
- package/dist/commands/plans.js +76 -33
- package/dist/commands/scan.js +3 -3
- package/dist/commands/shared.js +134 -21
- package/dist/flow.js +26 -7
- package/dist/payment.js +5 -5
- package/dist/steps.js +11 -2
- package/dist/ui.js +33 -6
- package/dist/writers.js +25 -0
- package/package.json +1 -1
- package/skills/sekura/SKILL.md +10 -6
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ The GitHub-code sign-in, the Terms in the terminal, the report download and a fr
|
|
|
19
19
|
## What a first run does
|
|
20
20
|
|
|
21
21
|
1. **Detects** the tools on this machine: Claude Code, Cursor, GitHub Copilot in VS Code, OpenAI Codex, Kiro, Cline, Zed, Antigravity, OpenCode, JetBrains Junie, Factory Droid, Tabnine, Devin and Goose. With none found it says how to name one (`--tools`) and carries on with your account.
|
|
22
|
-
2. **Asks one question**, with every detected tool, your user configuration, the skill and the sign-in as the defaults: `Connect Claude Code, Cursor and OpenAI Codex for every project, with the skill, and sign in to Sekura?` Answer **Yes**, **No**, or **
|
|
22
|
+
2. **Asks one question**, with every detected tool, your user configuration, the skill and the sign-in as the defaults: `Connect Claude Code, Cursor and OpenAI Codex for every project, with the skill, and sign in to Sekura?` Answer **Yes**, **No**, or **Choose** to pick the tools, where (every project, or this project only when run inside one), the skill and the sign-in. A flag answers its own question and skips it.
|
|
23
23
|
3. **Shows the plan** before anything happens: each file and the exact entry, or the tool's own command, with `Authorization: Bearer <your key, after sign-in>` where the key will go (a key you already have is shown as `sek_live_…abcd`). Then it asks **Apply?**
|
|
24
24
|
4. **Signs you in.** It prints a code, copies it to your clipboard and opens `github.com/login/device`; you enter the code and approve. Over SSH, in a container, or with `--no-browser`, it prints the address instead of opening it. If the sign-in does not finish, nothing is written and the run stops with exit code 4.
|
|
25
25
|
5. **Writes the tool entries and the skill**, one step at a time, saying what each did. Your tools get a key of their own (see Your keys). Files that are not plain JSON (Zed's `settings.json` with comments, for one) are never rewritten; you are shown the lines to add. Codex and Devin cannot take a key in their configuration, so the CLI prints the one command that signs each in (`codex mcp login sekura`, `devin mcp login sekura`).
|
|
@@ -35,7 +35,7 @@ The GitHub-code sign-in, the Terms in the terminal, the report download and a fr
|
|
|
35
35
|
| Command | What it does |
|
|
36
36
|
|---|---|
|
|
37
37
|
| `sekura`, `sekura init` | The first run above. |
|
|
38
|
-
| `login`, `logout` | Sign in with a GitHub code and give your connected tools their key; `logout` revokes the sign-in key on Sekura and forgets it here. |
|
|
38
|
+
| `login`, `logout` | Sign in with a GitHub code and give your connected tools their key, and nothing more; `logout` revokes the sign-in key on Sekura and forgets it here. |
|
|
39
39
|
| `status` (alias `account`) | Your account (sign-in, Terms, email, GitHub App, repositories, plans, cards) and which tools here are connected. |
|
|
40
40
|
| `doctor` | The same checklist, with the command to run for each thing that is not ready. Exits 4 when signed out, 5 when the account is not ready. |
|
|
41
41
|
| `terms` | Show the Terms and accept them. `--json` prints the version and text hash. |
|
|
@@ -45,9 +45,9 @@ The GitHub-code sign-in, the Terms in the terminal, the report download and a fr
|
|
|
45
45
|
| `scans` | Your scans and their status. |
|
|
46
46
|
| `findings <id>`, `report <id>` | A scan's findings; the report saved to a file (`-o` names it, `--open` opens it). |
|
|
47
47
|
| `plans` | Repositories on a monthly plan. |
|
|
48
|
-
| `plan start [repo]` | Start a monthly plan: `--tier weekly` (Weekly) or `--tier frequent` (More frequently), with `--weekday`, `--every`, `--time`, `--tz` or `--on-demand`. |
|
|
48
|
+
| `plan start [repo]` | Start a monthly plan: `--tier weekly` (Weekly) or `--tier frequent` (More frequently), with `--weekday`, `--every`, `--time`, `--tz` or `--on-demand`. In a terminal it asks for each one, the time zone with this machine's as the default, and asks again when Sekura cannot use a schedule. |
|
|
49
49
|
| `plan schedule [repo]`, `plan run [repo]`, `plan cancel [repo]` | Change when a plan runs, run its next scan now, end it. Each is shown first. |
|
|
50
|
-
| `billing [--open]` | Your saved cards, masked, and your
|
|
50
|
+
| `billing [--open]` | Your saved cards, masked, and your monthly plans. `--open` opens Stripe to add or change a card and waits for the change. |
|
|
51
51
|
| `pay [link] --plan <id>` | Open a Checkout link from a quote and wait for the payment; `--abandon --plan <id>` cancels a pending one. |
|
|
52
52
|
| `uninstall` | Remove the entries, the skill and the guidance block, and revoke the saved keys. |
|
|
53
53
|
|
|
@@ -130,6 +130,8 @@ SEKURA_ENDPOINT=https://dev.sekura.ai npx sekura@latest init
|
|
|
130
130
|
npx sekura@latest init --endpoint http://127.0.0.1:8787
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
Against any server other than `sekura.ai`, every command the CLI prints carries `--endpoint <server>`, so it reaches the same server when you copy it.
|
|
134
|
+
|
|
133
135
|
The address must be `https://`, or `http://` for `127.0.0.1` or `localhost` only (use `127.0.0.1` for a local server), with or without `/mcp` at the end. The default is `https://sekura.ai`. Each server's key is kept under that server's address in `credentials.json`, and a key saved for one server is never sent to another. After a sign-in on another server, a run without the override stays on that server (see Your keys); run `sekura init --endpoint https://sekura.ai` to point your tools back at `https://sekura.ai`.
|
|
134
136
|
|
|
135
137
|
## What it writes
|
|
@@ -146,7 +148,8 @@ The address must be `https://`, or `http://` for `127.0.0.1` or `localhost` only
|
|
|
146
148
|
| Antigravity | `~/.gemini/config/mcp_config.json` → `serverUrl` | `.agents/mcp_config.json` |
|
|
147
149
|
| OpenCode | `~/.config/opencode/opencode.json` → `mcp.sekura` | `opencode.json` |
|
|
148
150
|
| JetBrains Junie | — | `.junie/mcp/mcp.json` |
|
|
149
|
-
| Factory Droid, Tabnine
|
|
151
|
+
| Factory Droid, Tabnine | the tool's own `mcp add` command | — |
|
|
152
|
+
| Devin | `devin mcp add -s user …`; read back from `~/.config/devin/mcp_config.json` (or `config.json`), since `devin mcp list` also shows what Devin imports from Claude Code | — |
|
|
150
153
|
| Goose | `~/.config/goose/config.yaml` → `extensions.sekura` (`streamable_http`) | — |
|
|
151
154
|
|
|
152
155
|
The skill goes to `~/.agents/skills/sekura/SKILL.md` and, when Claude Code is present, `~/.claude/skills/sekura/SKILL.md`; in project scope to the same paths under the project, plus a section between `<!-- sekura:start -->` and `<!-- sekura:end -->` in `AGENTS.md` (and `CLAUDE.md` if one exists). Reruns replace only what sits between the markers.
|
package/dist/catalogue.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
13
13
|
import { homedir, platform } from 'node:os';
|
|
14
14
|
import { join, delimiter } from 'node:path';
|
|
15
|
+
import { setCommandOrigin } from './ui.js';
|
|
15
16
|
/** The home directory, overridable for tests. */
|
|
16
17
|
export const home = () => process.env.SEKURA_HOME || homedir();
|
|
17
18
|
/** Where the saved keys live (auth.ts reads and writes the file). Here,
|
|
@@ -52,6 +53,9 @@ export const ENDPOINT_SOURCE = fromEnv ? 'env' : fromSaved ? 'saved' : 'default'
|
|
|
52
53
|
/** Every link the CLI prints is on the server it talks to: dev.sekura.ai's
|
|
53
54
|
* pages for a dev key, never production's. */
|
|
54
55
|
export const ORIGIN = new URL(ENDPOINT).origin;
|
|
56
|
+
// Every command printed from here on names this server unless it is
|
|
57
|
+
// production (ui.ts, withEndpoint).
|
|
58
|
+
setCommandOrigin(ORIGIN === new URL(PRODUCTION).origin ? null : ORIGIN);
|
|
55
59
|
/** The server's host, where prose names it: sekura.ai, or dev.sekura.ai. */
|
|
56
60
|
export const HOST = new URL(ENDPOINT).host;
|
|
57
61
|
export const link = (path) => `${ORIGIN}${path.startsWith('/') ? path : `/${path}`}`;
|
|
@@ -100,6 +104,13 @@ export function gooseDir(h = home()) {
|
|
|
100
104
|
return join(process.env.APPDATA || join(h, 'AppData', 'Roaming'), 'Block', 'goose', 'config');
|
|
101
105
|
return join(xdg(h), 'goose');
|
|
102
106
|
}
|
|
107
|
+
/** Devin's own user configuration: ~/.config/devin on macOS and Linux,
|
|
108
|
+
* %APPDATA%\\devin on Windows. */
|
|
109
|
+
export function devinFile(h, name) {
|
|
110
|
+
if (platform() === 'win32')
|
|
111
|
+
return join(process.env.APPDATA || join(h, 'AppData', 'Roaming'), 'devin', name);
|
|
112
|
+
return join(xdg(h), 'devin', name);
|
|
113
|
+
}
|
|
103
114
|
/** True when `bin` is an executable on PATH. */
|
|
104
115
|
export function onPath(bin) {
|
|
105
116
|
const exts = platform() === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
|
|
@@ -232,7 +243,17 @@ export const TOOLS = [
|
|
|
232
243
|
{
|
|
233
244
|
id: 'tools-devin', name: 'Devin Desktop and the Devin CLI',
|
|
234
245
|
detect: () => onPath('devin'),
|
|
235
|
-
|
|
246
|
+
// `devin mcp list` also lists the servers Devin imports from Claude
|
|
247
|
+
// Code's ~/.claude.json (and Cursor's, Zed's, OpenCode's), so after a
|
|
248
|
+
// Claude Code-only setup Devin read as connected though the CLI never
|
|
249
|
+
// wrote to it (Varsha's test, R1). Its own entry is read from its own
|
|
250
|
+
// files (docs.devin.ai, MCP configuration: mcp_config.json since
|
|
251
|
+
// v3000.3, mcpServers in config.json before). `-s user`: without it,
|
|
252
|
+
// `devin mcp add` writes to the folder the CLI was run in.
|
|
253
|
+
user: (h) => [{
|
|
254
|
+
kind: 'command', bin: 'devin', add: ['mcp', 'add', '-s', 'user', SERVER_NAME, ENDPOINT], remove: ['mcp', 'remove', SERVER_NAME], list: ['mcp', 'list'],
|
|
255
|
+
own: [devinFile(h, 'mcp_config.json'), devinFile(h, 'config.json')],
|
|
256
|
+
}],
|
|
236
257
|
signIn: `run devin mcp login ${SERVER_NAME}.`,
|
|
237
258
|
next: `start a new devin session, or restart Devin Desktop.`,
|
|
238
259
|
login: ['mcp', 'login', SERVER_NAME],
|
package/dist/commands/billing.js
CHANGED
|
@@ -38,9 +38,10 @@ function sayCards(b, heading) {
|
|
|
38
38
|
for (const l of lines)
|
|
39
39
|
say(` ${l}`);
|
|
40
40
|
}
|
|
41
|
-
/** The active plans by repository, from getPlans: what the cards
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
/** The active monthly plans by repository, from getPlans: what the cards
|
|
42
|
+
* pay for. One-time scans are not plans and are left out (Varsha's test,
|
|
43
|
+
* P6: four of them were listed under "Active plans"). A failed read is said
|
|
44
|
+
* and is not a failure of the command; the cards above it are already shown. */
|
|
44
45
|
async function sayPlans(key) {
|
|
45
46
|
let lines;
|
|
46
47
|
try {
|
|
@@ -51,10 +52,10 @@ async function sayPlans(key) {
|
|
|
51
52
|
return;
|
|
52
53
|
}
|
|
53
54
|
if (!lines.length) {
|
|
54
|
-
say(`${dot} No
|
|
55
|
+
say(`${dot} No monthly plans.`);
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
|
-
say(`${tick}
|
|
58
|
+
say(`${tick} Monthly plans:`);
|
|
58
59
|
for (const l of lines)
|
|
59
60
|
say(` ${l}`);
|
|
60
61
|
}
|
|
@@ -99,7 +100,12 @@ export async function runBilling(opts = {}) {
|
|
|
99
100
|
const link = page.link;
|
|
100
101
|
const opened = opts.browser === false ? false : openBrowser(link);
|
|
101
102
|
const where = page.what === 'card' ? 'Stripe\'s page for saving a card' : page.what === 'portal' ? 'your cards on Stripe' : 'your payment methods';
|
|
102
|
-
|
|
103
|
+
if (opened)
|
|
104
|
+
say(`${tick} Opened ${where} in the browser.`);
|
|
105
|
+
else {
|
|
106
|
+
say(`${dot} Open this link in a browser to add or change a card:`);
|
|
107
|
+
say(` ${link}`);
|
|
108
|
+
}
|
|
103
109
|
const was = cardsFingerprint(before);
|
|
104
110
|
let now = before;
|
|
105
111
|
const minutes = Number(opts.timeout);
|
package/dist/commands/init.js
CHANGED
|
@@ -19,6 +19,7 @@ import { EXIT, Exit, exitCodeFor, messageFor } from '../exit.js';
|
|
|
19
19
|
import { howToScan, nextSteps } from '../guide.js';
|
|
20
20
|
import { currentSession, signInFresh, toolKeyFor, toolKeyName } from '../session.js';
|
|
21
21
|
import { ensureRepository, ensureTerms } from '../steps.js';
|
|
22
|
+
import { getTerms } from '../terms.js';
|
|
22
23
|
import { runScan } from './scan.js';
|
|
23
24
|
import { personText } from './shared.js';
|
|
24
25
|
import { select, checkbox, ask, banner, c, cross, dot, say, step, tick, warn } from '../ui.js';
|
|
@@ -144,6 +145,21 @@ async function firstScan(repo, opts, cwd, key) {
|
|
|
144
145
|
return exitCodeFor(e);
|
|
145
146
|
}
|
|
146
147
|
}
|
|
148
|
+
/** What the account steps after the review will still do. A returning
|
|
149
|
+
* person was promised the Terms, the GitHub App and a first scan they had
|
|
150
|
+
* long done (Varsha's test, R1). Without a session yet, all of it. */
|
|
151
|
+
async function stillToDo(session, scan) {
|
|
152
|
+
const first = 'your first scan (quoted before it starts)';
|
|
153
|
+
if (!session?.account)
|
|
154
|
+
return ['Terms', 'GitHub App', 'a repository', ...(scan ? [first] : [])];
|
|
155
|
+
const a = session.account;
|
|
156
|
+
return [
|
|
157
|
+
...(a.termsAccepted !== true || a.termsUpdated === true ? ['Terms'] : []),
|
|
158
|
+
...(a.installations ? [] : ['GitHub App']),
|
|
159
|
+
'a repository',
|
|
160
|
+
...(scan && a.freeScanAvailable !== false && await noScanYet(session.key) ? [first] : []),
|
|
161
|
+
];
|
|
162
|
+
}
|
|
147
163
|
export async function runInit(opts) {
|
|
148
164
|
const interactive = !opts.yes && !!process.stdin.isTTY && !!process.stderr.isTTY;
|
|
149
165
|
const unattended = !opts.yes && !interactive;
|
|
@@ -182,7 +198,7 @@ export async function runInit(opts) {
|
|
|
182
198
|
}
|
|
183
199
|
const missing = TOOLS.length - detected.length;
|
|
184
200
|
if (missing > 0)
|
|
185
|
-
say(` ${c.dim(`○ ${missing} more supported tools, not installed here`)}`);
|
|
201
|
+
say(` ${c.dim(`○ ${missing} more supported ${missing === 1 ? 'tool' : 'tools'}, not installed here`)}`);
|
|
186
202
|
}
|
|
187
203
|
let scope = opts.scope ?? 'user';
|
|
188
204
|
const inProject = isProjectDir(cwd);
|
|
@@ -203,7 +219,10 @@ export async function runInit(opts) {
|
|
|
203
219
|
}
|
|
204
220
|
// 2. One question, with Edit for the four it stands for.
|
|
205
221
|
if (interactive && chosen.length) {
|
|
206
|
-
|
|
222
|
+
// "Where?" is always asked when it was not given (Varsha's test, F3: it
|
|
223
|
+
// was left out outside a project folder, though the menu names it); there,
|
|
224
|
+
// "This project only" is shown but cannot be picked.
|
|
225
|
+
const open = { tools: !opts.tools, scope: !opts.scope, skill: opts.skill === undefined, login: opts.login === undefined };
|
|
207
226
|
if (open.tools || open.scope || open.skill || open.login) {
|
|
208
227
|
step('Choose tools');
|
|
209
228
|
const names = chosen.map((id) => toolById(id)?.name ?? id);
|
|
@@ -234,8 +253,9 @@ export async function runInit(opts) {
|
|
|
234
253
|
message: 'Where?',
|
|
235
254
|
choices: [
|
|
236
255
|
{ name: 'Every project (your user settings)', value: 'user' },
|
|
237
|
-
{ name: `This project only (${tilde(cwd)})`, value: 'project' },
|
|
256
|
+
{ name: `This project only (${tilde(cwd)})`, value: 'project', disabled: inProject ? false : '(run it inside a project folder)' },
|
|
238
257
|
],
|
|
258
|
+
default: scope,
|
|
239
259
|
});
|
|
240
260
|
}
|
|
241
261
|
if (open.skill)
|
|
@@ -279,8 +299,11 @@ export async function runInit(opts) {
|
|
|
279
299
|
say(`${dot} ${opts.dryRun ? describeStep(s, true) : planLine(s)}`);
|
|
280
300
|
for (const s of shown.skipped)
|
|
281
301
|
say(`${dot} ${s.tool.name}: ${c.dim(`skipped, ${s.why}`)}`);
|
|
282
|
-
if (account)
|
|
283
|
-
|
|
302
|
+
if (account) {
|
|
303
|
+
const left = await stillToDo(session, opts.scan !== false);
|
|
304
|
+
if (left.length)
|
|
305
|
+
say(`${dot} Then: ${left.join(', ')}`);
|
|
306
|
+
}
|
|
284
307
|
say(` ${c.dim('Nothing else is changed.')}`);
|
|
285
308
|
say();
|
|
286
309
|
if (opts.dryRun)
|
|
@@ -374,6 +397,13 @@ export async function runInit(opts) {
|
|
|
374
397
|
throw e;
|
|
375
398
|
say(`${dot} The Terms could not be checked just now: ${messageFor(e)}`);
|
|
376
399
|
}
|
|
400
|
+
// The heading stood alone with nothing under it for a returning person
|
|
401
|
+
// (Varsha's test, R1).
|
|
402
|
+
if (terms === 'current') {
|
|
403
|
+
// Only a key from the GitHub-code sign-in reaches the CLI routes.
|
|
404
|
+
const version = session.kind === 'cli' ? await getTerms(session.key).then((t) => t.version, () => null) : null;
|
|
405
|
+
say(`${tick} Terms already accepted${version ? ` ${c.dim(`(version ${version})`)}` : ''}`);
|
|
406
|
+
}
|
|
377
407
|
step('GitHub App and repository');
|
|
378
408
|
try {
|
|
379
409
|
repo = await ensureRepository(session, flags);
|
package/dist/commands/login.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// `sekura login`: sign in here (in the browser, or with a code on another
|
|
2
|
-
// device) and put the key into every tool already connected,
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// device) and put the key into every tool already connected, and stop
|
|
3
|
+
// there. For someone who skipped the sign-in during init or revoked the key.
|
|
4
|
+
// It went on into the Terms and "Which repository should Sekura scan?"
|
|
5
|
+
// (Varsha's test, R6); signing in is not a request to scan. `sekura logout`:
|
|
5
6
|
// forget the saved key.
|
|
6
7
|
import { Command } from 'commander';
|
|
7
8
|
import { applyStep, buildPlan, detectTools, stepPresent } from '../plan.js';
|
|
@@ -10,8 +11,13 @@ import { credentialsPath, forgetKey, hostOf, readSavedKey, savedCredentials } fr
|
|
|
10
11
|
import { EXIT, Exit } from '../exit.js';
|
|
11
12
|
import { howToScan, toolLogin } from '../guide.js';
|
|
12
13
|
import { revokeSessionKey, toolKeyFor, toolKeyName } from '../session.js';
|
|
13
|
-
import {
|
|
14
|
+
import { ensureSignedIn } from '../steps.js';
|
|
15
|
+
import { defaultRepository } from '../state.js';
|
|
14
16
|
import { cross, dot, say, tick } from '../ui.js';
|
|
17
|
+
/** A tool name that names two things ("Devin Desktop and the Devin CLI")
|
|
18
|
+
* takes a plural verb: "Devin Desktop and the Devin CLI keep their own
|
|
19
|
+
* sign-in", not "keeps its" (Varsha's test, R6). */
|
|
20
|
+
export const plural = (name) => / and /.test(name);
|
|
15
21
|
export async function runLogin(opts) {
|
|
16
22
|
const cwd = opts.cwd ?? process.cwd();
|
|
17
23
|
const interactive = !!(process.stdin.isTTY && process.stderr.isTTY);
|
|
@@ -48,7 +54,7 @@ export async function runLogin(opts) {
|
|
|
48
54
|
if (!carriesKey(s.target)) {
|
|
49
55
|
const cmd = toolLogin(s);
|
|
50
56
|
if (cmd)
|
|
51
|
-
say(`${dot} ${s.tool.name} keeps its own sign-in: run ${cmd} when you first use it there`);
|
|
57
|
+
say(`${dot} ${s.tool.name} ${plural(s.tool.name) ? 'keep their' : 'keeps its'} own sign-in: run ${cmd} when you first use it there`);
|
|
52
58
|
continue;
|
|
53
59
|
}
|
|
54
60
|
const r = applyStep(s);
|
|
@@ -65,18 +71,20 @@ export async function runLogin(opts) {
|
|
|
65
71
|
}
|
|
66
72
|
if (!names.length)
|
|
67
73
|
say(`${dot} No tool on this machine has Sekura yet: run npx sekura@latest init.`);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
74
|
+
const a = session.account;
|
|
75
|
+
if (a?.termsAccepted === false || a?.termsUpdated === true) {
|
|
76
|
+
say();
|
|
77
|
+
say(`${dot} Terms not accepted yet. A scan cannot start before that: npx sekura@latest terms`);
|
|
78
|
+
}
|
|
71
79
|
if (names.length) {
|
|
72
80
|
say();
|
|
73
|
-
howToScan(names,
|
|
81
|
+
howToScan(names, defaultRepository(), a);
|
|
74
82
|
}
|
|
75
83
|
say();
|
|
76
84
|
return failed;
|
|
77
85
|
}
|
|
78
86
|
export const loginCommand = new Command('login')
|
|
79
|
-
.description('Sign in to Sekura with a GitHub code
|
|
87
|
+
.description('Sign in to Sekura with a GitHub code and give your connected tools a key.')
|
|
80
88
|
.option('--legacy-login', 'sign in on a Sekura page instead of with a GitHub code')
|
|
81
89
|
.option('--device', 'with --legacy-login: sign in with a code on another device')
|
|
82
90
|
.option('--no-browser', 'print links instead of opening them')
|
package/dist/commands/pay.js
CHANGED
|
@@ -13,9 +13,11 @@ const minutes = (raw, fallback) => {
|
|
|
13
13
|
};
|
|
14
14
|
function sayOpened(link, opened) {
|
|
15
15
|
if (opened)
|
|
16
|
-
say(`${tick} Opened Stripe Checkout in your browser
|
|
17
|
-
else
|
|
18
|
-
say(`${dot} Open this link in a browser to pay
|
|
16
|
+
say(`${tick} Opened Stripe Checkout in your browser.`);
|
|
17
|
+
else {
|
|
18
|
+
say(`${dot} Open this link in a browser to pay:`);
|
|
19
|
+
say(` ${link.href}`);
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
function sayOutcome(state, plan) {
|
|
21
23
|
const repo = planName(plan);
|
|
@@ -28,7 +30,7 @@ function sayOutcome(state, plan) {
|
|
|
28
30
|
say(` ${scanLink(state.scanId)}`);
|
|
29
31
|
}
|
|
30
32
|
else if (state.kind === 'paid') {
|
|
31
|
-
say(`${tick} Payment received for ${repo}. The scan starts within a few minutes
|
|
33
|
+
say(`${tick} Payment received for ${repo}. The scan starts within a few minutes: npx sekura@latest scans`);
|
|
32
34
|
}
|
|
33
35
|
else if (state.kind === 'cancelled') {
|
|
34
36
|
say(`${cross} Checkout was closed without paying, so nothing was charged and ${repo} is back to how it was.`);
|
|
@@ -64,7 +66,7 @@ export async function runPay(link, opts = {}) {
|
|
|
64
66
|
sayOpened(url, opened);
|
|
65
67
|
const key = readKey();
|
|
66
68
|
if (!opts.plan || !key) {
|
|
67
|
-
say(`${dot} ${key ? 'No plan id was given' : 'Not signed in here (npx sekura@latest login)'}, so this terminal cannot tell when the payment lands. After paying
|
|
69
|
+
say(`${dot} ${key ? 'No plan id was given' : 'Not signed in here (npx sekura@latest login)'}, so this terminal cannot tell when the payment lands. After paying: npx sekura@latest plans`);
|
|
68
70
|
return PAY_EXIT.notSignedIn;
|
|
69
71
|
}
|
|
70
72
|
const planId = opts.plan;
|
|
@@ -90,7 +92,7 @@ export async function runPay(link, opts = {}) {
|
|
|
90
92
|
if (abandoned === 'paid')
|
|
91
93
|
return PAY_EXIT.paid;
|
|
92
94
|
}
|
|
93
|
-
say(`${dot} ${result === 'skipped' ? 'Stopped waiting' : 'No payment yet'}. The Checkout link stays valid for 24 hours; the scan starts as soon as it is paid.
|
|
95
|
+
say(`${dot} ${result === 'skipped' ? 'Stopped waiting' : 'No payment yet'}. The Checkout link stays valid for 24 hours; the scan starts as soon as it is paid. To check: npx sekura@latest plans`);
|
|
94
96
|
return PAY_EXIT.timeout;
|
|
95
97
|
}
|
|
96
98
|
export const payCommand = new Command('pay')
|
package/dist/commands/plans.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { input } from '@inquirer/prompts';
|
|
3
|
-
import { call, getPlans, tools } from '../api.js';
|
|
4
|
-
import { EXIT, Exit } from '../exit.js';
|
|
3
|
+
import { call, getPlans, isToolError, tools } from '../api.js';
|
|
4
|
+
import { EXIT, Exit, messageFor } from '../exit.js';
|
|
5
5
|
import { confirmQuote, requireKey, startWithPayment } from '../flow.js';
|
|
6
6
|
import { monthlyName } from '../payment.js';
|
|
7
|
-
import { select, dot, interactive, printJson, printTable, say } from '../ui.js';
|
|
7
|
+
import { select, cross, dot, interactive, printJson, printTable, say } from '../ui.js';
|
|
8
8
|
import { afterStart, ready, resolveRepository, sayText, withQuoteOptions, withoutConfirm } from './shared.js';
|
|
9
9
|
const when = (iso) => (iso ? iso.replace('T', ' ').slice(0, 16) : '');
|
|
10
10
|
const stateOf = (p) => p.status === 'pending' ? 'waiting on a payment'
|
|
@@ -68,15 +68,34 @@ const localZone = () => {
|
|
|
68
68
|
return 'UTC';
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
+
/** An IANA zone this machine's Intl knows, as the server checks it. */
|
|
72
|
+
export function validZone(raw) {
|
|
73
|
+
if (!raw.trim())
|
|
74
|
+
return false;
|
|
75
|
+
try {
|
|
76
|
+
new Intl.DateTimeFormat('en-US', { timeZone: raw.trim() });
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** The day an on-demand Weekly plan carries. A server before 30 November
|
|
84
|
+
* 2026 refuses an on-demand weekly schedule with no weekday ("a weekday is
|
|
85
|
+
* required … call quoteAlways again", Varsha's test, P4), though nothing
|
|
86
|
+
* runs on it; production is such a server, so the CLI always sends one. */
|
|
87
|
+
const ON_DEMAND_WEEKDAY = 1;
|
|
71
88
|
const flagged = (f) => !!f.onDemand || f.weekday !== undefined || f.time !== undefined || f.every !== undefined;
|
|
72
89
|
export function scheduleFromFlags(tier, f) {
|
|
73
90
|
const kind = cadenceOf(tier);
|
|
74
91
|
const tz = f.tz?.trim() || localZone();
|
|
92
|
+
if (!validZone(tz))
|
|
93
|
+
throw new Exit(EXIT.error, `--tz takes a time zone such as Europe/London or America/New_York; ${tz} is not one.`);
|
|
75
94
|
const minute = f.time !== undefined ? minuteOf(f.time) : 540;
|
|
76
95
|
if (f.onDemand) {
|
|
77
96
|
if (f.weekday !== undefined || f.every !== undefined)
|
|
78
97
|
throw new Exit(EXIT.error, '--on-demand means no scheduled runs, so it does not go with --weekday or --every.');
|
|
79
|
-
return { kind, minute, tz, onDemand: true };
|
|
98
|
+
return kind === 'weekly' ? { kind, weekday: ON_DEMAND_WEEKDAY, minute, tz, onDemand: true } : { kind, minute, tz, onDemand: true };
|
|
80
99
|
}
|
|
81
100
|
if (kind === 'weekly') {
|
|
82
101
|
if (f.every !== undefined)
|
|
@@ -92,9 +111,8 @@ export function scheduleFromFlags(tier, f) {
|
|
|
92
111
|
throw new Exit(EXIT.error, `--every takes 1, 2 or 3 (every day, every second day, every third day); ${f.every} is not one.`);
|
|
93
112
|
return { kind, minute, tz, everyDays: every };
|
|
94
113
|
}
|
|
95
|
-
async function askSchedule(tier) {
|
|
114
|
+
async function askSchedule(tier, givenTz) {
|
|
96
115
|
const kind = cadenceOf(tier);
|
|
97
|
-
const tz = localZone();
|
|
98
116
|
const how = await select({
|
|
99
117
|
message: 'When should it scan?',
|
|
100
118
|
choices: [
|
|
@@ -103,7 +121,14 @@ async function askSchedule(tier) {
|
|
|
103
121
|
],
|
|
104
122
|
});
|
|
105
123
|
if (how === 'on-demand')
|
|
106
|
-
return {
|
|
124
|
+
return scheduleFromFlags(tier, { onDemand: true, tz: givenTz });
|
|
125
|
+
// The time zone was shown in the time question but never asked (Varsha's
|
|
126
|
+
// test, P1): this machine's zone is the default, and --tz answers it.
|
|
127
|
+
const tz = givenTz?.trim() || (await input({
|
|
128
|
+
message: 'Time zone?',
|
|
129
|
+
default: localZone(),
|
|
130
|
+
validate: (v) => validZone(v) || 'A time zone such as Europe/London or America/New_York',
|
|
131
|
+
})).trim();
|
|
107
132
|
const flags = { tz };
|
|
108
133
|
if (kind === 'weekly') {
|
|
109
134
|
flags.weekday = String(await select({ message: 'Which day?', choices: DAYS.map((d, i) => ({ name: d[0].toUpperCase() + d.slice(1), value: i })), default: 1 }));
|
|
@@ -118,9 +143,30 @@ async function scheduleFor(tier, f, command) {
|
|
|
118
143
|
if (flagged(f))
|
|
119
144
|
return scheduleFromFlags(tier, f);
|
|
120
145
|
if (interactive())
|
|
121
|
-
return askSchedule(tier);
|
|
146
|
+
return askSchedule(tier, f.tz);
|
|
122
147
|
throw new Exit(EXIT.error, `${command} needs a schedule when there is no terminal to ask in: ${cadenceOf(tier) === 'weekly' ? '--weekday <day> --time <HH:MM>' : '--every <1|2|3> --time <HH:MM>'}, or --on-demand. --tz names the time zone; the default is this machine's.`);
|
|
123
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Quotes with a schedule, and asks for it again when the server refuses it.
|
|
151
|
+
* An interactive run ended on the refusal, with words for an agent ("correct
|
|
152
|
+
* the schedule and call quoteAlways again", Varsha's test, P4). A schedule
|
|
153
|
+
* that came from flags is the caller's to correct, so that still ends the run.
|
|
154
|
+
*/
|
|
155
|
+
async function quoteSchedule(f, ask, quote) {
|
|
156
|
+
for (;;) {
|
|
157
|
+
const args = await ask();
|
|
158
|
+
try {
|
|
159
|
+
return await quote(args);
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
const asked = !f.confirm && !f.yes && !flagged(f) && interactive();
|
|
163
|
+
if (!asked || !isToolError(e, 'invalid_schedule'))
|
|
164
|
+
throw e;
|
|
165
|
+
const why = /cannot be used: (.+?)\. Nothing/.exec(messageFor(e))?.[1];
|
|
166
|
+
say(`${cross} That schedule cannot be used${why ? `: ${why}` : ''}. Nothing was changed or charged. Choose another:`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
124
170
|
const withScheduleOptions = (cmd) => cmd
|
|
125
171
|
.option('--on-demand', 'no scheduled runs: you start each scan with sekura plan run')
|
|
126
172
|
.option('--weekday <day>', 'Weekly: the day it runs, such as monday')
|
|
@@ -138,20 +184,19 @@ export async function runPlanStart(repo, opts = {}) {
|
|
|
138
184
|
const tier = tierOf(opts.tier);
|
|
139
185
|
const command = `npx sekura@latest plan start ${repository}`;
|
|
140
186
|
await ready(async () => {
|
|
141
|
-
const
|
|
142
|
-
const agreed = await confirmQuote({
|
|
187
|
+
const agreed = await quoteSchedule(opts, async () => (opts.confirm ? { repository } : { repository, tier, schedule: await scheduleFor(tier, opts, command) }), (args) => confirmQuote({
|
|
143
188
|
op: 'quoteAlways',
|
|
144
189
|
args,
|
|
145
190
|
fetch: () => tools.quoteAlways(key, args),
|
|
146
191
|
flags: opts,
|
|
147
192
|
command,
|
|
148
193
|
question: `Do you agree, and start ${tier === 'pro' ? 'More frequently' : 'Weekly'} for ${repository}?`,
|
|
149
|
-
sayQuote: sayText,
|
|
150
|
-
});
|
|
194
|
+
sayQuote: (text) => sayText(text, repository),
|
|
195
|
+
}));
|
|
151
196
|
if (agreed.kind === 'quoted')
|
|
152
197
|
return;
|
|
153
198
|
const outcome = await startWithPayment(key, agreed.confirmOperation, agreed.confirmArguments, { quoteId: agreed.quoteId, browser: opts.browser });
|
|
154
|
-
await afterStart(key, outcome, { what: `The plan for ${repository}`, watch: opts.watch, report: opts.report, output: opts.output, json: opts.json });
|
|
199
|
+
await afterStart(key, outcome, { what: `The plan for ${repository}`, repository, watch: opts.watch, report: opts.report, output: opts.output, json: opts.json });
|
|
155
200
|
});
|
|
156
201
|
}
|
|
157
202
|
async function planFor(key, repository) {
|
|
@@ -165,22 +210,21 @@ export async function runPlanSchedule(repo, opts = {}) {
|
|
|
165
210
|
const repository = resolveRepository(repo, opts.cwd);
|
|
166
211
|
const command = `npx sekura@latest plan schedule ${repository}`;
|
|
167
212
|
await ready(async () => {
|
|
168
|
-
let
|
|
213
|
+
let plan;
|
|
169
214
|
if (!opts.confirm) {
|
|
170
|
-
|
|
215
|
+
plan = await planFor(key, repository);
|
|
171
216
|
if (!plan || !monthlyName(plan))
|
|
172
217
|
throw new Exit(EXIT.error, `${repository} has no monthly plan to schedule. To start one: npx sekura@latest plan start ${repository}`);
|
|
173
|
-
args = { repository, schedule: await scheduleFor(plan.tier ?? plan.plan, opts, command) };
|
|
174
218
|
}
|
|
175
|
-
const agreed = await confirmQuote({
|
|
219
|
+
const agreed = await quoteSchedule(opts, async () => (plan ? { repository, schedule: await scheduleFor(plan.tier ?? plan.plan, opts, command) } : { repository }), (args) => confirmQuote({
|
|
176
220
|
op: 'quoteSchedule',
|
|
177
221
|
args,
|
|
178
222
|
fetch: () => tools.quoteSchedule(key, args),
|
|
179
223
|
flags: opts,
|
|
180
224
|
command,
|
|
181
225
|
question: `Change the schedule for ${repository}?`,
|
|
182
|
-
sayQuote: sayText,
|
|
183
|
-
});
|
|
226
|
+
sayQuote: (text) => sayText(text, repository),
|
|
227
|
+
}));
|
|
184
228
|
if (agreed.kind === 'quoted')
|
|
185
229
|
return;
|
|
186
230
|
const outcome = await startWithPayment(key, agreed.confirmOperation, agreed.confirmArguments, { quoteId: agreed.quoteId, browser: opts.browser });
|
|
@@ -188,10 +232,10 @@ export async function runPlanSchedule(repo, opts = {}) {
|
|
|
188
232
|
if (opts.json)
|
|
189
233
|
printJson(outcome.data);
|
|
190
234
|
else
|
|
191
|
-
sayText(outcome.text);
|
|
235
|
+
sayText(outcome.text, repository);
|
|
192
236
|
return;
|
|
193
237
|
}
|
|
194
|
-
await afterStart(key, outcome, { what: `The new schedule for ${repository}`, watch: false, json: opts.json });
|
|
238
|
+
await afterStart(key, outcome, { what: `The new schedule for ${repository}`, repository, watch: false, json: opts.json });
|
|
195
239
|
});
|
|
196
240
|
}
|
|
197
241
|
/**
|
|
@@ -207,30 +251,29 @@ export async function runPlanChange(repo, opts = {}) {
|
|
|
207
251
|
const repository = resolveRepository(repo, opts.cwd);
|
|
208
252
|
const command = `npx sekura@latest plan change ${repository}`;
|
|
209
253
|
await ready(async () => {
|
|
210
|
-
let
|
|
254
|
+
let to = null;
|
|
211
255
|
let toName = 'the other plan';
|
|
212
256
|
if (!opts.confirm) {
|
|
213
257
|
const plan = await planFor(key, repository);
|
|
214
258
|
if (!plan || !monthlyName(plan))
|
|
215
259
|
throw new Exit(EXIT.error, `${repository} has no monthly plan to change. To start one: npx sekura@latest plan start ${repository}`);
|
|
216
260
|
const now = tierOf(plan.tier === 'pro' ? 'pro' : 'always');
|
|
217
|
-
|
|
261
|
+
to = opts.to ? tierOf(opts.to) : now === 'pro' ? 'always' : 'pro';
|
|
218
262
|
if (to === now)
|
|
219
263
|
throw new Exit(EXIT.error, `${repository} is already on ${monthlyName(plan)}. To change when it scans: npx sekura@latest plan schedule ${repository}`);
|
|
220
264
|
toName = to === 'pro' ? 'More frequently' : 'Weekly';
|
|
221
265
|
if (!flagged(opts) && interactive())
|
|
222
266
|
say(` ${toName} scans ${to === 'pro' ? 'every one to three days' : 'once a week'}. Choose its schedule:`);
|
|
223
|
-
args = { repository, tier: to, schedule: await scheduleFor(to, opts, command) };
|
|
224
267
|
}
|
|
225
|
-
const agreed = await confirmQuote({
|
|
268
|
+
const agreed = await quoteSchedule(opts, async () => (to ? { repository, tier: to, schedule: await scheduleFor(to, opts, command) } : { repository }), (args) => confirmQuote({
|
|
226
269
|
op: 'quotePlanChange',
|
|
227
270
|
args,
|
|
228
271
|
fetch: () => tools.quotePlanChange(key, args),
|
|
229
272
|
flags: opts,
|
|
230
273
|
command,
|
|
231
274
|
question: `Move ${repository} to ${toName}?`,
|
|
232
|
-
sayQuote: sayText,
|
|
233
|
-
});
|
|
275
|
+
sayQuote: (text) => sayText(text, repository),
|
|
276
|
+
}));
|
|
234
277
|
if (agreed.kind === 'quoted')
|
|
235
278
|
return;
|
|
236
279
|
const outcome = await startWithPayment(key, agreed.confirmOperation, agreed.confirmArguments, { quoteId: agreed.quoteId, browser: opts.browser });
|
|
@@ -238,10 +281,10 @@ export async function runPlanChange(repo, opts = {}) {
|
|
|
238
281
|
if (opts.json)
|
|
239
282
|
printJson(outcome.data);
|
|
240
283
|
else
|
|
241
|
-
sayText(outcome.text);
|
|
284
|
+
sayText(outcome.text, repository);
|
|
242
285
|
return;
|
|
243
286
|
}
|
|
244
|
-
await afterStart(key, outcome, { what: `The plan change for ${repository}`, watch: false, json: opts.json });
|
|
287
|
+
await afterStart(key, outcome, { what: `The plan change for ${repository}`, repository, watch: false, json: opts.json });
|
|
245
288
|
});
|
|
246
289
|
}
|
|
247
290
|
export async function runPlanRun(repo, opts = {}) {
|
|
@@ -256,12 +299,12 @@ export async function runPlanRun(repo, opts = {}) {
|
|
|
256
299
|
flags: opts,
|
|
257
300
|
command: `npx sekura@latest plan run ${repository}`,
|
|
258
301
|
question: `Start a scan of ${repository} now?`,
|
|
259
|
-
sayQuote: sayText,
|
|
302
|
+
sayQuote: (text) => sayText(text, repository),
|
|
260
303
|
});
|
|
261
304
|
if (agreed.kind === 'quoted')
|
|
262
305
|
return;
|
|
263
306
|
const outcome = await startWithPayment(key, agreed.confirmOperation, agreed.confirmArguments, { quoteId: agreed.quoteId, browser: opts.browser });
|
|
264
|
-
await afterStart(key, outcome, { what: `The scan of ${repository}`, watch: opts.watch, report: opts.report, output: opts.output, json: opts.json });
|
|
307
|
+
await afterStart(key, outcome, { what: `The scan of ${repository}`, repository, watch: opts.watch, report: opts.report, output: opts.output, json: opts.json });
|
|
265
308
|
});
|
|
266
309
|
}
|
|
267
310
|
export async function runPlanCancel(repo, opts = {}) {
|
|
@@ -276,7 +319,7 @@ export async function runPlanCancel(repo, opts = {}) {
|
|
|
276
319
|
flags: opts,
|
|
277
320
|
command: `npx sekura@latest plan cancel ${repository}`,
|
|
278
321
|
question: `Cancel the plan for ${repository}?`,
|
|
279
|
-
sayQuote: sayText,
|
|
322
|
+
sayQuote: (text) => sayText(text, repository),
|
|
280
323
|
});
|
|
281
324
|
if (agreed.kind === 'quoted')
|
|
282
325
|
return;
|
|
@@ -284,7 +327,7 @@ export async function runPlanCancel(repo, opts = {}) {
|
|
|
284
327
|
if (opts.json)
|
|
285
328
|
printJson(reply.data);
|
|
286
329
|
else
|
|
287
|
-
sayText(reply.text);
|
|
330
|
+
sayText(reply.text, repository);
|
|
288
331
|
});
|
|
289
332
|
}
|
|
290
333
|
const REPO_ARG = 'owner/repo; the default is your saved repository, then this folder\'s GitHub remote';
|
package/dist/commands/scan.js
CHANGED
|
@@ -16,12 +16,12 @@ export async function runScan(repo, opts = {}) {
|
|
|
16
16
|
flags: opts,
|
|
17
17
|
command: `npx sekura@latest scan ${repository}`,
|
|
18
18
|
question: `Do you agree, and start the scan of ${repository}?`,
|
|
19
|
-
sayQuote: sayText,
|
|
19
|
+
sayQuote: (text) => sayText(text, repository),
|
|
20
20
|
});
|
|
21
21
|
if (agreed.kind === 'quoted')
|
|
22
22
|
return;
|
|
23
23
|
const outcome = await startWithPayment(key, agreed.confirmOperation, agreed.confirmArguments, { quoteId: agreed.quoteId, browser: opts.browser });
|
|
24
|
-
await afterStart(key, outcome, { what: `The scan of ${repository}`, watch: opts.watch, report: opts.report, output: opts.output, json: opts.json, intervalMs: opts.intervalMs, timeoutMs: opts.timeoutMs });
|
|
24
|
+
await afterStart(key, outcome, { what: `The scan of ${repository}`, repository, watch: opts.watch, report: opts.report, output: opts.output, json: opts.json, intervalMs: opts.intervalMs, timeoutMs: opts.timeoutMs });
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
export async function runScanShow(scanId, opts = {}) {
|
|
@@ -31,7 +31,7 @@ export async function runScanShow(scanId, opts = {}) {
|
|
|
31
31
|
const w = await watchScan(key, scanId, {
|
|
32
32
|
...(opts.timeoutMs ? { timeoutMs: opts.timeoutMs } : {}),
|
|
33
33
|
...(opts.intervalMs ? { intervalMs: opts.intervalMs } : {}),
|
|
34
|
-
onStatus: (status) => { if (!scanFinished(status) && !opts.json)
|
|
34
|
+
onStatus: (status) => { if (!scanFinished(status) && !opts.json && !process.stderr.isTTY)
|
|
35
35
|
say(`${dot} ${status}`); },
|
|
36
36
|
});
|
|
37
37
|
if (w.detail)
|
package/dist/commands/shared.js
CHANGED
|
@@ -55,30 +55,127 @@ export function resolveRepository(given, cwd = process.cwd()) {
|
|
|
55
55
|
const AGENT_LINE = /^If the person agrees, call |payment: \{ sharedPaymentToken|^nextStep:/;
|
|
56
56
|
const CONFIRM_WITH = /; confirm with payment: \{ savedCard: (?:true|\{ card: "[^"]*" \}) \}/g;
|
|
57
57
|
const CHECKOUT_HOW = /: leave payment out; the answer is 402 with a Stripe Checkout link to open in the person's browser/;
|
|
58
|
-
|
|
58
|
+
/** The server's tool names. A person at a terminal cannot call any of them,
|
|
59
|
+
* so a sentence still naming one after the rewrites below is left out. */
|
|
60
|
+
export const TOOL_NAMES = [
|
|
61
|
+
'getAccount', 'listRepositories', 'listScans', 'getScan', 'getScanFindings', 'getReportLink', 'getPlans', 'getBilling',
|
|
62
|
+
'quoteScan', 'startScan', 'quoteAlways', 'startAlways', 'quoteSchedule', 'updateSchedule', 'quotePlanChange', 'changePlan',
|
|
63
|
+
'quoteRunNow', 'runNow', 'previewCancelScan', 'cancelScan', 'previewCancelPlan', 'cancelPlan', 'quoteComparison', 'startComparison',
|
|
64
|
+
];
|
|
65
|
+
/** Words written for an agent, never for the person reading a terminal. */
|
|
66
|
+
export const AGENT_WORDS = new RegExp(`\\bthe person\\b|\\bconnector\\b|\\bconnected tool\\b|\\b(?:${TOOL_NAMES.join('|')})\\b`, 'i');
|
|
67
|
+
// The server writes for an agent that shows its answer to a person ("the
|
|
59
68
|
// 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
|
|
61
|
-
// show themselves the price (29 November 2026)
|
|
62
|
-
//
|
|
69
|
+
// terminal, it talks about the reader in the third person, tells them to
|
|
70
|
+
// show themselves the price (29 November 2026), and names tools they cannot
|
|
71
|
+
// call: getScan, quoteAlways, cancelScan, "as given through this connector"
|
|
72
|
+
// (Varsha's test, 30 November 2026: F10, R2, R4, P1, C3, C4, C7, X1). These
|
|
73
|
+
// are the server's own sentences (sekura-www src/connector), turned into the
|
|
74
|
+
// reader's; a sentence none of them reaches that still speaks to an agent is
|
|
75
|
+
// left out rather than printed.
|
|
63
76
|
const PERSON_REWRITES = [
|
|
64
77
|
[/, 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
|
-
|
|
78
|
+
// "Before Sekura moves o/r to More frequently, show the person the change
|
|
79
|
+
// below and ask whether they agree." and its kin for a schedule, a run now.
|
|
80
|
+
[/Before Sekura (\w+?)s (.+?), show the person (what it does|the change) below and ask whether they agree\./g,
|
|
81
|
+
(_m, verb, what, kind) => `Sekura would ${verb} ${what}. Here is ${kind === 'the change' ? 'the change' : 'what it does'}.`],
|
|
82
|
+
[/ ?Show the person what that means and ask whether they agree\./g, ''],
|
|
66
83
|
[/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
84
|
(_m, url, price) => `Your first scan is still free, at ${url}. Agreeing here buys a one-time scan at ${price} instead.`],
|
|
85
|
+
[/The free[ ]first[ ]scan is started on sekura\.ai by the person, at (\S+?), not through a connected tool\. Through this connection a scan is a one-time scan: call \w+ to show the person the price, and confirm with \w+ only once they agree\./g,
|
|
86
|
+
(_m, url) => `Your first scan is free, and starts on the website, at ${url}. Here, a scan is a paid one-time scan.`],
|
|
68
87
|
// The refusal for a stale wording tells an agent to re-quote and show the
|
|
69
88
|
// person; in a terminal the person is the reader (29 November 2026).
|
|
70
89
|
[/The authorization wording has changed since it was shown: the current version is \S+\. Nothing was started\. Call \w+ again to get the current text, show it to the person, and confirm with \w+ and disclosureVersion "[^"]+" only once they agree\.(?:\s+https?:\/\/\S+)?/g,
|
|
71
90
|
'The authorization wording changed since you saw it. Nothing was started. Run the same command again to see the current wording.'],
|
|
91
|
+
// "Nothing is charged" said twice in one breath (Varsha's test, F10).
|
|
92
|
+
[/Nothing is charged\. This is the account's free[ ]first[ ]scan: no card is needed and nothing is charged\./g, 'Your first scan is free: nothing is charged.'],
|
|
93
|
+
[/This is the account's free[ ]first[ ]scan: no card is needed and nothing is charged\./g, 'Your first scan is free: no card is needed and nothing is charged.'],
|
|
94
|
+
[/;\s*getScan with that id reports progress\./g, '.'],
|
|
95
|
+
[/\.\s*getScan with that id reports progress, and the report/g, '. The report'],
|
|
96
|
+
[/\s*getScan with that id reports progress\./g, ''],
|
|
97
|
+
[/The authorization was recorded in this account's name, as given through this connector\./g, 'Your authorization is recorded on your account.'],
|
|
98
|
+
[/(?:under )?a new authorization recorded in the person's name through this connector/g, 'a new authorization in your name'],
|
|
99
|
+
[/listScans shows it once it has started/g, 'npx sekura@latest scans shows it once it has started'],
|
|
100
|
+
[/;\s*the answer to updateSchedule states when the next scan runs/g, ''],
|
|
101
|
+
[/\(scan id ([\w-]+)\)([^()]*?)[.;] cancelScan stops it while its five-minute window is open\./g,
|
|
102
|
+
(_m, id, rest) => `(scan id ${id})${rest}. To stop it inside its five-minute cancel window: npx sekura@latest scan cancel ${id}`],
|
|
103
|
+
[/until the person pays on that page, and if they close it/g, 'until you pay on that page, and if you close it'],
|
|
104
|
+
[/; correct the schedule and call \w+ again\./g, '; choose another schedule.'],
|
|
105
|
+
[/; call \w+ again for how it would be paid now\./g, '; run the same command again to see how it would be paid now.'],
|
|
106
|
+
[/,? or call \w+ again for how it would be paid now\./g, ', or run the same command again to see how it would be paid now.'],
|
|
107
|
+
[/\b[Cc]all (\w+)(?: again)?(?: with the same arguments)?,? (?:to )?show the person [^.]*?only once they (?:agree|pick one)\./g, 'Run the same command again to see it.'],
|
|
108
|
+
[/in the person's browser/g, 'in your browser'],
|
|
109
|
+
[/the person's name/g, 'your name'],
|
|
110
|
+
[/as the person chooses/g, 'as you choose'],
|
|
72
111
|
];
|
|
73
|
-
|
|
112
|
+
/** One sentence at a time, for the last check: a period that ends a sentence
|
|
113
|
+
* is followed by a space and a capital; one inside a URL or "e.g." is not. */
|
|
114
|
+
const sentences = (line) => line.split(/(?<=[.!?])\s+(?=[A-Z])/);
|
|
115
|
+
/** The repository as the person typed it, where the server answered with its
|
|
116
|
+
* lower-cased canonical name ("varsha311002/navidrome", Varsha's test, F10). */
|
|
117
|
+
export function namedAs(text, repo) {
|
|
118
|
+
if (!repo || !repo.includes('/'))
|
|
119
|
+
return text;
|
|
120
|
+
const esc = repo.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
121
|
+
return text.replace(new RegExp(`(?<![\\w./-])${esc}(?![\\w-]|\\.[\\w])`, 'gi'), repo);
|
|
122
|
+
}
|
|
123
|
+
/** "How it can be paid, as the person chooses …" and its list of options,
|
|
124
|
+
* each with the value an agent sends, became one plain line. The chooser
|
|
125
|
+
* below the quote asks how to pay; "Change payment method" is not one of
|
|
126
|
+
* its choices, so the line does not offer it (Varsha's test, R4). */
|
|
127
|
+
function paymentLine(items) {
|
|
128
|
+
const cards = [];
|
|
129
|
+
let checkout = false;
|
|
130
|
+
for (const raw of items) {
|
|
131
|
+
const item = raw.replace(/^- /, '');
|
|
132
|
+
if (/^Pay with a Checkout link\b/.test(item)) {
|
|
133
|
+
checkout = true;
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
if (/^(Change payment method|A Shared Payment Token)\b/.test(item))
|
|
137
|
+
continue;
|
|
138
|
+
const card = /^(.+?)(?: \((?:the )?default card\))?: charged in place/.exec(item);
|
|
139
|
+
if (card)
|
|
140
|
+
cards.push(`${card[1]}${/default card\)/.test(item) ? ' (default)' : ''}`);
|
|
141
|
+
}
|
|
142
|
+
const ways = [...cards, ...(checkout ? [cards.length ? 'a Stripe Checkout page' : 'a Stripe Checkout page in your browser'] : [])];
|
|
143
|
+
return `Payment: ${ways.length > 1 ? `${ways.slice(0, -1).join(', ')} or ${ways[ways.length - 1]}` : ways[0] ?? 'as Sekura names it'}`;
|
|
144
|
+
}
|
|
145
|
+
export function personText(text, repo) {
|
|
74
146
|
const out = [];
|
|
75
|
-
|
|
147
|
+
const lines = text.split('\n');
|
|
148
|
+
let inAuth = false;
|
|
149
|
+
for (let i = 0; i < lines.length; i++) {
|
|
150
|
+
const raw = lines[i];
|
|
151
|
+
// The authorization is the hashed text the person agrees to: never
|
|
152
|
+
// rewritten, never shortened.
|
|
153
|
+
if (/^Authorization wording, version .+:$/.test(raw)) {
|
|
154
|
+
inAuth = true;
|
|
155
|
+
out.push(raw);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (inAuth && !AGENT_LINE.test(raw)) {
|
|
159
|
+
out.push(raw);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
inAuth = false;
|
|
76
163
|
if (AGENT_LINE.test(raw.replace(/^- /, '')))
|
|
77
164
|
continue;
|
|
165
|
+
if (/^How it can be paid\b.*:$/.test(raw)) {
|
|
166
|
+
const items = [];
|
|
167
|
+
while (i + 1 < lines.length && lines[i + 1].startsWith('- '))
|
|
168
|
+
items.push(lines[++i]);
|
|
169
|
+
out.push(paymentLine(items));
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
78
172
|
let line = raw.replace(CONFIRM_WITH, '').replace(CHECKOUT_HOW, ': a Stripe Checkout page in your browser');
|
|
79
173
|
for (const [re, to] of PERSON_REWRITES)
|
|
80
174
|
line = line.replace(re, to);
|
|
81
|
-
out.
|
|
175
|
+
// Anything still written for an agent is left out, a sentence at a time.
|
|
176
|
+
if (AGENT_WORDS.test(line))
|
|
177
|
+
line = sentences(line).filter((x) => !AGENT_WORDS.test(x)).join(' ');
|
|
178
|
+
out.push(namedAs(line, repo));
|
|
82
179
|
}
|
|
83
180
|
while (out.length && !out[out.length - 1].trim())
|
|
84
181
|
out.pop();
|
|
@@ -95,7 +192,7 @@ export function personText(text) {
|
|
|
95
192
|
* text the person agrees to is the text that was hashed. Anything this does
|
|
96
193
|
* not recognise is printed as it came.
|
|
97
194
|
*/
|
|
98
|
-
export function quoteLines(text) {
|
|
195
|
+
export function quoteLines(text, repo) {
|
|
99
196
|
const out = [];
|
|
100
197
|
let version = null;
|
|
101
198
|
let inAuth = false;
|
|
@@ -109,7 +206,7 @@ export function quoteLines(text) {
|
|
|
109
206
|
out.push(`${c.dim(k.padEnd(w))} ${v}`);
|
|
110
207
|
facts.length = 0;
|
|
111
208
|
};
|
|
112
|
-
for (const raw of personText(text).split('\n')) {
|
|
209
|
+
for (const raw of personText(text, repo).split('\n')) {
|
|
113
210
|
const line = raw.trimEnd();
|
|
114
211
|
const wording = /^Authorization wording, version (.+?):$/.exec(line);
|
|
115
212
|
if (wording) {
|
|
@@ -149,16 +246,20 @@ export function quoteLines(text) {
|
|
|
149
246
|
out.push(line);
|
|
150
247
|
continue;
|
|
151
248
|
}
|
|
152
|
-
const fact = /^(Repository|Price|How it is paid|Schedule|Plan|Target|Live app|Test account|Card|Charged today|Then|Tests?): (.+)$/.exec(line);
|
|
249
|
+
const fact = /^(Repository|Price|How it is paid|Payment|Schedule|Schedule now|New schedule|Plan|Plan now|New plan|What stops|Billing|Target|Live app|Test account|Card|Charged today|Then|Tests?): (.+)$/.exec(line);
|
|
153
250
|
if (fact) {
|
|
154
|
-
|
|
251
|
+
let value = fact[1] === 'Price' && /^nothing\. (?:This is the account's free[ ]first[ ]scan|Your first scan is free)/.test(fact[2]) ? 'Free, your first scan (no card needed)' : fact[2];
|
|
252
|
+
// One sentence reads as a value, not a sentence: "$10 (one-time scan)",
|
|
253
|
+
// not "$10 (one-time scan)." (Varsha's test, R2).
|
|
254
|
+
if (/\.$/.test(value) && !/[.!?]\s/.test(value.slice(0, -1)))
|
|
255
|
+
value = value.slice(0, -1);
|
|
155
256
|
facts.push([fact[1], value]);
|
|
156
257
|
continue;
|
|
157
258
|
}
|
|
158
|
-
const nothing = /^(.*?)\s*Nothing has been started or charged
|
|
259
|
+
const nothing = /^(.*?)\s*(Nothing has been (?:started|changed|cancelled)(?: or charged)?(?: yet)?\.)$/.exec(line);
|
|
159
260
|
if (nothing && nothing[1]) {
|
|
160
261
|
flushFacts();
|
|
161
|
-
out.push(nothing[1], c.dim(
|
|
262
|
+
out.push(nothing[1], c.dim(nothing[2]));
|
|
162
263
|
continue;
|
|
163
264
|
}
|
|
164
265
|
flushFacts();
|
|
@@ -173,9 +274,9 @@ export function quoteLines(text) {
|
|
|
173
274
|
out.push('', c.dim(`Version ${version}`));
|
|
174
275
|
return out;
|
|
175
276
|
}
|
|
176
|
-
export function sayText(text) {
|
|
277
|
+
export function sayText(text, repo) {
|
|
177
278
|
say();
|
|
178
|
-
for (const l of quoteLines(text))
|
|
279
|
+
for (const l of quoteLines(text, repo))
|
|
179
280
|
say(l ? ` ${l}` : '');
|
|
180
281
|
say();
|
|
181
282
|
}
|
|
@@ -290,7 +391,9 @@ export async function followScan(key, scanId, opts = {}) {
|
|
|
290
391
|
const w = await watchScan(key, scanId, {
|
|
291
392
|
...(opts.timeoutMs ? { timeoutMs: opts.timeoutMs } : {}),
|
|
292
393
|
...(opts.intervalMs ? { intervalMs: opts.intervalMs } : {}),
|
|
293
|
-
|
|
394
|
+
// On a terminal the state changes in place on the spinner's line; a log
|
|
395
|
+
// gets one line per state.
|
|
396
|
+
onStatus: (status) => { if (!scanFinished(status) && !process.stderr.isTTY)
|
|
294
397
|
say(`${dot} ${status}`); },
|
|
295
398
|
});
|
|
296
399
|
if (w.result !== 'done') {
|
|
@@ -318,7 +421,7 @@ export async function followScan(key, scanId, opts = {}) {
|
|
|
318
421
|
export async function afterStart(key, o, opts) {
|
|
319
422
|
if (o.kind === 'started') {
|
|
320
423
|
if (o.text)
|
|
321
|
-
sayText(o.text);
|
|
424
|
+
sayText(o.text, opts.repository);
|
|
322
425
|
say(`${tick} ${opts.what} started.${o.scanId ? ` Scan id ${o.scanId}.` : ''}`);
|
|
323
426
|
if (o.scanId)
|
|
324
427
|
await followScan(key, o.scanId, opts);
|
|
@@ -336,7 +439,17 @@ export async function afterStart(key, o, opts) {
|
|
|
336
439
|
if (o.kind === 'payment-cancelled') {
|
|
337
440
|
throw new Exit(EXIT.declined, 'Checkout was closed without paying, so nothing was charged and nothing was started.', { planId: o.planId });
|
|
338
441
|
}
|
|
339
|
-
if (o.why === 'skipped')
|
|
340
|
-
|
|
341
|
-
|
|
442
|
+
if (o.why === 'skipped') {
|
|
443
|
+
// A cancelled payment is the end of it: the "stays valid for 24 hours"
|
|
444
|
+
// line that followed contradicted "the Checkout link stops working" just
|
|
445
|
+
// above it (Varsha's test, P4).
|
|
446
|
+
const abandoned = await offerAbandon(key, o.planId);
|
|
447
|
+
if (abandoned === 'abandoned')
|
|
448
|
+
throw new Exit(EXIT.declined, '', { planId: o.planId });
|
|
449
|
+
if (abandoned === 'paid') {
|
|
450
|
+
say(`${dot} The scan starts within a few minutes: npx sekura@latest scans`);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
throw new Exit(exitCodeOfStart(o), `No payment yet. The Checkout link stays valid for 24 hours, and the scan starts as soon as it is paid:\n ${o.checkoutUrl}${o.planId ? `\n To wait for it again: npx sekura@latest pay ${o.checkoutUrl} --plan ${o.planId} --no-open` : ''}`, { planId: o.planId, checkoutUrl: o.checkoutUrl });
|
|
342
455
|
}
|
package/dist/flow.js
CHANGED
|
@@ -116,7 +116,7 @@ export async function confirmQuote(req) {
|
|
|
116
116
|
return { kind: 'agreed', how: 'yes-flag', confirmOperation: q.confirmOperation, confirmArguments: withPayment(q.confirmArguments, paymentFromFlag(q, flags.card)), amountCents: amount, quoteId: null, quote: q };
|
|
117
117
|
}
|
|
118
118
|
if (!interactive())
|
|
119
|
-
throw new Exit(EXIT.agreementRequired, `There is no terminal to agree in, so nothing was started. Run ${again},
|
|
119
|
+
throw new Exit(EXIT.agreementRequired, `There is no terminal to agree in, so nothing was started. Run ${again}, agree to the quote it prints, then run it with --confirm <quoteId>.`);
|
|
120
120
|
const payment = await askPayment(q, flags.card);
|
|
121
121
|
const agreed = await ask(req.question ?? 'Do you agree?', { default: false, short: 'Do you agree?' });
|
|
122
122
|
if (!agreed)
|
|
@@ -126,25 +126,42 @@ export async function confirmQuote(req) {
|
|
|
126
126
|
export async function planById(key, planId) {
|
|
127
127
|
return (await getPlans(key)).plans.find((p) => p.id === planId);
|
|
128
128
|
}
|
|
129
|
+
/** How often a payment is asked about, and how long a payment that has
|
|
130
|
+
* landed waits for its scan to show before the terminal says so anyway. The
|
|
131
|
+
* terminal waited for the scan, not the payment, and noticed a paid Checkout
|
|
132
|
+
* about a minute late (Varsha's test, R3). */
|
|
133
|
+
export const PAYMENT_POLL = { intervalMs: 2000, scanGraceMs: 15_000 };
|
|
129
134
|
export async function waitForPayment(key, planId, start, opts = {}) {
|
|
130
135
|
let last = start;
|
|
131
136
|
let state = { kind: 'waiting' };
|
|
132
137
|
let cancelledSeen = 0;
|
|
133
|
-
|
|
138
|
+
let paidAt = null;
|
|
139
|
+
const m = opts.message ?? 'Waiting for the payment to complete in your browser (Enter to stop waiting)';
|
|
140
|
+
const waiting = typeof m === 'function' ? m : () => m;
|
|
141
|
+
const result = await waitFor(() => (paidAt ? 'Payment received. Waiting for the scan to start (Enter to stop waiting)' : waiting()), async () => {
|
|
134
142
|
last = await planById(key, planId);
|
|
135
143
|
state = paymentState(start, last);
|
|
136
144
|
if (state.kind === 'cancelled')
|
|
137
145
|
return ++cancelledSeen >= 2;
|
|
138
146
|
cancelledSeen = 0;
|
|
147
|
+
if (state.kind === 'paid') {
|
|
148
|
+
paidAt ??= Date.now();
|
|
149
|
+
return Date.now() - paidAt >= PAYMENT_POLL.scanGraceMs;
|
|
150
|
+
}
|
|
139
151
|
return state.kind === 'started';
|
|
140
|
-
}, { ...(opts.timeoutMs ? { timeoutMs: opts.timeoutMs } : {}),
|
|
152
|
+
}, { ...(opts.timeoutMs ? { timeoutMs: opts.timeoutMs } : {}), intervalMs: opts.intervalMs ?? PAYMENT_POLL.intervalMs });
|
|
141
153
|
return { result, state: state, plan: last };
|
|
142
154
|
}
|
|
155
|
+
/** A Checkout link is long, and wrapped by the terminal it ran back to the
|
|
156
|
+
* left edge (Varsha's test, R3). Opened, it is not printed; otherwise it
|
|
157
|
+
* gets a line of its own, never broken. */
|
|
143
158
|
const sayCheckout = (opened, url) => {
|
|
144
159
|
if (opened.opened)
|
|
145
|
-
say(`${tick} Opened Stripe Checkout in your browser
|
|
146
|
-
else
|
|
147
|
-
say(`${dot} Open this link in a browser to pay
|
|
160
|
+
say(`${tick} Opened Stripe Checkout in your browser.`);
|
|
161
|
+
else {
|
|
162
|
+
say(`${dot} Open this link in a browser to pay:`);
|
|
163
|
+
say(` ${url.href}`);
|
|
164
|
+
}
|
|
148
165
|
};
|
|
149
166
|
export async function startWithPayment(key, op, args, opts = {}) {
|
|
150
167
|
let reply;
|
|
@@ -204,7 +221,9 @@ export const scanFinished = (status) => !!status && SCAN_TERMINAL.has(status);
|
|
|
204
221
|
export async function watchScan(key, scanId, opts = {}) {
|
|
205
222
|
let detail = null;
|
|
206
223
|
let seen = null;
|
|
207
|
-
|
|
224
|
+
// The state is part of the one spinner line, updated in place.
|
|
225
|
+
const message = opts.message ?? (() => `Scan ${scanId} is ${seen?.replace(/_/g, ' ') ?? 'starting'} (Enter stops watching; the scan carries on)`);
|
|
226
|
+
const result = await waitFor(message, async () => {
|
|
208
227
|
detail = (await tools.getScan(key, { scanId })).data;
|
|
209
228
|
const status = String(detail.scan?.status ?? '');
|
|
210
229
|
if (status && status !== seen) {
|
package/dist/payment.js
CHANGED
|
@@ -54,13 +54,13 @@ const day = (iso) => {
|
|
|
54
54
|
const d = new Date(iso);
|
|
55
55
|
return Number.isNaN(d.getTime()) ? iso : d.toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric', timeZone: 'UTC' });
|
|
56
56
|
};
|
|
57
|
-
/** One line per active plan: "owner/repo · Weekly · on demand".
|
|
57
|
+
/** One line per active monthly plan: "owner/repo · Weekly · on demand".
|
|
58
|
+
* A one-time scan's row is active too, but it is not a plan. */
|
|
58
59
|
export function planLines(plans) {
|
|
59
|
-
return plans.filter((p) => p.status === 'active').map((p) => {
|
|
60
|
+
return plans.filter((p) => p.status === 'active' && monthlyName(p)).map((p) => {
|
|
60
61
|
const repo = p.owner && p.name ? `${p.owner}/${p.name}` : p.id;
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
if (monthly && p.schedule?.description)
|
|
62
|
+
const parts = [repo, monthlyName(p)];
|
|
63
|
+
if (p.schedule?.description)
|
|
64
64
|
parts.push(p.schedule.description);
|
|
65
65
|
if (p.canceledAt)
|
|
66
66
|
parts.push(p.currentPeriodEnd ? `cancelled, ends ${day(p.currentPeriodEnd)}` : 'cancelled');
|
package/dist/steps.js
CHANGED
|
@@ -251,7 +251,8 @@ export async function ensureApp(s, flags = {}) {
|
|
|
251
251
|
? 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.`
|
|
252
252
|
: `${dot} Sekura GitHub App not installed yet, so there is nothing to scan.`);
|
|
253
253
|
if (!interactive) {
|
|
254
|
-
say(
|
|
254
|
+
say(' Install it and choose repositories at:');
|
|
255
|
+
say(` ${url}`);
|
|
255
256
|
if (flags.soft || covered())
|
|
256
257
|
return { installed: repos.length > 0, found: covered(), repositories: repos, link: url, accounts: accountsOf(list) };
|
|
257
258
|
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 });
|
|
@@ -267,8 +268,16 @@ export async function ensureApp(s, flags = {}) {
|
|
|
267
268
|
if (!go)
|
|
268
269
|
return { installed: repos.length > 0, found: false, repositories: repos, link: url, accounts: accountsOf(list) };
|
|
269
270
|
}
|
|
271
|
+
// The install link carries a long state token: printed after "Opened" it
|
|
272
|
+
// wrapped back to the left edge and was no use to anyone (Varsha's test,
|
|
273
|
+
// F8). Opened, it is not printed; otherwise it gets a line of its own.
|
|
270
274
|
const opened = openLink(url, { browser: flags.browser });
|
|
271
|
-
|
|
275
|
+
if (opened.opened)
|
|
276
|
+
say(` Opened ${onGithub ? 'github.com' : HOST} in your browser.`);
|
|
277
|
+
else {
|
|
278
|
+
say(' Open this link to install it:');
|
|
279
|
+
say(` ${url}`);
|
|
280
|
+
}
|
|
272
281
|
const before = new Set(repos.map((r) => r.fullName.toLowerCase()));
|
|
273
282
|
const r = await waitFor('Waiting for the GitHub App install… press Enter to skip', async () => {
|
|
274
283
|
list = await listRepositories(s.key, { refresh: true });
|
package/dist/ui.js
CHANGED
|
@@ -49,14 +49,32 @@ export function wrapLine(line, cols) {
|
|
|
49
49
|
out.push(cur);
|
|
50
50
|
return out;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* The server every printed command must reach. A command printed while the
|
|
54
|
+
* CLI talks to dev.sekura.ai read "npx sekura@latest scan owner/repo", and
|
|
55
|
+
* copied as printed it ran against production (Varsha's test, 30 November
|
|
56
|
+
* 2026, R1 and R3). catalogue.ts sets this once it knows the address; every
|
|
57
|
+
* line that goes through say() or print() then carries the flag. The flag
|
|
58
|
+
* goes straight after the package name, so it reaches every subcommand and
|
|
59
|
+
* is never cut off by the sentence around it; the flag, not
|
|
60
|
+
* SEKURA_ENDPOINT=…, because PowerShell rejects that form.
|
|
61
|
+
*/
|
|
62
|
+
let commandOrigin = null;
|
|
63
|
+
export const setCommandOrigin = (origin) => { commandOrigin = origin; };
|
|
64
|
+
export const withEndpoint = (s) => commandOrigin ? s.replace(/npx sekura@latest(?! --endpoint)/g, `npx sekura@latest --endpoint ${commandOrigin}`) : s;
|
|
65
|
+
/** True while a spinner line is on screen: a line said then clears it first,
|
|
66
|
+
* or the spinner's text and the new line ran together. */
|
|
67
|
+
let spinning = false;
|
|
52
68
|
export const say = (s = '') => {
|
|
53
69
|
const cols = process.stderr.isTTY ? process.stderr.columns || 0 : 0;
|
|
54
|
-
const
|
|
55
|
-
|
|
70
|
+
const text = withEndpoint(s);
|
|
71
|
+
const lines = cols >= 40 ? text.split('\n').flatMap((l) => wrapLine(l, cols - 1)) : [text];
|
|
72
|
+
process.stderr.write(`${spinning ? '\r\x1b[2K' : ''}${lines.join('\n')}\n`);
|
|
56
73
|
};
|
|
57
74
|
export const print = (s = '') => {
|
|
58
75
|
const cols = process.stdout.isTTY ? process.stdout.columns || 0 : 0;
|
|
59
|
-
const
|
|
76
|
+
const text = withEndpoint(s);
|
|
77
|
+
const lines = cols >= 40 ? text.split('\n').flatMap((l) => wrapLine(l, cols - 1)) : [text];
|
|
60
78
|
process.stdout.write(lines.join('\n') + '\n');
|
|
61
79
|
};
|
|
62
80
|
/** A spinner line redraws in place with \r, so it must never wrap: cut to the width. */
|
|
@@ -116,12 +134,14 @@ export function spinner(message) {
|
|
|
116
134
|
let f = 0;
|
|
117
135
|
const draw = () => { process.stderr.write(`\r${fitLine(` ${FRAMES[f++ % FRAMES.length]} ${message}`)}`); };
|
|
118
136
|
draw();
|
|
137
|
+
spinning = true;
|
|
119
138
|
const timer = setInterval(draw, 120);
|
|
120
139
|
let stopped = false;
|
|
121
140
|
return () => {
|
|
122
141
|
if (stopped)
|
|
123
142
|
return;
|
|
124
143
|
stopped = true;
|
|
144
|
+
spinning = false;
|
|
125
145
|
clearInterval(timer);
|
|
126
146
|
process.stderr.write('\r\x1b[2K');
|
|
127
147
|
};
|
|
@@ -133,6 +153,10 @@ export function spinner(message) {
|
|
|
133
153
|
* by itself when they have finished.
|
|
134
154
|
*/
|
|
135
155
|
export async function waitFor(message, check, opts = {}) {
|
|
156
|
+
// A message that is a function is read at every frame, so what it says
|
|
157
|
+
// (a scan's state) changes in place on the one line (Varsha's test, F10:
|
|
158
|
+
// each new state printed a new line under the spinner's).
|
|
159
|
+
const text = typeof message === 'function' ? message : () => message;
|
|
136
160
|
const interval = opts.intervalMs ?? WAIT.intervalMs;
|
|
137
161
|
const deadline = Date.now() + (opts.timeoutMs ?? WAIT.timeoutMs);
|
|
138
162
|
const tty = !!process.stderr.isTTY;
|
|
@@ -148,12 +172,14 @@ export async function waitFor(message, check, opts = {}) {
|
|
|
148
172
|
process.stdin.resume();
|
|
149
173
|
}
|
|
150
174
|
let f = 0;
|
|
151
|
-
const draw = () => { process.stderr.write(`\r${fitLine(` ${FRAMES[f++ % FRAMES.length]} ${
|
|
175
|
+
const draw = () => { process.stderr.write(`\r\x1b[2K${fitLine(` ${FRAMES[f++ % FRAMES.length]} ${text()}`)}`); };
|
|
152
176
|
const spin = tty ? setInterval(draw, 120) : null;
|
|
153
|
-
if (tty)
|
|
177
|
+
if (tty) {
|
|
154
178
|
draw();
|
|
179
|
+
spinning = true;
|
|
180
|
+
}
|
|
155
181
|
else
|
|
156
|
-
say(` ${
|
|
182
|
+
say(` ${text()}`);
|
|
157
183
|
const pause = (ms) => new Promise((r) => { const t = setTimeout(r, ms); wake = () => { clearTimeout(t); r(); }; });
|
|
158
184
|
try {
|
|
159
185
|
for (;;) {
|
|
@@ -175,6 +201,7 @@ export async function waitFor(message, check, opts = {}) {
|
|
|
175
201
|
finally {
|
|
176
202
|
if (spin)
|
|
177
203
|
clearInterval(spin);
|
|
204
|
+
spinning = false;
|
|
178
205
|
if (tty)
|
|
179
206
|
process.stderr.write('\r\x1b[2K');
|
|
180
207
|
if (enter) {
|
package/dist/writers.js
CHANGED
|
@@ -323,10 +323,35 @@ export function signedInByTool(t) {
|
|
|
323
323
|
const l = listed(t);
|
|
324
324
|
return !!l && l.lines.some((x) => (x.match(URLS) ?? []).some(isOurs) && /\bOAuth\b/.test(x) && !/\bnot\b/i.test(x));
|
|
325
325
|
}
|
|
326
|
+
/** Whether one of a tool's own JSON files has our entry at our address
|
|
327
|
+
* (mcpServers.sekura). Its list is not asked: it shows servers the tool
|
|
328
|
+
* imports from other tools' files too. A file that cannot be read as JSON
|
|
329
|
+
* leaves it unknown. */
|
|
330
|
+
function ownHas(paths) {
|
|
331
|
+
let unknown = false;
|
|
332
|
+
for (const path of paths) {
|
|
333
|
+
if (!existsSync(path))
|
|
334
|
+
continue;
|
|
335
|
+
let data;
|
|
336
|
+
try {
|
|
337
|
+
data = JSON.parse(readFileSync(path, 'utf8'));
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
unknown = true;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
const entry = data?.mcpServers?.[SERVER_NAME];
|
|
344
|
+
if (entry && (JSON.stringify(entry).match(URLS) ?? []).some(isOurs))
|
|
345
|
+
return true;
|
|
346
|
+
}
|
|
347
|
+
return unknown ? 'unknown' : false;
|
|
348
|
+
}
|
|
326
349
|
/** Whether the tool's own command lists our entry at our address, and with
|
|
327
350
|
* our key when the entry carries one. A tool that does not print its
|
|
328
351
|
* headers reads as not having it, and the entry is written again. */
|
|
329
352
|
function commandHas(t) {
|
|
353
|
+
if (t.own)
|
|
354
|
+
return ownHas(t.own);
|
|
330
355
|
if (!t.get)
|
|
331
356
|
return listHas(t);
|
|
332
357
|
const r = spawn(t.bin, t.get, ASK_MS);
|
package/package.json
CHANGED
package/skills/sekura/SKILL.md
CHANGED
|
@@ -46,11 +46,15 @@ the first word:
|
|
|
46
46
|
- On demand: `onDemand` true, keeping the plan's own `kind`, with `minute` and
|
|
47
47
|
`tz`. Nothing runs until the user asks; `quoteRunNow` then `runNow` starts each scan.
|
|
48
48
|
- `change <owner/repo>`: move the repository to the other monthly plan, up to More
|
|
49
|
-
frequently (`tier` `pro`) or down to Weekly (`tier` `always`)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
frequently (`tier` `pro`) or down to Weekly (`tier` `always`), or change its
|
|
50
|
+
schedule. Never assume the direction from the plan it is on: unless the user
|
|
51
|
+
named the plan, first ask which plan they want, Weekly or More frequently, then ask
|
|
52
|
+
the schedule on that plan and its time zone. If they pick the plan the repository
|
|
53
|
+
is already on, it is a schedule change only: `quoteSchedule`, then the two-step
|
|
54
|
+
rule (`updateSchedule`), never `quotePlanChange`. Otherwise `quotePlanChange` and
|
|
55
|
+
the two-step rule (`changePlan`). Say the money as the quote does: an upgrade
|
|
56
|
+
charges the whole difference between the two monthly prices now; a downgrade
|
|
57
|
+
charges nothing. The renewal date does not change.
|
|
54
58
|
- `schedule <owner/repo>`: `quoteSchedule` for that repository with the schedule
|
|
55
59
|
the user gives (ask for one if they gave none), then the two-step rule.
|
|
56
60
|
- `plans`: `getPlans`. `billing`: `getBilling`.
|
|
@@ -106,7 +110,7 @@ Quote, then confirm. The quote changes nothing and charges nothing:
|
|
|
106
110
|
- `quoteScan` → `startScan`: a one-time scan of one repository.
|
|
107
111
|
- `quoteAlways` → `startAlways`: a monthly plan (Weekly or More frequently) for one repository.
|
|
108
112
|
- `quoteSchedule` → `updateSchedule`: change when a repository on a monthly plan is scanned. It charges nothing.
|
|
109
|
-
- `quotePlanChange` → `changePlan`: move a repository between Weekly and More frequently. Moving up charges the difference
|
|
113
|
+
- `quotePlanChange` → `changePlan`: move a repository between Weekly and More frequently. Moving up charges the whole difference between the two monthly prices now and keeps the renewal date; moving down charges nothing and refunds nothing, and the lower price applies from the renewal.
|
|
110
114
|
- `quoteRunNow` → `runNow`: run a monthly plan's next scan now: brought forward on a schedule, started on demand. It is one of the plan's own runs, so there is no charge. Over the plan's limit it is refused with the first day a scan may start; tell the user that day.
|
|
111
115
|
|
|
112
116
|
Preview, then act. The preview cancels nothing:
|