deepseek-rust-cli 1.20.4

A lightweight, high-speed autonomous CLI system agent port of DeepSeek CLI.
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
use serde_json::json;

use crate::api::types::Tool;

/// Full unfiltered tool list (used when context detection isn't available).
pub fn get_tools_schemas() -> Vec<Tool> {
    get_filtered_tools_schemas(true, true)
}

/// Return tool schemas filtered by context:
/// - `is_git_repo`: include local git tools (status, diff, commit, push, etc.)
/// - `has_github_token`: include GitHub API tools
///
/// Core tools (shell, file I/O, code/web) are always included.
pub fn get_filtered_tools_schemas(is_git_repo: bool, has_github_token: bool) -> Vec<Tool> {
    let mut tools = Vec::with_capacity(40);

    // ─── Shell & System (always) ────────────────────────────
    tools.push(create_tool(
        "execute_shell_command",
        "Execute a shell command.",
        json!({
            "command": { "type": "string" },
            "is_background": { "type": "boolean" }
        }),
        vec!["command"],
    ));
    tools.push(create_tool(
        "get_system_info",
        "Get system information.",
        json!({}),
        vec![],
    ));
    tools.push(create_tool(
        "start_background_process",
        "Start a command in the background, allowing the agent to continuously monitor its logs \
         and terminate it when needed. Ideal for dev servers.",
        json!({
            "command": { "type": "string", "description": "The command to run" },
            "cwd": { "type": "string", "description": "Optional: working directory" },
            "env": {
                "type": "object",
                "description": "Optional: environment variables as key-value pairs"
            }
        }),
        vec!["command"],
    ));
    tools.push(create_tool(
        "read_background_process_logs",
        "Read accumulated stdout/stderr logs from a running background process.",
        json!({
            "pid": { "type": "integer", "description": "The process ID (PID) of the background process" }
        }),
        vec!["pid"],
    ));
    tools.push(create_tool(
        "kill_background_process",
        "Kill a background process started by the agent.",
        json!({
            "pid": { "type": "integer", "description": "The process ID (PID) to terminate" }
        }),
        vec!["pid"],
    ));
    tools.push(create_tool(
        "list_background_processes",
        "List all active background processes started by the agent.",
        json!({}),
        vec![],
    ));
    tools.push(create_tool(
        "check_port_status",
        "Check if a local port is occupied, free, or blocked.",
        json!({
            "port": { "type": "integer", "description": "Port number to check" },
            "host": { "type": "string", "description": "Optional: host (defaults to '127.0.0.1')" }
        }),
        vec!["port"],
    ));

    // ─── File I/O (always) ──────────────────────────────────
    tools.push(create_tool(
        "read_local_file",
        "Read a local file.",
        json!({
            "file_path": { "type": "string" },
            "start_line": { "type": "integer" },
            "end_line": { "type": "integer" }
        }),
        vec!["file_path"],
    ));
    tools.push(create_tool(
        "write_local_file",
        "Write to a local file.",
        json!({
            "file_path": { "type": "string" },
            "content": { "type": "string" }
        }),
        vec!["file_path", "content"],
    ));
    tools.push(create_tool(
        "replace_text_in_file",
        "Replace text in a file.",
        json!({
            "file_path": { "type": "string" },
            "old_text": { "type": "string" },
            "new_text": { "type": "string" }
        }),
        vec!["file_path", "old_text", "new_text"],
    ));
    tools.push(create_tool(
        "list_directory",
        "List directory contents.",
        json!({
            "path": { "type": "string" }
        }),
        vec![],
    ));
    tools.push(create_tool(
        "tree_view",
        "Show directory tree.",
        json!({
            "path": { "type": "string" },
            "max_depth": { "type": "integer" }
        }),
        vec![],
    ));
    tools.push(create_tool(
        "delete_file",
        "Delete a file or directory.",
        json!({
            "file_path": { "type": "string" }
        }),
        vec!["file_path"],
    ));
    tools.push(create_tool(
        "rename_file",
        "Rename or move a file.",
        json!({
            "source_path": { "type": "string" },
            "destination_path": { "type": "string" }
        }),
        vec!["source_path", "destination_path"],
    ));
    tools.push(create_tool(
        "diff_files",
        "Compare two files.",
        json!({
            "file1": { "type": "string" },
            "file2": { "type": "string" }
        }),
        vec!["file1", "file2"],
    ));
    tools.push(create_tool(
        "hash_file",
        "Calculate file hash.",
        json!({
            "path": { "type": "string" },
            "algorithm": { "type": "string", "enum": ["sha256", "md5"] }
        }),
        vec!["path"],
    ));
    tools.push(create_tool(
        "count_lines",
        "Count lines, words and characters in a file.",
        json!({
            "path": { "type": "string" }
        }),
        vec!["path"],
    ));
    tools.push(create_tool(
        "search_files",
        "Search files for a text pattern using native Rust (no shell process needed). Fast \
         parallel search with regex support.",
        json!({
            "query": { "type": "string" },
            "path": { "type": "string" },
            "glob": { "type": "string" },
            "max_results": { "type": "integer" }
        }),
        vec!["query"],
    ));
    tools.push(create_tool(
        "bulk_rename",
        "Rename multiple files in a directory using a regex pattern.",
        json!({
            "path": { "type": "string" },
            "pattern": { "type": "string" },
            "replacement": { "type": "string" }
        }),
        vec!["path", "pattern", "replacement"],
    ));

    tools.push(create_tool(
        "copy_file",
        "Copy a file from source_path to destination_path natively.",
        json!({
            "source_path": { "type": "string" },
            "destination_path": { "type": "string" }
        }),
        vec!["source_path", "destination_path"],
    ));
    tools.push(create_tool(
        "copy_directory",
        "Recursively copy a directory from source_path to destination_path natively.",
        json!({
            "source_path": { "type": "string" },
            "destination_path": { "type": "string" }
        }),
        vec!["source_path", "destination_path"],
    ));
    tools.push(create_tool(
        "create_directory",
        "Create a directory (and any necessary parent directories) natively.",
        json!({
            "directory_path": { "type": "string" }
        }),
        vec!["directory_path"],
    ));
    tools.push(create_tool(
        "file_exists",
        "Check if a file or directory exists at the given path.",
        json!({
            "file_path": { "type": "string" }
        }),
        vec!["file_path"],
    ));
    tools.push(create_tool(
        "get_file_info",
        "Get metadata for a file (type, size, timestamps, permissions) natively.",
        json!({
            "file_path": { "type": "string" }
        }),
        vec!["file_path"],
    ));

    // ─── Code & Web (always) ───────────────────────────────
    tools.push(create_tool(
        "run_python_code",
        "Execute Python code snippet.",
        json!({
            "code": { "type": "string" }
        }),
        vec!["code"],
    ));
    tools.push(create_tool(
        "fetch_url",
        "Fetch and clean content from a URL.",
        json!({
            "url": { "type": "string" }
        }),
        vec!["url"],
    ));
    tools.push(create_tool(
        "get_env_var",
        "Read an environment variable.",
        json!({
            "name": { "type": "string" }
        }),
        vec!["name"],
    ));

    // ─── New Advanced Tools ─────────────────────────────────
    tools.push(create_tool(
        "regex_replace_in_file",
        "Replace text in a file using a regular expression.",
        json!({
            "file_path": { "type": "string" },
            "regex": { "type": "string" },
            "replacement": { "type": "string" }
        }),
        vec!["file_path", "regex", "replacement"],
    ));
    tools.push(create_tool(
        "json_update_value",
        "Read a JSON file, update a value at a specified key path (e.g. \
         'dependencies.tokio.version'), and save it.",
        json!({
            "file_path": { "type": "string" },
            "key_path": { "type": "string" },
            "new_value": { "type": "string" }
        }),
        vec!["file_path", "key_path", "new_value"],
    ));
    tools.push(create_tool(
        "edit_file_by_lines",
        "Edit a file by specifying one or more non-overlapping line ranges. This is highly \
         efficient for modifying code without rewriting the whole file.",
        json!({
            "file_path": {
                "type": "string",
                "description": "Path to the file to edit"
            },
            "edits": {
                "type": "array",
                "description": "List of line-based replacement edits",
                "items": {
                    "type": "object",
                    "properties": {
                        "start_line": {
                            "type": "integer",
                            "description": "The 1-indexed start line number of the range to replace (inclusive)"
                        },
                        "end_line": {
                            "type": "integer",
                            "description": "The 1-indexed end line number of the range to replace (inclusive)"
                        },
                        "replacement_content": {
                            "type": "string",
                            "description": "The new content to insert in place of the target line range"
                        },
                        "target_content": {
                            "type": "string",
                            "description": "Optional: The exact content of the lines being replaced. If provided, it will be verified against the file contents to ensure correctness before applying the edit."
                        }
                    },
                    "required": ["start_line", "end_line", "replacement_content"]
                }
            }
        }),
        vec!["file_path", "edits"],
    ));
    tools.push(create_tool(
        "apply_diff_patch",
        "Apply a unified diff patch to a local file. Ideal for complex or multi-hunk code modifications.",
        json!({
            "file_path": { "type": "string", "description": "Path to the file to patch" },
            "patch_content": { "type": "string", "description": "The unified diff content (including hunk headers @@)" }
        }),
        vec!["file_path", "patch_content"],
    ));
    tools.push(create_tool(
        "list_symbols",
        "Parse code symbols (functions, structs, classes, etc.) from a file using lightweight \
         regex.",
        json!({
            "file_path": { "type": "string" }
        }),
        vec!["file_path"],
    ));
    tools.push(create_tool(
        "view_symbol_contents",
        "View the full implementation code of a specific symbol (function, class, struct, enum, or impl) from a file.",
        json!({
            "file_path": { "type": "string", "description": "Path to the file to inspect" },
            "symbol_name": { "type": "string", "description": "The name of the symbol/definition to view" }
        }),
        vec!["file_path", "symbol_name"],
    ));
    tools.push(create_tool(
        "screenshot_webapp",
        "Take a screenshot of a local web app or website using Microsoft Edge or Google Chrome in \
         headless mode.",
        json!({
            "url": { "type": "string" },
            "output_path": { "type": "string" }
        }),
        vec!["url", "output_path"],
    ));
    tools.push(create_tool(
        "web_search_duckduckgo",
        "Perform an internet search query via DuckDuckGo and return top results.",
        json!({
            "query": { "type": "string" }
        }),
        vec!["query"],
    ));

    // ─── Refactoring & Advanced Ops ────────────────────────
    tools.push(create_tool(
        "move_code_block",
        "Move a code block (function, struct, etc.) from one file to another using regex.",
        json!({
            "source_path": { "type": "string" },
            "destination_path": { "type": "string" },
            "block_pattern": { "type": "string" }
        }),
        vec!["source_path", "destination_path", "block_pattern"],
    ));
    tools.push(create_tool(
        "split_file",
        "Split a file into multiple parts based on a regex pattern.",
        json!({
            "file_path": { "type": "string" },
            "split_pattern": { "type": "string" },
            "output_prefix": { "type": "string" }
        }),
        vec!["file_path", "split_pattern", "output_prefix"],
    ));
    tools.push(create_tool(
        "cleanup_file",
        "Clean up a file by removing trailing spaces and normalizing line endings.",
        json!({
            "file_path": { "type": "string" }
        }),
        vec!["file_path"],
    ));
    tools.push(create_tool(
        "summarize_project",
        "Analyze the current project and provide a high-level summary of files, languages, and \
         structure.",
        json!({}),
        vec![],
    ));
    tools.push(create_tool(
        "list_todo_tasks",
        "Search the project for TODO, FIXME, HACK, and BUG comments and list them with file and \
         line info.",
        json!({}),
        vec![],
    ));
    tools.push(create_tool(
        "project_checkpoint",
        "Create a project-wide backup archive of the source code and configuration.",
        json!({
            "name": { "type": "string", "description": "Short mnemonic name for the checkpoint" }
        }),
        vec!["name"],
    ));
    tools.push(create_tool(
        "restore_checkpoint",
        "Restore the project from a previously created checkpoint archive.",
        json!({
            "checkpoint_file": { "type": "string", "description": "Filename of the .tar.gz checkpoint" }
        }),
        vec!["checkpoint_file"],
    ));
    tools.push(create_tool(
        "project_wide_replace",
        "Perform a global search and replace across the entire project (filtering target files by \
         glob).",
        json!({
            "old_text": { "type": "string" },
            "new_text": { "type": "string" },
            "glob": { "type": "string", "description": "Glob pattern for files, e.g. '**/*.rs'" }
        }),
        vec!["old_text", "new_text"],
    ));

    // ─── Local Git Operations (only if in a git repo) ──────
    if is_git_repo {
        tools.push(create_tool(
            "git_status",
            "Show git status.",
            json!({
                "path": { "type": "string" }
            }),
            vec![],
        ));
        tools.push(create_tool(
            "git_diff",
            "Show git diff.",
            json!({
                "path": { "type": "string" },
                "staged": { "type": "boolean" }
            }),
            vec![],
        ));
        tools.push(create_tool(
            "git_log",
            "Show git commit history.",
            json!({
                "path": { "type": "string" },
                "count": { "type": "integer" }
            }),
            vec![],
        ));
        tools.push(create_tool(
            "git_branch",
            "List, create, delete, or switch git branches.",
            json!({
                "path": { "type": "string" },
                "action": { "type": "string", "enum": ["list", "create", "delete", "switch"] },
                "name": { "type": "string" }
            }),
            vec![],
        ));
        tools.push(create_tool(
            "git_add",
            "Stage files for commit.",
            json!({
                "path": { "type": "string" },
                "files": { "type": "string" }
            }),
            vec![],
        ));
        tools.push(create_tool(
            "git_commit",
            "Commit staged changes.",
            json!({
                "path": { "type": "string" },
                "message": { "type": "string" }
            }),
            vec!["message"],
        ));
        tools.push(create_tool(
            "git_push",
            "Push commits to remote.",
            json!({
                "path": { "type": "string" },
                "remote": { "type": "string" },
                "branch": { "type": "string" }
            }),
            vec![],
        ));
        tools.push(create_tool(
            "git_pull",
            "Pull changes from remote.",
            json!({
                "path": { "type": "string" },
                "remote": { "type": "string" },
                "branch": { "type": "string" }
            }),
            vec![],
        ));
        tools.push(create_tool(
            "git_checkout",
            "Checkout branch or file.",
            json!({
                "path": { "type": "string" },
                "target": { "type": "string" }
            }),
            vec!["target"],
        ));
        tools.push(create_tool(
            "git_clone",
            "Clone a git repository.",
            json!({
                "url": { "type": "string" },
                "dest": { "type": "string" }
            }),
            vec!["url"],
        ));
        tools.push(create_tool(
            "git_remote_list",
            "List git remotes.",
            json!({
                "path": { "type": "string" }
            }),
            vec![],
        ));
        tools.push(create_tool(
            "git_stash",
            "Stash, pop, or list git stashes.",
            json!({
                "path": { "type": "string" },
                "action": { "type": "string", "enum": ["save", "pop", "list"] }
            }),
            vec![],
        ));
    }

    // ─── GitHub API Operations (only if GITHUB_TOKEN is set)
    if has_github_token {
        tools.push(create_tool(
            "github_repo_info",
            "Get GitHub repository information. Requires GITHUB_TOKEN.",
            json!({
                "repo": { "type": "string" }
            }),
            vec!["repo"],
        ));
        tools.push(create_tool(
            "github_repo_list_issues",
            "List GitHub issues for a repository.",
            json!({
                "repo": { "type": "string" },
                "state": { "type": "string", "enum": ["open", "closed", "all"] },
                "limit": { "type": "integer" }
            }),
            vec!["repo"],
        ));
        tools.push(create_tool(
            "github_issue_create",
            "Create a GitHub issue. Requires GITHUB_TOKEN.",
            json!({
                "repo": { "type": "string" },
                "title": { "type": "string" },
                "body": { "type": "string" },
                "labels": { "type": "string" }
            }),
            vec!["repo", "title"],
        ));
        tools.push(create_tool(
            "github_issue_update",
            "Update a GitHub issue. Requires GITHUB_TOKEN.",
            json!({
                "repo": { "type": "string" },
                "issue_number": { "type": "integer" },
                "title": { "type": "string" },
                "body": { "type": "string" },
                "state": { "type": "string", "enum": ["open", "closed"] }
            }),
            vec!["repo", "issue_number"],
        ));
        tools.push(create_tool(
            "github_pr_list",
            "List GitHub pull requests.",
            json!({
                "repo": { "type": "string" },
                "state": { "type": "string", "enum": ["open", "closed", "all"] },
                "limit": { "type": "integer" }
            }),
            vec!["repo"],
        ));
        tools.push(create_tool(
            "github_pr_create",
            "Create a GitHub pull request. Requires GITHUB_TOKEN.",
            json!({
                "repo": { "type": "string" },
                "title": { "type": "string" },
                "head": { "type": "string" },
                "base": { "type": "string" },
                "body": { "type": "string" },
                "draft": { "type": "boolean" }
            }),
            vec!["repo", "title", "head", "base"],
        ));
        tools.push(create_tool(
            "github_pr_info",
            "Get detailed information about a pull request.",
            json!({
                "repo": { "type": "string" },
                "pr_number": { "type": "integer" }
            }),
            vec!["repo", "pr_number"],
        ));
        tools.push(create_tool(
            "github_pr_merge",
            "Merge a GitHub pull request. Requires GITHUB_TOKEN.",
            json!({
                "repo": { "type": "string" },
                "pr_number": { "type": "integer" },
                "method": { "type": "string", "enum": ["merge", "squash", "rebase"] }
            }),
            vec!["repo", "pr_number"],
        ));
        tools.push(create_tool(
            "github_search_code",
            "Search code on GitHub. Requires GITHUB_TOKEN.",
            json!({
                "query": { "type": "string" },
                "repo": { "type": "string" },
                "limit": { "type": "integer" }
            }),
            vec!["query"],
        ));
        tools.push(create_tool(
            "github_search_repos",
            "Search GitHub repositories. Requires GITHUB_TOKEN.",
            json!({
                "query": { "type": "string" },
                "limit": { "type": "integer" }
            }),
            vec!["query"],
        ));
        tools.push(create_tool(
            "github_get_file",
            "Get file content from a GitHub repository.",
            json!({
                "repo": { "type": "string" },
                "path": { "type": "string" },
                "ref": { "type": "string" }
            }),
            vec!["repo", "path"],
        ));
        tools.push(create_tool(
            "github_workflow_list",
            "List GitHub Actions workflows.",
            json!({
                "repo": { "type": "string" }
            }),
            vec!["repo"],
        ));
        tools.push(create_tool(
            "github_workflow_runs",
            "List GitHub Actions workflow runs.",
            json!({
                "repo": { "type": "string" },
                "workflow_id": { "type": "string" },
                "limit": { "type": "integer" }
            }),
            vec!["repo"],
        ));
    }

    tools
}

fn create_tool(name: &str, desc: &str, props: serde_json::Value, required: Vec<&str>) -> Tool {
    Tool {
        r#type: "function".to_string(),
        function: crate::api::types::FunctionDefinition {
            name: name.to_string(),
            description: desc.to_string(),
            parameters: json!({
                "type": "object",
                "properties": props,
                "required": required
            }),
        },
    }
}