codeproof 1.0.4 → 1.0.5

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/utils/files.js CHANGED
@@ -1,50 +1,50 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- const DEFAULT_EXCLUDES = new Set([".git", "node_modules", ".venv", "dist", "build"]);
5
-
6
- export function getDefaultExcludes() {
7
- return DEFAULT_EXCLUDES;
8
- }
9
-
10
- export function isBinaryFile(filePath) {
11
- // Heuristic: if the first chunk contains a null byte, treat as binary.
12
- try {
13
- const fd = fs.openSync(filePath, "r");
14
- const buffer = Buffer.alloc(8000);
15
- const bytesRead = fs.readSync(fd, buffer, 0, buffer.length, 0);
16
- fs.closeSync(fd);
17
- for (let i = 0; i < bytesRead; i += 1) {
18
- if (buffer[i] === 0) {
19
- return true;
20
- }
21
- }
22
- return false;
23
- } catch {
24
- return true;
25
- }
26
- }
27
-
28
- export function listFilesRecursive(rootDir, excludes = DEFAULT_EXCLUDES) {
29
- const results = [];
30
-
31
- function walk(currentDir) {
32
- const entries = fs.readdirSync(currentDir, { withFileTypes: true });
33
- for (const entry of entries) {
34
- if (excludes.has(entry.name)) {
35
- continue;
36
- }
37
-
38
- const fullPath = path.join(currentDir, entry.name);
39
-
40
- if (entry.isDirectory()) {
41
- walk(fullPath);
42
- } else if (entry.isFile()) {
43
- results.push(fullPath);
44
- }
45
- }
46
- }
47
-
48
- walk(rootDir);
49
- return results;
50
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ const DEFAULT_EXCLUDES = new Set([".git", "node_modules", ".venv", "dist", "build"]);
5
+
6
+ export function getDefaultExcludes() {
7
+ return DEFAULT_EXCLUDES;
8
+ }
9
+
10
+ export function isBinaryFile(filePath) {
11
+ // Heuristic: if the first chunk contains a null byte, treat as binary.
12
+ try {
13
+ const fd = fs.openSync(filePath, "r");
14
+ const buffer = Buffer.alloc(8000);
15
+ const bytesRead = fs.readSync(fd, buffer, 0, buffer.length, 0);
16
+ fs.closeSync(fd);
17
+ for (let i = 0; i < bytesRead; i += 1) {
18
+ if (buffer[i] === 0) {
19
+ return true;
20
+ }
21
+ }
22
+ return false;
23
+ } catch {
24
+ return true;
25
+ }
26
+ }
27
+
28
+ export function listFilesRecursive(rootDir, excludes = DEFAULT_EXCLUDES) {
29
+ const results = [];
30
+
31
+ function walk(currentDir) {
32
+ const entries = fs.readdirSync(currentDir, { withFileTypes: true });
33
+ for (const entry of entries) {
34
+ if (excludes.has(entry.name)) {
35
+ continue;
36
+ }
37
+
38
+ const fullPath = path.join(currentDir, entry.name);
39
+
40
+ if (entry.isDirectory()) {
41
+ walk(fullPath);
42
+ } else if (entry.isFile()) {
43
+ results.push(fullPath);
44
+ }
45
+ }
46
+ }
47
+
48
+ walk(rootDir);
49
+ return results;
50
+ }
package/utils/git.js CHANGED
@@ -1,63 +1,63 @@
1
- import { spawnSync } from "child_process";
2
- import { logError } from "./logger.js";
3
-
4
- function runGit(args, cwd) {
5
- const result = spawnSync("git", args, {
6
- cwd,
7
- stdio: "pipe",
8
- encoding: "utf8"
9
- });
10
-
11
- if (result.error) {
12
- throw result.error;
13
- }
14
-
15
- return result;
16
- }
17
-
18
- export function ensureGitRepo(cwd) {
19
- const result = runGit(["rev-parse", "--is-inside-work-tree"], cwd);
20
- if (result.status !== 0 || !String(result.stdout).trim().includes("true")) {
21
- logError("Not a Git repository. Run this inside a Git repo.");
22
- process.exit(1);
23
- }
24
- }
25
-
26
- export function getGitRoot(cwd) {
27
- const result = runGit(["rev-parse", "--show-toplevel"], cwd);
28
- if (result.status !== 0) {
29
- logError("Failed to resolve Git root.");
30
- process.exit(1);
31
- }
32
- return String(result.stdout).trim();
33
- }
34
-
35
- export function getStagedFiles(cwd) {
36
- const result = runGit(["diff", "--cached", "--name-only"], cwd);
37
- if (result.status !== 0) {
38
- logError("Failed to read staged files.");
39
- process.exit(1);
40
- }
41
-
42
- return String(result.stdout)
43
- .split(/\r?\n/)
44
- .map((line) => line.trim())
45
- .filter(Boolean);
46
- }
47
-
48
- export function getRepoIdentifier(gitRoot) {
49
- try {
50
- const result = runGit(["config", "--get", "remote.origin.url"], gitRoot);
51
- if (result.status === 0) {
52
- return String(result.stdout).trim() || gitRoot;
53
- }
54
- } catch {
55
- // Fallback to directory name
56
- }
57
- return gitRoot;
58
- }
59
-
60
- export function getProjectName(gitRoot) {
61
- const parts = gitRoot.split(/[\\/]/);
62
- return parts[parts.length - 1] || "Unknown";
63
- }
1
+ import { spawnSync } from "child_process";
2
+ import { logError } from "./logger.js";
3
+
4
+ function runGit(args, cwd) {
5
+ const result = spawnSync("git", args, {
6
+ cwd,
7
+ stdio: "pipe",
8
+ encoding: "utf8"
9
+ });
10
+
11
+ if (result.error) {
12
+ throw result.error;
13
+ }
14
+
15
+ return result;
16
+ }
17
+
18
+ export function ensureGitRepo(cwd) {
19
+ const result = runGit(["rev-parse", "--is-inside-work-tree"], cwd);
20
+ if (result.status !== 0 || !String(result.stdout).trim().includes("true")) {
21
+ logError("Not a Git repository. Run this inside a Git repo.");
22
+ process.exit(1);
23
+ }
24
+ }
25
+
26
+ export function getGitRoot(cwd) {
27
+ const result = runGit(["rev-parse", "--show-toplevel"], cwd);
28
+ if (result.status !== 0) {
29
+ logError("Failed to resolve Git root.");
30
+ process.exit(1);
31
+ }
32
+ return String(result.stdout).trim();
33
+ }
34
+
35
+ export function getStagedFiles(cwd) {
36
+ const result = runGit(["diff", "--cached", "--name-only"], cwd);
37
+ if (result.status !== 0) {
38
+ logError("Failed to read staged files.");
39
+ process.exit(1);
40
+ }
41
+
42
+ return String(result.stdout)
43
+ .split(/\r?\n/)
44
+ .map((line) => line.trim())
45
+ .filter(Boolean);
46
+ }
47
+
48
+ export function getRepoIdentifier(gitRoot) {
49
+ try {
50
+ const result = runGit(["config", "--get", "remote.origin.url"], gitRoot);
51
+ if (result.status === 0) {
52
+ return String(result.stdout).trim() || gitRoot;
53
+ }
54
+ } catch {
55
+ // Fallback to directory name
56
+ }
57
+ return gitRoot;
58
+ }
59
+
60
+ export function getProjectName(gitRoot) {
61
+ const parts = gitRoot.split(/[\\/]/);
62
+ return parts[parts.length - 1] || "Unknown";
63
+ }
@@ -1,55 +1,55 @@
1
- import path from "path";
2
- import { spawnSync } from "child_process";
3
-
4
- function normalizePathForGit(filePath, gitRoot) {
5
- const relative = path.isAbsolute(filePath)
6
- ? path.relative(gitRoot, filePath)
7
- : filePath;
8
-
9
- if (!relative || relative.startsWith("..")) {
10
- return null;
11
- }
12
-
13
- return relative.replace(/\\/g, "/");
14
- }
15
-
16
- export function filterIgnoredFiles({ gitRoot, filePaths }) {
17
- if (!Array.isArray(filePaths) || filePaths.length === 0) {
18
- return [];
19
- }
20
-
21
- const normalized = new Map();
22
- for (const filePath of filePaths) {
23
- const relative = normalizePathForGit(filePath, gitRoot);
24
- if (relative) {
25
- normalized.set(relative, filePath);
26
- }
27
- }
28
-
29
- if (normalized.size === 0) {
30
- return [];
31
- }
32
-
33
- // Use `git check-ignore` to respect .gitignore rules quickly and accurately.
34
- const input = `${Array.from(normalized.keys()).join("\u0000")}\u0000`;
35
- const result = spawnSync("git", ["check-ignore", "--stdin", "-z"], {
36
- cwd: gitRoot,
37
- input,
38
- encoding: "utf8"
39
- });
40
-
41
- if (result.error || (result.status && result.status > 1)) {
42
- return Array.from(normalized.values());
43
- }
44
-
45
- const ignored = new Set(
46
- String(result.stdout)
47
- .split("\u0000")
48
- .map((entry) => entry.trim())
49
- .filter(Boolean)
50
- );
51
-
52
- return Array.from(normalized.entries())
53
- .filter(([relative]) => !ignored.has(relative))
54
- .map(([, original]) => original);
55
- }
1
+ import path from "path";
2
+ import { spawnSync } from "child_process";
3
+
4
+ function normalizePathForGit(filePath, gitRoot) {
5
+ const relative = path.isAbsolute(filePath)
6
+ ? path.relative(gitRoot, filePath)
7
+ : filePath;
8
+
9
+ if (!relative || relative.startsWith("..")) {
10
+ return null;
11
+ }
12
+
13
+ return relative.replace(/\\/g, "/");
14
+ }
15
+
16
+ export function filterIgnoredFiles({ gitRoot, filePaths }) {
17
+ if (!Array.isArray(filePaths) || filePaths.length === 0) {
18
+ return [];
19
+ }
20
+
21
+ const normalized = new Map();
22
+ for (const filePath of filePaths) {
23
+ const relative = normalizePathForGit(filePath, gitRoot);
24
+ if (relative) {
25
+ normalized.set(relative, filePath);
26
+ }
27
+ }
28
+
29
+ if (normalized.size === 0) {
30
+ return [];
31
+ }
32
+
33
+ // Use `git check-ignore` to respect .gitignore rules quickly and accurately.
34
+ const input = `${Array.from(normalized.keys()).join("\u0000")}\u0000`;
35
+ const result = spawnSync("git", ["check-ignore", "--stdin", "-z"], {
36
+ cwd: gitRoot,
37
+ input,
38
+ encoding: "utf8"
39
+ });
40
+
41
+ if (result.error || (result.status && result.status > 1)) {
42
+ return Array.from(normalized.values());
43
+ }
44
+
45
+ const ignored = new Set(
46
+ String(result.stdout)
47
+ .split("\u0000")
48
+ .map((entry) => entry.trim())
49
+ .filter(Boolean)
50
+ );
51
+
52
+ return Array.from(normalized.entries())
53
+ .filter(([relative]) => !ignored.has(relative))
54
+ .map(([, original]) => original);
55
+ }
package/utils/logger.js CHANGED
@@ -1,25 +1,25 @@
1
- function formatPrefix(level) {
2
- const map = {
3
- info: "[codeproof]",
4
- success: "[codeproof]",
5
- warn: "[codeproof]",
6
- error: "[codeproof]"
7
- };
8
- return map[level] || "[codeproof]";
9
- }
10
-
11
- export function logInfo(message) {
12
- console.log(`${formatPrefix("info")} ${message}`);
13
- }
14
-
15
- export function logSuccess(message) {
16
- console.log(`${formatPrefix("success")} ${message}`);
17
- }
18
-
19
- export function logWarn(message) {
20
- console.warn(`${formatPrefix("warn")} ${message}`);
21
- }
22
-
23
- export function logError(message) {
24
- console.error(`${formatPrefix("error")} ${message}`);
25
- }
1
+ function formatPrefix(level) {
2
+ const map = {
3
+ info: "[codeproof]",
4
+ success: "[codeproof]",
5
+ warn: "[codeproof]",
6
+ error: "[codeproof]"
7
+ };
8
+ return map[level] || "[codeproof]";
9
+ }
10
+
11
+ export function logInfo(message) {
12
+ console.log(`${formatPrefix("info")} ${message}`);
13
+ }
14
+
15
+ export function logSuccess(message) {
16
+ console.log(`${formatPrefix("success")} ${message}`);
17
+ }
18
+
19
+ export function logWarn(message) {
20
+ console.warn(`${formatPrefix("warn")} ${message}`);
21
+ }
22
+
23
+ export function logError(message) {
24
+ console.error(`${formatPrefix("error")} ${message}`);
25
+ }
@@ -1,20 +1,20 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- export function detectProjectType(rootDir) {
5
- const hasFile = (fileName) => fs.existsSync(path.join(rootDir, fileName));
6
-
7
- if (hasFile("package.json")) {
8
- return "Node";
9
- }
10
-
11
- if (hasFile("requirements.txt") || hasFile("pyproject.toml")) {
12
- return "Python";
13
- }
14
-
15
- if (hasFile("pom.xml") || hasFile("build.gradle")) {
16
- return "Java";
17
- }
18
-
19
- return "Unknown";
20
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export function detectProjectType(rootDir) {
5
+ const hasFile = (fileName) => fs.existsSync(path.join(rootDir, fileName));
6
+
7
+ if (hasFile("package.json")) {
8
+ return "Node";
9
+ }
10
+
11
+ if (hasFile("requirements.txt") || hasFile("pyproject.toml")) {
12
+ return "Python";
13
+ }
14
+
15
+ if (hasFile("pom.xml") || hasFile("build.gradle")) {
16
+ return "Java";
17
+ }
18
+
19
+ return "Unknown";
20
+ }
package/.env DELETED
@@ -1 +0,0 @@
1
- AI_API_URL = "https://api-risk-fgef.onrender.com/predict"