samagotchi 0.111.1 → 0.112.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2153d4c9c7afa58d9d06d330d1839a021032df3502f515d4a093bad7f9dde347
4
- data.tar.gz: 9ac11fddf172afa0eb4c5ea520d3e64471c0b2502753539fafcce28aa4e99294
3
+ metadata.gz: bd818cf8fcf56a7040bdf84299d75a547b2031eb7bea13a1fdb087d12ed051d0
4
+ data.tar.gz: 27890e5a3913053d11b5240c66f335ac66e0c5b4e55a9c0410b7a885ec9319d3
5
5
  SHA512:
6
- metadata.gz: cc73ef6cdd220a1dfb83b4e1b6f51ba4e42c80eff05ae661363b06d4d53b9bf4c0c2c954173997475571518ed98e7f589afe0eb9251787e3a894eab8dd1fec00
7
- data.tar.gz: 9105631a20fcfe1e6889dbc904e146c4fcc68c75e5879111e589efe515ecaaecd4e03b6e7a3f389eb674bd1b0c0bb6a1420dca439b01cdefe04ed508d0830c9a
6
+ metadata.gz: 44e69d35e152608b949071ca95d22367115c8524c284378a1e854ab98636e40f8f53bd5644bd816bfa903a2f3125e3c09a2f297999d4c251ee1bed6bf7a10e52
7
+ data.tar.gz: d47e33d2b044590f507f3f551b179c60aa848e11ca79c9543d3f1af2a4b199f9ffee9bfa590488f66a0b439c65e7600a05c4c2caa335b4c26534782929d6c89e
data/CHANGELOG.md CHANGED
@@ -8,6 +8,33 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.112.0] - 2026-10-25
12
+
13
+ ### Added
14
+
15
+ - chi web: the phone's push notifications now come for everything the tab notifies for: a step-limit question, a card
16
+ that asks (check-in's Nudge / Keep going / Stop) and a failed turn, beside approvals and questions. Done turns are
17
+ off by default, per device (the switch comes with the devices list).
18
+ - chi web: no push while a chi web page is in front and was touched in the last 2 minutes (you are looking); at most
19
+ 30 pushes an hour; a busy push service is tried once more; an approval asked while chi web was restarting is pushed
20
+ once when it starts.
21
+
22
+ ### Changed
23
+
24
+ - chi web: an untitled session's card, top bar and browser tab read its recap's first sentence (what the session is
25
+ doing) instead of its first message, so long-lived sessions started the same way no longer look alike; the card
26
+ then leaves out its recap line, and a session with no recap yet still reads its first message.
27
+
28
+ ### Fixed
29
+
30
+ - chi web: tapping the composer (or any other text field) on an iPhone or iPad no longer zooms the page in. Text
31
+ fields are 16px on phones and touch devices, the size under which iOS Safari zooms on focus (and the Home Screen
32
+ app never zooms back); a mouse desktop keeps its sizes.
33
+ - chi web: the sessions list's cards on an iPhone show their whole preview, title and recap again instead of cutting
34
+ them through the middle.
35
+
36
+ Update with `chi update` (the system bundle 0.112.0), then restart `chi web`.
37
+
11
38
  ## [0.111.1] - 2026-10-25
12
39
 
13
40
  ### Fixed
@@ -4264,7 +4291,8 @@ and long-lived sessions.
4264
4291
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
4265
4292
  hotkey panel that send selected text or the clipboard to your sessions.
4266
4293
 
4267
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.111.1...HEAD
4294
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.112.0...HEAD
4295
+ [0.112.0]: https://github.com/dm1try/samagotchi/compare/v0.111.1...v0.112.0
4268
4296
  [0.111.1]: https://github.com/dm1try/samagotchi/compare/v0.111.0...v0.111.1
4269
4297
  [0.111.0]: https://github.com/dm1try/samagotchi/compare/v0.110.0...v0.111.0
4270
4298
  [0.110.0]: https://github.com/dm1try/samagotchi/compare/v0.109.0...v0.110.0
data/docs/architecture.md CHANGED
@@ -701,8 +701,8 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
701
701
  | LLM context strategies | `llm_context_strategy.rb`, `llm_context_view.rb`, `llm_context_stale.rb`, `llm_context_forget.rb` | What a request sends of the history (none, stale, forget) ([internals/llm-context-forget.md](internals/llm-context-forget.md)). |
702
702
  | Session chains | `session_continue.rb` (`SessionContinue`), `session_chain.rb` (`SessionChain`) | A session that continues an earlier one. `SessionChain.opener_for` gives the text web `continue →` prefills in the new link: the previous link's own first typed message when that link continues one itself, else nil (the 201's `opener`; not saved) ([sessions.md](sessions.md)). |
