samagotchi 0.180.0 → 0.182.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 (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +71 -1
  3. data/bin/chi +11 -0
  4. data/docs/architecture.md +2 -2
  5. data/docs/bundles.md +7 -2
  6. data/docs/cli.md +46 -13
  7. data/docs/configuration.md +25 -4
  8. data/docs/internals/anthropic.md +4 -3
  9. data/docs/internals/background-tasks.md +2 -0
  10. data/docs/internals/block-renderers.md +123 -6
  11. data/docs/internals/bridge.md +10 -0
  12. data/docs/internals/engine.md +11 -0
  13. data/docs/internals/inline-widgets.md +3 -1
  14. data/docs/internals/objectives.md +9 -4
  15. data/docs/internals/prompt-caching.md +9 -1
  16. data/docs/internals/remote-sessions.md +14 -2
  17. data/docs/internals/web-frontend.md +100 -10
  18. data/docs/internals/working-set.md +24 -5
  19. data/docs/memory.md +3 -0
  20. data/docs/plugins.md +11 -4
  21. data/docs/sessions.md +8 -5
  22. data/docs/testing.md +1 -1
  23. data/lib/samagotchi/answer_display.rb +3 -2
  24. data/lib/samagotchi/block_fix/stamp.rb +49 -0
  25. data/lib/samagotchi/block_fix.rb +220 -0
  26. data/lib/samagotchi/bridge/block_fix_route.rb +30 -0
  27. data/lib/samagotchi/bridge/turn_drawings.rb +19 -0
  28. data/lib/samagotchi/bridge.rb +11 -2
  29. data/lib/samagotchi/bridge_client.rb +9 -0
  30. data/lib/samagotchi/bundle_command.rb +4 -1
  31. data/lib/samagotchi/bundles/known-names/manifest.yml +2 -2
  32. data/lib/samagotchi/bundles/known-names/plugin.rb +4 -3
  33. data/lib/samagotchi/bundles/system/config_modification_protocol.md +3 -2
  34. data/lib/samagotchi/bundles/system/manifest.yml +2 -2
  35. data/lib/samagotchi/client.rb +8 -1
  36. data/lib/samagotchi/config.rb +9 -1
  37. data/lib/samagotchi/continue_intent.rb +8 -0
  38. data/lib/samagotchi/core_notice.rb +44 -0
  39. data/lib/samagotchi/engine/block_fix.rb +332 -0
  40. data/lib/samagotchi/engine/side_requests.rb +7 -5
  41. data/lib/samagotchi/engine.rb +4 -0
  42. data/lib/samagotchi/events.rb +1 -0
  43. data/lib/samagotchi/host_address.rb +7 -0
  44. data/lib/samagotchi/host_config.rb +8 -5
  45. data/lib/samagotchi/host_registry.rb +26 -8
  46. data/lib/samagotchi/idle_client.rb +10 -6
  47. data/lib/samagotchi/inline_widgets.rb +12 -0
  48. data/lib/samagotchi/kernel_loop.rb +10 -7
  49. data/lib/samagotchi/llm/adapter_common.rb +3 -2
  50. data/lib/samagotchi/llm/adapters.rb +2 -1
  51. data/lib/samagotchi/llm/anthropic_assembly.rb +5 -0
  52. data/lib/samagotchi/llm/anthropic_messages.rb +6 -2
  53. data/lib/samagotchi/llm/chat_loop.rb +8 -5
  54. data/lib/samagotchi/llm/errors.rb +41 -3
  55. data/lib/samagotchi/llm/http.rb +85 -22
  56. data/lib/samagotchi/llm/openai_chat.rb +20 -3
  57. data/lib/samagotchi/markdown_parser.rb +28 -0
  58. data/lib/samagotchi/memory_bundle/status.rb +2 -1
  59. data/lib/samagotchi/objectives.rb +7 -2
  60. data/lib/samagotchi/owner_lock.rb +2 -0
  61. data/lib/samagotchi/plugin/api.rb +4 -1
  62. data/lib/samagotchi/plugin/context.rb +9 -0
  63. data/lib/samagotchi/plugin/peer.rb +32 -15
  64. data/lib/samagotchi/plugin/tool_spec.rb +13 -2
  65. data/lib/samagotchi/row_refs.rb +14 -3
  66. data/lib/samagotchi/session_access/contract.rb +3 -0
  67. data/lib/samagotchi/session_access/delete_plan.rb +77 -0
  68. data/lib/samagotchi/session_access/local.rb +13 -0
  69. data/lib/samagotchi/session_access/remote.rb +19 -1
  70. data/lib/samagotchi/session_access.rb +1 -0
  71. data/lib/samagotchi/session_chain/delete.rb +45 -87
  72. data/lib/samagotchi/session_chain/delete_preview.rb +55 -19
  73. data/lib/samagotchi/session_delete_command.rb +129 -3
  74. data/lib/samagotchi/session_manager/delegate_rule.rb +86 -0
  75. data/lib/samagotchi/session_manager/listing.rb +4 -4
  76. data/lib/samagotchi/session_manager/removal.rb +40 -14
  77. data/lib/samagotchi/session_manager/running_tasks.rb +50 -23
  78. data/lib/samagotchi/session_manager.rb +1 -0
  79. data/lib/samagotchi/tool_ids.rb +19 -0
  80. data/lib/samagotchi/tool_runner.rb +8 -4
  81. data/lib/samagotchi/tools/registry.rb +3 -2
  82. data/lib/samagotchi/tools/task_runtime.rb +34 -0
  83. data/lib/samagotchi/turn_stages/objectives.rb +10 -5
  84. data/lib/samagotchi/version.rb +1 -1
  85. data/lib/samagotchi/web/app.rb +13 -1
  86. data/lib/samagotchi/web/block_fix_routes.rb +39 -0
  87. data/lib/samagotchi/web/markdown_renderer.rb +24 -9
  88. data/lib/samagotchi/web/message_display.rb +6 -1
  89. data/lib/samagotchi/web/participant_view.rb +1 -1
  90. data/lib/samagotchi/web/public/app.js +15 -19
  91. data/lib/samagotchi/web/public/block_fix.js +270 -0
  92. data/lib/samagotchi/web/public/block_fix_note.js +104 -0
  93. data/lib/samagotchi/web/public/block_frame.js +6 -3
  94. data/lib/samagotchi/web/public/block_host.js +21 -21
  95. data/lib/samagotchi/web/public/block_renderers.css +17 -5
  96. data/lib/samagotchi/web/public/block_watch.js +16 -2
  97. data/lib/samagotchi/web/public/context_chips.js +3 -4
  98. data/lib/samagotchi/web/public/images.js +1 -1
  99. data/lib/samagotchi/web/public/index.html +24 -5
  100. data/lib/samagotchi/web/public/inline_widgets.js +1 -1
  101. data/lib/samagotchi/web/public/objectives_strip.js +16 -6
  102. data/lib/samagotchi/web/public/pan_zoom.js +121 -0
  103. data/lib/samagotchi/web/public/peer_chip.js +3 -3
  104. data/lib/samagotchi/web/public/peer_data.js +27 -15
  105. data/lib/samagotchi/web/public/picture_viewer.js +304 -0
  106. data/lib/samagotchi/web/public/popover_modal.js +3 -2
  107. data/lib/samagotchi/web/public/session_view.js +4 -0
  108. data/lib/samagotchi/web/public/stream_handlers.js +5 -1
  109. data/lib/samagotchi/web/public/turn_block.js +5 -2
  110. data/lib/samagotchi/web/public/working_set.js +9 -3
  111. data/lib/samagotchi/web/public/working_set_view.js +28 -11
  112. data/lib/samagotchi/web/public/ws_cards.js +36 -10
  113. data/lib/samagotchi/web/public/ws_markdown.js +129 -0
  114. data/lib/samagotchi/web/public/ws_order.js +48 -0
  115. data/lib/samagotchi/web/public/ws_peek.js +22 -5
  116. data/lib/samagotchi/web/public/ws_preview.css +41 -1
  117. data/lib/samagotchi/web/public/ws_reader.js +35 -6
  118. data/lib/samagotchi/web/public/ws_sections.js +24 -15
  119. data/lib/samagotchi/web/server.rb +6 -4
  120. data/lib/samagotchi/web/session_control.rb +53 -21
  121. data/lib/samagotchi/worker/block_fixes.rb +22 -0
  122. data/lib/samagotchi/worker.rb +10 -3
  123. metadata +17 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '056860037a4db0a4c2ec4fb0fa92aa022024dd344e13786bdb55d7947999c572'
4
- data.tar.gz: 8a3bb8f657b9b05ad682abd3e708be26ee70e8759a4e5df01a212e5fc715c292
3
+ metadata.gz: 39e6d208e1727e50fcb10c903c2c8cfc2bcb5c659f769de03916a52a527fc216
4
+ data.tar.gz: d9b8cca3456163bcec4c133e9559a7ef6e87a60eb6bcbd18537016e4afb4927a
5
5
  SHA512:
6
- metadata.gz: af64aaac919f8722c9b274984a82712d0f3c7464d78f3c6428ffb74c47f4ac3158e7fc11b21ad46df24c7452f581d5bbee9e8d97f782b5640802f7bd60037452
7
- data.tar.gz: ed980f2025a4b03c1e868008f828bec79f185b6fa2682d05808a83cb94243d6b09802bfddf751a822c110582ce5849aba6aedebbc20d27746c76d3eb8011be27
6
+ metadata.gz: 5737d57d34e0a8b8c49e776f1a771354a1f5abb2afaff856cc29b73fe0adf6c1740048c3b32df19087a23580d38b6532b5203b286de4fe96c84022a5b684eef9
7
+ data.tar.gz: 92dd02c054a4353dfd7ce245b3c6c11ceecbf571922704af64b0cffcde5fc95615309f96165242dac203d05f6b3c6372d372226fcc5afd92ff0a1686edde8619
data/CHANGELOG.md CHANGED
@@ -8,6 +8,74 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.182.0] - 2026-11-21
12
+
13
+ ### Added
14
+
15
+ - In the web, a fenced block chi can't draw in the newest answer (a `chi-ui` picks or walk, a Mermaid diagram) is
16
+ asked for again once, on the side: no message is sent and no turn runs. The fixed block draws with "Drawn after a
17
+ fix" under it, and the saved answer holds it. A fix that didn't help, or an older answer's block, gets an "Ask in
18
+ chat" button that fills the composer. `web.block_fix: off` turns it off.
19
+ - `chi sessions delete --dry-run ID...` prints what the delete would do and deletes nothing: what goes, what is
20
+ stopped first and what stays (the web's delete sheet in the terminal), and which of `--force` / `--stop-tasks` it
21
+ needs; with `--chain`, the chain's. It exits 1 when the delete would be refused. With `--remote` it needs a chi
22
+ web of this version.
23
+
24
+ ### Changed
25
+
26
+ - Deleting a session (the web, `chi sessions delete`, `/exit --delete`) now deletes its stopped delegates with it; a
27
+ running delegate keeps running on its own. With `--remote`, an older chi web still leaves them.
28
+
29
+ ### Fixed
30
+
31
+ - A remote archive refusal keeps the hidden session count and names every worker stopped before its task check.
32
+
33
+ Update with `chi update`.
34
+
35
+ ## [0.181.0] - 2026-11-21
36
+
37
+ ### Added
38
+
39
+ - In the web, an attached image opens in a full-screen viewer, fitted: pinch, Ctrl/Cmd + scroll or the bar's − and +
40
+ zoom (sharp at every size), a drag or scroll moves, a double tap goes close and back, ✕ or Esc closes. A tap on
41
+ the picture no longer closes it.
42
+ - In the web, one tap on a drawn diagram (a mermaid block) opens it in that viewer, fitted to the screen, to zoom in
43
+ and move around; in the answer it stays fitted to the column (the tap no longer switches it to its natural size).
44
+ On a phone the diagram's rendered | source switch stays shown, faint.
45
+ - In the web, the working set's reader and peek show a memory and a whole read of a `.md` file as rendered
46
+ markdown, with a `rendered | source` switch on the reader's cards (the same small pill on a phone); a memory's
47
+ peek starts at its body, without the front matter. A slice of a file stays numbered source.
48
+ - chi reminds you once on stderr when no core safety bundles are installed, including in a one-shot.
49
+
50
+ ### Changed
51
+
52
+ - A background task's folder (`tmp/tasks/`) is added to the repository's `.git/info/exclude`, so `git status`
53
+ doesn't list it.
54
+ - In the web, the working set's peek and reader say an item read in the step still running shows once that step's
55
+ tools finish, rather than "Nothing of it in the conversation yet".
56
+ - `chi bundle status NAME` reports a rule or script with no recorded sha256 as `[unrecorded]`, not `[modified]`.
57
+ - The web's working-set list opens on what chi touched last: "Read in this session" first, newest first (a row's
58
+ step tag is its last touch), the conversation's row, then "From the start", folded to one line with its
59
+ `held twice` count. Rows don't move while the list is open; new ones come in on top.
60
+
61
+ ### Fixed
62
+
63
+ - The known-names guardrail no longer flags a project's class name in backticks
64
+ (`CoffeeAssistant` for `coffee_assistant`) as a typo.
65
+ - A streamed answer that stops mid-way (no text, reasoning or tool call for `stream_idle_timeout` seconds; default
66
+ 120 on remote hosts, off on local) is closed and asked again like a dropped stream, then fails with `the model's
67
+ stream stalled …`, instead of waiting on keep-alives until the read timeout.
68
+ - The objectives strip no longer shows an empty 0/0 bar when every objective is dropped, and disappears at once when
69
+ the list goes away.
70
+ - A continue no longer starts with an empty Objectives bubble when every objective was dropped.
71
+ - Deleting a session no longer sometimes refuses it as in use while chi web is checking it.
72
+ - The peer chip says when no inbox is attached, rather than blaming a remote.
73
+ - Sending a peer the same part twice no longer marks the first, answered send "not sent" in the web: each send has
74
+ its own id.
75
+
76
+ Update with `chi update` (known-names 0.2.1 carries the backtick fix).
77
+
78
+
11
79
  ## [0.180.0] - 2026-11-20
