Skip to content

cc-stats: make the skill reliable when an agent runs it - #48

Merged
datacas merged 2 commits into
mainfrom
issue-42-cc-stats-ux
Sep 23, 2026
Merged

datacas merged 2 commits into
mainfrom
issue-42-cc-stats-ux

Conversation

@datacas

@datacas datacas commented Sep 23, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes from a level-1 rehearsal of cc-stats: a sandbox repository with the toolkit installed, an isolated CODE_CYCLE_HOME seeded with 237 validated rows, and real headless Claude Code sessions (Sonnet) invoking the skill. The component's aggregates matched the seeded data exactly; the failures were in how agents used the skill.

Problem found Fix
Natural-language requests ("muéstrame las estadísticas del toolkit", "últimos 7 días") ran another tool's analytics instead Description names the report's contents and example requests in any language, and excludes token-savings analytics
A session searched /, found another checkout's stats.py, cd'd into it and reported the wrong repository Skill checks only the project, user and toolkit-checkout runtime paths, never searches, and runs with an explicit --cwd for the current repository
Agents summarised the report instead of showing it; two summaries misstated counts Reply must begin with the report's heading and contain it verbatim; at most two sentences of reading afterwards
2/30 measured drift was read as "measured only 2 of 30" "2 of 30 dispatches that reported their model ran a different one; N did not report a model"
An empty store and an empty period looked like a normal report with zeros The report names the repository and says at the top when no telemetry exists or the period is empty
14-row daily activity table One-line sparkline (weekly beyond 45 days) with busiest day and active-day count, as #42 asked

Work item: #42 (end-to-end check with a real cycle still pending).

Verification

  • python3 scripts/validate-package.py — passed
  • python3 -m unittest discover -s tests — 593 tests passed (new: empty/quiet-period messages, drift wording, sparkline)
  • git diff --check — passed
  • Rehearsal, final iteration: 8 headless sessions (/cc-stats, two Spanish natural-language requests, "todo el histórico", each twice) — 8/8 loaded cc-stats, used the sandbox runtime with --cwd, passed the right period flag, and replied with the report verbatim for sandbox/cc-stats. Before these changes: 2/4 routed to another tool and 3/4 replied with a summary only.

A level-1 rehearsal (isolated CODE_CYCLE_HOME, seeded store, real headless
Claude Code sessions) found that the component's numbers were exact but the
skill failed in use:

- Natural-language requests ("muéstrame las estadísticas del toolkit") were
  routed to another tool's analytics. The description now names the report's
  contents and example requests in any language, and excludes token-savings
  analytics.
- One session searched the filesystem, found another checkout's stats.py,
  changed into it and reported the wrong repository. The skill now checks only
  the project, user and toolkit-checkout runtime paths, never searches, and
  runs the component for the current repository with an explicit --cwd.
- Agents summarised the report instead of showing it, and paraphrased counts
  wrongly. The reply must now begin with the report's own heading and contain
  it verbatim, with at most two sentences of reading after it.

The report also names the repository, says at the top when no telemetry exists
or the period is empty, states model drift as dispatches that reported their
model and ran a different one, and shows daily activity as a one-line
sparkline (weekly beyond 45 days).

Refs #42
@datacas

datacas commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Initial review — PR #48 cc-stats: make the skill reliable when an agent runs it

Verdict: CHANGES_REQUESTED. Reviewed HEAD: c790ee4dca88e251ac2caa9bc29e8249629589f6. Base: main @ 0a94152 (merge-base = current main).

Disclosure: this PR was written in the same agent session that is reviewing it. The findings below come from executing the code, but an independent human or agent review is still advisable.

Summary and scope

