polycheck 0.2.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.
- polycheck/__init__.py +19 -0
- polycheck/cli.py +791 -0
- polycheck/config.py +123 -0
- polycheck/detect.py +151 -0
- polycheck/finding.py +131 -0
- polycheck/initializer.py +333 -0
- polycheck/languages/__init__.py +10 -0
- polycheck/mcp_server.py +994 -0
- polycheck/py.typed +0 -0
- polycheck/registry.py +119 -0
- polycheck/reporters/__init__.py +33 -0
- polycheck/reporters/json_reporter.py +58 -0
- polycheck/reporters/markdown_reporter.py +141 -0
- polycheck/reporters/sarif_reporter.py +114 -0
- polycheck/runner.py +279 -0
- polycheck/session.py +134 -0
- polycheck/tools/__init__.py +10 -0
- polycheck/tools/actionlint.py +66 -0
- polycheck/tools/base.py +449 -0
- polycheck/tools/depcheck.py +96 -0
- polycheck/tools/deptry.py +83 -0
- polycheck/tools/eslint.py +89 -0
- polycheck/tools/gitleaks.py +78 -0
- polycheck/tools/hadolint.py +75 -0
- polycheck/tools/knip.py +84 -0
- polycheck/tools/mypy.py +85 -0
- polycheck/tools/npm_audit.py +74 -0
- polycheck/tools/pip_audit.py +132 -0
- polycheck/tools/ruff.py +80 -0
- polycheck/tools/semgrep.py +80 -0
- polycheck/tools/shellcheck.py +80 -0
- polycheck/tools/sonarless.py +238 -0
- polycheck/tools/tsc.py +77 -0
- polycheck/tools/vulture.py +82 -0
- polycheck/verify.py +288 -0
- polycheck/workflows/__init__.py +76 -0
- polycheck-0.2.0.dist-info/METADATA +614 -0
- polycheck-0.2.0.dist-info/RECORD +42 -0
- polycheck-0.2.0.dist-info/WHEEL +5 -0
- polycheck-0.2.0.dist-info/entry_points.txt +2 -0
- polycheck-0.2.0.dist-info/licenses/LICENSE +21 -0
- polycheck-0.2.0.dist-info/top_level.txt +1 -0
polycheck/initializer.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"""Initializer for coding-assistant slash-command integrations."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from .workflows import WORKFLOW_TEMPLATES
|
|
12
|
+
|
|
13
|
+
HOSTS = ("kilo", "opencode", "claude")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class InitAction:
|
|
18
|
+
"""One file that the initializer plans to write or skip."""
|
|
19
|
+
|
|
20
|
+
host: str
|
|
21
|
+
kind: str
|
|
22
|
+
path: Path | None
|
|
23
|
+
status: str
|
|
24
|
+
message: str = ""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def normalize_hosts(hosts: list[str] | None) -> list[str]:
|
|
28
|
+
"""Normalize host CLI values."""
|
|
29
|
+
values = hosts or ["all"]
|
|
30
|
+
expanded: list[str] = []
|
|
31
|
+
for value in values:
|
|
32
|
+
for raw_host in value.split(","):
|
|
33
|
+
host_value = raw_host.strip()
|
|
34
|
+
if not host_value:
|
|
35
|
+
continue
|
|
36
|
+
if host_value == "all":
|
|
37
|
+
expanded.extend(HOSTS)
|
|
38
|
+
else:
|
|
39
|
+
expanded.append(host_value)
|
|
40
|
+
|
|
41
|
+
out: list[str] = []
|
|
42
|
+
seen: set[str] = set()
|
|
43
|
+
for host in expanded:
|
|
44
|
+
host = host.lower()
|
|
45
|
+
if host not in HOSTS:
|
|
46
|
+
allowed = ", ".join((*HOSTS, "all"))
|
|
47
|
+
raise ValueError(f"Unknown host '{host}'. Expected one of: {allowed}")
|
|
48
|
+
if host not in seen:
|
|
49
|
+
out.append(host)
|
|
50
|
+
seen.add(host)
|
|
51
|
+
return out
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def resolve_workflow_path(
|
|
55
|
+
*,
|
|
56
|
+
host: str,
|
|
57
|
+
scope: str,
|
|
58
|
+
project_root: Path,
|
|
59
|
+
home: Path,
|
|
60
|
+
) -> Path:
|
|
61
|
+
"""Resolve where a slash-command workflow file should live."""
|
|
62
|
+
template = WORKFLOW_TEMPLATES[host]
|
|
63
|
+
if scope == "project":
|
|
64
|
+
return project_root / template.path
|
|
65
|
+
if host == "kilo":
|
|
66
|
+
return home / ".config" / "kilo" / "commands" / "polycheck.md"
|
|
67
|
+
if host == "opencode":
|
|
68
|
+
return home / ".config" / "opencode" / "commands" / "polycheck.md"
|
|
69
|
+
return home / ".claude" / "skills" / "polycheck" / "SKILL.md"
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def resolve_mcp_config_path(
|
|
73
|
+
*,
|
|
74
|
+
host: str,
|
|
75
|
+
scope: str,
|
|
76
|
+
project_root: Path,
|
|
77
|
+
home: Path,
|
|
78
|
+
) -> Path | None:
|
|
79
|
+
"""Resolve MCP config path.
|
|
80
|
+
|
|
81
|
+
Claude global/user-scope config is intentionally not written directly.
|
|
82
|
+
Claude Code versions differ in how user-scope MCP servers are stored, so
|
|
83
|
+
the initializer prints the official `claude mcp add` command for that case.
|
|
84
|
+
"""
|
|
85
|
+
if scope == "project":
|
|
86
|
+
if host == "claude":
|
|
87
|
+
return project_root / ".mcp.json"
|
|
88
|
+
if host == "kilo":
|
|
89
|
+
return project_root / "kilo.jsonc"
|
|
90
|
+
if host == "opencode":
|
|
91
|
+
return project_root / "opencode.jsonc"
|
|
92
|
+
if host == "kilo":
|
|
93
|
+
return home / ".config" / "kilo" / "kilo.jsonc"
|
|
94
|
+
if host == "opencode":
|
|
95
|
+
return home / ".config" / "opencode" / "opencode.jsonc"
|
|
96
|
+
if host == "claude":
|
|
97
|
+
return home / ".claude.json"
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def build_plan(
|
|
102
|
+
*,
|
|
103
|
+
hosts: list[str],
|
|
104
|
+
scope: str,
|
|
105
|
+
project_root: Path,
|
|
106
|
+
home: Path,
|
|
107
|
+
include_workflows: bool = True,
|
|
108
|
+
include_mcp: bool = True,
|
|
109
|
+
) -> list[InitAction]:
|
|
110
|
+
"""Build all file actions for an initializer run."""
|
|
111
|
+
actions: list[InitAction] = []
|
|
112
|
+
for host in hosts:
|
|
113
|
+
if include_workflows:
|
|
114
|
+
actions.append(
|
|
115
|
+
InitAction(
|
|
116
|
+
host=host,
|
|
117
|
+
kind="workflow",
|
|
118
|
+
path=resolve_workflow_path(
|
|
119
|
+
host=host,
|
|
120
|
+
scope=scope,
|
|
121
|
+
project_root=project_root,
|
|
122
|
+
home=home,
|
|
123
|
+
),
|
|
124
|
+
status="planned",
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
if include_mcp:
|
|
128
|
+
path = resolve_mcp_config_path(
|
|
129
|
+
host=host,
|
|
130
|
+
scope=scope,
|
|
131
|
+
project_root=project_root,
|
|
132
|
+
home=home,
|
|
133
|
+
)
|
|
134
|
+
if path is None:
|
|
135
|
+
actions.append(
|
|
136
|
+
InitAction(
|
|
137
|
+
host=host,
|
|
138
|
+
kind="mcp",
|
|
139
|
+
path=None,
|
|
140
|
+
status="skipped",
|
|
141
|
+
message="MCP config path is not available for this host/scope",
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
else:
|
|
145
|
+
actions.append(
|
|
146
|
+
InitAction(
|
|
147
|
+
host=host,
|
|
148
|
+
kind="mcp",
|
|
149
|
+
path=path,
|
|
150
|
+
status="planned",
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
return actions
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def apply_plan(
|
|
157
|
+
actions: list[InitAction],
|
|
158
|
+
*,
|
|
159
|
+
force: bool = False,
|
|
160
|
+
dry_run: bool = False,
|
|
161
|
+
) -> list[InitAction]:
|
|
162
|
+
"""Apply a plan and return the resulting actions."""
|
|
163
|
+
results: list[InitAction] = []
|
|
164
|
+
for action in actions:
|
|
165
|
+
if action.kind == "workflow":
|
|
166
|
+
results.append(_apply_workflow_action(action, force=force, dry_run=dry_run))
|
|
167
|
+
elif action.kind == "mcp":
|
|
168
|
+
results.append(_apply_mcp_action(action, force=force, dry_run=dry_run))
|
|
169
|
+
return results
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _apply_workflow_action(
|
|
173
|
+
action: InitAction,
|
|
174
|
+
*,
|
|
175
|
+
force: bool,
|
|
176
|
+
dry_run: bool,
|
|
177
|
+
) -> InitAction:
|
|
178
|
+
path = action.path
|
|
179
|
+
if path is None:
|
|
180
|
+
return InitAction(
|
|
181
|
+
host=action.host,
|
|
182
|
+
kind=action.kind,
|
|
183
|
+
path=None,
|
|
184
|
+
status="skipped",
|
|
185
|
+
message="no path",
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
if path.exists() and not force:
|
|
189
|
+
return InitAction(
|
|
190
|
+
host=action.host,
|
|
191
|
+
kind=action.kind,
|
|
192
|
+
path=path,
|
|
193
|
+
status="skipped",
|
|
194
|
+
message="already exists; pass --force to overwrite",
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
if dry_run:
|
|
198
|
+
return InitAction(
|
|
199
|
+
host=action.host,
|
|
200
|
+
kind=action.kind,
|
|
201
|
+
path=path,
|
|
202
|
+
status="planned",
|
|
203
|
+
message="would write workflow" if not path.exists() else "would overwrite workflow",
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
207
|
+
path.write_text(WORKFLOW_TEMPLATES[action.host].content, encoding="utf-8")
|
|
208
|
+
return InitAction(
|
|
209
|
+
host=action.host,
|
|
210
|
+
kind=action.kind,
|
|
211
|
+
path=path,
|
|
212
|
+
status="written",
|
|
213
|
+
message="workflow written",
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _apply_mcp_action(
|
|
218
|
+
action: InitAction,
|
|
219
|
+
*,
|
|
220
|
+
force: bool,
|
|
221
|
+
dry_run: bool,
|
|
222
|
+
) -> InitAction:
|
|
223
|
+
path = action.path
|
|
224
|
+
if path is None:
|
|
225
|
+
return action
|
|
226
|
+
|
|
227
|
+
if dry_run:
|
|
228
|
+
status = "planned" if not path.exists() else "planned-merge"
|
|
229
|
+
return InitAction(
|
|
230
|
+
host=action.host,
|
|
231
|
+
kind=action.kind,
|
|
232
|
+
path=path,
|
|
233
|
+
status=status,
|
|
234
|
+
message="would merge MCP config",
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
merged = _merge_mcp_config(path, action.host)
|
|
238
|
+
if isinstance(merged, str):
|
|
239
|
+
return InitAction(
|
|
240
|
+
host=action.host,
|
|
241
|
+
kind=action.kind,
|
|
242
|
+
path=path,
|
|
243
|
+
status="skipped",
|
|
244
|
+
message=merged,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
248
|
+
path.write_text(json.dumps(merged, indent=2) + "\n", encoding="utf-8")
|
|
249
|
+
return InitAction(
|
|
250
|
+
host=action.host,
|
|
251
|
+
kind=action.kind,
|
|
252
|
+
path=path,
|
|
253
|
+
status="written",
|
|
254
|
+
message="MCP config merged",
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _merge_mcp_config(path: Path, host: str) -> dict[str, Any] | str:
|
|
259
|
+
"""Merge polycheck MCP config into a JSON/JSONC file."""
|
|
260
|
+
if path.exists():
|
|
261
|
+
parsed = _read_json_file(path)
|
|
262
|
+
if isinstance(parsed, str):
|
|
263
|
+
return parsed
|
|
264
|
+
data = parsed
|
|
265
|
+
else:
|
|
266
|
+
data = {}
|
|
267
|
+
|
|
268
|
+
if not isinstance(data, dict):
|
|
269
|
+
return f"{path} exists but is not a JSON object"
|
|
270
|
+
|
|
271
|
+
if host in ("kilo", "opencode"):
|
|
272
|
+
mcp = data.setdefault("mcp", {})
|
|
273
|
+
if not isinstance(mcp, dict):
|
|
274
|
+
return f"{path} has non-object 'mcp' key"
|
|
275
|
+
mcp["polycheck"] = {
|
|
276
|
+
"type": "local",
|
|
277
|
+
"command": ["polycheck", "mcp"],
|
|
278
|
+
"enabled": True,
|
|
279
|
+
}
|
|
280
|
+
elif host == "claude":
|
|
281
|
+
servers = data.setdefault("mcpServers", {})
|
|
282
|
+
if not isinstance(servers, dict):
|
|
283
|
+
return f"{path} has non-object 'mcpServers' key"
|
|
284
|
+
servers["polycheck"] = {
|
|
285
|
+
"command": "polycheck",
|
|
286
|
+
"args": ["mcp"],
|
|
287
|
+
}
|
|
288
|
+
else:
|
|
289
|
+
return f"unsupported host: {host}"
|
|
290
|
+
|
|
291
|
+
return data
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def _read_json_file(path: Path) -> dict[str, Any] | list[Any] | str:
|
|
295
|
+
"""Read JSON. JSONC with comments is rejected to avoid destructive edits."""
|
|
296
|
+
try:
|
|
297
|
+
text = path.read_text(encoding="utf-8")
|
|
298
|
+
except OSError as exc:
|
|
299
|
+
return f"could not read {path}: {exc}"
|
|
300
|
+
|
|
301
|
+
try:
|
|
302
|
+
return json.loads(text)
|
|
303
|
+
except json.JSONDecodeError:
|
|
304
|
+
if _strip_json_comments(text).strip():
|
|
305
|
+
return (
|
|
306
|
+
f"{path} contains comments or invalid JSON; "
|
|
307
|
+
"convert it to valid JSON or pass --force with a manual edit"
|
|
308
|
+
)
|
|
309
|
+
return {}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _strip_json_comments(text: str) -> str:
|
|
313
|
+
"""Return text with simple // and /* */ comments removed for detection."""
|
|
314
|
+
without_line = re.sub(r"//.*", "", text)
|
|
315
|
+
return re.sub(r"/\*.*?\*/", "", without_line, flags=re.DOTALL)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def format_action(action: InitAction) -> str:
|
|
319
|
+
"""Format one action for CLI output."""
|
|
320
|
+
path = action.path or Path("—")
|
|
321
|
+
if path.is_absolute():
|
|
322
|
+
try:
|
|
323
|
+
path = path.relative_to(Path.cwd())
|
|
324
|
+
except ValueError:
|
|
325
|
+
pass
|
|
326
|
+
prefix = {
|
|
327
|
+
"planned": "plan",
|
|
328
|
+
"planned-merge": "plan",
|
|
329
|
+
"written": "wrote",
|
|
330
|
+
"skipped": "skip",
|
|
331
|
+
}.get(action.status, action.status)
|
|
332
|
+
suffix = f" — {action.message}" if action.message else ""
|
|
333
|
+
return f" {prefix}: {action.host}/{action.kind}: {path}{suffix}"
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Language-specific defaults.
|
|
2
|
+
|
|
3
|
+
Each submodule (e.g. ``polycheck.languages.python``) is responsible
|
|
4
|
+
for declaring which tools are *always* relevant for its language,
|
|
5
|
+
and any default config (e.g. ``ruff`` line-length, ``mypy`` strict
|
|
6
|
+
mode). This is the place to add per-language opinions without
|
|
7
|
+
hard-coding them in the runner.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
# No-op package marker. Concrete defaults are added in submodules.
|