@ai-coach/adapter-gemini
The online judge. After you've sparred offline, coach judge sends your answers to Google's Gemini for a stricter, independent Tier 2 check. The judge never sees your notes: it gets only the questions you were asked, your answers and, unless you turn it off, the idea's core assertions. You change this package when the judge's prompt, reply format or model handling changes.
What it does not do
- No deciding what leaves your machine. The payload is built and re-checked by
tier2Payloadin@ai-coach/domainandJudgingin@ai-coach/application; this adapter sends exactly what it is given. - No final verdict rule. The rule that a pass stands only if no claim is flawed and no gap remains is applied in the domain, on top of whatever the model said.
- No queue. Waiting sessions are kept by
adapter-local-state. - Only
@google/genai,zodand Node built-ins. Nx boundaries (adapter:gemini) forbid anything else.
Architecture fit
- Scope:
scope:coach - Style:
architecture:hexagonal(type:adapter,adapter:gemini) - Depends on:
@ai-coach/application(theJudgeport),@ai-coach/domain - Used by:
@ai-coach/cli, in its composition root
[Judging] ──Tier2Payload──▶ GeminiJudge ──prompt (protocol.ts)──▶ Gemini API
◀──JudgeReport── reply checked against JudgeReply (zod)
Internal architecture & rules
gemini-judge.tsholdsGeminiJudge: one request per session, all answers judged together and returned in the same order. A malformed reply is retried once; a rate limit or 5xx error triesfallbackModelonce.protocol.tsholds the system instruction, the user prompt and theJudgeReplyschema. For each answer the judge lists claims (mechanism, assertion or definition), checks each for fallacies from a fixed list of 12 and for hand-waving, lists the gaps, and gives a verdict with a one-sentence reason.- Answers are data, not instructions. They're wrapped in tags with a random marker, so an answer can't tell the judge what to decide.
- Nothing is lost if it fails. Sessions stay queued until they're judged and recorded.
- No comments in source code (DEC-AIC-0011).
Public surface
GeminiJudge— theJudgeport, built withGeminiJudgeOptions(model,fallbackModel,thinkingLevel, and an injectable client for tests).DEFAULT_JUDGE_MODEL— the model used when none is configured.JudgeReply,replyJsonSchema,systemInstruction,userPrompt— the wire protocol, exported for tests and tuning.
Your API key goes in a git-ignored .env as GEMINI_API_KEY; the judge settings (model, fallbackModel, thinkingLevel, includeAssertions) are in the configuration guide, and what leaves your machine is in the privacy guide.
How to extend it
- If the report needs new fields, change
JudgeReportin@ai-coach/applicationfirst. - Update the prompt and the
JudgeReplyschema insrc/lib/protocol.ts. - Map the reply in
GeminiJudgeand cover it insrc/lib/gemini-judge.spec.tswith the fake client. - Run
npm exec nx test @ai-coach/adapter-geminiandnpm exec nx lint @ai-coach/adapter-gemini.
Running & testing
npm exec nx test @ai-coach/adapter-gemini
npm exec nx lint @ai-coach/adapter-gemini
npm exec nx typecheck @ai-coach/adapter-gemini
npm exec nx build @ai-coach/adapter-gemini
The specs use a fake client, so they never call Gemini or need a key.
Key ADRs
- DEC-AIC-0002 — Tier 2 is a zero-knowledge online judge.
- DEC-AIC-0006 — blind claim extraction and the verdict rule.
- DEC-AIC-0025 — each answer is judged by the style it was sparred in, with core assertions on request.
- DEC-AIC-0015 — the API key comes from a git-ignored
.env.