shieldcortex 2.20.0 → 3.0.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/README.md +228 -380
- package/dashboard/.next/standalone/dashboard/.next/BUILD_ID +1 -1
- package/dashboard/.next/standalone/dashboard/.next/build-manifest.json +5 -5
- package/dashboard/.next/standalone/dashboard/.next/prerender-manifest.json +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error/page/build-manifest.json +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.html +2 -2
- package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found/page/build-manifest.json +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.html +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.rsc +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/dashboard/.next/standalone/dashboard/.next/server/app/index.html +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/index.rsc +4 -4
- package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/_full.segment.rsc +4 -4
- package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/_index.segment.rsc +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- package/dashboard/.next/standalone/dashboard/.next/server/app/page/build-manifest.json +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/app/page/react-loadable-manifest.json +2 -2
- package/dashboard/.next/standalone/dashboard/.next/server/app/page.js.nft.json +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/app/page_client-reference-manifest.js +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/chunks/ssr/9f1d4_next_dist_esm_build_templates_app-page_f7d4354e.js +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/chunks/ssr/9f1d4_next_dist_fe6a9400._.js +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/chunks/ssr/[root-of-the-server]__c95102dd._.js +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/chunks/ssr/dashboard_1cd9d700._.js +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/chunks/ssr/dashboard_3051539d._.js +11 -0
- package/dashboard/.next/standalone/dashboard/.next/server/middleware-build-manifest.js +3 -3
- package/dashboard/.next/standalone/dashboard/.next/server/pages/404.html +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/pages/500.html +2 -2
- package/dashboard/.next/standalone/dashboard/.next/server/server-reference-manifest.js +1 -1
- package/dashboard/.next/standalone/dashboard/.next/server/server-reference-manifest.json +1 -1
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/{d334b69bff7779be.js → 215ce64499260c25.js} +1 -1
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/{acf32ffeb20e4854.js → 39e59c45c12073c2.js} +1 -1
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/3cc7e8d4f73cf5d2.js +1 -0
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/{da96df828f9a0188.js → 6ba7a5c1a80a6791.js} +1 -1
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/{fc4e920d4281c89e.js → 7d08316952ccdcef.js} +1 -1
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/be6970da20a17c0b.js +9 -0
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/da64d159c042f5ae.js +1 -0
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/e63d2228780629dd.css +3 -0
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/f69fd1c5e71fbbfd.js +1 -0
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/{26118d592a545e00.js → fa5217550a8ab9a6.js} +2 -2
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/{turbopack-7cf1ece01d32a474.js → turbopack-c2d84e7d37269ac1.js} +1 -1
- package/dist/api/control.d.ts +0 -1
- package/dist/api/control.js +0 -1
- package/dist/api/events.d.ts +0 -1
- package/dist/api/events.js +0 -1
- package/dist/api/session-token.d.ts +0 -1
- package/dist/api/session-token.js +0 -1
- package/dist/api/version.d.ts +0 -1
- package/dist/api/version.js +0 -1
- package/dist/api/visualization-server.d.ts +0 -1
- package/dist/api/visualization-server.js +117 -3
- package/dist/audit/env-scanner.d.ts +0 -1
- package/dist/audit/env-scanner.js +0 -1
- package/dist/audit/index.d.ts +0 -1
- package/dist/audit/index.js +0 -1
- package/dist/audit/mcp-config-scanner.d.ts +0 -1
- package/dist/audit/mcp-config-scanner.js +0 -1
- package/dist/audit/memory-scanner.d.ts +0 -1
- package/dist/audit/memory-scanner.js +0 -1
- package/dist/audit/report-formatter.d.ts +0 -1
- package/dist/audit/report-formatter.js +0 -1
- package/dist/audit/rules-file-scanner.d.ts +0 -1
- package/dist/audit/rules-file-scanner.js +0 -1
- package/dist/audit/types.d.ts +0 -1
- package/dist/audit/types.js +0 -1
- package/dist/cli/audit.d.ts +0 -1
- package/dist/cli/audit.js +0 -1
- package/dist/cli/doctor.d.ts +0 -1
- package/dist/cli/doctor.js +0 -1
- package/dist/cli/iron-dome.d.ts +0 -1
- package/dist/cli/iron-dome.js +0 -1
- package/dist/cloud/cli.d.ts +0 -1
- package/dist/cloud/cli.js +0 -1
- package/dist/cloud/config.d.ts +0 -1
- package/dist/cloud/config.js +1 -2
- package/dist/cloud/iron-dome-sync.d.ts +0 -1
- package/dist/cloud/iron-dome-sync.js +0 -1
- package/dist/cloud/quarantine-sync.d.ts +0 -1
- package/dist/cloud/quarantine-sync.js +0 -1
- package/dist/cloud/sync-queue.d.ts +0 -1
- package/dist/cloud/sync-queue.js +0 -1
- package/dist/cloud/sync.d.ts +0 -1
- package/dist/cloud/sync.js +0 -1
- package/dist/cloud/verify.d.ts +0 -1
- package/dist/cloud/verify.js +0 -1
- package/dist/context/project-context.d.ts +0 -1
- package/dist/context/project-context.js +0 -1
- package/dist/database/init.d.ts +0 -1
- package/dist/database/init.js +0 -1
- package/dist/defence/audit/export.d.ts +0 -1
- package/dist/defence/audit/export.js +0 -1
- package/dist/defence/audit/index.d.ts +0 -1
- package/dist/defence/audit/index.js +0 -1
- package/dist/defence/audit/logger.d.ts +0 -1
- package/dist/defence/audit/logger.js +0 -1
- package/dist/defence/audit/queries.d.ts +22 -1
- package/dist/defence/audit/queries.js +179 -1
- package/dist/defence/credential-leak/entropy.d.ts +0 -1
- package/dist/defence/credential-leak/entropy.js +0 -1
- package/dist/defence/credential-leak/index.d.ts +0 -1
- package/dist/defence/credential-leak/index.js +0 -1
- package/dist/defence/credential-leak/patterns.d.ts +0 -1
- package/dist/defence/credential-leak/patterns.js +0 -1
- package/dist/defence/custom-patterns/store.d.ts +0 -1
- package/dist/defence/custom-patterns/store.js +0 -1
- package/dist/defence/custom-rules/store.d.ts +0 -1
- package/dist/defence/custom-rules/store.js +0 -1
- package/dist/defence/firewall/anomaly-scorer.d.ts +0 -1
- package/dist/defence/firewall/anomaly-scorer.js +0 -1
- package/dist/defence/firewall/encoding-detector.d.ts +0 -1
- package/dist/defence/firewall/encoding-detector.js +0 -1
- package/dist/defence/firewall/index.d.ts +0 -1
- package/dist/defence/firewall/index.js +0 -1
- package/dist/defence/firewall/instruction-detector.d.ts +0 -1
- package/dist/defence/firewall/instruction-detector.js +0 -1
- package/dist/defence/firewall/privilege-detector.d.ts +0 -1
- package/dist/defence/firewall/privilege-detector.js +0 -1
- package/dist/defence/fragmentation/assembly-detector.d.ts +0 -1
- package/dist/defence/fragmentation/assembly-detector.js +0 -1
- package/dist/defence/fragmentation/entity-extractor.d.ts +0 -1
- package/dist/defence/fragmentation/entity-extractor.js +0 -1
- package/dist/defence/fragmentation/index.d.ts +0 -1
- package/dist/defence/fragmentation/index.js +0 -1
- package/dist/defence/fragmentation/temporal-analyzer.d.ts +0 -1
- package/dist/defence/fragmentation/temporal-analyzer.js +0 -1
- package/dist/defence/index.d.ts +0 -1
- package/dist/defence/index.js +0 -1
- package/dist/defence/input-sanitisation/index.d.ts +0 -1
- package/dist/defence/input-sanitisation/index.js +0 -1
- package/dist/defence/iron-dome/action-gate.d.ts +0 -1
- package/dist/defence/iron-dome/action-gate.js +0 -1
- package/dist/defence/iron-dome/audit.d.ts +0 -1
- package/dist/defence/iron-dome/audit.js +0 -1
- package/dist/defence/iron-dome/config.d.ts +0 -1
- package/dist/defence/iron-dome/config.js +0 -1
- package/dist/defence/iron-dome/confirmation-gate.d.ts +0 -1
- package/dist/defence/iron-dome/confirmation-gate.js +0 -1
- package/dist/defence/iron-dome/custom-policies.d.ts +0 -1
- package/dist/defence/iron-dome/custom-policies.js +0 -1
- package/dist/defence/iron-dome/gateway.d.ts +0 -1
- package/dist/defence/iron-dome/gateway.js +0 -1
- package/dist/defence/iron-dome/index.d.ts +0 -1
- package/dist/defence/iron-dome/index.js +0 -1
- package/dist/defence/iron-dome/injection-scanner.d.ts +0 -1
- package/dist/defence/iron-dome/injection-scanner.js +0 -1
- package/dist/defence/iron-dome/kill-switch.d.ts +0 -1
- package/dist/defence/iron-dome/kill-switch.js +0 -1
- package/dist/defence/iron-dome/pii-guard.d.ts +0 -1
- package/dist/defence/iron-dome/pii-guard.js +0 -1
- package/dist/defence/pipeline.d.ts +0 -1
- package/dist/defence/pipeline.js +0 -1
- package/dist/defence/quarantine/auto-expire.d.ts +0 -1
- package/dist/defence/quarantine/auto-expire.js +0 -1
- package/dist/defence/scanner/index.d.ts +0 -1
- package/dist/defence/scanner/index.js +0 -1
- package/dist/defence/scanner/scan-existing.d.ts +0 -1
- package/dist/defence/scanner/scan-existing.js +0 -1
- package/dist/defence/sensitivity/classifier.d.ts +0 -1
- package/dist/defence/sensitivity/classifier.js +0 -1
- package/dist/defence/sensitivity/index.d.ts +0 -1
- package/dist/defence/sensitivity/index.js +0 -1
- package/dist/defence/sensitivity/patterns.d.ts +0 -1
- package/dist/defence/sensitivity/patterns.js +0 -1
- package/dist/defence/sensitivity/redaction.d.ts +0 -1
- package/dist/defence/sensitivity/redaction.js +0 -1
- package/dist/defence/skill-scanner/deep-scan.d.ts +0 -1
- package/dist/defence/skill-scanner/deep-scan.js +0 -1
- package/dist/defence/skill-scanner/discover.d.ts +0 -1
- package/dist/defence/skill-scanner/discover.js +0 -1
- package/dist/defence/skill-scanner/index.d.ts +0 -1
- package/dist/defence/skill-scanner/index.js +0 -1
- package/dist/defence/skill-scanner/parser.d.ts +0 -1
- package/dist/defence/skill-scanner/parser.js +0 -1
- package/dist/defence/skill-scanner/patterns.d.ts +0 -1
- package/dist/defence/skill-scanner/patterns.js +0 -1
- package/dist/defence/skill-scanner/scan-skill.d.ts +0 -1
- package/dist/defence/skill-scanner/scan-skill.js +0 -1
- package/dist/defence/tool-response-scanner.d.ts +0 -1
- package/dist/defence/tool-response-scanner.js +0 -1
- package/dist/defence/trust/access-control.d.ts +0 -1
- package/dist/defence/trust/access-control.js +0 -1
- package/dist/defence/trust/agent-scorer.d.ts +0 -1
- package/dist/defence/trust/agent-scorer.js +0 -1
- package/dist/defence/trust/env-detector.d.ts +0 -1
- package/dist/defence/trust/env-detector.js +0 -1
- package/dist/defence/trust/index.d.ts +0 -1
- package/dist/defence/trust/index.js +0 -1
- package/dist/defence/trust/recall-filter.d.ts +0 -1
- package/dist/defence/trust/recall-filter.js +0 -1
- package/dist/defence/trust/source-scorer.d.ts +0 -1
- package/dist/defence/trust/source-scorer.js +0 -1
- package/dist/defence/types.d.ts +0 -1
- package/dist/defence/types.js +0 -1
- package/dist/embeddings/generator.d.ts +0 -1
- package/dist/embeddings/generator.js +0 -1
- package/dist/embeddings/index.d.ts +0 -1
- package/dist/embeddings/index.js +0 -1
- package/dist/embeddings/worker.d.ts +0 -1
- package/dist/embeddings/worker.js +0 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -1
- package/dist/events/webhooks.d.ts +0 -1
- package/dist/events/webhooks.js +0 -1
- package/dist/graph/backfill.d.ts +0 -1
- package/dist/graph/backfill.js +0 -1
- package/dist/graph/extract.d.ts +0 -1
- package/dist/graph/extract.js +0 -1
- package/dist/graph/resolve.d.ts +0 -1
- package/dist/graph/resolve.js +0 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -2
- package/dist/integrations/index.d.ts +0 -1
- package/dist/integrations/index.js +0 -1
- package/dist/integrations/langchain.d.ts +0 -1
- package/dist/integrations/langchain.js +0 -1
- package/dist/integrations/openclaw.d.ts +0 -1
- package/dist/integrations/openclaw.js +0 -1
- package/dist/integrations/universal.d.ts +0 -1
- package/dist/integrations/universal.js +0 -1
- package/dist/lib.d.ts +0 -1
- package/dist/lib.js +0 -1
- package/dist/license/cli.d.ts +0 -1
- package/dist/license/cli.js +0 -1
- package/dist/license/gate.d.ts +0 -1
- package/dist/license/gate.js +0 -1
- package/dist/license/index.d.ts +0 -1
- package/dist/license/index.js +0 -1
- package/dist/license/keys.d.ts +0 -1
- package/dist/license/keys.js +0 -1
- package/dist/license/store.d.ts +0 -1
- package/dist/license/store.js +0 -1
- package/dist/license/types.d.ts +0 -1
- package/dist/license/types.js +0 -1
- package/dist/license/validate.d.ts +0 -1
- package/dist/license/validate.js +0 -1
- package/dist/license/verify.d.ts +0 -1
- package/dist/license/verify.js +0 -1
- package/dist/memory/activation.d.ts +0 -1
- package/dist/memory/activation.js +0 -1
- package/dist/memory/consolidate.d.ts +0 -1
- package/dist/memory/consolidate.js +0 -1
- package/dist/memory/contradiction.d.ts +0 -1
- package/dist/memory/contradiction.js +0 -1
- package/dist/memory/decay.d.ts +0 -1
- package/dist/memory/decay.js +0 -1
- package/dist/memory/embedding-cache.d.ts +0 -1
- package/dist/memory/embedding-cache.js +0 -1
- package/dist/memory/embedding.d.ts +7 -2
- package/dist/memory/embedding.js +68 -7
- package/dist/memory/expiry.d.ts +0 -1
- package/dist/memory/expiry.js +0 -1
- package/dist/memory/salience.d.ts +0 -1
- package/dist/memory/salience.js +0 -1
- package/dist/memory/similarity.d.ts +0 -1
- package/dist/memory/similarity.js +0 -1
- package/dist/memory/store.d.ts +3 -1
- package/dist/memory/store.js +204 -123
- package/dist/memory/types.d.ts +21 -1
- package/dist/memory/types.js +0 -1
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -1
- package/dist/service/install.d.ts +0 -1
- package/dist/service/install.js +0 -1
- package/dist/service/templates.d.ts +0 -1
- package/dist/service/templates.js +0 -1
- package/dist/setup/claude-md.d.ts +0 -1
- package/dist/setup/claude-md.js +0 -1
- package/dist/setup/copilot.d.ts +0 -1
- package/dist/setup/copilot.js +0 -1
- package/dist/setup/doctor.d.ts +0 -1
- package/dist/setup/doctor.js +0 -1
- package/dist/setup/hooks.d.ts +3 -1
- package/dist/setup/hooks.js +76 -12
- package/dist/setup/migrate.d.ts +0 -1
- package/dist/setup/migrate.js +0 -1
- package/dist/setup/openclaw.d.ts +0 -1
- package/dist/setup/openclaw.js +0 -1
- package/dist/setup/quickstart.d.ts +8 -0
- package/dist/setup/quickstart.js +108 -0
- package/dist/setup/settings-hooks.d.ts +0 -1
- package/dist/setup/settings-hooks.js +0 -1
- package/dist/setup/status.d.ts +0 -1
- package/dist/setup/status.js +0 -1
- package/dist/setup/uninstall.d.ts +0 -1
- package/dist/setup/uninstall.js +0 -1
- package/dist/tools/context.d.ts +0 -1
- package/dist/tools/context.js +0 -1
- package/dist/tools/forget.d.ts +0 -1
- package/dist/tools/forget.js +0 -1
- package/dist/tools/graph.d.ts +0 -1
- package/dist/tools/graph.js +0 -1
- package/dist/tools/recall.d.ts +0 -1
- package/dist/tools/recall.js +1 -1
- package/dist/tools/remember.d.ts +0 -1
- package/dist/tools/remember.js +0 -1
- package/dist/worker/brain-worker.d.ts +1 -1
- package/dist/worker/brain-worker.js +9 -2
- package/dist/worker/link-discovery.d.ts +0 -1
- package/dist/worker/link-discovery.js +0 -1
- package/dist/worker/predictive-consolidation.d.ts +0 -1
- package/dist/worker/predictive-consolidation.js +0 -1
- package/dist/worker/types.d.ts +0 -1
- package/dist/worker/types.js +0 -1
- package/hooks/openclaw/cortex-memory/handler.ts +62 -8
- package/package.json +9 -8
- package/scripts/run-jest.mjs +45 -0
- package/dashboard/.next/standalone/dashboard/.next/server/chunks/ssr/dashboard_25b1b286._.js +0 -11
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/364656baa57adaa7.js +0 -1
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/6a6ccfb7834de00a.js +0 -9
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/6b11a7d29e9abffd.js +0 -1
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/ab13d81ce0e121f2.css +0 -3
- package/dashboard/.next/standalone/dashboard/.next/static/chunks/cf05262adfab5818.js +0 -1
- package/dist/__tests__/consolidation-merge.test.d.ts +0 -9
- package/dist/__tests__/consolidation-merge.test.d.ts.map +0 -1
- package/dist/__tests__/consolidation-merge.test.js +0 -137
- package/dist/__tests__/consolidation-merge.test.js.map +0 -1
- package/dist/__tests__/contradictions.test.d.ts +0 -8
- package/dist/__tests__/contradictions.test.d.ts.map +0 -1
- package/dist/__tests__/contradictions.test.js +0 -78
- package/dist/__tests__/contradictions.test.js.map +0 -1
- package/dist/__tests__/format-memory.test.d.ts +0 -11
- package/dist/__tests__/format-memory.test.d.ts.map +0 -1
- package/dist/__tests__/format-memory.test.js +0 -69
- package/dist/__tests__/format-memory.test.js.map +0 -1
- package/dist/__tests__/salience-evolution.test.d.ts +0 -7
- package/dist/__tests__/salience-evolution.test.d.ts.map +0 -1
- package/dist/__tests__/salience-evolution.test.js +0 -151
- package/dist/__tests__/salience-evolution.test.js.map +0 -1
- package/dist/__tests__/store.test.d.ts +0 -7
- package/dist/__tests__/store.test.d.ts.map +0 -1
- package/dist/__tests__/store.test.js +0 -583
- package/dist/__tests__/store.test.js.map +0 -1
- package/dist/api/control.d.ts.map +0 -1
- package/dist/api/control.js.map +0 -1
- package/dist/api/events.d.ts.map +0 -1
- package/dist/api/events.js.map +0 -1
- package/dist/api/session-token.d.ts.map +0 -1
- package/dist/api/session-token.js.map +0 -1
- package/dist/api/version.d.ts.map +0 -1
- package/dist/api/version.js.map +0 -1
- package/dist/api/visualization-server.d.ts.map +0 -1
- package/dist/api/visualization-server.js.map +0 -1
- package/dist/audit/env-scanner.d.ts.map +0 -1
- package/dist/audit/env-scanner.js.map +0 -1
- package/dist/audit/index.d.ts.map +0 -1
- package/dist/audit/index.js.map +0 -1
- package/dist/audit/mcp-config-scanner.d.ts.map +0 -1
- package/dist/audit/mcp-config-scanner.js.map +0 -1
- package/dist/audit/memory-scanner.d.ts.map +0 -1
- package/dist/audit/memory-scanner.js.map +0 -1
- package/dist/audit/report-formatter.d.ts.map +0 -1
- package/dist/audit/report-formatter.js.map +0 -1
- package/dist/audit/rules-file-scanner.d.ts.map +0 -1
- package/dist/audit/rules-file-scanner.js.map +0 -1
- package/dist/audit/types.d.ts.map +0 -1
- package/dist/audit/types.js.map +0 -1
- package/dist/cli/audit.d.ts.map +0 -1
- package/dist/cli/audit.js.map +0 -1
- package/dist/cli/doctor.d.ts.map +0 -1
- package/dist/cli/doctor.js.map +0 -1
- package/dist/cli/iron-dome.d.ts.map +0 -1
- package/dist/cli/iron-dome.js.map +0 -1
- package/dist/cloud/cli.d.ts.map +0 -1
- package/dist/cloud/cli.js.map +0 -1
- package/dist/cloud/config.d.ts.map +0 -1
- package/dist/cloud/config.js.map +0 -1
- package/dist/cloud/iron-dome-sync.d.ts.map +0 -1
- package/dist/cloud/iron-dome-sync.js.map +0 -1
- package/dist/cloud/quarantine-sync.d.ts.map +0 -1
- package/dist/cloud/quarantine-sync.js.map +0 -1
- package/dist/cloud/sync-queue.d.ts.map +0 -1
- package/dist/cloud/sync-queue.js.map +0 -1
- package/dist/cloud/sync.d.ts.map +0 -1
- package/dist/cloud/sync.js.map +0 -1
- package/dist/cloud/verify.d.ts.map +0 -1
- package/dist/cloud/verify.js.map +0 -1
- package/dist/context/project-context.d.ts.map +0 -1
- package/dist/context/project-context.js.map +0 -1
- package/dist/database/init.d.ts.map +0 -1
- package/dist/database/init.js.map +0 -1
- package/dist/defence/__tests__/access-control.test.d.ts +0 -5
- package/dist/defence/__tests__/access-control.test.d.ts.map +0 -1
- package/dist/defence/__tests__/access-control.test.js +0 -89
- package/dist/defence/__tests__/access-control.test.js.map +0 -1
- package/dist/defence/__tests__/agent-scorer.test.d.ts +0 -5
- package/dist/defence/__tests__/agent-scorer.test.d.ts.map +0 -1
- package/dist/defence/__tests__/agent-scorer.test.js +0 -75
- package/dist/defence/__tests__/agent-scorer.test.js.map +0 -1
- package/dist/defence/__tests__/credential-leak.test.d.ts +0 -8
- package/dist/defence/__tests__/credential-leak.test.d.ts.map +0 -1
- package/dist/defence/__tests__/credential-leak.test.js +0 -403
- package/dist/defence/__tests__/credential-leak.test.js.map +0 -1
- package/dist/defence/__tests__/env-detector.test.d.ts +0 -5
- package/dist/defence/__tests__/env-detector.test.d.ts.map +0 -1
- package/dist/defence/__tests__/env-detector.test.js +0 -100
- package/dist/defence/__tests__/env-detector.test.js.map +0 -1
- package/dist/defence/__tests__/firewall.test.d.ts +0 -8
- package/dist/defence/__tests__/firewall.test.d.ts.map +0 -1
- package/dist/defence/__tests__/firewall.test.js +0 -123
- package/dist/defence/__tests__/firewall.test.js.map +0 -1
- package/dist/defence/__tests__/fragmentation.test.d.ts +0 -7
- package/dist/defence/__tests__/fragmentation.test.d.ts.map +0 -1
- package/dist/defence/__tests__/fragmentation.test.js +0 -51
- package/dist/defence/__tests__/fragmentation.test.js.map +0 -1
- package/dist/defence/__tests__/pipeline.test.d.ts +0 -8
- package/dist/defence/__tests__/pipeline.test.d.ts.map +0 -1
- package/dist/defence/__tests__/pipeline.test.js +0 -106
- package/dist/defence/__tests__/pipeline.test.js.map +0 -1
- package/dist/defence/__tests__/sensitivity.test.d.ts +0 -7
- package/dist/defence/__tests__/sensitivity.test.d.ts.map +0 -1
- package/dist/defence/__tests__/sensitivity.test.js +0 -61
- package/dist/defence/__tests__/sensitivity.test.js.map +0 -1
- package/dist/defence/__tests__/tool-response-scanner.test.d.ts +0 -8
- package/dist/defence/__tests__/tool-response-scanner.test.d.ts.map +0 -1
- package/dist/defence/__tests__/tool-response-scanner.test.js +0 -106
- package/dist/defence/__tests__/tool-response-scanner.test.js.map +0 -1
- package/dist/defence/__tests__/trust.test.d.ts +0 -7
- package/dist/defence/__tests__/trust.test.d.ts.map +0 -1
- package/dist/defence/__tests__/trust.test.js +0 -50
- package/dist/defence/__tests__/trust.test.js.map +0 -1
- package/dist/defence/__tests__/verify.test.d.ts +0 -7
- package/dist/defence/__tests__/verify.test.d.ts.map +0 -1
- package/dist/defence/__tests__/verify.test.js +0 -143
- package/dist/defence/__tests__/verify.test.js.map +0 -1
- package/dist/defence/audit/export.d.ts.map +0 -1
- package/dist/defence/audit/export.js.map +0 -1
- package/dist/defence/audit/index.d.ts.map +0 -1
- package/dist/defence/audit/index.js.map +0 -1
- package/dist/defence/audit/logger.d.ts.map +0 -1
- package/dist/defence/audit/logger.js.map +0 -1
- package/dist/defence/audit/queries.d.ts.map +0 -1
- package/dist/defence/audit/queries.js.map +0 -1
- package/dist/defence/credential-leak/entropy.d.ts.map +0 -1
- package/dist/defence/credential-leak/entropy.js.map +0 -1
- package/dist/defence/credential-leak/index.d.ts.map +0 -1
- package/dist/defence/credential-leak/index.js.map +0 -1
- package/dist/defence/credential-leak/patterns.d.ts.map +0 -1
- package/dist/defence/credential-leak/patterns.js.map +0 -1
- package/dist/defence/custom-patterns/store.d.ts.map +0 -1
- package/dist/defence/custom-patterns/store.js.map +0 -1
- package/dist/defence/custom-rules/store.d.ts.map +0 -1
- package/dist/defence/custom-rules/store.js.map +0 -1
- package/dist/defence/firewall/anomaly-scorer.d.ts.map +0 -1
- package/dist/defence/firewall/anomaly-scorer.js.map +0 -1
- package/dist/defence/firewall/encoding-detector.d.ts.map +0 -1
- package/dist/defence/firewall/encoding-detector.js.map +0 -1
- package/dist/defence/firewall/index.d.ts.map +0 -1
- package/dist/defence/firewall/index.js.map +0 -1
- package/dist/defence/firewall/instruction-detector.d.ts.map +0 -1
- package/dist/defence/firewall/instruction-detector.js.map +0 -1
- package/dist/defence/firewall/privilege-detector.d.ts.map +0 -1
- package/dist/defence/firewall/privilege-detector.js.map +0 -1
- package/dist/defence/fragmentation/assembly-detector.d.ts.map +0 -1
- package/dist/defence/fragmentation/assembly-detector.js.map +0 -1
- package/dist/defence/fragmentation/entity-extractor.d.ts.map +0 -1
- package/dist/defence/fragmentation/entity-extractor.js.map +0 -1
- package/dist/defence/fragmentation/index.d.ts.map +0 -1
- package/dist/defence/fragmentation/index.js.map +0 -1
- package/dist/defence/fragmentation/temporal-analyzer.d.ts.map +0 -1
- package/dist/defence/fragmentation/temporal-analyzer.js.map +0 -1
- package/dist/defence/index.d.ts.map +0 -1
- package/dist/defence/index.js.map +0 -1
- package/dist/defence/input-sanitisation/index.d.ts.map +0 -1
- package/dist/defence/input-sanitisation/index.js.map +0 -1
- package/dist/defence/iron-dome/__tests__/action-gate.test.d.ts +0 -5
- package/dist/defence/iron-dome/__tests__/action-gate.test.d.ts.map +0 -1
- package/dist/defence/iron-dome/__tests__/action-gate.test.js +0 -71
- package/dist/defence/iron-dome/__tests__/action-gate.test.js.map +0 -1
- package/dist/defence/iron-dome/__tests__/confirmation-gate.test.d.ts +0 -5
- package/dist/defence/iron-dome/__tests__/confirmation-gate.test.d.ts.map +0 -1
- package/dist/defence/iron-dome/__tests__/confirmation-gate.test.js +0 -144
- package/dist/defence/iron-dome/__tests__/confirmation-gate.test.js.map +0 -1
- package/dist/defence/iron-dome/__tests__/gateway.test.d.ts +0 -5
- package/dist/defence/iron-dome/__tests__/gateway.test.d.ts.map +0 -1
- package/dist/defence/iron-dome/__tests__/gateway.test.js +0 -60
- package/dist/defence/iron-dome/__tests__/gateway.test.js.map +0 -1
- package/dist/defence/iron-dome/__tests__/injection-scanner.test.d.ts +0 -7
- package/dist/defence/iron-dome/__tests__/injection-scanner.test.d.ts.map +0 -1
- package/dist/defence/iron-dome/__tests__/injection-scanner.test.js +0 -230
- package/dist/defence/iron-dome/__tests__/injection-scanner.test.js.map +0 -1
- package/dist/defence/iron-dome/__tests__/pii-guard.test.d.ts +0 -5
- package/dist/defence/iron-dome/__tests__/pii-guard.test.d.ts.map +0 -1
- package/dist/defence/iron-dome/__tests__/pii-guard.test.js +0 -130
- package/dist/defence/iron-dome/__tests__/pii-guard.test.js.map +0 -1
- package/dist/defence/iron-dome/action-gate.d.ts.map +0 -1
- package/dist/defence/iron-dome/action-gate.js.map +0 -1
- package/dist/defence/iron-dome/audit.d.ts.map +0 -1
- package/dist/defence/iron-dome/audit.js.map +0 -1
- package/dist/defence/iron-dome/config.d.ts.map +0 -1
- package/dist/defence/iron-dome/config.js.map +0 -1
- package/dist/defence/iron-dome/confirmation-gate.d.ts.map +0 -1
- package/dist/defence/iron-dome/confirmation-gate.js.map +0 -1
- package/dist/defence/iron-dome/custom-policies.d.ts.map +0 -1
- package/dist/defence/iron-dome/custom-policies.js.map +0 -1
- package/dist/defence/iron-dome/gateway.d.ts.map +0 -1
- package/dist/defence/iron-dome/gateway.js.map +0 -1
- package/dist/defence/iron-dome/index.d.ts.map +0 -1
- package/dist/defence/iron-dome/index.js.map +0 -1
- package/dist/defence/iron-dome/injection-scanner.d.ts.map +0 -1
- package/dist/defence/iron-dome/injection-scanner.js.map +0 -1
- package/dist/defence/iron-dome/kill-switch.d.ts.map +0 -1
- package/dist/defence/iron-dome/kill-switch.js.map +0 -1
- package/dist/defence/iron-dome/pii-guard.d.ts.map +0 -1
- package/dist/defence/iron-dome/pii-guard.js.map +0 -1
- package/dist/defence/pipeline.d.ts.map +0 -1
- package/dist/defence/pipeline.js.map +0 -1
- package/dist/defence/quarantine/auto-expire.d.ts.map +0 -1
- package/dist/defence/quarantine/auto-expire.js.map +0 -1
- package/dist/defence/scanner/index.d.ts.map +0 -1
- package/dist/defence/scanner/index.js.map +0 -1
- package/dist/defence/scanner/scan-existing.d.ts.map +0 -1
- package/dist/defence/scanner/scan-existing.js.map +0 -1
- package/dist/defence/sensitivity/classifier.d.ts.map +0 -1
- package/dist/defence/sensitivity/classifier.js.map +0 -1
- package/dist/defence/sensitivity/index.d.ts.map +0 -1
- package/dist/defence/sensitivity/index.js.map +0 -1
- package/dist/defence/sensitivity/patterns.d.ts.map +0 -1
- package/dist/defence/sensitivity/patterns.js.map +0 -1
- package/dist/defence/sensitivity/redaction.d.ts.map +0 -1
- package/dist/defence/sensitivity/redaction.js.map +0 -1
- package/dist/defence/skill-scanner/__tests__/skill-scanner.test.d.ts +0 -12
- package/dist/defence/skill-scanner/__tests__/skill-scanner.test.d.ts.map +0 -1
- package/dist/defence/skill-scanner/__tests__/skill-scanner.test.js +0 -471
- package/dist/defence/skill-scanner/__tests__/skill-scanner.test.js.map +0 -1
- package/dist/defence/skill-scanner/deep-scan.d.ts.map +0 -1
- package/dist/defence/skill-scanner/deep-scan.js.map +0 -1
- package/dist/defence/skill-scanner/discover.d.ts.map +0 -1
- package/dist/defence/skill-scanner/discover.js.map +0 -1
- package/dist/defence/skill-scanner/index.d.ts.map +0 -1
- package/dist/defence/skill-scanner/index.js.map +0 -1
- package/dist/defence/skill-scanner/parser.d.ts.map +0 -1
- package/dist/defence/skill-scanner/parser.js.map +0 -1
- package/dist/defence/skill-scanner/patterns.d.ts.map +0 -1
- package/dist/defence/skill-scanner/patterns.js.map +0 -1
- package/dist/defence/skill-scanner/scan-skill.d.ts.map +0 -1
- package/dist/defence/skill-scanner/scan-skill.js.map +0 -1
- package/dist/defence/tool-response-scanner.d.ts.map +0 -1
- package/dist/defence/tool-response-scanner.js.map +0 -1
- package/dist/defence/trust/access-control.d.ts.map +0 -1
- package/dist/defence/trust/access-control.js.map +0 -1
- package/dist/defence/trust/agent-scorer.d.ts.map +0 -1
- package/dist/defence/trust/agent-scorer.js.map +0 -1
- package/dist/defence/trust/env-detector.d.ts.map +0 -1
- package/dist/defence/trust/env-detector.js.map +0 -1
- package/dist/defence/trust/index.d.ts.map +0 -1
- package/dist/defence/trust/index.js.map +0 -1
- package/dist/defence/trust/recall-filter.d.ts.map +0 -1
- package/dist/defence/trust/recall-filter.js.map +0 -1
- package/dist/defence/trust/source-scorer.d.ts.map +0 -1
- package/dist/defence/trust/source-scorer.js.map +0 -1
- package/dist/defence/types.d.ts.map +0 -1
- package/dist/defence/types.js.map +0 -1
- package/dist/embeddings/generator.d.ts.map +0 -1
- package/dist/embeddings/generator.js.map +0 -1
- package/dist/embeddings/index.d.ts.map +0 -1
- package/dist/embeddings/index.js.map +0 -1
- package/dist/embeddings/worker.d.ts.map +0 -1
- package/dist/embeddings/worker.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/events/webhooks.d.ts.map +0 -1
- package/dist/events/webhooks.js.map +0 -1
- package/dist/graph/backfill.d.ts.map +0 -1
- package/dist/graph/backfill.js.map +0 -1
- package/dist/graph/extract.d.ts.map +0 -1
- package/dist/graph/extract.js.map +0 -1
- package/dist/graph/resolve.d.ts.map +0 -1
- package/dist/graph/resolve.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/integrations/__tests__/openclaw.test.d.ts +0 -2
- package/dist/integrations/__tests__/openclaw.test.d.ts.map +0 -1
- package/dist/integrations/__tests__/openclaw.test.js +0 -72
- package/dist/integrations/__tests__/openclaw.test.js.map +0 -1
- package/dist/integrations/__tests__/universal.test.d.ts +0 -2
- package/dist/integrations/__tests__/universal.test.d.ts.map +0 -1
- package/dist/integrations/__tests__/universal.test.js +0 -144
- package/dist/integrations/__tests__/universal.test.js.map +0 -1
- package/dist/integrations/index.d.ts.map +0 -1
- package/dist/integrations/index.js.map +0 -1
- package/dist/integrations/langchain.d.ts.map +0 -1
- package/dist/integrations/langchain.js.map +0 -1
- package/dist/integrations/openclaw.d.ts.map +0 -1
- package/dist/integrations/openclaw.js.map +0 -1
- package/dist/integrations/universal.d.ts.map +0 -1
- package/dist/integrations/universal.js.map +0 -1
- package/dist/lib.d.ts.map +0 -1
- package/dist/lib.js.map +0 -1
- package/dist/license/__tests__/feature-gating.test.d.ts +0 -10
- package/dist/license/__tests__/feature-gating.test.d.ts.map +0 -1
- package/dist/license/__tests__/feature-gating.test.js +0 -188
- package/dist/license/__tests__/feature-gating.test.js.map +0 -1
- package/dist/license/cli.d.ts.map +0 -1
- package/dist/license/cli.js.map +0 -1
- package/dist/license/gate.d.ts.map +0 -1
- package/dist/license/gate.js.map +0 -1
- package/dist/license/index.d.ts.map +0 -1
- package/dist/license/index.js.map +0 -1
- package/dist/license/keys.d.ts.map +0 -1
- package/dist/license/keys.js.map +0 -1
- package/dist/license/store.d.ts.map +0 -1
- package/dist/license/store.js.map +0 -1
- package/dist/license/types.d.ts.map +0 -1
- package/dist/license/types.js.map +0 -1
- package/dist/license/validate.d.ts.map +0 -1
- package/dist/license/validate.js.map +0 -1
- package/dist/license/verify.d.ts.map +0 -1
- package/dist/license/verify.js.map +0 -1
- package/dist/memory/activation.d.ts.map +0 -1
- package/dist/memory/activation.js.map +0 -1
- package/dist/memory/consolidate.d.ts.map +0 -1
- package/dist/memory/consolidate.js.map +0 -1
- package/dist/memory/contradiction.d.ts.map +0 -1
- package/dist/memory/contradiction.js.map +0 -1
- package/dist/memory/decay.d.ts.map +0 -1
- package/dist/memory/decay.js.map +0 -1
- package/dist/memory/embedding-cache.d.ts.map +0 -1
- package/dist/memory/embedding-cache.js.map +0 -1
- package/dist/memory/embedding.d.ts.map +0 -1
- package/dist/memory/embedding.js.map +0 -1
- package/dist/memory/expiry.d.ts.map +0 -1
- package/dist/memory/expiry.js.map +0 -1
- package/dist/memory/salience.d.ts.map +0 -1
- package/dist/memory/salience.js.map +0 -1
- package/dist/memory/similarity.d.ts.map +0 -1
- package/dist/memory/similarity.js.map +0 -1
- package/dist/memory/store.d.ts.map +0 -1
- package/dist/memory/store.js.map +0 -1
- package/dist/memory/types.d.ts.map +0 -1
- package/dist/memory/types.js.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/service/install.d.ts.map +0 -1
- package/dist/service/install.js.map +0 -1
- package/dist/service/templates.d.ts.map +0 -1
- package/dist/service/templates.js.map +0 -1
- package/dist/setup/claude-md.d.ts.map +0 -1
- package/dist/setup/claude-md.js.map +0 -1
- package/dist/setup/copilot.d.ts.map +0 -1
- package/dist/setup/copilot.js.map +0 -1
- package/dist/setup/doctor.d.ts.map +0 -1
- package/dist/setup/doctor.js.map +0 -1
- package/dist/setup/hooks.d.ts.map +0 -1
- package/dist/setup/hooks.js.map +0 -1
- package/dist/setup/migrate.d.ts.map +0 -1
- package/dist/setup/migrate.js.map +0 -1
- package/dist/setup/openclaw.d.ts.map +0 -1
- package/dist/setup/openclaw.js.map +0 -1
- package/dist/setup/settings-hooks.d.ts.map +0 -1
- package/dist/setup/settings-hooks.js.map +0 -1
- package/dist/setup/status.d.ts.map +0 -1
- package/dist/setup/status.js.map +0 -1
- package/dist/setup/uninstall.d.ts.map +0 -1
- package/dist/setup/uninstall.js.map +0 -1
- package/dist/tools/context.d.ts.map +0 -1
- package/dist/tools/context.js.map +0 -1
- package/dist/tools/forget.d.ts.map +0 -1
- package/dist/tools/forget.js.map +0 -1
- package/dist/tools/graph.d.ts.map +0 -1
- package/dist/tools/graph.js.map +0 -1
- package/dist/tools/recall.d.ts.map +0 -1
- package/dist/tools/recall.js.map +0 -1
- package/dist/tools/remember.d.ts.map +0 -1
- package/dist/tools/remember.js.map +0 -1
- package/dist/worker/brain-worker.d.ts.map +0 -1
- package/dist/worker/brain-worker.js.map +0 -1
- package/dist/worker/link-discovery.d.ts.map +0 -1
- package/dist/worker/link-discovery.js.map +0 -1
- package/dist/worker/predictive-consolidation.d.ts.map +0 -1
- package/dist/worker/predictive-consolidation.js.map +0 -1
- package/dist/worker/types.d.ts.map +0 -1
- package/dist/worker/types.js.map +0 -1
- package/plugins/openclaw/README.md +0 -93
- package/plugins/openclaw/index.ts +0 -432
- package/plugins/openclaw/openclaw.plugin.json +0 -10
- /package/dashboard/.next/standalone/dashboard/.next/static/{aFo1BShJENvQZgqpWRJaw → ljjBNdtxDUABGiIMYNYT6}/_buildManifest.js +0 -0
- /package/dashboard/.next/standalone/dashboard/.next/static/{aFo1BShJENvQZgqpWRJaw → ljjBNdtxDUABGiIMYNYT6}/_clientMiddlewareManifest.json +0 -0
- /package/dashboard/.next/standalone/dashboard/.next/static/{aFo1BShJENvQZgqpWRJaw → ljjBNdtxDUABGiIMYNYT6}/_ssgManifest.js +0 -0
package/dist/memory/embedding.js
CHANGED
|
@@ -9,6 +9,31 @@
|
|
|
9
9
|
import { generateEmbedding, cosineSimilarity as rawCosineSimilarity, preloadModel } from '../embeddings/index.js';
|
|
10
10
|
let initialized = false;
|
|
11
11
|
let initFailed = false;
|
|
12
|
+
const QUERY_CACHE_TTL_MS = 10 * 60 * 1000;
|
|
13
|
+
const QUERY_CACHE_MAX = 64;
|
|
14
|
+
const queryEmbeddingCache = new Map();
|
|
15
|
+
function isExpectedEmbeddingDisable(message) {
|
|
16
|
+
return message.includes('SHIELDCORTEX_SKIP_EMBEDDINGS=1');
|
|
17
|
+
}
|
|
18
|
+
function normalizeQuery(text) {
|
|
19
|
+
return text.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
20
|
+
}
|
|
21
|
+
function cloneEmbedding(embedding) {
|
|
22
|
+
return new Float32Array(embedding);
|
|
23
|
+
}
|
|
24
|
+
function pruneQueryCache(now) {
|
|
25
|
+
for (const [key, entry] of queryEmbeddingCache) {
|
|
26
|
+
if (entry.expiresAt <= now) {
|
|
27
|
+
queryEmbeddingCache.delete(key);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
while (queryEmbeddingCache.size > QUERY_CACHE_MAX) {
|
|
31
|
+
const oldestKey = queryEmbeddingCache.keys().next().value;
|
|
32
|
+
if (!oldestKey)
|
|
33
|
+
break;
|
|
34
|
+
queryEmbeddingCache.delete(oldestKey);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
12
37
|
/**
|
|
13
38
|
* Lazy-load the embedding model. Cache the pipeline.
|
|
14
39
|
* Returns false on failure (doesn't crash).
|
|
@@ -24,7 +49,10 @@ export async function initEmbeddings() {
|
|
|
24
49
|
return true;
|
|
25
50
|
}
|
|
26
51
|
catch (e) {
|
|
27
|
-
|
|
52
|
+
const message = e.message;
|
|
53
|
+
if (!isExpectedEmbeddingDisable(message)) {
|
|
54
|
+
console.warn('[shieldcortex] Embedding init failed, vector recall disabled:', message);
|
|
55
|
+
}
|
|
28
56
|
initFailed = false; // Allow retry on next call
|
|
29
57
|
return false;
|
|
30
58
|
}
|
|
@@ -40,7 +68,10 @@ export async function embedText(text) {
|
|
|
40
68
|
return embedding;
|
|
41
69
|
}
|
|
42
70
|
catch (e) {
|
|
43
|
-
|
|
71
|
+
const message = e.message;
|
|
72
|
+
if (!isExpectedEmbeddingDisable(message)) {
|
|
73
|
+
console.warn('[shieldcortex] embedText failed:', message);
|
|
74
|
+
}
|
|
44
75
|
return null;
|
|
45
76
|
}
|
|
46
77
|
}
|
|
@@ -52,16 +83,47 @@ export function cosineSimilarity(a, b) {
|
|
|
52
83
|
return 0;
|
|
53
84
|
return rawCosineSimilarity(a, b);
|
|
54
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Cache repeated query embeddings in-process to avoid re-embedding the same
|
|
88
|
+
* recall queries during one MCP/API session.
|
|
89
|
+
*/
|
|
90
|
+
export async function getCachedQueryEmbedding(query) {
|
|
91
|
+
const normalized = normalizeQuery(query);
|
|
92
|
+
if (!normalized)
|
|
93
|
+
return null;
|
|
94
|
+
const now = Date.now();
|
|
95
|
+
const cached = queryEmbeddingCache.get(normalized);
|
|
96
|
+
if (cached && cached.expiresAt > now) {
|
|
97
|
+
queryEmbeddingCache.delete(normalized);
|
|
98
|
+
queryEmbeddingCache.set(normalized, cached);
|
|
99
|
+
return cloneEmbedding(cached.embedding);
|
|
100
|
+
}
|
|
101
|
+
if (cached) {
|
|
102
|
+
queryEmbeddingCache.delete(normalized);
|
|
103
|
+
}
|
|
104
|
+
const embedding = await embedText(query);
|
|
105
|
+
if (!embedding)
|
|
106
|
+
return null;
|
|
107
|
+
queryEmbeddingCache.set(normalized, {
|
|
108
|
+
embedding: cloneEmbedding(embedding),
|
|
109
|
+
expiresAt: now + QUERY_CACHE_TTL_MS,
|
|
110
|
+
});
|
|
111
|
+
pruneQueryCache(now);
|
|
112
|
+
return embedding;
|
|
113
|
+
}
|
|
114
|
+
export function clearQueryEmbeddingCache() {
|
|
115
|
+
queryEmbeddingCache.clear();
|
|
116
|
+
}
|
|
55
117
|
/**
|
|
56
118
|
* Embed the query, compute similarity against all memory embeddings,
|
|
57
119
|
* return top K (default 10) sorted by score desc.
|
|
58
120
|
*
|
|
59
121
|
* Non-throwing: returns empty array on failure.
|
|
60
122
|
*/
|
|
61
|
-
export async function findSimilarMemories(query, memories, topK = 10) {
|
|
123
|
+
export async function findSimilarMemories(query, memories, topK = 10, queryEmbedding) {
|
|
62
124
|
try {
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
125
|
+
const activeQueryEmbedding = queryEmbedding ?? await getCachedQueryEmbedding(query);
|
|
126
|
+
if (!activeQueryEmbedding)
|
|
65
127
|
return [];
|
|
66
128
|
// We need embeddings for each memory — caller should provide pre-computed
|
|
67
129
|
// embeddings via the cache. For memories without cached embeddings, we
|
|
@@ -72,7 +134,7 @@ export async function findSimilarMemories(query, memories, topK = 10) {
|
|
|
72
134
|
const memEmbedding = await getOrComputeEmbedding(mem.id, `${mem.title}\n${mem.content}`);
|
|
73
135
|
if (!memEmbedding)
|
|
74
136
|
continue;
|
|
75
|
-
const score = cosineSimilarity(
|
|
137
|
+
const score = cosineSimilarity(activeQueryEmbedding, memEmbedding);
|
|
76
138
|
scored.push({ id: mem.id, score });
|
|
77
139
|
}
|
|
78
140
|
scored.sort((a, b) => b.score - a.score);
|
|
@@ -83,4 +145,3 @@ export async function findSimilarMemories(query, memories, topK = 10) {
|
|
|
83
145
|
return [];
|
|
84
146
|
}
|
|
85
147
|
}
|
|
86
|
-
//# sourceMappingURL=embedding.js.map
|
package/dist/memory/expiry.d.ts
CHANGED
package/dist/memory/expiry.js
CHANGED
|
@@ -33,4 +33,3 @@ export declare function isWorthRemembering(input: MemoryInput, minSalience?: num
|
|
|
33
33
|
* Get a human-readable explanation of why something was considered important
|
|
34
34
|
*/
|
|
35
35
|
export declare function explainSalience(factors: SalienceFactors): string;
|
|
36
|
-
//# sourceMappingURL=salience.d.ts.map
|
package/dist/memory/salience.js
CHANGED
|
@@ -54,4 +54,3 @@ export declare function wordOverlap(textA: string, textB: string): number;
|
|
|
54
54
|
* @returns True if texts share at least minOverlap words
|
|
55
55
|
*/
|
|
56
56
|
export declare function hasSignificantOverlap(textA: string, textB: string, minOverlap?: number): boolean;
|
|
57
|
-
//# sourceMappingURL=similarity.d.ts.map
|
package/dist/memory/store.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export declare function getEnrichmentCooldownStatus(memoryId: number): {
|
|
|
99
99
|
*/
|
|
100
100
|
export declare function updateDecayScores(): number;
|
|
101
101
|
export declare function searchMemories(options: SearchOptions, config?: MemoryConfig, source?: DefenceSource): Promise<SearchResult[]>;
|
|
102
|
+
export declare function searchMemoriesExplained(options: SearchOptions, config?: MemoryConfig, source?: DefenceSource): Promise<SearchResult[]>;
|
|
102
103
|
/**
|
|
103
104
|
* Recall with embedding-based vector similarity fallback.
|
|
104
105
|
*
|
|
@@ -112,6 +113,8 @@ export declare function recallWithEmbeddings(query: string, options?: {
|
|
|
112
113
|
limit?: number;
|
|
113
114
|
project?: string;
|
|
114
115
|
threshold?: number;
|
|
116
|
+
existingResults?: SearchResult[];
|
|
117
|
+
queryEmbedding?: Float32Array | null;
|
|
115
118
|
}): Promise<Memory[]>;
|
|
116
119
|
/**
|
|
117
120
|
* Get all memories for a project
|
|
@@ -190,4 +193,3 @@ export declare function detectRelationships(memory: Memory, maxResults?: number)
|
|
|
190
193
|
relationship: RelationshipType;
|
|
191
194
|
strength: number;
|
|
192
195
|
}[];
|
|
193
|
-
//# sourceMappingURL=store.d.ts.map
|
package/dist/memory/store.js
CHANGED
|
@@ -22,6 +22,7 @@ import { checkAccess } from '../defence/trust/access-control.js';
|
|
|
22
22
|
import { scoreSource } from '../defence/trust/source-scorer.js';
|
|
23
23
|
import { logAudit } from '../defence/audit/logger.js';
|
|
24
24
|
import { dispatchWebhook } from '../events/webhooks.js';
|
|
25
|
+
import { getCachedQueryEmbedding, findSimilarMemories } from './embedding.js';
|
|
25
26
|
// Anti-bloat: Maximum content size per memory (10KB)
|
|
26
27
|
const MAX_CONTENT_SIZE = 10 * 1024;
|
|
27
28
|
// Track truncation info globally for the last addMemory call
|
|
@@ -147,33 +148,42 @@ function detectGlobalPattern(content, category, tags) {
|
|
|
147
148
|
// Tracks write attempts per source to prevent audit log flooding
|
|
148
149
|
const RATE_LIMIT_WINDOW_MS = 60_000; // 1 minute
|
|
149
150
|
const RATE_LIMIT_MAX = 20; // max writes per window per source
|
|
150
|
-
|
|
151
|
-
let rateLimitCheckCount = 0;
|
|
152
|
-
function pruneRateLimitMap() {
|
|
153
|
-
const now = Date.now();
|
|
154
|
-
for (const [key, entry] of rateLimitMap) {
|
|
155
|
-
if (now - entry.windowStart > RATE_LIMIT_WINDOW_MS * 2) {
|
|
156
|
-
rateLimitMap.delete(key);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
151
|
+
let rateLimitPruneCount = 0;
|
|
160
152
|
function checkRateLimit(source) {
|
|
161
|
-
|
|
162
|
-
if (++rateLimitCheckCount % 50 === 0) {
|
|
163
|
-
pruneRateLimitMap();
|
|
164
|
-
}
|
|
153
|
+
const db = getDatabase();
|
|
165
154
|
const key = `${source.type}:${source.identifier}`;
|
|
166
155
|
const now = Date.now();
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
156
|
+
// Prune expired entries every 50 checks
|
|
157
|
+
if (++rateLimitPruneCount % 50 === 0) {
|
|
158
|
+
try {
|
|
159
|
+
db.prepare('DELETE FROM rate_limits WHERE ? - window_start_ms > ?')
|
|
160
|
+
.run(now, RATE_LIMIT_WINDOW_MS * 2);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// Table may not exist yet in legacy DBs — fall through to allow
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
const row = db.prepare('SELECT write_count, window_start_ms FROM rate_limits WHERE source_key = ?')
|
|
168
|
+
.get(key);
|
|
169
|
+
if (!row || now - row.window_start_ms > RATE_LIMIT_WINDOW_MS) {
|
|
170
|
+
// New window — upsert
|
|
171
|
+
db.prepare('INSERT INTO rate_limits (source_key, write_count, window_start_ms) VALUES (?, 1, ?) ON CONFLICT(source_key) DO UPDATE SET write_count = 1, window_start_ms = ?').run(key, now, now);
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
// Increment counter
|
|
175
|
+
const newCount = row.write_count + 1;
|
|
176
|
+
db.prepare('UPDATE rate_limits SET write_count = ? WHERE source_key = ?')
|
|
177
|
+
.run(newCount, key);
|
|
178
|
+
if (newCount > RATE_LIMIT_MAX) {
|
|
179
|
+
return false; // rate limited
|
|
180
|
+
}
|
|
170
181
|
return true;
|
|
171
182
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return
|
|
183
|
+
catch {
|
|
184
|
+
// If rate_limits table doesn't exist (legacy DB), allow the write
|
|
185
|
+
return true;
|
|
175
186
|
}
|
|
176
|
-
return true;
|
|
177
187
|
}
|
|
178
188
|
// ── Read-Time Access Control ──
|
|
179
189
|
function logAccessDenial(memoryId, source, reason) {
|
|
@@ -410,7 +420,9 @@ export function addMemory(input, config = DEFAULT_CONFIG, source) {
|
|
|
410
420
|
}
|
|
411
421
|
})
|
|
412
422
|
.catch(e => {
|
|
413
|
-
if (e instanceof Error &&
|
|
423
|
+
if (e instanceof Error &&
|
|
424
|
+
(e.message.includes('Embedding worker unavailable') ||
|
|
425
|
+
e.message.includes('Embeddings disabled via SHIELDCORTEX_SKIP_EMBEDDINGS=1'))) {
|
|
414
426
|
return;
|
|
415
427
|
}
|
|
416
428
|
console.error('[shieldcortex] Failed to generate embedding:', e);
|
|
@@ -866,42 +878,87 @@ function vectorSearch(queryEmbedding, limit, project, includeGlobal = true) {
|
|
|
866
878
|
.slice(0, limit);
|
|
867
879
|
return results;
|
|
868
880
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
881
|
+
function buildSearchExplanation(memory, context, values) {
|
|
882
|
+
const matchedTags = context.queryTags.filter((queryTag) => memory.tags.some((memoryTag) => {
|
|
883
|
+
const lowerMemoryTag = memoryTag.toLowerCase();
|
|
884
|
+
return lowerMemoryTag.includes(queryTag) || queryTag.includes(lowerMemoryTag);
|
|
885
|
+
}));
|
|
886
|
+
const reasons = [];
|
|
887
|
+
if (values.vectorSimilarity > 0) {
|
|
888
|
+
reasons.push(`Semantic similarity ${(values.vectorSimilarity * 100).toFixed(0)}%`);
|
|
889
|
+
}
|
|
890
|
+
if (values.ftsScore > 0.3) {
|
|
891
|
+
reasons.push('Strong keyword match');
|
|
892
|
+
}
|
|
893
|
+
if (values.categoryBoost > 0 && context.detectedCategory) {
|
|
894
|
+
reasons.push(`Matches ${context.detectedCategory} category intent`);
|
|
895
|
+
}
|
|
896
|
+
if (matchedTags.length > 0) {
|
|
897
|
+
reasons.push(`Shared tags: ${matchedTags.slice(0, 3).join(', ')}`);
|
|
898
|
+
}
|
|
899
|
+
if (values.recencyBoost > 0) {
|
|
900
|
+
reasons.push('Recently accessed');
|
|
901
|
+
}
|
|
902
|
+
if (values.linkBoost > 0) {
|
|
903
|
+
reasons.push('Connected to related memories');
|
|
904
|
+
}
|
|
905
|
+
if (values.activationBoost > 0) {
|
|
906
|
+
reasons.push('Activated by recent recall activity');
|
|
907
|
+
}
|
|
908
|
+
if (reasons.length === 0) {
|
|
909
|
+
reasons.push('Ranked by salience and base recall heuristics');
|
|
910
|
+
}
|
|
911
|
+
return {
|
|
912
|
+
query: context.query,
|
|
913
|
+
reasons,
|
|
914
|
+
breakdown: {
|
|
915
|
+
ftsScore: values.ftsScore,
|
|
916
|
+
vectorSimilarity: values.vectorSimilarity,
|
|
917
|
+
vectorBoost: values.vectorBoost,
|
|
918
|
+
decayedScore: values.decayedScore,
|
|
919
|
+
priorityBoost: values.priorityBoost,
|
|
920
|
+
recencyBoost: values.recencyBoost,
|
|
921
|
+
categoryBoost: values.categoryBoost,
|
|
922
|
+
linkBoost: values.linkBoost,
|
|
923
|
+
tagBoost: values.tagBoost,
|
|
924
|
+
activationBoost: values.activationBoost,
|
|
925
|
+
finalScore: values.finalScore,
|
|
926
|
+
matchedTags,
|
|
927
|
+
matchedCategory: values.categoryBoost > 0 ? context.detectedCategory : null,
|
|
928
|
+
},
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
async function searchMemoriesInternal(options, config, source, execution) {
|
|
875
932
|
if (++searchCount % 100 === 0) {
|
|
876
933
|
pruneActivationCache();
|
|
877
934
|
}
|
|
878
935
|
const db = getDatabase();
|
|
879
936
|
const limit = options.limit || 20;
|
|
880
937
|
const includeGlobal = options.includeGlobal ?? true;
|
|
881
|
-
// Detect query category for boosting
|
|
882
938
|
const detectedCategory = options.query ? detectQueryCategory(options.query) : null;
|
|
883
939
|
const queryTags = options.query ? extractQueryTags(options.query) : [];
|
|
884
|
-
// SEMANTIC SEARCH: Generate query embedding (may fail on first call while model loads)
|
|
885
940
|
let queryEmbedding = null;
|
|
886
|
-
|
|
941
|
+
const vectorResults = new Map();
|
|
887
942
|
if (options.query && options.query.trim()) {
|
|
888
943
|
try {
|
|
889
|
-
queryEmbedding = await
|
|
944
|
+
queryEmbedding = await getCachedQueryEmbedding(options.query);
|
|
945
|
+
if (!queryEmbedding) {
|
|
946
|
+
throw new Error('query embedding unavailable');
|
|
947
|
+
}
|
|
890
948
|
const vectorHits = vectorSearch(queryEmbedding, limit * 2, options.project, includeGlobal);
|
|
891
949
|
for (const hit of vectorHits) {
|
|
892
950
|
vectorResults.set(hit.memory.id, hit.similarity);
|
|
893
951
|
}
|
|
894
952
|
}
|
|
895
|
-
catch
|
|
896
|
-
|
|
897
|
-
|
|
953
|
+
catch {
|
|
954
|
+
if (process.env.SHIELDCORTEX_SKIP_EMBEDDINGS !== '1') {
|
|
955
|
+
console.log('[shieldcortex] Vector search unavailable, using FTS only');
|
|
956
|
+
}
|
|
898
957
|
}
|
|
899
958
|
}
|
|
900
959
|
let sql;
|
|
901
960
|
const params = [];
|
|
902
961
|
if (options.query && options.query.trim()) {
|
|
903
|
-
// Use FTS search - escape query to prevent FTS5 syntax errors
|
|
904
|
-
// FTS5 interprets "word-word" as "column:value", so we quote terms
|
|
905
962
|
const escapedQuery = escapeFts5Query(options.query.trim());
|
|
906
963
|
sql = `
|
|
907
964
|
SELECT m.*, fts.rank
|
|
@@ -912,10 +969,8 @@ export async function searchMemories(options, config = DEFAULT_CONFIG, source) {
|
|
|
912
969
|
params.push(escapedQuery);
|
|
913
970
|
}
|
|
914
971
|
else {
|
|
915
|
-
// No query, just filter
|
|
916
972
|
sql = `SELECT *, 0 as rank FROM memories m WHERE 1=1`;
|
|
917
973
|
}
|
|
918
|
-
// Add filters - include global memories if enabled
|
|
919
974
|
if (options.project) {
|
|
920
975
|
if (includeGlobal) {
|
|
921
976
|
sql += ` AND (m.project = ? OR m.scope = 'global')`;
|
|
@@ -938,8 +993,6 @@ export async function searchMemories(options, config = DEFAULT_CONFIG, source) {
|
|
|
938
993
|
params.push(options.minSalience);
|
|
939
994
|
}
|
|
940
995
|
if (options.tags && options.tags.length > 0) {
|
|
941
|
-
// Use json_each() for proper JSON array parsing
|
|
942
|
-
// This avoids false positives from LIKE matching (e.g., "api" matching "api-gateway")
|
|
943
996
|
const tagPlaceholders = options.tags.map(() => '?').join(',');
|
|
944
997
|
sql += ` AND EXISTS (
|
|
945
998
|
SELECT 1 FROM json_each(m.tags)
|
|
@@ -950,94 +1003,98 @@ export async function searchMemories(options, config = DEFAULT_CONFIG, source) {
|
|
|
950
1003
|
sql += ' ORDER BY m.salience DESC, m.last_accessed DESC LIMIT ?';
|
|
951
1004
|
params.push(limit);
|
|
952
1005
|
const rows = db.prepare(sql).all(...params);
|
|
953
|
-
|
|
954
|
-
|
|
1006
|
+
const scoringContext = {
|
|
1007
|
+
db,
|
|
1008
|
+
config,
|
|
1009
|
+
detectedCategory,
|
|
1010
|
+
queryTags,
|
|
1011
|
+
vectorResults,
|
|
1012
|
+
query: options.query,
|
|
1013
|
+
};
|
|
1014
|
+
const results = rows.map((row) => {
|
|
955
1015
|
const memory = rowToMemory(row);
|
|
956
1016
|
const decayedScore = calculateDecayedScore(memory, config);
|
|
957
1017
|
memory.decayedScore = decayedScore;
|
|
958
|
-
// Improved FTS score normalization (BM25-style)
|
|
959
|
-
// FTS5 rank is negative, closer to 0 = better match
|
|
960
1018
|
const rawRank = row.rank;
|
|
961
1019
|
const ftsScore = rawRank ? 1 / (1 + Math.abs(rawRank)) : 0.3;
|
|
962
|
-
// Recency boost for recently accessed memories
|
|
963
1020
|
const hoursSinceAccess = (Date.now() - new Date(memory.lastAccessed).getTime()) / (1000 * 60 * 60);
|
|
964
1021
|
const recencyBoost = hoursSinceAccess < 1 ? 0.1 : (hoursSinceAccess < 24 ? 0.05 : 0);
|
|
965
|
-
// Category match bonus
|
|
966
1022
|
const categoryBoost = detectedCategory && memory.category === detectedCategory ? 0.1 : 0;
|
|
967
|
-
// Link boost - memories connected to high-salience memories rank higher
|
|
968
1023
|
const linkBoost = calculateLinkBoost(memory.id, db);
|
|
969
|
-
// Partial tag match bonus
|
|
970
1024
|
const tagBoost = calculateTagScore(queryTags, memory.tags);
|
|
971
|
-
// ORGANIC FEATURE: Spreading Activation boost (Phase 2)
|
|
972
|
-
// Recently accessed memories and their linked neighbors get a boost
|
|
973
1025
|
const activationBoost = getActivationBoost(memory.id);
|
|
974
|
-
// SEMANTIC SEARCH: Vector similarity boost (Phase 5)
|
|
975
|
-
// If memory was found by vector search, add similarity as a boost
|
|
976
1026
|
const vectorSimilarity = vectorResults.get(memory.id) || 0;
|
|
977
|
-
const vectorBoost = vectorSimilarity * 0.3;
|
|
978
|
-
|
|
979
|
-
const relevanceScore = (ftsScore * 0.25 +
|
|
980
|
-
vectorBoost +
|
|
981
|
-
decayedScore * 0.2 +
|
|
982
|
-
|
|
1027
|
+
const vectorBoost = vectorSimilarity * 0.3;
|
|
1028
|
+
const priorityBoost = calculatePriority(memory) * 0.05;
|
|
1029
|
+
const relevanceScore = (ftsScore * 0.25 +
|
|
1030
|
+
vectorBoost +
|
|
1031
|
+
decayedScore * 0.2 +
|
|
1032
|
+
priorityBoost +
|
|
983
1033
|
recencyBoost + categoryBoost + linkBoost + tagBoost + activationBoost);
|
|
984
|
-
|
|
1034
|
+
const result = { memory, relevanceScore };
|
|
1035
|
+
if (execution.includeExplanation) {
|
|
1036
|
+
result.explanation = buildSearchExplanation(memory, scoringContext, {
|
|
1037
|
+
ftsScore,
|
|
1038
|
+
vectorSimilarity,
|
|
1039
|
+
vectorBoost,
|
|
1040
|
+
decayedScore,
|
|
1041
|
+
priorityBoost,
|
|
1042
|
+
recencyBoost,
|
|
1043
|
+
categoryBoost,
|
|
1044
|
+
linkBoost,
|
|
1045
|
+
tagBoost,
|
|
1046
|
+
activationBoost,
|
|
1047
|
+
finalScore: relevanceScore,
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
return result;
|
|
985
1051
|
});
|
|
986
|
-
// Sort by relevance and filter out too-decayed memories
|
|
987
1052
|
const sortedResults = results
|
|
988
|
-
.filter(
|
|
1053
|
+
.filter((result) => options.includeDecayed || result.memory.decayedScore >= config.salienceThreshold)
|
|
989
1054
|
.sort((a, b) => b.relevanceScore - a.relevanceScore);
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
const idB = topResults[j].memory.id;
|
|
1005
|
-
const existing = db.prepare('SELECT strength FROM memory_links WHERE (source_id = ? AND target_id = ?) OR (source_id = ? AND target_id = ?)').get(idA, idB, idB, idA);
|
|
1006
|
-
if (existing) {
|
|
1007
|
-
const newStrength = Math.min(1.0, existing.strength + 0.03);
|
|
1008
|
-
db.prepare('UPDATE memory_links SET strength = ? WHERE (source_id = ? AND target_id = ?) OR (source_id = ? AND target_id = ?)').run(newStrength, idA, idB, idB, idA);
|
|
1009
|
-
}
|
|
1010
|
-
else {
|
|
1011
|
-
try {
|
|
1012
|
-
db.prepare('INSERT INTO memory_links (source_id, target_id, relationship, strength) VALUES (?, ?, ?, ?)').run(idA, idB, 'related', 0.2);
|
|
1055
|
+
if (execution.enableSideEffects) {
|
|
1056
|
+
const topResults = sortedResults.slice(0, 5);
|
|
1057
|
+
for (const result of topResults) {
|
|
1058
|
+
reinforceFromSearch(result.memory.id);
|
|
1059
|
+
}
|
|
1060
|
+
if (topResults.length >= 2) {
|
|
1061
|
+
for (let i = 0; i < topResults.length; i++) {
|
|
1062
|
+
for (let j = i + 1; j < topResults.length; j++) {
|
|
1063
|
+
const idA = topResults[i].memory.id;
|
|
1064
|
+
const idB = topResults[j].memory.id;
|
|
1065
|
+
const existing = db.prepare('SELECT strength FROM memory_links WHERE (source_id = ? AND target_id = ?) OR (source_id = ? AND target_id = ?)').get(idA, idB, idB, idA);
|
|
1066
|
+
if (existing) {
|
|
1067
|
+
const newStrength = Math.min(1.0, existing.strength + 0.03);
|
|
1068
|
+
db.prepare('UPDATE memory_links SET strength = ? WHERE (source_id = ? AND target_id = ?) OR (source_id = ? AND target_id = ?)').run(newStrength, idA, idB, idB, idA);
|
|
1013
1069
|
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1070
|
+
else {
|
|
1071
|
+
try {
|
|
1072
|
+
db.prepare('INSERT INTO memory_links (source_id, target_id, relationship, strength) VALUES (?, ?, ?, ?)').run(idA, idB, 'related', 0.2);
|
|
1073
|
+
}
|
|
1074
|
+
catch (e) {
|
|
1075
|
+
if (!(e instanceof Error && e.message.includes('UNIQUE constraint'))) {
|
|
1076
|
+
console.warn('[shieldcortex] Unexpected error linking co-returned memories:', e);
|
|
1077
|
+
}
|
|
1018
1078
|
}
|
|
1019
1079
|
}
|
|
1020
1080
|
}
|
|
1021
1081
|
}
|
|
1022
1082
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
enrichMemory(topResult.memory.id, options.query, 'search');
|
|
1083
|
+
if (sortedResults.length > 0 && options.query && options.query.length > 30) {
|
|
1084
|
+
const topResult = sortedResults[0];
|
|
1085
|
+
const queryWords = new Set(options.query.toLowerCase().split(/\s+/).filter(w => w.length > 3));
|
|
1086
|
+
const contentWords = new Set(topResult.memory.content.toLowerCase().split(/\s+/));
|
|
1087
|
+
const newWords = [...queryWords].filter(w => !contentWords.has(w));
|
|
1088
|
+
if (newWords.length > queryWords.size * 0.3 && options.query.length > 50) {
|
|
1089
|
+
try {
|
|
1090
|
+
enrichMemory(topResult.memory.id, options.query, 'search');
|
|
1091
|
+
}
|
|
1092
|
+
catch {
|
|
1093
|
+
// enrichment is best-effort
|
|
1094
|
+
}
|
|
1036
1095
|
}
|
|
1037
|
-
catch { /* enrichment is best-effort */ }
|
|
1038
1096
|
}
|
|
1039
1097
|
}
|
|
1040
|
-
// Look up contradictions for top results
|
|
1041
1098
|
const finalResults = sortedResults.slice(0, limit);
|
|
1042
1099
|
for (const result of finalResults) {
|
|
1043
1100
|
const contradictions = db.prepare(`
|
|
@@ -1048,13 +1105,15 @@ export async function searchMemories(options, config = DEFAULT_CONFIG, source) {
|
|
|
1048
1105
|
AND (ml.source_id = ? OR ml.target_id = ?)
|
|
1049
1106
|
`).all(result.memory.id, result.memory.id, result.memory.id);
|
|
1050
1107
|
if (contradictions.length > 0) {
|
|
1051
|
-
result.contradictions = contradictions.map(
|
|
1052
|
-
const other = db.prepare('SELECT title FROM memories WHERE id = ?').get(
|
|
1053
|
-
return { memoryId:
|
|
1108
|
+
result.contradictions = contradictions.map((contradiction) => {
|
|
1109
|
+
const other = db.prepare('SELECT title FROM memories WHERE id = ?').get(contradiction.other_id);
|
|
1110
|
+
return { memoryId: contradiction.other_id, title: other?.title || 'Unknown', score: contradiction.strength };
|
|
1054
1111
|
});
|
|
1112
|
+
if (result.explanation) {
|
|
1113
|
+
result.explanation.reasons.push(`${contradictions.length} contradiction link${contradictions.length === 1 ? '' : 's'} attached`);
|
|
1114
|
+
}
|
|
1055
1115
|
}
|
|
1056
1116
|
}
|
|
1057
|
-
// ACCESS CONTROL: Filter results by source trust level
|
|
1058
1117
|
if (source) {
|
|
1059
1118
|
const db2 = getDatabase();
|
|
1060
1119
|
return finalResults.filter(result => {
|
|
@@ -1069,6 +1128,23 @@ export async function searchMemories(options, config = DEFAULT_CONFIG, source) {
|
|
|
1069
1128
|
}
|
|
1070
1129
|
return finalResults;
|
|
1071
1130
|
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Search memories using full-text search, vector similarity, and filters
|
|
1133
|
+
* Now uses hybrid search combining FTS5 keywords with semantic vector matching
|
|
1134
|
+
*/
|
|
1135
|
+
let searchCount = 0;
|
|
1136
|
+
export async function searchMemories(options, config = DEFAULT_CONFIG, source) {
|
|
1137
|
+
return searchMemoriesInternal(options, config, source, {
|
|
1138
|
+
enableSideEffects: true,
|
|
1139
|
+
includeExplanation: false,
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
export async function searchMemoriesExplained(options, config = DEFAULT_CONFIG, source) {
|
|
1143
|
+
return searchMemoriesInternal(options, config, source, {
|
|
1144
|
+
enableSideEffects: false,
|
|
1145
|
+
includeExplanation: true,
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1072
1148
|
/**
|
|
1073
1149
|
* Recall with embedding-based vector similarity fallback.
|
|
1074
1150
|
*
|
|
@@ -1082,18 +1158,20 @@ export async function recallWithEmbeddings(query, options) {
|
|
|
1082
1158
|
const limit = options?.limit ?? 15;
|
|
1083
1159
|
const threshold = options?.threshold ?? 0.3;
|
|
1084
1160
|
// Step 1: Try FTS5 search first
|
|
1085
|
-
let ftsResults = [];
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1161
|
+
let ftsResults = options?.existingResults ?? [];
|
|
1162
|
+
if (ftsResults.length === 0) {
|
|
1163
|
+
try {
|
|
1164
|
+
ftsResults = await searchMemories({
|
|
1165
|
+
query,
|
|
1166
|
+
project: options?.project,
|
|
1167
|
+
limit,
|
|
1168
|
+
includeGlobal: true,
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
catch (e) {
|
|
1172
|
+
// FTS search failed — continue to embedding fallback
|
|
1173
|
+
console.warn('[shieldcortex] FTS search failed in recallWithEmbeddings:', e.message);
|
|
1174
|
+
}
|
|
1097
1175
|
}
|
|
1098
1176
|
const ftsMemories = ftsResults.map(r => r.memory);
|
|
1099
1177
|
// Step 2: If FTS5 returns >= 3 results, no need for embedding fallback
|
|
@@ -1102,7 +1180,7 @@ export async function recallWithEmbeddings(query, options) {
|
|
|
1102
1180
|
}
|
|
1103
1181
|
// Step 3: Run embedding similarity search as fallback
|
|
1104
1182
|
try {
|
|
1105
|
-
const { initEmbeddings
|
|
1183
|
+
const { initEmbeddings } = await import('./embedding.js');
|
|
1106
1184
|
const ready = await initEmbeddings();
|
|
1107
1185
|
if (!ready) {
|
|
1108
1186
|
return ftsMemories.slice(0, limit);
|
|
@@ -1123,9 +1201,13 @@ export async function recallWithEmbeddings(query, options) {
|
|
|
1123
1201
|
if (newCandidates.length === 0) {
|
|
1124
1202
|
return ftsMemories.slice(0, limit);
|
|
1125
1203
|
}
|
|
1204
|
+
const queryEmbedding = options?.queryEmbedding ?? await getCachedQueryEmbedding(query);
|
|
1205
|
+
if (!queryEmbedding) {
|
|
1206
|
+
return ftsMemories.slice(0, limit);
|
|
1207
|
+
}
|
|
1126
1208
|
// Find similar memories using embeddings
|
|
1127
1209
|
const remainingSlots = limit - ftsMemories.length;
|
|
1128
|
-
const similar = await findSimilarMemories(query, newCandidates, remainingSlots);
|
|
1210
|
+
const similar = await findSimilarMemories(query, newCandidates, remainingSlots, queryEmbedding);
|
|
1129
1211
|
// Filter by threshold and fetch full Memory objects
|
|
1130
1212
|
const embeddingMemories = [];
|
|
1131
1213
|
for (const hit of similar) {
|
|
@@ -1498,4 +1580,3 @@ export function detectRelationships(memory, maxResults = 5) {
|
|
|
1498
1580
|
.sort((a, b) => b.strength - a.strength)
|
|
1499
1581
|
.slice(0, maxResults);
|
|
1500
1582
|
}
|
|
1501
|
-
//# sourceMappingURL=store.js.map
|