| #!/usr/bin/env zsh |
|
|
| |
|
|
| |
| |
| |
| |
| |
| function _forge_action_default() { |
| local user_action="$1" |
| local input_text="$2" |
| local command_type="" |
| |
| |
| if [[ -n "$user_action" ]]; then |
| local commands_list=$(_forge_get_commands) |
| if [[ -n "$commands_list" ]]; then |
| |
| local command_row=$(echo "$commands_list" | grep "^${user_action}\b") |
| if [[ -z "$command_row" ]]; then |
| echo |
| _forge_log error "Command '\033[1m${user_action}\033[0m' not found" |
| return 0 |
| fi |
| |
| |
| |
| command_type=$(echo "$command_row" | awk '{print $2}') |
| |
| if [[ "${command_type:l}" == "custom" ]]; then |
| |
| if [[ -z "$_FORGE_CONVERSATION_ID" ]]; then |
| local new_id=$($_FORGE_BIN conversation new) |
| |
| _FORGE_CONVERSATION_ID="$new_id" |
| fi |
| |
| echo |
| |
| if [[ -n "$input_text" ]]; then |
| _forge_exec cmd execute --cid "$_FORGE_CONVERSATION_ID" "$user_action" "$input_text" |
| else |
| _forge_exec cmd execute --cid "$_FORGE_CONVERSATION_ID" "$user_action" |
| fi |
| return 0 |
| fi |
| fi |
| fi |
| |
| |
| if [[ -z "$input_text" ]]; then |
| if [[ -n "$user_action" ]]; then |
| if [[ "${command_type:l}" != "agent" ]]; then |
| echo |
| _forge_log error "Command '\033[1m${user_action}\033[0m' not found" |
| return 0 |
| fi |
| echo |
| |
| _FORGE_ACTIVE_AGENT="$user_action" |
| _forge_log info "\033[1;37m${_FORGE_ACTIVE_AGENT:u}\033[0m \033[90mis now the active agent\033[0m" |
| fi |
| return 0 |
| fi |
| |
| |
| if [[ -z "$_FORGE_CONVERSATION_ID" ]]; then |
| local new_id=$($_FORGE_BIN conversation new) |
| |
| _FORGE_CONVERSATION_ID="$new_id" |
| fi |
| |
| echo |
| |
| |
| if [[ -n "$user_action" ]]; then |
| _FORGE_ACTIVE_AGENT="$user_action" |
| fi |
| |
| |
| _forge_exec_interactive -p "$input_text" --cid "$_FORGE_CONVERSATION_ID" |
| |
| |
| _forge_start_background_sync |
| |
| _forge_start_background_update |
| } |
|
|
| function forge-accept-line() { |
| |
| local original_buffer="$BUFFER" |
| |
| |
| local user_action="" |
| local input_text="" |
| |
| |
| if [[ "$BUFFER" =~ "^:([a-zA-Z][a-zA-Z0-9_-]*)( (.*))?$" ]]; then |
| |
| user_action="${match[1]}" |
| |
| if [[ -n "${match[2]}" ]]; then |
| input_text="${match[3]}" |
| else |
| input_text="" |
| fi |
| elif [[ "$BUFFER" =~ "^: (.*)$" ]]; then |
| |
| user_action="" |
| input_text="${match[1]}" |
| else |
| |
| zle accept-line |
| return |
| fi |
| |
| |
| print -s -- "$original_buffer" |
| |
| CURSOR=${#BUFFER} |
| zle redisplay |
| |
| |
| case "$user_action" in |
| ask) |
| user_action="sage" |
| ;; |
| plan) |
| user_action="muse" |
| ;; |
| esac |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| _forge_osc133_emit "B" |
| _forge_osc133_emit "C" |
| |
| |
| case "$user_action" in |
| new|n) |
| _forge_action_new "$input_text" |
| ;; |
| info|i) |
| _forge_action_info |
| ;; |
| dump|d) |
| _forge_action_dump "$input_text" |
| ;; |
| compact) |
| _forge_action_compact |
| ;; |
| retry|r) |
| _forge_action_retry |
| ;; |
| help) |
| _forge_action_help |
| ;; |
| agent|a) |
| _forge_action_agent "$input_text" |
| ;; |
| conversation|c) |
| _forge_action_conversation "$input_text" |
| ;; |
| conversation-tree|ct) |
| _forge_action_conversation_tree |
| ;; |
| config-model|cm) |
| _forge_action_model "$input_text" |
| ;; |
| model|m) |
| _forge_action_session_model "$input_text" |
| ;; |
| config-reload|cr|model-reset|mr) |
| _forge_action_config_reload |
| ;; |
| reasoning-effort|re) |
| _forge_action_reasoning_effort "$input_text" |
| ;; |
| config-reasoning-effort|cre) |
| _forge_action_config_reasoning_effort "$input_text" |
| ;; |
| config-commit-model|ccm) |
| _forge_action_commit_model "$input_text" |
| ;; |
| config-suggest-model|csm) |
| _forge_action_suggest_model "$input_text" |
| ;; |
| tools|t) |
| _forge_action_tools |
| ;; |
| config|env|e) |
| _forge_action_config |
| ;; |
| config-edit|ce) |
| _forge_action_config_edit |
| ;; |
| skill) |
| _forge_action_skill |
| ;; |
| edit|ed) |
| _forge_action_editor "$input_text" |
| local action_status=$? |
| _forge_osc133_emit "D;$action_status" |
| _forge_osc133_emit "A" |
| |
| return $action_status |
| ;; |
| commit) |
| _forge_action_commit "$input_text" |
| ;; |
| commit-preview) |
| _forge_action_commit_preview "$input_text" |
| local action_status=$? |
| _forge_osc133_emit "D;$action_status" |
| _forge_osc133_emit "A" |
| |
| return $action_status |
| ;; |
| suggest|s) |
| _forge_action_suggest "$input_text" |
| local action_status=$? |
| _forge_osc133_emit "D;$action_status" |
| _forge_osc133_emit "A" |
| |
| return $action_status |
| ;; |
| clone) |
| _forge_action_clone "$input_text" |
| ;; |
| rename|rn) |
| _forge_action_rename "$input_text" |
| ;; |
| conversation-rename) |
| _forge_action_conversation_rename "$input_text" |
| ;; |
| copy) |
| _forge_action_copy |
| ;; |
| workspace-sync|sync) |
| _forge_action_sync |
| ;; |
| workspace-init|sync-init) |
| _forge_action_sync_init |
| ;; |
| workspace-status|sync-status) |
| _forge_action_sync_status |
| ;; |
| workspace-info|sync-info) |
| _forge_action_sync_info |
| ;; |
| provider-login|login|provider) |
| _forge_action_login "$input_text" |
| ;; |
| logout) |
| _forge_action_logout "$input_text" |
| ;; |
| *) |
| _forge_action_default "$user_action" "$input_text" |
| ;; |
| esac |
| |
| local action_status=$? |
| _forge_osc133_emit "D;$action_status" |
| _forge_osc133_emit "A" |
| |
| |
| |
| |
| _forge_reset |
| return $action_status |
| } |
|
|