MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getCompoundCommandPrefixesStatic

Function getCompoundCommandPrefixesStatic

src/utils/bash/prefix.ts:135–175  ·  view source on GitHub ↗
(
  command: string,
  excludeSubcommand?: (subcommand: string) => boolean,
)

Source from the content-addressed store, hash-verified

133 * commands that are already auto-allowed).
134 */
135export async function getCompoundCommandPrefixesStatic(
136 command: string,
137 excludeSubcommand?: (subcommand: string) => boolean,
138): Promise<string[]> {
139 const subcommands = splitCommand_DEPRECATED(command)
140 if (subcommands.length <= 1) {
141 const result = await getCommandPrefixStatic(command)
142 return result?.commandPrefix ? [result.commandPrefix] : []
143 }
144
145 const prefixes: string[] = []
146 for (const subcmd of subcommands) {
147 const trimmed = subcmd.trim()
148 if (excludeSubcommand?.(trimmed)) continue
149 const result = await getCommandPrefixStatic(trimmed)
150 if (result?.commandPrefix) {
151 prefixes.push(result.commandPrefix)
152 }
153 }
154
155 if (prefixes.length === 0) return []
156
157 // Group prefixes by their first word (root command)
158 const groups = new Map<string, string[]>()
159 for (const prefix of prefixes) {
160 const root = prefix.split(' ')[0]!
161 const group = groups.get(root)
162 if (group) {
163 group.push(prefix)
164 } else {
165 groups.set(root, [prefix])
166 }
167 }
168
169 // Collapse each group via word-aligned LCP
170 const collapsed: string[] = []
171 for (const [, group] of groups) {
172 collapsed.push(longestCommonPrefix(group))
173 }
174 return collapsed
175}
176
177/**
178 * Compute the longest common prefix of strings, aligned to word boundaries.

Callers 2

Calls 6

splitCommand_DEPRECATEDFunction · 0.85
longestCommonPrefixFunction · 0.85
getCommandPrefixStaticFunction · 0.70
getMethod · 0.65
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected