@jagilber-org/index-server 1.22.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 (372) hide show
  1. package/CHANGELOG.md +1354 -0
  2. package/CODE_OF_CONDUCT.md +49 -0
  3. package/CONTRIBUTING.md +99 -0
  4. package/LICENSE +21 -0
  5. package/README.md +228 -0
  6. package/SECURITY.md +50 -0
  7. package/dist/config/configUtils.d.ts +11 -0
  8. package/dist/config/configUtils.js +87 -0
  9. package/dist/config/dashboardConfig.d.ts +46 -0
  10. package/dist/config/dashboardConfig.js +67 -0
  11. package/dist/config/defaultValues.d.ts +63 -0
  12. package/dist/config/defaultValues.js +72 -0
  13. package/dist/config/dirConstants.d.ts +18 -0
  14. package/dist/config/dirConstants.js +29 -0
  15. package/dist/config/featureConfig.d.ts +61 -0
  16. package/dist/config/featureConfig.js +121 -0
  17. package/dist/config/runtimeConfig.d.ts +151 -0
  18. package/dist/config/runtimeConfig.js +380 -0
  19. package/dist/config/serverConfig.d.ts +90 -0
  20. package/dist/config/serverConfig.js +167 -0
  21. package/dist/dashboard/analytics/AnalyticsEngine.d.ts +142 -0
  22. package/dist/dashboard/analytics/AnalyticsEngine.js +373 -0
  23. package/dist/dashboard/analytics/BusinessIntelligence.d.ts +187 -0
  24. package/dist/dashboard/analytics/BusinessIntelligence.js +594 -0
  25. package/dist/dashboard/client/admin.html +2175 -0
  26. package/dist/dashboard/client/chunks/mermaid-layout-elk.esm.min/chunk-SP2CHFBE.mjs +1 -0
  27. package/dist/dashboard/client/chunks/mermaid-layout-elk.esm.min/render-T6MDALS3.mjs +27 -0
  28. package/dist/dashboard/client/css/admin.css +1587 -0
  29. package/dist/dashboard/client/js/admin.auth.js +179 -0
  30. package/dist/dashboard/client/js/admin.boot.js +359 -0
  31. package/dist/dashboard/client/js/admin.config.js +196 -0
  32. package/dist/dashboard/client/js/admin.embeddings.js +426 -0
  33. package/dist/dashboard/client/js/admin.graph.js +615 -0
  34. package/dist/dashboard/client/js/admin.instances.js +120 -0
  35. package/dist/dashboard/client/js/admin.instructions.js +579 -0
  36. package/dist/dashboard/client/js/admin.logs.js +113 -0
  37. package/dist/dashboard/client/js/admin.maintenance.js +393 -0
  38. package/dist/dashboard/client/js/admin.messaging.js +636 -0
  39. package/dist/dashboard/client/js/admin.monitor.js +184 -0
  40. package/dist/dashboard/client/js/admin.overview.js +221 -0
  41. package/dist/dashboard/client/js/admin.performance.js +61 -0
  42. package/dist/dashboard/client/js/admin.sessions.js +292 -0
  43. package/dist/dashboard/client/js/admin.sqlite.js +373 -0
  44. package/dist/dashboard/client/js/admin.utils.js +49 -0
  45. package/dist/dashboard/client/js/chart.umd.js +14 -0
  46. package/dist/dashboard/client/js/elk.bundled.js +6696 -0
  47. package/dist/dashboard/client/js/marked.umd.js +74 -0
  48. package/dist/dashboard/client/js/mermaid.min.js +3022 -0
  49. package/dist/dashboard/client/mermaid-layout-elk.esm.min.mjs +1 -0
  50. package/dist/dashboard/export/DataExporter.d.ts +169 -0
  51. package/dist/dashboard/export/DataExporter.js +737 -0
  52. package/dist/dashboard/export/exporters/csvExporter.d.ts +11 -0
  53. package/dist/dashboard/export/exporters/csvExporter.js +47 -0
  54. package/dist/dashboard/export/exporters/exportTypes.d.ts +89 -0
  55. package/dist/dashboard/export/exporters/exportTypes.js +5 -0
  56. package/dist/dashboard/export/exporters/jsonExporter.d.ts +7 -0
  57. package/dist/dashboard/export/exporters/jsonExporter.js +23 -0
  58. package/dist/dashboard/export/exporters/xmlExporter.d.ts +17 -0
  59. package/dist/dashboard/export/exporters/xmlExporter.js +176 -0
  60. package/dist/dashboard/integration/APIIntegration.d.ts +41 -0
  61. package/dist/dashboard/integration/APIIntegration.js +95 -0
  62. package/dist/dashboard/security/SecurityMonitor.d.ts +167 -0
  63. package/dist/dashboard/security/SecurityMonitor.js +560 -0
  64. package/dist/dashboard/server/AdminPanel.d.ts +195 -0
  65. package/dist/dashboard/server/AdminPanel.js +861 -0
  66. package/dist/dashboard/server/AdminPanelConfig.d.ts +42 -0
  67. package/dist/dashboard/server/AdminPanelConfig.js +80 -0
  68. package/dist/dashboard/server/AdminPanelState.d.ts +47 -0
  69. package/dist/dashboard/server/AdminPanelState.js +215 -0
  70. package/dist/dashboard/server/ApiRoutes.d.ts +17 -0
  71. package/dist/dashboard/server/ApiRoutes.js +184 -0
  72. package/dist/dashboard/server/DashboardServer.d.ts +49 -0
  73. package/dist/dashboard/server/DashboardServer.js +160 -0
  74. package/dist/dashboard/server/FileMetricsStorage.d.ts +49 -0
  75. package/dist/dashboard/server/FileMetricsStorage.js +196 -0
  76. package/dist/dashboard/server/HttpTransport.d.ts +23 -0
  77. package/dist/dashboard/server/HttpTransport.js +116 -0
  78. package/dist/dashboard/server/InstanceManager.d.ts +53 -0
  79. package/dist/dashboard/server/InstanceManager.js +295 -0
  80. package/dist/dashboard/server/KnowledgeStore.d.ts +35 -0
  81. package/dist/dashboard/server/KnowledgeStore.js +105 -0
  82. package/dist/dashboard/server/LeaderElection.d.ts +81 -0
  83. package/dist/dashboard/server/LeaderElection.js +268 -0
  84. package/dist/dashboard/server/MetricsCollector.d.ts +200 -0
  85. package/dist/dashboard/server/MetricsCollector.js +810 -0
  86. package/dist/dashboard/server/SessionPersistenceManager.d.ts +88 -0
  87. package/dist/dashboard/server/SessionPersistenceManager.js +458 -0
  88. package/dist/dashboard/server/ThinClient.d.ts +64 -0
  89. package/dist/dashboard/server/ThinClient.js +237 -0
  90. package/dist/dashboard/server/WebSocketManager.d.ts +161 -0
  91. package/dist/dashboard/server/WebSocketManager.js +448 -0
  92. package/dist/dashboard/server/httpLifecycle.d.ts +17 -0
  93. package/dist/dashboard/server/httpLifecycle.js +35 -0
  94. package/dist/dashboard/server/legacyDashboardHtml.d.ts +9 -0
  95. package/dist/dashboard/server/legacyDashboardHtml.js +618 -0
  96. package/dist/dashboard/server/legacyDashboardStyles.d.ts +5 -0
  97. package/dist/dashboard/server/legacyDashboardStyles.js +490 -0
  98. package/dist/dashboard/server/metricsAggregation.d.ts +252 -0
  99. package/dist/dashboard/server/metricsAggregation.js +210 -0
  100. package/dist/dashboard/server/metricsSerializer.d.ts +25 -0
  101. package/dist/dashboard/server/metricsSerializer.js +195 -0
  102. package/dist/dashboard/server/middleware/ensureLoadedMiddleware.d.ts +25 -0
  103. package/dist/dashboard/server/middleware/ensureLoadedMiddleware.js +24 -0
  104. package/dist/dashboard/server/routes/admin.routes.d.ts +16 -0
  105. package/dist/dashboard/server/routes/admin.routes.js +574 -0
  106. package/dist/dashboard/server/routes/adminAuth.d.ts +4 -0
  107. package/dist/dashboard/server/routes/adminAuth.js +46 -0
  108. package/dist/dashboard/server/routes/alerts.routes.d.ts +7 -0
  109. package/dist/dashboard/server/routes/alerts.routes.js +91 -0
  110. package/dist/dashboard/server/routes/api.feedback.routes.d.ts +73 -0
  111. package/dist/dashboard/server/routes/api.feedback.routes.js +171 -0
  112. package/dist/dashboard/server/routes/api.instructions.routes.d.ts +101 -0
  113. package/dist/dashboard/server/routes/api.instructions.routes.js +213 -0
  114. package/dist/dashboard/server/routes/api.usage.routes.d.ts +57 -0
  115. package/dist/dashboard/server/routes/api.usage.routes.js +374 -0
  116. package/dist/dashboard/server/routes/embeddings.routes.d.ts +6 -0
  117. package/dist/dashboard/server/routes/embeddings.routes.js +246 -0
  118. package/dist/dashboard/server/routes/graph.routes.d.ts +6 -0
  119. package/dist/dashboard/server/routes/graph.routes.js +279 -0
  120. package/dist/dashboard/server/routes/index.d.ts +39 -0
  121. package/dist/dashboard/server/routes/index.js +229 -0
  122. package/dist/dashboard/server/routes/instances.routes.d.ts +6 -0
  123. package/dist/dashboard/server/routes/instances.routes.js +35 -0
  124. package/dist/dashboard/server/routes/instructions.routes.d.ts +8 -0
  125. package/dist/dashboard/server/routes/instructions.routes.js +268 -0
  126. package/dist/dashboard/server/routes/knowledge.routes.d.ts +6 -0
  127. package/dist/dashboard/server/routes/knowledge.routes.js +80 -0
  128. package/dist/dashboard/server/routes/logs.routes.d.ts +6 -0
  129. package/dist/dashboard/server/routes/logs.routes.js +166 -0
  130. package/dist/dashboard/server/routes/messaging.routes.d.ts +16 -0
  131. package/dist/dashboard/server/routes/messaging.routes.js +307 -0
  132. package/dist/dashboard/server/routes/metrics.routes.d.ts +10 -0
  133. package/dist/dashboard/server/routes/metrics.routes.js +335 -0
  134. package/dist/dashboard/server/routes/scripts.routes.d.ts +9 -0
  135. package/dist/dashboard/server/routes/scripts.routes.js +84 -0
  136. package/dist/dashboard/server/routes/sqlite.routes.d.ts +9 -0
  137. package/dist/dashboard/server/routes/sqlite.routes.js +570 -0
  138. package/dist/dashboard/server/routes/status.routes.d.ts +7 -0
  139. package/dist/dashboard/server/routes/status.routes.js +179 -0
  140. package/dist/dashboard/server/routes/synthetic.routes.d.ts +7 -0
  141. package/dist/dashboard/server/routes/synthetic.routes.js +197 -0
  142. package/dist/dashboard/server/routes/tools.routes.d.ts +6 -0
  143. package/dist/dashboard/server/routes/tools.routes.js +47 -0
  144. package/dist/dashboard/server/routes/usage.routes.d.ts +6 -0
  145. package/dist/dashboard/server/routes/usage.routes.js +26 -0
  146. package/dist/dashboard/server/wsInit.d.ts +16 -0
  147. package/dist/dashboard/server/wsInit.js +35 -0
  148. package/dist/externalClientLib.d.ts +1 -0
  149. package/dist/externalClientLib.js +2 -0
  150. package/dist/minimal/index.d.ts +1 -0
  151. package/dist/minimal/index.js +140 -0
  152. package/dist/models/SessionPersistence.d.ts +115 -0
  153. package/dist/models/SessionPersistence.js +66 -0
  154. package/dist/models/instruction.d.ts +46 -0
  155. package/dist/models/instruction.js +2 -0
  156. package/dist/perf/benchmark.d.ts +1 -0
  157. package/dist/perf/benchmark.js +50 -0
  158. package/dist/portableClientWrapper.d.ts +1 -0
  159. package/dist/portableClientWrapper.js +2 -0
  160. package/dist/schemas/index.d.ts +132 -0
  161. package/dist/schemas/index.js +372 -0
  162. package/dist/scripts/runPerformanceBaseline.d.ts +1 -0
  163. package/dist/scripts/runPerformanceBaseline.js +17 -0
  164. package/dist/server/backgroundServicesStartup.d.ts +3 -0
  165. package/dist/server/backgroundServicesStartup.js +51 -0
  166. package/dist/server/handshakeManager.d.ts +25 -0
  167. package/dist/server/handshakeManager.js +470 -0
  168. package/dist/server/index-server.d.ts +38 -0
  169. package/dist/server/index-server.js +620 -0
  170. package/dist/server/multiInstanceStartup.d.ts +6 -0
  171. package/dist/server/multiInstanceStartup.js +132 -0
  172. package/dist/server/registry.d.ts +44 -0
  173. package/dist/server/registry.js +236 -0
  174. package/dist/server/sdkServer.d.ts +8 -0
  175. package/dist/server/sdkServer.js +299 -0
  176. package/dist/server/shutdownGuard.d.ts +41 -0
  177. package/dist/server/shutdownGuard.js +52 -0
  178. package/dist/server/startupDiagnostics.d.ts +2 -0
  179. package/dist/server/startupDiagnostics.js +33 -0
  180. package/dist/server/thin-client.d.ts +22 -0
  181. package/dist/server/thin-client.js +111 -0
  182. package/dist/server/transport.d.ts +41 -0
  183. package/dist/server/transport.js +312 -0
  184. package/dist/server/transportFactory.d.ts +21 -0
  185. package/dist/server/transportFactory.js +429 -0
  186. package/dist/services/atomicFs.d.ts +22 -0
  187. package/dist/services/atomicFs.js +103 -0
  188. package/dist/services/auditLog.d.ts +38 -0
  189. package/dist/services/auditLog.js +142 -0
  190. package/dist/services/autoBackup.d.ts +14 -0
  191. package/dist/services/autoBackup.js +171 -0
  192. package/dist/services/autoSplit.d.ts +32 -0
  193. package/dist/services/autoSplit.js +113 -0
  194. package/dist/services/backupZip.d.ts +25 -0
  195. package/dist/services/backupZip.js +112 -0
  196. package/dist/services/bootstrapGating.d.ts +123 -0
  197. package/dist/services/bootstrapGating.js +221 -0
  198. package/dist/services/canonical.d.ts +23 -0
  199. package/dist/services/canonical.js +65 -0
  200. package/dist/services/categoryRules.d.ts +7 -0
  201. package/dist/services/categoryRules.js +37 -0
  202. package/dist/services/classificationService.d.ts +42 -0
  203. package/dist/services/classificationService.js +168 -0
  204. package/dist/services/embeddingService.d.ts +62 -0
  205. package/dist/services/embeddingService.js +264 -0
  206. package/dist/services/errors.d.ts +22 -0
  207. package/dist/services/errors.js +31 -0
  208. package/dist/services/featureFlags.d.ts +25 -0
  209. package/dist/services/featureFlags.js +89 -0
  210. package/dist/services/features.d.ts +13 -0
  211. package/dist/services/features.js +35 -0
  212. package/dist/services/handlers/instructions.add.d.ts +1 -0
  213. package/dist/services/handlers/instructions.add.js +510 -0
  214. package/dist/services/handlers/instructions.groom.d.ts +1 -0
  215. package/dist/services/handlers/instructions.groom.js +575 -0
  216. package/dist/services/handlers/instructions.import.d.ts +1 -0
  217. package/dist/services/handlers/instructions.import.js +205 -0
  218. package/dist/services/handlers/instructions.patch.d.ts +1 -0
  219. package/dist/services/handlers/instructions.patch.js +121 -0
  220. package/dist/services/handlers/instructions.query.d.ts +159 -0
  221. package/dist/services/handlers/instructions.query.js +469 -0
  222. package/dist/services/handlers/instructions.reload.d.ts +1 -0
  223. package/dist/services/handlers/instructions.reload.js +13 -0
  224. package/dist/services/handlers/instructions.remove.d.ts +1 -0
  225. package/dist/services/handlers/instructions.remove.js +122 -0
  226. package/dist/services/handlers/instructions.shared.d.ts +32 -0
  227. package/dist/services/handlers/instructions.shared.js +91 -0
  228. package/dist/services/handlers.activation.d.ts +1 -0
  229. package/dist/services/handlers.activation.js +203 -0
  230. package/dist/services/handlers.bootstrap.d.ts +1 -0
  231. package/dist/services/handlers.bootstrap.js +38 -0
  232. package/dist/services/handlers.dashboardConfig.d.ts +34 -0
  233. package/dist/services/handlers.dashboardConfig.js +110 -0
  234. package/dist/services/handlers.diagnostics.d.ts +1 -0
  235. package/dist/services/handlers.diagnostics.js +64 -0
  236. package/dist/services/handlers.feedback.d.ts +15 -0
  237. package/dist/services/handlers.feedback.js +389 -0
  238. package/dist/services/handlers.gates.d.ts +1 -0
  239. package/dist/services/handlers.gates.js +47 -0
  240. package/dist/services/handlers.graph.d.ts +53 -0
  241. package/dist/services/handlers.graph.js +231 -0
  242. package/dist/services/handlers.help.d.ts +1 -0
  243. package/dist/services/handlers.help.js +119 -0
  244. package/dist/services/handlers.instructionSchema.d.ts +1 -0
  245. package/dist/services/handlers.instructionSchema.js +227 -0
  246. package/dist/services/handlers.instructions.d.ts +8 -0
  247. package/dist/services/handlers.instructions.js +14 -0
  248. package/dist/services/handlers.instructionsDiagnostics.d.ts +1 -0
  249. package/dist/services/handlers.instructionsDiagnostics.js +14 -0
  250. package/dist/services/handlers.integrity.d.ts +1 -0
  251. package/dist/services/handlers.integrity.js +35 -0
  252. package/dist/services/handlers.manifest.d.ts +1 -0
  253. package/dist/services/handlers.manifest.js +24 -0
  254. package/dist/services/handlers.messaging.d.ts +12 -0
  255. package/dist/services/handlers.messaging.js +203 -0
  256. package/dist/services/handlers.metrics.d.ts +1 -0
  257. package/dist/services/handlers.metrics.js +43 -0
  258. package/dist/services/handlers.promote.d.ts +1 -0
  259. package/dist/services/handlers.promote.js +326 -0
  260. package/dist/services/handlers.prompt.d.ts +1 -0
  261. package/dist/services/handlers.prompt.js +7 -0
  262. package/dist/services/handlers.search.d.ts +69 -0
  263. package/dist/services/handlers.search.js +669 -0
  264. package/dist/services/handlers.testPrimitive.d.ts +1 -0
  265. package/dist/services/handlers.testPrimitive.js +5 -0
  266. package/dist/services/handlers.trace.d.ts +1 -0
  267. package/dist/services/handlers.trace.js +35 -0
  268. package/dist/services/handlers.usage.d.ts +1 -0
  269. package/dist/services/handlers.usage.js +11 -0
  270. package/dist/services/hotScore.d.ts +137 -0
  271. package/dist/services/hotScore.js +244 -0
  272. package/dist/services/indexContext.d.ts +117 -0
  273. package/dist/services/indexContext.js +989 -0
  274. package/dist/services/indexLoader.d.ts +44 -0
  275. package/dist/services/indexLoader.js +920 -0
  276. package/dist/services/indexRepository.d.ts +32 -0
  277. package/dist/services/indexRepository.js +71 -0
  278. package/dist/services/indexingService.d.ts +1 -0
  279. package/dist/services/indexingService.js +2 -0
  280. package/dist/services/instructions.dispatcher.d.ts +1 -0
  281. package/dist/services/instructions.dispatcher.js +231 -0
  282. package/dist/services/logPrefix.d.ts +1 -0
  283. package/dist/services/logPrefix.js +30 -0
  284. package/dist/services/logger.d.ts +52 -0
  285. package/dist/services/logger.js +268 -0
  286. package/dist/services/manifestManager.d.ts +82 -0
  287. package/dist/services/manifestManager.js +200 -0
  288. package/dist/services/messaging/agentMailbox.d.ts +60 -0
  289. package/dist/services/messaging/agentMailbox.js +353 -0
  290. package/dist/services/messaging/messagingPersistence.d.ts +20 -0
  291. package/dist/services/messaging/messagingPersistence.js +111 -0
  292. package/dist/services/messaging/messagingTypes.d.ts +150 -0
  293. package/dist/services/messaging/messagingTypes.js +66 -0
  294. package/dist/services/ownershipService.d.ts +1 -0
  295. package/dist/services/ownershipService.js +36 -0
  296. package/dist/services/performanceBaseline.d.ts +19 -0
  297. package/dist/services/performanceBaseline.js +210 -0
  298. package/dist/services/preflight.d.ts +12 -0
  299. package/dist/services/preflight.js +79 -0
  300. package/dist/services/promptReviewService.d.ts +44 -0
  301. package/dist/services/promptReviewService.js +101 -0
  302. package/dist/services/responseEnvelope.d.ts +6 -0
  303. package/dist/services/responseEnvelope.js +25 -0
  304. package/dist/services/seedBootstrap.d.ts +34 -0
  305. package/dist/services/seedBootstrap.js +259 -0
  306. package/dist/services/storage/factory.d.ts +17 -0
  307. package/dist/services/storage/factory.js +35 -0
  308. package/dist/services/storage/hashUtils.d.ts +11 -0
  309. package/dist/services/storage/hashUtils.js +35 -0
  310. package/dist/services/storage/index.d.ts +12 -0
  311. package/dist/services/storage/index.js +18 -0
  312. package/dist/services/storage/jsonFileStore.d.ts +32 -0
  313. package/dist/services/storage/jsonFileStore.js +241 -0
  314. package/dist/services/storage/migrationEngine.d.ts +35 -0
  315. package/dist/services/storage/migrationEngine.js +93 -0
  316. package/dist/services/storage/sqliteMessageStore.d.ts +53 -0
  317. package/dist/services/storage/sqliteMessageStore.js +146 -0
  318. package/dist/services/storage/sqliteSchema.d.ts +12 -0
  319. package/dist/services/storage/sqliteSchema.js +123 -0
  320. package/dist/services/storage/sqliteStore.d.ts +42 -0
  321. package/dist/services/storage/sqliteStore.js +361 -0
  322. package/dist/services/storage/sqliteUsageStore.d.ts +35 -0
  323. package/dist/services/storage/sqliteUsageStore.js +94 -0
  324. package/dist/services/storage/types.d.ts +171 -0
  325. package/dist/services/storage/types.js +12 -0
  326. package/dist/services/toolHandlers.d.ts +23 -0
  327. package/dist/services/toolHandlers.js +50 -0
  328. package/dist/services/toolRegistry.d.ts +20 -0
  329. package/dist/services/toolRegistry.js +490 -0
  330. package/dist/services/toolRegistry.zod.d.ts +10 -0
  331. package/dist/services/toolRegistry.zod.js +325 -0
  332. package/dist/services/tracing.d.ts +26 -0
  333. package/dist/services/tracing.js +260 -0
  334. package/dist/services/usageBuckets.d.ts +161 -0
  335. package/dist/services/usageBuckets.js +364 -0
  336. package/dist/services/validationService.d.ts +38 -0
  337. package/dist/services/validationService.js +125 -0
  338. package/dist/utils/BufferRing.d.ts +203 -0
  339. package/dist/utils/BufferRing.js +551 -0
  340. package/dist/utils/BufferRingExamples.d.ts +55 -0
  341. package/dist/utils/BufferRingExamples.js +188 -0
  342. package/dist/utils/envUtils.d.ts +42 -0
  343. package/dist/utils/envUtils.js +80 -0
  344. package/dist/utils/memoryMonitor.d.ts +83 -0
  345. package/dist/utils/memoryMonitor.js +275 -0
  346. package/dist/versioning/schemaVersion.d.ts +6 -0
  347. package/dist/versioning/schemaVersion.js +94 -0
  348. package/package.json +139 -0
  349. package/schemas/README.md +13 -0
  350. package/schemas/feedback-entry.schema.json +27 -0
  351. package/schemas/graph-export-v2.schema.json +60 -0
  352. package/schemas/index-server.code-schema.json +40670 -0
  353. package/schemas/instruction.schema.json +262 -0
  354. package/schemas/json-schema/SessionPersistence-persisted-admin-session.schema.json +54 -0
  355. package/schemas/json-schema/SessionPersistence-persisted-session-history-entry.schema.json +51 -0
  356. package/schemas/json-schema/SessionPersistence-persisted-web-socket-connection.schema.json +54 -0
  357. package/schemas/json-schema/SessionPersistence-session-persistence-config.schema.json +110 -0
  358. package/schemas/json-schema/SessionPersistence-session-persistence-data.schema.json +229 -0
  359. package/schemas/json-schema/SessionPersistence-session-persistence-manifest.schema.json +109 -0
  360. package/schemas/json-schema/SessionPersistence-session-persistence-metadata.schema.json +55 -0
  361. package/schemas/json-schema/instruction-audience-scope.schema.json +14 -0
  362. package/schemas/json-schema/instruction-content-type.schema.json +17 -0
  363. package/schemas/json-schema/instruction-instruction-entry.schema.json +210 -0
  364. package/schemas/json-schema/instruction-requirement-level.schema.json +16 -0
  365. package/schemas/manifest.json +78 -0
  366. package/schemas/manifest.schema.json +33 -0
  367. package/schemas/usage-batch.schema.json +16 -0
  368. package/schemas/usage-buckets.schema.json +30 -0
  369. package/schemas/usage-event.schema.json +17 -0
  370. package/scripts/copy-dashboard-assets.mjs +170 -0
  371. package/scripts/dist/README.md +15 -0
  372. package/scripts/setup-hooks.cjs +28 -0
