Skip to content

Commit 8ab2d56

Browse files
committed
refactor: standardize AI and editor adapter initialization
Consolidate common logic for AI and editor adapters into reusable functions. Introduce _ai_define_standard and _editor_define_standard to streamline adapter setup, reducing redundancy across multiple adapter scripts. This refactor enhances maintainability and clarity in the codebase.
1 parent d7d0db8 commit 8ab2d56

19 files changed

Lines changed: 326 additions & 563 deletions

adapters/ai/aider.sh

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
11
#!/usr/bin/env bash
22
# Aider AI coding assistant adapter
33

4-
# Check if Aider is available
5-
ai_can_start() {
6-
command -v aider >/dev/null 2>&1
7-
}
8-
9-
# Start Aider in a directory
10-
# Usage: ai_start path [args...]
11-
ai_start() {
12-
local path="$1"
13-
shift
14-
15-
if ! ai_can_start; then
16-
log_error "Aider not found. Install with: pip install aider-chat"
17-
log_info "See https://aider.chat for more information"
18-
return 1
19-
fi
20-
21-
if [ ! -d "$path" ]; then
22-
log_error "Directory not found: $path"
23-
return 1
24-
fi
25-
26-
# Change to the directory and run aider with any additional arguments
27-
(cd "$path" && aider "$@")
28-
}
4+
_AI_CMD="aider"
5+
_AI_ERR_MSG="Aider not found. Install with: pip install aider-chat"
6+
_AI_INFO_LINES=("See https://aider.chat for more information")
7+
_ai_define_standard

adapters/ai/auggie.sh

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
#!/usr/bin/env bash
22
# Auggie CLI AI adapter
33

4-
# Check if Auggie is available
5-
ai_can_start() {
6-
command -v auggie >/dev/null 2>&1
7-
}
8-
9-
# Start Auggie in a directory
10-
# Usage: ai_start path [args...]
11-
ai_start() {
12-
local path="$1"
13-
shift
14-
15-
if ! ai_can_start; then
16-
log_error "Auggie CLI not found. Install with: npm install -g @augmentcode/auggie"
17-
log_info "See https://www.augmentcode.com/product/CLI for more information"
18-
return 1
19-
fi
20-
21-
if [ ! -d "$path" ]; then
22-
log_error "Directory not found: $path"
23-
return 1
24-
fi
25-
26-
# Change to the directory and run auggie with any additional arguments
27-
(cd "$path" && auggie "$@")
28-
}
29-
4+
_AI_CMD="auggie"
5+
_AI_ERR_MSG="Auggie CLI not found. Install with: npm install -g @augmentcode/auggie"
6+
_AI_INFO_LINES=("See https://www.augmentcode.com/product/CLI for more information")
7+
_ai_define_standard

adapters/ai/codex.sh

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
#!/usr/bin/env bash
22
# OpenAI Codex CLI adapter
33

4-
# Check if Codex is available
5-
ai_can_start() {
6-
command -v codex >/dev/null 2>&1
7-
}
8-
9-
# Start Codex in a directory
10-
# Usage: ai_start path [args...]
11-
ai_start() {
12-
local path="$1"
13-
shift
14-
15-
if ! ai_can_start; then
16-
log_error "Codex CLI not found. Install with: npm install -g @openai/codex"
17-
log_info "Or: brew install codex"
18-
log_info "See https://github.com/openai/codex for more info"
19-
return 1
20-
fi
21-
22-
if [ ! -d "$path" ]; then
23-
log_error "Directory not found: $path"
24-
return 1
25-
fi
26-
27-
# Change to the directory and run codex with any additional arguments
28-
(cd "$path" && codex "$@")
29-
}
4+
_AI_CMD="codex"
5+
_AI_ERR_MSG="Codex CLI not found. Install with: npm install -g @openai/codex"
6+
_AI_INFO_LINES=(
7+
"Or: brew install codex"
8+
"See https://github.com/openai/codex for more info"
9+
)
10+
_ai_define_standard

