code-context-control 2.157.2__py3-none-any.whl → 2.158.0__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 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.157.2"
94
+ __version__ = "2.158.0"
95
95
 
96
96
  # The PreToolUse matcher for native subagent calls (installer and hub migration).
97
97
  AGENT_MATCHER = "Agent|Task"
cli/mcp_server.py CHANGED
@@ -768,10 +768,13 @@ def _finalize_response(ctx: Context, tool_name: str, args: dict,
768
768
  reasoning=f"Budget at {snap_pct}% — auto-snapshot before potential /clear",
769
769
  description="", summary="", event_type="auto",
770
770
  svc=svc, finalize=lambda *a, **kw: "")
771
- response += (
772
- f"\n\n[c3:auto_snapshot] Budget {snap_pct}%. Snapshot saved. "
773
- f"Tell user to /clear, then restore."
774
- )
771
+ # A format="json" reply must stay parseable: no text appended.
772
+ from cli.tools._json_reply import is_json_reply
773
+ if not is_json_reply(response):
774
+ response += (
775
+ f"\n\n[c3:auto_snapshot] Budget {snap_pct}%. Snapshot saved. "
776
+ f"Tell user to /clear, then restore."
777
+ )
775
778
  svc.activity_log.log("auto_snapshot", {"budget_pct": snap_pct})
776
779
  except Exception:
777
780
  pass
@@ -1289,11 +1292,20 @@ async def c3_bitbucket(
1289
1292
  webhook_id: int = 0,
1290
1293
  comment_id: int = 0,
1291
1294
  limit: int = 50,
1295
+ path: str = "",
1296
+ at: str = "",
1297
+ filter_text: str = "",
1298
+ order: str = "",
1299
+ format: str = "",
1292
1300
  ctx: Context = None,
1293
1301
  ) -> str:
1294
1302
  """BITBUCKET (Data Center / Server) — see and act on PRs, branches, builds, repo admin.
1295
- actions: status, whoami, list_projects, list_repos, get_repo,
1303
+ actions: status, whoami, list_projects, list_repos, get_repo (description,
1304
+ default branch, browse and clone URLs),
1305
+ readme ([at=branch/commit] — the root README, markdown preferred),
1306
+ get_file (path [at] — one text file, 256 KB cap, binary refused),
1296
1307
  list_prs, get_pr, get_pr_diff, get_pr_activities, get_pr_commits,
1308
+ pr_issues (pr_id — Jira issues Bitbucket's Jira integration links to the PR),
1297
1309
  create_pr, update_pr (pr_id + any of title/description/reviewers/to_branch —
1298
1310
  unchanged fields are preserved; reviewers is the FULL comma-separated
1299
1311
  replacement set), comment_pr,
@@ -1305,10 +1317,13 @@ async def c3_bitbucket(
1305
1317
  list_pr_tasks (state filters OPEN/RESOLVED), create_pr_task (pr_id, body —
1306
1318
  a blocker task on the PR), resolve_pr_task (pr_id, comment_id from
1307
1319
  list_pr_tasks),
1308
- list_branches, create_branch, delete_branch,
1309
- list_commits, list_activity, build_status,
1320
+ list_branches ([filter_text] [order=MODIFICATION|ALPHABETICAL]), create_branch,
1321
+ delete_branch, list_commits ([branch] [path]), list_activity, build_status (commit),
1310
1322
  repo_settings, update_repo_settings, list_webhooks, create_webhook, delete_webhook,
1311
1323
  list_permissions.
1324
+ format="json": reads return {"ok", "action", "data"} JSON (normalized fields, a
1325
+ ~400k-char cap that trims lists and sets "truncated"); writes return the text
1326
+ reply in data.text; errors return {"ok": false, "error"}. For programs, not agents.
1312
1327
  project/repo fall back to bitbucket.default_project/default_repo from .c3/config.json.
1313
1328
  Tokens live in the OS keyring — `c3 bitbucket login` to set them up first."""
1314
1329
  svc = _svc(ctx)
@@ -1324,7 +1339,8 @@ async def c3_bitbucket(
1324
1339
  description=description, reviewers=reviewers, name=name, url=url,
1325
1340
  events=events, start_point=start_point, commit=commit,
1326
1341
  settings=settings, webhook_id=webhook_id, comment_id=comment_id,
1327
- limit=limit,
1342
+ limit=limit, path=path, at=at, filter_text=filter_text, order=order,
1343
+ format=format,
1328
1344
  )
1329
1345
 
1330
1346
 
@@ -1357,10 +1373,16 @@ async def c3_jira(
1357
1373
  file_path: str = "",
1358
1374
  delete_subtasks: bool = False,
1359
1375
  limit: int = 25,
1376
+ validate: str = "",
1377
+ format: str = "",
1360
1378
  ctx: Context = None,
1361
1379
  ) -> str:
