@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
package/dist/config.js
ADDED
|
@@ -0,0 +1,1141 @@
|
|
|
1
|
+
import { existsSync, readFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { stripJsoncComments } from "./services/jsonc.js";
|
|
5
|
+
import { resolveSecretValue } from "./services/secret-resolver.js";
|
|
6
|
+
import { isPlaceholderApiKey } from "./services/ai/api-key-placeholder.js";
|
|
7
|
+
import { getDefaultInjectionMarkers } from "./services/injected-prompt-filter.js";
|
|
8
|
+
const CONFIG_DIR = join(homedir(), ".config", "opencode");
|
|
9
|
+
const DATA_DIR = join(homedir(), ".opencode-mem");
|
|
10
|
+
const CONFIG_FILES = [
|
|
11
|
+
join(CONFIG_DIR, "opencode-mem.jsonc"),
|
|
12
|
+
join(CONFIG_DIR, "opencode-mem.json"),
|
|
13
|
+
];
|
|
14
|
+
if (!existsSync(CONFIG_DIR)) {
|
|
15
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
if (!existsSync(DATA_DIR)) {
|
|
18
|
+
mkdirSync(DATA_DIR, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
const DEFAULTS = {
|
|
21
|
+
storagePath: join(DATA_DIR, "data"),
|
|
22
|
+
memoryBackend: "database",
|
|
23
|
+
embeddingModel: "Xenova/nomic-embed-text-v1",
|
|
24
|
+
embeddingDimensions: 768,
|
|
25
|
+
embeddingUseTaskPrefixes: false,
|
|
26
|
+
embeddingPooling: "mean",
|
|
27
|
+
embeddingIdleTimeoutMs: 0,
|
|
28
|
+
similarityThreshold: 0.6,
|
|
29
|
+
maxMemories: 10,
|
|
30
|
+
// Deprecated compatibility value; not used for profile selection.
|
|
31
|
+
maxProfileItems: 5,
|
|
32
|
+
injectProfile: true,
|
|
33
|
+
containerTagPrefix: "opencode",
|
|
34
|
+
autoCaptureEnabled: true,
|
|
35
|
+
autoCaptureMaxIterations: 5,
|
|
36
|
+
autoCaptureIterationTimeout: 30000,
|
|
37
|
+
autoCaptureMaxRetries: 3,
|
|
38
|
+
autoCaptureMaxContextBytes: 131072,
|
|
39
|
+
autoCaptureProviderOrder: "opencode-first",
|
|
40
|
+
updateOnCaptureEnabled: false,
|
|
41
|
+
updateOnCaptureSimilarityThreshold: 0.75,
|
|
42
|
+
updateOnCaptureMaxCandidates: 5,
|
|
43
|
+
aiSessionRetentionDays: 7,
|
|
44
|
+
webServerEnabled: true,
|
|
45
|
+
webServerPort: 4747,
|
|
46
|
+
webServerHost: "127.0.0.1",
|
|
47
|
+
maxVectorsPerShard: 50000,
|
|
48
|
+
autoCleanupEnabled: true,
|
|
49
|
+
autoCleanupRetentionDays: 30,
|
|
50
|
+
deduplicationEnabled: true,
|
|
51
|
+
deduplicationSimilarityThreshold: 0.9,
|
|
52
|
+
userProfileAnalysisInterval: 10,
|
|
53
|
+
userProfileMaxContextBytes: 32768,
|
|
54
|
+
// Deprecated compatibility values; not used by the UI.
|
|
55
|
+
userProfileDisplayPreferences: 20,
|
|
56
|
+
userProfileDisplayPatterns: 15,
|
|
57
|
+
userProfileDisplayWorkflows: 10,
|
|
58
|
+
userProfileStaleDays: 2,
|
|
59
|
+
userProfileInjectPreferences: 5,
|
|
60
|
+
userProfileInjectPatterns: 5,
|
|
61
|
+
userProfileInjectWorkflows: 3,
|
|
62
|
+
userProfileConfidenceDecayDays: 30,
|
|
63
|
+
userProfileChangelogRetentionCount: 5,
|
|
64
|
+
userProfileEmbeddingThresholdSameCat: 0.8,
|
|
65
|
+
userProfileEmbeddingThresholdSameCatWeak: 0.5,
|
|
66
|
+
userProfileEmbeddingThresholdCrossCat: 0.9,
|
|
67
|
+
userProfileEmbeddingThresholdCrossCatWeak: 0.8,
|
|
68
|
+
userProfileCentroidDriftThreshold: 0.65,
|
|
69
|
+
userProfileEmbeddingMinDescriptionLength: 5,
|
|
70
|
+
userProfileMinEvidenceForRetention: 3,
|
|
71
|
+
userProfileAutoCleanupEnabled: true,
|
|
72
|
+
userProfileAutoCleanupInterval: 100,
|
|
73
|
+
userProfileValidationEnabled: false,
|
|
74
|
+
showAutoCaptureToasts: true,
|
|
75
|
+
showUserProfileToasts: true,
|
|
76
|
+
showErrorToasts: true,
|
|
77
|
+
databaseEncryptionEnabled: false,
|
|
78
|
+
databaseEncryptionCipher: "aes256gcm",
|
|
79
|
+
autoUpdate: true,
|
|
80
|
+
tursoAutoHeal: true,
|
|
81
|
+
tursoMultiprocessWal: true,
|
|
82
|
+
memory: {
|
|
83
|
+
defaultScope: "project",
|
|
84
|
+
},
|
|
85
|
+
compaction: {
|
|
86
|
+
enabled: true,
|
|
87
|
+
memoryLimit: 10,
|
|
88
|
+
},
|
|
89
|
+
chatMessage: {
|
|
90
|
+
enabled: true,
|
|
91
|
+
maxMemories: 3,
|
|
92
|
+
excludeCurrentSession: true,
|
|
93
|
+
maxAgeDays: undefined,
|
|
94
|
+
injectOn: "first",
|
|
95
|
+
recall: "relevant",
|
|
96
|
+
recallScope: "default",
|
|
97
|
+
similarityThreshold: undefined,
|
|
98
|
+
filterInjectedPrompts: true,
|
|
99
|
+
injectionMarkers: [...getDefaultInjectionMarkers()],
|
|
100
|
+
captureChildSessions: false,
|
|
101
|
+
},
|
|
102
|
+
dreaming: {
|
|
103
|
+
enabled: false,
|
|
104
|
+
intervalHours: 24,
|
|
105
|
+
maxGroupsPerRun: 5,
|
|
106
|
+
trashRetentionDays: 30,
|
|
107
|
+
relatedThreshold: 0.75,
|
|
108
|
+
crossProject: false,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
function expandPath(path) {
|
|
112
|
+
if (path.startsWith("~/")) {
|
|
113
|
+
return join(homedir(), path.slice(2));
|
|
114
|
+
}
|
|
115
|
+
if (path === "~") {
|
|
116
|
+
return homedir();
|
|
117
|
+
}
|
|
118
|
+
return path;
|
|
119
|
+
}
|
|
120
|
+
function normalizeMemoryBackend(value) {
|
|
121
|
+
if (value === "markdown")
|
|
122
|
+
return "markdown";
|
|
123
|
+
return "database";
|
|
124
|
+
}
|
|
125
|
+
function loadConfigFromPaths(paths) {
|
|
126
|
+
for (const path of paths) {
|
|
127
|
+
if (existsSync(path)) {
|
|
128
|
+
try {
|
|
129
|
+
const content = readFileSync(path, "utf-8");
|
|
130
|
+
const json = stripJsoncComments(content);
|
|
131
|
+
return JSON.parse(json);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// ignore unreadable or invalid config files
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
const GLOBAL_ONLY_REMOTE_PROVIDER_FIELDS = [
|
|
141
|
+
"embeddingApiUrl",
|
|
142
|
+
"embeddingApiKey",
|
|
143
|
+
"memoryProvider",
|
|
144
|
+
"memoryApiUrl",
|
|
145
|
+
"memoryApiKey",
|
|
146
|
+
];
|
|
147
|
+
function assertProjectRemoteProviderConfigIsSafe(projectConfig) {
|
|
148
|
+
const configuredFields = GLOBAL_ONLY_REMOTE_PROVIDER_FIELDS.filter((field) => Object.prototype.hasOwnProperty.call(projectConfig, field));
|
|
149
|
+
if (configuredFields.length > 0) {
|
|
150
|
+
throw new Error(`Project config cannot set remote provider fields: ${configuredFields.join(", ")}. ` +
|
|
151
|
+
`Move them to the global config at ${CONFIG_FILES[0]}.`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const CONFIG_TEMPLATE = `{
|
|
155
|
+
// ============================================
|
|
156
|
+
// OpenCode Memory Plugin Configuration
|
|
157
|
+
// ============================================
|
|
158
|
+
|
|
159
|
+
// Storage location for vector database (and search index when using markdown backend)
|
|
160
|
+
"storagePath": "~/.opencode-mem/data",
|
|
161
|
+
|
|
162
|
+
// Memory persistence: "database" (default) or "markdown"
|
|
163
|
+
// "memoryBackend": "markdown",
|
|
164
|
+
// "markdownPath": "~/Documents/LLM-Wiki",
|
|
165
|
+
|
|
166
|
+
"userEmailOverride": "",
|
|
167
|
+
"userNameOverride": "",
|
|
168
|
+
|
|
169
|
+
// ============================================
|
|
170
|
+
// Embedding Model (for similarity search)
|
|
171
|
+
// ============================================
|
|
172
|
+
// Local = Hugging Face / ONNX via @huggingface/transformers (not Apple MLX).
|
|
173
|
+
// Remote = set BOTH embeddingApiUrl and embeddingApiKey (OpenAI-compatible /embeddings).
|
|
174
|
+
|
|
175
|
+
// Default: Nomic Embed v1 (768 dimensions, 8192 context, multilingual)
|
|
176
|
+
"embeddingModel": "Xenova/nomic-embed-text-v1",
|
|
177
|
+
|
|
178
|
+
// Opt-in Nomic task prefixes (search_document: / search_query:). After enabling,
|
|
179
|
+
// re-index existing memories so store and query vectors stay aligned.
|
|
180
|
+
// "embeddingUseTaskPrefixes": true,
|
|
181
|
+
|
|
182
|
+
// Local pooling: "mean" (default) | "cls" | "last_token".
|
|
183
|
+
// Unset → model preset (bge-m3=cls, Qwen3-Embedding=last_token) or "mean".
|
|
184
|
+
// "embeddingPooling": "mean",
|
|
185
|
+
|
|
186
|
+
// Custom task prefixes (override presets / Nomic). Explicit "" disables a side.
|
|
187
|
+
// Changing pooling or prefixes requires re-embedding stored memories.
|
|
188
|
+
// "embeddingQueryPrefix": "query: ",
|
|
189
|
+
// "embeddingDocumentPrefix": "passage: ",
|
|
190
|
+
|
|
191
|
+
// Optional local ONNX dtype override (e.g. "q8", "fp32"). When unset, transformers.js defaults apply.
|
|
192
|
+
// "embeddingDtype": "q8",
|
|
193
|
+
|
|
194
|
+
// Release the local model after this many ms without embedding work.
|
|
195
|
+
// 0 (default) keeps it loaded for the whole process lifetime.
|
|
196
|
+
// "embeddingIdleTimeoutMs": 600000,
|
|
197
|
+
|
|
198
|
+
// Auto-detected dimensions (no need to set manually)
|
|
199
|
+
// "embeddingDimensions": 768,
|
|
200
|
+
|
|
201
|
+
// Other recommended local models:
|
|
202
|
+
// "embeddingModel": "Xenova/jina-embeddings-v2-base-en", // 768 dims, English-only, 8192 context
|
|
203
|
+
// "embeddingModel": "Xenova/jina-embeddings-v2-small-en", // 512 dims, faster, 8192 context
|
|
204
|
+
// "embeddingModel": "Xenova/all-MiniLM-L6-v2", // 384 dims, very fast, 512 context
|
|
205
|
+
// "embeddingModel": "Xenova/all-mpnet-base-v2", // 768 dims, good quality, 512 context
|
|
206
|
+
// "embeddingModel": "Xenova/bge-m3", // 1024 dims, CLS pooling (auto)
|
|
207
|
+
// "embeddingModel": "intfloat/multilingual-e5-large", // 1024 dims, query:/passage: prefixes (auto)
|
|
208
|
+
|
|
209
|
+
// Optional: OpenAI-compatible API for embeddings (both URL and key required)
|
|
210
|
+
// "embeddingApiUrl": "https://api.openai.com/v1",
|
|
211
|
+
// "embeddingApiKey": "env://OPENAI_API_KEY", // or "sk-..." / "file:///path/to/key"
|
|
212
|
+
// "embeddingModel": "text-embedding-3-small", // 1536 dims, auto-detected
|
|
213
|
+
|
|
214
|
+
// ============================================
|
|
215
|
+
// Web Server Settings
|
|
216
|
+
// ============================================
|
|
217
|
+
|
|
218
|
+
// Enable web UI for managing memories (accessible at http://localhost:4747)
|
|
219
|
+
"webServerEnabled": true,
|
|
220
|
+
|
|
221
|
+
// Port for web UI server
|
|
222
|
+
"webServerPort": 4747,
|
|
223
|
+
|
|
224
|
+
// Host address for web UI (use 127.0.0.1 for local only, 0.0.0.0 for network access)
|
|
225
|
+
"webServerHost": "127.0.0.1",
|
|
226
|
+
|
|
227
|
+
// Optional HTTP Basic Auth for the web UI. Accepts literal, env://, or file:// secrets.
|
|
228
|
+
// "webServerAuthPassword": "",
|
|
229
|
+
// "webServerAuthUsername": "",
|
|
230
|
+
|
|
231
|
+
// Required when webServerHost is not loopback. Protects /api/* with Bearer / X-Opencode-Mem-Token.
|
|
232
|
+
// "webServerApiToken": "env://OPENCODE_MEM_WEB_TOKEN",
|
|
233
|
+
|
|
234
|
+
// ============================================
|
|
235
|
+
// Database Settings
|
|
236
|
+
// ============================================
|
|
237
|
+
|
|
238
|
+
// Maximum vectors per database shard (auto-creates new shard when limit reached)
|
|
239
|
+
"maxVectorsPerShard": 50000,
|
|
240
|
+
|
|
241
|
+
// Automatically delete old memories based on retention period
|
|
242
|
+
"autoCleanupEnabled": true,
|
|
243
|
+
|
|
244
|
+
// Days to keep memories before auto-cleanup (only if autoCleanupEnabled is true)
|
|
245
|
+
"autoCleanupRetentionDays": 30,
|
|
246
|
+
|
|
247
|
+
// Automatically detect and remove duplicate memories
|
|
248
|
+
"deduplicationEnabled": true,
|
|
249
|
+
|
|
250
|
+
// Similarity threshold (0-1) for detecting duplicates (higher = stricter)
|
|
251
|
+
"deduplicationSimilarityThreshold": 0.90,
|
|
252
|
+
|
|
253
|
+
// ============================================
|
|
254
|
+
// Memory Scope Settings
|
|
255
|
+
// ============================================
|
|
256
|
+
|
|
257
|
+
// Default scope for memory list/search queries
|
|
258
|
+
// "project" keeps queries within the current project, "all-projects" searches across all project shards
|
|
259
|
+
"memory": {
|
|
260
|
+
"defaultScope": "project"
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
// ============================================
|
|
264
|
+
// OpenCode Provider Settings (RECOMMENDED)
|
|
265
|
+
// ============================================
|
|
266
|
+
|
|
267
|
+
// Use any provider that is already authenticated in opencode for auto-capture
|
|
268
|
+
// and user profile learning. The plugin calls opencode's session.prompt API
|
|
269
|
+
// (with structured output) instead of talking to provider HTTPS endpoints
|
|
270
|
+
// directly, so opencode owns the auth, token refresh, and provider routing.
|
|
271
|
+
//
|
|
272
|
+
// No separate API key is needed in this plugin — whatever you configured in
|
|
273
|
+
// opencode (OAuth like Claude Pro/Max, GitHub Copilot personal/business,
|
|
274
|
+
// bring-your-own API key, custom provider, ...) just works.
|
|
275
|
+
//
|
|
276
|
+
// If NOT set, falls back to the manual config (memoryApiKey/memoryApiUrl/memoryModel below).
|
|
277
|
+
//
|
|
278
|
+
// Examples (the provider name must be one returned by 'opencode providers list'):
|
|
279
|
+
// Anthropic (OAuth/API key): "opencodeProvider": "anthropic", "opencodeModel": "claude-haiku-4-5-20251001"
|
|
280
|
+
// OpenAI (API key): "opencodeProvider": "openai", "opencodeModel": "gpt-4o-mini"
|
|
281
|
+
// GitHub Copilot: "opencodeProvider": "github-copilot", "opencodeModel": "gpt-4o-mini"
|
|
282
|
+
// OpenRouter: "opencodeProvider": "openrouter", "opencodeModel": "…"
|
|
283
|
+
//
|
|
284
|
+
// Avoid pinning the built-in Free provider "opencode" (e.g. big-pickle) for
|
|
285
|
+
// auto-capture: those models are often restricted to interactive OpenCode
|
|
286
|
+
// chat and fail on the plugin's internal structured-output sessions. Prefer
|
|
287
|
+
// an authenticated provider above, or "opencodeModel": "inherit".
|
|
288
|
+
//
|
|
289
|
+
// "opencodeProvider": "anthropic",
|
|
290
|
+
// "opencodeModel": "claude-haiku-4-5-20251001",
|
|
291
|
+
// Optional model reasoning variant for internal LLM calls (e.g. "xhigh");
|
|
292
|
+
// also applies when opencodeModel is "inherit":
|
|
293
|
+
// "opencodeVariant": "xhigh",
|
|
294
|
+
// Optional timeout in milliseconds for the plugin's internal structured-output LLM calls
|
|
295
|
+
// (auto-capture summaries, profile learning; default 90000, clamped to 10000..600000;
|
|
296
|
+
// invalid values fall back to the default; numeric strings are coerced):
|
|
297
|
+
// "opencodeTimeoutMs": 180000,
|
|
298
|
+
|
|
299
|
+
// ============================================
|
|
300
|
+
// Auto-Capture Settings
|
|
301
|
+
// ============================================
|
|
302
|
+
|
|
303
|
+
// IMPORTANT: Auto-capture only runs after either opencodeProvider/opencodeModel
|
|
304
|
+
// above is configured, or the manual fallback below is uncommented with real values.
|
|
305
|
+
// If autoCaptureEnabled is true but neither path is ready, the plugin shows a
|
|
306
|
+
// startup warning toast (when showErrorToasts is true).
|
|
307
|
+
// It runs in background without blocking your main session
|
|
308
|
+
// Note: Ollama may not support tool calling. Use OpenAI, Anthropic, or Groq for best results.
|
|
309
|
+
|
|
310
|
+
"autoCaptureEnabled": true,
|
|
311
|
+
|
|
312
|
+
// Opt-in: before saving a new auto-capture memory, search for similar entries
|
|
313
|
+
// and let the model choose add / update / supersede (old rows go to trash).
|
|
314
|
+
// "updateOnCaptureEnabled": true,
|
|
315
|
+
// "updateOnCaptureSimilarityThreshold": 0.75,
|
|
316
|
+
// "updateOnCaptureMaxCandidates": 5,
|
|
317
|
+
|
|
318
|
+
// Provider type: "api-route" | "atlas-cloud" | "cheaper-inference" | "openai-chat" | "openai-responses" | "anthropic" | "minimax" | "orcarouter" | "runcrate" | "cloudgpu"
|
|
319
|
+
// Note: "openai-chat" is a generic OpenAI API-compatible mode.
|
|
320
|
+
// Any service that follows the OpenAI Chat Completions API can use it via custom "memoryApiUrl".
|
|
321
|
+
"memoryProvider": "openai-chat",
|
|
322
|
+
|
|
323
|
+
// Manual fallback. Uncomment all 3 lines and replace memoryApiKey before use:
|
|
324
|
+
// "memoryModel": "gpt-4o-mini",
|
|
325
|
+
// "memoryApiUrl": "https://api.openai.com/v1",
|
|
326
|
+
// "memoryApiKey": "sk-...",
|
|
327
|
+
|
|
328
|
+
// API Key Formats:
|
|
329
|
+
// Direct value: "sk-..."
|
|
330
|
+
// From file: "file://~/.config/litellm-key.txt"
|
|
331
|
+
// From env variable: "env://LITELLM_API_KEY"
|
|
332
|
+
|
|
333
|
+
// Examples for different providers:
|
|
334
|
+
// Any OpenAI-compatible endpoint can use the "openai-chat" provider pattern below.
|
|
335
|
+
// Common examples: DeepSeek, Qwen (via Alibaba Cloud ModelStudio),
|
|
336
|
+
// Zhipu GLM (BigModel platform), and Kimi (Moonshot AI platform).
|
|
337
|
+
|
|
338
|
+
// OpenAI Chat Completion (default, backward compatible):
|
|
339
|
+
// "memoryProvider": "openai-chat"
|
|
340
|
+
// "memoryModel": "gpt-4o-mini"
|
|
341
|
+
// "memoryApiUrl": "https://api.openai.com/v1"
|
|
342
|
+
// "memoryApiKey": "sk-..."
|
|
343
|
+
|
|
344
|
+
// DeepSeek (OpenAI-compatible example):
|
|
345
|
+
// "memoryProvider": "openai-chat"
|
|
346
|
+
// "memoryModel": "deepseek-chat"
|
|
347
|
+
// "memoryApiUrl": "https://api.deepseek.com/v1"
|
|
348
|
+
// "memoryApiKey": "sk-..."
|
|
349
|
+
|
|
350
|
+
// OpenAI Responses API (recommended, with session support):
|
|
351
|
+
// "memoryProvider": "openai-responses"
|
|
352
|
+
// "memoryModel": "gpt-4o"
|
|
353
|
+
// "memoryApiUrl": "https://api.openai.com/v1"
|
|
354
|
+
// "memoryApiKey": "sk-..."
|
|
355
|
+
|
|
356
|
+
// Anthropic (with session support):
|
|
357
|
+
// "memoryProvider": "anthropic"
|
|
358
|
+
// "memoryModel": "claude-3-5-haiku-20241022"
|
|
359
|
+
// "memoryApiUrl": "https://api.anthropic.com/v1"
|
|
360
|
+
// "memoryApiKey": "sk-ant-..."
|
|
361
|
+
|
|
362
|
+
// MiniMax (Anthropic Messages-compatible endpoint, with session support):
|
|
363
|
+
// "memoryProvider": "minimax"
|
|
364
|
+
// "memoryModel": "MiniMax-M3.1-Flash" // 1,000,000-token context; thinking always on
|
|
365
|
+
// // Alternative: "MiniMax-M3" // 1,000,000-token context; thinking off by default
|
|
366
|
+
// "memoryApiUrl": "https://api.minimax.io" // global endpoint
|
|
367
|
+
// "memoryApiKey": "<MiniMax API key>"
|
|
368
|
+
// // China endpoint: "memoryApiUrl": "https://api.minimax.cn"
|
|
369
|
+
// // Flash effort: low | medium | high | xhigh | max (default). Do not disable thinking.
|
|
370
|
+
// "memoryExtraParams": { "output_config": { "effort": "max" } }
|
|
371
|
+
// // For MiniMax-M3, optionally use { "thinking": { "type": "adaptive" } } instead.
|
|
372
|
+
|
|
373
|
+
// OrcaRouter (OpenAI-compatible gateway, namespaced model IDs, with session support):
|
|
374
|
+
// "memoryProvider": "orcarouter"
|
|
375
|
+
// "memoryApiKey": "<OrcaRouter API key>"
|
|
376
|
+
// // memoryApiUrl and memoryModel are optional — they default to
|
|
377
|
+
// // https://api.orcarouter.ai/v1 and "orcarouter/auto" (a routing alias).
|
|
378
|
+
// // OrcaRouter rejects bare model names, so if you set memoryModel, use a
|
|
379
|
+
// // namespaced ID such as "openai/gpt-5.5" or "deepseek/deepseek-v4-flash".
|
|
380
|
+
// "memoryModel": "openai/gpt-5.5"
|
|
381
|
+
|
|
382
|
+
// Atlas Cloud (OpenAI-compatible Chat Completions preset, with session support):
|
|
383
|
+
// "memoryProvider": "atlas-cloud"
|
|
384
|
+
// "memoryApiKey": "env://ATLASCLOUD_API_KEY"
|
|
385
|
+
// // memoryApiUrl and memoryModel are optional — they default to
|
|
386
|
+
// // https://api.atlascloud.ai/v1 and "deepseek-ai/deepseek-v4-pro".
|
|
387
|
+
// // When selected, auto-capture/profile prompts, responses, and relevant
|
|
388
|
+
// // conversation context are sent to api.atlascloud.ai.
|
|
389
|
+
// // "memoryModel": "deepseek-ai/deepseek-v4-pro"
|
|
390
|
+
|
|
391
|
+
// Cheaper Inference (OpenAI-compatible Chat Completions preset, with session support):
|
|
392
|
+
// "memoryProvider": "cheaper-inference"
|
|
393
|
+
// "memoryApiKey": "env://CHEAPER_INFERENCE_API_KEY"
|
|
394
|
+
// // memoryApiUrl and memoryModel are optional — they default to
|
|
395
|
+
// // https://api.cheaperinference.com/v1 and "gpt-5.4-mini".
|
|
396
|
+
// // When selected, auto-capture/profile prompts, responses, and relevant
|
|
397
|
+
// // conversation context are sent to api.cheaperinference.com.
|
|
398
|
+
// // "memoryModel": "gpt-5.4-mini"
|
|
399
|
+
|
|
400
|
+
// API Route (OpenAI-compatible Chat Completions preset, with session support):
|
|
401
|
+
// "memoryProvider": "api-route"
|
|
402
|
+
// "memoryApiKey": "env://API_ROUTE_API_KEY"
|
|
403
|
+
// // memoryApiUrl and memoryModel are optional — they default to
|
|
404
|
+
// // https://global.api-route.com/v1 and "gpt-6.1-sol".
|
|
405
|
+
// // When selected, auto-capture/profile prompts, responses, and relevant
|
|
406
|
+
// // conversation context are sent to global.api-route.com.
|
|
407
|
+
// // "memoryModel": "gpt-6.1-sol"
|
|
408
|
+
|
|
409
|
+
// Runcrate (OpenAI-compatible Chat Completions preset, with session support):
|
|
410
|
+
// "memoryProvider": "runcrate"
|
|
411
|
+
// "memoryApiKey": "env://RUNCRATE_API_KEY"
|
|
412
|
+
// // memoryApiUrl and memoryModel are optional — they default to
|
|
413
|
+
// // https://api.runcrate.ai/v1 and "deepseek-ai/DeepSeek-V4.1-Flash".
|
|
414
|
+
// // When selected, auto-capture/profile prompts, responses, and relevant
|
|
415
|
+
// // conversation context are sent to api.runcrate.ai.
|
|
416
|
+
// // "memoryModel": "deepseek-ai/DeepSeek-V4.1-Flash"
|
|
417
|
+
|
|
418
|
+
// CloudGPU (OpenAI-compatible Chat Completions preset, with session support):
|
|
419
|
+
// "memoryProvider": "cloudgpu"
|
|
420
|
+
// "memoryApiKey": "env://CLOUDGPU_API_KEY"
|
|
421
|
+
// // memoryApiUrl and memoryModel are optional — they default to
|
|
422
|
+
// // https://cloudgpu.app/v1 and "deepseek-v4.1-flash".
|
|
423
|
+
// // Create a key at https://cloudgpu.app/api/console (docs: https://cloudgpu.app/api/docs).
|
|
424
|
+
// // When selected, auto-capture/profile prompts, responses, and relevant
|
|
425
|
+
// // conversation context are sent to cloudgpu.app.
|
|
426
|
+
// // "memoryModel": "deepseek-v4.1-flash"
|
|
427
|
+
|
|
428
|
+
// Groq (OpenAI-compatible, use openai-chat provider):
|
|
429
|
+
// "memoryProvider": "openai-chat"
|
|
430
|
+
// "memoryModel": "llama-3.3-70b-versatile"
|
|
431
|
+
// "memoryApiUrl": "https://api.groq.com/openai/v1"
|
|
432
|
+
// "memoryApiKey": "gsk_..."
|
|
433
|
+
|
|
434
|
+
// Maximum iterations for multi-turn AI analysis (for openai-responses, anthropic, and minimax)
|
|
435
|
+
"autoCaptureMaxIterations": 5,
|
|
436
|
+
|
|
437
|
+
// Timeout per iteration in milliseconds (30 seconds default)
|
|
438
|
+
"autoCaptureIterationTimeout": 30000,
|
|
439
|
+
|
|
440
|
+
// Maximum number of times to retry capturing a prompt if it fails (due to network, API errors, etc.)
|
|
441
|
+
"autoCaptureMaxRetries": 3,
|
|
442
|
+
|
|
443
|
+
// Maximum UTF-8 bytes for the auto-capture markdown context sent to the summary model.
|
|
444
|
+
// Prevents HTTP 400 context overflows on models with ~131K token windows (e.g. Groq Llama).
|
|
445
|
+
// Rough guide: tokens ≈ bytes / 4 for mixed code/prose.
|
|
446
|
+
"autoCaptureMaxContextBytes": 131072,
|
|
447
|
+
|
|
448
|
+
// When both opencodeProvider and manual memoryModel/memoryApiUrl are set, which
|
|
449
|
+
// channel to try first for auto-capture summaries. Default "opencode-first".
|
|
450
|
+
// Prefer "external-first" if the host session API is slow/busy (~15–50s) and
|
|
451
|
+
// you want the faster external API path (~3s). Failed primary falls back.
|
|
452
|
+
// Faster opencode failover also: lower "opencodeTimeoutMs" (default 90000).
|
|
453
|
+
// "autoCaptureProviderOrder": "external-first",
|
|
454
|
+
|
|
455
|
+
// Days to keep AI session history before cleanup
|
|
456
|
+
"aiSessionRetentionDays": 7,
|
|
457
|
+
|
|
458
|
+
// Temperature for AI API requests (set to false to omit parameter for models that don't support it)
|
|
459
|
+
// Some reasoning models (like o1, o3, gpt-5) don't support temperature parameter
|
|
460
|
+
// Set to false and add "memoryTemperature": false in config when using such models
|
|
461
|
+
"memoryTemperature": 0.3,
|
|
462
|
+
|
|
463
|
+
// Force tool calls on openai-chat / orcarouter / atlas-cloud / cheaper-inference / api-route / runcrate / cloudgpu (tool_choice: "required"). Default true.
|
|
464
|
+
// Some thinking/reasoning models reject forced tool choice — set false to fall back to "auto":
|
|
465
|
+
// "forceToolChoice": false,
|
|
466
|
+
|
|
467
|
+
// Extra parameters to include in API request body
|
|
468
|
+
// Useful for local inference servers (e.g. llama-server with --jinja) that support
|
|
469
|
+
// additional parameters like disabling thinking/reasoning mode
|
|
470
|
+
// Example for Qwen3 models: { "enable_thinking": false }
|
|
471
|
+
// "memoryExtraParams": {},
|
|
472
|
+
|
|
473
|
+
// Language for auto-capture summaries and user profile learning (default: "auto" for auto-detection)
|
|
474
|
+
// Options: "auto", "en", "id", "zh", "ja", "es", "fr", "de", "ru", "pt", "ar", "ko"
|
|
475
|
+
// "autoCaptureLanguage": "auto",
|
|
476
|
+
|
|
477
|
+
// ============================================
|
|
478
|
+
// Toast Notifications
|
|
479
|
+
// ============================================
|
|
480
|
+
|
|
481
|
+
// Show toast when memory is auto-captured
|
|
482
|
+
"showAutoCaptureToasts": true,
|
|
483
|
+
|
|
484
|
+
// Show toast when user profile is updated
|
|
485
|
+
"showUserProfileToasts": true,
|
|
486
|
+
|
|
487
|
+
// Show toast for error messages
|
|
488
|
+
"showErrorToasts": true,
|
|
489
|
+
|
|
490
|
+
// Opt-in encryption at rest for local Turso DB shards (AES-256-GCM).
|
|
491
|
+
// When enabled without a key, the plugin creates
|
|
492
|
+
// ~/.config/opencode/opencode-mem-db.key (chmod 600) once.
|
|
493
|
+
// "databaseEncryptionEnabled": true,
|
|
494
|
+
// Optional override: "databaseEncryptionKey": "env://OPENCODE_MEM_DB_KEY",
|
|
495
|
+
// "databaseEncryptionCipher": "aes256gcm",
|
|
496
|
+
|
|
497
|
+
// Automatically update when installed as opencode-mem@latest (or a range).
|
|
498
|
+
// Pinned versions like opencode-mem@2.26.0 are never auto-updated.
|
|
499
|
+
"autoUpdate": true,
|
|
500
|
+
|
|
501
|
+
// Recover a store whose Turso WAL index is stale (a leftover -tshm/-shm, often
|
|
502
|
+
// beside a 0-byte -wal). The guard copies the main .db, verifies it with
|
|
503
|
+
// PRAGMA integrity_check, moves the -shm/-tshm index sidecars to
|
|
504
|
+
// <storagePath>/recovery/, and retries the open once. A non-empty -wal is
|
|
505
|
+
// never moved, so committed but uncheckpointed transactions are preserved.
|
|
506
|
+
// Recovery is serialised across processes by <storagePath>/recovery/<db>.lock.
|
|
507
|
+
"tursoAutoHeal": true,
|
|
508
|
+
|
|
509
|
+
// Turso experimental multiprocess_wal (Unix). Set false for single-owner mode:
|
|
510
|
+
// a second process then fails loudly with "database is locked" instead of
|
|
511
|
+
// writing into a divergent WAL. See issue #435.
|
|
512
|
+
"tursoMultiprocessWal": true,
|
|
513
|
+
|
|
514
|
+
// ============================================
|
|
515
|
+
// User Profile System
|
|
516
|
+
// ============================================
|
|
517
|
+
|
|
518
|
+
// Analyze user prompts every N prompts to build/update your user profile
|
|
519
|
+
// When N uncaptured prompts accumulate, AI will analyze them to identify:
|
|
520
|
+
// - User preferences (code style, communication style, tool preferences)
|
|
521
|
+
// - User patterns (recurring topics, problem domains, technical interests)
|
|
522
|
+
// - User workflows (development habits, sequences, learning style)
|
|
523
|
+
// - Skill level (overall and per-domain assessment)
|
|
524
|
+
"userProfileAnalysisInterval": 10,
|
|
525
|
+
|
|
526
|
+
// Days before inactive items (all types) are eligible for removal
|
|
527
|
+
"userProfileStaleDays": 2,
|
|
528
|
+
|
|
529
|
+
// Number of preferences injected into LLM conversation context
|
|
530
|
+
// Keep this small — the strongest signals are enough; more dilute LLM attention
|
|
531
|
+
"userProfileInjectPreferences": 5,
|
|
532
|
+
|
|
533
|
+
// Number of patterns injected into LLM conversation context
|
|
534
|
+
"userProfileInjectPatterns": 5,
|
|
535
|
+
|
|
536
|
+
// Number of workflows injected into LLM conversation context
|
|
537
|
+
"userProfileInjectWorkflows": 3,
|
|
538
|
+
|
|
539
|
+
// Days before preference confidence starts to decay (if not reinforced)
|
|
540
|
+
// Preferences that aren't seen again will gradually lose confidence and be removed
|
|
541
|
+
"userProfileConfidenceDecayDays": 30,
|
|
542
|
+
|
|
543
|
+
// Number of profile versions to keep in changelog (for rollback/debugging)
|
|
544
|
+
// Older versions are automatically cleaned up
|
|
545
|
+
"userProfileChangelogRetentionCount": 5,
|
|
546
|
+
|
|
547
|
+
// Minimum evidence count for a preference/pattern to survive confidence decay
|
|
548
|
+
// Items confirmed fewer times are more likely to be pruned when confidence decays
|
|
549
|
+
"userProfileMinEvidenceForRetention": 3,
|
|
550
|
+
|
|
551
|
+
// Periodically merge duplicate or irrelevant profile items with the configured AI provider
|
|
552
|
+
"userProfileAutoCleanupEnabled": true,
|
|
553
|
+
// Number of analyzed user prompts between automatic AI cleanup runs
|
|
554
|
+
"userProfileAutoCleanupInterval": 100,
|
|
555
|
+
|
|
556
|
+
// Enable LLM validation of existing preferences against recent behavior.
|
|
557
|
+
// When enabled, each analysis round checks if top-5 preferences still match recent prompts.
|
|
558
|
+
// Experimental — disabled by default.
|
|
559
|
+
"userProfileValidationEnabled": false,
|
|
560
|
+
|
|
561
|
+
// ============================================
|
|
562
|
+
// Search Settings
|
|
563
|
+
// ============================================
|
|
564
|
+
|
|
565
|
+
// Minimum similarity score (0-1) for memory search results
|
|
566
|
+
"similarityThreshold": 0.6,
|
|
567
|
+
|
|
568
|
+
// Maximum number of memories to return in search results
|
|
569
|
+
"maxMemories": 10,
|
|
570
|
+
|
|
571
|
+
// ============================================
|
|
572
|
+
// Advanced Settings
|
|
573
|
+
// ============================================
|
|
574
|
+
|
|
575
|
+
// Inject user profile into AI context (preferences, patterns, workflows)
|
|
576
|
+
"injectProfile": true,
|
|
577
|
+
|
|
578
|
+
// Chat message capture and injection behavior
|
|
579
|
+
"chatMessage": {
|
|
580
|
+
// How auto-injected memories are picked for the prompt context.
|
|
581
|
+
// "relevant" (default) embeds the user message and runs vector search.
|
|
582
|
+
// "recent" keeps the legacy newest-N listing. "both" prefers relevant,
|
|
583
|
+
// then fills remaining slots with recent memories.
|
|
584
|
+
"recall": "relevant",
|
|
585
|
+
// Scope for auto-recall. "default" follows memory.defaultScope above.
|
|
586
|
+
// "recallScope": "default",
|
|
587
|
+
// Optional similarity floor for relevant recall (else similarityThreshold).
|
|
588
|
+
// "similarityThreshold": 0.6,
|
|
589
|
+
|
|
590
|
+
// Skip prompt text injected by the host or by other OpenCode plugins
|
|
591
|
+
// (system reminders, orchestration directives, background-task
|
|
592
|
+
// notifications) so it is never stored as if the user had typed it.
|
|
593
|
+
// Disable only if you deliberately want that content memorized.
|
|
594
|
+
"filterInjectedPrompts": true,
|
|
595
|
+
|
|
596
|
+
// Capture prompts from orchestrator child sessions (sessions with a parentID,
|
|
597
|
+
// e.g. OpenCode task/subagent children). Their "user" messages are written
|
|
598
|
+
// by the parent agent, not by you, so default false means they are not
|
|
599
|
+
// stored, auto-captured, used for profile learning, or given memory
|
|
600
|
+
// context. Enable only if you deliberately want those prompts memorized.
|
|
601
|
+
"captureChildSessions": false
|
|
602
|
+
|
|
603
|
+
// Extra markers identifying injected blocks. These are ADDED to the
|
|
604
|
+
// built-in list, never replace it.
|
|
605
|
+
// "injectionMarkers": ["<my-plugin-banner>"]
|
|
606
|
+
},
|
|
607
|
+
|
|
608
|
+
// Opt-in background consolidation: merge/update/supersede related memories
|
|
609
|
+
// via the configured LLM and soft-delete superseded rows into trash.
|
|
610
|
+
// "enabled" gates only the scheduler; the Dream button / POST /api/dreaming/run
|
|
611
|
+
// still work when false (manual-only mode).
|
|
612
|
+
"dreaming": {
|
|
613
|
+
"enabled": false,
|
|
614
|
+
"intervalHours": 24,
|
|
615
|
+
"maxGroupsPerRun": 5,
|
|
616
|
+
"trashRetentionDays": 30,
|
|
617
|
+
// Related (not only near-duplicate) grouping floor; independent of
|
|
618
|
+
// deduplicationSimilarityThreshold (default 0.9).
|
|
619
|
+
"relatedThreshold": 0.75,
|
|
620
|
+
// Also effective when memory.defaultScope is "all-projects".
|
|
621
|
+
"crossProject": false
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
`;
|
|
625
|
+
function ensureConfigExists() {
|
|
626
|
+
const configPath = join(CONFIG_DIR, "opencode-mem.jsonc");
|
|
627
|
+
if (!existsSync(configPath)) {
|
|
628
|
+
try {
|
|
629
|
+
writeFileSync(configPath, CONFIG_TEMPLATE, "utf-8");
|
|
630
|
+
console.log(`\n✓ Created config template: ${configPath}`);
|
|
631
|
+
console.log(" Edit this file to customize opencode-mem settings.\n");
|
|
632
|
+
}
|
|
633
|
+
catch {
|
|
634
|
+
// ignore if the template cannot be written
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
ensureConfigExists();
|
|
639
|
+
const QWEN3_EMBEDDING_QUERY_PREFIX = "Instruct: Given a web search query, retrieve relevant passages that answer the query\nQuery: ";
|
|
640
|
+
/**
|
|
641
|
+
* Known local embedding model presets (substring match on `embeddingModel`).
|
|
642
|
+
* Explicit config keys always win over these defaults.
|
|
643
|
+
*/
|
|
644
|
+
export function getEmbeddingModelPreset(model) {
|
|
645
|
+
const id = model.toLowerCase();
|
|
646
|
+
if (id.includes("bge-m3")) {
|
|
647
|
+
return { pooling: "cls", queryPrefix: "", documentPrefix: "" };
|
|
648
|
+
}
|
|
649
|
+
if (id.includes("multilingual-e5") || id.includes("e5-")) {
|
|
650
|
+
return { pooling: "mean", queryPrefix: "query: ", documentPrefix: "passage: " };
|
|
651
|
+
}
|
|
652
|
+
if (id.includes("qwen3-embedding")) {
|
|
653
|
+
return {
|
|
654
|
+
pooling: "last_token",
|
|
655
|
+
queryPrefix: QWEN3_EMBEDDING_QUERY_PREFIX,
|
|
656
|
+
documentPrefix: "",
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
if (id.includes("jina-embeddings")) {
|
|
660
|
+
return { pooling: "mean", queryPrefix: "", documentPrefix: "" };
|
|
661
|
+
}
|
|
662
|
+
if (id.includes("nomic-embed")) {
|
|
663
|
+
return { pooling: "mean" };
|
|
664
|
+
}
|
|
665
|
+
return undefined;
|
|
666
|
+
}
|
|
667
|
+
export function normalizeEmbeddingPooling(value) {
|
|
668
|
+
if (value === "mean" || value === "cls" || value === "last_token")
|
|
669
|
+
return value;
|
|
670
|
+
throw new Error(`Invalid embeddingPooling config: ${String(value)} (expected "mean" | "cls" | "last_token")`);
|
|
671
|
+
}
|
|
672
|
+
/** Dtypes accepted by transformers.js `pipeline({ dtype })`. */
|
|
673
|
+
export const LOCAL_ONNX_DTYPES = [
|
|
674
|
+
"auto",
|
|
675
|
+
"fp32",
|
|
676
|
+
"fp16",
|
|
677
|
+
"q8",
|
|
678
|
+
"int8",
|
|
679
|
+
"uint8",
|
|
680
|
+
"q4",
|
|
681
|
+
"bnb4",
|
|
682
|
+
"q4f16",
|
|
683
|
+
"q2",
|
|
684
|
+
"q2f16",
|
|
685
|
+
"q1",
|
|
686
|
+
"q1f16",
|
|
687
|
+
];
|
|
688
|
+
export function normalizeEmbeddingDtype(value) {
|
|
689
|
+
if (value === undefined || value === null)
|
|
690
|
+
return undefined;
|
|
691
|
+
if (typeof value !== "string") {
|
|
692
|
+
throw new Error(`Invalid embeddingDtype config: ${String(value)}`);
|
|
693
|
+
}
|
|
694
|
+
const trimmed = value.trim();
|
|
695
|
+
if (!trimmed)
|
|
696
|
+
return undefined;
|
|
697
|
+
if (LOCAL_ONNX_DTYPES.includes(trimmed)) {
|
|
698
|
+
return trimmed;
|
|
699
|
+
}
|
|
700
|
+
throw new Error(`Invalid embeddingDtype config: ${trimmed} (expected one of ${LOCAL_ONNX_DTYPES.join(", ")})`);
|
|
701
|
+
}
|
|
702
|
+
export function normalizeEmbeddingIdleTimeoutMs(value) {
|
|
703
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
704
|
+
throw new Error(`Invalid embeddingIdleTimeoutMs config: ${String(value)}`);
|
|
705
|
+
}
|
|
706
|
+
return value;
|
|
707
|
+
}
|
|
708
|
+
function getEmbeddingDimensions(model) {
|
|
709
|
+
const dimensionMap = {
|
|
710
|
+
// Local Xenova models
|
|
711
|
+
"Xenova/nomic-embed-text-v1": 768,
|
|
712
|
+
"Xenova/nomic-embed-text-v1-unsupervised": 768,
|
|
713
|
+
"Xenova/nomic-embed-text-v1-ablated": 768,
|
|
714
|
+
"Xenova/jina-embeddings-v2-base-en": 768,
|
|
715
|
+
"Xenova/jina-embeddings-v2-base-zh": 768,
|
|
716
|
+
"Xenova/jina-embeddings-v2-base-de": 768,
|
|
717
|
+
"Xenova/jina-embeddings-v2-small-en": 512,
|
|
718
|
+
"Xenova/all-MiniLM-L6-v2": 384,
|
|
719
|
+
"Xenova/all-MiniLM-L12-v2": 384,
|
|
720
|
+
"Xenova/all-mpnet-base-v2": 768,
|
|
721
|
+
"Xenova/bge-base-en-v1.5": 768,
|
|
722
|
+
"Xenova/bge-small-en-v1.5": 384,
|
|
723
|
+
"Xenova/bge-m3": 1024,
|
|
724
|
+
"Xenova/gte-small": 384,
|
|
725
|
+
"Xenova/GIST-small-Embedding-v0": 384,
|
|
726
|
+
"Xenova/text-embedding-ada-002": 1536,
|
|
727
|
+
// Other local / ONNX community models
|
|
728
|
+
"intfloat/multilingual-e5-large": 1024,
|
|
729
|
+
"intfloat/multilingual-e5-base": 768,
|
|
730
|
+
"intfloat/e5-large-v2": 1024,
|
|
731
|
+
"onnx-community/Qwen3-Embedding-0.6B-ONNX": 1024,
|
|
732
|
+
// OpenAI API models
|
|
733
|
+
"text-embedding-3-small": 1536,
|
|
734
|
+
"text-embedding-3-large": 3072,
|
|
735
|
+
"text-embedding-ada-002": 1536,
|
|
736
|
+
// Cohere API models
|
|
737
|
+
"embed-english-v3.0": 1024,
|
|
738
|
+
"embed-multilingual-v3.0": 1024,
|
|
739
|
+
"embed-english-light-v3.0": 384,
|
|
740
|
+
"embed-multilingual-light-v3.0": 384,
|
|
741
|
+
// Google API models
|
|
742
|
+
"text-embedding-004": 768,
|
|
743
|
+
"text-multilingual-embedding-002": 768,
|
|
744
|
+
// Voyage AI models
|
|
745
|
+
"voyage-3": 1024,
|
|
746
|
+
"voyage-3-lite": 512,
|
|
747
|
+
"voyage-code-3": 1024,
|
|
748
|
+
};
|
|
749
|
+
return dimensionMap[model] || 768;
|
|
750
|
+
}
|
|
751
|
+
export function normalizeAutoCaptureMaxContextBytes(value) {
|
|
752
|
+
if (!Number.isInteger(value) || value < 16384 || value > 16 * 1024 * 1024) {
|
|
753
|
+
throw new Error(`Invalid autoCaptureMaxContextBytes config: ${value}`);
|
|
754
|
+
}
|
|
755
|
+
return value;
|
|
756
|
+
}
|
|
757
|
+
/** Invalid / unset values fall back to the historical default (opencode-first). */
|
|
758
|
+
export function normalizeAutoCaptureProviderOrder(value) {
|
|
759
|
+
return value === "external-first" ? "external-first" : "opencode-first";
|
|
760
|
+
}
|
|
761
|
+
export function normalizeAutoCleanupRetentionDays(value) {
|
|
762
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
763
|
+
throw new Error(`Invalid autoCleanupRetentionDays config: ${value}`);
|
|
764
|
+
}
|
|
765
|
+
return value;
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Blank/whitespace-only opencodeVariant values are treated as unset so the
|
|
769
|
+
* prompt bodies never carry an empty `variant` key.
|
|
770
|
+
*/
|
|
771
|
+
function normalizeOpencodeVariant(value) {
|
|
772
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
773
|
+
return trimmed ? trimmed : undefined;
|
|
774
|
+
}
|
|
775
|
+
export const OPENCODE_TIMEOUT_MS_MIN = 10_000;
|
|
776
|
+
export const OPENCODE_TIMEOUT_MS_MAX = 600_000;
|
|
777
|
+
export const OPENCODE_TIMEOUT_MS_DEFAULT = 90_000;
|
|
778
|
+
/**
|
|
779
|
+
* Structured-output prompt timeout: non-number/non-finite values fall back to
|
|
780
|
+
* the default (numeric strings are coerced first), otherwise the value is
|
|
781
|
+
* clamped to [OPENCODE_TIMEOUT_MS_MIN, OPENCODE_TIMEOUT_MS_MAX].
|
|
782
|
+
*/
|
|
783
|
+
export function normalizeOpencodeTimeoutMs(value) {
|
|
784
|
+
let numeric = value;
|
|
785
|
+
if (typeof value === "string") {
|
|
786
|
+
const trimmed = value.trim();
|
|
787
|
+
if (trimmed.length === 0)
|
|
788
|
+
return OPENCODE_TIMEOUT_MS_DEFAULT;
|
|
789
|
+
numeric = Number(trimmed);
|
|
790
|
+
}
|
|
791
|
+
if (typeof numeric !== "number" || !Number.isFinite(numeric)) {
|
|
792
|
+
return OPENCODE_TIMEOUT_MS_DEFAULT;
|
|
793
|
+
}
|
|
794
|
+
return Math.min(OPENCODE_TIMEOUT_MS_MAX, Math.max(OPENCODE_TIMEOUT_MS_MIN, numeric));
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Margin added to the configured structured-output timeout for the outer
|
|
798
|
+
* safety-net races around generateStructuredOutput calls: the inner, more
|
|
799
|
+
* informative provider timeout always fires first.
|
|
800
|
+
*/
|
|
801
|
+
export const OPENCODE_TIMEOUT_OUTER_MARGIN_MS = 30_000;
|
|
802
|
+
/**
|
|
803
|
+
* Outer safety-net timeout wrapping one structured-output call, derived from
|
|
804
|
+
* the configured timeout plus a fixed margin.
|
|
805
|
+
*/
|
|
806
|
+
export function outerStructuredOutputTimeoutMs(configured) {
|
|
807
|
+
return (configured ?? OPENCODE_TIMEOUT_MS_DEFAULT) + OPENCODE_TIMEOUT_OUTER_MARGIN_MS;
|
|
808
|
+
}
|
|
809
|
+
export function normalizeChatMessageRecall(value) {
|
|
810
|
+
if (value === "recent" || value === "relevant" || value === "both")
|
|
811
|
+
return value;
|
|
812
|
+
return "relevant";
|
|
813
|
+
}
|
|
814
|
+
export function normalizeChatMessageRecallScope(value) {
|
|
815
|
+
if (value === "project" || value === "all-projects" || value === "default")
|
|
816
|
+
return value;
|
|
817
|
+
return "default";
|
|
818
|
+
}
|
|
819
|
+
export function normalizeDreamingIntervalHours(value) {
|
|
820
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
821
|
+
return 24;
|
|
822
|
+
}
|
|
823
|
+
return Math.max(1, Math.trunc(value));
|
|
824
|
+
}
|
|
825
|
+
export function normalizeDreamingMaxGroupsPerRun(value) {
|
|
826
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
827
|
+
return 5;
|
|
828
|
+
}
|
|
829
|
+
return Math.max(1, Math.trunc(value));
|
|
830
|
+
}
|
|
831
|
+
export function normalizeDreamingTrashRetentionDays(value) {
|
|
832
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
833
|
+
return 30;
|
|
834
|
+
}
|
|
835
|
+
return value;
|
|
836
|
+
}
|
|
837
|
+
export function normalizeSimilarityUnitInterval(value, fallback) {
|
|
838
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
839
|
+
return fallback;
|
|
840
|
+
}
|
|
841
|
+
if (value < 0)
|
|
842
|
+
return 0;
|
|
843
|
+
if (value > 1)
|
|
844
|
+
return 1;
|
|
845
|
+
return value;
|
|
846
|
+
}
|
|
847
|
+
export function normalizeUpdateOnCaptureMaxCandidates(value) {
|
|
848
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
849
|
+
return 5;
|
|
850
|
+
}
|
|
851
|
+
return Math.max(1, Math.min(20, Math.trunc(value)));
|
|
852
|
+
}
|
|
853
|
+
export function normalizeDreamingRelatedThreshold(value) {
|
|
854
|
+
return normalizeSimilarityUnitInterval(value, 0.75);
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* User-supplied markers extend the built-in set rather than replacing it, so
|
|
858
|
+
* adding one marker cannot silently disable protection against all the others.
|
|
859
|
+
*/
|
|
860
|
+
export function normalizeInjectionMarkers(value) {
|
|
861
|
+
const defaults = getDefaultInjectionMarkers();
|
|
862
|
+
if (value === undefined)
|
|
863
|
+
return [...defaults];
|
|
864
|
+
if (!Array.isArray(value)) {
|
|
865
|
+
throw new Error(`Invalid chatMessage.injectionMarkers config: expected an array`);
|
|
866
|
+
}
|
|
867
|
+
const merged = [...defaults];
|
|
868
|
+
for (const marker of value) {
|
|
869
|
+
if (typeof marker !== "string") {
|
|
870
|
+
throw new Error(`Invalid chatMessage.injectionMarkers entry: expected a string, got ${typeof marker}`);
|
|
871
|
+
}
|
|
872
|
+
const trimmed = marker.trim();
|
|
873
|
+
if (!trimmed)
|
|
874
|
+
continue;
|
|
875
|
+
if (!merged.some((existing) => existing.toLowerCase() === trimmed.toLowerCase())) {
|
|
876
|
+
merged.push(trimmed);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return merged;
|
|
880
|
+
}
|
|
881
|
+
function buildConfig(fileConfig) {
|
|
882
|
+
const memoryProvider = (fileConfig.memoryProvider ?? "openai-chat");
|
|
883
|
+
const memoryApiKey = resolveSecretValue(fileConfig.memoryApiKey) ??
|
|
884
|
+
(memoryProvider === "atlas-cloud"
|
|
885
|
+
? process.env.ATLASCLOUD_API_KEY
|
|
886
|
+
: memoryProvider === "cheaper-inference"
|
|
887
|
+
? process.env.CHEAPER_INFERENCE_API_KEY
|
|
888
|
+
: memoryProvider === "api-route"
|
|
889
|
+
? process.env.API_ROUTE_API_KEY
|
|
890
|
+
: memoryProvider === "runcrate"
|
|
891
|
+
? process.env.RUNCRATE_API_KEY
|
|
892
|
+
: memoryProvider === "cloudgpu"
|
|
893
|
+
? process.env.CLOUDGPU_API_KEY
|
|
894
|
+
: undefined);
|
|
895
|
+
const embeddingModel = fileConfig.embeddingModel ?? DEFAULTS.embeddingModel;
|
|
896
|
+
const embeddingPreset = getEmbeddingModelPreset(embeddingModel);
|
|
897
|
+
const embeddingDimensions = fileConfig.embeddingDimensions ?? getEmbeddingDimensions(embeddingModel);
|
|
898
|
+
const embeddingPooling = normalizeEmbeddingPooling(fileConfig.embeddingPooling ?? embeddingPreset?.pooling ?? DEFAULTS.embeddingPooling);
|
|
899
|
+
const embeddingQueryPrefix = fileConfig.embeddingQueryPrefix !== undefined
|
|
900
|
+
? fileConfig.embeddingQueryPrefix
|
|
901
|
+
: embeddingPreset?.queryPrefix;
|
|
902
|
+
const embeddingDocumentPrefix = fileConfig.embeddingDocumentPrefix !== undefined
|
|
903
|
+
? fileConfig.embeddingDocumentPrefix
|
|
904
|
+
: embeddingPreset?.documentPrefix;
|
|
905
|
+
const embeddingDtype = normalizeEmbeddingDtype(fileConfig.embeddingDtype);
|
|
906
|
+
const embeddingIdleTimeoutMs = normalizeEmbeddingIdleTimeoutMs(fileConfig.embeddingIdleTimeoutMs ?? DEFAULTS.embeddingIdleTimeoutMs);
|
|
907
|
+
const autoCaptureMaxContextBytes = normalizeAutoCaptureMaxContextBytes(fileConfig.autoCaptureMaxContextBytes ?? DEFAULTS.autoCaptureMaxContextBytes);
|
|
908
|
+
const userProfileAutoCleanupInterval = fileConfig.userProfileAutoCleanupInterval ?? DEFAULTS.userProfileAutoCleanupInterval;
|
|
909
|
+
if (!Number.isInteger(embeddingDimensions) ||
|
|
910
|
+
embeddingDimensions <= 0 ||
|
|
911
|
+
embeddingDimensions > 65536) {
|
|
912
|
+
throw new Error(`Invalid embeddingDimensions config: ${embeddingDimensions}`);
|
|
913
|
+
}
|
|
914
|
+
if (!Number.isInteger(userProfileAutoCleanupInterval) || userProfileAutoCleanupInterval <= 0) {
|
|
915
|
+
throw new Error(`Invalid userProfileAutoCleanupInterval config: ${userProfileAutoCleanupInterval}`);
|
|
916
|
+
}
|
|
917
|
+
const memoryBackend = normalizeMemoryBackend(fileConfig.memoryBackend);
|
|
918
|
+
const markdownPathRaw = typeof fileConfig.markdownPath === "string" ? fileConfig.markdownPath.trim() : "";
|
|
919
|
+
const markdownPath = markdownPathRaw ? expandPath(markdownPathRaw) : undefined;
|
|
920
|
+
if (memoryBackend === "markdown" && !markdownPath) {
|
|
921
|
+
throw new Error('memoryBackend "markdown" requires markdownPath to be set');
|
|
922
|
+
}
|
|
923
|
+
return {
|
|
924
|
+
storagePath: expandPath(fileConfig.storagePath ?? DEFAULTS.storagePath),
|
|
925
|
+
memoryBackend,
|
|
926
|
+
markdownPath,
|
|
927
|
+
userEmailOverride: fileConfig.userEmailOverride,
|
|
928
|
+
userNameOverride: fileConfig.userNameOverride,
|
|
929
|
+
embeddingModel,
|
|
930
|
+
embeddingDimensions,
|
|
931
|
+
embeddingUseTaskPrefixes: fileConfig.embeddingUseTaskPrefixes ?? DEFAULTS.embeddingUseTaskPrefixes,
|
|
932
|
+
embeddingPooling,
|
|
933
|
+
embeddingQueryPrefix,
|
|
934
|
+
embeddingDocumentPrefix,
|
|
935
|
+
embeddingDtype,
|
|
936
|
+
embeddingIdleTimeoutMs,
|
|
937
|
+
embeddingApiUrl: fileConfig.embeddingApiUrl,
|
|
938
|
+
embeddingApiKey: fileConfig.embeddingApiUrl
|
|
939
|
+
? resolveSecretValue(fileConfig.embeddingApiKey ?? process.env.OPENAI_API_KEY)
|
|
940
|
+
: undefined,
|
|
941
|
+
similarityThreshold: fileConfig.similarityThreshold ?? DEFAULTS.similarityThreshold,
|
|
942
|
+
maxMemories: fileConfig.maxMemories ?? DEFAULTS.maxMemories,
|
|
943
|
+
/**
|
|
944
|
+
* @deprecated No effect. Use userProfileInjectPreferences, userProfileInjectPatterns,
|
|
945
|
+
* and userProfileInjectWorkflows to limit injected profile context.
|
|
946
|
+
*/
|
|
947
|
+
maxProfileItems: fileConfig.maxProfileItems ?? DEFAULTS.maxProfileItems,
|
|
948
|
+
injectProfile: fileConfig.injectProfile ?? DEFAULTS.injectProfile,
|
|
949
|
+
containerTagPrefix: fileConfig.containerTagPrefix ?? DEFAULTS.containerTagPrefix,
|
|
950
|
+
autoCaptureEnabled: fileConfig.autoCaptureEnabled ?? DEFAULTS.autoCaptureEnabled,
|
|
951
|
+
autoCaptureMaxIterations: fileConfig.autoCaptureMaxIterations ?? DEFAULTS.autoCaptureMaxIterations,
|
|
952
|
+
autoCaptureIterationTimeout: fileConfig.autoCaptureIterationTimeout ?? DEFAULTS.autoCaptureIterationTimeout,
|
|
953
|
+
autoCaptureMaxRetries: fileConfig.autoCaptureMaxRetries ?? DEFAULTS.autoCaptureMaxRetries,
|
|
954
|
+
autoCaptureMaxContextBytes,
|
|
955
|
+
autoCaptureLanguage: fileConfig.autoCaptureLanguage,
|
|
956
|
+
autoCaptureProviderOrder: normalizeAutoCaptureProviderOrder(fileConfig.autoCaptureProviderOrder),
|
|
957
|
+
updateOnCaptureEnabled: fileConfig.updateOnCaptureEnabled ?? DEFAULTS.updateOnCaptureEnabled,
|
|
958
|
+
updateOnCaptureSimilarityThreshold: normalizeSimilarityUnitInterval(fileConfig.updateOnCaptureSimilarityThreshold, DEFAULTS.updateOnCaptureSimilarityThreshold),
|
|
959
|
+
updateOnCaptureMaxCandidates: normalizeUpdateOnCaptureMaxCandidates(fileConfig.updateOnCaptureMaxCandidates),
|
|
960
|
+
memoryProvider,
|
|
961
|
+
memoryModel: fileConfig.memoryModel,
|
|
962
|
+
memoryApiUrl: fileConfig.memoryApiUrl,
|
|
963
|
+
memoryApiKey,
|
|
964
|
+
memoryTemperature: fileConfig.memoryTemperature,
|
|
965
|
+
forceToolChoice: fileConfig.forceToolChoice,
|
|
966
|
+
memoryExtraParams: fileConfig.memoryExtraParams,
|
|
967
|
+
opencodeProvider: fileConfig.opencodeProvider,
|
|
968
|
+
opencodeModel: fileConfig.opencodeModel,
|
|
969
|
+
opencodeVariant: normalizeOpencodeVariant(fileConfig.opencodeVariant),
|
|
970
|
+
opencodeTimeoutMs: normalizeOpencodeTimeoutMs(fileConfig.opencodeTimeoutMs),
|
|
971
|
+
autoCaptureProviderStatus: getAutoCaptureProviderStatus({
|
|
972
|
+
opencodeProvider: fileConfig.opencodeProvider,
|
|
973
|
+
opencodeModel: fileConfig.opencodeModel,
|
|
974
|
+
memoryProvider,
|
|
975
|
+
memoryModel: fileConfig.memoryModel,
|
|
976
|
+
memoryApiUrl: fileConfig.memoryApiUrl,
|
|
977
|
+
memoryApiKey,
|
|
978
|
+
}),
|
|
979
|
+
aiSessionRetentionDays: fileConfig.aiSessionRetentionDays ?? DEFAULTS.aiSessionRetentionDays,
|
|
980
|
+
webServerEnabled: fileConfig.webServerEnabled ?? DEFAULTS.webServerEnabled,
|
|
981
|
+
webServerPort: fileConfig.webServerPort ?? DEFAULTS.webServerPort,
|
|
982
|
+
webServerHost: fileConfig.webServerHost ?? DEFAULTS.webServerHost,
|
|
983
|
+
webServerAuthPassword: resolveSecretValue(fileConfig.webServerAuthPassword),
|
|
984
|
+
webServerAuthUsername: fileConfig.webServerAuthUsername,
|
|
985
|
+
webServerApiToken: fileConfig.webServerApiToken
|
|
986
|
+
? resolveSecretValue(fileConfig.webServerApiToken)
|
|
987
|
+
: undefined,
|
|
988
|
+
maxVectorsPerShard: fileConfig.maxVectorsPerShard ?? DEFAULTS.maxVectorsPerShard,
|
|
989
|
+
autoCleanupEnabled: fileConfig.autoCleanupEnabled ?? DEFAULTS.autoCleanupEnabled,
|
|
990
|
+
autoCleanupRetentionDays: normalizeAutoCleanupRetentionDays(fileConfig.autoCleanupRetentionDays ?? DEFAULTS.autoCleanupRetentionDays),
|
|
991
|
+
deduplicationEnabled: fileConfig.deduplicationEnabled ?? DEFAULTS.deduplicationEnabled,
|
|
992
|
+
deduplicationSimilarityThreshold: fileConfig.deduplicationSimilarityThreshold ?? DEFAULTS.deduplicationSimilarityThreshold,
|
|
993
|
+
userProfileAnalysisInterval: fileConfig.userProfileAnalysisInterval ?? DEFAULTS.userProfileAnalysisInterval,
|
|
994
|
+
userProfileMaxContextBytes: fileConfig.userProfileMaxContextBytes ?? DEFAULTS.userProfileMaxContextBytes,
|
|
995
|
+
/**
|
|
996
|
+
* @deprecated No effect on the UI. Use userProfileInjectPreferences for LLM context only.
|
|
997
|
+
*/
|
|
998
|
+
userProfileDisplayPreferences: fileConfig.userProfileDisplayPreferences ?? DEFAULTS.userProfileDisplayPreferences,
|
|
999
|
+
/**
|
|
1000
|
+
* @deprecated No effect on the UI. Use userProfileInjectPatterns for LLM context only.
|
|
1001
|
+
*/
|
|
1002
|
+
userProfileDisplayPatterns: fileConfig.userProfileDisplayPatterns ?? DEFAULTS.userProfileDisplayPatterns,
|
|
1003
|
+
/**
|
|
1004
|
+
* @deprecated No effect on the UI. Use userProfileInjectWorkflows for LLM context only.
|
|
1005
|
+
*/
|
|
1006
|
+
userProfileDisplayWorkflows: fileConfig.userProfileDisplayWorkflows ?? DEFAULTS.userProfileDisplayWorkflows,
|
|
1007
|
+
userProfileInjectPreferences: fileConfig.userProfileInjectPreferences ?? DEFAULTS.userProfileInjectPreferences,
|
|
1008
|
+
userProfileInjectPatterns: fileConfig.userProfileInjectPatterns ?? DEFAULTS.userProfileInjectPatterns,
|
|
1009
|
+
userProfileInjectWorkflows: fileConfig.userProfileInjectWorkflows ?? DEFAULTS.userProfileInjectWorkflows,
|
|
1010
|
+
userProfileConfidenceDecayDays: fileConfig.userProfileConfidenceDecayDays ?? DEFAULTS.userProfileConfidenceDecayDays,
|
|
1011
|
+
userProfileChangelogRetentionCount: fileConfig.userProfileChangelogRetentionCount ?? DEFAULTS.userProfileChangelogRetentionCount,
|
|
1012
|
+
userProfileEmbeddingThresholdSameCat: fileConfig.userProfileEmbeddingThresholdSameCat ??
|
|
1013
|
+
DEFAULTS.userProfileEmbeddingThresholdSameCat,
|
|
1014
|
+
userProfileEmbeddingThresholdSameCatWeak: fileConfig.userProfileEmbeddingThresholdSameCatWeak ??
|
|
1015
|
+
DEFAULTS.userProfileEmbeddingThresholdSameCatWeak,
|
|
1016
|
+
userProfileEmbeddingThresholdCrossCat: fileConfig.userProfileEmbeddingThresholdCrossCat ??
|
|
1017
|
+
DEFAULTS.userProfileEmbeddingThresholdCrossCat,
|
|
1018
|
+
userProfileEmbeddingThresholdCrossCatWeak: fileConfig.userProfileEmbeddingThresholdCrossCatWeak ??
|
|
1019
|
+
DEFAULTS.userProfileEmbeddingThresholdCrossCatWeak,
|
|
1020
|
+
userProfileCentroidDriftThreshold: fileConfig.userProfileCentroidDriftThreshold ?? DEFAULTS.userProfileCentroidDriftThreshold,
|
|
1021
|
+
userProfileEmbeddingMinDescriptionLength: fileConfig.userProfileEmbeddingMinDescriptionLength ??
|
|
1022
|
+
DEFAULTS.userProfileEmbeddingMinDescriptionLength,
|
|
1023
|
+
userProfileMinEvidenceForRetention: fileConfig.userProfileMinEvidenceForRetention ?? DEFAULTS.userProfileMinEvidenceForRetention,
|
|
1024
|
+
userProfileAutoCleanupEnabled: fileConfig.userProfileAutoCleanupEnabled ?? DEFAULTS.userProfileAutoCleanupEnabled,
|
|
1025
|
+
userProfileAutoCleanupInterval,
|
|
1026
|
+
userProfileValidationEnabled: fileConfig.userProfileValidationEnabled ?? DEFAULTS.userProfileValidationEnabled,
|
|
1027
|
+
userProfileStaleDays: fileConfig.userProfileStaleDays ?? DEFAULTS.userProfileStaleDays,
|
|
1028
|
+
showAutoCaptureToasts: fileConfig.showAutoCaptureToasts ?? DEFAULTS.showAutoCaptureToasts,
|
|
1029
|
+
showUserProfileToasts: fileConfig.showUserProfileToasts ?? DEFAULTS.showUserProfileToasts,
|
|
1030
|
+
showErrorToasts: fileConfig.showErrorToasts ?? DEFAULTS.showErrorToasts,
|
|
1031
|
+
databaseEncryptionEnabled: fileConfig.databaseEncryptionEnabled ?? DEFAULTS.databaseEncryptionEnabled,
|
|
1032
|
+
// Keep raw ref (env:// / file:// / hex); resolved lazily with optional auto-create.
|
|
1033
|
+
databaseEncryptionKey: fileConfig.databaseEncryptionKey,
|
|
1034
|
+
databaseEncryptionCipher: fileConfig.databaseEncryptionCipher ?? DEFAULTS.databaseEncryptionCipher,
|
|
1035
|
+
autoUpdate: fileConfig.autoUpdate ?? DEFAULTS.autoUpdate,
|
|
1036
|
+
tursoAutoHeal: fileConfig.tursoAutoHeal ?? DEFAULTS.tursoAutoHeal,
|
|
1037
|
+
tursoMultiprocessWal: fileConfig.tursoMultiprocessWal ?? DEFAULTS.tursoMultiprocessWal,
|
|
1038
|
+
memory: {
|
|
1039
|
+
defaultScope: fileConfig.memory?.defaultScope ?? DEFAULTS.memory.defaultScope,
|
|
1040
|
+
},
|
|
1041
|
+
compaction: {
|
|
1042
|
+
enabled: fileConfig.compaction?.enabled ?? DEFAULTS.compaction.enabled,
|
|
1043
|
+
memoryLimit: fileConfig.compaction?.memoryLimit ?? DEFAULTS.compaction.memoryLimit,
|
|
1044
|
+
},
|
|
1045
|
+
chatMessage: {
|
|
1046
|
+
enabled: fileConfig.chatMessage?.enabled ?? DEFAULTS.chatMessage.enabled,
|
|
1047
|
+
maxMemories: fileConfig.chatMessage?.maxMemories ?? DEFAULTS.chatMessage.maxMemories,
|
|
1048
|
+
excludeCurrentSession: fileConfig.chatMessage?.excludeCurrentSession ?? DEFAULTS.chatMessage.excludeCurrentSession,
|
|
1049
|
+
maxAgeDays: fileConfig.chatMessage?.maxAgeDays,
|
|
1050
|
+
injectOn: (fileConfig.chatMessage?.injectOn ?? DEFAULTS.chatMessage.injectOn),
|
|
1051
|
+
recall: normalizeChatMessageRecall(fileConfig.chatMessage?.recall),
|
|
1052
|
+
recallScope: normalizeChatMessageRecallScope(fileConfig.chatMessage?.recallScope),
|
|
1053
|
+
similarityThreshold: typeof fileConfig.chatMessage?.similarityThreshold === "number" &&
|
|
1054
|
+
Number.isFinite(fileConfig.chatMessage.similarityThreshold)
|
|
1055
|
+
? fileConfig.chatMessage.similarityThreshold
|
|
1056
|
+
: DEFAULTS.chatMessage.similarityThreshold,
|
|
1057
|
+
filterInjectedPrompts: fileConfig.chatMessage?.filterInjectedPrompts ?? DEFAULTS.chatMessage.filterInjectedPrompts,
|
|
1058
|
+
injectionMarkers: normalizeInjectionMarkers(fileConfig.chatMessage?.injectionMarkers),
|
|
1059
|
+
captureChildSessions: fileConfig.chatMessage?.captureChildSessions ?? DEFAULTS.chatMessage.captureChildSessions,
|
|
1060
|
+
},
|
|
1061
|
+
dreaming: {
|
|
1062
|
+
enabled: fileConfig.dreaming?.enabled ?? DEFAULTS.dreaming.enabled,
|
|
1063
|
+
intervalHours: normalizeDreamingIntervalHours(fileConfig.dreaming?.intervalHours),
|
|
1064
|
+
maxGroupsPerRun: normalizeDreamingMaxGroupsPerRun(fileConfig.dreaming?.maxGroupsPerRun),
|
|
1065
|
+
trashRetentionDays: normalizeDreamingTrashRetentionDays(fileConfig.dreaming?.trashRetentionDays),
|
|
1066
|
+
relatedThreshold: normalizeDreamingRelatedThreshold(fileConfig.dreaming?.relatedThreshold),
|
|
1067
|
+
crossProject: fileConfig.dreaming?.crossProject ?? DEFAULTS.dreaming.crossProject,
|
|
1068
|
+
},
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
const _globalFileConfig = loadConfigFromPaths(CONFIG_FILES);
|
|
1072
|
+
export let CONFIG = buildConfig(_globalFileConfig);
|
|
1073
|
+
function hasValue(value) {
|
|
1074
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
1075
|
+
}
|
|
1076
|
+
export { isPlaceholderApiKey };
|
|
1077
|
+
export function getAutoCaptureProviderStatus(config) {
|
|
1078
|
+
const hasOpencodeProvider = hasValue(config.opencodeProvider);
|
|
1079
|
+
const hasOpencodeModel = hasValue(config.opencodeModel);
|
|
1080
|
+
if (hasOpencodeProvider && hasOpencodeModel) {
|
|
1081
|
+
return { ready: true, mode: "opencode", issues: [] };
|
|
1082
|
+
}
|
|
1083
|
+
const issues = [];
|
|
1084
|
+
if (!hasOpencodeProvider)
|
|
1085
|
+
issues.push("opencodeProvider is not configured");
|
|
1086
|
+
if (!hasOpencodeModel)
|
|
1087
|
+
issues.push("opencodeModel is not configured");
|
|
1088
|
+
const hasMemoryModel = hasValue(config.memoryModel);
|
|
1089
|
+
const hasMemoryApiUrl = hasValue(config.memoryApiUrl);
|
|
1090
|
+
const hasMemoryApiKey = hasValue(config.memoryApiKey);
|
|
1091
|
+
const hasPlaceholderMemoryApiKey = isPlaceholderApiKey(config.memoryApiKey);
|
|
1092
|
+
// Preset providers fill endpoint/model themselves, so only an API key is
|
|
1093
|
+
// required for the manual fallback path.
|
|
1094
|
+
if (config.memoryProvider === "orcarouter" ||
|
|
1095
|
+
config.memoryProvider === "atlas-cloud" ||
|
|
1096
|
+
config.memoryProvider === "cheaper-inference" ||
|
|
1097
|
+
config.memoryProvider === "api-route" ||
|
|
1098
|
+
config.memoryProvider === "runcrate" ||
|
|
1099
|
+
config.memoryProvider === "cloudgpu") {
|
|
1100
|
+
if (!hasMemoryApiKey)
|
|
1101
|
+
issues.push("memoryApiKey is not configured");
|
|
1102
|
+
if (hasPlaceholderMemoryApiKey)
|
|
1103
|
+
issues.push("memoryApiKey contains a placeholder value");
|
|
1104
|
+
if (hasMemoryApiKey && !hasPlaceholderMemoryApiKey) {
|
|
1105
|
+
return { ready: true, mode: "manual", issues: [] };
|
|
1106
|
+
}
|
|
1107
|
+
return { ready: false, issues };
|
|
1108
|
+
}
|
|
1109
|
+
if (!hasMemoryModel)
|
|
1110
|
+
issues.push("memoryModel is not configured");
|
|
1111
|
+
if (!hasMemoryApiUrl)
|
|
1112
|
+
issues.push("memoryApiUrl is not configured");
|
|
1113
|
+
if (!hasMemoryApiKey)
|
|
1114
|
+
issues.push("memoryApiKey is not configured");
|
|
1115
|
+
if (hasPlaceholderMemoryApiKey)
|
|
1116
|
+
issues.push("memoryApiKey contains a placeholder value");
|
|
1117
|
+
if (hasMemoryModel && hasMemoryApiUrl && hasMemoryApiKey && !hasPlaceholderMemoryApiKey) {
|
|
1118
|
+
return { ready: true, mode: "manual", issues: [] };
|
|
1119
|
+
}
|
|
1120
|
+
return { ready: false, issues };
|
|
1121
|
+
}
|
|
1122
|
+
export function hasAutoCaptureProviderConfig(config = CONFIG) {
|
|
1123
|
+
return getAutoCaptureProviderStatus(config).ready;
|
|
1124
|
+
}
|
|
1125
|
+
export function initConfig(directory) {
|
|
1126
|
+
const projectPaths = [
|
|
1127
|
+
join(directory, ".opencode", "opencode-mem.jsonc"),
|
|
1128
|
+
join(directory, ".opencode", "opencode-mem.json"),
|
|
1129
|
+
];
|
|
1130
|
+
const globalConfig = loadConfigFromPaths(CONFIG_FILES);
|
|
1131
|
+
const projectConfig = loadConfigFromPaths(projectPaths);
|
|
1132
|
+
assertProjectRemoteProviderConfigIsSafe(projectConfig);
|
|
1133
|
+
const projectOverrides = { ...projectConfig };
|
|
1134
|
+
delete projectOverrides.autoCleanupEnabled;
|
|
1135
|
+
delete projectOverrides.autoCleanupRetentionDays;
|
|
1136
|
+
const merged = { ...globalConfig, ...projectOverrides };
|
|
1137
|
+
CONFIG = buildConfig(merged);
|
|
1138
|
+
}
|
|
1139
|
+
export function isConfigured() {
|
|
1140
|
+
return true;
|
|
1141
|
+
}
|