Bases: CommandGroup
A command group for AI-powered operations.
This class provides commands for AI-assisted development tasks including
code review, commit summarization, project analysis, and question answering.
The constructor for the AICommandGroup class.
This method initializes the command group with the AI service,
terminal interface, and task manager.
Parameters:
-
ai
(AIService)
–
The AI service for AI operations.
-
terminal
(Terminal | None, default:
None
)
–
The blessed Terminal instance for display operations.
Source code in dev_tool/commands/ai.py
| def __init__(self, ai: AIService, terminal: Terminal | None = None) -> None:
"""
The constructor for the AICommandGroup class.
This method initializes the command group with the AI service,
terminal interface, and task manager.
:param ai: The AI service for AI operations.
:param terminal: The blessed Terminal instance for display operations.
"""
super().__init__()
self.ai = ai
self.interface = AIInterface(terminal or Terminal())
self.task_manager = TaskManager()
|
The string representation of the command group.
This method returns the category name for the command group.
Returns:
-
str
–
The category name as a string.
Source code in dev_tool/commands/ai.py
| def __str__(self) -> str:
"""
The string representation of the command group.
This method returns the category name for the command group.
:return: The category name as a string.
"""
return 'AI'
|
A command that analyzes the current project using AI.
This method packages project information and submits it to the AI
service for analysis as a background task.
Source code in dev_tool/commands/ai.py
| @ordered_command(label='Analyze project')
def analyze_project(self) -> None:
"""
A command that analyzes the current project using AI.
This method packages project information and submits it to the AI
service for analysis as a background task.
"""
if not self._check_ai_availability():
return
try:
context = self.ai.package_project()
except Exception as e:
emit_error(f'Failed to package project for analysis: {e}')
return
def process_analysis() -> str:
return self.ai.analyze_project(context)
try:
self.task_manager.submit(
TaskType.PROJECT_ANALYSIS,
'Analyzing project structure and code',
process_analysis,
completion_callback=self._on_task_completion
)
except Exception as e:
emit_error(f'Failed to submit project analysis task: {e}')
|
A command that allows asking questions about the project using AI.
This method prompts the user for a question, packages project context,
and submits the question to the AI service as a background task.
Source code in dev_tool/commands/ai.py
| @ordered_command(label='Ask about project')
def ask_question(self) -> None:
"""
A command that allows asking questions about the project using AI.
This method prompts the user for a question, packages project context,
and submits the question to the AI service as a background task.
"""
if not self._check_ai_availability():
return
question = get_user_input('What would you like to know about this project?')
if not question.strip():
message = 'No question entered.'
emit_warning(message)
return
try:
context = self.ai.package_project()
except Exception as e:
emit_error(f'Failed to package project for question: {e}')
return
def process_question() -> str:
return self.ai.ask_question(context, question)
try:
self.task_manager.submit(
TaskType.PROJECT_QUESTION,
f'Answering: {question[:50]}...' if len(question) > 50 else f'Answering: {question}',
process_question,
completion_callback=self._on_task_completion,
question=question
)
except Exception as e:
emit_error(f'Failed to submit question task: {e}')
|
A command that reviews current code changes using AI.
This method retrieves uncommitted code changes from Git and submits
them to the AI service for code review as a background task.
Source code in dev_tool/commands/ai.py
| @ordered_command(label='Review code changes')
def review_changes(self) -> None:
"""
A command that reviews current code changes using AI.
This method retrieves uncommitted code changes from Git and submits
them to the AI service for code review as a background task.
"""
if not self._check_ai_availability():
return
try:
changes = self.ai.get_git_changes()
except Exception as e:
emit_error(f'Failed to get code changes: {e}')
return
if changes in ['Git not found in PATH', 'Could not retrieve changes', 'No changes found']:
message = f'Unable to retrieve changes: {changes}'
emit_error(message)
return
if not changes.strip():
message = 'No uncommitted changes found to review.'
emit_normal(message)
return
def process_review() -> str:
return self.ai.review_code(changes)
try:
self.task_manager.submit(
TaskType.CODE_REVIEW,
'Code review of current changes',
process_review,
completion_callback=self._on_task_completion,
changes_summary=changes[:100] + '...' if len(changes) > 100 else changes
)
except Exception as e:
emit_error(f'Failed to submit code review task: {e}')
|
A command that summarizes recent Git commits using AI.
This method retrieves the last 10 commits from Git and submits
them to the AI service for summarization as a background task.
Source code in dev_tool/commands/ai.py
| @ordered_command(label='Summarize recent commits')
def summarize_commits(self) -> None:
"""
A command that summarizes recent Git commits using AI.
This method retrieves the last 10 commits from Git and submits
them to the AI service for summarization as a background task.
"""
if not self._check_ai_availability():
return
try:
commits = self.ai.get_recent_commits(10)
except Exception as e:
emit_error(f'Failed to get recent commits: {e}')
return
if commits in ['Git not found in PATH', 'Could not retrieve commit history', 'No commits found']:
message = f'Unable to retrieve commits: {commits}'
emit_error(message)
return
def process_summary() -> str:
return self.ai.summarize_commits(commits)
try:
self.task_manager.submit(
TaskType.COMMIT_SUMMARY,
'Summarizing last 10 commits',
process_summary,
completion_callback=self._on_task_completion,
commits_preview=commits[:100] + '...' if len(commits) > 100 else commits
)
except Exception as e:
emit_error(f'Failed to submit commit summary task: {e}')
|