Skip to content

Commit 98ce5fc

Browse files
committed
Introduce prune context functionality with compact token calculation and associated UI updates
1 parent 7d84b36 commit 98ce5fc

22 files changed

Lines changed: 538 additions & 76 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Code with AI in a way that foster codebase understanding and gets you fast and a
4040

4141
## Enabling autofill in browser
4242

43-
Install the zero-setup Connector extension in your favorite browser and never copy and paste again!
43+
Start using [projects](https://help.openai.com/en/articles/10169521-projects-in-chatgpt) (also called [gems](https://gemini.google/pl/overview/gems) or [spaces](https://docs.github.com/en/copilot/concepts/context/spaces)) without a tedious copy and paste!
4444

4545
- [Chrome Web Store](https://chromewebstore.google.com/detail/code-web-chat-connector/ljookipcanaglfaocjbgdicfbdhhjffp)
4646
- [Firefox Add-ons](https://addons.mozilla.org/en-US/firefox/addon/code-web-chat-connector/)

‎packages/shared/src/types/prompt-types.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ export type WebPromptType =
33
| 'edit-context'
44
| 'code-completions'
55
| 'no-context'
6-
export type ApiPromptType = 'edit-context' | 'code-completions'
6+
| 'prune-context'
7+
8+
export type ApiPromptType =
9+
| 'edit-context'
10+
| 'code-completions'
11+
| 'prune-context'

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export namespace Configurations {
1616
}
1717

1818
export type Props = {
19-
api_prompt_type: 'edit-context' | 'code-completions'
19+
api_prompt_type: 'edit-context' | 'code-completions' | 'prune-context'
2020
configurations: Configuration[]
2121
on_configuration_click: (id: string) => void
2222
on_reorder?: (configurations: Configuration[]) => void

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ export namespace Presets {
4343
}
4444

4545
export type Props = {
46-
web_prompt_type: 'ask' | 'edit-context' | 'code-completions' | 'no-context'
46+
web_prompt_type:
47+
| 'ask'
48+
| 'edit-context'
49+
| 'code-completions'
50+
| 'no-context'
51+
| 'prune-context'
4752
is_connected: boolean
4853
has_instructions: boolean
4954
is_in_code_completions_mode: boolean

‎packages/vscode/package.json‎

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,146 @@
11611161
}
11621162
}
11631163
},
1164+
"codeWebChat.chatPresetsForPruneContext": {
1165+
"type": "array",
1166+
"default": [
1167+
{
1168+
"name": "Popular"
1169+
},
1170+
{
1171+
"name": "(1)",
1172+
"chatbot": "ChatGPT"
1173+
},
1174+
{
1175+
"name": "(2)",
1176+
"chatbot": "Claude"
1177+
},
1178+
{
1179+
"name": "(3)",
1180+
"chatbot": "Gemini"
1181+
},
1182+
{
1183+
"name": "(4)",
1184+
"chatbot": "Grok"
1185+
},
1186+
{
1187+
"name": "(5)",
1188+
"chatbot": "DeepSeek"
1189+
},
1190+
{},
1191+
{
1192+
"name": "Others"
1193+
},
1194+
{
1195+
"name": "(6)",
1196+
"chatbot": "AI Studio",
1197+
"systemInstructions": "You're a helpful coding assistant."
1198+
},
1199+
{
1200+
"name": "(7)",
1201+
"chatbot": "Copilot"
1202+
},
1203+
{
1204+
"name": "(8)",
1205+
"chatbot": "Doubao"
1206+
},
1207+
{
1208+
"name": "(9)",
1209+
"chatbot": "GitHub Copilot"
1210+
},
1211+
{
1212+
"name": "(10)",
1213+
"chatbot": "HuggingChat"
1214+
},
1215+
{
1216+
"name": "(11)",
1217+
"chatbot": "Kimi"
1218+
},
1219+
{
1220+
"name": "(12)",
1221+
"chatbot": "LMArena"
1222+
},
1223+
{
1224+
"name": "(13)",
1225+
"chatbot": "Mistral"
1226+
},
1227+
{
1228+
"name": "(14)",
1229+
"chatbot": "Open WebUI"
1230+
},
1231+
{
1232+
"name": "(15)",
1233+
"chatbot": "OpenRouter"
1234+
},
1235+
{
1236+
"name": "(16)",
1237+
"chatbot": "Qwen"
1238+
},
1239+
{
1240+
"name": "(17)",
1241+
"chatbot": "Together"
1242+
},
1243+
{
1244+
"name": "(18)",
1245+
"chatbot": "Yuanbao"
1246+
},
1247+
{
1248+
"name": "(19)",
1249+
"chatbot": "Z.AI"
1250+
},
1251+
{}
1252+
],
1253+
"items": {
1254+
"type": "object",
1255+
"properties": {
1256+
"name": {
1257+
"type": "string"
1258+
},
1259+
"chatbot": {
1260+
"type": "string"
1261+
},
1262+
"model": {
1263+
"type": "string"
1264+
},
1265+
"options": {
1266+
"type": "array",
1267+
"items": {
1268+
"type": "string"
1269+
}
1270+
},
1271+
"temperature": {
1272+
"type": "number"
1273+
},
1274+
"topP": {
1275+
"type": "number"
1276+
},
1277+
"systemInstructions": {
1278+
"type": "string"
1279+
},
1280+
"port": {
1281+
"type": "number"
1282+
},
1283+
"newUrl": {
1284+
"type": "string"
1285+
},
1286+
"thinkingBudget": {
1287+
"type": "number"
1288+
},
1289+
"reasoningEffort": {
1290+
"type": "string"
1291+
},
1292+
"isSelected": {
1293+
"type": "boolean"
1294+
},
1295+
"isCollapsed": {
1296+
"type": "boolean"
1297+
},
1298+
"isPinned": {
1299+
"type": "boolean"
1300+
}
1301+
}
1302+
}
1303+
},
11641304
"codeWebChat.chatPresetsForNoContext": {
11651305
"type": "array",
11661306
"default": [
@@ -1401,6 +1541,24 @@
14011541
]
14021542
}
14031543
},
1544+
"codeWebChat.promptTemplatesForPruneContext": {
1545+
"type": "array",
1546+
"default": [],
1547+
"items": {
1548+
"type": "object",
1549+
"properties": {
1550+
"name": {
1551+
"type": "string"
1552+
},
1553+
"template": {
1554+
"type": "string"
1555+
}
1556+
},
1557+
"required": [
1558+
"template"
1559+
]
1560+
}
1561+
},
14041562
"codeWebChat.modelProviders": {
14051563
"type": "array",
14061564
"default": [],
@@ -1485,6 +1643,44 @@
14851643
]
14861644
}
14871645
},
1646+
"codeWebChat.configurationsForPruneContext": {
1647+
"type": "array",
1648+
"scope": "resource",
1649+
"default": [],
1650+
"items": {
1651+
"type": "object",
1652+
"properties": {
1653+
"providerName": {
1654+
"type": "string"
1655+
},
1656+
"model": {
1657+
"type": "string"
1658+
},
1659+
"temperature": {
1660+
"type": "number"
1661+
},
1662+
"reasoningEffort": {
1663+
"type": "string",
1664+
"enum": [
1665+
"none",
1666+
"low",
1667+
"medium",
1668+
"high"
1669+
]
1670+
},
1671+
"isDefault": {
1672+
"type": "boolean"
1673+
},
1674+
"isPinned": {
1675+
"type": "boolean"
1676+
}
1677+
},
1678+
"required": [
1679+
"providerName",
1680+
"model"
1681+
]
1682+
}
1683+
},
14881684
"codeWebChat.configurationsForEditContext": {
14891685
"type": "array",
14901686
"scope": "resource",

‎packages/vscode/src/constants/instructions.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ export const intelligent_update_instructions =
2424

2525
export const commit_message_instructions =
2626
"Write a brief and precise summary for the changes, limited to a single sentence, if possible and nothing else. Because the summary will be used for a commit message, don't use any markdown formatting. Use an imperative tone to ensure clarity and focus on the primary change or purpose."
27+
28+
export const optimize_context_instructions = (instructions: string) =>
29+
`Optimistically list relevant files to accomplish following task: ${instructions}
30+
<system>
31+
Your response must list paths one under another, and show nothing else, e.g.:
32+
- \`src/hello.ts\`
33+
- \`src/welcome.ts\`
34+
</system>`

‎packages/vscode/src/constants/state-keys.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const CONTEXT_CHECKED_URLS_STATE_KEY = 'context-checked-urls'
1414
export const CONTEXT_CHECKED_TIMESTAMPS_STATE_KEY = 'context-checked-timestamps'
1515
export const LAST_SELECTED_CODE_COMPLETION_CONFIG_ID_STATE_KEY =
1616
'lastSelectedCodeCompletionConfigId'
17+
export const LAST_SELECTED_PRUNE_CONTEXT_CONFIG_ID_STATE_KEY =
18+
'lastSelectedPruneContextConfigId'
1719
export const LAST_SELECTED_EDIT_CONTEXT_CONFIG_ID_STATE_KEY =
1820
'lastSelectedEditContextConfigId'
1921
export const LAST_SELECTED_COMMIT_MESSAGES_CONFIG_ID_STATE_KEY =
@@ -51,23 +53,29 @@ export const INSTRUCTIONS_ASK_STATE_KEY = 'instructions-ask'
5153
export const INSTRUCTIONS_NO_CONTEXT_STATE_KEY = 'instructions-no-context'
5254
export const INSTRUCTIONS_CODE_COMPLETIONS_STATE_KEY =
5355
'instructions-code-completions'
56+
export const INSTRUCTIONS_PRUNE_CONTEXT_STATE_KEY = 'instructions-prune-context'
5457

5558
export const ARE_TASKS_COLLAPSED_STATE_KEY = 'are-tasks-collapsed'
5659
export const IS_TIMELINE_COLLAPSED_STATE_KEY = 'is-timeline-collapsed'
5760

5861
export const HISTORY_ASK_STATE_KEY = 'history-ask'
5962
export const HISTORY_EDIT_STATE_KEY = 'history-edit'
6063
export const HISTORY_CODE_COMPLETIONS_STATE_KEY = 'history-code-completions'
64+
export const HISTORY_PRUNE_CONTEXT_STATE_KEY = 'history-prune-context'
6165
export const HISTORY_NO_CONTEXT_STATE_KEY = 'history-no-context'
6266

6367
export const PINNED_HISTORY_ASK_STATE_KEY = 'pinned-history-ask'
6468
export const PINNED_HISTORY_EDIT_STATE_KEY = 'pinned-history-edit'
6569
export const PINNED_HISTORY_CODE_COMPLETIONS_STATE_KEY =
6670
'pinned-history-code-completions'
71+
export const PINNED_HISTORY_PRUNE_CONTEXT_STATE_KEY =
72+
'pinned-history-prune-context'
6773
export const PINNED_HISTORY_NO_CONTEXT_STATE_KEY = 'pinned-history-no-context'
6874

6975
export const RECENTLY_USED_CODE_COMPLETION_CONFIG_IDS_STATE_KEY =
7076
'recently-used-code-completion-config-ids'
77+
export const RECENTLY_USED_PRUNE_CONTEXT_CONFIG_IDS_STATE_KEY =
78+
'recently-used-prune-context-config-ids'
7179
export const RECENTLY_USED_EDIT_CONTEXT_CONFIG_IDS_STATE_KEY =
7280
'recently-used-edit-context-config-ids'
7381

‎packages/vscode/src/context/context-initialization.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ export const context_initialization = async (
143143
const update_view_badges = async () => {
144144
let context_token_count = 0
145145
if (context_provider && context_view) {
146-
const files_count =
146+
const files_count = (
147147
await workspace_provider.get_checked_files_token_count()
148+
).total
148149
const websites_count =
149150
websites_provider.get_checked_websites_token_count()
150151
context_token_count = files_count + websites_count

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export class OpenEditorsProvider
287287
}
288288

289289
const range = this._workspace_provider.get_range(file_path)
290-
const token_count =
290+
const tokens =
291291
this._workspace_provider.get_cached_token_count(file_path) ||
292292
(await this._workspace_provider.calculate_file_tokens(file_path))
293293

@@ -299,7 +299,9 @@ export class OpenEditorsProvider
299299
checkbox_state,
300300
false,
301301
true,
302-
token_count,
302+
tokens.total,
303+
tokens.compact,
304+
undefined,
303305
undefined,
304306
description,
305307
false,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { display_token_count } from '../../../utils/display-token-count'
55

66
export class WebsiteItem extends vscode.TreeItem {
77
public readonly token_count: number
8+
public readonly compact_token_count: number
89

910
constructor(
1011
public readonly title: string,
@@ -17,7 +18,10 @@ export class WebsiteItem extends vscode.TreeItem {
1718
super(title, vscode.TreeItemCollapsibleState.None)
1819

1920
const content_xml = `<document title="${title}">\n<![CDATA[\n${content}\n]]>\n</document>\n`
21+
2022
this.token_count = Math.floor(content_xml.length / 4)
23+
this.compact_token_count = this.token_count
24+
2125
const formatted_token_count = display_token_count(this.token_count)
2226
this.tooltip = `${title} - About ${formatted_token_count} tokens`
2327
this.description = formatted_token_count

0 commit comments

Comments
 (0)