hippo-memory 1.44.0 → 1.46.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 +68 -24
- package/bin/hippo.js +3 -1
- package/dist/ablation.d.ts +10 -1
- package/dist/ablation.js +17 -1
- package/dist/api.d.ts +81 -22
- package/dist/api.js +258 -49
- package/dist/audit.d.ts +2 -2
- package/dist/audit.js +9 -0
- package/dist/autolearn.d.ts +1 -1
- package/dist/autolearn.js +2 -1
- package/dist/capture-error.d.ts +20 -0
- package/dist/capture-error.js +82 -0
- package/dist/capture.d.ts +25 -8
- package/dist/capture.js +100 -5
- package/dist/cli.d.ts +9 -1
- package/dist/cli.js +531 -119
- package/dist/client.d.ts +4 -21
- package/dist/client.js +3 -112
- package/dist/config.d.ts +20 -0
- package/dist/config.js +37 -1
- package/dist/consolidate.d.ts +9 -0
- package/dist/consolidate.js +133 -46
- package/dist/dag.d.ts +1 -0
- package/dist/dag.js +10 -5
- package/dist/dashboard.js +7 -3
- package/dist/db.js +69 -24
- package/dist/dedupe.d.ts +1 -0
- package/dist/dedupe.js +4 -7
- package/dist/doctor.d.ts +34 -0
- package/dist/doctor.js +174 -0
- package/dist/dormant.d.ts +91 -0
- package/dist/dormant.js +121 -0
- package/dist/embedding-provider.js +2 -1
- package/dist/embeddings.js +81 -8
- package/dist/eval-stats.d.ts +123 -0
- package/dist/eval-stats.js +187 -0
- package/dist/extract.d.ts +2 -0
- package/dist/extract.js +9 -4
- package/dist/half-life-migration.d.ts +55 -0
- package/dist/half-life-migration.js +111 -0
- package/dist/hooks.d.ts +4 -0
- package/dist/hooks.js +47 -0
- package/dist/mcp/server.d.ts +6 -0
- package/dist/mcp/server.js +90 -48
- package/dist/memory.d.ts +18 -1
- package/dist/memory.js +33 -5
- package/dist/physics-config.js +5 -1
- package/dist/recall-scope.d.ts +24 -0
- package/dist/recall-scope.js +41 -0
- package/dist/refine-llm.js +3 -2
- package/dist/reject-flow.d.ts +3 -3
- package/dist/reject-flow.js +10 -3
- package/dist/rerankers/jev.js +3 -2
- package/dist/rerankers/llm.js +3 -2
- package/dist/search.d.ts +4 -4
- package/dist/search.js +26 -21
- package/dist/server.d.ts +5 -0
- package/dist/server.js +49 -29
- package/dist/shared.js +1 -1
- package/dist/store.d.ts +29 -11
- package/dist/store.js +197 -70
- package/dist/token-ledger.d.ts +119 -0
- package/dist/token-ledger.js +181 -0
- 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 +7 -3
- 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 -109
- 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 -1346
- 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 -9387
- 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 -2731
- 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 -399
- 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 -172
- 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 -91
- 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 -186
- 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/stdin.js +0 -41
- package/dist/src/stdin.js.map +0 -1
- package/dist/src/store.js +0 -3749
- 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/stdin.d.ts.map +0 -1
- package/dist/stdin.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/extract.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Layer, createMemory } from './memory.js';
|
|
2
|
-
import { writeEntry } from './store.js';
|
|
3
|
-
import { RejectedValueError } from './rejection.js';
|
|
4
|
-
function isJsonString(value) {
|
|
5
|
-
return typeof value === 'string';
|
|
6
|
-
}
|
|
7
|
-
const EXTRACTION_PROMPT = `You are extracting factual statements from a conversation or memory entry. Extract 1-8 standalone factual statements that would be useful to remember later.
|
|
8
|
-
|
|
9
|
-
Rules:
|
|
10
|
-
- Each fact must be a complete, standalone sentence
|
|
11
|
-
- Include the speaker's name in every fact (e.g. "Alice prefers..." not "She prefers...")
|
|
12
|
-
- Preserve specific details: names, numbers, dates, paths, IDs
|
|
13
|
-
- Return a JSON array of objects with: content (string), tags (array of "speaker:X" and "topic:Y" strings), valence ("neutral", "positive", "negative", or "critical")
|
|
14
|
-
- Return an empty array [] for small talk with no extractable facts
|
|
15
|
-
- Output ONLY the JSON array, no preamble or explanation
|
|
16
|
-
|
|
17
|
-
Input text:
|
|
18
|
-
`;
|
|
19
|
-
export async function extractFacts(text, opts) {
|
|
20
|
-
const model = opts.model ?? 'claude-sonnet-4-6';
|
|
21
|
-
const fetchFn = opts.fetcher ?? fetch;
|
|
22
|
-
let res;
|
|
23
|
-
try {
|
|
24
|
-
res = await fetchFn('https://api.anthropic.com/v1/messages', {
|
|
25
|
-
method: 'POST',
|
|
26
|
-
headers: {
|
|
27
|
-
'content-type': 'application/json',
|
|
28
|
-
'x-api-key': opts.apiKey,
|
|
29
|
-
'anthropic-version': '2023-06-01',
|
|
30
|
-
},
|
|
31
|
-
body: JSON.stringify({
|
|
32
|
-
model,
|
|
33
|
-
max_tokens: 1200,
|
|
34
|
-
messages: [{ role: 'user', content: EXTRACTION_PROMPT + text }],
|
|
35
|
-
}),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return [];
|
|
40
|
-
}
|
|
41
|
-
if (!res.ok)
|
|
42
|
-
return [];
|
|
43
|
-
try {
|
|
44
|
-
const data = await res.json();
|
|
45
|
-
const raw = data.content?.[0]?.text?.trim() ?? '';
|
|
46
|
-
if (!raw)
|
|
47
|
-
return [];
|
|
48
|
-
const parsed = JSON.parse(raw);
|
|
49
|
-
if (!Array.isArray(parsed))
|
|
50
|
-
return [];
|
|
51
|
-
const validValences = new Set(['neutral', 'positive', 'negative', 'critical']);
|
|
52
|
-
const facts = [];
|
|
53
|
-
for (const item of parsed) {
|
|
54
|
-
if (facts.length >= 8)
|
|
55
|
-
break;
|
|
56
|
-
if (!item ||
|
|
57
|
-
!isJsonString(item.content) ||
|
|
58
|
-
item.content.length < 3)
|
|
59
|
-
continue;
|
|
60
|
-
const itemTags = item.tags;
|
|
61
|
-
const tags = Array.isArray(itemTags)
|
|
62
|
-
? itemTags.filter((t) => isJsonString(t))
|
|
63
|
-
: [];
|
|
64
|
-
// SAFETY: validValences.has(item.valence) above confirms item.valence is one of the four literal strings of EmotionalValence.
|
|
65
|
-
const valence = validValences.has(item.valence)
|
|
66
|
-
? item.valence
|
|
67
|
-
: 'neutral';
|
|
68
|
-
facts.push({ content: item.content, tags, valence });
|
|
69
|
-
}
|
|
70
|
-
return facts;
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
return [];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
const INHERITABLE_PREFIXES = ['conv:', 'session:', 'scope:', 'path:'];
|
|
77
|
-
export function storeExtractedFacts(hippoRoot, source, facts) {
|
|
78
|
-
const inheritedTags = source.tags.filter((t) => INHERITABLE_PREFIXES.some((p) => t.startsWith(p)));
|
|
79
|
-
const entries = [];
|
|
80
|
-
let rejected = 0;
|
|
81
|
-
for (const fact of facts) {
|
|
82
|
-
const tags = ['extracted', ...inheritedTags, ...fact.tags];
|
|
83
|
-
const entry = createMemory(fact.content, {
|
|
84
|
-
layer: Layer.Semantic,
|
|
85
|
-
tags,
|
|
86
|
-
emotional_valence: fact.valence,
|
|
87
|
-
confidence: 'inferred',
|
|
88
|
-
source: source.source,
|
|
89
|
-
extracted_from: source.id,
|
|
90
|
-
// T1 executor check (2026-08-15 hardening pass): same defect as the
|
|
91
|
-
// consolidate.ts merge/trace passes — createMemory with no tenantId
|
|
92
|
-
// option stamps 'default' (memory.ts:535) regardless of the source
|
|
93
|
-
// entry's own tenant. Thread it through so extracted facts land in
|
|
94
|
-
// the same tenant as the episodic memory they were extracted from.
|
|
95
|
-
tenantId: source.tenantId,
|
|
96
|
-
});
|
|
97
|
-
// AT1 containment: a refusal is per-VALUE — one rejected fact must not
|
|
98
|
-
// drop the rest of this batch. writeEntry has already audited the
|
|
99
|
-
// refusal (reject_refusal) before rethrowing, so skip-and-count here.
|
|
100
|
-
try {
|
|
101
|
-
writeEntry(hippoRoot, entry);
|
|
102
|
-
}
|
|
103
|
-
catch (err) {
|
|
104
|
-
if (err instanceof RejectedValueError) {
|
|
105
|
-
rejected++;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
throw err;
|
|
109
|
-
}
|
|
110
|
-
entries.push(entry);
|
|
111
|
-
}
|
|
112
|
-
if (rejected > 0) {
|
|
113
|
-
console.error(`storeExtractedFacts: skipped ${rejected} rejected value(s)`);
|
|
114
|
-
}
|
|
115
|
-
return entries;
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=extract.js.map
|
package/dist/src/extract.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,EAAoB,YAAY,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAkBpD,SAAS,YAAY,CAAC,KAAgB;IACpC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;AACnC,CAAC;AAED,MAAM,iBAAiB,GAAG;;;;;;;;;;;CAWzB,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAA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EF,MAAM,OAAO,GAAkB,EAAE,CAAC;IAClC,IAAI,QAAQ,GAAG,CAAC,CAAC;IAEjB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,CAAC,WAAW,EAAE,GAAG,aAAa,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3D,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE;YACvC,KAAK,EAAE,KAAK,CAAC,QAAQ;YACrB,IAAI;YACJ,iBAAiB,EAAE,IAAI,CAAC,OAAO;YAC/B,UAAU,EAAE,UAAU;YACtB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,cAAc,EAAE,MAAM,CAAC,EAAE;YACzB,oEAAoE;YACpE,oEAAoE;YACpE,mEAAmE;YACnE,mEAAmE;YACnE,mEAAmE;YACnE,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC,CAAC;QAEH,uEAAuE;QACvE,kEAAkE;QAClE,sEAAsE;QACtE,IAAI,CAAC;YACH,UAAU,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,kBAAkB,EAAE,CAAC;gBACtC,QAAQ,EAAE,CAAC;gBACX,SAAS;YACX,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,gCAAgC,QAAQ,oBAAoB,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* J3.2 forward-claim detector — pure-function regex set + token extraction.
|
|
3
|
-
*
|
|
4
|
-
* No DB. No state. No dependencies beyond stdlib regex + String.
|
|
5
|
-
*
|
|
6
|
-
* The detector's job is to decide whether a recall query carries a
|
|
7
|
-
* forward-prediction phrase ("will take ~3 days", "ship by Friday",
|
|
8
|
-
* "ETA in 2 weeks"). Calibration is intentionally HIGH-PRECISION /
|
|
9
|
-
* LOW-RECALL: better to fire on 20% of real forward-claims than 80% with
|
|
10
|
-
* 40% noise. Cry-wolf failure dominates planning-fallacy hint UX (Lovallo-
|
|
11
|
-
* Kahneman 2003 inside-vs-outside view).
|
|
12
|
-
*
|
|
13
|
-
* Iteration signal: the `recall_autodebias_hint_no_class_match` audit op
|
|
14
|
-
* (emitted by computePlanningFallacyHint when a phrase matches but no class
|
|
15
|
-
* resolves) is the telemetry channel for deciding whether to add an
|
|
16
|
-
* embedding-based detector in J3.3.
|
|
17
|
-
*
|
|
18
|
-
* Plan: docs/plans/2026-05-26-j32-auto-injection.md (Task 1).
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Patterns ship-locked at v1.13.x. Each pattern is intentionally narrow —
|
|
22
|
-
* adding a pattern should require evidence from the
|
|
23
|
-
* `recall_autodebias_hint_no_class_match` audit channel that real forward-
|
|
24
|
-
* claims are slipping through, NOT speculative "this might match more".
|
|
25
|
-
*
|
|
26
|
-
* Word boundaries (`\b`) are mandatory: prevent `~5 days` inside
|
|
27
|
-
* `~5 days_ago` from matching, and prevent `ETA` substring matches inside
|
|
28
|
-
* a longer token (e.g. `BETAtesting`).
|
|
29
|
-
*/
|
|
30
|
-
// Reused fragment for ALL duration-suffix patterns. Requires a digit + unit
|
|
31
|
-
// so 'will take ownership' / 'ship in Docker' (no time component) don't
|
|
32
|
-
// match. Codex round 2 P2: patterns that allowed verb-only matches fired
|
|
33
|
-
// on every-day non-estimate queries that happened to share a class-token.
|
|
34
|
-
// Accepts `<N> unit` (3 days), `a/an unit` (a week — implicit 1), and
|
|
35
|
-
// `one unit` so natural English forward-claims aren't lost.
|
|
36
|
-
const DURATION_TAIL = String.raw `(?:about|around|~|≈)?\s*(?:\d+|a|an|one)\s*(?:day|week|month|hour|hr|min(?:ute)?|sec(?:ond)?)s?\b`;
|
|
37
|
-
const FORWARD_CLAIM_PATTERNS = [
|
|
38
|
-
// Verb + duration tail. Old pattern `/\b(?:will|should...) take\b/i`
|
|
39
|
-
// matched `who will take ownership of auth?` because there was no
|
|
40
|
-
// quantifier requirement. Now requires `<verb> take <N> <unit>`.
|
|
41
|
-
new RegExp(String.raw `\b(?:will|should|gonna|going\s+to)\s+take\s+${DURATION_TAIL}`, 'i'),
|
|
42
|
-
// Ship + by/in + duration-or-day. Old pattern `/\bship(?:ping)?\s+(?:by|in)\b/i`
|
|
43
|
-
// matched `how does this ship in Docker?`. Now requires either a
|
|
44
|
-
// duration tail OR a literal day-of-week reference.
|
|
45
|
-
new RegExp(String.raw `\bship(?:ping|s)?\s+(?:by|in)\s+(?:(?:about|around)\s+)?(?:next\s+)?(?:${DURATION_TAIL}|(?:monday|tuesday|wednesday|thursday|friday|saturday|sunday))\b`, 'i'),
|
|
46
|
-
/\bestimate(?:d)?\s+(?:at\s+)?(?:~|≈|about|around)?\s*\d+/i,
|
|
47
|
-
/\b(?:by|in|within)\s+(?:about|around|~)?\s*\d+\s*(?:day|week|month|hour)s?\b/i,
|
|
48
|
-
/\bETA\s*(?:is|:)?\s*\d+/i,
|
|
49
|
-
/\b(?:by|before)\s+next\s+(?:week|month|sprint|monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/i,
|
|
50
|
-
// Standalone tilde duration: '~3 days for migration', 'estimate ~3 days'.
|
|
51
|
-
// Lookbehind asserts start-of-string OR whitespace before the tilde
|
|
52
|
-
// because \b before ~ requires a word char immediately preceding (~ is
|
|
53
|
-
// not a word character), so /\b~/ would only match in 'foo~3 days'
|
|
54
|
-
// (malformed) and silently miss the legitimate cases. Codex review
|
|
55
|
-
// round 1 catch.
|
|
56
|
-
/(?<=^|\s)~\s*\d+\s*(?:day|week|month|hour)s?\b/i,
|
|
57
|
-
// Should + verb + duration tail. Same tightening as the leading 'will
|
|
58
|
-
// take' rule: 'should ship by EOD' must include a quantifier.
|
|
59
|
-
new RegExp(String.raw `\bshould\s+(?:be|ship|finish|complete|land)\s+(?:by|in|within)\s+(?:(?:about|around)\s+)?(?:next\s+)?(?:${DURATION_TAIL}|(?:monday|tuesday|wednesday|thursday|friday|saturday|sunday))\b`, 'i'),
|
|
60
|
-
];
|
|
61
|
-
/**
|
|
62
|
-
* Pronouns + function words + modal verbs the regex set already gates on.
|
|
63
|
-
* Dropped before class-resolution so the overlap signal comes from
|
|
64
|
-
* domain tokens ("migration", "auth", "refactor") rather than connectives.
|
|
65
|
-
*/
|
|
66
|
-
const STOP_WORDS = new Set([
|
|
67
|
-
'the', 'a', 'an', 'and', 'or', 'but', 'for', 'to', 'in', 'on', 'at', 'of',
|
|
68
|
-
'by', 'with', 'my', 'your', 'our', 'their', 'its', 'it', 'this', 'that',
|
|
69
|
-
'these', 'those', 'will', 'should', 'can', 'i', 'we', 'they', 'he', 'she',
|
|
70
|
-
'is', 'be', 'was', 'are', 'were', 'has', 'have', 'had', 'do', 'does', 'did',
|
|
71
|
-
'from', 'as', 'so', 'than', 'then',
|
|
72
|
-
// Verbs that appear inside FORWARD_CLAIM_PATTERNS themselves — they're
|
|
73
|
-
// signal for the regex gate but NOT signal for class resolution (you
|
|
74
|
-
// wouldn't name a prediction class "take" or "ship"). Listing here so
|
|
75
|
-
// they don't pollute the classQueryTokens overlap score.
|
|
76
|
-
'take', 'taken', 'takes', 'ship', 'ships', 'finish', 'complete', 'land',
|
|
77
|
-
'eta', 'estimate', 'estimated', 'next', 'about', 'around',
|
|
78
|
-
// Duration units appear in every forward-claim phrase by design (the
|
|
79
|
-
// regex set REQUIRES a `<N> <unit>` quantifier after the verb). Letting
|
|
80
|
-
// them through to class resolution lets a class tag containing 'days'
|
|
81
|
-
// win or tie on the unit token instead of the domain token. Codex round
|
|
82
|
-
// 2 P3 catch.
|
|
83
|
-
'day', 'days', 'week', 'weeks', 'month', 'months',
|
|
84
|
-
'hour', 'hours', 'hr', 'hrs',
|
|
85
|
-
'min', 'mins', 'minute', 'minutes', 'sec', 'secs', 'second', 'seconds',
|
|
86
|
-
]);
|
|
87
|
-
/**
|
|
88
|
-
* Detect whether a recall query carries a forward-prediction phrase.
|
|
89
|
-
*
|
|
90
|
-
* @returns first-match phrase + extracted class-resolution tokens when
|
|
91
|
-
* any pattern matches; null otherwise. Token extraction runs only on a
|
|
92
|
-
* match — non-forward queries pay zero work beyond the regex gate.
|
|
93
|
-
*/
|
|
94
|
-
export function detectForwardClaim(queryText) {
|
|
95
|
-
if (!queryText)
|
|
96
|
-
return null;
|
|
97
|
-
for (const pat of FORWARD_CLAIM_PATTERNS) {
|
|
98
|
-
const m = queryText.match(pat);
|
|
99
|
-
if (m) {
|
|
100
|
-
const tokens = extractClassQueryTokens(queryText);
|
|
101
|
-
return { phrase: m[0], classQueryTokens: tokens };
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
function extractClassQueryTokens(queryText) {
|
|
107
|
-
return queryText
|
|
108
|
-
.toLowerCase()
|
|
109
|
-
// Strip everything that's not alphanum or whitespace or hyphen / underscore.
|
|
110
|
-
.replace(/[^a-z0-9\s_-]/g, ' ')
|
|
111
|
-
// Split on whitespace AND hyphen AND underscore so `migration-effort`
|
|
112
|
-
// produces ['migration', 'effort'] — matching the class-tag split
|
|
113
|
-
// pattern in resolveClassFromTokens (split on /[-_\s]+/).
|
|
114
|
-
.split(/[\s_-]+/)
|
|
115
|
-
.filter((t) => t.length >= 3 && !STOP_WORDS.has(t) && !/^\d+$/.test(t));
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=forward-claim-detector.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"forward-claim-detector.js","sourceRoot":"","sources":["../../src/forward-claim-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;;;;;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5E,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;QAC/B,sEAAsE;QACtE,kEAAkE;QAClE,0DAA0D;SACzD,KAAK,CAAC,SAAS,CAAC;SAChB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/src/goals.js
DELETED
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
// src/goals.ts
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { openHippoDb, closeHippoDb } from './db.js';
|
|
4
|
-
export const MAX_ACTIVE_GOAL_DEPTH = 3;
|
|
5
|
-
export const MAX_FINAL_MULTIPLIER = 3.0;
|
|
6
|
-
export function rowToGoal(row) {
|
|
7
|
-
return {
|
|
8
|
-
id: row.id,
|
|
9
|
-
sessionId: row.session_id,
|
|
10
|
-
tenantId: row.tenant_id,
|
|
11
|
-
goalName: row.goal_name,
|
|
12
|
-
level: row.level,
|
|
13
|
-
parentGoalId: row.parent_goal_id ?? undefined,
|
|
14
|
-
status: row.status,
|
|
15
|
-
successCondition: row.success_condition ?? undefined,
|
|
16
|
-
retrievalPolicyId: row.retrieval_policy_id ?? undefined,
|
|
17
|
-
createdAt: row.created_at,
|
|
18
|
-
completedAt: row.completed_at ?? undefined,
|
|
19
|
-
outcomeScore: row.outcome_score ?? undefined,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export function pushGoal(hippoRoot, opts) {
|
|
23
|
-
const db = openHippoDb(hippoRoot);
|
|
24
|
-
try {
|
|
25
|
-
return pushGoalWithDb(db, opts);
|
|
26
|
-
}
|
|
27
|
-
finally {
|
|
28
|
-
closeHippoDb(db);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* v1.7.4 — depth-cap enforcer extracted from pushGoalWithDb and resumeGoal.
|
|
33
|
-
* If the (tenant, session) has >= MAX_ACTIVE_GOAL_DEPTH active goals,
|
|
34
|
-
* suspend the oldest `overflow` ones.
|
|
35
|
-
*
|
|
36
|
-
* **Precondition: caller MUST already be inside a `BEGIN IMMEDIATE`
|
|
37
|
-
* transaction.** Helper does not open or commit -- name reflects this so it
|
|
38
|
-
* is impossible to misread the contract at a call site. Both existing call
|
|
39
|
-
* sites (pushGoalWithDb, resumeGoal) wrap in `BEGIN IMMEDIATE` already.
|
|
40
|
-
*
|
|
41
|
-
* @internal v1.7.4 -- internal goal-stack invariant. Subject to change.
|
|
42
|
-
*/
|
|
43
|
-
export function enforceDepthCapWithinTx(db, tenantId, sessionId) {
|
|
44
|
-
// SAFETY: the row comes from the SELECT above, which projects exactly one
|
|
45
|
-
// column, `c`, as a COUNT(*).
|
|
46
|
-
const activeCount = db.prepare(`
|
|
47
|
-
SELECT COUNT(*) AS c
|
|
48
|
-
FROM goal_stack
|
|
49
|
-
WHERE tenant_id = ? AND session_id = ? AND status = 'active'
|
|
50
|
-
`).get(tenantId, sessionId).c;
|
|
51
|
-
if (activeCount >= MAX_ACTIVE_GOAL_DEPTH) {
|
|
52
|
-
const overflow = activeCount - MAX_ACTIVE_GOAL_DEPTH + 1;
|
|
53
|
-
db.prepare(`
|
|
54
|
-
UPDATE goal_stack
|
|
55
|
-
SET status = 'suspended'
|
|
56
|
-
WHERE id IN (
|
|
57
|
-
SELECT id FROM goal_stack
|
|
58
|
-
WHERE tenant_id = ? AND session_id = ? AND status = 'active'
|
|
59
|
-
ORDER BY created_at ASC
|
|
60
|
-
LIMIT ?
|
|
61
|
-
)
|
|
62
|
-
`).run(tenantId, sessionId, overflow);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export function pushGoalWithDb(db, opts) {
|
|
66
|
-
const id = `g_${randomUUID().replace(/-/g, '').slice(0, 16)}`;
|
|
67
|
-
const createdAt = new Date().toISOString();
|
|
68
|
-
let policyId = null;
|
|
69
|
-
db.exec('BEGIN IMMEDIATE');
|
|
70
|
-
try {
|
|
71
|
-
// Depth cap: count active for (tenant, session); suspend oldest if at cap.
|
|
72
|
-
enforceDepthCapWithinTx(db, opts.tenantId, opts.sessionId);
|
|
73
|
-
if (opts.parentGoalId) {
|
|
74
|
-
// SAFETY: the row comes from the SELECT above, which projects exactly
|
|
75
|
-
// the tenant_id and session_id columns of goal_stack.
|
|
76
|
-
const parent = db.prepare(`SELECT tenant_id, session_id FROM goal_stack WHERE id = ?`).get(opts.parentGoalId);
|
|
77
|
-
if (!parent) {
|
|
78
|
-
throw new Error(`parent goal not found: ${opts.parentGoalId}`);
|
|
79
|
-
}
|
|
80
|
-
if (parent.tenant_id !== opts.tenantId || parent.session_id !== opts.sessionId) {
|
|
81
|
-
throw new Error(`parent goal ${opts.parentGoalId} belongs to a different (tenant, session)`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// Parent goal_stack row first (FK target).
|
|
85
|
-
db.prepare(`
|
|
86
|
-
INSERT INTO goal_stack
|
|
87
|
-
(id, session_id, tenant_id, goal_name, level, parent_goal_id, status,
|
|
88
|
-
success_condition, retrieval_policy_id, created_at)
|
|
89
|
-
VALUES (?, ?, ?, ?, ?, ?, 'active', ?, NULL, ?)
|
|
90
|
-
`).run(id, opts.sessionId, opts.tenantId, opts.goalName, opts.level ?? 0, opts.parentGoalId ?? null, opts.successCondition ?? null, createdAt);
|
|
91
|
-
// Optional policy row, then point goal_stack.retrieval_policy_id at it.
|
|
92
|
-
if (opts.policy) {
|
|
93
|
-
policyId = `rp_${randomUUID().replace(/-/g, '').slice(0, 16)}`;
|
|
94
|
-
db.prepare(`
|
|
95
|
-
INSERT INTO retrieval_policy
|
|
96
|
-
(id, goal_id, policy_type, weight_schema_fit, weight_recency, weight_outcome, error_priority)
|
|
97
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
98
|
-
`).run(policyId, id, opts.policy.policyType, opts.policy.weightSchemaFit ?? 1.0, opts.policy.weightRecency ?? 1.0, opts.policy.weightOutcome ?? 1.0, opts.policy.errorPriority ?? 1.0);
|
|
99
|
-
db.prepare(`UPDATE goal_stack SET retrieval_policy_id = ? WHERE id = ?`).run(policyId, id);
|
|
100
|
-
}
|
|
101
|
-
db.exec('COMMIT');
|
|
102
|
-
}
|
|
103
|
-
catch (err) {
|
|
104
|
-
try {
|
|
105
|
-
db.exec('ROLLBACK');
|
|
106
|
-
}
|
|
107
|
-
catch { /* already rolled back; keep the original error */ }
|
|
108
|
-
throw err;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
id,
|
|
112
|
-
sessionId: opts.sessionId,
|
|
113
|
-
tenantId: opts.tenantId,
|
|
114
|
-
goalName: opts.goalName,
|
|
115
|
-
level: opts.level ?? 0,
|
|
116
|
-
parentGoalId: opts.parentGoalId,
|
|
117
|
-
status: 'active',
|
|
118
|
-
successCondition: opts.successCondition,
|
|
119
|
-
retrievalPolicyId: policyId ?? undefined,
|
|
120
|
-
createdAt,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
export function getActiveGoals(hippoRoot, opts) {
|
|
124
|
-
const db = openHippoDb(hippoRoot);
|
|
125
|
-
try {
|
|
126
|
-
return getActiveGoalsWithDb(db, opts);
|
|
127
|
-
}
|
|
128
|
-
finally {
|
|
129
|
-
closeHippoDb(db);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export function getActiveGoalsWithDb(db, opts) {
|
|
133
|
-
// SAFETY: rows come from the SELECT above, which projects exactly
|
|
134
|
-
// GoalRow's columns (in the same order goal_stack defines them).
|
|
135
|
-
const rows = db.prepare(`
|
|
136
|
-
SELECT id, session_id, tenant_id, goal_name, level, parent_goal_id, status,
|
|
137
|
-
success_condition, retrieval_policy_id, created_at, completed_at, outcome_score
|
|
138
|
-
FROM goal_stack
|
|
139
|
-
WHERE tenant_id = ? AND session_id = ? AND status = 'active'
|
|
140
|
-
ORDER BY created_at ASC
|
|
141
|
-
`).all(opts.tenantId, opts.sessionId);
|
|
142
|
-
return rows.map(rowToGoal);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* v1.7.4 -- dlPFC goal-stack boost helper. Applies the multi-goal boost to a
|
|
146
|
-
* list of entry-backed scored rows when (tenant, session) has active goals.
|
|
147
|
-
* Pre-v1.7.4 this logic lived inline in cmdRecall (src/cli.ts:988-1140);
|
|
148
|
-
* lifting here lets api.recall (primary band only) AND MCP physics/hybrid
|
|
149
|
-
* call it.
|
|
150
|
-
*
|
|
151
|
-
* Caller responsibilities:
|
|
152
|
-
* - Do NOT call when an explicit `goalTag` is set (caller's gate)
|
|
153
|
-
* - Pass entry-backed rows (with `entry.tags`, `entry.id`, optional
|
|
154
|
-
* `entry.schema_fit`)
|
|
155
|
-
* - Manage the db handle lifecycle (helper neither opens nor closes)
|
|
156
|
-
* - Recompute `tokens` after if returned rows are projected to a budgeted
|
|
157
|
-
* shape
|
|
158
|
-
*
|
|
159
|
-
* Side effects:
|
|
160
|
-
* - INSERT OR IGNORE into `goal_recall_log` for each (boosted, goal) pair
|
|
161
|
-
* - Local memory id filter applied before INSERT (skips global-only ids
|
|
162
|
-
* to preserve FK invariant on goal_recall_log.memory_id)
|
|
163
|
-
*
|
|
164
|
-
* @internal v1.7.4 -- internal recall ranking helper. Subject to change.
|
|
165
|
-
*/
|
|
166
|
-
export function applyGoalStackBoost(db, results, opts) {
|
|
167
|
-
const { sessionId, tenantId, limit, trace } = opts;
|
|
168
|
-
const active = getActiveGoalsWithDb(db, { sessionId, tenantId });
|
|
169
|
-
if (active.length === 0)
|
|
170
|
-
return results;
|
|
171
|
-
const goalsByTag = new Map(active.map((g) => [g.goalName, g]));
|
|
172
|
-
// Load retrieval_policy rows for active goals so per-policy multipliers
|
|
173
|
-
// can compose onto the base goal-tag boost. Composed result is hard-capped
|
|
174
|
-
// at MAX_FINAL_MULTIPLIER (3.0x) BEFORE applying to score -- even an
|
|
175
|
-
// `errorPriority: 9.0` policy cannot exceed 3.0x.
|
|
176
|
-
const policiesByGoalId = new Map();
|
|
177
|
-
for (const g of active) {
|
|
178
|
-
if (!g.retrievalPolicyId)
|
|
179
|
-
continue;
|
|
180
|
-
// SAFETY: the row comes from the SELECT above, which projects exactly
|
|
181
|
-
// these seven retrieval_policy columns.
|
|
182
|
-
const row = db.prepare(`
|
|
183
|
-
SELECT id, goal_id, policy_type, weight_schema_fit, weight_recency, weight_outcome, error_priority
|
|
184
|
-
FROM retrieval_policy WHERE id = ?
|
|
185
|
-
`).get(g.retrievalPolicyId);
|
|
186
|
-
if (row) {
|
|
187
|
-
policiesByGoalId.set(g.id, {
|
|
188
|
-
id: row.id,
|
|
189
|
-
goalId: row.goal_id,
|
|
190
|
-
policyType: row.policy_type,
|
|
191
|
-
weightSchemaFit: row.weight_schema_fit,
|
|
192
|
-
weightRecency: row.weight_recency,
|
|
193
|
-
weightOutcome: row.weight_outcome,
|
|
194
|
-
errorPriority: row.error_priority,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// Goal-tag matches per boosted row, keyed by entry id. Kept as a side table
|
|
199
|
-
// (rather than a spread-on `_goalMatches` marker property) so `boosted`
|
|
200
|
-
// stays exactly R[] end to end, with no cast-tag-then-strip round trip.
|
|
201
|
-
const matchesByEntryId = new Map();
|
|
202
|
-
const boosted = results
|
|
203
|
-
.map((r) => {
|
|
204
|
-
const tags = r.entry.tags ?? [];
|
|
205
|
-
const matches = tags.filter((t) => goalsByTag.has(t));
|
|
206
|
-
if (matches.length === 0)
|
|
207
|
-
return r;
|
|
208
|
-
// Base 2.0x for first match, +0.5x per additional, capped at 3.0x.
|
|
209
|
-
let multiplier = Math.min(2.0 + 0.5 * (matches.length - 1), MAX_FINAL_MULTIPLIER);
|
|
210
|
-
// Compose per-policy multipliers per matched tag.
|
|
211
|
-
for (const tag of matches) {
|
|
212
|
-
const goal = goalsByTag.get(tag);
|
|
213
|
-
const policy = policiesByGoalId.get(goal.id);
|
|
214
|
-
if (!policy)
|
|
215
|
-
continue;
|
|
216
|
-
if (policy.policyType === 'error-prioritized' && tags.includes('error')) {
|
|
217
|
-
multiplier *= policy.errorPriority;
|
|
218
|
-
}
|
|
219
|
-
else if (policy.policyType === 'schema-fit-biased') {
|
|
220
|
-
// Linearly weight schema_fit in [0,1] up to (weightSchemaFit)x.
|
|
221
|
-
// Default 1.0 is a no-op.
|
|
222
|
-
multiplier *=
|
|
223
|
-
1.0 +
|
|
224
|
-
Math.max(0, policy.weightSchemaFit - 1.0) *
|
|
225
|
-
(r.entry.schema_fit ?? 0.5);
|
|
226
|
-
}
|
|
227
|
-
else if (policy.policyType === 'recency-first') {
|
|
228
|
-
multiplier *= policy.weightRecency;
|
|
229
|
-
}
|
|
230
|
-
else if (policy.policyType === 'hybrid') {
|
|
231
|
-
multiplier *= policy.weightOutcome;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
// Hard cap AFTER all composition.
|
|
235
|
-
multiplier = Math.min(multiplier, MAX_FINAL_MULTIPLIER);
|
|
236
|
-
// A7 recall-trace side-channel: record the goal-boost step BEFORE the
|
|
237
|
-
// score is mutated, keyed by entry id. Pure read of r.score here; the
|
|
238
|
-
// mutation below is byte-identical to pre-A7.
|
|
239
|
-
if (trace) {
|
|
240
|
-
trace.set(r.entry.id, {
|
|
241
|
-
stage: 'goal-boost',
|
|
242
|
-
multiplier,
|
|
243
|
-
scoreBefore: r.score,
|
|
244
|
-
scoreAfter: r.score * multiplier,
|
|
245
|
-
note: matches.join(', '),
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
matchesByEntryId.set(r.entry.id, matches);
|
|
249
|
-
// SAFETY: spreading a generic-constrained `r: R` widens the result to
|
|
250
|
-
// the spread's plain object type; only `score` changes, so the value
|
|
251
|
-
// still satisfies R's shape exactly.
|
|
252
|
-
return { ...r, score: r.score * multiplier };
|
|
253
|
-
})
|
|
254
|
-
// T2 note: deliberately a PLAIN stable score sort, no compareEntryIdentity
|
|
255
|
-
// tail -- a re-sort of an already deterministically-ordered ranking
|
|
256
|
-
// inherits its determinism via sort stability, and ties preserve the
|
|
257
|
-
// prior (meaningful) rank instead of reordering by content.
|
|
258
|
-
.sort((a, b) => b.score - a.score);
|
|
259
|
-
// Filter to local memories only -- global memory IDs aren't in this DB's
|
|
260
|
-
// memories table, so the FK on goal_recall_log.memory_id would fail.
|
|
261
|
-
// dlPFC depth's outcome propagation is session-scoped to local; boost on
|
|
262
|
-
// ranking still applies to global results, just no log row -> no
|
|
263
|
-
// propagation.
|
|
264
|
-
const topKIds = boosted.slice(0, limit).map((r) => r.entry.id);
|
|
265
|
-
const localIds = new Set();
|
|
266
|
-
if (topKIds.length > 0) {
|
|
267
|
-
const placeholders = topKIds.map(() => '?').join(',');
|
|
268
|
-
// SAFETY: rows come from the SELECT above, which projects exactly one
|
|
269
|
-
// column, `id`, from memories.
|
|
270
|
-
const localRows = db.prepare(`SELECT id FROM memories WHERE id IN (${placeholders})`).all(...topKIds);
|
|
271
|
-
for (const row of localRows)
|
|
272
|
-
localIds.add(row.id);
|
|
273
|
-
}
|
|
274
|
-
// Log top-K boosted recalls. INSERT OR IGNORE because
|
|
275
|
-
// UNIQUE(memory_id, goal_id) means a re-recall during the same goal life
|
|
276
|
-
// is a no-op for outcome attribution.
|
|
277
|
-
const recalledAt = new Date().toISOString();
|
|
278
|
-
const insertLog = db.prepare(`
|
|
279
|
-
INSERT OR IGNORE INTO goal_recall_log
|
|
280
|
-
(goal_id, memory_id, tenant_id, session_id, recalled_at, score)
|
|
281
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
282
|
-
`);
|
|
283
|
-
for (const r of boosted.slice(0, limit)) {
|
|
284
|
-
if (!localIds.has(r.entry.id))
|
|
285
|
-
continue; // global -> skip log insert
|
|
286
|
-
const matches = matchesByEntryId.get(r.entry.id);
|
|
287
|
-
if (!matches || matches.length === 0)
|
|
288
|
-
continue;
|
|
289
|
-
for (const tag of matches) {
|
|
290
|
-
const goal = goalsByTag.get(tag);
|
|
291
|
-
if (!goal)
|
|
292
|
-
continue;
|
|
293
|
-
insertLog.run(goal.id, r.entry.id, tenantId, sessionId, recalledAt, r.score);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return boosted;
|
|
297
|
-
}
|
|
298
|
-
const POSITIVE_OUTCOME_THRESHOLD = 0.7;
|
|
299
|
-
const NEGATIVE_OUTCOME_THRESHOLD = 0.3;
|
|
300
|
-
const STRENGTH_BOOST = 1.10;
|
|
301
|
-
const STRENGTH_DECAY = 0.85;
|
|
302
|
-
export function completeGoal(hippoRoot, goalId, opts) {
|
|
303
|
-
const db = openHippoDb(hippoRoot);
|
|
304
|
-
try {
|
|
305
|
-
const completedAt = new Date().toISOString();
|
|
306
|
-
const score = opts.outcomeScore ?? null;
|
|
307
|
-
db.exec('BEGIN IMMEDIATE');
|
|
308
|
-
try {
|
|
309
|
-
// SAFETY: the row comes from the SELECT above, which projects exactly
|
|
310
|
-
// the created_at and status columns of goal_stack.
|
|
311
|
-
const goalRow = db.prepare(`SELECT created_at, status FROM goal_stack WHERE id = ?`).get(goalId);
|
|
312
|
-
if (!goalRow) {
|
|
313
|
-
db.exec('COMMIT');
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
if (goalRow.status === 'completed') {
|
|
317
|
-
// Already completed -- second call is a no-op for idempotency.
|
|
318
|
-
db.exec('COMMIT');
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
db.prepare(`
|
|
322
|
-
UPDATE goal_stack
|
|
323
|
-
SET status = 'completed', completed_at = ?, outcome_score = ?
|
|
324
|
-
WHERE id = ?
|
|
325
|
-
`).run(completedAt, score, goalId);
|
|
326
|
-
if (score !== null && !opts.noPropagate) {
|
|
327
|
-
let multiplier = 1;
|
|
328
|
-
if (score >= POSITIVE_OUTCOME_THRESHOLD)
|
|
329
|
-
multiplier = STRENGTH_BOOST;
|
|
330
|
-
else if (score < NEGATIVE_OUTCOME_THRESHOLD)
|
|
331
|
-
multiplier = STRENGTH_DECAY;
|
|
332
|
-
if (multiplier !== 1) {
|
|
333
|
-
// Lifespan window: only memories whose recall happened during this
|
|
334
|
-
// goal's active life. UNIQUE(memory_id, goal_id) guarantees one
|
|
335
|
-
// adjustment per (memory, goal) pair.
|
|
336
|
-
db.prepare(`
|
|
337
|
-
UPDATE memories
|
|
338
|
-
SET strength = MIN(1.0, MAX(0.0, strength * ?))
|
|
339
|
-
WHERE id IN (
|
|
340
|
-
SELECT memory_id FROM goal_recall_log
|
|
341
|
-
WHERE goal_id = ?
|
|
342
|
-
AND recalled_at >= ?
|
|
343
|
-
AND recalled_at <= ?
|
|
344
|
-
)
|
|
345
|
-
`).run(multiplier, goalId, goalRow.created_at, completedAt);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
db.exec('COMMIT');
|
|
349
|
-
}
|
|
350
|
-
catch (err) {
|
|
351
|
-
try {
|
|
352
|
-
db.exec('ROLLBACK');
|
|
353
|
-
}
|
|
354
|
-
catch { /* already rolled back; keep the original error */ }
|
|
355
|
-
throw err;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
finally {
|
|
359
|
-
closeHippoDb(db);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
export function suspendGoal(hippoRoot, goalId) {
|
|
363
|
-
const db = openHippoDb(hippoRoot);
|
|
364
|
-
try {
|
|
365
|
-
db.prepare(`UPDATE goal_stack SET status = 'suspended' WHERE id = ? AND status = 'active'`).run(goalId);
|
|
366
|
-
}
|
|
367
|
-
finally {
|
|
368
|
-
closeHippoDb(db);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
export function resumeGoal(hippoRoot, goalId) {
|
|
372
|
-
const db = openHippoDb(hippoRoot);
|
|
373
|
-
try {
|
|
374
|
-
db.exec('BEGIN IMMEDIATE');
|
|
375
|
-
try {
|
|
376
|
-
// SAFETY: the row comes from the SELECT above, which projects exactly
|
|
377
|
-
// the session_id, tenant_id, and status columns of goal_stack.
|
|
378
|
-
const row = db.prepare(`SELECT session_id, tenant_id, status FROM goal_stack WHERE id = ?`).get(goalId);
|
|
379
|
-
if (!row || row.status !== 'suspended') {
|
|
380
|
-
db.exec('COMMIT');
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
enforceDepthCapWithinTx(db, row.tenant_id, row.session_id);
|
|
384
|
-
db.prepare(`UPDATE goal_stack SET status = 'active' WHERE id = ?`).run(goalId);
|
|
385
|
-
db.exec('COMMIT');
|
|
386
|
-
}
|
|
387
|
-
catch (err) {
|
|
388
|
-
try {
|
|
389
|
-
db.exec('ROLLBACK');
|
|
390
|
-
}
|
|
391
|
-
catch { /* already rolled back; keep the original error */ }
|
|
392
|
-
throw err;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
finally {
|
|
396
|
-
closeHippoDb(db);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
//# sourceMappingURL=goals.js.map
|