How does Warp's completion system work beyond the menu keys — engine internals, the ghost's content source, the history store, matching breadth, and the corpus format — and what should DropTerm copy for depth?
Question: Warp's client is open source; what are the full mechanics of its
completion engine (expansion, matching, ranking, coalescing), the
autosuggestion ghost's content source, the history store behind it, the
spec-corpus format, and the surrounding surface (command scanning, native
shell completions, settings) — everything warp-completion-behavior.md
stopped short of — so DropTerm can copy the capability depth, not just the
menu keys?
Date: 2026-11-24
Method: four read-only research sweeps over the same pinned checkout —
github.com/warpdotdev/warp @ f8223ce (committed 2026-11-20; local clone
/tmp/warp-src, the identical rev the shipped record cites) and the corpus
repo github.com/warpdotdev/command-signatures @ 48fd7aa (the exact rev
pinned by Warp's workspace; local clone /tmp/warp-specs). This record
consolidates the sweeps; it supplements — never rewrites — the shipped
warp-completion-behavior record, whose menu
mechanics (findings 3-5), match policy sketch (finding 2), and corpus
premise (finding 7) carry over unchanged.
TL;DR: Warp's depth is four systems, all in the open source except the
LLM server. (1) The engine is a parse → locate → expand-aliases → dispatch →
coalesce → filter-at-query pipeline whose default match strategy is fuzzy
(exact case-sensitive → exact case-insensitive → prefix → fuzzy by score,
fuzzy refusing punctuation-only queries), with priority-clamped buckets and
a display-deduped, uncapped result list. (2) The ghost's content comes from
a three-tier chain over a fully open sqlite history store — similar-context
next-command counting (same command prefix, equal pwd + exit code + shell,
top-5 most common, 25-context cap), then recency with pwd preference, then
the completer engine as fallback — with the "intelligent" AI tier being a
skip-LLM-if-history-is-sure wrapper whose only closed piece is the server
endpoint. (3) Matching breadth is the default strategy: paths, variables,
commands, flags, and arguments all match case-insensitively and fuzzily by
default, while the Tab LCP fill deliberately stays case-sensitive. (4) The
corpus is compile-time-embedded MIT JSON (496 hand-written + 663
autogenerated PowerShell specs) behind a lazy per-command parse cache, with
several parsed-but-dropped fields (exclusiveOn, dependsOn,
history/help templates, insertValue) a reimplementation may legally
keep. Everything else (per-shell command scanning via the user's own shell,
OSC 9280 native shell completions, menu chrome) is documented below with its
DropTerm verdict. Behavior only: no AGPL code crosses.
Findings
All path:line citations are into the local clones above, repo-root
relative (crates/warp_completer/src/… abbreviated wc/… where noted).
The shipped record's citation discipline applies unchanged.
1. The engine pipeline, in depth (shipped record finding 2, expanded)
- Entry:
suggestions(line, pos, …)truncates the line toline[0..pos]— only text before the cursor is completed on — and returnsNonefor an empty/whitespace line (wc/completer/suggest/mod.rs:631-634). - Parse:
parse_for_completionskeeps only the last unclosed command, recursing into open subshells —echo $(git ccompletes inside the subshell (wc/parsers/simple/mod.rs:21-37, 161-183). - Locate: the parsed command flattens into
Vec<CompletionLocation>= Command / Flag / Argument / Variable, each spanned; the cursor's location is chosen with an inclusive span test ("no space between cursor and text"), and the caller'sreplacement_spanis the last location's span (wc/completer/engine/mod.rs:24-51, 379-507;wc/completer/suggest/mod.rs:671-674). - Cursor-fallback heuristics: between tokens, text containing
|,(,;marks a command position; otherwise both an Argument and a Flag location are yielded (arg-only after--) (wc/completer/engine/mod.rs:376, 462-492). Typing-produces both an Argument and a Flag location ("the user is likely expecting a flag"); typing any non-dash character suppresses the flag location (wc/completer/engine/mod.rs:426-447). - Alias expansion runs after the first parse/locate — "We had to parse
before alias expansion in order to get the correct replacement span" —
capped at 5 indirections, each alias expanded at most once, top-level
aliases only when a space follows (
"kgp"never expands,"kgp "does), then the line re-parses and re-locates (wc/completer/suggest/mod.rs:696-705;wc/completer/suggest/alias.rs:11-29, 121-141, 213-242). - Dispatch routes each location to one engine: command, variable (env-var
names), flag, argument
(
wc/completer/suggest/legacy.rs:29-80). - Coalesce: results bucket by clamped priority [-100, 100] into high /
default / low; default rows keep engine order grouped by suggestion
type (Command → Variable → Argument → Subcommand → Option — "We don't
sort default priority suggestions to preserve the ordering produced by
the completion engine"); high and low buckets sort by descending
priority, ties lexicographic by display (trailing path separators
trimmed, case-insensitive); the concatenation dedupes by display
string, first occurrence wins (
wc/completer/completer/coalesce.rs:11-67;wc/completer/suggest/priority/mod.rs:9-13;wc/completer/suggest/mod.rs:113-136, 204-211). - Filter-at-query: ordering happens per keystroke in
filter_by_query— (1) a single case-sensitive exact; (2) a single case-insensitive exact (later exact duplicates of the same display are silently dropped); (3) all prefix matches in coalesce order; (4) fuzzy matches by descending score, with the stable sort.rev()ed so fuzzy ties surface in reverse insertion order (wc/completer/suggest/mod.rs:308-314, 362-389, 404-414). - Hidden suggestions surface only on exact match
(
wc/completer/suggest/mod.rs:362-365). - Tab resolution (
explicit_tab_completion): exactly one case-sensitive prefix/exact candidate inserts directly; else the LCP over case-sensitive prefix/exact matches' replacement strings inserts and opens iffcommon_prefix.len() > replacement_span.distance() && common_prefix.starts_with(query); else the menu opens (wc/completer/suggest/mod.rs:457-510, 513-581). The app-side Tab path mirrors it and adds the guard "Ignore fuzzy matches when calculating longest common prefix" (app/src/terminal/input.rs:13696-13755).
2. Matching breadth: the default strategy is fuzzy, the fill stays case-sensitive
MatchStrategyhas three flavors: CaseSensitive (cs matches only), CaseInsensitive (cs + ci), Fuzzy (ci exact/prefix first, then a fuzzy fallback). The engine's defaultmatch_strategyis Fuzzy (wc/completer/completer/matchers.rs:30-40, 52-82;wc/completer/suggest/mod.rs:609-618).- The fuzzy fallback refuses punctuation-only queries: "Only fall back to a
subsequence match for a query with at least one alphanumeric character.
Fuzzy matches on punctuation produce poor results."
(
wc/completer/completer/matchers.rs:72-76). - Fuzzy backend:
SkimMatcherV2::default().ignore_case()from the MITfuzzy-matcher0.3.7 crate — the scoring is upstream's defaults, pinned here for reimplementation: base 16 per matched char; word-head bonus 8; after-soft-separator 7; camel 6; consecutive-run floor 4; gap start −3, extension −1; first-char bonus ×2; case-mismatch penalty −2 (smart-case: the match is case-sensitive iff the query carries an uppercase char); affine-gap DP whose carried run bonus persists through consecutive runs; ties resolve to the rightmost alignment (crates/fuzzy_match/src/lib.rs:55-90; upstreamfuzzy-matcher/src/skim.rs:318-334, 489-543, 690-748, 774-832). - A separate wildcard/glob matcher (
*/?, ASCII-case-insensitive, scores 800/1000/2000 by pattern shape) exists for file search — not the completion path (crates/fuzzy_match/src/lib.rs:217-294). - Everything matches this ladder: commands, flags, arguments, static
suggestion lists, env variables, and paths — path entries match the
typed token's last segment with the caller's strategy (usually Fuzzy)
(
wc/completer/engine/path.rs:310). - The case-sensitivity split the shipped record flagged (finding 4) is the
deliberate asymmetry: rows match ci/fuzzy, the Tab fill stays
case-sensitive over cs prefix/exact rows — "inserting a shorter prefix
would shorten the input" (
app/src/terminal/input.rs:13703-13742).
3. The ghost's content source: three tiers over an open sqlite store
The ghost is editor-native text appended after the buffer, active while the
buffer is unchanged or only grows by a prefix of the ghost
(app/src/editor/view/mod.rs:3517-3547; location always EndOfBuffer,
app/src/terminal/input.rs:8413-8427). Its content, per keystroke (the
previous request aborted; no debounce and no staleness timer —
freshness is abort + buffer-equality on arrival,
app/src/terminal/input.rs:10165-10395, 17304-17329):
- Similar-context history first: the last completed block's
command/pwd/exit_code/shell_host queries
get_similar_history_contexton a read-only sqlite connection; next commands that start with the typed prefix are counted,k_most_common_ordered(5)taken, and the first valid one returned (app/src/terminal/input.rs:10270-10318). - Recency with pwd preference: the most recent prefix-matching history
command, preferring the current working directory
(
app/src/terminal/input.rs:10322-10340;app/src/ai/predict/next_command_model.rs:837-862). - The completer engine as fallback:
completer::suggestions(…, MatchStrategy::CaseSensitive, fallback FilePaths)— note the ghost's completer pass is case-sensitive while the menu's is fuzzy — and the full suggestion is rebuilt from the replacement span (app/src/terminal/input.rs:10349-10378).
- Stale results are dropped on arrival by buffer-equality; an ignored
suggestion is remembered and excluded; the ghost is suppressed while a
manually opened menu shows (feature-flagged) but not under as-you-type
(
app/src/terminal/input.rs:13289-13300). - The zero-state "intelligent" ghost (after a block completes, empty
buffer): the NextCommand model gathers up to 25 similar history contexts,
counts k-most-common next commands, and skips the LLM when history is
confident — thresholds: with a typed prefix, ≥1 sample and ≥0.1
likelihood; zero-state, ≥2 and ≥0.25 — otherwise it calls the closed
/ai/generate_input_suggestionsserver endpoint (request construction open, model server-side) (app/src/ai/predict/next_command_model.rs:55-68, 284-318, 429-513;app/src/server/server_api.rs:1153-1179). - Suggestions are validated against completion specs before display:
parse with specs, file/folder args checked on disk, generator args
validated with a 150 ms timeout — "If the completions call times out,
assume the arg is valid"
(
app/src/ai/predict/next_command_model.rs:63, 675-831). - Accept keys: whole ghost on Right, one word on Alt+Right, subword
motions; each accept emits an acceptance event
(
app/src/editor/view/mod.rs:5997-6477).
4. The history store: schema and "similar contexts" in the open code
- The store is plain sqlite (diesel), read-only connections for queries;
"We want only one write connection to exist and use event processing to
write any data needed" (
app/src/persistence/sqlite.rs:203-238, 469-479). - History entries carry: command, pwd, timestamps, exit_code,
shell_host, session id, workflow links
(
app/src/terminal/history.rs:233-256). - "Similar contexts" is concrete:
get_same_commands_from_historyselects the last N occurrences of the same command with equal pwd, exit_code, shell, hostname, newest first ("the last num_commands times the same command was run in a similar context",app/src/persistence/commands.rs:43-70); each occurrence contributes a context of its preceding commands plus its next command, oldest→newest, capped at 25 contexts (app/src/ai/predict/next_command_model.rs:55, 203-256). - The in-memory History model merges the sqlite table, the shell's history
file (read per host), and the live session, deduped
(
app/src/terminal/history.rs:161-187, 798-859).
5. Menu lifecycle facts the shipped record stopped short of
- The replaced span is the word at the cursor (the last location's
span), for accepts and fills alike:
select_and_replace(replacement, [replacement_start..cursor])(app/src/terminal/input.rs:13352-13411). - Trailing-space rule: a space is appended after an inserted suggestion
when not as-you-type, the replacement ends at buffer end, and it does not
end with a path separator or
=(app/src/terminal/input.rs:13385-13402). - Preselect: results preselect the first row in the modern mode,
nothing in the legacy classic mode; no user-facing preselect setting
exists (
app/src/terminal/input.rs:13333-13343;app/src/input_suggestions.rs:303-312). - Sources can ask the shell:
CompletionSources::{WarpOnly, NativeOnly, WarpThenNative, None}— "Bundled specs first, asking the shell only if they come back empty"; native is ineligible for as-you-type (app/src/terminal/input.rs:1584-1641, 12800-12839). - While the menu is open under Tab, typing filters the original set;
under as-you-type it recomputes — the shipped record's finding 3,
with the filter mechanics pinned
(
app/src/terminal/input.rs:12297-12370, 11168-11205).
6. The remaining surface
- Command scanning is the user's own shell, once per session: bash
filters
compgen -cthroughtype -tkeeping only "file" ("to avoid a lot of overhead invoking it thousands of times"), fishcomplete -C --escape '', zshprint -l -- ${(ok)commands}, PowerShellGet-Command -CommandType Application; the result is a once-per-session HashSet shared by concurrent callers (crates/warp_terminal/src/shell/mod.rs:615-690;app/src/terminal/model/session.rs:1265-1367). - Env variables: the bootstrap payload collects env-var names; the
engine completes
$VAR→${name}from the name set — names only, values never read for completion (wc/completer/completer/engine/variable.rs:17-39;app/src/terminal/model/session.rs:800-809). - Path completion details: listings always come from a context trait
(local or remote);
.and..are always chained onto every listing; a synthetic/entry appears only at the filesystem root; dotfiles hide unless the query starts with.; directories get the separator appended to display and replacement; replacements are shell-escaped, displays are not;~/$HOMEexpand with an escaped-tilde disambiguation;cd's folder template consults CDPATH in shell order (wc/completer/completer/engine/path.rs:19-31, 199-215, 275, 291-339, 363-421). - Generators are Rust functions keyed by
generatorName, running a shell command at pwd, parsed on success only — failure yields nothing, never a fallback (wc/completer/completer/engine/argument/legacy.rs:729-788). - Native shell completions ride OSC 9280: shell-integration scripts
(zsh
compaddoverride, bashCOMPREPLY, fishcomplete -C, PowerShellCompleteInput) emit matches + descriptions + byte spans; the terminal buffers them and converts to case-insensitive prefix-matched suggestions (crates/warp_terminal/src/model/ansi/mod.rs:72-77, 1176-1245;crates/warp_terminal/src/model/completions.rs:3-51;app/assets/bundled/bootstrap/zsh_body.sh:1560-1641). - Menu chrome: no completion-specific theme slots — the menu uses
generic
surface_2/outlinetokens, is user-resizable with persisted width/height settings, and reuses the same mode machinery for history, workflow enums, and AI menus (app/src/terminal/input/suggestions_mode_menu.rs:199-204, 207-262;app/src/settings/input.rs:185-200). - Settings defaults (settling the shipped record's Unverified flag):
completions_open_while_typingdefaults to false; the ghost'senable_autosuggestionsdefaults to true; Warp's completions and native shell completions both default on (app/src/settings/input.rs:48-87;app/src/settings/editor.rs:254-264). - Spec freshness is a pinned rev, nothing else: the corpus is a git
dependency at
48fd7aa, embedded at compile time (rust-embed, lazy per-command parse, 256-entry negative cache, 255-char token cap); there is no download or update path in the open source (Cargo.toml:401;wc/signatures/legacy/registry.rs:22-96;/tmp/warp-specs/command-signatures/src/lib.rs:14-60).
7. The corpus format: what parses, what is dropped, what an adapter may keep
- Schema (Fig-compatible JSON):
Command{name, subcommands, options, args, description, priority, hidden, parserDirectives},CommandOption{name, args, isRequired, exclusiveOn, dependsOn, requiresEquals, isRepeatable, isPersistent, priority, hidden},Arg{name, suggestions[], generatorName, template, isVariadic, isOptional, isCommand, filterTemplateName, skipGeneratorValidation}(/tmp/warp-specs/completion-metadata/src/fig_types.rs:74-114, 164-265). - Scale: 496 hand-written specs (one top-level command each) + 663
autogenerated PowerShell + 10 overrides; usage: template args in 357,
static suggestion lists in 277, generators in 169, exclusiveOn in 74
(
findcounts over/tmp/warp-specs/command-signatures/json/). - Priority: Fig's 50-default maps to a clamped ±100 integer; template args
route to the path engine; multi-source args concatenate Generators →
Suggestions (sorted) → Templates in declared order
(
fig_types.rs:450-462;wc/completer/completer/engine/argument/legacy.rs:598-647). - Parsed but dropped — an adapter is free to keep these where DropTerm's
schema has a home:
exclusiveOn(74 specs) anddependsOn(38) are deserialized but not carried into the runtime option;requiresEqualsandisRepeatablelikewise; thehistoryandhelptemplates fail conversion and are dropped; Fig's JSgenerateSpecis ignored by design;insertValue(53 specs) is parsed away (fig_types.rs:485-499, 501-513; corpus AGENTS.md; grep overfig_types.rs).
8. What DropTerm has today (refreshed at HEAD 09241f4, 2026-11-24)
| Capability | Warp (f8223ce) | DropTerm (09241f4) |
|---|---|---|
| Menu keys/show rules | findings 3-5, shipped record | landed (suggest-parity SP1-SP4, incl. the fill-anchor fixes 12837be/09241f4) |
| Match ladder | exact cs → exact ci → prefix → fuzzy (SkimMatcherV2 defaults) | specs walker only (filter_rank/match_tier, a hand-rolled port); history/path/catalog are case-sensitive prefix |
| Ghost content | similar-context sqlite → recency+pwd → completer cs fallback | five providers, history recency first, no context |
| History store | sqlite, entries with pwd/exit_code/shell_host, similar-context queries | in-memory ring + shell-history seed, strings only, no cwd |
$VAR completion | env-var names, ${name} replacement | none |
./.. in path listings | always chained | none observed |
| Trailing-space on insert | conditional rule | none |
| Corpus | 496+663 specs, embedded, pinned rev | 624 commands (92 floor + 532 extended), extractor pipeline |
| Native shell completions (OSC 9280) | shell-integration scripts → menu | n/a — the PTY shows the shell's own completion; DropTerm's Tab flows through |
| AI next-command ghost | history-first with skip-LLM thresholds, closed server | separate Proposed record (ai-completion-providers); not this module |
Sources
github.com/warpdotdev/warp@f8223ce— local clone/tmp/warp-src(the identical rev the shipped record cites), swept 2026-11-24 in four read-only research passes:crates/warp_completer/src/**(engine, matchers, coalesce, describe, suggest/priority, context),crates/fuzzy_match/src/**,app/src/{input_suggestions.rs, completer/, terminal/input.rs, terminal/input/, ai/predict/, persistence/, settings/, terminal/model/, terminal/history.rs, editor/view/},app/assets/bundled/bootstrap/,Cargo.toml.github.com/warpdotdev/command-signatures@48fd7aa— local clone/tmp/warp-specs(the exact pinned rev), swept 2026-11-24:command-signatures/json/counts,completion-metadata/src/ {fig_types.rs, signature.rs},command-signatures/src/{lib.rs, generators/}.- The shipped record
warp-completion-behavior.md(2026-11-23) and the prior surveyai-completion-providers.md(2026-11-23) carry over; this record supplements them, never edits them. - Upstream
fuzzy-matcherv0.3.7src/skim.rs(skim-rs/fuzzy-matcher, MIT/Apache) — the scoring table Warp inherits unmodified.
Unverified / closed-source boundary: the LLM server behind
/ai/generate_input_suggestions (request construction and thresholds are
open; the model is server-side). Warp's shipped defaults are now verified
from app/src/settings/* except where a feature flag gates a path at
runtime; everything else cited above is open code.