@@ -6,7 +6,7 @@ const HOOK_MARKER = '# codeant-push-protection';
66const HOOK_MARKER_END = '# end-codeant-push-protection' ;
77
88/**
9- * Build the full pre-push hook script (with shebang).
9+ * Build the full pre-commit hook script (with shebang).
1010 */
1111function buildHookScript ( cliPath ) {
1212 return `#!/bin/sh
@@ -21,27 +21,28 @@ ${buildHookBlock(cliPath)}
2121 */
2222function buildHookBlock ( cliPath ) {
2323 if ( cliPath ) {
24+ const quotedCliPath = `'${ cliPath . replace ( / ' / g, "'\\''" ) } '` ;
2425 return `${ HOOK_MARKER }
25- # Auto-installed by CodeAnt AI — blocks pushes containing secrets.
26+ # Auto-installed by CodeAnt AI — blocks commits containing secrets.
2627# To disable: delete this hook or run "codeant push-protection disable"
2728# Uses the CLI bundled with the VS Code extension.
2829# Reopen stdin from terminal so the CLI can show an interactive bypass prompt.
29- # In non-interactive environments (CI), this silently fails and the push is blocked.
30+ # In non-interactive environments (CI), this silently fails and the commit is blocked.
3031exec < /dev/tty 2>/dev/null || true
31- if [ -f " ${ cliPath } " ] && command -v node >/dev/null 2>&1; then
32- node " ${ cliPath } " secrets --committed --hook
32+ if [ -f ${ quotedCliPath } ] && command -v node >/dev/null 2>&1; then
33+ node ${ quotedCliPath } secrets --staged --hook
3334else
3435 command -v codeant >/dev/null 2>&1 || exit 0
35- codeant secrets --committed --hook
36+ codeant secrets --staged --hook
3637fi
3738${ HOOK_MARKER_END } `;
3839 }
3940 return `${ HOOK_MARKER }
40- # Auto-installed by CodeAnt AI — blocks pushes containing secrets.
41+ # Auto-installed by CodeAnt AI — blocks commits containing secrets.
4142# To disable: delete this hook or run "codeant push-protection disable"
4243exec < /dev/tty 2>/dev/null || true
4344command -v codeant >/dev/null 2>&1 || exit 0
44- codeant secrets --committed --hook
45+ codeant secrets --staged --hook
4546${ HOOK_MARKER_END } `;
4647}
4748
@@ -97,7 +98,7 @@ function getHooksDir(gitRoot) {
9798}
9899
99100/**
100- * Install a pre-push hook that runs secret scanning before push .
101+ * Install a pre-commit hook that runs secret scanning before commit .
101102 *
102103 * @param {string } workspacePath - Path to the git repository
103104 * @param {string } [cliPath] - Absolute path to the codeant CLI entry point (from extension node_modules)
@@ -113,7 +114,7 @@ export function installPushProtectionHook(workspacePath, cliPath) {
113114 if ( ! existsSync ( hooksDir ) ) {
114115 mkdirSync ( hooksDir , { recursive : true } ) ;
115116 }
116- const hookPath = path . join ( hooksDir , 'pre-push ' ) ;
117+ const hookPath = path . join ( hooksDir , 'pre-commit ' ) ;
117118
118119 // If hook already exists, check if it's ours
119120 if ( existsSync ( hookPath ) ) {
@@ -127,14 +128,14 @@ export function installPushProtectionHook(workspacePath, cliPath) {
127128 }
128129 // There's a user-managed hook — append only for shell hooks to avoid breaking non-shell scripts
129130 const firstLine = existing . split ( '\n' , 1 ) [ 0 ] || '' ;
130- const isShellHook = firstLine . startsWith ( '#!' ) ? / \/ ( b a | z | k ) ? s h ( \s | $ ) / . test ( firstLine ) : true ;
131+ const isShellHook = firstLine . startsWith ( '#!' ) ? / ^ # ! \s * (?: \/ \S * \/ | \/ u s r \/ b i n \/ e n v \s + (?: - S \s + ) ? ) ( b a | z | k ) ? s h ( \s | $ ) / . test ( firstLine ) : true ;
131132 if ( ! isShellHook ) {
132- return { installed : false , hookPath, message : 'Existing pre-push hook is non-shell; cannot append CodeAnt block safely' } ;
133+ return { installed : false , hookPath, message : 'Existing pre-commit hook is non-shell; cannot append CodeAnt block safely' } ;
133134 }
134135 const appended = existing . trimEnd ( ) + '\n\n' + buildHookBlock ( cliPath ) + '\n' ;
135136 writeFileSync ( hookPath , appended , 'utf-8' ) ;
136137 chmodSync ( hookPath , 0o755 ) ;
137- return { installed : true , hookPath, message : 'Hook appended to existing pre-push ' } ;
138+ return { installed : true , hookPath, message : 'Hook appended to existing pre-commit ' } ;
138139 }
139140
140141 writeFileSync ( hookPath , buildHookScript ( cliPath ) , 'utf-8' ) ;
@@ -143,7 +144,7 @@ export function installPushProtectionHook(workspacePath, cliPath) {
143144}
144145
145146/**
146- * Remove the CodeAnt pre-push hook (or just our section if appended).
147+ * Remove the CodeAnt pre-commit hook (or just our section if appended).
147148 *
148149 * @param {string } workspacePath
149150 * @returns {{ removed: boolean, message: string } }
@@ -155,10 +156,10 @@ export function removePushProtectionHook(workspacePath) {
155156 }
156157
157158 const hooksDir = getHooksDir ( gitRoot ) ;
158- const hookPath = path . join ( hooksDir , 'pre-push ' ) ;
159+ const hookPath = path . join ( hooksDir , 'pre-commit ' ) ;
159160
160161 if ( ! existsSync ( hookPath ) ) {
161- return { removed : false , message : 'No pre-push hook found' } ;
162+ return { removed : false , message : 'No pre-commit hook found' } ;
162163 }
163164
164165 const content = readFileSync ( hookPath , 'utf-8' ) ;
0 commit comments