Skip to content

Commit cdfaef1

Browse files
committed
add auto-fix pull requests toggle to loop form
1 parent 542dfab commit cdfaef1

3 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { LoopSchemas } from "@posthog/api-client/loops";
2+
import { Switch } from "@posthog/quill";
3+
import { Flex, Text } from "@radix-ui/themes";
4+
import { isAutoFixEnabled, withAutoFix } from "../loopFormTypes";
5+
6+
interface LoopBehaviorFieldsProps {
7+
behaviors: LoopSchemas.LoopBehaviors;
8+
onChange: (behaviors: LoopSchemas.LoopBehaviors) => void;
9+
disabled?: boolean;
10+
}
11+
12+
export function LoopBehaviorFields({
13+
behaviors,
14+
onChange,
15+
disabled,
16+
}: LoopBehaviorFieldsProps) {
17+
return (
18+
<Flex
19+
direction="column"
20+
gap="2"
21+
className="rounded-(--radius-2) border border-border bg-(--color-panel-solid) p-3"
22+
>
23+
<Flex align="center" justify="between" gap="2">
24+
<Flex direction="column" gap="0">
25+
<Text className="font-medium text-[13px] text-gray-12">
26+
Auto-fix pull requests
27+
</Text>
28+
<Text className="text-[12px] text-gray-10">
29+
Watch CI and review comments on PRs this loop opens, and let Claude
30+
push fixes.
31+
</Text>
32+
</Flex>
33+
<Switch
34+
checked={isAutoFixEnabled(behaviors)}
35+
disabled={disabled}
36+
aria-label="Auto-fix pull requests"
37+
onCheckedChange={(checked) =>
38+
onChange(withAutoFix(behaviors, checked))
39+
}
40+
/>
41+
</Flex>
42+
</Flex>
43+
);
44+
}

packages/ui/src/features/loops/components/LoopForm.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import { useLoopDraftStore } from "../loopDraftStore";
2121
import {
2222
emptyLoopFormValues,
2323
formValuesToLoopWrite,
24+
isAutoFixEnabled,
2425
isLoopFormValid,
2526
isTriggerDraftValid,
2627
type LoopFormValues,
2728
loopToFormValues,
2829
} from "../loopFormTypes";
30+
import { LoopBehaviorFields } from "./LoopBehaviorFields";
2931
import { Field } from "./LoopFormPrimitives";
3032
import { LoopModelFields } from "./LoopModelFields";
3133
import { LoopNotificationsFields } from "./LoopNotificationsFields";
@@ -230,6 +232,16 @@ export function LoopForm({ loop }: LoopFormProps) {
230232

231233
<Divider />
232234

235+
<Field label="Behavior">
236+
<LoopBehaviorFields
237+
behaviors={values.behaviors}
238+
disabled={isSubmitting}
239+
onChange={(behaviors) => patch({ behaviors })}
240+
/>
241+
</Field>
242+
243+
<Divider />
244+
233245
<Field label="Notifications">
234246
<LoopNotificationsFields
235247
notifications={values.notifications}
@@ -473,6 +485,10 @@ function ReviewList({ values }: { values: LoopFormValues }) {
473485
: values.triggers.map(describeTrigger).join(", ")
474486
}
475487
/>
488+
<ReviewRow
489+
label="Auto-fix PRs"
490+
value={isAutoFixEnabled(values.behaviors) ? "On" : "Off"}
491+
/>
476492
<ReviewRow
477493
label="Notifications"
478494
value={channels.length === 0 ? "None" : channels.join(", ")}

packages/ui/src/features/loops/loopFormTypes.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface LoopFormValues {
3131
*/
3232
repositories: LoopSchemas.LoopRepositoryEntry[];
3333
triggers: LoopTriggerDraft[];
34+
behaviors: LoopSchemas.LoopBehaviors;
3435
notifications: LoopSchemas.LoopNotifications;
3536
}
3637

@@ -51,6 +52,30 @@ export function defaultLoopNotifications(): LoopSchemas.LoopNotifications {
5152
return { push: { ...off }, email: { ...off }, slack: { ...off } };
5253
}
5354

55+
export function defaultLoopBehaviors(): LoopSchemas.LoopBehaviors {
56+
return {
57+
create_prs: true,
58+
watch_ci: false,
59+
fix_review_comments: false,
60+
max_fix_iterations: 3,
61+
};
62+
}
63+
64+
/** The single "Auto-fix pull requests" toggle drives both CI-watching and
65+
* review-comment fixing; it reads as on only when both are on. */
66+
export function isAutoFixEnabled(
67+
behaviors: LoopSchemas.LoopBehaviors,
68+
): boolean {
69+
return behaviors.watch_ci && behaviors.fix_review_comments;
70+
}
71+
72+
export function withAutoFix(
73+
behaviors: LoopSchemas.LoopBehaviors,
74+
enabled: boolean,
75+
): LoopSchemas.LoopBehaviors {
76+
return { ...behaviors, watch_ci: enabled, fix_review_comments: enabled };
77+
}
78+
5479
let draftKeySeq = 0;
5580

5681
export function nextDraftTriggerKey(): string {
@@ -69,6 +94,7 @@ export function emptyLoopFormValues(): LoopFormValues {
6994
reasoningEffort: null,
7095
repositories: [],
7196
triggers: [],
97+
behaviors: defaultLoopBehaviors(),
7298
notifications: defaultLoopNotifications(),
7399
};
74100
}
@@ -90,6 +116,7 @@ export function loopToFormValues(loop: LoopSchemas.Loop): LoopFormValues {
90116
enabled: trigger.enabled,
91117
config: trigger.config,
92118
})),
119+
behaviors: loop.behaviors,
93120
notifications: loop.notifications,
94121
};
95122
}
@@ -112,6 +139,7 @@ export function formValuesToLoopWrite(
112139
enabled: trigger.enabled,
113140
config: trigger.config,
114141
})),
142+
behaviors: values.behaviors,
115143
notifications: values.notifications,
116144
};
117145
}

0 commit comments

Comments
 (0)