codehere 0.3.0 → 0.4.0

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.

Potentially problematic release.


This version of codehere might be problematic. Click here for more details.

Files changed (297) hide show
  1. package/README.md +223 -42
  2. package/dist/application/agents/documentation-agent.d.ts +24 -0
  3. package/dist/application/agents/documentation-agent.d.ts.map +1 -0
  4. package/dist/application/agents/documentation-agent.js +399 -0
  5. package/dist/application/agents/documentation-agent.js.map +1 -0
  6. package/dist/application/agents/execution-agent.d.ts +11 -0
  7. package/dist/application/agents/execution-agent.d.ts.map +1 -1
  8. package/dist/application/agents/execution-agent.js +289 -80
  9. package/dist/application/agents/execution-agent.js.map +1 -1
  10. package/dist/application/agents/multi-agent-orchestrator.d.ts +3 -0
  11. package/dist/application/agents/multi-agent-orchestrator.d.ts.map +1 -1
  12. package/dist/application/agents/multi-agent-orchestrator.js +86 -0
  13. package/dist/application/agents/multi-agent-orchestrator.js.map +1 -1
  14. package/dist/application/agents/planning-agent.d.ts +3 -0
  15. package/dist/application/agents/planning-agent.d.ts.map +1 -1
  16. package/dist/application/agents/planning-agent.js +132 -64
  17. package/dist/application/agents/planning-agent.js.map +1 -1
  18. package/dist/application/agents/product-requirements-agent.d.ts +21 -0
  19. package/dist/application/agents/product-requirements-agent.d.ts.map +1 -0
  20. package/dist/application/agents/product-requirements-agent.js +247 -0
  21. package/dist/application/agents/product-requirements-agent.js.map +1 -0
  22. package/dist/application/agents/validation-agent.d.ts +5 -1
  23. package/dist/application/agents/validation-agent.d.ts.map +1 -1
  24. package/dist/application/agents/validation-agent.js +156 -21
  25. package/dist/application/agents/validation-agent.js.map +1 -1
  26. package/dist/application/services/dependency-container.d.ts +22 -2
  27. package/dist/application/services/dependency-container.d.ts.map +1 -1
  28. package/dist/application/services/dependency-container.js +144 -6
  29. package/dist/application/services/dependency-container.js.map +1 -1
  30. package/dist/application/services/intelligent-router.d.ts +13 -0
  31. package/dist/application/services/intelligent-router.d.ts.map +1 -1
  32. package/dist/application/services/intelligent-router.js +300 -87
  33. package/dist/application/services/intelligent-router.js.map +1 -1
  34. package/dist/application/use-cases/ask-question-use-case.d.ts +19 -0
  35. package/dist/application/use-cases/ask-question-use-case.d.ts.map +1 -1
  36. package/dist/application/use-cases/ask-question-use-case.js +125 -46
  37. package/dist/application/use-cases/ask-question-use-case.js.map +1 -1
  38. package/dist/application/use-cases/edit-file-use-case.d.ts.map +1 -1
  39. package/dist/application/use-cases/edit-file-use-case.js +16 -1
  40. package/dist/application/use-cases/edit-file-use-case.js.map +1 -1
  41. package/dist/domain/entities/documentation.d.ts +35 -0
  42. package/dist/domain/entities/documentation.d.ts.map +1 -0
  43. package/dist/domain/entities/documentation.js +6 -0
  44. package/dist/domain/entities/documentation.js.map +1 -0
  45. package/dist/domain/entities/product-requirements.d.ts +50 -0
  46. package/dist/domain/entities/product-requirements.d.ts.map +1 -0
  47. package/dist/domain/entities/product-requirements.js +6 -0
  48. package/dist/domain/entities/product-requirements.js.map +1 -0
  49. package/dist/domain/entities/task.d.ts +152 -0
  50. package/dist/domain/entities/task.d.ts.map +1 -0
  51. package/dist/domain/entities/task.js +61 -0
  52. package/dist/domain/entities/task.js.map +1 -0
  53. package/dist/domain/interfaces/agent.interface.d.ts +15 -0
  54. package/dist/domain/interfaces/agent.interface.d.ts.map +1 -0
  55. package/dist/domain/interfaces/agent.interface.js +6 -0
  56. package/dist/domain/interfaces/agent.interface.js.map +1 -0
  57. package/dist/domain/services/environment-mode-manager.d.ts +18 -0
  58. package/dist/domain/services/environment-mode-manager.d.ts.map +1 -0
  59. package/dist/domain/services/environment-mode-manager.js +37 -0
  60. package/dist/domain/services/environment-mode-manager.js.map +1 -0
  61. package/dist/domain/services/risk-tier-detector.d.ts +18 -0
  62. package/dist/domain/services/risk-tier-detector.d.ts.map +1 -0
  63. package/dist/domain/services/risk-tier-detector.js +65 -0
  64. package/dist/domain/services/risk-tier-detector.js.map +1 -0
  65. package/dist/formatter.d.ts.map +1 -1
  66. package/dist/formatter.js +10 -3
  67. package/dist/formatter.js.map +1 -1
  68. package/dist/index.js +103 -129
  69. package/dist/index.js.map +1 -1
  70. package/dist/infrastructure/ai/cohere-ai-service.d.ts.map +1 -1
  71. package/dist/infrastructure/ai/cohere-ai-service.js +15 -2
  72. package/dist/infrastructure/ai/cohere-ai-service.js.map +1 -1
  73. package/dist/infrastructure/ai/fake-ai-service.d.ts +22 -0
  74. package/dist/infrastructure/ai/fake-ai-service.d.ts.map +1 -0
  75. package/dist/infrastructure/ai/fake-ai-service.js +59 -0
  76. package/dist/infrastructure/ai/fake-ai-service.js.map +1 -0
  77. package/dist/infrastructure/ai/provider-ai-service.d.ts +59 -0
  78. package/dist/infrastructure/ai/provider-ai-service.d.ts.map +1 -0
  79. package/dist/infrastructure/ai/provider-ai-service.js +477 -0
  80. package/dist/infrastructure/ai/provider-ai-service.js.map +1 -0
  81. package/dist/infrastructure/cache/embedding-cache.d.ts +13 -1
  82. package/dist/infrastructure/cache/embedding-cache.d.ts.map +1 -1
  83. package/dist/infrastructure/cache/embedding-cache.js +80 -9
  84. package/dist/infrastructure/cache/embedding-cache.js.map +1 -1
  85. package/dist/infrastructure/cache/response-cache.d.ts +86 -0
  86. package/dist/infrastructure/cache/response-cache.d.ts.map +1 -0
  87. package/dist/infrastructure/cache/response-cache.js +224 -0
  88. package/dist/infrastructure/cache/response-cache.js.map +1 -0
  89. package/dist/infrastructure/context/conversation-context.d.ts +58 -0
  90. package/dist/infrastructure/context/conversation-context.d.ts.map +1 -0
  91. package/dist/infrastructure/context/conversation-context.js +170 -0
  92. package/dist/infrastructure/context/conversation-context.js.map +1 -0
  93. package/dist/infrastructure/context/session-manager.d.ts +26 -0
  94. package/dist/infrastructure/context/session-manager.d.ts.map +1 -0
  95. package/dist/infrastructure/context/session-manager.js +98 -0
  96. package/dist/infrastructure/context/session-manager.js.map +1 -0
  97. package/dist/infrastructure/cost/cost-tracker.d.ts +1 -0
  98. package/dist/infrastructure/cost/cost-tracker.d.ts.map +1 -1
  99. package/dist/infrastructure/cost/cost-tracker.js +12 -5
  100. package/dist/infrastructure/cost/cost-tracker.js.map +1 -1
  101. package/dist/infrastructure/governance/nist-ai-rmf.d.ts +6 -8
  102. package/dist/infrastructure/governance/nist-ai-rmf.d.ts.map +1 -1
  103. package/dist/infrastructure/governance/nist-ai-rmf.js +6 -8
  104. package/dist/infrastructure/governance/nist-ai-rmf.js.map +1 -1
  105. package/dist/infrastructure/governance/policy-as-code.d.ts +6 -8
  106. package/dist/infrastructure/governance/policy-as-code.d.ts.map +1 -1
  107. package/dist/infrastructure/governance/policy-as-code.js +6 -8
  108. package/dist/infrastructure/governance/policy-as-code.js.map +1 -1
  109. package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts +7 -9
  110. package/dist/infrastructure/governance/prompt-to-code-lineage.d.ts.map +1 -1
  111. package/dist/infrastructure/governance/prompt-to-code-lineage.js +7 -9
  112. package/dist/infrastructure/governance/prompt-to-code-lineage.js.map +1 -1
  113. package/dist/infrastructure/providers/cohere-provider.d.ts +39 -0
  114. package/dist/infrastructure/providers/cohere-provider.d.ts.map +1 -0
  115. package/dist/infrastructure/providers/cohere-provider.js +359 -0
  116. package/dist/infrastructure/providers/cohere-provider.js.map +1 -0
  117. package/dist/infrastructure/providers/fake-provider.d.ts +43 -0
  118. package/dist/infrastructure/providers/fake-provider.d.ts.map +1 -0
  119. package/dist/infrastructure/providers/fake-provider.js +130 -0
  120. package/dist/infrastructure/providers/fake-provider.js.map +1 -0
  121. package/dist/infrastructure/providers/local-llm-provider.d.ts +49 -0
  122. package/dist/infrastructure/providers/local-llm-provider.d.ts.map +1 -0
  123. package/dist/infrastructure/providers/local-llm-provider.js +330 -0
  124. package/dist/infrastructure/providers/local-llm-provider.js.map +1 -0
  125. package/dist/infrastructure/providers/model-config.types.d.ts +70 -0
  126. package/dist/infrastructure/providers/model-config.types.d.ts.map +1 -0
  127. package/dist/infrastructure/providers/model-config.types.js +9 -0
  128. package/dist/infrastructure/providers/model-config.types.js.map +1 -0
  129. package/dist/infrastructure/providers/model-provider.interface.d.ts +113 -0
  130. package/dist/infrastructure/providers/model-provider.interface.d.ts.map +1 -0
  131. package/dist/infrastructure/providers/model-provider.interface.js +8 -0
  132. package/dist/infrastructure/providers/model-provider.interface.js.map +1 -0
  133. package/dist/infrastructure/providers/openai-provider.d.ts +38 -0
  134. package/dist/infrastructure/providers/openai-provider.d.ts.map +1 -0
  135. package/dist/infrastructure/providers/openai-provider.js +413 -0
  136. package/dist/infrastructure/providers/openai-provider.js.map +1 -0
  137. package/dist/infrastructure/providers/operation-provider-resolver.d.ts +48 -0
  138. package/dist/infrastructure/providers/operation-provider-resolver.d.ts.map +1 -0
  139. package/dist/infrastructure/providers/operation-provider-resolver.js +105 -0
  140. package/dist/infrastructure/providers/operation-provider-resolver.js.map +1 -0
  141. package/dist/infrastructure/providers/provider-config-loader.d.ts +37 -0
  142. package/dist/infrastructure/providers/provider-config-loader.d.ts.map +1 -0
  143. package/dist/infrastructure/providers/provider-config-loader.js +120 -0
  144. package/dist/infrastructure/providers/provider-config-loader.js.map +1 -0
  145. package/dist/infrastructure/providers/provider-registry.d.ts +53 -0
  146. package/dist/infrastructure/providers/provider-registry.d.ts.map +1 -0
  147. package/dist/infrastructure/providers/provider-registry.js +88 -0
  148. package/dist/infrastructure/providers/provider-registry.js.map +1 -0
  149. package/dist/infrastructure/storage/task-helpers.d.ts +58 -0
  150. package/dist/infrastructure/storage/task-helpers.d.ts.map +1 -0
  151. package/dist/infrastructure/storage/task-helpers.js +157 -0
  152. package/dist/infrastructure/storage/task-helpers.js.map +1 -0
  153. package/dist/infrastructure/storage/task-repository.d.ts +67 -0
  154. package/dist/infrastructure/storage/task-repository.d.ts.map +1 -0
  155. package/dist/infrastructure/storage/task-repository.js +205 -0
  156. package/dist/infrastructure/storage/task-repository.js.map +1 -0
  157. package/dist/infrastructure/ux/bi-directional-learning.d.ts +22 -0
  158. package/dist/infrastructure/ux/bi-directional-learning.d.ts.map +1 -1
  159. package/dist/infrastructure/ux/bi-directional-learning.js +144 -7
  160. package/dist/infrastructure/ux/bi-directional-learning.js.map +1 -1
  161. package/dist/infrastructure/ux/capability-boundaries.d.ts +50 -0
  162. package/dist/infrastructure/ux/capability-boundaries.d.ts.map +1 -0
  163. package/dist/infrastructure/ux/capability-boundaries.js +167 -0
  164. package/dist/infrastructure/ux/capability-boundaries.js.map +1 -0
  165. package/dist/infrastructure/ux/comprehensive-formatter.d.ts +63 -0
  166. package/dist/infrastructure/ux/comprehensive-formatter.d.ts.map +1 -0
  167. package/dist/infrastructure/ux/comprehensive-formatter.js +212 -0
  168. package/dist/infrastructure/ux/comprehensive-formatter.js.map +1 -0
  169. package/dist/infrastructure/ux/feedback-prompt.d.ts +42 -0
  170. package/dist/infrastructure/ux/feedback-prompt.d.ts.map +1 -0
  171. package/dist/infrastructure/ux/feedback-prompt.js +181 -0
  172. package/dist/infrastructure/ux/feedback-prompt.js.map +1 -0
  173. package/dist/infrastructure/ux/hitl-review-portal.d.ts.map +1 -1
  174. package/dist/infrastructure/ux/hitl-review-portal.js +4 -1
  175. package/dist/infrastructure/ux/hitl-review-portal.js.map +1 -1
  176. package/dist/infrastructure/ux/hitl-validation.d.ts +35 -0
  177. package/dist/infrastructure/ux/hitl-validation.d.ts.map +1 -1
  178. package/dist/infrastructure/ux/hitl-validation.js +86 -0
  179. package/dist/infrastructure/ux/hitl-validation.js.map +1 -1
  180. package/dist/infrastructure/ux/progress-indicator.d.ts +2 -1
  181. package/dist/infrastructure/ux/progress-indicator.d.ts.map +1 -1
  182. package/dist/infrastructure/ux/progress-indicator.js +13 -3
  183. package/dist/infrastructure/ux/progress-indicator.js.map +1 -1
  184. package/dist/infrastructure/ux/proportional-friction.d.ts +73 -0
  185. package/dist/infrastructure/ux/proportional-friction.d.ts.map +1 -0
  186. package/dist/infrastructure/ux/proportional-friction.js +200 -0
  187. package/dist/infrastructure/ux/proportional-friction.js.map +1 -0
  188. package/dist/infrastructure/validation/agent-feedback.d.ts +115 -0
  189. package/dist/infrastructure/validation/agent-feedback.d.ts.map +1 -0
  190. package/dist/infrastructure/validation/agent-feedback.js +227 -0
  191. package/dist/infrastructure/validation/agent-feedback.js.map +1 -0
  192. package/dist/infrastructure/validation/agent-validation-helper.d.ts +75 -0
  193. package/dist/infrastructure/validation/agent-validation-helper.d.ts.map +1 -0
  194. package/dist/infrastructure/validation/agent-validation-helper.js +88 -0
  195. package/dist/infrastructure/validation/agent-validation-helper.js.map +1 -0
  196. package/dist/infrastructure/validation/feedback-stats.d.ts +99 -0
  197. package/dist/infrastructure/validation/feedback-stats.d.ts.map +1 -0
  198. package/dist/infrastructure/validation/feedback-stats.js +173 -0
  199. package/dist/infrastructure/validation/feedback-stats.js.map +1 -0
  200. package/dist/infrastructure/validation/review-handler.d.ts +54 -0
  201. package/dist/infrastructure/validation/review-handler.d.ts.map +1 -0
  202. package/dist/infrastructure/validation/review-handler.js +206 -0
  203. package/dist/infrastructure/validation/review-handler.js.map +1 -0
  204. package/dist/infrastructure/validation/summary-aggregator.d.ts +42 -0
  205. package/dist/infrastructure/validation/summary-aggregator.d.ts.map +1 -0
  206. package/dist/infrastructure/validation/summary-aggregator.js +156 -0
  207. package/dist/infrastructure/validation/summary-aggregator.js.map +1 -0
  208. package/dist/infrastructure/validation/summary-extractor.d.ts +59 -0
  209. package/dist/infrastructure/validation/summary-extractor.d.ts.map +1 -0
  210. package/dist/infrastructure/validation/summary-extractor.js +102 -0
  211. package/dist/infrastructure/validation/summary-extractor.js.map +1 -0
  212. package/dist/infrastructure/validation/trace-summary.d.ts +72 -0
  213. package/dist/infrastructure/validation/trace-summary.d.ts.map +1 -0
  214. package/dist/infrastructure/validation/trace-summary.js +371 -0
  215. package/dist/infrastructure/validation/trace-summary.js.map +1 -0
  216. package/dist/infrastructure/validation/trust-config.d.ts +27 -0
  217. package/dist/infrastructure/validation/trust-config.d.ts.map +1 -0
  218. package/dist/infrastructure/validation/trust-config.js +113 -0
  219. package/dist/infrastructure/validation/trust-config.js.map +1 -0
  220. package/dist/infrastructure/xai/attention-visualizer.d.ts +6 -8
  221. package/dist/infrastructure/xai/attention-visualizer.d.ts.map +1 -1
  222. package/dist/infrastructure/xai/attention-visualizer.js +6 -8
  223. package/dist/infrastructure/xai/attention-visualizer.js.map +1 -1
  224. package/dist/infrastructure/xai/cot-visualizer.d.ts +6 -9
  225. package/dist/infrastructure/xai/cot-visualizer.d.ts.map +1 -1
  226. package/dist/infrastructure/xai/cot-visualizer.js +6 -9
  227. package/dist/infrastructure/xai/cot-visualizer.js.map +1 -1
  228. package/dist/infrastructure/xai/decision-tree-log.d.ts +6 -10
  229. package/dist/infrastructure/xai/decision-tree-log.d.ts.map +1 -1
  230. package/dist/infrastructure/xai/decision-tree-log.js +6 -10
  231. package/dist/infrastructure/xai/decision-tree-log.js.map +1 -1
  232. package/dist/infrastructure/xai/interactive-xai.d.ts +6 -8
  233. package/dist/infrastructure/xai/interactive-xai.d.ts.map +1 -1
  234. package/dist/infrastructure/xai/interactive-xai.js +6 -8
  235. package/dist/infrastructure/xai/interactive-xai.js.map +1 -1
  236. package/dist/infrastructure/xai/uncertainty-quantifier.d.ts +6 -9
  237. package/dist/infrastructure/xai/uncertainty-quantifier.d.ts.map +1 -1
  238. package/dist/infrastructure/xai/uncertainty-quantifier.js +6 -9
  239. package/dist/infrastructure/xai/uncertainty-quantifier.js.map +1 -1
  240. package/dist/presentation/cli/commands/ask-command.d.ts.map +1 -1
  241. package/dist/presentation/cli/commands/ask-command.js +84 -2
  242. package/dist/presentation/cli/commands/ask-command.js.map +1 -1
  243. package/dist/presentation/cli/commands/docs-command.d.ts +12 -0
  244. package/dist/presentation/cli/commands/docs-command.d.ts.map +1 -0
  245. package/dist/presentation/cli/commands/docs-command.js +196 -0
  246. package/dist/presentation/cli/commands/docs-command.js.map +1 -0
  247. package/dist/presentation/cli/commands/fix-command.d.ts +8 -0
  248. package/dist/presentation/cli/commands/fix-command.d.ts.map +1 -0
  249. package/dist/presentation/cli/commands/fix-command.js +309 -0
  250. package/dist/presentation/cli/commands/fix-command.js.map +1 -0
  251. package/dist/presentation/cli/commands/help-command.d.ts.map +1 -1
  252. package/dist/presentation/cli/commands/help-command.js +2 -0
  253. package/dist/presentation/cli/commands/help-command.js.map +1 -1
  254. package/dist/presentation/cli/commands/orchestrate-command.d.ts +1 -0
  255. package/dist/presentation/cli/commands/orchestrate-command.d.ts.map +1 -1
  256. package/dist/presentation/cli/commands/orchestrate-command.js +53 -0
  257. package/dist/presentation/cli/commands/orchestrate-command.js.map +1 -1
  258. package/dist/presentation/cli/commands/plan-command.d.ts +1 -0
  259. package/dist/presentation/cli/commands/plan-command.d.ts.map +1 -1
  260. package/dist/presentation/cli/commands/plan-command.js +80 -3
  261. package/dist/presentation/cli/commands/plan-command.js.map +1 -1
  262. package/dist/presentation/cli/commands/product-command.d.ts +12 -0
  263. package/dist/presentation/cli/commands/product-command.d.ts.map +1 -0
  264. package/dist/presentation/cli/commands/product-command.js +188 -0
  265. package/dist/presentation/cli/commands/product-command.js.map +1 -0
  266. package/dist/presentation/cli/commands/react-command.d.ts.map +1 -1
  267. package/dist/presentation/cli/commands/react-command.js +3 -1
  268. package/dist/presentation/cli/commands/react-command.js.map +1 -1
  269. package/dist/presentation/cli/commands/review-command.d.ts +14 -0
  270. package/dist/presentation/cli/commands/review-command.d.ts.map +1 -0
  271. package/dist/presentation/cli/commands/review-command.js +22 -0
  272. package/dist/presentation/cli/commands/review-command.js.map +1 -0
  273. package/dist/presentation/cli/commands/run-command.d.ts +15 -0
  274. package/dist/presentation/cli/commands/run-command.d.ts.map +1 -0
  275. package/dist/presentation/cli/commands/run-command.js +29 -0
  276. package/dist/presentation/cli/commands/run-command.js.map +1 -0
  277. package/dist/presentation/cli/commands/smart-command.d.ts +3 -1
  278. package/dist/presentation/cli/commands/smart-command.d.ts.map +1 -1
  279. package/dist/presentation/cli/commands/smart-command.js +92 -6
  280. package/dist/presentation/cli/commands/smart-command.js.map +1 -1
  281. package/dist/presentation/cli/commands/status-command.d.ts +11 -0
  282. package/dist/presentation/cli/commands/status-command.d.ts.map +1 -0
  283. package/dist/presentation/cli/commands/status-command.js +176 -0
  284. package/dist/presentation/cli/commands/status-command.js.map +1 -0
  285. package/dist/presentation/cli/commands/suggest-command.d.ts +13 -0
  286. package/dist/presentation/cli/commands/suggest-command.d.ts.map +1 -0
  287. package/dist/presentation/cli/commands/suggest-command.js +25 -0
  288. package/dist/presentation/cli/commands/suggest-command.js.map +1 -0
  289. package/dist/presentation/cli/error-display.d.ts.map +1 -1
  290. package/dist/presentation/cli/error-display.js +43 -0
  291. package/dist/presentation/cli/error-display.js.map +1 -1
  292. package/dist/session.js +19 -2
  293. package/dist/session.js.map +1 -1
  294. package/dist/ui.d.ts.map +1 -1
  295. package/dist/ui.js +8 -5
  296. package/dist/ui.js.map +1 -1
  297. package/package.json +10 -2
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Infrastructure: Agent Validation Helper
3
+ * Shared utilities for integrating Validation Layer into agents
4
+ *
5
+ * Provides:
6
+ * - Automatic TraceSummary generation
7
+ * - AgentFeedback recording
8
+ * - Run context tracking
9
+ */
10
+ import type { TraceSummary } from './trace-summary.js';
11
+ import type { FeedbackOutcome, UserAction } from './agent-feedback.js';
12
+ export interface AgentValidationContext {
13
+ runId: string;
14
+ agentName: string;
15
+ operation: string;
16
+ startTime: number;
17
+ }
18
+ export interface AgentValidationResult<T = any> {
19
+ result: T;
20
+ summary: TraceSummary;
21
+ feedbackId: string;
22
+ runId: string;
23
+ }
24
+ /**
25
+ * Helper class for agent validation integration
26
+ */
27
+ export declare class AgentValidationHelper {
28
+ /**
29
+ * Start validation context for an agent operation
30
+ */
31
+ startAgentOperation(agentName: string, operation: string, context?: {
32
+ query?: string;
33
+ codebaseId?: string;
34
+ }): AgentValidationContext;
35
+ /**
36
+ * Complete agent operation and generate validation artifacts
37
+ */
38
+ completeAgentOperation<T>(validationContext: AgentValidationContext, result: T, metadata: {
39
+ outcome: FeedbackOutcome;
40
+ userAction?: UserAction;
41
+ filesChanged?: string[];
42
+ filesCreated?: string[];
43
+ filesDeleted?: string[];
44
+ errors?: string[];
45
+ warnings?: string[];
46
+ validationChecks?: Array<{
47
+ check: string;
48
+ passed: boolean;
49
+ message?: string;
50
+ critical?: boolean;
51
+ }>;
52
+ metrics?: {
53
+ tokensUsed?: number;
54
+ duration?: number;
55
+ filesAnalyzed?: number;
56
+ changesProposed?: number;
57
+ changesApplied?: number;
58
+ };
59
+ additionalContext?: Record<string, any>;
60
+ }): Promise<AgentValidationResult<T>>;
61
+ /**
62
+ * Record a trace during agent operation
63
+ */
64
+ trace(operation: {
65
+ operationType: 'llm_call' | 'tool_invocation' | 'memory_operation' | 'plan_generation' | 'code_analysis' | 'file_operation' | 'git_operation' | 'other';
66
+ operationName: string;
67
+ input?: any;
68
+ output?: any;
69
+ error?: Error;
70
+ metadata?: Record<string, any>;
71
+ duration?: number;
72
+ }): string;
73
+ }
74
+ export declare const agentValidationHelper: AgentValidationHelper;
75
+ //# sourceMappingURL=agent-validation-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-validation-helper.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/validation/agent-validation-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAiB,eAAe,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtF,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB,CAAC,CAAC,GAAG,GAAG;IAC5C,MAAM,EAAE,CAAC,CAAC;IACV,OAAO,EAAE,YAAY,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,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AAG,iBAAiB,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,eAAe,GAAG,gBAAgB,GAAG,eAAe,GAAG,OAAO,CAAC;QACxJ,aAAa,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,MAAM,CAAC,EAAE,GAAG,CAAC;QACb,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,MAAM;CAGX;AAGD,eAAO,MAAM,qBAAqB,uBAA8B,CAAC"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Infrastructure: Agent Validation Helper
3
+ * Shared utilities for integrating Validation Layer into agents
4
+ *
5
+ * Provides:
6
+ * - Automatic TraceSummary generation
7
+ * - AgentFeedback recording
8
+ * - Run context tracking
9
+ */
10
+ import { executionTracer } from '../observability/execution-tracer.js';
11
+ import { agentFeedbackManager } from './agent-feedback.js';
12
+ import { traceSummaryFormatter } from './trace-summary.js';
13
+ /**
14
+ * Helper class for agent validation integration
15
+ */
16
+ export class AgentValidationHelper {
17
+ /**
18
+ * Start validation context for an agent operation
19
+ */
20
+ startAgentOperation(agentName, operation, context) {
21
+ const runId = executionTracer.startRun(`${agentName}:${operation}`, {
22
+ query: context?.query,
23
+ codebaseId: context?.codebaseId,
24
+ });
25
+ return {
26
+ runId,
27
+ agentName,
28
+ operation,
29
+ startTime: Date.now(),
30
+ };
31
+ }
32
+ /**
33
+ * Complete agent operation and generate validation artifacts
34
+ */
35
+ async completeAgentOperation(validationContext, result, metadata) {
36
+ // End trace to finalize run context
37
+ executionTracer.endRun();
38
+ // Small delay to ensure file is written
39
+ await new Promise(resolve => setTimeout(resolve, 100));
40
+ // Get finalized run context
41
+ const run = executionTracer.getRun(validationContext.runId);
42
+ const duration = Date.now() - validationContext.startTime;
43
+ // Note: Feedback recording is handled by CLI commands with proper userAction from review decision
44
+ // This helper only creates the validation summary, not the feedback record
45
+ const feedbackId = 'pending-cli-feedback';
46
+ // Create trace summary
47
+ const summary = traceSummaryFormatter.createSummary(run || {
48
+ runId: validationContext.runId,
49
+ startTime: validationContext.startTime,
50
+ endTime: Date.now(),
51
+ operation: validationContext.operation,
52
+ query: metadata.additionalContext?.query,
53
+ codebaseId: metadata.additionalContext?.codebaseId,
54
+ traces: [],
55
+ }, agentFeedbackManager.getFeedbackForRun(validationContext.runId) || undefined, validationContext.agentName);
56
+ // Update summary with metadata if available
57
+ if (metadata.filesChanged) {
58
+ summary.filesChanged = metadata.filesChanged;
59
+ }
60
+ if (metadata.filesCreated) {
61
+ summary.filesCreated = metadata.filesCreated;
62
+ }
63
+ if (metadata.filesDeleted) {
64
+ summary.filesDeleted = metadata.filesDeleted;
65
+ }
66
+ if (metadata.errors) {
67
+ summary.errors = metadata.errors;
68
+ }
69
+ if (metadata.warnings) {
70
+ summary.warnings = metadata.warnings;
71
+ }
72
+ return {
73
+ result,
74
+ summary,
75
+ feedbackId,
76
+ runId: validationContext.runId,
77
+ };
78
+ }
79
+ /**
80
+ * Record a trace during agent operation
81
+ */
82
+ trace(operation) {
83
+ return executionTracer.trace(operation);
84
+ }
85
+ }
86
+ // Singleton instance
87
+ export const agentValidationHelper = new AgentValidationHelper();
88
+ //# sourceMappingURL=agent-validation-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-validation-helper.js","sourceRoot":"","sources":["../../../src/infrastructure/validation/agent-validation-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAmB3D;;GAEG;AACH,MAAM,OAAO,qBAAqB;IAChC;;OAEG;IACH,mBAAmB,CACjB,SAAiB,EACjB,SAAiB,E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C5E,iBAAiB,CAAC,SAAS,CAC5B,CAAC;QAEF,4CAA4C;QAC5C,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC1B,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC/C,CAAC;QACD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC1B,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC/C,CAAC;QACD,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC1B,OAAO,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;QAC/C,CAAC;QACD,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QACnC,CAAC;QACD,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACtB,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QACvC,CAAC;QAED,OAAO;YACL,MAAM;YACN,OAAO;YACP,UAAU;YACV,KAAK,EAAE,iBAAiB,CAAC,KAAK;SAC/B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAQL;QACC,OAAO,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;CACF;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Infrastructure: Feedback Statistics Builders
3
+ * Pure functions to compute feedback analytics and status snapshots
4
+ *
5
+ * Clean Architecture: Infrastructure Layer
6
+ * Strategic: Provides machine-readable JSON outputs for CI/dashboards
7
+ */
8
+ import type { TrustConfig } from './trust-config.js';
9
+ export type FeedbackOutcome = 'success' | 'failure' | 'partial_success' | 'cancelled' | 'error';
10
+ export type UserAction = 'approved' | 'rejected' | 'modified' | 'skipped' | 'not_required';
11
+ export interface AgentFeedback {
12
+ feedbackId: string;
13
+ runId: string;
14
+ agentName: string;
15
+ timestamp: number;
16
+ operation: string;
17
+ query?: string;
18
+ outcome: FeedbackOutcome;
19
+ userAction?: UserAction;
20
+ filesChanged?: string[];
21
+ filesCreated?: string[];
22
+ filesDeleted?: string[];
23
+ errors?: string[];
24
+ warnings?: string[];
25
+ validationChecks?: Array<{
26
+ check: string;
27
+ passed: boolean;
28
+ message?: string;
29
+ }>;
30
+ metrics?: {
31
+ tokensUsed?: number;
32
+ duration?: number;
33
+ filesAnalyzed?: number;
34
+ };
35
+ }
36
+ /**
37
+ * JSON output for analyze-feedback script
38
+ */
39
+ export interface FeedbackAnalyticsJson {
40
+ totalRecords: number;
41
+ agents: Array<{
42
+ agentName: string;
43
+ totalRuns: number;
44
+ trustScore: number;
45
+ belowThreshold: boolean;
46
+ threshold: number;
47
+ outcomes: Record<string, number>;
48
+ userActions: Record<string, number>;
49
+ }>;
50
+ operations: Array<{
51
+ operation: string;
52
+ count: number;
53
+ outcomes: Record<string, number>;
54
+ }>;
55
+ }
56
+ /**
57
+ * JSON output for status command
58
+ */
59
+ export interface StatusSnapshotJson {
60
+ totalRecords: number;
61
+ agents: Array<{
62
+ agentName: string;
63
+ success: {
64
+ runs: number;
65
+ total: number;
66
+ };
67
+ trustScore: number;
68
+ threshold: number;
69
+ belowThreshold: boolean;
70
+ }>;
71
+ operations: Array<{
72
+ operation: string;
73
+ runs: number;
74
+ }>;
75
+ }
76
+ /**
77
+ * Build feedback analytics JSON from feedback records and trust config
78
+ */
79
+ export declare function buildFeedbackAnalyticsJson(feedback: AgentFeedback[], trustConfig: TrustConfig): FeedbackAnalyticsJson;
80
+ /**
81
+ * Build status snapshot JSON from feedback records and trust config
82
+ */
83
+ export declare function buildStatusSnapshotJson(feedback: AgentFeedback[], trustConfig: TrustConfig): StatusSnapshotJson;
84
+ /**
85
+ * Result of trust threshold evaluation
86
+ */
87
+ export interface TrustCheckResult {
88
+ offenders: Array<{
89
+ agentName: string;
90
+ trustScore: number;
91
+ threshold: number;
92
+ }>;
93
+ }
94
+ /**
95
+ * Evaluate trust thresholds from analytics JSON
96
+ * Returns agents that are below their configured thresholds
97
+ */
98
+ export declare function evaluateTrustThresholds(analytics: FeedbackAnalyticsJson): TrustCheckResult;
99
+ //# sourceMappingURL=feedback-stats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feedback-stats.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/validation/feedback-stats.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,SAAS,GAAG,iBAAiB,GAAG,WAAW,GAAG,OAAO,CAAC;AAChG,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,cAAc,CAAC;AAE3F,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,eAAe,CAAC;IACzB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,gBAAgB,CAAC,EAAE,KAAK,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,OAAO,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC,CAAC;IACH,OAAO,CAAC,EAAE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AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,aAAa,EAAE,EACzB,WAAW,EAAE,WAAW,GACvB,kBAAkB,CAwEpB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,KAAK,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;CACJ;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,qBAAqB,GAAG,gBAAgB,CAmB1F"}
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Infrastructure: Feedback Statistics Builders
3
+ * Pure functions to compute feedback analytics and status snapshots
4
+ *
5
+ * Clean Architecture: Infrastructure Layer
6
+ * Strategic: Provides machine-readable JSON outputs for CI/dashboards
7
+ */
8
+ import { getAgentThreshold } from './trust-config.js';
9
+ /**
10
+ * Build feedback analytics JSON from feedback records and trust config
11
+ */
12
+ export function buildFeedbackAnalyticsJson(feedback, trustConfig) {
13
+ const byAgent = {};
14
+ const byOperationMap = {};
15
+ // Aggregate feedback
16
+ for (const record of feedback) {
17
+ // Aggregate by agent
18
+ if (!byAgent[record.agentName]) {
19
+ byAgent[record.agentName] = {
20
+ totalRuns: 0,
21
+ outcomes: {
22
+ success: 0,
23
+ failure: 0,
24
+ partial_success: 0,
25
+ cancelled: 0,
26
+ error: 0,
27
+ },
28
+ userActions: {
29
+ approved: 0,
30
+ rejected: 0,
31
+ modified: 0,
32
+ skipped: 0,
33
+ not_required: 0,
34
+ },
35
+ };
36
+ }
37
+ const agentStats = byAgent[record.agentName];
38
+ agentStats.totalRuns++;
39
+ agentStats.outcomes[record.outcome] = (agentStats.outcomes[record.outcome] || 0) + 1;
40
+ if (record.userAction) {
41
+ agentStats.userActions[record.userAction] =
42
+ (agentStats.userActions[record.userAction] || 0) + 1;
43
+ }
44
+ // Aggregate by operation
45
+ if (record.operation) {
46
+ if (!byOperationMap[record.operation]) {
47
+ byOperationMap[record.operation] = {
48
+ operation: record.operation,
49
+ count: 0,
50
+ outcomes: {
51
+ success: 0,
52
+ failure: 0,
53
+ partial_success: 0,
54
+ cancelled: 0,
55
+ error: 0,
56
+ },
57
+ };
58
+ }
59
+ const opStats = byOperationMap[record.operation];
60
+ opStats.count++;
61
+ opStats.outcomes[record.outcome] = (opStats.outcomes[record.outcome] || 0) + 1;
62
+ }
63
+ }
64
+ // Calculate trust scores and build agent array
65
+ const agents = Object.entries(byAgent)
66
+ .map(([agentName, stats]) => {
67
+ const approvedSuccessRuns = feedback.filter(f => f.agentName === agentName &&
68
+ f.outcome === 'success' &&
69
+ f.userAction === 'approved').length;
70
+ const trustScore = stats.totalRuns > 0
71
+ ? (approvedSuccessRuns / stats.totalRuns) * 100
72
+ : 0;
73
+ const threshold = getAgentThreshold(trustConfig, agentName);
74
+ const belowThreshold = threshold > 0 && trustScore < threshold;
75
+ return {
76
+ agentName,
77
+ totalRuns: stats.totalRuns,
78
+ trustScore: Math.round(trustScore * 100) / 100, // Round to 2 decimal places
79
+ belowThreshold,
80
+ threshold,
81
+ outcomes: stats.outcomes,
82
+ userActions: stats.userActions,
83
+ };
84
+ })
85
+ .sort((a, b) => b.totalRuns - a.totalRuns);
86
+ // Build operations array
87
+ const operations = Object.values(byOperationMap)
88
+ .sort((a, b) => b.count - a.count);
89
+ return {
90
+ totalRecords: feedback.length,
91
+ agents,
92
+ operations,
93
+ };
94
+ }
95
+ /**
96
+ * Build status snapshot JSON from feedback records and trust config
97
+ */
98
+ export function buildStatusSnapshotJson(feedback, trustConfig) {
99
+ const agentStatsMap = {};
100
+ const operationStatsMap = {};
101
+ // Aggregate feedback
102
+ for (const record of feedback) {
103
+ // Aggregate by agent
104
+ if (!agentStatsMap[record.agentName]) {
105
+ agentStatsMap[record.agentName] = {
106
+ totalRuns: 0,
107
+ successRuns: 0,
108
+ trustScore: 0,
109
+ };
110
+ }
111
+ const stats = agentStatsMap[record.agentName];
112
+ stats.totalRuns++;
113
+ if (record.outcome === 'success') {
114
+ stats.successRuns++;
115
+ }
116
+ // Aggregate by operation
117
+ if (record.operation) {
118
+ operationStatsMap[record.operation] = (operationStatsMap[record.operation] || 0) + 1;
119
+ }
120
+ }
121
+ // Calculate trust scores and build agent array
122
+ const agents = Object.entries(agentStatsMap)
123
+ .map(([agentName, stats]) => {
124
+ const approvedSuccessRuns = feedback.filter(f => f.agentName === agentName &&
125
+ f.outcome === 'success' &&
126
+ f.userAction === 'approved').length;
127
+ const trustScore = stats.totalRuns > 0
128
+ ? (approvedSuccessRuns / stats.totalRuns) * 100
129
+ : 0;
130
+ const threshold = getAgentThreshold(trustConfig, agentName);
131
+ const belowThreshold = threshold > 0 && trustScore < threshold;
132
+ return {
133
+ agentName,
134
+ success: {
135
+ runs: stats.successRuns,
136
+ total: stats.totalRuns,
137
+ },
138
+ trustScore: Math.round(trustScore * 100) / 100, // Round to 2 decimal places
139
+ threshold,
140
+ belowThreshold,
141
+ };
142
+ })
143
+ .sort((a, b) => b.trustScore - a.trustScore);
144
+ // Build operations array
145
+ const operations = Object.entries(operationStatsMap)
146
+ .map(([operation, runs]) => ({ operation, runs }))
147
+ .sort((a, b) => b.runs - a.runs)
148
+ .slice(0, 5); // Top 5 operations
149
+ return {
150
+ totalRecords: feedback.length,
151
+ agents,
152
+ operations,
153
+ };
154
+ }
155
+ /**
156
+ * Evaluate trust thresholds from analytics JSON
157
+ * Returns agents that are below their configured thresholds
158
+ */
159
+ export function evaluateTrustThresholds(analytics) {
160
+ const offenders = [];
161
+ for (const agent of analytics.agents) {
162
+ // Only consider agents with threshold > 0
163
+ if (agent.threshold > 0 && agent.trustScore < agent.threshold) {
164
+ offenders.push({
165
+ agentName: agent.agentName,
166
+ trustScore: agent.trustScore,
167
+ threshold: agent.threshold,
168
+ });
169
+ }
170
+ }
171
+ return { offenders };
172
+ }
173
+ //# sourceMappingURL=feedback-stats.js.map
@@ -0,0 +1 @@
1
+ {"version":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+ * Infrastructure: Review Handler
3
+ * Handles --review flag behavior: pause, display summary, ask yes/no
4
+ */
5
+ import type { TraceSummary } from './trace-summary.js';
6
+ export interface ReviewDecision {
7
+ approved: boolean;
8
+ proceed: boolean;
9
+ reason?: string;
10
+ userAction: 'approved' | 'rejected' | 'not_required';
11
+ }
12
+ /**
13
+ * Review Handler
14
+ * Manages the review flow when --review flag is enabled
15
+ */
16
+ export declare class ReviewHandler {
17
+ /**
18
+ * Request user review before proceeding
19
+ */
20
+ requestReview(summary: TraceSummary, options?: {
21
+ timeout?: number;
22
+ defaultAction?: 'approve' | 'reject';
23
+ }): Promise<ReviewDecision>;
24
+ /**
25
+ * Prompt user for approval (yes/no)
26
+ */
27
+ private promptApproval;
28
+ /**
29
+ * Check if review should be required based on summary
30
+ */
31
+ shouldRequireReview(summary: TraceSummary): boolean;
32
+ /**
33
+ * Get review decision - single source of truth for userAction
34
+ *
35
+ * This method is the ONLY place where userAction is determined.
36
+ * All CLI commands must use this method and trust its userAction value.
37
+ *
38
+ * Logic:
39
+ * 1. If reviewRequested === false:
40
+ * → userAction = 'not_required'
41
+ *
42
+ * 2. If reviewRequested === true and shouldReview === false:
43
+ * → userAction = 'approved' (user explicitly requested review, treat as approved)
44
+ *
45
+ * 3. If reviewRequested === true and shouldReview === true:
46
+ * → Call requestReview() which handles:
47
+ * - Interactive mode: prompt user, return 'approved' or 'rejected'
48
+ * - Non-interactive + auto-approve: return 'approved'
49
+ * - Non-interactive + no auto-approve: return 'rejected'
50
+ */
51
+ getReviewDecision(summary: TraceSummary, reviewRequested: boolean): Promise<ReviewDecision>;
52
+ }
53
+ export declare const reviewHandler: ReviewHandler;
54
+ //# sourceMappingURL=review-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review-handler.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/validation/review-handler.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGvD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,UAAU,GAAG,UAAU,GAAG,cAAc,CAAC;CACtD;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB;;OAEG;IACG,aAAa,CACjB,OAAO,EAAE,YAAY,EACrB,OAAO,GAAE;QACP,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;KACjC,GACL,OAAO,CAAC,cAAc,CAAC;IAkE1B;;OAEG;YACW,cAAc;IAmE5B;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO;IAwBnD;;;;;;;;;;;;;;;;;;OAkBG;IACG,iBAAiB,CACrB,OAAO,EAAE,YAAY,EACrB,eAAe,EAAE,OAAO,GACvB,OAAO,CAAC,cAAc,CAAC;CAiC3B;AAGD,eAAO,MAAM,aAAa,eAAsB,CAAC"}