onbuzz 4.9.13 → 4.10.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.
Files changed (451) hide show
  1. package/node_modules/glob/README.md +31 -5
  2. package/node_modules/glob/dist/commonjs/glob.d.ts +8 -0
  3. package/node_modules/glob/dist/commonjs/glob.d.ts.map +1 -1
  4. package/node_modules/glob/dist/commonjs/glob.js +2 -1
  5. package/node_modules/glob/dist/commonjs/glob.js.map +1 -1
  6. package/node_modules/glob/dist/commonjs/index.min.js +3 -3
  7. package/node_modules/glob/dist/commonjs/index.min.js.map +4 -4
  8. package/node_modules/glob/dist/commonjs/pattern.d.ts +3 -0
  9. package/node_modules/glob/dist/commonjs/pattern.d.ts.map +1 -1
  10. package/node_modules/glob/dist/commonjs/pattern.js +4 -0
  11. package/node_modules/glob/dist/commonjs/pattern.js.map +1 -1
  12. package/node_modules/glob/dist/esm/glob.d.ts +8 -0
  13. package/node_modules/glob/dist/esm/glob.d.ts.map +1 -1
  14. package/node_modules/glob/dist/esm/glob.js +2 -1
  15. package/node_modules/glob/dist/esm/glob.js.map +1 -1
  16. package/node_modules/glob/dist/esm/index.min.js +3 -3
  17. package/node_modules/glob/dist/esm/index.min.js.map +4 -4
  18. package/node_modules/glob/dist/esm/pattern.d.ts +3 -0
  19. package/node_modules/glob/dist/esm/pattern.d.ts.map +1 -1
  20. package/node_modules/glob/dist/esm/pattern.js +4 -0
  21. package/node_modules/glob/dist/esm/pattern.js.map +1 -1
  22. package/node_modules/{@isaacs → glob/node_modules}/balanced-match/README.md +7 -10
  23. package/node_modules/{@isaacs → glob/node_modules}/balanced-match/package.json +7 -18
  24. package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/README.md +3 -6
  25. package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.js +6 -4
  26. package/node_modules/glob/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -0
  27. package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.js +6 -4
  28. package/node_modules/glob/node_modules/brace-expansion/dist/esm/index.js.map +1 -0
  29. package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/package.json +11 -7
  30. package/node_modules/glob/node_modules/minimatch/README.md +76 -1
  31. package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts +1 -1
  32. package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.d.ts.map +1 -1
  33. package/node_modules/glob/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js.map +1 -1
  34. package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.d.ts +4 -2
  35. package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.d.ts.map +1 -1
  36. package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.js +309 -55
  37. package/node_modules/glob/node_modules/minimatch/dist/commonjs/ast.js.map +1 -1
  38. package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.d.ts.map +1 -1
  39. package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.js +2 -4
  40. package/node_modules/glob/node_modules/minimatch/dist/commonjs/brace-expressions.js.map +1 -1
  41. package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.d.ts +1 -1
  42. package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.d.ts.map +1 -1
  43. package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.js +4 -4
  44. package/node_modules/glob/node_modules/minimatch/dist/commonjs/escape.js.map +1 -1
  45. package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.d.ts +81 -1
  46. package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.d.ts.map +1 -1
  47. package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js +232 -134
  48. package/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js.map +1 -1
  49. package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.d.ts +1 -1
  50. package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.d.ts.map +1 -1
  51. package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.js +8 -8
  52. package/node_modules/glob/node_modules/minimatch/dist/commonjs/unescape.js.map +1 -1
  53. package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts +1 -1
  54. package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.d.ts.map +1 -1
  55. package/node_modules/glob/node_modules/minimatch/dist/esm/assert-valid-pattern.js.map +1 -1
  56. package/node_modules/glob/node_modules/minimatch/dist/esm/ast.d.ts +4 -2
  57. package/node_modules/glob/node_modules/minimatch/dist/esm/ast.d.ts.map +1 -1
  58. package/node_modules/glob/node_modules/minimatch/dist/esm/ast.js +309 -55
  59. package/node_modules/glob/node_modules/minimatch/dist/esm/ast.js.map +1 -1
  60. package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.d.ts.map +1 -1
  61. package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.js +2 -4
  62. package/node_modules/glob/node_modules/minimatch/dist/esm/brace-expressions.js.map +1 -1
  63. package/node_modules/glob/node_modules/minimatch/dist/esm/escape.d.ts +1 -1
  64. package/node_modules/glob/node_modules/minimatch/dist/esm/escape.d.ts.map +1 -1
  65. package/node_modules/glob/node_modules/minimatch/dist/esm/escape.js +4 -4
  66. package/node_modules/glob/node_modules/minimatch/dist/esm/escape.js.map +1 -1
  67. package/node_modules/glob/node_modules/minimatch/dist/esm/index.d.ts +81 -1
  68. package/node_modules/glob/node_modules/minimatch/dist/esm/index.d.ts.map +1 -1
  69. package/node_modules/glob/node_modules/minimatch/dist/esm/index.js +232 -134
  70. package/node_modules/glob/node_modules/minimatch/dist/esm/index.js.map +1 -1
  71. package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.d.ts +1 -1
  72. package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.d.ts.map +1 -1
  73. package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.js +8 -8
  74. package/node_modules/glob/node_modules/minimatch/dist/esm/unescape.js.map +1 -1
  75. package/node_modules/glob/node_modules/minimatch/package.json +17 -11
  76. package/node_modules/glob/package.json +10 -13
  77. package/node_modules/minipass/LICENSE.md +55 -0
  78. package/node_modules/minipass/dist/commonjs/index.d.ts +12 -16
  79. package/node_modules/minipass/dist/commonjs/index.d.ts.map +1 -1
  80. package/node_modules/minipass/dist/commonjs/index.js +13 -3
  81. package/node_modules/minipass/dist/commonjs/index.js.map +1 -1
  82. package/node_modules/minipass/dist/esm/index.d.ts +12 -16
  83. package/node_modules/minipass/dist/esm/index.d.ts.map +1 -1
  84. package/node_modules/minipass/dist/esm/index.js +3 -1
  85. package/node_modules/minipass/dist/esm/index.js.map +1 -1
  86. package/node_modules/minipass/package.json +9 -14
  87. package/node_modules/path-scurry/node_modules/lru-cache/README.md +96 -10
  88. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.d.ts.map +1 -0
  89. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel-browser.js.map +1 -0
  90. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.d.ts +5 -0
  91. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
  92. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.d.ts +1400 -0
  93. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.d.ts.map +1 -0
  94. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
  95. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js.map +1 -0
  96. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
  97. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js.map +7 -0
  98. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.d.ts +12 -0
  99. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.d.ts.map +1 -0
  100. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
  101. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js.map +1 -0
  102. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.cjs.map +1 -0
  103. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
  104. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.d.ts +5 -0
  105. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
  106. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.d.ts +109 -32
  107. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.d.ts.map +1 -1
  108. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +334 -197
  109. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js.map +1 -1
  110. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
  111. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js.map +4 -4
  112. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.d.ts.map +1 -0
  113. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel-node.js.map +1 -0
  114. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.d.ts +5 -0
  115. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
  116. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.d.ts +1400 -0
  117. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.d.ts.map +1 -0
  118. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
  119. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js.map +1 -0
  120. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
  121. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js.map +7 -0
  122. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.d.ts +12 -0
  123. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.d.ts.map +1 -0
  124. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
  125. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js.map +1 -0
  126. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.d.ts +12 -0
  127. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.d.ts.map +1 -0
  128. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
  129. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js.map +1 -0
  130. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel-browser.d.ts.map +1 -0
  131. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel-browser.js.map +1 -0
  132. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.d.ts +5 -0
  133. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  134. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.d.ts +1400 -0
  135. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.d.ts.map +1 -0
  136. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
  137. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js.map +1 -0
  138. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  139. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js.map +7 -0
  140. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.d.ts +12 -0
  141. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.d.ts.map +1 -0
  142. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
  143. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js.map +1 -0
  144. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
  145. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.mjs.map +1 -0
  146. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.d.ts +5 -0
  147. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  148. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.d.ts +109 -32
  149. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.d.ts.map +1 -1
  150. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +333 -196
  151. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js.map +1 -1
  152. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +1 -1
  153. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js.map +4 -4
  154. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel-node.d.ts.map +1 -0
  155. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel-node.js.map +1 -0
  156. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.d.ts +5 -0
  157. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
  158. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.d.ts +1400 -0
  159. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.d.ts.map +1 -0
  160. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
  161. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js.map +1 -0
  162. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  163. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js.map +7 -0
  164. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.d.ts +12 -0
  165. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.d.ts.map +1 -0
  166. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
  167. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js.map +1 -0
  168. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.d.ts +12 -0
  169. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.d.ts.map +1 -0
  170. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
  171. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js.map +1 -0
  172. package/node_modules/path-scurry/node_modules/lru-cache/package.json +71 -18
  173. package/node_modules/path-scurry/package.json +8 -24
  174. package/package.json +1 -1
  175. package/scripts/debug-balance-probe.mjs +35 -35
  176. package/scripts/push-image.sh +43 -43
  177. package/scripts/setup-acr.sh +65 -65
  178. package/scripts/verify-optional-deps.js +96 -1
  179. package/src/__tests__/composioCliFlags.test.js +239 -239
  180. package/src/analyzers/CSSAnalyzer.js +298 -297
  181. package/src/analyzers/ConfigValidator.js +691 -690
  182. package/src/analyzers/ESLintAnalyzer.js +320 -320
  183. package/src/analyzers/JavaScriptAnalyzer.js +260 -261
  184. package/src/analyzers/PrettierFormatter.js +246 -247
  185. package/src/analyzers/PythonAnalyzer.js +283 -283
  186. package/src/analyzers/SecurityAnalyzer.js +729 -729
  187. package/src/analyzers/SparrowAnalyzer.js +341 -341
  188. package/src/analyzers/TypeScriptAnalyzer.js +247 -247
  189. package/src/analyzers/__tests__/CSSAnalyzer.test.js +41 -41
  190. package/src/analyzers/__tests__/ConfigValidator.test.js +362 -362
  191. package/src/analyzers/__tests__/JavaScriptAnalyzer.test.js +40 -40
  192. package/src/analyzers/__tests__/PythonAnalyzer.test.js +205 -208
  193. package/src/analyzers/__tests__/SecurityAnalyzer.test.js +303 -303
  194. package/src/analyzers/__tests__/TypeScriptAnalyzer.test.js +187 -187
  195. package/src/analyzers/codeCloneDetector/analyzer.js +344 -344
  196. package/src/analyzers/codeCloneDetector/detector.js +250 -250
  197. package/src/analyzers/codeCloneDetector/index.js +194 -192
  198. package/src/analyzers/codeCloneDetector/parser.js +199 -199
  199. package/src/core/__tests__/agentPool.test.js +866 -866
  200. package/src/core/__tests__/agentPoolAutoResume.test.js +209 -209
  201. package/src/core/__tests__/agentPoolWakeOnMessage.test.js +315 -315
  202. package/src/core/__tests__/agentScheduler.emptyResponseChatStall.test.js +213 -213
  203. package/src/core/__tests__/agentScheduler.errorCategorisation.test.js +246 -246
  204. package/src/core/__tests__/agentScheduler.firstChunkTimeout.test.js +138 -138
  205. package/src/core/__tests__/agentScheduler.modeTransitions.test.js +233 -233
  206. package/src/core/__tests__/agentScheduler.nativePromptPick.test.js +319 -319
  207. package/src/core/__tests__/agentScheduler.taskLifecycleInstruction.test.js +78 -78
  208. package/src/core/__tests__/agentScheduler.visualizer.test.js +258 -258
  209. package/src/core/__tests__/flowCheckpointStore.test.js +140 -140
  210. package/src/core/__tests__/flowEndToEnd.test.js +565 -565
  211. package/src/core/__tests__/flowFieldMapping.test.js +188 -189
  212. package/src/core/__tests__/flowLintClientMirror.test.js +96 -98
  213. package/src/core/__tests__/flowSavePayload.test.js +170 -169
  214. package/src/core/__tests__/flowTemplates.test.js +311 -311
  215. package/src/core/__tests__/flowVersionStore.test.js +123 -123
  216. package/src/core/__tests__/messageProcessor.test.js +669 -669
  217. package/src/core/__tests__/stateManager.test.js +0 -1
  218. package/src/core/agentPool.js +2474 -2475
  219. package/src/core/agentScheduler.js +1 -4
  220. package/src/core/contextManager.js +708 -708
  221. package/src/core/flowExecutor.js +1510 -1510
  222. package/src/core/flowFieldMapping.js +136 -138
  223. package/src/core/messageProcessor.js +953 -954
  224. package/src/core/orchestrator.js +593 -595
  225. package/src/core/stateManager.js +1765 -1752
  226. package/src/index.js +1221 -1221
  227. package/src/interfaces/__tests__/archivedAgentDelete.test.js +207 -207
  228. package/src/interfaces/__tests__/bulkAgentRoute.test.js +361 -361
  229. package/src/interfaces/__tests__/imageServing.test.js +228 -228
  230. package/src/interfaces/__tests__/remoteSessionAuth.test.js +308 -308
  231. package/src/interfaces/__tests__/videoJobsRoutes.test.js +178 -179
  232. package/src/interfaces/__tests__/webServer.marketplace.test.js +629 -629
  233. package/src/interfaces/schedulerRoutes.js +50 -50
  234. package/src/interfaces/terminal/__tests__/smoke/connection.test.js +341 -350
  235. package/src/interfaces/terminal/__tests__/smoke/enhancements.test.js +156 -156
  236. package/src/interfaces/terminal/__tests__/smoke/imports.test.js +325 -330
  237. package/src/interfaces/terminal/__tests__/smoke/tools.test.js +385 -388
  238. package/src/interfaces/terminal/api/session.js +265 -266
  239. package/src/interfaces/terminal/api/websocket.js +496 -497
  240. package/src/interfaces/terminal/components/AgentCreator.js +691 -705
  241. package/src/interfaces/terminal/components/AgentEditor.js +676 -678
  242. package/src/interfaces/terminal/components/AgentSwitcher.js +331 -330
  243. package/src/interfaces/terminal/components/ErrorPanel.js +263 -264
  244. package/src/interfaces/terminal/components/Header.js +28 -28
  245. package/src/interfaces/terminal/components/Layout.js +598 -603
  246. package/src/interfaces/terminal/components/MessageList.js +280 -281
  247. package/src/interfaces/terminal/components/SettingsPanel.js +410 -415
  248. package/src/interfaces/terminal/components/StatusBar.js +2 -0
  249. package/src/interfaces/terminal/index.js +168 -168
  250. package/src/interfaces/terminal/state/useAgentControl.js +496 -496
  251. package/src/interfaces/terminal/state/useAgents.js +537 -537
  252. package/src/interfaces/terminal/state/useMessages.js +629 -630
  253. package/src/interfaces/terminal/state/useTools.js +554 -554
  254. package/src/interfaces/terminal/utils/debugLogger.js +44 -44
  255. package/src/interfaces/terminal/utils/settingsStorage.js +232 -232
  256. package/src/interfaces/webServer.js +7578 -7579
  257. package/src/interfaces/webServer.js.bak +7046 -7046
  258. package/src/modules/fileExplorer/__tests__/zipDownload.test.js +237 -237
  259. package/src/modules/fileExplorer/controller.js +470 -469
  260. package/src/modules/fileExplorer/routes.js +285 -286
  261. package/src/modules/widget/__tests__/isDisabled.test.js +41 -41
  262. package/src/modules/widget/__tests__/routes.test.js +677 -678
  263. package/src/modules/widget/__tests__/runtime.test.js +401 -401
  264. package/src/modules/widget/__tests__/versioning.test.js +309 -309
  265. package/src/modules/widget/__tests__/webComponentRuntime.test.js +565 -565
  266. package/src/modules/widget/__tests__/widgetTool.test.js +316 -316
  267. package/src/modules/widget/routes.js +435 -435
  268. package/src/modules/widget/runtime/bundle.js +640 -640
  269. package/src/modules/widget/runtime/webComponentBundle.js +470 -470
  270. package/src/modules/widget/schema.js +182 -181
  271. package/src/modules/widget/widgetTool.js +1389 -1389
  272. package/src/services/__tests__/agentActivityService.test.js +401 -402
  273. package/src/services/__tests__/benchmarkService.test.js +184 -184
  274. package/src/services/__tests__/contextInjectionService.test.js +246 -246
  275. package/src/services/__tests__/conversationQuery.test.js +721 -723
  276. package/src/services/__tests__/credentialVault.test.js +469 -469
  277. package/src/services/__tests__/discordService.integration.test.js +638 -639
  278. package/src/services/__tests__/flowContextService.test.js +590 -590
  279. package/src/services/__tests__/memoryService.test.js +1 -1
  280. package/src/services/__tests__/messageSource.test.js +380 -380
  281. package/src/services/__tests__/modelRouterNaming.test.js +111 -111
  282. package/src/services/__tests__/projectDetector.test.js +34 -34
  283. package/src/services/__tests__/promptService.test.js +242 -242
  284. package/src/services/__tests__/telegramService.test.js +941 -941
  285. package/src/services/__tests__/tokenCountingService.test.js +48 -48
  286. package/src/services/agentActivityService.js +419 -420
  287. package/src/services/aiService.js +2997 -3001
  288. package/src/services/apiKeyManager.js +359 -359
  289. package/src/services/benchmarkService.js +196 -196
  290. package/src/services/codebaseKnowledgeService.js +2 -2
  291. package/src/services/composioService.js +738 -738
  292. package/src/services/conversationCompactionService.js +1258 -1257
  293. package/src/services/credentialVault.js +685 -685
  294. package/src/services/discordService.js +792 -793
  295. package/src/services/embeddings/__tests__/azureCustomProvider.test.js +232 -232
  296. package/src/services/embeddings/__tests__/embeddingService.test.js +417 -417
  297. package/src/services/embeddings/__tests__/localProvider.test.js +263 -263
  298. package/src/services/embeddings/autoRecall.js +218 -219
  299. package/src/services/embeddings/indexers/__tests__/agentIndexer.test.js +232 -232
  300. package/src/services/embeddings/indexers/__tests__/memoryIndexer.test.js +418 -418
  301. package/src/services/embeddings/indexers/__tests__/reminisceIndexer.test.js +356 -357
  302. package/src/services/embeddings/indexers/__tests__/skillsIndexer.test.js +145 -145
  303. package/src/services/embeddings/indexers/__tests__/taskIndexer.test.js +146 -146
  304. package/src/services/embeddings/indexers/composioIndexer.js +279 -279
  305. package/src/services/embeddings/providerInterface.js +206 -206
  306. package/src/services/embeddings/providers/localProvider.js +11 -7
  307. package/src/services/embeddings/providers/openaiProvider.js +101 -101
  308. package/src/services/embeddings/vectorStore/inMemoryJsonStore.js +356 -356
  309. package/src/services/errorHandler.js +809 -809
  310. package/src/services/flowContextService.js +586 -586
  311. package/src/services/grounding/MockAdapter.js +125 -125
  312. package/src/services/modelRouterService.js +26 -31
  313. package/src/services/modelsService.js +322 -322
  314. package/src/services/ollamaService.js +452 -452
  315. package/src/services/projectDetector.js +403 -404
  316. package/src/services/promptService.js +418 -418
  317. package/src/services/qualityInspector.js +795 -795
  318. package/src/services/scheduleService.js +726 -726
  319. package/src/services/serviceRegistry.js +386 -386
  320. package/src/services/telegrafBot.js +174 -174
  321. package/src/services/telegramService.js +1972 -1972
  322. package/src/services/visualEditorBridge.js +1033 -1033
  323. package/src/services/visualEditorServer.js +1769 -1774
  324. package/src/services/whatsappService.js +667 -668
  325. package/src/tools/__tests__/agentCommunicationTool.findAgent.test.js +226 -226
  326. package/src/tools/__tests__/agentCommunicationTool.test.js +3 -3
  327. package/src/tools/__tests__/agentDelayTool.test.js +342 -342
  328. package/src/tools/__tests__/baseTool.test.js +3 -3
  329. package/src/tools/__tests__/codeMapTool.test.js +915 -915
  330. package/src/tools/__tests__/fileContentReplaceTool.test.js +309 -309
  331. package/src/tools/__tests__/fileTreeTool.test.js +274 -274
  332. package/src/tools/__tests__/filesystemTool.test.js +815 -815
  333. package/src/tools/__tests__/foundryWebSearchTool.test.js +252 -252
  334. package/src/tools/__tests__/imageTool.validator.test.js +194 -194
  335. package/src/tools/__tests__/jobDoneTool.test.js +580 -581
  336. package/src/tools/__tests__/memoryTool.forgetStale.test.js +272 -272
  337. package/src/tools/__tests__/memoryTool.reminisce.test.js +2 -2
  338. package/src/tools/__tests__/memoryTool.reminisceSemanticSearch.test.js +301 -301
  339. package/src/tools/__tests__/memoryTool.semanticSearch.test.js +405 -405
  340. package/src/tools/__tests__/memoryTool.teamPool.test.js +293 -293
  341. package/src/tools/__tests__/memoryTool.test.js +1 -1
  342. package/src/tools/__tests__/seekTool.test.js +282 -282
  343. package/src/tools/__tests__/skillsTool.search.test.js +164 -164
  344. package/src/tools/__tests__/skillsTool.test.js +226 -226
  345. package/src/tools/__tests__/staticAnalysisTool.test.js +509 -509
  346. package/src/tools/__tests__/taskManagerTool.discipline.test.js +137 -137
  347. package/src/tools/__tests__/taskManagerTool.search.test.js +143 -143
  348. package/src/tools/__tests__/taskManagerTool.test.js +866 -866
  349. package/src/tools/__tests__/terminalTool.test.js +448 -448
  350. package/src/tools/__tests__/toolShapeForgiveness.test.js +259 -260
  351. package/src/tools/__tests__/userPromptTool.test.js +297 -297
  352. package/src/tools/__tests__/videoTool.jobs.test.js +147 -147
  353. package/src/tools/__tests__/webTool.e2e.test.js +609 -603
  354. package/src/tools/__tests__/webTool.unit.test.js +195 -195
  355. package/src/tools/__tests__/webTool.visionModel.test.js +75 -75
  356. package/src/tools/agentCommunicationTool.js +8 -10
  357. package/src/tools/agentDelayTool.js +496 -497
  358. package/src/tools/asyncToolManager.js +602 -603
  359. package/src/tools/baseTool.js +12 -11
  360. package/src/tools/cloneDetectionTool.js +576 -581
  361. package/src/tools/codeMapTool.js +0 -6
  362. package/src/tools/composioTool.js +617 -617
  363. package/src/tools/dependencyResolverTool.js +1211 -1212
  364. package/src/tools/desktop/DesktopTool.js +629 -638
  365. package/src/tools/desktop/__tests__/DesktopTool.e2e.test.js +306 -306
  366. package/src/tools/desktop/__tests__/DesktopTool.test.js +507 -507
  367. package/src/tools/desktop/__tests__/osController.test.js +364 -364
  368. package/src/tools/desktop/osController.js +491 -491
  369. package/src/tools/docxTool.js +623 -623
  370. package/src/tools/excelTool.js +636 -636
  371. package/src/tools/fileContentReplaceTool.js +5 -7
  372. package/src/tools/fileSystemTool.js +12 -19
  373. package/src/tools/fileTreeTool.js +840 -840
  374. package/src/tools/foundryWebSearchTool.js +273 -273
  375. package/src/tools/helpTool.js +198 -198
  376. package/src/tools/imageTool.js +1397 -1397
  377. package/src/tools/importAnalyzerTool.js +1056 -1056
  378. package/src/tools/jobDoneTool.js +495 -495
  379. package/src/tools/memoryTool.js +1 -1
  380. package/src/tools/office/pres/__tests__/presSystem.test.js +365 -365
  381. package/src/tools/office/pres/archetypes/agenda.js +61 -61
  382. package/src/tools/office/pres/archetypes/bentoGrid.js +218 -219
  383. package/src/tools/office/pres/archetypes/bigStat.js +140 -142
  384. package/src/tools/office/pres/archetypes/closing.js +70 -70
  385. package/src/tools/office/pres/archetypes/hero.js +70 -70
  386. package/src/tools/office/pres/archetypes/productHero.js +93 -94
  387. package/src/tools/office/pres/archetypes/table.js +73 -74
  388. package/src/tools/office/pres/backgrounds/orb.js +66 -66
  389. package/src/tools/office/pres/components.js +422 -423
  390. package/src/tools/officeTool.js +441 -441
  391. package/src/tools/pdfTool.js +625 -627
  392. package/src/tools/platformControlTool.js +1081 -1081
  393. package/src/tools/seekTool.js +917 -918
  394. package/src/tools/skillsTool.js +1 -1
  395. package/src/tools/staticAnalysisTool.js +2143 -2146
  396. package/src/tools/taskManagerTool.js +3324 -3324
  397. package/src/tools/terminalTool.js +2615 -2618
  398. package/src/tools/videoTool.js +1303 -1303
  399. package/src/tools/visionTool.js +508 -508
  400. package/src/tools/visualEditorTool.js +1289 -1290
  401. package/src/tools/webTool.js +3368 -3368
  402. package/src/tools/whatsappTool.js +464 -464
  403. package/src/types/__tests__/agent.test.js +499 -499
  404. package/src/types/__tests__/contextReference.test.js +606 -606
  405. package/src/types/__tests__/conversation.test.js +555 -555
  406. package/src/types/__tests__/toolCommand.test.js +584 -584
  407. package/src/types/contextReference.js +974 -971
  408. package/src/types/conversation.js +729 -729
  409. package/src/types/toolCommand.js +746 -746
  410. package/src/utilities/__tests__/attachmentValidator.test.js +80 -80
  411. package/src/utilities/__tests__/auditReport.test.js +328 -328
  412. package/src/utilities/__tests__/directoryAccessManager.test.js +388 -388
  413. package/src/utilities/__tests__/jsonRepair.test.js +103 -104
  414. package/src/utilities/__tests__/modeTransitionReasons.test.js +105 -105
  415. package/src/utilities/__tests__/platformUtils.test.js +80 -87
  416. package/src/utilities/__tests__/structuredFileValidator.test.js +261 -263
  417. package/src/utilities/__tests__/toolConstants.test.js +92 -94
  418. package/src/utilities/__tests__/useIsTouchDevice.detect.test.js +114 -114
  419. package/src/utilities/__tests__/webUiUtilSync.test.js +117 -117
  420. package/src/utilities/attachmentValidator.js +284 -288
  421. package/src/utilities/authCache.js.backup-1779570472481 +121 -121
  422. package/src/utilities/browserStealth.js +631 -630
  423. package/src/utilities/configManager.js +616 -617
  424. package/src/utilities/directoryAccessManager.js +564 -565
  425. package/src/utilities/fileProcessor.js +308 -307
  426. package/src/utilities/humanBehavior.js +454 -453
  427. package/src/utilities/logger.js +479 -479
  428. package/src/utilities/structuredFileValidator.js +696 -699
  429. package/src/utilities/tagParser.js +5 -10
  430. package/src/utilities/userDataDir.js +308 -308
  431. package/node_modules/@isaacs/brace-expansion/dist/commonjs/index.js.map +0 -1
  432. package/node_modules/@isaacs/brace-expansion/dist/esm/index.js.map +0 -1
  433. package/node_modules/minipass/LICENSE +0 -15
  434. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/LICENSE.md +0 -0
  435. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.d.ts +0 -0
  436. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.d.ts.map +0 -0
  437. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.js +0 -0
  438. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/index.js.map +0 -0
  439. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/commonjs/package.json +0 -0
  440. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.d.ts +0 -0
  441. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.d.ts.map +0 -0
  442. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.js +0 -0
  443. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/index.js.map +0 -0
  444. /package/node_modules/{@isaacs → glob/node_modules}/balanced-match/dist/esm/package.json +0 -0
  445. /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/LICENSE +0 -0
  446. /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.d.ts +0 -0
  447. /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/index.d.ts.map +0 -0
  448. /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/commonjs/package.json +0 -0
  449. /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.d.ts +0 -0
  450. /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/index.d.ts.map +0 -0
  451. /package/node_modules/{@isaacs → glob/node_modules}/brace-expansion/dist/esm/package.json +0 -0
