feat: add noirdoc ns summary <ns> for counts-only namespace inspection - #2
Merged
Conversation
`ns show` dumps the full reverse mapping (pseudonym → original) and is
unsafe to call from any context that captures stdout — wrappers, audit
pipelines, and the noirdoc-claude-plugin all currently work around this
by either blocking the call or losing useful info.
`ns summary` returns only counts:
{ "namespace": "...", "total_entities": N, "by_type": { ... } }
Implementation reuses the per-label counter the mapper already maintains;
no regex parsing of placeholder keys, no access to private attributes
from the CLI. Not-found contract (stderr + exit 1) matches `ns show`.
Closes #1
comppaz
added a commit
that referenced
this pull request
Apr 27, 2026
The v0.1.1 tag shipped without a corresponding changelog section, so the daemon (PR #3) was undocumented and `ns summary` (PR #2) was still parked under [Unreleased]. Backfill the section now so the GitHub release link (which dereferences to CHANGELOG.md) and future readers see what 0.1.1 actually contained. Documentation-only; no code change, no re-tag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1.
Summary
noirdoc ns summary <ns>returns only counts —total_entitiesand per-labelby_type— never the original values.noirdoc-claude-plugin's/noirdoc-status), CI/audit scripts, and any pipeline that captures stdout into longer-lived buffers.ns show, which remains the human-facing full-mapping dump.Output shape matches the issue spec:
{ "namespace": "mandant-foo", "total_entities": 42, "by_type": { "PERSON": 12, "EMAIL": 7, "IBAN": 3, "LOCATION": 15, "DATE": 5 } }Implementation notes
PseudonymMapper._counters(already maintained per unique entity insideget_or_create) via a new publicget_counts_summary()method — no regex parsing of placeholder keys, no reaching into private attributes from the CLI.total_entitiesis sourced fromentity_count(canonical mapping size),by_typefrom the counter map. In custom-label mode (PseudonymMapper(label="X")),by_typereflects the label, matching what the placeholder format actually encodes.ns show: stderr"Namespace '<name>' does not exist."and exit code 1.Test plan
tests/test_mapper.py::test_counts_summary— unit test for the new mapper method, including an assertion that originals never appear injson.dumps(summary)tests/test_cli.py(new file) —CliRunnercovering the happy path (asserts originals don't leak into stdout) and the not-found path (asserts the exact error message + exit 1)ruff check,ruff format --check,mypyclean on touched filesnoirdoc ns summary __does_not_exist__→ stderr message + exit 1;--helplists the new commandPre-existing failures in
test_flair_recognizer.py(missing[full]extra) and two Presidio detector tests are unrelated to this change.Follow-up (not in this PR)
After release,
noirdoc-claude-plugin's/noirdoc-statusshould be updated to callns summaryinstead ofns list, and itsPreToolUsehook should allowns summary(still blockingns showandlookup).