a3s-code-core 1.11.0

A3S Code Core - Embeddable AI agent library with tool execution
Documentation
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
---
name: builtin-tools
description: Built-in file operation and shell tools
version: 1.0.0
kind: instruction
tags:
  - tools
  - documentation
tools:
  - name: read
    description: Read the contents of a file. Returns line-numbered output. Supports text files and images.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        file_path:
          type: string
          description: Path to the file to read (absolute or relative to workspace)
        offset:
          type: integer
          description: Line number to start reading from (0-indexed, default 0)
        limit:
          type: integer
          description: Maximum number of lines to read (default 2000)
      required:
        - file_path

  - name: write
    description: Write content to a file. Creates the file and parent directories if they don't exist.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        file_path:
          type: string
          description: Path to the file to write
        content:
          type: string
          description: Content to write to the file
      required:
        - file_path
        - content

  - name: edit
    description: Edit a file by replacing a specific string with another. The old_string must be unique in the file unless replace_all is true.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        file_path:
          type: string
          description: Path to the file to edit
        old_string:
          type: string
          description: The exact string to replace (must be unique unless replace_all=true)
        new_string:
          type: string
          description: The string to replace it with
        replace_all:
          type: boolean
          description: Replace all occurrences (default false)
      required:
        - file_path
        - old_string
        - new_string

  - name: patch
    description: Apply a unified diff patch to a file. Use this for complex multi-line edits where the edit tool would be cumbersome. The diff must be in unified diff format with @@ hunk headers.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        file_path:
          type: string
          description: Path to the file to patch
        diff:
          type: string
          description: "Unified diff content with @@ hunk headers. Example:\n@@ -1,3 +1,3 @@\n line1\n-old_line\n+new_line\n line3"
      required:
        - file_path
        - diff

  - name: bash
    description: Execute a shell command in the workspace directory. On Windows this runs in PowerShell, not GNU bash. Use for running commands, installing packages, running tests, and local diagnostics.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        command:
          type: string
          description: The shell command to execute. On Windows, write PowerShell-compatible commands by default. A limited compatibility shim exists for curl, wget, bare HTTP verbs (GET/POST/PUT/PATCH/DELETE/OPTIONS), which, and head.
        timeout:
          type: integer
          description: Timeout in milliseconds (default 120000)
      required:
        - command

  - name: grep
    description: Search for a pattern in files using ripgrep. Returns matching lines with file paths and line numbers.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        pattern:
          type: string
          description: Regular expression pattern to search for
        path:
          type: string
          description: Directory or file to search in (default workspace root)
        glob:
          type: string
          description: Glob pattern to filter files (e.g., '*.rs', '*.{ts,tsx}')
        context:
          type: integer
          description: Number of context lines to show before and after matches
        -i:
          type: boolean
          description: Case insensitive search
      required:
        - pattern

  - name: glob
    description: Find files matching a glob pattern. Returns a list of file paths.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        pattern:
          type: string
          description: Glob pattern to match (e.g., '**/*.rs', 'src/**/*.ts')
        path:
          type: string
          description: Base directory for the search (default workspace root)
      required:
        - pattern

  - name: ls
    description: List contents of a directory with file types and sizes.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        path:
          type: string
          description: Directory path to list (default workspace root)
      required: []

  - name: web_fetch
    description: |
      Fetch content from a URL and convert to text or markdown.
      - Supports HTML to Markdown conversion
      - 5MB response size limit
      - Configurable timeout (max 120 seconds)
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        url:
          type: string
          description: The URL to fetch content from (must start with http:// or https://)
        format:
          type: string
          enum: ["markdown", "text", "html"]
          description: "Output format (default: markdown)"
        timeout:
          type: integer
          description: "Timeout in seconds (default: 30, max: 120)"
      required:
        - url

  - name: box
    description: |
      Run code or commands inside an A3S Box secure sandbox (VM-level isolation).
      Use this when you need to execute untrusted code, run experiments safely,
      or isolate side effects from the host system.
      The sandbox has its own filesystem, network, and process namespace.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        command:
          type: string
          description: The command to execute inside the sandbox
        image:
          type: string
          description: "Sandbox image to use (default: ubuntu-22.04)"
        timeout:
          type: integer
          description: Timeout in milliseconds (default 60000)
        files:
          type: object
          description: Files to inject into the sandbox before execution (key=path, value=content)
      required:
        - command

  - name: git
    description: |
      Execute Git operations using the system git command. Supports: status, log, branch, checkout, diff, stash, remote, and worktree management. **Automatically downloads and installs git if not available** on Windows, macOS, and Linux.

      Auto-installation: Downloads official pre-built git binaries from GitHub/git-scm.com to `~/.local/git/bin/`. Does not require any package manager.
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        command:
          type: string
          enum: ["status", "log", "branch", "checkout", "diff", "stash", "remote", "worktree"]
          description: "Required. Git command to execute."
        name:
          type: string
          description: Branch name for branch/checkout/worktree operations.
        path:
          type: string
          description: Path for worktree operations.
        ref:
          type: string
          description: Reference for checkout command.
        target:
          type: string
          description: Target ref for diff (e.g., HEAD~1).
        max_count:
          type: integer
          description: Maximum log entries to show (default 10).
        message:
          type: string
          description: Message for stash.
        include_untracked:
          type: boolean
          description: Include untracked files in stash.
        force:
          type: boolean
          description: Force checkout/create operation.
        new_branch:
          type: boolean
          description: Create new branch for worktree (default true).
        base:
          type: string
          description: Base ref for new branch (default HEAD).
      required:
        - command

  - name: web_search
    description: |
      Search the web using multiple search engines.
      - Aggregates results from multiple engines (DuckDuckGo, Wikipedia, Google, Brave, Baidu, etc.)
      - Supports proxy configuration for anti-crawler protection
      - Returns deduplicated and ranked results
    backend:
      type: builtin
    parameters:
      type: object
      properties:
        query:
          type: string
          description: The search query
        engines:
          type: array
          items:
            type: string
          description: "List of engines to use (default: [\"ddg\",\"wiki\"]). Available: ddg (DuckDuckGo), brave (Brave Search), wiki (Wikipedia), sogou (Sogou), 360 / so360 (360 Search). Note: use 'engines' (plural), not 'engine' (singular)."
        limit:
          type: integer
          description: "Maximum number of results to return (default: 10, max: 50)"
        timeout:
          type: integer
          description: "Search timeout in seconds (default: 10, max: 60)"
        proxy:
          type: string
          description: "Proxy URL (e.g., http://127.0.0.1:8080 or socks5://127.0.0.1:1080)"
        format:
          type: string
          enum: ["text", "json"]
          description: "Output format (default: text)"
      required:
        - query
---

# Built-in Tools

Core file operation and shell tools for A3S Code.

## Tools

- **read**: Read file contents with line numbers
- **write**: Write content to files
- **edit**: Edit files with string replacement
- **patch**: Apply unified diff patches to files
- **bash**: Execute shell commands in the workspace
- **box**: Run commands inside an A3S Box secure sandbox (VM-level isolation)
- **grep**: Search file contents with ripgrep
- **glob**: Find files by pattern
- **ls**: List directory contents
- **git**: Execute Git operations with auto-install support (auto-downloads git if not available)
- **web_fetch**: Fetch web content and convert to text/markdown
- **web_search**: Search the web using multiple search engines

## When to Use box vs bash

- Use **bash** for normal workspace operations (read files, run tests, build code)

## Windows Shell Rules

- On Windows, the **bash** tool executes the command through **PowerShell**, not GNU bash and not `cmd.exe`.
- Prefer native PowerShell syntax on Windows.
- For HTTP calls on Windows, prefer `curl.exe` or `Invoke-RestMethod`. A compatibility shim also accepts `curl`, `wget`, and bare verbs like `GET http://127.0.0.1:18790/health`.
- Do not assume Unix utilities or GNU shell behavior on Windows. Avoid patterns like `grep`, `sed`, `awk`, `tail -f`, `cmd1 && cmd2`, or bash-specific quoting unless you explicitly convert them to PowerShell syntax.
- If you need to inspect only the first few output lines in PowerShell, prefer `Select-Object -First N`. The compatibility shim also supports `head -N`.
- Use **box** when you need:
  - VM-level isolation from the host
  - Safe execution of untrusted or experimental code
  - Sandboxed network/filesystem access
  - Running code that might have side effects you want to contain

## Usage

These tools are native Rust implementations automatically available in every agent session.

Parameters are passed as JSON objects matching each tool's parameter schema defined in the YAML frontmatter above.

## Examples

### File Operations

```json
// Read a file
{"file_path": "src/main.rs", "offset": 0, "limit": 100}

// Write to a file
{"file_path": "output.txt", "content": "Hello, world!"}

// Edit a file
{"file_path": "config.json", "old_string": "\"debug\": false", "new_string": "\"debug\": true"}

// Apply a patch
{"file_path": "src/lib.rs", "diff": "@@ -1,3 +1,3 @@\n line1\n-old\n+new\n line3"}
```

### Search Operations

```json
// Search with grep
{"pattern": "fn main", "glob": "**/*.rs", "context": 3}

// Find files with glob
{"pattern": "**/*.{rs,toml}", "path": "."}

// List directory
{"path": "src"}
```

### Sandbox Execution (A3S Box)

```json
// Run a command in a secure sandbox
{"command": "python3 -c 'import os; print(os.listdir(\"/\"))'", "image": "ubuntu-22.04"}

// Run with injected files
{"command": "python3 /sandbox/script.py", "files": {"/sandbox/script.py": "print('hello from sandbox')"}}
```

### Execution

```json
// Run a bash command
{"command": "cargo test", "timeout": 120000}
```

### Web Operations

```json
// Fetch web content
{"url": "https://example.com", "format": "markdown", "timeout": 30}

// Search the web
{"query": "rust async programming", "engines": ["ddg", "wiki"], "limit": 10}
```

### Git Operations

```json
// Show repository status
{"command": "status"}

// Show commit log
{"command": "log", "max_count": 5}

// List all branches
{"command": "branch"}

// Create a new branch
{"command": "branch", "name": "feature-x"}

// Checkout a branch
{"command": "checkout", "ref": "feature-x"}

// Show diff against HEAD
{"command": "diff"}

// Show diff between commits
{"command": "diff", "target": "HEAD~1"}

// List stashes
{"command": "stash"}

// Create a stash
{"command": "stash", "message": "WIP: work in progress"}

// Show remotes
{"command": "remote"}

// List all worktrees
{"command": "worktree", "command": "list"}

// Create a new worktree
{"command": "worktree", "command": "create", "name": "feature-x", "path": "../repo-feature-x"}

// Remove a worktree
{"command": "worktree", "command": "remove", "path": "../repo-feature-x", "force": true}
```