Skip to content

Commit 7f1f21b

Browse files
committed
Remove instructions placement configuration and prioritize recently modified files in context collection
1 parent edcbfca commit 7f1f21b

11 files changed

Lines changed: 116 additions & 244 deletions

File tree

‎packages/vscode/package.json‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,13 +1472,6 @@
14721472
"high"
14731473
]
14741474
},
1475-
"instructionsPlacement": {
1476-
"type": "string",
1477-
"enum": [
1478-
"above-and-below",
1479-
"below-only"
1480-
]
1481-
},
14821475
"isPinned": {
14831476
"type": "boolean"
14841477
}

‎packages/vscode/src/migrations/migrate-state-to-settings.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ type OldToolConfig = {
3535
temperature: number
3636
reasoning_effort?: string
3737
max_concurrency?: number
38-
instructions_placement?: string
3938
}
4039

4140
type NewToolConfig = {
@@ -45,7 +44,6 @@ type NewToolConfig = {
4544
reasoningEffort?: string
4645
isDefault?: boolean
4746
maxConcurrency?: number
48-
instructionsPlacement?: string
4947
}
5048

5149
async function migrateProviders(context: vscode.ExtensionContext) {
@@ -92,9 +90,6 @@ function transformToolConfig(
9290
if (oldConfig.max_concurrency !== undefined) {
9391
newConfig.maxConcurrency = oldConfig.max_concurrency
9492
}
95-
if (oldConfig.instructions_placement !== undefined) {
96-
newConfig.instructionsPlacement = oldConfig.instructions_placement
97-
}
9893
return newConfig
9994
}
10095

‎packages/vscode/src/services/model-providers-manager.ts‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ export type Provider = BuiltInProvider | CustomProvider
1919

2020
export type ReasoningEffort = 'none' | 'low' | 'medium' | 'high'
2121

22-
export type InstructionsPlacement = 'above-and-below' | 'below-only'
23-
2422
export type ToolConfig = {
2523
provider_type: string
2624
provider_name: string
2725
model: string
2826
temperature?: number
2927
reasoning_effort?: ReasoningEffort
3028
max_concurrency?: number
31-
instructions_placement?: InstructionsPlacement
3229
is_pinned?: boolean
3330
}
3431

@@ -39,7 +36,6 @@ export const get_tool_config_id = (config: ToolConfig): string => {
3936
config.temperature,
4037
config.reasoning_effort ?? '',
4138
config.max_concurrency ?? '',
42-
config.instructions_placement ?? ''
4339
]
4440
.filter((v) => v !== null && v !== undefined)
4541
.join(':')
@@ -167,7 +163,6 @@ export class ModelProvidersManager {
167163
temperature?: number
168164
reasoningEffort?: ReasoningEffort
169165
maxConcurrency?: number
170-
instructionsPlacement?: InstructionsPlacement
171166
isPinned?: boolean
172167
}[]
173168
>(settings_key, [])
@@ -182,7 +177,6 @@ export class ModelProvidersManager {
182177
temperature: sc.temperature,
183178
reasoning_effort: sc.reasoningEffort,
184179
max_concurrency: sc.maxConcurrency,
185-
instructions_placement: sc.instructionsPlacement,
186180
is_pinned: sc.isPinned
187181
}
188182
})
@@ -214,8 +208,6 @@ export class ModelProvidersManager {
214208
new_config.reasoningEffort = c.reasoning_effort
215209
if (c.max_concurrency !== undefined)
216210
new_config.maxConcurrency = c.max_concurrency
217-
if (c.instructions_placement !== undefined)
218-
new_config.instructionsPlacement = c.instructions_placement
219211
if (c.is_pinned) new_config.isPinned = c.is_pinned
220212
return new_config
221213
})
@@ -238,9 +230,7 @@ export class ModelProvidersManager {
238230
(settings_config.reasoningEffort ?? undefined) ===
239231
(tool_config.reasoning_effort ?? undefined) &&
240232
(settings_config.maxConcurrency ?? undefined) ===
241-
(tool_config.max_concurrency ?? undefined) &&
242-
(settings_config.instructionsPlacement ?? undefined) ===
243-
(tool_config.instructions_placement ?? undefined)
233+
(tool_config.max_concurrency ?? undefined)
244234
)
245235
}
246236

@@ -256,7 +246,6 @@ export class ModelProvidersManager {
256246
reasoningEffort?: ReasoningEffort
257247
isDefault?: boolean
258248
maxConcurrency?: number
259-
instructionsPlacement?: InstructionsPlacement
260249
isPinned?: boolean
261250
}[]
262251
>(settings_key, [])
@@ -275,8 +264,6 @@ export class ModelProvidersManager {
275264
temperature: default_config_from_settings.temperature,
276265
reasoning_effort: default_config_from_settings.reasoningEffort,
277266
max_concurrency: default_config_from_settings.maxConcurrency,
278-
instructions_placement:
279-
default_config_from_settings.instructionsPlacement,
280267
is_pinned: default_config_from_settings.isPinned
281268
}
282269
const validated_config = this._validate_tool_config(tool_config)

