Skip to content

Commit cb4d216

Browse files
authored
feat(settings): add rtk compression toggle, on by default
One boolean in Settings > Advanced, "Compress command output", default on. When off: local and worktree sessions get POSTHOG_RTK=0 on the agent environment (start and reconnect), and cloud runs send rtk_enabled: false into TaskRun.state so the sandbox launches with rtk disabled. When on, nothing is sent and the server-side default (enabled) applies. Generated-By: PostHog Code Task-Id: 2d6eed7f-9209-4d1f-be54-ae3e22bf2990
1 parent 12cfd51 commit cb4d216

13 files changed

Lines changed: 94 additions & 2 deletions

File tree

packages/api-client/src/posthog-client.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,41 @@ describe("PostHogAPIClient", () => {
177177
);
178178
});
179179

180+
it("serializes an rtk opt-out as rtk_enabled false on run creation", async () => {
181+
const fetch = vi.fn().mockResolvedValue({
182+
ok: true,
183+
json: async () => ({ id: "run-123", environment: "cloud" }),
184+
});
185+
const client = new PostHogAPIClient(
186+
"http://localhost:8000",
187+
async () => "token",
188+
async () => "token",
189+
123,
190+
);
191+
192+
(
193+
client as unknown as {
194+
api: { baseUrl: string; fetcher: { fetch: typeof fetch } };
195+
}
196+
).api = {
197+
baseUrl: "http://localhost:8000",
198+
fetcher: { fetch },
199+
};
200+
201+
await client.createTaskRun("task-123", {
202+
environment: "cloud",
203+
mode: "interactive",
204+
rtkEnabled: false,
205+
});
206+
207+
const request = fetch.mock.calls[0][0] as {
208+
overrides: { body: string };
209+
};
210+
expect(JSON.parse(request.overrides.body)).toMatchObject({
211+
rtk_enabled: false,
212+
});
213+
});
214+
180215
it("starts an existing cloud task run with run-scoped artifact ids", async () => {
181216
const fetch = vi.fn().mockResolvedValue({
182217
ok: true,

packages/api-client/src/posthog-client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ interface CloudRunOptions {
480480
sandboxEnvironmentId?: string;
481481
prAuthorshipMode?: PrAuthorshipMode;
482482
autoPublish?: boolean;
483+
/** Only false is sent: opts the run out of rtk command-output compression. */
484+
rtkEnabled?: boolean;
483485
runSource?: CloudRunSource;
484486
signalReportId?: string;
485487
initialPermissionMode?: PermissionMode;
@@ -556,6 +558,9 @@ function buildCloudRunRequestBody(
556558
if (options?.autoPublish) {
557559
body.auto_publish = options.autoPublish;
558560
}
561+
if (options?.rtkEnabled === false) {
562+
body.rtk_enabled = false;
563+
}
559564
if (options?.runSource) {
560565
body.run_source = options.runSource;
561566
}

packages/core/src/sessions/sessionService.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ export interface SessionServiceDeps {
298298
setAdapter(taskRunId: string, adapter: Adapter): void;
299299
removeAdapter(taskRunId: string): void;
300300
};
301-
readonly settings: { customInstructions?: string | null };
301+
readonly settings: {
302+
customInstructions?: string | null;
303+
rtkEnabled?: boolean;
304+
};
302305
usageLimit: { show: (...args: any[]) => any };
303306
readonly addDirectoryDialog: { open: boolean };
304307
taskViewedApi: { markActivity(taskId: string): void };
@@ -1022,11 +1025,12 @@ export class SessionService {
10221025
this.d.log.warn("Failed to verify workspace", { taskId, err });
10231026
});
10241027

1025-
const { customInstructions } = this.d.settings;
1028+
const { customInstructions, rtkEnabled } = this.d.settings;
10261029
const result = await this.d.trpc.agent.reconnect.mutate({
10271030
taskId,
10281031
taskRunId,
10291032
repoPath,
1033+
rtkEnabled,
10301034
apiHost: auth.apiHost,
10311035
projectId: auth.projectId,
10321036
logUrl,
@@ -1357,6 +1361,7 @@ export class SessionService {
13571361
permissionMode: executionMode,
13581362
adapter,
13591363
customInstructions: startCustomInstructions || undefined,
1364+
rtkEnabled: this.d.settings.rtkEnabled,
13601365
effort: effortLevelSchema.safeParse(reasoningLevel).success
13611366
? (reasoningLevel as EffortLevel)
13621367
: undefined,
@@ -2994,6 +2999,7 @@ export class SessionService {
29942999
artifactIds.length > 0 ? artifactIds : undefined,
29953000
prAuthorshipMode,
29963001
autoPublish: previousState.auto_publish === true || undefined,
3002+
rtkEnabled: this.d.settings.rtkEnabled,
29973003
runSource: getCloudRunSource(previousState),
29983004
signalReportId:
29993005
typeof previousState.signal_report_id === "string"

packages/core/src/task-detail/taskCreationApiClient.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface CreateTaskRunClientOptions {
1515
sandboxEnvironmentId?: string;
1616
prAuthorshipMode?: PrAuthorshipMode;
1717
autoPublish?: boolean;
18+
rtkEnabled?: boolean;
1819
runSource?: CloudRunSource;
1920
signalReportId?: string;
2021
initialPermissionMode?: string;

packages/core/src/task-detail/taskCreationSaga.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ describe("TaskCreationSaga", () => {
153153
model: "gpt-5.4",
154154
reasoningLevel: "high",
155155
cloudAutoPublish: true,
156+
rtkEnabled: false,
156157
});
157158

158159
expect(result.success).toBe(true);
@@ -170,6 +171,7 @@ describe("TaskCreationSaga", () => {
170171
sandboxEnvironmentId: undefined,
171172
prAuthorshipMode: "user",
172173
autoPublish: true,
174+
rtkEnabled: false,
173175
runSource: "manual",
174176
signalReportId: undefined,
175177
initialPermissionMode: "auto",

packages/core/src/task-detail/taskCreationSaga.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ export class TaskCreationSaga extends Saga<
402402
sandboxEnvironmentId: input.sandboxEnvironmentId,
403403
prAuthorshipMode,
404404
autoPublish: input.cloudAutoPublish,
405+
rtkEnabled: input.rtkEnabled,
405406
runSource: input.cloudRunSource ?? "manual",
406407
signalReportId: input.signalReportId,
407408
homeQuickAction: input.homeQuickActionLabel,

packages/core/src/task-detail/taskInput.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface PrepareTaskInputOptions {
2828
channelId?: string;
2929
customInstructions?: string;
3030
autoPublishCloudRuns?: boolean;
31+
rtkEnabled?: boolean;
3132
allowNoRepo?: boolean;
3233
}
3334

@@ -62,6 +63,7 @@ export function prepareTaskInput(
6263
cloudRunSource:
6364
options.signalReportId && isCloud ? "signal_report" : undefined,
6465
cloudAutoPublish: isCloud ? options.autoPublishCloudRuns : undefined,
66+
rtkEnabled: options.rtkEnabled,
6567
signalReportId: options.signalReportId,
6668
additionalDirectories: isCloud ? undefined : options.additionalDirectories,
6769
channelContext: options.channelContext,

packages/shared/src/task-creation-domain.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export interface TaskCreationInput {
4242
* completion without waiting for an explicit ask (Settings → Advanced).
4343
*/
4444
cloudAutoPublish?: boolean;
45+
/**
46+
* rtk command-output compression for the run. Only false is meaningful:
47+
* it opts the run out of the server-side default (enabled).
48+
*/
49+
rtkEnabled?: boolean;
4550
signalReportId?: string;
4651
additionalDirectories?: string[];
4752
/**

packages/ui/src/features/settings/sections/AdvancedSettings.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export function AdvancedSettings() {
2727
const setAutoPublishCloudRuns = useSettingsStore(
2828
(s) => s.setAutoPublishCloudRuns,
2929
);
30+
const rtkEnabled = useSettingsStore((s) => s.rtkEnabled);
31+
const setRtkEnabled = useSettingsStore((s) => s.setRtkEnabled);
3032
const devModeClient = useServiceOptional<DevModeClient>(DEV_MODE_CLIENT);
3133

3234
return (
@@ -41,6 +43,12 @@ export function AdvancedSettings() {
4143
size="1"
4244
/>
4345
</SettingRow>
46+
<SettingRow
47+
label="Compress command output"
48+
description="Route eligible shell commands through rtk so their verbose output is compressed before it reaches the model, reducing token usage. Applies to local, worktree, and cloud runs"
49+
>
50+
<Switch checked={rtkEnabled} onCheckedChange={setRtkEnabled} size="1" />
51+
</SettingRow>
4452
<SettingRow
4553
label="Reset onboarding and tours"
4654
description="Re-run the onboarding tutorial and product tours on next app restart"

packages/ui/src/features/settings/settingsStore.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,14 @@ interface SettingsStore {
153153
// When on, cloud runs push their work and open a draft PR on completion
154154
// without waiting for an explicit ask.
155155
autoPublishCloudRuns: boolean;
156+
// When on, agent runs compress eligible command output through rtk before it
157+
// reaches the model. Applies to local, worktree, and cloud runs.
158+
rtkEnabled: boolean;
156159
setAllowBypassPermissions: (enabled: boolean) => void;
157160
setPreventSleepWhileRunning: (enabled: boolean) => void;
158161
setDebugLogsCloudRuns: (enabled: boolean) => void;
159162
setAutoPublishCloudRuns: (enabled: boolean) => void;
163+
setRtkEnabled: (enabled: boolean) => void;
160164

161165
// Terminal
162166
terminalFont: TerminalFont;
@@ -324,13 +328,15 @@ export const useSettingsStore = create<SettingsStore>()(
324328
preventSleepWhileRunning: false,
325329
debugLogsCloudRuns: false,
326330
autoPublishCloudRuns: true,
331+
rtkEnabled: true,
327332
setAllowBypassPermissions: (enabled) =>
328333
set({ allowBypassPermissions: enabled }),
329334
setPreventSleepWhileRunning: (enabled) =>
330335
set({ preventSleepWhileRunning: enabled }),
331336
setDebugLogsCloudRuns: (enabled) => set({ debugLogsCloudRuns: enabled }),
332337
setAutoPublishCloudRuns: (enabled) =>
333338
set({ autoPublishCloudRuns: enabled }),
339+
setRtkEnabled: (enabled) => set({ rtkEnabled: enabled }),
334340

335341
// Terminal
336342
terminalFont: "berkeley-mono",
@@ -444,6 +450,7 @@ export const useSettingsStore = create<SettingsStore>()(
444450
preventSleepWhileRunning: state.preventSleepWhileRunning,
445451
debugLogsCloudRuns: state.debugLogsCloudRuns,
446452
autoPublishCloudRuns: state.autoPublishCloudRuns,
453+
rtkEnabled: state.rtkEnabled,
447454

448455
// Terminal
449456
terminalFont: state.terminalFont,

0 commit comments

Comments
 (0)