chirkle 0.3.0 → 0.4.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 (156) hide show
  1. package/README.md +99 -47
  2. package/bin/release/darwin-amd64/chirkle-server +4 -0
  3. package/bin/release/darwin-arm64/chirkle-server +0 -0
  4. package/bin/release/linux-amd64/chirkle-server +0 -0
  5. package/bin/release/linux-arm64/chirkle-server +0 -0
  6. package/package.json +9 -6
  7. package/pb_hooks/federation/inbox.js +2 -69
  8. package/pb_hooks/federation/messages.js +5 -3
  9. package/pb_hooks/federation/net.js +1 -0
  10. package/pb_hooks/federation/people.js +1 -0
  11. package/pb_hooks/federation.pb.js +1 -8
  12. package/pb_hooks/lib/access.js +33 -10
  13. package/pb_hooks/lib/account.js +542 -6
  14. package/pb_hooks/lib/anonymous.js +2 -129
  15. package/pb_hooks/lib/bulk.js +1 -2
  16. package/pb_hooks/lib/collections.js +4 -4
  17. package/pb_hooks/lib/dms.js +1 -1
  18. package/pb_hooks/lib/files.js +82 -120
  19. package/pb_hooks/lib/handles.js +2 -2
  20. package/pb_hooks/lib/inbox.js +40 -54
  21. package/pb_hooks/lib/invites.js +266 -0
  22. package/pb_hooks/lib/media.js +5 -43
  23. package/pb_hooks/lib/messages.js +72 -117
  24. package/pb_hooks/lib/moderation.js +2 -16
  25. package/pb_hooks/lib/reactions.js +28 -4
  26. package/pb_hooks/lib/retention.js +88 -0
  27. package/pb_hooks/lib/site.js +13 -2
  28. package/pb_hooks/lib/stats.js +6 -34
  29. package/pb_hooks/lib/users.js +88 -7
  30. package/pb_hooks/lib/worker.js +22 -1
  31. package/pb_hooks/main.pb.js +85 -94
  32. package/pb_hooks/telegram/api.js +64 -12
  33. package/pb_hooks/telegram/inbound.js +158 -31
  34. package/pb_hooks/telegram/links.js +4 -3
  35. package/pb_hooks/telegram/outbound.js +86 -45
  36. package/pb_hooks/telegram/people.js +3 -3
  37. package/pb_hooks/telegram/worker.js +59 -15
  38. package/pb_migrations/1760000045_password_reset.js +38 -0
  39. package/pb_migrations/1760000047_telegram_supergroup_ids.js +51 -0
  40. package/pb_migrations/1760000048_inbox_reactions_merged.js +24 -0
  41. package/pb_migrations/1760000049_inbox_room_index.js +22 -0
  42. package/pb_migrations/1760000050_messages_unread_index.js +22 -0
  43. package/pb_migrations/1760000051_users_kind.js +31 -0
  44. package/pb_migrations/1760000052_deleted_accounts.js +19 -0
  45. package/pb_migrations/1760000053_account_jobs.js +45 -0
  46. package/pb_migrations/1760000054_room_invites.js +39 -0
  47. package/pb_migrations/1760000055_invite_barred.js +16 -0
  48. package/pb_migrations/1760000056_telegram_fetch.js +21 -0
  49. package/pb_public/assets/{access-PB77EH4F.css → access-GPRLOZOO.css} +2 -2
  50. package/pb_public/assets/{access-PB77EH4F.css.map → access-GPRLOZOO.css.map} +2 -2
  51. package/pb_public/assets/access-UK3L54NR.js +2 -0
  52. package/pb_public/assets/access-UK3L54NR.js.map +7 -0
  53. package/pb_public/assets/account-CT2BVMAX.css +2 -0
  54. package/pb_public/assets/account-CT2BVMAX.css.map +7 -0
  55. package/pb_public/assets/account-api-J6A6IYVX.js +2 -0
  56. package/pb_public/assets/account-api-J6A6IYVX.js.map +7 -0
  57. package/pb_public/assets/app-HB3NZHQ2.js +3 -0
  58. package/pb_public/assets/app-HB3NZHQ2.js.map +7 -0
  59. package/pb_public/assets/app-XJ73EU5O.css +2 -0
  60. package/pb_public/assets/app-XJ73EU5O.css.map +7 -0
  61. package/pb_public/assets/chunk-56ACD3V5.js +2 -0
  62. package/pb_public/assets/chunk-56ACD3V5.js.map +7 -0
  63. package/pb_public/assets/chunk-AG73QNUN.js +2 -0
  64. package/pb_public/assets/chunk-AG73QNUN.js.map +7 -0
  65. package/pb_public/assets/chunk-DCLJRQ53.js +2 -0
  66. package/pb_public/assets/chunk-DCLJRQ53.js.map +7 -0
  67. package/pb_public/assets/chunk-DZC4SY4M.js +2 -0
  68. package/pb_public/assets/chunk-DZC4SY4M.js.map +7 -0
  69. package/pb_public/assets/chunk-N2OFGBCZ.js +2 -0
  70. package/pb_public/assets/chunk-N2OFGBCZ.js.map +7 -0
  71. package/pb_public/assets/chunk-OKIIBH7O.js +2 -0
  72. package/pb_public/assets/chunk-OKIIBH7O.js.map +7 -0
  73. package/pb_public/assets/chunk-RPCBA7VF.js +2 -0
  74. package/pb_public/assets/chunk-RPCBA7VF.js.map +7 -0
  75. package/pb_public/assets/chunk-UZDXAORM.js +2 -0
  76. package/pb_public/assets/chunk-UZDXAORM.js.map +7 -0
  77. package/pb_public/assets/chunk-VTOUI25E.js +4 -0
  78. package/pb_public/assets/chunk-VTOUI25E.js.map +7 -0
  79. package/pb_public/assets/chunk-WR25F7FU.js +2 -0
  80. package/pb_public/assets/chunk-WR25F7FU.js.map +7 -0
  81. package/pb_public/assets/{emoji-VA2WCEAC.css → emoji-WWNPWCF3.css} +2 -2
  82. package/pb_public/assets/{emoji-VA2WCEAC.css.map → emoji-WWNPWCF3.css.map} +2 -2
  83. package/pb_public/assets/{emoji-picker-65VVVGYW.js → emoji-picker-K6JTK2GV.js} +4 -4
  84. package/pb_public/assets/emoji-picker-K6JTK2GV.js.map +7 -0
  85. package/pb_public/assets/forward-267HRNPY.js +2 -0
  86. package/pb_public/assets/forward-267HRNPY.js.map +7 -0
  87. package/pb_public/assets/inbox-CLMYESNI.js +2 -0
  88. package/pb_public/assets/inbox-CLMYESNI.js.map +7 -0
  89. package/pb_public/assets/invite-OGT5E2MZ.js +2 -0
  90. package/pb_public/assets/invite-OGT5E2MZ.js.map +7 -0
  91. package/pb_public/assets/invite-api-7G7XPXQW.js +2 -0
  92. package/pb_public/assets/invite-api-7G7XPXQW.js.map +7 -0
  93. package/pb_public/assets/lazy-H3KIJVB5.js +2 -0
  94. package/pb_public/assets/lazy-H3KIJVB5.js.map +7 -0
  95. package/pb_public/assets/login-TK6K4WGB.js +2 -0
  96. package/pb_public/assets/login-TK6K4WGB.js.map +7 -0
  97. package/pb_public/assets/media-WZ4653L5.js +2 -0
  98. package/pb_public/assets/media-WZ4653L5.js.map +7 -0
  99. package/pb_public/assets/mention-suggest-ODJD2IC5.js +2 -0
  100. package/pb_public/assets/mention-suggest-ODJD2IC5.js.map +7 -0
  101. package/pb_public/assets/notify-EPDM772N.js +2 -0
  102. package/pb_public/assets/notify-EPDM772N.js.map +7 -0
  103. package/pb_public/assets/profile-3R6S5QYS.js +2 -0
  104. package/pb_public/assets/profile-3R6S5QYS.js.map +7 -0
  105. package/pb_public/assets/search-WCHOGAJQ.js +2 -0
  106. package/pb_public/assets/search-WCHOGAJQ.js.map +7 -0
  107. package/pb_public/assets/stats-GTO2H6PG.js +2 -0
  108. package/pb_public/assets/stats-GTO2H6PG.js.map +7 -0
  109. package/pb_public/assets/switcher-TFSO45KV.js +2 -0
  110. package/pb_public/assets/switcher-TFSO45KV.js.map +7 -0
  111. package/pb_public/assets/user-search-3HQOCQWL.js +2 -0
  112. package/pb_public/assets/user-search-3HQOCQWL.js.map +7 -0
  113. package/pb_public/assets/viewer-2Y5FJBW4.js +2 -0
  114. package/pb_public/assets/viewer-2Y5FJBW4.js.map +7 -0
  115. package/pb_public/index.html +10 -2
  116. package/pb_public/stats.html +1 -1
  117. package/scripts/service.mjs +201 -0
  118. package/scripts/start.mjs +21 -17
  119. package/pb_hooks/lib/enrich.js +0 -75
  120. package/pb_hooks/lib/lists.js +0 -179
  121. package/pb_hooks/lib/live.js +0 -137
  122. package/pb_hooks/lib/reads.js +0 -183
  123. package/pb_public/assets/access-GUDTDXIP.js +0 -2
  124. package/pb_public/assets/access-GUDTDXIP.js.map +0 -7
  125. package/pb_public/assets/app-3WX5JYL2.js +0 -3
  126. package/pb_public/assets/app-3WX5JYL2.js.map +0 -7
  127. package/pb_public/assets/app-WAFKVN2H.css +0 -2
  128. package/pb_public/assets/app-WAFKVN2H.css.map +0 -7
  129. package/pb_public/assets/emoji-picker-65VVVGYW.js.map +0 -7
  130. package/pb_public/assets/forward-66PELNWT.js +0 -2
  131. package/pb_public/assets/forward-66PELNWT.js.map +0 -7
  132. package/pb_public/assets/inbox-TZJWPRTG.js +0 -2
  133. package/pb_public/assets/inbox-TZJWPRTG.js.map +0 -7
  134. package/pb_public/assets/lazy-4CXRBHHM.js +0 -2
  135. package/pb_public/assets/lazy-4CXRBHHM.js.map +0 -7
  136. package/pb_public/assets/login-G7Y44CJ7.js +0 -2
  137. package/pb_public/assets/login-G7Y44CJ7.js.map +0 -7
  138. package/pb_public/assets/media-FPRU2QH5.js +0 -2
  139. package/pb_public/assets/media-FPRU2QH5.js.map +0 -7
  140. package/pb_public/assets/mention-suggest-R7MXUH6R.js +0 -2
  141. package/pb_public/assets/mention-suggest-R7MXUH6R.js.map +0 -7
  142. package/pb_public/assets/notify-RQ6ZLR46.js +0 -2
  143. package/pb_public/assets/notify-RQ6ZLR46.js.map +0 -7
  144. package/pb_public/assets/profile-2CNVT2KX.js +0 -2
  145. package/pb_public/assets/profile-2CNVT2KX.js.map +0 -7
  146. package/pb_public/assets/search-3UT4HMES.js +0 -2
  147. package/pb_public/assets/search-3UT4HMES.js.map +0 -7
  148. package/pb_public/assets/stats-JX52AQCO.js +0 -2
  149. package/pb_public/assets/stats-JX52AQCO.js.map +0 -7
  150. package/pb_public/assets/switcher-CEUKRLEY.js +0 -2
  151. package/pb_public/assets/switcher-CEUKRLEY.js.map +0 -7
  152. package/pb_public/assets/user-search-7GNEIXMN.js +0 -2
  153. package/pb_public/assets/user-search-7GNEIXMN.js.map +0 -7
  154. package/pb_public/assets/viewer-DXT7SKOU.js +0 -2
  155. package/pb_public/assets/viewer-DXT7SKOU.js.map +0 -7
  156. package/scripts/fetch-pocketbase.sh +0 -63
