oficina / base Public

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

Every Oficina connect path, browser ones included, goes through checked
start and finish functions; the shared guard has per-caller request
policies; switches are offered only once Equipo serves the abilities
route, replacing the dated lead line.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev da56b106089bde3122aa69bbf6d42898e51b5f09 parent 50114d9
1 file changed, +33 −10
  • docs/superpowers/plans/2026-11-27-assistant-abilities.md +33 −10

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:32AM INF Unknown SCM platform. Use --platform to include links in findings. host=amadan.net
9:32AM INF 1 commits scanned.
9:32AM INF scanned ~2579717 bytes (2.58 MB) in 274ms
9:32AM 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.03s 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.187s amadan.net/oficina/base/internal/webtest
receipt: slow package 665ms amadan.net/oficina/base/internal/issuer
receipt: slow package 591ms amadan.net/oficina/base/internal/operations
receipt: slow package 202ms amadan.net/oficina/base/internal/consumer
receipt: slow package 171ms amadan.net/oficina/base/internal/web
receipt: slow test 1.52s amadan.net/oficina/base/internal/webtest TestHomeDoesNotWaitOnAStalledSnapshot
receipt: slow test 1.08s amadan.net/oficina/base/internal/webtest TestAskZoneIsToldOnce
receipt: slow test 510ms amadan.net/oficina/base/internal/operations TestOperationsRefusals
receipt: slow test 400ms amadan.net/oficina/base/internal/issuer TestAuthorizeSignsForInstalledApp
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 aefee39..4597983 100644
--- a/docs/superpowers/plans/2026-11-27-assistant-abilities.md
+++ b/docs/superpowers/plans/2026-11-27-assistant-abilities.md
@@ -94,7 +94,7 @@ Neither the jobs plan nor the MCP plan has landed any code on either main.
- **Errors deny.** A read error, a missing copy, a revoked copy or one more than 10 minutes past `confirmed_at` refuses every switched operation `unavailable` (§5.3).
- **Timings (§5.3):** fetch bound 5 s; refresh when `confirmed_at` is older than 60 s; housekeeping refresh every 60 s for people with a running turn or an unfinished job; expiry 10 min; hint throttle 5 s.
- **Lookup caps (§4.2):** 2 per turn, 100 per person in a rolling 24 h, 1 request per second per host from the instance, 2 queries of at most 200 characters, 8 results per query, 3 reads, at most 5 sources, at most 2 lookups per reply, a pack of at most 4 KiB, 2 earlier lookup turns within 30 min, an answer of at most 1,200 characters, a step timeout of 20 s, a 40 s end-to-end limit with about 15 s as the target.
-- **Guarded client (§4.3):** https on 443 only; an `http://` the person typed is tried once as https; `websource.CheckHost` plus the deny list; every DNS answer must pass `websource.PublicAddress` and lie outside the inventory; the dial goes to the checked IP with a `Control` re-check; no keep-alive; at most 5 redirects for lookups and none for services; `GET` only; headers `User-Agent: OficinaLookup/1`, `Accept`, `Accept-Encoding: gzip` (plus the backend's key header for searches); no cookies, `Authorization`, `Referer` or environment proxy. Time limits: 5 s connect, 10 s to first byte, 15 s per request, 25 s per page with its redirects, 10 s per search. Size limits: headers 32 KiB, bodies 2 MiB decompressed, URLs 2 KiB. Types sniffed: HTML, text, JSON, XML, RSS and Atom.
+- **Guarded client (§4.3):** network checks shared by every caller, request policies per caller (Task 3.1). For lookups: https on 443 only; an `http://` the person typed is tried once as https; `websource.CheckHost` plus the deny list; every DNS answer must pass `websource.PublicAddress` and lie outside the inventory; the dial goes to the checked IP with a `Control` re-check; no keep-alive; at most 5 redirects for lookups and none for services; `GET` only; headers `User-Agent: OficinaLookup/1`, `Accept`, `Accept-Encoding: gzip` (plus the backend's key header for searches); no cookies, `Authorization`, `Referer` or environment proxy. Time limits: 5 s connect, 10 s to first byte, 15 s per request, 25 s per page with its redirects, 10 s per search. Size limits: headers 32 KiB, bodies 2 MiB decompressed, URLs 2 KiB. Types sniffed: HTML, text, JSON, XML, RSS and Atom.
- **Answer step budget (§4.3):** serialized input at most 56 KiB; snippets at most 300 bytes and titles at most 200 bytes, cut at a character boundary; page text at most 16 KiB, then the lowest-ranked page is cut first; `truncated` is set whenever anything was cut.
- **Never stored:** page text, snippets and the pack. Never logged: a query, a URL path, a person's words or a key. Refusals log the rule and the registrable domain only (§4.3, §4.7).
- **Outcomes, not machinery.** No Equipo, team, runner, task, branch, merge, repository, MCP, server or token in any Base-visible string. The reply test runs the jobs plan's `machinery_words` list (Equipo, team, Coordinator, runner, task, branch, merge, check, repository, Amadan) where it exists, or this plan's copy of it in `internal/thintest/machinery_words.go` (Task 3.10).
@@ -125,7 +125,7 @@ Neither the jobs plan nor the MCP plan has landed any code on either main.
| 3a | Equipo | Phase 3 instance with protocol 34 known, deployed with `EQUIPO_ABILITIES=web=off` | `web_lookup` isn't listed to a runner below 34, to a person whose Base hasn't sent `lookup_answers`, before the inventory is confirmed, or without a usable backend |
| 3b | Equipo | Runners (`upgrade-thin.sh`) | `Encode` refuses `lookup_step` below 34 |
| 3c | operator | Set and confirm `EQUIPO_INSTANCE_PREFIXES`; store keys and caps; remove `web=off`; run the weather check (Task 3.11) | |
-| 4 | Base | Phase 4: the switchboard (migration 0014) | Equipo enforces from step 2, so the person page never promises what isn't enforced. If an environment gets step 4 before step 2, the lead line reads `abilities.later` (Task 4.3) |
+| 4 | Base | Phase 4: the switchboard (migration 0014) | Equipo step 2 is a hard prerequisite on each environment. As a guard against the wrong order, the person page offers switches only once Equipo answers `GET /api/v1/assistant/abilities` (Task 4.3); until then the rows are disabled with `abilities.not_yet`, and a POST is refused 409 |
| 5 | both | Jobs plan phase 1 with spec §7.1's changes (Task 5.3), then MCP S1 and S2 with §7.2's changes. If jobs plan phase 1 landed before step 2, its card rows ship in step 2 (Task 2.12b) | The jobs plan's own switches (`BASE_JOB_ACTIONS`) |
Each step goes to staging (`*.oncarlos.com`) first, then to production (`*.oficina.works`) after Paul's live check. The versions in between are tested as deployed (Tasks 2.13, 3.10, 4.8). The planner deploys nothing.
@@ -441,12 +441,18 @@ ALTER TABLE chat_assistant_hosts ADD COLUMN capabilities text; -- omitted if j
### Task 2.8 (Equipo): Connect cards and the Oficina connect routes
-**Files:** `internal/equipo/chat_wiring.go` (`OnUnconnected`), `internal/equipo/oficina_connect.go` (`/oficina/connect` and `/oficina/connect/finish`), `internal/equipo/oficina_connect_abilities_test.go` (new).
+**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.
- [ ] **Step 1: Failing tests:**
- `TestOficinaConnectNeedsAppsRead`: no card is raised, and `POST /oficina/connect` and `/finish` answer 403 `ability_off`.
- `TestExistingOficinaConnectionKeptUnused`.
-- [ ] **Step 2:** Run `CGO_ENABLED=0 go test ./internal/equipo/... -run 'OficinaConnectNeeds|KeptUnused' -count=1`. Expected: FAIL.
+ - `TestOficinaBrowserStartNeedsAppsRead`: `oficinaStart` with `apps_read` off doesn't call `Start`.
+ - `TestOficinaConsentFinishedAfterRevoke`: consent begun with `apps_read` on and finished after it went off, through `oficinaDone` and through the API, exchanges no code and saves no connection.
+ - `TestOficinaDisconnectWhileOff`.
+ - `TestOnlyCheckedPathsCallOficina`: a source scan finds `s.oficina.Start(` and `s.oficina.Finish(` only inside `startOficina` and `finishOficina`.
+- [ ] **Step 2:** Run `CGO_ENABLED=0 go test ./internal/equipo/... -run 'OficinaConnectNeeds|KeptUnused|OficinaBrowserStart|OficinaConsentFinished|OficinaDisconnect|OnlyCheckedPaths' -count=1`. Expected: FAIL.
- [ ] **Step 3:** Implement. The connect card is raised only when the person has `apps_read`.
- [ ] **Step 4:** Run. Expected: PASS.
- [ ] **Step 5:** Commit `Abilities: Oficina connect needs apps_read`.
@@ -553,7 +559,12 @@ 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, with these additions:
+- 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`:
+ - `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.
+
+ A request outside its policy is refused `policy`, before any dial. The additions to MCP's interface are:
- `Config.Redirects int` (page reads 5; searches and services 0) and `Config.Timeouts` (page reads: 5 s connect, 10 s to first byte, 15 s per request, 25 s per page including redirects; searches: 10 s);
- `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;
@@ -571,6 +582,8 @@ 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`.
+ - `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`.
- `TestHTTPTypedTriedAsHTTPSOnce`.
- `TestGuardNeverDialsInTests`.
@@ -873,11 +886,12 @@ Planning only: the executor runs this with the operator. No key is printed.
**Files:** `internal/web/people.go` (`personPage`, `setAbility`), `internal/web/app.go` (`GET /people/{number}`, `POST /people/{number}/abilities`), `internal/web/templates/person.html` (new), `internal/web/templates/people.html` (owner rows link to the member's page), `internal/look/static/*.css`, `internal/webtest/person_test.go` (new).
**Interfaces:**
-- Consumes: Task 4.1's store; `equipo.AbilityKeys` (AD5); `(c *Client) OwnAbilities(ctx, token)` from Task 4.4 for fixed keys.
+- Consumes: Task 4.1's store; `equipo.AbilityKeys` (AD5).
+- Produces first: `(c *Client) OwnAbilities(ctx context.Context, token string) (Own, error)` in `internal/equipo/abilities.go`, with `type Own struct { Abilities map[string]bool; Fixed []string; Ask string }` (Equipo's `GET /api/v1/assistant/abilities`), and the fake Equipo serving it, or 404 to stand for an Equipo before step 2. It gives the fixed keys and the enforcement check.
- Every string comes from Task 0.1's approved keys.
- Rows follow §3's order, with `services_add` indented. Each row has its name, line, and an On/Off pair with `aria-pressed` in its own form. A disabled row reads `abilities.implied` or `abilities.fixed`. The off-consequence lines follow, then Recent changes (the last 20), and `abilities.owner` on the owner's page.
- A POST answers 303 back to the page, 422 for an unknown key, 409 for a fixed key, and 404 for a non-owner, all with Base's existing form protections.
-- The lead line is `abilities.lead`, or `abilities.later` while `BASE_ABILITIES_FROM` (date, config; empty by default) is in the future. That covers the §9 step 4 exception.
+- **Enforcement check.** The page offers switches only when Equipo has answered `OwnAbilities` (above) with a 200, using the owner's Equipo bearer or else the target member's, cached in memory for 5 minutes. With no 200 (an Equipo before step 2 answers 404, or neither bearer exists), every row is disabled, the lead line is replaced by `abilities.not_yet`, and `POST /people/{number}/abilities` answers 409 without saving. This replaces the spec's `abilities.later` and its "from {date}" (§9 step 4): no switch is ever saved before enforcement is confirmed, so no timing promise is needed.
- [ ] **Step 1: Failing tests:**
- `TestPersonPageOwnerOnly`.
@@ -888,14 +902,15 @@ Planning only: the executor runs this with the operator. No key is printed.
- `TestRecentChangesOnlyWithRows`.
- `TestAbilityTogglePostedTwice` (Review Focus 3).
- `TestPeopleRowsLinkForOwner`.
-- [ ] **Step 2:** Run `go test ./internal/webtest -run 'PersonPage|AbilityToggle|AbilityImplied|AbilityFixed|CannotLimit|RecentChanges|PeopleRows' -count=1`. Expected: FAIL.
+ - `TestSwitchesDisabledBeforeEnforcement`: fake Equipo answers 404 on `/api/v1/assistant/abilities`, so rows are disabled with `abilities.not_yet` and a POST is refused 409 with nothing saved; once it answers 200, the switches work.
+- [ ] **Step 2:** Run `go test ./internal/webtest -run 'PersonPage|AbilityToggle|AbilityImplied|AbilityFixed|CannotLimit|RecentChanges|PeopleRows|SwitchesDisabledBefore' -count=1`. Expected: FAIL.
- [ ] **Step 3:** Implement.
- [ ] **Step 4:** Run. Expected: PASS.
- [ ] **Step 5:** Commit `People: a page per member with what their assistant can do`.
### Task 4.4 (Base): The hint and the saved status
-**Files:** `internal/equipo/abilities.go` (`(c *Client) RefreshAbilities(ctx, token string) (revision int64, now bool, err error)`, `(c *Client) OwnAbilities(ctx, token string) (Own, error)`), `internal/equipo/equipotest/chat.go` (the fake records refresh calls and their bearer), `internal/web/people.go`, `internal/webtest/person_test.go`.
+**Files:** `internal/equipo/abilities.go` (`(c *Client) RefreshAbilities(ctx, token string) (revision int64, now bool, err error)`, beside Task 4.3's `OwnAbilities`), `internal/equipo/equipotest/chat.go` (the fake records refresh calls and their bearer), `internal/web/people.go`, `internal/webtest/person_test.go`.
**Interfaces:** After `SetAbility` changes something, Base calls `RefreshAbilities` with the **target member's** Equipo bearer, when it holds one. The status is `abilities.saved_now` only for a 200 with a revision at least the saved one. Every other outcome shows `abilities.saved_later`.
@@ -959,7 +974,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); 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), 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.
- [ ] **Step 2:** Done when both plan documents carry the changes and their Astra review passes.
## Copy register additions (this plan)
@@ -970,6 +985,8 @@ These go through Task 0.1 with the spec's register. All are DRAFT.
|---|---|---|
| `ask.fallback_sources` | Base, in the plain text an older app gets instead of a drawn answer (Task 1.6) | Sources: |
| `assistant.job.detail.ability_back` | Base, under a held job's "Stopped" once building is on again (AD4) | Building is on again. You can carry on with this, or drop it. |
+| `abilities.not_yet` | Base, person page, in place of the lead line while the switches can't be changed yet (replaces the spec's `abilities.later`) | You'll be able to change these soon. |
+| `oficina.connect.ability_off` | Equipo's own page, when connecting Oficina is refused because reading apps is off | Reading your Oficina apps is turned off for you. {Owner} can turn it on. |
| `abilities.save_failed` | Base, person page, with scripts, when a toggle couldn't be saved | That didn't save. Try again. |
| `chat.card.ability_off` | Equipo's own conversation page, when a job card that would start work is answered there while `build` is off | Building is turned off for you, so this can't start. You can still drop it. |
| `services.inventory.question`, `services.inventory.confirm` | Equipo's own page, owners only (MCP Task 7's strings, reviewed here if this plan builds the inventory) | Before your assistant can look things up on the web or reach other services, confirm the network this server is on. / Confirm |
@@ -996,3 +1013,9 @@ These go through Task 0.1 with the spec's register. All are DRAFT.
- **P2, cap exhaustion versus refusal.** `Before` is authorization only. `Chain` owns the cap, and a spent cap moves to the fallback (AD3, Task 3.3).
- **P2, `base_apps` under the web gate.** `baseAppOrigins` uses its own gate bound to `base_apps` (Task 3.7).
- **P2, the credential's value.** `Credential.Value`, one of header or param, and redacted formatting (Task 3.1).
+
+**Round 3** (Astra, 2026-11-27): NOT READY, with 1 P1 and 2 P2. All were applied.
+
+- **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).