Skip to content
Merged
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
14 changes: 13 additions & 1 deletion apps/mobile/src/app/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ export default function SettingsScreen() {
const setAutoPublishCloudRuns = usePreferencesStore(
(s) => s.setAutoPublishCloudRuns,
);
const rtkEnabledCloud = usePreferencesStore((s) => s.rtkEnabledCloud);
const setRtkEnabledCloud = usePreferencesStore((s) => s.setRtkEnabledCloud);
const defaultMessagingMode = useMessagingModeStore((s) => s.defaultMode);
const setDefaultMessagingMode = useMessagingModeStore(
(s) => s.setDefaultMode,
Expand Down Expand Up @@ -427,14 +429,24 @@ export default function SettingsScreen() {
<SettingsRow
label="Always create pull requests for cloud runs"
description="Cloud runs push their changes and open a draft pull request when they finish, without waiting for you to ask"
showDivider={false}
rightSlot={
<Switch
value={autoPublishCloudRuns}
onValueChange={setAutoPublishCloudRuns}
/>
}
/>
<SettingsRow
label="Compress command output"
description="Route verbose shell command output through rtk so it is compressed before it reaches the model, reducing token usage"
showDivider={false}
rightSlot={
<Switch
value={rtkEnabledCloud}
onValueChange={setRtkEnabledCloud}
/>
}
/>
</SettingsSection>

{/* Integrations */}
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/app/task/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ export default function TaskDetailScreen() {
model: composerModel,
reasoningEffort: supportsReasoning ? composerReasoning : undefined,
initialPermissionMode: composerMode,
rtkEnabled: usePreferencesStore.getState().rtkEnabledCloud,
});
setTask(updatedTask);
await connectToTask(updatedTask);
Expand Down Expand Up @@ -478,6 +479,7 @@ export default function TaskDetailScreen() {

const updatedTask = await runTaskInCloud(taskId, {
resumeFromRunId: task.latest_run?.id,
rtkEnabled: usePreferencesStore.getState().rtkEnabledCloud,
});
setTask(updatedTask);
await connectToTask(updatedTask);
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/app/task/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export default function NewTaskScreen() {
reasoningEffort: supportsReasoning ? reasoning : undefined,
initialPermissionMode: mode,
autoPublish: usePreferencesStore.getState().autoPublishCloudRuns,
rtkEnabled: usePreferencesStore.getState().rtkEnabledCloud,
...(signalReport
? {
runSource: "signal_report" as const,
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/features/inbox/components/TinderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
useSafeAreaInsets,
} from "react-native-safe-area-context";
import { MarkdownText } from "@/features/chat/components/MarkdownText";
import { usePreferencesStore } from "@/features/preferences/stores/preferencesStore";
import { createTask, runTaskInCloud } from "@/features/tasks/api";
import { DEFAULT_MODEL } from "@/features/tasks/composer/options";
import type {
Expand Down Expand Up @@ -256,6 +257,7 @@ export function TinderView({
initialPermissionMode: "plan",
runSource: "signal_report",
signalReportId: report.id,
rtkEnabled: usePreferencesStore.getState().rtkEnabledCloud,
});

acceptReport(report.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ interface PreferencesState {

autoPublishCloudRuns: boolean;
setAutoPublishCloudRuns: (enabled: boolean) => void;

rtkEnabledCloud: boolean;
setRtkEnabledCloud: (enabled: boolean) => void;
}

export const usePreferencesStore = create<PreferencesState>()(
Expand Down Expand Up @@ -127,6 +130,9 @@ export const usePreferencesStore = create<PreferencesState>()(
autoPublishCloudRuns: true,
setAutoPublishCloudRuns: (enabled) =>
set({ autoPublishCloudRuns: enabled }),

rtkEnabledCloud: true,
setRtkEnabledCloud: (enabled) => set({ rtkEnabledCloud: enabled }),
}),
{
name: "posthog-preferences",
Expand All @@ -144,6 +150,7 @@ export const usePreferencesStore = create<PreferencesState>()(
defaultReasoningEffort: state.defaultReasoningEffort,
lastUsedReasoningEffort: state.lastUsedReasoningEffort,
autoPublishCloudRuns: state.autoPublishCloudRuns,
rtkEnabledCloud: state.rtkEnabledCloud,
}),
},
),
Expand Down
15 changes: 15 additions & 0 deletions apps/mobile/src/features/tasks/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,19 @@ describe("runTaskInCloud", () => {
const [, init] = mockFetch.mock.calls[0] as [string, RequestInit];
expect(init.body).toBeUndefined();
});

it("sends rtk_enabled=false when the run opts out", async () => {
await runTaskInCloud("task-1", { rtkEnabled: false });

expect(bodyOf(mockFetch.mock.calls[0])).toMatchObject({
rtk_enabled: false,
});
});

it("omits rtk_enabled when the run keeps compression on", async () => {
await runTaskInCloud("task-1", { rtkEnabled: true });

const [, init] = mockFetch.mock.calls[0] as [string, RequestInit];
expect(init.body).toBeUndefined();
});
});
8 changes: 7 additions & 1 deletion apps/mobile/src/features/tasks/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ export interface RunTaskInCloudOptions {
/** When true, the cloud run pushes its changes and opens a draft PR on
* completion without waiting for an explicit ask. */
autoPublish?: boolean;
Comment thread
Gilbert09 marked this conversation as resolved.
/** Only false is sent: opts the run out of rtk command-output compression. */
rtkEnabled?: boolean;
}

export async function runTaskInCloud(
Expand All @@ -460,7 +462,8 @@ export async function runTaskInCloud(
options.initialPermissionMode !== undefined ||
options.runSource !== undefined ||
options.signalReportId !== undefined ||
options.autoPublish !== undefined);
options.autoPublish !== undefined ||
options.rtkEnabled === false);

let body: string | undefined;
if (hasOptions) {
Expand Down Expand Up @@ -490,6 +493,9 @@ export async function runTaskInCloud(
if (options?.autoPublish !== undefined) {
payload.auto_publish = options.autoPublish;
}
if (options?.rtkEnabled === false) {
payload.rtk_enabled = false;
}
body = JSON.stringify(payload);
}

Expand Down
17 changes: 17 additions & 0 deletions apps/mobile/src/features/tasks/stores/taskSessionStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ vi.mock("../api", () => ({
sendCloudCommand: vi.fn(),
}));

import { usePreferencesStore } from "@/features/preferences/stores/preferencesStore";
import { getTask, runTaskInCloud } from "../api";
import type {
CloudTaskUpdatePayload,
Expand Down Expand Up @@ -155,6 +156,7 @@ describe("_resumeCloudRun", () => {
vi.clearAllMocks();
useTaskStore.setState({ composerConfigByTaskId: {} });
useTaskSessionStore.setState({ sessions: {} });
usePreferencesStore.setState({ rtkEnabledCloud: true });
mockRunTaskInCloud.mockResolvedValue({
id: "t1",
latest_run: { id: "new-run" },
Expand All @@ -180,9 +182,24 @@ describe("_resumeCloudRun", () => {
pendingUserMessage: "hi",
reasoningEffort: "low",
initialPermissionMode: "acceptEdits",
rtkEnabled: true,
});
});

it("forwards the rtk compression opt-out so resume preserves it", async () => {
usePreferencesStore.setState({ rtkEnabledCloud: false });
mockGetTask.mockResolvedValue(previousTask({ branch: "feature" }));

await useTaskSessionStore
.getState()
._resumeCloudRun("t1", "prev-run", "hi");

expect(mockRunTaskInCloud).toHaveBeenCalledWith(
"t1",
expect.objectContaining({ rtkEnabled: false }),
);
});

it("prefers the composer's current selection over the previous run", async () => {
useTaskStore.setState({
composerConfigByTaskId: { t1: { mode: "plan", reasoning: "max" } },
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/features/tasks/stores/taskSessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ export const useTaskSessionStore = create<TaskSessionStore>((set, get) => ({
pendingUserMessage: prompt,
reasoningEffort,
initialPermissionMode,
rtkEnabled: usePreferencesStore.getState().rtkEnabledCloud,
});

const newRun = updatedTask.latest_run;
Expand Down
Loading