claude-flow-novice 2.15.2 → 2.15.3
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/.claude/hooks/cfn-BACKUP_USAGE.md +243 -243
- package/.claude/hooks/cfn-invoke-security-validation.sh +69 -69
- package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
- package/.claude/hooks/cfn-post-edit.config.json +44 -44
- package/.claude/skills/agent-lifecycle/SKILL.md +60 -0
- package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
- package/.claude/skills/agent-lifecycle/simple-audit.sh +31 -0
- package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
- package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
- package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
- package/.claude/skills/cfn-redis-coordination/get-context.sh +112 -112
- package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
- package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
- package/.claude/skills/cfn-transparency-middleware/test-integration.sh +161 -161
- package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
- package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
- package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
- package/claude-assets/hooks/cfn-BACKUP_USAGE.md +243 -243
- package/claude-assets/hooks/cfn-invoke-security-validation.sh +69 -69
- package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
- package/claude-assets/hooks/cfn-post-edit.config.json +44 -44
- package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +19 -19
- package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +19 -19
- package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +572 -572
- package/claude-assets/skills/agent-lifecycle/simple-audit.sh +30 -30
- package/claude-assets/skills/cfn-automatic-memory-persistence/persist-agent-output.sh +48 -48
- package/claude-assets/skills/cfn-automatic-memory-persistence/query-agent-history.sh +34 -34
- package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +261 -261
- package/claude-assets/skills/cfn-expert-update/update-expert.sh +345 -345
- package/claude-assets/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
- package/claude-assets/skills/cfn-intervention-detector/detect-intervention.sh +110 -110
- package/claude-assets/skills/cfn-intervention-orchestrator/execute-intervention.sh +58 -58
- package/claude-assets/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
- package/claude-assets/skills/cfn-loop2-output-processing/process-validator-output.sh +275 -275
- package/claude-assets/skills/cfn-memory-management/check-memory.sh +159 -159
- package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +196 -196
- package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +325 -325
- package/claude-assets/skills/cfn-playbook-auto-update/auto-update-playbook.sh +85 -85
- package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
- package/claude-assets/skills/cfn-redis-coordination/get-context.sh +112 -112
- package/claude-assets/skills/cfn-scope-simplifier/simplify-scope.sh +67 -67
- package/claude-assets/skills/cfn-specialist-injection/recommend-specialist.sh +56 -56
- package/claude-assets/skills/cfn-standardized-error-handling/capture-agent-error.sh +86 -86
- package/claude-assets/skills/cfn-standardized-error-handling/test-error-handling.sh +165 -165
- package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +264 -264
- package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +278 -278
- package/claude-assets/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
- package/claude-assets/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
- package/claude-assets/skills/cfn-transparency-middleware/test-integration.sh +161 -161
- package/claude-assets/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
- package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
- package/claude-assets/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
- package/claude-assets/skills/docker-build/SKILL.md +96 -203
- package/claude-assets/skills/docker-build/build.sh +73 -73
- package/claude-assets/skills/integration/agent-handoff.sh +494 -0
- package/claude-assets/skills/integration/file-operations.sh +414 -0
- package/claude-assets/skills/workflow-codification/APPROVAL_WORKFLOW.md +806 -0
- package/claude-assets/skills/workflow-codification/COST_TRACKING.md +637 -0
- package/claude-assets/skills/workflow-codification/EDGE_CASE_TRACKING.md +404 -0
- package/claude-assets/skills/workflow-codification/README_PHASE4.md +457 -0
- package/claude-assets/skills/workflow-codification/SKILL.md +110 -0
- package/claude-assets/skills/workflow-codification/analyze-patterns.sh +899 -0
- package/claude-assets/skills/workflow-codification/approval-workflow.sh +514 -0
- package/claude-assets/skills/workflow-codification/generate-skill-update.sh +525 -0
- package/claude-assets/skills/workflow-codification/review-skill.sh +643 -0
- package/claude-assets/skills/workflow-codification/templates/email-notification.txt +114 -0
- package/claude-assets/skills/workflow-codification/templates/slack-notification.md +85 -0
- package/claude-assets/skills/workflow-codification/test-integration.sh +281 -0
- package/claude-assets/skills/workflow-codification/track-cost-savings.sh +445 -0
- package/claude-assets/skills/workflow-codification/track-edge-case.sh +323 -0
- package/dist/cli/config-manager.js +91 -109
- package/dist/cli/config-manager.js.map +1 -1
- package/dist/integration/DatabaseHandoff.js +507 -0
- package/dist/integration/DatabaseHandoff.js.map +1 -0
- package/dist/integration/StandardAdapter.js +291 -0
- package/dist/integration/StandardAdapter.js.map +1 -0
- package/dist/lib/agent-output-parser.js +518 -0
- package/dist/lib/agent-output-parser.js.map +1 -0
- package/dist/lib/agent-output-validator.js +950 -0
- package/dist/lib/agent-output-validator.js.map +1 -0
- package/dist/lib/artifact-registry.js +443 -0
- package/dist/lib/artifact-registry.js.map +1 -0
- package/dist/lib/config-validator.js +687 -0
- package/dist/lib/config-validator.js.map +1 -0
- package/dist/types/agent-output.js +44 -0
- package/dist/types/agent-output.js.map +1 -0
- package/dist/types/config.js +28 -0
- package/dist/types/config.js.map +1 -0
- package/package.json +2 -1
- package/scripts/artifact-cleanup.sh +392 -0
- package/scripts/deploy-production.sh +355 -355
- package/scripts/docker-playwright-fix.sh +311 -311
- package/scripts/docker-rebuild-all-agents.sh +127 -127
- package/scripts/memory-leak-prevention.sh +305 -305
- package/scripts/migrate-artifacts.sh +563 -0
- package/scripts/migrate-yaml-to-json.sh +465 -0
- package/scripts/run-marketing-tests.sh +42 -42
- package/scripts/update_paths.sh +46 -46
|
@@ -1,573 +1,573 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Agent Lifecycle Hook Execution Script
|
|
4
|
-
# Provides SQLite-based lifecycle management for agent auditing
|
|
5
|
-
# Usage: ./execute-lifecycle-hook.sh <action> [options]
|
|
6
|
-
|
|
7
|
-
set -euo pipefail
|
|
8
|
-
|
|
9
|
-
# Configuration
|
|
10
|
-
DB_PATH="${AGENT_LIFECYCLE_DB:-./agent-lifecycle.db}"
|
|
11
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
12
|
-
|
|
13
|
-
# Colors for output
|
|
14
|
-
RED='\033[0;31m'
|
|
15
|
-
GREEN='\033[0;32m'
|
|
16
|
-
YELLOW='\033[1;33m'
|
|
17
|
-
BLUE='\033[0;34m'
|
|
18
|
-
NC='\033[0m' # No Color
|
|
19
|
-
|
|
20
|
-
# Logging functions
|
|
21
|
-
log_info() {
|
|
22
|
-
echo -e "${BLUE}[INFO]${NC} $1"
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
log_success() {
|
|
26
|
-
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
log_warning() {
|
|
30
|
-
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
log_error() {
|
|
34
|
-
echo -e "${RED}[ERROR]${NC} $1"
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
# Initialize SQLite database
|
|
38
|
-
init_database() {
|
|
39
|
-
if [[ ! -f "$DB_PATH" ]]; then
|
|
40
|
-
log_info "Creating agent lifecycle database: $DB_PATH"
|
|
41
|
-
sqlite3 "$DB_PATH" << 'EOF'
|
|
42
|
-
-- Create agents table
|
|
43
|
-
CREATE TABLE IF NOT EXISTS agents (
|
|
44
|
-
id TEXT PRIMARY KEY,
|
|
45
|
-
name TEXT NOT NULL,
|
|
46
|
-
type TEXT NOT NULL,
|
|
47
|
-
status TEXT NOT NULL DEFAULT 'spawned',
|
|
48
|
-
confidence REAL,
|
|
49
|
-
output TEXT,
|
|
50
|
-
metadata TEXT,
|
|
51
|
-
spawned_at TEXT NOT NULL,
|
|
52
|
-
completed_at TEXT,
|
|
53
|
-
updated_at TEXT NOT NULL
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
-- Create lifecycle_events table
|
|
57
|
-
CREATE TABLE IF NOT EXISTS lifecycle_events (
|
|
58
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
59
|
-
agent_id TEXT NOT NULL,
|
|
60
|
-
event_type TEXT NOT NULL,
|
|
61
|
-
confidence REAL,
|
|
62
|
-
reasoning TEXT,
|
|
63
|
-
phase TEXT,
|
|
64
|
-
iteration INTEGER,
|
|
65
|
-
timestamp TEXT NOT NULL,
|
|
66
|
-
FOREIGN KEY (agent_id) REFERENCES agents(id)
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
-- Create indexes for performance
|
|
70
|
-
CREATE INDEX IF NOT EXISTS idx_agents_status ON agents(status);
|
|
71
|
-
CREATE INDEX IF NOT EXISTS idx_agents_type ON agents(type);
|
|
72
|
-
CREATE INDEX IF NOT EXISTS idx_lifecycle_agent_id ON lifecycle_events(agent_id);
|
|
73
|
-
CREATE INDEX IF NOT EXISTS idx_lifecycle_timestamp ON lifecycle_events(timestamp);
|
|
74
|
-
CREATE INDEX IF NOT EXISTS idx_lifecycle_event_type ON lifecycle_events(event_type);
|
|
75
|
-
EOF
|
|
76
|
-
log_success "Database initialized successfully"
|
|
77
|
-
fi
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
# Validate agent ID format
|
|
81
|
-
validate_agent_id() {
|
|
82
|
-
local agent_id="$1"
|
|
83
|
-
if [[ ! "$agent_id" =~ ^[a-zA-Z0-9_-]+$ ]]; then
|
|
84
|
-
log_error "Invalid agent ID format: $agent_id"
|
|
85
|
-
log_error "Agent ID must contain only alphanumeric characters, hyphens, and underscores"
|
|
86
|
-
exit 1
|
|
87
|
-
fi
|
|
88
|
-
|
|
89
|
-
if [[ ${#agent_id} -lt 3 || ${#agent_id} -gt 64 ]]; then
|
|
90
|
-
log_error "Agent ID must be between 3 and 64 characters: $agent_id"
|
|
91
|
-
exit 1
|
|
92
|
-
fi
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
# Validate confidence score
|
|
96
|
-
validate_confidence() {
|
|
97
|
-
local confidence="$1"
|
|
98
|
-
if [[ ! "$confidence" =~ ^0\.[0-9]+$|^1\.0$|^0$|^1$ ]]; then
|
|
99
|
-
log_error "Invalid confidence score: $confidence"
|
|
100
|
-
log_error "Confidence must be between 0.0 and 1.0"
|
|
101
|
-
exit 1
|
|
102
|
-
fi
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
# Spawn agent registration
|
|
106
|
-
spawn_agent() {
|
|
107
|
-
local agent_id="$1"
|
|
108
|
-
local agent_type="$2"
|
|
109
|
-
local acl_level="${3:-1}"
|
|
110
|
-
local agent_name="${4:-$agent_id}"
|
|
111
|
-
|
|
112
|
-
validate_agent_id "$agent_id"
|
|
113
|
-
|
|
114
|
-
if [[ ! "$acl_level" =~ ^[1-6]$ ]]; then
|
|
115
|
-
log_error "Invalid ACL level: $acl_level (must be 1-6)"
|
|
116
|
-
exit 1
|
|
117
|
-
fi
|
|
118
|
-
|
|
119
|
-
log_info "Registering agent spawn: $agent_id (type: $agent_type, ACL: $acl_level)"
|
|
120
|
-
|
|
121
|
-
sqlite3 "$DB_PATH" << EOF
|
|
122
|
-
INSERT OR REPLACE INTO agents (
|
|
123
|
-
id, name, type, status, metadata, spawned_at, updated_at
|
|
124
|
-
) VALUES (
|
|
125
|
-
'$agent_id',
|
|
126
|
-
'$agent_name',
|
|
127
|
-
'$agent_type',
|
|
128
|
-
'spawned',
|
|
129
|
-
'{"aclLevel": $acl_level, "spawnedAt": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"}',
|
|
130
|
-
datetime('now'),
|
|
131
|
-
datetime('now')
|
|
132
|
-
);
|
|
133
|
-
EOF
|
|
134
|
-
|
|
135
|
-
# Log spawn event
|
|
136
|
-
sqlite3 "$DB_PATH" << EOF
|
|
137
|
-
INSERT INTO lifecycle_events (
|
|
138
|
-
agent_id, event_type, reasoning, timestamp
|
|
139
|
-
) VALUES (
|
|
140
|
-
'$agent_id',
|
|
141
|
-
'spawn',
|
|
142
|
-
'Agent spawned via lifecycle hook',
|
|
143
|
-
datetime('now')
|
|
144
|
-
);
|
|
145
|
-
EOF
|
|
146
|
-
|
|
147
|
-
log_success "Agent $agent_id registered successfully"
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
# Update agent confidence
|
|
151
|
-
update_confidence() {
|
|
152
|
-
local agent_id="$1"
|
|
153
|
-
local confidence="$2"
|
|
154
|
-
local reasoning="${3:-No reasoning provided}"
|
|
155
|
-
local phase="${4:-}"
|
|
156
|
-
local iteration="${5:-}"
|
|
157
|
-
|
|
158
|
-
validate_agent_id "$agent_id"
|
|
159
|
-
validate_confidence "$confidence"
|
|
160
|
-
|
|
161
|
-
log_info "Updating confidence for agent $agent_id: $confidence"
|
|
162
|
-
|
|
163
|
-
# Update agent confidence
|
|
164
|
-
sqlite3 "$DB_PATH" << EOF
|
|
165
|
-
UPDATE agents
|
|
166
|
-
SET confidence = $confidence, updated_at = datetime('now')
|
|
167
|
-
WHERE id = '$agent_id';
|
|
168
|
-
EOF
|
|
169
|
-
|
|
170
|
-
# Log confidence update event
|
|
171
|
-
sqlite3 "$DB_PATH" << EOF
|
|
172
|
-
INSERT INTO lifecycle_events (
|
|
173
|
-
agent_id, event_type, confidence, reasoning, phase, iteration, timestamp
|
|
174
|
-
) VALUES (
|
|
175
|
-
'$agent_id',
|
|
176
|
-
'confidence_update',
|
|
177
|
-
$confidence,
|
|
178
|
-
'$reasoning',
|
|
179
|
-
${phase:+"'${phase}'":NULL},
|
|
180
|
-
${iteration:+$iteration},
|
|
181
|
-
datetime('now')
|
|
182
|
-
);
|
|
183
|
-
EOF
|
|
184
|
-
|
|
185
|
-
log_success "Confidence updated for agent $agent_id"
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
# Complete agent
|
|
189
|
-
complete_agent() {
|
|
190
|
-
local agent_id="$1"
|
|
191
|
-
local confidence="$2"
|
|
192
|
-
local output="${3:-}"
|
|
193
|
-
local phase="${4:-}"
|
|
194
|
-
local iteration="${5:-}"
|
|
195
|
-
|
|
196
|
-
validate_agent_id "$agent_id"
|
|
197
|
-
validate_confidence "$confidence"
|
|
198
|
-
|
|
199
|
-
log_info "Completing agent $agent_id with confidence: $confidence"
|
|
200
|
-
|
|
201
|
-
# Mark agent as completed
|
|
202
|
-
sqlite3 "$DB_PATH" << EOF
|
|
203
|
-
UPDATE agents
|
|
204
|
-
SET status = 'completed',
|
|
205
|
-
confidence = $confidence,
|
|
206
|
-
output = ${output:+"'${output}'":NULL},
|
|
207
|
-
completed_at = datetime('now'),
|
|
208
|
-
updated_at = datetime('now')
|
|
209
|
-
WHERE id = '$agent_id';
|
|
210
|
-
EOF
|
|
211
|
-
|
|
212
|
-
# Log completion event
|
|
213
|
-
sqlite3 "$DB_PATH" << EOF
|
|
214
|
-
INSERT INTO lifecycle_events (
|
|
215
|
-
agent_id, event_type, confidence, reasoning, phase, iteration, timestamp
|
|
216
|
-
) VALUES (
|
|
217
|
-
'$agent_id',
|
|
218
|
-
'complete',
|
|
219
|
-
$confidence,
|
|
220
|
-
${output:="'${output}'":'Agent completed'},
|
|
221
|
-
${phase:+"'${phase}'":NULL},
|
|
222
|
-
${iteration:+$iteration},
|
|
223
|
-
datetime('now')
|
|
224
|
-
);
|
|
225
|
-
EOF
|
|
226
|
-
|
|
227
|
-
# Check CFN Loop gate
|
|
228
|
-
local gate_status="FAIL"
|
|
229
|
-
if (( $(echo "$confidence >= 0.75" | bc -l) )); then
|
|
230
|
-
gate_status="PASS"
|
|
231
|
-
fi
|
|
232
|
-
|
|
233
|
-
log_success "Agent $agent_id completed (CFN Loop 3 Gate: $gate_status)"
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
# Terminate agent
|
|
237
|
-
terminate_agent() {
|
|
238
|
-
local agent_id="$1"
|
|
239
|
-
local reason="${2:-Normal termination}"
|
|
240
|
-
|
|
241
|
-
validate_agent_id "$agent_id"
|
|
242
|
-
|
|
243
|
-
log_info "Terminating agent $agent_id: $reason"
|
|
244
|
-
|
|
245
|
-
# Mark agent as terminated
|
|
246
|
-
sqlite3 "$DB_PATH" << EOF
|
|
247
|
-
UPDATE agents
|
|
248
|
-
SET status = 'terminated', updated_at = datetime('now')
|
|
249
|
-
WHERE id = '$agent_id';
|
|
250
|
-
EOF
|
|
251
|
-
|
|
252
|
-
# Log termination event
|
|
253
|
-
sqlite3 "$DB_PATH" << EOF
|
|
254
|
-
INSERT INTO lifecycle_events (
|
|
255
|
-
agent_id, event_type, reasoning, timestamp
|
|
256
|
-
) VALUES (
|
|
257
|
-
'$agent_id',
|
|
258
|
-
'terminate',
|
|
259
|
-
'$reason',
|
|
260
|
-
datetime('now')
|
|
261
|
-
);
|
|
262
|
-
EOF
|
|
263
|
-
|
|
264
|
-
log_success "Agent $agent_id terminated"
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
# Query agent status
|
|
268
|
-
query_status() {
|
|
269
|
-
local agent_id="$1"
|
|
270
|
-
local limit="${2:-10}"
|
|
271
|
-
|
|
272
|
-
validate_agent_id "$agent_id"
|
|
273
|
-
|
|
274
|
-
log_info "Querying status for agent $agent_id"
|
|
275
|
-
|
|
276
|
-
echo ""
|
|
277
|
-
echo "=== Agent Status ==="
|
|
278
|
-
sqlite3 "$DB_PATH" << EOF
|
|
279
|
-
SELECT
|
|
280
|
-
id,
|
|
281
|
-
name,
|
|
282
|
-
type,
|
|
283
|
-
status,
|
|
284
|
-
confidence,
|
|
285
|
-
spawned_at,
|
|
286
|
-
completed_at,
|
|
287
|
-
updated_at
|
|
288
|
-
FROM agents
|
|
289
|
-
WHERE id = '$agent_id';
|
|
290
|
-
EOF
|
|
291
|
-
|
|
292
|
-
echo ""
|
|
293
|
-
echo "=== Recent Lifecycle Events ==="
|
|
294
|
-
sqlite3 "$DB_PATH" << EOF
|
|
295
|
-
SELECT
|
|
296
|
-
timestamp,
|
|
297
|
-
event_type,
|
|
298
|
-
confidence,
|
|
299
|
-
reasoning
|
|
300
|
-
FROM lifecycle_events
|
|
301
|
-
WHERE agent_id = '$agent_id'
|
|
302
|
-
ORDER BY timestamp DESC
|
|
303
|
-
LIMIT $limit;
|
|
304
|
-
EOF
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
# Show usage
|
|
308
|
-
show_usage() {
|
|
309
|
-
echo "Agent Lifecycle Hook Execution Script"
|
|
310
|
-
echo ""
|
|
311
|
-
echo "Usage: $0 <action> [options]"
|
|
312
|
-
echo ""
|
|
313
|
-
echo "Actions:"
|
|
314
|
-
echo " spawn --agent-id <id> --agent-type <type> [--acl-level <level>] [--name <name>]"
|
|
315
|
-
echo " update --agent-id <id> --confidence <score> --reasoning <text> [--phase <phase>] [--iteration <n>]"
|
|
316
|
-
echo " complete --agent-id <id> --confidence <score> [--output <text>] [--phase <phase>] [--iteration <n>]"
|
|
317
|
-
echo " terminate --agent-id <id> [--reason <text>]"
|
|
318
|
-
echo " status --agent-id <id> [--limit <n>]"
|
|
319
|
-
echo ""
|
|
320
|
-
echo "Environment Variables:"
|
|
321
|
-
echo " AGENT_LIFECYCLE_DB Path to SQLite database (default: ./agent-lifecycle.db)"
|
|
322
|
-
echo ""
|
|
323
|
-
echo "Examples:"
|
|
324
|
-
echo " $0 spawn --agent-id docker-1 --agent-type docker-specialist --acl-level 1"
|
|
325
|
-
echo " $0 update --agent-id docker-1 --confidence 0.85 --reasoning 'Implementation complete'"
|
|
326
|
-
echo " $0 complete --agent-id docker-1 --confidence 0.90 --output 'Docker setup complete'"
|
|
327
|
-
echo " $0 status --agent-id docker-1"
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
# Parse command line arguments
|
|
331
|
-
parse_args() {
|
|
332
|
-
local action="$1"
|
|
333
|
-
shift
|
|
334
|
-
|
|
335
|
-
case "$action" in
|
|
336
|
-
"spawn")
|
|
337
|
-
local agent_id=""
|
|
338
|
-
local agent_type=""
|
|
339
|
-
local acl_level="1"
|
|
340
|
-
local agent_name=""
|
|
341
|
-
|
|
342
|
-
while [[ $# -gt 0 ]]; do
|
|
343
|
-
case "$1" in
|
|
344
|
-
--agent-id)
|
|
345
|
-
agent_id="$2"
|
|
346
|
-
shift 2
|
|
347
|
-
;;
|
|
348
|
-
--agent-type)
|
|
349
|
-
agent_type="$2"
|
|
350
|
-
shift 2
|
|
351
|
-
;;
|
|
352
|
-
--acl-level)
|
|
353
|
-
acl_level="$2"
|
|
354
|
-
shift 2
|
|
355
|
-
;;
|
|
356
|
-
--name)
|
|
357
|
-
agent_name="$2"
|
|
358
|
-
shift 2
|
|
359
|
-
;;
|
|
360
|
-
*)
|
|
361
|
-
log_error "Unknown option: $1"
|
|
362
|
-
show_usage
|
|
363
|
-
exit 1
|
|
364
|
-
;;
|
|
365
|
-
esac
|
|
366
|
-
done
|
|
367
|
-
|
|
368
|
-
if [[ -z "$agent_id" || -z "$agent_type" ]]; then
|
|
369
|
-
log_error "Missing required arguments for spawn"
|
|
370
|
-
show_usage
|
|
371
|
-
exit 1
|
|
372
|
-
fi
|
|
373
|
-
|
|
374
|
-
init_database
|
|
375
|
-
spawn_agent "$agent_id" "$agent_type" "$acl_level" "$agent_name"
|
|
376
|
-
;;
|
|
377
|
-
|
|
378
|
-
"update")
|
|
379
|
-
local agent_id=""
|
|
380
|
-
local confidence=""
|
|
381
|
-
local reasoning=""
|
|
382
|
-
local phase=""
|
|
383
|
-
local iteration=""
|
|
384
|
-
|
|
385
|
-
while [[ $# -gt 0 ]]; do
|
|
386
|
-
case "$1" in
|
|
387
|
-
--agent-id)
|
|
388
|
-
agent_id="$2"
|
|
389
|
-
shift 2
|
|
390
|
-
;;
|
|
391
|
-
--confidence)
|
|
392
|
-
confidence="$2"
|
|
393
|
-
shift 2
|
|
394
|
-
;;
|
|
395
|
-
--reasoning)
|
|
396
|
-
reasoning="$2"
|
|
397
|
-
shift 2
|
|
398
|
-
;;
|
|
399
|
-
--phase)
|
|
400
|
-
phase="$2"
|
|
401
|
-
shift 2
|
|
402
|
-
;;
|
|
403
|
-
--iteration)
|
|
404
|
-
iteration="$2"
|
|
405
|
-
shift 2
|
|
406
|
-
;;
|
|
407
|
-
*)
|
|
408
|
-
log_error "Unknown option: $1"
|
|
409
|
-
show_usage
|
|
410
|
-
exit 1
|
|
411
|
-
;;
|
|
412
|
-
esac
|
|
413
|
-
done
|
|
414
|
-
|
|
415
|
-
if [[ -z "$agent_id" || -z "$confidence" ]]; then
|
|
416
|
-
log_error "Missing required arguments for update"
|
|
417
|
-
show_usage
|
|
418
|
-
exit 1
|
|
419
|
-
fi
|
|
420
|
-
|
|
421
|
-
init_database
|
|
422
|
-
update_confidence "$agent_id" "$confidence" "$reasoning" "$phase" "$iteration"
|
|
423
|
-
;;
|
|
424
|
-
|
|
425
|
-
"complete")
|
|
426
|
-
local agent_id=""
|
|
427
|
-
local confidence=""
|
|
428
|
-
local output=""
|
|
429
|
-
local phase=""
|
|
430
|
-
local iteration=""
|
|
431
|
-
|
|
432
|
-
while [[ $# -gt 0 ]]; do
|
|
433
|
-
case "$1" in
|
|
434
|
-
--agent-id)
|
|
435
|
-
agent_id="$2"
|
|
436
|
-
shift 2
|
|
437
|
-
;;
|
|
438
|
-
--confidence)
|
|
439
|
-
confidence="$2"
|
|
440
|
-
shift 2
|
|
441
|
-
;;
|
|
442
|
-
--output)
|
|
443
|
-
output="$2"
|
|
444
|
-
shift 2
|
|
445
|
-
;;
|
|
446
|
-
--phase)
|
|
447
|
-
phase="$2"
|
|
448
|
-
shift 2
|
|
449
|
-
;;
|
|
450
|
-
--iteration)
|
|
451
|
-
iteration="$2"
|
|
452
|
-
shift 2
|
|
453
|
-
;;
|
|
454
|
-
*)
|
|
455
|
-
log_error "Unknown option: $1"
|
|
456
|
-
show_usage
|
|
457
|
-
exit 1
|
|
458
|
-
;;
|
|
459
|
-
esac
|
|
460
|
-
done
|
|
461
|
-
|
|
462
|
-
if [[ -z "$agent_id" || -z "$confidence" ]]; then
|
|
463
|
-
log_error "Missing required arguments for complete"
|
|
464
|
-
show_usage
|
|
465
|
-
exit 1
|
|
466
|
-
fi
|
|
467
|
-
|
|
468
|
-
init_database
|
|
469
|
-
complete_agent "$agent_id" "$confidence" "$output" "$phase" "$iteration"
|
|
470
|
-
;;
|
|
471
|
-
|
|
472
|
-
"terminate")
|
|
473
|
-
local agent_id=""
|
|
474
|
-
local reason=""
|
|
475
|
-
|
|
476
|
-
while [[ $# -gt 0 ]]; do
|
|
477
|
-
case "$1" in
|
|
478
|
-
--agent-id)
|
|
479
|
-
agent_id="$2"
|
|
480
|
-
shift 2
|
|
481
|
-
;;
|
|
482
|
-
--reason)
|
|
483
|
-
reason="$2"
|
|
484
|
-
shift 2
|
|
485
|
-
;;
|
|
486
|
-
*)
|
|
487
|
-
log_error "Unknown option: $1"
|
|
488
|
-
show_usage
|
|
489
|
-
exit 1
|
|
490
|
-
;;
|
|
491
|
-
esac
|
|
492
|
-
done
|
|
493
|
-
|
|
494
|
-
if [[ -z "$agent_id" ]]; then
|
|
495
|
-
log_error "Missing required arguments for terminate"
|
|
496
|
-
show_usage
|
|
497
|
-
exit 1
|
|
498
|
-
fi
|
|
499
|
-
|
|
500
|
-
init_database
|
|
501
|
-
terminate_agent "$agent_id" "$reason"
|
|
502
|
-
;;
|
|
503
|
-
|
|
504
|
-
"status")
|
|
505
|
-
local agent_id=""
|
|
506
|
-
local limit="10"
|
|
507
|
-
|
|
508
|
-
while [[ $# -gt 0 ]]; do
|
|
509
|
-
case "$1" in
|
|
510
|
-
--agent-id)
|
|
511
|
-
agent_id="$2"
|
|
512
|
-
shift 2
|
|
513
|
-
;;
|
|
514
|
-
--limit)
|
|
515
|
-
limit="$2"
|
|
516
|
-
shift 2
|
|
517
|
-
;;
|
|
518
|
-
*)
|
|
519
|
-
log_error "Unknown option: $1"
|
|
520
|
-
show_usage
|
|
521
|
-
exit 1
|
|
522
|
-
;;
|
|
523
|
-
esac
|
|
524
|
-
done
|
|
525
|
-
|
|
526
|
-
if [[ -z "$agent_id" ]]; then
|
|
527
|
-
log_error "Missing required arguments for status"
|
|
528
|
-
show_usage
|
|
529
|
-
exit 1
|
|
530
|
-
fi
|
|
531
|
-
|
|
532
|
-
init_database
|
|
533
|
-
query_status "$agent_id" "$limit"
|
|
534
|
-
;;
|
|
535
|
-
|
|
536
|
-
"help"|"--help"|"-h")
|
|
537
|
-
show_usage
|
|
538
|
-
;;
|
|
539
|
-
|
|
540
|
-
*)
|
|
541
|
-
log_error "Unknown action: $action"
|
|
542
|
-
show_usage
|
|
543
|
-
exit 1
|
|
544
|
-
;;
|
|
545
|
-
esac
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
# Check for required dependencies
|
|
549
|
-
check_dependencies() {
|
|
550
|
-
if ! command -v sqlite3 &> /dev/null; then
|
|
551
|
-
log_error "sqlite3 is required but not installed"
|
|
552
|
-
exit 1
|
|
553
|
-
fi
|
|
554
|
-
|
|
555
|
-
if ! command -v bc &> /dev/null; then
|
|
556
|
-
log_warning "bc is recommended for confidence calculations"
|
|
557
|
-
fi
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
# Main execution
|
|
561
|
-
main() {
|
|
562
|
-
check_dependencies
|
|
563
|
-
|
|
564
|
-
if [[ $# -eq 0 ]]; then
|
|
565
|
-
show_usage
|
|
566
|
-
exit 1
|
|
567
|
-
fi
|
|
568
|
-
|
|
569
|
-
parse_args "$@"
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
# Execute main function
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Agent Lifecycle Hook Execution Script
|
|
4
|
+
# Provides SQLite-based lifecycle management for agent auditing
|
|
5
|
+
# Usage: ./execute-lifecycle-hook.sh <action> [options]
|
|
6
|
+
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
|
|
9
|
+
# Configuration
|
|
10
|
+
DB_PATH="${AGENT_LIFECYCLE_DB:-./agent-lifecycle.db}"
|
|
11
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
12
|
+
|
|
13
|
+
# Colors for output
|
|
14
|
+
RED='\033[0;31m'
|
|
15
|
+
GREEN='\033[0;32m'
|
|
16
|
+
YELLOW='\033[1;33m'
|
|
17
|
+
BLUE='\033[0;34m'
|
|
18
|
+
NC='\033[0m' # No Color
|
|
19
|
+
|
|
20
|
+
# Logging functions
|
|
21
|
+
log_info() {
|
|
22
|
+
echo -e "${BLUE}[INFO]${NC} $1"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
log_success() {
|
|
26
|
+
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
log_warning() {
|
|
30
|
+
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
log_error() {
|
|
34
|
+
echo -e "${RED}[ERROR]${NC} $1"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Initialize SQLite database
|
|
38
|
+
init_database() {
|
|
39
|
+
if [[ ! -f "$DB_PATH" ]]; then
|
|
40
|
+
log_info "Creating agent lifecycle database: $DB_PATH"
|
|
41
|
+
sqlite3 "$DB_PATH" << 'EOF'
|
|
42
|
+
-- Create agents table
|
|
43
|
+
CREATE TABLE IF NOT EXISTS agents (
|
|
44
|
+
id TEXT PRIMARY KEY,
|
|
45
|
+
name TEXT NOT NULL,
|
|
46
|
+
type TEXT NOT NULL,
|
|
47
|
+
status TEXT NOT NULL DEFAULT 'spawned',
|
|
48
|
+
confidence REAL,
|
|
49
|
+
output TEXT,
|
|
50
|
+
metadata TEXT,
|
|
51
|
+
spawned_at TEXT NOT NULL,
|
|
52
|
+
completed_at TEXT,
|
|
53
|
+
updated_at TEXT NOT NULL
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
-- Create lifecycle_events table
|
|
57
|
+
CREATE TABLE IF NOT EXISTS lifecycle_events (
|
|
58
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
59
|
+
agent_id TEXT NOT NULL,
|
|
60
|
+
event_type TEXT NOT NULL,
|
|
61
|
+
confidence REAL,
|
|
62
|
+
reasoning TEXT,
|
|
63
|
+
phase TEXT,
|
|
64
|
+
iteration INTEGER,
|
|
65
|
+
timestamp TEXT NOT NULL,
|
|
66
|
+
FOREIGN KEY (agent_id) REFERENCES agents(id)
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
-- Create indexes for performance
|
|
70
|
+
CREATE INDEX IF NOT EXISTS idx_agents_status ON agents(status);
|
|
71
|
+
CREATE INDEX IF NOT EXISTS idx_agents_type ON agents(type);
|
|
72
|
+
CREATE INDEX IF NOT EXISTS idx_lifecycle_agent_id ON lifecycle_events(agent_id);
|
|
73
|
+
CREATE INDEX IF NOT EXISTS idx_lifecycle_timestamp ON lifecycle_events(timestamp);
|
|
74
|
+
CREATE INDEX IF NOT EXISTS idx_lifecycle_event_type ON lifecycle_events(event_type);
|
|
75
|
+
EOF
|
|
76
|
+
log_success "Database initialized successfully"
|
|
77
|
+
fi
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# Validate agent ID format
|
|
81
|
+
validate_agent_id() {
|
|
82
|
+
local agent_id="$1"
|
|
83
|
+
if [[ ! "$agent_id" =~ ^[a-zA-Z0-9_-]+$ ]]; then
|
|
84
|
+
log_error "Invalid agent ID format: $agent_id"
|
|
85
|
+
log_error "Agent ID must contain only alphanumeric characters, hyphens, and underscores"
|
|
86
|
+
exit 1
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
if [[ ${#agent_id} -lt 3 || ${#agent_id} -gt 64 ]]; then
|
|
90
|
+
log_error "Agent ID must be between 3 and 64 characters: $agent_id"
|
|
91
|
+
exit 1
|
|
92
|
+
fi
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
# Validate confidence score
|
|
96
|
+
validate_confidence() {
|
|
97
|
+
local confidence="$1"
|
|
98
|
+
if [[ ! "$confidence" =~ ^0\.[0-9]+$|^1\.0$|^0$|^1$ ]]; then
|
|
99
|
+
log_error "Invalid confidence score: $confidence"
|
|
100
|
+
log_error "Confidence must be between 0.0 and 1.0"
|
|
101
|
+
exit 1
|
|
102
|
+
fi
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# Spawn agent registration
|
|
106
|
+
spawn_agent() {
|
|
107
|
+
local agent_id="$1"
|
|
108
|
+
local agent_type="$2"
|
|
109
|
+
local acl_level="${3:-1}"
|
|
110
|
+
local agent_name="${4:-$agent_id}"
|
|
111
|
+
|
|
112
|
+
validate_agent_id "$agent_id"
|
|
113
|
+
|
|
114
|
+
if [[ ! "$acl_level" =~ ^[1-6]$ ]]; then
|
|
115
|
+
log_error "Invalid ACL level: $acl_level (must be 1-6)"
|
|
116
|
+
exit 1
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
log_info "Registering agent spawn: $agent_id (type: $agent_type, ACL: $acl_level)"
|
|
120
|
+
|
|
121
|
+
sqlite3 "$DB_PATH" << EOF
|
|
122
|
+
INSERT OR REPLACE INTO agents (
|
|
123
|
+
id, name, type, status, metadata, spawned_at, updated_at
|
|
124
|
+
) VALUES (
|
|
125
|
+
'$agent_id',
|
|
126
|
+
'$agent_name',
|
|
127
|
+
'$agent_type',
|
|
128
|
+
'spawned',
|
|
129
|
+
'{"aclLevel": $acl_level, "spawnedAt": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"}',
|
|
130
|
+
datetime('now'),
|
|
131
|
+
datetime('now')
|
|
132
|
+
);
|
|
133
|
+
EOF
|
|
134
|
+
|
|
135
|
+
# Log spawn event
|
|
136
|
+
sqlite3 "$DB_PATH" << EOF
|
|
137
|
+
INSERT INTO lifecycle_events (
|
|
138
|
+
agent_id, event_type, reasoning, timestamp
|
|
139
|
+
) VALUES (
|
|
140
|
+
'$agent_id',
|
|
141
|
+
'spawn',
|
|
142
|
+
'Agent spawned via lifecycle hook',
|
|
143
|
+
datetime('now')
|
|
144
|
+
);
|
|
145
|
+
EOF
|
|
146
|
+
|
|
147
|
+
log_success "Agent $agent_id registered successfully"
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
# Update agent confidence
|
|
151
|
+
update_confidence() {
|
|
152
|
+
local agent_id="$1"
|
|
153
|
+
local confidence="$2"
|
|
154
|
+
local reasoning="${3:-No reasoning provided}"
|
|
155
|
+
local phase="${4:-}"
|
|
156
|
+
local iteration="${5:-}"
|
|
157
|
+
|
|
158
|
+
validate_agent_id "$agent_id"
|
|
159
|
+
validate_confidence "$confidence"
|
|
160
|
+
|
|
161
|
+
log_info "Updating confidence for agent $agent_id: $confidence"
|
|
162
|
+
|
|
163
|
+
# Update agent confidence
|
|
164
|
+
sqlite3 "$DB_PATH" << EOF
|
|
165
|
+
UPDATE agents
|
|
166
|
+
SET confidence = $confidence, updated_at = datetime('now')
|
|
167
|
+
WHERE id = '$agent_id';
|
|
168
|
+
EOF
|
|
169
|
+
|
|
170
|
+
# Log confidence update event
|
|
171
|
+
sqlite3 "$DB_PATH" << EOF
|
|
172
|
+
INSERT INTO lifecycle_events (
|
|
173
|
+
agent_id, event_type, confidence, reasoning, phase, iteration, timestamp
|
|
174
|
+
) VALUES (
|
|
175
|
+
'$agent_id',
|
|
176
|
+
'confidence_update',
|
|
177
|
+
$confidence,
|
|
178
|
+
'$reasoning',
|
|
179
|
+
${phase:+"'${phase}'":NULL},
|
|
180
|
+
${iteration:+$iteration},
|
|
181
|
+
datetime('now')
|
|
182
|
+
);
|
|
183
|
+
EOF
|
|
184
|
+
|
|
185
|
+
log_success "Confidence updated for agent $agent_id"
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
# Complete agent
|
|
189
|
+
complete_agent() {
|
|
190
|
+
local agent_id="$1"
|
|
191
|
+
local confidence="$2"
|
|
192
|
+
local output="${3:-}"
|
|
193
|
+
local phase="${4:-}"
|
|
194
|
+
local iteration="${5:-}"
|
|
195
|
+
|
|
196
|
+
validate_agent_id "$agent_id"
|
|
197
|
+
validate_confidence "$confidence"
|
|
198
|
+
|
|
199
|
+
log_info "Completing agent $agent_id with confidence: $confidence"
|
|
200
|
+
|
|
201
|
+
# Mark agent as completed
|
|
202
|
+
sqlite3 "$DB_PATH" << EOF
|
|
203
|
+
UPDATE agents
|
|
204
|
+
SET status = 'completed',
|
|
205
|
+
confidence = $confidence,
|
|
206
|
+
output = ${output:+"'${output}'":NULL},
|
|
207
|
+
completed_at = datetime('now'),
|
|
208
|
+
updated_at = datetime('now')
|
|
209
|
+
WHERE id = '$agent_id';
|
|
210
|
+
EOF
|
|
211
|
+
|
|
212
|
+
# Log completion event
|
|
213
|
+
sqlite3 "$DB_PATH" << EOF
|
|
214
|
+
INSERT INTO lifecycle_events (
|
|
215
|
+
agent_id, event_type, confidence, reasoning, phase, iteration, timestamp
|
|
216
|
+
) VALUES (
|
|
217
|
+
'$agent_id',
|
|
218
|
+
'complete',
|
|
219
|
+
$confidence,
|
|
220
|
+
${output:="'${output}'":'Agent completed'},
|
|
221
|
+
${phase:+"'${phase}'":NULL},
|
|
222
|
+
${iteration:+$iteration},
|
|
223
|
+
datetime('now')
|
|
224
|
+
);
|
|
225
|
+
EOF
|
|
226
|
+
|
|
227
|
+
# Check CFN Loop gate
|
|
228
|
+
local gate_status="FAIL"
|
|
229
|
+
if (( $(echo "$confidence >= 0.75" | bc -l) )); then
|
|
230
|
+
gate_status="PASS"
|
|
231
|
+
fi
|
|
232
|
+
|
|
233
|
+
log_success "Agent $agent_id completed (CFN Loop 3 Gate: $gate_status)"
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
# Terminate agent
|
|
237
|
+
terminate_agent() {
|
|
238
|
+
local agent_id="$1"
|
|
239
|
+
local reason="${2:-Normal termination}"
|
|
240
|
+
|
|
241
|
+
validate_agent_id "$agent_id"
|
|
242
|
+
|
|
243
|
+
log_info "Terminating agent $agent_id: $reason"
|
|
244
|
+
|
|
245
|
+
# Mark agent as terminated
|
|
246
|
+
sqlite3 "$DB_PATH" << EOF
|
|
247
|
+
UPDATE agents
|
|
248
|
+
SET status = 'terminated', updated_at = datetime('now')
|
|
249
|
+
WHERE id = '$agent_id';
|
|
250
|
+
EOF
|
|
251
|
+
|
|
252
|
+
# Log termination event
|
|
253
|
+
sqlite3 "$DB_PATH" << EOF
|
|
254
|
+
INSERT INTO lifecycle_events (
|
|
255
|
+
agent_id, event_type, reasoning, timestamp
|
|
256
|
+
) VALUES (
|
|
257
|
+
'$agent_id',
|
|
258
|
+
'terminate',
|
|
259
|
+
'$reason',
|
|
260
|
+
datetime('now')
|
|
261
|
+
);
|
|
262
|
+
EOF
|
|
263
|
+
|
|
264
|
+
log_success "Agent $agent_id terminated"
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
# Query agent status
|
|
268
|
+
query_status() {
|
|
269
|
+
local agent_id="$1"
|
|
270
|
+
local limit="${2:-10}"
|
|
271
|
+
|
|
272
|
+
validate_agent_id "$agent_id"
|
|
273
|
+
|
|
274
|
+
log_info "Querying status for agent $agent_id"
|
|
275
|
+
|
|
276
|
+
echo ""
|
|
277
|
+
echo "=== Agent Status ==="
|
|
278
|
+
sqlite3 "$DB_PATH" << EOF
|
|
279
|
+
SELECT
|
|
280
|
+
id,
|
|
281
|
+
name,
|
|
282
|
+
type,
|
|
283
|
+
status,
|
|
284
|
+
confidence,
|
|
285
|
+
spawned_at,
|
|
286
|
+
completed_at,
|
|
287
|
+
updated_at
|
|
288
|
+
FROM agents
|
|
289
|
+
WHERE id = '$agent_id';
|
|
290
|
+
EOF
|
|
291
|
+
|
|
292
|
+
echo ""
|
|
293
|
+
echo "=== Recent Lifecycle Events ==="
|
|
294
|
+
sqlite3 "$DB_PATH" << EOF
|
|
295
|
+
SELECT
|
|
296
|
+
timestamp,
|
|
297
|
+
event_type,
|
|
298
|
+
confidence,
|
|
299
|
+
reasoning
|
|
300
|
+
FROM lifecycle_events
|
|
301
|
+
WHERE agent_id = '$agent_id'
|
|
302
|
+
ORDER BY timestamp DESC
|
|
303
|
+
LIMIT $limit;
|
|
304
|
+
EOF
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
# Show usage
|
|
308
|
+
show_usage() {
|
|
309
|
+
echo "Agent Lifecycle Hook Execution Script"
|
|
310
|
+
echo ""
|
|
311
|
+
echo "Usage: $0 <action> [options]"
|
|
312
|
+
echo ""
|
|
313
|
+
echo "Actions:"
|
|
314
|
+
echo " spawn --agent-id <id> --agent-type <type> [--acl-level <level>] [--name <name>]"
|
|
315
|
+
echo " update --agent-id <id> --confidence <score> --reasoning <text> [--phase <phase>] [--iteration <n>]"
|
|
316
|
+
echo " complete --agent-id <id> --confidence <score> [--output <text>] [--phase <phase>] [--iteration <n>]"
|
|
317
|
+
echo " terminate --agent-id <id> [--reason <text>]"
|
|
318
|
+
echo " status --agent-id <id> [--limit <n>]"
|
|
319
|
+
echo ""
|
|
320
|
+
echo "Environment Variables:"
|
|
321
|
+
echo " AGENT_LIFECYCLE_DB Path to SQLite database (default: ./agent-lifecycle.db)"
|
|
322
|
+
echo ""
|
|
323
|
+
echo "Examples:"
|
|
324
|
+
echo " $0 spawn --agent-id docker-1 --agent-type docker-specialist --acl-level 1"
|
|
325
|
+
echo " $0 update --agent-id docker-1 --confidence 0.85 --reasoning 'Implementation complete'"
|
|
326
|
+
echo " $0 complete --agent-id docker-1 --confidence 0.90 --output 'Docker setup complete'"
|
|
327
|
+
echo " $0 status --agent-id docker-1"
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
# Parse command line arguments
|
|
331
|
+
parse_args() {
|
|
332
|
+
local action="$1"
|
|
333
|
+
shift
|
|
334
|
+
|
|
335
|
+
case "$action" in
|
|
336
|
+
"spawn")
|
|
337
|
+
local agent_id=""
|
|
338
|
+
local agent_type=""
|
|
339
|
+
local acl_level="1"
|
|
340
|
+
local agent_name=""
|
|
341
|
+
|
|
342
|
+
while [[ $# -gt 0 ]]; do
|
|
343
|
+
case "$1" in
|
|
344
|
+
--agent-id)
|
|
345
|
+
agent_id="$2"
|
|
346
|
+
shift 2
|
|
347
|
+
;;
|
|
348
|
+
--agent-type)
|
|
349
|
+
agent_type="$2"
|
|
350
|
+
shift 2
|
|
351
|
+
;;
|
|
352
|
+
--acl-level)
|
|
353
|
+
acl_level="$2"
|
|
354
|
+
shift 2
|
|
355
|
+
;;
|
|
356
|
+
--name)
|
|
357
|
+
agent_name="$2"
|
|
358
|
+
shift 2
|
|
359
|
+
;;
|
|
360
|
+
*)
|
|
361
|
+
log_error "Unknown option: $1"
|
|
362
|
+
show_usage
|
|
363
|
+
exit 1
|
|
364
|
+
;;
|
|
365
|
+
esac
|
|
366
|
+
done
|
|
367
|
+
|
|
368
|
+
if [[ -z "$agent_id" || -z "$agent_type" ]]; then
|
|
369
|
+
log_error "Missing required arguments for spawn"
|
|
370
|
+
show_usage
|
|
371
|
+
exit 1
|
|
372
|
+
fi
|
|
373
|
+
|
|
374
|
+
init_database
|
|
375
|
+
spawn_agent "$agent_id" "$agent_type" "$acl_level" "$agent_name"
|
|
376
|
+
;;
|
|
377
|
+
|
|
378
|
+
"update")
|
|
379
|
+
local agent_id=""
|
|
380
|
+
local confidence=""
|
|
381
|
+
local reasoning=""
|
|
382
|
+
local phase=""
|
|
383
|
+
local iteration=""
|
|
384
|
+
|
|
385
|
+
while [[ $# -gt 0 ]]; do
|
|
386
|
+
case "$1" in
|
|
387
|
+
--agent-id)
|
|
388
|
+
agent_id="$2"
|
|
389
|
+
shift 2
|
|
390
|
+
;;
|
|
391
|
+
--confidence)
|
|
392
|
+
confidence="$2"
|
|
393
|
+
shift 2
|
|
394
|
+
;;
|
|
395
|
+
--reasoning)
|
|
396
|
+
reasoning="$2"
|
|
397
|
+
shift 2
|
|
398
|
+
;;
|
|
399
|
+
--phase)
|
|
400
|
+
phase="$2"
|
|
401
|
+
shift 2
|
|
402
|
+
;;
|
|
403
|
+
--iteration)
|
|
404
|
+
iteration="$2"
|
|
405
|
+
shift 2
|
|
406
|
+
;;
|
|
407
|
+
*)
|
|
408
|
+
log_error "Unknown option: $1"
|
|
409
|
+
show_usage
|
|
410
|
+
exit 1
|
|
411
|
+
;;
|
|
412
|
+
esac
|
|
413
|
+
done
|
|
414
|
+
|
|
415
|
+
if [[ -z "$agent_id" || -z "$confidence" ]]; then
|
|
416
|
+
log_error "Missing required arguments for update"
|
|
417
|
+
show_usage
|
|
418
|
+
exit 1
|
|
419
|
+
fi
|
|
420
|
+
|
|
421
|
+
init_database
|
|
422
|
+
update_confidence "$agent_id" "$confidence" "$reasoning" "$phase" "$iteration"
|
|
423
|
+
;;
|
|
424
|
+
|
|
425
|
+
"complete")
|
|
426
|
+
local agent_id=""
|
|
427
|
+
local confidence=""
|
|
428
|
+
local output=""
|
|
429
|
+
local phase=""
|
|
430
|
+
local iteration=""
|
|
431
|
+
|
|
432
|
+
while [[ $# -gt 0 ]]; do
|
|
433
|
+
case "$1" in
|
|
434
|
+
--agent-id)
|
|
435
|
+
agent_id="$2"
|
|
436
|
+
shift 2
|
|
437
|
+
;;
|
|
438
|
+
--confidence)
|
|
439
|
+
confidence="$2"
|
|
440
|
+
shift 2
|
|
441
|
+
;;
|
|
442
|
+
--output)
|
|
443
|
+
output="$2"
|
|
444
|
+
shift 2
|
|
445
|
+
;;
|
|
446
|
+
--phase)
|
|
447
|
+
phase="$2"
|
|
448
|
+
shift 2
|
|
449
|
+
;;
|
|
450
|
+
--iteration)
|
|
451
|
+
iteration="$2"
|
|
452
|
+
shift 2
|
|
453
|
+
;;
|
|
454
|
+
*)
|
|
455
|
+
log_error "Unknown option: $1"
|
|
456
|
+
show_usage
|
|
457
|
+
exit 1
|
|
458
|
+
;;
|
|
459
|
+
esac
|
|
460
|
+
done
|
|
461
|
+
|
|
462
|
+
if [[ -z "$agent_id" || -z "$confidence" ]]; then
|
|
463
|
+
log_error "Missing required arguments for complete"
|
|
464
|
+
show_usage
|
|
465
|
+
exit 1
|
|
466
|
+
fi
|
|
467
|
+
|
|
468
|
+
init_database
|
|
469
|
+
complete_agent "$agent_id" "$confidence" "$output" "$phase" "$iteration"
|
|
470
|
+
;;
|
|
471
|
+
|
|
472
|
+
"terminate")
|
|
473
|
+
local agent_id=""
|
|
474
|
+
local reason=""
|
|
475
|
+
|
|
476
|
+
while [[ $# -gt 0 ]]; do
|
|
477
|
+
case "$1" in
|
|
478
|
+
--agent-id)
|
|
479
|
+
agent_id="$2"
|
|
480
|
+
shift 2
|
|
481
|
+
;;
|
|
482
|
+
--reason)
|
|
483
|
+
reason="$2"
|
|
484
|
+
shift 2
|
|
485
|
+
;;
|
|
486
|
+
*)
|
|
487
|
+
log_error "Unknown option: $1"
|
|
488
|
+
show_usage
|
|
489
|
+
exit 1
|
|
490
|
+
;;
|
|
491
|
+
esac
|
|
492
|
+
done
|
|
493
|
+
|
|
494
|
+
if [[ -z "$agent_id" ]]; then
|
|
495
|
+
log_error "Missing required arguments for terminate"
|
|
496
|
+
show_usage
|
|
497
|
+
exit 1
|
|
498
|
+
fi
|
|
499
|
+
|
|
500
|
+
init_database
|
|
501
|
+
terminate_agent "$agent_id" "$reason"
|
|
502
|
+
;;
|
|
503
|
+
|
|
504
|
+
"status")
|
|
505
|
+
local agent_id=""
|
|
506
|
+
local limit="10"
|
|
507
|
+
|
|
508
|
+
while [[ $# -gt 0 ]]; do
|
|
509
|
+
case "$1" in
|
|
510
|
+
--agent-id)
|
|
511
|
+
agent_id="$2"
|
|
512
|
+
shift 2
|
|
513
|
+
;;
|
|
514
|
+
--limit)
|
|
515
|
+
limit="$2"
|
|
516
|
+
shift 2
|
|
517
|
+
;;
|
|
518
|
+
*)
|
|
519
|
+
log_error "Unknown option: $1"
|
|
520
|
+
show_usage
|
|
521
|
+
exit 1
|
|
522
|
+
;;
|
|
523
|
+
esac
|
|
524
|
+
done
|
|
525
|
+
|
|
526
|
+
if [[ -z "$agent_id" ]]; then
|
|
527
|
+
log_error "Missing required arguments for status"
|
|
528
|
+
show_usage
|
|
529
|
+
exit 1
|
|
530
|
+
fi
|
|
531
|
+
|
|
532
|
+
init_database
|
|
533
|
+
query_status "$agent_id" "$limit"
|
|
534
|
+
;;
|
|
535
|
+
|
|
536
|
+
"help"|"--help"|"-h")
|
|
537
|
+
show_usage
|
|
538
|
+
;;
|
|
539
|
+
|
|
540
|
+
*)
|
|
541
|
+
log_error "Unknown action: $action"
|
|
542
|
+
show_usage
|
|
543
|
+
exit 1
|
|
544
|
+
;;
|
|
545
|
+
esac
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
# Check for required dependencies
|
|
549
|
+
check_dependencies() {
|
|
550
|
+
if ! command -v sqlite3 &> /dev/null; then
|
|
551
|
+
log_error "sqlite3 is required but not installed"
|
|
552
|
+
exit 1
|
|
553
|
+
fi
|
|
554
|
+
|
|
555
|
+
if ! command -v bc &> /dev/null; then
|
|
556
|
+
log_warning "bc is recommended for confidence calculations"
|
|
557
|
+
fi
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
# Main execution
|
|
561
|
+
main() {
|
|
562
|
+
check_dependencies
|
|
563
|
+
|
|
564
|
+
if [[ $# -eq 0 ]]; then
|
|
565
|
+
show_usage
|
|
566
|
+
exit 1
|
|
567
|
+
fi
|
|
568
|
+
|
|
569
|
+
parse_args "$@"
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
# Execute main function
|
|
573
573
|
main "$@"
|