12
80
 
13
81
  ### Added
@@ -6576,7 +6644,9 @@ and long-lived sessions.
6576
6644
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
6577
6645
  hotkey panel that send selected text or the clipboard to your sessions.
6578
6646
 
6579
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.180.0...HEAD
6647
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.182.0...HEAD
6648
+ [0.182.0]: https://github.com/dm1try/samagotchi/compare/v0.181.0...v0.182.0
6649
+ [0.181.0]: https://github.com/dm1try/samagotchi/compare/v0.180.0...v0.181.0
6580
6650
  [0.180.0]: https://github.com/dm1try/samagotchi/compare/v0.179.0...v0.180.0
6581
6651
  [0.179.0]: https://github.com/dm1try/samagotchi/compare/v0.178.0...v0.179.0
6582
6652
  [0.178.0]: https://github.com/dm1try/samagotchi/compare/v0.177.1...v0.178.0
data/bin/chi CHANGED
@@ -260,6 +260,10 @@ end
260
260
 
261
261
  if options[:web]
262
262
  chi_update_hint.call unless web_restarted
263
+ unless web_restarted
264
+ require "samagotchi/core_notice"
265
+ Samagotchi::CoreNotice.show
266
+ end
263
267
  require "samagotchi/web/server"
264
268
  port = options[:web_port] || Samagotchi::Config.get("web.port")
265
269
  markdown = options[:web_markdown]
@@ -269,6 +273,7 @@ if options[:web]
269
273
  working_set: Samagotchi::Config.get("web.working_set"),
270
274
  stage_collapsed: Samagotchi::Config.get("web.stage_collapsed"),
271
275
  reload_check: Samagotchi::Config.get("web.reload_check"),
276
+ block_fix: Samagotchi::Config.get("web.block_fix"),
272
277
  annotate_presets: Samagotchi::Config.get("web.annotate_presets"),
273
278
  editor: Samagotchi::Config.get("web.editor"),
274
279
  start_dir: options[:start_dir] || Samagotchi::Config.get("web.start_dir"),
@@ -416,6 +421,8 @@ if launch == :attached
416
421
  exit 1
417
422
  end
418
423
 
424
+ require "samagotchi/core_notice"
425
+ Samagotchi::CoreNotice.show
419
426
  require "samagotchi/terminal_ui/attach_launcher"
420
427
  begin
