@mostra/runtime 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1194,8 +1194,8 @@
1194
1194
  "phase": "host",
1195
1195
  "title": "Too many runs wait for the owner",
1196
1196
  "hint": "Wait for the owner to come back and work through its queue, then press again.",
1197
- "explanation": "The artifact's owner instance is offline and as many runs as the server allows already wait for it, so this one was refused before anything was recorded. Runs already waiting keep their place.",
1198
- "fix": "Bring the owner instance back online: waiting runs then go out in the order they were made. The cap is the server's `relay.waitingRunsPerArtifact` setting."
1197
+ "explanation": "The artifact's owner instance is offline and as many runs as the server allows already wait for it, or the server's operator allows no more waiting runs for this account now (its `limits` port, `run.wait`, whose message is the operator's own), so this one was refused before anything was recorded. Runs already waiting keep their place.",
1198
+ "fix": "Bring the owner instance back online: waiting runs then go out in the order they were made. The cap is the server's `relay.waitingRunsPerArtifact` setting, or the operator's limit its message names; its `Retry-After`, when present, says when to try again."
1199
1199
  },
1200
1200
  {
1201
1201
  "code": "MOSTRA_REMOTE_RATE_LIMITED",
@@ -12,11 +12,11 @@ Too many runs wait for the owner. Severity: error. Phase: host.
12
12
 
13
13
  ## What it means
14
14
 
15
- The artifact's owner instance is offline and as many runs as the server allows already wait for it, so this one was refused before anything was recorded. Runs already waiting keep their place.
15
+ The artifact's owner instance is offline and as many runs as the server allows already wait for it, or the server's operator allows no more waiting runs for this account now (its `limits` port, `run.wait`, whose message is the operator's own), so this one was refused before anything was recorded. Runs already waiting keep their place.
16
16
 
17
17
  ## How to fix it
18
18
 
19
- Bring the owner instance back online: waiting runs then go out in the order they were made. The cap is the server's `relay.waitingRunsPerArtifact` setting.
19
+ Bring the owner instance back online: waiting runs then go out in the order they were made. The cap is the server's `relay.waitingRunsPerArtifact` setting, or the operator's limit its message names; its `Retry-After`, when present, says when to try again.
20
20
 
21
21
  ## Hint
22
22
 
@@ -39,7 +39,7 @@ The server reads a JSON file (`--config`) and `MOSTRA_SERVER_<KEY>` variables. A
39
39
  | `apiOrigin` | The API origin, `https:` |
40
40
  | `domains.active`, `domains.spares` | The user-content domain new links use, and older ones that issued links keep working on. To move off a domain, make a spare active and restart the server |
41
41
  | `trustedProxies` | Addresses or CIDR ranges whose `X-Forwarded-For` the server believes. It reads the header from the right and takes the first address that isn't a trusted proxy. Rate limits count IPv6 clients per /64 (`rateLimits.ipv6Prefix`) |
42
- | `identityProviders` | How people sign in: `github` (an OAuth app), `oidc` (any OpenID Connect provider: `issuer`, `clientId`, `clientSecretFile`) or `development` (trusts any typed name; for tests only, never on a public server) |
42
+ | `identityProviders` | How people sign in: `github` (an OAuth app), `oidc` (any OpenID Connect provider: `issuer`, `clientId`, `clientSecretFile`) or `development` (trusts any typed name; for tests only, never on a public server). An `oidc` entry's `claims` names up to 8 of its ID token's claims (such as `hd`, a Google Workspace account's domain) that an operator module then reads in the sign-in's `facts`. A page's sender line says the name was verified with the provider's `label`, as recorded when the person signed in, so renaming or removing a provider later leaves names already verified as they were |
43
43
  | `rateLimits` | Rates as `{ "count", "per" }`: `perIp.submissions` and `perLink.submissions` for answers, `perLink.relayedRuns` for actions, and `perIp.requests` for every request an address sends (a health check aside). Past a rate the answer is 429 with `Retry-After`; a page says to try again shortly and keeps the draft. A key left out is no limit |
44
44
  | `relay`, `homes`, `ledger` | The relay's waiting-run cap and drain rate, how long an idle hosted home stays open, and the ledger's WAL checkpoint (`0` for a backup replicator) |
45
45
  | `operator` | The path of an operator module, which adds limits, metering, accounts and abuse handling through the operator ports (`@mostra/protocol/operator`). Without one, every port keeps its no-op default |
@@ -4,7 +4,7 @@ description: Communicate visually with the user through Mostra. Use whenever sho
4
4
  license: Apache-2.0
5
5
  compatibility: Needs a shell that runs `mostra` (or `npx` with Node.js 22.19 or later) on macOS, Linux or Windows, x64 or arm64.
6
6
  metadata:
7
- version: "0.12.0"
7
+ version: "0.13.0"
8
8
  ---
9
9
 
10
10
  # Mostra
@@ -13,7 +13,7 @@ Mostra turns a React page you write into an **artifact**: a web page a person op
13
13
 
14
14
  ## Running Mostra
15
15
 
16
- Run `mostra <command>`. When `mostra` isn't on the `PATH`, run `npx -y @mostra/cli@0.12.0 <command>` everywhere this Skill says `mostra`; the first run downloads Mostra's own runtime (no global Node.js needed beyond `npx`). Every command takes `--json` (one JSON envelope on stdout, logs on stderr) and `--help`. `mostra docs <topic>` prints the reference, including every diagnostic code's page (`mostra docs MOSTRA_FIELD_DUPLICATE_ID`). `mostra list` lists the artifacts you've published, and `mostra status` shows the running instance.
16
+ Run `mostra <command>`. When `mostra` isn't on the `PATH`, run `npx -y @mostra/cli@0.13.0 <command>` everywhere this Skill says `mostra`; the first run downloads Mostra's own runtime (no global Node.js needed beyond `npx`). Every command takes `--json` (one JSON envelope on stdout, logs on stderr) and `--help`. `mostra docs <topic>` prints the reference, including every diagnostic code's page (`mostra docs MOSTRA_FIELD_DUPLICATE_ID`). `mostra list` lists the artifacts you've published, and `mostra status` shows the running instance.
17
17
 
18
18
  When Mostra's tools are in your tool list (`artifact_create`, `artifact_verify` and the rest), use them instead: each step below has its tool, and everything else here holds unchanged. See [references/mcp.md](references/mcp.md).
19
19
 
@@ -59,10 +59,10 @@ A chat app's connector reaches the person's own computer through their Mostra se
59
59
 
60
60
  ## Adding the server to a client
61
61
 
62
- A client starts the server as `mostra mcp` over stdio, or `npx -y @mostra/cli@0.12.0 mcp` where `mostra` isn't installed. Its configuration names that command, for example:
62
+ A client starts the server as `mostra mcp` over stdio, or `npx -y @mostra/cli@0.13.0 mcp` where `mostra` isn't installed. Its configuration names that command, for example:
63
63
 
64
64
  ```json
65
- { "mcpServers": { "mostra": { "command": "npx", "args": ["-y", "@mostra/cli@0.12.0", "mcp"] } } }
65
+ { "mcpServers": { "mostra": { "command": "npx", "args": ["-y", "@mostra/cli@0.13.0", "mcp"] } } }
66
66
  ```
67
67
 
68
68
  For a client that speaks only HTTP, `mostra mcp --http` serves Streamable HTTP on `127.0.0.1` and prints its URL and a token on stderr; every request sends `Authorization: Bearer <token>` (set `MOSTRA_MCP_TOKEN` to choose it). `--workspace <dir>` chooses where new artifacts go.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostra/runtime",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "The Mostra runtime: the supervisor that owns a home, its ledger, its child processes and the host protocol server (mostra-runtime host|daemon).",
5
5
  "license": "Apache-2.0",
6
6
  "author": "The Mostra Authors",
@@ -36,8 +36,8 @@
36
36
  "dependencies": {
37
37
  "@hono/node-server": "2.1.5",
38
38
  "@mdx-js/mdx": "3.1.1",
39
- "@mostra/mcp": "0.12.0",
40
- "@mostra/protocol": "0.12.0",
39
+ "@mostra/mcp": "0.13.0",
40
+ "@mostra/protocol": "0.13.0",
41
41
  "@tailwindcss/vite": "4.3.3",
42
42
  "@vitejs/plugin-react": "6.1.2",
43
43
  "better-sqlite3": "13.0.3",
@@ -60,11 +60,11 @@
60
60
  "@modelcontextprotocol/client": "2.4.0",
61
61
  "@modelcontextprotocol/conformance": "0.1.16",
62
62
  "@modelcontextprotocol/conformance-next": "npm:@modelcontextprotocol/conformance@0.2.0-alpha.12",
63
- "@mostra/shell": "0.12.0",
63
+ "@mostra/shell": "0.13.0",
64
64
  "@mostra/tools": "0.0.0",
65
- "@mostra/verify": "0.12.0",
65
+ "@mostra/verify": "0.13.0",
66
66
  "@mostra/warm": "0.0.0",
67
- "@mostra/worker": "0.12.0",
67
+ "@mostra/worker": "0.13.0",
68
68
  "@types/better-sqlite3": "9.6.0",
69
69
  "@types/node": "24.19.2",
70
70
  "@types/semver": "7.8.0",
@@ -99,7 +99,10 @@ export interface Actions {
99
99
  input: { readonly viewId: string; readonly fnId: string; readonly args: Batches },
100
100
  signal: AbortSignal,
101
101
  ): Promise<AsyncIterable<CallLine>>;
102
- /** Starts or joins a run (AC-02, AC-03); the page follows it from here. */
102
+ /**
103
+ * Starts or joins a run (AC-02, AC-03); the page follows it from here. A hosted home's relay
104
+ * answers asynchronously, since it asks the operator's `limits` before it records a run.
105
+ */
103
106
  startRun(
104
107
  page: PageIdentity,
105
108
  input: {
@@ -109,7 +112,7 @@ export interface Actions {
109
112
  readonly key?: string;
110
113
  readonly clientKey: string;
111
114
  },
112
- ): RunState;
115
+ ): RunState | Promise<RunState>;
113
116
  /** Reads runs and follows them for a minute (re-attach, AC-02). */
114
117
  attach(
115
118
  page: PageIdentity,
@@ -49,9 +49,14 @@ const STATUS: Readonly<Record<string, number>> = {
49
49
  // A hosted page's relay (D165 item 4, INTERFACES §4).
50
50
  MOSTRA_REMOTE_OWNER_OFFLINE: 503,
51
51
  MOSTRA_REMOTE_QUEUE_FULL: 503,
52
+ MOSTRA_REMOTE_LIMIT_REACHED: 403,
52
53
  MOSTRA_REMOTE_SIGN_IN_REQUIRED: 403,
53
54
  MOSTRA_REMOTE_RATE_LIMITED: 429,
54
55
  MOSTRA_ACTION_PAUSED: 423,
56
+ // A link revoked or expired, or a page that stopped waiting, while the relay asked the
57
+ // operator (MT-03).
58
+ MOSTRA_HYGIENE_TOKEN_REVOKED: 410,
59
+ MOSTRA_ACTION_CANCELLED: 409,
55
60
  };
56
61
 
57
62
  type Handler = (context: RouteContext) => Response | Promise<Response>;
@@ -237,7 +242,7 @@ export function actionRoutes(options: ActionRoutesOptions): ActionRoutes {
237
242
  if (pausedNow) return pausedNow;
238
243
  try {
239
244
  return jsonResponse(
240
- actions.startRun(page, {
245
+ await actions.startRun(page, {
241
246
  viewId: request.viewId,
242
247
  fnId: request.fnId,
243
248
  args: request.args,
@@ -266,6 +266,8 @@ export interface CapabilitiesOptions {
266
266
  * links, so its operator's `revokeLink` finds a link's home, WP-30).
267
267
  */
268
268
  readonly onMinted?: (token: { readonly tokenId: string; readonly artifactId: string }) => void;
269
+ /** How often a session's `last_seen_at` is written at most; an hour unless a test shortens it. */
270
+ readonly touchIntervalMs?: number;
269
271
  }
270
272
 
271
273
  /** What a stream ticket opens (D158 item 5). */
@@ -302,6 +304,7 @@ export class Capabilities {
302
304
  /** Failure times per artifact (`""` for tokens of no artifact in this home). */
303
305
  readonly #failures = new Map<string, number[]>();
304
306
  readonly #touched = new Map<string, number>();
307
+ readonly #touchIntervalMs: number;
305
308
 
306
309
  constructor(options: CapabilitiesOptions) {
307
310
  this.#ledger = options.ledger;
@@ -311,6 +314,7 @@ export class Capabilities {
311
314
  this.#shellOrigin = options.shellOrigin;
312
315
  this.#servesShell = options.servesShell ?? ((origin) => origin === this.#shellOrigin());
313
316
  this.#onMinted = options.onMinted;
317
+ this.#touchIntervalMs = options.touchIntervalMs ?? TOUCH_INTERVAL_MS;
314
318
  }
315
319
 
316
320
  /** Runs `fn` in the caller's transaction, or in a new one. */
@@ -731,7 +735,7 @@ export class Capabilities {
731
735
  /** Writes `last_seen_at` at most hourly, so serving files doesn't write the ledger per request. */
732
736
  #touch(sessionId: string): void {
733
737
  const now = this.#now();
734
- if (now - (this.#touched.get(sessionId) ?? 0) < TOUCH_INTERVAL_MS) return;
738
+ if (now - (this.#touched.get(sessionId) ?? 0) < this.#touchIntervalMs) return;
735
739
  this.#touched.set(sessionId, now);
736
740
  this.#ledger.write((db) =>
737
741
  db.run("UPDATE session SET last_seen_at = ? WHERE id = ?", this.#iso(now), sessionId),
@@ -295,6 +295,8 @@ export interface HostedAddressing {
295
295
  readonly artifactId: string;
296
296
  readonly versionId: string;
297
297
  readonly tokenId: string;
298
+ /** The shell session asking for the ticket: its own activity is this visit's (MT-03). */
299
+ readonly sessionId: string;
298
300
  readonly client: string | undefined;
299
301
  }) => Promise<(Refusal & { readonly retryAfter?: number }) | undefined>;
300
302
  /** A version whose files are withheld now (a quarantine): refused even to an open frame. */
@@ -1405,6 +1407,7 @@ export function createGateway(options: GatewayOptions): Gateway {
1405
1407
  artifactId,
1406
1408
  versionId: version.id,
1407
1409
  tokenId: session.grant.tokenId,
1410
+ sessionId: session.id,
1408
1411
  client: context.client,
1409
1412
  });
1410
1413
  if (refused) return refuse(checks, refused, meta);
@@ -923,4 +923,13 @@ export const MIGRATIONS: readonly Migration[] = [
923
923
  `);
924
924
  },
925
925
  },
926
+ {
927
+ version: 17,
928
+ name: "a link's views",
929
+ up(db) {
930
+ // A hosted link's idle expiry is judged by its last view (`LinkPolicy.idleExpiry`, MT-03),
931
+ // read at every frame ticket a hosted page asks for: the link's views by its token.
932
+ db.exec("CREATE INDEX view_token ON view (token_id, opened_at)");
933
+ },
934
+ },
926
935
  ];
package/src/server/api.ts CHANGED
@@ -418,7 +418,7 @@ export function createApi(options: ApiOptions): Api {
418
418
  }
419
419
  if (existsSync(target)) await rm(scratch, { force: true });
420
420
  else renameSync(scratch, target);
421
- home.uploaded(sha);
421
+ home.uploaded(sha, size);
422
422
  options.stored?.(who.homeId, size);
423
423
  send(response, 201, { sha256: sha, size });
424
424
  };
@@ -16,7 +16,7 @@ import { AccountId, HomeId, LinkId } from "@mostra/protocol";
16
16
  import type { SignInIdentity } from "@mostra/protocol/operator";
17
17
  import type { Ledger, LedgerDb } from "../ledger/index.ts";
18
18
  import type { Log } from "../log.ts";
19
- import type { RemoteServerConfig } from "./config.ts";
19
+ import { configuredVerifier, type RemoteServerConfig } from "./config.ts";
20
20
  import type { Operator } from "./operator.ts";
21
21
 
22
22
  /** The CLI's client ID: a first-party public client (§18.5). */
@@ -224,9 +224,24 @@ export interface Authorization {
224
224
  * `accounts.resolve` when it has one, else the server's own accounts; `steps` counts the first
225
225
  * sign-in steps already taken.
226
226
  */
227
- resolveAccount(identity: SignInIdentity, steps: number): Promise<ResolvedAccount>;
228
- /** An account's display name, and the provider that verified it (its first identity's). */
229
- accountName(accountId: string): { readonly name?: string; readonly provider?: string };
227
+ resolveAccount(
228
+ identity: SignInIdentity,
229
+ steps: number,
230
+ /**
231
+ * The label of the provider's verifier (`IdentityProvider.verifies`), recorded on the identity
232
+ * as it links or signs in; absent: the provider verified no name (MT-03).
233
+ */
234
+ verifiedBy?: string,
235
+ ): Promise<ResolvedAccount>;
236
+ /**
237
+ * An account's display name, its first identity's provider, and the label of that identity's
238
+ * verifier as it was recorded when the provider last named the person (MT-03).
239
+ */
240
+ accountName(accountId: string): {
241
+ readonly name?: string;
242
+ readonly provider?: string;
243
+ readonly verifiedBy?: string;
244
+ };
230
245
  /** Mints an authorization code (one minute, single use; only its hash is kept). */
231
246
  issueCode(grant: CodeGrant): string;
232
247
  /**
@@ -290,6 +305,29 @@ export function createAuthorization(options: AuthorizationOptions): Authorizatio
290
305
  JSON.stringify({ client_name: "Mostra CLI" }),
291
306
  iso(now()),
292
307
  );
308
+ // Identities linked before the server recorded who verified each (MT-03) take, once, the
309
+ // verifier the configuration names for their provider now, as their sender lines showed it
310
+ // until then; any other (a provider retired, or one an operator module supplied) none. The
311
+ // configuration may since have given a provider's ID to another kind, so a row keeps none
312
+ // unless its shape is that kind's (its Opus review): never one the development provider made
313
+ // (whose subject is the typed name, lower-cased), and for GitHub only a numeric subject (its
314
+ // user ID). From then on the recorded label is the one shown, whatever the configuration says.
315
+ const at = iso(now());
316
+ for (const provider of config.identityProviders ?? []) {
317
+ const label = configuredVerifier(provider);
318
+ if (label === undefined) continue;
319
+ db.run(
320
+ `UPDATE identity SET verified_by = ?, verified_recorded_at = ?
321
+ WHERE provider = ? AND verified_recorded_at IS NULL
322
+ AND (name IS NULL OR subject != lower(name))
323
+ AND (? != 'github' OR (subject != '' AND subject NOT GLOB '*[^0-9]*'))`,
324
+ label,
325
+ at,
326
+ provider.id,
327
+ provider.kind,
328
+ );
329
+ }
330
+ db.run("UPDATE identity SET verified_recorded_at = ? WHERE verified_recorded_at IS NULL", at);
293
331
  });
294
332
 
295
333
  const deviceRow = (db: LedgerDb, hash: string) =>
@@ -305,6 +343,7 @@ export function createAuthorization(options: AuthorizationOptions): Authorizatio
305
343
  account: string,
306
344
  name: string | undefined,
307
345
  status: "active" | "suspended",
346
+ verifiedBy: string | undefined,
308
347
  ): void => {
309
348
  db.run(
310
349
  `INSERT INTO account (id, name, status, created_at) VALUES (?, ?, ?, ?)
@@ -315,29 +354,47 @@ export function createAuthorization(options: AuthorizationOptions): Authorizatio
315
354
  iso(now()),
316
355
  );
317
356
  db.run(
318
- `INSERT INTO identity (provider, subject, account_id, email, name, linked_at) VALUES (?, ?, ?, ?, ?, ?)
357
+ `INSERT INTO identity (provider, subject, account_id, email, name, linked_at, verified_by, verified_recorded_at)
358
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
319
359
  ON CONFLICT (provider, subject) DO UPDATE SET account_id = excluded.account_id,
320
- email = excluded.email, name = excluded.name`,
360
+ email = excluded.email, name = excluded.name, verified_by = excluded.verified_by,
361
+ verified_recorded_at = excluded.verified_recorded_at`,
321
362
  identity.provider,
322
363
  identity.subject,
323
364
  account,
324
365
  identity.email ?? null,
325
366
  identity.name ?? null,
326
367
  iso(now()),
368
+ verifiedBy ?? null,
369
+ iso(now()),
327
370
  );
328
371
  };
329
372
 
330
- /** The account for a sign-in identity, made on the first sign-in. */
373
+ /**
374
+ * The account for a sign-in identity, made on the first sign-in. The identity records who
375
+ * verified the person's name as it signs in (`verifiedBy`, the provider's verifier label, or none),
376
+ * so a provider renamed or retired later changes no sender line (MT-03).
377
+ */
331
378
  const accountFor = (
332
379
  db: LedgerDb,
333
380
  identity: { provider: string; subject: string; name?: string },
381
+ verifiedBy: string | undefined,
334
382
  ): string => {
335
383
  const found = db.get<{ account_id: string }>(
336
384
  "SELECT account_id FROM identity WHERE provider = ? AND subject = ?",
337
385
  identity.provider,
338
386
  identity.subject,
339
387
  );
340
- if (found) return found.account_id;
388
+ if (found) {
389
+ db.run(
390
+ "UPDATE identity SET verified_by = ?, verified_recorded_at = ? WHERE provider = ? AND subject = ?",
391
+ verifiedBy ?? null,
392
+ iso(now()),
393
+ identity.provider,
394
+ identity.subject,
395
+ );
396
+ return found.account_id;
397
+ }
341
398
  const account = AccountId.create();
342
399
  db.run(
343
400
  "INSERT INTO account (id, name, status, created_at) VALUES (?, ?, 'active', ?)",
@@ -346,12 +403,14 @@ export function createAuthorization(options: AuthorizationOptions): Authorizatio
346
403
  iso(now()),
347
404
  );
348
405
  db.run(
349
- "INSERT INTO identity (provider, subject, account_id, name, linked_at) VALUES (?, ?, ?, ?, ?)",
406
+ "INSERT INTO identity (provider, subject, account_id, name, linked_at, verified_by, verified_recorded_at) VALUES (?, ?, ?, ?, ?, ?, ?)",
350
407
  identity.provider,
351
408
  identity.subject,
352
409
  account,
353
410
  identity.name ?? null,
354
411
  iso(now()),
412
+ verifiedBy ?? null,
413
+ iso(now()),
355
414
  );
356
415
  return account;
357
416
  };
@@ -866,13 +925,13 @@ export function createAuthorization(options: AuthorizationOptions): Authorizatio
866
925
  });
867
926
  },
868
927
 
869
- async resolveAccount(identity, steps) {
928
+ async resolveAccount(identity, steps, verifiedBy) {
870
929
  const verdict = options.operator
871
930
  ? await options.operator.resolve(identity, steps)
872
931
  : ({ default: true } as const);
873
932
  if (verdict === "unavailable") return { kind: "unavailable" };
874
933
  if ("default" in verdict) {
875
- const accountId = directory.write((db) => accountFor(db, identity));
934
+ const accountId = directory.write((db) => accountFor(db, identity, verifiedBy));
876
935
  const status = directory.read(
877
936
  (db) =>
878
937
  db.get<{ status: string }>("SELECT status FROM account WHERE id = ?", accountId)
@@ -884,7 +943,7 @@ export function createAuthorization(options: AuthorizationOptions): Authorizatio
884
943
  if ("step" in verdict) return { kind: "step", url: verdict.step.url };
885
944
  if ("refused" in verdict) return { kind: "refused", message: verdict.refused.message };
886
945
  directory.write((db) =>
887
- operatorAccount(db, identity, verdict.account, verdict.name, verdict.status),
946
+ operatorAccount(db, identity, verdict.account, verdict.name, verdict.status, verifiedBy),
888
947
  );
889
948
  if (verdict.status === "suspended") return { kind: "suspended" };
890
949
  return { kind: "account", accountId: verdict.account, name: verdict.name ?? identity.name };
@@ -892,14 +951,21 @@ export function createAuthorization(options: AuthorizationOptions): Authorizatio
892
951
 
893
952
  accountName(accountId) {
894
953
  return directory.read((db) => {
895
- const row = db.get<{ name: string | null; provider: string | null }>(
896
- `SELECT a.name, (SELECT i.provider FROM identity i WHERE i.account_id = a.id
897
- ORDER BY i.linked_at LIMIT 1) AS provider FROM account a WHERE a.id = ?`,
954
+ const row = db.get<{
955
+ name: string | null;
956
+ provider: string | null;
957
+ verified_by: string | null;
958
+ }>(
959
+ `SELECT a.name, i.provider, i.verified_by FROM account a
960
+ LEFT JOIN identity i ON i.rowid = (SELECT rowid FROM identity WHERE account_id = a.id
961
+ ORDER BY linked_at, rowid LIMIT 1)
962
+ WHERE a.id = ?`,
898
963
  accountId,
899
964
  );
900
965
  return {
901
966
  ...(row?.name ? { name: row.name } : {}),
902
967
  ...(row?.provider ? { provider: row.provider } : {}),
968
+ ...(row?.verified_by ? { verifiedBy: row.verified_by } : {}),
903
969
  };
904
970
  });
905
971
  },
@@ -1120,7 +1186,8 @@ export function createAuthorization(options: AuthorizationOptions): Authorizatio
1120
1186
  );
1121
1187
  return { ok: true as const };
1122
1188
  }
1123
- const account = accountFor(db, input.identity);
1189
+ // The development sign-in's name is taken on trust: no verifier (D161).
1190
+ const account = accountFor(db, input.identity, undefined);
1124
1191
  db.run(
1125
1192
  "INSERT INTO consent (account_id, client_id, granted_at) VALUES (?, ?, ?) ON CONFLICT (account_id, client_id) DO UPDATE SET revoked_at = NULL",
1126
1193
  account,
@@ -26,6 +26,7 @@ import {
26
26
  import type { Ledger } from "../ledger/index.ts";
27
27
  import type { Log } from "../log.ts";
28
28
  import { type Authorization, canonicalResource, hashSecret } from "./auth.ts";
29
+ import { verifierLabel } from "./config.ts";
29
30
  import { type Clients, type OAuthClient, redirectAllowed } from "./oauth-clients.ts";
30
31
  import type { Operator } from "./operator.ts";
31
32
 
@@ -253,6 +254,19 @@ export function createAuthorize(options: AuthorizeOptions): Authorize {
253
254
 
254
255
  // ── providers ───────────────────────────────────────────────────────────────────────────
255
256
 
257
+ /**
258
+ * The label a provider's verified names carry (`IdentityProvider.verifies`, MT-03): text of 1 to
259
+ * 64 characters, else none, since an operator's provider is checked as every operator answer is.
260
+ */
261
+ const verifierOf = (provider: IdentityProvider): string | undefined => {
262
+ const raw: unknown = (provider as { verifies?: { label?: unknown } }).verifies?.label;
263
+ const label = verifierLabel(raw);
264
+ if (label === undefined && provider.verifies !== undefined) {
265
+ log.warn("signin.verifier_refused", { provider: provider.id });
266
+ }
267
+ return label;
268
+ };
269
+
256
270
  /** The providers now: configured ones, then the operator's (asked each time, D167). */
257
271
  const providers = async (): Promise<IdentityProvider[]> => {
258
272
  const supplied = await operator.providers();
@@ -270,6 +284,8 @@ export function createAuthorize(options: AuthorizeOptions): Authorize {
270
284
  }
271
285
  interface StepRecord {
272
286
  readonly identity: SignInIdentity;
287
+ /** The verifier label of the provider that named the person (MT-03). */
288
+ readonly verifiedBy?: string;
273
289
  readonly steps: number;
274
290
  readonly flow: string;
275
291
  readonly next: string;
@@ -306,11 +322,12 @@ export function createAuthorize(options: AuthorizeOptions): Authorize {
306
322
  const resolved = async (
307
323
  response: ServerResponse,
308
324
  identity: SignInIdentity,
325
+ verifiedBy: string | undefined,
309
326
  steps: number,
310
327
  flow: string,
311
328
  next: string,
312
329
  ): Promise<void> => {
313
- const account = await auth.resolveAccount(identity, steps);
330
+ const account = await auth.resolveAccount(identity, steps, verifiedBy);
314
331
  if (account.kind === "unavailable") {
315
332
  problem(response, 503, "Sign-in is unavailable for a moment; try again shortly.");
316
333
  return;
@@ -329,7 +346,13 @@ export function createAuthorize(options: AuthorizeOptions): Authorize {
329
346
  return;
330
347
  }
331
348
  const handle = token();
332
- keep("step", handle, { identity, steps: steps + 1, flow, next } satisfies StepRecord);
349
+ keep("step", handle, {
350
+ identity,
351
+ ...(verifiedBy !== undefined ? { verifiedBy } : {}),
352
+ steps: steps + 1,
353
+ flow,
354
+ next,
355
+ } satisfies StepRecord);
333
356
  const url = new URL(account.url);
334
357
  url.searchParams.set("mostra_return", `${apiOrigin}/signin/return?step=${handle}`);
335
358
  redirect(response, url.href);
@@ -792,7 +815,7 @@ export function createAuthorize(options: AuthorizeOptions): Authorize {
792
815
  );
793
816
  return true;
794
817
  }
795
- await resolved(response, identity, 0, pending.flow, pending.next);
818
+ await resolved(response, identity, verifierOf(provider), 0, pending.flow, pending.next);
796
819
  return true;
797
820
  }
798
821
  if (method === "GET" && path === "/signin/return") {
@@ -807,7 +830,7 @@ export function createAuthorize(options: AuthorizeOptions): Authorize {
807
830
  );
808
831
  return true;
809
832
  }
810
- await resolved(response, step.identity, step.steps, step.flow, step.next);
833
+ await resolved(response, step.identity, step.verifiedBy, step.steps, step.flow, step.next);
811
834
  return true;
812
835
  }
813
836
  return false;
@@ -64,8 +64,39 @@ export interface IdentityProviderConfig {
64
64
  readonly issuer?: string | undefined;
65
65
  readonly clientId?: string | undefined;
66
66
  readonly clientSecretFile?: string | undefined;
67
+ /**
68
+ * An `oidc` provider's ID-token claims that go into `SignInIdentity.facts` under their own names,
69
+ * when present (a Google Workspace account's domain, `hd`): at most 8 short names (MT-03).
70
+ */
71
+ readonly claims?: string[] | undefined;
67
72
  }
68
73
 
74
+ /**
75
+ * The label a configured provider's verified names carry on a hosted page's sender line ("verified
76
+ * with GitHub"): its `label`, else GitHub's name or its ID; none for the development provider, which
77
+ * takes the typed name on trust (D161). Recorded on each identity the provider links (MT-03).
78
+ */
79
+ export function configuredVerifier(provider: IdentityProviderConfig): string | undefined {
80
+ if (provider.kind === "development") return undefined;
81
+ return verifierLabel(provider.label ?? (provider.kind === "github" ? "GitHub" : provider.id));
82
+ }
83
+
84
+ /**
85
+ * A verifier's label as the sender line may show it (MT-03, and its Opus review): text of 1 to 64
86
+ * characters with no control, format (bidirectional overrides, zero-width joiners), line or
87
+ * paragraph separator characters, which could make one label read as another's ("verified with
88
+ * GitHub" from reversed text); anything else is no label.
89
+ */
90
+ export function verifierLabel(label: unknown): string | undefined {
91
+ if (typeof label !== "string") return undefined;
92
+ if (label.trim() === "" || label.length > 64) return undefined;
93
+ if (/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u.test(label)) return undefined;
94
+ return label;
95
+ }
96
+
97
+ /** Claim names that would reach an object's prototype rather than a key of its own. */
98
+ const RESERVED_CLAIMS = new Set(["__proto__", "constructor", "prototype"]);
99
+
69
100
  /** The configuration a remote server runs with (INTERFACES §18.1). */
70
101
  export interface RemoteServerConfig {
71
102
  readonly apiOrigin: string;
@@ -120,6 +151,20 @@ const Config: z.ZodType<RemoteServerConfig> & { readonly shape: Record<string, u
120
151
  issuer: z.string().optional(),
121
152
  clientId: z.string().optional(),
122
153
  clientSecretFile: z.string().optional(),
154
+ claims: z
155
+ .array(
156
+ z
157
+ .string()
158
+ .regex(/^[A-Za-z_][A-Za-z0-9_.:-]{0,63}$/, {
159
+ message: "must be claim names of at most 64 letters, digits and `_.:-`",
160
+ })
161
+ .refine((name) => !RESERVED_CLAIMS.has(name), {
162
+ message: "can't name `__proto__`, `constructor` or `prototype`",
163
+ }),
164
+ )
165
+ .min(1)
166
+ .max(8)
167
+ .optional(),
123
168
  }),
124
169
  )
125
170
  .optional(),
@@ -215,6 +260,14 @@ export function readServerConfig(file: string | undefined, env: Environment): Re
215
260
  "The configuration key `apiOrigin` can't be on a user-content domain: sign-in and the binding live apart from tenant pages (D165 item 7).",
216
261
  );
217
262
  }
263
+ const claimed = (config.identityProviders ?? []).findIndex(
264
+ (provider) => provider.claims !== undefined && provider.kind !== "oidc",
265
+ );
266
+ if (claimed >= 0) {
267
+ throw invalid(
268
+ `The configuration key \`identityProviders.${claimed}.claims\` can't be used: only an \`oidc\` provider passes on its ID token's claims.`,
269
+ );
270
+ }
218
271
  const proxy = validProxies(config.trustedProxies ?? []);
219
272
  if (proxy !== undefined) {
220
273
  throw invalid(
@@ -229,4 +229,55 @@ export const SERVER_MIGRATIONS: readonly Migration[] = [
229
229
  `);
230
230
  },
231
231
  },
232
+ {
233
+ version: 5,
234
+ name: "the verifier on each identity",
235
+ up(db) {
236
+ // MT-03 (DATA_MODEL §7.1, additive). Who verified the person's name, as the provider that
237
+ // links or signs in an identity says (`IdentityProvider.verifies`), recorded on the identity:
238
+ // a hosted page's sender line reads it from here, so renaming or retiring a provider later
239
+ // turns no verified name into an unverified one. `verified_recorded_at` is when it was
240
+ // recorded; an identity linked before this has none until the server, at its next start,
241
+ // gives it the verifier its configuration names for its provider then (the server's own
242
+ // accounts' sender lines unchanged by the upgrade).
243
+ db.exec(`
244
+ ALTER TABLE identity ADD COLUMN verified_by TEXT;
245
+ ALTER TABLE identity ADD COLUMN verified_recorded_at TEXT;
246
+ `);
247
+ },
248
+ },
249
+ {
250
+ version: 6,
251
+ name: "what each home holds",
252
+ up(db) {
253
+ // MT-03 (DATA_MODEL §7.1, additive). The bytes of each version file a home holds, as its push
254
+ // gave them (held to the bytes uploaded), and each home's running total, kept by triggers in
255
+ // the transaction of every change to `home_file`, so metering's `bytes.held` reads one row a
256
+ // home and falls when a removal frees files. `held_dirty` marks a home whose total changed
257
+ // since `held_reported` (the level last queued for the operator), so a change is reported
258
+ // after a restart too. A row from before this has no size until the server, at its next
259
+ // start, reads the stored file's (0 for one that is gone, so it is read once).
260
+ db.exec(`
261
+ ALTER TABLE home_file ADD COLUMN size INTEGER CHECK (size IS NULL OR size >= 0);
262
+ ALTER TABLE home ADD COLUMN held_bytes INTEGER NOT NULL DEFAULT 0 CHECK (held_bytes >= 0);
263
+ ALTER TABLE home ADD COLUMN held_reported INTEGER;
264
+ ALTER TABLE home ADD COLUMN held_dirty INTEGER NOT NULL DEFAULT 0 CHECK (held_dirty IN (0, 1));
265
+ CREATE INDEX home_held_dirty ON home (held_dirty) WHERE held_dirty = 1;
266
+ CREATE TRIGGER home_file_held_insert AFTER INSERT ON home_file WHEN NEW.size IS NOT NULL
267
+ BEGIN
268
+ UPDATE home SET held_bytes = held_bytes + NEW.size, held_dirty = 1 WHERE id = NEW.home_id;
269
+ END;
270
+ CREATE TRIGGER home_file_held_delete AFTER DELETE ON home_file WHEN OLD.size IS NOT NULL
271
+ BEGIN
272
+ UPDATE home SET held_bytes = held_bytes - OLD.size, held_dirty = 1 WHERE id = OLD.home_id;
273
+ END;
274
+ CREATE TRIGGER home_file_held_size AFTER UPDATE OF size ON home_file
275
+ WHEN COALESCE(OLD.size, -1) != COALESCE(NEW.size, -1)
276
+ BEGIN
277
+ UPDATE home SET held_bytes = held_bytes - COALESCE(OLD.size, 0) + COALESCE(NEW.size, 0),
278
+ held_dirty = 1 WHERE id = NEW.home_id;
279
+ END;
280
+ `);
281
+ },
282
+ },
232
283
  ];