Skip to content

feat(skills): mount /v1/skills — snapshots and evidence (#447) - #615

Merged
thinkclay merged 1 commit into
mainfrom
claude/feat-skill-analytics-api
Aug 12, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/feat-skill-analytics-api

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes 9 more gaps in #447 (KNOWN_GAPS 73 → 64). Third instance of the same pattern: tables built, UI built, no router.

Nothing was mounted at /v1/skills

core.skill_snapshots and core.skill_evidence have existed for some time. features/skills-analytics renders five widgets against them on the live /assessments route, and ReviewImpactSummary sits inside the profile ReviewsWidget. All nine calls 404'd, so every one of those widgets showed its error state.

GET /v1/skills/snapshots list, and latest (same path, differing by limit)
GET /v1/skills/snapshots/timeline chart points, oldest first
GET /v1/skills/snapshots/{id} one snapshot
POST /v1/skills/snapshots take a snapshot
POST /v1/skills/snapshots/compare diff two
GET /v1/skills/evidence list, filterable
POST /v1/skills/evidence add
PATCH /v1/skills/evidence/{id} edit title/description/url
POST /v1/skills/evidence/{id}/verify vouch for someone else's

Snapshots are built server-side from the caller's current ratings; the client sends only the trigger. Letting it post its own numbers would make the history a record of what a client believed rather than of what the data said.

Two decisions in lib/skill-snapshots.ts worth knowing: the overall average is the mean of every rating, not the mean of the category means — so a category with one rating does not weigh as much as one with ten. And a category present in only one of two compared snapshots still appears in the diff, because a skill area the worker started rating is a change worth showing.

Three things the live run caught

Evidence with no skill reference 500'd. core.skill_evidence has a check constraint requiring soft_skill_id, or skill_taxonomy and skill_ref_id. The schema allowed all three to be omitted, so the database rejected what the API had accepted. Now mirrored — 400 naming what is missing.

Verification could not work through the user client. skill_evidence_update is auth.uid() = user_id, and verification is by definition someone else vouching — that policy and this feature are in direct conflict. Relaxing the policy would be worse: RLS cannot restrict which columns a writer touches, so a broader policy would also let a stranger rewrite the title. That single write uses the service client, after the handler confirms the row exists and the caller is not its owner.

Self-verification is refused (403), and verified is not writable on PATCH — the strict schema rejects it with 400. A flag anyone can set on their own evidence means nothing.

Verification

Live, against a real stack:

snapshot 1  overall 3.67, summary null        (first — nothing to compare against)
            → nudge a rating →
snapshot 2  overall 5, summary {delta_overall: 1.33, previous_overall: 3.67}
compare     {deltaOverall: 1.33, improvedCount: 1, declinedCount: 0}

self-verify 403 · carlos verifies 200 (verified/verifiedBy/verifiedAt all set)
edit another user's evidence 404 · snapshot another user 403
PATCH {"verified":true} → 400

Test rows removed afterwards. 13 new assertions on the snapshot arithmetic; 69 Deno assertions pass. deno check on the new route: same four error codes as every other route — #477's untyped context, no new categories.

CI checks will show red without running — Actions billing block, #375.

🤖 Generated with Claude Code

core.skill_snapshots and core.skill_evidence have existed for some time, and
features/skills-analytics renders five widgets against them on the live
/assessments route, plus ReviewImpactSummary inside the profile ReviewsWidget.
No router was ever mounted at /v1/skills, so all nine calls 404'd and every one
of those widgets showed its error state.

  GET   /v1/skills/snapshots           list, and latest (same path, by limit)
  GET   /v1/skills/snapshots/timeline  chart points, oldest first
  GET   /v1/skills/snapshots/{id}      one snapshot
  POST  /v1/skills/snapshots           take a snapshot
  POST  /v1/skills/snapshots/compare   diff two of them
  GET   /v1/skills/evidence            list, filterable
  POST  /v1/skills/evidence            add
  PATCH /v1/skills/evidence/{id}       edit title/description/url
  POST  /v1/skills/evidence/{id}/verify  vouch for someone else's

Snapshots are built server-side from the caller's current ratings; the client
sends only the trigger. Letting it post its own numbers would make the history a
record of what a client believed rather than of what the data said.

The arithmetic lives in lib/skill-snapshots.ts, away from the handlers, because
it is the only part with logic worth testing directly. Two decisions in there
worth knowing: the overall average is the mean of every rating rather than the
mean of the category means, so a category with one rating does not weigh as much
as one with ten; and a category present in only one of two compared snapshots
still appears in the diff, because a skill area the worker started rating is a
change worth showing.

Three things the live run caught:

- **Evidence with no skill reference 500'd.** core.skill_evidence has a check
  constraint requiring soft_skill_id, or skill_taxonomy plus skill_ref_id. The
  request schema allowed all three to be omitted, so the database rejected what
  the API had accepted. The schema now mirrors the constraint and answers 400
  naming what is missing.

- **Verification could not work through the user client.** skill_evidence_update
  is `auth.uid() = user_id`, and verification is by definition someone else
  vouching, so that policy and this feature are in direct conflict. Relaxing the
  policy would be worse — RLS cannot restrict which columns a writer touches, so
  a broader policy would also let a stranger rewrite the title. That one write
  uses the service client, after the handler has checked the row exists and the
  caller is not its owner.

- **Self-verification is refused** (403), and `verified` is not a writable field
  on PATCH — the strict schema rejects it with a 400. A flag anyone can set on
  their own evidence means nothing.

Verified against a live stack: two snapshots taken either side of a rating
change produced delta_overall 1.33 against previous_overall 3.67, compare agreed
(improvedCount 1), and a first snapshot correctly carried a null summary rather
than claiming it had not changed. Cross-user checks: editing another user's
evidence 404s, snapshotting another user 403s.

KNOWN_GAPS 73 -> 64. 13 new assertions on the snapshot arithmetic; 69 Deno
assertions pass overall.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit cf2efe5 into main Aug 12, 2026
6 of 12 checks passed
@thinkclay
thinkclay deleted the claude/feat-skill-analytics-api branch August 12, 2026 12:06
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