codecortex 0.8.0__tar.gz → 0.8.1__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.
Files changed (66) hide show
  1. {codecortex-0.8.0/src/codecortex.egg-info → codecortex-0.8.1}/PKG-INFO +1 -1
  2. {codecortex-0.8.0 → codecortex-0.8.1/src/codecortex.egg-info}/PKG-INFO +1 -1
  3. codecortex-0.8.1/src/codeintel/__init__.py +1 -0
  4. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/__main__.py +6 -2
  5. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/mapper.py +46 -4
  6. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/server.py +5 -3
  7. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_mapper.py +57 -3
  8. codecortex-0.8.0/src/codeintel/__init__.py +0 -1
  9. {codecortex-0.8.0 → codecortex-0.8.1}/LICENSE +0 -0
  10. {codecortex-0.8.0 → codecortex-0.8.1}/README.md +0 -0
  11. {codecortex-0.8.0 → codecortex-0.8.1}/pyproject.toml +0 -0
  12. {codecortex-0.8.0 → codecortex-0.8.1}/setup.cfg +0 -0
  13. {codecortex-0.8.0 → codecortex-0.8.1}/src/codecortex.egg-info/SOURCES.txt +0 -0
  14. {codecortex-0.8.0 → codecortex-0.8.1}/src/codecortex.egg-info/dependency_links.txt +0 -0
  15. {codecortex-0.8.0 → codecortex-0.8.1}/src/codecortex.egg-info/entry_points.txt +0 -0
  16. {codecortex-0.8.0 → codecortex-0.8.1}/src/codecortex.egg-info/requires.txt +0 -0
  17. {codecortex-0.8.0 → codecortex-0.8.1}/src/codecortex.egg-info/top_level.txt +0 -0
  18. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/auth.py +0 -0
  19. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/cache.py +0 -0
  20. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/config.py +0 -0
  21. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/doctor.py +0 -0
  22. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/gateway.py +0 -0
  23. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/http_server.py +0 -0
  24. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/indexer.py +0 -0
  25. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/injector.py +0 -0
  26. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/installer.py +0 -0
  27. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/logconfig.py +0 -0
  28. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/metrics.py +0 -0
  29. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/onboarding.py +0 -0
  30. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/policy.py +0 -0
  31. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/provider.py +0 -0
  32. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/providers/__init__.py +0 -0
  33. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/providers/graph.py +0 -0
  34. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/providers/lsp.py +0 -0
  35. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/providers/none.py +0 -0
  36. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/providers/semantic.py +0 -0
  37. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/reindexer.py +0 -0
  38. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/reset.py +0 -0
  39. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/searcher.py +0 -0
  40. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/semantic_db.py +0 -0
  41. {codecortex-0.8.0 → codecortex-0.8.1}/src/codeintel/term.py +0 -0
  42. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_cache.py +0 -0
  43. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_chunking.py +0 -0
  44. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_config.py +0 -0
  45. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_doctor.py +0 -0
  46. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_e2e.py +0 -0
  47. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_enterprise.py +0 -0
  48. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_gateway.py +0 -0
  49. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_graph_provider.py +0 -0
  50. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_graph_real.py +0 -0
  51. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_graph_stdin.py +0 -0
  52. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_hardening.py +0 -0
  53. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_http_auth.py +0 -0
  54. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_http_server.py +0 -0
  55. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_integration.py +0 -0
  56. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_lsp_provider.py +0 -0
  57. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_lsp_real.py +0 -0
  58. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_never_raise.py +0 -0
  59. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_onboarding.py +0 -0
  60. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_rbac.py +0 -0
  61. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_reindexer.py +0 -0
  62. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_rerank.py +0 -0
  63. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_reset.py +0 -0
  64. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_semantic_provider.py +0 -0
  65. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_term.py +0 -0
  66. {codecortex-0.8.0 → codecortex-0.8.1}/tests/test_treesitter.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codecortex
3
- Version: 0.8.0
3
+ Version: 0.8.1
4
4
  Summary: Local-first, MCP-native code-intelligence server — graph, LSP, and semantic search behind one safe code.query tool for coding agents.
5
5
  Author: Shammai Hamilton
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: codecortex
3
- Version: 0.8.0
3
+ Version: 0.8.1
4
4
  Summary: Local-first, MCP-native code-intelligence server — graph, LSP, and semantic search behind one safe code.query tool for coding agents.
5
5
  Author: Shammai Hamilton
6
6
  License-Expression: MIT
@@ -0,0 +1 @@
1
+ __version__ = "0.8.1"
@@ -166,8 +166,12 @@ def main() -> None:
166
166
  gen = MapGenerator(provider)
167
167
  try:
168
168
  content = gen.generate(project_root, budget_bytes=args.budget)
