Skip to content

Commit 9b5bc8f

Browse files
committed
Implement Prune Context mode with dedicated prompt instructions, history management, tool configurations, and compact token count display
1 parent 98ce5fc commit 9b5bc8f

12 files changed

Lines changed: 118 additions & 15 deletions

‎packages/vscode/src/context/providers/open-editors/open-editors-provider.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export class OpenEditorsProvider
2929
private _shared_state: SharedFileState
3030
private _config_change_handler: vscode.Disposable
3131
private _workspace_provider: WorkspaceProvider
32+
private _use_compact_token_count: boolean = false
33+
34+
public set_use_compact_token_count(use_compact: boolean): void {
35+
if (this._use_compact_token_count != use_compact) {
36+
this._use_compact_token_count = use_compact
37+
this.refresh()
38+
}
39+
}
3240

3341
constructor(
3442
workspace_folders: vscode.WorkspaceFolder[],
@@ -184,7 +192,9 @@ export class OpenEditorsProvider
184192

185193
element.checkboxState = checkbox_state
186194

187-
const token_count = element.tokenCount
195+
const token_count = this._use_compact_token_count
196+
? element.compactTokenCount
197+
: element.tokenCount
188198

189199
let final_description = element.description || ''
190200

‎packages/vscode/src/context/providers/workspace/workspace-provider.ts‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ export class WorkspaceProvider
6666
public gitignore_initialization: Promise<void>
6767
public ranges_initialization: Promise<void>
6868

69+
private _use_compact_token_count: boolean = false
70+
71+
public set_use_compact_token_count(use_compact: boolean): void {
72+
if (this._use_compact_token_count != use_compact) {
73+
this._use_compact_token_count = use_compact
74+
this.refresh()
75+
}
76+
}
77+
6978
constructor(
7079
workspace_folders: vscode.WorkspaceFolder[],
7180
private _context: vscode.ExtensionContext
@@ -523,8 +532,12 @@ export class WorkspaceProvider
523532

524533
element.checkboxState = checkbox_state
525534

526-
const total_token_count = element.tokenCount
527-
const selected_token_count = element.selectedTokenCount
535+
const total_token_count = this._use_compact_token_count
536+
? element.compactTokenCount
537+
: element.tokenCount
538+
const selected_token_count = this._use_compact_token_count
539+
? element.selectedCompactTokenCount
540+
: element.selectedTokenCount
528541

529542
const formatted_total =
530543
total_token_count !== undefined && total_token_count > 0
@@ -700,11 +713,12 @@ export class WorkspaceProvider
700713
vscode.TreeItemCheckboxState.Unchecked,
701714
false, // Is not symbolic link
702715
false, // Is not open file
703-
total_tokens,
704-
selected_tokens,
716+
total_tokens.total,
717+
total_tokens.compact,
718+
selected_tokens.total,
719+
selected_tokens.compact,
705720
undefined,
706-
true, // Is workspace root
707-
undefined
721+
true // Is workspace root
708722
)
709723
)
710724
if (context_view) {

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export type CodeCompletionsConfigs = ToolConfig[]
4545
export type EditContextConfigs = ToolConfig[]
4646
export type IntelligentUpdateConfigs = ToolConfig[]
4747
export type CommitMessagesConfigs = ToolConfig[]
48+
export type PruneContextConfigs = ToolConfig[]
4849

4950
export class ModelProvidersManager {
5051
private _providers: Provider[] = []
@@ -421,6 +422,18 @@ export class ModelProvidersManager {
421422
)
422423
}
423424

425+
public async get_prune_context_tool_configs(): Promise<PruneContextConfigs> {
426+
await this._load_promise
427+
return this._get_tool_configs_from_settings('configurationsForPruneContext')
428+
}
429+
430+
public async save_prune_context_tool_configs(configs: PruneContextConfigs) {
431+
await this._save_tool_configs_to_settings(
432+
'configurationsForPruneContext',
433+
configs
434+
)
435+
}
436+
424437
public async update_provider_name_in_configs(params: {
425438
old_name: string
426439
new_name: string
@@ -432,7 +445,8 @@ export class ModelProvidersManager {
432445
'configurationsForCodeCompletions',
433446
'configurationsForEditContext',
434447
'configurationsForIntelligentUpdate',
435-
'configurationsForCommitMessages'
448+
'configurationsForCommitMessages',
449+
'configurationsForPruneContext'
436450
]
437451

438452
for (const key of settings_keys) {

‎packages/vscode/src/views/panel/backend/message-handlers/handle-get-api-tool-configurations.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ export const handle_get_api_tool_configurations = async (
1515
const [
1616
edit_context_configs,
1717
code_completions_configs,
18-
default_code_completions_config
18+
default_code_completions_config,
19+
prune_context_configs
1920
] = await Promise.all([
2021
providers_manager.get_edit_context_tool_configs(),
2122
providers_manager.get_code_completions_tool_configs(),
22-
providers_manager.get_default_code_completions_config()
23+
providers_manager.get_default_code_completions_config(),
24+
providers_manager.get_prune_context_tool_configs()
2325
])
2426

2527
const is_config_default = (
@@ -46,6 +48,10 @@ export const handle_get_api_tool_configurations = async (
4648
...config,
4749
id: get_tool_config_id(config),
4850
is_default: is_config_default(config, default_code_completions_config)
51+
})),
52+
'prune-context': prune_context_configs.map((config) => ({
53+
...config,
54+
id: get_tool_config_id(config)
4955
}))
5056
}
5157

‎packages/vscode/src/views/panel/backend/message-handlers/handle-get-history.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
HISTORY_CODE_COMPLETIONS_STATE_KEY,
44
HISTORY_EDIT_STATE_KEY,
55
HISTORY_NO_CONTEXT_STATE_KEY,
6+
HISTORY_PRUNE_CONTEXT_STATE_KEY,
67
HistoryEntry
78
} from '@/constants/state-keys'
89
import { PanelProvider } from '@/views/panel/backend/panel-provider'
@@ -21,12 +22,16 @@ export const handle_get_history = (panel_provider: PanelProvider): void => {
2122
const no_context_history = panel_provider.context.workspaceState.get<
2223
HistoryEntry[]
2324
>(HISTORY_NO_CONTEXT_STATE_KEY, [])
25+
const prune_context_history = panel_provider.context.workspaceState.get<
26+
HistoryEntry[]
27+
>(HISTORY_PRUNE_CONTEXT_STATE_KEY, [])
2428

2529
panel_provider.send_message({
2630
command: 'CHAT_HISTORY',
2731
ask: ask_history.map((h) => h.text),
2832
edit_context: edit_history.map((h) => h.text),
2933
no_context: no_context_history.map((h) => h.text),
30-
code_completions: code_completions_history.map((h) => h.text)
34+
code_completions: code_completions_history.map((h) => h.text),
35+
prune_context: prune_context_history.map((h) => h.text)
3136
})
3237
}

‎packages/vscode/src/views/panel/backend/message-handlers/handle-get-instructions.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const handle_get_instructions = (
88
ask: panel_provider.ask_instructions,
99
edit_context: panel_provider.edit_instructions,
1010
no_context: panel_provider.no_context_instructions,
11-
code_completions: panel_provider.code_completion_instructions
11+
code_completions: panel_provider.code_completion_instructions,
12+
prune_context: panel_provider.prune_context_instructions
1213
})
1314
}

