Skip to content

Commit 9e64eac

Browse files
committed
feat(sessions): gate per-task cost behind posthog-code-task-cost flag
Wrap the cost readout (indicator chip suffix and breakdown popover row) in a feature flag so it can roll out gradually. On in local dev via the import.meta.env.DEV fallback, matching the other UI flags. Generated-By: PostHog Code Task-Id: f6d673c3-965e-4598-a4bd-663f2651a5a5
1 parent ca67b12 commit 9e64eac

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

packages/shared/src/flags.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ export const GLM_MODEL_FLAG = "posthog-code-glm-model";
2121
export const SPOKEN_NARRATION_FLAG = "posthog-code-spoken-narration";
2222
// Gates importing and relaying local MCP servers into cloud task runs.
2323
export const LOCAL_MCP_IMPORT_FLAG = "posthog-code-local-mcp-import";
24+
/** Per-task estimated cost readout in the context usage indicator. */
25+
export const TASK_COST_FLAG = "posthog-code-task-cost";

packages/ui/src/features/sessions/components/ContextBreakdownPopover.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import { Flex, Text } from "@radix-ui/themes";
99

1010
interface ContextBreakdownPopoverProps {
1111
usage: ContextUsage;
12+
showCost?: boolean;
1213
}
1314

1415
export function ContextBreakdownPopover({
1516
usage,
17+
showCost = false,
1618
}: ContextBreakdownPopoverProps) {
1719
const { used, size, percentage, cost, breakdown } = usage;
1820
const fillColor = getOverallUsageColor(percentage);
@@ -73,7 +75,7 @@ export function ContextBreakdownPopover({
7375
</Text>
7476
)}
7577

76-
{cost && (
78+
{showCost && cost && (
7779
<Flex
7880
align="center"
7981
justify="between"

packages/ui/src/features/sessions/components/ContextUsageIndicator.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { TASK_COST_FLAG } from "@posthog/shared";
2+
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
13
import {
24
formatCostUsd,
35
formatTokensCompact,
@@ -17,6 +19,8 @@ interface ContextUsageIndicatorProps {
1719
}
1820

1921
export function ContextUsageIndicator({ usage }: ContextUsageIndicatorProps) {
22+
const costEnabled = useFeatureFlag(TASK_COST_FLAG) || import.meta.env.DEV;
23+
2024
if (!usage) return null;
2125

2226
const { used, size, percentage, cost } = usage;
@@ -25,10 +29,11 @@ export function ContextUsageIndicator({ usage }: ContextUsageIndicatorProps) {
2529
const hasSize = size > 0;
2630
const strokeDashoffset = CIRCUMFERENCE - (percentage / 100) * CIRCUMFERENCE;
2731
const color = getOverallUsageColor(percentage);
32+
const showCost = costEnabled && cost !== null;
2833
const tokenLabel = hasSize
2934
? `${formatTokensCompact(used)}/${formatTokensCompact(size)} · ${percentage}%`
3035
: formatTokensCompact(used);
31-
const label = cost
36+
const label = showCost
3237
? `${tokenLabel} · ${formatCostUsd(cost.amount)}`
3338
: tokenLabel;
3439

@@ -79,7 +84,7 @@ export function ContextUsageIndicator({ usage }: ContextUsageIndicatorProps) {
7984
</button>
8085
</Popover.Trigger>
8186
<Popover.Content size="2" side="top" align="end" sideOffset={6}>
82-
<ContextBreakdownPopover usage={usage} />
87+
<ContextBreakdownPopover usage={usage} showCost={showCost} />
8388
</Popover.Content>
8489
</Popover.Root>
8590
);

0 commit comments

Comments
 (0)