Skip to content

feat: AI spend solution with custom metrics, scorecard, and team plugin - #231

Merged
jeff-schnitter merged 43 commits into
mainfrom
worktree-cx-2-ai-spend-metrics
Aug 7, 2026
Merged

feat: AI spend solution with custom metrics, scorecard, and team plugin#231
jeff-schnitter merged 43 commits into
mainfrom
worktree-cx-2-ai-spend-metrics

Conversation

@jeff-schnitter

Copy link
Copy Markdown
Collaborator

Summary

  • Adds ai-spend solution: track per-employee Claude AI spend in Cortex using custom metrics with full team hierarchy rollup visibility
  • New employee entity type and team-member relationship type with sample org of 5 employees across 4 teams
  • sync-claude-spend.py script + GitHub Actions workflow to pull weekly spend from the Anthropic Analytics API and push to Cortex custom metrics with team rollups via DFS hierarchy walk
  • ai-spend-scorecard — bronze/silver/gold budget compliance scorecard using CQL against the ai-spend custom metric
  • team-ai-spend plugin — per-team spend visualization with budget-aware header card (green/red) and per-member bar chart
  • Extends backup import to support custom-metrics/ directories

Version

1.29.0 (minor bump — feat: commits)

Test plan

  • cortex solutions install -s ai-spend installs all resources cleanly
  • cortex solutions info -s ai-spend shows ASCII flow diagram
  • Plugin renders on team entity pages with correct spend and budget coloring
  • Scorecard evaluates bronze/silver/gold correctly per team budget
  • sync-claude-spend.py maps emails to entity tags and pushes team rollups

🤖 Generated with Claude Code

jeff-schnitter and others added 30 commits August 4, 2026 15:25
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add YAML frontmatter, diagram code block, and After Installing section
so solutions install Data Model and Next steps menu options work correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add ai-spend-scorecard with bronze/silver/gold budget compliance tiers
  (bronze = tracking, silver = within 125% of budget, gold = under budget)
- Add ai-budget-weekly and ai-spend-weekly custom data to team catalog entities
  (platform=$480, frontend=$360, data=$280, engineering=$1100 budgets)
- Add team rollup entries (8 weeks) to ai-spend.json sample data
- Update sync script to walk team-member hierarchy (DFS) and write both
  ai-spend custom metric and ai-spend-weekly custom data on team entities
- Update README with scorecard docs, budget CLI command, and updated diagram

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace custom("ai-spend-weekly") metadata approach with:
  customMetrics(key="ai-spend", lookback=duration("P8D")).map((m) => m.value).average()

The time-series custom metric is the source of truth for both trending
and budget compliance — no separate custom data key needed for spend.
Also removes push_custom_data from sync script and ai-spend-weekly from
team YAML catalog files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace direct employee filter with DFS adjacency-map walk so the plugin
correctly resolves sub-teams (e.g. team-engineering → team-platform →
employee-alice-chen) instead of only showing direct employee members.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
jeff-schnitter and others added 13 commits August 6, 2026 16:54
The Cortex relationships API returns a non-standard type value for custom
entity types so checking dst.type === 'employee' is unreliable. Instead,
nodes with outgoing team-member relationships are sub-teams; nodes without
are leaf employees.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ctx.tag is the plugin's own tag; ctx.entity.tag is the entity being viewed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The custom metrics GET endpoint returns { data: [...] }, not { values: [...] }.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Total card: green when under budget, red when over, purple when no budget set
- Bar chart: stacked green/red split at budget threshold per member
- Dashed vertical budget line with label drawn via custom Chart.js plugin
- Falls back to original purple chart when no ai-budget-weekly is set

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Switch afterDraw to afterDatasetsDraw so line renders on top of bars
- Set suggestedMax to max(budget, maxSpend)*1.1 so budget line is always
  within the visible x-axis range (was off-screen when all spend < budget)
- Remove bounds guard that was hiding the line
- Green bars match total card color (#16a34a); red bars match (#dc2626)
- Tooltip: hover green shows "Budget: $X/wk", hover red shows "Over by: +$X"
- interaction mode: nearest+intersect so each segment tooltips independently
- filter: raw > 0 hides phantom tooltip on zero-value overflow segments

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jeff-schnitter
jeff-schnitter merged commit 451331a into main Aug 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant