@cybedefend/vibedefend 1.3.1 → 1.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 +32 -5
- package/bin/resolve.js +19 -0
- package/bin/vibedefend.js +4 -1
- package/dist/api/projects.js +158 -0
- package/dist/api/projects.js.map +1 -0
- package/dist/clients/claude-code.js +2 -2
- package/dist/clients/claude-code.js.map +1 -1
- package/dist/clients/codex.js +2 -2
- package/dist/clients/codex.js.map +1 -1
- package/dist/clients/cursor.js +2 -2
- package/dist/clients/cursor.js.map +1 -1
- package/dist/clients/vscode.js +2 -2
- package/dist/clients/vscode.js.map +1 -1
- package/dist/clients/windsurf.js +2 -2
- package/dist/clients/windsurf.js.map +1 -1
- package/dist/config.js +2 -0
- package/dist/config.js.map +1 -1
- package/dist/custom-regions.js +5 -0
- package/dist/custom-regions.js.map +1 -1
- package/dist/endpoints.js +59 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/git.js +103 -0
- package/dist/git.js.map +1 -0
- package/dist/hook-runner.js +554 -281
- package/dist/hooks/install.js +49 -6
- package/dist/hooks/install.js.map +1 -1
- package/dist/hooks/runtime/fetch-rules.js +5 -3
- package/dist/hooks/runtime/fetch-rules.js.map +1 -1
- package/dist/hooks/runtime/judge-injection.js +65 -0
- package/dist/hooks/runtime/judge-injection.js.map +1 -0
- package/dist/hooks/runtime/near-miss.js +6 -1
- package/dist/hooks/runtime/near-miss.js.map +1 -1
- package/dist/hooks/runtime/repo-link-cache.js +116 -0
- package/dist/hooks/runtime/repo-link-cache.js.map +1 -0
- package/dist/hooks/runtime/resolve.js +79 -0
- package/dist/hooks/runtime/resolve.js.map +1 -1
- package/dist/hooks/runtime/session-review.js +10 -3
- package/dist/hooks/runtime/session-review.js.map +1 -1
- package/dist/hooks/runtime/session-start.js +5 -3
- package/dist/hooks/runtime/session-start.js.map +1 -1
- package/dist/hooks/runtime/user-prompt-submit.js +10 -7
- package/dist/hooks/runtime/user-prompt-submit.js.map +1 -1
- package/dist/index.js +40 -2
- package/dist/index.js.map +1 -1
- package/dist/install.js +142 -88
- package/dist/install.js.map +1 -1
- package/dist/link.js +325 -0
- package/dist/link.js.map +1 -0
- package/dist/login.js +2 -23
- package/dist/login.js.map +1 -1
- package/dist/logout.js +87 -0
- package/dist/logout.js.map +1 -0
- package/dist/org-gate.js +110 -0
- package/dist/org-gate.js.map +1 -0
- package/dist/prompts.js +5 -7
- package/dist/prompts.js.map +1 -1
- package/package.json +1 -1
package/dist/git.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git origin remote detection + parsing.
|
|
3
|
+
*
|
|
4
|
+
* Used by `vibedefend link` to auto-detect which CybeDefend project a repo
|
|
5
|
+
* corresponds to: read `origin`'s URL via `git remote get-url origin`, then
|
|
6
|
+
* parse it into a provider + host + slug the gateway can match against a
|
|
7
|
+
* project's configured repo.
|
|
8
|
+
*/
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
/**
|
|
11
|
+
* Parse a git remote URL into { provider, host, slug }.
|
|
12
|
+
*
|
|
13
|
+
* Supports:
|
|
14
|
+
* - https(s)/git/ssh URLs with a `://` scheme, e.g.
|
|
15
|
+
* `https://github.com/o/r.git`, `ssh://git@gitlab.com/g/sg/p.git`
|
|
16
|
+
* - scp-like syntax, e.g. `git@github.com:o/r.git`
|
|
17
|
+
*
|
|
18
|
+
* `provider` is derived from a substring match on the host ("github" /
|
|
19
|
+
* "gitlab"), so self-hosted instances (`gitlab.example.com`, GitHub
|
|
20
|
+
* Enterprise) are still recognized. An unrecognized host still yields a
|
|
21
|
+
* result with `provider: null` — the caller can fall back to a manual
|
|
22
|
+
* project pick rather than failing outright.
|
|
23
|
+
*
|
|
24
|
+
* Returns `null` when the input can't be parsed into a host + non-empty
|
|
25
|
+
* slug at all (empty string, not a URL, no path component).
|
|
26
|
+
*
|
|
27
|
+
* Whitespace is trimmed, a trailing `.git` suffix is stripped from the
|
|
28
|
+
* slug, and any embedded userinfo (`user:pass@`) is ignored.
|
|
29
|
+
*/
|
|
30
|
+
export function parseRemoteUrl(url) {
|
|
31
|
+
const trimmed = url.trim();
|
|
32
|
+
if (trimmed.length === 0)
|
|
33
|
+
return null;
|
|
34
|
+
let host;
|
|
35
|
+
let rawPath;
|
|
36
|
+
if (trimmed.includes('://')) {
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = new URL(trimmed);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (!parsed.hostname)
|
|
45
|
+
return null;
|
|
46
|
+
host = parsed.hostname;
|
|
47
|
+
rawPath = parsed.pathname;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// scp-like syntax: [user@]host:path (no "://" present).
|
|
51
|
+
const scpMatch = /^(?:[^@\s]+@)?([^:\s/]+):(.+)$/.exec(trimmed);
|
|
52
|
+
if (!scpMatch)
|
|
53
|
+
return null;
|
|
54
|
+
// Lowercase to match the `://` branch: WHATWG URL parsing ASCII-folds
|
|
55
|
+
// `hostname`, so both branches must agree on casing for the same host.
|
|
56
|
+
host = scpMatch[1].toLowerCase();
|
|
57
|
+
rawPath = scpMatch[2];
|
|
58
|
+
}
|
|
59
|
+
const slug = rawPath
|
|
60
|
+
.replace(/^\/+/, '')
|
|
61
|
+
.replace(/\/+$/, '')
|
|
62
|
+
.replace(/\.git$/i, '');
|
|
63
|
+
if (slug.length === 0)
|
|
64
|
+
return null;
|
|
65
|
+
return { provider: detectProvider(host), host, slug };
|
|
66
|
+
}
|
|
67
|
+
function detectProvider(host) {
|
|
68
|
+
const lower = host.toLowerCase();
|
|
69
|
+
if (lower.includes('github'))
|
|
70
|
+
return 'github';
|
|
71
|
+
if (lower.includes('gitlab'))
|
|
72
|
+
return 'gitlab';
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const GIT_REMOTE_TIMEOUT_MS = 3000;
|
|
76
|
+
/**
|
|
77
|
+
* Read the `origin` remote's URL for the git repo at `cwd` via
|
|
78
|
+
* `git remote get-url origin`. Returns `null` when `cwd` isn't a git repo,
|
|
79
|
+
* there's no `origin` remote, or the command otherwise fails/times out —
|
|
80
|
+
* never throws.
|
|
81
|
+
*/
|
|
82
|
+
export function getOriginRemote(cwd, deps = {}) {
|
|
83
|
+
const execImpl = deps.execImpl ?? defaultExecImpl;
|
|
84
|
+
const result = execImpl('git', ['remote', 'get-url', 'origin'], {
|
|
85
|
+
cwd,
|
|
86
|
+
timeoutMs: GIT_REMOTE_TIMEOUT_MS,
|
|
87
|
+
});
|
|
88
|
+
if (result.status !== 0)
|
|
89
|
+
return null;
|
|
90
|
+
const url = result.stdout.trim();
|
|
91
|
+
return url.length > 0 ? url : null;
|
|
92
|
+
}
|
|
93
|
+
function defaultExecImpl(cmd, args, opts) {
|
|
94
|
+
const result = spawnSync(cmd, args, {
|
|
95
|
+
cwd: opts.cwd,
|
|
96
|
+
encoding: 'utf8',
|
|
97
|
+
timeout: opts.timeoutMs,
|
|
98
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
99
|
+
windowsHide: true,
|
|
100
|
+
});
|
|
101
|
+
return { status: result.status, stdout: result.stdout ?? '' };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=git.js.map
|
package/dist/git.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../src/git.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAQ/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,MAAM,OAAO,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEtC,IAAI,IAAY,CAAC;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