421
428
  ended = Samagotchi::TerminalUI::AttachLauncher.run(attach: options[:attach], resume: options[:resume],
@@ -445,6 +452,10 @@ end
445
452
 
446
453
  # --non-interactive: the -p prompt's one turn in this process (TerminalUI,
447
454
  # the one-shot host); bare, a no-op that creates no session.
455
+ if options[:prompt]
456
+ require "samagotchi/core_notice"
457
+ Samagotchi::CoreNotice.show
458
+ end
448
459
  require "samagotchi/cli/exit"
449
460
  require "samagotchi/terminal_ui"
450
461
  begin
data/docs/architecture.md CHANGED
@@ -623,7 +623,7 @@ of chi reads (the prompt is input + cache reads + cache writes), stop reasons to
623
623
  (`max_tokens` → `length`, `tool_use` → `tool_calls`, `end_turn` → `stop`). A stream is read by content-block index
624
624
  from the `data:` lines alone (`event:` lines are not needed); `message_start` / `message_delta` events reach
625
625
  `on_delta` with that normalized `usage`, pings not at all, and a block's start or delta counts as shown for the
626
- first-token limit. Both adapters share their model-list cache (`LLM::ModelListing`) and their HTTP plumbing
626
+ first-token and stream-idle limits (`message_delta` and `message_stop` restart the idle clock without counting). Both adapters share their model-list cache (`LLM::ModelListing`) and their HTTP plumbing
627
627
  (`LLM::AdapterCommon`: timeouts, the paged model list, the SSE line loop, JSON errors). A host's `dialect:`
628
628
  (`LLM::Dialect`, `fireworks`) changes the auth header, the thinking `display`, the cache breakpoints and a session
629
629
  header; [internals/anthropic.md](internals/anthropic.md) covers the adapter.
@@ -652,7 +652,7 @@ A map of the parts the overview above doesn't name (paths under `lib/samagotchi/
652
652
 
653
653
  | Component | Main file(s) | What it is |
654
654
  |---|---|---|
655
- | Worker | `worker.rb` (`worker_boot.rb`, `worker_idle_exit.rb`, `worker_inbound.rb`, `worker_signals.rb`, `worker_wakes.rb`, `worker_task_wakes.rb`, `task_watch.rb`, `worker_participant_gate.rb`, `worker_exit_claim.rb`) | A session's background process: builds the `Engine` and `Bridge`, runs queued turns and the wake turns nobody typed (delegate reports, a background task that finished unseen: [Finish wake](internals/background-tasks.md#finish-wake), attached context), exits when idle. A spawned one traps TERM, HUP and INT (`WorkerSignals`, installed by `WorkerBoot.run_session_loop` when `SAMAGOTCHI_WORKER_PROCESS=1`): the running turn stops as a Stop with reason `signal`, is saved, and the worker leaves (`:signal`, exit 0; a new worker only for input already queued). A running turn is checkpointed at its iteration boundaries (`TurnCheckpoint`, the `interrupted_turn` mark), and the next worker settles a turn its predecessor died in (`TurnCheckpoint.settle`). The session is saved from the turn's thread, Bridge threads and a signal's thread; `Session#save` takes a per-session lock around its snapshot and write, so an older snapshot never lands over a newer one. `WorkerParticipantGate` is the one seat for "may this participant act" (a queued turn as it starts, the drain, the mid-turn stop, the Continue: [internals/participants.md](internals/participants.md)); `WorkerExitClaim` is the exit claim (`POST /exit`): one lock for the kind being taken and the exit taken. Threads: the gate is loop-thread only (a turn runs on the loop; no lock), the claim is safe from any thread (its own mutex, taken after the event lock). The concerns are `include`d parts in `lib/samagotchi/worker/` (`Worker::LeavePart`: exit and leave; `Worker::WakeTurnsPart`: the turns nobody typed; `Worker::StartupPart`: the start-up settle; `Worker::SignalGracePart`: a signal's grace; `Worker::ScratchPart`: a scratch worker whose terminal left; `Worker::ChildSidePart`: a delegate child's rings, Verify fresh verdicts; `Worker::CommandQueuePart`: session commands between turns). `worker.rb` keeps the loop, the wiring, the prompt turns and the drain. They share Worker's ivars, and each header says what it writes and reads. |
655
+ | Worker | `worker.rb` (`worker_boot.rb`, `worker_idle_exit.rb`, `worker_inbound.rb`, `worker_signals.rb`, `worker_wakes.rb`, `worker_task_wakes.rb`, `task_watch.rb`, `worker_participant_gate.rb`, `worker_exit_claim.rb`) | A session's background process: builds the `Engine` and `Bridge`, runs queued turns and the wake turns nobody typed (delegate reports, a background task that finished unseen: [Finish wake](internals/background-tasks.md#finish-wake), attached context), exits when idle. A spawned one traps TERM, HUP and INT (`WorkerSignals`, installed by `WorkerBoot.run_session_loop` when `SAMAGOTCHI_WORKER_PROCESS=1`): the running turn stops as a Stop with reason `signal`, is saved, and the worker leaves (`:signal`, exit 0; a new worker only for input already queued). A running turn is checkpointed at its iteration boundaries (`TurnCheckpoint`, the `interrupted_turn` mark), and the next worker settles a turn its predecessor died in (`TurnCheckpoint.settle`). The session is saved from the turn's thread, Bridge threads and a signal's thread; `Session#save` takes a per-session lock around its snapshot and write, so an older snapshot never lands over a newer one. `WorkerParticipantGate` is the one seat for "may this participant act" (a queued turn as it starts, the drain, the mid-turn stop, the Continue: [internals/participants.md](internals/participants.md)); `WorkerExitClaim` is the exit claim (`POST /exit`): one lock for the kind being taken and the exit taken. Threads: the gate is loop-thread only (a turn runs on the loop; no lock), the claim is safe from any thread (its own mutex, taken after the event lock). The concerns are `include`d parts in `lib/samagotchi/worker/` (`Worker::LeavePart`: exit and leave; `Worker::WakeTurnsPart`: the turns nobody typed; `Worker::StartupPart`: the start-up settle; `Worker::SignalGracePart`: a signal's grace; `Worker::ScratchPart`: a scratch worker whose terminal left; `Worker::ChildSidePart`: a delegate child's rings, Verify fresh verdicts; `Worker::CommandQueuePart`: session commands between turns; `Worker::BlockFixesPart`: a failed block's fix, written between turns). `worker.rb` keeps the loop, the wiring, the prompt turns and the drain. They share Worker's ivars, and each header says what it writes and reads. |
656
656
  | Session lifecycle | `session_manager/`, `worker_boot.rb`, the session sidecar files | Marker writers, derived states, lock order, crash repair and the known open windows are mapped in [Session lifecycle](internals/session-lifecycle.md). |
657
657
  | Config | `config.rb`, `config/restart_watch.rb` | Every setting as an `Entry`: env, config.yml and CLI layers ([configuration.md](configuration.md)); the notice a worker or chi web gets when config.yml changes a setting it reads only at its start. With `log.rb` it is the bottom layer: nothing it references reaches back to it, so `hosts:` and `models:` entries parse next to their types (`HostConfig.all`, `ModelSettings.all`). |
658
658
  | Paths | `paths.rb` (`Paths`) | The XDG base dirs chi's files live under, read from the env on every call: `Paths.state_home` (`$XDG_STATE_HOME`, else `~/.local/state`) and `Paths.config_home` (`$XDG_CONFIG_HOME`, else `~/.config`), both defaults under `Dir.home`; a blank variable counts as unset, a relative one is made absolute from the current directory. `Paths.tilde` shows a path with `~` for the home folder. `SessionManager` hands a spawned worker the spawner's `XDG_STATE_HOME` / `XDG_CONFIG_HOME`, when set, made absolute, so a relative one isn't read from the session's folder. |
data/docs/bundles.md CHANGED
@@ -9,6 +9,10 @@ feature they belong to: **source-links** in [hooks.md](hooks.md#the-source-links
9
9
  every shipped bundle with code does; before known-names 0.2.0 and source-links 0.7.0 they shipped a `hooks/*.rb` file
10
10
  (chi no longer loads one: [hooks.md](hooks.md#class-file-hooks-are-retired); `chi update` removes the old file).
11
11
 
12
+ `chi bootstrap` installs the recommended `core` safety profile. If none of its members has an install record,
13
+ chi prints a reminder to stderr at a session or web launch, including a one-shot, once per state directory. See
14
+ [Bundle profiles](memory.md#bundle-profiles-core-and-dev).
15
+
12
16
  ## The btw bundle
13
17
 
14
18
  `chi bundle install btw` (or the `dev` profile) installs the bundle shipped with chi. It is written
@@ -1049,8 +1053,9 @@ Claude pairs; without one the bundle costs one tool declaration.
1049
1053
  - **The tool `claude_send(kind, title, text)`**, `kind` being `validate`,
1050
1054
  `context` or `question`, writes one JSON line to that socket. The message
1051
1055
  starts with a header, `chi <id> · <kind> · <title>`, and a second line,
1052
- `ref: <send id>` (`s-` and 6 hex, from the kind, title and text as given:
1053
- the same part sent again has the same id), which Claude's answer gives back
1056
+ `ref: <send id>` (`s-` and 6 hex, from the kind, title and text as given
1057
+ and the send itself: each send has its own id, the same part sent again
1058
+ too; an older chi's resend shared one), which Claude's answer gives back
1054
1059
  so chi can tie it to its send; the tool's row in the web carries the id too.
1055
1060
  A text up to 4,000 characters follows inline; a longer one goes to a file,
1056
1061
  `$XDG_STATE_HOME/samagotchi/plugins/claude-peer/sessions/<id>/<HHMMSS>-<slug>.md`
data/docs/cli.md CHANGED
@@ -774,7 +774,7 @@ worker; stopped 1 background task)`). `/archive` says the same and names
774
774
  `chi sessions archive --stop-tasks ID`; the web asks a second confirm. See
775
775
  [Sessions](sessions.md#archiving-a-session).
776
776
 
777
- `chi sessions delete [--force] [--chain] [--stop-tasks] ID...` deletes sessions for good: the
777
+ `chi sessions delete [--force] [--chain] [--stop-tasks] [--dry-run] ID...` deletes sessions for good: the
778
778
  session file and its whole directory (notes, images, queued input). Each id
779
779
  (or unique prefix) gets one line: `deleted`, or `refused` with the reason.
780
780
  Deleting a chain's newest link undoes its continue and says so (`… deleted;
@@ -782,8 +782,12 @@ the previous link 1a2b3c4d is back in the lists`): the previous link comes
782
782
  back, not started, with the delegates and notes that had moved on. `--chain`
783
783
  deletes every link of the session's chain with their delegates (a running
784
784
  delegate is left running), one line per link and a `chain: …` summary; a
785
- schedule on the chain refuses it. See docs/sessions.md (Session chains →
786
- Deleting a link). A
785
+ schedule on the chain refuses it. A plain delete takes the session's stopped
786
+ delegates with it too (archived ones as well) and says how many (`… deleted;
787
+ 2 delegates deleted with it; 1 left running: 9d0e1f2a`); a running delegate
788
+ keeps running on its own, with its subtree. A delegate that would go and is a
789
+ schedule's target, or in a one-turn run, refuses the delete. See
790
+ docs/sessions.md (Session chains → Deleting a link). A
787
791
  session whose worker runs is refused unless `--force` stops the worker first;
788
792
  one a `--non-interactive` run has is always refused ("in use by a one-turn chi
789
793
  --non-interactive run or an older chi's terminal; let it finish first"). A
@@ -797,7 +801,25 @@ running)`). `--stop-tasks` is not `--force`: a live worker is still refused
797
801
  without it. `/exit --delete` refuses the same way and names `chi sessions
798
802
  delete --stop-tasks ID`. Exit
799
803
  status: 0 when all are gone, 1 when any was refused or unknown, 2 on a usage
800
- error. The Web UI deletes too: `delete` in the info bar, or the ✕ on a card in
804
+ error.
805
+
806
+ `--dry-run` prints what the delete would do and deletes nothing: the rows the
807
+ web's delete sheet shows (`back`: the previous link an undo brings back;
808
+ `goes`: the links and stopped delegates; `stopped first`: its worker or running
809
+ turn, the background tasks, another session's with its id in front; `stays`:
810
+ the running delegates, and the tasks chi can't verify), each only when it
811
+ applies, and which of `--force` / `--stop-tasks` the real delete needs. With `--chain` it prints the chain's choice. `--force` and `--stop-tasks` are ignored in the print-only plan; it reports
812
+ which real-delete flags would be needed instead. An unknown id or an id that cannot be resolved exits 1 as a would-be
813
+ refusal too. A plan that would be refused prints `would be refused: <why>` instead and exits 1; otherwise it exits 0:
814
+
815
+ ```text
816
+ $ chi sessions delete --dry-run ab12cd34
817
+ ab12cd34 would delete "fix the flaky spec"
818
+ goes: 2 stopped delegates (9d0e1f2a, 77aa0b1c)
819
+ stopped first: its worker; 2 background tasks (npm run dev, rspec) — needs --force, --stop-tasks
820
+ stays: 1 running delegate (5c1b22e0), without a parent
821
+ ```
822
+ The Web UI deletes too: `delete` in the info bar, or the ✕ on a card in
801
823
  All sessions; it asks first and stops a live worker, and asks again, naming
802
824
  them, when background tasks still run (OK stops them).
803
825
 
@@ -1172,7 +1194,9 @@ A model that can see images gets them these ways:
1172
1194
  the photo library, and is hidden while a turn runs). Each shows as a chip (× removes it) and is sent with the
1173
1195
  message; an image alone is sent as `[image: name]`. A message takes up to 20
1174
1196
  images of up to 20 MB each; a toast names the files left out (over a cap, or
1175
- not an image). Messages show thumbnails; a click opens one full size.
1197
+ not an image). Messages show thumbnails; a click opens one in the
1198
+ picture viewer, fitted to the screen: pinch, Ctrl/Cmd + scroll or the bar's − + zoom, a drag or scroll moves, a
1199
+ double tap goes close and back, ✕ or Esc closes.
1176
1200
  - **`chi send --image PATH`** (repeatable, up to 20) with a message, from a
1177
1201
  script or another terminal: `chi send --image shot.png -m "why is this red?"
1178
1202
  3fa2`. The attached terminal and the web show it like an image typed there.
@@ -1409,10 +1433,13 @@ session bar shows the `mem N` chip again.
1409
1433
  (`--mute`) memories included; its dot lights when the set changed since you
1410
1434
  last opened it.
1411
1435
  - **The list** the three open (a bottom sheet on a phone): always the whole
1412
- session's set, files grouped by folder (a group opens in place), memories
1436
+ session's set, last touched first, files grouped by folder (a group opens in place), memories
1413
1437
  (used, preloaded, muted) and URLs, each with what was done to it (`read ×2`,
1414
- `read, edited`, `preloaded`) and a step tag (`t2·s3`, `prompt` for a preloaded
1415
- memory) that goes to the call. The header's `session | ‹ turn N ›` is a lens:
1438
+ `read, edited`, `preloaded`) and a step tag (`t2·s3`: where it was last touched; `prompt` for a preloaded
1439
+ memory) that goes to that call. The order is taken when the list opens and holds while it is open: what chi
1440
+ touches meanwhile comes in on top, the other rows stay put. With the session's prompt parts known, "Read in
1441
+ this session" comes first, then the conversation's row, then "From the start" (the system prompt's parts),
1442
+ folded to one line (with its `held twice` count) until you open it; a fold you set is kept for the session. The header's `session | ‹ turn N ›` is a lens:
1416
1443
  the chip opens the session, a footprint or the rail opens a turn, and `‹` `›`
1417
1444
  step through the turns. In a turn's lens the rows that turn touched are lit,
1418
1445
  with that turn's words and step tag (`s3`), the others dimmed; the line under
@@ -1440,11 +1467,13 @@ session bar shows the `mem N` chip again.
1440
1467
  stage's rail shows an add queued for its end as a dashed `+ name · next turn`
1441
1468
  line.
1442
1469
  - **What chi has of an item**: a row's `▸` in the list peeks at it (its latest edit's diff, else its newest
1443
- read's first lines); `Open the timeline` (also a tool row's `timeline` and a file ref's ▾ `What chi has`) puts
1444
- the item's timeline over the stage, newest first: reads merged into line slices over a strip of the file, edits
1445
- as diffs, what chi no longer has greyed (with `undrop` for your drop), a changed memory's `Now · diff`. `← Stage`
1446
- or Esc goes back to the same place, ↑↓ step through the set; on a phone it is full screen (`‹ Set`, `‹ ›`).
1447
- Yours only: a participant's list has no `▸`.
1470
+ read's first lines, or a memory or a whole `.md` file rendered); `Open the timeline` (also a tool row's
1471
+ `timeline` and a file ref's ▾ `What chi has`) puts the item's timeline over the stage, newest first: reads merged
1472
+ into line slices over a strip of the file, edits as diffs, what chi no longer has greyed (with `undrop` for your
1473
+ drop), a changed memory's `Now · diff`. A memory and a whole read of an `.md` file show as rendered markdown (a
1474
+ leading front matter as source above it), with a `rendered | source` switch on the card; a slice of a file stays
1475
+ numbered source, and with markdown off everything is source. `← Stage` or Esc goes back to the same place, ↑↓
1476
+ step through the set; on a phone it is full screen (`‹ Set`, `‹ ›`). Yours only: a participant's list has no `▸`.
1448
1477
 
