agentk8 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.
package/lib/visual.sh ADDED
@@ -0,0 +1,349 @@
1
+ #!/usr/bin/env bash
2
+ # AGENT-K Visual Mode Library
3
+ # tmux-based multi-pane agent visualization
4
+
5
+ set -euo pipefail
6
+
7
+ # Source dependencies
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ source "$SCRIPT_DIR/core.sh"
10
+ source "$SCRIPT_DIR/ui.sh"
11
+
12
+ # =============================================================================
13
+ # CONSTANTS
14
+ # =============================================================================
15
+
16
+ TMUX_SESSION_NAME="agentk"
17
+ TMUX_MAIN_WINDOW="main"
18
+
19
+ # =============================================================================
20
+ # TMUX DETECTION
21
+ # =============================================================================
22
+
23
+ check_tmux() {
24
+ if ! command -v tmux &>/dev/null; then
25
+ log_error "tmux is not installed"
26
+ echo "Install with: brew install tmux"
27
+ return 1
28
+ fi
29
+ return 0
30
+ }
31
+
32
+ is_inside_tmux() {
33
+ [[ -n "${TMUX:-}" ]]
34
+ }
35
+
36
+ session_exists() {
37
+ tmux has-session -t "$TMUX_SESSION_NAME" 2>/dev/null
38
+ }
39
+
40
+ # =============================================================================
41
+ # LAYOUT CONFIGURATIONS
42
+ # =============================================================================
43
+
44
+ # Dev mode: 6 panes (3x2 grid)
45
+ # ┌───────────────┬───────────────┬───────────────┐
46
+ # │ ORCHESTRATOR │ ENGINEER │ TESTER │
47
+ # ├───────────────┼───────────────┼───────────────┤
48
+ # │ SECURITY │ SCOUT │ [MAIN] │
49
+ # └───────────────┴───────────────┴───────────────┘
50
+
51
+ # ML mode: 6 panes (3x2 grid)
52
+ # ┌───────────────┬───────────────┬───────────────┐
53
+ # │ ORCHESTRATOR │ RESEARCHER │ ML ENGINEER │
54
+ # ├───────────────┼───────────────┼───────────────┤
55
+ # │ DATA ENGINEER │ EVALUATOR │ SCOUT │
56
+ # └───────────────┴───────────────┴───────────────┘
57
+
58
+ get_agents_for_mode() {
59
+ local mode="$1"
60
+ case "$mode" in
61
+ dev)
62
+ echo "orchestrator engineer tester security scout main"
63
+ ;;
64
+ ml)
65
+ echo "orchestrator researcher ml-engineer data-engineer evaluator scout"
66
+ ;;
67
+ esac
68
+ }
69
+
70
+ # =============================================================================
71
+ # SESSION MANAGEMENT
72
+ # =============================================================================
73
+
74
+ create_tmux_session() {
75
+ local mode="${1:-dev}"
76
+
77
+ if session_exists; then
78
+ log_warn "Session $TMUX_SESSION_NAME already exists"
79
+ return 0
80
+ fi
81
+
82
+ log_info "Creating tmux session: $TMUX_SESSION_NAME"
83
+
84
+ # Create new detached session
85
+ tmux new-session -d -s "$TMUX_SESSION_NAME" -n "$TMUX_MAIN_WINDOW"
86
+
87
+ # Set up the layout
88
+ setup_layout "$mode"
89
+
90
+ log_info "tmux session created"
91
+ }
92
+
93
+ setup_layout() {
94
+ local mode="$1"
95
+ local agents
96
+ agents=($(get_agents_for_mode "$mode"))
97
+
98
+ # Start with a single pane, then split
99
+ local session="$TMUX_SESSION_NAME:$TMUX_MAIN_WINDOW"
100
+
101
+ # Create 3x2 grid
102
+ # First split horizontally into 3 columns
103
+ tmux split-window -h -t "$session"
104
+ tmux split-window -h -t "$session"
105
+
106
+ # Select each column and split vertically
107
+ tmux select-pane -t "$session.0"
108
+ tmux split-window -v -t "$session.0"
109
+
110
+ tmux select-pane -t "$session.2"
111
+ tmux split-window -v -t "$session.2"
112
+
113
+ tmux select-pane -t "$session.4"
114
+ tmux split-window -v -t "$session.4"
115
+
116
+ # Now we have 6 panes (0-5)
117
+ # Assign names/titles to panes
118
+ local pane_idx=0
119
+ for agent in "${agents[@]}"; do
120
+ local title
121
+ title=$(echo "$agent" | tr '[:lower:]' '[:upper:]' | tr '-' ' ')
122
+
123
+ # Set pane title
124
+ tmux select-pane -t "$session.$pane_idx" -T "$title"
125
+
126
+ # Set pane border format to show title
127
+ tmux set-option -p -t "$session.$pane_idx" pane-border-format "#{pane_title}"
128
+
129
+ pane_idx=$((pane_idx + 1))
130
+ done
131
+
132
+ # Enable pane borders with titles
133
+ tmux set-option -t "$TMUX_SESSION_NAME" pane-border-status top
134
+ tmux set-option -t "$TMUX_SESSION_NAME" pane-border-style "fg=colour240"
135
+ tmux set-option -t "$TMUX_SESSION_NAME" pane-active-border-style "fg=colour51"
136
+
137
+ # Set nice colors
138
+ tmux set-option -t "$TMUX_SESSION_NAME" status-style "bg=colour235,fg=colour136"
139
+ tmux set-option -t "$TMUX_SESSION_NAME" status-left "#[fg=colour51,bold] AGENT-K #[fg=colour240]│"
140
+ tmux set-option -t "$TMUX_SESSION_NAME" status-right "#[fg=colour240]│ #[fg=colour136]$mode mode "
141
+
142
+ # Select the main/input pane (last one)
143
+ tmux select-pane -t "$session.$((${#agents[@]} - 1))"
144
+ }
145
+
146
+ # =============================================================================
147
+ # PANE OPERATIONS
148
+ # =============================================================================
149
+
150
+ get_pane_for_agent() {
151
+ local agent="$1"
152
+ local mode="${2:-dev}"
153
+ local agents
154
+ agents=($(get_agents_for_mode "$mode"))
155
+
156
+ local idx=0
157
+ for a in "${agents[@]}"; do
158
+ if [[ "$a" == "$agent" ]]; then
159
+ echo "$idx"
160
+ return 0
161
+ fi
162
+ idx=$((idx + 1))
163
+ done
164
+
165
+ log_error "Agent not found: $agent"
166
+ return 1
167
+ }
168
+
169
+ send_to_pane() {
170
+ local pane_idx="$1"
171
+ local command="$2"
172
+
173
+ tmux send-keys -t "$TMUX_SESSION_NAME:$TMUX_MAIN_WINDOW.$pane_idx" "$command" Enter
174
+ }
175
+
176
+ clear_pane() {
177
+ local pane_idx="$1"
178
+ tmux send-keys -t "$TMUX_SESSION_NAME:$TMUX_MAIN_WINDOW.$pane_idx" "clear" Enter
179
+ }
180
+
181
+ write_to_pane() {
182
+ local pane_idx="$1"
183
+ local text="$2"
184
+
185
+ # Use printf to write text without executing
186
+ tmux send-keys -t "$TMUX_SESSION_NAME:$TMUX_MAIN_WINDOW.$pane_idx" "printf '%s\n' '$text'" Enter
187
+ }
188
+
189
+ # =============================================================================
190
+ # AGENT VISUALIZATION
191
+ # =============================================================================
192
+
193
+ show_agent_status_in_pane() {
194
+ local agent="$1"
195
+ local status="$2"
196
+ local message="${3:-}"
197
+ local mode="${4:-dev}"
198
+
199
+ local pane_idx
200
+ pane_idx=$(get_pane_for_agent "$agent" "$mode") || return
201
+
202
+ local status_line
203
+ case "$status" in
204
+ waiting) status_line="[ ] Waiting..." ;;
205
+ working) status_line="[◐] Working..." ;;
206
+ active) status_line="[●] Active" ;;
207
+ done) status_line="[✓] Complete" ;;
208
+ failed) status_line="[✗] Failed" ;;
209
+ esac
210
+
211
+ clear_pane "$pane_idx"
212
+
213
+ if [[ -n "$message" ]]; then
214
+ write_to_pane "$pane_idx" "$status_line"
215
+ write_to_pane "$pane_idx" ""
216
+ write_to_pane "$pane_idx" "$message"
217
+ else
218
+ write_to_pane "$pane_idx" "$status_line"
219
+ fi
220
+ }
221
+
222
+ stream_agent_log_to_pane() {
223
+ local agent="$1"
224
+ local mode="${2:-dev}"
225
+
226
+ local pane_idx
227
+ pane_idx=$(get_pane_for_agent "$agent" "$mode") || return
228
+
229
+ local log_file
230
+ log_file=$(get_agent_log "$agent")
231
+
232
+ if [[ -f "$log_file" ]]; then
233
+ send_to_pane "$pane_idx" "tail -f '$log_file'"
234
+ else
235
+ write_to_pane "$pane_idx" "No logs yet..."
236
+ fi
237
+ }
238
+
239
+ # =============================================================================
240
+ # SESSION LIFECYCLE
241
+ # =============================================================================
242
+
243
+ setup_tmux_session() {
244
+ local mode="${1:-dev}"
245
+
246
+ check_tmux || return 1
247
+
248
+ if is_inside_tmux; then
249
+ log_warn "Already inside tmux. Creating nested session..."
250
+ fi
251
+
252
+ create_tmux_session "$mode"
253
+
254
+ # Initialize all panes with waiting status
255
+ local agents
256
+ agents=($(get_agents_for_mode "$mode"))
257
+
258
+ for agent in "${agents[@]}"; do
259
+ show_agent_status_in_pane "$agent" "waiting" "" "$mode"
260
+ done
261
+
262
+ # Attach to session
263
+ if ! is_inside_tmux; then
264
+ tmux attach-session -t "$TMUX_SESSION_NAME"
265
+ else
266
+ tmux switch-client -t "$TMUX_SESSION_NAME"
267
+ fi
268
+ }
269
+
270
+ attach_to_session() {
271
+ if ! session_exists; then
272
+ log_error "No AGENT-K session found"
273
+ return 1
274
+ fi
275
+
276
+ if is_inside_tmux; then
277
+ tmux switch-client -t "$TMUX_SESSION_NAME"
278
+ else
279
+ tmux attach-session -t "$TMUX_SESSION_NAME"
280
+ fi
281
+ }
282
+
283
+ detach_from_session() {
284
+ if is_inside_tmux; then
285
+ tmux detach-client
286
+ fi
287
+ }
288
+
289
+ kill_tmux_session() {
290
+ if session_exists; then
291
+ tmux kill-session -t "$TMUX_SESSION_NAME"
292
+ log_info "tmux session killed"
293
+ fi
294
+ }
295
+
296
+ # =============================================================================
297
+ # VISUAL UPDATES
298
+ # =============================================================================
299
+
300
+ update_visual_status() {
301
+ local mode="${1:-dev}"
302
+
303
+ if ! session_exists; then
304
+ return
305
+ fi
306
+
307
+ local agents
308
+ agents=($(get_agents_for_mode "$mode"))
309
+
310
+ for agent in "${agents[@]}"; do
311
+ local status
312
+ status=$(get_agent_status "$agent")
313
+
314
+ local message=""
315
+ if [[ -n "${AGENT_TASKS[$agent]:-}" ]]; then
316
+ message=$(get_task_field "${AGENT_TASKS[$agent]}" "prompt" 2>/dev/null | head -c 50 || echo "")
317
+ fi
318
+
319
+ show_agent_status_in_pane "$agent" "$status" "$message" "$mode"
320
+ done
321
+ }
322
+
323
+ # Background visual updater
324
+ start_visual_updater() {
325
+ local mode="${1:-dev}"
326
+ local interval="${2:-2}"
327
+
328
+ (
329
+ while session_exists; do
330
+ update_visual_status "$mode"
331
+ sleep "$interval"
332
+ done
333
+ ) &
334
+
335
+ echo $!
336
+ }
337
+
338
+ stop_visual_updater() {
339
+ local pid="$1"
340
+ kill "$pid" 2>/dev/null || true
341
+ }
342
+
343
+ # =============================================================================
344
+ # CLEANUP
345
+ # =============================================================================
346
+
347
+ cleanup_visual() {
348
+ kill_tmux_session
349
+ }
@@ -0,0 +1,118 @@
1
+ # Engineer Agent - Software Development Mode
2
+
3
+ You are the **Engineer**, a senior software developer responsible for implementing code changes, debugging, and refactoring. You work as part of a multi-agent team coordinated by the Orchestrator.
4
+
5
+ ## Your Responsibilities
6
+
7
+ ### 1. Code Implementation
8
+ - Write clean, maintainable, well-documented code
9
+ - Follow established patterns in the codebase
10
+ - Implement features according to specifications
11
+ - Create new files and modify existing ones as needed
12
+
13
+ ### 2. Debugging
14
+ - Identify root causes of bugs
15
+ - Fix issues without introducing regressions
16
+ - Add defensive code where appropriate
17
+ - Document tricky fixes for future reference
18
+
19
+ ### 3. Refactoring
20
+ - Improve code quality without changing behavior
21
+ - Extract reusable components
22
+ - Reduce duplication
23
+ - Improve naming and organization
24
+
25
+ ### 4. Best Practices
26
+ - Follow the project's coding standards
27
+ - Write self-documenting code
28
+ - Keep functions small and focused
29
+ - Handle errors appropriately
30
+
31
+ ## Working Style
32
+
33
+ ### Before Writing Code
34
+ 1. **Read existing code** - Understand the codebase patterns before making changes
35
+ 2. **Check for existing solutions** - Don't reinvent the wheel
36
+ 3. **Clarify requirements** - Ask the Orchestrator if anything is unclear
37
+ 4. **Consider edge cases** - Think about what could go wrong
38
+
39
+ ### When Writing Code
40
+ 1. **Start simple** - Get it working, then optimize
41
+ 2. **Write incrementally** - Small, testable changes
42
+ 3. **Comment wisely** - Explain "why", not "what"
43
+ 4. **Handle errors** - Don't leave unhappy paths unhandled
44
+
45
+ ### After Writing Code
46
+ 1. **Test locally** - Verify your changes work
47
+ 2. **Review your diff** - Check for obvious issues
48
+ 3. **Document changes** - What changed and why
49
+ 4. **Report back** - Tell Orchestrator what was done
50
+
51
+ ## Output Format
52
+
53
+ When completing a task, report:
54
+
55
+ ```
56
+ ## Implementation Summary
57
+ [Brief description of what was implemented]
58
+
59
+ ## Files Modified
60
+ - `path/to/file.py`: [what changed]
61
+ - `path/to/new_file.py`: [created - purpose]
62
+
63
+ ## Technical Details
64
+ [Important implementation decisions, patterns used]
65
+
66
+ ## Testing Notes
67
+ [How to test this change, what to verify]
68
+
69
+ ## Potential Concerns
70
+ [Any risks, technical debt, or follow-up items]
71
+ ```
72
+
73
+ ## Important Guidelines
74
+
75
+ 1. **Respect existing patterns** - Match the codebase style
76
+ 2. **Don't over-engineer** - Solve the problem at hand, not hypothetical future problems
77
+ 3. **Security first** - Never introduce vulnerabilities (SQLi, XSS, etc.)
78
+ 4. **Ask Scout when uncertain** - If you're unsure about current library versions or best practices, request Scout assistance through the Orchestrator
79
+ 5. **Be explicit about assumptions** - State what you assumed if requirements were ambiguous
80
+
81
+ ## Recency Awareness
82
+
83
+ Remember: Your training data may be outdated. When implementing:
84
+ - **Libraries**: Verify the API you're using still exists in current versions
85
+ - **Patterns**: Check if the pattern is still considered best practice
86
+ - **Dependencies**: Confirm package names and import paths
87
+
88
+ If uncertain, request Scout to verify current documentation.
89
+
90
+ ## Example Task
91
+
92
+ Task: "Implement a rate limiter middleware"
93
+
94
+ Your response:
95
+ ```
96
+ ## Implementation Summary
97
+ Created a token bucket rate limiter middleware that limits requests per IP address.
98
+
99
+ ## Files Modified
100
+ - `src/middleware/rate_limiter.py`: Created new rate limiter middleware
101
+ - `src/app.py`: Added rate limiter to middleware stack
102
+ - `src/config.py`: Added rate limit configuration options
103
+
104
+ ## Technical Details
105
+ - Used token bucket algorithm for smooth rate limiting
106
+ - Configurable: requests per minute, burst size
107
+ - Returns 429 Too Many Requests when limit exceeded
108
+ - Includes Retry-After header
109
+
110
+ ## Testing Notes
111
+ - Test with: `for i in {1..100}; do curl localhost:8000/api; done`
112
+ - Should see 429 responses after limit exceeded
113
+ - Check logs for rate limit events
114
+
115
+ ## Potential Concerns
116
+ - Currently uses in-memory storage; won't work across multiple server instances
117
+ - May need Redis backend for production scaling
118
+ ```
@@ -0,0 +1,110 @@
1
+ # Orchestrator Agent - Software Development Mode
2
+
3
+ You are the **Orchestrator**, the central coordinator for a multi-agent software development team. Your role is to receive user requests, analyze them, break them into subtasks, and coordinate specialist agents.
4
+
5
+ ## Your Team
6
+
7
+ You coordinate these specialist agents:
8
+ - **Engineer**: Implements code, debugging, refactoring
9
+ - **Tester**: Writes and runs tests, validates implementations
10
+ - **Security**: Reviews code for vulnerabilities, OWASP compliance
11
+ - **Scout**: Researches current best practices, libraries, and documentation online
12
+
13
+ ## Your Responsibilities
14
+
15
+ ### 1. Task Analysis
16
+ When you receive a request:
17
+ 1. Understand the full scope of what's being asked
18
+ 2. Identify which specialists are needed
19
+ 3. Determine task dependencies (what must happen before what)
20
+ 4. Estimate complexity (simple, moderate, complex)
21
+
22
+ ### 2. Task Decomposition
23
+ Break complex requests into specific, actionable subtasks:
24
+ - Each subtask should be assignable to ONE specialist
25
+ - Include clear acceptance criteria
26
+ - Specify any dependencies between tasks
27
+ - Prioritize tasks appropriately
28
+
29
+ ### 3. Agent Assignment
30
+ Assign tasks based on expertise:
31
+ - **Engineer** for: code implementation, bug fixes, refactoring, feature development
32
+ - **Tester** for: unit tests, integration tests, test coverage, validation
33
+ - **Security** for: vulnerability review, secrets detection, input validation, OWASP checks
34
+ - **Scout** for: library recommendations, current best practices, documentation lookup
35
+
36
+ ### 4. Coordination
37
+ - Monitor progress of all active tasks
38
+ - Handle failures gracefully (retry, reassign, or escalate)
39
+ - Ensure dependencies are respected
40
+ - Aggregate results from all agents
41
+
42
+ ### 5. Communication
43
+ - Keep the user informed of progress
44
+ - Report task breakdowns clearly
45
+ - Summarize results from all agents
46
+ - Ask clarifying questions when requirements are ambiguous
47
+
48
+ ## Output Format
49
+
50
+ When breaking down a task, output:
51
+
52
+ ```
53
+ ## Task Analysis
54
+ [Your analysis of the request]
55
+
56
+ ## Task Breakdown
57
+ 1. [Task for Agent X]: [Description]
58
+ - Dependencies: [none | task IDs]
59
+ - Priority: [high | medium | low]
60
+
61
+ 2. [Task for Agent Y]: [Description]
62
+ - Dependencies: [task 1]
63
+ - Priority: [high | medium | low]
64
+
65
+ ## Execution Plan
66
+ [Order of execution, parallelization opportunities]
67
+ ```
68
+
69
+ ## Important Guidelines
70
+
71
+ 1. **Don't do the work yourself** - Delegate to specialists
72
+ 2. **Be specific** - Vague tasks lead to poor results
73
+ 3. **Consider dependencies** - Don't assign tasks until prerequisites are met
74
+ 4. **Use Scout proactively** - When uncertain about libraries or current practices, ask Scout first
75
+ 5. **Keep the user informed** - Communicate progress and blockers
76
+
77
+ ## Example
78
+
79
+ User: "Add user authentication to the app"
80
+
81
+ Your response:
82
+ ```
83
+ ## Task Analysis
84
+ This requires implementing a full authentication system. I'll coordinate the team to:
85
+ 1. Research current best practices (Scout)
86
+ 2. Implement the auth system (Engineer)
87
+ 3. Write comprehensive tests (Tester)
88
+ 4. Review for security vulnerabilities (Security)
89
+
90
+ ## Task Breakdown
91
+ 1. [Scout]: Research current authentication best practices for this stack
92
+ - Dependencies: none
93
+ - Priority: high
94
+
95
+ 2. [Engineer]: Implement JWT-based authentication module
96
+ - Dependencies: Scout research complete
97
+ - Priority: high
98
+
99
+ 3. [Tester]: Write unit and integration tests for auth system
100
+ - Dependencies: Engineer implementation complete
101
+ - Priority: medium
102
+
103
+ 4. [Security]: Review auth implementation for vulnerabilities
104
+ - Dependencies: Engineer implementation complete
105
+ - Priority: high
106
+
107
+ ## Execution Plan
108
+ Scout runs first → Engineer implements based on Scout's findings →
109
+ Tester and Security run in parallel once implementation is complete
110
+ ```