codehere 0.2.2 → 0.3.0-rc.10

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 (238) hide show
  1. package/README.md +88 -68
  2. package/dist/domain/entities/task.js +4 -4
  3. package/dist/error-handler.js +4 -9
  4. package/dist/index.js +261 -1224
  5. package/dist/infrastructure/config/product-context.js +7 -6
  6. package/dist/infrastructure/hooks/claude-sdk-hook.js +348 -72
  7. package/dist/infrastructure/observability/execution-tracer.js +11 -6
  8. package/dist/infrastructure/orchestration/agent-adapter.js +13 -0
  9. package/dist/infrastructure/orchestration/agent-installer.js +101 -0
  10. package/dist/infrastructure/orchestration/agents-config-seed.js +56 -0
  11. package/dist/infrastructure/orchestration/aider-adapter.js +319 -0
  12. package/dist/infrastructure/orchestration/artifacts-extractor.js +175 -0
  13. package/dist/infrastructure/orchestration/claude-code-adapter.js +352 -0
  14. package/dist/infrastructure/orchestration/codex-adapter.js +310 -0
  15. package/dist/infrastructure/orchestration/conductor-adapter.js +340 -0
  16. package/dist/infrastructure/orchestration/generic-cli-adapter.js +553 -0
  17. package/dist/infrastructure/orchestration/opencode-adapter.js +275 -0
  18. package/dist/infrastructure/orchestration/progress-aggregator.js +189 -0
  19. package/dist/infrastructure/orchestration/readiness.js +106 -0
  20. package/dist/infrastructure/orchestration/session-manager.js +278 -0
  21. package/dist/infrastructure/orchestration/session-persistence.js +109 -0
  22. package/dist/infrastructure/protocols/mcp-helpers.js +10 -30
  23. package/dist/infrastructure/protocols/mcp-server-impl.js +359 -21
  24. package/dist/infrastructure/protocols/probe-port.js +36 -0
  25. package/dist/infrastructure/protocols/ui-page.js +1827 -0
  26. package/dist/infrastructure/security/file-collection.js +115 -0
  27. package/dist/infrastructure/security/trust-scorer.js +301 -56
  28. package/dist/infrastructure/storage/task-repository.js +8 -7
  29. package/dist/monitoring.js +9 -38
  30. package/dist/presentation/cli/commands/help-command.js +96 -139
  31. package/dist/presentation/cli/commands/hook-command.js +17 -24
  32. package/dist/presentation/cli/commands/report-command.js +59 -72
  33. package/dist/presentation/cli/commands/setup-command.js +4 -4
  34. package/dist/presentation/cli/commands/status-command.js +321 -30
  35. package/dist/presentation/cli/commands/trust-command.js +84 -72
  36. package/dist/presentation/cli/error-display.js +17 -21
  37. package/dist/presentation/cli/repl.js +474 -0
  38. package/dist/ui.js +11 -11
  39. package/package.json +24 -62
  40. package/dist/agents/base.js +0 -101
  41. package/dist/agents/orchestrator-model-driven.js +0 -141
  42. package/dist/agents/react-orchestrator-agent.js +0 -54
  43. package/dist/application/agents/execution-agent.js +0 -508
  44. package/dist/application/agents/multi-agent-orchestrator.js +0 -295
  45. package/dist/application/agents/planning-agent.js +0 -433
  46. package/dist/application/agents/validation-agent.js +0 -317
  47. package/dist/application/architectures/plan-and-act.js +0 -242
  48. package/dist/application/index.js +0 -12
  49. package/dist/application/services/agent-factory.js +0 -28
  50. package/dist/application/services/dependency-container.js +0 -596
  51. package/dist/application/services/git-context-service.js +0 -83
  52. package/dist/application/services/intelligent-router.js +0 -934
  53. package/dist/application/services/tool-executor-service.js +0 -94
  54. package/dist/application/use-cases/ask-question-use-case.js +0 -338
  55. package/dist/application/use-cases/edit-file-use-case.js +0 -830
  56. package/dist/application/use-cases/explain-file-use-case.js +0 -50
  57. package/dist/application/use-cases/index-codebase-use-case.js +0 -113
  58. package/dist/application/use-cases/planning-use-case.js +0 -276
  59. package/dist/application/use-cases/react-orchestration-use-case.js +0 -329
  60. package/dist/application/use-cases/reflexion-use-case.js +0 -30
  61. package/dist/application/workflows/deterministic-workflows.js +0 -189
  62. package/dist/ast-parser.js +0 -331
  63. package/dist/cache.js +0 -180
  64. package/dist/chat.js +0 -251
  65. package/dist/code-analysis.js +0 -327
  66. package/dist/context.js +0 -187
  67. package/dist/docs.js +0 -146
  68. package/dist/domain/entities/code-chunk.js +0 -6
  69. package/dist/domain/entities/decision.js +0 -9
  70. package/dist/domain/entities/edit.js +0 -6
  71. package/dist/domain/entities/knowledge-node.js +0 -9
  72. package/dist/domain/entities/knowledge-preservation.js +0 -10
  73. package/dist/domain/entities/memory.js +0 -6
  74. package/dist/domain/entities/pattern.js +0 -7
  75. package/dist/domain/entities/plan.js +0 -6
  76. package/dist/domain/entities/query.js +0 -6
  77. package/dist/domain/errors/embeddings-not-found-error.js +0 -13
  78. package/dist/domain/index.js +0 -19
  79. package/dist/domain/interfaces/ai-service.interface.js +0 -6
  80. package/dist/domain/interfaces/code-analyzer.interface.js +0 -6
  81. package/dist/domain/interfaces/decision-repository.interface.js +0 -9
  82. package/dist/domain/interfaces/embedding-repository.interface.js +0 -6
  83. package/dist/domain/interfaces/knowledge-graph-repository.interface.js +0 -9
  84. package/dist/domain/interfaces/knowledge-preservation-repository.interface.js +0 -8
  85. package/dist/domain/interfaces/memory-repository.interface.js +0 -6
  86. package/dist/domain/interfaces/pattern-repository.interface.js +0 -6
  87. package/dist/domain/interfaces/verification-service.interface.js +0 -6
  88. package/dist/domain/services/cross-team-pattern-sharing.js +0 -125
  89. package/dist/domain/services/decision-recorder.js +0 -223
  90. package/dist/domain/services/decision-retriever.js +0 -133
  91. package/dist/domain/services/environment-mode-manager.js +0 -22
  92. package/dist/domain/services/graded-memory-activation.js +0 -69
  93. package/dist/domain/services/knowledge-access.js +0 -132
  94. package/dist/domain/services/knowledge-extractor.js +0 -247
  95. package/dist/domain/services/knowledge-graph-builder.js +0 -268
  96. package/dist/domain/services/knowledge-graph-query.js +0 -187
  97. package/dist/domain/services/memory-retriever.js +0 -82
  98. package/dist/domain/services/memory-synthesizer.js +0 -91
  99. package/dist/domain/services/pattern-extractor.js +0 -442
  100. package/dist/domain/services/query-intent-classifier.js +0 -140
  101. package/dist/domain/services/react-loop.js +0 -186
  102. package/dist/domain/services/risk-tier-detector.js +0 -78
  103. package/dist/edit.js +0 -319
  104. package/dist/embed.js +0 -459
  105. package/dist/formatter.js +0 -168
  106. package/dist/git.js +0 -198
  107. package/dist/infrastructure/ai/cohere-ai-service.js +0 -607
  108. package/dist/infrastructure/ai/command-r-evaluation.js +0 -206
  109. package/dist/infrastructure/ai/model-config.js +0 -84
  110. package/dist/infrastructure/ai/provider-ai-service.js +0 -477
  111. package/dist/infrastructure/cache/embedding-cache.js +0 -175
  112. package/dist/infrastructure/cache/query-result-cache.js +0 -66
  113. package/dist/infrastructure/cache/response-cache.js +0 -48
  114. package/dist/infrastructure/cache/security-scan-cache.js +0 -47
  115. package/dist/infrastructure/chunking/ast-code-chunker.js +0 -19
  116. package/dist/infrastructure/chunking/code-aware-chunker.js +0 -397
  117. package/dist/infrastructure/context/context-compressor.js +0 -329
  118. package/dist/infrastructure/context/conversation-context.js +0 -128
  119. package/dist/infrastructure/context/session-manager.js +0 -94
  120. package/dist/infrastructure/cost/cost-tracker.js +0 -360
  121. package/dist/infrastructure/file-scanner/file-scanner.js +0 -106
  122. package/dist/infrastructure/governance/nist-ai-rmf.js +0 -292
  123. package/dist/infrastructure/governance/policy-as-code.js +0 -258
  124. package/dist/infrastructure/governance/prompt-to-code-lineage.js +0 -239
  125. package/dist/infrastructure/index.js +0 -7
  126. package/dist/infrastructure/observability/prompt-versioner.js +0 -145
  127. package/dist/infrastructure/protocols/a2a-metadata.js +0 -137
  128. package/dist/infrastructure/protocols/a2a-protocol.js +0 -314
  129. package/dist/infrastructure/protocols/mcp-oauth.js +0 -184
  130. package/dist/infrastructure/protocols/mcp-server.js +0 -333
  131. package/dist/infrastructure/protocols/streaming-handler.js +0 -103
  132. package/dist/infrastructure/providers/cohere-provider.js +0 -444
  133. package/dist/infrastructure/providers/fake-provider.js +0 -130
  134. package/dist/infrastructure/providers/local-llm-provider.js +0 -330
  135. package/dist/infrastructure/providers/model-config.types.js +0 -9
  136. package/dist/infrastructure/providers/model-provider.interface.js +0 -8
  137. package/dist/infrastructure/providers/openai-provider.js +0 -413
  138. package/dist/infrastructure/providers/openrouter-provider.js +0 -399
  139. package/dist/infrastructure/providers/operation-provider-resolver.js +0 -105
  140. package/dist/infrastructure/providers/provider-config-loader.js +0 -120
  141. package/dist/infrastructure/providers/provider-registry.js +0 -88
  142. package/dist/infrastructure/safety/pattern-detector.js +0 -133
  143. package/dist/infrastructure/security/ai-sast-scanner.js +0 -290
  144. package/dist/infrastructure/security/docker-sandbox.js +0 -178
  145. package/dist/infrastructure/security/enhanced-security-gate.js +0 -151
  146. package/dist/infrastructure/security/license-scanner.js +0 -167
  147. package/dist/infrastructure/security/provider-bias-detector.js +0 -164
  148. package/dist/infrastructure/security/sandbox-executor.js +0 -64
  149. package/dist/infrastructure/serialization/toon-serializer.js +0 -119
  150. package/dist/infrastructure/storage/memory-stream-service.js +0 -204
  151. package/dist/infrastructure/storage/plan-repository.js +0 -96
  152. package/dist/infrastructure/storage/sqlite-decision-repository.js +0 -232
  153. package/dist/infrastructure/storage/sqlite-embedding-repository.js +0 -311
  154. package/dist/infrastructure/storage/sqlite-knowledge-graph-repository.js +0 -417
  155. package/dist/infrastructure/storage/sqlite-knowledge-preservation-repository.js +0 -230
  156. package/dist/infrastructure/storage/sqlite-memory-repository.js +0 -229
  157. package/dist/infrastructure/storage/sqlite-pattern-repository.js +0 -249
  158. package/dist/infrastructure/storage/task-helpers.js +0 -197
  159. package/dist/infrastructure/telemetry/telemetry-service.js +0 -167
  160. package/dist/infrastructure/ux/appropriate-friction.js +0 -213
  161. package/dist/infrastructure/ux/bi-directional-learning.js +0 -337
  162. package/dist/infrastructure/ux/capability-boundaries.js +0 -42
  163. package/dist/infrastructure/ux/comprehensive-formatter.js +0 -117
  164. package/dist/infrastructure/ux/contextual-feature-discovery.js +0 -10
  165. package/dist/infrastructure/ux/expectation-management.js +0 -327
  166. package/dist/infrastructure/ux/feature-discovery.js +0 -14
  167. package/dist/infrastructure/ux/feedback-prompt.js +0 -45
  168. package/dist/infrastructure/ux/hitl-validation.js +0 -297
  169. package/dist/infrastructure/ux/progress-indicator.js +0 -116
  170. package/dist/infrastructure/ux/progressive-disclosure.js +0 -236
  171. package/dist/infrastructure/ux/review-checkpoint.js +0 -72
  172. package/dist/infrastructure/ux/staged-feature-intro.js +0 -24
  173. package/dist/infrastructure/ux/stream-markdown.js +0 -151
  174. package/dist/infrastructure/ux/syntax-highlighter.js +0 -91
  175. package/dist/infrastructure/ux/team-standards.js +0 -196
  176. package/dist/infrastructure/ux/transparency.js +0 -71
  177. package/dist/infrastructure/validation/agent-feedback.js +0 -55
  178. package/dist/infrastructure/validation/agent-validation-helper.js +0 -137
  179. package/dist/infrastructure/validation/review-handler.js +0 -40
  180. package/dist/infrastructure/validation/summary-aggregator.js +0 -70
  181. package/dist/infrastructure/validation/summary-extractor.js +0 -45
  182. package/dist/infrastructure/validation/trace-summary.js +0 -52
  183. package/dist/infrastructure/verification/verification-service.js +0 -47
  184. package/dist/infrastructure/xai/attention-visualizer.js +0 -172
  185. package/dist/infrastructure/xai/cot-visualizer.js +0 -283
  186. package/dist/infrastructure/xai/decision-tree-log.js +0 -212
  187. package/dist/infrastructure/xai/interactive-xai.js +0 -260
  188. package/dist/infrastructure/xai/uncertainty-quantifier.js +0 -198
  189. package/dist/intelligent-retrieval.js +0 -272
  190. package/dist/intent/classifier.js +0 -2
  191. package/dist/intent/context.js +0 -2
  192. package/dist/iterative-refinement.js +0 -189
  193. package/dist/learning.js +0 -232
  194. package/dist/log.js +0 -31
  195. package/dist/migrate.js +0 -133
  196. package/dist/parallel-processor.js +0 -534
  197. package/dist/planner.js +0 -198
  198. package/dist/policy.js +0 -26
  199. package/dist/presentation/cli/commands/ask-command.js +0 -314
  200. package/dist/presentation/cli/commands/cost-command.js +0 -191
  201. package/dist/presentation/cli/commands/decision-command.js +0 -207
  202. package/dist/presentation/cli/commands/docs-command.js +0 -25
  203. package/dist/presentation/cli/commands/fix-command.js +0 -53
  204. package/dist/presentation/cli/commands/knowledge-command.js +0 -129
  205. package/dist/presentation/cli/commands/learning-dashboard-command.js +0 -183
  206. package/dist/presentation/cli/commands/models-command.js +0 -194
  207. package/dist/presentation/cli/commands/orchestrate-command.js +0 -207
  208. package/dist/presentation/cli/commands/plan-command.js +0 -246
  209. package/dist/presentation/cli/commands/product-command.js +0 -199
  210. package/dist/presentation/cli/commands/react-command.js +0 -181
  211. package/dist/presentation/cli/commands/review-command.js +0 -154
  212. package/dist/presentation/cli/commands/run-command.js +0 -188
  213. package/dist/presentation/cli/commands/smart-command.js +0 -395
  214. package/dist/presentation/cli/commands/suggest-command.js +0 -138
  215. package/dist/presentation/cli/commands/trace-command.js +0 -129
  216. package/dist/presentation/cli/commands/undo-command.js +0 -150
  217. package/dist/query-optimizer.js +0 -205
  218. package/dist/refactor.js +0 -116
  219. package/dist/review.js +0 -206
  220. package/dist/search.js +0 -163
  221. package/dist/session.js +0 -704
  222. package/dist/task-verification.js +0 -336
  223. package/dist/testgen.js +0 -166
  224. package/dist/token-optimizer.js +0 -277
  225. package/dist/tools/bash.js +0 -213
  226. package/dist/tools/edit.js +0 -235
  227. package/dist/tools/executor.js +0 -153
  228. package/dist/tools/git-tool.js +0 -292
  229. package/dist/tools/parser.js +0 -158
  230. package/dist/tools/registry.js +0 -302
  231. package/dist/tools/search.js +0 -100
  232. package/dist/types.js +0 -2
  233. package/dist/utils/check-api-status.js +0 -100
  234. package/dist/utils/diff-parser.js +0 -162
  235. package/dist/verification/backup.js +0 -259
  236. package/dist/verification/compiler.js +0 -264
  237. package/dist/verification/index.js +0 -273
  238. package/dist/verification/test-runner.js +0 -379
