π File detail
utils/slashCommandParsing.ts
π§© .tsπ 61 linesπΎ 1,437 bytesπ text
β Back to All Filesπ― Use case
This file lives under βutils/β, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, β¦). On the API surface it exposes ParsedSlashCommand and parseSlashCommand β mainly functions, hooks, or classes. What the file header says: Centralized utilities for parsing slash commands.
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
Centralized utilities for parsing slash commands
π€ Exports (heuristic)
ParsedSlashCommandparseSlashCommand
π₯οΈ Source preview
/**
* Centralized utilities for parsing slash commands
*/
export type ParsedSlashCommand = {
commandName: string
args: string
isMcp: boolean
}
/**
* Parses a slash command input string into its component parts
*
* @param input - The raw input string (should start with '/')
* @returns Parsed command name, args, and MCP flag, or null if invalid
*
* @example
* parseSlashCommand('/search foo bar')
* // => { commandName: 'search', args: 'foo bar', isMcp: false }
*
* @example
* parseSlashCommand('/mcp:tool (MCP) arg1 arg2')
* // => { commandName: 'mcp:tool (MCP)', args: 'arg1 arg2', isMcp: true }
*/
export function parseSlashCommand(input: string): ParsedSlashCommand | null {
const trimmedInput = input.trim()
// Check if input starts with '/'
if (!trimmedInput.startsWith('/')) {
return null
}
// Remove the leading '/' and split by spaces
const withoutSlash = trimmedInput.slice(1)
const words = withoutSlash.split(' ')
if (!words[0]) {
return null
}
let commandName = words[0]
let isMcp = false
let argsStartIndex = 1
// Check for MCP commands (second word is '(MCP)')
if (words.length > 1 && words[1] === '(MCP)') {
commandName = commandName + ' (MCP)'
isMcp = true
argsStartIndex = 2
}
// Extract arguments (everything after command name)
const args = words.slice(argsStartIndex).join(' ')
return {
commandName,
args,
isMcp,
}
}