‎packages/vscode/src/views/panel/backend/message-handlers/handle-reorder-api-tool-configurations.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,22 @@ export const handle_reorder_api_tool_configurations = async (
4949
reordered_configs
5050
)
5151
}
52+
} else if (message.mode == 'prune-context') {
53+
const current_configs =
54+
await providers_manager.get_prune_context_tool_configs()
55+
const reordered_configs = reordered_ids
56+
.map((id) => {
57+
const found = current_configs.find((p) => get_tool_config_id(p) === id)
58+
if (!found) {
59+
console.error(`Config with id ${id} not found during reorder.`)
60+
return null
61+
}
62+
return found
63+
})
64+
.filter((p): p is ToolConfig => p !== null)
65+
66+
if (reordered_configs.length === current_configs.length) {
67+
await providers_manager.save_prune_context_tool_configs(reordered_configs)
68+
}
5269
}
5370
}

‎packages/vscode/src/views/panel/backend/message-handlers/handle-save-history.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
PINNED_HISTORY_ASK_STATE_KEY,
88
PINNED_HISTORY_CODE_COMPLETIONS_STATE_KEY,
99
PINNED_HISTORY_EDIT_STATE_KEY,
10-
PINNED_HISTORY_NO_CONTEXT_STATE_KEY
10+
PINNED_HISTORY_NO_CONTEXT_STATE_KEY,
11+
HISTORY_PRUNE_CONTEXT_STATE_KEY,
12+
PINNED_HISTORY_PRUNE_CONTEXT_STATE_KEY
1113
} from '@/constants/state-keys'
1214
import { PanelProvider } from '@/views/panel/backend/panel-provider'
1315
import { SaveHistoryMessage } from '@/views/panel/types/messages'
@@ -35,6 +37,10 @@ export const handle_save_history = async (
3537
key = HISTORY_CODE_COMPLETIONS_STATE_KEY
3638
pinned_key = PINNED_HISTORY_CODE_COMPLETIONS_STATE_KEY
3739
break
40+
case 'prune-context':
41+
key = HISTORY_PRUNE_CONTEXT_STATE_KEY
42+
pinned_key = PINNED_HISTORY_PRUNE_CONTEXT_STATE_KEY
43+
break
3844
}
3945
if (key) {
4046
const text_history: string[] = message.messages

‎packages/vscode/src/views/panel/backend/message-handlers/handle-show-history-quick-pick.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
PINNED_HISTORY_CODE_COMPLETIONS_STATE_KEY,
1111
PINNED_HISTORY_EDIT_STATE_KEY,
1212
PINNED_HISTORY_NO_CONTEXT_STATE_KEY,
13+
HISTORY_PRUNE_CONTEXT_STATE_KEY,
14+
PINNED_HISTORY_PRUNE_CONTEXT_STATE_KEY,
1315
HistoryEntry
1416
} from '@/constants/state-keys'
1517
import { PanelProvider } from '@/views/panel/backend/panel-provider'
@@ -50,6 +52,10 @@ export const handle_show_history_quick_pick = async (
5052
history_key = HISTORY_NO_CONTEXT_STATE_KEY
5153
pinned_history_key = PINNED_HISTORY_NO_CONTEXT_STATE_KEY
5254
break
55+
case 'prune-context':
56+
history_key = HISTORY_PRUNE_CONTEXT_STATE_KEY
57+
pinned_history_key = PINNED_HISTORY_PRUNE_CONTEXT_STATE_KEY
58+
break
5359
}
5460

