oficina / base Public

Abilities plan: Astra round 6 is READY; apply its 2 P2s

Monthly-cap reservations carry their backend and month and are refunded
exactly; searches are paced after DNS on the actual host, then gated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 32a1cd40748adf5ac13b4e00f9289bd65ddde7c8 parent 995b12c
1 file changed, +11 −4
  • docs/superpowers/plans/2026-11-27-assistant-abilities.md +11 −4

CI passed — run details

CI log
=== build ===
CGO_ENABLED=0 go build ./...
=== vet ===
go vet ./...
=== fmt-check ===
=== staticcheck ===
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./...
=== govulncheck ===
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./...
No vulnerabilities found.
=== gitleaks ===
9:41AM INF Unknown SCM platform. Use --platform to include links in findings. host=amadan.net
9:41AM INF 1 commits scanned.
9:41AM INF scanned ~2585504 bytes (2.59 MB) in 220ms
9:41AM INF no leaks found
=== budget ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size
budget size: 22 directories within budget
=== script-test ===
scripts/prepare-apps_test.sh
ok   releases lookup failure stops before ship
ok   app owned elsewhere stops the script
ok   apps listing failure stops before create
ok   ambiguous release dir is refused
ok   explicit version resolves the ambiguity
ok   releases match is exact, not substring
ok   shipped version is only promoted, existing app not created
ok   fresh account creates, ships, promotes to edge, enables
ok   failing promote stops the script
ok   ship is retried while uploads are rate limited
all passed
hack/fonts_test.sh
fonts_test: ok
=== test ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -count=1 ./...

