@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/mcp/index.js
CHANGED
|
@@ -320,6 +320,7 @@ function translateSql(sql) {
|
|
|
320
320
|
let translated = sql.replace(/\?/g, () => `$${++parameterIndex}`);
|
|
321
321
|
const ISO_FMT = `'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'`;
|
|
322
322
|
translated = translated.replace(/datetime\s*\(\s*'now'\s*\)/gi, `to_char(now() AT TIME ZONE 'UTC', ${ISO_FMT})`);
|
|
323
|
+
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})`);
|
|
323
324
|
translated = translated.replace(/datetime\s*\(\s*'now'\s*,\s*'(-?\d+)\s+(minutes?|hours?|days?|seconds?)'\s*\)/gi, (_match, amount, unit) => {
|
|
324
325
|
const parsed = parseInt(String(amount), 10);
|
|
325
326
|
const absolute = Math.abs(parsed);
|
|
@@ -804,16 +805,24 @@ function transferRows(target, table, rows, options) {
|
|
|
804
805
|
const conflictColumn = options.conflictColumn ?? "updated_at";
|
|
805
806
|
let written = 0;
|
|
806
807
|
let skipped = 0;
|
|
808
|
+
let maxSyncedAt = null;
|
|
807
809
|
const errors = [];
|
|
810
|
+
const bumpMaxSyncedAt = (row) => {
|
|
811
|
+
const value = row[conflictColumn];
|
|
812
|
+
if (typeof value === "string" && (maxSyncedAt === null || value > maxSyncedAt)) {
|
|
813
|
+
maxSyncedAt = value;
|
|
814
|
+
}
|
|
815
|
+
};
|
|
808
816
|
if (rows.length === 0) {
|
|
809
|
-
return { written, skipped, errors };
|
|
817
|
+
return { written, skipped, errors, maxSyncedAt };
|
|
810
818
|
}
|
|
811
819
|
const columns = Object.keys(rows[0] ?? {});
|
|
812
820
|
if (!columns.includes(primaryKey)) {
|
|
813
821
|
return {
|
|
814
822
|
written,
|
|
815
823
|
skipped,
|
|
816
|
-
errors: [`Table "${table}" has no "${primaryKey}" column; skipping`]
|
|
824
|
+
errors: [`Table "${table}" has no "${primaryKey}" column; skipping`],
|
|
825
|
+
maxSyncedAt
|
|
817
826
|
};
|
|
818
827
|
}
|
|
819
828
|
const hasConflictColumn = columns.includes(conflictColumn);
|
|
@@ -826,6 +835,7 @@ function transferRows(target, table, rows, options) {
|
|
|
826
835
|
const incomingTime = Date.parse(String(row[conflictColumn]));
|
|
827
836
|
if (Number.isFinite(existingTime) && Number.isFinite(incomingTime) && existingTime >= incomingTime) {
|
|
828
837
|
skipped++;
|
|
838
|
+
bumpMaxSyncedAt(row);
|
|
829
839
|
continue;
|
|
830
840
|
}
|
|
831
841
|
}
|
|
@@ -838,11 +848,12 @@ function transferRows(target, table, rows, options) {
|
|
|
838
848
|
target.run(`INSERT INTO "${table}" (${columnList}) VALUES (${placeholders})`, ...columns.map((column) => row[column]));
|
|
839
849
|
}
|
|
840
850
|
written++;
|
|
851
|
+
bumpMaxSyncedAt(row);
|
|
841
852
|
} catch (error) {
|
|
842
853
|
errors.push(`Row ${String(row[primaryKey] ?? "unknown")}: ${error instanceof Error ? error.message : String(error)}`);
|
|
843
854
|
}
|
|
844
855
|
}
|
|
845
|
-
return { written, skipped, errors };
|
|
856
|
+
return { written, skipped, errors, maxSyncedAt };
|
|
846
857
|
}
|
|
847
858
|
function incrementalSyncPush(local, remote, tables, options = {}) {
|
|
848
859
|
return runIncrementalSync("push", local, remote, local, tables, options);
|
|
@@ -880,22 +891,29 @@ function runIncrementalSync(direction, source, target, metaDb, tables, options)
|
|
|
880
891
|
rows = source.all(`SELECT * FROM "${table}"`);
|
|
881
892
|
stat.first_sync = true;
|
|
882
893
|
}
|
|
894
|
+
let maxSyncedAt = null;
|
|
883
895
|
for (let offset = 0;offset < rows.length; offset += batchSize) {
|
|
884
896
|
const batch = rows.slice(offset, offset + batchSize);
|
|
885
897
|
const result = transferRows(target, table, batch, options);
|
|
886
898
|
stat.synced_rows += result.written;
|
|
887
899
|
stat.skipped_rows += result.skipped;
|
|
888
900
|
stat.errors.push(...result.errors);
|
|
901
|
+
if (result.maxSyncedAt !== null && (maxSyncedAt === null || result.maxSyncedAt > maxSyncedAt)) {
|
|
902
|
+
maxSyncedAt = result.maxSyncedAt;
|
|
903
|
+
}
|
|
889
904
|
}
|
|
890
905
|
if (rows.length === 0) {
|
|
891
906
|
stat.skipped_rows = stat.total_rows;
|
|
892
907
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
908
|
+
const nextCursor = maxSyncedAt ?? meta?.last_synced_at ?? null;
|
|
909
|
+
if (rows.length > 0 && stat.errors.length === 0 && nextCursor !== null) {
|
|
910
|
+
upsertSyncMeta(metaDb, {
|
|
911
|
+
table_name: table,
|
|
912
|
+
last_synced_at: nextCursor,
|
|
913
|
+
last_synced_row_count: stat.synced_rows,
|
|
914
|
+
direction
|
|
915
|
+
});
|
|
916
|
+
}
|
|
899
917
|
} catch (error) {
|
|
900
918
|
stat.errors.push(`Table "${table}": ${error instanceof Error ? error.message : String(error)}`);
|
|
901
919
|
}
|
|
@@ -923,8 +941,13 @@ var init_storage = __esm(() => {
|
|
|
923
941
|
data;
|
|
924
942
|
closed = false;
|
|
925
943
|
lastError = null;
|
|
944
|
+
generation = 0;
|
|
926
945
|
static DATA_BYTES = 128 * 1024 * 1024;
|
|
927
|
-
static
|
|
946
|
+
static queryTimeoutMs() {
|
|
947
|
+
const raw = process.env["MEMENTOS_PGSYNC_QUERY_TIMEOUT_MS"]?.trim();
|
|
948
|
+
const parsed = raw ? Number(raw) : Number.NaN;
|
|
949
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 60000;
|
|
950
|
+
}
|
|
928
951
|
static resolveWorkerPath() {
|
|
929
952
|
const ext = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
|
|
930
953
|
const here = fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -939,12 +962,12 @@ var init_storage = __esm(() => {
|
|
|
939
962
|
}
|
|
940
963
|
return candidates[0];
|
|
941
964
|
}
|
|
942
|
-
constructor(connectionString) {
|
|
943
|
-
const control = new SharedArrayBuffer(
|
|
965
|
+
constructor(connectionString, workerPath) {
|
|
966
|
+
const control = new SharedArrayBuffer(12);
|
|
944
967
|
const dataSab = new SharedArrayBuffer(PgSyncPool.DATA_BYTES);
|
|
945
968
|
this.status = new Int32Array(control);
|
|
946
969
|
this.data = new Uint8Array(dataSab);
|
|
947
|
-
this.worker = new Worker(PgSyncPool.resolveWorkerPath(), {
|
|
970
|
+
this.worker = new Worker(workerPath ?? PgSyncPool.resolveWorkerPath(), {
|
|
948
971
|
workerData: {
|
|
949
972
|
dsn: stripSslParams(connectionString),
|
|
950
973
|
ssl: sslConfigFor(connectionString),
|
|
@@ -962,21 +985,35 @@ var init_storage = __esm(() => {
|
|
|
962
985
|
throw new Error("PgSyncPool is closed");
|
|
963
986
|
if (this.lastError)
|
|
964
987
|
throw this.lastError;
|
|
988
|
+
const timeoutMs = PgSyncPool.queryTimeoutMs();
|
|
989
|
+
const gen = ++this.generation;
|
|
965
990
|
Atomics.store(this.status, 0, 0);
|
|
966
|
-
this.
|
|
967
|
-
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
991
|
+
Atomics.store(this.status, 2, 0);
|
|
992
|
+
this.worker.postMessage({ sql, params, gen });
|
|
993
|
+
const deadline = Date.now() + timeoutMs;
|
|
994
|
+
for (;; ) {
|
|
995
|
+
const remaining = deadline - Date.now();
|
|
996
|
+
const responding = Atomics.load(this.status, 0);
|
|
997
|
+
if (responding === gen) {
|
|
998
|
+
const code = Atomics.load(this.status, 2);
|
|
999
|
+
const len = Atomics.load(this.status, 1);
|
|
1000
|
+
const payload = JSON.parse(new TextDecoder().decode(this.data.subarray(0, len)));
|
|
1001
|
+
if (code === 2) {
|
|
1002
|
+
throw new Error(payload.message ?? "PostgreSQL error");
|
|
1003
|
+
}
|
|
1004
|
+
return payload;
|
|
1005
|
+
}
|
|
1006
|
+
if (responding !== 0) {
|
|
1007
|
+
Atomics.compareExchange(this.status, 0, responding, 0);
|
|
1008
|
+
continue;
|
|
1009
|
+
}
|
|
1010
|
+
if (remaining <= 0) {
|
|
1011
|
+
if (this.lastError)
|
|
1012
|
+
throw this.lastError;
|
|
1013
|
+
throw new Error(`PostgreSQL query timed out after ${timeoutMs}ms`);
|
|
1014
|
+
}
|
|
1015
|
+
Atomics.wait(this.status, 0, 0, remaining);
|
|
978
1016
|
}
|
|
979
|
-
return payload;
|
|
980
1017
|
}
|
|
981
1018
|
end() {
|
|
982
1019
|
if (this.closed)
|
|
@@ -1202,7 +1239,16 @@ x-api-key: ${cfg.apiKey}
|
|
|
1202
1239
|
function apiJson(method, path, body, options) {
|
|
1203
1240
|
const raw = apiRequestRaw(method, path, body);
|
|
1204
1241
|
if (raw.status >= 200 && raw.status < 300) {
|
|
1205
|
-
|
|
1242
|
+
let data;
|
|
1243
|
+
if (raw.body.trim()) {
|
|
1244
|
+
try {
|
|
1245
|
+
data = JSON.parse(raw.body);
|
|
1246
|
+
} catch (e) {
|
|
1247
|
+
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));
|
|
1248
|
+
}
|
|
1249
|
+
} else {
|
|
1250
|
+
data = undefined;
|
|
1251
|
+
}
|
|
1206
1252
|
return { status: raw.status, data };
|
|
1207
1253
|
}
|
|
1208
1254
|
if (raw.status === 404 && options?.allow404) {
|
|
@@ -3243,8 +3289,12 @@ __export(exports_memories, {
|
|
|
3243
3289
|
updateMemory: () => updateMemory,
|
|
3244
3290
|
touchMemory: () => touchMemory,
|
|
3245
3291
|
semanticSearch: () => semanticSearch,
|
|
3292
|
+
reservedAgentIdViolation: () => reservedAgentIdViolation,
|
|
3246
3293
|
parseMemoryRow: () => parseMemoryRow,
|
|
3294
|
+
listMemoryHistoryPage: () => listMemoryHistoryPage,
|
|
3247
3295
|
listMemoryHistory: () => listMemoryHistory,
|
|
3296
|
+
listMemoriesPage: () => listMemoriesPage,
|
|
3297
|
+
listMemoriesBounded: () => listMemoriesBounded,
|
|
3248
3298
|
listMemories: () => listMemories,
|
|
3249
3299
|
listLowTrustMemories: () => listLowTrustMemories,
|
|
3250
3300
|
indexMemoryEmbedding: () => indexMemoryEmbedding,
|
|
@@ -3258,6 +3308,8 @@ __export(exports_memories, {
|
|
|
3258
3308
|
getMemoriesByKey: () => getMemoriesByKey,
|
|
3259
3309
|
deleteMemory: () => deleteMemory,
|
|
3260
3310
|
createMemory: () => createMemory,
|
|
3311
|
+
countMemoryHistory: () => countMemoryHistory,
|
|
3312
|
+
countMemories: () => countMemories,
|
|
3261
3313
|
cleanExpiredMemories: () => cleanExpiredMemories,
|
|
3262
3314
|
bulkUpsertMemories: () => bulkUpsertMemories,
|
|
3263
3315
|
bulkDeleteMemories: () => bulkDeleteMemories
|
|
@@ -3309,7 +3361,20 @@ function parseMemoryRow(row) {
|
|
|
3309
3361
|
accessed_at: row["accessed_at"] || null
|
|
3310
3362
|
};
|
|
3311
3363
|
}
|
|
3364
|
+
function reservedAgentIdViolation(agentId) {
|
|
3365
|
+
if (!agentId)
|
|
3366
|
+
return null;
|
|
3367
|
+
const normalized = agentId.trim().toLowerCase();
|
|
3368
|
+
if (RESERVED_AGENT_IDS.has(normalized)) {
|
|
3369
|
+
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.`;
|
|
3370
|
+
}
|
|
3371
|
+
return null;
|
|
3372
|
+
}
|
|
3312
3373
|
function createMemory(input, dedupeMode = "merge", db) {
|
|
3374
|
+
const reservedViolation = reservedAgentIdViolation(input.agent_id);
|
|
3375
|
+
if (reservedViolation) {
|
|
3376
|
+
throw new Error(reservedViolation);
|
|
3377
|
+
}
|
|
3313
3378
|
if (!db && isApiMode()) {
|
|
3314
3379
|
const { status, data } = apiJson("POST", "/memories", { ...input, dedupe: dedupeMode });
|
|
3315
3380
|
if (!data || !data.id) {
|
|
@@ -3359,7 +3424,8 @@ function createMemory(input, dedupeMode = "merge", db) {
|
|
|
3359
3424
|
importance = ?, metadata = ?, expires_at = ?,
|
|
3360
3425
|
when_to_use = ?,
|
|
3361
3426
|
pinned = COALESCE(pinned, 0),
|
|
3362
|
-
version = version + 1, updated_at =
|
|
3427
|
+
version = version + 1, updated_at = ?,
|
|
3428
|
+
updated_by_agent = ?
|
|
3363
3429
|
WHERE id = ?`, [
|
|
3364
3430
|
safeValue,
|
|
3365
3431
|
input.category || "knowledge",
|
|
@@ -3370,6 +3436,7 @@ function createMemory(input, dedupeMode = "merge", db) {
|
|
|
3370
3436
|
expiresAt,
|
|
3371
3437
|
input.when_to_use || null,
|
|
3372
3438
|
timestamp,
|
|
3439
|
+
input.agent_id || null,
|
|
3373
3440
|
existing.id
|
|
3374
3441
|
]);
|
|
3375
3442
|
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [existing.id]);
|
|
@@ -3474,6 +3541,12 @@ function bulkUpsertMemories(memories, db) {
|
|
|
3474
3541
|
errors.push(`Rejected "${key}": ${formatEnumViolation(violation)}`);
|
|
3475
3542
|
continue;
|
|
3476
3543
|
}
|
|
3544
|
+
const agentViolation = reservedAgentIdViolation(typeof mem["agent_id"] === "string" ? mem["agent_id"] : undefined);
|
|
3545
|
+
if (agentViolation) {
|
|
3546
|
+
rejected++;
|
|
3547
|
+
errors.push(`Rejected "${key}": ${agentViolation}`);
|
|
3548
|
+
continue;
|
|
3549
|
+
}
|
|
3477
3550
|
const timestamp = now();
|
|
3478
3551
|
let tags = [];
|
|
3479
3552
|
const rawTags = mem["tags"];
|
|
@@ -3624,29 +3697,7 @@ function getMemoriesByKey(key, scope, agentId, projectId, db) {
|
|
|
3624
3697
|
const rows = d.query(sql).all(...params);
|
|
3625
3698
|
return rows.map(parseMemoryRow);
|
|
3626
3699
|
}
|
|
3627
|
-
function
|
|
3628
|
-
if (!db && isApiMode()) {
|
|
3629
|
-
const f = filter || {};
|
|
3630
|
-
const q = toQuery({
|
|
3631
|
-
key: f.key,
|
|
3632
|
-
scope: f.scope,
|
|
3633
|
-
category: f.category,
|
|
3634
|
-
status: f.status,
|
|
3635
|
-
tags: f.tags,
|
|
3636
|
-
min_importance: f.min_importance,
|
|
3637
|
-
pinned: f.pinned,
|
|
3638
|
-
agent_id: f.agent_id,
|
|
3639
|
-
project_id: f.project_id,
|
|
3640
|
-
session_id: f.session_id,
|
|
3641
|
-
namespace: f.namespace,
|
|
3642
|
-
as_of: f.as_of,
|
|
3643
|
-
limit: f.limit,
|
|
3644
|
-
offset: f.offset
|
|
3645
|
-
});
|
|
3646
|
-
const { data } = apiJson("GET", `/memories${q}`);
|
|
3647
|
-
return data?.memories ?? [];
|
|
3648
|
-
}
|
|
3649
|
-
const d = db || getDatabase();
|
|
3700
|
+
function buildMemoryListConditions(filter) {
|
|
3650
3701
|
const conditions = [];
|
|
3651
3702
|
const params = [];
|
|
3652
3703
|
if (filter) {
|
|
@@ -3758,21 +3809,114 @@ function listMemories(filter, db) {
|
|
|
3758
3809
|
} else {
|
|
3759
3810
|
conditions.push("status = 'active'");
|
|
3760
3811
|
}
|
|
3812
|
+
return { conditions, params };
|
|
3813
|
+
}
|
|
3814
|
+
function listMemoriesPage(filter, db) {
|
|
3815
|
+
const f = filter || {};
|
|
3816
|
+
if (!db && isApiMode()) {
|
|
3817
|
+
const q = toQuery({
|
|
3818
|
+
key: f.key,
|
|
3819
|
+
scope: f.scope,
|
|
3820
|
+
category: f.category,
|
|
3821
|
+
status: f.status,
|
|
3822
|
+
tags: f.tags,
|
|
3823
|
+
min_importance: f.min_importance,
|
|
3824
|
+
pinned: f.pinned,
|
|
3825
|
+
agent_id: f.agent_id,
|
|
3826
|
+
project_id: f.project_id,
|
|
3827
|
+
session_id: f.session_id,
|
|
3828
|
+
machine_id: f.machine_id,
|
|
3829
|
+
visible_to_machine_id: f.visible_to_machine_id,
|
|
3830
|
+
search: f.search,
|
|
3831
|
+
source: f.source,
|
|
3832
|
+
flag: f.flag,
|
|
3833
|
+
namespace: f.namespace,
|
|
3834
|
+
as_of: f.as_of,
|
|
3835
|
+
limit: f.limit,
|
|
3836
|
+
offset: f.offset
|
|
3837
|
+
});
|
|
3838
|
+
const { data } = apiJson("GET", `/memories${q}`);
|
|
3839
|
+
return {
|
|
3840
|
+
rows: data?.memories ?? [],
|
|
3841
|
+
has_more: data?.has_more,
|
|
3842
|
+
next_cursor: data?.next_cursor ?? null
|
|
3843
|
+
};
|
|
3844
|
+
}
|
|
3845
|
+
const d = db || getDatabase();
|
|
3846
|
+
const { conditions, params } = buildMemoryListConditions(f);
|
|
3761
3847
|
let sql = "SELECT * FROM memories";
|
|
3762
3848
|
if (conditions.length > 0) {
|
|
3763
3849
|
sql += ` WHERE ${conditions.join(" AND ")}`;
|
|
3764
3850
|
}
|
|
3765
3851
|
sql += " ORDER BY importance DESC, created_at DESC";
|
|
3766
|
-
if (
|
|
3852
|
+
if (f.limit) {
|
|
3767
3853
|
sql += " LIMIT ?";
|
|
3768
|
-
params.push(
|
|
3854
|
+
params.push(f.limit);
|
|
3769
3855
|
}
|
|
3770
|
-
if (
|
|
3856
|
+
if (f.offset) {
|
|
3771
3857
|
sql += " OFFSET ?";
|
|
3772
|
-
params.push(
|
|
3858
|
+
params.push(f.offset);
|
|
3773
3859
|
}
|
|
3774
3860
|
const rows = d.query(sql).all(...params);
|
|
3775
|
-
|
|
3861
|
+
const parsed = rows.map(parseMemoryRow);
|
|
3862
|
+
const hasMore = f.limit !== undefined && parsed.length === f.limit;
|
|
3863
|
+
return {
|
|
3864
|
+
rows: parsed,
|
|
3865
|
+
has_more: hasMore,
|
|
3866
|
+
next_cursor: hasMore ? (f.offset ?? 0) + parsed.length : null
|
|
3867
|
+
};
|
|
3868
|
+
}
|
|
3869
|
+
function listMemories(filter, db) {
|
|
3870
|
+
return listMemoriesPage(filter, db).rows;
|
|
3871
|
+
}
|
|
3872
|
+
function listMemoriesBounded(filter = {}, target, db) {
|
|
3873
|
+
const pageSize = 1000;
|
|
3874
|
+
const maxPages = 1000;
|
|
3875
|
+
const want = target === undefined ? undefined : target + 1;
|
|
3876
|
+
const rows = [];
|
|
3877
|
+
const seenCursors = new Set;
|
|
3878
|
+
let cursor = filter.offset ?? 0;
|
|
3879
|
+
let pages = 0;
|
|
3880
|
+
for (;; ) {
|
|
3881
|
+
if (want !== undefined && rows.length >= want)
|
|
3882
|
+
break;
|
|
3883
|
+
if (++pages > maxPages) {
|
|
3884
|
+
throw new Error(`memories list traversal exceeded ${maxPages} pages while collecting rows \u2014 aborting (cursor cycle?)`);
|
|
3885
|
+
}
|
|
3886
|
+
const limit = Math.min(want === undefined ? pageSize : want - rows.length, pageSize);
|
|
3887
|
+
const page = listMemoriesPage({ ...filter, limit, offset: cursor }, db);
|
|
3888
|
+
rows.push(...page.rows);
|
|
3889
|
+
if (page.has_more === false)
|
|
3890
|
+
break;
|
|
3891
|
+
if (page.has_more === undefined && page.rows.length < limit)
|
|
3892
|
+
break;
|
|
3893
|
+
if (page.has_more === true && (page.next_cursor === null || page.next_cursor === undefined)) {
|
|
3894
|
+
throw new Error("memories list page claimed more results without a next cursor \u2014 aborting");
|
|
3895
|
+
}
|
|
3896
|
+
const next = page.next_cursor ?? cursor + page.rows.length;
|
|
3897
|
+
if (seenCursors.has(next)) {
|
|
3898
|
+
throw new Error("memories list traversal repeated a cursor \u2014 aborting");
|
|
3899
|
+
}
|
|
3900
|
+
seenCursors.add(next);
|
|
3901
|
+
cursor = next;
|
|
3902
|
+
}
|
|
3903
|
+
const hasMore = target !== undefined && rows.length > target;
|
|
3904
|
+
const trimmed = hasMore ? rows.slice(0, target) : rows;
|
|
3905
|
+
return {
|
|
3906
|
+
rows: trimmed,
|
|
3907
|
+
has_more: hasMore,
|
|
3908
|
+
next_cursor: hasMore ? (filter.offset ?? 0) + trimmed.length : null
|
|
3909
|
+
};
|
|
3910
|
+
}
|
|
3911
|
+
function countMemories(filter, db) {
|
|
3912
|
+
const d = db || getDatabase();
|
|
3913
|
+
const { conditions, params } = buildMemoryListConditions(filter);
|
|
3914
|
+
let sql = "SELECT COUNT(*) AS c FROM memories";
|
|
3915
|
+
if (conditions.length > 0) {
|
|
3916
|
+
sql += ` WHERE ${conditions.join(" AND ")}`;
|
|
3917
|
+
}
|
|
3918
|
+
const row = d.query(sql).get(...params);
|
|
3919
|
+
return row?.c ?? 0;
|
|
3776
3920
|
}
|
|
3777
3921
|
function getMemoryBriefing(opts, db) {
|
|
3778
3922
|
const limit = opts.limit ?? 20;
|
|
@@ -3834,13 +3978,17 @@ function listLowTrustMemories(opts = {}, db) {
|
|
|
3834
3978
|
const rows = d.prepare(`SELECT * FROM memories WHERE ${conditions.join(" AND ")} ORDER BY trust_score ASC LIMIT ? OFFSET ?`).all(...params);
|
|
3835
3979
|
return rows.map(parseMemoryRow);
|
|
3836
3980
|
}
|
|
3837
|
-
function
|
|
3981
|
+
function listMemoryHistoryPage(opts = {}, db) {
|
|
3838
3982
|
const limit = opts.limit ?? 20;
|
|
3839
3983
|
const offset = opts.offset ?? 0;
|
|
3840
3984
|
if (!db && isApiMode()) {
|
|
3841
3985
|
const q = toQuery({ limit, offset });
|
|
3842
3986
|
const { data } = apiJson("GET", `/memories/history${q}`);
|
|
3843
|
-
return
|
|
3987
|
+
return {
|
|
3988
|
+
rows: data?.memories ?? [],
|
|
3989
|
+
has_more: data?.has_more,
|
|
3990
|
+
next_cursor: data?.next_cursor ?? null
|
|
3991
|
+
};
|
|
3844
3992
|
}
|
|
3845
3993
|
const d = db || getDatabase();
|
|
3846
3994
|
const params = [limit];
|
|
@@ -3850,7 +3998,21 @@ function listMemoryHistory(opts = {}, db) {
|
|
|
3850
3998
|
params.push(offset);
|
|
3851
3999
|
}
|
|
3852
4000
|
const rows = d.query(sql).all(...params);
|
|
3853
|
-
|
|
4001
|
+
const parsed = rows.map(parseMemoryRow);
|
|
4002
|
+
const hasMore = parsed.length === limit;
|
|
4003
|
+
return {
|
|
4004
|
+
rows: parsed,
|
|
4005
|
+
has_more: hasMore,
|
|
4006
|
+
next_cursor: hasMore ? offset + parsed.length : null
|
|
4007
|
+
};
|
|
4008
|
+
}
|
|
4009
|
+
function listMemoryHistory(opts = {}, db) {
|
|
4010
|
+
return listMemoryHistoryPage(opts, db).rows;
|
|
4011
|
+
}
|
|
4012
|
+
function countMemoryHistory(db) {
|
|
4013
|
+
const d = db || getDatabase();
|
|
4014
|
+
const row = d.query("SELECT COUNT(*) AS c FROM memories WHERE status = 'active' AND accessed_at IS NOT NULL").get();
|
|
4015
|
+
return row?.c ?? 0;
|
|
3854
4016
|
}
|
|
3855
4017
|
function getMemoryChain(sequenceGroup, projectId, db) {
|
|
3856
4018
|
if (!db && isApiMode()) {
|
|
@@ -3947,20 +4109,29 @@ function updateMemory(id, input, db) {
|
|
|
3947
4109
|
sets.push("when_to_use = ?");
|
|
3948
4110
|
params.push(input.when_to_use ?? null);
|
|
3949
4111
|
}
|
|
4112
|
+
if (input.updated_by_agent !== undefined) {
|
|
4113
|
+
sets.push("updated_by_agent = ?");
|
|
4114
|
+
params.push(input.updated_by_agent ?? null);
|
|
4115
|
+
}
|
|
3950
4116
|
if (input.tags !== undefined) {
|
|
3951
4117
|
sets.push("tags = ?");
|
|
3952
4118
|
params.push(JSON.stringify(input.tags));
|
|
3953
|
-
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
|
|
3954
|
-
const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
|
|
3955
|
-
for (const tag of input.tags) {
|
|
3956
|
-
insertTag.run(memoryId, tag);
|
|
3957
|
-
}
|
|
3958
4119
|
}
|
|
3959
4120
|
params.push(memoryId);
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
4121
|
+
d.transaction(() => {
|
|
4122
|
+
const res = d.run(`UPDATE memories SET ${sets.join(", ")} WHERE id = ?`, params);
|
|
4123
|
+
if (res.changes === 0) {
|
|
4124
|
+
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.`);
|
|
4125
|
+
}
|
|
4126
|
+
if (input.tags !== undefined) {
|
|
4127
|
+
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
|
|
4128
|
+
const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
|
|
4129
|
+
for (const tag of input.tags) {
|
|
4130
|
+
insertTag.run(memoryId, tag);
|
|
4131
|
+
}
|
|
4132
|
+
}
|
|
4133
|
+
return res;
|
|
4134
|
+
});
|
|
3964
4135
|
const updated = getMemory(memoryId, d);
|
|
3965
4136
|
if (input.value !== undefined) {
|
|
3966
4137
|
try {
|
|
@@ -4131,7 +4302,7 @@ async function semanticSearch(queryText, options = {}, db) {
|
|
|
4131
4302
|
scored.sort((a, b) => b.score - a.score);
|
|
4132
4303
|
return scored.slice(0, limit);
|
|
4133
4304
|
}
|
|
4134
|
-
var RECALL_PROMOTE_THRESHOLD = 3;
|
|
4305
|
+
var RESERVED_AGENT_IDS, RECALL_PROMOTE_THRESHOLD = 3;
|
|
4135
4306
|
var init_memories = __esm(() => {
|
|
4136
4307
|
init_types();
|
|
4137
4308
|
init_database();
|
|
@@ -4141,6 +4312,12 @@ var init_memories = __esm(() => {
|
|
|
4141
4312
|
init_poisoning();
|
|
4142
4313
|
init_entity_memories();
|
|
4143
4314
|
init_api_mode();
|
|
4315
|
+
RESERVED_AGENT_IDS = new Set([
|
|
4316
|
+
"agent-a",
|
|
4317
|
+
"agent-x",
|
|
4318
|
+
"agent-z",
|
|
4319
|
+
"nonexistent-agent"
|
|
4320
|
+
]);
|
|
4144
4321
|
});
|
|
4145
4322
|
|
|
4146
4323
|
// src/db/machines.ts
|
|
@@ -5018,7 +5195,7 @@ function buildFilterConditions(filter) {
|
|
|
5018
5195
|
const conditions = [];
|
|
5019
5196
|
const params = [];
|
|
5020
5197
|
conditions.push("m.status = 'active'");
|
|
5021
|
-
conditions.push("(m.expires_at IS NULL OR m.expires_at >=
|
|
5198
|
+
conditions.push("(m.expires_at IS NULL OR m.expires_at >= strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))");
|
|
5022
5199
|
if (!filter)
|
|
5023
5200
|
return { conditions, params };
|
|
5024
5201
|
if (filter.scope) {
|
|
@@ -7027,7 +7204,7 @@ async function detectContradiction(newKey, newValue, options = {}, db) {
|
|
|
7027
7204
|
conditions.push("project_id = ?");
|
|
7028
7205
|
params.push(project_id);
|
|
7029
7206
|
}
|
|
7030
|
-
conditions.push("(valid_until IS NULL OR valid_until >
|
|
7207
|
+
conditions.push("(valid_until IS NULL OR valid_until > strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))");
|
|
7031
7208
|
const sql = `SELECT * FROM memories WHERE ${conditions.join(" AND ")} ORDER BY importance DESC LIMIT 10`;
|
|
7032
7209
|
const rows = d.query(sql).all(...params);
|
|
7033
7210
|
if (rows.length === 0) {
|
|
@@ -23216,7 +23393,7 @@ class JSONSchemaGenerator {
|
|
|
23216
23393
|
if (val === undefined) {
|
|
23217
23394
|
if (this.unrepresentable === "throw") {
|
|
23218
23395
|
throw new Error("Literal `undefined` cannot be represented in JSON Schema");
|
|
23219
|
-
}
|
|
23396
|
+
}
|
|
23220
23397
|
} else if (typeof val === "bigint") {
|
|
23221
23398
|
if (this.unrepresentable === "throw") {
|
|
23222
23399
|
throw new Error("BigInt literals cannot be represented in JSON Schema");
|
|
@@ -44866,7 +45043,7 @@ var require_tracestate_impl = __commonJS((exports) => {
|
|
|
44866
45043
|
const value = listMember.slice(i + 1, part.length);
|
|
44867
45044
|
if ((0, tracestate_validators_1.validateKey)(key) && (0, tracestate_validators_1.validateValue)(value)) {
|
|
44868
45045
|
agg.set(key, value);
|
|
44869
|
-
}
|
|
45046
|
+
}
|
|
44870
45047
|
}
|
|
44871
45048
|
return agg;
|
|
44872
45049
|
}, new Map);
|
|
@@ -58425,6 +58602,89 @@ function updateAgent(id, updates, db) {
|
|
|
58425
58602
|
// src/db/projects.ts
|
|
58426
58603
|
init_database();
|
|
58427
58604
|
init_api_mode();
|
|
58605
|
+
|
|
58606
|
+
// src/project-registration/historical-receipt.ts
|
|
58607
|
+
var ROOT_TENANT_ID = "adfd95c7-ee8b-52cb-ae47-4ae65dae3313";
|
|
58608
|
+
var FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION = {
|
|
58609
|
+
authority: "mementos",
|
|
58610
|
+
authority_route: "mementos.project-registration.v1",
|
|
58611
|
+
package_version: "1.0.0-rc.3",
|
|
58612
|
+
authority_id: "mementos",
|
|
58613
|
+
tenant_id: "default",
|
|
58614
|
+
corpus_id: "default",
|
|
58615
|
+
operation_id: "op-cli-register-full",
|
|
58616
|
+
step_id: "mementos_project",
|
|
58617
|
+
resource_kind: "project",
|
|
58618
|
+
direction: "forward",
|
|
58619
|
+
target_selector: "wks_005285827590a93b70e5",
|
|
58620
|
+
target_id: "mm_project_f75606ef14e51fb577a15882ba0ab8ed333b2c29",
|
|
58621
|
+
idempotency_key: "prk_786cdc6babddeae1be8d5078d0f75322d1ea1010ac5d8a50",
|
|
58622
|
+
receipt_id: "mmpr_a647f9908a33bb64bf137f584202590f91b72a33",
|
|
58623
|
+
request_digest: "8eb0e3fee26fdb7edb8a444aeddaaedb79a84a5a36e742ae03616f62b19f5c22",
|
|
58624
|
+
precondition_digest: "0b6c22fcf75d835f9f27308b1a9d40e8902e48a97da370fd56df5acacfcd968e",
|
|
58625
|
+
result_revision: "2026-08-09T13:37:43.068Z",
|
|
58626
|
+
result_digest: "26fb0dd5c5e20909d3653ab0ddd8fa45e5142728e4e66d595e2419f7ed40b036",
|
|
58627
|
+
created_at: "2026-08-09T13:37:43.068Z",
|
|
58628
|
+
identity_digest: "1108dd972c90e4989036fb6ecec7dde10f54641a697bd53cfcd64017f589ace7",
|
|
58629
|
+
target_digest: "72789fcd60668eeb66ee068936d3afa96deadcb007228830c64b6de783b6dcef",
|
|
58630
|
+
operation_digest: "d7e37bfb2c0d28f8c4086c53224cd855d14694f32807b74c102b61a99963f3c0",
|
|
58631
|
+
idempotency_digest: "b56d8ec37efb818759cdd2ee3b58bc1401ac13384c8d64c1813bb5c198b1e376",
|
|
58632
|
+
receipt_digest: "52ce90c5de6817989f107d9d27e06156962a2b9c365e34e16a57aa37886501a2",
|
|
58633
|
+
response_digest: "2fa3ed508f5f192c18753b1205ced996340fdf02f735420d32db897fc239805c"
|
|
58634
|
+
};
|
|
58635
|
+
var FLEET_RESOURCES_HISTORICAL_RECEIPT = {
|
|
58636
|
+
receipt_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.receipt_id,
|
|
58637
|
+
authority: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority,
|
|
58638
|
+
route: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_route,
|
|
58639
|
+
package_version: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.package_version,
|
|
58640
|
+
authority_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_id,
|
|
58641
|
+
tenant_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.tenant_id,
|
|
58642
|
+
corpus_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.corpus_id,
|
|
58643
|
+
operation_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.operation_id,
|
|
58644
|
+
step_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.step_id,
|
|
58645
|
+
resource_kind: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.resource_kind,
|
|
58646
|
+
direction: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.direction,
|
|
58647
|
+
idempotency_key: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.idempotency_key,
|
|
58648
|
+
request_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.request_digest,
|
|
58649
|
+
precondition_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.precondition_digest,
|
|
58650
|
+
outcome: "accepted",
|
|
58651
|
+
reason: null,
|
|
58652
|
+
target_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_id,
|
|
58653
|
+
result_revision: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.result_revision,
|
|
58654
|
+
result_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.result_digest,
|
|
58655
|
+
duplicate_of_receipt_id: null,
|
|
58656
|
+
accepted_receipt_id: null,
|
|
58657
|
+
created_by_operation: true,
|
|
58658
|
+
created_at: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.created_at
|
|
58659
|
+
};
|
|
58660
|
+
var FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY = {
|
|
58661
|
+
authority_id: "mementos",
|
|
58662
|
+
tenant_id: ROOT_TENANT_ID,
|
|
58663
|
+
corpus_id: "mementos:postgresql"
|
|
58664
|
+
};
|
|
58665
|
+
var FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY = {
|
|
58666
|
+
source: {
|
|
58667
|
+
authority: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority,
|
|
58668
|
+
authority_route: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_route,
|
|
58669
|
+
package_version: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.package_version,
|
|
58670
|
+
authority_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_id,
|
|
58671
|
+
tenant_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.tenant_id,
|
|
58672
|
+
corpus_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.corpus_id,
|
|
58673
|
+
operation_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.operation_id,
|
|
58674
|
+
step_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.step_id,
|
|
58675
|
+
resource_kind: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.resource_kind,
|
|
58676
|
+
direction: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.direction,
|
|
58677
|
+
target_selector: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_selector,
|
|
58678
|
+
target_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_id,
|
|
58679
|
+
idempotency_key: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.idempotency_key,
|
|
58680
|
+
receipt_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.receipt_id
|
|
58681
|
+
},
|
|
58682
|
+
destination: FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY,
|
|
58683
|
+
lookup_only: true,
|
|
58684
|
+
immutable_receipt: true
|
|
58685
|
+
};
|
|
58686
|
+
|
|
58687
|
+
// src/db/projects.ts
|
|
58428
58688
|
function parseProjectRow(row) {
|
|
58429
58689
|
return {
|
|
58430
58690
|
id: row["id"],
|
|
@@ -60011,7 +60271,10 @@ function getMemoryStats(db) {
|
|
|
60011
60271
|
const byCategory = d.query("SELECT category, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY category").all();
|
|
60012
60272
|
const byStatus = d.query("SELECT status, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY status").all();
|
|
60013
60273
|
const pinnedCount = d.query("SELECT COUNT(*) as c FROM memories WHERE pinned = 1 AND status = 'active'").get().c;
|
|
60014
|
-
const expiredCount = d.query("SELECT COUNT(*) as c FROM memories WHERE status = 'expired'
|
|
60274
|
+
const expiredCount = d.query("SELECT COUNT(*) as c FROM memories WHERE status = 'expired'").get().c;
|
|
60275
|
+
const expiresAtCount = d.query("SELECT COUNT(*) as c FROM memories WHERE expires_at IS NOT NULL").get().c;
|
|
60276
|
+
const nowIso = new Date().toISOString();
|
|
60277
|
+
const expiredDueCount = d.query("SELECT COUNT(*) as c FROM memories WHERE status = 'expired' OR (expires_at IS NOT NULL AND expires_at < ?)").get(nowIso).c;
|
|
60015
60278
|
const stats = {
|
|
60016
60279
|
total,
|
|
60017
60280
|
by_scope: { global: 0, shared: 0, private: 0, working: 0 },
|
|
@@ -60019,7 +60282,9 @@ function getMemoryStats(db) {
|
|
|
60019
60282
|
by_status: { active: 0, archived: 0, expired: 0 },
|
|
60020
60283
|
by_agent: {},
|
|
60021
60284
|
pinned_count: pinnedCount,
|
|
60022
|
-
expired_count: expiredCount
|
|
60285
|
+
expired_count: expiredCount,
|
|
60286
|
+
expires_at_count: expiresAtCount,
|
|
60287
|
+
expired_due_count: expiredDueCount
|
|
60023
60288
|
};
|
|
60024
60289
|
for (const row of byScope)
|
|
60025
60290
|
if (row.scope in stats.by_scope)
|
|
@@ -60053,7 +60318,9 @@ function normalizeStats(data) {
|
|
|
60053
60318
|
by_status: { active: 0, archived: 0, expired: 0, ...data?.by_status ?? {} },
|
|
60054
60319
|
by_agent: data?.by_agent ?? {},
|
|
60055
60320
|
pinned_count: data?.pinned_count ?? 0,
|
|
60056
|
-
expired_count: data?.expired_count ?? 0
|
|
60321
|
+
expired_count: data?.expired_count ?? 0,
|
|
60322
|
+
expires_at_count: data?.expires_at_count ?? 0,
|
|
60323
|
+
expired_due_count: data?.expired_due_count ?? 0
|
|
60057
60324
|
};
|
|
60058
60325
|
}
|
|
60059
60326
|
function getMemoryActivity(filter = {}, db) {
|
|
@@ -60146,19 +60413,31 @@ function getMemoryReport(filter = {}, db) {
|
|
|
60146
60413
|
top_agents: topAgents
|
|
60147
60414
|
};
|
|
60148
60415
|
}
|
|
60149
|
-
function
|
|
60416
|
+
function getStaleMemoriesPage(filter = {}, db) {
|
|
60150
60417
|
const days = Math.min(filter.days || 30, 365);
|
|
60151
60418
|
const limit = filter.limit ?? 20;
|
|
60152
60419
|
const offset = filter.offset ?? 0;
|
|
60153
60420
|
if (!db && isApiMode()) {
|
|
60154
|
-
const q = toQuery({ days, project_id: filter.project_id, agent_id: filter.agent_id, limit, offset });
|
|
60421
|
+
const q = toQuery({ days, project_id: filter.project_id, agent_id: filter.agent_id, pinned: filter.pinned, limit, offset });
|
|
60155
60422
|
const { data } = apiJson("GET", `/memories/stale${q}`);
|
|
60156
|
-
|
|
60423
|
+
const rows2 = data?.memories ?? [];
|
|
60424
|
+
return {
|
|
60425
|
+
rows: rows2,
|
|
60426
|
+
total: data?.total ?? rows2.length,
|
|
60427
|
+
has_more: data?.has_more,
|
|
60428
|
+
next_cursor: data?.next_cursor ?? null
|
|
60429
|
+
};
|
|
60157
60430
|
}
|
|
60158
60431
|
const d = db || getDatabase();
|
|
60159
60432
|
const cutoffDate = new Date(Date.now() - days * 86400000).toISOString();
|
|
60160
|
-
const conds = ["status = 'active'", "(accessed_at IS NULL OR accessed_at < ?)"
|
|
60433
|
+
const conds = ["status = 'active'", "(accessed_at IS NULL OR accessed_at < ?)"];
|
|
60161
60434
|
const params = [cutoffDate];
|
|
60435
|
+
if (filter.pinned !== undefined) {
|
|
60436
|
+
conds.push("pinned = ?");
|
|
60437
|
+
params.push(filter.pinned ? 1 : 0);
|
|
60438
|
+
} else {
|
|
60439
|
+
conds.push("pinned = 0");
|
|
60440
|
+
}
|
|
60162
60441
|
if (filter.project_id) {
|
|
60163
60442
|
conds.push("project_id = ?");
|
|
60164
60443
|
params.push(filter.project_id);
|
|
@@ -60167,13 +60446,25 @@ function getStaleMemories(filter = {}, db) {
|
|
|
60167
60446
|
conds.push("agent_id = ?");
|
|
60168
60447
|
params.push(filter.agent_id);
|
|
60169
60448
|
}
|
|
60170
|
-
|
|
60449
|
+
const where = conds.join(" AND ");
|
|
60450
|
+
const countRow = d.query(`SELECT COUNT(*) AS c FROM memories WHERE ${where}`).get(...params);
|
|
60451
|
+
let sql = `SELECT id, key, value, importance, scope, category, accessed_at, access_count, created_at FROM memories WHERE ${where} ORDER BY COALESCE(accessed_at, created_at) ASC LIMIT ?`;
|
|
60171
60452
|
params.push(limit);
|
|
60172
60453
|
if (offset) {
|
|
60173
60454
|
sql += " OFFSET ?";
|
|
60174
60455
|
params.push(offset);
|
|
60175
60456
|
}
|
|
60176
|
-
|
|
60457
|
+
const rows = d.query(sql).all(...params);
|
|
60458
|
+
const hasMore = rows.length === limit;
|
|
60459
|
+
return {
|
|
60460
|
+
rows,
|
|
60461
|
+
total: countRow?.c ?? 0,
|
|
60462
|
+
has_more: hasMore,
|
|
60463
|
+
next_cursor: hasMore ? offset + rows.length : null
|
|
60464
|
+
};
|
|
60465
|
+
}
|
|
60466
|
+
function getStaleMemories(filter = {}, db) {
|
|
60467
|
+
return getStaleMemoriesPage(filter, db).rows;
|
|
60177
60468
|
}
|
|
60178
60469
|
function getMemoryHealth(filter = {}, db) {
|
|
60179
60470
|
const staleDays = filter.stale_days ?? 30;
|
|
@@ -60344,7 +60635,7 @@ function hasFts5Table2(db) {
|
|
|
60344
60635
|
function buildScopeFilter(opts) {
|
|
60345
60636
|
const conditions = [
|
|
60346
60637
|
"m.status = 'active'",
|
|
60347
|
-
"(m.expires_at IS NULL OR m.expires_at >=
|
|
60638
|
+
"(m.expires_at IS NULL OR m.expires_at >= strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))",
|
|
60348
60639
|
"m.category IN ('preference', 'fact', 'knowledge')"
|
|
60349
60640
|
];
|
|
60350
60641
|
const params = [];
|
|
@@ -60612,7 +60903,7 @@ async function runTemporalAgent(db, query, opts) {
|
|
|
60612
60903
|
const maxResults = opts.max_results ?? 20;
|
|
60613
60904
|
const limit = maxResults * 3;
|
|
60614
60905
|
const conditions = [
|
|
60615
|
-
"(m.expires_at IS NULL OR m.expires_at >=
|
|
60906
|
+
"(m.expires_at IS NULL OR m.expires_at >= strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))"
|
|
60616
60907
|
];
|
|
60617
60908
|
const params = [];
|
|
60618
60909
|
if (opts.project_id) {
|
|
@@ -61330,6 +61621,7 @@ function registerMemoryLifecycleTools(server) {
|
|
|
61330
61621
|
});
|
|
61331
61622
|
server.tool("memory_stale", "Find memories not accessed recently. Useful for cleanup or review.", {
|
|
61332
61623
|
days: exports_external.coerce.number().optional(),
|
|
61624
|
+
pinned: exports_external.boolean().optional().describe("Review stale pinned memories (default excludes pinned)"),
|
|
61333
61625
|
project_id: exports_external.string().optional(),
|
|
61334
61626
|
agent_id: exports_external.string().optional(),
|
|
61335
61627
|
limit: exports_external.coerce.number().optional()
|
|
@@ -61338,6 +61630,7 @@ function registerMemoryLifecycleTools(server) {
|
|
|
61338
61630
|
const days = args.days || 30;
|
|
61339
61631
|
const rows = getStaleMemories({
|
|
61340
61632
|
days,
|
|
61633
|
+
pinned: args.pinned,
|
|
61341
61634
|
project_id: args.project_id,
|
|
61342
61635
|
agent_id: args.agent_id,
|
|
61343
61636
|
limit: args.limit || 20
|
|
@@ -61538,7 +61831,7 @@ function registerMemoryIoTools(server) {
|
|
|
61538
61831
|
const entries = exportV12({ ...args });
|
|
61539
61832
|
return { content: [{ type: "text", text: toJsonl2(entries) }] };
|
|
61540
61833
|
}
|
|
61541
|
-
const memories =
|
|
61834
|
+
const memories = listMemoriesBounded({ ...args }, 1e4).rows;
|
|
61542
61835
|
return { content: [{ type: "text", text: JSON.stringify(memories, null, 2) }] };
|
|
61543
61836
|
} catch (e) {
|
|
61544
61837
|
return { content: [{ type: "text", text: formatError(e) }], isError: true };
|
|
@@ -63014,6 +63307,7 @@ function syncMemoriesTable(source, target, local, direction, currentMachineId) {
|
|
|
63014
63307
|
const countResult = source.get(`SELECT COUNT(*) as cnt FROM "${MEMORY_TABLE}"`);
|
|
63015
63308
|
stat.total_rows = countResult?.cnt ?? 0;
|
|
63016
63309
|
const rows = since ? source.all(`SELECT * FROM "${MEMORY_TABLE}" WHERE updated_at > ?`, since) : source.all(`SELECT * FROM "${MEMORY_TABLE}"`);
|
|
63310
|
+
const erroredRowIds = new Set;
|
|
63017
63311
|
for (const row of rows) {
|
|
63018
63312
|
try {
|
|
63019
63313
|
const sourceMachine = sourceMachineRef(row, currentMachineId);
|
|
@@ -63072,18 +63366,34 @@ function syncMemoriesTable(source, target, local, direction, currentMachineId) {
|
|
|
63072
63366
|
clearMemoryEmbedding(winnerDb, String(winner["id"]));
|
|
63073
63367
|
stat.synced_rows++;
|
|
63074
63368
|
} catch (error) {
|
|
63369
|
+
erroredRowIds.add(String(row["id"] ?? "unknown"));
|
|
63075
63370
|
stat.errors.push(`Memory ${String(row["id"] ?? "unknown")}: ${error instanceof Error ? error.message : String(error)}`);
|
|
63076
63371
|
}
|
|
63077
63372
|
}
|
|
63078
63373
|
if (rows.length === 0) {
|
|
63079
63374
|
stat.skipped_rows = stat.total_rows;
|
|
63080
63375
|
}
|
|
63081
|
-
|
|
63082
|
-
|
|
63083
|
-
|
|
63084
|
-
|
|
63085
|
-
|
|
63086
|
-
|
|
63376
|
+
if (rows.length > 0 && stat.errors.length === 0) {
|
|
63377
|
+
let maxSyncedAt = null;
|
|
63378
|
+
for (const row of rows) {
|
|
63379
|
+
if (erroredRowIds.has(String(row["id"] ?? "unknown"))) {
|
|
63380
|
+
continue;
|
|
63381
|
+
}
|
|
63382
|
+
const value = row["updated_at"];
|
|
63383
|
+
if (typeof value === "string" && (maxSyncedAt === null || value > maxSyncedAt)) {
|
|
63384
|
+
maxSyncedAt = value;
|
|
63385
|
+
}
|
|
63386
|
+
}
|
|
63387
|
+
const nextCursor = maxSyncedAt ?? syncMeta?.last_synced_at ?? null;
|
|
63388
|
+
if (nextCursor !== null) {
|
|
63389
|
+
upsertMemorySyncMeta(local, {
|
|
63390
|
+
table_name: MEMORY_TABLE,
|
|
63391
|
+
direction,
|
|
63392
|
+
last_synced_at: nextCursor,
|
|
63393
|
+
last_synced_row_count: stat.synced_rows
|
|
63394
|
+
});
|
|
63395
|
+
}
|
|
63396
|
+
}
|
|
63087
63397
|
} catch (error) {
|
|
63088
63398
|
stat.errors.push(error instanceof Error ? error.message : String(error));
|
|
63089
63399
|
}
|
|
@@ -63484,7 +63794,7 @@ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive",
|
|
|
63484
63794
|
}
|
|
63485
63795
|
const d = db || getDatabase();
|
|
63486
63796
|
cleanExpiredLocks(d);
|
|
63487
|
-
const ownLock = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND agent_id = ? AND lock_type = ? AND expires_at >
|
|
63797
|
+
const ownLock = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND agent_id = ? AND lock_type = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')").get(resourceType, resourceId, agentId, lockType);
|
|
63488
63798
|
if (ownLock) {
|
|
63489
63799
|
const newExpiry = new Date(Date.now() + ttlSeconds * 1000).toISOString();
|
|
63490
63800
|
d.run("UPDATE resource_locks SET expires_at = ? WHERE id = ?", [
|
|
@@ -63494,7 +63804,7 @@ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive",
|
|
|
63494
63804
|
return parseLockRow({ ...ownLock, expires_at: newExpiry });
|
|
63495
63805
|
}
|
|
63496
63806
|
if (lockType === "exclusive") {
|
|
63497
|
-
const existing = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = 'exclusive' AND agent_id != ? AND expires_at >
|
|
63807
|
+
const existing = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = 'exclusive' AND agent_id != ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')").get(resourceType, resourceId, agentId);
|
|
63498
63808
|
if (existing) {
|
|
63499
63809
|
return null;
|
|
63500
63810
|
}
|
|
@@ -63530,7 +63840,7 @@ function checkLock(resourceType, resourceId, lockType, db) {
|
|
|
63530
63840
|
}
|
|
63531
63841
|
const d = db || getDatabase();
|
|
63532
63842
|
cleanExpiredLocks(d);
|
|
63533
|
-
const query = lockType ? "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at >
|
|
63843
|
+
const query = lockType ? "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')" : "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
|
|
63534
63844
|
const rows = lockType ? d.query(query).all(resourceType, resourceId, lockType) : d.query(query).all(resourceType, resourceId);
|
|
63535
63845
|
return rows.map(parseLockRow);
|
|
63536
63846
|
}
|
|
@@ -63541,14 +63851,14 @@ function listAgentLocks(agentId, db) {
|
|
|
63541
63851
|
}
|
|
63542
63852
|
const d = db || getDatabase();
|
|
63543
63853
|
cleanExpiredLocks(d);
|
|
63544
|
-
const rows = d.query("SELECT * FROM resource_locks WHERE agent_id = ? AND expires_at >
|
|
63854
|
+
const rows = d.query("SELECT * FROM resource_locks WHERE agent_id = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now') ORDER BY locked_at DESC").all(agentId);
|
|
63545
63855
|
return rows.map(parseLockRow);
|
|
63546
63856
|
}
|
|
63547
63857
|
function cleanExpiredLocksWithInfo(db) {
|
|
63548
63858
|
const d = db || getDatabase();
|
|
63549
|
-
const expired = d.query("SELECT id, resource_type, resource_id, agent_id, lock_type FROM resource_locks WHERE expires_at <=
|
|
63859
|
+
const expired = d.query("SELECT id, resource_type, resource_id, agent_id, lock_type FROM resource_locks WHERE expires_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')").all();
|
|
63550
63860
|
if (expired.length > 0) {
|
|
63551
|
-
d.run("DELETE FROM resource_locks WHERE expires_at <=
|
|
63861
|
+
d.run("DELETE FROM resource_locks WHERE expires_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')");
|
|
63552
63862
|
}
|
|
63553
63863
|
return expired;
|
|
63554
63864
|
}
|
|
@@ -63558,7 +63868,7 @@ function cleanExpiredLocks(db) {
|
|
|
63558
63868
|
return data?.cleaned ?? 0;
|
|
63559
63869
|
}
|
|
63560
63870
|
const d = db || getDatabase();
|
|
63561
|
-
const result = d.run("DELETE FROM resource_locks WHERE expires_at <=
|
|
63871
|
+
const result = d.run("DELETE FROM resource_locks WHERE expires_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')");
|
|
63562
63872
|
return result.changes;
|
|
63563
63873
|
}
|
|
63564
63874
|
|
|
@@ -65348,6 +65658,12 @@ function getNextPendingJob(db) {
|
|
|
65348
65658
|
return null;
|
|
65349
65659
|
return parseJobRow(row);
|
|
65350
65660
|
}
|
|
65661
|
+
function claimSessionJob(id, db) {
|
|
65662
|
+
const d = db || getDatabase();
|
|
65663
|
+
const startedAt = now();
|
|
65664
|
+
const result = d.run("UPDATE session_memory_jobs SET status = 'processing', started_at = ? WHERE id = ? AND status = 'pending'", [startedAt, id]);
|
|
65665
|
+
return result.changes;
|
|
65666
|
+
}
|
|
65351
65667
|
|
|
65352
65668
|
// src/lib/session-queue.ts
|
|
65353
65669
|
init_database();
|
|
@@ -65691,7 +66007,11 @@ async function processSessionJob(jobId, db) {
|
|
|
65691
66007
|
return result;
|
|
65692
66008
|
}
|
|
65693
66009
|
try {
|
|
65694
|
-
|
|
66010
|
+
const changes = claimSessionJob(jobId, db);
|
|
66011
|
+
if (changes === 0) {
|
|
66012
|
+
result.errors.push(`Job already claimed or not pending: ${jobId}`);
|
|
66013
|
+
return result;
|
|
66014
|
+
}
|
|
65695
66015
|
} catch (e) {
|
|
65696
66016
|
result.errors.push(`Failed to mark job as processing: ${String(e)}`);
|
|
65697
66017
|
return result;
|