Skip to content

Commit 8841703

Browse files
committed
Add context-aware apply prompts for clipboard responses and agentic CLI terminals while validating applicability
- rename 'ResponsePreview' to 'CodeReview' - should refer to 'preview'/'response preview' as 'code review'. you're allowed to change fodler, file, identifiers etc. names └── apps └── editor └── src ├── commands │ ├── apply-from-clipboard-command.ts │ └── apply-from-terminal-command.ts ├── extension.ts ├── features │ └── apply-response │ ├── apply-response.ts │ ├── index.ts │ ├── response-processor │ │ ├── handlers │ │ │ ├── diff-handler.ts │ │ │ ├── fast-replace-handler.ts │ │ │ ├── search-replace-handler.ts │ │ │ └── truncated-handler.ts │ │ ├── index.ts │ │ └── response-processor.ts │ ├── types │ │ └── original-file-state.ts │ └── utils │ ├── file-checks.ts │ ├── file-operations │ │ ├── apply-file-content.ts │ │ ├── apply-file-relocations.ts │ │ ├── cleanup-rename-source.ts │ │ ├── close-file-tabs.ts │ │ ├── create-file-if-needed.ts │ │ ├── ensure-directory.ts │ │ ├── get-rename-source-info.ts │ │ ├── handle-deleted-file-item.ts │ │ ├── index.ts │ │ ├── prepare-rename-operation.ts │ │ ├── preserve-newline.ts │ │ ├── read-rename-source-file.ts │ │ ├── relocate-file.ts │ │ ├── remove-directory-if-empty.ts │ │ ├── undo-files.ts │ │ └── uri-exists.ts │ ├── state-manager.ts │ ├── tab-group-manager.ts │ └── workspace.ts ├── i18n │ └── translations │ └── commands │ └── apply-from-terminal-command.ts ├── services │ └── websocket-manager.ts └── views └── prompt ├── backend │ ├── message-handlers │ │ ├── handle-apply-response-from-history.ts │ │ ├── handle-invoke-agentic-cli.ts │ │ ├── handle-make-api-call.ts │ │ ├── handle-request-can-undo.ts │ │ └── handle-undo.ts │ └── prompt-view-provider.ts ├── frontend │ └── Prompt.tsx └── types └── messages.ts
1 parent 6d8f4b9 commit 8841703

201 files changed

Lines changed: 345 additions & 1434 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 1 addition & 1 deletion

‎apps/editor/src/commands/apply-from-clipboard-command.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import * as vscode from 'vscode'
22
import { t } from '@/i18n'
33
import { apply_response } from '@/features/apply-response/apply-response'
4+
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
5+
import { is_response_applicable } from '@/utils/is-response-applicable'
6+
import { get_all_workspace_files } from '@/context/helpers/get-all-workspace-files'
47

5-
export const apply_from_clipboard_command = (): vscode.Disposable => {
8+
export const apply_from_clipboard_command = (params: {
9+
prompt_view_provider: PromptViewProvider
10+
}): vscode.Disposable => {
611
return vscode.commands.registerCommand(
712
'codeWebChat.applyFromClipboard',
813
async (args?: {
@@ -17,7 +22,29 @@ export const apply_from_clipboard_command = (): vscode.Disposable => {
1722
return false
1823
}
1924

20-
return await apply_response({
25+
const is_single_root_folder_workspace =
26+
(vscode.workspace.workspaceFolders?.length ?? 0) <= 1
27+
const workspace_files = await get_all_workspace_files({
28+
workspace_provider: params.prompt_view_provider.workspace_provider
29+
})
30+
31+
const is_applicable = is_response_applicable({
32+
response: clipboard_text,
33+
is_single_root_folder_workspace,
34+
workspace_files
35+
})
36+
37+
if (!is_applicable) {
38+
vscode.window.showWarningMessage(
39+
t('command.apply-from-clipboard-command.warning.no-valid-response')
40+
)
41+
return false
42+
}
43+
44+
await vscode.env.clipboard.writeText('')
45+
await params.prompt_view_provider.check_clipboard_for_applicable_response()
46+
47+
apply_response({
2148
response: clipboard_text,
2249
raw_instructions: args?.raw_instructions,
2350
web_configuration_details: args?.web_configuration_details

‎apps/editor/src/commands/apply-from-terminal-command.ts‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { apply_response } from '@/features/apply-response/apply-response'
77
import { t } from '@/i18n'
88
import { generate_diff_markdown } from '../utils/agentic-cli-invocation/utils/generate-diff-markdown'
99
import { Logger } from '@shared/utils/logger'
10+
import { get_terminal_cwd } from '@/utils/get-terminal-cwd'
1011

1112
const build_diff_from_sandbox = async (
1213
sandbox_dir: string
@@ -93,23 +94,12 @@ export const apply_from_terminal_command = (): vscode.Disposable => {
9394
return
9495
}
9596

96-
const creation_options = active_terminal.creationOptions as
97-
| vscode.TerminalOptions
98-
| undefined
99-
const cwd = creation_options?.cwd
97+
const cwd_path = get_terminal_cwd(active_terminal)
98+
const is_cwc_cli = Boolean(
99+
cwd_path && cwd_path.startsWith(path.join(os.tmpdir(), 'cwc-cli-edit-'))
100+
)
100101

101-
let is_cwc_cli = false
102-
let cwd_path = ''
103-
104-
if (cwd) {
105-
cwd_path = typeof cwd === 'string' ? cwd : cwd.fsPath
106-
107-
if (cwd_path.startsWith(path.join(os.tmpdir(), 'cwc-cli-edit-'))) {
108-
is_cwc_cli = true
109-
}
110-
}
111-
112-
if (is_cwc_cli) {
102+
if (is_cwc_cli && cwd_path) {
113103
try {
114104
const diff_markdown = await build_diff_from_sandbox(cwd_path)
115105

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/code-at-cursor-parser/test/cases/standard/1-file.txt‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/code-at-cursor-parser/test/cases/standard/standard.txt‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/code-at-cursor-parser/test/cases/with-text/1-text.txt‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/code-at-cursor-parser/test/cases/with-text/2-file.txt‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/code-at-cursor-parser/test/cases/with-text/3-text.txt‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/code-at-cursor-parser/test/cases/with-text/with-text.txt‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/test/cases/deletion-via-header/1-file.txt‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)