@blueshed/joined 0.0.0-stage → 0.1.20

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 (213) hide show
  1. package/.claude/skills/joined/SKILL.md +17 -0
  2. package/.claude/skills/joined/reference.md +768 -0
  3. package/LICENSE +19 -0
  4. package/README.md +115 -2
  5. package/docs/design.md +148 -0
  6. package/docs/introduction.md +193 -0
  7. package/docs/learning.md +76 -0
  8. package/docs/stories.md +82 -0
  9. package/examples/app.css +27 -0
  10. package/examples/cafe/books.html +38 -0
  11. package/examples/cafe/books.json +13 -0
  12. package/examples/cafe/books.ts +64 -0
  13. package/examples/cafe/cafe.css +512 -0
  14. package/examples/cafe/front.html +115 -0
  15. package/examples/cafe/front.ts +7 -0
  16. package/examples/cafe/generated/books.elements.ts +52 -0
  17. package/examples/cafe/generated/books.queries.ts +11 -0
  18. package/examples/cafe/generated/books.rules.ts +42 -0
  19. package/examples/cafe/generated/kitchen.elements.ts +87 -0
  20. package/examples/cafe/generated/kitchen.queries.ts +47 -0
  21. package/examples/cafe/generated/kitchen.rules.ts +98 -0
  22. package/examples/cafe/generated/menu.elements.ts +61 -0
  23. package/examples/cafe/generated/menu.queries.ts +28 -0
  24. package/examples/cafe/generated/menu.rules.ts +65 -0
  25. package/examples/cafe/generated/order.elements.ts +87 -0
  26. package/examples/cafe/generated/order.queries.ts +47 -0
  27. package/examples/cafe/generated/order.rules.ts +95 -0
  28. package/examples/cafe/generated/staff.elements.ts +55 -0
  29. package/examples/cafe/generated/staff.queries.ts +27 -0
  30. package/examples/cafe/generated/staff.rules.ts +59 -0
  31. package/examples/cafe/generated/supplies.elements.ts +62 -0
  32. package/examples/cafe/generated/supplies.queries.ts +43 -0
  33. package/examples/cafe/generated/supplies.rules.ts +84 -0
  34. package/examples/cafe/generated/till.elements.ts +93 -0
  35. package/examples/cafe/generated/till.queries.ts +57 -0
  36. package/examples/cafe/generated/till.rules.ts +113 -0
  37. package/examples/cafe/index.html +70 -0
  38. package/examples/cafe/kitchen.css +107 -0
  39. package/examples/cafe/kitchen.html +39 -0
  40. package/examples/cafe/kitchen.ts +125 -0
  41. package/examples/cafe/menu.html +55 -0
  42. package/examples/cafe/menu.json +41 -0
  43. package/examples/cafe/menu.ts +84 -0
  44. package/examples/cafe/migrations/001-cafe.ts +11 -0
  45. package/examples/cafe/order.html +37 -0
  46. package/examples/cafe/order.ts +45 -0
  47. package/examples/cafe/rail-drag.ts +30 -0
  48. package/examples/cafe/routes.ts +32 -0
  49. package/examples/cafe/staff.json +20 -0
  50. package/examples/cafe/stories.jsonl +43 -0
  51. package/examples/cafe/supplies.html +77 -0
  52. package/examples/cafe/supplies.json +33 -0
  53. package/examples/cafe/supplies.ts +170 -0
  54. package/examples/cafe/till.json +95 -0
  55. package/examples/cafe/till.ts +122 -0
  56. package/examples/cafe/trust.ts +20 -0
  57. package/examples/cafe/views.ts +171 -0
  58. package/examples/docs.ts +28 -0
  59. package/examples/film.jpg +0 -0
  60. package/examples/hello/generated/elements.ts +45 -0
  61. package/examples/hello/generated/queries.ts +24 -0
  62. package/examples/hello/generated/rules.ts +45 -0
  63. package/examples/hello/hello.css +27 -0
  64. package/examples/hello/hello.json +1 -0
  65. package/examples/hello/index.html +32 -0
  66. package/examples/hello/migrations/001-hello.ts +6 -0
  67. package/examples/hello/page.ts +49 -0
  68. package/examples/hello/routes.ts +6 -0
  69. package/examples/hello/stories.jsonl +3 -0
  70. package/examples/index.html +146 -0
  71. package/examples/page.ts +11 -0
  72. package/examples/people/adding.ts +20 -0
  73. package/examples/people/generated/elements.ts +68 -0
  74. package/examples/people/generated/queries.ts +28 -0
  75. package/examples/people/generated/rules.ts +85 -0
  76. package/examples/people/links.ts +124 -0
  77. package/examples/people/migrations/001-people.ts +6 -0
  78. package/examples/people/migrations/002-add-people-member-and-guard-people.ts +7 -0
  79. package/examples/people/migrations/003-add-people-rank-and-guard-people.ts +7 -0
  80. package/examples/people/order.ts +61 -0
  81. package/examples/people/people.css +65 -0
  82. package/examples/people/people.json +26 -0
  83. package/examples/people/routes.ts +12 -0
  84. package/examples/people/stories.jsonl +20 -0
  85. package/examples/people/trust.ts +14 -0
  86. package/examples/people/view.ts +115 -0
  87. package/examples/routes.ts +11 -0
  88. package/examples/trip/answer-rows.ts +70 -0
  89. package/examples/trip/answers.ts +11 -0
  90. package/examples/trip/bar.ts +89 -0
  91. package/examples/trip/calendar-map.css +709 -0
  92. package/examples/trip/calendar-map.ts +249 -0
  93. package/examples/trip/drags.ts +143 -0
  94. package/examples/trip/drawer.ts +250 -0
  95. package/examples/trip/event-form.ts +199 -0
  96. package/examples/trip/generated/elements.ts +144 -0
  97. package/examples/trip/generated/queries.ts +46 -0
  98. package/examples/trip/generated/rules.ts +239 -0
  99. package/examples/trip/holding.ts +61 -0
  100. package/examples/trip/ics.ts +117 -0
  101. package/examples/trip/index.html +82 -0
  102. package/examples/trip/line-stops.ts +92 -0
  103. package/examples/trip/line-words.ts +79 -0
  104. package/examples/trip/line.ts +121 -0
  105. package/examples/trip/map.ts +234 -0
  106. package/examples/trip/mercator.ts +28 -0
  107. package/examples/trip/migrations/001-trip.ts +7 -0
  108. package/examples/trip/migrations/002-add-events-zone-and-guard-events.ts +7 -0
  109. package/examples/trip/migrations/003-guard-events-and-create-events_asked-and-more.ts +9 -0
  110. package/examples/trip/migrations/004-create-stays.ts +6 -0
  111. package/examples/trip/migrations/005-guard-events-and-create-events_arrives-and-more.ts +8 -0
  112. package/examples/trip/month.ts +87 -0
  113. package/examples/trip/other-weeks.ts +67 -0
  114. package/examples/trip/page.ts +121 -0
  115. package/examples/trip/peek.ts +71 -0
  116. package/examples/trip/people-chips.ts +74 -0
  117. package/examples/trip/place-search.ts +51 -0
  118. package/examples/trip/places.ts +34 -0
  119. package/examples/trip/routes.ts +27 -0
  120. package/examples/trip/shell.ts +39 -0
  121. package/examples/trip/stays.css +51 -0
  122. package/examples/trip/stays.ts +68 -0
  123. package/examples/trip/stories.jsonl +72 -0
  124. package/examples/trip/time.ts +46 -0
  125. package/examples/trip/told.ts +48 -0
  126. package/examples/trip/trip.json +69 -0
  127. package/examples/trip/trust.ts +51 -0
  128. package/examples/trip/week.ts +237 -0
  129. package/examples/trip/words.ts +4 -0
  130. package/examples/trip/writes.ts +91 -0
  131. package/examples/trip/zones.ts +16 -0
  132. package/examples/trips/card.ts +149 -0
  133. package/examples/trips/generated/elements.ts +60 -0
  134. package/examples/trips/generated/queries.ts +28 -0
  135. package/examples/trips/generated/rules.ts +62 -0
  136. package/examples/trips/index.html +47 -0
  137. package/examples/trips/map.ts +52 -0
  138. package/examples/trips/migrations/001-trips.ts +8 -0
  139. package/examples/trips/new-trip.ts +46 -0
  140. package/examples/trips/page.ts +9 -0
  141. package/examples/trips/routes.ts +7 -0
  142. package/examples/trips/stories.jsonl +12 -0
  143. package/examples/trips/trips.css +183 -0
  144. package/examples/trips/trips.json +7 -0
  145. package/examples/weeks/derive.ts +23 -0
  146. package/examples/weeks/generated/elements.ts +52 -0
  147. package/examples/weeks/generated/rules.ts +33 -0
  148. package/examples/weeks/routes.ts +4 -0
  149. package/examples/weeks/weeks.json +1 -0
  150. package/examples/welcome.css +299 -0
  151. package/package.json +55 -4
  152. package/src/attachment.ts +70 -0
  153. package/src/cli.ts +52 -0
  154. package/src/client.ts +98 -0
  155. package/src/compile.ts +2034 -0
  156. package/src/css.d.ts +5 -0
  157. package/src/definitions.ts +268 -0
  158. package/src/demo.css +29 -0
  159. package/src/demo.ts +42 -0
  160. package/src/draft.ts +69 -0
  161. package/src/engine.ts +288 -0
  162. package/src/file-value.ts +13 -0
  163. package/src/files.ts +187 -0
  164. package/src/follow.ts +56 -0
  165. package/src/hues.ts +3 -0
  166. package/src/icon-names.ts +77 -0
  167. package/src/icon.png +0 -0
  168. package/src/icons.ts +32 -0
  169. package/src/keep.ts +33 -0
  170. package/src/link.ts +31 -0
  171. package/src/mcp.ts +252 -0
  172. package/src/members/demo.ts +53 -0
  173. package/src/members/generated/elements.ts +68 -0
  174. package/src/members/generated/queries.ts +29 -0
  175. package/src/members/generated/rules.ts +65 -0
  176. package/src/members/group.ts +294 -0
  177. package/src/members/keys.ts +221 -0
  178. package/src/members/members.json +9 -0
  179. package/src/members/migrations/001-members.ts +6 -0
  180. package/src/members/migrations/002-guard-members.ts +11 -0
  181. package/src/members/migrations/003-add-members-act-and-guard-members.ts +7 -0
  182. package/src/members/panel.css +208 -0
  183. package/src/members/panel.ts +398 -0
  184. package/src/members/routes.ts +4 -0
  185. package/src/members/stories.jsonl +27 -0
  186. package/src/members/trust.ts +116 -0
  187. package/src/migrate.ts +597 -0
  188. package/src/migrations/001-joined.ts +13 -0
  189. package/src/migrations/002-group-keys.ts +16 -0
  190. package/src/migrations/003-change-inverse.ts +10 -0
  191. package/src/migrations/004-change-followed.ts +6 -0
  192. package/src/ops.ts +61 -0
  193. package/src/page.css +79 -0
  194. package/src/page.ts +413 -0
  195. package/src/parts.css +471 -0
  196. package/src/parts.ts +152 -0
  197. package/src/server.ts +862 -0
  198. package/src/settings.ts +94 -0
  199. package/src/starter.ts +89 -0
  200. package/src/store.ts +815 -0
  201. package/src/stories.ts +387 -0
  202. package/src/toast.ts +52 -0
  203. package/src/together.ts +167 -0
  204. package/src/tokens.css +85 -0
  205. package/src/tokens.json +457 -0
  206. package/src/upkeep.ts +86 -0
  207. package/src/visitors.ts +43 -0
  208. package/src/write.ts +567 -0
  209. package/starter/CLAUDE.md +37 -0
  210. package/starter/gitignore +3 -0
  211. package/starter/tests/hello-page.test.ts +14 -0
  212. package/starter/tests/hello.test.ts +8 -0
  213. package/starter/tsconfig.json +17 -0
