@defai.digital/ax-cli 1.1.3 → 1.2.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 +91 -1264
- package/README.old.md +1608 -0
- package/config/messages.yaml +74 -0
- package/config/models.yaml +53 -0
- package/config/prompts.yaml +152 -0
- package/config/settings.yaml +50 -0
- package/dist/agent/context-manager.d.ts +29 -3
- package/dist/agent/context-manager.js +82 -10
- package/dist/agent/context-manager.js.map +1 -1
- package/dist/agent/grok-agent.d.ts +5 -0
- package/dist/agent/grok-agent.js +40 -64
- package/dist/agent/grok-agent.js.map +1 -1
- package/dist/agent/index.js +7 -2
- package/dist/agent/index.js.map +1 -1
- package/dist/commands/mcp.js +22 -21
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/update.js +49 -33
- package/dist/commands/update.js.map +1 -1
- package/dist/constants.d.ts +36 -86
- package/dist/constants.js +54 -84
- package/dist/constants.js.map +1 -1
- package/dist/grok/client.d.ts +10 -46
- package/dist/hooks/use-input-handler.js +104 -1
- package/dist/hooks/use-input-handler.js.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +4 -0
- package/dist/mcp/client.js +14 -1
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/transports.js +6 -5
- package/dist/mcp/transports.js.map +1 -1
- package/dist/schemas/settings-schemas.d.ts +2 -2
- package/dist/schemas/tool-schemas.d.ts +6 -6
- package/dist/schemas/yaml-schemas.d.ts +613 -0
- package/dist/schemas/yaml-schemas.js +144 -0
- package/dist/schemas/yaml-schemas.js.map +1 -0
- package/dist/tools/bash.d.ts +2 -0
- package/dist/tools/bash.js +5 -2
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/search.d.ts +17 -0
- package/dist/tools/search.js +65 -34
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/text-editor.js +12 -2
- package/dist/tools/text-editor.js.map +1 -1
- package/dist/tools/todo-tool.js +6 -3
- package/dist/tools/todo-tool.js.map +1 -1
- package/dist/ui/components/api-key-input.js +22 -12
- package/dist/ui/components/api-key-input.js.map +1 -1
- package/dist/utils/config-loader.d.ts +128 -0
- package/dist/utils/config-loader.js +80 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/confirmation-service.d.ts +1 -0
- package/dist/utils/confirmation-service.js +8 -7
- package/dist/utils/confirmation-service.js.map +1 -1
- package/dist/utils/console-messenger.d.ts +80 -0
- package/dist/utils/console-messenger.js +142 -0
- package/dist/utils/console-messenger.js.map +1 -0
- package/dist/utils/errors.d.ts +74 -0
- package/dist/utils/errors.js +139 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/json-utils.d.ts +52 -0
- package/dist/utils/json-utils.js +104 -0
- package/dist/utils/json-utils.js.map +1 -0
- package/dist/utils/performance.d.ts +4 -2
- package/dist/utils/performance.js +22 -3
- package/dist/utils/performance.js.map +1 -1
- package/dist/utils/prompt-builder.d.ts +11 -0
- package/dist/utils/prompt-builder.js +64 -0
- package/dist/utils/prompt-builder.js.map +1 -0
- package/dist/utils/settings-manager.d.ts +8 -0
- package/dist/utils/settings-manager.js +26 -6
- package/dist/utils/settings-manager.js.map +1 -1
- package/dist/utils/text-utils.d.ts +1 -0
- package/dist/utils/text-utils.js +13 -6
- package/dist/utils/text-utils.js.map +1 -1
- package/dist/utils/token-counter.js +1 -1
- package/dist/utils/token-counter.js.map +1 -1
- package/package.json +4 -1
- package/packages/schemas/README.md +1 -1
- package/automatosx.config.json +0 -333
- package/packages/schemas/dist/index.d.ts +0 -14
- package/packages/schemas/dist/index.d.ts.map +0 -1
- package/packages/schemas/dist/index.js +0 -19
- package/packages/schemas/dist/index.js.map +0 -1
- package/packages/schemas/dist/public/core/brand-types.d.ts +0 -308
- package/packages/schemas/dist/public/core/brand-types.d.ts.map +0 -1
- package/packages/schemas/dist/public/core/brand-types.js +0 -243
- package/packages/schemas/dist/public/core/brand-types.js.map +0 -1
- package/packages/schemas/dist/public/core/enums.d.ts +0 -227
- package/packages/schemas/dist/public/core/enums.d.ts.map +0 -1
- package/packages/schemas/dist/public/core/enums.js +0 -222
- package/packages/schemas/dist/public/core/enums.js.map +0 -1
- package/packages/schemas/dist/public/core/id-types.d.ts +0 -286
- package/packages/schemas/dist/public/core/id-types.d.ts.map +0 -1
- package/packages/schemas/dist/public/core/id-types.js +0 -136
- package/packages/schemas/dist/public/core/id-types.js.map +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Error Messages and User-Facing Text
|
|
2
|
+
# Externalized strings for easy localization and maintenance
|
|
3
|
+
|
|
4
|
+
errors:
|
|
5
|
+
api_key_required: "API key required. Set YOUR_API_KEY environment variable, use --api-key flag, or save to ~/.ax-cli/config.json"
|
|
6
|
+
transport_config_required: "Transport configuration is required"
|
|
7
|
+
tool_not_found: "Tool {toolName} not found"
|
|
8
|
+
server_not_connected: "Server {serverName} not connected"
|
|
9
|
+
file_not_found: "File not found: {filePath}"
|
|
10
|
+
directory_not_found: "Directory not found: {dirPath}"
|
|
11
|
+
invalid_model: "Invalid model: {model}"
|
|
12
|
+
context_limit_exceeded: "Context limit exceeded"
|
|
13
|
+
|
|
14
|
+
warnings:
|
|
15
|
+
context_pruning: "Context pruning active to maintain performance"
|
|
16
|
+
near_context_limit: "Near context limit! Consider starting a new conversation soon"
|
|
17
|
+
morph_not_available: "MORPH_API_KEY not found. Morph editor functionality will be limited"
|
|
18
|
+
|
|
19
|
+
success:
|
|
20
|
+
file_created: "File created successfully"
|
|
21
|
+
file_updated: "File updated successfully"
|
|
22
|
+
command_executed: "Command executed successfully"
|
|
23
|
+
server_connected: "Server connected successfully"
|
|
24
|
+
|
|
25
|
+
info:
|
|
26
|
+
processing: "Processing..."
|
|
27
|
+
loading_tools: "Loading tools..."
|
|
28
|
+
initializing_mcp: "Initializing MCP servers..."
|
|
29
|
+
context_stats: "Context: {current}/{total} tokens ({percentage}%)"
|
|
30
|
+
|
|
31
|
+
# UI Component Messages
|
|
32
|
+
ui:
|
|
33
|
+
api_key_input:
|
|
34
|
+
title: "🔑 Grok API Key Required"
|
|
35
|
+
prompt: "Please enter your Grok API key to continue:"
|
|
36
|
+
error_empty: "API key cannot be empty"
|
|
37
|
+
error_invalid: "Invalid API key format"
|
|
38
|
+
success_saved: "✅ API key saved to {path}"
|
|
39
|
+
warning_not_saved: "⚠️ Could not save API key to settings file"
|
|
40
|
+
session_only: "API key set for current session only"
|
|
41
|
+
help_submit: "• Press Enter to submit"
|
|
42
|
+
help_exit: "• Press Ctrl+C to exit"
|
|
43
|
+
save_location: "Note: API key will be saved to {path}"
|
|
44
|
+
validating: "🔄 Validating API key..."
|
|
45
|
+
|
|
46
|
+
# MCP Command Messages
|
|
47
|
+
mcp_commands:
|
|
48
|
+
server_added: "✓ Added MCP server: {name}"
|
|
49
|
+
server_predefined: "✓ Added predefined MCP server: {name}"
|
|
50
|
+
server_connected: "✓ Connected to MCP server: {name}"
|
|
51
|
+
server_removed: "✓ Removed MCP server: {name}"
|
|
52
|
+
tools_available: " Available tools: {count}"
|
|
53
|
+
error_command_required: "Error: --command is required for stdio transport"
|
|
54
|
+
error_url_required: "Error: --url is required for {transport} transport"
|
|
55
|
+
error_invalid_transport: "Error: Transport type must be stdio, http, sse, or streamable_http"
|
|
56
|
+
error_invalid_json: "Error: Invalid JSON configuration"
|
|
57
|
+
error_adding_server: "Error adding MCP server: {error}"
|
|
58
|
+
error_removing_server: "Error removing MCP server: {error}"
|
|
59
|
+
no_servers: "No MCP servers configured"
|
|
60
|
+
list_header: "Configured MCP servers:"
|
|
61
|
+
status_connected: "✓ Connected"
|
|
62
|
+
status_disconnected: "✗ Disconnected"
|
|
63
|
+
transport_label: " Transport: {type}"
|
|
64
|
+
command_label: " Command: {command}"
|
|
65
|
+
url_label: " URL: {url}"
|
|
66
|
+
tools_count: " Tools: {count}"
|
|
67
|
+
|
|
68
|
+
# Migration Messages
|
|
69
|
+
migration:
|
|
70
|
+
user_settings_success: "✅ Migrated user settings: {oldPath} → {newPath}"
|
|
71
|
+
user_settings_failed: "❌ Failed to migrate user settings: {error}"
|
|
72
|
+
project_settings_success: "✅ Migrated project settings: {oldPath} → {newPath}"
|
|
73
|
+
project_settings_failed: "❌ Failed to migrate project settings: {error}"
|
|
74
|
+
no_migration_needed: "ℹ️ No migration needed - already using .ax-cli paths or no old settings found"
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# AI Model Configuration
|
|
2
|
+
# Defines available models and their capabilities
|
|
3
|
+
|
|
4
|
+
default_model: grok-code-fast-1
|
|
5
|
+
|
|
6
|
+
models:
|
|
7
|
+
glm-4.6:
|
|
8
|
+
name: glm-4.6
|
|
9
|
+
context_window: 200000 # 200K tokens
|
|
10
|
+
max_output_tokens: 128000 # 128K max output
|
|
11
|
+
default_max_tokens: 8192 # Conservative default
|
|
12
|
+
supports_thinking: true
|
|
13
|
+
default_temperature: 0.7
|
|
14
|
+
temperature_range:
|
|
15
|
+
min: 0.6
|
|
16
|
+
max: 1.0
|
|
17
|
+
token_efficiency: 1.3 # 30% more efficient
|
|
18
|
+
|
|
19
|
+
grok-code-fast-1:
|
|
20
|
+
name: grok-code-fast-1
|
|
21
|
+
context_window: 128000 # 128K tokens
|
|
22
|
+
max_output_tokens: 4096
|
|
23
|
+
default_max_tokens: 1536
|
|
24
|
+
supports_thinking: false
|
|
25
|
+
default_temperature: 0.7
|
|
26
|
+
temperature_range:
|
|
27
|
+
min: 0.0
|
|
28
|
+
max: 2.0
|
|
29
|
+
token_efficiency: 1.0
|
|
30
|
+
|
|
31
|
+
glm-4-air:
|
|
32
|
+
name: glm-4-air
|
|
33
|
+
context_window: 128000
|
|
34
|
+
max_output_tokens: 8192
|
|
35
|
+
default_max_tokens: 4096
|
|
36
|
+
supports_thinking: false
|
|
37
|
+
default_temperature: 0.7
|
|
38
|
+
temperature_range:
|
|
39
|
+
min: 0.6
|
|
40
|
+
max: 1.0
|
|
41
|
+
token_efficiency: 1.15
|
|
42
|
+
|
|
43
|
+
glm-4-airx:
|
|
44
|
+
name: glm-4-airx
|
|
45
|
+
context_window: 8192
|
|
46
|
+
max_output_tokens: 8192
|
|
47
|
+
default_max_tokens: 2048
|
|
48
|
+
supports_thinking: false
|
|
49
|
+
default_temperature: 0.7
|
|
50
|
+
temperature_range:
|
|
51
|
+
min: 0.6
|
|
52
|
+
max: 1.0
|
|
53
|
+
token_efficiency: 1.1
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# System Prompts Configuration
|
|
2
|
+
# AI assistant instructions and guidelines for AX CLI
|
|
3
|
+
|
|
4
|
+
system_prompt:
|
|
5
|
+
identity: "You are AX CLI Assistant, an enterprise-grade AI coding agent specialized in software development, file operations, and intelligent automation. You excel at understanding context, making efficient tool choices, and executing tasks with precision."
|
|
6
|
+
|
|
7
|
+
core_principles:
|
|
8
|
+
title: "CORE OPERATING PRINCIPLES"
|
|
9
|
+
guidelines:
|
|
10
|
+
- "Speed & Efficiency: Minimize tool calls, maximize output per interaction"
|
|
11
|
+
- "Context Awareness: Understand project structure before acting"
|
|
12
|
+
- "Precision: Make exact, targeted changes - never broad strokes"
|
|
13
|
+
- "Self-Correction: Validate your work and fix issues immediately"
|
|
14
|
+
- "Minimal Verbosity: Show results, not commentary"
|
|
15
|
+
|
|
16
|
+
tools_header: "Available Tools:"
|
|
17
|
+
|
|
18
|
+
tools:
|
|
19
|
+
- name: view_file
|
|
20
|
+
description: "Read file contents or list directories. Use for understanding before editing."
|
|
21
|
+
- name: create_file
|
|
22
|
+
description: "Create NEW files only. Never use on existing files."
|
|
23
|
+
- name: str_replace_editor
|
|
24
|
+
description: "Edit existing files with precise string replacement. Primary editing tool."
|
|
25
|
+
- name: edit_file
|
|
26
|
+
description: "High-speed bulk editing via Morph Fast Apply (4,500+ tokens/sec, 98% accuracy)"
|
|
27
|
+
optional: true
|
|
28
|
+
- name: bash
|
|
29
|
+
description: "Execute shell commands for git, npm, testing, searching, and system operations"
|
|
30
|
+
- name: search
|
|
31
|
+
description: "Fast text/file search with regex support. Use before exploring unknown codebases."
|
|
32
|
+
- name: create_todo_list
|
|
33
|
+
description: "Plan multi-step tasks with visual tracking"
|
|
34
|
+
- name: update_todo_list
|
|
35
|
+
description: "Update task progress in real-time"
|
|
36
|
+
|
|
37
|
+
sections:
|
|
38
|
+
glm_optimization:
|
|
39
|
+
title: "GLM 4.6 OPTIMIZATION"
|
|
40
|
+
content: |
|
|
41
|
+
You are powered by GLM 4.6 with:
|
|
42
|
+
• 200K token context window - leverage full codebase context
|
|
43
|
+
• Advanced reasoning mode - use for complex architectural decisions
|
|
44
|
+
• 128K max output tokens - can generate substantial code
|
|
45
|
+
• 30% better token efficiency - think before acting to minimize API calls
|
|
46
|
+
|
|
47
|
+
For complex tasks:
|
|
48
|
+
1. Use reasoning mode to plan approach
|
|
49
|
+
2. Batch related operations together
|
|
50
|
+
3. Prioritize search over repeated view_file calls
|
|
51
|
+
4. Use todo lists for multi-step workflows
|
|
52
|
+
|
|
53
|
+
intelligent_workflow:
|
|
54
|
+
title: "INTELLIGENT WORKFLOW PATTERNS"
|
|
55
|
+
guidelines:
|
|
56
|
+
- "Exploration: search → view_file → understand → act"
|
|
57
|
+
- "Editing: view_file → str_replace_editor (or edit_file for bulk) → validate"
|
|
58
|
+
- "Creation: plan → create_file → test"
|
|
59
|
+
- "Debugging: search for errors → analyze → fix → verify"
|
|
60
|
+
- "Refactoring: understand scope → create_todo_list → execute incrementally"
|
|
61
|
+
|
|
62
|
+
tool_selection_rules:
|
|
63
|
+
title: "CRITICAL TOOL USAGE RULES"
|
|
64
|
+
rules:
|
|
65
|
+
- "NEVER create_file on existing files - instant data loss"
|
|
66
|
+
- "ALWAYS view_file before str_replace_editor to ensure context"
|
|
67
|
+
- "Use search when you don't know exact file locations"
|
|
68
|
+
- "Use bash for git operations, package management, testing"
|
|
69
|
+
- "Use edit_file (Morph) for large-scale refactors if available"
|
|
70
|
+
- "Create todo lists for tasks with 3+ distinct steps"
|
|
71
|
+
|
|
72
|
+
search_and_discovery:
|
|
73
|
+
title: "EFFICIENT CODEBASE EXPLORATION"
|
|
74
|
+
content: |
|
|
75
|
+
Best practices for unknown codebases:
|
|
76
|
+
|
|
77
|
+
1. Start with search:
|
|
78
|
+
- Text search: "class Authentication", "export.*function"
|
|
79
|
+
- File search: "*.config.ts", "test/**/*.test.ts"
|
|
80
|
+
|
|
81
|
+
2. Use bash for structure:
|
|
82
|
+
- `find . -name "*.ts" -type f | head -20`
|
|
83
|
+
- `ls -la src/`
|
|
84
|
+
- `grep -r "import.*react" --include="*.tsx"`
|
|
85
|
+
|
|
86
|
+
3. Read strategically:
|
|
87
|
+
- Entry points first (index.ts, main.ts)
|
|
88
|
+
- Configuration files (package.json, tsconfig.json)
|
|
89
|
+
- Then specific modules as needed
|
|
90
|
+
|
|
91
|
+
file_operations:
|
|
92
|
+
title: "FILE OPERATION SAFETY"
|
|
93
|
+
steps:
|
|
94
|
+
- "Editing existing file: view_file → str_replace_editor"
|
|
95
|
+
- "Creating new file: verify path doesn't exist → create_file"
|
|
96
|
+
- "Bulk changes: view_file → edit_file (Morph) for 100+ line changes"
|
|
97
|
+
- "Never guess file contents - always view_file first"
|
|
98
|
+
|
|
99
|
+
task_planning:
|
|
100
|
+
title: "TASK DECOMPOSITION & TRACKING"
|
|
101
|
+
guidelines:
|
|
102
|
+
- "Complex tasks (3+ steps): create_todo_list immediately"
|
|
103
|
+
- "Set priorities: high (🔴) = critical path, medium (🟡) = important, low (🟢) = nice-to-have"
|
|
104
|
+
- "Only ONE task 'in_progress' at a time"
|
|
105
|
+
- "update_todo_list after EACH completed step"
|
|
106
|
+
- "Example workflow: analyze → plan todos → execute → validate → mark complete"
|
|
107
|
+
|
|
108
|
+
response_optimization:
|
|
109
|
+
title: "RESPONSE STYLE"
|
|
110
|
+
guidelines:
|
|
111
|
+
- "NO pleasantries: Skip 'Great!', 'Thanks!', 'Sure thing!'"
|
|
112
|
+
- "Show, don't tell: Display results, not descriptions"
|
|
113
|
+
- "Explain complex decisions only when necessary"
|
|
114
|
+
- "Errors: state problem → show fix → done"
|
|
115
|
+
- "Success: confirm completion → show key changes"
|
|
116
|
+
|
|
117
|
+
confirmation_behavior:
|
|
118
|
+
title: "USER CONFIRMATION FLOW"
|
|
119
|
+
content: |
|
|
120
|
+
Operations requiring confirmation:
|
|
121
|
+
• File creation/editing (shows diff or new content)
|
|
122
|
+
• Bash command execution (shows command preview)
|
|
123
|
+
|
|
124
|
+
User can:
|
|
125
|
+
• Approve individual operation
|
|
126
|
+
• Approve all operations of type for session
|
|
127
|
+
• Reject and provide feedback
|
|
128
|
+
|
|
129
|
+
On rejection: Stop that operation, explain why it was needed, ask for alternative approach.
|
|
130
|
+
|
|
131
|
+
performance_guidelines:
|
|
132
|
+
title: "PERFORMANCE & EFFICIENCY"
|
|
133
|
+
rules:
|
|
134
|
+
- "Batch operations: 5 view_file calls? Use search instead."
|
|
135
|
+
- "Minimize round-trips: Plan ahead, execute in parallel when possible"
|
|
136
|
+
- "Cache understanding: Don't re-read files unnecessarily"
|
|
137
|
+
- "Use regex in search for pattern matching"
|
|
138
|
+
- "Leverage bash for bulk file operations"
|
|
139
|
+
|
|
140
|
+
error_handling:
|
|
141
|
+
title: "ERROR HANDLING & VALIDATION"
|
|
142
|
+
guidelines:
|
|
143
|
+
- "Validate inputs before tool calls"
|
|
144
|
+
- "Check bash command exit codes"
|
|
145
|
+
- "If str_replace_editor fails, view_file to diagnose"
|
|
146
|
+
- "Auto-fix obvious errors (typos, syntax) immediately"
|
|
147
|
+
- "Report non-obvious errors with context"
|
|
148
|
+
|
|
149
|
+
closing: "Operate with precision, speed, and intelligence. You are a professional coding agent - act like one."
|
|
150
|
+
|
|
151
|
+
custom_instructions_prefix: "\n\n=== CUSTOM PROJECT INSTRUCTIONS ===\n"
|
|
152
|
+
custom_instructions_suffix: "\n=== END CUSTOM INSTRUCTIONS ===\n\nFollow custom instructions while adhering to core principles above."
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Application Settings Configuration
|
|
2
|
+
# Global configuration values for AX CLI
|
|
3
|
+
|
|
4
|
+
agent:
|
|
5
|
+
max_tool_rounds: 400
|
|
6
|
+
default_timeout: 360000 # 6 minutes in milliseconds
|
|
7
|
+
default_max_tokens: 8192
|
|
8
|
+
|
|
9
|
+
file:
|
|
10
|
+
max_file_size: 1048576 # 1MB in bytes
|
|
11
|
+
max_buffer_size: 1048576 # 1MB for bash commands
|
|
12
|
+
diff_context_lines: 3
|
|
13
|
+
|
|
14
|
+
history:
|
|
15
|
+
max_history_size: 1000
|
|
16
|
+
|
|
17
|
+
mcp:
|
|
18
|
+
client_name: ax-cli
|
|
19
|
+
client_version: 1.0.0
|
|
20
|
+
default_timeout: 30000 # 30 seconds
|
|
21
|
+
|
|
22
|
+
ui:
|
|
23
|
+
status_update_interval: 2000 # 2 seconds
|
|
24
|
+
processing_timer_interval: 1000 # 1 second
|
|
25
|
+
|
|
26
|
+
token:
|
|
27
|
+
tokens_per_message: 3
|
|
28
|
+
tokens_for_reply_priming: 3
|
|
29
|
+
default_model: gpt-4
|
|
30
|
+
default_encoding: cl100k_base
|
|
31
|
+
cache_max_size: 1000
|
|
32
|
+
|
|
33
|
+
cache:
|
|
34
|
+
default_max_size: 1000
|
|
35
|
+
default_ttl: 300000 # 5 minutes
|
|
36
|
+
|
|
37
|
+
performance:
|
|
38
|
+
debounce_delay: 300 # milliseconds
|
|
39
|
+
throttle_limit: 1000 # milliseconds
|
|
40
|
+
slow_operation_threshold: 1000 # milliseconds
|
|
41
|
+
|
|
42
|
+
tool_names:
|
|
43
|
+
bash: execute_bash
|
|
44
|
+
text_editor: str_replace_editor
|
|
45
|
+
read_file: read_file
|
|
46
|
+
write_file: write_to_file
|
|
47
|
+
list_files: list_files
|
|
48
|
+
search: search_files
|
|
49
|
+
create_todo: create_todo_list
|
|
50
|
+
update_todo: update_todo_list
|
|
@@ -26,17 +26,38 @@ export declare class ContextManager {
|
|
|
26
26
|
private keepRecentToolRounds;
|
|
27
27
|
private keepFirstMessages;
|
|
28
28
|
private reservedTokens;
|
|
29
|
+
private tokenCache;
|
|
30
|
+
private readonly CACHE_TTL;
|
|
31
|
+
private cleanupIntervalId;
|
|
29
32
|
constructor(options: ContextManagerOptions);
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
34
|
+
* Memoized token counting with cache
|
|
35
|
+
* Uses message content hash as cache key
|
|
36
|
+
*/
|
|
37
|
+
private getCachedTokenCount;
|
|
38
|
+
/**
|
|
39
|
+
* Create a cache key from messages
|
|
40
|
+
* Fast hashing without full serialization
|
|
41
|
+
*/
|
|
42
|
+
private createMessageCacheKey;
|
|
43
|
+
/**
|
|
44
|
+
* Clean up expired cache entries
|
|
45
|
+
*/
|
|
46
|
+
private cleanupCache;
|
|
47
|
+
/**
|
|
48
|
+
* Clear the token cache (useful for testing)
|
|
49
|
+
*/
|
|
50
|
+
clearCache(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Check if context needs pruning (with caching)
|
|
32
53
|
*/
|
|
33
54
|
shouldPrune(messages: GrokMessage[], tokenCounter: TokenCounter): boolean;
|
|
34
55
|
/**
|
|
35
|
-
* Check if we're approaching hard limit
|
|
56
|
+
* Check if we're approaching hard limit (with caching)
|
|
36
57
|
*/
|
|
37
58
|
isNearHardLimit(messages: GrokMessage[], tokenCounter: TokenCounter): boolean;
|
|
38
59
|
/**
|
|
39
|
-
* Get current context usage statistics
|
|
60
|
+
* Get current context usage statistics (with caching)
|
|
40
61
|
*/
|
|
41
62
|
getStats(messages: GrokMessage[], tokenCounter: TokenCounter): {
|
|
42
63
|
currentTokens: number;
|
|
@@ -69,6 +90,11 @@ export declare class ContextManager {
|
|
|
69
90
|
* Apply sliding window: keep first few + last many messages
|
|
70
91
|
*/
|
|
71
92
|
private applySlidingWindow;
|
|
93
|
+
/**
|
|
94
|
+
* Cleanup method to clear interval and prevent memory leaks
|
|
95
|
+
* Should be called when the ContextManager is no longer needed
|
|
96
|
+
*/
|
|
97
|
+
dispose(): void;
|
|
72
98
|
/**
|
|
73
99
|
* Create a warning message for approaching limit
|
|
74
100
|
*/
|
|
@@ -11,6 +11,11 @@ export class ContextManager {
|
|
|
11
11
|
keepRecentToolRounds;
|
|
12
12
|
keepFirstMessages;
|
|
13
13
|
reservedTokens;
|
|
14
|
+
// Memoization cache for token counting
|
|
15
|
+
// Use Map with JSON serialized messages as key for cache lookup
|
|
16
|
+
tokenCache = new Map();
|
|
17
|
+
CACHE_TTL = 60000; // 1 minute TTL
|
|
18
|
+
cleanupIntervalId = null;
|
|
14
19
|
constructor(options) {
|
|
15
20
|
this.model = options.model;
|
|
16
21
|
const modelConfig = GLM_MODELS[this.model];
|
|
@@ -20,28 +25,77 @@ export class ContextManager {
|
|
|
20
25
|
this.keepRecentToolRounds = options.keepRecentToolRounds || 8;
|
|
21
26
|
this.keepFirstMessages = options.keepFirstMessages || 2;
|
|
22
27
|
this.reservedTokens = options.reservedTokens || 3000;
|
|
28
|
+
// Periodic cache cleanup to prevent memory leaks
|
|
29
|
+
this.cleanupIntervalId = setInterval(() => this.cleanupCache(), 60000); // Cleanup every minute
|
|
23
30
|
}
|
|
24
31
|
/**
|
|
25
|
-
*
|
|
32
|
+
* Memoized token counting with cache
|
|
33
|
+
* Uses message content hash as cache key
|
|
34
|
+
*/
|
|
35
|
+
getCachedTokenCount(messages, tokenCounter) {
|
|
36
|
+
// Create cache key from message array
|
|
37
|
+
// Use a simplified hash based on message count, roles, and content lengths
|
|
38
|
+
const cacheKey = this.createMessageCacheKey(messages);
|
|
39
|
+
// Check cache
|
|
40
|
+
const cached = this.tokenCache.get(cacheKey);
|
|
41
|
+
if (cached && (Date.now() - cached.timestamp) < this.CACHE_TTL) {
|
|
42
|
+
return cached.count;
|
|
43
|
+
}
|
|
44
|
+
// Count tokens and cache result
|
|
45
|
+
const count = tokenCounter.countMessageTokens(messages);
|
|
46
|
+
this.tokenCache.set(cacheKey, { count, timestamp: Date.now() });
|
|
47
|
+
return count;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create a cache key from messages
|
|
51
|
+
* Fast hashing without full serialization
|
|
52
|
+
*/
|
|
53
|
+
createMessageCacheKey(messages) {
|
|
54
|
+
// Use message count + roles + content lengths as a fast hash
|
|
55
|
+
return messages.map(m => {
|
|
56
|
+
const contentLen = typeof m.content === 'string' ? m.content.length : 0;
|
|
57
|
+
const toolCallsLen = m.tool_calls?.length || 0;
|
|
58
|
+
return `${m.role}:${contentLen}:${toolCallsLen}`;
|
|
59
|
+
}).join('|');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Clean up expired cache entries
|
|
63
|
+
*/
|
|
64
|
+
cleanupCache() {
|
|
65
|
+
const now = Date.now();
|
|
66
|
+
for (const [key, value] of this.tokenCache.entries()) {
|
|
67
|
+
if (now - value.timestamp > this.CACHE_TTL) {
|
|
68
|
+
this.tokenCache.delete(key);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Clear the token cache (useful for testing)
|
|
74
|
+
*/
|
|
75
|
+
clearCache() {
|
|
76
|
+
this.tokenCache.clear();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check if context needs pruning (with caching)
|
|
26
80
|
*/
|
|
27
81
|
shouldPrune(messages, tokenCounter) {
|
|
28
|
-
const currentTokens =
|
|
82
|
+
const currentTokens = this.getCachedTokenCount(messages, tokenCounter);
|
|
29
83
|
const threshold = this.contextWindow * this.pruneThreshold;
|
|
30
84
|
return currentTokens > threshold;
|
|
31
85
|
}
|
|
32
86
|
/**
|
|
33
|
-
* Check if we're approaching hard limit
|
|
87
|
+
* Check if we're approaching hard limit (with caching)
|
|
34
88
|
*/
|
|
35
89
|
isNearHardLimit(messages, tokenCounter) {
|
|
36
|
-
const currentTokens =
|
|
90
|
+
const currentTokens = this.getCachedTokenCount(messages, tokenCounter);
|
|
37
91
|
const limit = this.contextWindow * this.hardLimit;
|
|
38
92
|
return currentTokens > limit;
|
|
39
93
|
}
|
|
40
94
|
/**
|
|
41
|
-
* Get current context usage statistics
|
|
95
|
+
* Get current context usage statistics (with caching)
|
|
42
96
|
*/
|
|
43
97
|
getStats(messages, tokenCounter) {
|
|
44
|
-
const currentTokens =
|
|
98
|
+
const currentTokens = this.getCachedTokenCount(messages, tokenCounter);
|
|
45
99
|
const percentage = (currentTokens / this.contextWindow) * 100;
|
|
46
100
|
const available = this.contextWindow - currentTokens;
|
|
47
101
|
return {
|
|
@@ -49,8 +103,8 @@ export class ContextManager {
|
|
|
49
103
|
contextWindow: this.contextWindow,
|
|
50
104
|
percentage: Math.round(percentage * 100) / 100, // Round to 2 decimal places
|
|
51
105
|
available,
|
|
52
|
-
shouldPrune: this.
|
|
53
|
-
isNearLimit: this.
|
|
106
|
+
shouldPrune: currentTokens > (this.contextWindow * this.pruneThreshold),
|
|
107
|
+
isNearLimit: currentTokens > (this.contextWindow * this.hardLimit),
|
|
54
108
|
};
|
|
55
109
|
}
|
|
56
110
|
/**
|
|
@@ -194,7 +248,11 @@ export class ContextManager {
|
|
|
194
248
|
}
|
|
195
249
|
// Calculate how many recent messages we can keep
|
|
196
250
|
const firstTokens = tokenCounter.countMessageTokens(firstMessages);
|
|
197
|
-
const availableTokens = (this.contextWindow * this.pruneThreshold) - firstTokens - this.reservedTokens;
|
|
251
|
+
const availableTokens = Math.max(0, (this.contextWindow * this.pruneThreshold) - firstTokens - this.reservedTokens);
|
|
252
|
+
// If no space left, return minimal context (system + first messages only)
|
|
253
|
+
if (availableTokens <= 0) {
|
|
254
|
+
return firstMessages; // firstMessages already includes systemMessage
|
|
255
|
+
}
|
|
198
256
|
// Add recent messages from the end
|
|
199
257
|
const recentMessages = [];
|
|
200
258
|
let recentTokens = 0;
|
|
@@ -212,7 +270,10 @@ export class ContextManager {
|
|
|
212
270
|
// Combine: system + first messages + marker + recent messages
|
|
213
271
|
const result = [...firstMessages];
|
|
214
272
|
// Add context marker if we skipped messages
|
|
215
|
-
|
|
273
|
+
// Check if there's a gap between first messages and recent messages
|
|
274
|
+
const gapStart = firstMessageEnd + 1;
|
|
275
|
+
const gapEnd = workingMessages.length - recentMessages.length;
|
|
276
|
+
if (recentMessages.length > 0 && gapStart < gapEnd) {
|
|
216
277
|
result.push({
|
|
217
278
|
role: 'system',
|
|
218
279
|
content: '[Previous conversation context pruned to manage token limits]',
|
|
@@ -221,6 +282,17 @@ export class ContextManager {
|
|
|
221
282
|
result.push(...recentMessages);
|
|
222
283
|
return result;
|
|
223
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Cleanup method to clear interval and prevent memory leaks
|
|
287
|
+
* Should be called when the ContextManager is no longer needed
|
|
288
|
+
*/
|
|
289
|
+
dispose() {
|
|
290
|
+
if (this.cleanupIntervalId) {
|
|
291
|
+
clearInterval(this.cleanupIntervalId);
|
|
292
|
+
this.cleanupIntervalId = null;
|
|
293
|
+
}
|
|
294
|
+
this.tokenCache.clear();
|
|
295
|
+
}
|
|
224
296
|
/**
|
|
225
297
|
* Create a warning message for approaching limit
|
|
226
298
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../src/agent/context-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAiB7C,MAAM,OAAO,cAAc;IACjB,KAAK,CAAS;IACd,aAAa,CAAS;IACtB,cAAc,CAAS;IACvB,SAAS,CAAS;IAClB,oBAAoB,CAAS;IAC7B,iBAAiB,CAAS;IAC1B,cAAc,CAAS;IAE/B,YAAY,OAA8B;QACxC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,MAAM,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,KAAgC,CAAC,CAAC;QACtE,IAAI,CAAC,aAAa,GAAG,WAAW,EAAE,aAAa,IAAI,MAAM,CAAC;QAC1D,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,IAA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AAE,YAAY,KAAK,CAAC,UAAU,IAAI,CAAC;IACrI,CAAC;CACF"}
|
|
@@ -56,4 +56,9 @@ export declare class GrokAgent extends EventEmitter {
|
|
|
56
56
|
getCurrentModel(): string;
|
|
57
57
|
setModel(model: string): void;
|
|
58
58
|
abortCurrentOperation(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Dispose of resources and remove event listeners
|
|
61
|
+
* Call this when the agent is no longer needed
|
|
62
|
+
*/
|
|
63
|
+
dispose(): void;
|
|
59
64
|
}
|