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/bin/codeproof.js CHANGED
@@ -1,61 +1,61 @@
1
1
  #!/usr/bin/env node
2
- import { runInit } from "../commands/init.js";
3
- import { runCli } from "../commands/run.js";
4
- import { runReportDashboard } from "../commands/reportDashboard.js";
5
- import { runMoveSecret } from "../commands/moveSecret.js";
6
- import { runWhoAmI } from "../commands/whoami.js";
7
- import { runIgnore } from "../commands/ignore.js";
8
- import { runApply } from "../commands/apply.js";
9
- import { logError, logInfo } from "../utils/logger.js";
10
-
11
- const [, , command, ...args] = process.argv;
12
-
13
- async function main() {
14
- if (!command || command === "-h" || command === "--help") {
15
- logInfo("Usage: codeproof <command>\n\nCommands:\n init Initialize CodeProof in a Git repository\n run Run CodeProof checks (stub)\n report@dashboard Send latest report and show dashboard link\n move-secret Move high-confidence secrets to .env\n ignore Temporarily disable commit enforcement\n apply Re-enable commit enforcement\n whoami Show the local CodeProof client ID");
16
- process.exit(0);
17
- }
18
-
19
- if (command === "init") {
20
- await runInit({ args, cwd: process.cwd() });
21
- return;
22
- }
23
-
24
- if (command === "run") {
25
- await runCli({ args, cwd: process.cwd() });
26
- return;
27
- }
28
-
29
- if (command === "report@dashboard") {
30
- await runReportDashboard({ args, cwd: process.cwd() });
31
- return;
32
- }
33
-
34
- if (command === "move-secret") {
35
- await runMoveSecret({ args, cwd: process.cwd() });
36
- return;
37
- }
38
-
39
- if (command === "ignore") {
40
- await runIgnore({ args, cwd: process.cwd() });
41
- return;
42
- }
43
-
44
- if (command === "apply") {
45
- await runApply({ args, cwd: process.cwd() });
46
- return;
47
- }
48
-
49
- if (command === "whoami") {
50
- await runWhoAmI();
51
- return;
52
- }
53
-
54
- logError(`Unknown command: ${command}`);
55
- process.exit(1);
56
- }
57
-
58
- main().catch((error) => {
59
- logError(error?.message || String(error));
60
- process.exit(1);
61
- });
2
+ import { runInit } from "../commands/init.js";
3
+ import { runCli } from "../commands/run.js";
4
+ import { runReportDashboard } from "../commands/reportDashboard.js";
5
+ import { runMoveSecret } from "../commands/moveSecret.js";
6
+ import { runWhoAmI } from "../commands/whoami.js";
7
+ import { runIgnore } from "../commands/ignore.js";
8
+ import { runApply } from "../commands/apply.js";
9
+ import { logError, logInfo } from "../utils/logger.js";
10
+
11
+ const [, , command, ...args] = process.argv;
12
+
13
+ async function main() {
14
+ if (!command || command === "-h" || command === "--help") {
15
+ logInfo("Usage: codeproof <command>\n\nCommands:\n init Initialize CodeProof in a Git repository\n run Run CodeProof checks (stub)\n report@dashboard Send latest report and show dashboard link\n move-secret Move high-confidence secrets to .env\n ignore Temporarily disable commit enforcement\n apply Re-enable commit enforcement\n whoami Show the local CodeProof client ID");
16
+ process.exit(0);
17
+ }
18
+
19
+ if (command === "init") {
20
+ await runInit({ args, cwd: process.cwd() });
21
+ return;
22
+ }
23
+
24
+ if (command === "run") {
25
+ await runCli({ args, cwd: process.cwd() });
26
+ return;
27
+ }
28
+
29
+ if (command === "report@dashboard") {
30
+ await runReportDashboard({ args, cwd: process.cwd() });
31
+ return;
32
+ }
33
+
34
+ if (command === "move-secret") {
35
+ await runMoveSecret({ args, cwd: process.cwd() });
36
+ return;
37
+ }
38
+
39
+ if (command === "ignore") {
40
+ await runIgnore({ args, cwd: process.cwd() });
41
+ return;
42
+ }
43
+
44
+ if (command === "apply") {
45
+ await runApply({ args, cwd: process.cwd() });
46
+ return;
47
+ }
48
+
49
+ if (command === "whoami") {
50
+ await runWhoAmI();
51
+ return;
52
+ }
53
+
54
+ logError(`Unknown command: ${command}`);
55
+ process.exit(1);
56
+ }
57
+
58
+ main().catch((error) => {
59
+ logError(error?.message || String(error));
60
+ process.exit(1);
61
+ });
package/commands/apply.js CHANGED
@@ -1,32 +1,32 @@
1
- import { ensureGitRepo, getGitRoot } from "../utils/git.js";
2
- import { logError, logInfo, logSuccess, logWarn } from "../utils/logger.js";
3
- import { getEnforcementState, setEnforcementState } from "../core/enforcement.js";
4
-
5
- export async function runApply({ cwd }) {
6
- // Re-enable enforcement explicitly to restore pre-commit blocking.
7
- ensureGitRepo(cwd);
8
- const gitRoot = getGitRoot(cwd);
9
-
10
- let current = "enabled";
11
- try {
12
- current = getEnforcementState(gitRoot);
13
- } catch (error) {
14
- logError(error?.message || "Unable to read codeproof.config.json.");
15
- process.exit(1);
16
- }
17
-
18
- if (current === "enabled") {
19
- logWarn("CodeProof enforcement is already enabled.");
20
- return;
21
- }
22
-
23
- try {
24
- setEnforcementState(gitRoot, "enabled");
25
- } catch (error) {
26
- logError(error?.message || "Unable to update codeproof.config.json.");
27
- process.exit(1);
28
- }
29
-
30
- logSuccess("CodeProof enforcement re-enabled.");
31
- logInfo("Pre-commit protection active.");
32
- }
1
+ import { ensureGitRepo, getGitRoot } from "../utils/git.js";
2
+ import { logError, logInfo, logSuccess, logWarn } from "../utils/logger.js";
3
+ import { getEnforcementState, setEnforcementState } from "../core/enforcement.js";
4
+
5
+ export async function runApply({ cwd }) {
6
+ // Re-enable enforcement explicitly to restore pre-commit blocking.
7
+ ensureGitRepo(cwd);
8
+ const gitRoot = getGitRoot(cwd);
9
+
10
+ let current = "enabled";
11
+ try {
12
+ current = getEnforcementState(gitRoot);
13
+ } catch (error) {
14
+ logError(error?.message || "Unable to read codeproof.config.json.");
15
+ process.exit(1);
16
+ }
17
+
18
+ if (current === "enabled") {
19
+ logWarn("CodeProof enforcement is already enabled.");
20
+ return;
21
+ }
22
+
23
+ try {
24
+ setEnforcementState(gitRoot, "enabled");
25
+ } catch (error) {
26
+ logError(error?.message || "Unable to update codeproof.config.json.");
27
+ process.exit(1);
28
+ }
29
+
30
+ logSuccess("CodeProof enforcement re-enabled.");
31
+ logInfo("Pre-commit protection active.");
32
+ }
@@ -1,32 +1,32 @@
1
- import { ensureGitRepo, getGitRoot } from "../utils/git.js";
2
- import { logError, logInfo, logSuccess, logWarn } from "../utils/logger.js";
3
- import { getEnforcementState, setEnforcementState } from "../core/enforcement.js";
4
-
5
- export async function runIgnore({ cwd }) {
6
- // Controlled bypass: disabling enforcement is explicit and project-scoped.
7
- ensureGitRepo(cwd);
8
- const gitRoot = getGitRoot(cwd);
9
-
10
- let current = "enabled";
11
- try {
12
- current = getEnforcementState(gitRoot);
13
- } catch (error) {
14
- logError(error?.message || "Unable to read codeproof.config.json.");
15
- process.exit(1);
16
- }
17
-
18
- if (current === "disabled") {
19
- logWarn("CodeProof enforcement is already disabled.");
20
- return;
21
- }
22
-
23
- try {
24
- setEnforcementState(gitRoot, "disabled");
25
- } catch (error) {
26
- logError(error?.message || "Unable to update codeproof.config.json.");
27
- process.exit(1);
28
- }
29
-
30
- logSuccess("CodeProof enforcement disabled.");
31
- logInfo("Commits will not be blocked until `codeproof apply` is run.");
32
- }
1
+ import { ensureGitRepo, getGitRoot } from "../utils/git.js";
2
+ import { logError, logInfo, logSuccess, logWarn } from "../utils/logger.js";
3
+ import { getEnforcementState, setEnforcementState } from "../core/enforcement.js";
4
+
5
+ export async function runIgnore({ cwd }) {
6
+ // Controlled bypass: disabling enforcement is explicit and project-scoped.
7
+ ensureGitRepo(cwd);
8
+ const gitRoot = getGitRoot(cwd);
9
+
10
+ let current = "enabled";
11
+ try {
12
+ current = getEnforcementState(gitRoot);
13
+ } catch (error) {
14
+ logError(error?.message || "Unable to read codeproof.config.json.");
15
+ process.exit(1);
16
+ }
17
+
18
+ if (current === "disabled") {
19
+ logWarn("CodeProof enforcement is already disabled.");
20
+ return;
21
+ }
22
+
23
+ try {
24
+ setEnforcementState(gitRoot, "disabled");
25
+ } catch (error) {
26
+ logError(error?.message || "Unable to update codeproof.config.json.");
27
+ process.exit(1);
28
+ }
29
+
30
+ logSuccess("CodeProof enforcement disabled.");
31
+ logInfo("Commits will not be blocked until `codeproof apply` is run.");
32
+ }
package/commands/init.js CHANGED
@@ -1,107 +1,107 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import { ensureGitRepo, getGitRoot } from "../utils/git.js";
4
- import { logInfo, logSuccess, logWarn } from "../utils/logger.js";
5
- import { detectProjectType } from "../utils/projectType.js";
6
- import { installPreCommitHook } from "../hooks/preCommit.js";
7
- import { showWelcomeScreen } from "../ui/welcomeScreen.js";
8
- import { getClientId } from "../core/identity.js";
9
- import { randomUUID } from "crypto";
10
-
11
-
12
-
13
- export async function runInit({ cwd }) {
14
- logInfo("Initializing CodeProof...");
15
-
16
- getClientId();
17
-
18
- ensureGitRepo(cwd);
19
- logSuccess("Git repository detected.");
20
-
21
- const gitRoot = getGitRoot(cwd);
22
- logInfo(`Project root: ${gitRoot}`);
23
-
24
- const projectType = detectProjectType(gitRoot);
25
- logInfo(`Detected project type: ${projectType}`);
26
-
27
- const configPath = path.join(gitRoot, "codeproof.config.json");
28
- // Avoid overwriting user configuration to keep init idempotent.
29
- if (fs.existsSync(configPath)) {
30
- let updated = false;
31
- try {
32
- const raw = fs.readFileSync(configPath, "utf8");
33
- const existing = JSON.parse(raw);
34
- if (!existing.projectId) {
35
- existing.projectId = randomUUID();
36
- updated = true;
37
- fs.writeFileSync(configPath, JSON.stringify(existing, null, 2) + "\n", "utf8");
38
- }
39
- } catch {
40
- logWarn("Config already exists but could not be updated.");
41
- }
42
-
43
- if (updated) {
44
- logSuccess("Added projectId to codeproof.config.json");
45
- } else {
46
- logWarn("Config already exists. Skipping creation.");
47
- }
48
- } else {
49
- const config = {
50
- projectId: randomUUID(),
51
- projectType,
52
- scanMode: "staged",
53
- enforcement: "enabled",
54
- features: {
55
- reporting: true,
56
- integration: false,
57
- aiEscalation: false,
58
- secretRemediation: false
59
- },
60
- integration: {
61
- enabled: false,
62
- endpointUrl: ""
63
- },
64
- severityRules: {
65
- block: [],
66
- warn: [],
67
- allow: []
68
- }
69
- };
70
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
71
- logSuccess("Created codeproof.config.json");
72
- }
73
-
74
- try {
75
- const raw = fs.readFileSync(configPath, "utf8");
76
- const existing = JSON.parse(raw);
77
- if (!existing.enforcement) {
78
- existing.enforcement = "enabled";
79
- fs.writeFileSync(configPath, JSON.stringify(existing, null, 2) + "\n", "utf8");
80
- logSuccess("Added enforcement=enabled to codeproof.config.json");
81
- }
82
- } catch {
83
- logWarn("Unable to update enforcement in codeproof.config.json.");
84
- }
85
-
86
- installPreCommitHook(gitRoot);
87
- logSuccess("Pre-commit hook installed.");
88
-
89
- logSuccess("CodeProof initialization complete.");
90
-
91
- let scanMode = "staged";
92
- try {
93
- const configRaw = fs.readFileSync(configPath, "utf8");
94
- const parsed = JSON.parse(configRaw);
95
- if (parsed?.scanMode) {
96
- scanMode = String(parsed.scanMode).toLowerCase();
97
- }
98
- } catch {
99
- // UX: welcome message should never fail init; fall back to defaults for display.
100
- }
101
-
102
- showWelcomeScreen({
103
- projectType,
104
- scanMode,
105
- configPath
106
- });
1
+ import path from "path";
2
+ import fs from "fs";
3
+ import { ensureGitRepo, getGitRoot } from "../utils/git.js";
4
+ import { logInfo, logSuccess, logWarn } from "../utils/logger.js";
5
+ import { detectProjectType } from "../utils/projectType.js";
6
+ import { installPreCommitHook } from "../hooks/preCommit.js";
7
+ import { showWelcomeScreen } from "../ui/welcomeScreen.js";
8
+ import { getClientId } from "../core/identity.js";
9
+ import { randomUUID } from "crypto";
10
+
11
+
12
+
13
+ export async function runInit({ cwd }) {
14
+ logInfo("Initializing CodeProof...");
15
+
16
+ getClientId();
17
+
18
+ ensureGitRepo(cwd);
19
+ logSuccess("Git repository detected.");
20
+
21
+ const gitRoot = getGitRoot(cwd);
22
+ logInfo(`Project root: ${gitRoot}`);
23
+
24
+ const projectType = detectProjectType(gitRoot);
25
+ logInfo(`Detected project type: ${projectType}`);
26
+
27
+ const configPath = path.join(gitRoot, "codeproof.config.json");
28
+ // Avoid overwriting user configuration to keep init idempotent.
29
+ if (fs.existsSync(configPath)) {
30
+ let updated = false;
31
+ try {
32
+ const raw = fs.readFileSync(configPath, "utf8");
33
+ const existing = JSON.parse(raw);
34
+ if (!existing.projectId) {
35
+ existing.projectId = randomUUID();
36
+ updated = true;
37
+ fs.writeFileSync(configPath, JSON.stringify(existing, null, 2) + "\n", "utf8");
38
+ }
39
+ } catch {
40
+ logWarn("Config already exists but could not be updated.");
41
+ }
42
+
43
+ if (updated) {
44
+ logSuccess("Added projectId to codeproof.config.json");
45
+ } else {
46
+ logWarn("Config already exists. Skipping creation.");
47
+ }
48
+ } else {
49
+ const config = {
50
+ projectId: randomUUID(),
51
+ projectType,
52
+ scanMode: "staged",
53
+ enforcement: "enabled",
54
+ features: {
55
+ reporting: true,
56
+ integration: false,
57
+ aiEscalation: false,
58
+ secretRemediation: false
59
+ },
60
+ integration: {
61
+ enabled: false,
62
+ endpointUrl: ""
63
+ },
64
+ severityRules: {
65
+ block: [],
66
+ warn: [],
67
+ allow: []
68
+ }
69
+ };
70
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n", "utf8");
71
+ logSuccess("Created codeproof.config.json");
72
+ }
73
+
74
+ try {
75
+ const raw = fs.readFileSync(configPath, "utf8");
76
+ const existing = JSON.parse(raw);
77
+ if (!existing.enforcement) {
78
+ existing.enforcement = "enabled";
79
+ fs.writeFileSync(configPath, JSON.stringify(existing, null, 2) + "\n", "utf8");
80
+ logSuccess("Added enforcement=enabled to codeproof.config.json");
81
+ }
82
+ } catch {
83
+ logWarn("Unable to update enforcement in codeproof.config.json.");
84
+ }
85
+
86
+ installPreCommitHook(gitRoot);
87
+ logSuccess("Pre-commit hook installed.");
88
+
89
+ logSuccess("CodeProof initialization complete.");
90
+
91
+ let scanMode = "staged";
92
+ try {
93
+ const configRaw = fs.readFileSync(configPath, "utf8");
94
+ const parsed = JSON.parse(configRaw);
95
+ if (parsed?.scanMode) {
96
+ scanMode = String(parsed.scanMode).toLowerCase();
97
+ }
98
+ } catch {
99
+ // UX: welcome message should never fail init; fall back to defaults for display.
100
+ }
101
+
102
+ showWelcomeScreen({
103
+ projectType,
104
+ scanMode,
105
+ configPath
106
+ });
107
107
  }