samagotchi 0.55.0 → 0.57.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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +65 -1
  3. data/README.md +1 -1
  4. data/docs/architecture.md +6 -2
  5. data/docs/cli.md +30 -8
  6. data/docs/configuration.md +84 -8
  7. data/docs/hooks.md +2 -2
  8. data/docs/internals/background-tasks.md +1 -1
  9. data/docs/internals/engine.md +14 -0
  10. data/docs/internals/prompt-caching.md +8 -0
  11. data/docs/memory.md +1 -1
  12. data/docs/plugins.md +63 -0
  13. data/docs/sessions.md +1 -1
  14. data/lib/samagotchi/bootstrap/config_writer.rb +2 -0
  15. data/lib/samagotchi/bootstrap/probe.rb +3 -0
  16. data/lib/samagotchi/bootstrap_command.rb +2 -0
  17. data/lib/samagotchi/broadcast_command.rb +2 -0
  18. data/lib/samagotchi/bundles/core/manifest.yml +2 -1
  19. data/lib/samagotchi/bundles/mcp/manifest.yml +2 -2
  20. data/lib/samagotchi/bundles/mcp/plugin.rb +15 -1
  21. data/lib/samagotchi/bundles/slow-commands/manifest.yml +11 -0
  22. data/lib/samagotchi/bundles/slow-commands/plugin.rb +320 -0
  23. data/lib/samagotchi/bundles/system/config_modification_protocol.md +1 -1
  24. data/lib/samagotchi/bundles/system/manifest.yml +3 -3
  25. data/lib/samagotchi/bundles/system/memory_guide.md +1 -1
  26. data/lib/samagotchi/cache_confirm.rb +51 -0
  27. data/lib/samagotchi/client_id.rb +12 -0
  28. data/lib/samagotchi/config.rb +7 -3
  29. data/lib/samagotchi/context_command.rb +2 -0
  30. data/lib/samagotchi/desktop/macos.rb +3 -0
  31. data/lib/samagotchi/engine.rb +102 -8
  32. data/lib/samagotchi/engine_peers.rb +1 -0
  33. data/lib/samagotchi/gem_update.rb +3 -0
  34. data/lib/samagotchi/guardrails/shell_lex.rb +8 -0
  35. data/lib/samagotchi/guardrails/shell_paths.rb +3 -0
  36. data/lib/samagotchi/host_config.rb +6 -3
  37. data/lib/samagotchi/host_registry.rb +19 -3
  38. data/lib/samagotchi/installed_versions.rb +3 -0
  39. data/lib/samagotchi/kernel_loop.rb +99 -16
  40. data/lib/samagotchi/llm/chat_loop.rb +122 -71
  41. data/lib/samagotchi/llm/openai_chat.rb +2 -1
  42. data/lib/samagotchi/llm/stream_drops.rb +63 -0
  43. data/lib/samagotchi/llm/turn_settings.rb +9 -5
  44. data/lib/samagotchi/model_settings.rb +5 -2
  45. data/lib/samagotchi/plugin/context.rb +5 -0
  46. data/lib/samagotchi/reasoning_history.rb +132 -0
  47. data/lib/samagotchi/reasoning_history_command.rb +107 -0
  48. data/lib/samagotchi/redacted_inspect.rb +28 -0
  49. data/lib/samagotchi/self_report.rb +21 -0
  50. data/lib/samagotchi/session.rb +23 -2
  51. data/lib/samagotchi/session_commands.rb +55 -15
  52. data/lib/samagotchi/session_manager.rb +2 -1
  53. data/lib/samagotchi/session_setup.rb +7 -5
  54. data/lib/samagotchi/setting_explained.rb +20 -0
  55. data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
  56. data/lib/samagotchi/terminal_ui/attached_loop.rb +23 -5
  57. data/lib/samagotchi/terminal_ui/formatting.rb +8 -5
  58. data/lib/samagotchi/terminal_ui.rb +13 -6
  59. data/lib/samagotchi/thinking.rb +20 -25
  60. data/lib/samagotchi/thinking_command.rb +33 -11
  61. data/lib/samagotchi/tool_runner.rb +14 -3
  62. data/lib/samagotchi/tools/builtins.rb +6 -2
  63. data/lib/samagotchi/tools/execute.rb +3 -2
  64. data/lib/samagotchi/tools/peers.rb +4 -2
  65. data/lib/samagotchi/tools/task_runtime.rb +2 -1
  66. data/lib/samagotchi/version.rb +1 -1
  67. data/lib/samagotchi/web/app.rb +29 -6
  68. data/lib/samagotchi/web/public/app.js +44 -9
  69. data/lib/samagotchi/web/public/commands.js +36 -3
  70. data/lib/samagotchi/web/public/composer.js +5 -1
  71. data/lib/samagotchi/web/public/index.html +22 -5
  72. data/lib/samagotchi/web/public/info_bar.js +5 -3
  73. data/lib/samagotchi/web/public/level_chip.js +174 -0
  74. data/lib/samagotchi/web/public/model_pick.js +1 -1
  75. data/lib/samagotchi/web/public/question_card.js +5 -3
  76. data/lib/samagotchi/web/public/question_cards.js +21 -1
  77. data/lib/samagotchi/web/public/read_view.js +74 -0
  78. data/lib/samagotchi/web/public/reasoning_history_chip.js +49 -0
  79. data/lib/samagotchi/web/public/ref_scan.js +206 -0
  80. data/lib/samagotchi/web/public/refs.js +19 -10
  81. data/lib/samagotchi/web/public/session_state.js +5 -0
  82. data/lib/samagotchi/web/public/stream_handlers.js +10 -2
  83. data/lib/samagotchi/web/public/thinking_chip.js +33 -138
  84. data/lib/samagotchi/web/public/turn_html.js +4 -2
  85. data/lib/samagotchi/web/public/turn_view.js +5 -3
  86. data/lib/samagotchi/web/token.rb +3 -0
  87. data/lib/samagotchi/worker.rb +17 -5
  88. metadata +13 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f90692cf867e2bd082f40c2ae576604656d23169163ed5584f9221ccec528ac1
4
- data.tar.gz: ac4852809e3ccdc332dd0d052e17671096eb167691cdde6f01fc2ef6e43b9870
3
+ metadata.gz: 75f7f85ba516cdddbcb52f53060ff9cad85ba2bbbb433baa0d8d4190dee29036
4
+ data.tar.gz: 992280b49b2b8843f85f62de8859b448ff0c4643680d7d1c5ab429ed645d35c6
5
5
  SHA512:
