Skip to content

Commit 3c05a50

Browse files
committed
Merge branch 'dev'
2 parents 92a2eea + bcd2656 commit 3c05a50

66 files changed

Lines changed: 716 additions & 468 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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<a href="https://marketplace.visualstudio.com/items?itemName=robertpiosik.gemini-coder" target="_blank"><img src="https://img.shields.io/badge/Install-VS_Code_Marketplace-blue" alt="Get from Visual Studio Code Marketplace" /></a> <a href="https://open-vsx.org/extension/robertpiosik/gemini-coder" target="_blank"><img src="https://img.shields.io/badge/Install-Open_VSX_Registry-a60ee5" alt="Get from Open VSX Registry" /></a> <a href="https://github.com/robertpiosik/CodeWebChat/blob/dev/LICENSE" target="_blank"><img src="https://img.shields.io/badge/License-GPL--3.0-green.svg" alt="GPL-3.0 license" /></a>
44

5-
**AI coding without agents.** Guide the model to production-grade code with engineer-level control over context. Community-driven, free and open-source.
5+
**The privacy AI coding without agents.** Guide the model to production-grade code with engineer-level control over context. Community-driven, free and open-source.
66

77
Works with VS Code, and forks like Cursor, Windsurf, etc.
88

@@ -25,17 +25,19 @@ Works with VS Code, and forks like Cursor, Windsurf, etc.
2525

2626
Code Web Chat helps you use your favorite coding web tools like ChatGPT's canvas. The idea to initialize chatbots is borrowed from [Firefox](https://support.mozilla.org/en-US/kb/ai-chatbot) and because there is no further automation once the prompt is sent, by using CWC you're not violating their Terms of Use. Contributors should not submit pull requests implementing further chat automations of any kind, as these will be kindly rejected.
2727

28-
🧑‍💻 **Guide the model with context**
28+
🧑‍💻 **The limitations of LLMs**
2929

3030
Large language models (LLMs) are trained on vast datasets targeting many use cases. For code generation, a model's training involves analyzing millions of simulated problem-solving flows, such as arriving at the accepted answer from a given StackOverflow question. For the purpose of agentic coding, models are trained on an additional layer of data that simulates gathering context and planning its next steps.
3131

3232
Because the model is only as smart as examples it has seen in its pre-training stage, the possible coverage of real-world problems when approached at a high level is fundamentally limited.
3333

3434
Therefore, CWC is designed to align with LLMs' true capabilities—that is, code generation in a controlled signal-to-noise ratio environment. Controlled by you, the engineer.
3535

36-
🙋 **Meet the non-agentic workflow**
36+
🙋 **Guide the model with context**
3737

38-
Select folders and files for context, enter prompt, and send message via...
38+
Unlike coding agents that require detailed instructions to understand your intent and locate relevant files, CWC lets you provide context up front, making prompts simpler and responses faster and more accurate.
39+
40+
Select folders and files, enter prompt, and send message via...
3941

