Skip to content

Commit 4027c6e

Browse files
committed
Add status bars to apply changes from clipboard or active CLI terminal
- in prompt view: should actively listen to terminals, if there is one in the front that is at the 'edit' temp folder - e.g. `cwc-cli-edit-2`, should display status bar above prompt field: `'Apply from terminal?' [Apply]` - should not watch for changes in terminal sandbox and ever show [Pasted text] notification - shouldn't check_active_terminal read cwd from different place? this is how terminal's object looks upon editor reload [Pasted text] - reading the terminal cwd should be an util in `apps/editor/src/utils` - we need to be able to easily determine if the response is applilcable from the outside - should create an util in `apps/editor/src/utils`, potentially importing stuff from the 'apply-response' feature. - Prompt View, when in 'WEB' target, should read clipboard text whenever edior window gains focus. When clipboard text is applicable `apps/editor/src/utils/is-response-applicable.ts`, should display status bar: `Clipboard contains applicable response [Apply]` - once applied from clipboard, should clear its value with e.g. [Pasted text] and update `PromptViewProvider.clipboard_has_applicable_response` - before doing [Fragment], recheck if response is applicable. also the warning notification if not, should be disaptched from the `apps/editor/src/commands/apply-from-clipboard-command.ts` command, not the feature - move [Pasted text] to `apps/editor/src/i18n/translations/commands/apply-from-clipboard-command.ts`, while updating key name appropriately ├── apps │ └── editor │ ├── package.json │ └── src │ ├── commands │ │ ├── apply-from-clipboard-command.ts │ │ ├── apply-from-terminal-command.ts │ │ └── index.ts │ ├── context │ │ └── helpers │ │ └── get-all-workspace-files.ts │ ├── extension.ts │ ├── features │ │ └── apply-response │ │ ├── apply-response.ts │ │ ├── response-processor │ │ │ └── response-processor.ts │ │ └── utils │ │ ├── preview │ │ │ └── preview.ts │ │ └── response-parser │ │ ├── index.ts │ │ ├── parsers │ │ │ ├── code-at-cursor-parser │ │ │ │ ├── code-at-cursor-parser.ts │ │ │ │ ├── index.ts │ │ │ │ └── test │ │ │ │ └── code-at-cursor-parser.spec.ts │ │ │ ├── commit-message-parser │ │ │ │ ├── commit-message-parser.ts │ │ │ │ ├── index.ts │ │ │ │ └── test │ │ │ │ └── commit-message-parser.spec.ts │ │ │ ├── diff-parser │ │ │ │ ├── diff-parser.ts │ │ │ │ ├── helpers │ │ │ │ │ ├── block-utils.ts │ │ │ │ │ ├── index.ts │ │ │ │ │ ├── patch-utils.ts │ │ │ │ │ └── path-utils.ts │ │ │ │ ├── index.ts │ │ │ │ └── test │ │ │ │ └── diff-parser.spec.ts │ │ │ ├── index.ts │ │ │ ├── intelligent-file-search-results-parser │ │ │ │ ├── index.ts │ │ │ │ └── intelligent-file-search-results-parser.ts │ │ │ ├── patch-repair-parser │ │ │ │ ├── index.ts │ │ │ │ ├── patch-repair-parser.ts │ │ │ │ └── test │ │ │ │ └── patch-repair-parser.spec.ts │ │ │ └── standard-parser │ │ │ ├── helpers │ │ │ │ ├── create-or-update-file-item.ts │ │ │ │ ├── extract-and-set-workspace-path.ts │ │ │ │ ├── flush-text-block.ts │ │ │ │ └── process-conflict-markers.ts │ │ │ ├── index.ts │ │ │ ├── standard-parser.ts │ │ │ └── test │ │ │ └── standard-parser.spec.ts │ │ └── response-parser.ts │ ├── i18n │ │ └── translations │ │ └── commands │ │ ├── apply-from-clipboard-command.ts │ │ ├── apply-from-terminal-command.ts │ │ ├── apply-response-command.ts │ │ └── index.ts │ ├── utils │ │ ├── agentic-cli-invocation │ │ │ ├── index.ts │ │ │ └── invoke-agentic-cli.ts │ │ ├── get-terminal-cwd.ts │ │ └── is-response-applicable.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-apply.ts │ │ │ ├── handle-invoke-agentic-cli.ts │ │ │ ├── handle-mode-changed.ts │ │ │ └── handle-patch-repair.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ ├── MainView.module.scss │ │ │ └── MainView.tsx │ │ └── i18n │ │ └── translations │ │ └── prompt-field.ts │ └── types │ └── messages.ts └── packages └── ui └── src └── components └── editor ├── common │ └── prompts │ └── PromptField │ ├── PromptField.module.scss │ └── PromptField.tsx └── prompt-view └── StatusBar ├── StatusBar.module.scss ├── StatusBar.tsx └── index.ts
1 parent c8c8da3 commit 4027c6e

