Skip to content

Keyless demo mode, a measured rule-based scorer, seeded demo data, demo-team switch, compose smoke test - #23

Merged
Bogzx merged 9 commits into
mainfrom
improve/2026-10-01-keyless-demo
Oct 1, 2026
Merged

Bogzx merged 9 commits into
mainfrom
improve/2026-10-01-keyless-demo

Conversation

@Bogzx

@Bogzx Bogzx commented Oct 1, 2026

Copy link
Copy Markdown
Owner

Stacked on #22. This branch contains #22's four commits; please merge #22 first. Once it is merged, this PR's diff shrinks to the five commits below.

Why

  • Nothing could be tried without a Gemini key. The API refused to boot without one, so a stranger, or a recruiter following the README, could not see the coach work at all.
  • The scorer at the centre of the product had never been measured. The eval harness exists but needs a key, so it never ran: no baseline, no CI signal, and "the rubric is concrete enough that a human could apply it" was an assertion.
  • A fresh stack showed an empty dashboard. The seed had no prompt activity, and compose never ran it.
  • The public demo team could not be turned off. Its secret is in the repo, so on a networked server anyone could write to it and spend the operator's Gemini quota through it.
  • CI built the image but never ran docker compose up.

What changed

  1. Rule-based baseline scorer + eval (e3c7e2c).

    • packages/scoring/src/heuristic-score.mjs scores the five rubric dimensions with transparent rules over surface features: file paths, identifiers, numbers with units, constraint and output phrasing, and text aimed at the scorer. It is deterministic, has no imports and no Node APIs (so a browser can run it), and is a floor for the model, not a substitute.
    • The eval gains an ordering metric (for prompt pairs whose expected bands don't overlap, is the better one scored higher?), --scorer heuristic, and eval/holdout.json: 16 prompts with bands, written before the rules were frozen and never tuned on.
    • baseline.test.ts runs the scorer over both sets in npm test.
    Set Overall in band Dims in band Pairs ordered
    golden (seen while writing the rules) 29/30 47/49 152/152
    holdout (unseen) 14/16 18/22 38/38

    Known misses are listed in apps/api/eval/README.md. The Gemini scorer has still not been run on either set; that needs a key.

  2. Keyless demo mode (1ea5bd1). With TRAILHEAD_LLM=offline, routes call llm.ts, which picks per call between gemini.ts and offline-llm.ts:

    • scoring uses the rule-based scorer;
    • topics come from keyword rules;
    • the LLM-written rewrites, tips and summaries are empty, so the existing static templates take over;
    • /diff and /improve use templates;
    • rich bootstrap returns 503.

    It says so everywhere: GET / reports llm, /score and /coach return scorer: "heuristic", coaching text ends with a note, the extension score card shows "Rule-based score", and the API warns at startup.

    It never switches on by itself. Without a key and without TRAILHEAD_LLM, the API still refuses to start, and the error message names both fixes. gemini.ts now creates its client lazily, and compose no longer requires the key up front.

  3. Demo-team switch (1e44561). TRAILHEAD_DEMO_TEAM=on|off: default on, but off once TRAILHEAD_ADMIN_TOKEN is set. When off, the demo secret gets 401 demo_team_disabled. GET / reports the setting.

  4. Seeded demo data (8297fec).

    • The seed adds 48 synthetic prompts each for three made-up users over the last 6 days (720 observations, fixed-seed PRNG) and 18 captures. It stays idempotent, and re-running it moves the window to now.
    • Compose gains a one-shot seed service under --profile demo.
    • The dashboard's demo card now says the data is synthetic; it used to call the fictional team's wiki "the team's actual repo conventions".
  5. CI compose smoke test (7abf3f2). The docker job runs TRAILHEAD_LLM=offline docker compose up --wait and the seed, then checks with jq: health, a team registration, a wiki write, a rule-based score, and the seeded metrics. It always tears down.

Verification

Check Result
npm run typecheck / npm run lint / npm audit --audit-level=high exit 0 / 0 / 0
npm test all pass. API 86 (+14: llm-mode, offline-llm, ordering, --scorer heuristic, baseline ×3); scoring 43 (+8 heuristic rule tests); score-card 6 (+1)
Integration suite, Postgres 16 40/40. New: offline mode scores, coaches, promotes, diffs and improves with zero request-path Gemini calls, and rich bootstrap returns 503. Also new: demo-team switch default / admin-token / explicit.
Mutation check Pointing routes/score.ts back at gemini.ts makes the offline integration test fail.
TRAILHEAD_LLM=offline docker compose -p … --profile demo up --build, fresh volume GET / → llm: offline; seed exits 0. /team/metrics: 720 observations, 3 users, avg 5.2. /score "fix it" → 0; a fully specified prompt → 8. /coach uses the library example and ends with the offline note.
Dashboard (next dev) against that stack, headless Chromium /skill-arc renders 24 hour-buckets; /team cards are non-zero
CI smoke script The same commands, run locally against that stack: all four jq checks true

Needs a human

  • Run the Gemini eval once with a key (apps/api/eval/README.md), for example GEMINI_API_KEY=… npm --workspace=apps/api run eval -- --yes --runs 5 (150 calls). Then compare it with the baseline rows above.
  • In offline mode the library's "independent re-score" is the same deterministic rules, so it confirms nothing. This is documented in SELFHOSTING, along with TRAILHEAD_PROMOTION_MODE=review for teams that will rely on the library.

🤖 Generated with Claude Code

Bogdan Truta and others added 9 commits October 1, 2026 12:26
app.ts held every route, its helpers and the middleware in one 87 KB file.
It is now the app shell (CORS, body caps, tracing, auth, LLM rate limits,
GET /, route mounting, error handler: 243 lines), with:

- http.ts: what the middleware and the routes share (env type, tenant
  policy, rate limiting, the prompt cap, skill-observation writes)
- routes/{score,coach,assist,wiki,prompts,metrics,teams,onboard}.ts: one
  Hono sub-app per area, mounted after the middleware so every route still
  gets auth, body caps, tracing and rate limits

Code moved verbatim (apart from `app.<verb>` → `<router>.<verb>` and
`export` on the shared helpers), so behaviour is unchanged: the 38
Postgres integration tests, which drive every route and cross-check the
GET / catalog, pass unchanged. apps/api/README.md documents the layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wiki-bootstrap-job.ts built its own GoogleGenAI client, so the rich
bootstrap (the biggest fan-out of LLM calls in the API) bypassed the retry
policy and never appeared in Langfuse traces. It now calls
gemini.generateText, which goes through the same tracedGenerate/withRetry
path as the request handlers: 429/5xx are retried with backoff, timeouts
are still never retried (90 s per call, as before). generateText does not
apply the 4 000-char cap meant for short structured answers, because folder
narratives are several thousand words; a new test pins both properties.

Removed as dead code: extractLearning (gemini.ts), EXTRACT_MODEL
(gemma-4-31b-it) and the extract-prompt module in packages/scoring with its
tests. They served the Stop hook that was removed in PR #5; nothing has
imported them since. The README's "Gemma for async learning extraction"
claim goes with them; every call uses gemini-3-flash-preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ecutable

Next 16.3 generates AGENTS.md and CLAUDE.md in apps/dashboard on every
`next dev` unless `agentRules: false` is set; they showed up as untracked
files for anyone running the dashboard. apps/mcp-server/bin/cli.mjs has a
shebang and is the package's `bin`, but was committed as 100644 (npm fixed
the mode on install, leaving a dirty tree).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…utes/

