Skip to content

feat(miner): add a ledger metrics command that renders event-ledger Prometheus text (#4841) - #5486

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
cleanjunc:feat-miner-event-ledger-metrics
Jul 12, 2026
Merged

feat(miner): add a ledger metrics command that renders event-ledger Prometheus text (#4841)#5486
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
cleanjunc:feat-miner-event-ledger-metrics

Conversation

@cleanjunc

Copy link
Copy Markdown
Contributor

Summary

The event ledger is a structured audit trail, but the only way to consume it is gittensory-miner ledger list --json — there is no scrape surface a self-hoster's own Grafana/Prometheus/alerting can ingest without polling that command and re-parsing its output (#4841).

This adds a gittensory-miner ledger metrics subcommand that renders the event ledger as Prometheus text-exposition counters:

# HELP gittensory_miner_events_total Event-ledger entries the miner has recorded, by event type.
# TYPE gittensory_miner_events_total counter
gittensory_miner_events_total{type="discovered_issue"} 12
gittensory_miner_events_total{type="manage_pr_update"} 3

One gittensory_miner_events_total{type} series per event type, so a new ledger entry is observable on the next scrape without polling ledger list. A scrape wrapper or cron job runs the command and serves/redirects its stdout.

The renderer mirrors the metric-naming and HELP/TYPE/label conventions of the engine's existing renderMinerPredictionMetrics (packages/gittensory-engine/src/miner-prediction-metrics.ts) — the same pattern the metrics command already uses for prediction-calibration counters. It is pure and side-effect-free (the caller supplies the rows and prints the result), deterministic (series sorted by type), and always emits HELP/TYPE so an empty ledger is still a well-formed document. Like ledger list, the command is strictly local and offline: it reads only the local event ledger and makes no network calls.

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate. Every changed line and branch here is covered (verified via coverage/lcov.info BRDA intersected with git diff -U0).
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • This is an isolated packages/gittensory-miner/lib change (the event-ledger CLI plus its --help line) with no worker, MCP, OpenAPI, or UI surface. The checks that actually exercise it were run locally and are green: git diff --check, npm run actionlint, npm run typecheck, npm run test:coverage (changed lines and branches at 100%), npm run build:miner (node --check over the miner lib), npm run miner:env-reference:check (confirms the change adds no new env.* read, so the env-reference doc is unchanged), and npm audit --audit-level=moderate. The test:workers, build:mcp, test:mcp-pack, and ui:* jobs do not touch this package and are covered by this PR's CI.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

Notes

  • No UI/API/MCP/OpenAPI surface changes — this is a CLI-only, offline addition, so the auth/CORS negative-path and UI-evidence boxes are not applicable.
  • Tests cover every new line and branch: the renderer (sorted multi-type output, the empty ledger, label-value escaping), runLedgerMetrics (render + exit 0, its own default-ledger open/close path, the unexpected-argument usage error, and both the Error and non-Error catch arms), the runLedgerCli metrics dispatch, and the new --help line.

Closes #4841

@cleanjunc
cleanjunc requested a review from JSONbored as a code owner July 12, 2026 23:02
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.74%. Comparing base (849e11e) to head (655ee33).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5486   +/-   ##
=======================================
  Coverage   94.73%   94.74%           
=======================================
  Files         561      561           
  Lines       44794    44815   +21     
  Branches    14667    14667           
=======================================
+ Hits        42437    42458   +21     
  Misses       1622     1622           
  Partials      735      735           
Flag Coverage Δ
shard-1 43.77% <9.52%> (-0.52%) ⬇️
shard-2 35.36% <0.00%> (+0.08%) ⬆️
shard-3 31.66% <9.52%> (-0.36%) ⬇️
shard-4 31.63% <9.52%> (+0.24%) ⬆️
shard-5 33.14% <100.00%> (-0.09%) ⬇️
shard-6 43.84% <0.00%> (+0.25%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/gittensory-miner/lib/cli.js 100.00% <ø> (ø)
packages/gittensory-miner/lib/event-ledger-cli.js 96.69% <100.00%> (+0.69%) ⬆️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cleanjunc
cleanjunc marked this pull request as draft July 12, 2026 23:07
@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 12, 2026
@loopover-orb

loopover-orb Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ Gittensory review result - approve/merge recommended

Review updated: 2026-07-12 23:13:50 UTC

5 files · 2 AI reviewers · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This adds a `ledger metrics` subcommand that renders event-ledger event counts as Prometheus text, closely mirroring the existing `renderMinerPredictionMetrics` pattern (naming, HELP/TYPE conventions, escaping, sorted output, trailing-newline handling). The implementation is correct: it aggregates by type, sorts deterministically, escapes label values, and reuses the established `withEventLedger`/`runLedgerList` error-handling shape. Tests cover the renderer (empty ledger, escaping, sort order), the CLI wrapper (default vs injected ledger, usage errors, thrown errors), and dispatch via `runLedgerCli`, closely mirroring the sibling `metrics-cli.js` test suite.

Nits — 5 non-blocking
  • The external brief's 'magic number 4841' and 'debug leftover console' flags are false positives — `Add a push/scrape surface for the event ledger #4841` is just an issue reference in a comment and the `console.log`/`console.error` calls are the command's intended stdout/stderr output, matching the pattern in `runLedgerList` and `runMetrics`.
  • packages/gittensory-miner/lib/event-ledger-cli.js: the metric-naming/escaping helpers (`escapeHelpText`, `escapeLabelValue`, `MINER_EVENTS_TOTAL`) duplicate the engine's `miner-prediction-metrics.ts` almost verbatim; the comment explains this is intentional to avoid a cross-package import, which is a reasonable but debatable tradeoff worth double-checking with the maintainers if the engine package is meant to be the shared home for this kind of renderer.
  • No CLI usage/help text example is added showing sample output for `ledger metrics` the way the PR description does — minor doc completeness gap in `cli.js`'s help listing.
  • Consider whether `renderEventLedgerMetrics`'s duplicated escaping helpers should eventually be extracted to a shared location (e.g. gittensory-engine) if a third metrics-emitting command appears, to avoid a third copy-paste.
  • packages/gittensory-miner/lib/event-ledger-cli.d.ts: type signature `readonly LedgerEntry[]` is a nice touch for immutability guarantees on the public API.
Signal Result Evidence
Code review ✅ No blockers 2 reviewers, synthesized
Linked issue ✅ Linked #4841
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 68 registered-repo PR(s), 28 merged, 30 issue(s).
Contributor context ✅ Confirmed Gittensor contributor cleanjunc; Gittensor profile; 68 PR(s), 30 issue(s).
Gate result ✅ Passing No configured blocker found.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence. LLM value judgment: moderate — The PR adds a small, well-tested, self-contained scrape endpoint for an existing local data source, following an established pattern in the same package, giving self-hosters a genuine new observability capability with low risk.
Review context
  • Author: cleanjunc
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 68 PR(s), 30 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
[BETA] Chat with Gittensory

Ask Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @gittensory ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @gittensory chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @gittensory mention with a real question is routed to the closest matching read-only command automatically -- no exact syntax required.

Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@cleanjunc
cleanjunc marked this pull request as ready for review July 12, 2026 23:11

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gittensory approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 16b4191 into JSONbored:main Jul 12, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a push/scrape surface for the event ledger

1 participant