Uh oh!
There was an error while loading. Please reload this page.
feat(coder): meter bridge-default key against free MIND allotment - #17
Merged
Conversation
…ment The coder's "env-fallback" path (shared bridge OPENROUTER_API_KEY) now spends a user's free MIND allotment from the mind-node ledger: it gates a run on the owner's balance and debits a flat price on success. A user on their own key (source "user-pref") is never metered; with the ledger off (no MIND_NODE_URL / MIND_OPERATOR_TOKEN env), env-fallback runs unmetered exactly as before. - src/lib/ledger/client.ts — server-only operator client (getBalance, debit) - src/lib/ledger/policy.ts — pure gateEnvFallback decision (unit-tested) - coder driver — gate before run (block with "add your key" at 0), debit once on a successful run (failed/late debit never fails the user after the fact) - GET /api/profile/ai — returns freeBalance so the builder can show it Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.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 freeto 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.
What
Meters the coder's bridge-default (
env-fallback, sharedOPENROUTER_API_KEY) runs against a user's free MIND allotment in the mind-node ledger. BYOK runs (user-pref) and the ledger-off case are unchanged.How
src/lib/ledger/client.ts— server-only operator client (getBalance,debit) over mind-node/.admin/tokens*.src/lib/ledger/policy.ts— puregateEnvFallback: ledger off → allow unmetered; balance spent → block; has/unknown balance → allow + meter (fail open on a ledger outage).drivers/coder.ts) — gates an env-fallback run on the owner's balance (blocks at 0 with "connect your own key at /profile/ai-providers"), then debits once on a successful run. A failed/late debit never fails the user after the work is done.GET /api/profile/ai— returnsfreeBalanceso the Builder UI can show remaining MIND.Rollout (safe, env-gated)
Unset
MIND_NODE_URL/MIND_OPERATOR_TOKEN⇒ no metering, today's behavior. Depends on mind-nodePOST /.admin/tokens/debit(MIND-Studio/mind-node#9).Tested
vitest run tests/ledger-gate.test.ts— 4/4 (gate decision matrix).tsc --noEmitclean.🤖 Generated with Claude Code