forked from Alishahryar1/free-claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnostics.py
More file actions
47 lines (36 loc) · 1.38 KB
/
Copy pathdiagnostics.py
File metadata and controls
47 lines (36 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Managed Claude Code diagnostic classification."""
from dataclasses import dataclass
_BENIGN_STDERR_MARKERS = ("claude.ai connectors are disabled",)
@dataclass(frozen=True, slots=True)
class ManagedClaudeStderrDiagnostics:
"""Classified stderr lines from one managed Claude Code invocation."""
benign_lines: tuple[str, ...]
fatal_lines: tuple[str, ...]
@property
def fatal_text(self) -> str | None:
text = "\n".join(self.fatal_lines).strip()
return text or None
@property
def has_benign(self) -> bool:
return bool(self.benign_lines)
def classify_managed_claude_stderr(
stderr_text: str,
) -> ManagedClaudeStderrDiagnostics:
"""Classify known benign Claude Code diagnostics separately from failures."""
benign_lines: list[str] = []
fatal_lines: list[str] = []
for line in _stderr_lines(stderr_text):
lowered = line.lower()
if any(marker in lowered for marker in _BENIGN_STDERR_MARKERS):
benign_lines.append(line)
else:
fatal_lines.append(line)
return ManagedClaudeStderrDiagnostics(
benign_lines=tuple(benign_lines),
fatal_lines=tuple(fatal_lines),
)
def _stderr_lines(stderr_text: str) -> tuple[str, ...]:
stripped = stderr_text.strip()
if not stripped:
return ()
return tuple(line.strip() for line in stripped.splitlines() if line.strip())