oficina / base Public

Abilities plan: Astra round 4 fixes (1 P1, 3 P2)

Every redirect hop is paced and gated (guard.WithBeforeHop); an
exported chat.Store.Allowed for package equipo and the Oficina
provider; guard.New and the search constructors return errors;
Mojeek's written zero-retention confirmation gates lookups going on.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 0b75ee6dfa16234286f7548695a79b46d5fd0661 parent da56b10
1 file changed, +20 −9
  • docs/superpowers/plans/2026-11-27-assistant-abilities.md +20 −9

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:35AM INF Unknown SCM platform. Use --platform to include links in findings. host=amadan.net
9:35AM INF 1 commits scanned.
9:35AM INF scanned ~2582528 bytes (2.58 MB) in 281ms
9:35AM 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 7.171s 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 6.295s amadan.net/oficina/base/internal/webtest
receipt: slow package 1.132s amadan.net/oficina/base/internal/issuer
receipt: slow package 598ms amadan.net/oficina/base/internal/operations
receipt: slow package 197ms amadan.net/oficina/base/internal/consumer
receipt: slow package 165ms amadan.net/oficina/base/internal/web
receipt: slow test 1.51s amadan.net/oficina/base/internal/webtest TestHomeDoesNotWaitOnAStalledSnapshot
receipt: slow test 1.08s amadan.net/oficina/base/internal/webtest TestAskZoneIsToldOnce
receipt: slow test 860ms amadan.net/oficina/base/internal/issuer TestAuthorizeSignsForInstalledApp
receipt: slow test 520ms amadan.net/oficina/base/internal/operations TestOperationsRefusals
receipt: slow test 240ms amadan.net/oficina/base/internal/issuer TestAuthorizeRefusals
=== 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 4597983..9223781 100644
--- a/docs/superpowers/plans/2026-11-27-assistant-abilities.md
+++ b/docs/superpowers/plans/2026-11-27-assistant-abilities.md
@@ -149,7 +149,7 @@ Nothing here goes in a repository. The values are never printed.
- [ ] **Step 1:** Put the Mojeek API key in 1Password, vault "Oficina", item "Mojeek Search API". Ask Mojeek in writing for zero retention of queries on this key, and keep the reply with the item.
- [ ] **Step 2:** Create the Brave Search API key, set a monthly limit in Brave's dashboard, and store it in the same vault as "Brave Search API".
- [ ] **Step 3:** Choose the monthly caps (queries) for each backend, for staging and for production, and record them in the items' notes.
-- [ ] **Step 4:** Done when both items exist and the caps are recorded. The keys are installed on the instance in Task 3.11.
+- [ ] **Step 4:** Done when both items exist, the caps are recorded, and Mojeek's **written confirmation of zero retention for this key** is saved with the item. Mojeek's standard API retention is 90 days, with zero retention on request. The keys are installed on the instance in Task 3.11.
## Phase 1. Base draws lookup answers (Base)
@@ -426,7 +426,7 @@ ALTER TABLE chat_assistant_hosts ADD COLUMN capabilities text; -- omitted if j
- `type GateFunc func(op Operation) error`, `func WithGate(ctx context.Context, f GateFunc) context.Context` and `func Gate(ctx context.Context, op Operation) error`. With no gate on the context, `Gate` refuses `ability_unmapped`, so a missing gate fails closed.
- Every provider calls `Gate` immediately before the request that performs the operation: in `http.go` before the operation's `POST`, in `oficina.go` after `teams` and before the `POST`, and (Task 3.7) before each search and read.
- The bound gate is `func (s *Store) sendGate(person string, bound assist.Operation) assist.GateFunc`: one short transaction reads `switches`, and the gate refuses `operation_changed` when `op` differs from `bound` in provider, name, `ReadOnly` or `Scope`.
- - `func (s *Store) clientAllowed(ctx, person, key string) error` is called by the Oficina connection read and token refresh before any authenticated request. Revocation and Disconnect are exempt.
+ - `func (s *Store) Allowed(ctx context.Context, person, ability string) error`, exported from package `chat`. It runs `refreshIfStale` outside any transaction, then reads `switches` in a short transaction, and returns `assist.Failure{Code: wire.CodeAbilityOff}` or `unavailable`. Package `equipo` reaches it through `s.Chat().Allowed(...)` (`internal/equipo/chat_wiring.go:27`). The Oficina connection read and token refresh call it under `apps_read` before any authenticated request, through a callback the Oficina provider is given at construction (`assist.NewOficinaProvider(..., allowed func(ctx, person string) error)`). Revocation and Disconnect are exempt.
- [ ] **Step 1: Failing tests:**
- `TestSendGate`: the switch goes off at each of §10.1's four points and nothing is sent; switched off after the gate passed, that request completes and the next is refused.
@@ -443,7 +443,7 @@ ALTER TABLE chat_assistant_hosts ADD COLUMN capabilities text; -- omitted if j
**Files:** `internal/equipo/chat_wiring.go` (`OnUnconnected`), `internal/equipo/oficina_connect.go` (the person API's `/oficina/connect` and `/oficina/connect/finish`, and the browser paths `oficinaStart` at `:177` and `oficinaDone` at `:306`), `internal/equipo/copy.go` (`oficina.connect.ability_off`, pending until Task 0.1), `internal/equipo/oficina_connect_abilities_test.go` (new).
-**Interfaces:** Produces `func (s *Store) startOficina(ctx context.Context, person, returnTo string) (string, error)` and `func (s *Store) finishOficina(ctx context.Context, person, state, code string) error`. Each runs `refreshIfStale` and then checks `apps_read` in a transaction before calling `s.oficina.Start` or `s.oficina.Finish`, refusing `ability_off` without it. All four paths call these two, and nothing else calls `s.oficina.Start` or `Finish`. The browser paths show `oficina.connect.ability_off` on a refusal. Disconnect isn't gated.
+**Interfaces:** Produces `func (s *Store) startOficina(ctx context.Context, person, returnTo string) (string, error)` and `func (s *Store) finishOficina(ctx context.Context, person, state, code string) error`. Both live in package `equipo` and call `s.Chat().Allowed(ctx, person, wire.AbilityAppsRead)` (Task 2.7) before calling `s.oficina.Start` or `s.oficina.Finish`, refusing `ability_off` without it. All four paths call these two, and nothing else calls `s.oficina.Start` or `Finish`. The browser paths show `oficina.connect.ability_off` on a refusal. Disconnect isn't gated.
- [ ] **Step 1: Failing tests:**
- `TestOficinaConnectNeedsAppsRead`: no card is raised, and `POST /oficina/connect` and `/finish` answer 403 `ability_off`.
@@ -559,7 +559,7 @@ Only if jobs plan phase 1 has merged by the time `abilities-2` is rebased for me
- Modify: `internal/websource/websource.go` (export `CheckHost`)
**Interfaces:**
-- Produces: MCP plan Task 6's `Inventory`, `Config`, `Response`, `Refusal`, `New` and `Do`, at the new path. The network checks (scheme, port, host rules, deny list, addresses, inventory, the checked dial, TLS, proxy off, no cookies, size and time limits) are common to every caller. What a request may carry is a named policy, `Config.Policy`:
+- Produces: MCP plan Task 6's `Inventory`, `Config`, `Response`, `Refusal` and `Do`, at the new path, with `func New(c Config) (*Client, error)`, which returns an error for an invalid `Policy` or `Credential` (MCP's `New(Config) *Client` changes to this, Task 5.3). The network checks (scheme, port, host rules, deny list, addresses, inventory, the checked dial, TLS, proxy off, no cookies, size and time limits) are common to every caller. What a request may carry is a named policy, `Config.Policy`:
- `PolicyLookupPage`: `GET` only, the fixed headers, no `Authorization` and no credential, up to 5 redirects;
- `PolicySearch`: `GET` only, the fixed headers plus the bound `Credential`, no `Authorization`, no redirects;
- `PolicyService` (MCP): `GET` and `POST`, `Authorization` and `Content-Type` allowed, no redirects, as MCP Task 6 and 8 need.
@@ -569,6 +569,7 @@ Only if jobs plan phase 1 has merged by the time `abilities-2` is rebased for me
- `Config.UserAgent`;
- `Config.Credential *Credential` with `Credential{Origin, Header, Param, Value string}`. Exactly one of `Header` and `Param` is set, or `New` refuses. The guard adds `Value`, as that header or query parameter, only when the request's origin equals `Origin` exactly, and refuses `Redirects > 0` with a credential. `Credential` implements `String`, `GoString` and `Format` as `credential(<origin>)`, so the value never prints, and guard errors never include the request URL. Only the two search clients set it;
- `func WithDeny(ctx context.Context, hosts []string) context.Context`, which adds per-request denied hosts to `Config.Deny`, each hop included;
+ - `func WithBeforeHop(ctx context.Context, f func(ctx context.Context, host string) error) context.Context`. The guard calls `f` with the actual destination host for the first request and for every redirect hop, after that hop's checks and immediately before it is sent. An error from `f` stops the request with nothing sent for that hop;
- decompression with the limit applied after it;
- `Response.FinalURL`, plus `Response.Type` sniffed as one of `html`, `text`, `json`, `xml`, `feed`, or `unsupported`;
- `func Registrable(host string) string` for logs.
@@ -582,6 +583,7 @@ Only if jobs plan phase 1 has merged by the time `abilities-2` is rebased for me
- `TestRedirectsZeroForServices`.
- `TestCredentialBoundToOrigin`: a sentinel key goes only to the configured origin, a credential with redirects is refused at `New`, and a 302 from the fake vendor to another host is not followed, so that host receives nothing.
- `TestWithDenyEachHop`.
+ - `TestBeforeHopEveryHop`: `f` runs once per hop with that hop's host, and an error on hop 2 means hop 2 is never sent.
- `TestLookupPoliciesRefusePostAndAuthorization`: a `POST` or an `Authorization` header through either lookup policy is refused `policy`, and nothing is dialled.
- `TestServicePolicyAllowsAuthenticatedPost`.
- `TestCredentialRedacted`: `%v`, `%+v`, `%#v` and every guard error with a sentinel value omit it, and `New` refuses a credential with both or neither of `Header` and `Param`.
@@ -622,10 +624,10 @@ 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` and `func NewBrave(key string, g guard.Config) Searcher`, each building its own guarded client 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`);
+ - `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) }`, 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, guard *guard.Client, usage Usage) (Chain, bool)`, where `false` means no usable backend;
+ - `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}`.
- Snippets are cut at 300 bytes and titles at 200, at a rune boundary. Results that aren't https are dropped.
@@ -747,7 +749,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 `Before` that calls `assist.Gate` and the pacer (never `Usage`, which the chain owns), and calls `assist.Gate` and the pacer before each page read. 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 `Before` that calls `assist.Gate` and the pacer (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;
@@ -770,6 +772,8 @@ 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`.
+ - `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.
- `TestRevokedDuringPrimaryNoFallback`: `web` goes off while the fake primary is answering with an error, and the fake fallback receives zero requests.
- `TestLookupUnsupported`: an older runner, a client without `lookup_answers`, no inventory, and no backend each leave it unlisted.
- `TestLookupExemptFromOutboundRule`, added with MCP Task 27. Until then it is skipped with that reason.
@@ -825,7 +829,7 @@ Planning only: the executor runs this with the operator. No key is printed.
- [ ] **Step 1:** Deploy the instance to staging with `EQUIPO_ABILITIES=web=off`, then the runners (`upgrade-thin.sh`). Confirm with `GET /api/v1/assistant/abilities` that `web` is fixed off.
- [ ] **Step 2:** Set `EQUIPO_INSTANCE_PREFIXES`. An Equipo owner confirms the inventory card.
- [ ] **Step 3:** Store the keys from 1Password without echoing them: `carlos secrets set EQUIPO_MOJEEK_KEY="$(op read 'op://Oficina/Mojeek Search API/credential')"` in a shell without `set -x` or history, as `scripts/staging-thin.py` does for `EQUIPO_INSTANCE_KEY`. Do the same for `EQUIPO_BRAVE_KEY`. Set `EQUIPO_WEB_SEARCH=mojeek`, `EQUIPO_WEB_SEARCH_FALLBACK=brave` and both monthly caps from Task 0.2.
-- [ ] **Step 4:** Remove `web=off` and restart.
+- [ ] **Step 4:** Check that Task 0.2's zero-retention confirmation covers the key just installed. If it doesn't, leave `web=off` and ask Paul whether to wait or to start with Brave as the primary meanwhile. Don't decide alone. Otherwise remove `web=off` and restart.
- [ ] **Step 5: Acceptance (spec §10.3 item 1).** Paul asks Base "What's the weather in Dublin?". Pass: in one reply, within about 15 seconds, a forecast with at least one source, and no card. Run it 5 times across a day. Pass needs 5 out of 5 with a forecast, not a link elsewhere. Record each run's time, its code and which backend answered (`chat_lookups.queries`).
- [ ] **Step 6:** If step 5 fails on content (no forecast in the answer) rather than on time or plumbing, do Task 3.12. Otherwise skip it.
- [ ] **Step 7:** After Paul's check, repeat steps 1 to 5 on production (deploy step 3).
@@ -974,7 +978,7 @@ Planning only: the executor runs this with the operator. No key is printed.
- [ ] **Step 1:** Before either plan is executed, its executor applies spec §7 and AD1/AD2 to it, as a commit on that plan's branch:
- **jobs plan:** renumber protocols from the next free (34 or later) and migrations from the next free; Task 1.4 becomes `Draws`; Tasks 1.5, 1.6, 1.7, 1.10, 1.11, 1.12, 1.15, 1.17, 2.4, 2.7, 2.8, 2.12 and T13 as spec §7.1; `ask_clients` and `Base-Capabilities` already exist (Task 1.1), so it adds only `job_actions`;
- - **MCP plan:** renumber protocol 29 and migrations 0095 to 0106 from the next free; Task 6 is `internal/websource/guard` (already built, Task 3.1), and its clients use `PolicyService`; Task 7 is already built (Task 3.1b); Task 11 is rewritten on `Switches` (spec §7.2), without `service_settings`, `service_permissions`, `EQUIPO_SERVICES_ADD` or `EQUIPO_SERVICES_REVIEW`; Tasks 8, 15, 17, 18, 24, 25, 27, 28, 38 and 40 as spec §7.2, including `assist.Gate` in `SendPrepared` and recovery with spec §10.1's `TestApprovedConfirmExpiresWhenOff`, `TestSendPreparedGate` and `TestRecoveryBlockedStaysUnknown`, and `TestPackRespectsEpoch` and `TestLookupExemptFromOutboundRule` un-skipped.
+ - **MCP plan:** renumber protocol 29 and migrations 0095 to 0106 from the next free; Task 6 is `internal/websource/guard` (already built, Task 3.1), its clients use `PolicyService`, and `guard.New` returns `(*Client, error)`; Task 7 is already built (Task 3.1b); Task 11 is rewritten on `Switches` (spec §7.2), without `service_settings`, `service_permissions`, `EQUIPO_SERVICES_ADD` or `EQUIPO_SERVICES_REVIEW`; Tasks 8, 15, 17, 18, 24, 25, 27, 28, 38 and 40 as spec §7.2, including `assist.Gate` in `SendPrepared` and recovery with spec §10.1's `TestApprovedConfirmExpiresWhenOff`, `TestSendPreparedGate` and `TestRecoveryBlockedStaysUnknown`, and `TestPackRespectsEpoch` and `TestLookupExemptFromOutboundRule` un-skipped.
- [ ] **Step 2:** Done when both plan documents carry the changes and their Astra review passes.
## Copy register additions (this plan)
@@ -1019,3 +1023,10 @@ These go through Task 0.1 with the spec's register. All are DRAFT.
- **P1, Equipo's browser connect paths bypassed the check.** `startOficina` and `finishOficina` check `apps_read` for all four paths, and a source scan pins that (Task 2.8).
- **P2, one guard with different request needs.** Common network checks, plus a named request policy per caller: lookup page, search, service (Task 3.1).
- **P2, the early-switchboard promise.** Switches are offered only once Equipo answers the abilities route. Until then they are disabled with `abilities.not_yet`, which replaces the spec's dated line (Task 4.3).
+
+**Round 4** (Astra, 2026-11-27): NOT READY, with 1 P1 and 3 P2. All were applied.
+
+- **P1, redirect hops skipped the gate and the pacer.** `guard.WithBeforeHop` runs the pacer and the bound gate before every hop (Tasks 3.1 and 3.7).
+- **P2, a check package `equipo` couldn't call.** `chat.Store.Allowed`, exported, reached through `s.Chat()`, and given to the Oficina provider as a callback (Tasks 2.7 and 2.8).
+- **P2, the search constructors.** `guard.New` returns an error, and `FromConfig` takes a `guard.Config` (Tasks 3.1 and 3.3, with MCP's handover in 5.3).
+- **P2, zero retention.** Mojeek's written confirmation is part of Task 0.2's done condition, and Task 3.11 checks it before lookups go on.