sekura 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/verify.js CHANGED
@@ -10,8 +10,12 @@ export async function verifyEndpoint(endpoint = ENDPOINT, timeoutMs = 8000) {
10
10
  try {
11
11
  const r = await fetch(endpoint, { method: 'GET', headers: { accept: 'application/json' }, signal: ctl.signal, redirect: 'manual' });
12
12
  const type = r.headers.get('content-type') || '';
13
+ // The check sends no key on purpose, so a 401 says only that the server is
14
+ // there. Worded as the 401 itself, it printed "as it should before you
15
+ // sign in" straight after "Signed in to Sekura" (29 November 2026), and
16
+ // read as the sign-in having failed. The key was proved by that sign-in.
13
17
  if (r.status === 401 && type.includes('json'))
14
- return { ok: true, detail: `${endpoint} answers 401 (sign-in required), as it should before you sign in` };
18
+ return { ok: true, detail: `${endpoint} is reachable` };
15
19
  if (r.status === 200)
16
20
  return { ok: true, detail: `${endpoint} answers 200` };
17
21
  return { ok: false, detail: `${endpoint} answered ${r.status} ${type || ''}`.trim() };
package/dist/writers.js CHANGED
@@ -236,8 +236,10 @@ export function hasYaml(t) {
236
236
  return 'entry' in at && !!at.entry && yamlOk(t, lines.slice(at.entry[0] + 1, at.entry[1]));
237
237
  }
238
238
  // ── commands ────────────────────────────────────────────────────────────────
239
- function spawn(bin, args) {
240
- return spawnSync(bin, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
239
+ /** A read-only question (get, list) is given a time limit: a tool that
240
+ * stopped to ask something on a closed stdin would hang `status` forever. */
241
+ function spawn(bin, args, timeout) {
242
+ return spawnSync(bin, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], ...(timeout ? { timeout } : {}) });
241
243
  }
242
244
  export function runCommand(bin, args) {
243
245
  const r = spawn(bin, args);
@@ -248,29 +250,93 @@ export function runCommand(bin, args) {
248
250
  return { status: 'failed', where, why: redactAll((r.stderr || r.stdout || `exit ${r.status}`).trim().split('\n').slice(-3).join(' ')) };
249
251
  return { status: 'ran', where };
250
252
  }
253
+ const ASK_MS = 15_000;
254
+ const URLS = /\bhttps?:\/\/[^\s"'<>()\[\],|]+/g;
255
+ const bare = (u) => u.replace(/[.,;:]+$/, '').replace(/\/$/, '');
256
+ const isOurs = (u) => bare(u) === bare(ENDPOINT);
257
+ /** The lines that name our entry. URLs are taken out first, so a line for
258
+ * another server at a sekura.ai address is not read as ours. */
259
+ const ourLines = (out) => out.split(/\r?\n/).filter((l) => new RegExp(`(^|[^\\w-])${SERVER_NAME}([^\\w-]|$)`, 'i').test(l.replace(URLS, ' ')));
260
+ /** What the tool's own list says, or null when it could not be asked: the
261
+ * binary is missing, it failed, or it printed its help instead (an older
262
+ * version without `mcp list`). */
263
+ function listed(t) {
264
+ if (!t.list)
265
+ return null;
266
+ const r = spawn(t.bin, t.list, ASK_MS);
267
+ if (r.error || r.status !== 0)
268
+ return null;
269
+ const out = `${r.stdout ?? ''}\n${r.stderr ?? ''}`;
270
+ const lines = ourLines(out);
271
+ if (!lines.length && /\b(usage|unknown command|unrecognized|invalid command)\b/i.test(out))
272
+ return null;
273
+ return { out, lines };
274
+ }
275
+ /** Whether the tool's list has our entry at our address. A line with our
276
+ * name and another address is an entry pointing elsewhere: not connected. */
277
+ function listHas(t) {
278
+ const l = listed(t);
279
+ if (!l)
280
+ return 'unknown';
281
+ if (!l.lines.length)
282
+ return false;
283
+ if (l.lines.some((x) => (x.match(URLS) ?? []).some(isOurs)))
284
+ return true;
285
+ if (l.lines.some((x) => (x.match(URLS) ?? []).length))
286
+ return false;
287
+ // A layout with the address on its own line (one field per line).
288
+ return (l.out.match(URLS) ?? []).some(isOurs) ? true : 'unknown';
289
+ }
290
+ /** Whether the tool's own list shows our entry signed in with OAuth (Codex
291
+ * prints an Auth column: "OAuth" once `codex mcp login` has run, "Not
292
+ * logged in" before). Every `mcp login` mints a new key on Sekura that
293
+ * nothing revokes, so one that has already happened is not repeated. */
294
+ export function signedInByTool(t) {
295
+ if (t.kind !== 'command')
296
+ return false;
297
+ const l = listed(t);
298
+ return !!l && l.lines.some((x) => (x.match(URLS) ?? []).some(isOurs) && /\bOAuth\b/.test(x) && !/\bnot\b/i.test(x));
299
+ }
251
300
  /** Whether the tool's own command lists our entry at our address, and with
252
301
  * our key when the entry carries one. A tool that does not print its
253
302
  * headers reads as not having it, and the entry is written again. */
254
303
  function commandHas(t) {
255
304
  if (!t.get)
256
- return 'unknown';
257
- const r = spawn(t.bin, t.get);
305
+ return listHas(t);
306
+ const r = spawn(t.bin, t.get, ASK_MS);
258
307
  if (r.error)
259
308
  return 'unknown';
260
309
  const key = keyOf(t);
261
310
  return r.status === 0 && `${r.stdout}`.includes(ENDPOINT) && (!key || `${r.stdout}`.includes(key));
262
311
  }
312
+ /** The ways a tool says the name is taken. Factory Droid's is "To overwrite
313
+ * this configuration, please first remove the existing server with: /mcp
314
+ * remove sekura", which has no "already exists" in it, so until 0.4.2 a
315
+ * rerun with a new address left Droid on the old one. */
316
+ const TAKEN = /already exists|already configured|remove the existing|to overwrite/i;
263
317
  /** Adds the entry. A tool that refuses because the name is taken is asked
264
- * what it holds: our address is "already there"; another one is replaced,
265
- * the way a JSON entry pointing elsewhere is corrected on rerun. */
318
+ * what it holds: our address is "already there"; anything else is removed
319
+ * and added again, the way a JSON entry pointing elsewhere is corrected on
320
+ * rerun. When the tool will not remove it, the person is shown the exact
321
+ * commands to run. */
266
322
  export function applyCommand(t) {
267
323
  const r = runCommand(t.bin, t.add);
268
- if (r.status !== 'failed' || !t.get || !/already exists/i.test(r.why))
324
+ if (r.status !== 'failed' || !TAKEN.test(r.why))
269
325
  return r;
270
- if (commandHas(t) === true)
271
- return { status: 'unchanged', where: `${t.bin} ${t.get.join(' ')}` };
326
+ const asked = t.get ?? t.list;
327
+ if (asked && commandHas(t) === true)
328
+ return { status: 'unchanged', where: `${t.bin} ${asked.join(' ')}` };
272
329
  const out = runCommand(t.bin, t.remove);
273
- return out.status === 'failed' ? out : runCommand(t.bin, t.add);
330
+ if (out.status !== 'failed')
331
+ return runCommand(t.bin, t.add);
332
+ // The tool's own way, when its refusal names one ("/mcp remove sekura").
333
+ const own = /with:\s*(\S.*?)\s*$/i.exec(r.why)?.[1];
334
+ return {
335
+ status: 'by-hand',
336
+ where: redactAll(`${t.bin} ${t.add.join(' ')}`),
337
+ why: `${t.bin} already has a ${SERVER_NAME} entry and did not remove it (${out.why}). Remove it, then add it again:`,
338
+ snippet: redactAll([`${t.bin} ${t.remove.join(' ')}${own ? ` (or, inside the tool: ${own})` : ''}`, `${t.bin} ${t.add.join(' ')}`].join('\n')),
339
+ };
274
340
  }
275
341
  // ── one door for every kind ────────────────────────────────────────────
276
342
  export function apply(t) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sekura",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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 test/pay.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 test/keys.test.mjs test/commands.test.mjs",
41
41
  "prepack": "npm run build"
42
42
  },
43
43
  "dependencies": {
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: sekura
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> | findings <scan> | report <scan> | cancel <scan|owner/repo> | always <owner/repo> | schedule <owner/repo> | plans | billing]"
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 monthly plan. 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> | findings <scan> | report <scan> | cancel <scan|owner/repo> | monthly <owner/repo> | schedule <owner/repo> | plans | billing]"
5
5
  ---
6
6
 
7
7
  # Sekura
@@ -25,18 +25,26 @@ the first word:
25
25
  anything the account still needs on sekura.ai, and the repositories Sekura can
26
26
  scan, then end with "Type `/sekura help` for commands."
27
27
  - `repos`: `listRepositories`.
28
- - `scan <owner/repo>`: `quoteScan` for that repository, then the two-step rule below.
28
+ - `scan <owner/repo>`: `quoteScan` for that repository (a one-time scan), then the two-step rule below.
29
29
  - `scans`: `listScans`.
30
30
  - `scan-status <scan>`: `getScan`. `findings <scan>`: `getScanFindings`.
31
31
  - `report <scan>`: `getReportLink`.
32
32
  - `cancel <scan>`: `previewCancelScan` with that scan id. `cancel <owner/repo>`:
33
33
  `previewCancelPlan` with that repository. An argument with a `/` in it is a
34
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`.
35
+ - `monthly <owner/repo>` (or `always <owner/repo>`, its older name):
36
+ `quoteAlways` for that repository, then the two-step rule. There are two
37
+ monthly plans: Weekly (`tier` `always`, the default) and More frequently
38
+ (`tier` `pro`). Use `pro` only when the user asks for More frequently, and
39
+ call it More frequently, never by its schedule kind (`daily`). It needs a
40
+ schedule; if the user gave none, ask before quoting, and always ask the time zone.
41
+ - Weekly: a weekday and a time (`schedule.kind` `weekly`), or on demand. At most
42
+ one scan in seven days.
43
+ - More frequently: every day, every second day or every third day at a time
44
+ (`schedule.kind` `daily`, `everyDays` 1, 2 or 3), or on demand. At most one scan
45
+ a day.
46
+ - On demand: `onDemand` true, keeping the plan's own `kind`, with `minute` and
47
+ `tz`. Nothing runs until the user asks; `runNow` starts each scan.
40
48
  - `schedule <owner/repo>`: `updateSchedule` for that repository with the schedule
41
49
  the user gives; ask for one if they gave none.
42
50
  - `plans`: `getPlans`. `billing`: `getBilling`.
@@ -49,16 +57,16 @@ Sekura: AI red team scans for your GitHub repositories
49
57
 
50
58
  /sekura account and repositories at a glance
51
59
  /sekura repos repositories Sekura can scan
52
- /sekura scan <owner/repo> quote a scan; it starts only after you agree
60
+ /sekura scan <owner/repo> quote a one-time scan; it starts only after you agree
53
61
  /sekura scans your scans and their status
54
62
  /sekura scan-status <scan> one scan's progress
55
63
  /sekura findings <scan> a scan's findings, with proof
56
64
  /sekura report <scan> link to the report
57
65
  /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
66
+ /sekura cancel <owner/repo> the same for a repository's monthly plan
67
+ /sekura monthly <owner/repo> quote a monthly plan: Weekly or More frequently
68
+ /sekura schedule <owner/repo> change when a monthly plan runs
69
+ /sekura plans repositories on a monthly plan
62
70
  /sekura billing what is being billed
63
71
  /sekura help this list
64
72
 
@@ -81,22 +89,22 @@ The server has eighteen tools. Read, change nothing, no confirmation:
81
89
  - `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.
82
90
  - `listRepositories`: the repositories the Sekura GitHub App is installed on.
83
91
  - `listScans`, `getScan`, `getScanFindings`, `getReportLink`: scans, their status, their findings and the report.
84
- - `getPlans`, `getBilling`: the repositories on a recurring plan, and a billing summary without card numbers.
92
+ - `getPlans`, `getBilling`: the repositories on a monthly plan, and a billing summary without card numbers.
85
93
 
86
94
  Quote, then confirm. The quote changes nothing and charges nothing:
87
95
 
88
- - `quoteScan` → `startScan`: a Sekura Once scan of one repository.
89
- - `quoteAlways` → `startAlways`: a recurring Sekura Always plan for one repository.
96
+ - `quoteScan` → `startScan`: a one-time scan of one repository.
97
+ - `quoteAlways` → `startAlways`: a monthly plan (Weekly or More frequently) for one repository.
90
98
 
91
99
  Preview, then act. The preview cancels nothing:
92
100
 
93
101
  - `previewCancelScan` → `cancelScan`: stop a scan inside its five-minute window.
94
- - `previewCancelPlan` → `cancelPlan`: end a repository's Sekura Always plan.
102
+ - `previewCancelPlan` → `cancelPlan`: end a repository's monthly plan.
95
103
 
96
104
  One call, charges nothing:
97
105
 
98
- - `updateSchedule`: change when a repository on Sekura Always is scanned.
99
- - `runNow`: bring an Always plan's next scheduled run forward. It is one of the plan's own runs, so there is no quote.
106
+ - `updateSchedule`: change when a repository on a monthly plan is scanned.
107
+ - `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.
100
108
 
101
109
  ## The two-step rule
102
110
 
@@ -146,7 +154,7 @@ Then:
146
154
  - **A saved card**: call the confirm with that option's `payment`, which is
147
155
  `{ "savedCard": { "card": "pm_…" } }` with the card the user picked. Only that
148
156
  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.
157
+ to which card ("Charged $10 to Visa ending 4242"), the scan id and the link.
150
158
  - **Pay with a Checkout link**: call the confirm with no `payment`. It answers 402
151
159
  with `checkoutUrl` and `planId`. Run, in the terminal, with a timeout of ten
152
160
  minutes:
@@ -171,7 +179,11 @@ picked is charged.
171
179
 
172
180
  ## What to tell the user
173
181
 
174
- - Through this connection a scan is Sekura Once at the quoted price. Do not mention or offer any free scan.
182
+ - Through this connection a scan is a one-time scan at the quoted price. Do not mention or offer any free scan.
183
+ - The plans a user can buy here: a one-time scan ($10), or a monthly plan for
184
+ one repository, Weekly ($10 a month per repository) or More frequently ($25 a
185
+ month per repository). The quote's price is the one that counts. There is no
186
+ trial. Enterprise is quoted by Sekura: give no price or plan name for it.
175
187
  - 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.
176
188
  - A scan can take a while. Offer `getScan` to check on it rather than polling in a loop.
177
189
  - Findings carry proof. When summarising, keep the evidence the finding gives; do not soften a severity.