@hasna/mementos 0.14.84 → 0.14.86
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/bun.lock +63 -4
- package/dist/cli/index.js +769 -261
- package/dist/diagnostics/historical-project-registration-receipt.js +1675 -0
- package/dist/index.js +343 -85
- package/dist/mcp/index.js +419 -99
- package/dist/pg-sync-worker.js +7 -5
- package/dist/project-registration.js +309 -68
- package/dist/sdk/index.js +123 -30
- package/dist/server/index.js +677 -317
- package/dist/storage.js +63 -26
- package/hasna.contract.json +5 -4
- package/package.json +6 -4
- package/dist/cli/__fixtures__/clean-fallback-stub-server.d.ts +0 -2
- package/dist/cli/__fixtures__/clean-fallback-stub-server.d.ts.map +0 -1
- package/dist/cli/brains.d.ts +0 -3
- package/dist/cli/brains.d.ts.map +0 -1
- package/dist/cli/commands/agent.d.ts +0 -3
- package/dist/cli/commands/agent.d.ts.map +0 -1
- package/dist/cli/commands/consolidation.d.ts +0 -3
- package/dist/cli/commands/consolidation.d.ts.map +0 -1
- package/dist/cli/commands/entity.d.ts +0 -3
- package/dist/cli/commands/entity.d.ts.map +0 -1
- package/dist/cli/commands/graph.d.ts +0 -3
- package/dist/cli/commands/graph.d.ts.map +0 -1
- package/dist/cli/commands/info-context.d.ts +0 -3
- package/dist/cli/commands/info-context.d.ts.map +0 -1
- package/dist/cli/commands/info-history.d.ts +0 -3
- package/dist/cli/commands/info-history.d.ts.map +0 -1
- package/dist/cli/commands/info-report.d.ts +0 -3
- package/dist/cli/commands/info-report.d.ts.map +0 -1
- package/dist/cli/commands/info-stale.d.ts +0 -3
- package/dist/cli/commands/info-stale.d.ts.map +0 -1
- package/dist/cli/commands/info-stats.d.ts +0 -3
- package/dist/cli/commands/info-stats.d.ts.map +0 -1
- package/dist/cli/commands/info.d.ts +0 -12
- package/dist/cli/commands/info.d.ts.map +0 -1
- package/dist/cli/commands/init.d.ts +0 -3
- package/dist/cli/commands/init.d.ts.map +0 -1
- package/dist/cli/commands/io-backup.d.ts +0 -3
- package/dist/cli/commands/io-backup.d.ts.map +0 -1
- package/dist/cli/commands/io-clean.d.ts +0 -3
- package/dist/cli/commands/io-clean.d.ts.map +0 -1
- package/dist/cli/commands/io-export.d.ts +0 -3
- package/dist/cli/commands/io-export.d.ts.map +0 -1
- package/dist/cli/commands/io-import.d.ts +0 -3
- package/dist/cli/commands/io-import.d.ts.map +0 -1
- package/dist/cli/commands/io-restore.d.ts +0 -3
- package/dist/cli/commands/io-restore.d.ts.map +0 -1
- package/dist/cli/commands/io.d.ts +0 -12
- package/dist/cli/commands/io.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-bulk.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-bulk.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-chain.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-chain.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-crud.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-crud.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-diff.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-diff.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-list.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-list.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-recall-exit.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-recall-exit.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-recall.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-recall.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-remove.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-remove.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-search.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-search.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-tail.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-tail.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-util.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-util.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-view.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-view.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-watch.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-watch.d.ts.map +0 -1
- package/dist/cli/commands/memory-cmd-when-to-use.d.ts +0 -3
- package/dist/cli/commands/memory-cmd-when-to-use.d.ts.map +0 -1
- package/dist/cli/commands/memory.d.ts +0 -3
- package/dist/cli/commands/memory.d.ts.map +0 -1
- package/dist/cli/commands/project-panel.d.ts +0 -3
- package/dist/cli/commands/project-panel.d.ts.map +0 -1
- package/dist/cli/commands/project.d.ts +0 -3
- package/dist/cli/commands/project.d.ts.map +0 -1
- package/dist/cli/commands/relation.d.ts +0 -3
- package/dist/cli/commands/relation.d.ts.map +0 -1
- package/dist/cli/commands/storage.d.ts +0 -3
- package/dist/cli/commands/storage.d.ts.map +0 -1
- package/dist/cli/commands/system-auto-memory.d.ts +0 -3
- package/dist/cli/commands/system-auto-memory.d.ts.map +0 -1
- package/dist/cli/commands/system-completions.d.ts +0 -13
- package/dist/cli/commands/system-completions.d.ts.map +0 -1
- package/dist/cli/commands/system-config.d.ts +0 -3
- package/dist/cli/commands/system-config.d.ts.map +0 -1
- package/dist/cli/commands/system-doctor.d.ts +0 -3
- package/dist/cli/commands/system-doctor.d.ts.map +0 -1
- package/dist/cli/commands/system-hooks.d.ts +0 -3
- package/dist/cli/commands/system-hooks.d.ts.map +0 -1
- package/dist/cli/commands/system-mcp.d.ts +0 -3
- package/dist/cli/commands/system-mcp.d.ts.map +0 -1
- package/dist/cli/commands/system-misc.d.ts +0 -3
- package/dist/cli/commands/system-misc.d.ts.map +0 -1
- package/dist/cli/commands/system-profile.d.ts +0 -3
- package/dist/cli/commands/system-profile.d.ts.map +0 -1
- package/dist/cli/commands/system-session.d.ts +0 -3
- package/dist/cli/commands/system-session.d.ts.map +0 -1
- package/dist/cli/commands/system-sessions.d.ts +0 -3
- package/dist/cli/commands/system-sessions.d.ts.map +0 -1
- package/dist/cli/commands/system-synthesis.d.ts +0 -3
- package/dist/cli/commands/system-synthesis.d.ts.map +0 -1
- package/dist/cli/commands/system-synthesized-profile.d.ts +0 -3
- package/dist/cli/commands/system-synthesized-profile.d.ts.map +0 -1
- package/dist/cli/commands/system-tools.d.ts +0 -3
- package/dist/cli/commands/system-tools.d.ts.map +0 -1
- package/dist/cli/commands/system-watch.d.ts +0 -3
- package/dist/cli/commands/system-watch.d.ts.map +0 -1
- package/dist/cli/commands/system.d.ts +0 -3
- package/dist/cli/commands/system.d.ts.map +0 -1
- package/dist/cli/exit-codes.d.ts +0 -13
- package/dist/cli/exit-codes.d.ts.map +0 -1
- package/dist/cli/global-options.d.ts +0 -27
- package/dist/cli/global-options.d.ts.map +0 -1
- package/dist/cli/helpers.d.ts +0 -119
- package/dist/cli/helpers.d.ts.map +0 -1
- package/dist/cli/index.d.ts +0 -3
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/register-all.d.ts +0 -17
- package/dist/cli/register-all.d.ts.map +0 -1
- package/dist/cli/startup-side-effects.d.ts +0 -9
- package/dist/cli/startup-side-effects.d.ts.map +0 -1
- package/dist/db/__fixtures__/fail-closed-stub-server.d.ts +0 -2
- package/dist/db/__fixtures__/fail-closed-stub-server.d.ts.map +0 -1
- package/dist/db/acl.d.ts +0 -34
- package/dist/db/acl.d.ts.map +0 -1
- package/dist/db/agents.d.ts +0 -21
- package/dist/db/agents.d.ts.map +0 -1
- package/dist/db/analytics.d.ts +0 -107
- package/dist/db/analytics.d.ts.map +0 -1
- package/dist/db/api-mode.d.ts +0 -127
- package/dist/db/api-mode.d.ts.map +0 -1
- package/dist/db/audit.d.ts +0 -53
- package/dist/db/audit.d.ts.map +0 -1
- package/dist/db/database.d.ts +0 -26
- package/dist/db/database.d.ts.map +0 -1
- package/dist/db/entities.d.ts +0 -62
- package/dist/db/entities.d.ts.map +0 -1
- package/dist/db/entity-memories.d.ts +0 -34
- package/dist/db/entity-memories.d.ts.map +0 -1
- package/dist/db/feedback.d.ts +0 -9
- package/dist/db/feedback.d.ts.map +0 -1
- package/dist/db/locks.d.ts +0 -63
- package/dist/db/locks.d.ts.map +0 -1
- package/dist/db/machines.d.ts +0 -23
- package/dist/db/machines.d.ts.map +0 -1
- package/dist/db/memories.d.ts +0 -137
- package/dist/db/memories.d.ts.map +0 -1
- package/dist/db/memory-links.d.ts +0 -21
- package/dist/db/memory-links.d.ts.map +0 -1
- package/dist/db/memory-project-link.d.ts +0 -13
- package/dist/db/memory-project-link.d.ts.map +0 -1
- package/dist/db/migrations.d.ts +0 -3
- package/dist/db/migrations.d.ts.map +0 -1
- package/dist/db/pg-migrate.d.ts +0 -27
- package/dist/db/pg-migrate.d.ts.map +0 -1
- package/dist/db/pg-migrations.d.ts +0 -2
- package/dist/db/pg-migrations.d.ts.map +0 -1
- package/dist/db/projects.d.ts +0 -27
- package/dist/db/projects.d.ts.map +0 -1
- package/dist/db/ratings.d.ts +0 -23
- package/dist/db/ratings.d.ts.map +0 -1
- package/dist/db/relations.d.ts +0 -49
- package/dist/db/relations.d.ts.map +0 -1
- package/dist/db/session-jobs.d.ts +0 -49
- package/dist/db/session-jobs.d.ts.map +0 -1
- package/dist/db/store-backend.d.ts +0 -42
- package/dist/db/store-backend.d.ts.map +0 -1
- package/dist/db/subscriptions.d.ts +0 -24
- package/dist/db/subscriptions.d.ts.map +0 -1
- package/dist/db/synthesis.d.ts +0 -101
- package/dist/db/synthesis.d.ts.map +0 -1
- package/dist/db/tasks.d.ts +0 -89
- package/dist/db/tasks.d.ts.map +0 -1
- package/dist/db/tool-events.d.ts +0 -27
- package/dist/db/tool-events.d.ts.map +0 -1
- package/dist/db/webhook_hooks.d.ts +0 -25
- package/dist/db/webhook_hooks.d.ts.map +0 -1
- package/dist/generated/storage-kit/backend.d.ts +0 -20
- package/dist/generated/storage-kit/backend.d.ts.map +0 -1
- package/dist/generated/storage-kit/health.d.ts +0 -20
- package/dist/generated/storage-kit/health.d.ts.map +0 -1
- package/dist/generated/storage-kit/index.d.ts +0 -8
- package/dist/generated/storage-kit/index.d.ts.map +0 -1
- package/dist/generated/storage-kit/migrations.d.ts +0 -48
- package/dist/generated/storage-kit/migrations.d.ts.map +0 -1
- package/dist/generated/storage-kit/own.d.ts +0 -11
- package/dist/generated/storage-kit/own.d.ts.map +0 -1
- package/dist/generated/storage-kit/pool.d.ts +0 -35
- package/dist/generated/storage-kit/pool.d.ts.map +0 -1
- package/dist/generated/storage-kit/query.d.ts +0 -36
- package/dist/generated/storage-kit/query.d.ts.map +0 -1
- package/dist/generated/storage-kit/tls.d.ts +0 -53
- package/dist/generated/storage-kit/tls.d.ts.map +0 -1
- package/dist/index.d.ts +0 -45
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/activation-matcher.d.ts +0 -17
- package/dist/lib/activation-matcher.d.ts.map +0 -1
- package/dist/lib/asmr/categorizer.d.ts +0 -31
- package/dist/lib/asmr/categorizer.d.ts.map +0 -1
- package/dist/lib/asmr/context-agent.d.ts +0 -4
- package/dist/lib/asmr/context-agent.d.ts.map +0 -1
- package/dist/lib/asmr/ensemble.d.ts +0 -23
- package/dist/lib/asmr/ensemble.d.ts.map +0 -1
- package/dist/lib/asmr/fact-agent.d.ts +0 -4
- package/dist/lib/asmr/fact-agent.d.ts.map +0 -1
- package/dist/lib/asmr/index.d.ts +0 -7
- package/dist/lib/asmr/index.d.ts.map +0 -1
- package/dist/lib/asmr/orchestrator.d.ts +0 -4
- package/dist/lib/asmr/orchestrator.d.ts.map +0 -1
- package/dist/lib/asmr/recall.d.ts +0 -3
- package/dist/lib/asmr/recall.d.ts.map +0 -1
- package/dist/lib/asmr/temporal-agent.d.ts +0 -4
- package/dist/lib/asmr/temporal-agent.d.ts.map +0 -1
- package/dist/lib/asmr/types.d.ts +0 -27
- package/dist/lib/asmr/types.d.ts.map +0 -1
- package/dist/lib/auto-inject-orchestrator.d.ts +0 -57
- package/dist/lib/auto-inject-orchestrator.d.ts.map +0 -1
- package/dist/lib/auto-memory-queue.d.ts +0 -48
- package/dist/lib/auto-memory-queue.d.ts.map +0 -1
- package/dist/lib/auto-memory.d.ts +0 -19
- package/dist/lib/auto-memory.d.ts.map +0 -1
- package/dist/lib/bench.d.ts +0 -20
- package/dist/lib/bench.d.ts.map +0 -1
- package/dist/lib/built-in-hooks.d.ts +0 -12
- package/dist/lib/built-in-hooks.d.ts.map +0 -1
- package/dist/lib/channel-pusher.d.ts +0 -39
- package/dist/lib/channel-pusher.d.ts.map +0 -1
- package/dist/lib/config.d.ts +0 -9
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/connectors/files.d.ts +0 -8
- package/dist/lib/connectors/files.d.ts.map +0 -1
- package/dist/lib/connectors/github.d.ts +0 -7
- package/dist/lib/connectors/github.d.ts.map +0 -1
- package/dist/lib/connectors/index.d.ts +0 -12
- package/dist/lib/connectors/index.d.ts.map +0 -1
- package/dist/lib/connectors/notion.d.ts +0 -7
- package/dist/lib/connectors/notion.d.ts.map +0 -1
- package/dist/lib/connectors/types.d.ts +0 -27
- package/dist/lib/connectors/types.d.ts.map +0 -1
- package/dist/lib/consolidation.d.ts +0 -52
- package/dist/lib/consolidation.d.ts.map +0 -1
- package/dist/lib/context-extractor.d.ts +0 -14
- package/dist/lib/context-extractor.d.ts.map +0 -1
- package/dist/lib/context.d.ts +0 -36
- package/dist/lib/context.d.ts.map +0 -1
- package/dist/lib/contradiction.d.ts +0 -50
- package/dist/lib/contradiction.d.ts.map +0 -1
- package/dist/lib/decay.d.ts +0 -35
- package/dist/lib/decay.d.ts.map +0 -1
- package/dist/lib/dedup.d.ts +0 -33
- package/dist/lib/dedup.d.ts.map +0 -1
- package/dist/lib/duration.d.ts +0 -28
- package/dist/lib/duration.d.ts.map +0 -1
- package/dist/lib/embeddings.d.ts +0 -20
- package/dist/lib/embeddings.d.ts.map +0 -1
- package/dist/lib/enum-validation.d.ts +0 -20
- package/dist/lib/enum-validation.d.ts.map +0 -1
- package/dist/lib/export-v1.d.ts +0 -30
- package/dist/lib/export-v1.d.ts.map +0 -1
- package/dist/lib/extractor.d.ts +0 -9
- package/dist/lib/extractor.d.ts.map +0 -1
- package/dist/lib/extractors/audio.d.ts +0 -8
- package/dist/lib/extractors/audio.d.ts.map +0 -1
- package/dist/lib/extractors/index.d.ts +0 -12
- package/dist/lib/extractors/index.d.ts.map +0 -1
- package/dist/lib/extractors/ocr.d.ts +0 -7
- package/dist/lib/extractors/ocr.d.ts.map +0 -1
- package/dist/lib/extractors/pdf.d.ts +0 -7
- package/dist/lib/extractors/pdf.d.ts.map +0 -1
- package/dist/lib/extractors/types.d.ts +0 -12
- package/dist/lib/extractors/types.d.ts.map +0 -1
- package/dist/lib/file-deps.d.ts +0 -27
- package/dist/lib/file-deps.d.ts.map +0 -1
- package/dist/lib/focus.d.ts +0 -58
- package/dist/lib/focus.d.ts.map +0 -1
- package/dist/lib/gatherer.d.ts +0 -16
- package/dist/lib/gatherer.d.ts.map +0 -1
- package/dist/lib/gdpr.d.ts +0 -39
- package/dist/lib/gdpr.d.ts.map +0 -1
- package/dist/lib/hooks.d.ts +0 -50
- package/dist/lib/hooks.d.ts.map +0 -1
- package/dist/lib/importers/index.d.ts +0 -38
- package/dist/lib/importers/index.d.ts.map +0 -1
- package/dist/lib/injector.d.ts +0 -89
- package/dist/lib/injector.d.ts.map +0 -1
- package/dist/lib/machine-visibility.d.ts +0 -6
- package/dist/lib/machine-visibility.d.ts.map +0 -1
- package/dist/lib/matryoshka.d.ts +0 -50
- package/dist/lib/matryoshka.d.ts.map +0 -1
- package/dist/lib/memory-lock.d.ts +0 -58
- package/dist/lib/memory-lock.d.ts.map +0 -1
- package/dist/lib/model-config.d.ts +0 -14
- package/dist/lib/model-config.d.ts.map +0 -1
- package/dist/lib/open-sessions-connector.d.ts +0 -60
- package/dist/lib/open-sessions-connector.d.ts.map +0 -1
- package/dist/lib/package-version.d.ts +0 -3
- package/dist/lib/package-version.d.ts.map +0 -1
- package/dist/lib/poisoning.d.ts +0 -19
- package/dist/lib/poisoning.d.ts.map +0 -1
- package/dist/lib/poll.d.ts +0 -17
- package/dist/lib/poll.d.ts.map +0 -1
- package/dist/lib/procedural-extractor.d.ts +0 -21
- package/dist/lib/procedural-extractor.d.ts.map +0 -1
- package/dist/lib/profile-sync.d.ts +0 -20
- package/dist/lib/profile-sync.d.ts.map +0 -1
- package/dist/lib/profile-synthesizer.d.ts +0 -20
- package/dist/lib/profile-synthesizer.d.ts.map +0 -1
- package/dist/lib/project-detect.d.ts +0 -18
- package/dist/lib/project-detect.d.ts.map +0 -1
- package/dist/lib/project-panel.d.ts +0 -7
- package/dist/lib/project-panel.d.ts.map +0 -1
- package/dist/lib/providers/anthropic.d.ts +0 -21
- package/dist/lib/providers/anthropic.d.ts.map +0 -1
- package/dist/lib/providers/base.d.ts +0 -96
- package/dist/lib/providers/base.d.ts.map +0 -1
- package/dist/lib/providers/cerebras.d.ts +0 -20
- package/dist/lib/providers/cerebras.d.ts.map +0 -1
- package/dist/lib/providers/grok.d.ts +0 -19
- package/dist/lib/providers/grok.d.ts.map +0 -1
- package/dist/lib/providers/index.d.ts +0 -7
- package/dist/lib/providers/index.d.ts.map +0 -1
- package/dist/lib/providers/openai-compat.d.ts +0 -18
- package/dist/lib/providers/openai-compat.d.ts.map +0 -1
- package/dist/lib/providers/openai.d.ts +0 -20
- package/dist/lib/providers/openai.d.ts.map +0 -1
- package/dist/lib/providers/registry.d.ts +0 -38
- package/dist/lib/providers/registry.d.ts.map +0 -1
- package/dist/lib/quality.d.ts +0 -16
- package/dist/lib/quality.d.ts.map +0 -1
- package/dist/lib/redact.d.ts +0 -10
- package/dist/lib/redact.d.ts.map +0 -1
- package/dist/lib/reflection.d.ts +0 -83
- package/dist/lib/reflection.d.ts.map +0 -1
- package/dist/lib/retention.d.ts +0 -17
- package/dist/lib/retention.d.ts.map +0 -1
- package/dist/lib/retired-storage-mode.d.ts +0 -11
- package/dist/lib/retired-storage-mode.d.ts.map +0 -1
- package/dist/lib/search.d.ts +0 -52
- package/dist/lib/search.d.ts.map +0 -1
- package/dist/lib/session-auto-resolve.d.ts +0 -28
- package/dist/lib/session-auto-resolve.d.ts.map +0 -1
- package/dist/lib/session-processor.d.ts +0 -38
- package/dist/lib/session-processor.d.ts.map +0 -1
- package/dist/lib/session-queue.d.ts +0 -28
- package/dist/lib/session-queue.d.ts.map +0 -1
- package/dist/lib/session-registry.d.ts +0 -47
- package/dist/lib/session-registry.d.ts.map +0 -1
- package/dist/lib/session-start-briefing.d.ts +0 -10
- package/dist/lib/session-start-briefing.d.ts.map +0 -1
- package/dist/lib/session-watcher.d.ts +0 -30
- package/dist/lib/session-watcher.d.ts.map +0 -1
- package/dist/lib/storage-sync.d.ts +0 -45
- package/dist/lib/storage-sync.d.ts.map +0 -1
- package/dist/lib/sync.d.ts +0 -10
- package/dist/lib/sync.d.ts.map +0 -1
- package/dist/lib/synthesis/corpus-builder.d.ts +0 -30
- package/dist/lib/synthesis/corpus-builder.d.ts.map +0 -1
- package/dist/lib/synthesis/executor.d.ts +0 -14
- package/dist/lib/synthesis/executor.d.ts.map +0 -1
- package/dist/lib/synthesis/index.d.ts +0 -37
- package/dist/lib/synthesis/index.d.ts.map +0 -1
- package/dist/lib/synthesis/llm-analyzer.d.ts +0 -18
- package/dist/lib/synthesis/llm-analyzer.d.ts.map +0 -1
- package/dist/lib/synthesis/metrics.d.ts +0 -13
- package/dist/lib/synthesis/metrics.d.ts.map +0 -1
- package/dist/lib/synthesis/scheduler.d.ts +0 -18
- package/dist/lib/synthesis/scheduler.d.ts.map +0 -1
- package/dist/lib/synthesis/validator.d.ts +0 -19
- package/dist/lib/synthesis/validator.d.ts.map +0 -1
- package/dist/lib/task-runner.d.ts +0 -37
- package/dist/lib/task-runner.d.ts.map +0 -1
- package/dist/lib/tool-lesson-extractor.d.ts +0 -24
- package/dist/lib/tool-lesson-extractor.d.ts.map +0 -1
- package/dist/lib/tool-memory-synthesizer.d.ts +0 -28
- package/dist/lib/tool-memory-synthesizer.d.ts.map +0 -1
- package/dist/lib/topic-clusterer.d.ts +0 -21
- package/dist/lib/topic-clusterer.d.ts.map +0 -1
- package/dist/lib/when-to-use-generator.d.ts +0 -22
- package/dist/lib/when-to-use-generator.d.ts.map +0 -1
- package/dist/mcp/http.d.ts +0 -17
- package/dist/mcp/http.d.ts.map +0 -1
- package/dist/mcp/index.d.ts +0 -6
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/memory-broadcast.d.ts +0 -12
- package/dist/mcp/memory-broadcast.d.ts.map +0 -1
- package/dist/mcp/tools/agent-tools.d.ts +0 -3
- package/dist/mcp/tools/agent-tools.d.ts.map +0 -1
- package/dist/mcp/tools/auto-memory-tools.d.ts +0 -5
- package/dist/mcp/tools/auto-memory-tools.d.ts.map +0 -1
- package/dist/mcp/tools/bulk-tools.d.ts +0 -3
- package/dist/mcp/tools/bulk-tools.d.ts.map +0 -1
- package/dist/mcp/tools/consolidation-tools.d.ts +0 -3
- package/dist/mcp/tools/consolidation-tools.d.ts.map +0 -1
- package/dist/mcp/tools/focus-tools.d.ts +0 -3
- package/dist/mcp/tools/focus-tools.d.ts.map +0 -1
- package/dist/mcp/tools/graph-entity-tools.d.ts +0 -3
- package/dist/mcp/tools/graph-entity-tools.d.ts.map +0 -1
- package/dist/mcp/tools/graph-query-tools.d.ts +0 -3
- package/dist/mcp/tools/graph-query-tools.d.ts.map +0 -1
- package/dist/mcp/tools/graph-relation-tools.d.ts +0 -3
- package/dist/mcp/tools/graph-relation-tools.d.ts.map +0 -1
- package/dist/mcp/tools/graph-tools.d.ts +0 -3
- package/dist/mcp/tools/graph-tools.d.ts.map +0 -1
- package/dist/mcp/tools/graph-utils.d.ts +0 -5
- package/dist/mcp/tools/graph-utils.d.ts.map +0 -1
- package/dist/mcp/tools/hook-tools.d.ts +0 -3
- package/dist/mcp/tools/hook-tools.d.ts.map +0 -1
- package/dist/mcp/tools/lock-tools.d.ts +0 -3
- package/dist/mcp/tools/lock-tools.d.ts.map +0 -1
- package/dist/mcp/tools/memory-audit.d.ts +0 -3
- package/dist/mcp/tools/memory-audit.d.ts.map +0 -1
- package/dist/mcp/tools/memory-crud.d.ts +0 -3
- package/dist/mcp/tools/memory-crud.d.ts.map +0 -1
- package/dist/mcp/tools/memory-health.d.ts +0 -3
- package/dist/mcp/tools/memory-health.d.ts.map +0 -1
- package/dist/mcp/tools/memory-history.d.ts +0 -3
- package/dist/mcp/tools/memory-history.d.ts.map +0 -1
- package/dist/mcp/tools/memory-inject.d.ts +0 -3
- package/dist/mcp/tools/memory-inject.d.ts.map +0 -1
- package/dist/mcp/tools/memory-io.d.ts +0 -3
- package/dist/mcp/tools/memory-io.d.ts.map +0 -1
- package/dist/mcp/tools/memory-lifecycle.d.ts +0 -3
- package/dist/mcp/tools/memory-lifecycle.d.ts.map +0 -1
- package/dist/mcp/tools/memory-search.d.ts +0 -3
- package/dist/mcp/tools/memory-search.d.ts.map +0 -1
- package/dist/mcp/tools/memory-stats.d.ts +0 -3
- package/dist/mcp/tools/memory-stats.d.ts.map +0 -1
- package/dist/mcp/tools/memory-tools.d.ts +0 -17
- package/dist/mcp/tools/memory-tools.d.ts.map +0 -1
- package/dist/mcp/tools/memory-utils.d.ts +0 -27
- package/dist/mcp/tools/memory-utils.d.ts.map +0 -1
- package/dist/mcp/tools/memory-validation.d.ts +0 -3
- package/dist/mcp/tools/memory-validation.d.ts.map +0 -1
- package/dist/mcp/tools/project-tools.d.ts +0 -3
- package/dist/mcp/tools/project-tools.d.ts.map +0 -1
- package/dist/mcp/tools/session-tools.d.ts +0 -3
- package/dist/mcp/tools/session-tools.d.ts.map +0 -1
- package/dist/mcp/tools/storage-tools.d.ts +0 -3
- package/dist/mcp/tools/storage-tools.d.ts.map +0 -1
- package/dist/mcp/tools/synthesis-tools.d.ts +0 -3
- package/dist/mcp/tools/synthesis-tools.d.ts.map +0 -1
- package/dist/mcp/tools/system-tools-events.d.ts +0 -3
- package/dist/mcp/tools/system-tools-events.d.ts.map +0 -1
- package/dist/mcp/tools/system-tools-memory-admin.d.ts +0 -3
- package/dist/mcp/tools/system-tools-memory-admin.d.ts.map +0 -1
- package/dist/mcp/tools/system-tools-shared.d.ts +0 -23
- package/dist/mcp/tools/system-tools-shared.d.ts.map +0 -1
- package/dist/mcp/tools/system-tools.d.ts +0 -3
- package/dist/mcp/tools/system-tools.d.ts.map +0 -1
- package/dist/mcp/tools/tool-registry.d.ts +0 -30
- package/dist/mcp/tools/tool-registry.d.ts.map +0 -1
- package/dist/mcp/tools/utility-tools.d.ts +0 -3
- package/dist/mcp/tools/utility-tools.d.ts.map +0 -1
- package/dist/memory-project-link/index.d.ts +0 -2
- package/dist/memory-project-link/index.d.ts.map +0 -1
- package/dist/memory-project-link/schema.d.ts +0 -5
- package/dist/memory-project-link/schema.d.ts.map +0 -1
- package/dist/pg-sync-worker.d.ts +0 -2
- package/dist/pg-sync-worker.d.ts.map +0 -1
- package/dist/project-registration/authority.d.ts +0 -43
- package/dist/project-registration/authority.d.ts.map +0 -1
- package/dist/project-registration/http.d.ts +0 -32
- package/dist/project-registration/http.d.ts.map +0 -1
- package/dist/project-registration/identity.d.ts +0 -20
- package/dist/project-registration/identity.d.ts.map +0 -1
- package/dist/project-registration/index.d.ts +0 -11
- package/dist/project-registration/index.d.ts.map +0 -1
- package/dist/project-registration/project-references.d.ts +0 -71
- package/dist/project-registration/project-references.d.ts.map +0 -1
- package/dist/project-registration/project-resources.d.ts +0 -22
- package/dist/project-registration/project-resources.d.ts.map +0 -1
- package/dist/project-registration/schema.d.ts +0 -5
- package/dist/project-registration/schema.d.ts.map +0 -1
- package/dist/project-registration/types.d.ts +0 -293
- package/dist/project-registration/types.d.ts.map +0 -1
- package/dist/project-registration.d.ts +0 -2
- package/dist/project-registration.d.ts.map +0 -1
- package/dist/sdk/index.d.ts +0 -971
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/server/auth.d.ts +0 -11
- package/dist/server/auth.d.ts.map +0 -1
- package/dist/server/helpers.d.ts +0 -22
- package/dist/server/helpers.d.ts.map +0 -1
- package/dist/server/index.d.ts +0 -14
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/openapi.d.ts +0 -2
- package/dist/server/openapi.d.ts.map +0 -1
- package/dist/server/router.d.ts +0 -17
- package/dist/server/router.d.ts.map +0 -1
- package/dist/server/routes/agents.d.ts +0 -2
- package/dist/server/routes/agents.d.ts.map +0 -1
- package/dist/server/routes/entities.d.ts +0 -2
- package/dist/server/routes/entities.d.ts.map +0 -1
- package/dist/server/routes/memories-bulk.d.ts +0 -2
- package/dist/server/routes/memories-bulk.d.ts.map +0 -1
- package/dist/server/routes/memories-crud.d.ts +0 -2
- package/dist/server/routes/memories-crud.d.ts.map +0 -1
- package/dist/server/routes/memories-io.d.ts +0 -2
- package/dist/server/routes/memories-io.d.ts.map +0 -1
- package/dist/server/routes/memories-misc.d.ts +0 -2
- package/dist/server/routes/memories-misc.d.ts.map +0 -1
- package/dist/server/routes/memories-search.d.ts +0 -2
- package/dist/server/routes/memories-search.d.ts.map +0 -1
- package/dist/server/routes/memories-stats.d.ts +0 -2
- package/dist/server/routes/memories-stats.d.ts.map +0 -1
- package/dist/server/routes/memories.d.ts +0 -19
- package/dist/server/routes/memories.d.ts.map +0 -1
- package/dist/server/routes/memory-project-link.d.ts +0 -2
- package/dist/server/routes/memory-project-link.d.ts.map +0 -1
- package/dist/server/routes/project-registration.d.ts +0 -2
- package/dist/server/routes/project-registration.d.ts.map +0 -1
- package/dist/server/routes/projects.d.ts +0 -2
- package/dist/server/routes/projects.d.ts.map +0 -1
- package/dist/server/routes/system-auto-memory.d.ts +0 -2
- package/dist/server/routes/system-auto-memory.d.ts.map +0 -1
- package/dist/server/routes/system-chain.d.ts +0 -2
- package/dist/server/routes/system-chain.d.ts.map +0 -1
- package/dist/server/routes/system-consolidation.d.ts +0 -2
- package/dist/server/routes/system-consolidation.d.ts.map +0 -1
- package/dist/server/routes/system-hooks.d.ts +0 -2
- package/dist/server/routes/system-hooks.d.ts.map +0 -1
- package/dist/server/routes/system-sessions.d.ts +0 -2
- package/dist/server/routes/system-sessions.d.ts.map +0 -1
- package/dist/server/routes/system-subscriptions.d.ts +0 -2
- package/dist/server/routes/system-subscriptions.d.ts.map +0 -1
- package/dist/server/routes/system-synthesis.d.ts +0 -2
- package/dist/server/routes/system-synthesis.d.ts.map +0 -1
- package/dist/server/routes/system-tools.d.ts +0 -2
- package/dist/server/routes/system-tools.d.ts.map +0 -1
- package/dist/server/routes/system.d.ts +0 -2
- package/dist/server/routes/system.d.ts.map +0 -1
- package/dist/server/routes/tasks.d.ts +0 -2
- package/dist/server/routes/tasks.d.ts.map +0 -1
- package/dist/storage.d.ts +0 -266
- package/dist/storage.d.ts.map +0 -1
- package/dist/test-support/preload-local-store.d.ts +0 -2
- package/dist/test-support/preload-local-store.d.ts.map +0 -1
- package/dist/test-support/project-authority-identity.d.ts +0 -8
- package/dist/test-support/project-authority-identity.d.ts.map +0 -1
- package/dist/test-support/store-isolation.d.ts +0 -108
- package/dist/test-support/store-isolation.d.ts.map +0 -1
- package/dist/test-support/strip-ansi.d.ts +0 -3
- package/dist/test-support/strip-ansi.d.ts.map +0 -1
- package/dist/types/hooks.d.ts +0 -136
- package/dist/types/hooks.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -472
- package/dist/types/index.d.ts.map +0 -1
package/dist/pg-sync-worker.js
CHANGED
|
@@ -20,7 +20,7 @@ async function ensureConnected() {
|
|
|
20
20
|
}
|
|
21
21
|
await connecting;
|
|
22
22
|
}
|
|
23
|
-
function respond(statusCode, payload) {
|
|
23
|
+
function respond(gen, statusCode, payload) {
|
|
24
24
|
const bytes = encoder.encode(JSON.stringify(payload));
|
|
25
25
|
if (bytes.length > dataView.length) {
|
|
26
26
|
const errBytes = encoder.encode(JSON.stringify({
|
|
@@ -28,21 +28,23 @@ function respond(statusCode, payload) {
|
|
|
28
28
|
}));
|
|
29
29
|
dataView.set(errBytes, 0);
|
|
30
30
|
Atomics.store(status, 1, errBytes.length);
|
|
31
|
-
Atomics.store(status,
|
|
31
|
+
Atomics.store(status, 2, 2);
|
|
32
|
+
Atomics.store(status, 0, gen);
|
|
32
33
|
Atomics.notify(status, 0);
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
36
|
dataView.set(bytes, 0);
|
|
36
37
|
Atomics.store(status, 1, bytes.length);
|
|
37
|
-
Atomics.store(status,
|
|
38
|
+
Atomics.store(status, 2, statusCode);
|
|
39
|
+
Atomics.store(status, 0, gen);
|
|
38
40
|
Atomics.notify(status, 0);
|
|
39
41
|
}
|
|
40
42
|
parentPort?.on("message", async (msg) => {
|
|
41
43
|
try {
|
|
42
44
|
await ensureConnected();
|
|
43
45
|
const result = await client.query(msg.sql, msg.params);
|
|
44
|
-
respond(1, { rows: result.rows, rowCount: result.rowCount });
|
|
46
|
+
respond(msg.gen, 1, { rows: result.rows, rowCount: result.rowCount });
|
|
45
47
|
} catch (error) {
|
|
46
|
-
respond(2, { message: error instanceof Error ? error.message : String(error) });
|
|
48
|
+
respond(msg.gen, 2, { message: error instanceof Error ? error.message : String(error) });
|
|
47
49
|
}
|
|
48
50
|
});
|
|
@@ -235,6 +235,7 @@ function translateSql(sql) {
|
|
|
235
235
|
let translated = sql.replace(/\?/g, () => `$${++parameterIndex}`);
|
|
236
236
|
const ISO_FMT = `'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'`;
|
|
237
237
|
translated = translated.replace(/datetime\s*\(\s*'now'\s*\)/gi, `to_char(now() AT TIME ZONE 'UTC', ${ISO_FMT})`);
|
|
238
|
+
translated = translated.replace(/strftime\s*\(\s*'%Y-%m-%dT%H:%M:%fZ'\s*,\s*'now'\s*\)/gi, `to_char(now() AT TIME ZONE 'UTC', ${ISO_FMT})`);
|
|
238
239
|
translated = translated.replace(/datetime\s*\(\s*'now'\s*,\s*'(-?\d+)\s+(minutes?|hours?|days?|seconds?)'\s*\)/gi, (_match, amount, unit) => {
|
|
239
240
|
const parsed = parseInt(String(amount), 10);
|
|
240
241
|
const absolute = Math.abs(parsed);
|
|
@@ -736,16 +737,24 @@ function transferRows(target, table, rows, options) {
|
|
|
736
737
|
const conflictColumn = options.conflictColumn ?? "updated_at";
|
|
737
738
|
let written = 0;
|
|
738
739
|
let skipped = 0;
|
|
740
|
+
let maxSyncedAt = null;
|
|
739
741
|
const errors = [];
|
|
742
|
+
const bumpMaxSyncedAt = (row) => {
|
|
743
|
+
const value = row[conflictColumn];
|
|
744
|
+
if (typeof value === "string" && (maxSyncedAt === null || value > maxSyncedAt)) {
|
|
745
|
+
maxSyncedAt = value;
|
|
746
|
+
}
|
|
747
|
+
};
|
|
740
748
|
if (rows.length === 0) {
|
|
741
|
-
return { written, skipped, errors };
|
|
749
|
+
return { written, skipped, errors, maxSyncedAt };
|
|
742
750
|
}
|
|
743
751
|
const columns = Object.keys(rows[0] ?? {});
|
|
744
752
|
if (!columns.includes(primaryKey)) {
|
|
745
753
|
return {
|
|
746
754
|
written,
|
|
747
755
|
skipped,
|
|
748
|
-
errors: [`Table "${table}" has no "${primaryKey}" column; skipping`]
|
|
756
|
+
errors: [`Table "${table}" has no "${primaryKey}" column; skipping`],
|
|
757
|
+
maxSyncedAt
|
|
749
758
|
};
|
|
750
759
|
}
|
|
751
760
|
const hasConflictColumn = columns.includes(conflictColumn);
|
|
@@ -758,6 +767,7 @@ function transferRows(target, table, rows, options) {
|
|
|
758
767
|
const incomingTime = Date.parse(String(row[conflictColumn]));
|
|
759
768
|
if (Number.isFinite(existingTime) && Number.isFinite(incomingTime) && existingTime >= incomingTime) {
|
|
760
769
|
skipped++;
|
|
770
|
+
bumpMaxSyncedAt(row);
|
|
761
771
|
continue;
|
|
762
772
|
}
|
|
763
773
|
}
|
|
@@ -770,11 +780,12 @@ function transferRows(target, table, rows, options) {
|
|
|
770
780
|
target.run(`INSERT INTO "${table}" (${columnList}) VALUES (${placeholders})`, ...columns.map((column) => row[column]));
|
|
771
781
|
}
|
|
772
782
|
written++;
|
|
783
|
+
bumpMaxSyncedAt(row);
|
|
773
784
|
} catch (error) {
|
|
774
785
|
errors.push(`Row ${String(row[primaryKey] ?? "unknown")}: ${error instanceof Error ? error.message : String(error)}`);
|
|
775
786
|
}
|
|
776
787
|
}
|
|
777
|
-
return { written, skipped, errors };
|
|
788
|
+
return { written, skipped, errors, maxSyncedAt };
|
|
778
789
|
}
|
|
779
790
|
function incrementalSyncPush(local, remote, tables, options = {}) {
|
|
780
791
|
return runIncrementalSync("push", local, remote, local, tables, options);
|
|
@@ -812,22 +823,29 @@ function runIncrementalSync(direction, source, target, metaDb, tables, options)
|
|
|
812
823
|
rows = source.all(`SELECT * FROM "${table}"`);
|
|
813
824
|
stat.first_sync = true;
|
|
814
825
|
}
|
|
826
|
+
let maxSyncedAt = null;
|
|
815
827
|
for (let offset = 0;offset < rows.length; offset += batchSize) {
|
|
816
828
|
const batch = rows.slice(offset, offset + batchSize);
|
|
817
829
|
const result = transferRows(target, table, batch, options);
|
|
818
830
|
stat.synced_rows += result.written;
|
|
819
831
|
stat.skipped_rows += result.skipped;
|
|
820
832
|
stat.errors.push(...result.errors);
|
|
833
|
+
if (result.maxSyncedAt !== null && (maxSyncedAt === null || result.maxSyncedAt > maxSyncedAt)) {
|
|
834
|
+
maxSyncedAt = result.maxSyncedAt;
|
|
835
|
+
}
|
|
821
836
|
}
|
|
822
837
|
if (rows.length === 0) {
|
|
823
838
|
stat.skipped_rows = stat.total_rows;
|
|
824
839
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
840
|
+
const nextCursor = maxSyncedAt ?? meta?.last_synced_at ?? null;
|
|
841
|
+
if (rows.length > 0 && stat.errors.length === 0 && nextCursor !== null) {
|
|
842
|
+
upsertSyncMeta(metaDb, {
|
|
843
|
+
table_name: table,
|
|
844
|
+
last_synced_at: nextCursor,
|
|
845
|
+
last_synced_row_count: stat.synced_rows,
|
|
846
|
+
direction
|
|
847
|
+
});
|
|
848
|
+
}
|
|
831
849
|
} catch (error) {
|
|
832
850
|
stat.errors.push(`Table "${table}": ${error instanceof Error ? error.message : String(error)}`);
|
|
833
851
|
}
|
|
@@ -866,8 +884,13 @@ var init_storage = __esm(() => {
|
|
|
866
884
|
data;
|
|
867
885
|
closed = false;
|
|
868
886
|
lastError = null;
|
|
887
|
+
generation = 0;
|
|
869
888
|
static DATA_BYTES = 128 * 1024 * 1024;
|
|
870
|
-
static
|
|
889
|
+
static queryTimeoutMs() {
|
|
890
|
+
const raw = process.env["MEMENTOS_PGSYNC_QUERY_TIMEOUT_MS"]?.trim();
|
|
891
|
+
const parsed = raw ? Number(raw) : Number.NaN;
|
|
892
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 60000;
|
|
893
|
+
}
|
|
871
894
|
static resolveWorkerPath() {
|
|
872
895
|
const ext = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
|
|
873
896
|
const here = fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -882,12 +905,12 @@ var init_storage = __esm(() => {
|
|
|
882
905
|
}
|
|
883
906
|
return candidates[0];
|
|
884
907
|
}
|
|
885
|
-
constructor(connectionString) {
|
|
886
|
-
const control = new SharedArrayBuffer(
|
|
908
|
+
constructor(connectionString, workerPath) {
|
|
909
|
+
const control = new SharedArrayBuffer(12);
|
|
887
910
|
const dataSab = new SharedArrayBuffer(PgSyncPool.DATA_BYTES);
|
|
888
911
|
this.status = new Int32Array(control);
|
|
889
912
|
this.data = new Uint8Array(dataSab);
|
|
890
|
-
this.worker = new Worker(PgSyncPool.resolveWorkerPath(), {
|
|
913
|
+
this.worker = new Worker(workerPath ?? PgSyncPool.resolveWorkerPath(), {
|
|
891
914
|
workerData: {
|
|
892
915
|
dsn: stripSslParams(connectionString),
|
|
893
916
|
ssl: sslConfigFor(connectionString),
|
|
@@ -905,21 +928,35 @@ var init_storage = __esm(() => {
|
|
|
905
928
|
throw new Error("PgSyncPool is closed");
|
|
906
929
|
if (this.lastError)
|
|
907
930
|
throw this.lastError;
|
|
931
|
+
const timeoutMs = PgSyncPool.queryTimeoutMs();
|
|
932
|
+
const gen = ++this.generation;
|
|
908
933
|
Atomics.store(this.status, 0, 0);
|
|
909
|
-
this.
|
|
910
|
-
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
934
|
+
Atomics.store(this.status, 2, 0);
|
|
935
|
+
this.worker.postMessage({ sql, params, gen });
|
|
936
|
+
const deadline = Date.now() + timeoutMs;
|
|
937
|
+
for (;; ) {
|
|
938
|
+
const remaining = deadline - Date.now();
|
|
939
|
+
const responding = Atomics.load(this.status, 0);
|
|
940
|
+
if (responding === gen) {
|
|
941
|
+
const code = Atomics.load(this.status, 2);
|
|
942
|
+
const len = Atomics.load(this.status, 1);
|
|
943
|
+
const payload = JSON.parse(new TextDecoder().decode(this.data.subarray(0, len)));
|
|
944
|
+
if (code === 2) {
|
|
945
|
+
throw new Error(payload.message ?? "PostgreSQL error");
|
|
946
|
+
}
|
|
947
|
+
return payload;
|
|
948
|
+
}
|
|
949
|
+
if (responding !== 0) {
|
|
950
|
+
Atomics.compareExchange(this.status, 0, responding, 0);
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
if (remaining <= 0) {
|
|
954
|
+
if (this.lastError)
|
|
955
|
+
throw this.lastError;
|
|
956
|
+
throw new Error(`PostgreSQL query timed out after ${timeoutMs}ms`);
|
|
957
|
+
}
|
|
958
|
+
Atomics.wait(this.status, 0, 0, remaining);
|
|
921
959
|
}
|
|
922
|
-
return payload;
|
|
923
960
|
}
|
|
924
961
|
end() {
|
|
925
962
|
if (this.closed)
|
|
@@ -1147,7 +1184,16 @@ x-api-key: ${cfg.apiKey}
|
|
|
1147
1184
|
function apiJson(method, path, body, options) {
|
|
1148
1185
|
const raw = apiRequestRaw(method, path, body);
|
|
1149
1186
|
if (raw.status >= 200 && raw.status < 300) {
|
|
1150
|
-
|
|
1187
|
+
let data;
|
|
1188
|
+
if (raw.body.trim()) {
|
|
1189
|
+
try {
|
|
1190
|
+
data = JSON.parse(raw.body);
|
|
1191
|
+
} catch (e) {
|
|
1192
|
+
throw new ApiRequestError(`mementos cloud ${method} ${path} returned status ${raw.status} with a body that is not valid JSON (${e instanceof Error ? e.message : String(e)}) \u2014 the response is truncated or the server is unhealthy`, raw.status, raw.body.slice(0, 500));
|
|
1193
|
+
}
|
|
1194
|
+
} else {
|
|
1195
|
+
data = undefined;
|
|
1196
|
+
}
|
|
1151
1197
|
return { status: raw.status, data };
|
|
1152
1198
|
}
|
|
1153
1199
|
if (raw.status === 404 && options?.allow404) {
|
|
@@ -2886,6 +2932,90 @@ class MementosProjectRegistrationError extends Error {
|
|
|
2886
2932
|
}
|
|
2887
2933
|
}
|
|
2888
2934
|
|
|
2935
|
+
// src/project-registration/historical-receipt.ts
|
|
2936
|
+
var ROOT_TENANT_ID = "adfd95c7-ee8b-52cb-ae47-4ae65dae3313";
|
|
2937
|
+
var FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION = {
|
|
2938
|
+
authority: "mementos",
|
|
2939
|
+
authority_route: "mementos.project-registration.v1",
|
|
2940
|
+
package_version: "1.0.0-rc.3",
|
|
2941
|
+
authority_id: "mementos",
|
|
2942
|
+
tenant_id: "default",
|
|
2943
|
+
corpus_id: "default",
|
|
2944
|
+
operation_id: "op-cli-register-full",
|
|
2945
|
+
step_id: "mementos_project",
|
|
2946
|
+
resource_kind: "project",
|
|
2947
|
+
direction: "forward",
|
|
2948
|
+
target_selector: "wks_005285827590a93b70e5",
|
|
2949
|
+
target_id: "mm_project_f75606ef14e51fb577a15882ba0ab8ed333b2c29",
|
|
2950
|
+
idempotency_key: "prk_786cdc6babddeae1be8d5078d0f75322d1ea1010ac5d8a50",
|
|
2951
|
+
receipt_id: "mmpr_a647f9908a33bb64bf137f584202590f91b72a33",
|
|
2952
|
+
request_digest: "8eb0e3fee26fdb7edb8a444aeddaaedb79a84a5a36e742ae03616f62b19f5c22",
|
|
2953
|
+
precondition_digest: "0b6c22fcf75d835f9f27308b1a9d40e8902e48a97da370fd56df5acacfcd968e",
|
|
2954
|
+
result_revision: "2026-08-09T13:37:43.068Z",
|
|
2955
|
+
result_digest: "26fb0dd5c5e20909d3653ab0ddd8fa45e5142728e4e66d595e2419f7ed40b036",
|
|
2956
|
+
created_at: "2026-08-09T13:37:43.068Z",
|
|
2957
|
+
identity_digest: "1108dd972c90e4989036fb6ecec7dde10f54641a697bd53cfcd64017f589ace7",
|
|
2958
|
+
target_digest: "72789fcd60668eeb66ee068936d3afa96deadcb007228830c64b6de783b6dcef",
|
|
2959
|
+
operation_digest: "d7e37bfb2c0d28f8c4086c53224cd855d14694f32807b74c102b61a99963f3c0",
|
|
2960
|
+
idempotency_digest: "b56d8ec37efb818759cdd2ee3b58bc1401ac13384c8d64c1813bb5c198b1e376",
|
|
2961
|
+
receipt_digest: "52ce90c5de6817989f107d9d27e06156962a2b9c365e34e16a57aa37886501a2",
|
|
2962
|
+
response_digest: "2fa3ed508f5f192c18753b1205ced996340fdf02f735420d32db897fc239805c"
|
|
2963
|
+
};
|
|
2964
|
+
var FLEET_RESOURCES_HISTORICAL_RECEIPT = {
|
|
2965
|
+
receipt_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.receipt_id,
|
|
2966
|
+
authority: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority,
|
|
2967
|
+
route: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_route,
|
|
2968
|
+
package_version: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.package_version,
|
|
2969
|
+
authority_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_id,
|
|
2970
|
+
tenant_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.tenant_id,
|
|
2971
|
+
corpus_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.corpus_id,
|
|
2972
|
+
operation_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.operation_id,
|
|
2973
|
+
step_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.step_id,
|
|
2974
|
+
resource_kind: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.resource_kind,
|
|
2975
|
+
direction: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.direction,
|
|
2976
|
+
idempotency_key: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.idempotency_key,
|
|
2977
|
+
request_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.request_digest,
|
|
2978
|
+
precondition_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.precondition_digest,
|
|
2979
|
+
outcome: "accepted",
|
|
2980
|
+
reason: null,
|
|
2981
|
+
target_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_id,
|
|
2982
|
+
result_revision: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.result_revision,
|
|
2983
|
+
result_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.result_digest,
|
|
2984
|
+
duplicate_of_receipt_id: null,
|
|
2985
|
+
accepted_receipt_id: null,
|
|
2986
|
+
created_by_operation: true,
|
|
2987
|
+
created_at: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.created_at
|
|
2988
|
+
};
|
|
2989
|
+
var FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY = {
|
|
2990
|
+
authority_id: "mementos",
|
|
2991
|
+
tenant_id: ROOT_TENANT_ID,
|
|
2992
|
+
corpus_id: "mementos:postgresql"
|
|
2993
|
+
};
|
|
2994
|
+
var FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY = {
|
|
2995
|
+
source: {
|
|
2996
|
+
authority: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority,
|
|
2997
|
+
authority_route: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_route,
|
|
2998
|
+
package_version: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.package_version,
|
|
2999
|
+
authority_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_id,
|
|
3000
|
+
tenant_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.tenant_id,
|
|
3001
|
+
corpus_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.corpus_id,
|
|
3002
|
+
operation_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.operation_id,
|
|
3003
|
+
step_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.step_id,
|
|
3004
|
+
resource_kind: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.resource_kind,
|
|
3005
|
+
direction: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.direction,
|
|
3006
|
+
target_selector: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_selector,
|
|
3007
|
+
target_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_id,
|
|
3008
|
+
idempotency_key: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.idempotency_key,
|
|
3009
|
+
receipt_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.receipt_id
|
|
3010
|
+
},
|
|
3011
|
+
destination: FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY,
|
|
3012
|
+
lookup_only: true,
|
|
3013
|
+
immutable_receipt: true
|
|
3014
|
+
};
|
|
3015
|
+
function supportsFleetResourcesHistoricalReceiptLookup(capability) {
|
|
3016
|
+
return capability.authority_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.authority_id && capability.tenant_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.tenant_id && capability.corpus_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.corpus_id;
|
|
3017
|
+
}
|
|
3018
|
+
|
|
2889
3019
|
// src/project-registration/identity.ts
|
|
2890
3020
|
var MEMENTOS_PROJECT_AUTHORITY_ENV = {
|
|
2891
3021
|
authorityId: "MEMENTOS_PROJECT_AUTHORITY_ID",
|
|
@@ -2927,12 +3057,13 @@ function resolveMementosProjectAuthorityIdentity(options = {}) {
|
|
|
2927
3057
|
}
|
|
2928
3058
|
function buildMementosProjectRegistrationCapability(options = {}) {
|
|
2929
3059
|
const identity = resolveMementosProjectAuthorityIdentity(options);
|
|
2930
|
-
|
|
3060
|
+
const capability = {
|
|
2931
3061
|
authority: "mementos",
|
|
2932
3062
|
route: MEMENTOS_PROJECT_REGISTRATION_ROUTE,
|
|
2933
3063
|
package_version: options.packageVersion ?? getMementosPackageVersion(),
|
|
2934
3064
|
...identity,
|
|
2935
3065
|
supported_resources: ["project"],
|
|
3066
|
+
supported_historical_lookup_identities: [],
|
|
2936
3067
|
conditional_create: true,
|
|
2937
3068
|
immutable_receipts: true,
|
|
2938
3069
|
exact_terminal_lookup: true,
|
|
@@ -2951,6 +3082,12 @@ function buildMementosProjectRegistrationCapability(options = {}) {
|
|
|
2951
3082
|
stable_keyset_pagination: true,
|
|
2952
3083
|
explicit_membership_only: true
|
|
2953
3084
|
};
|
|
3085
|
+
if (supportsFleetResourcesHistoricalReceiptLookup(capability)) {
|
|
3086
|
+
capability.supported_historical_lookup_identities = [
|
|
3087
|
+
FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY
|
|
3088
|
+
];
|
|
3089
|
+
}
|
|
3090
|
+
return capability;
|
|
2954
3091
|
}
|
|
2955
3092
|
|
|
2956
3093
|
// src/db/projects.ts
|
|
@@ -4028,12 +4165,21 @@ function assertInverseRequest(request, capability) {
|
|
|
4028
4165
|
}
|
|
4029
4166
|
return accepted;
|
|
4030
4167
|
}
|
|
4168
|
+
function matchesCurrentLookupIdentity(request, capability) {
|
|
4169
|
+
return request.authority_route === capability.route && request.package_version === capability.package_version && request.authority_id === capability.authority_id && request.tenant_id === capability.tenant_id && request.corpus_id === capability.corpus_id;
|
|
4170
|
+
}
|
|
4171
|
+
function matchesFleetResourcesHistoricalLookup(request, capability) {
|
|
4172
|
+
if (!supportsFleetResourcesHistoricalReceiptLookup(capability))
|
|
4173
|
+
return false;
|
|
4174
|
+
const source = FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY.source;
|
|
4175
|
+
return request.authority === source.authority && request.authority_route === source.authority_route && request.package_version === source.package_version && request.authority_id === source.authority_id && request.tenant_id === source.tenant_id && request.corpus_id === source.corpus_id && request.operation_id === source.operation_id && request.step_id === source.step_id && request.resource_kind === source.resource_kind && request.direction === source.direction && request.target_selector === source.target_selector && request.target_id === source.target_id && request.idempotency_key === source.idempotency_key;
|
|
4176
|
+
}
|
|
4031
4177
|
function assertLookup(request, capability) {
|
|
4032
4178
|
assertBounds(request);
|
|
4033
4179
|
if (request.max_items !== 1) {
|
|
4034
4180
|
throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_INVALID_BOUNDS", "terminal receipt lookup requires max_items exactly 1");
|
|
4035
4181
|
}
|
|
4036
|
-
if (request.authority !== "mementos" || request.resource_kind !== "project" || request
|
|
4182
|
+
if (request.authority !== "mementos" || request.resource_kind !== "project" || !matchesCurrentLookupIdentity(request, capability) && !matchesFleetResourcesHistoricalLookup(request, capability)) {
|
|
4037
4183
|
throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_CAPABILITY_MISMATCH", "receipt lookup does not match this authority capability identity");
|
|
4038
4184
|
}
|
|
4039
4185
|
requireString(request.operation_id, "operation_id", { pattern: OPERATION_PATTERN });
|
|
@@ -4051,6 +4197,7 @@ function assertLookup(request, capability) {
|
|
|
4051
4197
|
pattern: PROJECT_ID_PATTERN
|
|
4052
4198
|
});
|
|
4053
4199
|
}
|
|
4200
|
+
return matchesCurrentLookupIdentity(request, capability) ? "current" : "fleet_resources_historical";
|
|
4054
4201
|
}
|
|
4055
4202
|
|
|
4056
4203
|
class PackageOwnedMementosProjectRegistrationAuthority {
|
|
@@ -4315,11 +4462,14 @@ class PackageOwnedMementosProjectRegistrationAuthority {
|
|
|
4315
4462
|
}
|
|
4316
4463
|
async lookupReceipt(request) {
|
|
4317
4464
|
const startedAt = Date.now();
|
|
4318
|
-
assertLookup(request, this.capabilityValue);
|
|
4465
|
+
const lookupIdentity = assertLookup(request, this.capabilityValue);
|
|
4319
4466
|
const receipt = getReceiptForLookup(this.db, request);
|
|
4320
4467
|
if (!receipt || request.target_id !== undefined && receipt.target_id !== request.target_id) {
|
|
4321
4468
|
throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_RECEIPT_NOT_FOUND", "exact immutable terminal receipt was not found");
|
|
4322
4469
|
}
|
|
4470
|
+
if (lookupIdentity === "fleet_resources_historical" && (receipt.receipt_id !== FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY.source.receipt_id || canonicalMementosProjectRegistrationJson(publicReceipt(receipt)) !== canonicalMementosProjectRegistrationJson(FLEET_RESOURCES_HISTORICAL_RECEIPT))) {
|
|
4471
|
+
throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_RECEIPT_NOT_FOUND", "exact immutable historical terminal receipt was not found");
|
|
4472
|
+
}
|
|
4323
4473
|
return withResponseControl(publicReceipt(receipt), request, startedAt);
|
|
4324
4474
|
}
|
|
4325
4475
|
async compensate(request) {
|
|
@@ -5242,7 +5392,26 @@ function parseMemoryRow(row) {
|
|
|
5242
5392
|
accessed_at: row["accessed_at"] || null
|
|
5243
5393
|
};
|
|
5244
5394
|
}
|
|
5395
|
+
var RESERVED_AGENT_IDS = new Set([
|
|
5396
|
+
"agent-a",
|
|
5397
|
+
"agent-x",
|
|
5398
|
+
"agent-z",
|
|
5399
|
+
"nonexistent-agent"
|
|
5400
|
+
]);
|
|
5401
|
+
function reservedAgentIdViolation(agentId) {
|
|
5402
|
+
if (!agentId)
|
|
5403
|
+
return null;
|
|
5404
|
+
const normalized = agentId.trim().toLowerCase();
|
|
5405
|
+
if (RESERVED_AGENT_IDS.has(normalized)) {
|
|
5406
|
+
return `Reserved placeholder agent id "${agentId}" cannot own a memory. ` + `Refusing to write: test harnesses must not write memories under placeholder agent ` + `identities. Register a real agent (mementos register-agent <name>) and pass its id.`;
|
|
5407
|
+
}
|
|
5408
|
+
return null;
|
|
5409
|
+
}
|
|
5245
5410
|
function createMemory(input, dedupeMode = "merge", db) {
|
|
5411
|
+
const reservedViolation = reservedAgentIdViolation(input.agent_id);
|
|
5412
|
+
if (reservedViolation) {
|
|
5413
|
+
throw new Error(reservedViolation);
|
|
5414
|
+
}
|
|
5246
5415
|
if (!db && isApiMode()) {
|
|
5247
5416
|
const { status, data } = apiJson("POST", "/memories", { ...input, dedupe: dedupeMode });
|
|
5248
5417
|
if (!data || !data.id) {
|
|
@@ -5292,7 +5461,8 @@ function createMemory(input, dedupeMode = "merge", db) {
|
|
|
5292
5461
|
importance = ?, metadata = ?, expires_at = ?,
|
|
5293
5462
|
when_to_use = ?,
|
|
5294
5463
|
pinned = COALESCE(pinned, 0),
|
|
5295
|
-
version = version + 1, updated_at =
|
|
5464
|
+
version = version + 1, updated_at = ?,
|
|
5465
|
+
updated_by_agent = ?
|
|
5296
5466
|
WHERE id = ?`, [
|
|
5297
5467
|
safeValue,
|
|
5298
5468
|
input.category || "knowledge",
|
|
@@ -5303,6 +5473,7 @@ function createMemory(input, dedupeMode = "merge", db) {
|
|
|
5303
5473
|
expiresAt,
|
|
5304
5474
|
input.when_to_use || null,
|
|
5305
5475
|
timestamp,
|
|
5476
|
+
input.agent_id || null,
|
|
5306
5477
|
existing.id
|
|
5307
5478
|
]);
|
|
5308
5479
|
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [existing.id]);
|
|
@@ -5476,29 +5647,7 @@ function getMemoriesByKey(key, scope, agentId, projectId, db) {
|
|
|
5476
5647
|
const rows = d.query(sql).all(...params);
|
|
5477
5648
|
return rows.map(parseMemoryRow);
|
|
5478
5649
|
}
|
|
5479
|
-
function
|
|
5480
|
-
if (!db && isApiMode()) {
|
|
5481
|
-
const f = filter || {};
|
|
5482
|
-
const q = toQuery({
|
|
5483
|
-
key: f.key,
|
|
5484
|
-
scope: f.scope,
|
|
5485
|
-
category: f.category,
|
|
5486
|
-
status: f.status,
|
|
5487
|
-
tags: f.tags,
|
|
5488
|
-
min_importance: f.min_importance,
|
|
5489
|
-
pinned: f.pinned,
|
|
5490
|
-
agent_id: f.agent_id,
|
|
5491
|
-
project_id: f.project_id,
|
|
5492
|
-
session_id: f.session_id,
|
|
5493
|
-
namespace: f.namespace,
|
|
5494
|
-
as_of: f.as_of,
|
|
5495
|
-
limit: f.limit,
|
|
5496
|
-
offset: f.offset
|
|
5497
|
-
});
|
|
5498
|
-
const { data } = apiJson("GET", `/memories${q}`);
|
|
5499
|
-
return data?.memories ?? [];
|
|
5500
|
-
}
|
|
5501
|
-
const d = db || getDatabase();
|
|
5650
|
+
function buildMemoryListConditions(filter) {
|
|
5502
5651
|
const conditions = [];
|
|
5503
5652
|
const params = [];
|
|
5504
5653
|
if (filter) {
|
|
@@ -5610,21 +5759,104 @@ function listMemories(filter, db) {
|
|
|
5610
5759
|
} else {
|
|
5611
5760
|
conditions.push("status = 'active'");
|
|
5612
5761
|
}
|
|
5762
|
+
return { conditions, params };
|
|
5763
|
+
}
|
|
5764
|
+
function listMemoriesPage(filter, db) {
|
|
5765
|
+
const f = filter || {};
|
|
5766
|
+
if (!db && isApiMode()) {
|
|
5767
|
+
const q = toQuery({
|
|
5768
|
+
key: f.key,
|
|
5769
|
+
scope: f.scope,
|
|
5770
|
+
category: f.category,
|
|
5771
|
+
status: f.status,
|
|
5772
|
+
tags: f.tags,
|
|
5773
|
+
min_importance: f.min_importance,
|
|
5774
|
+
pinned: f.pinned,
|
|
5775
|
+
agent_id: f.agent_id,
|
|
5776
|
+
project_id: f.project_id,
|
|
5777
|
+
session_id: f.session_id,
|
|
5778
|
+
machine_id: f.machine_id,
|
|
5779
|
+
visible_to_machine_id: f.visible_to_machine_id,
|
|
5780
|
+
search: f.search,
|
|
5781
|
+
source: f.source,
|
|
5782
|
+
flag: f.flag,
|
|
5783
|
+
namespace: f.namespace,
|
|
5784
|
+
as_of: f.as_of,
|
|
5785
|
+
limit: f.limit,
|
|
5786
|
+
offset: f.offset
|
|
5787
|
+
});
|
|
5788
|
+
const { data } = apiJson("GET", `/memories${q}`);
|
|
5789
|
+
return {
|
|
5790
|
+
rows: data?.memories ?? [],
|
|
5791
|
+
has_more: data?.has_more,
|
|
5792
|
+
next_cursor: data?.next_cursor ?? null
|
|
5793
|
+
};
|
|
5794
|
+
}
|
|
5795
|
+
const d = db || getDatabase();
|
|
5796
|
+
const { conditions, params } = buildMemoryListConditions(f);
|
|
5613
5797
|
let sql = "SELECT * FROM memories";
|
|
5614
5798
|
if (conditions.length > 0) {
|
|
5615
5799
|
sql += ` WHERE ${conditions.join(" AND ")}`;
|
|
5616
5800
|
}
|
|
5617
5801
|
sql += " ORDER BY importance DESC, created_at DESC";
|
|
5618
|
-
if (
|
|
5802
|
+
if (f.limit) {
|
|
5619
5803
|
sql += " LIMIT ?";
|
|
5620
|
-
params.push(
|
|
5804
|
+
params.push(f.limit);
|
|
5621
5805
|
}
|
|
5622
|
-
if (
|
|
5806
|
+
if (f.offset) {
|
|
5623
5807
|
sql += " OFFSET ?";
|
|
5624
|
-
params.push(
|
|
5808
|
+
params.push(f.offset);
|
|
5625
5809
|
}
|
|
5626
5810
|
const rows = d.query(sql).all(...params);
|
|
5627
|
-
|
|
5811
|
+
const parsed = rows.map(parseMemoryRow);
|
|
5812
|
+
const hasMore = f.limit !== undefined && parsed.length === f.limit;
|
|
5813
|
+
return {
|
|
5814
|
+
rows: parsed,
|
|
5815
|
+
has_more: hasMore,
|
|
5816
|
+
next_cursor: hasMore ? (f.offset ?? 0) + parsed.length : null
|
|
5817
|
+
};
|
|
5818
|
+
}
|
|
5819
|
+
function listMemories(filter, db) {
|
|
5820
|
+
return listMemoriesPage(filter, db).rows;
|
|
5821
|
+
}
|
|
5822
|
+
function listMemoriesBounded(filter = {}, target, db) {
|
|
5823
|
+
const pageSize = 1000;
|
|
5824
|
+
const maxPages = 1000;
|
|
5825
|
+
const want = target === undefined ? undefined : target + 1;
|
|
5826
|
+
const rows = [];
|
|
5827
|
+
const seenCursors = new Set;
|
|
5828
|
+
let cursor = filter.offset ?? 0;
|
|
5829
|
+
let pages = 0;
|
|
5830
|
+
for (;; ) {
|
|
5831
|
+
if (want !== undefined && rows.length >= want)
|
|
5832
|
+
break;
|
|
5833
|
+
if (++pages > maxPages) {
|
|
5834
|
+
throw new Error(`memories list traversal exceeded ${maxPages} pages while collecting rows \u2014 aborting (cursor cycle?)`);
|
|
5835
|
+
}
|
|
5836
|
+
const limit = Math.min(want === undefined ? pageSize : want - rows.length, pageSize);
|
|
5837
|
+
const page = listMemoriesPage({ ...filter, limit, offset: cursor }, db);
|
|
5838
|
+
rows.push(...page.rows);
|
|
5839
|
+
if (page.has_more === false)
|
|
5840
|
+
break;
|
|
5841
|
+
if (page.has_more === undefined && page.rows.length < limit)
|
|
5842
|
+
break;
|
|
5843
|
+
if (page.has_more === true && (page.next_cursor === null || page.next_cursor === undefined)) {
|
|
5844
|
+
throw new Error("memories list page claimed more results without a next cursor \u2014 aborting");
|
|
5845
|
+
}
|
|
5846
|
+
const next = page.next_cursor ?? cursor + page.rows.length;
|
|
5847
|
+
if (seenCursors.has(next)) {
|
|
5848
|
+
throw new Error("memories list traversal repeated a cursor \u2014 aborting");
|
|
5849
|
+
}
|
|
5850
|
+
seenCursors.add(next);
|
|
5851
|
+
cursor = next;
|
|
5852
|
+
}
|
|
5853
|
+
const hasMore = target !== undefined && rows.length > target;
|
|
5854
|
+
const trimmed = hasMore ? rows.slice(0, target) : rows;
|
|
5855
|
+
return {
|
|
5856
|
+
rows: trimmed,
|
|
5857
|
+
has_more: hasMore,
|
|
5858
|
+
next_cursor: hasMore ? (filter.offset ?? 0) + trimmed.length : null
|
|
5859
|
+
};
|
|
5628
5860
|
}
|
|
5629
5861
|
function updateMemory(id, input, db) {
|
|
5630
5862
|
if (!db && isApiMode()) {
|
|
@@ -5690,20 +5922,29 @@ function updateMemory(id, input, db) {
|
|
|
5690
5922
|
sets.push("when_to_use = ?");
|
|
5691
5923
|
params.push(input.when_to_use ?? null);
|
|
5692
5924
|
}
|
|
5925
|
+
if (input.updated_by_agent !== undefined) {
|
|
5926
|
+
sets.push("updated_by_agent = ?");
|
|
5927
|
+
params.push(input.updated_by_agent ?? null);
|
|
5928
|
+
}
|
|
5693
5929
|
if (input.tags !== undefined) {
|
|
5694
5930
|
sets.push("tags = ?");
|
|
5695
5931
|
params.push(JSON.stringify(input.tags));
|
|
5696
|
-
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
|
|
5697
|
-
const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
|
|
5698
|
-
for (const tag of input.tags) {
|
|
5699
|
-
insertTag.run(memoryId, tag);
|
|
5700
|
-
}
|
|
5701
5932
|
}
|
|
5702
5933
|
params.push(memoryId);
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
|
|
5706
|
-
|
|
5934
|
+
d.transaction(() => {
|
|
5935
|
+
const res = d.run(`UPDATE memories SET ${sets.join(", ")} WHERE id = ?`, params);
|
|
5936
|
+
if (res.changes === 0) {
|
|
5937
|
+
throw new Error(`Update affected no rows for memory ${memoryId}: the record was read but not written. ` + `This is a bug in @hasna/mementos, not a bad argument \u2014 please report it.`);
|
|
5938
|
+
}
|
|
5939
|
+
if (input.tags !== undefined) {
|
|
5940
|
+
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
|
|
5941
|
+
const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
|
|
5942
|
+
for (const tag of input.tags) {
|
|
5943
|
+
insertTag.run(memoryId, tag);
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5946
|
+
return res;
|
|
5947
|
+
});
|
|
5707
5948
|
const updated = getMemory(memoryId, d);
|
|
5708
5949
|
if (input.value !== undefined) {
|
|
5709
5950
|
try {
|