adapters/ai/continue.sh

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
11
#!/usr/bin/env bash
22
# Continue CLI adapter
33

4-
# Check if Continue is available
5-
ai_can_start() {
6-
command -v cn >/dev/null 2>&1
7-
}
8-
9-
# Start Continue in a directory
10-
# Usage: ai_start path [args...]
11-
ai_start() {
12-
local path="$1"
13-
shift
14-
15-
if ! ai_can_start; then
16-
log_error "Continue CLI not found. Install from https://continue.dev"
17-
log_info "See https://docs.continue.dev/cli/install for installation"
18-
return 1
19-
fi
20-
21-
if [ ! -d "$path" ]; then
22-
log_error "Directory not found: $path"
23-
return 1
24-
fi
25-
26-
# Change to the directory and run cn with any additional arguments
27-
(cd "$path" && cn "$@")
28-
}
4+
_AI_CMD="cn"
5+
_AI_ERR_MSG="Continue CLI not found. Install from https://continue.dev"
6+
_AI_INFO_LINES=("See https://docs.continue.dev/cli/install for installation")
7+
_ai_define_standard

adapters/ai/copilot.sh

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
11
#!/usr/bin/env bash
22
# GitHub Copilot CLI adapter
33

4-
# Check if GitHub Copilot CLI is available
5-
ai_can_start() {
6-
command -v copilot >/dev/null 2>&1
7-
}
8-
9-
# Start GitHub Copilot CLI in a directory
10-
# Usage: ai_start path [args...]
11-
ai_start() {
12-
local path="$1"
13-
shift
14-
15-
if ! ai_can_start; then
16-
log_error "GitHub Copilot CLI not found."
17-
log_info "Install with: npm install -g @github/copilot"
18-
log_info "Or: brew install copilot-cli"
19-
log_info "See https://github.com/github/copilot-cli for more information"
20-
return 1
21-
fi
22-
23-
if [ ! -d "$path" ]; then
24-
log_error "Directory not found: $path"
25-
return 1
26-
fi
27-
28-
# Change to the directory and run copilot with any additional arguments
29-
(cd "$path" && copilot "$@")
30-
}
4+
_AI_CMD="copilot"
5+
_AI_ERR_MSG="GitHub Copilot CLI not found."
6+
_AI_INFO_LINES=(
7+
"Install with: npm install -g @github/copilot"
8+
"Or: brew install copilot-cli"
9+
"See https://github.com/github/copilot-cli for more information"
10+
)
11+
_ai_define_standard

adapters/ai/gemini.sh

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,10 @@
11
#!/usr/bin/env bash
22
# Gemini CLI adapter
33

4-
# Check if Gemini is available
5-
ai_can_start() {
6-
command -v gemini >/dev/null 2>&1
7-
}
8-
9-
# Start Gemini in a directory
10-
# Usage: ai_start path [args...]
11-
ai_start() {
12-
local path="$1"
13-
shift
14-
15-
if ! ai_can_start; then
16-
log_error "Gemini CLI not found. Install with: npm install -g @google/gemini-cli"
17-
log_info "Or: brew install gemini-cli"
18-
log_info "See https://github.com/google-gemini/gemini-cli for more info"
19-
return 1
20-
fi
21-
22-
if [ ! -d "$path" ]; then
23-
log_error "Directory not found: $path"
24-
return 1
25-
fi
26-
27-
# Change to the directory and run gemini with any additional arguments
28-
(cd "$path" && gemini "$@")
29-
}
4+
_AI_CMD="gemini"
5+
_AI_ERR_MSG="Gemini CLI not found. Install with: npm install -g @google/gemini-cli"
6+
_AI_INFO_LINES=(
7+
"Or: brew install gemini-cli"
8+
"See https://github.com/google-gemini/gemini-cli for more info"
9+
)
10+
_ai_define_standard