The README said gemma-4-31b-it handled "async learning extraction" and
"diff narration, rich bootstrap". Learning extraction was never wired up
(removed in the previous commits) and /diff and the bootstrap use
gemini-3-flash-preview. Also points the route table at the new layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…l that runs in CI

The scorer at the centre of the product (one Gemini call) had never been
measured: the eval harness existed but needs a key, so nothing ran. This
adds the part that can run anywhere.

packages/scoring/src/heuristic-score.mjs scores a prompt on the five rubric
dimensions with transparent rules over surface features (file paths,
identifiers, numbers with units, constraint and output phrasing, meta
instructions aimed at the scorer). It is deterministic, has no imports and
no Node APIs, so the API's offline mode and the landing page can both use
it. It is a floor for the model, not a substitute.

The eval gains:
- an ordering metric: for every pair of prompts whose expected bands don't
  overlap, does the scorer rank the better one higher (ties count as wrong);
- `--scorer heuristic` (free, no key, no --yes);
- eval/holdout.json: 16 prompts with bands, written before the rule set was
  frozen and never used to tune it (golden.json was visible while writing);
- baseline.test.ts: runs the rule-based scorer over both sets in `npm test`
  and fails if it drops below what it measured when frozen.

Measured (heuristic-v1):
  golden  (seen):   29/30 overall in band, 47/49 dims, 152/152 pairs ordered
  holdout (unseen): 14/16 overall in band, 18/22 dims,   38/38 pairs ordered
The known misses are listed in eval/README.md. The Gemini scorer still has
not been run on either set; that needs a key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nothing ran without a Gemini key: the API refused to boot, so a stranger
could not see the coach work, and nobody could try the stack before getting
a key.

