-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauto_copyright_header.py
More file actions
63 lines (50 loc) · 1.58 KB
/
auto_copyright_header.py
File metadata and controls
63 lines (50 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Copyright (c) 2026 Nardo (nardovibecoding). AGPL-3.0 — see LICENSE
#!/usr/bin/env python3
"""PostToolUse hook: check copyright header after writing .py/.js files."""
import json
import sys
from pathlib import Path
def main():
try:
input_data = json.load(sys.stdin)
except (json.JSONDecodeError, EOFError):
print("{}")
return
tool_name = input_data.get("tool_name", "")
tool_input = input_data.get("tool_input", {})
if tool_name not in ("Write", "Edit"):
print("{}")
return
file_path = tool_input.get("file_path", "")
if not file_path:
print("{}")
return
path = Path(file_path)
# Only check .py and .js files
if path.suffix not in (".py", ".js"):
print("{}")
return
# Skip non-repo files (hooks dir, tmp, etc.)
# Only enforce on files under repos that will be published
skip_dirs = [".claude/hooks", "/tmp/", ".claude/skills"]
if any(d in file_path for d in skip_dirs):
print("{}")
return
# Check if file has copyright header in first 300 chars
try:
head = path.read_text()[:300]
except Exception:
print("{}")
return
if "Copyright" in head or "SPDX" in head or "license" in head.lower()[:100]:
print("{}")
return
fname = path.name
print(json.dumps({
"systemMessage": (
f"⚠️ **`{fname}` missing copyright header.** Add to top:\n"
f"`# Copyright (c) 2026 Nardo (nardovibecoding). AGPL-3.0 — see LICENSE`"
)
}))
if __name__ == "__main__":
main()