@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
package/docs/Hooks/Protocol.md
DELETED
|
@@ -1,817 +0,0 @@
|
|
|
1
|
-
# Hook Protocol Specification
|
|
2
|
-
|
|
3
|
-
**Technical Specification for Hook Communication Protocol**
|
|
4
|
-
|
|
5
|
-
This document defines the complete protocol for hook communication in OLLM CLI.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 📋 Table of Contents
|
|
10
|
-
|
|
11
|
-
1. [Overview](#overview)
|
|
12
|
-
2. [Communication Protocol](#communication-protocol)
|
|
13
|
-
3. [Input Specification](#input-specification)
|
|
14
|
-
4. [Output Specification](#output-specification)
|
|
15
|
-
5. [Event Types](#event-types)
|
|
16
|
-
6. [Error Handling](#error-handling)
|
|
17
|
-
7. [Security Considerations](#security-considerations)
|
|
18
|
-
|
|
19
|
-
**See Also:**
|
|
20
|
-
|
|
21
|
-
- [Hook System Overview](3%20projects/OLLM%20CLI/Hooks/README.md) - Hook system introduction
|
|
22
|
-
- [Hook User Guide](3%20projects/OLLM%20CLI/Hooks/user-guide.md) - Using hooks
|
|
23
|
-
- [Hook Development Guide](3%20projects/OLLM%20CLI/Hooks/development-guide.md) - Creating hooks
|
|
24
|
-
- [MCP Architecture](MCP_architecture.md) - System architecture
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
## Overview
|
|
29
|
-
|
|
30
|
-
### Protocol Summary
|
|
31
|
-
|
|
32
|
-
The hook protocol defines how OLLM CLI communicates with hooks:
|
|
33
|
-
|
|
34
|
-
- **Transport:** Standard input/output (stdin/stdout)
|
|
35
|
-
- **Format:** JSON
|
|
36
|
-
- **Encoding:** UTF-8
|
|
37
|
-
- **Direction:** Bidirectional (request/response)
|
|
38
|
-
|
|
39
|
-
### Design Principles
|
|
40
|
-
|
|
41
|
-
1. **Simplicity** - Easy to implement in any language
|
|
42
|
-
2. **Extensibility** - Support for future event types
|
|
43
|
-
3. **Security** - Safe by default
|
|
44
|
-
4. **Performance** - Minimal overhead
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## Communication Protocol
|
|
49
|
-
|
|
50
|
-
### Message Flow
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
┌─────────────┐ ┌──────────┐
|
|
54
|
-
│ OLLM CLI │ │ Hook │
|
|
55
|
-
└──────┬──────┘ └────┬─────┘
|
|
56
|
-
│ │
|
|
57
|
-
│ 1. Write JSON to stdin │
|
|
58
|
-
│───────────────────────────────>│
|
|
59
|
-
│ │
|
|
60
|
-
│ 2. Hook processes event │
|
|
61
|
-
│ │
|
|
62
|
-
│ 3. Read JSON from stdout │
|
|
63
|
-
│<───────────────────────────────│
|
|
64
|
-
│ │
|
|
65
|
-
│ 4. Process response │
|
|
66
|
-
│ │
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Execution Model
|
|
70
|
-
|
|
71
|
-
1. **Event occurs** in OLLM CLI
|
|
72
|
-
2. **Hook registry** finds matching hooks
|
|
73
|
-
3. **Trust check** determines if approval needed
|
|
74
|
-
4. **Approval requested** (if needed)
|
|
75
|
-
5. **Hook executed** with event data on stdin
|
|
76
|
-
6. **Hook processes** event and returns response on stdout
|
|
77
|
-
7. **Response processed** by OLLM CLI
|
|
78
|
-
8. **Execution continues** or blocks based on response
|
|
79
|
-
|
|
80
|
-
### Timeout
|
|
81
|
-
|
|
82
|
-
- **Default timeout:** 5 seconds
|
|
83
|
-
- **Configurable:** Per hook or globally
|
|
84
|
-
- **On timeout:** Hook is terminated, operation blocked
|
|
85
|
-
|
|
86
|
-
---
|
|
87
|
-
|
|
88
|
-
## Input Specification
|
|
89
|
-
|
|
90
|
-
### Input Schema
|
|
91
|
-
|
|
92
|
-
```json
|
|
93
|
-
{
|
|
94
|
-
"event": "string (required)",
|
|
95
|
-
"context": {
|
|
96
|
-
"...": "event-specific data (required)"
|
|
97
|
-
},
|
|
98
|
-
"metadata": {
|
|
99
|
-
"timestamp": "ISO 8601 string (optional)",
|
|
100
|
-
"hookName": "string (optional)",
|
|
101
|
-
"hookVersion": "string (optional)",
|
|
102
|
-
"sessionId": "string (optional)"
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Field Definitions
|
|
108
|
-
|
|
109
|
-
#### event (required)
|
|
110
|
-
|
|
111
|
-
- **Type:** string
|
|
112
|
-
- **Description:** Event type identifier
|
|
113
|
-
- **Values:** See [Event Types](#event-types)
|
|
114
|
-
- **Example:** `"pre-tool-call"`
|
|
115
|
-
|
|
116
|
-
#### context (required)
|
|
117
|
-
|
|
118
|
-
- **Type:** object
|
|
119
|
-
- **Description:** Event-specific context data
|
|
120
|
-
- **Contents:** Varies by event type
|
|
121
|
-
- **Example:** `{"tool": "read-file", "args": {...}}`
|
|
122
|
-
|
|
123
|
-
#### metadata (optional)
|
|
124
|
-
|
|
125
|
-
- **Type:** object
|
|
126
|
-
- **Description:** Additional metadata
|
|
127
|
-
- **Fields:**
|
|
128
|
-
- `timestamp` - ISO 8601 timestamp
|
|
129
|
-
- `hookName` - Name of the hook
|
|
130
|
-
- `hookVersion` - Version of the hook
|
|
131
|
-
- `sessionId` - Current session ID
|
|
132
|
-
|
|
133
|
-
### Example Input
|
|
134
|
-
|
|
135
|
-
```json
|
|
136
|
-
{
|
|
137
|
-
"event": "pre-tool-call",
|
|
138
|
-
"context": {
|
|
139
|
-
"tool": "read-file",
|
|
140
|
-
"args": {
|
|
141
|
-
"path": "README.md"
|
|
142
|
-
},
|
|
143
|
-
"session": {
|
|
144
|
-
"id": "abc123",
|
|
145
|
-
"user": "developer",
|
|
146
|
-
"startTime": "2026-01-16T10:00:00Z"
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
"metadata": {
|
|
150
|
-
"timestamp": "2026-01-16T10:05:30Z",
|
|
151
|
-
"hookName": "safety-check",
|
|
152
|
-
"hookVersion": "1.0.0",
|
|
153
|
-
"sessionId": "abc123"
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
---
|
|
159
|
-
|
|
160
|
-
## Output Specification
|
|
161
|
-
|
|
162
|
-
### Output Schema
|
|
163
|
-
|
|
164
|
-
```json
|
|
165
|
-
{
|
|
166
|
-
"allow": "boolean (required)",
|
|
167
|
-
"message": "string (optional)",
|
|
168
|
-
"metadata": {
|
|
169
|
-
"...": "any additional data (optional)"
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Field Definitions
|
|
175
|
-
|
|
176
|
-
#### allow (required)
|
|
177
|
-
|
|
178
|
-
- **Type:** boolean
|
|
179
|
-
- **Description:** Whether to allow the operation
|
|
180
|
-
- **Values:**
|
|
181
|
-
- `true` - Allow operation to proceed
|
|
182
|
-
- `false` - Block operation
|
|
183
|
-
- **Example:** `true`
|
|
184
|
-
|
|
185
|
-
#### message (optional)
|
|
186
|
-
|
|
187
|
-
- **Type:** string
|
|
188
|
-
- **Description:** Human-readable message
|
|
189
|
-
- **Use Cases:**
|
|
190
|
-
- Success message
|
|
191
|
-
- Error explanation
|
|
192
|
-
- Warning message
|
|
193
|
-
- **Example:** `"Operation approved"`
|
|
194
|
-
|
|
195
|
-
#### metadata (optional)
|
|
196
|
-
|
|
197
|
-
- **Type:** object
|
|
198
|
-
- **Description:** Additional data to return
|
|
199
|
-
- **Contents:** Any JSON-serializable data
|
|
200
|
-
- **Use Cases:**
|
|
201
|
-
- Execution metrics
|
|
202
|
-
- Modified data
|
|
203
|
-
- Debug information
|
|
204
|
-
- **Example:** `{"duration": 0.05, "checked": true}`
|
|
205
|
-
|
|
206
|
-
### Example Output
|
|
207
|
-
|
|
208
|
-
**Success:**
|
|
209
|
-
|
|
210
|
-
```json
|
|
211
|
-
{
|
|
212
|
-
"allow": true,
|
|
213
|
-
"message": "Operation approved",
|
|
214
|
-
"metadata": {
|
|
215
|
-
"checked": true,
|
|
216
|
-
"duration": 0.05,
|
|
217
|
-
"timestamp": "2026-01-16T10:05:30Z"
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
**Blocked:**
|
|
223
|
-
|
|
224
|
-
```json
|
|
225
|
-
{
|
|
226
|
-
"allow": false,
|
|
227
|
-
"message": "Dangerous operation detected",
|
|
228
|
-
"metadata": {
|
|
229
|
-
"reason": "rm -rf detected",
|
|
230
|
-
"severity": "critical"
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
**Error:**
|
|
236
|
-
|
|
237
|
-
```json
|
|
238
|
-
{
|
|
239
|
-
"allow": false,
|
|
240
|
-
"message": "Hook execution failed: Invalid input",
|
|
241
|
-
"metadata": {
|
|
242
|
-
"error": "ValidationError",
|
|
243
|
-
"code": "INVALID_INPUT"
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
---
|
|
249
|
-
|
|
250
|
-
## Event Types
|
|
251
|
-
|
|
252
|
-
### pre-execution
|
|
253
|
-
|
|
254
|
-
**When:** Before LLM execution starts
|
|
255
|
-
|
|
256
|
-
**Context:**
|
|
257
|
-
|
|
258
|
-
```json
|
|
259
|
-
{
|
|
260
|
-
"prompt": "string",
|
|
261
|
-
"session": {
|
|
262
|
-
"id": "string",
|
|
263
|
-
"user": "string",
|
|
264
|
-
"startTime": "ISO 8601"
|
|
265
|
-
},
|
|
266
|
-
"config": {
|
|
267
|
-
"model": "string",
|
|
268
|
-
"temperature": "number"
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### post-execution
|
|
274
|
-
|
|
275
|
-
**When:** After LLM execution completes
|
|
276
|
-
|
|
277
|
-
**Context:**
|
|
278
|
-
|
|
279
|
-
```json
|
|
280
|
-
{
|
|
281
|
-
"prompt": "string",
|
|
282
|
-
"response": "string",
|
|
283
|
-
"session": {
|
|
284
|
-
"id": "string",
|
|
285
|
-
"user": "string"
|
|
286
|
-
},
|
|
287
|
-
"metrics": {
|
|
288
|
-
"duration": "number (seconds)",
|
|
289
|
-
"tokens": "number"
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### pre-tool-call
|
|
295
|
-
|
|
296
|
-
**When:** Before a tool is executed
|
|
297
|
-
|
|
298
|
-
**Context:**
|
|
299
|
-
|
|
300
|
-
```json
|
|
301
|
-
{
|
|
302
|
-
"tool": "string",
|
|
303
|
-
"args": "object",
|
|
304
|
-
"session": {
|
|
305
|
-
"id": "string",
|
|
306
|
-
"user": "string"
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### post-tool-call
|
|
312
|
-
|
|
313
|
-
**When:** After a tool is executed
|
|
314
|
-
|
|
315
|
-
**Context:**
|
|
316
|
-
|
|
317
|
-
```json
|
|
318
|
-
{
|
|
319
|
-
"tool": "string",
|
|
320
|
-
"args": "object",
|
|
321
|
-
"result": "any",
|
|
322
|
-
"metrics": {
|
|
323
|
-
"duration": "number (seconds)",
|
|
324
|
-
"success": "boolean"
|
|
325
|
-
},
|
|
326
|
-
"session": {
|
|
327
|
-
"id": "string"
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
### on-error
|
|
333
|
-
|
|
334
|
-
**When:** When an error occurs
|
|
335
|
-
|
|
336
|
-
**Context:**
|
|
337
|
-
|
|
338
|
-
```json
|
|
339
|
-
{
|
|
340
|
-
"error": {
|
|
341
|
-
"message": "string",
|
|
342
|
-
"code": "string",
|
|
343
|
-
"stack": "string"
|
|
344
|
-
},
|
|
345
|
-
"operation": "string",
|
|
346
|
-
"session": {
|
|
347
|
-
"id": "string"
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### on-file-change
|
|
353
|
-
|
|
354
|
-
**When:** When a file is modified
|
|
355
|
-
|
|
356
|
-
**Context:**
|
|
357
|
-
|
|
358
|
-
```json
|
|
359
|
-
{
|
|
360
|
-
"file": "string (path)",
|
|
361
|
-
"changes": {
|
|
362
|
-
"type": "string (created|modified|deleted)",
|
|
363
|
-
"size": "number (bytes)",
|
|
364
|
-
"timestamp": "ISO 8601"
|
|
365
|
-
},
|
|
366
|
-
"session": {
|
|
367
|
-
"id": "string"
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
```
|
|
371
|
-
|
|
372
|
-
### on-git-commit
|
|
373
|
-
|
|
374
|
-
**When:** Before a git commit
|
|
375
|
-
|
|
376
|
-
**Context:**
|
|
377
|
-
|
|
378
|
-
```json
|
|
379
|
-
{
|
|
380
|
-
"files": ["string (paths)"],
|
|
381
|
-
"message": "string (commit message)",
|
|
382
|
-
"branch": "string",
|
|
383
|
-
"session": {
|
|
384
|
-
"id": "string"
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
### on-session-start
|
|
390
|
-
|
|
391
|
-
**When:** When a session starts
|
|
392
|
-
|
|
393
|
-
**Context:**
|
|
394
|
-
|
|
395
|
-
```json
|
|
396
|
-
{
|
|
397
|
-
"session": {
|
|
398
|
-
"id": "string",
|
|
399
|
-
"user": "string",
|
|
400
|
-
"startTime": "ISO 8601",
|
|
401
|
-
"config": "object"
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
### on-session-end
|
|
407
|
-
|
|
408
|
-
**When:** When a session ends
|
|
409
|
-
|
|
410
|
-
**Context:**
|
|
411
|
-
|
|
412
|
-
```json
|
|
413
|
-
{
|
|
414
|
-
"session": {
|
|
415
|
-
"id": "string",
|
|
416
|
-
"user": "string",
|
|
417
|
-
"startTime": "ISO 8601",
|
|
418
|
-
"endTime": "ISO 8601",
|
|
419
|
-
"duration": "number (seconds)",
|
|
420
|
-
"messageCount": "number"
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
### on-context-overflow
|
|
426
|
-
|
|
427
|
-
**When:** When context is full
|
|
428
|
-
|
|
429
|
-
**Context:**
|
|
430
|
-
|
|
431
|
-
```json
|
|
432
|
-
{
|
|
433
|
-
"session": {
|
|
434
|
-
"id": "string"
|
|
435
|
-
},
|
|
436
|
-
"context": {
|
|
437
|
-
"size": "number (tokens)",
|
|
438
|
-
"maxSize": "number (tokens)",
|
|
439
|
-
"utilization": "number (0-1)"
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
### on-approval-request
|
|
445
|
-
|
|
446
|
-
**When:** When approval is needed
|
|
447
|
-
|
|
448
|
-
**Context:**
|
|
449
|
-
|
|
450
|
-
```json
|
|
451
|
-
{
|
|
452
|
-
"operation": "string",
|
|
453
|
-
"details": "object",
|
|
454
|
-
"requester": "string",
|
|
455
|
-
"session": {
|
|
456
|
-
"id": "string"
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
### custom
|
|
462
|
-
|
|
463
|
-
**When:** Custom events triggered by extensions
|
|
464
|
-
|
|
465
|
-
**Context:**
|
|
466
|
-
|
|
467
|
-
```json
|
|
468
|
-
{
|
|
469
|
-
"eventName": "string",
|
|
470
|
-
"data": "any",
|
|
471
|
-
"source": "string (extension name)",
|
|
472
|
-
"session": {
|
|
473
|
-
"id": "string"
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
---
|
|
479
|
-
|
|
480
|
-
## Error Handling
|
|
481
|
-
|
|
482
|
-
### Hook Errors
|
|
483
|
-
|
|
484
|
-
**Hook execution fails:**
|
|
485
|
-
|
|
486
|
-
- Hook returns non-zero exit code
|
|
487
|
-
- Hook times out
|
|
488
|
-
- Hook produces invalid JSON
|
|
489
|
-
- Hook crashes
|
|
490
|
-
|
|
491
|
-
**Behavior:**
|
|
492
|
-
|
|
493
|
-
- Operation is blocked (`allow: false`)
|
|
494
|
-
- Error message is logged
|
|
495
|
-
- User is notified
|
|
496
|
-
- Execution continues with next hook
|
|
497
|
-
|
|
498
|
-
### Invalid Input
|
|
499
|
-
|
|
500
|
-
**Hook receives invalid input:**
|
|
501
|
-
|
|
502
|
-
- Missing required fields
|
|
503
|
-
- Invalid JSON
|
|
504
|
-
- Unexpected event type
|
|
505
|
-
|
|
506
|
-
**Recommended behavior:**
|
|
507
|
-
|
|
508
|
-
- Return `allow: false`
|
|
509
|
-
- Include error message
|
|
510
|
-
- Log error details
|
|
511
|
-
|
|
512
|
-
**Example:**
|
|
513
|
-
|
|
514
|
-
```json
|
|
515
|
-
{
|
|
516
|
-
"allow": false,
|
|
517
|
-
"message": "Invalid input: missing required field 'event'",
|
|
518
|
-
"metadata": {
|
|
519
|
-
"error": "ValidationError",
|
|
520
|
-
"field": "event"
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
```
|
|
524
|
-
|
|
525
|
-
### Invalid Output
|
|
526
|
-
|
|
527
|
-
**Hook produces invalid output:**
|
|
528
|
-
|
|
529
|
-
- Invalid JSON
|
|
530
|
-
- Missing required fields
|
|
531
|
-
- Wrong data types
|
|
532
|
-
|
|
533
|
-
**Behavior:**
|
|
534
|
-
|
|
535
|
-
- Operation is blocked
|
|
536
|
-
- Error is logged
|
|
537
|
-
- User is notified
|
|
538
|
-
|
|
539
|
-
### Timeout Handling
|
|
540
|
-
|
|
541
|
-
**Hook exceeds timeout:**
|
|
542
|
-
|
|
543
|
-
- Hook process is terminated
|
|
544
|
-
- Operation is blocked
|
|
545
|
-
- Timeout error is logged
|
|
546
|
-
|
|
547
|
-
**Recommended timeout handling in hooks:**
|
|
548
|
-
|
|
549
|
-
```javascript
|
|
550
|
-
// Set internal timeout
|
|
551
|
-
const timeout = setTimeout(() => {
|
|
552
|
-
console.log(
|
|
553
|
-
JSON.stringify({
|
|
554
|
-
allow: false,
|
|
555
|
-
message: 'Hook timed out',
|
|
556
|
-
})
|
|
557
|
-
);
|
|
558
|
-
process.exit(1);
|
|
559
|
-
}, 4000); // 4 seconds (before 5 second system timeout)
|
|
560
|
-
|
|
561
|
-
// Clear timeout on completion
|
|
562
|
-
clearTimeout(timeout);
|
|
563
|
-
```
|
|
564
|
-
|
|
565
|
-
---
|
|
566
|
-
|
|
567
|
-
## Security Considerations
|
|
568
|
-
|
|
569
|
-
### Input Validation
|
|
570
|
-
|
|
571
|
-
**Always validate:**
|
|
572
|
-
|
|
573
|
-
- Event type is expected
|
|
574
|
-
- Required fields are present
|
|
575
|
-
- Data types are correct
|
|
576
|
-
- Values are within expected ranges
|
|
577
|
-
|
|
578
|
-
**Example:**
|
|
579
|
-
|
|
580
|
-
```javascript
|
|
581
|
-
function validateInput(input) {
|
|
582
|
-
if (!input.event) {
|
|
583
|
-
throw new Error('Missing event field');
|
|
584
|
-
}
|
|
585
|
-
if (!input.context) {
|
|
586
|
-
throw new Error('Missing context field');
|
|
587
|
-
}
|
|
588
|
-
// More validation...
|
|
589
|
-
}
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
### Output Sanitization
|
|
593
|
-
|
|
594
|
-
**Always sanitize:**
|
|
595
|
-
|
|
596
|
-
- Remove sensitive data
|
|
597
|
-
- Escape special characters
|
|
598
|
-
- Limit message length
|
|
599
|
-
- Validate JSON structure
|
|
600
|
-
|
|
601
|
-
### Command Injection
|
|
602
|
-
|
|
603
|
-
**Prevent command injection:**
|
|
604
|
-
|
|
605
|
-
- Never use `eval()` or `exec()`
|
|
606
|
-
- Sanitize file paths
|
|
607
|
-
- Validate command arguments
|
|
608
|
-
- Use safe APIs
|
|
609
|
-
|
|
610
|
-
**Bad:**
|
|
611
|
-
|
|
612
|
-
```bash
|
|
613
|
-
# DON'T DO THIS
|
|
614
|
-
file=$(echo "$input" | jq -r '.context.file')
|
|
615
|
-
eval "cat $file" # DANGEROUS!
|
|
616
|
-
```
|
|
617
|
-
|
|
618
|
-
**Good:**
|
|
619
|
-
|
|
620
|
-
```bash
|
|
621
|
-
# DO THIS
|
|
622
|
-
file=$(echo "$input" | jq -r '.context.file')
|
|
623
|
-
cat "$file" # Safe
|
|
624
|
-
```
|
|
625
|
-
|
|
626
|
-
### Resource Limits
|
|
627
|
-
|
|
628
|
-
**Implement limits:**
|
|
629
|
-
|
|
630
|
-
- Maximum execution time
|
|
631
|
-
- Maximum memory usage
|
|
632
|
-
- Maximum file size
|
|
633
|
-
- Maximum output size
|
|
634
|
-
|
|
635
|
-
### Privilege Separation
|
|
636
|
-
|
|
637
|
-
**Run with minimal privileges:**
|
|
638
|
-
|
|
639
|
-
- Don't run as root
|
|
640
|
-
- Use dedicated user account
|
|
641
|
-
- Limit file system access
|
|
642
|
-
- Restrict network access
|
|
643
|
-
|
|
644
|
-
---
|
|
645
|
-
|
|
646
|
-
## Versioning
|
|
647
|
-
|
|
648
|
-
### Protocol Version
|
|
649
|
-
|
|
650
|
-
Current version: **1.0.0**
|
|
651
|
-
|
|
652
|
-
### Version Negotiation
|
|
653
|
-
|
|
654
|
-
Future versions may include version field:
|
|
655
|
-
|
|
656
|
-
```json
|
|
657
|
-
{
|
|
658
|
-
"version": "1.0.0",
|
|
659
|
-
"event": "pre-tool-call",
|
|
660
|
-
"context": {...}
|
|
661
|
-
}
|
|
662
|
-
```
|
|
663
|
-
|
|
664
|
-
### Backward Compatibility
|
|
665
|
-
|
|
666
|
-
- New fields are optional
|
|
667
|
-
- Existing fields maintain meaning
|
|
668
|
-
- Deprecated fields are documented
|
|
669
|
-
- Breaking changes require major version bump
|
|
670
|
-
|
|
671
|
-
---
|
|
672
|
-
|
|
673
|
-
## Best Practices
|
|
674
|
-
|
|
675
|
-
### Performance
|
|
676
|
-
|
|
677
|
-
**Do:**
|
|
678
|
-
|
|
679
|
-
- ✅ Process input efficiently
|
|
680
|
-
- ✅ Return response quickly (< 1 second)
|
|
681
|
-
- ✅ Use streaming for large data
|
|
682
|
-
- ✅ Cache results when appropriate
|
|
683
|
-
|
|
684
|
-
**Don't:**
|
|
685
|
-
|
|
686
|
-
- ❌ Make blocking network calls
|
|
687
|
-
- ❌ Process large files synchronously
|
|
688
|
-
- ❌ Perform expensive computations
|
|
689
|
-
- ❌ Wait for user input
|
|
690
|
-
|
|
691
|
-
### Reliability
|
|
692
|
-
|
|
693
|
-
**Do:**
|
|
694
|
-
|
|
695
|
-
- ✅ Handle all error cases
|
|
696
|
-
- ✅ Validate all input
|
|
697
|
-
- ✅ Return valid JSON always
|
|
698
|
-
- ✅ Log errors appropriately
|
|
699
|
-
|
|
700
|
-
**Don't:**
|
|
701
|
-
|
|
702
|
-
- ❌ Crash on invalid input
|
|
703
|
-
- ❌ Return empty output
|
|
704
|
-
- ❌ Ignore errors silently
|
|
705
|
-
- ❌ Assume input is valid
|
|
706
|
-
|
|
707
|
-
### Security
|
|
708
|
-
|
|
709
|
-
**Do:**
|
|
710
|
-
|
|
711
|
-
- ✅ Validate and sanitize input
|
|
712
|
-
- ✅ Use safe APIs
|
|
713
|
-
- ✅ Limit resource usage
|
|
714
|
-
- ✅ Run with minimal privileges
|
|
715
|
-
|
|
716
|
-
**Don't:**
|
|
717
|
-
|
|
718
|
-
- ❌ Execute arbitrary code
|
|
719
|
-
- ❌ Trust user input
|
|
720
|
-
- ❌ Use eval or exec
|
|
721
|
-
- ❌ Access sensitive files
|
|
722
|
-
|
|
723
|
-
---
|
|
724
|
-
|
|
725
|
-
## Examples
|
|
726
|
-
|
|
727
|
-
### Minimal Hook
|
|
728
|
-
|
|
729
|
-
```bash
|
|
730
|
-
#!/bin/bash
|
|
731
|
-
cat | jq '{allow: true, message: "OK"}'
|
|
732
|
-
```
|
|
733
|
-
|
|
734
|
-
### Complete Hook
|
|
735
|
-
|
|
736
|
-
```javascript
|
|
737
|
-
#!/usr/bin/env node
|
|
738
|
-
|
|
739
|
-
const fs = require('fs');
|
|
740
|
-
|
|
741
|
-
try {
|
|
742
|
-
// Read and parse input
|
|
743
|
-
const input = JSON.parse(fs.readFileSync(0, 'utf-8'));
|
|
744
|
-
|
|
745
|
-
// Validate input
|
|
746
|
-
if (!input.event || !input.context) {
|
|
747
|
-
throw new Error('Invalid input');
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
// Process event
|
|
751
|
-
const result = processEvent(input);
|
|
752
|
-
|
|
753
|
-
// Return response
|
|
754
|
-
console.log(
|
|
755
|
-
JSON.stringify({
|
|
756
|
-
allow: result.success,
|
|
757
|
-
message: result.message,
|
|
758
|
-
metadata: {
|
|
759
|
-
duration: result.duration,
|
|
760
|
-
timestamp: new Date().toISOString(),
|
|
761
|
-
},
|
|
762
|
-
})
|
|
763
|
-
);
|
|
764
|
-
} catch (error) {
|
|
765
|
-
// Return error response
|
|
766
|
-
console.log(
|
|
767
|
-
JSON.stringify({
|
|
768
|
-
allow: false,
|
|
769
|
-
message: `Error: ${error.message}`,
|
|
770
|
-
metadata: {
|
|
771
|
-
error: error.name,
|
|
772
|
-
stack: error.stack,
|
|
773
|
-
},
|
|
774
|
-
})
|
|
775
|
-
);
|
|
776
|
-
process.exit(1);
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
function processEvent(input) {
|
|
780
|
-
const start = Date.now();
|
|
781
|
-
// Your logic here
|
|
782
|
-
return {
|
|
783
|
-
success: true,
|
|
784
|
-
message: 'Success',
|
|
785
|
-
duration: (Date.now() - start) / 1000,
|
|
786
|
-
};
|
|
787
|
-
}
|
|
788
|
-
```
|
|
789
|
-
|
|
790
|
-
---
|
|
791
|
-
|
|
792
|
-
## Further Reading
|
|
793
|
-
|
|
794
|
-
### Documentation
|
|
795
|
-
|
|
796
|
-
- [Hook System Overview](3%20projects/OLLM%20CLI/Hooks/README.md) - Introduction
|
|
797
|
-
- [Hook User Guide](3%20projects/OLLM%20CLI/Hooks/user-guide.md) - Using hooks
|
|
798
|
-
- [Hook Development Guide](3%20projects/OLLM%20CLI/Hooks/development-guide.md) - Creating hooks
|
|
799
|
-
- [MCP Architecture](MCP_architecture.md) - System architecture
|
|
800
|
-
|
|
801
|
-
### Standards
|
|
802
|
-
|
|
803
|
-
- JSON Specification (https://www.json.org/)
|
|
804
|
-
- ISO 8601 (Timestamps) (https://en.wikipedia.org/wiki/ISO_8601)
|
|
805
|
-
- UTF-8 Encoding (https://en.wikipedia.org/wiki/UTF-8)
|
|
806
|
-
|
|
807
|
-
### Tools
|
|
808
|
-
|
|
809
|
-
- jq Manual (https://stedolan.github.io/jq/manual/)
|
|
810
|
-
- JSON Schema (https://json-schema.org/)
|
|
811
|
-
- JSON Validator (https://jsonlint.com/)
|
|
812
|
-
|
|
813
|
-
---
|
|
814
|
-
|
|
815
|
-
**Last Updated:** 2026-01-16
|
|
816
|
-
**Version:** 1.0.0
|
|
817
|
-
**Protocol Version:** 1.0.0
|