@compilr-dev/agents 0.3.16 → 0.3.18
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 +108 -0
- package/README.md +2 -2
- package/dist/agent.d.ts +28 -0
- package/dist/agent.js +43 -2
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.js +4 -0
- package/dist/context/observation-masker.d.ts +80 -0
- package/dist/context/observation-masker.js +192 -0
- package/dist/context/result-compactor.d.ts +15 -0
- package/dist/context/result-compactor.js +165 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -1
- package/dist/tools/builtin/ask-user-simple.js +2 -4
- package/dist/tools/builtin/ask-user.js +2 -4
- package/dist/tools/builtin/backlog.js +4 -6
- package/dist/tools/builtin/bash-output.js +4 -21
- package/dist/tools/builtin/bash.js +7 -37
- package/dist/tools/builtin/edit.js +2 -29
- package/dist/tools/builtin/glob.js +9 -52
- package/dist/tools/builtin/grep.js +12 -66
- package/dist/tools/builtin/kill-shell.js +4 -14
- package/dist/tools/builtin/read-file.js +6 -27
- package/dist/tools/builtin/recall-result.js +2 -3
- package/dist/tools/builtin/suggest.js +4 -24
- package/dist/tools/builtin/todo.js +13 -15
- package/dist/tools/builtin/web-fetch.js +11 -10
- package/dist/tools/builtin/write-file.js +10 -33
- package/package.json +2 -2
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compact Tool Result Formatting — Phase 2 of Advanced Token Optimization
|
|
3
|
+
*
|
|
4
|
+
* Replaces JSON.stringify for tool results in the LLM messages array.
|
|
5
|
+
* Per-tool formatters strip JSON overhead (escaped newlines, metadata fields)
|
|
6
|
+
* and produce a text format the LLM can parse just as well.
|
|
7
|
+
*
|
|
8
|
+
* Only affects what the LLM reads in its message history.
|
|
9
|
+
* CLI formatters, events, and hooks still receive the raw ToolExecutionResult.
|
|
10
|
+
*/
|
|
11
|
+
// ============================================================
|
|
12
|
+
// Helpers
|
|
13
|
+
// ============================================================
|
|
14
|
+
/** Safely extract a string field from an unknown record. */
|
|
15
|
+
function str(value, fallback = '') {
|
|
16
|
+
return typeof value === 'string' ? value : fallback;
|
|
17
|
+
}
|
|
18
|
+
/** Safely extract a number field from an unknown record. */
|
|
19
|
+
function num(value, fallback = 0) {
|
|
20
|
+
return typeof value === 'number' ? value : fallback;
|
|
21
|
+
}
|
|
22
|
+
// ============================================================
|
|
23
|
+
// Public API
|
|
24
|
+
// ============================================================
|
|
25
|
+
/**
|
|
26
|
+
* Format a tool result as compact text for LLM context.
|
|
27
|
+
* Falls back to JSON.stringify for unknown tools or non-object results.
|
|
28
|
+
*/
|
|
29
|
+
export function compactToolResult(toolName, result, input) {
|
|
30
|
+
// String results — already compact
|
|
31
|
+
if (typeof result === 'string')
|
|
32
|
+
return result;
|
|
33
|
+
if (result === null || result === undefined)
|
|
34
|
+
return '';
|
|
35
|
+
// Per-tool formatters
|
|
36
|
+
const formatter = TOOL_FORMATTERS.get(toolName);
|
|
37
|
+
if (formatter)
|
|
38
|
+
return formatter(result, input);
|
|
39
|
+
// Fallback: JSON.stringify (current behavior)
|
|
40
|
+
return JSON.stringify(result);
|
|
41
|
+
}
|
|
42
|
+
const TOOL_FORMATTERS = new Map([
|
|
43
|
+
['read_file', formatReadFile],
|
|
44
|
+
['bash', formatBash],
|
|
45
|
+
['bash_output', formatBash],
|
|
46
|
+
['grep', formatGrep],
|
|
47
|
+
['glob', formatGlob],
|
|
48
|
+
['edit', formatEdit],
|
|
49
|
+
['write_file', formatWriteFile],
|
|
50
|
+
]);
|
|
51
|
+
/**
|
|
52
|
+
* read_file → [path 200L] + content
|
|
53
|
+
*/
|
|
54
|
+
function formatReadFile(r) {
|
|
55
|
+
const path = str(r.path);
|
|
56
|
+
const content = str(r.content);
|
|
57
|
+
const totalLines = typeof r.totalLines === 'number' ? r.totalLines : undefined;
|
|
58
|
+
const linesReturned = typeof r.linesReturned === 'number' ? r.linesReturned : undefined;
|
|
59
|
+
const truncated = r.truncated === true;
|
|
60
|
+
// Header: [path NL] or [path M/NL] if truncated
|
|
61
|
+
let header;
|
|
62
|
+
if (truncated && linesReturned !== undefined && totalLines !== undefined) {
|
|
63
|
+
header = `[${path} ${String(linesReturned)}/${String(totalLines)}L]`;
|
|
64
|
+
}
|
|
65
|
+
else if (totalLines !== undefined) {
|
|
66
|
+
header = `[${path} ${String(totalLines)}L]`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
header = `[${path}]`;
|
|
70
|
+
}
|
|
71
|
+
return `${header}\n${content}`;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* bash → $ command\nstdout\n[stderr]\nstderr
|
|
75
|
+
* Non-zero exit: [exit:N] $ command\n...
|
|
76
|
+
* Background: shell_id message
|
|
77
|
+
*/
|
|
78
|
+
function formatBash(r, input) {
|
|
79
|
+
// Background execution has different shape
|
|
80
|
+
if (r.shell_id) {
|
|
81
|
+
return `[bg:${str(r.shell_id)}] ${str(r.message)}`;
|
|
82
|
+
}
|
|
83
|
+
const stdout = str(r.stdout);
|
|
84
|
+
const stderr = str(r.stderr);
|
|
85
|
+
const exitCode = num(r.exitCode);
|
|
86
|
+
const command = input ? str(input.command) : '';
|
|
87
|
+
const parts = [];
|
|
88
|
+
// Command line
|
|
89
|
+
if (command) {
|
|
90
|
+
const prefix = exitCode !== 0 ? `[exit:${String(exitCode)}] ` : '';
|
|
91
|
+
parts.push(`${prefix}$ ${command}`);
|
|
92
|
+
}
|
|
93
|
+
else if (exitCode !== 0) {
|
|
94
|
+
parts.push(`[exit:${String(exitCode)}]`);
|
|
95
|
+
}
|
|
96
|
+
// stdout
|
|
97
|
+
if (stdout) {
|
|
98
|
+
parts.push(stdout);
|
|
99
|
+
}
|
|
100
|
+
// stderr (only if non-empty)
|
|
101
|
+
if (stderr) {
|
|
102
|
+
parts.push('[stderr]');
|
|
103
|
+
parts.push(stderr);
|
|
104
|
+
}
|
|
105
|
+
return parts.join('\n');
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* grep → N matches in M files:\n...matches
|
|
109
|
+
* Files-only mode → N files matching:\n...files
|
|
110
|
+
*/
|
|
111
|
+
function formatGrep(r) {
|
|
112
|
+
const count = num(r.count);
|
|
113
|
+
// Files-only mode (has `files` array)
|
|
114
|
+
if (Array.isArray(r.files)) {
|
|
115
|
+
const files = r.files;
|
|
116
|
+
if (files.length === 0)
|
|
117
|
+
return '0 files matching';
|
|
118
|
+
return `${String(count)} files matching:\n${files.join('\n')}`;
|
|
119
|
+
}
|
|
120
|
+
// Matches mode
|
|
121
|
+
const matches = Array.isArray(r.matches) ? r.matches : undefined;
|
|
122
|
+
const filesSearched = typeof r.filesSearched === 'number' ? r.filesSearched : undefined;
|
|
123
|
+
if (!matches || matches.length === 0) {
|
|
124
|
+
return filesSearched ? `0 matches in ${String(filesSearched)} files` : '0 matches';
|
|
125
|
+
}
|
|
126
|
+
const summary = filesSearched
|
|
127
|
+
? `${String(count)} matches in ${String(filesSearched)} files:`
|
|
128
|
+
: `${String(count)} matches:`;
|
|
129
|
+
return `${summary}\n${matches.join('\n')}`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* glob → N files:\n...files
|
|
133
|
+
*/
|
|
134
|
+
function formatGlob(r) {
|
|
135
|
+
const files = Array.isArray(r.files) ? r.files : undefined;
|
|
136
|
+
const count = num(r.count);
|
|
137
|
+
if (!files || files.length === 0)
|
|
138
|
+
return '0 files';
|
|
139
|
+
return `${String(count)} files:\n${files.join('\n')}`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* edit → OK path (N replacements)
|
|
143
|
+
*/
|
|
144
|
+
function formatEdit(r) {
|
|
145
|
+
const filePath = str(r.filePath);
|
|
146
|
+
const replacements = num(r.replacements);
|
|
147
|
+
const created = r.created === true;
|
|
148
|
+
if (created) {
|
|
149
|
+
return `OK created ${filePath}`;
|
|
150
|
+
}
|
|
151
|
+
return `OK ${filePath} (${String(replacements)} replacement${replacements !== 1 ? 's' : ''})`;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* write_file → OK wrote path (NB)
|
|
155
|
+
*/
|
|
156
|
+
function formatWriteFile(r) {
|
|
157
|
+
const path = str(r.path);
|
|
158
|
+
const bytesWritten = typeof r.bytesWritten === 'number' ? r.bytesWritten : undefined;
|
|
159
|
+
const mode = str(r.mode);
|
|
160
|
+
const action = mode === 'appended' ? 'appended' : 'wrote';
|
|
161
|
+
if (bytesWritten !== undefined) {
|
|
162
|
+
return `OK ${action} ${path} (${String(bytesWritten)}B)`;
|
|
163
|
+
}
|
|
164
|
+
return `OK ${action} ${path}`;
|
|
165
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -39,8 +39,8 @@ export type { ToolPairingValidation } from './messages/index.js';
|
|
|
39
39
|
export { generateId, sleep, retry, truncate, withRetryGenerator, calculateBackoffDelay, DEFAULT_RETRY_CONFIG, countTokens, countMessageTokens, } from './utils/index.js';
|
|
40
40
|
export type { RetryConfig as LLMRetryConfig, WithRetryOptions } from './utils/index.js';
|
|
41
41
|
export { AgentError, ProviderError, ToolError, ToolTimeoutError, ToolLoopError, ValidationError, MaxIterationsError, AbortError, ContextOverflowError, isAgentError, isProviderError, isToolError, isToolTimeoutError, isToolLoopError, isContextOverflowError, wrapError, } from './errors.js';
|
|
42
|
-
export { ContextManager, DEFAULT_CONTEXT_CONFIG, FileAccessTracker, createFileTrackingHook, TRACKED_TOOLS, DelegatedResultStore, ToolResultDelegator, DELEGATION_SYSTEM_PROMPT, DEFAULT_DELEGATION_CONFIG, } from './context/index.js';
|
|
43
|
-
export type { ContextManagerOptions, ContextCategory, BudgetAllocation, CategoryBudgetInfo, PreflightResult, VerbosityLevel, VerbosityConfig, ContextConfig, FilteringConfig, CompactionConfig, SummarizationConfig, CompactionResult, SummarizationResult, FilteringResult, ContextEvent, ContextEventHandler, ContextStats, FileAccessType, FileAccess, FileAccessTrackerOptions, FormatHintsOptions, FileAccessStats, RestorationHintMessage, DelegatedResultStoreStats, ToolResultDelegatorOptions, DelegationConfig, StoredResult, DelegationEvent, } from './context/index.js';
|
|
42
|
+
export { ContextManager, DEFAULT_CONTEXT_CONFIG, FileAccessTracker, createFileTrackingHook, TRACKED_TOOLS, DelegatedResultStore, ToolResultDelegator, DELEGATION_SYSTEM_PROMPT, DEFAULT_DELEGATION_CONFIG, compactToolResult, ObservationMasker, DEFAULT_MASK_CONFIG, extractInputSummary, buildMaskText, isMasked, } from './context/index.js';
|
|
43
|
+
export type { ContextManagerOptions, ContextCategory, BudgetAllocation, CategoryBudgetInfo, PreflightResult, VerbosityLevel, VerbosityConfig, ContextConfig, FilteringConfig, CompactionConfig, SummarizationConfig, CompactionResult, SummarizationResult, FilteringResult, ContextEvent, ContextEventHandler, ContextStats, FileAccessType, FileAccess, FileAccessTrackerOptions, FormatHintsOptions, FileAccessStats, RestorationHintMessage, DelegatedResultStoreStats, ToolResultDelegatorOptions, DelegationConfig, StoredResult, DelegationEvent, ObservationMaskConfig, MaskResult, ObservationMaskStats, } from './context/index.js';
|
|
44
44
|
export { SkillRegistry, defineSkill, createSkillRegistry, builtinSkills, getDefaultSkillRegistry, resetDefaultSkillRegistry, } from './skills/index.js';
|
|
45
45
|
export type { Skill, SkillInvocationResult, SkillInvokeOptions } from './skills/index.js';
|
|
46
46
|
export { JsonSerializer, CompactJsonSerializer, defaultSerializer, MemoryCheckpointer, FileCheckpointer, StateError, StateErrorCode, CURRENT_STATE_VERSION, } from './state/index.js';
|
package/dist/index.js
CHANGED
|
@@ -47,7 +47,11 @@ export { AgentError, ProviderError, ToolError, ToolTimeoutError, ToolLoopError,
|
|
|
47
47
|
// Context management
|
|
48
48
|
export { ContextManager, DEFAULT_CONTEXT_CONFIG, FileAccessTracker, createFileTrackingHook, TRACKED_TOOLS,
|
|
49
49
|
// Tool result delegation
|
|
50
|
-
DelegatedResultStore, ToolResultDelegator, DELEGATION_SYSTEM_PROMPT, DEFAULT_DELEGATION_CONFIG,
|
|
50
|
+
DelegatedResultStore, ToolResultDelegator, DELEGATION_SYSTEM_PROMPT, DEFAULT_DELEGATION_CONFIG,
|
|
51
|
+
// Compact tool result formatting (Phase 2 Token Optimization)
|
|
52
|
+
compactToolResult,
|
|
53
|
+
// Observation masking (Phase 1 Token Optimization)
|
|
54
|
+
ObservationMasker, DEFAULT_MASK_CONFIG, extractInputSummary, buildMaskText, isMasked, } from './context/index.js';
|
|
51
55
|
// Skills system
|
|
52
56
|
export { SkillRegistry, defineSkill, createSkillRegistry, builtinSkills, getDefaultSkillRegistry, resetDefaultSkillRegistry, } from './skills/index.js';
|
|
53
57
|
// State management
|
|
@@ -75,10 +75,8 @@ async function askSimpleWithReadline(question, options, defaultValue) {
|
|
|
75
75
|
*/
|
|
76
76
|
export const askUserSimpleTool = defineTool({
|
|
77
77
|
name: 'ask_user_simple',
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
'Provide 2-4 clear, concise options. ' +
|
|
81
|
-
'The user can select by number or by typing the option text.',
|
|
78
|
+
// Original: 'Ask a single simple question with string options. Use this instead of ask_user when you only need one question. Provide 2-4 clear, concise options. The user can select by number or by typing the option text.'
|
|
79
|
+
description: 'Ask a single question with 2-4 string options.',
|
|
82
80
|
inputSchema: {
|
|
83
81
|
type: 'object',
|
|
84
82
|
properties: {
|
|
@@ -90,10 +90,8 @@ async function askWithReadline(questions) {
|
|
|
90
90
|
*/
|
|
91
91
|
export const askUserTool = defineTool({
|
|
92
92
|
name: 'ask_user',
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
'Each question should have 2-4 clear options. ' +
|
|
96
|
-
'Prefer ask_user_simple for single simple questions.',
|
|
93
|
+
// Original: 'Ask the user one or more questions with predefined options. Use this to gather preferences, make decisions, or get user input during workflows. Each question should have 2-4 clear options. Prefer ask_user_simple for single simple questions.'
|
|
94
|
+
description: 'Ask 1-4 questions with predefined options. Prefer ask_user_simple for single questions.',
|
|
97
95
|
inputSchema: {
|
|
98
96
|
type: 'object',
|
|
99
97
|
properties: {
|
|
@@ -86,9 +86,8 @@ function generateItemId(type, items) {
|
|
|
86
86
|
*/
|
|
87
87
|
export const backlogReadTool = defineTool({
|
|
88
88
|
name: 'backlog_read',
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
'Returns items sorted by priority (critical first) then by creation date.',
|
|
89
|
+
// Original: 'Read backlog items from the project. Use filters to narrow results. Use id parameter to get a specific item. Returns items sorted by priority (critical first) then by creation date.'
|
|
90
|
+
description: 'Read backlog items, sorted by priority then creation date.',
|
|
92
91
|
inputSchema: {
|
|
93
92
|
type: 'object',
|
|
94
93
|
properties: {
|
|
@@ -189,9 +188,8 @@ export const backlogReadTool = defineTool({
|
|
|
189
188
|
*/
|
|
190
189
|
export const backlogWriteTool = defineTool({
|
|
191
190
|
name: 'backlog_write',
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
'IDs are auto-generated for new items based on type (e.g., FEAT-001, BUG-002).',
|
|
191
|
+
// Original: 'Create, update, or delete backlog items. Actions: add (new item), update (modify existing), delete (remove), replace (full list). IDs are auto-generated for new items based on type (e.g., FEAT-001, BUG-002).'
|
|
192
|
+
description: 'Create, update, or delete backlog items.',
|
|
195
193
|
inputSchema: {
|
|
196
194
|
type: 'object',
|
|
197
195
|
properties: {
|
|
@@ -8,9 +8,8 @@ import { getDefaultShellManager } from './shell-manager.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export const bashOutputTool = defineTool({
|
|
10
10
|
name: 'bash_output',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
'Use this to monitor long-running commands started with run_in_background.',
|
|
11
|
+
// Original: 'Retrieve output from a running or completed background bash shell. Returns only new output since the last check. Use this to monitor long-running commands started with run_in_background.'
|
|
12
|
+
description: 'Retrieve output from a background bash shell.',
|
|
14
13
|
inputSchema: {
|
|
15
14
|
type: 'object',
|
|
16
15
|
properties: {
|
|
@@ -67,24 +66,8 @@ export function createBashOutputTool(options) {
|
|
|
67
66
|
const manager = options?.shellManager ?? getDefaultShellManager();
|
|
68
67
|
return defineTool({
|
|
69
68
|
name: 'bash_output',
|
|
70
|
-
description:
|
|
71
|
-
|
|
72
|
-
'Use this to monitor long-running commands started with run_in_background.',
|
|
73
|
-
inputSchema: {
|
|
74
|
-
type: 'object',
|
|
75
|
-
properties: {
|
|
76
|
-
bash_id: {
|
|
77
|
-
type: 'string',
|
|
78
|
-
description: 'The ID of the background shell to retrieve output from',
|
|
79
|
-
},
|
|
80
|
-
filter: {
|
|
81
|
-
type: 'string',
|
|
82
|
-
description: 'Optional regular expression to filter output lines. ' +
|
|
83
|
-
'Only lines matching this regex will be included.',
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
required: ['bash_id'],
|
|
87
|
-
},
|
|
69
|
+
description: bashOutputTool.definition.description,
|
|
70
|
+
inputSchema: bashOutputTool.definition.inputSchema,
|
|
88
71
|
execute: (input) => Promise.resolve(executeBashOutput(input, manager)),
|
|
89
72
|
});
|
|
90
73
|
}
|
|
@@ -78,9 +78,9 @@ function truncateOutput(output, maxSize) {
|
|
|
78
78
|
*/
|
|
79
79
|
export const bashTool = defineTool({
|
|
80
80
|
name: 'bash',
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
'
|
|
81
|
+
// Original: 'Execute a shell command and return its output. Commands run in bash shell. Use for system operations, git commands, npm, etc. Set run_in_background=true for long-running commands, then use bash_output to monitor.'
|
|
82
|
+
description: 'Execute a shell command. ' +
|
|
83
|
+
'For long-running commands, set run_in_background and poll with bash_output.',
|
|
84
84
|
inputSchema: {
|
|
85
85
|
type: 'object',
|
|
86
86
|
properties: {
|
|
@@ -94,7 +94,8 @@ export const bashTool = defineTool({
|
|
|
94
94
|
},
|
|
95
95
|
timeout: {
|
|
96
96
|
type: 'number',
|
|
97
|
-
description: 'Timeout in milliseconds
|
|
97
|
+
description: 'Timeout in milliseconds. Ignored for background commands.',
|
|
98
|
+
default: 60000,
|
|
98
99
|
},
|
|
99
100
|
env: {
|
|
100
101
|
type: 'object',
|
|
@@ -479,39 +480,8 @@ function isExecError(error) {
|
|
|
479
480
|
export function createBashTool(options) {
|
|
480
481
|
return defineTool({
|
|
481
482
|
name: 'bash',
|
|
482
|
-
description:
|
|
483
|
-
|
|
484
|
-
'Set run_in_background=true for long-running commands, then use bash_output to monitor.',
|
|
485
|
-
inputSchema: {
|
|
486
|
-
type: 'object',
|
|
487
|
-
properties: {
|
|
488
|
-
command: {
|
|
489
|
-
type: 'string',
|
|
490
|
-
description: 'The shell command to execute',
|
|
491
|
-
},
|
|
492
|
-
cwd: {
|
|
493
|
-
type: 'string',
|
|
494
|
-
description: 'Working directory for the command',
|
|
495
|
-
},
|
|
496
|
-
timeout: {
|
|
497
|
-
type: 'number',
|
|
498
|
-
description: 'Timeout in milliseconds (default: 60000). Ignored for background commands.',
|
|
499
|
-
},
|
|
500
|
-
env: {
|
|
501
|
-
type: 'object',
|
|
502
|
-
description: 'Additional environment variables',
|
|
503
|
-
},
|
|
504
|
-
run_in_background: {
|
|
505
|
-
type: 'boolean',
|
|
506
|
-
description: 'Run command in background and return shell ID. Use bash_output to get results.',
|
|
507
|
-
},
|
|
508
|
-
description: {
|
|
509
|
-
type: 'string',
|
|
510
|
-
description: 'Brief description of what this command does',
|
|
511
|
-
},
|
|
512
|
-
},
|
|
513
|
-
required: ['command'],
|
|
514
|
-
},
|
|
483
|
+
description: bashTool.definition.description,
|
|
484
|
+
inputSchema: bashTool.definition.inputSchema,
|
|
515
485
|
execute: async (input, context) => {
|
|
516
486
|
const { cwd: defaultCwd, timeout: defaultTimeout = DEFAULT_TIMEOUT, maxOutputSize = DEFAULT_MAX_OUTPUT_SIZE, blockedCommands = [], restrictToAllowed = false, allowedCommands = [], shell = '/bin/bash', shellManager, fifoMode = 'warn', } = options ?? {};
|
|
517
487
|
const command = input.command.trim();
|
|
@@ -157,35 +157,8 @@ function truncate(str, maxLength) {
|
|
|
157
157
|
export function createEditTool(options) {
|
|
158
158
|
return defineTool({
|
|
159
159
|
name: 'edit',
|
|
160
|
-
description:
|
|
161
|
-
|
|
162
|
-
'Use replaceAll to replace all occurrences.',
|
|
163
|
-
inputSchema: {
|
|
164
|
-
type: 'object',
|
|
165
|
-
properties: {
|
|
166
|
-
filePath: {
|
|
167
|
-
type: 'string',
|
|
168
|
-
description: 'Path to the file to edit',
|
|
169
|
-
},
|
|
170
|
-
oldString: {
|
|
171
|
-
type: 'string',
|
|
172
|
-
description: 'The text to search for and replace',
|
|
173
|
-
},
|
|
174
|
-
newString: {
|
|
175
|
-
type: 'string',
|
|
176
|
-
description: 'The replacement text',
|
|
177
|
-
},
|
|
178
|
-
replaceAll: {
|
|
179
|
-
type: 'boolean',
|
|
180
|
-
description: 'Replace all occurrences instead of requiring uniqueness',
|
|
181
|
-
},
|
|
182
|
-
createIfMissing: {
|
|
183
|
-
type: 'boolean',
|
|
184
|
-
description: 'Create the file with newString content if it does not exist',
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
required: ['filePath', 'oldString', 'newString'],
|
|
188
|
-
},
|
|
160
|
+
description: editTool.definition.description,
|
|
161
|
+
inputSchema: editTool.definition.inputSchema,
|
|
189
162
|
execute: async (input) => {
|
|
190
163
|
let targetPath = input.filePath;
|
|
191
164
|
// Resolve relative paths
|
|
@@ -34,9 +34,8 @@ const DEFAULT_EXCLUDE_DIRS = [
|
|
|
34
34
|
export const globTool = defineTool({
|
|
35
35
|
name: 'glob',
|
|
36
36
|
readonly: true,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'Returns a list of matching file paths.',
|
|
37
|
+
// Original: 'Find files matching glob patterns. Supports common patterns like **/*.ts for recursive matching. Returns a list of matching file paths.'
|
|
38
|
+
description: 'Find files matching glob patterns.',
|
|
40
39
|
inputSchema: {
|
|
41
40
|
type: 'object',
|
|
42
41
|
properties: {
|
|
@@ -50,7 +49,7 @@ export const globTool = defineTool({
|
|
|
50
49
|
},
|
|
51
50
|
includeHidden: {
|
|
52
51
|
type: 'boolean',
|
|
53
|
-
description: 'Include hidden files/directories
|
|
52
|
+
description: 'Include hidden files/directories',
|
|
54
53
|
},
|
|
55
54
|
onlyDirectories: {
|
|
56
55
|
type: 'boolean',
|
|
@@ -58,7 +57,8 @@ export const globTool = defineTool({
|
|
|
58
57
|
},
|
|
59
58
|
onlyFiles: {
|
|
60
59
|
type: 'boolean',
|
|
61
|
-
description: 'Only match files
|
|
60
|
+
description: 'Only match files',
|
|
61
|
+
default: true,
|
|
62
62
|
},
|
|
63
63
|
maxDepth: {
|
|
64
64
|
type: 'number',
|
|
@@ -66,7 +66,8 @@ export const globTool = defineTool({
|
|
|
66
66
|
},
|
|
67
67
|
maxResults: {
|
|
68
68
|
type: 'number',
|
|
69
|
-
description: 'Maximum number of results
|
|
69
|
+
description: 'Maximum number of results',
|
|
70
|
+
default: 1000,
|
|
70
71
|
},
|
|
71
72
|
absolute: {
|
|
72
73
|
type: 'boolean',
|
|
@@ -224,52 +225,8 @@ export function createGlobTool(options) {
|
|
|
224
225
|
return defineTool({
|
|
225
226
|
name: 'glob',
|
|
226
227
|
readonly: true,
|
|
227
|
-
description:
|
|
228
|
-
|
|
229
|
-
'Returns a list of matching file paths.',
|
|
230
|
-
inputSchema: {
|
|
231
|
-
type: 'object',
|
|
232
|
-
properties: {
|
|
233
|
-
pattern: {
|
|
234
|
-
type: 'string',
|
|
235
|
-
description: 'Glob pattern (e.g., "**/*.ts", "src/**/*.js", "*.md")',
|
|
236
|
-
},
|
|
237
|
-
path: {
|
|
238
|
-
type: 'string',
|
|
239
|
-
description: 'Base directory to search in (default: current directory)',
|
|
240
|
-
},
|
|
241
|
-
includeHidden: {
|
|
242
|
-
type: 'boolean',
|
|
243
|
-
description: 'Include hidden files/directories (default: false)',
|
|
244
|
-
},
|
|
245
|
-
onlyDirectories: {
|
|
246
|
-
type: 'boolean',
|
|
247
|
-
description: 'Only match directories',
|
|
248
|
-
},
|
|
249
|
-
onlyFiles: {
|
|
250
|
-
type: 'boolean',
|
|
251
|
-
description: 'Only match files (default: true)',
|
|
252
|
-
},
|
|
253
|
-
maxDepth: {
|
|
254
|
-
type: 'number',
|
|
255
|
-
description: 'Maximum directory depth to traverse',
|
|
256
|
-
},
|
|
257
|
-
maxResults: {
|
|
258
|
-
type: 'number',
|
|
259
|
-
description: 'Maximum number of results (default: 1000)',
|
|
260
|
-
},
|
|
261
|
-
absolute: {
|
|
262
|
-
type: 'boolean',
|
|
263
|
-
description: 'Return absolute paths instead of relative',
|
|
264
|
-
},
|
|
265
|
-
excludeDirs: {
|
|
266
|
-
type: 'array',
|
|
267
|
-
items: { type: 'string' },
|
|
268
|
-
description: 'Directory names to exclude (default: node_modules, .git, dist, build, etc.)',
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
required: ['pattern'],
|
|
272
|
-
},
|
|
228
|
+
description: globTool.definition.description,
|
|
229
|
+
inputSchema: globTool.definition.inputSchema,
|
|
273
230
|
execute: async (input) => {
|
|
274
231
|
let searchPath = input.path ?? '.';
|
|
275
232
|
// Resolve relative paths
|
|
@@ -35,9 +35,8 @@ const DEFAULT_EXCLUDE_DIRS = [
|
|
|
35
35
|
export const grepTool = defineTool({
|
|
36
36
|
name: 'grep',
|
|
37
37
|
readonly: true,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
'Returns matching lines with optional context.',
|
|
38
|
+
// Original: 'Search for patterns in files using regular expressions. Can search a single file or recursively through directories. Returns matching lines with optional context.'
|
|
39
|
+
description: 'Search for regex patterns in files or directories.',
|
|
41
40
|
inputSchema: {
|
|
42
41
|
type: 'object',
|
|
43
42
|
properties: {
|
|
@@ -51,11 +50,13 @@ export const grepTool = defineTool({
|
|
|
51
50
|
},
|
|
52
51
|
ignoreCase: {
|
|
53
52
|
type: 'boolean',
|
|
54
|
-
description: 'Case insensitive search
|
|
53
|
+
description: 'Case insensitive search',
|
|
54
|
+
default: false,
|
|
55
55
|
},
|
|
56
56
|
lineNumbers: {
|
|
57
57
|
type: 'boolean',
|
|
58
|
-
description: 'Include line numbers in output
|
|
58
|
+
description: 'Include line numbers in output',
|
|
59
|
+
default: true,
|
|
59
60
|
},
|
|
60
61
|
before: {
|
|
61
62
|
type: 'number',
|
|
@@ -80,11 +81,13 @@ export const grepTool = defineTool({
|
|
|
80
81
|
},
|
|
81
82
|
maxMatches: {
|
|
82
83
|
type: 'number',
|
|
83
|
-
description: 'Maximum number of matches to return
|
|
84
|
+
description: 'Maximum number of matches to return',
|
|
85
|
+
default: 100,
|
|
84
86
|
},
|
|
85
87
|
recursive: {
|
|
86
88
|
type: 'boolean',
|
|
87
|
-
description: 'Search recursively in directories
|
|
89
|
+
description: 'Search recursively in directories',
|
|
90
|
+
default: true,
|
|
88
91
|
},
|
|
89
92
|
},
|
|
90
93
|
required: ['pattern', 'path'],
|
|
@@ -321,65 +324,8 @@ export function createGrepTool(options) {
|
|
|
321
324
|
return defineTool({
|
|
322
325
|
name: 'grep',
|
|
323
326
|
readonly: true,
|
|
324
|
-
description:
|
|
325
|
-
|
|
326
|
-
'Returns matching lines with optional context.',
|
|
327
|
-
inputSchema: {
|
|
328
|
-
type: 'object',
|
|
329
|
-
properties: {
|
|
330
|
-
pattern: {
|
|
331
|
-
type: 'string',
|
|
332
|
-
description: 'Regular expression pattern to search for',
|
|
333
|
-
},
|
|
334
|
-
path: {
|
|
335
|
-
type: 'string',
|
|
336
|
-
description: 'Path to file or directory to search in',
|
|
337
|
-
},
|
|
338
|
-
ignoreCase: {
|
|
339
|
-
type: 'boolean',
|
|
340
|
-
description: 'Case insensitive search (default: false)',
|
|
341
|
-
},
|
|
342
|
-
lineNumbers: {
|
|
343
|
-
type: 'boolean',
|
|
344
|
-
description: 'Include line numbers in output (default: true)',
|
|
345
|
-
},
|
|
346
|
-
before: {
|
|
347
|
-
type: 'number',
|
|
348
|
-
description: 'Number of context lines before match',
|
|
349
|
-
},
|
|
350
|
-
after: {
|
|
351
|
-
type: 'number',
|
|
352
|
-
description: 'Number of context lines after match',
|
|
353
|
-
},
|
|
354
|
-
filesOnly: {
|
|
355
|
-
type: 'boolean',
|
|
356
|
-
description: 'Only return filenames with matches',
|
|
357
|
-
},
|
|
358
|
-
includeHidden: {
|
|
359
|
-
type: 'boolean',
|
|
360
|
-
description: 'Include hidden files/directories',
|
|
361
|
-
},
|
|
362
|
-
extensions: {
|
|
363
|
-
type: 'array',
|
|
364
|
-
items: { type: 'string' },
|
|
365
|
-
description: 'File extensions to include (e.g., [".ts", ".js"])',
|
|
366
|
-
},
|
|
367
|
-
maxMatches: {
|
|
368
|
-
type: 'number',
|
|
369
|
-
description: 'Maximum number of matches to return (default: 100)',
|
|
370
|
-
},
|
|
371
|
-
recursive: {
|
|
372
|
-
type: 'boolean',
|
|
373
|
-
description: 'Search recursively in directories (default: true)',
|
|
374
|
-
},
|
|
375
|
-
excludeDirs: {
|
|
376
|
-
type: 'array',
|
|
377
|
-
items: { type: 'string' },
|
|
378
|
-
description: 'Directory names to exclude (default: node_modules, .git, dist, build, etc.)',
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
required: ['pattern', 'path'],
|
|
382
|
-
},
|
|
327
|
+
description: grepTool.definition.description,
|
|
328
|
+
inputSchema: grepTool.definition.inputSchema,
|
|
383
329
|
execute: async (input) => {
|
|
384
330
|
let searchPath = input.path;
|
|
385
331
|
// Resolve relative paths
|
|
@@ -8,8 +8,8 @@ import { getDefaultShellManager } from './shell-manager.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export const killShellTool = defineTool({
|
|
10
10
|
name: 'kill_shell',
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// Original: 'Kill a running background bash shell by its ID. Use this to terminate long-running commands that are no longer needed.'
|
|
12
|
+
description: 'Terminate a background bash shell by ID.',
|
|
13
13
|
inputSchema: {
|
|
14
14
|
type: 'object',
|
|
15
15
|
properties: {
|
|
@@ -63,18 +63,8 @@ export function createKillShellTool(options) {
|
|
|
63
63
|
const manager = options?.shellManager ?? getDefaultShellManager();
|
|
64
64
|
return defineTool({
|
|
65
65
|
name: 'kill_shell',
|
|
66
|
-
description:
|
|
67
|
-
|
|
68
|
-
inputSchema: {
|
|
69
|
-
type: 'object',
|
|
70
|
-
properties: {
|
|
71
|
-
shell_id: {
|
|
72
|
-
type: 'string',
|
|
73
|
-
description: 'The ID of the background shell to kill',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
required: ['shell_id'],
|
|
77
|
-
},
|
|
66
|
+
description: killShellTool.definition.description,
|
|
67
|
+
inputSchema: killShellTool.definition.inputSchema,
|
|
78
68
|
execute: (input) => Promise.resolve(executeKillShell(input, manager)),
|
|
79
69
|
});
|
|
80
70
|
}
|