4042
- new chat—to continue in the connected browser
4143
- API call—to use a model provider of choice
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './search-paths'
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { search_paths } from './search-paths'
2+
3+
describe('search_paths', () => {
4+
const paths = ['src/index.ts', 'src/routes/HomePage.tsx', 'src/utils.py']
5+
6+
it('should return all paths for an empty search', () => {
7+
expect(search_paths({ paths, search_value: '' })).toEqual(paths)
8+
})
9+
10+
it('should find "src/index.ts" with query "index"', () => {
11+
const result = search_paths({ paths, search_value: 'index' })
12+
expect(result).toHaveLength(1)
13+
expect(result[0]).toBe('src/index.ts')
14+
})
15+
16+
it('should find "src/index.ts" with query "indexts"', () => {
17+
const result = search_paths({ paths, search_value: 'indexts' })
18+
expect(result).toHaveLength(1)
19+
expect(result[0]).toBe('src/index.ts')
20+
})
21+
22+
it('should find "src/index.ts" with query "srcindex"', () => {
23+
const result = search_paths({ paths, search_value: 'srcindex' })
24+
expect(result).toHaveLength(1)
25+
expect(result[0]).toBe('src/index.ts')
26+
})
27+
28+
it('should find "src/routes/HomePage.tsx" with query "srcpagetsx"', () => {
29+
const result = search_paths({ paths, search_value: 'srcpagetsx' })
30+
expect(result).toHaveLength(1)
31+
expect(result[0]).toBe('src/routes/HomePage.tsx')
32+
})
33+
34+
it('should find "src/routes/HomePage.tsx" with query "srcroutepagetsx"', () => {
35+
const result = search_paths({ paths, search_value: 'srcroutepagetsx' })
36+
expect(result).toHaveLength(1)
37+
expect(result[0]).toBe('src/routes/HomePage.tsx')
38+
})
39+
40+
it('should not find "src/routes/HomePage.tsx" with query "srcagetsx"', () => {
41+
const result = search_paths({ paths, search_value: 'srcagetsx' })
42+
expect(result).toHaveLength(0)
43+
})
44+
45+
it('should return an empty array if no match is found', () => {
46+
const result = search_paths({ paths, search_value: 'nomatch' })
47+
expect(result).toHaveLength(0)
48+
})
49+
50+
it('should be case-insensitive', () => {
51+
const result = search_paths({ paths, search_value: 'INDEX.TS' })
52+
expect(result).toHaveLength(1)
53+
expect(result[0]).toBe('src/index.ts')
54+
})
55+
})
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const get_path_parts = (path: string): string[] => {
2+
return path
3+
.split(/[/\\]/)
4+
.flatMap((part) => {
5+
const with_spaces = part
6+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
7+
.replace(/[._-]/g, ' ')
8+
return with_spaces.split(/\s+/)
9+
})
10+
.map((p) => p.toLowerCase())
11+
.filter((p) => p.length > 0)
12+
}
13+
14+
const is_prefix_match_recursive = (params: {
15+
query: string
16+
parts: string[]
17+
part_idx: number
18+
memo: Record<string, boolean>
19+
}): boolean => {
20+
const key = `${params.part_idx}:${params.query.length}`
21+
if (params.memo[key] !== undefined) {
22+
return params.memo[key]
23+
}
24+
25+
if (params.query.length === 0) {
26+
return true
27+
}
28+
29+
if (params.part_idx >= params.parts.length) {
30+
return false
31+
}
32+
33+
// Option 1: Skip current part and try to match the query with the rest of the parts.
34+
if (
35+
is_prefix_match_recursive({
36+
query: params.query,
37+
parts: params.parts,
38+
part_idx: params.part_idx + 1,
39+
memo: params.memo
40+
})
41+
) {
42+
return (params.memo[key] = true)
43+
}
44+
45+
// Option 2: Match a prefix of the query with a prefix of the current part.
46+
const part = params.parts[params.part_idx]
47+
for (let i = 1; i <= params.query.length; i++) {
48+
const query_prefix = params.query.substring(0, i)
49+
if (part.startsWith(query_prefix)) {
50+
if (
51+
is_prefix_match_recursive({
52+
query: params.query.substring(i),
53+
parts: params.parts,
54+
part_idx: params.part_idx + 1,
55+
memo: params.memo
56+
})
57+
) {
58+
return (params.memo[key] = true)
59+
}
60+
} else {
61+
break
62+
}
63+
}
64+
65+
return (params.memo[key] = false)
66+
}
67+
68+
export const search_paths = (params: {
69+
paths: string[]
70+
search_value: string
71+
}): string[] => {
72+
if (!params.search_value) {
73+
return params.paths
74+
}
75+
return params.paths.filter((path_item) => {
76+
const search_lower = params.search_value.toLowerCase()
77+
const path_to_search_lower = path_item.toLowerCase()
78+
79+
if (path_to_search_lower.includes(search_lower)) {
80+
return true
81+
}
82+
83+
const query_alphanumeric = search_lower.replace(/[^a-z0-9]/g, '')
84+
if (!query_alphanumeric) {
85+
return false
86+
}
87+
88+
const parts = get_path_parts(path_item)
89+
return is_prefix_match_recursive({
90+
query: query_alphanumeric,
91+
parts,
92+
part_idx: 0,
93+
memo: {}
94+
})
95+
})
96+
}