receipt: test step 6.668s against a 60s target (the gate's other steps are not in this figure)
receipt: 16 packages ran, 0 cached, 6 without tests, 0 failed
receipt: slow package 5.944s amadan.net/oficina/base/internal/webtest
receipt: slow package 729ms amadan.net/oficina/base/internal/issuer
receipt: slow package 577ms amadan.net/oficina/base/internal/operations
receipt: slow package 171ms amadan.net/oficina/base/internal/consumer
receipt: slow package 162ms amadan.net/oficina/base/internal/web
receipt: slow test 1.51s amadan.net/oficina/base/internal/webtest TestHomeDoesNotWaitOnAStalledSnapshot
receipt: slow test 1.07s amadan.net/oficina/base/internal/webtest TestAskZoneIsToldOnce
receipt: slow test 510ms amadan.net/oficina/base/internal/operations TestOperationsRefusals
receipt: slow test 510ms amadan.net/oficina/base/internal/issuer TestAuthorizeSignsForInstalledApp
receipt: slow test 220ms amadan.net/oficina/base/internal/webtest TestAskZoneAgainOnANewConnection
=== native ===
strings: copy review's strings.json is not here (git-ignored); its comparison skipped
strings: 119 in the catalog, 116 used
worktree-lib_test: ok
diff --git a/docs/superpowers/plans/2026-11-27-assistant-abilities.md b/docs/superpowers/plans/2026-11-27-assistant-abilities.md
index 7589099..d9cdb78 100644
--- a/docs/superpowers/plans/2026-11-27-assistant-abilities.md
+++ b/docs/superpowers/plans/2026-11-27-assistant-abilities.md
@@ -66,10 +66,10 @@ Neither the jobs plan nor the MCP plan has landed any code on either main.
- **AD3 One search interface; Mojeek first, Brave as fallback (Ruling Q1).** New Equipo package `internal/websearch`:
- `type Searcher interface { Name() string; Search(ctx context.Context, query string, n int) ([]Result, error) }` with `Result{Title, URL, Snippet, Date string}`, and failures as `*websearch.Error{Backend, Class string}`, where `Class` is one of `limit`, `auth`, `unavailable`, `bad_response`. An `Error` never carries a URL, a query or a key, because Go's `*url.Error` would print the Mojeek key, which travels in the query string.
- Backends: `mojeek` (`GET https://www.mojeek.com/search?api_key=…&q=…&fmt=json&t=8&date=1`. `response.status` is `"OK"`, or an error text such as `"ERROR: Daily Limit Reached"`, which counts as `limit`. Results come from `response.results[]` `{url, title, desc, date}`) and `brave` (`GET https://api.search.brave.com/res/v1/web/search?q=…&count=8` with `X-Subscription-Token`. Results come from `web.results[]` `{title, url, description, age}`. 429 counts as `limit`, 401 and 403 as `auth`). Both go through the guarded client (Task 3.1). The executor confirms the field names against each vendor's API docs before writing the fixtures.
- - `Chain{Primary, Fallback Searcher; Usage Usage}` tries the fallback, once per query, when the primary fails for any class, when its monthly cap is spent, or when it returns no results. A failed fallback means no more tries. `Chain.Search` takes a `Before` hook that runs immediately before **each** backend request, the fallback's included. `Before` is authorization only, meaning the bound send gate and the per-host pacer, and any refusal from it stops the whole chain, so a switch turned off while the primary answers means no request to the fallback. The cap belongs to `Chain` alone: after `Before` passes, `Chain` reserves one query on that backend with `Usage.Take`, which is atomic. A spent cap is not a refusal but a reason to try the fallback (its own `Before`, then its own `Take`). The **final** authorization is the bound gate installed with `guard.WithBeforeHop` on the context the lookup passes to `Chain.Search`. The search client's guard calls it after pacing, DNS and address checks, immediately before sending, for primary and fallback alike. If it refuses, nothing is sent, `Chain` returns the reservation with `Usage.Return`, and the chain stops. So each request actually sent holds exactly one reservation.
+ - `Chain{Primary, Fallback Searcher; Usage Usage}` tries the fallback, once per query, when the primary fails for any class, when its monthly cap is spent, or when it returns no results. A failed fallback means no more tries. `Chain.Search` takes a `Before` hook that runs immediately before **each** backend request, the fallback's included. `Before` is an early authorization check only, and any refusal from it stops the whole chain, so a switch turned off while the primary answers means no request to the fallback. The cap belongs to `Chain` alone: after `Before` passes, `Chain` reserves one query on that backend with `Usage.Take`, which is atomic. A spent cap is not a refusal but a reason to try the fallback (its own `Before`, then its own `Take`). Pacing and the **final** authorization are installed with `guard.WithBeforeHop` on the context the lookup passes to `Chain.Search`. The search client's guard calls it after pacing, DNS and address checks, immediately before sending, for primary and fallback alike. If it refuses, nothing is sent, `Chain` refunds that exact reservation with `Usage.Return(ctx, r)`, and the chain stops. So each request actually sent holds exactly one reservation.
- Search requests use their own guarded client: `Redirects: 0`, so a 3xx is `bad_response` and never followed, and the key is set only on a request to the backend's fixed origin (`https://www.mojeek.com`, `https://api.search.brave.com`). The page-reading client carries no key and allows no extra headers.
- Config, all operator-held: `EQUIPO_WEB_SEARCH` (`mojeek` or `brave`), `EQUIPO_WEB_SEARCH_FALLBACK` (`brave`, `mojeek` or empty), `EQUIPO_MOJEEK_KEY`, `EQUIPO_BRAVE_KEY`, `EQUIPO_MOJEEK_MONTHLY_CAP` and `EQUIPO_BRAVE_MONTHLY_CAP` (queries per UTC calendar month, an integer above 0). Keys are stored with `carlos secrets set` from 1Password (vault "Oficina") and never committed. Swapping the backend is a config change. A backend that is named but has no key or no cap is left out. The instance logs `web_search.misconfigured backend=<name>`, never the value. With no usable backend, `web_lookup` isn't listed.
- - The cap is counted on the instance in `chat_web_search_usage(backend, month, used)` (Task 3.3), incremented in the gate transaction before each request, so it holds even where a vendor has no cap of its own. Once both caps are spent the lookup fails `lookup_limit`. The operator also sets the vendor-side cap where the vendor offers one.
+ - The cap is counted on the instance in `chat_web_search_usage(backend, month, used)` (Task 3.3), reserved atomically by `Chain` before each request is sent and refunded if that request is refused (Task 3.3), so it holds even where a vendor has no cap of its own. Once both caps are spent the lookup fails `lookup_limit`. The operator also sets the vendor-side cap where the vendor offers one.
- No live API calls in CI. Tests use `websearchtest.Fake` and recorded fixtures served by TLS test servers through the guard's `TestDial`. In a test binary the guard refuses any real dial (Task 3.1, `TestGuardNeverDialsInTests`).
- **AD4 Try again before the jobs plan.** Spec §6.3's stop row needs a Try again tap. On main the only person-facing resume path is Carry on now (`Store.CarryOn`, Base `POST /ask/cards/{id}/carry_on`, label already approved). Today it is offered only on `paused` cards: Equipo's card view (`chat/jobs.go:395`, `c.CarryOn && c.State == wire.JobPaused`), Base's `Card.Clean`, `chat.html`, `ask.js` and the native `offersCarryOn` all check that. So:
- **Equipo (Task 2.10)** offers `carry_on` on a `stopped` card too, but only when the hand-off has `ability_held_at` and the person holds `build` again. `carry_on_connection` stays empty, so no "other plan" line is drawn. The detail then changes from `assistant.job.detail.ability_off` to `assistant.job.detail.ability_back`. `Store.CarryOn` on a held hand-off runs `resumeAbilityHold`.
@@ -625,7 +625,7 @@ Only if jobs plan phase 1 has merged by the time `abilities-2` is rebased for me
**Interfaces:**
- Produces:
- `func NewMojeek(key string, g guard.Config) (Searcher, error)` and `func NewBrave(key string, g guard.Config) (Searcher, error)`, each building its own guarded client from a copy of `g` with `Redirects: 0` and its `Credential` (Mojeek: param `api_key` on `https://www.mojeek.com`; Brave: header `X-Subscription-Token` on `https://api.search.brave.com`);
- - `type Usage interface { Take(ctx context.Context, backend string) (ok bool, err error); Return(ctx context.Context, backend string) error }`, backed by `chat_web_search_usage(backend text, month text, used integer, PRIMARY KEY(backend, month))` with `month` as `2006-01` UTC, where `Take` increments only while `used < cap`;
+ - `type Reservation struct { Backend, Month string }` and `type Usage interface { Take(ctx context.Context, backend string) (r Reservation, ok bool, err error); Return(ctx context.Context, r Reservation) error }`. `Return` refunds exactly that backend and month, once, backed by `chat_web_search_usage(backend text, month text, used integer, PRIMARY KEY(backend, month))` with `month` as `2006-01` UTC, where `Take` increments only while `used < cap`;
- `type Before func(ctx context.Context, backend string) error` and `func (c Chain) Search(ctx context.Context, q string, n int, before Before) (results []Result, backend string, err error)`, which calls `before` immediately before each backend request;
- `func FromConfig(cfg Config, g guard.Config, usage Usage) (Chain, bool, error)`, where `g` is the base guard configuration (inventory, deny list, resolver) shared with the page client, `false` means no usable backend, and an error means a constructor refused its configuration (a code bug, so boot fails);
- `websearchtest.Fake{Results map[string][]Result; Fail map[string]*Error; Calls []string}`.
@@ -639,6 +639,7 @@ Only if jobs plan phase 1 has merged by the time `abilities-2` is rebased for me
- `TestChainNoFallbackConfigured`.
- `TestChainBothCapsSpentIsLimit`.
- `TestMonthlyCapResetsByUTCMonth`.
+ - `TestReturnRefundsItsOwnMonth`: a reservation taken at 23:59:59 UTC on the month's last day and refused after midnight refunds the old month, with concurrent reservations in both months counted correctly.
- `TestBackendSwapByConfig`: `EQUIPO_WEB_SEARCH=brave` with no fallback uses Brave only.
- `TestMisconfiguredBackendLeftOut`: no key or no cap. The log line names the backend and not the value.
- `TestSearchErrorsNeverCarryKey` (Review Focus 1).
@@ -749,7 +750,7 @@ CREATE INDEX chat_lookup_person ON chat_lookups(person, created_at);
- Consumes: `assist.Gate` (Task 2.7), `guard.Client` (3.1), `websource.Readable` (3.2), `websearch.Chain` (3.3), `lookupPack` and `lookupStep` (3.6), and `callFrom(ctx)` for the call row.
- Produces:
- Provider `web`, with one operation: `web_lookup`, `ReadOnly: true`, input schema `{"type":"object","additionalProperties":false}`, and description exactly as in spec §4.1.
- - `func (s *Store) webLookup(ctx context.Context, call toolCallRecord) (json.RawMessage, error)` runs spec §4.2 steps 1 to 8. It reads `websource.Mentions` first, at most 3, from the composer message (step 2). It refuses a query that `websource.LooksSecret` flags. It passes `Chain.Search` a context carrying `guard.WithBeforeHop` (the bound `assist.Gate`, the final check before each search request is sent) and a `Before` that waits on the pacer and then runs an early `assist.Gate` to stop the chain (never `Usage`, which the chain owns), and reads each page with `guard.WithBeforeHop` set to the pacer for that host, then `assist.Gate`, so every hop of a redirect chain is paced and gated, not just the first. It builds the per-lookup deny list with `func (s *Store) lookupDeny(ctx context.Context, person string) ([]string, error)`: the instance origin, every `EQUIPO_ASSISTANT_HOSTS` origin, oficina-connect's origin and the forge host from config, plus the origins of the person's Oficina apps from `base_apps`. The app origins come from `func (s *Store) baseAppOrigins(ctx context.Context, person string) ([]string, error)`, an instance-owned call to `Registry.Invoke` for `base_apps` on a context carrying its **own** gate, `assist.WithGate(ctx, s.sendGate(person, baseAppsOp))`, bound to that operation. The lookup's web gate is kept for searches and reads only. The list is cached per person in memory, refreshed when older than 60 s and kept for at most 10 minutes. With no list available, the lookup fails `lookup_failed`. The list is passed through `guard.WithDeny`. It enforces 1 request per second per host through `type hostPacer struct` on the Store (keyed by host, in memory) and the 40 s limit through the context. It returns only the fixed `shown` result, or a failure code, as model-facing text.
+ - `func (s *Store) webLookup(ctx context.Context, call toolCallRecord) (json.RawMessage, error)` runs spec §4.2 steps 1 to 8. It reads `websource.Mentions` first, at most 3, from the composer message (step 2). It refuses a query that `websource.LooksSecret` flags. It passes `Chain.Search` a context carrying `guard.WithBeforeHop` (the pacer for the actual destination host, then the bound `assist.Gate`: the final check, right before each search request is sent, after DNS) and a `Before` that runs only an early `assist.Gate` to stop the chain (never `Usage`, which the chain owns), and reads each page with `guard.WithBeforeHop` set to the pacer for that host, then `assist.Gate`, so every hop of a redirect chain is paced and gated, not just the first. It builds the per-lookup deny list with `func (s *Store) lookupDeny(ctx context.Context, person string) ([]string, error)`: the instance origin, every `EQUIPO_ASSISTANT_HOSTS` origin, oficina-connect's origin and the forge host from config, plus the origins of the person's Oficina apps from `base_apps`. The app origins come from `func (s *Store) baseAppOrigins(ctx context.Context, person string) ([]string, error)`, an instance-owned call to `Registry.Invoke` for `base_apps` on a context carrying its **own** gate, `assist.WithGate(ctx, s.sendGate(person, baseAppsOp))`, bound to that operation. The lookup's web gate is kept for searches and reads only. The list is cached per person in memory, refreshed when older than 60 s and kept for at most 10 minutes. With no list available, the lookup fails `lookup_failed`. The list is passed through `guard.WithDeny`. It enforces 1 request per second per host through `type hostPacer struct` on the Store (keyed by host, in memory) and the 40 s limit through the context. It returns only the fixed `shown` result, or a failure code, as model-facing text.
- Listed only when all of these hold:
- the turn's kind is `person`;
- the primary speaks protocol 34 or later;
@@ -772,6 +773,7 @@ CREATE INDEX chat_lookup_person ON chat_lookups(person, created_at);
- `TestAnswerStepBudget`.
- `TestRevokedMidLookupStopsNextRequest` (Review Focus 5).
- `TestOficinaAppOriginRefused`: a publicly addressed app origin from `base_apps` is refused when typed and when reached by a redirect. `TestDenyUnavailableFailsClosed`. `TestLookupDenyReadsBaseAppsThroughOwnGate`: with the real registry and Base HTTP provider and an empty cache, the lookup reads `base_apps` and proceeds, with no `operation_changed` or `ability_unmapped`.
+ - `TestSearchPacedAfterDNS`: two concurrent lookups whose DNS answers complete together send to the same backend at least 1 second apart, primary and fallback traffic included.
- `TestRevokedWhileSearchWaits`: `web` goes off while a search waits on the pacer, and again while it waits on the resolver. Neither the primary nor the fallback receives a request.
- `TestRevokedDuringRedirectStops`: `web` goes off while the first response (a 302) arrives, and the redirect's target receives nothing.
- `TestSameHostRedirectPaced`: a same-host redirect waits for the 1-second pace.
@@ -1039,3 +1041,8 @@ These go through Task 0.1 with the spec's register. All are DRAFT.
- **P1, a search could pass authorization and then wait.** The bound gate also runs through the search client's `WithBeforeHop`, right before sending, with the reservation returned on a refusal (AD3, Tasks 3.3 and 3.7).
- **P2, the Settings line's source.** It reads `OwnAbilities` with the member's own bearer, and shows nothing when Equipo is unavailable (Task 4.6).
+
+**Round 6** (Astra, 2026-11-27): **READY**, with no P1 and 2 P2. The P2s were applied once, as the review rule asks, and the loop stopped there.
+
+- **P2, a refund without its month.** `Take` returns a `Reservation` with backend and month, and `Return` refunds exactly that one (Task 3.3).
+- **P2, search pacing before DNS.** Searches are paced in `WithBeforeHop` on the actual host, after DNS, then gated, as page reads are (AD3, Task 3.7).