703
703
  | Review sessions | `review_start.rb` (`ReviewStart`), `session_review.rb` (`SessionReview`, the session's `review` field), `review_command.rb` (`ReviewCommand`, `chi review`), `review_apply.rb` (`ReviewApply`) | A session made to be shared: idle, its subjects project files checked by `Guardrails::ReviewPaths`, a fork of a working session from its recap (`--from`); Apply quotes a participant's review turn into the owner's composer ([sessions.md](sessions.md#review-sessions), [internals/participants.md](internals/participants.md)). |
704
- | chi web's routes | `web/app.rb` (`Web::App`: the gate, `ROUTES`, the shared helpers), `web/message_display.rb` (`Web::MessageDisplay`: saved messages and cards as display items, `POST /api/render`), `web/session_show.rb` (`Web::SessionShow`: `GET /api/sessions/:id` with its `cards`, `tail` and `timing` re-reads, `GET …/output`, the timing payload), `web/session_create.rb` (`Web::SessionCreate`: `POST /api/sessions`, a continue, a review fork), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `web/push_routes.rb` (`Web::PushRoutes`: `/api/push`, its subscriptions and test) | The handlers `App`'s `ROUTES` name, in the file that holds their kind; each mixin is included in `App` and reads its helpers and ivars, so `app.send(:handle_show, …)` and the specs that stub `App` methods work as before. |
705
- | Web Push | `web/push.rb` (`Web::Push`: `Runtime`, `preflight!`, the `web.push.*` settings), `web/push/crypto.rb` (`Push::Crypto`: RFC 8291 aes128gcm, RFC 8292 VAPID), `web/push/store.rb` (`Push::Store`, `Store::Sub`: `web-push/vapid.pem`, `subscriptions.json`), `web/push/client.rb` (`Push::Client`, `Client::Result`), `web/push/attention.rb` (`Push::Attention`: notify.js's rules in Ruby), `web/push/notifier.rb` (`Push::Notifier`, a hub subscriber with a sender thread), `web/push_routes.rb` (`Web::PushRoutes`), `web/private_files.rb` (`Web::PrivateFiles`, shared with the grants), `public/sw.js`, `public/push.js`, `public/manifest.webmanifest` | chi web pushes approvals and questions to the owner's Home Screen app over an https public URL: the Notifier turns the hub's new approvals and questions into show pushes after a hold (each carries the keys still open, and the badge; no close push: every push shows a notification); the bell (`notifications.js`) subscribes the device, and the service worker and the page close the answered ones. See [internals/web-push.md](internals/web-push.md). |
704
+ | chi web's routes | `web/app.rb` (`Web::App`: the gate, `ROUTES`, the shared helpers), `web/message_display.rb` (`Web::MessageDisplay`: saved messages and cards as display items, `POST /api/render`), `web/session_show.rb` (`Web::SessionShow`: `GET /api/sessions/:id` with its `cards`, `tail` and `timing` re-reads, `GET …/output`, the timing payload), `web/session_create.rb` (`Web::SessionCreate`: `POST /api/sessions`, a continue, a review fork), `web/session_control.rb` (`Web::SessionControl`: answer, command, turn and images, cancel, stop, restart, archive, delete), `web/push_routes.rb` (`Web::PushRoutes`: `/api/push`, its subscriptions, prefs, test and presence) | The handlers `App`'s `ROUTES` name, in the file that holds their kind; each mixin is included in `App` and reads its helpers and ivars, so `app.send(:handle_show, …)` and the specs that stub `App` methods work as before. |
705
+ | Web Push | `web/push.rb` (`Web::Push`: `Runtime`, `preflight!`, the `web.push.*` settings), `web/push/crypto.rb` (`Push::Crypto`: RFC 8291 aes128gcm, RFC 8292 VAPID), `web/push/store.rb` (`Push::Store`, `Store::Sub`: `web-push/vapid.pem`, `subscriptions.json`), `web/push/client.rb` (`Push::Client`, `Client::Result`), `web/push/attention.rb` (`Push::Attention`: notify.js's rules in Ruby, shared cases in `spec/fixtures/attention_cases.json`), `web/push/presence.rb` (`Push::Presence`: the pages' "in front" reports), `web/push/notifier.rb` (`Push::Notifier`, a hub subscriber with a sender thread), `web/push_routes.rb` (`Web::PushRoutes`), `web/private_files.rb` (`Web::PrivateFiles`, shared with the grants), `public/sw.js`, `public/push.js`, `public/manifest.webmanifest` | chi web pushes what the tab notifies for (approvals, questions, step-limit questions, cards, failed turns; done turns to a device that asks) to the owner's Home Screen app over an https public URL: the Notifier turns the hub's new attentions into show pushes after a hold, unless a chi web page is in front, at most 30 an hour, with one retry and a restart catch-up (`sent.json`) (each carries the keys still open, and the badge; no close push: every push shows a notification); the bell (`notifications.js`) subscribes the device, and the service worker and the page close the answered ones. See [internals/web-push.md](internals/web-push.md). |
706
706
  | Behind an auth proxy | `web/public_url.rb` (`Web::PublicUrl`: `web.public_url`, `web.proxy.identity_header`, `web.proxy.owner`), `web/proxy_gate.rb` (`Web::ProxyGate`, mixed into App; `RawHeaderNames`, prepended to WEBrick's request by `Web::Server`), `web/link_codes.rb` (`Web::LinkCodes`: the links' one-time codes), `proxy_trace.rb` (`ProxyTrace`), `web/public/token_fragment.js`, `web/public/auth_lost.js`, `web/tunnel.rb` + `web/tunnel/tailscale.rb` (`Web::Tunnel`, `Web::Tunnel::Tailscale`: `chi web --tunnel tailscale`, Tailscale Serve set for one run and the PublicUrl it makes) | Experimental: chi web behind an auth proxy. Every request needs the token; a proxied one's owner also needs the identity header (one clean value under one name); the `__Host-` cookie, an absolute `Location` from the public URL, https links with a one-time code in the fragment; the page's lost-sign-in banner. Bridges refuse proxy traces ([configuration.md](configuration.md#behind-an-auth-proxy)). |
707
707
  | Participants | `participants.rb` (`Participants`, the `participants.json` sidecar), `share_command.rb` (`ShareCommand`, `chi share`), `session_participants.rb`, `participants_watch.rb`, `web/grants.rb` (`Web::Grants`), `web/principal.rb` (`Web::Principal`), `web/participant_access.rb` (`Web::ParticipantAccess`: the participant's gate and routes), `web/participants_admin.rb` (`Web::ParticipantsAdmin`: the owner's invite, list, revoke, cap and Apply routes), `web/participant_review.rb` + `web/participant_view.rb` (`Web::ParticipantReview`, `Web::ParticipantView`), `web/participant_stream_filter.rb`, `guardrails/review_boundary.rb` + `guardrails/review_paths.rb` | The people or agents an owner invites to review one session through chi web: their grants and gate, what they read, their read-only review turns ([internals/participants.md](internals/participants.md), [guardrails.md](guardrails.md)). |
708
708
  | Analytics | `analytics_file.rb` (`AnalyticsFile`), `session_metrics/totals.rb` (`SessionMetrics::Totals`), `session_metrics/model_segment.rb` (`SessionMetrics::ModelSegment`) | A session's `analytics.json` (`SessionMetrics#persist`); the sums over its turn records (`Totals`: tokens, cost, speeds, kept as running counters) and their split per model after a `/model` switch (`ModelSegment`: a run of turns on one model, the `model_segments` rows); `session_metrics/cost.rb` (`SessionMetrics::Cost`): the spend `ctx.cost` reads; `session_metrics/usage.rb` (`SessionMetrics::Usage`): the work `ctx.usage` reads. `session_metrics/side_totals.rb` (`SessionMetrics::SideTotals`) and `side_usage.rb` (`SideUsage`): the side requests' sums, apart from the turns'. |
@@ -1770,10 +1770,11 @@ Tailnet Lock is off: a device Tailscale's servers add to your tailnet could reac
1770
1770
 
1771
1771
  ### Phone notifications (Web Push)
1772
1772
 
1773
- chi web as an app on your iPhone's Home Screen that buzzes (the Watch too) when a session waits on an **approval** or
1774
- a **question**, also while the app is closed. A tap opens that session; once it is answered anywhere (the Mac, the
1775
- phone, `chi answer`), its notification goes when you open the app (or swipe it away). Every
1776
- push shows a notification: iOS turns off an app's pushes after a few that show none.
1773
+ chi web as an app on your iPhone's Home Screen that buzzes (the Watch too) when a session needs you: an
1774
+ **approval**, a **question**, a **step-limit** question, a **card** that asks (check-in's Nudge / Keep going / Stop),
1775
+ or a **failed turn**, also while the app is closed. A tap opens that session; once it is answered anywhere (the Mac,
1776
+ the phone, `chi answer`), its notification goes when you open the app (or swipe it away; a failed turn's stays until
1777
+ you do). Every push shows a notification: iOS turns off an app's pushes after a few that show none.
1777
1778
 
1778
1779
  What it needs:
1779
1780
 
@@ -1787,18 +1788,26 @@ app → tap the **bell** at the top → Allow. A test notification arrives at on
1787
1788
  bell again to turn it off on that phone. In a browser tab the bell stays the tab's own notifications (while the tab
1788
1789
  is in the background), as before.
1789
1790
 
1790
- - **What is sent**: the session's name and the reason ("needs approval", "needs an answer"), never the question or
1791
- the command, as the tab's notification on the Mac. The session's name shows on the lock screen and the Watch.
1791
+ - **What is sent**: the session's name and the reason ("needs approval", "needs an answer", "hit its step limit",
1792
+ "needs you", "turn failed", "done in N s"), never the question or the command, as the tab's notification on the
1793
+ Mac. The session's name shows on the lock screen and the Watch.
1792
1794
  - **What Apple sees**: the push is end-to-end encrypted to the phone; Apple's push service sees that this machine
1793
1795
  pushes to that device, and when. A subscription holds no device name and no personal data (an opaque address on
1794
1796
  `web.push.apple.com` and two keys); chi names it itself ("iPhone · 2026-10-24", from the User-Agent's device class
1795
1797
  and the date).
1796
- - **When**: an approval or a question that is still open 3 s after it was asked (3.5 s for a delegated child's
1797
- approval, which its parent may relay instead); one push per question; a step-limit question, a failed or a long
1798
- turn don't push yet. A push arrives even while you look at the page (the phone can't tell chi web that it is in
1799
- front yet).
1800
- - **The files**: `$XDG_STATE_HOME/samagotchi/web-push/` (next to `web-token`): `vapid.pem` (chi web's key) and
1801
- `subscriptions.json` (the devices), 0600 in a 0700 folder; chi web refuses to start when others can read them.
1798
+ - **When**: the same things the tab notifies for, still open 3 s after they came (3.5 s for a delegated child's
1799
+ approval, which its parent may relay instead); one push each. A delegated child's failed or finished turn is its
1800
+ parent's to report. **Done turns** (10 s or longer, or one nobody started: a delegate's report, a context change, a
1801
+ finished task) are **off** by default, per device; the switch comes with the devices list (for now:
1802
+ `PATCH /api/push/subscriptions/ID {"prefs": {"done": true}}`, the id from `GET /api/push`'s `devices`).
1803
+ - **Quiet while you look**: nothing is pushed while any chi web page (a tab on the Mac, or the app) is in front and
1804
+ was touched in the last 2 minutes; what came meanwhile is never pushed later (the page has it). A page left in
1805
+ front untouched stops quieting the phone after about 2 minutes.
1806
+ - **Limits**: at most 30 pushes an hour (the rest are dropped, with one warning on chi web's terminal); a busy push service is tried once more. An approval or question asked while chi web was stopped or
1807
+ restarting (under an hour ago, still open) is pushed once when it starts; the first restart after updating may
1808
+ push one you already saw, once.
1809
+ - **The files**: `$XDG_STATE_HOME/samagotchi/web-push/` (next to `web-token`): `vapid.pem` (chi web's key),
1810
+ `subscriptions.json` (the devices) and `sent.json` (what was pushed in the last day), 0600 in a 0700 folder; chi web refuses to start when others can read them.
1802
1811
  Subscriptions belong to the public URL they were made on: after renaming the machine or the tailnet, turn the bell
1803
1812
  on again on the phone (the old ones are never sent to). iOS can drop a subscription without telling chi web; if
1804
1813
  notifications stop arriving, turn the bell off and on again: the new subscription replaces the dead one.
@@ -1940,7 +1949,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
1940
1949
  | `web.public_url` | | | Experimental. The https origin people open `chi web` at through an auth proxy (`https://host` or `https://host:port`, no path); set, every request needs the access token, this machine's too, and links use it. A value that isn't an https origin stops `chi web` from starting. See [Behind an auth proxy](#behind-an-auth-proxy). |
1941
1950
  | `web.proxy.identity_header` | | | Experimental. The request header the proxy puts the signed-in user's email in (`X-Forwarded-Email` for oauth2-proxy), checked next to the token: only one the proxy sets *and* replaces. Unset or `none`: the token alone decides. See [Behind an auth proxy](#behind-an-auth-proxy). |
1942
1951
  | `web.proxy.owner` | | | Experimental. Your email as the identity header carries it (any case): a proxied request is the owner only with this identity and the token. Unset: nobody is the owner by identity. Needs `web.proxy.identity_header`. |
1943
- | `web.push.enabled` | `true` | | Push notifications to a phone's Home Screen app (approvals and questions) when the bell there is on. Does anything only with an https public URL (`web.public_url`, or `chi web --tunnel tailscale`'s) and once a device subscribed; `false` turns the pushes and the routes off. See [Phone notifications](#phone-notifications-web-push). |
1952
+ | `web.push.enabled` | `true` | | Push notifications to a phone's Home Screen app (approvals, questions, step-limit questions, cards, failed turns; done turns per device) when the bell there is on. Does anything only with an https public URL (`web.public_url`, or `chi web --tunnel tailscale`'s) and once a device subscribed; `false` turns the pushes and the routes off. See [Phone notifications](#phone-notifications-web-push). |
1944
1953
  | `web.push.contact` | the public URL | | The contact the push services see in chi web's VAPID token: a `mailto:` address or an `https://` URL. Anything else stops `chi web` from starting (Apple refuses it). |
1945
1954
  | `history.file` | state dir | | Prompt history path, shared by the TUI and the web composer. |
1946
1955
  | `no_interrupt` | `false` | `--no-interrupt` | Raise the step limit of a turn to 1000 (or `turn.max_iterations`, when larger); a top-level key. |
@@ -1,17 +1,19 @@
1
1
  # Web Push (internals)
2
2
 
3
- chi web pushes to the owner's phone when a session waits on an approval or a question: the phone runs chi web as a
4
- Home Screen app (iOS 16.4+), its bell subscribes the device, and chi web, the only sender, pushes through the
5
- device's push service (Apple's `web.push.apple.com`). The user side is in
6
- [configuration.md](../configuration.md#phone-notifications-web-push). This page is how it is built (P1 of the plan:
7
- approvals and questions; the step-limit question, cards, failed and done turns, presence and the device list come
8
- later).
3
+ chi web pushes to the owner's phone when a session needs them, for what the tab notifies for: an approval, a
4
+ question, a step-limit question, a card with actions, a failed turn, and (per device, off by default) a done one. The
5
+ phone runs chi web as a Home Screen app (iOS 16.4+), its bell subscribes the device, and chi web, the only sender,
6
+ pushes through the device's push service (Apple's `web.push.apple.com`). The user side is in
7
+ [configuration.md](../configuration.md#phone-notifications-web-push). This page is how it is built (P1 and P2a of the
8
+ plan; the devices list in the page and `chi web push` come later).
9
9
 
10
10
  ```
11
11
  SessionHub ──emit──▶ Notifier#call(event) ──Queue──▶ sender thread
12
- Attention rules hold 3 s → still open?
12
+ Attention rules hold 3 s → still open? a page in front? the cap?
13
13
  Crypto.encrypt + VAPID → Client#deliver(endpoint)
14
14
  201 ok · 404/410 drop the device · 403 BadJwtToken stop + log
15
+ 429/5xx one retry · handled keys → sent.json
16
+ page ──POST /api/push/presence──▶ Presence (in front, touched < 2 min)
15
17
  service worker ◀── Apple (web.push.apple.com) ◀──────── {v, kind: show, tag, title, body, url, badge, open?}
16
18
  ```
17
19
 
@@ -50,8 +52,14 @@ files, one per machine, never in config.yml:
50
52
  another key and makes a new one.
51
53
  - `subscriptions.json`: `{"version": 1, "subscriptions": [{id, endpoint, keys: {p256dh, auth}, origin, label,
52
54
  created_at, last_ok_at, last_error, prefs}]}`, read as `Store::Sub` values. `id` is the first 8 hex of the
53
- endpoint's SHA-256: the only name of a device outside the store. `Sub#public_h` and `#inspect` never carry the
54
- endpoint or the keys; neither do the log lines.
55
+ endpoint's SHA-256: the only name of a device outside the store. `Sub#public_h` (id, label, origin, the dates,
56
+ `last_error`, `prefs: {done:}`) and `#inspect` never carry the endpoint or the keys; neither do the log lines.
57
+ `prefs` is `{"done": false}` until `Store#set_prefs(id, done:, origin:)` (the PATCH route) sets it; `Sub#done?`.
58
+ - `sent.json`: `{"version": 1, "keys": {KEY: iso time}}`, the attention keys already handled (a device took the
59
+ show, or it was skipped while a page was in front, or capped), written by `Store#mark_sent` under `store.lock`,
60
+ keys older than a day (`SENT_KEEP`) pruned on each write. `Store#sent_keys` reads it; one that doesn't read is
61
+ logged once (`push_sent_corrupt`) and read as none, and the next write replaces it (it only spares a restart's
62
+ repeat). It is in `check_permissions!`'s list.
55
63
 
56
64
  `Store#add` checks what `pushManager.subscribe` gave, one message per refusal (the route answers it as 400
57
65
  `invalid_subscription`): an endpoint and both keys; https on port 443 without userinfo, at most 2048 bytes; a host in
@@ -73,9 +81,11 @@ tailnet leaves the old ones stale (never sent to: a tap would open an origin tha
73
81
  ## The client (`web/push/client.rb`)
74
82
 
75
83
  `Client#deliver(sub, payload, ttl:, urgency:)` encrypts the payload's JSON, POSTs it over TLS (open 5 s, read 10 s,
76
- no redirects, no retry) with `Content-Encoding: aes128gcm`, `TTL`, `Urgency` and the VAPID header, and answers a
77
- `Client::Result`: `:ok` (200/201/202), `:gone` (404/410: the device dropped it), `:bad_jwt` (403 with
78
- `BadJwtToken`), `:failed` (anything else; a connection error as its class name or `timeout`, never its message). The
84
+ no redirects, no retry of its own) with `Content-Encoding: aes128gcm`, `TTL`, `Urgency` and the VAPID header, and
85
+ answers a `Client::Result`: `:ok` (200/201/202), `:gone` (404/410: the device dropped it), `:bad_jwt` (403 with
86
+ `BadJwtToken`), `:failed` (anything else; a connection error as its class name or `timeout`, never its message).
87
+ A 429 or 5xx also carries `retry_after`: its `Retry-After` delta-seconds up to `RETRY_MAX` 60, else (missing, an
88
+ HTTP date) `RETRY_DEFAULT` 10; nil for anything else, a connection error too (it may have been delivered). The
79
89
  transport is injectable: `spec/web/push/client_spec.rb` runs a fake push service (WEBrick, plain http through the
80
90
  injected transport) that decrypts each body with the device's key and checks the headers and the JWT.
81
91
 
@@ -84,18 +94,20 @@ injected transport) that decrypts each body with the device's key and checks the
84
94
  The service worker is the only reader of the payload (JSON, at most `Notifier::OPEN_LIMIT`, 3000 bytes, with
85
95
  `open`; one aes128gcm record leaves 3993 bytes of plaintext under Web Push's 4096: 86 header, 1 delimiter, 16 tag):
86
96
 
87
- - `{"v":1,"kind":"show","tag":KEY,"title":…,"body":…,"url":"/#/s/<id>","badge":N,"open":[KEY…]}`: TTL 12 h,
88
- `Urgency: high`. `open` only while the whole list fits the limit; the test push (`chi:test`) has neither `open`
89
- nor `badge`.
97
+ - `{"v":1,"kind":"show","tag":KEY,"title":…,"body":…,"url":"/#/s/<id>","badge":N,"open":[KEY…]}`: a waiting
98
+ reason's (approval, question, continue, card) TTL 12 h (`SHOW_TTL`), `Urgency: high`; a failed or done turn's
99
+ TTL 10 min (`EVENT_TTL`), `Urgency: normal`. `open` only while the whole list fits the limit; the test push
100
+ (`chi:test`) has neither `open` nor `badge`.
90
101
 
91
- `badge` and `open` are the keys still open in the Notifier's summaries (`Attention.open_keys`: a pending approval
92
- or question, a hook's too, not relayed), so an approval pushed by an earlier chi web run still counts after a
93
- restart. `public/sw.js` is a classic script (module service workers on iOS are unverified) at scope `/`. Every push
102
+ `badge` and `open` are the waiting keys still open in the Notifier's summaries (`Attention.open_keys`: a pending
103
+ question of any reason, a hook's and a continue's too, not relayed, and a card with actions; never a failed or done
104
+ turn), so an approval pushed by an earlier chi web run still counts after a restart. `public/sw.js` is a classic script (module service workers on iOS are unverified) at scope `/`. Every push
94
105
  event ends in `showNotification`: a payload that isn't a readable v1 show (no data, bad JSON, another `v`, a stale
95
106
  `close` from an older chi web, any other kind) shows a fallback (`chi` / "open chi", tag `chi:other`, url `/`), and a
