codeveto 0.1.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.
Files changed (106) hide show
  1. codeveto/__init__.py +3 -0
  2. codeveto/__main__.py +8 -0
  3. codeveto/ai/__init__.py +19 -0
  4. codeveto/ai/harness.py +303 -0
  5. codeveto/ai/packets.py +855 -0
  6. codeveto/ai/policy.py +222 -0
  7. codeveto/ai/prompt.py +101 -0
  8. codeveto/ai/providers/__init__.py +178 -0
  9. codeveto/ai/providers/claude.py +247 -0
  10. codeveto/ai/providers/openai_compat.py +246 -0
  11. codeveto/ai/runner.py +293 -0
  12. codeveto/ai/verify.py +324 -0
  13. codeveto/anchor.py +211 -0
  14. codeveto/cli.py +247 -0
  15. codeveto/cli_explain.py +49 -0
  16. codeveto/cli_hook.py +31 -0
  17. codeveto/cli_init.py +254 -0
  18. codeveto/cli_mcp.py +29 -0
  19. codeveto/cli_packets.py +35 -0
  20. codeveto/cli_publish.py +29 -0
  21. codeveto/cli_review.py +362 -0
  22. codeveto/cli_rules.py +78 -0
  23. codeveto/cli_verify.py +47 -0
  24. codeveto/config.py +1229 -0
  25. codeveto/data/README.md +16 -0
  26. codeveto/data/ai-wire.schema.json +53 -0
  27. codeveto/data/prompts/system.md +57 -0
  28. codeveto/data/report-v1.schema.json +268 -0
  29. codeveto/data/templates/forgejo-codeveto.yml +104 -0
  30. codeveto/data/templates/github-codeveto.yml +18 -0
  31. codeveto/embedded.py +311 -0
  32. codeveto/engine.py +1570 -0
  33. codeveto/git.py +1549 -0
  34. codeveto/globs.py +348 -0
  35. codeveto/integrations/__init__.py +1 -0
  36. codeveto/integrations/hooks.py +327 -0
  37. codeveto/integrations/mcp.py +770 -0
  38. codeveto/integrations/mcp_ai.py +77 -0
  39. codeveto/integrations/prepush.py +222 -0
  40. codeveto/jsonsafe.py +60 -0
  41. codeveto/languages.py +539 -0
  42. codeveto/lexers.py +2560 -0
  43. codeveto/model.py +372 -0
  44. codeveto/publish/__init__.py +28 -0
  45. codeveto/publish/action.py +330 -0
  46. codeveto/publish/common.py +84 -0
  47. codeveto/publish/diff.py +208 -0
  48. codeveto/publish/event.py +241 -0
  49. codeveto/publish/forgejo.py +184 -0
  50. codeveto/publish/github.py +380 -0
  51. codeveto/publish/http.py +263 -0
  52. codeveto/publish/pull.py +218 -0
  53. codeveto/publish/untrusted.py +110 -0
  54. codeveto/py.typed +0 -0
  55. codeveto/redact.py +113 -0
  56. codeveto/render/__init__.py +64 -0
  57. codeveto/render/agent.py +43 -0
  58. codeveto/render/github.py +101 -0
  59. codeveto/render/json.py +23 -0
  60. codeveto/render/markdown.py +208 -0
  61. codeveto/render/safe.py +249 -0
  62. codeveto/render/sarif.py +217 -0
  63. codeveto/render/text.py +210 -0
  64. codeveto/report.py +252 -0
  65. codeveto/rules/__init__.py +84 -0
  66. codeveto/rules/agent.py +2972 -0
  67. codeveto/rules/base.py +1026 -0
  68. codeveto/rules/ci.py +1708 -0
  69. codeveto/rules/config.py +493 -0
  70. codeveto/rules/deps.py +1693 -0
  71. codeveto/rules/docker.py +479 -0
  72. codeveto/rules/examples/__init__.py +148 -0
  73. codeveto/rules/examples/agent.py +839 -0
  74. codeveto/rules/examples/ci.py +1046 -0
  75. codeveto/rules/examples/config.py +191 -0
  76. codeveto/rules/examples/deps.py +369 -0
  77. codeveto/rules/examples/docker.py +157 -0
  78. codeveto/rules/examples/go.py +241 -0
  79. codeveto/rules/examples/hygiene.py +466 -0
  80. codeveto/rules/examples/js.py +462 -0
  81. codeveto/rules/examples/python.py +595 -0
  82. codeveto/rules/examples/rust.py +268 -0
  83. codeveto/rules/examples/secrets.py +561 -0
  84. codeveto/rules/examples/security.py +608 -0
  85. codeveto/rules/examples/shell.py +174 -0
  86. codeveto/rules/examples/sql.py +194 -0
  87. codeveto/rules/examples/tests.py +497 -0
  88. codeveto/rules/go.py +328 -0
  89. codeveto/rules/hygiene.py +1094 -0
  90. codeveto/rules/js.py +768 -0
  91. codeveto/rules/python.py +1642 -0
  92. codeveto/rules/rust.py +209 -0
  93. codeveto/rules/secrets.py +1335 -0
  94. codeveto/rules/security.py +3680 -0
  95. codeveto/rules/shell.py +867 -0
  96. codeveto/rules/sql.py +629 -0
  97. codeveto/rules/tests.py +1404 -0
  98. codeveto/schema.py +384 -0
  99. codeveto/statements.py +607 -0
  100. codeveto/worktree.py +1176 -0
  101. codeveto/yamlish.py +1179 -0
  102. codeveto-0.1.0.dist-info/METADATA +253 -0
  103. codeveto-0.1.0.dist-info/RECORD +106 -0
  104. codeveto-0.1.0.dist-info/WHEEL +4 -0
  105. codeveto-0.1.0.dist-info/entry_points.txt +2 -0
  106. codeveto-0.1.0.dist-info/licenses/LICENSE +21 -0
