MCPcopy Create free account
hub / github.com/AICoderTudou/claude-code-tudou / runInteractive

Function runInteractive

src/localRecoveryCli.ts:200–285  ·  view source on GitHub ↗
(parsed: {
  model?: string
  systemPrompt?: string
  appendSystemPrompt?: string
})

Source from the content-addressed store, hash-verified

198}
199
200async function runInteractive(parsed: {
201 model?: string
202 systemPrompt?: string
203 appendSystemPrompt?: string
204}): Promise<void> {
205 const apiKey = process.env.ANTHROPIC_API_KEY
206 const authToken = process.env.ANTHROPIC_AUTH_TOKEN
207 if (!apiKey && !authToken) {
208 process.stderr.write(
209 'Error: set ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN\n',
210 )
211 process.exitCode = 1
212 return
213 }
214
215 const model =
216 parsed.model ||
217 process.env.ANTHROPIC_DEFAULT_SONNET_MODEL ||
218 process.env.ANTHROPIC_MODEL
219
220 if (!model) {
221 process.stderr.write('Error: model is required\n')
222 process.exitCode = 1
223 return
224 }
225
226 const client = new Anthropic({
227 apiKey: apiKey ?? undefined,
228 authToken: authToken ?? undefined,
229 baseURL: process.env.ANTHROPIC_BASE_URL || undefined,
230 timeout: parseInt(process.env.API_TIMEOUT_MS || String(600_000), 10),
231 maxRetries: 0,
232 })
233
234 const system = getSystemPrompt(parsed.systemPrompt, parsed.appendSystemPrompt)
235 const messages: Array<{ role: 'user' | 'assistant'; content: string }> = []
236 const rl = createInterface({
237 input: process.stdin,
238 output: process.stdout,
239 prompt: 'you> ',
240 })
241
242 process.stdout.write(
243 `Claude Haha local interactive mode\nmodel: ${model}\ncommands: /exit, /clear\n\n`,
244 )
245 rl.prompt()
246
247 for await (const line of rl) {
248 const input = line.trim()
249 if (!input) {
250 rl.prompt()
251 continue
252 }
253 if (input === '/exit' || input === '/quit') {
254 rl.close()
255 break
256 }
257 if (input === '/clear') {

Callers 1

runFunction · 0.85

Calls 4

getSystemPromptFunction · 0.70
createMethod · 0.65
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected