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

Function getCommandPrefixImpl

source code/utils/shell/prefix.ts:174–332  ·  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

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

Callers 1

Calls 9

jsonStringifyFunction · 0.85
queryHaikuFunction · 0.85
asSystemPromptFunction · 0.85
startsWithApiErrorPrefixFunction · 0.85
logEventFunction · 0.85
writeMethod · 0.45
warnMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected