om-memory-system 4.22.0 → 4.24.0-next.147
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/dist/config-template.d.ts +6 -0
- package/dist/config-template.js +385 -0
- package/dist/config.d.ts +18 -1
- package/dist/config.js +68 -382
- package/dist/services/client.js +32 -4
- package/dist/services/global-config-writer.js +54 -7
- package/dist/services/request-timeouts.d.ts +5 -0
- package/dist/services/request-timeouts.js +8 -0
- package/dist/services/reranker-test.d.ts +1 -0
- package/dist/services/reranker-test.js +94 -0
- package/dist/services/reranker.d.ts +45 -0
- package/dist/services/reranker.js +133 -0
- package/dist/services/retrieval-rerank.d.ts +43 -0
- package/dist/services/retrieval-rerank.js +42 -0
- package/dist/services/settings-snapshot.js +25 -4
- package/dist/services/web-server.js +3 -0
- package/dist/utils/memory-limits.d.ts +7 -8
- package/dist/utils/memory-limits.js +10 -4
- package/dist/utils/threshold-default.d.ts +12 -0
- package/dist/utils/threshold-default.js +22 -0
- package/dist/web/assets/index-B_2GCxJJ.js +127 -0
- package/dist/web/assets/index-JAZ-QY-Z.css +2 -0
- package/dist/web/index.html +2 -2
- package/package.json +1 -1
- package/dist/web/assets/index-7385lY75.css +0 -2
- package/dist/web/assets/index-C9y78EH_.js +0 -127
package/dist/config.js
CHANGED
|
@@ -10,6 +10,8 @@ import { getAutoCaptureProviderStatus } from "./services/ai/live-model-choice.js
|
|
|
10
10
|
import { parseBackfillModel } from "./importer/backfill-model.js";
|
|
11
11
|
import { parseIgnoredDirectories, parseImportPathMaps } from "./importer/import-path-maps.js";
|
|
12
12
|
import { checkedMemoryLimit, MEMORY_LIMITS } from "./utils/memory-limits.js";
|
|
13
|
+
import { defaultSimilarityThreshold } from "./utils/threshold-default.js";
|
|
14
|
+
import { RERANKER_TIMEOUT_DEFAULT_MS, RERANKER_TIMEOUT_MAX_MS, RERANKER_TIMEOUT_MIN_MS, } from "./services/request-timeouts.js";
|
|
13
15
|
import { resolveDefaultStoragePath, runLegacyStoreMigration, legacyMigrationPaths, } from "./services/legacy-migration.js";
|
|
14
16
|
const OMMS_CONFIG_DIR = join(homedir(), ".config", "omms");
|
|
15
17
|
const DATA_DIR = join(homedir(), ".omms");
|
|
@@ -38,8 +40,9 @@ const DEFAULTS = {
|
|
|
38
40
|
embeddingModel: "Xenova/nomic-embed-text-v1",
|
|
39
41
|
embeddingDimensions: 768,
|
|
40
42
|
embeddingUseTaskPrefixes: false,
|
|
41
|
-
similarityThreshold: 0.6,
|
|
42
43
|
maxMemories: 10,
|
|
44
|
+
rerankerEnabled: false,
|
|
45
|
+
rerankerTimeoutMs: RERANKER_TIMEOUT_DEFAULT_MS,
|
|
43
46
|
retrievalMaxTokens: 2000,
|
|
44
47
|
maxProfileItems: 5,
|
|
45
48
|
injectProfile: true,
|
|
@@ -161,384 +164,8 @@ function assertProjectRemoteProviderConfigIsSafe(projectConfig) {
|
|
|
161
164
|
`Move them to the global config at ${CONFIG_FILES[0]}.`);
|
|
162
165
|
}
|
|
163
166
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// omms (Opinionated Modular Memory System) Configuration
|
|
167
|
-
// ============================================
|
|
168
|
-
|
|
169
|
-
// Storage location for the vector database. Leave unset to use the
|
|
170
|
-
// default ~/.omms/data (a legacy ~/.opencode-mem/data store is migrated
|
|
171
|
-
// there automatically on first start; see docs/omms-migration.md).
|
|
172
|
-
// "storagePath": "~/.omms/data",
|
|
173
|
-
|
|
174
|
-
"userEmailOverride": "",
|
|
175
|
-
"userNameOverride": "",
|
|
176
|
-
|
|
177
|
-
// ============================================
|
|
178
|
-
// Embedding Model (for similarity search)
|
|
179
|
-
// ============================================
|
|
180
|
-
// Local = Hugging Face / ONNX via @huggingface/transformers (not Apple MLX).
|
|
181
|
-
// Remote = set embeddingApiUrl (OpenAI-compatible /embeddings); embeddingApiKey is optional.
|
|
182
|
-
|
|
183
|
-
// Default: Nomic Embed v1 (768 dimensions, 8192 context, multilingual)
|
|
184
|
-
"embeddingModel": "Xenova/nomic-embed-text-v1",
|
|
185
|
-
|
|
186
|
-
// Opt-in Nomic task prefixes (search_document: / search_query:). After enabling,
|
|
187
|
-
// re-index existing memories so store and query vectors stay aligned.
|
|
188
|
-
// "embeddingUseTaskPrefixes": true,
|
|
189
|
-
|
|
190
|
-
// Auto-detected dimensions (no need to set manually)
|
|
191
|
-
// "embeddingDimensions": 768,
|
|
192
|
-
|
|
193
|
-
// Other recommended local models:
|
|
194
|
-
// "embeddingModel": "Xenova/jina-embeddings-v2-base-en", // 768 dims, English-only, 8192 context
|
|
195
|
-
// "embeddingModel": "Xenova/jina-embeddings-v2-small-en", // 512 dims, faster, 8192 context
|
|
196
|
-
// "embeddingModel": "Xenova/all-MiniLM-L6-v2", // 384 dims, very fast, 512 context
|
|
197
|
-
// "embeddingModel": "Xenova/all-mpnet-base-v2", // 768 dims, good quality, 512 context
|
|
198
|
-
|
|
199
|
-
// Optional: OpenAI-compatible API for embeddings (URL required; key only if the server needs one)
|
|
200
|
-
// "embeddingApiUrl": "https://api.openai.com/v1",
|
|
201
|
-
// "embeddingApiKey": "env://OPENAI_API_KEY", // or "sk-..." / "file:///path/to/key"
|
|
202
|
-
// "embeddingModel": "text-embedding-3-small", // 1536 dims, auto-detected
|
|
203
|
-
|
|
204
|
-
// ============================================
|
|
205
|
-
// Web Server Settings
|
|
206
|
-
// ============================================
|
|
207
|
-
|
|
208
|
-
// Start a background import of past chats on each host's next start.
|
|
209
|
-
"autoBackfill": true,
|
|
210
|
-
// "piBackfillModel": "inherit", // or "external", or "provider/model"
|
|
211
|
-
// "opencodeBackfillModel": "inherit", // or "external", or "provider/model"
|
|
212
|
-
// Directory maps for history recorded in moved or deleted directories.
|
|
213
|
-
// "importPathMaps": [{ "from": "~/code/app-feat-x", "to": "~/code/app" }],
|
|
214
|
-
// Unresolved directories to hide on the Directory maps page. They stay unimported.
|
|
215
|
-
// "importIgnoredDirectories": ["/private/tmp/scratch"],
|
|
216
|
-
// Claude Code's folder, when it is not ~/.claude (like CLAUDE_CONFIG_DIR).
|
|
217
|
-
// "claudeConfigDir": "~/.claude-work",
|
|
218
|
-
|
|
219
|
-
// Register the web app to start when you log in.
|
|
220
|
-
"webServerAutoStart": true,
|
|
221
|
-
// Enable web UI for managing memories (accessible at http://localhost:4747)
|
|
222
|
-
"webServerEnabled": true,
|
|
223
|
-
|
|
224
|
-
// Port for web UI server
|
|
225
|
-
"webServerPort": 4747,
|
|
226
|
-
|
|
227
|
-
// Host address for web UI (use 127.0.0.1 for local only, 0.0.0.0 for network access)
|
|
228
|
-
"webServerHost": "127.0.0.1",
|
|
229
|
-
|
|
230
|
-
// Optional HTTP Basic Auth for the web UI. Accepts literal, env://, or file:// secrets.
|
|
231
|
-
// "webServerAuthPassword": "",
|
|
232
|
-
// "webServerAuthUsername": "",
|
|
233
|
-
|
|
234
|
-
// Deprecated: imported once into the API token table, then no longer read.
|
|
235
|
-
// Create API tokens on the Settings page (Keys and access) instead.
|
|
236
|
-
// "webServerApiToken": "env://OMMS_WEB_TOKEN",
|
|
237
|
-
|
|
238
|
-
// ============================================
|
|
239
|
-
// Database Settings
|
|
240
|
-
// ============================================
|
|
241
|
-
|
|
242
|
-
// Maximum vectors per database shard (auto-creates new shard when limit reached)
|
|
243
|
-
"maxVectorsPerShard": 50000,
|
|
244
|
-
|
|
245
|
-
// Automatically delete old memories based on retention period
|
|
246
|
-
"autoCleanupEnabled": true,
|
|
247
|
-
|
|
248
|
-
// Days to keep memories before auto-cleanup (only if autoCleanupEnabled is true)
|
|
249
|
-
"autoCleanupRetentionDays": 30,
|
|
250
|
-
|
|
251
|
-
// Automatically detect and remove duplicate memories
|
|
252
|
-
"deduplicationEnabled": true,
|
|
253
|
-
|
|
254
|
-
// Similarity threshold (0-1) for detecting duplicates (higher = stricter)
|
|
255
|
-
"deduplicationSimilarityThreshold": 0.90,
|
|
256
|
-
|
|
257
|
-
// ============================================
|
|
258
|
-
// Memory Scope Settings
|
|
259
|
-
// ============================================
|
|
260
|
-
|
|
261
|
-
// Default scope for memory list/search queries
|
|
262
|
-
// "project" keeps queries within the current project, "all-projects" searches across all project shards
|
|
263
|
-
"memory": {
|
|
264
|
-
"defaultScope": "project"
|
|
265
|
-
},
|
|
266
|
-
|
|
267
|
-
// ============================================
|
|
268
|
-
// Model for auto-capture and profile learning (same rule in OpenCode and Pi)
|
|
269
|
-
// ============================================
|
|
270
|
-
|
|
271
|
-
// Which model summarises your work, in this order:
|
|
272
|
-
// 1. The host model below: opencodeProvider/opencodeModel in OpenCode,
|
|
273
|
-
// piProvider/piModel in Pi. Set the model to "inherit" to follow
|
|
274
|
-
// whatever model the session is using, or to "external" to send
|
|
275
|
-
// every call to the external API below.
|
|
276
|
-
// 2. If no host model is set: the external API (memoryModel/memoryApiUrl/
|
|
277
|
-
// memoryApiKey further down).
|
|
278
|
-
// 3. If neither is set: the session's own model.
|
|
279
|
-
// If the host model fails and the external API is configured, the external
|
|
280
|
-
// API is used instead.
|
|
281
|
-
//
|
|
282
|
-
// Host models go through OpenCode's or Pi's own sign-in (OAuth like Claude
|
|
283
|
-
// Pro/Max, GitHub Copilot, ChatGPT, or your own key there), so no separate API
|
|
284
|
-
// key is needed here.
|
|
285
|
-
//
|
|
286
|
-
// Examples (OpenCode names from 'opencode providers list'; Pi names from its model list):
|
|
287
|
-
// "opencodeProvider": "anthropic", "opencodeModel": "claude-haiku-4-5-20251001"
|
|
288
|
-
// "opencodeProvider": "openai", "opencodeModel": "inherit"
|
|
289
|
-
// "piProvider": "openai-codex", "piModel": "gpt-5.6-luna"
|
|
290
|
-
//
|
|
291
|
-
// "opencodeProvider": "anthropic",
|
|
292
|
-
// "opencodeModel": "claude-haiku-4-5-20251001",
|
|
293
|
-
// "piProvider": "openai-codex",
|
|
294
|
-
// "piModel": "gpt-5.6-luna",
|
|
295
|
-
|
|
296
|
-
// ============================================
|
|
297
|
-
// Auto-Capture Settings
|
|
298
|
-
// ============================================
|
|
299
|
-
|
|
300
|
-
// Auto-capture runs in the background without blocking your main session.
|
|
301
|
-
// Note: Ollama may not support tool calling. Use OpenAI, Anthropic, or Groq for best results.
|
|
302
|
-
|
|
303
|
-
"autoCaptureEnabled": true,
|
|
304
|
-
|
|
305
|
-
// Provider type: "openai-chat" | "openai-responses" | "anthropic" | "minimax" | "orcarouter" | "google-gemini"
|
|
306
|
-
// Note: "openai-chat" is a generic OpenAI API-compatible mode.
|
|
307
|
-
// Any service that follows the OpenAI Chat Completions API can use it via custom "memoryApiUrl".
|
|
308
|
-
"memoryProvider": "openai-chat",
|
|
309
|
-
|
|
310
|
-
// External API (step 2 above, and the fallback when a host model fails).
|
|
311
|
-
// Uncomment all 3 lines and replace memoryApiKey before use:
|
|
312
|
-
// "memoryModel": "gpt-4o-mini",
|
|
313
|
-
// "memoryApiUrl": "https://api.openai.com/v1",
|
|
314
|
-
// "memoryApiKey": "sk-...",
|
|
315
|
-
|
|
316
|
-
// API Key Formats:
|
|
317
|
-
// Direct value: "sk-..."
|
|
318
|
-
// From file: "file://~/.config/litellm-key.txt"
|
|
319
|
-
// From env variable: "env://LITELLM_API_KEY"
|
|
320
|
-
|
|
321
|
-
// Examples for different providers:
|
|
322
|
-
// Any OpenAI-compatible endpoint can use the "openai-chat" provider pattern below.
|
|
323
|
-
// Common examples: DeepSeek, Qwen (via Alibaba Cloud ModelStudio),
|
|
324
|
-
// Zhipu GLM (BigModel platform), and Kimi (Moonshot AI platform).
|
|
325
|
-
|
|
326
|
-
// OpenAI Chat Completion (default, backward compatible):
|
|
327
|
-
// "memoryProvider": "openai-chat"
|
|
328
|
-
// "memoryModel": "gpt-4o-mini"
|
|
329
|
-
// "memoryApiUrl": "https://api.openai.com/v1"
|
|
330
|
-
// "memoryApiKey": "sk-..."
|
|
331
|
-
|
|
332
|
-
// DeepSeek (OpenAI-compatible example):
|
|
333
|
-
// "memoryProvider": "openai-chat"
|
|
334
|
-
// "memoryModel": "deepseek-chat"
|
|
335
|
-
// "memoryApiUrl": "https://api.deepseek.com/v1"
|
|
336
|
-
// "memoryApiKey": "sk-..."
|
|
337
|
-
|
|
338
|
-
// OpenAI Responses API (recommended, with session support):
|
|
339
|
-
// "memoryProvider": "openai-responses"
|
|
340
|
-
// "memoryModel": "gpt-4o"
|
|
341
|
-
// "memoryApiUrl": "https://api.openai.com/v1"
|
|
342
|
-
// "memoryApiKey": "sk-..."
|
|
343
|
-
|
|
344
|
-
// Anthropic (with session support):
|
|
345
|
-
// "memoryProvider": "anthropic"
|
|
346
|
-
// "memoryModel": "claude-3-5-haiku-20241022"
|
|
347
|
-
// "memoryApiUrl": "https://api.anthropic.com/v1"
|
|
348
|
-
// "memoryApiKey": "sk-ant-..."
|
|
349
|
-
|
|
350
|
-
// MiniMax (Anthropic Messages-compatible endpoint, with session support):
|
|
351
|
-
// "memoryProvider": "minimax"
|
|
352
|
-
// "memoryModel": "MiniMax-M3"
|
|
353
|
-
// "memoryApiUrl": "https://api.minimax.io" // global endpoint
|
|
354
|
-
// "memoryApiKey": "<MiniMax API key>"
|
|
355
|
-
// // China endpoint: "memoryApiUrl": "https://api.minimaxi.com"
|
|
356
|
-
// // Optional adaptive thinking for MiniMax-M3:
|
|
357
|
-
// "memoryExtraParams": { "thinking": { "type": "adaptive" } }
|
|
358
|
-
|
|
359
|
-
// OrcaRouter (OpenAI-compatible gateway, namespaced model IDs, with session support):
|
|
360
|
-
// "memoryProvider": "orcarouter"
|
|
361
|
-
// "memoryApiKey": "<OrcaRouter API key>"
|
|
362
|
-
// // memoryApiUrl and memoryModel are optional — they default to
|
|
363
|
-
// // https://api.orcarouter.ai/v1 and "orcarouter/auto" (a routing alias).
|
|
364
|
-
// // OrcaRouter rejects bare model names, so if you set memoryModel, use a
|
|
365
|
-
// // namespaced ID such as "openai/gpt-5.5" or "deepseek/deepseek-v4-flash".
|
|
366
|
-
// "memoryModel": "openai/gpt-5.5"
|
|
367
|
-
|
|
368
|
-
// Groq (OpenAI-compatible, use openai-chat provider):
|
|
369
|
-
// "memoryProvider": "openai-chat"
|
|
370
|
-
// "memoryModel": "llama-3.3-70b-versatile"
|
|
371
|
-
// "memoryApiUrl": "https://api.groq.com/openai/v1"
|
|
372
|
-
// "memoryApiKey": "gsk_..."
|
|
373
|
-
|
|
374
|
-
// Maximum iterations for multi-turn AI analysis (for openai-responses, anthropic, and minimax)
|
|
375
|
-
"autoCaptureMaxIterations": 5,
|
|
376
|
-
|
|
377
|
-
// Timeout per iteration in milliseconds (30 seconds default)
|
|
378
|
-
"autoCaptureIterationTimeout": 30000,
|
|
379
|
-
|
|
380
|
-
// Tries for one turn's capture, on Pi and OpenCode, 2 and 4 seconds apart. After the
|
|
381
|
-
// last one fails, a turn the model could not reach goes to the capture retry queue.
|
|
382
|
-
"autoCaptureMaxRetries": 3,
|
|
383
|
-
|
|
384
|
-
// Maximum UTF-8 bytes for the auto-capture markdown context sent to the summary model.
|
|
385
|
-
// Prevents HTTP 400 context overflows on models with ~131K token windows (e.g. Groq Llama).
|
|
386
|
-
// Rough guide: tokens ≈ bytes / 4 for mixed code/prose.
|
|
387
|
-
"autoCaptureMaxContextBytes": 131072,
|
|
388
|
-
|
|
389
|
-
// Days to keep AI session history before cleanup
|
|
390
|
-
"aiSessionRetentionDays": 7,
|
|
391
|
-
|
|
392
|
-
// Capture diagnostics: every capture attempt always writes one metadata line
|
|
393
|
-
// (model, stop reason, sizes, outcome) to ~/.omms/omms.log, with no
|
|
394
|
-
// conversation text. Set captureTrace to true to also write each attempt's
|
|
395
|
-
// prompt and raw reply to ~/.omms/traces/ for debugging. Traces can contain
|
|
396
|
-
// conversation content: <private> text and common API key formats are
|
|
397
|
-
// redacted, files are readable only by you, and they are deleted after
|
|
398
|
-
// captureTraceRetentionDays. Only this global file can turn tracing on.
|
|
399
|
-
// "captureTrace": false,
|
|
400
|
-
// "captureTraceRetentionDays": 7,
|
|
401
|
-
// "captureAttemptRetentionDays": 30,
|
|
402
|
-
|
|
403
|
-
// Capture retry queue: when a live capture fails because the model cannot be
|
|
404
|
-
// reached (network error, timeout, HTTP 408, 429 or 5xx), OMMS keeps a copy of
|
|
405
|
-
// the turn in ~/.omms/data and tries it again later. The copy has <private>
|
|
406
|
-
// text and common API key formats removed. Turns are deleted when the retry
|
|
407
|
-
// ends or after captureRetryRetentionHours (0 to 720). 0 turns the queue off.
|
|
408
|
-
// Only this global file can set it.
|
|
409
|
-
// "captureRetryRetentionHours": 72,
|
|
410
|
-
|
|
411
|
-
// Temperature for AI API requests (set to false to omit parameter for models that don't support it)
|
|
412
|
-
// Some reasoning models (like o1, o3, gpt-5) don't support temperature parameter
|
|
413
|
-
// Set to false and add "memoryTemperature": false in config when using such models
|
|
414
|
-
"memoryTemperature": 0.3,
|
|
415
|
-
|
|
416
|
-
// Extra parameters to include in API request body
|
|
417
|
-
// Useful for local inference servers (e.g. llama-server with --jinja) that support
|
|
418
|
-
// additional parameters like disabling thinking/reasoning mode
|
|
419
|
-
// Example for Qwen3 models: { "enable_thinking": false }
|
|
420
|
-
// "memoryExtraParams": {},
|
|
421
|
-
|
|
422
|
-
// Language for auto-capture summaries (default: "auto" for auto-detection)
|
|
423
|
-
// Options: "auto", "en", "id", "zh", "ja", "es", "fr", "de", "ru", "pt", "ar", "ko"
|
|
424
|
-
// "autoCaptureLanguage": "auto",
|
|
425
|
-
|
|
426
|
-
// ============================================
|
|
427
|
-
// Toast Notifications
|
|
428
|
-
// ============================================
|
|
429
|
-
|
|
430
|
-
// Show toast when memory is auto-captured
|
|
431
|
-
"showAutoCaptureToasts": true,
|
|
432
|
-
|
|
433
|
-
// Show toast when user profile is updated
|
|
434
|
-
"showUserProfileToasts": true,
|
|
435
|
-
|
|
436
|
-
// Show toast for error messages
|
|
437
|
-
"showErrorToasts": true,
|
|
438
|
-
|
|
439
|
-
// ============================================
|
|
440
|
-
// User Profile System
|
|
441
|
-
// ============================================
|
|
442
|
-
|
|
443
|
-
// Analyze user prompts every N prompts to build/update your user profile
|
|
444
|
-
// When N uncaptured prompts accumulate, AI will analyze them to identify:
|
|
445
|
-
// - User preferences (code style, communication style, tool preferences)
|
|
446
|
-
// - User patterns (recurring topics, problem domains, technical interests)
|
|
447
|
-
// - User workflows (development habits, sequences, learning style)
|
|
448
|
-
// - Skill level (overall and per-domain assessment)
|
|
449
|
-
"userProfileAnalysisInterval": 10,
|
|
450
|
-
|
|
451
|
-
// Days before inactive items (all types) are eligible for removal
|
|
452
|
-
"userProfileStaleDays": 2,
|
|
453
|
-
|
|
454
|
-
// Days before an inactive workflow is eligible for removal. A workflow seen
|
|
455
|
-
// userProfileMinEvidenceForRetention times or more is kept.
|
|
456
|
-
"userProfileWorkflowStaleDays": 30,
|
|
457
|
-
|
|
458
|
-
// Number of preferences shown in UI
|
|
459
|
-
"userProfileDisplayPreferences": 20,
|
|
460
|
-
|
|
461
|
-
// Number of patterns shown in UI
|
|
462
|
-
"userProfileDisplayPatterns": 15,
|
|
463
|
-
|
|
464
|
-
// Number of workflows shown in UI
|
|
465
|
-
"userProfileDisplayWorkflows": 10,
|
|
466
|
-
|
|
467
|
-
// Number of preferences injected into LLM conversation context
|
|
468
|
-
// Keep this small — the strongest signals are enough; more dilute LLM attention
|
|
469
|
-
"userProfileInjectPreferences": 5,
|
|
470
|
-
|
|
471
|
-
// Number of patterns injected into LLM conversation context
|
|
472
|
-
"userProfileInjectPatterns": 5,
|
|
473
|
-
|
|
474
|
-
// Number of workflows injected into LLM conversation context
|
|
475
|
-
"userProfileInjectWorkflows": 3,
|
|
476
|
-
|
|
477
|
-
// Days before preference confidence starts to decay (if not reinforced)
|
|
478
|
-
// Preferences that aren't seen again will gradually lose confidence and be removed
|
|
479
|
-
"userProfileConfidenceDecayDays": 30,
|
|
480
|
-
|
|
481
|
-
// Number of profile versions to keep in changelog (for rollback/debugging)
|
|
482
|
-
// Older versions are automatically cleaned up
|
|
483
|
-
"userProfileChangelogRetentionCount": 5,
|
|
484
|
-
|
|
485
|
-
// Minimum evidence count for a preference/pattern to survive confidence decay
|
|
486
|
-
// Items confirmed fewer times are more likely to be pruned when confidence decays
|
|
487
|
-
"userProfileMinEvidenceForRetention": 3,
|
|
488
|
-
|
|
489
|
-
// Merge duplicate or vague profile items every N analysed prompts (about 1 model call per 100 items)
|
|
490
|
-
"userProfileAutoCleanupEnabled": true,
|
|
491
|
-
"userProfileAutoCleanupInterval": 500,
|
|
492
|
-
|
|
493
|
-
// Enable LLM validation of existing preferences against recent behavior.
|
|
494
|
-
// When enabled, each analysis round checks if top-5 preferences still match recent prompts.
|
|
495
|
-
// Experimental — disabled by default.
|
|
496
|
-
"userProfileValidationEnabled": false,
|
|
497
|
-
|
|
498
|
-
// ============================================
|
|
499
|
-
// Search Settings
|
|
500
|
-
// ============================================
|
|
501
|
-
|
|
502
|
-
// Minimum similarity score (0-1) for memory search results
|
|
503
|
-
"similarityThreshold": 0.6,
|
|
504
|
-
|
|
505
|
-
// Maximum number of memories to return in search results.
|
|
506
|
-
// Manual searches can ask for fewer; prompt retrieval uses this ceiling.
|
|
507
|
-
"maxMemories": 10,
|
|
508
|
-
|
|
509
|
-
// ============================================
|
|
510
|
-
// Memory Context Controls
|
|
511
|
-
// ============================================
|
|
512
|
-
|
|
513
|
-
// Recent memories added at fresh session start (OpenCode V1 and Claude Code).
|
|
514
|
-
// Pi and OpenCode V2 search the store with each prompt instead.
|
|
515
|
-
"chatMessage": {
|
|
516
|
-
"enabled": true,
|
|
517
|
-
// Recent memories injected at session start.
|
|
518
|
-
"maxMemories": 3,
|
|
519
|
-
"excludeCurrentSession": true,
|
|
520
|
-
// When to inject: "first" message of a session or "always".
|
|
521
|
-
// "injectOn": "first",
|
|
522
|
-
},
|
|
523
|
-
|
|
524
|
-
// OpenCode profile-learning input limit, in UTF-8 bytes. Smaller values can
|
|
525
|
-
// omit prompts from that input. Does not limit Pi or Claude Code profile input.
|
|
526
|
-
"userProfileMaxContextBytes": 32768,
|
|
527
|
-
|
|
528
|
-
// Shared budget for automatic memory context (profile text, memories, and
|
|
529
|
-
// formatting) across all hosts, in approximate tokens: ceil(UTF-8 bytes / 4).
|
|
530
|
-
// Covers prompt retrieval, recent-memory injection, and session-memory
|
|
531
|
-
// restoration. Not an exact provider token limit or a spending limit.
|
|
532
|
-
"retrievalMaxTokens": 2000,
|
|
533
|
-
|
|
534
|
-
// ============================================
|
|
535
|
-
// Advanced Settings
|
|
536
|
-
// ============================================
|
|
537
|
-
|
|
538
|
-
// Inject user profile into AI context (preferences, patterns, workflows)
|
|
539
|
-
"injectProfile": true
|
|
540
|
-
}
|
|
541
|
-
`;
|
|
167
|
+
import { CONFIG_TEMPLATE } from "./config-template.js";
|
|
168
|
+
export { CONFIG_TEMPLATE };
|
|
542
169
|
function ensureConfigExists() {
|
|
543
170
|
const configPath = join(OMMS_CONFIG_DIR, "omms.jsonc");
|
|
544
171
|
const hasOmmsConfig = CONFIG_FILES.slice(0, 2).some((path) => existsSync(path));
|
|
@@ -618,6 +245,49 @@ export function normalizeCaptureRetryRetentionHours(value) {
|
|
|
618
245
|
}
|
|
619
246
|
return Math.min(720, Math.max(0, Math.floor(value)));
|
|
620
247
|
}
|
|
248
|
+
/** The reranker key must be a reference, never a literal secret in the file. */
|
|
249
|
+
function isRerankerKeyReference(value) {
|
|
250
|
+
return /^(env:\/\/[A-Za-z_][A-Za-z0-9_]*|file:\/\/.+)$/.test(value.trim());
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Validate the five opt-in reranker keys when present (openspec change
|
|
254
|
+
* retrieval-threshold-and-reranker). Messages name the setting and its
|
|
255
|
+
* accepted values only; the value is never quoted back.
|
|
256
|
+
*/
|
|
257
|
+
function checkedRerankerSettings(fileConfig) {
|
|
258
|
+
const invalid = (setting, accepted) => new Error(`Invalid ${setting} config (accepted: ${accepted})`);
|
|
259
|
+
if (fileConfig.rerankerEnabled !== undefined && typeof fileConfig.rerankerEnabled !== "boolean") {
|
|
260
|
+
throw invalid("rerankerEnabled", "boolean");
|
|
261
|
+
}
|
|
262
|
+
for (const key of ["rerankerApiUrl", "rerankerModel"]) {
|
|
263
|
+
const value = fileConfig[key];
|
|
264
|
+
if (value === undefined)
|
|
265
|
+
continue;
|
|
266
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
267
|
+
throw invalid(key, "a non-empty string");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (fileConfig.rerankerApiUrl !== undefined &&
|
|
271
|
+
!/^https?:\/\/\S+$/.test(fileConfig.rerankerApiUrl.trim())) {
|
|
272
|
+
throw invalid("rerankerApiUrl", "an http:// or https:// URL");
|
|
273
|
+
}
|
|
274
|
+
if (fileConfig.rerankerApiKey !== undefined) {
|
|
275
|
+
if (typeof fileConfig.rerankerApiKey !== "string" ||
|
|
276
|
+
!isRerankerKeyReference(fileConfig.rerankerApiKey)) {
|
|
277
|
+
throw invalid("rerankerApiKey", "an env:// or file:// secret reference");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (fileConfig.rerankerTimeoutMs !== undefined) {
|
|
281
|
+
const value = fileConfig.rerankerTimeoutMs;
|
|
282
|
+
const ok = typeof value === "number" &&
|
|
283
|
+
Number.isSafeInteger(value) &&
|
|
284
|
+
value >= RERANKER_TIMEOUT_MIN_MS &&
|
|
285
|
+
value <= RERANKER_TIMEOUT_MAX_MS;
|
|
286
|
+
if (!ok) {
|
|
287
|
+
throw invalid("rerankerTimeoutMs", `integers from ${RERANKER_TIMEOUT_MIN_MS} to ${RERANKER_TIMEOUT_MAX_MS}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
621
291
|
export function normalizeAutoCleanupRetentionDays(value) {
|
|
622
292
|
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
623
293
|
throw new Error(`Invalid autoCleanupRetentionDays config: ${value}`);
|
|
@@ -640,8 +310,11 @@ function resolveMemoryApiKey(value) {
|
|
|
640
310
|
}
|
|
641
311
|
function buildConfig(fileConfig) {
|
|
642
312
|
const memoryApiKey = resolveMemoryApiKey(fileConfig.memoryApiKey);
|
|
643
|
-
|
|
644
|
-
|
|
313
|
+
checkedRerankerSettings(fileConfig);
|
|
314
|
+
const embeddingModel = fileConfig.embeddingModel ?? DEFAULTS.embeddingModel;
|
|
315
|
+
// The default follows the embedder; a value present in the file always wins.
|
|
316
|
+
const similarityThreshold = checkedOwnMemoryLimit(MEMORY_LIMITS.similarityThreshold, fileConfig, "similarityThreshold", defaultSimilarityThreshold(embeddingModel));
|
|
317
|
+
const embeddingDimensions = fileConfig.embeddingDimensions ?? getEmbeddingDimensions(embeddingModel);
|
|
645
318
|
const autoCaptureMaxContextBytes = checkedOwnMemoryLimit(MEMORY_LIMITS.autoCaptureMaxContextBytes, fileConfig, "autoCaptureMaxContextBytes", DEFAULTS.autoCaptureMaxContextBytes);
|
|
646
319
|
const maxMemories = checkedOwnMemoryLimit(MEMORY_LIMITS.maxMemories, fileConfig, "maxMemories", DEFAULTS.maxMemories);
|
|
647
320
|
const retrievalMaxTokens = checkedOwnMemoryLimit(MEMORY_LIMITS.retrievalMaxTokens, fileConfig, "retrievalMaxTokens", DEFAULTS.retrievalMaxTokens);
|
|
@@ -685,7 +358,12 @@ function buildConfig(fileConfig) {
|
|
|
685
358
|
? // No ambient OPENAI_API_KEY: an unset key means no Authorization header.
|
|
686
359
|
resolveSecretValue(fileConfig.embeddingApiKey)
|
|
687
360
|
: undefined,
|
|
688
|
-
similarityThreshold
|
|
361
|
+
similarityThreshold,
|
|
362
|
+
rerankerEnabled: fileConfig.rerankerEnabled ?? DEFAULTS.rerankerEnabled,
|
|
363
|
+
rerankerApiUrl: fileConfig.rerankerApiUrl?.trim() || undefined,
|
|
364
|
+
rerankerModel: fileConfig.rerankerModel?.trim() || undefined,
|
|
365
|
+
rerankerApiKey: fileConfig.rerankerApiKey,
|
|
366
|
+
rerankerTimeoutMs: fileConfig.rerankerTimeoutMs ?? DEFAULTS.rerankerTimeoutMs,
|
|
689
367
|
maxMemories,
|
|
690
368
|
retrievalMaxTokens,
|
|
691
369
|
maxProfileItems: fileConfig.maxProfileItems ?? DEFAULTS.maxProfileItems,
|
|
@@ -887,6 +565,14 @@ export function initConfig(directory, options = {}) {
|
|
|
887
565
|
delete projectOverrides.piBackfillModel;
|
|
888
566
|
delete projectOverrides.importPathMaps;
|
|
889
567
|
delete projectOverrides.importIgnoredDirectories;
|
|
568
|
+
// The reranker decides where memory text is sent, so only the global file
|
|
569
|
+
// may set it; a checked-in project file must not redirect a user's
|
|
570
|
+
// memories to its own server.
|
|
571
|
+
delete projectOverrides.rerankerEnabled;
|
|
572
|
+
delete projectOverrides.rerankerApiUrl;
|
|
573
|
+
delete projectOverrides.rerankerModel;
|
|
574
|
+
delete projectOverrides.rerankerApiKey;
|
|
575
|
+
delete projectOverrides.rerankerTimeoutMs;
|
|
890
576
|
// A checked-in project file must not point the web app at another folder.
|
|
891
577
|
delete projectOverrides.claudeConfigDir;
|
|
892
578
|
delete projectOverrides.webServerAutoStart;
|
package/dist/services/client.js
CHANGED
|
@@ -5,6 +5,8 @@ import { tursoConnectionManager } from "./turso/connection-manager.js";
|
|
|
5
5
|
import { ensureTursoReady } from "./turso/ready.js";
|
|
6
6
|
import { formatTagsForEmbedding } from "./turso/vector-utils.js";
|
|
7
7
|
import { extractScopeFromContainerTag, resolveMemoryScope, } from "./memory-scope.js";
|
|
8
|
+
import { rerankSettingsFrom } from "./reranker.js";
|
|
9
|
+
import { rerankedSearch } from "./retrieval-rerank.js";
|
|
8
10
|
import { CONFIG } from "../config.js";
|
|
9
11
|
import { log } from "./logger.js";
|
|
10
12
|
function safeToISOString(timestamp) {
|
|
@@ -86,10 +88,17 @@ export class LocalMemoryClient {
|
|
|
86
88
|
this.reset();
|
|
87
89
|
}
|
|
88
90
|
async searchMemories(query, containerTag, scope = "project") {
|
|
89
|
-
// Capture the result count at entry: initialize,
|
|
90
|
-
// reads all await, and a config edit during them must
|
|
91
|
-
// search's limit.
|
|
91
|
+
// Capture the result count and the reranker settings at entry: initialize,
|
|
92
|
+
// embedding, and shard reads all await, and a config edit during them must
|
|
93
|
+
// not change this search's limit or reranker target.
|
|
92
94
|
const maxMemories = CONFIG.maxMemories;
|
|
95
|
+
const reranker = rerankSettingsFrom(CONFIG);
|
|
96
|
+
if (CONFIG.rerankerEnabled && !reranker) {
|
|
97
|
+
// On but incomplete: search must keep working, so treat it as off.
|
|
98
|
+
log("Reranker enabled without a URL or model; searching without it", {
|
|
99
|
+
code: "reranker_not_configured",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
93
102
|
try {
|
|
94
103
|
await this.initialize();
|
|
95
104
|
const queryVector = await embeddingService.embedWithTimeout(query, { task: "query" });
|
|
@@ -98,7 +107,26 @@ export class LocalMemoryClient {
|
|
|
98
107
|
if (shards.length === 0) {
|
|
99
108
|
return { success: true, results: [], total: 0, timing: 0 };
|
|
100
109
|
}
|
|
101
|
-
|
|
110
|
+
let results;
|
|
111
|
+
let warnings;
|
|
112
|
+
if (reranker) {
|
|
113
|
+
// One shard read with no threshold feeds both the reranker and the
|
|
114
|
+
// fallback path (retrieval-rerank.ts, design decision 7).
|
|
115
|
+
({ results, warnings } = await rerankedSearch({
|
|
116
|
+
shards,
|
|
117
|
+
queryVector,
|
|
118
|
+
containerTag: scope === "all-projects" ? "" : containerTag,
|
|
119
|
+
queryText: query,
|
|
120
|
+
maxMemories,
|
|
121
|
+
similarityThreshold: CONFIG.similarityThreshold,
|
|
122
|
+
}, reranker, {
|
|
123
|
+
search: (shardList, vector, tag, limit, threshold, queryText) => tursoVectorSearch.searchAcrossShards(shardList, vector, tag, limit, threshold, queryText),
|
|
124
|
+
log: (message, meta) => log(message, meta),
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
({ results, warnings } = await tursoVectorSearch.searchAcrossShards(shards, queryVector, scope === "all-projects" ? "" : containerTag, maxMemories, CONFIG.similarityThreshold, query));
|
|
129
|
+
}
|
|
102
130
|
return {
|
|
103
131
|
success: true,
|
|
104
132
|
results,
|
|
@@ -2,9 +2,11 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
2
2
|
import { promises as fs, readFileSync, statSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { applyEdits, modify, parse } from "jsonc-parser";
|
|
5
|
-
import {
|
|
5
|
+
import { getGlobalConfigSourcePath, getGlobalConfigWritePath, validateGlobalConfig, } from "../config.js";
|
|
6
|
+
import { CONFIG_TEMPLATE } from "../config-template.js";
|
|
6
7
|
import { isValidClaudeConfigDir } from "./claude-folder.js";
|
|
7
8
|
import { getMemoryLimitRule } from "../utils/memory-limits.js";
|
|
9
|
+
import { RERANKER_TIMEOUT_MAX_MS, RERANKER_TIMEOUT_MIN_MS } from "./request-timeouts.js";
|
|
8
10
|
const keys = new Set([
|
|
9
11
|
"opencodeProvider",
|
|
10
12
|
"opencodeModel",
|
|
@@ -33,6 +35,12 @@ const keys = new Set([
|
|
|
33
35
|
"autoCaptureMaxContextBytes",
|
|
34
36
|
"userProfileMaxContextBytes",
|
|
35
37
|
"retrievalMaxTokens",
|
|
38
|
+
"similarityThreshold",
|
|
39
|
+
"rerankerEnabled",
|
|
40
|
+
"rerankerApiUrl",
|
|
41
|
+
"rerankerModel",
|
|
42
|
+
"rerankerApiKey",
|
|
43
|
+
"rerankerTimeoutMs",
|
|
36
44
|
]);
|
|
37
45
|
/**
|
|
38
46
|
* Written only by the embedding apply route, together, after a passing test.
|
|
@@ -58,8 +66,34 @@ const MEMORY_PROVIDERS = [
|
|
|
58
66
|
export function isSecretReference(value) {
|
|
59
67
|
return (typeof value === "string" && /^(env:\/\/[A-Za-z_][A-Za-z0-9_]*|file:\/\/.+)$/.test(value.trim()));
|
|
60
68
|
}
|
|
69
|
+
/** Reranker keys that a null edit removes, the same wire form as a limit reset. */
|
|
70
|
+
const OPTIONAL_RERANKER_KEYS = ["rerankerApiUrl", "rerankerModel", "rerankerApiKey"];
|
|
61
71
|
function isValidEdit(key, value) {
|
|
62
|
-
// `undefined` removes the key from the file.
|
|
72
|
+
// `undefined` removes the key from the file. `null` is the wire form of
|
|
73
|
+
// "reset to default", accepted for the six memory limits and the optional reranker keys.
|
|
74
|
+
const memoryLimit = getMemoryLimitRule(key);
|
|
75
|
+
if (memoryLimit && value === null)
|
|
76
|
+
return true;
|
|
77
|
+
if (OPTIONAL_RERANKER_KEYS.includes(key) && value === null)
|
|
78
|
+
return true;
|
|
79
|
+
// The five opt-in reranker keys (openspec retrieval-threshold-and-reranker).
|
|
80
|
+
if (key === "rerankerEnabled")
|
|
81
|
+
return typeof value === "boolean";
|
|
82
|
+
if (key === "rerankerApiUrl") {
|
|
83
|
+
return value === undefined || (typeof value === "string" && /^https?:\/\/\S+$/.test(value));
|
|
84
|
+
}
|
|
85
|
+
if (key === "rerankerModel") {
|
|
86
|
+
return value === undefined || (typeof value === "string" && value.trim().length > 0);
|
|
87
|
+
}
|
|
88
|
+
if (key === "rerankerApiKey") {
|
|
89
|
+
return value === undefined || isSecretReference(value);
|
|
90
|
+
}
|
|
91
|
+
if (key === "rerankerTimeoutMs") {
|
|
92
|
+
return (typeof value === "number" &&
|
|
93
|
+
Number.isSafeInteger(value) &&
|
|
94
|
+
value >= RERANKER_TIMEOUT_MIN_MS &&
|
|
95
|
+
value <= RERANKER_TIMEOUT_MAX_MS);
|
|
96
|
+
}
|
|
63
97
|
if (key === "embeddingApiUrl") {
|
|
64
98
|
return value === undefined || (typeof value === "string" && /^https?:\/\/\S+$/.test(value));
|
|
65
99
|
}
|
|
@@ -98,8 +132,8 @@ function isValidEdit(key, value) {
|
|
|
98
132
|
// Entries are checked by the startup validation below.
|
|
99
133
|
if (key === "importPathMaps" || key === "importIgnoredDirectories")
|
|
100
134
|
return Array.isArray(value);
|
|
101
|
-
// The five memory limits share one validation rule set
|
|
102
|
-
|
|
135
|
+
// The five memory limits share one validation rule set (six with
|
|
136
|
+
// similarityThreshold; null means reset, handled above).
|
|
103
137
|
if (memoryLimit)
|
|
104
138
|
return memoryLimit.isValid(value);
|
|
105
139
|
// An empty value clears the field.
|
|
@@ -147,11 +181,19 @@ options = {}) {
|
|
|
147
181
|
if (!isValidEdit(key, value)) {
|
|
148
182
|
// Never echo the value: a rejected memoryApiKey may be a literal key.
|
|
149
183
|
const memoryRule = getMemoryLimitRule(key);
|
|
150
|
-
|
|
184
|
+
const rerankerAccepted = {
|
|
185
|
+
rerankerEnabled: "boolean",
|
|
186
|
+
rerankerApiUrl: "an http:// or https:// URL",
|
|
187
|
+
rerankerModel: "a non-empty string",
|
|
188
|
+
rerankerTimeoutMs: `integers from ${RERANKER_TIMEOUT_MIN_MS} to ${RERANKER_TIMEOUT_MAX_MS}`,
|
|
189
|
+
};
|
|
190
|
+
throw new Error(["memoryApiKey", "embeddingApiKey", "webServerAuthPassword", "rerankerApiKey"].includes(key)
|
|
151
191
|
? `${key} must be an env:// or file:// reference`
|
|
152
192
|
: memoryRule
|
|
153
193
|
? `Invalid ${key} setting: accepted ${memoryRule.accepted}`
|
|
154
|
-
:
|
|
194
|
+
: rerankerAccepted[key]
|
|
195
|
+
? `Invalid ${key} setting: accepted ${rerankerAccepted[key]}`
|
|
196
|
+
: `Invalid ${key} setting`);
|
|
155
197
|
}
|
|
156
198
|
}
|
|
157
199
|
const wasQueued = pending > 0;
|
|
@@ -173,7 +215,12 @@ options = {}) {
|
|
|
173
215
|
// A nested limit identifier maps to its JSONC leaf path, so
|
|
174
216
|
// chatMessage.maxMemories writes the leaf, never a literal dotted key.
|
|
175
217
|
const jsoncPath = (getMemoryLimitRule(key)?.path ?? [key]);
|
|
176
|
-
|
|
218
|
+
// null is the wire form of "reset to default": remove the key so the
|
|
219
|
+
// value follows the default again (undefined removes in jsonc modify).
|
|
220
|
+
const jsoncValue = value === null && (getMemoryLimitRule(key) || OPTIONAL_RERANKER_KEYS.includes(key))
|
|
221
|
+
? undefined
|
|
222
|
+
: value;
|
|
223
|
+
content = applyEdits(content, modify(content, jsoncPath, jsoncValue, {
|
|
177
224
|
formattingOptions: { insertSpaces: true, tabSize: 2, eol: "\n" },
|
|
178
225
|
}));
|
|
179
226
|
}
|