()
| 17 | } |
| 18 | |
| 19 | async function main() { |
| 20 | const options = parseArgs(process.argv.slice(2)) |
| 21 | if (options.help) { |
| 22 | printHelp() |
| 23 | return |
| 24 | } |
| 25 | |
| 26 | const initialPrompt = await getInitialPrompt(options) |
| 27 | if (initialPrompt) { |
| 28 | await runPromptOnce({ |
| 29 | ...options, |
| 30 | prompt: initialPrompt, |
| 31 | }) |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | const state = createState(options) |
| 36 | const rl = createInterface({ |
| 37 | input: process.stdin, |
| 38 | output: process.stdout, |
| 39 | }) |
| 40 | |
| 41 | console.log('Compatible shell ready.') |
| 42 | console.log(`Workspace: ${state.workspaceDir}`) |
| 43 | console.log(`Model endpoint: ${state.clientConfig.baseUrl}`) |
| 44 | console.log(`Model: ${state.clientConfig.model}`) |
| 45 | console.log(`Session file: ${state.sessionStore.sessionPath}`) |
| 46 | console.log('Type /help for commands.') |
| 47 | |
| 48 | while (true) { |
| 49 | const line = (await rl.question('compat> ')).trim() |
| 50 | if (!line) { |
| 51 | continue |
| 52 | } |
| 53 | |
| 54 | if (line.startsWith('/')) { |
| 55 | const shouldExit = await handleSlashCommand(line, state) |
| 56 | if (shouldExit) { |
| 57 | break |
| 58 | } |
| 59 | continue |
| 60 | } |
| 61 | |
| 62 | await runUserTurn(line, state, rl) |
| 63 | } |
| 64 | |
| 65 | await persistSession(state) |
| 66 | rl.close() |
| 67 | } |
| 68 | |
| 69 | function createState(options = {}) { |
| 70 | const workspaceDir = path.resolve( |
no test coverage detected