Skip to content

Commit a8fdba1

Browse files
committed
Add preview support for git changes, commits, and skills via symbol clicks
- hold max prompt field tabs in `apps/editor/src/constants/values.ts` - in the prompt field, clicking on 'changes' and 'commit' symbols should preview the markdown - [Fragment] should not be optional - preview skill like you preview git symbols - in markdown file. On the markdown file keep the URL link-opening action button - remove the 'view on skills.sh' line - when previewing text use the pattern of opening a file saved in a temp dir (create a shared utility in `apps/editor/src/views/prompt/backend/utils`) - remove [Pasted text] (should always be true) - `apps/editor/src/views/prompt/backend/message-handlers/handle-preview-skill-symbol.ts` should use `apps/editor/src/views/prompt/backend/utils/preview-text-in-temp-file.ts` ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-hash-sign-quick-pick │ │ │ │ ├── handle-hash-sign-quick-pick.ts │ │ │ │ ├── index.ts │ │ │ │ └── symbols │ │ │ │ ├── changes-symbol.ts │ │ │ │ ├── clipboard-paths-symbol.ts │ │ │ │ ├── commit-symbol.ts │ │ │ │ ├── index.ts │ │ │ │ ├── saved-context-symbol.ts │ │ │ │ ├── selection-symbol.ts │ │ │ │ └── skill-symbol.ts │ │ │ ├── handle-open-prompt-pasted-text.ts │ │ │ ├── handle-preview-changes-symbol.ts │ │ │ ├── handle-preview-commit-symbol.ts │ │ │ ├── handle-preview-prompt.ts │ │ │ ├── handle-preview-skill-symbol.ts │ │ │ └── index.ts │ │ ├── prompt-view-provider.ts │ │ └── utils │ │ ├── preview-text-in-temp-file.ts │ │ ├── symbols │ │ │ ├── git │ │ │ │ └── replace-git-symbols.ts │ │ │ ├── replace-symbols.ts │ │ │ └── skill │ │ │ └── replace-skill-symbol.ts │ │ └── website-fetcher.ts │ ├── frontend │ │ ├── Main │ │ │ ├── Main.tsx │ │ │ └── MainView │ │ │ └── MainView.tsx │ │ ├── Prompt.tsx │ │ └── hooks │ │ └── use-prompt │ │ └── use-prompt.ts │ └── types │ └── messages.ts └── packages └── ui └── src └── components └── editor ├── common │ └── prompts │ ├── PromptField │ │ ├── PromptField.module.scss │ │ ├── PromptField.stories.tsx │ │ ├── PromptField.tsx │ │ ├── hooks │ │ │ ├── use-drag-drop.ts │ │ │ ├── use-dropdown.ts │ │ │ ├── use-ghost-text.ts │ │ │ ├── use-handlers │ │ │ │ ├── handle-copy.ts │ │ │ │ ├── handle-cut.ts │ │ │ │ ├── handle-input-change.ts │ │ │ │ ├── handle-input-click.ts │ │ │ │ ├── handle-key-down.ts │ │ │ │ ├── handle-paste.ts │ │ │ │ ├── handle-submit.ts │ │ │ │ ├── index.ts │ │ │ │ ├── types.ts │ │ │ │ ├── use-handlers.ts │ │ │ │ └── utils.ts │ │ │ └── use-keyboard-shortcuts.ts │ │ └── index.ts │ ├── Template │ │ ├── Template.module.scss │ │ ├── Template.tsx │ │ └── index.ts │ └── shared │ └── symbols │ ├── caret.ts │ ├── get-highlighted-text.tsx │ ├── index.ts │ ├── position-mapping.ts │ ├── prompt-symbols.module.scss │ ├── reconstruct-raw-value.ts │ └── use-symbol-deletion.ts └── prompt └── Tasks ├── components │ └── TaskGroup.tsx ├── hooks │ └── use-auto-focus-new-task.ts └── index.ts
1 parent 13530b1 commit a8fdba1

16 files changed

