@blueshed/joined 0.2.2 → 0.3.1

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.
Files changed (237) hide show
  1. package/.claude/skills/joined/SKILL.md +9 -1
  2. package/.claude/skills/joined/reference.md +316 -63
  3. package/.claude/skills/joined-door/SKILL.md +57 -0
  4. package/README.md +19 -50
  5. package/docs/design.md +158 -37
  6. package/docs/introduction.md +27 -27
  7. package/docs/light-and-shadow.svg +2 -1
  8. package/docs/links-and-trust.svg +1 -0
  9. package/docs/stories-to-code.svg +2 -1
  10. package/docs/wire-op.svg +1 -0
  11. package/examples/README.md +20 -0
  12. package/examples/account/account.json +1 -0
  13. package/examples/account/derive.ts +41 -0
  14. package/examples/account/generated/elements.ts +52 -0
  15. package/examples/account/generated/rows.ts +22 -0
  16. package/examples/account/generated/rules.ts +32 -0
  17. package/examples/account/routes.ts +5 -0
  18. package/examples/app.css +11 -1
  19. package/examples/cafe/books.html +2 -2
  20. package/examples/cafe/cafe.css +96 -85
  21. package/examples/cafe/generated/books.rows.ts +22 -0
  22. package/examples/cafe/generated/books.rules.ts +3 -2
  23. package/examples/cafe/generated/kitchen.rows.ts +27 -0
  24. package/examples/cafe/generated/kitchen.rules.ts +11 -1
  25. package/examples/cafe/generated/menu.rows.ts +22 -0
  26. package/examples/cafe/generated/menu.rules.ts +3 -2
  27. package/examples/cafe/generated/order.rows.ts +27 -0
  28. package/examples/cafe/generated/order.rules.ts +11 -1
  29. package/examples/cafe/generated/staff.elements.ts +7 -2
  30. package/examples/cafe/generated/staff.rows.ts +22 -0
  31. package/examples/cafe/generated/staff.rules.ts +9 -1
  32. package/examples/cafe/generated/supplies.queries.ts +4 -2
  33. package/examples/cafe/generated/supplies.rows.ts +22 -0
  34. package/examples/cafe/generated/supplies.rules.ts +17 -1
  35. package/examples/cafe/generated/till.queries.ts +2 -0
  36. package/examples/cafe/generated/till.rows.ts +27 -0
  37. package/examples/cafe/generated/till.rules.ts +11 -1
  38. package/examples/cafe/index.html +14 -15
  39. package/examples/cafe/kitchen.css +11 -19
  40. package/examples/cafe/kitchen.ts +7 -3
  41. package/examples/cafe/look.ts +30 -0
  42. package/examples/cafe/menu.html +10 -26
  43. package/examples/cafe/menu.ts +8 -80
  44. package/examples/cafe/migrations/002-guard-supplies.ts +15 -0
  45. package/examples/cafe/order.html +8 -7
  46. package/examples/cafe/order.ts +6 -2
  47. package/examples/cafe/routes.ts +0 -1
  48. package/examples/cafe/staff.json +5 -0
  49. package/examples/cafe/stories.jsonl +6 -2
  50. package/examples/cafe/supplies.html +35 -34
  51. package/examples/cafe/supplies.ts +59 -39
  52. package/examples/cafe/till.ts +19 -11
  53. package/examples/cafe/views.ts +7 -5
  54. package/examples/chart/arches.ts +150 -0
  55. package/examples/chart/chart.css +11 -0
  56. package/examples/chart/chart.json +87 -0
  57. package/examples/chart/generated/elements.ts +105 -0
  58. package/examples/chart/generated/queries.ts +36 -0
  59. package/examples/chart/generated/rows.ts +27 -0
  60. package/examples/chart/generated/rules.ts +111 -0
  61. package/examples/chart/grid.ts +118 -0
  62. package/examples/chart/index.html +78 -0
  63. package/examples/chart/migrations/001-chart.ts +6 -0
  64. package/examples/chart/migrations/002-create-conditions.ts +6 -0
  65. package/examples/chart/page.ts +20 -0
  66. package/examples/chart/routes.ts +7 -0
  67. package/examples/chart/stories.jsonl +14 -0
  68. package/examples/chart/teeth.ts +57 -0
  69. package/examples/desk/desk.css +6 -10
  70. package/examples/desk/generated/elements.ts +1 -1
  71. package/examples/desk/generated/rows.ts +22 -0
  72. package/examples/desk/generated/rules.ts +34 -1
  73. package/examples/desk/index.html +10 -3
  74. package/examples/desk/lanes.css +21 -19
  75. package/examples/desk/routes.ts +0 -2
  76. package/examples/desk/stories.jsonl +4 -3
  77. package/examples/desk/tally.css +1 -1
  78. package/examples/desk/thumbs.ts +2 -2
  79. package/examples/docs.ts +7 -4
  80. package/examples/hello/generated/elements.ts +2 -2
  81. package/examples/hello/generated/rules.ts +3 -2
  82. package/examples/hello/hello.css +2 -4
  83. package/examples/hello/index.html +10 -3
  84. package/examples/hello/page.ts +4 -4
  85. package/examples/index.html +20 -12
  86. package/examples/notes/generated/elements.ts +112 -0
  87. package/examples/notes/generated/queries.ts +42 -0
  88. package/examples/notes/generated/rows.ts +27 -0
  89. package/examples/notes/generated/rules.ts +133 -0
  90. package/examples/notes/index.html +32 -0
  91. package/examples/notes/look.ts +41 -0
  92. package/examples/notes/migrations/001-notes.ts +7 -0
  93. package/examples/notes/notes.json +78 -0
  94. package/examples/notes/page.ts +21 -0
  95. package/examples/notes/routes.ts +6 -0
  96. package/examples/notes/stories.jsonl +24 -0
  97. package/examples/page.ts +9 -2
  98. package/examples/people/generated/rows.ts +22 -0
  99. package/examples/people/generated/rules.ts +11 -1
  100. package/examples/people/links.ts +8 -9
  101. package/examples/people/people.css +1 -1
  102. package/examples/people/routes.ts +1 -3
  103. package/examples/people/stories.jsonl +1 -0
  104. package/examples/people/view.ts +5 -2
  105. package/examples/trip/generated/elements.ts +5 -3
  106. package/examples/trip/generated/queries.ts +12 -1
  107. package/examples/trip/generated/rows.ts +27 -0
  108. package/examples/trip/generated/rules.ts +56 -2
  109. package/examples/trip/index.html +58 -12
  110. package/examples/trip/line.css +186 -0
  111. package/examples/trip/line.ts +51 -40
  112. package/examples/trip/page.ts +65 -71
  113. package/examples/trip/routes.ts +9 -5
  114. package/examples/trip/stays.css +13 -13
  115. package/examples/trip/stays.ts +15 -10
  116. package/examples/trip/stories.jsonl +2 -0
  117. package/examples/trip/told.ts +3 -26
  118. package/examples/trip/trip.css +16 -0
  119. package/examples/trips/generated/elements.ts +1 -1
  120. package/examples/trips/generated/rows.ts +22 -0
  121. package/examples/trips/generated/rules.ts +9 -1
  122. package/examples/trips/index.html +10 -10
  123. package/examples/trips/map.ts +3 -14
  124. package/examples/trips/new-trip.ts +14 -16
  125. package/examples/trips/trips.css +24 -23
  126. package/examples/weeks/generated/elements.ts +1 -1
  127. package/examples/weeks/generated/queries.ts +11 -0
  128. package/examples/weeks/generated/rows.ts +22 -0
  129. package/examples/weeks/generated/rules.ts +11 -5
  130. package/examples/weeks/routes.ts +3 -2
  131. package/examples/weeks/stories.jsonl +1 -0
  132. package/examples/welcome.css +43 -33
  133. package/package.json +8 -2
  134. package/src/attachment.ts +17 -2
  135. package/src/awesome.ts +103 -0
  136. package/src/board.css +76 -0
  137. package/src/board.ts +173 -0
  138. package/src/cli.ts +28 -3
  139. package/src/compile.ts +821 -109
  140. package/src/definitions.ts +113 -27
  141. package/src/demo.css +2 -5
  142. package/src/draft.ts +48 -27
  143. package/src/drawer.ts +248 -0
  144. package/src/engine.ts +253 -170
  145. package/src/fields.ts +341 -0
  146. package/src/file-value.ts +12 -2
  147. package/src/files.ts +113 -33
  148. package/src/ground.ts +110 -0
  149. package/src/icon-names.ts +19 -2
  150. package/src/keep.ts +16 -3
  151. package/src/kit.ts +51 -0
  152. package/src/link.ts +3 -3
  153. package/src/map.css +140 -0
  154. package/src/map.ts +200 -0
  155. package/src/mcp.ts +129 -24
  156. package/src/members/demo.ts +13 -12
  157. package/src/members/generated/rows.ts +22 -0
  158. package/src/members/generated/rules.ts +3 -2
  159. package/src/members/group.ts +105 -55
  160. package/src/members/keys.ts +95 -79
  161. package/src/members/panel.css +40 -35
  162. package/src/members/panel.ts +58 -37
  163. package/src/migrate.ts +178 -125
  164. package/src/migrations/005-change-kept.ts +7 -0
  165. package/src/month.css +129 -0
  166. package/src/month.ts +179 -0
  167. package/src/ops.ts +40 -1
  168. package/src/page.css +11 -2
  169. package/src/page.ts +68 -17
  170. package/src/parts.css +614 -230
  171. package/src/parts.ts +259 -36
  172. package/src/plane.css +61 -0
  173. package/src/plane.ts +153 -0
  174. package/src/postgres-server.ts +60 -0
  175. package/src/reading.css +73 -0
  176. package/src/reading.ts +238 -0
  177. package/src/rows.css +289 -0
  178. package/src/rows.ts +864 -0
  179. package/src/search.css +80 -0
  180. package/src/search.ts +130 -0
  181. package/src/server.ts +355 -137
  182. package/src/settings.ts +9 -4
  183. package/src/sheet.ts +116 -0
  184. package/src/skill.ts +40 -0
  185. package/src/slots.css +90 -0
  186. package/src/slots.ts +213 -0
  187. package/src/specs.ts +38 -0
  188. package/src/starter.ts +19 -2
  189. package/src/store.ts +224 -161
  190. package/src/stories.ts +43 -11
  191. package/src/surface.ts +164 -0
  192. package/src/time.ts +2 -0
  193. package/src/timeline.css +111 -0
  194. package/src/timeline.ts +235 -0
  195. package/src/toast.ts +21 -48
  196. package/src/together.ts +15 -24
  197. package/src/tokens.css +89 -3
  198. package/src/tokens.json +287 -7
  199. package/src/tool.ts +210 -0
  200. package/src/upkeep.ts +47 -22
  201. package/src/views.css +43 -0
  202. package/src/views.ts +111 -0
  203. package/src/week.css +150 -0
  204. package/src/week.ts +254 -0
  205. package/src/write.ts +326 -78
  206. package/starter/CHANGELOG.md +8 -0
  207. package/starter/CLAUDE.md +9 -3
  208. package/starter/bunfig +5 -0
  209. package/starter/githooks/pre-commit +13 -0
  210. package/starter/prettierignore +5 -0
  211. package/starter/tests/hello.test.ts +2 -0
  212. package/starter/tests/records.test.ts +40 -0
  213. package/starter/todo.jsonl +0 -0
  214. package/docs/learning.md +0 -76
  215. package/examples/cafe/trust.ts +0 -20
  216. package/examples/desk/trust.ts +0 -24
  217. package/examples/people/trust.ts +0 -14
  218. package/examples/trip/answer-rows.ts +0 -70
  219. package/examples/trip/bar.ts +0 -89
  220. package/examples/trip/calendar-map.css +0 -711
  221. package/examples/trip/calendar-map.ts +0 -249
  222. package/examples/trip/drags.ts +0 -143
  223. package/examples/trip/drawer.ts +0 -250
  224. package/examples/trip/event-form.ts +0 -200
  225. package/examples/trip/holding.ts +0 -61
  226. package/examples/trip/map.ts +0 -234
  227. package/examples/trip/month.ts +0 -87
  228. package/examples/trip/other-weeks.ts +0 -67
  229. package/examples/trip/peek.ts +0 -71
  230. package/examples/trip/people-chips.ts +0 -74
  231. package/examples/trip/shell.ts +0 -39
  232. package/examples/trip/trust.ts +0 -51
  233. package/examples/trip/week.ts +0 -237
  234. package/examples/trip/writes.ts +0 -91
  235. package/examples/trip/zones.ts +0 -16
  236. package/examples/weeks/derive.ts +0 -23
  237. package/src/scrim.ts +0 -81