TRAILHEAD_LLM=offline runs the same API with no model:
- llm.ts: every LLM call the routes make goes through it and picks its
  provider per call (llm-mode.ts): gemini.ts by default, offline-llm.ts in
  offline mode. gemini.ts now creates its client on first use, so importing
  it needs no key.
- offline-llm.ts: the rule-based scorer from packages/scoring for /score and
  /coach; keyword rules for topics; '' for the LLM-written rewrites, tips,
  acknowledgements and summaries (the /coach renderers already fall back to
  their static templates); a template /diff narrative naming the biggest
  gap; an /improve that asks the static question per weak dimension and
  appends the answers. POST /onboard/repo/full answers 503 llm_unavailable.
- It says so everywhere: GET / reports "llm", /score and /coach return
  "scorer": "heuristic", coaching text ends with a note, the score card in
  the extensions shows "Rule-based score", and the API warns at startup.
- It never switches on by itself: with no key and no TRAILHEAD_LLM the API
  still refuses to start (now naming both ways to fix it), so a deploy that
  lost its key fails loudly instead of quietly scoring with rules.

docker-compose.yml no longer requires the key up front, so
`TRAILHEAD_LLM=offline docker compose up` works with no .env at all.
SELFHOSTING.md documents what offline mode does and does not do, including
that the confirming re-score for library promotion is the same rules.

Tests: llm-mode and offline-llm unit tests (with fetch stubbed to fail), and
an integration test against real Postgres that scores, coaches, promotes,
diffs and improves in offline mode and asserts no request-path Gemini call
was made (verified: pointing /score back at gemini.ts makes it fail).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…DEMO_TEAM)

The seeded demo team's secret (trailhead_demo_acme_2026) is in this repo, and
schema.sql always creates the team. On a server reachable from a network,
anyone could write to its wiki and spend the operator's Gemini quota through
it; the only bound was the per-team and per-IP rate limits, and there was no
way to turn it off.

TRAILHEAD_DEMO_TEAM=on|off controls it. The default stays on for a local
setup, but setting TRAILHEAD_ADMIN_TOKEN (the sign of a networked deploy)
turns it off unless TRAILHEAD_DEMO_TEAM=on says otherwise. Off, the demo
secret gets 401 with reason demo_team_disabled and a message saying what to
do; the team row stays, so turning it back on just works. GET / reports
`demo_team`.

Integration test: default on; off once an admin token is set (other teams
unaffected); an explicit value wins in both directions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…demo up`

The seed wrote a wiki and four library prompts but no prompt activity
("Full §11 seed ... deferred"), and compose never ran it, so a fresh stack
showed an empty skill-arc chart and zeros on the team page.

packages/db/seed.mjs now also writes, for three made-up users, 48 scored
prompts each spread over the last six days with scores that drift upwards
(720 skill_observations, deterministic: fixed-seed PRNG), plus 18 captures
with outcomes. It stays idempotent: the synthetic rows are replaced on every
run, which also moves the window up to "now" (the dashboard shows the last
24 h and the team page the last 7 days). The header says plainly that all of
it is synthetic, and the dashboard's demo-team card no longer calls the
fictional Acme Fintech "the team's actual repo conventions".

docker-compose.yml gains a one-shot `seed` service under the `demo`
profile, started after the API is healthy:
  TRAILHEAD_LLM=offline docker compose --profile demo up --build

Verified with that command on a fresh volume: seed exits 0, /team/metrics
reports 720 observations, 3 active users, avg 5.2; the dashboard's
/skill-arc renders 24 hour-buckets and /team shows non-zero cards (headless
Chromium). Running the seed twice leaves the same counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CI built the API image but never ran the stack, so "docker compose up"
could break (schema mount, healthcheck, env wiring) without a red build.
The docker job now brings the stack up the way a stranger would, with no
key (TRAILHEAD_LLM=offline), runs the demo seed, and checks: GET / is ok
and offline, a team registers, a wiki write lands, /score answers with the
rule-based scorer, and the seeded demo team has its activity. Logs are
printed on failure and the stack is always torn down (down -v).

The same commands were run locally against a compose stack before
committing (all four jq checks true).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
learnloop Ready Ready Preview Oct 1, 2026 1:03pm UTC
polihackwinners-dashboard Ready Ready Preview Oct 1, 2026 1:03pm UTC

This branch was successfully deployed

2 active deployments
Preview – polihackwinners-dashboard — 7abf3f20 Deployed Oct 1, 2026 by vercel[bot]
Preview – learnloop — 7abf3f20 Deployed Oct 1, 2026 by vercel[bot]
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