Skip to content

Commit 4067c58

Browse files
committed
chore(docs): align AGENTS and contract docs with current code
1 parent 8ddd743 commit 4067c58

7 files changed

Lines changed: 105 additions & 22 deletions

File tree

AGENTS.md

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ uv run pytest -q tests/test_codex_plugin.py
135135

136136
## 4) Baseline contract (v2, stable)
137137

138+
### Versioned constants (single source of truth)
139+
140+
All schema/version constants live in `codeclone/contracts.py`. **Always read them from code, never copy
141+
from another doc.** Current values (verified at write time):
142+
143+
| Constant | Source | Current value |
144+
|-----------------------------------|------------------------------|---------------|
145+
| `BASELINE_SCHEMA_VERSION` | `codeclone/contracts.py` | `2.1` |
146+
| `BASELINE_FINGERPRINT_VERSION` | `codeclone/contracts.py` | `1` |
147+
| `CACHE_VERSION` | `codeclone/contracts.py` | `2.4` |
148+
| `REPORT_SCHEMA_VERSION` | `codeclone/contracts.py` | `2.8` |
149+
| `METRICS_BASELINE_SCHEMA_VERSION` | `codeclone/contracts.py` | `1.2` |
150+
151+
When updating any doc that mentions a version, re-read `codeclone/contracts.py` first. Do not derive
152+
versions from another document.
153+
138154
### Baseline file structure (canonical)
139155

140156
```json
@@ -144,7 +160,7 @@ uv run pytest -q tests/test_codex_plugin.py
144160
"name": "codeclone",
145161
"version": "X.Y.Z"
146162
},
147-
"schema_version": "2.0",
163+
"schema_version": "2.1",
148164
"fingerprint_version": "1",
149165
"python_tag": "cp313",
150166
"created_at": "2026-02-08T14:20:15Z",
@@ -163,8 +179,9 @@ uv run pytest -q tests/test_codex_plugin.py
163179
### Rules
164180

165181
- `schema_version` is **baseline schema**, not package version.
166-
- Runtime writes baseline schema `2.0`.
167-
- Runtime accepts baseline schema `1.x` and `2.x` for compatibility checks.
182+
- Runtime writes baseline schema `2.1`.
183+
- Runtime accepts baseline schema `1.0` and `2.0``2.1` (governed by
184+
`_BASELINE_SCHEMA_MAX_MINOR_BY_MAJOR` in `codeclone/baseline.py`).
168185
- Compatibility is tied to:
169186
- `fingerprint_version`
170187
- `python_tag`
@@ -358,8 +375,8 @@ Architecture is layered, but grounded in current code (not aspirational diagrams
358375
`codeclone/grouping.py`, `codeclone/scanner.py`) produces normalized structural facts and clone candidates.
359376
- **Domain/contracts layer** (`codeclone/models.py`, `codeclone/contracts.py`, `codeclone/errors.py`,
360377
`codeclone/domain/*.py`) defines typed entities and stable enums/constants used across layers.
361-
- **Persistence contracts** (`codeclone/baseline.py`, `codeclone/cache.py`, `codeclone/metrics_baseline.py`) store
362-
trusted comparison state and optimization state.
378+
- **Persistence contracts** (`codeclone/baseline.py`, `codeclone/cache.py`, `codeclone/cache_io.py`,
379+
`codeclone/metrics_baseline.py`) store trusted comparison state and optimization state.
363380
- **Canonical report + projections** (`codeclone/report/json_contract.py`, `codeclone/report/*.py`) converts analysis
364381
facts to deterministic, contract-shaped outputs.
365382
- **HTML/UI rendering** (`codeclone/html_report.py`, `codeclone/_html_report/*`, `codeclone/_html_*.py`,
@@ -411,8 +428,12 @@ Use this map to route changes to the right owner module.
411428
deterministic.
412429
- `codeclone/baseline.py` — baseline schema/trust/integrity/compatibility contract; all baseline format changes go here
413430
with explicit contract process.
414-
- `codeclone/cache.py` — cache schema/integrity/profile compatibility and serialization; cache remains
431+
- `codeclone/cache.py` — cache schema/status/profile compatibility and high-level serialization policy; cache remains
415432
optimization-only.
433+
- `codeclone/cache_io.py` — IO-layer helpers for the cache: atomic JSON read/write
434+
(`read_json_document`, `write_json_document_atomically`), canonical JSON (`canonical_json`), and
435+
HMAC signing/verification (`sign_cache_payload`, `verify_cache_payload_signature`); attribute these
436+
functions to `cache_io.py`, not `cache.py`.
416437
- `codeclone/report/json_contract.py` — canonical report schema builder/integrity payload; any JSON contract shape
417438
change belongs here.
418439
- `codeclone/report/*.py` (other modules) — deterministic projections/format transforms (
@@ -529,7 +550,7 @@ Policy:
529550
### Public / contract-sensitive surfaces
530551

531552
- CLI flags, defaults, exit codes, and stable script-facing messages.
532-
- Baseline schema/trust semantics/integrity compatibility (`2.0` baseline contract family).
553+
- Baseline schema/trust semantics/integrity compatibility (`BASELINE_SCHEMA_VERSION` contract family).
533554
- Cache schema/status/profile compatibility/integrity (`CACHE_VERSION` contract family).
534555
- Canonical report JSON schema/payload semantics (`REPORT_SCHEMA_VERSION` contract family).
535556
- Documented report projections and their machine/user-facing semantics (HTML/Markdown/SARIF/Text).
@@ -621,7 +642,68 @@ Avoid deep package hierarchies unless they clearly reduce coupling.
621642

622643
---
623644

624-
## 20) Minimal checklist for PRs (agents)
645+
## 20) Agent safety rules
646+
647+
These rules exist because of real incidents in this repo. They are non-negotiable.
648+
649+
### Scope discipline
650+
651+
- Touch only files directly related to your current task.
652+
- Do not "clean up", reformat, or refactor code in files outside your task scope.
653+
- Do not delete functions, classes, blocks, or whole files written by other contributors unless
654+
deletion is the explicit goal of your task.
655+
- If you discover unrelated issues, report them in your final message — do not fix them silently.
656+
- Before starting work, run `git status` and review uncommitted/untracked changes. They may belong
657+
to a parallel agent or to the maintainer; do not delete or overwrite them without explicit approval.
658+
659+
### Documentation hygiene
660+
661+
- Every doc claim about code (schema version, module path, function name, MCP tool count, exit code,
662+
CLI flag) must be verified against the **current** code before writing or editing.
663+
- Always read version constants from `codeclone/contracts.py` (see Section 4 table), never from
664+
another doc.
665+
- When updating a file that mentions schema versions, verify **every** version reference in that
666+
file — not only the one you came to change.
667+
- Do not remove narrative content from docs you did not author. Add or correct only.
668+
- Do not replace a multi-section doc with a "pointer" stub unless the maintainer explicitly asks for it.
669+
- Do not create new `*.md` design specs ("PROPOSED", "FUTURE", "RFC") inside `docs/`. Use the
670+
maintainer's planning channel instead — orphaned specs become stale and misleading.
671+
672+
### Audit completeness
673+
674+
- When the maintainer asks to audit "all" of something, list every file you actually opened in your
675+
final report. Selective audits silently skip the most error-prone files.
676+
- Prefer parallel `Explore` agents partitioned by file group over a single sequential pass —
677+
coverage is the contract, not effort.
678+
679+
### Shared helpers
680+
681+
- HTML/UI helpers (`_html_badges.py`, `_html_css.py`, `_html_js.py`, `_html_escape.py`,
682+
`_html_report/_glossary.py`) are imported, not duplicated locally inside `_html_report/_sections/*`.
683+
If you need a helper that doesn't exist, add it to the shared module.
684+
- Glossary terms used in stat-card labels live in `codeclone/_html_report/_glossary.py`. Adding a
685+
new label without a glossary entry is a contract gap.
686+
687+
### Conflict avoidance
688+
689+
- Do not force-push, `git reset --hard`, or `git checkout --` over uncommitted work without
690+
explicit maintainer approval.
691+
- If your changes conflict with recent commits or other agents' work, rebase or merge cleanly —
692+
never silently drop the other side.
693+
- Never use `--no-verify` to bypass pre-commit hooks; fix the underlying issue.
694+
695+
### Verification before "done"
696+
697+
- A task that touches HTML rendering is not complete until
698+
`pytest tests/test_html_report.py -x -q` is green.
699+
- A task that touches MCP is not complete until
700+
`pytest tests/test_mcp_service.py tests/test_mcp_server.py -x -q` is green.
701+
- A task that touches docs schema/version claims is not complete until you have grep'd the whole
702+
file for *all* version-shaped strings and verified each against `codeclone/contracts.py`.
703+
704+
---
705+
706+
## 21) Minimal checklist for PRs (agents)
625707

626708
- [ ] Change is deterministic.
627709
- [ ] Contracts preserved or versioned.

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ CodeClone maintains several versioned schema contracts:
138138

139139
| Schema | Current version | Owner |
140140
|------------------|-----------------|-------------------------------------|
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` |
141+
| Baseline | `2.1` | `codeclone/baseline.py` |
142+
| Report | `2.8` | `codeclone/report/json_contract.py` |
143+
| Cache | `2.4` | `codeclone/cache_io.py` |
144+
| Metrics baseline | `1.2` | `codeclone/metrics_baseline.py` |
145145

146146
Any change to schema shape or semantics requires version review, documentation, and tests.
147147

docs/book/10-html-render.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ Refs:
9292
- Structural finding cards may render a compact inline suggested action when a
9393
low-signal local hint intentionally has no separate suggestion card.
9494
- IDE link `data-file` and `data-line` attributes are escaped via
95-
`_escape_attr` before insertion into HTML.
95+
`_escape_html` before insertion into HTML.
9696

9797
Refs:
9898

99-
- `codeclone/_html_escape.py:_escape_attr`
99+
- `codeclone/_html_escape.py:_escape_html`
100100
- `codeclone/_html_snippets.py:_render_code_block`
101101
- `codeclone/_html_report/_sections/_clones.py:render_clones_panel`
102102
- `codeclone/_html_report/_tables.py` (path cell IDE links)

docs/book/12-determinism.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Refs:
3232
- `codeclone/report/json_contract.py:build_report_document`
3333
- `codeclone/report/serialize.py:render_text_report_document`
3434
- `codeclone/baseline.py:_compute_payload_sha256`
35-
- `codeclone/cache.py:_sign_data`
35+
- `codeclone/cache_io.py:sign_cache_payload`
3636

3737
## Invariants (MUST)
3838

@@ -67,7 +67,7 @@ Primary canonicalization points:
6767
Refs:
6868

6969
- `codeclone/baseline.py:_compute_payload_sha256`
70-
- `codeclone/cache.py:_canonical_json`
70+
- `codeclone/cache_io.py:canonical_json`
7171
- `codeclone/report/json_contract.py:_build_integrity_payload`
7272

7373
## Locked by tests

docs/book/18-benchmarking.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ Permissions note:
8989

9090
- Workflow: `.github/workflows/benchmark.yml`
9191
- Triggers:
92-
- manual (`workflow_dispatch`)
93-
- pull requests targeting `feat/2.0.0`
92+
- `push` on all branches
93+
- `pull_request` (all targets)
94+
- manual (`workflow_dispatch`) with profile choice (`smoke` / `extended`)
9495
- Job behavior:
9596
- runs Docker benchmark with pinned runner limits
9697
- uploads `.cache/benchmarks/codeclone-benchmark.json` as artifact

docs/claude-desktop-bundle.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ The bundle prefers the current workspace launcher first:
2323

2424
```bash
2525
uv venv
26-
uv pip install --python .venv/bin/python "codeclone[mcp]>=2.0.0b4"
26+
uv pip install --python .venv/bin/python "codeclone[mcp]>=2.0.0b5"
2727
.venv/bin/codeclone-mcp --help
2828
```
2929

3030
Global fallback:
3131

3232
```bash
33-
uv tool install "codeclone[mcp]>=2.0.0b4"
33+
uv tool install "codeclone[mcp]>=2.0.0b5"
3434
codeclone-mcp --help
3535
```
3636

docs/codex-plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Repo-local discovery via `.agents/plugins/marketplace.json`.
1717

1818
```bash
1919
uv venv
20-
uv pip install --python .venv/bin/python "codeclone[mcp]>=2.0.0b4"
20+
uv pip install --python .venv/bin/python "codeclone[mcp]>=2.0.0b5"
2121
.venv/bin/codeclone-mcp --help
2222
```
2323

2424
Global fallback:
2525

2626
```bash
27-
uv tool install "codeclone[mcp]>=2.0.0b4"
27+
uv tool install "codeclone[mcp]>=2.0.0b5"
2828
codeclone-mcp --help
2929
```
3030

0 commit comments

Comments
 (0)