cmdr-agent 1.0.0
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/LICENSE +21 -0
- package/README.md +238 -0
- package/dist/bin/cmdr.d.ts +9 -0
- package/dist/bin/cmdr.d.ts.map +1 -0
- package/dist/bin/cmdr.js +49 -0
- package/dist/bin/cmdr.js.map +1 -0
- package/dist/src/cli/args.d.ts +19 -0
- package/dist/src/cli/args.d.ts.map +1 -0
- package/dist/src/cli/args.js +89 -0
- package/dist/src/cli/args.js.map +1 -0
- package/dist/src/cli/commands.d.ts +12 -0
- package/dist/src/cli/commands.d.ts.map +1 -0
- package/dist/src/cli/commands.js +400 -0
- package/dist/src/cli/commands.js.map +1 -0
- package/dist/src/cli/renderer.d.ts +8 -0
- package/dist/src/cli/renderer.d.ts.map +1 -0
- package/dist/src/cli/renderer.js +47 -0
- package/dist/src/cli/renderer.js.map +1 -0
- package/dist/src/cli/repl.d.ts +18 -0
- package/dist/src/cli/repl.d.ts.map +1 -0
- package/dist/src/cli/repl.js +751 -0
- package/dist/src/cli/repl.js.map +1 -0
- package/dist/src/cli/spinner.d.ts +16 -0
- package/dist/src/cli/spinner.d.ts.map +1 -0
- package/dist/src/cli/spinner.js +233 -0
- package/dist/src/cli/spinner.js.map +1 -0
- package/dist/src/cli/theme.d.ts +95 -0
- package/dist/src/cli/theme.d.ts.map +1 -0
- package/dist/src/cli/theme.js +178 -0
- package/dist/src/cli/theme.js.map +1 -0
- package/dist/src/communication/message-bus.d.ts +35 -0
- package/dist/src/communication/message-bus.d.ts.map +1 -0
- package/dist/src/communication/message-bus.js +60 -0
- package/dist/src/communication/message-bus.js.map +1 -0
- package/dist/src/communication/shared-memory.d.ts +19 -0
- package/dist/src/communication/shared-memory.d.ts.map +1 -0
- package/dist/src/communication/shared-memory.js +37 -0
- package/dist/src/communication/shared-memory.js.map +1 -0
- package/dist/src/communication/task-queue.d.ts +50 -0
- package/dist/src/communication/task-queue.d.ts.map +1 -0
- package/dist/src/communication/task-queue.js +158 -0
- package/dist/src/communication/task-queue.js.map +1 -0
- package/dist/src/config/config-loader.d.ts +23 -0
- package/dist/src/config/config-loader.d.ts.map +1 -0
- package/dist/src/config/config-loader.js +91 -0
- package/dist/src/config/config-loader.js.map +1 -0
- package/dist/src/config/defaults.d.ts +6 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +21 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/schema.d.ts +135 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +35 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/config/telemetry.d.ts +41 -0
- package/dist/src/config/telemetry.d.ts.map +1 -0
- package/dist/src/config/telemetry.js +57 -0
- package/dist/src/config/telemetry.js.map +1 -0
- package/dist/src/core/agent-pool.d.ts +40 -0
- package/dist/src/core/agent-pool.d.ts.map +1 -0
- package/dist/src/core/agent-pool.js +66 -0
- package/dist/src/core/agent-pool.js.map +1 -0
- package/dist/src/core/agent-runner.d.ts +51 -0
- package/dist/src/core/agent-runner.d.ts.map +1 -0
- package/dist/src/core/agent-runner.js +251 -0
- package/dist/src/core/agent-runner.js.map +1 -0
- package/dist/src/core/agent.d.ts +34 -0
- package/dist/src/core/agent.d.ts.map +1 -0
- package/dist/src/core/agent.js +143 -0
- package/dist/src/core/agent.js.map +1 -0
- package/dist/src/core/intent.d.ts +33 -0
- package/dist/src/core/intent.d.ts.map +1 -0
- package/dist/src/core/intent.js +91 -0
- package/dist/src/core/intent.js.map +1 -0
- package/dist/src/core/orchestrator.d.ts +43 -0
- package/dist/src/core/orchestrator.d.ts.map +1 -0
- package/dist/src/core/orchestrator.js +115 -0
- package/dist/src/core/orchestrator.js.map +1 -0
- package/dist/src/core/permissions.d.ts +36 -0
- package/dist/src/core/permissions.d.ts.map +1 -0
- package/dist/src/core/permissions.js +129 -0
- package/dist/src/core/permissions.js.map +1 -0
- package/dist/src/core/presets.d.ts +12 -0
- package/dist/src/core/presets.d.ts.map +1 -0
- package/dist/src/core/presets.js +148 -0
- package/dist/src/core/presets.js.map +1 -0
- package/dist/src/core/team.d.ts +44 -0
- package/dist/src/core/team.d.ts.map +1 -0
- package/dist/src/core/team.js +156 -0
- package/dist/src/core/team.js.map +1 -0
- package/dist/src/core/types.d.ts +257 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +7 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/index.d.ts +44 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/llm/adapter.d.ts +5 -0
- package/dist/src/llm/adapter.d.ts.map +1 -0
- package/dist/src/llm/adapter.js +5 -0
- package/dist/src/llm/adapter.js.map +1 -0
- package/dist/src/llm/model-registry.d.ts +14 -0
- package/dist/src/llm/model-registry.d.ts.map +1 -0
- package/dist/src/llm/model-registry.js +30 -0
- package/dist/src/llm/model-registry.js.map +1 -0
- package/dist/src/llm/ollama.d.ts +26 -0
- package/dist/src/llm/ollama.d.ts.map +1 -0
- package/dist/src/llm/ollama.js +375 -0
- package/dist/src/llm/ollama.js.map +1 -0
- package/dist/src/llm/token-counter.d.ts +11 -0
- package/dist/src/llm/token-counter.d.ts.map +1 -0
- package/dist/src/llm/token-counter.js +35 -0
- package/dist/src/llm/token-counter.js.map +1 -0
- package/dist/src/plugins/mcp-client.d.ts +38 -0
- package/dist/src/plugins/mcp-client.d.ts.map +1 -0
- package/dist/src/plugins/mcp-client.js +113 -0
- package/dist/src/plugins/mcp-client.js.map +1 -0
- package/dist/src/plugins/plugin-manager.d.ts +37 -0
- package/dist/src/plugins/plugin-manager.d.ts.map +1 -0
- package/dist/src/plugins/plugin-manager.js +146 -0
- package/dist/src/plugins/plugin-manager.js.map +1 -0
- package/dist/src/scheduling/semaphore.d.ts +20 -0
- package/dist/src/scheduling/semaphore.d.ts.map +1 -0
- package/dist/src/scheduling/semaphore.js +52 -0
- package/dist/src/scheduling/semaphore.js.map +1 -0
- package/dist/src/scheduling/strategies.d.ts +39 -0
- package/dist/src/scheduling/strategies.d.ts.map +1 -0
- package/dist/src/scheduling/strategies.js +88 -0
- package/dist/src/scheduling/strategies.js.map +1 -0
- package/dist/src/session/compaction.d.ts +32 -0
- package/dist/src/session/compaction.d.ts.map +1 -0
- package/dist/src/session/compaction.js +172 -0
- package/dist/src/session/compaction.js.map +1 -0
- package/dist/src/session/cost-tracker.d.ts +41 -0
- package/dist/src/session/cost-tracker.d.ts.map +1 -0
- package/dist/src/session/cost-tracker.js +76 -0
- package/dist/src/session/cost-tracker.js.map +1 -0
- package/dist/src/session/project-context.d.ts +6 -0
- package/dist/src/session/project-context.d.ts.map +1 -0
- package/dist/src/session/project-context.js +147 -0
- package/dist/src/session/project-context.js.map +1 -0
- package/dist/src/session/prompt-builder.d.ts +11 -0
- package/dist/src/session/prompt-builder.d.ts.map +1 -0
- package/dist/src/session/prompt-builder.js +30 -0
- package/dist/src/session/prompt-builder.js.map +1 -0
- package/dist/src/session/session-manager.d.ts +32 -0
- package/dist/src/session/session-manager.d.ts.map +1 -0
- package/dist/src/session/session-manager.js +84 -0
- package/dist/src/session/session-manager.js.map +1 -0
- package/dist/src/session/session-persistence.d.ts +44 -0
- package/dist/src/session/session-persistence.d.ts.map +1 -0
- package/dist/src/session/session-persistence.js +150 -0
- package/dist/src/session/session-persistence.js.map +1 -0
- package/dist/src/session/undo-manager.d.ts +35 -0
- package/dist/src/session/undo-manager.d.ts.map +1 -0
- package/dist/src/session/undo-manager.js +79 -0
- package/dist/src/session/undo-manager.js.map +1 -0
- package/dist/src/tools/built-in/ask-user.d.ts +7 -0
- package/dist/src/tools/built-in/ask-user.d.ts.map +1 -0
- package/dist/src/tools/built-in/ask-user.js +28 -0
- package/dist/src/tools/built-in/ask-user.js.map +1 -0
- package/dist/src/tools/built-in/bash.d.ts +9 -0
- package/dist/src/tools/built-in/bash.d.ts.map +1 -0
- package/dist/src/tools/built-in/bash.js +67 -0
- package/dist/src/tools/built-in/bash.js.map +1 -0
- package/dist/src/tools/built-in/file-edit.d.ts +9 -0
- package/dist/src/tools/built-in/file-edit.d.ts.map +1 -0
- package/dist/src/tools/built-in/file-edit.js +39 -0
- package/dist/src/tools/built-in/file-edit.js.map +1 -0
- package/dist/src/tools/built-in/file-read.d.ts +9 -0
- package/dist/src/tools/built-in/file-read.d.ts.map +1 -0
- package/dist/src/tools/built-in/file-read.js +41 -0
- package/dist/src/tools/built-in/file-read.js.map +1 -0
- package/dist/src/tools/built-in/file-write.d.ts +8 -0
- package/dist/src/tools/built-in/file-write.d.ts.map +1 -0
- package/dist/src/tools/built-in/file-write.js +29 -0
- package/dist/src/tools/built-in/file-write.js.map +1 -0
- package/dist/src/tools/built-in/git-commit.d.ts +12 -0
- package/dist/src/tools/built-in/git-commit.d.ts.map +1 -0
- package/dist/src/tools/built-in/git-commit.js +96 -0
- package/dist/src/tools/built-in/git-commit.js.map +1 -0
- package/dist/src/tools/built-in/git-diff.d.ts +8 -0
- package/dist/src/tools/built-in/git-diff.d.ts.map +1 -0
- package/dist/src/tools/built-in/git-diff.js +43 -0
- package/dist/src/tools/built-in/git-diff.js.map +1 -0
- package/dist/src/tools/built-in/git-log.d.ts +8 -0
- package/dist/src/tools/built-in/git-log.d.ts.map +1 -0
- package/dist/src/tools/built-in/git-log.js +39 -0
- package/dist/src/tools/built-in/git-log.js.map +1 -0
- package/dist/src/tools/built-in/glob.d.ts +8 -0
- package/dist/src/tools/built-in/glob.d.ts.map +1 -0
- package/dist/src/tools/built-in/glob.js +60 -0
- package/dist/src/tools/built-in/glob.js.map +1 -0
- package/dist/src/tools/built-in/grep.d.ts +9 -0
- package/dist/src/tools/built-in/grep.d.ts.map +1 -0
- package/dist/src/tools/built-in/grep.js +115 -0
- package/dist/src/tools/built-in/grep.js.map +1 -0
- package/dist/src/tools/built-in/index.d.ts +21 -0
- package/dist/src/tools/built-in/index.d.ts.map +1 -0
- package/dist/src/tools/built-in/index.js +30 -0
- package/dist/src/tools/built-in/index.js.map +1 -0
- package/dist/src/tools/built-in/think.d.ts +7 -0
- package/dist/src/tools/built-in/think.d.ts.map +1 -0
- package/dist/src/tools/built-in/think.js +18 -0
- package/dist/src/tools/built-in/think.js.map +1 -0
- package/dist/src/tools/built-in/web-fetch.d.ts +11 -0
- package/dist/src/tools/built-in/web-fetch.d.ts.map +1 -0
- package/dist/src/tools/built-in/web-fetch.js +70 -0
- package/dist/src/tools/built-in/web-fetch.js.map +1 -0
- package/dist/src/tools/executor.d.ts +25 -0
- package/dist/src/tools/executor.d.ts.map +1 -0
- package/dist/src/tools/executor.js +61 -0
- package/dist/src/tools/executor.js.map +1 -0
- package/dist/src/tools/registry.d.ts +25 -0
- package/dist/src/tools/registry.d.ts.map +1 -0
- package/dist/src/tools/registry.js +135 -0
- package/dist/src/tools/registry.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in git_commit tool — commit changes from the working tree.
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { defineTool } from '../registry.js';
|
|
7
|
+
function runGit(args, cwd) {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
const child = spawn('git', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
10
|
+
const stdout = [];
|
|
11
|
+
const stderr = [];
|
|
12
|
+
child.stdout.on('data', (c) => stdout.push(c));
|
|
13
|
+
child.stderr.on('data', (c) => stderr.push(c));
|
|
14
|
+
child.on('close', (code) => {
|
|
15
|
+
resolve({
|
|
16
|
+
stdout: Buffer.concat(stdout).toString('utf-8').trim(),
|
|
17
|
+
stderr: Buffer.concat(stderr).toString('utf-8').trim(),
|
|
18
|
+
code: code ?? 1,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
child.on('error', (err) => {
|
|
22
|
+
resolve({ stdout: '', stderr: err.message, code: 1 });
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export const gitCommitTool = defineTool({
|
|
27
|
+
name: 'git_commit',
|
|
28
|
+
description: 'Stage and commit files. Can stage specific files or all changes, ' +
|
|
29
|
+
'then create a commit with the given message.',
|
|
30
|
+
inputSchema: z.object({
|
|
31
|
+
message: z.string().describe('Commit message.'),
|
|
32
|
+
files: z.array(z.string()).optional().describe('Specific files to stage. If omitted, stages all changes (git add -A).'),
|
|
33
|
+
}),
|
|
34
|
+
execute: async (input, context) => {
|
|
35
|
+
const cwd = context.cwd ?? process.cwd();
|
|
36
|
+
// Stage files
|
|
37
|
+
if (input.files && input.files.length > 0) {
|
|
38
|
+
const stageResult = await runGit(['add', '--', ...input.files], cwd);
|
|
39
|
+
if (stageResult.code !== 0) {
|
|
40
|
+
return { data: `git add failed: ${stageResult.stderr}`, isError: true };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const stageResult = await runGit(['add', '-A'], cwd);
|
|
45
|
+
if (stageResult.code !== 0) {
|
|
46
|
+
return { data: `git add failed: ${stageResult.stderr}`, isError: true };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Commit
|
|
50
|
+
const commitResult = await runGit(['commit', '-m', input.message], cwd);
|
|
51
|
+
if (commitResult.code !== 0) {
|
|
52
|
+
// "nothing to commit" is not really an error
|
|
53
|
+
if (commitResult.stdout.includes('nothing to commit')) {
|
|
54
|
+
return { data: 'Nothing to commit, working tree clean.' };
|
|
55
|
+
}
|
|
56
|
+
return { data: `git commit failed: ${commitResult.stderr || commitResult.stdout}`, isError: true };
|
|
57
|
+
}
|
|
58
|
+
return { data: commitResult.stdout };
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
export const gitBranchTool = defineTool({
|
|
62
|
+
name: 'git_branch',
|
|
63
|
+
description: 'Create, switch, or list git branches.',
|
|
64
|
+
inputSchema: z.object({
|
|
65
|
+
action: z.enum(['list', 'create', 'switch']).describe('Branch action.'),
|
|
66
|
+
name: z.string().optional().describe('Branch name (for create/switch).'),
|
|
67
|
+
}),
|
|
68
|
+
execute: async (input, context) => {
|
|
69
|
+
const cwd = context.cwd ?? process.cwd();
|
|
70
|
+
switch (input.action) {
|
|
71
|
+
case 'list': {
|
|
72
|
+
const result = await runGit(['branch', '--no-color', '-a'], cwd);
|
|
73
|
+
return { data: result.stdout || '(no branches)', isError: result.code !== 0 };
|
|
74
|
+
}
|
|
75
|
+
case 'create': {
|
|
76
|
+
if (!input.name)
|
|
77
|
+
return { data: 'Branch name required.', isError: true };
|
|
78
|
+
const result = await runGit(['checkout', '-b', input.name], cwd);
|
|
79
|
+
if (result.code !== 0) {
|
|
80
|
+
return { data: result.stderr, isError: true };
|
|
81
|
+
}
|
|
82
|
+
return { data: `Created and switched to branch: ${input.name}` };
|
|
83
|
+
}
|
|
84
|
+
case 'switch': {
|
|
85
|
+
if (!input.name)
|
|
86
|
+
return { data: 'Branch name required.', isError: true };
|
|
87
|
+
const result = await runGit(['checkout', input.name], cwd);
|
|
88
|
+
if (result.code !== 0) {
|
|
89
|
+
return { data: result.stderr, isError: true };
|
|
90
|
+
}
|
|
91
|
+
return { data: `Switched to branch: ${input.name}` };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
//# sourceMappingURL=git-commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git-commit.js","sourceRoot":"","sources":["../../../../src/tools/built-in/git-commit.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,SAAS,MAAM,CAAC,IAAc,EAAE,GAAW;IACzC,OAAO,IAAI,OAAO,CAAC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AO,MAAM,WAAW;;;EAwCtB,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in git_diff tool — show git diff of working tree.
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { defineTool } from '../registry.js';
|
|
7
|
+
export const gitDiffTool = defineTool({
|
|
8
|
+
name: 'git_diff',
|
|
9
|
+
description: 'Show the git diff of the working tree or staged changes. ' +
|
|
10
|
+
'Useful for reviewing changes before committing.',
|
|
11
|
+
inputSchema: z.object({
|
|
12
|
+
staged: z.boolean().optional().describe('If true, show staged changes (--cached).'),
|
|
13
|
+
path: z.string().optional().describe('Limit diff to a specific file or directory.'),
|
|
14
|
+
}),
|
|
15
|
+
execute: async (input, context) => {
|
|
16
|
+
const args = ['diff', '--no-color'];
|
|
17
|
+
if (input.staged)
|
|
18
|
+
args.push('--cached');
|
|
19
|
+
if (input.path)
|
|
20
|
+
args.push('--', input.path);
|
|
21
|
+
const cwd = context.cwd ?? process.cwd();
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
const child = spawn('git', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
24
|
+
const chunks = [];
|
|
25
|
+
const errChunks = [];
|
|
26
|
+
child.stdout.on('data', (c) => chunks.push(c));
|
|
27
|
+
child.stderr.on('data', (c) => errChunks.push(c));
|
|
28
|
+
child.on('close', (code) => {
|
|
29
|
+
if (code === 0) {
|
|
30
|
+
const output = Buffer.concat(chunks).toString('utf-8').trim();
|
|
31
|
+
resolve({ data: output || '(no changes)' });
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
resolve({ data: Buffer.concat(errChunks).toString('utf-8'), isError: true });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
child.on('error', (err) => {
|
|
38
|
+
resolve({ data: err.message, isError: true });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
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"mappings":"AAAA;;GAEG;AAMH,eAAO,MAAM,UAAU;;;EAoCrB,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in git_log tool — recent git history.
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { defineTool } from '../registry.js';
|
|
7
|
+
export const gitLogTool = defineTool({
|
|
8
|
+
name: 'git_log',
|
|
9
|
+
description: 'Show recent git commit history.',
|
|
10
|
+
inputSchema: z.object({
|
|
11
|
+
count: z.number().optional().describe('Number of commits to show. Defaults to 10.'),
|
|
12
|
+
oneline: z.boolean().optional().describe('Use one-line format. Defaults to true.'),
|
|
13
|
+
}),
|
|
14
|
+
execute: async (input, context) => {
|
|
15
|
+
const count = input.count ?? 10;
|
|
16
|
+
const format = input.oneline !== false ? '--oneline' : '--format=medium';
|
|
17
|
+
const args = ['log', format, `-n${count}`, '--no-color'];
|
|
18
|
+
const cwd = context.cwd ?? process.cwd();
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
const child = spawn('git', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
21
|
+
const chunks = [];
|
|
22
|
+
const errChunks = [];
|
|
23
|
+
child.stdout.on('data', (c) => chunks.push(c));
|
|
24
|
+
child.stderr.on('data', (c) => errChunks.push(c));
|
|
25
|
+
child.on('close', (code) => {
|
|
26
|
+
if (code === 0) {
|
|
27
|
+
resolve({ data: Buffer.concat(chunks).toString('utf-8').trim() || '(no commits)' });
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
resolve({ data: Buffer.concat(errChunks).toString('utf-8'), isError: true });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
child.on('error', (err) => {
|
|
34
|
+
resolve({ data: err.message, isError: true });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=git-log.js.map
|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 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in glob tool — find files by pattern.
|
|
3
|
+
*/
|
|
4
|
+
import { readdir } from 'fs/promises';
|
|
5
|
+
import { join, relative } from 'path';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { defineTool } from '../registry.js';
|
|
8
|
+
export const globTool = defineTool({
|
|
9
|
+
name: 'glob',
|
|
10
|
+
description: 'Find files matching a glob pattern. Useful for discovering project structure. ' +
|
|
11
|
+
'Skips node_modules and hidden directories by default.',
|
|
12
|
+
inputSchema: z.object({
|
|
13
|
+
pattern: z.string().describe('Glob pattern (e.g. "**/*.ts", "src/**/*.js").'),
|
|
14
|
+
path: z.string().optional().describe('Root directory to search from. Defaults to cwd.'),
|
|
15
|
+
}),
|
|
16
|
+
execute: async (input, context) => {
|
|
17
|
+
const root = input.path ?? context.cwd ?? process.cwd();
|
|
18
|
+
const regex = globToRegex(input.pattern);
|
|
19
|
+
const matches = [];
|
|
20
|
+
async function walk(dir) {
|
|
21
|
+
if (matches.length > 500)
|
|
22
|
+
return;
|
|
23
|
+
try {
|
|
24
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
25
|
+
for (const entry of entries) {
|
|
26
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules')
|
|
27
|
+
continue;
|
|
28
|
+
const full = join(dir, entry.name);
|
|
29
|
+
const rel = relative(root, full);
|
|
30
|
+
if (entry.isDirectory()) {
|
|
31
|
+
if (regex.test(rel + '/'))
|
|
32
|
+
matches.push(rel + '/');
|
|
33
|
+
await walk(full);
|
|
34
|
+
}
|
|
35
|
+
else if (entry.isFile() && regex.test(rel)) {
|
|
36
|
+
matches.push(rel);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// skip unreadable directories
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
await walk(root);
|
|
45
|
+
return { data: matches.slice(0, 500).join('\n') || '(no matches)' };
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
function globToRegex(glob) {
|
|
49
|
+
let pattern = glob
|
|
50
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
51
|
+
// Handle glob ? FIRST (before we generate regex ? quantifiers)
|
|
52
|
+
.replace(/\?/g, '[^/]')
|
|
53
|
+
// Handle **/ (match zero or more directories)
|
|
54
|
+
.replace(/\*\*\//g, '(.+/)?')
|
|
55
|
+
// Handle remaining ** (e.g. trailing /**)
|
|
56
|
+
.replace(/\*\*/g, '.*')
|
|
57
|
+
.replace(/\*/g, '[^/]*');
|
|
58
|
+
return new RegExp(`^${pattern}$`, 'i');
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=glob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../../src/tools/built-in/glob.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAQ,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;IACjC,IAAI,EAAE,MAAM;IACZ,WAAW,EACT,gFAAgF;QAChF,uDAAuD;IAEzD,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;QAC7E,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iDAAiD,CAAC;KACxF,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAChC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI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K,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,cAAc,EAAE,CAAA;IACrE,CAAC;CACF,CAAC,CAAA;AAEF,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,OAAO,GAAG,IAAI;SACf,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC;QACrC,+DAA+D;SAC9D,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,8CAA8C;SAC7C,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC;QAC7B,0CAA0C;SACzC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC;SACtB,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAC1B,OAAO,IAAI,MAAM,CAAC,IAAI,OAAO,GAAG,EAAE,GAAG,CAAC,CAAA;AACxC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in grep tool — search files with regex, ripgrep-first with Node fallback.
|
|
3
|
+
*/
|
|
4
|
+
export declare const grepTool: import("../registry.js").ToolDefinition<{
|
|
5
|
+
pattern: string;
|
|
6
|
+
path?: string | undefined;
|
|
7
|
+
include?: string | undefined;
|
|
8
|
+
}>;
|
|
9
|
+
//# sourceMappingURL=grep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../../../src/tools/built-in/grep.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,eAAO,MAAM,QAAQ;;;;EA6BnB,CAAA"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in grep tool — search files with regex, ripgrep-first with Node fallback.
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import { readdir, readFile, stat } from 'fs/promises';
|
|
6
|
+
import { join, relative } from 'path';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { defineTool } from '../registry.js';
|
|
9
|
+
export const grepTool = defineTool({
|
|
10
|
+
name: 'grep',
|
|
11
|
+
description: 'Search for a regex pattern in files. Uses ripgrep (rg) if available, ' +
|
|
12
|
+
'otherwise falls back to a Node.js implementation. Returns matching lines with file paths.',
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
pattern: z.string().describe('Regex pattern to search for.'),
|
|
15
|
+
path: z.string().optional().describe('Directory or file to search in. Defaults to cwd.'),
|
|
16
|
+
include: z.string().optional().describe('Glob pattern to filter files (e.g. "*.ts").'),
|
|
17
|
+
}),
|
|
18
|
+
execute: async (input, context) => {
|
|
19
|
+
const searchPath = input.path ?? context.cwd ?? process.cwd();
|
|
20
|
+
try {
|
|
21
|
+
const result = await tryRipgrep(input.pattern, searchPath, input.include);
|
|
22
|
+
return { data: result || '(no matches)' };
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// ripgrep not available, use Node fallback
|
|
26
|
+
try {
|
|
27
|
+
const result = await nodeGrep(input.pattern, searchPath, input.include);
|
|
28
|
+
return { data: result || '(no matches)' };
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
32
|
+
return { data: msg, isError: true };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
function tryRipgrep(pattern, searchPath, include) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
const args = ['--no-heading', '--line-number', '--color', 'never', '-e', pattern];
|
|
40
|
+
if (include)
|
|
41
|
+
args.push('--glob', include);
|
|
42
|
+
args.push(searchPath);
|
|
43
|
+
const child = spawn('rg', args, { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
44
|
+
const chunks = [];
|
|
45
|
+
child.stdout.on('data', (chunk) => chunks.push(chunk));
|
|
46
|
+
child.on('close', (code) => {
|
|
47
|
+
if (code === 0 || code === 1) {
|
|
48
|
+
resolve(Buffer.concat(chunks).toString('utf-8').trim());
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
reject(new Error(`rg exited with code ${code}`));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
child.on('error', reject);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async function nodeGrep(pattern, searchPath, include) {
|
|
58
|
+
const regex = new RegExp(pattern, 'gi');
|
|
59
|
+
const includeRegex = include ? globToRegex(include) : null;
|
|
60
|
+
const results = [];
|
|
61
|
+
async function walk(dir) {
|
|
62
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules')
|
|
65
|
+
continue;
|
|
66
|
+
const full = join(dir, entry.name);
|
|
67
|
+
if (entry.isDirectory()) {
|
|
68
|
+
await walk(full);
|
|
69
|
+
}
|
|
70
|
+
else if (entry.isFile()) {
|
|
71
|
+
if (includeRegex && !includeRegex.test(entry.name))
|
|
72
|
+
continue;
|
|
73
|
+
try {
|
|
74
|
+
const content = await readFile(full, 'utf-8');
|
|
75
|
+
const lines = content.split('\n');
|
|
76
|
+
for (let i = 0; i < lines.length; i++) {
|
|
77
|
+
if (regex.test(lines[i])) {
|
|
78
|
+
const rel = relative(searchPath, full);
|
|
79
|
+
results.push(`${rel}:${i + 1}:${lines[i]}`);
|
|
80
|
+
}
|
|
81
|
+
regex.lastIndex = 0;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
// skip binary/unreadable files
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (results.length > 200)
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const info = await stat(searchPath);
|
|
93
|
+
if (info.isFile()) {
|
|
94
|
+
const content = await readFile(searchPath, 'utf-8');
|
|
95
|
+
const lines = content.split('\n');
|
|
96
|
+
for (let i = 0; i < lines.length; i++) {
|
|
97
|
+
if (regex.test(lines[i])) {
|
|
98
|
+
results.push(`${searchPath}:${i + 1}:${lines[i]}`);
|
|
99
|
+
}
|
|
100
|
+
regex.lastIndex = 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
await walk(searchPath);
|
|
105
|
+
}
|
|
106
|
+
return results.slice(0, 200).join('\n');
|
|
107
|
+
}
|
|
108
|
+
function globToRegex(glob) {
|
|
109
|
+
const escaped = glob
|
|
110
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
111
|
+
.replace(/\*/g, '.*')
|
|
112
|
+
.replace(/\?/g, '.');
|
|
113
|
+
return new RegExp(`^${escaped}$`, 'i');
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=grep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../../src/tools/built-in/grep.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACrC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;IACjC,IAAI,EAAE,MAAM;IACZ,WAAW,EACT,uEAAuE;QACvE,2FAA2F;IAE7F,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;QAC5D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kDAAkD,CAAC;QACxF,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,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js';
|
|
5
|
+
import { ToolRegistry } from '../registry.js';
|
|
6
|
+
import { bashTool } from './bash.js';
|
|
7
|
+
import { fileReadTool } from './file-read.js';
|
|
8
|
+
import { fileWriteTool } from './file-write.js';
|
|
9
|
+
import { fileEditTool } from './file-edit.js';
|
|
10
|
+
import { grepTool } from './grep.js';
|
|
11
|
+
import { globTool } from './glob.js';
|
|
12
|
+
import { gitDiffTool } from './git-diff.js';
|
|
13
|
+
import { gitLogTool } from './git-log.js';
|
|
14
|
+
import { gitCommitTool, gitBranchTool } from './git-commit.js';
|
|
15
|
+
import { thinkTool } from './think.js';
|
|
16
|
+
import { webFetchTool } from './web-fetch.js';
|
|
17
|
+
import { askUserTool } from './ask-user.js';
|
|
18
|
+
export { bashTool, fileReadTool, fileWriteTool, fileEditTool, grepTool, globTool, gitDiffTool, gitLogTool, gitCommitTool, gitBranchTool, thinkTool, webFetchTool, askUserTool, };
|
|
19
|
+
export declare const BUILT_IN_TOOLS: ToolDefinition<any>[];
|
|
20
|
+
export declare function registerBuiltInTools(registry: ToolRegistry): void;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tools/built-in/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EACL,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EACnD,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EACzE,SAAS,EAAE,YAAY,EAAE,WAAW,GACrC,CAAA;AAGD,eAAO,MAAM,cAAc,EAAE,cAAc,CAAC,GAAG,CAAC,EAI/C,CAAA;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAMjE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in tool collection — register all tools at once.
|
|
3
|
+
*/
|
|
4
|
+
import { bashTool } from './bash.js';
|
|
5
|
+
import { fileReadTool } from './file-read.js';
|
|
6
|
+
import { fileWriteTool } from './file-write.js';
|
|
7
|
+
import { fileEditTool } from './file-edit.js';
|
|
8
|
+
import { grepTool } from './grep.js';
|
|
9
|
+
import { globTool } from './glob.js';
|
|
10
|
+
import { gitDiffTool } from './git-diff.js';
|
|
11
|
+
import { gitLogTool } from './git-log.js';
|
|
12
|
+
import { gitCommitTool, gitBranchTool } from './git-commit.js';
|
|
13
|
+
import { thinkTool } from './think.js';
|
|
14
|
+
import { webFetchTool } from './web-fetch.js';
|
|
15
|
+
import { askUserTool } from './ask-user.js';
|
|
16
|
+
export { bashTool, fileReadTool, fileWriteTool, fileEditTool, grepTool, globTool, gitDiffTool, gitLogTool, gitCommitTool, gitBranchTool, thinkTool, webFetchTool, askUserTool, };
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
export const BUILT_IN_TOOLS = [
|
|
19
|
+
bashTool, fileReadTool, fileWriteTool, fileEditTool,
|
|
20
|
+
grepTool, globTool, gitDiffTool, gitLogTool, gitCommitTool, gitBranchTool,
|
|
21
|
+
thinkTool, webFetchTool, askUserTool,
|
|
22
|
+
];
|
|
23
|
+
export function registerBuiltInTools(registry) {
|
|
24
|
+
for (const tool of BUILT_IN_TOOLS) {
|
|
25
|
+
if (!registry.has(tool.name)) {
|
|
26
|
+
registry.register(tool);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tools/built-in/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,OAAO,EACL,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EACnD,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EACzE,SAAS,EAAE,YAAY,EAAE,WAAW,GACrC,CAAA;AAED,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAA0B;IACnD,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY;IACnD,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa;IACzE,SAAS,EAAE,YAAY,EAAE,WAAW;CACrC,CAAA;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAsB;IACzD,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;QAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"think.d.ts","sourceRoot":"","sources":["../../../../src/tools/built-in/think.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,eAAO,MAAM,SAAS;;EAcpB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in think tool — extended thinking scratchpad with no side effects.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { defineTool } from '../registry.js';
|
|
6
|
+
export const thinkTool = defineTool({
|
|
7
|
+
name: 'think',
|
|
8
|
+
description: 'Use this tool to think through complex problems step by step. ' +
|
|
9
|
+
'Has no side effects — purely a reasoning scratchpad. ' +
|
|
10
|
+
'Use before making important decisions or complex code changes.',
|
|
11
|
+
inputSchema: z.object({
|
|
12
|
+
thought: z.string().describe('Your step-by-step reasoning.'),
|
|
13
|
+
}),
|
|
14
|
+
execute: async (input) => {
|
|
15
|
+
return { data: `Thought recorded: ${input.thought.slice(0, 100)}...` };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=think.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"think.js","sourceRoot":"","sources":["../../../../src/tools/built-in/think.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC;IAClC,IAAI,EAAE,OAAO;IACb,WAAW,EACT,gEAAgE;QAChE,uDAAuD;QACvD,gEAAgE;IAElE,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,8BAA8B,CAAC;KAC7D,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QACvB,OAAO,EAAE,IAAI,EAAE,qBAAqB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,CAAA;IACxE,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web_fetch — HTTP fetch tool for retrieving web content.
|
|
3
|
+
*/
|
|
4
|
+
export declare const webFetchTool: import("../registry.js").ToolDefinition<{
|
|
5
|
+
url: string;
|
|
6
|
+
method?: "GET" | "POST" | undefined;
|
|
7
|
+
headers?: Record<string, string> | undefined;
|
|
8
|
+
body?: string | undefined;
|
|
9
|
+
maxBytes?: number | undefined;
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=web-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-fetch.d.ts","sourceRoot":"","sources":["../../../../src/tools/built-in/web-fetch.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,eAAO,MAAM,YAAY;;;;;;EAuEvB,CAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* web_fetch — HTTP fetch tool for retrieving web content.
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { defineTool } from '../registry.js';
|
|
6
|
+
export const webFetchTool = defineTool({
|
|
7
|
+
name: 'web_fetch',
|
|
8
|
+
description: 'Fetch content from a URL. Returns the response body as text. Supports GET and POST.',
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
url: z.string().describe('The URL to fetch'),
|
|
11
|
+
method: z.enum(['GET', 'POST']).default('GET').describe('HTTP method'),
|
|
12
|
+
headers: z.record(z.string()).optional().describe('Additional HTTP headers'),
|
|
13
|
+
body: z.string().optional().describe('Request body (for POST)'),
|
|
14
|
+
maxBytes: z.number().default(100000).describe('Max response size in bytes (default: 100KB)'),
|
|
15
|
+
}),
|
|
16
|
+
execute: async (input) => {
|
|
17
|
+
// Validate URL
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = new URL(input.url);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return { data: `Invalid URL: ${input.url}`, isError: true };
|
|
24
|
+
}
|
|
25
|
+
// Block private/internal addresses
|
|
26
|
+
const hostname = parsed.hostname.toLowerCase();
|
|
27
|
+
if (hostname === 'localhost' ||
|
|
28
|
+
hostname === '127.0.0.1' ||
|
|
29
|
+
hostname === '::1' ||
|
|
30
|
+
hostname === '0.0.0.0' ||
|
|
31
|
+
hostname.endsWith('.local') ||
|
|
32
|
+
hostname.startsWith('192.168.') ||
|
|
33
|
+
hostname.startsWith('10.') ||
|
|
34
|
+
hostname.startsWith('172.16.') ||
|
|
35
|
+
/^169\.254\./.test(hostname)) {
|
|
36
|
+
return { data: `Blocked: cannot fetch private/internal addresses (${hostname})`, isError: true };
|
|
37
|
+
}
|
|
38
|
+
// Only allow http/https
|
|
39
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
40
|
+
return { data: `Blocked: only http/https URLs are allowed`, isError: true };
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const controller = new AbortController();
|
|
44
|
+
const timeout = setTimeout(() => controller.abort(), 30000);
|
|
45
|
+
const response = await fetch(input.url, {
|
|
46
|
+
method: input.method,
|
|
47
|
+
headers: input.headers,
|
|
48
|
+
body: input.method === 'POST' ? input.body : undefined,
|
|
49
|
+
signal: controller.signal,
|
|
50
|
+
redirect: 'follow',
|
|
51
|
+
});
|
|
52
|
+
clearTimeout(timeout);
|
|
53
|
+
const contentType = response.headers.get('content-type') ?? '';
|
|
54
|
+
const buffer = await response.arrayBuffer();
|
|
55
|
+
const maxBytes = input.maxBytes ?? 100000;
|
|
56
|
+
if (buffer.byteLength > maxBytes) {
|
|
57
|
+
const text = new TextDecoder().decode(buffer.slice(0, maxBytes));
|
|
58
|
+
return { data: `[${response.status}] (truncated to ${maxBytes} bytes)\n${text}` };
|
|
59
|
+
}
|
|
60
|
+
const text = new TextDecoder().decode(buffer);
|
|
61
|
+
const statusLine = `[${response.status} ${response.statusText}] ${contentType}`;
|
|
62
|
+
return { data: `${statusLine}\n${text}` };
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
66
|
+
return { data: `Fetch failed: ${msg}`, isError: true };
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=web-fetch.js.map
|