96
107
  show iOS refuses is shown once more without its icon and data. A show calls `showNotification(title, {body, tag,
97
- icon, data: {url}})` first; then, when `open` is an array, closes every `getNotifications()` whose tag is a
98
- question's `"<sid>:<qid>"` (never `chi:*`), isn't the new one and isn't in `open` (after the show: closing before it
108
+ icon, data: {url}})` first; then, when `open` is an array, closes every `getNotifications()` whose tag is a waiting
109
+ key (`WAITING_TAG`: a question's `"<sid>:<qid>"` or a card's `"<sid>:card:<cid>"`, never `chi:*` nor a failed or
110
+ done turn's `"<sid>:<ended_at>"`, whose time has colons), isn't the new one and isn't in `open` (after the show: closing before it
99
111
  fails on iOS; errors are swallowed); then `setAppBadge(badge)` when `badge` is a number. A tap focuses the app's first window and navigates it to the url, else opens one (only a path of chi web's); `install`
100
112
  skips waiting, `activate` claims the clients. A Home Screen app can stay open for days, and the browser checks for
101
113
  a newer `sw.js` only on `register()` and on navigations: so when the page comes back in front (`backInFront` in
@@ -111,17 +123,30 @@ transparency with black).
111
123
 
112
124
  ## The Notifier (`web/push/notifier.rb`) and its rules (`web/push/attention.rb`)
113
125
 
114
- `Push::Attention` is the server's port of `web/public/notify.js` for what P1 pushes, so a push and the tab's
115
- notification ring for the same thing under the same key:
116
-
117
- - `Attention.for(prev, next)`: a new `pending_question` id that isn't `relayed_to` (absent when nil: the summary
118
- compacts it), whose **reason** (notify.js `questionReason`: `approval`, `continue`, anything else incl. `hook` is
119
- a question) is approval or question. Filtering on the reason, never on `kind == "question"`, keeps hook questions.
120
- A delegated child's (`parent_id`) approval or hook question holds `RELAY_HOLD` 3.5 s (notify.js `RELAY_HOLD_MS`):
121
- its parent may relay it. The key is `"<sid>:<qid>"`.
122
- - `Attention.closed_keys(prev, next)`: the question answered, replaced, newly relayed, or the session gone.
126
+ `Push::Attention` is the server's port of `web/public/notify.js`, so a push and the tab's notification ring for the
127
+ same thing under the same key. **One set of rules for both sides**: `spec/fixtures/attention_cases.json` holds the
128
+ cases (`attention`: `{name, prev, next, attention: {reason, key, hold_ms}|null, closed}` in the summary's JSON;
129
+ `open_keys`: `{name, by_id, open}`), and `spec/web/push/attention_cases_spec.rb` (the summary's key types: symbols at
130
+ the top and in `pending_question` / `pending_card`, strings in `last_turn`), `notify.test.js` (`attentionFor`,
131
+ `closedKeys`) and `push.test.js` (`openPushKeys`) run every row. A change to either side adds its row there.
132
+
133
+ - `Attention.for(prev, next)`, in notify.js's order:
134
+ 1. a new `pending_question` id: none if it is `relayed_to` already (absent when nil: the summary compacts it);
135
+ else its **reason** (notify.js `questionReason`: `approval`, `continue`, anything else incl. `hook` is a
136
+ question), key `"<sid>:<qid>"`. A delegated child's (`parent_id`) approval or hook question holds `RELAY_HOLD`
137
+ 3.5 s (notify.js `RELAY_HOLD_MS`): its parent may relay it.
138
+ 2. a new `pending_card` id: `card`, key `"<sid>:card:<cid>"`.
139
+ 3. a top-level turn whose `last_turn["ended_at"]` changed (a delegated child's is its parent's to report):
140
+ `failed`, or `done` when `completed` and `seconds` ≥ `DONE_MIN_SECONDS` 10 or its origin is in
141
+ `UNWATCHED_ORIGINS` (`delegate_report`, `context`, `task`); key `"<sid>:<ended_at>"`. A reminder turn follows
142
+ the same rules (no reminder event of its own).
143
+ - `WAITING` (approval, question, continue, card) are the reasons that stay open until answered: badged, in `open`,
144
+ cleaned up, and pushed only while still open. A failed or done turn has nothing to answer.
145
+ - `Attention.closed_keys(prev, next)`: the question answered, replaced, newly relayed; the card resolved or
146
+ replaced; both when the session is gone.
123
147
  - `Attention.text(summary, reason)`: notify.js `attentionText`'s words: the session's title, first preview or last
124
- prompt clipped to 61, and "needs approval" / "needs an answer". Never the question or the command.
148
+ prompt clipped to 61, and "needs approval" / "needs an answer" / "hit its step limit" / "needs you" / "turn
149
+ failed" / "done in N s" (`last_turn["seconds"]` rounded). Never the question or the command.
125
150
 
126
151
  `Notifier#call(event)` is a `SessionHub` sink. **The hub calls it under its Monitor**, from the tick thread and also
