code-context-control 2.157.1__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/_shell_writes.py +68 -3
- cli/c3.py +1 -1
- cli/hook_access_guard.py +115 -14
- cli/mcp_server.py +36 -9
- cli/tools/_json_reply.py +90 -0
- cli/tools/bitbucket.py +497 -146
- cli/tools/jira.py +263 -75
- cli/tools/shell.py +80 -19
- {code_context_control-2.157.1.dist-info → code_context_control-2.158.0.dist-info}/METADATA +1 -1
- {code_context_control-2.157.1.dist-info → code_context_control-2.158.0.dist-info}/RECORD +19 -18
- {code_context_control-2.157.1.dist-info → code_context_control-2.158.0.dist-info}/WHEEL +1 -1
- services/access_guard.py +13 -1
- services/bitbucket_client.py +115 -2
- services/jira_client.py +170 -4
- services/jira_cloud.py +19 -3
- services/jira_data_center.py +34 -13
- {code_context_control-2.157.1.dist-info → code_context_control-2.158.0.dist-info}/entry_points.txt +0 -0
- {code_context_control-2.157.1.dist-info → code_context_control-2.158.0.dist-info}/licenses/LICENSE +0 -0
- {code_context_control-2.157.1.dist-info → code_context_control-2.158.0.dist-info}/top_level.txt +0 -0
cli/_shell_writes.py
CHANGED
|
@@ -33,7 +33,73 @@ _PY_WRITE_TEXT_RE = re.compile(r"""Path\(\s*(?P<q>['"])(?P<t>[^'"]+)(?P=q)\s*\)\
|
|
|
33
33
|
_FILE_CMDS = {"cp", "mv", "touch", "rm", "install"}
|
|
34
34
|
_STREAMS = {"/dev/null", "/dev/stdout", "/dev/stderr", "nul", "&1", "&2", "-"}
|
|
35
35
|
_SYNTAX = set("$`(){}|<>*?")
|
|
36
|
+
_MSYS_DRIVE_RE = re.compile(r"^/([a-zA-Z])(?=/|$)")
|
|
37
|
+
_QUOTED_RES = (re.compile(r'"([^"\n]{1,400})"'), re.compile(r"'([^'\n]{1,400})'"))
|
|
36
38
|
MAX_TARGETS = 20
|
|
39
|
+
MAX_QUOTED = 64
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def msys_drive(path: str) -> str:
|
|
43
|
+
"""`/c/x` -> `c:/x` on Windows, where Git Bash spells drives that way.
|
|
44
|
+
|
|
45
|
+
Without it `cd /u/repo` resolves to `<cwd drive>:/u/repo`, a directory
|
|
46
|
+
that does not exist, and every relative path after it is judged there.
|
|
47
|
+
"""
|
|
48
|
+
if os.name != "nt" or not _MSYS_DRIVE_RE.match(path):
|
|
49
|
+
return path
|
|
50
|
+
return f"{path[1]}:/{path[3:]}"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _shell_quoted(cmd: str) -> list[str]:
|
|
54
|
+
"""Quoted strings as the shell reads them: `'` is literal inside `"`."""
|
|
55
|
+
out: list[str] = []
|
|
56
|
+
buf: list[str] = []
|
|
57
|
+
quote, esc = None, False
|
|
58
|
+
for ch in cmd:
|
|
59
|
+
if quote is None:
|
|
60
|
+
if esc:
|
|
61
|
+
esc = False
|
|
62
|
+
elif ch == "\\":
|
|
63
|
+
esc = True
|
|
64
|
+
elif ch in "'\"":
|
|
65
|
+
quote, buf = ch, []
|
|
66
|
+
elif quote == '"' and esc:
|
|
67
|
+
buf.append(ch)
|
|
68
|
+
esc = False
|
|
69
|
+
elif quote == '"' and ch == "\\":
|
|
70
|
+
buf.append(ch)
|
|
71
|
+
esc = True
|
|
72
|
+
elif ch == quote:
|
|
73
|
+
out.append("".join(buf))
|
|
74
|
+
quote = None
|
|
75
|
+
else:
|
|
76
|
+
buf.append(ch)
|
|
77
|
+
return out
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def quoted_paths(cmd: str) -> list[str]:
|
|
81
|
+
"""Path-shaped quoted substrings of a command, for the access scans.
|
|
82
|
+
|
|
83
|
+
A quoted path with spaces (`"U:/1. Projects/x/.env"`) splits into
|
|
84
|
+
fragments under a whitespace tokenizer, and quoted code
|
|
85
|
+
(`node -e "fs.readFileSync('x/.env')"`, a heredoc body) hides its
|
|
86
|
+
path inside a larger token. So this returns the shell's own quoted
|
|
87
|
+
strings plus the string literals inside them and anywhere in the text.
|
|
88
|
+
Over-collecting is expected: callers judge each candidate against files
|
|
89
|
+
that exist.
|
|
90
|
+
"""
|
|
91
|
+
out: list[str] = []
|
|
92
|
+
cmd = cmd or ""
|
|
93
|
+
tops = _shell_quoted(cmd)
|
|
94
|
+
for s in tops + [m.group(1) for t in tops + [cmd]
|
|
95
|
+
for rx in _QUOTED_RES for m in rx.finditer(t)]:
|
|
96
|
+
s = s.strip()
|
|
97
|
+
if (s and "\n" not in s and len(s) <= 400 and s not in out
|
|
98
|
+
and ("/" in s or "\\" in s or s.startswith("."))):
|
|
99
|
+
out.append(s)
|
|
100
|
+
if len(out) >= MAX_QUOTED:
|
|
101
|
+
break
|
|
102
|
+
return out
|
|
37
103
|
|
|
38
104
|
|
|
39
105
|
def _clean(tok: str) -> str:
|
|
@@ -79,7 +145,7 @@ def _cd_target(segment: str, cwd: str) -> str | None:
|
|
|
79
145
|
m = _CD_RE.match(segment)
|
|
80
146
|
if not m:
|
|
81
147
|
return None
|
|
82
|
-
target = m.group("dir").strip("\"'")
|
|
148
|
+
target = msys_drive(os.path.expanduser(m.group("dir").strip("\"'")))
|
|
83
149
|
try:
|
|
84
150
|
return target if os.path.isabs(target) else os.path.normpath(os.path.join(cwd, target))
|
|
85
151
|
except (OSError, ValueError):
|
|
@@ -99,8 +165,7 @@ def shell_write_targets(cmd: str, cwd: str) -> list[str]:
|
|
|
99
165
|
try:
|
|
100
166
|
for segment in _SEGMENT_SPLIT.split(cmd or ""):
|
|
101
167
|
for tok in _segment_targets(segment):
|
|
102
|
-
|
|
103
|
-
tok = f"{tok[1]}:{tok[2:]}"
|
|
168
|
+
tok = msys_drive(os.path.expanduser(tok))
|
|
104
169
|
try:
|
|
105
170
|
p = Path(tok) if os.path.isabs(tok) else Path(here) / tok
|
|
106
171
|
key = os.path.normcase(os.path.normpath(str(p)))
|
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.
|
|
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/hook_access_guard.py
CHANGED
|
@@ -34,13 +34,19 @@ except Exception: # pragma: no cover — telemetry is never load-bearing
|
|
|
34
34
|
# The same write-target extractor the edit ledger uses after the fact. Its
|
|
35
35
|
# absence degrades the shell branch to the read-only scan, never to a crash.
|
|
36
36
|
try:
|
|
37
|
-
from _shell_writes import shell_write_targets
|
|
37
|
+
from _shell_writes import msys_drive, quoted_paths, shell_write_targets
|
|
38
38
|
except Exception: # pragma: no cover — package-style import (dispatcher, tests)
|
|
39
39
|
try:
|
|
40
|
-
from cli._shell_writes import shell_write_targets
|
|
40
|
+
from cli._shell_writes import msys_drive, quoted_paths, shell_write_targets
|
|
41
41
|
except Exception:
|
|
42
42
|
shell_write_targets = None
|
|
43
43
|
|
|
44
|
+
def msys_drive(path: str) -> str:
|
|
45
|
+
return path
|
|
46
|
+
|
|
47
|
+
def quoted_paths(cmd: str) -> list:
|
|
48
|
+
return []
|
|
49
|
+
|
|
44
50
|
_WRITE_TOOLS = {"Edit", "Write", "MultiEdit", "NotebookEdit"}
|
|
45
51
|
_READ_TOOLS = {"Read", "SearchText"}
|
|
46
52
|
_SEARCH_TOOLS = {"Grep", "Glob", "FindFiles"}
|
|
@@ -112,7 +118,20 @@ _DOUBLE_COLON_RE = re.compile(r"::(?!\$)")
|
|
|
112
118
|
# `<rev>:<path>` — how git names a blob: `git show HEAD:setup.py`,
|
|
113
119
|
# `git cat-file -p origin/main:src/a.py`.
|
|
114
120
|
_GIT_REVSPEC_RE = re.compile(r"^(?P<rev>[^:\s]+):(?P<path>[^:\s]+)$")
|
|
115
|
-
|
|
121
|
+
# Loop and conditional bodies (`do git show …`) and env prefixes
|
|
122
|
+
# (`GIT_PAGER= git show …`) are still git commands.
|
|
123
|
+
_GIT_CMD_RE = re.compile(
|
|
124
|
+
r"^\s*(?:(?:do|then|else|time|exec|command)\s+|[!({]\s*|[A-Za-z_]\w*=\S*\s+)*"
|
|
125
|
+
r"(?:[\w.\-]*[/\\])?git(?:\.exe)?\b",
|
|
126
|
+
re.IGNORECASE,
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
# Refusals that judge how a path is SPELLED rather than which file it names.
|
|
130
|
+
# A shell token that trips one is usually not a path at all, so these are
|
|
131
|
+
# re-judged as the file they could reach (_spelling_verdict).
|
|
132
|
+
_SPELLING_RULES = frozenset({"<ads>", "<unc>", "<empty-component>", "<8.3-alias>"})
|
|
133
|
+
# `\\host\share` or `//host/share`: one separator between host and share.
|
|
134
|
+
_UNC_SHARE_RE = re.compile(r"^(?:\\\\|//)[^\\/\s]+[\\/][^\\/\s]+")
|
|
116
135
|
|
|
117
136
|
# Where one command ends and the next begins. Anchoring "is this git?" to the
|
|
118
137
|
# start of the whole string was wrong in the most ordinary way possible:
|
|
@@ -190,6 +209,56 @@ def _looks_like_a_path(tok: str) -> bool:
|
|
|
190
209
|
return not (_SYNTAX_CHARS & set(tok))
|
|
191
210
|
|
|
192
211
|
|
|
212
|
+
def _exists(path: str) -> bool:
|
|
213
|
+
try:
|
|
214
|
+
return Path(path).exists()
|
|
215
|
+
except (OSError, ValueError):
|
|
216
|
+
return False
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def _stream_base(path: str) -> str:
|
|
220
|
+
"""`C:/x/f.txt:name:$DATA` -> `C:/x/f.txt`: the file a stream belongs to."""
|
|
221
|
+
head = path[:2] if re.match(r"^[A-Za-z]:", path) else ""
|
|
222
|
+
return head + path[len(head):].split(":", 1)[0]
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def _dots_collapsed(path: str) -> str:
|
|
226
|
+
"""The path Windows opens for a spelling with dot-only components.
|
|
227
|
+
|
|
228
|
+
Win32 strips trailing dots and spaces, so `a/.../b` and `a/x/../b` both
|
|
229
|
+
land somewhere real; model that before asking which file it is.
|
|
230
|
+
"""
|
|
231
|
+
parts = re.split(r"[\\/]", path)
|
|
232
|
+
kept = [p if p in ("", ".", "..") or p.rstrip(". ") else "." for p in parts]
|
|
233
|
+
return os.path.normpath("/".join(kept))
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _spelling_verdict(denial, tok: str, probe: str, base: str):
|
|
237
|
+
"""The deny a path-spelling refusal stands for in a shell command, or None.
|
|
238
|
+
|
|
239
|
+
The spelling rules keep a protected file from being reached under an odd
|
|
240
|
+
name. Tokens that trip them in shell text are mostly not paths
|
|
241
|
+
(`origin/main:x`, `// comment`, `taskkill //F`, `...`), so the token is
|
|
242
|
+
judged as the file it could name, with the usual existence gate, and
|
|
243
|
+
refused only when that file is denied. A real UNC share stays denied: a
|
|
244
|
+
network path cannot be judged locally.
|
|
245
|
+
"""
|
|
246
|
+
if denial.rule == "<unc>":
|
|
247
|
+
unc = any(_UNC_SHARE_RE.match(t) for t in (tok, tok.replace("\\\\", "\\")))
|
|
248
|
+
return denial if unc else None
|
|
249
|
+
if denial.rule == "<ads>":
|
|
250
|
+
target = _stream_base(probe)
|
|
251
|
+
elif denial.rule == "<empty-component>":
|
|
252
|
+
target = _dots_collapsed(probe)
|
|
253
|
+
else:
|
|
254
|
+
return None # <8.3-alias>: a short name that does not exist names nothing
|
|
255
|
+
real = ag.check(target, "read", base)
|
|
256
|
+
if (real and real.kind == "deny" and not real.rule.startswith("<")
|
|
257
|
+
and _exists(target)):
|
|
258
|
+
return real
|
|
259
|
+
return None
|
|
260
|
+
|
|
261
|
+
|
|
193
262
|
def _deny(reason: str) -> dict:
|
|
194
263
|
return {
|
|
195
264
|
"hookSpecificOutput": {
|
|
@@ -290,7 +359,8 @@ def _cd_target(segment: str, cwd: str) -> str | None:
|
|
|
290
359
|
if not target or target.startswith("-"):
|
|
291
360
|
return None
|
|
292
361
|
try:
|
|
293
|
-
return os.path.abspath(
|
|
362
|
+
return os.path.abspath(
|
|
363
|
+
os.path.join(cwd, msys_drive(os.path.expanduser(target))))
|
|
294
364
|
except (OSError, ValueError):
|
|
295
365
|
return None
|
|
296
366
|
|
|
@@ -300,12 +370,13 @@ def _scan_shell(cmd: str, base: str):
|
|
|
300
370
|
|
|
301
371
|
Confident = the token resolves to an EXISTING path that a ``deny`` rule
|
|
302
372
|
covers (existence-gating keeps regex/pattern arguments like '\\.env'
|
|
303
|
-
from false-denying)
|
|
373
|
+
from false-denying). A spelling refusal (``<ads>``, ``<unc>``, …) counts
|
|
374
|
+
only when the file the spelling could reach is itself denied
|
|
375
|
+
(``_spelling_verdict``). Quoted substrings are judged as well, so a
|
|
376
|
+
quoted path with spaces is not lost to whitespace splitting.
|
|
304
377
|
|
|
305
378
|
Tokens that are shell syntax rather than path arguments are skipped
|
|
306
|
-
outright, as are URLs and IPv6 literals
|
|
307
|
-
check, which is exempt from existence-gating, so a token naming nothing on
|
|
308
|
-
disk would otherwise hard-deny (#50).
|
|
379
|
+
outright, as are URLs and IPv6 literals.
|
|
309
380
|
|
|
310
381
|
Scanning is per **command segment**, not per whole string. A segment is what
|
|
311
382
|
sits between `&&`, `||`, `;`, `|` or a newline, and each one answers "am I a
|
|
@@ -315,6 +386,7 @@ def _scan_shell(cmd: str, base: str):
|
|
|
315
386
|
"""
|
|
316
387
|
budget = _MAX_TOKENS
|
|
317
388
|
cwd = base
|
|
389
|
+
visited = [base]
|
|
318
390
|
for segment in _SEGMENT_SPLIT.split(cmd or ""):
|
|
319
391
|
if budget <= 0:
|
|
320
392
|
break
|
|
@@ -347,8 +419,7 @@ def _scan_shell(cmd: str, base: str):
|
|
|
347
419
|
from_revspec = revspec_path is not None
|
|
348
420
|
if from_revspec:
|
|
349
421
|
tok = revspec_path
|
|
350
|
-
|
|
351
|
-
tok = f"{tok[1]}:{tok[2:]}"
|
|
422
|
+
tok = msys_drive(tok)
|
|
352
423
|
# Resolve against the cwd the command will actually run in, not the
|
|
353
424
|
# session root. `cd /elsewhere && cat .env` used to compute the
|
|
354
425
|
# denial correctly and then throw it away, because the existence
|
|
@@ -363,10 +434,12 @@ def _scan_shell(cmd: str, base: str):
|
|
|
363
434
|
probe = tok
|
|
364
435
|
denial = ag.check(probe, "read", base)
|
|
365
436
|
if denial and denial.kind == "deny":
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
437
|
+
if denial.rule in _SPELLING_RULES:
|
|
438
|
+
denial = _spelling_verdict(denial, tok, probe, base)
|
|
439
|
+
if denial is not None:
|
|
440
|
+
return denial, tok
|
|
441
|
+
continue
|
|
442
|
+
exists = _exists(probe)
|
|
370
443
|
# A revspec names a path in HISTORY, so the working tree is the
|
|
371
444
|
# wrong place to ask whether it is real. `git show HEAD~5:.env`
|
|
372
445
|
# reads a denied file whether or not that file exists today, and
|
|
@@ -378,6 +451,34 @@ def _scan_shell(cmd: str, base: str):
|
|
|
378
451
|
moved = _cd_target(segment, cwd)
|
|
379
452
|
if moved is not None:
|
|
380
453
|
cwd = moved
|
|
454
|
+
visited.append(cwd)
|
|
455
|
+
return _scan_quoted(cmd, visited, base)
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _scan_quoted(cmd: str, dirs: list, base: str):
|
|
459
|
+
"""(denial, token) for a quoted path naming an existing denied file.
|
|
460
|
+
|
|
461
|
+
Quotes can span the segment separators, so this runs over the whole
|
|
462
|
+
command and resolves a relative path against every directory the scan
|
|
463
|
+
visited. A quoted `//host/path` is far more often a protocol-relative URL
|
|
464
|
+
in code than a share, so `<unc>` is not judged here; the token scan still
|
|
465
|
+
judges it.
|
|
466
|
+
"""
|
|
467
|
+
for raw in quoted_paths(cmd):
|
|
468
|
+
if _is_network_token(raw):
|
|
469
|
+
continue
|
|
470
|
+
tok = msys_drive(os.path.expanduser(raw))
|
|
471
|
+
for here in ([base] if os.path.isabs(tok) else dirs):
|
|
472
|
+
probe = tok if os.path.isabs(tok) else os.path.join(here, tok)
|
|
473
|
+
denial = ag.check(probe, "read", base)
|
|
474
|
+
if not denial or denial.kind != "deny" or denial.rule == "<unc>":
|
|
475
|
+
continue
|
|
476
|
+
if denial.rule in _SPELLING_RULES:
|
|
477
|
+
denial = _spelling_verdict(denial, tok, probe, base)
|
|
478
|
+
elif not (_exists(probe) or denial.rule.startswith("<")):
|
|
479
|
+
denial = None
|
|
480
|
+
if denial is not None:
|
|
481
|
+
return denial, tok
|
|
381
482
|
return None, ""
|
|
382
483
|
|
|
383
484
|
|
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
|
-
|
|
772
|
-
|
|
773
|
-
|
|
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,
|
|
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
|
|
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
|
|
cli/tools/_json_reply.py
ADDED
|
@@ -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": ')
|