169
- path = gen.write(project_root, content)
170
- print(f"Wrote {path} ({len(content.encode())} bytes)")
169
+ path, wrote = gen.write(project_root, content)
170
+ if wrote:
171
+ print(f"Wrote {path} ({len(content.encode())} bytes)")
172
+ else:
173
+ print(f"Kept existing {path} — new map was a stub (graph empty/unindexed; "
174
+ f"run `codeintel index` first)")
171
175
  if args.inject:
172
176
  inj_path, inj_action = Injector().inject(project_root)
173
177
  if inj_path:
@@ -1,11 +1,30 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import logging
3
4
  import os
4
5
  from typing import Optional, TYPE_CHECKING
5
6
 
6
7
  if TYPE_CHECKING:
7
8
  from codeintel.providers.graph import GraphProvider
8
9
 
10
+ logger = logging.getLogger(__name__)
11
+
12
+ # A map with any of these sections carries real, indexed orientation content. Anything without
13
+ # them is a degraded stub: `_minimal_map` (graph unavailable / repo unindexed / generation failed),
14
+ # or a render over an empty graph. Note the ranked marker includes "(by caller count)" — the
15
+ # empty-graph render emits a differently-worded "## Ranked Symbols" heading that is NOT this.
16
+ _POPULATED_MARKERS = (
17
+ "## Architecture Overview",
18
+ "## Ranked Symbols (by caller count)",
19
+ "## Entry Points",
20
+ )
21
+
22
+
23
+ def _is_populated_map(text: str) -> bool:
24
+ """True when the map has real content (architecture overview, a ranked-symbol table, or entry
25
+ points) rather than a degraded stub — used to avoid overwriting a good CODE_INTEL.md."""
26
+ return any(marker in text for marker in _POPULATED_MARKERS)
27
+
9
28
  # Real codebase-memory-mcp contract (verified live): query_graph returns {columns, rows}
10
29
  # value-arrays, module-level calls are USAGE (not only CALLS), and nodes carry `is_entry_point`
11
30
  # (there is no `fn.type` property — that filter matched nothing, so the old queries were dead).
@@ -82,15 +101,38 @@ class MapGenerator:
82
101
  except Exception as exc:
83
102
  return _minimal_map(project_root, note=f"map generation failed: {exc}")
84
103
 
85
- def write(self, project_root: str, content: str) -> str:
104
+ def write(self, project_root: str, content: str) -> tuple[str, bool]:
105
+ """Write CODE_INTEL.md; return ``(path, wrote)``. ``wrote`` is False when an existing
106
+ populated map was preserved rather than clobbered by a stub (or the write failed), so
107
+ callers can report the outcome honestly.
108
+
109
+ Don't clobber a good map with a degraded stub: `generate` returns a stub when the graph
110
+ backend is unavailable or hasn't indexed this repo yet — a common transient during
111
+ `codeintel index`'s best-effort refresh. Overwriting a previously-populated CODE_INTEL.md
112
+ with that stub silently destroys real orientation content, so when the new content is a
113
+ stub and an existing map is populated, preserve the existing file."""
86
114
  path = os.path.join(project_root, "CODE_INTEL.md")
115
+ if not _is_populated_map(content):
116
+ try:
117
+ if os.path.isfile(path):
118
+ with open(path, encoding="utf-8") as f:
119
+ existing = f.read()
120
+ if _is_populated_map(existing):
121
+ logger.warning(
122
+ "CODE_INTEL.md: new map is a stub (graph empty/unavailable) — keeping "
123
+ "the existing populated map at %s (run `codeintel index` to refresh)",
124
+ path,
125
+ )
126
+ return path, False
127
+ except Exception:
128
+ pass # can't read the existing file — fall through and write (best-effort)
87
129
  try:
88
130
  with open(path, "w", encoding="utf-8") as f:
89
131
  f.write(content)
132
+ return path, True
90
133
  except Exception as exc:
91
- import logging
92
- logging.getLogger(__name__).warning("CODE_INTEL.md write failed: %s", exc)
93
- return path
134
+ logger.warning("CODE_INTEL.md write failed: %s", exc)
135
+ return path, False
94
136
 
95
137
 
96
138
  def _query_ranked_symbols(provider: GraphProvider, project: str) -> list[dict]:
@@ -195,15 +195,17 @@ def code_map_handler(args: dict) -> dict:
195
195
 
196
196
  gen = MapGenerator(provider)
197
197
  content = gen.generate(project_root, budget_bytes=budget)
198
- path = gen.write(project_root, content)
199
- size = len(content.encode("utf-8"))
198
+ path, wrote = gen.write(project_root, content)
199
+ # size_bytes = bytes actually written; 0 when an existing populated map was preserved
200
+ # (the new content was a stub) — `wrote` disambiguates for the caller.
201
+ size = len(content.encode("utf-8")) if wrote else 0
200
202
 
201
203
  inject_result = None
202
204
  if inject:
203
205
  inj_path, inj_action = Injector().inject(project_root)
