@aislop-inc/opencode-mem 0.0.0-stage → 2.41.2
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/LICENSE +21 -0
- package/README.md +811 -2
- package/dist/config.d.ts +577 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +1141 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1268 -0
- package/dist/plugin.d.ts +10 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +10 -0
- package/dist/services/ai/ai-provider-factory.d.ts +8 -0
- package/dist/services/ai/ai-provider-factory.d.ts.map +1 -0
- package/dist/services/ai/ai-provider-factory.js +61 -0
- package/dist/services/ai/api-key-placeholder.d.ts +2 -0
- package/dist/services/ai/api-key-placeholder.d.ts.map +1 -0
- package/dist/services/ai/api-key-placeholder.js +14 -0
- package/dist/services/ai/internal-capture-sessions.d.ts +7 -0
- package/dist/services/ai/internal-capture-sessions.d.ts.map +1 -0
- package/dist/services/ai/internal-capture-sessions.js +31 -0
- package/dist/services/ai/opencode-diagnostics.d.ts +8 -0
- package/dist/services/ai/opencode-diagnostics.d.ts.map +1 -0
- package/dist/services/ai/opencode-diagnostics.js +36 -0
- package/dist/services/ai/opencode-host-config.d.ts +11 -0
- package/dist/services/ai/opencode-host-config.d.ts.map +1 -0
- package/dist/services/ai/opencode-host-config.js +51 -0
- package/dist/services/ai/opencode-provider-loader.d.ts +4 -0
- package/dist/services/ai/opencode-provider-loader.d.ts.map +1 -0
- package/dist/services/ai/opencode-provider-loader.js +4 -0
- package/dist/services/ai/opencode-provider.d.ts +154 -0
- package/dist/services/ai/opencode-provider.d.ts.map +1 -0
- package/dist/services/ai/opencode-provider.js +731 -0
- package/dist/services/ai/opencode-sdk-client.d.ts +7 -0
- package/dist/services/ai/opencode-sdk-client.d.ts.map +1 -0
- package/dist/services/ai/opencode-sdk-client.js +38 -0
- package/dist/services/ai/profile-llm-client.d.ts +3 -0
- package/dist/services/ai/profile-llm-client.d.ts.map +1 -0
- package/dist/services/ai/profile-llm-client.js +29 -0
- package/dist/services/ai/provider-config.d.ts +19 -0
- package/dist/services/ai/provider-config.d.ts.map +1 -0
- package/dist/services/ai/provider-config.js +36 -0
- package/dist/services/ai/providers/anthropic-messages.d.ts +35 -0
- package/dist/services/ai/providers/anthropic-messages.d.ts.map +1 -0
- package/dist/services/ai/providers/anthropic-messages.js +220 -0
- package/dist/services/ai/providers/api-route.d.ts +49 -0
- package/dist/services/ai/providers/api-route.d.ts.map +1 -0
- package/dist/services/ai/providers/api-route.js +57 -0
- package/dist/services/ai/providers/atlas-cloud.d.ts +51 -0
- package/dist/services/ai/providers/atlas-cloud.d.ts.map +1 -0
- package/dist/services/ai/providers/atlas-cloud.js +59 -0
- package/dist/services/ai/providers/base-provider.d.ts +33 -0
- package/dist/services/ai/providers/base-provider.d.ts.map +1 -0
- package/dist/services/ai/providers/base-provider.js +24 -0
- package/dist/services/ai/providers/cheaper-inference.d.ts +50 -0
- package/dist/services/ai/providers/cheaper-inference.d.ts.map +1 -0
- package/dist/services/ai/providers/cheaper-inference.js +58 -0
- package/dist/services/ai/providers/cloudgpu.d.ts +52 -0
- package/dist/services/ai/providers/cloudgpu.d.ts.map +1 -0
- package/dist/services/ai/providers/cloudgpu.js +60 -0
- package/dist/services/ai/providers/google-gemini.d.ts +16 -0
- package/dist/services/ai/providers/google-gemini.d.ts.map +1 -0
- package/dist/services/ai/providers/google-gemini.js +228 -0
- package/dist/services/ai/providers/minimax.d.ts +38 -0
- package/dist/services/ai/providers/minimax.d.ts.map +1 -0
- package/dist/services/ai/providers/minimax.js +57 -0
- package/dist/services/ai/providers/openai-chat-completion.d.ts +30 -0
- package/dist/services/ai/providers/openai-chat-completion.d.ts.map +1 -0
- package/dist/services/ai/providers/openai-chat-completion.js +532 -0
- package/dist/services/ai/providers/openai-responses.d.ts +14 -0
- package/dist/services/ai/providers/openai-responses.d.ts.map +1 -0
- package/dist/services/ai/providers/openai-responses.js +182 -0
- package/dist/services/ai/providers/orcarouter.d.ts +52 -0
- package/dist/services/ai/providers/orcarouter.d.ts.map +1 -0
- package/dist/services/ai/providers/orcarouter.js +66 -0
- package/dist/services/ai/providers/runcrate.d.ts +49 -0
- package/dist/services/ai/providers/runcrate.d.ts.map +1 -0
- package/dist/services/ai/providers/runcrate.js +57 -0
- package/dist/services/ai/session/ai-session-manager.d.ts +25 -0
- package/dist/services/ai/session/ai-session-manager.d.ts.map +1 -0
- package/dist/services/ai/session/ai-session-manager.js +180 -0
- package/dist/services/ai/session/session-types.d.ts +43 -0
- package/dist/services/ai/session/session-types.d.ts.map +1 -0
- package/dist/services/ai/session/session-types.js +1 -0
- package/dist/services/ai/tools/tool-schema.d.ts +41 -0
- package/dist/services/ai/tools/tool-schema.d.ts.map +1 -0
- package/dist/services/ai/tools/tool-schema.js +24 -0
- package/dist/services/ai/validators/user-profile-validator.d.ts +13 -0
- package/dist/services/ai/validators/user-profile-validator.d.ts.map +1 -0
- package/dist/services/ai/validators/user-profile-validator.js +114 -0
- package/dist/services/api-handlers.d.ts +277 -0
- package/dist/services/api-handlers.d.ts.map +1 -0
- package/dist/services/api-handlers.js +1740 -0
- package/dist/services/auth-token.d.ts +11 -0
- package/dist/services/auth-token.d.ts.map +1 -0
- package/dist/services/auth-token.js +44 -0
- package/dist/services/auto-capture-config-status.d.ts +15 -0
- package/dist/services/auto-capture-config-status.d.ts.map +1 -0
- package/dist/services/auto-capture-config-status.js +31 -0
- package/dist/services/auto-capture.d.ts +33 -0
- package/dist/services/auto-capture.d.ts.map +1 -0
- package/dist/services/auto-capture.js +906 -0
- package/dist/services/auto-update.d.ts +28 -0
- package/dist/services/auto-update.d.ts.map +1 -0
- package/dist/services/auto-update.js +197 -0
- package/dist/services/capture-evidence-events.d.ts +3 -0
- package/dist/services/capture-evidence-events.d.ts.map +1 -0
- package/dist/services/capture-evidence-events.js +15 -0
- package/dist/services/capture-evidence.d.ts +21 -0
- package/dist/services/capture-evidence.d.ts.map +1 -0
- package/dist/services/capture-evidence.js +168 -0
- package/dist/services/capture-tool-evidence.d.ts +21 -0
- package/dist/services/capture-tool-evidence.d.ts.map +1 -0
- package/dist/services/capture-tool-evidence.js +109 -0
- package/dist/services/cleanup-service.d.ts +26 -0
- package/dist/services/cleanup-service.d.ts.map +1 -0
- package/dist/services/cleanup-service.js +199 -0
- package/dist/services/client.d.ts +167 -0
- package/dist/services/client.d.ts.map +1 -0
- package/dist/services/client.js +535 -0
- package/dist/services/context.d.ts +15 -0
- package/dist/services/context.d.ts.map +1 -0
- package/dist/services/context.js +44 -0
- package/dist/services/cors.d.ts +13 -0
- package/dist/services/cors.d.ts.map +1 -0
- package/dist/services/cors.js +52 -0
- package/dist/services/deduplication-service.d.ts +29 -0
- package/dist/services/deduplication-service.d.ts.map +1 -0
- package/dist/services/deduplication-service.js +113 -0
- package/dist/services/dreaming-lock.d.ts +6 -0
- package/dist/services/dreaming-lock.d.ts.map +1 -0
- package/dist/services/dreaming-lock.js +84 -0
- package/dist/services/dreaming-service.d.ts +96 -0
- package/dist/services/dreaming-service.d.ts.map +1 -0
- package/dist/services/dreaming-service.js +626 -0
- package/dist/services/embedding.d.ts +92 -0
- package/dist/services/embedding.d.ts.map +1 -0
- package/dist/services/embedding.js +467 -0
- package/dist/services/injected-prompt-filter.d.ts +49 -0
- package/dist/services/injected-prompt-filter.d.ts.map +1 -0
- package/dist/services/injected-prompt-filter.js +79 -0
- package/dist/services/jsonc.d.ts +7 -0
- package/dist/services/jsonc.d.ts.map +1 -0
- package/dist/services/jsonc.js +110 -0
- package/dist/services/language-detector.d.ts +3 -0
- package/dist/services/language-detector.d.ts.map +1 -0
- package/dist/services/language-detector.js +33 -0
- package/dist/services/logger.d.ts +15 -0
- package/dist/services/logger.d.ts.map +1 -0
- package/dist/services/logger.js +171 -0
- package/dist/services/markdown/backend.d.ts +35 -0
- package/dist/services/markdown/backend.d.ts.map +1 -0
- package/dist/services/markdown/backend.js +111 -0
- package/dist/services/markdown/document.d.ts +44 -0
- package/dist/services/markdown/document.d.ts.map +1 -0
- package/dist/services/markdown/document.js +159 -0
- package/dist/services/markdown/reconcile.d.ts +26 -0
- package/dist/services/markdown/reconcile.d.ts.map +1 -0
- package/dist/services/markdown/reconcile.js +333 -0
- package/dist/services/markdown/vault.d.ts +32 -0
- package/dist/services/markdown/vault.d.ts.map +1 -0
- package/dist/services/markdown/vault.js +142 -0
- package/dist/services/markdown/watcher.d.ts +22 -0
- package/dist/services/markdown/watcher.d.ts.map +1 -0
- package/dist/services/markdown/watcher.js +131 -0
- package/dist/services/memory-portability-service.d.ts +38 -0
- package/dist/services/memory-portability-service.d.ts.map +1 -0
- package/dist/services/memory-portability-service.js +372 -0
- package/dist/services/memory-provenance.d.ts +16 -0
- package/dist/services/memory-provenance.d.ts.map +1 -0
- package/dist/services/memory-provenance.js +115 -0
- package/dist/services/memory-recall.d.ts +49 -0
- package/dist/services/memory-recall.d.ts.map +1 -0
- package/dist/services/memory-recall.js +196 -0
- package/dist/services/memory-scope.d.ts +17 -0
- package/dist/services/memory-scope.d.ts.map +1 -0
- package/dist/services/memory-scope.js +43 -0
- package/dist/services/migration-service.d.ts +43 -0
- package/dist/services/migration-service.d.ts.map +1 -0
- package/dist/services/migration-service.js +333 -0
- package/dist/services/onnxruntime-resolve.d.ts +25 -0
- package/dist/services/onnxruntime-resolve.d.ts.map +1 -0
- package/dist/services/onnxruntime-resolve.js +176 -0
- package/dist/services/privacy.d.ts +38 -0
- package/dist/services/privacy.d.ts.map +1 -0
- package/dist/services/privacy.js +156 -0
- package/dist/services/request-timeouts.d.ts +4 -0
- package/dist/services/request-timeouts.d.ts.map +1 -0
- package/dist/services/request-timeouts.js +5 -0
- package/dist/services/runtime-require.d.ts +18 -0
- package/dist/services/runtime-require.d.ts.map +1 -0
- package/dist/services/runtime-require.js +75 -0
- package/dist/services/secret-resolver.d.ts +2 -0
- package/dist/services/secret-resolver.d.ts.map +1 -0
- package/dist/services/secret-resolver.js +65 -0
- package/dist/services/shard-inventory-service.d.ts +70 -0
- package/dist/services/shard-inventory-service.d.ts.map +1 -0
- package/dist/services/shard-inventory-service.js +315 -0
- package/dist/services/shard-path-migration-service.d.ts +32 -0
- package/dist/services/shard-path-migration-service.d.ts.map +1 -0
- package/dist/services/shard-path-migration-service.js +386 -0
- package/dist/services/skills/skills-manager.d.ts +39 -0
- package/dist/services/skills/skills-manager.d.ts.map +1 -0
- package/dist/services/skills/skills-manager.js +231 -0
- package/dist/services/skills/types.d.ts +32 -0
- package/dist/services/skills/types.d.ts.map +1 -0
- package/dist/services/skills/types.js +5 -0
- package/dist/services/stats-service.d.ts +71 -0
- package/dist/services/stats-service.d.ts.map +1 -0
- package/dist/services/stats-service.js +288 -0
- package/dist/services/tags.d.ts +30 -0
- package/dist/services/tags.d.ts.map +1 -0
- package/dist/services/tags.js +245 -0
- package/dist/services/transformers-resolve.d.ts +17 -0
- package/dist/services/transformers-resolve.d.ts.map +1 -0
- package/dist/services/transformers-resolve.js +142 -0
- package/dist/services/turso/connection-manager.d.ts +66 -0
- package/dist/services/turso/connection-manager.d.ts.map +1 -0
- package/dist/services/turso/connection-manager.js +408 -0
- package/dist/services/turso/encryption-key.d.ts +17 -0
- package/dist/services/turso/encryption-key.d.ts.map +1 -0
- package/dist/services/turso/encryption-key.js +111 -0
- package/dist/services/turso/encryption-migrator.d.ts +6 -0
- package/dist/services/turso/encryption-migrator.d.ts.map +1 -0
- package/dist/services/turso/encryption-migrator.js +234 -0
- package/dist/services/turso/engine-migrator.d.ts +6 -0
- package/dist/services/turso/engine-migrator.d.ts.map +1 -0
- package/dist/services/turso/engine-migrator.js +318 -0
- package/dist/services/turso/error-classifiers.d.ts +4 -0
- package/dist/services/turso/error-classifiers.d.ts.map +1 -0
- package/dist/services/turso/error-classifiers.js +19 -0
- package/dist/services/turso/legacy-migrator.d.ts +2 -0
- package/dist/services/turso/legacy-migrator.d.ts.map +1 -0
- package/dist/services/turso/legacy-migrator.js +535 -0
- package/dist/services/turso/lifecycle.d.ts +11 -0
- package/dist/services/turso/lifecycle.d.ts.map +1 -0
- package/dist/services/turso/lifecycle.js +32 -0
- package/dist/services/turso/operation-lock.d.ts +26 -0
- package/dist/services/turso/operation-lock.d.ts.map +1 -0
- package/dist/services/turso/operation-lock.js +188 -0
- package/dist/services/turso/plugin-refs.d.ts +13 -0
- package/dist/services/turso/plugin-refs.d.ts.map +1 -0
- package/dist/services/turso/plugin-refs.js +43 -0
- package/dist/services/turso/ready.d.ts +3 -0
- package/dist/services/turso/ready.d.ts.map +1 -0
- package/dist/services/turso/ready.js +32 -0
- package/dist/services/turso/schema-migrations.d.ts +24 -0
- package/dist/services/turso/schema-migrations.d.ts.map +1 -0
- package/dist/services/turso/schema-migrations.js +367 -0
- package/dist/services/turso/shard-manager.d.ts +41 -0
- package/dist/services/turso/shard-manager.d.ts.map +1 -0
- package/dist/services/turso/shard-manager.js +419 -0
- package/dist/services/turso/sqlite-handle-release.d.ts +31 -0
- package/dist/services/turso/sqlite-handle-release.d.ts.map +1 -0
- package/dist/services/turso/sqlite-handle-release.js +101 -0
- package/dist/services/turso/turso-db.d.ts +61 -0
- package/dist/services/turso/turso-db.d.ts.map +1 -0
- package/dist/services/turso/turso-db.js +214 -0
- package/dist/services/turso/types.d.ts +52 -0
- package/dist/services/turso/types.d.ts.map +1 -0
- package/dist/services/turso/types.js +1 -0
- package/dist/services/turso/vector-search.d.ts +63 -0
- package/dist/services/turso/vector-search.d.ts.map +1 -0
- package/dist/services/turso/vector-search.js +510 -0
- package/dist/services/turso/vector-utils.d.ts +16 -0
- package/dist/services/turso/vector-utils.d.ts.map +1 -0
- package/dist/services/turso/vector-utils.js +98 -0
- package/dist/services/turso/wal-index-recovery.d.ts +51 -0
- package/dist/services/turso/wal-index-recovery.d.ts.map +1 -0
- package/dist/services/turso/wal-index-recovery.js +248 -0
- package/dist/services/update-on-capture.d.ts +77 -0
- package/dist/services/update-on-capture.d.ts.map +1 -0
- package/dist/services/update-on-capture.js +116 -0
- package/dist/services/user-memory-learning.d.ts +137 -0
- package/dist/services/user-memory-learning.d.ts.map +1 -0
- package/dist/services/user-memory-learning.js +787 -0
- package/dist/services/user-profile/ai-cleanup.d.ts +59 -0
- package/dist/services/user-profile/ai-cleanup.d.ts.map +1 -0
- package/dist/services/user-profile/ai-cleanup.js +488 -0
- package/dist/services/user-profile/learning-lock.d.ts +41 -0
- package/dist/services/user-profile/learning-lock.d.ts.map +1 -0
- package/dist/services/user-profile/learning-lock.js +619 -0
- package/dist/services/user-profile/profile-context.d.ts +2 -0
- package/dist/services/user-profile/profile-context.d.ts.map +1 -0
- package/dist/services/user-profile/profile-context.js +105 -0
- package/dist/services/user-profile/profile-utils.d.ts +17 -0
- package/dist/services/user-profile/profile-utils.d.ts.map +1 -0
- package/dist/services/user-profile/profile-utils.js +77 -0
- package/dist/services/user-profile/types.d.ts +93 -0
- package/dist/services/user-profile/types.d.ts.map +1 -0
- package/dist/services/user-profile/types.js +1 -0
- package/dist/services/user-profile/user-profile-manager.d.ts +106 -0
- package/dist/services/user-profile/user-profile-manager.d.ts.map +1 -0
- package/dist/services/user-profile/user-profile-manager.js +1793 -0
- package/dist/services/user-prompt/user-prompt-manager.d.ts +64 -0
- package/dist/services/user-prompt/user-prompt-manager.d.ts.map +1 -0
- package/dist/services/user-prompt/user-prompt-manager.js +428 -0
- package/dist/services/web-api-auth.d.ts +4 -0
- package/dist/services/web-api-auth.d.ts.map +1 -0
- package/dist/services/web-api-auth.js +24 -0
- package/dist/services/web-auth.d.ts +47 -0
- package/dist/services/web-auth.d.ts.map +1 -0
- package/dist/services/web-auth.js +105 -0
- package/dist/services/web-server.d.ts +58 -0
- package/dist/services/web-server.d.ts.map +1 -0
- package/dist/services/web-server.js +774 -0
- package/dist/shared/api/index.d.ts +5 -0
- package/dist/shared/api/index.d.ts.map +1 -0
- package/dist/shared/api/index.js +2 -0
- package/dist/shared/api/portability-schemas.d.ts +57 -0
- package/dist/shared/api/portability-schemas.d.ts.map +1 -0
- package/dist/shared/api/portability-schemas.js +39 -0
- package/dist/shared/api/schemas.d.ts +296 -0
- package/dist/shared/api/schemas.d.ts.map +1 -0
- package/dist/shared/api/schemas.js +134 -0
- package/dist/shared/api/types.d.ts +29 -0
- package/dist/shared/api/types.d.ts.map +1 -0
- package/dist/shared/api/types.js +1 -0
- package/dist/tui.d.ts +10 -0
- package/dist/tui.d.ts.map +1 -0
- package/dist/tui.js +17 -0
- package/dist/types/index.d.ts +19 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/context-limit.d.ts +11 -0
- package/dist/utils/context-limit.d.ts.map +1 -0
- package/dist/utils/context-limit.js +43 -0
- package/dist/utils/math.d.ts +8 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +48 -0
- package/dist/utils/profile.d.ts +3 -0
- package/dist/utils/profile.d.ts.map +1 -0
- package/dist/utils/profile.js +15 -0
- package/dist/v2/adapter.d.ts +3 -0
- package/dist/v2/adapter.d.ts.map +1 -0
- package/dist/v2/adapter.js +217 -0
- package/dist/v2/legacy-client.d.ts +22 -0
- package/dist/v2/legacy-client.d.ts.map +1 -0
- package/dist/v2/legacy-client.js +410 -0
- package/dist/v2/plugin.d.ts +4 -0
- package/dist/v2/plugin.d.ts.map +1 -0
- package/dist/v2/plugin.js +34 -0
- package/dist/v2/toast-rpc.d.ts +43 -0
- package/dist/v2/toast-rpc.d.ts.map +1 -0
- package/dist/v2/toast-rpc.js +26 -0
- package/dist/web/accent-preview.html +444 -0
- package/dist/web/assets/index-mTgxOb5l.css +2 -0
- package/dist/web/assets/index-ysje17yK.js +109 -0
- package/dist/web/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
- package/dist/web/favicon.ico +0 -0
- package/dist/web/favicon.svg +11 -0
- package/dist/web/index.html +29 -0
- package/dist/web/opencode-mem-icon.png +0 -0
- package/package.json +122 -4
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { basename, join, normalize, resolve } from "node:path";
|
|
2
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
3
|
+
import { CONFIG } from "../config.js";
|
|
4
|
+
import { assertSafeScopeHash, isValidScopeHash } from "./memory-scope.js";
|
|
5
|
+
import { getProjectTagInfo } from "./tags.js";
|
|
6
|
+
import { ensureTursoReady } from "./turso/ready.js";
|
|
7
|
+
import { tursoShardManager } from "./turso/shard-manager.js";
|
|
8
|
+
import { tursoConnectionManager } from "./turso/connection-manager.js";
|
|
9
|
+
import { tursoVectorSearch } from "./turso/vector-search.js";
|
|
10
|
+
const SHARD_FILENAME_RE = /^(user|project)_([a-f0-9]{16})_shard_(\d+)\.db$/;
|
|
11
|
+
export function normalizeProjectPath(path) {
|
|
12
|
+
const normalized = normalize(resolve(path)).replace(/\\/g, "/");
|
|
13
|
+
if (normalized.length > 1 && normalized.endsWith("/")) {
|
|
14
|
+
return normalized.replace(/\/+$/, "");
|
|
15
|
+
}
|
|
16
|
+
return normalized;
|
|
17
|
+
}
|
|
18
|
+
function listProjectShardDbPaths() {
|
|
19
|
+
const dir = join(CONFIG.storagePath, "projects");
|
|
20
|
+
if (!existsSync(dir))
|
|
21
|
+
return [];
|
|
22
|
+
return readdirSync(dir)
|
|
23
|
+
.filter((file) => file.endsWith(".db") && !file.includes(".bak") && !file.includes(".tmp"))
|
|
24
|
+
.map((file) => join(dir, file));
|
|
25
|
+
}
|
|
26
|
+
async function inspectShardContent(dbPath) {
|
|
27
|
+
if (!existsSync(dbPath)) {
|
|
28
|
+
return {
|
|
29
|
+
memoryCount: 0,
|
|
30
|
+
pathCandidates: [],
|
|
31
|
+
projectName: null,
|
|
32
|
+
gitRepoUrl: null,
|
|
33
|
+
containerTag: null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const db = await tursoConnectionManager.getConnection(dbPath);
|
|
37
|
+
const memoryCount = await tursoVectorSearch.countAllVectors(db);
|
|
38
|
+
const pathCounts = await tursoVectorSearch.getProjectPathCounts(db);
|
|
39
|
+
const tags = await tursoVectorSearch.getDistinctTags(db);
|
|
40
|
+
const first = tags[0];
|
|
41
|
+
// Collapse path+tag rows into path totals while keeping a representative tag.
|
|
42
|
+
const byPath = new Map();
|
|
43
|
+
for (const row of pathCounts) {
|
|
44
|
+
const key = normalizeProjectPath(row.projectPath);
|
|
45
|
+
const existing = byPath.get(key);
|
|
46
|
+
if (existing) {
|
|
47
|
+
existing.count += row.count;
|
|
48
|
+
if (!existing.containerTag && row.containerTag) {
|
|
49
|
+
existing.containerTag = row.containerTag;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
byPath.set(key, {
|
|
54
|
+
path: key,
|
|
55
|
+
count: row.count,
|
|
56
|
+
containerTag: row.containerTag,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const pathCandidates = [...byPath.values()].sort((a, b) => b.count - a.count || a.path.localeCompare(b.path));
|
|
61
|
+
return {
|
|
62
|
+
memoryCount,
|
|
63
|
+
pathCandidates,
|
|
64
|
+
projectName: first?.project_name ? String(first.project_name) : null,
|
|
65
|
+
gitRepoUrl: first?.git_repo_url ? String(first.git_repo_url) : null,
|
|
66
|
+
containerTag: pathCandidates[0]?.containerTag ??
|
|
67
|
+
(first?.container_tag ? String(first.container_tag) : null),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function deriveStatus(input) {
|
|
71
|
+
if (input.pathCandidates.length > 1) {
|
|
72
|
+
return "ambiguous";
|
|
73
|
+
}
|
|
74
|
+
if (input.allFilesMissing) {
|
|
75
|
+
return "missing-file";
|
|
76
|
+
}
|
|
77
|
+
if (input.memoryCount === 0) {
|
|
78
|
+
return "empty";
|
|
79
|
+
}
|
|
80
|
+
if (input.matchesCurrentProject) {
|
|
81
|
+
return "current";
|
|
82
|
+
}
|
|
83
|
+
if (input.projectPath && !input.pathExists) {
|
|
84
|
+
return "orphaned";
|
|
85
|
+
}
|
|
86
|
+
if (input.projectPath && input.pathExists) {
|
|
87
|
+
return "linked";
|
|
88
|
+
}
|
|
89
|
+
if (input.anyFileMissing) {
|
|
90
|
+
return "missing-file";
|
|
91
|
+
}
|
|
92
|
+
return "orphaned";
|
|
93
|
+
}
|
|
94
|
+
export class ShardInventoryService {
|
|
95
|
+
async listShards(currentDirectory) {
|
|
96
|
+
await ensureTursoReady();
|
|
97
|
+
const current = getProjectTagInfo(currentDirectory);
|
|
98
|
+
const currentHash = current.tag.split("_").pop();
|
|
99
|
+
assertSafeScopeHash(currentHash);
|
|
100
|
+
const registered = await tursoShardManager.getAllShards("project", "");
|
|
101
|
+
const byHash = new Map();
|
|
102
|
+
for (const shard of registered) {
|
|
103
|
+
const entry = byHash.get(shard.scopeHash) ?? { registered: [], filePaths: new Set() };
|
|
104
|
+
entry.registered.push(shard);
|
|
105
|
+
entry.filePaths.add(shard.dbPath);
|
|
106
|
+
byHash.set(shard.scopeHash, entry);
|
|
107
|
+
}
|
|
108
|
+
for (const path of listProjectShardDbPaths()) {
|
|
109
|
+
const match = SHARD_FILENAME_RE.exec(basename(path));
|
|
110
|
+
if (!match || match[1] !== "project")
|
|
111
|
+
continue;
|
|
112
|
+
const scopeHash = match[2];
|
|
113
|
+
const entry = byHash.get(scopeHash) ?? { registered: [], filePaths: new Set() };
|
|
114
|
+
entry.filePaths.add(path);
|
|
115
|
+
byHash.set(scopeHash, entry);
|
|
116
|
+
}
|
|
117
|
+
const groups = [];
|
|
118
|
+
for (const [scopeHash, entry] of byHash) {
|
|
119
|
+
const shardIndexes = new Set();
|
|
120
|
+
for (const shard of entry.registered) {
|
|
121
|
+
shardIndexes.add(shard.shardIndex);
|
|
122
|
+
}
|
|
123
|
+
for (const path of entry.filePaths) {
|
|
124
|
+
const match = SHARD_FILENAME_RE.exec(basename(path));
|
|
125
|
+
if (match)
|
|
126
|
+
shardIndexes.add(Number(match[3]));
|
|
127
|
+
}
|
|
128
|
+
const descriptors = [];
|
|
129
|
+
let memoryCount = 0;
|
|
130
|
+
const pathCountMap = new Map();
|
|
131
|
+
let projectName = null;
|
|
132
|
+
let gitRepoUrl = null;
|
|
133
|
+
let containerTag = null;
|
|
134
|
+
for (const shardIndex of [...shardIndexes].sort((a, b) => a - b)) {
|
|
135
|
+
const registeredShard = entry.registered.find((shard) => shard.shardIndex === shardIndex) ?? null;
|
|
136
|
+
const dbPath = registeredShard?.dbPath ??
|
|
137
|
+
tursoShardManager.getShardPath("project", scopeHash, shardIndex);
|
|
138
|
+
const fileExists = existsSync(dbPath);
|
|
139
|
+
const content = await inspectShardContent(dbPath);
|
|
140
|
+
memoryCount += content.memoryCount;
|
|
141
|
+
for (const candidate of content.pathCandidates) {
|
|
142
|
+
pathCountMap.set(candidate.path, (pathCountMap.get(candidate.path) ?? 0) + candidate.count);
|
|
143
|
+
if (!containerTag && candidate.containerTag) {
|
|
144
|
+
containerTag = candidate.containerTag;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!projectName && content.projectName)
|
|
148
|
+
projectName = content.projectName;
|
|
149
|
+
if (!gitRepoUrl && content.gitRepoUrl)
|
|
150
|
+
gitRepoUrl = content.gitRepoUrl;
|
|
151
|
+
if (!containerTag && content.containerTag)
|
|
152
|
+
containerTag = content.containerTag;
|
|
153
|
+
descriptors.push({
|
|
154
|
+
shardId: registeredShard?.id ?? null,
|
|
155
|
+
shardIndex,
|
|
156
|
+
dbPath,
|
|
157
|
+
fileName: basename(dbPath),
|
|
158
|
+
isActive: registeredShard?.isActive ?? shardIndex === Math.max(...shardIndexes),
|
|
159
|
+
vectorCount: registeredShard?.vectorCount ?? content.memoryCount,
|
|
160
|
+
memoryCount: content.memoryCount,
|
|
161
|
+
fileExists,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const projectPathCandidates = [...pathCountMap.entries()]
|
|
165
|
+
.map(([path, count]) => ({ path, count }))
|
|
166
|
+
.sort((a, b) => b.count - a.count || a.path.localeCompare(b.path));
|
|
167
|
+
const projectPath = projectPathCandidates[0]?.path ?? null;
|
|
168
|
+
const pathExists = projectPath ? existsSync(projectPath) : false;
|
|
169
|
+
const matchesCurrentProject = scopeHash === currentHash;
|
|
170
|
+
const anyFileMissing = descriptors.some((shard) => !shard.fileExists);
|
|
171
|
+
const allFilesMissing = descriptors.length > 0 && descriptors.every((shard) => !shard.fileExists);
|
|
172
|
+
groups.push({
|
|
173
|
+
scope: "project",
|
|
174
|
+
scopeHash,
|
|
175
|
+
shardIndices: descriptors.map((shard) => shard.shardIndex),
|
|
176
|
+
shards: descriptors,
|
|
177
|
+
memoryCount,
|
|
178
|
+
containerTag: containerTag ?? `${CONFIG.containerTagPrefix}_project_${scopeHash}`,
|
|
179
|
+
projectPath,
|
|
180
|
+
projectPathCandidates,
|
|
181
|
+
projectName,
|
|
182
|
+
gitRepoUrl,
|
|
183
|
+
pathExists,
|
|
184
|
+
status: deriveStatus({
|
|
185
|
+
matchesCurrentProject,
|
|
186
|
+
memoryCount,
|
|
187
|
+
pathExists,
|
|
188
|
+
projectPath,
|
|
189
|
+
pathCandidates: projectPathCandidates,
|
|
190
|
+
anyFileMissing,
|
|
191
|
+
allFilesMissing,
|
|
192
|
+
}),
|
|
193
|
+
matchesCurrentProject,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
groups.sort((a, b) => {
|
|
197
|
+
if (a.matchesCurrentProject !== b.matchesCurrentProject) {
|
|
198
|
+
return a.matchesCurrentProject ? -1 : 1;
|
|
199
|
+
}
|
|
200
|
+
return b.memoryCount - a.memoryCount || a.scopeHash.localeCompare(b.scopeHash);
|
|
201
|
+
});
|
|
202
|
+
const summary = {
|
|
203
|
+
total: groups.length,
|
|
204
|
+
current: groups.filter((g) => g.status === "current").length,
|
|
205
|
+
linked: groups.filter((g) => g.status === "linked").length,
|
|
206
|
+
orphaned: groups.filter((g) => g.status === "orphaned").length,
|
|
207
|
+
missingFile: groups.filter((g) => g.status === "missing-file").length,
|
|
208
|
+
empty: groups.filter((g) => g.status === "empty").length,
|
|
209
|
+
ambiguous: groups.filter((g) => g.status === "ambiguous").length,
|
|
210
|
+
};
|
|
211
|
+
return {
|
|
212
|
+
success: true,
|
|
213
|
+
storagePath: CONFIG.storagePath,
|
|
214
|
+
currentProject: {
|
|
215
|
+
tag: current.tag,
|
|
216
|
+
scopeHash: currentHash,
|
|
217
|
+
projectPath: current.projectPath || getProjectTagInfo(currentDirectory).displayName,
|
|
218
|
+
},
|
|
219
|
+
shards: groups,
|
|
220
|
+
summary,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
async resolveMigrationSource(currentDirectory, options) {
|
|
224
|
+
const inventory = await this.listShards(currentDirectory);
|
|
225
|
+
const { fromHash, fromPath } = options;
|
|
226
|
+
if (fromHash) {
|
|
227
|
+
if (!isValidScopeHash(fromHash)) {
|
|
228
|
+
return {
|
|
229
|
+
success: false,
|
|
230
|
+
error: `Invalid fromHash: expected 16 lowercase hex characters, got "${fromHash}"`,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
const group = inventory.shards.find((shard) => shard.scopeHash === fromHash);
|
|
234
|
+
if (!group) {
|
|
235
|
+
return {
|
|
236
|
+
success: false,
|
|
237
|
+
error: `No project shards found for hash ${fromHash}. Run memory list-shards to inspect available shards.`,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (group.memoryCount === 0) {
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
error: `Shard hash ${fromHash} exists but contains no memories.`,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
success: true,
|
|
248
|
+
source: {
|
|
249
|
+
scopeHash: fromHash,
|
|
250
|
+
matchedBy: "fromHash",
|
|
251
|
+
group,
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
if (!fromPath || !fromPath.trim()) {
|
|
256
|
+
return {
|
|
257
|
+
success: false,
|
|
258
|
+
error: "fromPath or fromHash is required for migrate",
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const normalizedFrom = normalizeProjectPath(fromPath);
|
|
262
|
+
const pathMatches = inventory.shards.filter((group) => group.projectPathCandidates.some((candidate) => candidate.path === normalizedFrom));
|
|
263
|
+
if (pathMatches.length === 1) {
|
|
264
|
+
const group = pathMatches[0];
|
|
265
|
+
if (group.memoryCount === 0) {
|
|
266
|
+
return {
|
|
267
|
+
success: false,
|
|
268
|
+
error: `Matched project path ${normalizedFrom} but the shard contains no memories.`,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
success: true,
|
|
273
|
+
source: {
|
|
274
|
+
scopeHash: group.scopeHash,
|
|
275
|
+
matchedBy: "storedProjectPath",
|
|
276
|
+
group,
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (pathMatches.length > 1) {
|
|
281
|
+
return {
|
|
282
|
+
success: false,
|
|
283
|
+
error: `Ambiguous fromPath match for ${normalizedFrom}. Use fromHash with memory list-shards to select one shard.`,
|
|
284
|
+
candidates: pathMatches,
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// If the old directory still exists, resolve its live project identity.
|
|
288
|
+
if (existsSync(normalizedFrom)) {
|
|
289
|
+
try {
|
|
290
|
+
const live = getProjectTagInfo(normalizedFrom);
|
|
291
|
+
const liveHash = live.tag.split("_").pop();
|
|
292
|
+
const group = inventory.shards.find((shard) => shard.scopeHash === liveHash);
|
|
293
|
+
if (group && group.memoryCount > 0) {
|
|
294
|
+
return {
|
|
295
|
+
success: true,
|
|
296
|
+
source: {
|
|
297
|
+
scopeHash: liveHash,
|
|
298
|
+
matchedBy: "liveProjectIdentity",
|
|
299
|
+
group,
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
// Fall through to the generic missing-source error.
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
success: false,
|
|
310
|
+
error: `No shard found for fromPath ${normalizedFrom}. ` +
|
|
311
|
+
`If the old directory no longer exists, run memory list-shards and migrate with fromHash.`,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
export const shardInventoryService = new ShardInventoryService();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ResolveMigrationSourceOptions, type ResolvedMigrationSource } from "./shard-inventory-service.js";
|
|
2
|
+
export interface PathMigrationOptions extends ResolveMigrationSourceOptions {
|
|
3
|
+
currentDirectory: string;
|
|
4
|
+
dryRun?: boolean;
|
|
5
|
+
allowLinkedSource?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface PathMigrationAction {
|
|
8
|
+
type: "rename" | "archive-empty-target" | "update-memories" | "update-prompts" | "reassign-metadata";
|
|
9
|
+
detail: string;
|
|
10
|
+
}
|
|
11
|
+
export interface PathMigrationResult {
|
|
12
|
+
success: boolean;
|
|
13
|
+
dryRun: boolean;
|
|
14
|
+
migratedShards?: number;
|
|
15
|
+
migratedMemories?: number;
|
|
16
|
+
oldPath?: string | null;
|
|
17
|
+
newPath?: string;
|
|
18
|
+
oldHash?: string;
|
|
19
|
+
newHash?: string;
|
|
20
|
+
matchedBy?: ResolvedMigrationSource["matchedBy"];
|
|
21
|
+
actions?: PathMigrationAction[];
|
|
22
|
+
error?: string;
|
|
23
|
+
candidates?: unknown[];
|
|
24
|
+
}
|
|
25
|
+
export declare class ShardPathMigrationService {
|
|
26
|
+
migrate(options: PathMigrationOptions): Promise<PathMigrationResult>;
|
|
27
|
+
private rollbackSwap;
|
|
28
|
+
/** Roll back an interrupted staged swap before normal storage access resumes. */
|
|
29
|
+
recoverInterruptedSwap(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export declare const shardPathMigrationService: ShardPathMigrationService;
|
|
32
|
+
//# sourceMappingURL=shard-path-migration-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shard-path-migration-service.d.ts","sourceRoot":"","sources":["../../src/services/shard-path-migration-service.ts"],"names":[],"mappings":"AAoBA,OAAO,EAEL,KAAK,6BAA6B,EAClC,KAAK,uBAAuB,EAC7B,MAAM,8BAA8B,CAAC;AAGtC,MAAM,WAAW,oBAAqB,SAAQ,6BAA6B;IACzE,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EACF,QAAQ,GAAG,sBAAsB,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;IACjG,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,uBAAuB,CAAC,WAAW,CAAC,CAAC;IACjD,OAAO,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC;CACxB;AA2DD,qBAAa,yBAAyB;IAC9B,OAAO,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAkT5D,YAAY;IAuE1B,iFAAiF;IAC3E,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CAqC9C;AAED,eAAO,MAAM,yBAAyB,2BAAkC,CAAC"}
|