@hasna/mementos 0.14.85 → 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 +419 -188
- package/dist/diagnostics/historical-project-registration-receipt.js +36 -17
- package/dist/index.js +139 -50
- package/dist/mcp/index.js +181 -60
- package/dist/pg-sync-worker.js +7 -5
- package/dist/project-registration.js +108 -36
- package/dist/sdk/index.js +1 -0
- package/dist/server/index.js +384 -280
- package/dist/storage.js +63 -26
- package/hasna.contract.json +5 -4
- package/package.json +4 -3
- 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 -150
- 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 -120
- 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 -193
- 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/diagnostics/historical-project-registration-receipt.d.ts +0 -39
- package/dist/diagnostics/historical-project-registration-receipt.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/historical-receipt.d.ts +0 -38
- package/dist/project-registration/historical-receipt.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 -319
- 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 -978
- 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/memories-page-stub-server.d.ts +0 -2
- package/dist/test-support/memories-page-stub-server.d.ts.map +0 -1
- package/dist/test-support/memories-page-stub.d.ts +0 -28
- package/dist/test-support/memories-page-stub.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)
|
|
@@ -3252,6 +3289,7 @@ __export(exports_memories, {
|
|
|
3252
3289
|
updateMemory: () => updateMemory,
|
|
3253
3290
|
touchMemory: () => touchMemory,
|
|
3254
3291
|
semanticSearch: () => semanticSearch,
|
|
3292
|
+
reservedAgentIdViolation: () => reservedAgentIdViolation,
|
|
3255
3293
|
parseMemoryRow: () => parseMemoryRow,
|
|
3256
3294
|
listMemoryHistoryPage: () => listMemoryHistoryPage,
|
|
3257
3295
|
listMemoryHistory: () => listMemoryHistory,
|
|
@@ -3323,7 +3361,20 @@ function parseMemoryRow(row) {
|
|
|
3323
3361
|
accessed_at: row["accessed_at"] || null
|
|
3324
3362
|
};
|
|
3325
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
|
+
}
|
|
3326
3373
|
function createMemory(input, dedupeMode = "merge", db) {
|
|
3374
|
+
const reservedViolation = reservedAgentIdViolation(input.agent_id);
|
|
3375
|
+
if (reservedViolation) {
|
|
3376
|
+
throw new Error(reservedViolation);
|
|
3377
|
+
}
|
|
3327
3378
|
if (!db && isApiMode()) {
|
|
3328
3379
|
const { status, data } = apiJson("POST", "/memories", { ...input, dedupe: dedupeMode });
|
|
3329
3380
|
if (!data || !data.id) {
|
|
@@ -3373,7 +3424,8 @@ function createMemory(input, dedupeMode = "merge", db) {
|
|
|
3373
3424
|
importance = ?, metadata = ?, expires_at = ?,
|
|
3374
3425
|
when_to_use = ?,
|
|
3375
3426
|
pinned = COALESCE(pinned, 0),
|
|
3376
|
-
version = version + 1, updated_at =
|
|
3427
|
+
version = version + 1, updated_at = ?,
|
|
3428
|
+
updated_by_agent = ?
|
|
3377
3429
|
WHERE id = ?`, [
|
|
3378
3430
|
safeValue,
|
|
3379
3431
|
input.category || "knowledge",
|
|
@@ -3384,6 +3436,7 @@ function createMemory(input, dedupeMode = "merge", db) {
|
|
|
3384
3436
|
expiresAt,
|
|
3385
3437
|
input.when_to_use || null,
|
|
3386
3438
|
timestamp,
|
|
3439
|
+
input.agent_id || null,
|
|
3387
3440
|
existing.id
|
|
3388
3441
|
]);
|
|
3389
3442
|
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [existing.id]);
|
|
@@ -3488,6 +3541,12 @@ function bulkUpsertMemories(memories, db) {
|
|
|
3488
3541
|
errors.push(`Rejected "${key}": ${formatEnumViolation(violation)}`);
|
|
3489
3542
|
continue;
|
|
3490
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
|
+
}
|
|
3491
3550
|
const timestamp = now();
|
|
3492
3551
|
let tags = [];
|
|
3493
3552
|
const rawTags = mem["tags"];
|
|
@@ -3766,6 +3825,11 @@ function listMemoriesPage(filter, db) {
|
|
|
3766
3825
|
agent_id: f.agent_id,
|
|
3767
3826
|
project_id: f.project_id,
|
|
3768
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,
|
|
3769
3833
|
namespace: f.namespace,
|
|
3770
3834
|
as_of: f.as_of,
|
|
3771
3835
|
limit: f.limit,
|
|
@@ -4045,20 +4109,29 @@ function updateMemory(id, input, db) {
|
|
|
4045
4109
|
sets.push("when_to_use = ?");
|
|
4046
4110
|
params.push(input.when_to_use ?? null);
|
|
4047
4111
|
}
|
|
4112
|
+
if (input.updated_by_agent !== undefined) {
|
|
4113
|
+
sets.push("updated_by_agent = ?");
|
|
4114
|
+
params.push(input.updated_by_agent ?? null);
|
|
4115
|
+
}
|
|
4048
4116
|
if (input.tags !== undefined) {
|
|
4049
4117
|
sets.push("tags = ?");
|
|
4050
4118
|
params.push(JSON.stringify(input.tags));
|
|
4051
|
-
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
|
|
4052
|
-
const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
|
|
4053
|
-
for (const tag of input.tags) {
|
|
4054
|
-
insertTag.run(memoryId, tag);
|
|
4055
|
-
}
|
|
4056
4119
|
}
|
|
4057
4120
|
params.push(memoryId);
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
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
|
+
});
|
|
4062
4135
|
const updated = getMemory(memoryId, d);
|
|
4063
4136
|
if (input.value !== undefined) {
|
|
4064
4137
|
try {
|
|
@@ -4229,7 +4302,7 @@ async function semanticSearch(queryText, options = {}, db) {
|
|
|
4229
4302
|
scored.sort((a, b) => b.score - a.score);
|
|
4230
4303
|
return scored.slice(0, limit);
|
|
4231
4304
|
}
|
|
4232
|
-
var RECALL_PROMOTE_THRESHOLD = 3;
|
|
4305
|
+
var RESERVED_AGENT_IDS, RECALL_PROMOTE_THRESHOLD = 3;
|
|
4233
4306
|
var init_memories = __esm(() => {
|
|
4234
4307
|
init_types();
|
|
4235
4308
|
init_database();
|
|
@@ -4239,6 +4312,12 @@ var init_memories = __esm(() => {
|
|
|
4239
4312
|
init_poisoning();
|
|
4240
4313
|
init_entity_memories();
|
|
4241
4314
|
init_api_mode();
|
|
4315
|
+
RESERVED_AGENT_IDS = new Set([
|
|
4316
|
+
"agent-a",
|
|
4317
|
+
"agent-x",
|
|
4318
|
+
"agent-z",
|
|
4319
|
+
"nonexistent-agent"
|
|
4320
|
+
]);
|
|
4242
4321
|
});
|
|
4243
4322
|
|
|
4244
4323
|
// src/db/machines.ts
|
|
@@ -5116,7 +5195,7 @@ function buildFilterConditions(filter) {
|
|
|
5116
5195
|
const conditions = [];
|
|
5117
5196
|
const params = [];
|
|
5118
5197
|
conditions.push("m.status = 'active'");
|
|
5119
|
-
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'))");
|
|
5120
5199
|
if (!filter)
|
|
5121
5200
|
return { conditions, params };
|
|
5122
5201
|
if (filter.scope) {
|
|
@@ -7125,7 +7204,7 @@ async function detectContradiction(newKey, newValue, options = {}, db) {
|
|
|
7125
7204
|
conditions.push("project_id = ?");
|
|
7126
7205
|
params.push(project_id);
|
|
7127
7206
|
}
|
|
7128
|
-
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'))");
|
|
7129
7208
|
const sql = `SELECT * FROM memories WHERE ${conditions.join(" AND ")} ORDER BY importance DESC LIMIT 10`;
|
|
7130
7209
|
const rows = d.query(sql).all(...params);
|
|
7131
7210
|
if (rows.length === 0) {
|
|
@@ -60192,7 +60271,10 @@ function getMemoryStats(db) {
|
|
|
60192
60271
|
const byCategory = d.query("SELECT category, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY category").all();
|
|
60193
60272
|
const byStatus = d.query("SELECT status, COUNT(*) as c FROM memories WHERE status = 'active' GROUP BY status").all();
|
|
60194
60273
|
const pinnedCount = d.query("SELECT COUNT(*) as c FROM memories WHERE pinned = 1 AND status = 'active'").get().c;
|
|
60195
|
-
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;
|
|
60196
60278
|
const stats = {
|
|
60197
60279
|
total,
|
|
60198
60280
|
by_scope: { global: 0, shared: 0, private: 0, working: 0 },
|
|
@@ -60200,7 +60282,9 @@ function getMemoryStats(db) {
|
|
|
60200
60282
|
by_status: { active: 0, archived: 0, expired: 0 },
|
|
60201
60283
|
by_agent: {},
|
|
60202
60284
|
pinned_count: pinnedCount,
|
|
60203
|
-
expired_count: expiredCount
|
|
60285
|
+
expired_count: expiredCount,
|
|
60286
|
+
expires_at_count: expiresAtCount,
|
|
60287
|
+
expired_due_count: expiredDueCount
|
|
60204
60288
|
};
|
|
60205
60289
|
for (const row of byScope)
|
|
60206
60290
|
if (row.scope in stats.by_scope)
|
|
@@ -60234,7 +60318,9 @@ function normalizeStats(data) {
|
|
|
60234
60318
|
by_status: { active: 0, archived: 0, expired: 0, ...data?.by_status ?? {} },
|
|
60235
60319
|
by_agent: data?.by_agent ?? {},
|
|
60236
60320
|
pinned_count: data?.pinned_count ?? 0,
|
|
60237
|
-
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
|
|
60238
60324
|
};
|
|
60239
60325
|
}
|
|
60240
60326
|
function getMemoryActivity(filter = {}, db) {
|
|
@@ -60332,7 +60418,7 @@ function getStaleMemoriesPage(filter = {}, db) {
|
|
|
60332
60418
|
const limit = filter.limit ?? 20;
|
|
60333
60419
|
const offset = filter.offset ?? 0;
|
|
60334
60420
|
if (!db && isApiMode()) {
|
|
60335
|
-
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 });
|
|
60336
60422
|
const { data } = apiJson("GET", `/memories/stale${q}`);
|
|
60337
60423
|
const rows2 = data?.memories ?? [];
|
|
60338
60424
|
return {
|
|
@@ -60344,8 +60430,14 @@ function getStaleMemoriesPage(filter = {}, db) {
|
|
|
60344
60430
|
}
|
|
60345
60431
|
const d = db || getDatabase();
|
|
60346
60432
|
const cutoffDate = new Date(Date.now() - days * 86400000).toISOString();
|
|
60347
|
-
const conds = ["status = 'active'", "(accessed_at IS NULL OR accessed_at < ?)"
|
|
60433
|
+
const conds = ["status = 'active'", "(accessed_at IS NULL OR accessed_at < ?)"];
|
|
60348
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
|
+
}
|
|
60349
60441
|
if (filter.project_id) {
|
|
60350
60442
|
conds.push("project_id = ?");
|
|
60351
60443
|
params.push(filter.project_id);
|
|
@@ -60543,7 +60635,7 @@ function hasFts5Table2(db) {
|
|
|
60543
60635
|
function buildScopeFilter(opts) {
|
|
60544
60636
|
const conditions = [
|
|
60545
60637
|
"m.status = 'active'",
|
|
60546
|
-
"(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'))",
|
|
60547
60639
|
"m.category IN ('preference', 'fact', 'knowledge')"
|
|
60548
60640
|
];
|
|
60549
60641
|
const params = [];
|
|
@@ -60811,7 +60903,7 @@ async function runTemporalAgent(db, query, opts) {
|
|
|
60811
60903
|
const maxResults = opts.max_results ?? 20;
|
|
60812
60904
|
const limit = maxResults * 3;
|
|
60813
60905
|
const conditions = [
|
|
60814
|
-
"(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'))"
|
|
60815
60907
|
];
|
|
60816
60908
|
const params = [];
|
|
60817
60909
|
if (opts.project_id) {
|
|
@@ -61529,6 +61621,7 @@ function registerMemoryLifecycleTools(server) {
|
|
|
61529
61621
|
});
|
|
61530
61622
|
server.tool("memory_stale", "Find memories not accessed recently. Useful for cleanup or review.", {
|
|
61531
61623
|
days: exports_external.coerce.number().optional(),
|
|
61624
|
+
pinned: exports_external.boolean().optional().describe("Review stale pinned memories (default excludes pinned)"),
|
|
61532
61625
|
project_id: exports_external.string().optional(),
|
|
61533
61626
|
agent_id: exports_external.string().optional(),
|
|
61534
61627
|
limit: exports_external.coerce.number().optional()
|
|
@@ -61537,6 +61630,7 @@ function registerMemoryLifecycleTools(server) {
|
|
|
61537
61630
|
const days = args.days || 30;
|
|
61538
61631
|
const rows = getStaleMemories({
|
|
61539
61632
|
days,
|
|
61633
|
+
pinned: args.pinned,
|
|
61540
61634
|
project_id: args.project_id,
|
|
61541
61635
|
agent_id: args.agent_id,
|
|
61542
61636
|
limit: args.limit || 20
|
|
@@ -63213,6 +63307,7 @@ function syncMemoriesTable(source, target, local, direction, currentMachineId) {
|
|
|
63213
63307
|
const countResult = source.get(`SELECT COUNT(*) as cnt FROM "${MEMORY_TABLE}"`);
|
|
63214
63308
|
stat.total_rows = countResult?.cnt ?? 0;
|
|
63215
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;
|
|
63216
63311
|
for (const row of rows) {
|
|
63217
63312
|
try {
|
|
63218
63313
|
const sourceMachine = sourceMachineRef(row, currentMachineId);
|
|
@@ -63271,18 +63366,34 @@ function syncMemoriesTable(source, target, local, direction, currentMachineId) {
|
|
|
63271
63366
|
clearMemoryEmbedding(winnerDb, String(winner["id"]));
|
|
63272
63367
|
stat.synced_rows++;
|
|
63273
63368
|
} catch (error) {
|
|
63369
|
+
erroredRowIds.add(String(row["id"] ?? "unknown"));
|
|
63274
63370
|
stat.errors.push(`Memory ${String(row["id"] ?? "unknown")}: ${error instanceof Error ? error.message : String(error)}`);
|
|
63275
63371
|
}
|
|
63276
63372
|
}
|
|
63277
63373
|
if (rows.length === 0) {
|
|
63278
63374
|
stat.skipped_rows = stat.total_rows;
|
|
63279
63375
|
}
|
|
63280
|
-
|
|
63281
|
-
|
|
63282
|
-
|
|
63283
|
-
|
|
63284
|
-
|
|
63285
|
-
|
|
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
|
+
}
|
|
63286
63397
|
} catch (error) {
|
|
63287
63398
|
stat.errors.push(error instanceof Error ? error.message : String(error));
|
|
63288
63399
|
}
|
|
@@ -63683,7 +63794,7 @@ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive",
|
|
|
63683
63794
|
}
|
|
63684
63795
|
const d = db || getDatabase();
|
|
63685
63796
|
cleanExpiredLocks(d);
|
|
63686
|
-
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);
|
|
63687
63798
|
if (ownLock) {
|
|
63688
63799
|
const newExpiry = new Date(Date.now() + ttlSeconds * 1000).toISOString();
|
|
63689
63800
|
d.run("UPDATE resource_locks SET expires_at = ? WHERE id = ?", [
|
|
@@ -63693,7 +63804,7 @@ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive",
|
|
|
63693
63804
|
return parseLockRow({ ...ownLock, expires_at: newExpiry });
|
|
63694
63805
|
}
|
|
63695
63806
|
if (lockType === "exclusive") {
|
|
63696
|
-
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);
|
|
63697
63808
|
if (existing) {
|
|
63698
63809
|
return null;
|
|
63699
63810
|
}
|
|
@@ -63729,7 +63840,7 @@ function checkLock(resourceType, resourceId, lockType, db) {
|
|
|
63729
63840
|
}
|
|
63730
63841
|
const d = db || getDatabase();
|
|
63731
63842
|
cleanExpiredLocks(d);
|
|
63732
|
-
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')";
|
|
63733
63844
|
const rows = lockType ? d.query(query).all(resourceType, resourceId, lockType) : d.query(query).all(resourceType, resourceId);
|
|
63734
63845
|
return rows.map(parseLockRow);
|
|
63735
63846
|
}
|
|
@@ -63740,14 +63851,14 @@ function listAgentLocks(agentId, db) {
|
|
|
63740
63851
|
}
|
|
63741
63852
|
const d = db || getDatabase();
|
|
63742
63853
|
cleanExpiredLocks(d);
|
|
63743
|
-
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);
|
|
63744
63855
|
return rows.map(parseLockRow);
|
|
63745
63856
|
}
|
|
63746
63857
|
function cleanExpiredLocksWithInfo(db) {
|
|
63747
63858
|
const d = db || getDatabase();
|
|
63748
|
-
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();
|
|
63749
63860
|
if (expired.length > 0) {
|
|
63750
|
-
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')");
|
|
63751
63862
|
}
|
|
63752
63863
|
return expired;
|
|
63753
63864
|
}
|
|
@@ -63757,7 +63868,7 @@ function cleanExpiredLocks(db) {
|
|
|
63757
63868
|
return data?.cleaned ?? 0;
|
|
63758
63869
|
}
|
|
63759
63870
|
const d = db || getDatabase();
|
|
63760
|
-
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')");
|
|
63761
63872
|
return result.changes;
|
|
63762
63873
|
}
|
|
63763
63874
|
|
|
@@ -65547,6 +65658,12 @@ function getNextPendingJob(db) {
|
|
|
65547
65658
|
return null;
|
|
65548
65659
|
return parseJobRow(row);
|
|
65549
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
|
+
}
|
|
65550
65667
|
|
|
65551
65668
|
// src/lib/session-queue.ts
|
|
65552
65669
|
init_database();
|
|
@@ -65890,7 +66007,11 @@ async function processSessionJob(jobId, db) {
|
|
|
65890
66007
|
return result;
|
|
65891
66008
|
}
|
|
65892
66009
|
try {
|
|
65893
|
-
|
|
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
|
+
}
|
|
65894
66015
|
} catch (e) {
|
|
65895
66016
|
result.errors.push(`Failed to mark job as processing: ${String(e)}`);
|
|
65896
66017
|
return result;
|
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
|
});
|