@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,205 @@
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
+ const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const registry_1 = require("../../server/registry");
10
+ const indexContext_1 = require("../indexContext");
11
+ const features_1 = require("../features");
12
+ const schemaVersion_1 = require("../../versioning/schemaVersion");
13
+ const classificationService_1 = require("../classificationService");
14
+ const ownershipService_1 = require("../ownershipService");
15
+ const auditLog_1 = require("../auditLog");
16
+ const runtimeConfig_1 = require("../../config/runtimeConfig");
17
+ const manifestManager_1 = require("../manifestManager");
18
+ const instructions_shared_1 = require("./instructions.shared");
19
+ /** Validate that a resolved path falls within allowed base directories (cwd or configured data dir). */
20
+ function isPathAllowed(resolved) {
21
+ const cwd = process.cwd();
22
+ const config = (0, runtimeConfig_1.getRuntimeConfig)();
23
+ const dataDir = config.index.baseDir || cwd;
24
+ const normalizedResolved = path_1.default.resolve(resolved);
25
+ const allowedRoots = [path_1.default.resolve(cwd), path_1.default.resolve(dataDir)];
26
+ return allowedRoots.some(root => normalizedResolved.startsWith(root + path_1.default.sep) || normalizedResolved === root);
27
+ }
28
+ function parseInlineEntries(rawEntries) {
29
+ const trimmed = rawEntries.trim();
30
+ if (!(trimmed.startsWith('[') && trimmed.endsWith(']')))
31
+ return {};
32
+ try {
33
+ const parsed = JSON.parse(trimmed);
34
+ if (!Array.isArray(parsed))
35
+ return { error: { error: 'entries JSON must contain an array' } };
36
+ return { entries: parsed };
37
+ }
38
+ catch (e) {
39
+ return { error: { error: 'entries JSON parse error', detail: e.message } };
40
+ }
41
+ }
42
+ (0, registry_1.registerHandler)('index_import', (0, instructions_shared_1.guard)('index_import', (p) => {
43
+ let entries;
44
+ const mode = p.mode || 'skip';
45
+ if (Array.isArray(p.entries)) {
46
+ entries = p.entries;
47
+ }
48
+ else if (typeof p.entries === 'string') {
49
+ const inlineEntries = parseInlineEntries(p.entries);
50
+ if (inlineEntries.error)
51
+ return inlineEntries.error;
52
+ if (inlineEntries.entries) {
53
+ entries = inlineEntries.entries;
54
+ }
55
+ else {
56
+ const filePath = path_1.default.resolve(p.entries);
57
+ if (!isPathAllowed(filePath))
58
+ return { error: 'entries path is outside allowed directories', path: filePath };
59
+ if (!fs_1.default.existsSync(filePath))
60
+ return { error: 'entries file not found', path: filePath };
61
+ try {
62
+ const raw = JSON.parse(fs_1.default.readFileSync(filePath, 'utf8'));
63
+ if (!Array.isArray(raw))
64
+ return { error: 'entries file must contain a JSON array', path: filePath };
65
+ entries = raw;
66
+ }
67
+ catch (e) {
68
+ return { error: 'entries file parse error', path: filePath, detail: e.message };
69
+ }
70
+ }
71
+ }
72
+ else if (typeof p.source === 'string') {
73
+ const dirPath = path_1.default.resolve(p.source);
74
+ if (!isPathAllowed(dirPath))
75
+ return { error: 'source path is outside allowed directories', path: dirPath };
76
+ if (!fs_1.default.existsSync(dirPath))
77
+ return { error: 'source directory not found', path: dirPath };
78
+ let stat;
79
+ try {
80
+ stat = fs_1.default.statSync(dirPath);
81
+ }
82
+ catch (e) {
83
+ return { error: 'source path inaccessible', path: dirPath, detail: e.message };
84
+ }
85
+ if (!stat.isDirectory())
86
+ return { error: 'source path is not a directory', path: dirPath };
87
+ const files = fs_1.default.readdirSync(dirPath).filter(f => f.endsWith('.json') && !f.startsWith('_'));
88
+ entries = [];
89
+ for (const fname of files) {
90
+ const fpath = path_1.default.join(dirPath, fname);
91
+ try {
92
+ const parsed = JSON.parse(fs_1.default.readFileSync(fpath, 'utf8'));
93
+ if (parsed && typeof parsed === 'object' && parsed.id)
94
+ entries.push(parsed);
95
+ }
96
+ catch { /* skip unparseable files */ }
97
+ }
98
+ }
99
+ else {
100
+ entries = [];
101
+ }
102
+ if (!entries.length)
103
+ return { error: 'no entries' };
104
+ const dir = (0, indexContext_1.getInstructionsDir)();
105
+ if (!fs_1.default.existsSync(dir))
106
+ fs_1.default.mkdirSync(dir, { recursive: true });
107
+ const instructionsCfg = (0, runtimeConfig_1.getRuntimeConfig)().instructions;
108
+ let imported = 0, skipped = 0, overwritten = 0;
109
+ const errors = [];
110
+ const classifier = new classificationService_1.ClassificationService();
111
+ for (const e of entries) {
112
+ if (!e || !e.id || !e.title || !e.body) {
113
+ const id = e?.id || 'unknown';
114
+ errors.push({ id, error: 'missing required fields' });
115
+ continue;
116
+ }
117
+ const bodyTrimmed = typeof e.body === 'string' ? e.body.trim() : String(e.body);
118
+ const { bodyWarnLength: importBodyMax } = (0, runtimeConfig_1.getRuntimeConfig)().index;
119
+ if (bodyTrimmed.length > importBodyMax) {
120
+ errors.push({ id: e.id, error: `body_too_large: ${bodyTrimmed.length} chars exceeds ${importBodyMax} limit. Split into cross-linked instructions.` });
121
+ continue;
122
+ }
123
+ const file = path_1.default.join(dir, `${e.id}.json`);
124
+ const stImport = (0, indexContext_1.ensureLoaded)();
125
+ const storeHas = stImport.byId.has(e.id);
126
+ const fileExists = storeHas || fs_1.default.existsSync(file);
127
+ const now = new Date().toISOString();
128
+ let categories = Array.from(new Set((Array.isArray(e.categories) ? e.categories : []).filter((c) => typeof c === 'string' && c.trim().length > 0).map(c => c.toLowerCase()))).sort();
129
+ const primaryCategoryRaw = e.primaryCategory;
130
+ if (!categories.length) {
131
+ if (instructionsCfg.requireCategory) {
132
+ errors.push({ id: e.id, error: 'category_required' });
133
+ continue;
134
+ }
135
+ categories = ['uncategorized'];
136
+ (0, features_1.incrementCounter)('instructions:autoCategory');
137
+ }
138
+ const effectivePrimary = (primaryCategoryRaw && categories.includes(primaryCategoryRaw.toLowerCase())) ? primaryCategoryRaw.toLowerCase() : categories[0];
139
+ const newBodyHash = crypto_1.default.createHash('sha256').update(bodyTrimmed, 'utf8').digest('hex');
140
+ let existing = null;
141
+ if (fileExists) {
142
+ // Try store first (covers SQLite), fall back to disk
143
+ const memEntry = stImport.byId.get(e.id);
144
+ if (memEntry) {
145
+ existing = { ...memEntry };
146
+ }
147
+ else {
148
+ try {
149
+ existing = JSON.parse(fs_1.default.readFileSync(file, 'utf8'));
150
+ }
151
+ catch {
152
+ existing = null;
153
+ }
154
+ }
155
+ }
156
+ if (e.priorityTier === 'P1' && (!categories.length || !e.owner)) {
157
+ errors.push({ id: e.id, error: 'P1 requires category & owner' });
158
+ continue;
159
+ }
160
+ if ((e.requirement === 'mandatory' || e.requirement === 'critical') && !e.owner) {
161
+ errors.push({ id: e.id, error: 'mandatory/critical require owner' });
162
+ continue;
163
+ }
164
+ if (fileExists && mode === 'skip') {
165
+ skipped++;
166
+ continue;
167
+ }
168
+ if (fileExists && mode === 'overwrite')
169
+ overwritten++;
170
+ else if (!fileExists)
171
+ imported++;
172
+ const base = existing ? { ...existing, title: e.title, body: bodyTrimmed, rationale: e.rationale, priority: e.priority, audience: e.audience, requirement: e.requirement, categories, primaryCategory: effectivePrimary, updatedAt: now } : { id: e.id, title: e.title, body: bodyTrimmed, rationale: e.rationale, priority: e.priority, audience: e.audience, requirement: e.requirement, categories, primaryCategory: effectivePrimary, sourceHash: newBodyHash, schemaVersion: schemaVersion_1.SCHEMA_VERSION, deprecatedBy: e.deprecatedBy, createdAt: now, updatedAt: now, riskScore: e.riskScore, createdByAgent: instructionsCfg.agentId, sourceWorkspace: instructionsCfg.workspaceId, extensions: e.extensions };
173
+ const govKeys = ['version', 'owner', 'status', 'priorityTier', 'classification', 'lastReviewedAt', 'nextReviewDue', 'changeLog', 'semanticSummary', 'contentType', 'extensions'];
174
+ for (const k of govKeys) {
175
+ const v = e[k];
176
+ if (v !== undefined) {
177
+ base[k] = v;
178
+ }
179
+ }
180
+ if (!base.sourceWorkspace)
181
+ base.sourceWorkspace = instructionsCfg.workspaceId;
182
+ base.sourceHash = newBodyHash;
183
+ const record = classifier.normalize(base);
184
+ if (record.owner === 'unowned') {
185
+ const auto = (0, ownershipService_1.resolveOwner)(record.id);
186
+ if (auto) {
187
+ record.owner = auto;
188
+ record.updatedAt = new Date().toISOString();
189
+ }
190
+ }
191
+ try {
192
+ (0, indexContext_1.writeEntry)(record);
193
+ }
194
+ catch {
195
+ errors.push({ id: e.id, error: 'write-failed' });
196
+ }
197
+ }
198
+ (0, indexContext_1.touchIndexVersion)();
199
+ (0, indexContext_1.invalidate)();
200
+ const st = (0, indexContext_1.ensureLoaded)();
201
+ const summary = { hash: st.hash, imported, skipped, overwritten, total: entries.length, errors };
202
+ (0, auditLog_1.logAudit)('import', entries.map(e => e.id), { imported, skipped, overwritten, errors: errors.length });
203
+ (0, manifestManager_1.attemptManifestUpdate)();
204
+ return summary;
205
+ }));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const registry_1 = require("../../server/registry");
4
+ const indexContext_1 = require("../indexContext");
5
+ const auditLog_1 = require("../auditLog");
6
+ const manifestManager_1 = require("../manifestManager");
7
+ const features_1 = require("../features");
8
+ const instructions_shared_1 = require("./instructions.shared");
9
+ (0, registry_1.registerHandler)('index_governanceHash', () => {
10
+ let st = (0, indexContext_1.ensureLoaded)();
11
+ const now = Date.now();
12
+ const loadedAgo = now - new Date(st.loadedAt).getTime();
13
+ if (loadedAgo > 50) {
14
+ try {
15
+ // Force reload if stale — trust the store for freshness
16
+ (0, indexContext_1.invalidate)();
17
+ st = (0, indexContext_1.ensureLoaded)();
18
+ }
19
+ catch { /* ignore verification errors */ }
20
+ }
21
+ let projections = st.list.slice().sort((a, b) => a.id.localeCompare(b.id)).map(indexContext_1.projectGovernance);
22
+ try {
23
+ const storeCount = st.list.length;
24
+ if (storeCount && (projections.length === 0 || projections.length < Math.floor(storeCount * 0.9))) {
25
+ // Late materialization: reload from store to pick up any missing entries
26
+ (0, indexContext_1.invalidate)();
27
+ st = (0, indexContext_1.ensureLoaded)();
28
+ projections = st.list.slice().sort((a, b) => a.id.localeCompare(b.id)).map(indexContext_1.projectGovernance);
29
+ }
30
+ }
31
+ catch { /* ignore defensive reload errors */ }
32
+ const governanceHash = (0, indexContext_1.computeGovernanceHash)(st.list);
33
+ if (projections.length && projections.length < Math.floor(st.list.length * 0.9) || projections.some(p => !p.owner)) {
34
+ try {
35
+ (0, indexContext_1.invalidate)();
36
+ const st2 = (0, indexContext_1.ensureLoaded)();
37
+ projections = st2.list.slice().sort((a, b) => a.id.localeCompare(b.id)).map(indexContext_1.projectGovernance);
38
+ try {
39
+ (0, features_1.incrementCounter)('governance:projectionRepair');
40
+ }
41
+ catch { /* ignore */ }
42
+ }
43
+ catch { /* ignore reload failure */ }
44
+ }
45
+ return { count: projections.length, governanceHash, items: projections };
46
+ });
47
+ (0, registry_1.registerHandler)('index_governanceUpdate', (0, instructions_shared_1.guard)('index_governanceUpdate', (p) => {
48
+ const id = p.id;
49
+ const st = (0, indexContext_1.ensureLoaded)();
50
+ const existing = st.byId.get(id);
51
+ if (!existing)
52
+ return { id, notFound: true };
53
+ // Read from store (in-memory), fall back to disk for JSON backend
54
+ const record = { ...existing };
55
+ let changed = false;
56
+ const now = new Date().toISOString();
57
+ const bump = p.bump || 'none';
58
+ if (p.owner && p.owner !== record.owner) {
59
+ record.owner = p.owner;
60
+ changed = true;
61
+ }
62
+ if (p.status) {
63
+ const allowed = ['draft', 'review', 'approved', 'deprecated'];
64
+ const desired = p.status === 'active' ? 'approved' : p.status;
65
+ if (!allowed.includes(desired)) {
66
+ return { id, error: 'invalid status', provided: p.status };
67
+ }
68
+ if (desired !== record.status) {
69
+ record.status = desired;
70
+ changed = true;
71
+ }
72
+ }
73
+ if (p.lastReviewedAt) {
74
+ record.lastReviewedAt = p.lastReviewedAt;
75
+ changed = true;
76
+ }
77
+ if (p.nextReviewDue) {
78
+ record.nextReviewDue = p.nextReviewDue;
79
+ changed = true;
80
+ }
81
+ if (bump && bump !== 'none') {
82
+ const parts = (record.version || '1.0.0').split('.').map(n => parseInt(n || '0', 10));
83
+ while (parts.length < 3)
84
+ parts.push(0);
85
+ if (bump === 'major')
86
+ parts[0]++;
87
+ else if (bump === 'minor')
88
+ parts[1]++;
89
+ else if (bump === 'patch')
90
+ parts[2]++;
91
+ if (bump === 'major') {
92
+ parts[1] = 0;
93
+ parts[2] = 0;
94
+ }
95
+ if (bump === 'minor') {
96
+ parts[2] = 0;
97
+ }
98
+ const newVersion = parts.join('.');
99
+ if (newVersion !== record.version) {
100
+ record.version = newVersion;
101
+ record.changeLog = [...(record.changeLog || []), { version: newVersion, changedAt: now, summary: `manual ${bump} bump via governanceUpdate` }];
102
+ changed = true;
103
+ }
104
+ }
105
+ if (!changed)
106
+ return { id, changed: false };
107
+ record.updatedAt = now;
108
+ try {
109
+ (0, indexContext_1.writeEntry)(record);
110
+ }
111
+ catch {
112
+ return { id, error: 'write-failed' };
113
+ }
114
+ (0, indexContext_1.touchIndexVersion)();
115
+ (0, indexContext_1.invalidate)();
116
+ (0, indexContext_1.ensureLoaded)();
117
+ const resp = { id, changed: true, version: record.version, owner: record.owner, status: record.status, lastReviewedAt: record.lastReviewedAt, nextReviewDue: record.nextReviewDue };
118
+ (0, auditLog_1.logAudit)('governanceUpdate', id, { changed: true, version: record.version });
119
+ (0, manifestManager_1.attemptManifestUpdate)();
120
+ return resp;
121
+ }));
@@ -0,0 +1,159 @@
1
+ import { InstructionEntry } from '../../models/instruction';
2
+ export declare const instructionActions: {
3
+ list: (p: {
4
+ category?: string;
5
+ expectId?: string;
6
+ contentType?: string;
7
+ limit?: number;
8
+ offset?: number;
9
+ }) => {
10
+ hash: string;
11
+ count: number;
12
+ items: InstructionEntry[];
13
+ };
14
+ listScoped: (p: {
15
+ userId?: string;
16
+ workspaceId?: string;
17
+ teamIds?: string[];
18
+ }) => {
19
+ hash: string;
20
+ count: number;
21
+ scope: string;
22
+ items: InstructionEntry[];
23
+ };
24
+ get: (p: {
25
+ id: string;
26
+ }) => {
27
+ hash: string;
28
+ item: InstructionEntry;
29
+ notFound?: undefined;
30
+ id?: undefined;
31
+ readonly hint?: undefined;
32
+ example?: undefined;
33
+ } | {
34
+ notFound: boolean;
35
+ id: string;
36
+ hint: string;
37
+ example: {
38
+ action: string;
39
+ id: string;
40
+ };
41
+ hash?: undefined;
42
+ item?: undefined;
43
+ };
44
+ getEnhanced: (p: {
45
+ id: string;
46
+ }) => {
47
+ readonly hash: string;
48
+ readonly item: InstructionEntry;
49
+ notFound?: undefined;
50
+ } | {
51
+ notFound: boolean;
52
+ hash?: undefined;
53
+ item?: undefined;
54
+ };
55
+ search: (p: {
56
+ q?: string;
57
+ keywords?: string[];
58
+ mode?: "keyword" | "regex" | "semantic";
59
+ limit?: number;
60
+ includeCategories?: boolean;
61
+ caseSensitive?: boolean;
62
+ contentType?: string;
63
+ }) => Promise<{
64
+ hash: string;
65
+ count: number;
66
+ totalMatches: number;
67
+ items: InstructionEntry[];
68
+ results: import("../handlers.search").SearchResult[];
69
+ query: {
70
+ keywords: string[];
71
+ mode: "regex" | "keyword" | "semantic";
72
+ limit: number;
73
+ includeCategories: boolean;
74
+ caseSensitive: boolean;
75
+ contentType?: string;
76
+ };
77
+ autoTokenized: boolean | undefined;
78
+ hints: string[] | undefined;
79
+ }>;
80
+ diff: (p: {
81
+ clientHash?: string;
82
+ known?: {
83
+ id: string;
84
+ sourceHash: string;
85
+ }[];
86
+ }) => {
87
+ upToDate: boolean;
88
+ hash: string;
89
+ added?: undefined;
90
+ updated?: undefined;
91
+ removed?: undefined;
92
+ changed?: undefined;
93
+ } | {
94
+ hash: string;
95
+ added: InstructionEntry[];
96
+ updated: InstructionEntry[];
97
+ removed: string[];
98
+ upToDate?: undefined;
99
+ changed?: undefined;
100
+ } | {
101
+ hash: string;
102
+ changed: InstructionEntry[];
103
+ upToDate?: undefined;
104
+ added?: undefined;
105
+ updated?: undefined;
106
+ removed?: undefined;
107
+ };
108
+ export: (p: {
109
+ ids?: string[];
110
+ metaOnly?: boolean;
111
+ }) => {
112
+ hash: string;
113
+ count: number;
114
+ items: InstructionEntry[];
115
+ };
116
+ query: (p: {
117
+ categoriesAll?: string[];
118
+ categoriesAny?: string[];
119
+ excludeCategories?: string[];
120
+ contentType?: string;
121
+ priorityMin?: number;
122
+ priorityMax?: number;
123
+ priorityTiers?: ("P1" | "P2" | "P3" | "P4")[];
124
+ requirements?: InstructionEntry["requirement"][];
125
+ text?: string;
126
+ limit?: number;
127
+ offset?: number;
128
+ }) => {
129
+ hash: string;
130
+ total: number;
131
+ count: number;
132
+ offset: number;
133
+ limit: number;
134
+ items: InstructionEntry[];
135
+ applied: {
136
+ catsAll: string[];
137
+ catsAny: string[];
138
+ catsEx: string[];
139
+ prMin: number | undefined;
140
+ prMax: number | undefined;
141
+ tiers: ("P1" | "P2" | "P3" | "P4")[];
142
+ requirements: import("../../models/instruction").RequirementLevel[];
143
+ text: string | undefined;
144
+ };
145
+ };
146
+ categories: (_p: unknown) => {
147
+ count: number;
148
+ categories: {
149
+ name: string;
150
+ count: number;
151
+ }[];
152
+ };
153
+ dir: () => {
154
+ dir: string;
155
+ filesCount: number;
156
+ files: string[];
157
+ };
158
+ };
159
+ export {};