Skip to content

feat(setup): spend-driven "Optimize your AI usage" discovered task#3212

Draft
vdekrijger wants to merge 3 commits into
mainfrom
posthog-code/optimize-ai-usage-suggestion
Draft

feat(setup): spend-driven "Optimize your AI usage" discovered task#3212
vdekrijger wants to merge 3 commits into
mainfrom
posthog-code/optimize-ai-usage-suggestion

Conversation

@vdekrijger

@vdekrijger vdekrijger commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Requested from a Slack thread: help users improve how they use PostHog Code itself — spot repeated work worth turning into skills, memory files worth tightening, and other ways to reduce token spend. An earlier revision of this PR added a static starter card to the channels new-task screen; a data-driven discovered task is more compelling because it only appears when there's a real win, with the user's own spend as evidence.

Changes

  • New ai_usage discovered-task category (enricher-only, like posthog_setup), rendered with a Gauge icon in cyan.
  • On each enricher pass, SetupRunService fetches the user's personal LLM spend analysis via a new getSpendAnalysis() port method (authenticated PostHog API client). When recent PostHog Code spend crosses a small threshold, it surfaces an "Optimize your AI usage" suggestion — quoting the user's own spend and the dominant tool hotspot as evidence.
  • The one-click prompt audits recent sessions for repeated workflows worth capturing as a skill, recurring questions better served by a scheduled scout/AI report, bloated or stale memory files, and under-specified prompts — delivering an impact-ranked report and offering to implement quick wins.
  • Spend-analysis failures are non-fatal: enrichment still completes and the suggestion is simply skipped.

How did you test this?

  • Added unit tests for buildAiUsageSuggestion (threshold gating, stable id, spend/window summary, hotspot line) and for the SetupRunService enricher path (suggestion added when spend is above threshold; enrichment completes when spend analysis throws).
  • packages/core full suite: 200 files, 2122 tests passing. Typecheck clean for @posthog/core, @posthog/ui, @posthog/shared. Biome lint clean (zero noRestrictedImports in core).

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog from a Slack thread

Add a starter-prompt card to CHANNEL_TASK_SUGGESTIONS that kicks off a
task to review recent agent/task usage and find efficiency improvements —
reusable skills, memory-file tuning, and token-cost reductions.

Generated-By: PostHog Code
Task-Id: e5484dae-c3c0-473b-a1ea-12f4cc3d9ab5
@trunk-io

trunk-io Bot commented Jul 7, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 1bdd45c.

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(canvas): add "Optimize your AI usag..." | Re-trigger Greptile

Name the concrete evidence to review (repeated workflows, recurring
questions, memory bloat, under-specified prompts), point each finding at
the right PostHog Code feature (skills, scouts, scheduled AI reports,
memory edits), and shape the deliverable: an impact-ranked report with
evidence and estimated savings, plus an offer to implement quick wins.

Generated-By: PostHog Code
Task-Id: e5484dae-c3c0-473b-a1ea-12f4cc3d9ab5
Replace the static channel starter card with a real enricher-produced
discovered task. On each enricher pass the setup orchestration fetches the
user's personal LLM spend analysis and, when recent PostHog Code spend
crosses a threshold, surfaces an "Optimize your AI usage" suggestion in the
new-task panel — including the dominant tool hotspot as evidence. The
one-click prompt audits recent sessions for skill-worthy repeated
workflows, memory-file bloat, and recurring questions better served by
scheduled reports.

Adds an ai_usage category (enricher-only, like posthog_setup), a
getSpendAnalysis port method implemented via the authenticated PostHog
API client, and unit tests for the builder and orchestration paths.

Generated-By: PostHog Code
Task-Id: e5484dae-c3c0-473b-a1ea-12f4cc3d9ab5
@vdekrijger vdekrijger changed the title feat(canvas): add "Optimize your AI usage" new-task suggestion feat(setup): spend-driven "Optimize your AI usage" discovered task Jul 7, 2026
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