omni-cortex 1.17.2__py3-none-any.whl → 1.17.4__py3-none-any.whl

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.
Files changed (93) hide show
  1. omni_cortex/_bundled/dashboard/backend/.env.example +12 -0
  2. omni_cortex/_bundled/dashboard/backend/backfill_summaries.py +280 -0
  3. omni_cortex/_bundled/dashboard/backend/chat_service.py +631 -0
  4. omni_cortex/_bundled/dashboard/backend/database.py +1773 -0
  5. omni_cortex/_bundled/dashboard/backend/image_service.py +552 -0
  6. omni_cortex/_bundled/dashboard/backend/logging_config.py +122 -0
  7. omni_cortex/_bundled/dashboard/backend/main.py +1888 -0
  8. omni_cortex/_bundled/dashboard/backend/models.py +472 -0
  9. omni_cortex/_bundled/dashboard/backend/project_config.py +170 -0
  10. omni_cortex/_bundled/dashboard/backend/project_scanner.py +164 -0
  11. omni_cortex/_bundled/dashboard/backend/prompt_security.py +111 -0
  12. omni_cortex/_bundled/dashboard/backend/pyproject.toml +23 -0
  13. omni_cortex/_bundled/dashboard/backend/security.py +104 -0
  14. omni_cortex/_bundled/dashboard/backend/test_database.py +301 -0
  15. omni_cortex/_bundled/dashboard/backend/tmpclaude-2dfa-cwd +1 -0
  16. omni_cortex/_bundled/dashboard/backend/tmpclaude-c460-cwd +1 -0
  17. omni_cortex/_bundled/dashboard/backend/uv.lock +1110 -0
  18. omni_cortex/_bundled/dashboard/backend/websocket_manager.py +104 -0
  19. omni_cortex/_bundled/dashboard/frontend/dist/assets/index-CQlQK3nE.js +551 -0
  20. omni_cortex/_bundled/dashboard/frontend/dist/assets/index-CmUNNfe4.css +1 -0
  21. omni_cortex/_bundled/dashboard/frontend/dist/index.html +14 -0
  22. omni_cortex/_bundled/hooks/post_tool_use.py +497 -0
  23. omni_cortex/_bundled/hooks/pre_tool_use.py +277 -0
  24. omni_cortex/_bundled/hooks/session_utils.py +186 -0
  25. omni_cortex/_bundled/hooks/stop.py +219 -0
  26. omni_cortex/_bundled/hooks/subagent_stop.py +120 -0
  27. omni_cortex/_bundled/hooks/user_prompt.py +331 -0
  28. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/main.py +2 -2
  29. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/hooks/user_prompt.py +113 -2
  30. {omni_cortex-1.17.2.dist-info → omni_cortex-1.17.4.dist-info}/METADATA +6 -1
  31. omni_cortex-1.17.4.dist-info/RECORD +53 -0
  32. omni_cortex/__init__.py +0 -3
  33. omni_cortex/categorization/__init__.py +0 -9
  34. omni_cortex/categorization/auto_tags.py +0 -166
  35. omni_cortex/categorization/auto_type.py +0 -165
  36. omni_cortex/config.py +0 -141
  37. omni_cortex/dashboard.py +0 -232
  38. omni_cortex/database/__init__.py +0 -24
  39. omni_cortex/database/connection.py +0 -137
  40. omni_cortex/database/migrations.py +0 -210
  41. omni_cortex/database/schema.py +0 -212
  42. omni_cortex/database/sync.py +0 -421
  43. omni_cortex/decay/__init__.py +0 -7
  44. omni_cortex/decay/importance.py +0 -147
  45. omni_cortex/embeddings/__init__.py +0 -35
  46. omni_cortex/embeddings/local.py +0 -442
  47. omni_cortex/models/__init__.py +0 -20
  48. omni_cortex/models/activity.py +0 -265
  49. omni_cortex/models/agent.py +0 -144
  50. omni_cortex/models/memory.py +0 -395
  51. omni_cortex/models/relationship.py +0 -206
  52. omni_cortex/models/session.py +0 -290
  53. omni_cortex/resources/__init__.py +0 -1
  54. omni_cortex/search/__init__.py +0 -22
  55. omni_cortex/search/hybrid.py +0 -197
  56. omni_cortex/search/keyword.py +0 -204
  57. omni_cortex/search/ranking.py +0 -127
  58. omni_cortex/search/semantic.py +0 -232
  59. omni_cortex/server.py +0 -360
  60. omni_cortex/setup.py +0 -278
  61. omni_cortex/tools/__init__.py +0 -13
  62. omni_cortex/tools/activities.py +0 -453
  63. omni_cortex/tools/memories.py +0 -536
  64. omni_cortex/tools/sessions.py +0 -311
  65. omni_cortex/tools/utilities.py +0 -477
  66. omni_cortex/utils/__init__.py +0 -13
  67. omni_cortex/utils/formatting.py +0 -282
  68. omni_cortex/utils/ids.py +0 -72
  69. omni_cortex/utils/timestamps.py +0 -129
  70. omni_cortex/utils/truncation.py +0 -111
  71. omni_cortex-1.17.2.dist-info/RECORD +0 -65
  72. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/.env.example +0 -0
  73. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/backfill_summaries.py +0 -0
  74. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/chat_service.py +0 -0
  75. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/database.py +0 -0
  76. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/image_service.py +0 -0
  77. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/logging_config.py +0 -0
  78. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/models.py +0 -0
  79. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/project_config.py +0 -0
  80. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/project_scanner.py +0 -0
  81. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/prompt_security.py +0 -0
  82. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/pyproject.toml +0 -0
  83. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/security.py +0 -0
  84. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/uv.lock +0 -0
  85. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/dashboard/backend/websocket_manager.py +0 -0
  86. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/hooks/post_tool_use.py +0 -0
  87. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/hooks/pre_tool_use.py +0 -0
  88. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/hooks/session_utils.py +0 -0
  89. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/hooks/stop.py +0 -0
  90. {omni_cortex-1.17.2.data → omni_cortex-1.17.4.data}/data/share/omni-cortex/hooks/subagent_stop.py +0 -0
  91. {omni_cortex-1.17.2.dist-info → omni_cortex-1.17.4.dist-info}/WHEEL +0 -0
  92. {omni_cortex-1.17.2.dist-info → omni_cortex-1.17.4.dist-info}/entry_points.txt +0 -0
  93. {omni_cortex-1.17.2.dist-info → omni_cortex-1.17.4.dist-info}/licenses/LICENSE +0 -0