‎packages/ui/src/components/editor/common/DropdownMenu/DropdownMenu.module.scss‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
position: absolute;
33
top: calc(100% + var(--padding-4px));
44
right: 0;
5-
background-color: var(--vscode-menu-background);
6-
border: 1px solid var(--vscode-menu-border);
5+
background-color: var(--vscode-quickInput-background);
76
border-radius: var(--border-radius-8px);
8-
box-shadow: 0 2px 8px var(--vscode-widget-shadow);
7+
border: 1px solid var(--vscode-widget-border);
8+
box-shadow: 0 0 8px 2px var(--vscode-widget-shadow);
99
z-index: 1;
1010
padding: var(--padding-4px);
1111
width: max-content;
@@ -21,13 +21,13 @@
2121
padding: 0 var(--padding-6px);
2222
height: 24px;
2323
cursor: pointer;
24-
color: var(--vscode-menu-foreground);
24+
color: var(--vscode-quickInput-foreground);
2525
white-space: nowrap;
2626
border-radius: var(--border-radius-4px);
2727

2828
&:hover,
2929
&[data-selected='true'] {
30-
background-color: var(--vscode-menu-selectionBackground);
30+
background-color: var(--vscode-list-activeSelectionBackground);
3131
& > span {
3232
color: var(--vscode-menu-selectionForeground);
3333
}

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.module.scss‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@
118118
margin: 0;
119119
}
120120

121+
.tab-hint {
122+
display: inline-flex;
123+
align-items: center;
124+
justify-content: center;
125+
color: var(--cwc-text-color);
126+
opacity: 0.5;
127+
font-size: var(--font-size-10px);
128+
padding: 0 3px;
129+
margin-left: 2px;
130+
font-weight: 500;
131+
border: 1px solid var(--cwc-border-color);
132+
border-radius: 5px;
133+
}
134+
121135
.selection-keyword {
122136
background-color: var(--vscode-editor-selectionBackground);
123137
border-radius: var(--border-radius-2px);

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.stories.tsx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const Empty = () => (
2222
on_hash_sign_click={() => console.log('# clicked')}
2323
on_search_click={() => console.log('Search clicked')}
2424
on_submit_with_control={() => console.log('Submitted with control')}
25+
context_file_paths={[]}
2526
on_curly_braces_click={() => {}}
2627
/>
2728
)
@@ -43,6 +44,7 @@ export const WithText = () => (
4344
on_hash_sign_click={() => console.log('# clicked')}
4445
on_search_click={() => console.log('Search clicked')}
4546
on_submit_with_control={() => console.log('Submitted with control')}
47+
context_file_paths={[]}
4648
on_curly_braces_click={() => {}}
4749
/>
4850
)
@@ -64,6 +66,7 @@ export const LongText = () => (
6466
on_hash_sign_click={() => console.log('# clicked')}
6567
on_search_click={() => console.log('Search clicked')}
6668
on_submit_with_control={() => console.log('Submitted with control')}
69+
context_file_paths={[]}
6770
on_curly_braces_click={() => {}}
6871
/>
6972
)
@@ -85,6 +88,7 @@ export const WithPlaceholderSavedContext = () => (
8588
on_hash_sign_click={() => console.log('# clicked')}
8689
is_web_mode={false}
8790
on_submit_with_control={() => console.log('Submitted with control')}
91+
context_file_paths={[]}
8892
on_curly_braces_click={() => {}}
8993
/>
9094
)
@@ -106,6 +110,7 @@ export const WithPlaceholderSelection = () => (
106110
on_hash_sign_click={() => console.log('# clicked')}
107111
is_web_mode={false}
108112
on_submit_with_control={() => console.log('Submitted with control')}
113+
context_file_paths={[]}
109114
on_curly_braces_click={() => {}}
110115
/>
111116
)
@@ -138,6 +143,29 @@ export const WithEditFormatSelector = () => {
138143
truncated: 'Use truncated...',
139144
diff: 'Use diff...'
140145
}}
146+
context_file_paths={[]}
141147
/>
142148
)
143149
}
150+
151+
export const WithFilePaths = () => (
152+
<ChatInput
153+
value="This is about `path/to/my/file.ts` and not about `another/file.txt`"
154+
chat_history={[]}
155+
on_change={(value) => console.log('Changed:', value)}
156+
on_submit={() => console.log('Submitted')}
157+
on_copy={() => console.log('Copied')}
158+
is_connected={true}
159+
is_in_code_completions_mode={false}
160+
has_active_selection={false}
161+
has_active_editor={true}
162+
on_caret_position_change={(pos) => console.log('Caret position:', pos)}
163+
is_web_mode={false}
164+
on_at_sign_click={() => console.log('@ clicked')}
165+
on_hash_sign_click={() => console.log('# clicked')}
166+
on_search_click={() => console.log('Search clicked')}
167+
on_submit_with_control={() => console.log('Submitted with control')}
168+
on_curly_braces_click={() => {}}
169+
context_file_paths={['path/to/my/file.ts']}
170+
/>
171+
)

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.tsx‎

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRef, useEffect, useMemo } from 'react'
1+
import { useRef, useEffect, useMemo, useState } from 'react'
22
import styles from './ChatInput.module.scss'
33
import TextareaAutosize from 'react-textarea-autosize'
44
import cn from 'classnames'
@@ -7,6 +7,7 @@ import { get_highlighted_text } from './utils/get-highlighted-text'
77
import { use_handlers } from './hooks/use-handlers'
88
import { use_dropdown } from './hooks/use-dropdown'
99
import { DropdownMenu } from '../../common/DropdownMenu'
10+
import { search_paths } from '@shared/utils/search-paths'
1011

