samagotchi 0.106.0 → 0.107.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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +121 -1
  3. data/bin/chi +2 -0
  4. data/docs/architecture.md +4 -0
  5. data/docs/cli.md +45 -5
  6. data/docs/guardrails.md +8 -2
  7. data/docs/internals/participants.md +126 -30
  8. data/docs/internals/remote-sessions.md +12 -5
  9. data/docs/plugins.md +29 -1
  10. data/docs/releasing.md +2 -0
  11. data/docs/sessions.md +36 -1
  12. data/docs/sub-agent.md +2 -0
  13. data/docs/testing.md +2 -0
  14. data/lib/samagotchi/bridge/turn_accumulator.rb +6 -0
  15. data/lib/samagotchi/bridge.rb +4 -0
  16. data/lib/samagotchi/bridge_client/stream_request.rb +10 -3
  17. data/lib/samagotchi/bundles/coordinator/manifest.yml +6 -5
  18. data/lib/samagotchi/bundles/coordinator/plugin.rb +85 -5
  19. data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +18 -0
  20. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  21. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  22. data/lib/samagotchi/continue_offer.rb +51 -4
  23. data/lib/samagotchi/guardrails/review_boundary.rb +6 -57
  24. data/lib/samagotchi/guardrails/review_paths.rb +93 -0
  25. data/lib/samagotchi/model_profile.rb +5 -3
  26. data/lib/samagotchi/parent_report.rb +23 -1
  27. data/lib/samagotchi/participant_messages.rb +11 -0
  28. data/lib/samagotchi/participants.rb +20 -6
  29. data/lib/samagotchi/plugin/api.rb +2 -1
  30. data/lib/samagotchi/plugin/sessions.rb +25 -0
  31. data/lib/samagotchi/remote_command.rb +1 -1
  32. data/lib/samagotchi/remotes.rb +23 -8
  33. data/lib/samagotchi/review_apply.rb +123 -0
  34. data/lib/samagotchi/review_command.rb +121 -0
  35. data/lib/samagotchi/review_start.rb +161 -0
  36. data/lib/samagotchi/run_options.rb +17 -2
  37. data/lib/samagotchi/send_command/wait_target.rb +5 -0
  38. data/lib/samagotchi/send_command.rb +2 -0
  39. data/lib/samagotchi/session.rb +33 -5
  40. data/lib/samagotchi/session_access/contract.rb +10 -2
  41. data/lib/samagotchi/session_access/dispatch.rb +8 -2
  42. data/lib/samagotchi/session_access/http_transport.rb +10 -1
  43. data/lib/samagotchi/session_access/local.rb +19 -2
  44. data/lib/samagotchi/session_access/remote.rb +15 -1
  45. data/lib/samagotchi/session_access/web_bridge_client.rb +1 -1
  46. data/lib/samagotchi/session_access.rb +23 -10
  47. data/lib/samagotchi/session_chain.rb +10 -2
  48. data/lib/samagotchi/session_continue.rb +4 -3
  49. data/lib/samagotchi/session_manager.rb +30 -8
  50. data/lib/samagotchi/session_review.rb +28 -0
  51. data/lib/samagotchi/share_command.rb +7 -1
  52. data/lib/samagotchi/terminal_ui/attached_loop.rb +4 -1
  53. data/lib/samagotchi/testing/sessions.rb +10 -2
  54. data/lib/samagotchi/turn_checkpoint.rb +13 -0
  55. data/lib/samagotchi/version.rb +1 -1
  56. data/lib/samagotchi/web/app.rb +106 -21
  57. data/lib/samagotchi/web/grants.rb +90 -16
  58. data/lib/samagotchi/web/participant_access.rb +82 -26
  59. data/lib/samagotchi/web/participant_review.rb +45 -2
  60. data/lib/samagotchi/web/participant_stream_filter.rb +118 -17
  61. data/lib/samagotchi/web/participant_view.rb +12 -1
  62. data/lib/samagotchi/web/public/app.js +60 -5
  63. data/lib/samagotchi/web/public/chip_popover.js +10 -3
  64. data/lib/samagotchi/web/public/data.js +10 -2
  65. data/lib/samagotchi/web/public/delivery_line.js +79 -15
  66. data/lib/samagotchi/web/public/index.html +26 -0
  67. data/lib/samagotchi/web/public/info_bar.js +7 -3
  68. data/lib/samagotchi/web/public/info_bar_model.js +7 -1
  69. data/lib/samagotchi/web/public/live_turn.js +3 -0
  70. data/lib/samagotchi/web/public/participant.html +58 -5
  71. data/lib/samagotchi/web/public/participant.js +171 -24
  72. data/lib/samagotchi/web/public/participant_model.js +84 -24
  73. data/lib/samagotchi/web/public/participant_names.js +36 -4
  74. data/lib/samagotchi/web/public/participants_panel.js +84 -16
  75. data/lib/samagotchi/web/public/question_cards.js +1 -0
  76. data/lib/samagotchi/web/public/review_apply.js +34 -0
  77. data/lib/samagotchi/web/public/review_start.js +101 -0
  78. data/lib/samagotchi/web/public/send_turn.js +25 -1
  79. data/lib/samagotchi/web/public/session_actions.js +44 -3
  80. data/lib/samagotchi/web/public/session_state.js +3 -0
  81. data/lib/samagotchi/web/public/start_page.js +38 -2
  82. data/lib/samagotchi/web/public/stream_handlers.js +10 -0
  83. data/lib/samagotchi/web/public/turn_html.js +2 -1
  84. data/lib/samagotchi/web/public/turn_view.js +5 -0
  85. data/lib/samagotchi/web/session_summary.rb +3 -0
  86. data/lib/samagotchi/worker.rb +16 -4
  87. metadata +8 -1
@@ -7,8 +7,11 @@ limited and capped; and what they **see** (P4a): their page and its reads, all t
7
7
  experimental. An agent participant waits on its own turns' replies through the API. The code and docs say
8
8
  "participants" and "review", never "shared": `session.shared` already means "attached by default".
9
9
 
10
- Until `web.public_url` lands, participants are a **LAN** feature (`web.host: lan`): a loopback peer is always the
11
- owner, and a reverse proxy on the same machine would make every visitor loopback.
10
+ Participants are a **LAN** feature for now (`web.host: lan`; a public URL, `web.public_url`, is planned, not a
11
+ config key yet): a loopback peer with no token is
12
+ the owner, and a reverse proxy on the same machine would make every visitor loopback. A participant's token is the
13
+ participant's wherever it comes from: their link opened on this machine (or on a chi web not on the LAN, whose link
14
+ works on this machine only) is the participant, never the owner.
12
15
 
13
16
  ## Grants
14
17
 
@@ -38,22 +41,33 @@ participant** and **one role**, until it expires or is revoked.
38
41
  be read by another user, or isn't this user's (`Grants.check_permissions!`, one message naming the `chmod`). Only
39
42
  those two are checked: the state dir above is often 0755, and that's fine. Never point `XDG_STATE_HOME` at a
40
43
  shared folder.
44
+ - **A store that doesn't read** (not JSON, a grant without its id, digest or expiry) fails closed: its tokens find no
45
+ grant (a bare 401), it is logged (`grants_unreadable`, once per change of the file), and nothing writes over it, so
46
+ an invite can't keep only its own grant and lose every other digest. The owner's invite, cap, revoke and list are
47
+ refused with one message naming the file (`Grants::Corrupt`: `chi share` exits 1, chi web answers 500 with it);
48
+ an archive or delete still goes ahead. Fix the file, or move it aside to end every link.
41
49
  - Rotating the owner token (`chi web --new-token`) never touches grants; `chi share revoke --all` ends them all.
