Skip to content

Commit 7811af4

Browse files
committed
feat: sync workspace trust setting from vscode
1 parent 4fe0b3c commit 7811af4

File tree

5 files changed

+53
-26
lines changed

5 files changed

+53
-26
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,8 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12501250
const machineId = vscode.env.machineId
12511251
const allowedCommands = vscode.workspace.getConfiguration("roo-cline").get<string[]>("allowedCommands") || []
12521252
const cwd = this.cwd
1253+
const workspaceTrustEnabled =
1254+
vscode.workspace.getConfiguration("security").get<boolean>("workspace.trust.enabled") ?? false
12531255

12541256
return {
12551257
version: this.context.extension?.packageJSON?.version ?? "",
@@ -1325,6 +1327,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13251327
maxReadFileLine: maxReadFileLine ?? 500,
13261328
settingsImportedAt: this.settingsImportedAt,
13271329
showGreeting: showGreeting ?? true, // Ensure showGreeting is included in the returned state
1330+
workspaceTrustEnabled, // Add the workspace trust setting here
13281331
}
13291332
}
13301333

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export type ExtensionState = Pick<
209209

210210
renderContext: "sidebar" | "editor"
211211
settingsImportedAt?: number
212+
workspaceTrustEnabled?: boolean
212213
}
213214

214215
export type { ClineMessage, ClineAsk, ClineSay }

webview-ui/src/components/history/HistoryPreview.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { memo } from "react"
1+
import { memo, useEffect } from "react"
22

33
import { vscode } from "@/utils/vscode"
44
import { formatLargeNumber, formatDate } from "@/utils/format"
55
import { Button, Checkbox } from "@/components/ui"
6+
import { useExtensionState } from "@/context/ExtensionStateContext" // Import the context hook
67

78
import { useAppTranslation } from "../../i18n/TranslationContext"
89
import { CopyButton } from "./CopyButton"
@@ -13,8 +14,15 @@ type HistoryPreviewProps = {
1314
}
1415
const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
1516
const { tasks, showAllWorkspaces, setShowAllWorkspaces } = useTaskSearch()
17+
const { workspaceTrustEnabled } = useExtensionState()
1618
const { t } = useAppTranslation()
1719

