@zds-ai/cli 0.1.7 → 0.1.10
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 +387 -34
- package/dist/agent/context-manager.d.ts +70 -0
- package/dist/agent/context-manager.js +138 -0
- package/dist/agent/context-manager.js.map +1 -0
- package/dist/agent/hook-manager.d.ts +194 -0
- package/dist/agent/hook-manager.js +676 -0
- package/dist/agent/hook-manager.js.map +1 -0
- package/dist/agent/llm-agent.d.ts +470 -100
- package/dist/agent/llm-agent.js +788 -1576
- package/dist/agent/llm-agent.js.map +1 -1
- package/dist/agent/message-processor.d.ts +103 -0
- package/dist/agent/message-processor.js +225 -0
- package/dist/agent/message-processor.js.map +1 -0
- package/dist/agent/prompt-variables.d.ts +113 -40
- package/dist/agent/prompt-variables.js +272 -81
- package/dist/agent/prompt-variables.js.map +1 -1
- package/dist/agent/session-manager.d.ts +75 -0
- package/dist/agent/session-manager.js +194 -0
- package/dist/agent/session-manager.js.map +1 -0
- package/dist/agent/streaming-agent.d.ts +33 -0
- package/dist/agent/streaming-agent.js +629 -0
- package/dist/agent/streaming-agent.js.map +1 -0
- package/dist/agent/tool-executor.d.ts +111 -0
- package/dist/agent/tool-executor.js +397 -0
- package/dist/agent/tool-executor.js.map +1 -0
- package/dist/bin/encode-speech.sh +64 -0
- package/dist/bin/extract-text.sh +66 -0
- package/dist/bin/generate_image_sd.sh +23 -12
- package/dist/bin/joycaption.sh +37 -0
- package/dist/bin/talking-agents.sh +291 -0
- package/dist/grok/client.d.ts +54 -0
- package/dist/grok/client.js +173 -20
- package/dist/grok/client.js.map +1 -1
- package/dist/grok/tools.js +98 -11
- package/dist/grok/tools.js.map +1 -1
- package/dist/hooks/use-enhanced-input.js +3 -1
- package/dist/hooks/use-enhanced-input.js.map +1 -1
- package/dist/hooks/use-input-handler.d.ts +1 -1
- package/dist/hooks/use-input-handler.js +101 -8
- package/dist/hooks/use-input-handler.js.map +1 -1
- package/dist/index.js +25 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp/config.d.ts +1 -0
- package/dist/mcp/config.js +45 -7
- package/dist/mcp/config.js.map +1 -1
- package/dist/tools/audio-tool.d.ts +13 -0
- package/dist/tools/audio-tool.js +55 -0
- package/dist/tools/audio-tool.js.map +1 -0
- package/dist/tools/character-tool.js +13 -1
- package/dist/tools/character-tool.js.map +1 -1
- package/dist/tools/image-tool.d.ts +21 -1
- package/dist/tools/image-tool.js +201 -14
- package/dist/tools/image-tool.js.map +1 -1
- package/dist/tools/index.d.ts +11 -10
- package/dist/tools/index.js +11 -10
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/introspect-tool.js +325 -2
- package/dist/tools/introspect-tool.js.map +1 -1
- package/dist/tools/morph-editor.d.ts +21 -9
- package/dist/tools/morph-editor.js +21 -9
- package/dist/tools/morph-editor.js.map +1 -1
- package/dist/ui/components/active-task-status.d.ts +1 -1
- package/dist/ui/components/api-key-input.d.ts +1 -1
- package/dist/ui/components/backend-status.d.ts +1 -1
- package/dist/ui/components/chat-history.d.ts +1 -1
- package/dist/ui/components/chat-input.js +1 -1
- package/dist/ui/components/chat-input.js.map +1 -1
- package/dist/ui/components/chat-interface.d.ts +1 -1
- package/dist/ui/components/chat-interface.js +2 -2
- package/dist/ui/components/chat-interface.js.map +1 -1
- package/dist/ui/components/context-status.d.ts +1 -1
- package/dist/ui/components/mood-status.d.ts +1 -1
- package/dist/ui/components/persona-status.d.ts +1 -1
- package/dist/ui/utils/markdown-renderer.js +2 -2
- package/dist/utils/chat-history-manager.d.ts +12 -4
- package/dist/utils/chat-history-manager.js +26 -11
- package/dist/utils/chat-history-manager.js.map +1 -1
- package/dist/utils/hook-executor.d.ts +53 -2
- package/dist/utils/hook-executor.js +261 -39
- package/dist/utils/hook-executor.js.map +1 -1
- package/dist/utils/path-utils.d.ts +2 -1
- package/dist/utils/path-utils.js +25 -4
- package/dist/utils/path-utils.js.map +1 -1
- package/dist/utils/rephrase-handler.d.ts +1 -1
- package/dist/utils/settings-manager.d.ts +41 -11
- package/dist/utils/settings-manager.js +172 -40
- package/dist/utils/settings-manager.js.map +1 -1
- package/dist/utils/slash-commands.d.ts +3 -3
- package/dist/utils/slash-commands.js +11 -5
- package/dist/utils/slash-commands.js.map +1 -1
- package/dist/utils/startup-hook.js +9 -2
- package/dist/utils/startup-hook.js.map +1 -1
- package/package.json +29 -24
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LLMToolCall } from "../grok/client.js";
|
|
2
2
|
import type { ChatCompletionContentPart } from "openai/resources/chat/completions.js";
|
|
3
3
|
import { ToolResult } from "../types/index.js";
|
|
4
4
|
import { EventEmitter } from "events";
|
|
5
|
+
import { SessionState } from "../utils/chat-history-manager.js";
|
|
6
|
+
/**
|
|
7
|
+
* Represents a single entry in the conversation history.
|
|
8
|
+
* Supports various message types including user messages, assistant responses,
|
|
9
|
+
* tool calls, tool results, and system messages.
|
|
10
|
+
*/
|
|
5
11
|
export interface ChatEntry {
|
|
6
12
|
type: "user" | "assistant" | "tool_result" | "tool_call" | "system";
|
|
7
13
|
content?: string | ChatCompletionContentPart[];
|
|
@@ -22,6 +28,10 @@ export interface ChatEntry {
|
|
|
22
28
|
[key: string]: any;
|
|
23
29
|
};
|
|
24
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Represents a chunk of data in the streaming response.
|
|
33
|
+
* Used for real-time communication between the agent and UI components.
|
|
34
|
+
*/
|
|
25
35
|
export interface StreamingChunk {
|
|
26
36
|
type: "content" | "tool_calls" | "tool_result" | "done" | "token_count" | "user_message";
|
|
27
37
|
content?: string;
|
|
@@ -32,6 +42,60 @@ export interface StreamingChunk {
|
|
|
32
42
|
userEntry?: ChatEntry;
|
|
33
43
|
systemMessages?: ChatEntry[];
|
|
34
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Main LLM Agent class that orchestrates AI conversations with tool execution capabilities.
|
|
47
|
+
*
|
|
48
|
+
* ## Architecture Overview
|
|
49
|
+
*
|
|
50
|
+
* The LLMAgent serves as the central coordinator for AI-powered conversations, managing:
|
|
51
|
+
* - **Conversation Flow**: Handles user messages, AI responses, and multi-turn conversations
|
|
52
|
+
* - **Tool Execution**: Coordinates with various tools (file editing, shell commands, web search, etc.)
|
|
53
|
+
* - **Context Management**: Tracks conversation history and manages token limits
|
|
54
|
+
* - **Session State**: Maintains persona, mood, active tasks, and other session data
|
|
55
|
+
* - **Streaming Support**: Provides real-time response streaming for better UX
|
|
56
|
+
*
|
|
57
|
+
* ## Delegation Architecture
|
|
58
|
+
*
|
|
59
|
+
* The agent delegates specialized functionality to focused manager classes:
|
|
60
|
+
* - **ToolExecutor**: Handles all tool execution, validation, and approval workflows
|
|
61
|
+
* - **HookManager**: Manages persona/mood/task hooks and backend testing
|
|
62
|
+
* - **SessionManager**: Handles session persistence and state restoration
|
|
63
|
+
* - **MessageProcessor**: Processes user input, handles rephrasing, and XML parsing
|
|
64
|
+
* - **ContextManager**: Manages context warnings, compaction, and token tracking
|
|
65
|
+
*
|
|
66
|
+
* ## Key Features
|
|
67
|
+
*
|
|
68
|
+
* - **Multi-Model Support**: Works with various LLM backends (Grok, OpenAI, etc.)
|
|
69
|
+
* - **Tool Integration**: Seamlessly integrates with 15+ built-in tools
|
|
70
|
+
* - **MCP Support**: Extends capabilities via Model Context Protocol servers
|
|
71
|
+
* - **Vision Support**: Handles image inputs for vision-capable models
|
|
72
|
+
* - **Streaming Responses**: Real-time response generation with token counting
|
|
73
|
+
* - **Context Awareness**: Intelligent context management and automatic compaction
|
|
74
|
+
* - **Hook System**: Extensible hook system for custom behaviors
|
|
75
|
+
* - **Session Persistence**: Maintains conversation state across restarts
|
|
76
|
+
*
|
|
77
|
+
* ## Usage Patterns
|
|
78
|
+
*
|
|
79
|
+
* ```typescript
|
|
80
|
+
* // Initialize agent
|
|
81
|
+
* const agent = new LLMAgent(apiKey, baseURL, model);
|
|
82
|
+
* await agent.initialize();
|
|
83
|
+
*
|
|
84
|
+
* // Process messages (non-streaming)
|
|
85
|
+
* const entries = await agent.processUserMessage("Hello, world!");
|
|
86
|
+
*
|
|
87
|
+
* // Process messages (streaming)
|
|
88
|
+
* for await (const chunk of agent.processUserMessageStream("Write a file")) {
|
|
89
|
+
* console.log(chunk);
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* // Manage session state
|
|
93
|
+
* await agent.setPersona("helpful assistant");
|
|
94
|
+
* await agent.startActiveTask("coding", "writing tests");
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @extends EventEmitter Emits 'contextChange' events for token usage updates
|
|
98
|
+
*/
|
|
35
99
|
export declare class LLMAgent extends EventEmitter {
|
|
36
100
|
private llmClient;
|
|
37
101
|
private textEditor;
|
|
@@ -48,6 +112,7 @@ export declare class LLMAgent extends EventEmitter {
|
|
|
48
112
|
private imageTool;
|
|
49
113
|
private fileConversionTool;
|
|
50
114
|
private restartTool;
|
|
115
|
+
private audioTool;
|
|
51
116
|
private chatHistory;
|
|
52
117
|
private messages;
|
|
53
118
|
private tokenCounter;
|
|
@@ -57,8 +122,6 @@ export declare class LLMAgent extends EventEmitter {
|
|
|
57
122
|
private temperature;
|
|
58
123
|
private maxTokens;
|
|
59
124
|
private firstMessageProcessed;
|
|
60
|
-
private contextWarningAt80;
|
|
61
|
-
private contextWarningAt90;
|
|
62
125
|
private persona;
|
|
63
126
|
private personaColor;
|
|
64
127
|
private mood;
|
|
@@ -69,72 +132,314 @@ export declare class LLMAgent extends EventEmitter {
|
|
|
69
132
|
private apiKeyEnvVar;
|
|
70
133
|
private pendingContextEditSession;
|
|
71
134
|
private rephraseState;
|
|
72
|
-
private
|
|
135
|
+
private toolExecutor;
|
|
136
|
+
private hookManager;
|
|
137
|
+
private sessionManager;
|
|
138
|
+
private messageProcessor;
|
|
139
|
+
private contextManager;
|
|
140
|
+
private maxContextSize;
|
|
141
|
+
/**
|
|
142
|
+
* Cleans up incomplete tool calls in the message history.
|
|
143
|
+
* Ensures all tool calls have corresponding tool results to prevent API errors.
|
|
144
|
+
*
|
|
145
|
+
* This method scans the last assistant message for tool calls and adds
|
|
146
|
+
* "[Cancelled by user]" results for any tool calls that don't have results.
|
|
147
|
+
*
|
|
148
|
+
* @private
|
|
149
|
+
*/
|
|
150
|
+
private cleanupIncompleteToolCalls;
|
|
151
|
+
/**
|
|
152
|
+
* Executes the instance hook if it hasn't been run yet.
|
|
153
|
+
*
|
|
154
|
+
* The instance hook runs once per agent session and can:
|
|
155
|
+
* - Set prompt variables
|
|
156
|
+
* - Add system messages
|
|
157
|
+
* - Provide prefill text for responses
|
|
158
|
+
*
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
private executeInstanceHookIfNeeded;
|
|
162
|
+
/**
|
|
163
|
+
* Creates a new LLMAgent instance.
|
|
164
|
+
*
|
|
165
|
+
* @param apiKey - API key for the LLM service
|
|
166
|
+
* @param baseURL - Optional base URL for the API endpoint
|
|
167
|
+
* @param model - Optional model name (defaults to saved model or "grok-code-fast-1")
|
|
168
|
+
* @param maxToolRounds - Maximum number of tool execution rounds (default: 400)
|
|
169
|
+
* @param debugLogFile - Optional path for MCP debug logging
|
|
170
|
+
* @param startupHookOutput - Optional output from startup hook execution
|
|
171
|
+
* @param temperature - Optional temperature for API requests (0.0-2.0)
|
|
172
|
+
* @param maxTokens - Optional maximum tokens for API responses
|
|
173
|
+
*/
|
|
73
174
|
constructor(apiKey: string, baseURL?: string, model?: string, maxToolRounds?: number, debugLogFile?: string, startupHookOutput?: string, temperature?: number, maxTokens?: number);
|
|
74
175
|
private startupHookOutput?;
|
|
75
176
|
private systemPrompt;
|
|
76
177
|
private hasRunInstanceHook;
|
|
77
178
|
/**
|
|
78
|
-
* Initialize the agent with dynamic system prompt
|
|
79
|
-
*
|
|
179
|
+
* Initialize the agent with dynamic system prompt.
|
|
180
|
+
*
|
|
181
|
+
* This method must be called after construction to:
|
|
182
|
+
* - Build the system message with current tool availability
|
|
183
|
+
* - Set up the initial conversation context
|
|
184
|
+
* - Execute the instance hook if configured
|
|
185
|
+
*
|
|
186
|
+
* @throws {Error} If system message generation fails
|
|
80
187
|
*/
|
|
81
188
|
initialize(): Promise<void>;
|
|
82
189
|
/**
|
|
83
|
-
* Build/rebuild the system message with current tool availability
|
|
84
|
-
*
|
|
190
|
+
* Build/rebuild the system message with current tool availability.
|
|
191
|
+
*
|
|
192
|
+
* This method:
|
|
193
|
+
* - Generates a dynamic tool list using the introspect tool
|
|
194
|
+
* - Sets the APP:TOOLS variable for template rendering
|
|
195
|
+
* - Renders the full SYSTEM template with all variables
|
|
196
|
+
* - Updates messages[0] with the new system prompt
|
|
197
|
+
*
|
|
198
|
+
* The system prompt is always at messages[0] and contains the core
|
|
199
|
+
* instructions, tool descriptions, and current context information.
|
|
85
200
|
*/
|
|
86
201
|
buildSystemMessage(): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Render system message with current variable state
|
|
204
|
+
* Called before LLM API calls and task processing to ensure fresh content
|
|
205
|
+
*/
|
|
206
|
+
renderSystemMessage(): void;
|
|
207
|
+
/**
|
|
208
|
+
* Load initial conversation history from persistence.
|
|
209
|
+
*
|
|
210
|
+
* This method:
|
|
211
|
+
* - Loads the chat history (excluding system messages)
|
|
212
|
+
* - Sets or generates the system prompt
|
|
213
|
+
* - Converts history to API message format
|
|
214
|
+
* - Handles tool call/result matching
|
|
215
|
+
* - Updates token counts
|
|
216
|
+
*
|
|
217
|
+
* @param history - Array of chat entries to load
|
|
218
|
+
* @param systemPrompt - Optional system prompt (will generate if not provided)
|
|
219
|
+
*/
|
|
87
220
|
loadInitialHistory(history: ChatEntry[], systemPrompt?: string): Promise<void>;
|
|
221
|
+
/**
|
|
222
|
+
* Initialize Model Context Protocol (MCP) servers in the background.
|
|
223
|
+
*
|
|
224
|
+
* This method loads MCP configuration and initializes any configured
|
|
225
|
+
* servers without blocking agent construction. Errors are logged but
|
|
226
|
+
* don't prevent agent operation.
|
|
227
|
+
*
|
|
228
|
+
* @param debugLogFile - Optional path for MCP debug output
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
88
231
|
private initializeMCP;
|
|
232
|
+
/**
|
|
233
|
+
* Checks if the current model is a Grok model.
|
|
234
|
+
* Used to enable Grok-specific features like web search.
|
|
235
|
+
*
|
|
236
|
+
* @returns True if the current model name contains "grok"
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
89
239
|
private isGrokModel;
|
|
240
|
+
/**
|
|
241
|
+
* Heuristic to determine if web search should be enabled for a message.
|
|
242
|
+
*
|
|
243
|
+
* Analyzes the message content for keywords that suggest the user is
|
|
244
|
+
* asking for current information, news, or time-sensitive data.
|
|
245
|
+
*
|
|
246
|
+
* @param message - The user message to analyze
|
|
247
|
+
* @returns True if web search should be enabled
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
90
250
|
private shouldUseSearchFor;
|
|
251
|
+
/**
|
|
252
|
+
* Process a user message and return all conversation entries generated.
|
|
253
|
+
*
|
|
254
|
+
* This is the main non-streaming message processing method that:
|
|
255
|
+
* - Handles rephrase commands and message preprocessing
|
|
256
|
+
* - Manages the agent loop with tool execution
|
|
257
|
+
* - Processes multiple rounds of AI responses and tool calls
|
|
258
|
+
* - Handles errors and context management
|
|
259
|
+
* - Returns all new conversation entries
|
|
260
|
+
*
|
|
261
|
+
* ## Processing Flow
|
|
262
|
+
*
|
|
263
|
+
* 1. **Setup**: Parse rephrase commands, clean incomplete tool calls
|
|
264
|
+
* 2. **Message Processing**: Parse images, assemble content, add to history
|
|
265
|
+
* 3. **Agent Loop**: Continue until no more tool calls or max rounds reached
|
|
266
|
+
* - Get AI response
|
|
267
|
+
* - Execute any tool calls
|
|
268
|
+
* - Add results to conversation
|
|
269
|
+
* - Get next response if needed
|
|
270
|
+
* 4. **Cleanup**: Handle errors, update context, return entries
|
|
271
|
+
*
|
|
272
|
+
* @param message - The user message to process
|
|
273
|
+
* @returns Promise resolving to array of new conversation entries
|
|
274
|
+
* @throws {Error} If message processing fails critically
|
|
275
|
+
*/
|
|
91
276
|
processUserMessage(message: string): Promise<ChatEntry[]>;
|
|
92
277
|
/**
|
|
93
|
-
*
|
|
94
|
-
*
|
|
278
|
+
* Process a user message with real-time streaming response.
|
|
279
|
+
*
|
|
280
|
+
* This is the main streaming message processing method that yields
|
|
281
|
+
* chunks of data as the conversation progresses. Provides real-time
|
|
282
|
+
* updates for:
|
|
283
|
+
* - User message processing
|
|
284
|
+
* - AI response streaming (content as it's generated)
|
|
285
|
+
* - Tool execution progress
|
|
286
|
+
* - Token count updates
|
|
287
|
+
* - System messages from hooks
|
|
288
|
+
*
|
|
289
|
+
* ## Streaming Flow
|
|
290
|
+
*
|
|
291
|
+
* 1. **Setup**: Process user message, yield user entry
|
|
292
|
+
* 2. **Agent Loop**: Stream AI responses and execute tools
|
|
293
|
+
* - Stream AI response content in real-time
|
|
294
|
+
* - Yield tool calls when detected
|
|
295
|
+
* - Execute tools and yield results
|
|
296
|
+
* - Continue until completion
|
|
297
|
+
* 3. **Completion**: Yield final token counts and done signal
|
|
298
|
+
*
|
|
299
|
+
* ## Chunk Types
|
|
300
|
+
*
|
|
301
|
+
* - `user_message`: Initial user message entry
|
|
302
|
+
* - `content`: Streaming AI response content
|
|
303
|
+
* - `tool_calls`: Tool calls detected in AI response
|
|
304
|
+
* - `tool_result`: Results from tool execution
|
|
305
|
+
* - `token_count`: Updated token usage
|
|
306
|
+
* - `done`: Processing complete
|
|
307
|
+
*
|
|
308
|
+
* @param message - The user message to process
|
|
309
|
+
* @yields StreamingChunk objects with real-time updates
|
|
310
|
+
* @throws {Error} If streaming fails critically
|
|
95
311
|
*/
|
|
96
|
-
private parseXMLToolCalls;
|
|
97
|
-
private messageReducer;
|
|
98
312
|
processUserMessageStream(message: string): AsyncGenerator<StreamingChunk, void, unknown>;
|
|
99
313
|
/**
|
|
100
314
|
* Apply default parameter values for tools
|
|
101
315
|
* This ensures the approval hook sees the same parameters that will be used during execution
|
|
102
316
|
*/
|
|
103
|
-
private applyToolParameterDefaults;
|
|
104
317
|
/**
|
|
105
318
|
* Validate tool arguments against the tool's schema
|
|
106
319
|
* Returns null if valid, or an error message if invalid
|
|
107
320
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Get a copy of the current chat history.
|
|
323
|
+
* @returns Array of chat entries (defensive copy)
|
|
324
|
+
*/
|
|
111
325
|
getChatHistory(): ChatEntry[];
|
|
326
|
+
/**
|
|
327
|
+
* Set the chat history to a new array of entries.
|
|
328
|
+
* @param history - New chat history entries
|
|
329
|
+
*/
|
|
112
330
|
setChatHistory(history: ChatEntry[]): void;
|
|
331
|
+
/**
|
|
332
|
+
* Get the current system prompt.
|
|
333
|
+
* @returns The system prompt string
|
|
334
|
+
*/
|
|
113
335
|
getSystemPrompt(): string;
|
|
336
|
+
/**
|
|
337
|
+
* Set a new system prompt and update the first message.
|
|
338
|
+
* @param prompt - Ignored (deprecated) - system prompt is always rendered from variables
|
|
339
|
+
*/
|
|
114
340
|
setSystemPrompt(prompt: string): void;
|
|
341
|
+
/**
|
|
342
|
+
* Get a copy of the current API messages array.
|
|
343
|
+
* @returns Array of LLM messages (defensive copy)
|
|
344
|
+
*/
|
|
115
345
|
getMessages(): any[];
|
|
346
|
+
/**
|
|
347
|
+
* Get the current token count for the conversation.
|
|
348
|
+
* @returns Number of tokens in the current message context
|
|
349
|
+
*/
|
|
116
350
|
getCurrentTokenCount(): number;
|
|
351
|
+
/**
|
|
352
|
+
* Get the maximum context size for the current model.
|
|
353
|
+
* @returns Maximum number of tokens supported
|
|
354
|
+
* @todo Make this model-specific for different context windows
|
|
355
|
+
*/
|
|
117
356
|
getMaxContextSize(): number;
|
|
357
|
+
/**
|
|
358
|
+
* Get the current context usage as a percentage.
|
|
359
|
+
* @returns Percentage of context window used (0-100)
|
|
360
|
+
*/
|
|
118
361
|
getContextUsagePercent(): number;
|
|
119
362
|
/**
|
|
120
|
-
* Convert context
|
|
363
|
+
* Convert the conversation context to markdown format for viewing.
|
|
364
|
+
*
|
|
365
|
+
* Creates a human-readable markdown representation of the conversation
|
|
366
|
+
* including:
|
|
367
|
+
* - Header with context file path and token usage
|
|
368
|
+
* - Numbered messages with timestamps
|
|
369
|
+
* - Formatted tool calls and results
|
|
370
|
+
* - Proper attribution (User/Assistant/System)
|
|
371
|
+
*
|
|
121
372
|
* Format: (N) Name (role) - timestamp
|
|
373
|
+
*
|
|
374
|
+
* @returns Promise resolving to markdown-formatted conversation
|
|
122
375
|
*/
|
|
123
376
|
convertContextToMarkdown(): Promise<string>;
|
|
377
|
+
/**
|
|
378
|
+
* Get the current persona setting.
|
|
379
|
+
* @returns Current persona string
|
|
380
|
+
*/
|
|
124
381
|
getPersona(): string;
|
|
382
|
+
/**
|
|
383
|
+
* Get the current persona display color.
|
|
384
|
+
* @returns Color name for persona display
|
|
385
|
+
*/
|
|
125
386
|
getPersonaColor(): string;
|
|
387
|
+
/**
|
|
388
|
+
* Get the current mood setting.
|
|
389
|
+
* @returns Current mood string
|
|
390
|
+
*/
|
|
126
391
|
getMood(): string;
|
|
392
|
+
/**
|
|
393
|
+
* Get the current mood display color.
|
|
394
|
+
* @returns Color name for mood display
|
|
395
|
+
*/
|
|
127
396
|
getMoodColor(): string;
|
|
397
|
+
/**
|
|
398
|
+
* Get the current active task.
|
|
399
|
+
* @returns Current active task string
|
|
400
|
+
*/
|
|
128
401
|
getActiveTask(): string;
|
|
402
|
+
/**
|
|
403
|
+
* Get the current active task action.
|
|
404
|
+
* @returns Current task action string
|
|
405
|
+
*/
|
|
129
406
|
getActiveTaskAction(): string;
|
|
407
|
+
/**
|
|
408
|
+
* Get the current active task display color.
|
|
409
|
+
* @returns Color name for task display
|
|
410
|
+
*/
|
|
130
411
|
getActiveTaskColor(): string;
|
|
412
|
+
/**
|
|
413
|
+
* Set a pending context edit session for file-based context editing.
|
|
414
|
+
* @param tmpJsonPath - Path to temporary JSON file
|
|
415
|
+
* @param contextFilePath - Path to actual context file
|
|
416
|
+
*/
|
|
131
417
|
setPendingContextEditSession(tmpJsonPath: string, contextFilePath: string): void;
|
|
418
|
+
/**
|
|
419
|
+
* Get the current pending context edit session.
|
|
420
|
+
* @returns Edit session info or null if none pending
|
|
421
|
+
*/
|
|
132
422
|
getPendingContextEditSession(): {
|
|
133
423
|
tmpJsonPath: string;
|
|
134
424
|
contextFilePath: string;
|
|
135
425
|
} | null;
|
|
426
|
+
/**
|
|
427
|
+
* Clear the pending context edit session.
|
|
428
|
+
*/
|
|
136
429
|
clearPendingContextEditSession(): void;
|
|
430
|
+
/**
|
|
431
|
+
* Set the rephrase state for message editing operations.
|
|
432
|
+
* @param originalAssistantMessageIndex - Index of original assistant message
|
|
433
|
+
* @param rephraseRequestIndex - Index of rephrase request
|
|
434
|
+
* @param newResponseIndex - Index of new response (-1 if not yet created)
|
|
435
|
+
* @param messageType - Type of message being rephrased
|
|
436
|
+
* @param prefillText - Optional prefill text for the response
|
|
437
|
+
*/
|
|
137
438
|
setRephraseState(originalAssistantMessageIndex: number, rephraseRequestIndex: number, newResponseIndex: number, messageType: "user" | "system", prefillText?: string): void;
|
|
439
|
+
/**
|
|
440
|
+
* Get the current rephrase state.
|
|
441
|
+
* @returns Rephrase state info or null if none active
|
|
442
|
+
*/
|
|
138
443
|
getRephraseState(): {
|
|
139
444
|
originalAssistantMessageIndex: number;
|
|
140
445
|
rephraseRequestIndex: number;
|
|
@@ -142,135 +447,200 @@ export declare class LLMAgent extends EventEmitter {
|
|
|
142
447
|
messageType: "user" | "system";
|
|
143
448
|
prefillText?: string;
|
|
144
449
|
} | null;
|
|
450
|
+
/**
|
|
451
|
+
* Clear the current rephrase state.
|
|
452
|
+
*/
|
|
145
453
|
clearRephraseState(): void;
|
|
454
|
+
/**
|
|
455
|
+
* Set the agent's persona with optional color.
|
|
456
|
+
*
|
|
457
|
+
* Executes the persona hook if configured and updates the agent's
|
|
458
|
+
* persona state on success.
|
|
459
|
+
*
|
|
460
|
+
* @param persona - The persona description
|
|
461
|
+
* @param color - Optional display color (defaults to "white")
|
|
462
|
+
* @returns Promise resolving to success/error result
|
|
463
|
+
*/
|
|
146
464
|
setPersona(persona: string, color?: string): Promise<{
|
|
147
465
|
success: boolean;
|
|
148
466
|
error?: string;
|
|
149
467
|
}>;
|
|
468
|
+
/**
|
|
469
|
+
* Set the agent's mood with optional color.
|
|
470
|
+
*
|
|
471
|
+
* Executes the mood hook if configured and updates the agent's
|
|
472
|
+
* mood state on success.
|
|
473
|
+
*
|
|
474
|
+
* @param mood - The mood description
|
|
475
|
+
* @param color - Optional display color (defaults to "white")
|
|
476
|
+
* @returns Promise resolving to success/error result
|
|
477
|
+
*/
|
|
150
478
|
setMood(mood: string, color?: string): Promise<{
|
|
151
479
|
success: boolean;
|
|
152
480
|
error?: string;
|
|
153
481
|
}>;
|
|
482
|
+
/**
|
|
483
|
+
* Start an active task with specified action and color.
|
|
484
|
+
*
|
|
485
|
+
* Executes the task start hook if configured and updates the agent's
|
|
486
|
+
* task state on success.
|
|
487
|
+
*
|
|
488
|
+
* @param activeTask - The task description
|
|
489
|
+
* @param action - The current action within the task
|
|
490
|
+
* @param color - Optional display color (defaults to "white")
|
|
491
|
+
* @returns Promise resolving to success/error result
|
|
492
|
+
*/
|
|
154
493
|
startActiveTask(activeTask: string, action: string, color?: string): Promise<{
|
|
155
494
|
success: boolean;
|
|
156
495
|
error?: string;
|
|
157
496
|
}>;
|
|
497
|
+
/**
|
|
498
|
+
* Transition the active task to a new action/status.
|
|
499
|
+
*
|
|
500
|
+
* Updates the current task action without changing the task itself.
|
|
501
|
+
*
|
|
502
|
+
* @param action - The new action description
|
|
503
|
+
* @param color - Optional display color (defaults to current color)
|
|
504
|
+
* @returns Promise resolving to success/error result
|
|
505
|
+
*/
|
|
158
506
|
transitionActiveTaskStatus(action: string, color?: string): Promise<{
|
|
159
507
|
success: boolean;
|
|
160
508
|
error?: string;
|
|
161
509
|
}>;
|
|
510
|
+
/**
|
|
511
|
+
* Stop the current active task with reason and documentation.
|
|
512
|
+
*
|
|
513
|
+
* Executes the task stop hook if configured and clears the agent's
|
|
514
|
+
* task state on success.
|
|
515
|
+
*
|
|
516
|
+
* @param reason - Reason for stopping the task
|
|
517
|
+
* @param documentationFile - Path to documentation file
|
|
518
|
+
* @param color - Optional display color (defaults to "white")
|
|
519
|
+
* @returns Promise resolving to success/error result
|
|
520
|
+
*/
|
|
162
521
|
stopActiveTask(reason: string, documentationFile: string, color?: string): Promise<{
|
|
163
522
|
success: boolean;
|
|
164
523
|
error?: string;
|
|
165
524
|
}>;
|
|
166
|
-
private emitContextChange;
|
|
167
|
-
private addContextWarningIfNeeded;
|
|
168
|
-
executeCommand(command: string, skipConfirmation?: boolean): Promise<ToolResult>;
|
|
169
|
-
getCurrentModel(): string;
|
|
170
|
-
setModel(model: string): void;
|
|
171
|
-
/**
|
|
172
|
-
* Strip in-progress tool calls from messages for backend/model testing
|
|
173
|
-
* Removes tool_calls from the last assistant message and any corresponding tool results
|
|
174
|
-
* @returns Cleaned copy of messages array, or original if no stripping needed
|
|
175
|
-
*/
|
|
176
|
-
static stripInProgressToolCalls(messages: LLMMessage[]): LLMMessage[];
|
|
177
525
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
526
|
+
* Delegation method for hook processing (used by ToolExecutor).
|
|
527
|
+
*
|
|
528
|
+
* Processes hook results through the HookManager to handle commands,
|
|
529
|
+
* variable transformations, and other hook-specific logic.
|
|
530
|
+
*
|
|
531
|
+
* @param hookResult - Result object from hook execution
|
|
532
|
+
* @param envKey - Optional environment key for variable transformation
|
|
533
|
+
* @returns Promise resolving to processing result
|
|
182
534
|
*/
|
|
183
|
-
|
|
535
|
+
processHookResult(hookResult: {
|
|
536
|
+
commands?: any[];
|
|
537
|
+
}, envKey?: string): Promise<{
|
|
184
538
|
success: boolean;
|
|
185
|
-
|
|
539
|
+
transformedValue?: string;
|
|
186
540
|
}>;
|
|
187
541
|
/**
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* @param
|
|
191
|
-
* @param
|
|
192
|
-
* @
|
|
193
|
-
* @param model Model to use (optional, uses current model if not specified)
|
|
194
|
-
* @returns Promise with success status and optional error message
|
|
542
|
+
* Execute a shell command through the ZSH tool.
|
|
543
|
+
*
|
|
544
|
+
* @param command - Shell command to execute
|
|
545
|
+
* @param skipConfirmation - Whether to skip confirmation prompts
|
|
546
|
+
* @returns Promise resolving to tool execution result
|
|
195
547
|
*/
|
|
196
|
-
|
|
197
|
-
success: boolean;
|
|
198
|
-
error?: string;
|
|
199
|
-
}>;
|
|
548
|
+
executeCommand(command: string, skipConfirmation?: boolean): Promise<ToolResult>;
|
|
200
549
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @param hookResult Hook execution result
|
|
204
|
-
* @param envKey Optional ENV key to check for transformation (e.g., ZDS_AI_AGENT_PERSONA)
|
|
205
|
-
* @returns Object with success status and transformed value (if any)
|
|
550
|
+
* Get the current LLM model name.
|
|
551
|
+
* @returns Current model identifier
|
|
206
552
|
*/
|
|
207
|
-
|
|
553
|
+
getCurrentModel(): string;
|
|
208
554
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
555
|
+
* Set a new LLM model and update related components.
|
|
556
|
+
*
|
|
557
|
+
* This method:
|
|
558
|
+
* - Updates the LLM client model
|
|
559
|
+
* - Resets vision support flag
|
|
560
|
+
* - Updates the token counter for the new model
|
|
561
|
+
* - Handles model name suffixes (e.g., :nothinking)
|
|
562
|
+
*
|
|
563
|
+
* @param model - New model identifier
|
|
564
|
+
*/
|
|
565
|
+
setModel(model: string): void;
|
|
566
|
+
/**
|
|
567
|
+
* Get the backend name (e.g., "grok", "openai").
|
|
568
|
+
* @returns Backend identifier string
|
|
212
569
|
*/
|
|
213
|
-
private processHookCommands;
|
|
214
570
|
getBackend(): string;
|
|
571
|
+
/**
|
|
572
|
+
* Abort the current operation if one is in progress.
|
|
573
|
+
*
|
|
574
|
+
* This will cancel streaming responses and tool execution.
|
|
575
|
+
*/
|
|
215
576
|
abortCurrentOperation(): void;
|
|
577
|
+
/**
|
|
578
|
+
* Clear the conversation cache and reinitialize the agent.
|
|
579
|
+
*
|
|
580
|
+
* This method:
|
|
581
|
+
* - Backs up current conversation to timestamped files
|
|
582
|
+
* - Clears chat history and messages
|
|
583
|
+
* - Resets context warnings and processing flags
|
|
584
|
+
* - Re-executes startup and instance hooks
|
|
585
|
+
* - Saves the cleared state
|
|
586
|
+
* - Emits context change events
|
|
587
|
+
*
|
|
588
|
+
* Used when context becomes too large or user requests a fresh start.
|
|
589
|
+
*/
|
|
216
590
|
clearCache(): Promise<void>;
|
|
217
591
|
/**
|
|
218
|
-
* Get current session state for persistence
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
592
|
+
* Get current session state for persistence.
|
|
593
|
+
*
|
|
594
|
+
* Collects all session-related state including:
|
|
595
|
+
* - Model and backend configuration
|
|
596
|
+
* - Persona, mood, and task settings
|
|
597
|
+
* - Context usage statistics
|
|
598
|
+
* - API key environment variable
|
|
599
|
+
*
|
|
600
|
+
* @returns Complete session state object
|
|
601
|
+
*/
|
|
602
|
+
getSessionState(): SessionState;
|
|
603
|
+
/**
|
|
604
|
+
* Restore session state from persistence.
|
|
605
|
+
*
|
|
606
|
+
* Restores all session-related state including:
|
|
607
|
+
* - Model and backend configuration
|
|
608
|
+
* - Persona, mood, and task settings
|
|
609
|
+
* - Token counter and API client setup
|
|
610
|
+
*
|
|
611
|
+
* @param state - Session state to restore
|
|
612
|
+
*/
|
|
613
|
+
restoreSessionState(state: SessionState): Promise<void>;
|
|
238
614
|
/**
|
|
239
|
-
*
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
mood: string;
|
|
246
|
-
moodColor: string;
|
|
247
|
-
activeTask: string;
|
|
248
|
-
activeTaskAction: string;
|
|
249
|
-
activeTaskColor: string;
|
|
250
|
-
cwd: string;
|
|
251
|
-
contextCurrent?: number;
|
|
252
|
-
contextMax?: number;
|
|
253
|
-
backend?: string;
|
|
254
|
-
baseUrl?: string;
|
|
255
|
-
apiKeyEnvVar?: string;
|
|
256
|
-
model?: string;
|
|
257
|
-
supportsVision?: boolean;
|
|
258
|
-
}): Promise<void>;
|
|
259
|
-
/**
|
|
260
|
-
* Compact conversation context by keeping system prompt and last N messages
|
|
261
|
-
* Reduces context size when it grows too large for backend to handle
|
|
615
|
+
* Compact conversation context by keeping system prompt and last N messages.
|
|
616
|
+
*
|
|
617
|
+
* Reduces context size when it grows too large for the backend to handle.
|
|
618
|
+
* Removes older messages while preserving the system prompt and recent context.
|
|
619
|
+
*
|
|
620
|
+
* @param keepLastMessages - Number of recent messages to keep (default: 20)
|
|
262
621
|
* @returns Number of messages removed
|
|
263
622
|
*/
|
|
264
623
|
compactContext(keepLastMessages?: number): number;
|
|
265
624
|
/**
|
|
266
|
-
* Get all tool instances and their class names for display purposes
|
|
625
|
+
* Get all tool instances and their class names for display purposes.
|
|
626
|
+
*
|
|
627
|
+
* Uses reflection to find all tool instances and extract their
|
|
628
|
+
* class names and handled method names for introspection.
|
|
629
|
+
*
|
|
630
|
+
* @returns Array of tool info objects with class names and methods
|
|
267
631
|
*/
|
|
268
632
|
getToolClassInfo(): Array<{
|
|
269
633
|
className: string;
|
|
270
634
|
methods: string[];
|
|
271
635
|
}>;
|
|
272
636
|
/**
|
|
273
|
-
* Get all tool instances via reflection
|
|
637
|
+
* Get all tool instances via reflection.
|
|
638
|
+
*
|
|
639
|
+
* Scans all properties of the agent instance to find objects that
|
|
640
|
+
* implement the tool interface (have getHandledToolNames method).
|
|
641
|
+
*
|
|
642
|
+
* @returns Array of tool instances with their class names
|
|
643
|
+
* @private
|
|
274
644
|
*/
|
|
275
645
|
private getToolInstances;
|
|
276
646
|
}
|