

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
123456# Search Functionality Guide78This guide explains how the search system works in Script Kit based on comprehensive test coverage analysis.910## Core Files1112- **Main Implementation**: [src/main/search.ts](mdc:src/main/search.ts)13- **Test Coverage**: [src/main/search.test.ts](mdc:src/main/search.test.ts)14- **Helper Functions**: [src/main/helpers.ts](mdc:src/main/helpers.ts)1516## Main Search Functions1718### `invokeSearch(prompt, input, reason?)`1920The primary search function that handles choice filtering, searching, and grouping.2122**Key Behaviors:**23- Returns early if UI is not `arg` type or choices array is empty24- Transforms input using `inputRegex` if set (extracts match groups)25- For empty input: shows non-filtered choices (excludes `miss`, `pass`, `hideWithoutInput`)26- For non-empty input: uses QuickScore for fuzzy search with fallback to manual string matching2728**Choice Type Handling:**29- **Info choices**: Treated as regular choices, always shown for empty input30- **Miss choices**: Only shown in fallback when no regular choices exist31- **Pass choices**: Excluded from regular results, shown in fallback32- **hideWithoutInput choices**: Only shown when input is not empty3334**Grouping Logic:**35- Uses complex grouping when `hasGroup` is true36- Creates "Exact Match" group headers for grouped results37- Handles `lastGroup` choices separately at the end38- Supports alias and trigger matching with special group headers3940### `invokeFlagSearch(prompt, input)`4142Handles flag-specific search functionality.4344**Behaviors:**45- For empty input: filters out `pass`, `hideWithoutInput`, `miss` flags46- Supports grouped flag search with match headers47- Falls back to miss flags when no results found4849### `setFlags(prompt, flags)`5051Configures flag choices and sets up flag search.5253**Process:**541. Converts flag object to choice array format552. Applies grouping if any flags have groups563. Formats choices and sets up QuickScore instance574. Triggers initial flag search5859### `setShortcodes(prompt, choices)`6061Manages shortcodes, keywords, triggers, and postfixes.6263**Important Implementation Details:**64- **Bug**: Keywords map is NOT cleared (only shortcodes, triggers, postfixes are cleared)65- **Keywords**: Only processes `choice.keyword` property, not `tag`66- **Triggers**: Extracts from `choice.trigger` or parses `[trigger]` from choice name67- **Postfixes**: Only string `pass` values that don't start with `/` (not regex)68- **Shortcodes**: Case-insensitive storage6970### `setChoices(prompt, choices, options)`7172Main function for setting up search choices.7374**Process:**751. Filters out choices with `exclude: true`762. Handles caching for main script choices773. Sets up QuickScore instance with configurable scoring784. Calls `setShortcodes` to process special choice properties795. Triggers initial search unless `skipInitialSearch` is true8081## Search Algorithm Details8283### Empty Input Logic84```851. Filter choices: exclude miss, pass, hideWithoutInput862. Include info choices as regular choices873. If no regular choices found → show miss and info choices as fallback88```8990### Non-Empty Input Logic91```921. Use QuickScore for fuzzy search932. If grouped: complex grouping with exact match headers943. If no results: manual string matching across search keys954. Apply filtering based on choice types (miss, pass, info)96```9798### Grouping Behavior99- **startsWithGroup**: Choices whose names start with the search input100- **includesGroup**: Choices whose names include the search input (but don't start with it)101- **matchLastGroup**: Choices with `lastGroup: true`, sorted by keyword presence102- **Exact Match header**: Added when grouped results exist103104## Important Edge Cases105106### Regex Pass Patterns107- Choices with `pass: '/regex/i'` are tested against input108- Invalid regex patterns are handled gracefully without throwing109110### Manual String Matching111- When QuickScore returns no results, fallback to manual searching112- Searches across all keys defined in `prompt.kitSearch.keys`113- Creates scored choices with match positions114115### Choice Filtering Priority116```117miss choices: only in fallback scenarios118pass choices: included in fallback119info choices: treated as regular choices120hideWithoutInput: only shown when input exists121```122123## Performance Considerations124125- Uses QuickScore with configurable max iterations (env: `KIT_SEARCH_MAX_ITERATIONS`)126- Configurable minimum score threshold (env: `KIT_SEARCH_MIN_SCORE`)127- Debounced search with 100ms delay (`debounceInvokeSearch`)128- Caches main script choices for performance129130## Testing Coverage131132The search functionality has **39 comprehensive tests** covering all aspects with a focus on realistic testing:133134### Real Implementations Used135- **QuickScore**: Actual search and scoring algorithms for realistic behavior136- **Pure utility functions**: formatChoices, groupChoices, createScoredChoice use real implementations137- **Kit utils**: Most @johnlindquist/kit/core/utils functions run unmodified138139### Strategic Mocking140- **lodash debounce**: Mocked for immediate execution (testing search logic, not timing)141- **State management**: Mocked kitCache and kitState for test isolation142- **External dependencies**: Logging and messages mocked to avoid test noise143144### Test Coverage Areas145- All main functions and their edge cases146- Choice type handling and filtering logic (miss, pass, info, hideWithoutInput)147- Grouping and sorting behaviors (including complex lastGroup logic)148- Configuration functions (setChoices, setFlags, setShortcodes)149- Caching and performance optimizations150- Error handling and fallback scenarios151152This approach provides realistic test behavior while maintaining fast, deterministic tests. Tests assume current implementation is correct and capture actual behavior for safe refactoring.153154## Known Issues1551561. **Keywords map not cleared**: `setShortcodes` doesn't clear the keywords map (potential memory leak)1572. **Tag property ignored**: Only `keyword` property is processed for keywords, not `tag`1583. **Complex grouping logic**: The grouping algorithm is quite complex and could benefit from simplification159160This documentation serves as a foundation for understanding the search system before refactoring for cleanliness and reliability.161
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| script-kit/app.cursor/rules/_testing.mdc · 97 | Cursor rules | setupteststylearch+5 | 81/100 | today | |
| script-kit/app.cursor/rules/debugging-logs.mdc · 97 | Cursor rules | archagent-behaviour | 54/100 | today | |
| script-kit/app.cursor/rules/debugging-workflow.mdc · 97 | Cursor rules | lint-formatarchagent-behaviour | 58/100 | today | |
| script-kit/app.cursor/rules/development-workflow.mdc · 97 | Cursor rules | lint-formatstyletypesagent-behaviour | 61/100 | today |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 46 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 14 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 14 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 14 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 14 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 46 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/script-kit-app-cursor-rules-search)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.