Phase 8: Hub API (/capabilities, read-only /ask, /notify)

The project side of the frozen Hub contract
(central_ai_llm_master/docs/ask-contract.md), on this service's own port:

  GET  /capabilities  the routing topics the Hub reads, project "compass_nhs"
  POST /ask           one short, read-only answer about a child's school work
  POST /notify        accept the contract's notification shape, deliver via Apprise

All three require the shared bearer token SCHOOL_HUB_TOKEN; with no token they
answer 503. GET /health now also carries "ok": true and "hub_api".

/ask answers deterministically (no model on the path) from the stored Compass
items, reusing dashboard.Classify so the answer and the dashboard never
disagree. It is one short sentence, for example "Harry has 8 school events
today from 8:55am to 6:00pm and 6 overdue tasks", with the buckets in `data`.
It reads only, enforced by a Reader interface with no write method and by
TestHubAskReadsOnly.

Fail loudly (FR-12): a missing or failed scan is never an empty day. /ask says
due work is unknown, and an answer older than 36 hours carries a stale warning.
Permission follows the contract: a parent may ask about any child; anyone else
only about themselves.

/notify follows the house interpretation already used by internet_use_control:
the contract shape is accepted and delivered to the named person, recorded in
notifications with scope "hub". An unknown person is refused, not misdelivered.

Live proof on .13 (deploy/verify-phase8.sh):
  /health        200, ok true
  /capabilities  200, project compass_nhs; unsigned 401
  /ask           200, the sentence above, duration 1ms
  /notify        400 on a bad level (auth proven, nothing sent), then 200 with
                 a real delivery to Sam on email and WhatsApp

The live Hub registration (HUB_PROJECTS + HUB_PROJECT_COMPASS_NHS_TOKEN +
hub restart) is a change to a running family service and is pending approval.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-10-15 19:47:32 +11:00
parent 09639c5125
commit 9cbfa7db9b
13 changed files with 1720 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
IMAGE ?= compass-teams-nhs/school:0.5.0-phase7
BUILD_VERSION ?= 0.5.0-phase7
IMAGE ?= compass-teams-nhs/school:0.6.0-phase8
BUILD_VERSION ?= 0.6.0-phase8
# Parse options (see scripts/parse-compass.sh).
CHILD ?= Harry
@@ -19,7 +19,7 @@ GO_RUN = timeout 600 docker run --rm --network host --user "$$(id -u):$$(id -g)"
-e HOME=/src/.gocache -e GOMODCACHE=/src/.gocache/mod -e GOCACHE=/src/.gocache/build \
-v "$$PWD":/src -w /src $(GO_IMAGE)
.PHONY: help test vet build up down restart logs ps deps fmt hash-password gen-secret verify-phase1 parse scan calendar notify morning-brief
.PHONY: help test vet build up down restart logs ps deps fmt hash-password gen-secret verify-phase1 verify-phase8 parse scan calendar notify morning-brief
help:
@echo "make test run go test ./... in golang:1.25-alpine"
@@ -39,6 +39,7 @@ help:
@echo "make preview print the briefs without sending (Phase 7)"
@echo "make morning-brief scan both children, then send the briefs (the n8n job)"
@echo "make verify-phase1 prove /health, the login and the Caddy route"
@echo "make verify-phase8 prove the Hub API: /capabilities, /ask, /notify (--send delivers)"
test:
$(GO_RUN) go test ./...
@@ -105,3 +106,8 @@ morning-brief:
# Caddy route on .35.
verify-phase1:
deploy/verify-phase1.sh
# Phase 8 definition of done: the Hub API answers and authenticates. Pass
# ARGS=--send to deliver one real /notify message to Sam.
verify-phase8:
deploy/verify-phase8.sh $(ARGS)