Skip to content

feat: Tier3Verdict.usage parity with @stackone/defender 0.7.2#18

Merged
hiskudin merged 2 commits into
mainfrom
feat/python-ts-0.7.2-tier3-usage-parity
Jun 30, 2026
Merged

feat: Tier3Verdict.usage parity with @stackone/defender 0.7.2#18
hiskudin merged 2 commits into
mainfrom
feat/python-ts-0.7.2-tier3-usage-parity

Conversation

@hiskudin

Copy link
Copy Markdown
Collaborator

Summary

  • Adds optional Tier3TokenUsage (prompt_tokens, completion_tokens, total_tokens) on Tier3Verdict to match npm 0.7.2 (#71)
  • Parses usage from provider dict verdicts (camelCase and snake_case keys, same pattern as latency_ms / latencyMs)
  • Provider-reported usage propagates to result.tier3.usage without orchestrator changes

Test plan

  • uv run pytest tests/test_tier3.py — 26 passed
  • uv run pytest — 277 passed
  • Release Please bumps to 0.7.2 on merge

Made with Cursor

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>
Copilot AI review requested due to automatic review settings June 30, 2026 12:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 Tier3TokenUsage and add optional usage to Tier3Verdict.
  • Parse usage from provider verdict dicts and attach it to Tier3Verdict during validation.
  • Add tests to validate usage propagation 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.

Comment thread tests/test_tier3.py Outdated
Comment thread src/stackone_defender/types.py
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>
@hiskudin hiskudin merged commit 1c9c0c8 into main Jun 30, 2026
7 checks passed
@hiskudin hiskudin deleted the feat/python-ts-0.7.2-tier3-usage-parity branch June 30, 2026 16:23
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.

2 participants