Skip to content

feat(coder): meter bridge-default key against free MIND allotment - #17

Merged
huhn511 merged 1 commit into
mainfrom
feat/free-llm-allotment
Jun 20, 2026
Merged

feat(coder): meter bridge-default key against free MIND allotment#17
huhn511 merged 1 commit into
mainfrom
feat/free-llm-allotment

Conversation

@huhn511

Copy link
Copy Markdown
Contributor

What

Meters the coder's bridge-default (env-fallback, shared OPENROUTER_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 — pure gateEnvFallback: ledger off → allow unmetered; balance spent → block; has/unknown balance → allow + meter (fail open on a ledger outage).
  • coder driver (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 — returns freeBalance so 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-node POST /.admin/tokens/debit (MIND-Studio/mind-node#9).

Tested

  • vitest run tests/ledger-gate.test.ts — 4/4 (gate decision matrix).
  • Live integration of the client against a running mind-node: balance → debit → drain → 402.
  • tsc --noEmit clean.

🤖 Generated with Claude Code

…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>
@huhn511
huhn511 merged commit 4617fb3 into mainJun 20, 2026
@huhn511
huhn511 deleted the feat/free-llm-allotment branch June 20, 2026 15:33
Sign up for freeto 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

@huhn511