@defai.digital/ax-cli 3.15.25 → 4.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/README.md +59 -6
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.js +98 -122
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/setup.js +4 -4
- package/dist/commands/setup.js.map +1 -1
- package/dist/llm/tools.d.ts +14 -0
- package/dist/llm/tools.js +17 -4
- package/dist/llm/tools.js.map +1 -1
- package/dist/planner/types.d.ts +4 -4
- package/dist/tools/definitions/ask-user.d.ts +8 -0
- package/dist/tools/definitions/ask-user.js +168 -0
- package/dist/tools/definitions/ask-user.js.map +1 -0
- package/dist/tools/definitions/ax-agent.d.ts +7 -0
- package/dist/tools/definitions/ax-agent.js +149 -0
- package/dist/tools/definitions/ax-agent.js.map +1 -0
- package/dist/tools/definitions/bash-output.d.ts +7 -0
- package/dist/tools/definitions/bash-output.js +78 -0
- package/dist/tools/definitions/bash-output.js.map +1 -0
- package/dist/tools/definitions/bash.d.ts +8 -0
- package/dist/tools/definitions/bash.js +152 -0
- package/dist/tools/definitions/bash.js.map +1 -0
- package/dist/tools/definitions/create-file.d.ts +7 -0
- package/dist/tools/definitions/create-file.js +129 -0
- package/dist/tools/definitions/create-file.js.map +1 -0
- package/dist/tools/definitions/design.d.ts +12 -0
- package/dist/tools/definitions/design.js +368 -0
- package/dist/tools/definitions/design.js.map +1 -0
- package/dist/tools/definitions/index.d.ts +48 -0
- package/dist/tools/definitions/index.js +96 -0
- package/dist/tools/definitions/index.js.map +1 -0
- package/dist/tools/definitions/multi-edit.d.ts +7 -0
- package/dist/tools/definitions/multi-edit.js +123 -0
- package/dist/tools/definitions/multi-edit.js.map +1 -0
- package/dist/tools/definitions/search.d.ts +7 -0
- package/dist/tools/definitions/search.js +159 -0
- package/dist/tools/definitions/search.js.map +1 -0
- package/dist/tools/definitions/str-replace-editor.d.ts +7 -0
- package/dist/tools/definitions/str-replace-editor.js +145 -0
- package/dist/tools/definitions/str-replace-editor.js.map +1 -0
- package/dist/tools/definitions/todo.d.ts +8 -0
- package/dist/tools/definitions/todo.js +261 -0
- package/dist/tools/definitions/todo.js.map +1 -0
- package/dist/tools/definitions/view-file.d.ts +7 -0
- package/dist/tools/definitions/view-file.js +111 -0
- package/dist/tools/definitions/view-file.js.map +1 -0
- package/dist/tools/format-generators.d.ts +62 -0
- package/dist/tools/format-generators.js +291 -0
- package/dist/tools/format-generators.js.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/result-enhancer.d.ts +64 -0
- package/dist/tools/result-enhancer.js +215 -0
- package/dist/tools/result-enhancer.js.map +1 -0
- package/dist/tools/types.d.ts +249 -0
- package/dist/tools/types.js +11 -0
- package/dist/tools/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format Generators for Tool Definitions
|
|
3
|
+
*
|
|
4
|
+
* Converts rich ToolDefinition objects to various output formats:
|
|
5
|
+
* - OpenAI function calling format
|
|
6
|
+
* - Anthropic tool format
|
|
7
|
+
* - System prompt sections
|
|
8
|
+
*
|
|
9
|
+
* These are DERIVED formats - the ToolDefinition is the source of truth.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Convert ParameterDefinition to JSON Schema format for OpenAI
|
|
13
|
+
*/
|
|
14
|
+
function toJSONSchemaProperty(param) {
|
|
15
|
+
// Build the base schema
|
|
16
|
+
const baseSchema = {
|
|
17
|
+
type: param.type,
|
|
18
|
+
description: param.description,
|
|
19
|
+
};
|
|
20
|
+
if (param.default !== undefined) {
|
|
21
|
+
baseSchema.default = param.default;
|
|
22
|
+
}
|
|
23
|
+
if (param.enum) {
|
|
24
|
+
baseSchema.enum = param.enum;
|
|
25
|
+
}
|
|
26
|
+
if (param.items && param.type === 'array') {
|
|
27
|
+
const items = param.items;
|
|
28
|
+
if (items.type === 'object' && items.properties) {
|
|
29
|
+
baseSchema.items = {
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: Object.fromEntries(Object.entries(items.properties).map(([key, val]) => [
|
|
32
|
+
key,
|
|
33
|
+
toJSONSchemaProperty(val),
|
|
34
|
+
])),
|
|
35
|
+
required: items.required || [],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
baseSchema.items = { type: items.type };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return baseSchema;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generate a compact description suitable for API calls
|
|
46
|
+
*
|
|
47
|
+
* The compact description is the first paragraph plus key constraints
|
|
48
|
+
* for dangerous tools.
|
|
49
|
+
*/
|
|
50
|
+
export function generateCompactDescription(tool) {
|
|
51
|
+
// Get first paragraph (up to first double newline or 500 chars)
|
|
52
|
+
const firstParagraph = tool.description.split('\n\n')[0].slice(0, 500);
|
|
53
|
+
// For dangerous tools, add the most important constraint
|
|
54
|
+
if (tool.safetyLevel === 'dangerous' && tool.constraints.length > 0) {
|
|
55
|
+
return `${firstParagraph} IMPORTANT: ${tool.constraints[0]}`;
|
|
56
|
+
}
|
|
57
|
+
return firstParagraph;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Convert rich ToolDefinition to OpenAI function calling format
|
|
61
|
+
*
|
|
62
|
+
* This is a DERIVED format for API calls. The full tool details
|
|
63
|
+
* should be provided in the system prompt.
|
|
64
|
+
*/
|
|
65
|
+
export function toOpenAIFormat(tool) {
|
|
66
|
+
const properties = {};
|
|
67
|
+
for (const [name, param] of Object.entries(tool.parameters.properties)) {
|
|
68
|
+
properties[name] = toJSONSchemaProperty(param);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
type: 'function',
|
|
72
|
+
function: {
|
|
73
|
+
name: tool.name,
|
|
74
|
+
description: generateCompactDescription(tool),
|
|
75
|
+
parameters: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties,
|
|
78
|
+
required: tool.parameters.required,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Convert rich ToolDefinition to Anthropic tool format
|
|
85
|
+
*/
|
|
86
|
+
export function toAnthropicFormat(tool) {
|
|
87
|
+
const properties = {};
|
|
88
|
+
for (const [name, param] of Object.entries(tool.parameters.properties)) {
|
|
89
|
+
properties[name] = toJSONSchemaProperty(param);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
name: tool.name,
|
|
93
|
+
description: generateCompactDescription(tool),
|
|
94
|
+
input_schema: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties,
|
|
97
|
+
required: tool.parameters.required,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Generate a full system prompt section for a tool
|
|
103
|
+
*
|
|
104
|
+
* This includes all the rich metadata: description, parameters,
|
|
105
|
+
* usage notes, constraints, anti-patterns, and examples.
|
|
106
|
+
*/
|
|
107
|
+
export function toSystemPromptSection(tool) {
|
|
108
|
+
const sections = [];
|
|
109
|
+
// Header
|
|
110
|
+
sections.push(`## ${tool.displayName}`);
|
|
111
|
+
sections.push('');
|
|
112
|
+
sections.push(tool.description);
|
|
113
|
+
sections.push('');
|
|
114
|
+
// Parameters
|
|
115
|
+
sections.push('### Parameters');
|
|
116
|
+
sections.push('');
|
|
117
|
+
for (const [name, param] of Object.entries(tool.parameters.properties)) {
|
|
118
|
+
const required = tool.parameters.required.includes(name) ? '(required)' : '(optional)';
|
|
119
|
+
sections.push(`- \`${name}\` ${required}: ${param.description}`);
|
|
120
|
+
if (param.default !== undefined) {
|
|
121
|
+
sections.push(` - Default: \`${JSON.stringify(param.default)}\``);
|
|
122
|
+
}
|
|
123
|
+
if (param.enum) {
|
|
124
|
+
sections.push(` - Options: ${param.enum.map(e => `\`${e}\``).join(', ')}`);
|
|
125
|
+
}
|
|
126
|
+
if (param.examples && param.examples.length > 0) {
|
|
127
|
+
sections.push(` - Examples: ${param.examples.map(e => `\`${JSON.stringify(e)}\``).join(', ')}`);
|
|
128
|
+
}
|
|
129
|
+
if (param.constraints && param.constraints.length > 0) {
|
|
130
|
+
param.constraints.forEach(c => sections.push(` - ${c}`));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
sections.push('');
|
|
134
|
+
// Usage Notes
|
|
135
|
+
if (tool.usageNotes.length > 0) {
|
|
136
|
+
sections.push('### Usage Notes');
|
|
137
|
+
sections.push('');
|
|
138
|
+
tool.usageNotes.forEach(note => sections.push(`- ${note}`));
|
|
139
|
+
sections.push('');
|
|
140
|
+
}
|
|
141
|
+
// Constraints
|
|
142
|
+
if (tool.constraints.length > 0) {
|
|
143
|
+
sections.push('### Constraints');
|
|
144
|
+
sections.push('');
|
|
145
|
+
tool.constraints.forEach(c => sections.push(`- ${c}`));
|
|
146
|
+
sections.push('');
|
|
147
|
+
}
|
|
148
|
+
// Anti-patterns (when NOT to use)
|
|
149
|
+
if (tool.antiPatterns && tool.antiPatterns.length > 0) {
|
|
150
|
+
sections.push('### Do NOT Use When');
|
|
151
|
+
sections.push('');
|
|
152
|
+
tool.antiPatterns.forEach(ap => sections.push(`- ${ap}`));
|
|
153
|
+
sections.push('');
|
|
154
|
+
}
|
|
155
|
+
// Examples
|
|
156
|
+
if (tool.examples.length > 0) {
|
|
157
|
+
sections.push('### Examples');
|
|
158
|
+
sections.push('');
|
|
159
|
+
tool.examples.forEach(ex => {
|
|
160
|
+
sections.push(`**${ex.description}**`);
|
|
161
|
+
sections.push(`- Scenario: ${ex.scenario}`);
|
|
162
|
+
sections.push(`- Input: \`${JSON.stringify(ex.input)}\``);
|
|
163
|
+
sections.push(`- Expected: ${ex.expectedBehavior}`);
|
|
164
|
+
if (ex.notes) {
|
|
165
|
+
sections.push(`- Note: ${ex.notes}`);
|
|
166
|
+
}
|
|
167
|
+
sections.push('');
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Related tools
|
|
171
|
+
if (tool.relatedTools && tool.relatedTools.length > 0) {
|
|
172
|
+
sections.push(`**Related tools:** ${tool.relatedTools.join(', ')}`);
|
|
173
|
+
sections.push('');
|
|
174
|
+
}
|
|
175
|
+
// Alternatives
|
|
176
|
+
if (tool.alternatives && tool.alternatives.length > 0) {
|
|
177
|
+
sections.push(`**Alternatives:** ${tool.alternatives.join(', ')}`);
|
|
178
|
+
sections.push('');
|
|
179
|
+
}
|
|
180
|
+
return sections.join('\n');
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Generate the complete tool instructions section for system prompt
|
|
184
|
+
*
|
|
185
|
+
* @param tools - Array of tool definitions
|
|
186
|
+
* @returns Formatted markdown string with all tool documentation
|
|
187
|
+
*/
|
|
188
|
+
export function generateToolInstructions(tools) {
|
|
189
|
+
const sections = [];
|
|
190
|
+
sections.push('# Available Tools');
|
|
191
|
+
sections.push('');
|
|
192
|
+
sections.push('The following tools are available. Read each description carefully before using.');
|
|
193
|
+
sections.push('');
|
|
194
|
+
// Group tools by category
|
|
195
|
+
const byCategory = new Map();
|
|
196
|
+
for (const tool of tools) {
|
|
197
|
+
for (const category of tool.categories) {
|
|
198
|
+
if (!byCategory.has(category)) {
|
|
199
|
+
byCategory.set(category, []);
|
|
200
|
+
}
|
|
201
|
+
const categoryTools = byCategory.get(category);
|
|
202
|
+
if (categoryTools) {
|
|
203
|
+
categoryTools.push(tool);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Generate sections by category
|
|
208
|
+
const categoryOrder = [
|
|
209
|
+
'file-operations',
|
|
210
|
+
'command-execution',
|
|
211
|
+
'search',
|
|
212
|
+
'task-management',
|
|
213
|
+
'user-interaction',
|
|
214
|
+
'agent-delegation',
|
|
215
|
+
'design',
|
|
216
|
+
'web',
|
|
217
|
+
];
|
|
218
|
+
for (const category of categoryOrder) {
|
|
219
|
+
const categoryTools = byCategory.get(category);
|
|
220
|
+
if (categoryTools && categoryTools.length > 0) {
|
|
221
|
+
sections.push(`---`);
|
|
222
|
+
sections.push('');
|
|
223
|
+
sections.push(`# ${formatCategoryName(category)}`);
|
|
224
|
+
sections.push('');
|
|
225
|
+
// Deduplicate tools (a tool might be in multiple categories)
|
|
226
|
+
const seen = new Set();
|
|
227
|
+
for (const tool of categoryTools) {
|
|
228
|
+
if (!seen.has(tool.name)) {
|
|
229
|
+
seen.add(tool.name);
|
|
230
|
+
sections.push(toSystemPromptSection(tool));
|
|
231
|
+
sections.push('---');
|
|
232
|
+
sections.push('');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// Add general tool usage principles
|
|
238
|
+
sections.push('# Tool Usage Principles');
|
|
239
|
+
sections.push('');
|
|
240
|
+
sections.push('1. **Use specialized tools over general tools** - Use view_file instead of bash cat');
|
|
241
|
+
sections.push('2. **Read before editing** - Always view_file before str_replace_editor');
|
|
242
|
+
sections.push('3. **Parallel execution** - Make independent tool calls in parallel');
|
|
243
|
+
sections.push('4. **Sequential for dependencies** - Chain dependent calls with proper ordering');
|
|
244
|
+
sections.push('5. **Never guess parameters** - Ask if unsure about required values');
|
|
245
|
+
sections.push('6. **Match exact content** - For str_replace_editor, copy exact text from file');
|
|
246
|
+
sections.push('');
|
|
247
|
+
return sections.join('\n');
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Format category name for display
|
|
251
|
+
*/
|
|
252
|
+
function formatCategoryName(category) {
|
|
253
|
+
const names = {
|
|
254
|
+
'file-operations': 'File Operations',
|
|
255
|
+
'command-execution': 'Command Execution',
|
|
256
|
+
'search': 'Search',
|
|
257
|
+
'task-management': 'Task Management',
|
|
258
|
+
'user-interaction': 'User Interaction',
|
|
259
|
+
'agent-delegation': 'Agent Delegation',
|
|
260
|
+
'design': 'Design Tools',
|
|
261
|
+
'web': 'Web Tools',
|
|
262
|
+
};
|
|
263
|
+
return names[category] || category;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Calculate total token cost for a set of tools
|
|
267
|
+
*
|
|
268
|
+
* Useful for budget planning and deciding which tools to include
|
|
269
|
+
*/
|
|
270
|
+
export function calculateTotalTokenCost(tools) {
|
|
271
|
+
return tools.reduce((sum, tool) => sum + tool.tokenCost, 0);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Filter tools by category
|
|
275
|
+
*/
|
|
276
|
+
export function filterByCategory(tools, categories) {
|
|
277
|
+
return tools.filter(tool => tool.categories.some(c => categories.includes(c)));
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Filter tools by safety level
|
|
281
|
+
*/
|
|
282
|
+
export function filterBySafetyLevel(tools, levels) {
|
|
283
|
+
return tools.filter(tool => levels.includes(tool.safetyLevel));
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get tools that require confirmation
|
|
287
|
+
*/
|
|
288
|
+
export function getToolsRequiringConfirmation(tools) {
|
|
289
|
+
return tools.filter(tool => tool.requiresConfirmation);
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=format-generators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-generators.js","sourceRoot":"","sources":["../../src/tools/format-generators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH;;GAEG;AACH,SAAS,oBAAoB,CAAC,KAA0B;IACtD,wBAAwB;IACxB,MAAM,UAAU,GAAkE;QAChF,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC;IAEF,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAChC,UAAU,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IACrC,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,UAAU,CAAC,IAAI,GAAG,KAAK,CAAC,IA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KAAuB,EACvB,MAAgD;IAEhD,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAuB;IACnE,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -3,3 +3,7 @@ export { TextEditorTool } from "./text-editor.js";
|
|
|
3
3
|
export { TodoTool } from "./todo-tool.js";
|
|
4
4
|
export { ConfirmationTool } from "./confirmation-tool.js";
|
|
5
5
|
export { SearchTool } from "./search.js";
|
|
6
|
+
export * from "./types.js";
|
|
7
|
+
export * from "./format-generators.js";
|
|
8
|
+
export * from "./result-enhancer.js";
|
|
9
|
+
export { TOOL_DEFINITIONS, getToolDefinition, getToolsByCategory } from "./definitions/index.js";
|
package/dist/tools/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
// Tool implementations
|
|
1
2
|
export { BashTool } from "./bash.js";
|
|
2
3
|
export { TextEditorTool } from "./text-editor.js";
|
|
3
4
|
export { TodoTool } from "./todo-tool.js";
|
|
4
5
|
export { ConfirmationTool } from "./confirmation-tool.js";
|
|
5
6
|
export { SearchTool } from "./search.js";
|
|
7
|
+
// Tool System v3.0 - Rich definitions and utilities
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./format-generators.js";
|
|
10
|
+
export * from "./result-enhancer.js";
|
|
11
|
+
export { TOOL_DEFINITIONS, getToolDefinition, getToolsByCategory } from "./definitions/index.js";
|
|
6
12
|
//# sourceMappingURL=index.js.map
|
package/dist/tools/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,oDAAoD;AACpD,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Result Enhancer
|
|
3
|
+
*
|
|
4
|
+
* Enhances tool results with embedded instructions, security reminders,
|
|
5
|
+
* and contextual guidance based on the tool definition and result content.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolDefinition, EnhancedToolResult, ResultEnhancerConfig } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Result Enhancer Class
|
|
10
|
+
*
|
|
11
|
+
* Enhances tool results with:
|
|
12
|
+
* - Security reminders for potentially dangerous content
|
|
13
|
+
* - Failure guidance based on tool constraints
|
|
14
|
+
* - Format reminders for large outputs
|
|
15
|
+
*/
|
|
16
|
+
export declare class ToolResultEnhancer {
|
|
17
|
+
private config;
|
|
18
|
+
constructor(config?: Partial<ResultEnhancerConfig>);
|
|
19
|
+
/**
|
|
20
|
+
* Enhance a tool result with embedded instructions
|
|
21
|
+
*
|
|
22
|
+
* @param toolName - Name of the tool that was executed
|
|
23
|
+
* @param result - Raw result from tool execution
|
|
24
|
+
* @param success - Whether the tool executed successfully
|
|
25
|
+
* @param definition - Tool definition with metadata
|
|
26
|
+
* @returns Enhanced result with reminders
|
|
27
|
+
*/
|
|
28
|
+
enhance(toolName: string, result: string, success: boolean, definition?: ToolDefinition): EnhancedToolResult;
|
|
29
|
+
/**
|
|
30
|
+
* Get security reminders based on content patterns
|
|
31
|
+
*/
|
|
32
|
+
private getSecurityReminders;
|
|
33
|
+
/**
|
|
34
|
+
* Get failure guidance from tool constraints
|
|
35
|
+
*/
|
|
36
|
+
private getFailureGuidance;
|
|
37
|
+
/**
|
|
38
|
+
* Get format reminders for output handling
|
|
39
|
+
*/
|
|
40
|
+
private getFormatReminders;
|
|
41
|
+
/**
|
|
42
|
+
* Get tool-specific reminders based on tool and context
|
|
43
|
+
*/
|
|
44
|
+
private getToolSpecificReminders;
|
|
45
|
+
/**
|
|
46
|
+
* Update configuration
|
|
47
|
+
*/
|
|
48
|
+
setConfig(config: Partial<ResultEnhancerConfig>): void;
|
|
49
|
+
/**
|
|
50
|
+
* Get current configuration
|
|
51
|
+
*/
|
|
52
|
+
getConfig(): ResultEnhancerConfig;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a default result enhancer instance
|
|
56
|
+
*/
|
|
57
|
+
export declare function createResultEnhancer(config?: Partial<ResultEnhancerConfig>): ToolResultEnhancer;
|
|
58
|
+
/**
|
|
59
|
+
* Format reminders for inclusion in tool result message
|
|
60
|
+
*
|
|
61
|
+
* @param reminders - Array of reminder strings
|
|
62
|
+
* @returns Formatted string to append to result
|
|
63
|
+
*/
|
|
64
|
+
export declare function formatReminders(reminders: string[]): string;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Result Enhancer
|
|
3
|
+
*
|
|
4
|
+
* Enhances tool results with embedded instructions, security reminders,
|
|
5
|
+
* and contextual guidance based on the tool definition and result content.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Default configuration for the result enhancer
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_CONFIG = {
|
|
11
|
+
securityReminders: true,
|
|
12
|
+
toolGuidance: true,
|
|
13
|
+
formatReminders: true,
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Patterns that may indicate malicious content
|
|
17
|
+
*/
|
|
18
|
+
const MALWARE_PATTERNS = [
|
|
19
|
+
/eval\s*\(\s*atob/i,
|
|
20
|
+
/powershell\s+-enc/i,
|
|
21
|
+
/curl.*\|\s*bash/i,
|
|
22
|
+
/wget.*\|\s*sh/i,
|
|
23
|
+
/base64\s+-d.*\|\s*(bash|sh)/i,
|
|
24
|
+
/nc\s+-e\s+\/bin\/(ba)?sh/i,
|
|
25
|
+
/python\s+-c\s*['"]import\s+socket/i,
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Patterns that may indicate sensitive information
|
|
29
|
+
*/
|
|
30
|
+
const SENSITIVE_PATTERNS = [
|
|
31
|
+
/password\s*[=:]\s*["'][^"']+["']/i,
|
|
32
|
+
/-----BEGIN\s+(RSA\s+)?PRIVATE\s+KEY-----/,
|
|
33
|
+
/-----BEGIN\s+OPENSSH\s+PRIVATE\s+KEY-----/,
|
|
34
|
+
/sk-[a-zA-Z0-9]{48}/, // OpenAI key
|
|
35
|
+
/ghp_[a-zA-Z0-9]{36}/, // GitHub personal access token
|
|
36
|
+
/gho_[a-zA-Z0-9]{36}/, // GitHub OAuth token
|
|
37
|
+
/github_pat_[a-zA-Z0-9_]{22,}/i, // GitHub fine-grained PAT
|
|
38
|
+
/xox[baprs]-[a-zA-Z0-9-]+/, // Slack tokens
|
|
39
|
+
/AKIA[0-9A-Z]{16}/, // AWS access key
|
|
40
|
+
/eyJ[a-zA-Z0-9_-]+\.eyJ[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+/, // JWT tokens
|
|
41
|
+
];
|
|
42
|
+
/**
|
|
43
|
+
* Result Enhancer Class
|
|
44
|
+
*
|
|
45
|
+
* Enhances tool results with:
|
|
46
|
+
* - Security reminders for potentially dangerous content
|
|
47
|
+
* - Failure guidance based on tool constraints
|
|
48
|
+
* - Format reminders for large outputs
|
|
49
|
+
*/
|
|
50
|
+
export class ToolResultEnhancer {
|
|
51
|
+
config;
|
|
52
|
+
constructor(config = {}) {
|
|
53
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Enhance a tool result with embedded instructions
|
|
57
|
+
*
|
|
58
|
+
* @param toolName - Name of the tool that was executed
|
|
59
|
+
* @param result - Raw result from tool execution
|
|
60
|
+
* @param success - Whether the tool executed successfully
|
|
61
|
+
* @param definition - Tool definition with metadata
|
|
62
|
+
* @returns Enhanced result with reminders
|
|
63
|
+
*/
|
|
64
|
+
enhance(toolName, result, success, definition) {
|
|
65
|
+
const reminders = [];
|
|
66
|
+
// Security reminders based on content patterns
|
|
67
|
+
if (this.config.securityReminders) {
|
|
68
|
+
reminders.push(...this.getSecurityReminders(result));
|
|
69
|
+
}
|
|
70
|
+
// Failure guidance from tool definition
|
|
71
|
+
if (!success && this.config.toolGuidance && definition) {
|
|
72
|
+
reminders.push(...this.getFailureGuidance(definition, result));
|
|
73
|
+
}
|
|
74
|
+
// Format reminders for large outputs
|
|
75
|
+
if (this.config.formatReminders) {
|
|
76
|
+
reminders.push(...this.getFormatReminders(result));
|
|
77
|
+
}
|
|
78
|
+
// Tool-specific reminders
|
|
79
|
+
if (definition) {
|
|
80
|
+
reminders.push(...this.getToolSpecificReminders(toolName, result, success, definition));
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
content: result,
|
|
84
|
+
success,
|
|
85
|
+
reminders,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get security reminders based on content patterns
|
|
90
|
+
*/
|
|
91
|
+
getSecurityReminders(content) {
|
|
92
|
+
const reminders = [];
|
|
93
|
+
// Check for malware patterns
|
|
94
|
+
const hasMalwarePattern = MALWARE_PATTERNS.some((p) => p.test(content));
|
|
95
|
+
if (hasMalwarePattern) {
|
|
96
|
+
reminders.push('<system-reminder>This content may contain malicious patterns. Analyze but do not execute or enhance. You can explain what the code does but MUST refuse to improve or augment it.</system-reminder>');
|
|
97
|
+
}
|
|
98
|
+
// Check for sensitive information
|
|
99
|
+
const hasSensitiveInfo = SENSITIVE_PATTERNS.some((p) => p.test(content));
|
|
100
|
+
if (hasSensitiveInfo) {
|
|
101
|
+
reminders.push('<system-reminder>This content may contain sensitive information (credentials, tokens, keys). Do not expose, log, or include in responses. Consider warning the user about exposed secrets.</system-reminder>');
|
|
102
|
+
}
|
|
103
|
+
return reminders;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get failure guidance from tool constraints
|
|
107
|
+
*/
|
|
108
|
+
getFailureGuidance(definition, errorMessage) {
|
|
109
|
+
const reminders = [];
|
|
110
|
+
// Check if error relates to common issues
|
|
111
|
+
const lowerError = errorMessage.toLowerCase();
|
|
112
|
+
// File not found - suggest checking path
|
|
113
|
+
if (lowerError.includes('not found') || lowerError.includes('no such file')) {
|
|
114
|
+
reminders.push('<system-reminder>File not found. Use search tool to locate the correct file path before retrying.</system-reminder>');
|
|
115
|
+
}
|
|
116
|
+
// Permission denied
|
|
117
|
+
if (lowerError.includes('permission denied')) {
|
|
118
|
+
reminders.push('<system-reminder>Permission denied. The file may be read-only or require elevated privileges.</system-reminder>');
|
|
119
|
+
}
|
|
120
|
+
// String not found in file (for str_replace_editor)
|
|
121
|
+
if (lowerError.includes('not found in file') ||
|
|
122
|
+
lowerError.includes('old_str not found')) {
|
|
123
|
+
reminders.push('<system-reminder>The exact string was not found. Use view_file to see the current content and copy the exact text including whitespace and indentation.</system-reminder>');
|
|
124
|
+
}
|
|
125
|
+
// Multiple occurrences
|
|
126
|
+
if (lowerError.includes('multiple occurrences') || lowerError.includes('not unique')) {
|
|
127
|
+
reminders.push('<system-reminder>The string appears multiple times. Include more surrounding context to make it unique, or use replace_all: true if all occurrences should be replaced.</system-reminder>');
|
|
128
|
+
}
|
|
129
|
+
// Add first constraint as general guidance
|
|
130
|
+
if (definition.constraints.length > 0 && reminders.length === 0) {
|
|
131
|
+
reminders.push(`<system-reminder>Tool constraint: ${definition.constraints[0]}</system-reminder>`);
|
|
132
|
+
}
|
|
133
|
+
return reminders;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get format reminders for output handling
|
|
137
|
+
*/
|
|
138
|
+
getFormatReminders(content) {
|
|
139
|
+
const reminders = [];
|
|
140
|
+
// Large output truncation warning
|
|
141
|
+
if (content.length > 25000) {
|
|
142
|
+
reminders.push('<system-reminder>Output was truncated due to length. Use pagination parameters (start_line/end_line) or output redirection for full content.</system-reminder>');
|
|
143
|
+
}
|
|
144
|
+
// Very long lines
|
|
145
|
+
const lines = content.split('\n');
|
|
146
|
+
const hasVeryLongLines = lines.some((line) => line.length > 2000);
|
|
147
|
+
if (hasVeryLongLines) {
|
|
148
|
+
reminders.push('<system-reminder>Some lines were truncated due to length (>2000 chars). Consider using a tool that can handle the specific format.</system-reminder>');
|
|
149
|
+
}
|
|
150
|
+
return reminders;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get tool-specific reminders based on tool and context
|
|
154
|
+
*/
|
|
155
|
+
getToolSpecificReminders(toolName, result, success, _definition) {
|
|
156
|
+
const reminders = [];
|
|
157
|
+
// After viewing a file, remind about editing best practices
|
|
158
|
+
if (toolName === 'view_file' && success) {
|
|
159
|
+
// Check if this looks like code
|
|
160
|
+
if (result.includes('function') || result.includes('class') || result.includes('import')) {
|
|
161
|
+
reminders.push('<system-reminder>When editing this file, copy the exact content including whitespace from the line numbers shown. The format is: line number + tab + actual content.</system-reminder>');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// After bash command, check for common issues
|
|
165
|
+
if (toolName === 'bash') {
|
|
166
|
+
// Check for test failures
|
|
167
|
+
if (result.includes('FAIL') || result.includes('failed') || result.includes('Error:')) {
|
|
168
|
+
reminders.push('<system-reminder>Command output indicates errors or failures. Review the output carefully and address the issues before proceeding.</system-reminder>');
|
|
169
|
+
}
|
|
170
|
+
// Check for npm/yarn install suggestions
|
|
171
|
+
if (result.includes('npm install') || result.includes('yarn add')) {
|
|
172
|
+
reminders.push('<system-reminder>The output suggests installing dependencies. Consider running the suggested command if appropriate.</system-reminder>');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
// After search, guide next steps
|
|
176
|
+
if (toolName === 'search' && success) {
|
|
177
|
+
const matchCount = (result.match(/:\d+:/g) || []).length;
|
|
178
|
+
if (matchCount > 10) {
|
|
179
|
+
reminders.push('<system-reminder>Many results found. Consider using include_pattern or file_types to narrow down the search.</system-reminder>');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return reminders;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Update configuration
|
|
186
|
+
*/
|
|
187
|
+
setConfig(config) {
|
|
188
|
+
this.config = { ...this.config, ...config };
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get current configuration
|
|
192
|
+
*/
|
|
193
|
+
getConfig() {
|
|
194
|
+
return { ...this.config };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Create a default result enhancer instance
|
|
199
|
+
*/
|
|
200
|
+
export function createResultEnhancer(config) {
|
|
201
|
+
return new ToolResultEnhancer(config);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Format reminders for inclusion in tool result message
|
|
205
|
+
*
|
|
206
|
+
* @param reminders - Array of reminder strings
|
|
207
|
+
* @returns Formatted string to append to result
|
|
208
|
+
*/
|
|
209
|
+
export function formatReminders(reminders) {
|
|
210
|
+
if (reminders.length === 0) {
|
|
211
|
+
return '';
|
|
212
|
+
}
|
|
213
|
+
return '\n\n' + reminders.join('\n');
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=result-enhancer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-enhancer.js","sourceRoot":"","sources":["../../src/tools/result-enhancer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH;;GAEG;AACH,MAAM,cAAc,GAAyB;IAC3C,iBAAiB,EAAE,IAAI;IACvB,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,IAAI;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAa;IACjC,mBAAmB;IACnB,oBAAoB;IACpB,kBAAkB;IAClB,gBAAgB;IAChB,8BAA8B;IAC9B,2BAA2B;IAC3B,oCAAoC;CACrC,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAa;IACnC,mCAAmC;IACnC,0CAA0C;IAC1C,2CAA2C;IAC3C,oBAAoB,EAAE,aAAa;IACnC,qBAAqB,EAAE,+BAA+B;IACtD,qBAAqB,EAAE,qBAAqB;IAC5C,+BAA+B,EAAE,0BAA0B;IAC3D,0BAA0B,EAAE,eAAe;IAC3C,kBAAkB,EAAE,iBAAiB;IACrC,sDAAsD,EAAE,aAAa;CACtE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,CAAuB;IAErC,YAAY,SAAwC,EAAE;QACpD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IACjD,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,CACL,QAAgB,EAChB,MAAc,EACd,OAAgB,EAChB,UAA2B;QAE3B,MAAM,SAAS,GAAa,EAAE,CAAC;QAE/B,+CAA+C;QAC/C,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,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