20+
useEffect(() => {
21+
if (!workspaceTrustEnabled) {
22+
setShowAllWorkspaces(true)
23+
}
24+
}, [workspaceTrustEnabled, setShowAllWorkspaces])
25+
1826
return (
1927
<div className="flex flex-col gap-3 shrink-0 mx-5">
2028
<div className="flex items-center justify-between text-vscode-descriptionForeground">
@@ -26,17 +34,19 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
2634
{t("history:viewAll")}
2735
</Button>
2836
</div>
29-
<div className="flex items-center gap-2 mb-2">
30-
<Checkbox
31-
id="show-all-workspaces"
32-
checked={showAllWorkspaces}
33-
onCheckedChange={(checked) => setShowAllWorkspaces(checked === true)}
34-
variant="description"
35-
/>
36-
<label htmlFor="show-all-workspaces" className="text-xs text-vscode-foreground cursor-pointer">
37-
{t("history:showAllWorkspaces")}
38-
</label>
39-
</div>
37+
{workspaceTrustEnabled && (
38+
<div className="flex items-center gap-2 mb-2">
39+
<Checkbox
40+
id="show-all-workspaces"
41+
checked={showAllWorkspaces}
42+
onCheckedChange={(checked) => setShowAllWorkspaces(checked === true)}
43+
variant="description"
44+
/>
45+
<label htmlFor="show-all-workspaces" className="text-xs text-vscode-foreground cursor-pointer">
46+
{t("history:showAllWorkspaces")}
47+
</label>
48+
</div>
49+
)}
4050
{tasks.slice(0, 3).map((item) => (
4151
<div
4252
key={item.id}
@@ -85,7 +95,7 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
8595
</>
8696
)}
8797
</div>
88-
{showAllWorkspaces && item.workspace && (
98+
{showAllWorkspaces && workspaceTrustEnabled && item.workspace && (
8999
<div className="flex flex-row gap-1 text-vscode-descriptionForeground text-xs mt-1">
90100
<span className="codicon codicon-folder scale-80" />
91101
<span>{item.workspace}</span>

webview-ui/src/components/history/HistoryView.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { memo, useState } from "react"
1+
import React, { memo, useState, useEffect } from "react"
22
import { DeleteTaskDialog } from "./DeleteTaskDialog"
33
import { BatchDeleteTaskDialog } from "./BatchDeleteTaskDialog"
44
import prettyBytes from "pretty-bytes"
@@ -11,6 +11,7 @@ import { formatLargeNumber, formatDate } from "@/utils/format"
1111
import { cn } from "@/lib/utils"
1212
import { Button, Checkbox } from "@/components/ui"
1313
import { useAppTranslation } from "@/i18n/TranslationContext"
14+
import { useExtensionState } from "@/context/ExtensionStateContext" // Import the context hook
1415

1516
import { Tab, TabContent, TabHeader } from "../common/Tab"
1617
import { useTaskSearch } from "./useTaskSearch"
@@ -35,12 +36,19 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
3536
setShowAllWorkspaces,
3637
} = useTaskSearch()
3738
const { t } = useAppTranslation()
39+
const { workspaceTrustEnabled } = useExtensionState()
3840

3941
const [deleteTaskId, setDeleteTaskId] = useState<string | null>(null)
4042
const [isSelectionMode, setIsSelectionMode] = useState(false)
4143
const [selectedTaskIds, setSelectedTaskIds] = useState<string[]>([])
4244
const [showBatchDeleteDialog, setShowBatchDeleteDialog] = useState<boolean>(false)
4345

46+
useEffect(() => {
47+
if (!workspaceTrustEnabled) {
48+
setShowAllWorkspaces(true)
49+
}
50+
}, [workspaceTrustEnabled, setShowAllWorkspaces])
51+
4452
// Toggle selection mode
4553
const toggleSelectionMode = () => {
4654
setIsSelectionMode(!isSelectionMode)
@@ -156,17 +164,19 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
156164
</VSCodeRadio>
157165
</VSCodeRadioGroup>
158166

159-
<div className="flex items-center gap-2">
160-
<Checkbox
161-
id="show-all-workspaces-view"
162-
checked={showAllWorkspaces}
163-
onCheckedChange={(checked) => setShowAllWorkspaces(checked === true)}
164-
variant="description"
165-
/>
166-
<label htmlFor="show-all-workspaces-view" className="text-vscode-foreground cursor-pointer">
167-
{t("history:showAllWorkspaces")}
168-
</label>
169-
</div>
167+
{workspaceTrustEnabled && (
168+
<div className="flex items-center gap-2">
169+
<Checkbox
170+
id="show-all-workspaces-view"
171+
checked={showAllWorkspaces}
172+
onCheckedChange={(checked) => setShowAllWorkspaces(checked === true)}
173+
variant="description"
174+
/>
175+
<label htmlFor="show-all-workspaces-view" className="text-vscode-foreground cursor-pointer">
176+
{t("history:showAllWorkspaces")}
177+
</label>
178+
</div>
179+
)}
170180

171181
{/* Select all control in selection mode */}
172182
{isSelectionMode && tasks.length > 0 && (
@@ -436,7 +446,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
436446
</div>
437447
)}
438448

439-
{showAllWorkspaces && item.workspace && (
449+
{showAllWorkspaces && workspaceTrustEnabled && item.workspace && (
440450
<div className="flex flex-row gap-1 text-vscode-descriptionForeground text-xs">
441451
<span className="codicon codicon-folder scale-80" />
442452
<span>{item.workspace}</span>

webview-ui/src/context/ExtensionStateContext.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export interface ExtensionStateContextType extends ExtensionState {
8787
setPinnedApiConfigs: (value: Record<string, boolean>) => void
8888
togglePinnedApiConfig: (configName: string) => void
8989
setShowGreeting: (value: boolean) => void
90+
workspaceTrustEnabled: boolean
9091
}
9192

9293
export const ExtensionStateContext = createContext<ExtensionStateContextType | undefined>(undefined)
@@ -165,6 +166,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
165166
terminalZshOhMy: false, // Default Oh My Zsh integration setting
166167
terminalZshP10k: false, // Default Powerlevel10k integration setting
167168
terminalZdotdir: false, // Default ZDOTDIR handling setting
169+
workspaceTrustEnabled: false, // Add default value for the new property
168170
})
169171

170172
const [didHydrateState, setDidHydrateState] = useState(false)
@@ -243,6 +245,7 @@ export const ExtensionStateContextProvider: React.FC<{ children: React.ReactNode
243245

244246
const contextValue: ExtensionStateContextType = {
245247
...state,
248+
workspaceTrustEnabled: state.workspaceTrustEnabled ?? false,
246249
didHydrateState,
247250
showWelcome,
248251
theme,

0 commit comments

Comments
 (0)