stackdoctor-cli 1.0.1__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.
- stackdoctor/__init__.py +15 -0
- stackdoctor/__main__.py +6 -0
- stackdoctor/agent/__init__.py +5 -0
- stackdoctor/agent/compaction.py +66 -0
- stackdoctor/agent/diagnosis.py +398 -0
- stackdoctor/agent/loop.py +801 -0
- stackdoctor/agent/prompts.py +85 -0
- stackdoctor/agent/providers/__init__.py +295 -0
- stackdoctor/agent/providers/base.py +210 -0
- stackdoctor/agent/providers/claude.py +285 -0
- stackdoctor/agent/providers/gemini.py +312 -0
- stackdoctor/agent/providers/openai_compat.py +537 -0
- stackdoctor/agent/providers/prices.py +90 -0
- stackdoctor/benchmark/__init__.py +11 -0
- stackdoctor/benchmark/__main__.py +198 -0
- stackdoctor/benchmark/holmes.py +386 -0
- stackdoctor/benchmark/report.py +362 -0
- stackdoctor/benchmark/runner.py +710 -0
- stackdoctor/benchmark/scenarios.py +153 -0
- stackdoctor/benchmark/scoring.py +184 -0
- stackdoctor/cli.py +882 -0
- stackdoctor/dependencies.py +221 -0
- stackdoctor/discovery.py +361 -0
- stackdoctor/evidence.py +134 -0
- stackdoctor/github.py +168 -0
- stackdoctor/live.py +808 -0
- stackdoctor/mcp_server.py +233 -0
- stackdoctor/models.py +275 -0
- stackdoctor/pglog.py +55 -0
- stackdoctor/postgres.py +294 -0
- stackdoctor/probes.py +172 -0
- stackdoctor/py.typed +0 -0
- stackdoctor/redaction.py +215 -0
- stackdoctor/rules.py +303 -0
- stackdoctor/validation.py +61 -0
- stackdoctor_cli-1.0.1.dist-info/METADATA +177 -0
- stackdoctor_cli-1.0.1.dist-info/RECORD +40 -0
- stackdoctor_cli-1.0.1.dist-info/WHEEL +4 -0
- stackdoctor_cli-1.0.1.dist-info/entry_points.txt +3 -0
- stackdoctor_cli-1.0.1.dist-info/licenses/LICENSE +201 -0
stackdoctor/rules.py
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"""Validation rules.
|
|
2
|
+
|
|
3
|
+
A rule is a plain function that takes a discovered, redacted project and
|
|
4
|
+
returns findings. Each finding must cite evidence created with
|
|
5
|
+
`stackdoctor.evidence.make_evidence`. Rules are registered in `ALL_RULES`.
|
|
6
|
+
|
|
7
|
+
Every rule targets a configuration that `docker compose config` accepts but
|
|
8
|
+
that breaks at runtime. See docs/fault-scenarios.md for the catalog. The
|
|
9
|
+
PostgreSQL rules (SD106-SD108) live in `stackdoctor.postgres`.
|
|
10
|
+
Rules stay conservative: when the configuration does not say enough to be
|
|
11
|
+
sure, they report a warning or nothing, rather than guess.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import difflib
|
|
15
|
+
import re
|
|
16
|
+
from collections.abc import Callable, Iterable
|
|
17
|
+
|
|
18
|
+
from stackdoctor.dependencies import HostReference, find_host_references
|
|
19
|
+
from stackdoctor.evidence import make_evidence
|
|
20
|
+
from stackdoctor.models import ComposeProject, EvidenceRef, Finding, Service, Severity
|
|
21
|
+
from stackdoctor.postgres import RULES as POSTGRES_RULES
|
|
22
|
+
from stackdoctor.postgres import is_postgres
|
|
23
|
+
|
|
24
|
+
Rule = Callable[[ComposeProject], Iterable[Finding]]
|
|
25
|
+
|
|
26
|
+
POSTGRES_DEFAULT_PORT = 5432
|
|
27
|
+
_PORT_SPEC = re.compile(r"^(?P<start>\d{1,5})(?:-(?P<end>\d{1,5}))?(?:/\w+)?$")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# --- SD101 -------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def unknown_host(project: ComposeProject) -> Iterable[Finding]:
|
|
34
|
+
"""SD101: a single-label host that no service, alias or container name answers to."""
|
|
35
|
+
names = sorted(_dns_names(project))
|
|
36
|
+
for ref in find_host_references(project.services):
|
|
37
|
+
if ref.category != "unknown":
|
|
38
|
+
continue
|
|
39
|
+
close = difflib.get_close_matches(ref.host, names, n=1, cutoff=0.6)
|
|
40
|
+
yield Finding(
|
|
41
|
+
rule_id="SD101",
|
|
42
|
+
severity=Severity.ERROR,
|
|
43
|
+
title=f'Unknown host "{ref.host}"',
|
|
44
|
+
message=(
|
|
45
|
+
f'{ref.variable} points at "{ref.host}", but no service, network alias or '
|
|
46
|
+
"container name in this project answers to that name, so the lookup fails "
|
|
47
|
+
"inside the container."
|
|
48
|
+
),
|
|
49
|
+
service=ref.source,
|
|
50
|
+
hint=f'Did you mean "{close[0]}"?' if close else None,
|
|
51
|
+
evidence=(_env_evidence(project, ref),),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# --- SD102 -------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def no_shared_network(project: ComposeProject) -> Iterable[Finding]:
|
|
59
|
+
"""SD102: a service refers to another one it shares no network with."""
|
|
60
|
+
services = {service.name: service for service in project.services}
|
|
61
|
+
by_pair: dict[tuple[str, str], list[HostReference]] = {}
|
|
62
|
+
for ref in find_host_references(project.services):
|
|
63
|
+
if ref.category == "service" and ref.target and ref.target != ref.source:
|
|
64
|
+
by_pair.setdefault((ref.source, ref.target), []).append(ref)
|
|
65
|
+
|
|
66
|
+
for (source, target), refs in sorted(by_pair.items()):
|
|
67
|
+
source_net = _networking(services, source)
|
|
68
|
+
target_net = _networking(services, target)
|
|
69
|
+
if source_net is None or target_net is None:
|
|
70
|
+
continue # a network mode StackDoctor does not model
|
|
71
|
+
(source_mode, source_networks), (target_mode, target_networks) = source_net, target_net
|
|
72
|
+
if source_mode == "host":
|
|
73
|
+
reason = f"{source} uses network_mode: host, so it cannot resolve service names"
|
|
74
|
+
elif target_mode != "compose":
|
|
75
|
+
reason = f"{target} uses network_mode: {target_mode}, so it has no service name"
|
|
76
|
+
elif source_mode == "none":
|
|
77
|
+
reason = f"{source} uses network_mode: none, so it has no network at all"
|
|
78
|
+
elif source_networks & target_networks:
|
|
79
|
+
continue
|
|
80
|
+
else:
|
|
81
|
+
reason = f"{source} and {target} are not attached to any common network"
|
|
82
|
+
yield Finding(
|
|
83
|
+
rule_id="SD102",
|
|
84
|
+
severity=Severity.ERROR,
|
|
85
|
+
title=f"{source} cannot reach {target}",
|
|
86
|
+
message=(
|
|
87
|
+
f"{source} refers to {target} ({', '.join(r.variable for r in refs)}), "
|
|
88
|
+
f"but {reason}. The name will not resolve."
|
|
89
|
+
),
|
|
90
|
+
service=source,
|
|
91
|
+
hint=f"Attach {source} and {target} to a shared network.",
|
|
92
|
+
evidence=(
|
|
93
|
+
*(_env_evidence(project, ref) for ref in refs),
|
|
94
|
+
_network_evidence(project, services[source]),
|
|
95
|
+
_network_evidence(project, services[target]),
|
|
96
|
+
),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# --- SD103 -------------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def host_port_used_internally(project: ComposeProject) -> Iterable[Finding]:
|
|
104
|
+
"""SD103: a reference uses a port the target does not listen on inside the network."""
|
|
105
|
+
services = {service.name: service for service in project.services}
|
|
106
|
+
for ref in find_host_references(project.services):
|
|
107
|
+
if ref.category != "service" or ref.target is None or ref.port is None:
|
|
108
|
+
continue
|
|
109
|
+
target = services[ref.target]
|
|
110
|
+
container_ports = _container_ports(target)
|
|
111
|
+
if ref.port in container_ports:
|
|
112
|
+
continue
|
|
113
|
+
published = [
|
|
114
|
+
index
|
|
115
|
+
for index, mapping in enumerate(target.ports)
|
|
116
|
+
if mapping.published == str(ref.port)
|
|
117
|
+
]
|
|
118
|
+
if published:
|
|
119
|
+
mapping = target.ports[published[0]]
|
|
120
|
+
yield Finding(
|
|
121
|
+
rule_id="SD103",
|
|
122
|
+
severity=Severity.ERROR,
|
|
123
|
+
title=f"{ref.target}:{ref.port} is a host port",
|
|
124
|
+
message=(
|
|
125
|
+
f"{ref.variable} connects to {ref.target}:{ref.port}, but {ref.port} is the "
|
|
126
|
+
f"port {ref.target} publishes on the host. Other containers reach "
|
|
127
|
+
f"{ref.target} directly on its container port, {mapping.target}."
|
|
128
|
+
),
|
|
129
|
+
service=ref.source,
|
|
130
|
+
hint=f"Use {ref.target}:{mapping.target}.",
|
|
131
|
+
evidence=(
|
|
132
|
+
_env_evidence(project, ref),
|
|
133
|
+
make_evidence(project, "services", ref.target, "ports", published[0]),
|
|
134
|
+
),
|
|
135
|
+
)
|
|
136
|
+
elif is_postgres(target):
|
|
137
|
+
yield Finding(
|
|
138
|
+
rule_id="SD103",
|
|
139
|
+
severity=Severity.WARNING,
|
|
140
|
+
title=f"{ref.target} probably does not listen on {ref.port}",
|
|
141
|
+
message=(
|
|
142
|
+
f"{ref.variable} connects to {ref.target}:{ref.port}, but {ref.target} runs "
|
|
143
|
+
f"PostgreSQL, which listens on {POSTGRES_DEFAULT_PORT} unless configured "
|
|
144
|
+
"otherwise, and the Compose file declares no other port for it."
|
|
145
|
+
),
|
|
146
|
+
service=ref.source,
|
|
147
|
+
hint=f"Use {ref.target}:{POSTGRES_DEFAULT_PORT}, or declare the port it uses.",
|
|
148
|
+
evidence=(
|
|
149
|
+
_env_evidence(project, ref),
|
|
150
|
+
make_evidence(project, "services", ref.target, "image"),
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# --- SD104 -------------------------------------------------------------------------
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def localhost_reference(project: ComposeProject) -> Iterable[Finding]:
|
|
159
|
+
"""SD104: a service connects to localhost, which inside a container is itself."""
|
|
160
|
+
services = {service.name: service for service in project.services}
|
|
161
|
+
for ref in find_host_references(project.services):
|
|
162
|
+
if ref.category != "loopback":
|
|
163
|
+
continue
|
|
164
|
+
mode = services[ref.source].network_mode or ""
|
|
165
|
+
# With host networking, or a shared network namespace (a sidecar),
|
|
166
|
+
# localhost really is the other process.
|
|
167
|
+
if mode == "host" or mode.startswith(("service:", "container:")):
|
|
168
|
+
continue
|
|
169
|
+
candidates = (
|
|
170
|
+
sorted(
|
|
171
|
+
service.name
|
|
172
|
+
for service in project.services
|
|
173
|
+
if service.name != ref.source and ref.port in _container_ports(service)
|
|
174
|
+
)
|
|
175
|
+
if ref.port is not None
|
|
176
|
+
else []
|
|
177
|
+
)
|
|
178
|
+
hint = (
|
|
179
|
+
f"If you meant {candidates[0]}, use {candidates[0]}:{ref.port}."
|
|
180
|
+
if len(candidates) == 1
|
|
181
|
+
else "Use the target service's name instead of localhost."
|
|
182
|
+
)
|
|
183
|
+
yield Finding(
|
|
184
|
+
rule_id="SD104",
|
|
185
|
+
severity=Severity.WARNING,
|
|
186
|
+
title=f"{ref.source} connects to {ref.host}",
|
|
187
|
+
message=(
|
|
188
|
+
f"{ref.variable} points at {ref.host}. Inside the {ref.source} container that "
|
|
189
|
+
f"is {ref.source} itself, not another service."
|
|
190
|
+
),
|
|
191
|
+
service=ref.source,
|
|
192
|
+
hint=hint,
|
|
193
|
+
evidence=(_env_evidence(project, ref),),
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
# --- SD105 -------------------------------------------------------------------------
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def healthy_without_healthcheck(project: ComposeProject) -> Iterable[Finding]:
|
|
201
|
+
"""SD105: depends_on waits for service_healthy, but the target has no healthcheck."""
|
|
202
|
+
services = {service.name: service for service in project.services}
|
|
203
|
+
for service in project.services:
|
|
204
|
+
for dependency in service.depends_on:
|
|
205
|
+
target = services.get(dependency.service)
|
|
206
|
+
if dependency.condition != "service_healthy" or target is None:
|
|
207
|
+
continue
|
|
208
|
+
if target.healthcheck is not None:
|
|
209
|
+
continue
|
|
210
|
+
yield Finding(
|
|
211
|
+
rule_id="SD105",
|
|
212
|
+
severity=Severity.WARNING,
|
|
213
|
+
title=f"{dependency.service} has no healthcheck",
|
|
214
|
+
message=(
|
|
215
|
+
f"{service.name} waits for {dependency.service} to become healthy, but "
|
|
216
|
+
f"{dependency.service} has no healthcheck in the Compose file. Unless its "
|
|
217
|
+
f"image defines one, {service.name} will not start."
|
|
218
|
+
),
|
|
219
|
+
service=service.name,
|
|
220
|
+
hint=(
|
|
221
|
+
f"Add a healthcheck to {dependency.service}, or use condition: service_started."
|
|
222
|
+
),
|
|
223
|
+
evidence=(
|
|
224
|
+
make_evidence(
|
|
225
|
+
project,
|
|
226
|
+
"services",
|
|
227
|
+
service.name,
|
|
228
|
+
"depends_on",
|
|
229
|
+
dependency.service,
|
|
230
|
+
"condition",
|
|
231
|
+
),
|
|
232
|
+
make_evidence(project, "services", dependency.service, "healthcheck"),
|
|
233
|
+
),
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
ALL_RULES: tuple[Rule, ...] = (
|
|
238
|
+
unknown_host,
|
|
239
|
+
no_shared_network,
|
|
240
|
+
host_port_used_internally,
|
|
241
|
+
localhost_reference,
|
|
242
|
+
healthy_without_healthcheck,
|
|
243
|
+
*POSTGRES_RULES,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
# --- Helpers -----------------------------------------------------------------------
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _env_evidence(project: ComposeProject, ref: HostReference) -> EvidenceRef:
|
|
251
|
+
return make_evidence(project, "services", ref.source, "environment", ref.variable)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _network_evidence(project: ComposeProject, service: Service) -> EvidenceRef:
|
|
255
|
+
field = "network_mode" if service.network_mode else "networks"
|
|
256
|
+
return make_evidence(project, "services", service.name, field)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def _dns_names(project: ComposeProject) -> set[str]:
|
|
260
|
+
names: set[str] = set()
|
|
261
|
+
for service in project.services:
|
|
262
|
+
names.add(service.name)
|
|
263
|
+
if service.container_name:
|
|
264
|
+
names.add(service.container_name)
|
|
265
|
+
for aliases in service.network_aliases.values():
|
|
266
|
+
names.update(aliases)
|
|
267
|
+
return names
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def _networking(services: dict[str, Service], name: str) -> tuple[str, frozenset[str]] | None:
|
|
271
|
+
"""How a service is networked, following `network_mode: service:<x>`.
|
|
272
|
+
|
|
273
|
+
Returns ("compose", networks) for normal Compose networking, ("host", {})
|
|
274
|
+
or ("none", {}) for those modes, and None for anything not modeled (for
|
|
275
|
+
example `container:<id>`, or a `service:` loop).
|
|
276
|
+
"""
|
|
277
|
+
seen: set[str] = set()
|
|
278
|
+
while name in services and name not in seen:
|
|
279
|
+
seen.add(name)
|
|
280
|
+
mode = services[name].network_mode
|
|
281
|
+
if mode is None:
|
|
282
|
+
return "compose", frozenset(services[name].networks)
|
|
283
|
+
if mode in ("host", "none"):
|
|
284
|
+
return mode, frozenset()
|
|
285
|
+
if not mode.startswith("service:"):
|
|
286
|
+
return None
|
|
287
|
+
name = mode.removeprefix("service:")
|
|
288
|
+
return None
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def _container_ports(service: Service) -> set[int]:
|
|
292
|
+
ports = {mapping.target for mapping in service.ports}
|
|
293
|
+
for spec in service.expose:
|
|
294
|
+
match = _PORT_SPEC.match(spec)
|
|
295
|
+
if match:
|
|
296
|
+
start = int(match["start"])
|
|
297
|
+
ports.update(range(start, int(match["end"] or start) + 1))
|
|
298
|
+
if is_postgres(service):
|
|
299
|
+
ports.add(POSTGRES_DEFAULT_PORT)
|
|
300
|
+
pgport = service.environment.get("PGPORT")
|
|
301
|
+
if pgport and pgport.isdigit():
|
|
302
|
+
ports.add(int(pgport))
|
|
303
|
+
return ports
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Configuration validation: run the rules over a discovered project.
|
|
2
|
+
|
|
3
|
+
Deterministic and read-only. It works on the redacted `ComposeProject`, so
|
|
4
|
+
findings, messages and evidence excerpts never contain secret values.
|
|
5
|
+
|
|
6
|
+
The report carries the evidence its findings cite, and every reference is
|
|
7
|
+
resolved again (`check_report`) before the report is returned: a rule that
|
|
8
|
+
cites data that does not exist is a bug, and fails loudly instead of producing
|
|
9
|
+
an unsupported finding.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from collections.abc import Sequence
|
|
13
|
+
|
|
14
|
+
from stackdoctor import rules as rules_module
|
|
15
|
+
from stackdoctor.evidence import check_report, config_item
|
|
16
|
+
from stackdoctor.live import Snapshot, live_findings
|
|
17
|
+
from stackdoctor.models import ComposeProject, Severity, ValidationReport
|
|
18
|
+
from stackdoctor.rules import Rule
|
|
19
|
+
|
|
20
|
+
_SEVERITY_RANK = {Severity.ERROR: 2, Severity.WARNING: 1}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def validate_project(
|
|
24
|
+
project: ComposeProject,
|
|
25
|
+
rules: Sequence[Rule] | None = None,
|
|
26
|
+
*,
|
|
27
|
+
live: Snapshot | None = None,
|
|
28
|
+
) -> ValidationReport:
|
|
29
|
+
"""Run ``rules`` (default: all registered rules) and build a report.
|
|
30
|
+
|
|
31
|
+
With ``live`` (collected by `stackdoctor.live.collect`), the live rules run
|
|
32
|
+
too, and the report carries the live evidence and a summary.
|
|
33
|
+
"""
|
|
34
|
+
active = rules_module.ALL_RULES if rules is None else rules
|
|
35
|
+
static = [finding for rule in active for finding in rule(project)]
|
|
36
|
+
dynamic = live_findings(project, live) if live is not None else []
|
|
37
|
+
findings = sorted(
|
|
38
|
+
(*static, *dynamic),
|
|
39
|
+
key=lambda f: (
|
|
40
|
+
-_SEVERITY_RANK[f.severity],
|
|
41
|
+
f.rule_id,
|
|
42
|
+
f.service or "",
|
|
43
|
+
[str(part) for part in f.evidence[0].path],
|
|
44
|
+
),
|
|
45
|
+
)
|
|
46
|
+
report = ValidationReport(
|
|
47
|
+
project=project.name,
|
|
48
|
+
dependencies=project.dependencies,
|
|
49
|
+
findings=tuple(findings),
|
|
50
|
+
error_count=sum(f.severity is Severity.ERROR for f in findings),
|
|
51
|
+
warning_count=sum(f.severity is Severity.WARNING for f in findings),
|
|
52
|
+
evidence=(config_item(project), *(live.evidence() if live is not None else ())),
|
|
53
|
+
live=live.summary() if live is not None else None,
|
|
54
|
+
)
|
|
55
|
+
check_report(report)
|
|
56
|
+
return report
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def fails(report: ValidationReport, threshold: Severity) -> bool:
|
|
60
|
+
"""Whether the report has a finding at or above ``threshold``."""
|
|
61
|
+
return any(_SEVERITY_RANK[f.severity] >= _SEVERITY_RANK[threshold] for f in report.findings)
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stackdoctor-cli
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: AI-powered integration validation and root cause analysis for containerized applications.
|
|
5
|
+
Author: Hussein Haidar Ahmad
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Software Development :: Testing
|
|
16
|
+
Classifier: Topic :: System :: Monitoring
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Dist: mcp>=2.3.0
|
|
19
|
+
Requires-Dist: pydantic>=2.14.4
|
|
20
|
+
Requires-Dist: typer>=0.29.3
|
|
21
|
+
Requires-Dist: anthropic>=2.14.0 ; extra == 'anthropic'
|
|
22
|
+
Requires-Dist: google-genai>=3.6.1 ; extra == 'gemini'
|
|
23
|
+
Requires-Dist: openai>=3.60.0 ; extra == 'openai'
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Project-URL: Homepage, https://github.com/13husseinH/stackdoctor
|
|
26
|
+
Project-URL: Repository, https://github.com/13husseinH/stackdoctor
|
|
27
|
+
Project-URL: Issues, https://github.com/13husseinH/stackdoctor/issues
|
|
28
|
+
Project-URL: Changelog, https://github.com/13husseinH/stackdoctor/blob/main/CHANGELOG.md
|
|
29
|
+
Provides-Extra: anthropic
|
|
30
|
+
Provides-Extra: gemini
|
|
31
|
+
Provides-Extra: openai
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<picture>
|
|
36
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/13husseinH/stackdoctor/main/docs/assets/stackdoctor-logo-dark.svg">
|
|
37
|
+
<img alt="StackDoctor logo: stacked containers with a heartbeat line" src="https://raw.githubusercontent.com/13husseinH/stackdoctor/main/docs/assets/stackdoctor-logo-light.svg" width="160">
|
|
38
|
+
</picture>
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
<h1 align="center">StackDoctor</h1>
|
|
42
|
+
|
|
43
|
+
<p align="center"><strong>Finds the broken connections between the services of a Docker Compose stack.</strong></p>
|
|
44
|
+
|
|
45
|
+
## Why StackDoctor
|
|
46
|
+
|
|
47
|
+
Every container in your stack reports **healthy**, yet the API can't reach
|
|
48
|
+
PostgreSQL: its connection string points at `localhost` instead of the `db`
|
|
49
|
+
service. Health checks look at one service at a time. The failures that hurt
|
|
50
|
+
most live *between* services: wrong hostnames, services on different
|
|
51
|
+
networks, host ports used inside the network, mismatched database
|
|
52
|
+
credentials.
|
|
53
|
+
|
|
54
|
+
StackDoctor checks those connections:
|
|
55
|
+
|
|
56
|
+
- **Deterministic.** `scan` and `validate` use plain rules, not AI, and need
|
|
57
|
+
no API key. They check the Compose configuration, and with `--live` the
|
|
58
|
+
running containers too.
|
|
59
|
+
- **Read-only.** It never starts, stops or changes your project.
|
|
60
|
+
- **Secrets stay secret.** Passwords, tokens and keys are redacted before
|
|
61
|
+
anything is printed, saved or sent to an AI provider.
|
|
62
|
+
- **Evidence for every finding.** Each finding points at the exact value it
|
|
63
|
+
is based on.
|
|
64
|
+
|
|
65
|
+
<p align="center">
|
|
66
|
+
<img src="https://raw.githubusercontent.com/13husseinH/stackdoctor/main/docs/assets/demo-validate.svg" alt="Terminal output of stackdoctor validate on a project whose DATABASE_URL names the host postgress: error SD101, unknown host, with the hint Did you mean postgres? and the redacted URL as evidence" width="820">
|
|
67
|
+
</p>
|
|
68
|
+
|
|
69
|
+
## Install
|
|
70
|
+
|
|
71
|
+
StackDoctor needs Python 3.12 or later and the Docker CLI with the Compose
|
|
72
|
+
plugin. With [uv](https://docs.astral.sh/uv/), which also installs Python if
|
|
73
|
+
needed:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
uv tool install stackdoctor-cli
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Or from GitHub: `uv tool install "stackdoctor-cli @ git+https://github.com/13husseinH/stackdoctor@v1.0.1"`.
|
|
80
|
+
|
|
81
|
+
## Quickstart
|
|
82
|
+
|
|
83
|
+
Run it in a directory with a `compose.yaml`, or pass the directory:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
stackdoctor scan path/to/project # services, networks and dependencies
|
|
87
|
+
stackdoctor validate path/to/project # integration problems
|
|
88
|
+
stackdoctor validate --live # also check the running containers
|
|
89
|
+
stackdoctor validate --json # the report as JSON
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`validate` exits with code 1 when it finds an error (`--fail-on warning` to
|
|
93
|
+
fail on warnings too), so it fits in CI.
|
|
94
|
+
|
|
95
|
+
## GitHub Action
|
|
96
|
+
|
|
97
|
+
The action runs `validate` in a workflow: findings become annotations on the
|
|
98
|
+
Compose file, a findings table goes to the job summary, and the step fails on
|
|
99
|
+
findings. No AI and no API key.
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
103
|
+
with:
|
|
104
|
+
persist-credentials: false
|
|
105
|
+
- uses: 13husseinH/stackdoctor@v1.0.1 # or a full commit SHA
|
|
106
|
+
with:
|
|
107
|
+
path: deploy # the directory with compose.yaml
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Inputs, outputs and live checks are in the
|
|
111
|
+
[action's documentation](https://github.com/13husseinH/stackdoctor/blob/main/docs/github-action.md).
|
|
112
|
+
|
|
113
|
+
## AI diagnosis (optional)
|
|
114
|
+
|
|
115
|
+
`stackdoctor diagnose` lets an AI agent investigate with the same read-only
|
|
116
|
+
tools and explain the root cause. Every claim must cite evidence StackDoctor
|
|
117
|
+
collected, and the citations are checked in code. Install the extra for your
|
|
118
|
+
provider and set its key:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
uv tool install "stackdoctor-cli[gemini]"
|
|
122
|
+
export STACKDOCTOR_GEMINI_API_KEY=...
|
|
123
|
+
stackdoctor diagnose path/to/project
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
| `--provider` | Extra | API key |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `gemini` (default) | `gemini` | `STACKDOCTOR_GEMINI_API_KEY` |
|
|
129
|
+
| `groq` | `openai` | `STACKDOCTOR_GROQ_API_KEY` |
|
|
130
|
+
| `anthropic` | `anthropic` | `ANTHROPIC_API_KEY` |
|
|
131
|
+
| `ollama` | `openai` | none: a local server |
|
|
132
|
+
| `openai-compatible` | `openai` | the variable named with `--api-key-env` |
|
|
133
|
+
|
|
134
|
+
StackDoctor reads Gemini and Groq keys only from the `STACKDOCTOR_*`
|
|
135
|
+
variables, never from `GEMINI_API_KEY` or `GROQ_API_KEY`. Several extras
|
|
136
|
+
install together, as in `"stackdoctor-cli[gemini,openai]"`.
|
|
137
|
+
|
|
138
|
+
To keep keys in a `.env` file, let uv load it (StackDoctor never reads one
|
|
139
|
+
itself). A variable already set in your shell wins over the file:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
uvx --env-file .env --from "stackdoctor-cli[gemini]" stackdoctor diagnose path/to/project
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Keep that file outside your Compose project's directory, where Compose would
|
|
146
|
+
read it too.
|
|
147
|
+
|
|
148
|
+
Data is redacted before it is sent, but it is sent to the provider you choose;
|
|
149
|
+
with Ollama it stays on your machine. On the Gemini API free tier, Google may
|
|
150
|
+
use what it receives to improve its products. Each run is bounded by tool
|
|
151
|
+
calls, time, tokens and an estimated cost (default $0.10).
|
|
152
|
+
|
|
153
|
+
## Documentation
|
|
154
|
+
|
|
155
|
+
- [Usage](https://github.com/13husseinH/stackdoctor/blob/main/docs/usage.md):
|
|
156
|
+
every command, the rules, the AI diagnosis, the MCP server for Claude,
|
|
157
|
+
HolmesGPT and other clients, and exit codes
|
|
158
|
+
- [Live checks](https://github.com/13husseinH/stackdoctor/blob/main/docs/live-checks.md)
|
|
159
|
+
and [fault scenarios](https://github.com/13husseinH/stackdoctor/blob/main/docs/fault-scenarios.md)
|
|
160
|
+
- [LLM providers](https://github.com/13husseinH/stackdoctor/blob/main/docs/providers.md)
|
|
161
|
+
and [known issues](https://github.com/13husseinH/stackdoctor/blob/main/docs/known-issues.md)
|
|
162
|
+
- [Benchmark results and HolmesGPT comparison](https://github.com/13husseinH/stackdoctor/blob/main/docs/comparison/m6-results.md)
|
|
163
|
+
- [Architecture](https://github.com/13husseinH/stackdoctor/blob/main/docs/architecture.md)
|
|
164
|
+
- [Changelog](https://github.com/13husseinH/stackdoctor/blob/main/CHANGELOG.md),
|
|
165
|
+
[contributing](https://github.com/13husseinH/stackdoctor/blob/main/CONTRIBUTING.md)
|
|
166
|
+
and [security policy](https://github.com/13husseinH/stackdoctor/blob/main/SECURITY.md)
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
[Apache License 2.0](https://github.com/13husseinH/stackdoctor/blob/main/LICENSE).
|
|
171
|
+
StackDoctor contains no third-party source code; its dependencies are
|
|
172
|
+
installed separately under their own licenses (MIT or Apache-2.0). The test
|
|
173
|
+
corpus derived from [docker/awesome-compose](https://github.com/docker/awesome-compose)
|
|
174
|
+
is CC0-1.0 (see [its README](https://github.com/13husseinH/stackdoctor/blob/main/tests/corpus/README.md)).
|
|
175
|
+
StackDoctor is an independent project; it uses
|
|
176
|
+
[HolmesGPT](https://github.com/HolmesGPT/holmesgpt) as an architectural
|
|
177
|
+
reference but contains none of its code.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
stackdoctor/__init__.py,sha256=sU4Ri3IzIzUDK0DUdDsB8Nt66OW4bF3_bjNkNVz2CDk,691
|
|
2
|
+
stackdoctor/__main__.py,sha256=VCaWvCU7pXNC-fEEJ4qT2OAyajzwRcmArShz_1RTbGw,156
|
|
3
|
+
stackdoctor/agent/__init__.py,sha256=tm76JnPBlEXBDZNM_aIjV3HaWCt0ANsQjaM3gZyz3dQ,207
|
|
4
|
+
stackdoctor/agent/compaction.py,sha256=XNgsH_QTs25PBLiuGmDfS9pFf-b6YgF7GC0NJfbvR1Y,2729
|
|
5
|
+
stackdoctor/agent/diagnosis.py,sha256=7Owox6syCs952_AXF3zecoxbM6bO5poF24sDr0s2VJQ,14845
|
|
6
|
+
stackdoctor/agent/loop.py,sha256=1Hbl_FRXxBbppMXuLEDWR44sar1xB0tkiCFvK3N03Fw,33686
|
|
7
|
+
stackdoctor/agent/prompts.py,sha256=2ONh-x6e7eQibSWVcVvbDjxfhRP4WGZxQ1KuKmlGMIY,3841
|
|
8
|
+
stackdoctor/agent/providers/__init__.py,sha256=aNH5EeQN0tBoKVBn5XKwOnIci2yyjgLpA1Sqi6H2UXg,10831
|
|
9
|
+
stackdoctor/agent/providers/base.py,sha256=k26XukF_qVS1AXLCn4UuXJDkJrlfYUcTpcoXDvzY0mo,6521
|
|
10
|
+
stackdoctor/agent/providers/claude.py,sha256=9nb-Bg4_-fdyaM9myxx5mcou8lUo9VoMlgHT-HIjVwU,10534
|
|
11
|
+
stackdoctor/agent/providers/gemini.py,sha256=THIE9w7QHhWSj_mJ4Qdpxd1vvIVsv7tEOg39NKw48Pc,11766
|
|
12
|
+
stackdoctor/agent/providers/openai_compat.py,sha256=-ZnzsMpkvPEysXzYT9Lc2soJm5R-zl3T6QyJEECgYeE,21350
|
|
13
|
+
stackdoctor/agent/providers/prices.py,sha256=3MpONq_Zf1IdV6VbCl4YOR0pCc9U0T3eq-N6XZnn8Ro,3361
|
|
14
|
+
stackdoctor/benchmark/__init__.py,sha256=T5z7fOTFa6FsLEySaaWjHOipULy8BUyZTSMuBbb5B14,453
|
|
15
|
+
stackdoctor/benchmark/__main__.py,sha256=dZFdM-XTyBUE_-R44vRY07z7GfYeFqUgYtldCsEJJT0,7979
|
|
16
|
+
stackdoctor/benchmark/holmes.py,sha256=cphbjbyGlacsDUnb7XLXo33aazctqqbFZf6T83tsCC4,15969
|
|
17
|
+
stackdoctor/benchmark/report.py,sha256=xr9T9acLQZD4ulkUBuj08__K9AQsJ-1gZeP70dqTshQ,13472
|
|
18
|
+
stackdoctor/benchmark/runner.py,sha256=sqX58XRF2MvDB6Xrjh_gVMHrtHKOViLDO8Y_GZ9eD_w,25993
|
|
19
|
+
stackdoctor/benchmark/scenarios.py,sha256=BjrRm6lIkNxz7LL7SR8bklmy6PgebsfadG94uNI4XGQ,6115
|
|
20
|
+
stackdoctor/benchmark/scoring.py,sha256=__ZcoxBlsNXS-3vj29sSG2j_Uu4mk2l4UO5cHOTtr2c,6668
|
|
21
|
+
stackdoctor/cli.py,sha256=z2S5lreTf9p3FwSN81AJFLVB9WwGZxx0Z6dsqL0hgPs,33218
|
|
22
|
+
stackdoctor/dependencies.py,sha256=YdSgdbCh9nrZDSvyEc4DEiK0NhWZz6wV_J2YaVuonDU,8287
|
|
23
|
+
stackdoctor/discovery.py,sha256=RUNv1YfyBeTkJDYYRMrggQDkpt84mUyXDXclX7ZkIwg,13534
|
|
24
|
+
stackdoctor/evidence.py,sha256=PviO2RsA8kb6GyELKbjAd9kMsZ4lE5yfPiDZ7BLNsMM,5164
|
|
25
|
+
stackdoctor/github.py,sha256=_mpUGHZ2sf0C7PDeNUEFcoSpe3o0x_3ehoGs26jKM6U,6199
|
|
26
|
+
stackdoctor/live.py,sha256=oy-wrwlrCwtI6B832uM5sFchjQguDQN4KqVOPi05kjc,31725
|
|
27
|
+
stackdoctor/mcp_server.py,sha256=gFbd4o8iBVMIciNvq1H27UuBQAGgRKqsv40qfB4N3R0,9867
|
|
28
|
+
stackdoctor/models.py,sha256=X0-EKAG7O0jteJ5l28w1RWWzmSrwKK55eCLqmynK5XY,9749
|
|
29
|
+
stackdoctor/pglog.py,sha256=M3hoGKGHdcaplgjcZWjkBTM4OU64ckFDLhg17bedqr4,2175
|
|
30
|
+
stackdoctor/postgres.py,sha256=nDnjHD8TbxJUNBcHnbVVI9aP6R90t_EIaD9lZHbly9A,12709
|
|
31
|
+
stackdoctor/probes.py,sha256=r6c9V-M-jNE4B-kysQPKNH6MYK_pB8vSjD0yy6VyfCM,5974
|
|
32
|
+
stackdoctor/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
33
|
+
stackdoctor/redaction.py,sha256=xg6I8XsroaQ5jT2gaVdufB-4_sChTsHB1SDU6i2zjTk,8487
|
|
34
|
+
stackdoctor/rules.py,sha256=aMsjosQrCdOuA9q4cCudzxh2mYy1zvu6r3DzHfjpxwk,12579
|
|
35
|
+
stackdoctor/validation.py,sha256=ycNJjwu42v9b346gszIuZqvfhvZue2kFg1AZ3jmS5j8,2391
|
|
36
|
+
stackdoctor_cli-1.0.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
37
|
+
stackdoctor_cli-1.0.1.dist-info/WHEEL,sha256=wfHFB5CQ4yOA68LQ_ISeFjKJGxj2GfVzMH9QxkYgrCw,81
|
|
38
|
+
stackdoctor_cli-1.0.1.dist-info/entry_points.txt,sha256=zdj02MEINdCZKTjlnhuKD2DQ5a6yJU2sI9LCErSe4-I,53
|
|
39
|
+
stackdoctor_cli-1.0.1.dist-info/METADATA,sha256=BWqL048hC4MJ3RS_3inaD3cCcV1Fj22CXfboKUftOOM,7901
|
|
40
|
+
stackdoctor_cli-1.0.1.dist-info/RECORD,,
|