| #!/usr/bin/env zsh |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| function _forge_switch_conversation() { |
| local new_conversation_id="$1" |
| |
| |
| if [[ -n "$_FORGE_CONVERSATION_ID" && "$_FORGE_CONVERSATION_ID" != "$new_conversation_id" ]]; then |
| |
| _FORGE_PREVIOUS_CONVERSATION_ID="$_FORGE_CONVERSATION_ID" |
| fi |
| |
| |
| _FORGE_CONVERSATION_ID="$new_conversation_id" |
| } |
|
|
| |
| function _forge_clear_conversation() { |
| |
| if [[ -n "$_FORGE_CONVERSATION_ID" ]]; then |
| _FORGE_PREVIOUS_CONVERSATION_ID="$_FORGE_CONVERSATION_ID" |
| fi |
| |
| |
| _FORGE_CONVERSATION_ID="" |
| } |
|
|
| |
| function _forge_action_conversation() { |
| local input_text="$1" |
| |
| echo |
| |
| |
| if [[ "$input_text" == "-" ]]; then |
| |
| if [[ -z "$_FORGE_PREVIOUS_CONVERSATION_ID" ]]; then |
| |
| input_text="" |
| |
| else |
| |
| local temp="$_FORGE_CONVERSATION_ID" |
| _FORGE_CONVERSATION_ID="$_FORGE_PREVIOUS_CONVERSATION_ID" |
| _FORGE_PREVIOUS_CONVERSATION_ID="$temp" |
| |
| |
| echo |
| _forge_exec conversation show "$_FORGE_CONVERSATION_ID" |
| |
| |
| _forge_exec conversation info "$_FORGE_CONVERSATION_ID" |
| |
| |
| _forge_log success "Switched to conversation \033[1m${_FORGE_CONVERSATION_ID}\033[0m" |
| |
| return 0 |
| fi |
| fi |
| |
| |
| if [[ -n "$input_text" ]]; then |
| local conversation_id="$input_text" |
| |
| |
| _forge_switch_conversation "$conversation_id" |
| |
| |
| echo |
| _forge_exec conversation show "$conversation_id" |
| |
| |
| _forge_exec conversation info "$conversation_id" |
| |
| |
| _forge_log success "Switched to conversation \033[1m${conversation_id}\033[0m" |
| |
| return 0 |
| fi |
| |
| |
| local conversation_id |
| conversation_id=$(_forge_select conversation) |
| |
| if [[ -n "$conversation_id" ]]; then |
| |
| _forge_switch_conversation "$conversation_id" |
| |
| |
| echo |
| _forge_exec conversation show "$conversation_id" |
| |
| |
| _forge_exec conversation info "$conversation_id" |
| |
| |
| _forge_log success "Switched to conversation \033[1m${conversation_id}\033[0m" |
| fi |
| } |
|
|
|
|
| |
| function _forge_action_conversation_tree() { |
| _forge_select conversation --parent "$_FORGE_CONVERSATION_ID" |
| } |
|
|
| |
| function _forge_action_clone() { |
| local input_text="$1" |
| local clone_target="$input_text" |
| |
| echo |
| |
| |
| if [[ -n "$clone_target" ]]; then |
| _forge_clone_and_switch "$clone_target" |
| return 0 |
| fi |
| |
| |
| local conversation_id |
| conversation_id=$(_forge_select conversation) |
| |
| if [[ -n "$conversation_id" ]]; then |
| _forge_clone_and_switch "$conversation_id" |
| fi |
| } |
|
|
| |
| |
| function _forge_action_copy() { |
| echo |
|
|
| if [[ -z "$_FORGE_CONVERSATION_ID" ]]; then |
| _forge_log error "No active conversation. Start a conversation first or use :conversation to see existing ones" |
| return 0 |
| fi |
|
|
| |
| local content |
| content=$($_FORGE_BIN conversation show --md "$_FORGE_CONVERSATION_ID" 2>/dev/null) |
|
|
| if [[ -z "$content" ]]; then |
| _forge_log error "No assistant message found in the current conversation" |
| return 0 |
| fi |
|
|
| |
| if command -v pbcopy &>/dev/null; then |
| echo -n "$content" | pbcopy |
| elif command -v xclip &>/dev/null; then |
| echo -n "$content" | xclip -selection clipboard |
| elif command -v xsel &>/dev/null; then |
| echo -n "$content" | xsel --clipboard --input |
| else |
| _forge_log error "No clipboard utility found (pbcopy, xclip, or xsel required)" |
| return 0 |
| fi |
|
|
| |
| local line_count byte_count |
| line_count=$(echo "$content" | wc -l | tr -d ' ') |
| byte_count=$(echo -n "$content" | wc -c | tr -d ' ') |
|
|
| _forge_log success "Copied to clipboard \033[90m[${line_count} lines, ${byte_count} bytes]\033[0m" |
| } |
|
|
| |
| |
| function _forge_action_rename() { |
| local input_text="$1" |
|
|
| echo |
|
|
| if [[ -z "$_FORGE_CONVERSATION_ID" ]]; then |
| _forge_log error "No active conversation. Start a conversation first or use :conversation to select one" |
| return 0 |
| fi |
|
|
| if [[ -z "$input_text" ]]; then |
| _forge_log error "Usage: :rename <name>" |
| return 0 |
| fi |
|
|
| _forge_exec conversation rename "$_FORGE_CONVERSATION_ID" $input_text |
| } |
|
|
| |
| |
| function _forge_action_conversation_rename() { |
| local input_text="$1" |
|
|
| echo |
|
|
| |
| if [[ -n "$input_text" ]]; then |
| local conversation_id="${input_text%% *}" |
| local new_name="${input_text#* }" |
|
|
| if [[ "$conversation_id" == "$new_name" ]]; then |
| |
| _forge_log error "Usage: :conversation-rename <id> <name>" |
| return 0 |
| fi |
|
|
| _forge_exec conversation rename "$conversation_id" $new_name |
| return 0 |
| fi |
|
|
| |
| local conversation_id |
| conversation_id=$(_forge_select conversation) |
|
|
| if [[ -n "$conversation_id" ]]; then |
| |
| echo -n "Enter new name: " |
| read -r new_name </dev/tty |
|
|
| if [[ -n "$new_name" ]]; then |
| _forge_exec conversation rename "$conversation_id" $new_name |
| else |
| _forge_log error "No name provided, rename cancelled" |
| fi |
| fi |
| } |
|
|
| |
| function _forge_clone_and_switch() { |
| local clone_target="$1" |
| |
| |
| local original_conversation_id="$_FORGE_CONVERSATION_ID" |
| |
| |
| _forge_log info "Cloning conversation \033[1m${clone_target}\033[0m" |
| local clone_output |
| clone_output=$($_FORGE_BIN conversation clone "$clone_target" 2>&1) |
| local clone_exit_code=$? |
| |
| if [[ $clone_exit_code -eq 0 ]]; then |
| |
| local new_id=$(echo "$clone_output" | grep -oE '[a-f0-9-]{36}' | tail -1) |
| |
| if [[ -n "$new_id" ]]; then |
| |
| _forge_switch_conversation "$new_id" |
| |
| _forge_log success "└─ Switched to conversation \033[1m${new_id}\033[0m" |
| |
| |
| if [[ "$clone_target" != "$original_conversation_id" ]]; then |
| echo |
| _forge_exec conversation show "$new_id" |
| |
| |
| echo |
| _forge_exec conversation info "$new_id" |
| fi |
| else |
| _forge_log error "Failed to extract new conversation ID from clone output" |
| fi |
| else |
| _forge_log error "Failed to clone conversation: $clone_output" |
| fi |
| } |
|
|