21 files changed

Lines changed: 342 additions & 152 deletions

File tree

‎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/extension.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export const activate = async (extension_context: vscode.ExtensionContext) => {
147147
}
148148
),
149149
reference_in_prompt_command({ prompt_view_provider, workspace_provider }),
150-
apply_from_clipboard_command(),
150+
apply_from_clipboard_command({ prompt_view_provider }),
151151
...code_at_cursor_commands({
152152
workspace_provider,
153153
open_editors_provider,

‎apps/editor/src/features/apply-response/apply-response.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ export const setup_apply_response = (params: {
306306
params.prompt_view_provider.send_message({
307307
command: 'HIDE_PROGRESS'
308308
})
309-
vscode.window.showWarningMessage(
310-
t('command.apply-response-command.warning.no-valid-response')
311-
)
312309
return false
313310
}
314311
}

‎apps/editor/src/features/apply-response/response-processor/response-processor.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,6 @@ export const process_response = async (params: {
400400
)
401401

402402
if (files.length === 0) {
403-
vscode.window.showWarningMessage(
404-
t('command.apply-response-command.warning.no-valid-response')
405-
)
406-
407403
const output_channel = get_apply_response_output_channel()
408404
output_channel.show(true)
409405

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const translations = {
2+
'command.apply-from-clipboard-command.warning.no-valid-response': {
3+
en: 'No valid clipboard contents to apply.',
4+
pl: 'Brak prawidłowej zawartości schowka do zastosowania.',
5+
'zh-cn': '没有可应用的有效剪贴板内容。',
6+
ja: '適用する有効なクリップボードの内容がありません。',
7+
'zh-tw': '沒有可應用的有效剪貼簿內容。',
8+
de: 'Keine gültigen Inhalte in der Zwischenablage zum Anwenden vorhanden.',
9+
es: 'No hay contenido válido en el portapapeles para aplicar.',
10+
fr: 'Aucun contenu valide du presse-papiers à appliquer.',
11+
'pt-br': 'Nenhum conteúdo válido da área de transferência para aplicar.',
12+
ru: 'Нет допустимого содержимого буфера обмена для применения.',
13+
ko: '적용할 유효한 클립보드 내용이 없습니다.',
14+
it: 'Nessun contenuto valido negli appunti da applicare.',
15+
tr: 'Uygulanacak geçerli pano içeriği yok.',
16+
cs: 'Žádný platný obsah schránky k použití.',
17+
hu: 'Nincs alkalmazható érvényes vágólap-tartalom.',
18+
bg: 'Няма валидно съдържание в клипборда за прилагане.'
19+
}
20+
} as const

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,5 @@ export const translations = {
7171
cs: 'V terminálovém sandboxu nebyly nalezeny žádné změny.',
7272
hu: 'Nem találhatók változások a terminál homokozójában.',
7373
bg: 'Не са намерени промени в пясъчника на терминала.'
74-
},
75-
'command.apply-from-terminal-command.info.agent-started-edits': {
76-
en: 'Agent started making edits in sandbox. Apply to the workspace once finished.',
77-
pl: 'Agent rozpoczął wprowadzanie zmian w piaskownicy. Zastosuj do obszaru roboczego po zakończeniu.',
78-
'zh-cn': '代理已开始在沙盒中进行编辑。完成后请应用到工作区。',
79-
ja: 'エージェントがサンドボックスで編集を開始しました。完了したらワークスペースに適用してください。',
80-
'zh-tw': '代理已開始在沙盒中進行編輯。完成後請套用到工作區。',
81-
de: 'Der Agent hat mit der Bearbeitung in der Sandbox begonnen. Nach Abschluss auf den Arbeitsbereich anwenden.',
82-
es: 'El agente comenzó a realizar ediciones en el sandbox. Aplícalo al espacio de trabajo una vez finalizado.',
83-
fr: "L'agent a commencé à effectuer des modifications dans la sandbox. Appliquez-les à l'espace de travail une fois terminé.",
84-
'pt-br':
85-
'O agente começou a fazer edições no sandbox. Aplique ao espaço de trabalho quando terminar.',
86-
ru: 'Агент начал вносить изменения в песочнице. Примените их к рабочей области после завершения.',
87-
ko: '에이전트가 샌드박스에서 편집을 시작했습니다. 완료되면 작업 영역에 적용하세요.',
88-
it: "L'agente ha iniziato ad apportare modifiche nella sandbox. Applica all'area di lavoro una volta terminato.",
89-
tr: 'Ajan sandbox üzerinde düzenleme yapmaya başladı. Tamamlandığında çalışma alanına uygulayın.',
90-
cs: 'Agent začal provádět úpravy v sandboxu. Po dokončení je použijte na pracovní prostor.',
91-
hu: 'Az ügynök megkezdte a szerkesztést a homokozóban. Ha végzett, alkalmazza a munkaterületre.',
92-
bg: 'Агентът започна да прави редакции в пясъчника. Приложете към работното пространство, след като приключи.'
93-
},
94-
'command.apply-from-terminal-command.action.apply': {
95-
en: 'Apply',
96-
pl: 'Zastosuj',
97-
'zh-cn': '应用',
98-
ja: '適用',
99-
'zh-tw': '套用',
100-
de: 'Anwenden',
101-
es: 'Aplicar',
102-
fr: 'Appliquer',
103-
'pt-br': 'Aplicar',
104-
ru: 'Применить',
105-
ko: '적용',
106-
it: 'Applica',
107-
tr: 'Uygula',
108-
cs: 'Použít',
109-
hu: 'Alkalmaz',
110-
bg: 'Прилагане'
11174
}
11275
} as const

‎apps/editor/src/i18n/translations/commands/apply-response-command.ts‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,6 @@ export const translations = {
5353
hu: 'Erősítse meg a kontextusba foglalandó fájlokat',
5454
bg: 'Потвърдете файловете за включване в контекста'
5555
},
56-
'command.apply-response-command.warning.no-valid-response': {
57-
en: 'No valid clipboard contents to apply.',
58-
pl: 'Brak prawidłowej zawartości schowka do zastosowania.',
59-
'zh-cn': '没有可应用的有效剪贴板内容。',
60-
ja: '適用する有効なクリップボードの内容がありません。',
61-
'zh-tw': '沒有可應用的有效剪貼簿內容。',
62-
de: 'Keine gültigen Inhalte in der Zwischenablage zum Anwenden vorhanden.',
63-
es: 'No hay contenido válido en el portapapeles para aplicar.',
64-
fr: 'Aucun contenu valide du presse-papiers à appliquer.',
65-
'pt-br': 'Nenhum conteúdo válido da área de transferência para aplicar.',
66-
ru: 'Нет допустимого содержимого буфера обмена для применения.',
67-
ko: '적용할 유효한 클립보드 내용이 없습니다.',
68-
it: 'Nessun contenuto valido negli appunti da applicare.',
69-
tr: 'Uygulanacak geçerli pano içeriği yok.',
70-
cs: 'Žádný platný obsah schránky k použití.',
71-
hu: 'Nincs alkalmazható érvényes vágólap-tartalom.',
72-
bg: 'Няма валидно съдържание в клипборда за прилагане.'
73-
},
7456
'command.apply-response-command.error.no-workspace-folder': {
7557
en: 'No workspace folder open.',
7658
pl: 'Brak otwartego folderu obszaru roboczego.',

‎apps/editor/src/i18n/translations/commands/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { translations as generate_commit_message_command } from './generate-commit-message-command'
22
import { translations as code_at_cursor_command } from './code-at-cursor-command'
3+
import { translations as apply_from_clipboard_command } from './apply-from-clipboard-command'
34
import { translations as apply_response_command } from './apply-response-command'
45
import { translations as restore_context_command } from './restore-context-command'
56
import { translations as save_context_command } from './save-context-command'
@@ -31,6 +32,7 @@ export const translations = {
3132
...apply_from_terminal_command,
3233
...generate_commit_message_command,
3334
...code_at_cursor_command,
35+
...apply_from_clipboard_command,
3436
...apply_response_command,
3537
...restore_context_command,
3638
...save_context_command,

‎apps/editor/src/i18n/translations/views/prompt/handlers/handle-apply.ts‎

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

0 commit comments

Comments
 (0)