package/src/mcp.ts CHANGED
@@ -6,11 +6,18 @@
6
6
  // group's), whole or not at all, and told to every page at once. Its tools are written from each document's compiled
7
7
  // rules, never the stories: read_<doc>, the document as its member sees it, and write_<doc>, one write, its ops typed
8
8
  // as the grants allow; a kind's (trip:1) take the instance's key. A window isn't a tool's: a document is read as its
9
- // member sees it, whole or one collection's items (some, by id). Each app may give the agent its own words (its routes.ts's `instructions`), said as it opens.
9
+ // member sees it, whole or one collection's items (some, by id). How any document is read and written here is the
10
+ // door's own skill (src/skill.ts), served by MCP's skills extension, and said as it opens, then each app's own words
11
+ // (its routes.ts's `instructions`). It speaks both eras of MCP: the modern (2026-07-28), each request saying its
12
+ // version and the client's capabilities in its _meta, its headers checked against its body, server/discover in place
13
+ // of a handshake, and the skills extension declared; and the legacy, opened by initialize. To a client that loads
14
+ // skills itself the instructions say where the skill is; to any other, what it says.
10
15
 
11
16
  import { FORMS, SAID } from "./compile.ts";
17
+ import { skill, SKILLS } from "./skill.ts";
12
18
  import type { Who } from "./members/group.ts";
