-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew-airole
More file actions
executable file
·176 lines (141 loc) · 4.92 KB
/
new-airole
File metadata and controls
executable file
·176 lines (141 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bash
# Generates a new AI role prompt using the role metaprompt
# Environment setup
# -----------------------------------------------------------------------------
set -o pipefail # set -o errexit hides errors, don't use it
[[ ${DEBUG-} ]] && set -o xtrace
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" || exit 1; pwd)"
[[ ":${PATH}:" != *:"${SCRIPT_DIR}":* ]] && export PATH="${SCRIPT_DIR}:${PATH}"
source "${SCRIPT_DIR}/bash_modules/terminal.sh"
source "${SCRIPT_DIR}/bash_modules/desktop.sh"
source "${SCRIPT_DIR}/bash_modules/ai.sh"
[[ -z ${BASH_MODULES_DIR-} ]] && echo "ERROR: terminal.sh module missing" && exit 1
function print_usage() {
cat <<EOF
Usage: $(basename "$0") [-c|--clipboard] [-h|--help] [role_request...]
Generates a new AI role prompt using the role metaprompt.
Gets user input for AI role request, sends to AI, saves result or copies to clipboard.
Repository: https://github.com/grantcarthew/scripts/tree/main
Dependencies:
AI service One of claude, gemini, or aichat (configured via set-aiconfig)
Arguments:
role_request The AI role to create (e.g., 'Python expert', 'DevOps specialist')
If not provided, will prompt for input
Optional arguments:
-c, --clipboard Copy the generated role to clipboard instead of saving to file
-h, --help Show this help message and exit
EOF
}
declare copy_to_clipboard=false
declare -a role_args=()
while [[ $# -gt 0 ]]; do
case "$1" in
-c|--clipboard)
copy_to_clipboard=true
shift
;;
-h|--help)
print_usage
exit 0
;;
-*)
log_error "ERROR: Unknown option '${1}'"
print_usage
exit 1
;;
*)
role_args+=("$1")
shift
;;
esac
done
function ctrlc_trap() {
log_newline
log_warning "Script interrupted. Exiting."
exit 130
}
trap ctrlc_trap SIGINT
# Title and Dependency Checks
# -----------------------------------------------------------------------------
log_title "New AI Role Prompt Generator"
# No external dependencies needed since we're using local files
# Check if AI service is configured
if ! ai_get_command "claude" "fast" >/dev/null 2>&1; then
log_error "ERROR: No AI service configured. Run 'set-aiconfig' to configure AI services."
exit 1
fi
# Report Operational Values
# -----------------------------------------------------------------------------
log_heading "Operational Values"
declare local_file_path="${SCRIPT_DIR}/agents/metaprompts/role.md"
declare output_file="role.md"
log_message "$(
cat <<EOF
copy_to_clipboard: '${copy_to_clipboard}'
local_file_path: '${local_file_path}'
output_file: '${output_file}'
EOF
)"
# User Input
# -----------------------------------------------------------------------------
log_heading "AI Role Request"
if [[ ${#role_args[@]} -gt 0 ]]; then
user_role_request="${role_args[*]}"
log_message "Using role request from command line: '${user_role_request}'"
else
echo "What AI role do you want to create? (e.g., 'Python expert', 'DevOps specialist')" >&2
read -r user_role_request
while [[ -z "${user_role_request}" ]]; do
log_warning "Role request cannot be empty"
echo "What AI role do you want to create?" >&2
read -r user_role_request
done
log_message "Creating AI role for: '${user_role_request}'"
fi
# Load Role Metaprompt
# -----------------------------------------------------------------------------
log_heading "Loading Role Metaprompt"
if [[ ! -f "${local_file_path}" ]]; then
log_error "ERROR: Metaprompt file not found at '${local_file_path}'"
exit 1
fi
log_message "Loading metaprompt from local file"
metaprompt_content="$(cat "${local_file_path}")"
if [[ -z "${metaprompt_content}" ]]; then
log_error "ERROR: Failed to read metaprompt from '${local_file_path}'"
exit 1
fi
log_success "Metaprompt loaded successfully"
# Generate AI Role
# -----------------------------------------------------------------------------
log_heading "Generating AI Role"
combined_prompt="${metaprompt_content}
## User Request
Please create an AI role prompt for: ${user_role_request}"
log_message "Sending request to AI service..."
ai_command=$(ai_get_command "claude" "mid" "" "${combined_prompt}")
ai_response=$(eval "${ai_command}")
if [[ -z "${ai_response}" ]]; then
log_error "ERROR: No response received from AI service"
exit 1
fi
log_success "AI role generated successfully"
# Output Result
# -----------------------------------------------------------------------------
log_heading "Output Result"
if [[ "${copy_to_clipboard}" == true ]]; then
send_to_clipboard "${ai_response}"
log_success "AI role copied to clipboard!"
else
echo "${ai_response}" > "${output_file}"
log_success "AI role saved to '${output_file}'"
# Open the file for editing
if command -v nvim >/dev/null; then
nvim "${output_file}"
elif command -v vim >/dev/null; then
vim "${output_file}"
elif command -v nano >/dev/null; then
nano "${output_file}"
fi
fi
log_done