42
50
 
43
51
  ## The gate
44
52
 
45
53
  `App#principal_for` resolves every request to a `Web::Principal`:
46
54
 
47
- 1. A loopback peer, or a chi web not on the LAN: the **owner** (unchanged).
48
- 2. The owner's token (Bearer, then the cookie; `?token=` on the page's trade): the **owner**. Checked first, so the
55
+ 1. The owner's token (Bearer, then the cookie; `?token=` on the page's trade): the **owner**. Checked first, so the
49
56
  owner's requests never touch the grants store (measured: no change to an owner route's time).
50
- 3. A `chp_` token whose grant is active: a **participant** (`Principal.new(kind: :participant, grant:)`).
57
+ 2. A `chp_` token (`Grants.token?`) whose grant is active: a **participant** (`Principal.new(kind: :participant,
58
+ grant:)`), from any peer: loopback and a chi web not on the LAN too. An ended or unknown one is refused
59
+ (below), never the owner.
60
+ 3. No `chp_` token from a loopback peer, or on a chi web not on the LAN: the **owner** (unchanged).
51
61
  4. Anything else: nil. `#token_gate` answers an ended grant's token **401 `token_revoked`** or **401
52
- `token_expired`** (the page: "This review link has expired or was revoked. Ask the session's owner for a new
53
- one."), any other **401 `unauthorized`** as before.
62
+ `token_expired`** (the page says the same words as a sentence: "This review link was revoked by the session's
63
+ owner." / "This review link expired: ask the session's owner for a new one."), any other **401
64
+ `unauthorized`** as before.
54
65
 
55
66
  The `?token=` trade sets the `chi_token` cookie to the token that was presented, the owner's or the participant's
56
- (one at a time per browser: a participant link opened in the owner's browser replaces the owner's cookie there).
67
+ (one at a time per browser: a participant link opened in the owner's browser replaces the owner's cookie there, and
68
+ makes that browser the participant, on loopback too). A grant's token is traded on any peer; the owner's only where
69
+ the gate asks for it. On a peer the gate doesn't ask, the 401 for a grant's cookie that no longer works clears the
70
+ cookie, so that browser is the owner's again at its next request.
57
71
 
58
72
  Then `#route`, for each matching `ROUTES` row:
59
73
 
@@ -72,9 +86,9 @@ row answers another session's id 404, so a new route is covered without a new ex
72
86
  | `POST /api/sessions/:id/turn` | participant | a queued review turn of their own ([Turns](#turns)) |
73
87
  | `POST /api/sessions/:id/turn/:eid/dequeue` | participant | their own queued turn back; another's (the owner's included) is 403 `not_permitted` |
74
88
  | `GET /api/sessions/resolve?id=` | participant | their session for its id or a prefix of it; anything else 404 as no session (never an ambiguity listing others) |
75
- | `POST /api/sessions/:id/wait/prepare`, `…/wait` | participant | only for a turn of theirs (`turn`: the enqueued id `POST …/turn` answered; else 403); the answer trimmed to `{status, text, turn_id, cancel_reason}`; a question or approval their turn raised, or their turn held by the owner's step-limit Continue offer ([Turns](#turns)), is `{status: "waiting_for_owner", detail: "waiting for the session's owner"}` with nothing of it |
89
+ | `POST /api/sessions/:id/wait/prepare`, `…/wait` | participant | only for a turn of theirs (`turn`: the enqueued id `POST …/turn` answered; else 403); `wait/prepare` answers only what that wait needs, `{session_id, baseline: {last_turn}, known_turn, live, last_turn_id}` (`last_turn_id` only when it is their turn), never the owner's cursor, message count, question or running turn; the answer trimmed to `{status, text, turn_id, cancel_reason}`, the reply's `text` through `ParticipantView.reply` (no thinking or tool call, redacted) and any other text (an error's exception, a failed turn's summary) `ParticipantMessages::TURN_FAILED`; a question or approval their turn raised, or their turn held by the owner's step-limit Continue offer ([Turns](#turns)), is `{status: "waiting_for_owner", detail: "waiting for the session's owner"}` with nothing of it; a revoke or the expiry ends a `wait` already running (401 `token_revoked` / `token_expired`), as it ends their stream |
76
90
  | `GET /` | participant | the participant page's shell (`participant.html`, its body's `data-session` and `data-name` the grant's; `participant.js` reads the rest through the two routes below). Never the owner's page, where every route would refuse them. |
77
- | `GET /api/sessions/:id/review` | participant | the page's data, filtered ([What a participant sees](#what-a-participant-sees)): `{viewer, session: {id, title, status}, participants, messages, current_turn, waiting_for_owner, queued: {mine, others}, last_event_id}` |
91
+ | `GET /api/sessions/:id/review` | participant | the page's data, filtered ([What a participant sees](#what-a-participant-sees)): `{viewer, session: {id, title, status}, subjects, participants, messages, current_turn, waiting_for_owner, queued: {mine, others}, last_event_id}` |
78
92
  | `GET /api/sessions/:id/stream` | participant | the session's stream through `ParticipantStreamFilter` (only `from_seq` and `snapshot` reach the Bridge); it ends within a poll of a revoke or the expiry |
79
93
  | `GET /api/info` | participant | `{app, version, features}` (what `SessionAccess::Remote`'s check needs); not `pid`, `cwd`, `lan`, `installed` |
80
94
  | `GET /api/sessions/:id` | participant | their session only, whatever the query (`brief`, `cards`, `tail`, `timing`): `{session: {id, title, status, participants: [{id, name, kind, role}]}}` (the active ones). `title` is the session's own title, or "an untitled session": never `display_title`'s fallback, the first prompt's opening words |
@@ -98,7 +112,9 @@ input, origin `review`, source `participant`, labelled `review`); the body's `cl
98
112
 
99
113
  It goes out as `delivery: queue` (D6) with `pending_limit` = the grant's queue limit + 1 (the running one), never
100
114
  into the owner's prompt history. The Bridge counts the author's running and queued turns under its event lock and
101
- answers 429 `too_many_turns` past it; with no worker, their waiting input files are counted. The ack is 202 with
115
+ answers 429 `too_many_turns` past it; with no worker, their waiting input files are counted, and the new one
116
+ written, under the session dir's `participants.lock` (`SessionManager.deliver_turn`), so two at once can't both
117
+ pass. The ack is 202 with
102
118
  `delivery: "queue"`; chi web keeps enqueued id → grant (the last 1000), which `dequeue` and `wait` check, falling
103
119
  back to a waiting file's author after a restart.
104
120
 
@@ -110,9 +126,19 @@ feature (409 `review_unavailable` otherwise: it has no boundary; restart it), an
110
126
  that may be older holds the session (504 `worker_timeout`: send again). Before a queued participant turn starts, the
111
127
  worker checks their link (`participants.json`: revoked, expired) and their cap again: either way the turn is
112
128
  dequeued (`:turn_dequeued`) and audited (`revoked`, `cap_reached`) instead of run, so a revoke also stops what they
113
- had queued. A step-limit Continue of a participant's turn (the owner answers it) continues as theirs: its origin keeps
114
- their author (`ContinueOffer#run_continue_turn`), so it runs inside the boundary and on their spend; it isn't
115
- continued once their link ended or their cap is reached. The step-limit Continue offer of the owner's turn is the
129
+ had queued; its settled record (`TurnCheckpoint.record_refused`: canceled, `cancel_reason` the reason) ends their
130
+ wait on it at once, which `ParentReport` reads as status `refused`, exit 1.
131
+ **The owner's input during a review turn queues.** While a participant's turn runs, the owner's input never merges
132
+ into it, from any client (the web, an attached TUI, `chi send` without `--queue`): the Bridge's `POST /turn` makes it
133
+ `delivery: queue` whatever it asked, so it never steers or cuts (`TurnAccumulator#participant_turn?`, under the event
134
+ lock), and its ack and `:turn_enqueued` say `queue`; the worker's drain takes no input file during a participant's
135
+ turn (`Worker#pending_input_drain`, for a file the Bridge never saw), so each runs as the owner's own turn after it.
136
+ The web's delivery line says so (`participantTurn`: Enter queues, no cut), the TUI prints its queued note, `chi send`
137
+ says `(queued: runs after the current turn)` and its `--wait` waits for that turn (`WaitTarget.message`). The owner's
138
+ own turns steer as before. A step-limit Continue of a participant's turn (the owner answers it) continues as theirs: its origin keeps
139
+ their author (`ContinueOffer#run_continue_turn`), so it runs inside the boundary and on their spend; once their link ended or their cap is reached, the owner's Continue
140
+ ends the offer as a Stop instead (`ContinueOffer#refuse_continue`: decision `refused`, a notice, `not_continued`), so
141
+ nothing waits on it. The step-limit Continue offer of the owner's turn is the
116
142
  owner's to answer: while one stands, the worker **holds** a participant's input file (`Worker#run_input_files`,
117
143
  `SessionInbox.participant_input?`; an unreadable file counts) instead of running it, which would drop the offer. It
118
144
  stays in the inbox: still queued on the Bridge (counted against their queue limit, `turn/dequeue` takes it back),
@@ -174,7 +200,10 @@ fields: a field added to an event later reaches nobody until it is named there.
174
200
  `generation_retrying` (`restarted`), `tool_call_started` (the tool's name, and for a file tool the path relative to
175
201
  the session's folder when it is inside it; never when that folder is home or `/`), `tool_call_completed` (its status word), and bare markers (the type
176
202
  alone) for the queue (`turn_enqueued`, `turn_dequeued`, `input_merged`), the owner's question, approval or Continue
177
- offer and their answers, and `snapshot` / `reset`: the page re-reads its review data at each. Every other type,
203
+ offer and their answers, and `snapshot` / `reset`: the page re-reads its review data at each (the latest read
204
+ wins), draws no live event from a turn's start or end until that re-read, and then streams again from the data's
205
+ `last_event_id`, so the events after its snapshot replay onto it; a read that fails (unreachable, a 5xx) keeps the
206
+ page and is retried with a backoff under a "retrying" line. Refusals show the server's `detail`. Every other type,
178
207
  known (`DROPPED`) or new, is dropped. `spec/web/participant_view_spec.rb` scans every `type: :name` chi emits and
179
208
  every handler of the web's stream, and fails until a new one is named in `EVENTS` or `DROPPED`.
180
209
  - **The frames** (`Web::ParticipantStreamFilter`). The Bridge's chunks are cut into frames (`\r?\n\r?\n`, a partial
@@ -182,8 +211,11 @@ fields: a field added to an event later reaches nobody until it is named there.
182
211
  written again (`id:` the Bridge's cursor when it looks like one, `event:` the filtered type); a comment is a
183
212
  `: ping`; anything that doesn't parse is dropped. The reply's text goes out by whole lines, so a secret the model
184
213
  streams over two chunks is redacted as one, and a private key block is withheld from its BEGIN line to its END
185
- line; the rest of a line waits for its end, a tool call, the turn's end or the owner's question (or 400
186
- characters). The owner's stream never goes through it (a byte pipe).
214
+ line (or, left open, to the turn's end); the rest of a line waits for its end, a tool call, the turn's end or the owner's question (or 400
215
+ characters: then it is cut at its last space that splits no secret, never inside what `Redact` would redact
216
+ and never after a key word whose value is still to come, `Redact::OPEN_VALUE`; past 1600 with no such space,
217
+ the line's last unbroken run and the rest of that line go out as one `[redacted]`). The owner's stream never
218
+ goes through it (a byte pipe).
187
219
  - **The conversation** (`.messages`, over `App#messages_for_display(parts: true)`): a user message only when it is a
188
220
  turn's prompt (it has the turn's id) or a person's merged line, and never one from a source that isn't a person's;
189
221
  so the owner's `!` line and its output, a delegate's report (a wake turn's too), and the notes chi adds (a declined
@@ -197,19 +229,39 @@ fields: a field added to an event later reaches nobody until it is named there.
197
229
  `html` is rendered from the filtered text. The turn in progress (`.current_turn`, over the Bridge snapshot's) gives
198
230
  its start's fields, the text so far, its tool rows (with `running`) and `waiting_for_owner`.
199
231
  - **The queue.** Their own queued turns (enqueued id and text, for Take back) and how many others wait.
232
+ - **A fork's note.** A review fork (`chi review --from`, `/coordinate review`) starts with a note holding the source's
233
+ recap and, from the coordinator, its handoff's body: a participant's review turn reads it like the rest of the
234
+ history and may quote it (host paths, worktree names). That is by design (it is what the review is about); the
235
+ owner chose to share it. Nothing else of the source comes along.
236
+ - **The subjects** (`subjects`, a review session's: [docs/sessions.md](../sessions.md#review-sessions)): each
237
+ `{path, text, truncated, html}` (`html` for markdown only, rendered from the redacted text), or `{path, missing:
238
+ true}`. Every read checks the path again with `Guardrails::ReviewPaths` (a review turn's own check: under the
239
+ project root, as given and as it resolves, never a secret file or chi's own), so a subject that became a symlink
240
+ out of the project, or a session file edited to name `.env` or `../x`, is `missing`, never read. The text is cut
241
+ at 256 KiB (`SUBJECT_BYTES`) and redacted. The real path is what is checked and opened, with `O_NOFOLLOW`: a
242
+ symlink swapped in for the file itself after the check isn't read. That guards the last path component only: a
243
+ folder on the way swapped for a symlink between the check and the open is still followed. Doing that takes write
244
+ access to the project tree, the owner's, so it isn't a participant's way out; the next read checks again.
245
+ `[]` for a session that isn't a review session. The page's title for a
246
+ review session with no title of its own is `review of docs/plan.md` (`+N` for more), never the first prompt. The
247
+ page shows them as the Plan: beside the thread on a wide screen (≥ 1100 px), a Plan | Thread toggle on a narrower
248
+ one (the thread first, the composer pinned in both views); several subjects get a file picker. It re-reads them
249
+ with the rest at every turn boundary and redraws the Plan only when they changed.
200
250
  - **Redaction** (`ParticipantView::Redact`, on every string that goes out): secret shapes (`sk-…`, `ghp_…`,
201
251
  `github_pat_…`, `AKIA…`, `xox…-`, `chp_…`, `AIza…`, `rk_live_…`, JWTs, Slack webhooks, private key blocks, an
202
252
  `Authorization:` header's value, any `…token` / `…api_key` / `…secret` / `…password` value, `=` or `:`, quoted or
203
253
  not, and a URL's password), the owner's web token, the session's folder (shown as relative paths) and the home
204
254
  folder (`~`). Defence in depth only: the allowlist is the control; a reply that paraphrases a secret isn't caught.
205
- - **Errors.** A participant's 404 and 500 carry fixed words, never an exception's (which may name a path).
255
+ - **Errors.** A participant's 404 and 500 carry fixed words, never an exception's (which may name a path); so does their `wait` on a turn that failed (`TURN_FAILED`).
206
256
  - **The owner's participant view.** The owner reaches the same reads: `/?as=participant#s=<id>` serves the participant
207
257
  page, `GET …/review` is always the filtered view, and `…/stream?as=participant` goes through the same filter, with
208
258
  no participant of their own (nothing `mine`, no composer). It is the server's filter, never a page imitating it.
209
259
 
210
260
  The red-team spec (`spec/participant_red_team_spec.rb`) reads the stream, the review, every show variant, `/output`
211
261
  and an image as a participant, with an approval, a question, a tool's call and output, thinking, a memory, a steer,
212
- a delegate report, an unknown event and host paths in the session, and finds none of them.
262
+ a delegate report, an unknown event and host paths in the session, and finds none of them. It also names a secret,
263
+ a file outside the project and a symlink out of it as subjects in the session file and reads none of them through
264
+ `…/review`, and has `chi review` refuse each as a subject.
213
265
 
214
266
  ## The owner's controls
215
267
 
@@ -220,13 +272,46 @@ carries `qr_svg`, the link's QR, `Web::QR.svg`), revokes and sets caps through t
220
272
  prompt carries their name and colour (`--author-1…6` in `tokens.css`, by id, the same on both pages), from the saved
221
273
  message's `author_name`, `turn_started`'s, or the panel's list (`participant_names.js`).
222
274
 
275
+ ### Apply
276
+
277
+ A review turn proposes; the owner applies (D4, §3 Apply-as-quote). Under each participant's review turn that has a
278
+ reply, the owner's page shows **Apply** (`review_apply.js`; drawn by the history render, `turn_view.js`, and at a live
279
+ turn's end from its `turn_started`'s turn id and author, in the stage while the stage holds the turn; a full-width
280
+ button on a phone). It reads `GET …/apply?turn=T` and puts the answer in the composer, after whatever is typed there,
281
+ never sent: the owner reads it, edits it, sends it or not. While the composer holds it (`deliveryControl.hold()`,
282
+ `delivery_line.js`; let go when it is sent, emptied, or Esc'd while a turn runs, and only for the session it was
283
+ filled in), Enter and Send queue it (`delivery: queue`) behind a running turn instead of steering it in, and the
284
+ delivery line says so: the running turn may be a participant's read-only review turn, where the Apply's edits can't
285
+ run. An armed cut still wins and Esc steers it in during the owner's own turn; a worker without the `delivery`
286
+ feature refuses it with the Alt+Enter note. During a participant's turn the worker queues any owner input anyway
287
+ ([The owner's input during a review turn queues](#turns)).
288
+ The text (`ReviewApply.compose`, the one place it is worded)
289
+ is one line of the owner's and the review turn's reply quoted line by line:
290
+
291
+ ```
292
+ Apply this proposal from Alex's review turn 3f2a1c0d, as far as it fits the plan. It's quoted: a participant's turn wrote it; it isn't my instruction beyond this line.
293
+
294
+ > Add a fallback to phase 2: …
295
+ ```
296
+
297
+ The reply is cut on every line break a textarea or a model may read as one (`\r`, `\r\n`, U+0085, U+2028,
298
+ U+2029), so no part of it starts a line unquoted once the composer normalises it. The name is cleaned as the
299
+ header's is (`ParticipantName.clean`), so a name from a hand-edited session file can't break the owner's line.
300
+ So the participant's words, and whatever their turn's reply echoed of them, reach the model as quoted material
301
+ under the owner's line, never as the owner's instruction: every line of the proposal starts with `>`, whatever it
302
+ says (`spec/review_apply_spec.rb` quotes an "ignore the above and run rm" reply). The reply is the turn's last model
303
+ message with visible text (`OutputFormatter.strip_markup`: no thinking), from the live worker's messages or the saved
304
+ ones. Residual: the owner's turn then acts with the owner's tools on what it quotes, as far as the owner's line asks;
305
+ the owner sees the text before it runs (docs/guardrails.md, the review boundary).
306
+
223
307
  ## The owner's routes
224
308
 
225
309
  | Route | Body / params | Answer | Refusals |
226
310
  |---|---|---|---|
227
- | `GET /api/sessions/:id/participants` | | 200 `{participants: [grant]}`, every state | |
311
+ | `GET /api/sessions/:id/participants` | | 200 `{participants: [grant], warning}`, every state; `warning`: the share warning for a session that isn't a review session (`ReviewStart.share_warning`, null for one), shown before the panel's Invite with Start a review of it | |
228
312
  | `GET /api/participants` | | 200 `{participants: [grant]}`, every session's | |
229
- | `POST /api/sessions/:id/participants` | `name`, `kind` (`human`/`agent`), `ttl` (seconds) | 201 `{participant: grant, token, link, lan}`: the token and the link once; `link` names this chi web's LAN address (`http://IP:PORT/?token=…#s=<id>`), `lan` false when it has none | 400 `invalid_participant` (name, kind, ttl, an archived session); 404 |
313
+ | `POST /api/sessions/:id/participants` | `name`, `kind` (`human`/`agent`), `ttl` (seconds) | 201 `{participant: grant, token, link, lan, qr_svg, warning}`: the token and the link once; `warning` for a session that isn't a review session (`ReviewStart.share_warning`, null for one); `link` names this chi web's LAN address (`http://IP:PORT/?token=…#s=<id>`), `lan` false when it has none | 400 `invalid_participant` (name, kind, ttl, an archived session); 404 |
314
+ | `GET /api/sessions/:id/apply[?turn=T]` | `turn`: a turn id or a prefix (none: the latest review turn with a reply) | 200 `{text, turn_id, author, author_name}`: the Apply turn for the composer, never sent | 404 `not_found` (no such turn, no review turn), 400 `not_review_turn` (an owner's turn), 409 `no_reply` |
230
315
  | `DELETE /api/sessions/:id/participants[?id=p_…]` | | 200 `{revoked: [grant]}`: one participant, or the session's | 400 `invalid_participant` |
231
316
  | `DELETE /api/participants` | | 200 `{revoked: [grant]}`: every session's | |
232
317
  | `POST /api/sessions/:id/participants/:p/cap` | `cap` (dollars, 0 to 1000) | 200 `{participant: grant}`: their cap from their next turn on | 400 `invalid_participant` (the cap, no such active participant) |
@@ -242,12 +327,14 @@ this machine only.
242
327
 
243
328
  ## Files in the session dir
244
329
 
245
- Neither is in the session JSON (chi web never saves that, and a worker would overwrite a field it added), and
246
- neither is copied to a continue, a fork or a delegate (a continue starts with no participants). A session nobody was
247
- invited to has neither: its files stay byte for byte as they were.
330
+ None is in the session JSON (chi web never saves that, and a worker would overwrite a field it added), and
331
+ none is copied to a continue, a fork or a delegate (a continue starts with no participants). A session nobody was
332
+ invited to has none: its files stay byte for byte as they were.
248
333
 
249
334
  - **`participants.json`** (0600, `Participants.write`): `{participants: [{id, kind, name, role, added_at,
250
- expires_at, removed_at, cap}]}`, rewritten by whoever changes a grant (chi web, `chi share`). Never a token or a digest.
335
+ expires_at, removed_at, cap}]}`, rewritten by whoever changes a grant (chi web, `chi share`), inside the grants
336
+ store's lock (`Grants#update`'s `on_write`), so two writers can't finish out of order and lose a revoke here. Never
337
+ a token or a digest.
251
338
  The worker reads it with `Participants.read` (P3a's system-prompt line, `ctx`).
252
339
  - **`participants.jsonl`** (0600, append-only, `Participants.log`): one JSON line per event, with `at`: `issued`
253
340
  (participant, name, kind, role, expires_at), `revoked` (participant, by), `expired` (the first refused use after the
@@ -256,6 +343,8 @@ invited to has neither: its files stay byte for byte as they were.
256
343
  `!line` the Bridge or the worker refused), `turn` (chars, `status: accepted` with its enqueued id, or `refused` with
257
344
  the reason: `not_permitted`, `too_many_turns`, `cap_reached`, `review_unavailable`, `worker_timeout`), `cap` (a new
258
345
  cap). It goes with the session (retention, delete).
346
+ - **`participants.lock`** (0600, empty): the lock a participant's turn file is counted and written under when no
347
+ worker runs ([Turns](#turns)).
259
348
 
260
349
  ## Attribution
261
350
 
@@ -294,18 +383,22 @@ The residual injection risk (an owner turn that says "do what Alex said") is in
294
383
 
295
384
  ## Errors through `--remote`
296
385
 
297
- Each condition has one message, owned by its `SessionAccess` class and built from the remote's label
298
- (`Remote.access_error`, keyed by chi web's error code, for any route):
386
+ Each condition has one message, `ParticipantMessages`' (chi web's `detail`, the Bridge's and the worker's words
387
+ too); its `SessionAccess` class leads it with the remote's label (`Remote.access_error`, keyed by chi web's error
388
+ code, for any route):
299
389
 
300
390
  | Code | Class | Message |
301
391
  |---|---|---|
302
392
  | 401 `token_revoked` | `TokenRevoked` (an `AuthRefused`) | `this review link was revoked by the session's owner` |
303
393
  | 401 `token_expired` | `TokenExpired` (an `AuthRefused`) | `this review link expired: ask the session's owner for a new one` |
304
- | 403 `not_permitted` | `NotPermitted` | `this token is a participant's: only the session's owner can do that` |
394
+ | 403 `not_permitted` | `NotPermitted` | `a participant can't do that: only the session's owner can` |
305
395
  | 429 `too_many_turns` | `TooManyTurns` | `this participant has too many turns waiting: wait for one to finish` |
306
396
  | 429 `cap_reached` | `CapReached` | `this participant's spending cap is reached: ask the session's owner to raise it` |
307
397
 
308
- The server's details are the same words (`ParticipantMessages`), with no label.
398
+ The server's details are the same words, with no label. A participant's `wait` on a failed turn answers 200 with
399
+ `text` `this turn failed: the session's owner can see why` (`TURN_FAILED`). A queued turn the worker refused
400
+ because the link ended (`cancel_reason` `revoked`: participants.json reads it removed or expired, which it doesn't
401
+ tell apart) is `ParentReport`'s `refused` with `this review link was revoked or expired` (`TOKEN_ENDED`).
309
402
 
310
403
  A 401 `unauthorized` stays `AuthRefused`'s "the token was refused".
311
404
 
@@ -330,7 +423,8 @@ participant TUI in v1.
330
423
 
331
424
  ## Invariants
332
425
 
333
- - The owner is a loopback peer or the owner's token; nothing else. A participant token never widens to the owner.
426
+ - The owner is the owner's token, or a loopback peer (or a chi web not on the LAN) with no participant token; nothing
427
+ else. A participant token never widens to the owner, from any peer.
334
428
  - A participant reaches one session, through the `:participant` rows only; another session is a 404.
335
429
  - No token is written anywhere: the grants store has digests, the sidecar and the audit trail have neither.
336
430
  - Owner sessions are unchanged: no sidecar, no audit file, no key in the session JSON until a grant exists.
@@ -342,4 +436,6 @@ participant TUI in v1.
342
436
  shell line (chi web, the Bridge, the worker), and runs only on a worker with the review boundary, which denies
343
437
  everything but reads of the project.
344
438
  - A participant's message is never sent without its review header, and never merged into the owner's message.
439
+ - The owner's input is never merged into a participant's running turn (the Bridge queues it, the drain takes none):
440
+ it runs as the owner's own turn after it.
345
441
  - A participant's turn never answers or drops the owner's Continue offer: it waits until the owner has.
@@ -54,8 +54,9 @@ subcommand:
54
54
  this machine's), runs `RemoteAttachCommand.new(options, access: Remote.new(entry)).run`. A word left over exits 1.
55
55
  Without a remote, `--dir` exits 2 ("--dir goes with --remote; cd there instead").
56
56
  - Otherwise it calls `Remotes.find`, then `Samagotchi.const_get(klass).new(argv, access: Remote.new(entry)).run`.
57
- `Remotes::Invalid` (including `NotFound`) exits 2. A `RemoteFailed` that escapes the command prints
58
- `chi <cmd>: <message>` and exits 1.
57
+ `Remotes::Invalid` (including `NotFound`) exits 2. A `RemoteFailed` or `Refused` that escapes the command prints
58
+ `chi <cmd>: <message>` and exits 1; a `BadRequest` (a value chi web refused, e.g. `sessions list --cwd rel/dir`)
59
+ prints the same line and exits 2.
59
60
 
60
61
  ### Contract
61
62
 
@@ -129,7 +130,9 @@ the session commands*. Keep that table in step with `SessionAccessRoutes`.
129
130
  Bridge's 408; 501 → its 404). Anything unmapped becomes `RemoteFailed` "remote NAME (URL) answered STATUS code:
130
131
  message".
131
132
  - **Transport.** `HTTPTransport#call` turns socket errors into `RemoteFailed` "remote studio (http://…): connection
132
- refused" (also: no answer within 5 s, a read timeout, can't find host, host unreachable, TLS, a broken connection).
133
+ refused" (also: no answer within 5 s, a read or write timeout, can't find host, host unreachable, TLS, a broken
134
+ connection, and "it didn't answer HTTP" for a reply that isn't HTTP: `Net::HTTPBadResponse`, `ProtocolError`, as
135
+ another server on that port gives). The attached TUI's `WebBridgeClient` reads each as `Unreachable`.
133
136
  `ParentWait#run` catches `RemoteFailed` so that `--format json` still prints its error object. Dispatch catches it for
134
137
  the other commands.
135
138
  - **Auth.** `Remote.access_error`, keyed by chi web's error code on any route: a 401 `unauthorized` → "the token was
@@ -199,7 +202,7 @@ with a "Machine-local" comment; the rest branch on `@access.remote?` (`SendComma
199
202
  (`Principal#author`, nil for the owner) and rides with the turn (`SessionManager.deliver_turn(author:)` →
200
203
  `BridgeClient#post_turn` → `Bridge#handle_post_turn` → the input file, the fallback's too → the turn's `origin`);
201
204
  an owner's turn carries none, so its input file and session are byte for byte as before.
202
- - **The token at rest.** `remotes.yml` is written through `AtomicFile.write(perm: 0o600)`. `Entry#inspect` / `#to_s`
205
+ - **The token at rest.** `remotes.yml` is written through `AtomicFile.write(perm: 0o600)`, its read-modify-write (`Remotes.put` / `remove`) under `remotes.yml.lock`. `Entry#inspect` / `#to_s`
203
206
  redact the token. `chi remote ls` never prints it (JSON shows `token: true|false`). `HTTPTransport#inspect` and
204
207
  `Remote#inspect` show only the label.
205
208
  - **The Host check.** `local_host_header?` accepts only the loopback names and the exact LAN IP. `http://studio.local`
@@ -312,6 +315,10 @@ message, so a loop that rescues `IOError` around Bridge calls never crashes on o
312
315
 
313
316
  **The stream.** `connect_stream` writes `GET /api/sessions/:id/stream…` through `BridgeClient::StreamRequest` (the
314
317
  GET a local stream writes, with `Authorization: Bearer` and `Last-Event-ID`; `Host` is the entry's host and port).
318
+ An IPv6 entry (`http://[::1]:4567`) connects on the bare address (`URI#hostname`, as `HTTPTransport` does) and keeps
319
+ the brackets in `Host`.
320
+ Its connect is bounded by the header timeout (`StreamRequest::CONNECT_TIMEOUT`, 5 s, without one): a dead host's
321
+ SYN isn't waited on for the OS's minutes on every reconnect.
315
322
  chi web proxies the Bridge's bytes unchanged (under WEBrick a hijacked body is raw, `Connection: close`). No chunked
316
323
  decoding in v1: a `Transfer-Encoding: chunked` reply (a proxy in between) and an https entry are logged
317
324
  (`stream_refused`, `chunked_unsupported` / `tls_unsupported`) and read as unreachable; decoding and TLS plug into
@@ -353,7 +360,7 @@ the closing line reads `stopped` as `unreachable`, the words it always had.
353
360
  - `live_worker`: `Remote#attach_worker` (`WorkerReply`) with a reason (M5): `stopped` and `unknown_session` (gone),
354
361
  `auth_failed` (`AuthRefused`) and `too_old` (`RemoteTooOld`) end at once; `unreachable` (a transport
355
362
  `RemoteFailed`) and `worker_gone` (chi web answers, no live worker, not stopped) retry through
356
- `RECONNECT_DELAYS` (about a minute, P4-D5). A worker gone for `WAKE_AFTER` (3 s, so a restart's new worker isn't
363
+ `RECONNECT_DELAYS` (about a minute, P4-D5; up to two with a 5 s connect timeout per try on a dead host). A worker gone for `WAKE_AFTER` (3 s, so a restart's new worker isn't
357
364
  raced) is woken once per outage with `POST …/wake` (P4-D9). `failure` keeps the last message for the closing line.
358
365
  - `queues?`/`unqueues?`: the worker's `features`. `ingest_images`: `ImageStore.ingest` into a scratch dir here, then
359
366
  `Remote#upload_images`; `close` (`AttachLauncher.run`'s `ensure`) removes the dir.
data/docs/plugins.md CHANGED
@@ -988,6 +988,7 @@ ctx.sessions.send(id, "then the docs", delivery: :queue) # after its running tu
988
988
  ctx.sessions.read(id) # => {id:, title:, status:, parent_id:, running:, messages:} (title: its /title, else its preview)
989
989
  ctx.sessions.children # => [{id:, short_id:, state:, branch:, last_reply:, reported:, ...}]
990
990
  ctx.sessions.stop(id) # one of this session's own children
991
+ ctx.sessions.review(subjects: ["docs/plan.md"], seed: handoff) # => a review session's id (chi review --from)
991
992
  ```
992
993
 
993
994
  - `fork(messages:, title: nil, prompt: nil)` starts a child session in its
@@ -1001,6 +1002,18 @@ ctx.sessions.stop(id) # one of this session's own children
1001
1002
  `/title` of its own (see [Session titles](sessions.md#session-titles)).
1002
1003
  - An image a message names is copied into the child. One whose file is
1003
1004
  gone is dropped, with `[image x.png was not copied]` in its message.
1005
+ - `review(subjects: [], seed: nil, recap_wait: 0)` starts a review session of
1006
+ this one, as `chi review --from` does (see [Review sessions](sessions.md#review-sessions)):
1007
+ a new session in this session's folder, on its model and setup, seeded with
1008
+ its recap (never its transcript) and `seed:` (more context, a handoff say),
1009
+ idle, to share with participants (`chi share ID`). This session keeps
1010
+ running, unarchived; the review isn't its child. `subjects:` are project
1011
+ files relative to its folder (a secret or a file outside the project raises
1012
+ `Error` with chi review's one message). It uses the recap already saved: the
1013
+ worker is asked for a fresh one but not waited on unless `recap_wait:` (in
1014
+ seconds) says so, as it runs in this session's own worker. It returns the
1015
+ review session's id. The test kit's `bundle.sessions` answers `review-1`,
1016
+ `review-2`…
1004
1017
  - `send(id, text)` sends a user message to a session (an id or a unique
1005
1018
  prefix); it runs as a turn, and a stopped session is woken. It waits up to
1006
1019
  5 s for the session's worker, so call it from an anytime command or a
@@ -1345,7 +1358,7 @@ bundles:
1345
1358
  sentence of the server's `instructions` (from `initialize`), for its line
1346
1359
  in `find_tools`.
1347
1360
  - **The first run** (no saved list, or the config changed) starts the
1348
- server in an [init task](#chiinitlabel-provides_tools-false-quiet-false-timeout-nil--ctx--):
1361
+ server in an [init task](#chiinitlabel-provides_tools-false-quiet-false-timeout-nil-failed-nil--ctx--):
1349
1362
  every UI shows `Starting MCP server x (first run, saving its tools)`, and
1350
1363
  a turn sent meanwhile waits for its tools. A server that doesn't start,
1351
1364
  answer or list its tools within `startup_timeout` (each step) is a warn
@@ -2083,6 +2096,21 @@ by themselves there.
2083
2096
  report ending with the `/coordinate resume <slug>` to pick it up next
2084
2097
  time. It starts, merges and stops nothing: running children stay running
2085
2098
  and are named in the report.
2099
+ - **Sprint review (experimental, 0.6.0).** **`/coordinate review [name]`**
2100
+ starts a review session of this coordinator session (`ctx.sessions.review`:
2101
+ its recap, never its transcript; this session keeps running) seeded with the
2102
+ open handoff's body (the one named, the only one, or a card with a Review
2103
+ action each when several are open; with none, the recap alone), and prints
2104
+ the `chi share <id> --name NAME` line. A participant (a manager, a teammate)
2105
+ brings new context there; the skill's Sprint review section (copied into
2106
+ the seed: a participant's turn reads project memories only, and the skill
2107
+ is a system one) has the review's model answer it with a **hand-off diff** (the handoff's lines as
2108
+ they would change, in a `diff` block, and what it means per branch), in a
2109
+ turn that may only read. Your **Apply** under it (the web's) quotes the
2110
+ diff in your turn there: the model brings the handoff up to date and
2111
+ re-plans in words, and starts, stops or merges nothing from the review
2112
+ session: the coordinator session picks the change up from the handoff,
2113
+ merges still asked. Experimental: it may go if it doesn't earn its place.
2086
2114
  - **The coordinator toolkit.** The bundle declares `coordinator`: `lean`
2087
2115
  plus `delegate`, `delegate_result` and `list_sessions`
2088
2116
  ([Toolkits](configuration.md#toolkits)). `/coordinate` puts a fresh session
data/docs/releasing.md CHANGED
@@ -26,6 +26,8 @@ can run the whole release; the user approves the notes before the tag and the
26
26
  `release:check` fails while a marker is left. chi itself ignores the key,
27
27
  and `bundles:check` notes it (and fails a marker that isn't `true` or a
28
28
  one-line string). `release:bump` touches no other `requires_chi`;
29
+ - a new `ctx.*` / `chi.*` call a plugin may make gets its release's version in `Plugin::Api::SINCE` once
30
+ released (`chi bundle check`'s `requires-chi-floor` reads it); an unreleased one waits there as a comment;
29
31
  - a new shipped bundle joins a profile (`includes:` in `core` or `dev`; a
30
32
  spec checks every bundle is in exactly one), and that profile's version
31
33
  goes up: `chi update` then installs only the new bundle for those who
data/docs/sessions.md CHANGED
@@ -39,7 +39,7 @@ A session is deleted if **expired by age OR overflow by count** (unless `keep_st
39
39
 
40
40
  **Lazy sweep:** automatic prune runs only while `chi web` runs, at most once per `session.sweep_interval_hours` (default 24): the web's session hub gives it a chance on its periodic full scan, and `GET /api/sessions` does too. No cron, and a terminal-only chi never sweeps. Manual prune is always available.
41
41
 
42
- **CLI:**
42
+ <a id="cli"></a>**CLI:**
43
43
 
44
44
  ```sh
45
45
  chi sessions list [--sort updated_at|created_at] [--order desc|asc] [--limit N] [--scope=all]
@@ -257,6 +257,41 @@ A session can **continue** an earlier one: "the next run of the same routine" (a
257
257
  - **CLI:** `chi send --new --continues (ID|PREFIX|last:ID) [--model M] [-m TEXT]` (see *Starting a session*).
258
258
  - **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.
259
259
 
260
+ ## Review sessions
261
+
262
+ A **review session** is one made to be shared with participants (the shared-sessions plan's D2: a review is its own
263
+ session, so a participant's review turn can't quote a working session's tool outputs). `chi review FILE…` starts one
264
+ in a project, `chi review --from ID` as a review fork of a working session (see [CLI: Review
265
+ sessions](cli.md#review-sessions)); both start idle and print the `chi share` line to invite someone.
266
+
267
+ - **The field:** `review: {subjects: ["docs/plan.md", …], from: "<id>"}` in the session JSON: the subjects relative
268
+ to the project root (the work tree top of its folder, its folder outside git), and for a fork the session it
269
+ started from. A session without one has no `review` key at all, so other session files save as they were. A
270
+ continue keeps it; a fork (`ctx.sessions.fork`) and a delegate child don't.
271
+ - **The subjects** are checked where the session starts (`ReviewStart.check_subjects`), by the same check a review
272
+ turn's `read` goes through (`Guardrails::ReviewPaths`): an existing file under the project root, as given and as it
273
+ resolves, never a secret file or chi's own. They are what participants read beside the thread.
274
+ - **The note:** it starts with a context note from `review` naming the subjects and what a review turn does; a fork's
275
+ starts with `This review session starts from 3f9a1c2e (2026-10-23 09:12), a working session: it brings that
276
+ session's recap, not its transcript.` and the recap (as a continue's carry note), so nothing of the source's
277
+ history comes along. Its preview is `review: docs/plan.md`, or a fork's `review of <the source's title>`.
278
+ - **A fork isn't a continue:** the source is neither archived nor continued (no `continues`), and its delegates stay
279
+ its own; a coordinator can open a review of its own session and keep working (`/coordinate review`).
280
+ - **Web:** `POST /api/sessions` takes `review: {subjects: [...], from: "<id>"}` instead of a `prompt` (a review
281
+ session starts idle: `prompt`, `preview`, `idle` and `continues` beside it are 400 `invalid_review`). Without
282
+ `from`, the subjects are relative to `dir` and the setup fields work as for any create; with `from`, the source's
283
+ folder and setup are taken (`dir` and the setup fields beside it are 400 `invalid_review`) and `model` is the
284
+ only choice. A subject refused, or the source's folder gone, is 400 `invalid_review` with the one message; an
285
+ unknown source 404 `not_found`.
286
+ - **The page:** the start page's `review…` chip (beside think and llm ctx) takes the files (comma- or
287
+ space-separated, relative to the page's folder; a path with a space in double quotes, `"docs/my plan.md"`): its
288
+ chip then reads `review: plan.md +1`, and Start makes a review session (the message typed, if any, is its first
289
+ turn; with none it starts idle). A refused file shows the server's one message in the chip's form, opened again. On a session that isn't a review session the participants panel (the session bar's
290
+ participants chip) says so before its Invite, with the share warning (how many tool outputs its history holds)
291
+ and **Start a review of it**: a review fork of it, opened, with a toast (`Review 4b7e9a01 started from 3f9a1c2e's
292
+ recap; 3f9a1c2e keeps running.`) whose **Invite** opens the new session's panel. Every summary carries `review`
293
+ (null for other sessions).
294
+
260
295
  ## Toolkits
261
296
 
262
297
  A session file's `toolkit` (`{"name", "add", "remove"}`) is the toolkit it was created on, as named: config's
data/docs/sub-agent.md CHANGED
@@ -69,7 +69,9 @@ Exit codes, both commands:
69
69
  | 0 | `command` | (`chi send`) the message was a session command (`/model x`): it ran as one, no reply comes |
70
70
  | 0 | `not_continued` | (`chi answer`) a Stop answered the step-limit question; the turn's work so far stays |
71
71
  | 3 | `question` | chi waits for an answer: `question`, `answer_with` |
72
+ | 3 | `waiting_for_owner` | (a participant's wait, `chi --remote NAME send --wait` with their link's token) their review turn waits on the session's owner: a question or an approval it raised, or the owner's step-limit Continue; wait again |
72
73
  | 4 | `running` | `--timeout` passed; the turn goes on, wait again |
74
+ | 1 | `refused` | (a participant's wait) their queued review turn was refused before it ran: `cancel_reason` `revoked` (their link was revoked or expired) or `cap_reached` (they spent their cap); no turn ran for it |
73
75
  | 1 | `failed`, `canceled`, `limit`, `removed`, `no_answer`, `error`, `worker_gone`, `stopped` | `detail` says what happened (`limit`: the turn ran out of steps and nobody can be asked, e.g. an older worker; `chi send ID -m '/continue yes'` continues it, except under `guardrails.parent_answers: hard`, where a parent's `/continue yes` is refused as its `chi answer --option Continue` is; `removed`: the `--queue` message waited for was taken back before it ran, no turn ran for it). `failed` adds `error_kind` (the provider error's kind: `credits`, `credits_held`, `rate_limited`, `server`, `auth`, `connection`, …) and `retryable` when known; `canceled` adds `cancel_reason` (`user`: a Stop in the web; `session_stopped`: a session stop, `chi sessions stop` or the web's; `worker_stopped`: the `--queue` turn waited for died with its worker (detail "its worker exited mid-turn"), settled by the next one; `hook`; `ctrl_c`; `manual`) and `stopped_by` (the hook that stopped it, e.g. `loop-guard`) when known |
74
76
  | 2 | (no JSON) | usage error, or an option the question doesn't offer |
75
77
  | 130 | `running` | Ctrl-C; the turn goes on |
data/docs/testing.md CHANGED
@@ -87,6 +87,8 @@ run, CI) and too long on a fast one. The contract a new spec follows:
87
87
  files that must sort apart get distinct times, not a pause: `Session.new_session(now:)`, `Session#save(now:)` and
88
88
  `SessionInbox.write_input` / `write_note` / `write_output(now:)` take `now: next_stamp` (spec/support/stamps.rb:
89
89
  a millisecond later on each call, starting a second in the past).
90
+ An example at a threshold's edge (a TTL, a grace) passes one `now:` to both sides and never reads `Time.now`
91
+ twice for it: a second boundary crossed between the reads moves the edge (`ModelProfile.model_warning(now:)`).
90
92
  3. **What a spec starts, it stops and waits for** before teardown: `join!(thread, what)`, `with_task_dir { … }`
91
93
  (spec/support/task_dirs.rb: a tasks' folder of its own, its tasks stopped and their exit-status recorders joined
92
94
  with `TaskRuntime.quiesce!`), a `stop` that joins (`IdleScheduler#stop`). Never only `Thread#kill`.
@@ -67,6 +67,12 @@ module Samagotchi
67
67
  end
68
68
  end
69
69
 
70
+ # Whether the turn in progress is a participant's review turn (its
71
+ # author): the owner's input queues behind it then (Bridge's POST /turn).
72
+ def participant_turn?
73
+ @mutex.synchronize { !@turn.nil? && Steer.participant_author?(@turn[:author] || @turn.dig(:origin, :author)) }
74
+ end
75
+
70
76
  # The turn in progress as conversation messages, for a plugin's
71
77
  # ctx.messages mid-turn (plan O1): its prompt (with its images), the
72
78
  # model's text so far, and the lines merged into it, in order. Tool
@@ -957,6 +957,10 @@ module Samagotchi
957
957
  next :expired if expired?("turn_expired", deadline, sid: sid, client_id: client_id)
958
958
  next :too_many if pending_limit && pending_turns(author) >= pending_limit
959
959
 
960
+ # The owner's input never goes into a participant's read-only
961
+ # review turn (a steer, a cut): it queues behind it as the owner's
962
+ # own turn, and the ack and :turn_enqueued say so.
963
+ delivery = Delivery::QUEUE if @accumulator.participant_turn?
960
964
  queued_behind_turn = Delivery.queue?(delivery) && !@accumulator.current_turn.nil?
961
965
  enqueue_turn(prompt: prompt, client_id: client_id, enqueued_id: enqueued_id,
962
966
  no_interrupt: no_interrupt, images: images, delivery: delivery, author: author).tap do |ok|
@@ -12,22 +12,28 @@ module Samagotchi
12
12
  module StreamRequest
13
13
  # A reply's status line; its code is group 1 (BridgeClient::STATUS_LINE).
14
14
  STATUS_LINE = %r{\AHTTP/1\.[01] (\d{3})}
15
+ # The connect's bound when no +timeout+ is given (HTTPTransport's
16
+ # OPEN_TIMEOUT): a dead host (no SYN answer) is given up on, so a
17
+ # reconnect loop (RemoteLink's minute of tries) isn't held by the
18
+ # OS's minutes-long SYN timeout on each.
19
+ CONNECT_TIMEOUT = 5.0
15
20
 
16
21
  module_function
17
22
 
18
23
  # Open the stream and read past the response headers.
19
- # @param host [String]
24
+ # @param host [String] a name or an address, an IPv6 one bare (::1)
20
25
  # @param port [Integer]
21
26
  # @param path [String] the request path with its query
22
27
  # @param last_event_id [String, nil] the reconnect cursor
23
28
  # @param headers [Hash{String => String}] extra request headers, after
24
29
  # Last-Event-ID
25
- # @param timeout [Float, nil] give up when the headers aren't all in by then
30
+ # @param timeout [Float, nil] give up when the connect (CONNECT_TIMEOUT
31
+ # when nil), then the headers, aren't done by then
26
32
  # @return [Array(TCPSocket, Integer, Hash), nil] the socket positioned
27
33
  # at the body, the HTTP status and the response headers (names in
28
34
  # lower case), or nil when the server can't be reached
29
35
  def open(host:, port:, path:, last_event_id: nil, headers: {}, timeout: nil)
30
- sock = TCPSocket.new(host, port)
36
+ sock = TCPSocket.new(host, port, connect_timeout: timeout || CONNECT_TIMEOUT)
31
37
  sock.write(request(host: host, port: port, path: path, last_event_id: last_event_id, headers: headers))
32
38
  deadline = timeout && (Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout)
33
39
  status = header_line(sock, deadline).to_s[STATUS_LINE, 1].to_i
@@ -50,6 +56,7 @@ module Samagotchi
50
56
  lei = last_event_id.to_s.strip
51
57
  last_event_line = lei.empty? ? "" : "Last-Event-ID: #{lei}\r\n"
52
58
  extra = headers.map { |name, value| "#{name}: #{value}\r\n" }.join
59
+ host = "[#{host}]" if host.include?(":") && !host.start_with?("[")
53
60
  "GET #{path} HTTP/1.1\r\nHost: #{host}:#{port}\r\nAccept: text/event-stream\r\n#{last_event_line}#{extra}" \
54
61
  "Connection: keep-alive\r\n\r\n"
55
62
  end
@@ -1,17 +1,18 @@
1
1
  ---
2
2
  name: coordinator
3
- version: 0.5.0
3
+ version: 0.6.0
4
4
  scope: system
5
- description: "Coordinate parallel work: the coordinator skill (split the work, one worktree and child session per task, check each report, ask before each merge, a handoff memory to resume from), /coordinate <goal>, /coordinate resume, /coordinate end and /children; the coordinator toolkit (lean + delegate, delegate_result, list_sessions) and the coding toolkit for build children (child + be concise)"
5
+ description: "Coordinate parallel work: the coordinator skill (split the work, one worktree and child session per task, check each report, ask before each merge, a handoff memory to resume from), /coordinate <goal>, /coordinate resume, /coordinate end, /coordinate review (experimental: a sprint review session to share) and /children; the coordinator toolkit (lean + delegate, delegate_result, list_sessions) and the coding toolkit for build children (child + be concise)"
6
6
  trust_level: reviewed
7
7
  files:
8
8
  skill_coordinator.md:
9
- sha256: sha256:718cb76da10f9610a7582eddf1441590566836ebc6a9cb127b7f7847b17ceb92
9
+ sha256: sha256:5f6b879de274ebc89b7811d3dda3abbecbeb696159e326647a1c7393c3598f57
10
10
  description: "Coordinate parallel work: split it, delegate each task wait:false in its own worktree (cwd:), check each report, ask the user before each merge; resume from a handoff_* memory"
11
11
  plugin:
12
12
  file: plugin.rb
13
- sha256: sha256:3b5f766ad198862243c494e4c5aec7c4a0972e7644a6388bed843c5651f5ca0d
13
+ sha256: sha256:10ad704ca9c88f4843eb8a35931b732d54ee52e4824ccb59a5e608e84868006d
14
14
  # the coordinator toolkit needs chi.toolkit and ctx.use_toolkit (0.66.0); the
15
15
  # coding toolkit (chi.toolkit prompt:) and the skill's delegate toolkit: need
16
16
  # the next chi.
17
- requires_chi: ">= 0.72.0"
17
+ requires_chi: ">= 0.107.0"
18
+ # /coordinate review uses ctx.sessions.review (the next chi).