diff --git a/CLAUDE.md b/CLAUDE.md index 78b4866..98c6a00 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -88,12 +88,12 @@ Where to look first: - `internal/api` (`audit.go`): the audit log. Each changing handler records its change after it succeeded (`handler.audit` with an `auditChange`: resource, action, record id and name, projects, and views of the record before and after, `projectAudit`, `userAudit`, `connectionAudit`, `issueAudit`, `logAudit`, of which `services.AuditDiff` keeps the fields that differ and drops secret-named ones; `Replaced` puts `store.AuditReplaced` for a password or chat token that changed; a DSN reset keeps the old and the new DSN, field `dsn`), as `Call.Viewer` (email, role) or the API token, with `Call.Agent` (MCP: the grant's name) and `Call.IP` (`server.ClientIP`). Not recorded: own-account changes, test messages, refusals; an edit that changed nothing. The first admin's setup is recorded by `services.Users.SetupAdmin`. One request is one entry: a request that changed several records keeps them as `Items` (`store.AuditItem`), listed with `item_count` and a `record_name` such as "3 issues" (`itemsName`). `list_audit` (MCP and the web app) and `count_audit` read it through `services.Audit`, `list_audit_choices` (the web app) its filters' choices from tallies per project and resource, action and user (`auditTallies`, recounted once on databases from before them; `services.Audit.Choices`: the viewer's projects, of none only with every project, and the users they see; per project, so a rare entry spanning a project a limited viewer lacks can offer a value that matches nothing), `exists` saying the web app may link the record, and `get_audit_entry` (MCP and the web app) one entry with its items; an entry is seen by `AuditEntry.VisibleTo` (one record: all its projects within access; several: any item within it), trimmed to the viewer's items by `ShownTo` (403 outside it). A viewer who does not administer sees who acted only for the users they see (`AuditFilter.Actors`, `User.SeesUser`; `ShowsActor`): others are "Admin" or "User", without id, email, address or agent, and never found by `query` or `user_id`; agents never get the address. No endpoint changes it (`TestAuditTransports`). `audit_test.go` covers each action, secrets, visibility, actors and transports. - `internal/api` (`rest.go`, `NewREST`): serves the catalog under `/api/v1/` behind `protectAPI`: `GET` with query parameters when `ReadOnly` (converted with `Endpoint.FieldType`; lists repeated or comma-separated; unknown parameters 400), `POST` with a JSON object otherwise (`api.Route(transport, endpoint)`, the prefix from the transport; a body over 64 KiB 413; the other method at an endpoint's path 405 with `Allow`, `wrongMethod`, after the caller is checked). Routes are registered one by one by `register` (a subtree would overlap `/api/{projectID}/envelope/`, so names must never be `envelope`, `TestEndpointNames`); the HTTP transports share `serve` (the caller first, then the role, before the input is read, then the input and the run) and `fail`. Actor "API token" (`store.SourceAPI`). - `internal/api` (`ui.go`, `NewUI`): serves the catalog to the web app under `/api/ui/`, as the user of the login session (`SessionUsers`, the `session.Auth`): no valid session 401 `login required`, a session that could not be checked 500 (never a login loop). `guard` wraps every route and the fallback (`UI.ServeHTTP`: an unknown name 404 after the session check): `SecurityHeaders` with `default-src 'none'; frame-ancestors 'none'; sandbox`, `Cross-Origin-Resource-Policy: same-origin`, `Sec-Fetch-Site` cross-site or same-site 403, a change needs `application/json` (415) and a same-origin `Origin` (403); no CORS ever. The plain requests' handlers sit behind the same `guard` and the IP allowlist (`TestUIPlainRequests`). Actor the user with `store.SourceUI`; text unredacted (the user's own server). The API token, MCP tokens and the session never open each other's transports (`TestUIRequiresSession`). -- `internal/api` (`mcp.go`, `NewMCP`): MCP server for coding agents at `/mcp` (official `github.com/modelcontextprotocol/go-sdk`, Streamable HTTP, stateless, JSON responses; `run` recovers a panicking tool (`logging.PanicError`) into "internal error", since the SDK runs tools in goroutines without a recover; the SDK's localhost protection is off because a reverse proxy on the same host would trip it, and a token is required anyway). Behind `ALLOWED_IPS`, then `oauth.Protect` (OAuth access token or the personal token; `API_TOKEN` is the REST API's only). Tools are the catalog endpoints an agent's user may use, plus `fetch_skill` (agent only, `skills.go`), registered with `Server.AddTool` and the endpoint's schema: one `sdk.Server` per role, built at startup; `withCaller` (after `oauth.Protect`) reads the grant's user from the store at every request, so a role change applies at once (a deleted user 401 as an invalid token, `oauth.RefuseToken`; a failed read 500), and puts the `api.Call` into the context, which picks the server and reaches the tool handlers. `list_issues`, `get_issue` (latest or given event as the full agent prompt, `agentprompt.Build(services.AgentInput(...))` with up to 20 related logs), `get_issues` (`missing_issue_ids` apart from `forbidden_issue_ids`, other projects') and `update_issue_status` (1–100 IDs, `store.NormalizeIssueIDs`; the update is atomic: a hidden ID (403, checked first) or a missing one (404, named) changes nothing; recorded in the history as the grant's user, the call's `Actor`, found through `oauth.GrantOf(auth.TokenInfoFromContext(...))`, since `oauth.Protect` hands the grant to the SDK as its `auth.TokenInfo`), `delete_issue` (admins, destructive; also REST), `list_issue_events`, `get_event`, `list_logs` (`trace_id` for one request; a search that ran out of time says `stopped` and goes on by `next_cursor`), `list_projects` (with each project's `dsn`: `withCaller` puts the server address, `server.PublicURL`, into `Call.Address` and `config.Project.DSN` builds it, the same function as the Projects page), `fetch_skill`. Output goes to the agent's model provider: text is redacted (`ForAgent()`), raw payloads and log attributes are never returned. `instructions.md` (sent with every connection, kept short) gives the workflow and lists the skills; `skills/*/SKILL.md` are loaded on demand by `fetch_skill` (their names and descriptions come from their front matter), one topic each, no rule repeated between them and the instructions. Notifications carry ` MCP: get_issue {"issue_id":"k3x9q2mf"}` (`notify.mcpReference`, built by `agentprompt.MCPReference`). +- `internal/api` (`mcp.go`, `NewMCP`): MCP server for coding agents at `/mcp` (official `github.com/modelcontextprotocol/go-sdk`, Streamable HTTP, stateless, JSON responses; `run` recovers a panicking tool (`logging.PanicError`) into "internal error", since the SDK runs tools in goroutines without a recover; the SDK's localhost protection is off because a reverse proxy on the same host would trip it, and a token is required anyway). Behind `ALLOWED_IPS`, then `oauth.Protect` (OAuth access token or the personal token; `API_TOKEN` is the REST API's only). Tools are the catalog endpoints an agent's user may use, plus `fetch_skill` (agent only, `skills.go`), registered with `Server.AddTool` and the endpoint's schema: one `sdk.Server` per role, built at startup; `withCaller` (after `oauth.Protect`) reads the grant's user from the store at every request, so a role change applies at once (a deleted user 401 as an invalid token, `oauth.RefuseToken`; a failed read 500), and puts the `api.Call` into the context, which picks the server and reaches the tool handlers. `list_issues`, `get_issue` (latest or given event as the full agent prompt, `agentprompt.Build(services.AgentInput(...))` with up to 20 related logs), `get_issues` (`missing_issue_ids` apart from `forbidden_issue_ids`, other projects') and `update_issue_status` (1–100 IDs, `store.NormalizeIssueIDs`; the update is atomic: a hidden ID (403, checked first) or a missing one (404, named) changes nothing; recorded in the history as the grant's user, the call's `Actor`, found through `oauth.GrantOf(ctx)`, the grant `oauth.Protect` put into the request), `delete_issue` (admins, destructive; also REST), `list_issue_events`, `get_event`, `list_logs` (`trace_id` for one request; a search that ran out of time says `stopped` and goes on by `next_cursor`), `list_projects` (with each project's `dsn`: `withCaller` puts the server address, `server.PublicURL`, into `Call.Address` and `config.Project.DSN` builds it, the same function as the Projects page), `fetch_skill`. Output goes to the agent's model provider: text is redacted (`ForAgent()`), raw payloads and log attributes are never returned. `instructions.md` (sent with every connection, kept short) gives the workflow and lists the skills; `skills/*/SKILL.md` are loaded on demand by `fetch_skill` (their names and descriptions come from their front matter), one topic each, no rule repeated between them and the instructions. Notifications carry ` MCP: get_issue {"issue_id":"k3x9q2mf"}` (`notify.mcpReference`, built by `agentprompt.MCPReference`). - `internal/oauth`: how agents sign in to MCP; `server.Options.OAuth` mounts its endpoints. OAuth 2.1 for public clients: discovery (`/.well-known/oauth-protected-resource`, `oauth-authorization-server` and `openid-configuration`, each with or without the MCP path), client identification by a Client ID Metadata Document (`clientmetadata.go`: a `client_id` that is an https URL is the client's published JSON with its name and redirect_uris, fetched at every authorization and never stored; the fetch reaches only public addresses, checked after DNS resolution in the dialer's `Control`, no redirects, no keep-alive, 5 s, 5 KB; the consent page shows the publishing host; `Server.MetadataClient` points tests at a local server) or dynamic registration (`POST /oauth/register`; clients that never connected go after an hour, and a full table (1024) evicts the oldest unused, answering 429 only when every client is in use; the code carries the client name, so the token exchange needs neither), the consent page `/oauth/authorize`, a page of the web app (`routes/(app)/oauth/authorize`): it sends the query as the agent sent it to the plain request `authorization_request` (`CheckRequest`; a refused request answers 400 with its reason and never a redirect; a valid one gives the client, its site, the redirect URI and a form token bound to the session cookie and the exact request, `Auth.FormToken`), then Allow/Deny to `authorization_decision` (the form token checked, the request checked again, the answer the redirect URL with the code or `access_denied`, which the page opens with `location.assign`); it keeps the app's `frame-ancestors 'none'` and `Referrer-Policy: same-origin`, so the agent never gets its address as a referrer, `POST /oauth/token` (code + S256 PKCE; refresh). Access tokens last an hour, refresh tokens 30 days and are replaced at every use; a spent refresh token presented again (theft) revokes the grant (collection `oauth_spent`). Redirects: https or loopback http, matched exactly except a loopback port. Codes and tokens are random 32 bytes, stored only as SHA-256 hashes; nothing is kept in memory, and one `oauth.Server` built in `app.New` is shared by MCP and the web app (through `services.Agents`). Registration and token requests are rate limited per client network (`server.ClientNetwork`: an IPv4 address or an IPv6 /64; 30 and 120 a minute; past 4096 networks a minute new ones share one overflow count of 10 times that, so a flood of networks is limited without locking out those counted), registrations also by a total of 120 a minute (each is a synced write; tokens have none, so connected agents keep refreshing), the client table is capped, and browser requests must come from the server's own origin. A grant is a connected agent or a personal token (one per user, shown once after Generate/Regenerate) and acts for a user (the grant's user id, from the code of the user who allowed it; a grant without a user does not work). Deleting a user or a password reset on the Users page disconnects their agents; changing your own password or the `reset-password` command keeps them. The web app's page `/agents` ("MCP" in the menu; `routes/(app)/agents`, `McpSetup`, `ConnectedApps`) has Claude Code / Codex / Other tabs (`?client=`) from `get_mcp_setup` (`services.Agents.Setup`: the endpoint `Server.ResourceAt(Call.Address)`, the commands, `.mcp.json`, `token_set`, `unencrypted` (`oauth.Unencrypted(address)`: agents would reach the server over plain HTTP from another machine), `ips_restricted`), the viewer's personal token (plain request `personal_token`, `services.Agents.NewPersonalToken`: the token and a setup prompt that has an agent add the server with it at user level and check it with `list_projects`, kept only in the component), and the connected apps of `list_agents` (`connected`, `store.Grant.Connected`: an unused personal token is no app) with Disconnect; admins choose whose apps from `owners` (`?user=`; one they may not take over is a 403 with the reason, an unknown one a 404). - `internal/services`: the rules and every database access of the web app's pages and the agents' tools (the catalog of `internal/api`), built together by `services.New` (`services.All`), once in `app.New` and passed to `api.Endpoints`; every method reading project data takes a `store.Access` after `ctx`, or a record read through one (an issue: `SelectedEvent`, `History`; connections: `DeliveryHealth`, `SetActive`, `SendTest`) (changes where the role matters take the viewer: `Projects.Save`, `Issues.ApplyAction` and `Users` use its `ProjectAccess()`, `Logs.Delete` takes the access beside it), and a record asked for outside it is `services.ErrHidden` (403), a missing one `store.ErrNotFound` (`Projects.Check`/`Find`, `Issues.Get`, `Connections.Get`; lists only leave it out: `Access.Restrict`: a filter that cannot match answers empty without the store, whose empty project filter means any; `services.Visible`: a connection whose projects are all within access, one for every project or none only with every project; `Deliveries` only of visible connections and about projects within access, a hidden `connection_id` 403; a duplicate destination of a hidden connection is refused without naming it); a change of several steps (a chat destination plus its connection, a replaced secret plus the save, find-or-create an email destination) is one service method. `Issues` (list/count/get/get many, events, recent events, `SelectedEvent`, `Details` (the issue page, `issue_details.go`), `ApplyAction`/`SetStatus`/`Delete`, related logs, agent prompt), `Logs` (list/count, issues of logs, `Delete`, `ErrForbidden` without `CanAdminister`), `Projects` (names, DSN, color, `ColorsByName`, unresolved counts, database size and each project's part, setup code per platform (`project_setup.go`, the one source); `Get`/`Save`/`Delete` and `FormValues`, the project form's rules in `project_form.go`), `Connections` (list, delivery health, get, `Save` (create or update from the form, `connection_form.go`: rule fields, chat secrets, availability, the confirmed address, duplicates, default name), `New` (a new connection's defaults), `FormValues`, `SetActive`/`SendTest` (`store.ErrNotVerified` for an unconfirmed address), `TestChat`, `RetryNow`, `Delete`), `Deliveries` (the outbox for the delivery log), `Verification` (email destinations, `StartEmail` (also to send a code again)/`ConfirmCode`, codes, `ResendCooldown`), `Users` (`SetupAdmin`, the first admin, and `LogSetup`, create with a temporary password, update, reset password, delete, own name; each checks the viewer's role and returns `ErrForbidden` with its reason, a role the viewer may not give or access they may not change a `Refusal` at the field; `DeviceStamp` for the login's known device), `Agents` (`Setup`, `Page`: whose agents to list; `NewPersonalToken` with its setup prompt; disconnect; consent: `CheckRequest`/`Decide`), `Sessions` (the logins, for `session.Auth`), `Audit` (`Record`: a failed write is logged, never the change's error; `List`/`Count` within an access; `AuditFields`/`AuditDiff`). Package tests use a real temp database. - `internal/session`: the login of the web app, `session.Auth`, built once in `app.New` and passed to `api.NewUI` and the plain requests (sessions of users, `CookieName`, `User` (`store.ErrNotFound` without a valid session, other errors as they are), `SessionUser`, `ChangePassword` (own password: the current password counts against the login limit, `withCurrentPassword`), `Login` returning `LoginOK`/`LoginWrongCredentials`/`LoginBlocked` with the login limit inside, `EndSession`, `Disabled` (no admin), `FormToken`/`ValidFormToken` (the consent page's, bound to the session cookie and an action); sessions are stored through `services.Sessions`), the login limit (`loginLimiter`: an attempt is counted before its password is checked, under one lock, so concurrent attempts cannot pass it; a known device (cookie `exceptic_device`: any browser the user logged in from, holding the last user who logged in there; `expires.user.stamp`, HMACs of the expiry with the email, checked before the database is read so a made-up cookie tells nothing by timing, and with `services.Users.DeviceStamp` (a hash of the user's ID, role and password hash, so a password change or reset, a role change or deletion ends it; the hash never leaves services) under a key derived from `SECRET_KEY`/`secret.key`, set at every login and own password change) gets 10 per 15 minutes per network and email and 30 per email from all networks, so strangers cannot lock its owner out; any other attempt counts per client network (`server.ClientNetwork`) and per email, 10 each; the right password clears the network's count only when all its attempts in the window were at that email, otherwise it takes only itself off (an insider cannot reset guesses at others); the counters live in memory, a key for its 15-minute window (swept every minute), and past 10k keys (`maxLimiterKeys`) a new network or email is refused until windows end, with a warning once per window, while known devices go on; at most half the cores (at least one) run password checks plus one place for known devices (`waitForCheck`), and an attempt waits at most 5 s (`passwordCheckWait`) before it is refused as `LoginBlocked`; `docs/deployment.md`, Securing it). Passwords are checked by `services.Users` (`Authenticate`, which checks unknown emails and users without a password hash against a dummy hash, for equal timing, and opens neither, and `ChangeOwnPassword`); the password primitives stay private to `services`, so nothing outside it can set a password without the role checks of `Users`. - Users and roles: nothing creates users at start (`app.New` only logs, `services.Users.LogSetup`, how to set up an admin while there is none). While there is no admin, a login with `ADMIN_EMAIL`/`ADMIN_PASSWORD` (`session.Auth.Login`: through the same login limit and password-check places, after `Authenticate` fails; both compared in constant time and the admins read whatever was typed, `setupLogin`) starts no session but answers `LoginOutput.setup` and sets `exceptic_setup` (`internal/session/setup.go`: HttpOnly, SameSite=Strict, path `/api/ui/setup_admin`, 10 minutes, HMAC of its expiry and the env credentials under the device key), which opens the plain request `setup_admin` (`{email, password, confirm_password}`, problems at fields; without a valid cookie 403 `ErrSetupExpired`): `services.Users.SetupAdmin` (a real email, the password rules, not `ADMIN_PASSWORD`) and `store.CreateFirstAdmin`, which checks in the insert's batch that there is still no admin (`store.ErrAdminExists`, 403 `AdminExistsProblem`), then a new session; the login page swaps to `SetupAdminForm`. Once an admin exists the env credentials are a wrong login like any other. Unset, they are `exceptic`/`exceptic` (`config.DefaultAdminEmail`, `DefaultAdminPassword`); `ADMIN_PASSWORD` takes any length, the admin's own password follows the rules. What each role may do is the methods of `store.User`, enforced by the catalog (`Admin`, `AllowedFor`) and services and shown by the web app from `get_session`'s `can_administer` and the rows' `can_manage`: admin everything (every project, other admins too, deleting projects, issues and logs, the disk share); user projects, notifications, the users of the role user they see (docs/ui.md Users), issue statuses, logs and their own MCP agents, each within their project access (a user sees and changes only the part of another user's access within his own: outputs show `Access.Shown`, `get_user` and `list_users` rows have `can_take_over`/`take_over_reason` (`store.User.CanTakeOver`: email, name, role, password, deleting and agents only of a user whose projects he all has, else the email, name and role are field problems, a reset, delete or agent request 403 with `services.TakeOverProblem`; the Users page shows such a row with its actions disabled with the reason (`menu.ts` `unavailable`), its page with only the projects editable) and `access_editable`/`access_reason`; `create_user`/`update_user` take `all_projects` and `projects`, a new user gets the creator's access by default; `store.RoleSummaries`, which deployment.md and the Users page show, says the same). The Users page adds users by email (`config.ParseEmail`, lowercase; no confirmation) with a temporary password shown once (`must_change_password`), changes email, name and role, resets the password, deletes; nobody changes themselves there: `/account` changes your own name and password; the email is set once when the user is added (no endpoint changes it) (the current one required; other sessions end). Session cookie (`HttpOnly`, `SameSite=Lax`, `Secure` behind HTTPS or always with an https `PUBLIC_URL` (`Auth.secure`, so TRUSTED_PROXIES is needed only for client addresses), valid `SESSION_LIFETIME`), its SHA-256 stored in `session` with the user; a login always issues a new session and deletes the one the browser had. Full-server tests add users with `webUser` (`internal/api/ui_test.go`, a session without a password check) and an admin who logs in with `startLoginServer`/`seedAdmin` (`login_test.go`, which lowers `services.PasswordIterations` for the package); `setup_test.go` drives the first-admin setup. -- Google sign-in (`internal/session/google.go`, `GOOGLE_CLIENT_ID`/`GOOGLE_CLIENT_SECRET` with `PUBLIC_URL`, `config.Google`; no library): `GET /auth/google` sends the browser to Google with state, nonce and a PKCE S256 challenge whose secrets stay in a cookie signed with the device key (`exceptic_google`, path `/auth/google`, Lax, 10 minutes); `config.GoogleRedirectPath` checks the state, exchanges the code (client secret by HTTP Basic, no redirects followed), checks the ID token's claims (iss, aud, exp, nonce, `email_verified`; no signature check: it comes straight from Google over TLS, OIDC Core 3.1.3.7) and starts a session, or goes to `/login?error=` (`login.ts` `googleRefusal`). `services.Users.GoogleSignIn`: the user linked by `sub` (unique `google` index), else the user of the verified email, linked then by `Store.LinkGoogle`, which checks in its batch that the email is still theirs, no other account is linked (`ErrGoogleLinked`, result `not_linked`) and Google was not unlinked (`User.GoogleLinkOff`, `ErrGoogleOff`, result `unlinked`, cleared by a password sign-in, `RecordLogin`). `unlink_google` drops the link and disconnects the sessions opened through Google (`deleteGoogleSessions`, the viewer's own kept); an email never changes, so nothing else unlinks. Any Google-verified email links, Workspace and other domains too (the risk is in docs/deployment.md, the user's decision). Sessions record method, address, browser and last activity (`TouchSession` at most every `store.SessionActiveEvery`, also `User.LastActiveAt`; `Auth.touched` capped). The sign-in log (collection `signin`, `store.SignIn`): every attempt at an existing user, the newest `store.SignInsKept` sign-ins and as many refusals apart, so refusals never push a sign-in out; refusals are written apart from the answer (timing), at most `maxRecording` at once (more dropped), a blocked attempt once per network and email in a window (`loginLimiter.firstBlock`); rows of a user deleted meanwhile are not written. `get_activity`/`end_session`/`unlink_google` (`api/activity.go`, the web app only): viewing needs `CanManage` (or oneself), changing `CanTakeOver`; nobody disconnects the session they use (`Call.Session`, `store.SessionID`). `get_session` answers a temporary password without the projects' data (no unresolved count or colors). +- Google sign-in (`internal/session/google.go`, `GOOGLE_CLIENT_ID`/`GOOGLE_CLIENT_SECRET` with `PUBLIC_URL`, `config.Google`; the code flow through `golang.org/x/oauth2`, the ID token's claims checked by hand): `GET /auth/google` sends the browser to Google with state, nonce and a PKCE S256 challenge whose secrets stay in a cookie signed with the device key (`exceptic_google`, path `/auth/google`, Lax, 10 minutes); `config.GoogleRedirectPath` checks the state, exchanges the code (`oauth2.Config.Exchange`, client secret by HTTP Basic, `AuthStyleInHeader`, through a client that follows no redirects), checks the ID token's claims (iss, aud, exp, nonce, `email_verified`; no signature check: it comes straight from Google over TLS, OIDC Core 3.1.3.7) and starts a session, or goes to `/login?error=` (`login.ts` `googleRefusal`). `services.Users.GoogleSignIn`: the user linked by `sub` (unique `google` index), else the user of the verified email, linked then by `Store.LinkGoogle`, which checks in its batch that the email is still theirs, no other account is linked (`ErrGoogleLinked`, result `not_linked`) and Google was not unlinked (`User.GoogleLinkOff`, `ErrGoogleOff`, result `unlinked`, cleared by a password sign-in, `RecordLogin`). `unlink_google` drops the link and disconnects the sessions opened through Google (`deleteGoogleSessions`, the viewer's own kept); an email never changes, so nothing else unlinks. Any Google-verified email links, Workspace and other domains too (the risk is in docs/deployment.md, the user's decision). Sessions record method, address, browser and last activity (`TouchSession` at most every `store.SessionActiveEvery`, also `User.LastActiveAt`; `Auth.touched` capped). The sign-in log (collection `signin`, `store.SignIn`): every attempt at an existing user, the newest `store.SignInsKept` sign-ins and as many refusals apart, so refusals never push a sign-in out; refusals are written apart from the answer (timing), at most `maxRecording` at once (more dropped), a blocked attempt once per network and email in a window (`loginLimiter.firstBlock`); rows of a user deleted meanwhile are not written. `get_activity`/`end_session`/`unlink_google` (`api/activity.go`, the web app only): viewing needs `CanManage` (or oneself), changing `CanTakeOver`; nobody disconnects the session they use (`Call.Session`, `store.SessionID`). `get_session` answers a temporary password without the projects' data (no unresolved count or colors). - Logs are tied to an error by span, not by trace (a browser keeps one trace for the whole tab, so every request from it shares the trace): a log belongs to an event if it has the same `trace_id` and its `span_id` (from the `sentry.trace.parent_span_id` attribute) is the event's `span_id` or `parent_span_id`. Without a span match the issue page (`get_issue_details`) falls back to logs of the same trace within a minute of the error, by the server's time or the device's (log batches without `sent_at` keep it), and says so (`logsAround`: one search over both, since dates also bound a search by arrival, keeping only the logs near either time; `ClockDrift` is 0 for a time ingest replaced). - `web/` (repo root): the web UI, a SvelteKit 3 + Tailwind 4 SPA. The folder is both the Node project (pnpm, version in `packageManager`; Kit 3 keeps its config in `vite.config.ts`, the `#lib` alias is a package.json import) and Go package `web` (`web.go`): `//go:embed all:dist` with a committed `dist/.gitkeep`, so Go builds and tests need no Node, and adapter-static writes `dist/spa` (an SPA: `ssr = false`, fallback `200.html`). `main` builds it (`web.New`; without a build it warns and no web UI is served) and passes it to `app.New` as `Options.Web`; full-server tests pass `fixtures.WebApp`, a stand-in build. The app (`web.App.Register`, the `/` pattern, behind the IP allowlist) takes every address no other route does; other methods than GET/HEAD there answer 404. `App.serve`: files under `_app/immutable/` cached for good, other built files `no-cache`, a missing `_app/` file 404, any other address the page (`no-store`). Strict CSP: Go hashes the page's inline scripts at start (SvelteKit boots with one, whose text changes every build) into `script-src`; no inline styles, so `app.html` uses classes and the inline style of Kit's `#svelte-announcer` is removed by `web/patches/@sveltejs__kit.patch` (`pnpm patch`; an update it no longer applies to fails the install), the element styled in `layout.css`. TypeScript 6: the npm package of TypeScript 7 has no compiler API, which svelte-check, Kit and typescript-eslint need (checked 2026-11-20). `make dev` (`tools/dev.sh`) puts Vite on PORT (8000) and the Go server on the next port (`EXCEPTIC_URL`); Vite proxies the server's own addresses (`/api/`, `/mcp`, `/health`, `/oauth/token|register|jwks`, `/.well-known/`, `/unsubscribe/`) to it without changing Host, so DSNs, OAuth and the Origin check see :8000. - Loading: no request holds back the app's render. Every load is `deferred` (`#lib/deferred.ts`: it returns `{ loaded }`, its data unawaited); `+page.svelte` is a thin wrapper rendering it through `Loaded` (`Loading`, the `LoadingBar` of a busy Table, after a moment; the last data kept while the next loads; a refusal as the error page; a `redirect()` followed) into the page's own component beside it (`IssuesPage.svelte`, typed `Awaited`); a list's slow count and rows are a nested promise read with `Pending` (`#lib/pending.svelte.ts`), the Table busy meanwhile. @@ -107,7 +107,7 @@ Where to look first: - Rules: no `style` attribute (eslint; the `style:` directive is fine) and no `{@html}`; queries with `URLSearchParams` (`withQuery`), never by concatenation; no link takes its address from event data (event values go only into the app's own addresses, as `withQuery` parameters); a link to an address from event data would have to allow only http(s) or relative ones; secrets (temporary passwords, personal tokens) only in component or module memory, never in the address or storage; the page keeps `Referrer-Policy: same-origin` (`server.SecurityHeaders`), which the Origin check of `/api/ui` depends on. `src/error.html` is the page shown when the app cannot start (no `