1449
1478
  Only `read`, `edit`, `write`, `memory_read`, `memory_write` and `web_fetch`
1450
1479
  calls that succeeded count; files an `execute` touched don't.
@@ -1677,6 +1706,10 @@ CHI_REMOTE=studio chi context push claude-outbox ab12 < answer.json
1677
1706
  an older one deletes or archives as it always did. A new chi web answers an
1678
1707
  older CLI's delete or archive of a session whose tasks run with 409
1679
1708
  `tasks_running`, which that CLI prints as a failure.
1709
+ - `sessions delete --dry-run` needs a chi web there that lists the
1710
+ `delete_plan_all` feature; an older one is refused before anything is asked
1711
+ (update and restart chi web there), since its plan would leave out a plain
1712
+ session's delegates.
1680
1713
  - A remote that can't be reached names itself and why (`chi send: remote
1681
1714
  studio (http://192.168.1.29:4567): connection refused`, exit 1; with
1682
1715
  `--format json` an `error` object).
@@ -151,7 +151,7 @@ or `chi web` restart.
151
151
  | `default.input`, `no_default_input`, `no_interrupt` | Next CLI run | These set up that run's first prompt or turn limit. |
152
152
  | `default.max_tokens`, `max_tool_output_chars`, `memory.read_max_chars`, `read.*`, `execute.*` except `execute.description`, `image.*` | Next matching request or tool use | An operation already in progress keeps its resolved limits. |
153
153
  | `server.host`, `server.port`, `hosts.*` | Worker start | Includes host addresses, APIs, declared models and host-level settings. Commands (`chi self`, `chi models`, the session lists) and chi web (its model picker, the session cards) read `hosts:` as it is now; a running worker keeps the hosts it started with until it restarts. |
154
- | `server.open_timeout`, `server.read_timeout`, `server.first_token_timeout` | Worker start | The worker's clients retain the timeouts set when they were built. |
154
+ | `server.open_timeout`, `server.read_timeout`, `server.first_token_timeout`, `server.stream_idle_timeout` | Worker start | The worker's clients retain the timeouts set when they were built. |
155
155
  | `model_aliases` | Next model lookup | A session keeps its resolved model unless it is explicitly switched. |
156
156
  | `models.<key>.profile` | Session start or `/model` | It is resolved when that model is selected; editing it does not switch the current model's profile by itself. |
157
157
  | Other `models.<key>.*` settings | Next turn or model lookup | Sampling, thinking, vision, context, window, price and steer settings are resolved from the file for their next use. |
@@ -352,8 +352,8 @@ doesn't end in a local suffix (`gpu.example.com`). A name without a dot (`box`)
352
352
  or ending in `localhost`, `.local`, `.lan`, `.home`, `.home.arpa`, `.internal`,
353
353
  `.intranet`, `.localdomain`, `.private`, `.corp`, `.test`, `.box` (`fritz.box`)
354
354
  or `.ts.net` (Tailscale) is local: chi doesn't look names up. A remote
