s9n-devops-agent 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,299 @@
1
+ #!/usr/bin/env zsh
2
+
3
+ # ============================================================================
4
+ # INTERACTIVE DEVOPS SESSION STARTER
5
+ # ============================================================================
6
+ #
7
+ # This script provides a user-friendly way to start DevOps agent sessions.
8
+ # It handles the complete workflow:
9
+ # 1. Ask if using existing session or creating new
10
+ # 2. If new, creates session and generates instructions for Claude
11
+ # 3. Starts the DevOps agent monitoring the appropriate worktree
12
+ #
13
+ # ============================================================================
14
+
15
+ # Colors for output
16
+ RED='\033[0;31m'
17
+ GREEN='\033[0;32m'
18
+ YELLOW='\033[1;33m'
19
+ BLUE='\033[0;36m'
20
+ MAGENTA='\033[0;35m'
21
+ BOLD='\033[1m'
22
+ DIM='\033[2m'
23
+ NC='\033[0m' # No Color
24
+ BG_BLUE='\033[44m'
25
+ BG_GREEN='\033[42m'
26
+ BG_YELLOW='\033[43m'
27
+
28
+ # Get the directory where this script is located
29
+ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
30
+ SRC_DIR="$SCRIPT_DIR/src"
31
+
32
+ # Function to display copyright
33
+ show_copyright() {
34
+ echo
35
+ echo "======================================================================"
36
+ echo
37
+ echo " CS_DevOpsAgent - Intelligent Git Automation System"
38
+ echo " Version 2.4.0 | Build 20240930.1"
39
+ echo " "
40
+ echo " Copyright (c) 2024 SecondBrain Labs"
41
+ echo " Author: Sachin Dev Duggal"
42
+ echo " "
43
+ echo " Licensed under the MIT License"
44
+ echo " This software is provided 'as-is' without any warranty."
45
+ echo " See LICENSE file for full license text."
46
+ echo "======================================================================"
47
+ echo
48
+ }
49
+
50
+ # Function to display header
51
+ show_header() {
52
+ echo
53
+ echo -e "${BG_BLUE}${BOLD} ${NC}"
54
+ echo -e "${BG_BLUE}${BOLD} DevOps Agent Session Manager ${NC}"
55
+ echo -e "${BG_BLUE}${BOLD} ${NC}"
56
+ echo
57
+ }
58
+
59
+ # Function to display session instructions
60
+ display_instructions() {
61
+ local session_id="$1"
62
+ local worktree_path="$2"
63
+ local branch_name="$3"
64
+ local task="$4"
65
+
66
+ echo
67
+ echo -e "${BG_GREEN}${BOLD} Instructions for Claude/Cline ${NC}"
68
+ echo
69
+ echo -e "${YELLOW}══════════════════════════════════════════════════════════════${NC}"
70
+ echo -e "${BOLD}COPY AND PASTE THIS ENTIRE BLOCK INTO CLAUDE BEFORE YOUR PROMPT:${NC}"
71
+ echo -e "${YELLOW}──────────────────────────────────────────────────────────────${NC}"
72
+ echo
73
+ echo "I'm working in a DevOps-managed session with the following setup:"
74
+ echo "- Session ID: ${session_id}"
75
+ echo "- Working Directory: ${worktree_path}"
76
+ echo "- Task: ${task}"
77
+ echo ""
78
+ echo "Please switch to this directory before making any changes:"
79
+ echo "cd \"${worktree_path}\""
80
+ echo ""
81
+ echo "Write commit messages to: .devops-commit-${session_id}.msg"
82
+ echo "The DevOps agent will automatically commit and push changes."
83
+ echo
84
+ echo -e "${YELLOW}══════════════════════════════════════════════════════════════${NC}"
85
+ echo
86
+ echo -e "${GREEN}✓ DevOps agent will monitor for changes${NC}"
87
+ echo
88
+ }
89
+
90
+ # Function to list existing sessions
91
+ list_sessions() {
92
+ local sessions_dir="local_deploy/session-locks"
93
+
94
+ if [[ ! -d "$sessions_dir" ]] || [[ -z "$(ls -A $sessions_dir 2>/dev/null)" ]]; then
95
+ echo -e "${YELLOW}No existing sessions found.${NC}"
96
+ return 1
97
+ fi
98
+
99
+ echo -e "${BOLD}Existing Sessions:${NC}"
100
+ echo
101
+
102
+ local i=1
103
+ local session_files=()
104
+
105
+ for lock_file in "$sessions_dir"/*.lock; do
106
+ [[ ! -f "$lock_file" ]] && continue
107
+
108
+ local session_data=$(cat "$lock_file")
109
+ local session_id=$(echo "$session_data" | grep -o '"sessionId"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
110
+ local task=$(echo "$session_data" | grep -o '"task"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
111
+ local status=$(echo "$session_data" | grep -o '"status"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
112
+ local created=$(echo "$session_data" | grep -o '"created"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
113
+
114
+ # Color code based on status
115
+ local status_color="${GREEN}"
116
+ [[ "$status" == "stopped" ]] && status_color="${YELLOW}"
117
+ [[ "$status" == "inactive" ]] && status_color="${RED}"
118
+
119
+ echo -e " ${BOLD}$i)${NC} Session: ${BLUE}${session_id}${NC}"
120
+ echo -e " Task: ${task}"
121
+ echo -e " Status: ${status_color}${status}${NC}"
122
+ echo -e " Created: ${created}"
123
+ echo
124
+
125
+ session_files+=("$lock_file")
126
+ ((i++))
127
+ done
128
+
129
+ return 0
130
+ }
131
+
132
+ # Function to create a new session
133
+ create_new_session() {
134
+ echo -e "${BOLD}Creating New Session${NC}"
135
+ echo
136
+
137
+ # Ask for task name
138
+ echo -n "Enter task/feature name (e.g., 'authentication', 'api-endpoints'): "
139
+ read task_name
140
+
141
+ if [[ -z "$task_name" ]]; then
142
+ task_name="development"
143
+ fi
144
+
145
+ # Ask for agent type
146
+ echo -n "Agent type (claude/cline/copilot/cursor) [default: claude]: "
147
+ read agent_type
148
+
149
+ if [[ -z "$agent_type" ]]; then
150
+ agent_type="claude"
151
+ fi
152
+
153
+ echo
154
+ echo -e "${YELLOW}Creating session for: ${task_name}${NC}"
155
+
156
+ # Run the session coordinator to create AND START the session
157
+ cd "$SCRIPT_DIR"
158
+ node "$SRC_DIR/session-coordinator.js" create-and-start --task "$task_name" --agent "$agent_type"
159
+ }
160
+
161
+ # Function to prompt for session selection
162
+ select_session() {
163
+ echo -e "${BOLD}Select an Option:${NC}"
164
+ echo
165
+ echo " ${BOLD}N)${NC} Create a ${GREEN}new${NC} session"
166
+
167
+ # List existing sessions
168
+ local sessions_dir="local_deploy/session-locks"
169
+ local session_files=()
170
+
171
+ if [[ -d "$sessions_dir" ]] && [[ -n "$(ls -A $sessions_dir 2>/dev/null)" ]]; then
172
+ echo
173
+ echo -e "${BOLD}Or select an existing session:${NC}"
174
+ echo
175
+
176
+ local i=1
177
+ for lock_file in "$sessions_dir"/*.lock; do
178
+ [[ ! -f "$lock_file" ]] && continue
179
+
180
+ local session_data=$(cat "$lock_file")
181
+ local session_id=$(echo "$session_data" | grep -o '"sessionId"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
182
+ local task=$(echo "$session_data" | grep -o '"task"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
183
+
184
+ echo -e " ${BOLD}$i)${NC} ${BLUE}${session_id}${NC} - ${task}"
185
+ session_files+=("$lock_file")
186
+ ((i++))
187
+ done
188
+ fi
189
+
190
+ echo
191
+ echo -e " ${BOLD}Q)${NC} ${RED}Quit${NC} - Exit the session manager"
192
+ echo
193
+ echo -n "Your choice: "
194
+ read choice
195
+
196
+ # Handle the choice
197
+ if [[ "$choice" =~ ^[Qq]$ ]]; then
198
+ # Quit the session manager
199
+ echo
200
+ echo -e "${GREEN}Goodbye! Exiting DevOps Session Manager.${NC}"
201
+ exit 0
202
+ elif [[ "$choice" =~ ^[Nn]$ ]]; then
203
+ # Create new session
204
+ create_new_session
205
+ return 0
206
+ elif [[ "$choice" =~ ^[0-9]+$ ]] && [[ "$choice" -ge 1 ]] && [[ "$choice" -le "${#session_files[@]}" ]]; then
207
+ # Use existing session
208
+ local selected_file="${session_files[$choice]}"
209
+ local session_data=$(cat "$selected_file")
210
+ local session_id=$(echo "$session_data" | grep -o '"sessionId"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
211
+ local worktree_path=$(echo "$session_data" | grep -o '"worktreePath"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
212
+ local task=$(echo "$session_data" | grep -o '"task"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
213
+ local branch_name=$(echo "$session_data" | grep -o '"branchName"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
214
+
215
+ echo
216
+ echo -e "${GREEN}Using existing session: ${session_id}${NC}"
217
+
218
+ # Display instructions for Claude/Cline IMMEDIATELY after selection
219
+ display_instructions "$session_id" "$worktree_path" "$branch_name" "$task"
220
+
221
+ # Add a pause and visual separator before starting the agent
222
+ echo -e "${DIM}Press Enter to start the DevOps agent monitoring...${NC}"
223
+ read -r
224
+
225
+ echo
226
+ echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
227
+ echo -e "${BOLD}Starting DevOps Agent${NC}"
228
+ echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
229
+
230
+ # Start the agent for this session
231
+ cd "$SCRIPT_DIR"
232
+ node "$SRC_DIR/session-coordinator.js" start "$session_id"
233
+ return 0
234
+ else
235
+ echo -e "${RED}Invalid choice. Please try again.${NC}"
236
+ return 1
237
+ fi
238
+ }
239
+
240
+ # Main function
241
+ main() {
242
+ # Show copyright first
243
+ show_copyright
244
+
245
+ # Then show the header
246
+ show_header
247
+
248
+ # Check if we're in a git repository
249
+ if ! git rev-parse --git-dir > /dev/null 2>&1; then
250
+ echo -e "${RED}Error: Not in a git repository${NC}"
251
+ echo "Please run this from within a git repository."
252
+ exit 1
253
+ fi
254
+
255
+ # Get repo root
256
+ REPO_ROOT=$(git rev-parse --show-toplevel)
257
+ cd "$REPO_ROOT"
258
+
259
+ echo -e "${BOLD}Welcome to DevOps Agent Session Manager${NC}"
260
+ echo
261
+ echo "This tool will:"
262
+ echo " 1. Help you create or select a session"
263
+ echo " 2. Generate instructions for Claude/Cline"
264
+ echo " 3. Start the DevOps agent to monitor changes"
265
+ echo
266
+
267
+ # Main selection loop
268
+ while true; do
269
+ if select_session; then
270
+ # After agent exits, ask if they want to continue or exit
271
+ echo
272
+ echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
273
+ echo -e "${BOLD}Agent has stopped.${NC}"
274
+ echo -e "${YELLOW}═══════════════════════════════════════════════════════════${NC}"
275
+ echo
276
+ echo -e "Would you like to:"
277
+ echo -e " ${BOLD}1)${NC} Select another session"
278
+ echo -e " ${BOLD}2)${NC} Exit the session manager"
279
+ echo
280
+ echo -n "Your choice [1/2]: "
281
+ read continue_choice
282
+
283
+ if [[ "$continue_choice" == "2" ]]; then
284
+ echo
285
+ echo -e "${GREEN}Goodbye! Thank you for using DevOps Session Manager.${NC}"
286
+ exit 0
287
+ fi
288
+ echo
289
+ echo -e "${BLUE}Returning to session selection...${NC}"
290
+ echo
291
+ fi
292
+ done
293
+ }
294
+
295
+ # Handle Ctrl+C gracefully
296
+ trap 'echo -e "\n${YELLOW}Session terminated by user${NC}"; exit 0' INT
297
+
298
+ # Run main function
299
+ main "$@"