@gnost-cli/darwin-arm64 0.5.3 → 0.6.0-rc.1

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.
Files changed (65) hide show
  1. package/bundle/_internal/base_library.zip +0 -0
  2. package/bundle/_internal/certifi/cacert.pem +3885 -0
  3. package/bundle/_internal/gnost/__init__.py +1 -1
  4. package/bundle/_internal/gnost/analysis/analyzers/readability_analyzer.py +4 -1
  5. package/bundle/_internal/gnost/analysis/utils/tool_command.py +8 -0
  6. package/bundle/_internal/gnost/changes/__init__.py +1 -0
  7. package/bundle/_internal/gnost/changes/analyzer.py +215 -0
  8. package/bundle/_internal/gnost/changes/findings.py +55 -0
  9. package/bundle/_internal/gnost/changes/impact.py +59 -0
  10. package/bundle/_internal/gnost/changes/refs.py +105 -0
  11. package/bundle/_internal/gnost/changes/render.py +172 -0
  12. package/bundle/_internal/gnost/changes/report.py +124 -0
  13. package/bundle/_internal/gnost/changes/snapshot.py +109 -0
  14. package/bundle/_internal/gnost/ci/__init__.py +1 -0
  15. package/bundle/_internal/gnost/ci/baseline.py +88 -0
  16. package/bundle/_internal/gnost/ci/exit_codes.py +19 -0
  17. package/bundle/_internal/gnost/ci/fingerprint.py +44 -0
  18. package/bundle/_internal/gnost/ci/gate.py +42 -0
  19. package/bundle/_internal/gnost/ci/paths.py +57 -0
  20. package/bundle/_internal/gnost/ci/run.py +135 -0
  21. package/bundle/_internal/gnost/ci/sarif.py +149 -0
  22. package/bundle/_internal/gnost/ci/scorecard.py +95 -0
  23. package/bundle/_internal/gnost/cli/app.py +406 -155
  24. package/bundle/_internal/gnost/cli/commands/changes.py +144 -0
  25. package/bundle/_internal/gnost/cli/commands/init.py +192 -0
  26. package/bundle/_internal/gnost/cli/commands/onboard.py +83 -27
  27. package/bundle/_internal/gnost/cli/commands/remote.py +53 -0
  28. package/bundle/_internal/gnost/cli/commands/show.py +15 -14
  29. package/bundle/_internal/gnost/config/languages.py +19 -4
  30. package/bundle/_internal/gnost/config/settings.py +127 -2
  31. package/bundle/_internal/gnost/core/flow.py +27 -0
  32. package/bundle/_internal/gnost/core/insight_builder.py +3 -1
  33. package/bundle/_internal/gnost/core/risk.py +115 -0
  34. package/bundle/_internal/gnost/reporters/insights_json.py +65 -1
  35. package/bundle/_internal/gnost/reporters/loc_summary.py +3 -3
  36. package/bundle/_internal/gnost/reporters/markdown.py +89 -10
  37. package/bundle/_internal/gnost/reporters/mermaid.py +7 -0
  38. package/bundle/_internal/gnost/reporters/readme.py +11 -6
  39. package/bundle/_internal/gnost/reporters/stats.py +3 -3
  40. package/bundle/_internal/gnost/reporters/summary.py +48 -1
  41. package/bundle/_internal/gnost/scanner/filters.py +45 -12
  42. package/bundle/_internal/gnost/scanner/loc.py +5 -0
  43. package/bundle/_internal/gnost/schemas/insights.schema.json +153 -0
  44. package/bundle/_internal/gnost/utils/footer.py +36 -0
  45. package/bundle/_internal/gnost/utils/integrations.py +346 -0
  46. package/bundle/_internal/gnost/utils/layout.py +111 -0
  47. package/bundle/_internal/gnost/utils/progress.py +6 -3
  48. package/bundle/_internal/gnost/utils/update_check.py +253 -0
  49. package/bundle/_internal/gnost/vcs/__init__.py +1 -0
  50. package/bundle/_internal/gnost/vcs/git.py +181 -0
  51. package/bundle/_internal/gnost/vcs/history.py +404 -0
  52. package/bundle/_internal/gnost/vcs/remote.py +204 -0
  53. package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/METADATA +7 -4
  54. package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/RECORD +88 -30
  55. package/bundle/_internal/gnost-0.6.0rc1.dist-info/REQUESTED +0 -0
  56. package/bundle/_internal/yaml/_yaml.cpython-312-darwin.so +0 -0
  57. package/bundle/gnost +0 -0
  58. package/package.json +1 -1
  59. /package/bundle/_internal/{gnost-0.5.3.dist-info/REQUESTED → certifi/py.typed} +0 -0
  60. /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/INSTALLER +0 -0
  61. /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/WHEEL +0 -0
  62. /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/direct_url.json +0 -0
  63. /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/entry_points.txt +0 -0
  64. /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/licenses/LICENSE +0 -0
  65. /package/bundle/_internal/{gnost-0.5.3.dist-info → gnost-0.6.0rc1.dist-info}/top_level.txt +0 -0