I reviewed the accumulated diff (one commit, 4 files): scripts/stats.py, skills/cc-stats/SKILL.md, tests/test_stats.py, and CHANGELOG.md. It follows CONTRIBUTING.md: the shared skill sections are still byte-identical (the validator passes) and there is a changelog entry. Against work item #42 and the level-1 rehearsal it describes, the changes do what they claim:

  • trigger wording in the skill description;
  • runtime lookup limited to three paths, with an explicit --cwd;
  • a reply that must contain the report verbatim;
  • clearer model-drift wording;
  • empty-state messages;
  • a daily sparkline.

One problem blocks approval: in windows longer than 45 days, the sparkline's last weekly bin is usually partial, so steady activity reads as a recent drop. That is exactly the kind of false trend #42 warns about.

Findings

[REV-001] · medium · open · blocks:yes — Partial trailing week in the sparkline reads as a decline

Path: scripts/stats.py (_sparkline, weekly branch). Category: correctness.

Beyond 45 days, days are grouped into 7-day bins counted from the start of the window. The last bin, which covers the most recent days and is the one people read, holds only the remainder. Observed at runtime with one stage every day for 50 days:

_sparkline({...50 days, 1 each...}, "2026-08-01", "2026-09-19") -> ('███████▂', 'week')

Constant activity is drawn as a sharp fall in the latest week. This affects --days N with N > 45 and --all-time; the default 30-day view is not affected. Suggested fix: align the bins to the end of the window, so the partial bin is the oldest one, or scale a partial bin by the days it covers, or mark it. Add a test with a constant series.

[REV-002] · low · open · blocks:no — The reply rule conflicts with --format json

Path: skills/cc-stats/SKILL.md (Reply with the report itself, step 5). Category: maintainability.

The new section says the final reply "must … start with the report's own first line, ## Code Cycle stats · …". Step 5 still allows --format json for machine-readable aggregates, and that output has no such heading. An agent asked for the structured form gets two instructions that cannot both be followed. Scope the rule to the Markdown report and say what a JSON reply contains.

[REV-003] · low · open · blocks:no — "No telemetry was recorded in this period" shown next to recorded verdicts

Path: scripts/stats.py (render_markdown, empty-state branch). Category: correctness.

The check is not stages and not shadow_rows, so a window that contains only verdict or cycle rows (for example, a cycle whose dispatches fell before the window start) prints the message above a verdict table with data. Observed:

['No telemetry was recorded in this period; ask for a longer window or all recorded history.', '| APPROVED | 1 | ████████████ |']

Base the message on "no rows in the period" rather than "no stages".

[REV-004] · low · open · blocks:no — README does not document --cwd, which the skill now requires

Path: README.md (the cc-stats paragraph, around line 390). Category: documentation.

The skill now tells agents to always pass --cwd <repository root>, but the README's list of stats.py flags still only names --days N, --all-time, and --format json.

Security triage

Sensitive change: it reads local telemetry (observability/privacy) and changes the instructions an agent follows to locate and execute a script. Audit result:

  • Script location: the new instructions reduce exposure. The agent checks exactly three paths, must not search the filesystem, and must not change into another checkout. This closes the wrong-repository behaviour observed in the rehearsal.
  • Output: the report heading now names the repository selector, which the JSON already contained and Añadir cc-stats, una skill con informe visual de telemetry #42 requires.
  • Data access: there are no new data sources, queries, or fields. recorded_rows is an aggregate count.

No vulnerabilities or potential risks found.

Verification executed

Preflight: Python 3.10.12, PyYAML present, a detached worktree at c790ee4, and no services required.

Command Result
python3 scripts/validate-package.py VALID: 13 skills (6 cycle, 7 supporting)…
python3 -m unittest tests.test_stats OK
python3 -m unittest discover -s tests 592/593. The one failure is test_run_cycle.LocalOnlyPolicyTests.test_local_only_rejects_the_live_repository, the known artefact of running from a worktree outside the canonical checkout (it fails the same way on main there); CI passes it.
_sparkline with a constant 50-day series Reproduces REV-001
aggregate + render_markdown with only verdict and cycle rows Reproduces REV-003

