@defai.digital/ax-cli 3.15.26 → 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 +56 -21
- package/dist/commands/init.d.ts +3 -3
- package/dist/commands/init.js +175 -25
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/setup.d.ts +0 -1
- package/dist/commands/setup.js +7 -139
- 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,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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,EAAE,GAAG,MAAM,EAAE,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAsC;IAEtC,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,SAAmB;IACjD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rich Tool Definition Types for ax-cli Tool System v3.0
|
|
3
|
+
*
|
|
4
|
+
* This file defines the comprehensive ToolDefinition interface that serves as
|
|
5
|
+
* the single source of truth for all tool metadata. OpenAI/Anthropic formats
|
|
6
|
+
* are DERIVED from these definitions, not the other way around.
|
|
7
|
+
*
|
|
8
|
+
* @see PRD-AX-CLI-TOOL-SYSTEM-V3-FINAL.md
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Tool categories for organization and filtering
|
|
12
|
+
*/
|
|
13
|
+
export type ToolCategory = 'file-operations' | 'command-execution' | 'search' | 'task-management' | 'user-interaction' | 'web' | 'agent-delegation' | 'design';
|
|
14
|
+
/**
|
|
15
|
+
* Safety level classification for tools
|
|
16
|
+
* - safe: No risk of data loss or security issues
|
|
17
|
+
* - moderate: Some risk, but typically reversible
|
|
18
|
+
* - dangerous: High risk, requires confirmation
|
|
19
|
+
*/
|
|
20
|
+
export type ToolSafetyLevel = 'safe' | 'moderate' | 'dangerous';
|
|
21
|
+
/**
|
|
22
|
+
* Parameter type definitions (JSON Schema compatible)
|
|
23
|
+
*/
|
|
24
|
+
export type ParameterType = 'string' | 'number' | 'boolean' | 'array' | 'object';
|
|
25
|
+
/**
|
|
26
|
+
* Detailed parameter definition with rich metadata
|
|
27
|
+
*/
|
|
28
|
+
export interface ParameterDefinition {
|
|
29
|
+
/** JSON Schema type */
|
|
30
|
+
type: ParameterType;
|
|
31
|
+
/** Comprehensive description of the parameter */
|
|
32
|
+
description: string;
|
|
33
|
+
/** Default value if not provided */
|
|
34
|
+
default?: unknown;
|
|
35
|
+
/** Allowed values (for enum-like parameters) */
|
|
36
|
+
enum?: string[];
|
|
37
|
+
/** Format hint (e.g., 'file-path', 'url', 'date-iso8601') */
|
|
38
|
+
format?: string;
|
|
39
|
+
/** Example values for LLM guidance */
|
|
40
|
+
examples?: unknown[];
|
|
41
|
+
/** Constraints that must be satisfied */
|
|
42
|
+
constraints?: string[];
|
|
43
|
+
/** For array types: schema of array items */
|
|
44
|
+
items?: ParameterDefinition | {
|
|
45
|
+
type: ParameterType;
|
|
46
|
+
properties?: Record<string, ParameterDefinition>;
|
|
47
|
+
required?: string[];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Tool parameter schema (JSON Schema object format)
|
|
52
|
+
*/
|
|
53
|
+
export interface ToolParameterSchema {
|
|
54
|
+
type: 'object';
|
|
55
|
+
properties: Record<string, ParameterDefinition>;
|
|
56
|
+
required: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Concrete usage example for a tool
|
|
60
|
+
*/
|
|
61
|
+
export interface ToolExample {
|
|
62
|
+
/** Short description of what the example demonstrates */
|
|
63
|
+
description: string;
|
|
64
|
+
/** Scenario context - when would you use this */
|
|
65
|
+
scenario: string;
|
|
66
|
+
/** Example input arguments */
|
|
67
|
+
input: Record<string, unknown>;
|
|
68
|
+
/** Expected behavior/output description */
|
|
69
|
+
expectedBehavior: string;
|
|
70
|
+
/** Additional notes about the example */
|
|
71
|
+
notes?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Rich Tool Definition - Single Source of Truth
|
|
75
|
+
*
|
|
76
|
+
* This interface defines everything about a tool. OpenAI function calling
|
|
77
|
+
* format and Anthropic tool format are derived from this definition.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const viewFileTool: ToolDefinition = {
|
|
82
|
+
* name: 'view_file',
|
|
83
|
+
* displayName: 'View File',
|
|
84
|
+
* description: 'Read and display file contents...',
|
|
85
|
+
* parameters: { ... },
|
|
86
|
+
* usageNotes: ['Always read before editing', ...],
|
|
87
|
+
* constraints: ['Cannot modify files', ...],
|
|
88
|
+
* examples: [{ description: 'Read a source file', ... }],
|
|
89
|
+
* tokenCost: 439,
|
|
90
|
+
* safetyLevel: 'safe',
|
|
91
|
+
* requiresConfirmation: false,
|
|
92
|
+
* categories: ['file-operations'],
|
|
93
|
+
* };
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export interface ToolDefinition {
|
|
97
|
+
/** Tool identifier (lowercase with underscores) */
|
|
98
|
+
name: string;
|
|
99
|
+
/** Display name for UI (Title Case) */
|
|
100
|
+
displayName: string;
|
|
101
|
+
/**
|
|
102
|
+
* Comprehensive description (500+ words for complex tools)
|
|
103
|
+
*
|
|
104
|
+
* Should include:
|
|
105
|
+
* - What the tool does
|
|
106
|
+
* - When to use it
|
|
107
|
+
* - When NOT to use it
|
|
108
|
+
* - Important caveats
|
|
109
|
+
*/
|
|
110
|
+
description: string;
|
|
111
|
+
/** Input parameter schema */
|
|
112
|
+
parameters: ToolParameterSchema;
|
|
113
|
+
/**
|
|
114
|
+
* Detailed usage guidance for LLM
|
|
115
|
+
* Aim for 5-10 notes covering common patterns and best practices
|
|
116
|
+
*/
|
|
117
|
+
usageNotes: string[];
|
|
118
|
+
/**
|
|
119
|
+
* Constraints and limitations
|
|
120
|
+
* Things the LLM should NEVER do with this tool
|
|
121
|
+
*/
|
|
122
|
+
constraints: string[];
|
|
123
|
+
/**
|
|
124
|
+
* Concrete usage examples (3-5 per tool)
|
|
125
|
+
* Each example should cover a realistic scenario
|
|
126
|
+
*/
|
|
127
|
+
examples: ToolExample[];
|
|
128
|
+
/**
|
|
129
|
+
* Estimated token cost for this tool's description
|
|
130
|
+
* Used for token budget planning
|
|
131
|
+
*/
|
|
132
|
+
tokenCost: number;
|
|
133
|
+
/** Safety classification */
|
|
134
|
+
safetyLevel: ToolSafetyLevel;
|
|
135
|
+
/** Requires user confirmation before execution */
|
|
136
|
+
requiresConfirmation: boolean;
|
|
137
|
+
/** Alternative tools to consider */
|
|
138
|
+
alternatives?: string[];
|
|
139
|
+
/** Tool categories for organization */
|
|
140
|
+
categories: ToolCategory[];
|
|
141
|
+
/**
|
|
142
|
+
* When NOT to use this tool
|
|
143
|
+
* Common misuses that should be avoided
|
|
144
|
+
*/
|
|
145
|
+
antiPatterns?: string[];
|
|
146
|
+
/** Related tools that work well together */
|
|
147
|
+
relatedTools?: string[];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Result from tool execution
|
|
151
|
+
*/
|
|
152
|
+
export interface ToolResult {
|
|
153
|
+
/** Whether the tool executed successfully */
|
|
154
|
+
success: boolean;
|
|
155
|
+
/** Output content (success message or error description) */
|
|
156
|
+
output: string;
|
|
157
|
+
/** Error message if success is false */
|
|
158
|
+
error?: string;
|
|
159
|
+
/** Additional structured data */
|
|
160
|
+
data?: Record<string, unknown>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Enhanced result with embedded instructions
|
|
164
|
+
*/
|
|
165
|
+
export interface EnhancedToolResult {
|
|
166
|
+
/** Original tool result content */
|
|
167
|
+
content: string;
|
|
168
|
+
/** Whether the execution was successful */
|
|
169
|
+
success: boolean;
|
|
170
|
+
/** Reminders to inject into context */
|
|
171
|
+
reminders: string[];
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Tool implementation interface
|
|
175
|
+
* All tool implementations must implement this interface
|
|
176
|
+
*/
|
|
177
|
+
export interface ToolImplementation {
|
|
178
|
+
/** Execute the tool with given arguments */
|
|
179
|
+
execute(args: Record<string, unknown>): Promise<ToolResult>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Configuration for the result enhancer
|
|
183
|
+
*/
|
|
184
|
+
export interface ResultEnhancerConfig {
|
|
185
|
+
/** Include security reminders based on content patterns */
|
|
186
|
+
securityReminders: boolean;
|
|
187
|
+
/** Include failure guidance from tool constraints */
|
|
188
|
+
toolGuidance: boolean;
|
|
189
|
+
/** Include format reminders (truncation, etc.) */
|
|
190
|
+
formatReminders: boolean;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Pre-execution hook result
|
|
194
|
+
*/
|
|
195
|
+
export interface PreHookResult {
|
|
196
|
+
/** Whether to allow execution */
|
|
197
|
+
allow: boolean;
|
|
198
|
+
/** Modified arguments (if any) */
|
|
199
|
+
args: Record<string, unknown>;
|
|
200
|
+
/** Reason for blocking (if allow is false) */
|
|
201
|
+
blockReason?: string;
|
|
202
|
+
/** Reminders to add to result */
|
|
203
|
+
reminders: string[];
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Post-execution hook result
|
|
207
|
+
*/
|
|
208
|
+
export interface PostHookResult {
|
|
209
|
+
/** Reminders to add to result */
|
|
210
|
+
reminders: string[];
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* OpenAI function calling format (derived from ToolDefinition)
|
|
214
|
+
*/
|
|
215
|
+
export interface OpenAITool {
|
|
216
|
+
type: 'function';
|
|
217
|
+
function: {
|
|
218
|
+
name: string;
|
|
219
|
+
description: string;
|
|
220
|
+
parameters: {
|
|
221
|
+
type: 'object';
|
|
222
|
+
properties: Record<string, unknown>;
|
|
223
|
+
required: string[];
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Anthropic tool format (derived from ToolDefinition)
|
|
229
|
+
*/
|
|
230
|
+
export interface AnthropicTool {
|
|
231
|
+
name: string;
|
|
232
|
+
description: string;
|
|
233
|
+
input_schema: {
|
|
234
|
+
type: 'object';
|
|
235
|
+
properties: Record<string, unknown>;
|
|
236
|
+
required: string[];
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Tool execution result with context
|
|
241
|
+
*/
|
|
242
|
+
export interface ToolExecutionResult {
|
|
243
|
+
/** Whether the tool executed successfully */
|
|
244
|
+
success: boolean;
|
|
245
|
+
/** Result content */
|
|
246
|
+
result: string;
|
|
247
|
+
/** Reminders to include in context */
|
|
248
|
+
reminders: string[];
|
|
249
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rich Tool Definition Types for ax-cli Tool System v3.0
|
|
3
|
+
*
|
|
4
|
+
* This file defines the comprehensive ToolDefinition interface that serves as
|
|
5
|
+
* the single source of truth for all tool metadata. OpenAI/Anthropic formats
|
|
6
|
+
* are DERIVED from these definitions, not the other way around.
|
|
7
|
+
*
|
|
8
|
+
* @see PRD-AX-CLI-TOOL-SYSTEM-V3-FINAL.md
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defai.digital/ax-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"sdkVersion": "1.3.0",
|
|
5
5
|
"description": "Enterprise-Class AI Command Line Interface - Primary support for GLM (General Language Model) with multi-provider AI orchestration powered by AutomatosX.",
|
|
6
6
|
"type": "module",
|