kotoshu 1.0.2-x86_64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.kotoshu-baseline.json +1 -0
- data/.pre-commit-hooks.yaml +18 -0
- data/.rspec +3 -0
- data/.rubocop.yml +351 -0
- data/.yardopts +8 -0
- data/CHANGELOG.md +813 -0
- data/CLAUDE.md +176 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/Cargo.lock +359 -0
- data/Cargo.toml +15 -0
- data/LICENSE +31 -0
- data/README.adoc +1292 -0
- data/Rakefile +150 -0
- data/SECURITY.md +93 -0
- data/TODO.impl/00-cut-0.1.md +121 -0
- data/TODO.impl/00-cut-0.2.md +175 -0
- data/TODO.impl/00-vision.md +281 -0
- data/TODO.impl/01-hunspell-correctness.md +111 -0
- data/TODO.impl/02-cli-unification.md +74 -0
- data/TODO.impl/03-dynamic-download.md +107 -0
- data/TODO.impl/04-language-modules.md +89 -0
- data/TODO.impl/05-semantic-path.md +83 -0
- data/TODO.impl/06-cjk-support.md +105 -0
- data/TODO.impl/07-rtl-support.md +71 -0
- data/TODO.impl/08-grammar-engine.md +106 -0
- data/TODO.impl/09-integrity-security.md +90 -0
- data/TODO.impl/10-testing-ci.md +98 -0
- data/TODO.impl/100-full-feature-batch3.md +28 -0
- data/TODO.impl/101-int4-tier-experiment.md +32 -0
- data/TODO.impl/102-lid-chain.md +28 -0
- data/TODO.impl/103-oov-bucket-tables.md +27 -0
- data/TODO.impl/104-vscode-marketplace-readiness.md +32 -0
- data/TODO.impl/105-personal-dictionary-in-check.md +34 -0
- data/TODO.impl/106-native-lid-detection.md +36 -0
- data/TODO.impl/107-basic-support-every-staged-language.md +42 -0
- data/TODO.impl/108-ko-ne-full-feature.md +37 -0
- data/TODO.impl/109-ten-audit.md +26 -0
- data/TODO.impl/11-release-v1.md +95 -0
- data/TODO.impl/110-sr-latn-and-polish.md +33 -0
- data/TODO.impl/111-embedding-bakeoff.md +33 -0
- data/TODO.impl/112-deployability-and-gating.md +26 -0
- data/TODO.impl/113-language-packs.md +26 -0
- data/TODO.impl/114-typo-biencoder-thread.md +33 -0
- data/TODO.impl/115-hybrid-retrieval-pricing.md +22 -0
- data/TODO.impl/116-baseline-suggestion-skip.md +81 -0
- data/TODO.impl/117-deterministic-frequency-tiers.md +110 -0
- data/TODO.impl/118-server-gem-floor.md +33 -0
- data/TODO.impl/119-embedded-kelly-tiers.md +56 -0
- data/TODO.impl/120-setup-metadata-refresh.md +35 -0
- data/TODO.impl/121-jekyll-baseline-skip.md +33 -0
- data/TODO.impl/122-pack-compression-kpk2.md +66 -0
- data/TODO.impl/123-typo-corpus-synthesis.md +55 -0
- data/TODO.impl/124-owner-residue.md +19 -0
- data/TODO.impl/125-consumer-floor-guards.md +43 -0
- data/TODO.impl/126-tier-error-budgets.md +33 -0
- data/TODO.impl/127-suggestion-feedback-loop.md +34 -0
- data/TODO.impl/128-hybrid-pricing-verdict.md +47 -0
- data/TODO.impl/129-pt-fr-corpora.md +23 -0
- data/TODO.impl/130-news-truth-0912.md +23 -0
- data/TODO.impl/131-hybrid-productization.md +42 -0
- data/TODO.impl/132-techniques-page-and-prose.md +27 -0
- data/TODO.impl/133-rust-first-distribution.md +68 -0
- data/TODO.impl/20-encapsulation-cleanup.md +47 -0
- data/TODO.impl/21-autoload-migration.md +64 -0
- data/TODO.impl/22-url-pin-single-source-of-truth.md +120 -0
- data/TODO.impl/23-fix-url-defaults.md +57 -0
- data/TODO.impl/24-cli-auto-setup-prompt.md +76 -0
- data/TODO.impl/25-soft-onnxruntime-require.md +75 -0
- data/TODO.impl/26-onnx-vocab-json-generation.md +96 -0
- data/TODO.impl/27-end-to-end-smoke-spec.md +113 -0
- data/TODO.impl/28-readme-quickstart-verification.md +68 -0
- data/TODO.impl/29-status-command.md +84 -0
- data/TODO.impl/30-language-auto-detection.md +74 -0
- data/TODO.impl/31-download-progress.md +58 -0
- data/TODO.impl/32-sarif-output-verification.md +72 -0
- data/TODO.impl/33-audit-log-rotation.md +54 -0
- data/TODO.impl/34-cache-eviction.md +59 -0
- data/TODO.impl/35-shell-completion.md +61 -0
- data/TODO.impl/36-cleanup-regressions-0.3.1.md +134 -0
- data/TODO.impl/37-hunspell-correctness-tier2.md +203 -0
- data/TODO.impl/38-onnx-semantic-gating.md +218 -0
- data/TODO.impl/39-tier3-and-beyond.md +232 -0
- data/TODO.impl/40-spec-drift-cleanup.md +134 -0
- data/TODO.impl/50-structure-aware-document-api.md +194 -0
- data/TODO.impl/51-grammar-engine-expansion.md +75 -0
- data/TODO.impl/52-multi-language-documents.md +95 -0
- data/TODO.impl/53-document-plugin-architecture.md +94 -0
- data/TODO.impl/54-cjk-support.md +117 -0
- data/TODO.impl/55-rtl-support.md +109 -0
- data/TODO.impl/56-t4-t5-t6-quality-architecture-ecosystem.md +126 -0
- data/TODO.impl/57-t5.1-step3-pure-function-strategies.md +138 -0
- data/TODO.impl/58-t5.2-configuration-as-data.md +113 -0
- data/TODO.impl/59-yard-api-documentation.md +75 -0
- data/TODO.impl/60-lsp-server.md +174 -0
- data/TODO.impl/61-editor-ecosystem.md +167 -0
- data/TODO.impl/62-framework-integrations.md +159 -0
- data/TODO.impl/63-web-playground-wasm.md +186 -0
- data/TODO.impl/64-http-api-and-sdks.md +191 -0
- data/TODO.impl/65-universal-kotoshu.md +251 -0
- data/TODO.impl/66-kotoshu-core.md +169 -0
- data/TODO.impl/67-kotoshu-rs-and-access-libraries.md +137 -0
- data/TODO.impl/68-sota-adoption.md +152 -0
- data/TODO.impl/69-sota-typo-eval.md +74 -0
- data/TODO.impl/70-sota-confidence-cascade.md +59 -0
- data/TODO.impl/71-sota-nested-model.md +63 -0
- data/TODO.impl/72-model2vec-evaluation.md +49 -0
- data/TODO.impl/73-rl-reranker.md +42 -0
- data/TODO.impl/74-distilled-reranker.md +36 -0
- data/TODO.impl/75-llm-evaluator.md +35 -0
- data/TODO.impl/76-optional-llm-backend.md +37 -0
- data/TODO.impl/77-model-coverage-expansion.md +96 -0
- data/TODO.impl/78-in-browser-playground.md +69 -0
- data/TODO.impl/79-news-and-releases.md +60 -0
- data/TODO.impl/80-ecosystem-docs.md +56 -0
- data/TODO.impl/81-editor-reach.md +68 -0
- data/TODO.impl/82-doc-formats-and-ignores.md +81 -0
- data/TODO.impl/83-models-batch-2.md +56 -0
- data/TODO.impl/84-language-modules-wave2.md +75 -0
- data/TODO.impl/85-wasm-model-api.md +48 -0
- data/TODO.impl/86-site-truth-wave2.md +45 -0
- data/TODO.impl/87-lsp-personal-dictionary.md +36 -0
- data/TODO.impl/88-cli-directory-mode.md +54 -0
- data/TODO.impl/89-framework-integrations-exec.md +59 -0
- data/TODO.impl/90-gem-correctness-residues.md +44 -0
- data/TODO.impl/91-unicode-and-sv-aff.md +47 -0
- data/TODO.impl/92-tier-mirror-cors.md +88 -0
- data/TODO.impl/93-python-wheels.md +32 -0
- data/TODO.impl/94-site-integrations-docs.md +35 -0
- data/TODO.impl/95-editor-action-polish.md +27 -0
- data/TODO.impl/96-server-semantic-models.md +50 -0
- data/TODO.impl/97-yard-execution.md +73 -0
- data/TODO.impl/98-campaign-cleanup.md +78 -0
- data/TODO.impl/99-site-truth-performance-docs.md +31 -0
- data/conformance/vectors.jsonl +2630 -0
- data/data/en/grammar/rules.yaml +851 -0
- data/docs/STABILITY-1.0-AUDIT.md +251 -0
- data/docs/STABILITY-1.0.md +137 -0
- data/docs/cache-architecture.md +502 -0
- data/docs/verification-evidence/correct3/pr_body.md +37 -0
- data/docs/verification-evidence/correct3/rspec_final.log +5588 -0
- data/docs/verification-evidence/correct3/rspec_full.log +4504 -0
- data/docs/verification-evidence/correct3/sv.aff +856 -0
- data/docs/verification-evidence/correct3/sv.dic +153717 -0
- data/examples/01_basic_word_checking.rb +38 -0
- data/examples/02_text_document_checking.rb +77 -0
- data/examples/03_dictionary_backends.rb +137 -0
- data/examples/04_trie_data_structure.rb +146 -0
- data/examples/05_suggestion_algorithms.rb +239 -0
- data/examples/06_configuration_advanced.rb +287 -0
- data/examples/07_multi_language_dictionaries.rb +278 -0
- data/exe/kotoshu +6 -0
- data/lib/kotoshu/algorithms/capitalization.rb +276 -0
- data/lib/kotoshu/algorithms/edit_distance.rb +128 -0
- data/lib/kotoshu/algorithms/lookup/affix_form.rb +132 -0
- data/lib/kotoshu/algorithms/lookup/compound_checks.rb +209 -0
- data/lib/kotoshu/algorithms/lookup/compound_form.rb +50 -0
- data/lib/kotoshu/algorithms/lookup.rb +841 -0
- data/lib/kotoshu/algorithms/ngram_suggest.rb +367 -0
- data/lib/kotoshu/algorithms/permutations.rb +283 -0
- data/lib/kotoshu/algorithms/phonet_suggest.rb +162 -0
- data/lib/kotoshu/algorithms/soundex.rb +92 -0
- data/lib/kotoshu/algorithms/suggest.rb +794 -0
- data/lib/kotoshu/algorithms.rb +23 -0
- data/lib/kotoshu/analyzers/semantic_analyzer.rb +405 -0
- data/lib/kotoshu/analyzers.rb +8 -0
- data/lib/kotoshu/baseline/application.rb +18 -0
- data/lib/kotoshu/baseline/entry.rb +33 -0
- data/lib/kotoshu/baseline/store.rb +175 -0
- data/lib/kotoshu/baseline.rb +20 -0
- data/lib/kotoshu/cache/base_cache.rb +778 -0
- data/lib/kotoshu/cache/cache.rb +91 -0
- data/lib/kotoshu/cache/eviction_policy.rb +66 -0
- data/lib/kotoshu/cache/frequency_cache.rb +283 -0
- data/lib/kotoshu/cache/language_cache.rb +511 -0
- data/lib/kotoshu/cache/lookup_cache.rb +166 -0
- data/lib/kotoshu/cache/model_cache.rb +1147 -0
- data/lib/kotoshu/cache/model_registry.rb +109 -0
- data/lib/kotoshu/cache/staged_languages.rb +45 -0
- data/lib/kotoshu/cache/suggestion_cache.rb +113 -0
- data/lib/kotoshu/cache.rb +49 -0
- data/lib/kotoshu/cli/auto_setup.rb +71 -0
- data/lib/kotoshu/cli/baseline_command.rb +119 -0
- data/lib/kotoshu/cli/batch_reporter.rb +321 -0
- data/lib/kotoshu/cli/cache_command.rb +282 -0
- data/lib/kotoshu/cli/completions_command.rb +210 -0
- data/lib/kotoshu/cli/dict_command.rb +64 -0
- data/lib/kotoshu/cli/directory_check.rb +146 -0
- data/lib/kotoshu/cli/directory_walker.rb +132 -0
- data/lib/kotoshu/cli/display_formatter.rb +429 -0
- data/lib/kotoshu/cli/errors.rb +36 -0
- data/lib/kotoshu/cli/ignore_matcher.rb +205 -0
- data/lib/kotoshu/cli/interactive_reviewer.rb +314 -0
- data/lib/kotoshu/cli/language_resolver.rb +91 -0
- data/lib/kotoshu/cli/navigation_manager.rb +273 -0
- data/lib/kotoshu/cli/personal_command.rb +113 -0
- data/lib/kotoshu/cli/progress_reporter.rb +114 -0
- data/lib/kotoshu/cli/status_report.rb +130 -0
- data/lib/kotoshu/cli.rb +880 -0
- data/lib/kotoshu/components/passthrough_spell_checker.rb +70 -0
- data/lib/kotoshu/components/pos_tagger.rb +98 -0
- data/lib/kotoshu/components/spell_checker.rb +73 -0
- data/lib/kotoshu/components/synthesizer.rb +60 -0
- data/lib/kotoshu/components/tokenizer.rb +58 -0
- data/lib/kotoshu/components/whitespace_tokenizer.rb +94 -0
- data/lib/kotoshu/components.rb +13 -0
- data/lib/kotoshu/configuration/builder.rb +207 -0
- data/lib/kotoshu/configuration/resolver.rb +124 -0
- data/lib/kotoshu/configuration.rb +829 -0
- data/lib/kotoshu/conformance_exporter.rb +256 -0
- data/lib/kotoshu/conformance_runner.rb +176 -0
- data/lib/kotoshu/core/exceptions.rb +186 -0
- data/lib/kotoshu/core/indexed_dictionary.rb +293 -0
- data/lib/kotoshu/core/models/affix_rule.rb +262 -0
- data/lib/kotoshu/core/models/result/document_result.rb +132 -0
- data/lib/kotoshu/core/models/result/word_result.rb +131 -0
- data/lib/kotoshu/core/models/word.rb +131 -0
- data/lib/kotoshu/core/trie/builder.rb +119 -0
- data/lib/kotoshu/core/trie/node.rb +94 -0
- data/lib/kotoshu/core/trie/trie.rb +249 -0
- data/lib/kotoshu/core.rb +28 -0
- data/lib/kotoshu/data/common_words/de.yml +1800 -0
- data/lib/kotoshu/data/common_words/en.yml +1215 -0
- data/lib/kotoshu/data/common_words/es.yml +750 -0
- data/lib/kotoshu/data/common_words/fr.yml +1015 -0
- data/lib/kotoshu/data/common_words/pt.yml +870 -0
- data/lib/kotoshu/data/common_words/ru.yml +484 -0
- data/lib/kotoshu/data/common_words_loader.rb +141 -0
- data/lib/kotoshu/data/frozen_kelly/en.json +1154 -0
- data/lib/kotoshu/data/frozen_kelly.rb +38 -0
- data/lib/kotoshu/data.rb +8 -0
- data/lib/kotoshu/data_structures/bloom_filter.rb +188 -0
- data/lib/kotoshu/data_structures.rb +8 -0
- data/lib/kotoshu/debug_logger.rb +146 -0
- data/lib/kotoshu/debug_mode.rb +136 -0
- data/lib/kotoshu/defaults.rb +84 -0
- data/lib/kotoshu/dictionaries/catalog.rb +814 -0
- data/lib/kotoshu/dictionaries.rb +8 -0
- data/lib/kotoshu/dictionary/base.rb +324 -0
- data/lib/kotoshu/dictionary/cspell.rb +243 -0
- data/lib/kotoshu/dictionary/custom.rb +225 -0
- data/lib/kotoshu/dictionary/hunspell.rb +520 -0
- data/lib/kotoshu/dictionary/plain_text.rb +302 -0
- data/lib/kotoshu/dictionary/repository.rb +246 -0
- data/lib/kotoshu/dictionary/unified.rb +236 -0
- data/lib/kotoshu/dictionary/unix_words.rb +218 -0
- data/lib/kotoshu/dictionary.rb +15 -0
- data/lib/kotoshu/documents/document.rb +120 -0
- data/lib/kotoshu/documents/plain_text_document.rb +73 -0
- data/lib/kotoshu/documents/source_position.rb +45 -0
- data/lib/kotoshu/documents/source_range.rb +76 -0
- data/lib/kotoshu/documents/suppressions/scanner.rb +149 -0
- data/lib/kotoshu/documents/suppressions/suppression.rb +75 -0
- data/lib/kotoshu/documents/suppressions.rb +44 -0
- data/lib/kotoshu/documents/text_node.rb +49 -0
- data/lib/kotoshu/documents.rb +178 -0
- data/lib/kotoshu/embeddings/embedding_pipeline.rb +238 -0
- data/lib/kotoshu/embeddings/lru_cache.rb +244 -0
- data/lib/kotoshu/embeddings/onnx_runtime_model.rb +411 -0
- data/lib/kotoshu/embeddings/protocol.rb +96 -0
- data/lib/kotoshu/embeddings/protocols.rb +23 -0
- data/lib/kotoshu/embeddings/registry.rb +184 -0
- data/lib/kotoshu/embeddings/search.rb +204 -0
- data/lib/kotoshu/embeddings/similarity_engine.rb +278 -0
- data/lib/kotoshu/embeddings/similarity_search.rb +328 -0
- data/lib/kotoshu/embeddings/vocabulary.rb +306 -0
- data/lib/kotoshu/embeddings.rb +87 -0
- data/lib/kotoshu/fluent_checker.rb +94 -0
- data/lib/kotoshu/grammar/pattern_matchers/base_matcher.rb +48 -0
- data/lib/kotoshu/grammar/pattern_matchers/double_negative_matcher.rb +179 -0
- data/lib/kotoshu/grammar/pattern_matchers/phrase_matcher.rb +86 -0
- data/lib/kotoshu/grammar/pattern_matchers/possessive_context_matcher.rb +75 -0
- data/lib/kotoshu/grammar/pattern_matchers/possessive_contraction_matcher.rb +87 -0
- data/lib/kotoshu/grammar/pattern_matchers/sentence_start_matcher.rb +84 -0
- data/lib/kotoshu/grammar/pattern_matchers/vowel_sound_matcher.rb +81 -0
- data/lib/kotoshu/grammar/pattern_matchers/word_list_matcher.rb +66 -0
- data/lib/kotoshu/grammar/rule.rb +99 -0
- data/lib/kotoshu/grammar/rule_engine.rb +96 -0
- data/lib/kotoshu/grammar/rule_loader.rb +30 -0
- data/lib/kotoshu/grammar.rb +24 -0
- data/lib/kotoshu/integrity/audit_log.rb +167 -0
- data/lib/kotoshu/integrity/manifest.rb +116 -0
- data/lib/kotoshu/integrity/net_http.rb +51 -0
- data/lib/kotoshu/integrity/rotation_policy.rb +88 -0
- data/lib/kotoshu/integrity.rb +26 -0
- data/lib/kotoshu/jekyll.rb +101 -0
- data/lib/kotoshu/keyboard/layout.rb +116 -0
- data/lib/kotoshu/keyboard/layouts/arabic.rb +59 -0
- data/lib/kotoshu/keyboard/layouts/azerty.rb +55 -0
- data/lib/kotoshu/keyboard/layouts/bulgarian.rb +57 -0
- data/lib/kotoshu/keyboard/layouts/devanagari_inscript.rb +52 -0
- data/lib/kotoshu/keyboard/layouts/dubeolsik.rb +56 -0
- data/lib/kotoshu/keyboard/layouts/dvorak.rb +54 -0
- data/lib/kotoshu/keyboard/layouts/greek.rb +52 -0
- data/lib/kotoshu/keyboard/layouts/hebrew.rb +57 -0
- data/lib/kotoshu/keyboard/layouts/hrsl.rb +94 -0
- data/lib/kotoshu/keyboard/layouts/jcuken.rb +57 -0
- data/lib/kotoshu/keyboard/layouts/latin.rb +266 -0
- data/lib/kotoshu/keyboard/layouts/persian.rb +58 -0
- data/lib/kotoshu/keyboard/layouts/qwerty.rb +52 -0
- data/lib/kotoshu/keyboard/layouts/qwertz.rb +55 -0
- data/lib/kotoshu/keyboard/layouts/serbian.rb +59 -0
- data/lib/kotoshu/keyboard/layouts/turkish_q.rb +52 -0
- data/lib/kotoshu/keyboard/layouts/ukrainian.rb +51 -0
- data/lib/kotoshu/keyboard/registry.rb +201 -0
- data/lib/kotoshu/keyboard.rb +96 -0
- data/lib/kotoshu/kotoshu_native.so +0 -0
- data/lib/kotoshu/language/detector.rb +242 -0
- data/lib/kotoshu/language/identifier.rb +376 -0
- data/lib/kotoshu/language/languages/base.rb +271 -0
- data/lib/kotoshu/language/lid_detector.rb +188 -0
- data/lib/kotoshu/language/normalizer/arabic.rb +113 -0
- data/lib/kotoshu/language/normalizer/base.rb +133 -0
- data/lib/kotoshu/language/normalizer/greek.rb +63 -0
- data/lib/kotoshu/language/normalizer/hebrew.rb +72 -0
- data/lib/kotoshu/language/normalizer/persian.rb +36 -0
- data/lib/kotoshu/language/normalizer/turkish.rb +38 -0
- data/lib/kotoshu/language/registry.rb +209 -0
- data/lib/kotoshu/language/resources/ar/common_words.txt +6753 -0
- data/lib/kotoshu/language/resources/ar/confusion_sets.txt +11 -0
- data/lib/kotoshu/language/resources/de/common_words.txt +10003 -0
- data/lib/kotoshu/language/resources/de/confusion_sets.txt +246 -0
- data/lib/kotoshu/language/resources/en/common_words.txt +9979 -0
- data/lib/kotoshu/language/resources/en/confusion_sets.txt +871 -0
- data/lib/kotoshu/language/resources/es/common_words.txt +9992 -0
- data/lib/kotoshu/language/resources/es/confusion_sets.txt +17 -0
- data/lib/kotoshu/language/resources/fr/common_words.txt +9993 -0
- data/lib/kotoshu/language/resources/fr/confusion_sets.txt +76 -0
- data/lib/kotoshu/language/resources/pt/common_words.txt +9977 -0
- data/lib/kotoshu/language/resources/pt/confusion_sets.txt +18 -0
- data/lib/kotoshu/language/resources/ru/common_words.txt +9951 -0
- data/lib/kotoshu/language/resources/ru/confusion_sets.txt +5 -0
- data/lib/kotoshu/language/script.rb +128 -0
- data/lib/kotoshu/language/segmenter.rb +122 -0
- data/lib/kotoshu/language/suika.rb +38 -0
- data/lib/kotoshu/language/tokenizer/base.rb +187 -0
- data/lib/kotoshu/language/tokenizer/cyrillic_tokenizer.rb +76 -0
- data/lib/kotoshu/language/tokenizer/devanagari_tokenizer.rb +70 -0
- data/lib/kotoshu/language/tokenizer/french_tokenizer.rb +172 -0
- data/lib/kotoshu/language/tokenizer/german_tokenizer.rb +41 -0
- data/lib/kotoshu/language/tokenizer/greek_tokenizer.rb +72 -0
- data/lib/kotoshu/language/tokenizer/hangul_tokenizer.rb +70 -0
- data/lib/kotoshu/language/tokenizer/japanese_tokenizer.rb +55 -0
- data/lib/kotoshu/language/tokenizer/latin_tokenizer.rb +153 -0
- data/lib/kotoshu/language/tokenizer/portuguese_tokenizer.rb +160 -0
- data/lib/kotoshu/language/tokenizer/russian_tokenizer.rb +93 -0
- data/lib/kotoshu/language/tokenizer/script_tokenizer.rb +62 -0
- data/lib/kotoshu/language/tokenizer/spanish_tokenizer.rb +122 -0
- data/lib/kotoshu/language.rb +127 -0
- data/lib/kotoshu/languages/ar/language.rb +98 -0
- data/lib/kotoshu/languages/bg/language.rb +37 -0
- data/lib/kotoshu/languages/ca/language.rb +22 -0
- data/lib/kotoshu/languages/cs/language.rb +22 -0
- data/lib/kotoshu/languages/da/language.rb +22 -0
- data/lib/kotoshu/languages/de/language.rb +554 -0
- data/lib/kotoshu/languages/el/language.rb +50 -0
- data/lib/kotoshu/languages/en/language.rb +470 -0
- data/lib/kotoshu/languages/es/language.rb +476 -0
- data/lib/kotoshu/languages/et/language.rb +24 -0
- data/lib/kotoshu/languages/fa/language.rb +91 -0
- data/lib/kotoshu/languages/fr/language.rb +505 -0
- data/lib/kotoshu/languages/he/language.rb +98 -0
- data/lib/kotoshu/languages/hr/language.rb +24 -0
- data/lib/kotoshu/languages/hu/language.rb +22 -0
- data/lib/kotoshu/languages/id/language.rb +25 -0
- data/lib/kotoshu/languages/it/language.rb +22 -0
- data/lib/kotoshu/languages/ja/language.rb +476 -0
- data/lib/kotoshu/languages/ko/language.rb +56 -0
- data/lib/kotoshu/languages/latin_base.rb +53 -0
- data/lib/kotoshu/languages/lt/language.rb +24 -0
- data/lib/kotoshu/languages/lv/language.rb +24 -0
- data/lib/kotoshu/languages/nb/language.rb +25 -0
- data/lib/kotoshu/languages/ne/language.rb +60 -0
- data/lib/kotoshu/languages/nl/language.rb +22 -0
- data/lib/kotoshu/languages/nn/language.rb +26 -0
- data/lib/kotoshu/languages/pl/language.rb +22 -0
- data/lib/kotoshu/languages/pt/language.rb +439 -0
- data/lib/kotoshu/languages/ro/language.rb +22 -0
- data/lib/kotoshu/languages/ru/language.rb +420 -0
- data/lib/kotoshu/languages/sk/language.rb +25 -0
- data/lib/kotoshu/languages/sl/language.rb +25 -0
- data/lib/kotoshu/languages/sr/language.rb +39 -0
- data/lib/kotoshu/languages/sr-Latn/language.rb +35 -0
- data/lib/kotoshu/languages/sv/language.rb +22 -0
- data/lib/kotoshu/languages/tr/language.rb +36 -0
- data/lib/kotoshu/languages/uk/language.rb +38 -0
- data/lib/kotoshu/languages/vi/language.rb +22 -0
- data/lib/kotoshu/languages.rb +64 -0
- data/lib/kotoshu/metrics_collector.rb +238 -0
- data/lib/kotoshu/metrics_module.rb +121 -0
- data/lib/kotoshu/models/context.rb +119 -0
- data/lib/kotoshu/models/embedding_model.rb +181 -0
- data/lib/kotoshu/models/fasttext_model.rb +212 -0
- data/lib/kotoshu/models/nearest_neighbor.rb +96 -0
- data/lib/kotoshu/models/onnx_model.rb +330 -0
- data/lib/kotoshu/models/semantic_error.rb +204 -0
- data/lib/kotoshu/models/suggestion.rb +106 -0
- data/lib/kotoshu/models/word_embedding.rb +97 -0
- data/lib/kotoshu/models.rb +27 -0
- data/lib/kotoshu/multi_language_checker.rb +127 -0
- data/lib/kotoshu/native.rb +83 -0
- data/lib/kotoshu/native_backend.rb +131 -0
- data/lib/kotoshu/paths.rb +79 -0
- data/lib/kotoshu/personal_dictionary.rb +105 -0
- data/lib/kotoshu/plugins/plugin.rb +61 -0
- data/lib/kotoshu/plugins/registry.rb +118 -0
- data/lib/kotoshu/plugins.rb +9 -0
- data/lib/kotoshu/project_config.rb +76 -0
- data/lib/kotoshu/readers/aff_data.rb +530 -0
- data/lib/kotoshu/readers/aff_reader.rb +393 -0
- data/lib/kotoshu/readers/condition_checker.rb +125 -0
- data/lib/kotoshu/readers/dic_reader.rb +208 -0
- data/lib/kotoshu/readers/file_reader.rb +377 -0
- data/lib/kotoshu/readers/lookup_builder.rb +584 -0
- data/lib/kotoshu/readers/readers.rb +17 -0
- data/lib/kotoshu/readers.rb +25 -0
- data/lib/kotoshu/resource_bundle.rb +55 -0
- data/lib/kotoshu/resource_manager.rb +600 -0
- data/lib/kotoshu/results/result.rb +165 -0
- data/lib/kotoshu/results.rb +8 -0
- data/lib/kotoshu/rspec.rb +163 -0
- data/lib/kotoshu/scripts/fasttext_to_onnx.py +275 -0
- data/lib/kotoshu/source_registry.rb +104 -0
- data/lib/kotoshu/spellchecker/parallel_checker.rb +90 -0
- data/lib/kotoshu/spellchecker.rb +406 -0
- data/lib/kotoshu/string_metrics.rb +153 -0
- data/lib/kotoshu/suggestions/context.rb +43 -0
- data/lib/kotoshu/suggestions/frequency_provider.rb +80 -0
- data/lib/kotoshu/suggestions/generator.rb +169 -0
- data/lib/kotoshu/suggestions/pipeline.rb +135 -0
- data/lib/kotoshu/suggestions/semantic_cascade.rb +73 -0
- data/lib/kotoshu/suggestions/strategies/base_strategy.rb +315 -0
- data/lib/kotoshu/suggestions/strategies/composite_strategy.rb +197 -0
- data/lib/kotoshu/suggestions/strategies/edit_distance_strategy.rb +631 -0
- data/lib/kotoshu/suggestions/strategies/keyboard_proximity_strategy.rb +207 -0
- data/lib/kotoshu/suggestions/strategies/ngram_strategy.rb +165 -0
- data/lib/kotoshu/suggestions/strategies/phonetic_strategy.rb +284 -0
- data/lib/kotoshu/suggestions/strategies/semantic_strategy.rb +317 -0
- data/lib/kotoshu/suggestions/strategies/symspell_strategy.rb +270 -0
- data/lib/kotoshu/suggestions/strategies/word_index.rb +78 -0
- data/lib/kotoshu/suggestions/suggestion.rb +154 -0
- data/lib/kotoshu/suggestions/suggestion_set.rb +270 -0
- data/lib/kotoshu/suggestions/sweep_index.rb +137 -0
- data/lib/kotoshu/suggestions.rb +29 -0
- data/lib/kotoshu/tasks/check_task.rb +104 -0
- data/lib/kotoshu/tasks.rb +11 -0
- data/lib/kotoshu/validators/spelling_validator.rb +101 -0
- data/lib/kotoshu/validators.rb +9 -0
- data/lib/kotoshu/version.rb +5 -0
- data/lib/kotoshu.rb +538 -0
- data/rakelib/compile.rake +10 -0
- data/script/validate_all_dictionaries.rb +444 -0
- data/scripts/build_native_gem.rb +45 -0
- data/scripts/extract_eval_grids.rb +37 -0
- data/scripts/generate_frozen_tiers.rb +44 -0
- data/sig/kotoshu.rbs +435 -0
- data/test_oop.rb +79 -0
- metadata +546 -0
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Kotoshu
|
|
4
|
+
module Cli
|
|
5
|
+
# Formats output for interactive review mode.
|
|
6
|
+
#
|
|
7
|
+
# Provides methods to display errors, context, suggestions,
|
|
8
|
+
# and navigation prompts in a user-friendly CLI format.
|
|
9
|
+
#
|
|
10
|
+
# @example Displaying an error
|
|
11
|
+
# formatter = DisplayFormatter.new(verbose: true)
|
|
12
|
+
# puts formatter.issue_screen(error, index: 1, total: 10)
|
|
13
|
+
class DisplayFormatter
|
|
14
|
+
# ANSI color codes for terminal output
|
|
15
|
+
COLORS = {
|
|
16
|
+
error: "\e[31m", # Red
|
|
17
|
+
warning: "\e[33m", # Yellow
|
|
18
|
+
success: "\e[32m", # Green
|
|
19
|
+
info: "\e[36m", # Cyan
|
|
20
|
+
dim: "\e[2m", # Dim
|
|
21
|
+
bold: "\e[1m", # Bold
|
|
22
|
+
reset: "\e[0m" # Reset
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
# Confidence level indicators
|
|
26
|
+
CONFIDENCE_LABELS = {
|
|
27
|
+
high: '✓ High',
|
|
28
|
+
medium: '~ Medium',
|
|
29
|
+
low: '? Low'
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
attr_reader :verbose, :color_enabled
|
|
33
|
+
|
|
34
|
+
# Create a new display formatter.
|
|
35
|
+
#
|
|
36
|
+
# @param verbose [Boolean] Enable verbose output
|
|
37
|
+
# @param color_enabled [Boolean] Enable ANSI colors (default: true for TTY)
|
|
38
|
+
def initialize(verbose: false, color_enabled: nil)
|
|
39
|
+
@verbose = verbose
|
|
40
|
+
@color_enabled = color_enabled.nil? ? $stdout.tty? : color_enabled
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Display summary screen for document review.
|
|
44
|
+
#
|
|
45
|
+
# Shows error breakdown by type and confidence, plus navigation hints.
|
|
46
|
+
#
|
|
47
|
+
# @param document [Document] The document being reviewed
|
|
48
|
+
# @param navigation [NavigationManager] Navigation state
|
|
49
|
+
# @return [String] Formatted summary screen
|
|
50
|
+
def summary_screen(document, navigation)
|
|
51
|
+
stats = navigation.statistics
|
|
52
|
+
|
|
53
|
+
lines = []
|
|
54
|
+
lines << ""
|
|
55
|
+
lines << colorize("═══ Document Review Summary", :bold)
|
|
56
|
+
lines << ""
|
|
57
|
+
lines << "Document: #{document.name}"
|
|
58
|
+
lines << "Format: #{Document::FORMATS[document.format]}"
|
|
59
|
+
lines << "Language: #{document.language_code}"
|
|
60
|
+
lines << ""
|
|
61
|
+
lines << colorize("Error Summary", :bold)
|
|
62
|
+
lines << ("─" * 40)
|
|
63
|
+
|
|
64
|
+
# Total counts
|
|
65
|
+
lines << "Total errors found: #{stats[:total]}"
|
|
66
|
+
lines << " • Pending: #{stats[:pending]}"
|
|
67
|
+
lines << " • Modified: #{stats[:modified]}"
|
|
68
|
+
lines << " • Skipped: #{stats[:skipped]}"
|
|
69
|
+
lines << ""
|
|
70
|
+
|
|
71
|
+
# Breakdown by type
|
|
72
|
+
if stats[:by_type]&.any?
|
|
73
|
+
lines << colorize("By Type", :bold)
|
|
74
|
+
stats[:by_type].each do |type, count|
|
|
75
|
+
label = SemanticError::ERROR_TYPES[type] || type.to_s.capitalize
|
|
76
|
+
lines << " • #{label}: #{count}"
|
|
77
|
+
end
|
|
78
|
+
lines << ""
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Breakdown by confidence
|
|
82
|
+
if stats[:by_confidence]&.any?
|
|
83
|
+
lines << colorize("By Confidence", :bold)
|
|
84
|
+
lines << " • High (>0.8): #{stats[:by_confidence][:high]}"
|
|
85
|
+
lines << " • Medium (0.5-0.8): #{stats[:by_confidence][:medium]}"
|
|
86
|
+
lines << " • Low (≤0.5): #{stats[:by_confidence][:low]}"
|
|
87
|
+
lines << ""
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Navigation hints
|
|
91
|
+
lines << colorize("Navigation", :bold)
|
|
92
|
+
lines << " [Enter] Next error [s] Skip [a] Accept suggestion"
|
|
93
|
+
lines << " [b] Back [q] Quit [l] List all errors"
|
|
94
|
+
lines << " [j] Jump to error [h] Help [?] Show this summary"
|
|
95
|
+
lines << ""
|
|
96
|
+
|
|
97
|
+
lines.join("\n")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Display individual error screen.
|
|
101
|
+
#
|
|
102
|
+
# Shows the error with context, suggestions, and action prompt.
|
|
103
|
+
#
|
|
104
|
+
# @param error [SemanticError] The error to display
|
|
105
|
+
# @param index [Integer] Current error index (1-based)
|
|
106
|
+
# @param total [Integer] Total number of errors
|
|
107
|
+
# @param show_context [Boolean] Show context window (default: true)
|
|
108
|
+
# @return [String] Formatted error screen
|
|
109
|
+
def issue_screen(error, index:, total:, show_context: true)
|
|
110
|
+
lines = []
|
|
111
|
+
lines << ""
|
|
112
|
+
lines << colorize("═" * 70, :bold)
|
|
113
|
+
lines << (colorize("Error #{index} of #{total}", :bold) + " — #{error_type_label(error.error_type)}")
|
|
114
|
+
lines << colorize("═" * 70, :bold)
|
|
115
|
+
lines << ""
|
|
116
|
+
|
|
117
|
+
# Error location
|
|
118
|
+
lines << (colorize("Location:", :bold) + " #{error.location}")
|
|
119
|
+
lines << ""
|
|
120
|
+
|
|
121
|
+
# Error with highlighting
|
|
122
|
+
lines << (colorize("Found:", :error) + " #{highlight_in_context(error)}")
|
|
123
|
+
lines << ""
|
|
124
|
+
|
|
125
|
+
# Context window
|
|
126
|
+
if show_context && error.context
|
|
127
|
+
lines << colorize("Context:", :bold)
|
|
128
|
+
lines << format_context(error.context)
|
|
129
|
+
lines << ""
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
# Confidence indicator
|
|
133
|
+
conf_label = confidence_label(error.confidence)
|
|
134
|
+
lines << (colorize("Confidence:", :bold) + " #{conf_label} (#{(error.confidence * 100).round(1)}%)")
|
|
135
|
+
lines << ""
|
|
136
|
+
|
|
137
|
+
# Suggestions
|
|
138
|
+
if error.suggestions&.any?
|
|
139
|
+
lines << colorize("Suggestions:", :bold)
|
|
140
|
+
lines << format_suggestions(error.suggestions)
|
|
141
|
+
lines << ""
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Action prompt
|
|
145
|
+
lines << (colorize("Actions:",
|
|
146
|
+
:bold) + " [Enter] Next [1-#{error.suggestions&.size || 0}] Accept [s] Skip [b] Back [q] Quit")
|
|
147
|
+
lines << ""
|
|
148
|
+
|
|
149
|
+
lines.join("\n")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Highlight the error word within its context.
|
|
153
|
+
#
|
|
154
|
+
# @param error [SemanticError] The error to highlight
|
|
155
|
+
# @return [String] Highlighted error with context
|
|
156
|
+
def highlight_error(error)
|
|
157
|
+
return error.original unless error.context
|
|
158
|
+
|
|
159
|
+
ctx = error.context
|
|
160
|
+
highlighted = ctx.current.gsub(/\b#{Regexp.escape(error.original)}\b/i) do |match|
|
|
161
|
+
colorize(match, :error)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Truncate if too long
|
|
165
|
+
if highlighted.length > 100
|
|
166
|
+
"..." + highlighted[-100..-1]
|
|
167
|
+
else
|
|
168
|
+
highlighted
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
# Format suggestions list with confidence scores.
|
|
173
|
+
#
|
|
174
|
+
# @param suggestions [Array<Suggestion>] List of suggestions
|
|
175
|
+
# @param max_display [Integer] Maximum suggestions to show (default: 5)
|
|
176
|
+
# @return [String] Formatted suggestions
|
|
177
|
+
def format_suggestions(suggestions, max_display: 5)
|
|
178
|
+
return colorize("No suggestions", :dim) unless suggestions&.any?
|
|
179
|
+
|
|
180
|
+
lines = []
|
|
181
|
+
suggestions.first(max_display).each_with_index do |suggestion, idx|
|
|
182
|
+
number = colorize((idx + 1).to_s + '.', :info)
|
|
183
|
+
word = colorize(suggestion.word, suggestion.high_confidence? ? :success : :warning)
|
|
184
|
+
confidence = "(#{(suggestion.confidence * 100).round(0)}%)"
|
|
185
|
+
|
|
186
|
+
line = " #{number} #{word} #{confidence}"
|
|
187
|
+
line += " [#{suggestion.source}]" if suggestion.source && @verbose
|
|
188
|
+
lines << line
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
if suggestions.size > max_display
|
|
192
|
+
remaining = suggestions.size - max_display
|
|
193
|
+
lines << colorize(" ... and #{remaining} more", :dim)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
lines.join("\n")
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# Display all errors with status indicators.
|
|
200
|
+
#
|
|
201
|
+
# @param navigation [NavigationManager] Navigation state
|
|
202
|
+
# @return [String] Formatted error list
|
|
203
|
+
def list_all_errors(navigation)
|
|
204
|
+
lines = []
|
|
205
|
+
lines << ""
|
|
206
|
+
lines << colorize("All Errors (#{navigation.errors.size})", :bold)
|
|
207
|
+
lines << ("─" * 70)
|
|
208
|
+
|
|
209
|
+
navigation.list_all.each do |line|
|
|
210
|
+
# Add color coding based on status
|
|
211
|
+
colored_line = if line.include?('[DONE]')
|
|
212
|
+
colorize(line, :success)
|
|
213
|
+
elsif line.include?('[SKIP]')
|
|
214
|
+
colorize(line, :dim)
|
|
215
|
+
else
|
|
216
|
+
line
|
|
217
|
+
end
|
|
218
|
+
lines << colored_line
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
lines << ""
|
|
222
|
+
lines.join("\n")
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Display statistics summary.
|
|
226
|
+
#
|
|
227
|
+
# @param navigation [NavigationManager] Navigation state
|
|
228
|
+
# @return [String] Formatted statistics
|
|
229
|
+
def statistics(navigation)
|
|
230
|
+
stats = navigation.statistics
|
|
231
|
+
|
|
232
|
+
lines = []
|
|
233
|
+
lines << ""
|
|
234
|
+
lines << colorize("Review Statistics", :bold)
|
|
235
|
+
lines << ("─" * 40)
|
|
236
|
+
lines << "Total: #{stats[:total]}"
|
|
237
|
+
lines << "Pending: #{stats[:pending]}"
|
|
238
|
+
lines << colorize("Modified: #{stats[:modified]}", :success)
|
|
239
|
+
lines << colorize("Skipped: #{stats[:skipped]}", :dim)
|
|
240
|
+
lines << ""
|
|
241
|
+
|
|
242
|
+
if stats[:by_type]&.any?
|
|
243
|
+
lines << colorize("By Type:", :bold)
|
|
244
|
+
stats[:by_type].each do |type, count|
|
|
245
|
+
label = SemanticError::ERROR_TYPES[type] || type.to_s.capitalize
|
|
246
|
+
lines << " #{label}: #{count}"
|
|
247
|
+
end
|
|
248
|
+
lines << ""
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
lines.join("\n")
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# Display help screen.
|
|
255
|
+
#
|
|
256
|
+
# @return [String] Formatted help text
|
|
257
|
+
def help_screen
|
|
258
|
+
lines = []
|
|
259
|
+
lines << ""
|
|
260
|
+
lines << colorize("═══ Interactive Review Help ═══", :bold)
|
|
261
|
+
lines << ""
|
|
262
|
+
lines << colorize("Navigation Commands:", :bold)
|
|
263
|
+
lines << " [Enter] or [n] Move to next error"
|
|
264
|
+
lines << " [b] Move to previous error"
|
|
265
|
+
lines << " [j] <number> Jump to error by number"
|
|
266
|
+
lines << " [f] Jump to first error"
|
|
267
|
+
lines << " [l] Jump to last error"
|
|
268
|
+
lines << ""
|
|
269
|
+
lines << colorize("Error Actions:", :bold)
|
|
270
|
+
lines << " [1-9] Accept suggestion by number"
|
|
271
|
+
lines << " [s] Skip current error"
|
|
272
|
+
lines << " [e] Edit custom replacement"
|
|
273
|
+
lines << ""
|
|
274
|
+
lines << colorize("Display Commands:", :bold)
|
|
275
|
+
lines << " [l] List all errors with status"
|
|
276
|
+
lines << " [t] Toggle show/hide context"
|
|
277
|
+
lines << " [v] Toggle verbose mode"
|
|
278
|
+
lines << " [?] Show this summary"
|
|
279
|
+
lines << ""
|
|
280
|
+
lines << colorize("Program Commands:", :bold)
|
|
281
|
+
lines << " [q] Quit and save changes"
|
|
282
|
+
lines << " [Q] Quit without saving"
|
|
283
|
+
lines << " [!] Export corrections to file"
|
|
284
|
+
lines << ""
|
|
285
|
+
lines << colorize("Filter Commands:", :bold)
|
|
286
|
+
lines << " [c] <level> Filter by confidence (high, medium, low)"
|
|
287
|
+
lines << " [y] <type> Filter by error type"
|
|
288
|
+
lines << " [a] Show all errors (clear filters)"
|
|
289
|
+
lines << ""
|
|
290
|
+
|
|
291
|
+
lines.join("\n")
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Display export summary.
|
|
295
|
+
#
|
|
296
|
+
# @param navigation [NavigationManager] Navigation state
|
|
297
|
+
# @param export_path [String] Path to export file
|
|
298
|
+
# @return [String] Formatted export summary
|
|
299
|
+
def export_summary(navigation, export_path)
|
|
300
|
+
corrections = navigation.export_corrections
|
|
301
|
+
|
|
302
|
+
lines = []
|
|
303
|
+
lines << ""
|
|
304
|
+
lines << colorize("═══ Export Summary ═══", :bold)
|
|
305
|
+
lines << ""
|
|
306
|
+
lines << "Exported #{corrections.size} corrections to:"
|
|
307
|
+
lines << colorize(export_path, :info)
|
|
308
|
+
lines << ""
|
|
309
|
+
|
|
310
|
+
if corrections.any? && @verbose
|
|
311
|
+
lines << colorize("Corrections:", :bold)
|
|
312
|
+
corrections.first(10).each do |corr|
|
|
313
|
+
lines << " Line #{corr[:line]}: #{corr[:original]} → #{corr[:replacement]}"
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
if corrections.size > 10
|
|
317
|
+
lines << colorize(" ... and #{corrections.size - 10} more", :dim)
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
lines << ""
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
lines.join("\n")
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
# Format input prompt.
|
|
327
|
+
#
|
|
328
|
+
# @param text [String] Prompt text
|
|
329
|
+
# @return [String] Formatted prompt
|
|
330
|
+
def prompt(text)
|
|
331
|
+
colorize("#{text} ", :info)
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
# Display warning message.
|
|
335
|
+
#
|
|
336
|
+
# @param message [String] Warning message
|
|
337
|
+
# @return [String] Formatted warning
|
|
338
|
+
def warning(message)
|
|
339
|
+
colorize("Warning: #{message}", :warning)
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
# Display error message.
|
|
343
|
+
#
|
|
344
|
+
# @param message [String] Error message
|
|
345
|
+
# @return [String] Formatted error
|
|
346
|
+
def error(message)
|
|
347
|
+
colorize("Error: #{message}", :error)
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
# Display success message.
|
|
351
|
+
#
|
|
352
|
+
# @param message [String] Success message
|
|
353
|
+
# @return [String] Formatted success
|
|
354
|
+
def success(message)
|
|
355
|
+
colorize(message, :success)
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
private
|
|
359
|
+
|
|
360
|
+
# Highlight error in context with visual markers.
|
|
361
|
+
#
|
|
362
|
+
# @param error [SemanticError] The error to highlight
|
|
363
|
+
# @return [String] Error with context markers
|
|
364
|
+
def highlight_in_context(error)
|
|
365
|
+
# For now, just show the error word with color
|
|
366
|
+
# In full implementation, would extract from context and add markers
|
|
367
|
+
colorize(error.original, :error)
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
# Format context for display.
|
|
371
|
+
#
|
|
372
|
+
# @param context [Context] The context object
|
|
373
|
+
# @return [String] Formatted context with line numbers
|
|
374
|
+
def format_context(context)
|
|
375
|
+
lines = []
|
|
376
|
+
|
|
377
|
+
# Before context
|
|
378
|
+
if context.before && !context.before.empty?
|
|
379
|
+
lines << colorize(context.before.split("\n").last(2).join("\n"), :dim)
|
|
380
|
+
end
|
|
381
|
+
|
|
382
|
+
# Current line with marker
|
|
383
|
+
current = "→ #{context.current}"
|
|
384
|
+
lines << current
|
|
385
|
+
|
|
386
|
+
# After context
|
|
387
|
+
if context.after && !context.after.empty?
|
|
388
|
+
lines << colorize(context.after.split("\n").first(2).join("\n"), :dim)
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
lines.join("\n")
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
# Get confidence label with indicator.
|
|
395
|
+
#
|
|
396
|
+
# @param confidence [Float] Confidence score (0.0 to 1.0)
|
|
397
|
+
# @return [String] Confidence label
|
|
398
|
+
def confidence_label(confidence)
|
|
399
|
+
case confidence
|
|
400
|
+
when 0.8..1.0 then colorize(CONFIDENCE_LABELS[:high], :success)
|
|
401
|
+
when 0.5..0.8 then colorize(CONFIDENCE_LABELS[:medium], :warning)
|
|
402
|
+
else colorize(CONFIDENCE_LABELS[:low], :dim)
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
# Get human-readable error type label.
|
|
407
|
+
#
|
|
408
|
+
# @param error_type [Symbol] Error type symbol
|
|
409
|
+
# @return [String] Human-readable label
|
|
410
|
+
def error_type_label(error_type)
|
|
411
|
+
SemanticError::ERROR_TYPES[error_type] || error_type.to_s.capitalize
|
|
412
|
+
end
|
|
413
|
+
|
|
414
|
+
# Apply color to text if colors are enabled.
|
|
415
|
+
#
|
|
416
|
+
# @param text [String] Text to colorize
|
|
417
|
+
# @param color [Symbol] Color symbol
|
|
418
|
+
# @return [String] Colorized text or original if colors disabled
|
|
419
|
+
def colorize(text, color)
|
|
420
|
+
return text unless @color_enabled
|
|
421
|
+
|
|
422
|
+
code = COLORS[color]
|
|
423
|
+
return text unless code
|
|
424
|
+
|
|
425
|
+
"#{code}#{text}#{COLORS[:reset]}"
|
|
426
|
+
end
|
|
427
|
+
end
|
|
428
|
+
end
|
|
429
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "thor"
|
|
4
|
+
|
|
5
|
+
module Kotoshu
|
|
6
|
+
module Cli
|
|
7
|
+
# Semantic error classes for the CLI. Subclass Thor::Error so the CLI's
|
|
8
|
+
# top-level dispatcher can catch them and exit with the appropriate code.
|
|
9
|
+
# Each class carries an `exit_status` that the dispatcher reads.
|
|
10
|
+
module Errors
|
|
11
|
+
# Base class for all CLI errors. Carries an exit_status.
|
|
12
|
+
class CliError < Thor::Error
|
|
13
|
+
attr_reader :exit_status
|
|
14
|
+
|
|
15
|
+
def initialize(message, exit_status:)
|
|
16
|
+
super(message)
|
|
17
|
+
@exit_status = exit_status
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Usage error: bad flags, missing argument, file not found (exit 2).
|
|
22
|
+
class UsageError < CliError
|
|
23
|
+
def initialize(message)
|
|
24
|
+
super(message, exit_status: 2)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Resource unavailable: network down, offline+uncached, integrity failure (exit 3).
|
|
29
|
+
class ResourceUnavailable < CliError
|
|
30
|
+
def initialize(message)
|
|
31
|
+
super(message, exit_status: 3)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Kotoshu
|
|
4
|
+
module Cli
|
|
5
|
+
# Matcher for .gitignore / .ignore files — the standard glob
|
|
6
|
+
# subset, implemented in Ruby (no shelling out to git).
|
|
7
|
+
#
|
|
8
|
+
# Supported subset (documented honestly):
|
|
9
|
+
# - one pattern per line; blank lines and lines starting with #
|
|
10
|
+
# are ignored
|
|
11
|
+
# - leading ! negates a pattern; a leading backslash escapes a
|
|
12
|
+
# literal ! or #
|
|
13
|
+
# - a trailing / restricts the pattern to directories
|
|
14
|
+
# - a leading / anchors the pattern to the ignore file's
|
|
15
|
+
# directory; any pattern containing an interior / is anchored
|
|
16
|
+
# - * matches anything except /; ? matches one non-/ character
|
|
17
|
+
# - ** as a whole path segment: **/x matches x at any depth, x/**
|
|
18
|
+
# matches everything below x, a/**/b matches b at any depth
|
|
19
|
+
# under a
|
|
20
|
+
# - the last matching pattern wins (later lines override earlier
|
|
21
|
+
# ones), like git
|
|
22
|
+
#
|
|
23
|
+
# Like git, a file cannot be re-included once a parent directory
|
|
24
|
+
# is excluded: the walker never descends into an ignored
|
|
25
|
+
# directory, so a negation deeper in the tree has no effect
|
|
26
|
+
# there.
|
|
27
|
+
#
|
|
28
|
+
# Each matcher is scoped to the directory holding its ignore
|
|
29
|
+
# file; paths are matched relative to that directory.
|
|
30
|
+
class IgnoreMatcher
|
|
31
|
+
IGNORE_FILENAMES = %w[.gitignore .ignore].freeze
|
|
32
|
+
|
|
33
|
+
# One compiled ignore pattern.
|
|
34
|
+
class Pattern
|
|
35
|
+
attr_reader :source, :negated, :dir_only, :regex
|
|
36
|
+
|
|
37
|
+
# Compile one ignore-file line.
|
|
38
|
+
#
|
|
39
|
+
# @param line [String] the raw line from the ignore file
|
|
40
|
+
def initialize(line)
|
|
41
|
+
@source = line
|
|
42
|
+
escaped = line.match?(/\A\\[!#]/)
|
|
43
|
+
body = escaped ? line[1..] : line
|
|
44
|
+
@negated = !escaped && body.start_with?("!")
|
|
45
|
+
body = body.delete_prefix("!") if @negated
|
|
46
|
+
@dir_only = body.end_with?("/")
|
|
47
|
+
body = body.sub(%r{/+\z}, "")
|
|
48
|
+
anchored = body.start_with?("/") || body.include?("/")
|
|
49
|
+
body = body.delete_prefix("/")
|
|
50
|
+
@regex = build_regex(body, anchored: anchored)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Whether this pattern matches a path relative to the ignore
|
|
54
|
+
# file's directory.
|
|
55
|
+
#
|
|
56
|
+
# Directory-only patterns are evaluated solely against
|
|
57
|
+
# directories. Otherwise, a pattern matching any ancestor
|
|
58
|
+
# directory covers everything below it (gitignore
|
|
59
|
+
# semantics).
|
|
60
|
+
#
|
|
61
|
+
# @param relative [String] relative path
|
|
62
|
+
# @param directory [Boolean] whether the path is a directory
|
|
63
|
+
# @return [Boolean]
|
|
64
|
+
def matches?(relative, directory: false)
|
|
65
|
+
return false if @dir_only && !directory
|
|
66
|
+
|
|
67
|
+
return true if @regex.match?(relative)
|
|
68
|
+
|
|
69
|
+
segments = relative.split("/")
|
|
70
|
+
segments.first(segments.length - 1).each_with_object(+"") do |segment, prefix|
|
|
71
|
+
prefix << (prefix.empty? ? segment : "/#{segment}")
|
|
72
|
+
return true if @regex.match?(prefix)
|
|
73
|
+
end
|
|
74
|
+
false
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
# Compile the glob body into a Regexp.
|
|
80
|
+
#
|
|
81
|
+
# @param body [String] glob without negation/trailing-slash
|
|
82
|
+
# markers
|
|
83
|
+
# @param anchored [Boolean] whether the pattern is anchored
|
|
84
|
+
# to the ignore file's directory
|
|
85
|
+
# @return [Regexp]
|
|
86
|
+
def build_regex(body, anchored:)
|
|
87
|
+
translated = self.class.glob_body(body)
|
|
88
|
+
anchored ? /\A#{translated}\z/ : /(?:\A|\/)#{translated}\z/
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class << self
|
|
92
|
+
# Translate a gitignore glob body into a regex source.
|
|
93
|
+
#
|
|
94
|
+
# @param body [String] glob body
|
|
95
|
+
# @return [String] regex source
|
|
96
|
+
def glob_body(body)
|
|
97
|
+
parts = body.split("/")
|
|
98
|
+
out = +""
|
|
99
|
+
parts.each_with_index do |part, index|
|
|
100
|
+
if part == "**"
|
|
101
|
+
append_double_star(out, last: index == parts.length - 1)
|
|
102
|
+
else
|
|
103
|
+
append_segment(out, translate_segment(part), after_double_star: index.positive? && parts[index - 1] == "**")
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
out
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
private
|
|
110
|
+
|
|
111
|
+
# Append the translation for a ** segment.
|
|
112
|
+
#
|
|
113
|
+
# @param out [String] accumulator
|
|
114
|
+
# @param last [Boolean] whether ** ends the pattern
|
|
115
|
+
def append_double_star(out, last:)
|
|
116
|
+
out << (if out.empty?
|
|
117
|
+
".*"
|
|
118
|
+
else
|
|
119
|
+
(last ? "/.*" : "(?:[^/]*/)*")
|
|
120
|
+
end)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Append a translated normal segment with its separator.
|
|
124
|
+
#
|
|
125
|
+
# @param out [String] accumulator
|
|
126
|
+
# @param segment [String] translated segment
|
|
127
|
+
# @param after_double_star [Boolean] whether the previous
|
|
128
|
+
# segment was a non-final **
|
|
129
|
+
def append_segment(out, segment, after_double_star:)
|
|
130
|
+
out << "/" unless out.empty? || after_double_star
|
|
131
|
+
out << segment
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Translate one non-** segment.
|
|
135
|
+
#
|
|
136
|
+
# @param segment [String] raw segment
|
|
137
|
+
# @return [String] regex source for the segment
|
|
138
|
+
def translate_segment(segment)
|
|
139
|
+
Regexp.escape(segment).gsub('\*', '[^/]*').gsub('\?', '[^/]')
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Load all ignore files present in a directory.
|
|
145
|
+
#
|
|
146
|
+
# @param directory [String] absolute path to scan
|
|
147
|
+
# @return [IgnoreMatcher] matcher with the merged patterns in
|
|
148
|
+
# file order (.gitignore first, then .ignore)
|
|
149
|
+
def self.load_directory(directory)
|
|
150
|
+
lines = IGNORE_FILENAMES.filter_map do |name|
|
|
151
|
+
path = File.join(directory, name)
|
|
152
|
+
File.file?(path) ? File.readlines(path, chomp: true) : nil
|
|
153
|
+
end.flatten
|
|
154
|
+
new(lines)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# Whether a directory holds at least one ignore file.
|
|
158
|
+
#
|
|
159
|
+
# @param directory [String] absolute path to scan
|
|
160
|
+
# @return [Boolean]
|
|
161
|
+
def self.present_in?(directory)
|
|
162
|
+
IGNORE_FILENAMES.any? { |name| File.file?(File.join(directory, name)) }
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# @param lines [Array<String>] raw ignore-file lines
|
|
166
|
+
def initialize(lines)
|
|
167
|
+
@patterns = lines.filter_map { |line| compile(line) }
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
# The compiled patterns, in file order.
|
|
171
|
+
#
|
|
172
|
+
# @return [Array<Pattern>]
|
|
173
|
+
def patterns
|
|
174
|
+
@patterns
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Whether a path is ignored. Last matching pattern wins.
|
|
178
|
+
#
|
|
179
|
+
# @param relative [String] path relative to the ignore file's
|
|
180
|
+
# directory
|
|
181
|
+
# @param directory [Boolean] whether the path is a directory
|
|
182
|
+
# @return [Boolean] true when the path is ignored
|
|
183
|
+
def ignored?(relative, directory: false)
|
|
184
|
+
ignored = false
|
|
185
|
+
@patterns.each do |pattern|
|
|
186
|
+
ignored = !pattern.negated if pattern.matches?(relative, directory: directory)
|
|
187
|
+
end
|
|
188
|
+
ignored
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
private
|
|
192
|
+
|
|
193
|
+
# Compile one raw line, skipping blanks and comments.
|
|
194
|
+
#
|
|
195
|
+
# @param line [String] raw line
|
|
196
|
+
# @return [Pattern, nil]
|
|
197
|
+
def compile(line)
|
|
198
|
+
stripped = line.sub(/[ \t]+\z/, "")
|
|
199
|
+
return nil if stripped.empty? || stripped.start_with?("#")
|
|
200
|
+
|
|
201
|
+
Pattern.new(stripped)
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|