MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / getCommandPrefixImpl

Function getCommandPrefixImpl

src/utils/shell/prefix.ts:172–329  ·  view source on GitHub ↗
(
  command: string,
  abortSignal: AbortSignal,
  isNonInteractiveSession: boolean,
  toolName: string,
  policySpec: string,
  eventName: string,
  querySource: QuerySource,
  preCheck?: (command: string) => CommandPrefixResult | null,
)

Source from the content-addressed store, hash-verified

170}
171
172async function getCommandPrefixImpl(
173 command: string,
174 abortSignal: AbortSignal,
175 isNonInteractiveSession: boolean,
176 toolName: string,
177 policySpec: string,
178 eventName: string,
179 querySource: QuerySource,
180 preCheck?: (command: string) => CommandPrefixResult | null,
181): Promise<CommandPrefixResult | null> {
182 if (process.env.NODE_ENV === 'test') {
183 return null
184 }
185
186 // Run pre-check if provided (e.g., isHelpCommand for Bash)
187 if (preCheck) {
188 const preCheckResult = preCheck(command)
189 if (preCheckResult !== null) {
190 return preCheckResult
191 }
192 }
193
194 let preflightCheckTimeoutId: NodeJS.Timeout | undefined
195 const startTime = Date.now()
196 let result: CommandPrefixResult | null = null
197
198 try {
199 // Log a warning if the pre-flight check takes too long
200 preflightCheckTimeoutId = setTimeout(
201 (tn, nonInteractive) => {
202 const message = `[${tn}Tool] Pre-flight check is taking longer than expected. Run with ANTHROPIC_LOG=debug to check for failed or slow API requests.`
203 if (nonInteractive) {
204 process.stderr.write(jsonStringify({ level: 'warn', message }) + '\n')
205 } else {
206 console.warn(chalk.yellow(`⚠️ ${message}`))
207 }
208 },
209 10000, // 10 seconds
210 toolName,
211 isNonInteractiveSession,
212 )
213
214 const useSystemPromptPolicySpec = getFeatureValue_CACHED_MAY_BE_STALE(
215 'tengu_cork_m4q',
216 false,
217 )
218
219 const response = await queryHaiku({
220 systemPrompt: asSystemPrompt(
221 useSystemPromptPolicySpec
222 ? [
223 `Your task is to process ${toolName} commands that an AI coding agent wants to run.\n\n${policySpec}`,
224 ]
225 : [
226 `Your task is to process ${toolName} commands that an AI coding agent wants to run.\n\nThis policy spec defines how to determine the prefix of a ${toolName} command:`,
227 ],
228 ),
229 userPrompt: useSystemPromptPolicySpec

Callers 1

Calls 10

jsonStringifyFunction · 0.85
queryHaikuFunction · 0.85
asSystemPromptFunction · 0.85
startsWithApiErrorPrefixFunction · 0.85
logEventFunction · 0.85
nowMethod · 0.80
warnMethod · 0.65
writeMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected