Skip to content

Commit fc32108

Browse files
committed
feat(core): slim MCP payloads, fix stale analysis drift, and relicense code to MPL-2.0
- slim MCP summary and finding payloads: summary inventory now returns counts, `metrics` is summary-only, `metrics_detail` exposes the full dump, list/check envelopes expose `base_uri`, and summary/normal finding views drop repeated location `uri` and `priority_factors` - fix stale analysis drift by bumping cache schema to `2.3`, invalidating stale per-file cache entries after semantic analysis changes, and documenting the new cache compatibility rule - fix AST normalization side effects that corrupted downstream cohesion metrics and remove duplicated branch logic without changing canonical report schema - refresh the repository baseline and health snapshot after the analysis fix (`81 -> 85`) and update MCP/docs/tests to lock the new behavior - relicense repository code to `MPL-2.0`, keep documentation under `MIT`, update package metadata and user-facing license notes, add Mozilla file notices to Python sources, and add directory-level MPL notices for golden fixtures without changing fixture contents
1 parent c8086c7 commit fc32108

168 files changed

Lines changed: 1940 additions & 303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/codeclone/_action_impl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# SPDX-License-Identifier: MIT
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
# SPDX-License-Identifier: MPL-2.0
5+
# Copyright (c) 2026 Den Rozhnovskiy
26

37
from __future__ import annotations
48

.github/actions/codeclone/render_pr_comment.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# SPDX-License-Identifier: MIT
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
# SPDX-License-Identifier: MPL-2.0
5+
# Copyright (c) 2026 Den Rozhnovskiy
26

37
from __future__ import annotations
48

.github/actions/codeclone/run_codeclone.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# SPDX-License-Identifier: MIT
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
# SPDX-License-Identifier: MPL-2.0
5+
# Copyright (c) 2026 Den Rozhnovskiy
26

37
from __future__ import annotations
48

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Licensing
6+
7+
- Re-license repository code to MPL-2.0 and keep documentation under MIT.
8+
9+
### Packaging
10+
11+
- Ship both `LICENSE` and `LICENSE-docs`, update package metadata, and sync file-level SPDX headers.
12+
313
## [2.0.0b3]
414

515
### MCP server
@@ -11,6 +21,18 @@
1121
- Require explicit `--allow-remote` for non-loopback `streamable-http` binds; reject `cache_policy=refresh` to preserve
1222
read-only semantics.
1323
- Defer MCP process-count policy to the core runtime when `processes` is not explicitly overridden.
24+
- Slim MCP summary payloads for agent usage: `get_run_summary`, summary resources, and `analyze_changed_paths` now
25+
replace `inventory.file_registry.items` with `{encoding, count}` while `analyze_repository` keeps the full registry.
26+
- Split `get_report_section(section="metrics")` into a summary-only projection and add `metrics_detail` for the full
27+
metrics payload, without changing canonical report schema `2.1`.
28+
- Slim `health.dimensions` in granular `check_*` responses to the single dimension relevant to each tool.
29+
- Keep hotspot `source_kind` aligned with canonical finding payloads, including fixture-scoped findings.
30+
- Add envelope-level `base_uri` to `list_findings`, `list_hotspots`, and `check_*`, while removing repeated per-location
31+
`uri` values from summary/normal finding payloads.
32+
- Slim finding list payloads further: summary responses drop `priority_factors` and keep only `file` + `line` in
33+
locations; normal responses keep `symbol` but still omit `uri` and `priority_factors`; `get_finding` remains full.
34+
- Bump cache schema to `2.3` so stale per-file analysis entries from older metric semantics are ignored and rebuilt
35+
instead of being treated as reusable cache hits.
1436

1537
### CLI
1638

CONTRIBUTING.md

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Thank you for your interest in contributing to **CodeClone**.
44

55
CodeClone provides **structural code quality analysis** for Python, including clone detection,
6-
quality metrics, and baseline-aware CI governance.
6+
quality metrics, baseline-aware CI governance, and an optional MCP agent interface.
77

88
Contributions are welcome — especially those that improve **signal quality**, **CFG semantics**,
99
and **real-world CI usability**.
@@ -31,8 +31,11 @@ We especially welcome contributions in the following areas:
3131
- Control Flow Graph (CFG) construction and semantics
3232
- AST normalization improvements
3333
- Segment-level clone detection and reporting
34+
- Quality metrics (complexity, coupling, cohesion, dead-code, dependencies)
3435
- False-positive reduction
3536
- HTML report UX improvements
37+
- MCP server tools and agent workflows
38+
- GitHub Action improvements
3639
- Performance optimizations
3740
- Documentation and real-world examples
3841

@@ -51,6 +54,8 @@ When reporting issues related to clone detection, include:
5154
- AST-related,
5255
- CFG-related,
5356
- normalization-related,
57+
- metrics-related,
58+
- MCP-related,
5459
- reporting / UI-related.
5560

