code-context-control 2.158.1__py3-none-any.whl → 2.158.3__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/hub_server.py +4 -19
- cli/mcp_server.py +5 -1
- {code_context_control-2.158.1.dist-info → code_context_control-2.158.3.dist-info}/METADATA +1 -1
- {code_context_control-2.158.1.dist-info → code_context_control-2.158.3.dist-info}/RECORD +12 -12
- oracle/services/mobile_api.py +37 -5
- services/notifications.py +119 -18
- services/override_requests.py +5 -0
- {code_context_control-2.158.1.dist-info → code_context_control-2.158.3.dist-info}/WHEEL +0 -0
- {code_context_control-2.158.1.dist-info → code_context_control-2.158.3.dist-info}/entry_points.txt +0 -0
- {code_context_control-2.158.1.dist-info → code_context_control-2.158.3.dist-info}/licenses/LICENSE +0 -0
- {code_context_control-2.158.1.dist-info → code_context_control-2.158.3.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.3"
|
|
95
95
|
|
|
96
96
|
# The PreToolUse matcher for native subagent calls (installer and hub migration).
|
|
97
97
|
AGENT_MATCHER = "Agent|Task"
|
cli/hub_server.py
CHANGED
|
@@ -1072,25 +1072,10 @@ def api_project_notifications_clear():
|
|
|
1072
1072
|
if not nf.exists():
|
|
1073
1073
|
return jsonify({"cleared": 0})
|
|
1074
1074
|
try:
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
try:
|
|
1080
|
-
entries.append(json.loads(line))
|
|
1081
|
-
except json.JSONDecodeError:
|
|
1082
|
-
continue
|
|
1083
|
-
count = 0
|
|
1084
|
-
for e in entries:
|
|
1085
|
-
if not e.get("acknowledged"):
|
|
1086
|
-
e["acknowledged"] = True
|
|
1087
|
-
count += 1
|
|
1088
|
-
if count:
|
|
1089
|
-
nf.write_text(
|
|
1090
|
-
"\n".join(json.dumps(e, ensure_ascii=False) for e in entries) + "\n",
|
|
1091
|
-
encoding="utf-8",
|
|
1092
|
-
)
|
|
1093
|
-
return jsonify({"cleared": count})
|
|
1075
|
+
# Through the store: its rewrite holds the cross-process lock, so a
|
|
1076
|
+
# notification another process appends meanwhile is kept.
|
|
1077
|
+
from services.notifications import NotificationStore
|
|
1078
|
+
return jsonify({"cleared": NotificationStore(path).acknowledge_all()})
|
|
1094
1079
|
except Exception as e:
|
|
1095
1080
|
return jsonify({"error": str(e)}), 500
|
|
1096
1081
|
|
cli/mcp_server.py
CHANGED
|
@@ -1277,6 +1277,8 @@ async def c3_bitbucket(
|
|
|
1277
1277
|
pr_id: int = 0,
|
|
1278
1278
|
branch: str = "",
|
|
1279
1279
|
state: str = "OPEN",
|
|
1280
|
+
author: str = "",
|
|
1281
|
+
reviewer: str = "",
|
|
1280
1282
|
title: str = "",
|
|
1281
1283
|
body: str = "",
|
|
1282
1284
|
from_branch: str = "",
|
|
@@ -1304,7 +1306,8 @@ async def c3_bitbucket(
|
|
|
1304
1306
|
default branch, browse and clone URLs),
|
|
1305
1307
|
readme ([at=branch/commit] — the root README, markdown preferred),
|
|
1306
1308
|
get_file (path [at] — one text file, 256 KB cap, binary refused),
|
|
1307
|
-
list_prs
|
|
1309
|
+
list_prs ([author] [reviewer] — Bitbucket user names), get_pr,
|
|
1310
|
+
get_pr_diff, get_pr_activities, get_pr_commits,
|
|
1308
1311
|
pr_issues (pr_id — Jira issues Bitbucket's Jira integration links to the PR),
|
|
1309
1312
|
create_pr, update_pr (pr_id + any of title/description/reviewers/to_branch —
|
|
1310
1313
|
unchanged fields are preserved; reviewers is the FULL comma-separated
|
|
@@ -1335,6 +1338,7 @@ async def c3_bitbucket(
|
|
|
1335
1338
|
return await asyncio.to_thread(
|
|
1336
1339
|
handle_bitbucket, action, svc, finalize,
|
|
1337
1340
|
project=project, repo=repo, pr_id=pr_id, branch=branch, state=state,
|
|
1341
|
+
author=author, reviewer=reviewer,
|
|
1338
1342
|
title=title, body=body, from_branch=from_branch, to_branch=to_branch,
|
|
1339
1343
|
description=description, reviewers=reviewers, name=name, url=url,
|
|
1340
1344
|
events=events, start_point=start_point, commit=commit,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code-context-control
|
|
3
|
-
Version: 2.158.
|
|
3
|
+
Version: 2.158.3
|
|
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=1U8-jQ4LjeHnMzAJDDOQkleXM2aTIgMkf1Tff07N4CE,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
|
|
@@ -23,10 +23,10 @@ cli/hook_session_end.py,sha256=toFEPDKRoutDuVOmuOgHmQ8CM0o7tF7yALhMxJz7VEM,3482
|
|
|
23
23
|
cli/hook_session_open.py,sha256=VXStM1vsA2kwLZxczAvetJGf4aDT1dPlWYMeEW4ow4Y,11387
|
|
24
24
|
cli/hook_session_stats.py,sha256=I-2NeLlV1NxeqKtTM2JH9haSpFU7r4qG0u8pfCJ80YU,8725
|
|
25
25
|
cli/hook_terse_advisor.py,sha256=W_zaTfX2akgX-ifuUTsLu2H1atM8XmWt6jpPoeU7Pm0,6252
|
|
26
|
-
cli/hub_server.py,sha256=
|
|
26
|
+
cli/hub_server.py,sha256=CnpI0kqpVX-rJkPnGiVyuej8Ay0VHzBLWc-ZxDhEVZA,226168
|
|
27
27
|
cli/hub_ui.html,sha256=v41R_JAH4Jwodpy3tbeBUel-80FbNmffBrey-QH5Q64,2963
|
|
28
28
|
cli/mcp_proxy.py,sha256=r-Qhlie7gCtotex8yQUudCyBLRUK-IW6cNIW5RhBW0o,17648
|
|
29
|
-
cli/mcp_server.py,sha256=
|
|
29
|
+
cli/mcp_server.py,sha256=Gg1Chz3j7Lu5ZuU3JFMACNZHWp7KphM_2E8eoNHpp3M,84132
|
|
30
30
|
cli/progress.py,sha256=qTkNy0howOD3hXraMo4ok3dYTpBW5yG_tenKfF4UDM0,1470
|
|
31
31
|
cli/server.py,sha256=SQFONagf4Mmsv2Z0fdnr8cxAFUsBE3nPQ5XUZLgtjI8,174039
|
|
32
32
|
cli/ui.html,sha256=uuPwIJNKDQH_fsaR3xNB2AKky9WzKfaXnKr_k3aTtxo,5715
|
|
@@ -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.3.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
|
|
@@ -167,7 +167,7 @@ oracle/services/insight_engine.py,sha256=lwcdXtjt3CSZLqHVpXx6SG5gDhZYUKwXt4Z8dGy
|
|
|
167
167
|
oracle/services/local_session.py,sha256=nkawOjDbotUp5wtZQnC1wPDw3HopNYMkoYqWpP5ToCU,9227
|
|
168
168
|
oracle/services/memory_reader.py,sha256=rSEmoIXQu2JkolHJIQWpn0piPJpyuf1KZvW_9liQwkU,3727
|
|
169
169
|
oracle/services/memory_writer.py,sha256=hpvYsxjhl293jEjGcRKfjG5njUaAOXKqbmJaUu1WdUU,6997
|
|
170
|
-
oracle/services/mobile_api.py,sha256=
|
|
170
|
+
oracle/services/mobile_api.py,sha256=AmP0VBO0914EYCie1ETPhAbsaeQ1hbJqoYRyzgbA5bM,149397
|
|
171
171
|
oracle/services/mobile_fleet.py,sha256=lhbmHlrGyLrp3SVqoVj0FsJWOUXHZmVMUsy4WsvHbPs,24045
|
|
172
172
|
oracle/services/project_scanner.py,sha256=PkYJtwOLRME1EzwRy3GIkYk6Xw0u1_BzFcaMJ5gJ1_s,6118
|
|
173
173
|
oracle/services/review_agent.py,sha256=m_fzoHowpiibf0_iz3dF72LWSrwB_FbDd1am-SbeWXg,11273
|
|
@@ -274,7 +274,7 @@ services/memory_grounder.py,sha256=vM7_n_Ezkkc3oGQ1MECUT9Bpt2K1fsNx2kWiumAW6Qc,1
|
|
|
274
274
|
services/memory_queue.py,sha256=sSFh2oU_BLbv90jXhPbRWNIS2nlUi468-INw96GFIwU,3852
|
|
275
275
|
services/memory_scorer.py,sha256=32wccyVFBgcNwKdjwj_7RDnPukxSWBng8ohsRPTpQMM,9497
|
|
276
276
|
services/metrics.py,sha256=X4D5TgcQSFaFLbBoa1s3bAWf00DMMjq3IrOACrK-uDg,3289
|
|
277
|
-
services/notifications.py,sha256=
|
|
277
|
+
services/notifications.py,sha256=9yy7Qkhe0-SjuxXDI8jxuee_a_f6S8s7uAB9BtcAa34,21426
|
|
278
278
|
services/ollama_bridge.py,sha256=16ukWS98H4wFulOphUJDuXhN61GCiay793XLoyxTU-s,17455
|
|
279
279
|
services/ollama_client.py,sha256=UiC5Abca622-ac-4goCkAjwo7iUye9g9JGFMN6Ea08M,7983
|
|
280
280
|
services/ollama_credentials.py,sha256=EQx0YljYRrRBJ2voALlVTv11UBjfw-A6N7k7EP7fUFE,2770
|
|
@@ -283,7 +283,7 @@ services/output_filter.py,sha256=lknQHs38JlRtXU4Ogoru6sveNokSKBQPfZXhf-fE0xM,217
|
|
|
283
283
|
services/override_costs.py,sha256=qpCzDo8eNSYvy5TP3WJETnub2tsc64gukYImLHFeI78,7905
|
|
284
284
|
services/override_grants.py,sha256=BQVwD6WCxVORsUaqDWNToIalz2mStnJRMIR-SOxQzuQ,31189
|
|
285
285
|
services/override_policy.py,sha256=TehVPxfQ8LZWIOUzCnnioIdMUPZZ7JZa1ja77smpW2c,34169
|
|
286
|
-
services/override_requests.py,sha256=
|
|
286
|
+
services/override_requests.py,sha256=vVWR6CQQSU04DkxHLljaNSr6k8f33O8Ysq4J4S2E4-Q,31504
|
|
287
287
|
services/override_wake.py,sha256=HjSOXQTDi0irgeMyrTqngL7xLcSOOIgYsVW9yxod4ps,10363
|
|
288
288
|
services/parser.py,sha256=S_YoKLS3r1xCUVHApXb3BTEfoRAzFhuo1_8XsG0qxVE,63505
|
|
289
289
|
services/project_manager.py,sha256=dfA8jUjaEBQfX6JMVBy3iwXygb2gtPaI0sv_6QxLRFY,48983
|
|
@@ -350,8 +350,8 @@ tui/screens/search_view.py,sha256=MMHjVdlk3HZSuDBSvq8IGrqv_Mh5Us6YqXQ80bcWSMk,19
|
|
|
350
350
|
tui/screens/session_view.py,sha256=eZ1eDwHTvPOck1wCCviixtOaCxIkBT_95ytNNNriGNA,5991
|
|
351
351
|
tui/screens/stats.py,sha256=p81PjzdaIv7hllb8f45-rlVe4lJZwSdIMqu7e86_u5s,6223
|
|
352
352
|
tui/screens/ui_view.py,sha256=1QJCgLh2YfgWIpvzRG1KOGXYEaOYX6ojN61Azjf2oX0,2125
|
|
353
|
-
code_context_control-2.158.
|
|
354
|
-
code_context_control-2.158.
|
|
355
|
-
code_context_control-2.158.
|
|
356
|
-
code_context_control-2.158.
|
|
357
|
-
code_context_control-2.158.
|
|
353
|
+
code_context_control-2.158.3.dist-info/METADATA,sha256=mbeDL5dANAqMjLr2gHjYl42TNJsnpeN722R9-CjJOeE,29355
|
|
354
|
+
code_context_control-2.158.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
355
|
+
code_context_control-2.158.3.dist-info/entry_points.txt,sha256=7kX_WUsDCF2hbXzvbNyscyaBb9AeA-DJY5v_5hN0DlU,93
|
|
356
|
+
code_context_control-2.158.3.dist-info/top_level.txt,sha256=wRt41zBybVF3qAiNXHz9BURbkKvUvfhmWWtKMhaw6eE,29
|
|
357
|
+
code_context_control-2.158.3.dist-info/RECORD,,
|
oracle/services/mobile_api.py
CHANGED
|
@@ -500,6 +500,38 @@ def _resolve_registered(raw: str) -> Path | None:
|
|
|
500
500
|
return None
|
|
501
501
|
|
|
502
502
|
|
|
503
|
+
def _serving_project(raw: str) -> Path | None:
|
|
504
|
+
"""The registered project that serves an override row's ``project_path``:
|
|
505
|
+
that project itself, or the deepest registered project containing it.
|
|
506
|
+
|
|
507
|
+
A session in a worktree nested inside a registered project (Claude Code's
|
|
508
|
+
``.claude/worktrees/<name>``) files its requests under the worktree path,
|
|
509
|
+
which is never registered itself. Refusing those rows left the desk and
|
|
510
|
+
the phone unable to show or answer a hold the agent was blocked on.
|
|
511
|
+
"""
|
|
512
|
+
raw = (raw or "").strip()
|
|
513
|
+
if not raw or _scanner is None:
|
|
514
|
+
return None
|
|
515
|
+
try:
|
|
516
|
+
target = os.path.normcase(str(Path(raw).resolve()))
|
|
517
|
+
except (OSError, ValueError):
|
|
518
|
+
return None
|
|
519
|
+
best: Path | None = None
|
|
520
|
+
best_len = -1
|
|
521
|
+
for proj in _scanner.discover():
|
|
522
|
+
if not proj.get("has_c3"):
|
|
523
|
+
continue
|
|
524
|
+
try:
|
|
525
|
+
candidate = Path(proj["path"]).resolve()
|
|
526
|
+
except (OSError, ValueError):
|
|
527
|
+
continue
|
|
528
|
+
key = os.path.normcase(str(candidate))
|
|
529
|
+
inside = target == key or target.startswith(key.rstrip("\\/") + os.sep)
|
|
530
|
+
if inside and len(key) > best_len:
|
|
531
|
+
best, best_len = candidate, len(key)
|
|
532
|
+
return best
|
|
533
|
+
|
|
534
|
+
|
|
503
535
|
def _project_or_404(raw: str):
|
|
504
536
|
"""Returns (Path, None) or (None, error_response)."""
|
|
505
537
|
if not (raw or "").strip():
|
|
@@ -2453,7 +2485,7 @@ def mobile_overrides_list():
|
|
|
2453
2485
|
# does not serve — the store is one file across every project on the
|
|
2454
2486
|
# machine, including ones the scanner has since dropped.
|
|
2455
2487
|
rows = [r for r in rows
|
|
2456
|
-
if
|
|
2488
|
+
if _serving_project(str(r.get("project_path") or "")) is not None]
|
|
2457
2489
|
channels = _override_channels(rows)
|
|
2458
2490
|
cards = []
|
|
2459
2491
|
for r in rows:
|
|
@@ -2739,7 +2771,7 @@ def mobile_overrides_costs():
|
|
|
2739
2771
|
# whole machine, and a cross-project view must not name a project
|
|
2740
2772
|
# this token cannot otherwise see.
|
|
2741
2773
|
rules = [r for r in rules
|
|
2742
|
-
if
|
|
2774
|
+
if _serving_project(str(r.get("project_path") or "")) is not None]
|
|
2743
2775
|
return jsonify({"days": days, "rules": rules, "count": len(rules),
|
|
2744
2776
|
"project": project_path})
|
|
2745
2777
|
|
|
@@ -2754,7 +2786,7 @@ def mobile_override_get(request_id):
|
|
|
2754
2786
|
row = orq.get(str(request_id))
|
|
2755
2787
|
if row is None:
|
|
2756
2788
|
return jsonify({"error": "unknown request"}), 404
|
|
2757
|
-
if
|
|
2789
|
+
if _serving_project(str(row.get("project_path") or "")) is None:
|
|
2758
2790
|
# Same refusal as an unknown id: whether a request exists for a project
|
|
2759
2791
|
# this gateway does not serve is not this token's business.
|
|
2760
2792
|
return jsonify({"error": "unknown request"}), 404
|
|
@@ -2823,7 +2855,7 @@ def mobile_override_decide(request_id):
|
|
|
2823
2855
|
f"{', '.join(orq.MODES)}"}), 400
|
|
2824
2856
|
|
|
2825
2857
|
row = orq.get(str(request_id))
|
|
2826
|
-
if row is None or
|
|
2858
|
+
if row is None or _serving_project(str(row.get("project_path") or "")) is None:
|
|
2827
2859
|
return jsonify({"error": "unknown request"}), 404
|
|
2828
2860
|
if row.get("status") != orq.STATUS_PENDING:
|
|
2829
2861
|
# §12.7: it lapsed while the phone was showing it. 409, and the card
|
|
@@ -2961,7 +2993,7 @@ def mobile_override_mute(request_id):
|
|
|
2961
2993
|
from services import override_requests as orq
|
|
2962
2994
|
data = request.get_json(silent=True) or {}
|
|
2963
2995
|
row = orq.get(str(request_id))
|
|
2964
|
-
if row is None or
|
|
2996
|
+
if row is None or _serving_project(str(row.get("project_path") or "")) is None:
|
|
2965
2997
|
return jsonify({"error": "unknown request"}), 404
|
|
2966
2998
|
if row.get("status") != orq.STATUS_PENDING:
|
|
2967
2999
|
return jsonify({"error": f"request is {row.get('status')}, not pending",
|
services/notifications.py
CHANGED
|
@@ -2,20 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
Persists to .c3/notifications.jsonl. Supports dedup, severity filtering,
|
|
4
4
|
and auto-acknowledgement when surfaced to Claude via tool responses.
|
|
5
|
+
|
|
6
|
+
Several processes write one project's file at once: every MCP server (the
|
|
7
|
+
auto-ack on each tool response), hook subprocesses (session open and end, the
|
|
8
|
+
override request filed at a confirm denial), the Oracle (the phone's and the
|
|
9
|
+
desk's acks) and the job supervisor. So every method that can rewrite the
|
|
10
|
+
file holds a cross-process lock, and a rewrite is published by atomic
|
|
11
|
+
replace; otherwise a line appended between another writer's read and its
|
|
12
|
+
rewrite is lost.
|
|
5
13
|
"""
|
|
6
14
|
import hashlib
|
|
7
15
|
import json
|
|
16
|
+
import os
|
|
8
17
|
import threading
|
|
18
|
+
import time
|
|
9
19
|
import uuid
|
|
20
|
+
from contextlib import contextmanager
|
|
10
21
|
from datetime import datetime, timedelta, timezone
|
|
11
22
|
from pathlib import Path
|
|
12
23
|
|
|
24
|
+
from services.atomic_json import write_text_atomic
|
|
25
|
+
|
|
13
26
|
# How long to suppress a repeated agent+title after it has been acknowledged.
|
|
14
27
|
_COOLDOWN_MINUTES = {"critical": 5, "warning": 30, "info": 60}
|
|
15
28
|
|
|
16
29
|
# Duplicate collapse: keep the most severe label when merging records.
|
|
17
30
|
_SEVERITY_RANK = {"info": 0, "warning": 1, "critical": 2}
|
|
18
31
|
|
|
32
|
+
# How long a writer waits for another process's rewrite. Past it the write
|
|
33
|
+
# goes ahead unlocked rather than being dropped.
|
|
34
|
+
_LOCK_TIMEOUT_S = 5.0
|
|
35
|
+
_LOCK_POLL_S = 0.01
|
|
36
|
+
|
|
19
37
|
# Event kinds written by C3's own producers (v2.126.0). A client ROUTES on
|
|
20
38
|
# ``kind`` + ``ref_id`` rather than parsing the title; every kind here also
|
|
21
39
|
# lands in .c3/notifications.jsonl, which is one of the files the mobile
|
|
@@ -63,18 +81,84 @@ def _entry_count(entry: dict) -> int:
|
|
|
63
81
|
return 1
|
|
64
82
|
|
|
65
83
|
|
|
84
|
+
class _FileLock:
|
|
85
|
+
"""Advisory cross-process lock on a sidecar file, released by the OS if
|
|
86
|
+
the holder dies. The shape of ``services.task_store._FileLock``, except
|
|
87
|
+
that ``acquire`` gives up quietly: it returns False on timeout instead of
|
|
88
|
+
raising, and the caller carries on without the lock."""
|
|
89
|
+
|
|
90
|
+
def __init__(self, path: Path):
|
|
91
|
+
self.path = path
|
|
92
|
+
self._fh = None
|
|
93
|
+
|
|
94
|
+
def acquire(self, timeout_s: float = _LOCK_TIMEOUT_S) -> bool:
|
|
95
|
+
try:
|
|
96
|
+
fh = open(self.path, "ab") # never read/written; fd exists to hold the lock
|
|
97
|
+
except OSError:
|
|
98
|
+
return False
|
|
99
|
+
deadline = time.monotonic() + timeout_s
|
|
100
|
+
while True:
|
|
101
|
+
try:
|
|
102
|
+
if os.name == "nt":
|
|
103
|
+
import msvcrt
|
|
104
|
+
fh.seek(0)
|
|
105
|
+
msvcrt.locking(fh.fileno(), msvcrt.LK_NBLCK, 1)
|
|
106
|
+
else:
|
|
107
|
+
import fcntl
|
|
108
|
+
fcntl.flock(fh.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
|
|
109
|
+
self._fh = fh
|
|
110
|
+
return True
|
|
111
|
+
except OSError:
|
|
112
|
+
if time.monotonic() >= deadline:
|
|
113
|
+
fh.close()
|
|
114
|
+
return False
|
|
115
|
+
time.sleep(_LOCK_POLL_S)
|
|
116
|
+
|
|
117
|
+
def release(self) -> None:
|
|
118
|
+
fh, self._fh = self._fh, None
|
|
119
|
+
if fh is None:
|
|
120
|
+
return
|
|
121
|
+
try:
|
|
122
|
+
if os.name == "nt":
|
|
123
|
+
import msvcrt
|
|
124
|
+
fh.seek(0)
|
|
125
|
+
msvcrt.locking(fh.fileno(), msvcrt.LK_UNLCK, 1)
|
|
126
|
+
else:
|
|
127
|
+
import fcntl
|
|
128
|
+
fcntl.flock(fh.fileno(), fcntl.LOCK_UN)
|
|
129
|
+
except OSError:
|
|
130
|
+
pass
|
|
131
|
+
finally:
|
|
132
|
+
fh.close()
|
|
133
|
+
|
|
134
|
+
|
|
66
135
|
class NotificationStore:
|
|
67
136
|
"""Thread-safe JSONL notification store for background agents."""
|
|
68
137
|
|
|
69
138
|
def __init__(self, project_path: str):
|
|
70
139
|
self._file = Path(project_path) / ".c3" / "notifications.jsonl"
|
|
71
140
|
self._file.parent.mkdir(parents=True, exist_ok=True)
|
|
141
|
+
self._lock_file = self._file.with_name(self._file.name + ".lock")
|
|
72
142
|
self._lock = threading.Lock()
|
|
73
143
|
# Retro-cleanup runs at most once per store instance, lazily on first
|
|
74
144
|
# access, so pre-existing duplicate backlogs self-heal without a
|
|
75
145
|
# dedicated maintenance pass.
|
|
76
146
|
self._collapsed = False
|
|
77
147
|
|
|
148
|
+
@contextmanager
|
|
149
|
+
def _locked(self):
|
|
150
|
+
"""This instance's thread lock plus the cross-process file lock. Every
|
|
151
|
+
method that can rewrite the file runs under both; instances are made
|
|
152
|
+
per call all over C3, so the thread lock alone never covered two
|
|
153
|
+
threads, let alone two processes."""
|
|
154
|
+
with self._lock:
|
|
155
|
+
file_lock = _FileLock(self._lock_file)
|
|
156
|
+
file_lock.acquire()
|
|
157
|
+
try:
|
|
158
|
+
yield
|
|
159
|
+
finally:
|
|
160
|
+
file_lock.release()
|
|
161
|
+
|
|
78
162
|
def add(self, agent: str, severity: str, title: str, message: str,
|
|
79
163
|
ai_enhanced: bool = False, replace_if_unacked: bool = False,
|
|
80
164
|
kind: str = "", ref_id: str = "") -> dict | None:
|
|
@@ -95,9 +179,12 @@ class NotificationStore:
|
|
|
95
179
|
ref_id: the id of the thing the notification is ABOUT (e.g. the
|
|
96
180
|
override request), which is not the notification's own ``id``.
|
|
97
181
|
A client needs both: ``id`` to acknowledge, ``ref_id`` to navigate.
|
|
182
|
+
It is also part of the dedup identity: an entry with a ref_id
|
|
183
|
+
only collapses into, or is suppressed by, an entry with the same
|
|
184
|
+
ref_id (unless ``replace_if_unacked``).
|
|
98
185
|
Returns the entry if written/updated, None if deduped.
|
|
99
186
|
"""
|
|
100
|
-
with self.
|
|
187
|
+
with self._locked():
|
|
101
188
|
self._maybe_collapse_locked()
|
|
102
189
|
message_hash = hashlib.md5((message or "").encode("utf-8")).hexdigest()[:12]
|
|
103
190
|
cooldown = timedelta(minutes=_COOLDOWN_MINUTES.get(severity, 30))
|
|
@@ -106,6 +193,12 @@ class NotificationStore:
|
|
|
106
193
|
for existing in entries:
|
|
107
194
|
if existing.get("agent") != agent or existing.get("title") != title:
|
|
108
195
|
continue
|
|
196
|
+
# A second request on the same file is a new event, not a
|
|
197
|
+
# repeat: clients learn of requests only from this line.
|
|
198
|
+
# `replace_if_unacked` keeps title scope by request.
|
|
199
|
+
if (ref_id and not replace_if_unacked
|
|
200
|
+
and (existing.get("ref_id") or "") != ref_id):
|
|
201
|
+
continue
|
|
109
202
|
if not existing.get("acknowledged"):
|
|
110
203
|
if replace_if_unacked:
|
|
111
204
|
# Update in-place — prevents repeated pile-up for chatty agents
|
|
@@ -168,7 +261,7 @@ class NotificationStore:
|
|
|
168
261
|
|
|
169
262
|
def get_pending_count(self) -> int:
|
|
170
263
|
"""Return count of unacknowledged warning/critical notifications without consuming them."""
|
|
171
|
-
with self.
|
|
264
|
+
with self._locked():
|
|
172
265
|
self._maybe_collapse_locked()
|
|
173
266
|
return sum(
|
|
174
267
|
1 for e in self._read_all()
|
|
@@ -190,7 +283,7 @@ class NotificationStore:
|
|
|
190
283
|
"""
|
|
191
284
|
if severities is None:
|
|
192
285
|
severities = self._ACTIONABLE
|
|
193
|
-
with self.
|
|
286
|
+
with self._locked():
|
|
194
287
|
self._maybe_collapse_locked()
|
|
195
288
|
entries = [
|
|
196
289
|
e for e in self._read_all()
|
|
@@ -202,7 +295,7 @@ class NotificationStore:
|
|
|
202
295
|
|
|
203
296
|
def get_suppressed_info_count(self) -> int:
|
|
204
297
|
"""Count of unacknowledged 'info' notifications not shown in actionable view."""
|
|
205
|
-
with self.
|
|
298
|
+
with self._locked():
|
|
206
299
|
self._maybe_collapse_locked()
|
|
207
300
|
return sum(
|
|
208
301
|
1 for e in self._read_all()
|
|
@@ -218,12 +311,12 @@ class NotificationStore:
|
|
|
218
311
|
|
|
219
312
|
def acknowledge(self, notification_id: str) -> bool:
|
|
220
313
|
"""Mark a single notification as acknowledged."""
|
|
221
|
-
with self.
|
|
314
|
+
with self._locked():
|
|
222
315
|
return self._set_ack(lambda e: e.get("id") == notification_id)
|
|
223
316
|
|
|
224
317
|
def acknowledge_all(self) -> int:
|
|
225
318
|
"""Mark all unacknowledged notifications as acknowledged. Returns count."""
|
|
226
|
-
with self.
|
|
319
|
+
with self._locked():
|
|
227
320
|
entries = self._read_all()
|
|
228
321
|
count = 0
|
|
229
322
|
for e in entries:
|
|
@@ -239,7 +332,7 @@ class NotificationStore:
|
|
|
239
332
|
|
|
240
333
|
Auto-acknowledges those included. Returns empty string if none.
|
|
241
334
|
"""
|
|
242
|
-
with self.
|
|
335
|
+
with self._locked():
|
|
243
336
|
self._maybe_collapse_locked()
|
|
244
337
|
entries = self._read_all()
|
|
245
338
|
pending = [
|
|
@@ -282,7 +375,7 @@ class NotificationStore:
|
|
|
282
375
|
than ``min_age_minutes`` also stay, so add()'s post-ack cooldown
|
|
283
376
|
suppression window keeps working. Returns the count moved.
|
|
284
377
|
"""
|
|
285
|
-
with self.
|
|
378
|
+
with self._locked():
|
|
286
379
|
entries = self._read_all()
|
|
287
380
|
horizon = datetime.now(timezone.utc) - timedelta(
|
|
288
381
|
minutes=max(0, min_age_minutes))
|
|
@@ -312,14 +405,15 @@ class NotificationStore:
|
|
|
312
405
|
def collapse_duplicates(self) -> int:
|
|
313
406
|
"""Retro-cleanup: merge unacknowledged duplicates into one record each.
|
|
314
407
|
|
|
315
|
-
Unacknowledged entries sharing (agent, title) collapse into
|
|
316
|
-
recent record, which absorbs the group's total ``count``, the
|
|
317
|
-
``last_seen``, and the highest severity. The newest message wins —
|
|
408
|
+
Unacknowledged entries sharing (agent, title, ref_id) collapse into
|
|
409
|
+
the most recent record, which absorbs the group's total ``count``, the
|
|
410
|
+
max ``last_seen``, and the highest severity. The newest message wins —
|
|
318
411
|
older same-title messages are stale snapshots of the same condition.
|
|
412
|
+
Entries about different things (different ``ref_id``) never merge.
|
|
319
413
|
Acknowledged history is never touched. Returns the number of duplicate
|
|
320
414
|
records removed.
|
|
321
415
|
"""
|
|
322
|
-
with self.
|
|
416
|
+
with self._locked():
|
|
323
417
|
self._collapsed = True
|
|
324
418
|
return self._collapse_locked()
|
|
325
419
|
|
|
@@ -334,13 +428,14 @@ class NotificationStore:
|
|
|
334
428
|
pass # maintenance is best-effort — never break reads/writes
|
|
335
429
|
|
|
336
430
|
def _collapse_locked(self) -> int:
|
|
337
|
-
"""Merge unacked duplicates (same agent+title). Caller must hold
|
|
431
|
+
"""Merge unacked duplicates (same agent+title+ref_id). Caller must hold _locked()."""
|
|
338
432
|
entries = self._read_all()
|
|
339
433
|
groups: dict[tuple, list] = {}
|
|
340
434
|
for e in entries:
|
|
341
435
|
if e.get("acknowledged"):
|
|
342
436
|
continue
|
|
343
|
-
groups.setdefault((e.get("agent"), e.get("title")
|
|
437
|
+
groups.setdefault((e.get("agent"), e.get("title"),
|
|
438
|
+
e.get("ref_id") or ""), []).append(e)
|
|
344
439
|
|
|
345
440
|
drop_ids: set[int] = set()
|
|
346
441
|
removed = 0
|
|
@@ -377,10 +472,16 @@ class NotificationStore:
|
|
|
377
472
|
return entries
|
|
378
473
|
|
|
379
474
|
def _write_all(self, entries: list):
|
|
380
|
-
"""Rewrite entire file. Caller must hold
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
475
|
+
"""Rewrite entire file. Caller must hold _locked().
|
|
476
|
+
|
|
477
|
+
Published by atomic replace, so a reader that takes no lock (the
|
|
478
|
+
gateway feed, the hub) sees the old file or the new one, never the
|
|
479
|
+
truncated middle of a rewrite. No fsync: this is a feed, and what
|
|
480
|
+
readers need is the replace, not durability across a power cut.
|
|
481
|
+
"""
|
|
482
|
+
write_text_atomic(self._file,
|
|
483
|
+
"".join(json.dumps(e) + "\n" for e in entries),
|
|
484
|
+
fsync=False)
|
|
384
485
|
|
|
385
486
|
def _set_ack(self, predicate) -> bool:
|
|
386
487
|
"""Acknowledge entries matching predicate. Caller must hold _lock."""
|
services/override_requests.py
CHANGED
|
@@ -559,6 +559,11 @@ def _notify_decision(project_path: str, row: dict, grant=None) -> None:
|
|
|
559
559
|
severity="info",
|
|
560
560
|
title=f"Override {status}: {name}",
|
|
561
561
|
message=message,
|
|
562
|
+
# Scopes the store's dedup to this request: two decisions on one
|
|
563
|
+
# file inside the info cooldown are two lines, and a client drops
|
|
564
|
+
# a card answered elsewhere when it sees one. No `kind`, so the
|
|
565
|
+
# line still reads as a decision rather than a request to route to.
|
|
566
|
+
ref_id=str(row.get("id") or ""),
|
|
562
567
|
)
|
|
563
568
|
except Exception:
|
|
564
569
|
pass # the decision already happened; a missing feed line never undoes it
|
|
File without changes
|
{code_context_control-2.158.1.dist-info → code_context_control-2.158.3.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{code_context_control-2.158.1.dist-info → code_context_control-2.158.3.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
{code_context_control-2.158.1.dist-info → code_context_control-2.158.3.dist-info}/top_level.txt
RENAMED
|
File without changes
|