@checkvibe/ci 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CheckVibe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # @checkvibe/ci
2
+
3
+ Run CheckVibe's pull-request security review from any CI job and fail the build on what the pull request introduces.
4
+
5
+ ```yaml
6
+ # GitHub Actions
7
+ - run: npx @checkvibe/ci pr-scan --fail-on high
8
+ env:
9
+ CHECKVIBE_API_KEY: ${{ secrets.CHECKVIBE_API_KEY }}
10
+ ```
11
+
12
+ ```yaml
13
+ # GitLab CI
14
+ checkvibe:
15
+ script: npx @checkvibe/ci pr-scan --fail-on high
16
+ only: [merge_requests]
17
+ ```
18
+
19
+ The repository and pull request are read from the CI's own variables (`GITHUB_REPOSITORY`/`GITHUB_REF`, `CI_PROJECT_PATH`/`CI_MERGE_REQUEST_IID`, `BITBUCKET_REPO_FULL_NAME`/`BITBUCKET_PR_ID`) or passed with `--repo` and `--pr`. The API key needs the `scan:write` and `scan:read` scopes (Settings › API keys). The repository must already be connected to CheckVibe.
20
+
21
+ | Exit | Meaning |
22
+ |---|---|
23
+ | 0 | passed |
24
+ | 1 | blocked: new findings at or above `--fail-on` (or the repository's threshold; the Merge Gate's verdict wins when it ran) |
25
+ | 2 | the review did not complete, or timed out (`--timeout`, default 600 s) |
26
+ | 3 | usage or authentication error |
27
+
28
+ `--json` prints the scan as the API returns it. `--full` skips the fast lane and clones the repository in full. On GitHub Actions each finding is also emitted as a `::error`/`::warning` annotation on its line.
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ import { decideExit, EXIT, inferPullRequest, isTerminal, parseArgs, renderText, USAGE } from '../src/index.mjs';
3
+
4
+ const args = parseArgs(process.argv.slice(2));
5
+ const command = args._[0];
6
+ if (command !== 'pr-scan' || args.help) {
7
+ console.log(USAGE);
8
+ process.exit(command ? EXIT.PASS : EXIT.USAGE);
9
+ }
10
+ const apiKey = args['api-key'] ?? process.env.CHECKVIBE_API_KEY;
11
+ if (!apiKey) {
12
+ console.error('checkvibe-ci: no API key — pass --api-key or set CHECKVIBE_API_KEY');
13
+ process.exit(EXIT.USAGE);
14
+ }
15
+ const inferred = inferPullRequest(process.env);
16
+ const repo = args.repo ?? inferred?.repo;
17
+ const pr = Number(args.pr ?? inferred?.pr);
18
+ if (!repo || !Number.isInteger(pr) || pr < 1) {
19
+ console.error('checkvibe-ci: could not tell which pull request this is — pass --repo and --pr');
20
+ process.exit(EXIT.USAGE);
21
+ }
22
+ const origin = (args.origin ?? process.env.CHECKVIBE_ORIGIN ?? 'https://checkvibe.dev').replace(/\/$/, '');
23
+ const timeoutMs = Number(args.timeout ?? 600) * 1000;
24
+ const intervalMs = Math.max(2, Number(args.interval ?? 5)) * 1000;
25
+ const headers = { 'content-type': 'application/json', authorization: `Bearer ${apiKey}`, 'user-agent': 'checkvibe-ci/0.1' };
26
+ const onActions = !!process.env.GITHUB_ACTIONS;
27
+
28
+ async function api(path, init) {
29
+ const res = await fetch(`${origin}${path}`, { ...init, headers, signal: AbortSignal.timeout(30_000) });
30
+ const text = await res.text();
31
+ let body = null;
32
+ try { body = JSON.parse(text); } catch { /* prose error */ }
33
+ return { ok: res.ok, status: res.status, body, text };
34
+ }
35
+
36
+ const started = await api('/api/v1/pr-scans', { method: 'POST', body: JSON.stringify({ repo, pr_number: pr, full: !!args.full }) });
37
+ if (!started.ok || !started.body?.id) {
38
+ console.error(`checkvibe-ci: could not start the review (${started.status}): ${started.body?.message ?? started.body?.error ?? started.text.slice(0, 200)}`);
39
+ process.exit(started.status === 401 || started.status === 403 ? EXIT.USAGE : EXIT.INCOMPLETE);
40
+ }
41
+ const id = started.body.id;
42
+ if (!args.json) console.log(`checkvibe-ci: review ${id} ${started.body.result} · ${started.body.dashboard_url}`);
43
+
44
+ const deadline = Date.now() + timeoutMs;
45
+ let scan = null;
46
+ for (;;) {
47
+ const res = await api(`/api/v1/pr-scans/${id}`, { method: 'GET' });
48
+ if (res.ok && res.body) {
49
+ scan = res.body;
50
+ if (isTerminal(scan.status)) break;
51
+ } else if (res.status === 401 || res.status === 403 || res.status === 404) {
52
+ console.error(`checkvibe-ci: poll refused (${res.status})`);
53
+ process.exit(EXIT.USAGE);
54
+ }
55
+ if (Date.now() >= deadline) {
56
+ console.error(`checkvibe-ci: timed out after ${timeoutMs / 1000}s — the review is still running: ${origin}/dashboard/repositories/pull-requests/${id}`);
57
+ process.exit(EXIT.INCOMPLETE);
58
+ }
59
+ await new Promise((r) => setTimeout(r, intervalMs));
60
+ }
61
+ if (args.json) console.log(JSON.stringify(scan, null, 2));
62
+ else console.log(renderText(scan, { actions: onActions }));
63
+ process.exit(decideExit(scan, args['fail-on']));
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@checkvibe/ci",
3
+ "version": "0.1.0",
4
+ "description": "Run CheckVibe's pull-request security review from any CI job and fail the build on what the pull request introduces. Zero dependencies.",
5
+ "type": "module",
6
+ "bin": { "checkvibe-ci": "./bin/checkvibe-ci.mjs" },
7
+ "main": "./src/index.mjs",
8
+ "files": ["bin", "src", "README.md", "LICENSE"],
9
+ "engines": { "node": ">=18" },
10
+ "scripts": { "test": "node --test test/*.test.mjs" },
11
+ "keywords": ["security", "ci", "pull-request", "sast", "secrets", "dependencies"],
12
+ "license": "MIT",
13
+ "repository": { "type": "git", "url": "git+https://github.com/YvesMatteo/VibeCodeDetector.git", "directory": "packages/checkvibe-ci" },
14
+ "homepage": "https://checkvibe.dev",
15
+ "publishConfig": { "access": "public" }
16
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * The pure parts of `checkvibe-ci pr-scan`: reading the pull request from
3
+ * the CI environment, deciding an exit code, rendering the result. No
4
+ * network here — the bin wires these to fetch.
5
+ */
6
+
7
+ export const EXIT = Object.freeze({ PASS: 0, BLOCKED: 1, INCOMPLETE: 2, USAGE: 3 });
8
+
9
+ const SEV_RANK = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
10
+ const THRESHOLD_RANK = { never: null, critical: 0, high: 1, medium: 2, all: 4 };
11
+
12
+ /** The repository and pull request the job is running for, from the CI's own variables. */
13
+ export function inferPullRequest(env) {
14
+ // GitHub Actions: GITHUB_REPOSITORY=owner/name, GITHUB_REF=refs/pull/N/merge
15
+ const ghRef = /^refs\/pull\/(\d+)\//.exec(env.GITHUB_REF ?? '');
16
+ if (env.GITHUB_REPOSITORY && ghRef) return { repo: env.GITHUB_REPOSITORY, pr: Number(ghRef[1]), provider: 'github' };
17
+ // GitLab CI: CI_PROJECT_PATH=group/project, CI_MERGE_REQUEST_IID=N
18
+ if (env.CI_PROJECT_PATH && env.CI_MERGE_REQUEST_IID) return { repo: env.CI_PROJECT_PATH, pr: Number(env.CI_MERGE_REQUEST_IID), provider: 'gitlab' };
19
+ // Bitbucket Pipelines: BITBUCKET_REPO_FULL_NAME=workspace/repo, BITBUCKET_PR_ID=N
20
+ if (env.BITBUCKET_REPO_FULL_NAME && env.BITBUCKET_PR_ID) return { repo: env.BITBUCKET_REPO_FULL_NAME, pr: Number(env.BITBUCKET_PR_ID), provider: 'bitbucket' };
21
+ return null;
22
+ }
23
+
24
+ /** `--flag value` / `--flag=value` / `--bool`. Positionals kept in `_`. */
25
+ export function parseArgs(argv) {
26
+ const out = { _: [] };
27
+ for (let i = 0; i < argv.length; i++) {
28
+ const a = argv[i];
29
+ if (!a.startsWith('--')) { out._.push(a); continue; }
30
+ const eq = a.indexOf('=');
31
+ if (eq >= 0) { out[a.slice(2, eq)] = a.slice(eq + 1); continue; }
32
+ const next = argv[i + 1];
33
+ if (next !== undefined && !next.startsWith('--')) { out[a.slice(2)] = next; i++; }
34
+ else out[a.slice(2)] = true;
35
+ }
36
+ return out;
37
+ }
38
+
39
+ export function isTerminal(status) {
40
+ return status === 'completed' || status === 'partial' || status === 'failed' || status === 'skipped';
41
+ }
42
+
43
+ /**
44
+ * The exit code for a finished scan. `failOn` overrides the repository's
45
+ * configured threshold when given; the gate's own verdict wins when it ran.
46
+ */
47
+ export function decideExit(scan, failOn) {
48
+ if (!isTerminal(scan.status)) return EXIT.INCOMPLETE;
49
+ if (scan.status === 'failed' || scan.status === 'skipped') return EXIT.INCOMPLETE;
50
+ if (scan.gate && scan.gate.verdict) return scan.gate.passed ? EXIT.PASS : EXIT.BLOCKED;
51
+ const threshold = failOn ?? scan.gate?.fail_on ?? 'never';
52
+ const rank = THRESHOLD_RANK[threshold];
53
+ if (rank === null || rank === undefined) return EXIT.PASS;
54
+ const blocking = (scan.findings ?? []).filter((f) => f.novelty !== 'existing' && (SEV_RANK[f.severity] ?? 9) <= rank);
55
+ return blocking.length ? EXIT.BLOCKED : EXIT.PASS;
56
+ }
57
+
58
+ /** One line per finding, plus GitHub Actions annotations when running there. */
59
+ export function renderText(scan, { actions = false } = {}) {
60
+ const lines = [];
61
+ const c = scan.counts ?? {};
62
+ lines.push(`CheckVibe · ${scan.repo} #${scan.pr_number} · ${scan.status}${scan.error ? ` (${scan.error})` : ''}`);
63
+ if (typeof c.new === 'number') lines.push(`${c.new} new · ${c.solved ?? '?'} solved · ${c.existing ?? 0} pre-existing · ${c.files_changed ?? '?'} files changed${c.truncated ? ' · list truncated' : ''}`);
64
+ for (const f of scan.findings ?? []) {
65
+ const where = f.file ? `${f.file}${f.line ? `:${f.line}` : ''}` : f.package ?? '';
66
+ lines.push(` [${f.severity}] ${f.title}${where ? ` — ${where}` : ''}${f.novelty === 'undetermined' ? ' (unplaced, treated as new)' : ''}`);
67
+ if (actions && f.file) {
68
+ const level = f.severity === 'critical' || f.severity === 'high' ? 'error' : 'warning';
69
+ lines.push(`::${level} file=${f.file}${f.line ? `,line=${f.line}` : ''},title=CheckVibe::${f.title.replace(/[\r\n]/g, ' ')}`);
70
+ }
71
+ }
72
+ if (scan.gate) lines.push(scan.gate.passed === null ? 'gate: not decided' : scan.gate.passed ? `gate: passed (fails at ${scan.gate.fail_on})` : `gate: FAILED — ${scan.gate.blocking_count} blocking at ${scan.gate.fail_on}`);
73
+ lines.push(scan.dashboard_url);
74
+ return lines.join('\n');
75
+ }
76
+
77
+ export const USAGE = `checkvibe-ci pr-scan [--repo owner/name] [--pr N] [--fail-on never|critical|high|medium|all]
78
+ [--timeout 600] [--interval 5] [--full] [--json] [--api-key KEY] [--origin https://checkvibe.dev]
79
+
80
+ Starts CheckVibe's pull-request security review and waits for it. Repository and
81
+ pull request are read from GITHUB_REPOSITORY/GITHUB_REF, CI_PROJECT_PATH/
82
+ CI_MERGE_REQUEST_IID or BITBUCKET_REPO_FULL_NAME/BITBUCKET_PR_ID when not given.
83
+ The API key comes from --api-key or CHECKVIBE_API_KEY (scopes scan:write + scan:read).
84
+
85
+ Exit codes: 0 passed · 1 blocked by findings · 2 review did not complete · 3 usage or auth error.`;