@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/index.js
CHANGED
|
@@ -235,6 +235,7 @@ function translateSql(sql) {
|
|
|
235
235
|
let translated = sql.replace(/\?/g, () => `$${++parameterIndex}`);
|
|
236
236
|
const ISO_FMT = `'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'`;
|
|
237
237
|
translated = translated.replace(/datetime\s*\(\s*'now'\s*\)/gi, `to_char(now() AT TIME ZONE 'UTC', ${ISO_FMT})`);
|
|
238
|
+
translated = translated.replace(/strftime\s*\(\s*'%Y-%m-%dT%H:%M:%fZ'\s*,\s*'now'\s*\)/gi, `to_char(now() AT TIME ZONE 'UTC', ${ISO_FMT})`);
|
|
238
239
|
translated = translated.replace(/datetime\s*\(\s*'now'\s*,\s*'(-?\d+)\s+(minutes?|hours?|days?|seconds?)'\s*\)/gi, (_match, amount, unit) => {
|
|
239
240
|
const parsed = parseInt(String(amount), 10);
|
|
240
241
|
const absolute = Math.abs(parsed);
|
|
@@ -736,16 +737,24 @@ function transferRows(target, table, rows, options) {
|
|
|
736
737
|
const conflictColumn = options.conflictColumn ?? "updated_at";
|
|
737
738
|
let written = 0;
|
|
738
739
|
let skipped = 0;
|
|
740
|
+
let maxSyncedAt = null;
|
|
739
741
|
const errors = [];
|
|
742
|
+
const bumpMaxSyncedAt = (row) => {
|
|
743
|
+
const value = row[conflictColumn];
|
|
744
|
+
if (typeof value === "string" && (maxSyncedAt === null || value > maxSyncedAt)) {
|
|
745
|
+
maxSyncedAt = value;
|
|
746
|
+
}
|
|
747
|
+
};
|
|
740
748
|
if (rows.length === 0) {
|
|
741
|
-
return { written, skipped, errors };
|
|
749
|
+
return { written, skipped, errors, maxSyncedAt };
|
|
742
750
|
}
|
|
743
751
|
const columns = Object.keys(rows[0] ?? {});
|
|
744
752
|
if (!columns.includes(primaryKey)) {
|
|
745
753
|
return {
|
|
746
754
|
written,
|
|
747
755
|
skipped,
|
|
748
|
-
errors: [`Table "${table}" has no "${primaryKey}" column; skipping`]
|
|
756
|
+
errors: [`Table "${table}" has no "${primaryKey}" column; skipping`],
|
|
757
|
+
maxSyncedAt
|
|
749
758
|
};
|
|
750
759
|
}
|
|
751
760
|
const hasConflictColumn = columns.includes(conflictColumn);
|
|
@@ -758,6 +767,7 @@ function transferRows(target, table, rows, options) {
|
|
|
758
767
|
const incomingTime = Date.parse(String(row[conflictColumn]));
|
|
759
768
|
if (Number.isFinite(existingTime) && Number.isFinite(incomingTime) && existingTime >= incomingTime) {
|
|
760
769
|
skipped++;
|
|
770
|
+
bumpMaxSyncedAt(row);
|
|
761
771
|
continue;
|
|
762
772
|
}
|
|
763
773
|
}
|
|
@@ -770,11 +780,12 @@ function transferRows(target, table, rows, options) {
|
|
|
770
780
|
target.run(`INSERT INTO "${table}" (${columnList}) VALUES (${placeholders})`, ...columns.map((column) => row[column]));
|
|
771
781
|
}
|
|
772
782
|
written++;
|
|
783
|
+
bumpMaxSyncedAt(row);
|
|
773
784
|
} catch (error) {
|
|
774
785
|
errors.push(`Row ${String(row[primaryKey] ?? "unknown")}: ${error instanceof Error ? error.message : String(error)}`);
|
|
775
786
|
}
|
|
776
787
|
}
|
|
777
|
-
return { written, skipped, errors };
|
|
788
|
+
return { written, skipped, errors, maxSyncedAt };
|
|
778
789
|
}
|
|
779
790
|
function incrementalSyncPush(local, remote, tables, options = {}) {
|
|
780
791
|
return runIncrementalSync("push", local, remote, local, tables, options);
|
|
@@ -812,22 +823,29 @@ function runIncrementalSync(direction, source, target, metaDb, tables, options)
|
|
|
812
823
|
rows = source.all(`SELECT * FROM "${table}"`);
|
|
813
824
|
stat.first_sync = true;
|
|
814
825
|
}
|
|
826
|
+
let maxSyncedAt = null;
|
|
815
827
|
for (let offset = 0;offset < rows.length; offset += batchSize) {
|
|
816
828
|
const batch = rows.slice(offset, offset + batchSize);
|
|
817
829
|
const result = transferRows(target, table, batch, options);
|
|
818
830
|
stat.synced_rows += result.written;
|
|
819
831
|
stat.skipped_rows += result.skipped;
|
|
820
832
|
stat.errors.push(...result.errors);
|
|
833
|
+
if (result.maxSyncedAt !== null && (maxSyncedAt === null || result.maxSyncedAt > maxSyncedAt)) {
|
|
834
|
+
maxSyncedAt = result.maxSyncedAt;
|
|
835
|
+
}
|
|
821
836
|
}
|
|
822
837
|
if (rows.length === 0) {
|
|
823
838
|
stat.skipped_rows = stat.total_rows;
|
|
824
839
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
840
|
+
const nextCursor = maxSyncedAt ?? meta?.last_synced_at ?? null;
|
|
841
|
+
if (rows.length > 0 && stat.errors.length === 0 && nextCursor !== null) {
|
|
842
|
+
upsertSyncMeta(metaDb, {
|
|
843
|
+
table_name: table,
|
|
844
|
+
last_synced_at: nextCursor,
|
|
845
|
+
last_synced_row_count: stat.synced_rows,
|
|
846
|
+
direction
|
|
847
|
+
});
|
|
848
|
+
}
|
|
831
849
|
} catch (error) {
|
|
832
850
|
stat.errors.push(`Table "${table}": ${error instanceof Error ? error.message : String(error)}`);
|
|
833
851
|
}
|
|
@@ -866,8 +884,13 @@ var init_storage = __esm(() => {
|
|
|
866
884
|
data;
|
|
867
885
|
closed = false;
|
|
868
886
|
lastError = null;
|
|
887
|
+
generation = 0;
|
|
869
888
|
static DATA_BYTES = 128 * 1024 * 1024;
|
|
870
|
-
static
|
|
889
|
+
static queryTimeoutMs() {
|
|
890
|
+
const raw = process.env["MEMENTOS_PGSYNC_QUERY_TIMEOUT_MS"]?.trim();
|
|
891
|
+
const parsed = raw ? Number(raw) : Number.NaN;
|
|
892
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 60000;
|
|
893
|
+
}
|
|
871
894
|
static resolveWorkerPath() {
|
|
872
895
|
const ext = import.meta.url.endsWith(".ts") ? ".ts" : ".js";
|
|
873
896
|
const here = fileURLToPath(new URL(".", import.meta.url));
|
|
@@ -882,12 +905,12 @@ var init_storage = __esm(() => {
|
|
|
882
905
|
}
|
|
883
906
|
return candidates[0];
|
|
884
907
|
}
|
|
885
|
-
constructor(connectionString) {
|
|
886
|
-
const control = new SharedArrayBuffer(
|
|
908
|
+
constructor(connectionString, workerPath) {
|
|
909
|
+
const control = new SharedArrayBuffer(12);
|
|
887
910
|
const dataSab = new SharedArrayBuffer(PgSyncPool.DATA_BYTES);
|
|
888
911
|
this.status = new Int32Array(control);
|
|
889
912
|
this.data = new Uint8Array(dataSab);
|
|
890
|
-
this.worker = new Worker(PgSyncPool.resolveWorkerPath(), {
|
|
913
|
+
this.worker = new Worker(workerPath ?? PgSyncPool.resolveWorkerPath(), {
|
|
891
914
|
workerData: {
|
|
892
915
|
dsn: stripSslParams(connectionString),
|
|
893
916
|
ssl: sslConfigFor(connectionString),
|
|
@@ -905,21 +928,35 @@ var init_storage = __esm(() => {
|
|
|
905
928
|
throw new Error("PgSyncPool is closed");
|
|
906
929
|
if (this.lastError)
|
|
907
930
|
throw this.lastError;
|
|
931
|
+
const timeoutMs = PgSyncPool.queryTimeoutMs();
|
|
932
|
+
const gen = ++this.generation;
|
|
908
933
|
Atomics.store(this.status, 0, 0);
|
|
909
|
-
this.
|
|
910
|
-
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
934
|
+
Atomics.store(this.status, 2, 0);
|
|
935
|
+
this.worker.postMessage({ sql, params, gen });
|
|
936
|
+
const deadline = Date.now() + timeoutMs;
|
|
937
|
+
for (;; ) {
|
|
938
|
+
const remaining = deadline - Date.now();
|
|
939
|
+
const responding = Atomics.load(this.status, 0);
|
|
940
|
+
if (responding === gen) {
|
|
941
|
+
const code = Atomics.load(this.status, 2);
|
|
942
|
+
const len = Atomics.load(this.status, 1);
|
|
943
|
+
const payload = JSON.parse(new TextDecoder().decode(this.data.subarray(0, len)));
|
|
944
|
+
if (code === 2) {
|
|
945
|
+
throw new Error(payload.message ?? "PostgreSQL error");
|
|
946
|
+
}
|
|
947
|
+
return payload;
|
|
948
|
+
}
|
|
949
|
+
if (responding !== 0) {
|
|
950
|
+
Atomics.compareExchange(this.status, 0, responding, 0);
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
if (remaining <= 0) {
|
|
954
|
+
if (this.lastError)
|
|
955
|
+
throw this.lastError;
|
|
956
|
+
throw new Error(`PostgreSQL query timed out after ${timeoutMs}ms`);
|
|
957
|
+
}
|
|
958
|
+
Atomics.wait(this.status, 0, 0, remaining);
|
|
921
959
|
}
|
|
922
|
-
return payload;
|
|
923
960
|
}
|
|
924
961
|
end() {
|
|
925
962
|
if (this.closed)
|
|
@@ -1147,7 +1184,16 @@ x-api-key: ${cfg.apiKey}
|
|
|
1147
1184
|
function apiJson(method, path, body, options) {
|
|
1148
1185
|
const raw = apiRequestRaw(method, path, body);
|
|
1149
1186
|
if (raw.status >= 200 && raw.status < 300) {
|
|
1150
|
-
|
|
1187
|
+
let data;
|
|
1188
|
+
if (raw.body.trim()) {
|
|
1189
|
+
try {
|
|
1190
|
+
data = JSON.parse(raw.body);
|
|
1191
|
+
} catch (e) {
|
|
1192
|
+
throw new ApiRequestError(`mementos cloud ${method} ${path} returned status ${raw.status} with a body that is not valid JSON (${e instanceof Error ? e.message : String(e)}) \u2014 the response is truncated or the server is unhealthy`, raw.status, raw.body.slice(0, 500));
|
|
1193
|
+
}
|
|
1194
|
+
} else {
|
|
1195
|
+
data = undefined;
|
|
1196
|
+
}
|
|
1151
1197
|
return { status: raw.status, data };
|
|
1152
1198
|
}
|
|
1153
1199
|
if (raw.status === 404 && options?.allow404) {
|
|
@@ -16416,7 +16462,7 @@ class JSONSchemaGenerator {
|
|
|
16416
16462
|
if (val === undefined) {
|
|
16417
16463
|
if (this.unrepresentable === "throw") {
|
|
16418
16464
|
throw new Error("Literal `undefined` cannot be represented in JSON Schema");
|
|
16419
|
-
}
|
|
16465
|
+
}
|
|
16420
16466
|
} else if (typeof val === "bigint") {
|
|
16421
16467
|
if (this.unrepresentable === "throw") {
|
|
16422
16468
|
throw new Error("BigInt literals cannot be represented in JSON Schema");
|
|
@@ -38066,7 +38112,7 @@ var require_tracestate_impl = __commonJS((exports) => {
|
|
|
38066
38112
|
const value = listMember.slice(i + 1, part.length);
|
|
38067
38113
|
if ((0, tracestate_validators_1.validateKey)(key) && (0, tracestate_validators_1.validateValue)(value)) {
|
|
38068
38114
|
agg.set(key, value);
|
|
38069
|
-
}
|
|
38115
|
+
}
|
|
38070
38116
|
}
|
|
38071
38117
|
return agg;
|
|
38072
38118
|
}, new Map);
|
|
@@ -51885,7 +51931,26 @@ function parseMemoryRow(row) {
|
|
|
51885
51931
|
accessed_at: row["accessed_at"] || null
|
|
51886
51932
|
};
|
|
51887
51933
|
}
|
|
51934
|
+
var RESERVED_AGENT_IDS = new Set([
|
|
51935
|
+
"agent-a",
|
|
51936
|
+
"agent-x",
|
|
51937
|
+
"agent-z",
|
|
51938
|
+
"nonexistent-agent"
|
|
51939
|
+
]);
|
|
51940
|
+
function reservedAgentIdViolation(agentId) {
|
|
51941
|
+
if (!agentId)
|
|
51942
|
+
return null;
|
|
51943
|
+
const normalized = agentId.trim().toLowerCase();
|
|
51944
|
+
if (RESERVED_AGENT_IDS.has(normalized)) {
|
|
51945
|
+
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.`;
|
|
51946
|
+
}
|
|
51947
|
+
return null;
|
|
51948
|
+
}
|
|
51888
51949
|
function createMemory(input, dedupeMode = "merge", db) {
|
|
51950
|
+
const reservedViolation = reservedAgentIdViolation(input.agent_id);
|
|
51951
|
+
if (reservedViolation) {
|
|
51952
|
+
throw new Error(reservedViolation);
|
|
51953
|
+
}
|
|
51889
51954
|
if (!db && isApiMode()) {
|
|
51890
51955
|
const { status, data } = apiJson("POST", "/memories", { ...input, dedupe: dedupeMode });
|
|
51891
51956
|
if (!data || !data.id) {
|
|
@@ -51935,7 +52000,8 @@ function createMemory(input, dedupeMode = "merge", db) {
|
|
|
51935
52000
|
importance = ?, metadata = ?, expires_at = ?,
|
|
51936
52001
|
when_to_use = ?,
|
|
51937
52002
|
pinned = COALESCE(pinned, 0),
|
|
51938
|
-
version = version + 1, updated_at =
|
|
52003
|
+
version = version + 1, updated_at = ?,
|
|
52004
|
+
updated_by_agent = ?
|
|
51939
52005
|
WHERE id = ?`, [
|
|
51940
52006
|
safeValue,
|
|
51941
52007
|
input.category || "knowledge",
|
|
@@ -51946,6 +52012,7 @@ function createMemory(input, dedupeMode = "merge", db) {
|
|
|
51946
52012
|
expiresAt,
|
|
51947
52013
|
input.when_to_use || null,
|
|
51948
52014
|
timestamp,
|
|
52015
|
+
input.agent_id || null,
|
|
51949
52016
|
existing.id
|
|
51950
52017
|
]);
|
|
51951
52018
|
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [existing.id]);
|
|
@@ -52119,29 +52186,7 @@ function getMemoriesByKey(key, scope, agentId, projectId, db) {
|
|
|
52119
52186
|
const rows = d.query(sql).all(...params);
|
|
52120
52187
|
return rows.map(parseMemoryRow);
|
|
52121
52188
|
}
|
|
52122
|
-
function
|
|
52123
|
-
if (!db && isApiMode()) {
|
|
52124
|
-
const f = filter || {};
|
|
52125
|
-
const q = toQuery({
|
|
52126
|
-
key: f.key,
|
|
52127
|
-
scope: f.scope,
|
|
52128
|
-
category: f.category,
|
|
52129
|
-
status: f.status,
|
|
52130
|
-
tags: f.tags,
|
|
52131
|
-
min_importance: f.min_importance,
|
|
52132
|
-
pinned: f.pinned,
|
|
52133
|
-
agent_id: f.agent_id,
|
|
52134
|
-
project_id: f.project_id,
|
|
52135
|
-
session_id: f.session_id,
|
|
52136
|
-
namespace: f.namespace,
|
|
52137
|
-
as_of: f.as_of,
|
|
52138
|
-
limit: f.limit,
|
|
52139
|
-
offset: f.offset
|
|
52140
|
-
});
|
|
52141
|
-
const { data } = apiJson("GET", `/memories${q}`);
|
|
52142
|
-
return data?.memories ?? [];
|
|
52143
|
-
}
|
|
52144
|
-
const d = db || getDatabase();
|
|
52189
|
+
function buildMemoryListConditions(filter) {
|
|
52145
52190
|
const conditions = [];
|
|
52146
52191
|
const params = [];
|
|
52147
52192
|
if (filter) {
|
|
@@ -52253,21 +52298,104 @@ function listMemories(filter, db) {
|
|
|
52253
52298
|
} else {
|
|
52254
52299
|
conditions.push("status = 'active'");
|
|
52255
52300
|
}
|
|
52301
|
+
return { conditions, params };
|
|
52302
|
+
}
|
|
52303
|
+
function listMemoriesPage(filter, db) {
|
|
52304
|
+
const f = filter || {};
|
|
52305
|
+
if (!db && isApiMode()) {
|
|
52306
|
+
const q = toQuery({
|
|
52307
|
+
key: f.key,
|
|
52308
|
+
scope: f.scope,
|
|
52309
|
+
category: f.category,
|
|
52310
|
+
status: f.status,
|
|
52311
|
+
tags: f.tags,
|
|
52312
|
+
min_importance: f.min_importance,
|
|
52313
|
+
pinned: f.pinned,
|
|
52314
|
+
agent_id: f.agent_id,
|
|
52315
|
+
project_id: f.project_id,
|
|
52316
|
+
session_id: f.session_id,
|
|
52317
|
+
machine_id: f.machine_id,
|
|
52318
|
+
visible_to_machine_id: f.visible_to_machine_id,
|
|
52319
|
+
search: f.search,
|
|
52320
|
+
source: f.source,
|
|
52321
|
+
flag: f.flag,
|
|
52322
|
+
namespace: f.namespace,
|
|
52323
|
+
as_of: f.as_of,
|
|
52324
|
+
limit: f.limit,
|
|
52325
|
+
offset: f.offset
|
|
52326
|
+
});
|
|
52327
|
+
const { data } = apiJson("GET", `/memories${q}`);
|
|
52328
|
+
return {
|
|
52329
|
+
rows: data?.memories ?? [],
|
|
52330
|
+
has_more: data?.has_more,
|
|
52331
|
+
next_cursor: data?.next_cursor ?? null
|
|
52332
|
+
};
|
|
52333
|
+
}
|
|
52334
|
+
const d = db || getDatabase();
|
|
52335
|
+
const { conditions, params } = buildMemoryListConditions(f);
|
|
52256
52336
|
let sql = "SELECT * FROM memories";
|
|
52257
52337
|
if (conditions.length > 0) {
|
|
52258
52338
|
sql += ` WHERE ${conditions.join(" AND ")}`;
|
|
52259
52339
|
}
|
|
52260
52340
|
sql += " ORDER BY importance DESC, created_at DESC";
|
|
52261
|
-
if (
|
|
52341
|
+
if (f.limit) {
|
|
52262
52342
|
sql += " LIMIT ?";
|
|
52263
|
-
params.push(
|
|
52343
|
+
params.push(f.limit);
|
|
52264
52344
|
}
|
|
52265
|
-
if (
|
|
52345
|
+
if (f.offset) {
|
|
52266
52346
|
sql += " OFFSET ?";
|
|
52267
|
-
params.push(
|
|
52347
|
+
params.push(f.offset);
|
|
52268
52348
|
}
|
|
52269
52349
|
const rows = d.query(sql).all(...params);
|
|
52270
|
-
|
|
52350
|
+
const parsed = rows.map(parseMemoryRow);
|
|
52351
|
+
const hasMore = f.limit !== undefined && parsed.length === f.limit;
|
|
52352
|
+
return {
|
|
52353
|
+
rows: parsed,
|
|
52354
|
+
has_more: hasMore,
|
|
52355
|
+
next_cursor: hasMore ? (f.offset ?? 0) + parsed.length : null
|
|
52356
|
+
};
|
|
52357
|
+
}
|
|
52358
|
+
function listMemories(filter, db) {
|
|
52359
|
+
return listMemoriesPage(filter, db).rows;
|
|
52360
|
+
}
|
|
52361
|
+
function listMemoriesBounded(filter = {}, target, db) {
|
|
52362
|
+
const pageSize = 1000;
|
|
52363
|
+
const maxPages = 1000;
|
|
52364
|
+
const want = target === undefined ? undefined : target + 1;
|
|
52365
|
+
const rows = [];
|
|
52366
|
+
const seenCursors = new Set;
|
|
52367
|
+
let cursor = filter.offset ?? 0;
|
|
52368
|
+
let pages = 0;
|
|
52369
|
+
for (;; ) {
|
|
52370
|
+
if (want !== undefined && rows.length >= want)
|
|
52371
|
+
break;
|
|
52372
|
+
if (++pages > maxPages) {
|
|
52373
|
+
throw new Error(`memories list traversal exceeded ${maxPages} pages while collecting rows \u2014 aborting (cursor cycle?)`);
|
|
52374
|
+
}
|
|
52375
|
+
const limit = Math.min(want === undefined ? pageSize : want - rows.length, pageSize);
|
|
52376
|
+
const page = listMemoriesPage({ ...filter, limit, offset: cursor }, db);
|
|
52377
|
+
rows.push(...page.rows);
|
|
52378
|
+
if (page.has_more === false)
|
|
52379
|
+
break;
|
|
52380
|
+
if (page.has_more === undefined && page.rows.length < limit)
|
|
52381
|
+
break;
|
|
52382
|
+
if (page.has_more === true && (page.next_cursor === null || page.next_cursor === undefined)) {
|
|
52383
|
+
throw new Error("memories list page claimed more results without a next cursor \u2014 aborting");
|
|
52384
|
+
}
|
|
52385
|
+
const next = page.next_cursor ?? cursor + page.rows.length;
|
|
52386
|
+
if (seenCursors.has(next)) {
|
|
52387
|
+
throw new Error("memories list traversal repeated a cursor \u2014 aborting");
|
|
52388
|
+
}
|
|
52389
|
+
seenCursors.add(next);
|
|
52390
|
+
cursor = next;
|
|
52391
|
+
}
|
|
52392
|
+
const hasMore = target !== undefined && rows.length > target;
|
|
52393
|
+
const trimmed = hasMore ? rows.slice(0, target) : rows;
|
|
52394
|
+
return {
|
|
52395
|
+
rows: trimmed,
|
|
52396
|
+
has_more: hasMore,
|
|
52397
|
+
next_cursor: hasMore ? (filter.offset ?? 0) + trimmed.length : null
|
|
52398
|
+
};
|
|
52271
52399
|
}
|
|
52272
52400
|
function updateMemory(id, input, db) {
|
|
52273
52401
|
if (!db && isApiMode()) {
|
|
@@ -52333,20 +52461,29 @@ function updateMemory(id, input, db) {
|
|
|
52333
52461
|
sets.push("when_to_use = ?");
|
|
52334
52462
|
params.push(input.when_to_use ?? null);
|
|
52335
52463
|
}
|
|
52464
|
+
if (input.updated_by_agent !== undefined) {
|
|
52465
|
+
sets.push("updated_by_agent = ?");
|
|
52466
|
+
params.push(input.updated_by_agent ?? null);
|
|
52467
|
+
}
|
|
52336
52468
|
if (input.tags !== undefined) {
|
|
52337
52469
|
sets.push("tags = ?");
|
|
52338
52470
|
params.push(JSON.stringify(input.tags));
|
|
52339
|
-
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
|
|
52340
|
-
const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
|
|
52341
|
-
for (const tag of input.tags) {
|
|
52342
|
-
insertTag.run(memoryId, tag);
|
|
52343
|
-
}
|
|
52344
52471
|
}
|
|
52345
52472
|
params.push(memoryId);
|
|
52346
|
-
|
|
52347
|
-
|
|
52348
|
-
|
|
52349
|
-
|
|
52473
|
+
d.transaction(() => {
|
|
52474
|
+
const res = d.run(`UPDATE memories SET ${sets.join(", ")} WHERE id = ?`, params);
|
|
52475
|
+
if (res.changes === 0) {
|
|
52476
|
+
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.`);
|
|
52477
|
+
}
|
|
52478
|
+
if (input.tags !== undefined) {
|
|
52479
|
+
d.run("DELETE FROM memory_tags WHERE memory_id = ?", [memoryId]);
|
|
52480
|
+
const insertTag = d.prepare("INSERT OR IGNORE INTO memory_tags (memory_id, tag) VALUES (?, ?)");
|
|
52481
|
+
for (const tag of input.tags) {
|
|
52482
|
+
insertTag.run(memoryId, tag);
|
|
52483
|
+
}
|
|
52484
|
+
}
|
|
52485
|
+
return res;
|
|
52486
|
+
});
|
|
52350
52487
|
const updated = getMemory(memoryId, d);
|
|
52351
52488
|
if (input.value !== undefined) {
|
|
52352
52489
|
try {
|
|
@@ -52514,6 +52651,90 @@ class MementosProjectRegistrationError extends Error {
|
|
|
52514
52651
|
}
|
|
52515
52652
|
}
|
|
52516
52653
|
|
|
52654
|
+
// src/project-registration/historical-receipt.ts
|
|
52655
|
+
var ROOT_TENANT_ID = "adfd95c7-ee8b-52cb-ae47-4ae65dae3313";
|
|
52656
|
+
var FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION = {
|
|
52657
|
+
authority: "mementos",
|
|
52658
|
+
authority_route: "mementos.project-registration.v1",
|
|
52659
|
+
package_version: "1.0.0-rc.3",
|
|
52660
|
+
authority_id: "mementos",
|
|
52661
|
+
tenant_id: "default",
|
|
52662
|
+
corpus_id: "default",
|
|
52663
|
+
operation_id: "op-cli-register-full",
|
|
52664
|
+
step_id: "mementos_project",
|
|
52665
|
+
resource_kind: "project",
|
|
52666
|
+
direction: "forward",
|
|
52667
|
+
target_selector: "wks_005285827590a93b70e5",
|
|
52668
|
+
target_id: "mm_project_f75606ef14e51fb577a15882ba0ab8ed333b2c29",
|
|
52669
|
+
idempotency_key: "prk_786cdc6babddeae1be8d5078d0f75322d1ea1010ac5d8a50",
|
|
52670
|
+
receipt_id: "mmpr_a647f9908a33bb64bf137f584202590f91b72a33",
|
|
52671
|
+
request_digest: "8eb0e3fee26fdb7edb8a444aeddaaedb79a84a5a36e742ae03616f62b19f5c22",
|
|
52672
|
+
precondition_digest: "0b6c22fcf75d835f9f27308b1a9d40e8902e48a97da370fd56df5acacfcd968e",
|
|
52673
|
+
result_revision: "2026-08-09T13:37:43.068Z",
|
|
52674
|
+
result_digest: "26fb0dd5c5e20909d3653ab0ddd8fa45e5142728e4e66d595e2419f7ed40b036",
|
|
52675
|
+
created_at: "2026-08-09T13:37:43.068Z",
|
|
52676
|
+
identity_digest: "1108dd972c90e4989036fb6ecec7dde10f54641a697bd53cfcd64017f589ace7",
|
|
52677
|
+
target_digest: "72789fcd60668eeb66ee068936d3afa96deadcb007228830c64b6de783b6dcef",
|
|
52678
|
+
operation_digest: "d7e37bfb2c0d28f8c4086c53224cd855d14694f32807b74c102b61a99963f3c0",
|
|
52679
|
+
idempotency_digest: "b56d8ec37efb818759cdd2ee3b58bc1401ac13384c8d64c1813bb5c198b1e376",
|
|
52680
|
+
receipt_digest: "52ce90c5de6817989f107d9d27e06156962a2b9c365e34e16a57aa37886501a2",
|
|
52681
|
+
response_digest: "2fa3ed508f5f192c18753b1205ced996340fdf02f735420d32db897fc239805c"
|
|
52682
|
+
};
|
|
52683
|
+
var FLEET_RESOURCES_HISTORICAL_RECEIPT = {
|
|
52684
|
+
receipt_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.receipt_id,
|
|
52685
|
+
authority: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority,
|
|
52686
|
+
route: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_route,
|
|
52687
|
+
package_version: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.package_version,
|
|
52688
|
+
authority_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_id,
|
|
52689
|
+
tenant_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.tenant_id,
|
|
52690
|
+
corpus_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.corpus_id,
|
|
52691
|
+
operation_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.operation_id,
|
|
52692
|
+
step_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.step_id,
|
|
52693
|
+
resource_kind: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.resource_kind,
|
|
52694
|
+
direction: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.direction,
|
|
52695
|
+
idempotency_key: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.idempotency_key,
|
|
52696
|
+
request_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.request_digest,
|
|
52697
|
+
precondition_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.precondition_digest,
|
|
52698
|
+
outcome: "accepted",
|
|
52699
|
+
reason: null,
|
|
52700
|
+
target_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_id,
|
|
52701
|
+
result_revision: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.result_revision,
|
|
52702
|
+
result_digest: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.result_digest,
|
|
52703
|
+
duplicate_of_receipt_id: null,
|
|
52704
|
+
accepted_receipt_id: null,
|
|
52705
|
+
created_by_operation: true,
|
|
52706
|
+
created_at: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.created_at
|
|
52707
|
+
};
|
|
52708
|
+
var FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY = {
|
|
52709
|
+
authority_id: "mementos",
|
|
52710
|
+
tenant_id: ROOT_TENANT_ID,
|
|
52711
|
+
corpus_id: "mementos:postgresql"
|
|
52712
|
+
};
|
|
52713
|
+
var FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY = {
|
|
52714
|
+
source: {
|
|
52715
|
+
authority: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority,
|
|
52716
|
+
authority_route: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_route,
|
|
52717
|
+
package_version: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.package_version,
|
|
52718
|
+
authority_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.authority_id,
|
|
52719
|
+
tenant_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.tenant_id,
|
|
52720
|
+
corpus_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.corpus_id,
|
|
52721
|
+
operation_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.operation_id,
|
|
52722
|
+
step_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.step_id,
|
|
52723
|
+
resource_kind: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.resource_kind,
|
|
52724
|
+
direction: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.direction,
|
|
52725
|
+
target_selector: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_selector,
|
|
52726
|
+
target_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.target_id,
|
|
52727
|
+
idempotency_key: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.idempotency_key,
|
|
52728
|
+
receipt_id: FLEET_RESOURCES_HISTORICAL_PROJECT_REGISTRATION.receipt_id
|
|
52729
|
+
},
|
|
52730
|
+
destination: FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY,
|
|
52731
|
+
lookup_only: true,
|
|
52732
|
+
immutable_receipt: true
|
|
52733
|
+
};
|
|
52734
|
+
function supportsFleetResourcesHistoricalReceiptLookup(capability) {
|
|
52735
|
+
return capability.authority_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.authority_id && capability.tenant_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.tenant_id && capability.corpus_id === FLEET_RESOURCES_CURRENT_PROJECT_REGISTRATION_IDENTITY.corpus_id;
|
|
52736
|
+
}
|
|
52737
|
+
|
|
52517
52738
|
// src/project-registration/identity.ts
|
|
52518
52739
|
var MEMENTOS_PROJECT_AUTHORITY_ENV = {
|
|
52519
52740
|
authorityId: "MEMENTOS_PROJECT_AUTHORITY_ID",
|
|
@@ -52555,12 +52776,13 @@ function resolveMementosProjectAuthorityIdentity(options = {}) {
|
|
|
52555
52776
|
}
|
|
52556
52777
|
function buildMementosProjectRegistrationCapability(options = {}) {
|
|
52557
52778
|
const identity = resolveMementosProjectAuthorityIdentity(options);
|
|
52558
|
-
|
|
52779
|
+
const capability = {
|
|
52559
52780
|
authority: "mementos",
|
|
52560
52781
|
route: MEMENTOS_PROJECT_REGISTRATION_ROUTE,
|
|
52561
52782
|
package_version: options.packageVersion ?? getMementosPackageVersion(),
|
|
52562
52783
|
...identity,
|
|
52563
52784
|
supported_resources: ["project"],
|
|
52785
|
+
supported_historical_lookup_identities: [],
|
|
52564
52786
|
conditional_create: true,
|
|
52565
52787
|
immutable_receipts: true,
|
|
52566
52788
|
exact_terminal_lookup: true,
|
|
@@ -52579,6 +52801,12 @@ function buildMementosProjectRegistrationCapability(options = {}) {
|
|
|
52579
52801
|
stable_keyset_pagination: true,
|
|
52580
52802
|
explicit_membership_only: true
|
|
52581
52803
|
};
|
|
52804
|
+
if (supportsFleetResourcesHistoricalReceiptLookup(capability)) {
|
|
52805
|
+
capability.supported_historical_lookup_identities = [
|
|
52806
|
+
FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY
|
|
52807
|
+
];
|
|
52808
|
+
}
|
|
52809
|
+
return capability;
|
|
52582
52810
|
}
|
|
52583
52811
|
|
|
52584
52812
|
// src/db/memory-project-link.ts
|
|
@@ -53450,7 +53678,7 @@ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive",
|
|
|
53450
53678
|
}
|
|
53451
53679
|
const d = db || getDatabase();
|
|
53452
53680
|
cleanExpiredLocks(d);
|
|
53453
|
-
const ownLock = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND agent_id = ? AND lock_type = ? AND expires_at >
|
|
53681
|
+
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);
|
|
53454
53682
|
if (ownLock) {
|
|
53455
53683
|
const newExpiry = new Date(Date.now() + ttlSeconds * 1000).toISOString();
|
|
53456
53684
|
d.run("UPDATE resource_locks SET expires_at = ? WHERE id = ?", [
|
|
@@ -53460,7 +53688,7 @@ function acquireLock(agentId, resourceType, resourceId, lockType = "exclusive",
|
|
|
53460
53688
|
return parseLockRow({ ...ownLock, expires_at: newExpiry });
|
|
53461
53689
|
}
|
|
53462
53690
|
if (lockType === "exclusive") {
|
|
53463
|
-
const existing = d.query("SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = 'exclusive' AND agent_id != ? AND expires_at >
|
|
53691
|
+
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);
|
|
53464
53692
|
if (existing) {
|
|
53465
53693
|
return null;
|
|
53466
53694
|
}
|
|
@@ -53510,13 +53738,13 @@ function checkLock(resourceType, resourceId, lockType, db) {
|
|
|
53510
53738
|
}
|
|
53511
53739
|
const d = db || getDatabase();
|
|
53512
53740
|
cleanExpiredLocks(d);
|
|
53513
|
-
const query = lockType ? "SELECT * FROM resource_locks WHERE resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at >
|
|
53741
|
+
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')";
|
|
53514
53742
|
const rows = lockType ? d.query(query).all(resourceType, resourceId, lockType) : d.query(query).all(resourceType, resourceId);
|
|
53515
53743
|
return rows.map(parseLockRow);
|
|
53516
53744
|
}
|
|
53517
53745
|
function agentHoldsLock(agentId, resourceType, resourceId, lockType, db) {
|
|
53518
53746
|
const d = db || getDatabase();
|
|
53519
|
-
const query = lockType ? "SELECT * FROM resource_locks WHERE agent_id = ? AND resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at >
|
|
53747
|
+
const query = lockType ? "SELECT * FROM resource_locks WHERE agent_id = ? AND resource_type = ? AND resource_id = ? AND lock_type = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')" : "SELECT * FROM resource_locks WHERE agent_id = ? AND resource_type = ? AND resource_id = ? AND expires_at > strftime('%Y-%m-%dT%H:%M:%fZ', 'now')";
|
|
53520
53748
|
const row = lockType ? d.query(query).get(agentId, resourceType, resourceId, lockType) : d.query(query).get(agentId, resourceType, resourceId);
|
|
53521
53749
|
return row ? parseLockRow(row) : null;
|
|
53522
53750
|
}
|
|
@@ -53527,7 +53755,7 @@ function listAgentLocks(agentId, db) {
|
|
|
53527
53755
|
}
|
|
53528
53756
|
const d = db || getDatabase();
|
|
53529
53757
|
cleanExpiredLocks(d);
|
|
53530
|
-
const rows = d.query("SELECT * FROM resource_locks WHERE agent_id = ? AND expires_at >
|
|
53758
|
+
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);
|
|
53531
53759
|
return rows.map(parseLockRow);
|
|
53532
53760
|
}
|
|
53533
53761
|
function cleanExpiredLocks(db) {
|
|
@@ -53536,7 +53764,7 @@ function cleanExpiredLocks(db) {
|
|
|
53536
53764
|
return data?.cleaned ?? 0;
|
|
53537
53765
|
}
|
|
53538
53766
|
const d = db || getDatabase();
|
|
53539
|
-
const result = d.run("DELETE FROM resource_locks WHERE expires_at <=
|
|
53767
|
+
const result = d.run("DELETE FROM resource_locks WHERE expires_at <= strftime('%Y-%m-%dT%H:%M:%fZ', 'now')");
|
|
53540
53768
|
return result.changes;
|
|
53541
53769
|
}
|
|
53542
53770
|
// src/lib/memory-lock.ts
|
|
@@ -54730,12 +54958,21 @@ function assertInverseRequest(request, capability) {
|
|
|
54730
54958
|
}
|
|
54731
54959
|
return accepted;
|
|
54732
54960
|
}
|
|
54961
|
+
function matchesCurrentLookupIdentity(request, capability) {
|
|
54962
|
+
return request.authority_route === capability.route && request.package_version === capability.package_version && request.authority_id === capability.authority_id && request.tenant_id === capability.tenant_id && request.corpus_id === capability.corpus_id;
|
|
54963
|
+
}
|
|
54964
|
+
function matchesFleetResourcesHistoricalLookup(request, capability) {
|
|
54965
|
+
if (!supportsFleetResourcesHistoricalReceiptLookup(capability))
|
|
54966
|
+
return false;
|
|
54967
|
+
const source = FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY.source;
|
|
54968
|
+
return request.authority === source.authority && request.authority_route === source.authority_route && request.package_version === source.package_version && request.authority_id === source.authority_id && request.tenant_id === source.tenant_id && request.corpus_id === source.corpus_id && request.operation_id === source.operation_id && request.step_id === source.step_id && request.resource_kind === source.resource_kind && request.direction === source.direction && request.target_selector === source.target_selector && request.target_id === source.target_id && request.idempotency_key === source.idempotency_key;
|
|
54969
|
+
}
|
|
54733
54970
|
function assertLookup(request, capability) {
|
|
54734
54971
|
assertBounds(request);
|
|
54735
54972
|
if (request.max_items !== 1) {
|
|
54736
54973
|
throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_INVALID_BOUNDS", "terminal receipt lookup requires max_items exactly 1");
|
|
54737
54974
|
}
|
|
54738
|
-
if (request.authority !== "mementos" || request.resource_kind !== "project" || request
|
|
54975
|
+
if (request.authority !== "mementos" || request.resource_kind !== "project" || !matchesCurrentLookupIdentity(request, capability) && !matchesFleetResourcesHistoricalLookup(request, capability)) {
|
|
54739
54976
|
throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_CAPABILITY_MISMATCH", "receipt lookup does not match this authority capability identity");
|
|
54740
54977
|
}
|
|
54741
54978
|
requireString(request.operation_id, "operation_id", { pattern: OPERATION_PATTERN });
|
|
@@ -54753,6 +54990,7 @@ function assertLookup(request, capability) {
|
|
|
54753
54990
|
pattern: PROJECT_ID_PATTERN
|
|
54754
54991
|
});
|
|
54755
54992
|
}
|
|
54993
|
+
return matchesCurrentLookupIdentity(request, capability) ? "current" : "fleet_resources_historical";
|
|
54756
54994
|
}
|
|
54757
54995
|
|
|
54758
54996
|
class PackageOwnedMementosProjectRegistrationAuthority {
|
|
@@ -55017,11 +55255,14 @@ class PackageOwnedMementosProjectRegistrationAuthority {
|
|
|
55017
55255
|
}
|
|
55018
55256
|
async lookupReceipt(request) {
|
|
55019
55257
|
const startedAt = Date.now();
|
|
55020
|
-
assertLookup(request, this.capabilityValue);
|
|
55258
|
+
const lookupIdentity = assertLookup(request, this.capabilityValue);
|
|
55021
55259
|
const receipt = getReceiptForLookup(this.db, request);
|
|
55022
55260
|
if (!receipt || request.target_id !== undefined && receipt.target_id !== request.target_id) {
|
|
55023
55261
|
throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_RECEIPT_NOT_FOUND", "exact immutable terminal receipt was not found");
|
|
55024
55262
|
}
|
|
55263
|
+
if (lookupIdentity === "fleet_resources_historical" && (receipt.receipt_id !== FLEET_RESOURCES_HISTORICAL_LOOKUP_IDENTITY.source.receipt_id || canonicalMementosProjectRegistrationJson(publicReceipt(receipt)) !== canonicalMementosProjectRegistrationJson(FLEET_RESOURCES_HISTORICAL_RECEIPT))) {
|
|
55264
|
+
throw new MementosProjectRegistrationError("MEMENTOS_PROJECT_REGISTRATION_RECEIPT_NOT_FOUND", "exact immutable historical terminal receipt was not found");
|
|
55265
|
+
}
|
|
55025
55266
|
return withResponseControl(publicReceipt(receipt), request, startedAt);
|
|
55026
55267
|
}
|
|
55027
55268
|
async compensate(request) {
|
|
@@ -56438,7 +56679,7 @@ function buildFilterConditions(filter) {
|
|
|
56438
56679
|
const conditions = [];
|
|
56439
56680
|
const params = [];
|
|
56440
56681
|
conditions.push("m.status = 'active'");
|
|
56441
|
-
conditions.push("(m.expires_at IS NULL OR m.expires_at >=
|
|
56682
|
+
conditions.push("(m.expires_at IS NULL OR m.expires_at >= strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))");
|
|
56442
56683
|
if (!filter)
|
|
56443
56684
|
return { conditions, params };
|
|
56444
56685
|
if (filter.scope) {
|
|
@@ -57908,6 +58149,7 @@ function syncMemoriesTable(source, target, local, direction, currentMachineId) {
|
|
|
57908
58149
|
const countResult = source.get(`SELECT COUNT(*) as cnt FROM "${MEMORY_TABLE}"`);
|
|
57909
58150
|
stat.total_rows = countResult?.cnt ?? 0;
|
|
57910
58151
|
const rows = since ? source.all(`SELECT * FROM "${MEMORY_TABLE}" WHERE updated_at > ?`, since) : source.all(`SELECT * FROM "${MEMORY_TABLE}"`);
|
|
58152
|
+
const erroredRowIds = new Set;
|
|
57911
58153
|
for (const row of rows) {
|
|
57912
58154
|
try {
|
|
57913
58155
|
const sourceMachine = sourceMachineRef(row, currentMachineId);
|
|
@@ -57966,18 +58208,34 @@ function syncMemoriesTable(source, target, local, direction, currentMachineId) {
|
|
|
57966
58208
|
clearMemoryEmbedding(winnerDb, String(winner["id"]));
|
|
57967
58209
|
stat.synced_rows++;
|
|
57968
58210
|
} catch (error) {
|
|
58211
|
+
erroredRowIds.add(String(row["id"] ?? "unknown"));
|
|
57969
58212
|
stat.errors.push(`Memory ${String(row["id"] ?? "unknown")}: ${error instanceof Error ? error.message : String(error)}`);
|
|
57970
58213
|
}
|
|
57971
58214
|
}
|
|
57972
58215
|
if (rows.length === 0) {
|
|
57973
58216
|
stat.skipped_rows = stat.total_rows;
|
|
57974
58217
|
}
|
|
57975
|
-
|
|
57976
|
-
|
|
57977
|
-
|
|
57978
|
-
|
|
57979
|
-
|
|
57980
|
-
|
|
58218
|
+
if (rows.length > 0 && stat.errors.length === 0) {
|
|
58219
|
+
let maxSyncedAt = null;
|
|
58220
|
+
for (const row of rows) {
|
|
58221
|
+
if (erroredRowIds.has(String(row["id"] ?? "unknown"))) {
|
|
58222
|
+
continue;
|
|
58223
|
+
}
|
|
58224
|
+
const value = row["updated_at"];
|
|
58225
|
+
if (typeof value === "string" && (maxSyncedAt === null || value > maxSyncedAt)) {
|
|
58226
|
+
maxSyncedAt = value;
|
|
58227
|
+
}
|
|
58228
|
+
}
|
|
58229
|
+
const nextCursor = maxSyncedAt ?? syncMeta?.last_synced_at ?? null;
|
|
58230
|
+
if (nextCursor !== null) {
|
|
58231
|
+
upsertMemorySyncMeta(local, {
|
|
58232
|
+
table_name: MEMORY_TABLE,
|
|
58233
|
+
direction,
|
|
58234
|
+
last_synced_at: nextCursor,
|
|
58235
|
+
last_synced_row_count: stat.synced_rows
|
|
58236
|
+
});
|
|
58237
|
+
}
|
|
58238
|
+
}
|
|
57981
58239
|
} catch (error) {
|
|
57982
58240
|
stat.errors.push(error instanceof Error ? error.message : String(error));
|
|
57983
58241
|
}
|
|
@@ -60104,7 +60362,7 @@ ${matched.map((m) => `- ${m.key}: ${m.value.slice(0, 120)}${m.value.length > 120
|
|
|
60104
60362
|
};
|
|
60105
60363
|
}
|
|
60106
60364
|
var gatherTrainingData = async (options = {}) => {
|
|
60107
|
-
const allMemories =
|
|
60365
|
+
const allMemories = listMemoriesBounded({ status: "active" }, undefined).rows;
|
|
60108
60366
|
const filtered = options.since ? allMemories.filter((m) => new Date(m.created_at) >= options.since) : allMemories;
|
|
60109
60367
|
const sorted = filtered.slice().sort((a, b) => b.importance - a.importance);
|
|
60110
60368
|
const fetchSet = options.limit ? sorted.slice(0, options.limit * 3) : sorted;
|
|
@@ -60398,7 +60656,7 @@ function getTaskStats(db, filter2) {
|
|
|
60398
60656
|
const priorityRows = db.query(`SELECT priority, COUNT(*) as c FROM tasks ${where} GROUP BY priority`).all(...params);
|
|
60399
60657
|
for (const row of priorityRows)
|
|
60400
60658
|
byPriority[row.priority] = row.c;
|
|
60401
|
-
const overdue = db.query(`SELECT COUNT(*) as c FROM tasks ${where} AND status != 'completed' AND status != 'cancelled' AND due_at IS NOT NULL AND due_at <
|
|
60659
|
+
const overdue = db.query(`SELECT COUNT(*) as c FROM tasks ${where} AND status != 'completed' AND status != 'cancelled' AND due_at IS NOT NULL AND due_at < strftime('%Y-%m-%dT%H:%M:%fZ', 'now')`).get(...params).c;
|
|
60402
60660
|
return {
|
|
60403
60661
|
total,
|
|
60404
60662
|
by_status: {
|