@@ -0,0 +1,768 @@
1
+ # joined: reference
2
+
3
+ | # | Task | Where it's shown working |
4
+ |---|---|---|
5
+ | 1 | [Start an app](#1-start-an-app) | `examples/hello/` |
6
+ | 2 | [Stories, the source](#2-stories-the-source) | `examples/people/stories.jsonl` (the smallest with members), `examples/trip/stories.jsonl`, `tests/compile.test.ts` |
7
+ | 3 | [What the compiler writes](#3-what-the-compiler-writes) | `examples/trip/generated/` |
8
+ | 4 | [A view: an item element given a look](#4-a-view-an-item-element-given-a-look) | `examples/trip/stays.ts` (the smallest), `examples/hello/page.ts` (a Draft), `examples/cafe/menu.ts` (a drawer) |
9
+ | 5 | [A display: a collection drawn in a shadow](#5-a-display-a-collection-drawn-in-a-shadow) | `examples/cafe/kitchen.ts` (the smallest), `examples/cafe/rail-drag.ts` (a drag), `examples/trip/calendar-map.ts` (grown, a part a file) |
10
+ | 6 | [Links between documents](#6-links-between-documents) | an event's `people`; `examples/people/links.ts` |
11
+ | 7 | [Several documents on a page](#7-several-documents-on-a-page) | `examples/cafe/index.html`, `examples/trip/index.html` |
12
+ | 8 | [Routes: pages and edges](#8-routes-pages-and-edges) | `examples/hello/routes.ts`, `examples/cafe/routes.ts`, `examples/trip/routes.ts` |
13
+ | 9 | [Stylesheets](#9-stylesheets) | `examples/hello/hello.css`, `examples/cafe/kitchen.css` (a display's), `examples/trip/calendar-map.css` |
14
+ | 10 | [Icons](#10-icons) | `src/icons.ts` |
15
+ | 11 | [The group: sign-in by link](#11-the-group-sign-in-by-link) | `src/members/`, `tests/sign-in.test.ts` |
16
+ | 12 | [Tests](#12-tests) | `tests/pages.test.ts` (hello's), `tests/cafe.test.ts`, `tests/examples.test.ts` |
17
+ | 13 | [Traps](#13-traps) | met while building |
18
+ | 14 | [Seeds, the store, and running it elsewhere](#14-seeds-the-store-and-running-it-elsewhere) | `examples/trip/trip.json`, `src/store.ts`, `src/migrate.ts` |
19
+ | 15 | [What stories can't show: definitions, an app's own rules, a kind](#15-what-stories-cant-show-definitions-an-apps-own-rules-a-kind) | `examples/cafe/stories.jsonl`, `src/definitions.ts` |
20
+
21
+ ## 1. Start an app
22
+
23
+ **A project of its own:** `bun create joined my-app` (create-joined, `create/`) makes the folder, adds joined
24
+ (`joined@npm:@blueshed/joined`: its name in an app is `joined`), and runs `joined init` there: hello in `apps/`,
25
+ `apps/app.css`, this skill, a CLAUDE.md, a `.gitignore`, a `tsconfig.json`, a test telling hello's stories, and
26
+ the scripts (`dev`, `compile`, `start`, `link`, `upgrade`, `test`); then a first commit. hello is there to be
27
+ replaced: it answers `/`, so an app of one's own that takes the root deletes `apps/hello/` and its tests first (two
28
+ apps answering one path are refused at start). `joined init` in a folder of
29
+ one's own does the same, never over what's there. `bun run upgrade [version]` (`joined upgrade`) moves joined (the newest, if none
30
+ is said), refreshes this skill and compiles again. To try joined before it's published, `bun run pack` makes
31
+ `.pack/blueshed-joined-<version>.tgz`, and `JOINED_FROM=<it> bun create/index.ts my-app` makes an app on it
32
+ (`tests/starter.test.ts` does that).
33
+
34
+ An app is a folder under `examples/` (in a project using joined, `apps/`), named for its document:
35
+
36
+ ```
37
+ examples/notes/
38
+ stories.jsonl what happens to the document, one story a line (§2)
39
+ notes.json the seed: { "version": 1, "notes": [ … ] }, where the stories start
40
+ migrations/ its tables, written by bun run compile from the stories (§3): commit them
41
+ routes.ts export * as document from "./generated/rules.ts"; export const routes = { "/notes": page }
42
+ index.html the page: links joined/tokens.css, joined/page.css, ../app.css and ./notes.css, holds
43
+ <members-panel></members-panel> and <j-notes>
44
+ page.ts defines the item element (as it is, or a view), imports joined/panel
45
+ notes.css how the document's elements look
46
+ ```
47
+
48
+ Then `bun run compile`, add a link to the root page (`examples/index.html`), and `bun run dev`. The
49
+ server finds the app by its `routes.ts` and nothing else. A document that other pages hold, and
50
+ has no page of its own, needs only its stories, its seed and `routes.ts`, as `examples/people/` does.
51
+
52
+ Working: `examples/hello/`, the smallest: anyone's, so no group, no `<members-panel>` and no collection (its
53
+ element is the document); with the group and a collection, `examples/trips/`.
54
+
55
+ **An app imports joined by its name, never by a path into `src/`,** as a project that takes joined as
56
+ a dependency would; `tests/package.test.ts` refuses `../src/` under `examples/`. The names are
57
+ `package.json`'s `exports`: `joined/page` (`Answer`, `ask`), `joined/keep` (`keep`, `Row`), `joined/draft`,
58
+ `joined/parts` (`PARTS`, `face`, `said`, `askFirst`, `showsOpen`, `inHash`, `typeahead`), `joined/follow` (`follow`,
59
+ `held`), `joined/icons`, `joined/hues` (`hueOf`), `joined/panel` (`members`, `signedIn`, `group`: §11), `joined/toast`, `joined/client` (`open`),
60
+ `joined/stories` (`tell`), `joined/migrate`, `joined/server` (the type `Read`), `joined/compile`; and in a page's HTML
61
+ `joined/tokens.css`, `joined/page.css`, `joined/icon.png` (`joined/parts.css` and `joined/tokens.json` are there for
62
+ a design system). The compiler writes `joined/page` and `joined/migrate` too.
63
+
64
+ **A project of its own** takes joined as a dependency and keeps its apps in `apps/`: `joined compile`,
65
+ `joined start` and `joined link <name>` (`src/cli.ts`) run there, its data in `.data/` there. joined's
66
+ own scripts are the same command given `examples` (`tests/package.test.ts`). Each app's stories are told in a browser too (`inBrowser`, `tests/stories-in-browser.test.ts`):
67
+ a new document with a page needs its page named there. A member's page outside a browser:
68
+ `joined page show|watch|write <doc>` by their link in `JOINED_LINK` (never printed), or `joined/client`'s `open(link)`
69
+ in a program: `hold(doc)` (its `now()`, and `on(change)`), `write(doc, ops, why)` (`tests/client.test.ts`). To try a change as such a
70
+ project would, `bun pm pack` makes the package (`src/` alone), and a folder elsewhere takes the tarball as
71
+ its dependency, with apps copied in, their `generated/` left out.
72
+
73
+ ## 2. Stories, the source
74
+
75
+ A story is one JSON line in dzql's words:
76
+
77
+ ```jsonl
78
+ {"cast":{"phone":"peter","stranger":null}}
79
+ {"story":"The dinner runs longer","as":"peter","does":{"doc":"trip","ops":[{"op":"replace","path":"/events/2/duration","value":"PT3H"}]},"seen":["peter","phone"]}
80
+ {"story":"An event needs a start","as":"peter","cannot":{"doc":"trip","ops":[{"op":"add","path":"/events/-","value":{"title":"Sometime","duration":"PT1H"}}]}}
81
+ ```
82
+
83
+ - `as` is who tells it: a member's name, or a name the `cast` line gives (`null` is nobody, refused
84
+ at the door). A `cannot` may say `refused`: the words it's refused in, matched as they are, so copy them from
85
+ what the server says (`bun test` prints them when they differ). `seen` is every page that must hear it. A write may carry `why`, and a removal or
86
+ making someone read-only must.
87
+ - A `does` may say what it leaves: `then`, each path and the value it holds after, as the teller's page holds
88
+ the document (compared as JSON). A path names an item's field (`/orders/6/total`), the document's own
89
+ (`/greeting`) or an item whole (`/members/4`); another document's, its name before it
90
+ (`menu/items/5/stock`, a croissant taken at the till). Hearing says who's told; `then` says what's left:
91
+ `{"/members/4/inviter": 2}`, a move-up. The compiler refuses it on a `cannot`.
92
+ - A `does` (or `cannot`) may be a list of writes, one write all the same: all of it or none, each part held to its
93
+ own document's rules and told to its own pages (`"does":[{"doc":"boards",…},{"doc":"board:$1",…}]`). `"$n"` is
94
+ the write's nth add, whichever part made it: in a value its id (`"section":"$2"`), as a part's document the
95
+ instance of a kind it made (`board:$1`), only by an add to the kind's root. The compiler grants and types each
96
+ part of a `does` as one write's, in its document's app, the parts before it written first. A `cannot` of several
97
+ is refused whole, so it checks no role, owns or rule over values: say those with a cannot of one write. `then`
98
+ names the instance as it will be (`board:3/posts/4/section`). Working: `tests/together`.
99
+ - Without `as`, a story is anonymous: the core alone (no `seen`, `unseen` or `why`; its `premise` a list
100
+ of writes), told with nobody signed in. A project whose stories are all anonymous has no members. The
101
+ grammar, and what the compiler refuses: `docs/stories.md`.
102
+ - The model is only what the `does` stories do:
103
+ - **A collection** is a path's first step (`/events`), named in the plural.
104
+ - **A field** is a key an add gives or a replace names. Its type is its values': a string, or one
105
+ read off its form (a date-time `2026-11-07T19:00:00`, a time zone `Asia/Tokyo`, an instant `2026-11-07T10:00:00Z`, a duration `PT2H`, a place `geo:35.69,139.70`, a file `file:<its SHA-256>.webp`, one kept by `/files`, §8),
106
+ a boolean, an integer or a decimal (a value with a fraction), or a list of ids (§6). A value not its
107
+ form is refused in words.
108
+ - **A field is needed** if every add gives it. A story more that leaves it out lets it go:
109
+ `bun run compile` says so, naming the story.
110
+ - **An op is allowed** only if a story does it.
111
+ - **A field may be removed** if a story removes it (`remove /events/2/location`) and it isn't
112
+ needed.
113
+ - The compiler refuses, naming the story:
114
+ - a field typed two ways;
115
+ - a name that can't be an attribute;
116
+ - a path no op can have;
117
+ - a list of ids named for no collection;
118
+ - an empty list nothing else types;
119
+ - a collection that isn't a regular plural;
120
+ - two documents with a collection of one name.
121
+
122
+ Working: `examples/trip/stories.jsonl`; the model's rules in `tests/compile.test.ts`.
123
+
124
+ ## 3. What the compiler writes
125
+
126
+ `bun run compile` writes each app's `generated/`, the same every time (a test checks it):
127
+
128
+ - **`rules.ts`:**
129
+ - `doc`;
130
+ - `collections`, each `{ place: "j-events", tag: "j-event", fields }`;
131
+ - `grants`, each op a story does and the roles whose stories do it; `rolesOf`, `sees`, `holds` where the
132
+ definitions say them; `inWindow` and `triggers` where they say a window or a rule over values (`takes`);
133
+ and `query` and `items`, from `queries.ts`. What a value may be is the
134
+ tables': each its CHECK, named for the words it's refused in (`migrations/`, `guardTable`).
135
+ - **`elements.ts`:**
136
+ - **The collection's element** (`JEvents`, defined there): `items`, and `add(...values)`, one write
137
+ for them all, each a `JEventValue`: the fields as the stories write them, a dotted one nested (`terms: { days
138
+ }`), and a link to one item its id or an add's before it in the same write (`"$1"`, the till's lines naming
139
+ their order). On a page it holds its document (§7). An app's own `write(el, ops)` is typed the same.
140
+ - **The item's element** (`JEvent`, defined by the page, as it is or extended by a view, §4):
141
+ - `key`, `path` and `data` (its fields, read from its attributes; a missing number reads as
142
+ `undefined`, a boolean as `false`, a list as `[]`);
143
+ - and only the ops the stories allow, named for them: `replace({ field: value, … }, why?)` (one
144
+ write; a list of ids the stories link and unlink is written as the ids added and taken),
145
+ `link("field", id)` and `unlink("field", id)`, `removeField("field", …)`, `removeItem(why?)` (not
146
+ `remove()`, which is the DOM's own). Each returns its refusal (an `Answer` from `joined/page`:
147
+ its why, or nothing), and never rejects. **Two routes, a law:** a request's answer matters only when
148
+ it's refused, and only to whoever sent it: say why beside what sent it (`said(line, request)`, a
149
+ Draft's `refuse()`). What a write did comes on the broadcast, as every change does, to every page,
150
+ the writer's own included: never wait on a write's success, nor match a change to the request that
151
+ made it.
152
+ - **`write(from, ops, why?)`:** one write across the document's collections (a move with its legs),
153
+ sent from any element of it; its ops typed as the stories allow them (`<Doc>Op`), so one they don't
154
+ is a type error; it returns the write's answer too. Working: `tests/fixtures/ledger/page.ts`.
155
+
156
+ - **`migrations/NNN-<what>.ts`,** in `src/migrate.ts`'s words (`createTable`, `addColumn`…), when the stories
157
+ say more than the migrations so far: a collection is a table, a field a column (null where a story
158
+ or the seed may leave it out), a list of ids a table of pairs, `<collection>_<field>`. The same
159
+ history makes the tables in SQLite now and in Postgres later. A rename it can't know: it says so
160
+ (`by hand:`), and a person makes it `renameColumn`. A column made optional, its type as it was, the
161
+ compiler writes itself (in a `guardTable`); a type changed, or a column made needed, is a person's.
162
+ A `guardTable` that makes a SQLite table again keeps the rows linking to it (its foreign keys are off
163
+ while it runs, and checked whole before it commits). Never change one that has run anywhere.
164
+ - **Rows too: `export const up = (db, { nextId }) => …`** beside `changes` (or alone), run after them in
165
+ their transaction: SQL that moves or fills rows, as a changed type or a column made needed asks. A row
166
+ it adds takes `nextId("table")`; never write `joined_sequences` yourself. Synchronous: one that
167
+ awaits is refused, and rolled back. Working: `tests/migrate.test.ts`.
168
+
169
+ Never edit `generated/`. Change the stories, and compile.
170
+
171
+ Working: `examples/trip/generated/`.
172
+
173
+ ## 4. A view: an item element given a look
174
+
175
+ Extend the compiled item element, draw from its attributes, and send its own ops:
176
+
177
+ ```ts
178
+ class Greeting extends JGreeting {
179
+ #text = document.createElement("span");
180
+ #gone = iconButton("remove", "", () => this.removeItem());
181
+ connectedCallback() {
182
+ if (this.childElementCount) return this.draw(); // once: an element moved isn't made again
183
+ this.append(this.#text, this.#gone);
184
+ this.draw();
185
+ }
186
+ draw() { // called whenever an attribute changes
187
+ this.#text.textContent = this.data.text;
188
+ this.#gone.ariaLabel = `Remove ${this.data.text}`; // what names it, kept as it changes
189
+ }
190
+ }
191
+ // … every const the view draws with, then, last of all:
192
+ customElements.define(collections.greetings.tag, Greeting);
193
+ ```
194
+
195
+ A document's own element (`<j-hello>`, hello's) holds the document as it connects: its view calls
196
+ `super.connectedCallback()` first. An item's element has none to call.
197
+
198
+ The compiled element calls `draw()` whenever an attribute changes: a view needs no
199
+ `attributeChangedCallback`. `data` is read once until an attribute changes, and frozen: never change
200
+ it. Never set the element's own attributes: the applier does, from what the server sends back. On a
201
+ refusal (what the op returns), call `draw()` to show the document as it is.
202
+
203
+ **Offer only what this person may do: its `may`.** The applier sets a `may` attribute, space-separated, as
204
+ the server works it out from the grants and the person's roles (the same a write is held to, per item where a
205
+ role is the item's own, `@supplier`), kept so as the document and the roles change: on the collection's element
206
+ `add`; on an item's `remove`, `replace:price`, `replace:terms.days`, `remove:due`, `add:people[]` and
207
+ `remove:people[]` (an id of a list), and a move from where it is, `replace:status>being%20made` (the step's
208
+ value as a URL's, so a space doesn't part it); on a document's own element (`<j-hello>`), `replace:greeting`.
209
+ None: nothing. `draw()` is called when it changes too. A view offers by it, `this.matches('[may~="remove"]')`,
210
+ and CSS hides by it, `main:not(:has(j-orders[may~="add"])) form.place`. It's the stories' grants: an app's own
211
+ `trust.ts` may still refuse, and `may` never knows it, so a rule a role can say belongs in the stories, where `may`
212
+ offers it to that person alone. "Only who added an item may remove it" is a role, the item's own:
213
+ `{"roles":{"adder":"@adder"}}`, and the remove story told `as` "adder" (the cafe's `@buyer` and `@supplier`). `trust.ts`
214
+ is for what no role can say. No story's field may be named `key` or `may`. Working: `examples/cafe/views.ts`,
215
+ `supplies.ts`, `cafe.css`.
216
+
217
+ Words are changed in a drawer (`.drawer`, a part: `src/parts.css`), or a form on the page: it holds them as a
218
+ draft, as the document has them until they're changed there, and Save sends the changes in one
219
+ `replace()`; Never mind puts them back. Taking one away asks first, in a `<dialog>`: `askFirst(dialog)`
220
+ from `joined/parts` wires its Never mind (`keep`) and its deed (`sure`), and returns the way to ask it,
221
+ `ask(question, deed)`. The page's line, `#said`, says a request's refusal, emptied as the next is sent:
222
+ `said(line)`, from `joined/parts`. A page's reading (a filter, a calendar or a line) is in its address's query, `?view=line`, read as it loads and
223
+ said with `history.replaceState` as it changes, so a link opens it so (`examples/trip/page.ts`, `address`). What's
224
+ open in a drawer is in the URL's hash (`#event=2`), so Back closes it
225
+ and a link opens it: `inHash(name, items, picked, show, signal?)` from `joined/parts` returns `mark(key)`, called as one
226
+ is opened or closed, and `again()`, called as the items change, to open one named before it was there (the trip's
227
+ `<calendar-map>`). Its `signal` lets it go with the display.
228
+
229
+ The draft is `Draft` from `joined/draft`, given the form (Save named `go`, Never mind `never`) and
230
+ its note. `fill(saved, afresh)` sets the controls as the document has the item: afresh, all of
231
+ them; on a change from elsewhere (call it from the `MutationObserver`), only those not being
232
+ changed here. `edits()` is what's changed, by control name; `show("kept" | "changed" | "new")` says
233
+ so and turns Save and Never mind on or off; `refuse(why)` says a refusal until `refuse("")`. What the
234
+ changes are as ops (a time made a duration, an emptied field cleared) stays the page's own.
235
+
236
+ Working, smallest first:
237
+ - `examples/trip/stays.ts`: a view of an item (its name changed in place, a way to cancel it), and a form that adds.
238
+ - `examples/hello/page.ts`: a document's own element, and the smallest `Draft` (a form on the page, following the
239
+ greeting changed elsewhere).
240
+ - `examples/cafe/menu.ts`: the smallest drawer: an item changed in it, a `Draft` until Save, what's open in the
241
+ address (`inHash`), offered by `may` alone.
242
+ - `examples/cafe/till.ts` and `views.ts`: `askFirst`, and offering by `may`; the till's items how many are wanted of
243
+ how many are left.
244
+ - `examples/people/view.ts` (a person's row), `links.ts` (what links to them, kept as links come and go), `order.ts`
245
+ (dragged by a grip), `adding.ts` (the page's form).
246
+ - `examples/trip/event-form.ts` with `drawer.ts` and `writes.ts`: a `Draft` grown, in a drawer, its fields derived (a
247
+ time made a duration), its parts a file each (`zones.ts`, `place-search.ts`, `people-chips.ts`, `answer-rows.ts`).
248
+
249
+ A file field (a post's photo, a PDF) is `attachment(doc, put, take?)` from `joined/attachment`: `el` to append, and
250
+ `draw(value, { put, take })` called from the view's `draw()` with the item's value and its `may`
251
+ (`[may~="replace:attachment"]`, `[may~="remove:attachment"]`). A file chosen is sent to `/files` for `doc()` (the
252
+ collection's `doc` attribute, a guest's with its code), and its value put by `put` (`this.replace({ attachment })`,
253
+ or an add form's field); `take` is `this.removeField("attachment")`. A photo or an SVG is its picture, a PDF a link. Working:
254
+ `tests/attachments/board/page.ts`.
255
+
256
+ ## 5. A display: a collection drawn in a shadow
257
+
258
+ A display holds the collection's element as its child (`<calendar-map><j-events></j-events></calendar-map>`).
259
+ It never shows it, and draws its items in its shadow DOM:
260
+
261
+ - **Watch it** with a `MutationObserver` on itself (`childList`, `subtree`, `attributes`). Its
262
+ records name the item and the attribute that changed.
263
+ - **Read what it holds from live lists,** `this.getElementsByTagName(collections.orders.tag)`, made once: never a
264
+ search on each change. A tag is the compiler's collections', never typed out (`tests/examples.test.ts` holds every
265
+ example to it).
266
+ - **On the page it listens; off it, it lets go.** Its observers, timers and listeners beyond itself (the window, the
267
+ document, another collection) are undone in `disconnectedCallback` (the kitchen's), or given a signal that's
268
+ aborted there (the calendar's `#gone`, which builds it again if it's put back). A move connects it again at once.
269
+ - **Keep what you draw by key, and move only what changed.** For lists, `keep()` from
270
+ `joined/keep`: a row is made again only when what it shows (a string of what it draws from) has
271
+ changed, and never while it holds focus; the rest are moved into order, never made again. A row
272
+ kept outlives the moment it was made: what it acts on (who's chosen, say) is read when it's pressed.
273
+ - **Watch another collection for what you show of it, alone** (`attributeFilter`), and place again
274
+ only the items that link to what changed: a redraw that changes nothing then costs nothing.
275
+ - **Change the document only through the item's ops** (`el.replace({ start })`), never by setting
276
+ an attribute. Let the drawing follow the pointer while dragging; on letting go, hold the change
277
+ as a draft (a drawer's form), drawn where it puts the item, with the saved one faint behind. Save
278
+ sends the draft in one write, Never mind puts it back; on a refusal, keep the draft and draw the
279
+ rest from the document.
280
+ - **Never ask for typing that a hand can do:** a drag gives when, a pin gives where (and its
281
+ name, asked of Photon); the form asks only the rest.
282
+ - **Its look** is its own stylesheet, adopted in the shadow (§9). Its icons go in with
283
+ `iconify(this.#root)` (§10).
284
+ - **Another display's request** comes as an event on the item: `pick`, bubbling, is how the
285
+ people's links pick an event on the calendar.
286
+
287
+ Working: `examples/cafe/kitchen.ts`, the smallest (about 130 lines: tickets kept by `keep` in columns, a ticket made
288
+ again only as its order changes, the waits each minute), and `examples/cafe/rail-drag.ts`, the smallest drag (30
289
+ lines, `follow` and `held`); `examples/trip/calendar-map.ts`, the same grown, the file that composes its parts (one
290
+ change moves one block and one pin): `week.ts` (the calendar), `map.ts` (tiles, pins, pan, pinch), `month.ts`,
291
+ `peek.ts`, `drawer.ts` and `writes.ts` (the form's drawer and its writes), `drags.ts` (what a hand gives), `holding.ts`
292
+ (its events, read once a change), `told.ts` (the lists it's told of), `bar.ts`, `other-weeks.ts`, `shell.ts`; and
293
+ `src/members/panel.ts`. **One concept a file, under 250 lines** (`tests/examples.test.ts` holds every example to it).
294
+
295
+ ## 6. Links between documents
296
+
297
+ A field that's a list of ids, named for another document's collection, links to its items: an
298
+ event's `people: [1, 3]`. The name is the rule, not a guess.
299
+
300
+ - **The rules check it.** Every id must be in that document. An item anything links to can't be
301
+ removed, by a list or one id, named for its collection or declared (§15): "1 event in trip links to
302
+ it". A link to the group's members is the exception: a member can be removed (the group's rules say who may),
303
+ and what linked to them is cleared, the field none, so an app says what an item that was theirs becomes (the
304
+ shopping list Haiku built: anyone may take it off).
305
+ - **A list changes by the id:** a story that adds one (`/events/2/people/-`, an id) and takes one
306
+ (`/events/2/people/3`) lets two people link at once, and both land; `replace({ people })` then writes
307
+ only the ids added and taken.
308
+ - **On the page it's an IDREFS attribute,** `people="1 3"`, so CSS finds the links:
309
+ `[people~="2"]` is everything that links to person 2, in any document.
310
+ - **A display watches the linked document** too: `<calendar-map people="people">` names where the
311
+ people are, and observes it.
312
+
313
+ Working: the trip's events and `examples/people/links.ts` (what links to a person, kept as links come and go, and
314
+ `pick`); within one document, a line's `order` (`examples/cafe/views.ts`).
315
+
316
+ ## 7. Several documents on a page
317
+
318
+ Put each document's collection element on the page: that's all it takes to hold it. The page has
319
+ one socket, whatever it holds (a browser keeps few connections to a host, and every tab is one more):
320
+ it subscribes to each document (`{ subscribe: doc }`), is sent it whole, then every change. An element's ops go on
321
+ it named for their document, and each answers only its sender, and only with a refusal. A document
322
+ that isn't there is refused to the element holding it (a `refused` event on it). Taken off the
323
+ page (not moved: a move keeps its items), a collection's element lets its document go: its items with
324
+ it, and with the document's last element gone, `{ unsubscribe: doc }`. Put back, it's subscribed again, whole;
325
+ and so is one put back while another of its document's collections kept it held (it asks again with no version).
326
+ The server logs each write a page sends as one line: `write trip by member 1: done, version 12`, or
327
+ `refused, <why>` (quiet under `bun test`; `start({ log })` takes another).
328
+
329
+ When the socket drops (a phone asleep, a redeploy), the page is away (`body[data-away]`, and the
330
+ `away` event; `back` when it returns; the group's button says "· back soon"):
331
+ what it sends is refused at once, and it comes back by itself, each document put in place by key. Only
332
+ the server closing it on purpose, or the door refusing it, signs it out. A write refused, draw again,
333
+ and a display shows nothing as saved that wasn't. A socket can die with no close (the browser still calls it
334
+ open): woken, or its network back, the page asks it (`{ subscribe, id: 0 }`, answered `{ done: 0 }`), and one
335
+ that doesn't answer in 5 seconds is let go, and the page is away.
336
+
337
+ Each socket is told the server's build first (`{ build }`: the release and a hash of every app's `generated/`, read
338
+ at start; `/version` and `<body data-build>` say it too). A page served by another (a deploy, a restart with the
339
+ stories compiled anew) reloads: at once, or, while a write is unanswered or a draft shown holds changes
340
+ (`unsaved()`, `joined/draft`), once they're saved or closed, the toast saying so meanwhile. A page that holds
341
+ what's typed outside a `Draft` would lose it.
342
+
343
+ Working: `examples/cafe/index.html`, the till's page, holds the menu, the till's orders and lines, and the members;
344
+ `examples/trip/index.html` the trip, its weeks, the people, the stays and the members.
345
+
346
+ A write of several documents is one message, `{ id, writes: [{ doc, ops, why? }, …] }`, sent by `together(writes)`
347
+ from `joined/page`: each part a document the page holds, or one the write makes (`board:$1`), each asked in the
348
+ write's transaction whether its writer may hold it, and the rules a write to it is held to. It's answered as one
349
+ write. A document each person sees only some of is told a write's parts on it as one change.
350
+
351
+ ## 8. Routes: pages and edges
352
+
353
+ `routes.ts` is an app's one way in, and all the server imports of it:
354
+
355
+ ```ts
356
+ import page from "./index.html";
357
+ export * as document from "./generated/rules.ts";
358
+ export const routes = { "/hello": page }; // Bun's routes object
359
+ // or, where an edge needs a document, read as whoever asks sees it:
360
+ export const routes = (read: Read) => ({ "/trip/:n": page, "/trip/:n/trip.ics": (req, who) => new Response(toIcs(read(`trip:${req.params.n}`, who?.member).events, "The trip")) });
361
+ ```
362
+
363
+ - **A page** is anyone's: signed out, it shows the note to sign in. It's served with its documents in it:
364
+ each collection element filled with its items as its person sees them, each document's version on
365
+ `<body>`, so it subscribes with `since` (`tests/render.test.ts`). A display draws the items it finds.
366
+ - **An edge** (a function, or `{ GET, POST }`) is a member's: the group guards it, and gives it who asks
367
+ (`(req, who)`), so it reads a document as they see it (`read(doc, who.member)`; with owns, only theirs).
368
+ - **An open route** (`export const open = (read) => ({ "/card/:id": (req) => … })`) is anyone's, never guarded by
369
+ the group: a link's preview (og:title, og:image), a card for a stranger. Its `read` is as nobody (member 0):
370
+ owns and sees apply, so a part only some see isn't there, but the group's door doesn't: a document any member
371
+ sees whole is whole. So an open route shows only what it picks, and what it picks is public.
372
+ - **Two apps answering one path** are refused at start, open routes too.
373
+ - **The server writes** with the `write` a routes function is given beside `read` (`routes(read, write)`):
374
+ a webhook, an import, a job on the app's own timer. `write(doc, ops)` is shaped by the stories (only what
375
+ a story does), never asked of roles or `trust.ts`, by nobody, and told as any write; it throws `Refused`.
376
+ Never the group's document, and never a document's content from files at start: that's its seed (§13).
377
+ - **What follows from a write** is a rule over values where a definition can say it (`takes`: an order
378
+ taking stock, in the database, undone as the write is), and otherwise
379
+ `export const reactions: Reactions = (change, read) => [{ doc, ops }]`: a count, a total, a cascade, landed in
380
+ the change's transaction, round after round until none writes (ten at most). One that never settles, or
381
+ writes what no story does, lands nothing.
382
+ - **A derived document** (an aggregate, a join, one per person) is an app with a `derive.ts` in place of
383
+ stories (`doc`, `from`, `derive(read, member)`; its `routes.ts` re-exports `derive`) and an example,
384
+ `<doc>.json`, its shape: elements with no ops, every write refused. The server derives it for each
385
+ page's member as it's joined, and again after a write to what it's read from, sending it whole where it's
386
+ changed. `tests/fixtures/statement`; `examples/weeks` (each trip's weeks, from the trips and their kind).
387
+ - **The root's page** is `examples/routes.ts`.
388
+
389
+ Working: `examples/hello/routes.ts`, the smallest; `examples/cafe/routes.ts` (an app of several documents:
390
+ `export const documents`); `examples/trip/routes.ts` (an edge); `tests/server.test.ts` (folders, edges, clashes);
391
+ `tests/writes.test.ts` (a route's write, reactions).
392
+ - **A window that holds what overlaps it**: `{"window":{"events":{"week":{"from":"start","for":"P7D","length":"duration"}}}}`,
393
+ the items whose time overlaps its days (the trip's week and month).
394
+ - **An order** (`{"order":{"people":"rank"}}`): a collection held in a number of its own, then by id (an item
395
+ without one ranks by its id), its query and every page alike; a drag to reorder is a replace of the rank, between
396
+ its neighbours' (`examples/people/order.ts`; `held` and `follow` from `joined/follow`).
397
+ - **An invitation that acts** (`export const acts`): `{ person: (member, word) => ({ doc, ops }) }`, each an act a
398
+ member's invitation may name (`act: "person 3"`, given by its inviter). In by their link, the act's write is made
399
+ for them, as them (their grants, the app's trust), once; then the act is gone. The people's `person`: the person
400
+ they were invited as is them.
401
+
402
+ - **A file a document names** is joined's own route, never an app's: `POST /files?doc=<doc>` (the bytes the body)
403
+ by whoever may put a file in that document (an add to a collection with a file field, or its replace: a member by
404
+ their link, a guest by its code), from this site alone (another site's is refused); a photo made a WebP (1600px, no
405
+ EXIF), an SVG and a PDF as they are (an SVG served sandboxed: opened by its path, nothing in it runs), under 20 MB
406
+ and 50 megapixels, else refused in words; answered `{ file }`. Kept by its
407
+ content's hash in `files/` beside the store, or where `JOINED_FILES` says: another folder, or a bucket,
408
+ `s3://<bucket>/<prefix>` (Bun's S3 client, its keys, endpoint and region from `S3_*` or `AWS_*` in the
409
+ environment; a Railway bucket's credentials as they are, its addressing Bun's default, by path); served at
410
+ `/files/<name>` to anyone with its path, cached for good, the same from either
411
+ (`src/files.ts`, `tests/attachments.test.ts`).
412
+
413
+ ## 9. Stylesheets
414
+
415
+ - **What the look is,** `docs/design.md`: the surfaces, colour, a chip, a pin, type, icons, layout and
416
+ the parts. Read its section for what you draw; this section is how to draw it here.
417
+ - **Every page's layout,** `src/page.css` (`joined/page.css`), linked after the tokens: the body, `h1`, `h2`,
418
+ `.note`, `.bar`, `#said`, and `main` hidden signed out and dimmed away. A page's own look comes after it.
419
+ - **The parts,** `src/parts.css`, once: buttons, fields, labels, the drawer (`.drawer`), the modal
420
+ (`dialog`) and the sheet (`.sheet`, a popover with a title and its ×). Adopted by the page and every shadow (`src/parts.ts`,
421
+ imported by a display: `adoptedStyleSheets = [PARTS, SHEET]`). A button with words is `.act` (`.ink`,
422
+ `.danger`, `.quiet`), one with its icon alone `.icon-only`; a field needs no class. Never a button's or a
423
+ field's look in a display's own sheet: only how it sits (`flex: 1`).
424
+ - **Type** is nine styles, each a font in `src/tokens.css`: `font: var(--font-row)` (`body`,
425
+ `heading`, `title`, `row`, `label`, `tool`, `small`, `tiny`, `field`). Never a size by hand.
426
+ - **The colours,** `src/tokens.css` (`--paper`, `--card`, `--ink`, `--muted`, `--line`, `--edge`, `--add`,
427
+ `--danger`, `--scrim`, `--tint`…), light and dark, linked by every page before `app.css`. Every colour
428
+ is one of them, in a shadow too: custom properties pass into it. An app's own palette is named once, as properties
429
+ at the top of its sheet, and read by name (the cafe's flavours, `--flavour`). A person's hue is `--hue`, and a
430
+ chip is the hue at `--tint` over `--card`, a 3px stripe, words in `--ink`.
431
+ - **A value changes in `src/tokens.json`,** never in `src/tokens.css`, which `bun run design` makes from
432
+ it. A new part, or a new page, gets its card: a guideline in `design/<Name>/README.md`, and a scene in
433
+ `design/scenes.ts` (the page, its width, how a person puts it in that state, and what to cut), from which
434
+ `bun run design` captures the markup joined draws. Only a catalogue card (variants side by side) is a
435
+ `preview.html` by hand, icons as `<svg data-icon="name"></svg>`, held by `tests/design.test.ts` to classes
436
+ joined really has.
437
+ - **The app's,** `examples/app.css`: type, colours, controls, linked by every page. A signed-out
438
+ page hides its `<main>`.
439
+ - **A document's,** `examples/<doc>/<doc>.css`: how its elements look, linked by every page that
440
+ holds it.
441
+ - **A display's,** imported as text and adopted in its shadow:
442
+
443
+ ```ts
444
+ import STYLE from "./calendar-map.css" with { type: "text" };
445
+ const SHEET = new CSSStyleSheet(); SHEET.replaceSync(STYLE);
446
+ this.#root.adoptedStyleSheets = [SHEET];
447
+ ```
448
+
449
+ Sizes the code draws with are custom properties set on the host (`--hour`), so the numbers live
450
+ in one place.
451
+
452
+ Working: `examples/app.css`, `examples/cafe/cafe.css` (a page's look over joined's parts),
453
+ `examples/cafe/kitchen.css` (a display's own palette, named once on `:host`), `examples/people/people.css`,
454
+ `examples/trip/calendar-map.css`.
455
+
456
+ ## 10. Icons
457
+
458
+ lucide alone, by joined's own names, in `src/icons.ts`; what each means is `docs/design.md`'s
459
+ "Icons". To add one, import it from `lucide`, name it in `ICONS`, and give it its meaning there.
460
+
461
+ - **A row's harmless action is its icon alone,** labelled: `iconButton("copy", "Copy Nick's link",
462
+ act)`. Its words are its `aria-label` and title.
463
+ - **A bigger button has its icon before its words.** In markup, write `data-icon="add"`, then call
464
+ `iconify()` (or `iconify(this.#root)` in a shadow).
465
+ - **One way each:** markup's icons by `data-icon` and `iconify`, a button made in code by `iconButton`, and
466
+ `icon(name)` alone where an icon changes as the button's deed does (the event form's Save and Add).
467
+
468
+ Tests find an icon button by its `ariaLabel`.
469
+
470
+ Working: `src/icons.ts`; the members panel and every example.
471
+
472
+ ## 11. The group: sign-in by link
473
+
474
+ - **`ROOT_TOKEN` in `.env` makes joined invite-only.** Your link, the BDFL's, is
475
+ `/auth/<ROOT_TOKEN>`, printed at start while it is short (the local `42`); a long one, a secret, never
476
+ is: `bun run link <name>`. Without it, joined is open, which the live site (`NODE_ENV=production`)
477
+ refuses to be.
478
+ - **A link to a page its person can't open isn't offered:** mark it with the document the page holds,
479
+ `<a href="/cafe/till" data-holds="till">`, and `joined/panel` hides it for anyone who may not hold that document
480
+ (the group tells each page, with who it's signed in as, what its person may hold). The cafe's bar is shown working.
481
+ - **A demo on this machine (`JOINED_DEMO=1`, as an app's `bun run dev` sets it, and joined's) lets you be
482
+ anyone:** a page carrying `<joined-demo>` (`import "joined/demo"`; an app's home page, joined's root) has a
483
+ line, the BDFL first, each a link (`/as/<id>`) the server signs the browser in by, who you are filled, so being
484
+ Nora always has a way back; not a demo, it stays hidden. It answers this machine alone (403 from anywhere else), and the live site refuses to start
485
+ as one. Two people side by side: a second window at `127.0.0.1` keeps its own sign-in.
486
+ - **A project whose stories are all anonymous (none has `as`) has no members:** the group's document
487
+ isn't held, ROOT_TOKEN isn't asked for, and it runs open, live too. Its pages have no `<members-panel>`.
488
+ - **A project's group begins from its own `apps/members.json`,** else joined's: `{ "version": 1, "members": [ { "id":
489
+ 1, "name": "Peter" }, { "id": 2, "name": "Nora", "inviter": 1 } ] }`, the first with no inviter the BDFL. A story's `as`
490
+ is one of their names, in lower case.
491
+ - **Every page with members holds the group** with `<members-panel></members-panel>` and an import of
492
+ `joined/panel`, which gives a page `members` (the group's members, a live list: a name by key), `signedIn(then,
493
+ signal?)` (who the page is, told once known and as it changes) and `group()` (the group's document, to add an
494
+ invitation to). Never a search for `j-member` of your own, nor a `told` listener. `joined/toast` says a page's own words, `toast(words)`; a write that lands isn't
495
+ toasted (its change shows).
496
+ - **A link** works on every device until replaced in the page.
497
+ - A member holds their own link and those of the people they invited.
498
+ - The BDFL holds everyone's.
499
+ - `bun run link nick` prints a member's link.
500
+ - **Who may do what** is `src/members/trust.ts`, every rule of it. A new rule goes there, with a
501
+ story in `src/members/stories.jsonl` where it can be one.
502
+ - **The server knows none of it.** It calls the group's doors (`src/members/group.ts`): `at`,
503
+ `admit`, `opened`, `write`, `asked`, `edge`, `whoIs`.
504
+ - **To act for Peter,** use an agent's link he made, labelled (as `claude`). Its writes are his,
505
+ `via` the label, and it holds none of his keys.
506
+ - **The MCP door** (`src/mcp.ts`): an agent's link is a custom connector for Claude in a chat (claude.ai, a
507
+ phone), and the Agents tab copies it so: `POST /mcp/<its token>`, MCP's Streamable HTTP in plain JSON. Only an agent's token opens it. Its tools are
508
+ written from the compiled rules: `read_<doc>` (as its member sees it) and `write_<doc>` (one write, ops typed as
509
+ the grants allow, answered `{ done, version, ids }` or a tool error in the refusal's words); a kind's take `key`;
510
+ a window isn't one (read the document). An app's `routes.ts` may export `instructions`, its words for the agent,
511
+ said as the door opens (`examples/trip/routes.ts`). Never print the token: the URL holds it. A project with no
512
+ members (every story anonymous, hello) has no group and no agent's link: its door is anyone's, `POST /mcp` with no
513
+ token, as a stranger's page is, each write logged "by anyone" (`tests/server.test.ts`).
514
+ - **Never put `ROOT_TOKEN`, `.env`, the store (`joined.sqlite`, which holds the keys) or anyone's link in a commit,** nor in chat
515
+ outside a local preview.
516
+
517
+ Working: `src/members/`; `tests/sign-in.test.ts`; `tests/mcp.test.ts` (the door).
518
+
519
+ ## 12. Tests
520
+
521
+ - **`joined/stories` (`src/stories.ts`) is the story player,** here and in a project using joined;
522
+ `tests/helpers.ts` gives it joined's examples and `ROOT`:
523
+ - `fresh()` is a server on copies of the seeds, invite-only with `ROOT`; `fresh({ open: true })`
524
+ is one without sign-in.
525
+ - `tokenFor(name, cast)` gives a name's link.
526
+ - `page(url, doc, token)` is a page's socket subscribed to `doc`, signed in or refused, with
527
+ `next(match)`, `subscribe(doc)` and `closed`. A page's first told may come before you listen: wait with
528
+ `toldOnSignIn` (`tests/sign-in.test.ts`).
529
+ - **The stories are told by who they say,** every app's and the group's: `expect(await tell(doc)).toEqual([])`
530
+ (`tests/server.test.ts`). A story's `does` must pass, be heard by those it names, and leave what its
531
+ `then` says, and its `cannot` must be refused; `tell` says, a line each, any that didn't
532
+ (`tests/then.test.ts`).
533
+ - **What isn't an op** (the sign-in routes, links, notices, agents) is tested in
534
+ `tests/sign-in.test.ts`, refusals by their words.
535
+ - **Pages are tested in a browser** (`Bun.WebView`, `tests/pages.test.ts`: WebKit on a Mac, Chrome elsewhere):
536
+ - sign in by navigating to `/auth/<token>`, then `about:blank`;
537
+ - wait with `waitFor`;
538
+ - drag with the `PRESS` helpers;
539
+ - to prove a display moved only what changed, set an expando (`el.mark = …`) on its nodes, and
540
+ check them after;
541
+ - a drawer, a sheet or a modal, scrolled: `EDGES` (its head and its foot at its edges, the band of its card past
542
+ them), with a scrollbar that takes room;
543
+ - `JOINED_BROWSER=chrome` runs them in Chrome on a Mac too: before a release, run both.
544
+ - **A new app's page test:** in an app, copy `tests/hello-page.test.ts` (the starter's): `inBrowser(app, path, view)`
545
+ from `joined/stories` tells each story a page offers, in a `Bun.WebView`, as its member, and says what its page
546
+ didn't offer. In joined, copy hello's (`tests/pages.test.ts`, "hello: one value, anyone's"), and name its page in
547
+ `tests/stories-in-browser.test.ts` and in "every page loads without an error thrown".
548
+ - **The examples' ways** (`tests/examples.test.ts`): every element defined last, and no compiled tag typed out.
549
+ - **A fix is proved** by putting the bug back and watching its test fail.
550
+ - **Coverage:** `bun run test` reports it, and fails below every line and function of what runs in
551
+ Bun (`bunfig.toml`). The page's side runs in the browser, where Bun doesn't count it, so it's held
552
+ by the browser tests instead. A command line's work is a function (`writeAll`, `startUp`), so a
553
+ test can call it.
554
+
555
+ ## 13. Traps
556
+
557
+ - **A document is never written from files at start.** It begins from its seed (`<doc>.json`), and from then on
558
+ writes alone change it, each told to every page at once. A script run at start that adds or corrects items from
559
+ files of its own (a route's `write` in a `setTimeout`) makes the files the truth and the live document a
560
+ read-only copy of them, put back at every deploy: joined is then a static site. Content Claude gathers (cards,
561
+ places, words) goes in the seed, or later over an agent's link (§11), as any page's write; only what can't be a
562
+ value (a photo's file) waits on a deploy. Met on idea-cards, 1 Nov 2026.
563
+ - **Each role does only what a story shows it doing** (Gemini's "nothing moves", building cardlet, 6 Nov 2026):
564
+ a board's owner can't move a card to another column if only a collaborator's story does. Tell each role each of
565
+ its moves: owner and collaborator alike, where both may.
566
+ - **Someone two roles to one item** (Peter, the board's owner and a post's author) is refused at compile, "so it
567
+ can't say which it grants": the cast names the role the story is told as (`{"author": "nick"}`, `"as":
568
+ "author"`), or the seed keeps the roles apart.
569
+ - **A link to one member may be none:** an item's `owner` is typed `number | undefined` (cleared once they leave);
570
+ say what the page shows then. `bun check` finds it; the gate is `bun check` and `bun test`.
571
+ - **A stylesheet a page links is `{}` when a script imports it as text:** Bun's page bundle takes it
572
+ as CSS. A shadow reads the page's `src/tokens.css` by inheritance; never import it.
573
+ - **Bun's glob doesn't match** `{a,b}` across folders: scan each pattern alone.
574
+ - **A custom element is defined once a page,** so hot reload breaks a page: it's off, so reload.
575
+ - **A WebView navigating straight on from a redirect** is interrupted: go to `about:blank` between.
576
+ - **A WebView's `evaluate` takes one expression:** wrap statements in `(() => { … })()`.
577
+ - **A synthetic pointer event isn't composed:** dispatch `pointermove` and `pointerup` on
578
+ `window`, not on an element in a shadow.
579
+ - **In a shadow, `display: grid` beats `[hidden]`:** give the shadow `[hidden] { display: none
580
+ !important; }`.
581
+ - **`.map(Number)` on a regexp's groups** turns a missing group into `NaN`: give missing groups `0`
582
+ first.
583
+ - **A members page is told what's its after its document,** not before (`admit`, then the
584
+ document, then `opened`).
585
+ - **A test hook that returns Bun's shell promise** (`afterEach(() => Bun.$\`…\`)`) never finishes: await it in
586
+ an `async` hook.
587
+ - **Chrome's WebViews share one profile,** cookies and all, as WebKit's don't: a page signed in as someone else
588
+ goes to another host (`127.0.0.1`, not `localhost`), as a browser keeps a cookie a host.
589
+ - **A dialog's close event comes a task after `close()`:** a handler that clears what it was for checks it isn't
590
+ open again (`if (dialog.open) return`), or it clears what was asked since.
591
+ - **Bun's `WebSocket` takes `{ headers }`,** which the DOM's types don't know: cast it.
592
+ - **A Mac's scrollbar takes no room; Windows' and Linux's do.** A surface whose content is as wide as it scrolls
593
+ sideways there alone: a grid column is `minmax(0, 1fr)`, never `1fr` (its least width is its widest field's). Run
594
+ the pages in Chrome before a release (`JOINED_BROWSER=chrome`); the tests' edge probe gives a surface such a
595
+ scrollbar. Met in CI's Chrome, 2 Nov 2026.
596
+ - **A field that's `flex: 1` beside fields that keep their width shrinks to a sliver** where the row is narrow (a
597
+ sheet): `form.add input` beside a date and a number did. A form of several fields is a grid, its main field the
598
+ whole width. Met on the Stays sheet, 2 Nov 2026.
599
+ - **A search on a change's path costs what the page holds:** `querySelector` on a display's shadow seeks past every
600
+ block before the part it wants, and on the document past every item. Keep a display's own parts once found, and
601
+ read a kind of element from a live list (`getElementsByTagName`). `bun run claims` times it; Chrome's profiler
602
+ (`view.cdp("Profiler.start")`) says where. Met on the trip, 2 Nov 2026: 1.8 ms a change at 100,000 events, now 0.4.
603
+ - **Bun writes nothing copying a file into one it's asked `exists()` of** (`Bun.write(file, Bun.file(from))`, Bun
604
+ 1.4.4): write to the path instead. `joined init` made every file empty, met on its first try from the packed
605
+ tarball, 3 Nov 2026.
606
+ - **A hand's press gives a button the focus; a test's `.click()` doesn't.** `keep()` held a row with the focus in it,
607
+ so a row's own button kept its change from showing on the page that pressed it, unseen by every test. It waits
608
+ only on typing now; a test of a press focuses first (`go.focus(); go.click()`). Met on Haiku's shopping list, by
609
+ Peter as Nick, 3 Nov 2026.
610
+ - **Define an element last in its module:** those the page holds already are drawn as it's defined, before anything
611
+ declared after it is made. The people's view threw on every load, unseen, and after its fix a helper declared below
612
+ the define waited for a page served with links in it. `tests/examples.test.ts` refuses a declaration after a
613
+ define; the pages test's "every page loads without an error thrown" (Chrome) catches what throws.
614
+ - **What an AI copies is the example the skill points it at,** traps and all: idea-cards copied the calendar's frame
615
+ and not its moving only what changed. Point at the smallest instance (the contents table), and fix a trap in the
616
+ example, not only here. Met 3 Nov 2026.
617
+
618
+ ## 14. Seeds, the store, and running it elsewhere
619
+
620
+ - **A committed `<doc>.json` is the seed,** the stories' premise, in its app's folder.
621
+ - **What the pages change is kept apart from the code,** in the store (`src/store.ts`): one SQLite
622
+ file, `joined.sqlite` in the data folder (`DB`, from `JOINED_DB`; the folder from `JOINED_DATA`, or
623
+ `.data/`, which git ignores). Every app's tables are in it, the group's keys too, made by
624
+ migrations at start, joined's own first (`src/migrations/`), then the group's, then each app's.
625
+ - **Or Postgres** (`JOINED_ENGINE=postgres`, or `start({ engine })`): PGlite in a folder (`postgres/` in
626
+ the data folder), or in memory. The engine (`src/engine.ts`) answers synchronously, as SQLite does,
627
+ so a write is the same one transaction; the compiler writes each document's query, items and
628
+ triggers in both dialects (`generated/queries.ts`'s `postgres`). The stories are told on both
629
+ (`tests/helpers.ts`'s `ENGINES`); `fresh({ engine })` and `tell(doc, dir, engine)` take one.
630
+ joined doesn't vacuum or back up a Postgres store.
631
+ - A write is one synchronous transaction: its rows, the document's version, a row of its change
632
+ (`changes`: the ledger, and what a page catching up is sent), and the group's keys when a member
633
+ goes. Ids come from joined's sequences (`joined_sequences`): one is never handed out twice.
634
+ - A document new to the store begins from a `<doc>.json` in the data folder (from before the
635
+ store), else its seed: a site's own, from the folder `JOINED_SEEDS` names (`start({ seeds })`),
636
+ where it's there (a second site from the same apps), else its app's; the keys from
637
+ `members.keys.json`. A store that lasts renames those
638
+ `.imported`, never deletes them, and never renames a seed; a store in memory (`JOINED_DB=:memory:`) renames nothing.
639
+ - A store that lasts is kept up when idle (`src/upkeep.ts`): vacuumed once enough is written, and
640
+ backed up once a day (`VACUUM INTO`) to `backups/` beside it (`JOINED_BACKUPS`), the last seven kept.
641
+ A change is kept 90 days (`JOINED_HISTORY`), and any of a document's last 500 for good (what a page
642
+ catching up is sent); an older one is let go before the vacuum.
643
+ The files the documents name are in `files/` beside it, as its backups are, or a bucket (`JOINED_FILES`:
644
+ `s3://<bucket>/<prefix>`, a prefix each site's own); one no item and no kept change names is let go once it's
645
+ older than the history and the backups' week. A test's server has a files
646
+ folder of its own (`fresh()`).
647
+ To go back to one, stop joined and put it in the store's place, with no `-wal` or `-shm` beside it.
648
+
649
+ Never delete the database, or someone's rows, without being asked.
650
+ - **The tests have a data folder of their own, and a database in memory** (`tests/preload.ts`;
651
+ `tests/guard.test.ts` holds them to it), and no `ROOT_TOKEN` from `.env`, so no test can touch the
652
+ real ones. A test that needs a file (a restart) names its own, and deletes it.
653
+ - **Run elsewhere** (as on Railway):
654
+ - mount a volume and set `JOINED_DATA` to it, since the code's folder is replaced on every deploy:
655
+ the store's file is there;
656
+ - the server listens on `PORT`;
657
+ - `ROOT_TOKEN` is a long secret, set there, never `42`;
658
+ - the secure cookie follows `x-forwarded-proto`.
659
+ - **On Railway** it's `.railway/railway.ts`: one service, a volume at `/data`, `ROOT_TOKEN` kept
660
+ there. The project is `joined` in blueshed's workspace, made by `railway init --name joined`
661
+ (not `link`, which only picks an existing one). Then `bun run plan` (shown to Peter), `bun run apply`
662
+ (on his word), `bun run secrets` (the BDFL's link goes to `.railway/root-link`), then `bun run deploy`
663
+ sends the newest release and waits for `/version` to say it. Never `bunx railway`: railway/iac checks
664
+ the CLI's version by running `$_`, which under bunx is Bun, and refuses.
665
+
666
+ ## 15. What stories can't show: definitions, an app's own rules, a kind
667
+
668
+ - **`stories.jsonl`'s header lines**, after the cast, one a key (`{"owns":"owner | author"}`), say what the
669
+ stories can't show; the compiler alone reads them, refuses one no story checks, and writes them into
670
+ `generated/rules.ts` as code (`src/definitions.ts` says each key and the who-path):
671
+ - `links`: a field linking though not named for its collection, a list (`{ owners: "members" }`) or one
672
+ id (`{ account: { to: "accounts", one: true } }`), in its own document or another's. A link may name an
673
+ item an add before it in the same write makes: the id the store will give it.
674
+ A list a link declares is typed by it, though every story gives it empty. `gone: "with"` on one id
675
+ (`{ post: { to: "posts", one: true, gone: "with" } }`): removing the post removes what links to it first, in
676
+ the same write, told to the pages as removals and undone with it; without it, the removal is refused.
677
+ - `roles`: who someone is, a who-path each: `posts[role=keeper]@members`, `holdings@members`,
678
+ `members/members[!inviter]`, and in a kind `@owners`, the root item's; but an `@field` the item a write is to
679
+ has is the item's (a post's `@author` on a board, the board's `@owners`). Someone two roles to an item is told
680
+ as one: the cast names it (`{"author": "nick"}`, `"as": "author"`). What each role may do is read off the
681
+ stories: a `does` grants its ops to its teller's named role as the story finds them, its premise written on the
682
+ seeds (none: anyone).
683
+ The grants refuse the rest, in the write's transaction: "you may not add at /accounts/-".
684
+ - `owns`: who sees what, one who-path for the document or one per collection (`@members` is the item's
685
+ own). A page is sent whole, and told, only what its person sees: an item they come to see is added to
686
+ their page, and one they see no longer (or that's gone) is removed. Back from away, it's sent whole again.
687
+ Each change says the version that page was last told (`after`), so a page knows when it has missed one.
688
+ - `kind: { root: "shelves" }`: a document for each item of another's collection, `shelf:1`, held while
689
+ the item is there, at version 0 until its first write; a seed's items say their instance by a column
690
+ named for the kind. A collection element takes its document from its `doc` attribute: a page for each
691
+ (`/trip/:n`) sets it from its path (`examples/trip/page.ts`). A window is on an instance
692
+ (`trip:1?week=2026-11-02`); another window is held by putting a new collection element in place of the old
693
+ (the old one lets its window go), as the trip's page does a week (`examples/trip/page.ts`, `holding.ts`). Working: `examples/trips` and
694
+ `examples/trip`.
695
+ - `fills: { cards: { added: "now" }, boards: { count: 0 } }`: a field the server fills on every add,
696
+ which no story gives (`"now"`, the instant; `"me"`, the member who adds it: a post's author); the server's alone, so a page giving or replacing it is
697
+ refused, and a route's write or a reaction keeps it (a count, a total). But `"random"`, a code: a story may
698
+ replace it (`{"op":"replace","path":"/boards/1/code","value":"new"}`, granted its teller's role), and the server
699
+ makes the new code, whatever the write gives, before it's checked and kept: told and kept, twelve of a URL's own
700
+ characters. A board's secret link made new: the old one opens nothing (`tests/visitors`).
701
+ - `timed: { cards: "due" }`: an instant the stories give; when it comes the server clears it, as its own
702
+ write, and the app's reactions do what follows (a clock's next tick sets it again).
703
+ - `unique: { people: ["name"] }` (or fields together, `[["hotel", "name"]]`) and
704
+ `noOverlap: { stays: { range: ["from", "until"], same: ["room"] } }` (half open; the end a time, a
705
+ number, or a duration on from the start): asked once a write is done, in its transaction, of each item it
706
+ touched, and refused in words (`people 3 has that name already`), none of it landed.
707
+ - `window` and `order`: a part of a collection a page may hold alone, and a collection held in a number's order
708
+ (§8).
709
+ - `copies: {"lines": {"from": "item", "fields": ["name", "price"]}}`: fields an item takes from what one of its
710
+ links points at, once, as it's added, and never follows after (a line keeps the price it was sold at).
711
+ - `totals: {"orders": {"total": {"of": "lines", "by": "order", "sum": "qty", "times": "price"}}}`: a field the
712
+ database keeps as the sum of the rows linking to its item (an order's total, each line's qty times its price).
713
+ - `moves: {"orders": "status"}`: a field that moves only as the stories move it, each step by the roles whose
714
+ stories make it (placed, then being made, by the kitchen); `may` offers a step as `replace:status>being%20made`.
715
+ A step is from where the story finds its item, its premise written on the seeds; an add giving the field is a
716
+ first step (a writer's post added `waiting`, and only that).
717
+ - `takes` and `gives`: a rule over values: `{"lines": {"qty": "item.stock", "while": "order.status!=cancelled",
718
+ "refused": "The kitchen has {stock} of {name}: not enough to take {qty}."}}`, a line's qty taken from its item's
719
+ stock while its order isn't cancelled (given back as that changes); `gives` adds where `takes` takes (a supply
720
+ delivered). Refused in its words where it would leave less than none.
721
+ - `guests: {"orders": "code"}`: a field holding an item's own code; a page holding the document by it
722
+ (`order?code=…`) is that item's guest, signed in to nothing (the cafe's customer's link). In a kind, the root's
723
+ (`{"boards": "code"}`): a page holding `board:1?code=…` by the board's own code is its guest, sent it whole and
724
+ told each change (a wrong code: No access), what a guest may do told by stories with no `as` on that address.
725
+ Its code shows the board whole, past any `owns` of a collection: a board whose readers see only some of it gives
726
+ no secret link. Its guest holds the board's own row too, to draw it (its title, its settings): a page holding the
727
+ root's document by the code (`<j-boards doc="boards?code=…">`) is sent that board alone, past the root's `owns`,
728
+ and told its changes; it may write nothing there (a cannot with no `as` on `boards?code=…`: "you may not replace
729
+ at /boards/1/visitors"), and a wrong code is No access, as the instance's door says it.
730
+ - `visitors: {"boards": "visitors"}`, in a kind with `guests` on its root: the root's field holding the level its
731
+ guest is ("reader", "commenter", "writer"). A guest holding `board:1?code=…` is the role `guest:` that level,
732
+ granted what the stories with no `as` do on a board of that level, each level told by its own stories (Padlet's
733
+ add up: a commenter's stories react too). What's granted any member isn't a visitor's who is nobody; a member
734
+ holding the link keeps it, and gains the level's. A level no story lets a guest act on ("none", or none given) is
735
+ No access, the board's row by its code too; so is a page open by the code (either) once its root's level or code
736
+ changes, told no more, not even that change. A guest is nobody,
737
+ so a post it adds that fills `"me"` has no author. Checked by a guest's does at one level and a guest's cannot at
738
+ another; a cannot refused at the door may say `"refused": "No access"`. Working: `tests/visitors`.
739
+ - `frozen` and `waits`, in a kind: a yes-or-no field of the root item that governs its instance, as a board's
740
+ settings do. `{"frozen": {"by": "frozen", "refused": "the board is frozen: it's kept as it is"}}`: while the
741
+ board's frozen is true, every write the grants allow is refused in those words (a page's, a guest's, an agent's),
742
+ and `may` offers nothing; a write to the boards themselves (unfreezing) isn't. `{"waits": {"by": "moderated",
743
+ "posts": "waiting", "refused": "…"}}`: while it's true, an add to posts gives its field that moves (`moves`) as
744
+ that first step, or the write is refused whole in its words, and `may` offers the add only by it. The compiler
745
+ refuses one that isn't a kind's, says no words, isn't by a yes-or-no field of the root, or that no cannot is
746
+ refused in its words; and a waits step no story adds. A story's premise may write the root (freeze it, then the
747
+ cannot). Asked after trust.ts and the grants; a route's write or a reaction isn't asked them. Working:
748
+ `tests/settings`.
749
+ - `where`: which rows each of an app's several documents holds, and who may hold it at all: `{"kitchen":
750
+ {"holds": "kitchen | manager", "orders": {"status": ["placed", "being made", "ready"]}}}`; `last` and `by` keep only
751
+ the newest so many; a collection's name in place of the fields, the rows linking to those (an order's lines).
752
+ - `documents`: a read-only document worked out by member: `{"books": {"entries": {"from": "supplies", "when":
753
+ "delivered", "sides": {"buyer": "bought", "supplier": "sold"}, "fields": ["title", "buyer", "supplier"], "total": {"sum": "qty",
754
+ "times": "price"}}}}`, each side's books. A sum by member is this; a split (a cost divided among a group) isn't
755
+ a definition: work it out on the page, from the items, as a pure function (the shopping list's `balances.ts`).
756
+ - **`<app>/trust.ts`**, exported from `routes.ts` (`export { trust } from "./trust.ts"`), is the app's own
757
+ rule over a whole write, reading any document: `(write, { member, roles }, read) => why | null`. It's
758
+ asked first, so a refusal is in its words; it reads the ops as sent, before they're checked. It's asked
759
+ when the group is open too, of nobody (`member` 0).
760
+ - **A story's words for them:** `premise` (each name's writes before it, in order; an anonymous story's, a list), `unseen` (who must not
761
+ see it), `refused` (the words a cannot is refused in). `tell(doc, dir)` from `joined/stories` says each.
762
+ - Working: the cafe's stories (`examples/cafe/stories.jsonl`) say `copies`, `totals`, `moves`, `guests`, `where`,
763
+ `takes`, `gives` and `documents`, each a header line; a kind on the trips and the trip (`examples/trips`,
764
+ `examples/trip`); unique on the people (`examples/people/stories.jsonl`), noOverlap on the trip's stays. In joined's
765
+ own repository too (not shipped to an app): `tests/fixtures/ledger` and `tests/fixtures/shelf`
766
+ (`tests/definitions.test.ts`), fills and timed on a tally (`tests/writes.test.ts`); a Padlet (`tests/padlet`, `tests/padlet.test.ts`): item roles in
767
+ a kind, `"me"`, moves from a premise and an add's first step, `gone: "with"`, and a board's secret link, and its settings, frozen and waits (`tests/settings`), and visitor levels (`tests/visitors`); a write across documents (`tests/together`); a post's file
768
+ (`tests/attachments`).