omni_cortex/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- """Omni Cortex MCP - Universal Memory System for Claude Code."""
2
-
3
- __version__ = "1.17.1"
@@ -1,9 +0,0 @@
1
- """Auto-categorization for memories."""
2
-
3
- from .auto_type import detect_memory_type
4
- from .auto_tags import suggest_tags
5
-
6
- __all__ = [
7
- "detect_memory_type",
8
- "suggest_tags",
9
- ]
@@ -1,166 +0,0 @@
1
- """Auto-suggest tags based on content."""
2
-
3
- import re
4
- from typing import Optional
5
-
6
- # Tag patterns organized by category
7
- TAG_PATTERNS: dict[str, list[tuple[str, str]]] = {
8
- # Programming languages
9
- "languages": [
10
- (r"\b(python|\.py)\b", "python"),
11
- (r"\b(javascript|\.js|\.jsx)\b", "javascript"),
12
- (r"\b(typescript|\.ts|\.tsx)\b", "typescript"),
13
- (r"\b(rust|\.rs|cargo)\b", "rust"),
14
- (r"\b(go|golang|\.go)\b", "go"),
15
- (r"\b(java|\.java)\b", "java"),
16
- (r"\b(c\+\+|cpp|\.cpp|\.hpp)\b", "cpp"),
17
- (r"\b(c#|csharp|\.cs)\b", "csharp"),
18
- (r"\b(ruby|\.rb)\b", "ruby"),
19
- (r"\b(php|\.php)\b", "php"),
20
- (r"\b(swift|\.swift)\b", "swift"),
21
- (r"\b(kotlin|\.kt)\b", "kotlin"),
22
- (r"\b(sql|mysql|postgres|sqlite)\b", "sql"),
23
- (r"\b(html|\.html)\b", "html"),
24
- (r"\b(css|\.css|scss|sass)\b", "css"),
25
- (r"\b(shell|bash|\.sh|zsh)\b", "shell"),
26
- ],
27
- # Frameworks and libraries
28
- "frameworks": [
29
- (r"\b(react|reactjs|jsx)\b", "react"),
30
- (r"\b(vue|vuejs)\b", "vue"),
31
- (r"\b(angular)\b", "angular"),
32
- (r"\b(svelte)\b", "svelte"),
33
- (r"\b(nextjs|next\.js)\b", "nextjs"),
34
- (r"\b(express|expressjs)\b", "express"),
35
- (r"\b(fastapi)\b", "fastapi"),
36
- (r"\b(django)\b", "django"),
37
- (r"\b(flask)\b", "flask"),
38
- (r"\b(spring)\b", "spring"),
39
- (r"\b(rails|ruby on rails)\b", "rails"),
40
- (r"\b(laravel)\b", "laravel"),
41
- (r"\b(tailwind|tailwindcss)\b", "tailwind"),
42
- (r"\b(bootstrap)\b", "bootstrap"),
43
- ],
44
- # Tools and platforms
45
- "tools": [
46
- (r"\b(git|github|gitlab)\b", "git"),
47
- (r"\b(docker|dockerfile|container)\b", "docker"),
48
- (r"\b(kubernetes|k8s|kubectl)\b", "kubernetes"),
49
- (r"\b(aws|amazon web services|s3|ec2|lambda)\b", "aws"),
50
- (r"\b(gcp|google cloud)\b", "gcp"),
51
- (r"\b(azure|microsoft azure)\b", "azure"),
52
- (r"\b(terraform)\b", "terraform"),
53
- (r"\b(jenkins|ci\/cd|github actions)\b", "ci-cd"),
54
- (r"\b(npm|yarn|pnpm)\b", "npm"),
55
- (r"\b(pip|poetry|pipenv)\b", "pip"),
56
- (r"\b(vscode|visual studio code)\b", "vscode"),
57
- (r"\b(vim|neovim)\b", "vim"),
58
- ],
59
- # Concepts
60
- "concepts": [
61
- (r"\b(api|rest|graphql|endpoint)\b", "api"),
62
- (r"\b(database|db|query|schema)\b", "database"),
63
- (r"\b(auth|authentication|authorization|oauth|jwt)\b", "auth"),
64
- (r"\b(testing|test|unittest|pytest|jest)\b", "testing"),
65
- (r"\b(security|vulnerability|xss|csrf|injection)\b", "security"),
66
- (r"\b(performance|optimization|cache|speed)\b", "performance"),
67
- (r"\b(deploy|deployment|release)\b", "deployment"),
68
- (r"\b(debug|debugging|breakpoint)\b", "debugging"),
69
- (r"\b(error handling|exception|try catch)\b", "error-handling"),
70
- (r"\b(async|await|promise|concurrent)\b", "async"),
71
- (r"\b(regex|regular expression)\b", "regex"),
72
- (r"\b(json|yaml|xml|toml)\b", "config-format"),
73
- ],
74
- # Project-specific
75
- "project": [
76
- (r"\b(frontend|front-end|ui)\b", "frontend"),
77
- (r"\b(backend|back-end|server)\b", "backend"),
78
- (r"\b(fullstack|full-stack)\b", "fullstack"),
79
- (r"\b(cli|command line|terminal)\b", "cli"),
80
- (r"\b(mobile|ios|android|react native)\b", "mobile"),
81
- (r"\b(web|website|webapp)\b", "web"),
82
- ],
83
- }
84
-
85
- # Compile patterns
86
- _compiled_patterns: list[tuple[re.Pattern, str]] = []
87
-
88
-
89
- def _ensure_compiled() -> None:
90
- """Ensure patterns are compiled."""
91
- global _compiled_patterns
92
- if not _compiled_patterns:
93
- for category_patterns in TAG_PATTERNS.values():
94
- for pattern, tag in category_patterns:
95
- _compiled_patterns.append((
96
- re.compile(pattern, re.IGNORECASE),
97
- tag
98
- ))
99
-
100
-
101
- def suggest_tags(
102
- content: str,
103
- context: Optional[str] = None,
104
- max_tags: int = 5
105
- ) -> list[str]:
106
- """Suggest tags based on content analysis.
107
-
108
- Args:
109
- content: The memory content
110
- context: Optional context string
111
- max_tags: Maximum number of tags to suggest
112
-
113
- Returns:
114
- List of suggested tag strings
115
- """
116
- _ensure_compiled()
117
-
118
- if not content:
119
- return []
120
-
121
- text = content.lower()
122
- if context:
123
- text = f"{text}\n{context.lower()}"
124
-
125
- # Track tag occurrence counts
126
- tag_counts: dict[str, int] = {}
127
-
128
- for pattern, tag in _compiled_patterns:
129
- matches = pattern.findall(text)
130
- if matches:
131
- tag_counts[tag] = tag_counts.get(tag, 0) + len(matches)
132
-
133
- # Sort by count and return top tags
134
- sorted_tags = sorted(tag_counts.items(), key=lambda x: x[1], reverse=True)
135
- return [tag for tag, _ in sorted_tags[:max_tags]]
136
-
137
-
138
- def merge_tags(
139
- existing: list[str],
140
- suggested: list[str],
141
- user_provided: Optional[list[str]] = None
142
- ) -> list[str]:
143
- """Merge tag lists, removing duplicates.
144
-
145
- Args:
146
- existing: Existing tags on the memory
147
- suggested: Auto-suggested tags
148
- user_provided: Tags explicitly provided by user
149
-
150
- Returns:
151
- Merged list of unique tags
152
- """
153
- # Start with user-provided tags (highest priority)
154
- result = list(user_provided or [])
155
-
156
- # Add existing tags
157
- for tag in existing:
158
- if tag not in result:
159
- result.append(tag)
160
-
161
- # Add suggested tags
162
- for tag in suggested:
163
- if tag not in result:
164
- result.append(tag)
165
-
166
- return result
@@ -1,165 +0,0 @@
1
- """Auto-detect memory type based on content."""
2
-
3
- import re
4
- from typing import Optional
5
-
6
- # Memory types
7
- MEMORY_TYPES = [
8
- "warning",
9
- "tip",
10
- "config",
11
- "troubleshooting",
12
- "code",
13
- "error",
14
- "solution",
15
- "command",
16
- "concept",
17
- "decision",
18
- "general",
19
- ]
20
-
21
- # Pattern definitions for each type (case-insensitive)
22
- TYPE_PATTERNS: dict[str, list[str]] = {
23
- "warning": [
24
- r"\b(warning|caution|don't|dont|avoid|never|careful|danger|risk)\b",
25
- r"\b(do not|should not|shouldn't|mustn't|must not)\b",
26
- r"\b(beware|watch out|important note)\b",
27
- ],
28
- "tip": [
29
- r"\b(tip|trick|best practice|recommend|suggestion|pro tip)\b",
30
- r"\b(you can|try|consider|it's better|better to)\b",
31
- r"\b(shortcut|hack|optimization|improve)\b",
32
- ],
33
- "config": [
34
- r"\b(config|configuration|setting|setup|environment|env)\b",
35
- r"\b(\.env|\.yaml|\.json|\.toml|\.ini)\b",
36
- r"\b(variable|parameter|option|flag)\b",
37
- r"(API_KEY|DATABASE_URL|SECRET|TOKEN)",
38
- ],
39
- "troubleshooting": [
40
- r"\b(fix|solve|debug|troubleshoot|resolve|workaround)\b",
41
- r"\b(issue|problem|bug|broken|not working)\b",
42
- r"\b(symptoms?|cause|root cause)\b",
43
- ],
44
- "code": [
45
- r"```[\w]*\n", # Code block
46
- r"\b(function|def|class|const|let|var|import|export)\s+\w+",
47
- r"\b(async|await|return|yield)\b",
48
- r"^\s*(public|private|protected)\s+",
49
- ],
50
- "error": [
51
- r"\b(error|exception|failed|failure|crash)\b",
52
- r"\b(traceback|stack trace|line \d+)\b",
53
- r"\b(TypeError|ValueError|ImportError|SyntaxError)\b",
54
- r"\b(500|404|403|401)\s+(error|status)\b",
55
- ],
56
- "solution": [
57
- r"\b(solution|solved|fixed|resolved|works?)\b",
58
- r"\b(answer|resolution|the fix|working now)\b",
59
- r"\b(here's how|the way to|correct approach)\b",
60
- ],
61
- "command": [
62
- r"^\s*[$>]\s+\S+", # Shell prompt
63
- r"\b(npm|pip|git|docker|kubectl|yarn|pnpm)\s+\w+",
64
- r"\b(run|install|build|start|test|deploy)\s+",
65
- r"^(curl|wget|ssh|scp)\s+",
66
- ],
67
- "concept": [
68
- r"\b(is|are|means|defined as|refers to)\b",
69
- r"\b(concept|definition|explanation|understanding)\b",
70
- r"\b(basically|essentially|in other words)\b",
71
- ],
72
- "decision": [
73
- r"\b(decided|decision|approach|choice|chose|choosing)\b",
74
- r"\b(we will|going to|plan to|opted for)\b",
75
- r"\b(strategy|architecture|design|pattern)\b",
76
- ],
77
- }
78
-
79
- # Compiled patterns (case-insensitive)
80
- _compiled_patterns: dict[str, list[re.Pattern]] = {}
81
-
82
-
83
- def _get_patterns(mem_type: str) -> list[re.Pattern]:
84
- """Get compiled patterns for a memory type."""
85
- if mem_type not in _compiled_patterns:
86
- patterns = TYPE_PATTERNS.get(mem_type, [])
87
- _compiled_patterns[mem_type] = [
88
- re.compile(p, re.IGNORECASE | re.MULTILINE)
89
- for p in patterns
90
- ]
91
- return _compiled_patterns[mem_type]
92
-
93
-
94
- def detect_memory_type(content: str, context: Optional[str] = None) -> str:
95
- """Detect the most likely memory type from content.
96
-
97
- Args:
98
- content: The memory content
99
- context: Optional context string
100
-
101
- Returns:
102
- Memory type string
103
- """
104
- if not content:
105
- return "general"
106
-
107
- # Combine content and context for analysis
108
- text = content
109
- if context:
110
- text = f"{content}\n{context}"
111
-
112
- # Track match scores
113
- scores: dict[str, int] = {t: 0 for t in MEMORY_TYPES if t != "general"}
114
-
115
- # Check each type's patterns
116
- for mem_type, patterns in TYPE_PATTERNS.items():
117
- for pattern in _get_patterns(mem_type):
118
- matches = pattern.findall(text)
119
- if matches:
120
- scores[mem_type] += len(matches)
121
-
122
- # Find the type with highest score
123
- if scores:
124
- best_type = max(scores.items(), key=lambda x: x[1])
125
- if best_type[1] > 0:
126
- return best_type[0]
127
-
128
- return "general"
129
-
130
-
131
- def get_type_confidence(content: str, context: Optional[str] = None) -> dict[str, float]:
132
- """Get confidence scores for each memory type.
133
-
134
- Args:
135
- content: The memory content
136
- context: Optional context string
137
-
138
- Returns:
139
- Dictionary of type -> confidence (0.0 to 1.0)
140
- """
141
- if not content:
142
- return {"general": 1.0}
143
-
144
- text = content
145
- if context:
146
- text = f"{content}\n{context}"
147
-
148
- # Track raw scores
149
- scores: dict[str, int] = {t: 0 for t in MEMORY_TYPES if t != "general"}
150
-
151
- for mem_type, patterns in TYPE_PATTERNS.items():
152
- for pattern in _get_patterns(mem_type):
153
- matches = pattern.findall(text)
154
- scores[mem_type] += len(matches)
155
-
156
- # Normalize to confidence
157
- total = sum(scores.values())
158
- if total == 0:
159
- return {"general": 1.0}
160
-
161
- confidences = {t: s / total for t, s in scores.items() if s > 0}
162
- if not confidences:
163
- return {"general": 1.0}
164
-
165
- return confidences
omni_cortex/config.py DELETED
@@ -1,141 +0,0 @@
1
- """Configuration management for Omni Cortex."""
2
-
3
- import os
4
- from pathlib import Path
5
- from typing import Optional
6
- from dataclasses import dataclass, field
7
-
8
- import yaml
9
-
10
-
11
- @dataclass
12
- class CortexConfig:
13
- """Configuration settings for Omni Cortex."""
14
-
15
- # Database
16
- schema_version: str = "1.0"
17
-
18
- # Embedding (disabled by default - model loading can be slow)
19
- embedding_model: str = "all-MiniLM-L6-v2"
20
- embedding_enabled: bool = False
21
-
22
- # Decay
23
- decay_rate_per_day: float = 0.5
24
- freshness_review_days: int = 30
25
-
26
- # Output
27
- max_output_truncation: int = 10000
28
- max_tool_input_size: int = 10000
29
-
30
- # Session
31
- auto_provide_context: bool = True
32
- context_depth: int = 3
33
-
34
- # Search (default to keyword since embeddings are disabled by default)
35
- default_search_mode: str = "keyword"
36
-
37
- # Global
38
- global_sync_enabled: bool = True
39
- api_fallback_enabled: bool = False
40
- api_key: str = ""
41
-
42
-
43
- def get_project_path() -> Path:
44
- """Get the current project path from environment or cwd."""
45
- return Path(os.environ.get("CLAUDE_PROJECT_DIR", os.getcwd()))
46
-
47
-
48
- def get_project_db_dir() -> Path:
49
- """Get the project-local .omni-cortex directory."""
50
- return get_project_path() / ".omni-cortex"
51
-
52
-
53
- def get_project_db_path() -> Path:
54
- """Get the path to the project database."""
55
- return get_project_db_dir() / "cortex.db"
56
-
57
-
58
- def get_global_db_dir() -> Path:
59
- """Get the global ~/.omni-cortex directory."""
60
- return Path.home() / ".omni-cortex"
61
-
62
-
63
- def get_global_db_path() -> Path:
64
- """Get the path to the global database."""
65
- return get_global_db_dir() / "global.db"
66
-
67
-
68
- def get_session_id() -> Optional[str]:
69
- """Get the current session ID from environment."""
70
- return os.environ.get("CLAUDE_SESSION_ID")
71
-
72
-
73
- def load_config(project_path: Optional[Path] = None) -> CortexConfig:
74
- """Load configuration from project and global config files.
75
-
76
- Priority: project config > global config > defaults
77
- """
78
- config = CortexConfig()
79
-
80
- # Load global config
81
- global_config_path = get_global_db_dir() / "config.yaml"
82
- if global_config_path.exists():
83
- try:
84
- with open(global_config_path, "r") as f:
85
- global_cfg = yaml.safe_load(f) or {}
86
- _apply_config(config, global_cfg)
87
- except Exception:
88
- pass
89
-
90
- # Load project config
91
- if project_path is None:
92
- project_path = get_project_path()
93
- project_config_path = project_path / ".omni-cortex" / "config.yaml"
94
- if project_config_path.exists():
95
- try:
96
- with open(project_config_path, "r") as f:
97
- project_cfg = yaml.safe_load(f) or {}
98
- _apply_config(config, project_cfg)
99
- except Exception:
100
- pass
101
-
102
- return config
103
-
104
-
105
- def _apply_config(config: CortexConfig, data: dict) -> None:
106
- """Apply configuration data to config object."""
107
- for key, value in data.items():
108
- if hasattr(config, key) and value is not None:
109
- setattr(config, key, value)
110
-
111
-
112
- def save_config(config: CortexConfig, project: bool = True) -> None:
113
- """Save configuration to file.
114
-
115
- Args:
116
- config: Configuration to save
117
- project: If True, save to project config; otherwise global
118
- """
119
- if project:
120
- config_dir = get_project_db_dir()
121
- else:
122
- config_dir = get_global_db_dir()
123
-
124
- config_dir.mkdir(parents=True, exist_ok=True)
125
- config_path = config_dir / "config.yaml"
126
-
127
- data = {
128
- "schema_version": config.schema_version,
129
- "embedding_model": config.embedding_model,
130
- "embedding_enabled": config.embedding_enabled,
131
- "decay_rate_per_day": config.decay_rate_per_day,
132
- "freshness_review_days": config.freshness_review_days,
133
- "max_output_truncation": config.max_output_truncation,
134
- "auto_provide_context": config.auto_provide_context,
135
- "context_depth": config.context_depth,
136
- "default_search_mode": config.default_search_mode,
137
- "global_sync_enabled": config.global_sync_enabled,
138
- }
139
-
140
- with open(config_path, "w") as f:
141
- yaml.dump(data, f, default_flow_style=False)