@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.
- package/CHANGELOG.md +1354 -0
- package/CODE_OF_CONDUCT.md +49 -0
- package/CONTRIBUTING.md +99 -0
- package/LICENSE +21 -0
- package/README.md +228 -0
- package/SECURITY.md +50 -0
- package/dist/config/configUtils.d.ts +11 -0
- package/dist/config/configUtils.js +87 -0
- package/dist/config/dashboardConfig.d.ts +46 -0
- package/dist/config/dashboardConfig.js +67 -0
- package/dist/config/defaultValues.d.ts +63 -0
- package/dist/config/defaultValues.js +72 -0
- package/dist/config/dirConstants.d.ts +18 -0
- package/dist/config/dirConstants.js +29 -0
- package/dist/config/featureConfig.d.ts +61 -0
- package/dist/config/featureConfig.js +121 -0
- package/dist/config/runtimeConfig.d.ts +151 -0
- package/dist/config/runtimeConfig.js +380 -0
- package/dist/config/serverConfig.d.ts +90 -0
- package/dist/config/serverConfig.js +167 -0
- package/dist/dashboard/analytics/AnalyticsEngine.d.ts +142 -0
- package/dist/dashboard/analytics/AnalyticsEngine.js +373 -0
- package/dist/dashboard/analytics/BusinessIntelligence.d.ts +187 -0
- package/dist/dashboard/analytics/BusinessIntelligence.js +594 -0
- package/dist/dashboard/client/admin.html +2175 -0
- package/dist/dashboard/client/chunks/mermaid-layout-elk.esm.min/chunk-SP2CHFBE.mjs +1 -0
- package/dist/dashboard/client/chunks/mermaid-layout-elk.esm.min/render-T6MDALS3.mjs +27 -0
- package/dist/dashboard/client/css/admin.css +1587 -0
- package/dist/dashboard/client/js/admin.auth.js +179 -0
- package/dist/dashboard/client/js/admin.boot.js +359 -0
- package/dist/dashboard/client/js/admin.config.js +196 -0
- package/dist/dashboard/client/js/admin.embeddings.js +426 -0
- package/dist/dashboard/client/js/admin.graph.js +615 -0
- package/dist/dashboard/client/js/admin.instances.js +120 -0
- package/dist/dashboard/client/js/admin.instructions.js +579 -0
- package/dist/dashboard/client/js/admin.logs.js +113 -0
- package/dist/dashboard/client/js/admin.maintenance.js +393 -0
- package/dist/dashboard/client/js/admin.messaging.js +636 -0
- package/dist/dashboard/client/js/admin.monitor.js +184 -0
- package/dist/dashboard/client/js/admin.overview.js +221 -0
- package/dist/dashboard/client/js/admin.performance.js +61 -0
- package/dist/dashboard/client/js/admin.sessions.js +292 -0
- package/dist/dashboard/client/js/admin.sqlite.js +373 -0
- package/dist/dashboard/client/js/admin.utils.js +49 -0
- package/dist/dashboard/client/js/chart.umd.js +14 -0
- package/dist/dashboard/client/js/elk.bundled.js +6696 -0
- package/dist/dashboard/client/js/marked.umd.js +74 -0
- package/dist/dashboard/client/js/mermaid.min.js +3022 -0
- package/dist/dashboard/client/mermaid-layout-elk.esm.min.mjs +1 -0
- package/dist/dashboard/export/DataExporter.d.ts +169 -0
- package/dist/dashboard/export/DataExporter.js +737 -0
- package/dist/dashboard/export/exporters/csvExporter.d.ts +11 -0
- package/dist/dashboard/export/exporters/csvExporter.js +47 -0
- package/dist/dashboard/export/exporters/exportTypes.d.ts +89 -0
- package/dist/dashboard/export/exporters/exportTypes.js +5 -0
- package/dist/dashboard/export/exporters/jsonExporter.d.ts +7 -0
- package/dist/dashboard/export/exporters/jsonExporter.js +23 -0
- package/dist/dashboard/export/exporters/xmlExporter.d.ts +17 -0
- package/dist/dashboard/export/exporters/xmlExporter.js +176 -0
- package/dist/dashboard/integration/APIIntegration.d.ts +41 -0
- package/dist/dashboard/integration/APIIntegration.js +95 -0
- package/dist/dashboard/security/SecurityMonitor.d.ts +167 -0
- package/dist/dashboard/security/SecurityMonitor.js +560 -0
- package/dist/dashboard/server/AdminPanel.d.ts +195 -0
- package/dist/dashboard/server/AdminPanel.js +861 -0
- package/dist/dashboard/server/AdminPanelConfig.d.ts +42 -0
- package/dist/dashboard/server/AdminPanelConfig.js +80 -0
- package/dist/dashboard/server/AdminPanelState.d.ts +47 -0
- package/dist/dashboard/server/AdminPanelState.js +215 -0
- package/dist/dashboard/server/ApiRoutes.d.ts +17 -0
- package/dist/dashboard/server/ApiRoutes.js +184 -0
- package/dist/dashboard/server/DashboardServer.d.ts +49 -0
- package/dist/dashboard/server/DashboardServer.js +160 -0
- package/dist/dashboard/server/FileMetricsStorage.d.ts +49 -0
- package/dist/dashboard/server/FileMetricsStorage.js +196 -0
- package/dist/dashboard/server/HttpTransport.d.ts +23 -0
- package/dist/dashboard/server/HttpTransport.js +116 -0
- package/dist/dashboard/server/InstanceManager.d.ts +53 -0
- package/dist/dashboard/server/InstanceManager.js +295 -0
- package/dist/dashboard/server/KnowledgeStore.d.ts +35 -0
- package/dist/dashboard/server/KnowledgeStore.js +105 -0
- package/dist/dashboard/server/LeaderElection.d.ts +81 -0
- package/dist/dashboard/server/LeaderElection.js +268 -0
- package/dist/dashboard/server/MetricsCollector.d.ts +200 -0
- package/dist/dashboard/server/MetricsCollector.js +810 -0
- package/dist/dashboard/server/SessionPersistenceManager.d.ts +88 -0
- package/dist/dashboard/server/SessionPersistenceManager.js +458 -0
- package/dist/dashboard/server/ThinClient.d.ts +64 -0
- package/dist/dashboard/server/ThinClient.js +237 -0
- package/dist/dashboard/server/WebSocketManager.d.ts +161 -0
- package/dist/dashboard/server/WebSocketManager.js +448 -0
- package/dist/dashboard/server/httpLifecycle.d.ts +17 -0
- package/dist/dashboard/server/httpLifecycle.js +35 -0
- package/dist/dashboard/server/legacyDashboardHtml.d.ts +9 -0
- package/dist/dashboard/server/legacyDashboardHtml.js +618 -0
- package/dist/dashboard/server/legacyDashboardStyles.d.ts +5 -0
- package/dist/dashboard/server/legacyDashboardStyles.js +490 -0
- package/dist/dashboard/server/metricsAggregation.d.ts +252 -0
- package/dist/dashboard/server/metricsAggregation.js +210 -0
- package/dist/dashboard/server/metricsSerializer.d.ts +25 -0
- package/dist/dashboard/server/metricsSerializer.js +195 -0
- package/dist/dashboard/server/middleware/ensureLoadedMiddleware.d.ts +25 -0
- package/dist/dashboard/server/middleware/ensureLoadedMiddleware.js +24 -0
- package/dist/dashboard/server/routes/admin.routes.d.ts +16 -0
- package/dist/dashboard/server/routes/admin.routes.js +574 -0
- package/dist/dashboard/server/routes/adminAuth.d.ts +4 -0
- package/dist/dashboard/server/routes/adminAuth.js +46 -0
- package/dist/dashboard/server/routes/alerts.routes.d.ts +7 -0
- package/dist/dashboard/server/routes/alerts.routes.js +91 -0
- package/dist/dashboard/server/routes/api.feedback.routes.d.ts +73 -0
- package/dist/dashboard/server/routes/api.feedback.routes.js +171 -0
- package/dist/dashboard/server/routes/api.instructions.routes.d.ts +101 -0
- package/dist/dashboard/server/routes/api.instructions.routes.js +213 -0
- package/dist/dashboard/server/routes/api.usage.routes.d.ts +57 -0
- package/dist/dashboard/server/routes/api.usage.routes.js +374 -0
- package/dist/dashboard/server/routes/embeddings.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/embeddings.routes.js +246 -0
- package/dist/dashboard/server/routes/graph.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/graph.routes.js +279 -0
- package/dist/dashboard/server/routes/index.d.ts +39 -0
- package/dist/dashboard/server/routes/index.js +229 -0
- package/dist/dashboard/server/routes/instances.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/instances.routes.js +35 -0
- package/dist/dashboard/server/routes/instructions.routes.d.ts +8 -0
- package/dist/dashboard/server/routes/instructions.routes.js +268 -0
- package/dist/dashboard/server/routes/knowledge.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/knowledge.routes.js +80 -0
- package/dist/dashboard/server/routes/logs.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/logs.routes.js +166 -0
- package/dist/dashboard/server/routes/messaging.routes.d.ts +16 -0
- package/dist/dashboard/server/routes/messaging.routes.js +307 -0
- package/dist/dashboard/server/routes/metrics.routes.d.ts +10 -0
- package/dist/dashboard/server/routes/metrics.routes.js +335 -0
- package/dist/dashboard/server/routes/scripts.routes.d.ts +9 -0
- package/dist/dashboard/server/routes/scripts.routes.js +84 -0
- package/dist/dashboard/server/routes/sqlite.routes.d.ts +9 -0
- package/dist/dashboard/server/routes/sqlite.routes.js +570 -0
- package/dist/dashboard/server/routes/status.routes.d.ts +7 -0
- package/dist/dashboard/server/routes/status.routes.js +179 -0
- package/dist/dashboard/server/routes/synthetic.routes.d.ts +7 -0
- package/dist/dashboard/server/routes/synthetic.routes.js +197 -0
- package/dist/dashboard/server/routes/tools.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/tools.routes.js +47 -0
- package/dist/dashboard/server/routes/usage.routes.d.ts +6 -0
- package/dist/dashboard/server/routes/usage.routes.js +26 -0
- package/dist/dashboard/server/wsInit.d.ts +16 -0
- package/dist/dashboard/server/wsInit.js +35 -0
- package/dist/externalClientLib.d.ts +1 -0
- package/dist/externalClientLib.js +2 -0
- package/dist/minimal/index.d.ts +1 -0
- package/dist/minimal/index.js +140 -0
- package/dist/models/SessionPersistence.d.ts +115 -0
- package/dist/models/SessionPersistence.js +66 -0
- package/dist/models/instruction.d.ts +46 -0
- package/dist/models/instruction.js +2 -0
- package/dist/perf/benchmark.d.ts +1 -0
- package/dist/perf/benchmark.js +50 -0
- package/dist/portableClientWrapper.d.ts +1 -0
- package/dist/portableClientWrapper.js +2 -0
- package/dist/schemas/index.d.ts +132 -0
- package/dist/schemas/index.js +372 -0
- package/dist/scripts/runPerformanceBaseline.d.ts +1 -0
- package/dist/scripts/runPerformanceBaseline.js +17 -0
- package/dist/server/backgroundServicesStartup.d.ts +3 -0
- package/dist/server/backgroundServicesStartup.js +51 -0
- package/dist/server/handshakeManager.d.ts +25 -0
- package/dist/server/handshakeManager.js +470 -0
- package/dist/server/index-server.d.ts +38 -0
- package/dist/server/index-server.js +620 -0
- package/dist/server/multiInstanceStartup.d.ts +6 -0
- package/dist/server/multiInstanceStartup.js +132 -0
- package/dist/server/registry.d.ts +44 -0
- package/dist/server/registry.js +236 -0
- package/dist/server/sdkServer.d.ts +8 -0
- package/dist/server/sdkServer.js +299 -0
- package/dist/server/shutdownGuard.d.ts +41 -0
- package/dist/server/shutdownGuard.js +52 -0
- package/dist/server/startupDiagnostics.d.ts +2 -0
- package/dist/server/startupDiagnostics.js +33 -0
- package/dist/server/thin-client.d.ts +22 -0
- package/dist/server/thin-client.js +111 -0
- package/dist/server/transport.d.ts +41 -0
- package/dist/server/transport.js +312 -0
- package/dist/server/transportFactory.d.ts +21 -0
- package/dist/server/transportFactory.js +429 -0
- package/dist/services/atomicFs.d.ts +22 -0
- package/dist/services/atomicFs.js +103 -0
- package/dist/services/auditLog.d.ts +38 -0
- package/dist/services/auditLog.js +142 -0
- package/dist/services/autoBackup.d.ts +14 -0
- package/dist/services/autoBackup.js +171 -0
- package/dist/services/autoSplit.d.ts +32 -0
- package/dist/services/autoSplit.js +113 -0
- package/dist/services/backupZip.d.ts +25 -0
- package/dist/services/backupZip.js +112 -0
- package/dist/services/bootstrapGating.d.ts +123 -0
- package/dist/services/bootstrapGating.js +221 -0
- package/dist/services/canonical.d.ts +23 -0
- package/dist/services/canonical.js +65 -0
- package/dist/services/categoryRules.d.ts +7 -0
- package/dist/services/categoryRules.js +37 -0
- package/dist/services/classificationService.d.ts +42 -0
- package/dist/services/classificationService.js +168 -0
- package/dist/services/embeddingService.d.ts +62 -0
- package/dist/services/embeddingService.js +264 -0
- package/dist/services/errors.d.ts +22 -0
- package/dist/services/errors.js +31 -0
- package/dist/services/featureFlags.d.ts +25 -0
- package/dist/services/featureFlags.js +89 -0
- package/dist/services/features.d.ts +13 -0
- package/dist/services/features.js +35 -0
- package/dist/services/handlers/instructions.add.d.ts +1 -0
- package/dist/services/handlers/instructions.add.js +510 -0
- package/dist/services/handlers/instructions.groom.d.ts +1 -0
- package/dist/services/handlers/instructions.groom.js +575 -0
- package/dist/services/handlers/instructions.import.d.ts +1 -0
- package/dist/services/handlers/instructions.import.js +205 -0
- package/dist/services/handlers/instructions.patch.d.ts +1 -0
- package/dist/services/handlers/instructions.patch.js +121 -0
- package/dist/services/handlers/instructions.query.d.ts +159 -0
- package/dist/services/handlers/instructions.query.js +469 -0
- package/dist/services/handlers/instructions.reload.d.ts +1 -0
- package/dist/services/handlers/instructions.reload.js +13 -0
- package/dist/services/handlers/instructions.remove.d.ts +1 -0
- package/dist/services/handlers/instructions.remove.js +122 -0
- package/dist/services/handlers/instructions.shared.d.ts +32 -0
- package/dist/services/handlers/instructions.shared.js +91 -0
- package/dist/services/handlers.activation.d.ts +1 -0
- package/dist/services/handlers.activation.js +203 -0
- package/dist/services/handlers.bootstrap.d.ts +1 -0
- package/dist/services/handlers.bootstrap.js +38 -0
- package/dist/services/handlers.dashboardConfig.d.ts +34 -0
- package/dist/services/handlers.dashboardConfig.js +110 -0
- package/dist/services/handlers.diagnostics.d.ts +1 -0
- package/dist/services/handlers.diagnostics.js +64 -0
- package/dist/services/handlers.feedback.d.ts +15 -0
- package/dist/services/handlers.feedback.js +389 -0
- package/dist/services/handlers.gates.d.ts +1 -0
- package/dist/services/handlers.gates.js +47 -0
- package/dist/services/handlers.graph.d.ts +53 -0
- package/dist/services/handlers.graph.js +231 -0
- package/dist/services/handlers.help.d.ts +1 -0
- package/dist/services/handlers.help.js +119 -0
- package/dist/services/handlers.instructionSchema.d.ts +1 -0
- package/dist/services/handlers.instructionSchema.js +227 -0
- package/dist/services/handlers.instructions.d.ts +8 -0
- package/dist/services/handlers.instructions.js +14 -0
- package/dist/services/handlers.instructionsDiagnostics.d.ts +1 -0
- package/dist/services/handlers.instructionsDiagnostics.js +14 -0
- package/dist/services/handlers.integrity.d.ts +1 -0
- package/dist/services/handlers.integrity.js +35 -0
- package/dist/services/handlers.manifest.d.ts +1 -0
- package/dist/services/handlers.manifest.js +24 -0
- package/dist/services/handlers.messaging.d.ts +12 -0
- package/dist/services/handlers.messaging.js +203 -0
- package/dist/services/handlers.metrics.d.ts +1 -0
- package/dist/services/handlers.metrics.js +43 -0
- package/dist/services/handlers.promote.d.ts +1 -0
- package/dist/services/handlers.promote.js +326 -0
- package/dist/services/handlers.prompt.d.ts +1 -0
- package/dist/services/handlers.prompt.js +7 -0
- package/dist/services/handlers.search.d.ts +69 -0
- package/dist/services/handlers.search.js +669 -0
- package/dist/services/handlers.testPrimitive.d.ts +1 -0
- package/dist/services/handlers.testPrimitive.js +5 -0
- package/dist/services/handlers.trace.d.ts +1 -0
- package/dist/services/handlers.trace.js +35 -0
- package/dist/services/handlers.usage.d.ts +1 -0
- package/dist/services/handlers.usage.js +11 -0
- package/dist/services/hotScore.d.ts +137 -0
- package/dist/services/hotScore.js +244 -0
- package/dist/services/indexContext.d.ts +117 -0
- package/dist/services/indexContext.js +989 -0
- package/dist/services/indexLoader.d.ts +44 -0
- package/dist/services/indexLoader.js +920 -0
- package/dist/services/indexRepository.d.ts +32 -0
- package/dist/services/indexRepository.js +71 -0
- package/dist/services/indexingService.d.ts +1 -0
- package/dist/services/indexingService.js +2 -0
- package/dist/services/instructions.dispatcher.d.ts +1 -0
- package/dist/services/instructions.dispatcher.js +231 -0
- package/dist/services/logPrefix.d.ts +1 -0
- package/dist/services/logPrefix.js +30 -0
- package/dist/services/logger.d.ts +52 -0
- package/dist/services/logger.js +268 -0
- package/dist/services/manifestManager.d.ts +82 -0
- package/dist/services/manifestManager.js +200 -0
- package/dist/services/messaging/agentMailbox.d.ts +60 -0
- package/dist/services/messaging/agentMailbox.js +353 -0
- package/dist/services/messaging/messagingPersistence.d.ts +20 -0
- package/dist/services/messaging/messagingPersistence.js +111 -0
- package/dist/services/messaging/messagingTypes.d.ts +150 -0
- package/dist/services/messaging/messagingTypes.js +66 -0
- package/dist/services/ownershipService.d.ts +1 -0
- package/dist/services/ownershipService.js +36 -0
- package/dist/services/performanceBaseline.d.ts +19 -0
- package/dist/services/performanceBaseline.js +210 -0
- package/dist/services/preflight.d.ts +12 -0
- package/dist/services/preflight.js +79 -0
- package/dist/services/promptReviewService.d.ts +44 -0
- package/dist/services/promptReviewService.js +101 -0
- package/dist/services/responseEnvelope.d.ts +6 -0
- package/dist/services/responseEnvelope.js +25 -0
- package/dist/services/seedBootstrap.d.ts +34 -0
- package/dist/services/seedBootstrap.js +259 -0
- package/dist/services/storage/factory.d.ts +17 -0
- package/dist/services/storage/factory.js +35 -0
- package/dist/services/storage/hashUtils.d.ts +11 -0
- package/dist/services/storage/hashUtils.js +35 -0
- package/dist/services/storage/index.d.ts +12 -0
- package/dist/services/storage/index.js +18 -0
- package/dist/services/storage/jsonFileStore.d.ts +32 -0
- package/dist/services/storage/jsonFileStore.js +241 -0
- package/dist/services/storage/migrationEngine.d.ts +35 -0
- package/dist/services/storage/migrationEngine.js +93 -0
- package/dist/services/storage/sqliteMessageStore.d.ts +53 -0
- package/dist/services/storage/sqliteMessageStore.js +146 -0
- package/dist/services/storage/sqliteSchema.d.ts +12 -0
- package/dist/services/storage/sqliteSchema.js +123 -0
- package/dist/services/storage/sqliteStore.d.ts +42 -0
- package/dist/services/storage/sqliteStore.js +361 -0
- package/dist/services/storage/sqliteUsageStore.d.ts +35 -0
- package/dist/services/storage/sqliteUsageStore.js +94 -0
- package/dist/services/storage/types.d.ts +171 -0
- package/dist/services/storage/types.js +12 -0
- package/dist/services/toolHandlers.d.ts +23 -0
- package/dist/services/toolHandlers.js +50 -0
- package/dist/services/toolRegistry.d.ts +20 -0
- package/dist/services/toolRegistry.js +490 -0
- package/dist/services/toolRegistry.zod.d.ts +10 -0
- package/dist/services/toolRegistry.zod.js +325 -0
- package/dist/services/tracing.d.ts +26 -0
- package/dist/services/tracing.js +260 -0
- package/dist/services/usageBuckets.d.ts +161 -0
- package/dist/services/usageBuckets.js +364 -0
- package/dist/services/validationService.d.ts +38 -0
- package/dist/services/validationService.js +125 -0
- package/dist/utils/BufferRing.d.ts +203 -0
- package/dist/utils/BufferRing.js +551 -0
- package/dist/utils/BufferRingExamples.d.ts +55 -0
- package/dist/utils/BufferRingExamples.js +188 -0
- package/dist/utils/envUtils.d.ts +42 -0
- package/dist/utils/envUtils.js +80 -0
- package/dist/utils/memoryMonitor.d.ts +83 -0
- package/dist/utils/memoryMonitor.js +275 -0
- package/dist/versioning/schemaVersion.d.ts +6 -0
- package/dist/versioning/schemaVersion.js +94 -0
- package/package.json +139 -0
- package/schemas/README.md +13 -0
- package/schemas/feedback-entry.schema.json +27 -0
- package/schemas/graph-export-v2.schema.json +60 -0
- package/schemas/index-server.code-schema.json +40670 -0
- package/schemas/instruction.schema.json +262 -0
- package/schemas/json-schema/SessionPersistence-persisted-admin-session.schema.json +54 -0
- package/schemas/json-schema/SessionPersistence-persisted-session-history-entry.schema.json +51 -0
- package/schemas/json-schema/SessionPersistence-persisted-web-socket-connection.schema.json +54 -0
- package/schemas/json-schema/SessionPersistence-session-persistence-config.schema.json +110 -0
- package/schemas/json-schema/SessionPersistence-session-persistence-data.schema.json +229 -0
- package/schemas/json-schema/SessionPersistence-session-persistence-manifest.schema.json +109 -0
- package/schemas/json-schema/SessionPersistence-session-persistence-metadata.schema.json +55 -0
- package/schemas/json-schema/instruction-audience-scope.schema.json +14 -0
- package/schemas/json-schema/instruction-content-type.schema.json +17 -0
- package/schemas/json-schema/instruction-instruction-entry.schema.json +210 -0
- package/schemas/json-schema/instruction-requirement-level.schema.json +16 -0
- package/schemas/manifest.json +78 -0
- package/schemas/manifest.schema.json +33 -0
- package/schemas/usage-batch.schema.json +16 -0
- package/schemas/usage-buckets.schema.json +30 -0
- package/schemas/usage-event.schema.json +17 -0
- package/scripts/copy-dashboard-assets.mjs +170 -0
- package/scripts/dist/README.md +15 -0
- package/scripts/setup-hooks.cjs +28 -0
|
@@ -0,0 +1,259 @@
|
|
|
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.autoSeedBootstrap = autoSeedBootstrap;
|
|
7
|
+
exports._getCanonicalSeeds = _getCanonicalSeeds;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
const indexContext_1 = require("./indexContext");
|
|
12
|
+
const logger_1 = require("./logger");
|
|
13
|
+
const runtimeConfig_1 = require("../config/runtimeConfig");
|
|
14
|
+
// Canonical seed instruction objects (kept intentionally minimal – DO NOT add environment specific data)
|
|
15
|
+
const CANONICAL_SEEDS = [
|
|
16
|
+
{
|
|
17
|
+
file: '000-bootstrapper.json',
|
|
18
|
+
id: '000-bootstrapper',
|
|
19
|
+
json: {
|
|
20
|
+
id: '000-bootstrapper',
|
|
21
|
+
title: 'Index Server - AI Agent Quick Start',
|
|
22
|
+
body: `# Index Server: AI Agent Quick Start
|
|
23
|
+
|
|
24
|
+
Index Server is a shared knowledge base for AI agents via MCP. Agents search, read, and contribute instructions that persist across sessions and repositories.
|
|
25
|
+
|
|
26
|
+
## Verify Connection
|
|
27
|
+
|
|
28
|
+
\`\`\`json
|
|
29
|
+
{"method": "health_check", "params": {}}
|
|
30
|
+
\`\`\`
|
|
31
|
+
|
|
32
|
+
Success → skip to "How to Use" below. Error → see "Setup" at the end.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## How to Use
|
|
37
|
+
|
|
38
|
+
### Search First (always)
|
|
39
|
+
|
|
40
|
+
**Before creating, promoting, or rewriting instructions, search for existing ones:**
|
|
41
|
+
|
|
42
|
+
\`\`\`json
|
|
43
|
+
{"method": "index_search", "params": {"keywords": ["deployment", "docker"]}}
|
|
44
|
+
\`\`\`
|
|
45
|
+
|
|
46
|
+
Then retrieve the full content of a match:
|
|
47
|
+
|
|
48
|
+
\`\`\`json
|
|
49
|
+
{"method": "index_dispatch", "params": {"action": "get", "id": "instruction-id-from-search"}}
|
|
50
|
+
\`\`\`
|
|
51
|
+
|
|
52
|
+
Search when the task involves patterns, standards, prior approaches, governance, shared guidance, or cross-repo learnings.
|
|
53
|
+
|
|
54
|
+
### Browse & Discover
|
|
55
|
+
|
|
56
|
+
| Task | Tool | Params |
|
|
57
|
+
|------|------|--------|
|
|
58
|
+
| List all instructions | \`index_dispatch\` | \`{"action": "list"}\` |
|
|
59
|
+
| Browse categories | \`index_dispatch\` | \`{"action": "categories"}\` |
|
|
60
|
+
| Search by keywords | \`index_search\` | \`{"keywords": ["term1", "term2"]}\` |
|
|
61
|
+
| Get by ID | \`index_dispatch\` | \`{"action": "get", "id": "..."}\` |
|
|
62
|
+
| Server health | \`health_check\` | \`{}\` |
|
|
63
|
+
| All available tools | \`meta_tools\` | \`{}\` |
|
|
64
|
+
| Help & overview | \`help_overview\` | \`{}\` |
|
|
65
|
+
|
|
66
|
+
### When to Use Index Server
|
|
67
|
+
|
|
68
|
+
**Use for:** Cross-repo patterns, architecture decisions, coding standards, troubleshooting runbooks, security policies, onboarding guides, and validated learnings from past sessions.
|
|
69
|
+
|
|
70
|
+
**Don't use for:** Reading current file contents (use repo files directly), ephemeral task notes, or repo-private secrets.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Contributing Knowledge
|
|
75
|
+
|
|
76
|
+
### Search → Validate Locally → Promote
|
|
77
|
+
|
|
78
|
+
1. **Search first** — check if similar guidance already exists
|
|
79
|
+
2. **Start local** — create new instructions in your repo's \`.instructions/\` directory
|
|
80
|
+
3. **Validate** — use across multiple sessions to prove value
|
|
81
|
+
4. **Promote** — move proven patterns to the shared index:
|
|
82
|
+
|
|
83
|
+
\`\`\`json
|
|
84
|
+
{"method": "promote_from_repo", "params": {"repoPath": "/path/to/repo"}}
|
|
85
|
+
\`\`\`
|
|
86
|
+
|
|
87
|
+
Or add directly:
|
|
88
|
+
|
|
89
|
+
\`\`\`json
|
|
90
|
+
{"method": "index_add", "params": {"entry": {"id": "my-guide", "title": "My Guide", "body": "Content..."}, "lax": true}}
|
|
91
|
+
\`\`\`
|
|
92
|
+
|
|
93
|
+
### Maintenance
|
|
94
|
+
|
|
95
|
+
- \`index_groom\` — clean duplicates and stale entries
|
|
96
|
+
- \`index_governanceUpdate\` — deprecate outdated content (don't silently delete)
|
|
97
|
+
- \`feedback_dispatch\` with action="submit" — report issues or request features
|
|
98
|
+
- \`usage_track\` — signal when guidance was helpful or outdated
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Copilot Instructions Setup
|
|
103
|
+
|
|
104
|
+
Add these to your copilot instructions so agents always know about the knowledge base.
|
|
105
|
+
|
|
106
|
+
### Global (~/.github/copilot-instructions.md)
|
|
107
|
+
|
|
108
|
+
\`\`\`markdown
|
|
109
|
+
## Index Server
|
|
110
|
+
- If index-server MCP tools are available, use them as a shared knowledge base for validated cross-repo patterns and standards.
|
|
111
|
+
- Search before creating: use index_search with 2-5 keywords, then index_dispatch with action="get" for details.
|
|
112
|
+
- After learning something reusable, add it with index_add or promote from a repo with promote_from_repo.
|
|
113
|
+
- Index entries are promoted snapshots — always prefer current repo files over index content.
|
|
114
|
+
\`\`\`
|
|
115
|
+
|
|
116
|
+
### Per-Repo (.github/copilot-instructions.md)
|
|
117
|
+
|
|
118
|
+
\`\`\`markdown
|
|
119
|
+
## Index Server Integration
|
|
120
|
+
- Search order: repo files → .instructions/ → index-server → external docs
|
|
121
|
+
- Search before add/promote: always search for existing guidance before creating new instructions.
|
|
122
|
+
- To retrieve: index_search → index_dispatch with action="get" and the instruction ID
|
|
123
|
+
- To contribute: validate locally in .instructions/ first, then promote with promote_from_repo
|
|
124
|
+
- To maintain: use index_groom to clean duplicates, index_governanceUpdate to deprecate stale content
|
|
125
|
+
- Current repo state always wins over promoted index snapshots
|
|
126
|
+
\`\`\`
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Setup (if not yet configured)
|
|
131
|
+
|
|
132
|
+
### VS Code (.vscode/mcp.json)
|
|
133
|
+
|
|
134
|
+
\`\`\`json
|
|
135
|
+
{"servers": {"index-server": {"type": "stdio", "command": "npx", "args": ["@jagilber-org/index-server", "--dashboard"]}}}
|
|
136
|
+
\`\`\`
|
|
137
|
+
|
|
138
|
+
### Copilot CLI (~/.copilot/mcp-config.json)
|
|
139
|
+
|
|
140
|
+
\`\`\`json
|
|
141
|
+
{"mcpServers": {"index-server": {"type": "stdio", "command": "npx", "args": ["@jagilber-org/index-server", "--dashboard"], "tools": ["*"]}}}
|
|
142
|
+
\`\`\`
|
|
143
|
+
|
|
144
|
+
### Claude Desktop (claude_desktop_config.json)
|
|
145
|
+
|
|
146
|
+
\`\`\`json
|
|
147
|
+
{"mcpServers": {"index-server": {"type": "stdio", "command": "npx", "args": ["@jagilber-org/index-server", "--dashboard"], "tools": ["*"]}}}
|
|
148
|
+
\`\`\`
|
|
149
|
+
|
|
150
|
+
### Docker
|
|
151
|
+
|
|
152
|
+
\`\`\`bash
|
|
153
|
+
docker compose up # HTTP on :8787
|
|
154
|
+
\`\`\`
|
|
155
|
+
|
|
156
|
+
Restart your MCP client after configuration changes. Verify with \`health_check\`.
|
|
157
|
+
|
|
158
|
+
For full configuration options: see \`docs/mcp_configuration.md\` and \`docs/configuration.md\`.`,
|
|
159
|
+
audience: 'agents',
|
|
160
|
+
requirement: 'required',
|
|
161
|
+
priority: 100,
|
|
162
|
+
categories: ['bootstrap', 'mcp-activation', 'quick-start', 'documentation'],
|
|
163
|
+
owner: 'system',
|
|
164
|
+
version: 3,
|
|
165
|
+
schemaVersion: '4',
|
|
166
|
+
semanticSummary: 'Index Server quick start: search-first workflow, knowledge contribution, copilot instructions setup, and MCP client configuration for AI agents'
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
file: '001-lifecycle-bootstrap.json',
|
|
171
|
+
id: '001-lifecycle-bootstrap',
|
|
172
|
+
json: {
|
|
173
|
+
id: '001-lifecycle-bootstrap',
|
|
174
|
+
title: 'Lifecycle Bootstrap: Local-First Instruction Strategy',
|
|
175
|
+
body: 'Purpose: Early lifecycle guidance after bootstrap confirmation. Keep index minimal; prefer local-first P0/P1 additions; promote only after stability.',
|
|
176
|
+
audience: 'agents',
|
|
177
|
+
requirement: 'recommended',
|
|
178
|
+
priorityTier: 'p1',
|
|
179
|
+
categories: ['bootstrap', 'lifecycle'],
|
|
180
|
+
owner: 'system',
|
|
181
|
+
version: 1,
|
|
182
|
+
schemaVersion: '4',
|
|
183
|
+
semanticSummary: 'Lifecycle and promotion guardrails after bootstrap confirmation',
|
|
184
|
+
reviewIntervalDays: 120
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
];
|
|
188
|
+
function computeCanonicalHash() {
|
|
189
|
+
const canonical = CANONICAL_SEEDS.map(s => ({ id: s.id, file: s.file, json: s.json })).sort((a, b) => a.id.localeCompare(b.id));
|
|
190
|
+
return crypto_1.default.createHash('sha256').update(JSON.stringify(canonical), 'utf8').digest('hex');
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Run automatic bootstrap seeding if enabled. Creates canonical seed files only when they are
|
|
194
|
+
* absent — never overwrites existing content. Safe under concurrent multi-process startup.
|
|
195
|
+
* @returns A {@link SeedSummary} describing what was created, skipped, or already present
|
|
196
|
+
*/
|
|
197
|
+
function autoSeedBootstrap() {
|
|
198
|
+
const cfg = (0, runtimeConfig_1.getRuntimeConfig)().bootstrapSeed;
|
|
199
|
+
const disabled = !cfg.autoSeed;
|
|
200
|
+
const dir = safeInstructionsDir();
|
|
201
|
+
const summary = { dir, created: [], existing: [], skipped: [], disabled, hash: computeCanonicalHash() };
|
|
202
|
+
if (disabled) {
|
|
203
|
+
summary.reason = 'disabled_by_env';
|
|
204
|
+
return summary;
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
208
|
+
}
|
|
209
|
+
catch { /* ignore */ }
|
|
210
|
+
// Probe directory existence (previously stored entries unused; keep check for side effects)
|
|
211
|
+
try {
|
|
212
|
+
fs_1.default.readdirSync(dir);
|
|
213
|
+
}
|
|
214
|
+
catch { /* ignore */ }
|
|
215
|
+
for (const seed of CANONICAL_SEEDS) {
|
|
216
|
+
const target = path_1.default.join(dir, seed.file);
|
|
217
|
+
const exists = fs_1.default.existsSync(target);
|
|
218
|
+
if (exists) {
|
|
219
|
+
summary.existing.push(seed.file);
|
|
220
|
+
summary.skipped.push(seed.file);
|
|
221
|
+
continue; // do not overwrite
|
|
222
|
+
}
|
|
223
|
+
// Directory empty OR missing seed triggers creation.
|
|
224
|
+
try {
|
|
225
|
+
const tmp = path_1.default.join(dir, `.${seed.file}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`);
|
|
226
|
+
fs_1.default.writeFileSync(tmp, JSON.stringify(seed.json, null, 2), { encoding: 'utf8' });
|
|
227
|
+
fs_1.default.renameSync(tmp, target);
|
|
228
|
+
summary.created.push(seed.file);
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
summary.reason = `partial_failure ${(e instanceof Error) ? e.message : String(e)}`;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if ((0, runtimeConfig_1.getRuntimeConfig)().bootstrapSeed.verbose) {
|
|
235
|
+
try {
|
|
236
|
+
process.stderr.write(`[seed] dir="${dir}" created=${summary.created.length} existing=${summary.existing.length} disabled=${summary.disabled} hash=${summary.hash}\n`);
|
|
237
|
+
}
|
|
238
|
+
catch { /* ignore */ }
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
(0, logger_1.logInfo)('[seedBootstrap] Seed summary', summary);
|
|
242
|
+
}
|
|
243
|
+
catch { /* ignore */ }
|
|
244
|
+
return summary;
|
|
245
|
+
}
|
|
246
|
+
function safeInstructionsDir() {
|
|
247
|
+
try {
|
|
248
|
+
return (0, indexContext_1.getInstructionsDir)();
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
return path_1.default.join(process.cwd(), 'instructions');
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// Test helper re-export for direct validation
|
|
255
|
+
/**
|
|
256
|
+
* Return the list of canonical seed file/id pairs (without JSON bodies) for test assertions.
|
|
257
|
+
* @returns Array of `{ file, id }` objects for each canonical seed
|
|
258
|
+
*/
|
|
259
|
+
function _getCanonicalSeeds() { return CANONICAL_SEEDS.map(s => ({ file: s.file, id: s.id })); }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage backend factory.
|
|
3
|
+
*
|
|
4
|
+
* Creates the appropriate IInstructionStore implementation based on config.
|
|
5
|
+
* Default: JsonFileStore (json). Experimental: SqliteStore (sqlite).
|
|
6
|
+
*/
|
|
7
|
+
import type { IInstructionStore } from './types.js';
|
|
8
|
+
export type StorageBackend = 'json' | 'sqlite';
|
|
9
|
+
/**
|
|
10
|
+
* Create a storage backend instance.
|
|
11
|
+
*
|
|
12
|
+
* @param backend - Override backend type (default: from config).
|
|
13
|
+
* @param dir - Override instruction directory (default: from config).
|
|
14
|
+
* @param sqlitePath - Override SQLite DB path (default: from config).
|
|
15
|
+
* @returns An IInstructionStore implementation.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createStore(backend?: StorageBackend, dir?: string, sqlitePath?: string): IInstructionStore;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Storage backend factory.
|
|
4
|
+
*
|
|
5
|
+
* Creates the appropriate IInstructionStore implementation based on config.
|
|
6
|
+
* Default: JsonFileStore (json). Experimental: SqliteStore (sqlite).
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.createStore = createStore;
|
|
10
|
+
const runtimeConfig_js_1 = require("../../config/runtimeConfig.js");
|
|
11
|
+
const jsonFileStore_js_1 = require("./jsonFileStore.js");
|
|
12
|
+
const sqliteStore_js_1 = require("./sqliteStore.js");
|
|
13
|
+
/**
|
|
14
|
+
* Create a storage backend instance.
|
|
15
|
+
*
|
|
16
|
+
* @param backend - Override backend type (default: from config).
|
|
17
|
+
* @param dir - Override instruction directory (default: from config).
|
|
18
|
+
* @param sqlitePath - Override SQLite DB path (default: from config).
|
|
19
|
+
* @returns An IInstructionStore implementation.
|
|
20
|
+
*/
|
|
21
|
+
function createStore(backend, dir, sqlitePath) {
|
|
22
|
+
const config = (0, runtimeConfig_js_1.getRuntimeConfig)();
|
|
23
|
+
const resolvedBackend = backend ?? config.storage?.backend ?? 'json';
|
|
24
|
+
const resolvedDir = dir ?? config.index?.baseDir;
|
|
25
|
+
switch (resolvedBackend) {
|
|
26
|
+
case 'sqlite': {
|
|
27
|
+
console.warn('[storage] ⚠️ EXPERIMENTAL: SQLite backend is enabled. This feature has limited testing and may have data-loss or compatibility issues. Not recommended for production use.');
|
|
28
|
+
const dbPath = sqlitePath ?? config.storage?.sqlitePath ?? 'data/index.db';
|
|
29
|
+
return new sqliteStore_js_1.SqliteStore(dbPath);
|
|
30
|
+
}
|
|
31
|
+
case 'json':
|
|
32
|
+
default:
|
|
33
|
+
return new jsonFileStore_js_1.JsonFileStore(resolvedDir);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared governance hashing utilities for storage backends.
|
|
3
|
+
*
|
|
4
|
+
* Both JsonFileStore and SqliteStore must produce identical governance hashes
|
|
5
|
+
* for the same set of entries. This module ensures that.
|
|
6
|
+
*/
|
|
7
|
+
import { InstructionEntry } from '../../models/instruction.js';
|
|
8
|
+
/** @internal Governance projection for deterministic hashing. */
|
|
9
|
+
export declare function projectGovernance(e: InstructionEntry): Record<string, unknown>;
|
|
10
|
+
/** Compute deterministic governance hash from an array of entries. */
|
|
11
|
+
export declare function computeGovernanceHashFromEntries(entries: InstructionEntry[]): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared governance hashing utilities for storage backends.
|
|
4
|
+
*
|
|
5
|
+
* Both JsonFileStore and SqliteStore must produce identical governance hashes
|
|
6
|
+
* for the same set of entries. This module ensures that.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.projectGovernance = projectGovernance;
|
|
13
|
+
exports.computeGovernanceHashFromEntries = computeGovernanceHashFromEntries;
|
|
14
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
15
|
+
/** @internal Governance projection for deterministic hashing. */
|
|
16
|
+
function projectGovernance(e) {
|
|
17
|
+
return {
|
|
18
|
+
id: e.id,
|
|
19
|
+
title: e.title,
|
|
20
|
+
version: e.version ?? '0.0.0',
|
|
21
|
+
owner: e.owner ?? 'unowned',
|
|
22
|
+
priorityTier: e.priorityTier ?? 'P4',
|
|
23
|
+
nextReviewDue: e.nextReviewDue ?? '',
|
|
24
|
+
semanticSummarySha256: e.semanticSummary
|
|
25
|
+
? crypto_1.default.createHash('sha256').update(e.semanticSummary).digest('hex')
|
|
26
|
+
: '',
|
|
27
|
+
changeLogLength: e.changeLog?.length ?? 0,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Compute deterministic governance hash from an array of entries. */
|
|
31
|
+
function computeGovernanceHashFromEntries(entries) {
|
|
32
|
+
const sorted = [...entries].sort((a, b) => a.id.localeCompare(b.id));
|
|
33
|
+
const projection = sorted.map(e => JSON.stringify(projectGovernance(e)));
|
|
34
|
+
return crypto_1.default.createHash('sha256').update(projection.join('\n')).digest('hex');
|
|
35
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage — Instruction storage abstraction layer.
|
|
3
|
+
*
|
|
4
|
+
* Exports the IInstructionStore interface and backend implementations.
|
|
5
|
+
* Backend selection is controlled by INDEX_SERVER_STORAGE_BACKEND env var.
|
|
6
|
+
*/
|
|
7
|
+
export type { IInstructionStore, ListOptions, QueryOptions, ScopedListOptions, SearchOptions, SearchResult, UsagePersistRecord, UsageTrackOptions, LoadResult, } from './types.js';
|
|
8
|
+
export { JsonFileStore } from './jsonFileStore.js';
|
|
9
|
+
export { SqliteStore } from './sqliteStore.js';
|
|
10
|
+
export { createStore } from './factory.js';
|
|
11
|
+
export { computeGovernanceHashFromEntries, projectGovernance } from './hashUtils.js';
|
|
12
|
+
export type { StorageBackend } from './factory.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Storage — Instruction storage abstraction layer.
|
|
4
|
+
*
|
|
5
|
+
* Exports the IInstructionStore interface and backend implementations.
|
|
6
|
+
* Backend selection is controlled by INDEX_SERVER_STORAGE_BACKEND env var.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.projectGovernance = exports.computeGovernanceHashFromEntries = exports.createStore = exports.SqliteStore = exports.JsonFileStore = void 0;
|
|
10
|
+
var jsonFileStore_js_1 = require("./jsonFileStore.js");
|
|
11
|
+
Object.defineProperty(exports, "JsonFileStore", { enumerable: true, get: function () { return jsonFileStore_js_1.JsonFileStore; } });
|
|
12
|
+
var sqliteStore_js_1 = require("./sqliteStore.js");
|
|
13
|
+
Object.defineProperty(exports, "SqliteStore", { enumerable: true, get: function () { return sqliteStore_js_1.SqliteStore; } });
|
|
14
|
+
var factory_js_1 = require("./factory.js");
|
|
15
|
+
Object.defineProperty(exports, "createStore", { enumerable: true, get: function () { return factory_js_1.createStore; } });
|
|
16
|
+
var hashUtils_js_1 = require("./hashUtils.js");
|
|
17
|
+
Object.defineProperty(exports, "computeGovernanceHashFromEntries", { enumerable: true, get: function () { return hashUtils_js_1.computeGovernanceHashFromEntries; } });
|
|
18
|
+
Object.defineProperty(exports, "projectGovernance", { enumerable: true, get: function () { return hashUtils_js_1.projectGovernance; } });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JsonFileStore — JSON-file-per-instruction storage backend.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the existing file-based storage pattern: each instruction is a
|
|
5
|
+
* separate .json file in a directory. This is the default backend.
|
|
6
|
+
*
|
|
7
|
+
* Implements IInstructionStore for the storage abstraction layer.
|
|
8
|
+
*/
|
|
9
|
+
import { InstructionEntry } from '../../models/instruction.js';
|
|
10
|
+
import type { IInstructionStore, ListOptions, QueryOptions, ScopedListOptions, SearchOptions, SearchResult, LoadResult } from './types.js';
|
|
11
|
+
export declare class JsonFileStore implements IInstructionStore {
|
|
12
|
+
private readonly dir;
|
|
13
|
+
private cache;
|
|
14
|
+
private loaded;
|
|
15
|
+
/**
|
|
16
|
+
* @param dir - Directory containing instruction .json files.
|
|
17
|
+
*/
|
|
18
|
+
constructor(dir: string);
|
|
19
|
+
load(): LoadResult;
|
|
20
|
+
close(): void;
|
|
21
|
+
get(id: string): InstructionEntry | null;
|
|
22
|
+
write(entry: InstructionEntry): void;
|
|
23
|
+
remove(id: string): void;
|
|
24
|
+
list(opts?: ListOptions): InstructionEntry[];
|
|
25
|
+
query(opts: QueryOptions): InstructionEntry[];
|
|
26
|
+
listScoped(opts: ScopedListOptions): InstructionEntry[];
|
|
27
|
+
search(opts: SearchOptions): SearchResult[];
|
|
28
|
+
categories(): Map<string, number>;
|
|
29
|
+
computeHash(): string;
|
|
30
|
+
count(): number;
|
|
31
|
+
private ensureLoaded;
|
|
32
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JsonFileStore — JSON-file-per-instruction storage backend.
|
|
4
|
+
*
|
|
5
|
+
* Wraps the existing file-based storage pattern: each instruction is a
|
|
6
|
+
* separate .json file in a directory. This is the default backend.
|
|
7
|
+
*
|
|
8
|
+
* Implements IInstructionStore for the storage abstraction layer.
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.JsonFileStore = void 0;
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
18
|
+
const hashUtils_js_1 = require("./hashUtils.js");
|
|
19
|
+
class JsonFileStore {
|
|
20
|
+
dir;
|
|
21
|
+
cache = new Map();
|
|
22
|
+
loaded = false;
|
|
23
|
+
/**
|
|
24
|
+
* @param dir - Directory containing instruction .json files.
|
|
25
|
+
*/
|
|
26
|
+
constructor(dir) {
|
|
27
|
+
this.dir = dir;
|
|
28
|
+
if (!fs_1.default.existsSync(dir)) {
|
|
29
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// ── Lifecycle ──────────────────────────────────────────────────────
|
|
33
|
+
load() {
|
|
34
|
+
const errors = [];
|
|
35
|
+
const entries = [];
|
|
36
|
+
let scanned = 0;
|
|
37
|
+
let skipped = 0;
|
|
38
|
+
const files = fs_1.default.readdirSync(this.dir).filter(f => f.endsWith('.json') && !f.startsWith('_') && !f.startsWith('.'));
|
|
39
|
+
scanned = files.length;
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
try {
|
|
42
|
+
const raw = fs_1.default.readFileSync(path_1.default.join(this.dir, file), 'utf-8');
|
|
43
|
+
const parsed = JSON.parse(raw.replace(/^\uFEFF/, ''));
|
|
44
|
+
// Handle arrays (some files contain instruction arrays)
|
|
45
|
+
const items = Array.isArray(parsed) ? parsed : [parsed];
|
|
46
|
+
for (const item of items) {
|
|
47
|
+
const entry = item;
|
|
48
|
+
if (!entry.id || !entry.title || !entry.body) {
|
|
49
|
+
skipped++;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
entries.push(entry);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
skipped++;
|
|
57
|
+
errors.push({ file, error: err instanceof Error ? err.message : 'Unknown parse error' });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Deduplicate by ID (last-write-wins)
|
|
61
|
+
const byId = new Map();
|
|
62
|
+
for (const e of entries) {
|
|
63
|
+
byId.set(e.id, e);
|
|
64
|
+
}
|
|
65
|
+
const deduped = Array.from(byId.values());
|
|
66
|
+
this.cache = byId;
|
|
67
|
+
this.loaded = true;
|
|
68
|
+
return {
|
|
69
|
+
entries: deduped,
|
|
70
|
+
hash: (0, hashUtils_js_1.computeGovernanceHashFromEntries)(deduped),
|
|
71
|
+
errors,
|
|
72
|
+
debug: { scanned, accepted: deduped.length, skipped },
|
|
73
|
+
summary: {
|
|
74
|
+
scanned,
|
|
75
|
+
accepted: deduped.length,
|
|
76
|
+
skipped,
|
|
77
|
+
reasons: errors.length > 0 ? { 'parse-error': errors.length } : {},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
close() {
|
|
82
|
+
this.cache.clear();
|
|
83
|
+
this.loaded = false;
|
|
84
|
+
}
|
|
85
|
+
// ── CRUD ───────────────────────────────────────────────────────────
|
|
86
|
+
get(id) {
|
|
87
|
+
this.ensureLoaded();
|
|
88
|
+
return this.cache.get(id) ?? null;
|
|
89
|
+
}
|
|
90
|
+
write(entry) {
|
|
91
|
+
// Write to disk
|
|
92
|
+
const filePath = path_1.default.join(this.dir, `${entry.id}.json`);
|
|
93
|
+
const tmpPath = `${filePath}.${crypto_1.default.randomBytes(4).toString('hex')}.tmp`;
|
|
94
|
+
fs_1.default.writeFileSync(tmpPath, JSON.stringify(entry, null, 2), 'utf-8');
|
|
95
|
+
fs_1.default.renameSync(tmpPath, filePath);
|
|
96
|
+
// Update in-memory cache
|
|
97
|
+
this.cache.set(entry.id, entry);
|
|
98
|
+
this.loaded = true;
|
|
99
|
+
}
|
|
100
|
+
remove(id) {
|
|
101
|
+
const filePath = path_1.default.join(this.dir, `${id}.json`);
|
|
102
|
+
try {
|
|
103
|
+
if (fs_1.default.existsSync(filePath)) {
|
|
104
|
+
fs_1.default.unlinkSync(filePath);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// No-op on failure (file may already be gone)
|
|
109
|
+
}
|
|
110
|
+
this.cache.delete(id);
|
|
111
|
+
}
|
|
112
|
+
// ── Queries ────────────────────────────────────────────────────────
|
|
113
|
+
list(opts) {
|
|
114
|
+
this.ensureLoaded();
|
|
115
|
+
let result = Array.from(this.cache.values());
|
|
116
|
+
if (opts?.category) {
|
|
117
|
+
result = result.filter(e => e.categories?.includes(opts.category));
|
|
118
|
+
}
|
|
119
|
+
if (opts?.contentType) {
|
|
120
|
+
result = result.filter(e => e.contentType === opts.contentType);
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
query(opts) {
|
|
125
|
+
this.ensureLoaded();
|
|
126
|
+
let result = Array.from(this.cache.values());
|
|
127
|
+
if (opts.text) {
|
|
128
|
+
const lower = opts.text.toLowerCase();
|
|
129
|
+
result = result.filter(e => e.title.toLowerCase().includes(lower) ||
|
|
130
|
+
e.body.toLowerCase().includes(lower) ||
|
|
131
|
+
(e.semanticSummary && e.semanticSummary.toLowerCase().includes(lower)));
|
|
132
|
+
}
|
|
133
|
+
if (opts.categoriesAny?.length) {
|
|
134
|
+
const set = new Set(opts.categoriesAny);
|
|
135
|
+
result = result.filter(e => e.categories?.some(c => set.has(c)));
|
|
136
|
+
}
|
|
137
|
+
if (opts.categoriesAll?.length) {
|
|
138
|
+
result = result.filter(e => opts.categoriesAll.every(c => e.categories?.includes(c)));
|
|
139
|
+
}
|
|
140
|
+
if (opts.excludeCategories?.length) {
|
|
141
|
+
const excl = new Set(opts.excludeCategories);
|
|
142
|
+
result = result.filter(e => !e.categories?.some(c => excl.has(c)));
|
|
143
|
+
}
|
|
144
|
+
if (opts.contentType) {
|
|
145
|
+
result = result.filter(e => e.contentType === opts.contentType);
|
|
146
|
+
}
|
|
147
|
+
if (opts.priorityMin !== undefined) {
|
|
148
|
+
result = result.filter(e => e.priority >= opts.priorityMin);
|
|
149
|
+
}
|
|
150
|
+
if (opts.priorityMax !== undefined) {
|
|
151
|
+
result = result.filter(e => e.priority <= opts.priorityMax);
|
|
152
|
+
}
|
|
153
|
+
if (opts.priorityTiers?.length) {
|
|
154
|
+
const tiers = new Set(opts.priorityTiers);
|
|
155
|
+
result = result.filter(e => e.priorityTier && tiers.has(e.priorityTier));
|
|
156
|
+
}
|
|
157
|
+
if (opts.requirements?.length) {
|
|
158
|
+
const reqs = new Set(opts.requirements);
|
|
159
|
+
result = result.filter(e => reqs.has(e.requirement));
|
|
160
|
+
}
|
|
161
|
+
// Pagination
|
|
162
|
+
if (opts.offset) {
|
|
163
|
+
result = result.slice(opts.offset);
|
|
164
|
+
}
|
|
165
|
+
if (opts.limit) {
|
|
166
|
+
result = result.slice(0, opts.limit);
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
listScoped(opts) {
|
|
171
|
+
this.ensureLoaded();
|
|
172
|
+
let result = Array.from(this.cache.values());
|
|
173
|
+
if (opts.userId) {
|
|
174
|
+
result = result.filter(e => e.userId === opts.userId || e.audience === 'all');
|
|
175
|
+
}
|
|
176
|
+
if (opts.workspaceId) {
|
|
177
|
+
result = result.filter(e => e.workspaceId === opts.workspaceId || e.audience === 'all');
|
|
178
|
+
}
|
|
179
|
+
if (opts.teamIds?.length) {
|
|
180
|
+
const teams = new Set(opts.teamIds);
|
|
181
|
+
result = result.filter(e => e.audience === 'all' ||
|
|
182
|
+
e.teamIds?.some(t => teams.has(t)));
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
search(opts) {
|
|
187
|
+
this.ensureLoaded();
|
|
188
|
+
const results = [];
|
|
189
|
+
for (const entry of this.cache.values()) {
|
|
190
|
+
let score = 0;
|
|
191
|
+
const titleLower = entry.title.toLowerCase();
|
|
192
|
+
const bodyLower = entry.body.toLowerCase();
|
|
193
|
+
const catStr = (entry.categories ?? []).join(' ').toLowerCase();
|
|
194
|
+
for (const kw of opts.keywords) {
|
|
195
|
+
const kwLower = opts.caseSensitive ? kw : kw.toLowerCase();
|
|
196
|
+
const title = opts.caseSensitive ? entry.title : titleLower;
|
|
197
|
+
const body = opts.caseSensitive ? entry.body : bodyLower;
|
|
198
|
+
if (title.includes(kwLower))
|
|
199
|
+
score += 3;
|
|
200
|
+
if (body.includes(kwLower))
|
|
201
|
+
score += 1;
|
|
202
|
+
if (opts.includeCategories && catStr.includes(kwLower))
|
|
203
|
+
score += 2;
|
|
204
|
+
}
|
|
205
|
+
if (score > 0) {
|
|
206
|
+
results.push({ id: entry.id, score });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
results.sort((a, b) => b.score - a.score);
|
|
210
|
+
if (opts.limit) {
|
|
211
|
+
return results.slice(0, opts.limit);
|
|
212
|
+
}
|
|
213
|
+
return results;
|
|
214
|
+
}
|
|
215
|
+
categories() {
|
|
216
|
+
this.ensureLoaded();
|
|
217
|
+
const counts = new Map();
|
|
218
|
+
for (const entry of this.cache.values()) {
|
|
219
|
+
for (const cat of entry.categories ?? []) {
|
|
220
|
+
counts.set(cat, (counts.get(cat) ?? 0) + 1);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return counts;
|
|
224
|
+
}
|
|
225
|
+
// ── Integrity ──────────────────────────────────────────────────────
|
|
226
|
+
computeHash() {
|
|
227
|
+
this.ensureLoaded();
|
|
228
|
+
return (0, hashUtils_js_1.computeGovernanceHashFromEntries)(Array.from(this.cache.values()));
|
|
229
|
+
}
|
|
230
|
+
count() {
|
|
231
|
+
this.ensureLoaded();
|
|
232
|
+
return this.cache.size;
|
|
233
|
+
}
|
|
234
|
+
// ── Internal ───────────────────────────────────────────────────────
|
|
235
|
+
ensureLoaded() {
|
|
236
|
+
if (!this.loaded) {
|
|
237
|
+
this.load();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.JsonFileStore = JsonFileStore;
|