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,637 @@
|
|
|
1
|
+
# Cost Tracking and ROI Engine
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Cost Tracking Engine measures the economic value of skill automation by comparing script execution costs versus equivalent AI agent invocations. It provides ROI metrics, savings projections, and skill performance rankings.
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
Skill Execution
|
|
11
|
+
├─ Record execution metadata
|
|
12
|
+
├─ Calculate tokens avoided
|
|
13
|
+
├─ Compute cost savings (AI - Script)
|
|
14
|
+
└─ Store in skill_executions table
|
|
15
|
+
├─ Daily ROI snapshot generation
|
|
16
|
+
├─ Per-skill ranking analysis
|
|
17
|
+
└─ Monthly/Annual projections
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Database Schema
|
|
21
|
+
|
|
22
|
+
### skill_executions Table
|
|
23
|
+
|
|
24
|
+
```sql
|
|
25
|
+
CREATE TABLE skill_executions (
|
|
26
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
27
|
+
skill_name TEXT NOT NULL,
|
|
28
|
+
skill_version TEXT NOT NULL,
|
|
29
|
+
execution_time_ms INTEGER NOT NULL,
|
|
30
|
+
exit_code INTEGER NOT NULL,
|
|
31
|
+
tokens_avoided INTEGER NOT NULL,
|
|
32
|
+
cost_avoided_usd REAL NOT NULL,
|
|
33
|
+
timestamp TEXT DEFAULT (datetime('now')),
|
|
34
|
+
agent_type TEXT,
|
|
35
|
+
task_description TEXT,
|
|
36
|
+
metadata TEXT
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### roi_snapshots Table
|
|
41
|
+
|
|
42
|
+
```sql
|
|
43
|
+
CREATE TABLE roi_snapshots (
|
|
44
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
45
|
+
snapshot_date TEXT DEFAULT (date('now')),
|
|
46
|
+
total_executions INTEGER NOT NULL,
|
|
47
|
+
total_cost_avoided_usd REAL NOT NULL,
|
|
48
|
+
total_tokens_avoided INTEGER NOT NULL,
|
|
49
|
+
avg_execution_time_ms REAL NOT NULL,
|
|
50
|
+
top_skill_name TEXT,
|
|
51
|
+
top_skill_savings_usd REAL,
|
|
52
|
+
metadata TEXT
|
|
53
|
+
);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Indexes
|
|
57
|
+
|
|
58
|
+
- `idx_executions_skill`: (skill_name)
|
|
59
|
+
- `idx_executions_timestamp`: (timestamp)
|
|
60
|
+
- `idx_executions_exit_code`: (exit_code)
|
|
61
|
+
- `idx_roi_snapshots_date`: (snapshot_date)
|
|
62
|
+
|
|
63
|
+
## Cost Calculation Formulas
|
|
64
|
+
|
|
65
|
+
### AI Agent Cost
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
ai_cost = ((input_tokens + output_tokens) × $0.50) ÷ 1,000,000
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Default Token Estimates:**
|
|
72
|
+
- Input tokens: 2000 (skill-equivalent task description)
|
|
73
|
+
- Output tokens: 1000 (implementation + response)
|
|
74
|
+
- Total tokens: 3000
|
|
75
|
+
|
|
76
|
+
**Example:**
|
|
77
|
+
```
|
|
78
|
+
ai_cost = (3000 × $0.50) ÷ 1,000,000 = $0.0015
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Script Execution Cost
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
script_cost = $0.0001 (negligible infrastructure cost)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Cost Savings
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
savings = ai_cost - script_cost
|
|
91
|
+
savings = $0.0015 - $0.0001 = $0.0014 per execution
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Monthly Projection
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
monthly_savings = executions_per_month × savings_per_execution
|
|
98
|
+
|
|
99
|
+
# Example: 1000 executions/month
|
|
100
|
+
monthly_savings = 1000 × $0.0014 = $1.40
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Annual Projection
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
annual_savings = executions_per_year × savings_per_execution
|
|
107
|
+
|
|
108
|
+
# Example: 12,000 executions/year
|
|
109
|
+
annual_savings = 12000 × $0.0014 = $16.80
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Usage
|
|
113
|
+
|
|
114
|
+
### 1. Log Skill Execution
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
track-cost-savings.sh --action log \
|
|
118
|
+
--skill-name "cfn-coordination" \
|
|
119
|
+
--skill-version "1.0.0" \
|
|
120
|
+
--execution-time-ms 150 \
|
|
121
|
+
--exit-code 0 \
|
|
122
|
+
--tokens-avoided 3000 \
|
|
123
|
+
--agent-type "cfn-v3-coordinator" \
|
|
124
|
+
--task-description "Coordinate Loop 3 agents"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Output:**
|
|
128
|
+
```
|
|
129
|
+
Logged execution: cfn-coordination (saved $0.0014)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 2. Generate ROI Snapshot
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
track-cost-savings.sh --action snapshot
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Output:**
|
|
139
|
+
```
|
|
140
|
+
Generated ROI snapshot for 2025-11-15
|
|
141
|
+
Total executions: 156
|
|
142
|
+
Total cost avoided: $0.2184
|
|
143
|
+
Top skill: cfn-coordination ($0.0896)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 3. Query Skill ROI Ranking
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
track-cost-savings.sh --action ranking --period 30
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Output:**
|
|
153
|
+
```
|
|
154
|
+
skill_name executions total_savings_usd avg_savings_per_execution avg_execution_time_ms total_tokens_avoided
|
|
155
|
+
---------------------- ---------- ----------------- ------------------------- --------------------- --------------------
|
|
156
|
+
cfn-coordination 64 0.0896 0.0014 145.3 192000
|
|
157
|
+
cfn-agent-spawning 42 0.0588 0.0014 89.7 126000
|
|
158
|
+
cfn-loop-validation 28 0.0392 0.0014 203.1 84000
|
|
159
|
+
cfn-deliverable-valid 22 0.0308 0.0014 67.4 66000
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 4. Calculate Projections
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
track-cost-savings.sh --action projections --period 30
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Output:**
|
|
169
|
+
```
|
|
170
|
+
Cost Savings Projections (based on last 30 days):
|
|
171
|
+
---------------------------------------------------------
|
|
172
|
+
Daily Average:
|
|
173
|
+
- Executions: 5.20
|
|
174
|
+
- Savings: $0.00728
|
|
175
|
+
|
|
176
|
+
Monthly Projection:
|
|
177
|
+
- Executions: 156
|
|
178
|
+
- Savings: $0.22
|
|
179
|
+
|
|
180
|
+
Annual Projection:
|
|
181
|
+
- Savings: $2.66
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 5. Export Dashboard Metrics
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
track-cost-savings.sh --action dashboard --format json
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
**Output (JSON):**
|
|
191
|
+
```json
|
|
192
|
+
{
|
|
193
|
+
"total_executions": 156,
|
|
194
|
+
"total_cost_avoided_usd": 0.2184,
|
|
195
|
+
"total_tokens_avoided": 468000,
|
|
196
|
+
"avg_execution_time_ms": 134.2,
|
|
197
|
+
"success_rate": 0.9615384615384616,
|
|
198
|
+
"last_30_days": {
|
|
199
|
+
"executions": 156,
|
|
200
|
+
"cost_avoided_usd": 0.2184
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Table Format:**
|
|
206
|
+
```bash
|
|
207
|
+
track-cost-savings.sh --action dashboard --format table
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Output:**
|
|
211
|
+
```
|
|
212
|
+
period executions cost_avoided_usd avg_time_ms
|
|
213
|
+
------------- ---------- ---------------- -----------
|
|
214
|
+
All Time 156 0.2184 134.2
|
|
215
|
+
Last 30 Days 156 0.2184 134.2
|
|
216
|
+
Last 7 Days 38 0.0532 128.5
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Integration Patterns
|
|
220
|
+
|
|
221
|
+
### Pattern 1: Skill Wrapper with Timing
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
#!/usr/bin/env bash
|
|
225
|
+
set -euo pipefail
|
|
226
|
+
|
|
227
|
+
SKILL_NAME="cfn-coordination"
|
|
228
|
+
SKILL_VERSION="1.0.0"
|
|
229
|
+
TOKENS_AVOIDED=3000
|
|
230
|
+
|
|
231
|
+
# Execute skill with timing
|
|
232
|
+
START_TIME=$(date +%s%3N)
|
|
233
|
+
output=$(./cfn-coordination.sh "$@" 2>&1) || exit_code=$?
|
|
234
|
+
END_TIME=$(date +%s%3N)
|
|
235
|
+
|
|
236
|
+
EXECUTION_TIME=$((END_TIME - START_TIME))
|
|
237
|
+
|
|
238
|
+
# Track cost savings
|
|
239
|
+
/path/to/track-cost-savings.sh --action log \
|
|
240
|
+
--skill-name "$SKILL_NAME" \
|
|
241
|
+
--skill-version "$SKILL_VERSION" \
|
|
242
|
+
--execution-time-ms "$EXECUTION_TIME" \
|
|
243
|
+
--exit-code "${exit_code:-0}" \
|
|
244
|
+
--tokens-avoided "$TOKENS_AVOIDED" \
|
|
245
|
+
--task-description "$*"
|
|
246
|
+
|
|
247
|
+
exit ${exit_code:-0}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Pattern 2: Post-Execution Hook
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
# .claude/hooks/cfn-cost-tracking.sh
|
|
254
|
+
#!/usr/bin/env bash
|
|
255
|
+
set -euo pipefail
|
|
256
|
+
|
|
257
|
+
SKILL_NAME="$1"
|
|
258
|
+
SKILL_VERSION="$2"
|
|
259
|
+
EXECUTION_TIME_MS="$3"
|
|
260
|
+
EXIT_CODE="$4"
|
|
261
|
+
TOKENS_AVOIDED="${5:-3000}"
|
|
262
|
+
|
|
263
|
+
/path/to/track-cost-savings.sh --action log \
|
|
264
|
+
--skill-name "$SKILL_NAME" \
|
|
265
|
+
--skill-version "$SKILL_VERSION" \
|
|
266
|
+
--execution-time-ms "$EXECUTION_TIME_MS" \
|
|
267
|
+
--exit-code "$EXIT_CODE" \
|
|
268
|
+
--tokens-avoided "$TOKENS_AVOIDED"
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Pattern 3: Agent Integration with Dynamic Token Calculation
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
# Within agent execution
|
|
275
|
+
track_skill_execution() {
|
|
276
|
+
local skill_name="$1"
|
|
277
|
+
local skill_version="$2"
|
|
278
|
+
local execution_time_ms="$3"
|
|
279
|
+
local exit_code="$4"
|
|
280
|
+
local task_complexity="${5:-medium}" # low, medium, high
|
|
281
|
+
|
|
282
|
+
# Dynamic token estimation based on task complexity
|
|
283
|
+
local tokens_avoided
|
|
284
|
+
case "$task_complexity" in
|
|
285
|
+
low) tokens_avoided=1500 ;;
|
|
286
|
+
medium) tokens_avoided=3000 ;;
|
|
287
|
+
high) tokens_avoided=6000 ;;
|
|
288
|
+
*) tokens_avoided=3000 ;;
|
|
289
|
+
esac
|
|
290
|
+
|
|
291
|
+
track-cost-savings.sh --action log \
|
|
292
|
+
--skill-name "$skill_name" \
|
|
293
|
+
--skill-version "$skill_version" \
|
|
294
|
+
--execution-time-ms "$execution_time_ms" \
|
|
295
|
+
--exit-code "$exit_code" \
|
|
296
|
+
--tokens-avoided "$tokens_avoided" \
|
|
297
|
+
--agent-type "$AGENT_TYPE" \
|
|
298
|
+
--metadata "{\"task_complexity\": \"$task_complexity\"}"
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### Pattern 4: Batch Execution Tracking
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
# Track multiple skill executions in a workflow
|
|
306
|
+
track_workflow_execution() {
|
|
307
|
+
local workflow_name="$1"
|
|
308
|
+
shift
|
|
309
|
+
local skills=("$@")
|
|
310
|
+
|
|
311
|
+
local total_time=0
|
|
312
|
+
local total_tokens=0
|
|
313
|
+
local exit_code=0
|
|
314
|
+
|
|
315
|
+
for skill in "${skills[@]}"; do
|
|
316
|
+
START=$(date +%s%3N)
|
|
317
|
+
execute_skill "$skill" || exit_code=$?
|
|
318
|
+
END=$(date +%s%3N)
|
|
319
|
+
|
|
320
|
+
EXEC_TIME=$((END - START))
|
|
321
|
+
total_time=$((total_time + EXEC_TIME))
|
|
322
|
+
total_tokens=$((total_tokens + 3000))
|
|
323
|
+
|
|
324
|
+
track-cost-savings.sh --action log \
|
|
325
|
+
--skill-name "$skill" \
|
|
326
|
+
--skill-version "1.0.0" \
|
|
327
|
+
--execution-time-ms "$EXEC_TIME" \
|
|
328
|
+
--exit-code "$exit_code" \
|
|
329
|
+
--tokens-avoided 3000
|
|
330
|
+
done
|
|
331
|
+
|
|
332
|
+
echo "Workflow: $workflow_name"
|
|
333
|
+
echo "Total time: ${total_time}ms"
|
|
334
|
+
echo "Total tokens avoided: $total_tokens"
|
|
335
|
+
echo "Total cost saved: \$$(echo "scale=6; ($total_tokens * 0.50) / 1000000" | bc)"
|
|
336
|
+
}
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## ROI Analysis
|
|
340
|
+
|
|
341
|
+
### Per-Skill Performance
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# Top 10 skills by total savings
|
|
345
|
+
sqlite3 workflow-codification.db "
|
|
346
|
+
SELECT
|
|
347
|
+
skill_name,
|
|
348
|
+
COUNT(*) as executions,
|
|
349
|
+
SUM(cost_avoided_usd) as total_savings,
|
|
350
|
+
AVG(execution_time_ms) as avg_time_ms
|
|
351
|
+
FROM skill_executions
|
|
352
|
+
GROUP BY skill_name
|
|
353
|
+
ORDER BY total_savings DESC
|
|
354
|
+
LIMIT 10;
|
|
355
|
+
"
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Daily Trend Analysis
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
# Cost savings trend over last 30 days
|
|
362
|
+
sqlite3 workflow-codification.db "
|
|
363
|
+
SELECT
|
|
364
|
+
date(timestamp) as date,
|
|
365
|
+
COUNT(*) as executions,
|
|
366
|
+
SUM(cost_avoided_usd) as daily_savings,
|
|
367
|
+
AVG(execution_time_ms) as avg_time_ms
|
|
368
|
+
FROM skill_executions
|
|
369
|
+
WHERE timestamp >= datetime('now', '-30 days')
|
|
370
|
+
GROUP BY date(timestamp)
|
|
371
|
+
ORDER BY date;
|
|
372
|
+
"
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Success Rate Analysis
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
# Success rate by skill
|
|
379
|
+
sqlite3 workflow-codification.db "
|
|
380
|
+
SELECT
|
|
381
|
+
skill_name,
|
|
382
|
+
COUNT(*) as total_executions,
|
|
383
|
+
SUM(CASE WHEN exit_code = 0 THEN 1 ELSE 0 END) as successful,
|
|
384
|
+
CAST(SUM(CASE WHEN exit_code = 0 THEN 1 ELSE 0 END) AS REAL) / COUNT(*) as success_rate
|
|
385
|
+
FROM skill_executions
|
|
386
|
+
GROUP BY skill_name
|
|
387
|
+
ORDER BY success_rate DESC;
|
|
388
|
+
"
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Time-to-Value Calculation
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# Average execution time by skill
|
|
395
|
+
sqlite3 workflow-codification.db "
|
|
396
|
+
SELECT
|
|
397
|
+
skill_name,
|
|
398
|
+
AVG(execution_time_ms) as avg_time_ms,
|
|
399
|
+
MIN(execution_time_ms) as min_time_ms,
|
|
400
|
+
MAX(execution_time_ms) as max_time_ms,
|
|
401
|
+
COUNT(*) as sample_size
|
|
402
|
+
FROM skill_executions
|
|
403
|
+
WHERE exit_code = 0
|
|
404
|
+
GROUP BY skill_name
|
|
405
|
+
ORDER BY avg_time_ms ASC;
|
|
406
|
+
"
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
## Cost Comparison by Provider
|
|
410
|
+
|
|
411
|
+
### Z.ai (glm-4.6) - Default
|
|
412
|
+
|
|
413
|
+
```
|
|
414
|
+
Input: $0.50 / 1M tokens
|
|
415
|
+
Output: $0.50 / 1M tokens
|
|
416
|
+
Average cost per skill execution: $0.0015
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Anthropic (Claude Sonnet 4.5)
|
|
420
|
+
|
|
421
|
+
```
|
|
422
|
+
Input: $3.00 / 1M tokens
|
|
423
|
+
Output: $15.00 / 1M tokens
|
|
424
|
+
Average cost per skill execution: $0.021
|
|
425
|
+
Savings vs script: $0.0209 per execution
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### OpenRouter (Various Models)
|
|
429
|
+
|
|
430
|
+
```
|
|
431
|
+
Varies by model selection
|
|
432
|
+
Typical range: $0.002 - $0.030 per execution
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
## Dashboard Metrics
|
|
436
|
+
|
|
437
|
+
### Key Performance Indicators
|
|
438
|
+
|
|
439
|
+
1. **Total Executions** - Cumulative skill usage
|
|
440
|
+
2. **Total Cost Avoided** - Aggregate savings (USD)
|
|
441
|
+
3. **Average Execution Time** - Performance metric (ms)
|
|
442
|
+
4. **Success Rate** - Reliability metric (0-1)
|
|
443
|
+
5. **Top Performing Skills** - Highest ROI contributors
|
|
444
|
+
|
|
445
|
+
### Visualization Recommendations
|
|
446
|
+
|
|
447
|
+
#### Time Series Chart
|
|
448
|
+
- X-axis: Date
|
|
449
|
+
- Y-axis: Daily cost savings (USD)
|
|
450
|
+
- Line chart showing 30-day trend
|
|
451
|
+
|
|
452
|
+
#### Bar Chart - Top Skills
|
|
453
|
+
- X-axis: Skill name
|
|
454
|
+
- Y-axis: Total savings (USD)
|
|
455
|
+
- Top 10 skills by ROI
|
|
456
|
+
|
|
457
|
+
#### Pie Chart - Execution Distribution
|
|
458
|
+
- Segments: Skill categories
|
|
459
|
+
- Values: Execution count percentage
|
|
460
|
+
|
|
461
|
+
#### Gauge - Monthly Savings
|
|
462
|
+
- Current: Month-to-date savings
|
|
463
|
+
- Target: Projected monthly savings
|
|
464
|
+
- Max: Theoretical maximum (if all tasks automated)
|
|
465
|
+
|
|
466
|
+
## Automated Reporting
|
|
467
|
+
|
|
468
|
+
### Daily Snapshot Cron Job
|
|
469
|
+
|
|
470
|
+
```bash
|
|
471
|
+
# Add to crontab: Daily at 11:59 PM
|
|
472
|
+
59 23 * * * /path/to/track-cost-savings.sh --action snapshot >> /var/log/roi-snapshots.log 2>&1
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### Weekly Report Email
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
#!/usr/bin/env bash
|
|
479
|
+
# weekly-roi-report.sh
|
|
480
|
+
|
|
481
|
+
REPORT=$(cat <<REPORT
|
|
482
|
+
CFN Skills - Weekly ROI Report
|
|
483
|
+
==============================
|
|
484
|
+
Period: $(date -d '7 days ago' +%Y-%m-%d) to $(date +%Y-%m-%d)
|
|
485
|
+
|
|
486
|
+
$(track-cost-savings.sh --action ranking --period 7)
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
$(track-cost-savings.sh --action projections --period 7)
|
|
491
|
+
|
|
492
|
+
---
|
|
493
|
+
|
|
494
|
+
Dashboard: $(track-cost-savings.sh --action dashboard --format json)
|
|
495
|
+
REPORT
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
echo "$REPORT" | mail -s "CFN Skills Weekly ROI Report" team@example.com
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### Monthly Executive Summary
|
|
502
|
+
|
|
503
|
+
```bash
|
|
504
|
+
#!/usr/bin/env bash
|
|
505
|
+
# monthly-executive-summary.sh
|
|
506
|
+
|
|
507
|
+
MONTH=$(date +%Y-%m)
|
|
508
|
+
|
|
509
|
+
cat <<SUMMARY
|
|
510
|
+
Executive Summary - CFN Skills ROI
|
|
511
|
+
Month: $MONTH
|
|
512
|
+
===================================
|
|
513
|
+
|
|
514
|
+
Total Savings: \$$(sqlite3 workflow-codification.db "SELECT SUM(cost_avoided_usd) FROM skill_executions WHERE strftime('%Y-%m', timestamp) = '$MONTH';")
|
|
515
|
+
|
|
516
|
+
Total Executions: $(sqlite3 workflow-codification.db "SELECT COUNT(*) FROM skill_executions WHERE strftime('%Y-%m', timestamp) = '$MONTH';")
|
|
517
|
+
|
|
518
|
+
Top 5 Skills:
|
|
519
|
+
$(sqlite3 -header workflow-codification.db "SELECT skill_name, SUM(cost_avoided_usd) as savings FROM skill_executions WHERE strftime('%Y-%m', timestamp) = '$MONTH' GROUP BY skill_name ORDER BY savings DESC LIMIT 5;")
|
|
520
|
+
|
|
521
|
+
Annual Projection: \$$(track-cost-savings.sh --action projections --period 30 | grep "Annual Projection" -A1 | tail -1 | awk '{print $3}')
|
|
522
|
+
SUMMARY
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
## Token Estimation Strategies
|
|
526
|
+
|
|
527
|
+
### Static Estimation (Default)
|
|
528
|
+
|
|
529
|
+
```bash
|
|
530
|
+
tokens_avoided=3000 # Fixed value
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
**Pros:** Simple, consistent
|
|
534
|
+
**Cons:** May not reflect actual complexity
|
|
535
|
+
|
|
536
|
+
### Dynamic Estimation by Task Type
|
|
537
|
+
|
|
538
|
+
```bash
|
|
539
|
+
case "$task_type" in
|
|
540
|
+
coordination) tokens_avoided=2000 ;;
|
|
541
|
+
implementation) tokens_avoided=5000 ;;
|
|
542
|
+
validation) tokens_avoided=1500 ;;
|
|
543
|
+
documentation) tokens_avoided=4000 ;;
|
|
544
|
+
esac
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
### Historical Average
|
|
548
|
+
|
|
549
|
+
```bash
|
|
550
|
+
# Calculate average tokens for similar tasks
|
|
551
|
+
tokens_avoided=$(sqlite3 workflow-codification.db "
|
|
552
|
+
SELECT AVG(tokens_avoided)
|
|
553
|
+
FROM skill_executions
|
|
554
|
+
WHERE skill_name = '$SKILL_NAME'
|
|
555
|
+
AND exit_code = 0
|
|
556
|
+
LIMIT 100;
|
|
557
|
+
")
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
### Input-Based Estimation
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
# Estimate based on input parameter count
|
|
564
|
+
param_count=$(echo "$INPUT_PARAMS" | wc -w)
|
|
565
|
+
tokens_avoided=$((param_count * 300 + 1500)) # 300 tokens per param + base
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
## Best Practices
|
|
569
|
+
|
|
570
|
+
### 1. Track All Executions
|
|
571
|
+
Log both successful and failed executions for accurate ROI calculation.
|
|
572
|
+
|
|
573
|
+
### 2. Use Realistic Token Estimates
|
|
574
|
+
Calibrate token estimates based on actual AI agent usage patterns.
|
|
575
|
+
|
|
576
|
+
### 3. Generate Daily Snapshots
|
|
577
|
+
Automated daily snapshots enable trend analysis and forecasting.
|
|
578
|
+
|
|
579
|
+
### 4. Review ROI Rankings Weekly
|
|
580
|
+
Identify low-ROI skills for optimization or retirement.
|
|
581
|
+
|
|
582
|
+
### 5. Include Execution Context
|
|
583
|
+
Store agent_type and task_description for detailed analysis.
|
|
584
|
+
|
|
585
|
+
### 6. Monitor Success Rates
|
|
586
|
+
Track exit codes to correlate ROI with reliability.
|
|
587
|
+
|
|
588
|
+
## Troubleshooting
|
|
589
|
+
|
|
590
|
+
### Issue: Negative Cost Savings
|
|
591
|
+
**Cause:** Script cost exceeds AI cost (rare edge case)
|
|
592
|
+
**Solution:** Review token estimates, ensure using correct provider pricing
|
|
593
|
+
|
|
594
|
+
### Issue: Inconsistent Execution Times
|
|
595
|
+
**Cause:** Variable system load or network latency
|
|
596
|
+
**Solution:** Calculate median instead of mean for more stable metrics
|
|
597
|
+
|
|
598
|
+
### Issue: Missing Snapshots
|
|
599
|
+
**Cause:** Cron job failure or database lock
|
|
600
|
+
**Solution:** Check cron logs, implement retry logic
|
|
601
|
+
|
|
602
|
+
## Security Considerations
|
|
603
|
+
|
|
604
|
+
### Sensitive Task Descriptions
|
|
605
|
+
- **Risk:** Task descriptions may contain confidential information
|
|
606
|
+
- **Mitigation:** Sanitize descriptions before storage
|
|
607
|
+
|
|
608
|
+
### Database Access Control
|
|
609
|
+
- **Risk:** Unauthorized access to cost data
|
|
610
|
+
- **Mitigation:** Set file permissions to 600, use encryption at rest
|
|
611
|
+
|
|
612
|
+
### Data Retention
|
|
613
|
+
- **Risk:** Excessive historical data storage
|
|
614
|
+
- **Mitigation:** Implement retention policy (e.g., 90 days detail, annual summaries)
|
|
615
|
+
|
|
616
|
+
## Environment Variables
|
|
617
|
+
|
|
618
|
+
- `DB_PATH` - Database location (default: `./workflow-codification.db`)
|
|
619
|
+
- `AI_COST_PER_MILLION` - AI provider cost (default: 0.50)
|
|
620
|
+
- `SCRIPT_COST` - Script execution cost (default: 0.0001)
|
|
621
|
+
- `AVG_AI_INPUT_TOKENS` - Average input tokens (default: 2000)
|
|
622
|
+
- `AVG_AI_OUTPUT_TOKENS` - Average output tokens (default: 1000)
|
|
623
|
+
|
|
624
|
+
## Dependencies
|
|
625
|
+
|
|
626
|
+
- `bash` ≥4.0
|
|
627
|
+
- `sqlite3` ≥3.0
|
|
628
|
+
- `coreutils` (date, bc)
|
|
629
|
+
|
|
630
|
+
## Version History
|
|
631
|
+
|
|
632
|
+
- **v1.0.0** (2025-11-15) - Initial implementation
|
|
633
|
+
- Execution logging
|
|
634
|
+
- ROI snapshot generation
|
|
635
|
+
- Per-skill ranking
|
|
636
|
+
- Monthly/annual projections
|
|
637
|
+
- Dashboard metrics export
|