1362
1380
  """JIRA (Cloud + Data Center) — search, read, create, update, link, sprint, comment, transition, assign issues.
1363
- actions: status, whoami, search (jql), get_issue (issue — shows parent, links, attachments),
1381
+ actions: status, whoami, search (jql [validate=warn — Data Center: unknown keys in
1382
+ `key in (...)` become warnings instead of failing the query]),
1383
+ get_issue (issue — shows type, parent, subtasks, links, attachments),
1384
+ dev_status (issue — pull requests, branches and commits from Jira's development panel;
1385
+ some instances disable that API, which reports as unavailable),
1364
1386
  my_issues, list_projects, list_transitions (issue), get_create_metadata (project, issue_type),
1365
1387
  search_users (query), list_link_types,
1366
1388
  list_boards ([project]), list_sprints (board_id [sprint_state=active|future|closed]),
@@ -1383,6 +1405,10 @@ async def c3_jira(
1383
1405
  get_create_metadata reflects Jira's field configuration, not the create screen — if
1384
1406
  create_issue rejects a listed field ('not on the appropriate screen'), create without
1385
1407
  it and set it via update_issue (the edit screen is configured separately).
1408
+ format="json": reads return {"ok", "action", "data"} JSON (normalized fields incl.
1409
+ rendered HTML description/comments, a ~400k-char cap that trims lists and sets
1410
+ "truncated"); writes return the text reply in data.text; errors return
1411
+ {"ok": false, "error"}. For programs, not agents.
1386
1412
  project falls back to the account's default_project; account to jira.default_account.
1387
1413
  Mutating actions are ledger-logged. Tokens live in the OS keyring — `c3 jira login` first."""
1388
1414
  svc = _svc(ctx)
@@ -1402,6 +1428,7 @@ async def c3_jira(
1402
1428
  sprint_id=sprint_id, sprint_state=sprint_state,
1403
1429
  time_spent=time_spent, file_path=file_path,
1404
1430
  delete_subtasks=delete_subtasks, limit=limit,
1431
+ validate=validate, format=format,
1405
1432
  )
1406
1433
 
1407
1434
 
@@ -0,0 +1,90 @@
1
+ """JSON replies for c3_jira / c3_bitbucket ``format="json"``.
2
+
3
+ Programs (dashboards, the Work Agents Work page) read these tools too, and
4
+ the text replies are capped at a few thousand tokens for agents. JSON mode
5
+ returns the normalized data instead, under a much larger character cap that
6
+ trims list and string fields so the reply always stays valid JSON:
7
+
8
+ {"ok": true, "action": "get_issue", "data": {...}, "truncated": ["comments"]}
9
+ {"ok": false, "action": "get_issue", "error": "...", "status": 404}
10
+ """
11
+ from __future__ import annotations
12
+
13
+ import json
14
+ from typing import Any
15
+
16
+ JSON_CHAR_CAP = 400_000
17
+
18
+ # Lists ordered oldest first: trimming keeps their newest entries.
19
+ _KEEP_TAIL = {"comments", "activities"}
20
+
21
+ # A string shorter than this is not worth cutting; the next field is.
22
+ _MIN_CUT = 1000
23
+
24
+
25
+ def wants_json(kwargs: dict) -> bool:
26
+ return str(kwargs.get("format") or "").strip().lower() == "json"
27
+
28
+
29
+ def _dumps(obj: Any) -> str:
30
+ return json.dumps(obj, ensure_ascii=False, default=str)
31
+
32
+
33
+ def _fit(data: dict, cap: int, overhead: int) -> list[str]:
34
+ """Shrink the largest top-level fields of *data* in place until the
35
+ serialized dict fits in ``cap - overhead`` characters. Returns the names
36
+ of the fields that were cut."""
37
+ truncated: list[str] = []
38
+ budget = max(0, cap - overhead)
39
+ for _ in range(200):
40
+ if len(_dumps(data)) <= budget:
41
+ break
42
+ sizes = {k: len(_dumps(v)) for k, v in data.items()}
43
+ key = max(sizes, key=sizes.get)
44
+ value = data[key]
45
+ if isinstance(value, list) and len(value) > 1:
46
+ keep = max(1, len(value) * 3 // 4)
47
+ data[key] = value[-keep:] if key in _KEEP_TAIL else value[:keep]
48
+ elif isinstance(value, str) and len(value) > _MIN_CUT:
49
+ data[key] = value[: len(value) * 3 // 4]
50
+ elif isinstance(value, (list, dict)) and value:
51
+ data[key] = [] if isinstance(value, list) else {}
52
+ else:
53
+ data[key] = None
54
+ if key not in truncated:
55
+ truncated.append(key)
56
+ return truncated
57
+
58
+
59
+ def ok(action: str, data: Any, *, cap: int = JSON_CHAR_CAP) -> str:
60
+ """Serialize a successful read. A non-dict *data* is wrapped as
61
+ ``{"values": data}`` so every reply trims the same way."""
62
+ if not isinstance(data, dict):
63
+ data = {"values": data}
64
+ data = dict(data)
65
+ head = {"ok": True, "action": action}
66
+ truncated = _fit(data, cap, len(_dumps(head)) + 64)
67
+ out = {**head, "data": data}
68
+ if truncated:
69
+ out["truncated"] = truncated
70
+ return _dumps(out)
71
+
72
+
73
+ def error(action: str, message: str, *, status: int = 0, code: str = "") -> str:
74
+ out: dict[str, Any] = {"ok": False, "action": action, "error": message}
75
+ if status:
76
+ out["status"] = status
77
+ if code:
78
+ out["code"] = code
79
+ return _dumps(out)
80
+
81
+
82
+ def text(action: str, resp: str) -> str:
83
+ """An action with no structured form (writes, diffs) in JSON mode: the
84
+ text reply rides in ``data.text`` so the caller still gets JSON."""
85
+ return ok(action, {"text": resp})
86
+
87
+
88
+ def is_json_reply(response: str) -> bool:
89
+ """True for a reply built here; callers must not append text to it."""
90
+ return response.startswith('{"ok": ')