Skip to content

Commit 6baa73e

Browse files
committed
Include completed tasks in token count calculations and content checks
- are 'completed tasks' included in 'prompt token count'? They should - once 'completed tasks' are cleared, 'prompt token count' never updates on itself ├── apps │ └── editor │ └── src │ ├── utils │ │ └── prompt-builder.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ ├── handle-clear-completed-tasks.ts │ │ │ ├── handle-save-completed-tasks.ts │ │ │ └── utils │ │ │ ├── build-cli-prompt.ts │ │ │ └── build-prompt-payload.ts │ │ └── prompt-view-provider.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.tsx └── components └── CompletedTasks └── CompletedTasks.tsx
1 parent 8cf1337 commit 6baa73e

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎apps/editor/src/views/prompt/backend/message-handlers/handle-clear-completed-tasks.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const handle_clear_completed_tasks = async (
1717
command: 'COMPLETED_TASKS',
1818
completed_tasks: prompt_view_provider.completed_tasks
1919
})
20+
prompt_view_provider.send_token_count()
2021

2122
const selection = await vscode.window.showInformationMessage(
2223
t('views.prompt.handlers.handle-clear-completed-tasks.cleared'),
@@ -33,5 +34,6 @@ export const handle_clear_completed_tasks = async (
3334
command: 'COMPLETED_TASKS',
3435
completed_tasks: prompt_view_provider.completed_tasks
3536
})
37+
prompt_view_provider.send_token_count()
3638
}
3739
}

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,10 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
562562

563563
public async send_token_count() {
564564
const edit_instructions_result = await replace_symbols({
565-
instructions: [this.current_edit_files_instruction.trim()],
565+
instructions: [
566+
this.current_edit_files_instruction.trim(),
567+
...this.completed_tasks
568+
],
566569
extension_context: this.extension_context,
567570
workspace_provider: this.workspace_provider,
568571
remove_images: true,
@@ -580,12 +583,18 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
580583
command: 'TOKEN_COUNT_UPDATED',
581584
selected_files_token_count: this.current_selected_files_token_count,
582585
edit_instructions_token_count: Math.ceil(
583-
(edit_instructions_result.instructions[0].length +
586+
(edit_instructions_result.instructions.reduce(
587+
(acc, text) => acc + text.length,
588+
0
589+
) +
584590
edit_instructions_result.skill_definitions.length) /
585591
4
586592
),
587593
ask_instructions_token_count: Math.ceil(
588-
(ask_instructions_result.instructions[0].length +
594+
(ask_instructions_result.instructions.reduce(
595+
(acc, text) => acc + text.length,
596+
0
597+
) +
589598
ask_instructions_result.skill_definitions.length) /
590599
4
591600
)

‎packages/ui/src/components/editor/common/prompts/PromptField/PromptField.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export const PromptField: React.FC<PromptField.Props> = (props) => {
135135
const tabs_ref = useRef<TabsRef>(null)
136136

137137
const has_content =
138-
!!props.value || !!(props.selected_files && props.selected_files.length > 0)
138+
!!props.value ||
139+
!!(props.selected_files && props.selected_files.length > 0) ||
140+
props.completed_tasks.length > 0
139141

140142
const { is_alt_pressed, handle_container_key_down } =
141143
use_keyboard_shortcuts(props)

0 commit comments

Comments
 (0)