zyonix-cli 0.1.13__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.
- zyonix_cli/__init__.py +2 -0
- zyonix_cli/agent_init.py +228 -0
- zyonix_cli/auth_cmd.py +499 -0
- zyonix_cli/auth_store.py +124 -0
- zyonix_cli/brief.py +271 -0
- zyonix_cli/checks_cmd.py +160 -0
- zyonix_cli/client.py +130 -0
- zyonix_cli/cmdkit.py +142 -0
- zyonix_cli/common.py +94 -0
- zyonix_cli/context_view.py +116 -0
- zyonix_cli/deploy_cmd.py +52 -0
- zyonix_cli/drafts_cmd.py +260 -0
- zyonix_cli/explain.py +283 -0
- zyonix_cli/fix_cmd.py +284 -0
- zyonix_cli/guard_cmd.py +125 -0
- zyonix_cli/helpview.py +171 -0
- zyonix_cli/importer.py +274 -0
- zyonix_cli/issues_cmd.py +597 -0
- zyonix_cli/jobs_cmd.py +71 -0
- zyonix_cli/junit.py +49 -0
- zyonix_cli/mcp_cmd.py +96 -0
- zyonix_cli/mcp_server.py +375 -0
- zyonix_cli/monitor_cmd.py +120 -0
- zyonix_cli/perf_view.py +51 -0
- zyonix_cli/progress.py +57 -0
- zyonix_cli/prompts_cmd.py +166 -0
- zyonix_cli/regression_cmd.py +216 -0
- zyonix_cli/render.py +313 -0
- zyonix_cli/replay_cmd.py +215 -0
- zyonix_cli/review_cmd.py +169 -0
- zyonix_cli/runner.py +213 -0
- zyonix_cli/runs_cmd.py +638 -0
- zyonix_cli/spec_cmd.py +74 -0
- zyonix_cli/status_cmd.py +488 -0
- zyonix_cli/term.py +206 -0
- zyonix_cli/test_cmd.py +248 -0
- zyonix_cli/triage.py +215 -0
- zyonix_cli/usage.py +172 -0
- zyonix_cli/verify.py +223 -0
- zyonix_cli/verify_view.py +87 -0
- zyonix_cli-0.1.13.dist-info/METADATA +58 -0
- zyonix_cli-0.1.13.dist-info/RECORD +45 -0
- zyonix_cli-0.1.13.dist-info/WHEEL +4 -0
- zyonix_cli-0.1.13.dist-info/entry_points.txt +21 -0
- zyonix_cli-0.1.13.dist-info/licenses/LICENSE +202 -0
zyonix_cli/issues_cmd.py
ADDED
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
"""`zyonix issues`: the lifecycle board, one issue's root cause and evidence, and what to do next.
|
|
2
|
+
|
|
3
|
+
zyonix issues [list] [--status DIAGNOSED] # lifecycle board + issue list
|
|
4
|
+
zyonix issues show <id> # the brief: what failed, why, fix, next step
|
|
5
|
+
zyonix issues show <id> --verbose # every section: chain, cases, fixes, replay
|
|
6
|
+
zyonix issues groups # open issues grouped by what could fix them
|
|
7
|
+
zyonix issues context <id> [--text] # all evidence as one JSON document (agents)
|
|
8
|
+
zyonix issues report <id> [--out file.md] # the Markdown evidence report
|
|
9
|
+
zyonix issues reopen <id> --reason "..." # reopen a mitigated/resolved issue (admin)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from zyonix_cli import brief, explain, perf_view, term, triage, verify_view
|
|
19
|
+
from zyonix_cli.client import ApiClient, CliError
|
|
20
|
+
from zyonix_cli.cmdkit import add_overview, default_action, emit, group, leaf
|
|
21
|
+
from zyonix_cli.context_view import context_text
|
|
22
|
+
from zyonix_cli.render import (
|
|
23
|
+
ago,
|
|
24
|
+
badge,
|
|
25
|
+
clip,
|
|
26
|
+
heading,
|
|
27
|
+
jdump,
|
|
28
|
+
kv,
|
|
29
|
+
next_steps,
|
|
30
|
+
num,
|
|
31
|
+
pct,
|
|
32
|
+
plural,
|
|
33
|
+
print_json,
|
|
34
|
+
short_hash,
|
|
35
|
+
table,
|
|
36
|
+
when,
|
|
37
|
+
wrap,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
STATES = ("DETECTED", "DIAGNOSED", "FIX_PENDING", "VERIFYING", "AWAITING_APPROVAL",
|
|
41
|
+
"AWAITING_DEPLOY", "MONITORING", "RESOLVED", "REOPENED")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def register(sub: Any) -> None:
|
|
45
|
+
gp, actions = group(sub, "issues", "issues (clustered failures) with root cause and next step")
|
|
46
|
+
lp = leaf(actions, "list", "the lifecycle board and the issue list", cmd_list,
|
|
47
|
+
label="issues list")
|
|
48
|
+
lp.add_argument("--status", choices=STATES)
|
|
49
|
+
add_overview(lp)
|
|
50
|
+
default_action(gp, "list")
|
|
51
|
+
sp = leaf(actions, "show", "one issue: what failed, why and how sure, the fix, who acts next",
|
|
52
|
+
cmd_show, label="issues show")
|
|
53
|
+
sp.add_argument("issue", type=int, help="issue number (ISS-<n>)")
|
|
54
|
+
sp.add_argument("-v", "--verbose", action="store_true",
|
|
55
|
+
help="every section: evidence chain, differential, examples, regression "
|
|
56
|
+
"cases, Guard rates, fixes with replay results, monitoring, lifecycle")
|
|
57
|
+
leaf(actions, "groups", "open issues grouped by what could fix them, biggest first",
|
|
58
|
+
cmd_groups, label="issues groups")
|
|
59
|
+
cp = leaf(actions, "context", "all the evidence of one issue as one read-only JSON document "
|
|
60
|
+
"(for coding agents and scripts)", cmd_context, label="issues context")
|
|
61
|
+
cp.add_argument("issue", type=int, help="issue number (ISS-<n>)")
|
|
62
|
+
cp.add_argument("--max-bytes", type=int, default=65536,
|
|
63
|
+
help="size budget of the document (8192-262144); less important evidence is "
|
|
64
|
+
"dropped, and listed under limits.omitted, to fit")
|
|
65
|
+
cp.add_argument("--text", action="store_true",
|
|
66
|
+
help="a readable summary instead of JSON (untrusted text is delimited)")
|
|
67
|
+
rp = leaf(actions, "report", "the Markdown evidence report", cmd_report, label="issues report",
|
|
68
|
+
output=False)
|
|
69
|
+
rp.add_argument("issue", type=int)
|
|
70
|
+
rp.add_argument("--out", help="write the report to this file instead of printing it")
|
|
71
|
+
op = leaf(actions, "reopen", "reopen a mitigated or resolved issue so a root fix can be "
|
|
72
|
+
"attached (admin key)", cmd_reopen, label="issues reopen")
|
|
73
|
+
op.add_argument("issue", type=int)
|
|
74
|
+
op.add_argument("--reason", required=True)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def cause(i: dict[str, Any]) -> str:
|
|
78
|
+
rc = i["root_cause"]
|
|
79
|
+
text = rc["category"] or "UNDETERMINED"
|
|
80
|
+
if rc["subtype"]:
|
|
81
|
+
text += f"/{rc['subtype']}"
|
|
82
|
+
return text
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def issue_next(i: dict[str, Any]) -> list[tuple[str, str]]:
|
|
86
|
+
"""The next command for an issue, from its state and its latest fix."""
|
|
87
|
+
n = i["id"]
|
|
88
|
+
fixes = [f for f in i.get("fixes", []) if f["status"] != "superseded"]
|
|
89
|
+
fix = fixes[0] if fixes else None
|
|
90
|
+
st = i["status"]
|
|
91
|
+
if st in ("DIAGNOSED", "FIX_PENDING", "REOPENED"):
|
|
92
|
+
if fix and fix["status"] == "proposed" and fix["kind"] != "code_note":
|
|
93
|
+
return [(f"zyonix replay --fix {fix['id']}",
|
|
94
|
+
"verify the fix on your machine (k-of-N replay on sets A/B/C)")]
|
|
95
|
+
hint = [(f"zyonix fix propose --issue {n} --kind prompt --title \"...\" "
|
|
96
|
+
"--candidate-file fix.json",
|
|
97
|
+
"attach a fix (prompt | config | rule | code_note | runtime_policy)")]
|
|
98
|
+
if i.get("eligible_strategies"):
|
|
99
|
+
s = i["eligible_strategies"][0]
|
|
100
|
+
hint.append((f"zyonix fix propose --issue {n} --kind runtime_policy --strategy {s} "
|
|
101
|
+
f"--title \"enable {s}\"", "runtime repair; needs live dry-run evidence "
|
|
102
|
+
f"(zyonix guard mode {s} dry_run)"))
|
|
103
|
+
return hint
|
|
104
|
+
if st == "VERIFYING":
|
|
105
|
+
return [(f"zyonix fix show {fix['id']}" if fix else f"zyonix issues show {n}",
|
|
106
|
+
"verification is running; the result is uploaded by `zyonix replay`")]
|
|
107
|
+
if st == "AWAITING_APPROVAL" and fix:
|
|
108
|
+
return [(f"zyonix fix approve {fix['id']}", "approve the verified fix (human decision)"),
|
|
109
|
+
(f"zyonix fix reject {fix['id']} --reason \"...\"", "or send it back")]
|
|
110
|
+
if st == "AWAITING_DEPLOY" and fix:
|
|
111
|
+
return [(f"zyonix deploy --fix {fix['id']} --release <git-sha>",
|
|
112
|
+
"record that the approved fix is live (also detected from a release/hash change)")]
|
|
113
|
+
if st == "MONITORING":
|
|
114
|
+
return [("zyonix monitor status", "progress toward auto-resolve (0 recurrences, N runs, "
|
|
115
|
+
"D days)")]
|
|
116
|
+
if st == "DETECTED":
|
|
117
|
+
blocked = i.get("case_blockers") or []
|
|
118
|
+
if blocked:
|
|
119
|
+
return [(f"zyonix runs show {blocked[0]['run_id'][:12]}",
|
|
120
|
+
"diagnosis needs a regression case, and this failing run could not be "
|
|
121
|
+
f"frozen into one: {blocked[0]['reason'].replace('_', ' ')} (details above)")]
|
|
122
|
+
return [("zyonix review list", "diagnosis needs a regression case and, for uncertain "
|
|
123
|
+
"findings, a human confirmation")]
|
|
124
|
+
return []
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def cmd_list(client: ApiClient, args: argparse.Namespace) -> int:
|
|
128
|
+
out = client.get("/v1/issues", status=args.status)
|
|
129
|
+
if emit(args, out):
|
|
130
|
+
return 0
|
|
131
|
+
counts = out["counts"]
|
|
132
|
+
print("Lifecycle " + " ".join(f"{badge(s)} {counts[s]}" for s in STATES if counts.get(s)))
|
|
133
|
+
if not any(counts.values()):
|
|
134
|
+
print("no issues yet: nothing has failed enough to cluster, or detection has not run")
|
|
135
|
+
return 0
|
|
136
|
+
if not getattr(args, "verbose", False):
|
|
137
|
+
return _list_brief(client, out, args)
|
|
138
|
+
if out["review_open"]:
|
|
139
|
+
print(f"Review queue: {out['review_open']} open (zyonix review list)")
|
|
140
|
+
print()
|
|
141
|
+
print(table(["ISS", "STATUS", "SEV", "ROOT CAUSE", "RUNS", "LAST SEEN", "TITLE"], [
|
|
142
|
+
(f"ISS-{i['id']}", i["status"], i["severity"], cause(i), i["member_count"],
|
|
143
|
+
when(i["last_seen"]), i["title"]) for i in out["issues"]], max_col=60,
|
|
144
|
+
tones={1: "auto", 2: "auto"}))
|
|
145
|
+
print(next_steps([("zyonix issues show <id>", "root cause, evidence and the next step")]))
|
|
146
|
+
return 0
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def cmd_groups(client: ApiClient, args: argparse.Namespace) -> int:
|
|
150
|
+
out = client.get("/v1/problems")
|
|
151
|
+
if emit(args, out):
|
|
152
|
+
return 0
|
|
153
|
+
if not out["groups"]:
|
|
154
|
+
print("no open problems")
|
|
155
|
+
return 0
|
|
156
|
+
print(f"{plural(len(out['groups']), 'problem')}, {plural(out['open_issues'], 'open issue')}, "
|
|
157
|
+
f"{plural(out['documents_affected'], 'run')} affected")
|
|
158
|
+
for item in out["groups"]:
|
|
159
|
+
share = (f", {item['share_pct']:.0f}% of affected runs"
|
|
160
|
+
if item["shared_cause"] else "")
|
|
161
|
+
print(heading(item["title"]))
|
|
162
|
+
print(f" {plural(item['documents'], 'run')}{share}, {num(item['tokens'])} tokens")
|
|
163
|
+
print(wrap(item["why"]))
|
|
164
|
+
print(wrap(f"Could fix it: {item['fix']}"))
|
|
165
|
+
for title in item.get("concrete_fixes", []):
|
|
166
|
+
print(wrap(f"- {title}", indent=4))
|
|
167
|
+
print(wrap(item["basis"]))
|
|
168
|
+
print(" Issues: " + ", ".join(f"ISS-{i['id']}" for i in item["issues"]))
|
|
169
|
+
print(next_steps([("zyonix issues show <id>", "one issue: what failed, why, the next step")]))
|
|
170
|
+
return 0
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def _list_brief(client: ApiClient, out: dict[str, Any], args: argparse.Namespace) -> int:
|
|
174
|
+
"""One line per open issue, the most important first (all of them with a --status filter,
|
|
175
|
+
resolved ones included). ``--detail``: ERROR / ROOT CAUSE / FIX for each."""
|
|
176
|
+
if args.status: # one state asked for: all of its issues, resolved ones too
|
|
177
|
+
ranked = sorted(out["issues"], key=lambda i: (
|
|
178
|
+
brief.SEVERITY.get(i.get("severity") or "", 4), -(i.get("member_count") or 0)))
|
|
179
|
+
else:
|
|
180
|
+
ranked = brief.priority(out["issues"])
|
|
181
|
+
detail = getattr(args, "detail", False)
|
|
182
|
+
shown = ranked[:max(1, args.top or (3 if detail else triage.DEFAULT_TOP))]
|
|
183
|
+
print()
|
|
184
|
+
if not ranked:
|
|
185
|
+
print(brief.render("NO OPEN ISSUES", []))
|
|
186
|
+
print(" every issue is resolved")
|
|
187
|
+
elif detail:
|
|
188
|
+
more = (f"{len(ranked) - len(shown)} more: zyonix issues --top {len(ranked)}, or "
|
|
189
|
+
"the one-line overview: zyonix issues" if len(ranked) > len(shown) else None)
|
|
190
|
+
kind = f"{args.status or 'OPEN'} ISSUE"
|
|
191
|
+
word = plural(len(ranked), kind, kind + "S")
|
|
192
|
+
print(brief.render(word, [brief.issue_brief(client, i["id"]) for i in shown],
|
|
193
|
+
more=more))
|
|
194
|
+
else:
|
|
195
|
+
kind = f"{args.status or 'open'} issue"
|
|
196
|
+
print(f"{plural(len(ranked), kind, kind + 's')}: {triage.group_line(ranked)}")
|
|
197
|
+
text, _ = triage.overview_table(ranked, top=len(shown))
|
|
198
|
+
print(text)
|
|
199
|
+
first = (f"zyonix issues show {ranked[0]['id']}",
|
|
200
|
+
f"ISS-{ranked[0]['id']} first: what failed, why, and its next step") if ranked \
|
|
201
|
+
else ("zyonix issues show <n>", "root cause, evidence and the next step of one issue")
|
|
202
|
+
hints = [first,
|
|
203
|
+
("zyonix issues --detail", "ERROR / ROOT CAUSE / FIX for each issue"),
|
|
204
|
+
("zyonix issues --verbose", "every issue in one table")]
|
|
205
|
+
if out["review_open"]:
|
|
206
|
+
hints.append(("zyonix review list", f"{out['review_open']} uncertain finding(s) to decide"))
|
|
207
|
+
print(next_steps(hints))
|
|
208
|
+
return 0
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def cmd_show(client: ApiClient, args: argparse.Namespace) -> int:
|
|
212
|
+
i = client.get(f"/v1/issues/{args.issue}")
|
|
213
|
+
ev = client.get(f"/v1/issues/{args.issue}/evidence")
|
|
214
|
+
if emit(args, {"issue": i, "evidence": ev}):
|
|
215
|
+
return 0
|
|
216
|
+
if getattr(args, "verbose", False):
|
|
217
|
+
return _show_full(client, i, ev)
|
|
218
|
+
return _show_brief(client, i, ev)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _error_label(pf: dict[str, Any]) -> str:
|
|
222
|
+
"""How the failure was established: by a deterministic check, a person, or not yet."""
|
|
223
|
+
if not pf:
|
|
224
|
+
return ""
|
|
225
|
+
if pf.get("verdict") == "uncertain":
|
|
226
|
+
return "(not verified: a person decides whether it is wrong)"
|
|
227
|
+
return {"T7": "(reported by a person)",
|
|
228
|
+
"T4": "(observed: differs from the known correct value)"}.get(
|
|
229
|
+
pf.get("tier") or "", "(observed: a deterministic check failed)")
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _show_brief(client: ApiClient, i: dict[str, Any], ev: dict[str, Any]) -> int:
|
|
233
|
+
"""The issue brief: state and lifecycle, what failed, why (and how sure), the fix, who acts
|
|
234
|
+
next. Every statement is a stored field; ``--verbose`` prints every section in full."""
|
|
235
|
+
kind = explain.key_kind(client)
|
|
236
|
+
st, n = i["status"], i["id"]
|
|
237
|
+
pf = ev.get("primary_finding") or {}
|
|
238
|
+
rc = i.get("root_cause") or {}
|
|
239
|
+
|
|
240
|
+
# -- header: what, where it stands, who it waits for
|
|
241
|
+
print(term.paint(f"ISS-{n}", "head") + " "
|
|
242
|
+
+ brief._printable(i.get("heading") or i.get("title") or i["check"]))
|
|
243
|
+
share = (f" ({ev['pct']:.1f}% of {ev['runs_checked']} checked)"
|
|
244
|
+
if ev.get("runs_checked") else "")
|
|
245
|
+
seen = ago(i.get("last_seen"))
|
|
246
|
+
print(explain.fold_text(" ".join(x for x in (
|
|
247
|
+
badge(st), f"severity {badge(i.get('severity') or '-')}",
|
|
248
|
+
plural(i.get("member_count") or 0, "run") + share,
|
|
249
|
+
f"last seen {seen}" if seen else "") if x), indent=2, hang=2))
|
|
250
|
+
print(explain.progression(st))
|
|
251
|
+
print(kv([("Waiting for", _waiting(i)), ("Moves on to", _advance(i))], fold=True))
|
|
252
|
+
|
|
253
|
+
# -- ERROR: the observed failure (a check result, not a diagnosis)
|
|
254
|
+
print("\n" + term.paint("ERROR", "bad") + (" " + _error_label(pf) if pf else ""))
|
|
255
|
+
print(wrap(explain.check_sentence(i["check"], i.get("field"))))
|
|
256
|
+
tier = f" ({pf['tier']}, {explain.tier_name(pf['tier'])})" if pf.get("tier") else ""
|
|
257
|
+
detail = f": {brief._printable(pf['detail'])}" if pf.get("detail") else ""
|
|
258
|
+
print(wrap(f"Check {i['check']}{tier} failed{detail}"))
|
|
259
|
+
if pf.get("verdict"):
|
|
260
|
+
note = ""
|
|
261
|
+
if pf["verdict"] == "uncertain":
|
|
262
|
+
note = ("; a grounding finding is never confirmed automatically"
|
|
263
|
+
if pf.get("tier") == "T3" else "")
|
|
264
|
+
if st == "DETECTED":
|
|
265
|
+
note += "; decide it with `zyonix review list` (admin key)"
|
|
266
|
+
print(wrap(f"Verdict: {pf['verdict']}{note}"))
|
|
267
|
+
co = ev.get("co_occurring") or []
|
|
268
|
+
if co:
|
|
269
|
+
print(wrap("Also failing in the same runs: " + ", ".join(
|
|
270
|
+
f"{c['check_key']} ({c['runs']})" for c in co[:4])))
|
|
271
|
+
|
|
272
|
+
# -- ROOT CAUSE: the diagnosis, with how sure it is
|
|
273
|
+
lines, certainty = brief.cause_text(rc)
|
|
274
|
+
print("\n" + term.paint("ROOT CAUSE", "warn") + f" ({certainty})")
|
|
275
|
+
print(wrap(lines[0]))
|
|
276
|
+
if certainty != "insufficient evidence":
|
|
277
|
+
label = "/".join(x for x in (rc.get("category"), rc.get("subtype")) if x)
|
|
278
|
+
where = f" at step {rc['step']}" if rc.get("step") else ""
|
|
279
|
+
conf = f"; confidence {rc['confidence']}" if rc.get("confidence") else ""
|
|
280
|
+
print(wrap(f"Diagnosis: {label}{where}{conf}"))
|
|
281
|
+
chain = ev.get("chain") or []
|
|
282
|
+
if chain:
|
|
283
|
+
e = chain[0]
|
|
284
|
+
snippet = f" `{e['snippet']}`" if e.get("snippet") not in (None, "") else ""
|
|
285
|
+
more = f" (+{len(chain) - 1} more step(s) in --verbose)" if len(chain) > 1 else ""
|
|
286
|
+
print(wrap(f"Evidence: [{e.get('step') or 'run'}] {e['what']}{snippet} -> "
|
|
287
|
+
f"{e['result']}{more}"))
|
|
288
|
+
change = ev.get("recent_change")
|
|
289
|
+
if change:
|
|
290
|
+
print(wrap(f"Recent change: {change['attribute']} changed from "
|
|
291
|
+
f"{short_hash(change.get('previous'))} to {short_hash(change.get('value'))} "
|
|
292
|
+
f"(first seen {when(change.get('first_seen'))}). It coincides with the "
|
|
293
|
+
"failures; that alone does not prove it caused them."))
|
|
294
|
+
incidents = i.get("incidents") or []
|
|
295
|
+
if incidents:
|
|
296
|
+
print(wrap(f"Provider incidents: {len(incidents)} (failures through the same "
|
|
297
|
+
f"provider/model within {incidents[0]['gap_s']:g} s count as one)"))
|
|
298
|
+
|
|
299
|
+
# -- FIX: what is recommended, and what exists
|
|
300
|
+
print("\n" + term.paint("FIX", "good"))
|
|
301
|
+
action = [brief._printable(ev["action"])] if ev.get("action") and \
|
|
302
|
+
certainty != "insufficient evidence" else []
|
|
303
|
+
suggested = brief._suggestions(client, f"/v1/issues/{n}/suggestions")
|
|
304
|
+
recommended = brief.merge_recommended(action + suggested, certainty)
|
|
305
|
+
for r in recommended:
|
|
306
|
+
print(explain.fold_text(f"Recommended (not applied): {r}", indent=2, hang=4))
|
|
307
|
+
_brief_fix(i)
|
|
308
|
+
cases = ev.get("cases") or []
|
|
309
|
+
if cases:
|
|
310
|
+
print(wrap(f"Regression cases: {len(cases)} (zyonix test runs them; a fix must keep "
|
|
311
|
+
"them passing)"))
|
|
312
|
+
for b in (i.get("case_blockers") or [])[:2]:
|
|
313
|
+
print(wrap(f"Not frozen into a case: run {b['run_id'][:12]}: {b['detail']}"))
|
|
314
|
+
|
|
315
|
+
# -- Next: the commands for this state, with the key each needs
|
|
316
|
+
steps = issue_next(i)
|
|
317
|
+
if suggested and steps and steps[0][0].startswith("zyonix fix propose"):
|
|
318
|
+
steps.insert(0, (f"zyonix fix suggest --issue {n} --out zyonix-fixes",
|
|
319
|
+
"write Zyonix's suggested fix as files, to preview and propose"))
|
|
320
|
+
steps.append((f"zyonix issues show {n} --verbose", "the full evidence: chain, examples, "
|
|
321
|
+
"cases, Guard, fixes, lifecycle events"))
|
|
322
|
+
print(next_steps(explain.annotate(steps[:4], kind)))
|
|
323
|
+
return 0
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def _latest_fix(i: dict[str, Any]) -> dict[str, Any] | None:
|
|
327
|
+
fixes = [f for f in i.get("fixes") or [] if f.get("status") != "superseded"]
|
|
328
|
+
return fixes[-1] if fixes else None
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
# FIX_PENDING holds three situations; the newest fix tells them apart
|
|
332
|
+
_FIX_ENDED = {"failed": "the last fix failed verification",
|
|
333
|
+
"rejected": "the last fix was rejected"}
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _waiting(i: dict[str, Any]) -> str:
|
|
337
|
+
fix = _latest_fix(i)
|
|
338
|
+
if i["status"] == "FIX_PENDING" and fix and fix.get("status") in _FIX_ENDED:
|
|
339
|
+
return (f"a person with an admin key to propose a different fix "
|
|
340
|
+
f"({_FIX_ENDED[fix['status']]})")
|
|
341
|
+
return explain.WAITING.get(i["status"], i["status"])
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def _advance(i: dict[str, Any]) -> str:
|
|
345
|
+
m = i.get("monitoring") or {}
|
|
346
|
+
if i["status"] == "MONITORING" and m.get("mitigated"):
|
|
347
|
+
return ("never resolves automatically: the Guard mitigates it, so a root fix is needed "
|
|
348
|
+
f"(zyonix issues reopen {i['id']}, admin key)")
|
|
349
|
+
fix = _latest_fix(i)
|
|
350
|
+
if i["status"] == "FIX_PENDING" and fix and fix.get("status") in _FIX_ENDED:
|
|
351
|
+
return "VERIFYING once a new fix is proposed and `zyonix replay --fix` starts"
|
|
352
|
+
return explain.ADVANCE.get(i["status"], "-")
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _brief_fix(i: dict[str, Any]) -> None:
|
|
356
|
+
"""The newest fix that is not superseded, with its scorecard; monitoring progress."""
|
|
357
|
+
fixes = [f for f in i.get("fixes") or [] if f.get("status") != "superseded"]
|
|
358
|
+
if not fixes:
|
|
359
|
+
print(wrap("Current fix: none proposed yet."))
|
|
360
|
+
else:
|
|
361
|
+
f = fixes[-1] # the newest (rows come ordered by id)
|
|
362
|
+
state = brief.FIX_STATE.get(f.get("status"), f.get("status") or "?")
|
|
363
|
+
print(wrap(f"Current fix: #{f['id']} ({f['kind']}) {state}. "
|
|
364
|
+
f"{brief._printable(f.get('title') or '')}".rstrip()))
|
|
365
|
+
replay = f.get("replay") or {}
|
|
366
|
+
report = replay.get("report") or {}
|
|
367
|
+
if report.get("sets"):
|
|
368
|
+
for line in verify_view.scorecard({**report, "passed": replay.get("passed")},
|
|
369
|
+
indent=4, overall=verify_view.gate_word(replay)):
|
|
370
|
+
print(line)
|
|
371
|
+
if len(fixes) > 1:
|
|
372
|
+
print(wrap(f"{len(fixes) - 1} earlier fix(es): zyonix issues show {i['id']} "
|
|
373
|
+
"--verbose"))
|
|
374
|
+
m = i.get("monitoring")
|
|
375
|
+
if m:
|
|
376
|
+
need = []
|
|
377
|
+
if m["eligible_runs"] < m["min_runs"]:
|
|
378
|
+
need.append(f"{m['min_runs'] - m['eligible_runs']} more run(s)")
|
|
379
|
+
if m["days"] < m["min_days"]:
|
|
380
|
+
need.append(f"{m['min_days'] - m['days']:.1f} more day(s)")
|
|
381
|
+
recur = m["delivered_recurrences"] + m["raw_recurrences"]
|
|
382
|
+
print(wrap(f"Monitoring: {m['eligible_runs']} of {m['min_runs']} runs and "
|
|
383
|
+
f"{m['days']:.1f} of {m['min_days']:g} days since the deploy, "
|
|
384
|
+
f"{recur} recurrence(s)."
|
|
385
|
+
+ (" Mitigated by the Guard: it does not resolve on its own."
|
|
386
|
+
if m.get("mitigated") else
|
|
387
|
+
f" Resolves automatically after {' and '.join(need)} without a "
|
|
388
|
+
"recurrence." if need and not recur else "")))
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def _show_full(client: ApiClient, i: dict[str, Any], ev: dict[str, Any]) -> int:
|
|
392
|
+
"""`zyonix issues show <n> --verbose`: every section, as the command printed it before
|
|
393
|
+
the brief became the default."""
|
|
394
|
+
rc = i["root_cause"]
|
|
395
|
+
print(f"ISS-{i['id']} [{badge(i['status'])}] {i['title']}")
|
|
396
|
+
print(kv([
|
|
397
|
+
("severity", badge(i["severity"])),
|
|
398
|
+
("runs affected", f"{i['member_count']} ({ev['pct']:.1f}% of "
|
|
399
|
+
f"{ev['runs_checked']} checked)"),
|
|
400
|
+
("first / last seen", f"{when(i['first_seen'])} / {when(i['last_seen'])}"
|
|
401
|
+
+ (f" (last {ago(i['last_seen'])})" if ago(i["last_seen"]) else "")),
|
|
402
|
+
("check", i["check"] + (f" on field {i['field']}" if i["field"] else "")
|
|
403
|
+
+ (f" ({ev['primary_finding']['tier']}, {ev['primary_finding']['verdict']})"
|
|
404
|
+
if ev["primary_finding"] else "")),
|
|
405
|
+
("detail", ev["primary_finding"]["detail"] if ev["primary_finding"] else None),
|
|
406
|
+
("also failing", ", ".join(f"{c['check_key']} ({c['runs']})" for c in ev["co_occurring"])
|
|
407
|
+
or None),
|
|
408
|
+
("fingerprint", i["fingerprint"]),
|
|
409
|
+
]))
|
|
410
|
+
print(heading(f"Root cause: {cause(i)} (confidence {rc['confidence'] or 'medium'})"))
|
|
411
|
+
incidents = i.get("incidents") or []
|
|
412
|
+
if incidents:
|
|
413
|
+
gap = incidents[0]["gap_s"]
|
|
414
|
+
print(f" provider incidents: {len(incidents)} (runs failing through the same "
|
|
415
|
+
f"provider/model within {gap:g} s of each other are one incident)")
|
|
416
|
+
for inc in incidents[:8]:
|
|
417
|
+
print(f" #{inc['id']} {inc['runs']} run(s) {when(inc['first_at'], True)} to "
|
|
418
|
+
f"{when(inc['last_at'], True)} ({inc['span_s']:g} s) "
|
|
419
|
+
f"{clip(', '.join(inc['providers']), 60)}")
|
|
420
|
+
if len(incidents) > 8:
|
|
421
|
+
print(f" ... {len(incidents) - 8} more (--json for all)")
|
|
422
|
+
if rc["modifiers"]:
|
|
423
|
+
print(f" modifiers: {', '.join(rc['modifiers'])}")
|
|
424
|
+
change = ev["recent_change"]
|
|
425
|
+
if change:
|
|
426
|
+
print(f" RECENT_CHANGE: {change['attribute']} changed from {clip(change['previous'], 23)}"
|
|
427
|
+
f" to {clip(change['value'], 23)} (first seen {when(change['first_seen'])})")
|
|
428
|
+
print(" evidence chain:")
|
|
429
|
+
for n, e in enumerate(ev["chain"], 1):
|
|
430
|
+
snippet = f" `{e['snippet']}`" if e.get("snippet") not in (None, "") else ""
|
|
431
|
+
print(f" {n}. [{e.get('step') or 'run'}] {e['what']}{snippet} -> {e['result']}")
|
|
432
|
+
if not ev["chain"]:
|
|
433
|
+
print(" (no evidence chain stored)")
|
|
434
|
+
print(heading("What distinguishes the failing runs"))
|
|
435
|
+
if ev["differential"]:
|
|
436
|
+
for d in ev["differential"]:
|
|
437
|
+
print(f" {d['attribute']}={clip(d['value'], 23)}: {d['fail_share']:.0%} of failures "
|
|
438
|
+
f"vs {d['pass_share']:.0%} of passes")
|
|
439
|
+
else:
|
|
440
|
+
print(" no single attribute separates the failing runs from the passing ones")
|
|
441
|
+
print(heading("Examples"))
|
|
442
|
+
for x in ev["examples"]:
|
|
443
|
+
print(f" run {x['run_id'][:12]} doc {x['doc_id'] or '-'} (zyonix runs show "
|
|
444
|
+
f"{x['run_id'][:12]})")
|
|
445
|
+
if x.get("output_snippet"):
|
|
446
|
+
print(f" output: {x['output_snippet']}")
|
|
447
|
+
if x.get("source_snippet"):
|
|
448
|
+
print(f" source: {x['source_snippet']}")
|
|
449
|
+
print(heading("Regression cases"))
|
|
450
|
+
if ev["cases"]:
|
|
451
|
+
print(table(["CASE", "RUN", "DOC", "SUITE", "REASON", "ASSERTS", "EXPECTED"], [
|
|
452
|
+
(f"RC-{c['id']}", c["run_id"][:12], c["doc_id"], c["suite"], c["reason"],
|
|
453
|
+
", ".join(c["assertions"]), "known" if c["expected_known"] else "-")
|
|
454
|
+
for c in ev["cases"]], indent=2, max_col=40))
|
|
455
|
+
else:
|
|
456
|
+
print(" none yet")
|
|
457
|
+
for b in i.get("case_blockers") or []:
|
|
458
|
+
print(wrap(f"not frozen: run {b['run_id'][:12]} (doc {b['doc_id'] or '-'}): "
|
|
459
|
+
f"{b['detail']}", indent=2))
|
|
460
|
+
g = i["guard"]
|
|
461
|
+
print(heading("Raw vs delivered"))
|
|
462
|
+
print(wrap(f"{g['raw']} raw failure(s) of {i['check']} in {g['total_runs']} live run(s) "
|
|
463
|
+
f"({pct(g['raw_rate'])}) -> {g['delivered']} delivered "
|
|
464
|
+
f"({pct(g['delivered_rate'])}); "
|
|
465
|
+
f"{g['repaired']} repaired by the Guard before delivery. "
|
|
466
|
+
+ (f"Eligible strategies: {', '.join(i['eligible_strategies'])}."
|
|
467
|
+
if i["eligible_strategies"] else "No inline repair applies (R0: escalate).")))
|
|
468
|
+
_print_fixes(i)
|
|
469
|
+
print_suggestions(client, f"/v1/issues/{i['id']}/suggestions", f"--issue {i['id']}")
|
|
470
|
+
_print_monitoring(i)
|
|
471
|
+
print(heading("Recommended action"))
|
|
472
|
+
print(wrap(ev["action"]))
|
|
473
|
+
print(heading("Lifecycle"))
|
|
474
|
+
print(table(["WHEN", "FROM", "TO", "ACTOR", "REASON"], [
|
|
475
|
+
(when(e["at"], True), e["from"], e["to"], e["actor"], e["reason"]) for e in i["events"]],
|
|
476
|
+
indent=2, max_col=60))
|
|
477
|
+
print(next_steps(issue_next(i) + [(f"zyonix issues report {i['id']}", "Markdown report")]))
|
|
478
|
+
return 0
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def print_suggestions(client: ApiClient, path: str, target: str) -> None:
|
|
482
|
+
"""Fix candidates Zyonix derives from the findings (nothing is applied)."""
|
|
483
|
+
try:
|
|
484
|
+
sugg = client.get(path)["suggestions"]
|
|
485
|
+
except CliError:
|
|
486
|
+
return # a server from before fix suggestions
|
|
487
|
+
if not sugg:
|
|
488
|
+
return
|
|
489
|
+
print(heading("Suggested fixes (derived from the evidence; nothing is applied)"))
|
|
490
|
+
for n, s in enumerate(sugg, 1):
|
|
491
|
+
how = ("needs a code change in the application" if s["needs_code_change"]
|
|
492
|
+
else "replay-verifiable")
|
|
493
|
+
print(wrap(f"{n}. [{s['kind']}] {s['title']} ({how})", indent=2))
|
|
494
|
+
print(wrap(f"patch: {s['patch']}", indent=5))
|
|
495
|
+
for line in [x for x in s.get("evidence") or [] if x][:3]:
|
|
496
|
+
print(wrap(f"evidence: {line}", indent=5))
|
|
497
|
+
print(wrap(f"Write them as files for `zyonix replay --local` / `zyonix fix propose`: "
|
|
498
|
+
f"zyonix fix suggest {target} --out <dir>", indent=2))
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def _print_fixes(i: dict[str, Any]) -> None:
|
|
502
|
+
print(heading("Fix proposals"))
|
|
503
|
+
if i["recurrence"]:
|
|
504
|
+
r = i["recurrence"]
|
|
505
|
+
print(f" deployed {when(r['deployed_at'])} ({r['source']}, marker #{r['marker_id']}): "
|
|
506
|
+
f"{r['failures']} recurrence(s) in {r['eligible_runs']} run(s) since "
|
|
507
|
+
+ (f"({pct(r['rate'])})" if r.get("rate") is not None else ""))
|
|
508
|
+
if not i["fixes"]:
|
|
509
|
+
print(" none")
|
|
510
|
+
for f in i["fixes"]:
|
|
511
|
+
print(f"\n Fix #{f['id']} {f['kind']} [{badge(f['status'])}] {f['title']} "
|
|
512
|
+
f"(by {f['author']})")
|
|
513
|
+
if f["description"]:
|
|
514
|
+
print(wrap(f["description"], indent=4))
|
|
515
|
+
print(f" candidate: {jdump(f['candidate'])}")
|
|
516
|
+
if f["approved_by"]:
|
|
517
|
+
print(f" decided by: {f['approved_by']}")
|
|
518
|
+
rep = (f.get("replay") or {}).get("report") or {}
|
|
519
|
+
if rep.get("sets"):
|
|
520
|
+
a, b, c = (rep["sets"][k] for k in ("issue", "suite", "golden"))
|
|
521
|
+
print(f" replay run #{f['replay_run_id']} (k={f['replay']['k']}):")
|
|
522
|
+
print(f" set A (issue cases) {a['fixed']}/{a['reproduced']} reproduced "
|
|
523
|
+
"failing cases fixed"
|
|
524
|
+
+ (f"; {len(a['not_reproduced'])} did not reproduce"
|
|
525
|
+
if a["not_reproduced"] else ""))
|
|
526
|
+
print(f" set B (regression suite) {len(b['new_failures'])} new failure(s) in "
|
|
527
|
+
f"{b['cases']} case(s)")
|
|
528
|
+
acc = (f"{c['baseline_accuracy']:.1%} -> {c['candidate_accuracy']:.1%}"
|
|
529
|
+
if c["baseline_accuracy"] is not None and c["candidate_accuracy"] is not None
|
|
530
|
+
else "n/a")
|
|
531
|
+
print(f" set C (golden) accuracy {acc} ({c['cases']} case(s))")
|
|
532
|
+
if rep.get("unstable"):
|
|
533
|
+
print(f" unstable {len(rep['unstable'])} case(s)")
|
|
534
|
+
d = rep.get("dry_run")
|
|
535
|
+
if d:
|
|
536
|
+
print(f" dry-run evidence {d['strategy']}: {d['verified']}/"
|
|
537
|
+
f"{d['attempts']} live attempts VERIFIED, {d['unverified']} unverified")
|
|
538
|
+
verdict = "PASSED" if f["replay"]["passed"] else "FAILED"
|
|
539
|
+
print(f" verification {badge(verdict)}")
|
|
540
|
+
for reason in rep.get("reasons", []):
|
|
541
|
+
print(f" x {reason}")
|
|
542
|
+
perf_view.print_lines(rep, indent=6)
|
|
543
|
+
elif f["status"] == "proposed" and f["kind"] != "code_note":
|
|
544
|
+
print(f" not verified yet: zyonix replay --fix {f['id']}")
|
|
545
|
+
elif f["kind"] == "code_note":
|
|
546
|
+
print(" a code note is not replay-verifiable in the pilot")
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def _print_monitoring(i: dict[str, Any]) -> None:
|
|
550
|
+
m = i["monitoring"]
|
|
551
|
+
if not m:
|
|
552
|
+
return
|
|
553
|
+
print(heading("Monitoring"))
|
|
554
|
+
print(wrap(f"Fix #{m['fix_id']} ({m['fix_kind']}) deployed {when(m['deployed_at'])}: "
|
|
555
|
+
f"{m['eligible_runs']}/{m['min_runs']} eligible runs, {m['days']:.1f}/"
|
|
556
|
+
f"{m['min_days']:.0f} days, {m['delivered_recurrences']} delivered and "
|
|
557
|
+
f"{m['raw_recurrences']} repaired-before-delivery recurrence(s)."))
|
|
558
|
+
if m["mitigated"]:
|
|
559
|
+
print(wrap("Mitigated by the Guard: a root fix must pass the loop before this can "
|
|
560
|
+
f"resolve (zyonix issues reopen {i['id']} --reason \"...\")."))
|
|
561
|
+
elif i["status"] == "MONITORING":
|
|
562
|
+
print(wrap("Resolves automatically at 0 recurrences in both thresholds; any recurrence "
|
|
563
|
+
"reopens it with a new regression case."))
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
def cmd_context(client: ApiClient, args: argparse.Namespace) -> int:
|
|
567
|
+
"""JSON by default: this command is the one coding agents read, so --json is the default
|
|
568
|
+
and --text is the exception (the other read commands are the other way round)."""
|
|
569
|
+
doc = client.get(f"/v1/issues/{args.issue}/context", max_bytes=args.max_bytes)
|
|
570
|
+
if args.text:
|
|
571
|
+
print(context_text(doc))
|
|
572
|
+
else:
|
|
573
|
+
print_json(doc)
|
|
574
|
+
return 0
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
def cmd_report(client: ApiClient, args: argparse.Namespace) -> int:
|
|
578
|
+
text = client.get_text(f"/v1/issues/{args.issue}/report.md")
|
|
579
|
+
if args.out:
|
|
580
|
+
try:
|
|
581
|
+
Path(args.out).write_text(text, encoding="utf-8")
|
|
582
|
+
except OSError as exc:
|
|
583
|
+
raise CliError(f"cannot write {args.out}: {exc}") from None
|
|
584
|
+
print(f"report written to {args.out}")
|
|
585
|
+
else:
|
|
586
|
+
print(text, end="")
|
|
587
|
+
return 0
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def cmd_reopen(client: ApiClient, args: argparse.Namespace) -> int:
|
|
591
|
+
out = client.post(f"/v1/issues/{args.issue}/reopen", {"reason": args.reason})
|
|
592
|
+
if emit(args, out):
|
|
593
|
+
return 0
|
|
594
|
+
print(f"ISS-{out['issue_id']} reopened -> {out['status']} ({len(out['evidence_runs'])} "
|
|
595
|
+
"evidence run(s) attached)")
|
|
596
|
+
print(next_steps(issue_next({"id": args.issue, "status": "DIAGNOSED", "fixes": []})))
|
|
597
|
+
return 0
|