-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.ts
289 lines (249 loc) · 9.42 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import {join} from "jsr:@std/path"
import Anthropic from "anthropic"
import {homedir} from "node:os"
import {isJinaAvailable, loadUserSettings} from "./settings.ts"
export const EDITOR_DIR = join(homedir(), ".ComputerUseAgent", "editor_dir")
export const SESSIONS_DIR = join(homedir(), ".ComputerUseAgent", "sessions")
export const LOGS_DIR = join(homedir(), ".ComputerUseAgent", "logs")
export const EXPORT_PATH = join(homedir(), ".ComputerUseAgent", "exports")
export const DEFAULT_TOOLS_CONFIG_PATH = join(homedir(), ".ComputerUseAgent", "settings.json")
export const MEMORY_PATH = "/root/memory.json"
export const DEFAULT_EDITOR = Deno.env.get("EDITOR") ?? "nano"
export const EDITOR_SYSTEM_PROMPT = Deno.env.get("EDITOR_SYSTEM_PROMPT") ??
`You are a helpful assistant that helps users edit and work with text files.
You have the access of full file system, and you are currently in ${Deno.cwd()} directory.
Some rules for you to take care of
- All the paths you provide and use should be related to current directory.
- If user asks you to work with current directory or file from current directory, you can use '.' or './' as prefix.
- If user asks you to work with any subdirectory, it should be relative to current directory.
- If user asks you to refer to memory, read /root/memory.json file.`
export const BASH_SYSTEM_PROMPT = `
You are a helpful assistant that can execute shell command.
You operate in the environment mentioned in <SystemInfo> tag.
Please ensure all commands are compatible with this environment.
`
export const PLANNER_SYSTEM_PROMPT = `
Think step by step and prepare a plan for an agent running on CLI,
you will pass the generated plan to the agent and it will execute it according to the steps you will give them.
Make sure your steps will fulfill the user request,
user's requests and current system information will be provided to you in their respective tags.
The agent will have access to some tools, including bash and file system access,
additionally there will be some other tools, whose names will be provided to you in <Tools> tag.
Evaluate the user's request; if this is a simple request like a greeting, requesting information, or advice which can be done without any tools, simply respond with '[{step:0,action:'Reply to the user'}]'
However, for anything more complex, reflect on system information to create a step-by-step plan that the agent can follow.
Make sure each step can be executed independently of each other, but still have the ability to build on the previous steps.
Also, make sure each step can respect the system information, and the user request.
You should respond with a detailed JSON plan having the following shape:
[{step:1,action:'Action to be taken to achieve the goal'},"..."]
ONLY Respond in JSON without any codefences or any other details.
`
export const SYSTEM_PROMPT_TEMPLATE = `
You are a versatile assistant with full system access.
You are currently operating in \${Deno.cwd()} directory.
System Information:
\${systemInfo}
You have access to following tools and capabilities:
- BASH_TOOL:
- Name: "bash"
- Description: Execute shell commands
- Arguments:
- command: string (required) - The shell command to execute
- restart: boolean (optional) - Restart shell session if true
- Example: {command: "ls -la", restart: false}
- EDITOR_TOOL:
- Name: "str_replace_editor"
- Description: File manipulation operations
- Commands:
- view:
- path: string (required)
- create:
-path: string (required)
- file_text: string (required)
- str_replace:
- path: string (required)
- old_str: string (required)
- new_str: string (required)
- insert:
- path: string (required)
- insert_line: number (required)
- new_str: string (required)
- MEMORY_TOOLS:
- Name: "add_memory"
- Arguments: {content: string}
- Name: "get_memories"
- Arguments: none
- Name: "clear_memories"
- Arguments: none
- CLIPBOARD_TOOLS:
- Name: "read_clipboard"
- Arguments: none
\${additionalTools}
\${userContext}
\${additionalInstructions ?? ''}
Follow these rules:
1. File and Directory Operations:
- Use BASH_TOOL for all file/directory operations
- Default command structure:
\`\`\`
For files: {command: "rg [options] 'pattern' [file-pattern]"}
For dirs: {command: "tree . [options] [conditions]"}
\`\`\`
2. Content Search with ripgrep (rg):
- Always include these base options:
\`\`\`
--type - not=lock # Exclude lockfiles
--hidden # Include hidden files
- l # Only show file names
\`\`\`
- Common usage patterns:
\`\`\`
Search in YAML: {command: "rg --type-not=lock --hidden -t yaml 'pattern'"}
Specific files: {command: "rg --type-not=lock --hidden -g 'serverless.yml' 'pattern'"}
Multiple patterns: {command: "rg --type-not=lock --hidden -e 'pattern1' -e 'pattern2'"}
\`\`\`
3. File Editing:
- Use EDITOR_TOOL for all file modifications
- Always provide exact file paths (use BASH_TOOL with tree/rg first if needed)
4. Data Management:
- Use MEMORY_TOOLS when something you find will be needed later
- Use CLIPBOARD_TOOLS only when user tells you to read from clipboard
5. External Resources:
- Use JINA_TOOLS for web content and online searches
Note: When chaining operations, use separate BASH_TOOL commands and store results in MEMORY_TOOLS if needed.
`
export const API_CONFIG = {
MODEL: "claude-3-5-sonnet-20241022",
REASONING_MODEL: "claude-3-7-sonnet-20250219",
INTENT_MODEL: "claude-3-5-haiku-20241022",
MAX_TOKENS: 8192,
MIN_THINKING_TOKENS: 1024,
MAX_TOKENS_WHEN_THINKING: 20000,
MAX_INTENT_TOKENS: 20,
}
export const MEMORY_TOOLS: Anthropic.Beta.BetaTool[] = [
{
name: "add_memory",
description: "Add a new memory to the system",
type: "custom",
input_schema: {
type: "object",
properties: {
content: {
type: "string",
description: "The content to store in memory",
},
},
required: ["content"],
},
},
{
type: "custom",
name: "get_memories",
description: "Retrieve all stored memories",
input_schema: {
type: "object",
properties: {},
},
},
{
type: "custom",
name: "clear_memories",
description: "Clear all stored memories",
input_schema: {
type: "object",
properties: {},
},
},
]
export const CLIPBOARD_TOOLS: Anthropic.Beta.BetaTool[] = [
{
type: "custom",
name: "read_clipboard",
description: "Read content from system clipboard",
input_schema: {type: "object", properties: {}, required: []}
}
]
export const JINA_TOOLS: Anthropic.Beta.BetaTool[] = [
{
type: "custom",
name: "readPage",
description: "Read and parse content from a URL using Jina Reader API",
input_schema: {
type: "object",
properties: {
url: {
type: "string",
description: "The URL to read and parse",
},
},
required: ["url"],
},
},
{
type: "custom",
name: "search",
description: "Search content using Jina Search API",
input_schema: {
type: "object",
properties: {
searchTerm: {
type: "string",
description: "The term to search for",
},
},
required: ["searchTerm"],
},
},
{
type: "custom",
name: "searchGrounding",
description: "Search with grounding using Jina Grounding API",
input_schema: {
type: "object",
properties: {
searchTerm: {
type: "string",
description: "The term to search for with grounding",
},
},
required: ["searchTerm"],
},
},
]
interface SchemaProperty {
type: string
description?: string
}
export function getSystemContext(
additionalTools: Anthropic.Beta.Messages.BetaTool[] = [],
systemInfo: string = '{}',
additionalInstructions?: string,
): string {
const settings = loadUserSettings()
const toolsString = additionalTools.map(tool => {
const schema = tool.input_schema as {
type: string
properties: Record<string, SchemaProperty>
required?: string[]
}
return `
- ${tool.name.toUpperCase()}:
- Name: "${tool.name}"
- Description: ${tool.description}
- Arguments: ${Object.entries(schema.properties)
.map(([name, prop]) => `
- ${name}: ${prop.type}${schema.required?.includes(name) ? ' (required)' : ''} - ${prop.description || ''}`)
.join('')}
`
}).join('\n')
const userContext = `
User Context:
- Name: ${settings.userName}
`
return SYSTEM_PROMPT_TEMPLATE
.replace('${Deno.cwd()}', Deno.cwd())
.replace('${additionalTools}', toolsString)
.replace('${userContext}', userContext)
.replace('${systemInfo}', systemInfo)
.replace('${additionalInstructions ?? \'\'}', additionalInstructions ?? '')
}