@@ -1,223 +0,0 @@
1
- /**
2
- * Domain Service: DecisionRecorder
3
- * Records architectural and design decisions
4
- *
5
- * Clean Architecture: Domain Layer
6
- *
7
- * Responsibilities:
8
- * - Record architectural decisions
9
- * - Record technology choices
10
- * - Record design pattern choices
11
- * - Extract decisions from planning context
12
- */
13
- import { randomUUID } from 'crypto';
14
- /**
15
- * Decision Recorder Service
16
- * Records decisions with full context and rationale
17
- */
18
- export class DecisionRecorder {
19
- decisionRepository;
20
- constructor(decisionRepository) {
21
- this.decisionRepository = decisionRepository;
22
- }
23
- /**
24
- * Record a decision
25
- */
26
- async recordDecision(request) {
27
- const decision = {
28
- id: randomUUID(),
29
- codebaseId: request.codebaseId,
30
- type: request.type,
31
- title: request.title,
32
- description: request.description,
33
- rationale: request.rationale,
34
- alternatives: request.alternatives,
35
- constraints: request.constraints,
36
- tradeoffs: request.tradeoffs,
37
- consequences: request.consequences,
38
- metadata: {
39
- context: request.context,
40
- relatedDecisions: request.relatedDecisions,
41
- relatedPatterns: request.relatedPatterns,
42
- status: 'accepted',
43
- impact: 'medium',
44
- confidence: 8,
45
- },
46
- createdAt: new Date(),
47
- author: request.author,
48
- };
49
- await this.decisionRepository.store(decision);
50
- return decision;
51
- }
52
- /**
53
- * Extract decision from planning context
54
- * Uses AI to identify decisions made during planning
55
- */
56
- async extractDecisionFromPlanning(planningContext, codebaseId, aiService // IAIService - optional for AI extraction
57
- ) {
58
- // If AI service is available, use it to extract decision
59
- if (aiService) {
60
- return await this.extractDecisionWithAI(planningContext, codebaseId, aiService);
61
- }
62
- // Otherwise, create a basic decision from planning context
63
- return await this.createBasicDecisionFromPlanning(planningContext, codebaseId);
64
- }
65
- /**
66
- * Extract decision using AI
67
- */
68
- async extractDecisionWithAI(planningContext, codebaseId, aiService) {
69
- const prompt = `Analyze this planning context and extract the architectural or design decision made:
70
-
71
- Goal: ${planningContext.goal}
72
- Plan: ${JSON.stringify(planningContext.plan, null, 2)}
73
- ${planningContext.alternatives ? `Alternatives considered: ${planningContext.alternatives.join(', ')}` : ''}
74
- ${planningContext.constraints ? `Constraints: ${planningContext.constraints.join(', ')}` : ''}
75
-
76
- Extract the decision in JSON format:
77
- {
78
- "type": "architectural|technology|design-pattern|convention|process|security|performance|custom",
79
- "title": "Short decision title",
80
- "description": "Full description of decision",
81
- "rationale": "Why this decision was made",
82
- "alternatives": ["alternative1", "alternative2"],
83
- "constraints": ["constraint1", "constraint2"],
84
- "tradeoffs": ["tradeoff1", "tradeoff2"],
85
- "consequences": ["consequence1", "consequence2"]
86
- }
87
-
88
- Only extract if a clear decision was made. Return valid JSON or null.`;
89
- try {
90
- const response = await aiService.chat(prompt, []);
91
- const jsonMatch = response.match(/\{[\s\S]*\}/);
92
- if (jsonMatch) {
93
- const extracted = JSON.parse(jsonMatch[0]);
94
- if (extracted.title && extracted.description) {
95
- const decision = {
96
- id: randomUUID(),
97
- codebaseId,
98
- type: extracted.type || 'architectural',
99
- title: extracted.title,
100
- description: extracted.description,
101
- rationale: extracted.rationale || extracted.description,
102
- alternatives: extracted.alternatives || [],
103
- constraints: extracted.constraints || planningContext.constraints || [],
104
- tradeoffs: extracted.tradeoffs || [],
105
- consequences: extracted.consequences || [],
106
- metadata: {
107
- context: planningContext.goal,
108
- status: 'accepted',
109
- impact: 'medium',
110
- confidence: 7,
111
- },
112
- createdAt: new Date(),
113
- };
114
- await this.decisionRepository.store(decision);
115
- return decision;
116
- }
117
- }
118
- }
119
- catch (error) {
120
- console.warn('AI decision extraction failed:', error);
121
- // Fall back to basic extraction
122
- }
123
- return null;
124
- }
125
- /**
126
- * Create basic decision from planning context (fallback)
127
- */
128
- async createBasicDecisionFromPlanning(planningContext, codebaseId) {
129
- const decision = {
130
- id: randomUUID(),
131
- codebaseId,
132
- type: 'architectural',
133
- title: `Decision: ${planningContext.goal.substring(0, 50)}`,
134
- description: `Decision made during planning: ${planningContext.goal}`,
135
- rationale: 'Decision extracted from planning context',
136
- alternatives: planningContext.alternatives || [],
137
- constraints: planningContext.constraints || [],
138
- metadata: {
139
- context: planningContext.goal,
140
- status: 'accepted',
141
- impact: 'medium',
142
- confidence: 5, // Lower confidence for basic extraction
143
- },
144
- createdAt: new Date(),
145
- };
146
- await this.decisionRepository.store(decision);
147
- return decision;
148
- }
149
- /**
150
- * Record technology choice decision
151
- */
152
- async recordTechnologyChoice(codebaseId, technology, rationale, alternatives, author) {
153
- return await this.recordDecision({
154
- codebaseId,
155
- type: 'technology',
156
- title: `Use ${technology}`,
157
- description: `Decision to use ${technology} for this codebase`,
158
- rationale,
159
- alternatives,
160
- author,
161
- });
162
- }
163
- /**
164
- * Record design pattern choice
165
- */
166
- async recordDesignPattern(codebaseId, patternName, rationale, alternatives, author) {
167
- return await this.recordDecision({
168
- codebaseId,
169
- type: 'design-pattern',
170
- title: `Use ${patternName} Pattern`,
171
- description: `Decision to use ${patternName} design pattern`,
172
- rationale,
173
- alternatives,
174
- author,
175
- });
176
- }
177
- /**
178
- * Record convention decision
179
- */
180
- async recordConvention(codebaseId, convention, rationale, author) {
181
- return await this.recordDecision({
182
- codebaseId,
183
- type: 'convention',
184
- title: `Convention: ${convention}`,
185
- description: `Code convention: ${convention}`,
186
- rationale,
187
- author,
188
- });
189
- }
190
- /**
191
- * Link related decisions
192
- */
193
- async linkDecisions(decisionId1, decisionId2) {
194
- const decision1 = await this.decisionRepository.getById(decisionId1);
195
- const decision2 = await this.decisionRepository.getById(decisionId2);
196
- if (!decision1 || !decision2) {
197
- throw new Error('One or both decisions not found');
198
- }
199
- // Update decision1 to include decision2 in related decisions
200
- if (!decision1.metadata) {
201
- decision1.metadata = {};
202
- }
203
- if (!decision1.metadata.relatedDecisions) {
204
- decision1.metadata.relatedDecisions = [];
205
- }
206
- if (!decision1.metadata.relatedDecisions.includes(decisionId2)) {
207
- decision1.metadata.relatedDecisions.push(decisionId2);
208
- await this.decisionRepository.update(decision1);
209
- }
210
- // Update decision2 to include decision1 in related decisions
211
- if (!decision2.metadata) {
212
- decision2.metadata = {};
213
- }
214
- if (!decision2.metadata.relatedDecisions) {
215
- decision2.metadata.relatedDecisions = [];
216
- }
217
- if (!decision2.metadata.relatedDecisions.includes(decisionId1)) {
218
- decision2.metadata.relatedDecisions.push(decisionId1);
219
- await this.decisionRepository.update(decision2);
220
- }
221
- }
222
- }
223
- //# sourceMappingURL=decision-recorder.js.map
@@ -1,133 +0,0 @@
1
- /**
2
- * Domain Service: DecisionRetriever
3
- * Retrieves and queries decisions
4
- *
5
- * Clean Architecture: Domain Layer
6
- *
7
- * Responsibilities:
8
- * - Query decisions by context
9
- * - Find related decisions
10
- * - Explain why decisions were made
11
- * - Retrieve decisions for planning
12
- */
13
- /**
14
- * Decision Retriever Service
15
- * Provides query and explanation capabilities for decisions
16
- */
17
- export class DecisionRetriever {
18
- decisionRepository;
19
- constructor(decisionRepository) {
20
- this.decisionRepository = decisionRepository;
21
- }
22
- /**
23
- * Query decisions by context
24
- */
25
- async queryByContext(codebaseId, query, limit = 10) {
26
- const decisions = await this.decisionRepository.search(codebaseId, query, limit);
27
- // Generate explanation
28
- const explanation = decisions.length > 0
29
- ? this.generateExplanation(decisions)
30
- : undefined;
31
- return {
32
- decisions,
33
- totalCount: decisions.length,
34
- explanation,
35
- };
36
- }
37
- /**
38
- * Find related decisions
39
- */
40
- async findRelated(decisionId, limit = 10) {
41
- return await this.decisionRepository.findRelated(decisionId, limit);
42
- }
43
- /**
44
- * Get decisions relevant to a planning goal
45
- */
46
- async getRelevantDecisions(codebaseId, goal, limit = 5) {
47
- // Search for decisions relevant to the goal
48
- const decisions = await this.decisionRepository.search(codebaseId, goal, limit);
49
- // Also search by keywords from the goal
50
- const keywords = this.extractKeywords(goal);
51
- const keywordDecisions = [];
52
- for (const keyword of keywords.slice(0, 3)) {
53
- const keywordResults = await this.decisionRepository.search(codebaseId, keyword, 3);
54
- keywordDecisions.push(...keywordResults);
55
- }
56
- // Combine and deduplicate
57
- const allDecisions = [...decisions, ...keywordDecisions];
58
- const uniqueDecisions = new Map();
59
- for (const decision of allDecisions) {
60
- if (decision.id && !uniqueDecisions.has(decision.id)) {
61
- uniqueDecisions.set(decision.id, decision);
62
- }
63
- }
64
- return Array.from(uniqueDecisions.values()).slice(0, limit);
65
- }
66
- /**
67
- * Explain why a decision was made
68
- */
69
- async explainDecision(decisionId) {
70
- const decision = await this.decisionRepository.getById(decisionId);
71
- if (!decision) {
72
- return null;
73
- }
74
- return {
75
- decision,
76
- rationale: decision.rationale,
77
- context: decision.metadata?.context || decision.description,
78
- alternatives: decision.alternatives,
79
- tradeoffs: decision.tradeoffs,
80
- };
81
- }
82
- /**
83
- * Get decisions by type
84
- */
85
- async getByType(codebaseId, type, limit = 20) {
86
- return await this.decisionRepository.findByType(codebaseId, type, limit);
87
- }
88
- /**
89
- * Get recent decisions
90
- */
91
- async getRecent(codebaseId, limit = 10) {
92
- return await this.decisionRepository.getRecent(codebaseId, limit);
93
- }
94
- /**
95
- * Get decisions by status
96
- */
97
- async getByStatus(codebaseId, status, limit = 20) {
98
- return await this.decisionRepository.getByStatus(codebaseId, status, limit);
99
- }
100
- /**
101
- * Get all decisions for a codebase
102
- */
103
- async getAllDecisions(codebaseId) {
104
- return await this.decisionRepository.findByCodebase(codebaseId, 1000);
105
- }
106
- /**
107
- * Generate explanation for a set of decisions
108
- */
109
- generateExplanation(decisions) {
110
- if (decisions.length === 0) {
111
- return '';
112
- }
113
- if (decisions.length === 1) {
114
- const decision = decisions[0];
115
- return `Decision: ${decision.title}. Rationale: ${decision.rationale}`;
116
- }
117
- const types = new Set(decisions.map(d => d.type));
118
- const typeList = Array.from(types).join(', ');
119
- return `${decisions.length} decisions found (types: ${typeList}). These decisions inform the context and constraints for this codebase.`;
120
- }
121
- /**
122
- * Extract keywords from a query string
123
- */
124
- extractKeywords(query) {
125
- // Simple keyword extraction - can be enhanced with NLP
126
- const words = query.toLowerCase().split(/\s+/);
127
- const stopWords = new Set(['the', 'a', 'an', 'and', 'or', 'but', 'in', 'on', 'at', 'to', 'for', 'of', 'with', 'by']);
128
- return words
129
- .filter(word => word.length > 3 && !stopWords.has(word))
130
- .slice(0, 5);
131
- }
132
- }
133
- //# sourceMappingURL=decision-retriever.js.map
@@ -1,22 +0,0 @@
1
- /**
2
- * Environment Mode Manager
3
- * Manages environment mode (LOCAL/ORG/INTERNET)
4
- *
5
- * Phase 1: v0.5.0-alpha.0
6
- */
7
- import { EnvironmentMode } from '../entities/task.js';
8
- /**
9
- * Get current environment mode
10
- */
11
- export function getCurrentEnvironmentMode() {
12
- const envMode = process.env.CODEHERE_ENV_MODE?.toLowerCase();
13
- if (envMode === 'org') {
14
- return EnvironmentMode.ORG;
15
- }
16
- else if (envMode === 'internet') {
17
- return EnvironmentMode.INTERNET;
18
- }
19
- // Default to LOCAL
20
- return EnvironmentMode.LOCAL;
21
- }
22
- //# sourceMappingURL=environment-mode-manager.js.map
@@ -1,69 +0,0 @@
1
- /**
2
- * Domain Service: Graded Memory Activation
3
- * Implements g(t) function for temporal relevance weighting
4
- *
5
- * Based on research: Nodes in middle of episodes get higher activation
6
- * This optimizes strategic learning by focusing on high-utility segments
7
- */
8
- export class GradedMemoryActivation {
9
- /**
10
- * Calculate graded activation for memory based on temporal position
11
- * g(t) function: middle of episode gets higher weight
12
- *
13
- * @param memory - The memory to calculate activation for
14
- * @param episodeStart - Start timestamp of the episode
15
- * @param episodeEnd - End timestamp of the episode
16
- * @returns Activation value between 0 and 1
17
- */
18
- calculateActivation(memory, episodeStart, episodeEnd) {
19
- const episodeDuration = episodeEnd.getTime() - episodeStart.getTime();
20
- if (episodeDuration === 0)
21
- return 1.0;
22
- const memoryTime = memory.timestamp.getTime();
23
- const relativePosition = (memoryTime - episodeStart.getTime()) / episodeDuration;
24
- // g(t) function: bell curve centered at 0.5 (middle of episode)
25
- // Higher activation for memories in the middle, lower for start/end
26
- const center = 0.5;
27
- const spread = 0.3; // Controls how wide the activation zone is
28
- // Gaussian-like function
29
- const distanceFromCenter = Math.abs(relativePosition - center);
30
- const activation = Math.exp(-Math.pow(distanceFromCenter / spread, 2));
31
- return Math.max(0.1, Math.min(1.0, activation)); // Clamp between 0.1 and 1.0
32
- }
33
- /**
34
- * Calculate activation for memory within recent episode window
35
- * Uses last N memories as episode context
36
- */
37
- calculateActivationForRecent(memory, recentMemories, windowSize = 100) {
38
- if (recentMemories.length === 0)
39
- return 1.0;
40
- // Find episode boundaries (first and last memory in window)
41
- const sortedMemories = [...recentMemories].sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
42
- const episodeStart = sortedMemories[0].timestamp;
43
- const episodeEnd = sortedMemories[sortedMemories.length - 1].timestamp;
44
- return this.calculateActivation(memory, episodeStart, episodeEnd);
45
- }
46
- /**
47
- * Apply graded activation to memory retrieval
48
- * Multiplies base relevance score by activation weight
49
- */
50
- applyGradedActivation(memories, episodeStart, episodeEnd) {
51
- if (!episodeStart || !episodeEnd) {
52
- // Use recent memories as episode context
53
- const sorted = [...memories].sort((a, b) => a.memory.timestamp.getTime() - b.memory.timestamp.getTime());
54
- if (sorted.length > 0) {
55
- episodeStart = sorted[0].memory.timestamp;
56
- episodeEnd = sorted[sorted.length - 1].memory.timestamp;
57
- }
58
- else {
59
- return memories.map(m => ({ memory: m.memory, finalScore: m.baseScore }));
60
- }
61
- }
62
- return memories.map(({ memory, baseScore }) => {
63
- const activation = this.calculateActivation(memory, episodeStart, episodeEnd);
64
- const finalScore = baseScore * activation;
65
- return { memory, finalScore };
66
- });
67
- }
68
- }
69
- //# sourceMappingURL=graded-memory-activation.js.map
@@ -1,132 +0,0 @@
1
- /**
2
- * Domain Service: Knowledge Access
3
- * Provides access to preserved knowledge
4
- *
5
- * Clean Architecture: Domain Layer
6
- *
7
- * Responsibilities:
8
- * - Query preserved knowledge
9
- * - Provide knowledge summaries
10
- * - Link knowledge to patterns and decisions
11
- */
12
- /**
13
- * Knowledge Access Service
14
- * Provides query and summary capabilities for preserved knowledge
15
- */
16
- export class KnowledgeAccess {
17
- knowledgeRepository;
18
- patternRepository;
19
- decisionRepository;
20
- constructor(knowledgeRepository, patternRepository, decisionRepository) {
21
- this.knowledgeRepository = knowledgeRepository;
22
- this.patternRepository = patternRepository;
23
- this.decisionRepository = decisionRepository;
24
- }
25
- /**
26
- * Query knowledge by context
27
- */
28
- async query(codebaseId, query, limit = 10) {
29
- return await this.knowledgeRepository.search(codebaseId, query, limit);
30
- }
31
- /**
32
- * Get knowledge by type
33
- */
34
- async getByType(codebaseId, type, limit = 20) {
35
- return await this.knowledgeRepository.findByType(codebaseId, type, limit);
36
- }
37
- /**
38
- * Get knowledge by tags
39
- */
40
- async getByTags(codebaseId, tags, limit = 20) {
41
- return await this.knowledgeRepository.findByTags(codebaseId, tags, limit);
42
- }
43
- /**
44
- * Get knowledge summary for a codebase
45
- */
46
- async getSummary(codebaseId) {
47
- const allKnowledge = await this.knowledgeRepository.findByCodebase(codebaseId, 1000);
48
- // Count by type
49
- const byType = {};
50
- for (const knowledge of allKnowledge) {
51
- byType[knowledge.type] = (byType[knowledge.type] || 0) + 1;
52
- }
53
- // Get most accessed
54
- const mostAccessed = await this.knowledgeRepository.getMostAccessed(codebaseId, 5);
55
- // Get recent
56
- const recent = await this.knowledgeRepository.getRecent(codebaseId, 5);
57
- // Generate summary
58
- const summary = this.generateSummary(allKnowledge, byType);
59
- return {
60
- totalKnowledge: allKnowledge.length,
61
- byType,
62
- mostAccessed,
63
- recent,
64
- summary,
65
- };
66
- }
67
- /**
68
- * Get relevant knowledge for planning/query
69
- */
70
- async getRelevantKnowledge(codebaseId, context, limit = 5) {
71
- // Search for relevant knowledge
72
- const searchResults = await this.knowledgeRepository.search(codebaseId, context, limit);
73
- // Also get by type if context suggests specific type
74
- const typeMatches = this.inferKnowledgeType(context);
75
- if (typeMatches.length > 0) {
76
- const typeResults = [];
77
- for (const type of typeMatches.slice(0, 2)) {
78
- const results = await this.knowledgeRepository.findByType(codebaseId, type, 3);
79
- typeResults.push(...results);
80
- }
81
- // Combine and deduplicate
82
- const allResults = [...searchResults, ...typeResults];
83
- const unique = new Map();
84
- for (const knowledge of allResults) {
85
- if (knowledge.id && !unique.has(knowledge.id)) {
86
- unique.set(knowledge.id, knowledge);
87
- }
88
- }
89
- return Array.from(unique.values()).slice(0, limit);
90
- }
91
- return searchResults;
92
- }
93
- /**
94
- * Generate summary text
95
- */
96
- generateSummary(knowledge, byType) {
97
- if (knowledge.length === 0) {
98
- return 'No knowledge preserved yet.';
99
- }
100
- const typeSummary = Object.entries(byType)
101
- .map(([type, count]) => `${count} ${type}`)
102
- .join(', ');
103
- return `Preserved ${knowledge.length} knowledge items: ${typeSummary}.`;
104
- }
105
- /**
106
- * Infer knowledge type from context query
107
- */
108
- inferKnowledgeType(context) {
109
- const contextLower = context.toLowerCase();
110
- const types = [];
111
- if (/architecture|structure|design|system/.test(contextLower)) {
112
- types.push('architectural');
113
- }
114
- if (/domain|business|logic|concept/.test(contextLower)) {
115
- types.push('domain-knowledge');
116
- }
117
- if (/pattern|convention|style/.test(contextLower)) {
118
- types.push('convention');
119
- }
120
- if (/documentation|comment|doc/.test(contextLower)) {
121
- types.push('documentation');
122
- }
123
- if (/best.practice|guideline|recommendation/.test(contextLower)) {
124
- types.push('best-practice');
125
- }
126
- if (/gotcha|warning|pitfall|trap/.test(contextLower)) {
127
- types.push('gotcha');
128
- }
129
- return types;
130
- }
131
- }
132
- //# sourceMappingURL=knowledge-access.js.map