mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
6.9 KiB
6.9 KiB
Init Command Refactoring Plan
Current State
- File:
src/cli/commands/init.ts - Size: ~2,700 lines (TOO LARGE)
- Issues:
- Hard to maintain
- Missing
.claude/settings.jsongeneration - Missing MCP auto-setup
- No bash wrapper for user projects
Target State (Following claude-flow Pattern)
New Structure: src/cli/init/
src/cli/init/
├── index.ts # Main orchestrator (export initCommand function)
├── claude-config.ts # .claude/settings.json + MCP setup
├── directory-structure.ts # Directory creation logic
├── database-init.ts # AgentDB + Memory database initialization
├── documentation.ts # CLAUDE.md template copying
├── agents.ts # Agent template copying
├── fleet-config.ts # Fleet configuration
└── utils.ts # Shared utilities
File Responsibilities
1. index.ts (Main Orchestrator)
export async function initCommand(options: InitOptions): Promise<void> {
// Orchestrate initialization phases
await createDirectoryStructure(options);
await initializeDatabases(options);
await createClaudeConfig(options); // NEW: settings.json + MCP
await copyDocumentation(options); // NEW: CLAUDE.md
await createBashWrapper(options); // NEW: aqe wrapper
await copyAgentTemplates(options);
await createFleetConfig(options);
await displaySummary(options);
}
2. claude-config.ts (CRITICAL - Missing Functionality)
export async function createClaudeConfig(options: InitOptions): Promise<void> {
// Generate/merge .claude/settings.json with AgentDB hooks
await generateClaudeSettings();
// Setup MCP server integration
await setupMCPServer();
}
Functions:
generateClaudeSettings()- Create/merge settings.json with hookssetupMCPServer()- Auto-add MCP viaclaude mcp addmergeHooks()- Merge AQE hooks with existing hooksgetAQEHooks()- Return AQE hook configuration
3. directory-structure.ts
export async function createDirectoryStructure(force: boolean): Promise<void> {
// Create .agentic-qe/, .claude/, tests/ directories
}
4. database-init.ts
export async function initializeDatabases(config: FleetConfig): Promise<void> {
await initializeAgentDB(config);
await initializeMemoryDatabase();
await initializeLearningSystem(config);
}
5. documentation.ts (NEW)
export async function copyDocumentation(): Promise<void> {
await copyCLAUDEMdTemplate();
await generateMinimalClaudeMd(); // Fallback if template not found
}
6. bash-wrapper.ts (NEW)
export async function createBashWrapper(): Promise<void> {
// Create 'aqe' bash wrapper in project root
// Similar to claude-flow wrapper
}
Bash Wrapper Decision
Option 1: Create aqe wrapper (RECOMMENDED)
Pros:
- Ensures commands run from project directory
- Matches claude-flow pattern
- Better UX - users just type
./aqeinstead ofnpx aqe - Handles local vs global installations
Cons:
- Another file in project root
Option 2: Skip bash wrapper
Pros:
- Cleaner project root
- Users already know
npx aqe
Cons:
- Missing parity with claude-flow
- No guarantee of correct working directory
DECISION: Create aqe wrapper for consistency with claude-flow
Implementation Steps
Phase 1: Create Modular Structure (Non-Breaking)
- ✅ Create
src/cli/init/directory - ✅ Create module files with extracted functions
- ✅ Keep old
init.tsfunctional during migration
Phase 2: Extract Functions
- ✅ Move directory creation →
directory-structure.ts - ✅ Move database init →
database-init.ts - ✅ Move agent copying →
agents.ts - ✅ Move fleet config →
fleet-config.ts - ✅ NEW: Create
claude-config.tswith hooks - ✅ NEW: Create
documentation.ts - ✅ NEW: Create
bash-wrapper.ts
Phase 3: Create Orchestrator
- ✅ Create
src/cli/init/index.ts - ✅ Import and sequence all modules
- ✅ Add error handling and logging
Phase 4: Update Entry Point
- ✅ Update
src/cli/commands/init.tsto call new orchestrator - ✅ OR: Update
src/cli/index.tsto import from new location - ✅ Deprecate old command
Phase 5: Test & Verify
- ✅ Test
aqe initin new project - ✅ Verify
.claude/settings.jsoncreated with hooks - ✅ Verify MCP server auto-added
- ✅ Verify
aqebash wrapper created - ✅ Verify CLAUDE.md copied
Files to Create
1. aqe bash wrapper template
Location: templates/aqe.sh
#!/usr/bin/env bash
# AQE local wrapper
# Ensures aqe runs from your project directory
PROJECT_DIR="${PWD}"
export PWD="${PROJECT_DIR}"
export AQE_WORKING_DIR="${PROJECT_DIR}"
# Try to find aqe binary
if [ -f "${PROJECT_DIR}/node_modules/.bin/aqe" ]; then
cd "${PROJECT_DIR}"
exec "${PROJECT_DIR}/node_modules/.bin/aqe" "$@"
elif [ -f "${PROJECT_DIR}/../node_modules/.bin/aqe" ]; then
cd "${PROJECT_DIR}"
exec "${PROJECT_DIR}/../node_modules/.bin/aqe" "$@"
elif command -v aqe &> /dev/null; then
cd "${PROJECT_DIR}"
exec aqe "$@"
else
cd "${PROJECT_DIR}"
exec npx aqe@latest "$@"
fi
Benefits of Refactoring
- Maintainability: ~400 lines per file instead of 2,700
- Testability: Can test each module independently
- Readability: Clear separation of concerns
- Extensibility: Easy to add new init steps
- Parity: Matches claude-flow's proven architecture
- Fixes: Includes missing settings.json + MCP setup
Breaking Changes
NONE - This is a pure refactoring with new features added.
Existing aqe init command works identically, but now:
- ✅ Creates
.claude/settings.jsonwith learning hooks - ✅ Auto-adds MCP server
- ✅ Copies CLAUDE.md documentation
- ✅ Creates
aqebash wrapper
Timeline
- Phase 1-2: 2-3 hours (module extraction)
- Phase 3: 1 hour (orchestrator)
- Phase 4: 30 mins (entry point update)
- Phase 5: 1 hour (testing)
Total: ~5 hours
Success Criteria
After aqe init in a new project:
$ aqe init --yes
✅ Created directory structure
✅ Initialized databases (agentdb.db + memory.db)
✅ Created .claude/settings.json with learning hooks
✅ Added MCP server to Claude Code
✅ Copied CLAUDE.md documentation
✅ Created aqe bash wrapper
✅ Fleet initialization completed!
$ ls -la
-rwxr-xr-x aqe # NEW: Bash wrapper
drwxr-xr-x .agentic-qe/
drwxr-xr-x .claude/
-rw-r--r-- CLAUDE.md # NEW: Documentation
$ ls -la .claude/
-rw-r--r-- settings.json # NEW: With AgentDB hooks!
$ claude mcp list
agentic-qe npx aqe-mcp # NEW: Auto-added!
$ ./aqe learn status
✅ Learning system operational
📊 Patterns: 0 (ready to learn!)
All requirements met! ✅