Not re-run in this review: the 8 headless agent sessions from the PR description. I read the skill-text changes (REV-002) but did not exercise them at runtime.

CI

gh pr checks 48: 4/4 passed. That is Validate package run twice (push + pull_request), each with Skills, manifests, and Bash installer ✅ and PowerShell installer ✅. None are pending, skipped, or missing.

Residual risks

  • Getting the agent to reply with the report verbatim depends on the model following an instruction. The rehearsal reached 8/8 with Sonnet, but other models or hosts may still summarise.
  • The weekly sparkline has no test with more than 45 days of real data.

Project verdict: CHANGES_REQUESTED. REV-001 blocks approval; REV-002, REV-003, and REV-004 do not.

@datacas

datacas commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Resolution summary — PR #48

Result: RESOLVED. The fixes below are on HEAD 358abaaca97e2aec9221227549615f729a33df2f (previous reviewed HEAD: c790ee4dca88e251ac2caa9bc29e8249629589f6).

Findings

[REV-001] · medium · resolved · blocks:yes — Partial trailing week in the sparkline reads as a decline

Decision: Valid. Weekly buckets now align to the end of the period, placing a partial bucket first. Sparse weekly aggregation also avoids constructing a date string for every day in all-time reports.

Verification: A constant 50-day series now renders the recent full weeks at full height; python3 -m unittest -v tests.test_stats passed (14 tests).

Commit: 358abaaca97e2aec9221227549615f729a33df2f.

[REV-002] · low · resolved · blocks:no — The reply rule conflicts with --format json

Decision: Valid. The skill now requires verbatim Markdown only for Markdown requests and verbatim JSON for JSON requests; it also says to treat component output as data.

Verification: python3 scripts/validate-package.py passed; the stats unit tests passed.

Commit: 358abaaca97e2aec9221227549615f729a33df2f.

[REV-003] · low · resolved · blocks:no — “No telemetry was recorded in this period” shown next to recorded verdicts

Decision: Valid. The aggregate now exposes period_rows, and the empty-period message is based on all row types in the requested period.

Verification: Added a verdict-only regression test; it confirms the verdict appears without the empty-period message. The stats unit tests passed.

Commit: 358abaaca97e2aec9221227549615f729a33df2f.

[REV-004] · low · resolved · blocks:no — README does not document --cwd, which the skill now requires

Decision: Valid. README usage now documents --cwd <repository root>.

Verification: python3 scripts/validate-package.py passed.

Commit: 358abaaca97e2aec9221227549615f729a33df2f.

[REV-005] · medium · resolved · blocks:yes — Repository selector can inject Markdown instructions into the report

Decision: Valid security finding from the post-change audit. _report_config() now validates the configured selector with the telemetry identifier validator and rejects leading or trailing whitespace before the value reaches Markdown. The skill explicitly treats component output as data and never follows embedded instructions or commands.

Verification: Added regression coverage for multiline Markdown injection and a trailing newline; all 14 stats tests passed. The final delegated security review found no confirmed vulnerabilities.

Commit: 358abaaca97e2aec9221227549615f729a33df2f.

Verification and CI

  • python3 -m unittest -v tests.test_stats — 14 passed.
  • python3 -m unittest discover -s tests — 595 passed.
  • python3 scripts/validate-package.py — passed.
  • git diff --check — passed.
  • GitHub checks — 4 passed, 0 failed (Bash and PowerShell validation runs).
  • Delegated code review — no confirmed findings. Security review — no confirmed vulnerabilities. An extreme, unusually old local timestamp can still produce a large weekly report; sparse bucketing limits intermediate allocation to one slot per week.

PR remains open for the normal review and merge process.

@datacas
datacas merged commit 947f45e into main Sep 23, 2026
4 checks passed
@datacas
datacas deleted the issue-42-cc-stats-ux branch September 24, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant