From 9ab3ec3c11b8ded360f2a9c37b8f735c5f870113 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Tue, 18 Mar 2025 00:33:40 -0700 Subject: [PATCH] add autoapply --- .../contrib/void/browser/chatThreadService.ts | 2 +- .../contrib/void/browser/editCodeService.ts | 24 ++++++++++++++----- .../void/browser/editCodeServiceInterface.ts | 2 +- .../src/markdown/ApplyBlockHoverButtons.tsx | 2 +- .../react/src/sidebar-tsx/SidebarChat.tsx | 21 ++++++++++++++-- .../react/src/void-settings-tsx/Settings.tsx | 23 ++++++++++++++++-- .../contrib/void/browser/toolsService.ts | 2 +- .../contrib/void/common/voidSettingsTypes.ts | 2 ++ 8 files changed, 64 insertions(+), 14 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/chatThreadService.ts b/src/vs/workbench/contrib/void/browser/chatThreadService.ts index 8bdbc6b6..85f74703 100644 --- a/src/vs/workbench/contrib/void/browser/chatThreadService.ts +++ b/src/vs/workbench/contrib/void/browser/chatThreadService.ts @@ -712,7 +712,7 @@ class ChatThreadService extends Disposable implements IChatThreadService { } // 2. if tool requires approval, break from the loop, awaiting approval - const requiresApproval = true // TODO!!! + const requiresApproval = !this._settingsService.state.globalSettings.autoApprove if (requiresApproval && toolNamesThatRequireApproval.has(toolName)) { this._addMessageToThread(threadId, { role: 'tool_request', name: toolName, paramsStr: toolParamsStr, params: toolParams, id: toolId }) return true diff --git a/src/vs/workbench/contrib/void/browser/editCodeService.ts b/src/vs/workbench/contrib/void/browser/editCodeService.ts index 74ea60ba..8e141547 100644 --- a/src/vs/workbench/contrib/void/browser/editCodeService.ts +++ b/src/vs/workbench/contrib/void/browser/editCodeService.ts @@ -28,7 +28,6 @@ import { IConsistentEditorItemService, IConsistentItemService } from './helperSe import { voidPrefixAndSuffix, ctrlKStream_userMessage, ctrlKStream_systemMessage, defaultQuickEditFimTags, rewriteCode_systemMessage, rewriteCode_userMessage, searchReplace_systemMessage, searchReplace_userMessage, FINAL, ORIGINAL, DIVIDER, tripleTick, } from '../common/prompt/prompts.js'; import { mountCtrlK } from './react/out/quick-edit-tsx/index.js' -import { mountVoidCommandBar } from './react/out/void-command-bar-tsx/index.js' import { QuickEditPropsType } from './quickEditActions.js'; import { IModelContentChangedEvent } from '../../../../editor/common/textModelEvents.js'; import { extractCodeFromFIM, extractCodeFromRegular, ExtractedSearchReplaceBlock, extractSearchReplaceBlocks } from '../common/helpers/extractCodeFromResult.js'; @@ -1558,8 +1557,11 @@ class EditCodeService extends Disposable implements IEditCodeService { const originalFileCode = model.getValue(EndOfLinePreference.LF) const numLines = model.getLineCount() - // reject all diffZones on this URI, adding to history (there can't possibly be overlap after this) - this.removeDiffAreas({ uri, behavior: 'reject', removeCtrlKs: true }) + // Only reject diffZones if we're not using keep-conflicts + if (opts.startBehavior !== 'keep-conflicts') { + // reject all diffZones on this URI, adding to history (there can't possibly be overlap after this) + this.removeDiffAreas({ uri, behavior: 'reject', removeCtrlKs: true }) + } const startLine = 1 const endLine = numLines @@ -1692,7 +1694,7 @@ class EditCodeService extends Disposable implements IEditCodeService { nMessagesSent += 1 if (nMessagesSent >= 5) { - this._notifyError({ message: 'Void Error: Tried to Fast Apply 5 times but failed. Please try again with a smarter model or disable Fast Apply.', fullError: null }) + this._notifyError({ message: 'Tried to Fast Apply 5 times but failed. Please try again with a smarter model or disable Fast Apply.', fullError: null }) onDone() this._undoHistory(uri) break @@ -1732,7 +1734,11 @@ class EditCodeService extends Disposable implements IEditCodeService { else { // starting line is at least the number of lines in the generated code minus 1 const numLinesInOrig = numLinesOfStr(block.orig) - diffZone._streamState.line = Math.max(numLinesInOrig - 1, 1, diffZone._streamState.line ?? 1) + const newLine = Math.max(numLinesInOrig - 1, 1, diffZone._streamState.line ?? 1) + if (newLine !== diffZone._streamState.line) { + diffZone._streamState.line = newLine + this._refreshStylesAndDiffsInURI(uri) + } } // must be done writing original to move on to writing streamed content continue @@ -1746,6 +1752,7 @@ class EditCodeService extends Disposable implements IEditCodeService { // if error if (typeof originalBounds === 'string') { console.log('Error finding text in code:') + console.log('originalFileCode', { originalFileCode }) console.log('fullText', { fullText }) console.log('error:', originalBounds) console.log('block.orig:', block.orig) @@ -1759,6 +1766,7 @@ class EditCodeService extends Disposable implements IEditCodeService { // TODO!!! test this blocks.splice(blockNum, Infinity) // remove all blocks at and after this one oldBlocks = deepClone(blocks) + addedTrackingZoneOfBlockNum.splice(blockNum, Infinity) // also remove corresponding tracking zones // Reset streaming state but preserve line context shouldUpdateOrigStreamStyle = true @@ -2412,7 +2420,11 @@ class AcceptAllRejectAllWidget extends Widget implements IOverlayWidget { // Mount command bar using mountVoidCommandBar this._instantiationService.invokeFunction(accessor => { - mountVoidCommandBar(voidCommandBar, accessor, {}) + console.log(voidCommandBar) + if (voidCommandBar) { // remove this + Math.random() + } + // mountVoidCommandBar(voidCommandBar, accessor, {}) }); // Style accept button diff --git a/src/vs/workbench/contrib/void/browser/editCodeServiceInterface.ts b/src/vs/workbench/contrib/void/browser/editCodeServiceInterface.ts index 7fa25ce5..a16aaea2 100644 --- a/src/vs/workbench/contrib/void/browser/editCodeServiceInterface.ts +++ b/src/vs/workbench/contrib/void/browser/editCodeServiceInterface.ts @@ -19,7 +19,7 @@ export type StartApplyingOpts = ({ from: 'ClickApply'; applyStr: string; uri: 'current' | URI; - startBehavior: 'accept-conflicts' | 'reject-conflicts'; + startBehavior: 'accept-conflicts' | 'reject-conflicts' | 'keep-conflicts'; }) diff --git a/src/vs/workbench/contrib/void/browser/react/src/markdown/ApplyBlockHoverButtons.tsx b/src/vs/workbench/contrib/void/browser/react/src/markdown/ApplyBlockHoverButtons.tsx index e68b3bde..57807247 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/markdown/ApplyBlockHoverButtons.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/markdown/ApplyBlockHoverButtons.tsx @@ -154,7 +154,7 @@ export const useApplyButtonHTML = ({ codeStr, applyBoxId, uri }: { codeStr: stri from: 'ClickApply', applyStr: codeStr, uri: uri, - startBehavior: 'reject-conflicts', + startBehavior: 'keep-conflicts', }) ?? [] if (!newApplyingUri) console.log('NOT new applying') diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index e84f563e..e369fd58 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -1147,6 +1147,8 @@ const ToolRequestAcceptRejectButtons = () => { const accessor = useAccessor() const chatThreadsService = accessor.get('IChatThreadService') const metricsService = accessor.get('IMetricsService') + const voidSettingsService = accessor.get('IVoidSettingsService') + const voidSettingsState = useSettingsState() const onAccept = useCallback(() => { try { // this doesn't need to be wrapped in try/catch anymore @@ -1164,6 +1166,11 @@ const ToolRequestAcceptRejectButtons = () => { metricsService.capture('Tool Request Rejected', {}) }, [chatThreadsService, metricsService]) + const onToggleAutoApprove = useCallback((newValue: boolean) => { + voidSettingsService.setGlobalSetting('autoApprove', newValue) + metricsService.capture('Tool Auto-Accept Toggle', { enabled: newValue }) + }, [voidSettingsService, metricsService]) + const approveButton = ( ) - // const isCancelled = state.cancelled || (!isLastMessage && state.awaiting) + const autoApproveToggle = ( +
+ + Auto +
+ ) - return
+ return
{approveButton} {cancelButton} + {autoApproveToggle}
} diff --git a/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx b/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx index 7fa7d183..b0bdd19a 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/void-settings-tsx/Settings.tsx @@ -524,12 +524,31 @@ export const FeaturesTab = () => {
- - + {/* Tools Section */} +

Agent Options

+
+
+

Tools

+
Settings that control Tool behavior.
+ +
+ {/* Auto Accept Switch */} +
+ voidSettingsService.setGlobalSetting('autoApprove', newVal)} + /> + {voidSettingsState.globalSettings.autoApprove ? 'Auto-approve' : 'Ask for approval'} +
+
+
+
+ diff --git a/src/vs/workbench/contrib/void/browser/toolsService.ts b/src/vs/workbench/contrib/void/browser/toolsService.ts index 8c0a8187..89e4d8ae 100644 --- a/src/vs/workbench/contrib/void/browser/toolsService.ts +++ b/src/vs/workbench/contrib/void/browser/toolsService.ts @@ -348,7 +348,7 @@ export class ToolsService implements IToolsService { uri, applyStr: changeDescription, from: 'ClickApply', - startBehavior: 'accept-conflicts', + startBehavior: 'keep-conflicts', }) if (!res) throw new Error(`The Apply model did not start running on ${basename(uri.fsPath)}. Please try again.`) const [_, applyDonePromise] = res diff --git a/src/vs/workbench/contrib/void/common/voidSettingsTypes.ts b/src/vs/workbench/contrib/void/common/voidSettingsTypes.ts index 6668610f..acfe57f0 100644 --- a/src/vs/workbench/contrib/void/common/voidSettingsTypes.ts +++ b/src/vs/workbench/contrib/void/common/voidSettingsTypes.ts @@ -388,6 +388,7 @@ export type GlobalSettings = { syncApplyToChat: boolean; enableFastApply: boolean; chatMode: ChatMode; + autoApprove: boolean; } export const defaultGlobalSettings: GlobalSettings = { @@ -397,6 +398,7 @@ export const defaultGlobalSettings: GlobalSettings = { syncApplyToChat: true, enableFastApply: true, chatMode: 'agent', + autoApprove: false, } export type GlobalSettingName = keyof GlobalSettings