Skip to content

Commit 14852c0

Browse files
feat(svn): Add SVN context function support, and is turned off by default
In chat, it supports citing SVN submission records and working directory changes through @svn, @svn-changes, @r123, etc. Add relevant configuration options, type definitions, and test cases and integrate into existing context mention processing logic. - Added enableSvnContext configuration switch control function to enable - Extended Webview and Extension message interface definitions - Update settings interface to add SVN context options - Modify and mention the parsing logic to support SVN-related functions - Add international Chinese and English documents
1 parent cf20133 commit 14852c0

File tree

18 files changed

+85
-14
lines changed

18 files changed

+85
-14
lines changed

packages/types/src/global-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export const globalSettingsSchema = z.object({
8989
maxOpenTabsContext: z.number().optional(),
9090
maxWorkspaceFiles: z.number().optional(),
9191
showRooIgnoredFiles: z.boolean().optional(),
92+
enableSvnContext: z.boolean().optional(),
9293
maxReadFileLine: z.number().optional(),
9394

9495
terminalOutputLineLimit: z.number().optional(),

src/core/mentions/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export async function parseMentions(
8181
fileContextTracker?: FileContextTracker,
8282
rooIgnoreController?: RooIgnoreController,
8383
showRooIgnoredFiles: boolean = true,
84+
enableSvnContext: boolean = false,
8485
): Promise<string> {
8586
const mentions: Set<string> = new Set()
8687
let parsedText = text.replace(mentionRegexGlobal, (match, mention) => {
@@ -96,11 +97,11 @@ export async function parseMentions(
9697
return `Workspace Problems (see below for diagnostics)`
9798
} else if (mention === "git-changes") {
9899
return `Working directory changes (see below for details)`
99-
} else if (mention === "svn-changes") {
100+
} else if (enableSvnContext && mention === "svn-changes") {
100101
return `Working directory changes (see below for details)`
101102
} else if (/^[a-f0-9]{7,40}$/.test(mention)) {
102103
return `Git commit '${mention}' (see below for commit info)`
103-
} else if (/^r?\d+$/.test(mention)) {
104+
} else if (enableSvnContext && /^r?\d+$/.test(mention)) {
104105
return `SVN revision '${mention}' (see below for commit info)`
105106
} else if (mention === "terminal") {
106107
return `Terminal Output (see below for output)`
@@ -182,7 +183,7 @@ export async function parseMentions(
182183
} catch (error) {
183184
parsedText += `\n\n<git_working_state>\nError fetching working state: ${error.message}\n</git_working_state>`
184185
}
185-
} else if (mention === "svn-changes") {
186+
} else if (enableSvnContext && mention === "svn-changes") {
186187
try {
187188
const svnWorkingState = await getSvnWorkingState(cwd)
188189
console.log("[DEBUG] SVN working state object:", JSON.stringify(svnWorkingState, null, 2))
@@ -212,7 +213,7 @@ export async function parseMentions(
212213
} catch (error) {
213214
parsedText += `\n\n<git_commit hash="${mention}">\nError fetching commit info: ${error.message}\n</git_commit>`
214215
}
215-
} else if (/^r?\d+$/.test(mention)) {
216+
} else if (enableSvnContext && /^r?\d+$/.test(mention)) {
216217
try {
217218
const commitInfo = await getSvnCommitInfoForMentions(mention, cwd)
218219
parsedText += `\n\n<svn_commit revision="${mention}">\n${commitInfo}\n</svn_commit>`

src/core/mentions/processUserContentMentions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ export async function processUserContentMentions({
1313
fileContextTracker,
1414
rooIgnoreController,
1515
showRooIgnoredFiles = true,
16+
enableSvnContext = false,
1617
}: {
1718
userContent: Anthropic.Messages.ContentBlockParam[]
1819
cwd: string
1920
urlContentFetcher: UrlContentFetcher
2021
fileContextTracker: FileContextTracker
2122
rooIgnoreController?: any
2223
showRooIgnoredFiles?: boolean
24+
enableSvnContext?: boolean
2325
}) {
2426
// Process userContent array, which contains various block types:
2527
// TextBlockParam, ImageBlockParam, ToolUseBlockParam, and ToolResultBlockParam.
@@ -46,6 +48,7 @@ export async function processUserContentMentions({
4648
fileContextTracker,
4749
rooIgnoreController,
4850
showRooIgnoredFiles,
51+
enableSvnContext,
4952
),
5053
}
5154
}
@@ -63,6 +66,7 @@ export async function processUserContentMentions({
6366
fileContextTracker,
6467
rooIgnoreController,
6568
showRooIgnoredFiles,
69+
enableSvnContext,
6670
),
6771
}
6872
}
@@ -81,6 +85,7 @@ export async function processUserContentMentions({
8185
fileContextTracker,
8286
rooIgnoreController,
8387
showRooIgnoredFiles,
88+
enableSvnContext,
8489
),
8590
}
8691
}

src/core/task/Task.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,8 @@ export class Task extends EventEmitter<ClineEvents> {
12251225
}),
12261226
)
12271227

1228-
const { showRooIgnoredFiles = true } = (await this.providerRef.deref()?.getState()) ?? {}
1228+
const { showRooIgnoredFiles = true, enableSvnContext = false } =
1229+
(await this.providerRef.deref()?.getState()) ?? {}
12291230

12301231
const parsedUserContent = await processUserContentMentions({
12311232
userContent,
@@ -1234,6 +1235,7 @@ export class Task extends EventEmitter<ClineEvents> {
12341235
fileContextTracker: this.fileContextTracker,
12351236
rooIgnoreController: this.rooIgnoreController,
12361237
showRooIgnoredFiles,
1238+
enableSvnContext,
12371239
})
12381240

12391241
const environmentDetails = await getEnvironmentDetails(this, includeFileDetails)

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,7 @@ export class ClineProvider
14401440
alwaysAllowFollowupQuestions,
14411441
followupAutoApproveTimeoutMs,
14421442
diagnosticsEnabled,
1443+
enableSvnContext,
14431444
} = await this.getState()
14441445

14451446
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -1561,6 +1562,7 @@ export class ClineProvider
15611562
alwaysAllowFollowupQuestions: alwaysAllowFollowupQuestions ?? false,
15621563
followupAutoApproveTimeoutMs: followupAutoApproveTimeoutMs ?? 60000,
15631564
diagnosticsEnabled: diagnosticsEnabled ?? true,
1565+
enableSvnContext: enableSvnContext ?? false,
15641566
}
15651567
}
15661568

@@ -1699,6 +1701,7 @@ export class ClineProvider
16991701
browserToolEnabled: stateValues.browserToolEnabled ?? true,
17001702
telemetrySetting: stateValues.telemetrySetting || "unset",
17011703
showRooIgnoredFiles: stateValues.showRooIgnoredFiles ?? true,
1704+
enableSvnContext: stateValues.enableSvnContext ?? false,
17021705
maxReadFileLine: stateValues.maxReadFileLine ?? -1,
17031706
maxConcurrentFileReads: stateValues.maxConcurrentFileReads ?? 5,
17041707
historyPreviewCollapsed: stateValues.historyPreviewCollapsed ?? false,

src/core/webview/webviewMessageHandler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,10 @@ export const webviewMessageHandler = async (
12421242
await updateGlobalState("showRooIgnoredFiles", message.bool ?? true)
12431243
await provider.postStateToWebview()
12441244
break
1245+
case "enableSvnContext":
1246+
await updateGlobalState("enableSvnContext", message.bool ?? true)
1247+
await provider.postStateToWebview()
1248+
break
12451249
case "hasOpenedModeSelector":
12461250
await updateGlobalState("hasOpenedModeSelector", message.bool ?? true)
12471251
await provider.postStateToWebview()

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export type ExtensionState = Pick<
254254
maxOpenTabsContext: number // Maximum number of VSCode open tabs to include in context (0-500)
255255
maxWorkspaceFiles: number // Maximum number of files to include in current working directory details (0-500)
256256
showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings
257+
enableSvnContext: boolean // Whether to enable SVN context features (commits and changes)
257258
maxReadFileLine: number // Maximum number of lines to read from a file before truncating
258259

259260
experiments: Experiments // Map of experiment IDs to their enabled state

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export interface WebviewMessage {
157157
| "codebaseIndexEnabled"
158158
| "telemetrySetting"
159159
| "showRooIgnoredFiles"
160+
| "enableSvnContext"
160161
| "testBrowserConnection"
161162
| "browserConnectionResult"
162163
| "remoteBrowserEnabled"

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
8686
togglePinnedApiConfig,
8787
taskHistory,
8888
clineMessages,
89+
enableSvnContext,
8990
} = useExtensionState()
9091

9192
// Find the ID and display text for the currently selected API configuration
@@ -374,6 +375,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
374375
queryItems,
375376
fileSearchResults,
376377
allModes,
378+
enableSvnContext,
377379
)
378380
const optionsLength = options.length
379381

@@ -411,6 +413,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
411413
queryItems,
412414
fileSearchResults,
413415
allModes,
416+
enableSvnContext,
414417
)[selectedMenuIndex]
415418
if (
416419
selectedOption &&
@@ -501,6 +504,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
501504
fileSearchResults,
502505
handleHistoryNavigation,
503506
resetHistoryNavigation,
507+
enableSvnContext,
504508
],
505509
)
506510

