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