@ccdevkit/ccaudit 0.5.0 → 0.5.2

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.
Files changed (2) hide show
  1. package/install.js +108 -0
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -92,6 +92,9 @@ async function install() {
92
92
  }
93
93
 
94
94
  console.warn(`Installed ccaudit to ${binaryPath}`);
95
+
96
+ // Set up shell completions
97
+ setupShellCompletions(binaryPath);
95
98
  } catch (error) {
96
99
  console.error(`Failed to install ccaudit: ${error.message}`);
97
100
  console.error('');
@@ -101,4 +104,109 @@ async function install() {
101
104
  }
102
105
  }
103
106
 
107
+ function setupShellCompletions(binaryPath) {
108
+ // Skip on Windows - PowerShell completions require manual setup
109
+ if (process.platform === 'win32') {
110
+ return;
111
+ }
112
+
113
+ const homedir = require('os').homedir();
114
+ const shell = process.env.SHELL || '';
115
+
116
+ try {
117
+ if (shell.includes('zsh')) {
118
+ setupZshCompletions(binaryPath, homedir);
119
+ } else if (shell.includes('bash')) {
120
+ setupBashCompletions(binaryPath, homedir);
121
+ } else if (shell.includes('fish')) {
122
+ setupFishCompletions(binaryPath, homedir);
123
+ }
124
+ } catch (err) {
125
+ // Non-fatal - completions are a nice-to-have
126
+ console.warn(`Note: Could not set up shell completions: ${err.message}`);
127
+ }
128
+ }
129
+
130
+ function setupZshCompletions(binaryPath, homedir) {
131
+ const zshCompletionDir = path.join(homedir, '.zsh', 'completions');
132
+ const zshCompletionFile = path.join(zshCompletionDir, '_ccaudit');
133
+ const zshrcPath = path.join(homedir, '.zshrc');
134
+
135
+ // Create completions directory
136
+ if (!fs.existsSync(zshCompletionDir)) {
137
+ fs.mkdirSync(zshCompletionDir, { recursive: true });
138
+ }
139
+
140
+ // Generate and write completion script
141
+ const completionScript = execSync(`"${binaryPath}" completion zsh`, { encoding: 'utf8' });
142
+ fs.writeFileSync(zshCompletionFile, completionScript);
143
+
144
+ // Check if .zshrc already has our fpath setup
145
+ const marker = '# ccaudit completions';
146
+ let zshrcContent = '';
147
+ if (fs.existsSync(zshrcPath)) {
148
+ zshrcContent = fs.readFileSync(zshrcPath, 'utf8');
149
+ }
150
+
151
+ if (!zshrcContent.includes(marker)) {
152
+ // Add fpath and compinit to .zshrc
153
+ // We need to add fpath BEFORE compinit runs, so prepend to file
154
+ const completionSetup = `${marker}
155
+ fpath=(~/.zsh/completions $fpath)
156
+ autoload -Uz compinit && compinit -C
157
+ ${marker} end
158
+
159
+ `;
160
+ fs.writeFileSync(zshrcPath, completionSetup + zshrcContent);
161
+ console.warn('Shell completions installed (restart shell or run: source ~/.zshrc)');
162
+ }
163
+ }
164
+
165
+ function setupBashCompletions(binaryPath, homedir) {
166
+ const bashCompletionDir = path.join(homedir, '.local', 'share', 'bash-completion', 'completions');
167
+ const bashCompletionFile = path.join(bashCompletionDir, 'ccaudit');
168
+ const bashrcPath = path.join(homedir, '.bashrc');
169
+
170
+ // Create completions directory (XDG standard location)
171
+ if (!fs.existsSync(bashCompletionDir)) {
172
+ fs.mkdirSync(bashCompletionDir, { recursive: true });
173
+ }
174
+
175
+ // Generate and write completion script
176
+ const completionScript = execSync(`"${binaryPath}" completion bash`, { encoding: 'utf8' });
177
+ fs.writeFileSync(bashCompletionFile, completionScript);
178
+
179
+ // Check if .bashrc already sources our completion
180
+ const marker = '# ccaudit completions';
181
+ let bashrcContent = '';
182
+ if (fs.existsSync(bashrcPath)) {
183
+ bashrcContent = fs.readFileSync(bashrcPath, 'utf8');
184
+ }
185
+
186
+ if (!bashrcContent.includes(marker)) {
187
+ // Add source line to .bashrc
188
+ const completionSetup = `
189
+ ${marker}
190
+ [ -f "${bashCompletionFile}" ] && source "${bashCompletionFile}"
191
+ ${marker} end
192
+ `;
193
+ fs.appendFileSync(bashrcPath, completionSetup);
194
+ console.warn('Shell completions installed (restart shell or run: source ~/.bashrc)');
195
+ }
196
+ }
197
+
198
+ function setupFishCompletions(binaryPath, homedir) {
199
+ // Fish automatically loads completions from this directory - no rc modification needed
200
+ const fishCompletionDir = path.join(homedir, '.config', 'fish', 'completions');
201
+ const fishCompletionFile = path.join(fishCompletionDir, 'ccaudit.fish');
202
+
203
+ if (!fs.existsSync(fishCompletionDir)) {
204
+ fs.mkdirSync(fishCompletionDir, { recursive: true });
205
+ }
206
+
207
+ const completionScript = execSync(`"${binaryPath}" completion fish`, { encoding: 'utf8' });
208
+ fs.writeFileSync(fishCompletionFile, completionScript);
209
+ // Fish loads these automatically, no message needed
210
+ }
211
+
104
212
  install();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccdevkit/ccaudit",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "Audit tool for Claude Code projects - runs compliance checks on code and agent actions",
5
5
  "bin": {
6
6
  "ccaudit": "bin/ccaudit"