feat: 新增现代化命令替代功能 v0.2.0

🎯 主要功能:
- 智能检测系统中已安装的现代化命令行工具
- 支持 44 种默认命令映射 (ls→eza, cat→bat, find→fd 等)
- 灵活的环境变量配置系统
- AI 提示词集成,优先推荐现代化工具
- 完整的配置状态显示

⚙️ 配置方式:
- 环境变量: AI_SHELL_MODERN_COMMANDS="ls:eza,cat:bat"
- .env 文件配置支持
- 动态配置检测和合并

🔧 技术实现:
- 新增 get_modern_commands() 配置管理
- 新增 get_available_modern_commands() 系统检测
- 新增 generate_modern_commands_prompt() 提示词生成
- 更新 AI agent 系统提示词
- 完善配置显示和测试脚本

📊 支持的现代化工具:
文件操作: eza, bat, fd, tree
文本处理: rg, sd, choose, delta
系统监控: procs, htop, ncdu, duf
网络工具: gping, httpie, aria2c
编辑器: nvim, micro
其他: zoxide, trash, ouch, pnpm
This commit is contained in:
2025-07-12 22:32:09 +08:00
parent 51cc93d408
commit c4d1510ce9
9 changed files with 660 additions and 24 deletions

View File

@ -6,42 +6,48 @@ from textwrap import dedent
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel
from .config import get_model, setup_environment
from .config import get_model, setup_environment, generate_modern_commands_prompt
from .models import Answer
# System prompt for the AI agent
SYSTEM_PROMPT = dedent(
"""\
You are a professional developer specializing in shell commands.
Your task is to generate the correct shell commands based on the
user's request.
def create_system_prompt() -> str:
"""Create system prompt with modern commands preferences"""
base_prompt = dedent(
"""\
You are a professional developer specializing in shell commands.
Your task is to generate the correct shell commands based on the
user's request.
IMPORTANT: ALWAYS USE THE SAME LANGUAGE AS THE USER PROMPT IN
YOUR RESPONSE.
IMPORTANT: ALWAYS USE THE SAME LANGUAGE AS THE USER PROMPT IN
YOUR RESPONSE.
Process:
Process:
1. Think Aloud: Use the `think` function to explain your reasoning.
Justify why you chose a particular command, considering efficiency,
safety, and best practices.
1. Think Aloud: Use the `think` function to explain your reasoning.
Justify why you chose a particular command, considering efficiency,
safety, and best practices.
2. Provide the Final Command: Use the `answer` function to present
the final shell command concisely.
"""
)
2. Provide the Final Command: Use the `answer` function to present
the final shell command concisely.
"""
)
# Add modern commands preferences
modern_commands_prompt = generate_modern_commands_prompt()
return base_prompt + modern_commands_prompt
def create_agent() -> Agent:
"""Create and configure the AI agent"""
# Setup environment variables
setup_environment()
# Create OpenAI compatible model
model = OpenAIModel(get_model())
# Create agent
# Create agent with dynamic system prompt
agent = Agent(
model=model,
system_prompt=SYSTEM_PROMPT,
system_prompt=create_system_prompt(),
output_type=Answer,
)