let l:end_line = line("'>")
let l:selected_text = a:user_prompt . shellescape(join(getline(l:start_line, l:end_line)))
- let l:system_prompt = "detect programming language, reply with one function (do not implement other functions) code should be able to copied right into an editor, no explaining text, start always with ```c and end with ```"
+ let l:system_prompt = "detect programming language, reply with one function (do not implement other functions) code should be able to copied right into an editor, no explaining text, start always with ``` and end with ```"
" Prepare the JSON payload
let l:json_data = {
put =l:refactored_code
endfunction
+function! ClaudyBrainstorm()
+ " Create new window
+ botright new
+ setlocal buftype=nofile
+ setlocal bufhidden=hide
+ setlocal noswapfile
+ setlocal nowrap
+ let b:chat_history = []
+
+ " Set buffer name
+ file Claude-Chat
+
+ " Initialize with greeting
+ call append(0, "=== Claude Chat ===")
+ call append(1, "Type your message and press Enter to chat. Press q to quit.")
+ call append(2, "")
+
+ " Set up mappings for this buffer
+ nnoremap <buffer> <CR> :call <SID>SendMessage()<CR>
+ nnoremap <buffer> q :q<CR>
+
+ " Start in insert mode at the bottom
+ normal! G
+ startinsert!
+endfunction
+
+function! s:SendMessage()
+ " Get the last line as user message
+ let l:user_msg = getline('$')
+
+ " Skip if empty
+ if empty(l:user_msg)
+ return
+ endif
+
+ " Prepare JSON data
+ let l:json_data = {
+ \ 'model': 'claude-3-5-sonnet-20241022',
+ \ 'max_tokens': 1024,
+ \ 'messages': [
+ \ {
+ \ 'role': 'user',
+ \ 'content': l:user_msg
+ \ }
+ \ ]
+ \ }
+
+ " Add chat history if exists
+ if exists('b:chat_history') && len(b:chat_history) > 0
+ let l:json_data.messages = b:chat_history + l:json_data.messages
+ endif
+
+ " Get response
+ let l:response = ClaudyRequest(l:json_data)
+
+ " Update chat history
+ call add(b:chat_history, {'role': 'user', 'content': l:user_msg})
+ call add(b:chat_history, {'role': 'assistant', 'content': l:response})
+
+ " Add visual separator
+ call append('$', repeat('-', 80))
+ " Add response
+ put =l:response
+ " call append('$', 'Claude: ' . l:response)
+ call append('$', '')
+
+ " Move cursor to new line
+ normal! G
+ startinsert!
+endfunction
+
vnoremap <leader>c :<c-u>call ClaudyRefactor()
vnoremap <leader>i :<c-u>call ClaudyImplement()
vnoremap <leader>b :<c-u>call ClaudyTest()