chore: refine terminal ai prefix handling (#12328)

This commit is contained in:
ssongliu
2026-03-25 07:28:22 +00:00
committed by GitHub
parent 0d19069059
commit 096ec8edc7
11 changed files with 22 additions and 13 deletions
+12 -3
View File
@@ -105,7 +105,7 @@ func (i *aiInputInterceptor) HandleEnter(onStart func(), onDone func(string), on
recentCommands := append([]string(nil), i.recentCommands...)
i.mu.Unlock()
if !strings.HasPrefix(currentLine, i.prefix) {
if !matchesAIPrefix(currentLine, i.prefix) {
if currentLine != "" {
i.pushRecentCommand(currentLine)
}
@@ -211,13 +211,22 @@ func sanitizeInputLine(raw string) string {
return strings.TrimSpace(raw)
}
func matchesAIPrefix(line, prefix string) bool {
line = strings.TrimSpace(line)
prefix = strings.TrimSpace(prefix)
if line == "" || prefix == "" {
return false
}
return line == prefix || strings.HasPrefix(line, prefix+" ")
}
func normalizeCurrentLine(raw, prefix string) string {
line := sanitizeInputLine(raw)
prefix = strings.TrimSpace(prefix)
if line == "" || prefix == "" {
return line
}
if strings.HasPrefix(line, prefix) {
if matchesAIPrefix(line, prefix) {
return line
}
prefixIdx := strings.Index(line, prefix)
@@ -240,7 +249,7 @@ func looksLikePromptPrefix(value string) bool {
if value == "" {
return false
}
if strings.ContainsAny(value, " \t\r\n'\"`") {
if strings.ContainsAny(value, "'\"`") {
return false
}
return true
+1 -1
View File
@@ -1403,7 +1403,7 @@ const message = {
'Use the selected model account to generate and fill commands. For local models like Ollama and vLLM, use a custom model account.',
aiPrefix: 'Trigger Prefix',
aiPrefixHelper:
'Enter the specified prefix and press Enter to trigger AI command generation, for example: {0} help me check disk usage.',
'Enter "prefix + space" and press Enter to trigger AI command generation, for example: {0} help me check disk usage.',
aiRiskCommands: 'Risk Command Interception',
aiRiskCommandsHelper:
'Configure risky commands to intercept, one per line. When matched, generation will be blocked and filled back as comments.',
+1 -1
View File
@@ -1442,7 +1442,7 @@ const message = {
'Use la cuenta de modelo seleccionada para generar y rellenar comandos. Para modelos locales como Ollama y vLLM, use una cuenta de modelo personalizada.',
aiPrefix: 'Prefijo de activación',
aiPrefixHelper:
'Introduzca el prefijo indicado y pulse Enter para activar la generación de comandos por IA; por ejemplo: {0} ayúdame a consultar la información del disco.',
'Introduzca "prefijo + espacio" y pulse Enter para activar la generación de comandos por IA; por ejemplo: {0} ayúdame a consultar la información del disco.',
aiRiskCommands: 'Intercepción de comandos de riesgo',
aiRiskCommandsHelper:
'Configure los comandos de riesgo que se deben interceptar, uno por línea. Si coinciden, se bloqueará la generación y se devolverán como comentarios.',
+1 -1
View File
@@ -1413,7 +1413,7 @@ const message = {
'選択したモデルアカウントでコマンドを生成して補完しますOllama vLLM などのローカルモデルはカスタムモデルアカウントを使用してください',
aiPrefix: 'トリガープレフィックス',
aiPrefixHelper:
'指定したプレフィックスを入力して Enter を押すとAI コマンド生成がトリガーされます: {0} ディスク情報を確認して',
'プレフィックス + スペースを入力して Enter を押すとAI コマンド生成がトリガーされます: {0} ディスク情報を確認して',
aiRiskCommands: '危険コマンドの遮断',
aiRiskCommandsHelper:
'ブロック対象の危険コマンドを設定します1 行に 1 一致した場合生成を停止しコメントとして埋め戻します',
+1 -1
View File
@@ -1387,7 +1387,7 @@ const message = {
'선택한 모델 계정으로 명령을 생성하고 채웁니다. Ollama, vLLM 같은 로컬 모델은 사용자 지정 모델 계정을 사용하세요.',
aiPrefix: '트리거 접두사',
aiPrefixHelper:
'지정한 접두사를 입력하고 Enter를 누르면 AI 명령 생성이 시작됩니다. : {0} 디스크 정보를 조회해줘.',
'"접두사 + 공백" 입력하고 Enter를 누르면 AI 명령 생성이 시작됩니다. : {0} 디스크 정보를 조회해줘.',
aiRiskCommands: '위험 명령 차단',
aiRiskCommandsHelper:
'차단할 위험 명령을 설정하세요( 줄에 하나씩). 일치하면 생성이 차단되고 주석으로 다시 채워집니다.',
+1 -1
View File
@@ -1427,7 +1427,7 @@ const message = {
'Gunakan akaun model yang dipilih untuk menjana dan mengisi arahan. Untuk model tempatan seperti Ollama dan vLLM, gunakan akaun model tersuai.',
aiPrefix: 'Awalan pencetus',
aiPrefixHelper:
'Masukkan awalan yang ditetapkan dan tekan Enter untuk mencetuskan penjanaan arahan AI, contohnya: {0} bantu saya semak maklumat cakera.',
'Masukkan "awalan + ruang" dan tekan Enter untuk mencetuskan penjanaan arahan AI, contohnya: {0} bantu saya semak maklumat cakera.',
aiRiskCommands: 'Pencegatan arahan berisiko',
aiRiskCommandsHelper:
'Konfigurasikan arahan berisiko yang perlu dipintas, satu bagi setiap baris. Apabila sepadan, penjanaan akan disekat dan diisi semula sebagai komen.',
+1 -1
View File
@@ -1435,7 +1435,7 @@ const message = {
'Use a conta de modelo selecionada para gerar e preencher comandos. Para modelos locais como Ollama e vLLM, use uma conta de modelo personalizada.',
aiPrefix: 'Prefixo de disparo',
aiPrefixHelper:
'Digite o prefixo especificado e pressione Enter para acionar a geração de comandos por IA, por exemplo: {0} me ajude a consultar as informações do disco.',
'Digite "prefixo + espaço" e pressione Enter para acionar a geração de comandos por IA, por exemplo: {0} me ajude a consultar as informações do disco.',
aiRiskCommands: 'Intercepção de comandos de risco',
aiRiskCommandsHelper:
'Configure os comandos de risco que devem ser interceptados, um por linha. Quando houver correspondência, a geração será bloqueada e preenchida de volta como comentário.',
+1 -1
View File
@@ -1420,7 +1420,7 @@ const message = {
'Используйте выбранный модельный аккаунт для генерации и подстановки команд. Для локальных моделей, таких как Ollama и vLLM, используйте пользовательский модельный аккаунт.',
aiPrefix: 'Префикс запуска',
aiPrefixHelper:
'Введите указанный префикс и нажмите Enter, чтобы запустить генерацию команд ИИ, например: {0} помоги мне показать информацию о диске.',
'Введите "префикс + пробел" и нажмите Enter, чтобы запустить генерацию команд ИИ, например: {0} помоги мне показать информацию о диске.',
aiRiskCommands: 'Перехват опасных команд',
aiRiskCommandsHelper:
'Настройте опасные команды для перехвата, по одной в каждой строке. При совпадении генерация будет заблокирована, а команда подставлена обратно в виде комментария.',
+1 -1
View File
@@ -1424,7 +1424,7 @@ const message = {
'Komut üretmek ve doldurmak için seçili model hesabını kullanın. Ollama ve vLLM gibi yerel modeller için özel model hesabı kullanın.',
aiPrefix: 'Tetikleme öneki',
aiPrefixHelper:
'Belirtilen öneki girip Enter tuşuna bastığınızda AI komut üretimi tetiklenir; örneğin: {0} disk bilgisini sorgulamama yardım et.',
'"Önek + boşluk" girip Enter tuşuna bastığınızda AI komut üretimi tetiklenir; örneğin: {0} disk bilgisini sorgulamama yardım et.',
aiRiskCommands: 'Riskli komut engelleme',
aiRiskCommandsHelper:
'Engellenecek riskli komutlari yapılandırın, her satıra bir tane gelecek şekilde. Eşleşme olduğunda üretim durdurulur ve yorum olarak geri doldurulur.',
+1 -1
View File
@@ -1323,7 +1323,7 @@ const message = {
aiAssistant: 'AI 助手',
aiAccountHelper: '使用所選模型帳號生成並回填命令OllamavLLM 本地模型請使用自訂模型帳號',
aiPrefix: '觸發前綴',
aiPrefixHelper: '輸入指定前綴並按下 Enter 將觸發 AI 指令生成例如{0} 幫我查詢磁碟資訊',
aiPrefixHelper: '輸入前綴 + 空格並按下 Enter 將觸發 AI 指令生成例如{0} 幫我查詢磁碟資訊',
aiRiskCommands: '風險命令攔截',
aiRiskCommandsHelper: '配置需攔截的風險命令每行一條命中後將阻止生成並以註解回填',
aiSummary: ' {0} 前綴開頭並按下 Enter 會觸發 AI 命令生成',
+1 -1
View File
@@ -1332,7 +1332,7 @@ const message = {
aiAssistant: 'AI 助手',
aiAccountHelper: '使用所选模型账号生成并回填命令OllamavLLM 本地模型请用自定义模型账号',
aiPrefix: '触发前缀',
aiPrefixHelper: '输入指定前缀并按回车将触发 AI 命令生成例如{0} 帮我查询磁盘信息',
aiPrefixHelper: '输入前缀 + 空格回车将触发 AI 命令生成例如{0} 帮我查询磁盘信息',
aiRiskCommands: '风险命令拦截',
aiRiskCommandsHelper: '配置需拦截的风险命令每行一条命中后将阻止生成并以注释回填',
aiSummary: ' {0} 前缀开头并回车时会触发 AI 命令生成',