1112
export type EditFormat = 'whole' | 'truncated' | 'diff'
1213

@@ -36,12 +37,14 @@ export type ChatInputProps = {
3637
edit_format?: EditFormat
3738
on_edit_format_change?: (format: EditFormat) => void
3839
edit_format_instructions?: Record<EditFormat, string>
40+
context_file_paths?: string[]
3941
}
4042

4143
export const ChatInput: React.FC<ChatInputProps> = (props) => {
4244
const textarea_ref = useRef<HTMLTextAreaElement>(null)
4345
const highlight_ref = useRef<HTMLDivElement>(null)
4446
const container_ref = useRef<HTMLDivElement>(null)
47+
const [caret_position, set_caret_position] = useState(0)
4548
const {
4649
is_dropdown_open,
4750
toggle_dropdown,
@@ -147,6 +150,28 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
147150
handle_key_down(e)
148151
}
149152

153+
const show_tab_hint = useMemo(() => {
154+
const value = props.value
155+
if (
156+
!value ||
157+
caret_position != value.length ||
158+
value.endsWith(' ') ||
159+
!props.context_file_paths
160+
) {
161+
return false
162+
}
163+
const last_word = value.trim().split(/\s+/).pop()
164+
165+
if (last_word && last_word.length >= 3) {
166+
const matching_paths = search_paths({
167+
paths: props.context_file_paths,
168+
search_value: last_word
169+
})
170+
return matching_paths.length == 1
171+
}
172+
173+
return false
174+
}, [props.value, caret_position, props.context_file_paths])
150175
return (
151176
<div className={styles.container}>
152177
{props.has_active_selection && props.is_in_code_completions_mode && (
@@ -196,16 +221,24 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
196221
{get_highlighted_text({
197222
text: props.value,
198223
is_in_code_completions_mode: props.is_in_code_completions_mode,
199-
has_active_selection: props.has_active_selection
224+
has_active_selection: props.has_active_selection,
225+
context_file_paths: props.context_file_paths ?? []
200226
})}
227+
{show_tab_hint && <span className={styles['tab-hint']}>TAB</span>}
201228
</div>
202229
<TextareaAutosize
203230
ref={textarea_ref}
204231
placeholder={placeholder}
205232
value={props.value}
206-
onChange={handle_input_change}
233+
onChange={(e) => {
234+
handle_input_change(e)
235+
set_caret_position(e.target.selectionStart)
236+
}}
207237
onKeyDown={custom_handle_key_down}
208-
onSelect={handle_select}
238+
onSelect={(e) => {
239+
handle_select(e)
240+
set_caret_position(e.currentTarget.selectionStart)
241+
}}
209242
autoFocus
210243
className={styles.textarea}
211244
minRows={2}

0 commit comments

Comments
 (0)