5661
Screenshots alone are usually insufficient for analysis.
@@ -73,8 +78,6 @@ Well-argued false-positive reports are valuable and appreciated.
7378

7479
## CFG Semantics Discussions
7580

76-
CFG behavior in CodeClone is intentionally conservative in the 1.x series.
77-
7881
If proposing changes to CFG semantics, include:
7982

8083
- a description of the current behavior;
@@ -98,15 +101,13 @@ Such changes often require design-level discussion and may be staged across vers
98101

99102
## Baseline & CI
100103

101-
### Baseline contract (v1)
104+
### Baseline contract (v2)
102105

103-
- The baseline schema is versioned (`meta.schema_version`).
106+
- The baseline schema is versioned (`meta.schema_version`, currently `2.0`).
104107
- Compatibility/trust gates include `schema_version`, `fingerprint_version`, `python_tag`,
105108
and `meta.generator.name`.
106-
- Integrity is tamper-evident via `meta.payload_sha256` over canonical payload:
107-
`clones.functions`, `clones.blocks`, `meta.fingerprint_version`, `meta.python_tag`.
108-
`meta.schema_version`, `meta.generator.name`, `meta.generator.version`, and `created_at`
109-
are excluded from payload hashing.
109+
- Integrity is tamper-evident via `meta.payload_sha256` over canonical payload.
110+
- The baseline may embed a `metrics` section for metrics-baseline-aware CI gating.
110111

111112
### When baseline regeneration is required
112113

@@ -131,12 +132,55 @@ Such changes often require design-level discussion and may be staged across vers
131132

132133
---
133134

135+
## Versioned schemas
136+
137+
CodeClone maintains several versioned schema contracts:
138+
139+
| Schema | Current version | Owner |
140+
|------------------|-----------------|-------------------------------------|
141+
| Baseline | `2.0` | `codeclone/baseline.py` |
142+
| Report | `2.1` | `codeclone/report/json_contract.py` |
143+
| Cache | `2.2` | `codeclone/cache.py` |
144+
| Metrics baseline | `1.0` | `codeclone/metrics_baseline.py` |
145+
146+
Any change to schema shape or semantics requires version review, documentation, and tests.
147+
148+
---
149+
150+
## MCP Interface
151+
152+
CodeClone includes an optional **read-only MCP server** (`codeclone[mcp]`) for AI agents.
153+
154+
When contributing to MCP:
155+
156+
- MCP must remain **read-only** — it must never mutate baselines, source files, or repo state.
157+
- Session-local review markers are the only allowed mutable state (in-memory, ephemeral).
158+
- MCP reuses pipeline/report contracts — do not create a second analysis truth path.
159+
- Tool names, resource URIs, and response shapes are public surfaces — changes require tests and docs.
160+
161+
See `docs/mcp.md` and `docs/book/20-mcp-interface.md` for details.
162+
163+
---
164+
165+
## GitHub Action
166+
167+
CodeClone ships a composite GitHub Action (`.github/actions/codeclone/`).
168+
169+
When contributing to the Action:
170+
171+
- Never inline `${{ inputs.* }}` in shell scripts — pass through `env:` variables.
172+
- Prefer major-tag pinning for actions (e.g., `actions/setup-python@v5`).
173+
- Add timeouts to all `subprocess.run` calls.
174+
175+
---
176+
134177
## Development Setup
135178

136179
```bash
137180
git clone https://github.com/orenlab/codeclone.git
138181
cd codeclone
139182
uv sync --all-extras --dev
183+
uv run pre-commit install
140184
```
141185

142186
Run tests:
@@ -148,16 +192,26 @@ uv run pytest
148192
Static checks:
149193

150194
```bash
151-
uv run mypy .
152-
uv run ruff check .
153-
uv run ruff format .
195+
uv run pre-commit run --all-files
196+
```
197+
198+
Build documentation (if you touched `docs/` or `mkdocs.yml`):
199+
200+
```bash
201+
uv run --with mkdocs --with mkdocs-material mkdocs build --strict
202+
```
203+
204+
Run MCP tests (if you touched `mcp_service.py` or `mcp_server.py`):
205+
206+
```bash
207+
uv run pytest -q tests/test_mcp_service.py tests/test_mcp_server.py
154208
```
155209

156210
---
157211

158212
## Code Style
159213

160-
- Python **3.103.14**
214+
- Python **3.103.14**
161215
- Type annotations are required
162216
- `Any` should be minimized; prefer precise types and small typed helpers
163217
- `mypy` must pass
@@ -182,5 +236,7 @@ and may require a `fingerprint_version` bump (and thus baseline regeneration).
182236

183237
## License
184238

185-
By contributing to CodeClone, you agree that your contributions will be licensed
186-
under the **MIT License**.
239+
By contributing code to CodeClone, you agree that your contributions will be
240+
licensed under **MPL-2.0**.
241+
242+
Documentation contributions are licensed under **MIT**.

0 commit comments

Comments
 (0)