code-context-control 2.158.4__py3-none-any.whl → 2.158.5__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.
- cli/c3.py +1 -1
- cli/server.py +4 -0
- {code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/METADATA +1 -1
- {code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/RECORD +14 -14
- oracle/services/mobile_api.py +41 -27
- oracle/services/mobile_fleet.py +4 -5
- services/file_memory.py +37 -22
- services/ollama_client.py +49 -17
- services/project_manager.py +1 -1
- services/retention.py +66 -1
- {code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/WHEEL +0 -0
- {code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/entry_points.txt +0 -0
- {code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/licenses/LICENSE +0 -0
- {code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/top_level.txt +0 -0
cli/c3.py
CHANGED
|
@@ -91,7 +91,7 @@ console = Console() if HAS_RICH else None
|
|
|
91
91
|
# Config
|
|
92
92
|
CONFIG_DIR = ".c3"
|
|
93
93
|
CONFIG_FILE = ".c3/config.json"
|
|
94
|
-
__version__ = "2.158.
|
|
94
|
+
__version__ = "2.158.5"
|
|
95
95
|
|
|
96
96
|
# The PreToolUse matcher for native subagent calls (installer and hub migration).
|
|
97
97
|
AGENT_MATCHER = "Agent|Task"
|
cli/server.py
CHANGED
|
@@ -346,6 +346,10 @@ def api_projects_open():
|
|
|
346
346
|
@app.route('/api/health')
|
|
347
347
|
def api_health():
|
|
348
348
|
"""Lightweight health check with connection sources."""
|
|
349
|
+
# ?probe=1 is the liveness form: identity only. The hub sends it for every
|
|
350
|
+
# UI server on every /api/projects poll and only reads "service".
|
|
351
|
+
if request.args.get("probe") not in (None, "", "0", "false"):
|
|
352
|
+
return jsonify({"service": "c3-ui", "probe": True})
|
|
349
353
|
sources = {"c3": True} # If this endpoint responds, C3 API is up
|
|
350
354
|
|
|
351
355
|
# Check Ollama
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code-context-control
|
|
3
|
-
Version: 2.158.
|
|
3
|
+
Version: 2.158.5
|
|
4
4
|
Summary: Local MCP code-intelligence for AI coding tools: surgical search/read/edit, agent-config version history, path-level access + masking guards, and a multi-project hub.
|
|
5
5
|
Author-email: Dimitri Tselenchuk <dtselenc@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
cli/__init__.py,sha256=ec66drCZGNMRU4V6ov0zVhYZph1us12Vn8OvG_LJyRY,22
|
|
2
2
|
cli/_hook_utils.py,sha256=RhfS2WS5VMSi2w2Jxcts1wg5WC-UFp89JOQvcO5Jjb8,23002
|
|
3
3
|
cli/_shell_writes.py,sha256=iBbzK0v0d29rhrYgF3zKJIJbb1WSZhQjD_6w8-nOUec,7348
|
|
4
|
-
cli/c3.py,sha256=
|
|
4
|
+
cli/c3.py,sha256=fgDpzh09I0KH-AaM1XmMBINW7e6j3ndOc5ooN2Bl2qk,439372
|
|
5
5
|
cli/docs.html,sha256=pPxcP5ieY0DcfEDvegwIcRxbz1woLZoKLVSF-4JVy0Q,146784
|
|
6
6
|
cli/edits.html,sha256=UjAhoCmBmQ89cklGvJqzC6eyNP2tc8H6T-e01DVkLvE,43418
|
|
7
7
|
cli/hook_access_guard.py,sha256=4UF2YHp5_vISH7Gvolc_Bz3ppSye2lGpGx38egRLj1g,32116
|
|
@@ -28,7 +28,7 @@ cli/hub_ui.html,sha256=v41R_JAH4Jwodpy3tbeBUel-80FbNmffBrey-QH5Q64,2963
|
|
|
28
28
|
cli/mcp_proxy.py,sha256=r-Qhlie7gCtotex8yQUudCyBLRUK-IW6cNIW5RhBW0o,17648
|
|
29
29
|
cli/mcp_server.py,sha256=RcuX1Ljle6kRuMqzmwjsxkLHVQuATepaLJ1C3qIS4u4,84445
|
|
30
30
|
cli/progress.py,sha256=qTkNy0howOD3hXraMo4ok3dYTpBW5yG_tenKfF4UDM0,1470
|
|
31
|
-
cli/server.py,sha256=
|
|
31
|
+
cli/server.py,sha256=kK9ZNwPaYmohexrLSYuhncbB_cNN7jWKpFXKewddpPs,174314
|
|
32
32
|
cli/ui.html,sha256=uuPwIJNKDQH_fsaR3xNB2AKky9WzKfaXnKr_k3aTtxo,5715
|
|
33
33
|
cli/ui_legacy.html,sha256=cI8tC6RKmE2NIJOcsu7CY-zT4VznjcbD6NTjxb_fvUY,378460
|
|
34
34
|
cli/ui_nano.html,sha256=UAwQ6bbTOXAoGq191AZ7slhngR9edJSa3IhqpynveDg,27740
|
|
@@ -135,7 +135,7 @@ cli/ui/components/sessions.js,sha256=FIKtil76B8tCkAmcFV7hlj6GQ_DCJK2jCzvEmdK7NBE
|
|
|
135
135
|
cli/ui/components/settings.js,sha256=FXcn-UQE2mXC6HFsLeEas-wAUFKt0OJaLySroZQMhGA,84095
|
|
136
136
|
cli/ui/components/sidebar.js,sha256=K2ym2kUgpbyG-EBA_wBIIiqQY8qTatsiBZwzseMWuIQ,9939
|
|
137
137
|
cli/ui/components/tasks.js,sha256=vyKQ3uwoppMwvdEaHlhWXW4oWcAisx4NveqzMhsYqHo,38438
|
|
138
|
-
code_context_control-2.158.
|
|
138
|
+
code_context_control-2.158.5.dist-info/licenses/LICENSE,sha256=l8Kh5QCNWNvR6kIt8L0BUZvc2LAFiHv2c-FnsGnUZf4,11301
|
|
139
139
|
core/__init__.py,sha256=TSDCEcM4V7gcZVM3w2ykJaqEUch4Dkon-rivV17T73s,2501
|
|
140
140
|
core/codex_patch.py,sha256=CxvT_rQIwPNTRJZj9EHJmx0ZdOeSLxjiixuLI3Z7lPc,2107
|
|
141
141
|
core/config.py,sha256=wCjrZKXRywUbR6WRcO7optyOirAQ2DeRNdPCU0X5zIY,23762
|
|
@@ -168,8 +168,8 @@ oracle/services/insight_engine.py,sha256=lwcdXtjt3CSZLqHVpXx6SG5gDhZYUKwXt4Z8dGy
|
|
|
168
168
|
oracle/services/local_session.py,sha256=nkawOjDbotUp5wtZQnC1wPDw3HopNYMkoYqWpP5ToCU,9227
|
|
169
169
|
oracle/services/memory_reader.py,sha256=rSEmoIXQu2JkolHJIQWpn0piPJpyuf1KZvW_9liQwkU,3727
|
|
170
170
|
oracle/services/memory_writer.py,sha256=hpvYsxjhl293jEjGcRKfjG5njUaAOXKqbmJaUu1WdUU,6997
|
|
171
|
-
oracle/services/mobile_api.py,sha256=
|
|
172
|
-
oracle/services/mobile_fleet.py,sha256=
|
|
171
|
+
oracle/services/mobile_api.py,sha256=xpv5EAVN-mA7Fc0BoWrqZZoVWau-nDgEB7aMCYlwA0I,149909
|
|
172
|
+
oracle/services/mobile_fleet.py,sha256=1M6vN4vOlYdVt1qFDSK97PLPHjvZkus4ZZSRm-ow2Nc,23968
|
|
173
173
|
oracle/services/project_scanner.py,sha256=PkYJtwOLRME1EzwRy3GIkYk6Xw0u1_BzFcaMJ5gJ1_s,6118
|
|
174
174
|
oracle/services/review_agent.py,sha256=m_fzoHowpiibf0_iz3dF72LWSrwB_FbDd1am-SbeWXg,11273
|
|
175
175
|
oracle/services/schedule_api.py,sha256=wArv-2QE-P1qn5gNiMGisXA4kX-JJvsRabFpVqsClzQ,9212
|
|
@@ -248,7 +248,7 @@ services/embedding_index.py,sha256=-d6Gatqq5OCrneGbvDTGrWyzbVx7562SrwABOFBRhjY,4
|
|
|
248
248
|
services/enforcement_policy.py,sha256=znjABRB-8TSl0ELazY2ALzux2YJ5nWf8TvxLRhDsL2w,18905
|
|
249
249
|
services/error_reporting.py,sha256=HZ3ru8i5RLf8nq2R4iRnTs5sm1blUxknSbv5hdxuxs0,4139
|
|
250
250
|
services/file_map.py,sha256=j37DTR-UE_PMNj7vG2HiHucpwpJNaKgiD94UNUU-UXE,17091
|
|
251
|
-
services/file_memory.py,sha256=
|
|
251
|
+
services/file_memory.py,sha256=6wPXRCnBuRpV3Yi2nTyCU5FD7PyYl93ctLPXI_g1CSY,42387
|
|
252
252
|
services/fleet_overview.py,sha256=npWzUHoHVlgCafTE79GS7AUYYilMr5yuujuAns4fpLQ,19544
|
|
253
253
|
services/git_context.py,sha256=FFdA8Y46op4DYsUnZsXLTqxIjgxb0q_d-hkFTbosC8Q,9518
|
|
254
254
|
services/grok_integration.py,sha256=aiWVmG9e-0-9_MjrJ_p0dsbTSdAYFkLfsUMI7onmz0A,8299
|
|
@@ -277,7 +277,7 @@ services/memory_scorer.py,sha256=32wccyVFBgcNwKdjwj_7RDnPukxSWBng8ohsRPTpQMM,949
|
|
|
277
277
|
services/metrics.py,sha256=X4D5TgcQSFaFLbBoa1s3bAWf00DMMjq3IrOACrK-uDg,3289
|
|
278
278
|
services/notifications.py,sha256=9yy7Qkhe0-SjuxXDI8jxuee_a_f6S8s7uAB9BtcAa34,21426
|
|
279
279
|
services/ollama_bridge.py,sha256=16ukWS98H4wFulOphUJDuXhN61GCiay793XLoyxTU-s,17455
|
|
280
|
-
services/ollama_client.py,sha256=
|
|
280
|
+
services/ollama_client.py,sha256=liTolLq23KEupT-qMRhpQlU4cA1oBD9JI1fFawmXfhg,9079
|
|
281
281
|
services/ollama_credentials.py,sha256=EQx0YljYRrRBJ2voALlVTv11UBjfw-A6N7k7EP7fUFE,2770
|
|
282
282
|
services/oracle_service.py,sha256=BH_3YtyYJKNsFtoi8MQMLo8s70dE8CGE4KfT811q8io,5973
|
|
283
283
|
services/output_filter.py,sha256=lknQHs38JlRtXU4Ogoru6sveNokSKBQPfZXhf-fE0xM,21736
|
|
@@ -287,7 +287,7 @@ services/override_policy.py,sha256=TehVPxfQ8LZWIOUzCnnioIdMUPZZ7JZa1ja77smpW2c,3
|
|
|
287
287
|
services/override_requests.py,sha256=vVWR6CQQSU04DkxHLljaNSr6k8f33O8Ysq4J4S2E4-Q,31504
|
|
288
288
|
services/override_wake.py,sha256=HjSOXQTDi0irgeMyrTqngL7xLcSOOIgYsVW9yxod4ps,10363
|
|
289
289
|
services/parser.py,sha256=S_YoKLS3r1xCUVHApXb3BTEfoRAzFhuo1_8XsG0qxVE,63505
|
|
290
|
-
services/project_manager.py,sha256=
|
|
290
|
+
services/project_manager.py,sha256=VxbEsTauIgH4DE3CjxSFArqiCCq9QsKxrOuTOdYTxLY,48991
|
|
291
291
|
services/project_runtime.py,sha256=yyftX48BFjq4B2KcR4KGszDAAa4xR6gn6j0SgTyro1s,11603
|
|
292
292
|
services/protocol.py,sha256=CWZ0BWWd-jPui-11hZlvGgkNk18gMFhhLWbp-BP35Kk,12861
|
|
293
293
|
services/proxy_state.py,sha256=u5rd0k6CrOsywZA8FpRu_hMLwhR0TAJhZjy5MdWbCGc,6107
|
|
@@ -295,7 +295,7 @@ services/read_stamps.py,sha256=CTAy350FJ079-mDBXFZXU5OXhUdPobGnYelkC28W65Q,10654
|
|
|
295
295
|
services/repo_map.py,sha256=o-Z3c7ZqIxRKPyqquGafTngdooe1n-yRIcqpmOz5i2M,23208
|
|
296
296
|
services/repo_shape.py,sha256=QF0mXkY-bnBU8Q8mc5iimw2YBhMgZ4IYhoPc09Z8OBQ,4978
|
|
297
297
|
services/reranker.py,sha256=pnyNSzM7gXQ3ZodjY3rGIRCwpD2OIjookYkAJXb_LVE,4694
|
|
298
|
-
services/retention.py,sha256=
|
|
298
|
+
services/retention.py,sha256=Dw51RKc7Fv0uYbe7GMXj5ReNXtR5MDqpgk00MF_wezc,20569
|
|
299
299
|
services/retrieval.py,sha256=ADESdXRWA66n2-6iLVdGZHIyseqQwcfpnX172iow0n8,2143
|
|
300
300
|
services/retrieval_broker.py,sha256=9X67VZ_6AkbAzopHuuMFKmP4CGZLnW576kjSKMenBnw,5261
|
|
301
301
|
services/router.py,sha256=Cz10nx2fKTbaGn14mSBePWIDrw5rdcs_1JFYXeik084,15626
|
|
@@ -351,8 +351,8 @@ tui/screens/search_view.py,sha256=MMHjVdlk3HZSuDBSvq8IGrqv_Mh5Us6YqXQ80bcWSMk,19
|
|
|
351
351
|
tui/screens/session_view.py,sha256=eZ1eDwHTvPOck1wCCviixtOaCxIkBT_95ytNNNriGNA,5991
|
|
352
352
|
tui/screens/stats.py,sha256=p81PjzdaIv7hllb8f45-rlVe4lJZwSdIMqu7e86_u5s,6223
|
|
353
353
|
tui/screens/ui_view.py,sha256=1QJCgLh2YfgWIpvzRG1KOGXYEaOYX6ojN61Azjf2oX0,2125
|
|
354
|
-
code_context_control-2.158.
|
|
355
|
-
code_context_control-2.158.
|
|
356
|
-
code_context_control-2.158.
|
|
357
|
-
code_context_control-2.158.
|
|
358
|
-
code_context_control-2.158.
|
|
354
|
+
code_context_control-2.158.5.dist-info/METADATA,sha256=ZUMWxBpNfAWcat8V8LehZxH6XJniKT7_3W90AZD8WW0,29355
|
|
355
|
+
code_context_control-2.158.5.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
356
|
+
code_context_control-2.158.5.dist-info/entry_points.txt,sha256=7kX_WUsDCF2hbXzvbNyscyaBb9AeA-DJY5v_5hN0DlU,93
|
|
357
|
+
code_context_control-2.158.5.dist-info/top_level.txt,sha256=wRt41zBybVF3qAiNXHz9BURbkKvUvfhmWWtKMhaw6eE,29
|
|
358
|
+
code_context_control-2.158.5.dist-info/RECORD,,
|
oracle/services/mobile_api.py
CHANGED
|
@@ -474,12 +474,28 @@ def _caller() -> str:
|
|
|
474
474
|
|
|
475
475
|
# ── Path validation ───────────────────────────────────────
|
|
476
476
|
|
|
477
|
-
def
|
|
477
|
+
def _registered_roots() -> list[Path]:
|
|
478
|
+
"""Resolved path of every scanner-registered project with a .c3 dir."""
|
|
479
|
+
if _scanner is None:
|
|
480
|
+
return []
|
|
481
|
+
roots = []
|
|
482
|
+
for proj in _scanner.discover():
|
|
483
|
+
if not proj.get("has_c3"):
|
|
484
|
+
continue
|
|
485
|
+
try:
|
|
486
|
+
roots.append(Path(proj["path"]).resolve())
|
|
487
|
+
except (OSError, ValueError):
|
|
488
|
+
continue
|
|
489
|
+
return roots
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
def _resolve_registered(raw: str, roots: list[Path] | None = None) -> Path | None:
|
|
478
493
|
"""Resolve a request path to a scanner-registered project with a .c3 dir.
|
|
479
494
|
|
|
480
495
|
Case-insensitive on Windows (normcase both sides). Returns None for
|
|
481
496
|
anything unregistered — callers turn that into a 404 without ever
|
|
482
|
-
touching the filesystem at the requested location.
|
|
497
|
+
touching the filesystem at the requested location. ``roots`` is a
|
|
498
|
+
``_registered_roots()`` result to reuse across calls.
|
|
483
499
|
"""
|
|
484
500
|
raw = (raw or "").strip()
|
|
485
501
|
if not raw or _scanner is None:
|
|
@@ -488,19 +504,13 @@ def _resolve_registered(raw: str) -> Path | None:
|
|
|
488
504
|
target = os.path.normcase(str(Path(raw).resolve()))
|
|
489
505
|
except (OSError, ValueError):
|
|
490
506
|
return None
|
|
491
|
-
for
|
|
492
|
-
if
|
|
493
|
-
|
|
494
|
-
try:
|
|
495
|
-
candidate = os.path.normcase(str(Path(proj["path"]).resolve()))
|
|
496
|
-
except (OSError, ValueError):
|
|
497
|
-
continue
|
|
498
|
-
if candidate == target:
|
|
499
|
-
return Path(proj["path"]).resolve()
|
|
507
|
+
for root in (_registered_roots() if roots is None else roots):
|
|
508
|
+
if os.path.normcase(str(root)) == target:
|
|
509
|
+
return root
|
|
500
510
|
return None
|
|
501
511
|
|
|
502
512
|
|
|
503
|
-
def _serving_project(raw: str) -> Path | None:
|
|
513
|
+
def _serving_project(raw: str, roots: list[Path] | None = None) -> Path | None:
|
|
504
514
|
"""The registered project that serves an override row's ``project_path``:
|
|
505
515
|
that project itself, or the deepest registered project containing it.
|
|
506
516
|
|
|
@@ -518,13 +528,7 @@ def _serving_project(raw: str) -> Path | None:
|
|
|
518
528
|
return None
|
|
519
529
|
best: Path | None = None
|
|
520
530
|
best_len = -1
|
|
521
|
-
for
|
|
522
|
-
if not proj.get("has_c3"):
|
|
523
|
-
continue
|
|
524
|
-
try:
|
|
525
|
-
candidate = Path(proj["path"]).resolve()
|
|
526
|
-
except (OSError, ValueError):
|
|
527
|
-
continue
|
|
531
|
+
for candidate in (_registered_roots() if roots is None else roots):
|
|
528
532
|
key = os.path.normcase(str(candidate))
|
|
529
533
|
inside = target == key or target.startswith(key.rstrip("\\/") + os.sep)
|
|
530
534
|
if inside and len(key) > best_len:
|
|
@@ -1022,8 +1026,7 @@ def mobile_jobs():
|
|
|
1022
1026
|
# Cross-project listing must not leak rows for projects this gateway
|
|
1023
1027
|
# does not serve (the store root is shared across every project on
|
|
1024
1028
|
# the machine).
|
|
1025
|
-
rows =
|
|
1026
|
-
if _resolve_registered(str(r.get("project_path") or "")) is not None]
|
|
1029
|
+
rows = _registered_rows(rows)
|
|
1027
1030
|
if status:
|
|
1028
1031
|
rows = [r for r in rows if r.get("status") == status]
|
|
1029
1032
|
rows = rows[:limit]
|
|
@@ -1055,8 +1058,21 @@ def _schedule_row_or_404(schedule_id: str):
|
|
|
1055
1058
|
return row, None
|
|
1056
1059
|
|
|
1057
1060
|
|
|
1058
|
-
def _registered_rows(rows: list) -> list:
|
|
1059
|
-
|
|
1061
|
+
def _registered_rows(rows: list, serving: bool = False) -> list:
|
|
1062
|
+
"""The rows whose ``project_path`` is a registered project, or, with
|
|
1063
|
+
``serving``, lies inside one. Resolves the registered projects once and
|
|
1064
|
+
each distinct row path once, not once per row and project."""
|
|
1065
|
+
roots = _registered_roots()
|
|
1066
|
+
lookup = _serving_project if serving else _resolve_registered
|
|
1067
|
+
keep: dict[str, bool] = {}
|
|
1068
|
+
out = []
|
|
1069
|
+
for r in rows:
|
|
1070
|
+
raw = str(r.get("project_path") or "")
|
|
1071
|
+
if raw not in keep:
|
|
1072
|
+
keep[raw] = lookup(raw, roots) is not None
|
|
1073
|
+
if keep[raw]:
|
|
1074
|
+
out.append(r)
|
|
1075
|
+
return out
|
|
1060
1076
|
|
|
1061
1077
|
|
|
1062
1078
|
def _schedule_call(fn, *args, **kwargs):
|
|
@@ -2484,8 +2500,7 @@ def mobile_overrides_list():
|
|
|
2484
2500
|
# Cross-project listing must not leak rows for projects this gateway
|
|
2485
2501
|
# does not serve — the store is one file across every project on the
|
|
2486
2502
|
# machine, including ones the scanner has since dropped.
|
|
2487
|
-
rows =
|
|
2488
|
-
if _serving_project(str(r.get("project_path") or "")) is not None]
|
|
2503
|
+
rows = _registered_rows(rows, serving=True)
|
|
2489
2504
|
channels = _override_channels(rows)
|
|
2490
2505
|
cards = []
|
|
2491
2506
|
for r in rows:
|
|
@@ -2770,8 +2785,7 @@ def mobile_overrides_costs():
|
|
|
2770
2785
|
# Same rule as /overrides and /jobs: the store is one file for the
|
|
2771
2786
|
# whole machine, and a cross-project view must not name a project
|
|
2772
2787
|
# this token cannot otherwise see.
|
|
2773
|
-
rules =
|
|
2774
|
-
if _serving_project(str(r.get("project_path") or "")) is not None]
|
|
2788
|
+
rules = _registered_rows(rules, serving=True)
|
|
2775
2789
|
return jsonify({"days": days, "rules": rules, "count": len(rules),
|
|
2776
2790
|
"project": project_path})
|
|
2777
2791
|
|
oracle/services/mobile_fleet.py
CHANGED
|
@@ -563,11 +563,10 @@ def mobile_now():
|
|
|
563
563
|
jobs: list[dict] = []
|
|
564
564
|
try:
|
|
565
565
|
from services.shell_jobs import JobStore
|
|
566
|
-
jobs =
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
is not None]
|
|
566
|
+
jobs = m._registered_rows(
|
|
567
|
+
[r for r in JobStore().list_all(project_path=None,
|
|
568
|
+
limit=m._SOURCE_CAP)
|
|
569
|
+
if r.get("status") in ("queued", "running")])
|
|
571
570
|
except Exception:
|
|
572
571
|
jobs = []
|
|
573
572
|
body = fleet_overview.now(_registered(), job_rows=jobs)
|
services/file_memory.py
CHANGED
|
@@ -405,11 +405,18 @@ class FileMemoryStore:
|
|
|
405
405
|
Lists the store directory on every call but reads only records whose
|
|
406
406
|
filename it has not seen before; removed records drop out.
|
|
407
407
|
"""
|
|
408
|
+
return list(self._tracked().values())
|
|
409
|
+
|
|
410
|
+
def _tracked(self) -> dict[str, str]:
|
|
411
|
+
"""Record filename -> stored path for every readable record (a copy).
|
|
412
|
+
|
|
413
|
+
The refresh behind list_tracked(); {} when the store cannot be listed.
|
|
414
|
+
"""
|
|
408
415
|
try:
|
|
409
416
|
names = {e.name for e in os.scandir(self.store_dir)
|
|
410
417
|
if e.name.endswith(".json") and not e.name.startswith("_")}
|
|
411
418
|
except OSError:
|
|
412
|
-
return
|
|
419
|
+
return {}
|
|
413
420
|
with self._tracked_lock:
|
|
414
421
|
known = self._tracked_paths
|
|
415
422
|
for gone in known.keys() - names:
|
|
@@ -422,7 +429,7 @@ class FileMemoryStore:
|
|
|
422
429
|
continue
|
|
423
430
|
if path:
|
|
424
431
|
known[name] = path
|
|
425
|
-
return
|
|
432
|
+
return dict(known)
|
|
426
433
|
|
|
427
434
|
def prune_stale(self) -> list[str]:
|
|
428
435
|
"""Remove records whose source file no longer exists on disk.
|
|
@@ -432,31 +439,39 @@ class FileMemoryStore:
|
|
|
432
439
|
by the retention sweep. Records that fail to parse are left alone
|
|
433
440
|
(unreadable is not the same as stale). Returns the pruned relative
|
|
434
441
|
paths. Never raises.
|
|
442
|
+
|
|
443
|
+
Paths come from the list_tracked() cache, and existence is checked
|
|
444
|
+
with one listing per parent directory instead of a stat per record.
|
|
445
|
+
A name missing from its listing is confirmed with exists() before its
|
|
446
|
+
record is deleted, so a case-insensitive filesystem or an odd path
|
|
447
|
+
costs a stat, never a record.
|
|
435
448
|
"""
|
|
436
449
|
pruned: list[str] = []
|
|
437
450
|
try:
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
data = json.load(fh)
|
|
444
|
-
except Exception:
|
|
445
|
-
continue
|
|
446
|
-
rel = data.get("path", "")
|
|
447
|
-
if not rel:
|
|
448
|
-
continue
|
|
449
|
-
try:
|
|
450
|
-
if (self.project_path / rel).exists():
|
|
451
|
-
continue
|
|
452
|
-
except OSError:
|
|
453
|
-
continue
|
|
451
|
+
by_dir: dict[str, list[tuple[str, str, str]]] = {}
|
|
452
|
+
for name, rel in self._tracked().items():
|
|
453
|
+
parent, _, base = rel.replace("\\", "/").rpartition("/")
|
|
454
|
+
by_dir.setdefault(parent, []).append((name, rel, base))
|
|
455
|
+
for parent, entries in by_dir.items():
|
|
454
456
|
try:
|
|
455
|
-
|
|
457
|
+
with os.scandir(self.project_path / parent) as it:
|
|
458
|
+
present = {e.name for e in it}
|
|
456
459
|
except OSError:
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
+
present = set()
|
|
461
|
+
for name, rel, base in entries:
|
|
462
|
+
if base in present:
|
|
463
|
+
continue
|
|
464
|
+
try:
|
|
465
|
+
if (self.project_path / rel).exists():
|
|
466
|
+
continue
|
|
467
|
+
except OSError:
|
|
468
|
+
continue
|
|
469
|
+
try:
|
|
470
|
+
(self.store_dir / name).unlink()
|
|
471
|
+
except OSError:
|
|
472
|
+
continue
|
|
473
|
+
pruned.append(rel)
|
|
474
|
+
self._map_cache.pop(rel.replace("\\", "/"), None)
|
|
460
475
|
except Exception:
|
|
461
476
|
return pruned
|
|
462
477
|
if pruned:
|
services/ollama_client.py
CHANGED
|
@@ -7,6 +7,8 @@ Includes integrated LLM response cache (formerly llm_cache.py).
|
|
|
7
7
|
"""
|
|
8
8
|
import hashlib
|
|
9
9
|
import json
|
|
10
|
+
import threading
|
|
11
|
+
import time
|
|
10
12
|
import urllib.error
|
|
11
13
|
import urllib.request
|
|
12
14
|
from pathlib import Path
|
|
@@ -56,46 +58,76 @@ class LLMCache:
|
|
|
56
58
|
pass
|
|
57
59
|
|
|
58
60
|
|
|
61
|
+
# Answers from /api/tags, shared by every OllamaClient in the process:
|
|
62
|
+
# base_url -> {"avail": (monotonic ts, bool), "models": (ts, list | None)}.
|
|
63
|
+
# Callers build clients per request and per agent, so a per-instance cache let
|
|
64
|
+
# each of them probe the server again.
|
|
65
|
+
_PROBE_TTL_SECONDS = 30.0
|
|
66
|
+
_probe_cache: dict[str, dict[str, tuple[float, object]]] = {}
|
|
67
|
+
_probe_lock = threading.Lock()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def clear_probe_cache() -> None:
|
|
71
|
+
"""Forget every cached availability and model-list answer."""
|
|
72
|
+
with _probe_lock:
|
|
73
|
+
_probe_cache.clear()
|
|
74
|
+
|
|
75
|
+
|
|
59
76
|
class OllamaClient:
|
|
60
77
|
"""Minimal Ollama REST client using urllib."""
|
|
61
78
|
|
|
62
|
-
_AVAIL_TTL_SECONDS = 10.0
|
|
63
|
-
|
|
64
79
|
def __init__(self, base_url: str = DEFAULT_BASE_URL, cache_dir: str = ".c3/cache/llm"):
|
|
65
80
|
self.base_url = base_url.rstrip("/")
|
|
66
81
|
self.cache = LLMCache(cache_dir)
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
|
|
83
|
+
def _cached(self, key: str):
|
|
84
|
+
with _probe_lock:
|
|
85
|
+
hit = _probe_cache.get(self.base_url, {}).get(key)
|
|
86
|
+
if hit is not None and time.monotonic() - hit[0] < _PROBE_TTL_SECONDS:
|
|
87
|
+
return hit
|
|
88
|
+
return None
|
|
89
|
+
|
|
90
|
+
def _remember(self, key: str, value) -> None:
|
|
91
|
+
with _probe_lock:
|
|
92
|
+
_probe_cache.setdefault(self.base_url, {})[key] = (time.monotonic(), value)
|
|
69
93
|
|
|
70
94
|
# ── Availability ──────────────────────────────────────
|
|
71
95
|
|
|
72
96
|
def is_available(self, timeout: int | None = None) -> bool:
|
|
73
|
-
"""Check if Ollama is reachable.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return self._avail_value
|
|
97
|
+
"""Check if Ollama is reachable. The answer is shared process-wide for
|
|
98
|
+
``_PROBE_TTL_SECONDS``."""
|
|
99
|
+
hit = self._cached("avail")
|
|
100
|
+
if hit is not None:
|
|
101
|
+
return hit[1]
|
|
79
102
|
try:
|
|
80
103
|
req = urllib.request.Request(f"{self.base_url}/api/tags")
|
|
81
104
|
with urllib.request.urlopen(req, timeout=timeout or _TIMEOUT):
|
|
82
|
-
|
|
105
|
+
available = True
|
|
83
106
|
except Exception:
|
|
84
|
-
|
|
85
|
-
self.
|
|
86
|
-
return
|
|
107
|
+
available = False
|
|
108
|
+
self._remember("avail", available)
|
|
109
|
+
return available
|
|
87
110
|
|
|
88
111
|
# ── Models ────────────────────────────────────────────
|
|
89
112
|
|
|
90
113
|
def list_models(self) -> list[str] | None:
|
|
91
|
-
"""Return list of locally available model names, or None on failure.
|
|
114
|
+
"""Return list of locally available model names, or None on failure.
|
|
115
|
+
The answer is shared process-wide for ``_PROBE_TTL_SECONDS``."""
|
|
116
|
+
hit = self._cached("models")
|
|
117
|
+
if hit is not None:
|
|
118
|
+
return list(hit[1]) if hit[1] is not None else None
|
|
92
119
|
try:
|
|
93
120
|
req = urllib.request.Request(f"{self.base_url}/api/tags")
|
|
94
121
|
with urllib.request.urlopen(req, timeout=_TIMEOUT) as resp:
|
|
95
122
|
data = json.loads(resp.read())
|
|
96
|
-
|
|
123
|
+
models = [m["name"] for m in data.get("models", [])]
|
|
97
124
|
except Exception:
|
|
98
|
-
|
|
125
|
+
models = None
|
|
126
|
+
self._remember("models", models)
|
|
127
|
+
if models is not None:
|
|
128
|
+
self._remember("avail", True)
|
|
129
|
+
return list(models)
|
|
130
|
+
return None
|
|
99
131
|
|
|
100
132
|
def has_model(self, model: str) -> bool:
|
|
101
133
|
"""Check if a specific model is pulled locally."""
|
services/project_manager.py
CHANGED
|
@@ -101,7 +101,7 @@ class ProjectManager:
|
|
|
101
101
|
def _verify_c3_session(self, port: int) -> bool:
|
|
102
102
|
"""Verify that a given port is actually a C3 session UI."""
|
|
103
103
|
try:
|
|
104
|
-
url = f"http://127.0.0.1:{port}/api/health"
|
|
104
|
+
url = f"http://127.0.0.1:{port}/api/health?probe=1"
|
|
105
105
|
# 2 s, not 0.8: a server re-indexing after a burst of file changes
|
|
106
106
|
# answers late, and a late answer must not read as "not C3".
|
|
107
107
|
with urllib.request.urlopen(url, timeout=2.0) as r:
|
services/retention.py
CHANGED
|
@@ -329,6 +329,46 @@ def cap_session_files(sessions_dir, max_files: int = 50,
|
|
|
329
329
|
return pruned
|
|
330
330
|
|
|
331
331
|
|
|
332
|
+
def _try_lock(path: Path):
|
|
333
|
+
"""Take a non-blocking exclusive lock on ``path``; the open handle, or None.
|
|
334
|
+
|
|
335
|
+
The OS drops the lock when the holder dies, so a crashed sweep never
|
|
336
|
+
strands it.
|
|
337
|
+
"""
|
|
338
|
+
try:
|
|
339
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
340
|
+
fh = open(path, "ab")
|
|
341
|
+
except OSError:
|
|
342
|
+
return None
|
|
343
|
+
try:
|
|
344
|
+
if os.name == "nt":
|
|
345
|
+
import msvcrt
|
|
346
|
+
fh.seek(0)
|
|
347
|
+
msvcrt.locking(fh.fileno(), msvcrt.LK_NBLCK, 1)
|
|
348
|
+
else:
|
|
349
|
+
import fcntl
|
|
350
|
+
fcntl.flock(fh.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
351
|
+
except OSError:
|
|
352
|
+
fh.close()
|
|
353
|
+
return None
|
|
354
|
+
return fh
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def _unlock(fh) -> None:
|
|
358
|
+
try:
|
|
359
|
+
if os.name == "nt":
|
|
360
|
+
import msvcrt
|
|
361
|
+
fh.seek(0)
|
|
362
|
+
msvcrt.locking(fh.fileno(), msvcrt.LK_UNLCK, 1)
|
|
363
|
+
else:
|
|
364
|
+
import fcntl
|
|
365
|
+
fcntl.flock(fh.fileno(), fcntl.LOCK_UN)
|
|
366
|
+
except OSError:
|
|
367
|
+
pass
|
|
368
|
+
finally:
|
|
369
|
+
fh.close()
|
|
370
|
+
|
|
371
|
+
|
|
332
372
|
class RetentionManager:
|
|
333
373
|
"""Rate-limited retention sweep for a project's ``.c3`` directory.
|
|
334
374
|
|
|
@@ -341,6 +381,11 @@ class RetentionManager:
|
|
|
341
381
|
happens at write time in their own modules; this sweep owns the
|
|
342
382
|
structure-aware rotations (edit ledger, notifications), the session
|
|
343
383
|
cap, file-memory pruning, and archive TTL purging.
|
|
384
|
+
|
|
385
|
+
Every C3 process on a project (each MCP server and the UI server) owns
|
|
386
|
+
one of these, so ``maybe_run`` sweeps only when no process has swept
|
|
387
|
+
within the interval: ``.c3/retention.lock`` keeps two sweeps from
|
|
388
|
+
overlapping and the mtime of ``.c3/retention.last`` records the last one.
|
|
344
389
|
"""
|
|
345
390
|
|
|
346
391
|
def __init__(self, project_path, edit_ledger=None, notifications=None,
|
|
@@ -367,7 +412,27 @@ class RetentionManager:
|
|
|
367
412
|
self._next_run = now + interval
|
|
368
413
|
if not cfg.get("enabled", True):
|
|
369
414
|
return None
|
|
370
|
-
|
|
415
|
+
c3_dir = self.project_path / ".c3"
|
|
416
|
+
lock = _try_lock(c3_dir / "retention.lock")
|
|
417
|
+
if lock is None:
|
|
418
|
+
return None
|
|
419
|
+
try:
|
|
420
|
+
stamp = c3_dir / "retention.last"
|
|
421
|
+
try:
|
|
422
|
+
age = time.time() - stamp.stat().st_mtime
|
|
423
|
+
except OSError:
|
|
424
|
+
age = None
|
|
425
|
+
if age is not None and 0 <= age < interval:
|
|
426
|
+
self._next_run = now + (interval - age)
|
|
427
|
+
return None
|
|
428
|
+
summary = self.run_sweep(cfg)
|
|
429
|
+
try:
|
|
430
|
+
stamp.touch()
|
|
431
|
+
except OSError:
|
|
432
|
+
pass
|
|
433
|
+
return summary
|
|
434
|
+
finally:
|
|
435
|
+
_unlock(lock)
|
|
371
436
|
|
|
372
437
|
def run_sweep(self, cfg: Optional[dict] = None) -> dict:
|
|
373
438
|
"""Execute one full retention sweep. Never raises."""
|
|
File without changes
|
{code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{code_context_control-2.158.4.dist-info → code_context_control-2.158.5.dist-info}/top_level.txt
RENAMED
|
File without changes
|