| 1 | # Base First Slice Implementation Plan |
| 2 | |
| 3 | > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| 4 | |
| 5 | **Goal:** A team signs in to Base, invites a teammate, and installs and uninstalls real apps (Welcome and Scratchpad) on Base's own Platform account; installed apps know who the person is. |
| 6 | |
| 7 | **Architecture:** One Go module holds three binaries: |
| 8 | |
| 9 | - `base`: the front door. |
| 10 | - `scratchpad` and `welcome`: two tiny apps installed through Base. |
| 11 | |
| 12 | Base talks to Platform through a narrow `platform.Client`. Installing means writing an instance's config environment and then creating the instance. Identity flows by Base minting `rastrillo/assertion` tokens, using the handoff flow designed for Oficina home. Every installed app verifies them through one shared `consumer` package. |
| 13 | |
| 14 | **Tech Stack:** Go (`GOTOOLCHAIN=go1.26.10`, `CGO_ENABLED=0`), `amadan.net/rastrillo/rastrillo v0.33.0` (auth, passkey, sessions, csrf, migrate, mail, assertion, crypto, assets, harness), chi, SQLite. |
| 15 | |
| 16 | **Spec:** `docs/superpowers/specs/2026-11-06-base-first-slice-design.md`. The visual reference is `.superpowers/mockups/index.html`, which is git-ignored and published at [https://base-first-slice.docs-t1.dev.platform.tito.io](https://base-first-slice.docs-t1.dev.platform.tito.io). |
| 17 | |
| 18 | ## Global Constraints |
| 19 | |
| 20 | - **Module and layout:** module path `amadan.net/oficina/base`. Copy equipo's boot shape (`oficina/equipo/cmd/equipo/main.go:26-55`): `rastrillo.Resolve` → `db.Open` → app → `rastrillo.Serve`. Routes use chi. |
| 21 | - **Pages work with scripts off** (app spec 12.5): |
| 22 | - Every write is a plain `<form method="post">` answered with a 303. |
| 23 | - Scripts are `defer` add-ons. |
| 24 | - Anything that waits uses a `<noscript>` meta refresh. |
| 25 | - **Not an operating system** (spec 18.2): no windows, title bars or window controls. Opening an app is a normal link to its origin. |
| 26 | - **Assertions:** |
| 27 | - Signed with `rastrillo/assertion` (P-256), with `iss` = Base origin and `aud` = the installed instance's origin. |
| 28 | - Lifetime 120 s. |
| 29 | - `kid` = lowercase hex SHA-256 of `Keypair.SignPub()` (65 bytes). |
| 30 | - `Ext` carries display fields only. |
| 31 | - Origins must be `https://` hostnames; the verifier rejects IP addresses. |
| 32 | - **Shared app contract:** every app Base installs reads exactly these four variables. Nothing in Base is specific to Scratchpad. |
| 33 | - `BASE_APP_ORIGIN` |
| 34 | - `BASE_APP_ISSUER` |
| 35 | - `BASE_APP_CONSUMER_ID` |
| 36 | - `BASE_APP_KEYS` (base64 of a JSON object mapping each `kid` to the base64 of its 65-byte public key) |
| 37 | - **Platform:** |
| 38 | - Two service credentials, because a credential holds one role: |
| 39 | - `BASE_PLATFORM_INSTANCE_TOKEN` (role `instance`) |
| 40 | - `BASE_PLATFORM_OPERATE_TOKEN` (role `operate`) |
| 41 | - Both are account-wide (no `--app`). Header: `Authorization: Bearer <token>`. |
| 42 | - Never call `instances-manifest`; an operator enables each catalogue app once (spec 5.6). |
| 43 | - **Instance hosts:** |
| 44 | - Each is `<BASE_SLUG>-<appid>.<BASE_APPS_DOMAIN>`: one DNS label, at most 32 characters, matching `[a-z0-9]([a-z0-9-]*[a-z0-9])?`. |
| 45 | - The instance's config environment has the same name as the label. |
| 46 | - **Look** (spec 6): |
| 47 | - Approved colours: `#2FC6C0`, `#8B5CF6`, `#F472B6`, `#6EE7DC`; glass tint `rgba(14,17,42,.40)`; secondary text `#DDE3F0`. |
| 48 | - Fog loops of 10–17 s; everything stops under `prefers-reduced-motion`. |
| 49 | - Controls are 44px tall. |
| 50 | - Timeless Sans only: `STYL` 100 for body text, 0 for headings and the wordmark. Preloaded with `font-display: block`. |
| 51 | - WCAG AA contrast. |
| 52 | - **Timeless font:** never committed. `hack/fonts.sh` fetches `https://media.timeless.co/type/Timeless-Type-Family-1.094.zip`, checks SHA-256 `510685dfce6010b74a1a250af7de1204e1b9901be152a39f5dd6be85fc6d6084`, and extracts `Sans-Grotesk/TimelessSansVF.woff2`. The fallback is DM Sans (OFL, committed), with metrics matched as in ppl. |
| 53 | - **Copy** (exact strings the spec fixes): |
| 54 | - Uninstall confirmation: "Uninstall {App}? It's removed from Home for everyone at {Base name}. Its data is kept, and comes back if you install it again." |
| 55 | - Steps: "Signed in", "Invite your team", "Install your first app". |
| 56 | - Invited state: "Invited. Hasn't signed in yet." |
| 57 | - All new user-facing copy goes through the copy-review skill before it lands. |
| 58 | - **Commits:** subject under 80 characters, a body after a blank line, and the trailer `Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>`. Work on branch `first-slice`, not `main`. |
| 59 | - **Servers you start for local checks:** bind them to `127.0.0.1` only, and share them with `carlos devbox share --port`, which also supplies the HTTPS origins assertions need. |
| 60 | |
| 61 | ## Review Focus |
| 62 | |
| 63 | 1. **A replayed or late assertion:** posting the same assertion twice, or posting it after 120 s, must not sign anyone in. Test: `TestAssertionReplayRefused`, `TestAssertionExpiredRefused` (Task 9). |
| 64 | 2. **Install pressed twice, or in two tabs:** this must create one instance, not two and not an error. Test: `TestInstallTwiceIsOneInstance` (Task 6). |
| 65 | 3. **An install that fails halfway:** config written but the create refused, or an instance that never answers. The app must show as failed with a retry, never as a tile that leads nowhere. Test: `TestInstallCreateRefusedMarksFailed`, `TestInstallNeverAnswersMarksFailed` (Task 6). |
| 66 | 4. **Someone who shouldn't get an assertion asks for one:** a signed-in person who has been removed, a request for an app that isn't installed, or an unknown consumer. They must be refused without an assertion. Test: `TestAuthorizeRefusals` (Task 8). |
| 67 | 5. **Inviting an existing address in different case** (`Maria@Acme.co` vs `maria@acme.co`): this must not create a second member. Test: `TestInviteIsCaseInsensitive` (Task 4). |
| 68 | |
| 69 | --- |
| 70 | |
| 71 | ## File map |
| 72 | |
| 73 | ``` |
| 74 | cmd/base/main.go boot Base |
| 75 | cmd/scratchpad/main.go boot Scratchpad |
| 76 | cmd/welcome/main.go boot Welcome |
| 77 | internal/config/config.go Base settings from the environment |
| 78 | internal/store/ migrations, members, installs, owner bootstrap |
| 79 | internal/look/ layout, CSS, fonts handler, shared template funcs |
| 80 | internal/web/ Base routes and handlers (signin, home, people, store, settings) |
| 81 | internal/catalog/ catalog.json (embedded) and its type |
| 82 | internal/platform/ Client interface, HTTP client, Fake |
| 83 | internal/install/ Installer: install, uninstall, readiness, first-boot Welcome |
| 84 | internal/issuer/ /authorize: mints assertions for installed apps |
| 85 | internal/consumer/ shared app side: start, assertion, finish, sessions, replay store |
| 86 | internal/scratchpad/ Scratchpad's notes page |
| 87 | internal/welcome/ Welcome's page |
| 88 | hack/fonts.sh fetch Timeless (pinned) |
| 89 | scripts/prepare-apps.sh operator: create, ship and enable each catalogue app once |
| 90 | Makefile, run.sh, .env.local.example, README.md |
| 91 | ``` |
| 92 | |
| 93 | ### Task 1: Skeleton, config, store and owner bootstrap |
| 94 | |
| 95 | **Files:** |
| 96 | - Create: `go.mod`, `Makefile`, `run.sh`, `.env.local.example`, `cmd/base/main.go`, `internal/config/config.go`, `internal/store/{migrations.go,migrations/0001_base.sql,members.go,installs.go,bootstrap.go}` |
| 97 | - Modify: `.gitignore` (add `/.env.local`, `/.local/`, `*.db*`, `/releases/`, `internal/look/static/fonts/timeless/`) |
| 98 | - Test: `internal/config/config_test.go`, `internal/store/store_test.go` |
| 99 | |
| 100 | **Interfaces:** |
| 101 | - Produces: |
| 102 | - `config.Load(getenv func(string) string) (config.Config, error)`. `Config` has these fields: |
| 103 | - `Origin`, `Name`, `Slug`, `Owner`, `AppsDomain`, `Timezone *time.Location` |
| 104 | - `PlatformConsole`, `PlatformAccount`, `InstanceToken`, `OperateToken` |
| 105 | - `AssertionKey *crypto.Keypair` |
| 106 | - `AllowLoggedMail bool` |
| 107 | - Environment variables, all prefixed `BASE_`: `ORIGIN`, `NAME`, `SLUG`, `OWNER`, `APPS_DOMAIN`, `TIMEZONE` (default `Europe/London`), `PLATFORM_CONSOLE`, `PLATFORM_ACCOUNT`, `PLATFORM_INSTANCE_TOKEN`, `PLATFORM_OPERATE_TOKEN`, `ASSERTION_KEY` (base64 of `crypto.MarshalKeypair`), `ALLOW_LOGGED_MAIL`. |
| 108 | - `store.Schema`, and `store.BootSchema = migrate.Merge(sessions.Schema, auth.Schema, pow.Schema, store.Schema)`. |
| 109 | - `store.Member{ID, Email, Name string; Role string /* "owner"|"member" */; InvitedAt time.Time; JoinedAt *time.Time}`, plus: |
| 110 | - `store.Members(ctx, db) ([]Member, error)` |
| 111 | - `store.MemberByEmail(ctx, db, email) (Member, bool, error)` |
| 112 | - `store.Invite(ctx, db, email string) (Member, bool /*created*/, error)` |
| 113 | - `store.MarkJoined(ctx, db, id string) error` |
| 114 | - `store.Bootstrap(ctx, db, ownerEmail string) error`: seeds the owner only when there are no members. |
| 115 | - `store.Install{App, Host, State string /* "installing"|"installed"|"failed" */; Error string; UpdatedAt time.Time}`, plus: |
| 116 | - `store.Installs(ctx, db) ([]Install, error)` |
| 117 | - `store.ClaimInstall(ctx, db, app, host string) (bool, error)`: true only for the caller that moves the app into `installing`. |
| 118 | - `store.SetInstallState(ctx, db, app, state, errMsg string) error` |
| 119 | - `store.DeleteInstall(ctx, db, app string) error` |
| 120 | |
| 121 | - [ ] **Step 1: Write failing tests.** |
| 122 | - `TestLoadRequiresOriginAndOwner`: a missing `BASE_ORIGIN` or `BASE_OWNER` gives an error naming the variable. |
| 123 | - `TestLoadRefusesLoggedMailOffLoopback`: `BASE_ALLOW_LOGGED_MAIL=1` with a non-loopback origin gives an error. |
| 124 | - `TestSlugMakesLegalHosts`: a slug that would make a label over 32 characters, or with illegal characters, is refused. |
| 125 | - `TestBootstrapSeedsOwnerOnce`: the first call gives one member with role `owner`; a second call with a different email leaves one member. |
| 126 | - `TestClaimInstallOnlyOnce`: two claims on the same app give `true`, then `false`. |
| 127 | - [ ] **Step 2:** Run `go test ./internal/... -run 'TestLoad|TestSlug|TestBootstrap|TestClaim'`. Expected: FAIL (packages missing). |
| 128 | - [ ] **Step 3:** Implement the code above. The member `ID` is `assertion.RandomID()`. It becomes the assertion `sub`, so it is never the email. `Makefile` copies equipo's targets: `ci`, `test` (`rastrillo budget test -count=1 ./...`) and `release` building all three binaries. `run.sh` copies equipo's, with `BASE_*` names. |
| 129 | - [ ] **Step 4:** Run the same tests. Expected: PASS. Also run `go vet ./...`. |
| 130 | - [ ] **Step 5:** Commit: "Add Base skeleton, config and member store". |
| 131 | |
| 132 | ### Task 2: The look: layout, CSS and fonts |
| 133 | |
| 134 | **Files:** |
| 135 | - Create: |
| 136 | - `internal/look/look.go` |
| 137 | - `internal/look/templates/layout.html` |
| 138 | - `internal/look/static/app.css` |
| 139 | - `internal/look/static/fonts/dm-sans/4.004/DMSans-VF.woff2` (copy from `~/amadan.net/ppl/ppl/.claude/worktrees/profile-instance/internal/ppl/static/fonts/dm-sans/4.004/`, with `OFL.txt`) |
| 140 | - `internal/look/static/fonts/timeless/.keep` |
| 141 | - `hack/fonts.sh` |
| 142 | - Test: `internal/look/look_test.go` |
| 143 | |
| 144 | **Interfaces:** |
| 145 | - Produces: |
| 146 | - `look.Assets` (a `rastrillo.NewAssets` over the embedded `static`). |
| 147 | - `look.FontHandler() http.Handler`, mounted at `GET /static/fonts/` with `Cache-Control: public, max-age=31536000, immutable`. |
| 148 | - `look.Page(w http.ResponseWriter, name string, data any) error`: renders `layout.html` with one page template. Every Task 3–7 page uses it. |
| 149 | - Layout blocks: `title`, `main`. The layout carries the atmosphere: `.light`, plus `.fog` with four `<i>`. |
| 150 | |
| 151 | - [ ] **Step 1: Write failing tests.** |
| 152 | - `TestLayoutPreloadsTimeless`: the rendered layout contains `<link rel="preload" href="/static/fonts/timeless/1.094/TimelessSansVF.woff2" as="font" type="font/woff2" crossorigin>`. |
| 153 | - `TestFontsImmutable`: the DM Sans path answers 200 with the immutable header. A missing Timeless file answers 404. |
| 154 | - `TestLayoutHasNoRequiredScript`: every `<script>` in the layout has `defer`, and the page has no inline `onclick`. |
| 155 | - [ ] **Step 2:** Run `go test ./internal/look/`. Expected: FAIL. |
| 156 | - [ ] **Step 3:** Implement. Port `app.css` from the mockup's `<style>`: |
| 157 | - Keep the tokens, glass, fog paths, light sway, tiles and controls. |
| 158 | - Drop the mockup-only `.page`, `.row`, `figure` and `figcaption` rules. |
| 159 | - Add the `@font-face` blocks: `Timeless Sans` with `font-display: block`, and the `DM Sans` fallback with `size-adjust: 98%` and `ascent-override: 98.3%`, as ppl's `app.css:59-75` does. |
| 160 | - `hack/fonts.sh` downloads the zip, checks the SHA-256, extracts into `internal/look/static/fonts/timeless/1.094/`, and exits non-zero on a mismatch. |
| 161 | - [ ] **Step 4:** Run the tests again. Expected: PASS. |
| 162 | - [ ] **Step 5:** Commit: "Add Base layout, glass styles and fonts". |
| 163 | |
| 164 | ### Task 3: Sign in, sign out and the member gate |
| 165 | |
| 166 | **Files:** |
| 167 | - Create: `internal/web/app.go`, `internal/web/signin.go`, `internal/web/templates/{signin.html,confirm.html}` |
| 168 | - Modify: `cmd/base/main.go` |
| 169 | - Test: `internal/webtest/harness_test.go`, `internal/webtest/signin_test.go` |
| 170 | |
| 171 | **Interfaces:** |
| 172 | - Consumes: `config.Config`, `store.*`, `look.Page`. |
| 173 | - Produces: |
| 174 | - `web.App(db *sql.DB, cfg config.Config, mailer mail.Sender, inst Installer, logger *slog.Logger) (http.Handler, error)`. |
| 175 | - The Installer interface (implemented in Task 6): `type Installer interface { Install(ctx context.Context, app string) error; Uninstall(ctx context.Context, app string) error }`. |
| 176 | - `web.CurrentMember(r *http.Request) (store.Member, bool)`. |
| 177 | - The test harness `newApp(t) *testApp`, with `get`, `post` (sets `Origin`), `signIn(email)` and `mailbox()`, copied from equipo's `internal/equipotest/harness_test.go`. |
| 178 | - Until Task 6 lands, `main` and the harness pass a no-op `Installer`. |
| 179 | |
| 180 | - [ ] **Step 1: Write failing tests.** |
| 181 | - `TestOwnerCanSignIn`: the bootstrapped owner gets a link in the mailbox; following it reaches `/` with 200. |
| 182 | - `TestStrangerRefused`: an address that is neither owner nor invited gets no session. The page says sign-in isn't available for that address; the wording goes through copy-review. |
| 183 | - `TestInvitedMemberJoinsOnFirstSignIn`: after signing in, `JoinedAt` is set. |
| 184 | - `TestSignOut`: after a POST to `/auth/signout`, `/` redirects to `/signin`. |
| 185 | - [ ] **Step 2:** Run `go test ./internal/webtest/ -run 'TestOwner|TestStranger|TestInvited|TestSignOut'`. Expected: FAIL. |
| 186 | - [ ] **Step 3:** Implement by copying equipo's `setup/session_handlers.go:32-63`: |
| 187 | - `auth.New` with `KeymailServers: []string{"keymail.dev"}`, `SigninScreen: true`, `BeginPath: "/auth/begin"`, and `pow.NoProof`. |
| 188 | - The `Authorize` callback calls `store.MemberByEmail` and marks the member joined. |
| 189 | - Wrap every browser route in `csrf.Protect`. |
| 190 | - Mail comes from `mail.FromEnv("CARLOS", logger)`, as in equipo's `config.go:39-44`. Boot is refused without it unless `AllowLoggedMail` is set. |
| 191 | - [ ] **Step 4:** Run the tests again. Expected: PASS. |
| 192 | - [ ] **Step 5:** Commit: "Sign in to Base with email or Keymail". |
| 193 | |
| 194 | ### Task 4: People and invites |
| 195 | |
| 196 | **Files:** |
| 197 | - Create: `internal/web/people.go`, `internal/web/templates/people.html` |
| 198 | - Test: `internal/webtest/people_test.go` |
| 199 | |
| 200 | **Interfaces:** |
| 201 | - Consumes: `store.Invite`, `store.Members`, `web.CurrentMember`. |
| 202 | |
| 203 | - [ ] **Step 1: Write failing tests.** |
| 204 | - `TestOwnerInvites`: a POST to `/people` with `email=maria@acme.co` adds a row showing "Invited. Hasn't signed in yet." and puts one invitation in the mailbox. The invitation links to `BASE_ORIGIN/signin`. |
| 205 | - `TestInviteIsCaseInsensitive`: inviting `Maria@Acme.co` after `maria@acme.co` leaves one member and sends no second invitation. |
| 206 | - `TestMemberCannotInvite`: a non-owner's POST gets 403. |
| 207 | - `TestPeopleWorksWithoutScripts`: the page's form posts to `/people` and the reply is a 303. |
| 208 | - [ ] **Step 2:** Run `go test ./internal/webtest/ -run 'TestOwnerInvites|TestInvite|TestMemberCannot|TestPeople'`. Expected: FAIL. |
| 209 | - [ ] **Step 3:** Implement. Lowercase and trim the email before `store.Invite`. Run the invitation copy through copy-review. |
| 210 | - [ ] **Step 4:** Run the tests again. Expected: PASS. |
| 211 | - [ ] **Step 5:** Commit: "Invite teammates to Base". |
| 212 | |
| 213 | ### Task 5: Catalogue and Platform client |
| 214 | |
| 215 | **Files:** |
| 216 | - Create: `internal/catalog/{catalog.go,catalog.json}`, `internal/platform/{client.go,http.go,fake.go}` |
| 217 | - Test: `internal/catalog/catalog_test.go`, `internal/platform/http_test.go` |
| 218 | |
| 219 | **Interfaces:** |
| 220 | - Produces: |
| 221 | - `catalog.Entry{ID, Name, Summary, Tint string /* "amber"|"teal"|"violet"|"mist"|"rose" */; Icon string; Default bool}`, with `catalog.All() []Entry` and `catalog.Get(id string) (Entry, bool)`. |
| 222 | - `catalog.json` lists `welcome` (Default true, amber) and `scratchpad` (rose). |
| 223 | - The `platform.Client` interface: |
| 224 | - `SetEnv(ctx context.Context, app, environment string, vars map[string]string) error` |
| 225 | - `CreateInstance(ctx context.Context, app, host, environment string) error`: a 409 counts as success. |
| 226 | - `DeleteInstance(ctx context.Context, app, host string) error` |
| 227 | - `platform.NewHTTP(console, account, instanceToken, operateToken string, hc *http.Client) platform.Client`. |
| 228 | - `platform.Fake`: records calls, can be told to fail a given call, and implements `Client`. |
| 229 | |
| 230 | - [ ] **Step 1: Write failing tests** against an `httptest.Server` that records requests. |
| 231 | - `TestSetEnvShape`: `PUT {console}/api/cli/apps/{account}/{app}/config` with the operate token and body `{"environment":E,"message":"Base: install","set":{K:{"kind":"env","value":V}}}`. |
| 232 | - `TestCreateInstanceShape`: `POST .../instances` with the instance token and body `{"host":H,"environment":E,"message":"Base: install"}`. A 201 or a 409 is success. |
| 233 | - `TestDeleteInstanceShape`: `DELETE .../instances/{host}` with `X-Carlos-Message: Base: uninstall`. |
| 234 | - `TestErrorsCarryStatusNotBody`: a 403 gives an error naming the call and the status, without the response body. |
| 235 | - `TestCatalogIDsAreLabels`: every ID is a legal label part. |
| 236 | - [ ] **Step 2:** Run `go test ./internal/catalog/ ./internal/platform/`. Expected: FAIL. |
| 237 | - [ ] **Step 3:** Implement. Endpoints and bodies follow `carlos/platform/internal/console/apiinstances.go:608-683,1476-1537` and `apiconfig.go:279-304`. Base sets only `kind: "env"`, because nothing it sends is secret, so no sealing is needed. |
| 238 | - [ ] **Step 4:** Run the tests again. Expected: PASS. |
| 239 | - [ ] **Step 5:** Commit: "Add the catalogue and a Platform client". |
| 240 | |
| 241 | ### Task 6: Installer |
| 242 | |
| 243 | **Files:** |
| 244 | - Create: `internal/install/install.go` |
| 245 | - Test: `internal/install/install_test.go` |
| 246 | |
| 247 | **Interfaces:** |
| 248 | - Consumes: `platform.Client`, `catalog.Get`, the `store` install functions, `config.Config`. |
| 249 | - Produces: |
| 250 | - `install.New(db *sql.DB, cfg config.Config, pc platform.Client, probe func(ctx context.Context, origin string) error, logger *slog.Logger) *install.Installer`, which implements `web.Installer`. |
| 251 | - `install.HostFor(cfg config.Config, app string) (label, host string)`. |
| 252 | - `install.ProbeVersion(hc *http.Client) func(ctx, origin) error`: polls `GET {origin}/api/version` every 2 s until it gets a 200, giving up after 5 minutes. |
| 253 | - `(*Installer).EnsureDefaults(ctx) error`: installs every `Default` entry that isn't installed. Called once from `main` at boot, in the background. |
| 254 | - `install.AppVars(cfg config.Config, app, origin string) map[string]string`: the four `BASE_APP_*` values. |
| 255 | |
| 256 | - [ ] **Step 1: Write failing tests** using `platform.Fake` and a probe stub. |
| 257 | - `TestInstallWritesEnvThenCreates`: `SetEnv` is called with exactly `BASE_APP_ORIGIN=https://acme-scratchpad.bab.oncarlos.com`, `BASE_APP_ISSUER=<cfg.Origin>`, `BASE_APP_CONSUMER_ID=scratchpad` and `BASE_APP_KEYS=<base64 JSON {kid: base64 SignPub}>`. Then `CreateInstance` is called with the same label as environment. Then the state is `installed`. |
| 258 | - `TestInstallTwiceIsOneInstance`: two concurrent `Install` calls make one `CreateInstance` call. |
| 259 | - `TestInstallCreateRefusedMarksFailed`: the Fake fails the create. The state becomes `failed` with an error message, and a later `Install` retries. |
| 260 | - `TestInstallNeverAnswersMarksFailed`: the probe returns a timeout, and the state becomes `failed`. |
| 261 | - `TestUninstallDeletesInstanceKeepsNothingInBase`: `DeleteInstance` is called with the host, and the install row is gone. |
| 262 | - `TestEnsureDefaultsInstallsWelcomeOnce`. |
| 263 | - [ ] **Step 2:** Run `go test ./internal/install/`. Expected: FAIL. |
| 264 | - [ ] **Step 3:** Implement. |
| 265 | - `Install`: claim the app (`store.ClaimInstall`), then `SetEnv`, then `CreateInstance`, then the probe, then mark it `installed`, or `failed` with a short message that holds no response body. |
| 266 | - The `kid` is the lowercase hex SHA-256 of `cfg.AssertionKey.SignPub()`. |
| 267 | - Install runs in a goroutine started by the handler; the request doesn't wait for it. |
| 268 | - [ ] **Step 4:** Run the tests again. Expected: PASS. |
| 269 | - [ ] **Step 5:** Commit: "Install and uninstall apps on Base's account". |
| 270 | |
| 271 | ### Task 7: Home, Store and Settings pages |
| 272 | |
| 273 | **Files:** |
| 274 | - Create: `internal/web/{home.go,store.go,settings.go}`, `internal/web/templates/{home.html,store.html,uninstall.html,settings.html}` |
| 275 | - Test: `internal/webtest/home_test.go`, `internal/webtest/store_test.go` |
| 276 | |
| 277 | **Interfaces:** |
| 278 | - Consumes: `web.Installer`, `store.Installs`, `catalog.All`, `install.HostFor`. |
| 279 | |
| 280 | - [ ] **Step 1: Write failing tests.** |
| 281 | - `TestHomeGreetsByTimeOfDay`: with a fixed clock at 09:00 in `Europe/London`, the page shows "Good morning, Paul." The name is the member's `Name`, or else the email's local part capitalised. |
| 282 | - `TestHomeSteps`: a fresh Base shows "Signed in" done and the other two steps not done. After an invitation and an installed non-default app, all three are done. |
| 283 | - `TestHomeTilesLinkToOrigins`: each `installed` app's tile is `<a href="https://acme-scratchpad.bab.oncarlos.com/">` with its tint class. Apps still `installing` or `failed` show no tile. |
| 284 | - `TestStoreInstallButtonPostsAndRedirects`: an owner's POST to `/store/scratchpad/install` calls `Installer.Install` and answers 303 to `/store`. |
| 285 | - `TestStoreShowsInstallingWithRefresh`: while an app is `installing`, the page has `<noscript><meta http-equiv="refresh" content="2"></noscript>` and the button is disabled. |
| 286 | - `TestStoreShowsFailedWithRetry`. |
| 287 | - `TestUninstallNeedsConfirm`: `GET /store/scratchpad/uninstall` shows the exact confirmation copy from Global Constraints. Only a `POST` uninstalls. |
| 288 | - `TestMemberSeesStoreButCannotInstall`: there's no install button for a member, and their POST gets 403. |
| 289 | - [ ] **Step 2:** Run `go test ./internal/webtest/ -run 'TestHome|TestStore|TestUninstall|TestMember'`. Expected: FAIL. |
| 290 | - [ ] **Step 3:** Implement against the mockup's markup and classes. "Ask Base anything" is drawn but inert: a disabled field with a `title` saying it arrives later. Settings shows the Base name, the signed-in address and Sign out. |
| 291 | - [ ] **Step 4:** Run the tests again. Expected: PASS. |
| 292 | - [ ] **Step 5:** Commit: "Add Home, Store and Settings". |
| 293 | |
| 294 | ### Task 8: Issuer: assertions for installed apps |
| 295 | |
| 296 | **Files:** |
| 297 | - Create: `internal/issuer/issuer.go`, `internal/issuer/templates/handoff.html` |
| 298 | - Modify: `internal/web/app.go` (mount `GET /authorize` behind `RequireSession`) |
| 299 | - Test: `internal/issuer/issuer_test.go` |
| 300 | |
| 301 | **Interfaces:** |
| 302 | - Consumes: `web.CurrentMember`, `store.Installs`, `install.HostFor`, `cfg.AssertionKey`. |
| 303 | - Produces: |
| 304 | - `GET /authorize?consumer=<app>&nonce=<n>` renders `handoff.html`: a form that POSTs a field `assertion` to `{aud}/auth/assertion`, with a Continue button and a deferred script that submits it. |
| 305 | - The claims: |
| 306 | - `iss` = Base origin, `aud` = the app's origin, `sub` = `Member.ID`. |
| 307 | - `nonce` = the request's nonce; `jti` = `assertion.RandomID()`. |
| 308 | - `iat` = now, `exp` = now + 120, `auth_time` = the session's sign-in time. |
| 309 | - `Ext` = `{"name":…, "email":…, "base":cfg.Name}`. |
| 310 | |
| 311 | - [ ] **Step 1: Write failing tests.** |
| 312 | - `TestAuthorizeSignsForInstalledApp`: a verifier built with `assertion.NewVerifier(base, app, keys)` accepts the posted token. `aud`, `sub` and `nonce` match. |
| 313 | - `TestAuthorizeRefusals`, a table test. Each case gets 4xx and no assertion in the body: |
| 314 | - no session: redirect to sign-in |
| 315 | - unknown consumer |
| 316 | - consumer known but not `installed` |
| 317 | - missing or malformed nonce |
| 318 | - member removed after signing in |
| 319 | - [ ] **Step 2:** Run `go test ./internal/issuer/`. Expected: FAIL. |
| 320 | - [ ] **Step 3:** Implement with `assertion.Sign(cfg.AssertionKey, claims)`. The handoff page sets `Cache-Control: no-store`. |
| 321 | - [ ] **Step 4:** Run the tests again. Expected: PASS. |
| 322 | - [ ] **Step 5:** Commit: "Issue identity assertions to installed apps". |
| 323 | |
| 324 | ### Task 9: Consumer package, Scratchpad and Welcome |
| 325 | |
| 326 | **Files:** |
| 327 | - Create: |
| 328 | - `internal/consumer/{consumer.go,migrations/0001_consumer.sql}` |
| 329 | - `internal/scratchpad/{scratchpad.go,templates/notes.html,migrations/0001_notes.sql}` |
| 330 | - `internal/welcome/{welcome.go,templates/welcome.html}` |
| 331 | - `cmd/scratchpad/main.go`, `cmd/welcome/main.go` |
| 332 | - Test: `internal/consumer/consumer_test.go`, `internal/scratchpad/scratchpad_test.go`, `internal/e2e/handoff_test.go` |
| 333 | |
| 334 | **Interfaces:** |
| 335 | - Produces: |
| 336 | - `consumer.Load(getenv) (consumer.Config, error)`: reads the four `BASE_APP_*` variables and builds the `assertion.Verifier`. |
| 337 | - `consumer.Mount(r chi.Router, db *sql.DB, cfg consumer.Config, sess *sessions.Manager)`, which mounts: |
| 338 | 1. `GET /auth/start?return_to=`: sets a `__Host-base-pending` cookie holding the nonce, then 303 to `{issuer}/authorize?consumer=…&nonce=…`. |
| 339 | 2. `POST /auth/assertion`: requires `Origin` to equal the issuer, verifies the token, stores it pending, then 303 to `/auth/finish`. |
| 340 | 3. `GET /auth/finish`: compares the nonce with `subtle.ConstantTimeCompare`, atomically consumes the pending row and records the `jti`, then starts the session. |
| 341 | - `consumer.Require(next http.Handler) http.Handler`: an unauthenticated request redirects to `/auth/start`. |
| 342 | - `consumer.Person(r) (sub, name, base string, ok bool)`. |
| 343 | - Lifetimes: pending 600 s, inbox 120 s, as in home's `handoff/store.go:40-48`. |
| 344 | |
| 345 | - [ ] **Step 1: Write failing tests.** |
| 346 | - `TestHandoffEndToEnd` (in `internal/e2e`): seed Scratchpad as `installed` with `store.ClaimInstall` and `store.SetInstallState`, then build the Base app (Task 3 harness) and the Scratchpad app in-process. Base's origin is `https://base.test` and Scratchpad's is `https://acme-scratchpad.test`; requests use those `Host` values. A cookie jar shared per origin drives start, authorize, assertion and finish. Scratchpad's page then shows "Signed in as Paul, Acme Ltd". |
| 347 | - `TestAssertionReplayRefused`: posting the same assertion a second time gives no session. |
| 348 | - `TestAssertionExpiredRefused`: verifying at `iat + 121` gives no session. |
| 349 | - `TestAssertionWrongOriginRefused`: a POST with `Origin` other than the issuer gets 403. |
| 350 | - `TestSessionOutlivesBase`: after the handoff, Base's handler is replaced with one that always gives 503. Scratchpad's `/` still answers 200 for the signed-in person. |
| 351 | - `TestNotesSharedAcrossMembers`: two people's sessions see the same notepad text after one saves. |
| 352 | - [ ] **Step 2:** Run `go test ./internal/consumer/ ./internal/scratchpad/ ./internal/e2e/`. Expected: FAIL. |
| 353 | - [ ] **Step 3:** Implement. |
| 354 | - Scratchpad is one page with a `<textarea>` form that saves the shared note, plus the signed-in line. |
| 355 | - Scratchpad's access rule (spec 1.7: the app decides): anyone the configured Base vouches for may read and write. Say so in a code comment and in its README section. |
| 356 | - Welcome is one page: a greeting, the Base name, and a link back to Home. |
| 357 | - Both use the `look` package, so they share the atmosphere. |
| 358 | - [ ] **Step 4:** Run the tests again. Expected: PASS. |
| 359 | - [ ] **Step 5:** Commit: "Add the consumer side, Scratchpad and Welcome". |
| 360 | |
| 361 | ### Task 10: Passkeys on Base sign-in |
| 362 | |
| 363 | **Files:** |
| 364 | - Modify: `internal/web/signin.go`, `internal/web/templates/signin.html`, `internal/store/migrations/` (add passkey schema via `passkey.Schema` in `BootSchema`) |
| 365 | - Test: `internal/webtest/passkey_browser_test.go` (`//go:build browser`) |
| 366 | |
| 367 | **Interfaces:** |
| 368 | - Consumes: `rastrillo/passkey`: `New`, `DiscoverBegin`/`DiscoverFinish`, `RegisterBegin`/`RegisterFinish`, `JS()`. Wiring follows rastrillo's `skill/signin.md` ("Sign-in screen") and `docs/site/passkeys.md`. |
| 369 | |
| 370 | - [ ] **Step 1: Write a failing browser test.** `TestPasskeyRegisterThenSignIn`, using `rastrillo/harness` with a virtual authenticator: |
| 371 | 1. The owner signs in by email. |
| 372 | 2. They add a passkey from Settings. |
| 373 | 3. They sign out. |
| 374 | 4. They sign in with "Use a passkey". |
| 375 | - [ ] **Step 2:** Run `RASTRILLO_CHROME=$(which chromium) go test -tags browser ./internal/webtest/ -run TestPasskey`. Expected: FAIL. |
| 376 | - [ ] **Step 3:** Implement. With scripts off, the passkey button is hidden and email sign-in still works. |
| 377 | - [ ] **Step 4:** Run the test again. Expected: PASS. Also run the non-browser suite. |
| 378 | - [ ] **Step 5:** Commit: "Sign in to Base with a passkey". |
| 379 | |
| 380 | ### Task 11: Release, operator script and live check |
| 381 | |
| 382 | **Files:** |
| 383 | - Create: `scripts/prepare-apps.sh`, `README.md` |
| 384 | - Modify: `Makefile` (release builds `base`, `scratchpad` and `welcome` for linux/arm64) |
| 385 | |
| 386 | - [ ] **Step 1:** Write `scripts/prepare-apps.sh <account> <release-dir>`. For each catalogue ID it runs: |
| 387 | 1. `carlos apps create` |
| 388 | 2. `carlos deploy --app <id> --account <account> --channel stable` with the binary |
| 389 | 3. `carlos instances enable --app <id>` |
| 390 | |
| 391 | It stops on the first failure. Re-running it is safe: steps that are already done are skipped. |
| 392 | - [ ] **Step 2:** Write the README with humane-docs: what Base is, local run (`run.sh` plus `carlos devbox share --port` for HTTPS origins), deploying, the operator's one-time steps, and the four `BASE_APP_*` variables an app must read. |
| 393 | - [ ] **Step 3:** Run `make ci`. Expected: PASS. Run the browser suite once. |
| 394 | - [ ] **Step 4: Live check** on a flagship account Paul names (never on `main`'s behalf without asking): |
| 395 | 1. Deploy Base to the `edge` channel. |
| 396 | 2. Run `prepare-apps.sh`. |
| 397 | 3. Sign in as owner and invite a second address. |
| 398 | 4. Install Scratchpad, open it, and confirm "Signed in as". |
| 399 | 5. Write a note, uninstall, then install again. Confirm the note is back. This settles the spec 5.6 question about the parked database. If the note is gone, file the Platform request from spec section 9; don't work around it. |
| 400 | 6. Record the results in `docs/live-check.md`. |
| 401 | - [ ] **Step 5:** Commit: "Add release, operator script and README". |
| 402 | |