Skip to content

Commit 3a0179b

Browse files
committed
feat: better debug logging
chore: cleaner
1 parent e393c98 commit 3a0179b

File tree

9 files changed

+56
-38
lines changed

9 files changed

+56
-38
lines changed

apps/code/src/renderer/api/posthogClient.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,9 @@ export class PostHogAPIClient {
11841184
path: `/api/projects/${teamId}/sandbox_environments/`,
11851185
});
11861186
if (!response.ok) {
1187-
throw new Error(`Failed to fetch sandbox environments: ${response.statusText}`);
1187+
throw new Error(
1188+
`Failed to fetch sandbox environments: ${response.statusText}`,
1189+
);
11881190
}
11891191
const data = await response.json();
11901192
return (data.results ?? data) as SandboxEnvironment[];
@@ -1206,7 +1208,9 @@ export class PostHogAPIClient {
12061208
},
12071209
});
12081210
if (!response.ok) {
1209-
throw new Error(`Failed to create sandbox environment: ${response.statusText}`);
1211+
throw new Error(
1212+
`Failed to create sandbox environment: ${response.statusText}`,
1213+
);
12101214
}
12111215
return (await response.json()) as SandboxEnvironment;
12121216
}
@@ -1228,7 +1232,9 @@ export class PostHogAPIClient {
12281232
},
12291233
});
12301234
if (!response.ok) {
1231-
throw new Error(`Failed to update sandbox environment: ${response.statusText}`);
1235+
throw new Error(
1236+
`Failed to update sandbox environment: ${response.statusText}`,
1237+
);
12321238
}
12331239
return (await response.json()) as SandboxEnvironment;
12341240
}
@@ -1244,7 +1250,9 @@ export class PostHogAPIClient {
12441250
path: `/api/projects/${teamId}/sandbox_environments/${id}/`,
12451251
});
12461252
if (!response.ok) {
1247-
throw new Error(`Failed to delete sandbox environment: ${response.statusText}`);
1253+
throw new Error(
1254+
`Failed to delete sandbox environment: ${response.statusText}`,
1255+
);
12481256
}
12491257
}
12501258
}

