|
| 1 | +# License Header Management |
| 2 | + |
| 3 | +This document explains how to manage license headers in the DeerFlow project. |
| 4 | + |
| 5 | +## License Header Format |
| 6 | + |
| 7 | +All source files in this project should include license headers. |
| 8 | + |
| 9 | +### Python Files |
| 10 | + |
| 11 | +```python |
| 12 | +# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates |
| 13 | +# SPDX-License-Identifier: MIT |
| 14 | +``` |
| 15 | + |
| 16 | +For files with a shebang (`#!/usr/bin/env python3`), the header is placed after the shebang: |
| 17 | + |
| 18 | +```python |
| 19 | +#!/usr/bin/env python3 |
| 20 | +# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates |
| 21 | +# SPDX-License-Identifier: MIT |
| 22 | + |
| 23 | +import something |
| 24 | +``` |
| 25 | + |
| 26 | +### TypeScript Files |
| 27 | + |
| 28 | +```typescript |
| 29 | +// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates |
| 30 | +// SPDX-License-Identifier: MIT |
| 31 | + |
| 32 | +import { something } from "somewhere"; |
| 33 | +``` |
| 34 | + |
| 35 | +## Makefile Targets |
| 36 | + |
| 37 | +### Check License Headers |
| 38 | + |
| 39 | +Check if all Python and TypeScript files have the required license header: |
| 40 | + |
| 41 | +```bash |
| 42 | +# Check all files (Python and TypeScript) |
| 43 | +make check-license-all |
| 44 | + |
| 45 | +# Check only Python files |
| 46 | +make check-license |
| 47 | + |
| 48 | +# Check only TypeScript files |
| 49 | +make check-license-ts |
| 50 | +``` |
| 51 | + |
| 52 | +These commands: |
| 53 | +- Scan all source files in `src/`, `tests/`, `web/src/`, `web/tests/`, and root-level files |
| 54 | +- Report files missing the license header |
| 55 | +- Return exit code 1 if any files are missing headers (useful for CI/CD) |
| 56 | +- Return exit code 0 if all files have headers |
| 57 | + |
| 58 | +### Add License Headers |
| 59 | + |
| 60 | +Automatically add license headers to files that don't have them: |
| 61 | + |
| 62 | +```bash |
| 63 | +# Add to all files (Python and TypeScript) |
| 64 | +make add-license-all |
| 65 | + |
| 66 | +# Add only to Python files |
| 67 | +make add-license |
| 68 | + |
| 69 | +# Add only to TypeScript files |
| 70 | +make add-license-ts |
| 71 | +``` |
| 72 | + |
| 73 | +These commands: |
| 74 | +- Add the appropriate license header to files that don't have it |
| 75 | +- Preserve shebangs at the top of Python files |
| 76 | +- Add appropriate spacing after headers |
| 77 | +- Show vTypeScript files |
| 78 | +uv run python scripts/license_header.py web/src/components/ --check |
| 79 | + |
| 80 | +# Check a single file (works for both .py and .ts/.tsx) |
| 81 | +uv run python scripts/license_header.py src/workflow.py --check |
| 82 | +uv run python scripts/license_header.py web/src/core/api/chat.ts --check |
| 83 | +``` |
| 84 | +
|
| 85 | +### Script Options |
| 86 | +
|
| 87 | +- `--check`: Check mode - verify headers without modifying files |
| 88 | +- `--verbose` / `-v`: Show detailed output for each file processed |
| 89 | +- `paths`: One or more paths (files or directories) to process |
| 90 | +
|
| 91 | +### Supported File Types |
| 92 | +
|
| 93 | +The script automatically detects and processes: |
| 94 | +- Python files (`.py`) |
| 95 | +- TypeScript files (`.ts`) |
| 96 | +- TypeScript React files (`.tsx`) |
| 97 | +
|
| 98 | +## Pre-commit Hook |
| 99 | +
|
| 100 | +The license header check is integrated into the pre-commit hook. Before allowing a commit, it will: |
| 101 | +
|
| 102 | +1. Run linting (`make lint`) |
| 103 | +2. Run formatting (`make format`) |
| 104 | +
|
| 105 | +This ensures all merged code has proper license headers for both Python and TypeScript fileill be blocked. Run `make add-license` to fix. |
| 106 | +
|
| 107 | +## CI/CD Integration |
| 108 | +
|
| 109 | +For continuous integration, add the license check to your workflow: |
| 110 | +
|
| 111 | +```bash |
| 112 | +# In your CI script or GitHub Actions |
| 113 | +ma`.next` (Next.js build directory) |
| 114 | +- ke check-license |
| 115 | +``` |
| 116 | + |
| 117 | +This ensures all merged code has proper license headers. |
| 118 | + |
| 119 | +## Files Excluded |
| 120 | + |
| 121 | +The license header tool automatically skips: |
| 122 | +- `__pycache__` directories |
| 123 | +- `.pytest_cache`, `.ruff_cache`, `.mypy_cache` |
| 124 | +- `node_modules` |
| 125 | +- Virtual environment directories (`.venv`, `venv`, `.tox`) |
| 126 | +- Build artifacts (`build`, `dist`) |
| 127 | +- `.git` directory |
| 128 | + |
| 129 | +## Customization |
| 130 | + |
| 131 | +### Changing the License Header |
| 132 | +S` dictionary in `scripts/license_header.py`: |
| 133 | + |
| 134 | +```python |
| 135 | +LICENSE_HEADERS: Dict[str, str] = { |
| 136 | + "python": """# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates |
| 137 | +# SPDX-License-Identifier: MIT |
| 138 | +""", |
| 139 | + "typescript": """// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates |
| 140 | +// SPDX-License-Identifier: MIT |
| 141 | +""", |
| 142 | +} |
| 143 | +``` |
| 144 | + |
| 145 | +### Adding Mo-all: |
| 146 | + @uv run python scripts/license_header.py src/ tests/ scripts/ web/src/ web/test |
| 147 | +1. Add the extension to `FILE_TYPE_MAP` in `scripts/license_header.py` |
| 148 | +2. Add the corresponding header format to `LICENSE_HEADERS` |
| 149 | + |
| 150 | +```python |
| 151 | +FILE_TYPE_MAP = { |
| 152 | + ".py": "python", |
| 153 | + ".ts": "typescript", |
| 154 | + ".tsx": "typescript", |
| 155 | + ".js": "javascript", # Example: adding JavaScript support |
| 156 | +} |
| 157 | + |
| 158 | +LICENSE_HEADERS = { |
| 159 | + # ... existing headers ... |
| 160 | + "javascript": """// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates |
| 161 | +// SPDX-License-Identifier: MIT |
| 162 | +""", |
| 163 | +}PDX-License-Identifier: MIT |
| 164 | +""" |
| 165 | +``` |
| 166 | +-all |
| 167 | +Checking license headers in all source files... |
| 168 | +✅ All 289 source file(s) have license headers. |
| 169 | +``` |
| 170 | +
|
| 171 | +### Example 2: Check Only TypeScript Files |
| 172 | +```bash |
| 173 | +$ make check-license-ts |
| 174 | +Checking license headers in TypeScript files... |
| 175 | +❌ 3 file(s) missing license header: |
| 176 | + - web/src/components/new-component.tsx |
| 177 | + - web/src/core/api/new-api.ts |
| 178 | + - web/tests/new-test.test.ts |
| 179 | +
|
| 180 | +Run 'make add-license-ts' to add headers. |
| 181 | +``` |
| 182 | +
|
| 183 | +### Example 3: Add Headers to New Module |
| 184 | +```bash |
| 185 | +$ make add-license-all |
| 186 | +Adding license headers to all source files... |
| 187 | +✅ Added license header to 11 file(s). |
| 188 | +``` |
| 189 | +
|
| 190 | +### Example 4: Check Specific Directory |
| 191 | +```bash |
| 192 | +$ uv run python scripts/license_header.py web/src/components/ --check --verbose |
| 193 | +Header already present: web/src/components/deer-flow/logo.tsx |
| 194 | +Header already present: web/src/components/deer-flow/markdown.tsx |
| 195 | +Header already present: web/src/components/editor/index.tsx |
| 196 | +✅ All 24 sourceooks for exact matches (ignoring leading/trailing whitespace) |
| 197 | +
|
| 198 | +### "Pre-commit hook blocks my commit" |
| 199 | +- Run `make add-license` to add headers to all files |
| 200 | +- Or disable the check temporarily by editing the `pre-commit` file |
| 201 | +
|
| 202 | +## Examples |
| 203 | +
|
| 204 | +### Example 1: Check All Files |
| 205 | +```bash |
| 206 | +$ make check-license |
| 207 | +Checking license headers in Python files... |
| 208 | +✅ All 156 Python file(s) have license headers. |
| 209 | +``` |
| 210 | +
|
| 211 | +### Example 2: Add Headers to New Module |
| 212 | +```bash |
| 213 | +$ make add-license |
| 214 | +Adding license headers to Python files... |
| 215 | +✅ Added license header to 11 file(s). |
| 216 | +``` |
| 217 | +
|
| 218 | +### Example 3: Check Specific Directory |
| 219 | +```bash |
| 220 | +$ uv run python scripts/license_header.py src/agents/ --check --verbose |
| 221 | +Header already present: src/agents/base.py |
| 222 | +Header already present: src/agents/coordinator.py |
| 223 | +✅ All 8 Python file(s) have license headers. |
| 224 | +``` |
0 commit comments