Skip to content
Draft
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
4 changes: 4 additions & 0 deletions apps/code/src/renderer/api/posthogClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ interface CloudRunOptions {
model?: string;
reasoningLevel?: string;
sandboxEnvironmentId?: string;
sandboxRuntime?: string;
prAuthorshipMode?: PrAuthorshipMode;
runSource?: CloudRunSource;
signalReportId?: string;
Expand Down Expand Up @@ -241,6 +242,9 @@ function buildCloudRunRequestBody(
if (options?.sandboxEnvironmentId) {
body.sandbox_environment_id = options.sandboxEnvironmentId;
}
if (options?.sandboxRuntime) {
body.sandbox_runtime = options.sandboxRuntime;
}
if (options?.prAuthorshipMode) {
body.pr_authorship_mode = options.prAuthorshipMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export function TaskInput({
const [selectedCloudEnvId, setSelectedCloudEnvId] = useState<string | null>(
null,
);
const [selectedSandboxRuntime, setSelectedSandboxRuntime] = useState<
string | null
>(null);
const [activeReportAssociation, setActiveReportAssociation] = useState(
reportAssociation ?? null,
);
Expand Down Expand Up @@ -489,6 +492,10 @@ export function TaskInput({
effectiveWorkspaceMode === "cloud" && selectedCloudEnvId
? selectedCloudEnvId
: undefined,
sandboxRuntime:
effectiveWorkspaceMode === "cloud" && selectedSandboxRuntime
? selectedSandboxRuntime
: undefined,
signalReportId: activeReportAssociation?.reportId,
});

Expand Down Expand Up @@ -654,6 +661,8 @@ export function TaskInput({
onChange={setWorkspaceMode}
selectedCloudEnvironmentId={selectedCloudEnvId}
onCloudEnvironmentChange={setSelectedCloudEnvId}
selectedSandboxRuntime={selectedSandboxRuntime}
onSandboxRuntimeChange={setSelectedSandboxRuntime}
size="1"
/>
{workspaceMode === "worktree" && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ interface WorkspaceModeSelectProps {
overrideModes?: WorkspaceMode[];
selectedCloudEnvironmentId?: string | null;
onCloudEnvironmentChange?: (envId: string | null) => void;
selectedSandboxRuntime?: string | null;
onSandboxRuntimeChange?: (runtime: string | null) => void;
}

const HOGLAND_RUNTIME = "posthog";

const LOCAL_MODES: {
mode: WorkspaceMode;
label: string;
Expand Down Expand Up @@ -67,9 +71,13 @@ export function WorkspaceModeSelect({
overrideModes,
selectedCloudEnvironmentId,
onCloudEnvironmentChange,
selectedSandboxRuntime,
onSandboxRuntimeChange,
}: WorkspaceModeSelectProps) {
const cloudModeEnabled =
useFeatureFlag("twig-cloud-mode-toggle") || import.meta.env.DEV;
const hoglandRuntimeEnabled =
useFeatureFlag("tasks-hogland-runtime") || import.meta.env.DEV;

const { environments } = useSandboxEnvironments();
const openSettings = useSettingsDialogStore((s) => s.open);
Expand Down Expand Up @@ -97,12 +105,17 @@ export function WorkspaceModeSelect({
return environments.find((e) => e.id === selectedCloudEnvironmentId)?.name;
}, [value, selectedCloudEnvironmentId, environments]);

const isHoglandActive =
value === "cloud" && selectedSandboxRuntime === HOGLAND_RUNTIME;

const triggerLabel = useMemo(() => {
if (value === "cloud") {
return selectedEnvName ? `Cloud · ${selectedEnvName}` : "Cloud";
if (selectedEnvName) return `Cloud · ${selectedEnvName}`;
if (isHoglandActive) return "Cloud · Hogland";
return "Cloud";
}
return LOCAL_MODES.find((m) => m.mode === value)?.label ?? "Worktree";
}, [value, selectedEnvName]);
}, [value, selectedEnvName, isHoglandActive]);

const triggerIcon = useMemo(() => {
if (value === "cloud") return CLOUD_ICON;
Expand Down Expand Up @@ -145,6 +158,7 @@ export function WorkspaceModeSelect({
onClick={() => {
onChange(item.mode);
onCloudEnvironmentChange?.(null);
onSandboxRuntimeChange?.(null);
}}
render={
<ItemMenuItem size="xs" className="w-full">
Expand All @@ -164,25 +178,50 @@ export function WorkspaceModeSelect({
</DropdownMenuGroup>

{showCloud && environments.length === 0 && (
<DropdownMenuItem
onClick={() => {
onChange("cloud");
onCloudEnvironmentChange?.(null);
}}
render={
<ItemMenuItem size="xs" className="w-full">
<ItemMedia variant="icon" className="mt-2 ml-2">
<span>{CLOUD_ICON}</span>
</ItemMedia>
<ItemContent variant="menuItem">
<ItemTitle>Cloud</ItemTitle>
<ItemDescription className="whitespace-nowrap leading-none">
Run in a cloud sandbox
</ItemDescription>
</ItemContent>
</ItemMenuItem>
}
/>
<>
<DropdownMenuItem
onClick={() => {
onChange("cloud");
onCloudEnvironmentChange?.(null);
onSandboxRuntimeChange?.(null);
}}
render={
<ItemMenuItem size="xs" className="w-full">
<ItemMedia variant="icon" className="mt-2 ml-2">
<span>{CLOUD_ICON}</span>
</ItemMedia>
<ItemContent variant="menuItem">
<ItemTitle>Cloud</ItemTitle>
<ItemDescription className="whitespace-nowrap leading-none">
Run in a cloud sandbox
</ItemDescription>
</ItemContent>
</ItemMenuItem>
}
/>
{hoglandRuntimeEnabled && (
<DropdownMenuItem
onClick={() => {
onChange("cloud");
onCloudEnvironmentChange?.(null);
onSandboxRuntimeChange?.(HOGLAND_RUNTIME);
}}
render={
<ItemMenuItem size="xs" className="w-full">
<ItemMedia variant="icon" className="mt-2 ml-2">
<span>{CLOUD_ICON}</span>
</ItemMedia>
<ItemContent variant="menuItem">
<ItemTitle>Cloud · Hogland</ItemTitle>
<ItemDescription className="whitespace-nowrap leading-none">
Run on the PostHog sandbox backend
</ItemDescription>
</ItemContent>
</ItemMenuItem>
}
/>
)}
</>
)}

{showCloud && environments.length > 0 && (
Expand All @@ -205,6 +244,7 @@ export function WorkspaceModeSelect({
onClick={() => {
onChange("cloud");
onCloudEnvironmentChange?.(null);
onSandboxRuntimeChange?.(null);
}}
render={
<ItemMenuItem size="xs" className="w-full">
Expand All @@ -221,12 +261,36 @@ export function WorkspaceModeSelect({
}
/>

{hoglandRuntimeEnabled && (
<DropdownMenuItem
onClick={() => {
onChange("cloud");
onCloudEnvironmentChange?.(null);
onSandboxRuntimeChange?.(HOGLAND_RUNTIME);
}}
render={
<ItemMenuItem size="xs" className="w-full">
<ItemMedia variant="icon" className="mt-2 ml-2">
<span>{CLOUD_ICON}</span>
</ItemMedia>
<ItemContent variant="menuItem">
<ItemTitle>Hogland</ItemTitle>
<ItemDescription className="whitespace-nowrap leading-none">
PostHog sandbox backend
</ItemDescription>
</ItemContent>
</ItemMenuItem>
}
/>
)}

{environments.map((env) => (
<DropdownMenuItem
key={`cloud-env-${env.id}`}
onClick={() => {
onChange("cloud");
onCloudEnvironmentChange?.(env.id);
onSandboxRuntimeChange?.(null);
}}
render={
<ItemMenuItem size="xs" className="w-full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface UseTaskCreationOptions {
reasoningLevel?: string;
environmentId?: string | null;
sandboxEnvironmentId?: string;
sandboxRuntime?: string;
signalReportId?: string;
onTaskCreated?: (task: Task) => void;
}
Expand All @@ -69,6 +70,7 @@ function prepareTaskInput(
reasoningLevel?: string;
environmentId?: string | null;
sandboxEnvironmentId?: string;
sandboxRuntime?: string;
signalReportId?: string;
},
): TaskCreationInput {
Expand Down Expand Up @@ -98,6 +100,7 @@ function prepareTaskInput(
reasoningLevel: options.reasoningLevel,
environmentId: options.environmentId ?? undefined,
sandboxEnvironmentId: options.sandboxEnvironmentId,
sandboxRuntime: options.sandboxRuntime,
cloudPrAuthorshipMode:
options.signalReportId && options.workspaceMode === "cloud"
? "user"
Expand Down Expand Up @@ -185,6 +188,7 @@ export function useTaskCreation({
reasoningLevel,
environmentId,
sandboxEnvironmentId,
sandboxRuntime,
signalReportId,
onTaskCreated,
}: UseTaskCreationOptions): UseTaskCreationReturn {
Expand Down Expand Up @@ -258,6 +262,7 @@ export function useTaskCreation({
reasoningLevel,
environmentId,
sandboxEnvironmentId,
sandboxRuntime,
signalReportId,
});

Expand Down Expand Up @@ -332,6 +337,7 @@ export function useTaskCreation({
reasoningLevel,
environmentId,
sandboxEnvironmentId,
sandboxRuntime,
signalReportId,
clearTaskInputReportAssociation,
invalidateTasks,
Expand Down
2 changes: 2 additions & 0 deletions apps/code/src/renderer/sagas/task/task-creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface TaskCreationInput {
reasoningLevel?: string;
environmentId?: string;
sandboxEnvironmentId?: string;
sandboxRuntime?: string;
cloudPrAuthorshipMode?: PrAuthorshipMode;
cloudRunSource?: CloudRunSource;
signalReportId?: string;
Expand Down Expand Up @@ -248,6 +249,7 @@ export class TaskCreationSaga extends Saga<
model: input.model,
reasoningLevel: input.reasoningLevel,
sandboxEnvironmentId: input.sandboxEnvironmentId,
sandboxRuntime: input.sandboxRuntime,
prAuthorshipMode,
runSource: input.cloudRunSource ?? "manual",
signalReportId: input.signalReportId,
Expand Down
Loading