@@ -1271,6 +1275,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
12711275
modes={allModes}
12721276
loading={searchLoading}
12731277
dynamicSearchResults={fileSearchResults}
1278+
enableSvnContext={enableSvnContext}
12741279
/>
12751280
</div>
12761281
)}

webview-ui/src/components/chat/ContextMenu.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface ContextMenuProps {
2323
modes?: ModeConfig[]
2424
loading?: boolean
2525
dynamicSearchResults?: SearchResult[]
26+
enableSvnContext?: boolean
2627
}
2728

2829
const ContextMenu: React.FC<ContextMenuProps> = ({
@@ -36,13 +37,22 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
3637
queryItems,
3738
modes,
3839
dynamicSearchResults = [],
40+
enableSvnContext = false,
3941
}) => {
4042
const [materialIconsBaseUri, setMaterialIconsBaseUri] = useState("")
4143
const menuRef = useRef<HTMLDivElement>(null)
4244

4345
const filteredOptions = useMemo(() => {
44-
return getContextMenuOptions(searchQuery, inputValue, selectedType, queryItems, dynamicSearchResults, modes)
45-
}, [searchQuery, inputValue, selectedType, queryItems, dynamicSearchResults, modes])
46+
return getContextMenuOptions(
47+
searchQuery,
48+
inputValue,
49+
selectedType,
50+
queryItems,
51+
dynamicSearchResults,
52+
modes,
53+
enableSvnContext,
54+
)
55+
}, [searchQuery, inputValue, selectedType, queryItems, dynamicSearchResults, modes, enableSvnContext])
4656

4757
useEffect(() => {
4858
if (menuRef.current) {

0 commit comments

Comments
 (0)