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
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# track-cost-savings.sh - Log skill executions and calculate ROI metrics
|
|
5
|
+
# Tracks cost savings from script execution vs AI agent usage
|
|
6
|
+
|
|
7
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
8
|
+
DB_PATH="${DB_PATH:-${SCRIPT_DIR}/workflow-codification.db}"
|
|
9
|
+
|
|
10
|
+
# Cost constants
|
|
11
|
+
AI_COST_PER_MILLION=0.50 # $0.50 per 1M tokens (Z.ai glm-4.6)
|
|
12
|
+
SCRIPT_COST=0.0001 # Negligible script execution cost
|
|
13
|
+
AVG_AI_INPUT_TOKENS=2000 # Average input tokens for skill-equivalent task
|
|
14
|
+
AVG_AI_OUTPUT_TOKENS=1000 # Average output tokens for skill-equivalent task
|
|
15
|
+
|
|
16
|
+
# Initialize database schema
|
|
17
|
+
init_database() {
|
|
18
|
+
sqlite3 "$DB_PATH" <<'EOF'
|
|
19
|
+
CREATE TABLE IF NOT EXISTS skill_executions (
|
|
20
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
21
|
+
skill_name TEXT NOT NULL,
|
|
22
|
+
skill_version TEXT NOT NULL,
|
|
23
|
+
execution_time_ms INTEGER NOT NULL,
|
|
24
|
+
exit_code INTEGER NOT NULL,
|
|
25
|
+
tokens_avoided INTEGER NOT NULL,
|
|
26
|
+
cost_avoided_usd REAL NOT NULL,
|
|
27
|
+
timestamp TEXT DEFAULT (datetime('now')),
|
|
28
|
+
agent_type TEXT,
|
|
29
|
+
task_description TEXT,
|
|
30
|
+
metadata TEXT
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
CREATE INDEX IF NOT EXISTS idx_executions_skill ON skill_executions(skill_name);
|
|
34
|
+
CREATE INDEX IF NOT EXISTS idx_executions_timestamp ON skill_executions(timestamp);
|
|
35
|
+
CREATE INDEX IF NOT EXISTS idx_executions_exit_code ON skill_executions(exit_code);
|
|
36
|
+
|
|
37
|
+
CREATE TABLE IF NOT EXISTS roi_snapshots (
|
|
38
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
39
|
+
snapshot_date TEXT DEFAULT (date('now')),
|
|
40
|
+
total_executions INTEGER NOT NULL,
|
|
41
|
+
total_cost_avoided_usd REAL NOT NULL,
|
|
42
|
+
total_tokens_avoided INTEGER NOT NULL,
|
|
43
|
+
avg_execution_time_ms REAL NOT NULL,
|
|
44
|
+
top_skill_name TEXT,
|
|
45
|
+
top_skill_savings_usd REAL,
|
|
46
|
+
metadata TEXT
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
CREATE INDEX IF NOT EXISTS idx_roi_snapshots_date ON roi_snapshots(snapshot_date);
|
|
50
|
+
EOF
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
# Calculate AI cost based on tokens
|
|
54
|
+
calculate_ai_cost() {
|
|
55
|
+
local input_tokens="${1:-$AVG_AI_INPUT_TOKENS}"
|
|
56
|
+
local output_tokens="${2:-$AVG_AI_OUTPUT_TOKENS}"
|
|
57
|
+
|
|
58
|
+
local total_tokens=$((input_tokens + output_tokens))
|
|
59
|
+
local cost=$(echo "scale=6; ($total_tokens * $AI_COST_PER_MILLION) / 1000000" | bc)
|
|
60
|
+
|
|
61
|
+
echo "$cost"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Calculate cost savings
|
|
65
|
+
calculate_savings() {
|
|
66
|
+
local ai_cost="$1"
|
|
67
|
+
local script_cost="${2:-$SCRIPT_COST}"
|
|
68
|
+
|
|
69
|
+
local savings=$(echo "scale=6; $ai_cost - $script_cost" | bc)
|
|
70
|
+
echo "$savings"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
# Log skill execution
|
|
74
|
+
log_execution() {
|
|
75
|
+
local skill_name="$1"
|
|
76
|
+
local skill_version="$2"
|
|
77
|
+
local execution_time_ms="$3"
|
|
78
|
+
local exit_code="$4"
|
|
79
|
+
local tokens_avoided="${5:-$((AVG_AI_INPUT_TOKENS + AVG_AI_OUTPUT_TOKENS))}"
|
|
80
|
+
local agent_type="${6:-}"
|
|
81
|
+
local task_description="${7:-}"
|
|
82
|
+
local metadata="${8:-{}}"
|
|
83
|
+
|
|
84
|
+
# Calculate costs
|
|
85
|
+
local input_tokens=$((tokens_avoided * 2 / 3))
|
|
86
|
+
local output_tokens=$((tokens_avoided / 3))
|
|
87
|
+
local ai_cost
|
|
88
|
+
ai_cost=$(calculate_ai_cost "$input_tokens" "$output_tokens")
|
|
89
|
+
local cost_avoided
|
|
90
|
+
cost_avoided=$(calculate_savings "$ai_cost")
|
|
91
|
+
|
|
92
|
+
# Insert execution record
|
|
93
|
+
sqlite3 "$DB_PATH" <<EOF
|
|
94
|
+
INSERT INTO skill_executions (
|
|
95
|
+
skill_name,
|
|
96
|
+
skill_version,
|
|
97
|
+
execution_time_ms,
|
|
98
|
+
exit_code,
|
|
99
|
+
tokens_avoided,
|
|
100
|
+
cost_avoided_usd,
|
|
101
|
+
agent_type,
|
|
102
|
+
task_description,
|
|
103
|
+
metadata
|
|
104
|
+
) VALUES (
|
|
105
|
+
'$skill_name',
|
|
106
|
+
'$skill_version',
|
|
107
|
+
$execution_time_ms,
|
|
108
|
+
$exit_code,
|
|
109
|
+
$tokens_avoided,
|
|
110
|
+
$cost_avoided,
|
|
111
|
+
'$agent_type',
|
|
112
|
+
'$task_description',
|
|
113
|
+
'$metadata'
|
|
114
|
+
);
|
|
115
|
+
EOF
|
|
116
|
+
|
|
117
|
+
echo "Logged execution: $skill_name (saved \$$cost_avoided)"
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
# Generate ROI snapshot
|
|
121
|
+
generate_roi_snapshot() {
|
|
122
|
+
local snapshot_date="${1:-$(date +%Y-%m-%d)}"
|
|
123
|
+
|
|
124
|
+
# Calculate aggregate metrics
|
|
125
|
+
local total_executions
|
|
126
|
+
total_executions=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM skill_executions WHERE date(timestamp) = '$snapshot_date';")
|
|
127
|
+
|
|
128
|
+
if [[ "$total_executions" -eq 0 ]]; then
|
|
129
|
+
echo "No executions found for date: $snapshot_date"
|
|
130
|
+
return 0
|
|
131
|
+
fi
|
|
132
|
+
|
|
133
|
+
local total_cost_avoided
|
|
134
|
+
total_cost_avoided=$(sqlite3 "$DB_PATH" "SELECT COALESCE(SUM(cost_avoided_usd), 0) FROM skill_executions WHERE date(timestamp) = '$snapshot_date';")
|
|
135
|
+
|
|
136
|
+
local total_tokens_avoided
|
|
137
|
+
total_tokens_avoided=$(sqlite3 "$DB_PATH" "SELECT COALESCE(SUM(tokens_avoided), 0) FROM skill_executions WHERE date(timestamp) = '$snapshot_date';")
|
|
138
|
+
|
|
139
|
+
local avg_execution_time
|
|
140
|
+
avg_execution_time=$(sqlite3 "$DB_PATH" "SELECT COALESCE(AVG(execution_time_ms), 0) FROM skill_executions WHERE date(timestamp) = '$snapshot_date';")
|
|
141
|
+
|
|
142
|
+
# Get top performing skill
|
|
143
|
+
local top_skill_data
|
|
144
|
+
top_skill_data=$(sqlite3 "$DB_PATH" "SELECT skill_name, SUM(cost_avoided_usd) FROM skill_executions WHERE date(timestamp) = '$snapshot_date' GROUP BY skill_name ORDER BY SUM(cost_avoided_usd) DESC LIMIT 1;")
|
|
145
|
+
|
|
146
|
+
local top_skill_name
|
|
147
|
+
local top_skill_savings
|
|
148
|
+
if [[ -n "$top_skill_data" ]]; then
|
|
149
|
+
top_skill_name=$(echo "$top_skill_data" | cut -d'|' -f1)
|
|
150
|
+
top_skill_savings=$(echo "$top_skill_data" | cut -d'|' -f2)
|
|
151
|
+
else
|
|
152
|
+
top_skill_name=""
|
|
153
|
+
top_skill_savings="0"
|
|
154
|
+
fi
|
|
155
|
+
|
|
156
|
+
# Insert snapshot
|
|
157
|
+
sqlite3 "$DB_PATH" <<EOF
|
|
158
|
+
INSERT INTO roi_snapshots (
|
|
159
|
+
snapshot_date,
|
|
160
|
+
total_executions,
|
|
161
|
+
total_cost_avoided_usd,
|
|
162
|
+
total_tokens_avoided,
|
|
163
|
+
avg_execution_time_ms,
|
|
164
|
+
top_skill_name,
|
|
165
|
+
top_skill_savings_usd,
|
|
166
|
+
metadata
|
|
167
|
+
) VALUES (
|
|
168
|
+
'$snapshot_date',
|
|
169
|
+
$total_executions,
|
|
170
|
+
$total_cost_avoided,
|
|
171
|
+
$total_tokens_avoided,
|
|
172
|
+
$avg_execution_time,
|
|
173
|
+
'$top_skill_name',
|
|
174
|
+
$top_skill_savings,
|
|
175
|
+
'{}'
|
|
176
|
+
);
|
|
177
|
+
EOF
|
|
178
|
+
|
|
179
|
+
echo "Generated ROI snapshot for $snapshot_date"
|
|
180
|
+
echo "Total executions: $total_executions"
|
|
181
|
+
echo "Total cost avoided: \$$total_cost_avoided"
|
|
182
|
+
echo "Top skill: $top_skill_name (\$$top_skill_savings)"
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
# Query per-skill ROI ranking
|
|
186
|
+
query_skill_roi_ranking() {
|
|
187
|
+
local period="${1:-30}" # Default: last 30 days
|
|
188
|
+
|
|
189
|
+
sqlite3 -header -column "$DB_PATH" <<EOF
|
|
190
|
+
SELECT
|
|
191
|
+
skill_name,
|
|
192
|
+
COUNT(*) as executions,
|
|
193
|
+
SUM(cost_avoided_usd) as total_savings_usd,
|
|
194
|
+
AVG(cost_avoided_usd) as avg_savings_per_execution,
|
|
195
|
+
AVG(execution_time_ms) as avg_execution_time_ms,
|
|
196
|
+
SUM(tokens_avoided) as total_tokens_avoided
|
|
197
|
+
FROM skill_executions
|
|
198
|
+
WHERE timestamp >= datetime('now', '-$period days')
|
|
199
|
+
GROUP BY skill_name
|
|
200
|
+
ORDER BY total_savings_usd DESC;
|
|
201
|
+
EOF
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
# Calculate monthly/annual projections
|
|
205
|
+
calculate_projections() {
|
|
206
|
+
local period_days="${1:-30}"
|
|
207
|
+
|
|
208
|
+
# Get average daily metrics
|
|
209
|
+
local daily_executions
|
|
210
|
+
daily_executions=$(sqlite3 "$DB_PATH" "SELECT COALESCE(COUNT(*) / $period_days, 0) FROM skill_executions WHERE timestamp >= datetime('now', '-$period_days days');")
|
|
211
|
+
|
|
212
|
+
local daily_savings
|
|
213
|
+
daily_savings=$(sqlite3 "$DB_PATH" "SELECT COALESCE(SUM(cost_avoided_usd) / $period_days, 0) FROM skill_executions WHERE timestamp >= datetime('now', '-$period_days days');")
|
|
214
|
+
|
|
215
|
+
# Calculate projections
|
|
216
|
+
local monthly_executions=$(echo "$daily_executions * 30" | bc)
|
|
217
|
+
local monthly_savings=$(echo "scale=2; $daily_savings * 30" | bc)
|
|
218
|
+
local annual_savings=$(echo "scale=2; $daily_savings * 365" | bc)
|
|
219
|
+
|
|
220
|
+
cat <<PROJECTIONS
|
|
221
|
+
Cost Savings Projections (based on last $period_days days):
|
|
222
|
+
---------------------------------------------------------
|
|
223
|
+
Daily Average:
|
|
224
|
+
- Executions: $daily_executions
|
|
225
|
+
- Savings: \$$daily_savings
|
|
226
|
+
|
|
227
|
+
Monthly Projection:
|
|
228
|
+
- Executions: $monthly_executions
|
|
229
|
+
- Savings: \$$monthly_savings
|
|
230
|
+
|
|
231
|
+
Annual Projection:
|
|
232
|
+
- Savings: \$$annual_savings
|
|
233
|
+
PROJECTIONS
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
# Export dashboard metrics
|
|
237
|
+
export_dashboard_metrics() {
|
|
238
|
+
local output_format="${1:-json}"
|
|
239
|
+
|
|
240
|
+
case "$output_format" in
|
|
241
|
+
json)
|
|
242
|
+
cat <<JSON
|
|
243
|
+
{
|
|
244
|
+
"total_executions": $(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM skill_executions;"),
|
|
245
|
+
"total_cost_avoided_usd": $(sqlite3 "$DB_PATH" "SELECT COALESCE(SUM(cost_avoided_usd), 0) FROM skill_executions;"),
|
|
246
|
+
"total_tokens_avoided": $(sqlite3 "$DB_PATH" "SELECT COALESCE(SUM(tokens_avoided), 0) FROM skill_executions;"),
|
|
247
|
+
"avg_execution_time_ms": $(sqlite3 "$DB_PATH" "SELECT COALESCE(AVG(execution_time_ms), 0) FROM skill_executions;"),
|
|
248
|
+
"success_rate": $(sqlite3 "$DB_PATH" "SELECT COALESCE(CAST(SUM(CASE WHEN exit_code = 0 THEN 1 ELSE 0 END) AS REAL) / COUNT(*), 0) FROM skill_executions;"),
|
|
249
|
+
"last_30_days": {
|
|
250
|
+
"executions": $(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM skill_executions WHERE timestamp >= datetime('now', '-30 days');"),
|
|
251
|
+
"cost_avoided_usd": $(sqlite3 "$DB_PATH" "SELECT COALESCE(SUM(cost_avoided_usd), 0) FROM skill_executions WHERE timestamp >= datetime('now', '-30 days');")
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
JSON
|
|
255
|
+
;;
|
|
256
|
+
table)
|
|
257
|
+
sqlite3 -header -column "$DB_PATH" <<SQL
|
|
258
|
+
SELECT
|
|
259
|
+
'All Time' as period,
|
|
260
|
+
COUNT(*) as executions,
|
|
261
|
+
SUM(cost_avoided_usd) as cost_avoided_usd,
|
|
262
|
+
AVG(execution_time_ms) as avg_time_ms
|
|
263
|
+
FROM skill_executions
|
|
264
|
+
UNION ALL
|
|
265
|
+
SELECT
|
|
266
|
+
'Last 30 Days' as period,
|
|
267
|
+
COUNT(*) as executions,
|
|
268
|
+
SUM(cost_avoided_usd) as cost_avoided_usd,
|
|
269
|
+
AVG(execution_time_ms) as avg_time_ms
|
|
270
|
+
FROM skill_executions
|
|
271
|
+
WHERE timestamp >= datetime('now', '-30 days')
|
|
272
|
+
UNION ALL
|
|
273
|
+
SELECT
|
|
274
|
+
'Last 7 Days' as period,
|
|
275
|
+
COUNT(*) as executions,
|
|
276
|
+
SUM(cost_avoided_usd) as cost_avoided_usd,
|
|
277
|
+
AVG(execution_time_ms) as avg_time_ms
|
|
278
|
+
FROM skill_executions
|
|
279
|
+
WHERE timestamp >= datetime('now', '-7 days');
|
|
280
|
+
SQL
|
|
281
|
+
;;
|
|
282
|
+
*)
|
|
283
|
+
echo "Unknown format: $output_format" >&2
|
|
284
|
+
exit 1
|
|
285
|
+
;;
|
|
286
|
+
esac
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
# Main execution
|
|
290
|
+
main() {
|
|
291
|
+
# Initialize database
|
|
292
|
+
init_database
|
|
293
|
+
|
|
294
|
+
# Parse arguments
|
|
295
|
+
local action=""
|
|
296
|
+
local skill_name=""
|
|
297
|
+
local skill_version=""
|
|
298
|
+
local execution_time_ms=""
|
|
299
|
+
local exit_code=""
|
|
300
|
+
local tokens_avoided=""
|
|
301
|
+
local agent_type=""
|
|
302
|
+
local task_description=""
|
|
303
|
+
local metadata="{}"
|
|
304
|
+
local period="30"
|
|
305
|
+
local output_format="json"
|
|
306
|
+
|
|
307
|
+
while [[ $# -gt 0 ]]; do
|
|
308
|
+
case $1 in
|
|
309
|
+
--action)
|
|
310
|
+
action="$2"
|
|
311
|
+
shift 2
|
|
312
|
+
;;
|
|
313
|
+
--skill-name)
|
|
314
|
+
skill_name="$2"
|
|
315
|
+
shift 2
|
|
316
|
+
;;
|
|
317
|
+
--skill-version)
|
|
318
|
+
skill_version="$2"
|
|
319
|
+
shift 2
|
|
320
|
+
;;
|
|
321
|
+
--execution-time-ms)
|
|
322
|
+
execution_time_ms="$2"
|
|
323
|
+
shift 2
|
|
324
|
+
;;
|
|
325
|
+
--exit-code)
|
|
326
|
+
exit_code="$2"
|
|
327
|
+
shift 2
|
|
328
|
+
;;
|
|
329
|
+
--tokens-avoided)
|
|
330
|
+
tokens_avoided="$2"
|
|
331
|
+
shift 2
|
|
332
|
+
;;
|
|
333
|
+
--agent-type)
|
|
334
|
+
agent_type="$2"
|
|
335
|
+
shift 2
|
|
336
|
+
;;
|
|
337
|
+
--task-description)
|
|
338
|
+
task_description="$2"
|
|
339
|
+
shift 2
|
|
340
|
+
;;
|
|
341
|
+
--metadata)
|
|
342
|
+
metadata="$2"
|
|
343
|
+
shift 2
|
|
344
|
+
;;
|
|
345
|
+
--period)
|
|
346
|
+
period="$2"
|
|
347
|
+
shift 2
|
|
348
|
+
;;
|
|
349
|
+
--format)
|
|
350
|
+
output_format="$2"
|
|
351
|
+
shift 2
|
|
352
|
+
;;
|
|
353
|
+
--help)
|
|
354
|
+
cat <<HELP
|
|
355
|
+
Usage: track-cost-savings.sh --action <ACTION> [OPTIONS]
|
|
356
|
+
|
|
357
|
+
Actions:
|
|
358
|
+
log Log skill execution
|
|
359
|
+
snapshot Generate ROI snapshot
|
|
360
|
+
ranking Query per-skill ROI ranking
|
|
361
|
+
projections Calculate monthly/annual projections
|
|
362
|
+
dashboard Export dashboard metrics
|
|
363
|
+
|
|
364
|
+
Log Options:
|
|
365
|
+
--skill-name STRING Skill name (required)
|
|
366
|
+
--skill-version STRING Skill version (required)
|
|
367
|
+
--execution-time-ms INTEGER Execution time in milliseconds (required)
|
|
368
|
+
--exit-code INTEGER Exit code (required)
|
|
369
|
+
--tokens-avoided INTEGER Tokens avoided (default: 3000)
|
|
370
|
+
--agent-type STRING Agent type (optional)
|
|
371
|
+
--task-description STRING Task description (optional)
|
|
372
|
+
--metadata JSON Additional metadata (optional)
|
|
373
|
+
|
|
374
|
+
Ranking/Projections Options:
|
|
375
|
+
--period INTEGER Analysis period in days (default: 30)
|
|
376
|
+
|
|
377
|
+
Dashboard Options:
|
|
378
|
+
--format STRING Output format: json|table (default: json)
|
|
379
|
+
|
|
380
|
+
Environment Variables:
|
|
381
|
+
DB_PATH Path to SQLite database (default: ./workflow-codification.db)
|
|
382
|
+
|
|
383
|
+
Examples:
|
|
384
|
+
# Log execution
|
|
385
|
+
track-cost-savings.sh --action log \\
|
|
386
|
+
--skill-name "cfn-coordination" \\
|
|
387
|
+
--skill-version "1.0.0" \\
|
|
388
|
+
--execution-time-ms 150 \\
|
|
389
|
+
--exit-code 0 \\
|
|
390
|
+
--tokens-avoided 3000
|
|
391
|
+
|
|
392
|
+
# Generate daily ROI snapshot
|
|
393
|
+
track-cost-savings.sh --action snapshot
|
|
394
|
+
|
|
395
|
+
# Query skill ROI ranking (last 30 days)
|
|
396
|
+
track-cost-savings.sh --action ranking --period 30
|
|
397
|
+
|
|
398
|
+
# Calculate projections
|
|
399
|
+
track-cost-savings.sh --action projections --period 30
|
|
400
|
+
|
|
401
|
+
# Export dashboard metrics
|
|
402
|
+
track-cost-savings.sh --action dashboard --format json
|
|
403
|
+
HELP
|
|
404
|
+
exit 0
|
|
405
|
+
;;
|
|
406
|
+
*)
|
|
407
|
+
echo "Unknown argument: $1" >&2
|
|
408
|
+
exit 1
|
|
409
|
+
;;
|
|
410
|
+
esac
|
|
411
|
+
done
|
|
412
|
+
|
|
413
|
+
# Execute action
|
|
414
|
+
case "$action" in
|
|
415
|
+
log)
|
|
416
|
+
if [[ -z "$skill_name" || -z "$skill_version" || -z "$execution_time_ms" || -z "$exit_code" ]]; then
|
|
417
|
+
echo "Error: --skill-name, --skill-version, --execution-time-ms, and --exit-code are required" >&2
|
|
418
|
+
exit 1
|
|
419
|
+
fi
|
|
420
|
+
log_execution "$skill_name" "$skill_version" "$execution_time_ms" "$exit_code" \
|
|
421
|
+
"$tokens_avoided" "$agent_type" "$task_description" "$metadata"
|
|
422
|
+
;;
|
|
423
|
+
snapshot)
|
|
424
|
+
generate_roi_snapshot
|
|
425
|
+
;;
|
|
426
|
+
ranking)
|
|
427
|
+
query_skill_roi_ranking "$period"
|
|
428
|
+
;;
|
|
429
|
+
projections)
|
|
430
|
+
calculate_projections "$period"
|
|
431
|
+
;;
|
|
432
|
+
dashboard)
|
|
433
|
+
export_dashboard_metrics "$output_format"
|
|
434
|
+
;;
|
|
435
|
+
*)
|
|
436
|
+
echo "Error: Invalid action. Use --help for usage information." >&2
|
|
437
|
+
exit 1
|
|
438
|
+
;;
|
|
439
|
+
esac
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
# Execute main if not sourced
|
|
443
|
+
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
|
444
|
+
main "$@"
|
|
445
|
+
fi
|