moflo 4.8.17 → 4.8.20
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/.claude/guidance/shipped/moflo.md +45 -0
- package/.claude/helpers/statusline.cjs +1 -1
- package/.claude/workflow-state.json +9 -0
- package/bin/generate-code-map.mjs +91 -12
- package/package.json +2 -2
- package/src/@claude-flow/cli/bin/cli.js +5 -0
- package/src/@claude-flow/cli/dist/src/init/moflo-init.js +9 -0
- package/src/@claude-flow/cli/dist/src/init/statusline-generator.js +1 -1
- package/src/@claude-flow/cli/dist/src/services/agentic-flow-bridge.js +8 -0
- package/src/@claude-flow/cli/package.json +1 -1
- package/src/@claude-flow/memory/dist/agent-memory-scope.d.ts +131 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.js +223 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/agent-memory-scope.test.js +466 -0
- package/src/@claude-flow/memory/dist/agentdb-adapter.d.ts +165 -0
- package/src/@claude-flow/memory/dist/agentdb-adapter.js +806 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.d.ts +212 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.js +842 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.test.d.ts +7 -0
- package/src/@claude-flow/memory/dist/agentdb-backend.test.js +258 -0
- package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.d.ts +65 -0
- package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.js +129 -0
- package/src/@claude-flow/memory/dist/application/commands/store-memory.command.d.ts +48 -0
- package/src/@claude-flow/memory/dist/application/commands/store-memory.command.js +72 -0
- package/src/@claude-flow/memory/dist/application/index.d.ts +12 -0
- package/src/@claude-flow/memory/dist/application/index.js +15 -0
- package/src/@claude-flow/memory/dist/application/queries/search-memory.query.d.ts +72 -0
- package/src/@claude-flow/memory/dist/application/queries/search-memory.query.js +143 -0
- package/src/@claude-flow/memory/dist/application/services/memory-application-service.d.ts +121 -0
- package/src/@claude-flow/memory/dist/application/services/memory-application-service.js +190 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.d.ts +226 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.js +709 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/auto-memory-bridge.test.js +757 -0
- package/src/@claude-flow/memory/dist/benchmark.test.d.ts +2 -0
- package/src/@claude-flow/memory/dist/benchmark.test.js +277 -0
- package/src/@claude-flow/memory/dist/cache-manager.d.ts +134 -0
- package/src/@claude-flow/memory/dist/cache-manager.js +407 -0
- package/src/@claude-flow/memory/dist/controller-registry.d.ts +216 -0
- package/src/@claude-flow/memory/dist/controller-registry.js +893 -0
- package/src/@claude-flow/memory/dist/controller-registry.test.d.ts +14 -0
- package/src/@claude-flow/memory/dist/controller-registry.test.js +593 -0
- package/src/@claude-flow/memory/dist/database-provider.d.ts +87 -0
- package/src/@claude-flow/memory/dist/database-provider.js +372 -0
- package/src/@claude-flow/memory/dist/database-provider.test.d.ts +7 -0
- package/src/@claude-flow/memory/dist/database-provider.test.js +287 -0
- package/src/@claude-flow/memory/dist/domain/entities/memory-entry.d.ts +143 -0
- package/src/@claude-flow/memory/dist/domain/entities/memory-entry.js +226 -0
- package/src/@claude-flow/memory/dist/domain/index.d.ts +11 -0
- package/src/@claude-flow/memory/dist/domain/index.js +12 -0
- package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
- package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.js +11 -0
- package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.d.ts +105 -0
- package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.js +297 -0
- package/src/@claude-flow/memory/dist/hnsw-index.d.ts +111 -0
- package/src/@claude-flow/memory/dist/hnsw-index.js +781 -0
- package/src/@claude-flow/memory/dist/hnsw-lite.d.ts +23 -0
- package/src/@claude-flow/memory/dist/hnsw-lite.js +168 -0
- package/src/@claude-flow/memory/dist/index.d.ts +204 -0
- package/src/@claude-flow/memory/dist/index.js +358 -0
- package/src/@claude-flow/memory/dist/infrastructure/index.d.ts +17 -0
- package/src/@claude-flow/memory/dist/infrastructure/index.js +16 -0
- package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
- package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
- package/src/@claude-flow/memory/dist/learning-bridge.d.ts +137 -0
- package/src/@claude-flow/memory/dist/learning-bridge.js +335 -0
- package/src/@claude-flow/memory/dist/learning-bridge.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/learning-bridge.test.js +578 -0
- package/src/@claude-flow/memory/dist/memory-graph.d.ts +100 -0
- package/src/@claude-flow/memory/dist/memory-graph.js +333 -0
- package/src/@claude-flow/memory/dist/memory-graph.test.d.ts +8 -0
- package/src/@claude-flow/memory/dist/memory-graph.test.js +609 -0
- package/src/@claude-flow/memory/dist/migration.d.ts +68 -0
- package/src/@claude-flow/memory/dist/migration.js +513 -0
- package/src/@claude-flow/memory/dist/persistent-sona.d.ts +144 -0
- package/src/@claude-flow/memory/dist/persistent-sona.js +332 -0
- package/src/@claude-flow/memory/dist/query-builder.d.ts +211 -0
- package/src/@claude-flow/memory/dist/query-builder.js +438 -0
- package/src/@claude-flow/memory/dist/rvf-backend.d.ts +51 -0
- package/src/@claude-flow/memory/dist/rvf-backend.js +481 -0
- package/src/@claude-flow/memory/dist/rvf-learning-store.d.ts +139 -0
- package/src/@claude-flow/memory/dist/rvf-learning-store.js +295 -0
- package/src/@claude-flow/memory/dist/rvf-migration.d.ts +45 -0
- package/src/@claude-flow/memory/dist/rvf-migration.js +234 -0
- package/src/@claude-flow/memory/dist/sqljs-backend.d.ts +127 -0
- package/src/@claude-flow/memory/dist/sqljs-backend.js +600 -0
- package/src/@claude-flow/memory/dist/types.d.ts +484 -0
- package/src/@claude-flow/memory/dist/types.js +58 -0
- package/src/@claude-flow/shared/dist/core/config/defaults.d.ts +41 -0
- package/src/@claude-flow/shared/dist/core/config/defaults.js +186 -0
- package/src/@claude-flow/shared/dist/core/config/index.d.ts +8 -0
- package/src/@claude-flow/shared/dist/core/config/index.js +12 -0
- package/src/@claude-flow/shared/dist/core/config/loader.d.ts +45 -0
- package/src/@claude-flow/shared/dist/core/config/loader.js +222 -0
- package/src/@claude-flow/shared/dist/core/config/schema.d.ts +1134 -0
- package/src/@claude-flow/shared/dist/core/config/schema.js +158 -0
- package/src/@claude-flow/shared/dist/core/config/validator.d.ts +92 -0
- package/src/@claude-flow/shared/dist/core/config/validator.js +147 -0
- package/src/@claude-flow/shared/dist/core/event-bus.d.ts +31 -0
- package/src/@claude-flow/shared/dist/core/event-bus.js +197 -0
- package/src/@claude-flow/shared/dist/core/index.d.ts +15 -0
- package/src/@claude-flow/shared/dist/core/index.js +19 -0
- package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.d.ts +200 -0
- package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.js +6 -0
- package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.d.ts +310 -0
- package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.js +7 -0
- package/src/@claude-flow/shared/dist/core/interfaces/event.interface.d.ts +224 -0
- package/src/@claude-flow/shared/dist/core/interfaces/event.interface.js +46 -0
- package/src/@claude-flow/shared/dist/core/interfaces/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/core/interfaces/index.js +15 -0
- package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.d.ts +298 -0
- package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.js +7 -0
- package/src/@claude-flow/shared/dist/core/interfaces/task.interface.d.ts +185 -0
- package/src/@claude-flow/shared/dist/core/interfaces/task.interface.js +6 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.d.ts +35 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.js +101 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.d.ts +60 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.js +166 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/index.d.ts +46 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/index.js +64 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.d.ts +56 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.js +195 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.d.ts +83 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.js +193 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.d.ts +49 -0
- package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.js +253 -0
- package/src/@claude-flow/shared/dist/events/domain-events.d.ts +282 -0
- package/src/@claude-flow/shared/dist/events/domain-events.js +165 -0
- package/src/@claude-flow/shared/dist/events/event-store.d.ts +126 -0
- package/src/@claude-flow/shared/dist/events/event-store.js +432 -0
- package/src/@claude-flow/shared/dist/events/event-store.test.d.ts +8 -0
- package/src/@claude-flow/shared/dist/events/event-store.test.js +297 -0
- package/src/@claude-flow/shared/dist/events/example-usage.d.ts +10 -0
- package/src/@claude-flow/shared/dist/events/example-usage.js +193 -0
- package/src/@claude-flow/shared/dist/events/index.d.ts +21 -0
- package/src/@claude-flow/shared/dist/events/index.js +22 -0
- package/src/@claude-flow/shared/dist/events/projections.d.ts +177 -0
- package/src/@claude-flow/shared/dist/events/projections.js +421 -0
- package/src/@claude-flow/shared/dist/events/rvf-event-log.d.ts +82 -0
- package/src/@claude-flow/shared/dist/events/rvf-event-log.js +340 -0
- package/src/@claude-flow/shared/dist/events/state-reconstructor.d.ts +101 -0
- package/src/@claude-flow/shared/dist/events/state-reconstructor.js +263 -0
- package/src/@claude-flow/shared/dist/events.d.ts +80 -0
- package/src/@claude-flow/shared/dist/events.js +249 -0
- package/src/@claude-flow/shared/dist/hooks/example-usage.d.ts +42 -0
- package/src/@claude-flow/shared/dist/hooks/example-usage.js +351 -0
- package/src/@claude-flow/shared/dist/hooks/executor.d.ts +100 -0
- package/src/@claude-flow/shared/dist/hooks/executor.js +267 -0
- package/src/@claude-flow/shared/dist/hooks/hooks.test.d.ts +9 -0
- package/src/@claude-flow/shared/dist/hooks/hooks.test.js +322 -0
- package/src/@claude-flow/shared/dist/hooks/index.d.ts +52 -0
- package/src/@claude-flow/shared/dist/hooks/index.js +51 -0
- package/src/@claude-flow/shared/dist/hooks/registry.d.ts +133 -0
- package/src/@claude-flow/shared/dist/hooks/registry.js +277 -0
- package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.d.ts +105 -0
- package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.js +481 -0
- package/src/@claude-flow/shared/dist/hooks/safety/file-organization.d.ts +144 -0
- package/src/@claude-flow/shared/dist/hooks/safety/file-organization.js +328 -0
- package/src/@claude-flow/shared/dist/hooks/safety/git-commit.d.ts +158 -0
- package/src/@claude-flow/shared/dist/hooks/safety/git-commit.js +450 -0
- package/src/@claude-flow/shared/dist/hooks/safety/index.d.ts +17 -0
- package/src/@claude-flow/shared/dist/hooks/safety/index.js +17 -0
- package/src/@claude-flow/shared/dist/hooks/session-hooks.d.ts +234 -0
- package/src/@claude-flow/shared/dist/hooks/session-hooks.js +334 -0
- package/src/@claude-flow/shared/dist/hooks/task-hooks.d.ts +163 -0
- package/src/@claude-flow/shared/dist/hooks/task-hooks.js +326 -0
- package/src/@claude-flow/shared/dist/hooks/types.d.ts +267 -0
- package/src/@claude-flow/shared/dist/hooks/types.js +62 -0
- package/src/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +9 -0
- package/src/@claude-flow/shared/dist/hooks/verify-exports.test.js +93 -0
- package/src/@claude-flow/shared/dist/index.d.ts +20 -0
- package/src/@claude-flow/shared/dist/index.js +50 -0
- package/src/@claude-flow/shared/dist/mcp/connection-pool.d.ts +98 -0
- package/src/@claude-flow/shared/dist/mcp/connection-pool.js +364 -0
- package/src/@claude-flow/shared/dist/mcp/index.d.ts +69 -0
- package/src/@claude-flow/shared/dist/mcp/index.js +84 -0
- package/src/@claude-flow/shared/dist/mcp/server.d.ts +166 -0
- package/src/@claude-flow/shared/dist/mcp/server.js +593 -0
- package/src/@claude-flow/shared/dist/mcp/session-manager.d.ts +136 -0
- package/src/@claude-flow/shared/dist/mcp/session-manager.js +335 -0
- package/src/@claude-flow/shared/dist/mcp/tool-registry.d.ts +178 -0
- package/src/@claude-flow/shared/dist/mcp/tool-registry.js +439 -0
- package/src/@claude-flow/shared/dist/mcp/transport/http.d.ts +104 -0
- package/src/@claude-flow/shared/dist/mcp/transport/http.js +476 -0
- package/src/@claude-flow/shared/dist/mcp/transport/index.d.ts +102 -0
- package/src/@claude-flow/shared/dist/mcp/transport/index.js +238 -0
- package/src/@claude-flow/shared/dist/mcp/transport/stdio.d.ts +104 -0
- package/src/@claude-flow/shared/dist/mcp/transport/stdio.js +263 -0
- package/src/@claude-flow/shared/dist/mcp/transport/websocket.d.ts +133 -0
- package/src/@claude-flow/shared/dist/mcp/transport/websocket.js +396 -0
- package/src/@claude-flow/shared/dist/mcp/types.d.ts +438 -0
- package/src/@claude-flow/shared/dist/mcp/types.js +54 -0
- package/src/@claude-flow/shared/dist/plugin-interface.d.ts +544 -0
- package/src/@claude-flow/shared/dist/plugin-interface.js +23 -0
- package/src/@claude-flow/shared/dist/plugin-loader.d.ts +139 -0
- package/src/@claude-flow/shared/dist/plugin-loader.js +434 -0
- package/src/@claude-flow/shared/dist/plugin-registry.d.ts +183 -0
- package/src/@claude-flow/shared/dist/plugin-registry.js +457 -0
- package/src/@claude-flow/shared/dist/plugins/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/plugins/index.js +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.d.ts +106 -0
- package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.js +241 -0
- package/src/@claude-flow/shared/dist/plugins/official/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/index.js +10 -0
- package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.d.ts +121 -0
- package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.js +355 -0
- package/src/@claude-flow/shared/dist/plugins/types.d.ts +93 -0
- package/src/@claude-flow/shared/dist/plugins/types.js +9 -0
- package/src/@claude-flow/shared/dist/resilience/bulkhead.d.ts +105 -0
- package/src/@claude-flow/shared/dist/resilience/bulkhead.js +206 -0
- package/src/@claude-flow/shared/dist/resilience/circuit-breaker.d.ts +132 -0
- package/src/@claude-flow/shared/dist/resilience/circuit-breaker.js +233 -0
- package/src/@claude-flow/shared/dist/resilience/index.d.ts +19 -0
- package/src/@claude-flow/shared/dist/resilience/index.js +19 -0
- package/src/@claude-flow/shared/dist/resilience/rate-limiter.d.ts +168 -0
- package/src/@claude-flow/shared/dist/resilience/rate-limiter.js +314 -0
- package/src/@claude-flow/shared/dist/resilience/retry.d.ts +91 -0
- package/src/@claude-flow/shared/dist/resilience/retry.js +159 -0
- package/src/@claude-flow/shared/dist/security/index.d.ts +10 -0
- package/src/@claude-flow/shared/dist/security/index.js +12 -0
- package/src/@claude-flow/shared/dist/security/input-validation.d.ts +73 -0
- package/src/@claude-flow/shared/dist/security/input-validation.js +201 -0
- package/src/@claude-flow/shared/dist/security/secure-random.d.ts +92 -0
- package/src/@claude-flow/shared/dist/security/secure-random.js +142 -0
- package/src/@claude-flow/shared/dist/services/index.d.ts +7 -0
- package/src/@claude-flow/shared/dist/services/index.js +7 -0
- package/src/@claude-flow/shared/dist/services/v3-progress.service.d.ts +124 -0
- package/src/@claude-flow/shared/dist/services/v3-progress.service.js +402 -0
- package/src/@claude-flow/shared/dist/types/agent.types.d.ts +137 -0
- package/src/@claude-flow/shared/dist/types/agent.types.js +6 -0
- package/src/@claude-flow/shared/dist/types/index.d.ts +11 -0
- package/src/@claude-flow/shared/dist/types/index.js +17 -0
- package/src/@claude-flow/shared/dist/types/mcp.types.d.ts +266 -0
- package/src/@claude-flow/shared/dist/types/mcp.types.js +7 -0
- package/src/@claude-flow/shared/dist/types/memory.types.d.ts +236 -0
- package/src/@claude-flow/shared/dist/types/memory.types.js +7 -0
- package/src/@claude-flow/shared/dist/types/swarm.types.d.ts +186 -0
- package/src/@claude-flow/shared/dist/types/swarm.types.js +65 -0
- package/src/@claude-flow/shared/dist/types/task.types.d.ts +178 -0
- package/src/@claude-flow/shared/dist/types/task.types.js +32 -0
- package/src/@claude-flow/shared/dist/types.d.ts +197 -0
- package/src/@claude-flow/shared/dist/types.js +21 -0
- package/src/@claude-flow/shared/dist/utils/secure-logger.d.ts +69 -0
- package/src/@claude-flow/shared/dist/utils/secure-logger.js +208 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Hooks System - Main Export
|
|
3
|
+
*
|
|
4
|
+
* Provides extensible hook points for tool execution, file operations,
|
|
5
|
+
* and session lifecycle events. Integrates with event bus for coordination.
|
|
6
|
+
*
|
|
7
|
+
* Example usage:
|
|
8
|
+
*
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { createHookRegistry, createHookExecutor, HookEvent, HookPriority } from '@claude-flow/shared/hooks';
|
|
11
|
+
*
|
|
12
|
+
* const registry = createHookRegistry();
|
|
13
|
+
* const executor = createHookExecutor(registry, eventBus);
|
|
14
|
+
*
|
|
15
|
+
* // Register a hook
|
|
16
|
+
* const hookId = registry.register(
|
|
17
|
+
* HookEvent.PreToolUse,
|
|
18
|
+
* async (context) => {
|
|
19
|
+
* console.log('Before tool use:', context.tool?.name);
|
|
20
|
+
* return { success: true };
|
|
21
|
+
* },
|
|
22
|
+
* HookPriority.High
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* // Execute hooks
|
|
26
|
+
* const result = await executor.execute(
|
|
27
|
+
* HookEvent.PreToolUse,
|
|
28
|
+
* {
|
|
29
|
+
* event: HookEvent.PreToolUse,
|
|
30
|
+
* timestamp: new Date(),
|
|
31
|
+
* tool: { name: 'Read', parameters: { path: 'file.ts' } }
|
|
32
|
+
* }
|
|
33
|
+
* );
|
|
34
|
+
*
|
|
35
|
+
* // Unregister hook
|
|
36
|
+
* registry.unregister(hookId);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @module v3/shared/hooks
|
|
40
|
+
*/
|
|
41
|
+
export { HookEvent, HookPriority, } from './types.js';
|
|
42
|
+
// Export registry
|
|
43
|
+
export { HookRegistry, createHookRegistry, } from './registry.js';
|
|
44
|
+
export { HookExecutor, createHookExecutor, } from './executor.js';
|
|
45
|
+
// Export task hooks
|
|
46
|
+
export { TaskHooksManager, createTaskHooksManager, } from './task-hooks.js';
|
|
47
|
+
// Export session hooks
|
|
48
|
+
export { SessionHooksManager, createSessionHooksManager, InMemorySessionStorage, } from './session-hooks.js';
|
|
49
|
+
// Export safety hooks
|
|
50
|
+
export { BashSafetyHook, createBashSafetyHook, FileOrganizationHook, createFileOrganizationHook, GitCommitHook, createGitCommitHook, } from './safety/index.js';
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Hooks System - Hook Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for managing hook definitions and lifecycle.
|
|
5
|
+
* Provides registration, unregistration, and discovery of hooks.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/shared/hooks/registry
|
|
8
|
+
*/
|
|
9
|
+
import { HookEvent, HookPriority, HookHandler, HookDefinition, HookStats } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Hook registry implementation
|
|
12
|
+
*/
|
|
13
|
+
export declare class HookRegistry {
|
|
14
|
+
private hooks;
|
|
15
|
+
private hooksById;
|
|
16
|
+
private hookIdCounter;
|
|
17
|
+
private stats;
|
|
18
|
+
/**
|
|
19
|
+
* Register a new hook
|
|
20
|
+
*
|
|
21
|
+
* @param event - Hook event type
|
|
22
|
+
* @param handler - Hook handler function
|
|
23
|
+
* @param priority - Hook priority (default: Normal)
|
|
24
|
+
* @param options - Additional hook options
|
|
25
|
+
* @returns Hook ID for later unregistration
|
|
26
|
+
*/
|
|
27
|
+
register(event: HookEvent, handler: HookHandler, priority?: HookPriority, options?: {
|
|
28
|
+
name?: string;
|
|
29
|
+
timeout?: number;
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
metadata?: Record<string, unknown>;
|
|
32
|
+
}): string;
|
|
33
|
+
/**
|
|
34
|
+
* Unregister a hook by ID
|
|
35
|
+
*
|
|
36
|
+
* @param hookId - Hook ID to unregister
|
|
37
|
+
* @returns Whether hook was found and removed
|
|
38
|
+
*/
|
|
39
|
+
unregister(hookId: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Unregister all hooks for an event
|
|
42
|
+
*
|
|
43
|
+
* @param event - Event type to clear hooks for
|
|
44
|
+
* @returns Number of hooks removed
|
|
45
|
+
*/
|
|
46
|
+
unregisterAll(event?: HookEvent): number;
|
|
47
|
+
/**
|
|
48
|
+
* Get all hooks for a specific event (sorted by priority)
|
|
49
|
+
*
|
|
50
|
+
* @param event - Event type
|
|
51
|
+
* @param includeDisabled - Whether to include disabled hooks
|
|
52
|
+
* @returns Array of hook definitions
|
|
53
|
+
*/
|
|
54
|
+
getHandlers(event: HookEvent, includeDisabled?: boolean): HookDefinition[];
|
|
55
|
+
/**
|
|
56
|
+
* Get a hook by ID
|
|
57
|
+
*
|
|
58
|
+
* @param hookId - Hook ID
|
|
59
|
+
* @returns Hook definition or undefined
|
|
60
|
+
*/
|
|
61
|
+
getHook(hookId: string): HookDefinition | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Enable a hook
|
|
64
|
+
*
|
|
65
|
+
* @param hookId - Hook ID
|
|
66
|
+
* @returns Whether hook was found and enabled
|
|
67
|
+
*/
|
|
68
|
+
enable(hookId: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Disable a hook
|
|
71
|
+
*
|
|
72
|
+
* @param hookId - Hook ID
|
|
73
|
+
* @returns Whether hook was found and disabled
|
|
74
|
+
*/
|
|
75
|
+
disable(hookId: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* List all registered hooks
|
|
78
|
+
*
|
|
79
|
+
* @param filter - Optional filter options
|
|
80
|
+
* @returns Array of hook definitions
|
|
81
|
+
*/
|
|
82
|
+
listHooks(filter?: {
|
|
83
|
+
event?: HookEvent;
|
|
84
|
+
enabled?: boolean;
|
|
85
|
+
minPriority?: HookPriority;
|
|
86
|
+
}): HookDefinition[];
|
|
87
|
+
/**
|
|
88
|
+
* Get all event types with registered hooks
|
|
89
|
+
*
|
|
90
|
+
* @returns Array of event types
|
|
91
|
+
*/
|
|
92
|
+
getEventTypes(): HookEvent[];
|
|
93
|
+
/**
|
|
94
|
+
* Get count of hooks for an event
|
|
95
|
+
*
|
|
96
|
+
* @param event - Event type (optional)
|
|
97
|
+
* @returns Hook count
|
|
98
|
+
*/
|
|
99
|
+
count(event?: HookEvent): number;
|
|
100
|
+
/**
|
|
101
|
+
* Record hook execution statistics
|
|
102
|
+
*
|
|
103
|
+
* @param success - Whether execution succeeded
|
|
104
|
+
* @param executionTime - Execution time in ms
|
|
105
|
+
*/
|
|
106
|
+
recordExecution(success: boolean, executionTime: number): void;
|
|
107
|
+
/**
|
|
108
|
+
* Get hook statistics
|
|
109
|
+
*
|
|
110
|
+
* @returns Hook statistics
|
|
111
|
+
*/
|
|
112
|
+
getStats(): HookStats;
|
|
113
|
+
/**
|
|
114
|
+
* Reset statistics
|
|
115
|
+
*/
|
|
116
|
+
resetStats(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Check if a hook exists
|
|
119
|
+
*
|
|
120
|
+
* @param hookId - Hook ID
|
|
121
|
+
* @returns Whether hook exists
|
|
122
|
+
*/
|
|
123
|
+
has(hookId: string): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Clear all hooks and reset state
|
|
126
|
+
*/
|
|
127
|
+
clear(): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create a new hook registry
|
|
131
|
+
*/
|
|
132
|
+
export declare function createHookRegistry(): HookRegistry;
|
|
133
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Hooks System - Hook Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for managing hook definitions and lifecycle.
|
|
5
|
+
* Provides registration, unregistration, and discovery of hooks.
|
|
6
|
+
*
|
|
7
|
+
* @module v3/shared/hooks/registry
|
|
8
|
+
*/
|
|
9
|
+
import { HookPriority, } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Hook registry implementation
|
|
12
|
+
*/
|
|
13
|
+
export class HookRegistry {
|
|
14
|
+
hooks = new Map();
|
|
15
|
+
hooksById = new Map();
|
|
16
|
+
hookIdCounter = 0;
|
|
17
|
+
// Statistics tracking
|
|
18
|
+
stats = {
|
|
19
|
+
executions: 0,
|
|
20
|
+
failures: 0,
|
|
21
|
+
totalExecutionTime: 0,
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Register a new hook
|
|
25
|
+
*
|
|
26
|
+
* @param event - Hook event type
|
|
27
|
+
* @param handler - Hook handler function
|
|
28
|
+
* @param priority - Hook priority (default: Normal)
|
|
29
|
+
* @param options - Additional hook options
|
|
30
|
+
* @returns Hook ID for later unregistration
|
|
31
|
+
*/
|
|
32
|
+
register(event, handler, priority = HookPriority.Normal, options = {}) {
|
|
33
|
+
// Generate unique hook ID
|
|
34
|
+
const id = `hook_${++this.hookIdCounter}_${Date.now()}`;
|
|
35
|
+
// Create hook definition
|
|
36
|
+
const definition = {
|
|
37
|
+
id,
|
|
38
|
+
event,
|
|
39
|
+
handler,
|
|
40
|
+
priority,
|
|
41
|
+
name: options.name,
|
|
42
|
+
enabled: options.enabled ?? true,
|
|
43
|
+
timeout: options.timeout,
|
|
44
|
+
metadata: options.metadata,
|
|
45
|
+
};
|
|
46
|
+
// Add to event-specific list
|
|
47
|
+
let eventHooks = this.hooks.get(event);
|
|
48
|
+
if (!eventHooks) {
|
|
49
|
+
eventHooks = [];
|
|
50
|
+
this.hooks.set(event, eventHooks);
|
|
51
|
+
}
|
|
52
|
+
eventHooks.push(definition);
|
|
53
|
+
// Sort by priority (highest first)
|
|
54
|
+
eventHooks.sort((a, b) => b.priority - a.priority);
|
|
55
|
+
// Add to ID map
|
|
56
|
+
this.hooksById.set(id, definition);
|
|
57
|
+
return id;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Unregister a hook by ID
|
|
61
|
+
*
|
|
62
|
+
* @param hookId - Hook ID to unregister
|
|
63
|
+
* @returns Whether hook was found and removed
|
|
64
|
+
*/
|
|
65
|
+
unregister(hookId) {
|
|
66
|
+
const definition = this.hooksById.get(hookId);
|
|
67
|
+
if (!definition) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
// Remove from event-specific list
|
|
71
|
+
const eventHooks = this.hooks.get(definition.event);
|
|
72
|
+
if (eventHooks) {
|
|
73
|
+
const index = eventHooks.findIndex(h => h.id === hookId);
|
|
74
|
+
if (index !== -1) {
|
|
75
|
+
eventHooks.splice(index, 1);
|
|
76
|
+
}
|
|
77
|
+
// Clean up empty arrays
|
|
78
|
+
if (eventHooks.length === 0) {
|
|
79
|
+
this.hooks.delete(definition.event);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Remove from ID map
|
|
83
|
+
this.hooksById.delete(hookId);
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Unregister all hooks for an event
|
|
88
|
+
*
|
|
89
|
+
* @param event - Event type to clear hooks for
|
|
90
|
+
* @returns Number of hooks removed
|
|
91
|
+
*/
|
|
92
|
+
unregisterAll(event) {
|
|
93
|
+
if (event) {
|
|
94
|
+
const eventHooks = this.hooks.get(event) || [];
|
|
95
|
+
const count = eventHooks.length;
|
|
96
|
+
// Remove from ID map
|
|
97
|
+
for (const hook of eventHooks) {
|
|
98
|
+
this.hooksById.delete(hook.id);
|
|
99
|
+
}
|
|
100
|
+
// Clear event hooks
|
|
101
|
+
this.hooks.delete(event);
|
|
102
|
+
return count;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
// Clear all hooks
|
|
106
|
+
const count = this.hooksById.size;
|
|
107
|
+
this.hooks.clear();
|
|
108
|
+
this.hooksById.clear();
|
|
109
|
+
this.hookIdCounter = 0;
|
|
110
|
+
return count;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get all hooks for a specific event (sorted by priority)
|
|
115
|
+
*
|
|
116
|
+
* @param event - Event type
|
|
117
|
+
* @param includeDisabled - Whether to include disabled hooks
|
|
118
|
+
* @returns Array of hook definitions
|
|
119
|
+
*/
|
|
120
|
+
getHandlers(event, includeDisabled = false) {
|
|
121
|
+
const eventHooks = this.hooks.get(event) || [];
|
|
122
|
+
if (includeDisabled) {
|
|
123
|
+
return [...eventHooks];
|
|
124
|
+
}
|
|
125
|
+
return eventHooks.filter(h => h.enabled);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get a hook by ID
|
|
129
|
+
*
|
|
130
|
+
* @param hookId - Hook ID
|
|
131
|
+
* @returns Hook definition or undefined
|
|
132
|
+
*/
|
|
133
|
+
getHook(hookId) {
|
|
134
|
+
return this.hooksById.get(hookId);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Enable a hook
|
|
138
|
+
*
|
|
139
|
+
* @param hookId - Hook ID
|
|
140
|
+
* @returns Whether hook was found and enabled
|
|
141
|
+
*/
|
|
142
|
+
enable(hookId) {
|
|
143
|
+
const hook = this.hooksById.get(hookId);
|
|
144
|
+
if (hook) {
|
|
145
|
+
hook.enabled = true;
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Disable a hook
|
|
152
|
+
*
|
|
153
|
+
* @param hookId - Hook ID
|
|
154
|
+
* @returns Whether hook was found and disabled
|
|
155
|
+
*/
|
|
156
|
+
disable(hookId) {
|
|
157
|
+
const hook = this.hooksById.get(hookId);
|
|
158
|
+
if (hook) {
|
|
159
|
+
hook.enabled = false;
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* List all registered hooks
|
|
166
|
+
*
|
|
167
|
+
* @param filter - Optional filter options
|
|
168
|
+
* @returns Array of hook definitions
|
|
169
|
+
*/
|
|
170
|
+
listHooks(filter) {
|
|
171
|
+
let hooks;
|
|
172
|
+
if (filter?.event) {
|
|
173
|
+
hooks = this.hooks.get(filter.event) || [];
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
hooks = Array.from(this.hooksById.values());
|
|
177
|
+
}
|
|
178
|
+
// Apply filters
|
|
179
|
+
if (filter?.enabled !== undefined) {
|
|
180
|
+
hooks = hooks.filter(h => h.enabled === filter.enabled);
|
|
181
|
+
}
|
|
182
|
+
if (filter?.minPriority !== undefined) {
|
|
183
|
+
const minPriority = filter.minPriority;
|
|
184
|
+
hooks = hooks.filter(h => h.priority >= minPriority);
|
|
185
|
+
}
|
|
186
|
+
return hooks;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get all event types with registered hooks
|
|
190
|
+
*
|
|
191
|
+
* @returns Array of event types
|
|
192
|
+
*/
|
|
193
|
+
getEventTypes() {
|
|
194
|
+
return Array.from(this.hooks.keys());
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get count of hooks for an event
|
|
198
|
+
*
|
|
199
|
+
* @param event - Event type (optional)
|
|
200
|
+
* @returns Hook count
|
|
201
|
+
*/
|
|
202
|
+
count(event) {
|
|
203
|
+
if (event) {
|
|
204
|
+
return this.hooks.get(event)?.length || 0;
|
|
205
|
+
}
|
|
206
|
+
return this.hooksById.size;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Record hook execution statistics
|
|
210
|
+
*
|
|
211
|
+
* @param success - Whether execution succeeded
|
|
212
|
+
* @param executionTime - Execution time in ms
|
|
213
|
+
*/
|
|
214
|
+
recordExecution(success, executionTime) {
|
|
215
|
+
this.stats.executions++;
|
|
216
|
+
this.stats.totalExecutionTime += executionTime;
|
|
217
|
+
if (!success) {
|
|
218
|
+
this.stats.failures++;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get hook statistics
|
|
223
|
+
*
|
|
224
|
+
* @returns Hook statistics
|
|
225
|
+
*/
|
|
226
|
+
getStats() {
|
|
227
|
+
const byEvent = {};
|
|
228
|
+
for (const [event, hooks] of this.hooks) {
|
|
229
|
+
byEvent[event] = hooks.filter(h => h.enabled).length;
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
totalHooks: this.hooksById.size,
|
|
233
|
+
byEvent,
|
|
234
|
+
totalExecutions: this.stats.executions,
|
|
235
|
+
totalFailures: this.stats.failures,
|
|
236
|
+
avgExecutionTime: this.stats.executions > 0
|
|
237
|
+
? this.stats.totalExecutionTime / this.stats.executions
|
|
238
|
+
: 0,
|
|
239
|
+
totalExecutionTime: this.stats.totalExecutionTime,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Reset statistics
|
|
244
|
+
*/
|
|
245
|
+
resetStats() {
|
|
246
|
+
this.stats = {
|
|
247
|
+
executions: 0,
|
|
248
|
+
failures: 0,
|
|
249
|
+
totalExecutionTime: 0,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Check if a hook exists
|
|
254
|
+
*
|
|
255
|
+
* @param hookId - Hook ID
|
|
256
|
+
* @returns Whether hook exists
|
|
257
|
+
*/
|
|
258
|
+
has(hookId) {
|
|
259
|
+
return this.hooksById.has(hookId);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Clear all hooks and reset state
|
|
263
|
+
*/
|
|
264
|
+
clear() {
|
|
265
|
+
this.hooks.clear();
|
|
266
|
+
this.hooksById.clear();
|
|
267
|
+
this.hookIdCounter = 0;
|
|
268
|
+
this.resetStats();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Create a new hook registry
|
|
273
|
+
*/
|
|
274
|
+
export function createHookRegistry() {
|
|
275
|
+
return new HookRegistry();
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 Bash Safety Hook
|
|
3
|
+
*
|
|
4
|
+
* TypeScript conversion of V2 bash-hook.sh.
|
|
5
|
+
* Provides command safety analysis, dangerous command detection,
|
|
6
|
+
* secret detection, and safe alternatives.
|
|
7
|
+
*
|
|
8
|
+
* @module v3/shared/hooks/safety/bash-safety
|
|
9
|
+
*/
|
|
10
|
+
import { HookContext, HookResult } from '../types.js';
|
|
11
|
+
import { HookRegistry } from '../registry.js';
|
|
12
|
+
/**
|
|
13
|
+
* Bash safety hook result
|
|
14
|
+
*/
|
|
15
|
+
export interface BashSafetyResult extends HookResult {
|
|
16
|
+
/** Risk level assessment */
|
|
17
|
+
riskLevel: 'low' | 'medium' | 'high' | 'critical';
|
|
18
|
+
/** Whether the command should be blocked */
|
|
19
|
+
blocked: boolean;
|
|
20
|
+
/** Reason for blocking (if blocked) */
|
|
21
|
+
blockReason?: string;
|
|
22
|
+
/** Modified command (if applicable) */
|
|
23
|
+
modifiedCommand?: string;
|
|
24
|
+
/** Detected risks */
|
|
25
|
+
risks: CommandRisk[];
|
|
26
|
+
/** Safe alternatives */
|
|
27
|
+
safeAlternatives?: string[];
|
|
28
|
+
/** Warnings (non-blocking) */
|
|
29
|
+
warnings?: string[];
|
|
30
|
+
/** Missing dependencies detected */
|
|
31
|
+
missingDependencies?: string[];
|
|
32
|
+
/** Redacted command (secrets removed) */
|
|
33
|
+
redactedCommand?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Command risk definition
|
|
37
|
+
*/
|
|
38
|
+
export interface CommandRisk {
|
|
39
|
+
/** Risk type */
|
|
40
|
+
type: 'dangerous' | 'destructive' | 'secret' | 'privilege' | 'network' | 'resource';
|
|
41
|
+
/** Risk severity */
|
|
42
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
43
|
+
/** Risk description */
|
|
44
|
+
description: string;
|
|
45
|
+
/** Pattern that matched */
|
|
46
|
+
pattern?: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Bash Safety Hook Manager
|
|
50
|
+
*/
|
|
51
|
+
export declare class BashSafetyHook {
|
|
52
|
+
private registry;
|
|
53
|
+
private blockedCommands;
|
|
54
|
+
private availableDependencies;
|
|
55
|
+
constructor(registry: HookRegistry);
|
|
56
|
+
/**
|
|
57
|
+
* Register bash safety hooks
|
|
58
|
+
*/
|
|
59
|
+
private registerHooks;
|
|
60
|
+
/**
|
|
61
|
+
* Detect available dependencies
|
|
62
|
+
*/
|
|
63
|
+
private detectAvailableDependencies;
|
|
64
|
+
/**
|
|
65
|
+
* Analyze a command for safety
|
|
66
|
+
*/
|
|
67
|
+
analyzeCommand(context: HookContext): Promise<BashSafetyResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Detect secrets in command
|
|
70
|
+
*/
|
|
71
|
+
private detectSecrets;
|
|
72
|
+
/**
|
|
73
|
+
* Check for missing dependencies
|
|
74
|
+
*/
|
|
75
|
+
private checkDependencies;
|
|
76
|
+
/**
|
|
77
|
+
* Calculate overall risk level
|
|
78
|
+
*/
|
|
79
|
+
private calculateRiskLevel;
|
|
80
|
+
/**
|
|
81
|
+
* Create a result object
|
|
82
|
+
*/
|
|
83
|
+
private createResult;
|
|
84
|
+
/**
|
|
85
|
+
* Manually analyze a command
|
|
86
|
+
*/
|
|
87
|
+
analyze(command: string): Promise<BashSafetyResult>;
|
|
88
|
+
/**
|
|
89
|
+
* Add a custom dangerous pattern
|
|
90
|
+
*/
|
|
91
|
+
addDangerousPattern(pattern: RegExp, type: CommandRisk['type'], severity: CommandRisk['severity'], description: string, block?: boolean): void;
|
|
92
|
+
/**
|
|
93
|
+
* Mark a dependency as available
|
|
94
|
+
*/
|
|
95
|
+
markDependencyAvailable(dependency: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Check if a command would be blocked
|
|
98
|
+
*/
|
|
99
|
+
wouldBlock(command: string): boolean;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create bash safety hook
|
|
103
|
+
*/
|
|
104
|
+
export declare function createBashSafetyHook(registry: HookRegistry): BashSafetyHook;
|
|
105
|
+
//# sourceMappingURL=bash-safety.d.ts.map
|