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.
Files changed (244) hide show
  1. package/.claude/guidance/shipped/moflo.md +45 -0
  2. package/.claude/helpers/statusline.cjs +1 -1
  3. package/.claude/workflow-state.json +9 -0
  4. package/bin/generate-code-map.mjs +91 -12
  5. package/package.json +2 -2
  6. package/src/@claude-flow/cli/bin/cli.js +5 -0
  7. package/src/@claude-flow/cli/dist/src/init/moflo-init.js +9 -0
  8. package/src/@claude-flow/cli/dist/src/init/statusline-generator.js +1 -1
  9. package/src/@claude-flow/cli/dist/src/services/agentic-flow-bridge.js +8 -0
  10. package/src/@claude-flow/cli/package.json +1 -1
  11. package/src/@claude-flow/memory/dist/agent-memory-scope.d.ts +131 -0
  12. package/src/@claude-flow/memory/dist/agent-memory-scope.js +223 -0
  13. package/src/@claude-flow/memory/dist/agent-memory-scope.test.d.ts +8 -0
  14. package/src/@claude-flow/memory/dist/agent-memory-scope.test.js +466 -0
  15. package/src/@claude-flow/memory/dist/agentdb-adapter.d.ts +165 -0
  16. package/src/@claude-flow/memory/dist/agentdb-adapter.js +806 -0
  17. package/src/@claude-flow/memory/dist/agentdb-backend.d.ts +212 -0
  18. package/src/@claude-flow/memory/dist/agentdb-backend.js +842 -0
  19. package/src/@claude-flow/memory/dist/agentdb-backend.test.d.ts +7 -0
  20. package/src/@claude-flow/memory/dist/agentdb-backend.test.js +258 -0
  21. package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.d.ts +65 -0
  22. package/src/@claude-flow/memory/dist/application/commands/delete-memory.command.js +129 -0
  23. package/src/@claude-flow/memory/dist/application/commands/store-memory.command.d.ts +48 -0
  24. package/src/@claude-flow/memory/dist/application/commands/store-memory.command.js +72 -0
  25. package/src/@claude-flow/memory/dist/application/index.d.ts +12 -0
  26. package/src/@claude-flow/memory/dist/application/index.js +15 -0
  27. package/src/@claude-flow/memory/dist/application/queries/search-memory.query.d.ts +72 -0
  28. package/src/@claude-flow/memory/dist/application/queries/search-memory.query.js +143 -0
  29. package/src/@claude-flow/memory/dist/application/services/memory-application-service.d.ts +121 -0
  30. package/src/@claude-flow/memory/dist/application/services/memory-application-service.js +190 -0
  31. package/src/@claude-flow/memory/dist/auto-memory-bridge.d.ts +226 -0
  32. package/src/@claude-flow/memory/dist/auto-memory-bridge.js +709 -0
  33. package/src/@claude-flow/memory/dist/auto-memory-bridge.test.d.ts +8 -0
  34. package/src/@claude-flow/memory/dist/auto-memory-bridge.test.js +757 -0
  35. package/src/@claude-flow/memory/dist/benchmark.test.d.ts +2 -0
  36. package/src/@claude-flow/memory/dist/benchmark.test.js +277 -0
  37. package/src/@claude-flow/memory/dist/cache-manager.d.ts +134 -0
  38. package/src/@claude-flow/memory/dist/cache-manager.js +407 -0
  39. package/src/@claude-flow/memory/dist/controller-registry.d.ts +216 -0
  40. package/src/@claude-flow/memory/dist/controller-registry.js +893 -0
  41. package/src/@claude-flow/memory/dist/controller-registry.test.d.ts +14 -0
  42. package/src/@claude-flow/memory/dist/controller-registry.test.js +593 -0
  43. package/src/@claude-flow/memory/dist/database-provider.d.ts +87 -0
  44. package/src/@claude-flow/memory/dist/database-provider.js +372 -0
  45. package/src/@claude-flow/memory/dist/database-provider.test.d.ts +7 -0
  46. package/src/@claude-flow/memory/dist/database-provider.test.js +287 -0
  47. package/src/@claude-flow/memory/dist/domain/entities/memory-entry.d.ts +143 -0
  48. package/src/@claude-flow/memory/dist/domain/entities/memory-entry.js +226 -0
  49. package/src/@claude-flow/memory/dist/domain/index.d.ts +11 -0
  50. package/src/@claude-flow/memory/dist/domain/index.js +12 -0
  51. package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.d.ts +102 -0
  52. package/src/@claude-flow/memory/dist/domain/repositories/memory-repository.interface.js +11 -0
  53. package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.d.ts +105 -0
  54. package/src/@claude-flow/memory/dist/domain/services/memory-domain-service.js +297 -0
  55. package/src/@claude-flow/memory/dist/hnsw-index.d.ts +111 -0
  56. package/src/@claude-flow/memory/dist/hnsw-index.js +781 -0
  57. package/src/@claude-flow/memory/dist/hnsw-lite.d.ts +23 -0
  58. package/src/@claude-flow/memory/dist/hnsw-lite.js +168 -0
  59. package/src/@claude-flow/memory/dist/index.d.ts +204 -0
  60. package/src/@claude-flow/memory/dist/index.js +358 -0
  61. package/src/@claude-flow/memory/dist/infrastructure/index.d.ts +17 -0
  62. package/src/@claude-flow/memory/dist/infrastructure/index.js +16 -0
  63. package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.d.ts +66 -0
  64. package/src/@claude-flow/memory/dist/infrastructure/repositories/hybrid-memory-repository.js +409 -0
  65. package/src/@claude-flow/memory/dist/learning-bridge.d.ts +137 -0
  66. package/src/@claude-flow/memory/dist/learning-bridge.js +335 -0
  67. package/src/@claude-flow/memory/dist/learning-bridge.test.d.ts +8 -0
  68. package/src/@claude-flow/memory/dist/learning-bridge.test.js +578 -0
  69. package/src/@claude-flow/memory/dist/memory-graph.d.ts +100 -0
  70. package/src/@claude-flow/memory/dist/memory-graph.js +333 -0
  71. package/src/@claude-flow/memory/dist/memory-graph.test.d.ts +8 -0
  72. package/src/@claude-flow/memory/dist/memory-graph.test.js +609 -0
  73. package/src/@claude-flow/memory/dist/migration.d.ts +68 -0
  74. package/src/@claude-flow/memory/dist/migration.js +513 -0
  75. package/src/@claude-flow/memory/dist/persistent-sona.d.ts +144 -0
  76. package/src/@claude-flow/memory/dist/persistent-sona.js +332 -0
  77. package/src/@claude-flow/memory/dist/query-builder.d.ts +211 -0
  78. package/src/@claude-flow/memory/dist/query-builder.js +438 -0
  79. package/src/@claude-flow/memory/dist/rvf-backend.d.ts +51 -0
  80. package/src/@claude-flow/memory/dist/rvf-backend.js +481 -0
  81. package/src/@claude-flow/memory/dist/rvf-learning-store.d.ts +139 -0
  82. package/src/@claude-flow/memory/dist/rvf-learning-store.js +295 -0
  83. package/src/@claude-flow/memory/dist/rvf-migration.d.ts +45 -0
  84. package/src/@claude-flow/memory/dist/rvf-migration.js +234 -0
  85. package/src/@claude-flow/memory/dist/sqljs-backend.d.ts +127 -0
  86. package/src/@claude-flow/memory/dist/sqljs-backend.js +600 -0
  87. package/src/@claude-flow/memory/dist/types.d.ts +484 -0
  88. package/src/@claude-flow/memory/dist/types.js +58 -0
  89. package/src/@claude-flow/shared/dist/core/config/defaults.d.ts +41 -0
  90. package/src/@claude-flow/shared/dist/core/config/defaults.js +186 -0
  91. package/src/@claude-flow/shared/dist/core/config/index.d.ts +8 -0
  92. package/src/@claude-flow/shared/dist/core/config/index.js +12 -0
  93. package/src/@claude-flow/shared/dist/core/config/loader.d.ts +45 -0
  94. package/src/@claude-flow/shared/dist/core/config/loader.js +222 -0
  95. package/src/@claude-flow/shared/dist/core/config/schema.d.ts +1134 -0
  96. package/src/@claude-flow/shared/dist/core/config/schema.js +158 -0
  97. package/src/@claude-flow/shared/dist/core/config/validator.d.ts +92 -0
  98. package/src/@claude-flow/shared/dist/core/config/validator.js +147 -0
  99. package/src/@claude-flow/shared/dist/core/event-bus.d.ts +31 -0
  100. package/src/@claude-flow/shared/dist/core/event-bus.js +197 -0
  101. package/src/@claude-flow/shared/dist/core/index.d.ts +15 -0
  102. package/src/@claude-flow/shared/dist/core/index.js +19 -0
  103. package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.d.ts +200 -0
  104. package/src/@claude-flow/shared/dist/core/interfaces/agent.interface.js +6 -0
  105. package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.d.ts +310 -0
  106. package/src/@claude-flow/shared/dist/core/interfaces/coordinator.interface.js +7 -0
  107. package/src/@claude-flow/shared/dist/core/interfaces/event.interface.d.ts +224 -0
  108. package/src/@claude-flow/shared/dist/core/interfaces/event.interface.js +46 -0
  109. package/src/@claude-flow/shared/dist/core/interfaces/index.d.ts +10 -0
  110. package/src/@claude-flow/shared/dist/core/interfaces/index.js +15 -0
  111. package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.d.ts +298 -0
  112. package/src/@claude-flow/shared/dist/core/interfaces/memory.interface.js +7 -0
  113. package/src/@claude-flow/shared/dist/core/interfaces/task.interface.d.ts +185 -0
  114. package/src/@claude-flow/shared/dist/core/interfaces/task.interface.js +6 -0
  115. package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.d.ts +35 -0
  116. package/src/@claude-flow/shared/dist/core/orchestrator/event-coordinator.js +101 -0
  117. package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.d.ts +60 -0
  118. package/src/@claude-flow/shared/dist/core/orchestrator/health-monitor.js +166 -0
  119. package/src/@claude-flow/shared/dist/core/orchestrator/index.d.ts +46 -0
  120. package/src/@claude-flow/shared/dist/core/orchestrator/index.js +64 -0
  121. package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.d.ts +56 -0
  122. package/src/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.js +195 -0
  123. package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.d.ts +83 -0
  124. package/src/@claude-flow/shared/dist/core/orchestrator/session-manager.js +193 -0
  125. package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.d.ts +49 -0
  126. package/src/@claude-flow/shared/dist/core/orchestrator/task-manager.js +253 -0
  127. package/src/@claude-flow/shared/dist/events/domain-events.d.ts +282 -0
  128. package/src/@claude-flow/shared/dist/events/domain-events.js +165 -0
  129. package/src/@claude-flow/shared/dist/events/event-store.d.ts +126 -0
  130. package/src/@claude-flow/shared/dist/events/event-store.js +432 -0
  131. package/src/@claude-flow/shared/dist/events/event-store.test.d.ts +8 -0
  132. package/src/@claude-flow/shared/dist/events/event-store.test.js +297 -0
  133. package/src/@claude-flow/shared/dist/events/example-usage.d.ts +10 -0
  134. package/src/@claude-flow/shared/dist/events/example-usage.js +193 -0
  135. package/src/@claude-flow/shared/dist/events/index.d.ts +21 -0
  136. package/src/@claude-flow/shared/dist/events/index.js +22 -0
  137. package/src/@claude-flow/shared/dist/events/projections.d.ts +177 -0
  138. package/src/@claude-flow/shared/dist/events/projections.js +421 -0
  139. package/src/@claude-flow/shared/dist/events/rvf-event-log.d.ts +82 -0
  140. package/src/@claude-flow/shared/dist/events/rvf-event-log.js +340 -0
  141. package/src/@claude-flow/shared/dist/events/state-reconstructor.d.ts +101 -0
  142. package/src/@claude-flow/shared/dist/events/state-reconstructor.js +263 -0
  143. package/src/@claude-flow/shared/dist/events.d.ts +80 -0
  144. package/src/@claude-flow/shared/dist/events.js +249 -0
  145. package/src/@claude-flow/shared/dist/hooks/example-usage.d.ts +42 -0
  146. package/src/@claude-flow/shared/dist/hooks/example-usage.js +351 -0
  147. package/src/@claude-flow/shared/dist/hooks/executor.d.ts +100 -0
  148. package/src/@claude-flow/shared/dist/hooks/executor.js +267 -0
  149. package/src/@claude-flow/shared/dist/hooks/hooks.test.d.ts +9 -0
  150. package/src/@claude-flow/shared/dist/hooks/hooks.test.js +322 -0
  151. package/src/@claude-flow/shared/dist/hooks/index.d.ts +52 -0
  152. package/src/@claude-flow/shared/dist/hooks/index.js +51 -0
  153. package/src/@claude-flow/shared/dist/hooks/registry.d.ts +133 -0
  154. package/src/@claude-flow/shared/dist/hooks/registry.js +277 -0
  155. package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.d.ts +105 -0
  156. package/src/@claude-flow/shared/dist/hooks/safety/bash-safety.js +481 -0
  157. package/src/@claude-flow/shared/dist/hooks/safety/file-organization.d.ts +144 -0
  158. package/src/@claude-flow/shared/dist/hooks/safety/file-organization.js +328 -0
  159. package/src/@claude-flow/shared/dist/hooks/safety/git-commit.d.ts +158 -0
  160. package/src/@claude-flow/shared/dist/hooks/safety/git-commit.js +450 -0
  161. package/src/@claude-flow/shared/dist/hooks/safety/index.d.ts +17 -0
  162. package/src/@claude-flow/shared/dist/hooks/safety/index.js +17 -0
  163. package/src/@claude-flow/shared/dist/hooks/session-hooks.d.ts +234 -0
  164. package/src/@claude-flow/shared/dist/hooks/session-hooks.js +334 -0
  165. package/src/@claude-flow/shared/dist/hooks/task-hooks.d.ts +163 -0
  166. package/src/@claude-flow/shared/dist/hooks/task-hooks.js +326 -0
  167. package/src/@claude-flow/shared/dist/hooks/types.d.ts +267 -0
  168. package/src/@claude-flow/shared/dist/hooks/types.js +62 -0
  169. package/src/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +9 -0
  170. package/src/@claude-flow/shared/dist/hooks/verify-exports.test.js +93 -0
  171. package/src/@claude-flow/shared/dist/index.d.ts +20 -0
  172. package/src/@claude-flow/shared/dist/index.js +50 -0
  173. package/src/@claude-flow/shared/dist/mcp/connection-pool.d.ts +98 -0
  174. package/src/@claude-flow/shared/dist/mcp/connection-pool.js +364 -0
  175. package/src/@claude-flow/shared/dist/mcp/index.d.ts +69 -0
  176. package/src/@claude-flow/shared/dist/mcp/index.js +84 -0
  177. package/src/@claude-flow/shared/dist/mcp/server.d.ts +166 -0
  178. package/src/@claude-flow/shared/dist/mcp/server.js +593 -0
  179. package/src/@claude-flow/shared/dist/mcp/session-manager.d.ts +136 -0
  180. package/src/@claude-flow/shared/dist/mcp/session-manager.js +335 -0
  181. package/src/@claude-flow/shared/dist/mcp/tool-registry.d.ts +178 -0
  182. package/src/@claude-flow/shared/dist/mcp/tool-registry.js +439 -0
  183. package/src/@claude-flow/shared/dist/mcp/transport/http.d.ts +104 -0
  184. package/src/@claude-flow/shared/dist/mcp/transport/http.js +476 -0
  185. package/src/@claude-flow/shared/dist/mcp/transport/index.d.ts +102 -0
  186. package/src/@claude-flow/shared/dist/mcp/transport/index.js +238 -0
  187. package/src/@claude-flow/shared/dist/mcp/transport/stdio.d.ts +104 -0
  188. package/src/@claude-flow/shared/dist/mcp/transport/stdio.js +263 -0
  189. package/src/@claude-flow/shared/dist/mcp/transport/websocket.d.ts +133 -0
  190. package/src/@claude-flow/shared/dist/mcp/transport/websocket.js +396 -0
  191. package/src/@claude-flow/shared/dist/mcp/types.d.ts +438 -0
  192. package/src/@claude-flow/shared/dist/mcp/types.js +54 -0
  193. package/src/@claude-flow/shared/dist/plugin-interface.d.ts +544 -0
  194. package/src/@claude-flow/shared/dist/plugin-interface.js +23 -0
  195. package/src/@claude-flow/shared/dist/plugin-loader.d.ts +139 -0
  196. package/src/@claude-flow/shared/dist/plugin-loader.js +434 -0
  197. package/src/@claude-flow/shared/dist/plugin-registry.d.ts +183 -0
  198. package/src/@claude-flow/shared/dist/plugin-registry.js +457 -0
  199. package/src/@claude-flow/shared/dist/plugins/index.d.ts +10 -0
  200. package/src/@claude-flow/shared/dist/plugins/index.js +10 -0
  201. package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.d.ts +106 -0
  202. package/src/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.js +241 -0
  203. package/src/@claude-flow/shared/dist/plugins/official/index.d.ts +10 -0
  204. package/src/@claude-flow/shared/dist/plugins/official/index.js +10 -0
  205. package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.d.ts +121 -0
  206. package/src/@claude-flow/shared/dist/plugins/official/maestro-plugin.js +355 -0
  207. package/src/@claude-flow/shared/dist/plugins/types.d.ts +93 -0
  208. package/src/@claude-flow/shared/dist/plugins/types.js +9 -0
  209. package/src/@claude-flow/shared/dist/resilience/bulkhead.d.ts +105 -0
  210. package/src/@claude-flow/shared/dist/resilience/bulkhead.js +206 -0
  211. package/src/@claude-flow/shared/dist/resilience/circuit-breaker.d.ts +132 -0
  212. package/src/@claude-flow/shared/dist/resilience/circuit-breaker.js +233 -0
  213. package/src/@claude-flow/shared/dist/resilience/index.d.ts +19 -0
  214. package/src/@claude-flow/shared/dist/resilience/index.js +19 -0
  215. package/src/@claude-flow/shared/dist/resilience/rate-limiter.d.ts +168 -0
  216. package/src/@claude-flow/shared/dist/resilience/rate-limiter.js +314 -0
  217. package/src/@claude-flow/shared/dist/resilience/retry.d.ts +91 -0
  218. package/src/@claude-flow/shared/dist/resilience/retry.js +159 -0
  219. package/src/@claude-flow/shared/dist/security/index.d.ts +10 -0
  220. package/src/@claude-flow/shared/dist/security/index.js +12 -0
  221. package/src/@claude-flow/shared/dist/security/input-validation.d.ts +73 -0
  222. package/src/@claude-flow/shared/dist/security/input-validation.js +201 -0
  223. package/src/@claude-flow/shared/dist/security/secure-random.d.ts +92 -0
  224. package/src/@claude-flow/shared/dist/security/secure-random.js +142 -0
  225. package/src/@claude-flow/shared/dist/services/index.d.ts +7 -0
  226. package/src/@claude-flow/shared/dist/services/index.js +7 -0
  227. package/src/@claude-flow/shared/dist/services/v3-progress.service.d.ts +124 -0
  228. package/src/@claude-flow/shared/dist/services/v3-progress.service.js +402 -0
  229. package/src/@claude-flow/shared/dist/types/agent.types.d.ts +137 -0
  230. package/src/@claude-flow/shared/dist/types/agent.types.js +6 -0
  231. package/src/@claude-flow/shared/dist/types/index.d.ts +11 -0
  232. package/src/@claude-flow/shared/dist/types/index.js +17 -0
  233. package/src/@claude-flow/shared/dist/types/mcp.types.d.ts +266 -0
  234. package/src/@claude-flow/shared/dist/types/mcp.types.js +7 -0
  235. package/src/@claude-flow/shared/dist/types/memory.types.d.ts +236 -0
  236. package/src/@claude-flow/shared/dist/types/memory.types.js +7 -0
  237. package/src/@claude-flow/shared/dist/types/swarm.types.d.ts +186 -0
  238. package/src/@claude-flow/shared/dist/types/swarm.types.js +65 -0
  239. package/src/@claude-flow/shared/dist/types/task.types.d.ts +178 -0
  240. package/src/@claude-flow/shared/dist/types/task.types.js +32 -0
  241. package/src/@claude-flow/shared/dist/types.d.ts +197 -0
  242. package/src/@claude-flow/shared/dist/types.js +21 -0
  243. package/src/@claude-flow/shared/dist/utils/secure-logger.d.ts +69 -0
  244. 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