From f1b57a6c5329d35a1bf87322586dc079a1e5d599 Mon Sep 17 00:00:00 2001 From: jaakko Date: Tue, 7 Apr 2026 06:37:51 +0300 Subject: [PATCH] Tab korjaa kirjoitusvirheet + fuzzy-match alikomennoille MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tab-painallus yrittää ensin autokorjausta (typo-taulukko + Levenshtein), sitten normaalia tab-completionia. Myös alikomennot korjautuvat fuzzy-matchilla (esim. "kpn rnu" → "kpn run"). Co-Authored-By: Claude Opus 4.6 (1M context) --- network-poc/static/index.html | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/network-poc/static/index.html b/network-poc/static/index.html index fe282e3..9e50e81 100644 --- a/network-poc/static/index.html +++ b/network-poc/static/index.html @@ -2264,11 +2264,26 @@ Files: ${Object.keys(generatedFiles).join(', ')}`; } } // Levenshtein-etäisyys ensimmäiselle sanalle - const firstWord = input.trim().split(/\s+/)[0].toLowerCase(); + const words = input.trim().split(/\s+/); + const firstWord = words[0].toLowerCase(); if (firstWord !== 'kpn' && firstWord.length >= 2 && firstWord.length <= 5) { const dist = levenshtein(firstWord, 'kpn'); if (dist <= 2) return 'kpn' + input.slice(firstWord.length); } + // Fuzzy-korjaus alikomentotasolla: "kpn rnu" → "kpn run" + if (firstWord === 'kpn' && words.length >= 2) { + const sub = words[1].toLowerCase(); + const subCommands = ['help', 'run', 'project', 'pipeline', 'load', 'status', 'models', 'hello', 'clear']; + let bestMatch = null, bestDist = 3; + for (const cmd of subCommands) { + const d = levenshtein(sub, cmd); + if (d > 0 && d < bestDist) { bestDist = d; bestMatch = cmd; } + } + if (bestMatch) { + words[1] = bestMatch; + return words.join(' '); + } + } return null; } @@ -2426,6 +2441,13 @@ Files: ${Object.keys(generatedFiles).join(', ')}`; }; function tabComplete(input) { + // Autokorjaus ensin: korjaa typo ja palauta true jos korjattiin + const corrected = autocorrect(input.value.trim()); + if (corrected && corrected !== input.value.trim()) { + input.value = corrected; + return true; + } + const val = input.value; const words = val.trimEnd().split(/\s+/);