Skip to content

feat(usage): polymorfa usage summary, records and gates - #28

Merged
purpshell merged 13 commits into
devfrom
t3code/usage-metering-gates
Sep 23, 2026
Merged

purpshell merged 13 commits into
devfrom
t3code/usage-metering-gates

Conversation

@purpshell

@purpshell purpshell commented Sep 20, 2026 •

Copy link
Copy Markdown
Member

Adds polymorfa usage summary, usage records, and usage gates for the Calls metering contract merged in monorepo #228 at fdaff9a86220e3ef1f8ad75cc838dbfd03ede4eb. The commands use typed Client.usage methods from SDK #283, merged at eaa7f67a6dd24e67fea4a1a22fc5a85fad39deb9. The exact published @polymorfa/sdk@0.1.0-dev.20260923132258 tarball is pinned in the lockfile with integrity sha512-ol2nSNl0tfRJQOAk1kywPwMu3+7KJxO1pVVlZj5S6Akj2+mnyKzjSgSU1EVHIObDLY9LLgg/kkTSeVbBmf0FGg==.

summary reports one UTC month by meter and number; records reads newest-first pages and prints the next cursor; gates shows team gate state. Team keys can read across projects or select one with --project. Project tokens can read only their bound project's summary and records, with --project or a project-bound profile; the API refuses their gate reads with 403. A malformed period fails before a request. Usage is measured and unpriced; the outgoing Calls gate remains record-only. Calls remains unreleased, so merged commands alone do not establish customer access.

The branch normally merges current CLI dev at a63a6d84989c7c845e99d69af6c84a07e0f27ad9; its diff against that base is limited to usage commands, their typed service and tests, the exact SDK pin, and usage guidance. The latest dev Campaign behavior, including immediate stop without an operation, is retained.

Part Assessment
API Accepted upstream. Monorepo #228 owns handlers, authority, schemas, errors, usage/gate behavior and webhooks. This PR changes no API runtime.
SDKs Accepted upstream. SDK #283 supplies the exact typed methods and payloads pinned here. The CLI uses no raw usage transport.
CLI Updated. Commands, flags, help, typed calls, project-token scoping, JSON/human output, cursor display and failure exits are covered here.
Docs Updated. CLI README documents the commands and credential boundary with an access qualifier. The merged monorepo holds the authoritative API references and an internal unreleased guide; there is no customer launch changelog yet.
Feature releases Unchanged. Calls remains unreleased. No flag, entitlement, enrollment, price, rollout or deployment changed.
Admin Unaffected. This CLI adds no staff capability; aggregate gate/usage authority remains in merged API #228.

Full Node 22 npm run verify passed against the exact published SDK: formatting, lint, typecheck, 730 tests in 79 files, build, package dry run, and production audit with zero vulnerabilities. Command-level HTTP tests cover project-token binding, team-wide/default reads, pagination, malformed period, gate refusal, response metadata and output. A live credential and deployed API were not exercised. Fresh current-head CI and review are required before merge.

Reads /platform/usage, /platform/usage/records and /platform/gates through
the raw client until the typed SDK resource is published. Usage is measured,
not charged.

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 74 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 929f63e1-922f-4680-90f7-d25ecdb3e05d

📥 Commits

Reviewing files that changed from the base of the PR and between a63a6d8 and 281e3b8.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • README.md
  • package.json
  • src/commands/usage/gates.ts
  • src/commands/usage/records.ts
  • src/commands/usage/summary.ts
  • src/services/usage.ts
  • test/commands/usage.test.ts

Comment @coderabbitai help to get the list of available commands.

Co-Authored-By: Claude <noreply@anthropic.com>
@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T13:33:32.297572Z 281e3b8 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8023bae7d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/services/usage.ts Outdated
Comment on lines +169 to +173
...summary.numbers.map(
(number) =>
`${number.session}\t${number.meters
.map((total) => `${total.meter} ${total.quantity} ${total.unit}`)
.join(', ')}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include project IDs in cross-project number rows

When a team key requests a summary without --project, summary.projectId is null and the response can contain numbers from multiple projects, but these rows discard each entry's projectId. Sessions with the same name therefore render as indistinguishable duplicate rows, so users cannot attribute the per-number totals to the correct project; include the per-entry project identifier in this cross-project view.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 83dce18: when the summary covers every project (projectId null), each number row prints its project after the session. Project-scoped summaries keep the header line only. Tests cover both cases.

@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8023bae7d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/services/usage.ts
record.occurredAt,
record.meter,
`${record.quantity} ${record.unit}`,
record.session ?? '-',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Show each record's project in cross-project output

When a team key runs usage records without --project, the response can contain records from multiple projects, but the human-readable rows discard record.projectId. Sessions can share names across projects, so users cannot reliably attribute these records to a project; include the project identifier in the cross-project rendering.

Useful? React with 👍 / 👎.

@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 8023bae7d0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@purpshell

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 281e3b8960

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

),
{
...(flags.period === undefined ? {} : {period: flags.period}),
...(flags.project === undefined ? {} : {project: flags.project}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Send the resolved project UUID to usage APIs

When an organization-key user passes a project slug, developerEnvironment resolves it to a canonical UUID, but this reconstructs the projectId query from the original flags.project value. The API therefore receives the slug in a UUID field and rejects an otherwise supported --project <slug> invocation. The records and gates commands repeat the same pattern; retain the resolved environment and pass environment.context.projectId, as the call-analytics commands do.

Useful? React with 👍 / 👎.

@purpshell

Copy link
Copy Markdown
Member Author

Merge gate for exact head 281e3b89605a605ddfba6397d4cabfa22f716d96 (base dev): Node 22 CI passed, and the current-head GitHub Codex review completed clean. A separate local codex review --base origin/dev was clean; local Node 22 verification passed 730 tests, build, pack, and production audit. CodeRabbit reported “Review rate limited,” so its green status is not a clean review. The owner explicitly approved merging CLI #28 with CI + Codex and recording this missing CodeRabbit review. This exception applies to this PR/head only. Calls remains unreleased; this merge does not establish customer availability.

@purpshell
purpshell merged commit 4a730e8 into dev Sep 23, 2026
3 checks passed
@purpshell
purpshell deleted the t3code/usage-metering-gates branch October 26, 2026 15:52
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