127
152
  from chi web's request threads (`SessionHub#touch`, from the stop/archive/delete routes), so it only enqueues: a push
@@ -134,10 +159,30 @@ open already never pushes. The hub's projection is empty before its first scan,
134
159
  once after the `chi` line's subscribe and before `notifier.start(hub)`, then `hub.start`. Events that reach the sink
135
160
  before the seed is in (they are newer than the snapshot) are applied after it.
136
161
 
137
- The sender thread holds each show (`HOLD` 3 s, or the event's own), then pushes it only while its key is still in
138
- `Attention.open_keys` of the summaries (read under the sink's mutex at flush time), to every subscription on this
139
- run's origin, with that list as `open` and its size as `badge`. A close only drops a show still in its hold: it
140
- pushes nothing. Results: `:ok` stamps the device's
162
+ The sender thread holds each show (`HOLD` 3 s, or the event's own); then a waiting one goes only while its key is
163
+ still in `Attention.open_keys` of the summaries (read under the sink's mutex at flush time), a failed or done one as
164
+ is. It goes to every subscription on this run's origin (a done turn only to those whose `prefs.done` is true), with
165
+ that list as `open` and its size as `badge`, unless:
166
+
167
+ - **a page is in front** (`Push::Presence#present?`, below): no send at all, `push_skipped reason: present` (no
168
+ device), and the key is handled (never pushed later: the tab's notification and badge have it);
169
+ - **the cap**: `CAP` 30 shows in a rolling `CAP_WINDOW` hour, counted per show event (one to N devices is one; the
170
+ test push isn't the Notifier's): over it, not sent, handled, and one `push_capped` warning per hour (on chi web's
171
+ terminal too).
172
+
173
+ A close only drops a show still in its hold: it pushes nothing. **Retry**: a result with `retry_after` (a 429 or
174
+ 5xx) puts that device's show in the sender's retry table (`Notifier::Retry`, per key and device, due like a hold:
175
+ the sender never sleeps, other shows go out meanwhile; `push_retry` logs it); it goes once more to that device, still
176
+ there, only while a waiting key is open (a failed or done one as is), with the open list of that moment, and isn't
177
+ counted against the cap again. A second failure is final: `push_failed` and `last_error`, as any failure. A key a
178
+ device took (first try or retry), or one skipped or capped, goes in `sent.json` (`Store#mark_sent`).
179
+
180
+ **Restart catch-up**: `Session#waiting_question` carries the question's `created_at` (`PendingQuestion#created_at`,
181
+ iso8601; the summary's `pending_question` has it, the page ignores it). `Notifier#seed` shows each seed summary's
182
+ open, not relayed question asked under `CATCH_UP` (an hour) ago whose key isn't in `sent.json` (`push_catch_up`):
183
+ asked while chi web was down or restarting, it gets the normal hold, presence and the cap. Everything else seeds as
184
+ before (cards carry no time). The first restart after P2a may push a seen, still-open question once (no `sent.json`
185
+ yet). Results: `:ok` stamps the device's
141
186
  `last_ok_at`; `:gone` removes it; `:failed` keeps its code in `last_error` and logs `push_failed`; `:bad_jwt` logs
142
187
  one `push_bad_jwt` warning (on chi web's terminal too) and stops all pushes until chi web restarts. Log lines carry
143
188
  `device:` (the short id), `code:`, `ms:`, `kind:`: never the endpoint, keys or text. `#stop` drops pending holds and
@@ -150,16 +195,37 @@ joins with a timeout; `Server.start`'s ensure calls it. Specs drive `#pump` with
150
195
  `Web::PushRoutes`; `@push` is the run's `Push::Runtime` (store, client, origin), nil when push is off (no https
151
196
  public URL, or `web.push.enabled: false`):
152
197
 
153
- - `GET /api/push[?endpoint=E]` → `{enabled, public_key, origin, this: {id, label}|null}`; off: `enabled: false` and
154
- no key.
198
+ - `GET /api/push[?endpoint=E]` → `{enabled, public_key, origin, this: {id, label}|null, devices, stale}`: `devices`
199
+ this origin's (`Sub#public_h` + `this: bool`), `stale` how many were made on another origin; off: `enabled:
200
+ false` and no key.
155
201
  - `POST /api/push/subscriptions {subscription: {endpoint, keys}, replaces?: id}` → 201 `{id, label}`; the label is
156
202
  chi's own ("iPhone · <date>", from the User-Agent's device class: iPhone, iPad, Mac, else Browser); `replaces`
157
203
  drops the device's earlier entry (`Store#add`).
158
204
  - `DELETE /api/push/subscriptions {endpoint}` → 204.
205
+ - `PATCH /api/push/subscriptions/ID {prefs: {done: true|false}}` → 200 the device's `Sub#public_h`; 404
206
+ `unknown_device` (not this origin's, or not a short id: the id is a `([^/]+)` capture checked in the handler, as
207
+ `participant_gate_spec`'s `path_for` fills only those), 400 `invalid_prefs`; logs `push_prefs`. ROUTES' first
208
+ PATCH row.
209
+ - `POST /api/push/presence {page, front}` → 204 (also with push off: a desk tab has nothing to be told), 400
210
+ `invalid_presence`.
159
211
  - `POST /api/push/test {endpoint?}` → a test push to that device or every one on this origin, answered per device
160
212
  (`{devices: [{id, label, status, code, ms}]}`); the bell sends one after subscribing.
161
213
 
162
- With push off the three writes answer 409 `push_off`.
214
+ With push off the subscription writes and the test answer 409 `push_off`.
215
+
216
+ ## Presence (`web/push/presence.rb`)
217
+
218
+ "Don't push while I'm looking" is decided here, as the iPhone's service worker can't see the app in front. Every
219
+ chi web page, a desk tab or the Home Screen app (`notifications.js`, whether or not it gets pushes itself), reports
220
+ `POST /api/push/presence {page, front}`: `page` a random id per page load, `front` = visible + `hasFocus()` +
221
+ touched (pointerdown, keydown, touchstart) in the last 2 min (`TOUCH_FRESH_MS`; the load counts as a touch). It
222
+ reports on visibilitychange, window focus and blur, the first touch that brings it to the front, every 30 s
223
+ (`PRESENCE_EVERY_MS`) while front and once more when 2 min pass untouched; a hide or `pagehide` sends `front: false`
224
+ as a beacon (`presenceSender`: `navigator.sendBeacon` with a JSON Blob, same origin so the cookie goes; else the
225
+ api's fetch; errors swallowed). `Push::Presence` keeps each page's last report in memory (a Mutex; at most
226
+ `MAX_PAGES` 64, the longest unheard dropped); `present?` is any `front: true` younger than `TTL` 45 s. It is part of
227
+ `Push::Runtime` (`presence`), so the route writes and the Notifier (built in `Server.start` from the Runtime) reads
228
+ the same one. A page left in front untouched quiets the phone at most ~2 min after the last touch.
163
229
 
164
230
  ## The page (`public/push.js`, `public/notifications.js`)
165
231
 
@@ -175,8 +241,8 @@ delete (revoked meanwhile): then the id stays for the next subscribe to replace.
175
241
  chi web not pushing, the bell is the in-tab one, unchanged (no duplicate desktop pushes).
176
242
 
177
243
  **The device's tidy-up** (`syncDevice`, the Home Screen app with the bell on): closes the shown notifications whose
178
- tag is a question's (`push.js isQuestionTag`, so `chi:test` stays) and isn't open in the page's `byId`
179
- (`push.js openPushKeys`: `Attention.open_keys`'s rule, with notify.js's `questionReason`), and sets or clears the app
244
+ tag is a waiting key (`push.js isWaitingTag`, so `chi:test` and a failed or done turn's stay) and isn't open in the
245
+ page's `byId` (`push.js openPushKeys`: `Attention.open_keys`'s rule), and sets or clears the app
180
246
  badge (`navigator.setAppBadge` / `clearAppBadge`); the bell turned off clears it. It runs once push is known, when
181
247
  the page comes back in front, and after each hub frame while visible (so answering on the Mac with the app open
182
248
  clears it at once), one at a time with one rerun. Never before the first snapshot (an empty `byId` would close
@@ -201,7 +267,7 @@ can land after the page's tidy-up and stay until the next one. Unverified on iOS
201
267
  handler before `showNotification` doesn't remove the older one. A separate close push that only closed
202
268
  `getNotifications({tag})` did, but it shows nothing (see the quota below), so the worker now closes after its show.
203
269
  - **The service worker can't see the app in front** (`clients.matchAll` gave 0 windows with the app open) and a
204
- banner shows anyway: "don't push while I'm looking" has to be decided server-side, from the pages' presence (P2).
270
+ banner shows anyway: "don't push while I'm looking" has to be decided server-side, from the pages' presence (see Presence above).
205
271
  - **Silent pushes**: the spike's 4 close pushes in a row didn't revoke the subscription, but that was luck or lazy
206
272
  enforcement: the user check's 6 did (WebKit's quota is 3 pushes that show nothing; see the top of this page).
207
273
  - iOS sent the cookie with the manifest, `sw.js` and icon fetches, but Chrome fetches manifests without credentials:
data/docs/sessions.md CHANGED
@@ -239,6 +239,8 @@ chi send --new --continues last:3fa2 -m "new day" # the next link of 3fa2's
239
239
 
240
240
  A session is named by its first message until you give it a title: `/title Coordinator` (in the REPL, an attached terminal, the web composer or `chi send -m "/title Coordinator" ID`; a parent agent may name its delegates the same way). The title is saved in the session file (`title`), whitespace collapsed and cut at 80 characters, and runs mid-turn too, at once. `/title` alone shows it (`title: none (shows the first message: hey chi …)` without one); `/title --clear` drops it, and the first message names the session again. A session whose first line was the command itself (`chi send --new -m "/title X"`) takes its preview from its first real message.
241
241
 
242
+ Without a title, the web names a session by its recap's first sentence once it has one (see [Session recap](cli.md#session-recap); its subject phrase stripped), else by its first message: on its card (which then leaves out its recap line, the same sentence), the families and chain rows, the top bar and the browser tab, the delete confirm and the search; `chi sessions list` already reads title, else recap, else the first message. The notifications keep the first message. A participant's page is unchanged (the title or the review's subjects).
243
+
242
244
  The title names the session wherever its first message did: `chi sessions list` (plain, `--live`, tsv and json's `desc`, before the recap; json has `title` too), `chi sessions delete`'s line, the `list_sessions` tool, `chi broadcast`, the desktop helper, a parent's children (the coordinator bundle's `/children` card, `ctx.sessions.children`; `ctx.sessions.read` too), and in the web the cards, the families and chain rows, the top bar and the browser tab, the notifications and the search; the terminal's status row too (the REPL's and an attached one's, first, see [Status Line](cli.md#status-line)). In the web, `✎` (Rename this session) sits next to the session's title, on its active strip card or after the top bar's title: a small input over the title, prefilled with it; Enter or a click elsewhere sends `/title TEXT` when it changed (empty: `/title --clear`), Esc closes it unsent, and so does the title leaving the screen (All sessions opened, the card swiped out of a phone's strip). A session a chi REPL owns has no `✎`, nor one that shows no title yet (`/title` still works from the composer). A continue's new link keeps the title (see [Session chains](#session-chains)). An older `chi web` (or any chi from before the field) that saves a session drops its title: restart `chi web` after upgrading.
243
245
 
244
246
  ## Session chains
@@ -255,7 +257,7 @@ A session can **continue** an earlier one: "the next run of the same routine" (a
255
257
  - **If the continue fails part-way:** a new link that fails to start gives its moved delegates back before it is deleted (each gets a note saying so; its worker is stopped first, if one started, and a worker that won't stop is reported, the link left), with any report one of them rang it with meanwhile; the previous link, back in the lists, is woken for reports waiting. A continue that dies in the middle leaves a `move.json` in the new link's folder: the new link's next worker finishes that move (only the delegates it names, and without a second note to one already told) as it starts. Until the new link's own worker holds it, a ring from a moved delegate doesn't start another (a `starting` marker in its folder, which that worker removes; a stale one, over 60 s old or from a process that is gone, is ignored). An open delegate below an archived delegate refuses the continue (`under archived …`): unarchive that one, or archive this one.
256
258
  - **Refused too:** a link that is continued already (naming the link that continues it; continue that one, or `last:<id>`), a previous link whose folder is gone, and one whose model's host can't run it when no default model is configured to fall back to. A refusal starts nothing and archives nothing; a new link that fails to start puts back what was archived. Every refusal that can be known up front (the archive's ones included) comes before the recap wait. One continue of a session runs at a time (a lock in its folder; other chains don't wait), so a double click finds the first one's link and is refused, while a `last:<id>` continue that waited follows the chain to its new end.
257
259
  - **Web:** `POST /api/sessions` takes `continues: "<id, prefix or last:id>"`, with `idle: true` (a new link waiting for its first message, previewed by the previous link's, or `preview`) or a `prompt`, and `model` (or `model_name`) for the new link's model, but not `dir`, `llm_context`, `thinking`, `settings`, `toolkit`, `tools`, `no_tools` or `parent_answers` (400 `invalid_continues`: the previous link's are taken). 201 is the new session's summary, `continues` set, with `moved`: the ids of the delegates that moved to it (`[]` for none), and `model_warning`: the default-model fallback's warning, then any about the model id, joined by `; ` (`null` for none), and `opener`: the previous link's first typed message, in full, when that link continues one itself (`null` otherwise: a chain's first link's first message is its task); 404 `not_found`; 400 `ambiguous_id` for a prefix of several sessions, `invalid_model` for a given model whose host config.yml doesn't have (or a fallback with no default model); 409 `continued` with `next_id` (the link that continues it already, which the page opens instead), `open_children` with `ids` (open delegates that can't move), `folder_gone`, `busy`, `scratch` or `owned_by_tui`. Every session summary carries `continues`.
258
- - **The page:** the info bar's `continue →` continues the open session (`continues: <id>, idle: true`; it reads `continuing…` through the recap wait) and opens the new link with an opener in the composer, not sent (a draft written in this session stays instead; one carried over from another session or the start page gives way to the opener, and the toast's **Restore draft** brings it back): the previous link's own first typed message when that link continues one (the 201's `opener`; a `!shell` line isn't taken), else `Continue where we left off.`. So whatever you sent on the last link comes back on the next one, and editing it once changes it for every later link; the previous link is archived, a toast says so (`Continued 3fa2c1d0 in 4b7e9a01; 3fa2c1d0 is archived; 1 open delegate moved`), and a moved delegate's card folds under the new link. When the previous link's model's host is gone the link starts on the default model and the toast carries the server's `model_warning` too, and then stays until closed. A fresh link (one with no turn yet, however it was made: `continue →`, `chi send --new --continues`, a reload) shows the model picker in its composer with the link's model, until its first turn starts (a failed or canceled first turn ends it too); a pick runs `/model <name>` in the link (a command bubble; the info bar follows) and changes neither the start page's remembered model nor its Recent list, and a Send right after it waits for the `/model` to be taken. A link a chi REPL owns, or one continued already, shows none. A link continued already has no `continue →`: its `→` link goes to the next link (a stale page's continue answered 409 `continued` opens `next_id`). A continue refused for open delegates that can't move shows a toast that names each one (its preview and what the server says to do: `older chi worker 0.46.1; restart it`, `open in a chi REPL; close it there`), each a link to its page; any other refusal shows the server's words. The info bar of a link carries `← 2026-10-08` (the previous link's day) and, on an earlier link, `2026-10-10 →`, each a link with its id, its full start (`2026-10-10 14:32`) and its preview in the tooltip; a neighbour that started on the open link's own day shows its time instead (`← 09:12`, `14:32 →`). A link made by `continue →` inherits the previous link's preview (and its title, if it has one) when it is created, so its card keeps its chain's title whatever opener it is sent, and its top bar and browser tab show its card's title. A link whose title is the opener and nothing else (a `chi send --new --continues` link whose first message is `Continue where we left off.`) shows its chain's first link's title instead, on its card, in the popover and in its info bar's title line, display only (its messages and data keep the opener; its own title when the first link is gone). The lists fold a chain into the card of its latest listed link, whatever the earlier links' archived state (typing in an archived link brings it back, folded there still), their delegates with them: the card's `↩ #N` chip (`#N of M` when later links aren't listed; its tooltip `Session chain: link N of M`) opens a popover of the other links, newest first (`#N`, its date, with its time (`2026-10-17 14:32`) when another link of the chain started the same day, its own title when it differs from the card's (a link inherits its chain's, so mostly it doesn't), else its recap's first sentence, else its preview, `archived`), a click opens one; the chip shows a live dot or `waiting` for a link that has a worker or waits on the user, and a waiting link puts its chain's card first. All sessions folds nothing while a search is typed or "include archived" is on: every link is a card of its own then, its chip `#N of M`, with its own delegates folded in, so a search finds an earlier link and its delegates.
260
+ - **The page:** the info bar's `continue →` continues the open session (`continues: <id>, idle: true`; it reads `continuing…` through the recap wait) and opens the new link with an opener in the composer, not sent (a draft written in this session stays instead; one carried over from another session or the start page gives way to the opener, and the toast's **Restore draft** brings it back): the previous link's own first typed message when that link continues one (the 201's `opener`; a `!shell` line isn't taken), else `Continue where we left off.`. So whatever you sent on the last link comes back on the next one, and editing it once changes it for every later link; the previous link is archived, a toast says so (`Continued 3fa2c1d0 in 4b7e9a01; 3fa2c1d0 is archived; 1 open delegate moved`), and a moved delegate's card folds under the new link. When the previous link's model's host is gone the link starts on the default model and the toast carries the server's `model_warning` too, and then stays until closed. A fresh link (one with no turn yet, however it was made: `continue →`, `chi send --new --continues`, a reload) shows the model picker in its composer with the link's model, until its first turn starts (a failed or canceled first turn ends it too); a pick runs `/model <name>` in the link (a command bubble; the info bar follows) and changes neither the start page's remembered model nor its Recent list, and a Send right after it waits for the `/model` to be taken. A link a chi REPL owns, or one continued already, shows none. A link continued already has no `continue →`: its `→` link goes to the next link (a stale page's continue answered 409 `continued` opens `next_id`). A continue refused for open delegates that can't move shows a toast that names each one (its preview and what the server says to do: `older chi worker 0.46.1; restart it`, `open in a chi REPL; close it there`), each a link to its page; any other refusal shows the server's words. The info bar of a link carries `← 2026-10-08` (the previous link's day) and, on an earlier link, `2026-10-10 →`, each a link with its id, its full start (`2026-10-10 14:32`) and its preview in the tooltip; a neighbour that started on the open link's own day shows its time instead (`← 09:12`, `14:32 →`). A link made by `continue →` inherits the previous link's preview (and its title, if it has one) when it is created, so its card keeps its chain's title whatever opener it is sent, and its top bar and browser tab show its card's title. A link with a recap of its own reads its recap's first sentence instead (a link without one reads its chain's name, and a first link's recap names its chain). A link whose title is the opener and nothing else (a `chi send --new --continues` link whose first message is `Continue where we left off.`) shows its chain's first link's title instead, on its card, in the popover and in its info bar's title line, display only (its messages and data keep the opener; its own title when the first link is gone). The lists fold a chain into the card of its latest listed link, whatever the earlier links' archived state (typing in an archived link brings it back, folded there still), their delegates with them: the card's `↩ #N` chip (`#N of M` when later links aren't listed; its tooltip `Session chain: link N of M`) opens a popover of the other links, newest first (`#N`, its date, with its time (`2026-10-17 14:32`) when another link of the chain started the same day, its own title when it differs from the card's (a link inherits its chain's, so mostly it doesn't), else its recap's first sentence, else its preview, `archived`), a click opens one; the chip shows a live dot or `waiting` for a link that has a worker or waits on the user, and a waiting link puts its chain's card first. All sessions folds nothing while a search is typed or "include archived" is on: every link is a card of its own then, its chip `#N of M`, with its own delegates folded in, so a search finds an earlier link and its delegates.
259
261
  - **CLI:** `chi send --new --continues (ID|PREFIX|last:ID) [--model M] [-m TEXT]` (see *Starting a session*).
260
262
  - **Which link:** an id, a unique prefix, or `last:<id or prefix>`, the latest link of the chain that session is in. It walks the links that still exist: a deleted link in the middle (`chi sessions delete`, the retention sweep of an unarchived one) ends the walk before it, so `last:` of an earlier link then names that earlier link, and continuing it starts a second line beside the links after the gap; name a link after the gap instead. A trigger names the chain this way: `chi send` to an archived link would bring it back (a human's input), not continue the chain.
261
263
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: samagotchi-system
3
- version: 0.111.1
3
+ version: 0.112.0
4
4
  scope: system
5
5
  description: Default system memories — identity, self map, config modification protocol, memory guide and the delegated-session rules
6
6
  files:
@@ -378,7 +378,8 @@ module Samagotchi
378
378
 
379
379
  # The question this session waits on, as the lists show it: {id:, kind:}
380
380
  # with kind "question" (the model's), "approval", "hook" or "continue"
381
- # (the step-limit question, asked between turns); nil with
381
+ # (the step-limit question, asked between turns), +relayed_to+ and
382
+ # +created_at+ (iso8601: chi web's push catch-up) when set; nil with
382
383
  # none. Only while a worker runs it (+live+): a question saved by a
383
384
  # worker that died waits for no one (the next worker drops it). The
384
385
  # web's summaries and `chi sessions list` both ask this.
@@ -391,7 +392,8 @@ module Samagotchi
391
392
  kind = pending.kind.to_s
392
393
  relayed = pending.relayed_to
393
394
  relayed_to = relayed.is_a?(Hash) ? (relayed[:parent_short] || relayed["parent_short"]) : nil
394
- { id: pending.id, kind: %w[approval hook continue].include?(kind) ? kind : "question", relayed_to: relayed_to }.compact
395
+ { id: pending.id, kind: %w[approval hook continue].include?(kind) ? kind : "question", relayed_to: relayed_to,
396
+ created_at: pending.created_at }.compact
395
397
  end
396
398
 
397
399
  # A question saved by a process that no longer runs this session (the
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Samagotchi
4
- VERSION = "0.111.1"
4
+ VERSION = "0.112.0"
5
5
  # Sent as the User-Agent of every HTTP request chi makes.
6
6
  USER_AGENT = "chi/#{VERSION}"
7
7
  end
@@ -271,7 +271,10 @@ module Samagotchi
271
271
  ["GET", %r{\A/api/push\z}, :handle_push_info, :owner],
272
272
  ["POST", %r{\A/api/push/subscriptions\z}, :handle_push_subscribe, :owner],
273
273
  ["DELETE", %r{\A/api/push/subscriptions\z}, :handle_push_unsubscribe, :owner],
274
+ # The id checked in the handler (participant_gate_spec fills ([^/]+) captures only).
275
+ ["PATCH", %r{\A/api/push/subscriptions/([^/]+)\z}, :handle_push_prefs, :owner],
274
276
  ["POST", %r{\A/api/push/test\z}, :handle_push_test, :owner],
277
+ ["POST", %r{\A/api/push/presence\z}, :handle_push_presence, :owner],
275
278
  ["GET", %r{\A/api/sessions/([^/]+)\z}, :handle_show, :participant, :session],
276
279
  ["DELETE", %r{\A/api/sessions/([^/]+)\z}, :handle_delete, :owner, :session]
277
280
  ].freeze
@@ -60,11 +60,12 @@ export function isOpener(text) {
60
60
  // reads its chain's first link's title instead, so the links of a chain
61
61
  // keep its name. Its own title when the first link isn't in +byId+ (id →
62
62
  // session; deleted, or a walk a missing link cut short) or is the opener too.
63
- // A link with a title of its own (/title; a new link inherits it) reads it,
64
- // and a titled first link names its chain.
63
+ // A link with a title of its own (/title; a new link inherits it), an auto
64
+ // title or a recap of its own reads it, and a first link with any of them
65
+ // names its chain.
65
66
  export function chainTitle(s, byId) {
66
67
  const own = previewForCard(s);
67
- if (s?.title || !s?.continues || !isOpener(s.first_preview || s.last_prompt)) return own;
68
+ if (s?.title || s?.auto_title || s?.recap || !s?.continues || !isOpener(s.first_preview || s.last_prompt)) return own;
68
69
  const seen = new Set([s.id]);
69
70
  let at = s;
70
71
  while (at.continues) {
@@ -73,7 +74,8 @@ export function chainTitle(s, byId) {
73
74
  seen.add(prev.id);
74
75
  at = prev;
75
76
  }
76
- return !at.title && isOpener(at.first_preview || at.last_prompt) ? own : previewForCard(at);
77
+ const named = at.title || at.auto_title || at.recap;
78
+ return !named && isOpener(at.first_preview || at.last_prompt) ? own : previewForCard(at);
77
79
  }
78
80
 
79
81
  // The open session's title (app.js updateSessionTitle: the top bar and the
@@ -81,10 +83,11 @@ export function chainTitle(s, byId) {
81
83
  // (+shown+, its summary, has continues) reads +cardTitle+(shown) whatever
82
84
  // its first message: a web link inherits its chain's title, and its first
83
85
  // message is an opener (the constant or the user's own). Else +first+,
84
- // unless it is the opener. A titled session (/title) reads its card's too.
86
+ // unless it is the opener. A titled session (/title), or one with an auto
87
+ // title or a recap (its card's name then), reads its card's too.
85
88
  // +shown+ null: not listed yet, +first+.
86
89
  export function openTitle({ shown, first, cardTitle }) {
87
- if (shown && (shown.title || shown.continues || isOpener(first))) return cardTitle(shown);
90
+ if (shown && (shown.title || shown.auto_title || shown.recap || shown.continues || isOpener(first))) return cardTitle(shown);
88
91
  return first;
89
92
  }
90
93
 
@@ -57,11 +57,26 @@ export function firstPreview(text) {
57
57
  return clip(n, FIRST_PREVIEW_CHARS + 1);
58
58
  }
59
59
 
60
+ // What names a session's card, first found: its title (/title), its auto
61
+ // title (from the recap call), its recap's first sentence (+recap+), its
62
+ // first message, its last prompt. Display only.
63
+ function cardName(session) {
64
+ return session.title || session.auto_title || session.recap || session.first_preview || session.last_prompt || "";
65
+ }
66
+
60
67
  export function previewForCard(session) {
61
- // Unified card preview: its title (/title), else its first message (80),
62
- // else its last prompt.
63
- const raw = session.title || session.first_preview || session.last_prompt || "";
64
- return firstPreview(raw) || "\u2014";
68
+ // Unified card preview: cardName, cut at 80.
69
+ return firstPreview(cardName(session)) || "\u2014";
70
+ }
71
+
72
+ // Where previewForCard's words came from: "title", "auto" (auto_title),
73
+ // "recap" (the card then drops its recap line: the same sentence twice),
74
+ // "preview" (the first message or last prompt, or none).
75
+ export function cardTitleSource(session) {
76
+ if (session.title) return "title";
77
+ if (session.auto_title) return "auto";
78
+ if (session.recap) return "recap";
79
+ return "preview";
65
80
  }
66
81
 
67
82
  const DELETE_PREVIEW_CHARS = 40;
@@ -70,7 +85,7 @@ const DELETE_PREVIEW_CHARS = 40;
70
85
  // list's owner can be stale (a worker idle-exits), so a worker is only
71
86
  // "stopped if it's still running", never promised.
72
87
  export function deleteConfirmText(session) {
73
- const n = normalize(session.title || session.first_preview || session.last_prompt || "");
88
+ const n = normalize(cardName(session));
74
89
  const preview = clip(n, DELETE_PREVIEW_CHARS + 1);
75
90
  const shortId = session.short_id || String(session.id).slice(0, 8);
76
91
  const lines = [