@tecet/ollm 0.1.4 → 0.1.5
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/dist/cli.js +20 -14
- package/dist/cli.js.map +3 -3
- package/dist/services/documentService.d.ts.map +1 -1
- package/dist/services/documentService.js +12 -2
- package/dist/services/documentService.js.map +1 -1
- package/dist/ui/components/docs/DocsPanel.d.ts.map +1 -1
- package/dist/ui/components/docs/DocsPanel.js +1 -1
- package/dist/ui/components/docs/DocsPanel.js.map +1 -1
- package/dist/ui/components/launch/VersionBanner.js +1 -1
- package/dist/ui/components/launch/VersionBanner.js.map +1 -1
- package/dist/ui/components/layout/KeybindsLegend.d.ts.map +1 -1
- package/dist/ui/components/layout/KeybindsLegend.js +1 -1
- package/dist/ui/components/layout/KeybindsLegend.js.map +1 -1
- package/dist/ui/components/tabs/BugReportTab.js +1 -1
- package/dist/ui/components/tabs/BugReportTab.js.map +1 -1
- package/dist/ui/services/docsService.d.ts +12 -27
- package/dist/ui/services/docsService.d.ts.map +1 -1
- package/dist/ui/services/docsService.js +40 -67
- package/dist/ui/services/docsService.js.map +1 -1
- package/docs/README.md +3 -410
- package/package.json +10 -7
- package/scripts/copy-docs-to-user.cjs +34 -0
- package/docs/Context/CheckpointFlowDiagram.md +0 -673
- package/docs/Context/ContextArchitecture.md +0 -898
- package/docs/Context/ContextCompression.md +0 -1102
- package/docs/Context/ContextManagment.md +0 -750
- package/docs/Context/Index.md +0 -209
- package/docs/Context/README.md +0 -390
- package/docs/DevelopmentRoadmap/Index.md +0 -238
- package/docs/DevelopmentRoadmap/OLLM-CLI_Releases.md +0 -419
- package/docs/DevelopmentRoadmap/PlanedFeatures.md +0 -448
- package/docs/DevelopmentRoadmap/README.md +0 -174
- package/docs/DevelopmentRoadmap/Roadmap.md +0 -572
- package/docs/DevelopmentRoadmap/RoadmapVisual.md +0 -372
- package/docs/Hooks/Architecture.md +0 -885
- package/docs/Hooks/Index.md +0 -244
- package/docs/Hooks/KeyboardShortcuts.md +0 -248
- package/docs/Hooks/Protocol.md +0 -817
- package/docs/Hooks/README.md +0 -403
- package/docs/Hooks/UserGuide.md +0 -1483
- package/docs/Hooks/VisualGuide.md +0 -598
- package/docs/Index.md +0 -506
- package/docs/Installation.md +0 -586
- package/docs/Introduction.md +0 -367
- package/docs/LLM Models/Index.md +0 -239
- package/docs/LLM Models/LLM_GettingStarted.md +0 -748
- package/docs/LLM Models/LLM_Index.md +0 -701
- package/docs/LLM Models/LLM_MemorySystem.md +0 -337
- package/docs/LLM Models/LLM_ModelCompatibility.md +0 -499
- package/docs/LLM Models/LLM_ModelsArchitecture.md +0 -933
- package/docs/LLM Models/LLM_ModelsCommands.md +0 -839
- package/docs/LLM Models/LLM_ModelsConfiguration.md +0 -1094
- package/docs/LLM Models/LLM_ModelsList.md +0 -1071
- package/docs/LLM Models/LLM_ModelsList.md.backup +0 -400
- package/docs/LLM Models/README.md +0 -355
- package/docs/MCP/MCP_Architecture.md +0 -1086
- package/docs/MCP/MCP_Commands.md +0 -1111
- package/docs/MCP/MCP_GettingStarted.md +0 -590
- package/docs/MCP/MCP_Index.md +0 -524
- package/docs/MCP/MCP_Integration.md +0 -866
- package/docs/MCP/MCP_Marketplace.md +0 -160
- package/docs/MCP/README.md +0 -415
- package/docs/Prompts System/Architecture.md +0 -760
- package/docs/Prompts System/Index.md +0 -223
- package/docs/Prompts System/PromptsRouting.md +0 -1047
- package/docs/Prompts System/PromptsTemplates.md +0 -1102
- package/docs/Prompts System/README.md +0 -389
- package/docs/Prompts System/SystemPrompts.md +0 -856
- package/docs/Quickstart.md +0 -535
- package/docs/Tools/Architecture.md +0 -884
- package/docs/Tools/GettingStarted.md +0 -624
- package/docs/Tools/Index.md +0 -216
- package/docs/Tools/ManifestReference.md +0 -141
- package/docs/Tools/README.md +0 -440
- package/docs/Tools/UserGuide.md +0 -773
- package/docs/Troubleshooting.md +0 -1265
- package/docs/UI&Settings/Architecture.md +0 -729
- package/docs/UI&Settings/ColorASCII.md +0 -34
- package/docs/UI&Settings/Commands.md +0 -755
- package/docs/UI&Settings/Configuration.md +0 -872
- package/docs/UI&Settings/Index.md +0 -293
- package/docs/UI&Settings/Keybinds.md +0 -372
- package/docs/UI&Settings/README.md +0 -278
- package/docs/UI&Settings/Terminal.md +0 -637
- package/docs/UI&Settings/Themes.md +0 -604
- package/docs/UI&Settings/UIGuide.md +0 -550
|
@@ -1,884 +0,0 @@
|
|
|
1
|
-
# Tool Execution System Architecture
|
|
2
|
-
|
|
3
|
-
**Technical Architecture and Design of the Tool System**
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Table of Contents
|
|
8
|
-
|
|
9
|
-
1. [Overview](#overview)
|
|
10
|
-
2. [System Architecture](#system-architecture)
|
|
11
|
-
3. [Core Components](#core-components)
|
|
12
|
-
4. [Tool Categories](#tool-categories)
|
|
13
|
-
5. [Data Flow](#data-flow)
|
|
14
|
-
6. [Integration Points](#integration-points)
|
|
15
|
-
7. [Design Decisions](#design-decisions)
|
|
16
|
-
8. [Security Model](#security-model)
|
|
17
|
-
|
|
18
|
-
**See Also:**
|
|
19
|
-
|
|
20
|
-
- [Tool User Guide](UserGuide.md) - Using tools
|
|
21
|
-
- [MCP Architecture](../MCP/MCP_Architecture.md) - MCP tool integration
|
|
22
|
-
- [Hook Architecture](../Hooks/Architecture.md) - Hook system integration
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## Overview
|
|
27
|
-
|
|
28
|
-
The Tool Execution System manages tool registration, validation, permission checking, and execution. It provides a unified interface for built-in tools, MCP tools, and dynamically registered tools.
|
|
29
|
-
|
|
30
|
-
### Key Features
|
|
31
|
-
|
|
32
|
-
- ✅ Unified tool registry for all tool types
|
|
33
|
-
- ✅ Schema-based parameter validation
|
|
34
|
-
- ✅ Permission-based approval system
|
|
35
|
-
- ✅ Dynamic tool registration at runtime
|
|
36
|
-
- ✅ MCP tool integration
|
|
37
|
-
- ✅ Result formatting and truncation
|
|
38
|
-
- ✅ Error handling and recovery
|
|
39
|
-
|
|
40
|
-
---
|
|
41
|
-
|
|
42
|
-
## System Architecture
|
|
43
|
-
|
|
44
|
-
### High-Level Architecture
|
|
45
|
-
|
|
46
|
-
```mermaid
|
|
47
|
-
graph TB
|
|
48
|
-
subgraph Sources["Tool Sources"]
|
|
49
|
-
BuiltIn["Built-in Tools"]
|
|
50
|
-
MCP["MCP Tools"]
|
|
51
|
-
Dynamic["Dynamic Tools"]
|
|
52
|
-
Extension["Extension Tools"]
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
subgraph ToolSystem["Tool System"]
|
|
56
|
-
Registry["Tool Registry"]
|
|
57
|
-
Validator["Parameter Validator"]
|
|
58
|
-
Policy["Policy Engine"]
|
|
59
|
-
Executor["Tool Executor"]
|
|
60
|
-
Formatter["Result Formatter"]
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
subgraph LLM["LLM Integration"]
|
|
64
|
-
Provider["Provider"]
|
|
65
|
-
Agent["Agent"]
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
Sources --> Registry
|
|
69
|
-
Registry --> Validator
|
|
70
|
-
Validator --> Policy
|
|
71
|
-
Policy --> Executor
|
|
72
|
-
Executor --> Formatter
|
|
73
|
-
Formatter --> Provider
|
|
74
|
-
Provider --> Agent
|
|
75
|
-
|
|
76
|
-
style ToolSystem fill:#f9f,stroke:#333,stroke-width:2px
|
|
77
|
-
style Sources fill:#bbf,stroke:#333,stroke-width:2px
|
|
78
|
-
style LLM fill:#bfb,stroke:#333,stroke-width:2px
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### Component Interaction Flow
|
|
82
|
-
|
|
83
|
-
```mermaid
|
|
84
|
-
flowchart LR
|
|
85
|
-
LLM[LLM Request] --> Registry[Tool Registry]
|
|
86
|
-
Registry --> Validate[Validate Parameters]
|
|
87
|
-
Validate --> Policy[Check Permissions]
|
|
88
|
-
Policy --> Execute[Execute Tool]
|
|
89
|
-
Execute --> Format[Format Result]
|
|
90
|
-
Format --> Return[Return to LLM]
|
|
91
|
-
|
|
92
|
-
style LLM fill:#e1f5ff
|
|
93
|
-
style Policy fill:#fff4e1
|
|
94
|
-
style Execute fill:#e8f5e9
|
|
95
|
-
style Return fill:#f3e5f5
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## Core Components
|
|
101
|
-
|
|
102
|
-
### 1. Tool Registry
|
|
103
|
-
|
|
104
|
-
**Location:** `packages/core/src/tools/tool-registry.ts`
|
|
105
|
-
|
|
106
|
-
**Responsibilities:**
|
|
107
|
-
|
|
108
|
-
- Register and store tool definitions
|
|
109
|
-
- Provide tool list to LLM
|
|
110
|
-
- Route tool execution requests
|
|
111
|
-
- Manage tool lifecycle
|
|
112
|
-
|
|
113
|
-
**Key Methods:**
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
interface ToolRegistry {
|
|
117
|
-
registerTool(definition: ToolDefinition): void;
|
|
118
|
-
unregisterTool(name: string): void;
|
|
119
|
-
getTool(name: string): ToolDefinition | undefined;
|
|
120
|
-
getAllTools(): ToolDefinition[];
|
|
121
|
-
executeTool(name: string, args: any): Promise<any>;
|
|
122
|
-
}
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
**Tool Definition:**
|
|
126
|
-
|
|
127
|
-
```typescript
|
|
128
|
-
interface ToolDefinition {
|
|
129
|
-
name: string;
|
|
130
|
-
description: string;
|
|
131
|
-
inputSchema: {
|
|
132
|
-
type: 'object';
|
|
133
|
-
properties: Record<string, ParameterSchema>;
|
|
134
|
-
required: string[];
|
|
135
|
-
};
|
|
136
|
-
execute: (args: any) => Promise<any>;
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 2. Parameter Validator
|
|
141
|
-
|
|
142
|
-
**Location:** `packages/core/src/tools/validation.ts`
|
|
143
|
-
|
|
144
|
-
**Responsibilities:**
|
|
145
|
-
|
|
146
|
-
- Validate parameters against schema
|
|
147
|
-
- Type checking
|
|
148
|
-
- Required field verification
|
|
149
|
-
- Value range validation
|
|
150
|
-
|
|
151
|
-
**Validation Flow:**
|
|
152
|
-
|
|
153
|
-
```mermaid
|
|
154
|
-
flowchart TD
|
|
155
|
-
Start[Tool Call] --> CheckExists{Tool Exists?}
|
|
156
|
-
CheckExists -->|No| ErrorNotFound[Error: Tool Not Found]
|
|
157
|
-
CheckExists -->|Yes| ValidateSchema[Validate Against Schema]
|
|
158
|
-
|
|
159
|
-
ValidateSchema --> CheckRequired{All Required?}
|
|
160
|
-
CheckRequired -->|No| ErrorRequired[Error: Missing Required]
|
|
161
|
-
CheckRequired -->|Yes| CheckTypes{Types Match?}
|
|
162
|
-
|
|
163
|
-
CheckTypes -->|No| ErrorType[Error: Type Mismatch]
|
|
164
|
-
CheckTypes -->|Yes| CheckValues{Values Valid?}
|
|
165
|
-
|
|
166
|
-
CheckValues -->|No| ErrorValue[Error: Invalid Value]
|
|
167
|
-
CheckValues -->|Yes| Success[Validation Success]
|
|
168
|
-
|
|
169
|
-
style Start fill:#e1f5ff
|
|
170
|
-
style Success fill:#e8f5e9
|
|
171
|
-
style ErrorNotFound fill:#ffe1e1
|
|
172
|
-
style ErrorRequired fill:#ffe1e1
|
|
173
|
-
style ErrorType fill:#ffe1e1
|
|
174
|
-
style ErrorValue fill:#ffe1e1
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### 3. Policy Engine
|
|
178
|
-
|
|
179
|
-
**Location:** `packages/core/src/policy/policyEngine.ts`
|
|
180
|
-
|
|
181
|
-
**Responsibilities:**
|
|
182
|
-
|
|
183
|
-
- Check tool permissions
|
|
184
|
-
- Request user approval
|
|
185
|
-
- Evaluate risk levels
|
|
186
|
-
- Manage approval modes
|
|
187
|
-
|
|
188
|
-
**Approval Modes:**
|
|
189
|
-
|
|
190
|
-
```mermaid
|
|
191
|
-
graph TD
|
|
192
|
-
ToolCall[Tool Call] --> CheckMode{Approval Mode}
|
|
193
|
-
|
|
194
|
-
CheckMode -->|YOLO| AutoApprove[Auto-Approve All]
|
|
195
|
-
CheckMode -->|AUTO| CheckRisk{Check Risk Level}
|
|
196
|
-
CheckMode -->|ASK| RequestApproval[Request Approval]
|
|
197
|
-
|
|
198
|
-
CheckRisk -->|Low| AutoApprove
|
|
199
|
-
CheckRisk -->|Medium| RequestApproval
|
|
200
|
-
CheckRisk -->|High| RequestApproval
|
|
201
|
-
|
|
202
|
-
RequestApproval --> UserDecision{User Approves?}
|
|
203
|
-
UserDecision -->|Yes| Execute[Execute Tool]
|
|
204
|
-
UserDecision -->|No| Block[Block Execution]
|
|
205
|
-
|
|
206
|
-
AutoApprove --> Execute
|
|
207
|
-
|
|
208
|
-
style AutoApprove fill:#e8f5e9
|
|
209
|
-
style Execute fill:#e1f5ff
|
|
210
|
-
style Block fill:#ffe1e1
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
**Risk Levels:**
|
|
214
|
-
|
|
215
|
-
- **Low** - Read-only operations (glob, ls, grep, read_file)
|
|
216
|
-
- **Medium** - Write operations (write_file, edit_file)
|
|
217
|
-
- **High** - Dangerous operations (shell, delete)
|
|
218
|
-
|
|
219
|
-
### 4. Tool Executor
|
|
220
|
-
|
|
221
|
-
**Location:** `packages/core/src/tools/tool-registry.ts`
|
|
222
|
-
|
|
223
|
-
**Responsibilities:**
|
|
224
|
-
|
|
225
|
-
- Execute tool function
|
|
226
|
-
- Handle errors gracefully
|
|
227
|
-
- Capture results
|
|
228
|
-
- Manage timeouts
|
|
229
|
-
|
|
230
|
-
**Execution Flow:**
|
|
231
|
-
|
|
232
|
-
```mermaid
|
|
233
|
-
flowchart TD
|
|
234
|
-
Start[Start Execution] --> Validate[Validate Parameters]
|
|
235
|
-
Validate --> CheckPermission[Check Permission]
|
|
236
|
-
CheckPermission --> Approved{Approved?}
|
|
237
|
-
|
|
238
|
-
Approved -->|No| Block[Block Execution]
|
|
239
|
-
Approved -->|Yes| Execute[Execute Tool Function]
|
|
240
|
-
|
|
241
|
-
Execute --> Timeout{Timeout?}
|
|
242
|
-
Timeout -->|Yes| Error[Return Timeout Error]
|
|
243
|
-
Timeout -->|No| Success{Success?}
|
|
244
|
-
|
|
245
|
-
Success -->|No| CatchError[Catch Error]
|
|
246
|
-
Success -->|Yes| FormatResult[Format Result]
|
|
247
|
-
|
|
248
|
-
CatchError --> Error
|
|
249
|
-
FormatResult --> Return[Return Result]
|
|
250
|
-
|
|
251
|
-
Block --> Error
|
|
252
|
-
|
|
253
|
-
style Start fill:#e1f5ff
|
|
254
|
-
style Execute fill:#e8f5e9
|
|
255
|
-
style Return fill:#f3e5f5
|
|
256
|
-
style Error fill:#ffe1e1
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
### 5. Result Formatter
|
|
260
|
-
|
|
261
|
-
**Location:** `packages/core/src/tools/output-helpers.ts`
|
|
262
|
-
|
|
263
|
-
**Responsibilities:**
|
|
264
|
-
|
|
265
|
-
- Format results for LLM
|
|
266
|
-
- Truncate large outputs
|
|
267
|
-
- Add metadata
|
|
268
|
-
- Handle errors
|
|
269
|
-
|
|
270
|
-
**Truncation Strategy:**
|
|
271
|
-
|
|
272
|
-
| Output Type | Size Limit | Strategy |
|
|
273
|
-
| ------------------ | ----------- | ---------------------------------- |
|
|
274
|
-
| File contents | 10KB | Show first 5KB + "... [truncated]" |
|
|
275
|
-
| Directory listings | 1000 items | Show first 500 + count |
|
|
276
|
-
| Search results | 100 matches | Show first 50 + count |
|
|
277
|
-
| Shell output | 10KB | Show last 5KB (most recent) |
|
|
278
|
-
|
|
279
|
-
---
|
|
280
|
-
|
|
281
|
-
## Tool Categories
|
|
282
|
-
|
|
283
|
-
### File Discovery Tools
|
|
284
|
-
|
|
285
|
-
**Purpose:** Find and locate files
|
|
286
|
-
|
|
287
|
-
| Tool | Description | Risk Level |
|
|
288
|
-
| ------ | ----------------------- | ---------- |
|
|
289
|
-
| `glob` | Find files by pattern | Low |
|
|
290
|
-
| `ls` | List directory contents | Low |
|
|
291
|
-
| `grep` | Search file contents | Low |
|
|
292
|
-
|
|
293
|
-
**Auto-Approve:** ✅ Yes (in AUTO mode)
|
|
294
|
-
|
|
295
|
-
### File Operations Tools
|
|
296
|
-
|
|
297
|
-
**Purpose:** Read and write files
|
|
298
|
-
|
|
299
|
-
| Tool | Description | Risk Level |
|
|
300
|
-
| ----------------- | ---------------------- | ---------- |
|
|
301
|
-
| `read_file` | Read single file | Low |
|
|
302
|
-
| `read_many_files` | Read multiple files | Low |
|
|
303
|
-
| `edit_file` | Edit file sections | Medium |
|
|
304
|
-
| `write_file` | Create/overwrite files | Medium |
|
|
305
|
-
|
|
306
|
-
**Auto-Approve:**
|
|
307
|
-
|
|
308
|
-
- Read: ✅ Yes (in AUTO mode)
|
|
309
|
-
- Write: ❌ No (requires approval)
|
|
310
|
-
|
|
311
|
-
### Web Tools
|
|
312
|
-
|
|
313
|
-
**Purpose:** Access web resources
|
|
314
|
-
|
|
315
|
-
| Tool | Description | Risk Level |
|
|
316
|
-
| ------------ | ----------------- | ---------- |
|
|
317
|
-
| `web_search` | Search internet | Low |
|
|
318
|
-
| `web_fetch` | Fetch URL content | Low |
|
|
319
|
-
|
|
320
|
-
**Auto-Approve:** ✅ Yes (in AUTO mode)
|
|
321
|
-
|
|
322
|
-
### Shell Tool
|
|
323
|
-
|
|
324
|
-
**Purpose:** Execute shell commands
|
|
325
|
-
|
|
326
|
-
| Tool | Description | Risk Level |
|
|
327
|
-
| ------- | ---------------- | ---------- |
|
|
328
|
-
| `shell` | Execute commands | High |
|
|
329
|
-
|
|
330
|
-
**Auto-Approve:** ❌ No (always requires approval unless YOLO)
|
|
331
|
-
|
|
332
|
-
**Note:** Shell tool UI enhancement planned (collapsible terminal with visual indicators).
|
|
333
|
-
|
|
334
|
-
### Memory & Context Tools
|
|
335
|
-
|
|
336
|
-
**Purpose:** Manage memory and context
|
|
337
|
-
|
|
338
|
-
| Tool | Description | Risk Level |
|
|
339
|
-
| ------------------- | --------------------- | ---------- |
|
|
340
|
-
| `memory` | Persistent memory | Low |
|
|
341
|
-
| `remember` | Simplified memory | Low |
|
|
342
|
-
| `write_memory_dump` | Context snapshot | Low |
|
|
343
|
-
| `read_reasoning` | Review past reasoning | Low |
|
|
344
|
-
|
|
345
|
-
**Auto-Approve:** ✅ Yes (in AUTO mode)
|
|
346
|
-
|
|
347
|
-
### Goal Management Tools
|
|
348
|
-
|
|
349
|
-
**Purpose:** Manage goals and decisions
|
|
350
|
-
|
|
351
|
-
| Tool | Description | Risk Level |
|
|
352
|
-
| ------------------- | ------------------ | ---------- |
|
|
353
|
-
| `create_goal` | Create new goal | Low |
|
|
354
|
-
| `switch_goal` | Switch active goal | Low |
|
|
355
|
-
| `complete_goal` | Mark goal complete | Low |
|
|
356
|
-
| `create_checkpoint` | Create checkpoint | Low |
|
|
357
|
-
| `record_decision` | Record decision | Low |
|
|
358
|
-
|
|
359
|
-
**Auto-Approve:** ✅ Yes (in AUTO mode)
|
|
360
|
-
|
|
361
|
-
**See:** `dev_PromptSystem.md` for goal system architecture
|
|
362
|
-
|
|
363
|
-
---
|
|
364
|
-
|
|
365
|
-
## Data Flow
|
|
366
|
-
|
|
367
|
-
### Tool Registration Flow
|
|
368
|
-
|
|
369
|
-
```mermaid
|
|
370
|
-
flowchart TD
|
|
371
|
-
Start[Application Startup] --> InitRegistry[Initialize Tool Registry]
|
|
372
|
-
InitRegistry --> RegisterBuiltIn[Register Built-in Tools]
|
|
373
|
-
|
|
374
|
-
RegisterBuiltIn --> FileTools[File Tools]
|
|
375
|
-
RegisterBuiltIn --> WebTools[Web Tools]
|
|
376
|
-
RegisterBuiltIn --> ShellTool[Shell Tool]
|
|
377
|
-
RegisterBuiltIn --> MemoryTools[Memory Tools]
|
|
378
|
-
RegisterBuiltIn --> GoalTools[Goal Tools]
|
|
379
|
-
|
|
380
|
-
FileTools --> RegisterMCP[Register MCP Tools]
|
|
381
|
-
WebTools --> RegisterMCP
|
|
382
|
-
ShellTool --> RegisterMCP
|
|
383
|
-
MemoryTools --> RegisterMCP
|
|
384
|
-
GoalTools --> RegisterMCP
|
|
385
|
-
|
|
386
|
-
RegisterMCP --> ConnectServers[Connect to MCP Servers]
|
|
387
|
-
ConnectServers --> DiscoverTools[Discover Tools]
|
|
388
|
-
DiscoverTools --> ConvertSchemas[Convert Schemas]
|
|
389
|
-
ConvertSchemas --> WrapTools[Wrap with MCPToolWrapper]
|
|
390
|
-
|
|
391
|
-
WrapTools --> RegisterDynamic[Register Dynamic Tools]
|
|
392
|
-
RegisterDynamic --> MemoryDump[write_memory_dump]
|
|
393
|
-
RegisterDynamic --> HotSwap[trigger_hot_swap]
|
|
394
|
-
RegisterDynamic --> ExtensionTools[Extension Tools]
|
|
395
|
-
|
|
396
|
-
MemoryDump --> Ready[Tools Available to LLM]
|
|
397
|
-
HotSwap --> Ready
|
|
398
|
-
ExtensionTools --> Ready
|
|
399
|
-
|
|
400
|
-
style Start fill:#e1f5ff
|
|
401
|
-
style Ready fill:#e8f5e9
|
|
402
|
-
```
|
|
403
|
-
|
|
404
|
-
### Tool Execution Flow
|
|
405
|
-
|
|
406
|
-
```mermaid
|
|
407
|
-
flowchart TD
|
|
408
|
-
LLM[LLM Requests Tool] --> Lookup[Tool Registry Lookup]
|
|
409
|
-
Lookup --> Exists{Tool Exists?}
|
|
410
|
-
|
|
411
|
-
Exists -->|No| ErrorNotFound[Error: Tool Not Found]
|
|
412
|
-
Exists -->|Yes| Validate[Validate Parameters]
|
|
413
|
-
|
|
414
|
-
Validate --> Valid{Valid?}
|
|
415
|
-
Valid -->|No| ErrorInvalid[Error: Invalid Parameters]
|
|
416
|
-
Valid -->|Yes| CheckPermission[Check Permission]
|
|
417
|
-
|
|
418
|
-
CheckPermission --> Policy[Policy Engine]
|
|
419
|
-
Policy --> Approved{Approved?}
|
|
420
|
-
|
|
421
|
-
Approved -->|No| ErrorDenied[Error: Permission Denied]
|
|
422
|
-
Approved -->|Yes| Execute[Execute Tool Function]
|
|
423
|
-
|
|
424
|
-
Execute --> Success{Success?}
|
|
425
|
-
Success -->|No| CatchError[Catch Error]
|
|
426
|
-
Success -->|Yes| FormatResult[Format Result]
|
|
427
|
-
|
|
428
|
-
CatchError --> ErrorExecution[Error: Execution Failed]
|
|
429
|
-
FormatResult --> Truncate[Truncate if Needed]
|
|
430
|
-
Truncate --> AddMetadata[Add Metadata]
|
|
431
|
-
AddMetadata --> Return[Return to LLM]
|
|
432
|
-
|
|
433
|
-
ErrorNotFound --> Return
|
|
434
|
-
ErrorInvalid --> Return
|
|
435
|
-
ErrorDenied --> Return
|
|
436
|
-
ErrorExecution --> Return
|
|
437
|
-
|
|
438
|
-
style LLM fill:#e1f5ff
|
|
439
|
-
style Execute fill:#e8f5e9
|
|
440
|
-
style Return fill:#f3e5f5
|
|
441
|
-
style ErrorNotFound fill:#ffe1e1
|
|
442
|
-
style ErrorInvalid fill:#ffe1e1
|
|
443
|
-
style ErrorDenied fill:#ffe1e1
|
|
444
|
-
style ErrorExecution fill:#ffe1e1
|
|
445
|
-
```
|
|
446
|
-
|
|
447
|
-
### MCP Tool Execution Flow
|
|
448
|
-
|
|
449
|
-
```mermaid
|
|
450
|
-
flowchart TD
|
|
451
|
-
LLM[LLM Requests MCP Tool] --> Registry[Tool Registry]
|
|
452
|
-
Registry --> Wrapper[MCPToolWrapper]
|
|
453
|
-
Wrapper --> ValidateParams[Validate Parameters]
|
|
454
|
-
ValidateParams --> CheckPermission[Check Permission]
|
|
455
|
-
CheckPermission --> MCPClient[MCP Client]
|
|
456
|
-
|
|
457
|
-
MCPClient --> Transport[MCP Transport]
|
|
458
|
-
Transport --> Stdio[Stdio: Write to stdin]
|
|
459
|
-
Transport --> SSE[SSE: POST to endpoint]
|
|
460
|
-
Transport --> HTTP[HTTP: POST request]
|
|
461
|
-
|
|
462
|
-
Stdio --> Server[MCP Server]
|
|
463
|
-
SSE --> Server
|
|
464
|
-
HTTP --> Server
|
|
465
|
-
|
|
466
|
-
Server --> Process[Process Request]
|
|
467
|
-
Process --> Response[Send Response]
|
|
468
|
-
Response --> Receive[MCP Transport Receives]
|
|
469
|
-
Receive --> ConvertResult[Convert Result]
|
|
470
|
-
ConvertResult --> Format[Format for LLM]
|
|
471
|
-
Format --> Return[Return to LLM]
|
|
472
|
-
|
|
473
|
-
style LLM fill:#e1f5ff
|
|
474
|
-
style Server fill:#e8f5e9
|
|
475
|
-
style Return fill:#f3e5f5
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
---
|
|
479
|
-
|
|
480
|
-
## Integration Points
|
|
481
|
-
|
|
482
|
-
### 1. Provider Integration
|
|
483
|
-
|
|
484
|
-
Tools are passed to the provider alongside the system prompt:
|
|
485
|
-
|
|
486
|
-
```typescript
|
|
487
|
-
const turnOptions: ChatOptions = {
|
|
488
|
-
systemPrompt: systemPromptWithContext,
|
|
489
|
-
tools: tools, // All registered tools
|
|
490
|
-
...options,
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
const response = await provider.chat(messages, turnOptions);
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
**Current Issue:** Tools not being passed to provider (see Troubleshooting section).
|
|
497
|
-
|
|
498
|
-
### 2. MCP Integration
|
|
499
|
-
|
|
500
|
-
MCP tools are automatically registered in the Tool Registry:
|
|
501
|
-
|
|
502
|
-
```mermaid
|
|
503
|
-
sequenceDiagram
|
|
504
|
-
participant MCP as MCP Client
|
|
505
|
-
participant Converter as Schema Converter
|
|
506
|
-
participant Wrapper as Tool Wrapper
|
|
507
|
-
participant Registry as Tool Registry
|
|
508
|
-
participant LLM as LLM
|
|
509
|
-
|
|
510
|
-
MCP->>MCP: Connect to Server
|
|
511
|
-
MCP->>MCP: Discover Tools
|
|
512
|
-
MCP->>Converter: Convert Schema
|
|
513
|
-
Converter-->>MCP: Internal Schema
|
|
514
|
-
MCP->>Wrapper: Wrap Tool
|
|
515
|
-
Wrapper->>Registry: Register Tool
|
|
516
|
-
Registry-->>LLM: Tool Available
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
### 3. Hook Integration
|
|
520
|
-
|
|
521
|
-
Hooks can trigger tool execution through `askAgent` action:
|
|
522
|
-
|
|
523
|
-
```json
|
|
524
|
-
{
|
|
525
|
-
"action": {
|
|
526
|
-
"type": "askAgent",
|
|
527
|
-
"prompt": "Run linting on {{file.path}} using the shell tool"
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
The agent will then use the appropriate tool.
|
|
533
|
-
|
|
534
|
-
### 4. Dynamic Tool Registration
|
|
535
|
-
|
|
536
|
-
Services can register tools at runtime:
|
|
537
|
-
|
|
538
|
-
```typescript
|
|
539
|
-
// ChatContext registers memory dump tool
|
|
540
|
-
toolRegistry.registerTool({
|
|
541
|
-
name: 'write_memory_dump',
|
|
542
|
-
description: 'Create context snapshot',
|
|
543
|
-
inputSchema: {
|
|
544
|
-
/* ... */
|
|
545
|
-
},
|
|
546
|
-
execute: async (args) => {
|
|
547
|
-
return await chatContext.createMemoryDump(args);
|
|
548
|
-
},
|
|
549
|
-
});
|
|
550
|
-
```
|
|
551
|
-
|
|
552
|
-
---
|
|
553
|
-
|
|
554
|
-
## Design Decisions
|
|
555
|
-
|
|
556
|
-
### 1. Unified Tool Registry
|
|
557
|
-
|
|
558
|
-
**Decision:** Single registry for all tool types
|
|
559
|
-
|
|
560
|
-
**Rationale:**
|
|
561
|
-
|
|
562
|
-
- Consistent interface for LLM
|
|
563
|
-
- Simplified tool management
|
|
564
|
-
- Easier to add new tool sources
|
|
565
|
-
- Unified permission checking
|
|
566
|
-
|
|
567
|
-
**Trade-offs:**
|
|
568
|
-
|
|
569
|
-
- ✅ Consistency
|
|
570
|
-
- ✅ Simplicity
|
|
571
|
-
- ❌ Less flexibility per tool type
|
|
572
|
-
- ❌ Shared namespace
|
|
573
|
-
|
|
574
|
-
### 2. Schema-Based Validation
|
|
575
|
-
|
|
576
|
-
**Decision:** Use JSON Schema for parameter validation
|
|
577
|
-
|
|
578
|
-
**Rationale:**
|
|
579
|
-
|
|
580
|
-
- Standard format
|
|
581
|
-
- Type safety
|
|
582
|
-
- Clear documentation
|
|
583
|
-
- Tool compatibility
|
|
584
|
-
|
|
585
|
-
**Trade-offs:**
|
|
586
|
-
|
|
587
|
-
- ✅ Type safety
|
|
588
|
-
- ✅ Clear contracts
|
|
589
|
-
- ❌ Verbose schemas
|
|
590
|
-
- ❌ Limited validation logic
|
|
591
|
-
|
|
592
|
-
### 3. Permission-Based Approval
|
|
593
|
-
|
|
594
|
-
**Decision:** Three approval modes (YOLO, AUTO, ASK)
|
|
595
|
-
|
|
596
|
-
**Rationale:**
|
|
597
|
-
|
|
598
|
-
- Balance safety and speed
|
|
599
|
-
- User control
|
|
600
|
-
- Risk-based decisions
|
|
601
|
-
- Flexible workflow
|
|
602
|
-
|
|
603
|
-
**Modes:**
|
|
604
|
-
|
|
605
|
-
- **YOLO** - Maximum speed, minimum safety
|
|
606
|
-
- **AUTO** - Balanced (recommended)
|
|
607
|
-
- **ASK** - Maximum safety, slower workflow
|
|
608
|
-
|
|
609
|
-
### 4. Result Truncation
|
|
610
|
-
|
|
611
|
-
**Decision:** Truncate large outputs automatically
|
|
612
|
-
|
|
613
|
-
**Rationale:**
|
|
614
|
-
|
|
615
|
-
- Prevent context overflow
|
|
616
|
-
- Keep relevant information
|
|
617
|
-
- LLM can request more if needed
|
|
618
|
-
- Better performance
|
|
619
|
-
|
|
620
|
-
**Strategy:**
|
|
621
|
-
|
|
622
|
-
- File contents: First 5KB
|
|
623
|
-
- Directory listings: First 500 items
|
|
624
|
-
- Search results: First 50 matches
|
|
625
|
-
- Shell output: Last 5KB (most recent)
|
|
626
|
-
|
|
627
|
-
### 5. Dynamic Registration
|
|
628
|
-
|
|
629
|
-
**Decision:** Allow runtime tool registration
|
|
630
|
-
|
|
631
|
-
**Rationale:**
|
|
632
|
-
|
|
633
|
-
- Flexibility
|
|
634
|
-
- Service integration
|
|
635
|
-
- Extension support
|
|
636
|
-
- Hot-reload capability
|
|
637
|
-
|
|
638
|
-
**Use Cases:**
|
|
639
|
-
|
|
640
|
-
- Memory dump tool (ChatContext)
|
|
641
|
-
- Hot swap tool (HotSwapService)
|
|
642
|
-
- Extension tools
|
|
643
|
-
- MCP tools
|
|
644
|
-
|
|
645
|
-
---
|
|
646
|
-
|
|
647
|
-
## Security Model
|
|
648
|
-
|
|
649
|
-
### 1. Permission Checking
|
|
650
|
-
|
|
651
|
-
**Threat:** Unauthorized tool execution
|
|
652
|
-
|
|
653
|
-
**Mitigation:**
|
|
654
|
-
|
|
655
|
-
- Policy engine evaluation
|
|
656
|
-
- User approval workflow
|
|
657
|
-
- Risk-based decisions
|
|
658
|
-
- Approval persistence
|
|
659
|
-
|
|
660
|
-
**Implementation:**
|
|
661
|
-
|
|
662
|
-
```typescript
|
|
663
|
-
async function checkPermission(tool: string, args: any): Promise<boolean> {
|
|
664
|
-
const riskLevel = evaluateRisk(tool, args);
|
|
665
|
-
|
|
666
|
-
if (approvalMode === 'YOLO') {
|
|
667
|
-
return true;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
if (approvalMode === 'AUTO' && riskLevel === 'low') {
|
|
671
|
-
return true;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
return await requestUserApproval(tool, args);
|
|
675
|
-
}
|
|
676
|
-
```
|
|
677
|
-
|
|
678
|
-
### 2. Parameter Validation
|
|
679
|
-
|
|
680
|
-
**Threat:** Malicious or malformed parameters
|
|
681
|
-
|
|
682
|
-
**Mitigation:**
|
|
683
|
-
|
|
684
|
-
- Schema validation
|
|
685
|
-
- Type checking
|
|
686
|
-
- Value range validation
|
|
687
|
-
- Required field verification
|
|
688
|
-
|
|
689
|
-
**Implementation:**
|
|
690
|
-
|
|
691
|
-
```typescript
|
|
692
|
-
function validateParameters(tool: ToolDefinition, args: any): void {
|
|
693
|
-
const schema = tool.inputSchema;
|
|
694
|
-
|
|
695
|
-
// Check required fields
|
|
696
|
-
for (const field of schema.required) {
|
|
697
|
-
if (!(field in args)) {
|
|
698
|
-
throw new Error(`Missing required field: ${field}`);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// Check types
|
|
703
|
-
for (const [field, value] of Object.entries(args)) {
|
|
704
|
-
const fieldSchema = schema.properties[field];
|
|
705
|
-
if (!validateType(value, fieldSchema.type)) {
|
|
706
|
-
throw new Error(`Invalid type for field: ${field}`);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
```
|
|
711
|
-
|
|
712
|
-
### 3. Error Isolation
|
|
713
|
-
|
|
714
|
-
**Threat:** Tool errors affecting system
|
|
715
|
-
|
|
716
|
-
**Mitigation:**
|
|
717
|
-
|
|
718
|
-
- Try-catch blocks
|
|
719
|
-
- Error formatting
|
|
720
|
-
- Graceful degradation
|
|
721
|
-
- Error logging
|
|
722
|
-
|
|
723
|
-
**Implementation:**
|
|
724
|
-
|
|
725
|
-
```typescript
|
|
726
|
-
async function executeTool(name: string, args: any): Promise<any> {
|
|
727
|
-
try {
|
|
728
|
-
const tool = getTool(name);
|
|
729
|
-
const result = await tool.execute(args);
|
|
730
|
-
return formatResult(result);
|
|
731
|
-
} catch (error) {
|
|
732
|
-
logger.error(`Tool execution failed: ${error.message}`);
|
|
733
|
-
return {
|
|
734
|
-
error: error.message,
|
|
735
|
-
tool: name,
|
|
736
|
-
args: args,
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
```
|
|
741
|
-
|
|
742
|
-
### 4. Output Sanitization
|
|
743
|
-
|
|
744
|
-
**Threat:** Malicious output affecting LLM
|
|
745
|
-
|
|
746
|
-
**Mitigation:**
|
|
747
|
-
|
|
748
|
-
- Output truncation
|
|
749
|
-
- Special character escaping
|
|
750
|
-
- Size limits
|
|
751
|
-
- Format validation
|
|
752
|
-
|
|
753
|
-
---
|
|
754
|
-
|
|
755
|
-
## Performance Considerations
|
|
756
|
-
|
|
757
|
-
### 1. Tool Caching
|
|
758
|
-
|
|
759
|
-
**Optimization:** Cache tool definitions
|
|
760
|
-
|
|
761
|
-
**Implementation:**
|
|
762
|
-
|
|
763
|
-
- Store tool definitions in memory
|
|
764
|
-
- Lazy load tool implementations
|
|
765
|
-
- Cache validation results
|
|
766
|
-
- Reuse tool instances
|
|
767
|
-
|
|
768
|
-
### 2. Parallel Execution
|
|
769
|
-
|
|
770
|
-
**Optimization:** Execute independent tools in parallel
|
|
771
|
-
|
|
772
|
-
**Note:** Currently not implemented, but planned for future.
|
|
773
|
-
|
|
774
|
-
### 3. Result Streaming
|
|
775
|
-
|
|
776
|
-
**Optimization:** Stream large results
|
|
777
|
-
|
|
778
|
-
**Note:** Currently not implemented, but planned for shell tool enhancement.
|
|
779
|
-
|
|
780
|
-
---
|
|
781
|
-
|
|
782
|
-
## Troubleshooting
|
|
783
|
-
|
|
784
|
-
### Tools Not Available to LLM
|
|
785
|
-
|
|
786
|
-
**Symptom:** LLM doesn't use tools, only provides advice
|
|
787
|
-
|
|
788
|
-
**ROOT CAUSE:** Tools are not being passed to the provider in the chat request.
|
|
789
|
-
|
|
790
|
-
**Location:** `packages/core/src/core/chatClient.ts` line ~370
|
|
791
|
-
|
|
792
|
-
**Current Code (BROKEN):**
|
|
793
|
-
|
|
794
|
-
```typescript
|
|
795
|
-
const turnOptions: ChatOptions = {
|
|
796
|
-
...options,
|
|
797
|
-
systemPrompt: systemPromptWithContext,
|
|
798
|
-
// ❌ Missing: tools from ToolRegistry
|
|
799
|
-
};
|
|
800
|
-
```
|
|
801
|
-
|
|
802
|
-
**Fix:**
|
|
803
|
-
|
|
804
|
-
```typescript
|
|
805
|
-
// Get all registered tools
|
|
806
|
-
const tools = this.toolRegistry.getAllTools().map((tool) => ({
|
|
807
|
-
name: tool.name,
|
|
808
|
-
description: tool.description,
|
|
809
|
-
parameters: tool.inputSchema,
|
|
810
|
-
}));
|
|
811
|
-
|
|
812
|
-
const turnOptions: ChatOptions = {
|
|
813
|
-
...options,
|
|
814
|
-
systemPrompt: systemPromptWithContext,
|
|
815
|
-
tools: tools, // ✅ Add tools here
|
|
816
|
-
};
|
|
817
|
-
```
|
|
818
|
-
|
|
819
|
-
**See:** `works_todo.md` Task #10 for complete fix details
|
|
820
|
-
|
|
821
|
-
---
|
|
822
|
-
|
|
823
|
-
## File Locations
|
|
824
|
-
|
|
825
|
-
| File | Purpose |
|
|
826
|
-
| ------------------------------------------- | ------------------------------- |
|
|
827
|
-
| `packages/core/src/tools/tool-registry.ts` | Tool registration and execution |
|
|
828
|
-
| `packages/core/src/tools/types.ts` | Tool type definitions |
|
|
829
|
-
| `packages/core/src/tools/validation.ts` | Parameter validation |
|
|
830
|
-
| `packages/core/src/tools/output-helpers.ts` | Result formatting |
|
|
831
|
-
| `packages/core/src/policy/policyEngine.ts` | Permission checking |
|
|
832
|
-
| `packages/core/src/policy/policyRules.ts` | Risk evaluation rules |
|
|
833
|
-
| `packages/core/src/mcp/mcpToolWrapper.ts` | MCP tool wrapper |
|
|
834
|
-
| `packages/core/src/mcp/mcpClient.ts` | MCP client |
|
|
835
|
-
|
|
836
|
-
**Built-in Tools:**
|
|
837
|
-
|
|
838
|
-
- `packages/core/src/tools/glob.ts` - File pattern search
|
|
839
|
-
- `packages/core/src/tools/ls.ts` - Directory listing
|
|
840
|
-
- `packages/core/src/tools/grep.ts` - Content search
|
|
841
|
-
- `packages/core/src/tools/read-file.ts` - Read single file
|
|
842
|
-
- `packages/core/src/tools/read-many-files.ts` - Read multiple files
|
|
843
|
-
- `packages/core/src/tools/edit-file.ts` - Edit file sections
|
|
844
|
-
- `packages/core/src/tools/write-file.ts` - Create/overwrite files
|
|
845
|
-
- `packages/core/src/tools/web-search.ts` - Web search
|
|
846
|
-
- `packages/core/src/tools/web-fetch.ts` - Fetch URL content
|
|
847
|
-
- `packages/core/src/tools/shell.ts` - Shell execution
|
|
848
|
-
- `packages/core/src/tools/memory.ts` - Persistent memory
|
|
849
|
-
- `packages/core/src/tools/remember.ts` - Simplified memory
|
|
850
|
-
- `packages/core/src/tools/goal-management.ts` - Goal tools
|
|
851
|
-
- `packages/core/src/tools/write-todos.ts` - Todo management
|
|
852
|
-
- `packages/core/src/tools/read-reasoning.ts` - Reasoning retrieval
|
|
853
|
-
|
|
854
|
-
**Dynamic Tools:**
|
|
855
|
-
|
|
856
|
-
- `packages/core/src/tools/MemoryDumpTool.ts` - Memory dump tool
|
|
857
|
-
- `packages/core/src/tools/HotSwapTool.ts` - Hot swap tool
|
|
858
|
-
|
|
859
|
-
---
|
|
860
|
-
|
|
861
|
-
## Further Reading
|
|
862
|
-
|
|
863
|
-
### Documentation
|
|
864
|
-
|
|
865
|
-
- [Tool User Guide](UserGuide.md) - Using tools
|
|
866
|
-
- [MCP Architecture](../MCP/MCP_Architecture.md) - MCP tool integration
|
|
867
|
-
- [Hook Architecture](../Hooks/Architecture.md) - Hook system integration
|
|
868
|
-
|
|
869
|
-
### Related Systems
|
|
870
|
-
|
|
871
|
-
- [Goal Management](dev_PromptSystem.md) - Goal system architecture
|
|
872
|
-
- [Context Compression](dev_ContextCompression.md) - Goal system integration
|
|
873
|
-
- [Provider System](dev_ProviderSystem.md) - Provider integration
|
|
874
|
-
|
|
875
|
-
### External References
|
|
876
|
-
|
|
877
|
-
- JSON Schema (https://json-schema.org/)
|
|
878
|
-
- Tool Use Patterns (https://docs.anthropic.com/claude/docs/tool-use)
|
|
879
|
-
|
|
880
|
-
---
|
|
881
|
-
|
|
882
|
-
**Document Version:** 1.0
|
|
883
|
-
**Last Updated:** 2026-01-26
|
|
884
|
-
**Status:** ✅ Complete
|