@@ -4,12 +4,16 @@ import re
4
4
  GNOST_START = "<!-- GNOST:ONBOARDING:START -->"
5
5
  GNOST_END = "<!-- GNOST:ONBOARDING:END -->"
6
6
 
7
- GNOST_BLOCK = f"""{GNOST_START}
7
+ DEFAULT_LINK = "./.gnost/ONBOARD.md"
8
+
9
+
10
+ def render_block(link: str = DEFAULT_LINK) -> str:
11
+ return f"""{GNOST_START}
8
12
 
9
13
  ## Onboarding
10
14
  This repository includes an **auto-generated onboarding guide**
11
15
 
12
- [![Onboarding](https://img.shields.io/badge/onboarding-ONBOARD.md-cyan)](./ONBOARD.md)
16
+ [![Onboarding](https://img.shields.io/badge/onboarding-ONBOARD.md-cyan)]({link})
13
17
 
14
18
  Generated by <a href="https://gnost.readthedocs.io">GNOST</a> to help understand the codebase.
15
19
 
@@ -22,8 +26,9 @@ class ReadmeInjector:
22
26
  Safely injects or updates a GNOST-managed onboarding block in README.md
23
27
  """
24
28
 
25
- def __init__(self, root: str):
29
+ def __init__(self, root: str, link: str = DEFAULT_LINK):
26
30
  self.readme_path = Path(root) / "README.md"
31
+ self.block = render_block(link)
27
32
 
28
33
  # -------------------------
29
34
  # Public API
@@ -60,7 +65,7 @@ class ReadmeInjector:
60
65
  def _update_block(self, content: str) -> str:
61
66
  return re.sub(
62
67
  rf"{GNOST_START}.*?{GNOST_END}",
63
- GNOST_BLOCK,
68
+ lambda _match: self.block,
64
69
  content,
65
70
  flags=re.DOTALL,
66
71
  )
@@ -75,7 +80,7 @@ class ReadmeInjector:
75
80
  for i, line in enumerate(lines):
76
81
  # Detect H2 heading (## but not ###)
77
82
  if line.startswith("## ") and not line.startswith("###"):
78
- return "\n".join(lines[:i] + [""] + [GNOST_BLOCK] + [""] + lines[i:])
83
+ return "\n".join(lines[:i] + [""] + [self.block] + [""] + lines[i:])
79
84
 
80
85
  # No H2 found → append at end
81
- return content.rstrip() + "\n\n" + GNOST_BLOCK + "\n"
86
+ return content.rstrip() + "\n\n" + self.block + "\n"
@@ -1,12 +1,12 @@
1
1
  from rich.console import Console
2
- from gnost.config.languages import LANGUAGES
2
+ from gnost.config.languages import by_language_name
3
3
 
4
4
  console = Console()
5
5
 
6
6
 
7
7
  def render(data):
8
- for ext, stats in data["by_language"].items():
9
- console.print(f"[bold]{LANGUAGES[ext]['name']}[/bold]")
8
+ for name, stats in by_language_name(data["by_language"]).items():
9
+ console.print(f"[bold]{name}[/bold]")
10
10
  console.print(f" files : {stats['files']}")
11
11
  console.print(f" code : {stats['code']}")
12
12
  console.print(f" comments : {stats['comments']}")
@@ -22,7 +22,13 @@ class SummaryReporter:
22
22
  graph: DependencyGraph,
23
23
  printer: Optional[Printer] = None,
24
24
  insights: OnboardingInsights = None,
25
+ changes=None,
26
+ risks=None,
27
+ root_label: Optional[str] = None,
25
28
  ):
29
+ self.root_label = root_label or scan.root
30
+ self.changes = changes
31
+ self.risks = risks
26
32
  self.scan = scan
27
33
  self.flow = flow
28
34
  self.graph = graph
@@ -45,12 +51,53 @@ class SummaryReporter:
45
51
  if self.insights:
46
52
  self._first_files()
47
53
  self._caution_areas()
54
+ self._change_hotspots()
55
+ self._risk()
48
56
  self._cycles()
49
57
 
50
58
  # -------------------------
51
59
  # Sections
52
60
  # -------------------------
53
61
 
62
+ CHANGE_HOTSPOT_LIMIT = 5
63
+
64
+ def _change_hotspots(self) -> None:
65
+ """Print the most-changed files, or why there is no history worth mentioning."""
66
+ changes = self.changes
67
+ if changes is None:
68
+ return
69
+ if not changes.history.available:
70
+ if changes.note_worth_showing:
71
+ self.printer.section("Change Hotspots")
72
+ self.printer.text(f"Not available: {changes.history.reason}")
73
+ self.printer.newline()
74
+ return
75
+ if not changes.hotspots:
76
+ return
77
+ self.printer.section(
78
+ f"Change Hotspots (last {changes.history.window_days} days)"
79
+ )
80
+ for h in changes.hotspots[: self.CHANGE_HOTSPOT_LIMIT]:
81
+ c = h.change
82
+ self.printer.bullet(
83
+ f"{c.path} ({c.commits} commits, {c.author_count} authors, "
84
+ f"{c.recent_commits} recent)"
85
+ )
86
+ self.printer.newline()
87
+
88
+ def _risk(self) -> None:
89
+ """Print the files that are both fragile and changing."""
90
+ risks = self.risks
91
+ if risks is None or not risks.items:
92
+ return
93
+ self.printer.section("Risky and Changing")
94
+ for i in risks.items[: self.CHANGE_HOTSPOT_LIMIT]:
95
+ self.printer.bullet(
96
+ f"{i.path} (risk {i.risk:g}: caution {i.structural:g}, "
97
+ f"change {i.churn:g}; {i.why})"
98
+ )
99
+ self.printer.newline()
100
+
54
101
  def _header(self):
55
102
  self.printer.title("GNOST — Project Onboarding Summary")
56
103
 
@@ -61,7 +108,7 @@ class SummaryReporter:
61
108
  f"{lang} ({count})" for lang, count in self.scan.languages.items()
62
109
  )
63
110
 
64
- self.printer.kv("Root", self.scan.root)
111
+ self.printer.kv("Root", self.root_label)
65
112
  self.printer.kv("Languages", languages or "Unknown")
66
113
  self.printer.kv("Framework", self.scan.framework or "Not detected")
67
114
  self.printer.newline()
@@ -16,6 +16,7 @@ DEFAULT_EXCLUDES = {
16
16
  "target",
17
17
  ".gradle",
18
18
  "__pycache__",
19
+ ".gnost",
19
20
  }
20
21
 
21
22
 
@@ -46,6 +47,7 @@ IGNORE_DIRS = {
46
47
  ".gradle",
47
48
  ".idea",
48
49
  "out",
50
+ ".gnost",
49
51
  }
50
52
 
51
53
  IGNORE_FILES = {
@@ -85,27 +87,54 @@ def load_gitignore(root: str) -> list[str]:
85
87
  return patterns
86
88
 
87
89
 
90
+ def _matches(pattern: str, rel_path: str, is_dir: bool) -> bool:
91
+ """Whether one .gitignore pattern covers rel_path, following git's rules.
92
+
93
+ No slash (but a trailing one): any depth. A slash: relative to the root. A trailing slash: folders only.
94
+ """
95
+ rule = pattern.replace("\\", "/")
96
+ dir_only = rule.endswith("/")
97
+ rule = rule.rstrip("/")
98
+ anchored = "/" in rule
99
+ rule = rule.lstrip("/")
100
+ parts = rel_path.split("/")
101
+
102
+ if not anchored:
103
+ for index, part in enumerate(parts):
104
+ is_last = index == len(parts) - 1
105
+ if dir_only and is_last and not is_dir:
106
+ continue
107
+ if fnmatch.fnmatch(part, rule):
108
+ return True
109
+ return False
110
+
111
+ if rule.startswith("**/"):
112
+ tail = rule[3:]
113
+ return any(
114
+ fnmatch.fnmatch("/".join(parts[i:]), tail)
115
+ or fnmatch.fnmatch("/".join(parts[i:]), tail + "/*")
116
+ for i in range(len(parts))
117
+ )
118
+ if fnmatch.fnmatch(rel_path, rule) or rel_path.startswith(rule + "/"):
119
+ return not (dir_only and rel_path == rule and not is_dir)
120
+ return any(
121
+ fnmatch.fnmatch("/".join(parts[: i + 1]), rule) for i in range(len(parts) - 1)
122
+ )
123
+
124
+
88
125
  def is_gitignored(path: str, root: str, patterns: list[str]) -> bool:
126
+ """True if the .gitignore patterns cover path (the last matching pattern wins)."""
89
127
  if not patterns:
90
128
  return False
91
129
 
92
130
  rel_path = os.path.relpath(path, root).replace(os.sep, "/")
131
+ is_dir = os.path.isdir(path)
93
132
  ignored = False
94
133
 
95
134
  for pat in patterns:
96
135
  negate = pat.startswith("!")
97
136
  rule = pat[1:] if negate else pat
98
- rule = rule.replace("\\", "/")
99
-
100
- if rule.endswith("/"):
101
- rule = rule.rstrip("/")
102
- match = rel_path == rule or rel_path.startswith(rule + "/")
103
- else:
104
- match = fnmatch.fnmatch(rel_path, rule) or fnmatch.fnmatch(
105
- os.path.basename(rel_path), rule
106
- )
107
-
108
- if match:
137
+ if _matches(rule, rel_path, is_dir):
109
138
  ignored = not negate
110
139
 
111
140
  return ignored
@@ -185,7 +214,11 @@ def is_excluded(path: str, root: str, patterns: "list[str]") -> bool:
185
214
  rel = os.path.relpath(path, root).replace(os.sep, "/")
186
215
  parts = rel.split("/")
187
216
  for pattern in patterns:
188
- pat = pattern.strip().rstrip("/").lstrip("./")
217
+ pat = pattern.strip().rstrip("/")
218
+ while pat.startswith(
219
+ "./"
220
+ ): # not lstrip("./"): it would turn ".gnost" into "gnost"
221
+ pat = pat[2:]
189
222
  if not pat:
190
223
  continue
191
224
  if fnmatch.fnmatch(rel, pat) or fnmatch.fnmatch(parts[-1], pat):
@@ -5,6 +5,7 @@ from gnost.scanner.classify import classify_lines
5
5
  from gnost.scanner.filters import (
6
6
  DEFAULT_EXCLUDES,
7
7
  is_gitignored,
8
+ is_noise_file,
8
9
  is_virtualenv_dir,
9
10
  load_gitignore,
10
11
  should_skip,
@@ -46,6 +47,10 @@ def scan(path=".", include=None, exclude=None, progress=False):
46
47
  if is_gitignored(full_path, path, gitignore):
47
48
  continue
48
49
 
50
+ # Vendored libraries and minified bundles are not the project's code.
51
+ if is_noise_file(full_path, path):
52
+ continue
53
+
49
54
  try:
50
55
  with open(full_path, "r", encoding="utf-8", errors="ignore") as f:
51
56
  lines = f.readlines()
@@ -472,6 +472,159 @@
472
472
  "$ref": "#/definitions/paths"
473
473
  }
474
474
  }
475
+ },
476
+ "change_history": {
477
+ "type": "object",
478
+ "description": "Change hotspots from git history. `available` is false (with a `reason`) when there is no usable history.",
479
+ "required": [
480
+ "available",
481
+ "reason",
482
+ "window_days",
483
+ "commits_analyzed",
484
+ "files"
485
+ ],
486
+ "additionalProperties": false,
487
+ "properties": {
488
+ "available": {
489
+ "type": "boolean"
490
+ },
491
+ "reason": {
492
+ "type": [
493
+ "string",
494
+ "null"
495
+ ]
496
+ },
497
+ "window_days": {
498
+ "type": "integer",
499
+ "minimum": 0
500
+ },
501
+ "commits_analyzed": {
502
+ "type": "integer",
503
+ "minimum": 0
504
+ },
505
+ "files": {
506
+ "type": "array",
507
+ "items": {
508
+ "type": "object",
509
+ "required": [
510
+ "path",
511
+ "score",
512
+ "commits",
513
+ "authors",
514
+ "recent_commits",
515
+ "lines_added",
516
+ "lines_removed",
517
+ "last_changed"
518
+ ],
519
+ "additionalProperties": false,
520
+ "properties": {
521
+ "path": {
522
+ "type": "string"
523
+ },
524
+ "score": {
525
+ "type": "number",
526
+ "minimum": 0,
527
+ "maximum": 100
528
+ },
529
+ "commits": {
530
+ "type": "integer",
531
+ "minimum": 1
532
+ },
533
+ "authors": {
534
+ "type": "integer",
535
+ "minimum": 1
536
+ },
537
+ "recent_commits": {
538
+ "type": "integer",
539
+ "minimum": 0
540
+ },
541
+ "lines_added": {
542
+ "type": "integer",
543
+ "minimum": 0
544
+ },
545
+ "lines_removed": {
546
+ "type": "integer",
547
+ "minimum": 0
548
+ },
549
+ "last_changed": {
550
+ "type": "string",
551
+ "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
552
+ }
553
+ }
554
+ }
555
+ }
556
+ }
557
+ },
558
+ "risk": {
559
+ "type": "object",
560
+ "description": "Files that are both fragile to change (caution score) and changing often (change hotspots). Empty without git history.",
561
+ "required": [
562
+ "threshold",
563
+ "files"
564
+ ],
565
+ "additionalProperties": false,
566
+ "properties": {
567
+ "threshold": {
568
+ "type": "number",
569
+ "minimum": 0,
570
+ "maximum": 100
571
+ },
572
+ "files": {
573
+ "type": "array",
574
+ "items": {
575
+ "type": "object",
576
+ "required": [
577
+ "path",
578
+ "risk",
579
+ "structural_score",
580
+ "change_score",
581
+ "commits",
582
+ "authors",
583
+ "recent_commits",
584
+ "reasons"
585
+ ],
586
+ "additionalProperties": false,
587
+ "properties": {
588
+ "path": {
589
+ "type": "string"
590
+ },
591
+ "risk": {
592
+ "type": "number",
593
+ "minimum": 0,
594
+ "maximum": 100
595
+ },
596
+ "structural_score": {
597
+ "type": "number",
598
+ "minimum": 0,
599
+ "maximum": 100
600
+ },
601
+ "change_score": {
602
+ "type": "number",
603
+ "minimum": 0,
604
+ "maximum": 100
605
+ },
606
+ "commits": {
607
+ "type": "integer",
608
+ "minimum": 1
609
+ },
610
+ "authors": {
611
+ "type": "integer",
612
+ "minimum": 1
613
+ },
614
+ "recent_commits": {
615
+ "type": "integer",
616
+ "minimum": 0
617
+ },
618
+ "reasons": {
619
+ "type": "array",
620
+ "items": {
621
+ "type": "string"
622
+ }
623
+ }
624
+ }
625
+ }
626
+ }
627
+ }
475
628
  }
476
629
  },
477
630
  "definitions": {
@@ -0,0 +1,36 @@
1
+ """The "Generated by GNOST" line added to the Markdown files GNOST writes.
2
+
3
+ `Footer` builds that line (it can be switched off with `footer = false` in `.gnost.toml`) and
4
+ appends it to a document. People who open the file without knowing the tool learn what made it
5
+ and how to run it themselves.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from gnost import __version__
11
+
12
+ HOME_URL = "https://gnost.readthedocs.io"
13
+ TRY_IT = "npx gnost-cli onboard ."
14
+
15
+
16
+ class Footer:
17
+ """One footer line; empty when disabled."""
18
+
19
+ def __init__(self, enabled: bool = True, version: str = __version__) -> None:
20
+ self.enabled = enabled
21
+ self.version = version
22
+
23
+ def line(self) -> str:
24
+ """The footer as one Markdown line, or an empty string when switched off."""
25
+ if not self.enabled:
26
+ return ""
27
+ return (
28
+ f"<sub>Generated by [GNOST]({HOME_URL}) {self.version}. "
29
+ f"Try it on your own code: `{TRY_IT}`</sub>"
30
+ )
31
+
32
+ def append(self, text: str) -> str:
33
+ """The text followed by a rule and the footer; unchanged when disabled."""
34
+ if not self.enabled:
35
+ return text
36
+ return text.rstrip("\n") + f"\n\n---\n\n{self.line()}\n"