feat: Tier3Verdict.usage parity with @stackone/defender 0.7.2#18
Merged
Conversation
Let Tier 3 providers report prompt/completion/total token counts so callers can attribute LLM spend per request. Parses camelCase and snake_case usage dicts in verdict validation. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Adds Tier 3 token-usage reporting support so provider-reported usage (camelCase or snake_case) is parsed into a structured type and propagated into Tier3Verdict, aligning behavior with the referenced @stackone/defender parity goal.
Changes:
- Introduce
Tier3TokenUsageand add optionalusagetoTier3Verdict. - Parse
usagefrom provider verdict dicts and attach it toTier3Verdictduring validation. - Add tests to validate
usagepropagation and parsing behavior.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
uv.lock |
Updates the editable package version recorded in the lockfile. |
tests/test_tier3.py |
Adds coverage for usage propagation/parsing behavior. |
src/stackone_defender/types.py |
Defines Tier3TokenUsage and extends Tier3Verdict with an optional usage field. |
src/stackone_defender/core/prompt_defense.py |
Implements usage parsing and threads it into _validate_tier3_verdict. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Export Tier3TokenUsage from the package root and cover usage parsing via the public defend_tool_result_async API instead of private helpers. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Tier3TokenUsage(prompt_tokens,completion_tokens,total_tokens) onTier3Verdictto match npm 0.7.2 (#71)usagefrom provider dict verdicts (camelCase and snake_case keys, same pattern aslatency_ms/latencyMs)result.tier3.usagewithout orchestrator changesTest plan
uv run pytest tests/test_tier3.py— 26 passeduv run pytest— 277 passedMade with Cursor