feat(cli): add --debug/-d flag for CLI debugging

- Add -d/--debug option to ccw cli command
- Enable debug logging at runtime when flag is set
- Change DEBUG check from const to function for runtime evaluation
- Support debug mode for both exec and status subcommands
- Update help text to include --debug option

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
catlog22
2025-12-29 23:26:48 +08:00
parent 6efc499c77
commit f566b8aabc
5 changed files with 27 additions and 10 deletions

View File

@@ -171,6 +171,7 @@ export function run(argv: string[]): void {
.option('-f, --file <file>', 'Read prompt from file (best for multi-line prompts)') .option('-f, --file <file>', 'Read prompt from file (best for multi-line prompts)')
.option('--tool <tool>', 'CLI tool to use', 'gemini') .option('--tool <tool>', 'CLI tool to use', 'gemini')
.option('--mode <mode>', 'Execution mode: analysis, write, auto', 'analysis') .option('--mode <mode>', 'Execution mode: analysis, write, auto', 'analysis')
.option('-d, --debug', 'Enable debug logging for troubleshooting')
.option('--model <model>', 'Model override') .option('--model <model>', 'Model override')
.option('--cd <path>', 'Working directory') .option('--cd <path>', 'Working directory')
.option('--includeDirs <dirs>', 'Additional directories (--include-directories for gemini/qwen, --add-dir for codex/claude)') .option('--includeDirs <dirs>', 'Additional directories (--include-directories for gemini/qwen, --add-dir for codex/claude)')

View File

@@ -81,6 +81,7 @@ interface CliExecOptions {
noNative?: boolean; // Force prompt concatenation instead of native resume noNative?: boolean; // Force prompt concatenation instead of native resume
cache?: string | boolean; // Cache: true = auto from CONTEXT, string = comma-separated patterns/content cache?: string | boolean; // Cache: true = auto from CONTEXT, string = comma-separated patterns/content
injectMode?: 'none' | 'full' | 'progressive'; // Inject mode for cached content injectMode?: 'none' | 'full' | 'progressive'; // Inject mode for cached content
debug?: boolean; // Enable debug logging
} }
/** Cache configuration parsed from --cache */ /** Cache configuration parsed from --cache */
@@ -457,7 +458,13 @@ function testParseAction(args: string[], options: CliExecOptions): void {
/** /**
* Show CLI tool status * Show CLI tool status
*/ */
async function statusAction(): Promise<void> { async function statusAction(debug?: boolean): Promise<void> {
// Enable debug mode if --debug flag is set
if (debug) {
process.env.DEBUG = 'true';
console.log(chalk.yellow(' Debug mode enabled\n'));
}
console.log(chalk.bold.cyan('\n CLI Tools Status\n')); console.log(chalk.bold.cyan('\n CLI Tools Status\n'));
const status = await getCliToolsStatus(); const status = await getCliToolsStatus();
@@ -481,7 +488,13 @@ async function statusAction(): Promise<void> {
* @param {Object} options - CLI options * @param {Object} options - CLI options
*/ */
async function execAction(positionalPrompt: string | undefined, options: CliExecOptions): Promise<void> { async function execAction(positionalPrompt: string | undefined, options: CliExecOptions): Promise<void> {
const { prompt: optionPrompt, file, tool = 'gemini', mode = 'analysis', model, cd, includeDirs, timeout, stream, resume, id, noNative, cache, injectMode } = options; const { prompt: optionPrompt, file, tool = 'gemini', mode = 'analysis', model, cd, includeDirs, timeout, stream, resume, id, noNative, cache, injectMode, debug } = options;
// Enable debug mode if --debug flag is set
if (debug) {
process.env.DEBUG = 'true';
console.log(chalk.yellow(' Debug mode enabled\n'));
}
// Priority: 1. --file, 2. --prompt/-p option, 3. positional argument // Priority: 1. --file, 2. --prompt/-p option, 3. positional argument
let finalPrompt: string | undefined; let finalPrompt: string | undefined;
@@ -957,7 +970,7 @@ export async function cliCommand(
switch (subcommand) { switch (subcommand) {
case 'status': case 'status':
await statusAction(); await statusAction((options as CliExecOptions).debug);
break; break;
case 'history': case 'history':
@@ -1014,6 +1027,7 @@ export async function cliCommand(
console.log(chalk.gray(' -f, --file <file> Read prompt from file')); console.log(chalk.gray(' -f, --file <file> Read prompt from file'));
console.log(chalk.gray(' --tool <tool> Tool: gemini, qwen, codex (default: gemini)')); console.log(chalk.gray(' --tool <tool> Tool: gemini, qwen, codex (default: gemini)'));
console.log(chalk.gray(' --mode <mode> Mode: analysis, write, auto (default: analysis)')); console.log(chalk.gray(' --mode <mode> Mode: analysis, write, auto (default: analysis)'));
console.log(chalk.gray(' -d, --debug Enable debug logging for troubleshooting'));
console.log(chalk.gray(' --model <model> Model override')); console.log(chalk.gray(' --model <model> Model override'));
console.log(chalk.gray(' --cd <path> Working directory')); console.log(chalk.gray(' --cd <path> Working directory'));
console.log(chalk.gray(' --includeDirs <dirs> Additional directories')); console.log(chalk.gray(' --includeDirs <dirs> Additional directories'));

View File

@@ -10,11 +10,13 @@ import { spawn, ChildProcess } from 'child_process';
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, readdirSync, statSync } from 'fs'; import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, readdirSync, statSync } from 'fs';
import { join, relative } from 'path'; import { join, relative } from 'path';
// Debug logging utility // Debug logging utility - check env at runtime for --debug flag support
const DEBUG = process.env.DEBUG === 'true' || process.env.DEBUG === '1' || process.env.CCW_DEBUG === 'true'; function isDebugEnabled(): boolean {
return process.env.DEBUG === 'true' || process.env.DEBUG === '1' || process.env.CCW_DEBUG === 'true';
}
function debugLog(category: string, message: string, data?: Record<string, unknown>): void { function debugLog(category: string, message: string, data?: Record<string, unknown>): void {
if (!DEBUG) return; if (!isDebugEnabled()) return;
const timestamp = new Date().toISOString(); const timestamp = new Date().toISOString();
const prefix = `[${timestamp}] [CLI-DEBUG] [${category}]`; const prefix = `[${timestamp}] [CLI-DEBUG] [${category}]`;
if (data) { if (data) {
@@ -30,7 +32,7 @@ function errorLog(category: string, message: string, error?: Error | unknown, co
console.error(`${prefix} ${message}`); console.error(`${prefix} ${message}`);
if (error instanceof Error) { if (error instanceof Error) {
console.error(`${prefix} Error: ${error.message}`); console.error(`${prefix} Error: ${error.message}`);
if (DEBUG && error.stack) { if (isDebugEnabled() && error.stack) {
console.error(`${prefix} Stack: ${error.stack}`); console.error(`${prefix} Stack: ${error.stack}`);
} }
} else if (error) { } else if (error) {

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "claude-code-workflow", "name": "claude-code-workflow",
"version": "6.3.15", "version": "6.3.16",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "claude-code-workflow", "name": "claude-code-workflow",
"version": "6.3.15", "version": "6.3.16",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@modelcontextprotocol/sdk": "^1.0.4", "@modelcontextprotocol/sdk": "^1.0.4",

View File

@@ -1,6 +1,6 @@
{ {
"name": "claude-code-workflow", "name": "claude-code-workflow",
"version": "6.3.15", "version": "6.3.16",
"description": "JSON-driven multi-agent development framework with intelligent CLI orchestration (Gemini/Qwen/Codex), context-first architecture, and automated workflow execution", "description": "JSON-driven multi-agent development framework with intelligent CLI orchestration (Gemini/Qwen/Codex), context-first architecture, and automated workflow execution",
"type": "module", "type": "module",
"main": "ccw/src/index.js", "main": "ccw/src/index.js",