Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spell Checker Mod for Command Code

A Command Code mod that automatically corrects typos and misspellings in your input before it reaches the agent. Implements the SymSpell algorithm — the same engine used in many production spell checkers.

What It Does

  • Autocorrects typos in every message you send — tehthe, recievereceive, accomodateaccommodate
  • Compound-aware correction — handles split words (the quickbrownfoxthe quick brown fox) and merged words ("the horible" gets corrected word-by-word)
  • Word segmentation — inserts missing spaces in concatenated strings (thequickbrownfoxthe quick brown fox)
  • Reference protection — won't mangle image refs (![alt](img.png)), @file mentions, or file paths during correction
  • Case preservation — respects UPPERCASE, Titlecase, and lowercase patterns of the original text

What It's Based On

  • SymSpell algorithm by Wolf Garbe (original C#, JS port)
  • Wikipedia-sourced frequency dictionary of 82,765 English words
  • OSA Damerau-Levenshtein edit distance with early termination (optimized via SoftWx.Match)
  • Zero external dependencies — entirely self-contained TypeScript

Usage

Load the mod when starting Command Code:

cmd --mod .commandcode/mods/spell-checker.ts

Flags

Set these at launch to control initial behavior:

Flag Default Description
--mod-option spell-enabled=false true Enable/disable spell checking
--mod-option spell-max-distance=2 2 Maximum edit distance (1 or 2)
--mod-option spell-debug=true false Show detailed correction info
--mod-option spell-show-original=false true Show original text alongside corrections

Commands

Command Description
/spell-config Show all configuration settings
/spell-config <key> <value> Change a setting (enabled, maxDistance, debug, showOriginal)
/spell-check <word> Check a word and get suggestions
/spell-add <word> Add a word to the dictionary
/spell-segment <text> Segment and correct concatenated text
/spell-compound <text> Test compound-aware correction
/spell-load <path> Load a custom frequency dictionary file
/spell-bigrams <path> Load a bigram dictionary
/spell-status Show dictionary stats and settings
/spell-test Run built-in correctness tests

Examples

Autocorrect in messages:

You> i think teh recieve function is definately broken
→ Corrected to: i think the receive function is definitely broken

Check a word:

/spell-check recieve
→ Suggestions for "recieve":
    receive (distance: 1, frequency: 112,856)
    relieve (distance: 1, frequency: 5,475)

Segment concatenated text:

/spell-segment thequickbrownfox
→ Input:      "thequickbrownfox"
   Segmented:  "the quick brown fox"
   Corrected:  "the quick brown fox"

Compound-aware correction:

/spell-compound the horible wethaer
→ Input:      "the horible wethaer"
   Corrected:  "the horrible weather"
   Distance:   2

Add a word to the dictionary:

/spell-add lofi
→ Added "lofi" to dictionary (frequency: 10)

Toggle debug mode:

/spell-config debug true
→ debug = true

Now corrections show what changed: Corrected: definately → definitely, accomodate → accommodate

Disable temporarily:

/spell-config enabled false
→ enabled = false

(Re-enable with /spell-config enabled true)

Run tests to verify everything works:

/spell-test
→ Single-word corrections:
    ✓ teh: "the"
    ✓ recieve: "receive"
    ✓ occurance: "occurrence"
    ...
  Results: 30 passed, 0 failed, 30 total

How It Works

  1. Dictionary — 82,765 words are loaded at startup from the official SymSpell frequency dictionary (bundled as frequency_dictionary_en_82_765.txt)
  2. Delete index — Each dictionary word generates delete variants up to maxDistance edits, stored in a lookup index for O(n) correction
  3. Match — On input, the mod generates delete variants of each word and looks them up in the index, finding candidates within the configured edit distance
  4. Reference protection — Before correction, ![image](...), @file.ts, and path-like tokens (src/foo/bar) are split out and preserved, preventing false corrections on filenames and URLs
  5. Case preservation — The casing pattern of the original word is applied to the correction

Files

.commandcode/mods/
├── spell-checker.ts                              # Entry point (~160 lines)
├── spell-checker/
│   ├── lib/
│   │   ├── symspell.ts                           # SymSpell algorithm (core engine)
│   │   ├── types.ts                              # Shared type definitions
│   │   ├── config.ts                             # Configuration management
│   │   └── text-processing.ts                    # Text correction & reference protection
│   └── commands/
│       ├── types.ts                              # Command context types
│       ├── spell-config.ts                       # /spell-config command
│       ├── spell-load.ts                         # /spell-load command
│       ├── spell-check.ts                        # /spell-check command
│       ├── spell-add.ts                          # /spell-add command
│       ├── spell-status.ts                       # /spell-status command
│       ├── spell-segment.ts                      # /spell-segment command
│       ├── spell-compound.ts                     # /spell-compound command
│       ├── spell-bigrams.ts                      # /spell-bigrams command
│       └── spell-test.ts                         # /spell-test command
│   └── data/
│       ├── frequency_dictionary_en_82_765.txt    # Bundled word frequency dictionary (1.3 MB)
│       └── noisy_query_en_1000.txt               # Test data (1000 noisy queries)

Memory

The full dictionary with its delete index uses 80–150 MB of memory. This is inherent to how SymSpell works — it trades memory for O(n) correction speed by precomputing every possible deletion of every word up to the max edit distance. Without this index, correcting a single word would require computing edit distance against all 83K dictionary entries inline, which would be unusably slow for real-time input processing.

Limitations

  • Quoted prompts not supported — Spell checking does not currently run on input submitted via Command Code's quick-edit feature (pressing ' to re-submit a previous message). Only directly typed input is corrected.
  • Single-language — The bundled dictionary is English-only. Other languages require loading a custom dictionary via /spell-load.
  • Does not learn — Corrections are based solely on the frequency dictionary and do not adapt to your writing style over time. Words added via /spell-add persist only for the current session.

About

Spell Checker Mod for Command Code

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages