Skip to content

Command line: AutoComplete learns the commands used most - #24

Merged
SkryxDev merged 1 commit into
mainfrom
feat/cmdline-adaptive-suggestions
Nov 18, 2026
Merged

SkryxDev merged 1 commit into
mainfrom
feat/cmdline-adaptive-suggestions

Conversation

@SkryxDev

Copy link
Copy Markdown
Member

Implements the community request "Alias/Command Suggestion biasing" (from Treasure, using the web demo): typing LI lists LIST first, though LINE is used far more. The command line now learns which commands its user runs, as AutoCAD's adaptive suggestions and the fish shell do, with no alias editing.

How it ranks

  • Every command run from the command line (typed by name or alias, picked with the arrows, clicked in the list, or completed with Tab) adds 1 to its score, keyed by the resolved command id (l, li→LINE and line all count for LINE).
  • Scores decay with use, not wall-clock time: a score halves every 300 later command runs. Recent habits win over old ones, a week away changes nothing, and the result is deterministic (and the same on wasm). The scoring is a pure function (cmd_usage::decayed, cmd_usage::rank) with unit tests.
  • Suggestions are sorted by score. Ties keep the existing order (exact match, then id prefix, then alias prefix), so nothing changes until something is learned.
  • An exactly typed full command name always stays first. An exactly typed alias counts as 3 uses (EXACT_ALIAS_BONUS), so a couple of stray uses don't take its place. After about 4 uses LINE moves above LIST for LI, and Enter on LI then runs LINE. LIST stays one Down away, and choosing it counts for it.
  • Ranking happens before the list is cut to 8, so a well-used command can enter the list.
  • Scripts, the control channel, MCP and cmdline.input are not affected. Only the interactive Enter/Tab/click in the UI uses the learned order.

Keyboard

Treasure described "type li, key down to LINE, Enter". The list had no keyboard navigation, so it does now:

  • Up/Down move through the AutoComplete list while one is shown and the text was typed. Up on the first row, or while browsing the history, still browses the history as before.
  • Enter and Tab take the highlighted row. Typing anything else goes back to the first row.

Storage and bounds

  • Kept in the interface preferences (prefs_json → cmdlineUsage), which the desktop app and the web build (localStorage via eframe storage) already persist. Nothing is written while nothing has been learned.
  • Loaded data is treated as hostile:
    • a malformed whole is ignored, and malformed entries are skipped;
    • ids are validated;
    • scores must be finite and ≤ 1000;
    • at most 200 commands are kept (the lowest scores are dropped) and at most 800 entries are read;
    • the logical clock is rebased before it reaches 2^40.
  • No unwrap, expect or panic in non-test code.

Reset

ui.cmdline.resetsuggestions (Reset Suggestion Order) forgets everything learned. It is in the command line's right-click menu, next to Clear Command History, and greyed out while nothing is learned. It has no ribbon button: AutoCAD keeps its AutoComplete settings in the command line's shortcut menu too, and ui.cmdline.clear sets the precedent. Translations are in it/zh and the 12 other languages that already translate that menu (de/fr/ru don't have it yet).

Tests

  • cmd_usage::tests: decay, ranking ties and NaN, recency over frequency, caps, clock rebase, round trip, corrupt stored values ignored.
  • cmdline::autocomplete_tests:
    • li_lists_line_above_list_once_line_is_used_more
    • uses_typed_in_any_form_count_and_fade
    • learning_moves_a_command_into_the_shortened_list
    • arrows_move_the_highlight_and_typing_resets_it
    • learned_order_is_kept_with_the_preferences_and_can_be_reset (corrupt prefs included)
  • cargo xtask ci: fmt, clippy, i18n, assets, layers and wasm pass. All tests pass except the three known macOS-only failures (read_file_refuses_a_name_that_is_not_unicode, usage::non_unicode_output_names, thai_marks_stack_in_an_installed_font).
  • Checked in the running app over the control channel:
    • li lists LI (LIST) first;
    • Down highlights LINE;
    • after choosing LINE 4 times, LINE is first and highlighted;
    • after a restart, li + Enter starts LINE.

🤖 Generated with Claude Code

Commands run from the command line (typed, picked with the arrows, or
clicked in the list) feed a frecency score per command: +1 per use, halved
every 300 later command runs. Suggestions are ranked by it; ties keep the
old order. A full command name typed exactly always stays first; an exact
alias counts as 3 uses, so LI lists LINE above LIST once LINE is used more.

- Up/Down move through the AutoComplete list; Enter and Tab take the
  highlighted row.
- Scores persist in the interface prefs (cmdlineUsage), also on the web;
  loaded data is validated and capped (200 commands, score 1000).
- Reset Suggestion Order in the command line's shortcut menu forgets it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SkryxDev
SkryxDev merged commit 64499f4 into main Nov 18, 2026
4 checks passed
@SkryxDev
SkryxDev deleted the feat/cmdline-adaptive-suggestions branch November 18, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant