From f5615aa90530e535f4ae19ca0119758e4580fc9a Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 09:41:33 +0100 Subject: [PATCH 01/11] docs: add AGENTS.md with the architecture, rules and debt cycle Describe the open-source scope of ctrace, its pipeline and invariants, the development rules the repository already applies, and a cycle to observe, qualify, record, repay and verify technical debt. --- AGENTS.md | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..a7d727f --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,193 @@ +# AGENTS.md + +Instructions for coding agents working in this repository. Humans: start with +[CONTRIBUTING.md](CONTRIBUTING.md). Update this file in the same pull request as the build, +test or architecture rule it describes. + +## Scope + +This repository is `ctrace`, the open-source CLI and HTTP server that runs analyzers on C, C++ +and Python sources, merges their findings into one report (text, JSON, SARIF) and returns an +exit code that gates a CI pipeline. It is part of CoreTrace's open core, under Apache-2.0. + +- The analyzers live in their own repositories and are fetched at pinned versions + (`cmake/*.cmake`). A wrong or missing finding is fixed there, not here; `ctrace` only runs + them, reads their reports and gates on them. +- The hosted CoreTrace platform is developed separately and is out of scope. Never move a + feature out of this repository, and never add code that only the hosted service needs. The + boundary is in [GOVERNANCE.md](GOVERNANCE.md) ("Commitments") and + [docs/open-source-scope.md](docs/open-source-scope.md). + +## Commands + +Configure once, as the [README](README.md#build) says for your platform (LLVM/Clang 20, CMake +3.28+, Ninja). Then: + +```bash +cmake --build build --parallel 4 # warnings are errors (CORETRACE_WERROR=ON) +ctest --test-dir build --output-on-failure # everything; needs cppcheck installed +ctest --test-dir build -L unit # in process, about 7 s +ctest --test-dir build -L integration # the real binary on the fixtures of tests/ +./scripts/format-check.sh # ./scripts/format.sh applies the format +./scripts/check-license-compliance.sh # SPDX header on every source file +./scripts/release/check-pinned-dependencies.sh +``` + +The first build fetches and compiles the analyzers and takes minutes on every core: ask the +maintainer before starting it, and prefer `-L unit` or one test (`ctest -R `) while +iterating. + +## Architecture + +One pipeline, from the inputs to the verdict. It is the critical path of the +[test policy](docs/quality/test-policy.md): the worst failure of `ctrace` is a wrong verdict. + +| Stage | Where | Role | +|---|---|---| +| 1. Configuration | `src/App/Config.cpp`, `ToolConfig.cpp`, `ShippedDefaults.cpp`, `include/Config/config.hpp` | Built-in defaults < `--config` file < CLI, into one `ProgramConfig` (one struct per section) | +| 2. Inputs | `src/App/Files.cpp`, `src/Process/Tools/CompileCommands.cpp`, `include/Process/Tools/InputPaths.hpp` | Resolve the files; each goes to the tools of its language | +| 3. Tool runs | `include/Process/Tools/ToolsInvoker.hpp`, `src/Process/Tools/*ToolImplementation.cpp`, `include/Process/UnixProcess.hpp` | `ToolInvoker` schedules `IAnalysisTool`s on a thread pool; each writes to a `ToolOutput` | +| 4. Findings | `include/Process/Tools/Diagnostic.hpp`, `src/Process/Tools/Sarif.cpp`, `ReportFile.hpp` | Normalize, order, count, merge | +| 5. Verdict | `include/App/ExitPolicy.hpp`, `main.cpp` | `0` clean, `1` usage, `2` findings, `3` incomplete | + +Server mode (`--ipc serve`, `src/Process/Ipc/`) wraps the same pipeline per HTTP request and +returns the same verdict in `result.gate`. `src/App/Runner.cpp` is the entry of both modes. + +Two kinds of tools: + +- **Linked in process**: the stack and concurrency analyzers (`runsInProcess` in + `include/App/SupportedTools.hpp`). +- **External processes**: cppcheck, flawfinder, tscancode, ikos, and the Python and runtime + analyzers bundled under `libexec/coretrace/`. + +### Invariants + +A change that breaks one of these is wrong, or is a significant change (see Boundaries). + +1. **Tools know only `IAnalysisTool` and `ToolOutput`.** A tool normalizes its own format to + `Diagnostic`; counting, gating and merging never see a tool-specific format. +2. **Unknown is never clean.** A tool that could not run, or whose output could not be read, + marks its `ToolOutput` failed or unread, and the run exits with 3. Zero findings is a fact + only once the output was interpreted. An incomplete run wins over findings. +3. **Only `main.cpp` decides the exit code.** No `std::exit` or `abort` elsewhere: return the + error. +4. **One configuration, one schema.** A new setting is added to its `ProgramConfig` section, + the loader, the CLI and `docs/configuration.md` together. +5. **One output channel.** Tool results go through `ToolOutput`; status and progress go through + the logger. A tool never writes to `std::cout` or `std::cerr` itself. +6. **Output is deterministic.** Diagnostics are reported in a fixed order, whatever order the + tools finished in; sequential and parallel runs give the same fingerprints (F7 harness). +7. **In-process analyzers run under `inProcessAnalysisMutex()`** + (`include/Process/Tools/InProcessAnalysis.hpp`), until they are proven thread-safe. +8. **Dependencies are pinned** to a tag or commit, never a branch. + +### Adding or changing a tool + +A new tool is a significant change: an accepted issue comes first. Then it touches +`SUPPORTED_TOOLS` (`include/App/SupportedTools.hpp`), `registerTool` and the static or dynamic +list in `ToolsInvoker.hpp`, a class in `include/Process/Tools/AnalysisTools.hpp` with its +`src/Process/Tools/ToolImplementation.cpp`, `CMakeLists.txt`, `docs/configuration.md`, +the README, and tests with a fake tool (`tests/fake-*.sh`) for its failure paths. + +## Development rules + +- **Work from an issue.** A change no issue describes gets one first, to agree on the approach. +- **A change of behavior comes with its test, in the same pull request.** A bug fix comes with + a test that fails without the fix. Write that test first. +- **Fix the cause where every caller passes**, not the symptom on the path the report names. +- **Unit tests** go in `tests/_tests.cpp` as `ctrace__tests`, follow the + `TestReport`/`expect` pattern of `tests/tool_output_tests.cpp`, and are added to + `coretrace_unit_tests` in `CMakeLists.txt`. No network, no external tool, no dependence on + timing or ordering. +- **Integration tests** are named after the behavior they check + (`ctrace_exit_3_when_a_tool_cannot_run`). +- **An intermittent test is a bug to fix**, not to retry. Retries are for network steps only. +- **Documentation follows the change** in the same pull request: README, `docs/`, help text, + and `CHANGELOG.md` when users see it. +- **Small pull requests, one subject each.** English Conventional Commit titles, such as + `fix(cli): handle missing input`. Fill the pull request template: what and why, how it was + tested. +- **Validate at the boundary**: CLI arguments, configuration files, HTTP request bodies, tool + output. See [docs/quality/input-validation.md](docs/quality/input-validation.md). +- **Do not add what the task does not need**: no speculative option, abstraction or + configuration shape. Several past debts were exactly that (#48, #63). +- Formatting is `clang-format`'s job and warnings are the compiler's: run the commands instead + of reasoning about style. Every new source file starts with the SPDX header. + +## Boundaries + +- Never commit to `main`, force-push, or merge: `main` takes pull requests whose required + checks pass. Commit, push or open an issue or a pull request only when the maintainer asks. +- Never weaken a gate to make a change pass: `-Werror`, a test, a coverage floor, the pinned + dependency check, the license check. If a gate is wrong, say so and stop. +- These are frozen interfaces. Changing one needs an issue open for 7 days + ([GOVERNANCE.md](GOVERNANCE.md)): a command-line option, a configuration key, an exit code, + the `coretrace/v1` SARIF fingerprint, the `coretrace-1.0` HTTP protocol. So do a new runtime + dependency and a change of supported platform. +- A suspected vulnerability goes through [SECURITY.md](SECURITY.md), never a public issue. +- When stuck (the build does not configure, a test fails before your change, an invariant + seems to block the task), report what you found instead of working around it. + +## Technical debt + +Debt is what makes each change slower or riskier than it should be. The issues are the source +of truth; [docs/quality/technical-debt.md](docs/quality/technical-debt.md) is the register that +summarizes them at each review. + +### The rule for every change + +Leave no new debt: a pull request must not break an invariant, lower coverage of the files it +touches, add an unpinned dependency, or leave a `TODO` without an issue number. Repay only the +debt that lies in the lines the task already changes. Debt seen elsewhere is recorded, not +fixed in passing: a drive-by fix hides in an unrelated diff and escapes review. + +### The cycle + +Run steps 1 to 3 whenever debt is noticed during a task. Run the whole cycle as a debt review +when the maintainer asks for one, and before each release. + +1. **Observe.** Collect facts, not opinions: a broken invariant above, a duplicated source of + truth, dead code or a dead option, a `TODO`, an unpinned or duplicated dependency, a file of + the critical path under its coverage floor, a static analysis finding, documentation that + contradicts the code, a test that depends on timing. +2. **Qualify against the architecture.** Name the invariant or the pipeline stage it harms, + and what it costs: a wrong verdict, every change in an area, or one leftover. That gives the + severity: `severity/critical` (blocks reliable use), `severity/major` (structural, costs + every change), `severity/minor` (bug or leftover). Add `refactor` when the fix changes the + architecture. If it harms nothing named here, it is a preference, not debt: drop it. +3. **Record.** One debt, one issue: the problem with its evidence (file, line, command and + output), the fix, and acceptance criteria that a test or a command can check. Draft the + issue and give it to the maintainer; create it only when asked. Check first that no open + issue already covers it. +4. **Repay.** One pull request per issue, separate from features. Pin the current behavior + with a test first, then change the structure, then show the test still passes. A repayment + changes no behavior; if it must, that is a separate, announced change. +5. **Verify.** The pull request closes the issue only when its acceptance criteria hold and + the gates pass: build with `-Werror`, `ctest`, format, licenses, pinned dependencies, and + the coverage of the files touched not lower than before. +6. **Update the register.** Move the item from "Open debt" to "Repaid" in + `docs/quality/technical-debt.md`, with the issue and the pull request. At a review, also + re-read every open item: still true, still the same severity, or obsolete. + +Order of repayment: critical first, then major debt in the area the next roadmap item touches, +then minor debt in batches. Debt that nothing planned will ever touch may stay open, with its +reason written in the issue. + +### Where the result shows + +```bash +gh issue list --label severity/critical --state open +gh issue list --label severity/major --state open +gh issue list --label severity/minor --state open +gh issue list --label refactor --state all --limit 100 +``` + +- The register, [docs/quality/technical-debt.md](docs/quality/technical-debt.md): repaid and + open debt, by review. +- Coverage: the `coverage-report` artifact of the "Coverage (llvm-cov)" job of each pull + request, against the floors of the [test policy](docs/quality/test-policy.md); dated copies + are kept in `docs/quality/coverage/`. +- Static analysis: `ctrace` on its own code, with the protocol of + [docs/quality/static-analysis-initial.md](docs/quality/static-analysis-initial.md), so that + two reports can be compared. +- What the gates caught: [docs/quality/regressions.md](docs/quality/regressions.md). From 00965c97e3f528a4222060790d88ca80eee4efa4 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 09:41:33 +0100 Subject: [PATCH 02/11] docs(quality): update the technical debt register to 2026-11-20 Record the reviews of 2026-10-13 and 2026-10-15 to 10-19: 51 issues, 43 closed. Move D1, D8, D12 and D13 to repaid, add D14 to D16 (#192, #203, #207), and restate D3, D5, D10 and D11 from the current pins and issues. --- docs/quality/technical-debt.md | 52 ++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/docs/quality/technical-debt.md b/docs/quality/technical-debt.md index e6fc111..c3eb73b 100644 --- a/docs/quality/technical-debt.md +++ b/docs/quality/technical-debt.md @@ -5,8 +5,8 @@ tracked, what has been repaid, and what is left. | | | |---|---| -| Date | 2026-10-13 | -| Commit | `a4aece8` | +| Date | 2026-11-20 (first version: 2026-10-13, commit `a4aece8`) | +| Commit | `7de854e` | | Sources | Issues labelled `severity/*` or `refactor`; the [initial static analysis](static-analysis-initial.md); the CI coverage report; a review of the build files, the deprecated options and the documentation | ## How debt is tracked @@ -24,13 +24,15 @@ severity: ## Repaid -Three reviews recorded 36 issues. 35 are closed. +Five reviews recorded 51 issues. 43 are closed. | Review | Issues | Critical | Major | Minor | Other | Closed | |---|---|---:|---:|---:|---:|---| | Audit, 2026-09-14 | [#41](https://github.com/CoreTrace/coretrace/issues/41)–[#65](https://github.com/CoreTrace/coretrace/issues/65) | 4 | 11 | 9 | 1 | 24, between 2026-09-19 and 2026-09-27; [#54](https://github.com/CoreTrace/coretrace/issues/54) is still open | | Review, 2026-09-21 | [#89](https://github.com/CoreTrace/coretrace/issues/89)–[#93](https://github.com/CoreTrace/coretrace/issues/93) | 2 | 2 | 1 | 0 | all 5, the next day | | Review, 2026-10-01 to 10-04 | [#133](https://github.com/CoreTrace/coretrace/issues/133), [#136](https://github.com/CoreTrace/coretrace/issues/136), [#142](https://github.com/CoreTrace/coretrace/issues/142)–[#144](https://github.com/CoreTrace/coretrace/issues/144), [#167](https://github.com/CoreTrace/coretrace/issues/167) | 0 | 1 | 3 | 2 | all 6, within 4 days | +| Register, 2026-10-13 | [#169](https://github.com/CoreTrace/coretrace/issues/169), [#172](https://github.com/CoreTrace/coretrace/issues/172)–[#178](https://github.com/CoreTrace/coretrace/issues/178) | 0 | 2 | 6 | 0 | 4, between 2026-10-14 and 2026-10-31; [#172](https://github.com/CoreTrace/coretrace/issues/172), [#173](https://github.com/CoreTrace/coretrace/issues/173), [#174](https://github.com/CoreTrace/coretrace/issues/174) and [#176](https://github.com/CoreTrace/coretrace/issues/176) are still open | +| Review, 2026-10-15 to 10-19 | [#188](https://github.com/CoreTrace/coretrace/issues/188)–[#192](https://github.com/CoreTrace/coretrace/issues/192), [#203](https://github.com/CoreTrace/coretrace/issues/203), [#207](https://github.com/CoreTrace/coretrace/issues/207) | 0 | 2 | 5 | 0 | 4, between 2026-10-16 and 2026-10-25; [#192](https://github.com/CoreTrace/coretrace/issues/192), [#203](https://github.com/CoreTrace/coretrace/issues/203) and [#207](https://github.com/CoreTrace/coretrace/issues/207) are still open | The main repayments: @@ -45,9 +47,14 @@ The main repayments: `-Werror` and runs `ctest` and coverage on every pull request. - **One output channel** instead of three ([#51](https://github.com/CoreTrace/coretrace/issues/51) → [#79](https://github.com/CoreTrace/coretrace/issues/79)). The server is hardened: bounded request bodies, CORS and the shutdown token ([#61](https://github.com/CoreTrace/coretrace/issues/61) → [#85](https://github.com/CoreTrace/coretrace/issues/85)). +- **Runs that end.** The pinned stack analyzer did not finish on CoreTrace's own code; the pin + moved to v0.23.1 ([#169](https://github.com/CoreTrace/coretrace/issues/169) → [#194](https://github.com/CoreTrace/coretrace/issues/194)). Interrupting `ctrace` now stops the running tool and removes + its run directory ([#188](https://github.com/CoreTrace/coretrace/issues/188) → [#206](https://github.com/CoreTrace/coretrace/issues/206)). +- **The gate, again.** A run with no analysis selected, or with unreadable tool output, passed + with exit code 0 ([#189](https://github.com/CoreTrace/coretrace/issues/189) → [#205](https://github.com/CoreTrace/coretrace/issues/205)).
-All 36 issues +All 51 issues | Issue | Severity | Problem | Repaid by | Closed | |---|---|---|---|---| @@ -87,6 +94,21 @@ The main repayments: | [#143](https://github.com/CoreTrace/coretrace/issues/143) | minor | `splitByComma`: undefined behaviour on a lone quote | [#149](https://github.com/CoreTrace/coretrace/issues/149) | 2026-10-01 | | [#144](https://github.com/CoreTrace/coretrace/issues/144) | minor | `mangleFunction`: parameter types inside the namespace | [#150](https://github.com/CoreTrace/coretrace/issues/150) | 2026-10-01 | | [#167](https://github.com/CoreTrace/coretrace/issues/167) | refactor | `isMangled` in the public header | [#168](https://github.com/CoreTrace/coretrace/issues/168) | 2026-10-08 | +| [#169](https://github.com/CoreTrace/coretrace/issues/169) | major | Pinned stack analyzer (v0.22.0) does not finish on CoreTrace's own code | [#194](https://github.com/CoreTrace/coretrace/issues/194) | 2026-10-16 | +| [#172](https://github.com/CoreTrace/coretrace/issues/172) | major | Linked analyzers cannot be stopped | — | open | +| [#173](https://github.com/CoreTrace/coretrace/issues/173) | minor | Deprecated spellings, and `--output-file`, which no tool uses | — | open | +| [#174](https://github.com/CoreTrace/coretrace/issues/174) | minor | Optional tools fetched from `master`; `cmake/ikos.cmake` included nowhere | — | open | +| [#175](https://github.com/CoreTrace/coretrace/issues/175) | minor | `USE_EXTERNAL_CLI11` downloads CLI11 2.3.2 while the vendored header is 2.5.0 | [#217](https://github.com/CoreTrace/coretrace/issues/217) | 2026-10-31 | +| [#176](https://github.com/CoreTrace/coretrace/issues/176) | minor | coretrace-log declared under two names and downloaded twice | — | open | +| [#177](https://github.com/CoreTrace/coretrace/issues/177) | minor | `findStackAnalyzerSection` takes its `LoadContext` by non-const reference | [#214](https://github.com/CoreTrace/coretrace/issues/214) | 2026-10-29 | +| [#178](https://github.com/CoreTrace/coretrace/issues/178) | minor | Wiki's Developer Build page still builds with `make` | wiki edit | 2026-10-14 | +| [#188](https://github.com/CoreTrace/coretrace/issues/188) | major | Interrupting `ctrace` leaves the running tool and its run directory behind | [#206](https://github.com/CoreTrace/coretrace/issues/206) | 2026-10-21 | +| [#189](https://github.com/CoreTrace/coretrace/issues/189) | major | Two runs pass the gate without checking anything | [#205](https://github.com/CoreTrace/coretrace/issues/205) | 2026-10-21 | +| [#190](https://github.com/CoreTrace/coretrace/issues/190) | minor | Inputs starting with `-` become tool options; `--static` with `--invoke` runs a tool twice; missing inputs found late | [#211](https://github.com/CoreTrace/coretrace/issues/211) | 2026-10-25 | +| [#191](https://github.com/CoreTrace/coretrace/issues/191) | minor | Server: a port in use is not detected; errors not reflected in HTTP statuses | [#200](https://github.com/CoreTrace/coretrace/issues/200) | 2026-10-16 | +| [#192](https://github.com/CoreTrace/coretrace/issues/192) | minor | Builds without a build type are unoptimized | — | open | +| [#203](https://github.com/CoreTrace/coretrace/issues/203) | minor | An input name starting with `@` may be read as a response file | — | open | +| [#207](https://github.com/CoreTrace/coretrace/issues/207) | minor | Merged SARIF log drops rule descriptions | partly, [#208](https://github.com/CoreTrace/coretrace/issues/208) | open |
@@ -94,25 +116,25 @@ The main repayments: | | Debt | Area | Severity | Effect | Action | Issue | |---|---|---|---|---|---|---| -| D1 | The pinned stack analyzer (v0.22.0) does not finish on CoreTrace's own code | dependencies | major | `--static` can run for hours on a real project | Release the analyzer from `main`, update the pin | [#169](https://github.com/CoreTrace/coretrace/issues/169) | | D2 | The linked analyzers take no timeout (`docs/configuration.md`); [#137](https://github.com/CoreTrace/coretrace/issues/137) covered external tools only | architecture | major | A stuck analyzer stalls `ctrace`, and a server request with it | Run them in a child process, or give them a cancellation point | [#172](https://github.com/CoreTrace/coretrace/issues/172) | -| D3 | The in-process Clang overflows the stack of worker threads on macOS | dependencies | major | The concurrency analyzer crashes with `SIGBUS` under the default `--jobs` | Fix in `compilerlib` | [coretrace-compiler#204](https://github.com/CoreTrace/coretrace-compiler/issues/204) | +| D3 | The in-process Clang overflows the stack of worker threads on macOS. Fixed in coretrace-compiler on 2026-10-21 ([coretrace-compiler#204](https://github.com/CoreTrace/coretrace-compiler/issues/204)), but the pinned analyzers (stack v0.23.1, concurrency v0.7.1) were released before the fix | dependencies | major | The concurrency analyzer crashes with `SIGBUS` under the default `--jobs` | Release both analyzers on a coretrace-compiler that has the fix, update the pins | — | | D4 | The Windows backend does not compile; the port was reverted | platform | major | No Windows build | Resume the port behind CI | [#54](https://github.com/CoreTrace/coretrace/issues/54) | -| D5 | The analyzers replay `-Werror` from the compilation database | dependencies | minor | An input fails on a warning that only the analyzer's libc++ emits | Drop `-Werror` in both analyzers | [coretrace-stack-analyzer#214](https://github.com/CoreTrace/coretrace-stack-analyzer/issues/214), [coretrace-concurrency-analyzer#199](https://github.com/CoreTrace/coretrace-concurrency-analyzer/issues/199) | +| D5 | The analyzers replay `-Werror` from the compilation database. Fixed in the concurrency analyzer (v0.8.0, 2026-10-15), while `ctrace` still pins v0.7.1; open in the stack analyzer | dependencies | minor | An input fails on a warning that only the analyzer's libc++ emits | Update the concurrency analyzer's pin; drop `-Werror` in the stack analyzer | [coretrace-stack-analyzer#214](https://github.com/CoreTrace/coretrace-stack-analyzer/issues/214) | | D6 | Deprecated spellings kept for compatibility: `--async` and `runtime.async`, `--ipc=socket`, legacy config keys, root-level `invoke` and `input`. `--output-file` is accepted but no tool writes to it | code | minor | Code paths to maintain and test; one option that does nothing | Announce a removal release in `CHANGELOG.md`, then remove them | [#173](https://github.com/CoreTrace/coretrace/issues/173) | | D7 | `cmake/flawfinder.cmake`, `tscancode.cmake` and `ikos.cmake` fetch `master`. `ikos.cmake` is included nowhere | build | minor | Builds with `ENABLE_FLAWFINDER` or `ENABLE_TSCANCODE` are not reproducible; one dead module | Pin a commit, or remove the options; delete `ikos.cmake` | [#174](https://github.com/CoreTrace/coretrace/issues/174) | -| D8 | Two CLI11 versions: 2.5.0 in `external/`, 2.3.2 fetched with `USE_EXTERNAL_CLI11=ON` | build | minor | The option silently downgrades the parser | Remove the option, or pin it to 2.5.0 | [#175](https://github.com/CoreTrace/coretrace/issues/175) | | D9 | coretrace-log declared under two names: `coretrace-logger` here, `coretrace_logger` in coretrace-compiler, which downloads it before checking whether the target exists | build | minor | Downloaded twice; two declarations of this dependency already broke the build once ([#37](https://github.com/CoreTrace/coretrace/issues/37), [#40](https://github.com/CoreTrace/coretrace/issues/40)) | Declare it as `coretrace_logger` | [#176](https://github.com/CoreTrace/coretrace/issues/176) | -| D10 | Unit tests cover 64.6% of the lines (89.6% with integration tests), with no threshold | tests | minor | Least covered: `ApiHandler.hpp` 64.7%, `FlawfinderToolImplementation.cpp` 72.6%, `config.hpp` 73.1%, `RunDirectory.hpp` 76.5%, `HttpServer.cpp` 79.3%, `StackAnalyzerToolImplementation.cpp` 79.4% | Tests for these files; a threshold once the test policy defines the critical path | [#164](https://github.com/CoreTrace/coretrace/issues/164) (`RunDirectory`) | -| D11 | Static analysis: `findStackAnalyzerSection` can take its `LoadContext` by `const&` (`ToolConfig.cpp:1074`); 16 raw loops flagged | code | minor | — | Fix the first; decide on the loops | [#177](https://github.com/CoreTrace/coretrace/issues/177) | -| D12 | The wiki's "Developer Build and Configuration" page still builds with `make` | docs | minor | A newcomer following the wiki gets another build than the README's | Align the page with the README | [#178](https://github.com/CoreTrace/coretrace/issues/178) | -| D13 | The `refactor` label points to a `ROADMAP.md` that does not exist | docs | minor | — | Write the roadmap (due in December), or fix the label | — | +| D10 | Unit tests cover 64.6% of the lines (89.6% with integration tests), with no threshold (measure of 2026-10-15; `RunDirectory` is covered since [#164](https://github.com/CoreTrace/coretrace/issues/164)) | tests | minor | Least covered: `ApiHandler.hpp` 64.7%, `FlawfinderToolImplementation.cpp` 72.6%, `config.hpp` 73.1%, `HttpServer.cpp` 79.3%, `StackAnalyzerToolImplementation.cpp` 79.4% | Tests for these files; a threshold once the test policy defines the critical path | — | +| D11 | Static analysis: 16 raw loops flagged by cppcheck (`useStlAlgorithm`); the `const&` of `findStackAnalyzerSection` is fixed ([#177](https://github.com/CoreTrace/coretrace/issues/177)) | code | minor | — | Decide on the loops, case by case | — | +| D14 | No default `CMAKE_BUILD_TYPE`: the README's commands and CI's main job build without optimization; the job's `--config Release` has no effect with Ninja | build | minor | The stack analyzer runs 3 to 9 times slower in such a build | Default to `Release` on single-config generators; state the build type CI tests | [#192](https://github.com/CoreTrace/coretrace/issues/192) | +| D15 | An input name starting with `@` may be read as a response file by the compiler (not reproduced yet) | code | minor | The file's contents would be expanded as compiler options | Check which tools read `@` arguments; extend `notAnOption()` | [#203](https://github.com/CoreTrace/coretrace/issues/203) | +| D16 | The merged SARIF log has no rule descriptions for the linked analyzers (stack, concurrency). [#208](https://github.com/CoreTrace/coretrace/issues/208) added them for the tools whose SARIF describes its rules | code | minor | GitHub code scanning shows no name or help text for these rules | Pin analyzer releases that expose their rule catalog (both upstream issues are closed: [coretrace-concurrency-analyzer#214](https://github.com/CoreTrace/coretrace-concurrency-analyzer/issues/214), [coretrace-stack-analyzer#242](https://github.com/CoreTrace/coretrace-stack-analyzer/issues/242)), then read it in `ctrace` | [#207](https://github.com/CoreTrace/coretrace/issues/207) | ## Debt in the analyzers -The analyzers track their own debt: coretrace-stack-analyzer has 33 open issues (27 bugs, mostly -false positives), coretrace-concurrency-analyzer 35 (32 bugs), coretrace-compiler 4. It affects -the findings `ctrace` reports, not its code. `ctrace` gets their fixes by updating its pins (D1). +The analyzers track their own debt. On 2026-11-20, coretrace-stack-analyzer has 61 open issues (44 +bugs), coretrace-concurrency-analyzer 59 (56 bugs), coretrace-compiler 10 +(7 bugs). It affects the findings `ctrace` reports, not its code. `ctrace` gets their fixes by +updating its pins (D3, D5). ## Next review From 99c84e7167f7a99c4fe6c7c811f28e0893d0fd43 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:24:06 +0100 Subject: [PATCH 03/11] docs(quality): add a debt baseline with cppcheck and clang-tidy Measure ctrace's 22 translation units on 2026-11-20: 69 findings, none at error level, by tool and by check family, the five files that concentrate them, a proposed triage, and the protocol to repeat it. --- docs/quality/debt-baseline-2026-11-20.md | 123 +++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 docs/quality/debt-baseline-2026-11-20.md diff --git a/docs/quality/debt-baseline-2026-11-20.md b/docs/quality/debt-baseline-2026-11-20.md new file mode 100644 index 0000000..986ffd5 --- /dev/null +++ b/docs/quality/debt-baseline-2026-11-20.md @@ -0,0 +1,123 @@ +# Debt baseline: cppcheck and clang-tidy + +A measure of `ctrace`'s own code with two external analyzers, to count findings by severity and +name the files that concentrate them. It is the "measure" step of the debt cycle of +[AGENTS.md](../../AGENTS.md): the same commands on a later commit give the trend. + +| | | +|---|---| +| Date | 2026-11-20 | +| Commit | `00965c9` (branch `docs/agents-md`; the code is that of `main` `7de854e`) | +| Scope | The 22 translation units of the `ctrace` target (`src/**/*.cpp`, `main.cpp`) and the project headers they include (`include/`). Tests, `external/` and fetched dependencies are excluded. | +| Machine | macOS 27.0.1, Apple M3 (8 cores) | +| Tools | cppcheck 2.17.1, clang-tidy 20.1.2 (Homebrew LLVM) | +| Not run | The stack and concurrency analyzers: they need a built `ctrace`. See [Limits](#limits). | + +## Summary + +| Tool | Files | Errors | Warnings | Style | Information | +|---|---|---:|---:|---:|---:| +| cppcheck | 22/22 | 0 | 0 | 18 | 8 | +| clang-tidy | 22/22, no compilation error | 0 | 51 | — | — | + +69 findings in 23 files, none at error level. clang-tidy reports every check as a warning: its +families, below, are the useful split. + +| clang-tidy family | Findings | Checks | +|---|---:|---| +| `concurrency` | 16 | `mt-unsafe` ×16 | +| `performance` | 14 | `enum-size` ×6, `no-automatic-move` ×3, `faster-string-find` ×2, `inefficient-string-concatenation` ×2, `avoid-endl` ×1 | +| `bugprone` | 11 | `easily-swappable-parameters` ×9, `exception-escape` ×1, `nondeterministic-pointer-iteration-order` ×1 | +| `cert` | 5 | `err33-c` ×4, `err58-cpp` ×1 | +| `readability` (complexity) | 4 | `function-cognitive-complexity` ×4 | +| `clang-analyzer` | 1 | `optin.performance.Padding` ×1 | + +cppcheck: `useStlAlgorithm` ×17 and `variableScope` ×1 (style); +`normalCheckLevelMaxBranches` ×8 (information: it limited its branch exploration). + +Against the [initial report](static-analysis-initial.md) of 2026-10-13, for cppcheck, the only +tool both runs share: 18 findings then, 18 now. The `constParameterReference` of +`ToolConfig.cpp` is fixed ([#177](https://github.com/CoreTrace/coretrace/issues/177)), and one +more raw loop is flagged in `ApiHandler.cpp` (5 instead of 4). + +## Hotspots + +Findings per file, cppcheck's information notes left out. + +| | File | Findings | clang-tidy | cppcheck | Lines | What | +|---|---|---:|---:|---:|---:|---| +| 1 | `include/Process/UnixProcess.hpp` | 9 | 9 | 0 | 343 | `strerror` ×8 and `getenv` ×1, not thread-safe | +| 2 | `src/Process/Ipc/ApiHandler.cpp` | 6 | 1 | 5 | 543 | 5 raw loops; `run_analysis` has a cognitive complexity of 35 | +| 3 | `src/Process/Tools/StackAnalyzerToolImplementation.cpp` | 6 | 4 | 2 | 627 | `buildAnalyzerArgs` has a cognitive complexity of 68; swappable parameters ×3 | +| 4 | `include/Process/Interrupt.hpp` | 5 | 5 | 0 | 97 | Return values of `std::signal` and `std::raise` ignored ×4 | +| 5 | `src/App/ShippedDefaults.cpp` | 5 | 3 | 2 | 162 | `getenv` and `setenv`; 2 raw loops | + +Then `IpcStrategy.hpp`, `Sarif.cpp` and `ToolConfig.cpp`, with 4 each. + +Functions above clang-tidy's cognitive complexity threshold (25): + +| Function | File | Complexity | +|---|---|---:| +| `applyToolsSection` | `src/App/ToolConfig.cpp:1140` | 100 | +| `buildAnalyzerArgs` | `src/Process/Tools/StackAnalyzerToolImplementation.cpp:96` | 68 | +| `run_analysis` | `src/Process/Ipc/ApiHandler.cpp:294` | 35 | +| `splitCommandLine` | `src/Process/Tools/CompileCommands.cpp:22` | 28 | + +## Proposed triage + +None of these is recorded as debt yet: each line below is a proposal for the maintainer, who +opens the issue. + +| Finding | Location | Proposal | +|---|---|---| +| `concurrency-mt-unsafe`: `strerror` ×13 | `UnixProcess.hpp`, `IpcStrategy.hpp`, `RunDirectory.hpp` | To fix: tools run on a thread pool, and two failures at the same time can mix their error text. One helper over `strerror_r` or `std::system_category().message()` removes all 13. | +| `concurrency-mt-unsafe`: `getenv` ×2, `setenv` ×1 | `UnixProcess.hpp:287`, `ShippedDefaults.cpp:146,157` | `setenv("CT_CLANG")` is accepted: `main.cpp` calls it before any thread starts. The `getenv("PATH")` of `UnixProcess.hpp` runs on pool threads: to check. | +| `bugprone-exception-escape` | `src/ctrace_tools/strings.cpp:32` | To check first: `splitByComma` is `noexcept` and fills a `std::vector`, so an allocation failure ends the process. It is on the configuration stage of the critical path. | +| `cert-err33-c` ×4 | `include/Process/Interrupt.hpp:35,36,91,92` | Probably accepted: `std::signal` and `std::raise` on the way out of the process, where nothing can handle a failure. Say so with a `NOLINT` and its reason. | +| `function-cognitive-complexity` ×4 | table above | `applyToolsSection` (100) and `buildAnalyzerArgs` (68) are the two to split; both are on the critical path. | +| `bugprone-nondeterministic-pointer-iteration-order` | `include/Process/Tools/ToolsInvoker.hpp:411` | Probably a false positive: a `std::stable_partition` on a flag of each queue, not an order on pointer values. To confirm, since a deterministic output is an invariant. | +| `bugprone-easily-swappable-parameters` ×9, `performance-*` ×14, `Padding` ×1, `err58-cpp` ×1 | several | Style and micro-optimizations: decide per check whether it joins the gate, rather than per finding. | +| cppcheck `useStlAlgorithm` ×17, `variableScope` ×1 | several | Already known: D11 of the [register](technical-debt.md), and a false positive of the initial report. | + +## Limits + +- **Two tools out of four.** The stack and concurrency analyzers were not run: this measure + does not replace the final static analysis. +- **`ctrace` only.** No analyzer repository was measured. +- **The check set is a choice.** The repository has no `.clang-tidy`; the families below were + picked for this measure. Another set gives other counts, so only runs with the same set + compare. +- **cppcheck sees no include path**, as when `ctrace` runs it: it checks each `.cpp` without + the project headers. clang-tidy compiles each unit with its real command, and a finding in a + header is counted once, whatever the number of units that include it. +- **A count is a proxy.** 69 findings say where to look, not how much the debt costs; the + triage above already sets some aside. + +## Protocol + +```bash +# Compilation database: configure only, nothing is built +L=$(brew --prefix llvm@20) +cmake -S . -B build -G Ninja -DLLVM_DIR="$L/lib/cmake/llvm" -DClang_DIR="$L/lib/cmake/clang" \ + -DCLANG_EXECUTABLE="$L/bin/clang" -DENABLE_PYTHON_ANALYZER=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + +# CoreTrace's own translation units, without -Werror, as in the initial report +mkdir -p self +jq '[.[] | select((.file|test("/(src/|main\\.cpp$)")) and ((.output // .command)|contains("CMakeFiles/ctrace.dir"))) + | .command |= gsub(" -Werror"; "")]' build/compile_commands.json > self/compile_commands.json +jq -r '.[].file' self/compile_commands.json | sed "s|^$PWD/||" | sort > self/files.txt + +# cppcheck, with the options ctrace gives it +cppcheck --template='{file}|{line}|{severity}|{id}|{message}' \ + --enable=warning,style,performance,portability --inline-suppr --quiet \ + --file-list=self/files.txt 2> cppcheck.txt + +# clang-tidy, two files at a time (about 90 s) +CHECKS='-*,bugprone-*,clang-analyzer-*,cert-*,concurrency-*,performance-*,portability-*,readability-function-cognitive-complexity,readability-function-size' +xargs -P 2 -n 1 "$L/bin/clang-tidy" -p self --checks="$CHECKS" \ + --header-filter="^$PWD/(src|include)/" --quiet < self/files.txt > clang-tidy.txt +``` + +Counting: one clang-tidy finding per (normalized file, line, column, check), kept when the file +is under `src/`, `include/` or is `main.cpp`. The raw output holds 310 lines for 51 findings, +because a header is reported once per unit that includes it. From 98e8ab40ac62444b8adcd8f841542266650763a5 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:24:06 +0100 Subject: [PATCH 04/11] docs: add the AI-assisted code policy State what every pull request must satisfy, however it was written: optional declaration with a template box and the ai-assisted label, review by a maintainer, green gates, no new debt, and one fifth of each iteration to repay debt. Define four indicators with their baseline. Point AGENTS.md to the policy and the baseline. --- .github/pull_request_template.md | 1 + AGENTS.md | 15 +++- docs/quality/ai-assisted-code-policy.md | 100 ++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 docs/quality/ai-assisted-code-policy.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 85a3489..f50fbc8 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -15,3 +15,4 @@ Closes # - [ ] `ctest --test-dir build --output-on-failure` passes. - [ ] `./scripts/format-check.sh` passes. - [ ] The README, `docs/` or the help text follow the change, if users see it. +- [ ] Optional: an AI tool helped write this change (a maintainer adds the `ai-assisted` label; see the [policy](https://github.com/CoreTrace/coretrace/blob/main/docs/quality/ai-assisted-code-policy.md)). diff --git a/AGENTS.md b/AGENTS.md index a7d727f..d2087f0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -118,6 +118,9 @@ the README, and tests with a fake tool (`tests/fake-*.sh`) for its failure paths - Never commit to `main`, force-push, or merge: `main` takes pull requests whose required checks pass. Commit, push or open an issue or a pull request only when the maintainer asks. +- Follow the [AI-assisted code policy](docs/quality/ai-assisted-code-policy.md). Commits carry + no mark of the tool: no trailer, no co-author, no tool name. Declaring assistance is the + author's choice, with the box of the pull request template. - Never weaken a gate to make a change pass: `-Werror`, a test, a coverage floor, the pinned dependency check, the license check. If a gate is wrong, say so and stop. - These are frozen interfaces. Changing one needs an issue open for 7 days @@ -169,9 +172,9 @@ when the maintainer asks for one, and before each release. `docs/quality/technical-debt.md`, with the issue and the pull request. At a review, also re-read every open item: still true, still the same severity, or obsolete. -Order of repayment: critical first, then major debt in the area the next roadmap item touches, -then minor debt in batches. Debt that nothing planned will ever touch may stay open, with its -reason written in the issue. +One fifth of each iteration is reserved for repayment. Order: critical first, then major debt +in the area the next roadmap item touches, then minor debt in batches. Debt that nothing +planned will ever touch may stay open, with its reason written in the issue. ### Where the result shows @@ -189,5 +192,9 @@ gh issue list --label refactor --state all --limit 100 are kept in `docs/quality/coverage/`. - Static analysis: `ctrace` on its own code, with the protocol of [docs/quality/static-analysis-initial.md](docs/quality/static-analysis-initial.md), so that - two reports can be compared. + two reports can be compared. cppcheck and clang-tidy alone, without building `ctrace`: + [docs/quality/debt-baseline-2026-11-20.md](docs/quality/debt-baseline-2026-11-20.md). +- The four indicators of the + [AI-assisted code policy](docs/quality/ai-assisted-code-policy.md): findings, debt added and + repaid, time to fix a vulnerability, share of assisted pull requests. - What the gates caught: [docs/quality/regressions.md](docs/quality/regressions.md). diff --git a/docs/quality/ai-assisted-code-policy.md b/docs/quality/ai-assisted-code-policy.md new file mode 100644 index 0000000..740ea88 --- /dev/null +++ b/docs/quality/ai-assisted-code-policy.md @@ -0,0 +1,100 @@ +# AI-assisted code policy + +How `ctrace` keeps its technical and security debt under control when code is written faster, +with or without an AI tool: what a pull request must satisfy, how debt is repaid, and the +indicators that show whether it works. + +| | | +|---|---| +| Date | 2026-11-20 | +| Applies to | Every pull request of this repository | +| Related | [AGENTS.md](../../AGENTS.md) (rules for coding agents), [technical debt register](technical-debt.md), [debt baseline](debt-baseline-2026-11-20.md), [test policy](test-policy.md) | + +## Principle + +An AI tool changes how fast code arrives, not what the code must satisfy. The rules below are +the same for every pull request, and the author answers for every line of it, however it was +written. Nothing here guarantees the absence of debt: the policy measures it, bounds what a +change may add, and reserves time to repay it. + +## Rules + +1. **Declaring AI assistance is optional.** An author who used an AI tool may tick the box of + the pull request template; a maintainer then adds the `ai-assisted` label. Commits carry no + mark: no trailer, no co-author, no tool name. Nobody is asked to prove how code was written. +2. **The author answers for the change.** They have read the whole diff, can explain each part + of it, and know where the code comes from: nothing copied from a source whose license is + unknown or incompatible with Apache-2.0. +3. **Review.** A pull request of the lead maintainer merges once the required checks pass. + Every other pull request, from a contributor or from another maintainer, assisted or not, + merges only after a maintainer approved it with GitHub's review tool. +4. **No merge without green gates.** The required checks of `main` pass: build with `-Werror`, + tests, format, license headers, pinned dependencies. A gate is never weakened to let a + change through; a gate that is wrong is fixed in its own pull request. +5. **A change adds no debt.** It comes with its tests, breaks no invariant of + [AGENTS.md](../../AGENTS.md), and does not lower the coverage of the files it touches. Debt + noticed elsewhere is recorded as an issue, not fixed in passing. +6. **20% of each iteration repays debt.** One fifth of the time goes to issues labelled + `severity/*` or `refactor`, critical first, then major debt in the area the next roadmap + item touches. A security fix does not count against this budget: it comes before everything + else. +7. **A coding agent follows [AGENTS.md](../../AGENTS.md).** It commits, pushes, or opens an + issue or a pull request only when a maintainer asks, and never merges. + +Rule 3 is stricter than [GOVERNANCE.md](../../GOVERNANCE.md) today, which lets any maintainer +merge their own pull request on the required checks alone. It takes effect once +`GOVERNANCE.md` and `CONTRIBUTING.md` are changed, by the process `GOVERNANCE.md` sets for its +own changes. + +## Indicators + +Measured at each debt review, with the same commands, so that two measures compare. + +| | Indicator | How it is measured | On 2026-11-20 | +|---|---|---|---| +| 1 | Static analysis findings | cppcheck and clang-tidy on the 22 translation units, with the protocol of the [debt baseline](debt-baseline-2026-11-20.md) | 69 findings, 0 at error level (cppcheck: 18 style; clang-tidy: 51 warnings) | +| 2 | Debt added and repaid | Issues labelled `severity/*` or `refactor`, opened and closed in the period | September: 30 opened, 29 closed. October: 21 opened, 14 closed. November: none. In all, 51 recorded, 43 repaid, 8 open | +| 3 | Time to fix a vulnerability | Days from a report (security advisory) or an alert (dependency scanner) to the release that fixes it; median over the period | Not measurable yet: too few events for a median. As a reference, a debt issue closes in a median of 4.7 days (critical), 4.9 (major) and 5.6 (minor) | +| 4 | Share of AI-assisted pull requests | Merged pull requests labelled `ai-assisted`, over all merged pull requests of the period | 0 of 121: the label did not exist. From now on, a lower bound, since declaring is optional | + +```bash +# 2. Debt opened and closed, by month +gh issue list --state all --limit 500 --json labels,createdAt,closedAt \ + --jq '[.[] | select([.labels[].name] | any(startswith("severity/") or . == "refactor"))] + | (map(.createdAt[0:7]) | group_by(.) | map("opened \(.[0]) \(length)")), + (map(select(.closedAt) | .closedAt[0:7]) | group_by(.) | map("closed \(.[0]) \(length)")) + | .[]' + +# 4. Share of AI-assisted pull requests +gh pr list --state merged --limit 500 --label ai-assisted --json number --jq length +gh pr list --state merged --limit 500 --json number --jq length +``` + +What the indicators are read for: + +- **1 goes down, or stays flat while the code grows.** A rise after a period of many assisted + pull requests is the signal this policy exists to catch. +- **2: repaid stays close to added.** October repaid 14 for 21 added: the 20% budget of rule 6 + answers that gap. +- **3 stays within the response targets** of [SECURITY.md](../../SECURITY.md). +- **4 is context for the three others**, not a target: it is neither good nor bad in itself. + +## Limits + +- **"Guarantee" is not absolute.** The policy bounds and reduces debt and shows its trend; it + cannot prove there is none. +- **AI-written code cannot be told apart.** Rule 1 relies on what authors declare, and + declaring is optional: indicator 4 is a minimum, never the real share. That is why no rule + depends on it. +- **The lead maintainer's pull requests have no second reader.** There, the gates of rule 4 are + the only check, as [Pull requests and reviews](pull-requests-and-reviews.md) already + explains for a team of this size. +- **Counts are proxies.** A finding count depends on the tools and the checks chosen; the + number of issues depends on how carefully debt is recorded. Only measures made the same way + compare. +- **Technical and security debt are ranked apart.** A vulnerability goes through + [SECURITY.md](../../SECURITY.md) and comes before any refactor, whatever the budget says. +- **One measure is a starting point.** The figures above are a baseline; the trend needs the + next reviews. +- **AI is also part of the answer**: it drafts tests, reviews diffs and repays recorded debt. + [AGENTS.md](../../AGENTS.md) gives an agent the same rules as a contributor. From 61e2866c20e1d422a8cb55cb7645304dc0bd965a Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:26:06 +0100 Subject: [PATCH 05/11] docs: drop the declaration of AI assistance from the policy No label, no template box and no indicator on the share of assisted pull requests: the rules apply to every pull request in the same way. Rename the policy to ai-code-policy.md and restore the pull request template. --- .github/pull_request_template.md | 1 - AGENTS.md | 11 ++++----- ...isted-code-policy.md => ai-code-policy.md} | 24 +++++++------------ 3 files changed, 14 insertions(+), 22 deletions(-) rename docs/quality/{ai-assisted-code-policy.md => ai-code-policy.md} (82%) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index f50fbc8..85a3489 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -15,4 +15,3 @@ Closes # - [ ] `ctest --test-dir build --output-on-failure` passes. - [ ] `./scripts/format-check.sh` passes. - [ ] The README, `docs/` or the help text follow the change, if users see it. -- [ ] Optional: an AI tool helped write this change (a maintainer adds the `ai-assisted` label; see the [policy](https://github.com/CoreTrace/coretrace/blob/main/docs/quality/ai-assisted-code-policy.md)). diff --git a/AGENTS.md b/AGENTS.md index d2087f0..4002bd5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -118,9 +118,8 @@ the README, and tests with a fake tool (`tests/fake-*.sh`) for its failure paths - Never commit to `main`, force-push, or merge: `main` takes pull requests whose required checks pass. Commit, push or open an issue or a pull request only when the maintainer asks. -- Follow the [AI-assisted code policy](docs/quality/ai-assisted-code-policy.md). Commits carry - no mark of the tool: no trailer, no co-author, no tool name. Declaring assistance is the - author's choice, with the box of the pull request template. +- Follow the [AI code policy](docs/quality/ai-code-policy.md). Commits carry + no mark of the tool: no trailer, no co-author, no tool name. - Never weaken a gate to make a change pass: `-Werror`, a test, a coverage floor, the pinned dependency check, the license check. If a gate is wrong, say so and stop. - These are frozen interfaces. Changing one needs an issue open for 7 days @@ -194,7 +193,7 @@ gh issue list --label refactor --state all --limit 100 [docs/quality/static-analysis-initial.md](docs/quality/static-analysis-initial.md), so that two reports can be compared. cppcheck and clang-tidy alone, without building `ctrace`: [docs/quality/debt-baseline-2026-11-20.md](docs/quality/debt-baseline-2026-11-20.md). -- The four indicators of the - [AI-assisted code policy](docs/quality/ai-assisted-code-policy.md): findings, debt added and - repaid, time to fix a vulnerability, share of assisted pull requests. +- The three indicators of the + [AI code policy](docs/quality/ai-code-policy.md): findings, debt added and + repaid, time to fix a vulnerability. - What the gates caught: [docs/quality/regressions.md](docs/quality/regressions.md). diff --git a/docs/quality/ai-assisted-code-policy.md b/docs/quality/ai-code-policy.md similarity index 82% rename from docs/quality/ai-assisted-code-policy.md rename to docs/quality/ai-code-policy.md index 740ea88..89f337e 100644 --- a/docs/quality/ai-assisted-code-policy.md +++ b/docs/quality/ai-code-policy.md @@ -1,4 +1,4 @@ -# AI-assisted code policy +# AI code policy How `ctrace` keeps its technical and security debt under control when code is written faster, with or without an AI tool: what a pull request must satisfy, how debt is repaid, and the @@ -19,9 +19,9 @@ change may add, and reserves time to repay it. ## Rules -1. **Declaring AI assistance is optional.** An author who used an AI tool may tick the box of - the pull request template; a maintainer then adds the `ai-assisted` label. Commits carry no - mark: no trailer, no co-author, no tool name. Nobody is asked to prove how code was written. +1. **Nobody declares how code was written.** There is no label, no box to tick and no mark in + commits: no trailer, no co-author, no tool name. The rules below apply to every pull + request in the same way. 2. **The author answers for the change.** They have read the whole diff, can explain each part of it, and know where the code comes from: nothing copied from a source whose license is unknown or incompatible with Apache-2.0. @@ -55,7 +55,6 @@ Measured at each debt review, with the same commands, so that two measures compa | 1 | Static analysis findings | cppcheck and clang-tidy on the 22 translation units, with the protocol of the [debt baseline](debt-baseline-2026-11-20.md) | 69 findings, 0 at error level (cppcheck: 18 style; clang-tidy: 51 warnings) | | 2 | Debt added and repaid | Issues labelled `severity/*` or `refactor`, opened and closed in the period | September: 30 opened, 29 closed. October: 21 opened, 14 closed. November: none. In all, 51 recorded, 43 repaid, 8 open | | 3 | Time to fix a vulnerability | Days from a report (security advisory) or an alert (dependency scanner) to the release that fixes it; median over the period | Not measurable yet: too few events for a median. As a reference, a debt issue closes in a median of 4.7 days (critical), 4.9 (major) and 5.6 (minor) | -| 4 | Share of AI-assisted pull requests | Merged pull requests labelled `ai-assisted`, over all merged pull requests of the period | 0 of 121: the label did not exist. From now on, a lower bound, since declaring is optional | ```bash # 2. Debt opened and closed, by month @@ -64,28 +63,23 @@ gh issue list --state all --limit 500 --json labels,createdAt,closedAt \ | (map(.createdAt[0:7]) | group_by(.) | map("opened \(.[0]) \(length)")), (map(select(.closedAt) | .closedAt[0:7]) | group_by(.) | map("closed \(.[0]) \(length)")) | .[]' - -# 4. Share of AI-assisted pull requests -gh pr list --state merged --limit 500 --label ai-assisted --json number --jq length -gh pr list --state merged --limit 500 --json number --jq length ``` What the indicators are read for: -- **1 goes down, or stays flat while the code grows.** A rise after a period of many assisted - pull requests is the signal this policy exists to catch. +- **1 goes down, or stays flat while the code grows.** A rise after a period of fast delivery is + the signal this policy exists to catch. - **2: repaid stays close to added.** October repaid 14 for 21 added: the 20% budget of rule 6 answers that gap. - **3 stays within the response targets** of [SECURITY.md](../../SECURITY.md). -- **4 is context for the three others**, not a target: it is neither good nor bad in itself. ## Limits - **"Guarantee" is not absolute.** The policy bounds and reduces debt and shows its trend; it cannot prove there is none. -- **AI-written code cannot be told apart.** Rule 1 relies on what authors declare, and - declaring is optional: indicator 4 is a minimum, never the real share. That is why no rule - depends on it. +- **AI-written code cannot be told apart**, and this policy does not try: no rule depends on + it, and the share of assisted pull requests is not measured. The indicators show the effect + on the code, whatever its cause. - **The lead maintainer's pull requests have no second reader.** There, the gates of rule 4 are the only check, as [Pull requests and reviews](pull-requests-and-reviews.md) already explains for a team of this size. From 1b57e4f369f03bfe891e67858ef2252e1a8daced Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:30:17 +0100 Subject: [PATCH 06/11] docs: do not mention the share of assisted pull requests in the policy --- docs/quality/ai-code-policy.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/quality/ai-code-policy.md b/docs/quality/ai-code-policy.md index 89f337e..ad35c87 100644 --- a/docs/quality/ai-code-policy.md +++ b/docs/quality/ai-code-policy.md @@ -78,8 +78,7 @@ What the indicators are read for: - **"Guarantee" is not absolute.** The policy bounds and reduces debt and shows its trend; it cannot prove there is none. - **AI-written code cannot be told apart**, and this policy does not try: no rule depends on - it, and the share of assisted pull requests is not measured. The indicators show the effect - on the code, whatever its cause. + it. The indicators show the effect on the code, whatever its cause. - **The lead maintainer's pull requests have no second reader.** There, the gates of rule 4 are the only check, as [Pull requests and reviews](pull-requests-and-reviews.md) already explains for a team of this size. From d56790af25ea7724ffee1f07eabcaa5642a39789 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:34:09 +0100 Subject: [PATCH 07/11] docs: keep AGENTS.md to architecture, rules and debt Remove the reference to the AI code policy. State the commit rule in neutral terms and name the three debt indicators directly. --- AGENTS.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4002bd5..505cf2c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -118,8 +118,8 @@ the README, and tests with a fake tool (`tests/fake-*.sh`) for its failure paths - Never commit to `main`, force-push, or merge: `main` takes pull requests whose required checks pass. Commit, push or open an issue or a pull request only when the maintainer asks. -- Follow the [AI code policy](docs/quality/ai-code-policy.md). Commits carry - no mark of the tool: no trailer, no co-author, no tool name. +- A commit uses the git identity already configured, and holds a subject and a body only: no + co-author and no other trailer. - Never weaken a gate to make a change pass: `-Werror`, a test, a coverage floor, the pinned dependency check, the license check. If a gate is wrong, say so and stop. - These are frozen interfaces. Changing one needs an issue open for 7 days @@ -193,7 +193,6 @@ gh issue list --label refactor --state all --limit 100 [docs/quality/static-analysis-initial.md](docs/quality/static-analysis-initial.md), so that two reports can be compared. cppcheck and clang-tidy alone, without building `ctrace`: [docs/quality/debt-baseline-2026-11-20.md](docs/quality/debt-baseline-2026-11-20.md). -- The three indicators of the - [AI code policy](docs/quality/ai-code-policy.md): findings, debt added and - repaid, time to fix a vulnerability. +- Three indicators, measured the same way at each debt review: static analysis findings, + debt added and repaid in the period, and the time to fix a vulnerability. - What the gates caught: [docs/quality/regressions.md](docs/quality/regressions.md). From bf1ec6a38fd881741414e025fbab17331779ee49 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:34:43 +0100 Subject: [PATCH 08/11] docs: remove the AI code policy from the repository AGENTS.md carries the rules and the debt cycle for every change; the policy stays out of the repository. --- docs/quality/ai-code-policy.md | 93 ---------------------------------- 1 file changed, 93 deletions(-) delete mode 100644 docs/quality/ai-code-policy.md diff --git a/docs/quality/ai-code-policy.md b/docs/quality/ai-code-policy.md deleted file mode 100644 index ad35c87..0000000 --- a/docs/quality/ai-code-policy.md +++ /dev/null @@ -1,93 +0,0 @@ -# AI code policy - -How `ctrace` keeps its technical and security debt under control when code is written faster, -with or without an AI tool: what a pull request must satisfy, how debt is repaid, and the -indicators that show whether it works. - -| | | -|---|---| -| Date | 2026-11-20 | -| Applies to | Every pull request of this repository | -| Related | [AGENTS.md](../../AGENTS.md) (rules for coding agents), [technical debt register](technical-debt.md), [debt baseline](debt-baseline-2026-11-20.md), [test policy](test-policy.md) | - -## Principle - -An AI tool changes how fast code arrives, not what the code must satisfy. The rules below are -the same for every pull request, and the author answers for every line of it, however it was -written. Nothing here guarantees the absence of debt: the policy measures it, bounds what a -change may add, and reserves time to repay it. - -## Rules - -1. **Nobody declares how code was written.** There is no label, no box to tick and no mark in - commits: no trailer, no co-author, no tool name. The rules below apply to every pull - request in the same way. -2. **The author answers for the change.** They have read the whole diff, can explain each part - of it, and know where the code comes from: nothing copied from a source whose license is - unknown or incompatible with Apache-2.0. -3. **Review.** A pull request of the lead maintainer merges once the required checks pass. - Every other pull request, from a contributor or from another maintainer, assisted or not, - merges only after a maintainer approved it with GitHub's review tool. -4. **No merge without green gates.** The required checks of `main` pass: build with `-Werror`, - tests, format, license headers, pinned dependencies. A gate is never weakened to let a - change through; a gate that is wrong is fixed in its own pull request. -5. **A change adds no debt.** It comes with its tests, breaks no invariant of - [AGENTS.md](../../AGENTS.md), and does not lower the coverage of the files it touches. Debt - noticed elsewhere is recorded as an issue, not fixed in passing. -6. **20% of each iteration repays debt.** One fifth of the time goes to issues labelled - `severity/*` or `refactor`, critical first, then major debt in the area the next roadmap - item touches. A security fix does not count against this budget: it comes before everything - else. -7. **A coding agent follows [AGENTS.md](../../AGENTS.md).** It commits, pushes, or opens an - issue or a pull request only when a maintainer asks, and never merges. - -Rule 3 is stricter than [GOVERNANCE.md](../../GOVERNANCE.md) today, which lets any maintainer -merge their own pull request on the required checks alone. It takes effect once -`GOVERNANCE.md` and `CONTRIBUTING.md` are changed, by the process `GOVERNANCE.md` sets for its -own changes. - -## Indicators - -Measured at each debt review, with the same commands, so that two measures compare. - -| | Indicator | How it is measured | On 2026-11-20 | -|---|---|---|---| -| 1 | Static analysis findings | cppcheck and clang-tidy on the 22 translation units, with the protocol of the [debt baseline](debt-baseline-2026-11-20.md) | 69 findings, 0 at error level (cppcheck: 18 style; clang-tidy: 51 warnings) | -| 2 | Debt added and repaid | Issues labelled `severity/*` or `refactor`, opened and closed in the period | September: 30 opened, 29 closed. October: 21 opened, 14 closed. November: none. In all, 51 recorded, 43 repaid, 8 open | -| 3 | Time to fix a vulnerability | Days from a report (security advisory) or an alert (dependency scanner) to the release that fixes it; median over the period | Not measurable yet: too few events for a median. As a reference, a debt issue closes in a median of 4.7 days (critical), 4.9 (major) and 5.6 (minor) | - -```bash -# 2. Debt opened and closed, by month -gh issue list --state all --limit 500 --json labels,createdAt,closedAt \ - --jq '[.[] | select([.labels[].name] | any(startswith("severity/") or . == "refactor"))] - | (map(.createdAt[0:7]) | group_by(.) | map("opened \(.[0]) \(length)")), - (map(select(.closedAt) | .closedAt[0:7]) | group_by(.) | map("closed \(.[0]) \(length)")) - | .[]' -``` - -What the indicators are read for: - -- **1 goes down, or stays flat while the code grows.** A rise after a period of fast delivery is - the signal this policy exists to catch. -- **2: repaid stays close to added.** October repaid 14 for 21 added: the 20% budget of rule 6 - answers that gap. -- **3 stays within the response targets** of [SECURITY.md](../../SECURITY.md). - -## Limits - -- **"Guarantee" is not absolute.** The policy bounds and reduces debt and shows its trend; it - cannot prove there is none. -- **AI-written code cannot be told apart**, and this policy does not try: no rule depends on - it. The indicators show the effect on the code, whatever its cause. -- **The lead maintainer's pull requests have no second reader.** There, the gates of rule 4 are - the only check, as [Pull requests and reviews](pull-requests-and-reviews.md) already - explains for a team of this size. -- **Counts are proxies.** A finding count depends on the tools and the checks chosen; the - number of issues depends on how carefully debt is recorded. Only measures made the same way - compare. -- **Technical and security debt are ranked apart.** A vulnerability goes through - [SECURITY.md](../../SECURITY.md) and comes before any refactor, whatever the budget says. -- **One measure is a starting point.** The figures above are a baseline; the trend needs the - next reviews. -- **AI is also part of the answer**: it drafts tests, reviews diffs and repays recorded debt. - [AGENTS.md](../../AGENTS.md) gives an agent the same rules as a contributor. From c94168b621c7f4244fcc9d4caf54f1c6854387b0 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:43:03 +0100 Subject: [PATCH 09/11] docs: tell agents which scripts to run and when List the format, license header, pinned dependency, coverage and retry scripts in AGENTS.md, and say that no script checks commit messages. --- AGENTS.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 505cf2c..8fd191c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -37,6 +37,22 @@ The first build fetches and compiles the analyzers and takes minutes on every co maintainer before starting it, and prefer `-L unit` or one test (`ctest -R `) while iterating. +### Use the scripts, do not redo their work by hand + +Run the script and act on what it reports, rather than checking or formatting by reading. + +| When | Script | What it does | +|---|---|---| +| After changing C++ | `./scripts/format.sh`, then `./scripts/format-check.sh` | Applies, then verifies, the `clang-format` style on the project's own sources. CI runs the check with `clang-format` 20 | +| After adding a file | `./scripts/check-license-compliance.sh` | Fails on a tracked source, CMake, shell, Python or YAML file without `SPDX-License-Identifier: Apache-2.0` in its first 12 lines, and names it. It checks; it does not add the header: write it as the first line (`//` in C++, `#` elsewhere) | +| After touching `cmake/*.cmake` | `./scripts/release/check-pinned-dependencies.sh` | Fails on a dependency fetched from a branch, or a download without its hash | +| To measure coverage | `sh scripts/ci/coverage.sh build coverage` | Needs a build configured with `-DCORETRACE_COVERAGE=ON` (Clang), so a full build: ask first | +| In a CI step that uses the network | `scripts/ci/retry.sh` | Retries a command with a growing delay. Never for a test | + +No script checks commit messages in this repository: nothing will catch a wrong one. Write the +subject as an English Conventional Commit yourself, `type(scope): summary`, as the pull request +template asks for the title. + ## Architecture One pipeline, from the inputs to the verdict. It is the critical path of the From 094161058c7f1fd6effa782ee6cd5f4e867ddd73 Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:43:15 +0100 Subject: [PATCH 10/11] docs: give the pinned dependency check its source directory argument --- AGENTS.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8fd191c..7865fcc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,7 +30,7 @@ ctest --test-dir build -L unit # in process, about 7 s ctest --test-dir build -L integration # the real binary on the fixtures of tests/ ./scripts/format-check.sh # ./scripts/format.sh applies the format ./scripts/check-license-compliance.sh # SPDX header on every source file -./scripts/release/check-pinned-dependencies.sh +sh scripts/release/check-pinned-dependencies.sh . # the argument is the source directory ``` The first build fetches and compiles the analyzers and takes minutes on every core: ask the @@ -45,7 +45,7 @@ Run the script and act on what it reports, rather than checking or formatting by |---|---|---| | After changing C++ | `./scripts/format.sh`, then `./scripts/format-check.sh` | Applies, then verifies, the `clang-format` style on the project's own sources. CI runs the check with `clang-format` 20 | | After adding a file | `./scripts/check-license-compliance.sh` | Fails on a tracked source, CMake, shell, Python or YAML file without `SPDX-License-Identifier: Apache-2.0` in its first 12 lines, and names it. It checks; it does not add the header: write it as the first line (`//` in C++, `#` elsewhere) | -| After touching `cmake/*.cmake` | `./scripts/release/check-pinned-dependencies.sh` | Fails on a dependency fetched from a branch, or a download without its hash | +| After touching `cmake/*.cmake` | `sh scripts/release/check-pinned-dependencies.sh .` | Fails on a dependency fetched from a branch, or a download without its hash | | To measure coverage | `sh scripts/ci/coverage.sh build coverage` | Needs a build configured with `-DCORETRACE_COVERAGE=ON` (Clang), so a full build: ask first | | In a CI step that uses the network | `scripts/ci/retry.sh` | Retries a command with a growing delay. Never for a test | From 4981c6087aff0cdb818b163c05eb32fc7f0a3a5f Mon Sep 17 00:00:00 2001 From: Hugo Date: Fri, 20 Nov 2026 11:50:37 +0100 Subject: [PATCH 11/11] docs: split AGENTS.md into the project and this repository Part 1 describes CoreTrace as a whole: the repositories, how they fit together, the contracts between them, where a problem is fixed, and the rules and debt cycle shared by all. Part 2 keeps what is specific to ctrace: commands, scripts, architecture, invariants, tests. --- AGENTS.md | 319 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 212 insertions(+), 107 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 7865fcc..24213be 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,22 +1,209 @@ # AGENTS.md -Instructions for coding agents working in this repository. Humans: start with -[CONTRIBUTING.md](CONTRIBUTING.md). Update this file in the same pull request as the build, -test or architecture rule it describes. +Instructions for coding agents. Humans: start with [CONTRIBUTING.md](CONTRIBUTING.md). + +This file has two parts. **Part 1** describes the CoreTrace project as a whole and the rules +shared by its repositories; it is meant to be the same in each of them. **Part 2** describes +this repository. Where they disagree, Part 2 wins for this repository. Update this file in the +same pull request as the rule, command or architecture it describes. + +# Part 1: the CoreTrace project + +## What CoreTrace is + +CoreTrace finds bugs in C, C++ and Python code by running several analyzers and merging what +they find into one report and one verdict that can gate a CI pipeline. It is split into +repositories of the [CoreTrace organization](https://github.com/CoreTrace), each versioned and +released on its own. + +The open repositories are the open core of a hosted analysis service, the CoreTrace platform, +which is developed separately and is out of scope here: never move a feature out of an open +repository, and never add code that only the hosted service needs. + +## How the repositories fit together + +``` + clients the product + ┌──────────────────────────┐ ┌──────────────────────────────────────────────┐ + │ coretrace-gui (desktop) │ │ coretrace: ctrace │ + │ coretrace-vscode (editor)├───▶│ runs the tools, merges their findings, │ + │ a CI pipeline │ │ gives the verdict │ + └──────────────────────────┘ └───────┬──────────────────────────┬───────────┘ + │ links, in process │ runs, as processes + ┌───────────┴──────────┐ ┌──────────┴──────────────┐ + │ stack analyzer │ │ runtime analyzer │ + │ concurrency analyzer │ │ python analyzer │ + └───────────┬──────────┘ │ cppcheck, flawfinder... │ + │ compile └─────────────────────────┘ + ▼ through + ┌──────────────────────┐ + │ coretrace-compiler │ + └──────────────────────┘ +``` + +| Repository | Role | How it joins the product | +|---|---|---| +| `coretrace` | `ctrace`, the CLI and HTTP server: runs the tools, normalizes and merges their findings, returns the exit code | The entry point; the release archive is built here | +| `coretrace-stack-analyzer` | Stack, buffer, pointer-escape and initialization analysis on LLVM IR | Linked into `ctrace`, at a pinned tag | +| `coretrace-concurrency-analyzer` | Data races, missing joins, lock-order deadlocks | Linked into `ctrace`, at a pinned tag | +| `coretrace-runtime-analyzer` | Instrumented runs: bounds, allocations, vtables | Shipped next to `ctrace`, run as a separate process | +| `coretrace-python-analyzer` | Analysis of Python projects | Shipped next to `ctrace` as a standalone executable, run as a separate process | +| `coretrace-compiler` | Clang integration library | The analyzers compile their inputs through it; one `ctrace` build holds one version of it | +| `coretrace-log` | C++20 logging library | Fetched by `coretrace`, the stack analyzer and `coretrace-compiler` | +| `coretrace-gui` | Desktop interface (Tauri) | A client: it runs an installed `ctrace` | +| `coretrace-vscode` | VS Code extension | A client: it runs `ctrace` and shows its findings in the editor | +| `coretrace-tool-template` | Scaffold for a new tool | Where a convention shared by the tools starts | +| `coretrace-ci-consumer-demo` | Reference CI integration | Uses a release as an outside project would | + +`ctrace` also runs third-party tools when they are installed: cppcheck, flawfinder, ikos, and +TscanCode (a fork kept in `coretrace-TscanCode`). + +### What holds them together + +These are the contracts between the repositories. Whoever changes one breaks the others, so +each change is proposed in an issue first and stays open for comments for 7 days, as +[GOVERNANCE.md](https://github.com/CoreTrace/coretrace/blob/main/GOVERNANCE.md) sets: + +- **The finding model.** Every tool's output is normalized by `ctrace` to one model, written as + text, JSON or SARIF. In SARIF, a finding is identified by its `coretrace/v1` fingerprint. +- **The verdict.** Exit code `0` clean, `1` usage error, `2` findings, `3` incomplete analysis. + A tool that could not run, or could not be read, is never counted as clean. +- **The interfaces of `ctrace`**: its command-line options, its configuration schema, and the + `coretrace-1.0` HTTP protocol of its server. +- **Pinned versions.** A repository takes another at a tag or a commit, never a branch. A fix + in an analyzer reaches users in two steps: a release of the analyzer, then an update of the + pin in `coretrace`. +- **One compiler library per build.** The analyzers linked into `ctrace` must pin the same + `coretrace-compiler` commit; moving it means releasing them together. + +### Where a problem is fixed + +| Symptom | Repository | +|---|---| +| A wrong, missing or duplicated finding | The analyzer that produced it | +| An input that does not compile for the analyzers | `coretrace-compiler` | +| A finding lost or miscounted in the merged report, a wrong exit code, a tool not run | `coretrace` | +| A report shown wrongly | The client: `coretrace-gui` or `coretrace-vscode` | + +Do not work around another repository's defect here: record it there, and take the fix by +updating the pin. + +## How the project is organized + +- **Decisions are made in the open**, in issues and pull requests, by the rules of + [GOVERNANCE.md](https://github.com/CoreTrace/coretrace/blob/main/GOVERNANCE.md). The default + branch takes pull requests whose required checks pass. +- **Not every repository is maintained the same way.** The product and its desktop interface + welcome contributors; others are maintained without contribution calls, or published as is. + The levels are in the + [open-source scope](https://github.com/CoreTrace/coretrace/blob/main/docs/open-source-scope.md). +- **Licenses differ.** Most repositories are under Apache-2.0, some under MIT or GPL-3.0. Use + the license and the file header of the repository you are in, and never copy code from one + repository into another without checking that its license allows it. +- **Each repository is versioned on its own**, with semantic versioning; components in `0.x` + may still change incompatibly between minor versions. + +## Rules for every repository + +### Development + +- **Work from an issue.** A change no issue describes gets one first, to agree on the approach. +- **A change of behavior comes with its test, in the same pull request.** A bug fix comes with + a test that fails without the fix. Write that test first. +- **Fix the cause where every caller passes**, not the symptom on the path the report names. +- **An intermittent test is a bug to fix**, not to retry. Retries are for network steps only. +- **Documentation follows the change** in the same pull request: README, `docs/`, help text, + and the changelog when users see it. +- **Small pull requests, one subject each.** English Conventional Commit titles, such as + `fix(cli): handle missing input`. Fill the pull request template where there is one: what + and why, how it was tested. +- **Validate at the boundary**: arguments, configuration files, request bodies, the output of + another tool. +- **Do not add what the task does not need**: no speculative option, abstraction or + configuration shape. +- **Use the repository's scripts and tools** for formatting, license headers and other checks: + run them and act on what they report, rather than checking by reading. + +### Boundaries + +- Never commit to the default branch, force-push, or merge. Commit, push or open an issue or + a pull request only when the maintainer asks. +- A commit uses the git identity already configured, and holds a subject and a body only: no + co-author and no other trailer. +- Never weaken a gate to make a change pass: a compiler warning, a test, a coverage floor, a + dependency or license check. If a gate is wrong, say so and stop. +- Ask before a run that keeps most cores busy for more than about a minute: a full build, the + whole test suite, a benchmark. +- A suspected vulnerability goes through the repository's `SECURITY.md`, never a public issue. +- When stuck (the build does not configure, a test fails before your change, a rule seems to + block the task), report what you found instead of working around it. + +### Technical debt + +Debt is what makes each change slower or riskier than it should be. Each debt is an issue of +the repository it lies in; the issues are the source of truth. + +**The rule for every change.** Leave no new debt: a pull request must not break an invariant +of its repository, lower the coverage of the files it touches, add an unpinned dependency, or +leave a `TODO` without an issue number. Repay only the debt that lies in the lines the task +already changes. Debt seen elsewhere is recorded, not fixed in passing: a drive-by fix hides +in an unrelated diff and escapes review. + +**The cycle.** Run steps 1 to 3 whenever debt is noticed during a task. Run the whole cycle as +a debt review when the maintainer asks for one, and before each release. + +1. **Observe.** Collect facts, not opinions: a broken invariant, a duplicated source of truth, + dead code or a dead option, a `TODO`, an unpinned or duplicated dependency, a file under its + coverage floor, a static analysis finding, documentation that contradicts the code, a test + that depends on timing. +2. **Qualify against the architecture.** Name the invariant or the contract it harms, in this + repository or between repositories, and what it costs: a wrong result for users, every + change in an area, or one leftover. That gives the severity: `severity/critical` (blocks + reliable use), `severity/major` (structural, costs every change), `severity/minor` (bug or + leftover). Add `refactor` when the fix changes the architecture. If it harms nothing named, + it is a preference, not debt: drop it. +3. **Record.** One debt, one issue, in the repository where the fix belongs: the problem with + its evidence (file, line, command and output), the fix, and acceptance criteria that a test + or a command can check. Draft the issue and give it to the maintainer; create it only when + asked. Check first that no open issue already covers it. +4. **Repay.** One pull request per issue, separate from features. Pin the current behavior + with a test first, then change the structure, then show the test still passes. A repayment + changes no behavior; if it must, that is a separate, announced change. +5. **Verify.** The pull request closes the issue only when its acceptance criteria hold, the + gates pass, and the coverage of the files touched is not lower than before. +6. **Update the register**, where the repository keeps one: move the item from open to repaid, + with the issue and the pull request. At a review, also re-read every open item: still true, + still the same severity, or obsolete. + +One fifth of each iteration is reserved for repayment. Order: critical first, then major debt +in the area the next roadmap item touches, then minor debt in batches. Debt that nothing +planned will ever touch may stay open, with its reason written in the issue. + +**Where the result shows**, in any repository: + +```bash +gh issue list --label severity/critical --state open +gh issue list --label severity/major --state open +gh issue list --label severity/minor --state open +gh issue list --label refactor --state all --limit 100 +``` + +Three indicators are measured the same way at each debt review: static analysis findings, debt +added and repaid in the period, and the time to fix a vulnerability. + +# Part 2: this repository, `coretrace` ## Scope -This repository is `ctrace`, the open-source CLI and HTTP server that runs analyzers on C, C++ -and Python sources, merges their findings into one report (text, JSON, SARIF) and returns an -exit code that gates a CI pipeline. It is part of CoreTrace's open core, under Apache-2.0. +This repository is `ctrace`, under Apache-2.0: the CLI and HTTP server that runs the analyzers +on C, C++ and Python sources, merges their findings into one report (text, JSON, SARIF) and +returns the exit code. It owns the contracts of Part 1: the finding model, the verdict and the +interfaces of `ctrace`. -- The analyzers live in their own repositories and are fetched at pinned versions - (`cmake/*.cmake`). A wrong or missing finding is fixed there, not here; `ctrace` only runs - them, reads their reports and gates on them. -- The hosted CoreTrace platform is developed separately and is out of scope. Never move a - feature out of this repository, and never add code that only the hosted service needs. The - boundary is in [GOVERNANCE.md](GOVERNANCE.md) ("Commitments") and - [docs/open-source-scope.md](docs/open-source-scope.md). +The analyzers are fetched at pinned versions (`cmake/*.cmake`). `ctrace` only runs them, reads +their reports and gates on them; the boundary with the hosted platform is in +[GOVERNANCE.md](GOVERNANCE.md) ("Commitments") and +[docs/open-source-scope.md](docs/open-source-scope.md). ## Commands @@ -37,9 +224,7 @@ The first build fetches and compiles the analyzers and takes minutes on every co maintainer before starting it, and prefer `-L unit` or one test (`ctest -R `) while iterating. -### Use the scripts, do not redo their work by hand - -Run the script and act on what it reports, rather than checking or formatting by reading. +### Scripts | When | Script | What it does | |---|---|---| @@ -78,7 +263,7 @@ Two kinds of tools: ### Invariants -A change that breaks one of these is wrong, or is a significant change (see Boundaries). +A change that breaks one of these is wrong, or changes a contract of Part 1. 1. **Tools know only `IAnalysisTool` and `ToolOutput`.** A tool normalizes its own format to `Diagnostic`; counting, gating and merging never see a tool-specific format. @@ -105,103 +290,25 @@ list in `ToolsInvoker.hpp`, a class in `include/Process/Tools/AnalysisTools.hpp` `src/Process/Tools/ToolImplementation.cpp`, `CMakeLists.txt`, `docs/configuration.md`, the README, and tests with a fake tool (`tests/fake-*.sh`) for its failure paths. -## Development rules +## Tests -- **Work from an issue.** A change no issue describes gets one first, to agree on the approach. -- **A change of behavior comes with its test, in the same pull request.** A bug fix comes with - a test that fails without the fix. Write that test first. -- **Fix the cause where every caller passes**, not the symptom on the path the report names. - **Unit tests** go in `tests/_tests.cpp` as `ctrace__tests`, follow the `TestReport`/`expect` pattern of `tests/tool_output_tests.cpp`, and are added to `coretrace_unit_tests` in `CMakeLists.txt`. No network, no external tool, no dependence on timing or ordering. - **Integration tests** are named after the behavior they check (`ctrace_exit_3_when_a_tool_cannot_run`). -- **An intermittent test is a bug to fix**, not to retry. Retries are for network steps only. -- **Documentation follows the change** in the same pull request: README, `docs/`, help text, - and `CHANGELOG.md` when users see it. -- **Small pull requests, one subject each.** English Conventional Commit titles, such as - `fix(cli): handle missing input`. Fill the pull request template: what and why, how it was - tested. -- **Validate at the boundary**: CLI arguments, configuration files, HTTP request bodies, tool - output. See [docs/quality/input-validation.md](docs/quality/input-validation.md). -- **Do not add what the task does not need**: no speculative option, abstraction or - configuration shape. Several past debts were exactly that (#48, #63). -- Formatting is `clang-format`'s job and warnings are the compiler's: run the commands instead - of reasoning about style. Every new source file starts with the SPDX header. - -## Boundaries +- What to validate at the boundary, and how: + [docs/quality/input-validation.md](docs/quality/input-validation.md). +- Past debts came from options and shapes nobody needed (#48, #63): the rule of Part 1 against + speculative additions is not theoretical here. -- Never commit to `main`, force-push, or merge: `main` takes pull requests whose required - checks pass. Commit, push or open an issue or a pull request only when the maintainer asks. -- A commit uses the git identity already configured, and holds a subject and a body only: no - co-author and no other trailer. -- Never weaken a gate to make a change pass: `-Werror`, a test, a coverage floor, the pinned - dependency check, the license check. If a gate is wrong, say so and stop. -- These are frozen interfaces. Changing one needs an issue open for 7 days - ([GOVERNANCE.md](GOVERNANCE.md)): a command-line option, a configuration key, an exit code, - the `coretrace/v1` SARIF fingerprint, the `coretrace-1.0` HTTP protocol. So do a new runtime - dependency and a change of supported platform. -- A suspected vulnerability goes through [SECURITY.md](SECURITY.md), never a public issue. -- When stuck (the build does not configure, a test fails before your change, an invariant - seems to block the task), report what you found instead of working around it. - -## Technical debt - -Debt is what makes each change slower or riskier than it should be. The issues are the source -of truth; [docs/quality/technical-debt.md](docs/quality/technical-debt.md) is the register that -summarizes them at each review. - -### The rule for every change - -Leave no new debt: a pull request must not break an invariant, lower coverage of the files it -touches, add an unpinned dependency, or leave a `TODO` without an issue number. Repay only the -debt that lies in the lines the task already changes. Debt seen elsewhere is recorded, not -fixed in passing: a drive-by fix hides in an unrelated diff and escapes review. - -### The cycle - -Run steps 1 to 3 whenever debt is noticed during a task. Run the whole cycle as a debt review -when the maintainer asks for one, and before each release. - -1. **Observe.** Collect facts, not opinions: a broken invariant above, a duplicated source of - truth, dead code or a dead option, a `TODO`, an unpinned or duplicated dependency, a file of - the critical path under its coverage floor, a static analysis finding, documentation that - contradicts the code, a test that depends on timing. -2. **Qualify against the architecture.** Name the invariant or the pipeline stage it harms, - and what it costs: a wrong verdict, every change in an area, or one leftover. That gives the - severity: `severity/critical` (blocks reliable use), `severity/major` (structural, costs - every change), `severity/minor` (bug or leftover). Add `refactor` when the fix changes the - architecture. If it harms nothing named here, it is a preference, not debt: drop it. -3. **Record.** One debt, one issue: the problem with its evidence (file, line, command and - output), the fix, and acceptance criteria that a test or a command can check. Draft the - issue and give it to the maintainer; create it only when asked. Check first that no open - issue already covers it. -4. **Repay.** One pull request per issue, separate from features. Pin the current behavior - with a test first, then change the structure, then show the test still passes. A repayment - changes no behavior; if it must, that is a separate, announced change. -5. **Verify.** The pull request closes the issue only when its acceptance criteria hold and - the gates pass: build with `-Werror`, `ctest`, format, licenses, pinned dependencies, and - the coverage of the files touched not lower than before. -6. **Update the register.** Move the item from "Open debt" to "Repaid" in - `docs/quality/technical-debt.md`, with the issue and the pull request. At a review, also - re-read every open item: still true, still the same severity, or obsolete. - -One fifth of each iteration is reserved for repayment. Order: critical first, then major debt -in the area the next roadmap item touches, then minor debt in batches. Debt that nothing -planned will ever touch may stay open, with its reason written in the issue. - -### Where the result shows - -```bash -gh issue list --label severity/critical --state open -gh issue list --label severity/major --state open -gh issue list --label severity/minor --state open -gh issue list --label refactor --state all --limit 100 -``` +## Technical debt in this repository -- The register, [docs/quality/technical-debt.md](docs/quality/technical-debt.md): repaid and - open debt, by review. +- The register is [docs/quality/technical-debt.md](docs/quality/technical-debt.md): repaid and + open debt, by review. Step 6 of the cycle updates it. +- The gates of step 5 are: build with `-Werror`, `ctest`, format, license headers, pinned + dependencies. - Coverage: the `coverage-report` artifact of the "Coverage (llvm-cov)" job of each pull request, against the floors of the [test policy](docs/quality/test-policy.md); dated copies are kept in `docs/quality/coverage/`. @@ -209,6 +316,4 @@ gh issue list --label refactor --state all --limit 100 [docs/quality/static-analysis-initial.md](docs/quality/static-analysis-initial.md), so that two reports can be compared. cppcheck and clang-tidy alone, without building `ctrace`: [docs/quality/debt-baseline-2026-11-20.md](docs/quality/debt-baseline-2026-11-20.md). -- Three indicators, measured the same way at each debt review: static analysis findings, - debt added and repaid in the period, and the time to fix a vulnerability. - What the gates caught: [docs/quality/regressions.md](docs/quality/regressions.md).