MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / createSubcommandPrefixExtractor

Function createSubcommandPrefixExtractor

src/utils/shell/prefix.ts:138–170  ·  view source on GitHub ↗
(
  getPrefix: ReturnType<typeof createCommandPrefixExtractor>,
  splitCommand: (command: string) => string[] | Promise<string[]>,
)

Source from the content-addressed store, hash-verified

136 * @returns A memoized async function that extracts prefixes for the main command and all subcommands
137 */
138export function createSubcommandPrefixExtractor(
139 getPrefix: ReturnType<typeof createCommandPrefixExtractor>,
140 splitCommand: (command: string) => string[] | Promise<string[]>,
141) {
142 const memoized = memoizeWithLRU(
143 (
144 command: string,
145 abortSignal: AbortSignal,
146 isNonInteractiveSession: boolean,
147 ): Promise<CommandSubcommandPrefixResult | null> => {
148 const promise = getCommandSubcommandPrefixImpl(
149 command,
150 abortSignal,
151 isNonInteractiveSession,
152 getPrefix,
153 splitCommand,
154 )
155 // Evict on rejection so aborted calls don't poison future turns.
156 // Identity guard: after LRU eviction, a newer promise may occupy
157 // this key; a stale rejection must not delete it.
158 promise.catch(() => {
159 if (memoized.cache.get(command) === promise) {
160 memoized.cache.delete(command)
161 }
162 })
163 return promise
164 },
165 command => command, // memoize by command only
166 200,
167 )
168
169 return memoized
170}
171
172async function getCommandPrefixImpl(
173 command: string,

Callers 1

commands.tsFile · 0.85

Calls 4

getMethod · 0.65
deleteMethod · 0.65
memoizeWithLRUFunction · 0.50

Tested by

no test coverage detected