package/README.md CHANGED
@@ -2,17 +2,19 @@
2
2
 
3
3
  A small, fast, real-time group chat. One [PocketBase](https://pocketbase.io) binary is the whole backend
4
4
  (auth, data, realtime, static files); the frontend is vanilla TypeScript bundled by esbuild — no framework,
5
- ~49 KB of JS and ~11 KB of CSS gzipped (`npm run build` fails over its budget: 49.75 KB of JS,
6
- 11.25 KB of CSS; rarer screens such as the image viewer, search, room access and collections load on first use).
5
+ ~50 KB of JS and ~11 KB of CSS gzipped (`npm run build` fails over its budget: 62.5 KB for everything a visit loads
6
+ first, 16 KB for any rarer screen, such as the image viewer, search, room access, collections, the emoji picker and
7
+ Mentions & replies, which load on first use).
7
8
 
8
9
  <picture>
9
10
  <source media="(prefers-color-scheme: dark)" srcset="docs/screenshot-dark.png">
10
- <img alt="A room in Chirkle: the room list with unread counts on the left; messages with avatars, a reply, a photo and emoji reactions on the right" src="docs/screenshot-light.png">
11
+ <img alt="A room in Chirkle: the room list with unread counts on the left; messages with avatars, a reply, an @mention of you, a photo and emoji reactions on the right" src="docs/screenshot-light.png">
11
12
  </picture>
12
13
 
13
- - Runs on a $5 VPS (1 vCPU, 1 GB of RAM): about 500 people online at a normal pace, or 100 chatting nonstop
14
- (measured, [PERF.md §8](docs/PERF.md#8-2026-11-09-a-5-vps-one-cpu)); past 100–200 clients, everyone
15
- reconnecting at once can still swamp it
14
+ - Runs on a $5 VPS (1 vCPU, 1 GB of RAM): about 1,000 people online at a normal pace (2,000
15
+ with slow sends), or 300 chatting nonstop, and 1,000 reconnecting at once catch up within seconds; beyond that it
16
+ slows down but stays within its memory (measured, [PERF.md §13](docs/PERF.md#13-2026-11-12-one-serialization-per-answer-less-gc),
17
+ [§14](docs/PERF.md#14-2026-11-12-memory-under-overload-admission))
16
18
  - Public rooms anyone can create; hide rooms you don't care about; creators archive rooms (read-only, history kept)
17
19
  - Room access, chosen by each room's creator: **Private** (only the people they add), **Public** (everyone with an account) or **Open Air** (anyone can read it, no account needed; the home page shows these rooms to guests, who log in or sign up to join in); and who can post: everyone who can read it, or only the people they choose (the others read and react)
18
20
  - Live messages, edits and deletes (deleted messages leave a placeholder)
@@ -21,8 +23,14 @@ A small, fast, real-time group chat. One [PocketBase](https://pocketbase.io) bin
21
23
  - Avatars (or colored initials) and a profile page to change your picture, display name (unique) and password, and to log out
22
24
  - Search in any room or DM: every word you type, in any case ("привет" finds "Привет"), newest first; pick a result to go to it, however far back
23
25
  - Replies: answer any message with a quote of it; click the quote to jump to the original, however far back
26
+ - Handles and @mentions: everyone has an @handle (made from their name, changeable in Settings); type "@" in the
27
+ composer to pick someone. A message that mentions you is highlighted and notifies you like a reply, and rooms with
28
+ unread mentions or replies show an "@" by their count
29
+ - Mentions & replies: one page, right under Jump to, of every mention of you, reply to you and reaction to your
30
+ messages, newest first; each opens its message in its room
24
31
  - Links in messages are clickable and open in a new tab (http, https and www. addresses only)
25
- - Emoji: a picker in the composer, and reactions on any message (as many different ones as you like), live for everyone
32
+ - Emoji: a picker in the composer with search by name, ":name" suggestions as you type, and reactions on any message
33
+ (as many different ones as you like), live for everyone
26
34
  - Attachments: up to 10 files of 20 MB per message, with an upload progress bar; images shown as thumbnails and videos as their first frame (4 tiles, then "+N"); files are private to whoever can read the message
27
35
  - Image viewer: click a thumbnail to see it full size (or a video to play it) and step through the room's images and videos (buttons, arrow keys, swipe);
28
36
  loaded only when first used, so it adds nothing to the page's first load
@@ -31,7 +39,16 @@ A small, fast, real-time group chat. One [PocketBase](https://pocketbase.io) bin
31
39
  - Unread counts on every room and DM, live, and in sync across your tabs and devices; the total shows in the tab's favicon and title;
32
40
  a room with unread messages opens at the first of them, under a "New" line
33
41
  - What you were typing is kept per room, even across a reload; "Jump to latest" whenever you are scrolled up
42
+ - Invite links for private rooms: share one link that adds whoever opens it (after logging in or signing up) as a
43
+ member; it works for 1, 7 or 30 days and can be revoked or replaced at any time (web and Android)
44
+ - Moderators, chosen by the admin: they delete anyone's messages, change any room's access, archive rooms, and ban or
45
+ unban people (a banned account can't log in); DMs and private rooms they aren't in stay out of their reach
46
+ - Usage statistics at `/stats` for moderators and the admin: people online now, messages and active people over
47
+ time, no names (the admin can turn collecting them off)
48
+ - Anonymous rooms, set by the admin: messages show the room's name instead of their authors
34
49
  - Your own branding (title and logo) and, if you like, invite-only signups: set by the admin in PocketBase
50
+ - Forgot password: once the admin sets up email, "Forgot password?" on the login page (web and Android) emails a link
51
+ that sets a new password and logs out every device
35
52
  - Telegram bridge (optional): link rooms to Telegram groups through a bot; messages, replies, edits, files and (with the bot an admin) reactions go both ways (deletes from Chirkle to Telegram), Telegram people show under stand-in accounts with their names and pictures — see [Telegram integration](#telegram-integration)
36
53
  - Fast room switching: each room's latest messages are kept in the browser (IndexedDB) and shown at once while the
37
54
  server answers; unread rooms are fetched ahead. Attachment thumbnails are kept by the service worker, so going back
@@ -77,19 +94,20 @@ Open the page and sign up. The first run prints a link to create the admin (supe
77
94
  `HOST` and `PORT` choose the address (default `127.0.0.1:8090`; `HOST=0.0.0.0` to reach it from other machines),
78
95
  `CHIRKLE_DATA` the data directory (default `./pb_data`), and any other `pocketbase serve` flags can follow
79
96
  (`npx chirkle --http=0.0.0.0:80`). The settings of [Deploying](#deploying) (`TRUSTED_PROXY` behind a reverse proxy, …)
80
- apply as they are. PocketBase is kept in the package's `bin/` (or `~/.cache/chirkle/` when that isn't writable).
97
+ apply as they are. The package ships the server built for Linux and macOS (x64, arm64): no Go or PocketBase download
98
+ needed.
81
99
 
82
100
  ## Getting started (development)
83
101
 
84
102
  ```sh
85
103
  npm ci
86
- npm run setup # downloads the pinned PocketBase (checksum-verified) into bin/
87
- npm run dev # esbuild watch + PocketBase on http://127.0.0.1:8090
104
+ npm run setup # builds the server (server/: PocketBase with Go hooks) into bin/chirkle-server; needs Go 1.27+
105
+ npm run dev # esbuild watch + the server on http://127.0.0.1:8090
88
106
  ```
89
107
 
90
108
  Open http://127.0.0.1:8090 and sign up (top right). The dev database lives in `pb_data/` — delete it to start over.
91
109
  The PocketBase admin UI is at http://127.0.0.1:8090/_/ (create a superuser with
92
- `bin/pocketbase superuser upsert you@example.com <password> --dir=pb_data`).
110
+ `bin/chirkle-server superuser upsert you@example.com <password> --dir=pb_data`).
93
111
 
94
112
  ## Scripts
95
113
 
@@ -109,6 +127,7 @@ The PocketBase admin UI is at http://127.0.0.1:8090/_/ (create a superuser with
109
127
  | `npm run schema:snapshot` | Rewrite `docs/schema.snapshot.json` (every collection's API rules, fields and indexes, and the rate limits) after a migration changes them; `test:int` fails while it is out of date |
110
128
  | `npm run screenshots` | Rewrite the README screenshots (`docs/screenshot-*.png`, `docs/collections-*.png`): a throwaway server with made-up people, messages and collections, photographed in Chromium after `npm run build` |
111
129
  | `npm run check` | typecheck + lint + lint:sinks + test + test:int + build (what CI runs before e2e) |
130
+ | `npm run doctor` | Is this machine ready for the tests? Go, the server binary, ffmpeg, versitygw, free space in `TMPDIR`, stray test servers, free e2e ports, and a browser that starts and draws text (`-- --browsers=chromium,firefox,webkit`). The e2e setup runs it first |
112
131
 
113
132
  Every test run starts its own PocketBase on a free port with a temp data dir — nothing to clean up, and no fakes
114
133
  except a stub Telegram Bot API for the bridge's tests. CI (`.github/workflows/ci.yml`) runs typecheck, lint and build, then unit, integration and e2e side by side, e2e once
@@ -124,47 +143,56 @@ web/src/ frontend: api.ts (the only module that talks to PocketBase, thr
124
143
  store, cache.ts (the room cache), sw.ts (the service worker), views/, lib/ (pure logic)
125
144
  web/styles/ app.css (bundles app/*.css, one file per part) and viewer.css
126
145
  web/public/ icons/: the logo (logo.svg) as icon.svg and the PNG app icons, served as they are
127
- scripts/ build, dev, fetch-pocketbase, pb-types (PocketBase's types for the hooks), html-sink check
146
+ server/ the server binary: PocketBase with its JS hooks, plus the hot paths in Go (enrich, live, pages, unread)
147
+ scripts/ build, dev, build-server, pb-types (PocketBase's types for the hooks), html-sink check
128
148
  tests/ unit/, integration/, e2e/, perf/ (scale measurements), support/ (PocketBase harness, Telegram stub, helpers)
129
149
  android/ the Android app (docs/ANDROID.md): core/data (API, realtime, database, sync), core/ui, feature/*, app
130
150
  ```
131
151
 
132
152
  ## Deploying
133
153
 
134
- Build once, then copy `bin/pocketbase`, `pb_public/`, `pb_migrations/` and `pb_hooks/` to the server.
154
+ ### systemd, in one command
155
+
156
+ On a Linux server with Node 22+, with a domain pointing at it, this installs Chirkle as a systemd service that serves
157
+ HTTPS itself (Let's Encrypt, on :80/:443):
158
+
159
+ ```sh
160
+ sudo npx chirkle install-service chat.example.com
161
+ sudo -u chirkle /opt/chirkle/chirkle-server superuser upsert you@example.com <password> --dir=/opt/chirkle/pb_data
162
+ ```
163
+
164
+ It copies the server, `pb_public/`, `pb_migrations/` and `pb_hooks/` to `/opt/chirkle`, creates the system user
165
+ `chirkle`, which owns the data directory `/opt/chirkle/pb_data` (and nothing else), writes
166
+ `/etc/systemd/system/chirkle.service` (sandboxed: `ProtectSystem`, `ProtectHome`, `NoNewPrivileges`), and enables and
167
+ starts it. Run it again — `sudo npx chirkle@latest install-service chat.example.com` — to upgrade: the files are
168
+ replaced and the service restarted, the data stays. `sudo npx chirkle uninstall-service` stops and removes the unit
169
+ (files and data are left for you to delete).
170
+
171
+ - Without a domain it listens on `127.0.0.1:8090` for a reverse proxy on the same machine, and sets
172
+ `TRUSTED_PROXY=X-Forwarded-For` (see below); `--http=<addr>` picks another address (trusted only on loopback).
173
+ - `--prefix=<dir>`, `--data=<dir>`, `--user=<name>`, `--name=<unit>` (several instances side by side) change the
174
+ defaults; any other flag goes to `serve`.
175
+ - `--dry-run` prints the unit file and what it would do, and changes nothing; use it to write the unit yourself.
176
+ - More settings (`FFMPEG=`, other environment): `sudo systemctl edit chirkle`, which survives reinstalls.
177
+
178
+ ### By hand
179
+
180
+ Build once, then copy `bin/chirkle-server`, `pb_public/`, `pb_migrations/` and `pb_hooks/` to the server. It is PocketBase
181
+ with the hot paths in Go (`server/`): the same commands and flags as the `pocketbase` binary. Go builds it for another
182
+ platform with `GOOS`/`GOARCH` (`node scripts/build-server.mjs --all` builds them all into `bin/release/`).
135
183
  Migrations run automatically on start, and nothing is served until they are done, so they change only the database.
136
184
  What stored files need moving (the shared files of DESIGN.md §37) the media worker does afterwards, while the server
137
185
  runs.
138
186
 
139
187
  ```sh
140
188
  npm ci && npm run setup && npm run build
141
- rsync -a bin/pocketbase pb_public pb_migrations pb_hooks server:/opt/chirkle/
189
+ rsync -a bin/chirkle-server pb_public pb_migrations pb_hooks server:/opt/chirkle/
142
190
  ```
143
191
 
144
- With a domain pointing at the server, PocketBase serves HTTPS itself (Let's Encrypt):
145
-
146
- ```ini
147
- # /etc/systemd/system/chirkle.service
148
- [Unit]
149
- Description=Chirkle (PocketBase)
150
- After=network-online.target
151
-
152
- [Service]
153
- User=chirkle
154
- WorkingDirectory=/opt/chirkle
155
- ExecStart=/opt/chirkle/pocketbase serve chat.example.com --hooksPool=100 --dir=/opt/chirkle/pb_data --publicDir=/opt/chirkle/pb_public --migrationsDir=/opt/chirkle/pb_migrations --hooksDir=/opt/chirkle/pb_hooks
156
- Restart=on-failure
157
- AmbientCapabilities=CAP_NET_BIND_SERVICE
158
- LimitNOFILE=65536
159
-
160
- [Install]
161
- WantedBy=multi-user.target
162
- ```
163
-
164
- ```sh
165
- sudo systemctl enable --now chirkle
166
- sudo -u chirkle /opt/chirkle/pocketbase superuser upsert you@example.com <password> --dir=/opt/chirkle/pb_data
167
- ```
192
+ With a domain pointing at the server, PocketBase serves HTTPS itself (Let's Encrypt): run
193
+ `chirkle-server serve chat.example.com --hooksPool=100 --dir=… --publicDir=… --migrationsDir=… --hooksDir=…` under your
194
+ init system with `CAP_NET_BIND_SERVICE` (`npx chirkle install-service chat.example.com --dry-run` prints a systemd unit
195
+ for it).
168
196
 
169
197
  Behind an existing reverse proxy instead, use `serve --http=127.0.0.1:8090` and proxy to it (keep
170
198
  `/api/realtime` unbuffered — it is a Server-Sent Events stream — and let request bodies through up to 210 MB, since a
@@ -192,11 +220,23 @@ dokku nginx:set chirkle client-max-body-size 210m
192
220
  dokku letsencrypt:enable chirkle # with the dokku-letsencrypt plugin
193
221
  ```
194
222
 
195
- Then deploy (`git push dokku master` from a clone with `dokku@server:chirkle` as the `dokku` remote) and create a
196
- superuser:
223
+ Then deploy. The light way is to run the image GitHub builds: after CI passes on `master`,
224
+ `.github/workflows/image.yml` pushes `ghcr.io/border-radius/chirkle:<commit>` (and `:latest`), so the server only pulls
225
+ and restarts, however many apps run it:
197
226
 
198
227
  ```sh
199
- dokku run chirkle /app/pocketbase superuser upsert you@example.com <password> --dir=/pb_data
228
+ dokku git:from-image chirkle ghcr.io/border-radius/chirkle:<commit> # each deploy needs a new tag: use the commit
229
+ ```
230
+
231
+ To follow `master`, run that from cron with the commit `git ls-remote https://github.com/border-radius/chirkle.git
232
+ refs/heads/master` names; until its image exists (CI and the build take a few minutes, and a commit that fails CI
233
+ gets none) `docker pull` of it fails, and the app keeps running what it has.
234
+
235
+ Or build on the server: `git push dokku master` from a clone with `dokku@server:chirkle` as the `dokku` remote, or
236
+ `dokku git:sync --build chirkle https://github.com/border-radius/chirkle.git master`. Then create a superuser:
237
+
238
+ ```sh
239
+ dokku run chirkle /app/chirkle-server superuser upsert you@example.com <password> --dir=/pb_data
200
240
  ```
201
241
 
202
242
  Settings go in as environment variables (`dokku config:set chirkle KEY=value`, which restarts the app); the image already
@@ -211,10 +251,22 @@ only people who have the code sign up (they enter it on the Sign up form; it is
211
251
  the old one working; leave it empty to close signups. Existing accounts are unaffected, and you can still create
212
252
  accounts yourself under *Collections → users*.
213
253
 
254
+ **Moderators and statistics:** in the admin UI, *Collections → users*, tick `moderator` on someone's record. They
255
+ then delete messages, change room access, archive rooms and ban people from the app (`banned` on the same record
256
+ undoes a ban), and find usage statistics on Settings; superusers signed in to the admin UI open `/stats` directly.
257
+ Tick `no_stats` on the *site* record to stop recording them.
258
+
259
+ **Forgot password:** in the admin UI, set *Settings → Application → Application URL* to the server's public
260
+ address (the emailed link starts with it) and the sender under *Settings → Mail settings*, and turn on *Use SMTP
261
+ mail server* with your provider's host, port and login; *Send test email* checks it. Only then do the login pages
262
+ offer "Forgot password?" (an SMTP server set but turned off isn't used). The link opens `/reset-password/…` on the
263
+ web, works once for 30 minutes, and logs out every device of the account. The email's wording is under *Collections →
264
+ users → Options → Default Password reset email template*; keep `{APP_URL}/reset-password/{TOKEN}` as its link.
265
+
214
266
  **Backups:** in the admin UI, *Settings → Backups* — schedule automatic backups (optionally to S3-compatible
215
267
  storage). Uploaded files (avatars, attachments) live in `pb_data/storage` (or S3, under *Settings → Files storage*) and
216
268
  are part of the backups, so plan disk space for them. **Rate limits** (per IP: messages 10 per 5 s, edits/deletes 20
217
- per 10 s, reactions 30 per 10 s, forwarding and deleting several messages 20 requests per minute each, password changes 5 per minute, new rooms 5 per minute, opening DMs 10 per minute, marking rooms read 120 per minute, signups 20 per minute; PocketBase defaults for the rest)
269
+ per 10 s, reactions 30 per 10 s, forwarding and deleting several messages 20 requests per minute each, password changes 5 per minute, password reset emails 5 per 10 minutes, new rooms 5 per minute, opening DMs 10 per minute, marking rooms read 120 per minute, signups 20 per minute; PocketBase defaults for the rest)
218
270
  are set by the migrations and adjustable under *Settings → Rate limits*.
219
271
 
220
272
  ## Android app
@@ -225,7 +277,7 @@ it ([`CLAUDE.md`](CLAUDE.md), [`android/PARITY.md`](android/PARITY.md)).
225
277
  A native client for any server running Chirkle, with several accounts at once on one server or many (`android/`,
226
278
  design: [`docs/ANDROID.md`](docs/ANDROID.md), §17 for servers and accounts). It needs JDK 17+
227
279
  (21 recommended) and the Android SDK (`ANDROID_HOME`, or `sdk.dir` in `android/local.properties`); Gradle fetches the
228
- rest. Its tests start PocketBase from `bin/`, so run `npm run setup` first.
280
+ rest. Its tests start the server from `bin/`, so run `npm run setup` first.
229
281
 
230
282
  ```sh
231
283
  cd android
@@ -255,20 +307,20 @@ stages `chirkle@0.2.0` on npm; approve it on npmjs.com (2FA) to publish it. Setu
255
307
 
256
308
  ## Link previews
257
309
 
258
- Messages show a line under them for each link: the page's favicon and title ([`docs/DESIGN.md` §28](docs/DESIGN.md)).
310
+ Messages show a line under them for each link: the page's favicon and title ([`docs/DESIGN.md` §28](docs/design/28-link-previews.md)).
259
311
  The server fetches them with `curl` (in the Docker image), only from public addresses. Set `LINK_PREVIEWS=off` to turn
260
312
  it off.
261
313
 
262
314
  ## Media grid
263
315
 
264
- Each room's Media button shows its images and videos as a grid ([`docs/DESIGN.md` §30](docs/DESIGN.md)). A worker on
316
+ Each room's Media button shows its images and videos as a grid ([`docs/DESIGN.md` §30](docs/design/30-media-grid.md)). A worker on
265
317
  the server makes their thumbnails ahead of time, and a poster frame for each video with `ffmpeg` (in the Docker
266
318
  image), which the room shows too, so browsers don't load videos just to draw their first frame. Set `FFMPEG=off` to
267
319
  go without: videos then show their first frame in the room as before, and plain tiles in the grid.
268
320
 
269
321
  ## Telegram integration
270
322
 
271
- An optional bridge between rooms and Telegram groups ([`docs/DESIGN.md` §26](docs/DESIGN.md)). A bot sits in your
323
+ An optional bridge between rooms and Telegram groups ([`docs/DESIGN.md` §26](docs/design/26-telegram-bridge.md)). A bot sits in your
272
324
  groups; once a group is linked to a room, messages, replies, edits and files go both ways (deletes only from Chirkle
273
325
  to Telegram), and reactions too where the bot is a group admin. Telegram people show in the room under stand-in users ("Ann Lee (TG)") with their names and pictures;
274
326
  the bot posts Chirkle messages with the author's name above them.
@@ -298,7 +350,7 @@ the first two to remove it.
298
350
  ## Linked instances
299
351
 
300
352
  Two or more servers running this app can share rooms and let their people write DMs to each other
301
- ([`docs/DESIGN.md` §33](docs/DESIGN.md)). Each room has a home server; the others keep a copy, and messages, edits,
353
+ ([`docs/DESIGN.md` §33](docs/design/33-linked-instances.md)). Each room has a home server; the others keep a copy, and messages, edits,
302
354
  replies, reactions and files go both ways. People from the other server show under stand-in users named after them
303
355
  ("Ann (B)"). Only the admins of both servers pair them and choose which rooms to share.
304
356
 
@@ -0,0 +1,4 @@
1
+ [diffend] Oversized file quarantined before diffing.
2
+ name: package/bin/release/darwin-amd64/chirkle-server
3
+ size: 33843680 bytes
4
+ sha256: d3cb6ef1f9413c1584e9875fc55dadbb38534dc3b3f24b6e36d05b39d78d5cf1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chirkle",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "A small, fast, real-time group chat: one PocketBase server, a vanilla TypeScript web app",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -23,7 +23,8 @@
23
23
  "pb_hooks/",
24
24
  "pb_migrations/",
25
25
  "scripts/start.mjs",
26
- "scripts/fetch-pocketbase.sh"
26
+ "scripts/service.mjs",
27
+ "bin/release/"
27
28
  ],
28
29
  "engines": {
29
30
  "node": ">=22",
@@ -39,16 +40,18 @@
39
40
  ],
40
41
  "scripts": {
41
42
  "start": "node scripts/start.mjs",
42
- "prepack": "npm run build",
43
- "setup": "sh scripts/fetch-pocketbase.sh",
43
+ "prepack": "npm run build && node scripts/build-server.mjs --all",
44
+ "setup": "node scripts/build-server.mjs",
44
45
  "release": "node scripts/release.mjs",
45
46
  "dev": "node scripts/dev.mjs",
47
+ "doctor": "node scripts/doctor.mjs",
46
48
  "build": "node scripts/build.mjs",
47
- "typecheck": "sh scripts/pb-types.sh && tsc --noEmit && tsc --noEmit -p tsconfig.server.json",
49
+ "typecheck": "node scripts/build-server.mjs && sh scripts/pb-types.sh && tsc --noEmit && tsc --noEmit -p tsconfig.server.json",
48
50
  "lint": "biome check .",
49
51
  "format": "biome check --write .",
50
52
  "lint:sinks": "sh scripts/check-no-html-sinks.sh",
51
53
  "test": "vitest run --project unit --project component",
54
+ "test:go": "cd server && nice -n 19 go vet ./... && nice -n 19 go test -p 2 ./...",
52
55
  "test:unit": "vitest run --project unit",
53
56
  "test:watch": "vitest --project unit --project component",
54
57
  "test:int": "vitest run --project integration",
@@ -56,7 +59,7 @@
56
59
  "screenshots": "node --no-warnings scripts/screenshots.ts",
57
60
  "profile:web": "node --no-warnings scripts/profile-web.ts",
58
61
  "schema:snapshot": "vitest run --project integration -u tests/integration/schema.snapshot.test.ts",
59
- "check": "npm run typecheck && npm run lint && npm run lint:sinks && npm test && npm run test:int && npm run build"
62
+ "check": "npm run typecheck && npm run lint && npm run lint:sinks && npm run test:go && npm test && npm run test:int && npm run build"
60
63
  },
61
64
  "devDependencies": {
62
65
  "@axe-core/playwright": "4.13.0",
@@ -4,8 +4,7 @@
4
4
  // - POST /api/fed/inbox { events: [...] }: up to 50 events, each applied in a transaction of its own, in order. The
5
5
  // answer gives each one's status: 200 (applied, or a repeat), 4xx (refused: the sender drops it and logs why), 5xx
6
6
  // (failed for now: the sender tries it again).
7
- // - GET /api/fed/files/{message}/{file}: a message file, to a peer the message's room is shared with.
8
- // - GET /api/fed/avatars/{user}: the picture of someone the peer was told of.
7
+ // - The downloads, GET /api/fed/files/{message}/{file} and /api/fed/avatars/{user}, are in Go (server/federation.go).
9
8
  // - GET /api/fed/users?name=&for=dm|member: one person by exact name, for a DM or to add to a shared private room.
10
9
 
11
10
  const { canSee, accessOf } = require(`${__hooks}/lib/access.js`);
@@ -146,72 +145,6 @@ function inbox(e) {
146
145
  return e.json(200, { results });
147
146
  }
148
147
 
149
- /**
150
- * GET /api/fed/files/{message}/{file}: a file of a message in a room shared with the peer (as the home, or as its
151
- * mirror's home). A forward's are its original's (§33.5).
152
- * @param {core.RequestEvent} e
153
- */
154
- function file(e) {
155
- const { peer } = verify(e);
156
- const id = e.request?.pathValue("message") ?? "";
157
- const name = e.request?.pathValue("file") ?? "";
158
- let msg;
159
- try {
160
- msg = e.app.findRecordById("messages", id);
161
- } catch {
162
- throw new NotFoundError();
163
- }
164
- const room = e.app.findRecordById("rooms", msg.getString("room"));
165
- const shared =
166
- room.getString("peer") === peer.id ||
167
- e.app.findRecordsByFilter("fed_shares", "room = {:r} && peer = {:p} && state = 'active'", "", 1, 0, { r: room.id, p: peer.id }).length >
168
- 0;
169
- if (!shared || msg.getBool("deleted")) throw new NotFoundError();
170
- let src = msg;
171
- if (msg.getString("forward_of")) {
172
- try {
173
- src = e.app.findRecordById("messages", msg.getString("forward_of"));
174
- } catch {
175
- throw new NotFoundError();
176
- }
177
- }
178
- if (!src.getStringSlice("files").includes(name)) throw new NotFoundError();
179
- // Its shared file (§37).
180
- const files = require(`${__hooks}/lib/files.js`);
181
- const row = files.byName(e.app, name);
182
- if (!row) throw new NotFoundError();
183
- const fs = e.app.newFilesystem();
184
- try {
185
- fs.serve(e.response, /** @type {any} */ (e.request), files.keyOf(row), name);
186
- } finally {
187
- fs.close();
188
- }
189
- }
190
-
191
- /**
192
- * GET /api/fed/avatars/{user}: the picture of someone the peer was told of.
193
- * @param {core.RequestEvent} e
194
- */
195
- function avatar(e) {
196
- const { peer } = verify(e);
197
- const id = e.request?.pathValue("user") ?? "";
198
- let user;
199
- try {
200
- user = e.app.findRecordById("users", id);
201
- e.app.findFirstRecordByFilter("fed_people", "peer = {:p} && user = {:u} && kind = 'known'", { p: peer.id, u: id });
202
- } catch {
203
- throw new NotFoundError();
204
- }
205
- const name = user.getString("avatar");
206
- if (!name) throw new NotFoundError();
207
- const fs = e.app.newFilesystem();
208
- try {
209
- fs.serve(e.response, /** @type {any} */ (e.request), `${user.baseFilesPath()}/${name}`, name);
210
- } finally {
211
- fs.close();
212
- }
213
- }
214
-
215
148
  /**
216
149
  * GET /api/fed/users?name=&for=dm|member: one of this instance's own people by their exact name (never a list, so
217
150
  * nobody can go through another instance's people, §33.5). For a DM, only while DMs with the peer are on and they take
@@ -313,4 +246,4 @@ function remoteUser(e) {
313
246
  });
314
247
  }
315
248
 
316
- module.exports = { inbox, file, avatar, lookup, remoteUser };
249
+ module.exports = { inbox, lookup, remoteUser };
@@ -5,7 +5,7 @@
5
5
  // A message with files is saved once its files are fetched (the worker, §33.8); a forward goes as a snapshot of what it
6
6
  // shows. Service messages, reads, previews and push stay on each instance.
7
7
 
8
- const { reactionsOf, setReaction } = require(`${__hooks}/lib/reactions.js`);
8
+ const { overLimit, reactionsOf, setReaction } = require(`${__hooks}/lib/reactions.js`);
9
9
  /** @typedef {{ emoji: string, users: string[] }} Reaction */
10
10
  const { isReactionEmoji } = require(`${__hooks}/lib/emoji.js`);
11
11
  const { accessOf, canSee } = require(`${__hooks}/lib/access.js`);
@@ -429,8 +429,10 @@ function applyReact(app, sender, ev) {
429
429
  if (!user) throw refusal(403, "Only your own people react from there.");
430
430
  const rec = target(app, sender, ev, false);
431
431
  if (!rec || rec.getBool("deleted") || !rec.getString("author")) return;
432
- const next = setReaction(reactionsOf(rec), ev.emoji, user, ev.on);
433
- if (!next) return;
432
+ const list = reactionsOf(rec);
433
+ const next = setReaction(list, ev.emoji, user, ev.on);
434
+ // Over the limits (QA BUG-258): dropped. A mirror running these hooks refuses it first (lib/reactions.js).
435
+ if (!next || (ev.on && overLimit(list, ev.emoji, user))) return;
434
436
  rec.set("reactions", next);
435
437
  saveFor(app, rec, sender);
436
438
  }
@@ -41,6 +41,7 @@ function httpError(status, message) {
41
41
  /**
42
42
  * Check a server request (§33.6) and return its peer and body. Throws 401 for a request that isn't signed right, 403
43
43
  * for a peer that isn't paired, 503 for one suspended here (it keeps its queue and tries again later, §33.7).
44
+ * server/federation.go fedVerify is a Go copy for the GET downloads: change both, or neither (as `sign`).
44
45
  * @param {core.RequestEvent} e
45
46
  * @param {number} [max] body bytes
46
47
  * @returns {{ peer: core.Record, body: string }}
@@ -185,6 +185,7 @@ function userOf(app, sender, g, people = {}, own = false) {
185
185
  user.setPassword($security.randomString(40));
186
186
  user.set("peer", peer.id);
187
187
  user.set("instance", s.host);
188
+ user.set("kind", "peer");
188
189
  user.set("no_dms", true);
189
190
  saveWithName(app, user, profile.name, labelOf(peer, key));
190
191
  const made = new Record(app.findCollectionByNameOrId("fed_people"));
@@ -32,14 +32,7 @@ routerAdd("POST", "/api/fed/inbox", (e) => {
32
32
  require(`${__hooks}/federation/config.js`).requireOn(e.app);
33
33
  return require(`${__hooks}/federation/inbox.js`).inbox(e);
34
34
  });
35
- routerAdd("GET", "/api/fed/files/{message}/{file}", (e) => {
36
- require(`${__hooks}/federation/config.js`).requireOn(e.app);
37
- return require(`${__hooks}/federation/inbox.js`).file(e);
38
- });
39
- routerAdd("GET", "/api/fed/avatars/{user}", (e) => {
40
- require(`${__hooks}/federation/config.js`).requireOn(e.app);
41
- return require(`${__hooks}/federation/inbox.js`).avatar(e);
42
- });
35
+ // GET /api/fed/files/{message}/{file} and /api/fed/avatars/{user} are in Go (server/federation.go).
43
36
  routerAdd("GET", "/api/fed/users", (e) => {
44
37
  require(`${__hooks}/federation/config.js`).requireOn(e.app);
45
38
  return require(`${__hooks}/federation/inbox.js`).lookup(e);
@@ -38,6 +38,32 @@ function canSee(a, userId) {
38
38
  return a.visibility !== "private" || a.createdBy === userId || a.members.includes(userId);
39
39
  }
40
40
 
41
+ /**
42
+ * Who asks a route for a room: a guest, a signed-in user or a superuser, whom no room is hidden from. canSee is for users
43
+ * only (a mention's target, a member); a request's caller is a viewer. `id` is "" for a guest and for a superuser (a
44
+ * superuser's id is no user's). server/access.go has the same.
45
+ * @typedef {{ id: string, superuser: boolean }} Viewer
46
+ */
47
+
48
+ /**
49
+ * @param {core.Record | null | undefined} auth
50
+ * @returns {Viewer}
51
+ */
52
+ function viewerOf(auth) {
53
+ if (!auth) return { id: "", superuser: false };
54
+ if (auth.isSuperuser()) return { id: "", superuser: true };
55
+ return { id: auth.id, superuser: false };
56
+ }
57
+
58
+ /**
59
+ * canSee for a viewer.
60
+ * @param {Viewer} v
61
+ * @param {Access} a
62
+ */
63
+ function sees(v, a) {
64
+ return v.superuser || canSee(a, v.id);
65
+ }
66
+
41
67
  /**
42
68
  * Can `userId` post in the room (§23.6)? They must see it, signed in, and the room let everyone post or list them as a
43
69
  * writer (its creator always is). The messages create rule says the same.
@@ -57,19 +83,19 @@ function canWrite(room, userId) {
57
83
  const SEES_SQL = "(r.visibility != 'private' OR r.created_by = {:me} OR EXISTS (SELECT 1 FROM json_each(r.members) WHERE value = {:me}))";
58
84
 
59
85
  /**
60
- * The room if `userId` can see it, else null (also for a room that doesn't exist).
86
+ * The room if `v` can see it, else null (also for a room that doesn't exist).
61
87
  * @param {core.App} app
62
88
  * @param {string} roomId
63
- * @param {string} userId
89
+ * @param {Viewer} v
64
90
  */
65
- function visibleRoom(app, roomId, userId) {
91
+ function visibleRoom(app, roomId, v) {
66
92
  let room;
67
93
  try {
68
94
  room = app.findRecordById("rooms", roomId);
69
95
  } catch {
70
96
  return null;
71
97
  }
72
- return canSee(accessOf(room), userId) ? room : null;
98
+ return sees(v, accessOf(room)) ? room : null;
73
99
  }
74
100
 
75
101
  /**
@@ -90,13 +116,10 @@ function dropLostAccess(app, before, room) {
90
116
  for (const id of Object.keys(clients)) {
91
117
  const client = clients[id];
92
118
  if (!client || client.isDiscarded()) continue;
93
- /** @type {core.Record | null | undefined} */
94
- const auth = client.get("auth");
95
- if (auth?.isSuperuser()) continue;
96
- const userId = auth ? auth.id : "";
97
- if (!canSee(before, userId) || canSee(after, userId)) continue;
119
+ const v = viewerOf(/** @type {core.Record | null | undefined} */ (client.get("auth")));
120
+ if (!sees(v, before) || sees(v, after)) continue;
98
121
  for (const name of Object.keys(client.subscriptions("rooms"))) client.send(new SubscriptionMessage({ name, data }));
99
122
  }
100
123
  }
101
124
 
102
- module.exports = { MAX_MEMBERS, SEES_SQL, accessOf, canSee, canWrite, visibleRoom, dropLostAccess };
125
+ module.exports = { MAX_MEMBERS, SEES_SQL, accessOf, canSee, canWrite, viewerOf, sees, visibleRoom, dropLostAccess };