204
206
  inject_result = {"path": inj_path, "action": inj_action}
205
207
 
206
- return {"ok": True, "path": path, "size_bytes": size, "inject": inject_result}
208
+ return {"ok": True, "path": path, "size_bytes": size, "wrote": wrote, "inject": inject_result}
207
209
  except Exception:
208
210
  return {"ok": True, "path": None, "size_bytes": 0, "note": "map-error"}
209
211
 
@@ -6,9 +6,15 @@ from unittest.mock import MagicMock
6
6
 
7
7
  import pytest
8
8
 
9
- from codeintel.mapper import MapGenerator
9
+ from codeintel.mapper import MapGenerator, _minimal_map, _is_populated_map
10
10
  from codeintel.injector import Injector
11
11
 
12
+ _POPULATED = (
13
+ "# CODE_INTEL.md — repo\n\n"
14
+ "## Ranked Symbols (by caller count)\n"
15
+ "| Symbol | File | Callers |\n|--------|------|---------|\n| `foo` | a.py | 9 |\n"
16
+ )
17
+
12
18
 
13
19
  def _make_provider(ranked=None, entry=None, arch=None):
14
20
  """Return a mocked GraphProvider with configurable return values."""
@@ -117,13 +123,61 @@ def test_generate_reads_columns_rows_shape():
117
123
  def test_write_creates_file():
118
124
  gen = MapGenerator(None)
119
125
  with tempfile.TemporaryDirectory() as d:
120
- path = gen.write(d, "# content")
126
+ path, wrote = gen.write(d, "# content")
121
127
  expected = os.path.join(d, "CODE_INTEL.md")
122
- assert path == expected
128
+ assert path == expected and wrote is True
123
129
  assert os.path.exists(expected)
124
130
  assert open(expected).read() == "# content"
125
131
 
126
132
 
133
+ def test_write_preserves_populated_map_when_new_is_a_stub():
134
+ # the dogfooding bug: `codeintel index`'s best-effort refresh produced a stub (graph empty/
135
+ # unindexed at that moment) and clobbered a rich, populated CODE_INTEL.md. It must NOT.
136
+ gen = MapGenerator(None)
137
+ with tempfile.TemporaryDirectory() as d:
138
+ path = os.path.join(d, "CODE_INTEL.md")
139
+ open(path, "w").write(_POPULATED)
140
+ stub = _minimal_map(d, note="project not yet indexed")
141
+ assert not _is_populated_map(stub) and _is_populated_map(_POPULATED) # sanity
142
+ p, wrote = gen.write(d, stub)
143
+ assert p == path and wrote is False # preserved → reported as not written
144
+ assert open(path).read() == _POPULATED # preserved, not stubbed
145
+
146
+
147
+ def test_write_stub_ok_when_no_existing_map():
148
+ # first-ever generation of a stub is fine — there's nothing to preserve
149
+ gen = MapGenerator(None)
150
+ with tempfile.TemporaryDirectory() as d:
151
+ _, wrote = gen.write(d, _minimal_map(d, note="x"))
152
+ assert wrote is True
153
+ assert "Auto-generated" in open(os.path.join(d, "CODE_INTEL.md")).read()
154
+
155
+
156
+ def test_write_populated_replaces_a_stub():
157
+ # a real map SHOULD replace a prior stub — the normal refresh-improves case still works
158
+ gen = MapGenerator(None)
159
+ with tempfile.TemporaryDirectory() as d:
160
+ path = os.path.join(d, "CODE_INTEL.md")
161
+ open(path, "w").write(_minimal_map(d, note="stale"))
162
+ _, wrote = gen.write(d, _POPULATED)
163
+ assert wrote is True
164
+ assert _is_populated_map(open(path).read())
165
+
166
+
167
+ def test_entry_points_only_map_counts_as_populated():
168
+ # a sparse-but-real render (entry points, no arch/ranked table) is NOT a stub — it must refresh,
169
+ # not be misclassified and skipped (regression for the review's false-negative finding)
170
+ entry_only = ("# CODE_INTEL.md — repo\n\n## Ranked Symbols\n_(no symbols found)_\n\n"
171
+ "## Entry Points\n- `main` (app.py)\n")
172
+ assert _is_populated_map(entry_only)
173
+ gen = MapGenerator(None)
174
+ with tempfile.TemporaryDirectory() as d:
175
+ path = os.path.join(d, "CODE_INTEL.md")
176
+ open(path, "w").write(_POPULATED)
177
+ _, wrote = gen.write(d, entry_only) # real content replaces the old map, not skipped
178
+ assert wrote is True and "Entry Points" in open(path).read()
179
+
180
+
127
181
  # ---------------------------------------------------------------------------
128
182
  # Injector tests
129
183
  # ---------------------------------------------------------------------------
@@ -1 +0,0 @@
1
- __version__ = "0.8.0"
File without changes
File without changes
File without changes
File without changes
File without changes