specweave 0.23.18 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/.claude-plugin/marketplace.json +93 -49
  2. package/CLAUDE.md +137 -4
  3. package/dist/src/cli/helpers/ado-area-path-mapper.d.ts +89 -0
  4. package/dist/src/cli/helpers/ado-area-path-mapper.d.ts.map +1 -0
  5. package/dist/src/cli/helpers/ado-area-path-mapper.js +213 -0
  6. package/dist/src/cli/helpers/ado-area-path-mapper.js.map +1 -0
  7. package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.d.ts +29 -0
  8. package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.d.ts.map +1 -0
  9. package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.js +109 -0
  10. package/dist/src/cli/helpers/issue-tracker/ado-auto-discover.js.map +1 -0
  11. package/dist/src/cli/helpers/issue-tracker/ado.d.ts +1 -0
  12. package/dist/src/cli/helpers/issue-tracker/ado.d.ts.map +1 -1
  13. package/dist/src/cli/helpers/issue-tracker/ado.js +2 -0
  14. package/dist/src/cli/helpers/issue-tracker/ado.js.map +1 -1
  15. package/dist/src/cli/helpers/smart-filter.d.ts +83 -0
  16. package/dist/src/cli/helpers/smart-filter.d.ts.map +1 -0
  17. package/dist/src/cli/helpers/smart-filter.js +265 -0
  18. package/dist/src/cli/helpers/smart-filter.js.map +1 -0
  19. package/dist/src/core/qa/quality-gate-decider.d.ts +1 -1
  20. package/dist/src/core/qa/quality-gate-decider.js +2 -2
  21. package/dist/src/core/qa/quality-gate-decider.js.map +1 -1
  22. package/dist/src/core/qa/risk-calculator.d.ts +2 -2
  23. package/dist/src/core/qa/risk-calculator.js +2 -2
  24. package/dist/src/core/validators/ac-presence-validator.d.ts +56 -0
  25. package/dist/src/core/validators/ac-presence-validator.d.ts.map +1 -0
  26. package/dist/src/core/validators/ac-presence-validator.js +149 -0
  27. package/dist/src/core/validators/ac-presence-validator.js.map +1 -0
  28. package/dist/src/integrations/ado/area-path-mapper.d.ts +137 -0
  29. package/dist/src/integrations/ado/area-path-mapper.d.ts.map +1 -0
  30. package/dist/src/integrations/ado/area-path-mapper.js +267 -0
  31. package/dist/src/integrations/ado/area-path-mapper.js.map +1 -0
  32. package/dist/src/integrations/jira/filter-processor.d.ts +126 -0
  33. package/dist/src/integrations/jira/filter-processor.d.ts.map +1 -0
  34. package/dist/src/integrations/jira/filter-processor.js +207 -0
  35. package/dist/src/integrations/jira/filter-processor.js.map +1 -0
  36. package/dist/src/integrations/jira/jira-client.d.ts +13 -0
  37. package/dist/src/integrations/jira/jira-client.d.ts.map +1 -1
  38. package/dist/src/integrations/jira/jira-client.js +33 -0
  39. package/dist/src/integrations/jira/jira-client.js.map +1 -1
  40. package/dist/src/utils/ac-embedder.d.ts +63 -0
  41. package/dist/src/utils/ac-embedder.d.ts.map +1 -0
  42. package/dist/src/utils/ac-embedder.js +217 -0
  43. package/dist/src/utils/ac-embedder.js.map +1 -0
  44. package/dist/src/utils/env-manager.d.ts +86 -0
  45. package/dist/src/utils/env-manager.d.ts.map +1 -0
  46. package/dist/src/utils/env-manager.js +188 -0
  47. package/dist/src/utils/env-manager.js.map +1 -0
  48. package/package.json +1 -1
  49. package/plugins/specweave/.claude-plugin/plugin.json +1 -1
  50. package/plugins/specweave/agents/AGENTS-INDEX.md +1 -1
  51. package/plugins/specweave/agents/increment-quality-judge-v2/AGENT.md +9 -9
  52. package/plugins/specweave/commands/specweave-do.md +37 -0
  53. package/plugins/specweave/commands/specweave-done.md +159 -0
  54. package/plugins/specweave/commands/specweave-embed-acs.md +446 -0
  55. package/plugins/specweave/commands/specweave-next.md +148 -3
  56. package/plugins/specweave/commands/specweave-qa.md +2 -2
  57. package/plugins/specweave/hooks/pre-increment-start.sh +168 -0
  58. package/plugins/specweave/skills/SKILLS-INDEX.md +1 -1
  59. package/plugins/specweave-ado/.claude-plugin/plugin.json +1 -1
  60. package/plugins/specweave-ado/commands/specweave-ado-import-projects.md +331 -0
  61. package/plugins/specweave-alternatives/.claude-plugin/plugin.json +10 -0
  62. package/plugins/specweave-alternatives/commands/alternatives-analyze.md +336 -0
  63. package/plugins/specweave-alternatives/skills/architecture-alternatives/SKILL.md +651 -0
  64. package/plugins/specweave-alternatives/skills/bmad-method/SKILL.md +420 -0
  65. package/plugins/specweave-alternatives/skills/spec-kit-expert/SKILL.md +487 -0
  66. package/plugins/specweave-backend/commands/api-scaffold.md +80 -0
  67. package/plugins/specweave-backend/commands/crud-generate.md +109 -0
  68. package/plugins/specweave-backend/commands/migration-generate.md +139 -0
  69. package/plugins/specweave-confluent/commands/connector-deploy.md +154 -0
  70. package/plugins/specweave-confluent/commands/ksqldb-query.md +179 -0
  71. package/plugins/specweave-confluent/commands/schema-register.md +123 -0
  72. package/plugins/specweave-core/.claude-plugin/plugin.json +21 -0
  73. package/plugins/specweave-core/commands/architecture-review.md +288 -0
  74. package/plugins/specweave-core/commands/code-review.md +213 -0
  75. package/plugins/specweave-core/commands/refactor-plan.md +249 -0
  76. package/plugins/specweave-core/skills/code-quality/SKILL.md +157 -0
  77. package/plugins/specweave-core/skills/design-patterns/SKILL.md +244 -0
  78. package/plugins/specweave-core/skills/software-architecture/SKILL.md +83 -0
  79. package/plugins/specweave-cost-optimizer/.claude-plugin/plugin.json +22 -0
  80. package/plugins/specweave-cost-optimizer/commands/cost-analyze.md +360 -0
  81. package/plugins/specweave-cost-optimizer/commands/cost-optimize.md +480 -0
  82. package/plugins/specweave-cost-optimizer/skills/aws-cost-expert/SKILL.md +416 -0
  83. package/plugins/specweave-cost-optimizer/skills/cloud-pricing/SKILL.md +325 -0
  84. package/plugins/specweave-cost-optimizer/skills/cost-optimization/SKILL.md +337 -0
  85. package/plugins/specweave-diagrams/.claude-plugin/plugin.json +1 -1
  86. package/plugins/specweave-diagrams/commands/diagrams-generate.md +168 -0
  87. package/plugins/specweave-docs/.claude-plugin/plugin.json +10 -0
  88. package/plugins/specweave-docs/commands/docs-generate.md +441 -0
  89. package/plugins/specweave-docs/commands/docs-init.md +334 -0
  90. package/plugins/specweave-docs/skills/docusaurus/SKILL.md +581 -0
  91. package/plugins/specweave-docs/skills/spec-driven-brainstorming/SKILL.md +689 -0
  92. package/plugins/specweave-docs/skills/technical-writing/SKILL.md +1039 -0
  93. package/plugins/specweave-docs-preview/.claude-plugin/plugin.json +1 -1
  94. package/plugins/specweave-figma/.claude-plugin/plugin.json +23 -0
  95. package/plugins/specweave-figma/commands/figma-import.md +690 -0
  96. package/plugins/specweave-figma/commands/figma-to-react.md +834 -0
  97. package/plugins/specweave-figma/commands/figma-tokens.md +815 -0
  98. package/plugins/specweave-frontend/.claude-plugin/plugin.json +21 -0
  99. package/plugins/specweave-frontend/agents/frontend-architect/AGENT.md +387 -0
  100. package/plugins/specweave-frontend/agents/frontend-architect/README.md +385 -0
  101. package/plugins/specweave-frontend/agents/frontend-architect/examples.md +590 -0
  102. package/plugins/specweave-frontend/agents/frontend-architect/templates/component-template.tsx +152 -0
  103. package/plugins/specweave-frontend/agents/frontend-architect/templates/hook-template.ts +311 -0
  104. package/plugins/specweave-frontend/agents/frontend-architect/templates/page-template.tsx +228 -0
  105. package/plugins/specweave-frontend/commands/component-generate.md +510 -0
  106. package/plugins/specweave-frontend/commands/design-system-init.md +494 -0
  107. package/plugins/specweave-frontend/commands/frontend-scaffold.md +207 -0
  108. package/plugins/specweave-frontend/commands/nextjs-setup.md +396 -0
  109. package/plugins/specweave-frontend/skills/design-system-architect/SKILL.md +278 -0
  110. package/plugins/specweave-frontend/skills/frontend/SKILL.md +420 -0
  111. package/plugins/specweave-frontend/skills/nextjs/SKILL.md +546 -0
  112. package/plugins/specweave-github/.claude-plugin/plugin.json +1 -1
  113. package/plugins/specweave-github/hooks/.specweave/logs/hooks-debug.log +194 -0
  114. package/plugins/specweave-infrastructure/.claude-plugin/plugin.json +1 -1
  115. package/plugins/specweave-jira/.claude-plugin/plugin.json +1 -1
  116. package/plugins/specweave-jira/commands/import-projects.js +183 -0
  117. package/plugins/specweave-jira/commands/import-projects.md +97 -0
  118. package/plugins/specweave-jira/commands/import-projects.ts +288 -0
  119. package/plugins/specweave-jira/commands/specweave-jira-import-projects.md +298 -0
  120. package/plugins/specweave-kafka/.claude-plugin/plugin.json +1 -1
  121. package/plugins/specweave-kafka-streams/.claude-plugin/plugin.json +1 -1
  122. package/plugins/specweave-kubernetes/commands/cluster-setup.md +262 -0
  123. package/plugins/specweave-kubernetes/commands/deployment-generate.md +242 -0
  124. package/plugins/specweave-kubernetes/commands/helm-scaffold.md +333 -0
  125. package/plugins/specweave-ml/.claude-plugin/plugin.json +1 -1
  126. package/plugins/specweave-mobile/commands/app-scaffold.md +233 -0
  127. package/plugins/specweave-mobile/commands/build-config.md +256 -0
  128. package/plugins/specweave-mobile/commands/screen-generate.md +289 -0
  129. package/plugins/specweave-n8n/.claude-plugin/plugin.json +1 -1
  130. package/plugins/specweave-plugin-dev/.claude-plugin/plugin.json +13 -12
  131. package/plugins/specweave-plugin-dev/commands/plugin-create.md +333 -0
  132. package/plugins/specweave-plugin-dev/commands/plugin-publish.md +339 -0
  133. package/plugins/specweave-plugin-dev/commands/plugin-test.md +293 -0
  134. package/plugins/specweave-plugin-dev/skills/claude-sdk/SKILL.md +162 -0
  135. package/plugins/specweave-plugin-dev/skills/marketplace-publishing/SKILL.md +263 -0
  136. package/plugins/specweave-plugin-dev/skills/plugin-development/SKILL.md +316 -0
  137. package/plugins/specweave-release/.claude-plugin/plugin.json +1 -1
  138. package/plugins/specweave-release/commands/specweave-release-npm.md +110 -0
  139. package/plugins/specweave-release/hooks/.specweave/logs/dora-tracking.log +168 -0
  140. package/plugins/specweave-testing/.claude-plugin/plugin.json +21 -0
  141. package/plugins/specweave-testing/agents/qa-engineer/AGENT.md +797 -0
  142. package/plugins/specweave-testing/agents/qa-engineer/README.md +443 -0
  143. package/plugins/specweave-testing/agents/qa-engineer/templates/playwright-e2e-test.ts +470 -0
  144. package/plugins/specweave-testing/agents/qa-engineer/templates/test-data-factory.ts +507 -0
  145. package/plugins/specweave-testing/agents/qa-engineer/templates/vitest-unit-test.ts +400 -0
  146. package/plugins/specweave-testing/agents/qa-engineer/test-strategies.md +726 -0
  147. package/plugins/specweave-testing/commands/e2e-setup.md +1081 -0
  148. package/plugins/specweave-testing/commands/test-coverage.md +979 -0
  149. package/plugins/specweave-testing/commands/test-generate.md +1156 -0
  150. package/plugins/specweave-testing/commands/test-init.md +409 -0
  151. package/plugins/specweave-testing/skills/e2e-playwright/SKILL.md +769 -0
  152. package/plugins/specweave-testing/skills/tdd-expert/SKILL.md +934 -0
  153. package/plugins/specweave-testing/skills/unit-testing-expert/SKILL.md +1011 -0
  154. package/plugins/specweave-tooling/.claude-plugin/plugin.json +22 -0
  155. package/plugins/specweave-tooling/commands/specweave-tooling-skill-create.md +691 -0
  156. package/plugins/specweave-tooling/commands/specweave-tooling-skill-package.md +751 -0
  157. package/plugins/specweave-tooling/commands/specweave-tooling-skill-validate.md +858 -0
  158. package/plugins/specweave-ui/.claude-plugin/plugin.json +10 -0
  159. package/plugins/specweave-ui/commands/ui-automate.md +199 -0
  160. package/plugins/specweave-ui/commands/ui-inspect.md +70 -0
  161. package/plugins/specweave-ui/skills/browser-automation/SKILL.md +314 -0
  162. package/plugins/specweave-ui/skills/ui-testing/SKILL.md +716 -0
  163. package/plugins/specweave-ui/skills/visual-regression/SKILL.md +728 -0
  164. package/plugins/specweave/commands/check-hooks.md +0 -257
  165. package/plugins/specweave/commands/specweave-archive-increments.md +0 -82
  166. package/plugins/specweave-plugin-dev/skills/plugin-expert/SKILL.md +0 -1231
  167. /package/plugins/specweave/{agents/code-reviewer.md → skills/code-reviewer/SKILL.md} +0 -0
