跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

filesystem.go

99 行 · 4.2 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4// Portion of AI prompt texts from:
5// - https://github.com/google-gemini/gemini-cli/blob/v0.1.12/docs/tools/file-system.md
6//
7// SPDX-FileCopyrightText: Copyright 2025 Google LLC
8
9package msi
10
11import (
12 "io/fs"
13 "time"
14
15 "github.com/modelcontextprotocol/go-sdk/mcp"
16)
17
18var ListDirectory = &mcp.Tool{
19 Name: "list_directory",
20 Description: `Lists the names of files and subdirectories directly within a specified directory path.`,
21}
22
23type ListDirectoryParams struct {
24 Path string `json:"path" jsonschema:"The absolute path to the directory to list."`
25}
26
27// ListDirectoryResultEntry is similar to [io/fs.FileInfo].
28type ListDirectoryResultEntry struct {
29 Name string `json:"name" jsonschema:"base name of the file"`
30 Size *int64 `json:"size,omitempty" jsonschema:"length in bytes for regular files; system-dependent for others"`
31 Mode *fs.FileMode `json:"mode,omitempty" jsonschema:"file mode bits"`
32 ModTime *time.Time `json:"time,omitempty" jsonschema:"modification time"`
33 IsDir *bool `json:"is_dir,omitempty" jsonschema:"true for a directory"`
34}
35
36type ListDirectoryResult struct {
37 Entries []ListDirectoryResultEntry `json:"entries" jsonschema:"The directory content entries."`
38}
39
40var ReadFile = &mcp.Tool{
41 Name: "read_file",
42 Description: `Reads and returns the content of a specified file.`,
43}
44
45type ReadFileResult struct {
46 Content string `json:"content" jsonschema:"The content of the file."`
47}
48
49type ReadFileParams struct {
50 Path string `json:"path" jsonschema:"The absolute path to the file to read."`
51 // TODO: Offset *int `json:"offset,omitempty" jsonschema:"For text files, the 0-based line number to start reading from. Requires limit to be set."`
52 // TODO: Limit *int `json:"limit,omitempty" jsonschema:"For text files, the maximum number of lines to read. If omitted, reads a default maximum (e.g., 2000 lines) or the entire file if feasible."`
53}
54
55var WriteFile = &mcp.Tool{
56 Name: "write_file",
57 Description: `Writes content to a specified file. If the file exists, it will be overwritten. If the file doesn't exist, it (and any necessary parent directories) will be created.`,
58}
59
60type WriteFileResult struct {
61 // Empty for now
62}
63
64type WriteFileParams struct {
65 Path string `json:"path" jsonschema:"The absolute path to the file to write to."`
66 Content string `json:"content" jsonschema:"The content to write into the file."`
67}
68
69var Glob = &mcp.Tool{
70 Name: "glob",
71 Description: `Finds files matching specific glob patterns (e.g., src/**/*.ts, *.md)`, // Not sorted by mod time, unlike Gemini
72}
73
74type GlobParams struct {
75 Pattern string `json:"pattern" jsonschema:"The glob pattern to match against (e.g., '*.py', 'src/**/*.js')."`
76 Path *string `json:"path,omitempty" jsonschema:"The absolute path to the directory to search within. If omitted, searches the tool's root directory."`
77 // TODO: CaseSensitive bool `json:"case_sensitive,omitempty" jsonschema:": Whether the search should be case-sensitive. Defaults to false."`
78}
79
80type GlobResult struct {
81 Matches []string `json:"matches" jsonschema:"A list of absolute file paths that match the provided glob pattern."`
82}
83
84var SearchFileContent = &mcp.Tool{
85 Name: "search_file_content",
86 Description: `Searches for a regular expression pattern within the content of files in a specified directory. Internally calls 'git grep -n --no-index'.`,
87}
88
89type SearchFileContentParams struct {
90 Pattern string `json:"pattern" jsonschema:"The regular expression (regex) to search for (e.g., 'function\\s+myFunction')."`
91 Path *string `json:"path,omitempty" jsonschema:"The absolute path to the directory to search within. Defaults to the current working directory."`
92 Include *string `json:"include,omitempty" jsonschema:"A glob pattern to filter which files are searched (e.g., '*.js', 'src/**/*.{ts,tsx}'). If omitted, searches most files (respecting common ignores)."`
93}
94
95type SearchFileContentResult struct {
96 GitGrepOutput string `json:"git_grep_output" jsonschema:"The raw output from the 'git grep -n --no-index' command, containing matching lines with filenames and line numbers."`
97}
98
99// TODO: implement Replace