@aislop-inc/opencode-mem 0.0.0-stage → 2.41.1
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,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Force resolution of `onnxruntime-node` (and its `onnxruntime-common`) to this
|
|
3
|
+
* package's direct dependency stack.
|
|
4
|
+
*
|
|
5
|
+
* OpenCode installs plugins nested under its own cache. npm/Arborist only honors
|
|
6
|
+
* `overrides` at the install root, so `@huggingface/transformers` would otherwise
|
|
7
|
+
* keep nested `onnxruntime-node@1.24.3` (no darwin/x64 binding). See #184 / #158 / #210.
|
|
8
|
+
*
|
|
9
|
+
* We pin onnxruntime-node@1.31.1:
|
|
10
|
+
* - 1.21.0–1.23.2 crash during macOS Ort::Env process-exit teardown (#225 /
|
|
11
|
+
* microsoft/onnxruntime#24579); the fix shipped in 1.24.1
|
|
12
|
+
* - fixed releases still lack darwin/x64 binaries (microsoft/onnxruntime#27961);
|
|
13
|
+
* Intel Mac (darwin/x64) is unsupported for local embeddings
|
|
14
|
+
* - Overrides transformers' older declared onnxruntime-node so nested installs
|
|
15
|
+
* still resolve to this direct pin
|
|
16
|
+
*
|
|
17
|
+
* Transformers must be loaded via its CJS export so this Module._resolveFilename
|
|
18
|
+
* shim applies; the ESM entry's static `import "onnxruntime-node"` bypasses it.
|
|
19
|
+
*/
|
|
20
|
+
import { createRequire } from "node:module";
|
|
21
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
22
|
+
import { dirname, join } from "node:path";
|
|
23
|
+
import { createRuntimeRequire } from "./runtime-require.js";
|
|
24
|
+
const PACKAGE_NAME = "onnxruntime-node";
|
|
25
|
+
const COMMON_PACKAGE = "onnxruntime-common";
|
|
26
|
+
const PINNED_VERSION_HINT = "1.31.1";
|
|
27
|
+
const requireFromHere = createRuntimeRequire(import.meta);
|
|
28
|
+
let shimInstalled = false;
|
|
29
|
+
let pinnedPackageRoot = null;
|
|
30
|
+
let pinnedNodeEntry = null;
|
|
31
|
+
let pinnedCommonEntry = null;
|
|
32
|
+
function getPinnedOnnxruntimeEntry() {
|
|
33
|
+
if (pinnedNodeEntry)
|
|
34
|
+
return pinnedNodeEntry;
|
|
35
|
+
pinnedNodeEntry = requireFromHere.resolve(PACKAGE_NAME);
|
|
36
|
+
return pinnedNodeEntry;
|
|
37
|
+
}
|
|
38
|
+
function getPinnedOnnxruntimeCommonEntry() {
|
|
39
|
+
if (pinnedCommonEntry)
|
|
40
|
+
return pinnedCommonEntry;
|
|
41
|
+
// Resolve common from the pinned node package so we always get the pinned stack,
|
|
42
|
+
// whether the package manager hoists it or nests it under onnxruntime-node.
|
|
43
|
+
pinnedCommonEntry = createRequire(getPinnedOnnxruntimeEntry()).resolve(COMMON_PACKAGE);
|
|
44
|
+
return pinnedCommonEntry;
|
|
45
|
+
}
|
|
46
|
+
export function getPinnedOnnxruntimePackageRoot() {
|
|
47
|
+
if (pinnedPackageRoot)
|
|
48
|
+
return pinnedPackageRoot;
|
|
49
|
+
const entry = getPinnedOnnxruntimeEntry();
|
|
50
|
+
// package entry is typically …/dist/index.js — walk up to package root
|
|
51
|
+
let dir = dirname(entry);
|
|
52
|
+
for (let i = 0; i < 4; i++) {
|
|
53
|
+
if (existsSync(join(dir, "package.json"))) {
|
|
54
|
+
pinnedPackageRoot = dir;
|
|
55
|
+
return dir;
|
|
56
|
+
}
|
|
57
|
+
dir = dirname(dir);
|
|
58
|
+
}
|
|
59
|
+
pinnedPackageRoot = dirname(entry);
|
|
60
|
+
return pinnedPackageRoot;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve the N-API layout directory shipped by the pinned onnxruntime-node
|
|
64
|
+
* package (`napi-v3` for 1.20.x, `napi-v6` for 1.22.x, …).
|
|
65
|
+
*/
|
|
66
|
+
export function getOnnxruntimeNapiDirName(platform = process.platform, arch = process.arch) {
|
|
67
|
+
const binDir = join(getPinnedOnnxruntimePackageRoot(), "bin");
|
|
68
|
+
if (!existsSync(binDir))
|
|
69
|
+
return "napi-v3";
|
|
70
|
+
let entries;
|
|
71
|
+
try {
|
|
72
|
+
entries = readdirSync(binDir, { withFileTypes: true })
|
|
73
|
+
.filter((entry) => entry.isDirectory() && /^napi-v\d+$/.test(entry.name))
|
|
74
|
+
.map((entry) => entry.name)
|
|
75
|
+
.sort((a, b) => Number(a.slice("napi-v".length)) - Number(b.slice("napi-v".length)));
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return "napi-v3";
|
|
79
|
+
}
|
|
80
|
+
// Prefer a layout that actually contains the platform binding.
|
|
81
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
82
|
+
const name = entries[i];
|
|
83
|
+
if (existsSync(join(binDir, name, platform, arch, "onnxruntime_binding.node"))) {
|
|
84
|
+
return name;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return entries.at(-1) ?? "napi-v3";
|
|
88
|
+
}
|
|
89
|
+
export function getOnnxruntimeBindingPath(platform = process.platform, arch = process.arch) {
|
|
90
|
+
return join(getPinnedOnnxruntimePackageRoot(), "bin", getOnnxruntimeNapiDirName(platform, arch), platform, arch, "onnxruntime_binding.node");
|
|
91
|
+
}
|
|
92
|
+
export function formatMissingOnnxruntimeBindingError(platform = process.platform, arch = process.arch) {
|
|
93
|
+
const bindingPath = getOnnxruntimeBindingPath(platform, arch);
|
|
94
|
+
const intelHint = platform === "darwin" && arch === "x64"
|
|
95
|
+
? ` Intel Mac (darwin/x64) is unsupported for local embeddings: onnxruntime-node@${PINNED_VERSION_HINT} ships no x64 binding (microsoft/onnxruntime#27961). Configure remote embeddings via embeddingApiUrl + embeddingApiKey, or use Apple Silicon, Linux, or Windows.`
|
|
96
|
+
: ` Configure remote embeddings via embeddingApiUrl + embeddingApiKey, or reinstall the plugin so onnxruntime-node@${PINNED_VERSION_HINT} is used.`;
|
|
97
|
+
return `Local embedding native binding missing for ${platform}/${arch} at ${bindingPath}.${intelHint}`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Rewrite onnxruntime-related init failures.
|
|
101
|
+
*
|
|
102
|
+
* When the pinned binding is absent, keep the clear "missing" message.
|
|
103
|
+
* When it is present, preserve the original error so nested-1.24 / dlopen /
|
|
104
|
+
* codesign failures are not misreported as a missing pinned binding (#210).
|
|
105
|
+
*/
|
|
106
|
+
export function formatOnnxruntimeInitError(error, platform = process.platform, arch = process.arch) {
|
|
107
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
108
|
+
const isOnnxRelated = message.includes("onnxruntime_binding.node") ||
|
|
109
|
+
message.includes("onnxruntime-node") ||
|
|
110
|
+
message.includes("onnxruntime-common") ||
|
|
111
|
+
/napi-v\d+\/[^/]+\/[^/]+/.test(message);
|
|
112
|
+
if (!isOnnxRelated) {
|
|
113
|
+
return error instanceof Error ? error : new Error(message);
|
|
114
|
+
}
|
|
115
|
+
const bindingPath = getOnnxruntimeBindingPath(platform, arch);
|
|
116
|
+
if (!existsSync(bindingPath)) {
|
|
117
|
+
return new Error(formatMissingOnnxruntimeBindingError(platform, arch), { cause: error });
|
|
118
|
+
}
|
|
119
|
+
const intelHint = platform === "darwin" && arch === "x64"
|
|
120
|
+
? ` Intel Mac (darwin/x64) is unsupported for local embeddings; opencode-mem pins ${PINNED_VERSION_HINT} (no x64 binding).`
|
|
121
|
+
: "";
|
|
122
|
+
return new Error(`ONNX runtime failed to load despite pinned binding being present at ${bindingPath}. Original error: ${message}.${intelHint} If this persists after updating, clear OpenCode's plugin cache (~/.cache/opencode/packages/opencode-mem@*) and reinstall, or configure remote embeddings via embeddingApiUrl + embeddingApiKey.`, { cause: error });
|
|
123
|
+
}
|
|
124
|
+
export function assertOnnxruntimeBindingPresent(platform = process.platform, arch = process.arch) {
|
|
125
|
+
const bindingPath = getOnnxruntimeBindingPath(platform, arch);
|
|
126
|
+
if (!existsSync(bindingPath)) {
|
|
127
|
+
throw new Error(formatMissingOnnxruntimeBindingError(platform, arch));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function resolvePinnedRequest(request, packageName, pinnedEntry) {
|
|
131
|
+
if (request !== packageName && !request.startsWith(`${packageName}/`)) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
if (packageName === PACKAGE_NAME) {
|
|
136
|
+
return requireFromHere.resolve(request);
|
|
137
|
+
}
|
|
138
|
+
return createRequire(getPinnedOnnxruntimeEntry()).resolve(request);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
if (request === packageName)
|
|
142
|
+
return pinnedEntry;
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Patch Module._resolveFilename so require() of onnxruntime-node / onnxruntime-common
|
|
148
|
+
* from nested transformers resolves to our direct pinned dependency stack.
|
|
149
|
+
*/
|
|
150
|
+
export function installOnnxruntimeResolveShim() {
|
|
151
|
+
if (shimInstalled)
|
|
152
|
+
return;
|
|
153
|
+
// Resolve our pin first so a missing direct dep fails before transformers loads.
|
|
154
|
+
const pinnedEntry = getPinnedOnnxruntimeEntry();
|
|
155
|
+
const pinnedCommon = getPinnedOnnxruntimeCommonEntry();
|
|
156
|
+
const Module = requireFromHere("node:module");
|
|
157
|
+
const original = Module._resolveFilename;
|
|
158
|
+
Module._resolveFilename = function (request, parent, isMain, options) {
|
|
159
|
+
// Only intercept the onnx stack. Forwarding every other request through a
|
|
160
|
+
// wrapped _resolveFilename is required, but must not alter Bun --compile
|
|
161
|
+
// parent handling for unrelated packages (#210 follow-up).
|
|
162
|
+
const pinnedNode = resolvePinnedRequest(request, PACKAGE_NAME, pinnedEntry);
|
|
163
|
+
if (pinnedNode)
|
|
164
|
+
return pinnedNode;
|
|
165
|
+
const pinnedCommonResolved = resolvePinnedRequest(request, COMMON_PACKAGE, pinnedCommon);
|
|
166
|
+
if (pinnedCommonResolved)
|
|
167
|
+
return pinnedCommonResolved;
|
|
168
|
+
return original.call(this, request, parent, isMain, options);
|
|
169
|
+
};
|
|
170
|
+
shimInstalled = true;
|
|
171
|
+
}
|
|
172
|
+
/** Install resolve shim and fail fast if the platform binding is absent. */
|
|
173
|
+
export function prepareOnnxruntimeForTransformers() {
|
|
174
|
+
installOnnxruntimeResolveShim();
|
|
175
|
+
assertOnnxruntimeBindingPresent();
|
|
176
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replace every `<private>…</private>` region with `[REDACTED]`.
|
|
3
|
+
*
|
|
4
|
+
* Scans tags with a depth counter rather than matching pairs with a single
|
|
5
|
+
* regex, so that the two malformed shapes fail *closed*:
|
|
6
|
+
*
|
|
7
|
+
* - An **unclosed** `<private>` redacts to the end of the input. A non-greedy
|
|
8
|
+
* pair match found no closing tag and left the region untouched, so a typo or
|
|
9
|
+
* a truncated message stored the content verbatim.
|
|
10
|
+
* - **Nested** tags close at the outer tag, not the first inner one. Pair
|
|
11
|
+
* matching ended the region at the inner `</private>`, releasing the rest of
|
|
12
|
+
* the outer region and leaving a stray `</private>` in the output.
|
|
13
|
+
*
|
|
14
|
+
* Erring toward redaction is the only safe direction here: the caller persists
|
|
15
|
+
* this string, so a wrong guess in the other direction is an unrecoverable
|
|
16
|
+
* disclosure, while over-redacting merely loses text the user can retype.
|
|
17
|
+
*
|
|
18
|
+
* A `</private>` with no opener is markup rather than content, so it is dropped
|
|
19
|
+
* instead of being surfaced to the user as if it were part of their text.
|
|
20
|
+
*/
|
|
21
|
+
export declare function stripPrivateContent(content: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* True when nothing survives redaction — the caller refuses such a write rather
|
|
24
|
+
* than storing a message that is private in its entirety.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isFullyPrivate(content: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Best-effort protection for the plugin's memory text, before sending or saving
|
|
29
|
+
* it. Not a universal secret detector and not protection for OpenCode's original
|
|
30
|
+
* conversation or tool traffic. No raw matches are logged or retained.
|
|
31
|
+
*/
|
|
32
|
+
export declare function sanitizeMemoryContent(content: string): string;
|
|
33
|
+
/** JSON.stringify replacer: sanitize strings before escaping loses their syntax,
|
|
34
|
+
* and retain credential field context for literal values (including nesting).
|
|
35
|
+
* Other values pass through; serialization owns traversal, not this helper.
|
|
36
|
+
*/
|
|
37
|
+
export declare function sanitizeMemoryField(key: string, value: unknown): unknown;
|
|
38
|
+
//# sourceMappingURL=privacy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privacy.d.ts","sourceRoot":"","sources":["../../src/services/privacy.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA4C3D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGvD;AAmED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAoB7D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAMxE"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const REDACTED = "[REDACTED]";
|
|
2
|
+
// `<private>` / `</private>`, case-insensitive, tolerating whitespace inside the
|
|
3
|
+
// tag (`<private >`) the way an XML parser would.
|
|
4
|
+
const PRIVATE_TAG = /<(\/?)private\s*>/gi;
|
|
5
|
+
/**
|
|
6
|
+
* Replace every `<private>…</private>` region with `[REDACTED]`.
|
|
7
|
+
*
|
|
8
|
+
* Scans tags with a depth counter rather than matching pairs with a single
|
|
9
|
+
* regex, so that the two malformed shapes fail *closed*:
|
|
10
|
+
*
|
|
11
|
+
* - An **unclosed** `<private>` redacts to the end of the input. A non-greedy
|
|
12
|
+
* pair match found no closing tag and left the region untouched, so a typo or
|
|
13
|
+
* a truncated message stored the content verbatim.
|
|
14
|
+
* - **Nested** tags close at the outer tag, not the first inner one. Pair
|
|
15
|
+
* matching ended the region at the inner `</private>`, releasing the rest of
|
|
16
|
+
* the outer region and leaving a stray `</private>` in the output.
|
|
17
|
+
*
|
|
18
|
+
* Erring toward redaction is the only safe direction here: the caller persists
|
|
19
|
+
* this string, so a wrong guess in the other direction is an unrecoverable
|
|
20
|
+
* disclosure, while over-redacting merely loses text the user can retype.
|
|
21
|
+
*
|
|
22
|
+
* A `</private>` with no opener is markup rather than content, so it is dropped
|
|
23
|
+
* instead of being surfaced to the user as if it were part of their text.
|
|
24
|
+
*/
|
|
25
|
+
export function stripPrivateContent(content) {
|
|
26
|
+
if (!content.includes("<")) {
|
|
27
|
+
return content;
|
|
28
|
+
}
|
|
29
|
+
let result = "";
|
|
30
|
+
let depth = 0;
|
|
31
|
+
let cursor = 0;
|
|
32
|
+
PRIVATE_TAG.lastIndex = 0;
|
|
33
|
+
let match;
|
|
34
|
+
while ((match = PRIVATE_TAG.exec(content)) !== null) {
|
|
35
|
+
const isClosing = match[1] === "/";
|
|
36
|
+
if (!isClosing) {
|
|
37
|
+
if (depth === 0) {
|
|
38
|
+
result += content.slice(cursor, match.index);
|
|
39
|
+
}
|
|
40
|
+
depth++;
|
|
41
|
+
cursor = PRIVATE_TAG.lastIndex;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (depth === 0) {
|
|
45
|
+
// Stray closing tag: emit the text before it, drop the tag itself.
|
|
46
|
+
result += content.slice(cursor, match.index);
|
|
47
|
+
cursor = PRIVATE_TAG.lastIndex;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
depth--;
|
|
51
|
+
if (depth === 0) {
|
|
52
|
+
result += REDACTED;
|
|
53
|
+
}
|
|
54
|
+
cursor = PRIVATE_TAG.lastIndex;
|
|
55
|
+
}
|
|
56
|
+
if (depth > 0) {
|
|
57
|
+
// Unclosed region: everything from the opening tag onward stays private.
|
|
58
|
+
return result + REDACTED;
|
|
59
|
+
}
|
|
60
|
+
return result + content.slice(cursor);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* True when nothing survives redaction — the caller refuses such a write rather
|
|
64
|
+
* than storing a message that is private in its entirety.
|
|
65
|
+
*/
|
|
66
|
+
export function isFullyPrivate(content) {
|
|
67
|
+
const stripped = stripPrivateContent(content).trim();
|
|
68
|
+
return stripped === REDACTED || stripped === "";
|
|
69
|
+
}
|
|
70
|
+
// Deliberately recognizable formats, not an entropy detector: commit hashes,
|
|
71
|
+
// checksums, UUIDs and opaque application IDs are useful memory context.
|
|
72
|
+
const CREDENTIAL_PATTERNS = [
|
|
73
|
+
// GitHub now also issues stateless ghs_APPID_JWT installation tokens:
|
|
74
|
+
// https://github.blog/changelog/2026-04-24-notice-about-upcoming-new-format-for-github-app-installation-tokens/
|
|
75
|
+
[
|
|
76
|
+
/(?<![\w-])ghs_[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}(?![\w-])/g,
|
|
77
|
+
"github-token",
|
|
78
|
+
],
|
|
79
|
+
[/(?<![\w-])gh[pousr]_[A-Za-z0-9_]{36,}(?![\w-])/g, "github-token"],
|
|
80
|
+
[/(?<![\w-])github_pat_[A-Za-z0-9_]{40,}(?![\w-])/g, "github-token"],
|
|
81
|
+
[/(?<![\w-])sk-(?:proj-|svcacct-|ant-api\d+-)[A-Za-z0-9_-]{20,}(?![\w-])/g, "api-key"],
|
|
82
|
+
[/(?<![\w-])sk-or-v1-[a-fA-F0-9]{64}(?![\w-])/g, "api-key"],
|
|
83
|
+
[/(?<![\w-])sk-[A-Za-z0-9]{48}(?![\w-])/g, "api-key"],
|
|
84
|
+
[/(?<![\w-])AIza[A-Za-z0-9_-]{35}(?![\w-])/g, "api-key"],
|
|
85
|
+
[/(?<![\w-])xox[baprs]-[0-9]{6,}-[A-Za-z0-9-]{10,}(?![\w-])/g, "slack-token"],
|
|
86
|
+
[/(?<![\w])(?:AKIA|ASIA)[A-Z0-9]{16}(?![\w])/g, "aws-access-key"],
|
|
87
|
+
];
|
|
88
|
+
// Keep the authorization scheme, key name and surrounding syntax useful. Do
|
|
89
|
+
// not consume expressions (process.env.KEY, ${KEY}, config.key), ordinary code
|
|
90
|
+
// identifiers or common placeholders. Require letters and at least four digits
|
|
91
|
+
// in quoted literals or uppercase environment assignments. Bare lowercase
|
|
92
|
+
// values can be code references or YAML literals, so leave them ambiguous.
|
|
93
|
+
// Custom/short/all-letter secrets are not
|
|
94
|
+
// inferred; callers can use <private> for values without a recognizable shape.
|
|
95
|
+
const CREDENTIAL_KEY_NAME = String.raw `(?:[\w]+[_-])?(?:api[_-]?key|access[_-]?token|auth[_-]?token|client[_-]?secret|secret[_-]?key|password|passwd)`;
|
|
96
|
+
const CREDENTIAL_KEY = new RegExp(`^${CREDENTIAL_KEY_NAME}$`, "i");
|
|
97
|
+
const CREDENTIAL_ASSIGNMENT = new RegExp(String.raw `\b(${CREDENTIAL_KEY_NAME}\b["']?\s*[:=]\s*)(["']?)([A-Za-z0-9_+/=-]{8,})\2(?![\w.+/-])`, "gi");
|
|
98
|
+
function isPlaceholder(value) {
|
|
99
|
+
return /^(?:YOUR_|REPLACE_|EXAMPLE_|TOKEN_PLACEHOLDER$)/.test(value);
|
|
100
|
+
}
|
|
101
|
+
function hasCredentialEvidence(value) {
|
|
102
|
+
return !isPlaceholder(value) && /[a-z]/i.test(value) && (value.match(/\d/g)?.length ?? 0) >= 4;
|
|
103
|
+
}
|
|
104
|
+
function isCredentialLiteral(value) {
|
|
105
|
+
return /^[A-Za-z0-9_+/=-]{8,}$/.test(value) && hasCredentialEvidence(value);
|
|
106
|
+
}
|
|
107
|
+
const BEARER = /\b(Bearer[ \t]+)([A-Za-z0-9._~+/-]{12,}=*)(?![\w.~+/-])/gi;
|
|
108
|
+
function redactPrivateKeys(content) {
|
|
109
|
+
// A recognizable opener without a matching end marker fails closed to EOF,
|
|
110
|
+
// including a truncated opener missing its final dashes. Never retain a key
|
|
111
|
+
// body merely because capture was bounded or the user pasted malformed PEM.
|
|
112
|
+
const opener = /-----BEGIN ((?:[A-Z0-9]+ )?PRIVATE KEY)(?:-----)?/g;
|
|
113
|
+
let result = "";
|
|
114
|
+
let cursor = 0;
|
|
115
|
+
let match;
|
|
116
|
+
while ((match = opener.exec(content)) !== null) {
|
|
117
|
+
result += content.slice(cursor, match.index) + "[REDACTED:private-key]";
|
|
118
|
+
const endMarker = `-----END ${match[1]}-----`;
|
|
119
|
+
const end = content.indexOf(endMarker, opener.lastIndex);
|
|
120
|
+
if (end === -1)
|
|
121
|
+
return result;
|
|
122
|
+
cursor = end + endMarker.length;
|
|
123
|
+
opener.lastIndex = cursor;
|
|
124
|
+
}
|
|
125
|
+
return result + content.slice(cursor);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Best-effort protection for the plugin's memory text, before sending or saving
|
|
129
|
+
* it. Not a universal secret detector and not protection for OpenCode's original
|
|
130
|
+
* conversation or tool traffic. No raw matches are logged or retained.
|
|
131
|
+
*/
|
|
132
|
+
export function sanitizeMemoryContent(content) {
|
|
133
|
+
let result = redactPrivateKeys(stripPrivateContent(content));
|
|
134
|
+
for (const [pattern, kind] of CREDENTIAL_PATTERNS) {
|
|
135
|
+
result = result.replace(pattern, `[REDACTED:${kind}]`);
|
|
136
|
+
}
|
|
137
|
+
result = result.replace(BEARER, (match, prefix, value) => hasCredentialEvidence(value) ? `${prefix}[REDACTED:bearer-token]` : match);
|
|
138
|
+
return result.replace(CREDENTIAL_ASSIGNMENT, (match, prefix, quote, value, offset) => (quote ||
|
|
139
|
+
(/^[A-Z][A-Z0-9_]*\s*=\s*$/.test(prefix) &&
|
|
140
|
+
/^\s*(?:export\s+)?$/.test(result.slice(result.lastIndexOf("\n", offset - 1) + 1, offset)))) &&
|
|
141
|
+
isCredentialLiteral(value)
|
|
142
|
+
? `${prefix}${quote}[REDACTED:credential]${quote}`
|
|
143
|
+
: match);
|
|
144
|
+
}
|
|
145
|
+
/** JSON.stringify replacer: sanitize strings before escaping loses their syntax,
|
|
146
|
+
* and retain credential field context for literal values (including nesting).
|
|
147
|
+
* Other values pass through; serialization owns traversal, not this helper.
|
|
148
|
+
*/
|
|
149
|
+
export function sanitizeMemoryField(key, value) {
|
|
150
|
+
if (typeof value !== "string")
|
|
151
|
+
return value;
|
|
152
|
+
if (CREDENTIAL_KEY.test(key) && isCredentialLiteral(value)) {
|
|
153
|
+
return "[REDACTED:credential]";
|
|
154
|
+
}
|
|
155
|
+
return sanitizeMemoryContent(value);
|
|
156
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-timeouts.d.ts","sourceRoot":"","sources":["../../src/services/request-timeouts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mCAAmC,QAAS,CAAC;AAC1D,eAAO,MAAM,mCAAmC,SAAU,CAAC;AAI3D,eAAO,MAAM,yBAAyB,QAEf,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export const EXTERNAL_PROFILE_CLEANUP_TIMEOUT_MS = 60_000;
|
|
2
|
+
export const OPENCODE_PROFILE_CLEANUP_TIMEOUT_MS = 300_000;
|
|
3
|
+
const HTTP_TIMEOUT_GRACE_MS = 30_000;
|
|
4
|
+
export const NODE_HTTP_IDLE_TIMEOUT_MS = Math.max(EXTERNAL_PROFILE_CLEANUP_TIMEOUT_MS, OPENCODE_PROFILE_CLEANUP_TIMEOUT_MS) +
|
|
5
|
+
HTTP_TIMEOUT_GRACE_MS;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type RuntimeImportMeta = ImportMeta & {
|
|
2
|
+
require?: NodeRequire;
|
|
3
|
+
path?: string;
|
|
4
|
+
dirname?: string;
|
|
5
|
+
dir?: string;
|
|
6
|
+
resolve?: (specifier: string) => string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Build a require() for resolving/loading packages next to this plugin module.
|
|
10
|
+
* Throws a concrete diagnostic when no usable Bun/Node anchor exists.
|
|
11
|
+
*
|
|
12
|
+
* Prefer a path/url-anchored createRequire over Bun's import.meta.require when a
|
|
13
|
+
* concrete file anchor exists. In OpenCode's Bun --compile host, import.meta.url
|
|
14
|
+
* and import.meta.path are still valid for dynamically imported plugins even when
|
|
15
|
+
* some require referrers later surface as `from ''` (#210).
|
|
16
|
+
*/
|
|
17
|
+
export declare function createRuntimeRequire(meta: RuntimeImportMeta): NodeRequire;
|
|
18
|
+
//# sourceMappingURL=runtime-require.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-require.d.ts","sourceRoot":"","sources":["../../src/services/runtime-require.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG;IAC3C,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC;CACzC,CAAC;AAgCF;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,iBAAiB,GAAG,WAAW,CA4BzE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a CommonJS require() bound to the current ESM module.
|
|
3
|
+
*
|
|
4
|
+
* OpenCode ships as a Bun `--compile` binary. In that host, `import.meta.url`
|
|
5
|
+
* can be empty for dynamically loaded plugins, so `createRequire(import.meta.url)`
|
|
6
|
+
* yields `Cannot find module '…' from ''` (#210). Prefer Bun's module-bound
|
|
7
|
+
* `import.meta.require` when available, then fall back to a valid file/path anchor.
|
|
8
|
+
*/
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
function isUsableAnchor(value) {
|
|
12
|
+
return typeof value === "string" && value.trim().length > 0 && value !== "undefined";
|
|
13
|
+
}
|
|
14
|
+
function collectAnchors(meta) {
|
|
15
|
+
const anchors = [];
|
|
16
|
+
if (isUsableAnchor(meta.url))
|
|
17
|
+
anchors.push(meta.url);
|
|
18
|
+
if (isUsableAnchor(meta.path))
|
|
19
|
+
anchors.push(meta.path);
|
|
20
|
+
const dir = isUsableAnchor(meta.dirname)
|
|
21
|
+
? meta.dirname
|
|
22
|
+
: isUsableAnchor(meta.dir)
|
|
23
|
+
? meta.dir
|
|
24
|
+
: null;
|
|
25
|
+
if (dir) {
|
|
26
|
+
// createRequire needs a filename, not a directory.
|
|
27
|
+
anchors.push(join(dir, "runtime-require.js"));
|
|
28
|
+
}
|
|
29
|
+
if (typeof meta.resolve === "function") {
|
|
30
|
+
try {
|
|
31
|
+
const resolved = meta.resolve("./package.json");
|
|
32
|
+
if (isUsableAnchor(resolved))
|
|
33
|
+
anchors.push(resolved);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// import.meta.resolve may be unavailable or reject relative specifiers.
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return anchors;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build a require() for resolving/loading packages next to this plugin module.
|
|
43
|
+
* Throws a concrete diagnostic when no usable Bun/Node anchor exists.
|
|
44
|
+
*
|
|
45
|
+
* Prefer a path/url-anchored createRequire over Bun's import.meta.require when a
|
|
46
|
+
* concrete file anchor exists. In OpenCode's Bun --compile host, import.meta.url
|
|
47
|
+
* and import.meta.path are still valid for dynamically imported plugins even when
|
|
48
|
+
* some require referrers later surface as `from ''` (#210).
|
|
49
|
+
*/
|
|
50
|
+
export function createRuntimeRequire(meta) {
|
|
51
|
+
const anchors = collectAnchors(meta);
|
|
52
|
+
const errors = [];
|
|
53
|
+
for (const anchor of anchors) {
|
|
54
|
+
try {
|
|
55
|
+
return createRequire(anchor);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
59
|
+
errors.push(`${anchor}: ${message}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (typeof meta.require === "function") {
|
|
63
|
+
return meta.require;
|
|
64
|
+
}
|
|
65
|
+
throw new Error([
|
|
66
|
+
"Unable to create a module require for the OpenCode plugin host.",
|
|
67
|
+
`import.meta.url=${JSON.stringify(meta.url)}`,
|
|
68
|
+
`import.meta.path=${JSON.stringify(meta.path)}`,
|
|
69
|
+
"Bun import.meta.require is unavailable.",
|
|
70
|
+
errors.length > 0 ? `createRequire attempts: ${errors.join("; ")}` : null,
|
|
71
|
+
"This usually means the compiled OpenCode/Bun host cleared the plugin module referrer (#210).",
|
|
72
|
+
]
|
|
73
|
+
.filter(Boolean)
|
|
74
|
+
.join(" "));
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-resolver.d.ts","sourceRoot":"","sources":["../../src/services/secret-resolver.ts"],"names":[],"mappings":"AA6CA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAkChF"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { homedir, platform } from "node:os";
|
|
4
|
+
function expandPath(path) {
|
|
5
|
+
if (path.startsWith("~/")) {
|
|
6
|
+
return join(homedir(), path.slice(2));
|
|
7
|
+
}
|
|
8
|
+
if (path === "~") {
|
|
9
|
+
return homedir();
|
|
10
|
+
}
|
|
11
|
+
return path;
|
|
12
|
+
}
|
|
13
|
+
// Any group or other bit set means someone besides the owner can reach the
|
|
14
|
+
// secret. Owner bits are deliberately excluded: 0600 and 0400 are both fine.
|
|
15
|
+
const GROUP_AND_OTHER_BITS = 0o077;
|
|
16
|
+
function checkFilePermissions(filePath) {
|
|
17
|
+
if (platform() === "win32") {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const stats = statSync(filePath);
|
|
22
|
+
const mode = stats.mode & 0o777;
|
|
23
|
+
// Test the bits, not the numeric value. `mode > 0o600` compared a bitmask as
|
|
24
|
+
// an integer, so it missed every mode that grants group/other access while
|
|
25
|
+
// sorting numerically lower -- 0404 (world-readable) and 0006
|
|
26
|
+
// (world-writable) passed silently, while 0640, strictly less permissive
|
|
27
|
+
// than 0644, warned. The comparison and the property being checked were
|
|
28
|
+
// simply unrelated.
|
|
29
|
+
const exposedBits = mode & GROUP_AND_OTHER_BITS;
|
|
30
|
+
if (exposedBits !== 0) {
|
|
31
|
+
console.warn(`Warning: Secret file ${filePath} has permissive permissions (${mode.toString(8).padStart(3, "0")}) granting group/other access. Recommend chmod 600.`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
console.warn(`Warning: Could not check file permissions for ${filePath}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function resolveSecretValue(value) {
|
|
39
|
+
if (!value) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
if (value.startsWith("file://")) {
|
|
43
|
+
const filePath = expandPath(value.slice(7));
|
|
44
|
+
if (!existsSync(filePath)) {
|
|
45
|
+
throw new Error(`Secret file not found: ${filePath}`);
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
checkFilePermissions(filePath);
|
|
49
|
+
const content = readFileSync(filePath, "utf-8");
|
|
50
|
+
return content.trim();
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
throw new Error(`Failed to read secret file ${filePath}: ${error}`, { cause: error });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (value.startsWith("env://")) {
|
|
57
|
+
const envVar = value.slice(6);
|
|
58
|
+
const envValue = process.env[envVar];
|
|
59
|
+
if (!envValue) {
|
|
60
|
+
throw new Error(`Environment variable not found: ${envVar}`);
|
|
61
|
+
}
|
|
62
|
+
return envValue;
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export type ShardInventoryStatus = "current" | "linked" | "orphaned" | "missing-file" | "empty" | "ambiguous";
|
|
2
|
+
export interface ProjectShardDescriptor {
|
|
3
|
+
shardId: number | null;
|
|
4
|
+
shardIndex: number;
|
|
5
|
+
dbPath: string;
|
|
6
|
+
fileName: string;
|
|
7
|
+
isActive: boolean;
|
|
8
|
+
vectorCount: number;
|
|
9
|
+
memoryCount: number;
|
|
10
|
+
fileExists: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface ProjectShardGroup {
|
|
13
|
+
scope: "project";
|
|
14
|
+
scopeHash: string;
|
|
15
|
+
shardIndices: number[];
|
|
16
|
+
shards: ProjectShardDescriptor[];
|
|
17
|
+
memoryCount: number;
|
|
18
|
+
containerTag: string | null;
|
|
19
|
+
projectPath: string | null;
|
|
20
|
+
projectPathCandidates: Array<{
|
|
21
|
+
path: string;
|
|
22
|
+
count: number;
|
|
23
|
+
}>;
|
|
24
|
+
projectName: string | null;
|
|
25
|
+
gitRepoUrl: string | null;
|
|
26
|
+
pathExists: boolean;
|
|
27
|
+
status: ShardInventoryStatus;
|
|
28
|
+
matchesCurrentProject: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface ListShardsResult {
|
|
31
|
+
success: true;
|
|
32
|
+
storagePath: string;
|
|
33
|
+
currentProject: {
|
|
34
|
+
tag: string;
|
|
35
|
+
scopeHash: string;
|
|
36
|
+
projectPath: string;
|
|
37
|
+
};
|
|
38
|
+
shards: ProjectShardGroup[];
|
|
39
|
+
summary: {
|
|
40
|
+
total: number;
|
|
41
|
+
current: number;
|
|
42
|
+
linked: number;
|
|
43
|
+
orphaned: number;
|
|
44
|
+
missingFile: number;
|
|
45
|
+
empty: number;
|
|
46
|
+
ambiguous: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export interface ResolveMigrationSourceOptions {
|
|
50
|
+
fromPath?: string;
|
|
51
|
+
fromHash?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ResolvedMigrationSource {
|
|
54
|
+
scopeHash: string;
|
|
55
|
+
matchedBy: "fromHash" | "storedProjectPath" | "liveProjectIdentity";
|
|
56
|
+
group: ProjectShardGroup;
|
|
57
|
+
}
|
|
58
|
+
export interface ResolveMigrationSourceResult {
|
|
59
|
+
success: boolean;
|
|
60
|
+
source?: ResolvedMigrationSource;
|
|
61
|
+
candidates?: ProjectShardGroup[];
|
|
62
|
+
error?: string;
|
|
63
|
+
}
|
|
64
|
+
export declare function normalizeProjectPath(path: string): string;
|
|
65
|
+
export declare class ShardInventoryService {
|
|
66
|
+
listShards(currentDirectory: string): Promise<ListShardsResult>;
|
|
67
|
+
resolveMigrationSource(currentDirectory: string, options: ResolveMigrationSourceOptions): Promise<ResolveMigrationSourceResult>;
|
|
68
|
+
}
|
|
69
|
+
export declare const shardInventoryService: ShardInventoryService;
|
|
70
|
+
//# sourceMappingURL=shard-inventory-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shard-inventory-service.d.ts","sourceRoot":"","sources":["../../src/services/shard-inventory-service.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,oBAAoB,GAC9B,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,cAAc,GAAG,OAAO,GAAG,WAAW,CAAC;AAE7E,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE,sBAAsB,EAAE,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,qBAAqB,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9D,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,IAAI,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE;QACd,GAAG,EAAE,MAAM,CAAC;QACZ,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,MAAM,EAAE,iBAAiB,EAAE,CAAC;IAC5B,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,UAAU,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;IACpE,KAAK,EAAE,iBAAiB,CAAC;CAC1B;AAED,MAAM,WAAW,4BAA4B;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMzD;AAoGD,qBAAa,qBAAqB;IAC1B,UAAU,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAuJ/D,sBAAsB,CAC1B,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,4BAA4B,CAAC;CAoGzC;AAED,eAAO,MAAM,qBAAqB,uBAA8B,CAAC"}
|