adapters/ai/opencode.sh

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
#!/usr/bin/env bash
22
# OpenCode adapter
33

4-
# Check if OpenCode is available
5-
ai_can_start() {
6-
command -v opencode >/dev/null 2>&1
7-
}
8-
9-
# Start OpenCode in a directory
10-
# Usage: ai_start path [args...]
11-
ai_start() {
12-
local path="$1"
13-
shift
14-
15-
if ! ai_can_start; then
16-
log_error "OpenCode not found. Install from https://opencode.ai"
17-
log_info "Make sure the 'opencode' CLI is available in your PATH"
18-
return 1
19-
fi
20-
21-
if [ ! -d "$path" ]; then
22-
log_error "Directory not found: $path"
23-
return 1
24-
fi
25-
26-
# Change to the directory and run opencode with any additional arguments
27-
(cd "$path" && opencode "$@")
28-
}
29-
4+
_AI_CMD="opencode"
5+
_AI_ERR_MSG="OpenCode not found. Install from https://opencode.ai"
6+
_AI_INFO_LINES=("Make sure the 'opencode' CLI is available in your PATH")
7+
_ai_define_standard

adapters/editor/atom.sh

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
#!/usr/bin/env bash
22
# Atom editor adapter
33

4-
# Check if Atom is available
5-
editor_can_open() {
6-
command -v atom >/dev/null 2>&1
7-
}
8-
9-
# Open a directory in Atom
10-
# Usage: editor_open path
11-
editor_open() {
12-
local path="$1"
13-
14-
if ! editor_can_open; then
15-
log_error "Atom not found. Install from https://atom.io"
16-
return 1
17-
fi
18-
19-
atom "$path"
20-
}
4+
_EDITOR_CMD="atom"
5+
_EDITOR_ERR_MSG="Atom not found. Install from https://atom.io"
6+
_editor_define_standard

adapters/editor/cursor.sh

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
#!/usr/bin/env bash
22
# Cursor editor adapter
33

4-
# Check if Cursor is available
5-
editor_can_open() {
6-
command -v cursor >/dev/null 2>&1
7-
}
8-
9-
# Open a directory or workspace file in Cursor
10-
# Usage: editor_open path [workspace_file]
11-
editor_open() {
12-
local path="$1"
13-
local workspace="${2:-}"
14-
15-
if ! editor_can_open; then
16-
log_error "Cursor not found. Install from https://cursor.com or enable the shell command."
17-
return 1
18-
fi
19-
20-
# Open workspace file if provided, otherwise open directory
21-
if [ -n "$workspace" ] && [ -f "$workspace" ]; then
22-
cursor "$workspace"
23-
else
24-
cursor "$path"
25-
fi
26-
}
4+
_EDITOR_CMD="cursor"
5+
_EDITOR_ERR_MSG="Cursor not found. Install from https://cursor.com or enable the shell command."
6+
_EDITOR_WORKSPACE=1
7+
_editor_define_standard

adapters/editor/idea.sh

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
#!/usr/bin/env bash
22
# IntelliJ IDEA editor adapter
33

4-
# Check if IntelliJ IDEA is available
5-
editor_can_open() {
6-
command -v idea >/dev/null 2>&1
7-
}
8-
9-
# Open a directory in IntelliJ IDEA
10-
# Usage: editor_open path
11-
editor_open() {
12-
local path="$1"
13-
14-
if ! editor_can_open; then
15-
log_error "IntelliJ IDEA 'idea' command not found. Enable shell launcher in Tools > Create Command-line Launcher"
16-
return 1
17-
fi
18-
19-
idea "$path"
20-
}
4+
_EDITOR_CMD="idea"
5+
_EDITOR_ERR_MSG="IntelliJ IDEA 'idea' command not found. Enable shell launcher in Tools > Create Command-line Launcher"
6+
_editor_define_standard

0 commit comments

Comments
 (0)