@jovianops/cortex 0.3.0 → 1.0.0
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.
- package/.agents/plugins/marketplace.json +7 -7
- package/.claude-plugin/marketplace.json +8 -8
- package/.claude-plugin/plugin.json +2 -2
- package/.cursor-plugin/marketplace.json +3 -3
- package/.cursor-plugin/plugin.json +2 -2
- package/.github/plugin/marketplace.json +146 -0
- package/.github/plugin.json +59 -0
- package/AGENTS.md +1 -1
- package/GEMINI.md +4 -4
- package/README.md +103 -26
- package/checksums.json +65 -51
- package/evals/skill_evals.json +2 -2
- package/gemini-extension.json +2 -2
- package/package.json +6 -3
- package/packs.json +1 -1
- package/plugin.json +2 -2
- package/premium-skills/accessibility-auditor/SKILL.md +1 -1
- package/premium-skills/api-designer/SKILL.md +1 -1
- package/premium-skills/code-migration/SKILL.md +3 -1
- package/premium-skills/code-migration/scripts/migration_inventory.py +62 -0
- package/premium-skills/db-optimizer/SKILL.md +3 -1
- package/premium-skills/db-optimizer/scripts/lint_sql.py +99 -0
- package/premium-skills/devops-pipeline/SKILL.md +1 -1
- package/premium-skills/docker-generator/SKILL.md +1 -1
- package/premium-skills/incident-response/SKILL.md +3 -1
- package/premium-skills/incident-response/scripts/incident_timeline.py +78 -0
- package/premium-skills/observability-setup/SKILL.md +3 -1
- package/premium-skills/observability-setup/scripts/check_slo.py +81 -0
- package/premium-skills/performance-profiler/SKILL.md +3 -1
- package/premium-skills/performance-profiler/scripts/bench_compare.py +62 -0
- package/premium-skills/refactoring-assistant/SKILL.md +3 -1
- package/premium-skills/refactoring-assistant/scripts/complexity_scan.py +69 -0
- package/premium-skills/release-engineering/SKILL.md +1 -1
- package/premium-skills/release-engineering/scripts/semver_bump.py +0 -1
- package/premium-skills/security-auditor/SKILL.md +1 -1
- package/premium-skills/security-auditor/scripts/secret_scan.py +6 -0
- package/premium-skills/terraform-generator/SKILL.md +3 -1
- package/premium-skills/terraform-generator/scripts/lint_terraform.py +111 -0
- package/premium-skills/unit-test-generator/SKILL.md +3 -1
- package/premium-skills/unit-test-generator/scripts/test_skeleton.py +58 -0
- package/schemas/checksums.schema.json +42 -0
- package/schemas/cortex-lock.schema.json +28 -0
- package/schemas/packs.schema.json +31 -0
- package/scripts/__pycache__/eval_skills.cpython-312.pyc +0 -0
- package/scripts/__pycache__/install_skills.cpython-312.pyc +0 -0
- package/scripts/__pycache__/package_skills.cpython-312.pyc +0 -0
- package/scripts/bump_version.py +119 -0
- package/scripts/cortex.py +253 -14
- package/scripts/install_skills.py +63 -13
- package/scripts/package_skills.py +1 -1
- package/scripts/validate_manifests.py +7 -0
- package/scripts/validate_skills.py +0 -1
- package/scripts/validate_yaml.py +45 -16
- package/scripts/verify_site.py +104 -0
- package/skills/academic-assistant/SKILL.md +3 -1
- package/skills/academic-assistant/scripts/citation_check.py +54 -0
- package/skills/anti-hallucination/SKILL.md +3 -1
- package/skills/anti-hallucination/scripts/verify_claims.py +57 -0
- package/skills/blender-3d-modeling/SKILL.md +1 -1
- package/skills/code-review-assistant/SKILL.md +3 -1
- package/skills/code-review-assistant/scripts/diff_review.py +76 -0
- package/skills/college-report-card/SKILL.md +1 -1
- package/skills/documentation-generator/SKILL.md +1 -1
- package/skills/memory-manager/SKILL.md +1 -1
- package/skills/python-coding-assistant/SKILL.md +3 -1
- package/skills/python-coding-assistant/scripts/check_python_ast.py +77 -0
- package/skills/testing-automation/SKILL.md +3 -1
- package/skills/testing-automation/scripts/check_test_coverage_map.py +65 -0
- package/skills/web-scraper/SKILL.md +3 -1
- package/skills/web-scraper/scripts/check_robots.py +50 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Deterministic UTC incident timeline & MTTR/MTTD validator for incident-response skill."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_utc(ts: str) -> datetime:
|
|
13
|
+
if not ts.endswith("Z"):
|
|
14
|
+
raise ValueError(f"Timestamp must be UTC ISO-8601 ending in 'Z': {ts!r}")
|
|
15
|
+
return datetime.fromisoformat(ts.replace("Z", "+00:00"))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def validate_incident(data: dict) -> tuple[list[str], dict]:
|
|
19
|
+
errors: list[str] = []
|
|
20
|
+
events = data.get("timeline")
|
|
21
|
+
if not isinstance(events, list) or not events:
|
|
22
|
+
return ["'timeline' must be a non-empty list of UTC events."], {}
|
|
23
|
+
|
|
24
|
+
parsed: list[tuple[datetime, str]] = []
|
|
25
|
+
for idx, ev in enumerate(events):
|
|
26
|
+
if not isinstance(ev, dict) or "timestamp" not in ev or "event" not in ev:
|
|
27
|
+
errors.append(f"Event #{idx + 1} missing 'timestamp' or 'event'.")
|
|
28
|
+
continue
|
|
29
|
+
try:
|
|
30
|
+
dt = parse_utc(str(ev["timestamp"]))
|
|
31
|
+
except ValueError as exc:
|
|
32
|
+
errors.append(str(exc))
|
|
33
|
+
continue
|
|
34
|
+
if parsed and dt < parsed[-1][0]:
|
|
35
|
+
errors.append(f"Out-of-order timestamp at event #{idx + 1}: {ev['timestamp']}")
|
|
36
|
+
parsed.append((dt, str(ev.get("phase", "")).lower()))
|
|
37
|
+
|
|
38
|
+
by_phase = {phase: dt for dt, phase in parsed if phase}
|
|
39
|
+
metrics: dict[str, float | None] = {"mttd_minutes": None, "mttr_minutes": None}
|
|
40
|
+
if "impact_start" in by_phase and "detected" in by_phase:
|
|
41
|
+
metrics["mttd_minutes"] = round((by_phase["detected"] - by_phase["impact_start"]).total_seconds() / 60.0, 2)
|
|
42
|
+
if "impact_start" in by_phase and "resolved" in by_phase:
|
|
43
|
+
metrics["mttr_minutes"] = round((by_phase["resolved"] - by_phase["impact_start"]).total_seconds() / 60.0, 2)
|
|
44
|
+
|
|
45
|
+
actions = data.get("action_items", [])
|
|
46
|
+
if not isinstance(actions, list) or not actions:
|
|
47
|
+
errors.append("Postmortem must include at least one corrective 'action_items' entry.")
|
|
48
|
+
else:
|
|
49
|
+
for idx, item in enumerate(actions, 1):
|
|
50
|
+
if not isinstance(item, dict) or not item.get("owner") or not item.get("due_date"):
|
|
51
|
+
errors.append(f"Action item #{idx} missing required 'owner' or 'due_date'.")
|
|
52
|
+
|
|
53
|
+
return errors, metrics
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def main(argv: list[str] | None = None) -> int:
|
|
57
|
+
parser = argparse.ArgumentParser(description="Validate an incident timeline JSON and compute MTTD/MTTR.")
|
|
58
|
+
parser.add_argument("file", type=Path, help="Path to incident timeline JSON file.")
|
|
59
|
+
parser.add_argument("--json", action="store_true", dest="as_json")
|
|
60
|
+
args = parser.parse_args(argv)
|
|
61
|
+
if not args.file.is_file():
|
|
62
|
+
print(f"ERROR: File not found: {args.file}", file=sys.stderr)
|
|
63
|
+
return 2
|
|
64
|
+
|
|
65
|
+
data = json.loads(args.file.read_text(encoding="utf-8"))
|
|
66
|
+
errors, metrics = validate_incident(data)
|
|
67
|
+
if args.as_json:
|
|
68
|
+
print(json.dumps({"valid": not errors, "metrics": metrics, "errors": errors}, indent=2))
|
|
69
|
+
elif not errors:
|
|
70
|
+
print(f"OK: Timeline valid (MTTD={metrics['mttd_minutes']}m, MTTR={metrics['mttr_minutes']}m).")
|
|
71
|
+
else:
|
|
72
|
+
for e in errors:
|
|
73
|
+
print(f"ERROR: {e}")
|
|
74
|
+
return 1 if errors else 0
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
if __name__ == "__main__":
|
|
78
|
+
raise SystemExit(main())
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: observability-setup
|
|
3
3
|
description: Add structured logs, OTel traces, SLOs, and clean alerts.
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
author: Athalla Jovian Maharsa (athallajovian9-cyber), Hermes Agent
|
|
6
6
|
license: MIT
|
|
7
7
|
platforms: [linux, macos, windows]
|
|
@@ -29,6 +29,8 @@ Instrument services with high-signal, low-cardinality observability: structured
|
|
|
29
29
|
|
|
30
30
|
## How to Run
|
|
31
31
|
|
|
32
|
+
> **Bundled Helper Script (`v1.0.0`):** Run `python premium-skills/observability-setup/scripts/check_slo.py --slo 99.9 --scan src/` to compute exact SLO error budgets, multi-window burn-rate thresholds, and flag high-cardinality metric labels.
|
|
33
|
+
|
|
32
34
|
```bash
|
|
33
35
|
# Universal CLI (Claude Code, Codex, Gemini CLI, Cursor, Copilot, OpenCode, OpenClaw, Goose, Cline)
|
|
34
36
|
npx skills add JovianOps/cortex --skill observability-setup -g -y
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Deterministic SLO error-budget calculator & metric cardinality auditor for observability-setup skill."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
import sys
|
|
9
|
+
from decimal import Decimal
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
HIGH_CARDINALITY_LABELS = {
|
|
13
|
+
"user_id", "userid", "request_id", "requestid", "trace_id", "span_id",
|
|
14
|
+
"email", "ip", "client_ip", "session_id", "uuid", "order_id", "timestamp",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def compute_error_budget(slo_percent: Decimal, window_days: int) -> dict:
|
|
19
|
+
if not (Decimal("0") < slo_percent < Decimal("100")):
|
|
20
|
+
raise ValueError("SLO must be strictly between 0 and 100 (e.g., 99.9).")
|
|
21
|
+
total_minutes = Decimal(window_days) * Decimal(24 * 60)
|
|
22
|
+
error_ratio = (Decimal("100") - slo_percent) / Decimal("100")
|
|
23
|
+
budget_minutes = (total_minutes * error_ratio).quantize(Decimal("0.01"))
|
|
24
|
+
return {
|
|
25
|
+
"slo_percent": str(slo_percent),
|
|
26
|
+
"window_days": window_days,
|
|
27
|
+
"error_budget_minutes": str(budget_minutes),
|
|
28
|
+
"error_budget_ratio": f"{error_ratio:.6f}",
|
|
29
|
+
"multi_window_burn_alerts": {
|
|
30
|
+
"page_fast_2pct_1h_5m": {"burn_rate": 14.4, "error_rate_threshold": f"{error_ratio * Decimal('14.4'):.6f}"},
|
|
31
|
+
"page_slow_5pct_6h_30m": {"burn_rate": 6.0, "error_rate_threshold": f"{error_ratio * Decimal('6.0'):.6f}"},
|
|
32
|
+
"ticket_10pct_3d_6h": {"burn_rate": 1.0, "error_rate_threshold": f"{error_ratio:.6f}"},
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def scan_labels(path: Path) -> list[dict]:
|
|
38
|
+
findings: list[dict] = []
|
|
39
|
+
files = [path] if path.is_file() else sorted(p for p in path.rglob("*") if p.is_file() and p.suffix in {".py", ".ts", ".js", ".go", ".yml", ".yaml", ".json"})
|
|
40
|
+
for fp in files:
|
|
41
|
+
for idx, line in enumerate(fp.read_text(encoding="utf-8", errors="ignore").splitlines(), 1):
|
|
42
|
+
for label in HIGH_CARDINALITY_LABELS:
|
|
43
|
+
if re.search(rf'["\']{re.escape(label)}["\']', line) and re.search(r'(?i)(label|tag|metric|counter|histogram|gauge|prom)', line):
|
|
44
|
+
findings.append({
|
|
45
|
+
"severity": "HIGH",
|
|
46
|
+
"rule": "high-cardinality-label",
|
|
47
|
+
"file": fp.as_posix(),
|
|
48
|
+
"line": idx,
|
|
49
|
+
"label": label,
|
|
50
|
+
"message": f"High-cardinality label '{label}' detected on metric definition.",
|
|
51
|
+
})
|
|
52
|
+
return findings
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def main(argv: list[str] | None = None) -> int:
|
|
56
|
+
parser = argparse.ArgumentParser(description="Compute SLO error budgets and audit metric label cardinality.")
|
|
57
|
+
parser.add_argument("--slo", type=Decimal, default=Decimal("99.9"), help="SLO target percent (default: 99.9).")
|
|
58
|
+
parser.add_argument("--window-days", type=int, default=30, help="Rolling SLO window in days (default: 30).")
|
|
59
|
+
parser.add_argument("--scan", type=Path, help="Optional file or directory to scan for high-cardinality metric labels.")
|
|
60
|
+
parser.add_argument("--json", action="store_true", dest="as_json")
|
|
61
|
+
args = parser.parse_args(argv)
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
budget = compute_error_budget(args.slo, args.window_days)
|
|
65
|
+
except ValueError as exc:
|
|
66
|
+
print(f"ERROR: {exc}", file=sys.stderr)
|
|
67
|
+
return 2
|
|
68
|
+
|
|
69
|
+
findings = scan_labels(args.scan) if args.scan else []
|
|
70
|
+
payload = {"slo": budget, "cardinality_findings": findings}
|
|
71
|
+
if args.as_json:
|
|
72
|
+
print(json.dumps(payload, indent=2))
|
|
73
|
+
else:
|
|
74
|
+
print(f"SLO {budget['slo_percent']}% ({budget['window_days']}d window) -> Error Budget: {budget['error_budget_minutes']} min")
|
|
75
|
+
for f in findings:
|
|
76
|
+
print(f"[{f['severity']}] {f['file']}:{f['line']} — {f['message']}")
|
|
77
|
+
return 1 if findings else 0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if __name__ == "__main__":
|
|
81
|
+
raise SystemExit(main())
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: performance-profiler
|
|
3
3
|
description: Profile CPU, memory, and I/O with measured benchmarks.
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
author: Athalla Jovian Maharsa (athallajovian9-cyber), Hermes Agent
|
|
6
6
|
license: MIT
|
|
7
7
|
platforms: [linux, macos, windows]
|
|
@@ -27,6 +27,8 @@ Diagnose and fix CPU, memory, and I/O bottlenecks using mandatory baseline profi
|
|
|
27
27
|
|
|
28
28
|
## How to Run
|
|
29
29
|
|
|
30
|
+
> **Bundled Helper Script (`v1.0.0`):** Run `python premium-skills/performance-profiler/scripts/bench_compare.py base.json cand.json` to compare p50/p95/p99 latency samples and enforce a regression threshold.
|
|
31
|
+
|
|
30
32
|
```bash
|
|
31
33
|
hermes skills tap add JovianOps/cortex
|
|
32
34
|
hermes skills install JovianOps/cortex/premium-skills/performance-profiler --yes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Deterministic baseline vs. candidate latency benchmark comparator for performance-profiler skill."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def percentile(sorted_vals: list[float], pct: float) -> float:
|
|
12
|
+
if not sorted_vals:
|
|
13
|
+
return 0.0
|
|
14
|
+
k = max(0, min(len(sorted_vals) - 1, int(round((pct / 100.0) * (len(sorted_vals) - 1)))))
|
|
15
|
+
return round(sorted_vals[k], 4)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def summarize(samples: list[float]) -> dict[str, float]:
|
|
19
|
+
s = sorted(float(x) for x in samples)
|
|
20
|
+
return {"count": len(s), "p50": percentile(s, 50), "p95": percentile(s, 95), "p99": percentile(s, 99)}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def compare(baseline: list[float], candidate: list[float], max_regression_pct: float) -> dict:
|
|
24
|
+
b = summarize(baseline)
|
|
25
|
+
c = summarize(candidate)
|
|
26
|
+
p95_delta_pct = round(((c["p95"] - b["p95"]) / b["p95"]) * 100.0, 2) if b["p95"] > 0 else 0.0
|
|
27
|
+
regressed = p95_delta_pct > max_regression_pct
|
|
28
|
+
return {
|
|
29
|
+
"baseline": b,
|
|
30
|
+
"candidate": c,
|
|
31
|
+
"p95_delta_pct": p95_delta_pct,
|
|
32
|
+
"max_regression_pct": max_regression_pct,
|
|
33
|
+
"regressed": regressed,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def main(argv: list[str] | None = None) -> int:
|
|
38
|
+
parser = argparse.ArgumentParser(description="Compare baseline vs. candidate benchmark latency JSON arrays.")
|
|
39
|
+
parser.add_argument("baseline", type=Path, help="JSON file containing a list of numeric baseline durations.")
|
|
40
|
+
parser.add_argument("candidate", type=Path, help="JSON file containing a list of numeric candidate durations.")
|
|
41
|
+
parser.add_argument("--max-regression-pct", type=float, default=5.0, help="Max allowed p95 regression percent (default: 5.0).")
|
|
42
|
+
parser.add_argument("--json", action="store_true", dest="as_json")
|
|
43
|
+
args = parser.parse_args(argv)
|
|
44
|
+
if not args.baseline.is_file() or not args.candidate.is_file():
|
|
45
|
+
print("ERROR: Baseline or candidate file not found.", file=sys.stderr)
|
|
46
|
+
return 2
|
|
47
|
+
|
|
48
|
+
res = compare(
|
|
49
|
+
json.loads(args.baseline.read_text(encoding="utf-8")),
|
|
50
|
+
json.loads(args.candidate.read_text(encoding="utf-8")),
|
|
51
|
+
args.max_regression_pct,
|
|
52
|
+
)
|
|
53
|
+
if args.as_json:
|
|
54
|
+
print(json.dumps(res, indent=2))
|
|
55
|
+
else:
|
|
56
|
+
status = "REGRESSION" if res["regressed"] else "OK"
|
|
57
|
+
print(f"[{status}] p95: {res['baseline']['p95']} -> {res['candidate']['p95']} ({res['p95_delta_pct']:+.2f}%)")
|
|
58
|
+
return 1 if res["regressed"] else 0
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
if __name__ == "__main__":
|
|
62
|
+
raise SystemExit(main())
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: refactoring-assistant
|
|
3
3
|
description: Refactor complex code safely with parity verification.
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
author: Athalla Jovian Maharsa (athallajovian9-cyber), Hermes Agent
|
|
6
6
|
license: MIT
|
|
7
7
|
platforms: [linux, macos, windows]
|
|
@@ -29,6 +29,8 @@ Simplify complex, duplicated, or brittle code through small, measurable, behavio
|
|
|
29
29
|
|
|
30
30
|
## How to Run
|
|
31
31
|
|
|
32
|
+
> **Bundled Helper Script (`v1.0.0`):** Run `python premium-skills/refactoring-assistant/scripts/complexity_scan.py src/` to locate Python cyclomatic complexity and function-length hotspots before refactoring.
|
|
33
|
+
|
|
32
34
|
```bash
|
|
33
35
|
hermes skills tap add JovianOps/cortex
|
|
34
36
|
hermes skills install JovianOps/cortex/premium-skills/refactoring-assistant --yes
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Python AST cyclomatic complexity & function-length hotspot scanner for refactoring-assistant skill."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import ast
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
BRANCH_NODES = (ast.If, ast.For, ast.AsyncFor, ast.While, ast.ExceptHandler, ast.With, ast.AsyncWith, ast.Assert, ast.IfExp)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def cyclomatic_complexity(node: ast.AST) -> int:
|
|
15
|
+
score = 1
|
|
16
|
+
for child in ast.walk(node):
|
|
17
|
+
if isinstance(child, BRANCH_NODES):
|
|
18
|
+
score += 1
|
|
19
|
+
elif isinstance(child, ast.BoolOp):
|
|
20
|
+
score += len(child.values) - 1
|
|
21
|
+
return score
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def scan_file(path: Path, max_cc: int, max_lines: int) -> list[dict]:
|
|
25
|
+
tree = ast.parse(path.read_text(encoding="utf-8"), filename=path.as_posix())
|
|
26
|
+
hotspots: list[dict] = []
|
|
27
|
+
for node in ast.walk(tree):
|
|
28
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
29
|
+
cc = cyclomatic_complexity(node)
|
|
30
|
+
length = (getattr(node, "end_lineno", node.lineno) or node.lineno) - node.lineno + 1
|
|
31
|
+
if cc > max_cc or length > max_lines:
|
|
32
|
+
hotspots.append({
|
|
33
|
+
"file": path.as_posix(),
|
|
34
|
+
"function": node.name,
|
|
35
|
+
"line": node.lineno,
|
|
36
|
+
"complexity": cc,
|
|
37
|
+
"lines": length,
|
|
38
|
+
})
|
|
39
|
+
return hotspots
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def main(argv: list[str] | None = None) -> int:
|
|
43
|
+
parser = argparse.ArgumentParser(description="Find Python complexity & function-length refactoring hotspots.")
|
|
44
|
+
parser.add_argument("target", type=Path, help="Python file or directory.")
|
|
45
|
+
parser.add_argument("--max-cc", type=int, default=10, help="Cyclomatic complexity threshold (default: 10).")
|
|
46
|
+
parser.add_argument("--max-lines", type=int, default=60, help="Function line-count threshold (default: 60).")
|
|
47
|
+
parser.add_argument("--json", action="store_true", dest="as_json")
|
|
48
|
+
args = parser.parse_args(argv)
|
|
49
|
+
if not args.target.exists():
|
|
50
|
+
print(f"ERROR: Path not found: {args.target}", file=sys.stderr)
|
|
51
|
+
return 2
|
|
52
|
+
|
|
53
|
+
files = [args.target] if args.target.is_file() else sorted(args.target.rglob("*.py"))
|
|
54
|
+
hotspots: list[dict] = []
|
|
55
|
+
for fp in files:
|
|
56
|
+
hotspots.extend(scan_file(fp, args.max_cc, args.max_lines))
|
|
57
|
+
|
|
58
|
+
if args.as_json:
|
|
59
|
+
print(json.dumps({"files_checked": len(files), "count": len(hotspots), "hotspots": hotspots}, indent=2))
|
|
60
|
+
elif not hotspots:
|
|
61
|
+
print(f"OK: No complexity hotspots exceeding CC>{args.max_cc} or lines>{args.max_lines}.")
|
|
62
|
+
else:
|
|
63
|
+
for h in sorted(hotspots, key=lambda x: (-x["complexity"], -x["lines"])):
|
|
64
|
+
print(f"{h['file']}:{h['line']} {h['function']}() — CC={h['complexity']}, lines={h['lines']}")
|
|
65
|
+
return 1 if hotspots else 0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __name__ == "__main__":
|
|
69
|
+
raise SystemExit(main())
|
|
@@ -105,6 +105,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
105
105
|
return 2
|
|
106
106
|
findings = scan_path(args.target)
|
|
107
107
|
findings_for_output = sanitize_findings_for_output(findings)
|
|
108
|
+
for f in findings_for_output:
|
|
109
|
+
f["severity"] = str(f.get("severity", "UNKNOWN"))
|
|
110
|
+
f["cwe"] = str(f.get("cwe", "N/A"))
|
|
111
|
+
f["title"] = str(f.get("title", "Unknown finding"))[:200]
|
|
112
|
+
f["file"] = str(f.get("file", ""))[:500]
|
|
113
|
+
f["line"] = int(f.get("line", 0))
|
|
108
114
|
if args.format == "json":
|
|
109
115
|
print(json.dumps({"target": args.target.as_posix(), "count": len(findings_for_output), "findings": findings_for_output}, indent=2))
|
|
110
116
|
else:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: terraform-generator
|
|
3
3
|
description: Generate hardened, validated Terraform and OpenTofu IaC.
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
author: Athalla Jovian Maharsa (athallajovian9-cyber), Hermes Agent
|
|
6
6
|
license: MIT
|
|
7
7
|
platforms: [linux, macos, windows]
|
|
@@ -28,6 +28,8 @@ Generate modular, secure-by-default, validated Terraform/OpenTofu HCL configurat
|
|
|
28
28
|
|
|
29
29
|
## How to Run
|
|
30
30
|
|
|
31
|
+
> **Bundled Helper Script (`v1.0.0`):** Run `python premium-skills/terraform-generator/scripts/lint_terraform.py infra/` to audit `.tf` files for unpinned providers, `0.0.0.0/0` admin ports, hardcoded secrets, and disabled encryption.
|
|
32
|
+
|
|
31
33
|
```bash
|
|
32
34
|
hermes skills tap add JovianOps/cortex
|
|
33
35
|
hermes skills install JovianOps/cortex/premium-skills/terraform-generator --yes
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Deterministic offline Terraform (.tf) security & best-practice linter for terraform-generator skill."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
SENSITIVE_PORTS = {"22", "3389", "5432", "3306", "6379", "27017"}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def lint_tf_text(text: str, filename: str) -> list[dict]:
|
|
15
|
+
findings: list[dict] = []
|
|
16
|
+
lines = text.splitlines()
|
|
17
|
+
|
|
18
|
+
if "required_providers" in text and not re.search(r'version\s*=\s*"[^"]+"', text):
|
|
19
|
+
findings.append({
|
|
20
|
+
"severity": "HIGH",
|
|
21
|
+
"rule": "pin-provider-version",
|
|
22
|
+
"file": filename,
|
|
23
|
+
"line": 1,
|
|
24
|
+
"message": "required_providers block has no pinned version constraint.",
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
for idx, line in enumerate(lines, 1):
|
|
28
|
+
stripped = line.strip()
|
|
29
|
+
if stripped.startswith(("#", "//")):
|
|
30
|
+
continue
|
|
31
|
+
|
|
32
|
+
if re.search(r'0\.0\.0\.0/0|::/0', stripped):
|
|
33
|
+
window = "\n".join(lines[max(0, idx - 8) : min(len(lines), idx + 5)])
|
|
34
|
+
if any(re.search(rf'\b(from_port|to_port|port)\s*=\s*{p}\b', window) for p in SENSITIVE_PORTS):
|
|
35
|
+
findings.append({
|
|
36
|
+
"severity": "CRITICAL",
|
|
37
|
+
"rule": "open-admin-port",
|
|
38
|
+
"file": filename,
|
|
39
|
+
"line": idx,
|
|
40
|
+
"message": "Security group exposes administrative/database port to 0.0.0.0/0 or ::/0.",
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if re.search(r'(?i)\b(password|secret_key|access_key|api_key|token)\s*=\s*"[^"$]{6,}"', stripped):
|
|
44
|
+
findings.append({
|
|
45
|
+
"severity": "CRITICAL",
|
|
46
|
+
"rule": "hardcoded-secret",
|
|
47
|
+
"file": filename,
|
|
48
|
+
"line": idx,
|
|
49
|
+
"message": "Possible hardcoded credential in Terraform config; use variables/secrets manager.",
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
if re.search(r'(?i)\b(encrypted|storage_encrypted)\s*=\s*false\b', stripped):
|
|
53
|
+
findings.append({
|
|
54
|
+
"severity": "HIGH",
|
|
55
|
+
"rule": "encryption-disabled",
|
|
56
|
+
"file": filename,
|
|
57
|
+
"line": idx,
|
|
58
|
+
"message": "Storage encryption is explicitly disabled.",
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
if re.search(r'(?i)\bpublicly_accessible\s*=\s*true\b', stripped):
|
|
62
|
+
findings.append({
|
|
63
|
+
"severity": "HIGH",
|
|
64
|
+
"rule": "public-database",
|
|
65
|
+
"file": filename,
|
|
66
|
+
"line": idx,
|
|
67
|
+
"message": "Resource is marked publicly_accessible = true.",
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
if re.search(r'source\s*=\s*"(git::|github\.com/)', stripped) and "ref=" not in stripped:
|
|
71
|
+
findings.append({
|
|
72
|
+
"severity": "MEDIUM",
|
|
73
|
+
"rule": "unpinned-module-ref",
|
|
74
|
+
"file": filename,
|
|
75
|
+
"line": idx,
|
|
76
|
+
"message": "Remote Git module source lacks a pinned ?ref=<tag|sha>.",
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
return findings
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def scan_target(target: Path) -> tuple[int, list[dict]]:
|
|
83
|
+
files = [target] if target.is_file() else sorted(target.rglob("*.tf"))
|
|
84
|
+
findings: list[dict] = []
|
|
85
|
+
for fp in files:
|
|
86
|
+
findings.extend(lint_tf_text(fp.read_text(encoding="utf-8", errors="ignore"), fp.as_posix()))
|
|
87
|
+
return len(files), findings
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def main(argv: list[str] | None = None) -> int:
|
|
91
|
+
parser = argparse.ArgumentParser(description="Lint Terraform (.tf) files for security and version pinning.")
|
|
92
|
+
parser.add_argument("target", type=Path, help="Path to a .tf file or directory.")
|
|
93
|
+
parser.add_argument("--json", action="store_true", dest="as_json")
|
|
94
|
+
args = parser.parse_args(argv)
|
|
95
|
+
if not args.target.exists():
|
|
96
|
+
print(f"ERROR: Path not found: {args.target}", file=sys.stderr)
|
|
97
|
+
return 2
|
|
98
|
+
|
|
99
|
+
count, findings = scan_target(args.target)
|
|
100
|
+
if args.as_json:
|
|
101
|
+
print(json.dumps({"files_checked": count, "count": len(findings), "findings": findings}, indent=2))
|
|
102
|
+
elif not findings:
|
|
103
|
+
print(f"OK: {count} Terraform file(s) passed all checks.")
|
|
104
|
+
else:
|
|
105
|
+
for f in findings:
|
|
106
|
+
print(f"[{f['severity']}] ({f['rule']}) {f['file']}:{f['line']} — {f['message']}")
|
|
107
|
+
return 1 if findings else 0
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
raise SystemExit(main())
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: unit-test-generator
|
|
3
3
|
description: Generate branch-covering unit tests from source code.
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
author: Athalla Jovian Maharsa (athallajovian9-cyber), Hermes Agent
|
|
6
6
|
license: MIT
|
|
7
7
|
platforms: [linux, macos, windows]
|
|
@@ -28,6 +28,8 @@ Generate high-signal, branch-covering unit tests from real source code across Py
|
|
|
28
28
|
|
|
29
29
|
## How to Run
|
|
30
30
|
|
|
31
|
+
> **Bundled Helper Script (`v1.0.0`):** Run `python premium-skills/unit-test-generator/scripts/test_skeleton.py module.py` to generate an AST-derived branch and edge-case test checklist for every public function.
|
|
32
|
+
|
|
31
33
|
```bash
|
|
32
34
|
hermes skills tap add JovianOps/cortex
|
|
33
35
|
hermes skills install JovianOps/cortex/premium-skills/unit-test-generator --yes
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""AST-based unit test case & branch checklist generator for unit-test-generator skill."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import ast
|
|
7
|
+
import json
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def inspect_module(source_path: Path) -> list[dict]:
|
|
13
|
+
tree = ast.parse(source_path.read_text(encoding="utf-8"), filename=source_path.as_posix())
|
|
14
|
+
items: list[dict] = []
|
|
15
|
+
for node in tree.body:
|
|
16
|
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and not node.name.startswith("_"):
|
|
17
|
+
branches = sum(isinstance(n, (ast.If, ast.For, ast.While, ast.Try, ast.ExceptHandler, ast.Match)) for n in ast.walk(node))
|
|
18
|
+
raises = [
|
|
19
|
+
ast.unparse(n.exc) if n.exc is not None else "re-raise"
|
|
20
|
+
for n in ast.walk(node)
|
|
21
|
+
if isinstance(n, ast.Raise)
|
|
22
|
+
]
|
|
23
|
+
items.append({
|
|
24
|
+
"name": node.name,
|
|
25
|
+
"line": node.lineno,
|
|
26
|
+
"args": [a.arg for a in node.args.args],
|
|
27
|
+
"branch_count": branches,
|
|
28
|
+
"raises": raises,
|
|
29
|
+
"recommended_cases": [
|
|
30
|
+
f"test_{node.name}_happy_path",
|
|
31
|
+
f"test_{node.name}_boundary_inputs",
|
|
32
|
+
*( [f"test_{node.name}_raises_on_invalid_input"] if raises else [] ),
|
|
33
|
+
],
|
|
34
|
+
})
|
|
35
|
+
return items
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def main(argv: list[str] | None = None) -> int:
|
|
39
|
+
parser = argparse.ArgumentParser(description="Analyze a Python module and emit a unit-test branch checklist.")
|
|
40
|
+
parser.add_argument("source", type=Path, help="Python source file to analyze.")
|
|
41
|
+
parser.add_argument("--json", action="store_true", dest="as_json")
|
|
42
|
+
args = parser.parse_args(argv)
|
|
43
|
+
if not args.source.is_file():
|
|
44
|
+
print(f"ERROR: File not found: {args.source}", file=sys.stderr)
|
|
45
|
+
return 2
|
|
46
|
+
|
|
47
|
+
items = inspect_module(args.source)
|
|
48
|
+
if args.as_json:
|
|
49
|
+
print(json.dumps({"file": args.source.as_posix(), "functions": items}, indent=2))
|
|
50
|
+
else:
|
|
51
|
+
print(f"Unit-test checklist for {args.source} ({len(items)} public function(s)):")
|
|
52
|
+
for it in items:
|
|
53
|
+
print(f" - {it['name']}({', '.join(it['args'])}) [branches={it['branch_count']}]: {', '.join(it['recommended_cases'])}")
|
|
54
|
+
return 0
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://jovianops.github.io/cortex/schemas/checksums.schema.json",
|
|
4
|
+
"title": "Cortex Checksums Manifest (v1.0.0)",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["schema_version", "release_version", "skill_count", "skills"],
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"properties": {
|
|
9
|
+
"schema_version": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
|
|
12
|
+
},
|
|
13
|
+
"release_version": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z.-]+)?$"
|
|
16
|
+
},
|
|
17
|
+
"skill_count": {
|
|
18
|
+
"type": "integer",
|
|
19
|
+
"minimum": 1
|
|
20
|
+
},
|
|
21
|
+
"skills": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"minProperties": 1,
|
|
24
|
+
"additionalProperties": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"required": ["collection", "dir", "zip", "zip_sha256", "files"],
|
|
27
|
+
"additionalProperties": false,
|
|
28
|
+
"properties": {
|
|
29
|
+
"collection": { "type": "string", "enum": ["core", "extended"] },
|
|
30
|
+
"dir": { "type": "string", "enum": ["skills", "premium-skills"] },
|
|
31
|
+
"zip": { "type": "string", "pattern": "\\.zip$" },
|
|
32
|
+
"zip_sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
|
|
33
|
+
"files": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"required": ["SKILL.md"],
|
|
36
|
+
"additionalProperties": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|