@@ -0,0 +1,560 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SecurityMonitor = void 0;
7
+ exports.getSecurityMonitor = getSecurityMonitor;
8
+ /**
9
+ * SecurityMonitor - Phase 4 Security & Performance Monitoring
10
+ *
11
+ * Advanced security monitoring and performance analytics:
12
+ * - Real-time threat detection and alerting
13
+ * - Performance bottleneck identification
14
+ * - Resource usage monitoring
15
+ * - Security audit logging
16
+ * - Automated response mechanisms
17
+ *
18
+ * PH-3 compliance: All real user identifiers (IPs, usernames) are anonymized
19
+ * (SHA-256 hashed, first 16 hex chars) before storage or logging.
20
+ */
21
+ const crypto_1 = __importDefault(require("crypto"));
22
+ const logger_js_1 = require("../../services/logger.js");
23
+ class SecurityMonitor {
24
+ threats = new Map();
25
+ performanceMetrics = new Map();
26
+ securityRules = new Map();
27
+ monitoringInterval = null;
28
+ alertCallbacks = [];
29
+ constructor() {
30
+ this.initializeSecurityRules();
31
+ this.startMonitoring();
32
+ }
33
+ /**
34
+ * Anonymize a real user identifier (IP, username, etc.) for PH-3 compliance.
35
+ * Returns the first 16 hex characters of the SHA-256 hash of the identifier.
36
+ * @param identifier - Raw user identifier to anonymize
37
+ * @returns Anonymized identifier string (not reversible)
38
+ */
39
+ anonymize(identifier) {
40
+ return crypto_1.default.createHash('sha256').update(identifier, 'utf8').digest('hex').slice(0, 16);
41
+ }
42
+ /**
43
+ * Initialize default security rules
44
+ */
45
+ initializeSecurityRules() {
46
+ const defaultRules = [
47
+ {
48
+ id: 'rate_limit_api',
49
+ name: 'API Rate Limiting',
50
+ type: 'rate_limit',
51
+ enabled: true,
52
+ config: {
53
+ maxRequests: 100,
54
+ windowMs: 60000, // 1 minute
55
+ blacklistDuration: 300000 // 5 minutes
56
+ },
57
+ triggerCount: 0
58
+ },
59
+ {
60
+ id: 'suspicious_patterns',
61
+ name: 'Suspicious Activity Detection',
62
+ type: 'pattern_detection',
63
+ enabled: true,
64
+ config: {
65
+ patterns: [
66
+ 'SELECT.*FROM.*WHERE.*1=1',
67
+ '<script>.*</script>',
68
+ '../../../etc/passwd',
69
+ 'UNION.*SELECT.*FROM'
70
+ ],
71
+ caseSensitive: false
72
+ },
73
+ triggerCount: 0
74
+ },
75
+ {
76
+ id: 'authentication_anomaly',
77
+ name: 'Authentication Anomaly Detection',
78
+ type: 'anomaly_detection',
79
+ enabled: true,
80
+ config: {
81
+ maxFailedAttempts: 5,
82
+ timeWindow: 300000, // 5 minutes
83
+ lockoutDuration: 900000 // 15 minutes
84
+ },
85
+ triggerCount: 0
86
+ }
87
+ ];
88
+ defaultRules.forEach(rule => {
89
+ this.securityRules.set(rule.id, rule);
90
+ });
91
+ }
92
+ /**
93
+ * Start continuous monitoring
94
+ */
95
+ startMonitoring() {
96
+ this.monitoringInterval = setInterval(() => {
97
+ this.collectPerformanceMetrics();
98
+ this.analyzeSecurityThreats();
99
+ this.cleanupOldData();
100
+ }, 5000); // Monitor every 5 seconds
101
+ }
102
+ /**
103
+ * Stop monitoring
104
+ */
105
+ stopMonitoring() {
106
+ if (this.monitoringInterval) {
107
+ clearInterval(this.monitoringInterval);
108
+ this.monitoringInterval = null;
109
+ }
110
+ }
111
+ /**
112
+ * Collect system performance metrics
113
+ */
114
+ collectPerformanceMetrics() {
115
+ const timestamp = Date.now();
116
+ // CPU Usage
117
+ this.addPerformanceMetric({
118
+ id: `cpu_${timestamp}`,
119
+ type: 'cpu',
120
+ value: this.getCPUUsage(),
121
+ unit: 'percentage',
122
+ timestamp,
123
+ threshold: { warning: 70, critical: 90 },
124
+ trend: 'stable'
125
+ });
126
+ // Memory Usage
127
+ const memoryUsage = process.memoryUsage();
128
+ this.addPerformanceMetric({
129
+ id: `memory_${timestamp}`,
130
+ type: 'memory',
131
+ value: (memoryUsage.heapUsed / memoryUsage.heapTotal) * 100,
132
+ unit: 'percentage',
133
+ timestamp,
134
+ threshold: { warning: 80, critical: 95 },
135
+ trend: 'stable'
136
+ });
137
+ // API Latency (simulated)
138
+ this.addPerformanceMetric({
139
+ id: `api_latency_${timestamp}`,
140
+ type: 'api_latency',
141
+ value: this.getAverageAPILatency(),
142
+ unit: 'milliseconds',
143
+ timestamp,
144
+ threshold: { warning: 500, critical: 1000 },
145
+ trend: 'stable'
146
+ });
147
+ }
148
+ /**
149
+ * Add performance metric and analyze trends
150
+ */
151
+ addPerformanceMetric(metric) {
152
+ const metricType = metric.type;
153
+ if (!this.performanceMetrics.has(metricType)) {
154
+ this.performanceMetrics.set(metricType, []);
155
+ }
156
+ const metrics = this.performanceMetrics.get(metricType);
157
+ metrics.push(metric);
158
+ // Keep only last 100 metrics per type
159
+ if (metrics.length > 100) {
160
+ metrics.splice(0, metrics.length - 100);
161
+ }
162
+ // Analyze trend
163
+ if (metrics.length >= 3) {
164
+ const recent = metrics.slice(-3);
165
+ const values = recent.map(m => m.value);
166
+ metric.trend = this.calculateTrend(values);
167
+ }
168
+ // Check thresholds and create alerts
169
+ this.checkPerformanceThresholds(metric);
170
+ }
171
+ /**
172
+ * Calculate trend from values
173
+ */
174
+ calculateTrend(values) {
175
+ if (values.length < 2)
176
+ return 'stable';
177
+ const first = values[0];
178
+ const last = values[values.length - 1];
179
+ const change = Math.abs(last - first) / first;
180
+ if (change < 0.05)
181
+ return 'stable'; // Less than 5% change
182
+ return last > first ? 'increasing' : 'decreasing';
183
+ }
184
+ /**
185
+ * Check performance thresholds and create alerts
186
+ */
187
+ checkPerformanceThresholds(metric) {
188
+ let severity = null;
189
+ if (metric.value >= metric.threshold.critical) {
190
+ severity = 'critical';
191
+ }
192
+ else if (metric.value >= metric.threshold.warning) {
193
+ severity = 'high';
194
+ }
195
+ if (severity) {
196
+ const threat = {
197
+ id: `perf_${metric.type}_${Date.now()}`,
198
+ type: 'suspicious_activity',
199
+ severity,
200
+ source: 'performance_monitor',
201
+ timestamp: metric.timestamp,
202
+ details: {
203
+ metricType: metric.type,
204
+ value: metric.value,
205
+ unit: metric.unit,
206
+ threshold: metric.threshold,
207
+ trend: metric.trend
208
+ },
209
+ status: 'active'
210
+ };
211
+ this.reportThreat(threat);
212
+ }
213
+ }
214
+ /**
215
+ * Analyze current security threats
216
+ */
217
+ analyzeSecurityThreats() {
218
+ // Check for patterns in recent activity
219
+ this.detectAnomalousPatterns();
220
+ // Check rate limiting violations
221
+ this.checkRateLimits();
222
+ // Validate authentication attempts
223
+ this.validateAuthenticationAttempts();
224
+ }
225
+ /**
226
+ * Detect anomalous patterns in system activity
227
+ */
228
+ detectAnomalousPatterns() {
229
+ const rule = this.securityRules.get('suspicious_patterns');
230
+ if (!rule || !rule.enabled)
231
+ return;
232
+ const patterns = rule.config.patterns;
233
+ const caseSensitive = rule.config.caseSensitive;
234
+ // Simulate pattern detection in request logs
235
+ const suspiciousRequest = this.checkForSuspiciousPatterns(patterns, caseSensitive);
236
+ if (suspiciousRequest) {
237
+ const threat = {
238
+ id: `pattern_${Date.now()}`,
239
+ type: 'injection_attack',
240
+ severity: 'high',
241
+ source: this.anonymize(suspiciousRequest.source),
242
+ timestamp: Date.now(),
243
+ details: {
244
+ pattern: suspiciousRequest.pattern,
245
+ userAgent: suspiciousRequest.userAgent
246
+ },
247
+ status: 'active'
248
+ };
249
+ this.reportThreat(threat);
250
+ rule.triggerCount++;
251
+ rule.lastTriggered = Date.now();
252
+ }
253
+ }
254
+ /**
255
+ * Check rate limiting violations
256
+ */
257
+ checkRateLimits() {
258
+ const rule = this.securityRules.get('rate_limit_api');
259
+ if (!rule || !rule.enabled)
260
+ return;
261
+ const config = rule.config;
262
+ // Simulate rate limit checking
263
+ const violation = this.checkRateLimitViolation(config);
264
+ if (violation) {
265
+ const anonSource = this.anonymize(violation.ip);
266
+ const threat = {
267
+ id: `rate_limit_${Date.now()}`,
268
+ type: 'rate_limit_exceeded',
269
+ severity: 'medium',
270
+ source: anonSource,
271
+ timestamp: Date.now(),
272
+ details: {
273
+ requestCount: violation.requestCount,
274
+ maxRequests: config.maxRequests,
275
+ timeWindow: config.windowMs
276
+ },
277
+ status: 'active',
278
+ actionTaken: `Source [${anonSource}] blacklisted for ${config.blacklistDuration}ms`
279
+ };
280
+ this.reportThreat(threat);
281
+ rule.triggerCount++;
282
+ rule.lastTriggered = Date.now();
283
+ }
284
+ }
285
+ /**
286
+ * Validate authentication attempts
287
+ */
288
+ validateAuthenticationAttempts() {
289
+ const rule = this.securityRules.get('authentication_anomaly');
290
+ if (!rule || !rule.enabled)
291
+ return;
292
+ const config = rule.config;
293
+ // Simulate authentication monitoring
294
+ const anomaly = this.checkAuthenticationAnomaly(config);
295
+ if (anomaly) {
296
+ const anonSource = this.anonymize(anomaly.source);
297
+ const threat = {
298
+ id: `auth_anomaly_${Date.now()}`,
299
+ type: 'authentication_failure',
300
+ severity: 'high',
301
+ source: anonSource,
302
+ timestamp: Date.now(),
303
+ details: {
304
+ failedAttempts: anomaly.attempts,
305
+ maxAllowed: config.maxFailedAttempts,
306
+ timeWindow: config.timeWindow,
307
+ accounts: anomaly.accounts.map(a => this.anonymize(a))
308
+ },
309
+ status: 'active',
310
+ actionTaken: `Source [${anonSource}] locked out for ${config.lockoutDuration}ms`
311
+ };
312
+ this.reportThreat(threat);
313
+ rule.triggerCount++;
314
+ rule.lastTriggered = Date.now();
315
+ }
316
+ }
317
+ /**
318
+ * Report a security threat
319
+ */
320
+ reportThreat(threat) {
321
+ this.threats.set(threat.id, threat);
322
+ // Notify all registered callbacks
323
+ this.alertCallbacks.forEach(callback => {
324
+ try {
325
+ callback(threat);
326
+ }
327
+ catch (error) {
328
+ (0, logger_js_1.logError)('[SecurityMonitor] Error in security alert callback', error);
329
+ }
330
+ });
331
+ // Log to security audit trail
332
+ this.logSecurityEvent(threat);
333
+ }
334
+ /**
335
+ * Log security event to audit trail
336
+ */
337
+ logSecurityEvent(threat) {
338
+ const logEntry = {
339
+ timestamp: new Date(threat.timestamp).toISOString(),
340
+ threatId: threat.id,
341
+ type: threat.type,
342
+ severity: threat.severity,
343
+ source: threat.source,
344
+ details: threat.details,
345
+ actionTaken: threat.actionTaken
346
+ };
347
+ (0, logger_js_1.logInfo)('[SecurityMonitor] Security event', logEntry);
348
+ }
349
+ /**
350
+ * Get current system health status
351
+ */
352
+ getSystemHealth() {
353
+ const now = Date.now();
354
+ const recentThreats = Array.from(this.threats.values())
355
+ .filter(threat => threat.status === 'active' && (now - threat.timestamp) < 300000); // Last 5 minutes
356
+ // Determine overall health
357
+ let overall = 'healthy';
358
+ const criticalThreats = recentThreats.filter(t => t.severity === 'critical');
359
+ const highThreats = recentThreats.filter(t => t.severity === 'high');
360
+ if (criticalThreats.length > 0) {
361
+ overall = 'critical';
362
+ }
363
+ else if (highThreats.length > 0 || recentThreats.length > 5) {
364
+ overall = 'warning';
365
+ }
366
+ return {
367
+ overall,
368
+ services: this.getServiceStatuses(),
369
+ alerts: recentThreats,
370
+ performance: this.getRecentPerformanceMetrics()
371
+ };
372
+ }
373
+ /**
374
+ * Get service statuses
375
+ */
376
+ getServiceStatuses() {
377
+ return [
378
+ {
379
+ name: 'MCP Server',
380
+ status: 'up',
381
+ latency: this.getAverageAPILatency(),
382
+ uptime: process.uptime() * 1000,
383
+ lastCheck: Date.now()
384
+ },
385
+ {
386
+ name: 'Dashboard',
387
+ status: 'up',
388
+ latency: 50,
389
+ uptime: process.uptime() * 1000,
390
+ lastCheck: Date.now()
391
+ },
392
+ {
393
+ name: 'Analytics Engine',
394
+ status: 'up',
395
+ latency: 25,
396
+ uptime: process.uptime() * 1000,
397
+ lastCheck: Date.now()
398
+ }
399
+ ];
400
+ }
401
+ /**
402
+ * Get recent performance metrics
403
+ */
404
+ getRecentPerformanceMetrics() {
405
+ const recent = [];
406
+ const cutoff = Date.now() - 300000; // Last 5 minutes
407
+ this.performanceMetrics.forEach(metrics => {
408
+ const recentMetrics = metrics.filter(m => m.timestamp > cutoff);
409
+ recent.push(...recentMetrics);
410
+ });
411
+ return recent.sort((a, b) => b.timestamp - a.timestamp).slice(0, 20);
412
+ }
413
+ /**
414
+ * Register alert callback
415
+ */
416
+ onThreatDetected(callback) {
417
+ this.alertCallbacks.push(callback);
418
+ }
419
+ /**
420
+ * Mitigate a threat
421
+ */
422
+ mitigateThreat(threatId, action) {
423
+ const threat = this.threats.get(threatId);
424
+ if (!threat)
425
+ return false;
426
+ threat.status = 'mitigated';
427
+ threat.actionTaken = action;
428
+ this.logSecurityEvent(threat);
429
+ return true;
430
+ }
431
+ /**
432
+ * Resolve a threat
433
+ */
434
+ resolveThreat(threatId) {
435
+ const threat = this.threats.get(threatId);
436
+ if (!threat)
437
+ return false;
438
+ threat.status = 'resolved';
439
+ this.logSecurityEvent(threat);
440
+ return true;
441
+ }
442
+ /**
443
+ * Get list of active threats
444
+ */
445
+ getActiveThreats() {
446
+ const activeThreats = [];
447
+ const threatValues = Array.from(this.threats.values());
448
+ for (const threat of threatValues) {
449
+ if (threat.status === 'active') {
450
+ activeThreats.push(threat);
451
+ }
452
+ }
453
+ return activeThreats;
454
+ }
455
+ /**
456
+ * Clean up old data
457
+ */
458
+ cleanupOldData() {
459
+ const cutoff = Date.now() - 86400000; // 24 hours
460
+ // Clean old threats
461
+ const threatEntries = Array.from(this.threats.entries());
462
+ for (const [id, threat] of threatEntries) {
463
+ if (threat.timestamp < cutoff) {
464
+ this.threats.delete(id);
465
+ }
466
+ }
467
+ // Clean old performance metrics
468
+ this.performanceMetrics.forEach(metrics => {
469
+ const filtered = metrics.filter(m => m.timestamp > cutoff);
470
+ metrics.splice(0, metrics.length, ...filtered);
471
+ });
472
+ }
473
+ // Utility methods for simulated monitoring
474
+ getCPUUsage() {
475
+ // Simulate CPU usage between 10-80%
476
+ return Math.random() * 70 + 10;
477
+ }
478
+ getAverageAPILatency() {
479
+ // Simulate API latency between 50-300ms
480
+ return Math.random() * 250 + 50;
481
+ }
482
+ checkForSuspiciousPatterns(patterns, _caseSensitive) {
483
+ // Simulate 1% chance of detecting suspicious pattern
484
+ if (Math.random() < 0.01) {
485
+ const pattern = patterns[Math.floor(Math.random() * patterns.length)];
486
+ return {
487
+ pattern,
488
+ request: `/api/search?q=${pattern}`,
489
+ source: `192.168.1.${Math.floor(Math.random() * 255)}`,
490
+ userAgent: 'Mozilla/5.0 (compatible; SecurityScanner/1.0)'
491
+ };
492
+ }
493
+ return null;
494
+ }
495
+ checkRateLimitViolation(config) {
496
+ // Simulate 0.5% chance of rate limit violation
497
+ if (Math.random() < 0.005) {
498
+ return {
499
+ ip: `192.168.1.${Math.floor(Math.random() * 255)}`,
500
+ requestCount: config.maxRequests + Math.floor(Math.random() * 50),
501
+ userAgent: 'Mozilla/5.0 (compatible; BotScanner/1.0)'
502
+ };
503
+ }
504
+ return null;
505
+ }
506
+ checkAuthenticationAnomaly(config) {
507
+ // Simulate 0.2% chance of authentication anomaly
508
+ if (Math.random() < 0.002) {
509
+ return {
510
+ source: `192.168.1.${Math.floor(Math.random() * 255)}`,
511
+ attempts: config.maxFailedAttempts + Math.floor(Math.random() * 10),
512
+ accounts: ['admin', 'root', 'user', 'test'].slice(0, Math.floor(Math.random() * 4) + 1)
513
+ };
514
+ }
515
+ return null;
516
+ }
517
+ /**
518
+ * Get security rules configuration
519
+ */
520
+ getSecurityRules() {
521
+ return Array.from(this.securityRules.values());
522
+ }
523
+ /**
524
+ * Update security rule
525
+ */
526
+ updateSecurityRule(ruleId, updates) {
527
+ const rule = this.securityRules.get(ruleId);
528
+ if (!rule)
529
+ return false;
530
+ Object.assign(rule, updates);
531
+ return true;
532
+ }
533
+ /**
534
+ * Get threat statistics
535
+ */
536
+ getThreatStatistics() {
537
+ const threats = Array.from(this.threats.values());
538
+ const stats = {
539
+ total: threats.length,
540
+ active: threats.filter(t => t.status === 'active').length,
541
+ resolved: threats.filter(t => t.status === 'resolved').length,
542
+ byType: {},
543
+ bySeverity: {}
544
+ };
545
+ threats.forEach(threat => {
546
+ stats.byType[threat.type] = (stats.byType[threat.type] || 0) + 1;
547
+ stats.bySeverity[threat.severity] = (stats.bySeverity[threat.severity] || 0) + 1;
548
+ });
549
+ return stats;
550
+ }
551
+ }
552
+ exports.SecurityMonitor = SecurityMonitor;
553
+ // Singleton instance
554
+ let securityMonitor = null;
555
+ function getSecurityMonitor() {
556
+ if (!securityMonitor) {
557
+ securityMonitor = new SecurityMonitor();
558
+ }
559
+ return securityMonitor;
560
+ }