@@ -1,972 +1,975 @@
1
- /**
2
- * Context Reference Data Model - Type definitions and validation for context references
3
- *
4
- * Purpose:
5
- * - Define the structure and properties of context references
6
- * - Provide validation functions for context reference data
7
- * - Handle context reference resolution and management
8
- */
9
-
10
- import { CONTEXT_REFERENCE_TYPES, FILE_EXTENSIONS, CONTEXT_ICONS, FILE_ICONS } from '../utilities/constants.js';
11
-
12
- /**
13
- * Context Reference data model
14
- * @typedef {Object} ContextReference
15
- * @property {string} id - Unique reference identifier
16
- * @property {string} type - Reference type (file, component, selection, directory)
17
- * @property {string} path - Path or identifier of referenced item
18
- * @property {string} name - Human-readable name
19
- * @property {string} [content] - Referenced content (if loaded)
20
- * @property {ReferenceMetadata} metadata - Reference metadata
21
- * @property {ReferenceScope} scope - Reference scope and boundaries
22
- * @property {string} createdAt - ISO timestamp of creation
23
- * @property {string} [lastAccessed] - ISO timestamp of last access
24
- * @property {string} [lastModified] - ISO timestamp of last modification
25
- * @property {boolean} isValid - Whether reference is still valid
26
- * @property {string} [invalidReason] - Reason for invalidity
27
- * @property {number} accessCount - Number of times accessed
28
- * @property {Object} tags - Reference tags and labels
29
- */
30
-
31
- /**
32
- * Reference metadata
33
- * @typedef {Object} ReferenceMetadata
34
- * @property {string} [language] - Programming language (for code files)
35
- * @property {string} [encoding] - File encoding
36
- * @property {number} [size] - Content size in bytes
37
- * @property {string} [mimeType] - MIME type
38
- * @property {string} [checksum] - Content checksum for integrity
39
- * @property {string[]} [keywords] - Extracted keywords
40
- * @property {string} [description] - Reference description
41
- * @property {Object} [customFields] - Custom metadata fields
42
- * @property {string} [icon] - Display icon identifier
43
- * @property {Object} [permissions] - Access permissions
44
- */
45
-
46
- /**
47
- * Reference scope and boundaries
48
- * @typedef {Object} ReferenceScope
49
- * @property {number} [startLine] - Start line number (for selections)
50
- * @property {number} [endLine] - End line number (for selections)
51
- * @property {number} [startColumn] - Start column number
52
- * @property {number} [endColumn] - End column number
53
- * @property {string} [functionName] - Function/method name (for code)
54
- * @property {string} [className] - Class name (for code)
55
- * @property {string} [namespace] - Namespace or module (for code)
56
- * @property {string[]} [includePaths] - Included sub-paths (for directories)
57
- * @property {string[]} [excludePaths] - Excluded sub-paths (for directories)
58
- * @property {number} [maxDepth] - Maximum directory depth
59
- */
60
-
61
- /**
62
- * File Reference (extends ContextReference)
63
- * @typedef {Object} FileReference
64
- * @property {string} absolutePath - Absolute file path
65
- * @property {string} relativePath - Relative file path from workspace
66
- * @property {string} extension - File extension
67
- * @property {boolean} exists - Whether file exists on filesystem
68
- * @property {FileStats} [stats] - File system statistics
69
- * @property {string} [gitStatus] - Git status of file
70
- * @property {DependencyInfo} [dependencies] - File dependencies
71
- */
72
-
73
- /**
74
- * Directory Reference (extends ContextReference)
75
- * @typedef {Object} DirectoryReference
76
- * @property {string} absolutePath - Absolute directory path
77
- * @property {string} relativePath - Relative directory path from workspace
78
- * @property {FileSystemTree} [tree] - Directory tree structure
79
- * @property {number} [fileCount] - Number of files in directory
80
- * @property {number} [totalSize] - Total size of directory contents
81
- * @property {string[]} [fileTypes] - File types present in directory
82
- */
83
-
84
- /**
85
- * Selection Reference (extends ContextReference)
86
- * @typedef {Object} SelectionReference
87
- * @property {string} sourceFile - Source file path
88
- * @property {string} selectedText - Selected text content
89
- * @property {SyntaxInfo} [syntax] - Syntax information
90
- * @property {ContextInfo} [context] - Surrounding context
91
- * @property {string} [purpose] - Purpose of selection
92
- */
93
-
94
- /**
95
- * Component Reference (extends ContextReference)
96
- * @typedef {Object} ComponentReference
97
- * @property {string} componentType - Type of component
98
- * @property {string} [sourceFile] - Source file containing component
99
- * @property {Object} [properties] - Component properties
100
- * @property {string[]} [dependencies] - Component dependencies
101
- * @property {string} [documentation] - Component documentation
102
- */
103
-
104
- /**
105
- * File system statistics
106
- * @typedef {Object} FileStats
107
- * @property {number} size - File size in bytes
108
- * @property {string} created - Creation timestamp
109
- * @property {string} modified - Last modification timestamp
110
- * @property {string} accessed - Last access timestamp
111
- * @property {boolean} isDirectory - Whether item is directory
112
- * @property {boolean} isFile - Whether item is file
113
- * @property {number} mode - File permissions mode
114
- */
115
-
116
- /**
117
- * File system tree structure
118
- * @typedef {Object} FileSystemTree
119
- * @property {string} name - Item name
120
- * @property {string} path - Item path
121
- * @property {string} type - Item type (file, directory)
122
- * @property {FileSystemTree[]} [children] - Child items (for directories)
123
- * @property {number} [size] - Item size
124
- * @property {string} [extension] - File extension
125
- */
126
-
127
- /**
128
- * Syntax information
129
- * @typedef {Object} SyntaxInfo
130
- * @property {string} language - Programming language
131
- * @property {string[]} [symbols] - Identified symbols
132
- * @property {string[]} [imports] - Import statements
133
- * @property {string[]} [functions] - Function definitions
134
- * @property {string[]} [classes] - Class definitions
135
- * @property {string[]} [variables] - Variable definitions
136
- */
137
-
138
- /**
139
- * Context information
140
- * @typedef {Object} ContextInfo
141
- * @property {string} [beforeText] - Text before selection
142
- * @property {string} [afterText] - Text after selection
143
- * @property {number} [indentLevel] - Indentation level
144
- * @property {string[]} [surroundingFunctions] - Surrounding function names
145
- * @property {string[]} [surroundingClasses] - Surrounding class names
146
- */
147
-
148
- /**
149
- * Dependency information
150
- * @typedef {Object} DependencyInfo
151
- * @property {string[]} imports - Imported modules/files
152
- * @property {string[]} exports - Exported items
153
- * @property {string[]} dependencies - External dependencies
154
- * @property {string[]} dependents - Files that depend on this file
155
- */
156
-
157
- /**
158
- * Context Reference validation functions
159
- */
160
- export class ContextReferenceValidator {
161
- /**
162
- * Validate context reference data structure
163
- * @param {Object} reference - Context reference to validate
164
- * @returns {Object} Validation result
165
- */
166
- static validate(reference) {
167
- const errors = [];
168
- const warnings = [];
169
-
170
- // Required fields
171
- if (!reference.id || typeof reference.id !== 'string') {
172
- errors.push('Reference ID is required and must be a string');
173
- }
174
-
175
- if (!reference.type || typeof reference.type !== 'string') {
176
- errors.push('Reference type is required and must be a string');
177
- }
178
-
179
- if (!reference.path || typeof reference.path !== 'string') {
180
- errors.push('Reference path is required and must be a string');
181
- }
182
-
183
- if (!reference.name || typeof reference.name !== 'string') {
184
- errors.push('Reference name is required and must be a string');
185
- }
186
-
187
- // Type validation
188
- if (reference.type && !Object.values(CONTEXT_REFERENCE_TYPES).includes(reference.type)) {
189
- errors.push(`Invalid reference type: ${reference.type}`);
190
- }
191
-
192
- // Content validation
193
- if (reference.content && typeof reference.content !== 'string') {
194
- errors.push('Reference content must be a string');
195
- }
196
-
197
- if (reference.content && reference.content.length > 1000000) { // 1MB
198
- warnings.push('Reference content is very large (>1MB)');
199
- }
200
-
201
- // Metadata validation
202
- if (reference.metadata) {
203
- const metadataValidation = this.validateMetadata(reference.metadata);
204
- errors.push(...metadataValidation.errors);
205
- warnings.push(...metadataValidation.warnings);
206
- }
207
-
208
- // Scope validation
209
- if (reference.scope) {
210
- const scopeValidation = this.validateScope(reference.scope);
211
- errors.push(...scopeValidation.errors);
212
- warnings.push(...scopeValidation.warnings);
213
- }
214
-
215
- // Access count validation
216
- if (reference.accessCount !== undefined && typeof reference.accessCount !== 'number') {
217
- errors.push('Access count must be a number');
218
- }
219
-
220
- // Timestamp validation
221
- const timestampFields = ['createdAt', 'lastAccessed', 'lastModified'];
222
- timestampFields.forEach(field => {
223
- if (reference[field] && !this.isValidTimestamp(reference[field])) {
224
- errors.push(`Invalid timestamp for ${field}: ${reference[field]}`);
225
- }
226
- });
227
-
228
- // Type-specific validation
229
- switch (reference.type) {
230
- case CONTEXT_REFERENCE_TYPES.FILE:
231
- const fileValidation = this.validateFileReference(reference);
232
- errors.push(...fileValidation.errors);
233
- warnings.push(...fileValidation.warnings);
234
- break;
235
- case CONTEXT_REFERENCE_TYPES.SELECTION:
236
- const selectionValidation = this.validateSelectionReference(reference);
237
- errors.push(...selectionValidation.errors);
238
- warnings.push(...selectionValidation.warnings);
239
- break;
240
- case CONTEXT_REFERENCE_TYPES.DIRECTORY:
241
- const directoryValidation = this.validateDirectoryReference(reference);
242
- errors.push(...directoryValidation.errors);
243
- warnings.push(...directoryValidation.warnings);
244
- break;
245
- }
246
-
247
- return {
248
- isValid: errors.length === 0,
249
- errors,
250
- warnings
251
- };
252
- }
253
-
254
- /**
255
- * Validate reference metadata
256
- * @param {Object} metadata - Metadata to validate
257
- * @returns {Object} Validation result
258
- */
259
- static validateMetadata(metadata) {
260
- const errors = [];
261
- const warnings = [];
262
-
263
- if (metadata.size !== undefined && (typeof metadata.size !== 'number' || metadata.size < 0)) {
264
- errors.push('Metadata size must be a non-negative number');
265
- }
266
-
267
- if (metadata.language && typeof metadata.language !== 'string') {
268
- errors.push('Metadata language must be a string');
269
- }
270
-
271
- if (metadata.encoding && typeof metadata.encoding !== 'string') {
272
- errors.push('Metadata encoding must be a string');
273
- }
274
-
275
- if (metadata.keywords && !Array.isArray(metadata.keywords)) {
276
- errors.push('Metadata keywords must be an array');
277
- }
278
-
279
- if (metadata.mimeType && typeof metadata.mimeType !== 'string') {
280
- errors.push('Metadata MIME type must be a string');
281
- }
282
-
283
- return { errors, warnings };
284
- }
285
-
286
- /**
287
- * Validate reference scope
288
- * @param {Object} scope - Scope to validate
289
- * @returns {Object} Validation result
290
- */
291
- static validateScope(scope) {
292
- const errors = [];
293
- const warnings = [];
294
-
295
- const numericFields = ['startLine', 'endLine', 'startColumn', 'endColumn', 'maxDepth'];
296
- numericFields.forEach(field => {
297
- if (scope[field] !== undefined && (typeof scope[field] !== 'number' || scope[field] < 0)) {
298
- errors.push(`Scope ${field} must be a non-negative number`);
299
- }
300
- });
301
-
302
- // Line range validation
303
- if (scope.startLine !== undefined && scope.endLine !== undefined) {
304
- if (scope.startLine > scope.endLine) {
305
- errors.push('Start line must be <= end line');
306
- }
307
- }
308
-
309
- // Column range validation
310
- if (scope.startColumn !== undefined && scope.endColumn !== undefined) {
311
- if (scope.startColumn > scope.endColumn) {
312
- errors.push('Start column must be <= end column');
313
- }
314
- }
315
-
316
- const arrayFields = ['includePaths', 'excludePaths'];
317
- arrayFields.forEach(field => {
318
- if (scope[field] && !Array.isArray(scope[field])) {
319
- errors.push(`Scope ${field} must be an array`);
320
- }
321
- });
322
-
323
- return { errors, warnings };
324
- }
325
-
326
- /**
327
- * Validate file reference specific fields
328
- * @param {Object} reference - File reference to validate
329
- * @returns {Object} Validation result
330
- */
331
- static validateFileReference(reference) {
332
- const errors = [];
333
- const warnings = [];
334
-
335
- if (reference.absolutePath && typeof reference.absolutePath !== 'string') {
336
- errors.push('Absolute path must be a string');
337
- }
338
-
339
- if (reference.relativePath && typeof reference.relativePath !== 'string') {
340
- errors.push('Relative path must be a string');
341
- }
342
-
343
- if (reference.extension && typeof reference.extension !== 'string') {
344
- errors.push('File extension must be a string');
345
- }
346
-
347
- if (reference.exists !== undefined && typeof reference.exists !== 'boolean') {
348
- errors.push('File exists flag must be a boolean');
349
- }
350
-
351
- return { errors, warnings };
352
- }
353
-
354
- /**
355
- * Validate selection reference specific fields
356
- * @param {Object} reference - Selection reference to validate
357
- * @returns {Object} Validation result
358
- */
359
- static validateSelectionReference(reference) {
360
- const errors = [];
361
- const warnings = [];
362
-
363
- if (!reference.scope || (!reference.scope.startLine && !reference.scope.endLine)) {
364
- warnings.push('Selection reference should have line scope defined');
365
- }
366
-
367
- if (reference.selectedText && typeof reference.selectedText !== 'string') {
368
- errors.push('Selected text must be a string');
369
- }
370
-
371
- if (reference.sourceFile && typeof reference.sourceFile !== 'string') {
372
- errors.push('Source file must be a string');
373
- }
374
-
375
- return { errors, warnings };
376
- }
377
-
378
- /**
379
- * Validate directory reference specific fields
380
- * @param {Object} reference - Directory reference to validate
381
- * @returns {Object} Validation result
382
- */
383
- static validateDirectoryReference(reference) {
384
- const errors = [];
385
- const warnings = [];
386
-
387
- if (reference.fileCount !== undefined && (typeof reference.fileCount !== 'number' || reference.fileCount < 0)) {
388
- errors.push('File count must be a non-negative number');
389
- }
390
-
391
- if (reference.totalSize !== undefined && (typeof reference.totalSize !== 'number' || reference.totalSize < 0)) {
392
- errors.push('Total size must be a non-negative number');
393
- }
394
-
395
- if (reference.fileTypes && !Array.isArray(reference.fileTypes)) {
396
- errors.push('File types must be an array');
397
- }
398
-
399
- return { errors, warnings };
400
- }
401
-
402
- /**
403
- * Check if a timestamp is valid ISO string
404
- * @param {string} timestamp - Timestamp to validate
405
- * @returns {boolean} True if valid
406
- */
407
- static isValidTimestamp(timestamp) {
408
- if (typeof timestamp !== 'string') return false;
409
- const date = new Date(timestamp);
410
- return date instanceof Date && !isNaN(date.getTime());
411
- }
412
- }
413
-
414
- /**
415
- * Context Reference factory functions
416
- */
417
- export class ContextReferenceFactory {
418
- /**
419
- * Create a new context reference
420
- * @param {string} type - Reference type
421
- * @param {string} path - Reference path
422
- * @param {string} name - Reference name
423
- * @param {Object} options - Additional options
424
- * @returns {ContextReference} New context reference
425
- */
426
- static create(type, path, name, options = {}) {
427
- const now = new Date().toISOString();
428
- const referenceId = this.generateReferenceId();
429
-
430
- return {
431
- id: referenceId,
432
- type,
433
- path,
434
- name,
435
- content: options.content || null,
436
- metadata: this.createDefaultMetadata(type, path, options.metadata),
437
- scope: options.scope || {},
438
- createdAt: now,
439
- lastAccessed: null,
440
- lastModified: options.lastModified || null,
441
- isValid: true,
442
- invalidReason: null,
443
- accessCount: 0,
444
- tags: options.tags || {}
445
- };
446
- }
447
-
448
- /**
449
- * Create a file reference
450
- * @param {string} absolutePath - Absolute file path
451
- * @param {string} relativePath - Relative file path
452
- * @param {Object} options - Additional options
453
- * @returns {FileReference} File reference
454
- */
455
- static createFileReference(absolutePath, relativePath, options = {}) {
456
- const name = options.name || this.extractFileName(absolutePath);
457
- const extension = this.extractFileExtension(absolutePath);
458
-
459
- const reference = this.create(CONTEXT_REFERENCE_TYPES.FILE, relativePath, name, options);
460
-
461
- return {
462
- ...reference,
463
- absolutePath,
464
- relativePath,
465
- extension,
466
- exists: options.exists !== undefined ? options.exists : true,
467
- stats: options.stats || null,
468
- gitStatus: options.gitStatus || null,
469
- dependencies: options.dependencies || null
470
- };
471
- }
472
-
473
- /**
474
- * Create a selection reference
475
- * @param {string} sourceFile - Source file path
476
- * @param {string} selectedText - Selected text
477
- * @param {Object} scope - Selection scope
478
- * @param {Object} options - Additional options
479
- * @returns {SelectionReference} Selection reference
480
- */
481
- static createSelectionReference(sourceFile, selectedText, scope, options = {}) {
482
- const name = options.name || this.generateSelectionName(sourceFile, scope);
483
-
484
- const reference = this.create(CONTEXT_REFERENCE_TYPES.SELECTION, sourceFile, name, {
485
- ...options,
486
- scope,
487
- content: selectedText
488
- });
489
-
490
- return {
491
- ...reference,
492
- sourceFile,
493
- selectedText,
494
- syntax: options.syntax || null,
495
- context: options.context || null,
496
- purpose: options.purpose || null
497
- };
498
- }
499
-
500
- /**
501
- * Create a directory reference
502
- * @param {string} absolutePath - Absolute directory path
503
- * @param {string} relativePath - Relative directory path
504
- * @param {Object} options - Additional options
505
- * @returns {DirectoryReference} Directory reference
506
- */
507
- static createDirectoryReference(absolutePath, relativePath, options = {}) {
508
- const name = options.name || this.extractDirectoryName(absolutePath);
509
-
510
- const reference = this.create(CONTEXT_REFERENCE_TYPES.DIRECTORY, relativePath, name, options);
511
-
512
- return {
513
- ...reference,
514
- absolutePath,
515
- relativePath,
516
- tree: options.tree || null,
517
- fileCount: options.fileCount || null,
518
- totalSize: options.totalSize || null,
519
- fileTypes: options.fileTypes || null
520
- };
521
- }
522
-
523
- /**
524
- * Create a component reference
525
- * @param {string} componentType - Component type
526
- * @param {string} path - Component path/identifier
527
- * @param {string} name - Component name
528
- * @param {Object} options - Additional options
529
- * @returns {ComponentReference} Component reference
530
- */
531
- static createComponentReference(componentType, path, name, options = {}) {
532
- const reference = this.create(CONTEXT_REFERENCE_TYPES.COMPONENT, path, name, options);
533
-
534
- return {
535
- ...reference,
536
- componentType,
537
- sourceFile: options.sourceFile || null,
538
- properties: options.properties || null,
539
- dependencies: options.dependencies || null,
540
- documentation: options.documentation || null
541
- };
542
- }
543
-
544
- /**
545
- * Create default metadata for reference type
546
- * @param {string} type - Reference type
547
- * @param {string} path - Reference path
548
- * @param {Object} overrides - Metadata overrides
549
- * @returns {ReferenceMetadata} Default metadata
550
- */
551
- static createDefaultMetadata(type, path, overrides = {}) {
552
- const metadata = {
553
- language: null,
554
- encoding: 'utf-8',
555
- size: null,
556
- mimeType: null,
557
- checksum: null,
558
- keywords: [],
559
- description: '',
560
- customFields: {},
561
- icon: this.getDefaultIcon(type, path),
562
- permissions: {},
563
- ...overrides
564
- };
565
-
566
- // Set language for file references
567
- if (type === CONTEXT_REFERENCE_TYPES.FILE) {
568
- const extension = this.extractFileExtension(path);
569
- metadata.language = this.getLanguageFromExtension(extension);
570
- metadata.mimeType = this.getMimeTypeFromExtension(extension);
571
- }
572
-
573
- return metadata;
574
- }
575
-
576
- /**
577
- * Generate unique reference ID
578
- * @returns {string} Unique reference ID
579
- */
580
- static generateReferenceId() {
581
- const timestamp = Date.now().toString(36);
582
- const random = Math.random().toString(36).substr(2, 9);
583
- return `ref_${timestamp}_${random}`;
584
- }
585
-
586
- /**
587
- * Extract file name from path
588
- * @param {string} path - File path
589
- * @returns {string} File name
590
- */
591
- static extractFileName(path) {
592
- return path.split(/[/\\]/).pop() || path;
593
- }
594
-
595
- /**
596
- * Extract directory name from path
597
- * @param {string} path - Directory path
598
- * @returns {string} Directory name
599
- */
600
- static extractDirectoryName(path) {
601
- const parts = path.split(/[/\\]/).filter(Boolean);
602
- return parts[parts.length - 1] || 'Root';
603
- }
604
-
605
- /**
606
- * Extract file extension from path
607
- * @param {string} path - File path
608
- * @returns {string} File extension
609
- */
610
- static extractFileExtension(path) {
611
- const fileName = this.extractFileName(path);
612
- const lastDot = fileName.lastIndexOf('.');
613
- return lastDot !== -1 ? fileName.substring(lastDot) : '';
614
- }
615
-
616
- /**
617
- * Generate selection name from file and scope
618
- * @param {string} sourceFile - Source file path
619
- * @param {Object} scope - Selection scope
620
- * @returns {string} Selection name
621
- */
622
- static generateSelectionName(sourceFile, scope) {
623
- const fileName = this.extractFileName(sourceFile);
624
-
625
- if (scope.startLine && scope.endLine) {
626
- if (scope.startLine === scope.endLine) {
627
- return `${fileName}:${scope.startLine}`;
628
- } else {
629
- return `${fileName}:${scope.startLine}-${scope.endLine}`;
630
- }
631
- }
632
-
633
- if (scope.functionName) {
634
- return `${fileName}:${scope.functionName}()`;
635
- }
636
-
637
- if (scope.className) {
638
- return `${fileName}:${scope.className}`;
639
- }
640
-
641
- return `${fileName} (selection)`;
642
- }
643
-
644
- /**
645
- * Get default icon for reference type and path
646
- * @param {string} type - Reference type
647
- * @param {string} path - Reference path
648
- * @returns {string} Icon identifier
649
- */
650
- static getDefaultIcon(type, path) {
651
- if (type === CONTEXT_REFERENCE_TYPES.FILE) {
652
- const extension = this.extractFileExtension(path);
653
- return FILE_ICONS[extension] || CONTEXT_ICONS.DEFAULT;
654
- }
655
-
656
- return CONTEXT_ICONS[type] || CONTEXT_ICONS.DEFAULT;
657
- }
658
-
659
- /**
660
- * Get programming language from file extension
661
- * @param {string} extension - File extension
662
- * @returns {string|null} Programming language
663
- */
664
- static getLanguageFromExtension(extension) {
665
- const languageMap = {
666
- '.js': 'javascript',
667
- '.jsx': 'javascript',
668
- '.ts': 'typescript',
669
- '.tsx': 'typescript',
670
- '.py': 'python',
671
- '.java': 'java',
672
- '.cpp': 'cpp',
673
- '.c': 'c',
674
- '.cs': 'csharp',
675
- '.php': 'php',
676
- '.rb': 'ruby',
677
- '.go': 'go',
678
- '.rs': 'rust',
679
- '.html': 'html',
680
- '.css': 'css',
681
- '.scss': 'scss',
682
- '.json': 'json',
683
- '.yml': 'yaml',
684
- '.yaml': 'yaml',
685
- '.xml': 'xml',
686
- '.sql': 'sql',
687
- '.md': 'markdown'
688
- };
689
-
690
- return languageMap[extension.toLowerCase()] || null;
691
- }
692
-
693
- /**
694
- * Get MIME type from file extension
695
- * @param {string} extension - File extension
696
- * @returns {string|null} MIME type
697
- */
698
- static getMimeTypeFromExtension(extension) {
699
- const mimeMap = {
700
- '.js': 'application/javascript',
701
- '.jsx': 'application/javascript',
702
- '.ts': 'application/typescript',
703
- '.tsx': 'application/typescript',
704
- '.py': 'text/x-python',
705
- '.java': 'text/x-java-source',
706
- '.cpp': 'text/x-c++src',
707
- '.c': 'text/x-csrc',
708
- '.cs': 'text/x-csharp',
709
- '.php': 'application/x-php',
710
- '.rb': 'application/x-ruby',
711
- '.go': 'text/x-go',
712
- '.rs': 'text/x-rust',
713
- '.html': 'text/html',
714
- '.css': 'text/css',
715
- '.scss': 'text/x-scss',
716
- '.json': 'application/json',
717
- '.yml': 'application/x-yaml',
718
- '.yaml': 'application/x-yaml',
719
- '.xml': 'application/xml',
720
- '.sql': 'application/sql',
721
- '.md': 'text/markdown',
722
- '.txt': 'text/plain'
723
- };
724
-
725
- return mimeMap[extension.toLowerCase()] || 'text/plain';
726
- }
727
- }
728
-
729
- /**
730
- * Context Reference utility functions
731
- */
732
- export class ContextReferenceUtils {
733
- /**
734
- * Check if reference is still valid
735
- * @param {ContextReference} reference - Reference to check
736
- * @returns {boolean} True if valid
737
- */
738
- static isValid(reference) {
739
- return reference.isValid && !reference.invalidReason;
740
- }
741
-
742
- /**
743
- * Mark reference as accessed
744
- * @param {ContextReference} reference - Reference to mark
745
- * @returns {ContextReference} Updated reference
746
- */
747
- static markAccessed(reference) {
748
- return {
749
- ...reference,
750
- lastAccessed: new Date().toISOString(),
751
- accessCount: reference.accessCount + 1
752
- };
753
- }
754
-
755
- /**
756
- * Mark reference as invalid
757
- * @param {ContextReference} reference - Reference to invalidate
758
- * @param {string} reason - Reason for invalidation
759
- * @returns {ContextReference} Updated reference
760
- */
761
- static markInvalid(reference, reason) {
762
- return {
763
- ...reference,
764
- isValid: false,
765
- invalidReason: reason
766
- };
767
- }
768
-
769
- /**
770
- * Get reference display name with context
771
- * @param {ContextReference} reference - Reference to format
772
- * @returns {string} Display name
773
- */
774
- static getDisplayName(reference) {
775
- if (reference.type === CONTEXT_REFERENCE_TYPES.SELECTION && reference.scope) {
776
- return ContextReferenceFactory.generateSelectionName(reference.path, reference.scope);
777
- }
778
-
779
- return reference.name;
780
- }
781
-
782
- /**
783
- * Get reference description
784
- * @param {ContextReference} reference - Reference to describe
785
- * @returns {string} Description
786
- */
787
- static getDescription(reference) {
788
- if (reference.metadata?.description) {
789
- return reference.metadata.description;
790
- }
791
-
792
- switch (reference.type) {
793
- case CONTEXT_REFERENCE_TYPES.FILE:
794
- return `File: ${reference.path}`;
795
- case CONTEXT_REFERENCE_TYPES.DIRECTORY:
796
- return `Directory: ${reference.path}`;
797
- case CONTEXT_REFERENCE_TYPES.SELECTION:
798
- return `Selection from ${reference.path}`;
799
- case CONTEXT_REFERENCE_TYPES.COMPONENT:
800
- return `Component: ${reference.name}`;
801
- default:
802
- return reference.path;
803
- }
804
- }
805
-
806
- /**
807
- * Calculate reference relevance score
808
- * @param {ContextReference} reference - Reference to score
809
- * @param {Object} context - Scoring context
810
- * @returns {number} Relevance score (0-1)
811
- */
812
- static calculateRelevance(reference, context = {}) {
813
- let score = 0.5; // Base score
814
-
815
- // Recent access bonus
816
- if (reference.lastAccessed) {
817
- const daysSinceAccess = (Date.now() - new Date(reference.lastAccessed)) / (1000 * 60 * 60 * 24);
818
- score += Math.max(0, 0.2 * (1 - daysSinceAccess / 30)); // Decay over 30 days
819
- }
820
-
821
- // Access frequency bonus
822
- if (reference.accessCount > 0) {
823
- score += Math.min(0.2, reference.accessCount * 0.01);
824
- }
825
-
826
- // Type-specific scoring
827
- switch (reference.type) {
828
- case CONTEXT_REFERENCE_TYPES.FILE:
829
- if (context.fileTypes && reference.metadata?.language) {
830
- if (context.fileTypes.includes(reference.metadata.language)) {
831
- score += 0.2;
832
- }
833
- }
834
- break;
835
- case CONTEXT_REFERENCE_TYPES.SELECTION:
836
- score += 0.1; // Selections are often more relevant
837
- break;
838
- }
839
-
840
- // Keyword matching
841
- if (context.keywords && reference.metadata?.keywords) {
842
- const matches = context.keywords.filter(k =>
843
- reference.metadata.keywords.includes(k)
844
- ).length;
845
- score += Math.min(0.3, matches * 0.1);
846
- }
847
-
848
- // Invalid references get heavy penalty
849
- if (!reference.isValid) {
850
- score *= 0.1;
851
- }
852
-
853
- return Math.min(1, Math.max(0, score));
854
- }
855
-
856
- /**
857
- * Group references by type
858
- * @param {ContextReference[]} references - References to group
859
- * @returns {Object} Grouped references
860
- */
861
- static groupByType(references) {
862
- return references.reduce((groups, reference) => {
863
- const type = reference.type;
864
- if (!groups[type]) {
865
- groups[type] = [];
866
- }
867
- groups[type].push(reference);
868
- return groups;
869
- }, {});
870
- }
871
-
872
- /**
873
- * Sort references by relevance
874
- * @param {ContextReference[]} references - References to sort
875
- * @param {Object} context - Sorting context
876
- * @returns {ContextReference[]} Sorted references
877
- */
878
- static sortByRelevance(references, context = {}) {
879
- return [...references].sort((a, b) => {
880
- const scoreA = this.calculateRelevance(a, context);
881
- const scoreB = this.calculateRelevance(b, context);
882
- return scoreB - scoreA;
883
- });
884
- }
885
-
886
- /**
887
- * Filter references by criteria
888
- * @param {ContextReference[]} references - References to filter
889
- * @param {Object} criteria - Filter criteria
890
- * @returns {ContextReference[]} Filtered references
891
- */
892
- static filter(references, criteria = {}) {
893
- return references.filter(reference => {
894
- // Type filter
895
- if (criteria.types && !criteria.types.includes(reference.type)) {
896
- return false;
897
- }
898
-
899
- // Valid filter
900
- if (criteria.validOnly && !reference.isValid) {
901
- return false;
902
- }
903
-
904
- // Language filter
905
- if (criteria.languages && reference.metadata?.language) {
906
- if (!criteria.languages.includes(reference.metadata.language)) {
907
- return false;
908
- }
909
- }
910
-
911
- // Path filter
912
- if (criteria.pathPattern) {
913
- const regex = new RegExp(criteria.pathPattern, 'i');
914
- if (!regex.test(reference.path)) {
915
- return false;
916
- }
917
- }
918
-
919
- // Keyword filter
920
- if (criteria.keywords && reference.metadata?.keywords) {
921
- const hasKeyword = criteria.keywords.some(keyword =>
922
- reference.metadata.keywords.includes(keyword)
923
- );
924
- if (!hasKeyword) {
925
- return false;
926
- }
927
- }
928
-
929
- // Date range filter
930
- if (criteria.createdAfter) {
931
- if (new Date(reference.createdAt) < new Date(criteria.createdAfter)) {
932
- return false;
933
- }
934
- }
935
-
936
- if (criteria.createdBefore) {
937
- if (new Date(reference.createdAt) > new Date(criteria.createdBefore)) {
938
- return false;
939
- }
940
- }
941
-
942
- return true;
943
- });
944
- }
945
-
946
- /**
947
- * Format reference for display
948
- * @param {ContextReference} reference - Reference to format
949
- * @returns {Object} Formatted reference
950
- */
951
- static formatForDisplay(reference) {
952
- return {
953
- id: reference.id,
954
- type: reference.type,
955
- name: this.getDisplayName(reference),
956
- description: this.getDescription(reference),
957
- path: reference.path,
958
- icon: reference.metadata?.icon || CONTEXT_ICONS[reference.type] || CONTEXT_ICONS.DEFAULT,
959
- isValid: reference.isValid,
960
- lastAccessed: reference.lastAccessed,
961
- accessCount: reference.accessCount,
962
- size: reference.metadata?.size || null,
963
- language: reference.metadata?.language || null
964
- };
965
- }
966
- }
967
-
968
- export default {
969
- ContextReferenceValidator,
970
- ContextReferenceFactory,
971
- ContextReferenceUtils
1
+ /**
2
+ * Context Reference Data Model - Type definitions and validation for context references
3
+ *
4
+ * Purpose:
5
+ * - Define the structure and properties of context references
6
+ * - Provide validation functions for context reference data
7
+ * - Handle context reference resolution and management
8
+ */
9
+
10
+ import { CONTEXT_REFERENCE_TYPES, CONTEXT_ICONS, FILE_ICONS } from '../utilities/constants.js';
11
+
12
+ /**
13
+ * Context Reference data model
14
+ * @typedef {Object} ContextReference
15
+ * @property {string} id - Unique reference identifier
16
+ * @property {string} type - Reference type (file, component, selection, directory)
17
+ * @property {string} path - Path or identifier of referenced item
18
+ * @property {string} name - Human-readable name
19
+ * @property {string} [content] - Referenced content (if loaded)
20
+ * @property {ReferenceMetadata} metadata - Reference metadata
21
+ * @property {ReferenceScope} scope - Reference scope and boundaries
22
+ * @property {string} createdAt - ISO timestamp of creation
23
+ * @property {string} [lastAccessed] - ISO timestamp of last access
24
+ * @property {string} [lastModified] - ISO timestamp of last modification
25
+ * @property {boolean} isValid - Whether reference is still valid
26
+ * @property {string} [invalidReason] - Reason for invalidity
27
+ * @property {number} accessCount - Number of times accessed
28
+ * @property {Object} tags - Reference tags and labels
29
+ */
30
+
31
+ /**
32
+ * Reference metadata
33
+ * @typedef {Object} ReferenceMetadata
34
+ * @property {string} [language] - Programming language (for code files)
35
+ * @property {string} [encoding] - File encoding
36
+ * @property {number} [size] - Content size in bytes
37
+ * @property {string} [mimeType] - MIME type
38
+ * @property {string} [checksum] - Content checksum for integrity
39
+ * @property {string[]} [keywords] - Extracted keywords
40
+ * @property {string} [description] - Reference description
41
+ * @property {Object} [customFields] - Custom metadata fields
42
+ * @property {string} [icon] - Display icon identifier
43
+ * @property {Object} [permissions] - Access permissions
44
+ */
45
+
46
+ /**
47
+ * Reference scope and boundaries
48
+ * @typedef {Object} ReferenceScope
49
+ * @property {number} [startLine] - Start line number (for selections)
50
+ * @property {number} [endLine] - End line number (for selections)
51
+ * @property {number} [startColumn] - Start column number
52
+ * @property {number} [endColumn] - End column number
53
+ * @property {string} [functionName] - Function/method name (for code)
54
+ * @property {string} [className] - Class name (for code)
55
+ * @property {string} [namespace] - Namespace or module (for code)
56
+ * @property {string[]} [includePaths] - Included sub-paths (for directories)
57
+ * @property {string[]} [excludePaths] - Excluded sub-paths (for directories)
58
+ * @property {number} [maxDepth] - Maximum directory depth
59
+ */
60
+
61
+ /**
62
+ * File Reference (extends ContextReference)
63
+ * @typedef {Object} FileReference
64
+ * @property {string} absolutePath - Absolute file path
65
+ * @property {string} relativePath - Relative file path from workspace
66
+ * @property {string} extension - File extension
67
+ * @property {boolean} exists - Whether file exists on filesystem
68
+ * @property {FileStats} [stats] - File system statistics
69
+ * @property {string} [gitStatus] - Git status of file
70
+ * @property {DependencyInfo} [dependencies] - File dependencies
71
+ */
72
+
73
+ /**
74
+ * Directory Reference (extends ContextReference)
75
+ * @typedef {Object} DirectoryReference
76
+ * @property {string} absolutePath - Absolute directory path
77
+ * @property {string} relativePath - Relative directory path from workspace
78
+ * @property {FileSystemTree} [tree] - Directory tree structure
79
+ * @property {number} [fileCount] - Number of files in directory
80
+ * @property {number} [totalSize] - Total size of directory contents
81
+ * @property {string[]} [fileTypes] - File types present in directory
82
+ */
83
+
84
+ /**
85
+ * Selection Reference (extends ContextReference)
86
+ * @typedef {Object} SelectionReference
87
+ * @property {string} sourceFile - Source file path
88
+ * @property {string} selectedText - Selected text content
89
+ * @property {SyntaxInfo} [syntax] - Syntax information
90
+ * @property {ContextInfo} [context] - Surrounding context
91
+ * @property {string} [purpose] - Purpose of selection
92
+ */
93
+
94
+ /**
95
+ * Component Reference (extends ContextReference)
96
+ * @typedef {Object} ComponentReference
97
+ * @property {string} componentType - Type of component
98
+ * @property {string} [sourceFile] - Source file containing component
99
+ * @property {Object} [properties] - Component properties
100
+ * @property {string[]} [dependencies] - Component dependencies
101
+ * @property {string} [documentation] - Component documentation
102
+ */
103
+
104
+ /**
105
+ * File system statistics
106
+ * @typedef {Object} FileStats
107
+ * @property {number} size - File size in bytes
108
+ * @property {string} created - Creation timestamp
109
+ * @property {string} modified - Last modification timestamp
110
+ * @property {string} accessed - Last access timestamp
111
+ * @property {boolean} isDirectory - Whether item is directory
112
+ * @property {boolean} isFile - Whether item is file
113
+ * @property {number} mode - File permissions mode
114
+ */
115
+
116
+ /**
117
+ * File system tree structure
118
+ * @typedef {Object} FileSystemTree
119
+ * @property {string} name - Item name
120
+ * @property {string} path - Item path
121
+ * @property {string} type - Item type (file, directory)
122
+ * @property {FileSystemTree[]} [children] - Child items (for directories)
123
+ * @property {number} [size] - Item size
124
+ * @property {string} [extension] - File extension
125
+ */
126
+
127
+ /**
128
+ * Syntax information
129
+ * @typedef {Object} SyntaxInfo
130
+ * @property {string} language - Programming language
131
+ * @property {string[]} [symbols] - Identified symbols
132
+ * @property {string[]} [imports] - Import statements
133
+ * @property {string[]} [functions] - Function definitions
134
+ * @property {string[]} [classes] - Class definitions
135
+ * @property {string[]} [variables] - Variable definitions
136
+ */
137
+
138
+ /**
139
+ * Context information
140
+ * @typedef {Object} ContextInfo
141
+ * @property {string} [beforeText] - Text before selection
142
+ * @property {string} [afterText] - Text after selection
143
+ * @property {number} [indentLevel] - Indentation level
144
+ * @property {string[]} [surroundingFunctions] - Surrounding function names
145
+ * @property {string[]} [surroundingClasses] - Surrounding class names
146
+ */
147
+
148
+ /**
149
+ * Dependency information
150
+ * @typedef {Object} DependencyInfo
151
+ * @property {string[]} imports - Imported modules/files
152
+ * @property {string[]} exports - Exported items
153
+ * @property {string[]} dependencies - External dependencies
154
+ * @property {string[]} dependents - Files that depend on this file
155
+ */
156
+
157
+ /**
158
+ * Context Reference validation functions
159
+ */
160
+ export class ContextReferenceValidator {
161
+ /**
162
+ * Validate context reference data structure
163
+ * @param {Object} reference - Context reference to validate
164
+ * @returns {Object} Validation result
165
+ */
166
+ static validate(reference) {
167
+ const errors = [];
168
+ const warnings = [];
169
+
170
+ // Required fields
171
+ if (!reference.id || typeof reference.id !== 'string') {
172
+ errors.push('Reference ID is required and must be a string');
173
+ }
174
+
175
+ if (!reference.type || typeof reference.type !== 'string') {
176
+ errors.push('Reference type is required and must be a string');
177
+ }
178
+
179
+ if (!reference.path || typeof reference.path !== 'string') {
180
+ errors.push('Reference path is required and must be a string');
181
+ }
182
+
183
+ if (!reference.name || typeof reference.name !== 'string') {
184
+ errors.push('Reference name is required and must be a string');
185
+ }
186
+
187
+ // Type validation
188
+ if (reference.type && !Object.values(CONTEXT_REFERENCE_TYPES).includes(reference.type)) {
189
+ errors.push(`Invalid reference type: ${reference.type}`);
190
+ }
191
+
192
+ // Content validation
193
+ if (reference.content && typeof reference.content !== 'string') {
194
+ errors.push('Reference content must be a string');
195
+ }
196
+
197
+ if (reference.content && reference.content.length > 1000000) { // 1MB
198
+ warnings.push('Reference content is very large (>1MB)');
199
+ }
200
+
201
+ // Metadata validation
202
+ if (reference.metadata) {
203
+ const metadataValidation = this.validateMetadata(reference.metadata);
204
+ errors.push(...metadataValidation.errors);
205
+ warnings.push(...metadataValidation.warnings);
206
+ }
207
+
208
+ // Scope validation
209
+ if (reference.scope) {
210
+ const scopeValidation = this.validateScope(reference.scope);
211
+ errors.push(...scopeValidation.errors);
212
+ warnings.push(...scopeValidation.warnings);
213
+ }
214
+
215
+ // Access count validation
216
+ if (reference.accessCount !== undefined && typeof reference.accessCount !== 'number') {
217
+ errors.push('Access count must be a number');
218
+ }
219
+
220
+ // Timestamp validation
221
+ const timestampFields = ['createdAt', 'lastAccessed', 'lastModified'];
222
+ timestampFields.forEach(field => {
223
+ if (reference[field] && !this.isValidTimestamp(reference[field])) {
224
+ errors.push(`Invalid timestamp for ${field}: ${reference[field]}`);
225
+ }
226
+ });
227
+
228
+ // Type-specific validation
229
+ switch (reference.type) {
230
+ case CONTEXT_REFERENCE_TYPES.FILE: {
231
+ const fileValidation = this.validateFileReference(reference);
232
+ errors.push(...fileValidation.errors);
233
+ warnings.push(...fileValidation.warnings);
234
+ break;
235
+ }
236
+ case CONTEXT_REFERENCE_TYPES.SELECTION: {
237
+ const selectionValidation = this.validateSelectionReference(reference);
238
+ errors.push(...selectionValidation.errors);
239
+ warnings.push(...selectionValidation.warnings);
240
+ break;
241
+ }
242
+ case CONTEXT_REFERENCE_TYPES.DIRECTORY: {
243
+ const directoryValidation = this.validateDirectoryReference(reference);
244
+ errors.push(...directoryValidation.errors);
245
+ warnings.push(...directoryValidation.warnings);
246
+ break;
247
+ }
248
+ }
249
+
250
+ return {
251
+ isValid: errors.length === 0,
252
+ errors,
253
+ warnings
254
+ };
255
+ }
256
+
257
+ /**
258
+ * Validate reference metadata
259
+ * @param {Object} metadata - Metadata to validate
260
+ * @returns {Object} Validation result
261
+ */
262
+ static validateMetadata(metadata) {
263
+ const errors = [];
264
+ const warnings = [];
265
+
266
+ if (metadata.size !== undefined && (typeof metadata.size !== 'number' || metadata.size < 0)) {
267
+ errors.push('Metadata size must be a non-negative number');
268
+ }
269
+
270
+ if (metadata.language && typeof metadata.language !== 'string') {
271
+ errors.push('Metadata language must be a string');
272
+ }
273
+
274
+ if (metadata.encoding && typeof metadata.encoding !== 'string') {
275
+ errors.push('Metadata encoding must be a string');
276
+ }
277
+
278
+ if (metadata.keywords && !Array.isArray(metadata.keywords)) {
279
+ errors.push('Metadata keywords must be an array');
280
+ }
281
+
282
+ if (metadata.mimeType && typeof metadata.mimeType !== 'string') {
283
+ errors.push('Metadata MIME type must be a string');
284
+ }
285
+
286
+ return { errors, warnings };
287
+ }
288
+
289
+ /**
290
+ * Validate reference scope
291
+ * @param {Object} scope - Scope to validate
292
+ * @returns {Object} Validation result
293
+ */
294
+ static validateScope(scope) {
295
+ const errors = [];
296
+ const warnings = [];
297
+
298
+ const numericFields = ['startLine', 'endLine', 'startColumn', 'endColumn', 'maxDepth'];
299
+ numericFields.forEach(field => {
300
+ if (scope[field] !== undefined && (typeof scope[field] !== 'number' || scope[field] < 0)) {
301
+ errors.push(`Scope ${field} must be a non-negative number`);
302
+ }
303
+ });
304
+
305
+ // Line range validation
306
+ if (scope.startLine !== undefined && scope.endLine !== undefined) {
307
+ if (scope.startLine > scope.endLine) {
308
+ errors.push('Start line must be <= end line');
309
+ }
310
+ }
311
+
312
+ // Column range validation
313
+ if (scope.startColumn !== undefined && scope.endColumn !== undefined) {
314
+ if (scope.startColumn > scope.endColumn) {
315
+ errors.push('Start column must be <= end column');
316
+ }
317
+ }
318
+
319
+ const arrayFields = ['includePaths', 'excludePaths'];
320
+ arrayFields.forEach(field => {
321
+ if (scope[field] && !Array.isArray(scope[field])) {
322
+ errors.push(`Scope ${field} must be an array`);
323
+ }
324
+ });
325
+
326
+ return { errors, warnings };
327
+ }
328
+
329
+ /**
330
+ * Validate file reference specific fields
331
+ * @param {Object} reference - File reference to validate
332
+ * @returns {Object} Validation result
333
+ */
334
+ static validateFileReference(reference) {
335
+ const errors = [];
336
+ const warnings = [];
337
+
338
+ if (reference.absolutePath && typeof reference.absolutePath !== 'string') {
339
+ errors.push('Absolute path must be a string');
340
+ }
341
+
342
+ if (reference.relativePath && typeof reference.relativePath !== 'string') {
343
+ errors.push('Relative path must be a string');
344
+ }
345
+
346
+ if (reference.extension && typeof reference.extension !== 'string') {
347
+ errors.push('File extension must be a string');
348
+ }
349
+
350
+ if (reference.exists !== undefined && typeof reference.exists !== 'boolean') {
351
+ errors.push('File exists flag must be a boolean');
352
+ }
353
+
354
+ return { errors, warnings };
355
+ }
356
+
357
+ /**
358
+ * Validate selection reference specific fields
359
+ * @param {Object} reference - Selection reference to validate
360
+ * @returns {Object} Validation result
361
+ */
362
+ static validateSelectionReference(reference) {
363
+ const errors = [];
364
+ const warnings = [];
365
+
366
+ if (!reference.scope || (!reference.scope.startLine && !reference.scope.endLine)) {
367
+ warnings.push('Selection reference should have line scope defined');
368
+ }
369
+
370
+ if (reference.selectedText && typeof reference.selectedText !== 'string') {
371
+ errors.push('Selected text must be a string');
372
+ }
373
+
374
+ if (reference.sourceFile && typeof reference.sourceFile !== 'string') {
375
+ errors.push('Source file must be a string');
376
+ }
377
+
378
+ return { errors, warnings };
379
+ }
380
+
381
+ /**
382
+ * Validate directory reference specific fields
383
+ * @param {Object} reference - Directory reference to validate
384
+ * @returns {Object} Validation result
385
+ */
386
+ static validateDirectoryReference(reference) {
387
+ const errors = [];
388
+ const warnings = [];
389
+
390
+ if (reference.fileCount !== undefined && (typeof reference.fileCount !== 'number' || reference.fileCount < 0)) {
391
+ errors.push('File count must be a non-negative number');
392
+ }
393
+
394
+ if (reference.totalSize !== undefined && (typeof reference.totalSize !== 'number' || reference.totalSize < 0)) {
395
+ errors.push('Total size must be a non-negative number');
396
+ }
397
+
398
+ if (reference.fileTypes && !Array.isArray(reference.fileTypes)) {
399
+ errors.push('File types must be an array');
400
+ }
401
+
402
+ return { errors, warnings };
403
+ }
404
+
405
+ /**
406
+ * Check if a timestamp is valid ISO string
407
+ * @param {string} timestamp - Timestamp to validate
408
+ * @returns {boolean} True if valid
409
+ */
410
+ static isValidTimestamp(timestamp) {
411
+ if (typeof timestamp !== 'string') return false;
412
+ const date = new Date(timestamp);
413
+ return date instanceof Date && !isNaN(date.getTime());
414
+ }
415
+ }
416
+
417
+ /**
418
+ * Context Reference factory functions
419
+ */
420
+ export class ContextReferenceFactory {
421
+ /**
422
+ * Create a new context reference
423
+ * @param {string} type - Reference type
424
+ * @param {string} path - Reference path
425
+ * @param {string} name - Reference name
426
+ * @param {Object} options - Additional options
427
+ * @returns {ContextReference} New context reference
428
+ */
429
+ static create(type, path, name, options = {}) {
430
+ const now = new Date().toISOString();
431
+ const referenceId = this.generateReferenceId();
432
+
433
+ return {
434
+ id: referenceId,
435
+ type,
436
+ path,
437
+ name,
438
+ content: options.content || null,
439
+ metadata: this.createDefaultMetadata(type, path, options.metadata),
440
+ scope: options.scope || {},
441
+ createdAt: now,
442
+ lastAccessed: null,
443
+ lastModified: options.lastModified || null,
444
+ isValid: true,
445
+ invalidReason: null,
446
+ accessCount: 0,
447
+ tags: options.tags || {}
448
+ };
449
+ }
450
+
451
+ /**
452
+ * Create a file reference
453
+ * @param {string} absolutePath - Absolute file path
454
+ * @param {string} relativePath - Relative file path
455
+ * @param {Object} options - Additional options
456
+ * @returns {FileReference} File reference
457
+ */
458
+ static createFileReference(absolutePath, relativePath, options = {}) {
459
+ const name = options.name || this.extractFileName(absolutePath);
460
+ const extension = this.extractFileExtension(absolutePath);
461
+
462
+ const reference = this.create(CONTEXT_REFERENCE_TYPES.FILE, relativePath, name, options);
463
+
464
+ return {
465
+ ...reference,
466
+ absolutePath,
467
+ relativePath,
468
+ extension,
469
+ exists: options.exists !== undefined ? options.exists : true,
470
+ stats: options.stats || null,
471
+ gitStatus: options.gitStatus || null,
472
+ dependencies: options.dependencies || null
473
+ };
474
+ }
475
+
476
+ /**
477
+ * Create a selection reference
478
+ * @param {string} sourceFile - Source file path
479
+ * @param {string} selectedText - Selected text
480
+ * @param {Object} scope - Selection scope
481
+ * @param {Object} options - Additional options
482
+ * @returns {SelectionReference} Selection reference
483
+ */
484
+ static createSelectionReference(sourceFile, selectedText, scope, options = {}) {
485
+ const name = options.name || this.generateSelectionName(sourceFile, scope);
486
+
487
+ const reference = this.create(CONTEXT_REFERENCE_TYPES.SELECTION, sourceFile, name, {
488
+ ...options,
489
+ scope,
490
+ content: selectedText
491
+ });
492
+
493
+ return {
494
+ ...reference,
495
+ sourceFile,
496
+ selectedText,
497
+ syntax: options.syntax || null,
498
+ context: options.context || null,
499
+ purpose: options.purpose || null
500
+ };
501
+ }
502
+
503
+ /**
504
+ * Create a directory reference
505
+ * @param {string} absolutePath - Absolute directory path
506
+ * @param {string} relativePath - Relative directory path
507
+ * @param {Object} options - Additional options
508
+ * @returns {DirectoryReference} Directory reference
509
+ */
510
+ static createDirectoryReference(absolutePath, relativePath, options = {}) {
511
+ const name = options.name || this.extractDirectoryName(absolutePath);
512
+
513
+ const reference = this.create(CONTEXT_REFERENCE_TYPES.DIRECTORY, relativePath, name, options);
514
+
515
+ return {
516
+ ...reference,
517
+ absolutePath,
518
+ relativePath,
519
+ tree: options.tree || null,
520
+ fileCount: options.fileCount || null,
521
+ totalSize: options.totalSize || null,
522
+ fileTypes: options.fileTypes || null
523
+ };
524
+ }
525
+
526
+ /**
527
+ * Create a component reference
528
+ * @param {string} componentType - Component type
529
+ * @param {string} path - Component path/identifier
530
+ * @param {string} name - Component name
531
+ * @param {Object} options - Additional options
532
+ * @returns {ComponentReference} Component reference
533
+ */
534
+ static createComponentReference(componentType, path, name, options = {}) {
535
+ const reference = this.create(CONTEXT_REFERENCE_TYPES.COMPONENT, path, name, options);
536
+
537
+ return {
538
+ ...reference,
539
+ componentType,
540
+ sourceFile: options.sourceFile || null,
541
+ properties: options.properties || null,
542
+ dependencies: options.dependencies || null,
543
+ documentation: options.documentation || null
544
+ };
545
+ }
546
+
547
+ /**
548
+ * Create default metadata for reference type
549
+ * @param {string} type - Reference type
550
+ * @param {string} path - Reference path
551
+ * @param {Object} overrides - Metadata overrides
552
+ * @returns {ReferenceMetadata} Default metadata
553
+ */
554
+ static createDefaultMetadata(type, path, overrides = {}) {
555
+ const metadata = {
556
+ language: null,
557
+ encoding: 'utf-8',
558
+ size: null,
559
+ mimeType: null,
560
+ checksum: null,
561
+ keywords: [],
562
+ description: '',
563
+ customFields: {},
564
+ icon: this.getDefaultIcon(type, path),
565
+ permissions: {},
566
+ ...overrides
567
+ };
568
+
569
+ // Set language for file references
570
+ if (type === CONTEXT_REFERENCE_TYPES.FILE) {
571
+ const extension = this.extractFileExtension(path);
572
+ metadata.language = this.getLanguageFromExtension(extension);
573
+ metadata.mimeType = this.getMimeTypeFromExtension(extension);
574
+ }
575
+
576
+ return metadata;
577
+ }
578
+
579
+ /**
580
+ * Generate unique reference ID
581
+ * @returns {string} Unique reference ID
582
+ */
583
+ static generateReferenceId() {
584
+ const timestamp = Date.now().toString(36);
585
+ const random = Math.random().toString(36).substr(2, 9);
586
+ return `ref_${timestamp}_${random}`;
587
+ }
588
+
589
+ /**
590
+ * Extract file name from path
591
+ * @param {string} path - File path
592
+ * @returns {string} File name
593
+ */
594
+ static extractFileName(path) {
595
+ return path.split(/[/\\]/).pop() || path;
596
+ }
597
+
598
+ /**
599
+ * Extract directory name from path
600
+ * @param {string} path - Directory path
601
+ * @returns {string} Directory name
602
+ */
603
+ static extractDirectoryName(path) {
604
+ const parts = path.split(/[/\\]/).filter(Boolean);
605
+ return parts[parts.length - 1] || 'Root';
606
+ }
607
+
608
+ /**
609
+ * Extract file extension from path
610
+ * @param {string} path - File path
611
+ * @returns {string} File extension
612
+ */
613
+ static extractFileExtension(path) {
614
+ const fileName = this.extractFileName(path);
615
+ const lastDot = fileName.lastIndexOf('.');
616
+ return lastDot !== -1 ? fileName.substring(lastDot) : '';
617
+ }
618
+
619
+ /**
620
+ * Generate selection name from file and scope
621
+ * @param {string} sourceFile - Source file path
622
+ * @param {Object} scope - Selection scope
623
+ * @returns {string} Selection name
624
+ */
625
+ static generateSelectionName(sourceFile, scope) {
626
+ const fileName = this.extractFileName(sourceFile);
627
+
628
+ if (scope.startLine && scope.endLine) {
629
+ if (scope.startLine === scope.endLine) {
630
+ return `${fileName}:${scope.startLine}`;
631
+ } else {
632
+ return `${fileName}:${scope.startLine}-${scope.endLine}`;
633
+ }
634
+ }
635
+
636
+ if (scope.functionName) {
637
+ return `${fileName}:${scope.functionName}()`;
638
+ }
639
+
640
+ if (scope.className) {
641
+ return `${fileName}:${scope.className}`;
642
+ }
643
+
644
+ return `${fileName} (selection)`;
645
+ }
646
+
647
+ /**
648
+ * Get default icon for reference type and path
649
+ * @param {string} type - Reference type
650
+ * @param {string} path - Reference path
651
+ * @returns {string} Icon identifier
652
+ */
653
+ static getDefaultIcon(type, path) {
654
+ if (type === CONTEXT_REFERENCE_TYPES.FILE) {
655
+ const extension = this.extractFileExtension(path);
656
+ return FILE_ICONS[extension] || CONTEXT_ICONS.DEFAULT;
657
+ }
658
+
659
+ return CONTEXT_ICONS[type] || CONTEXT_ICONS.DEFAULT;
660
+ }
661
+
662
+ /**
663
+ * Get programming language from file extension
664
+ * @param {string} extension - File extension
665
+ * @returns {string|null} Programming language
666
+ */
667
+ static getLanguageFromExtension(extension) {
668
+ const languageMap = {
669
+ '.js': 'javascript',
670
+ '.jsx': 'javascript',
671
+ '.ts': 'typescript',
672
+ '.tsx': 'typescript',
673
+ '.py': 'python',
674
+ '.java': 'java',
675
+ '.cpp': 'cpp',
676
+ '.c': 'c',
677
+ '.cs': 'csharp',
678
+ '.php': 'php',
679
+ '.rb': 'ruby',
680
+ '.go': 'go',
681
+ '.rs': 'rust',
682
+ '.html': 'html',
683
+ '.css': 'css',
684
+ '.scss': 'scss',
685
+ '.json': 'json',
686
+ '.yml': 'yaml',
687
+ '.yaml': 'yaml',
688
+ '.xml': 'xml',
689
+ '.sql': 'sql',
690
+ '.md': 'markdown'
691
+ };
692
+
693
+ return languageMap[extension.toLowerCase()] || null;
694
+ }
695
+
696
+ /**
697
+ * Get MIME type from file extension
698
+ * @param {string} extension - File extension
699
+ * @returns {string|null} MIME type
700
+ */
701
+ static getMimeTypeFromExtension(extension) {
702
+ const mimeMap = {
703
+ '.js': 'application/javascript',
704
+ '.jsx': 'application/javascript',
705
+ '.ts': 'application/typescript',
706
+ '.tsx': 'application/typescript',
707
+ '.py': 'text/x-python',
708
+ '.java': 'text/x-java-source',
709
+ '.cpp': 'text/x-c++src',
710
+ '.c': 'text/x-csrc',
711
+ '.cs': 'text/x-csharp',
712
+ '.php': 'application/x-php',
713
+ '.rb': 'application/x-ruby',
714
+ '.go': 'text/x-go',
715
+ '.rs': 'text/x-rust',
716
+ '.html': 'text/html',
717
+ '.css': 'text/css',
718
+ '.scss': 'text/x-scss',
719
+ '.json': 'application/json',
720
+ '.yml': 'application/x-yaml',
721
+ '.yaml': 'application/x-yaml',
722
+ '.xml': 'application/xml',
723
+ '.sql': 'application/sql',
724
+ '.md': 'text/markdown',
725
+ '.txt': 'text/plain'
726
+ };
727
+
728
+ return mimeMap[extension.toLowerCase()] || 'text/plain';
729
+ }
730
+ }
731
+
732
+ /**
733
+ * Context Reference utility functions
734
+ */
735
+ export class ContextReferenceUtils {
736
+ /**
737
+ * Check if reference is still valid
738
+ * @param {ContextReference} reference - Reference to check
739
+ * @returns {boolean} True if valid
740
+ */
741
+ static isValid(reference) {
742
+ return reference.isValid && !reference.invalidReason;
743
+ }
744
+
745
+ /**
746
+ * Mark reference as accessed
747
+ * @param {ContextReference} reference - Reference to mark
748
+ * @returns {ContextReference} Updated reference
749
+ */
750
+ static markAccessed(reference) {
751
+ return {
752
+ ...reference,
753
+ lastAccessed: new Date().toISOString(),
754
+ accessCount: reference.accessCount + 1
755
+ };
756
+ }
757
+
758
+ /**
759
+ * Mark reference as invalid
760
+ * @param {ContextReference} reference - Reference to invalidate
761
+ * @param {string} reason - Reason for invalidation
762
+ * @returns {ContextReference} Updated reference
763
+ */
764
+ static markInvalid(reference, reason) {
765
+ return {
766
+ ...reference,
767
+ isValid: false,
768
+ invalidReason: reason
769
+ };
770
+ }
771
+
772
+ /**
773
+ * Get reference display name with context
774
+ * @param {ContextReference} reference - Reference to format
775
+ * @returns {string} Display name
776
+ */
777
+ static getDisplayName(reference) {
778
+ if (reference.type === CONTEXT_REFERENCE_TYPES.SELECTION && reference.scope) {
779
+ return ContextReferenceFactory.generateSelectionName(reference.path, reference.scope);
780
+ }
781
+
782
+ return reference.name;
783
+ }
784
+
785
+ /**
786
+ * Get reference description
787
+ * @param {ContextReference} reference - Reference to describe
788
+ * @returns {string} Description
789
+ */
790
+ static getDescription(reference) {
791
+ if (reference.metadata?.description) {
792
+ return reference.metadata.description;
793
+ }
794
+
795
+ switch (reference.type) {
796
+ case CONTEXT_REFERENCE_TYPES.FILE:
797
+ return `File: ${reference.path}`;
798
+ case CONTEXT_REFERENCE_TYPES.DIRECTORY:
799
+ return `Directory: ${reference.path}`;
800
+ case CONTEXT_REFERENCE_TYPES.SELECTION:
801
+ return `Selection from ${reference.path}`;
802
+ case CONTEXT_REFERENCE_TYPES.COMPONENT:
803
+ return `Component: ${reference.name}`;
804
+ default:
805
+ return reference.path;
806
+ }
807
+ }
808
+
809
+ /**
810
+ * Calculate reference relevance score
811
+ * @param {ContextReference} reference - Reference to score
812
+ * @param {Object} context - Scoring context
813
+ * @returns {number} Relevance score (0-1)
814
+ */
815
+ static calculateRelevance(reference, context = {}) {
816
+ let score = 0.5; // Base score
817
+
818
+ // Recent access bonus
819
+ if (reference.lastAccessed) {
820
+ const daysSinceAccess = (Date.now() - new Date(reference.lastAccessed)) / (1000 * 60 * 60 * 24);
821
+ score += Math.max(0, 0.2 * (1 - daysSinceAccess / 30)); // Decay over 30 days
822
+ }
823
+
824
+ // Access frequency bonus
825
+ if (reference.accessCount > 0) {
826
+ score += Math.min(0.2, reference.accessCount * 0.01);
827
+ }
828
+
829
+ // Type-specific scoring
830
+ switch (reference.type) {
831
+ case CONTEXT_REFERENCE_TYPES.FILE:
832
+ if (context.fileTypes && reference.metadata?.language) {
833
+ if (context.fileTypes.includes(reference.metadata.language)) {
834
+ score += 0.2;
835
+ }
836
+ }
837
+ break;
838
+ case CONTEXT_REFERENCE_TYPES.SELECTION:
839
+ score += 0.1; // Selections are often more relevant
840
+ break;
841
+ }
842
+
843
+ // Keyword matching
844
+ if (context.keywords && reference.metadata?.keywords) {
845
+ const matches = context.keywords.filter(k =>
846
+ reference.metadata.keywords.includes(k)
847
+ ).length;
848
+ score += Math.min(0.3, matches * 0.1);
849
+ }
850
+
851
+ // Invalid references get heavy penalty
852
+ if (!reference.isValid) {
853
+ score *= 0.1;
854
+ }
855
+
856
+ return Math.min(1, Math.max(0, score));
857
+ }
858
+
859
+ /**
860
+ * Group references by type
861
+ * @param {ContextReference[]} references - References to group
862
+ * @returns {Object} Grouped references
863
+ */
864
+ static groupByType(references) {
865
+ return references.reduce((groups, reference) => {
866
+ const type = reference.type;
867
+ if (!groups[type]) {
868
+ groups[type] = [];
869
+ }
870
+ groups[type].push(reference);
871
+ return groups;
872
+ }, {});
873
+ }
874
+
875
+ /**
876
+ * Sort references by relevance
877
+ * @param {ContextReference[]} references - References to sort
878
+ * @param {Object} context - Sorting context
879
+ * @returns {ContextReference[]} Sorted references
880
+ */
881
+ static sortByRelevance(references, context = {}) {
882
+ return [...references].sort((a, b) => {
883
+ const scoreA = this.calculateRelevance(a, context);
884
+ const scoreB = this.calculateRelevance(b, context);
885
+ return scoreB - scoreA;
886
+ });
887
+ }
888
+
889
+ /**
890
+ * Filter references by criteria
891
+ * @param {ContextReference[]} references - References to filter
892
+ * @param {Object} criteria - Filter criteria
893
+ * @returns {ContextReference[]} Filtered references
894
+ */
895
+ static filter(references, criteria = {}) {
896
+ return references.filter(reference => {
897
+ // Type filter
898
+ if (criteria.types && !criteria.types.includes(reference.type)) {
899
+ return false;
900
+ }
901
+
902
+ // Valid filter
903
+ if (criteria.validOnly && !reference.isValid) {
904
+ return false;
905
+ }
906
+
907
+ // Language filter
908
+ if (criteria.languages && reference.metadata?.language) {
909
+ if (!criteria.languages.includes(reference.metadata.language)) {
910
+ return false;
911
+ }
912
+ }
913
+
914
+ // Path filter
915
+ if (criteria.pathPattern) {
916
+ const regex = new RegExp(criteria.pathPattern, 'i');
917
+ if (!regex.test(reference.path)) {
918
+ return false;
919
+ }
920
+ }
921
+
922
+ // Keyword filter
923
+ if (criteria.keywords && reference.metadata?.keywords) {
924
+ const hasKeyword = criteria.keywords.some(keyword =>
925
+ reference.metadata.keywords.includes(keyword)
926
+ );
927
+ if (!hasKeyword) {
928
+ return false;
929
+ }
930
+ }
931
+
932
+ // Date range filter
933
+ if (criteria.createdAfter) {
934
+ if (new Date(reference.createdAt) < new Date(criteria.createdAfter)) {
935
+ return false;
936
+ }
937
+ }
938
+
939
+ if (criteria.createdBefore) {
940
+ if (new Date(reference.createdAt) > new Date(criteria.createdBefore)) {
941
+ return false;
942
+ }
943
+ }
944
+
945
+ return true;
946
+ });
947
+ }
948
+
949
+ /**
950
+ * Format reference for display
951
+ * @param {ContextReference} reference - Reference to format
952
+ * @returns {Object} Formatted reference
953
+ */
954
+ static formatForDisplay(reference) {
955
+ return {
956
+ id: reference.id,
957
+ type: reference.type,
958
+ name: this.getDisplayName(reference),
959
+ description: this.getDescription(reference),
960
+ path: reference.path,
961
+ icon: reference.metadata?.icon || CONTEXT_ICONS[reference.type] || CONTEXT_ICONS.DEFAULT,
962
+ isValid: reference.isValid,
963
+ lastAccessed: reference.lastAccessed,
964
+ accessCount: reference.accessCount,
965
+ size: reference.metadata?.size || null,
966
+ language: reference.metadata?.language || null
967
+ };
968
+ }
969
+ }
970
+
971
+ export default {
972
+ ContextReferenceValidator,
973
+ ContextReferenceFactory,
974
+ ContextReferenceUtils
972
975
  };