sekura 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/api.js +2 -0
- package/dist/catalogue.js +1 -1
- package/dist/cli.js +5 -1
- package/dist/commands/billing.js +60 -0
- package/dist/commands/pay.js +84 -0
- package/dist/payment.js +37 -0
- package/package.json +2 -2
- package/skills/sekura/SKILL.md +44 -8
package/README.md
CHANGED
|
@@ -28,6 +28,16 @@ Sekura is an AI red team as a service: it scans a GitHub repository you have gra
|
|
|
28
28
|
|
|
29
29
|
Every scan you then ask for in your coding tool is quoted first, with the price and the authorization wording, and starts only after you agree.
|
|
30
30
|
|
|
31
|
+
## Paying from your coding tool
|
|
32
|
+
|
|
33
|
+
The quote lists how you can pay:
|
|
34
|
+
|
|
35
|
+
- **A saved card**, shown only by brand and last four (`Visa •••• •••• •••• 4242`). Pick one and it is charged right there, with no browser: `Charged $199 to Visa ending 4242`, then the scan id and link.
|
|
36
|
+
- **Pay with a Checkout link.** The agent runs `npx sekura@latest pay "<link>" --plan <id>`, which opens Stripe Checkout in your default browser and waits. When the payment lands, the same session shows the scan id and link. Your first payment is always made this way, and the card you use is saved for next time.
|
|
37
|
+
- **Change payment method.** The agent runs `npx sekura@latest billing --open`, which opens the page where you add or change a card, then shows the updated list.
|
|
38
|
+
|
|
39
|
+
Nothing is charged without a quote and your yes, and only the card you pick is charged.
|
|
40
|
+
|
|
31
41
|
## Flags
|
|
32
42
|
|
|
33
43
|
| Flag | What it does |
|
|
@@ -53,9 +63,12 @@ npx sekura@latest init --no-login # no sign-in here; each tool signs in on
|
|
|
53
63
|
npx sekura@latest init --device # sign in with a code, for a terminal on another machine
|
|
54
64
|
npx sekura@latest login # sign in again, give connected tools the key, pick a repository
|
|
55
65
|
npx sekura@latest status # what is connected, and who is signed in
|
|
66
|
+
npx sekura@latest billing # your saved cards, masked; --open to change them
|
|
67
|
+
npx sekura@latest pay "<checkout link>" --plan <id> # open Checkout and wait for the payment
|
|
56
68
|
npx sekura@latest logout # forget the saved key
|
|
57
69
|
npx sekura@latest uninstall # remove the entries, the skill, the guidance block and the saved key
|
|
58
70
|
SEKURA_API_KEY=sek_live_… npx sekura@latest init --yes # unattended, with a key from Settings
|
|
71
|
+
SEKURA_ENDPOINT=https://dev.sekura.ai/mcp npx sekura@latest billing # against another Sekura server, for testing
|
|
59
72
|
```
|
|
60
73
|
|
|
61
74
|
## What it writes
|
package/dist/api.js
CHANGED
|
@@ -39,4 +39,6 @@ export async function callTool(key, name, args = {}) {
|
|
|
39
39
|
throw new Error(`Sekura ${name}: no data in the answer`);
|
|
40
40
|
}
|
|
41
41
|
export const getAccount = (key) => callTool(key, 'getAccount');
|
|
42
|
+
export const getPlans = (key) => callTool(key, 'getPlans');
|
|
43
|
+
export const getBilling = (key) => callTool(key, 'getBilling');
|
|
42
44
|
export const listRepositories = (key) => callTool(key, 'listRepositories');
|
package/dist/catalogue.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { existsSync, readdirSync } from 'node:fs';
|
|
13
13
|
import { homedir, platform } from 'node:os';
|
|
14
14
|
import { join, delimiter } from 'node:path';
|
|
15
|
-
export const ENDPOINT = 'https://sekura.ai/mcp';
|
|
15
|
+
export const ENDPOINT = process.env.SEKURA_ENDPOINT?.trim() || 'https://sekura.ai/mcp';
|
|
16
16
|
export const SERVER_NAME = 'sekura';
|
|
17
17
|
export const DOCS = 'https://sekura.ai/connect/';
|
|
18
18
|
/** The home directory, overridable for tests. */
|
package/dist/cli.js
CHANGED
|
@@ -16,6 +16,8 @@ import { initCommand } from './commands/init.js';
|
|
|
16
16
|
import { statusCommand } from './commands/status.js';
|
|
17
17
|
import { uninstallCommand } from './commands/uninstall.js';
|
|
18
18
|
import { loginCommand, logoutCommand } from './commands/login.js';
|
|
19
|
+
import { payCommand } from './commands/pay.js';
|
|
20
|
+
import { billingCommand } from './commands/billing.js';
|
|
19
21
|
import { DOCS } from './catalogue.js';
|
|
20
22
|
const { version } = createRequire(import.meta.url)('../package.json');
|
|
21
23
|
const program = new Command();
|
|
@@ -27,7 +29,9 @@ program
|
|
|
27
29
|
.addCommand(loginCommand)
|
|
28
30
|
.addCommand(statusCommand)
|
|
29
31
|
.addCommand(uninstallCommand)
|
|
30
|
-
.addCommand(logoutCommand)
|
|
32
|
+
.addCommand(logoutCommand)
|
|
33
|
+
.addCommand(payCommand)
|
|
34
|
+
.addCommand(billingCommand);
|
|
31
35
|
try {
|
|
32
36
|
await program.parseAsync(process.argv);
|
|
33
37
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { openBrowser, readKey } from '../auth.js';
|
|
3
|
+
import { getBilling, SignedOut } from '../api.js';
|
|
4
|
+
import { cardLines, cardsFingerprint, paymentMethodsLink } from '../payment.js';
|
|
5
|
+
import { cross, dot, say, tick, waitFor } from '../ui.js';
|
|
6
|
+
function sayCards(b, heading) {
|
|
7
|
+
const lines = cardLines(b);
|
|
8
|
+
if (!lines.length) {
|
|
9
|
+
say(`${dot} No saved card. Your first payment on a Stripe Checkout page saves the card you use there.`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
say(`${tick} ${heading}`);
|
|
13
|
+
for (const l of lines)
|
|
14
|
+
say(` ${l}`);
|
|
15
|
+
}
|
|
16
|
+
export async function runBilling(opts = {}) {
|
|
17
|
+
const key = readKey();
|
|
18
|
+
if (!key) {
|
|
19
|
+
say(`${cross} Not signed in here: run npx sekura@latest login first.`);
|
|
20
|
+
return 4;
|
|
21
|
+
}
|
|
22
|
+
let before;
|
|
23
|
+
try {
|
|
24
|
+
before = await getBilling(key);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
say(`${cross} ${e instanceof SignedOut ? `Your Sekura key no longer works (${e.message}); run npx sekura@latest login.` : `Sekura could not be asked: ${e.message}`}`);
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
if (!opts.open) {
|
|
31
|
+
sayCards(before, 'Saved cards:');
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
const link = paymentMethodsLink();
|
|
35
|
+
const opened = opts.browser === false ? false : openBrowser(link);
|
|
36
|
+
say(opened ? `${tick} Opened your payment methods in the browser: ${link}` : `${dot} Open this link in a browser to add or change a card: ${link}`);
|
|
37
|
+
const was = cardsFingerprint(before);
|
|
38
|
+
let now = before;
|
|
39
|
+
const minutes = Number(opts.timeout);
|
|
40
|
+
const result = await waitFor('Waiting for your cards to change (Enter when you are done)', async () => {
|
|
41
|
+
now = await getBilling(key);
|
|
42
|
+
return cardsFingerprint(now) !== was;
|
|
43
|
+
}, { timeoutMs: (Number.isFinite(minutes) && minutes > 0 ? Math.min(minutes, 60) : 5) * 60_000, ...(opts.intervalMs ? { intervalMs: opts.intervalMs } : {}) });
|
|
44
|
+
if (result !== 'done') {
|
|
45
|
+
try {
|
|
46
|
+
now = await getBilling(key);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
now = before;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
sayCards(now, cardsFingerprint(now) !== was ? 'Your cards now:' : 'No change seen. Saved cards:');
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
export const billingCommand = new Command('billing')
|
|
56
|
+
.description('Show your saved cards, masked; with --open, change them in the browser and show the new list.')
|
|
57
|
+
.option('--open', 'open the page where cards are added or changed, then wait for the change')
|
|
58
|
+
.option('--timeout <minutes>', 'how long to wait with --open', '5')
|
|
59
|
+
.option('--no-browser', 'print the link instead of opening it')
|
|
60
|
+
.action(async (opts) => { process.exitCode = await runBilling(opts); });
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { openBrowser, readKey } from '../auth.js';
|
|
3
|
+
import { getPlans, SignedOut } from '../api.js';
|
|
4
|
+
import { openableLink, paymentState, scanLink } from '../payment.js';
|
|
5
|
+
import { cross, dot, say, tick, waitFor } from '../ui.js';
|
|
6
|
+
export const PAY_EXIT = { started: 0, paid: 0, notSignedIn: 4, cancelled: 3, timeout: 2, badLink: 1 };
|
|
7
|
+
const planName = (p) => (p?.owner && p?.name ? `${p.owner}/${p.name}` : 'the repository');
|
|
8
|
+
const minutes = (raw, fallback) => {
|
|
9
|
+
const n = Number(raw);
|
|
10
|
+
return Number.isFinite(n) && n > 0 ? Math.min(n, 60) : fallback;
|
|
11
|
+
};
|
|
12
|
+
async function planById(key, planId) {
|
|
13
|
+
return (await getPlans(key)).plans.find((p) => p.id === planId);
|
|
14
|
+
}
|
|
15
|
+
function sayOpened(link, opened) {
|
|
16
|
+
if (opened)
|
|
17
|
+
say(`${tick} Opened Stripe Checkout in your browser: ${link.href}`);
|
|
18
|
+
else
|
|
19
|
+
say(`${dot} Open this link in a browser to pay: ${link.href}`);
|
|
20
|
+
}
|
|
21
|
+
function sayOutcome(state, plan) {
|
|
22
|
+
const repo = planName(plan);
|
|
23
|
+
if (state.kind === 'started') {
|
|
24
|
+
const what = plan?.plan === 'always' ? `Sekura Always is on for ${repo}, and its first scan` : `The scan of ${repo}`;
|
|
25
|
+
say(`${tick} Payment received. ${what} has started: scan id ${state.scanId} (${state.scanStatus}).`);
|
|
26
|
+
say(` ${scanLink(state.scanId)}`);
|
|
27
|
+
}
|
|
28
|
+
else if (state.kind === 'paid') {
|
|
29
|
+
say(`${tick} Payment received for ${repo}. The scan starts within a few minutes; ask your coding tool for listScans or getScan to follow it.`);
|
|
30
|
+
}
|
|
31
|
+
else if (state.kind === 'cancelled') {
|
|
32
|
+
say(`${cross} Checkout was closed without paying, so nothing was charged and ${repo} is back to how it was.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function runPay(link, opts = {}) {
|
|
36
|
+
const url = openableLink(link);
|
|
37
|
+
if (!url) {
|
|
38
|
+
say(`${cross} Not a Stripe Checkout or Sekura link, so it was not opened: ${link}`);
|
|
39
|
+
return PAY_EXIT.badLink;
|
|
40
|
+
}
|
|
41
|
+
const opened = opts.open === false ? false : openBrowser(url.href);
|
|
42
|
+
sayOpened(url, opened);
|
|
43
|
+
const key = readKey();
|
|
44
|
+
if (!opts.plan || !key) {
|
|
45
|
+
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, ask your coding tool for getPlans.`);
|
|
46
|
+
return PAY_EXIT.notSignedIn;
|
|
47
|
+
}
|
|
48
|
+
const planId = opts.plan;
|
|
49
|
+
let start;
|
|
50
|
+
try {
|
|
51
|
+
start = await planById(key, planId);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
if (e instanceof SignedOut) {
|
|
55
|
+
say(`${cross} Your Sekura key no longer works (${e.message}); run npx sekura@latest login.`);
|
|
56
|
+
return PAY_EXIT.notSignedIn;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
let last = start;
|
|
60
|
+
let state = { kind: 'waiting' };
|
|
61
|
+
let cancelledSeen = 0;
|
|
62
|
+
const result = await waitFor('Waiting for the payment to complete in your browser (Enter to stop waiting)', async () => {
|
|
63
|
+
last = await planById(key, planId);
|
|
64
|
+
state = paymentState(start, last);
|
|
65
|
+
if (state.kind === 'cancelled')
|
|
66
|
+
return ++cancelledSeen >= 2;
|
|
67
|
+
cancelledSeen = 0;
|
|
68
|
+
return state.kind === 'started';
|
|
69
|
+
}, { timeoutMs: minutes(opts.timeout, 9) * 60_000, ...(opts.intervalMs ? { intervalMs: opts.intervalMs } : {}) });
|
|
70
|
+
const final = state;
|
|
71
|
+
if (result === 'done' || final.kind === 'paid') {
|
|
72
|
+
sayOutcome(final, last);
|
|
73
|
+
return final.kind === 'cancelled' ? PAY_EXIT.cancelled : PAY_EXIT.started;
|
|
74
|
+
}
|
|
75
|
+
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. Ask your coding tool for getPlans to check.`);
|
|
76
|
+
return PAY_EXIT.timeout;
|
|
77
|
+
}
|
|
78
|
+
export const payCommand = new Command('pay')
|
|
79
|
+
.description('Open a Stripe Checkout link from a Sekura quote in your browser and wait until the payment lands.')
|
|
80
|
+
.argument('<checkout-link>', 'the Checkout link Sekura answered with')
|
|
81
|
+
.option('--plan <id>', 'the plan id from the same answer, to wait on')
|
|
82
|
+
.option('--timeout <minutes>', 'how long to wait', '9')
|
|
83
|
+
.option('--no-open', 'print the link instead of opening it')
|
|
84
|
+
.action(async (link, opts) => { process.exitCode = await runPay(link, opts); });
|
package/dist/payment.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ENDPOINT } from './catalogue.js';
|
|
2
|
+
export const SEKURA_ORIGIN = new URL(ENDPOINT).origin;
|
|
3
|
+
const OPENABLE_HOSTS = new Set(['checkout.stripe.com', 'billing.stripe.com', new URL(ENDPOINT).host]);
|
|
4
|
+
export function openableLink(raw) {
|
|
5
|
+
let url;
|
|
6
|
+
try {
|
|
7
|
+
url = new URL(raw);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const local = url.hostname === '127.0.0.1' || url.hostname === 'localhost';
|
|
13
|
+
if (url.protocol !== 'https:' && !(local && url.protocol === 'http:'))
|
|
14
|
+
return null;
|
|
15
|
+
return OPENABLE_HOSTS.has(url.host) ? url : null;
|
|
16
|
+
}
|
|
17
|
+
export const paymentMethodsLink = () => `${SEKURA_ORIGIN}/app/payment-methods`;
|
|
18
|
+
export const scanLink = (scanId) => `${SEKURA_ORIGIN}/app/scans/${encodeURIComponent(scanId.startsWith('ss-') ? scanId : `ss-${scanId}`)}`;
|
|
19
|
+
const newScanOf = (start, now) => now.lastScan && now.lastScan.id !== start?.lastScan?.id ? now.lastScan : null;
|
|
20
|
+
export function paymentState(start, now) {
|
|
21
|
+
if (!now)
|
|
22
|
+
return start ? { kind: 'cancelled' } : { kind: 'waiting' };
|
|
23
|
+
if (now.status === 'active') {
|
|
24
|
+
const scan = newScanOf(start, now);
|
|
25
|
+
if (scan)
|
|
26
|
+
return { kind: 'started', scanId: scan.id, scanStatus: scan.status };
|
|
27
|
+
const backAsItWas = start?.status === 'pending' && (start.pendingFrom === 'rerun' || start.pendingFrom === 'upgrade') && !now.nextRunAt && !now.pendingFrom;
|
|
28
|
+
return backAsItWas && start.plan === now.plan ? { kind: 'cancelled' } : { kind: 'paid' };
|
|
29
|
+
}
|
|
30
|
+
if (now.status === 'pending' && start?.selected && !now.selected)
|
|
31
|
+
return { kind: 'cancelled' };
|
|
32
|
+
if (now.status === 'canceled')
|
|
33
|
+
return { kind: 'cancelled' };
|
|
34
|
+
return { kind: 'waiting' };
|
|
35
|
+
}
|
|
36
|
+
export const cardLines = (b) => (b.cards ?? []).map((c) => `${c.masked}${c.isDefault ? ' (default)' : ''}`);
|
|
37
|
+
export const cardsFingerprint = (b) => (b.cards ?? []).map((c) => `${c.masked}:${c.isDefault ? 1 : 0}`).join('|');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sekura",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Connect your coding tool to Sekura in one command: npx sekura@latest init",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsc -p tsconfig.json && node -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
|
|
40
|
-
"test": "npm run build && node --test test/init.test.mjs test/login.test.mjs test/guide.test.mjs test/device.test.mjs test/skill.test.mjs",
|
|
40
|
+
"test": "npm run build && node --test test/init.test.mjs test/login.test.mjs test/guide.test.mjs test/device.test.mjs test/skill.test.mjs test/pay.test.mjs",
|
|
41
41
|
"prepack": "npm run build"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
package/skills/sekura/SKILL.md
CHANGED
|
@@ -68,6 +68,7 @@ only after you say yes. Cancelling is shown first too.
|
|
|
68
68
|
Setup, in a terminal:
|
|
69
69
|
npx sekura@latest login sign in again, or pick another repository
|
|
70
70
|
npx sekura@latest status what is connected on this machine
|
|
71
|
+
npx sekura@latest billing your saved cards (--open to change them)
|
|
71
72
|
|
|
72
73
|
Add repositories: https://sekura.ai/app (the Sekura GitHub App)
|
|
73
74
|
Documentation: https://sekura.ai/connect/
|
|
@@ -112,11 +113,10 @@ A scan or a plan is never started in one call.
|
|
|
112
113
|
authorization wording, and ask whether they agree. Start nothing until they
|
|
113
114
|
have said yes in the conversation.
|
|
114
115
|
3. Then call `startScan` or `startAlways` with `confirmArguments` exactly as the
|
|
115
|
-
quote returned them, plus the `payment` the user chose
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
has said yes. A confirm without the `disclosureVersion` is refused.
|
|
116
|
+
quote returned them, plus the `payment` for the way the user chose to pay (see
|
|
117
|
+
Paying, below). Never invent a `disclosureVersion` or an `amountCents`, never
|
|
118
|
+
reuse one from an older quote, and never call a confirm before the user has
|
|
119
|
+
said yes. A confirm without the `disclosureVersion` is refused.
|
|
120
120
|
|
|
121
121
|
If the confirm is refused because the wording or the price changed, the answer
|
|
122
122
|
carries a fresh quote: show that one to the user and ask again.
|
|
@@ -129,9 +129,45 @@ they agree.
|
|
|
129
129
|
`updateSchedule` and `runNow` take one call each and charge nothing; call them
|
|
130
130
|
only when the user has asked for that change.
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
## Paying
|
|
133
|
+
|
|
134
|
+
The quote's `paymentOptions` are the only ways to pay. Show them to the user as a
|
|
135
|
+
numbered list, each by its `label`, in the quote's order, and ask which one they
|
|
136
|
+
want together with whether they agree:
|
|
137
|
+
|
|
138
|
+
- With saved cards: one line per card, masked as the quote gives it (for example
|
|
139
|
+
`Visa •••• •••• •••• 4242`), then `Pay with a Checkout link`, then
|
|
140
|
+
`Change payment method`. Never show more of a card than the quote does.
|
|
141
|
+
- With no saved card: only `Pay with a Checkout link`. The first payment is
|
|
142
|
+
always made in the browser, and the card used there is saved for next time.
|
|
143
|
+
|
|
144
|
+
Then:
|
|
145
|
+
|
|
146
|
+
- **A saved card**: call the confirm with that option's `payment`, which is
|
|
147
|
+
`{ "savedCard": { "card": "pm_…" } }` with the card the user picked. Only that
|
|
148
|
+
card is charged, in place, with no browser. Relay the answer: what was charged
|
|
149
|
+
to which card ("Charged $199 to Visa ending 4242"), the scan id and the link.
|
|
150
|
+
- **Pay with a Checkout link**: call the confirm with no `payment`. It answers 402
|
|
151
|
+
with `checkoutUrl` and `planId`. Run, in the terminal, with a timeout of ten
|
|
152
|
+
minutes:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
npx sekura@latest pay "<checkoutUrl>" --plan <planId>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
It opens the link in the user's browser (where they are signed in to Sekura)
|
|
159
|
+
and waits until the payment lands, then prints the scan id and link, or that
|
|
160
|
+
Checkout was closed unpaid. Tell the user the page is open and you are
|
|
161
|
+
waiting, then relay what it printed. If the command cannot run here, give the
|
|
162
|
+
user the link to open, and once they say they have paid, call `getPlans` and
|
|
163
|
+
report the plan and its scan.
|
|
164
|
+
- **Change payment method**: starts and charges nothing. Run
|
|
165
|
+
`npx sekura@latest billing --open`, which opens the page where the user adds
|
|
166
|
+
or changes a card and waits for the change. Then call the quote again and show
|
|
167
|
+
its updated list of cards, and ask again.
|
|
168
|
+
|
|
169
|
+
Nothing is charged without a quote and the user's yes, and only the card the user
|
|
170
|
+
picked is charged.
|
|
135
171
|
|
|
136
172
|
## What to tell the user
|
|
137
173
|
|