scar-cli 0.27.2__tar.gz → 0.28.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. scar_cli-0.28.0/.github/workflows/scar-review-queue.yml +49 -0
  2. scar_cli-0.28.0/.release-please-manifest.json +3 -0
  3. scar_cli-0.27.2/.scars/candidates/slug-and-display-cleaning-are-different-jobs.md → scar_cli-0.28.0/.scars/0027-slug-and-display-cleaning-are-different-jobs.landmine.md +6 -4
  4. scar_cli-0.27.2/.scars/candidates/violation-evidence-must-not-persist-raw-edits.md → scar_cli-0.28.0/.scars/0028-violation-evidence-must-not-persist-raw-edits.fence.md +4 -2
  5. scar_cli-0.28.0/.scars/candidates/compliance-pools-by-repo-and-id.md +37 -0
  6. {scar_cli-0.27.2 → scar_cli-0.28.0}/CHANGELOG.md +14 -0
  7. {scar_cli-0.27.2 → scar_cli-0.28.0}/PKG-INFO +1 -1
  8. {scar_cli-0.27.2 → scar_cli-0.28.0}/SPEC.md +49 -1
  9. {scar_cli-0.27.2 → scar_cli-0.28.0}/plugin/plugin.json +1 -1
  10. {scar_cli-0.27.2 → scar_cli-0.28.0}/pyproject.toml +1 -1
  11. scar_cli-0.28.0/src/scar/__init__.py +0 -0
  12. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/cli.py +188 -8
  13. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/mcp.py +1 -2
  14. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/store.py +17 -2
  15. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_cli.py +22 -0
  16. scar_cli-0.28.0/tests/test_compliance_stats.py +259 -0
  17. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_docs.py +20 -0
  18. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_json_contract.py +5 -1
  19. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_mcp.py +15 -0
  20. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_store.py +19 -0
  21. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_sweep.py +2 -2
  22. {scar_cli-0.27.2 → scar_cli-0.28.0}/uv.lock +1 -1
  23. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/docs/methodology.md +14 -0
  24. scar_cli-0.27.2/.release-please-manifest.json +0 -3
  25. {scar_cli-0.27.2 → scar_cli-0.28.0}/.claude-plugin/marketplace.json +0 -0
  26. {scar_cli-0.27.2 → scar_cli-0.28.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  27. {scar_cli-0.27.2 → scar_cli-0.28.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  28. {scar_cli-0.27.2 → scar_cli-0.28.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  29. {scar_cli-0.27.2 → scar_cli-0.28.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  30. {scar_cli-0.27.2 → scar_cli-0.28.0}/.github/workflows/ci.yml +0 -0
  31. {scar_cli-0.27.2 → scar_cli-0.28.0}/.github/workflows/docs.yml +0 -0
  32. {scar_cli-0.27.2 → scar_cli-0.28.0}/.github/workflows/pr-validation.yml +0 -0
  33. {scar_cli-0.27.2 → scar_cli-0.28.0}/.github/workflows/release.yml +0 -0
  34. {scar_cli-0.27.2 → scar_cli-0.28.0}/.gitignore +0 -0
  35. {scar_cli-0.27.2 → scar_cli-0.28.0}/.pre-commit-config.yaml +0 -0
  36. {scar_cli-0.27.2 → scar_cli-0.28.0}/.pre-commit-hooks.yaml +0 -0
  37. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0001-git-grep-ere-pitfalls.landmine.md +0 -0
  38. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0002-agent-direct-hook-install.deadend.md +0 -0
  39. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0003-installer-binds-to-active-venv-scar.landmine.md +0 -0
  40. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0004-promote-roundtrip-drops-expires-evidence.landmine.md +0 -0
  41. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0005-history-rewrite-orphans-commit-evidence.landmine.md +0 -0
  42. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0006-yaml-pattern-anchor-over-escaping.landmine.md +0 -0
  43. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0007-release-please-config-change-skips-open-pr.landmine.md +0 -0
  44. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0008-rich-output-nontty-must-bypass-rich.landmine.md +0 -0
  45. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0009-anchor-survival-harness-measures-symbol-not-path-anchors.deadend.md +0 -0
  46. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0010-git-returncode-128-vs-empty-tracked-set.landmine.md +0 -0
  47. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0011-lint-compile-check-lets-redos-anchors-hang-hotpath.landmine.md +0 -0
  48. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0012-firing-log-readers-need-blanket-guards.landmine.md +0 -0
  49. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0013-docusaurus-future-v4-requires-faster-dep.landmine.md +0 -0
  50. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0014-inject-flag-dest-collides-with-subcommand-dispatch.landmine.md +0 -0
  51. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0015-zero-checkruns-means-approval-gate-not-workflow-bug.deadend.md +0 -0
  52. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0016-hook-ownership-must-be-kind-scoped.landmine.md +0 -0
  53. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0017-codex-pretool-context-can-replay-apply-patch.landmine.md +0 -0
  54. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0018-cli-subparsers-register-through-_add-wrapper.landmine.md +0 -0
  55. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0019-token-in-scar-body-cannot-prove-hook-delivery.deadend.md +0 -0
  56. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0020-one-directional-health-check-leaves-flattering-direction-unwatched.landmine.md +0 -0
  57. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0021-posttool-fix-in-hooks-does-not-reach-codex-or-cascade.landmine.md +0 -0
  58. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0022-codex-hook-delivery-needs-user-file-and-trust.landmine.md +0 -0
  59. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0023-cascade-block-exit-collides-with-argparse.fence.md +0 -0
  60. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0024-host-detection-must-not-read-the-process-home.deadend.md +0 -0
  61. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0025-one-plugin-hook-manifest-two-hosts-two-root-variables.landmine.md +0 -0
  62. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/0026-path-anchor-breadth-drives-the-review-due-threshold.landmine.md +0 -0
  63. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/README.md +0 -0
  64. /scar_cli-0.27.2/src/scar/__init__.py → /scar_cli-0.28.0/.scars/candidates/.gitkeep +0 -0
  65. {scar_cli-0.27.2 → scar_cli-0.28.0}/.scars/template.md +0 -0
  66. {scar_cli-0.27.2 → scar_cli-0.28.0}/AGENTS.md +0 -0
  67. {scar_cli-0.27.2 → scar_cli-0.28.0}/CONTRIBUTING.md +0 -0
  68. {scar_cli-0.27.2 → scar_cli-0.28.0}/IDEA.md +0 -0
  69. {scar_cli-0.27.2 → scar_cli-0.28.0}/LICENSE +0 -0
  70. {scar_cli-0.27.2 → scar_cli-0.28.0}/README.md +0 -0
  71. {scar_cli-0.27.2 → scar_cli-0.28.0}/ROADMAP.md +0 -0
  72. {scar_cli-0.27.2 → scar_cli-0.28.0}/SCAR-FORMAT.md +0 -0
  73. {scar_cli-0.27.2 → scar_cli-0.28.0}/STRESS-TEST.md +0 -0
  74. {scar_cli-0.27.2 → scar_cli-0.28.0}/action.yml +0 -0
  75. {scar_cli-0.27.2 → scar_cli-0.28.0}/codecov.yml +0 -0
  76. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/anchor-survival/PROTOCOL.md +0 -0
  77. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/anchor-survival/RESULTS.md +0 -0
  78. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/anchor-survival/long_replay.py +0 -0
  79. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/anchor-survival/replay.py +0 -0
  80. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/anchor-survival/replay_shipped.py +0 -0
  81. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/anchor-survival/test_replay_shipped.py +0 -0
  82. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/auto-authorship/FINDINGS.md +0 -0
  83. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/auto-authorship/PROTOCOL.md +0 -0
  84. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/.gitignore +0 -0
  85. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/PROTOCOL.md +0 -0
  86. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/RESULTS.md +0 -0
  87. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/fixture/.scars/0001-vendor-retry-window.fence.md +0 -0
  88. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/fixture/.scars/0002-evicting-session-store.deadend.md +0 -0
  89. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/fixture/.scars/0003-export-column-order.landmine.md +0 -0
  90. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/fixture/README.md +0 -0
  91. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/fixture/payments/retry.py +0 -0
  92. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/fixture/reports/export.py +0 -0
  93. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/fixture/services/sessions.py +0 -0
  94. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/fence-honor/grade.py +0 -0
  95. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/harvest/PROTOCOL.md +0 -0
  96. {scar_cli-0.27.2 → scar_cli-0.28.0}/experiments/harvest/harvest.py +0 -0
  97. {scar_cli-0.27.2 → scar_cli-0.28.0}/hook/scar-hooks.py +0 -0
  98. {scar_cli-0.27.2 → scar_cli-0.28.0}/plugin/hooks/run.sh +0 -0
  99. {scar_cli-0.27.2 → scar_cli-0.28.0}/plugin/skills/scar-authoring/SKILL.md +0 -0
  100. {scar_cli-0.27.2 → scar_cli-0.28.0}/plugin/skills/scar-authoring/assets/template.md +0 -0
  101. {scar_cli-0.27.2 → scar_cli-0.28.0}/release-please-config.json +0 -0
  102. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/agent.py +0 -0
  103. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/cascade.py +0 -0
  104. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/codex.py +0 -0
  105. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/draftcheck.py +0 -0
  106. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/evidence.py +0 -0
  107. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/firing_log.py +0 -0
  108. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/gc.py +0 -0
  109. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/harvest.py +0 -0
  110. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/hooks.py +0 -0
  111. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/hosts.py +0 -0
  112. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/installer.py +0 -0
  113. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/lint.py +0 -0
  114. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/match.py +0 -0
  115. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/model.py +0 -0
  116. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/orphan.py +0 -0
  117. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/output.py +0 -0
  118. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/reanchor.py +0 -0
  119. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/renames.py +0 -0
  120. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/render.py +0 -0
  121. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/review.py +0 -0
  122. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/skills/scar-authoring/SKILL.md +0 -0
  123. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/skills/scar-authoring/assets/template.md +0 -0
  124. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/symbols.py +0 -0
  125. {scar_cli-0.27.2 → scar_cli-0.28.0}/src/scar/violation_evidence.py +0 -0
  126. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/conftest.py +0 -0
  127. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_action_yml.py +0 -0
  128. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_anchor_kind.py +0 -0
  129. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_block_capability.py +0 -0
  130. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_cascade.py +0 -0
  131. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_codex.py +0 -0
  132. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_context_size.py +0 -0
  133. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_draftcheck.py +0 -0
  134. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_evidence.py +0 -0
  135. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_firing_log.py +0 -0
  136. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_gc.py +0 -0
  137. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_git_hook.py +0 -0
  138. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_harvest.py +0 -0
  139. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_hooks.py +0 -0
  140. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_hosts.py +0 -0
  141. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_installer.py +0 -0
  142. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_lifecycle.py +0 -0
  143. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_lint.py +0 -0
  144. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_match.py +0 -0
  145. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_matched_by.py +0 -0
  146. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_model.py +0 -0
  147. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_orphan.py +0 -0
  148. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_output.py +0 -0
  149. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_plugin.py +0 -0
  150. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_precommit_hooks.py +0 -0
  151. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_reanchor.py +0 -0
  152. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_renames.py +0 -0
  153. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_render.py +0 -0
  154. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_review.py +0 -0
  155. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_review_queue.py +0 -0
  156. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_skill.py +0 -0
  157. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_symbols.py +0 -0
  158. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_verdict_observability.py +0 -0
  159. {scar_cli-0.27.2 → scar_cli-0.28.0}/tests/test_violation_evidence.py +0 -0
  160. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/.gitignore +0 -0
  161. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/docs/agents.md +0 -0
  162. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/docs/concepts.md +0 -0
  163. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/docs/index.md +0 -0
  164. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/docs/quickstart.md +0 -0
  165. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/docusaurus.config.ts +0 -0
  166. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/package-lock.json +0 -0
  167. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/package.json +0 -0
  168. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/scripts/sync-changelog.mjs +0 -0
  169. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/sidebars.ts +0 -0
  170. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/src/css/custom.css +0 -0
  171. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/static/img/favicon.svg +0 -0
  172. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/static/img/social-card.png +0 -0
  173. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/static/llms.txt +0 -0
  174. {scar_cli-0.27.2 → scar_cli-0.28.0}/website/tsconfig.json +0 -0
@@ -0,0 +1,49 @@
1
+ # .github/workflows/scar-review-queue.yml
2
+ name: Scar review queue
3
+ on:
4
+ schedule:
5
+ - cron: '0 7 * * 1'
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+ issues: write
11
+
12
+ jobs:
13
+ queue:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0 # evidence-reachability checks need full history
19
+ - uses: astral-sh/setup-uv@v5
20
+ - name: Build the queue
21
+ # Keep lint's exit code, but let the next step run first: each run
22
+ # step is bash -e, so a bare failure would skip the issue sync.
23
+ run: |
24
+ set +e
25
+ uvx --from scar-cli scar lint --review-queue > queue.md
26
+ echo "status=$?" >> "$GITHUB_ENV"
27
+ exit 0
28
+ - name: Sync the rolling issue
29
+ env:
30
+ GH_TOKEN: ${{ github.token }}
31
+ run: |
32
+ label=scar-review-queue
33
+ gh label create "$label" --color BFD4F2 --description "Rolling Scar review queue" --force
34
+ issue=$(gh issue list --label "$label" --state all --limit 1 --json number,state)
35
+ number=$(jq -r '.[0].number // empty' <<<"$issue")
36
+ state=$(jq -r '.[0].state // empty' <<<"$issue")
37
+ if [ -s queue.md ]; then
38
+ if [ -z "$number" ]; then
39
+ gh issue create --title "Scar review queue" --label "$label" --body-file queue.md
40
+ else
41
+ gh issue edit "$number" --body-file queue.md
42
+ if [ "$state" = "CLOSED" ]; then gh issue reopen "$number"; fi
43
+ fi
44
+ elif [ -n "$number" ] && [ "$state" = "OPEN" ]; then
45
+ gh issue close "$number" --comment "Review queue is empty."
46
+ fi
47
+ - name: Fail the job if lint failed
48
+ if: env.status != '0'
49
+ run: exit 1
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.28.0"
3
+ }
@@ -1,15 +1,16 @@
1
1
  ---
2
- id: 0
2
+ id: 27
3
3
  type: landmine
4
4
  title: sanitize_signal_text is display cleaning, not a filename rule; slugify must not call it
5
5
  severity: medium
6
6
  confidence: 0.8
7
7
  created: 2026-11-06
8
8
  authors: ["claude-code"]
9
+ promoted_by: Kibukx
10
+ promoted_by_source: explicit
9
11
  anchors:
10
- - symbol: src/scar/store.py::slugify
11
12
  - path: src/scar/store.py
12
- violation: "(?<!def )sanitize_signal_text\("
13
+ - symbol: src/scar/store.py::slugify
13
14
  evidence:
14
15
  - issue: 365
15
16
  - issue: 159
@@ -17,7 +18,8 @@ evidence:
17
18
  expires:
18
19
  condition: "slugify and sanitize_signal_text stop sharing any code, or harvested titles stop being cleaned"
19
20
  review_after: 2027-11-06
20
- status: candidate
21
+ violation: "(?<!def )sanitize_signal_text\("
22
+ status: active
21
23
  ---
22
24
 
23
25
  `sanitize_signal_text` (#159) cleans mined git text for a human to read, so it
@@ -1,11 +1,13 @@
1
1
  ---
2
- id: 0
2
+ id: 28
3
3
  type: fence
4
4
  title: Violation evidence omits raw edits deliberately because excerpts can contain secrets
5
5
  severity: high
6
6
  confidence: 0.9
7
7
  created: 2026-11-05
8
8
  authors: ["codex"]
9
+ promoted_by: Kibukx
10
+ promoted_by_source: explicit
9
11
  anchors:
10
12
  - path: src/scar/violation_evidence.py
11
13
  - path: src/scar/hooks.py
@@ -13,7 +15,7 @@ evidence:
13
15
  - issue: 317
14
16
  expires:
15
17
  condition: "a reviewed capture design can retain original edits without exposing arbitrary secrets"
16
- status: candidate
18
+ status: active
17
19
  ---
18
20
 
19
21
  The display excerpt is arbitrary edited content, not safe log text (#317).
@@ -0,0 +1,37 @@
1
+ ---
2
+ id: 0
3
+ type: landmine
4
+ title: Pooled stats must key a scar by (repo, id); a bare id fuses different scars and a pooled rate must be recomputed, never averaged
5
+ severity: high
6
+ confidence: 0.8
7
+ created: 2026-11-07
8
+ authors: ["claude-code"]
9
+ anchors:
10
+ - path: src/scar/cli.py
11
+ - pattern: "def _compliance_block"
12
+ evidence:
13
+ - issue: 373
14
+ - issue: 137
15
+ expires:
16
+ condition: "compliance pooling stops spanning more than one repository"
17
+ review_after: 2027-05-07
18
+ status: candidate
19
+ ---
20
+
21
+ Scar ids are per-repo sequential integers, so #1 in one repo is a different
22
+ scar from #1 in another. `--repo` pools several repos into one compliance block,
23
+ and the dominant-scar cut picks the single largest scar. Keyed by bare id, two
24
+ unrelated scars merge into one and the "top scar" share is invented. It is the
25
+ same defect as the original --all-repos double count (#137), reached through a
26
+ new door.
27
+
28
+ Two rules hold the block together. Identify a scar by (repo, id) everywhere in
29
+ `_compliance_block`. And pool by summing F, V and the verdict counts, then
30
+ computing the rate once; averaging per-repo rates weights a one-firing repo the
31
+ same as a thousand-firing one. Scope filters (window, repo set) run on records
32
+ before any metric, exactly like `_filter_window`, so a set of two repos equals a
33
+ log that contains only those two.
34
+
35
+ V is "fired then violated": a violation counts only if that scar has an armed
36
+ firing on the same target at or before it. The rest are retrieval misses and
37
+ are reported as `violations_unmatched`, not folded into V (#373).
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.28.0](https://github.com/Daily-Nerd/Scar/compare/v0.27.3...v0.28.0) (2026-11-07)
4
+
5
+
6
+ ### Features
7
+
8
+ * **stats:** compute the compliance result natively ([#374](https://github.com/Daily-Nerd/Scar/issues/374)) ([131a640](https://github.com/Daily-Nerd/Scar/commit/131a6400da7770d2a319155e2f0364c60260e3d1))
9
+
10
+ ## [0.27.3](https://github.com/Daily-Nerd/Scar/compare/v0.27.2...v0.27.3) (2026-11-07)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **store:** one owner creates candidates/ and init keeps it in git ([#371](https://github.com/Daily-Nerd/Scar/issues/371)) ([67ed3ae](https://github.com/Daily-Nerd/Scar/commit/67ed3aec8c0be8b0a4e8d1248cc95914ff560c95))
16
+
3
17
  ## [0.27.2](https://github.com/Daily-Nerd/Scar/compare/v0.27.1...v0.27.2) (2026-11-07)
4
18
 
5
19
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: scar-cli
3
- Version: 0.27.2
3
+ Version: 0.28.0
4
4
  Summary: SCAR — version control for negative knowledge (deadends, fences, landmines)
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -231,7 +231,7 @@ Top-level keys, and the keys of each object inside the listed arrays.
231
231
  | `check` | `paths` array of str, `scars` array | `scars[]`: `id`, `type`, `severity`, `confidence`, `status`, `title`, `body` |
232
232
  | `sweep` | `files` int (tracked files swept), `skipped` int (tracked files with no readable content: oversized or binary), `scars` int (scars armed on at least one swept file), `hits` array | `hits[]`: `id` int, `type`, `severity`, `title`, `source` (scar file, repo-relative), `path`, `line` int (1-based), `excerpt` |
233
233
  | `why` | `path` str, `records` array | `records[]`: `id`, `type`, `status`, `title`, `file`, `body` |
234
- | `stats` | `repo` str, `total_firings` int, `per_scar` array, `most_fired` int, `last_fired` str, `never_fired` array of int, `demotions` int, `demotions_path_only` int, `demotions_cooldown` int, `demotions_reason_unknown` int, `census_known` int, `census_unknown` int, `cofires_per_edit` float **or null**, `edits_multi_fire` int, `path_only_ratio` float **or null**, `edits_observed` int, `injection_rate` float **or null**, `retrieval_misses` int **or null**, `instrument_disconnected` bool, `posttool_silent` bool, `last_fired_age_days` int, `armed_firings` int, `armed_unknown` int, `verdicts_expected` int, `verdicts_observed` int, `verdicts_unresolved` int, `verdicts_unplaceable` int, `firings_block_capable` int, `firings_advisory` int, `firings_block_unknown` int, `all_firings_advisory` bool, `firings_context_known` int, `firings_context_unknown` int, `command_firings` int, `firings_kind_unknown` int, `advisories` array. `window` object **only when `--since`/`--until` is given** | `per_scar[]`: `id`, `count`, `violations`. `window`: `since`, `until`, `excluded_undated` |
234
+ | `stats` | `repo` str, `total_firings` int, `per_scar` array, `most_fired` int, `last_fired` str, `never_fired` array of int, `demotions` int, `demotions_path_only` int, `demotions_cooldown` int, `demotions_reason_unknown` int, `census_known` int, `census_unknown` int, `cofires_per_edit` float **or null**, `edits_multi_fire` int, `path_only_ratio` float **or null**, `edits_observed` int, `injection_rate` float **or null**, `retrieval_misses` int **or null**, `instrument_disconnected` bool, `posttool_silent` bool, `last_fired_age_days` int, `armed_firings` int, `armed_unknown` int, `verdicts_expected` int, `verdicts_observed` int, `verdicts_unresolved` int, `verdicts_unplaceable` int, `firings_block_capable` int, `firings_advisory` int, `firings_block_unknown` int, `all_firings_advisory` bool, `firings_context_known` int, `firings_context_unknown` int, `command_firings` int, `firings_kind_unknown` int, `advisories` array, `compliance` object (§9.12). `window` object **only when `--since`/`--until` is given** | `per_scar[]`: `id`, `count`, `violations`. `window`: `since`, `until`, `excluded_undated`. `compliance`: `F`, `V`, `rate`, `violations_unmatched`, `verdicts_expected`, `verdicts_observed`, `verdicts_resolved`, `verdict_completeness`, `top_scar` (`repo`, `id`, `share`, `F`, `V`, `rate`) |
235
235
  | `gc` | `removed_markers` int, `dropped_firings` int, `dry_run` bool, `candidates` array, `fp_log` object | `candidates[]`: `name`, `age_days`. `fp_log`: `present`, `size`, `lines`, `path` (the state-dir log, #341), `legacy` (`null`, or `path` + `lines` of a leftover `.scars/candidates/fp-log.txt`) |
236
236
  | `orphan` | `orphan_detected`, `partial_rot` arrays | — |
237
237
  | `reanchor` | `proposals`, `pattern_diagnostics` arrays | — |
@@ -554,3 +554,51 @@ map for each target. Files under `.scars/` remain eligible for matching other
554
554
  scars; there is no blanket directory exclusion. Logging remains best-effort:
555
555
  failure to append cannot block an edit, and a failed write does not claim that
556
556
  evidence was recorded.
557
+
558
+ ### 9.12 The compliance result is computed by `stats`
559
+
560
+ `stats.compliance` is the published enforcement result, computed by the same
561
+ code that computes every other `stats` field, over the same filtered records.
562
+ The keys are additive; no existing key changed.
563
+
564
+ | Key | Meaning |
565
+ |---|---|
566
+ | `F` | Armed firings: the sum of `armed_ids` over the filtered rows (same count as `armed_firings`) |
567
+ | `V` | Violations that followed an armed firing (definition below) |
568
+ | `rate` | `V / F`, rounded to 3 places; **`null` when `F` is 0, never 0** |
569
+ | `violations_unmatched` | Violations excluded from `V` because no earlier armed firing of that scar on that target is in the filtered records. Retrieval misses, reported apart, never dropped |
570
+ | `verdicts_expected` | Same as `stats.verdicts_expected` |
571
+ | `verdicts_observed` | Same as `stats.verdicts_observed` |
572
+ | `verdicts_resolved` | Expected verdicts that were observed (joined on `edit_id`) |
573
+ | `verdict_completeness` | `verdicts_resolved / verdicts_expected`; `null` when nothing was expected. Resolved, not observed, so a verdict that joins to nothing cannot push it past 1 |
574
+ | `top_scar` | The scar with the largest `F`: `repo`, `id`, `share` (its share of `F`), and `F`, `V`, `rate` **with that scar excluded**. All six fields are `null` when `F` is 0, and `rate` is `null` when the excluded `F` is 0 |
575
+
576
+ **Definition of V.** A violation row counts toward `V` when the violated scar
577
+ has an armed firing (`armed_ids` on the firing row itself, never today's
578
+ `.scars/`) on the same `target` at or before the violation's `ts`. This is
579
+ "fired, then violated". A violation with no such firing is a retrieval miss
580
+ (`retrieval_misses`), and counting it in `V` would let a retrieval failure
581
+ inflate an enforcement rate. Rows that predate `armed_ids` place no armed
582
+ firing, so a window made only of such rows has `F` 0 and a `null` rate.
583
+
584
+ **Top scar ties** go to the lowest `id`, then the lexicographically lowest
585
+ `repo`. A scar is identified by `(repo, id)`, because ids are per-repo.
586
+
587
+ **No threshold is a parameter.** `stats` always reports the top scar's share and
588
+ the excluded figures. What counts as dominant, and what completeness is enough,
589
+ belongs to a pre-registration written before the data is read.
590
+
591
+ **Scope.** `--repo PATH` (repeatable) restricts the records to a set of
592
+ repositories before any metric runs, exactly like `--since`/`--until`. Paths
593
+ resolve the way the hook stamps a record (the enclosing `.scars/` root, else the
594
+ resolved path). A path with no records is not an error: the block reports zeros
595
+ and nulls. `--repo` and `--all-repos` are mutually exclusive. The output is one
596
+ block with `repo_set: true`, `repos` (the selected repo keys), `total_firings`,
597
+ `last_fired`, `compliance` and `window` when given; the per-repo stage fields
598
+ are not pooled because their ids are not comparable. `F`, `V` and the verdict
599
+ counts are summed and the rate is computed once from the sums; per-repo rates
600
+ are never averaged. `--all-repos` carries one `compliance` block per repo group.
601
+
602
+ **`injection_rate` is coverage, not a retrieval rate.** It is the share of
603
+ observed edits where any scar fired. It does not say whether the right scar was
604
+ shown, and it must not be given a retrieval threshold.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scar",
3
- "version": "0.27.2",
3
+ "version": "0.28.0",
4
4
  "description": "SCAR — version control for negative knowledge (deadends, fences, landmines)",
5
5
  "hooks": {
6
6
  "PreToolUse": [
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "scar-cli"
3
- version = "0.27.2"
3
+ version = "0.28.0"
4
4
  description = "SCAR — version control for negative knowledge (deadends, fences, landmines)"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
File without changes
@@ -84,7 +84,7 @@ def _cmd_init(args) -> int:
84
84
  # decision, not damage, so re-running init never resurrects it.
85
85
  seeded = False
86
86
  if fresh and not getattr(args, "no_seed", False):
87
- example = scars / "candidates" / EXAMPLE_SEED_NAME
87
+ example = ScarStore(root=Path.cwd(), scars_dir=scars).ensure_candidates_dir() / EXAMPLE_SEED_NAME
88
88
  example.write_text(EXAMPLE_SEED, encoding="utf-8")
89
89
  seeded = True
90
90
  has_history = _has_git_history(Path.cwd())
@@ -1970,6 +1970,7 @@ def _stage_lines(block: dict, per_scar: list[dict], total_firings: int) -> list[
1970
1970
  if anchor_line:
1971
1971
  lines.append(anchor_line)
1972
1972
  lines += [demotions, cofires]
1973
+ lines += _compliance_lines(block)
1973
1974
  return lines
1974
1975
 
1975
1976
 
@@ -2029,6 +2030,11 @@ def _aggregate_firings(records: list[dict]) -> dict:
2029
2030
  # today's .scars/ — a scar armed last week was not armed last month.
2030
2031
  armed_firings = 0
2031
2032
  armed_unknown = 0
2033
+ # #373: the same armed count, split per scar, and the first armed firing of
2034
+ # each (scar, target). Both come from the ROW's own `armed_ids`, never from
2035
+ # today's .scars/, so the compliance block inherits the #266 guarantee.
2036
+ armed_by_scar: dict[int, int] = {}
2037
+ armed_first: dict[tuple[int, str], str] = {}
2032
2038
  # #277: verdict accounting. `expected` are joinable armed firings (an
2033
2039
  # armed_ids list with at least one id, plus an edit_id to join on);
2034
2040
  # `observed` are posttool rows that actually reached a verdict. Anything
@@ -2102,6 +2108,13 @@ def _aggregate_firings(records: list[dict]) -> dict:
2102
2108
  eid = rec.get("edit_id")
2103
2109
  if isinstance(armed, list):
2104
2110
  armed_firings += sum(1 for a in armed if isinstance(a, int))
2111
+ for a in armed:
2112
+ if isinstance(a, int) and not isinstance(a, bool):
2113
+ armed_by_scar[a] = armed_by_scar.get(a, 0) + 1
2114
+ if isinstance(target, str) and isinstance(ts_rec, str):
2115
+ prev = armed_first.get((a, target))
2116
+ if prev is None or ts_rec < prev:
2117
+ armed_first[(a, target)] = ts_rec
2105
2118
  # A verdict is owed only when something armed actually fired,
2106
2119
  # AND only when the row was written by a version that could
2107
2120
  # resolve it. The marker carries the second fact; armed_ids
@@ -2210,6 +2223,18 @@ def _aggregate_firings(records: list[dict]) -> dict:
2210
2223
  if first is None or first > vts:
2211
2224
  retrieval_misses += 1
2212
2225
 
2226
+ # #373: V is "fired THEN violated". A violation counts only when the same
2227
+ # scar had an ARMED firing on the same target at or before it. One without
2228
+ # is a retrieval miss (the scar was never shown), already reported as
2229
+ # retrieval_misses, and folding it into V would let a retrieval failure
2230
+ # inflate an enforcement rate. It is counted apart, never dropped.
2231
+ violations_joined: dict[int, int] = {}
2232
+ for vid, target, vts in pending_violations:
2233
+ first = armed_first.get((vid, target))
2234
+ if first is not None and first <= vts:
2235
+ violations_joined[vid] = violations_joined.get(vid, 0) + 1
2236
+ violations_unmatched = sum(violations.values()) - sum(violations_joined.values())
2237
+
2213
2238
  # Merge counts and violations: include all scars that fired OR violated
2214
2239
  all_scar_ids = set(counts.keys()) | set(violations.keys())
2215
2240
  per_scar = sorted(({"id": sid, "count": counts.get(sid, 0), "violations": violations.get(sid, 0)}
@@ -2242,6 +2267,14 @@ def _aggregate_firings(records: list[dict]) -> dict:
2242
2267
  retrieval_misses = None
2243
2268
 
2244
2269
  return {"counts": counts, "per_scar": per_scar, "last_fired": last_fired,
2270
+ "compliance_raw": {
2271
+ "armed_by_scar": armed_by_scar,
2272
+ "violations_by_scar": violations_joined,
2273
+ "violations_unmatched": violations_unmatched,
2274
+ "verdicts_expected": len(verdict_expected_ids),
2275
+ "verdicts_observed": verdicts_observed,
2276
+ "verdicts_resolved": len(verdict_expected_ids & verdict_seen_ids),
2277
+ },
2245
2278
  "retrieval_misses": retrieval_misses,
2246
2279
  "demotions": demotions,
2247
2280
  "demotions_path_only": demotions_path_only,
@@ -2296,6 +2329,80 @@ def _aggregate_firings(records: list[dict]) -> dict:
2296
2329
  "total": sum(counts.values())}
2297
2330
 
2298
2331
 
2332
+ def _compliance_block(parts: list[tuple[str, dict]]) -> dict:
2333
+ """The compliance result (#373): F armed firings, V violations that
2334
+ followed an armed firing, V/F, verdict completeness, and the dominant-scar
2335
+ cut. ONE code path for every scope: a single repo is a one-part list, a
2336
+ repository set is several, and --all-repos calls it once per repo.
2337
+
2338
+ `parts` is (repo key, aggregate) pairs. Counts are SUMMED across parts and
2339
+ the rate is computed once from the sums, so a rate is never averaged. A
2340
+ scar is identified by (repo, id), because ids are per-repo and a bare id
2341
+ would fuse two different scars into one. Nothing here is a threshold: the
2342
+ block always reports the top scar's share and the excluded figures, and
2343
+ deciding what counts as dominant belongs to a pre-registration.
2344
+ """
2345
+ f_by: dict[tuple[str, int], int] = {}
2346
+ v_by: dict[tuple[str, int], int] = {}
2347
+ unmatched = expected = observed = resolved = 0
2348
+ for repo_key, agg in parts:
2349
+ raw = agg["compliance_raw"]
2350
+ for sid, n in raw["armed_by_scar"].items():
2351
+ f_by[(repo_key, sid)] = f_by.get((repo_key, sid), 0) + n
2352
+ for sid, n in raw["violations_by_scar"].items():
2353
+ v_by[(repo_key, sid)] = v_by.get((repo_key, sid), 0) + n
2354
+ unmatched += raw["violations_unmatched"]
2355
+ expected += raw["verdicts_expected"]
2356
+ observed += raw["verdicts_observed"]
2357
+ resolved += raw["verdicts_resolved"]
2358
+ f_total = sum(f_by.values())
2359
+ v_total = sum(v_by.values())
2360
+
2361
+ def ratio(v: int, f: int):
2362
+ # Refused, not zero: V/F over no armed firings is not "perfect
2363
+ # compliance", it is no measurement.
2364
+ return round(v / f, 3) if f else None
2365
+
2366
+ top = {"repo": None, "id": None, "share": None, "F": None, "V": None,
2367
+ "rate": None}
2368
+ if f_total:
2369
+ # Ties go to the lowest id (then repo key), so the cut is reproducible.
2370
+ key = min(f_by, key=lambda k: (-f_by[k], k[1], k[0]))
2371
+ f_top, v_top = f_by[key], v_by.get(key, 0)
2372
+ top = {"repo": key[0], "id": key[1], "share": round(f_top / f_total, 3),
2373
+ "F": f_total - f_top, "V": v_total - v_top,
2374
+ "rate": ratio(v_total - v_top, f_total - f_top)}
2375
+ return {"F": f_total, "V": v_total, "rate": ratio(v_total, f_total),
2376
+ "violations_unmatched": unmatched,
2377
+ "verdicts_expected": expected, "verdicts_observed": observed,
2378
+ "verdicts_resolved": resolved,
2379
+ # resolved, not observed: a verdict row that joins to no expected
2380
+ # firing must not push completeness past 1.
2381
+ "verdict_completeness": round(resolved / expected, 3) if expected else None,
2382
+ "top_scar": top}
2383
+
2384
+
2385
+ def _compliance_lines(block: dict) -> list[str]:
2386
+ """One human line for the compliance block, shared by every renderer."""
2387
+ c = block.get("compliance")
2388
+ if not c:
2389
+ return []
2390
+ rate = "n/a" if c["rate"] is None else f"{c['rate']:.1%}"
2391
+ line = f"compliance: {c['V']} violation(s) / {c['F']} armed firing(s) = {rate}"
2392
+ if c["verdict_completeness"] is not None:
2393
+ line += (f"; verdicts {c['verdicts_resolved']}/{c['verdicts_expected']} "
2394
+ f"resolved ({c['verdict_completeness']:.1%})")
2395
+ if c["violations_unmatched"]:
2396
+ line += (f"; {c['violations_unmatched']} violation(s) with no earlier armed "
2397
+ "firing on that target (retrieval misses, not counted)")
2398
+ top = c["top_scar"]
2399
+ if top["id"] is not None:
2400
+ excl = "n/a" if top["rate"] is None else f"{top['rate']:.1%}"
2401
+ line += (f"; top scar #{top['id']} = {top['share']:.1%} of F; "
2402
+ f"without it {top['V']}/{top['F']} = {excl}")
2403
+ return [line]
2404
+
2405
+
2299
2406
  def _age_in_days(ts: str | None) -> int | None:
2300
2407
  """Whole days between a firing-log timestamp and now, or None if it can't
2301
2408
  be read. scar 0012: firing-log readers need blanket guards — a corrupt ts
@@ -2354,6 +2461,9 @@ def _cmd_stats(args) -> int:
2354
2461
  if getattr(args, "all_repos", False):
2355
2462
  return _stats_all_repos(records, log_path, args, window)
2356
2463
 
2464
+ if getattr(args, "repo", None):
2465
+ return _stats_repo_set(records, log_path, args, window)
2466
+
2357
2467
  store = _require_store()
2358
2468
  if store is None:
2359
2469
  return 1
@@ -2389,6 +2499,7 @@ def _cmd_stats(args) -> int:
2389
2499
  "never_fired": never_fired,
2390
2500
  **_stage_block(agg),
2391
2501
  **_health_block(agg),
2502
+ "compliance": _compliance_block([(repo_key, agg)]),
2392
2503
  "advisories": advisories,
2393
2504
  }
2394
2505
  if window is not None:
@@ -2449,7 +2560,8 @@ def _stats_all_repos(records: list[dict], log_path: Path, args,
2449
2560
  groups.append({"repo": repo_key, "total_firings": agg["total"],
2450
2561
  "per_scar": agg["per_scar"],
2451
2562
  "last_fired": agg["last_fired"],
2452
- **_stage_block(agg), **_health_block(agg)})
2563
+ **_stage_block(agg), **_health_block(agg),
2564
+ "compliance": _compliance_block([(repo_key, agg)])})
2453
2565
  groups.sort(key=lambda g: (-g["total_firings"], g["repo"]))
2454
2566
  data = {"all_repos": True, "repos": groups}
2455
2567
  if window is not None:
@@ -2482,6 +2594,65 @@ def _stats_all_repos(records: list[dict], log_path: Path, args,
2482
2594
  return 0
2483
2595
 
2484
2596
 
2597
+ def _resolve_repo_key(path_text: str) -> str:
2598
+ """The key the hook stamps on a record for the repo at `path_text`: the
2599
+ resolved store root when one is found, else the resolved path itself. A
2600
+ path with no store is not an error: it selects no records, and the block
2601
+ says so with zeros rather than refusing."""
2602
+ p = Path(path_text).expanduser().resolve()
2603
+ store = ScarStore.discover(p) if p.exists() else None
2604
+ return str(store.root) if store is not None else str(p)
2605
+
2606
+
2607
+ def _stats_repo_set(records: list[dict], log_path: Path, args,
2608
+ window: dict | None = None) -> int:
2609
+ """Repository-set scope (#373): `--repo PATH` (repeatable). Records are
2610
+ filtered to the set BEFORE any metric runs, the same way the window is, so
2611
+ the compliance block is computed by the code that computes it for one repo.
2612
+ Each repo is aggregated on its own and the compliance counts are pooled by
2613
+ `_compliance_block`; scar ids are never merged across repos, so the
2614
+ per-repo stage fields do not appear in this view (use the default scope or
2615
+ --all-repos for those)."""
2616
+ keys = sorted({_resolve_repo_key(t) for t in args.repo})
2617
+ selected = set(keys)
2618
+ by_repo: dict[str, list[dict]] = {k: [] for k in keys}
2619
+ for rec in records:
2620
+ repo = rec.get("repo")
2621
+ if isinstance(repo, str) and repo in selected:
2622
+ by_repo[repo].append(rec)
2623
+ parts = [(k, _aggregate_firings(by_repo[k])) for k in keys]
2624
+ last = [a["last_fired"] for _k, a in parts if a["last_fired"]]
2625
+ data = {
2626
+ "repo": ", ".join(keys),
2627
+ "repo_set": True,
2628
+ "repos": keys,
2629
+ "total_firings": sum(a["total"] for _k, a in parts),
2630
+ "last_fired": max(last) if last else None,
2631
+ "compliance": _compliance_block(parts),
2632
+ }
2633
+ if window is not None:
2634
+ data["window"] = window
2635
+
2636
+ def plain():
2637
+ if window is not None:
2638
+ print(f"scar stats: window {window['since'] or 'start'} .. "
2639
+ f"{window['until'] or 'now'}"
2640
+ + (f" ({window['excluded_undated']} record(s) excluded: "
2641
+ "no usable timestamp)" if window["excluded_undated"] else ""))
2642
+ print(f"scar stats: {data['total_firings']} firing(s) recorded across "
2643
+ f"{len(keys)} repo(s) ({log_path})")
2644
+ for k in keys:
2645
+ print(f" {k}")
2646
+ for line in _compliance_lines(data):
2647
+ print(f" {line}")
2648
+ print(" note: scars are counted per (repo, id); ids are not merged "
2649
+ "across repos and rates are computed from pooled counts")
2650
+
2651
+ output.render(data=data, json_flag=getattr(args, "json", False),
2652
+ tty=plain, plain=plain)
2653
+ return 0
2654
+
2655
+
2485
2656
  def _cmd_gc(args) -> int:
2486
2657
  """Clean machine state (~/.claude/scar-state/ or SCAR_STATE_DIR), report
2487
2658
  repo hygiene. Posture (#115): machine state is regenerable, so gc ACTS on
@@ -2847,10 +3018,13 @@ def _harvest_write(repo: Path, args) -> int:
2847
3018
  print(f"harvest --write: N must be 1..{_WRITE_CAP} — mined candidates "
2848
3019
  "run ~13% precision, more drafts than that buries the reviewer")
2849
3020
  return 1
2850
- cand_dir = repo / ".scars" / "candidates"
2851
- if not cand_dir.is_dir():
2852
- print(f"no .scars/candidates/ in {repo} — run `scar init` there first")
3021
+ scars_dir = repo / ".scars"
3022
+ if not scars_dir.is_dir():
3023
+ print(f"no .scars/ in {repo}: run `scar init` there first")
2853
3024
  return 1
3025
+ # candidates/ is not git-tracked when empty (#370); only a missing .scars/
3026
+ # means Scar is not set up. The store is the one owner of the folder.
3027
+ cand_dir = ScarStore(root=repo, scars_dir=scars_dir).ensure_candidates_dir()
2854
3028
 
2855
3029
  result = harvest(repo)
2856
3030
  tracked = set(_hgit(repo, "ls-files").splitlines())
@@ -3273,9 +3447,15 @@ def build_parser() -> argparse.ArgumentParser:
3273
3447
 
3274
3448
  p = _add(sub, "stats", _cmd_stats, help="firing counts from the precheck hook's firing log")
3275
3449
  p.add_argument("--json", action="store_true", help="emit machine-readable JSON")
3276
- p.add_argument("--all-repos", action="store_true",
3277
- help="show the whole machine-global log grouped per repo "
3278
- "(default: only the current repo's records)")
3450
+ scope = p.add_mutually_exclusive_group()
3451
+ scope.add_argument("--all-repos", action="store_true",
3452
+ help="show the whole machine-global log grouped per repo "
3453
+ "(default: only the current repo's records)")
3454
+ scope.add_argument("--repo", action="append", metavar="PATH",
3455
+ help="restrict to this repository's records; repeat to "
3456
+ "pool a set. Records are filtered before any "
3457
+ "metric, and rates are computed from pooled counts, "
3458
+ "never averaged")
3279
3459
  p.add_argument("--since", metavar="WHEN",
3280
3460
  help="only records at or after this ISO date/datetime "
3281
3461
  "(a bare date means 00:00:00 that day)")
@@ -104,8 +104,7 @@ def _draft(args: dict[str, Any]) -> dict[str, Any]:
104
104
  errors = [f.message for f in findings if f.level == "error"]
105
105
  if errors:
106
106
  raise ValueError("refusing to draft invalid scar: " + "; ".join(errors))
107
- candidates = store.scars_dir / "candidates"
108
- candidates.mkdir(exist_ok=True)
107
+ candidates = store.ensure_candidates_dir()
109
108
  stem = _slug(str(args.get("slug") or scar.title))
110
109
  path = candidates / f"{stem}.md"
111
110
  i = 2
@@ -169,7 +169,7 @@ def init_scars(repo_root: Path) -> Path:
169
169
  """Create .scars/ layout. Idempotent; never clobbers existing files."""
170
170
  scars = Path(repo_root) / ".scars"
171
171
  scars.mkdir(exist_ok=True)
172
- (scars / "candidates").mkdir(exist_ok=True)
172
+ ScarStore(root=Path(repo_root), scars_dir=scars).ensure_candidates_dir()
173
173
  for name, content in (("README.md", README), ("template.md", TEMPLATE)):
174
174
  f = scars / name
175
175
  if not f.exists():
@@ -247,8 +247,23 @@ class ScarStore:
247
247
  pass
248
248
  return out
249
249
 
250
+ @property
251
+ def candidates_dir(self) -> Path:
252
+ return self.scars_dir / "candidates"
253
+
254
+ def ensure_candidates_dir(self) -> Path:
255
+ """The one place candidates/ is created (#370). Idempotent. Also keeps
256
+ an empty .gitkeep so the folder survives the last promotion in git;
257
+ candidates() and lint only look at *.md, so it is never a candidate."""
258
+ cand = self.candidates_dir
259
+ cand.mkdir(exist_ok=True)
260
+ keep = cand / ".gitkeep"
261
+ if not keep.exists():
262
+ keep.write_text("", encoding="utf-8")
263
+ return cand
264
+
250
265
  def candidates(self) -> list[Path]:
251
- cand = self.scars_dir / "candidates"
266
+ cand = self.candidates_dir
252
267
  return sorted(p for p in cand.glob("*.md")) if cand.is_dir() else []
253
268
 
254
269
  def next_id(self) -> int:
@@ -1470,6 +1470,28 @@ def test_harvest_write_requires_scars_dir(tmp_path, capsys):
1470
1470
  assert "scar init" in capsys.readouterr().out
1471
1471
 
1472
1472
 
1473
+ def test_harvest_write_recreates_missing_candidates_dir(harvest_write_repo):
1474
+ """#370: a missing candidates/ is not 'Scar not initialised'; .scars/ is."""
1475
+ import shutil
1476
+ shutil.rmtree(harvest_write_repo / ".scars" / "candidates")
1477
+ assert main(["harvest", str(harvest_write_repo), "--write", "2"]) == 0
1478
+ assert list((harvest_write_repo / ".scars" / "candidates").glob("*.md"))
1479
+
1480
+
1481
+ def test_harvest_write_works_after_last_candidate_promoted(harvest_write_repo):
1482
+ """#370: with only .gitkeep left (last candidate promoted), harvest
1483
+ --write still runs."""
1484
+ cand = harvest_write_repo / ".scars" / "candidates"
1485
+ assert (cand / ".gitkeep").is_file()
1486
+ assert main(["harvest", str(harvest_write_repo), "--write", "2"]) == 0
1487
+ assert list(cand.glob("*.md"))
1488
+
1489
+
1490
+ def test_init_writes_candidates_gitkeep(repo):
1491
+ assert main(["init", "--no-seed"]) == 0
1492
+ assert (repo / ".scars" / "candidates" / ".gitkeep").is_file()
1493
+
1494
+
1473
1495
  def test_write_title_and_slug_sanitize_markdown_and_urls():
1474
1496
  """Git text (revert subjects, squash-merge subjects) can carry markdown
1475
1497
  links, emphasis, and bare URLs; leaked into a candidate they make the title