Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

support mid-prompt slash command autocomplete (#416)

ktae44196c3947
diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md
index a5fd68dddd..08d2362331 100644
--- a/packages/tui/CHANGELOG.md
+++ b/packages/tui/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Fixed slash-command and skill autocomplete not appearing for references typed in the middle of prompts ([ENG-4628](https://linear.app/primeintellect/issue/ENG-4628/support-skill-and-command-autocomplete-mid-prompt)).
- Fixed focused full-pane overlays becoming slow to navigate on wider terminals.
## [0.3.0] - 2026-07-13
diff --git a/packages/tui/src/autocomplete.ts b/packages/tui/src/autocomplete.ts
index 53825a0f6d..aba5fa101d 100644
--- a/packages/tui/src/autocomplete.ts
+++ b/packages/tui/src/autocomplete.ts
@@ -3,6 +3,7 @@ import { readdirSync, statSync } from "fs";
import { homedir } from "os";
import { basename, dirname, join } from "path";
import { fuzzyFilter } from "./fuzzy.js";
+import { getSlashCommandContext } from "./slash-command-context.js";
const PATH_DELIMITERS = new Set([" ", "\t", '"', "'", "="]);
@@ -239,6 +240,7 @@ export interface SlashCommand {
export interface AutocompleteSuggestions {
items: AutocompleteItem[];
prefix: string; // What we're matching against (e.g., "/" or "src/")
+ kind?: "slash-command" | "file";
}
export interface AutocompleteProvider {
@@ -302,64 +304,62 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
return {
items: suggestions,
prefix: atPrefix,
+ kind: "file",
};
}
- if (!options.force && textBeforeCursor.startsWith("/")) {
- const spaceIndex = textBeforeCursor.indexOf(" ");
-
- if (spaceIndex === -1) {
- const prefix = textBeforeCursor.slice(1);
- const commandItems = this.commands.map((cmd) => {
- const name = "name" in cmd ? cmd.name : cmd.value;
- const aliases = "aliases" in cmd && cmd.aliases ? cmd.aliases : [];
- const hint = "argumentHint" in cmd && cmd.argumentHint ? cmd.argumentHint : undefined;
- const desc = cmd.description ?? "";
- const fullDesc = hint ? (desc ? `${hint} — ${desc}` : hint) : desc;
- const takesArgument = "takesArgument" in cmd ? cmd.takesArgument === true : false;
- return {
- name,
- searchText: [name, ...aliases].join(" "),
- label: name,
- description: fullDesc || undefined,
- takesArgument,
- };
- });
-
- const filtered = fuzzyFilter(commandItems, prefix, (item) => item.searchText).map((item) => ({
- value: item.name,
- label: item.label,
- ...(item.description && { description: item.description }),
- ...(item.takesArgument && { takesArgument: true }),
- }));
+ const slashContext = options.force ? null : getSlashCommandContext(lines, cursorLine, cursorCol);
+ if (slashContext?.kind === "name") {
+ const prefix = slashContext.prefix.slice(1);
+ const commandItems = this.commands.map((cmd) => {
+ const name = "name" in cmd ? cmd.name : cmd.value;
+ const aliases = "aliases" in cmd && cmd.aliases ? cmd.aliases : [];
+ const hint = "argumentHint" in cmd && cmd.argumentHint ? cmd.argumentHint : undefined;
+ const desc = cmd.description ?? "";
+ const fullDesc = hint ? (desc ? `${hint} — ${desc}` : hint) : desc;
+ const takesArgument = "takesArgument" in cmd ? cmd.takesArgument === true : false;
+ return {
+ name,
+ searchText: [name, ...aliases].join(" "),
+ label: name,
+ description: fullDesc || undefined,
+ takesArgument,
+ };
+ });
- if (filtered.length === 0) return null;
+ const filtered = fuzzyFilter(commandItems, prefix, (item) => item.searchText).map((item) => ({
+ value: item.name,
+ label: item.label,
+ ...(item.description && { description: item.description }),
+ ...(item.takesArgument && { takesArgument: true }),
+ }));
+ if (filtered.length > 0) {
return {
items: filtered,
- prefix: textBeforeCursor,
+ prefix: slashContext.prefix,
+ kind: "slash-command",
};
}
- const commandName = textBeforeCursor.slice(1, spaceIndex);
- const argumentText = textBeforeCursor.slice(spaceIndex + 1);
-
+ return null;
+ } else if (slashContext?.kind === "argument") {
const command = this.commands.find((cmd) => {
const name = "name" in cmd ? cmd.name : cmd.value;
- return name === commandName;
+ return name === slashContext.commandName;
});
if (!command || !("getArgumentCompletions" in command) || !command.getArgumentCompletions) {
return null;
}
- const argumentSuggestions = await command.getArgumentCompletions(argumentText);
+ const argumentSuggestions = await command.getArgumentCompletions(slashContext.prefix);
if (!Array.isArray(argumentSuggestions) || argumentSuggestions.length === 0) {
return null;
}
return {
items: argumentSuggestions,
- prefix: argumentText,
+ prefix: slashContext.prefix,
};
}
@@ -374,6 +374,7 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
return {
items: suggestions,
prefix: pathMatch,
+ kind: "file",
};
}
@@ -392,20 +393,23 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
const hasTrailingQuoteInItem = item.value.endsWith('"');
const adjustedAfterCursor =
isQuotedPrefix && hasTrailingQuoteInItem && hasLeadingQuoteAfterCursor ? afterCursor.slice(1) : afterCursor;
+ const slashContext = getSlashCommandContext(lines, cursorLine, cursorCol);
- // Check if we're completing a slash command (prefix starts with "/" but NOT a file path)
- // Slash commands are at the start of the line and don't contain path separators after the first /
- const isSlashCommand = prefix.startsWith("/") && beforePrefix.trim() === "" && !prefix.slice(1).includes("/");
+ const isSlashCommand =
+ slashContext?.kind === "name" &&
+ slashContext.prefix === prefix &&
+ this.commands.some((command) => ("name" in command ? command.name : command.value) === item.value);
if (isSlashCommand) {
- // This is a command name completion
- const newLine = `${beforePrefix}/${item.value} ${adjustedAfterCursor}`;
+ const hasSeparatorAfterCursor = /^[ \t]/.test(adjustedAfterCursor);
+ const separator = hasSeparatorAfterCursor ? "" : " ";
+ const newLine = `${beforePrefix}/${item.value}${separator}${adjustedAfterCursor}`;
const newLines = [...lines];
newLines[cursorLine] = newLine;
return {
lines: newLines,
cursorLine,
- cursorCol: beforePrefix.length + item.value.length + 2, // +2 for "/" and space
+ cursorCol: beforePrefix.length + item.value.length + 2,
};
}
@@ -429,10 +433,7 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
};
}
- // Check if we're in a slash command context (beforePrefix contains "/command ")
- const textBeforeCursor = currentLine.slice(0, cursorCol);
- if (textBeforeCursor.includes("/") && textBeforeCursor.includes(" ")) {
- // This is likely a command argument completion
+ if (slashContext?.kind === "argument" && slashContext.prefix === prefix) {
const newLine = beforePrefix + item.value + adjustedAfterCursor;
const newLines = [...lines];
newLines[cursorLine] = newLine;
@@ -778,14 +779,6 @@ export class CombinedAutocompleteProvider implements AutocompleteProvider {
// Check if we should trigger file completion (called on Tab key)
shouldTriggerFileCompletion(lines: string[], cursorLine: number, cursorCol: number): boolean {
- const currentLine = lines[cursorLine] || "";
- const textBeforeCursor = currentLine.slice(0, cursorCol);
-
- // Don't trigger if we're typing a slash command at the start of the line
- if (textBeforeCursor.trim().startsWith("/") && !textBeforeCursor.trim().includes(" ")) {
- return false;
- }
-
- return true;
+ return getSlashCommandContext(lines, cursorLine, cursorCol)?.kind !== "name";
}
}
diff --git a/packages/tui/src/components/editor.ts b/packages/tui/src/components/editor.ts
index 84874e763a..c3060f2c4f 100644
--- a/packages/tui/src/components/editor.ts
+++ b/packages/tui/src/components/editor.ts
@@ -3,6 +3,7 @@ import type { EditorPasteSnapshot } from "../editor-component.js";
import { getKeybindings } from "../keybindings.js";
import { decodePrintableKey, matchesKey } from "../keys.js";
import { KillRing } from "../kill-ring.js";
+import { getSlashCommandContext, type SlashCommandContext } from "../slash-command-context.js";
import { type Component, CURSOR_MARKER, type Focusable, type TUI } from "../tui.js";
import { UndoStack } from "../undo-stack.js";
import { getSegmenter, isPunctuationChar, isWhitespaceChar, truncateToWidth, visibleWidth } from "../utils.js";
@@ -278,6 +279,7 @@ export class Editor implements Component, Focusable {
private autocompleteList?: SelectList;
private autocompleteState: "regular" | "force" | null = null;
private autocompletePrefix: string = "";
+ private autocompleteKind?: AutocompleteSuggestions["kind"];
private autocompleteMaxVisible: number = 5;
private autocompleteAbort?: AbortController;
private autocompleteDebounceTimer?: ReturnType<typeof setTimeout>;
@@ -761,6 +763,14 @@ export class Editor implements Component, Focusable {
if (kb.matches(data, "tui.select.confirm")) {
const selected = this.autocompleteList.getSelectedItem();
if (selected && this.autocompleteProvider) {
+ const slashContext = this.getCurrentSlashCommandContext();
+ const isSlashCommandCompletion =
+ this.autocompleteKind === "slash-command" ||
+ (this.autocompleteKind === undefined &&
+ this.autocompleteState === "regular" &&
+ this.autocompletePrefix.startsWith("/"));
+ const shouldSubmitSlashCommand =
+ isSlashCommandCompletion && slashContext?.kind === "name" && slashContext.isAtPromptStart;
this.pushUndoSnapshot();
this.lastAction = null;
const result = this.autocompleteProvider.applyCompletion(
@@ -774,9 +784,9 @@ export class Editor implements Component, Focusable {
this.state.cursorLine = result.cursorLine;
this.setCursorCol(result.cursorCol);
- if (this.autocompletePrefix.startsWith("/")) {
+ if (isSlashCommandCompletion) {
this.cancelAutocomplete();
- if (selected.takesArgument) {
+ if (!shouldSubmitSlashCommand || selected.takesArgument) {
if (this.onChange) this.onChange(this.getText());
return;
}
@@ -1210,8 +1220,8 @@ export class Editor implements Component, Focusable {
// Check if we should trigger or update autocomplete
if (!this.autocompleteState) {
- // Auto-trigger for "/" at the start of a line (slash commands)
- if (char === "/" && this.isAtStartOfMessage()) {
+ const slashContext = this.getCurrentSlashCommandContext();
+ if (char === "/" && slashContext?.kind === "name") {
this.tryTriggerAutocomplete();
}
// Auto-trigger for symbol-based completion like @ or # at token boundaries
@@ -1227,8 +1237,7 @@ export class Editor implements Component, Focusable {
else if (/[a-zA-Z0-9.\-_]/.test(char)) {
const currentLine = this.state.lines[this.state.cursorLine] || "";
const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
- // Check if we're in a slash command (with or without space for arguments)
- if (this.isInSlashCommandContext(textBeforeCursor)) {
+ if (slashContext) {
this.tryTriggerAutocomplete();
}
// Check if we're in a symbol-based completion context like @ or #
@@ -1414,8 +1423,7 @@ export class Editor implements Component, Focusable {
// If autocomplete was cancelled (no matches), re-trigger if we're in a completable context
const currentLine = this.state.lines[this.state.cursorLine] || "";
const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
- // Slash command context
- if (this.isInSlashCommandContext(textBeforeCursor)) {
+ if (this.getCurrentSlashCommandContext()) {
this.tryTriggerAutocomplete();
}
// Symbol-based completion context like @ or #
@@ -1781,8 +1789,7 @@ export class Editor implements Component, Focusable {
} else {
const currentLine = this.state.lines[this.state.cursorLine] || "";
const textBeforeCursor = currentLine.slice(0, this.state.cursorCol);
- // Slash command context
- if (this.isInSlashCommandContext(textBeforeCursor)) {
+ if (this.getCurrentSlashCommandContext()) {
this.tryTriggerAutocomplete();
}
// Symbol-based completion context like @ or #
@@ -2226,21 +2233,8 @@ export class Editor implements Component, Focusable {
this.setCursorCol(newCol);
}
- // Slash menu only allowed on the first line of the editor
- private isSlashMenuAllowed(): boolean {
- return this.state.cursorLine === 0;
- }
-
- // Helper method to check if cursor is at start of message (for slash command detection)
- private isAtStartOfMessage(): boolean {
- if (!this.isSlashMenuAllowed()) return false;
- const currentLine = this.state.lines[this.state.cursorLine] || "";
- const beforeCursor = currentLine.slice(0, this.state.cursorCol);
- return beforeCursor.trim() === "" || beforeCursor.trim() === "/";
- }
-
- private isInSlashCommandContext(textBeforeCursor: string): boolean {
- return this.isSlashMenuAllowed() && textBeforeCursor.trimStart().startsWith("/");
+ private getCurrentSlashCommandContext(): SlashCommandContext | null {
+ return getSlashCommandContext(this.state.lines, this.state.cursorLine, this.state.cursorCol);
}
// Autocomplete methods
@@ -2273,12 +2267,12 @@ export class Editor implements Component, Focusable {
return firstPrefixIndex;
}
- private createAutocompleteList(
- prefix: string,
- items: Array<{ value: string; label: string; description?: string }>,
- ): SelectList {
- const layout = prefix.startsWith("/") ? SLASH_COMMAND_SELECT_LIST_LAYOUT : undefined;
- return new SelectList(items, this.autocompleteMaxVisible, this.theme.selectList, layout);
+ private createAutocompleteList(suggestions: AutocompleteSuggestions): SelectList {
+ const layout =
+ suggestions.kind === "slash-command" || (suggestions.kind === undefined && suggestions.prefix.startsWith("/"))
+ ? SLASH_COMMAND_SELECT_LIST_LAYOUT
+ : undefined;
+ return new SelectList(suggestions.items, this.autocompleteMaxVisible, this.theme.selectList, layout);
}
private tryTriggerAutocomplete(explicitTab: boolean = false): void {
@@ -2288,10 +2282,7 @@ export class Editor implements Component, Focusable {
private handleTabCompletion(): void {
if (!this.autocompleteProvider) return;
- const currentLine = this.state.lines[this.state.cursorLine] || "";
- const beforeCursor = currentLine.slice(0, this.state.cursorCol);
-
- if (this.isInSlashCommandContext(beforeCursor) && !beforeCursor.trimStart().includes(" ")) {
+ if (this.getCurrentSlashCommandContext()?.kind === "name") {
this.handleSlashCommandCompletion();
} else {
this.forceFileAutocomplete(true);
@@ -2441,9 +2432,11 @@ export class Editor implements Component, Focusable {
private applyAutocompleteSuggestions(suggestions: AutocompleteSuggestions, state: "regular" | "force"): void {
this.autocompletePrefix = suggestions.prefix;
- this.autocompleteList = this.createAutocompleteList(suggestions.prefix, suggestions.items);
+ this.autocompleteKind = suggestions.kind;
+ this.autocompleteList = this.createAutocompleteList(suggestions);
- const bestMatchIndex = this.getBestAutocompleteMatchIndex(suggestions.items, suggestions.prefix);
+ const matchingPrefix = suggestions.kind === "slash-command" ? suggestions.prefix.slice(1) : suggestions.prefix;
+ const bestMatchIndex = this.getBestAutocompleteMatchIndex(suggestions.items, matchingPrefix);
if (bestMatchIndex >= 0) {
this.autocompleteList.setSelectedIndex(bestMatchIndex);
}
@@ -2465,6 +2458,7 @@ export class Editor implements Component, Focusable {
this.autocompleteState = null;
this.autocompleteList = undefined;
this.autocompletePrefix = "";
+ this.autocompleteKind = undefined;
}
protected cancelAutocomplete(): void {
diff --git a/packages/tui/src/slash-command-context.ts b/packages/tui/src/slash-command-context.ts
new file mode 100644
index 0000000000..31f19b0773
--- /dev/null
+++ b/packages/tui/src/slash-command-context.ts
@@ -0,0 +1,46 @@
+export type SlashCommandContext =
+ | { kind: "name"; prefix: string; isAtPromptStart: boolean }
+ | { kind: "argument"; commandName: string; prefix: string; isAtPromptStart: true };
+
+export function getSlashCommandContext(
+ lines: string[],
+ cursorLine: number,
+ cursorCol: number,
+): SlashCommandContext | null {
+ const currentLine = lines[cursorLine] ?? "";
+ const textBeforeCursor = currentLine.slice(0, cursorCol);
+ const trimmedStart = textBeforeCursor.trimStart();
+
+ if (cursorLine === 0 && trimmedStart.startsWith("/")) {
+ const separatorIndex = trimmedStart.search(/[ \t]/);
+ const commandToken = separatorIndex === -1 ? trimmedStart : trimmedStart.slice(0, separatorIndex);
+
+ if (commandToken.slice(1).includes("/")) {
+ return null;
+ }
+
+ if (separatorIndex === -1) {
+ return { kind: "name", prefix: commandToken, isAtPromptStart: true };
+ }
+
+ const commandName = commandToken.slice(1);
+ if (!commandName) {
+ return null;
+ }
+
+ return {
+ kind: "argument",
+ commandName,
+ prefix: trimmedStart.slice(separatorIndex + 1),
+ isAtPromptStart: true,
+ };
+ }
+
+ const tokenStart = Math.max(textBeforeCursor.lastIndexOf(" "), textBeforeCursor.lastIndexOf("\t")) + 1;
+ const prefix = textBeforeCursor.slice(tokenStart);
+ if (!prefix.startsWith("/") || prefix.slice(1).includes("/")) {
+ return null;
+ }
+
+ return { kind: "name", prefix, isAtPromptStart: false };
+}
diff --git a/packages/tui/test/autocomplete.test.ts b/packages/tui/test/autocomplete.test.ts
index 372b37a69d..b7df453b01 100644
--- a/packages/tui/test/autocomplete.test.ts
+++ b/packages/tui/test/autocomplete.test.ts
@@ -5,6 +5,7 @@ import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { afterEach, beforeEach, describe, it, test } from "node:test";
import { CombinedAutocompleteProvider } from "../src/autocomplete.js";
+import { getSlashCommandContext } from "../src/slash-command-context.js";
const resolveFdPath = (): string | null => {
const command = process.platform === "win32" ? "where" : "which";
@@ -54,6 +55,35 @@ const getSuggestions = (
force: boolean = false,
) => provider.getSuggestions(lines, cursorLine, cursorCol, { signal: new AbortController().signal, force });
+describe("slash command context", () => {
+ it("finds inline command tokens on any line", () => {
+ assert.deepStrictEqual(getSlashCommandContext(["Please use /skill:brain"], 0, 23), {
+ kind: "name",
+ prefix: "/skill:brain",
+ isAtPromptStart: false,
+ });
+ assert.deepStrictEqual(getSlashCommandContext(["First line", "Then /he"], 1, 8), {
+ kind: "name",
+ prefix: "/he",
+ isAtPromptStart: false,
+ });
+ });
+
+ it("keeps standalone command arguments distinct from inline references", () => {
+ assert.deepStrictEqual(getSlashCommandContext(["/model gpt"], 0, 10), {
+ kind: "argument",
+ commandName: "model",
+ prefix: "gpt",
+ isAtPromptStart: true,
+ });
+ });
+
+ it("ignores URLs and path fragments", () => {
+ assert.strictEqual(getSlashCommandContext(["Visit https://example.com"], 0, 25), null);
+ assert.strictEqual(getSlashCommandContext(["Open src/components"], 0, 19), null);
+ });
+});
+
describe("CombinedAutocompleteProvider", () => {
describe("slash commands", () => {
it("matches command aliases while previewing and completing the canonical command", async () => {
@@ -71,6 +101,7 @@ describe("CombinedAutocompleteProvider", () => {
assert.deepStrictEqual(result, {
prefix: "/clear",
+ kind: "slash-command",
items: [{ value: "new", label: "new", description: "Start a new session" }],
});
});
@@ -92,6 +123,56 @@ describe("CombinedAutocompleteProvider", () => {
const fresh = await getSuggestions(provider, ["/new"], 0, 4);
assert.deepStrictEqual(fresh?.items, [{ value: "new", label: "new", description: "Start a new session" }]);
});
+
+ it("suggests skill commands for inline references", async () => {
+ const provider = new CombinedAutocompleteProvider(
+ [{ name: "skill:brainstorm", description: "Brainstorm approaches" }],
+ "/tmp",
+ );
+ const line = "Please use /skill:brain";
+ const result = await getSuggestions(provider, [line], 0, line.length);
+
+ assert.deepStrictEqual(result, {
+ prefix: "/skill:brain",
+ kind: "slash-command",
+ items: [{ value: "skill:brainstorm", label: "skill:brainstorm", description: "Brainstorm approaches" }],
+ });
+ });
+
+ it("suggests commands on later prompt lines", async () => {
+ const provider = new CombinedAutocompleteProvider([{ name: "help", description: "Show help" }], "/tmp");
+ const lines = ["First line", "Then /he"];
+ const result = await getSuggestions(provider, lines, 1, lines[1]!.length);
+
+ assert.deepStrictEqual(result, {
+ prefix: "/he",
+ kind: "slash-command",
+ items: [{ value: "help", label: "help", description: "Show help" }],
+ });
+ });
+
+ it("does not fall back to file suggestions for unmatched command tokens", async () => {
+ const provider = new CombinedAutocompleteProvider([], "/tmp");
+ const result = await getSuggestions(provider, ["/tm"], 0, 3);
+
+ assert.strictEqual(result, null);
+ });
+
+ it("replaces only the inline command token without duplicating whitespace", async () => {
+ const provider = new CombinedAutocompleteProvider([{ name: "help", description: "Show help" }], "/tmp");
+ const line = "Please use /he later";
+ const cursorCol = line.indexOf(" later");
+ const result = await getSuggestions(provider, [line], 0, cursorCol);
+ const item = result?.items[0];
+ assert.ok(result && item);
+
+ const applied = provider.applyCompletion([line], 0, cursorCol, item, result.prefix);
+ assert.deepStrictEqual(applied, {
+ lines: ["Please use /help later"],
+ cursorLine: 0,
+ cursorCol: "Please use /help ".length,
+ });
+ });
});
describe("extractPathPrefix", () => {
@@ -106,6 +187,7 @@ describe("CombinedAutocompleteProvider", () => {
assert.notEqual(result, null, "Should return suggestions for root directory");
if (result) {
assert.strictEqual(result.prefix, "/", "Prefix should be '/'");
+ assert.strictEqual(result.kind, "file");
}
});
diff --git a/packages/tui/test/editor.test.ts b/packages/tui/test/editor.test.ts
index 415e3bf352..557ba3dae6 100644
--- a/packages/tui/test/editor.test.ts
+++ b/packages/tui/test/editor.test.ts
@@ -2296,6 +2296,80 @@ describe("Editor component", () => {
assert.strictEqual(editor.isShowingAutocomplete(), false);
});
+ it("accepts an inline slash command with Enter without submitting the prompt", async () => {
+ const editor = new Editor(createTestTUI(), defaultEditorTheme);
+ const submitted: string[] = [];
+ editor.onSubmit = (text) => submitted.push(text);
+ editor.setAutocompleteProvider(
+ new CombinedAutocompleteProvider([{ name: "help", description: "Show help" }], process.cwd()),
+ );
+ editor.setText("Please use ");
+
+ editor.handleInput("/");
+ editor.handleInput("h");
+ editor.handleInput("e");
+ await flushAutocomplete();
+ assert.strictEqual(editor.isShowingAutocomplete(), true);
+
+ editor.handleInput("\r");
+ assert.strictEqual(editor.getText(), "Please use /help ");
+ assert.deepStrictEqual(submitted, []);
+ assert.strictEqual(editor.isShowingAutocomplete(), false);
+ });
+
+ it("accepts inline slash commands with Tab on later prompt lines", async () => {
+ const editor = new Editor(createTestTUI(), defaultEditorTheme);
+ editor.setAutocompleteProvider(
+ new CombinedAutocompleteProvider([{ name: "help", description: "Show help" }], process.cwd()),
+ );
+ editor.setText("First line\nThen ");
+
+ editor.handleInput("/");
+ editor.handleInput("h");
+ editor.handleInput("e");
+ await flushAutocomplete();
+ assert.strictEqual(editor.isShowingAutocomplete(), true);
+
+ editor.handleInput("\t");
+ assert.strictEqual(editor.getText(), "First line\nThen /help ");
+ assert.strictEqual(editor.isShowingAutocomplete(), false);
+ });
+
+ it("preserves standalone slash command submission", async () => {
+ const editor = new Editor(createTestTUI(), defaultEditorTheme);
+ const submitted: string[] = [];
+ editor.onSubmit = (text) => submitted.push(text);
+ editor.setAutocompleteProvider(
+ new CombinedAutocompleteProvider([{ name: "help", description: "Show help" }], process.cwd()),
+ );
+
+ editor.handleInput("/");
+ editor.handleInput("h");
+ editor.handleInput("e");
+ await flushAutocomplete();
+ editor.handleInput("\r");
+
+ assert.deepStrictEqual(submitted, ["/help"]);
+ assert.strictEqual(editor.getText(), "");
+ });
+
+ it("does not trigger slash command autocomplete inside URLs or paths", async () => {
+ const editor = new Editor(createTestTUI(), defaultEditorTheme);
+ editor.setAutocompleteProvider(
+ new CombinedAutocompleteProvider([{ name: "help", description: "Show help" }], process.cwd()),
+ );
+
+ editor.setText("Visit https:/");
+ editor.handleInput("/");
+ await flushAutocomplete();
+ assert.strictEqual(editor.isShowingAutocomplete(), false);
+
+ editor.setText("Open src");
+ editor.handleInput("/");
+ await flushAutocomplete();
+ assert.strictEqual(editor.isShowingAutocomplete(), false);
+ });
+
it("applies exact typed slash-argument value on Enter even when first item is highlighted", async () => {
const editor = new Editor(createTestTUI(), defaultEditorTheme);