apps/code/src/renderer/features/environments/components/EnvironmentSelector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function EnvironmentSelector({
4343
setOpen(false);
4444
useSettingsDialogStore
4545
.getState()
46-
.open("environments", { repoPath: repoPath ?? undefined });
46+
.open("cloud-environments", { repoPath: repoPath ?? undefined });
4747
};
4848

4949
const triggerContent = (

apps/code/src/renderer/features/sessions/components/ConversationView.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
useSessionForTask,
88
} from "@features/sessions/stores/sessionStore";
99
import { useSettingsStore } from "@features/settings/stores/settingsStore";
10-
import { useFeatureFlag } from "@hooks/useFeatureFlag";
1110
import { ArrowDown, XCircle } from "@phosphor-icons/react";
1211
import { Box, Button, Flex, Text } from "@radix-ui/themes";
1312
import type { AcpMessage } from "@shared/types/session-events";
@@ -50,9 +49,8 @@ export function ConversationView({
5049
}: ConversationViewProps) {
5150
const listRef = useRef<VirtualizedListHandle>(null);
5251
const [showScrollButton, setShowScrollButton] = useState(false);
53-
const agentLogsEnabled = useFeatureFlag("posthog-code-background-agent-logs");
5452
const debugLogsCloudRuns = useSettingsStore((s) => s.debugLogsCloudRuns);
55-
const showDebugLogs = agentLogsEnabled && debugLogsCloudRuns;
53+
const showDebugLogs = debugLogsCloudRuns;
5654
const contextUsage = useContextUsage(events);
5755

5856
const {

apps/code/src/renderer/features/settings/components/SettingsDialog.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
Code,
1111
Folder,
1212
GearSix,
13-
HardDrives,
1413
Keyboard,
1514
Palette,
1615
Plugs,
@@ -25,15 +24,14 @@ import { useHotkeys } from "react-hotkeys-hook";
2524
import { AccountSettings } from "./sections/AccountSettings";
2625
import { AdvancedSettings } from "./sections/AdvancedSettings";
2726
import { ClaudeCodeSettings } from "./sections/ClaudeCodeSettings";
28-
import { EnvironmentsSettings } from "./sections/environments/EnvironmentsSettings";
27+
import { CloudEnvironmentsSettings } from "./sections/CloudEnvironmentsSettings";
2928
import { GeneralSettings } from "./sections/GeneralSettings";
3029
import { McpServersSettings } from "./sections/McpServersSettings";
3130
import { PersonalizationSettings } from "./sections/PersonalizationSettings";
3231
import { ShortcutsSettings } from "./sections/ShortcutsSettings";
3332
import { SignalSourcesSettings } from "./sections/SignalSourcesSettings";
3433
import { UpdatesSettings } from "./sections/UpdatesSettings";
3534
import { WorkspacesSettings } from "./sections/WorkspacesSettings";
36-
import { CloudEnvironmentsSettings } from "./sections/CloudEnvironmentsSettings";
3735
import { WorktreesSettings } from "./sections/worktrees/WorktreesSettings";
3836

3937
interface SidebarItem {

apps/code/src/renderer/features/settings/components/sections/AdvancedSettings.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { Button, Flex, Switch } from "@radix-ui/themes";
66
import { clearApplicationStorage } from "@utils/clearStorage";
77

88
export function AdvancedSettings() {
9-
const showDebugLogsToggle = useFeatureFlag(
10-
"posthog-code-background-agent-logs",
11-
);
9+
const showDebugLogsToggle =
10+
useFeatureFlag("posthog-code-background-agent-logs") || import.meta.env.DEV;
1211
const debugLogsCloudRuns = useSettingsStore((s) => s.debugLogsCloudRuns);
1312
const setDebugLogsCloudRuns = useSettingsStore(
1413
(s) => s.setDebugLogsCloudRuns,

apps/code/src/renderer/features/settings/components/sections/CloudEnvironmentsSettings.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useSandboxEnvironments } from "@features/settings/hooks/useSandboxEnvironments";
22
import { useSettingsDialogStore } from "@features/settings/stores/settingsDialogStore";
33
import { PencilSimple, Plus, Trash } from "@phosphor-icons/react";
4+
import { ChevronDownIcon } from "@radix-ui/react-icons";
45
import {
56
Badge,
67
Button,
@@ -10,8 +11,11 @@ import {
1011
TextArea,
1112
TextField,
1213
} from "@radix-ui/themes";
13-
import { ChevronDownIcon } from "@radix-ui/react-icons";
14-
import type { NetworkAccessLevel, SandboxEnvironment } from "@shared/types";
14+
import type {
15+
NetworkAccessLevel,
16+
SandboxEnvironment,
17+
SandboxEnvironmentInput,
18+
} from "@shared/types";
1519
import { useCallback, useEffect, useMemo, useState } from "react";
1620
import { toast } from "sonner";
1721

@@ -37,14 +41,18 @@ const NETWORK_ACCESS_OPTIONS: {
3741
},
3842
];
3943

40-
const DOMAIN_RE = /^(\*\.)?[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$/;
44+
const DOMAIN_RE =
45+
/^(\*\.)?[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$/;
4146
const ENV_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
4247

4348
function isValidDomain(domain: string): boolean {
4449
return DOMAIN_RE.test(domain);
4550
}
4651

47-
function validateDomains(text: string): { domains: string[]; errors: string[] } {
52+
function validateDomains(text: string): {
53+
domains: string[];
54+
errors: string[];
55+
} {
4856
const domains: string[] = [];
4957
const errors: string[] = [];
5058
for (const line of text.split("\n")) {
@@ -161,7 +169,10 @@ function NetworkAccessSelect({
161169
className="flex w-full cursor-pointer flex-col gap-0 border-0 bg-transparent px-3 py-2 text-left transition-colors hover:bg-gray-3 data-[active]:bg-accent-4"
162170
data-active={opt.value === value || undefined}
163171
>
164-
<Text size="2" weight={opt.value === value ? "medium" : undefined}>
172+
<Text
173+
size="2"
174+
weight={opt.value === value ? "medium" : undefined}
175+
>
165176
{opt.label}
166177
</Text>
167178
<Text size="1" color="gray">
@@ -202,7 +213,8 @@ export function CloudEnvironmentsSettings() {
202213
const isFormOpen = isCreating || editingEnv !== null;
203214

204215
const domainValidation = useMemo(() => {
205-
if (form.network_access_level !== "custom") return { domains: [], errors: [] };
216+
if (form.network_access_level !== "custom")
217+
return { domains: [], errors: [] };
206218
return validateDomains(form.allowed_domains_text);
207219
}, [form.network_access_level, form.allowed_domains_text]);
208220

@@ -237,25 +249,22 @@ export function CloudEnvironmentsSettings() {
237249
return;
238250
}
239251

240-
const payload: Record<string, unknown> = {
252+
const payload: SandboxEnvironmentInput = {
241253
name: form.name,
242254
network_access_level: form.network_access_level,
243255
allowed_domains:
244-
form.network_access_level === "custom"
245-
? domainValidation.domains
246-
: [],
256+
form.network_access_level === "custom" ? domainValidation.domains : [],
247257
include_default_domains:
248258
form.network_access_level === "custom"
249259
? form.include_default_domains
250260
: false,
251261
private: form.private,
252262
repositories: [],
263+
...(form.environment_variables_text.trim()
264+
? { environment_variables: envVarValidation.vars }
265+
: {}),
253266
};
254267

255-
if (form.environment_variables_text.trim()) {
256-
payload.environment_variables = envVarValidation.vars;
257-
}
258-
259268
if (editingEnv) {
260269
await updateMutation.mutateAsync({ id: editingEnv.id, ...payload });
261270
} else {

apps/code/src/renderer/features/settings/hooks/useSandboxEnvironments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useAuthenticatedMutation } from "@hooks/useAuthenticatedMutation";
22
import { useAuthenticatedQuery } from "@hooks/useAuthenticatedQuery";
3-
import type { SandboxEnvironment, SandboxEnvironmentInput } from "@shared/types";
3+
import type { SandboxEnvironmentInput } from "@shared/types";
44
import { useQueryClient } from "@tanstack/react-query";
55
import { toast } from "sonner";
66

apps/code/src/renderer/features/settings/stores/settingsDialogStore.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ interface SettingsDialogState {
2626
}
2727

2828
interface SettingsDialogActions {
29-
open: (category?: SettingsCategory, context?: SettingsDialogContext) => void;
29+
open: (
30+
category?: SettingsCategory,
31+
contextOrAction?: SettingsDialogContext | string,
32+
) => void;
3033
close: () => void;
3134
setCategory: (category: SettingsCategory) => void;
3235
clearContext: () => void;
@@ -42,14 +45,16 @@ export const useSettingsDialogStore = create<SettingsDialogStore>()(
4245
context: {},
4346
initialAction: null,
4447

45-
open: (category, context) => {
48+
open: (category, contextOrAction) => {
4649
if (!get().isOpen) {
4750
window.history.pushState({ settingsOpen: true }, "");
4851
}
52+
const isAction = typeof contextOrAction === "string";
4953
set({
5054
isOpen: true,
5155
activeCategory: category ?? "general",
52-
context: context ?? {},
56+
context: isAction ? {} : (contextOrAction ?? {}),
57+
initialAction: isAction ? contextOrAction : null,
5358
});
5459
},
5560
close: () => {
@@ -58,7 +63,8 @@ export const useSettingsDialogStore = create<SettingsDialogStore>()(
5863
}
5964
set({ isOpen: false, context: {}, initialAction: null });
6065
},
61-
setCategory: (category) => set({ activeCategory: category, initialAction: null }),
66+
setCategory: (category) =>
67+
set({ activeCategory: category, initialAction: null }),
6268
clearContext: () => set({ context: {} }),
6369
consumeInitialAction: () => {
6470
const action = get().initialAction;

apps/code/src/renderer/features/task-detail/components/WorkspaceModeSelect.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useFeatureFlag } from "@hooks/useFeatureFlag";
21
import { useSandboxEnvironments } from "@features/settings/hooks/useSandboxEnvironments";
32
import { useSettingsDialogStore } from "@features/settings/stores/settingsDialogStore";
3+
import { useFeatureFlag } from "@hooks/useFeatureFlag";
44
import type { WorkspaceMode } from "@main/services/workspace/schemas";
55
import { ArrowsSplit, Cloud, Laptop, Plus } from "@phosphor-icons/react";
66
import { ChevronDownIcon } from "@radix-ui/react-icons";
@@ -98,7 +98,9 @@ export function WorkspaceModeSelect({
9898

9999
const triggerIcon = useMemo(() => {
100100
if (value === "cloud") return CLOUD_ICON;
101-
return LOCAL_MODES.find((m) => m.mode === value)?.icon ?? LOCAL_MODES[0].icon;
101+
return (
102+
LOCAL_MODES.find((m) => m.mode === value)?.icon ?? LOCAL_MODES[0].icon
103+
);
102104
}, [value]);
103105

104106
return (
@@ -125,9 +127,7 @@ export function WorkspaceModeSelect({
125127
}}
126128
style={{ padding: "6px 8px", height: "auto" }}
127129
>
128-
<div
129-
style={{ display: "flex", gap: 6, alignItems: "flex-start" }}
130-
>
130+
<div style={{ display: "flex", gap: 6, alignItems: "flex-start" }}>
131131
<span
132132
style={{
133133
marginTop: 2,

0 commit comments

Comments
 (0)