355
- host keeps its model list for 10 minutes, gets a 120-second first-token limit,
356
- and isn't asked for llama.cpp's `/props` (its context window and served model
355
+ host keeps its model list for 10 minutes, gets a 120-second first-token limit
356
+ and a 120-second stream-idle limit, and isn't asked for llama.cpp's `/props` (its context window and served model
357
357
  come from its model list and each turn). A local `api: openai` host has no
358
358
  `/props`, so `chi self` GETs its `/models` with the same short probe timeouts
359
359
  and reports up/down with the ids it serves. `remote: true` or `remote: false` on a
@@ -919,6 +919,24 @@ hosts:
919
919
  which applies to every host. With neither set, remote hosts (see "Remote or local" above) get 120 seconds and local
920
920
  servers no limit: a long prompt evaluation is normal there, and the read timeout catches a dead server.
921
921
 
922
+ Once a stream has shown something, a **stream-idle limit** watches the rest: the seconds it may go without showing
923
+ more text, reasoning or a tool call. Keep-alive comments don't count, so an answer that stops mid-way is no longer
924
+ held open until the read timeout. A stalled stream is closed and asked again like a dropped one (`↻ retrying
925
+ (stream dropped) …`, its partial output dropped; see "Retries" below); once those run out the turn fails with `the
926
+ model's stream stalled on host <name>: no output for 120s (stream_idle_timeout); …`. The end of an answer (a finish
927
+ reason, the usage chunk, Anthropic's `message_delta` and `message_stop`) restarts the clock too, so a slow trailing
928
+ usage chunk doesn't void a complete answer.
929
+
930
+ ```yaml
931
+ hosts:
932
+ openrouter:
933
+ stream_idle_timeout: 300 # seconds; 0 = off
934
+ ```
935
+
936
+ `hosts.<name>.stream_idle_timeout` wins over `server.stream_idle_timeout` (`SAMAGOTCHI_SERVER_STREAM_IDLE_TIMEOUT`),
937
+ which applies to every host. With neither set, remote hosts get 120 seconds and local servers no limit: a local
938
+ server may stream nothing while it buffers a long tool call's arguments.
939
+
922
940
  Every chat request carries the session's id as a `Session-Id` header (next to `User-Agent: chi/<version>`). A
923
941
  gateway that spreads requests over several providers can key on it to keep one conversation on one provider, so
924
942
  prompt caches hit and every turn is answered by the same model. Servers that don't know the header ignore it.
@@ -1114,7 +1132,8 @@ Transient network failures are retried automatically with exponential backoff.
1114
1132
  chat loop (an OpenAI-compatible host) drops the partial reply and asks again for the whole step, from the same
1115
1133
  conversation, at most twice (at most `retry.max` times when that is smaller: `retry.max: 0` turns it off), after
1116
1134
  the same backoff, reported as a retry (`↻ retrying (stream dropped) …`); once those run out the turn fails with
1117
- the error, as before. A refusal, a first-token timeout, a provider error and a cancel are never retried this way.
1135
+ the error, as before. A stream that stalled past its `stream_idle_timeout` is asked again the same way. A refusal,
1136
+ a first-token timeout, a provider error and a cancel are never retried this way.
1118
1137
  - Cancellation (`Ctrl-C`) is never retried.
1119
1138
 
1120
1139
  Configuration:
@@ -2247,6 +2266,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
2247
2266
  | `server.open_timeout` | `10` | yes | Connection timeout, seconds. |
2248
2267
  | `server.read_timeout` | `600` | yes | Read timeout, seconds. |
2249
2268
  | `server.first_token_timeout` | 120 remote, off local | | Seconds to the first token; `0` = off. `hosts.<name>.first_token_timeout` wins. |
2269
+ | `server.stream_idle_timeout` | 120 remote, off local | | Seconds a stream that showed something may go without more; `0` = off. `hosts.<name>.stream_idle_timeout` wins. |
2250
2270
  | `recap.enabled` | on | | `false` (or `recap: false`) turns the idle recap off. Per session too: `--set recap.enabled=false`, or `/recap off` in the session (see "Per-session settings"). |
2251
2271
  | `recap.model` | session's | yes | Model that writes the recap: an id, alias or `host:model` (the host then picks where to ask; a bare id goes where a bare `--model` goes). |
2252
2272
  | `recap.host_ref` | session's | yes | A `hosts:` name to ask (`host:` is accepted too, also a host name, not a model ref). |
@@ -2385,6 +2405,7 @@ column says so, a `--kebab-name` flag. The maps (`hosts:`, `models:`,
2385
2405
  | `web.working_set` | `true` | yes | The stage view's working set: the files, memories and URLs a turn brought into the model's context, in a rail in the stage, a footprint as each finished turn's block summary and a `set N` chip in place of the mem chip; `false` brings the mem chip back. `?working_set=1` or `?working_set=0` on the page URL overrides it for that page load. See [CLI: the working set](cli.md#the-working-set). |
2386
2406
  | `web.stage_collapsed` | `false` | yes | Every session's stage in `chi web` starts folded to its status row (the running turn's prompt, steps and cloud behind ▴), a participant's page too. A session you fold or unfold by hand keeps its own fold in that browser (`chi_stage_collapsed:<session>`), whatever this says; one never touched follows it. Read when `chi web` starts: restart it after a change. |
2387
2407
  | `web.reload_check` | `false` | yes | Opt-in: once each finished turn has moved into the history, the page reads the session again (one full read per turn end), draws that turn as a reload would and compares the two, strictly: a known divergence counts as a mismatch too. `chi web` logs one `reload_checked` line per check and a `reload_mismatch` line naming the kinds that differed, `excused` (the known divergences, `history_shape.js` `ACCEPTED`, that would explain them) and `explained` (all of them had one), with `turn_id`, `drawn` (the turn came back from its drawing, so a mismatch with `drawn: true` is a drawing bug), `undrawn` (how many of the reload's rows came without their turn's drawing, the page's plain fallback: 0 unless chi web missed a turn) and the worker's version: counts only, never content. The count is `grep -c reload_mismatch` over `grep -c reload_checked` in chi web's log, split by `excused`. The turn's own cards and questions are compared as data, apart from the history: what the page's stream said (`card_registry.js`) against what the read lists (CardStore), each card or question of this turn (`of_turn`) by its id, its kind, its status (answered, cancelled, still asking) and its summary line (a card's title); a difference counts as `card` or `question`. Bodies, buttons, folds, the tag a card is drawn in and where it sits are ignored (the history's compare leaves cards and questions out on both sides; their place is the specs'). A read that lists CardStore's cap of cards and questions may have lost an older one: a card the page has and such a read doesn't is no difference. A question the read gives no turn and no opening stamp for (an older worker) leaves the questions out. A page whose `app.js` is older than its `reload_check.js` (a mixed cache) compares no cards: its `reload_checked` line says `cards_compared: false`. Between-turn cards and notices stay with the e2e reload checks. Every open owner tab runs the check; `chi web` logs a turn's first report only, and starts over when it restarts. |
2408
+ | `web.block_fix` | `auto` | | `auto`: a fenced block the owner's page can't draw in the newest answer (a `chi-ui` picks or walk, a bundle's diagram such as Mermaid) is asked for again, once, as a side request (no turn, no message; it shows as `block-fix` in `/stats`' side line). The fixed block draws in place, with "Drawn after a fix" under it, and the saved answer holds it, so the model's next turn sees it too (or only the page, when a turn started meanwhile). A fix that doesn't draw either, an older answer, and the third block of an answer get an "Ask in chat" button that fills the composer. `off`: the block stays source under its error line, as before, and `POST /api/sessions/:id/blocks/fix` answers `404`. Read when `chi web` starts. See [block-renderers.md](internals/block-renderers.md#a-failed-block-is-asked-for-again). |
2388
2409
  | `web.annotate_presets` | `Agreed\|Could you please elaborate?` | yes | Quick replies next to Annotate in `chi web`, `\|`-separated (a YAML list works too); `""` in the file or on the CLI leaves only Annotate (an empty env value means the default). See [CLI](cli.md#web-annotate-presets). |
2389
2410
  | `web.editor` | `vscode` | yes | What a file ref in `chi web` (a file tool row's title, a diff line) opens, for a viewer on this machine: a preset (`vscode`, `vscode-insiders`, `cursor`, `zed`) or a URL template with `{path}` and an optional `{line}`; `none` turns refs off. See [Opening files from chi web](#opening-files-from-chi-web). |
2390
2411
  | `web.start_dir` | the folder `chi web` runs in | | The folder `chi web` starts in (`chi web --start-dir DIR` for one run): its page (the printed link, a bare `/`, the LAN link and QR code, the Home Screen app) opens on that folder's project, outside a project (no repository or marked folder) on every session, and a new session from the all view starts there; the header's project picker switches projects. `~` and a relative path (resolved from your home folder) work; one that isn't a folder stops `chi web` from starting. `chi web` never changes its own folder. See [CLI](cli.md). |
@@ -15,7 +15,7 @@ ChatLoop::Run#generate
15
15
  → AnthropicWire.translate # system blocks + messages, cache_control placed
16
16
  → AnthropicWire.tools # function schemas → {name, description, input_schema},
17
17
  # a deferred one with defer_loading: true
18
- → POST {base}/v1/messages # LLM::HTTP: retries, cancel, first-token limit
18
+ → POST {base}/v1/messages # LLM::HTTP: retries, cancel, first-token and stream-idle limits
19
19
  → AnthropicAssembly#add per SSE event # → ChatResponse (text, reasoning, tool_calls, usage,
20
20
  # finish_reason, provider_content)
21
21
  → a signature 400 (Claude 5.x preserved thinking): AnthropicBindingRecovery#advance, then the same
@@ -90,8 +90,9 @@ A stream is read from its `data:` lines alone (a gateway that drops the `event:`
90
90
  index: `message_start` (served model, usage), `content_block_start` (text, thinking, redacted_thinking, tool_use),
91
91
  `content_block_delta` (`text_delta`, `thinking_delta`, `signature_delta`, `input_json_delta`), `message_delta`
92
92
  (stop reason, `stop_details`, usage). `AnthropicMessages#chat_streamed` passes every event but `ping` to `on_delta`,
93
- `message_start` and `message_delta` with the usage so far attached (`#with_usage`); a block's start or delta counts as shown for the first-token limit
94
- (`.shows?`). A 200 whose body is a JSON error instead of a stream raises that error (`LLM::AdapterCommon#raise_plain_error`, shared with the OpenAI adapter).
93
+ `message_start` and `message_delta` with the usage so far attached (`#with_usage`); a block's start or delta counts as shown for the first-token and stream-idle limits
94
+ (`.shows?`); `message_delta` and `message_stop` restart the stream-idle clock without counting as shown (`.ending?`), so a
95
+ slow end of a complete answer doesn't stall it. A 200 whose body is a JSON error instead of a stream raises that error (`LLM::AdapterCommon#raise_plain_error`, shared with the OpenAI adapter).
95
96
 
96
97
  `#response` is a `ChatResponse`:
97
98
 
@@ -29,6 +29,8 @@ Behavior:
29
29
 
30
30
  - `execute`, `task_create` and the `!cmd` shell bang run the command in a non-login shell: `/bin/sh -c` on Linux; on macOS, when `/bin/zsh` is there, `/bin/zsh --emulate sh +o ignore_braces +o sh_glob -o bash_rematch +o bsd_echo -c` (macOS's `/bin/sh` is bash 3.2, which can't parse an apostrophe in a heredoc inside `"$( )"`, the usual commit message shape). That mode reads no rc files and keeps POSIX word splitting, unmatched globs left as is, `{1..3}`, `[[ … =~ (…) ]]` with `BASH_REMATCH`, arrays, `$'…'`, `&>` and echo expanding `\t`. Bash-only builtins and variables (`shopt`, `BASH_VERSION`, `${!prefix*}`, `read -p`) are not there.
31
31
  - Task metadata and output are persisted under `tmp/tasks/`: each task's `tmp/tasks/<id>/task.json` is a `TaskRecord` (`lib/samagotchi/tools/task_record.rb`, a value object: `.from_file` reads it, `#to_file` is the JSON object written, an update is a `#with`). Its keys keep their order; `stderr_path` and `handed_over_by` (a handed-over execute), `stop_requested_by` (a stop under way or done) and `leftovers` (`stopped` or `detached`: what the shell left holding the log, below) are left out until set. `bundles/slow-commands` reads these files on its own, so the shape is a contract.
32
+ - When a task is created in a git worktree, chi adds its `tmp/tasks/` path relative to the repository root to the
33
+ common git directory's `info/exclude`, once. An error is logged and does not prevent the task from starting.
32
34
  - A task record keeps its process's pid and start time (`pid_started`). Before `task_stop` signals, the pid must still lead its own process group and must not have started at another time; otherwise the pid was reused by another process, nothing is signalled and the task ends as failed. A start time that can't be read at that moment (a failed `ps`) falls back to the group check, as does a record without `pid_started` (from an older chi). `task_get`, `task_list`, `task_wait`'s polls and the running-task lists (a cancelled turn's note, a worker's restart hold, the finish wake's watch) make the same check, so a task whose pid was reused reads as exited (failed) at once, not as running until a `task_stop`; on macOS that is one `ps` per running task per check (~5 ms).
33
35
  - A stop (`task_stop`, the user's Stop of an `execute`, the execute limit in kill mode) TERMs the task's process group, then KILLs it after a grace. The groups its processes started are stopped too: a GNU `timeout N cmd` (without `--foreground`) moves itself and its command to a group of its own. `ProcessGroup.stop` finds them with one `ps -A -o pid=,ppid=,pgid=` (~40 ms on macOS) before the TERM and again before the KILL, walking down from the group's members. A process whose parent already exited (reparented to init, e.g. a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` after its shell exited) is not found by that walk; one still in the task's group is stopped by the leftover rule below, so only one outside the group runs on: a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` (GNU `timeout` moves to a group of its own). Holding the task's log, it is reported detached.
34
36
  - Task listing is workspace-scoped (current project only).
@@ -25,8 +25,8 @@ model. The TUI is untouched: it shows a fence as source.
25
25
  the first that `claims` the block's language draws it, and a language none claims is left alone. The contract
26
26
  (`claims`, `needsDraw`, `draw`, its `reconsider`, `sessionChanged`) is in the module's header. The shared DOM
27
27
  helpers live there too: `failBlock` and its `.block-note` (a click copies it), `holdingView`, `rejoin`, the
28
- toggle's listener; frames, the cache, hang marks, size checks, the zoom and the theme redraw stay in
29
- `block_host.js`. One `MutationObserver` per turn root,
28
+ toggle's listener; frames, the cache, hang marks, size checks, the click that opens the picture viewer and the theme
29
+ redraw stay in `block_host.js`. One `MutationObserver` per turn root,
30
30
  filtered to `TEXTS` (`text_roots.js`), so cards, a lead-in bubble, question replies and delegate reports never draw, and
31
31
  every path that adds a block to a root is seen the same way. One `IntersectionObserver` per scroller, with an explicit `root`
32
32
  (with `root: null`, `rootMargin` doesn't pass an `overflow: auto` in between). Closed `<details>` fire on open. **A
@@ -42,9 +42,12 @@ model. The TUI is untouched: it shows a fence as source.
42
42
  shows, never markup, and not in the bubble's `textContent`, which the page's dedupe and an annotation read (`copy.js`'s rule). CSS content can't be selected, so a click on the line copies its words.
43
43
  The toggle has an icon and an `aria-label`, no text (`copy.js`'s rule). A jump into the source shows it (`revealInHistory`).
44
44
  For a screen reader: the hidden `<pre>` isn't read, so the `<img>`'s alt names the toggle that shows it ("mermaid
45
- diagram, its source under the Show the source button"). The natural size, a click on the picture, is also a
46
- `.block-zoom` button (icon, `aria-label`, `aria-pressed`) for the keyboard: before the toggle, shown on keyboard focus
47
- only, and taking no pointer while hidden, so the mouse's view is as it was.
45
+ diagram, its source under the Show the source button"). In the answer the picture is always fitted to the column. A
46
+ click on it opens the page's picture viewer (`createBlockHost`'s `openPicture`, app.js's `picture_viewer.js`;
47
+ [web-frontend.md](web-frontend.md#picture-viewer)) with its `data:` URL and its size from the viewBox, zoomable and
48
+ movable there; without `openPicture` (an older app.js) a click does nothing. The same is a `.block-zoom` button
49
+ ("Open in the viewer": icon, `aria-label`) for the keyboard: before the toggle, shown on keyboard focus only, and
50
+ taking no pointer while hidden; Esc in the viewer gives it the focus back.
48
51
  6. Cache: a `Map` on `lang + theme + source`, about 200 entries, holding the `data:` URL; a later `bubble.innerHTML` wipes the
49
52
  figure and the observer redraws in the same pass. No `crypto.subtle`: it's undefined on a plain-http LAN address. A system
50
53
  theme change redraws through the figure (a hidden `<pre>` never intersects).
@@ -57,9 +60,123 @@ model. The TUI is untouched: it shows a fence as source.
57
60
  from `DOMParser`, never a regex over model-influenced XML (exponents, a comment holding `<svg`, a `>` in an attribute, entities and
58
61
  prefixes all fooled one), and a vast one isn't decoded. Then the decoded size is checked: over the maximum, or a width or
59
62
  height of 0 (WebKit's 0 x 150 for a viewBox it can't hold), the block stays source with its line. `.block-img`'s CSS
60
- `max-height` and natural `max-width` say the same number, a backstop whatever the parsing gets wrong. The decode is bounded too
63
+ `max-height` says the same number, a backstop whatever the parsing gets wrong. The decode is bounded too
61
64
  (15 s, the mark on until it ends). A very wide picture stays at least 120 px tall and scrolls sideways instead of a sliver.
62
65
 
66
+ ## A failed block is asked for again
67
+
68
+ One mechanism for every drawn block, a `chi-ui` picks or walk (core's drawer) and a bundle's renderer (chi-mermaid's
69
+ `mermaid`): a block the owner's page can't draw **in the newest answer**, for a reason that is the model's (a refused
70
+ `chi-ui` block, a renderer's own `error`), is asked for once more as a side request, and the answer is patched. No
71
+ message is sent and no turn runs. `web.block_fix: off` ([configuration.md](../configuration.md)) is the page as before:
72
+ the web route answers `404` instead of relaying a block fix.
73
+
74
+ ```
75
+ page: a drawer fails a block in the newest answer, marked fixable
76
+ └─ POST /api/sessions/:id/blocks/fix {turn_id, lang, source, reason} (chi web, :owner: Web::BlockFixRoutes)
77
+ → Bridge POST /session/:id/blocks/fix (Bridge::BlockFixRoute) → Engine#fix_block
78
+ ├─ the answer's stamp knows this block → 200 {state: "fixed" | "failed"}
79
+ └─ else 202 {state: "running"}; a side thread asks the model, checks the answer,
80
+ queues the result and wakes the worker's loop
81
+ worker loop, between turns (before any queued prompt): Engine#apply_block_fixes
82
+ └─ patches the answer (its text, or its display), stamps it, saves, announces :block_fix
83
+ page: on :block_fix → re-reads that answer; the patched block draws as any block
84
+ reload: the answer is the patched text; the render marks the block from the stamp
85
+ ```
86
+
87
+ **The request** (`BlockFix.request`, `Engine::BlockFixPart`): `ask_side_model`, as `/btw` and ctx.ask_model, on the
88
+ session's model: the conversation up to and including the answer as the side transcript (`Plugin::SideQuestion`, its
89
+ last 32,000 characters; display-only keys gone), then the failed block, its language and its error (cut to 300
90
+ characters, in the user part only). `BlockFix::SYSTEM` asks for the corrected block only, in one fence; for `chi-ui` the
91
+ schemas follow (`InlineWidgets::FIX_RULES`: core can't read the inline-widgets bundle's prompt sections). No tools,
92
+ thinking off, 25 s, 6,000 tokens out. It shows as `block-fix` in `/stats`' side line, always the owner's.
93
+ `BlockFix.extract` takes the first fence of the answer (else the whole answer); it is refused when the answer was cut
94
+ off at its limit, empty, the same block, or over 16 KB, and a `chi-ui` fix must parse (`BlockFix.check`). Any other
95
+ language passes: only the page can draw it.
96
+
97
+ **Where the block is** (`BlockFix.locate`, `locate_all`, `replace`, `replace_all`): commonmarker, the page's render's
98
+ parser (`MarkdownParser` loads it for the render and the worker), walks the `code_block` nodes; each in that language
99
+ whose normalised source is the block's is a copy of it (an answer may repeat a block: a fix patches every copy, so none
100
+ is left to fail and be asked for again), and its `source_position` gives its body's lines. `replace` keeps the fence lines and gives each
101
+ new line the old body's indent (a list item's) and the text's own line ends. A block in a blockquote isn't fixed (its
102
+ lines carry `> `). A block's identity is `BlockFix.key`: SHA-256 of the language and the normalised source, 32 hex
103
+ characters.
104
+
105
+ **The route's answers** (`Engine#fix_block`): 409 `fix_unavailable` (no session, a scratch one, no commonmarker), 413
106
+ `block_too_large` (over 16 KB), then the turn's answer (`AnswerTail.find` by turn id; none: 409 `block_not_found`) and
107
+ **its stamp before its text**: 200 with the stamp's state when the stamp knows the block, even when the block is no
108
+ longer in the answer (a page that drew the answer before its fix, a second tab: `fixed`, and it reads the answer
109
+ again); a block that is a fix and fails again, or a `fixed` block still in the shown text (a copy no fix reached),
110
+ answers `failed`, never `fixed`, so a page can't redraw and ask again. Then 409 `block_not_found` (the source isn't a
111
+ block of the answer), 202 `running` while that answer's block is asked (in flight per answer and block: the same block
112
+ in a newer answer is that answer's own ask), 429 `fix_limit` past 2 blocks of one answer (`BlockFix::PER_ANSWER`: its
113
+ stamp and its asks in flight or waiting, so a reload's page can't ask for a third), 429 `fix_busy` past 2 in flight
114
+ (`MAX_RUNNING`). The answer is resolved once, there: the result carries its **anchor** (its index in the conversation, its digest as `Bridge::TurnDrawings`
115
+ computes one, and the turn counter: `Engine#turn_messages` counts each turn).
116
+
117
+ **The write: on the worker's loop, between turns, never from the request's thread.** A running turn holds its own copy
118
+ of the conversation and writes it back at its end. `Worker::BlockFixesPart#apply_block_fixes` runs in each pass that
119
+ runs the queued commands, after them and before the notes and the next prompt (the idle pass and each input file's
120
+ step); the result's thread wakes the loop (`Engine#block_fix_ready=`, `Waker#wake`). Under the event lock, four
121
+ outcomes:
122
+
123
+ - **No turn started since the ask, and the answer is still the newest** (`AnswerTail.find`; notes, a `!cmd` line and
124
+ `/continue no` land after an answer without a request, so "the last message" isn't the test): its `content` is
125
+ patched, its `display` too when a hook set one, and on `api: anthropic` its saved blocks (`anthropic_content`, which
126
+ `AnthropicWire#assistant_blocks` sends as they are): the text block that holds the block whole, else the blocks are
127
+ dropped and the answer goes as its text. A thinking block is never touched (with the blocks dropped, the answer's
128
+ thinking blocks go with them: the `thinking` text stays on the message, a final answer with no `tool_use` is valid
129
+ without them, and `ReasoningHistory.earlier_thought?` reads `thinking` too). The next turn sends the patched answer.
130
+ A fix asked as its own turn ends (the page asks on the end event, before the turn's hooks are done) counts as no turn
131
+ since.
132
+ - **A turn started since** (or was running at the ask): only `display` (`AnswerDisplay::KEY`, what the page renders in
133
+ place of `content`; never sent to a model). No message a model has been sent is rewritten, so no prompt cache is
134
+ invalidated.
135
+ - **The answer is still there but the fix can't land** (the block left its shown text, say a hook's new display; or the
136
+ patched display would pass `AnswerDisplay::MAX_CHARS`, on either path): the block is stamped `failed` with the
137
+ reason ("the answer changed", "the fix is too long"), so a reload doesn't ask again.
138
+ - **The answer is gone** (its digest changed: a rollback, a new text; the turn id now names another answer: a reminder
139
+ turn's id names no prompt, so it falls back to the newest answer): the fix is dropped (`state: "dropped"`), no stamp.
140
+
141
+ A fix in an answer's text moves its digest; the engine keeps the move (`@block_fix_moved`), so the answer's other
142
+ block, asked before that fix landed, still finds its answer (and its event's `was_digest` is the digest it patched).
143
+ The move map is capped at `MOVED_DIGEST_LIMIT = 64`: the oldest move is evicted, so a fix landed after 64 later
144
+ text-changing moves no longer finds and patches the older answer.
145
+
146
+ A failed ask stamps the answer only. Each outcome is one `Log.info(:model, "block_fix_<state>", lang:, key:, bytes:, ms:,
147
+ landed:, reason:)` line (never the source) and one `:block_fix` event (`turn_id`, `key`, `lang`, `state`, `landed`,
148
+ `reason`, and the answer's digest before and after: `was_digest`, `digest`). A participant never gets it
149
+ (`ParticipantView::DROPPED`). A pending result doesn't keep a worker alive: an idle exit or a stop loses it, and the
150
+ page's give-up shows "Ask in chat".
151
+
152
+ **The stamp** (`BlockFix::STAMP`, `block_fixes` on the answer's model message: `{key, fixed_key, state, reason, at}`
153
+ per block asked) is display only (`AnswerDisplay::DISPLAY_ONLY`) and rides both loops' allowlists (`ChatLoop#plain`,
154
+ `KernelLoop#sanitize_history`). It is why nothing is asked twice: a reload, a second tab and a re-rendered bubble get the
155
+ stamp's answer. `Web::MarkdownRenderer#render(block_fixes:)`, from `MessageDisplay`'s answer render only, marks a block
156
+ that is a fix `data-block-fixed` and one whose fix failed `data-block-fix-failed`; an unstamped answer's HTML is as
157
+ before.
158
+
159
+ **The page** (`block_fix.js`, `block_fix_note.js`; [web-frontend.md](web-frontend.md#a-failed-block-asked-for-again)):
160
+ a block failed by the model's input (a refused `chi-ui` block, a renderer's own `error`: `FrameError.renderer`) is
161
+ marked fixable; a failure that isn't the model's (the renderer didn't load, a hang, a timeout, over 64 KB, a picture
162
+ too large) keeps today's line, with no button. In the newest answer the line reads "· asking for a fix…" with a
163
+ pulsing dot; the fixed block draws as any block, with "Drawn after a fix" under it. A fix that didn't help says so
164
+ with an **Ask in chat** button (it fills the composer with "The X block in your answer didn't draw: reason. Please
165
+ send it again, corrected."; never sends), as does an older answer's failed block and an answer's third. A live worker
166
+ without the feature (`workerPredates`, with the store's `bridgeUp`): "· restart this session to fix"; a worker that
167
+ isn't up is asked, and chi web's 503 `not_live` gives the plain line. An answer is read again at most once per block
168
+ for the page's life, so a copy still failing after the redraw says a fix didn't help. The terminal and a participant's page show nothing new.
169
+
170
+ **The turn's drawing.** A patched `content` changes the digest the turn's drawing line ends on (`TurnDrawings#holds?`),
171
+ so the Bridge's `TurnDrawings` (an observer of `:block_fix` with `landed: "answer"`) writes that turn's line again with
172
+ the new end digest, when the old one ended on the answer as it was (`was_digest`). A `display` patch keeps the digest.
173
+
174
+ **What a content patch costs**: nothing on a remote prefix cache or on Anthropic's Messages API (the cached prefix ends
175
+ before the answer); on llama.cpp the slot re-evaluates from the patched block, a few hundred tokens, and the turn-end
176
+ warm-up's gain is lost for that one turn ([prompt-caching.md](prompt-caching.md#the-turn-end-warm-up)). A `!rollback` or
177
+ a canceled Continue can restore a checkpoint from before the patch: the answer comes back unpatched and unstamped and may
178
+ be asked for once more.
179
+
63
180
  ## Security model
64
181
 
65
182
  The bundle's JS is trusted (installing a bundle already means trusting it, [plugins.md](../plugins.md#trust)). **Its input
@@ -426,6 +426,15 @@ The Bridge exposes:
426
426
  `200`, or `409` when it is no longer pending.
427
427
  - `POST /session/:id/guardrails/wrong` — `{id}`: label this session's System 1 auto-allow as
428
428
  one it should have asked about; `200`, `404` for an unknown judgment, `409` if already labelled.
429
+ - `POST /session/:id/blocks/fix` — `{turn_id, lang, source, reason}`: ask again, once, for a block the owner's page
430
+ couldn't draw in that turn's answer (`Bridge::BlockFixRoute` → `Engine#fix_block`; web route `POST
431
+ /api/sessions/:id/blocks/fix`, `Web::BlockFixRoutes`). `400 missing_fields` without a turn id, a fence language
432
+ (`BlockRenderers::LANG`) or a source, or `400 invalid_json` for a non-object body; `200 {state: "fixed" | "failed",
433
+ reason?}` when the answer's stamp knows the block, `202 {state: "running"}` while it is asked,
434
+ `404` for a worker or web route whose `block_fix` feature is off, `409 fix_unavailable` / `block_not_found`,
435
+ `413 block_too_large`, `429 fix_limit` / `fix_busy`. The result lands between turns and is announced as `:block_fix` (a `state` event; never a
436
+ participant's); a fix that patched the answer's text writes its turn's drawing line again with the new end digest
437
+ (`TurnDrawings#call`). See [block-renderers.md](block-renderers.md#a-failed-block-is-asked-for-again).
429
438
  - `POST /session/:id/holds/stop` — stop those holds without the worker leaving; `200 {status: "stopped",
430
439
  session_id, stopped}` or `501 holds_unavailable`.
431
440
  - `POST /session/:id/tasks/stop` — `{task_id}`: stop a background task as the user
@@ -666,6 +675,7 @@ compatibility from its version. `Bridge::FEATURES` advertises:
666
675
  | `cancel_turn_id` | `POST /session/:id/cancel` can stop only the named turn. |
667
676
  | `participant_revise` | chi web can pass a participant's Revise draft for worker-side validation. |
668
677
  | `participant_client_id` | chi web can identify a participant as `participant:<id>` instead of using the legacy `review:<id>`. |
678
+ | `block_fix` | `POST /session/:id/blocks/fix` asks again for a block the page couldn't draw; the owner's page without it says "restart this session to fix". |
669
679
  | `working_set_item` | `GET /session/:id/working_set/item` answers one item's timeline (the running turn's mid-turn), so chi web asks for it instead of the whole snapshot. |
670
680
 
671
681
  `chi web`'s `GET /api/sessions/:id/stream` proxies this bridge