‎packages/vscode/src/utils/files-collector.ts‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,30 @@ export class FilesCollector {
5151
}
5252

5353
const context_files = [...new Set(context_files_list)]
54-
context_files.sort((a, b) => natural_sort(a, b))
54+
const now = Date.now()
55+
const ONE_HOUR = 60 * 60 * 1000
56+
57+
context_files.sort((a, b) => {
58+
try {
59+
const mtime_a = fs.statSync(a).mtime.getTime()
60+
const mtime_b = fs.statSync(b).mtime.getTime()
61+
62+
const is_recent_a = now - mtime_a < ONE_HOUR
63+
const is_recent_b = now - mtime_b < ONE_HOUR
64+
65+
if (is_recent_a != is_recent_b) {
66+
return is_recent_a ? 1 : -1
67+
}
68+
69+
if (is_recent_a) {
70+
return mtime_a - mtime_b
71+
}
72+
73+
return natural_sort(a, b)
74+
} catch (error) {
75+
return natural_sort(a, b)
76+
}
77+
})
5578

5679
let collected_text = ''
5780

‎packages/vscode/src/views/panel/backend/message-handlers/handle-copy-prompt.ts‎

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -108,62 +108,42 @@ export const handle_copy_prompt = async (params: {
108108

109109
const instructions = replace_selection_placeholder(final_instruction)
110110

111-
let pre_context_instructions = instructions
112-
let post_context_instructions = instructions
111+
let processed_instructions = instructions
113112

114-
if (instructions.includes('#Changes:')) {
113+
if (processed_instructions.includes('#Changes:')) {
115114
const is_no_context_web_mode =
116115
params.panel_provider.mode == MODE.WEB &&
117116
params.panel_provider.web_prompt_type == 'no-context'
118117

119-
pre_context_instructions = await replace_changes_symbol({
120-
instruction: pre_context_instructions,
118+
processed_instructions = await replace_changes_symbol({
119+
instruction: processed_instructions,
121120
workspace_provider: params.panel_provider.workspace_provider,
122121
is_no_context_web_mode
123122
})
124-
post_context_instructions = await replace_changes_symbol({
125-
instruction: post_context_instructions,
126-
after_context: true,
127-
workspace_provider: params.panel_provider.workspace_provider
128-
})
129123
}
130124

131-
if (instructions.includes('#Commit:')) {
132-
pre_context_instructions = await replace_commit_symbol({
133-
instruction: pre_context_instructions
134-
})
135-
post_context_instructions = await replace_commit_symbol({
136-
instruction: post_context_instructions,
137-
after_context: true
125+
if (processed_instructions.includes('#Commit:')) {
126+
processed_instructions = await replace_commit_symbol({
127+
instruction: processed_instructions
138128
})
139129
}
140130

141-
if (instructions.includes('#ContextAtCommit:')) {
142-
pre_context_instructions = await replace_context_at_commit_symbol({
143-
instruction: pre_context_instructions,
144-
workspace_provider: params.panel_provider.workspace_provider
145-
})
146-
post_context_instructions = await replace_context_at_commit_symbol({
147-
instruction: post_context_instructions,
148-
after_context: true,
131+
if (processed_instructions.includes('#ContextAtCommit:')) {
132+
processed_instructions = await replace_context_at_commit_symbol({
133+
instruction: processed_instructions,
149134
workspace_provider: params.panel_provider.workspace_provider
150135
})
151136
}
152137

153-
if (instructions.includes('#SavedContext:')) {
154-
pre_context_instructions = await replace_saved_context_placeholder({
155-
instruction: pre_context_instructions,
156-
context: params.panel_provider.context,
157-
workspace_provider: params.panel_provider.workspace_provider
158-
})
159-
post_context_instructions = await replace_saved_context_placeholder({
160-
instruction: post_context_instructions,
138+
if (processed_instructions.includes('#SavedContext:')) {
139+
processed_instructions = await replace_saved_context_placeholder({
140+
instruction: processed_instructions,
161141
context: params.panel_provider.context,
162142
workspace_provider: params.panel_provider.workspace_provider,
163-
just_opening_tag: true
164143
})
165144
}
166145

146+
let system_instructions_xml = ''
167147
if (params.panel_provider.web_prompt_type == 'edit-context') {
168148
const edit_format =
169149
params.panel_provider.mode == MODE.WEB
@@ -185,15 +165,19 @@ export const handle_copy_prompt = async (params: {
185165
const edit_format_instructions =
186166
config.get<string>(instructions_key) || default_instructions
187167
if (edit_format_instructions) {
188-
const system_instructions = `<system>\n${edit_format_instructions}\n</system>`
189-
pre_context_instructions += `\n${system_instructions}`
190-
post_context_instructions = `${system_instructions}\n${post_context_instructions}`
168+
system_instructions_xml = `<system>\n${edit_format_instructions}\n</system>`
191169
}
192170
}
193171

194172
const text = context_text
195-
? `${pre_context_instructions}\n<files>\n${context_text}</files>\n${post_context_instructions}`
196-
: pre_context_instructions
173+
? `${
174+
system_instructions_xml ? system_instructions_xml + '\n' : ''
175+
}<files>\n${context_text}</files>\n${
176+
system_instructions_xml ? system_instructions_xml + '\n' : ''
177+
}${processed_instructions}`
178+
: `${
179+
system_instructions_xml ? system_instructions_xml + '\n' : ''
180+
}${processed_instructions}`
197181
vscode.env.clipboard.writeText(text.trim())
198182
} else {
199183
vscode.window.showWarningMessage(

‎packages/vscode/src/views/panel/backend/message-handlers/handle-edit-context.ts‎

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ const get_edit_context_config = async (
100100
if (config.reasoning_effort) {
101101
description_parts.push(`${config.reasoning_effort}`)
102102
}
103-
if (config.instructions_placement == 'below-only') {
104-
description_parts.push('cache-enabled')
105-
}
106103

107104
const buttons: vscode.QuickInputButton[] = []
108105

@@ -258,54 +255,33 @@ const perform_context_editing = async (params: {
258255
instructions = replace_selection_placeholder(instructions)
259256
}
260257

261-
let pre_context_instructions = instructions
262-
let post_context_instructions = instructions
258+
let processed_instructions = instructions
263259

264-
if (pre_context_instructions.includes('#Changes:')) {
265-
pre_context_instructions = await replace_changes_symbol({
266-
instruction: pre_context_instructions,
267-
workspace_provider: params.file_tree_provider
268-
})
269-
post_context_instructions = await replace_changes_symbol({
270-
instruction: post_context_instructions,
271-
after_context: true,
260+
if (processed_instructions.includes('#Changes:')) {
261+
processed_instructions = await replace_changes_symbol({
262+
instruction: processed_instructions,
272263
workspace_provider: params.file_tree_provider
273264
})
274265
}
275266

276-
if (pre_context_instructions.includes('#Commit:')) {
277-
pre_context_instructions = await replace_commit_symbol({
278-
instruction: pre_context_instructions
279-
})
280-
post_context_instructions = await replace_commit_symbol({
281-
instruction: post_context_instructions,
282-
after_context: true
267+
if (processed_instructions.includes('#Commit:')) {
268+
processed_instructions = await replace_commit_symbol({
269+
instruction: processed_instructions
283270
})
284271
}
285272

286-
if (pre_context_instructions.includes('#ContextAtCommit:')) {
287-
pre_context_instructions = await replace_context_at_commit_symbol({
288-
instruction: pre_context_instructions,
289-
workspace_provider: params.file_tree_provider
290-
})
291-
post_context_instructions = await replace_context_at_commit_symbol({
292-
instruction: post_context_instructions,
293-
after_context: true,
273+
if (processed_instructions.includes('#ContextAtCommit:')) {
274+
processed_instructions = await replace_context_at_commit_symbol({
275+
instruction: processed_instructions,
294276
workspace_provider: params.file_tree_provider
295277
})
296278
}
297279

298-
if (pre_context_instructions.includes('#SavedContext:')) {
299-
pre_context_instructions = await replace_saved_context_placeholder({
300-
instruction: pre_context_instructions,
301-
context: params.context,
302-
workspace_provider: params.file_tree_provider
303-
})
304-
post_context_instructions = await replace_saved_context_placeholder({
305-
instruction: post_context_instructions,
280+
if (processed_instructions.includes('#SavedContext:')) {
281+
processed_instructions = await replace_saved_context_placeholder({
282+
instruction: processed_instructions,
306283
context: params.context,
307284
workspace_provider: params.file_tree_provider,
308-
just_opening_tag: true
309285
})
310286
}
311287

@@ -380,26 +356,17 @@ const perform_context_editing = async (params: {
380356
}[edit_format]
381357
const edit_format_instructions =
382358
config.get<string>(instructions_key) || default_instructions
383-
let loop_pre_context_instructions = pre_context_instructions
384-
let loop_post_context_instructions = post_context_instructions
385359

360+
let system_instructions_xml = ''
386361
if (edit_format_instructions) {
387-
const system_instructions = `<system>\n${edit_format_instructions}\n</system>`
388-
loop_pre_context_instructions += `\n${system_instructions}`
389-
loop_post_context_instructions = `${system_instructions}\n${loop_post_context_instructions}`
362+
system_instructions_xml = `<system>\n${edit_format_instructions}\n</system>`
390363
}
391364

392-
// Use instructions placement setting to determine message structure
393-
const instructions_placement =
394-
edit_context_config.instructions_placement || 'above-and-below'
395-
let content: string
396-
if (instructions_placement == 'below-only') {
397-
// Place instructions only below context for better caching
398-
content = `${files}\n${loop_post_context_instructions}`
399-
} else {
400-
// Default: place instructions above and below context for better adherence
401-
content = `${loop_pre_context_instructions}\n${files}\n${loop_post_context_instructions}`
402-
}
365+
const content = `${
366+
system_instructions_xml ? system_instructions_xml + '\n' : ''
367+
}${files}\n${
368+
system_instructions_xml ? system_instructions_xml + '\n' : ''
369+
}${processed_instructions}`
403370

404371
const system_instructions = vscode.workspace
405372
.getConfiguration('codeWebChat')

0 commit comments

Comments
 (0)