Skip to content

Commit dde6c50

Browse files
committed
Update CLI prompt generation to include file contents and remove requirements
- all rules [Pasted text] should be objects with keys like: read_only, files, output_formatting - when building cli prompt: when attached files take no more 'tokens' than 20k characters, they should be placed inline. If they take more than 20k characters, they should be referenced as paths (current behavior) - when building cli prompt: when attaching preloaded files, use appropriate rule instead of 'files' (preloaded_files) - merge [Fragment] into a single cli_rules object - rename 'rules' to 'requirements' - remove 'output formatting' rule - remove 'read only' rule - when files are only referenced by paths, use 'referenced files' requirement. when they're inlined, use 'inline files' requirement - should not use delete requirements pattern, instead access [Fragment] keys explicitly - extract [Fragment] as 'read_only key on cli_requirements - dont use [Fragment] in requirements object - simplify [Fragment] to two keys 'preloaded files', 'referenced files' - extract [Fragment] to 'read_only' key - simplify [Pasted text] as there is only one erquirement. Don't use '- ' - small files (up to 1000 characters) should be always inlined, larger ones should use "### Large file: `[path]`" - as you inline files with up to 1000 characters, set up a counter so no more than 20000 characters are inlined - don't use file/large file distinction when all files no matter individual size don't exceed 20k characters - preload all files here [Fragment] - this limit [Fragment] should be for the total content - should use cli_requirements.referenced_files_only when all files referenced are large └── apps └── editor └── src ├── constants │ └── instructions.ts └── views └── prompt └── backend ├── message-handlers │ ├── handle-invoke-agentic-cli.ts │ ├── handle-make-api-call.ts │ └── utils │ └── build-cli-prompt.ts └── prompt-view-provider.ts
1 parent 466a829 commit dde6c50

2 files changed

Lines changed: 57 additions & 22 deletions

File tree

‎apps/editor/src/constants/instructions.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ These files contain the core greeting logic and module exports.`
6969
export const voice_input_instructions =
7070
'Respond with a transcription of the following audio recording or text "INAUDIBLE", and nothing else.'
7171

72-
export const cli_edit_requirements = `- This is a read-only session.
73-
- Read all the listed files provided as project-relative paths in full, and nothing else.
74-
- Formulate response adhering to the output formatting, in plain text.`
75-
76-
export const cli_ask_requirements = `- This is a read-only session.
77-
- Read all the listed files provided as project-relative paths in full, and nothing else.`
72+
export const cli_requirements = {
73+
preloaded_files:
74+
'Tool calling is disabled with exception to media and web access in [task](#task).',
75+
referenced_files_with_some_preloaded:
76+
'Tool calling is disabled with exception to reading large files provided as project-relative paths in [files](#files) and media and web access in [task](#task). Begin by reading large files from [files](#files) in full.',
77+
referenced_files_only:
78+
'Tool calling is disabled with exception to reading files provided as project-relative paths in [files](#files) and media and web access in [task](#task). Begin by reading files from [files](#files) in full.',
79+
}

‎apps/editor/src/views/prompt/backend/message-handlers/utils/build-cli-prompt.ts‎

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import * as path from 'path'
2+
import * as fs from 'fs/promises'
23
import { PromptViewProvider } from '@/views/prompt/backend/prompt-view-provider'
34
import { replace_symbols } from '@/views/prompt/backend/utils/symbols/replace-symbols'
45
import {
5-
cli_edit_requirements,
6-
cli_ask_requirements
7-
} from '@/constants/instructions'
8-
import {
6+
97
EDIT_FORMAT_INSTRUCTIONS_DIFF,
108
EDIT_FORMAT_INSTRUCTIONS_SEARCH_REPLACE,
119
EDIT_FORMAT_INSTRUCTIONS_TRUNCATED,
@@ -45,14 +43,55 @@ export const build_cli_prompt = async (params: {
4543
const checked_files =
4644
prompt_view_provider.workspace_provider.get_checked_files()
4745

46+
const files_data: { relative_path: string; content?: string }[] = []
47+
let total_content_length = 0
48+
49+
for (const f of checked_files) {
50+
const rel = selected_root ? path.relative(selected_root, f) : f
51+
const relative_path = (rel.startsWith('..') ? f : rel).replace(/\\/g, '/')
52+
53+
try {
54+
const content = await fs.readFile(f, 'utf8')
55+
files_data.push({ relative_path, content })
56+
total_content_length += content.length
57+
} catch (err) {
58+
files_data.push({ relative_path, content: undefined })
59+
}
60+
}
61+
4862
let files_section = ''
49-
if (checked_files.length > 0) {
50-
const relative_paths = checked_files.map((f) => {
51-
const rel = selected_root ? path.relative(selected_root, f) : f
52-
return rel.startsWith('..') ? f : rel
53-
})
5463

55-
files_section = `# Files\n\n${relative_paths.map((p) => `- \`${p.replace(/\\/g, '/')}\``).join('\n')}`
64+
if (total_content_length <= 20000) {
65+
const file_blocks = files_data.map((data) =>
66+
data.content !== undefined
67+
? `### File: \`${data.relative_path}\`\n\n\`\`\`\n${data.content}\n\`\`\``
68+
: `### File: \`${data.relative_path}\`\n\n\`\`\`\n\n\`\`\``
69+
)
70+
71+
files_section = `# Files\n\n${file_blocks.join('\n\n')}`
72+
} else {
73+
const file_blocks: string[] = []
74+
let total_inlined_characters = 0
75+
76+
for (const data of files_data) {
77+
if (data.content !== undefined) {
78+
if (
79+
data.content.length <= 1000 &&
80+
total_inlined_characters + data.content.length <= 20000
81+
) {
82+
total_inlined_characters += data.content.length
83+
file_blocks.push(
84+
`### File: \`${data.relative_path}\`\n\n\`\`\`\n${data.content}\n\`\`\``
85+
)
86+
} else {
87+
file_blocks.push(`### Large file: \`${data.relative_path}\``)
88+
}
89+
} else {
90+
file_blocks.push(`### File: \`${data.relative_path}\`\n\n\`\`\`\n\n\`\`\``)
91+
}
92+
}
93+
94+
files_section = `# Files\n\n${file_blocks.join('\n\n')}`
5695
}
5796

5897
let output_formatting_section = ''
@@ -69,18 +108,12 @@ export const build_cli_prompt = async (params: {
69108
}
70109
}
71110

72-
const requirements_section = `# Rules\n\n${
73-
prompt_view_provider.cli_prompt_type == 'ask-about-files'
74-
? cli_ask_requirements
75-
: cli_edit_requirements
76-
}`
77111
const task_section = `# Task\n\n${processed_query}`
78112

79113
const parts = [
80114
files_section,
81115
skill_definitions,
82116
output_formatting_section,
83-
requirements_section,
84117
task_section
85118
].filter((p) => p.trim() != '')
86119

0 commit comments

Comments
 (0)