UNPKG

scai

Version:

> AI-powered CLI tool for commit messages **and** pull request reviews — using local models.

20 lines (19 loc) 835 B
// src/utils/sanitizeQuery.ts import { STOP_WORDS } from '../fileRules/stopWords.js'; export function sanitizeQueryForFts(input) { input = input.trim().toLowerCase(); // If it's a single filename-like string (includes dots or slashes), quote it if (/^[\w\-./]+$/.test(input) && !/\s/.test(input)) { // Escape quotes and wrap with double-quotes for FTS safety return `"${input.replace(/"/g, '""')}"*`; } // Otherwise, treat it as a natural language prompt const tokens = input .split(/\s+/) .map(token => token.toLowerCase()) .filter(token => token.length > 2 && !STOP_WORDS.has(token) && /^[a-z0-9]+$/.test(token)) .map(token => token.replace(/[?*\\"]/g, '').replace(/'/g, "''") + '*'); return tokens.length > 0 ? tokens.join(' OR ') : '*'; }