cortex-kg 0.3.3__tar.gz → 0.3.4__tar.gz
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.
- {cortex_kg-0.3.3/src/cortex_kg.egg-info → cortex_kg-0.3.4}/PKG-INFO +1 -1
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/pyproject.toml +1 -1
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/__init__.py +1 -1
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/api/graph_viz.py +91 -7
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/api/rest.py +52 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/api/workspace_viz.py +38 -3
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/api_client.py +8 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/cli.py +143 -5
- cortex_kg-0.3.4/src/cortex/maintenance.py +223 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/server_profile/neo4j_store.py +49 -1
- cortex_kg-0.3.3/src/cortex/static/brain/assets/index-CrChQ736.css → cortex_kg-0.3.4/src/cortex/static/brain/assets/index-B1Qme9VI.css +1 -1
- cortex_kg-0.3.4/src/cortex/static/brain/assets/index-BHGAsAmN.js +488 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/static/brain/index.html +2 -2
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/storage/graph_store.py +139 -1
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/storage/keyword_store.py +8 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/storage/vector_store.py +23 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4/src/cortex_kg.egg-info}/PKG-INFO +1 -1
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex_kg.egg-info/SOURCES.txt +3 -2
- cortex_kg-0.3.3/src/cortex/static/brain/assets/index-CupNnt97.js +0 -488
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/LICENSE +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/MANIFEST.in +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/README.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/README.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/automation.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/benchmarks/graphify-vs-cortex-2026-07-25-post.json +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/benchmarks/graphify-vs-cortex-2026-07-25-rerun.json +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/benchmarks/graphify-vs-cortex-2026-07-25.json +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/benchmarks/graphify-vs-cortex-2026-07-25.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/cortex-brain.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/cortex-vs-graphify-replacement-rating.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/cursor.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/installation.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/other-platforms.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/project-workflow.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/publishing.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/templates/cortex-agent-rule.mdc +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/docs/templates/cortex-mcp.json +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/examples/sample_repo/README.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/examples/sample_repo/api/openapi.yaml +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/examples/sample_repo/docs/adr-001-session-tokens.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/examples/sample_repo/docs/architecture.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/examples/sample_repo/notes/meeting-2026-07-10-billing-sync.md +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/examples/sample_repo/schema/schema.sql +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/examples/sample_repo/src/auth_service.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/examples/sample_repo/src/billing_service.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/scripts/build_brain_ui.sh +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/sdk/python/cortex_sdk/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/sdk/python/pyproject.toml +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/sdk/typescript/package.json +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/sdk/typescript/src/index.ts +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/sdk/typescript/tsconfig.json +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/setup.cfg +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/__main__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/agents/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/agents/hooks.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/agents/writeback.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/analysis/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/analysis/flows.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/analysis/hubs.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/analysis/orientation.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/api/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/bench/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/bench/graphify_parity.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/config.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/context/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/context/generator.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/daemon.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/doctor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/evidence.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/export/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/export/studio.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/api_spec_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/base.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/code_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/db_schema_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/git_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/image_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/llm_relation_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/markdown_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/module_resolver.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/notes_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/extractors/pdf_extractor.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/ingestion/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/ingestion/content_hash.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/ingestion/ignore.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/ingestion/pipeline.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/ingestion/resolver.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/mcp_server/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/mcp_server/server.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/mcp_server/workspace_ctx.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/models.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/offline/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/offline/local_llm.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/ontology/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/ontology/registry.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/plugins/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/plugins/examples/jira_like_plugin/plugin.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/plugins/interface.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/plugins/loader.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/project_binding.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/replication/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/replication/crdt.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/retrieval/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/retrieval/embeddings.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/retrieval/fusion.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/retrieval/planner.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/retrieval/query_engine.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/retrieval/traversal.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/review/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/review/pack.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/security/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/security/acl.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/security/audit.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/security/encryption.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/security/secrets_scanner.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/server_profile/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/setup/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/setup/generators.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/storage/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/storage/provenance.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/sync/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/sync/change_feed.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/sync/job_queue.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/sync/watch_manager.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/sync/watcher.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/versioning/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/versioning/bitemporal.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/workspace/__init__.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/workspace/federation.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex/workspace/registry.py +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex_kg.egg-info/dependency_links.txt +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex_kg.egg-info/entry_points.txt +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex_kg.egg-info/requires.txt +0 -0
- {cortex_kg-0.3.3 → cortex_kg-0.3.4}/src/cortex_kg.egg-info/top_level.txt +0 -0
|
@@ -72,8 +72,12 @@ def _csv(value: Optional[str]) -> Optional[list[str]]:
|
|
|
72
72
|
return [v.strip() for v in value.split(",") if v.strip()]
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
def _node_payload(
|
|
76
|
-
|
|
75
|
+
def _node_payload(
|
|
76
|
+
n: Node,
|
|
77
|
+
*,
|
|
78
|
+
projects: Optional[list[str]] = None,
|
|
79
|
+
) -> dict[str, Any]:
|
|
80
|
+
payload: dict[str, Any] = {
|
|
77
81
|
"id": n.id,
|
|
78
82
|
"type": n.type,
|
|
79
83
|
"label": n.canonical_name,
|
|
@@ -85,6 +89,9 @@ def _node_payload(n: Node) -> dict[str, Any]:
|
|
|
85
89
|
"validFrom": n.valid_from,
|
|
86
90
|
"validTo": n.valid_to,
|
|
87
91
|
}
|
|
92
|
+
if projects is not None:
|
|
93
|
+
payload["projects"] = projects
|
|
94
|
+
return payload
|
|
88
95
|
|
|
89
96
|
|
|
90
97
|
def _edge_payload(e: Edge, daemon: Optional[CortexDaemon] = None) -> dict[str, Any]:
|
|
@@ -112,9 +119,20 @@ def _edge_payload(e: Edge, daemon: Optional[CortexDaemon] = None) -> dict[str, A
|
|
|
112
119
|
|
|
113
120
|
def _graph_payload(nodes: list[Node], edges: list[Edge], *, total: int, truncated: bool,
|
|
114
121
|
view: str, extra: Optional[dict] = None,
|
|
115
|
-
daemon: Optional[CortexDaemon] = None
|
|
122
|
+
daemon: Optional[CortexDaemon] = None,
|
|
123
|
+
node_projects: Optional[dict[str, list[str]]] = None) -> dict[str, Any]:
|
|
124
|
+
projects_map = node_projects
|
|
125
|
+
if projects_map is None and daemon is not None and getattr(daemon, "query_engine", None) is not None:
|
|
126
|
+
try:
|
|
127
|
+
projects_map = daemon.query_engine.node_projects_map()
|
|
128
|
+
except Exception:
|
|
129
|
+
projects_map = {}
|
|
130
|
+
projects_map = projects_map or {}
|
|
116
131
|
payload = {
|
|
117
|
-
"nodes": [
|
|
132
|
+
"nodes": [
|
|
133
|
+
_node_payload(n, projects=list(projects_map.get(n.id, [])))
|
|
134
|
+
for n in nodes
|
|
135
|
+
],
|
|
118
136
|
"edges": [_edge_payload(e, daemon) for e in edges],
|
|
119
137
|
"total": total,
|
|
120
138
|
"returned": len(nodes),
|
|
@@ -138,6 +156,62 @@ def _collect_by_types(daemon: CortexDaemon, types: list[str], limit: int) -> dic
|
|
|
138
156
|
return out
|
|
139
157
|
|
|
140
158
|
|
|
159
|
+
def _brain_nodes_fair_share(daemon: CortexDaemon, limit: int) -> dict[str, Node]:
|
|
160
|
+
"""Fill the brain budget fairly across projects so a large ingest cannot
|
|
161
|
+
starve a second project's nodes out of the snapshot.
|
|
162
|
+
"""
|
|
163
|
+
ws = daemon.workspace_id
|
|
164
|
+
projects = daemon.graph.list_nodes(type_="Project", workspace_id=ws, limit=500)
|
|
165
|
+
if not projects:
|
|
166
|
+
return {n.id: n for n in daemon.graph.list_nodes(workspace_id=ws, limit=limit)}
|
|
167
|
+
|
|
168
|
+
buckets: list[list[Node]] = []
|
|
169
|
+
claimed: set[str] = set()
|
|
170
|
+
for proj in projects:
|
|
171
|
+
members, _ = daemon.graph.traverse(
|
|
172
|
+
proj.id, edge_types=["consumes"], direction="out", max_depth=1,
|
|
173
|
+
)
|
|
174
|
+
# Highest confidence first, then newest created_at.
|
|
175
|
+
ranked = sorted(
|
|
176
|
+
members,
|
|
177
|
+
key=lambda n: (n.confidence or 0.0, n.created_at or ""),
|
|
178
|
+
reverse=True,
|
|
179
|
+
)
|
|
180
|
+
bucket = [
|
|
181
|
+
m for m in ranked
|
|
182
|
+
if m.id != proj.id and m.type not in _MEMBERSHIP_NODE_TYPES and m.id not in claimed
|
|
183
|
+
]
|
|
184
|
+
for m in bucket:
|
|
185
|
+
claimed.add(m.id)
|
|
186
|
+
buckets.append(bucket)
|
|
187
|
+
|
|
188
|
+
out: dict[str, Node] = {}
|
|
189
|
+
indices = [0] * len(buckets)
|
|
190
|
+
while len(out) < limit:
|
|
191
|
+
progressed = False
|
|
192
|
+
for i, bucket in enumerate(buckets):
|
|
193
|
+
while indices[i] < len(bucket):
|
|
194
|
+
node = bucket[indices[i]]
|
|
195
|
+
indices[i] += 1
|
|
196
|
+
if node.id not in out:
|
|
197
|
+
out[node.id] = node
|
|
198
|
+
progressed = True
|
|
199
|
+
break
|
|
200
|
+
if len(out) >= limit:
|
|
201
|
+
break
|
|
202
|
+
if not progressed:
|
|
203
|
+
break
|
|
204
|
+
|
|
205
|
+
if len(out) < limit:
|
|
206
|
+
for n in daemon.graph.list_nodes(workspace_id=ws, limit=max(limit * 2, limit)):
|
|
207
|
+
if n.id in out or n.type in _MEMBERSHIP_NODE_TYPES:
|
|
208
|
+
continue
|
|
209
|
+
out[n.id] = n
|
|
210
|
+
if len(out) >= limit:
|
|
211
|
+
break
|
|
212
|
+
return out
|
|
213
|
+
|
|
214
|
+
|
|
141
215
|
@router.get("/snapshot")
|
|
142
216
|
def snapshot(
|
|
143
217
|
view: str = Query(default="brain", description="brain|project|technology|architecture|business|relationship|code"),
|
|
@@ -149,6 +223,14 @@ def snapshot(
|
|
|
149
223
|
since: Optional[str] = Query(default=None, description="ISO timestamp; only nodes created at/after this (Timeline view)"),
|
|
150
224
|
until: Optional[str] = Query(default=None, description="ISO timestamp; only nodes created at/before this (Timeline view)"),
|
|
151
225
|
limit: int = Query(default=1500, ge=1, le=20000),
|
|
226
|
+
include_code_layer: bool = Query(
|
|
227
|
+
default=False,
|
|
228
|
+
description="When true, keep CodeFile/Function/Class in the brain overview",
|
|
229
|
+
),
|
|
230
|
+
include_projects: bool = Query(
|
|
231
|
+
default=False,
|
|
232
|
+
description="When true, keep Project hubs in the brain overview",
|
|
233
|
+
),
|
|
152
234
|
daemon: CortexDaemon = Depends(daemon_dep),
|
|
153
235
|
) -> dict:
|
|
154
236
|
"""Bounded, filterable snapshot of the graph, shaped for the WebGL
|
|
@@ -219,8 +301,8 @@ def snapshot(
|
|
|
219
301
|
if type_filter:
|
|
220
302
|
nodes_by_id = _collect_by_types(daemon, type_filter, limit)
|
|
221
303
|
else:
|
|
222
|
-
|
|
223
|
-
nodes_by_id =
|
|
304
|
+
# Fair-share across projects so multi-project workspaces stay balanced.
|
|
305
|
+
nodes_by_id = _brain_nodes_fair_share(daemon, limit)
|
|
224
306
|
|
|
225
307
|
if type_filter and view not in _VIEW_NODE_TYPES and view != "code":
|
|
226
308
|
nodes_by_id = {nid: n for nid, n in nodes_by_id.items() if n.type in type_filter}
|
|
@@ -237,6 +319,7 @@ def snapshot(
|
|
|
237
319
|
hide_membership = (
|
|
238
320
|
view == "brain"
|
|
239
321
|
and not project
|
|
322
|
+
and not include_projects
|
|
240
323
|
and edge_types is None
|
|
241
324
|
and (type_filter is None or not any(t in _MEMBERSHIP_NODE_TYPES for t in type_filter))
|
|
242
325
|
)
|
|
@@ -248,6 +331,7 @@ def snapshot(
|
|
|
248
331
|
# Brain overview: hide dense AST code layer unless explicitly requested.
|
|
249
332
|
hide_code_layer = (
|
|
250
333
|
view == "brain"
|
|
334
|
+
and not include_code_layer
|
|
251
335
|
and (type_filter is None or not any(t in _CODE_LAYER_NODE_TYPES for t in type_filter))
|
|
252
336
|
)
|
|
253
337
|
if hide_code_layer:
|
|
@@ -265,7 +349,7 @@ def snapshot(
|
|
|
265
349
|
|
|
266
350
|
return _graph_payload(
|
|
267
351
|
list(nodes_by_id.values()), edges,
|
|
268
|
-
total=total_nodes, truncated=
|
|
352
|
+
total=total_nodes, truncated=total_nodes > len(nodes_by_id),
|
|
269
353
|
view=view, extra=extra, daemon=daemon,
|
|
270
354
|
)
|
|
271
355
|
|
|
@@ -506,6 +506,58 @@ def list_projects(daemon: CortexDaemon = Depends(daemon_dep)) -> list[dict]:
|
|
|
506
506
|
return out
|
|
507
507
|
|
|
508
508
|
|
|
509
|
+
@app.delete("/projects")
|
|
510
|
+
def delete_project(
|
|
511
|
+
name: str = Query(..., description="project canonical_name"),
|
|
512
|
+
purge_exclusive: bool = Query(
|
|
513
|
+
default=False,
|
|
514
|
+
description="also delete knowledge nodes exclusively consumed by this project",
|
|
515
|
+
),
|
|
516
|
+
dry_run: bool = Query(default=True, description="preview counts without mutating"),
|
|
517
|
+
yes: bool = Query(default=False, description="required to apply when dry_run=false"),
|
|
518
|
+
daemon: CortexDaemon = Depends(daemon_dep),
|
|
519
|
+
) -> dict:
|
|
520
|
+
"""Detach a Project (drop consumes edges + unlink roots). Optional exclusive purge."""
|
|
521
|
+
from cortex.maintenance import remove_project
|
|
522
|
+
|
|
523
|
+
if not dry_run and not yes:
|
|
524
|
+
raise HTTPException(
|
|
525
|
+
status_code=400,
|
|
526
|
+
detail="set dry_run=false and yes=true to apply destructive changes",
|
|
527
|
+
)
|
|
528
|
+
report = remove_project(
|
|
529
|
+
daemon, name=name, purge_exclusive=purge_exclusive, dry_run=dry_run,
|
|
530
|
+
)
|
|
531
|
+
if not report.get("ok"):
|
|
532
|
+
raise HTTPException(status_code=404, detail=report.get("error", "project not found"))
|
|
533
|
+
return report
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
class PruneIn(BaseModel):
|
|
537
|
+
mode: str = "dangling" # dangling | low_confidence | rejected
|
|
538
|
+
threshold: float = 0.3
|
|
539
|
+
dry_run: bool = True
|
|
540
|
+
yes: bool = False
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
@app.post("/graph/prune")
|
|
544
|
+
def prune_graph(body: PruneIn, daemon: CortexDaemon = Depends(daemon_dep)) -> dict:
|
|
545
|
+
"""Prune dangling, low-confidence, or rejected edges."""
|
|
546
|
+
from cortex.maintenance import prune_connections
|
|
547
|
+
|
|
548
|
+
if not body.dry_run and not body.yes:
|
|
549
|
+
raise HTTPException(
|
|
550
|
+
status_code=400,
|
|
551
|
+
detail="set dry_run=false and yes=true to apply destructive changes",
|
|
552
|
+
)
|
|
553
|
+
report = prune_connections(
|
|
554
|
+
daemon, mode=body.mode, threshold=body.threshold, dry_run=body.dry_run,
|
|
555
|
+
)
|
|
556
|
+
if not report.get("ok"):
|
|
557
|
+
raise HTTPException(status_code=400, detail=report.get("error", "prune failed"))
|
|
558
|
+
return report
|
|
559
|
+
|
|
560
|
+
|
|
509
561
|
@app.post("/nodes", response_model=NodeOut)
|
|
510
562
|
def create_node(body: NodeIn, daemon: CortexDaemon = Depends(daemon_dep)) -> NodeOut:
|
|
511
563
|
daemon.ontology.ensure_node_type(body.type, registered_by=f"api:{body.actor}")
|
|
@@ -101,8 +101,14 @@ def _workspace_synthetic_node(ws: str, name: str, node_count: int, edge_count: i
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
def _node_payload_ws(
|
|
105
|
-
|
|
104
|
+
def _node_payload_ws(
|
|
105
|
+
n: Node,
|
|
106
|
+
workspace_ids: list[str],
|
|
107
|
+
shared_group: Optional[str] = None,
|
|
108
|
+
*,
|
|
109
|
+
projects: Optional[list[str]] = None,
|
|
110
|
+
) -> dict[str, Any]:
|
|
111
|
+
payload = _node_payload(n, projects=projects)
|
|
106
112
|
payload["workspaceIds"] = workspace_ids
|
|
107
113
|
payload["shared"] = len(workspace_ids) > 1
|
|
108
114
|
if shared_group:
|
|
@@ -207,6 +213,26 @@ def create_workspace(body: WorkspaceCreateIn) -> dict[str, Any]:
|
|
|
207
213
|
}
|
|
208
214
|
|
|
209
215
|
|
|
216
|
+
@router.post("/{workspace_id}/clear")
|
|
217
|
+
def clear_workspace_endpoint(
|
|
218
|
+
workspace_id: str,
|
|
219
|
+
dry_run: bool = Query(default=True),
|
|
220
|
+
yes: bool = Query(default=False),
|
|
221
|
+
) -> dict[str, Any]:
|
|
222
|
+
"""Wipe graph data, indexes, and source roots for a workspace."""
|
|
223
|
+
from cortex.maintenance import clear_workspace
|
|
224
|
+
|
|
225
|
+
if not dry_run and not yes:
|
|
226
|
+
raise HTTPException(
|
|
227
|
+
status_code=400,
|
|
228
|
+
detail="set dry_run=false and yes=true to apply destructive changes",
|
|
229
|
+
)
|
|
230
|
+
daemon, lock_err = _safe_daemon(workspace_id)
|
|
231
|
+
if daemon is None:
|
|
232
|
+
raise HTTPException(status_code=503, detail=lock_err or f"workspace '{workspace_id}' is locked")
|
|
233
|
+
return clear_workspace(daemon, dry_run=dry_run)
|
|
234
|
+
|
|
235
|
+
|
|
210
236
|
@router.get("/graph")
|
|
211
237
|
def workspace_graph(
|
|
212
238
|
workspaces: str = Query(default="*", description="comma-separated workspace ids, or * for every known workspace"),
|
|
@@ -285,6 +311,13 @@ def workspace_graph(
|
|
|
285
311
|
for ws in ws_ids:
|
|
286
312
|
nodes_by_id = per_ws_nodes.get(ws, {})
|
|
287
313
|
total += len(nodes_by_id)
|
|
314
|
+
projects_map: dict[str, list[str]] = {}
|
|
315
|
+
daemon = per_ws_daemons.get(ws)
|
|
316
|
+
if daemon is not None and getattr(daemon, "query_engine", None) is not None:
|
|
317
|
+
try:
|
|
318
|
+
projects_map = daemon.query_engine.node_projects_map()
|
|
319
|
+
except Exception:
|
|
320
|
+
projects_map = {}
|
|
288
321
|
if include_workspace_nodes:
|
|
289
322
|
meta = ws_meta.get(ws, {"name": ws})
|
|
290
323
|
nodes_out.append(_workspace_synthetic_node(
|
|
@@ -293,7 +326,9 @@ def workspace_graph(
|
|
|
293
326
|
for n in nodes_by_id.values():
|
|
294
327
|
gid = node_to_group.get(n.id)
|
|
295
328
|
group_workspaces = node_to_group_workspaces.get(n.id, [ws])
|
|
296
|
-
nodes_out.append(_node_payload_ws(
|
|
329
|
+
nodes_out.append(_node_payload_ws(
|
|
330
|
+
n, group_workspaces, gid, projects=list(projects_map.get(n.id, [])),
|
|
331
|
+
))
|
|
297
332
|
for e in per_ws_edges.get(ws, []):
|
|
298
333
|
edges_out.append(_edge_payload(e, per_ws_daemons.get(ws)))
|
|
299
334
|
|
|
@@ -77,6 +77,14 @@ def api_post(path: str, body: dict[str, Any], *, workspace: str = DEFAULT_WORKSP
|
|
|
77
77
|
)
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
def api_delete(path: str, *, workspace: str = DEFAULT_WORKSPACE,
|
|
81
|
+
params: Optional[dict[str, Any]] = None, base_url: Optional[str] = None,
|
|
82
|
+
timeout: float = 120.0) -> Any:
|
|
83
|
+
return _request(
|
|
84
|
+
"DELETE", path, workspace=workspace, params=params, base_url=base_url, timeout=timeout,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
80
88
|
def api_post_ndjson(
|
|
81
89
|
path: str,
|
|
82
90
|
body: dict[str, Any],
|
|
@@ -305,11 +305,15 @@ def cmd_setup(args: argparse.Namespace) -> None:
|
|
|
305
305
|
project_name=args.project or Path(project_path).resolve().name,
|
|
306
306
|
via_api=via_api,
|
|
307
307
|
)
|
|
308
|
+
steps = cursor_enable_instructions(args.workspace)
|
|
308
309
|
print(json.dumps({
|
|
309
310
|
"written": written,
|
|
310
311
|
"mcp_transport": "url" if via_api else "stdio",
|
|
311
|
-
"next_steps":
|
|
312
|
+
"next_steps": steps,
|
|
312
313
|
}, indent=2))
|
|
314
|
+
print("\nNext steps (Cursor leaves new MCP servers disabled):", file=sys.stderr)
|
|
315
|
+
for i, step in enumerate(steps, 1):
|
|
316
|
+
print(f" {i}. {step}", file=sys.stderr)
|
|
313
317
|
else:
|
|
314
318
|
print(json.dumps({
|
|
315
319
|
"mcp": cursor_mcp_config(args.workspace, project_path, via_api=via_api),
|
|
@@ -334,8 +338,14 @@ def cmd_setup(args: argparse.Namespace) -> None:
|
|
|
334
338
|
dest.write_text(json.dumps(existing, indent=2) + "\n", encoding="utf-8")
|
|
335
339
|
payload: dict = {"written": str(dest), "config": existing}
|
|
336
340
|
if args.target in ("cursor", "vscode"):
|
|
337
|
-
|
|
338
|
-
|
|
341
|
+
steps = cursor_enable_instructions(args.workspace)
|
|
342
|
+
payload["next_steps"] = steps
|
|
343
|
+
print(json.dumps(payload, indent=2))
|
|
344
|
+
print("\nNext steps (Cursor leaves new MCP servers disabled):", file=sys.stderr)
|
|
345
|
+
for i, step in enumerate(steps, 1):
|
|
346
|
+
print(f" {i}. {step}", file=sys.stderr)
|
|
347
|
+
else:
|
|
348
|
+
print(json.dumps(payload, indent=2))
|
|
339
349
|
else:
|
|
340
350
|
print(json.dumps(config, indent=2))
|
|
341
351
|
|
|
@@ -697,10 +707,110 @@ def cmd_workspaces(args: argparse.Namespace) -> None:
|
|
|
697
707
|
print(json.dumps({"written": str(dest), "workspace": args.name}, indent=2))
|
|
698
708
|
return
|
|
699
709
|
|
|
700
|
-
|
|
710
|
+
if args.workspaces_command == "clear":
|
|
711
|
+
from cortex.daemon import get_daemon
|
|
712
|
+
from cortex.maintenance import clear_workspace
|
|
713
|
+
|
|
714
|
+
dry_run = not bool(getattr(args, "yes", False))
|
|
715
|
+
target = getattr(args, "name", None) or args.workspace
|
|
716
|
+
if _via_api():
|
|
717
|
+
from cortex.api_client import api_post
|
|
718
|
+
report = api_post(
|
|
719
|
+
f"/workspaces/{target}/clear",
|
|
720
|
+
{},
|
|
721
|
+
workspace=target,
|
|
722
|
+
params={"dry_run": "true" if dry_run else "false", "yes": "false" if dry_run else "true"},
|
|
723
|
+
)
|
|
724
|
+
print(json.dumps(report, indent=2, default=str))
|
|
725
|
+
if dry_run:
|
|
726
|
+
print("Dry run only. Re-run with --yes to apply.", file=sys.stderr)
|
|
727
|
+
return
|
|
728
|
+
daemon = get_daemon(target)
|
|
729
|
+
report = clear_workspace(daemon, dry_run=dry_run)
|
|
730
|
+
print(json.dumps(report, indent=2, default=str))
|
|
731
|
+
if dry_run:
|
|
732
|
+
print("Dry run only. Re-run with --yes to apply.", file=sys.stderr)
|
|
733
|
+
return
|
|
734
|
+
|
|
735
|
+
print("usage: cortex workspaces list|use <name>|clear [--yes]", file=sys.stderr)
|
|
701
736
|
sys.exit(1)
|
|
702
737
|
|
|
703
738
|
|
|
739
|
+
def cmd_projects(args: argparse.Namespace) -> None:
|
|
740
|
+
if args.projects_command == "list":
|
|
741
|
+
if _via_api():
|
|
742
|
+
from cortex.api_client import api_get
|
|
743
|
+
print(json.dumps(api_get("/projects", workspace=args.workspace), indent=2, default=str))
|
|
744
|
+
return
|
|
745
|
+
from cortex.daemon import get_daemon
|
|
746
|
+
daemon = get_daemon(args.workspace)
|
|
747
|
+
projects = daemon.graph.list_nodes(type_="Project", workspace_id=daemon.workspace_id, limit=500)
|
|
748
|
+
print(json.dumps([
|
|
749
|
+
{"id": p.id, "name": p.canonical_name, "created_at": p.created_at}
|
|
750
|
+
for p in projects
|
|
751
|
+
], indent=2))
|
|
752
|
+
return
|
|
753
|
+
|
|
754
|
+
if args.projects_command == "remove":
|
|
755
|
+
from cortex.daemon import get_daemon
|
|
756
|
+
from cortex.maintenance import remove_project
|
|
757
|
+
|
|
758
|
+
dry_run = not bool(getattr(args, "yes", False))
|
|
759
|
+
purge = bool(getattr(args, "purge_exclusive", False))
|
|
760
|
+
if _via_api():
|
|
761
|
+
from cortex.api_client import api_delete
|
|
762
|
+
report = api_delete(
|
|
763
|
+
"/projects",
|
|
764
|
+
workspace=args.workspace,
|
|
765
|
+
params={
|
|
766
|
+
"name": args.name,
|
|
767
|
+
"purge_exclusive": "true" if purge else "false",
|
|
768
|
+
"dry_run": "true" if dry_run else "false",
|
|
769
|
+
"yes": "false" if dry_run else "true",
|
|
770
|
+
},
|
|
771
|
+
)
|
|
772
|
+
print(json.dumps(report, indent=2, default=str))
|
|
773
|
+
if dry_run:
|
|
774
|
+
print("Dry run only. Re-run with --yes to apply.", file=sys.stderr)
|
|
775
|
+
return
|
|
776
|
+
daemon = get_daemon(args.workspace)
|
|
777
|
+
report = remove_project(
|
|
778
|
+
daemon, name=args.name, purge_exclusive=purge, dry_run=dry_run,
|
|
779
|
+
)
|
|
780
|
+
print(json.dumps(report, indent=2, default=str))
|
|
781
|
+
if dry_run:
|
|
782
|
+
print("Dry run only. Re-run with --yes to apply.", file=sys.stderr)
|
|
783
|
+
return
|
|
784
|
+
|
|
785
|
+
print("usage: cortex projects list|remove <name> [--purge-exclusive] [--yes]", file=sys.stderr)
|
|
786
|
+
sys.exit(1)
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
def cmd_prune(args: argparse.Namespace) -> None:
|
|
790
|
+
from cortex.daemon import get_daemon
|
|
791
|
+
from cortex.maintenance import prune_connections
|
|
792
|
+
|
|
793
|
+
dry_run = not bool(getattr(args, "yes", False))
|
|
794
|
+
mode = getattr(args, "mode", "dangling") or "dangling"
|
|
795
|
+
threshold = float(getattr(args, "threshold", 0.3) or 0.3)
|
|
796
|
+
if _via_api():
|
|
797
|
+
from cortex.api_client import api_post
|
|
798
|
+
report = api_post(
|
|
799
|
+
"/graph/prune",
|
|
800
|
+
{"mode": mode, "threshold": threshold, "dry_run": dry_run, "yes": not dry_run},
|
|
801
|
+
workspace=args.workspace,
|
|
802
|
+
)
|
|
803
|
+
print(json.dumps(report, indent=2, default=str))
|
|
804
|
+
if dry_run:
|
|
805
|
+
print("Dry run only. Re-run with --yes to apply.", file=sys.stderr)
|
|
806
|
+
return
|
|
807
|
+
daemon = get_daemon(args.workspace)
|
|
808
|
+
report = prune_connections(daemon, mode=mode, threshold=threshold, dry_run=dry_run)
|
|
809
|
+
print(json.dumps(report, indent=2, default=str))
|
|
810
|
+
if dry_run:
|
|
811
|
+
print("Dry run only. Re-run with --yes to apply.", file=sys.stderr)
|
|
812
|
+
|
|
813
|
+
|
|
704
814
|
def cmd_shell(args: argparse.Namespace) -> None:
|
|
705
815
|
"""Long-lived REPL so search/context avoid ~50ms process start tax."""
|
|
706
816
|
from cortex.api_client import api_get, api_reachable
|
|
@@ -868,7 +978,7 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
868
978
|
)
|
|
869
979
|
p_setup.set_defaults(func=cmd_setup)
|
|
870
980
|
|
|
871
|
-
p_ws = sub.add_parser("workspaces", help="List or
|
|
981
|
+
p_ws = sub.add_parser("workspaces", help="List, bind, or clear workspaces")
|
|
872
982
|
ws_sub = p_ws.add_subparsers(dest="workspaces_command", required=True)
|
|
873
983
|
ws_sub.add_parser("list").set_defaults(func=cmd_workspaces)
|
|
874
984
|
p_ws_use = ws_sub.add_parser("use")
|
|
@@ -876,6 +986,34 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
876
986
|
p_ws_use.add_argument("--path", default=".")
|
|
877
987
|
p_ws_use.add_argument("--api-url", default=None, dest="api_url")
|
|
878
988
|
p_ws_use.set_defaults(func=cmd_workspaces)
|
|
989
|
+
p_ws_clear = ws_sub.add_parser("clear", help="Wipe graph/indexes/sources for a workspace (dry-run by default)")
|
|
990
|
+
p_ws_clear.add_argument("name", nargs="?", default=None, help="Workspace id (default: --workspace)")
|
|
991
|
+
p_ws_clear.add_argument("--yes", action="store_true", help="Apply destructive clear (otherwise dry-run)")
|
|
992
|
+
p_ws_clear.set_defaults(func=cmd_workspaces)
|
|
993
|
+
|
|
994
|
+
p_projects = sub.add_parser("projects", help="List or remove projects in a workspace")
|
|
995
|
+
projects_sub = p_projects.add_subparsers(dest="projects_command", required=True)
|
|
996
|
+
projects_sub.add_parser("list").set_defaults(func=cmd_projects)
|
|
997
|
+
p_proj_rm = projects_sub.add_parser("remove", help="Detach a project (dry-run by default)")
|
|
998
|
+
p_proj_rm.add_argument("name")
|
|
999
|
+
p_proj_rm.add_argument(
|
|
1000
|
+
"--purge-exclusive",
|
|
1001
|
+
action="store_true",
|
|
1002
|
+
dest="purge_exclusive",
|
|
1003
|
+
help="Also delete knowledge nodes exclusively consumed by this project",
|
|
1004
|
+
)
|
|
1005
|
+
p_proj_rm.add_argument("--yes", action="store_true", help="Apply (otherwise dry-run)")
|
|
1006
|
+
p_proj_rm.set_defaults(func=cmd_projects)
|
|
1007
|
+
|
|
1008
|
+
p_prune = sub.add_parser("prune", help="Prune dangling / low-confidence / rejected edges (dry-run by default)")
|
|
1009
|
+
p_prune.add_argument(
|
|
1010
|
+
"--mode",
|
|
1011
|
+
default="dangling",
|
|
1012
|
+
choices=["dangling", "low_confidence", "rejected"],
|
|
1013
|
+
)
|
|
1014
|
+
p_prune.add_argument("--threshold", type=float, default=0.3, help="For low_confidence mode")
|
|
1015
|
+
p_prune.add_argument("--yes", action="store_true", help="Apply (otherwise dry-run)")
|
|
1016
|
+
p_prune.set_defaults(func=cmd_prune)
|
|
879
1017
|
|
|
880
1018
|
sub.add_parser("shell", help="Interactive REPL over serve-api").set_defaults(func=cmd_shell)
|
|
881
1019
|
|