Skip to main content

@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 tier2Payload in @ai-coach/domain and Judging in @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, zod and 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 (the Judge port), @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.ts holds GeminiJudge: 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 tries fallbackModel once.
  • protocol.ts holds the system instruction, the user prompt and the JudgeReply schema. 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 — the Judge port, built with GeminiJudgeOptions (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​

  1. If the report needs new fields, change JudgeReport in @ai-coach/application first.
  2. Update the prompt and the JudgeReply schema in src/lib/protocol.ts.
  3. Map the reply in GeminiJudge and cover it in src/lib/gemini-judge.spec.ts with the fake client.
  4. Run npm exec nx test @ai-coach/adapter-gemini and npm 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.