codeant-cli 0.4.0 → 0.4.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeant-cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Code review CLI tool",
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,16 +8,31 @@ const HOOK_MARKER_END = '# end-codeant-push-protection';
8
8
  /**
9
9
  * Build the full pre-push hook script (with shebang).
10
10
  */
11
- function buildHookScript() {
11
+ function buildHookScript(cliPath) {
12
12
  return `#!/bin/sh
13
- ${buildHookBlock()}
13
+ ${buildHookBlock(cliPath)}
14
14
  `;
15
15
  }
16
16
 
17
17
  /**
18
18
  * Build just the CodeAnt block (no shebang), used when appending to an existing hook.
19
+ * If cliPath is provided, uses the absolute path to the extension-bundled CLI via node.
20
+ * Otherwise falls back to the global `codeant` command.
19
21
  */
20
- function buildHookBlock() {
22
+ function buildHookBlock(cliPath) {
23
+ if (cliPath) {
24
+ return `${HOOK_MARKER}
25
+ # Auto-installed by CodeAnt AI — blocks pushes containing secrets.
26
+ # To disable: delete this hook or run "codeant push-protection disable"
27
+ # Uses the CLI bundled with the VS Code extension.
28
+ if [ -f "${cliPath}" ]; then
29
+ node "${cliPath}" secrets --committed --hook
30
+ else
31
+ command -v codeant >/dev/null 2>&1 || exit 0
32
+ codeant secrets --committed --hook
33
+ fi
34
+ ${HOOK_MARKER_END}`;
35
+ }
21
36
  return `${HOOK_MARKER}
22
37
  # Auto-installed by CodeAnt AI — blocks pushes containing secrets.
23
38
  # To disable: delete this hook or run "codeant push-protection disable"
@@ -81,9 +96,10 @@ function getHooksDir(gitRoot) {
81
96
  * Install a pre-push hook that runs secret scanning before push.
82
97
  *
83
98
  * @param {string} workspacePath - Path to the git repository
99
+ * @param {string} [cliPath] - Absolute path to the codeant CLI entry point (from extension node_modules)
84
100
  * @returns {{ installed: boolean, hookPath: string|null, message: string }}
85
101
  */
86
- export function installPushProtectionHook(workspacePath) {
102
+ export function installPushProtectionHook(workspacePath, cliPath) {
87
103
  const gitRoot = findGitRoot(workspacePath);
88
104
  if (!gitRoot) {
89
105
  return { installed: false, hookPath: null, message: 'Not a git repository' };
@@ -100,7 +116,7 @@ export function installPushProtectionHook(workspacePath) {
100
116
  const existing = readFileSync(hookPath, 'utf-8');
101
117
  if (existing.includes(HOOK_MARKER)) {
102
118
  // Replace only our block, preserve everything else
103
- const updated = replaceCodeAntBlock(existing, buildHookBlock());
119
+ const updated = replaceCodeAntBlock(existing, buildHookBlock(cliPath));
104
120
  writeFileSync(hookPath, updated, 'utf-8');
105
121
  chmodSync(hookPath, 0o755);
106
122
  return { installed: true, hookPath, message: 'Hook updated' };
@@ -111,13 +127,13 @@ export function installPushProtectionHook(workspacePath) {
111
127
  if (!isShellHook) {
112
128
  return { installed: false, hookPath, message: 'Existing pre-push hook is non-shell; cannot append CodeAnt block safely' };
113
129
  }
114
- const appended = existing.trimEnd() + '\n\n' + buildHookBlock() + '\n';
130
+ const appended = existing.trimEnd() + '\n\n' + buildHookBlock(cliPath) + '\n';
115
131
  writeFileSync(hookPath, appended, 'utf-8');
116
132
  chmodSync(hookPath, 0o755);
117
133
  return { installed: true, hookPath, message: 'Hook appended to existing pre-push' };
118
134
  }
119
135
 
120
- writeFileSync(hookPath, buildHookScript(), 'utf-8');
136
+ writeFileSync(hookPath, buildHookScript(cliPath), 'utf-8');
121
137
  chmodSync(hookPath, 0o755);
122
138
  return { installed: true, hookPath, message: 'Hook installed' };
123
139
  }