Skip to content

Commit cd9b4b2

Browse files
committed
feat(cli): додано детальне логування до detection та execution процесів
1 parent 35210c2 commit cd9b4b2

3 files changed

Lines changed: 56 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,40 @@ The extension uses intelligent auto-detection to find Claude CLI **at runtime**
274274
### Extension not working
275275

276276
1. Check you're in a Git repository
277-
2. Open Output panel (View → Output)
278-
3. Look for error messages from the extension
277+
2. **Open Output panel** (View → Output) and select **"Claude Commit"** from the dropdown
278+
3. Look for detailed log messages showing:
279+
- Where the extension is searching for Claude CLI
280+
- What command is being executed
281+
- What output (if any) is received from Claude
279282
4. Try generating a commit message manually via Command Palette:
280283
- Press `Cmd+Shift+P` (or `Ctrl+Shift+P`)
281284
- Type "Claude Commit: Generate"
282285
5. If CLI path is incorrect, clear `claudeCommit.cliPath` in settings to trigger re-detection
283286

287+
### "Empty response from CLI" error
288+
289+
This error means Claude CLI was found but didn't return any output. **Check the Output panel** (select "Claude Commit") for details:
290+
291+
1. **CLI Path**: Verify the detected path is correct
292+
- Look for "Found Claude CLI at: ..." in the logs
293+
- Test the path manually: run `<path> --version` in terminal
294+
295+
2. **Authentication**: Ensure Claude CLI is authenticated
296+
```bash
297+
claude --version
298+
# Should show version without errors
299+
```
300+
301+
3. **Command Execution**: Check the exact command being run
302+
- Look for "Executing: ..." in the logs
303+
- The command should pipe your changes to Claude CLI
304+
305+
4. **Common causes**:
306+
- **Not authenticated**: Run `claude` in terminal to authenticate
307+
- **Network issues**: Check your internet connection
308+
- **Permissions**: Try setting `claudeCommit.privacyMode: false`
309+
- **Corrupted install**: Reinstall Claude CLI (`npm install -g @anthropic-ai/claude-code`)
310+
284311
## Privacy & Security
285312

286313
- Your code changes are processed through Claude CLI or Anthropic API

‎src/cli/detection.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { promisify } from "util";
44
import * as fs from "fs";
55
import * as path from "path";
66
import * as os from "os";
7+
import { log } from "../utils/logger";
78

89
const execAsync = promisify(exec);
910

@@ -79,36 +80,44 @@ export async function findClaudeCliPath(): Promise<string | null> {
7980
const userPath = config.get<string>("cliPath");
8081

8182
if (userPath && userPath.trim()) {
83+
log(`Checking user-configured CLI path: ${userPath}`);
8284
if (await fileExists(userPath)) {
85+
log(`Found CLI at user-configured path: ${userPath}`);
8386
return userPath;
8487
}
8588
throw new Error(`Configured CLI path not found: ${userPath}`);
8689
}
8790

8891
// 2. Check cache
8992
if (cachedCliPath && (await fileExists(cachedCliPath))) {
93+
log(`Using cached CLI path: ${cachedCliPath}`);
9094
return cachedCliPath;
9195
}
9296

97+
log("Searching for Claude CLI...");
98+
9399
// 3. Try which/where
94100
try {
95101
const cmd = process.platform === "win32" ? "where claude" : "which claude";
102+
log(`Trying command: ${cmd}`);
96103
const { stdout } = await execAsync(cmd, {
97104
env: { ...process.env },
98105
shell: process.platform === "win32" ? "cmd.exe" : "/bin/bash",
99106
});
100107
const foundPath = stdout.trim().split("\n")[0];
101108
if (foundPath && (await fileExists(foundPath))) {
109+
log(`Found CLI via ${cmd}: ${foundPath}`);
102110
cachedCliPath = foundPath;
103111
return foundPath;
104112
}
105-
} catch {
106-
// which/where not found
113+
} catch (err) {
114+
log(`which/where command failed: ${err instanceof Error ? err.message : String(err)}`);
107115
}
108116

109117
// 4. Try shell profile
110118
if (process.platform !== "win32") {
111119
try {
120+
log("Trying shell profile sourcing...");
112121
const { stdout } = await execAsync(
113122
"source ~/.zshrc 2>/dev/null || source ~/.bashrc 2>/dev/null || true; which claude",
114123
{
@@ -117,24 +126,28 @@ export async function findClaudeCliPath(): Promise<string | null> {
117126
);
118127
const foundPath = stdout.trim();
119128
if (foundPath && (await fileExists(foundPath))) {
129+
log(`Found CLI via shell profile: ${foundPath}`);
120130
cachedCliPath = foundPath;
121131
return foundPath;
122132
}
123-
} catch {
124-
// Failed
133+
} catch (err) {
134+
log(`Shell profile sourcing failed: ${err instanceof Error ? err.message : String(err)}`);
125135
}
126136
}
127137

128138
// 5. Check common paths
139+
log("Checking common installation paths...");
129140
const commonPaths = getCommonCliPaths();
130141
for (const p of commonPaths) {
131142
const found = await findCliWithGlob(p);
132143
if (found) {
144+
log(`Found CLI at common path: ${found}`);
133145
cachedCliPath = found;
134146
return found;
135147
}
136148
}
137149

150+
log("Claude CLI not found in any location");
138151
return null;
139152
}
140153

‎src/cli/execution.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export async function generateWithCLI(
2020
throw new Error("Claude CLI path not found");
2121
}
2222

23+
log(`Found Claude CLI at: ${cliPath}`);
2324
const escapedCliPath = cliPath.includes(" ") ? `"${cliPath}"` : cliPath;
2425

2526
const config = vscode.workspace.getConfiguration("claudeCommit");
@@ -60,19 +61,27 @@ export async function generateWithCLI(
6061
}
6162
if (stdout) {
6263
log(`CLI stdout (first 500 chars): ${stdout.substring(0, 500)}`);
64+
} else {
65+
log("CLI stdout is empty");
6366
}
6467

6568
if (stderr && !stdout) {
6669
throw new Error(`CLI error output: ${stderr.trim()}`);
6770
}
6871

72+
if (!stdout || stdout.trim().length === 0) {
73+
logError("Empty response from CLI", new Error(`Command: ${command}, stderr: ${stderr || 'none'}`));
74+
throw new Error("Empty response from CLI. Check Output panel for details.");
75+
}
76+
6977
const lines = stdout
7078
.split("\n")
7179
.map((line) => line.trim())
7280
.filter((line) => line.length > 0);
7381

7482
if (lines.length === 0) {
75-
throw new Error("Empty response from CLI");
83+
logError("No valid lines in CLI output", new Error(`stdout: ${stdout}`));
84+
throw new Error("Empty response from CLI. Check Output panel for details.");
7685
}
7786

7887
const multiLine = config.get<boolean>("multiLineCommit", false);

0 commit comments

Comments
 (0)