@sparkleideas/shared 3.0.0-alpha.7
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 +323 -0
- package/__tests__/hooks/bash-safety.test.ts +289 -0
- package/__tests__/hooks/file-organization.test.ts +335 -0
- package/__tests__/hooks/git-commit.test.ts +336 -0
- package/__tests__/hooks/index.ts +23 -0
- package/__tests__/hooks/session-hooks.test.ts +357 -0
- package/__tests__/hooks/task-hooks.test.ts +193 -0
- package/docs/EVENTS_IMPLEMENTATION_SUMMARY.md +388 -0
- package/docs/EVENTS_QUICK_REFERENCE.md +470 -0
- package/docs/EVENTS_README.md +352 -0
- package/package.json +39 -0
- package/src/core/config/defaults.ts +207 -0
- package/src/core/config/index.ts +15 -0
- package/src/core/config/loader.ts +271 -0
- package/src/core/config/schema.ts +188 -0
- package/src/core/config/validator.ts +209 -0
- package/src/core/event-bus.ts +236 -0
- package/src/core/index.ts +22 -0
- package/src/core/interfaces/agent.interface.ts +251 -0
- package/src/core/interfaces/coordinator.interface.ts +363 -0
- package/src/core/interfaces/event.interface.ts +267 -0
- package/src/core/interfaces/index.ts +19 -0
- package/src/core/interfaces/memory.interface.ts +332 -0
- package/src/core/interfaces/task.interface.ts +223 -0
- package/src/core/orchestrator/event-coordinator.ts +122 -0
- package/src/core/orchestrator/health-monitor.ts +214 -0
- package/src/core/orchestrator/index.ts +89 -0
- package/src/core/orchestrator/lifecycle-manager.ts +263 -0
- package/src/core/orchestrator/session-manager.ts +279 -0
- package/src/core/orchestrator/task-manager.ts +317 -0
- package/src/events/domain-events.ts +584 -0
- package/src/events/event-store.test.ts +387 -0
- package/src/events/event-store.ts +588 -0
- package/src/events/example-usage.ts +293 -0
- package/src/events/index.ts +90 -0
- package/src/events/projections.ts +561 -0
- package/src/events/state-reconstructor.ts +349 -0
- package/src/events.ts +367 -0
- package/src/hooks/INTEGRATION.md +658 -0
- package/src/hooks/README.md +532 -0
- package/src/hooks/example-usage.ts +499 -0
- package/src/hooks/executor.ts +379 -0
- package/src/hooks/hooks.test.ts +421 -0
- package/src/hooks/index.ts +131 -0
- package/src/hooks/registry.ts +333 -0
- package/src/hooks/safety/bash-safety.ts +604 -0
- package/src/hooks/safety/file-organization.ts +473 -0
- package/src/hooks/safety/git-commit.ts +623 -0
- package/src/hooks/safety/index.ts +46 -0
- package/src/hooks/session-hooks.ts +559 -0
- package/src/hooks/task-hooks.ts +513 -0
- package/src/hooks/types.ts +357 -0
- package/src/hooks/verify-exports.test.ts +125 -0
- package/src/index.ts +195 -0
- package/src/mcp/connection-pool.ts +438 -0
- package/src/mcp/index.ts +183 -0
- package/src/mcp/server.ts +774 -0
- package/src/mcp/session-manager.ts +428 -0
- package/src/mcp/tool-registry.ts +566 -0
- package/src/mcp/transport/http.ts +557 -0
- package/src/mcp/transport/index.ts +294 -0
- package/src/mcp/transport/stdio.ts +324 -0
- package/src/mcp/transport/websocket.ts +484 -0
- package/src/mcp/types.ts +565 -0
- package/src/plugin-interface.ts +663 -0
- package/src/plugin-loader.ts +638 -0
- package/src/plugin-registry.ts +604 -0
- package/src/plugins/index.ts +34 -0
- package/src/plugins/official/hive-mind-plugin.ts +330 -0
- package/src/plugins/official/index.ts +24 -0
- package/src/plugins/official/maestro-plugin.ts +508 -0
- package/src/plugins/types.ts +108 -0
- package/src/resilience/bulkhead.ts +277 -0
- package/src/resilience/circuit-breaker.ts +326 -0
- package/src/resilience/index.ts +26 -0
- package/src/resilience/rate-limiter.ts +420 -0
- package/src/resilience/retry.ts +224 -0
- package/src/security/index.ts +39 -0
- package/src/security/input-validation.ts +265 -0
- package/src/security/secure-random.ts +159 -0
- package/src/services/index.ts +16 -0
- package/src/services/v3-progress.service.ts +505 -0
- package/src/types/agent.types.ts +144 -0
- package/src/types/index.ts +22 -0
- package/src/types/mcp.types.ts +300 -0
- package/src/types/memory.types.ts +263 -0
- package/src/types/swarm.types.ts +255 -0
- package/src/types/task.types.ts +205 -0
- package/src/types.ts +367 -0
- package/src/utils/secure-logger.d.ts +69 -0
- package/src/utils/secure-logger.d.ts.map +1 -0
- package/src/utils/secure-logger.js +208 -0
- package/src/utils/secure-logger.js.map +1 -0
- package/src/utils/secure-logger.ts +257 -0
- package/tmp.json +0 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Hooks System - Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Provides extensible hook points for tool execution, file operations,
|
|
5
|
+
* and session lifecycle events. Integrates with event bus for coordination.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/shared/hooks/types
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hook event types
|
|
12
|
+
*/
|
|
13
|
+
export enum HookEvent {
|
|
14
|
+
// Tool execution hooks
|
|
15
|
+
PreToolUse = 'hook:pre-tool-use',
|
|
16
|
+
PostToolUse = 'hook:post-tool-use',
|
|
17
|
+
|
|
18
|
+
// File operation hooks
|
|
19
|
+
PreEdit = 'hook:pre-edit',
|
|
20
|
+
PostEdit = 'hook:post-edit',
|
|
21
|
+
PreRead = 'hook:pre-read',
|
|
22
|
+
PostRead = 'hook:post-read',
|
|
23
|
+
PreWrite = 'hook:pre-write',
|
|
24
|
+
PostWrite = 'hook:post-write',
|
|
25
|
+
|
|
26
|
+
// Command execution hooks
|
|
27
|
+
PreCommand = 'hook:pre-command',
|
|
28
|
+
PostCommand = 'hook:post-command',
|
|
29
|
+
|
|
30
|
+
// Session lifecycle hooks
|
|
31
|
+
SessionStart = 'hook:session-start',
|
|
32
|
+
SessionEnd = 'hook:session-end',
|
|
33
|
+
SessionPause = 'hook:session-pause',
|
|
34
|
+
SessionResume = 'hook:session-resume',
|
|
35
|
+
|
|
36
|
+
// Agent lifecycle hooks
|
|
37
|
+
PreAgentSpawn = 'hook:pre-agent-spawn',
|
|
38
|
+
PostAgentSpawn = 'hook:post-agent-spawn',
|
|
39
|
+
PreAgentTerminate = 'hook:pre-agent-terminate',
|
|
40
|
+
PostAgentTerminate = 'hook:post-agent-terminate',
|
|
41
|
+
|
|
42
|
+
// Task lifecycle hooks
|
|
43
|
+
PreTaskExecute = 'hook:pre-task-execute',
|
|
44
|
+
PostTaskExecute = 'hook:post-task-execute',
|
|
45
|
+
PreTaskComplete = 'hook:pre-task-complete',
|
|
46
|
+
PostTaskComplete = 'hook:post-task-complete',
|
|
47
|
+
|
|
48
|
+
// Memory hooks
|
|
49
|
+
PreMemoryStore = 'hook:pre-memory-store',
|
|
50
|
+
PostMemoryStore = 'hook:post-memory-store',
|
|
51
|
+
PreMemoryRetrieve = 'hook:pre-memory-retrieve',
|
|
52
|
+
PostMemoryRetrieve = 'hook:post-memory-retrieve',
|
|
53
|
+
|
|
54
|
+
// Error hooks
|
|
55
|
+
OnError = 'hook:on-error',
|
|
56
|
+
OnWarning = 'hook:on-warning',
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Hook priority levels (higher = earlier execution)
|
|
61
|
+
*/
|
|
62
|
+
export enum HookPriority {
|
|
63
|
+
Critical = 1000,
|
|
64
|
+
High = 500,
|
|
65
|
+
Normal = 0,
|
|
66
|
+
Low = -500,
|
|
67
|
+
Lowest = -1000,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Tool information for tool-related hooks
|
|
72
|
+
*/
|
|
73
|
+
export interface ToolInfo {
|
|
74
|
+
/** Tool name (e.g., 'Read', 'Write', 'Bash') */
|
|
75
|
+
name: string;
|
|
76
|
+
|
|
77
|
+
/** Tool parameters */
|
|
78
|
+
parameters: Record<string, unknown>;
|
|
79
|
+
|
|
80
|
+
/** Estimated execution time in ms */
|
|
81
|
+
estimatedDuration?: number;
|
|
82
|
+
|
|
83
|
+
/** Tool category */
|
|
84
|
+
category?: 'file' | 'bash' | 'search' | 'edit' | 'git' | 'other';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Command information for command-related hooks
|
|
89
|
+
*/
|
|
90
|
+
export interface CommandInfo {
|
|
91
|
+
/** Command string */
|
|
92
|
+
command: string;
|
|
93
|
+
|
|
94
|
+
/** Working directory */
|
|
95
|
+
cwd?: string;
|
|
96
|
+
|
|
97
|
+
/** Environment variables */
|
|
98
|
+
env?: Record<string, string>;
|
|
99
|
+
|
|
100
|
+
/** Command timeout in ms */
|
|
101
|
+
timeout?: number;
|
|
102
|
+
|
|
103
|
+
/** Whether command is destructive */
|
|
104
|
+
isDestructive?: boolean;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* File operation information
|
|
109
|
+
*/
|
|
110
|
+
export interface FileOperationInfo {
|
|
111
|
+
/** File path */
|
|
112
|
+
path: string;
|
|
113
|
+
|
|
114
|
+
/** Operation type */
|
|
115
|
+
operation: 'read' | 'write' | 'edit' | 'delete';
|
|
116
|
+
|
|
117
|
+
/** File content (for write/edit operations) */
|
|
118
|
+
content?: string;
|
|
119
|
+
|
|
120
|
+
/** Previous content (for edit operations) */
|
|
121
|
+
previousContent?: string;
|
|
122
|
+
|
|
123
|
+
/** File size in bytes */
|
|
124
|
+
size?: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Session information
|
|
129
|
+
*/
|
|
130
|
+
export interface SessionInfo {
|
|
131
|
+
/** Session ID */
|
|
132
|
+
id: string;
|
|
133
|
+
|
|
134
|
+
/** Session start time */
|
|
135
|
+
startTime: Date;
|
|
136
|
+
|
|
137
|
+
/** Session end time */
|
|
138
|
+
endTime?: Date;
|
|
139
|
+
|
|
140
|
+
/** Session metadata */
|
|
141
|
+
metadata?: Record<string, unknown>;
|
|
142
|
+
|
|
143
|
+
/** User ID (if available) */
|
|
144
|
+
userId?: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Agent information
|
|
149
|
+
*/
|
|
150
|
+
export interface AgentInfo {
|
|
151
|
+
/** Agent ID */
|
|
152
|
+
id: string;
|
|
153
|
+
|
|
154
|
+
/** Agent type/role */
|
|
155
|
+
type: string;
|
|
156
|
+
|
|
157
|
+
/** Agent configuration */
|
|
158
|
+
config?: Record<string, unknown>;
|
|
159
|
+
|
|
160
|
+
/** Parent agent ID */
|
|
161
|
+
parentId?: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Task information
|
|
166
|
+
*/
|
|
167
|
+
export interface TaskInfo {
|
|
168
|
+
/** Task ID */
|
|
169
|
+
id: string;
|
|
170
|
+
|
|
171
|
+
/** Task description */
|
|
172
|
+
description: string;
|
|
173
|
+
|
|
174
|
+
/** Task priority */
|
|
175
|
+
priority?: number;
|
|
176
|
+
|
|
177
|
+
/** Assigned agent ID */
|
|
178
|
+
agentId?: string;
|
|
179
|
+
|
|
180
|
+
/** Task metadata */
|
|
181
|
+
metadata?: Record<string, unknown>;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Memory operation information
|
|
186
|
+
*/
|
|
187
|
+
export interface MemoryInfo {
|
|
188
|
+
/** Memory key */
|
|
189
|
+
key: string;
|
|
190
|
+
|
|
191
|
+
/** Memory value */
|
|
192
|
+
value?: unknown;
|
|
193
|
+
|
|
194
|
+
/** Memory namespace */
|
|
195
|
+
namespace?: string;
|
|
196
|
+
|
|
197
|
+
/** TTL in seconds */
|
|
198
|
+
ttl?: number;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Error information
|
|
203
|
+
*/
|
|
204
|
+
export interface ErrorInfo {
|
|
205
|
+
/** Error object */
|
|
206
|
+
error: Error;
|
|
207
|
+
|
|
208
|
+
/** Error context */
|
|
209
|
+
context?: string;
|
|
210
|
+
|
|
211
|
+
/** Error severity */
|
|
212
|
+
severity: 'warning' | 'error' | 'fatal';
|
|
213
|
+
|
|
214
|
+
/** Recoverable flag */
|
|
215
|
+
recoverable: boolean;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Hook context - contains information about the event being hooked
|
|
220
|
+
*/
|
|
221
|
+
export interface HookContext {
|
|
222
|
+
/** Event type */
|
|
223
|
+
event: HookEvent;
|
|
224
|
+
|
|
225
|
+
/** Timestamp when hook was triggered */
|
|
226
|
+
timestamp: Date;
|
|
227
|
+
|
|
228
|
+
/** Correlation ID for tracking related events */
|
|
229
|
+
correlationId?: string;
|
|
230
|
+
|
|
231
|
+
/** Tool information (for tool hooks) */
|
|
232
|
+
tool?: ToolInfo;
|
|
233
|
+
|
|
234
|
+
/** Command information (for command hooks) */
|
|
235
|
+
command?: CommandInfo;
|
|
236
|
+
|
|
237
|
+
/** File operation information (for file hooks) */
|
|
238
|
+
file?: FileOperationInfo;
|
|
239
|
+
|
|
240
|
+
/** Session information (for session hooks) */
|
|
241
|
+
session?: SessionInfo;
|
|
242
|
+
|
|
243
|
+
/** Agent information (for agent hooks) */
|
|
244
|
+
agent?: AgentInfo;
|
|
245
|
+
|
|
246
|
+
/** Task information (for task hooks) */
|
|
247
|
+
task?: TaskInfo;
|
|
248
|
+
|
|
249
|
+
/** Memory information (for memory hooks) */
|
|
250
|
+
memory?: MemoryInfo;
|
|
251
|
+
|
|
252
|
+
/** Error information (for error hooks) */
|
|
253
|
+
error?: ErrorInfo;
|
|
254
|
+
|
|
255
|
+
/** Additional metadata */
|
|
256
|
+
metadata?: Record<string, unknown>;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Hook result - returned by hook handlers
|
|
261
|
+
*/
|
|
262
|
+
export interface HookResult {
|
|
263
|
+
/** Whether the hook succeeded */
|
|
264
|
+
success: boolean;
|
|
265
|
+
|
|
266
|
+
/** Result data (can modify context) */
|
|
267
|
+
data?: Partial<HookContext>;
|
|
268
|
+
|
|
269
|
+
/** Error if hook failed */
|
|
270
|
+
error?: Error;
|
|
271
|
+
|
|
272
|
+
/** Whether to continue executing other hooks */
|
|
273
|
+
continueChain?: boolean;
|
|
274
|
+
|
|
275
|
+
/** Whether to abort the operation */
|
|
276
|
+
abort?: boolean;
|
|
277
|
+
|
|
278
|
+
/** Hook execution time in ms */
|
|
279
|
+
executionTime?: number;
|
|
280
|
+
|
|
281
|
+
/** Additional metadata */
|
|
282
|
+
metadata?: Record<string, unknown>;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Hook handler function type
|
|
287
|
+
*/
|
|
288
|
+
export type HookHandler = (context: HookContext) => Promise<HookResult> | HookResult;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Hook definition with metadata
|
|
292
|
+
*/
|
|
293
|
+
export interface HookDefinition {
|
|
294
|
+
/** Unique hook ID */
|
|
295
|
+
id: string;
|
|
296
|
+
|
|
297
|
+
/** Hook event type */
|
|
298
|
+
event: HookEvent;
|
|
299
|
+
|
|
300
|
+
/** Hook handler function */
|
|
301
|
+
handler: HookHandler;
|
|
302
|
+
|
|
303
|
+
/** Hook priority */
|
|
304
|
+
priority: HookPriority;
|
|
305
|
+
|
|
306
|
+
/** Hook name/description */
|
|
307
|
+
name?: string;
|
|
308
|
+
|
|
309
|
+
/** Whether hook is enabled */
|
|
310
|
+
enabled: boolean;
|
|
311
|
+
|
|
312
|
+
/** Hook timeout in ms */
|
|
313
|
+
timeout?: number;
|
|
314
|
+
|
|
315
|
+
/** Hook metadata */
|
|
316
|
+
metadata?: Record<string, unknown>;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Hook statistics
|
|
321
|
+
*/
|
|
322
|
+
export interface HookStats {
|
|
323
|
+
/** Total hooks registered */
|
|
324
|
+
totalHooks: number;
|
|
325
|
+
|
|
326
|
+
/** Hooks by event type */
|
|
327
|
+
byEvent: Record<HookEvent, number>;
|
|
328
|
+
|
|
329
|
+
/** Total executions */
|
|
330
|
+
totalExecutions: number;
|
|
331
|
+
|
|
332
|
+
/** Total failures */
|
|
333
|
+
totalFailures: number;
|
|
334
|
+
|
|
335
|
+
/** Average execution time in ms */
|
|
336
|
+
avgExecutionTime: number;
|
|
337
|
+
|
|
338
|
+
/** Total execution time in ms */
|
|
339
|
+
totalExecutionTime: number;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Hook execution options
|
|
344
|
+
*/
|
|
345
|
+
export interface HookExecutionOptions {
|
|
346
|
+
/** Timeout in ms (overrides hook-specific timeout) */
|
|
347
|
+
timeout?: number;
|
|
348
|
+
|
|
349
|
+
/** Whether to continue on error */
|
|
350
|
+
continueOnError?: boolean;
|
|
351
|
+
|
|
352
|
+
/** Maximum parallel executions */
|
|
353
|
+
maxParallel?: number;
|
|
354
|
+
|
|
355
|
+
/** Whether to collect results from all hooks */
|
|
356
|
+
collectResults?: boolean;
|
|
357
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Hooks System - Export Verification
|
|
3
|
+
*
|
|
4
|
+
* Verifies that all exports are accessible through the public API.
|
|
5
|
+
*
|
|
6
|
+
* @module v3/shared/hooks/verify-exports.test
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from 'vitest';
|
|
10
|
+
|
|
11
|
+
describe('Hooks Module Exports', () => {
|
|
12
|
+
it('should export all types from main module', async () => {
|
|
13
|
+
const module = await import('./index.js');
|
|
14
|
+
|
|
15
|
+
// Enums
|
|
16
|
+
expect(module.HookEvent).toBeDefined();
|
|
17
|
+
expect(module.HookPriority).toBeDefined();
|
|
18
|
+
|
|
19
|
+
// Classes
|
|
20
|
+
expect(module.HookRegistry).toBeDefined();
|
|
21
|
+
expect(module.HookExecutor).toBeDefined();
|
|
22
|
+
|
|
23
|
+
// Factory functions
|
|
24
|
+
expect(module.createHookRegistry).toBeDefined();
|
|
25
|
+
expect(module.createHookExecutor).toBeDefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should export types (type-only imports)', () => {
|
|
29
|
+
// This test just verifies TypeScript compilation
|
|
30
|
+
// Types can't be checked at runtime
|
|
31
|
+
type Test1 = import('./types.js').HookContext;
|
|
32
|
+
type Test2 = import('./types.js').HookResult;
|
|
33
|
+
type Test3 = import('./types.js').HookHandler;
|
|
34
|
+
type Test4 = import('./types.js').HookDefinition;
|
|
35
|
+
type Test5 = import('./types.js').HookStats;
|
|
36
|
+
type Test6 = import('./types.js').HookExecutionOptions;
|
|
37
|
+
type Test7 = import('./types.js').ToolInfo;
|
|
38
|
+
type Test8 = import('./types.js').CommandInfo;
|
|
39
|
+
type Test9 = import('./types.js').FileOperationInfo;
|
|
40
|
+
type Test10 = import('./types.js').SessionInfo;
|
|
41
|
+
type Test11 = import('./types.js').AgentInfo;
|
|
42
|
+
type Test12 = import('./types.js').TaskInfo;
|
|
43
|
+
type Test13 = import('./types.js').MemoryInfo;
|
|
44
|
+
type Test14 = import('./types.js').ErrorInfo;
|
|
45
|
+
|
|
46
|
+
expect(true).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should create instances from exported factories', () => {
|
|
50
|
+
const { createHookRegistry, createHookExecutor } = require('./index.js');
|
|
51
|
+
|
|
52
|
+
const registry = createHookRegistry();
|
|
53
|
+
expect(registry).toBeDefined();
|
|
54
|
+
expect(typeof registry.register).toBe('function');
|
|
55
|
+
expect(typeof registry.unregister).toBe('function');
|
|
56
|
+
|
|
57
|
+
const executor = createHookExecutor(registry);
|
|
58
|
+
expect(executor).toBeDefined();
|
|
59
|
+
expect(typeof executor.execute).toBe('function');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should have all 26 hook events defined', () => {
|
|
63
|
+
const { HookEvent } = require('./index.js');
|
|
64
|
+
|
|
65
|
+
const expectedEvents = [
|
|
66
|
+
'PreToolUse',
|
|
67
|
+
'PostToolUse',
|
|
68
|
+
'PreEdit',
|
|
69
|
+
'PostEdit',
|
|
70
|
+
'PreRead',
|
|
71
|
+
'PostRead',
|
|
72
|
+
'PreWrite',
|
|
73
|
+
'PostWrite',
|
|
74
|
+
'PreCommand',
|
|
75
|
+
'PostCommand',
|
|
76
|
+
'SessionStart',
|
|
77
|
+
'SessionEnd',
|
|
78
|
+
'SessionPause',
|
|
79
|
+
'SessionResume',
|
|
80
|
+
'PreAgentSpawn',
|
|
81
|
+
'PostAgentSpawn',
|
|
82
|
+
'PreAgentTerminate',
|
|
83
|
+
'PostAgentTerminate',
|
|
84
|
+
'PreTaskExecute',
|
|
85
|
+
'PostTaskExecute',
|
|
86
|
+
'PreTaskComplete',
|
|
87
|
+
'PostTaskComplete',
|
|
88
|
+
'PreMemoryStore',
|
|
89
|
+
'PostMemoryStore',
|
|
90
|
+
'PreMemoryRetrieve',
|
|
91
|
+
'PostMemoryRetrieve',
|
|
92
|
+
'OnError',
|
|
93
|
+
'OnWarning',
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
for (const event of expectedEvents) {
|
|
97
|
+
expect(HookEvent[event]).toBeDefined();
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should have all 5 priority levels defined', () => {
|
|
102
|
+
const { HookPriority } = require('./index.js');
|
|
103
|
+
|
|
104
|
+
expect(HookPriority.Critical).toBe(1000);
|
|
105
|
+
expect(HookPriority.High).toBe(500);
|
|
106
|
+
expect(HookPriority.Normal).toBe(0);
|
|
107
|
+
expect(HookPriority.Low).toBe(-500);
|
|
108
|
+
expect(HookPriority.Lowest).toBe(-1000);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('Hooks Integration with Shared Module', () => {
|
|
113
|
+
it('should be importable from @sparkleideas/shared', async () => {
|
|
114
|
+
// This would be the actual import path in production
|
|
115
|
+
const module = await import('../index.js');
|
|
116
|
+
|
|
117
|
+
// Verify hooks are exported from main shared module
|
|
118
|
+
expect(module.HookEvent).toBeDefined();
|
|
119
|
+
expect(module.HookPriority).toBeDefined();
|
|
120
|
+
expect(module.HookRegistry).toBeDefined();
|
|
121
|
+
expect(module.HookExecutor).toBeDefined();
|
|
122
|
+
expect(module.createHookRegistry).toBeDefined();
|
|
123
|
+
expect(module.createHookExecutor).toBeDefined();
|
|
124
|
+
});
|
|
125
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @sparkleideas/shared - Shared Module
|
|
3
|
+
* Common types, events, utilities, and core interfaces for V3 Claude-Flow
|
|
4
|
+
*
|
|
5
|
+
* Based on ADR-002 (DDD) and ADR-006 (Unified Memory Service)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Types - Primary type definitions (from ./types.js)
|
|
10
|
+
// =============================================================================
|
|
11
|
+
export * from './types.js';
|
|
12
|
+
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Events - Event bus and basic event interfaces (from ./events.js)
|
|
15
|
+
// =============================================================================
|
|
16
|
+
export { EventBus } from './events.js';
|
|
17
|
+
export type { IEventBus, EventFilter } from './events.js';
|
|
18
|
+
|
|
19
|
+
// =============================================================================
|
|
20
|
+
// Event Sourcing - ADR-007 Domain events and event store
|
|
21
|
+
// (from ./events/index.js - no duplicates with ./events.js)
|
|
22
|
+
// =============================================================================
|
|
23
|
+
export type {
|
|
24
|
+
DomainEvent,
|
|
25
|
+
AllDomainEvents,
|
|
26
|
+
AgentSpawnedEvent,
|
|
27
|
+
AgentStartedEvent,
|
|
28
|
+
AgentStoppedEvent,
|
|
29
|
+
AgentFailedEvent,
|
|
30
|
+
AgentStatusChangedEvent,
|
|
31
|
+
AgentTaskAssignedEvent,
|
|
32
|
+
AgentTaskCompletedEvent,
|
|
33
|
+
TaskCreatedEvent,
|
|
34
|
+
TaskStartedEvent,
|
|
35
|
+
TaskCompletedEvent,
|
|
36
|
+
TaskFailedEvent,
|
|
37
|
+
TaskBlockedEvent,
|
|
38
|
+
TaskQueuedEvent,
|
|
39
|
+
MemoryStoredEvent,
|
|
40
|
+
MemoryRetrievedEvent,
|
|
41
|
+
MemoryDeletedEvent,
|
|
42
|
+
MemoryExpiredEvent,
|
|
43
|
+
SwarmInitializedEvent,
|
|
44
|
+
SwarmScaledEvent,
|
|
45
|
+
SwarmTerminatedEvent,
|
|
46
|
+
SwarmPhaseChangedEvent,
|
|
47
|
+
SwarmMilestoneReachedEvent,
|
|
48
|
+
SwarmErrorEvent,
|
|
49
|
+
EventStoreConfig,
|
|
50
|
+
EventSnapshot,
|
|
51
|
+
EventStoreStats,
|
|
52
|
+
AgentProjectionState,
|
|
53
|
+
TaskProjectionState,
|
|
54
|
+
MemoryProjectionState,
|
|
55
|
+
AggregateRoot,
|
|
56
|
+
ReconstructorOptions,
|
|
57
|
+
} from './events/index.js';
|
|
58
|
+
|
|
59
|
+
export {
|
|
60
|
+
createAgentSpawnedEvent,
|
|
61
|
+
createAgentStartedEvent,
|
|
62
|
+
createAgentStoppedEvent,
|
|
63
|
+
createAgentFailedEvent,
|
|
64
|
+
createTaskCreatedEvent,
|
|
65
|
+
createTaskStartedEvent,
|
|
66
|
+
createTaskCompletedEvent,
|
|
67
|
+
createTaskFailedEvent,
|
|
68
|
+
createMemoryStoredEvent,
|
|
69
|
+
createMemoryRetrievedEvent,
|
|
70
|
+
createMemoryDeletedEvent,
|
|
71
|
+
createSwarmInitializedEvent,
|
|
72
|
+
createSwarmScaledEvent,
|
|
73
|
+
createSwarmTerminatedEvent,
|
|
74
|
+
EventStore,
|
|
75
|
+
Projection,
|
|
76
|
+
AgentStateProjection,
|
|
77
|
+
TaskHistoryProjection,
|
|
78
|
+
MemoryIndexProjection,
|
|
79
|
+
StateReconstructor,
|
|
80
|
+
createStateReconstructor,
|
|
81
|
+
AgentAggregate,
|
|
82
|
+
TaskAggregate,
|
|
83
|
+
} from './events/index.js';
|
|
84
|
+
|
|
85
|
+
// =============================================================================
|
|
86
|
+
// Plugin System - ADR-004
|
|
87
|
+
// =============================================================================
|
|
88
|
+
export * from './plugin-loader.js';
|
|
89
|
+
export * from './plugin-registry.js';
|
|
90
|
+
|
|
91
|
+
// =============================================================================
|
|
92
|
+
// Core - DDD interfaces, config, orchestrator
|
|
93
|
+
// Note: Only export non-overlapping items from core to avoid duplicates with types.js
|
|
94
|
+
// =============================================================================
|
|
95
|
+
export {
|
|
96
|
+
// Event Bus
|
|
97
|
+
createEventBus,
|
|
98
|
+
// Orchestrator
|
|
99
|
+
createOrchestrator,
|
|
100
|
+
TaskManager,
|
|
101
|
+
SessionManager,
|
|
102
|
+
HealthMonitor,
|
|
103
|
+
LifecycleManager,
|
|
104
|
+
EventCoordinator,
|
|
105
|
+
// Config validation/loading
|
|
106
|
+
ConfigLoader,
|
|
107
|
+
loadConfig,
|
|
108
|
+
ConfigValidator,
|
|
109
|
+
validateAgentConfig,
|
|
110
|
+
validateTaskConfig,
|
|
111
|
+
validateSwarmConfig,
|
|
112
|
+
validateMemoryConfig,
|
|
113
|
+
validateMCPServerConfig,
|
|
114
|
+
validateOrchestratorConfig,
|
|
115
|
+
validateSystemConfig,
|
|
116
|
+
// Defaults
|
|
117
|
+
defaultAgentConfig,
|
|
118
|
+
defaultTaskConfig,
|
|
119
|
+
defaultSwarmConfigCore,
|
|
120
|
+
defaultMemoryConfig,
|
|
121
|
+
defaultMCPServerConfig,
|
|
122
|
+
defaultOrchestratorConfig,
|
|
123
|
+
defaultSystemConfig,
|
|
124
|
+
agentTypePresets,
|
|
125
|
+
mergeWithDefaults,
|
|
126
|
+
} from './core/index.js';
|
|
127
|
+
|
|
128
|
+
export type {
|
|
129
|
+
// Config types
|
|
130
|
+
LoadedConfig,
|
|
131
|
+
ConfigSource,
|
|
132
|
+
ValidationResult,
|
|
133
|
+
ValidationError,
|
|
134
|
+
// Orchestrator types
|
|
135
|
+
OrchestratorFacadeConfig,
|
|
136
|
+
OrchestratorComponents,
|
|
137
|
+
SessionManagerConfig,
|
|
138
|
+
HealthMonitorConfig,
|
|
139
|
+
LifecycleManagerConfig,
|
|
140
|
+
// Schema types (from config - note these extend the basic types from types.js)
|
|
141
|
+
AgentConfig,
|
|
142
|
+
TaskConfig,
|
|
143
|
+
SwarmConfig as SwarmConfigSchema,
|
|
144
|
+
MemoryConfig,
|
|
145
|
+
MCPServerConfig,
|
|
146
|
+
OrchestratorConfig,
|
|
147
|
+
SystemConfig,
|
|
148
|
+
AgentConfigInput,
|
|
149
|
+
TaskConfigInput,
|
|
150
|
+
SwarmConfigInput,
|
|
151
|
+
MemoryConfigInput,
|
|
152
|
+
MCPServerConfigInput,
|
|
153
|
+
OrchestratorConfigInput,
|
|
154
|
+
SystemConfigInput,
|
|
155
|
+
// Interface types
|
|
156
|
+
ITask,
|
|
157
|
+
ITaskCreate,
|
|
158
|
+
ITaskResult,
|
|
159
|
+
IAgent,
|
|
160
|
+
IAgentConfig,
|
|
161
|
+
IEventBus as ICoreEventBus,
|
|
162
|
+
IMemoryBackend as ICoreMemoryBackend,
|
|
163
|
+
ISwarmConfig,
|
|
164
|
+
ISwarmState,
|
|
165
|
+
ICoordinator,
|
|
166
|
+
ICoordinationManager,
|
|
167
|
+
IHealthStatus,
|
|
168
|
+
IComponentHealth,
|
|
169
|
+
IHealthMonitor,
|
|
170
|
+
IMetricsCollector,
|
|
171
|
+
IOrchestratorMetrics,
|
|
172
|
+
IOrchestrator,
|
|
173
|
+
SwarmTopology,
|
|
174
|
+
CoordinationStatus,
|
|
175
|
+
} from './core/index.js';
|
|
176
|
+
|
|
177
|
+
// =============================================================================
|
|
178
|
+
// Hooks System
|
|
179
|
+
// =============================================================================
|
|
180
|
+
export * from './hooks/index.js';
|
|
181
|
+
|
|
182
|
+
// =============================================================================
|
|
183
|
+
// Security Utilities
|
|
184
|
+
// =============================================================================
|
|
185
|
+
export * from './security/index.js';
|
|
186
|
+
|
|
187
|
+
// =============================================================================
|
|
188
|
+
// Resilience Patterns
|
|
189
|
+
// =============================================================================
|
|
190
|
+
export * from './resilience/index.js';
|
|
191
|
+
|
|
192
|
+
// =============================================================================
|
|
193
|
+
// Services
|
|
194
|
+
// =============================================================================
|
|
195
|
+
export * from './services/index.js';
|