codeveto/rules/rust.py ADDED
@@ -0,0 +1,209 @@
1
+ """Rust pack (SPEC 6.1, 6.5): language bug patterns.
2
+
3
+ Every rule matches the changed lines of ``masked_code``, so strings, raw
4
+ strings, char literals and comments (doc comments and their doctests
5
+ included) never match. Test code is ``#[cfg(test)]`` items
6
+ (``FileContext.in_test_region``) and files of the ``test`` class
7
+ (``tests/``); the rules that tolerate panicking in tests skip both.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import dataclasses
13
+ import re
14
+ from collections.abc import Iterator
15
+
16
+ from codeveto.rules.base import FileContext, Hit, Severity, rule
17
+
18
+ _TODO = re.compile(r"(?<![\w$])(?:todo|unimplemented)[ \t]*![ \t]*[(\[{]")
19
+ _DBG = re.compile(r"(?<![\w$])dbg[ \t]*![ \t]*[(\[{]")
20
+ _UNSAFE = re.compile(r"(?<![\w$])unsafe[ \t]*\{")
21
+ _UNWRAP = re.compile(r"\.[ \t]*unwrap[ \t]*\([ \t]*\)")
22
+ _PANIC = re.compile(r"(?<![\w$])panic[ \t]*![ \t]*[(\[{]")
23
+ _TRANSMUTE = re.compile(r"(?<![\w$])transmute(?:_copy)?[ \t]*(?:::[ \t]*<|\()")
24
+ _ALLOW = re.compile(r"#[ \t]*!?[ \t]*\[[ \t]*allow[ \t]*\(")
25
+ _NAMING_LINTS = frozenset({"non_snake_case", "non_camel_case_types", "non_upper_case_globals"})
26
+
27
+ _SCRIPT_DIRS = ("examples/", "benches/")
28
+
29
+
30
+ def _scripts(path: str) -> bool:
31
+ """Build scripts, examples and benchmarks: programs where panicking is the idiom."""
32
+ name = path.rsplit("/", 1)[-1]
33
+ return name == "build.rs" or any(path.startswith(d) or f"/{d}" in path for d in _SCRIPT_DIRS)
34
+
35
+
36
+ def _masked_lines(ctx: FileContext) -> Iterator[tuple[int, str]]:
37
+ """``(line, masked text)`` of each added line."""
38
+ masked = ctx.masked_code
39
+ if not masked:
40
+ return
41
+ index = ctx.line_index
42
+ for number in sorted(ctx.added_lines):
43
+ if number > index.line_count:
44
+ continue
45
+ start = index.line_start(number)
46
+ end = masked.find("\n", start)
47
+ yield number, masked[start : end if end >= 0 else len(masked)]
48
+
49
+
50
+ def _find(
51
+ ctx: FileContext, pattern: re.Pattern[str], *, skip_tests: bool, label: str
52
+ ) -> Iterator[Hit]:
53
+ for number, text in _masked_lines(ctx):
54
+ m = pattern.search(text)
55
+ if m is None or (skip_tests and ctx.in_test_region(number)):
56
+ continue
57
+ yield Hit(
58
+ number,
59
+ column=m.start() + 1,
60
+ evidence=f"{label}: {' '.join(text.split())[:300]}",
61
+ )
62
+
63
+
64
+ @rule(
65
+ id="rust/todo-macro",
66
+ severity="error",
67
+ title="todo!() or unimplemented!() in non-test code",
68
+ languages={"rust"},
69
+ classes={"source"},
70
+ rationale=(
71
+ "`todo!()` and `unimplemented!()` compile and then panic when reached, so an "
72
+ "unfinished path ships as a crash. Test files and `#[cfg(test)]` code are not "
73
+ "reported. `unimplemented!()` is a warning: libraries also use it on purpose for "
74
+ "trait methods a type cannot support, while `todo!()` always marks unfinished work."
75
+ ),
76
+ hint="Implement the path, or return an error the caller can handle.",
77
+ tags={"rust", "correctness"},
78
+ )
79
+ def todo_macro(ctx: FileContext) -> Iterator[Hit]:
80
+ """``todo!`` (error) and ``unimplemented!`` (warning) outside test code."""
81
+ for hit in _find(ctx, _TODO, skip_tests=True, label="todo"):
82
+ line = ctx.lines[hit.line - 1] if hit.line is not None else ""
83
+ macro = line[(hit.column or 1) - 1 :]
84
+ if macro.startswith("unimplemented"):
85
+ hit = dataclasses.replace(hit, severity=Severity.WARNING)
86
+ yield hit
87
+
88
+
89
+ @rule(
90
+ id="rust/dbg-macro",
91
+ severity="error",
92
+ title="dbg!() left in the code",
93
+ languages={"rust"},
94
+ rationale=(
95
+ "`dbg!` is a debugging aid: it prints file, line and value to stderr in every "
96
+ "build, release included, and `clippy::dbg_macro` exists to keep it out of "
97
+ "committed code."
98
+ ),
99
+ hint="Remove it, or log the value through the crate's logger.",
100
+ tags={"rust", "hygiene"},
101
+ )
102
+ def dbg_macro(ctx: FileContext) -> Iterator[Hit]:
103
+ """Any ``dbg!(...)``."""
104
+ yield from _find(ctx, _DBG, skip_tests=False, label="dbg")
105
+
106
+
107
+ @rule(
108
+ id="rust/unsafe-block",
109
+ severity="warning",
110
+ title="New unsafe block",
111
+ languages={"rust"},
112
+ rationale=(
113
+ "Inside `unsafe { ... }` the compiler no longer checks memory safety; each block "
114
+ "needs a reviewer to check the invariants it relies on (ideally written down in a "
115
+ "`// SAFETY:` comment)."
116
+ ),
117
+ hint="Prefer a safe API; otherwise document the invariant in a // SAFETY: comment.",
118
+ tags={"rust", "security", "memory-safety"},
119
+ )
120
+ def unsafe_block(ctx: FileContext) -> Iterator[Hit]:
121
+ """``unsafe {`` (blocks, not ``unsafe fn`` or ``unsafe impl`` declarations)."""
122
+ yield from _find(ctx, _UNSAFE, skip_tests=False, label="unsafe")
123
+
124
+
125
+ @rule(
126
+ id="rust/unwrap",
127
+ severity="warning",
128
+ title=".unwrap() outside tests",
129
+ languages={"rust"},
130
+ classes={"source"},
131
+ rationale=(
132
+ "`.unwrap()` panics on `None` or `Err` without saying why. Tests, `#[cfg(test)]` "
133
+ "code, build scripts (`build.rs`), `examples/` and `benches/` are not reported; "
134
+ '`.expect("why")` documents the invariant and is not reported either.'
135
+ ),
136
+ hint='Propagate with ?, handle the case, or use .expect("reason it cannot fail").',
137
+ tags={"rust", "robustness"},
138
+ )
139
+ def unwrap(ctx: FileContext) -> Iterator[Hit]:
140
+ """``.unwrap()`` outside test and script code."""
141
+ if not _scripts(ctx.path):
142
+ yield from _find(ctx, _UNWRAP, skip_tests=True, label="unwrap")
143
+
144
+
145
+ @rule(
146
+ id="rust/panic",
147
+ severity="warning",
148
+ title="panic!() outside tests",
149
+ languages={"rust"},
150
+ classes={"source"},
151
+ rationale=(
152
+ '`panic!` aborts the thread (or the process with panic = "abort"); library code '
153
+ "returns `Result` instead. Tests, `#[cfg(test)]` code, `build.rs`, `examples/` "
154
+ "and `benches/` are not reported."
155
+ ),
156
+ hint="Return an error, or document why the state is impossible.",
157
+ tags={"rust", "robustness"},
158
+ )
159
+ def panic(ctx: FileContext) -> Iterator[Hit]:
160
+ """``panic!(...)`` outside test and script code."""
161
+ if not _scripts(ctx.path):
162
+ yield from _find(ctx, _PANIC, skip_tests=True, label="panic")
163
+
164
+
165
+ @rule(
166
+ id="rust/transmute",
167
+ severity="warning",
168
+ title="mem::transmute",
169
+ languages={"rust"},
170
+ rationale=(
171
+ "`transmute` reinterprets bits as another type with no checks; a size, alignment "
172
+ "or validity mistake is undefined behaviour. Safe conversions (`from_ne_bytes`, "
173
+ "`as`, `bytemuck`) cover most uses."
174
+ ),
175
+ hint="Use a safe conversion, or document the layout guarantee being relied on.",
176
+ tags={"rust", "security", "memory-safety"},
177
+ )
178
+ def transmute(ctx: FileContext) -> Iterator[Hit]:
179
+ """``transmute(...)``, ``transmute::<..>`` and ``transmute_copy``."""
180
+ yield from _find(ctx, _TRANSMUTE, skip_tests=False, label="transmute")
181
+
182
+
183
+ @rule(
184
+ id="rust/allow-attribute",
185
+ severity="note",
186
+ title="Lint silenced with #[allow(...)]",
187
+ languages={"rust"},
188
+ rationale=(
189
+ "`#[allow(...)]` and `#![allow(...)]` turn off compiler or clippy lints for an "
190
+ "item or a whole module; worth a look to see that the lint is wrong here, not "
191
+ "inconvenient. An allow of naming lints only (non_snake_case, non_camel_case_types, "
192
+ "non_upper_case_globals) is not reported: FFI bindings use it to keep C's names, and "
193
+ "it was 90% of the hits in the Cargo registry."
194
+ ),
195
+ hint="Fix the lint, or use #[expect(...)] with a reason so it is revisited.",
196
+ tags={"rust", "hygiene"},
197
+ )
198
+ def allow_attribute(ctx: FileContext) -> Iterator[Hit]:
199
+ """``#[allow(`` and ``#![allow(``, unless the list names only naming lints."""
200
+ lines = ctx.lines
201
+ for hit in _find(ctx, _ALLOW, skip_tests=False, label="allow"):
202
+ line = lines[hit.line - 1] if hit.line is not None else ""
203
+ rest = line[(hit.column or 1) - 1 :]
204
+ start, close = rest.find("("), rest.find(")")
205
+ if 0 <= start < close:
206
+ names = [n.strip() for n in rest[start + 1 : close].split(",") if n.strip()]
207
+ if names and all(n in _NAMING_LINTS for n in names):
208
+ continue
209
+ yield hit