6
- metadata.gz: 541c55286cdad591988db3b43af6c60480061f931b418c83ff44afe3fe62e677df638021f082ce42241bd1f0145ca3a88173f9046341e9d282351cdc92814a1c
7
- data.tar.gz: ae24243b3978c3f8f87a655c50d9f446128618b63d6dc5b10923f09eef90d11fcd4bee714692d287157340029f83097476c7d057f27c8ddff98c86f30678758b
6
+ metadata.gz: 10d0cc0ee61e9eee9b0b96a03433e4bca70feb5e0f5a291eda877c5d892846cc935c94e399147b66f9df865fe432aa402512d05fbf2aafc6149adb6674cc69d0
7
+ data.tar.gz: 31d03c2a809991463364357bdd4f744120479b86e6f94d4b4e08026966f57d699f72025990eee0bd620887a06c3bdeb7d6d282e9983292dc5832c761691e2041
data/CHANGELOG.md CHANGED
@@ -8,6 +8,68 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.57.0] - 2026-10-11
12
+
13
+ ### Added
14
+
15
+ - Web: more refs. An edit or write approval card's path opens the current file at the first line the dry run
16
+ changes, and its diff lines open at theirs, so you can look at the real file before you approve. A read of a whole
17
+ file or a range (not the head/tail preview of a big file) gets a closed `lines 40–60` under its output: opened, it
18
+ shows the text as read with line numbers, and a click on a line opens the file there.
19
+ - Web: a `path:line` in an answer or a step's text opens that file in your editor too, when it names a file the
20
+ session's tool rows touched (`app.js:12` names the one touched file ending in it). It links once the turn has ended
21
+ and after a reload; code blocks, links (a PR link stays the PR's) and files the session didn't touch stay text.
22
+ - The `slow-commands` bundle, in the `core` profile: an `execute` that ran past its limit (or 80% of it) is remembered
23
+ for the project, and the next identical `execute` is denied once a turn with advice to start it with `task_create`
24
+ and wait with `task_wait` (with how long a finished task of it took, when there is one). `mode: notify` only warns;
25
+ `/slow-commands` lists a project's entries, `/slow-commands forget <n|all>` drops them. See "The slow-commands
26
+ bundle" in docs/plugins.md.
27
+ - `after_tool_call` hooks get `call:` (the call that ran), `elapsed_ms:` (the tool's run, nil for a denied call) and
28
+ `result:` (the tool's own text, without the `[tool]` lead, the `ran as:` line or the cap).
29
+
30
+ ### Fixed
31
+
32
+ - More of chi's internal objects (commands, bootstrap, gem update, the web token) no longer print the environment or
33
+ the web token when inspected, e.g. in a failing spec's output or a debugger: they show every other instance variable
34
+ but the ones holding the environment or token, which print `[redacted]`.
35
+ - The host registry and a plugin's `ctx` no longer print the environment (API keys included) when inspected, e.g.
36
+ in a failing spec's output or a debugger: they show host names, addresses, key variable names and models.
37
+ - `chi --resume ID --thinking X` whose `/thinking` fails (or waits for the running turn) now says `--thinking`, not
38
+ "could not set the --llm-context".
39
+ - The MCP bundle no longer prints a server's env values or command arguments (e.g. a token) when inspected; a failing
40
+ spec or a debugger now shows only the server's state, the command's first word and the env's variable names.
41
+
42
+ Update with `chi update`: it installs slow-commands (new in `core`, core 0.2.0) and updates mcp (0.6.2: no env
43
+ values when inspected). Then restart `chi web`.
44
+
45
+ ## [0.56.0] - 2026-10-11
46
+
47
+ ### Added
48
+
49
+ - `reasoning_history` (`drop`, `turn`, `all`) on a `models:` or `hosts:` entry, and `SAMAGOTCHI_REASONING_HISTORY`
50
+ for a whole process: which of its own reasoning a chat host's model gets back. `/model` names a configured level
51
+ and `chi self` shows it.
52
+ - `/reasoning-history drop|turn|all|default` sets a session's own level (saved; continue and fork copy it); `/model`,
53
+ `/stats` and the web's session bar (a `reasoning` chip, on chat hosts) show it with its source.
54
+ - `/thinking` and `/reasoning-history` ask before a change that makes the server read the conversation again (Gemma,
55
+ hosted APIs, a change to or from `all`); `--yes` applies at once. The terminal puts the `--yes` line in the next
56
+ input, the web's reply has an Apply button; `chi send`, `chi -p … --non-interactive` and piped lines apply directly.
57
+
58
+ ### Changed
59
+
60
+ - A chat host (`api: openai`) now gets the running turn's reasoning back: each of the turn's earlier replies carries its
61
+ reasoning as `reasoning_content`, as Qwen's, Gemma 4's and DeepSeek's templates and the hosted APIs expect
62
+ (`reasoning_history: turn`, the default). A local Qwen thought ~8x less per request with it. `drop` sends none (as
63
+ before), `all` sends every reply's, earlier turns too. A host that refuses it (a 400 about reasoning) gets the step
64
+ again without it, and that model sends none from then on (a notice says so once). See "Reasoning history" in
65
+ docs/configuration.md.
66
+ - `/thinking`'s cache note now tells a local chat server (only the tail; the whole prompt for a Gemma model) from a
67
+ hosted one (the whole conversation). The web's thinking chip sends its level with `--yes`.
68
+
69
+ ### Fixed
70
+
71
+ - A local llama.cpp turn whose connection dropped mid-answer now restarts that step (up to twice) instead of failing.
72
+
11
73
  ## [0.55.0] - 2026-10-10
12
74
 
13
75
  ### Added
@@ -2461,7 +2523,9 @@ and long-lived sessions.
2461
2523
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
2462
2524
  hotkey panel that send selected text or the clipboard to your sessions.
2463
2525
 
2464
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.55.0...HEAD
2526
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.57.0...HEAD
2527
+ [0.57.0]: https://github.com/dm1try/samagotchi/compare/v0.56.0...v0.57.0
2528
+ [0.56.0]: https://github.com/dm1try/samagotchi/compare/v0.55.0...v0.56.0
2465
2529
  [0.55.0]: https://github.com/dm1try/samagotchi/compare/v0.54.0...v0.55.0
2466
2530
  [0.54.0]: https://github.com/dm1try/samagotchi/compare/v0.53.0...v0.54.0
2467
2531
  [0.53.0]: https://github.com/dm1try/samagotchi/compare/v0.52.0...v0.53.0
data/README.md CHANGED
@@ -76,7 +76,7 @@ It finds out whether the server is llama.cpp or OpenAI-compatible, picks the
76
76
  model (or asks, when there are several), sends one test request and writes
77
77
  the config. With a config already there, it adds a `hosts:` entry and keeps
78
78
  the rest of the file. Then it installs the `core` bundles (loop-guard,
79
- check-in, guardrails: the safety set for a small local model) and, on a
79
+ check-in, guardrails, slow-commands: the safety set for a small local model) and, on a
80
80
  terminal, offers `dev` (known-names, mcp, btw, skills, source-links). Edit the
81
81
  file later as in [Configure](#configure); `chi bootstrap --help` has the
82
82
  options.
data/docs/architecture.md CHANGED
@@ -280,7 +280,10 @@ process that already owns the `Engine`); every worker starts it, and it exposes:
280
280
  `404` for an unknown id. A POST with a body because routes match exact paths.
281
281
  - `POST /session/:id/command` — a session command (`/model`, `/models`, `!rollback`, `!cmd`,
282
282
  `/continue`) for the worker loop; `202` with a `command_id` its `:command_ran` names, `400` when
283
- the line isn't one.
283
+ the line isn't one. A `:command_ran` carries `thinking`, `reasoning_history` and `llm_context`
284
+ (the summaries the next turn runs under) when the command changed them or the model, and
285
+ `confirm: {line, text}` when a `/thinking` or `/reasoning-history` change from a `web:` or `tui:`
286
+ client asks first (`CacheConfirm`; nothing changed, `line` applies it).
284
287
  - `POST /session/:id/exit` — ask the worker to exit now (`{client_id:}`). The worker checks with
285
288
  the event log held (`WorkerIdleExit#hold_for_request`): `200 {status: "exiting"}` and it leaves
286
289
  like an idle exit, or `409 {status: "held", reason:}` with `turn_running`, `input_queued`,
@@ -390,7 +393,8 @@ server's `reasoning_content`; the raw-prompt loop splits each generation's
390
393
  stream with a fresh `ThoughtStreamSplitter` (Qwen's `<think>` and Gemma's
391
394
  `<|channel>thought … <channel|>` are thinking, tool-call bodies are dropped
392
395
  from `text:`). The chat loop's model turns keep their `tool_calls` and tool results their `tool_call_id`,
393
- so later requests and resumed sessions pair them. It has its own system prompt
396
+ so later requests and resumed sessions pair them, and their reasoning (`thinking:`), which goes back as
397
+ `reasoning_content` on the running turn's replies (`reasoning_history`). It has its own system prompt
394
398
  (no raw-prompt tool declarations; the tools go as JSON schemas).
395
399
 
396
400
  `Engine#build_stream_event_handler` is the one seam both loops' streams pass
data/docs/cli.md CHANGED
@@ -64,7 +64,7 @@ chi bootstrap # try localhost 8080, 11434, 1234, 8000
64
64
  or with anchors gets the lines printed to paste instead. `--dry-run` shows
65
65
  what it would write.
66
66
  - **The bundles.** Unless writing the config failed, it installs the system
67
- bundle and the `core` profile (loop-guard, check-in, guardrails), one line
67
+ bundle and the `core` profile (loop-guard, check-in, guardrails, slow-commands), one line
68
68
  each; on a terminal it then asks `Also install dev (known-names, mcp, btw,
69
69
  skills, source-links)? [y/N]`. Run again, it installs nothing new: a bundle
70
70
  you uninstalled stays out ([Bundle profiles](memory.md#bundle-profiles-core-and-dev)).
@@ -489,14 +489,34 @@ from (`session`, `--thinking` / `SAMAGOTCHI_THINKING_LEVEL`, `models: <key>`,
489
489
  session's own level, which comes first; `/thinking default` unsets it. It is
490
490
  saved with the session (a `--resume`, a continue and `/model` keep it) and
491
491
  applies from the next turn's start; the reply says what the change costs the
492
- prompt cache: the whole prompt on native Gemma 4 (its `<|think|>` starts the
493
- prompt), only the tail on native Qwen, and other request fields on a chat host
494
- (a local llama.cpp or Splash server keeps its cache; a hosted API such as
495
- OpenRouter → Claude or OpenAI may restart its own). `/thinking` alone answers
492
+ prompt cache: the whole prompt on Gemma 4 (native, or a local chat server whose
493
+ model name says gemma: `<|think|>` starts the prompt), only the tail on Qwen
494
+ (native, or a local llama.cpp or Splash server), and the whole conversation on a
495
+ remote chat host (OpenRouter, a hosted API). `/thinking` alone answers
496
496
  mid-turn too; a change sent while a turn runs waits for the turn's end, and
497
497
  skips that turn's warm-up. `/stats` shows the level on its `thinking:` line.
498
498
  See "Thinking" in [configuration.md](configuration.md).
499
499
 
500
+ `/reasoning-history` shows which of its own reasoning a chat host's model gets
501
+ back from the next turn on, and where that came from (`session`,
502
+ `SAMAGOTCHI_REASONING_HISTORY`, `models: <key>`, `hosts.<name>`, the default
503
+ `turn`). `/reasoning-history drop|turn|all` sets the session's own level, which
504
+ comes first; `/reasoning-history default` unsets it. It is saved and carried as
505
+ `/thinking`'s is, and a native host ignores it (the reply says so). A change to
506
+ or from `all` once an earlier reply has thinking rewrites the earlier replies;
507
+ `drop` ↔ `turn` costs nothing. `/stats` shows it on its `reasoning history:`
508
+ line, the web as the `reasoning` chip. See "Reasoning history" in
509
+ [configuration.md](configuration.md).
510
+
511
+ A `/thinking` or `/reasoning-history` change that restarts the prompt cache
512
+ asks first: the reply says what it costs, changes nothing, and names the line
513
+ that applies it (`/thinking low --yes`). `--yes` (or `-y`) applies it at once.
514
+ The terminal puts that line in the next input (Enter applies it); the web's
515
+ reply has an Apply button. `chi send ID "/thinking low"`,
516
+ `chi -p "/thinking low" --non-interactive` and lines piped into the REPL apply
517
+ without asking (a plain `chi -p` opens the REPL, which asks). See "Changes that
518
+ restart the prompt cache" in [configuration.md](configuration.md).
519
+
500
520
  ### Typing during a turn
501
521
 
502
522
  The prompt stays open while a turn runs, in an attached terminal and in the plain
@@ -525,9 +545,10 @@ REPL alike:
525
545
  - At once, beside the turn: `/stats`, `/recap`, `/help`, `/context`, a
526
546
  plugin's anytime command (`/btw`), and the commands that only show
527
547
  something: `/models` (with a filter too), and `/model`, `/llm-context`,
528
- `/thinking` and `/guardrails` alone.
548
+ `/thinking`, `/reasoning-history` and `/guardrails` alone.
529
549
  - After the turn: the ones that change something (`/model X`, `/model clear`,
530
- `/llm-context strategy …`, `/thinking LEVEL`, `/guardrails revoke N`) and `!cmd`, whose output
550
+ `/llm-context strategy …`, `/thinking LEVEL`, `/reasoning-history LEVEL`, `/guardrails revoke N`) and
551
+ `!cmd`, whose output
531
552
  joins the conversation. `(queued: runs after this turn)` says so at once (the
532
553
  web draws the command's bubble dashed, with the same words, until it ran);
533
554
  when the turn ends they run in the order sent, a prompt sent before one
@@ -698,7 +719,8 @@ as you toggled them. A reloaded session shows the same block
698
719
  from the saved messages (each step's thinking, narration, tool parameters
699
720
  and output, the output capped at 2000 characters) and the timing records
700
721
  (status and duration per row). On an `api: openai` host the model's
701
- reasoning is saved with each step for this (never sent back to the model);
722
+ reasoning is saved with each step for this (and sent back to the model
723
+ within the turn: see "Reasoning history" in [Configuration](configuration.md));
702
724
  steps saved before that have none, so they show no thinking. An `edit` or
703
725
  `write` row has a closed `diff +3 −1` under it that opens to the change it
704
726
  made (up to 120 lines or 8 KB), live and after a reload (see
@@ -487,15 +487,15 @@ models:
487
487
  (`chi web`'s, say) wakes it later: use `chi send --new --thinking low`.
488
488
  - A level is fixed for a turn: a change takes effect at the next turn's start. `/thinking LEVEL` sent while a turn
489
489
  runs waits for its end (as `/model X` does), and holds off that turn's warm-up. What a change costs the prompt cache,
490
- which `/thinking` says:
490
+ which `/thinking` says (and asks before the costly ones: "Changes that restart the prompt cache"):
491
491
 
492
- | Backend | A level change |
493
- |---|---|
494
- | native Qwen (`qwen36`) | only the prompt's tail (the empty thought after the cue) |
495
- | native Gemma 4 (`gemma4`) | the whole prompt is read again: `<\|think\|>` starts the system prompt |
496
- | chat host, local llama.cpp or Splash | other request fields; the server keeps its cache (a Gemma template re-reads it all) |
497
- | chat host, OpenRouter → Claude | thinking params are part of the cached prefix: the cache restarts |
498
- | chat host, OpenRouter → OpenAI reasoning | an effort change rewrites hidden instructions: the prefix is lost |
492
+ | Backend | A level change | Asks |
493
+ |---|---|---|
494
+ | native Qwen (`qwen36`) | only the prompt's tail (the empty thought after the cue) | no |
495
+ | native Gemma 4 (`gemma4`) | the whole prompt is read again: `<\|think\|>` starts the system prompt | yes |
496
+ | chat host, local (llama.cpp, Splash), a model name with `gemma` | the whole prompt: the template writes the same token | yes |
497
+ | chat host, local, any other model | other request fields; the server keeps its cache, only the tail changes | no |
498
+ | chat host, remote (OpenRouter, a hosted API) | Claude's thinking params are part of the cached prefix, an OpenAI effort change rewrites hidden instructions: the conversation is read again | yes |
499
499
 
500
500
  - `models:` levels and `thinking.level` in the file are read every turn; a host's `thinking:` reaches a worker when
501
501
  it starts, as its `sampling:` does (`chi sessions stop` to change it).
@@ -539,6 +539,81 @@ hosts:
539
539
  A different level changes a native model's system prompt (Gemma's token, Qwen's turn preamble), so the next turn
540
540
  reads the whole context again once; on a chat host only the end of the prompt changes.
541
541
 
542
+ ## Reasoning history
543
+
544
+ Which of its own reasoning a chat host's model (`api: openai`) gets back. chi saves each step's reasoning; with it
545
+ sent back, the model goes on from its own plan between tool calls instead of working it out again (in one test a local
546
+ Qwen thought about 8x less per request and finished a small task about 40% sooner). One level, set per model or per host:
547
+
548
+ ```yaml
549
+ hosts:
550
+ deepseek-api:
551
+ url: https://api.deepseek.com/v1
552
+ api: openai
553
+ api_key_env: DEEPSEEK_API_KEY
554
+ reasoning_history: all # its API wants every earlier reply's reasoning when tools are sent
555
+ models:
556
+ some-model:
557
+ reasoning_history: drop
558
+ ```
559
+
560
+ - `turn` (the default) sends the running turn's reasoning: each reply since the last user message carries its
561
+ reasoning as `reasoning_content`, which is what Qwen's, Gemma 4's and DeepSeek's chat templates and the hosted APIs
562
+ (OpenRouter takes it for DeepSeek, Qwen and other text-reasoning models) expect. The running turn starts at the
563
+ last message you sent (a prompt, or a steer: as the chat template counts it) and never before the turn's own start,
564
+ so a turn that goes on by itself (a reminder, a context wake, a continue after a stop) sends nothing of the one
565
+ before it, an interrupted reply's partial thought included.
566
+ - `drop` sends none (what chi did before this setting).
567
+ - `all` sends every reply's reasoning, earlier turns too. It sends only the field: a local template that leaves out
568
+ earlier turns' reasoning (Qwen's) needs `sampling: {chat_template_kwargs: {preserve_thinking: true}}` as well.
569
+ - Order, first set wins: the session's own level, `SAMAGOTCHI_REASONING_HISTORY` (the whole process; for A/B runs),
570
+ the `models:` entry (found the way `profile:` is), the `hosts:` entry, then `turn`. Anything else than a level warns
571
+ once and counts as unset. A host's level reaches a worker when it starts, as its `sampling:` does.
572
+ - **A session's own level** (`drop`, `turn` or `all`; an explicit `turn` counts as its own) is saved in the session
573
+ (its file's `"reasoning_history"`), so a `--resume`, a respawned worker, a continue and `/model` keep it; a plugin's
574
+ fork copies it, a delegate child starts without it. Set it with `/reasoning-history LEVEL` in the session
575
+ (`/reasoning-history default` unsets it, `/reasoning-history` alone shows the level and where it came from) or the
576
+ web's `reasoning` chip in the session bar (shown on chat hosts only). There is no start flag: a fresh session runs
577
+ the command before its first turn at no cost. A change takes effect at the next turn's start; sent while a turn runs
578
+ it waits for its end.
579
+ - What a change costs the prompt cache (`/reasoning-history` says so, and asks first when it costs: "Changes that
580
+ restart the prompt cache"):
581
+
582
+ | Change | Cost |
583
+ |---|---|
584
+ | `drop` ↔ `turn` | none: a turn's first request carries no reasoning under either |
585
+ | to or from `all`, once an earlier reply has thinking | every earlier reply gains or loses its reasoning: a server that renders it (hosted APIs, llama.cpp's default template) reads the conversation again from the first earlier thought |
586
+ | nothing thought yet, the same level, or a native host | none |
587
+
588
+ - The native loop (`/completion`) ignores it: it always keeps the running turn's reasoning, a mid-turn steer included
589
+ (the chat loop starts again after a steer).
590
+ - When a host answers a request that sent reasoning back with an HTTP 400 about reasoning, chi asks again without it,
591
+ sends none to that model from then on (until the worker restarts) and says so once. If the request without it is
592
+ refused too, the thinking fields get the same fallback ("Thinking") and the reasoning goes back on the next step.
593
+ - `/model` names a level that isn't the default (`reasoning history: drop (models: some-model)`, `all (session)`),
594
+ `/stats` shows it on its `reasoning history:` line (chat hosts only), and `chi self` on its `reasoning history` row
595
+ (a session's own level first when run from its commands).
596
+ - Claude via OpenRouter signs its reasoning (`reasoning_details`), which chi doesn't keep: it gets the plain text,
597
+ and the fallback above covers a refusal.
598
+
599
+ ## Changes that restart the prompt cache
600
+
601
+ `/thinking` and `/reasoning-history` ask before a change that makes the server read the conversation again: Gemma's
602
+ thinking switch, a remote chat host's thinking fields ("Thinking"), and a change to or from `all` once an earlier reply
603
+ has thinking ("Reasoning history"). They ask only when the level the next turn runs under really changes and the
604
+ session has a model reply.
605
+
606
+ - The reply says what it costs and changes nothing yet: `Nothing changed yet: send /thinking low --yes to apply.`
607
+ - `--yes` (or `-y`, anywhere after the command) applies it at once.
608
+ - The terminal (the REPL and an attached TUI) puts the `--yes` line in the next input: Enter applies it.
609
+ - The web's reply bubble has an **Apply (restarts the cache)** button. The session bar's chips are already an explicit
610
+ choice: their Set sends the `--yes` line, and their form says what a change costs. Command bubbles are page-only, so
611
+ the button is gone after a reload.
612
+ - Only a person at a web tab or a chi TUI is asked. `chi send ID "/thinking low"`,
613
+ `chi -p "/thinking low" --non-interactive`, lines piped into the REPL, a delegate, a plugin and a card's action
614
+ apply directly, since nobody would see the question; so do the start flags (`chi --thinking` on a resumed or
615
+ attached session sends `/thinking LEVEL --yes`). A plain `chi -p` opens the REPL, which asks.
616
+
542
617
  ## Llama HTTP Timeouts
543
618
 
544
619
  Long-running llama.cpp completions can exceed Ruby's default HTTP read timeout.
@@ -1199,6 +1274,7 @@ described in their own sections.
1199
1274
  | `context.every_seconds` | `300` | | How often an attached context source's command runs when it has no `--every` (seconds, at least 30). See [Attached context](context.md). |
1200
1275
  | `context.wake` | `true` | yes | A source whose update says `wake: true` may start a turn in a live, idle session (one per source per 10 minutes, within `session.max_wakes`); `false`: updates wait as notes for the next turn. See [Waking](context.md#waking). |
1201
1276
  | `thinking.turn_preamble` | `true` | yes | Ask a `qwen36` model to open its thinking with a short `TURN:` line (the step label). |
1277
+ | `reasoning_history` | `turn` | | Which of its reasoning a chat host's model gets back: `drop`, `turn`, `all`; environment only (`SAMAGOTCHI_REASONING_HISTORY`), below a session's own level (`/reasoning-history`), above the `models:`/`hosts:` entries. See "Reasoning history". |
1202
1278
  | `thinking.level` | `default` | `--thinking` | `off`, `low`, `medium`, `high` or `default` for every model; the flag and env outrank the `models:`/`hosts:` entries, the file's value doesn't; a session's own level outranks them all, and `--thinking` sets it on a session run (on `chi web` it sets this). See "Thinking". |
1203
1279
  | `models.<key>.thinking`, `hosts.<name>.thinking` | none | | A model's or host's level. See "Thinking". |
1204
1280
  | `hosts.<name>.models` | none | | The model ids a host serves whatever its `/v1/models` lists: a map of ids, or a plain list. See "Models a host serves but doesn't list". |
data/docs/hooks.md CHANGED
@@ -56,7 +56,7 @@ The plugin class must respond to `#call(event)` — duck-typed, no base class re
56
56
  | `:after_generation` | After LLM returns (both loops); not after a generation a hook cut (`stop_generation`) | `{ type: :after_generation, iteration: N, response: "...", messages: [...] (the conversation as sent) }` |
57
57
  | `:generation_progress` | While the response streams, in batches (see [Watching the stream](#watching-the-stream)) | `{ type: :generation_progress, iteration: N, thinking: "..." (new since the last fire), text: "..." (new visible text), thinking_chars: N, text_chars: N (this generation so far), elapsed_ms: N, restarted: true (only on the first fire after a dropped stream was asked again) }` |
58
58
  | `:before_tool_call` | Before tool dispatch (and before `tool_call_started`) | `{ type: :before_tool_call, iteration: N, call: {...}, params: "...", guardrail: Verdict, context: {...}, targets: {...}, blocked: false, block_reason: nil }` |
59
- | `:after_tool_call` | After tool execution | `{ type: :after_tool_call, iteration: N, tool: "read", output: "..." (the text the model gets: capped at max_tool_output_chars, a cut one ending in a [cut: N of M chars …] line), status: "ok" \| "error" \| "blocked" \| "stopped" }`; `stopped` is a `task_wait` the turn's Stop ended (the task runs on) or whose task was stopped |
59
+ | `:after_tool_call` | After tool execution | `{ type: :after_tool_call, iteration: N, tool: "read", output: "..." (the text the model gets: capped at max_tool_output_chars, a cut one ending in a [cut: N of M chars …] line), status: "ok" \| "error" \| "blocked" \| "stopped", call: {...} (the call that ran, as the gate left it), elapsed_ms: N (the tool's own run, without an approval wait; nil for a denied call), result: "..." (the tool's own text: no "[read]" lead, no "ran as:" line, never cut) }`; `stopped` is a `task_wait` the turn's Stop ended (the task runs on) or whose task was stopped. Match on `result:`, not `output:`: it is what the tool said (`Error: command timed out after 120s` for an execute killed at its limit, `Samagotchi::Tools::Execute::TIMEOUT_PREFIX`) |
60
60
  | `:session_end` | After each turn `:after_turn` fires for, after it (turn-level lifecycle) | `{ type: :session_end, session_id: "..." }` |
61
61
 
62
62
  Every event also carries the hook runtime (next section): `hook:` (the label
@@ -507,7 +507,7 @@ Notes:
507
507
  - Ordering: bundle hooks fire by `(priority, bundle_name, hook_name)` (lower priority first), then plain `config.yml` hooks in registration order.
508
508
  - Settings: a hook class with `initialize(settings = {})` gets the bundle's section of `config.yml` `bundles:` (see [Settings](#settings)).
509
509
  - A bundle can also ship a `plugin.rb` whose `chi.on(event)` blocks are bundle hooks too, next to commands and tools; see [Plugins](plugins.md). There `ctx.notify`, `ctx.steer` and the other `ctx` helpers act as this page's `event[:notify]`… do for the event the block runs for.
510
- - Shipped bundles (each in a profile: `core` or `dev`, see [Bundle profiles](memory.md#bundle-profiles-core-and-dev)): `chi bundle install guardrails` (rules, see [Guardrails](guardrails.md#the-guardrails-bundle)) and `chi bundle install known-names` (a hook, see [Guardrails](guardrails.md#the-known-names-bundle)), `chi bundle install source-links` (a hook: announces source refs, see [The source-links bundle](#the-source-links-bundle)), `chi bundle install btw` (a plugin: `/btw`, see [Plugins](plugins.md#the-btw-bundle)), `chi bundle install mcp` (a plugin: tools from MCP servers, see [Plugins](plugins.md#the-mcp-bundle)) `chi bundle install loop-guard` (a plugin: breaks tool-call loops, see [Plugins](plugins.md#the-loop-guard-bundle)), `chi bundle install check-in` (a plugin: checks on a long turn, see [Plugins](plugins.md#the-check-in-bundle)) and `chi bundle install skills` (a plugin: `/skill`, versions of skills, see [Plugins](plugins.md#the-skills-bundle)).
510
+ - Shipped bundles (each in a profile: `core` or `dev`, see [Bundle profiles](memory.md#bundle-profiles-core-and-dev)): `chi bundle install guardrails` (rules, see [Guardrails](guardrails.md#the-guardrails-bundle)) and `chi bundle install known-names` (a hook, see [Guardrails](guardrails.md#the-known-names-bundle)), `chi bundle install source-links` (a hook: announces source refs, see [The source-links bundle](#the-source-links-bundle)), `chi bundle install btw` (a plugin: `/btw`, see [Plugins](plugins.md#the-btw-bundle)), `chi bundle install mcp` (a plugin: tools from MCP servers, see [Plugins](plugins.md#the-mcp-bundle)) `chi bundle install loop-guard` (a plugin: breaks tool-call loops, see [Plugins](plugins.md#the-loop-guard-bundle)), `chi bundle install check-in` (a plugin: checks on a long turn, see [Plugins](plugins.md#the-check-in-bundle)), `chi bundle install slow-commands` (a plugin: commands that ran past the execute limit are run as tasks next time, see [Plugins](plugins.md#the-slow-commands-bundle)) and `chi bundle install skills` (a plugin: `/skill`, versions of skills, see [Plugins](plugins.md#the-skills-bundle)).
511
511
  - Installing a bundle executes its hook code at `Engine` startup. Only install bundles you trust, as you would a gem. Hooks are **not** executed at install time (copy-only); they are `module_eval`'d at `Engine.new` inside per-bundle `Samagotchi::Bundles::<name>` namespaces (no top-level `require` collisions). Keep hook files side-effect-free at load time; do work in `#call` — top-level side effects (require, IO, `at_exit`, global assignment) run once per `Engine.new` (class redefinition is idempotent).
512
512
 
513
513
  Lifecycle:
@@ -24,6 +24,6 @@ Behavior:
24
24
  - `task_get` returns metadata and `output_path`; use `read` for output contents.
25
25
  - `task_wait` accepts `timeout`, `tail_lines` (maximum 100), and `done_pattern` (a regular expression string).
26
26
  - `task_create` accepts `env` as a JSON object string for deterministic overrides such as `PATH`; use an absolute interpreter path when that is simpler. Ruby/Bundler isolation variables remain protected.
27
- - `execute` and `task_create` export chi's own markers into the command, set over the model's `env` (which can't set them: `Error: env key is reserved`): `SAMAGOTCHI_PARENT_SESSION` (the session's id, `chi` without one; a chi started there answers as a parent agent), `SAMAGOTCHI_SESSION_MODEL` (the resolved ref the session runs on, read at each call so it follows `/model`; unset when unknown) and `SAMAGOTCHI_SESSION_THINKING` (the session's own thinking level; unset when it has none). `chi self` reads the last two for its model and thinking level. The three are `TaskRuntime::MARKER_ENV_KEYS` (and `SessionManager::SESSION_MARKER_ENV`, which a spawned worker unsets). A session's worker never inherits them from whoever started it (a `chi send` run by another session's `execute`): its other commands (a user's `!cmd`, an MCP server, a context command) have none.
27
+ - `execute` and `task_create` export chi's own markers into the command, set over the model's `env` (which can't set them: `Error: env key is reserved`): `SAMAGOTCHI_PARENT_SESSION` (the session's id, `chi` without one; a chi started there answers as a parent agent), `SAMAGOTCHI_SESSION_MODEL` (the resolved ref the session runs on, read at each call so it follows `/model`; unset when unknown) `SAMAGOTCHI_SESSION_THINKING` (the session's own thinking level; unset when it has none) and `SAMAGOTCHI_SESSION_REASONING_HISTORY` (its own reasoning_history level, the same way). `chi self` reads the last three for its model, thinking level and reasoning history. The four are `TaskRuntime::MARKER_ENV_KEYS` (and `SessionManager::SESSION_MARKER_ENV`, which a spawned worker unsets). A session's worker never inherits them from whoever started it (a `chi send` run by another session's `execute`): its other commands (a user's `!cmd`, an MCP server, a context command) have none.
28
28
 
29
29
  Work that needs a model, not a shell command, goes to a child chi session instead: `delegate` / `delegate_result` have the same shape (start, then wait) and return only the child's final reply; see [Sessions: Delegating](../sessions.md#delegating).
@@ -174,6 +174,19 @@ The differences from the native loop:
174
174
  as `stable_length:`), where the prompt's stable part ends. For remote Claude, `LLM::PromptCache` puts the
175
175
  first cache breakpoint there; see prompt-caching.md.
176
176
  - Each call's result is its own tool message, paired by `tool_call_id`.
177
+ - A model turn's saved reasoning (`thinking:`) goes back as `reasoning_content` per the turn's
178
+ `TurnSettings#reasoning_history` (`ReasoningHistory.resolve`, the session's own level first:
179
+ `Session#reasoning_history`, `/reasoning-history`): `all` on every model message, `turn` past
180
+ `ChatLoop#reasoning_boundary`: the later of the last query (a `role: "user"` entry: a prompt, a steer, merged input,
181
+ the chat template's `last_query_index`; or a `turn_start` entry) and the Run's start (`Run`'s `@start`, the
182
+ conversation length at `#complete`), so a continue turn (reminder, context wake, continue after a stop) replays
183
+ nothing of the run before. `Run#prompt_chars` counts it (`#reasoning_chars`). The native loop differs on a steer:
184
+ `KernelLoop#inject_pending_input!` doesn't re-sanitize, so native keeps the turn's reasoning across a mid-turn
185
+ steer, where the chat loop starts again (as the template does).
186
+ - A 400 about reasoning (`BadRequest#reasoning_refused?`) for a request that sent reasoning back asks the step again
187
+ without it; when that goes through, `#reasoning_history_refused!` marks the model (worker lifetime) and
188
+ `:reasoning_history_refused` goes out. When it is refused too, the thinking-fields fallback (`#thinking_refused!`,
189
+ `:thinking_refused`) runs on it, still without reasoning. Up to three requests per step.
177
190
 
178
191
  ### Shared: ToolResponse (per batch) and ToolRunner (per call)
179
192
 
@@ -320,6 +333,7 @@ Turn events (the main ones; `Events` in `events.rb` keeps the shared sets):
320
333
  | `:empty_answer_retry` | an empty, cut or malformed answer is asked again | `{iteration, attempt, of, finish_reason, thinking_chars, stopped_by?, malformed?}` |
321
334
  | `:steer_cut` | a steer cut the generation | `{iteration, source}` |
322
335
  | `:llm_context_edited` | the apply rule applied a batch of LLM context edits (a request, a forget_outputs call, turn end; never the warm-up) | `{moment, why, freed_tokens, tail_tokens, staged, text, groups}` (`LLMContextNotice`) |
336
+ | `:thinking_refused` / `:reasoning_history_refused` | the chat loop asked a step again without the thinking fields / the reasoning sent back; the Engine logs it and makes a once-per-session-and-host `:hook_notice` of it, the event itself never reaches the sink | `{iteration, model, level, detail}` |
323
337
  | `:pending_input_merged` | queued input joined the conversation | `{iteration, count, content, steers?, answer}` |
324
338
  | `:tool_dispatch_started` / `:tool_dispatch_completed` | around a batch | `{iteration, call_count}` |
325
339
  | `:tool_call_started` | before a call runs | see ToolRunner |
@@ -135,6 +135,14 @@ is prefilled once. The native and the chat loop use the same plan.
135
135
  on its `generation_completed` log line. `/stats` shows "cached N (P%)" and "cache writes". A change that
136
136
  drops `cached=` on the second fresh session is a regression. Update the prompt snapshot fixtures with
137
137
  `UPDATE_PROMPTS=1` and read the diff: a cache-friendly change moves sections, it doesn't reorder per run.
138
+ 6. **Ask before a setting change that restarts the cache.** A session setting whose change makes the server read
139
+ the conversation again asks a person at a web tab or a TUI first (`CacheConfirm`: the reply carries the
140
+ `--yes` line, `SessionCommands::Result#confirm` and the `command_ran` event's `confirm`). Each setting has a
141
+ classifier: `Thinking.cache_cost` (`:full` for Gemma, `:provider` for a remote chat host, `:tail` otherwise) and
142
+ `ReasoningHistory.cache_cost` (`:history` for a change to or from `all` once an earlier reply has thinking).
143
+ `CacheConfirm.needed?` asks only for `:full`, `:provider` and `:history`, when the effective level changes and
144
+ the session has a model reply. A new setting with a cost (a `/model` across templates, `/llm-context` turning
145
+ forget on) adds its classifier and goes through the same step.
138
146
 
139
147
  ## Server-side settings worth knowing
140
148
 
data/docs/memory.md CHANGED
@@ -269,7 +269,7 @@ profiles, meta bundles that install a set of them:
269
269
 
270
270
  | profile | bundles |
271
271
  |---|---|
272
- | `core` | loop-guard, check-in, guardrails: the recommended safety set |
272
+ | `core` | loop-guard, check-in, guardrails, slow-commands: the recommended safety set |
273
273
  | `dev` | known-names, mcp, btw, skills, source-links, github-pr, coordinator |
274
274
 
275
275
  `chi bootstrap` installs `core` and, on a terminal, offers `dev`. An existing
data/docs/plugins.md CHANGED
@@ -1171,6 +1171,69 @@ and goes with the session; another session starts from config.yml:
1171
1171
  | `/checkin mode ask` / `nudge` / `notify` | the mode |
1172
1172
  | `/checkin nudge` / `later` / `stop` | the card's actions, also by hand |
1173
1173
 
1174
+ ## The slow-commands bundle
1175
+
1176
+ `chi bundle install slow-commands` installs the bundle shipped with chi (`chi
1177
+ bootstrap` installs it with the `core` profile). It is written only against
1178
+ this API (`lib/samagotchi/bundles/slow-commands/plugin.rb`), with `chi.on`
1179
+ hooks and a `/slow-commands` command, and has no memory file.
1180
+
1181
+ `execute` kills a command at its limit (120 s, `execute.timeout_sec`). A full
1182
+ test suite or a build takes longer, so the model loses those two minutes,
1183
+ then starts it again with `task_create` and `task_wait`; the next session
1184
+ does the same. slow-commands remembers such a command for the project:
1185
+
1186
+ - An `execute` that **timed out**, or ran **`warn_ratio` of the limit** or
1187
+ longer (default 0.8, so 96 s of 120), is recorded as slow. A later run of
1188
+ it under half the limit **with exit 0** drops the entry; a fast failure (a
1189
+ load error) doesn't, since it says nothing about how long the suite takes.
1190
+ Nor does one through a filter the key leaves out (`rspec 2>&1 | tail -30`
1191
+ exits with `tail`'s 0, and a `| head` can end it early).
1192
+ A call the user stopped, or that was denied, records nothing.
1193
+ - The **next identical `execute`** is **denied** with advice:
1194
+
1195
+ ```
1196
+ [execute] Error: denied by guardrail (bundle slow-commands): slow command. The user was not asked. This command ran past the execute limit (120 s) here on 2026-10-09. Start it with task_create, then task_wait (timeout 600). A finished task of this command took 4m10s.
1197
+ ```
1198
+
1199
+ The last sentence is there when a task of the same command (and cwd)
1200
+ finished with exit 0 in the project's `tmp/tasks`; a longer one raises the
1201
+ `task_wait` timeout it suggests. The user sees one line:
1202
+ `slow-commands> execute bundle exec rspec: ran past 120 s before, denied`.
1203
+ - **Once per command per turn**: the same `execute` again in that turn runs.
1204
+ The model insisting is a signal (maybe the suite got faster), and that run
1205
+ records the new truth. A new turn denies again.
1206
+
1207
+ A command is the same when its project and its text match. The project is
1208
+ the session's git checkout (else its working directory). The text is the
1209
+ command's words and operators (`a && b` is not `a b`), the call's `cwd:`
1210
+ folded in as `cd web && …`, and a trailing `2>&1`, `| tail …`, `| head …`
1211
+ or `| grep …` dropped (they don't change how long it runs). Arguments stay:
1212
+ `bundle exec rspec` (the suite) is slow, `bundle exec rspec
1213
+ spec/foo_spec.rb` isn't the same command, and stays the fast path. A
1214
+ command that ends inside a quote, `$(` or heredoc is never recorded, nor
1215
+ one with a `$(…)`, backticks or a heredoc `cat` or `tee` reads (the key
1216
+ can't tell two of those apart). A heredoc script (`python3 - <<'EOF'`)
1217
+ keeps its body in the key, so each script is its own command.
1218
+
1219
+ Entries live in `$XDG_STATE_HOME/samagotchi/plugins/slow-commands/commands.json`,
1220
+ shared by every session (another session's record counts at once) and
1221
+ forgotten after `ttl_days`.
1222
+
1223
+ ```yaml
1224
+ # config.yml
1225
+ bundles:
1226
+ slow-commands:
1227
+ mode: deny # deny | notify (warn the user, never deny)
1228
+ warn_ratio: 0.8 # a run this share of the execute limit or longer is slow
1229
+ ttl_days: 14 # entries older than this are forgotten
1230
+ ```
1231
+
1232
+ | | |
1233
+ |---|---|
1234
+ | `/slow-commands` | this project's slow commands, numbered |
1235
+ | `/slow-commands forget 2` / `forget all` | drop one (a wrong entry) or all of them |
1236
+
1174
1237
  ## The skills bundle
1175
1238
 
1176
1239
  `chi bundle install skills` (or the `dev` profile) installs the bundle shipped with chi
data/docs/sessions.md CHANGED
@@ -68,7 +68,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
68
68
  **Ordering:**
69
69
 
70
70
  - `Session.list` / `SessionManager.list_sessions` / `GET /api/sessions?sort=&order=&limit=&offset=` default to `updated_at desc` (newest activity first). Also supports `created_at`, `asc`. `X-Total-Count` header when paginated.
71
- - Web UI (`chi web`): the page's scope is in its URL. Started in a git repo, `chi web` opens `/?dir=<that folder>`: that project's sessions, and new chats start in that folder; the header chip says `<project> · all`, and `all` opens the same place without `?dir` (every session; a new chat there starts in the server's own folder, shown on the start page, and cards name their folder; `← <project>` goes back to the project view it came from, or to the server's own project). One server serves every project: a second `chi web` (from another repo) finds it through `GET /api/info` and prints (with `--open`, opens) its page for its own folder instead of starting another. The 3 latest sessions sit above the chat (`hide ▴` puts them away behind a `▾ N sessions` pill, remembered; in a window under 900 px wide, where the strip scrolls sideways, `▴ hide` sits in the top bar where the pill comes back; a window under 700 px tall hides them by itself, so a question or approval card in the stage keeps room, and the pill shows them until the window is tall again). A parent and its delegates are one card there: its `▸ 2 delegates · 1 live · 1 waiting` chip (the waiting part in the attention colour, the card's border too) opens their rows in a popover under it (a row per delegate at any depth, indented; a click opens that one, Esc or a click outside closes it, and the strip's order holds while it is open). A fork is a card of its own, and so is a delegate whose parent isn't listed (archived, another project), with its `↳ <parent>` chip; the pill counts cards, and every live or waiting session. "All sessions" (or `/`) opens every session at `#/sessions`, with a search over preview, id and status (Esc or Back returns). There a parent's card holds its delegates the same way, the chip opening their rows inside the card (each with an archive button on hover), open by itself while one of them waits on you; the count says `14 (+7 delegates)`, a search that matches a delegate shows its parent's card with the list open and the matching rows marked, and select mode picks cards (archiving a parent takes its delegates). The open session is in the URL (`#/s/<id>`), so a reload or a copied link opens it again; the chi logo top left goes back to the empty start for a new chat. The message box grows with its text; drag its top edge to keep it taller (double-click resets). A file in a tool row (a read, edit or write's title) and its diff lines are refs: hover one and click to open the current file in your editor at that line, on this machine only (`web.editor`; the browser's "always allow" for the page's port and VS Code's "allow opening local files" are asked once; see [Opening files from chi web](configuration.md#opening-files-from-chi-web)). The info bar copies `chi --attach <id>` for a terminal. A session whose prompt carried model notes has a `notes: deepseek` chip there (the names without `model_notes_`; the tooltip lists each with its scope and size; `session.prompt_notes` in `GET /api/sessions/:id`, the live worker's, else the session file's; see [Memory](memory.md#model-notes)). Its `llm ctx` chip names the LLM context strategy the next turn runs under (`llm ctx stale,forget · session`, in the accent colour when the session set its own; the tooltip gives each value's source), and its popover sets the session's own strategy, apply rule and budget, or follows the model again, by running `/llm-context` in the worker (the reply shows as a command bubble); `GET /api/sessions/:id`'s `session.llm_context` carries the values (the live worker's, else resolved from the session file), and a `command_ran` that changed them carries the new ones. It shows the context used (`ctx 42%`) and the last generation's decode speed (`87 tok/s`, `~64 tok/s` when estimated; see `/stats` in [cli.md](cli.md#session-commands)); hovering `ctx` there or on a session card lists the session's tokens in (summed over every request, with the cached share), out (with reasoning) and the cost when the provider reports one, for this session only (one estimated from a `hosts.<name>.models` price shows with `~`: `cost: ~$0.54 ($0.42 reported, ~$0.12 estimated)`), and the memory indexes its prompt holds (`memory index: ~3.4k tokens in this session's prompt (system 2.0k, project 1.4k)`; see [Memory](memory.md#the-indexs-size)). The start page's model picker (bottom left of the composer, the chosen name `▾`) chooses the model a new chat starts on; it opens a search list over the conversation (↓ or a click; downward when the start page leaves no room above): an empty search shows the last 5 picks (Recent) and then each host's model ids A–Z under the host, the default host first (an id the host declares under `hosts.<name>.models` first, noted `config`, its tooltip `served by config (hosts.<name>.models)`; a host that failed to list its models keeps those ids, greyed and noted `host down`, still pickable; a remembered or default model stays chosen even then, greyed on the button); typed words must each match the host or the id (a substring, else for 3+ characters the letters in order, so `deepseek4.1 fla` finds `openrouter · deepseek/deepseek-v4.1-flash`), ⏎ picks, Esc/Tab close, a pick puts the focus in the message box: `GET /api/models` lists the hosts' models as chi spells them (`{default, models: [{name, host, id, configured?, unavailable?, sampling?, llm_context?}], warning?}`; `configured: true` marks an id declared under `hosts.<name>.models`, listed first under its host, `unavailable: true` one whose host failed to list its models; `sampling` is the model's configured request parameters as `/model` words them, the row's tooltip in the list; bare for the default host, `host:model` for the others, from the same cached lists as `/models`, a bounded wait, a host that is down noted in `warning`), and `POST /api/sessions` takes `model` (blank means the default). Beside it, an `llm ctx` chip shows the LLM context the picked model starts under (each `GET /api/models` row's `llm_context`, as the info bar's); its form sets one for the new chat only, sent as `POST /api/sessions`'s `llm_context` and never remembered (see [configuration.md](configuration.md#llm-context-a-sessions-own-strategy)). The start page's first message goes as later ones do: `POST /api/sessions` with `idle: true` and `preview` (the message, which names the session until its turn is saved), then `POST /api/sessions/:id/turn`, so a failed first turn puts its prompt back in the composer too; a first line that is one of the new session's commands (`/model …`) goes to `POST /api/sessions/:id/command` instead, as later ones do. The browser remembers the last model picked; a running session's model is in the info bar and changes only with `/model`. In the composer a line is a command when it is `!…` or starts with one of the session's command names (its `commands` list; `/stats`, `/exit` and the other terminal words get the page's own reply); an unknown `/word` (`/usr/bin/env is missing`) goes to the model as a prompt, as in a terminal; a one-word `/word` no command answers (`/modle`) is not sent: the page shows `Unknown command /modle. Did you mean /model? /help lists the commands.` (the "Did you mean" part only when a name is close). A `POST /turn` (or a session's first `prompt`) that is one of the worker's commands runs as that command too (`202 {status, command_id, session_id}`), so `chi send`, `chi -p` and a page whose command list lags all get the command. ↑/↓ in the composer walk the prompt history the TUI's ↑ walks ([Persistent Prompt History](cli.md#persistent-prompt-history)): ↑ with the caret on the first line, ↓ from the last line while browsing, ↓ past the newest brings the draft back; `GET /api/history` returns `{entries: [...]}`, oldest first (the page fetches it on focus and after each send). The server records a sent line in the routes once the worker took it (`POST /turn` accepted, a `!command` through `POST /command` or as a session's first line); `"history": false` in the body keeps it out (an image-only send).
71
+ - Web UI (`chi web`): the page's scope is in its URL. Started in a git repo, `chi web` opens `/?dir=<that folder>`: that project's sessions, and new chats start in that folder; the header chip says `<project> · all`, and `all` opens the same place without `?dir` (every session; a new chat there starts in the server's own folder, shown on the start page, and cards name their folder; `← <project>` goes back to the project view it came from, or to the server's own project). One server serves every project: a second `chi web` (from another repo) finds it through `GET /api/info` and prints (with `--open`, opens) its page for its own folder instead of starting another. The 3 latest sessions sit above the chat (`hide ▴` puts them away behind a `▾ N sessions` pill, remembered; in a window under 900 px wide, where the strip scrolls sideways, `▴ hide` sits in the top bar where the pill comes back; a window under 700 px tall hides them by itself, so a question or approval card in the stage keeps room, and the pill shows them until the window is tall again). A parent and its delegates are one card there: its `▸ 2 delegates · 1 live · 1 waiting` chip (the waiting part in the attention colour, the card's border too) opens their rows in a popover under it (a row per delegate at any depth, indented; a click opens that one, Esc or a click outside closes it, and the strip's order holds while it is open). A fork is a card of its own, and so is a delegate whose parent isn't listed (archived, another project), with its `↳ <parent>` chip; the pill counts cards, and every live or waiting session. "All sessions" (or `/`) opens every session at `#/sessions`, with a search over preview, id and status (Esc or Back returns). There a parent's card holds its delegates the same way, the chip opening their rows inside the card (each with an archive button on hover), open by itself while one of them waits on you; the count says `14 (+7 delegates)`, a search that matches a delegate shows its parent's card with the list open and the matching rows marked, and select mode picks cards (archiving a parent takes its delegates). The open session is in the URL (`#/s/<id>`), so a reload or a copied link opens it again; the chi logo top left goes back to the empty start for a new chat. The message box grows with its text; drag its top edge to keep it taller (double-click resets). A file in a tool row (a read, edit or write's title) and its diff lines are refs: hover one and click to open the current file in your editor at that line, on this machine only (`web.editor`; the browser's "always allow" for the page's port and VS Code's "allow opening local files" are asked once; see [Opening files from chi web](configuration.md#opening-files-from-chi-web)). So are an edit or write approval card's paths (at the first line the dry run changes) and its diff lines, before you approve, and the numbered lines of a read's output: `lines 40–60` under it opens the text as read, numbered, when the output is the file as-is (not the head/tail preview of a big file, an error or an image; no numbers after a cut). A `path:line` (or `path:line-line`) in an answer or a step's text is one too once the turn has ended, and after a reload, when it names a file a row or card on the page touched: the path under the session's folder, else the one touched file it ends with (a bare `app.js:12` when only one touched file is named so; two such files make it none); a path without a line counts only when it is a touched file exactly. Code blocks, links (a github-pr link to the PR stays the PR's), bare URLs and inline code with more than the ref in it are left alone, and a file the session didn't touch is never linked. The info bar copies `chi --attach <id>` for a terminal. A session whose prompt carried model notes has a `notes: deepseek` chip there (the names without `model_notes_`; the tooltip lists each with its scope and size; `session.prompt_notes` in `GET /api/sessions/:id`, the live worker's, else the session file's; see [Memory](memory.md#model-notes)). Its `llm ctx` chip names the LLM context strategy the next turn runs under (`llm ctx stale,forget · session`, in the accent colour when the session set its own; the tooltip gives each value's source), and its popover sets the session's own strategy, apply rule and budget, or follows the model again, by running `/llm-context` in the worker (the reply shows as a command bubble); `GET /api/sessions/:id`'s `session.llm_context` carries the values (the live worker's, else resolved from the session file), and a `command_ran` that changed them carries the new ones. Its `think` chip does the same for the thinking level (`/thinking`), and on a chat host its `reasoning` chip for the reasoning history (`reasoning all · session`, `/reasoning-history`; `session.reasoning_history`, null on a native host). A `/thinking` or `/reasoning-history` change that restarts the prompt cache asks first: the reply bubble has an **Apply (restarts the cache)** button that sends its `--yes` line (the chips' Set sends that line itself; see [Changes that restart the prompt cache](configuration.md#changes-that-restart-the-prompt-cache)). It shows the context used (`ctx 42%`) and the last generation's decode speed (`87 tok/s`, `~64 tok/s` when estimated; see `/stats` in [cli.md](cli.md#session-commands)); hovering `ctx` there or on a session card lists the session's tokens in (summed over every request, with the cached share), out (with reasoning) and the cost when the provider reports one, for this session only (one estimated from a `hosts.<name>.models` price shows with `~`: `cost: ~$0.54 ($0.42 reported, ~$0.12 estimated)`), and the memory indexes its prompt holds (`memory index: ~3.4k tokens in this session's prompt (system 2.0k, project 1.4k)`; see [Memory](memory.md#the-indexs-size)). The start page's model picker (bottom left of the composer, the chosen name `▾`) chooses the model a new chat starts on; it opens a search list over the conversation (↓ or a click; downward when the start page leaves no room above): an empty search shows the last 5 picks (Recent) and then each host's model ids A–Z under the host, the default host first (an id the host declares under `hosts.<name>.models` first, noted `config`, its tooltip `served by config (hosts.<name>.models)`; a host that failed to list its models keeps those ids, greyed and noted `host down`, still pickable; a remembered or default model stays chosen even then, greyed on the button); typed words must each match the host or the id (a substring, else for 3+ characters the letters in order, so `deepseek4.1 fla` finds `openrouter · deepseek/deepseek-v4.1-flash`), ⏎ picks, Esc/Tab close, a pick puts the focus in the message box: `GET /api/models` lists the hosts' models as chi spells them (`{default, models: [{name, host, id, configured?, unavailable?, sampling?, llm_context?}], warning?}`; `configured: true` marks an id declared under `hosts.<name>.models`, listed first under its host, `unavailable: true` one whose host failed to list its models; `sampling` is the model's configured request parameters as `/model` words them, the row's tooltip in the list; bare for the default host, `host:model` for the others, from the same cached lists as `/models`, a bounded wait, a host that is down noted in `warning`), and `POST /api/sessions` takes `model` (blank means the default). Beside it, an `llm ctx` chip shows the LLM context the picked model starts under (each `GET /api/models` row's `llm_context`, as the info bar's); its form sets one for the new chat only, sent as `POST /api/sessions`'s `llm_context` and never remembered (see [configuration.md](configuration.md#llm-context-a-sessions-own-strategy)). The start page's first message goes as later ones do: `POST /api/sessions` with `idle: true` and `preview` (the message, which names the session until its turn is saved), then `POST /api/sessions/:id/turn`, so a failed first turn puts its prompt back in the composer too; a first line that is one of the new session's commands (`/model …`) goes to `POST /api/sessions/:id/command` instead, as later ones do. The browser remembers the last model picked; a running session's model is in the info bar and changes only with `/model`. In the composer a line is a command when it is `!…` or starts with one of the session's command names (its `commands` list; `/stats`, `/exit` and the other terminal words get the page's own reply); an unknown `/word` (`/usr/bin/env is missing`) goes to the model as a prompt, as in a terminal; a one-word `/word` no command answers (`/modle`) is not sent: the page shows `Unknown command /modle. Did you mean /model? /help lists the commands.` (the "Did you mean" part only when a name is close). A `POST /turn` (or a session's first `prompt`) that is one of the worker's commands runs as that command too (`202 {status, command_id, session_id}`), so `chi send`, `chi -p` and a page whose command list lags all get the command. ↑/↓ in the composer walk the prompt history the TUI's ↑ walks ([Persistent Prompt History](cli.md#persistent-prompt-history)): ↑ with the caret on the first line, ↓ from the last line while browsing, ↓ past the newest brings the draft back; `GET /api/history` returns `{entries: [...]}`, oldest first (the page fetches it on focus and after each send). The server records a sent line in the routes once the worker took it (`POST /turn` accepted, a `!command` through `POST /command` or as a session's first line); `"history": false` in the body keeps it out (an image-only send).
72
72
  - Web notifications: when a session needs you while the tab is hidden or behind another window (a question or a guardrail approval, a plugin card with buttons during a turn such as check-in's, a failed turn, a turn done after 10 s or more; a delegated session only for its questions, a canceled turn never), the page title counts it, `(N) Chi`, until you come back to the tab. The bell at the right of the top bar also turns on OS notifications ("needs an answer", "needs approval", "needs you", "turn failed", "done in 42 s", under the session's first message; a click opens the session): its first click asks the browser for the permission, and the choice is kept per browser. Any session of the page's scope counts, not only the open one. What was already so when the page loaded never counts, and several chi tabs show one notification per event. A chi tab in front tells the others (a `BroadcastChannel`), so while you look at one, the ones behind neither notify nor count what it shows; coming back to a tab clears those events in the other tabs' titles too. The hub's `session` frames carry what this needs: `pending_question` (`{id, kind}`, kind `question` or `approval`), `pending_card` (`{id, bundle}`: the running turn's card with actions, from `pending_card.json` that the worker keeps in the session's folder while one is open; a card without actions, such as loop-guard's, never counts) and `last_turn` (`{outcome, ended_at, seconds, origin}`, saved in the session's JSON as the engine ends each turn).
73
73
  - The web frontend is a zero-build ES-module stack in `lib/samagotchi/web/public/`: `data.js` (retrieval, typed SSE `openStream` for a session and `openEvents` for the session list), `sessions_list.js` (the list as a pure reducer over `GET /api/events`: a snapshot replaces it, an upsert keeps a known card in place, a removal drops it; `families()` groups delegates under their parent), `families_view.js` (a parent's family chip, its rows and the strip's popover), `chains.js` (session chains: the links from `continues`, the cards folded into the latest link's, its `day N` chip and rows, the info bar's ← → links, a refused continue), `notify.js` (which of those events needs the user, for the notifications), `app.js` (presentation/state; a session with no live stream gets one when its `session` event says `bridge_up`, after one re-read: `event_seq` starts over in each worker, so a dropped stream is never resumed with its old cursor), `format.js` (pure formatters such as `previewOf`), `prompt_history.js` (the composer's ↑/↓ over the shared prompt history), `commands.js` (session commands: which composer lines are commands, the page's own replies, a `command_ran`'s bubble, the page's command bubbles kept across a re-read), `composer.js` (where a composer line goes, `routeComposerLine`: /cut and /queue, the start page's own replies, a session command or `!cmd`, a typo hint, else a turn; and a session command sent from the composer or a chip), `restore.js` (a failed turn's prompt handed back into this tab's composer, before or after its `/turn` ack), `lists_view.js` (the session lists: the strip and its pill, all sessions with its search, count and select mode, their cards, the family and chain popovers; the cards, tile and pill as lit-html templates, drawn as new nodes each time, and the lists' orders as pure functions), `stream_handlers.js` (the open session's stream event handlers, by event type, over the page's views and hooks; a snapshot replays through them too), `info_bar.js` (the session bar's info line as a lit-html template over a plain model: id, status, model, chain links, chips, ctx, speed, clock, worker badge), `session_state.js` (what the page knows about the open session: its empty state, and `sessionStateFrom`, the fields a `GET /sessions/:id` payload sets), `refs.js` (refs: a kind and a target on the element, the actions per kind, one delegated click). Unit-tested via `npm test` (`node --test spec/web/public/*.test.js`).
74
74
  - Selecting a session in the web UI is read-only: `GET /api/sessions/:id` never spawns a worker (it reads a live worker's snapshot when one runs, else the session file). A prompt (`POST /turn`) or a command (`POST /command`) wakes the worker, and `/stream` briefly waits for a freshly-spawned bridge before answering. A caught-up SSE reconnect holds the stream open; `reset` markers are only sent for reconnects behind the ring window, or with a cursor from another worker (event ids are `<event_seq>-<epoch>`, one epoch per worker).
@@ -7,6 +7,7 @@ require "ipaddr"
7
7
  require_relative "../atomic_file"
8
8
  require_relative "../config"
9
9
  require_relative "../yaml_lines"
10
+ require_relative "../redacted_inspect"
10
11
 
11
12
  module Samagotchi
12
13
  module Bootstrap
@@ -17,6 +18,7 @@ module Samagotchi
17
18
  # other key must be unchanged, or the backup goes back.
18
19
  class ConfigWriter
19
20
  include YAMLLines
21
+ include RedactedInspect
20
22
 
21
23
  class Error < StandardError
22
24
  end
@@ -9,6 +9,7 @@ require_relative "../version"
9
9
  require_relative "../llm/openai_chat"
10
10
  require_relative "../llm/http"
11
11
  require_relative "../llm/api_key"
12
+ require_relative "../redacted_inspect"
12
13
 
13
14
  module Samagotchi
14
15
  module Bootstrap
@@ -17,6 +18,8 @@ module Samagotchi
17
18
  # API key, or nothing. One attempt per request, no retries: a refused
18
19
  # port answers at once instead of after chi's usual backoff.
19
20
  class Probe
21
+ include RedactedInspect
22
+
20
23
  # The ports `chi bootstrap` with no target tries on localhost.
21
24
  LOCAL_PORTS = { 8080 => "llama.cpp", 11_434 => "Ollama", 1234 => "LM Studio", 8000 => "vLLM" }.freeze
22
25
  DEFAULT_PORT = 8080
@@ -9,6 +9,7 @@ require_relative "bootstrap/config_writer"
9
9
  require_relative "bootstrap/bundles"
10
10
  require_relative "cli/command"
11
11
  require_relative "cli/flags"
12
+ require_relative "redacted_inspect"
12
13
 
13
14
  module Samagotchi
14
15
  # `chi bootstrap [TARGET]`: the first setup. It names a model server, works
@@ -19,6 +20,7 @@ module Samagotchi
19
20
  # Prompts only on a terminal; a script gets the list and exit 2 instead.
20
21
  class BootstrapCommand
21
22
  include CLI::Command
23
+ include RedactedInspect
22
24
 
23
25
  USAGE = <<~TEXT
24
26
  Usage: chi bootstrap [TARGET] [--name NAME] [--model ID] [--key-env VAR] [--no-test] [--dry-run]
@@ -13,6 +13,7 @@ require_relative "broadcast/triage_model"
13
13
  require_relative "broadcast/triage_log"
14
14
  require_relative "cli/command"
15
15
  require_relative "cli/flags"
16
+ require_relative "redacted_inspect"
16
17
 
17
18
  module Samagotchi
18
19
  # `chi broadcast`: share a note with every session it may concern,
@@ -25,6 +26,7 @@ module Samagotchi
25
26
  # skipped. For the user only: refused inside a chi session.
26
27
  class BroadcastCommand
27
28
  include CLI::Command
29
+ include RedactedInspect
28
30
 
29
31
  SOURCE = "broadcast"
30
32
  # Bytes kept free under SessionInbox's 16 KiB for the line each note