code-jig 0.12.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.
- code_jig-0.12.0.dist-info/METADATA +154 -0
- code_jig-0.12.0.dist-info/RECORD +52 -0
- code_jig-0.12.0.dist-info/WHEEL +4 -0
- code_jig-0.12.0.dist-info/entry_points.txt +2 -0
- code_jig-0.12.0.dist-info/licenses/LICENSE +202 -0
- codejig/__init__.py +1 -0
- codejig/__main__.py +106 -0
- codejig/_core/VERSION +2 -0
- codejig/_core/bench/requirements.toml +4 -0
- codejig/_core/core/AGENTS.core.md +9 -0
- codejig/_core/core/agents/explorer.toml +24 -0
- codejig/_core/core/agents/judge.toml +19 -0
- codejig/_core/core/agents/reviewer.toml +10 -0
- codejig/_core/core/tiers.toml +4 -0
- codejig/_core/skills/bug-hunt/SKILL.md +131 -0
- codejig/_core/skills/code-analysis/SKILL.md +72 -0
- codejig/_core/skills/codegen/SKILL.md +46 -0
- codejig/_core/skills/cross-review/SKILL.md +32 -0
- codejig/_core/skills/grilling/SKILL.md +60 -0
- codejig/_core/skills/hld-trace/SKILL.md +69 -0
- codejig/_core/skills/improve/SKILL.md +38 -0
- codejig/_core/skills/redacao/SKILL.md +114 -0
- codejig/_core/skills/redacao/checar.py +75 -0
- codejig/_core/skills/redacao/reference.md +118 -0
- codejig/_core/skills/regression-tests/SKILL.md +53 -0
- codejig/_core/skills/remove-ai-attribution/SKILL.md +33 -0
- codejig/_core/skills/skill-validate/SKILL.md +58 -0
- codejig/_core/skills/web-consensus/SKILL.md +55 -0
- codejig/analyze.py +499 -0
- codejig/atomicwrite.py +49 -0
- codejig/collect.py +311 -0
- codejig/doctor.py +370 -0
- codejig/evidence.py +418 -0
- codejig/feedback.py +165 -0
- codejig/gitgate.py +278 -0
- codejig/hooks.py +64 -0
- codejig/humanize.py +206 -0
- codejig/install.py +381 -0
- codejig/managed.py +64 -0
- codejig/migrate.py +515 -0
- codejig/overlay.py +43 -0
- codejig/paths.py +40 -0
- codejig/probe.py +136 -0
- codejig/review.py +73 -0
- codejig/scrub.py +255 -0
- codejig/skillcheck.py +400 -0
- codejig/skilllint.py +99 -0
- codejig/sources.py +248 -0
- codejig/tiers.py +63 -0
- codejig/tokens.py +118 -0
- codejig/trace.py +137 -0
- codejig/watermark.py +147 -0
codejig/watermark.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from codejig.atomicwrite import atomic_write, resolve_inside
|
|
5
|
+
|
|
6
|
+
_CHAR_CODES = [
|
|
7
|
+
(0x200b, "ZERO WIDTH SPACE"),
|
|
8
|
+
(0x200c, "ZERO WIDTH NON-JOINER"),
|
|
9
|
+
(0x200d, "ZERO WIDTH JOINER"),
|
|
10
|
+
(0x2060, "WORD JOINER"),
|
|
11
|
+
(0x2061, "FUNCTION APPLICATION"),
|
|
12
|
+
(0x2062, "INVISIBLE TIMES"),
|
|
13
|
+
(0x2063, "INVISIBLE SEPARATOR"),
|
|
14
|
+
(0x2064, "INVISIBLE PLUS"),
|
|
15
|
+
(0x180e, "MONGOLIAN VOWEL SEPARATOR"),
|
|
16
|
+
(0xfeff, "ZERO WIDTH NO-BREAK SPACE"),
|
|
17
|
+
(0x00ad, "SOFT HYPHEN"),
|
|
18
|
+
(0x202f, "NARROW NO-BREAK SPACE"),
|
|
19
|
+
(0x00a0, "NO-BREAK SPACE"),
|
|
20
|
+
(0x202a, "LEFT-TO-RIGHT EMBEDDING"),
|
|
21
|
+
(0x202b, "RIGHT-TO-LEFT EMBEDDING"),
|
|
22
|
+
(0x202c, "POP DIRECTIONAL FORMATTING"),
|
|
23
|
+
(0x202d, "LEFT-TO-RIGHT OVERRIDE"),
|
|
24
|
+
(0x202e, "RIGHT-TO-LEFT OVERRIDE"),
|
|
25
|
+
(0x2066, "LEFT-TO-RIGHT ISOLATE"),
|
|
26
|
+
(0x2067, "RIGHT-TO-LEFT ISOLATE"),
|
|
27
|
+
(0x2068, "FIRST STRONG ISOLATE"),
|
|
28
|
+
(0x2069, "POP DIRECTIONAL ISOLATE"),
|
|
29
|
+
]
|
|
30
|
+
INVISIBLE_CHARS = {chr(code): name for code, name in _CHAR_CODES}
|
|
31
|
+
|
|
32
|
+
_TOOLS = rb"claude|codex|chatgpt|gpt-?\d+|github[ \t]+copilot|copilot|gemini|antigravity|cursor|aider|devin|jules|openai|anthropic"
|
|
33
|
+
_PRODUCT_WORDS = rb"code|agent|ai|assistant|cli|opus|sonnet|haiku|fable|pro|flash|ultra|\d+(?:\.\d+)*"
|
|
34
|
+
_TOOL_NAME = rb"(?:claude|codex|chatgpt|gpt-?\d+|github[ \t]+copilot|copilot|gemini|antigravity|cursor[ \t]+agent|aider|devin[ \t]+ai|jules)(?:[ \t]+(?:" + _PRODUCT_WORDS + rb"))*"
|
|
35
|
+
_TOOL_DOMAINS = rb"anthropic\.com|openai\.com|cursor\.com|cognition\.ai|cognition-labs\.com|aider\.chat"
|
|
36
|
+
ATTRIBUTION_LINES = re.compile(
|
|
37
|
+
rb"(?mi)^[ \t]*("
|
|
38
|
+
rb"co-authored-by:(?:[ \t]*" + _TOOL_NAME + rb"[ \t]*(?:<[^>\n]*>)?[ \t]*\r?(?=\n|$)|"
|
|
39
|
+
rb"[^\n]*\[bot\][^\n]*|"
|
|
40
|
+
rb"[^\n]*<[^>\n]*@(?:" + _TOOL_DOMAINS + rb")>[^\n]*|"
|
|
41
|
+
rb"[^\n]*\ban ai\b[^\n]*)|"
|
|
42
|
+
rb"claude-session:[^\n]*|"
|
|
43
|
+
rb"generated (?:with|by)[ \t]+\[?(?:" + _TOOLS + rb")\b[^\n]*|"
|
|
44
|
+
rb"made with cursor[^\n]*|"
|
|
45
|
+
rb"[^\n]*\xf0\x9f\xa4\x96 generated[^\n]*|"
|
|
46
|
+
rb"(?:ai-assisted|ai-generated)[^\n]*"
|
|
47
|
+
rb")[ \t]*\n?"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
BOM = b"\xef\xbb\xbf"
|
|
51
|
+
_NO_BREAK_SPACE = chr(0x00a0)
|
|
52
|
+
_NARROW_NO_BREAK_SPACE = chr(0x202f)
|
|
53
|
+
_SOFT_HYPHEN = chr(0x00ad)
|
|
54
|
+
_BIDI = {chr(c) for c in (*range(0x202A, 0x202F), *range(0x2066, 0x206A))}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def is_binary(data: bytes) -> bool:
|
|
58
|
+
try:
|
|
59
|
+
data.decode("utf-8", errors="strict")
|
|
60
|
+
return False
|
|
61
|
+
except UnicodeDecodeError:
|
|
62
|
+
return True
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _strip_chars(text: str) -> tuple[str, dict]:
|
|
66
|
+
counts = {"zero_width": 0, "directional": 0}
|
|
67
|
+
out = []
|
|
68
|
+
for ch in text:
|
|
69
|
+
if ch in (_NO_BREAK_SPACE, _NARROW_NO_BREAK_SPACE):
|
|
70
|
+
out.append(" ")
|
|
71
|
+
counts["zero_width"] += 1
|
|
72
|
+
elif ch in INVISIBLE_CHARS:
|
|
73
|
+
counts["directional" if ch in _BIDI else "zero_width"] += 1
|
|
74
|
+
else:
|
|
75
|
+
out.append(ch)
|
|
76
|
+
return "".join(out), counts
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def strip_bytes(original: bytes, attribution: bool = True) -> tuple[bytes, dict]:
|
|
80
|
+
"""Watermark-free bytes and how many of each kind were removed."""
|
|
81
|
+
text = original.decode("utf-8")
|
|
82
|
+
had_bom = text.startswith("\ufeff")
|
|
83
|
+
if had_bom:
|
|
84
|
+
text = text[1:]
|
|
85
|
+
text, counts = _strip_chars(text)
|
|
86
|
+
data = text.encode("utf-8")
|
|
87
|
+
counts["attribution_lines"] = 0
|
|
88
|
+
if attribution:
|
|
89
|
+
counts["attribution_lines"] = len(ATTRIBUTION_LINES.findall(data))
|
|
90
|
+
data = ATTRIBUTION_LINES.sub(b"", data)
|
|
91
|
+
return (BOM + data if had_bom else data), counts
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def clean_message(msg: bytes) -> bytes:
|
|
95
|
+
try:
|
|
96
|
+
data = _strip_chars(msg.decode("utf-8"))[0].encode("utf-8")
|
|
97
|
+
except UnicodeDecodeError:
|
|
98
|
+
data = msg
|
|
99
|
+
new = ATTRIBUTION_LINES.sub(b"", data)
|
|
100
|
+
return msg if new == msg else new.rstrip(b"\n") + b"\n"
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def has_watermark(msg: bytes) -> bool:
|
|
104
|
+
return clean_message(msg) != msg
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def strip_watermark(path: str, root: str | None = None) -> dict:
|
|
108
|
+
result = {"file": path, "zero_width": 0, "directional": 0, "attribution_lines": 0}
|
|
109
|
+
target = resolve_inside(path, root)
|
|
110
|
+
if target is None:
|
|
111
|
+
return result
|
|
112
|
+
try:
|
|
113
|
+
original = target.read_bytes()
|
|
114
|
+
if is_binary(original):
|
|
115
|
+
return result
|
|
116
|
+
cleaned, counts = strip_bytes(original)
|
|
117
|
+
result.update(counts)
|
|
118
|
+
if cleaned != original:
|
|
119
|
+
atomic_write(target, cleaned)
|
|
120
|
+
result["changed"] = True
|
|
121
|
+
except Exception as e:
|
|
122
|
+
print(f"watermark: error processing {path}: {e}", file=sys.stderr)
|
|
123
|
+
return result
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def report_result(result: dict) -> str | None:
|
|
127
|
+
if not result.get("changed"):
|
|
128
|
+
return None
|
|
129
|
+
parts = [
|
|
130
|
+
f"{result[k]} {label}"
|
|
131
|
+
for k, label in (
|
|
132
|
+
("zero_width", "invisible chars"),
|
|
133
|
+
("directional", "bidi controls"),
|
|
134
|
+
("attribution_lines", "attribution lines"),
|
|
135
|
+
)
|
|
136
|
+
if result.get(k)
|
|
137
|
+
]
|
|
138
|
+
msg = f"watermark: {result['file']}: stripped {', '.join(parts)}"
|
|
139
|
+
print(msg, file=sys.stderr)
|
|
140
|
+
return msg
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def cli(args) -> int:
|
|
144
|
+
for path in (args.path or []):
|
|
145
|
+
result = strip_watermark(path)
|
|
146
|
+
report_result(result)
|
|
147
|
+
return 0
|