@@ -0,0 +1,480 @@
1
+ # /specweave-cost-optimizer:cost-optimize
2
+
3
+ Implement cost optimization recommendations with automated resource modifications and savings plan purchases.
4
+
5
+ You are an expert cloud cost optimizer who safely implements cost-saving measures across AWS, Azure, and GCP.
6
+
7
+ ## Your Task
8
+
9
+ Implement cost optimization recommendations with safety checks, rollback plans, and cost tracking.
10
+
11
+ ### 1. Optimization Categories
12
+
13
+ **Immediate Actions (No Downtime)**:
14
+ - Terminate idle resources
15
+ - Delete orphaned resources (unattached EBS, old snapshots)
16
+ - Implement storage lifecycle policies
17
+ - Enable compression/deduplication
18
+ - Clean up unused security groups, load balancers
19
+
20
+ **Scheduled Actions (Maintenance Window)**:
21
+ - Right-size instances (resize down/up)
22
+ - Migrate to reserved instances
23
+ - Convert EBS types (gp2 → gp3)
24
+ - Database version upgrades
25
+
26
+ **Long-term Actions (Architecture Changes)**:
27
+ - Migrate to serverless
28
+ - Implement auto-scaling
29
+ - Multi-region optimization
30
+ - Spot/preemptible adoption
31
+
32
+ ### 2. Safety Framework
33
+
34
+ **Pre-optimization Checks**:
35
+ ```typescript
36
+ interface SafetyCheck {
37
+ resourceId: string;
38
+ checks: {
39
+ hasBackup: boolean;
40
+ hasMonitoring: boolean;
41
+ hasRollbackPlan: boolean;
42
+ impactAssessment: 'none' | 'low' | 'medium' | 'high';
43
+ stakeholderApproval: boolean;
44
+ };
45
+ canProceed: boolean;
46
+ blockers: string[];
47
+ }
48
+
49
+ // Example safety check
50
+ async function canOptimize(resource: Resource): Promise<SafetyCheck> {
51
+ const checks = {
52
+ hasBackup: await hasRecentBackup(resource),
53
+ hasMonitoring: await hasActiveAlarms(resource),
54
+ hasRollbackPlan: true, // Manual rollback documented
55
+ impactAssessment: assessImpact(resource),
56
+ stakeholderApproval: resource.tags.ApprovedForOptimization === 'true',
57
+ };
58
+
59
+ const blockers = [];
60
+ if (!checks.hasBackup) blockers.push('Missing backup');
61
+ if (!checks.hasMonitoring) blockers.push('No monitoring alarms');
62
+ if (checks.impactAssessment === 'high' && !checks.stakeholderApproval) {
63
+ blockers.push('Requires stakeholder approval');
64
+ }
65
+
66
+ return {
67
+ resourceId: resource.id,
68
+ checks,
69
+ canProceed: blockers.length === 0,
70
+ blockers,
71
+ };
72
+ }
73
+ ```
74
+
75
+ **Rollback Plans**:
76
+ ```typescript
77
+ interface RollbackPlan {
78
+ optimizationId: string;
79
+ originalState: any;
80
+ rollbackSteps: Array<{
81
+ action: string;
82
+ command: string;
83
+ estimatedTime: number;
84
+ }>;
85
+ rollbackWindow: number; // hours
86
+ contactInfo: string[];
87
+ }
88
+
89
+ // Example: EC2 instance resize rollback
90
+ const rollback: RollbackPlan = {
91
+ optimizationId: 'opt-001',
92
+ originalState: {
93
+ instanceType: 'c5.2xlarge',
94
+ instanceId: 'i-1234567890abcdef0',
95
+ },
96
+ rollbackSteps: [
97
+ {
98
+ action: 'Stop instance',
99
+ command: 'aws ec2 stop-instances --instance-ids i-1234567890abcdef0',
100
+ estimatedTime: 2,
101
+ },
102
+ {
103
+ action: 'Resize to original',
104
+ command: 'aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --instance-type c5.2xlarge',
105
+ estimatedTime: 1,
106
+ },
107
+ {
108
+ action: 'Start instance',
109
+ command: 'aws ec2 start-instances --instance-ids i-1234567890abcdef0',
110
+ estimatedTime: 3,
111
+ },
112
+ ],
113
+ rollbackWindow: 24,
114
+ contactInfo: ['oncall@example.com', 'platform-team@example.com'],
115
+ };
116
+ ```
117
+
118
+ ### 3. Optimization Actions
119
+
120
+ **Right-size EC2 Instance**:
121
+ ```bash
122
+ #!/bin/bash
123
+ # Right-size EC2 instance with safety checks
124
+
125
+ INSTANCE_ID="i-1234567890abcdef0"
126
+ NEW_TYPE="c5.xlarge"
127
+ OLD_TYPE=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].InstanceType' --output text)
128
+
129
+ # 1. Create AMI backup
130
+ echo "Creating backup AMI..."
131
+ AMI_ID=$(aws ec2 create-image --instance-id $INSTANCE_ID --name "backup-before-resize-$(date +%Y%m%d)" --no-reboot --output text)
132
+ echo "AMI created: $AMI_ID"
133
+
134
+ # 2. Wait for AMI to be available
135
+ aws ec2 wait image-available --image-ids $AMI_ID
136
+
137
+ # 3. Stop instance
138
+ echo "Stopping instance..."
139
+ aws ec2 stop-instances --instance-ids $INSTANCE_ID
140
+ aws ec2 wait instance-stopped --instance-ids $INSTANCE_ID
141
+
142
+ # 4. Modify instance type
143
+ echo "Resizing $OLD_TYPE -> $NEW_TYPE..."
144
+ aws ec2 modify-instance-attribute --instance-id $INSTANCE_ID --instance-type "{\"Value\":\"$NEW_TYPE\"}"
145
+
146
+ # 5. Start instance
147
+ echo "Starting instance..."
148
+ aws ec2 start-instances --instance-ids $INSTANCE_ID
149
+ aws ec2 wait instance-running --instance-ids $INSTANCE_ID
150
+
151
+ # 6. Health check
152
+ sleep 30
153
+ HEALTH=$(aws ec2 describe-instance-status --instance-ids $INSTANCE_ID --query 'InstanceStatuses[0].InstanceStatus.Status' --output text)
154
+
155
+ if [ "$HEALTH" = "ok" ]; then
156
+ echo "✅ Resize successful!"
157
+ else
158
+ echo "❌ Health check failed. Rolling back..."
159
+ # Rollback logic here
160
+ fi
161
+ ```
162
+
163
+ **Purchase Reserved Instances**:
164
+ ```typescript
165
+ interface RIPurchase {
166
+ instanceType: string;
167
+ count: number;
168
+ term: '1year' | '3year';
169
+ paymentOption: 'all-upfront' | 'partial-upfront' | 'no-upfront';
170
+ estimatedSavings: number;
171
+ breakEvenMonths: number;
172
+ }
173
+
174
+ // Example RI purchase decision
175
+ const riRecommendation: RIPurchase = {
176
+ instanceType: 't3.large',
177
+ count: 10, // Running 10 steady-state instances
178
+ term: '1year',
179
+ paymentOption: 'partial-upfront',
180
+ estimatedSavings: 3500, // $3,500/year
181
+ breakEvenMonths: 4,
182
+ };
183
+
184
+ // Purchase command
185
+ aws ec2 purchase-reserved-instances-offering \
186
+ --reserved-instances-offering-id <offering-id> \
187
+ --instance-count 10
188
+ ```
189
+
190
+ **Implement S3 Lifecycle Policy**:
191
+ ```typescript
192
+ const lifecyclePolicy = {
193
+ Rules: [
194
+ {
195
+ Id: 'Move old logs to Glacier',
196
+ Status: 'Enabled',
197
+ Filter: { Prefix: 'logs/' },
198
+ Transitions: [
199
+ {
200
+ Days: 30,
201
+ StorageClass: 'STANDARD_IA', // Infrequent Access after 30 days
202
+ },
203
+ {
204
+ Days: 90,
205
+ StorageClass: 'GLACIER', // Glacier after 90 days
206
+ },
207
+ {
208
+ Days: 365,
209
+ StorageClass: 'DEEP_ARCHIVE', // Deep Archive after 1 year
210
+ },
211
+ ],
212
+ Expiration: {
213
+ Days: 2555, // Delete after 7 years
214
+ },
215
+ },
216
+ {
217
+ Id: 'Delete incomplete multipart uploads',
218
+ Status: 'Enabled',
219
+ AbortIncompleteMultipartUpload: {
220
+ DaysAfterInitiation: 7,
221
+ },
222
+ },
223
+ ],
224
+ };
225
+
226
+ // Apply policy
227
+ aws s3api put-bucket-lifecycle-configuration \
228
+ --bucket my-bucket \
229
+ --lifecycle-configuration file://lifecycle-policy.json
230
+ ```
231
+
232
+ **Delete Orphaned Resources**:
233
+ ```bash
234
+ #!/bin/bash
235
+ # Find and delete orphaned EBS snapshots
236
+
237
+ echo "Finding orphaned snapshots..."
238
+
239
+ # Get all snapshots owned by account
240
+ SNAPSHOTS=$(aws ec2 describe-snapshots --owner-ids self --query 'Snapshots[*].[SnapshotId,Description,VolumeId,StartTime]' --output text)
241
+
242
+ # Check each snapshot
243
+ while IFS=$'\t' read -r SNAP_ID DESC VOL_ID START_TIME; do
244
+ # Check if source volume still exists
245
+ if ! aws ec2 describe-volumes --volume-ids "$VOL_ID" &>/dev/null; then
246
+ AGE_DAYS=$(( ($(date +%s) - $(date -d "$START_TIME" +%s)) / 86400 ))
247
+
248
+ if [ $AGE_DAYS -gt 90 ]; then
249
+ echo "Orphaned snapshot: $SNAP_ID (age: $AGE_DAYS days)"
250
+ echo " Description: $DESC"
251
+ echo " Volume: $VOL_ID (deleted)"
252
+
253
+ # Dry run (remove --dry-run to execute)
254
+ # aws ec2 delete-snapshot --snapshot-id "$SNAP_ID"
255
+ fi
256
+ fi
257
+ done <<< "$SNAPSHOTS"
258
+ ```
259
+
260
+ ### 4. Serverless Optimization
261
+
262
+ **Lambda Memory Optimization**:
263
+ ```typescript
264
+ // AWS Lambda Power Tuning
265
+ // Uses AWS Lambda Power Tuning tool to find optimal memory
266
+
267
+ interface PowerTuningResult {
268
+ functionName: string;
269
+ currentConfig: {
270
+ memory: number;
271
+ avgDuration: number;
272
+ avgCost: number;
273
+ };
274
+ optimalConfig: {
275
+ memory: number;
276
+ avgDuration: number;
277
+ avgCost: number;
278
+ };
279
+ savings: {
280
+ costReduction: number; // %
281
+ durationReduction: number; // %
282
+ monthlySavings: number; // $
283
+ };
284
+ }
285
+
286
+ // Example optimization
287
+ const result: PowerTuningResult = {
288
+ functionName: 'processImage',
289
+ currentConfig: {
290
+ memory: 1024, // MB
291
+ avgDuration: 3200, // ms
292
+ avgCost: 0.0000133, // per invocation
293
+ },
294
+ optimalConfig: {
295
+ memory: 2048, // More memory = faster CPU
296
+ avgDuration: 1800, // 44% faster
297
+ avgCost: 0.0000119, // 11% cheaper
298
+ },
299
+ savings: {
300
+ costReduction: 10.5,
301
+ durationReduction: 43.8,
302
+ monthlySavings: 142, // 1M invocations/month
303
+ },
304
+ };
305
+
306
+ // Apply optimization
307
+ aws lambda update-function-configuration \
308
+ --function-name processImage \
309
+ --memory-size 2048
310
+ ```
311
+
312
+ ### 5. Cost Tracking & Validation
313
+
314
+ **Pre/Post Optimization Comparison**:
315
+ ```typescript
316
+ interface OptimizationResult {
317
+ optimizationId: string;
318
+ implementationDate: Date;
319
+ resource: string;
320
+ action: string;
321
+ preOptimization: {
322
+ cost: number;
323
+ metrics: Record<string, number>;
324
+ };
325
+ postOptimization: {
326
+ cost: number;
327
+ metrics: Record<string, number>;
328
+ };
329
+ actualSavings: number;
330
+ projectedSavings: number;
331
+ varianceExplanation: string;
332
+ }
333
+
334
+ // Track for 30 days post-optimization
335
+ async function validateOptimization(optId: string): Promise<OptimizationResult> {
336
+ const baseline = await getCostBaseline(optId, 'before');
337
+ const current = await getCostBaseline(optId, 'after');
338
+
339
+ const actualSavings = baseline.cost - current.cost;
340
+ const variance = (actualSavings / projectedSavings - 1) * 100;
341
+
342
+ return {
343
+ optimizationId: optId,
344
+ implementationDate: new Date('2025-01-15'),
345
+ resource: 'i-1234567890abcdef0',
346
+ action: 'Right-size: c5.2xlarge → c5.xlarge',
347
+ preOptimization: baseline,
348
+ postOptimization: current,
349
+ actualSavings,
350
+ projectedSavings: 145,
351
+ varianceExplanation: variance > 10
352
+ ? 'Higher traffic than baseline period'
353
+ : 'Within expected range',
354
+ };
355
+ }
356
+ ```
357
+
358
+ ### 6. Automation Scripts
359
+
360
+ **Auto-Stop Dev/Test Instances**:
361
+ ```typescript
362
+ // Lambda function to auto-stop instances outside business hours
363
+ export async function autoStopDevInstances() {
364
+ const now = new Date();
365
+ const hour = now.getHours();
366
+ const day = now.getDay();
367
+
368
+ // Outside business hours (6pm-8am weekdays, all weekend)
369
+ const isOffHours = hour < 8 || hour >= 18 || day === 0 || day === 6;
370
+
371
+ if (!isOffHours) return;
372
+
373
+ // Find running dev/test instances
374
+ const instances = await ec2.describeInstances({
375
+ Filters: [
376
+ { Name: 'tag:Environment', Values: ['dev', 'test'] },
377
+ { Name: 'instance-state-name', Values: ['running'] },
378
+ { Name: 'tag:AutoStop', Values: ['true'] },
379
+ ],
380
+ }).promise();
381
+
382
+ const instanceIds = instances.Reservations
383
+ .flatMap(r => r.Instances || [])
384
+ .map(i => i.InstanceId!);
385
+
386
+ if (instanceIds.length > 0) {
387
+ await ec2.stopInstances({ InstanceIds: instanceIds }).promise();
388
+ console.log(`Stopped ${instanceIds.length} dev/test instances`);
389
+ }
390
+ }
391
+
392
+ // Schedule: Run every hour
393
+ // CloudWatch Events: cron(0 * * * ? *)
394
+ ```
395
+
396
+ ### 7. Optimization Dashboard
397
+
398
+ **Cost Savings Dashboard**:
399
+ ```typescript
400
+ interface SavingsDashboard {
401
+ period: string;
402
+ totalSavings: number;
403
+ savingsByCategory: {
404
+ compute: number;
405
+ storage: number;
406
+ database: number;
407
+ network: number;
408
+ other: number;
409
+ };
410
+ topOptimizations: Array<{
411
+ description: string;
412
+ savings: number;
413
+ status: 'completed' | 'in-progress' | 'planned';
414
+ }>;
415
+ roi: number;
416
+ }
417
+
418
+ // Monthly dashboard
419
+ const dashboard: SavingsDashboard = {
420
+ period: 'January 2025',
421
+ totalSavings: 12450,
422
+ savingsByCategory: {
423
+ compute: 6200,
424
+ storage: 1800,
425
+ database: 3500,
426
+ network: 750,
427
+ other: 200,
428
+ },
429
+ topOptimizations: [
430
+ {
431
+ description: 'Right-sized 32 EC2 instances',
432
+ savings: 4100,
433
+ status: 'completed',
434
+ },
435
+ {
436
+ description: 'Purchased 5 RDS Reserved Instances',
437
+ savings: 3500,
438
+ status: 'completed',
439
+ },
440
+ {
441
+ description: 'Terminated 15 idle instances',
442
+ savings: 2100,
443
+ status: 'completed',
444
+ },
445
+ ],
446
+ roi: 8.5, // Implementation time vs savings
447
+ };
448
+ ```
449
+
450
+ ## Workflow
451
+
452
+ 1. **Review Recommendations**: Prioritize by savings + effort
453
+ 2. **Safety Check**: Verify backups, monitoring, approvals
454
+ 3. **Create Rollback Plan**: Document restore steps
455
+ 4. **Implement Change**: Execute optimization (staged rollout)
456
+ 5. **Monitor Impact**: Track metrics for 24-48 hours
457
+ 6. **Validate Savings**: Compare actual vs projected costs
458
+ 7. **Document Results**: Update cost tracking dashboard
459
+
460
+ ## Example Usage
461
+
462
+ **User**: "Optimize our over-provisioned EC2 instances"
463
+
464
+ **Response**:
465
+ - Reviews 32 over-provisioned instances
466
+ - Creates safety checklist (backups, monitoring, approvals)
467
+ - Generates resize plan with rollback procedures
468
+ - Provides automated scripts for off-hours execution
469
+ - Sets up post-optimization monitoring
470
+ - Projects $4,100/month savings
471
+
472
+ ## When to Use
473
+
474
+ - Implementing cost analysis recommendations
475
+ - Emergency budget cuts
476
+ - Scheduled optimization sprints
477
+ - New architecture deployment
478
+ - Post-incident cost spike mitigation
479
+
480
+ Optimize cloud costs safely with automated tooling!