MCPcopy
hub / github.com/claude-code-best/claude-code / createCommandPrefixExtractor

Function createCommandPrefixExtractor

src/utils/shell/prefix.ts:92–126  ·  view source on GitHub ↗
(config: PrefixExtractorConfig)

Source from the content-addressed store, hash-verified

90 * @returns A memoized async function that extracts command prefixes
91 */
92export function createCommandPrefixExtractor(config: PrefixExtractorConfig) {
93 const { toolName, policySpec, eventName, querySource, preCheck } = config
94
95 const memoized = memoizeWithLRU(
96 (
97 command: string,
98 abortSignal: AbortSignal,
99 isNonInteractiveSession: boolean,
100 ): Promise<CommandPrefixResult | null> => {
101 const promise = getCommandPrefixImpl(
102 command,
103 abortSignal,
104 isNonInteractiveSession,
105 toolName,
106 policySpec,
107 eventName,
108 querySource,
109 preCheck,
110 )
111 // Evict on rejection so aborted calls don't poison future turns.
112 // Identity guard: after LRU eviction, a newer promise may occupy
113 // this key; a stale rejection must not delete it.
114 promise.catch(() => {
115 if (memoized.cache.get(command) === promise) {
116 memoized.cache.delete(command)
117 }
118 })
119 return promise
120 },
121 command => command, // memoize by command only
122 200,
123 )
124
125 return memoized
126}
127
128/**
129 * Creates a memoized function to get prefixes for compound commands with subcommands.

Callers 1

commands.tsFile · 0.85

Calls 4

getCommandPrefixImplFunction · 0.85
getMethod · 0.65
deleteMethod · 0.65
memoizeWithLRUFunction · 0.50

Tested by

no test coverage detected