Lines changed: 300 additions & 38 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as vscode from 'vscode'
2+
import { replace_changes_symbol } from '../utils/symbols/git/replace-git-symbols'
3+
import { preview_text_in_temp_file } from '../utils/preview-text-in-temp-file'
4+
5+
export const handle_preview_changes_symbol = async (message: {
6+
branch_name: string
7+
}) => {
8+
try {
9+
const instruction = `#Changes(${message.branch_name})`
10+
const { changes_definitions } = await replace_changes_symbol({
11+
instruction
12+
})
13+
14+
if (changes_definitions) {
15+
await preview_text_in_temp_file({
16+
prefix: 'cwc-changes',
17+
content: changes_definitions.trim(),
18+
extension: '.md'
19+
})
20+
} else {
21+
vscode.window.showInformationMessage('No changes found or failed to generate diff.')
22+
}
23+
} catch (error) {
24+
vscode.window.showErrorMessage(`Failed to preview changes: ${error}`)
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as vscode from 'vscode'
2+
import { replace_commit_symbol } from '../utils/symbols/git/replace-git-symbols'
3+
import { preview_text_in_temp_file } from '../utils/preview-text-in-temp-file'
4+
5+
export const handle_preview_commit_symbol = async (message: {
6+
repo_name: string
7+
commit_hash: string
8+
commit_message?: string
9+
type: 'Commit' | 'CommitMessage'
10+
}) => {
11+
try {
12+
const message_escaped = message.commit_message
13+
? ` "${message.commit_message.replace(/"/g, '\\"')}"`
14+
: ''
15+
const instruction = `#${message.type}(${message.repo_name}:${message.commit_hash}${message_escaped})`
16+
const { commit_definitions } = await replace_commit_symbol({
17+
instruction
18+
})
19+
20+
if (commit_definitions) {
21+
await preview_text_in_temp_file({
22+
prefix: 'cwc-commit',
23+
content: commit_definitions.trim(),
24+
extension: '.md'
25+
})
26+
} else {
27+
vscode.window.showInformationMessage('Failed to generate commit preview.')
28+
}
29+
} catch (error) {
30+
vscode.window.showErrorMessage(`Failed to preview commit: ${error}`)
31+
}
32+
}

‎apps/editor/src/views/prompt/backend/message-handlers/handle-preview-prompt.ts‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
2-
import * as vscode from 'vscode'
32
import { build_prompt_payload } from './utils/build-prompt-payload'
43
import {
54
EDIT_FORMAT_INSTRUCTIONS_WHOLE,
@@ -8,10 +7,7 @@ import {
87
EDIT_FORMAT_INSTRUCTIONS_DIFF
98
} from '@/constants/edit-format-instructions'
109
import { PromptBuilder } from '@/utils/prompt-builder'
11-
import * as os from 'os'
12-
import * as path from 'path'
13-
import * as fs from 'fs'
14-
import * as crypto from 'crypto'
10+
import { preview_text_in_temp_file } from '../utils/preview-text-in-temp-file'
1511

1612
export const handle_preview_prompt = async (params: {
1713
prompt_view_provider: PromptViewProvider
@@ -51,26 +47,9 @@ export const handle_preview_prompt = async (params: {
5147
separator: true
5248
})
5349

54-
const hash = crypto.createHash('md5').update(`${Date.now()}`).digest('hex')
55-
const temp_file_path = path.join(os.tmpdir(), `cwc-prompt-${hash}.md`)
56-
57-
try {
58-
await fs.promises.writeFile(temp_file_path, text, 'utf8')
59-
} catch (error) {
60-
vscode.window.showErrorMessage(
61-
'Failed to create temporary file for preview.'
62-
)
63-
return
64-
}
65-
66-
try {
67-
const document = await vscode.workspace.openTextDocument(
68-
vscode.Uri.file(temp_file_path)
69-
)
70-
await vscode.window.showTextDocument(document, { preview: false })
71-
} catch (error: any) {
72-
vscode.window.showErrorMessage(
73-
`Failed to open view: ${error.message || 'Unknown error'}`
74-
)
75-
}
50+
await preview_text_in_temp_file({
51+
prefix: 'cwc-prompt',
52+
content: text,
53+
extension: '.md'
54+
})
7655
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as vscode from 'vscode'
2+
import { replace_skill_symbol } from '../utils/symbols/skill/replace-skill-symbol'
3+
import { preview_text_in_temp_file } from '../utils/preview-text-in-temp-file'
4+
5+
export const handle_preview_skill_symbol = async (message: {
6+
agent: string
7+
repo: string
8+
skill_name: string
9+
}) => {
10+
try {
11+
const instruction = `#Skill(${message.agent}:${message.repo}:${message.skill_name})`
12+
const { skill_definitions } = await replace_skill_symbol({
13+
instruction
14+
})
15+
16+
if (skill_definitions) {
17+
await preview_text_in_temp_file({
18+
prefix: 'cwc-skill',
19+
content: skill_definitions.trim(),
20+
extension: '.md'
21+
})
22+
} else {
23+
vscode.window.showInformationMessage('Failed to generate skill preview.')
24+
}
25+
} catch (error) {
26+
vscode.window.showErrorMessage(`Failed to preview skill: ${error}`)
27+
}
28+
}

‎apps/editor/src/views/prompt/backend/message-handlers/index.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ export * from './handle-request-return-home'
6767
export * from './handle-pick-tasks-workspace'
6868
export * from './handle-preview-prompt'
6969
export * from './handle-install-browser-extension'
70+
export * from './handle-preview-changes-symbol'
71+
export * from './handle-preview-commit-symbol'
72+
export * from './handle-preview-skill-symbol'

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ import {
8080
handle_request_return_home,
8181
handle_pick_tasks_workspace,
8282
handle_preview_prompt,
83-
handle_install_browser_extension
83+
handle_install_browser_extension,
84+
handle_preview_changes_symbol,
85+
handle_preview_commit_symbol,
86+
handle_preview_skill_symbol
8487
} from './message-handlers'
8588
import { handle_update_api_configuration } from './message-handlers/handle-update-api-configuration'
8689
import { handle_pick_model_provider } from './message-handlers/handle-pick-model-provider'
@@ -836,6 +839,12 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
836839
})
837840
} else if (message.command == 'INSTALL_BROWSER_EXTENSION') {
838841
await handle_install_browser_extension()
842+
} else if (message.command == 'PREVIEW_CHANGES_SYMBOL') {
843+
await handle_preview_changes_symbol(message)
844+
} else if (message.command == 'PREVIEW_COMMIT_SYMBOL') {
845+
await handle_preview_commit_symbol(message)
846+
} else if (message.command == 'PREVIEW_SKILL_SYMBOL') {
847+
await handle_preview_skill_symbol(message)
839848
}
840849
} catch (error: any) {
841850
Logger.error({
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as vscode from 'vscode'
2+
import * as os from 'os'
3+
import * as path from 'path'
4+
import * as fs from 'fs'
5+
import * as crypto from 'crypto'
6+
7+
export const preview_text_in_temp_file = async (params: {
8+
prefix: string
9+
content: string
10+
extension?: string
11+
}): Promise<void> => {
12+
const hash = crypto
13+
.createHash('md5')
14+
.update(`${Date.now()}-${Math.random()}`)
15+
.digest('hex')
16+
const ext = params.extension || '.txt'
17+
const temp_file_path = path.join(os.tmpdir(), `${params.prefix}-${hash}${ext}`)
18+
19+
try {
20+
await fs.promises.writeFile(temp_file_path, params.content, 'utf8')
21+
} catch (error) {
22+
vscode.window.showErrorMessage(
23+
'Failed to create temporary file for preview.'
24+
)
25+
return
26+
}
27+
28+
try {
29+
const document = await vscode.workspace.openTextDocument(
30+
vscode.Uri.file(temp_file_path)
31+
)
32+
await vscode.window.showTextDocument(document, {
33+
preview: true
34+
})
35+
} catch (error: any) {
36+
vscode.window.showErrorMessage(
37+
`Failed to open view: ${error.message || 'Unknown error'}`
38+
)
39+
}
40+
}

‎apps/editor/src/views/prompt/backend/utils/symbols/skill/replace-skill-symbol.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const replace_skill_symbol = async (params: {
1818

1919
const instruction = params.instruction.replace(
2020
regex,
21-
(full_match, agent_name, _repo_id, skill_name) => {
21+
(full_match, agent_name, repo_id, skill_name) => {
2222
const key = `${agent_name}:${skill_name}`
2323

2424
const formatted_skill_name = skill_name

‎apps/editor/src/views/prompt/frontend/Main/Main.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ type Props = {
7474
ask_instructions_token_count: number
7575
bottom_spacer_height?: number
7676
on_preview_prompt: () => void
77+
on_changes_click?: (branch_name: string) => void
78+
on_commit_click?: (
79+
repo_name: string,
80+
commit_hash: string,
81+
type: 'Commit' | 'CommitMessage',
82+
commit_message?: string,
83+
) => void
84+
on_skill_click?: (agent: string, repo: string, skill_name: string) => void
7785
}
7886

7987
export const Main: React.FC<Props> = (props) => {
@@ -545,6 +553,9 @@ export const Main: React.FC<Props> = (props) => {
545553
voice_input_push_to_talk={props.voice_input_push_to_talk}
546554
bottom_spacer_height={props.bottom_spacer_height}
547555
on_preview_prompt={props.on_preview_prompt}
556+
on_changes_click={props.on_changes_click}
557+
on_commit_click={props.on_commit_click}
558+
on_skill_click={props.on_skill_click}
548559
on_install_browser_extension={handle_install_browser_extension}
549560
/>
550561
)

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ type Props = {
111111
voice_input_push_to_talk: boolean
112112
bottom_spacer_height?: number
113113
on_preview_prompt: () => void
114+
on_changes_click?: (branch_name: string) => void
115+
on_commit_click?: (
116+
repo_name: string,
117+
commit_hash: string,
118+
type: 'Commit' | 'CommitMessage',
119+
commit_message?: string,
120+
) => void
121+
on_skill_click?: (agent: string, repo: string, skill_name: string) => void
114122
on_install_browser_extension: () => void
115123
}
116124

@@ -365,6 +373,9 @@ export const MainView: React.FC<Props> = (props) => {
365373
on_paste_long_text={props.on_paste_long_text}
366374
on_open_pasted_text={props.on_open_pasted_text}
367375
on_paste_url={props.on_paste_url}
376+
on_changes_click={props.on_changes_click}
377+
on_commit_click={props.on_commit_click}
378+
on_skill_click={props.on_skill_click}
368379
on_preview_prompt={props.on_preview_prompt}
369380
is_recording={props.is_recording}
370381
on_recording_started={props.on_recording_started}

0 commit comments

Comments
 (0)