codeant-cli 0.5.5 → 0.5.6
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/package.json
CHANGED
|
@@ -343,7 +343,7 @@ function BypassPrompt({ secrets, onSelect }) {
|
|
|
343
343
|
{ label: "It's used in tests", value: 'used_in_tests' },
|
|
344
344
|
{ label: "I'll fix it later", value: 'fix_later' },
|
|
345
345
|
{ label: 'Other (type your reason)', value: 'other' },
|
|
346
|
-
{ label: 'Cancel \u2014 block this
|
|
346
|
+
{ label: 'Cancel \u2014 block this commit', value: 'cancel' },
|
|
347
347
|
];
|
|
348
348
|
|
|
349
349
|
useInput((input, key) => {
|
package/src/index.js
CHANGED
|
@@ -72,7 +72,7 @@ program
|
|
|
72
72
|
.option('--base-commit <commit>', 'Compare against a specific commit (e.g. --base-commit HEAD~3)')
|
|
73
73
|
.option('--include <paths>', 'Comma-separated list of file paths glob patterns to include')
|
|
74
74
|
.option('--exclude <paths>', 'Comma-separated list of file paths glob patterns to exclude')
|
|
75
|
-
.option('--hook', 'Running from pre-
|
|
75
|
+
.option('--hook', 'Running from pre-commit hook (enables bypass prompt)')
|
|
76
76
|
.action((options) => {
|
|
77
77
|
let scanType = 'all';
|
|
78
78
|
let lastNCommits = 1;
|
|
@@ -6,7 +6,7 @@ const HOOK_MARKER = '# codeant-push-protection';
|
|
|
6
6
|
const HOOK_MARKER_END = '# end-codeant-push-protection';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Build the full pre-
|
|
9
|
+
* Build the full pre-commit hook script (with shebang).
|
|
10
10
|
*/
|
|
11
11
|
function buildHookScript(cliPath) {
|
|
12
12
|
return `#!/bin/sh
|
|
@@ -21,27 +21,28 @@ ${buildHookBlock(cliPath)}
|
|
|
21
21
|
*/
|
|
22
22
|
function buildHookBlock(cliPath) {
|
|
23
23
|
if (cliPath) {
|
|
24
|
+
const quotedCliPath = `'${cliPath.replace(/'/g, "'\\''")}'`;
|
|
24
25
|
return `${HOOK_MARKER}
|
|
25
|
-
# Auto-installed by CodeAnt AI — blocks
|
|
26
|
+
# Auto-installed by CodeAnt AI — blocks commits containing secrets.
|
|
26
27
|
# To disable: delete this hook or run "codeant push-protection disable"
|
|
27
28
|
# Uses the CLI bundled with the VS Code extension.
|
|
28
29
|
# Reopen stdin from terminal so the CLI can show an interactive bypass prompt.
|
|
29
|
-
# In non-interactive environments (CI), this silently fails and the
|
|
30
|
+
# In non-interactive environments (CI), this silently fails and the commit is blocked.
|
|
30
31
|
exec < /dev/tty 2>/dev/null || true
|
|
31
|
-
if [ -f
|
|
32
|
-
node
|
|
32
|
+
if [ -f ${quotedCliPath} ] && command -v node >/dev/null 2>&1; then
|
|
33
|
+
node ${quotedCliPath} secrets --staged --hook
|
|
33
34
|
else
|
|
34
35
|
command -v codeant >/dev/null 2>&1 || exit 0
|
|
35
|
-
codeant secrets --
|
|
36
|
+
codeant secrets --staged --hook
|
|
36
37
|
fi
|
|
37
38
|
${HOOK_MARKER_END}`;
|
|
38
39
|
}
|
|
39
40
|
return `${HOOK_MARKER}
|
|
40
|
-
# Auto-installed by CodeAnt AI — blocks
|
|
41
|
+
# Auto-installed by CodeAnt AI — blocks commits containing secrets.
|
|
41
42
|
# To disable: delete this hook or run "codeant push-protection disable"
|
|
42
43
|
exec < /dev/tty 2>/dev/null || true
|
|
43
44
|
command -v codeant >/dev/null 2>&1 || exit 0
|
|
44
|
-
codeant secrets --
|
|
45
|
+
codeant secrets --staged --hook
|
|
45
46
|
${HOOK_MARKER_END}`;
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -97,7 +98,7 @@ function getHooksDir(gitRoot) {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
|
-
* Install a pre-
|
|
101
|
+
* Install a pre-commit hook that runs secret scanning before commit.
|
|
101
102
|
*
|
|
102
103
|
* @param {string} workspacePath - Path to the git repository
|
|
103
104
|
* @param {string} [cliPath] - Absolute path to the codeant CLI entry point (from extension node_modules)
|
|
@@ -113,7 +114,7 @@ export function installPushProtectionHook(workspacePath, cliPath) {
|
|
|
113
114
|
if (!existsSync(hooksDir)) {
|
|
114
115
|
mkdirSync(hooksDir, { recursive: true });
|
|
115
116
|
}
|
|
116
|
-
const hookPath = path.join(hooksDir, 'pre-
|
|
117
|
+
const hookPath = path.join(hooksDir, 'pre-commit');
|
|
117
118
|
|
|
118
119
|
// If hook already exists, check if it's ours
|
|
119
120
|
if (existsSync(hookPath)) {
|
|
@@ -127,14 +128,14 @@ export function installPushProtectionHook(workspacePath, cliPath) {
|
|
|
127
128
|
}
|
|
128
129
|
// There's a user-managed hook — append only for shell hooks to avoid breaking non-shell scripts
|
|
129
130
|
const firstLine = existing.split('\n', 1)[0] || '';
|
|
130
|
-
const isShellHook = firstLine.startsWith('#!') ?
|
|
131
|
+
const isShellHook = firstLine.startsWith('#!') ? /^#!\s*(?:\/\S*\/|\/usr\/bin\/env\s+(?:-S\s+)?)(ba|z|k)?sh(\s|$)/.test(firstLine) : true;
|
|
131
132
|
if (!isShellHook) {
|
|
132
|
-
return { installed: false, hookPath, message: 'Existing pre-
|
|
133
|
+
return { installed: false, hookPath, message: 'Existing pre-commit hook is non-shell; cannot append CodeAnt block safely' };
|
|
133
134
|
}
|
|
134
135
|
const appended = existing.trimEnd() + '\n\n' + buildHookBlock(cliPath) + '\n';
|
|
135
136
|
writeFileSync(hookPath, appended, 'utf-8');
|
|
136
137
|
chmodSync(hookPath, 0o755);
|
|
137
|
-
return { installed: true, hookPath, message: 'Hook appended to existing pre-
|
|
138
|
+
return { installed: true, hookPath, message: 'Hook appended to existing pre-commit' };
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
writeFileSync(hookPath, buildHookScript(cliPath), 'utf-8');
|
|
@@ -143,7 +144,7 @@ export function installPushProtectionHook(workspacePath, cliPath) {
|
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
/**
|
|
146
|
-
* Remove the CodeAnt pre-
|
|
147
|
+
* Remove the CodeAnt pre-commit hook (or just our section if appended).
|
|
147
148
|
*
|
|
148
149
|
* @param {string} workspacePath
|
|
149
150
|
* @returns {{ removed: boolean, message: string }}
|
|
@@ -155,10 +156,10 @@ export function removePushProtectionHook(workspacePath) {
|
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
const hooksDir = getHooksDir(gitRoot);
|
|
158
|
-
const hookPath = path.join(hooksDir, 'pre-
|
|
159
|
+
const hookPath = path.join(hooksDir, 'pre-commit');
|
|
159
160
|
|
|
160
161
|
if (!existsSync(hookPath)) {
|
|
161
|
-
return { removed: false, message: 'No pre-
|
|
162
|
+
return { removed: false, message: 'No pre-commit hook found' };
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
const content = readFileSync(hookPath, 'utf-8');
|