13
- import { NTH, parts, type Op, type Type } from "./ops.ts";
19
+ import { upTo } from "./files.ts";
20
+ import { isOp, MESSAGE, NTH, OPS, parts, type Op, type Type } from "./ops.ts";
14
21
  import type { Doc } from "./store.ts";
15
22
  import type { Rules } from "./write.ts";
16
23
 
@@ -23,8 +30,8 @@ type Door = {
23
30
  /** Where nobody's a member: anyone's, with no link, as a stranger's page is. */
24
31
  anyone?: boolean;
25
32
  /** Why a member may not hold a document (or it isn't there), or null. */
26
- holds(doc: string, member: number): string | null;
27
- read(doc: string, member: number): Doc;
33
+ holds(doc: string, member: number): Promise<string | null>;
34
+ read(doc: string, member: number): Promise<Doc>;
28
35
  /** A write by an agent's member; or, at a door that's anyone's, nobody's (null), as a stranger's page writes. */
29
36
  write(doc: string, ops: Op[], why: string | undefined, who: Who | null): Promise<Written>;
30
37
  instructions: string;
@@ -35,8 +42,34 @@ type Collection = Rules["collections"][string] & { needs?: readonly string[] };
35
42
  /** A tool's answer, as MCP says it: its words, and whether it's a refusal. */
36
43
  type Result = { content: { type: "text"; text: string }[]; isError?: true };
37
44
 
38
- /** The versions of MCP it speaks: the one a client asks, if it's one of these, else the newest. */
45
+ /** The versions of MCP it speaks: the modern, said on every request; and the legacy, opened by initialize (the one a
46
+ * client asks, if it's one of these, else the newest). */
47
+ const MODERN = ["2026-07-28"];
39
48
  const VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
49
+ /** The prefix of what MCP itself names in a _meta. */
50
+ const MCP = "io.modelcontextprotocol/";
51
+ /** A JSON-RPC message, as it's posted. */
52
+ type Message = { id?: unknown; method?: string; params?: any };
53
+ /** What the modern HTTP transport has a request name in its Mcp-Name header, by its method. */
54
+ const NAMED: Record<string, string> = { "tools/call": "name", "resources/read": "uri", "prompts/get": "name" };
55
+
56
+ /** A header's value as it's meant: =?base64?…?= decoded (a name that isn't plain ASCII), anything else as it is. */
57
+ const decoded = (v: string | null) => {
58
+ const b64 = v && /^=\?base64\?(.*)\?=$/.exec(v)?.[1];
59
+ return b64 ? Buffer.from(b64, "base64").toString("utf8") : v;
60
+ };
61
+
62
+ /** Why a modern request's headers don't say what its body does (its version, its method, a call's or a read's name),
63
+ * or null: the transport refuses a mismatch, so nothing on the way acts on one thing and the door on another. */
64
+ function unheaded(req: Request, m: Message, version: string): string | null {
65
+ if (req.headers.get("mcp-protocol-version") !== version)
66
+ return `MCP-Protocol-Version isn't ${version}, as the request's _meta says`;
67
+ if (req.headers.get("mcp-method") !== m.method) return `Mcp-Method isn't ${m.method}, as the request says`;
68
+ const named = NAMED[m.method ?? ""];
69
+ if (named && decoded(req.headers.get("mcp-name")) !== m.params?.[named])
70
+ return `Mcp-Name isn't ${m.params?.[named]}, as the request's ${named} says`;
71
+ return null;
72
+ }
40
73
  const ID = "[1-9]\\d*";
41
74
 
42
75
  const answered = (value: unknown): Result => ({ content: [{ type: "text", text: JSON.stringify(value) }] });
@@ -167,23 +200,25 @@ function readOf(doc: Doc, args: { collection?: unknown; ids?: unknown }): Doc |
167
200
  /** Who comes to a door that's anyone's: nobody, as a stranger's page is. */
168
201
  const ANYONE: Who = { member: 0, token: "" };
169
202
 
170
- /** The door: POST answers MCP's messages, by the agent its token names; a GET is refused, as no stream is kept. */
203
+ /** The door: POST answers MCP's messages, by the agent its token names; a GET is refused, as no stream is kept; an
204
+ * OPTIONS says it's POST, and nothing of another site's (no CORS), so a browser's page elsewhere is never let post. */
171
205
  export function door(d: Door) {
172
206
  const rpc = (id: unknown, result: unknown) => ({ jsonrpc: "2.0", id, result });
173
207
  const fail = (id: unknown, code: number, message: string) => ({ jsonrpc: "2.0", id, error: { code, message } });
174
208
 
175
209
  /** The tools for a member's agent: each document's read and, where pages write it, its write; a kind's take its key. */
176
- function toolsFor(who: Who) {
210
+ async function toolsFor(who: Who) {
177
211
  const tools: {
178
212
  name: string;
179
213
  description: string;
180
214
  inputSchema: Schema;
215
+ annotations: Schema;
181
216
  run(args: any): Promise<Result> | Result;
182
217
  }[] = [];
183
218
  for (const r of d.rules) {
184
219
  // the document a call names: a kind's instance by its key (trip:1), or the one
185
220
  const name = (args: { key?: unknown }) => (r.kind ? `${r.doc}:${args.key}` : r.doc);
186
- if (!r.kind && d.holds(r.doc, who.member)) continue;
221
+ if (!r.kind && (await d.holds(r.doc, who.member))) continue;
187
222
  const key = r.kind
188
223
  ? { key: { type: "integer", description: `which ${r.doc}: the id of one of ${r.kind.doc}'s ${r.kind.root}` } }
189
224
  : {};
@@ -204,10 +239,12 @@ export function door(d: Door) {
204
239
  name: `read_${r.doc}`,
205
240
  description: `Read ${r.doc}, as you see it, with its version${colls.length ? `: whole, or one collection's items, or some of them by id` : ""}. It holds ${described(r)}.`,
206
241
  inputSchema: { type: "object", properties: { ...key, ...part }, required: Object.keys(key) },
207
- run: (args) => {
208
- const no = d.holds(name(args), who.member);
242
+ // a read changes nothing: a client needn't ask before it
243
+ annotations: { readOnlyHint: true },
244
+ run: async (args) => {
245
+ const no = await d.holds(name(args), who.member);
209
246
  if (no) return refused(no);
210
- const read = readOf(d.read(name(args), who.member), args);
247
+ const read = readOf(await d.read(name(args), who.member), args);
211
248
  return typeof read === "string" ? refused(read) : answered(read);
212
249
  },
213
250
  });
@@ -241,10 +278,13 @@ export function door(d: Door) {
241
278
  },
242
279
  required: [...Object.keys(key), "ops"],
243
280
  },
281
+ // a write that may replace or remove what's there undoes what someone made; one that only adds doesn't
282
+ annotations: { readOnlyHint: false, destructiveHint: ops.some((o) => o.op !== "add") },
244
283
  run: async (args) => {
245
284
  if (!Array.isArray(args.ops) || !args.ops.length)
246
285
  return refused("ops: one write's ops, a list of at least one");
247
- const no = d.holds(name(args), who.member);
286
+ if (!args.ops.every(isOp)) return refused(OPS);
287
+ const no = await d.holds(name(args), who.member);
248
288
  if (no) return refused(no);
249
289
  const w = await d.write(
250
290
  name(args),
@@ -259,22 +299,52 @@ export function door(d: Door) {
259
299
  return tools;
260
300
  }
261
301
 
262
- /** One message: answered, or a notification (no id), which isn't. */
263
- async function one(m: { id?: unknown; method?: string; params?: any }, who: Who) {
302
+ /** One message, in its era: answered, or a notification (no id), which isn't. A modern answer says it's complete,
303
+ * and where it may be kept a while, for how long (none: the grants can change) and for whom. */
304
+ async function one(m: Message, who: Who, modern: boolean) {
264
305
  if (m.id === undefined) return null;
265
- if (m.method === "initialize")
306
+ const done = (result: object, kept?: "public" | "private") =>
307
+ rpc(
308
+ m.id,
309
+ modern ? { resultType: "complete", ...result, ...(kept ? { ttlMs: 0, cacheScope: kept } : {}) } : result,
310
+ );
311
+ // to a client that loads skills itself (it says so in the request's capabilities), where the skill is
312
+ const loads = !!m.params?._meta?.[`${MCP}clientCapabilities`]?.extensions?.[SKILLS];
313
+ const instructions = [loads ? skill.pointer : skill.body, d.instructions].filter(Boolean).join("\n\n");
314
+ if (modern && m.method === "server/discover")
315
+ return done(
316
+ {
317
+ supportedVersions: MODERN,
318
+ capabilities: { tools: {}, resources: {}, extensions: { [SKILLS]: {} } },
319
+ _meta: { [`${MCP}serverInfo`]: { name: "joined", version: d.version } },
320
+ instructions,
321
+ },
322
+ "private",
323
+ );
324
+ if (!modern && m.method === "initialize")
266
325
  return rpc(m.id, {
267
326
  protocolVersion: VERSIONS.includes(m.params?.protocolVersion) ? m.params.protocolVersion : VERSIONS[0],
268
- capabilities: { tools: {} },
327
+ capabilities: { tools: {}, resources: {} },
269
328
  serverInfo: { name: "joined", version: d.version },
270
- ...(d.instructions ? { instructions: d.instructions } : {}),
329
+ instructions,
271
330
  });
272
- if (m.method === "ping") return rpc(m.id, {});
273
- if (m.method === "tools/list") return rpc(m.id, { tools: toolsFor(who).map(({ run: _, ...t }) => t) });
331
+ if (!modern && m.method === "ping") return rpc(m.id, {});
332
+ if (m.method === "resources/list") return done({ resources: [skill.resource] }, "public");
333
+ if (m.method === "resources/read")
334
+ return m.params?.uri === skill.uri
335
+ ? done({ contents: [{ uri: skill.uri, mimeType: "text/markdown", text: skill.text }] }, "public")
336
+ : fail(m.id, -32602, `there's no resource at ${m.params?.uri}`);
337
+ if (modern && m.method === "skills/list") return done({ skills: [skill.entry] }, "public");
338
+ if (modern && m.method === "skills/get")
339
+ return m.params?.uri === skill.uri
340
+ ? done({ skill: skill.entry }, "public")
341
+ : fail(m.id, -32602, `No skill is served at ${m.params?.uri}`);
342
+ if (m.method === "tools/list")
343
+ return done({ tools: (await toolsFor(who)).map(({ run: _, ...t }) => t) }, "private");
274
344
  if (m.method === "tools/call") {
275
- const tool = toolsFor(who).find((t) => t.name === m.params?.name);
345
+ const tool = (await toolsFor(who)).find((t) => t.name === m.params?.name);
276
346
  return tool
277
- ? rpc(m.id, await tool.run(m.params.arguments ?? {}))
347
+ ? done(await tool.run(m.params.arguments ?? {}))
278
348
  : fail(m.id, -32602, `no tool called ${m.params?.name}`);
279
349
  }
280
350
  return fail(m.id, -32601, `no method called ${m.method}`);
@@ -282,6 +352,7 @@ export function door(d: Door) {
282
352
 
283
353
  return {
284
354
  GET: () => new Response("this door is POST alone", { status: 405, headers: { allow: "POST" } }),
355
+ OPTIONS: () => new Response(null, { status: 204, headers: { allow: "POST" } }),
285
356
  async POST(req: Request & { params: { token?: string } }) {
286
357
  // an agent's link alone (never a member's own, a removed agent's or one unknown); where nobody's a member, anyone
287
358
  const who = d.anyone ? ANYONE : await d.whoIs(req.params.token!);
@@ -292,15 +363,49 @@ export function door(d: Door) {
292
363
  status: 401,
293
364
  },
294
365
  );
295
- const m = await req.json().catch(() => undefined);
366
+ // read as it comes, no more than a page's message may be
367
+ const body = await upTo(req, MESSAGE);
368
+ if (!body)
369
+ return Response.json(fail(null, -32600, `that message is too big: under ${MESSAGE >> 20} MB, please`), {
370
+ status: 413,
371
+ });
372
+ let m: Message | undefined;
373
+ try {
374
+ m = JSON.parse(new TextDecoder().decode(body));
375
+ } catch {}
296
376
  if (!m || typeof m !== "object")
297
377
  return Response.json(fail(null, -32700, "that isn't a JSON-RPC message"), { status: 400 });
378
+ // a batch, said as one: MCP has had none since 2025-06-18, and an older client sends one message at a time too
379
+ if (Array.isArray(m))
380
+ return Response.json(fail(null, -32600, "a batch isn't answered: send one message at a time"), { status: 400 });
381
+ // modern, where the request says its version in its _meta: its headers saying the same, and a version it speaks
382
+ const version = m.params?._meta?.[`${MCP}protocolVersion`];
383
+ if (version !== undefined) {
384
+ const why = unheaded(req, m, String(version));
385
+ if (why) return Response.json(fail(m.id ?? null, -32020, `Header mismatch: ${why}`), { status: 400 });
386
+ if (!MODERN.includes(version))
387
+ return Response.json(
388
+ {
389
+ jsonrpc: "2.0",
390
+ id: m.id ?? null,
391
+ error: {
392
+ code: -32022,
393
+ message: "Unsupported protocol version",
394
+ data: { supported: MODERN, requested: version },
395
+ },
396
+ },
397
+ { status: 400 },
398
+ );
399
+ }
298
400
  // never thrown: Bun's line for a request that throws names its URL, and the URL holds the agent's token
299
- const answer = await one(m, who!).catch((e) => {
401
+ const answer = await one(m, who!, version !== undefined).catch((e) => {
300
402
  console.error("the MCP door failed:", e);
301
403
  return fail(m.id ?? null, -32603, "That wasn't done: the server had a problem with it.");
302
404
  });
303
- return answer ? Response.json(answer) : new Response(null, { status: 202 });
405
+ if (!answer) return new Response(null, { status: 202 });
406
+ // a method it hasn't, to a modern request, is a 404 (a legacy one's is answered as any error is)
407
+ const missing = version !== undefined && "error" in answer && answer.error.code === -32601;
408
+ return Response.json(answer, missing ? { status: 404 } : undefined);
304
409
  },
305
410
  };
306
411
  }
@@ -26,26 +26,27 @@ export function demoRoutes({
26
26
  signIn,
27
27
  }: {
28
28
  here: (req: Request) => boolean;
29
- members: () => Member[];
30
- bdfl: () => number;
29
+ members: () => Promise<Member[]>;
30
+ bdfl: () => Promise<number>;
31
31
  me: (req: Request) => Promise<number | null>;
32
32
  signIn: (req: Request, member: number) => Promise<Response>;
33
33
  }) {
34
34
  const refused = () => new Response("a demo answers this machine alone", { status: 403 });
35
35
  return {
36
- "/as": async (req: Request) =>
37
- here(req)
38
- ? Response.json({
39
- me: await me(req),
40
- people: [...members()]
41
- .sort((a, b) => Number(b.id === bdfl()) - Number(a.id === bdfl()))
42
- .map((m) => ({ id: m.id, name: m.name, bdfl: m.id === bdfl() })),
43
- })
44
- : refused(),
36
+ "/as": async (req: Request) => {
37
+ if (!here(req)) return refused();
38
+ const top = await bdfl();
39
+ return Response.json({
40
+ me: await me(req),
41
+ people: [...(await members())]
42
+ .sort((a, b) => Number(b.id === top) - Number(a.id === top))
43
+ .map((m) => ({ id: m.id, name: m.name, bdfl: m.id === top })),
44
+ });
45
+ },
45
46
  "/as/:member": async (req: Bun.BunRequest<"/as/:member">) => {
46
47
  const member = Number(req.params.member);
47
48
  if (!here(req)) return refused();
48
- return members().some((m) => m.id === member)
49
+ return (await members()).some((m) => m.id === member)
49
50
  ? signIn(req, member)
50
51
  : new Response("no such member", { status: 404 });
51
52
  },
@@ -0,0 +1,22 @@
1
+ // Written by src/compile.ts from src/members/stories.jsonl: change the stories, not this.
2
+
3
+ // Each collection of members as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
4
+ // extended, by define() from joined/rows, and holds each collection's element in its rows:
5
+ // <j-members-rows><j-members></j-members></j-members-rows>
6
+ // A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
7
+ // To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
8
+ // step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
9
+ // under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
10
+ // use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
11
+ // elements. Never change this file: change the stories.
12
+
13
+ import { rows, type Spec } from "joined/rows";
14
+ import { JMember } from "./elements.ts";
15
+
16
+ const members: Spec = {"doc":"members","name":"members","place":"j-members","tag":"j-member","one":"member","title":"name","fields":[{"name":"name","type":"string","needed":true},{"name":"inviter","type":"integer","needed":true},{"name":"act","type":"string"},{"name":"readonly","type":"integer"}]};
17
+
18
+ /** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
19
+ export const specs = { "members": members };
20
+
21
+ /** <j-members-rows>: members's members as rows, each named by its name. */
22
+ export class JMembersRows extends rows(members, { "j-member": JMember }) {}
@@ -3,7 +3,7 @@
3
3
  export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
4
4
 
5
5
  /** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
6
- * what each link is to. */
6
+ * what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
7
7
  export const doc = "members";
8
8
  export const collections = {
9
9
  "members": {
@@ -19,7 +19,8 @@ export const collections = {
19
19
  "name",
20
20
  "inviter"
21
21
  ],
22
- "links": {}
22
+ "links": {},
23
+ "pops": {}
23
24
  }
24
25
  } as const;
25
26
  /** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */