hippo-memory 1.43.3 → 1.45.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 +14 -12
- package/bin/hippo.js +3 -1
- package/dist/api.d.ts +21 -21
- package/dist/api.js +69 -42
- package/dist/audit-prune.js +4 -1
- package/dist/audit.d.ts +1 -1
- package/dist/audit.js +9 -0
- package/dist/autolearn.d.ts +1 -1
- package/dist/autolearn.js +2 -1
- package/dist/capture.d.ts +11 -10
- package/dist/capture.js +22 -30
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +309 -171
- package/dist/client.d.ts +4 -21
- package/dist/client.js +3 -112
- package/dist/config.js +2 -1
- package/dist/consolidate.d.ts +3 -0
- package/dist/consolidate.js +44 -42
- package/dist/dag.d.ts +1 -0
- package/dist/dag.js +10 -5
- package/dist/dashboard.js +7 -3
- package/dist/db.js +16 -24
- package/dist/dedupe.d.ts +1 -0
- package/dist/dedupe.js +4 -7
- package/dist/embedding-provider.d.ts +1 -1
- package/dist/embedding-provider.js +3 -2
- package/dist/embeddings.js +81 -8
- package/dist/extract.d.ts +2 -0
- package/dist/extract.js +9 -4
- package/dist/goals.js +12 -3
- package/dist/mcp/server.js +21 -36
- package/dist/memory.d.ts +3 -0
- package/dist/memory.js +7 -1
- package/dist/physics-state.js +4 -1
- package/dist/raw-archive.js +5 -2
- package/dist/recall-trace.js +4 -1
- package/dist/refine-llm.js +3 -2
- package/dist/rerankers/jev.js +3 -2
- package/dist/rerankers/llm.js +3 -2
- package/dist/search.js +3 -3
- package/dist/server.d.ts +5 -0
- package/dist/server.js +39 -29
- package/dist/shared.js +1 -1
- package/dist/stdin.d.ts +12 -0
- package/dist/stdin.js +41 -0
- package/dist/store.d.ts +18 -11
- package/dist/store.js +152 -65
- package/dist/version.d.ts +4 -6
- package/dist/version.js +4 -7
- package/extensions/openclaw-plugin/openclaw.plugin.json +1 -1
- package/extensions/openclaw-plugin/package.json +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +8 -5
- package/dist/ablation.d.ts.map +0 -1
- package/dist/ablation.js.map +0 -1
- package/dist/ambient.d.ts.map +0 -1
- package/dist/ambient.js.map +0 -1
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js.map +0 -1
- package/dist/audit-prune.d.ts.map +0 -1
- package/dist/audit-prune.js.map +0 -1
- package/dist/audit.d.ts.map +0 -1
- package/dist/audit.js.map +0 -1
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js.map +0 -1
- package/dist/autolearn.d.ts.map +0 -1
- package/dist/autolearn.js.map +0 -1
- package/dist/availability.d.ts.map +0 -1
- package/dist/availability.js.map +0 -1
- package/dist/benchmarks/e1.3/incident-recall-eval.js +0 -78
- package/dist/benchmarks/e1.3/incident-recall-eval.js.map +0 -1
- package/dist/benchmarks/e1.3/slack-1000-event-smoke.js +0 -103
- package/dist/benchmarks/e1.3/slack-1000-event-smoke.js.map +0 -1
- package/dist/capture.d.ts.map +0 -1
- package/dist/capture.js.map +0 -1
- package/dist/card-detail.d.ts.map +0 -1
- package/dist/card-detail.js.map +0 -1
- package/dist/card.d.ts.map +0 -1
- package/dist/card.js.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/compare.d.ts.map +0 -1
- package/dist/compare.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/connectors/github/backfill.d.ts.map +0 -1
- package/dist/connectors/github/backfill.js.map +0 -1
- package/dist/connectors/github/cli-impl.d.ts.map +0 -1
- package/dist/connectors/github/cli-impl.js.map +0 -1
- package/dist/connectors/github/deletion.d.ts.map +0 -1
- package/dist/connectors/github/deletion.js.map +0 -1
- package/dist/connectors/github/dlq.d.ts.map +0 -1
- package/dist/connectors/github/dlq.js.map +0 -1
- package/dist/connectors/github/idempotency.d.ts.map +0 -1
- package/dist/connectors/github/idempotency.js.map +0 -1
- package/dist/connectors/github/ingest.d.ts.map +0 -1
- package/dist/connectors/github/ingest.js.map +0 -1
- package/dist/connectors/github/octokit-client.d.ts.map +0 -1
- package/dist/connectors/github/octokit-client.js.map +0 -1
- package/dist/connectors/github/ratelimit.d.ts.map +0 -1
- package/dist/connectors/github/ratelimit.js.map +0 -1
- package/dist/connectors/github/scope.d.ts.map +0 -1
- package/dist/connectors/github/scope.js.map +0 -1
- package/dist/connectors/github/signature.d.ts.map +0 -1
- package/dist/connectors/github/signature.js.map +0 -1
- package/dist/connectors/github/tenant-routing.d.ts.map +0 -1
- package/dist/connectors/github/tenant-routing.js.map +0 -1
- package/dist/connectors/github/transform.d.ts.map +0 -1
- package/dist/connectors/github/transform.js.map +0 -1
- package/dist/connectors/github/types.d.ts.map +0 -1
- package/dist/connectors/github/types.js.map +0 -1
- package/dist/connectors/slack/backfill.d.ts.map +0 -1
- package/dist/connectors/slack/backfill.js.map +0 -1
- package/dist/connectors/slack/deletion.d.ts.map +0 -1
- package/dist/connectors/slack/deletion.js.map +0 -1
- package/dist/connectors/slack/dlq.d.ts.map +0 -1
- package/dist/connectors/slack/dlq.js.map +0 -1
- package/dist/connectors/slack/idempotency.d.ts.map +0 -1
- package/dist/connectors/slack/idempotency.js.map +0 -1
- package/dist/connectors/slack/ingest.d.ts.map +0 -1
- package/dist/connectors/slack/ingest.js.map +0 -1
- package/dist/connectors/slack/ratelimit.d.ts.map +0 -1
- package/dist/connectors/slack/ratelimit.js.map +0 -1
- package/dist/connectors/slack/scope.d.ts.map +0 -1
- package/dist/connectors/slack/scope.js.map +0 -1
- package/dist/connectors/slack/signature.d.ts.map +0 -1
- package/dist/connectors/slack/signature.js.map +0 -1
- package/dist/connectors/slack/tenant-routing.d.ts.map +0 -1
- package/dist/connectors/slack/tenant-routing.js.map +0 -1
- package/dist/connectors/slack/transform.d.ts.map +0 -1
- package/dist/connectors/slack/transform.js.map +0 -1
- package/dist/connectors/slack/types.d.ts.map +0 -1
- package/dist/connectors/slack/types.js.map +0 -1
- package/dist/connectors/slack/web-client.d.ts.map +0 -1
- package/dist/connectors/slack/web-client.js.map +0 -1
- package/dist/connectors/slack/workspaces.d.ts.map +0 -1
- package/dist/connectors/slack/workspaces.js.map +0 -1
- package/dist/consolidate.d.ts.map +0 -1
- package/dist/consolidate.js.map +0 -1
- package/dist/correction-latency.d.ts.map +0 -1
- package/dist/correction-latency.js.map +0 -1
- package/dist/customer-notes.d.ts.map +0 -1
- package/dist/customer-notes.js.map +0 -1
- package/dist/dag.d.ts.map +0 -1
- package/dist/dag.js.map +0 -1
- package/dist/dashboard.d.ts.map +0 -1
- package/dist/dashboard.js.map +0 -1
- package/dist/db.d.ts.map +0 -1
- package/dist/db.js.map +0 -1
- package/dist/decisions.d.ts.map +0 -1
- package/dist/decisions.js.map +0 -1
- package/dist/dedupe.d.ts.map +0 -1
- package/dist/dedupe.js.map +0 -1
- package/dist/embedding-provider.d.ts.map +0 -1
- package/dist/embedding-provider.js.map +0 -1
- package/dist/embeddings.d.ts.map +0 -1
- package/dist/embeddings.js.map +0 -1
- package/dist/eval-suite.d.ts.map +0 -1
- package/dist/eval-suite.js.map +0 -1
- package/dist/eval.d.ts.map +0 -1
- package/dist/eval.js.map +0 -1
- package/dist/extensions/openclaw-plugin/index.js.map +0 -1
- package/dist/extract.d.ts.map +0 -1
- package/dist/extract.js.map +0 -1
- package/dist/forward-claim-detector.d.ts.map +0 -1
- package/dist/forward-claim-detector.js.map +0 -1
- package/dist/goals.d.ts.map +0 -1
- package/dist/goals.js.map +0 -1
- package/dist/graph-extract.d.ts.map +0 -1
- package/dist/graph-extract.js.map +0 -1
- package/dist/graph-recall.d.ts.map +0 -1
- package/dist/graph-recall.js.map +0 -1
- package/dist/graph-stream.d.ts.map +0 -1
- package/dist/graph-stream.js.map +0 -1
- package/dist/graph-view.d.ts.map +0 -1
- package/dist/graph-view.js.map +0 -1
- package/dist/graph.d.ts.map +0 -1
- package/dist/graph.js.map +0 -1
- package/dist/handoff.d.ts.map +0 -1
- package/dist/handoff.js.map +0 -1
- package/dist/hooks.d.ts.map +0 -1
- package/dist/hooks.js.map +0 -1
- package/dist/importers.d.ts.map +0 -1
- package/dist/importers.js.map +0 -1
- package/dist/incidents.d.ts.map +0 -1
- package/dist/incidents.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/invalidation.d.ts.map +0 -1
- package/dist/invalidation.js.map +0 -1
- package/dist/mcp/framing.d.ts.map +0 -1
- package/dist/mcp/framing.js.map +0 -1
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/mcp/server.js.map +0 -1
- package/dist/memory-value-weights.d.ts.map +0 -1
- package/dist/memory-value-weights.js.map +0 -1
- package/dist/memory-value.d.ts.map +0 -1
- package/dist/memory-value.js.map +0 -1
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js.map +0 -1
- package/dist/multihop.d.ts.map +0 -1
- package/dist/multihop.js.map +0 -1
- package/dist/owner-validation.d.ts.map +0 -1
- package/dist/owner-validation.js.map +0 -1
- package/dist/path-context.d.ts.map +0 -1
- package/dist/path-context.js.map +0 -1
- package/dist/physics-config.d.ts.map +0 -1
- package/dist/physics-config.js.map +0 -1
- package/dist/physics-state.d.ts.map +0 -1
- package/dist/physics-state.js.map +0 -1
- package/dist/physics.d.ts.map +0 -1
- package/dist/physics.js.map +0 -1
- package/dist/policies.d.ts.map +0 -1
- package/dist/policies.js.map +0 -1
- package/dist/postinstall.d.ts.map +0 -1
- package/dist/postinstall.js.map +0 -1
- package/dist/predictions.d.ts.map +0 -1
- package/dist/predictions.js.map +0 -1
- package/dist/processes.d.ts.map +0 -1
- package/dist/processes.js.map +0 -1
- package/dist/project-briefs.d.ts.map +0 -1
- package/dist/project-briefs.js.map +0 -1
- package/dist/project-identity.d.ts.map +0 -1
- package/dist/project-identity.js.map +0 -1
- package/dist/provenance-coverage.d.ts.map +0 -1
- package/dist/provenance-coverage.js.map +0 -1
- package/dist/rate-limit.d.ts.map +0 -1
- package/dist/rate-limit.js.map +0 -1
- package/dist/raw-archive-mirror-cleanup.d.ts.map +0 -1
- package/dist/raw-archive-mirror-cleanup.js.map +0 -1
- package/dist/raw-archive.d.ts.map +0 -1
- package/dist/raw-archive.js.map +0 -1
- package/dist/recall-history.d.ts.map +0 -1
- package/dist/recall-history.js.map +0 -1
- package/dist/recall-scope.d.ts.map +0 -1
- package/dist/recall-scope.js.map +0 -1
- package/dist/recall-trace.d.ts.map +0 -1
- package/dist/recall-trace.js.map +0 -1
- package/dist/refine-llm.d.ts.map +0 -1
- package/dist/refine-llm.js.map +0 -1
- package/dist/reject-flow.d.ts.map +0 -1
- package/dist/reject-flow.js.map +0 -1
- package/dist/rejection.d.ts.map +0 -1
- package/dist/rejection.js.map +0 -1
- package/dist/replay.d.ts.map +0 -1
- package/dist/replay.js.map +0 -1
- package/dist/rerankers/cross-encoder.d.ts.map +0 -1
- package/dist/rerankers/cross-encoder.js.map +0 -1
- package/dist/rerankers/index.d.ts.map +0 -1
- package/dist/rerankers/index.js.map +0 -1
- package/dist/rerankers/jev.d.ts.map +0 -1
- package/dist/rerankers/jev.js.map +0 -1
- package/dist/rerankers/llm.d.ts.map +0 -1
- package/dist/rerankers/llm.js.map +0 -1
- package/dist/rerankers/types.d.ts.map +0 -1
- package/dist/rerankers/types.js.map +0 -1
- package/dist/rrf.d.ts.map +0 -1
- package/dist/rrf.js.map +0 -1
- package/dist/salience.d.ts.map +0 -1
- package/dist/salience.js.map +0 -1
- package/dist/scheduler.d.ts.map +0 -1
- package/dist/scheduler.js.map +0 -1
- package/dist/scope.d.ts.map +0 -1
- package/dist/scope.js.map +0 -1
- package/dist/search.d.ts.map +0 -1
- package/dist/search.js.map +0 -1
- package/dist/secret-detect.d.ts.map +0 -1
- package/dist/secret-detect.js.map +0 -1
- package/dist/server-detect.d.ts.map +0 -1
- package/dist/server-detect.js.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/shared.d.ts.map +0 -1
- package/dist/shared.js.map +0 -1
- package/dist/skills.d.ts.map +0 -1
- package/dist/skills.js.map +0 -1
- package/dist/sleep-redact.d.ts +0 -58
- package/dist/sleep-redact.d.ts.map +0 -1
- package/dist/sleep-redact.js +0 -80
- package/dist/sleep-redact.js.map +0 -1
- package/dist/src/ablation.js +0 -138
- package/dist/src/ablation.js.map +0 -1
- package/dist/src/ambient.js +0 -148
- package/dist/src/ambient.js.map +0 -1
- package/dist/src/api.js +0 -2109
- package/dist/src/api.js.map +0 -1
- package/dist/src/audit-prune.js +0 -106
- package/dist/src/audit-prune.js.map +0 -1
- package/dist/src/audit.js +0 -213
- package/dist/src/audit.js.map +0 -1
- package/dist/src/auth.js +0 -97
- package/dist/src/auth.js.map +0 -1
- package/dist/src/autolearn.js +0 -174
- package/dist/src/autolearn.js.map +0 -1
- package/dist/src/availability.js +0 -94
- package/dist/src/availability.js.map +0 -1
- package/dist/src/capture.js +0 -1354
- package/dist/src/capture.js.map +0 -1
- package/dist/src/card-detail.js +0 -15
- package/dist/src/card-detail.js.map +0 -1
- package/dist/src/card.js +0 -19
- package/dist/src/card.js.map +0 -1
- package/dist/src/cli.js +0 -9328
- package/dist/src/cli.js.map +0 -1
- package/dist/src/client.js +0 -237
- package/dist/src/client.js.map +0 -1
- package/dist/src/compare.js +0 -122
- package/dist/src/compare.js.map +0 -1
- package/dist/src/config.js +0 -135
- package/dist/src/config.js.map +0 -1
- package/dist/src/connectors/github/backfill.js +0 -281
- package/dist/src/connectors/github/backfill.js.map +0 -1
- package/dist/src/connectors/github/cli-impl.js +0 -234
- package/dist/src/connectors/github/cli-impl.js.map +0 -1
- package/dist/src/connectors/github/deletion.js +0 -85
- package/dist/src/connectors/github/deletion.js.map +0 -1
- package/dist/src/connectors/github/dlq.js +0 -190
- package/dist/src/connectors/github/dlq.js.map +0 -1
- package/dist/src/connectors/github/idempotency.js +0 -27
- package/dist/src/connectors/github/idempotency.js.map +0 -1
- package/dist/src/connectors/github/ingest.js +0 -156
- package/dist/src/connectors/github/ingest.js.map +0 -1
- package/dist/src/connectors/github/octokit-client.js +0 -70
- package/dist/src/connectors/github/octokit-client.js.map +0 -1
- package/dist/src/connectors/github/ratelimit.js +0 -31
- package/dist/src/connectors/github/ratelimit.js.map +0 -1
- package/dist/src/connectors/github/scope.js +0 -13
- package/dist/src/connectors/github/scope.js.map +0 -1
- package/dist/src/connectors/github/signature.js +0 -81
- package/dist/src/connectors/github/signature.js.map +0 -1
- package/dist/src/connectors/github/tenant-routing.js +0 -69
- package/dist/src/connectors/github/tenant-routing.js.map +0 -1
- package/dist/src/connectors/github/transform.js +0 -103
- package/dist/src/connectors/github/transform.js.map +0 -1
- package/dist/src/connectors/github/types.js +0 -100
- package/dist/src/connectors/github/types.js.map +0 -1
- package/dist/src/connectors/slack/backfill.js +0 -78
- package/dist/src/connectors/slack/backfill.js.map +0 -1
- package/dist/src/connectors/slack/deletion.js +0 -59
- package/dist/src/connectors/slack/deletion.js.map +0 -1
- package/dist/src/connectors/slack/dlq.js +0 -224
- package/dist/src/connectors/slack/dlq.js.map +0 -1
- package/dist/src/connectors/slack/idempotency.js +0 -31
- package/dist/src/connectors/slack/idempotency.js.map +0 -1
- package/dist/src/connectors/slack/ingest.js +0 -109
- package/dist/src/connectors/slack/ingest.js.map +0 -1
- package/dist/src/connectors/slack/ratelimit.js +0 -18
- package/dist/src/connectors/slack/ratelimit.js.map +0 -1
- package/dist/src/connectors/slack/scope.js +0 -13
- package/dist/src/connectors/slack/scope.js.map +0 -1
- package/dist/src/connectors/slack/signature.js +0 -27
- package/dist/src/connectors/slack/signature.js.map +0 -1
- package/dist/src/connectors/slack/tenant-routing.js +0 -41
- package/dist/src/connectors/slack/tenant-routing.js.map +0 -1
- package/dist/src/connectors/slack/transform.js +0 -47
- package/dist/src/connectors/slack/transform.js.map +0 -1
- package/dist/src/connectors/slack/types.js +0 -35
- package/dist/src/connectors/slack/types.js.map +0 -1
- package/dist/src/connectors/slack/web-client.js +0 -43
- package/dist/src/connectors/slack/web-client.js.map +0 -1
- package/dist/src/connectors/slack/workspaces.js +0 -62
- package/dist/src/connectors/slack/workspaces.js.map +0 -1
- package/dist/src/consolidate.js +0 -978
- package/dist/src/consolidate.js.map +0 -1
- package/dist/src/correction-latency.js +0 -74
- package/dist/src/correction-latency.js.map +0 -1
- package/dist/src/customer-notes.js +0 -325
- package/dist/src/customer-notes.js.map +0 -1
- package/dist/src/dag.js +0 -352
- package/dist/src/dag.js.map +0 -1
- package/dist/src/dashboard.js +0 -258
- package/dist/src/dashboard.js.map +0 -1
- package/dist/src/db.js +0 -2728
- package/dist/src/db.js.map +0 -1
- package/dist/src/decisions.js +0 -304
- package/dist/src/decisions.js.map +0 -1
- package/dist/src/dedupe.js +0 -141
- package/dist/src/dedupe.js.map +0 -1
- package/dist/src/embedding-provider.js +0 -314
- package/dist/src/embedding-provider.js.map +0 -1
- package/dist/src/embeddings.js +0 -543
- package/dist/src/embeddings.js.map +0 -1
- package/dist/src/eval-suite.js +0 -294
- package/dist/src/eval-suite.js.map +0 -1
- package/dist/src/eval.js +0 -187
- package/dist/src/eval.js.map +0 -1
- package/dist/src/extract.js +0 -117
- package/dist/src/extract.js.map +0 -1
- package/dist/src/forward-claim-detector.js +0 -117
- package/dist/src/forward-claim-detector.js.map +0 -1
- package/dist/src/goals.js +0 -390
- package/dist/src/goals.js.map +0 -1
- package/dist/src/graph-extract.js +0 -314
- package/dist/src/graph-extract.js.map +0 -1
- package/dist/src/graph-recall.js +0 -277
- package/dist/src/graph-recall.js.map +0 -1
- package/dist/src/graph-stream.js +0 -176
- package/dist/src/graph-stream.js.map +0 -1
- package/dist/src/graph-view.js +0 -310
- package/dist/src/graph-view.js.map +0 -1
- package/dist/src/graph.js +0 -762
- package/dist/src/graph.js.map +0 -1
- package/dist/src/handoff.js +0 -65
- package/dist/src/handoff.js.map +0 -1
- package/dist/src/hooks.js +0 -926
- package/dist/src/hooks.js.map +0 -1
- package/dist/src/importers.js +0 -881
- package/dist/src/importers.js.map +0 -1
- package/dist/src/incidents.js +0 -336
- package/dist/src/incidents.js.map +0 -1
- package/dist/src/index.js +0 -32
- package/dist/src/index.js.map +0 -1
- package/dist/src/invalidation.js +0 -129
- package/dist/src/invalidation.js.map +0 -1
- package/dist/src/mcp/framing.js +0 -45
- package/dist/src/mcp/framing.js.map +0 -1
- package/dist/src/mcp/server.js +0 -1298
- package/dist/src/mcp/server.js.map +0 -1
- package/dist/src/memory-value-weights.js +0 -31
- package/dist/src/memory-value-weights.js.map +0 -1
- package/dist/src/memory-value.js +0 -261
- package/dist/src/memory-value.js.map +0 -1
- package/dist/src/memory.js +0 -425
- package/dist/src/memory.js.map +0 -1
- package/dist/src/multihop.js +0 -35
- package/dist/src/multihop.js.map +0 -1
- package/dist/src/owner-validation.js +0 -56
- package/dist/src/owner-validation.js.map +0 -1
- package/dist/src/path-context.js +0 -48
- package/dist/src/path-context.js.map +0 -1
- package/dist/src/physics-config.js +0 -26
- package/dist/src/physics-config.js.map +0 -1
- package/dist/src/physics-state.js +0 -169
- package/dist/src/physics-state.js.map +0 -1
- package/dist/src/physics.js +0 -378
- package/dist/src/physics.js.map +0 -1
- package/dist/src/policies.js +0 -414
- package/dist/src/policies.js.map +0 -1
- package/dist/src/postinstall.js +0 -101
- package/dist/src/postinstall.js.map +0 -1
- package/dist/src/predictions.js +0 -629
- package/dist/src/predictions.js.map +0 -1
- package/dist/src/processes.js +0 -349
- package/dist/src/processes.js.map +0 -1
- package/dist/src/project-briefs.js +0 -492
- package/dist/src/project-briefs.js.map +0 -1
- package/dist/src/project-identity.js +0 -200
- package/dist/src/project-identity.js.map +0 -1
- package/dist/src/provenance-coverage.js +0 -23
- package/dist/src/provenance-coverage.js.map +0 -1
- package/dist/src/rate-limit.js +0 -60
- package/dist/src/rate-limit.js.map +0 -1
- package/dist/src/raw-archive-mirror-cleanup.js +0 -55
- package/dist/src/raw-archive-mirror-cleanup.js.map +0 -1
- package/dist/src/raw-archive.js +0 -88
- package/dist/src/raw-archive.js.map +0 -1
- package/dist/src/recall-history.js +0 -235
- package/dist/src/recall-history.js.map +0 -1
- package/dist/src/recall-scope.js +0 -89
- package/dist/src/recall-scope.js.map +0 -1
- package/dist/src/recall-trace.js +0 -183
- package/dist/src/recall-trace.js.map +0 -1
- package/dist/src/refine-llm.js +0 -156
- package/dist/src/refine-llm.js.map +0 -1
- package/dist/src/reject-flow.js +0 -209
- package/dist/src/reject-flow.js.map +0 -1
- package/dist/src/rejection.js +0 -160
- package/dist/src/rejection.js.map +0 -1
- package/dist/src/replay.js +0 -122
- package/dist/src/replay.js.map +0 -1
- package/dist/src/rerankers/cross-encoder.js +0 -137
- package/dist/src/rerankers/cross-encoder.js.map +0 -1
- package/dist/src/rerankers/index.js +0 -20
- package/dist/src/rerankers/index.js.map +0 -1
- package/dist/src/rerankers/jev.js +0 -119
- package/dist/src/rerankers/jev.js.map +0 -1
- package/dist/src/rerankers/llm.js +0 -80
- package/dist/src/rerankers/llm.js.map +0 -1
- package/dist/src/rerankers/types.js +0 -2
- package/dist/src/rerankers/types.js.map +0 -1
- package/dist/src/rrf.js +0 -61
- package/dist/src/rrf.js.map +0 -1
- package/dist/src/salience.js +0 -74
- package/dist/src/salience.js.map +0 -1
- package/dist/src/scheduler.js +0 -77
- package/dist/src/scheduler.js.map +0 -1
- package/dist/src/scope.js +0 -35
- package/dist/src/scope.js.map +0 -1
- package/dist/src/search.js +0 -1003
- package/dist/src/search.js.map +0 -1
- package/dist/src/secret-detect.js +0 -95
- package/dist/src/secret-detect.js.map +0 -1
- package/dist/src/server-detect.js +0 -231
- package/dist/src/server-detect.js.map +0 -1
- package/dist/src/server.js +0 -3255
- package/dist/src/server.js.map +0 -1
- package/dist/src/shared.js +0 -502
- package/dist/src/shared.js.map +0 -1
- package/dist/src/skills.js +0 -346
- package/dist/src/skills.js.map +0 -1
- package/dist/src/sleep-redact.js +0 -80
- package/dist/src/sleep-redact.js.map +0 -1
- package/dist/src/sso.js +0 -22
- package/dist/src/sso.js.map +0 -1
- package/dist/src/store.js +0 -3743
- package/dist/src/store.js.map +0 -1
- package/dist/src/tenant.js +0 -17
- package/dist/src/tenant.js.map +0 -1
- package/dist/src/trace.js +0 -72
- package/dist/src/trace.js.map +0 -1
- package/dist/src/version.js +0 -40
- package/dist/src/version.js.map +0 -1
- package/dist/src/working-memory.js +0 -157
- package/dist/src/working-memory.js.map +0 -1
- package/dist/src/yaml.js +0 -107
- package/dist/src/yaml.js.map +0 -1
- package/dist/sso.d.ts +0 -13
- package/dist/sso.d.ts.map +0 -1
- package/dist/sso.js +0 -22
- package/dist/sso.js.map +0 -1
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/tenant.d.ts.map +0 -1
- package/dist/tenant.js.map +0 -1
- package/dist/trace.d.ts.map +0 -1
- package/dist/trace.js.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/working-memory.d.ts.map +0 -1
- package/dist/working-memory.js.map +0 -1
- package/dist/yaml.d.ts.map +0 -1
- package/dist/yaml.js.map +0 -1
package/dist/src/importers.js
DELETED
|
@@ -1,881 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Memory importers for Hippo.
|
|
3
|
-
* Imports memories from ChatGPT, Claude, Cursor, generic files, and structured markdown.
|
|
4
|
-
*/
|
|
5
|
-
import * as fs from 'fs';
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
import { createHash } from 'node:crypto';
|
|
8
|
-
import { createMemory, Layer } from './memory.js';
|
|
9
|
-
import { initStore, loadAllEntries, writeEntry } from './store.js';
|
|
10
|
-
import { textOverlap } from './search.js';
|
|
11
|
-
import { getGlobalRoot, initGlobal } from './shared.js';
|
|
12
|
-
import { remember, archiveRaw, isPrivateScope } from './api.js';
|
|
13
|
-
import { openHippoDb, closeHippoDb } from './db.js';
|
|
14
|
-
import { RejectedValueError, checkRejectionGuard } from './rejection.js';
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
// Shared core: dedup + write
|
|
17
|
-
// ---------------------------------------------------------------------------
|
|
18
|
-
/**
|
|
19
|
-
* Given an array of raw text chunks, deduplicate against existing memories,
|
|
20
|
-
* create MemoryEntry objects, write them (unless dry-run), and return a result.
|
|
21
|
-
*/
|
|
22
|
-
export function importEntries(chunks, source, tags, options) {
|
|
23
|
-
const targetRoot = options.global ? getGlobalRoot() : options.hippoRoot;
|
|
24
|
-
// Ensure store is ready
|
|
25
|
-
if (options.global) {
|
|
26
|
-
initGlobal();
|
|
27
|
-
}
|
|
28
|
-
const existing = loadAllEntries(targetRoot, options.global ? undefined : options.tenantId);
|
|
29
|
-
const allTags = [...new Set([...tags, ...(options.extraTags ?? [])])];
|
|
30
|
-
let total = 0;
|
|
31
|
-
let imported = 0;
|
|
32
|
-
let skipped = 0;
|
|
33
|
-
let rejected = 0;
|
|
34
|
-
const entries = [];
|
|
35
|
-
// AT1 P2 fix: a dry-run preview never called writeEntry, so it never
|
|
36
|
-
// checked tombstones either — every non-duplicate chunk counted as
|
|
37
|
-
// `imported` even when a real run would refuse it, making the preview's
|
|
38
|
-
// `rejected` count silently 0. Probe (read-only) via the same guard
|
|
39
|
-
// writeEntry uses internally, without ever writing.
|
|
40
|
-
const dryRunDb = options.dryRun ? openHippoDb(targetRoot) : null;
|
|
41
|
-
try {
|
|
42
|
-
for (const raw of chunks) {
|
|
43
|
-
const trimmed = raw.trim();
|
|
44
|
-
if (trimmed.length > 1000) {
|
|
45
|
-
console.error(`Warning: imported memory truncated from ${trimmed.length} to 1000 chars`);
|
|
46
|
-
}
|
|
47
|
-
const chunk = trimmed.slice(0, 1000);
|
|
48
|
-
// Skip empty or too-short chunks
|
|
49
|
-
if (!chunk || chunk.length < 10) {
|
|
50
|
-
skipped++;
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
total++;
|
|
54
|
-
// Dedup check: textOverlap > 0.7 with any existing memory = skip
|
|
55
|
-
let isDuplicate = false;
|
|
56
|
-
for (const existing_entry of existing) {
|
|
57
|
-
if (textOverlap(chunk, existing_entry.content) > 0.7) {
|
|
58
|
-
isDuplicate = true;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (isDuplicate) {
|
|
63
|
-
skipped++;
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
// A3: kind defaults to 'distilled'. ChatGPT/Claude/Cursor exports are curated
|
|
67
|
-
// user pastes, not raw transcripts from a system of record, so distilled is
|
|
68
|
-
// correct here. E1.3 (Slack ingestion) shipped 2026-04-29 in src/connectors/slack/
|
|
69
|
-
// and sets kind: 'raw' + routes deletions through archiveRawMemory() — these
|
|
70
|
-
// importers stay 'distilled' per the original reasoning. See MEMORY_ENVELOPE.md.
|
|
71
|
-
// L9: the dedup read above is scoped by options.tenantId — the WRITE
|
|
72
|
-
// must match, or scoped-dedup-passes-then-default-tenant-write breaks
|
|
73
|
-
// the per-tenant contract. Mirror the dedup-read guard: global=true
|
|
74
|
-
// → host-wide write to global store (tenantId irrelevant, createMemory
|
|
75
|
-
// defaults to 'default'). global=false → write to the same tenant as
|
|
76
|
-
// the dedup read.
|
|
77
|
-
const entry = createMemory(chunk, {
|
|
78
|
-
layer: Layer.Episodic,
|
|
79
|
-
tags: allTags,
|
|
80
|
-
source,
|
|
81
|
-
confidence: 'observed',
|
|
82
|
-
tenantId: options.global ? undefined : options.tenantId,
|
|
83
|
-
});
|
|
84
|
-
if (options.dryRun) {
|
|
85
|
-
if (dryRunDb) {
|
|
86
|
-
try {
|
|
87
|
-
checkRejectionGuard(dryRunDb, entry.tenantId ?? 'default', entry.id, entry.content);
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
if (err instanceof RejectedValueError) {
|
|
91
|
-
rejected++;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
throw err;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// AT1 (plan §3 containment): a rejection refuses one CHUNK, not the
|
|
100
|
-
// whole import batch. Caught per-item so siblings still land.
|
|
101
|
-
try {
|
|
102
|
-
writeEntry(targetRoot, entry);
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
if (err instanceof RejectedValueError) {
|
|
106
|
-
rejected++;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
throw err;
|
|
110
|
-
}
|
|
111
|
-
// Add to existing so subsequent chunks dedup against freshly imported ones
|
|
112
|
-
existing.push(entry);
|
|
113
|
-
}
|
|
114
|
-
entries.push(entry);
|
|
115
|
-
imported++;
|
|
116
|
-
}
|
|
117
|
-
return { total, imported, skipped, rejected, entries };
|
|
118
|
-
}
|
|
119
|
-
finally {
|
|
120
|
-
if (dryRunDb)
|
|
121
|
-
closeHippoDb(dryRunDb);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function isJsonString(x) {
|
|
125
|
-
return typeof x === 'string';
|
|
126
|
-
}
|
|
127
|
-
function isJsonPlainObject(x) {
|
|
128
|
-
return x !== null && !Array.isArray(x) && typeof x === 'object';
|
|
129
|
-
}
|
|
130
|
-
/** Coerce one imported record (string, `{content|text: ...}` object, or
|
|
131
|
-
* anything else) into the plain-text memory chunk it represents. */
|
|
132
|
-
function extractMemoryText(candidate) {
|
|
133
|
-
if (isJsonString(candidate))
|
|
134
|
-
return candidate;
|
|
135
|
-
if (isJsonPlainObject(candidate)) {
|
|
136
|
-
return String(candidate['content'] ?? candidate['text'] ?? '');
|
|
137
|
-
}
|
|
138
|
-
return '';
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Parse ChatGPT memory export file.
|
|
142
|
-
* Supports:
|
|
143
|
-
* - JSON array of strings: ["memory 1", "memory 2"]
|
|
144
|
-
* - JSON array of objects: [{"content": "...", "created": "..."}]
|
|
145
|
-
* - ChatGPT export format: {"memories": [{"content": "...", "created_at": "..."}]}
|
|
146
|
-
* - Plain text: one memory per line
|
|
147
|
-
*/
|
|
148
|
-
function parseChatGPTFile(filePath) {
|
|
149
|
-
const raw = fs.readFileSync(filePath, 'utf8').trim();
|
|
150
|
-
// Try JSON first
|
|
151
|
-
if (raw.startsWith('[') || raw.startsWith('{')) {
|
|
152
|
-
try {
|
|
153
|
-
const parsed = JSON.parse(raw);
|
|
154
|
-
// {"memories": [...]} - ChatGPT export format
|
|
155
|
-
if (isJsonPlainObject(parsed) && Array.isArray(parsed.memories)) {
|
|
156
|
-
return parsed.memories.map(extractMemoryText).filter(Boolean);
|
|
157
|
-
}
|
|
158
|
-
// Array format
|
|
159
|
-
if (Array.isArray(parsed)) {
|
|
160
|
-
return parsed.map(extractMemoryText).filter(Boolean);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
// Fall through to plain text
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
// Plain text: one memory per line
|
|
168
|
-
return raw.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
169
|
-
}
|
|
170
|
-
export function importChatGPT(filePath, options) {
|
|
171
|
-
const chunks = parseChatGPTFile(filePath);
|
|
172
|
-
return importEntries(chunks, 'import:chatgpt', ['imported', 'chatgpt'], options);
|
|
173
|
-
}
|
|
174
|
-
// ---------------------------------------------------------------------------
|
|
175
|
-
// Claude importer
|
|
176
|
-
// ---------------------------------------------------------------------------
|
|
177
|
-
const HIPPO_START = '<!-- hippo:start -->';
|
|
178
|
-
const HIPPO_END = '<!-- hippo:end -->';
|
|
179
|
-
/**
|
|
180
|
-
* Strip the hippo hook block from markdown content.
|
|
181
|
-
*/
|
|
182
|
-
function stripHippoBlock(content) {
|
|
183
|
-
const startIdx = content.indexOf(HIPPO_START);
|
|
184
|
-
const endIdx = content.indexOf(HIPPO_END);
|
|
185
|
-
if (startIdx === -1 || endIdx === -1)
|
|
186
|
-
return content;
|
|
187
|
-
return content.slice(0, startIdx) + content.slice(endIdx + HIPPO_END.length);
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Split markdown into meaningful chunks (headings + bullet points).
|
|
191
|
-
*/
|
|
192
|
-
function splitMarkdown(content) {
|
|
193
|
-
const chunks = [];
|
|
194
|
-
const lines = content.split('\n');
|
|
195
|
-
let current = '';
|
|
196
|
-
for (const line of lines) {
|
|
197
|
-
const trimmed = line.trim();
|
|
198
|
-
// Heading: start a new chunk
|
|
199
|
-
if (/^#{1,6}\s+/.test(trimmed)) {
|
|
200
|
-
if (current.trim())
|
|
201
|
-
chunks.push(current.trim());
|
|
202
|
-
current = trimmed;
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
// Bullet point: each bullet is its own chunk (flush previous if not a bullet context)
|
|
206
|
-
if (/^[-*+]\s+/.test(trimmed)) {
|
|
207
|
-
if (current.trim() && !/^[-*+]\s+/.test(current.split('\n')[0])) {
|
|
208
|
-
chunks.push(current.trim());
|
|
209
|
-
current = '';
|
|
210
|
-
}
|
|
211
|
-
if (current.trim()) {
|
|
212
|
-
chunks.push(current.trim());
|
|
213
|
-
current = '';
|
|
214
|
-
}
|
|
215
|
-
current = trimmed.replace(/^[-*+]\s+/, '').trim();
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
// Numbered list item
|
|
219
|
-
if (/^\d+\.\s+/.test(trimmed)) {
|
|
220
|
-
if (current.trim()) {
|
|
221
|
-
chunks.push(current.trim());
|
|
222
|
-
current = '';
|
|
223
|
-
}
|
|
224
|
-
current = trimmed.replace(/^\d+\.\s+/, '').trim();
|
|
225
|
-
continue;
|
|
226
|
-
}
|
|
227
|
-
// Empty line
|
|
228
|
-
if (!trimmed) {
|
|
229
|
-
if (current.trim()) {
|
|
230
|
-
chunks.push(current.trim());
|
|
231
|
-
current = '';
|
|
232
|
-
}
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
// Regular line: append to current
|
|
236
|
-
current = current ? current + ' ' + trimmed : trimmed;
|
|
237
|
-
}
|
|
238
|
-
if (current.trim())
|
|
239
|
-
chunks.push(current.trim());
|
|
240
|
-
return chunks.filter(Boolean);
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Parse CLAUDE.md or Claude memory.json.
|
|
244
|
-
*/
|
|
245
|
-
function parseClaudeFile(filePath) {
|
|
246
|
-
const raw = fs.readFileSync(filePath, 'utf8');
|
|
247
|
-
// JSON memory file
|
|
248
|
-
if (filePath.endsWith('.json')) {
|
|
249
|
-
try {
|
|
250
|
-
const parsed = JSON.parse(raw.trim());
|
|
251
|
-
if (Array.isArray(parsed)) {
|
|
252
|
-
return parsed.map(extractMemoryText).filter(Boolean);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
catch {
|
|
256
|
-
// Fall through to markdown
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
// Markdown file: strip hippo block and split
|
|
260
|
-
const cleaned = stripHippoBlock(raw);
|
|
261
|
-
return splitMarkdown(cleaned);
|
|
262
|
-
}
|
|
263
|
-
export function importClaude(filePath, options) {
|
|
264
|
-
const chunks = parseClaudeFile(filePath);
|
|
265
|
-
return importEntries(chunks, 'import:claude', ['imported', 'claude'], options);
|
|
266
|
-
}
|
|
267
|
-
// ---------------------------------------------------------------------------
|
|
268
|
-
// Cursor importer
|
|
269
|
-
// ---------------------------------------------------------------------------
|
|
270
|
-
/**
|
|
271
|
-
* Split cursor rules file into chunks.
|
|
272
|
-
* Priority: numbered items, then bullet points, then double newlines.
|
|
273
|
-
*/
|
|
274
|
-
function parseCursorFile(content) {
|
|
275
|
-
const chunks = [];
|
|
276
|
-
const lines = content.split('\n');
|
|
277
|
-
let current = '';
|
|
278
|
-
for (const line of lines) {
|
|
279
|
-
const trimmed = line.trim();
|
|
280
|
-
// Skip comment-only lines that are empty after stripping #
|
|
281
|
-
if (!trimmed || trimmed === '#') {
|
|
282
|
-
if (current.trim()) {
|
|
283
|
-
chunks.push(current.trim());
|
|
284
|
-
current = '';
|
|
285
|
-
}
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
// Numbered item: 1. 2. 3.
|
|
289
|
-
if (/^\d+\.\s+/.test(trimmed)) {
|
|
290
|
-
if (current.trim()) {
|
|
291
|
-
chunks.push(current.trim());
|
|
292
|
-
current = '';
|
|
293
|
-
}
|
|
294
|
-
current = trimmed.replace(/^\d+\.\s+/, '').trim();
|
|
295
|
-
continue;
|
|
296
|
-
}
|
|
297
|
-
// Bullet: - or *
|
|
298
|
-
if (/^[-*]\s+/.test(trimmed)) {
|
|
299
|
-
if (current.trim()) {
|
|
300
|
-
chunks.push(current.trim());
|
|
301
|
-
current = '';
|
|
302
|
-
}
|
|
303
|
-
current = trimmed.replace(/^[-*]\s+/, '').trim();
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
// Regular line
|
|
307
|
-
current = current ? current + ' ' + trimmed : trimmed;
|
|
308
|
-
}
|
|
309
|
-
if (current.trim())
|
|
310
|
-
chunks.push(current.trim());
|
|
311
|
-
// Also split on double newlines within chunks if they somehow ended up there
|
|
312
|
-
return chunks.flatMap((c) => {
|
|
313
|
-
const parts = c.split(/\n{2,}/);
|
|
314
|
-
return parts.map((p) => p.trim()).filter(Boolean);
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
export function importCursor(filePath, options) {
|
|
318
|
-
const raw = fs.readFileSync(filePath, 'utf8');
|
|
319
|
-
const chunks = parseCursorFile(raw);
|
|
320
|
-
return importEntries(chunks, 'import:cursor', ['imported', 'cursor'], options);
|
|
321
|
-
}
|
|
322
|
-
// ---------------------------------------------------------------------------
|
|
323
|
-
// Generic file importer
|
|
324
|
-
// ---------------------------------------------------------------------------
|
|
325
|
-
/**
|
|
326
|
-
* Split a generic file into chunks.
|
|
327
|
-
* Markdown: split on headings and bullet points.
|
|
328
|
-
* Plain text: split on double newlines or one-per-line.
|
|
329
|
-
*/
|
|
330
|
-
function parseGenericFile(filePath) {
|
|
331
|
-
const raw = fs.readFileSync(filePath, 'utf8');
|
|
332
|
-
const isMarkdown = filePath.endsWith('.md') || filePath.endsWith('.mdx');
|
|
333
|
-
if (isMarkdown) {
|
|
334
|
-
return splitMarkdown(raw);
|
|
335
|
-
}
|
|
336
|
-
// Plain text: try double newlines first
|
|
337
|
-
const byParagraph = raw.split(/\n{2,}/).map((p) => p.trim()).filter(Boolean);
|
|
338
|
-
if (byParagraph.length > 1)
|
|
339
|
-
return byParagraph;
|
|
340
|
-
// Fall back to one-per-line
|
|
341
|
-
return raw.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
342
|
-
}
|
|
343
|
-
export function importGenericFile(filePath, options) {
|
|
344
|
-
const chunks = parseGenericFile(filePath);
|
|
345
|
-
return importEntries(chunks, 'import:file', ['imported'], options);
|
|
346
|
-
}
|
|
347
|
-
// ---------------------------------------------------------------------------
|
|
348
|
-
// Structured markdown importer (MEMORY.md / AGENTS.md format)
|
|
349
|
-
// ---------------------------------------------------------------------------
|
|
350
|
-
/**
|
|
351
|
-
* Slugify a heading for use as a tag.
|
|
352
|
-
* "Data Pipeline & Cache" -> "data-pipeline-cache"
|
|
353
|
-
*/
|
|
354
|
-
function slugify(heading) {
|
|
355
|
-
return heading
|
|
356
|
-
.toLowerCase()
|
|
357
|
-
.replace(/[^a-z0-9\s-]/g, ' ')
|
|
358
|
-
.trim()
|
|
359
|
-
.replace(/\s+/g, '-')
|
|
360
|
-
.replace(/-+/g, '-')
|
|
361
|
-
.slice(0, 50);
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Parse structured markdown into {content, sectionSlug} pairs.
|
|
365
|
-
* Each heading starts a new section. Bullet points / numbered items under
|
|
366
|
-
* the heading become individual memories tagged with the section slug.
|
|
367
|
-
*/
|
|
368
|
-
function parseStructuredMarkdown(raw) {
|
|
369
|
-
const results = [];
|
|
370
|
-
const lines = raw.split('\n');
|
|
371
|
-
let currentSection = '';
|
|
372
|
-
let currentSlug = '';
|
|
373
|
-
let pendingText = '';
|
|
374
|
-
function flush() {
|
|
375
|
-
if (!pendingText.trim())
|
|
376
|
-
return;
|
|
377
|
-
results.push({ content: pendingText.trim(), sectionSlug: currentSlug });
|
|
378
|
-
pendingText = '';
|
|
379
|
-
}
|
|
380
|
-
for (const line of lines) {
|
|
381
|
-
const trimmed = line.trim();
|
|
382
|
-
// Heading
|
|
383
|
-
const headingMatch = trimmed.match(/^(#{1,6})\s+(.+)/);
|
|
384
|
-
if (headingMatch) {
|
|
385
|
-
flush();
|
|
386
|
-
currentSection = headingMatch[2].trim();
|
|
387
|
-
currentSlug = slugify(currentSection);
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
// Bullet or numbered item: flush previous, start new
|
|
391
|
-
if (/^[-*+]\s+/.test(trimmed) || /^\d+\.\s+/.test(trimmed)) {
|
|
392
|
-
flush();
|
|
393
|
-
const itemText = trimmed.replace(/^[-*+]\s+/, '').replace(/^\d+\.\s+/, '').trim();
|
|
394
|
-
pendingText = itemText;
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
// Empty line: flush current pending
|
|
398
|
-
if (!trimmed) {
|
|
399
|
-
flush();
|
|
400
|
-
continue;
|
|
401
|
-
}
|
|
402
|
-
// Continuation of current item
|
|
403
|
-
pendingText = pendingText ? pendingText + ' ' + trimmed : trimmed;
|
|
404
|
-
}
|
|
405
|
-
flush();
|
|
406
|
-
return results.filter((r) => r.content.length > 0);
|
|
407
|
-
}
|
|
408
|
-
export function importMarkdown(filePath, options) {
|
|
409
|
-
const raw = fs.readFileSync(filePath, 'utf8');
|
|
410
|
-
const parsed = parseStructuredMarkdown(raw);
|
|
411
|
-
// Group by section slug so we can pass per-chunk tags
|
|
412
|
-
// We call importEntries per unique slug to get the right tags per section
|
|
413
|
-
const bySlug = new Map();
|
|
414
|
-
for (const { content, sectionSlug } of parsed) {
|
|
415
|
-
const list = bySlug.get(sectionSlug) ?? [];
|
|
416
|
-
list.push(content);
|
|
417
|
-
bySlug.set(sectionSlug, list);
|
|
418
|
-
}
|
|
419
|
-
let totalResult = { total: 0, imported: 0, skipped: 0, rejected: 0, entries: [] };
|
|
420
|
-
for (const [slug, chunks] of bySlug.entries()) {
|
|
421
|
-
const sectionTags = slug ? ['imported', slug] : ['imported'];
|
|
422
|
-
const result = importEntries(chunks, 'import:markdown', sectionTags, options);
|
|
423
|
-
totalResult = {
|
|
424
|
-
total: totalResult.total + result.total,
|
|
425
|
-
imported: totalResult.imported + result.imported,
|
|
426
|
-
skipped: totalResult.skipped + result.skipped,
|
|
427
|
-
// AT1 P2 fix: `rejected` is now optional on ImportResult (compat) — tolerate
|
|
428
|
-
// undefined on either side of the accumulation.
|
|
429
|
-
rejected: (totalResult.rejected ?? 0) + (result.rejected ?? 0),
|
|
430
|
-
entries: [...totalResult.entries, ...result.entries],
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
return totalResult;
|
|
434
|
-
}
|
|
435
|
-
// ---------------------------------------------------------------------------
|
|
436
|
-
// K1 vault importer (markdown-vault FOLDER → kind='raw' memories)
|
|
437
|
-
//
|
|
438
|
-
// MIRRORS THE CONNECTOR PATTERN (src/connectors/slack|github), NOT the
|
|
439
|
-
// single-file importers above. Each note becomes a single kind='raw' row with
|
|
440
|
-
// provenance in TAGS (`source:vault` + `vault:<name>`), an artifactRef cursor
|
|
441
|
-
// key, and a content-hash tag. Changes APPEND a new raw row after archiveRaw of
|
|
442
|
-
// the old one; deletions archiveRaw the orphaned rows. We NEVER `supersede` a
|
|
443
|
-
// raw row (supersede yields kind='distilled', losing raw-append-only protection
|
|
444
|
-
// and escaping the kind='raw' deletion rescan) — all raw deletions route through
|
|
445
|
-
// `archiveRaw` (the only trigger-legit raw delete).
|
|
446
|
-
// ---------------------------------------------------------------------------
|
|
447
|
-
/** Escape LIKE wildcards in operator-supplied text (mirror of
|
|
448
|
-
* src/project-briefs.ts:477 / src/store.ts:782, kept local since neither is
|
|
449
|
-
* exported). Used so a `%`/`_`/`\` in the vault name cannot over-match the
|
|
450
|
-
* loader prefix and archive another vault's rows. */
|
|
451
|
-
function escapeLike(term) {
|
|
452
|
-
return term.replace(/[%_\\]/g, '\\$&');
|
|
453
|
-
}
|
|
454
|
-
function parseFrontmatter(raw) {
|
|
455
|
-
// Must start with `---` on its own line. Accept CRLF or LF.
|
|
456
|
-
const m = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
|
|
457
|
-
if (!m)
|
|
458
|
-
return { fm: {}, body: raw };
|
|
459
|
-
const block = m[1];
|
|
460
|
-
const body = raw.slice(m[0].length);
|
|
461
|
-
const fm = {};
|
|
462
|
-
const lines = block.split(/\r?\n/);
|
|
463
|
-
for (let i = 0; i < lines.length; i++) {
|
|
464
|
-
const kv = lines[i].match(/^([A-Za-z0-9_-]+)\s*:\s*(.*)$/);
|
|
465
|
-
if (!kv)
|
|
466
|
-
continue;
|
|
467
|
-
let val = kv[2].trim();
|
|
468
|
-
if (val === '') {
|
|
469
|
-
// YAML block-style list: `key:` followed by indented `- item` lines
|
|
470
|
-
// (common in Obsidian/Dendron frontmatter). Collect them into a
|
|
471
|
-
// comma-joined value so frontmatterList parses them (codex P2).
|
|
472
|
-
const items = [];
|
|
473
|
-
let j = i + 1;
|
|
474
|
-
let item;
|
|
475
|
-
while (j < lines.length && (item = lines[j].match(/^\s+-\s+(.+?)\s*$/)) !== null) {
|
|
476
|
-
items.push(item[1].replace(/^['"]|['"]$/g, '').trim());
|
|
477
|
-
j++;
|
|
478
|
-
}
|
|
479
|
-
if (items.length) {
|
|
480
|
-
val = items.join(', ');
|
|
481
|
-
i = j - 1;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
fm[kv[1]] = val;
|
|
485
|
-
}
|
|
486
|
-
return { fm, body };
|
|
487
|
-
}
|
|
488
|
-
/** Pull a frontmatter field that may be a YAML flow list (`[a, b]`), a
|
|
489
|
-
* comma-separated scalar (`a, b`), or a single token, into a string[]. Quotes
|
|
490
|
-
* and surrounding brackets are stripped; empty entries dropped. */
|
|
491
|
-
function frontmatterList(value) {
|
|
492
|
-
if (!value)
|
|
493
|
-
return [];
|
|
494
|
-
let v = value.trim();
|
|
495
|
-
if (v.startsWith('[') && v.endsWith(']'))
|
|
496
|
-
v = v.slice(1, -1);
|
|
497
|
-
return v
|
|
498
|
-
.split(',')
|
|
499
|
-
.map((s) => s.trim().replace(/^['"]|['"]$/g, '').trim())
|
|
500
|
-
.filter(Boolean);
|
|
501
|
-
}
|
|
502
|
-
/** Parse `[[wikilinks]]` from body text. `[[target]]` and `[[target|alias]]`
|
|
503
|
-
* both yield `target` (alias dropped). Returns de-duplicated, order-preserving
|
|
504
|
-
* target strings (trimmed). Embeds (`![[…]]`) are intentionally matched too —
|
|
505
|
-
* the leading `!` is not part of the `[[…]]` capture, so an embed contributes
|
|
506
|
-
* its target as a candidate, which is the desired no-crash baseline behaviour. */
|
|
507
|
-
function parseWikilinks(body) {
|
|
508
|
-
const out = [];
|
|
509
|
-
const seen = new Set();
|
|
510
|
-
const re = /\[\[([^\]]+?)\]\]/g;
|
|
511
|
-
let match;
|
|
512
|
-
while ((match = re.exec(body)) !== null) {
|
|
513
|
-
const inner = match[1];
|
|
514
|
-
const target = (inner.split('|')[0] ?? '').trim();
|
|
515
|
-
if (!target)
|
|
516
|
-
continue;
|
|
517
|
-
if (seen.has(target))
|
|
518
|
-
continue;
|
|
519
|
-
seen.add(target);
|
|
520
|
-
out.push(target);
|
|
521
|
-
}
|
|
522
|
-
return out;
|
|
523
|
-
}
|
|
524
|
-
/** Recursively collect `*.md` files under `root`, returning paths relative to
|
|
525
|
-
* `root` with forward-slash separators (stable artifactRef keys across OSes).
|
|
526
|
-
* Symlinks are not followed. Skips dot-directories (the default `.hippo` store,
|
|
527
|
-
* `.git`, `.obsidian`, `.trash`) AND the canonicalized Hippo store path during
|
|
528
|
-
* the walk, so re-importing a vault that CONTAINS the store never ingests its own
|
|
529
|
-
* markdown mirror files (codex R5 P1: `hippo import --vault .` after `hippo
|
|
530
|
-
* init` in the vault would otherwise self-import its mirror rows and grow on
|
|
531
|
-
* every run). The root-IS-the-store case is handled one level up in
|
|
532
|
-
* importVault (a no-op early return), NOT here: returning [] for it would feed
|
|
533
|
-
* the deletion-sync an empty scan that mass-archives every live row (codex R8). */
|
|
534
|
-
function collectMarkdownFiles(root, hippoRoot) {
|
|
535
|
-
const out = [];
|
|
536
|
-
// Canonicalize (realpath) so a non-dot HIPPO_HOME store nested in the vault is
|
|
537
|
-
// skipped even when hippoRoot is an aliased path (junction / Windows case
|
|
538
|
-
// variant); path.resolve would miss it and self-import the store's mirror
|
|
539
|
-
// files (codex R9 follow-up: same gap as the importVault guard, sibling site).
|
|
540
|
-
const resolvedHippoRoot = realpathOrResolve(hippoRoot);
|
|
541
|
-
const walk = (dir) => {
|
|
542
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
543
|
-
for (const ent of entries) {
|
|
544
|
-
if (ent.isSymbolicLink())
|
|
545
|
-
continue;
|
|
546
|
-
const abs = path.join(dir, ent.name);
|
|
547
|
-
if (ent.isDirectory()) {
|
|
548
|
-
// Skip dot-dirs (config/system, incl. the default `.hippo` store) and
|
|
549
|
-
// the canonicalized store path (covers a HIPPO_HOME outside `.hippo`).
|
|
550
|
-
if (ent.name.startsWith('.'))
|
|
551
|
-
continue;
|
|
552
|
-
if (realpathOrResolve(abs) === resolvedHippoRoot)
|
|
553
|
-
continue;
|
|
554
|
-
walk(abs);
|
|
555
|
-
}
|
|
556
|
-
else if (ent.isFile() && ent.name.toLowerCase().endsWith('.md')) {
|
|
557
|
-
out.push(path.relative(root, abs).split(path.sep).join('/'));
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
};
|
|
561
|
-
walk(root);
|
|
562
|
-
out.sort();
|
|
563
|
-
return out;
|
|
564
|
-
}
|
|
565
|
-
/** Canonicalize a path for the self-store comparison: dereference symlinks /
|
|
566
|
-
* junctions and normalize case (Windows) via the OS realpath, so a junction or
|
|
567
|
-
* a case-variant path to the store is still recognized as self-store (codex R9
|
|
568
|
-
* P2: path.resolve does neither, so an aliased store path slipped past the
|
|
569
|
-
* guard and triggered the mass-archive). Falls back to path.resolve when the
|
|
570
|
-
* path does not exist yet - an uninitialized store or a typo'd vault path
|
|
571
|
-
* cannot be a live self-store, and a non-existent vault folder fails later in
|
|
572
|
-
* the walk (readdirSync) before deletion-sync can archive anything. */
|
|
573
|
-
function realpathOrResolve(p) {
|
|
574
|
-
try {
|
|
575
|
-
return fs.realpathSync.native(p);
|
|
576
|
-
}
|
|
577
|
-
catch {
|
|
578
|
-
return path.resolve(p);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
/**
|
|
582
|
-
* Import a markdown vault FOLDER as `kind='raw'` memories.
|
|
583
|
-
*
|
|
584
|
-
* NOT re-entrant: idempotency rests on the in-memory `existing` Map loaded once
|
|
585
|
-
* at the top. Two concurrent importVault runs over the same vault could both see
|
|
586
|
-
* a note as absent and double-insert (the connector pattern relies on a single
|
|
587
|
-
* sequential writer; same caveat applies here).
|
|
588
|
-
*/
|
|
589
|
-
export function importVault(folderPath, options) {
|
|
590
|
-
const hippoRoot = options.hippoRoot;
|
|
591
|
-
const tenantId = options.tenantId ?? 'default';
|
|
592
|
-
// Vault NAME is the identity key for the destructive deletion-sync below, so it
|
|
593
|
-
// must be explicit. Defaulting to the folder basename meant two unrelated vaults
|
|
594
|
-
// sharing a basename (e.g. work/notes and personal/notes) collided on the same
|
|
595
|
-
// `vault:<name>:*` prefix - importing the second loaded the first's rows and the
|
|
596
|
-
// deletion-sync archived them (codex R10 P2). Require a deliberate name instead
|
|
597
|
-
// of inferring a path-unstable one.
|
|
598
|
-
const vaultName = options.name?.trim();
|
|
599
|
-
if (!vaultName) {
|
|
600
|
-
throw new Error('importVault requires an explicit vault name (options.name): it is the identity key for source-deletion sync and must not be inferred from the folder basename.');
|
|
601
|
-
}
|
|
602
|
-
if (vaultName.includes(':')) {
|
|
603
|
-
// ':' is the artifactRef delimiter (vault:<name>:<relpath>); a name
|
|
604
|
-
// containing it lets a different vault's prefix scan over-match and archive
|
|
605
|
-
// its rows (codex P2). Reject rather than silently corrupt the keys.
|
|
606
|
-
throw new Error(`vault name must not contain ':' (artifactRef delimiter): ${vaultName}`);
|
|
607
|
-
}
|
|
608
|
-
const scope = options.scope ?? null;
|
|
609
|
-
// Privacy footgun guard (codex R13 P2): hippo's recall filter only default-denies
|
|
610
|
-
// scopes shaped `<source>:private:*` (see isPrivateScope / PRIVATE_SCOPE_RE in
|
|
611
|
-
// scope.ts). A bare `private` (or `private:<x>`) first segment is NOT recognized
|
|
612
|
-
// as private, so notes a user believes are private would still be returned to
|
|
613
|
-
// no-scope recall callers. Reject the alias and point at the source-prefixed form
|
|
614
|
-
// rather than silently storing public-visible "private" notes. Use recall's own
|
|
615
|
-
// isPrivateScope as the single source of truth: reject a scope that names a
|
|
616
|
-
// `private` segment yet is NOT a valid `<source>:private:*` (catches `private`,
|
|
617
|
-
// `private:x`, and `vault:private` with a missing trailing segment).
|
|
618
|
-
if (scope !== null && scope.split(':').includes('private') && !isPrivateScope(scope)) {
|
|
619
|
-
throw new Error(`vault scope '${scope}' is not recognized as private by recall (only '<source>:private:*' scopes are default-denied). Use a source-prefixed scope such as 'vault:private:${vaultName}'.`);
|
|
620
|
-
}
|
|
621
|
-
const extraTags = options.extraTags ?? [];
|
|
622
|
-
const dryRun = options.dryRun ?? false;
|
|
623
|
-
if (options.global) {
|
|
624
|
-
// The raw-archive path is tenant-local; global mode would put raw vault rows
|
|
625
|
-
// in the wrong store. Reject for SDK callers too (the CLI also rejects
|
|
626
|
-
// --global) rather than silently writing local (codex P2).
|
|
627
|
-
throw new Error('importVault does not support global mode (raw rows are tenant-local).');
|
|
628
|
-
}
|
|
629
|
-
// Self-store no-op guard (codex R8 P1). MUST run BEFORE the existing-rows load
|
|
630
|
-
// and the deletion-sync pass below. If the vault folder IS the store (or lives
|
|
631
|
-
// inside it), there are no real vault notes - only the store's own markdown
|
|
632
|
-
// mirror files. Letting collectMarkdownFiles return [] for this case is NOT
|
|
633
|
-
// safe: an empty scan is indistinguishable from "every note was deleted", so
|
|
634
|
-
// deletion-sync would archive every live vault:<name>:* row, and raw-archive
|
|
635
|
-
// content redaction makes that loss IRREVERSIBLE. The only safe reading of
|
|
636
|
-
// "import the store into itself" is "do nothing". Canonicalize both paths
|
|
637
|
-
// (realpath: dereference junctions/symlinks + normalize Windows case) so an
|
|
638
|
-
// aliased path to the store is still caught (codex R9 P2).
|
|
639
|
-
const resolvedStore = realpathOrResolve(hippoRoot);
|
|
640
|
-
const resolvedFolder = realpathOrResolve(folderPath);
|
|
641
|
-
if (resolvedFolder === resolvedStore || resolvedFolder.startsWith(resolvedStore + path.sep)) {
|
|
642
|
-
return { total: 0, imported: 0, skipped: 0, rejected: 0, archived: 0, entries: [] };
|
|
643
|
-
}
|
|
644
|
-
const ctx = {
|
|
645
|
-
hippoRoot,
|
|
646
|
-
tenantId,
|
|
647
|
-
// Process-local actor; the vault importer is a CLI/SDK ingestion path, not
|
|
648
|
-
// a bearer-authed request. archiveRaw / remember thread this into audit.
|
|
649
|
-
actor: { subject: 'connector:vault', role: 'admin' },
|
|
650
|
-
};
|
|
651
|
-
// Load ONCE: every existing raw row for this vault, tenant-scoped. The same
|
|
652
|
-
// Map serves both per-file idempotency AND the deletion diff (no second
|
|
653
|
-
// query). LIKE-escape the vault name so a `%`/`_` in it can't over-match.
|
|
654
|
-
initStore(hippoRoot);
|
|
655
|
-
// artifactRef -> ALL its live raw rows. >1 only after a concurrent double-insert
|
|
656
|
-
// (the importer is not re-entrant; see the JSDoc). The buckets matter: a later
|
|
657
|
-
// changed/deletion pass must archive EVERY matching row, not just the last one
|
|
658
|
-
// scanned, or older raw vault content lingers live + searchable (codex P2).
|
|
659
|
-
const existing = new Map();
|
|
660
|
-
{
|
|
661
|
-
const db = openHippoDb(hippoRoot);
|
|
662
|
-
try {
|
|
663
|
-
const likeParam = `vault:${escapeLike(vaultName)}:%`;
|
|
664
|
-
// SAFETY: query selects exactly the columns of VaultRow, in the same
|
|
665
|
-
// names, from the memories table this module owns.
|
|
666
|
-
const rows = db
|
|
667
|
-
.prepare(`SELECT id, artifact_ref, tags_json, scope FROM memories
|
|
668
|
-
WHERE artifact_ref LIKE ? ESCAPE '\\' AND tenant_id = ? AND kind = 'raw'`)
|
|
669
|
-
.all(likeParam, tenantId);
|
|
670
|
-
// SQLite LIKE is case-insensitive for ASCII, so the query over-fetches
|
|
671
|
-
// (vault 'A' also matches 'vault:a:%'). Filter to the EXACT-case prefix in
|
|
672
|
-
// JS so deletion-sync never archives a different-cased vault's rows (codex P2).
|
|
673
|
-
const exactPrefix = `vault:${vaultName}:`;
|
|
674
|
-
for (const row of rows) {
|
|
675
|
-
if (row.artifact_ref && row.artifact_ref.startsWith(exactPrefix)) {
|
|
676
|
-
const bucket = existing.get(row.artifact_ref);
|
|
677
|
-
if (bucket)
|
|
678
|
-
bucket.push(row);
|
|
679
|
-
else
|
|
680
|
-
existing.set(row.artifact_ref, [row]);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
finally {
|
|
685
|
-
closeHippoDb(db);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
const relpaths = collectMarkdownFiles(folderPath, hippoRoot);
|
|
689
|
-
const seen = new Set();
|
|
690
|
-
let total = 0;
|
|
691
|
-
let imported = 0;
|
|
692
|
-
let skipped = 0;
|
|
693
|
-
let rejected = 0;
|
|
694
|
-
let archived = 0;
|
|
695
|
-
const entries = [];
|
|
696
|
-
// AT1 P2 fix: dry-run never called remember(), so it never probed
|
|
697
|
-
// tombstones — every note that reached the write step counted as
|
|
698
|
-
// `imported` even when a real run would refuse it. Probe (read-only) via
|
|
699
|
-
// the same guard remember()/writeEntry uses, without ever writing.
|
|
700
|
-
const dryRunDb = dryRun ? openHippoDb(hippoRoot) : null;
|
|
701
|
-
try {
|
|
702
|
-
for (const relpath of relpaths) {
|
|
703
|
-
total++;
|
|
704
|
-
const artifactRef = `vault:${vaultName}:${relpath}`;
|
|
705
|
-
seen.add(artifactRef);
|
|
706
|
-
// Content-hash is computed from the RAW file bytes (deterministic; no
|
|
707
|
-
// Date/random in the content path) so idempotency survives frontmatter
|
|
708
|
-
// edits identically to body edits.
|
|
709
|
-
let rawFileContent;
|
|
710
|
-
try {
|
|
711
|
-
rawFileContent = fs.readFileSync(path.join(folderPath, relpath), 'utf8');
|
|
712
|
-
}
|
|
713
|
-
catch {
|
|
714
|
-
// File vanished between enumeration and read (TOCTOU), or a transient
|
|
715
|
-
// IO/permission error. Skip this one file rather than aborting the whole
|
|
716
|
-
// import (incl. the deletion-sync pass); an idempotent re-run picks it up.
|
|
717
|
-
skipped++;
|
|
718
|
-
continue;
|
|
719
|
-
}
|
|
720
|
-
const hash = createHash('sha256').update(rawFileContent).digest('hex');
|
|
721
|
-
const hashTag = `content-hash:${hash}`;
|
|
722
|
-
// Load every live raw row for this ref (>1 only after a concurrent double-
|
|
723
|
-
// insert). The idempotency decision happens below, AFTER the full tag set is
|
|
724
|
-
// built, so it can compare the complete envelope rather than a subset.
|
|
725
|
-
const priors = existing.get(artifactRef) ?? [];
|
|
726
|
-
const { fm, body } = parseFrontmatter(rawFileContent);
|
|
727
|
-
// Empty / frontmatter-only note: nothing storable (createMemory enforces a
|
|
728
|
-
// min content length). The note's CONTENT was deleted at source, so this is a
|
|
729
|
-
// content-deletion: archive any prior row(s) - the old body must not stay live
|
|
730
|
-
// and searchable after the source no longer holds it (codex R12 P2) - then
|
|
731
|
-
// skip the write. Archiving here is safe precisely because we then skip
|
|
732
|
-
// remember() entirely: there is no archive-then-throw-on-empty-body hazard
|
|
733
|
-
// (the original reason this branch did not archive). The note stays in `seen`
|
|
734
|
-
// so deletion-sync does not double-process it.
|
|
735
|
-
if (body.trim().length < 3) {
|
|
736
|
-
for (const p of priors) {
|
|
737
|
-
archived++; // count even in dryRun so the preview reflects the removal
|
|
738
|
-
if (!dryRun)
|
|
739
|
-
archiveRaw(ctx, p.id, `emptied:${artifactRef}`);
|
|
740
|
-
}
|
|
741
|
-
skipped++;
|
|
742
|
-
continue;
|
|
743
|
-
}
|
|
744
|
-
// Build the FULL tag envelope this import would write, BEFORE the idempotency
|
|
745
|
-
// decision. De-duplicate (createMemory stores tags verbatim, so a collision
|
|
746
|
-
// between, e.g., a frontmatter tag and an extraTag would otherwise produce a
|
|
747
|
-
// duplicate). Order-preserving.
|
|
748
|
-
const frontmatterTags = [
|
|
749
|
-
...frontmatterList(fm['tags']),
|
|
750
|
-
...frontmatterList(fm['aliases']).map((a) => `alias:${a}`),
|
|
751
|
-
];
|
|
752
|
-
const wikilinkTags = parseWikilinks(body).map((t) => `wikilink-candidate:${t}`);
|
|
753
|
-
const tags = Array.from(new Set([
|
|
754
|
-
'source:vault',
|
|
755
|
-
`vault:${vaultName}`,
|
|
756
|
-
hashTag,
|
|
757
|
-
...frontmatterTags,
|
|
758
|
-
...wikilinkTags,
|
|
759
|
-
...extraTags,
|
|
760
|
-
]));
|
|
761
|
-
// Unchanged iff EVERY live raw row carries the EXACT same tag set AND scope.
|
|
762
|
-
// Comparing the COMPLETE set (not the content-hash + a subset of extra tags)
|
|
763
|
-
// means every envelope change registers: content (via the content-hash tag),
|
|
764
|
-
// frontmatter, wikilinks, an ADDED extra tag, or a REMOVED one - the earlier
|
|
765
|
-
// piecemeal checks missed scope (R10 P2) then tag removal (R11 P2). Set
|
|
766
|
-
// equality is order-independent and both sides are deduped. (`length > 0`
|
|
767
|
-
// guard: a never-seen file must import, not skip; archiving ALL priors on a
|
|
768
|
-
// mismatch also clears any concurrent-double-insert duplicates.)
|
|
769
|
-
const wantTags = new Set(tags);
|
|
770
|
-
const envelopeUnchanged = priors.length > 0 &&
|
|
771
|
-
priors.every((p) => {
|
|
772
|
-
if ((p.scope ?? null) !== scope)
|
|
773
|
-
return false;
|
|
774
|
-
const priorTags = parseJsonArrayLoose(p.tags_json);
|
|
775
|
-
return priorTags.length === wantTags.size && priorTags.every((t) => wantTags.has(t));
|
|
776
|
-
});
|
|
777
|
-
if (envelopeUnchanged) {
|
|
778
|
-
// Unchanged file + envelope → skip (idempotent re-import).
|
|
779
|
-
skipped++;
|
|
780
|
-
continue;
|
|
781
|
-
}
|
|
782
|
-
// Changed file → archive EVERY old raw row for this ref (normally one; >1
|
|
783
|
-
// only after a concurrent double-insert), then append the new one. NEVER
|
|
784
|
-
// supersede (would yield kind='distilled'). archiveRaw commits + closes its
|
|
785
|
-
// handle before remember() runs, so there is no double-live row; a crash
|
|
786
|
-
// between them self-heals (file re-imported as fresh raw next run).
|
|
787
|
-
for (const p of priors) {
|
|
788
|
-
archived++; // count the would-be archive even in dryRun (true preview)
|
|
789
|
-
if (!dryRun)
|
|
790
|
-
archiveRaw(ctx, p.id, `changed:${artifactRef}`);
|
|
791
|
-
}
|
|
792
|
-
// remember() owns the actual write. We build an `echo` of the SAME content +
|
|
793
|
-
// tags via createMemory purely for the ImportResult, then reconcile its id to
|
|
794
|
-
// remember()'s real row id so entries[] reflects the row that landed.
|
|
795
|
-
const echo = createMemory(body, {
|
|
796
|
-
kind: 'raw',
|
|
797
|
-
tags,
|
|
798
|
-
scope,
|
|
799
|
-
owner: 'agent:vault-import',
|
|
800
|
-
artifact_ref: artifactRef,
|
|
801
|
-
tenantId,
|
|
802
|
-
});
|
|
803
|
-
// dryRun preview: count what WOULD import, but make no writes (codex P2).
|
|
804
|
-
if (!dryRun) {
|
|
805
|
-
// AT1 (plan §3 containment): a rejected note must not abort the rest
|
|
806
|
-
// of the vault scan (deletion-sync pass included). The priors above
|
|
807
|
-
// are already archived by this point — same self-heal story as any
|
|
808
|
-
// other crash between archiveRaw and remember() (comment above): a
|
|
809
|
-
// re-run with the file still rejected hits the same refusal again,
|
|
810
|
-
// loud each time via the rejected count.
|
|
811
|
-
try {
|
|
812
|
-
const result = remember(ctx, {
|
|
813
|
-
content: body,
|
|
814
|
-
kind: 'raw',
|
|
815
|
-
artifactRef,
|
|
816
|
-
owner: 'agent:vault-import',
|
|
817
|
-
scope: scope ?? undefined,
|
|
818
|
-
tags,
|
|
819
|
-
});
|
|
820
|
-
echo.id = result.id;
|
|
821
|
-
}
|
|
822
|
-
catch (err) {
|
|
823
|
-
if (err instanceof RejectedValueError) {
|
|
824
|
-
rejected++;
|
|
825
|
-
continue;
|
|
826
|
-
}
|
|
827
|
-
throw err;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
else if (dryRunDb) {
|
|
831
|
-
// AT1 P2 fix: probe the tombstone without writing so the preview's
|
|
832
|
-
// `rejected` count matches what a real run would refuse.
|
|
833
|
-
try {
|
|
834
|
-
checkRejectionGuard(dryRunDb, tenantId, echo.id, echo.content);
|
|
835
|
-
}
|
|
836
|
-
catch (err) {
|
|
837
|
-
if (err instanceof RejectedValueError) {
|
|
838
|
-
rejected++;
|
|
839
|
-
continue;
|
|
840
|
-
}
|
|
841
|
-
throw err;
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
entries.push(echo);
|
|
845
|
-
imported++;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
finally {
|
|
849
|
-
if (dryRunDb)
|
|
850
|
-
closeHippoDb(dryRunDb);
|
|
851
|
-
}
|
|
852
|
-
// Deletion-sync: any artifactRef present in the Map but NOT seen this run is a
|
|
853
|
-
// note that vanished from the source folder → archive its raw row. Per-file
|
|
854
|
-
// archiveRaw (own handle); no outer SAVEPOINT (no cross-file idempotency row
|
|
855
|
-
// to commit atomically, unlike github's multi-row case).
|
|
856
|
-
for (const [artifactRef, rows] of existing) {
|
|
857
|
-
if (seen.has(artifactRef))
|
|
858
|
-
continue;
|
|
859
|
-
for (const row of rows) {
|
|
860
|
-
archived++; // count even in dryRun so the preview reflects destructive deletes
|
|
861
|
-
if (!dryRun)
|
|
862
|
-
archiveRaw(ctx, row.id, `source_deleted:${artifactRef}`);
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
return { total, imported, skipped, rejected, archived, entries };
|
|
866
|
-
}
|
|
867
|
-
/** Local tolerant JSON-array parse for the loader's `tags_json` column. The
|
|
868
|
-
* store's own `parseJsonArray` is not exported; this matches its contract
|
|
869
|
-
* (returns [] on null/garbage). */
|
|
870
|
-
function parseJsonArrayLoose(value) {
|
|
871
|
-
if (!value)
|
|
872
|
-
return [];
|
|
873
|
-
try {
|
|
874
|
-
const parsed = JSON.parse(value);
|
|
875
|
-
return Array.isArray(parsed) ? parsed.filter(isJsonString) : [];
|
|
876
|
-
}
|
|
877
|
-
catch {
|
|
878
|
-
return [];
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
//# sourceMappingURL=importers.js.map
|