Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export function AgentHandoffProductPrompt({

<Flex align="center" gap="md">
<Button
busy={handoff.isPending}
disabled={copyDisabled}
icon={<IconCopy />}
variant="primary"
Expand Down
16 changes: 7 additions & 9 deletions static/app/components/agentHandoff/agentHandoffPrompt.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ describe('AgentHandoffPrompt', () => {
{organization}
);

expect(screen.getByRole('link', {name: 'See the full instructions'})).toHaveAttribute(
'href',
'https://sentry.io/agent-handoff.md'
);
expect(screen.getByText(/Read and follow/)).toHaveTextContent(
'Read and follow https://sentry-jest-tests.example.com/agent-handoff.md verbatim. Your handoff code is sntryh_****.'
);
Expand All @@ -70,7 +66,7 @@ describe('AgentHandoffPrompt', () => {
name: 'https://sentry-jest-tests.example.com/agent-handoff.md',
})
).toHaveAttribute('href', 'https://sentry-jest-tests.example.com/agent-handoff.md');
await userEvent.click(screen.getByRole('button', {name: 'Copy agent prompt'}));
await userEvent.click(screen.getByRole('button', {name: 'Copy prompt'}));

await waitFor(() => expect(onCopySuccess).toHaveBeenCalledTimes(1));
expect(onCopySuccess).toHaveBeenCalledWith(handoffId);
Expand Down Expand Up @@ -101,13 +97,15 @@ describe('AgentHandoffPrompt', () => {
{organization}
);

await userEvent.click(screen.getByRole('button', {name: 'Advanced options'}));
await userEvent.click(screen.getByRole('menuitemradio', {name: /Use IP pinning/}));
const ipPinning = screen.getByRole('checkbox', {name: /Only allow this network/});
expect(ipPinning).toBeChecked();
await userEvent.click(ipPinning);
expect(ipPinning).not.toBeChecked();

expect(
screen.getByText(/anyone with this prompt can use its handoff code/)
).toBeInTheDocument();
await userEvent.click(screen.getByRole('button', {name: 'Copy agent prompt'}));
await userEvent.click(screen.getByRole('button', {name: 'Copy prompt'}));

await waitFor(() =>
expect(mint).toHaveBeenCalledWith(
Expand Down Expand Up @@ -186,7 +184,7 @@ describe('AgentHandoffPrompt', () => {
{organization}
);

await userEvent.click(screen.getByRole('button', {name: 'Copy agent prompt'}));
await userEvent.click(screen.getByRole('button', {name: 'Copy prompt'}));

expect(
await screen.findByText('Unable to create your agent prompt. Try again.')
Expand Down
101 changes: 55 additions & 46 deletions static/app/components/agentHandoff/agentHandoffPrompt.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import {useId} from 'react';
import styled from '@emotion/styled';
import {IconCopy} from '@sentry/icons/copy';
import {IconOpen} from '@sentry/icons/open';
import {useStore} from 'zustand';

import {Button} from '@sentry/scraps/button';
import {Checkbox} from '@sentry/scraps/checkbox';
import {InfoTip} from '@sentry/scraps/info';
import {Flex, Stack} from '@sentry/scraps/layout';
import {ExternalLink} from '@sentry/scraps/link';
import {Text} from '@sentry/scraps/text';

import {FeedbackButton} from 'sentry/components/feedbackButton/feedbackButton';
import {t} from 'sentry/locale';
import {ConfigStore} from 'sentry/stores/configStore';

import {
getHandoffPreviewUrl,
HandoffAdvancedMenu,
HandoffPromptAlerts,
HandoffPromptBox,
} from './handoffPromptParts';
import {HandoffPromptAlerts, HandoffPromptBox} from './handoffPromptParts';
import {AgentHandoffFlow, type AgentHandoffContext} from './types';
import {useHandoffPromptCopy} from './useHandoffPromptCopy';

Expand All @@ -36,11 +31,10 @@ export function AgentHandoffPrompt<Flow extends AgentHandoffFlow>({
onCopySuccess,
onSelect,
}: AgentHandoffPromptProps<Flow>) {
const sentryUrl = useStore(ConfigStore, state => state.links.sentryUrl);
const previewUrl = getHandoffPreviewUrl(sentryUrl);

const {copyPrompt, copyDisabled, handoff, useIpPinning, toggleIpPinning} =
useHandoffPromptCopy({flow, context, onCopySuccess});
const ipPinningId = useId();
const ipPinningDescriptionId = useId();

return (
<Stack gap="md">
Expand All @@ -49,44 +43,59 @@ export function AgentHandoffPrompt<Flow extends AgentHandoffFlow>({
context={context}
onCopyPrompt={copyPrompt}
onSelect={onSelect}
topRightAction={
<Button
aria-label={t('Copy agent prompt')}
busy={handoff.isPending}
disabled={copyDisabled}
icon={<IconCopy />}
size="zero"
variant="transparent"
onClick={copyPrompt}
/>
}
size="md"
/>

<Flex align="center" justify="between" gap="lg">
<Text size="sm">
<ExternalLink href={previewUrl}>
<Flex as="span" align="center" gap="xs">
{t('See the full instructions')}
<IconOpen size="xs" />
</Flex>
</ExternalLink>
</Text>

<Flex align="center" gap="sm">
<FeedbackButton
size="xs"
feedbackOptions={{tags: {'feedback.source': feedbackSource}}}
/>

<HandoffAdvancedMenu
disabled={copyDisabled}
useIpPinning={useIpPinning}
onToggle={toggleIpPinning}
/>
</Flex>
<Flex align="start" gap="md" padding="xs 0">
<Checkbox
id={ipPinningId}
aria-describedby={ipPinningDescriptionId}
checked={useIpPinning}
disabled={copyDisabled}
onChange={toggleIpPinning}
/>
<Stack gap="sm">
<Flex align="center" gap="xs">
<Text as="label" htmlFor={ipPinningId} size="md">
{t('Only allow this network')}
</Text>
<InfoTip
size="xs"
title={t('Keeps your secret token safe if the prompt leaks.')}
/>
</Flex>
<Description id={ipPinningDescriptionId} size="sm" variant="muted">
{t(
'Uncheck if your agent runs in the cloud, or you use iCloud Private Relay.'
)}
</Description>
</Stack>
</Flex>

<HandoffPromptAlerts useIpPinning={useIpPinning} error={handoff.error} />

<Button
disabled={copyDisabled}
icon={<IconCopy />}
variant="primary"
onClick={copyPrompt}
>
{t('Copy prompt')}
</Button>

<Flex justify="end" paddingTop="xs">
<FeedbackButton
size="xs"
feedbackOptions={{tags: {'feedback.source': feedbackSource}}}
>
{t('Give feedback')}
</FeedbackButton>
</Flex>
</Stack>
);
}

// Help text reads best a little looser than the largest density token (1.4).
const Description = styled(Text)`
line-height: 1.5;
`;
51 changes: 31 additions & 20 deletions static/app/components/agentHandoff/handoffPromptParts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Fragment, useState, type PointerEventHandler, type ReactNode} from 'react';
import {css, ThemeProvider, type Theme} from '@emotion/react';
import {Fragment, useState, type PointerEventHandler} from 'react';
import {css, ThemeProvider, useTheme, type Theme} from '@emotion/react';
import styled from '@emotion/styled';
import {IconSettings} from '@sentry/icons/settings';
import {AnimatePresence, motion} from 'framer-motion';

import {Alert} from '@sentry/scraps/alert';
import {DropdownMenu} from '@sentry/scraps/dropdownMenu';
Expand Down Expand Up @@ -75,15 +76,30 @@ interface HandoffPromptAlertsProps {
}

export function HandoffPromptAlerts({useIpPinning, error}: HandoffPromptAlertsProps) {
const theme = useTheme();
// Both prompts render the alerts in a Stack with an md gap. Pulling the warning
// up by that gap while collapsed lets the gap animate with it instead of popping.
const collapsedOffset = `-${theme.space.md}`;

return (
<Fragment>
{!useIpPinning && (
<Alert variant="warning">
{t(
'Without IP pinning, anyone with this prompt can use its handoff code from any IP address to authorize an agent on your behalf. Avoid pasting your prompt when streaming or screen sharing.'
)}
</Alert>
)}
<AnimatePresence initial={false}>
{!useIpPinning && (
<motion.div
initial={{height: 0, opacity: 0, marginTop: collapsedOffset}}
animate={{height: 'auto', opacity: 1, marginTop: '0px'}}
exit={{height: 0, opacity: 0, marginTop: collapsedOffset}}
transition={{duration: 0.12, ease: 'easeOut'}}
style={{overflow: 'hidden'}}
>
<Alert variant="warning">
{t(
'Without IP pinning, anyone with this prompt can use its handoff code from any IP address to authorize an agent on your behalf. Avoid pasting your prompt when streaming or screen sharing.'
)}
</Alert>
</motion.div>
)}
</AnimatePresence>
{error && <Alert variant="danger">{error.message}</Alert>}
</Fragment>
);
Expand All @@ -94,15 +110,16 @@ interface HandoffPromptBoxProps<Flow extends AgentHandoffFlow> {
flow: Flow;
onCopyPrompt: () => void;
onSelect?: () => void;
topRightAction?: ReactNode;
/** `md` sets the prompt in larger, looser monospace text with roomier vertical padding. */
size?: 'sm' | 'md';
}

export function HandoffPromptBox<Flow extends AgentHandoffFlow>({
context,
flow,
onCopyPrompt,
onSelect,
topRightAction,
size = 'sm',
}: HandoffPromptBoxProps<Flow>) {
const [isPromptSelected, setIsPromptSelected] = useState(false);
const guideUrl = getHandoffGuideUrl();
Expand All @@ -125,17 +142,16 @@ export function HandoffPromptBox<Flow extends AgentHandoffFlow>({
background="primary"
border="primary"
radius="md"
padding="md xl"
paddingRight={topRightAction ? '3xl' : 'xl'}
position="relative"
padding={size === 'md' ? 'lg xl' : 'md xl'}
>
{promptBoxProps => (
<PromptBox {...promptBoxProps} onCopy={onCopy}>
<PromptText
ref={promptRef}
as="div"
monospace
size="sm"
size={size}
density={size === 'md' ? 'comfortable' : undefined}
tabIndex={tabIndex}
textWrap="wrap"
onBlur={() => setIsPromptSelected(false)}
Expand Down Expand Up @@ -163,11 +179,6 @@ export function HandoffPromptBox<Flow extends AgentHandoffFlow>({
),
})}
</PromptText>
{topRightAction && (
<Container position="absolute" top="8px" right="8px">
{topRightAction}
</Container>
)}
</PromptBox>
)}
</Container>
Expand Down
4 changes: 3 additions & 1 deletion static/app/components/agentHandoff/useHandoffPromptCopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export function useHandoffPromptCopy<Flow extends AgentHandoffFlow>({
}: UseHandoffPromptCopyOptions<Flow>) {
const [useIpPinning, setUseIpPinning] = useState(true);
const handoff = useAgentHandoff(flow, context);
const copyDisabled = !context || handoff.isPending;
// Minting the code is near-instant, so a busy or disabled state while it runs
// only flashes. copyPrompt ignores clicks until the request settles.
const copyDisabled = !context;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinning toggle races with in-flight copy

Medium Severity

copyDisabled no longer includes handoff.isPending, but the IP pinning checkbox and Advanced menu still use that same flag. Pinning can change while a mint is in flight. toggleIpPinning then calls handoff.reset(), which clears isPending while copyOperation still holds the original request, so a follow-up copy can reuse the old disableIpPinning value. The clipboard prompt can disagree with the pinning control and warning.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 349be71. Configure here.


function copyPrompt() {
if (handoff.isPending) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Fragment} from 'react';
import styled from '@emotion/styled';

import {Stack} from '@sentry/scraps/layout';
import {Heading, Text} from '@sentry/scraps/text';
import {Heading} from '@sentry/scraps/text';

import {AgentHandoffPrompt} from 'sentry/components/agentHandoff/agentHandoffPrompt';
import {AgentHandoffFlow} from 'sentry/components/agentHandoff/types';
Expand Down Expand Up @@ -29,19 +30,16 @@ export function AgentSetupCard({
}: AgentSetupCardProps) {
return (
<Fragment>
<Stack gap="2xs">
<Heading as="h3" size="lg">
{t('Let your agent set up Sentry')}
</Heading>
<Text as="p" size="lg" variant="secondary">
{t('Paste one prompt and your agent does the rest')}
</Text>
</Stack>

<Stack as="ul" role="list" gap="sm" padding="xl 0" margin="0">
<Benefit>{t('Detects your stack and installs the Sentry CLI')}</Benefit>
<Benefit>{t('Installs and configures the right SDKs')}</Benefit>
<Benefit>{t('Sends a test error to confirm it works')}</Benefit>
<Stack gap="xl" padding="xs 0 xl">
<CardHeading as="h3" size="xl">
{t('Set up Sentry using your coding agent')}
</CardHeading>

<Stack as="ul" role="list" gap="md" padding="0 0 sm" margin="0">
<Benefit size="lg">{t('Installs the Sentry CLI and signs you in')}</Benefit>
<Benefit size="lg">{t('Detects your stack and adds the right SDK')}</Benefit>
<Benefit size="lg">{t('Sends a test error so you can see it work')}</Benefit>
</Stack>
</Stack>

<AgentHandoffPrompt
Expand All @@ -54,3 +52,7 @@ export function AgentSetupCard({
</Fragment>
);
}

const CardHeading = styled(Heading)`
color: ${p => p.theme.tokens.content.headings};
`;
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ interface AgenticSetupProps {
onSetupInBrowser: () => void;
run: AgenticProgressRun | undefined;
handoffFlow?: AgentHandoffFlow;
/** Tilts the setup card and adds the stacked brand border and shadows. */
layered?: boolean;
/** Rendered at the end of the row under the progress list. */
metaAction?: React.ReactNode;
}
Expand All @@ -53,7 +51,6 @@ export function AgenticSetup({
onRefresh,
run,
handoffFlow = AgentHandoffFlow.ONBOARDING,
layered = false,
metaAction,
}: AgenticSetupProps) {
const showsProgress =
Expand Down Expand Up @@ -124,7 +121,7 @@ export function AgenticSetup({
exit={{opacity: 0}}
transition={CARD_MORPH_TRANSITION}
>
<SetupCardFrame layered={layered}>
<SetupCardFrame>
<AgentSetupCard
feedbackSource={feedbackSource}
flow={handoffFlow}
Expand Down
Loading
Loading