5561
if (!history_key || !pinned_history_key) return
@@ -169,6 +175,9 @@ export const handle_show_history_quick_pick = async (
169175
case 'code-completions':
170176
panel_provider.code_completion_instructions = text
171177
break
178+
case 'prune-context':
179+
panel_provider.prune_context_instructions = text
180+
break
172181
default:
173182
return
174183
}
@@ -178,7 +187,8 @@ export const handle_show_history_quick_pick = async (
178187
ask: panel_provider.ask_instructions,
179188
edit_context: panel_provider.edit_instructions,
180189
no_context: panel_provider.no_context_instructions,
181-
code_completions: panel_provider.code_completion_instructions
190+
code_completions: panel_provider.code_completion_instructions,
191+
prune_context: panel_provider.prune_context_instructions
182192
})
183193
}
184194

‎packages/vscode/src/views/panel/backend/message-handlers/handle-toggle-pinned-api-tool-configuration.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export const handle_toggle_pinned_api_tool_configuration = async (
1717
configs = await providers_manager.get_edit_context_tool_configs()
1818
} else if (mode == 'code-completions') {
1919
configs = await providers_manager.get_code_completions_tool_configs()
20+
} else if (mode == 'prune-context') {
21+
configs = await providers_manager.get_prune_context_tool_configs()
2022
} else {
2123
return
2224
}
@@ -30,6 +32,8 @@ export const handle_toggle_pinned_api_tool_configuration = async (
3032
await providers_manager.save_edit_context_tool_configs(configs)
3133
} else if (mode == 'code-completions') {
3234
await providers_manager.save_code_completions_tool_configs(configs)
35+
} else if (mode == 'prune-context') {
36+
await providers_manager.save_prune_context_tool_configs(configs)
3337
}
3438
await handle_get_api_tool_configurations(panel_provider)
3539
}

0 commit comments

Comments
 (0)