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
@@ -0,0 +1,174 @@
1
+ """Examples for the shell pack."""
2
+
3
+ from codeveto.rules.base import bad, good
4
+
5
+ EXAMPLES = {
6
+ "shell/rm-rf-variable": [
7
+ bad(
8
+ "scripts/clean.sh",
9
+ "#!/bin/bash\n"
10
+ 'STEAMROOT="$(cd "${0%/*}" && echo "$PWD")"\n'
11
+ 'rm -rf "$STEAMROOT/"* # expect\n',
12
+ note="If the cd fails the substitution is empty and this deletes /*.",
13
+ ),
14
+ bad(
15
+ "scripts/uninstall.sh",
16
+ "#!/bin/sh\n"
17
+ "uninstall() {\n"
18
+ ' local prefix="$1"\n'
19
+ " rm -fr ${prefix}/lib/app # expect\n"
20
+ ' sudo rm --recursive --force "${prefix}/share/app" # expect\n'
21
+ "}\n",
22
+ note="A function argument can be empty; every spelling of the flags counts.",
23
+ ),
24
+ bad(
25
+ "Dockerfile",
26
+ "FROM debian:12.5\n"
27
+ "ARG CACHE_DIR\n"
28
+ "RUN apt-get update \\\n"
29
+ " && rm -rf $CACHE_DIR/* # expect\n"
30
+ "USER nobody\n",
31
+ note="Dockerfile RUN commands are shell too; an ARG without a default is empty.",
32
+ ),
33
+ good(
34
+ "scripts/clean.sh",
35
+ "#!/usr/bin/env bash\n"
36
+ "set -euo pipefail\n"
37
+ 'BUILD_DIR="${1:?usage: clean.sh DIR}"\n'
38
+ 'rm -rf "$BUILD_DIR/"*\n'
39
+ 'rm -rf "${OUT_DIR:?}/cache"\n'
40
+ "tmp=$(mktemp -d)\n"
41
+ "trap 'rm -rf \"$tmp\"' EXIT\n"
42
+ 'rm -rf "$tmp/stage"\n',
43
+ note="set -u, ${VAR:?} and mktemp all rule out an empty value.",
44
+ ),
45
+ good(
46
+ "scripts/reset.sh",
47
+ "#!/bin/sh\n"
48
+ "DIST=dist\n"
49
+ 'rm -rf "$DIST/"*\n'
50
+ 'rm -rf "$workdir"\n'
51
+ 'rm -rf ./build /var/lib/apt/lists/*\n'
52
+ '[ -n "$CACHE" ] && rm -rf "$CACHE/tmp"\n'
53
+ 'echo "never run rm -rf $HOME/ by hand" # rm -rf $X/\n'
54
+ 'rm -rf "$HOME/.cache/app"\n',
55
+ note="A literal assignment, a bare operand, constant paths, a -n check, text in "
56
+ "strings and comments, and HOME are fine.",
57
+ ),
58
+ ],
59
+ "shell/curl-pipe-shell": [
60
+ bad(
61
+ "install.sh",
62
+ "#!/bin/sh\n"
63
+ "curl -fsSL https://get.example.com/install.sh | sh # expect\n",
64
+ ),
65
+ bad(
66
+ "scripts/bootstrap.sh",
67
+ "#!/bin/bash\n"
68
+ 'wget -qO- "$INSTALLER_URL" | \\\n'
69
+ " sudo bash -s -- --yes\n"
70
+ "bash <(curl -s http://example.com/setup.sh)\n"
71
+ 'sh -c "$(curl -fsSL https://example.com/tool.sh)"\n',
72
+ expect=[
73
+ ("scripts/bootstrap.sh", 2, "new"),
74
+ ("scripts/bootstrap.sh", 4, "new"),
75
+ ("scripts/bootstrap.sh", 5, "new"),
76
+ ],
77
+ note="A variable URL into sudo (reported at the download, line 2), plain HTTP "
78
+ "through process substitution, and sh -c over a command substitution.",
79
+ ),
80
+ good(
81
+ "install.sh",
82
+ "#!/bin/sh\n"
83
+ "set -eu\n"
84
+ "curl -fsSLo install.sh https://get.example.com/install.sh\n"
85
+ 'echo "${INSTALL_SHA256} install.sh" | sha256sum -c -\n'
86
+ "sh install.sh\n",
87
+ note="Download, verify, then run.",
88
+ ),
89
+ good(
90
+ "scripts/keys.sh",
91
+ "#!/bin/sh\n"
92
+ "curl -fsSL https://example.com/key.gpg | sudo tee /etc/apt/keyrings/example.gpg\n"
93
+ "curl -s https://api.example.com/v1/status | jq .state\n"
94
+ "# never: curl https://x | sh\n",
95
+ note="Piping into tee or jq does not run the download.",
96
+ ),
97
+ bad(
98
+ "Dockerfile",
99
+ "FROM debian:12.5\n"
100
+ "RUN apt-get update \\\n"
101
+ " && curl -fsSL http://deb.example.com/setup.sh | bash -\n"
102
+ "RUN <<EOF\n"
103
+ "set -e\n"
104
+ "curl -fsSL https://sh.example.com/install | sh\n"
105
+ "EOF\n"
106
+ "USER nobody\n",
107
+ expect=[("Dockerfile", 3, "new"), ("Dockerfile", 6, "new")],
108
+ note="Dockerfile RUN commands (an error over http://) and RUN heredocs (a "
109
+ "warning over https://) are shell too.",
110
+ ),
111
+ good(
112
+ "Dockerfile",
113
+ "FROM debian:12.5\n"
114
+ "ARG SETUP_SHA256\n"
115
+ "RUN curl -fsSLo /tmp/setup.sh https://deb.example.com/setup.sh \\\n"
116
+ ' && echo "${SETUP_SHA256} /tmp/setup.sh" | sha256sum -c - \\\n'
117
+ " && bash /tmp/setup.sh\n"
118
+ "RUN cat <<EOF > /etc/motd\n"
119
+ "Installed with: curl https://deb.example.com/setup.sh | bash\n"
120
+ "EOF\n"
121
+ "USER nobody\n",
122
+ note="Verified before running; a heredoc written to a file is data, not shell.",
123
+ ),
124
+ ],
125
+ "shell/eval": [
126
+ bad(
127
+ "scripts/run.sh",
128
+ "#!/bin/sh\n"
129
+ 'cmd="deploy --target $1"\n'
130
+ 'eval "$cmd" # expect\n',
131
+ ),
132
+ bad(
133
+ "scripts/vars.sh",
134
+ "#!/bin/bash\n"
135
+ "for kv in \"$@\"; do\n"
136
+ " eval export \"${kv}\" # expect\n"
137
+ "done\n",
138
+ note="Arguments become code: a=1;rm x runs the rm.",
139
+ ),
140
+ good(
141
+ "scripts/env.sh",
142
+ "#!/bin/bash\n"
143
+ 'eval "$(ssh-agent -s)"\n'
144
+ 'eval "$(direnv hook bash)"\n',
145
+ note="Evaluating the fixed output of a known tool is the usual idiom.",
146
+ ),
147
+ good(
148
+ "scripts/run.sh",
149
+ "#!/bin/sh\n"
150
+ 'echo "do not eval $1"\n'
151
+ "# eval \"$cmd\" was replaced\n"
152
+ 'deploy --target "$1"\n',
153
+ ),
154
+ bad(
155
+ "Dockerfile",
156
+ "FROM python:3.13-slim\n"
157
+ "ARG EXTRA_SETUP\n"
158
+ 'RUN pip install --no-cache-dir app && eval "$EXTRA_SETUP" # expect\n'
159
+ "USER nobody\n",
160
+ note="A build argument becomes shell code in the RUN command.",
161
+ ),
162
+ good(
163
+ "Dockerfile",
164
+ "FROM python:3.13-slim\n"
165
+ 'RUN eval "$(python -m app.env --shell)" && app --check\n'
166
+ "RUN <<EOF\n"
167
+ "set -e\n"
168
+ 'eval "$(ssh-agent -s)"\n'
169
+ "EOF\n"
170
+ "USER nobody\n",
171
+ note="Fixed command substitutions in RUN and heredocs are the usual idiom.",
172
+ ),
173
+ ],
174
+ }
@@ -0,0 +1,194 @@
1
+ """Examples for the sql pack."""
2
+
3
+ from codeveto.rules.base import bad, good
4
+
5
+ EXAMPLES = {
6
+ "sql/delete-without-where": [
7
+ bad(
8
+ "db/cleanup.sql",
9
+ "-- Remove expired sessions.\nDELETE FROM sessions; -- expect\n",
10
+ note="The condition on expires_at was forgotten: every session is deleted.",
11
+ ),
12
+ bad(
13
+ "app/store.py",
14
+ 'def reset(cur):\n cur.execute("DELETE FROM carts") # expect\n',
15
+ old='def reset(cur):\n cur.execute("DELETE FROM carts WHERE abandoned")\n',
16
+ note="SQL in a string literal passed to execute() is checked too.",
17
+ ),
18
+ bad(
19
+ "migrations/0007_purge.sql",
20
+ "DELETE FROM ONLY audit_log AS a -- expect\nRETURNING a.id;\n",
21
+ note="An alias and RETURNING do not limit the rows.",
22
+ ),
23
+ good(
24
+ "db/cleanup.sql",
25
+ "DELETE FROM sessions -- expired ones only\nWHERE expires_at < now();\n",
26
+ note="The WHERE clause after a comment still belongs to the statement.",
27
+ ),
28
+ good(
29
+ "db/batch.sql",
30
+ "DELETE FROM outbox ORDER BY id LIMIT 500;\n",
31
+ note="A LIMIT bounds the delete.",
32
+ ),
33
+ good(
34
+ "app/store.py",
35
+ "def reset(cur, where):\n"
36
+ ' cur.execute("DELETE FROM carts " + where)\n'
37
+ ' log.info("Delete from cart")\n',
38
+ note="A concatenated string and prose are not judged as whole statements.",
39
+ ),
40
+ good(
41
+ "tests/conftest.py",
42
+ 'def clean(cur):\n cur.execute("DELETE FROM users")\n',
43
+ note="Tests empty their tables on purpose.",
44
+ ),
45
+ ],
46
+ "sql/update-without-where": [
47
+ bad(
48
+ "db/backfill.sql",
49
+ "UPDATE accounts -- expect\n SET plan = 'free';\n",
50
+ note="Every account is moved to the free plan.",
51
+ ),
52
+ bad(
53
+ "internal/store/users.go",
54
+ "package store\n"
55
+ "\n"
56
+ "func Deactivate(db DB) error {\n"
57
+ "\t_, err := db.Exec(`UPDATE users SET active = false`) // expect\n"
58
+ "\treturn err\n"
59
+ "}\n",
60
+ note="Go raw strings passed to Exec are SQL too.",
61
+ ),
62
+ bad(
63
+ "db/sync.sql",
64
+ "UPDATE orders AS o -- expect\n SET status = s.status\n FROM shipments AS s;\n",
65
+ note="UPDATE ... FROM without WHERE joins every order with every shipment.",
66
+ ),
67
+ good(
68
+ "db/backfill.sql",
69
+ "UPDATE accounts\n SET plan = 'free'\n WHERE plan IS NULL;\n",
70
+ ),
71
+ good(
72
+ "db/upsert.sql",
73
+ "INSERT INTO counters (name, value) VALUES ('hits', 1)\n"
74
+ "ON CONFLICT (name) DO UPDATE SET value = counters.value + 1;\n",
75
+ note="ON CONFLICT DO UPDATE only touches the conflicting row.",
76
+ ),
77
+ good(
78
+ "app/users.py",
79
+ "def deactivate(cur, ids):\n"
80
+ ' sql = "UPDATE users SET active = 0"\n'
81
+ ' sql += " WHERE id = ANY(%s)"\n'
82
+ " cur.execute(sql, (ids,))\n",
83
+ note="A string assigned and extended later is not a whole statement.",
84
+ ),
85
+ ],
86
+ "sql/drop-table": [
87
+ bad(
88
+ "migrations/0012_remove_legacy.sql",
89
+ "DROP TABLE legacy_invoices; -- expect\n",
90
+ ),
91
+ bad(
92
+ "db/migrate/20240101_cleanup.sql",
93
+ "-- +goose Up\n"
94
+ "DROP TABLE IF EXISTS user_tokens; -- expect\n"
95
+ "\n"
96
+ "-- +goose Down\n"
97
+ "CREATE TABLE user_tokens (id bigint PRIMARY KEY);\n",
98
+ note="Only the down section of a goose migration is exempt.",
99
+ ),
100
+ good(
101
+ "migrations/0012_remove_legacy.down.sql",
102
+ "DROP TABLE legacy_invoices;\n",
103
+ note="A down migration reverts what its up migration created.",
104
+ ),
105
+ good(
106
+ "db/schema.sql",
107
+ "DROP TABLE IF EXISTS settings;\n"
108
+ "CREATE TABLE settings (key text PRIMARY KEY, value text NOT NULL);\n",
109
+ note="A table dropped and created again in the same script is rebuilt.",
110
+ ),
111
+ good(
112
+ "db/report.sql",
113
+ "DROP TEMPORARY TABLE IF EXISTS tmp_totals;\n",
114
+ note="Temporary tables hold no lasting data.",
115
+ ),
116
+ ],
117
+ "sql/drop-column": [
118
+ bad(
119
+ "migrations/0013_drop_fax.sql",
120
+ "ALTER TABLE customers DROP COLUMN fax; -- expect\n",
121
+ ),
122
+ bad(
123
+ "migrations/0014_cleanup.sql",
124
+ "ALTER TABLE orders\n ADD COLUMN note text,\n DROP legacy_ref; -- expect\n",
125
+ note="MySQL allows DROP without COLUMN.",
126
+ ),
127
+ good(
128
+ "migrations/0015_constraints.sql",
129
+ "ALTER TABLE orders DROP CONSTRAINT orders_total_check;\n"
130
+ "ALTER TABLE orders ALTER COLUMN status DROP DEFAULT;\n",
131
+ note="Dropping constraints and defaults keeps the data.",
132
+ ),
133
+ good(
134
+ "migrations/0016_add_note/down.sql",
135
+ "ALTER TABLE orders DROP COLUMN note;\n",
136
+ note="Reverting an added column in a down migration.",
137
+ ),
138
+ ],
139
+ "sql/truncate": [
140
+ bad("db/reset.sql", "TRUNCATE TABLE events; -- expect\n"),
141
+ bad(
142
+ "app/jobs.py",
143
+ 'def rotate(cur):\n cur.execute("TRUNCATE audit_log RESTART IDENTITY") # expect\n',
144
+ ),
145
+ good(
146
+ "db/reset.sql",
147
+ "-- TRUNCATE TABLE events;\n"
148
+ "DELETE FROM events WHERE created_at < now() - interval '90 days';\n",
149
+ note="A commented-out statement does not run.",
150
+ ),
151
+ good(
152
+ "tests/fixtures/reset.sql",
153
+ "TRUNCATE TABLE events;\n",
154
+ note="Test fixtures reset their data.",
155
+ ),
156
+ ],
157
+ "sql/not-null-without-default": [
158
+ bad(
159
+ "migrations/0020_region.sql",
160
+ "ALTER TABLE customers ADD COLUMN region text NOT NULL; -- expect\n",
161
+ note="Fails on any table that already has rows.",
162
+ ),
163
+ bad(
164
+ "migrations/0021_flags.sql",
165
+ "ALTER TABLE accounts\n"
166
+ " ADD COLUMN created_by bigint NULL,\n"
167
+ " ADD COLUMN tier smallint NOT NULL; -- expect\n",
168
+ ),
169
+ good(
170
+ "migrations/0020_region.sql",
171
+ "ALTER TABLE customers ADD COLUMN region text NOT NULL DEFAULT 'eu';\n",
172
+ ),
173
+ good(
174
+ "migrations/0022_items.sql",
175
+ "CREATE TABLE items (id bigint PRIMARY KEY);\n"
176
+ "ALTER TABLE items ADD COLUMN sku text NOT NULL;\n",
177
+ note="A table created in the same migration is still empty.",
178
+ ),
179
+ good(
180
+ "migrations/0023_ids.sql",
181
+ "ALTER TABLE events ADD COLUMN seq bigint GENERATED ALWAYS AS IDENTITY NOT NULL;\n"
182
+ "ALTER TABLE events ADD COLUMN IF NOT EXISTS note text;\n",
183
+ ),
184
+ ],
185
+ "sql/grant-all": [
186
+ bad("db/roles.sql", "GRANT ALL PRIVILEGES ON DATABASE shop TO reporting; -- expect\n"),
187
+ bad("db/roles.sql", "GRANT ALL ON ALL TABLES IN SCHEMA public TO app; -- expect\n"),
188
+ good("db/roles.sql", "GRANT SELECT ON ALL TABLES IN SCHEMA public TO reporting;\n"),
189
+ good(
190
+ "db/roles.sql",
191
+ "GRANT SELECT, INSERT, UPDATE ON orders TO app;\nREVOKE ALL ON orders FROM PUBLIC;\n",
192
+ ),
193
+ ],
194
+ }