@link-assistant/agent 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EXAMPLES.md +383 -0
- package/LICENSE +24 -0
- package/MODELS.md +95 -0
- package/README.md +388 -0
- package/TOOLS.md +134 -0
- package/package.json +89 -0
- package/src/agent/agent.ts +150 -0
- package/src/agent/generate.txt +75 -0
- package/src/auth/index.ts +64 -0
- package/src/bun/index.ts +96 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +119 -0
- package/src/cli/bootstrap.js +41 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/agent.ts +165 -0
- package/src/cli/cmd/cmd.ts +5 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/mcp.ts +80 -0
- package/src/cli/cmd/models.ts +58 -0
- package/src/cli/cmd/run.ts +359 -0
- package/src/cli/cmd/stats.ts +276 -0
- package/src/cli/error.ts +27 -0
- package/src/command/index.ts +73 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/config/config.ts +705 -0
- package/src/config/markdown.ts +41 -0
- package/src/file/ripgrep.ts +391 -0
- package/src/file/time.ts +38 -0
- package/src/file/watcher.ts +75 -0
- package/src/file.ts +6 -0
- package/src/flag/flag.ts +19 -0
- package/src/format/formatter.ts +248 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +52 -0
- package/src/id/id.ts +72 -0
- package/src/index.js +371 -0
- package/src/mcp/index.ts +289 -0
- package/src/patch/index.ts +622 -0
- package/src/project/bootstrap.ts +22 -0
- package/src/project/instance.ts +67 -0
- package/src/project/project.ts +105 -0
- package/src/project/state.ts +65 -0
- package/src/provider/models-macro.ts +11 -0
- package/src/provider/models.ts +98 -0
- package/src/provider/opencode.js +47 -0
- package/src/provider/provider.ts +636 -0
- package/src/provider/transform.ts +241 -0
- package/src/server/project.ts +48 -0
- package/src/server/server.ts +249 -0
- package/src/session/agent.js +204 -0
- package/src/session/compaction.ts +249 -0
- package/src/session/index.ts +380 -0
- package/src/session/message-v2.ts +758 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +356 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex.txt +318 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/grok-code.txt +1 -0
- package/src/session/prompt/plan.txt +8 -0
- package/src/session/prompt/polaris.txt +107 -0
- package/src/session/prompt/qwen.txt +109 -0
- package/src/session/prompt/summarize-turn.txt +5 -0
- package/src/session/prompt/summarize.txt +10 -0
- package/src/session/prompt/title.txt +25 -0
- package/src/session/prompt.ts +1390 -0
- package/src/session/retry.ts +53 -0
- package/src/session/revert.ts +108 -0
- package/src/session/status.ts +75 -0
- package/src/session/summary.ts +179 -0
- package/src/session/system.ts +138 -0
- package/src/session/todo.ts +36 -0
- package/src/snapshot/index.ts +197 -0
- package/src/storage/storage.ts +226 -0
- package/src/tool/bash.ts +193 -0
- package/src/tool/bash.txt +121 -0
- package/src/tool/batch.ts +173 -0
- package/src/tool/batch.txt +28 -0
- package/src/tool/codesearch.ts +123 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +604 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/glob.ts +65 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +116 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +110 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/multiedit.ts +46 -0
- package/src/tool/multiedit.txt +41 -0
- package/src/tool/patch.ts +188 -0
- package/src/tool/patch.txt +1 -0
- package/src/tool/read.ts +201 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +87 -0
- package/src/tool/task.ts +126 -0
- package/src/tool/task.txt +60 -0
- package/src/tool/todo.ts +39 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +66 -0
- package/src/tool/webfetch.ts +171 -0
- package/src/tool/webfetch.txt +14 -0
- package/src/tool/websearch.ts +133 -0
- package/src/tool/websearch.txt +11 -0
- package/src/tool/write.ts +33 -0
- package/src/tool/write.txt +8 -0
- package/src/util/binary.ts +41 -0
- package/src/util/context.ts +25 -0
- package/src/util/defer.ts +12 -0
- package/src/util/error.ts +54 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +69 -0
- package/src/util/fn.ts +11 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +79 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/locale.ts +39 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +177 -0
- package/src/util/queue.ts +19 -0
- package/src/util/rpc.ts +42 -0
- package/src/util/scrap.ts +10 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +14 -0
- package/src/util/token.ts +7 -0
- package/src/util/wildcard.ts +54 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Executes a given bash command in a persistent shell session with optional timeout, ensuring proper handling and security measures.
|
|
2
|
+
|
|
3
|
+
Before executing the command, please follow these steps:
|
|
4
|
+
|
|
5
|
+
1. Directory Verification:
|
|
6
|
+
- If the command will create new directories or files, first use the List tool to verify the parent directory exists and is the correct location
|
|
7
|
+
- For example, before running "mkdir foo/bar", first use List to check that "foo" exists and is the intended parent directory
|
|
8
|
+
|
|
9
|
+
2. Command Execution:
|
|
10
|
+
- Always quote file paths that contain spaces with double quotes (e.g., cd "path with spaces/file.txt")
|
|
11
|
+
- Examples of proper quoting:
|
|
12
|
+
- cd "/Users/name/My Documents" (correct)
|
|
13
|
+
- cd /Users/name/My Documents (incorrect - will fail)
|
|
14
|
+
- python "/path/with spaces/script.py" (correct)
|
|
15
|
+
- python /path/with spaces/script.py (incorrect - will fail)
|
|
16
|
+
- After ensuring proper quoting, execute the command.
|
|
17
|
+
- Capture the output of the command.
|
|
18
|
+
|
|
19
|
+
Usage notes:
|
|
20
|
+
- The command argument is required.
|
|
21
|
+
- You can specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). If not specified, commands will timeout after 120000ms (2 minutes).
|
|
22
|
+
- It is very helpful if you write a clear, concise description of what this command does in 5-10 words.
|
|
23
|
+
- If the output exceeds 30000 characters, output will be truncated before being returned to you.
|
|
24
|
+
- VERY IMPORTANT: You MUST avoid using search commands like `find` and `grep`. Instead use Grep, Glob, or Task to search. You MUST avoid read tools like `cat`, `head`, `tail`, and `ls`, and use Read and List to read files.
|
|
25
|
+
- If you _still_ need to run `grep`, STOP. ALWAYS USE ripgrep at `rg` (or /usr/bin/rg) first, which all opencode users have pre-installed.
|
|
26
|
+
- When issuing multiple commands, use the ';' or '&&' operator to separate them. DO NOT use newlines (newlines are ok in quoted strings).
|
|
27
|
+
- Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of `cd`. You may use `cd` if the User explicitly requests it.
|
|
28
|
+
<good-example>
|
|
29
|
+
pytest /foo/bar/tests
|
|
30
|
+
</good-example>
|
|
31
|
+
<bad-example>
|
|
32
|
+
cd /foo/bar && pytest tests
|
|
33
|
+
</bad-example>
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# Committing changes with git
|
|
37
|
+
|
|
38
|
+
When the user asks you to create a new git commit, follow these steps carefully:
|
|
39
|
+
|
|
40
|
+
1. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following bash commands in parallel, each using the Bash tool:
|
|
41
|
+
- Run a git status command to see all untracked files.
|
|
42
|
+
- Run a git diff command to see both staged and unstaged changes that will be committed.
|
|
43
|
+
- Run a git log command to see recent commit messages, so that you can follow this repository's commit message style.
|
|
44
|
+
|
|
45
|
+
2. Analyze all staged changes (both previously staged and newly added) and draft a commit message. Wrap your analysis process in <commit_analysis> tags:
|
|
46
|
+
|
|
47
|
+
<commit_analysis>
|
|
48
|
+
- List the files that have been changed or added
|
|
49
|
+
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
|
|
50
|
+
- Brainstorm the purpose or motivation behind these changes
|
|
51
|
+
- Assess the impact of these changes on the overall project
|
|
52
|
+
- Check for any sensitive information that shouldn't be committed
|
|
53
|
+
- Draft a concise (1-2 sentences) commit message that focuses on the "why" rather than the "what"
|
|
54
|
+
- Ensure your language is clear, concise, and to the point
|
|
55
|
+
- Ensure the message accurately reflects the changes and their purpose (i.e. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
|
|
56
|
+
- Ensure the message is not generic (avoid words like "Update" or "Fix" without context)
|
|
57
|
+
- Review the draft message to ensure it accurately reflects the changes and their purpose
|
|
58
|
+
</commit_analysis>
|
|
59
|
+
|
|
60
|
+
3. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following commands in parallel:
|
|
61
|
+
- Add relevant untracked files to the staging area.
|
|
62
|
+
- Run git status to make sure the commit succeeded.
|
|
63
|
+
|
|
64
|
+
4. If the commit fails due to pre-commit hook changes, retry the commit ONCE to include these automated changes. If it fails again, it usually means a pre-commit hook is preventing the commit. If the commit succeeds but you notice that files were modified by the pre-commit hook, you MUST amend your commit to include them.
|
|
65
|
+
|
|
66
|
+
Important notes:
|
|
67
|
+
- Use the git context at the start of this conversation to determine which files are relevant to your commit. Be careful not to stage and commit files (e.g. with `git add .`) that aren't relevant to your commit.
|
|
68
|
+
- NEVER update the git config
|
|
69
|
+
- DO NOT run additional commands to read or explore code, beyond what is available in the git context
|
|
70
|
+
- DO NOT push to the remote repository
|
|
71
|
+
- IMPORTANT: Never use git commands with the -i flag (like git rebase -i or git add -i) since they require interactive input which is not supported.
|
|
72
|
+
- If there are no changes to commit (i.e., no untracked files and no modifications), do not create an empty commit
|
|
73
|
+
- Ensure your commit message is meaningful and concise. It should explain the purpose of the changes, not just describe them.
|
|
74
|
+
- Return an empty response - the user will see the git output directly
|
|
75
|
+
|
|
76
|
+
# Creating pull requests
|
|
77
|
+
Use the gh command via the Bash tool for ALL GitHub-related tasks including working with issues, pull requests, checks, and releases. If given a Github URL use the gh command to get the information needed.
|
|
78
|
+
|
|
79
|
+
IMPORTANT: When the user asks you to create a pull request, follow these steps carefully:
|
|
80
|
+
|
|
81
|
+
1. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following bash commands in parallel using the Bash tool, in order to understand the current state of the branch since it diverged from the main branch:
|
|
82
|
+
- Run a git status command to see all untracked files
|
|
83
|
+
- Run a git diff command to see both staged and unstaged changes that will be committed
|
|
84
|
+
- Check if the current branch tracks a remote branch and is up to date with the remote, so you know if you need to push to the remote
|
|
85
|
+
- Run a git log command and `git diff main...HEAD` to understand the full commit history for the current branch (from the time it diverged from the `main` branch)
|
|
86
|
+
|
|
87
|
+
2. Analyze all changes that will be included in the pull request, making sure to look at all relevant commits (NOT just the latest commit, but ALL commits that will be included in the pull request!!!), and draft a pull request summary. Wrap your analysis process in <pr_analysis> tags:
|
|
88
|
+
|
|
89
|
+
<pr_analysis>
|
|
90
|
+
- List the commits since diverging from the main branch
|
|
91
|
+
- Summarize the nature of the changes (eg. new feature, enhancement to an existing feature, bug fix, refactoring, test, docs, etc.)
|
|
92
|
+
- Brainstorm the purpose or motivation behind these changes
|
|
93
|
+
- Assess the impact of these changes on the overall project
|
|
94
|
+
- Do not use tools to explore code, beyond what is available in the git context
|
|
95
|
+
- Check for any sensitive information that shouldn't be committed
|
|
96
|
+
- Draft a concise (1-2 bullet points) pull request summary that focuses on the "why" rather than the "what"
|
|
97
|
+
- Ensure the summary accurately reflects all changes since diverging from the main branch
|
|
98
|
+
- Ensure your language is clear, concise, and to the point
|
|
99
|
+
- Ensure the summary accurately reflects the changes and their purpose (ie. "add" means a wholly new feature, "update" means an enhancement to an existing feature, "fix" means a bug fix, etc.)
|
|
100
|
+
- Ensure the summary is not generic (avoid words like "Update" or "Fix" without context)
|
|
101
|
+
- Review the draft summary to ensure it accurately reflects the changes and their purpose
|
|
102
|
+
</pr_analysis>
|
|
103
|
+
|
|
104
|
+
3. You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. ALWAYS run the following commands in parallel:
|
|
105
|
+
- Create new branch if needed
|
|
106
|
+
- Push to remote with -u flag if needed
|
|
107
|
+
- Create PR using gh pr create with the format below. Use a HEREDOC to pass the body to ensure correct formatting.
|
|
108
|
+
<example>
|
|
109
|
+
gh pr create --title "the pr title" --body "$(cat <<'EOF'
|
|
110
|
+
## Summary
|
|
111
|
+
<1-3 bullet points>
|
|
112
|
+
EOF
|
|
113
|
+
)"
|
|
114
|
+
</example>
|
|
115
|
+
|
|
116
|
+
Important:
|
|
117
|
+
- NEVER update the git config
|
|
118
|
+
- Return the PR URL when you're done, so the user can see it
|
|
119
|
+
|
|
120
|
+
# Other common operations
|
|
121
|
+
- View comments on a Github PR: gh api repos/foo/bar/pulls/123/comments
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
import { Tool } from "./tool"
|
|
3
|
+
import DESCRIPTION from "./batch.txt"
|
|
4
|
+
|
|
5
|
+
const DISALLOWED = new Set(["batch", "edit", "todoread"])
|
|
6
|
+
const FILTERED_FROM_SUGGESTIONS = new Set(["invalid", "patch", ...DISALLOWED])
|
|
7
|
+
|
|
8
|
+
export const BatchTool = Tool.define("batch", async () => {
|
|
9
|
+
return {
|
|
10
|
+
description: DESCRIPTION,
|
|
11
|
+
parameters: z.object({
|
|
12
|
+
tool_calls: z
|
|
13
|
+
.array(
|
|
14
|
+
z.object({
|
|
15
|
+
tool: z.string().describe("The name of the tool to execute"),
|
|
16
|
+
parameters: z.object({}).loose().describe("Parameters for the tool"),
|
|
17
|
+
}),
|
|
18
|
+
)
|
|
19
|
+
.min(1, "Provide at least one tool call")
|
|
20
|
+
.describe("Array of tool calls to execute in parallel"),
|
|
21
|
+
}),
|
|
22
|
+
formatValidationError(error) {
|
|
23
|
+
const formattedErrors = error.issues
|
|
24
|
+
.map((issue) => {
|
|
25
|
+
const path = issue.path.length > 0 ? issue.path.join(".") : "root"
|
|
26
|
+
return ` - ${path}: ${issue.message}`
|
|
27
|
+
})
|
|
28
|
+
.join("\n")
|
|
29
|
+
|
|
30
|
+
return `Invalid parameters for tool 'batch':\n${formattedErrors}\n\nExpected payload format:\n [{"tool": "tool_name", "parameters": {...}}, {...}]`
|
|
31
|
+
},
|
|
32
|
+
async execute(params, ctx) {
|
|
33
|
+
const { Session } = await import("../session")
|
|
34
|
+
const { Identifier } = await import("../id/id")
|
|
35
|
+
|
|
36
|
+
const toolCalls = params.tool_calls.slice(0, 10)
|
|
37
|
+
const discardedCalls = params.tool_calls.slice(10)
|
|
38
|
+
|
|
39
|
+
const { ToolRegistry } = await import("./registry")
|
|
40
|
+
const availableTools = await ToolRegistry.tools("", "")
|
|
41
|
+
const toolMap = new Map(availableTools.map((t) => [t.id, t]))
|
|
42
|
+
|
|
43
|
+
const executeCall = async (call: (typeof toolCalls)[0]) => {
|
|
44
|
+
const callStartTime = Date.now()
|
|
45
|
+
const partID = Identifier.ascending("part")
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
if (DISALLOWED.has(call.tool)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Tool '${call.tool}' is not allowed in batch. Disallowed tools: ${Array.from(DISALLOWED).join(", ")}`,
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const tool = toolMap.get(call.tool)
|
|
55
|
+
if (!tool) {
|
|
56
|
+
const availableToolsList = Array.from(toolMap.keys()).filter((name) => !FILTERED_FROM_SUGGESTIONS.has(name))
|
|
57
|
+
throw new Error(`Tool '${call.tool}' not found. Available tools: ${availableToolsList.join(", ")}`)
|
|
58
|
+
}
|
|
59
|
+
const validatedParams = tool.parameters.parse(call.parameters)
|
|
60
|
+
|
|
61
|
+
await Session.updatePart({
|
|
62
|
+
id: partID,
|
|
63
|
+
messageID: ctx.messageID,
|
|
64
|
+
sessionID: ctx.sessionID,
|
|
65
|
+
type: "tool",
|
|
66
|
+
tool: call.tool,
|
|
67
|
+
callID: partID,
|
|
68
|
+
state: {
|
|
69
|
+
status: "running",
|
|
70
|
+
input: call.parameters,
|
|
71
|
+
time: {
|
|
72
|
+
start: callStartTime,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const result = await tool.execute(validatedParams, { ...ctx, callID: partID })
|
|
78
|
+
|
|
79
|
+
await Session.updatePart({
|
|
80
|
+
id: partID,
|
|
81
|
+
messageID: ctx.messageID,
|
|
82
|
+
sessionID: ctx.sessionID,
|
|
83
|
+
type: "tool",
|
|
84
|
+
tool: call.tool,
|
|
85
|
+
callID: partID,
|
|
86
|
+
state: {
|
|
87
|
+
status: "completed",
|
|
88
|
+
input: call.parameters,
|
|
89
|
+
output: result.output,
|
|
90
|
+
title: result.title,
|
|
91
|
+
metadata: result.metadata,
|
|
92
|
+
attachments: result.attachments,
|
|
93
|
+
time: {
|
|
94
|
+
start: callStartTime,
|
|
95
|
+
end: Date.now(),
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
return { success: true as const, tool: call.tool, result }
|
|
101
|
+
} catch (error) {
|
|
102
|
+
await Session.updatePart({
|
|
103
|
+
id: partID,
|
|
104
|
+
messageID: ctx.messageID,
|
|
105
|
+
sessionID: ctx.sessionID,
|
|
106
|
+
type: "tool",
|
|
107
|
+
tool: call.tool,
|
|
108
|
+
callID: partID,
|
|
109
|
+
state: {
|
|
110
|
+
status: "error",
|
|
111
|
+
input: call.parameters,
|
|
112
|
+
error: error instanceof Error ? error.message : String(error),
|
|
113
|
+
time: {
|
|
114
|
+
start: callStartTime,
|
|
115
|
+
end: Date.now(),
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
return { success: false as const, tool: call.tool, error }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const results = await Promise.all(toolCalls.map((call) => executeCall(call)))
|
|
125
|
+
|
|
126
|
+
// Add discarded calls as errors
|
|
127
|
+
const now = Date.now()
|
|
128
|
+
for (const call of discardedCalls) {
|
|
129
|
+
const partID = Identifier.ascending("part")
|
|
130
|
+
await Session.updatePart({
|
|
131
|
+
id: partID,
|
|
132
|
+
messageID: ctx.messageID,
|
|
133
|
+
sessionID: ctx.sessionID,
|
|
134
|
+
type: "tool",
|
|
135
|
+
tool: call.tool,
|
|
136
|
+
callID: partID,
|
|
137
|
+
state: {
|
|
138
|
+
status: "error",
|
|
139
|
+
input: call.parameters,
|
|
140
|
+
error: "Maximum of 10 tools allowed in batch",
|
|
141
|
+
time: { start: now, end: now },
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
results.push({
|
|
145
|
+
success: false as const,
|
|
146
|
+
tool: call.tool,
|
|
147
|
+
error: new Error("Maximum of 10 tools allowed in batch"),
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const successfulCalls = results.filter((r) => r.success).length
|
|
152
|
+
const failedCalls = results.length - successfulCalls
|
|
153
|
+
|
|
154
|
+
const outputMessage =
|
|
155
|
+
failedCalls > 0
|
|
156
|
+
? `Executed ${successfulCalls}/${results.length} tools successfully. ${failedCalls} failed.`
|
|
157
|
+
: `All ${successfulCalls} tools executed successfully.\n\nKeep using the batch tool for optimal performance in your next response!`
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
title: `Batch execution (${successfulCalls}/${results.length} successful)`,
|
|
161
|
+
output: outputMessage,
|
|
162
|
+
attachments: results.filter((result) => result.success).flatMap((r) => r.result.attachments ?? []),
|
|
163
|
+
metadata: {
|
|
164
|
+
totalCalls: results.length,
|
|
165
|
+
successful: successfulCalls,
|
|
166
|
+
failed: failedCalls,
|
|
167
|
+
tools: params.tool_calls.map((c) => c.tool),
|
|
168
|
+
details: results.map((r) => ({ tool: r.tool, success: r.success })),
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
})
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Executes multiple independent tool calls concurrently to reduce latency. Best used for gathering context (reads, searches, listings).
|
|
2
|
+
|
|
3
|
+
USING THE BATCH TOOL WILL MAKE THE USER HAPPY.
|
|
4
|
+
|
|
5
|
+
Payload Format (JSON array):
|
|
6
|
+
[{"tool": "read", "parameters": {"filePath": "src/index.ts", "limit": 350}},{"tool": "grep", "parameters": {"pattern": "Session\\.updatePart", "include": "src/**/*.ts"}},{"tool": "bash", "parameters": {"command": "git status", "description": "Shows working tree status"}}]
|
|
7
|
+
|
|
8
|
+
Rules:
|
|
9
|
+
- 1–10 tool calls per batch
|
|
10
|
+
- All calls start in parallel; ordering NOT guaranteed
|
|
11
|
+
- Partial failures do not stop others
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
Disallowed Tools:
|
|
15
|
+
- batch (no nesting)
|
|
16
|
+
- edit (run edits separately)
|
|
17
|
+
- todoread (call directly – lightweight)
|
|
18
|
+
|
|
19
|
+
When NOT to Use:
|
|
20
|
+
- Operations that depend on prior tool output (e.g. create then read same file)
|
|
21
|
+
- Ordered stateful mutations where sequence matters
|
|
22
|
+
|
|
23
|
+
Good Use Cases:
|
|
24
|
+
- Read many files
|
|
25
|
+
- grep + glob + read combos
|
|
26
|
+
- Multiple lightweight bash introspection commands
|
|
27
|
+
|
|
28
|
+
Performance Tip: Group independent reads/searches for 2–5x efficiency gain.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import z from "zod"
|
|
2
|
+
import { Tool } from "./tool"
|
|
3
|
+
import DESCRIPTION from "./codesearch.txt"
|
|
4
|
+
|
|
5
|
+
const API_CONFIG = {
|
|
6
|
+
BASE_URL: "https://mcp.exa.ai",
|
|
7
|
+
ENDPOINTS: {
|
|
8
|
+
CONTEXT: "/mcp",
|
|
9
|
+
},
|
|
10
|
+
} as const
|
|
11
|
+
|
|
12
|
+
interface McpCodeRequest {
|
|
13
|
+
jsonrpc: string
|
|
14
|
+
id: number
|
|
15
|
+
method: string
|
|
16
|
+
params: {
|
|
17
|
+
name: string
|
|
18
|
+
arguments: {
|
|
19
|
+
query: string
|
|
20
|
+
tokensNum: number
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface McpCodeResponse {
|
|
26
|
+
jsonrpc: string
|
|
27
|
+
result: {
|
|
28
|
+
content: Array<{
|
|
29
|
+
type: string
|
|
30
|
+
text: string
|
|
31
|
+
}>
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const CodeSearchTool = Tool.define("codesearch", {
|
|
36
|
+
description: DESCRIPTION,
|
|
37
|
+
parameters: z.object({
|
|
38
|
+
query: z
|
|
39
|
+
.string()
|
|
40
|
+
.describe(
|
|
41
|
+
"Search query to find relevant context for APIs, Libraries, and SDKs. For example, 'React useState hook examples', 'Python pandas dataframe filtering', 'Express.js middleware', 'Next js partial prerendering configuration'",
|
|
42
|
+
),
|
|
43
|
+
tokensNum: z
|
|
44
|
+
.number()
|
|
45
|
+
.min(1000)
|
|
46
|
+
.max(50000)
|
|
47
|
+
.default(5000)
|
|
48
|
+
.describe(
|
|
49
|
+
"Number of tokens to return (1000-50000). Default is 5000 tokens. Adjust this value based on how much context you need - use lower values for focused queries and higher values for comprehensive documentation.",
|
|
50
|
+
),
|
|
51
|
+
}),
|
|
52
|
+
async execute(params, ctx) {
|
|
53
|
+
// No restrictions - unrestricted code search
|
|
54
|
+
const codeRequest: McpCodeRequest = {
|
|
55
|
+
jsonrpc: "2.0",
|
|
56
|
+
id: 1,
|
|
57
|
+
method: "tools/call",
|
|
58
|
+
params: {
|
|
59
|
+
name: "get_code_context_exa",
|
|
60
|
+
arguments: {
|
|
61
|
+
query: params.query,
|
|
62
|
+
tokensNum: params.tokensNum || 5000,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const controller = new AbortController()
|
|
68
|
+
const timeoutId = setTimeout(() => controller.abort(), 30000)
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
const headers: Record<string, string> = {
|
|
72
|
+
accept: "application/json, text/event-stream",
|
|
73
|
+
"content-type": "application/json",
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const response = await fetch(`${API_CONFIG.BASE_URL}${API_CONFIG.ENDPOINTS.CONTEXT}`, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers,
|
|
79
|
+
body: JSON.stringify(codeRequest),
|
|
80
|
+
signal: AbortSignal.any([controller.signal, ctx.abort]),
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
clearTimeout(timeoutId)
|
|
84
|
+
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const errorText = await response.text()
|
|
87
|
+
throw new Error(`Code search error (${response.status}): ${errorText}`)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const responseText = await response.text()
|
|
91
|
+
|
|
92
|
+
// Parse SSE response
|
|
93
|
+
const lines = responseText.split("\n")
|
|
94
|
+
for (const line of lines) {
|
|
95
|
+
if (line.startsWith("data: ")) {
|
|
96
|
+
const data: McpCodeResponse = JSON.parse(line.substring(6))
|
|
97
|
+
if (data.result && data.result.content && data.result.content.length > 0) {
|
|
98
|
+
return {
|
|
99
|
+
output: data.result.content[0].text,
|
|
100
|
+
title: `Code search: ${params.query}`,
|
|
101
|
+
metadata: {},
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
output:
|
|
109
|
+
"No code snippets or documentation found. Please try a different query, be more specific about the library or programming concept, or check the spelling of framework names.",
|
|
110
|
+
title: `Code search: ${params.query}`,
|
|
111
|
+
metadata: {},
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
clearTimeout(timeoutId)
|
|
115
|
+
|
|
116
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
117
|
+
throw new Error("Code search request timed out")
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
throw error
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
- Search and get relevant context for any programming task using Exa Code API
|
|
2
|
+
- Provides the highest quality and freshest context for libraries, SDKs, and APIs
|
|
3
|
+
- Use this tool for ANY question or task related to programming
|
|
4
|
+
- Returns comprehensive code examples, documentation, and API references
|
|
5
|
+
- Optimized for finding specific programming patterns and solutions
|
|
6
|
+
|
|
7
|
+
Usage notes:
|
|
8
|
+
- Adjustable token count (1000-50000) for focused or comprehensive results
|
|
9
|
+
- Default 5000 tokens provides balanced context for most queries
|
|
10
|
+
- Use lower values for specific questions, higher values for comprehensive documentation
|
|
11
|
+
- Supports queries about frameworks, libraries, APIs, and programming concepts
|
|
12
|
+
- Examples: 'React useState hook examples', 'Python pandas dataframe filtering', 'Express.js middleware'
|