samagotchi 0.68.0 → 0.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -1
- data/docs/architecture.md +1 -1
- data/docs/cli.md +6 -1
- data/docs/configuration.md +28 -6
- data/docs/guardrails.md +23 -1
- data/docs/hooks.md +4 -0
- data/docs/internals/bundles.md +1 -1
- data/docs/internals/engine.md +15 -8
- data/docs/internals/prompt-caching.md +9 -2
- data/docs/plugins.md +42 -19
- data/docs/releasing.md +14 -6
- data/docs/sessions.md +3 -3
- data/docs/testing.md +7 -1
- data/lib/samagotchi/bootstrap/probe.rb +1 -3
- data/lib/samagotchi/bundles/system/manifest.yml +2 -2
- data/lib/samagotchi/bundles/system/self_map.md +1 -1
- data/lib/samagotchi/config.rb +0 -19
- data/lib/samagotchi/engine.rb +5 -2
- data/lib/samagotchi/guardrails/targets.rb +9 -2
- data/lib/samagotchi/host_config.rb +1 -29
- data/lib/samagotchi/host_model.rb +0 -7
- data/lib/samagotchi/kernel_loop.rb +24 -7
- data/lib/samagotchi/llm/errors.rb +47 -1
- data/lib/samagotchi/llm/http.rb +20 -2
- data/lib/samagotchi/llm_context_stale.rb +6 -0
- data/lib/samagotchi/memory_bundle/manifest.rb +3 -0
- data/lib/samagotchi/model_price.rb +2 -4
- data/lib/samagotchi/session_metrics.rb +4 -1
- data/lib/samagotchi/system_prompt.rb +19 -3
- data/lib/samagotchi/terminal_ui/formatting.rb +5 -2
- data/lib/samagotchi/tool_activity.rb +3 -0
- data/lib/samagotchi/tool_row_fields.rb +4 -2
- data/lib/samagotchi/tool_runner.rb +24 -3
- data/lib/samagotchi/toolkit.rb +27 -14
- data/lib/samagotchi/toolkit_binding.rb +8 -2
- data/lib/samagotchi/toolkit_command.rb +20 -4
- data/lib/samagotchi/tools/builtin_calls.rb +45 -1
- data/lib/samagotchi/tools/registry.rb +95 -8
- data/lib/samagotchi/tools/tool_index.rb +223 -72
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +14 -9
- data/lib/samagotchi/web/message_parts.rb +5 -2
- data/lib/samagotchi/web/public/activity.js +3 -1
- data/lib/samagotchi/web/public/app.js +123 -22
- data/lib/samagotchi/web/public/chains.js +19 -2
- data/lib/samagotchi/web/public/families_view.js +15 -0
- data/lib/samagotchi/web/public/index.html +7 -5
- data/lib/samagotchi/web/public/model_picker.js +21 -6
- data/lib/samagotchi/web/public/session_state.js +5 -0
- data/lib/samagotchi/web/public/stream_handlers.js +5 -2
- data/lib/samagotchi/web/public/timing.js +3 -1
- data/lib/samagotchi/web/public/toast_place.js +16 -0
- data/lib/samagotchi/web/public/toolkit_chip.js +11 -4
- data/lib/samagotchi/web/public/turn_html.js +4 -2
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5ef7820f894e85b932288a38a22e1f312e01b5f4f1d100996acde11443baab19
|
|
4
|
+
data.tar.gz: 44f15fe12934aa7c56bff657e8b93a1d0165a752bcf0715f71cb04bb17ed7ac6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38d2aebcc7f777a40ceb1f0008c0160fd374541ff97b74b44ba0d61611cf7e2a103a4398571327b26cd7ffa80d564a552166d74ecfca172788483b1b43d166c7
|
|
7
|
+
data.tar.gz: 64a08c7808f2a9d58cbd5135ebadef7f59157876d738c16a3b6793c9b424f8a6dca90454ea961672ce0e14a71f809026ac49ba51d1db0b1ff4389073a06fbd4e
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,46 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.69.0] - 2026-10-14
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Web: a new chain link (continue →) shows the model picker in its composer until its first turn, so the next link can
|
|
16
|
+
start on another model or provider; the continue toast shows the fallback warning when the previous model's host is
|
|
17
|
+
gone.
|
|
18
|
+
- Built-ins a session's toolkit leaves out are reachable: `find_tools` searches them (group `chi`) beside MCP
|
|
19
|
+
servers' tools, and `call_tool` runs them through the usual guardrails as the real call. `remove:` /
|
|
20
|
+
`--no-tool` / `/toolkit remove` stay hard.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- find_tools' description and its `server` parameter (now `group`) changed: sessions with MCP servers read their
|
|
25
|
+
prompt again once. So do sessions on `lean`, `child`, `coordinator` or a kit based on them: they now declare
|
|
26
|
+
`find_tools` and `call_tool`, and their not-loaded line changed.
|
|
27
|
+
- A toolkit based on `lean` or `child` (a `toolkit.kits` entry, a bundle's `chi.toolkit`) no longer keeps the
|
|
28
|
+
built-ins its base leaves out from the model: they're reachable through `find_tools` / `call_tool`, guarded as
|
|
29
|
+
themselves. Name one under `remove:` to keep it out.
|
|
30
|
+
- Guardrail rules on `call_tool` no longer see calls of chi's own tools made through it; they match the tool's own
|
|
31
|
+
name.
|
|
32
|
+
- Shipped bundles: a change that needs a newer chi marks the manifest `requires_chi_next` instead of raising
|
|
33
|
+
`requires_chi`; `rake release:bump` raises it to the released version and `rake release:check` fails on a marker
|
|
34
|
+
left over.
|
|
35
|
+
- `/toolkit remove X` on a tool the toolkit leaves out is saved (it makes X unreachable). `/toolkit add X` then
|
|
36
|
+
`/toolkit remove X` now removes X (it used to go back to the kit's default), and a remove then an add declares X.
|
|
37
|
+
- The `child` toolkit also removes `delegate` and `delegate_result`: a child on it can't start children, even
|
|
38
|
+
through call_tool.
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
|
|
42
|
+
- A TLS handshake blip on a gateway (`SSL_connect … unexpected eof`, a reset mid-handshake) is retried like other
|
|
43
|
+
network errors instead of failing the turn at once; a certificate chi doesn't trust, a certificate for another
|
|
44
|
+
name, or an `https://` base_url on a plain HTTP port fails at once, saying what to check (`SSL_CERT_FILE`, the
|
|
45
|
+
host's base_url).
|
|
46
|
+
- A bundle tool named like an MCP tool (`mcp_fs_read`) no longer takes `call_tool` calls of that MCP tool out of
|
|
47
|
+
`mcp_*` rules.
|
|
48
|
+
- Web: on a phone the start page's model, thinking and LLM context chips wrap instead of being cut short; a toast no
|
|
49
|
+
longer covers a fresh link's open model panel; the family popover's status dots keep pulsing in step.
|
|
50
|
+
|
|
11
51
|
## [0.68.0] - 2026-10-14
|
|
12
52
|
|
|
13
53
|
### Changed
|
|
@@ -2956,7 +2996,8 @@ and long-lived sessions.
|
|
|
2956
2996
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
2957
2997
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
2958
2998
|
|
|
2959
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
2999
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.69.0...HEAD
|
|
3000
|
+
[0.69.0]: https://github.com/dm1try/samagotchi/compare/v0.68.0...v0.69.0
|
|
2960
3001
|
[0.68.0]: https://github.com/dm1try/samagotchi/compare/v0.67.0...v0.68.0
|
|
2961
3002
|
[0.67.0]: https://github.com/dm1try/samagotchi/compare/v0.66.0...v0.67.0
|
|
2962
3003
|
[0.66.0]: https://github.com/dm1try/samagotchi/compare/v0.65.0...v0.66.0
|
data/docs/architecture.md
CHANGED
|
@@ -452,7 +452,7 @@ message (docs/internals/context-telemetry.md).
|
|
|
452
452
|
`HostRegistry#adapter_for`, built by `LLM::Adapters` from the host's api) share
|
|
453
453
|
`LLM::HTTP`: timeouts, TLS for https, a line reader for streamed bodies, the retry loop (`retry.*`; network errors, 429 and
|
|
454
454
|
500/502/503/504/529, honouring `Retry-After`; never after a stream has produced
|
|
455
|
-
output) and cancel. Cancel closes the in-flight socket from the
|
|
455
|
+
output; a refused connection and a TLS handshake that can't work, `LLM::TLSError`, fail at once) and cancel. Cancel closes the in-flight socket from the
|
|
456
456
|
`CancellationController` listener, so it works on any thread.
|
|
457
457
|
|
|
458
458
|
`LLM::AnthropicMessages` talks Anthropic's Messages API (`POST {root}/v1/messages`) for the same chat loop:
|
data/docs/cli.md
CHANGED
|
@@ -517,7 +517,12 @@ line, the web as the `reasoning` chip. See "Reasoning history" in
|
|
|
517
517
|
[configuration.md](configuration.md).
|
|
518
518
|
|
|
519
519
|
`/toolkit` lists the tools the next turn declares (each with its estimated
|
|
520
|
-
tokens), the session's toolkit and the tools it leaves out
|
|
520
|
+
tokens), the session's toolkit and the tools it leaves out: `reachable
|
|
521
|
+
(find_tools): …` (built-ins the model reaches with find_tools and call_tool)
|
|
522
|
+
and `removed: …` (only `/toolkit add` brings one back), or `not loaded: …` when
|
|
523
|
+
the toolkit removes call_tool. `/toolkit remove TOOL` is hard: a tool the
|
|
524
|
+
toolkit left out reachable becomes unreachable (saved, and asked first once the
|
|
525
|
+
session has a model reply), also after an add. `/toolkit NAME` puts
|
|
521
526
|
the session on another toolkit (dropping its own adds and removes); `/toolkit
|
|
522
527
|
add TOOL` and `/toolkit remove TOOL` change one tool (a tool's name keeps its
|
|
523
528
|
case). The change is saved at once and applies from the next turn's start; a
|
data/docs/configuration.md
CHANGED
|
@@ -988,8 +988,8 @@ Transient network failures are retried automatically with exponential backoff.
|
|
|
988
988
|
|
|
989
989
|
- Default retries: `5` (up to `6` total attempts including the first call).
|
|
990
990
|
- Default backoff: `0.5s`, `1s`, `2s`, `4s`, `8s`.
|
|
991
|
-
- Retry scope: transient network errors (timeouts, reset connections, EOF/socket reachability
|
|
992
|
-
HTTP 429 and HTTP 500/502/503/504/529. A `Retry-After` header replaces the backoff delay; one longer than
|
|
991
|
+
- Retry scope: transient network errors (timeouts, reset connections, broken pipes, EOF/socket reachability
|
|
992
|
+
failures, a TLS handshake that drops: `SSL_connect … unexpected eof while reading`), HTTP 429 and HTTP 500/502/503/504/529. A `Retry-After` header replaces the backoff delay; one longer than
|
|
993
993
|
60s is not waited out and the error is reported instead.
|
|
994
994
|
- An HTTP 402 about credit held by in-flight requests (OpenRouter reserves credit for each running request, so
|
|
995
995
|
one session's long request can make another's fail) is retried like a 429, 20s apart unless `Retry-After`
|
|
@@ -998,6 +998,11 @@ Transient network failures are retried automatically with exponential backoff.
|
|
|
998
998
|
budget, so it fails at once (lower `default.max_tokens` or raise the key's limit).
|
|
999
999
|
- A refused connection (nothing listening) is not retried: the turn fails at once with `can't reach host <name> at
|
|
1000
1000
|
<address> (connection refused) — is the server running?`.
|
|
1001
|
+
- Nor is a TLS handshake that can't work, which fails at once saying what to check: a certificate chi doesn't
|
|
1002
|
+
trust (`certificate verify failed (self-signed certificate)`, `unable to get local issuer certificate`, an expired
|
|
1003
|
+
one: set `SSL_CERT_FILE` to a CA bundle that has the gateway's CA), a certificate for another name (`hostname
|
|
1004
|
+
mismatch`: check the host's `base_url`), or a server that doesn't speak TLS there (`wrong version number`: an
|
|
1005
|
+
`https://` base_url on a plain HTTP port; should it be `http://`?).
|
|
1001
1006
|
- A stream that has already produced output is never retried at the transport (the retry would repeat it). The
|
|
1002
1007
|
chat loop (an OpenAI-compatible host) drops the partial reply and asks again for the whole step, from the same
|
|
1003
1008
|
conversation, at most twice (at most `retry.max` times when that is smaller: `retry.max: 0` turns it off), after
|
|
@@ -1331,7 +1336,7 @@ toolkit:
|
|
|
1331
1336
|
|---|---|
|
|
1332
1337
|
| `full` | every built-in; the default |
|
|
1333
1338
|
| `lean` | `execute`, `read`, `write`, `edit`, `memory_read`, `memory_write`, `task_create`, `task_wait`, `task_get`, `task_list`, `task_stop`, `ask_user_question`, `web_fetch`, `context_read` |
|
|
1334
|
-
| `child` | `lean` plus `send_note`, without `memory_write` |
|
|
1339
|
+
| `child` | `lean` plus `send_note`, without `memory_write`, `delegate`, `delegate_result` |
|
|
1335
1340
|
| `coordinator` | `lean` plus `delegate`, `delegate_result`, `list_sessions` (declared by the coordinator bundle) |
|
|
1336
1341
|
|
|
1337
1342
|
- **Plugin tools** are declared in every toolkit unless its `remove:` names them, and so is `forget_outputs` under
|
|
@@ -1342,9 +1347,26 @@ toolkit:
|
|
|
1342
1347
|
for a delegate child, or `chi --toolkit NAME` / `--tool` / `--no-tool` ([cli](cli.md)). Changing `toolkit.default`
|
|
1343
1348
|
doesn't move existing sessions, not even when their worker is woken again; a session from before toolkits is on
|
|
1344
1349
|
`full`. A continue and a fork keep the toolkit. `/toolkit` shows and changes it.
|
|
1345
|
-
- **
|
|
1346
|
-
|
|
1347
|
-
the
|
|
1350
|
+
- **Left out: reachable or removed.** A built-in missing from a kit's base list (`lean` has no `delegate`; a
|
|
1351
|
+
`kits:` entry on `base: lean` or `child` inherits that) is left out softly: it is **reachable**. `find_tools` searches it as group `chi` (`chi/delegate`, with its inputSchema) beside
|
|
1352
|
+
the MCP servers' tools, and `call_tool(tool: "chi/delegate", args: {…})` runs it as `delegate` itself, through the
|
|
1353
|
+
usual guardrails, approvals and hooks ([plugins](plugins.md#chitool_sourcecall-acts_as-label-wait-prefix)). A
|
|
1354
|
+
tool in a toolkit's `remove:`, a `--no-tool` or a `/toolkit remove` is **removed**: hard, also after an add, and
|
|
1355
|
+
call_tool can't reach it (`child` removes `memory_write`, `delegate` and `delegate_result`, so a child on it
|
|
1356
|
+
starts no children). To keep a built-in away from the model, name it under `remove:`. `find_tools` and `call_tool`
|
|
1357
|
+
are declared when a toolkit has a reachable built-in (or an MCP server is configured); `full` with no MCP server
|
|
1358
|
+
declares neither.
|
|
1359
|
+
- **The prompt line.** One line after the base prompt names them: `Not declared in this session (toolkit lean): ….
|
|
1360
|
+
Search them with find_tools; call one with call_tool.`, then `Removed (toolkit child): memory_write, …. Only the
|
|
1361
|
+
user can load one (/toolkit add <name>).` With `find_tools` removed, the first sentence ends `Call one with
|
|
1362
|
+
call_tool(tool: "chi/<name>", args: {…}).` instead. With `call_tool` itself removed, nothing is reachable and one
|
|
1363
|
+
line names them all: `Not loaded in this session (toolkit lean): …. Only the user can load one (/toolkit add
|
|
1364
|
+
<name>).`
|
|
1365
|
+
- **Calls by name.** A direct call of a reachable tool is refused before the guardrails (no approval card), with
|
|
1366
|
+
the route: `Error: delegate isn't declared in this session (toolkit lean); call it with call_tool(tool:
|
|
1367
|
+
"chi/delegate", args: {…}) (find_tools gives its inputSchema).` A removed tool's: `Error: memory_write isn't
|
|
1368
|
+
loaded in this session (toolkit child) and can't be loaded from here; only the user can (/toolkit add
|
|
1369
|
+
memory_write).` `/toolkit` lists both kinds, and the web's toolkit chip says them in its tooltip.
|
|
1348
1370
|
- **Applied at a turn's start.** A change (`/toolkit`, a plugin's `ctx.use_toolkit`) is saved at once and the next
|
|
1349
1371
|
turn declares it; once the session has a model reply, `/toolkit` asks first ("Changes that restart the prompt
|
|
1350
1372
|
cache").
|
data/docs/guardrails.md
CHANGED
|
@@ -303,7 +303,7 @@ A plugin tool that runs other tools for the model (a dispatcher such as
|
|
|
303
303
|
and with which arguments (`args:`). A rule's `tool:` then matches the call's
|
|
304
304
|
own name **or** the tool it acts as: `tool: mcp_github_*` fires for a
|
|
305
305
|
`call_tool` that acts as `mcp_github_merge_pull_request`, and `tool: call_tool`
|
|
306
|
-
fires whatever it acts as. The question names the tool it acts as (by the
|
|
306
|
+
fires whatever MCP tool it acts as. The question names the tool it acts as (by the
|
|
307
307
|
`label:` its `targets:` gives, if any: display only) and shows its arguments, and an approval of "this call" is keyed by the real name, the
|
|
308
308
|
alias and those arguments (`/guardrails` lists it as
|
|
309
309
|
`call_tool>mcp_github_merge_pull_request:number=7 …`), so it never covers a
|
|
@@ -313,6 +313,28 @@ one of chi's own tools or another bundle's tool: that `acts_as:` is dropped
|
|
|
313
313
|
name only. Hooks and loop-guard's `ignore_tools` still see the call's own
|
|
314
314
|
name.
|
|
315
315
|
|
|
316
|
+
chi's `call_tool` is exempt from the "another bundle's tool" drop (not the
|
|
317
|
+
core-tool one): its `acts_as` is always a tool its sources published, so a
|
|
318
|
+
bundle tool that happens to share an MCP tool's `mcp_<server>_<tool>` name
|
|
319
|
+
can't take `call_tool` calls of that MCP tool out of your `mcp_*` rules. The
|
|
320
|
+
trade-off, when such a clash exists:
|
|
321
|
+
- an `allow` or `ask` rule by that name matches both the bundle tool and the
|
|
322
|
+
MCP call;
|
|
323
|
+
- a `rule`-scope approval ("always for this rule") covers both, because it
|
|
324
|
+
matches by rule, source and place, not by tool;
|
|
325
|
+
- `session` and `repo` approvals stay distinct (`call_tool>mcp_x:…` vs
|
|
326
|
+
`mcp_x:…`);
|
|
327
|
+
- deny rules cover both, which is the point.
|
|
328
|
+
|
|
329
|
+
A `call_tool` of one of chi's own tools (`chi/delegate`: a built-in the
|
|
330
|
+
session's toolkit leaves out, [toolkits](configuration.md#toolkits)) is
|
|
331
|
+
gated **as that tool**: it is turned into the `delegate` call before the
|
|
332
|
+
guardrails run, so every rule on `delegate` (or `execute`'s `command:`, the
|
|
333
|
+
`rm` check, a delegate child's boundary) gives the same verdict as for a
|
|
334
|
+
direct call, and an approval is keyed `delegate:…` either way. `tool:
|
|
335
|
+
call_tool` rules no longer see such calls, only MCP calls and misses. A
|
|
336
|
+
`chi/` name the toolkit removes is refused before the gate, with no card.
|
|
337
|
+
|
|
316
338
|
```yaml
|
|
317
339
|
- id: mcp-ask
|
|
318
340
|
# every MCP call (call_tool, acting as mcp_<server>_<tool>); not a find_tools search.
|
data/docs/hooks.md
CHANGED
|
@@ -536,6 +536,10 @@ A `write`'s `content:` is the file text; an `edit` carries `old_text:` and
|
|
|
536
536
|
arguments whole on `args:` (string keys) instead, and its `content:` is those
|
|
537
537
|
arguments as JSON. An MCP tool's call is chi's `call_tool` (its tool index's, which the mcp
|
|
538
538
|
bundle runs): `tool: "call_tool"`, with `args: {"tool" => "<server>/<tool>", "args" => {…}}`.
|
|
539
|
+
A built-in reached through `call_tool` (`chi/delegate`, a tool the session's toolkit doesn't
|
|
540
|
+
declare) fires as that built-in, its call built as a direct call's, with `call[:via] == "call_tool"`.
|
|
541
|
+
A hook that drops `via:` or rewrites the call to a tool the toolkit removes gets the call refused
|
|
542
|
+
by its name.
|
|
539
543
|
|
|
540
544
|
## Bundle Hooks (unified workflow bundle)
|
|
541
545
|
|
data/docs/internals/bundles.md
CHANGED
|
@@ -24,7 +24,7 @@ user-facing side (what a bundle owns, profiles, needs) is in [memory.md](../memo
|
|
|
24
24
|
|---|---|
|
|
25
25
|
| `BundleCommand` (`lib/samagotchi/bundle_command.rb`) | `chi bundle install/upgrade/uninstall/status/diff/list/build/trash`; runs the Installer, prints its summary, runs the conflict agent step |
|
|
26
26
|
| `SourceNormalizer` (source.rb) | source → local dir; a git/zip/tar extract is *owned* and removed after the install |
|
|
27
|
-
| `Manifest` | parses/validates `manifest.yml` (files, hooks as `BundleHook`, plugin, scripts, needs, requires_chi, includes, context_providers) and writes it (`Manifest.write`, for Builder) |
|
|
27
|
+
| `Manifest` | parses/validates `manifest.yml` (files, hooks as `BundleHook`, plugin, scripts, needs, requires_chi, includes, context_providers) and writes it (`Manifest.write`, for Builder). It ignores `requires_chi_next`, a shipped bundle's release-time marker (`script/release/release_tools.rb`, docs/releasing.md) |
|
|
28
28
|
| `Installer` | one install/upgrade/dry run of one bundle (below) |
|
|
29
29
|
| `AssetInstaller` | the parts that live in `.bundles/<name>/`: hooks, guardrail rules, plugin, scripts; returns `AssetInstaller::Installed` (the paths the record keeps) |
|
|
30
30
|
| `Merger` | 3-way classification per file: `install`, `fast_forward`, `keep`, `noop`, `conflict` |
|
data/docs/internals/engine.md
CHANGED
|
@@ -37,7 +37,8 @@ Engine#run_turn(session, prompt, on_event:, max_iterations:, cancel_controller:,
|
|
|
37
37
|
│ # turn.settings = LLM::TurnSettings (vision, sampling, thinking; model_name is set in generate),
|
|
38
38
|
│ # from one EffectiveModel; ThinkingNotices#turn_started keeps the level and says one the host can't do
|
|
39
39
|
│ # announces guardrail load failures, starts and awaits plugin init tasks, applies staged tools,
|
|
40
|
-
│ # then the session's toolkit (apply_toolkit!: Registry#toolkit,
|
|
40
|
+
│ # then the session's toolkit (apply_toolkit!: Registry#toolkit, ToolIndex#refresh! for find_tools'
|
|
41
|
+
│ # chi line, a prompt rebuild when it changed)
|
|
41
42
|
│ # fires the :session_start hook on the Engine's first turn, then the :before_turn hook
|
|
42
43
|
│ # (a frozen copy of the history, the prompt, and resumed)
|
|
43
44
|
│ # turn_messages: system head + history + due reminders (:reminder_injected) + the user message
|
|
@@ -255,8 +256,11 @@ One iteration with tool calls:
|
|
|
255
256
|
→ :tool_dispatch_started {iteration, call_count}
|
|
256
257
|
→ for each call: ToolRunner#run(call, iteration:, call_index:, call_count:,
|
|
257
258
|
on_stream_event:, max_tool_output_chars:)
|
|
258
|
-
→
|
|
259
|
-
|
|
259
|
+
→ first, the call's entry unwraps it (Registry::Entry#unwrap: a call_tool of chi/<built-in> becomes
|
|
260
|
+
that built-in's call with via: "call_tool", ToolIndex#unwrap); the rest sees the real call
|
|
261
|
+
→ a tool the session's toolkit leaves out (Registry#left_out; with via:, one Registry#indexed doesn't
|
|
262
|
+
reach) skips the gate: no hooks, no card; KernelLoop#dispatch answers it (the call_tool route for a
|
|
263
|
+
reachable tool, the not-loaded error for a removed one)
|
|
260
264
|
→ Guardrails::Gate#evaluate (the before_tool_call hooks, then the core checks)
|
|
261
265
|
→ :tool_call_started
|
|
262
266
|
→ an ask verdict: Gate#settle_ask (asks the user, records waited_ms)
|
|
@@ -273,11 +277,13 @@ One iteration with tool calls:
|
|
|
273
277
|
```
|
|
274
278
|
|
|
275
279
|
**ToolRunner** (`ToolRunner#run`):
|
|
280
|
+
- Unwraps a call_tool of a built-in first (`Registry::Entry#unwrap`), so `original`, the params and the label
|
|
281
|
+
are the built-in's and no "ran as:" line follows.
|
|
276
282
|
- Runs the gate first, so `:tool_call_started` shows the call that will run (a before_tool_call hook may
|
|
277
283
|
replace it; known-names corrects a misspelled name this way, and the model gets one line saying what ran).
|
|
278
284
|
- Emits `:tool_call_started` {iteration, call_count, call_index, tool, call, params, label (plugin tools),
|
|
279
|
-
title, called_as, view, ref, refs}. The row fields (title, called_as, view, ref) come from `ToolRowFields.for`, which the
|
|
280
|
-
reload (`Web::MessageParts#tool_part`) calls too. `ToolRowFields::ACTIVITY_KEYS` (title, called_as) travel
|
|
285
|
+
title, called_as, via, view, ref, refs}. The row fields (title, called_as, via, view, ref) come from `ToolRowFields.for`, which the
|
|
286
|
+
reload (`Web::MessageParts#tool_part`, after `BuiltinCalls.unwrap_saved`) calls too. `ToolRowFields::ACTIVITY_KEYS` (title, called_as, via) travel
|
|
281
287
|
inside `activity` on the completed event; `EVENT_KEYS` (view, ref, refs) go top-level on both events.
|
|
282
288
|
`Bridge::TurnAccumulator` (snapshot and replay) and the web (`activity.js` `ACTIVITY_FIELDS` /
|
|
283
289
|
`EVENT_FIELDS`) copy them by these lists, so a new row field is added there. `ref` is `FileRef.for` (a
|
|
@@ -486,9 +492,10 @@ Engine initialization (in this order, among other things):
|
|
|
486
492
|
@toolkit_binding (ToolkitBinding: the kits, the plugins' among them, and the turn-start apply)
|
|
487
493
|
@extension_load = ExtensionLoad.new; @hooks = @extension_load.hooks (config.yml's, then the bundles')
|
|
488
494
|
@tools = Tools::Builtins.registry; the bundles' plugins load (load_plugins → ExtensionLoad#load_plugins),
|
|
489
|
-
then @tool_index.declare(@tools): find_tools + call_tool (source "index", not core)
|
|
490
|
-
|
|
491
|
-
the
|
|
495
|
+
then (plugins or not) @tool_index.declare(@tools): find_tools + call_tool (source "index", not core),
|
|
496
|
+
declared per toolkit by Registry#declared? (a source registered at load, or a reachable built-in) and
|
|
497
|
+
sets call_tool's unwrap (Tools::ToolIndex: the chi group from Registry#reachable_names, the sources'
|
|
498
|
+
groups, search, call checks, the unwrap; a source runs the call with its own plugin Context)
|
|
492
499
|
wire_kernel: @kernel = KernelLoop.new(client:, profile:, hooks:, reminder_store:, tools:)
|
|
493
500
|
@kernel.guardrail_gate = @guardrail_wiring.gate; @kernel.warmup = PromptWarmup.new
|
|
494
501
|
@hooks.runtime = @hook_routes.runtime (HookRoutes, built first: what a hook or plugin does reaches the UIs)
|
|
@@ -25,13 +25,14 @@ right-hand column happens.
|
|
|
25
25
|
┌──────────────────────────────────────────────────────────────────────────┐
|
|
26
26
|
│ tools built-ins, then plugin tools sorted by (bundle, name), │ a tool added/changed,
|
|
27
27
|
│ the tool index's find_tools/call_tool as bundle "index" │
|
|
28
|
-
│ (
|
|
28
|
+
│ (per toolkit; MCP lines from load, the chi line per toolkit)│
|
|
29
29
|
│ those the session's toolkit declares (per toolkit) │ /model, a profile change,
|
|
30
30
|
│ (chat: the `tools` field; native: the model's template) │ a toolkit change
|
|
31
31
|
├──────────────────────────────────────────────────────────────────────────┤
|
|
32
32
|
│ SYSTEM, stable part SystemPrompt#system_prompt_with_index
|
|
33
33
|
│ [native thinking token] base prompt │
|
|
34
|
-
│ not-loaded line (only when the toolkit leaves tools out
|
|
34
|
+
│ not-loaded line (only when the toolkit leaves tools out: │
|
|
35
|
+
│ not declared / removed) │
|
|
35
36
|
│ rg guidance │ /thinking level,
|
|
36
37
|
│ system identity (+ model overlay) │ /model, editing a
|
|
37
38
|
│ model notes (model_notes_* matching the model) │ memory / AGENTS.md
|
|
@@ -70,6 +71,12 @@ right-hand column happens.
|
|
|
70
71
|
beside `apply_staged_tools!`, then `reset!`): the chat loop builds `tools:` per request, so a mid-turn change
|
|
71
72
|
would differ from the turn's prompt. Under `full` nothing is filtered and no line is added: the bytes are what
|
|
72
73
|
they were before toolkits.
|
|
74
|
+
- find_tools' description is a function of the toolkit and the source groups **at load**: `ToolIndex#declare`
|
|
75
|
+
snapshots the MCP groups' lines (name, summary, callable count) and `ToolIndex#refresh!` (from
|
|
76
|
+
`ToolkitBinding#apply!`) rebuilds only the `chi` line, the built-ins the toolkit reaches. An MCP server that
|
|
77
|
+
finishes booting between load and the first turn changes search answers only, so two sessions on the same
|
|
78
|
+
toolkit with the same MCP cache send the same bytes. Whether find_tools/call_tool are declared at all reads the
|
|
79
|
+
same two things (`Registry#index_needed?`), never live groups.
|
|
73
80
|
- On remote Claude, `LLM::PromptCache.mark` sends the system message as two text parts. The stable part carries
|
|
74
81
|
breakpoint #1, so a **new session** reads it from the cache. The last non-system message carries breakpoint
|
|
75
82
|
#2, so the **next request in the session** reads everything up to it. Mid and tail system messages never take
|
data/docs/plugins.md
CHANGED
|
@@ -25,6 +25,8 @@ plugin:
|
|
|
25
25
|
file: plugin.rb
|
|
26
26
|
sha256: sha256:6a1a7022… # shasum -a 256 plugin.rb
|
|
27
27
|
requires_chi: ">= 0.1.28" # optional: a gem-style requirement (">= 0.1.28, < 0.2"); the bundle's hooks/ check it too
|
|
28
|
+
# requires_chi_next: true # shipped bundles only, ignored by chi: rake release:bump raises requires_chi
|
|
29
|
+
# to the chi being released (docs/releasing.md)
|
|
28
30
|
needs: [gh] # optional: outside commands it relies on (see memory.md#bundles-that-need-outside-commands)
|
|
29
31
|
```
|
|
30
32
|
|
|
@@ -294,6 +296,8 @@ is what `targets:` says:
|
|
|
294
296
|
(chi's `call_tool`, which calls a tool a [source](#chitool_sourcecall-acts_as-label-wait-prefix) published). Rules keyed by that tool's name match the
|
|
295
297
|
call too, as well as rules on the tool's own name. It can't be one of
|
|
296
298
|
chi's own tools or another bundle's tool: that is dropped (and logged).
|
|
299
|
+
The "another bundle's tool" drop doesn't apply to chi's `call_tool`: its
|
|
300
|
+
`acts_as` is always a tool its sources published.
|
|
297
301
|
- `args:`: the arguments it acts with (a Hash), when they aren't the call's
|
|
298
302
|
own (a dispatcher's inner arguments). A call with no `command:` or
|
|
299
303
|
`paths:` is asked about with them, and "allow this call" is keyed by them.
|
|
@@ -583,15 +587,32 @@ chi.toolkit "review", base: "lean", add: %w[delegate delegate_result]
|
|
|
583
587
|
|
|
584
588
|
Tools the model reaches through a search instead of declaring them one by
|
|
585
589
|
one: the plugin publishes them into chi's **tool index**, and chi declares
|
|
586
|
-
two tools in all, whatever the number of sources: `find_tools
|
|
587
|
-
search that answers each match's `inputSchema`) and
|
|
588
|
-
`<group>/<tool>`; its row label is the
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
590
|
+
two tools in all, whatever the number of sources: `find_tools(query,
|
|
591
|
+
group?)` (a keyword search that answers each match's `inputSchema`) and
|
|
592
|
+
`call_tool(tool, args)` (calls one as `<group>/<tool>`; its row label is the
|
|
593
|
+
first source's `label`). The index has one group of its own, **`chi`**: the
|
|
594
|
+
built-ins the session's toolkit leaves out but doesn't remove
|
|
595
|
+
([toolkits](configuration.md#toolkits)), each with its registered schema.
|
|
596
|
+
The two tools are registered once, after the plugins load, and declared per
|
|
597
|
+
toolkit: when a plugin registered a source then, or when the toolkit has a
|
|
598
|
+
reachable built-in (`full` with no source declares neither). Nothing a
|
|
599
|
+
source publishes later changes the request's tools, only what a search
|
|
600
|
+
answers, so the prompt cache keeps: the search tool's description lists the
|
|
601
|
+
source groups as they were at load, and a `chi` line first, per toolkit.
|
|
602
|
+
The mcp bundle is the only source so far (a group per server). A source's
|
|
603
|
+
group named `chi`, or named like an earlier group, is left out of search,
|
|
604
|
+
lookup and the description, with one warning per name.
|
|
605
|
+
|
|
606
|
+
**A built-in through `call_tool` runs as that built-in.** `call_tool(tool:
|
|
607
|
+
"chi/delegate", args: {…})` (or a bare `delegate` while it's reachable) is
|
|
608
|
+
turned into the `delegate` call itself before the guardrails, so rules on
|
|
609
|
+
`delegate`, approvals (keyed `delegate:…`, the same as a direct call's),
|
|
610
|
+
`before_tool_call`/`after_tool_call` hooks and the row see `delegate`, with
|
|
611
|
+
`call[:via] == "call_tool"`; the row reads "delegate (via call_tool)", live
|
|
612
|
+
and after a reload. `tool: call_tool` rules see MCP calls and misses only. A
|
|
613
|
+
`chi/` name the toolkit removes or declares, or any built-in once
|
|
614
|
+
`call_tool` itself is removed, is refused by its name before the guardrails
|
|
615
|
+
(no hook, no card).
|
|
595
616
|
|
|
596
617
|
```ruby
|
|
597
618
|
@source = chi.tool_source(label: "mcp", prefix: "mcp_",
|
|
@@ -621,7 +642,8 @@ index = Samagotchi::Tools::ToolIndex
|
|
|
621
642
|
block returns (a String, a `ToolResult` with images).
|
|
622
643
|
- **Guardrails** see a `call_tool` as the tool it calls: its `acts_as`, its
|
|
623
644
|
arguments and `"<group>: <tool>"` as the question's label
|
|
624
|
-
([acts_as:](#guardrails))
|
|
645
|
+
([acts_as:](#guardrails)), even when another bundle has a tool of that
|
|
646
|
+
name (only the core-tool drop applies). A call made before its tool is published is
|
|
625
647
|
named by `acts_as` from the names alone; a bare name with `prefix` is
|
|
626
648
|
taken as an `acts_as` as given. The `acts_as:` hook must give exactly the
|
|
627
649
|
`acts_as` the source publishes for that tool: a call whose tool isn't the
|
|
@@ -632,11 +654,11 @@ index = Samagotchi::Tools::ToolIndex
|
|
|
632
654
|
what the two tools take in every request (none when other tools had both
|
|
633
655
|
names). A `Group` in a state other than the three, holding another group's
|
|
634
656
|
tool, or a `Tool` with a blank `acts_as` raises `ArgumentError`.
|
|
635
|
-
- `find_tools` and `call_tool` aren't chi's own tools:
|
|
636
|
-
them (unless its `remove:` names
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
declares neither.
|
|
657
|
+
- `find_tools` and `call_tool` aren't chi's own tools: a toolkit that needs
|
|
658
|
+
them declares them (unless its `remove:` names one; `call_tool` stays
|
|
659
|
+
usable with `find_tools` removed). A bundle that declares tools of other
|
|
660
|
+
names itself (an mcp bundle before 0.7.0 has `find_mcp_tools` and
|
|
661
|
+
`mcp_call`) keeps them; with no source, `full` declares neither of chi's.
|
|
640
662
|
|
|
641
663
|
### `chi.peer_source(name, label:)`
|
|
642
664
|
|
|
@@ -1064,7 +1086,7 @@ bundles:
|
|
|
1064
1086
|
|
|
1065
1087
|
- **Tools: search, then call.** The servers' tools are kept in chi's tool index;
|
|
1066
1088
|
the model has two fixed tools:
|
|
1067
|
-
- `find_tools(query,
|
|
1089
|
+
- `find_tools(query, group?)` searches it by keywords over the
|
|
1068
1090
|
server's name, the tool's name and its description, and answers up to 5
|
|
1069
1091
|
tools, each with its name `<server>/<tool>`, its description and its
|
|
1070
1092
|
whole `inputSchema`. A word counts more the fewer tools have it (a word
|
|
@@ -1089,7 +1111,7 @@ bundles:
|
|
|
1089
1111
|
`args` are typed by the tool's
|
|
1090
1112
|
`inputSchema` (numbers and booleans given as text, JSON text for an
|
|
1091
1113
|
object). A name it doesn't know answers the closest ones (`Error: no
|
|
1092
|
-
|
|
1114
|
+
tool chrome/open_url. Closest: chrome/new_page, …`). Its row shows
|
|
1093
1115
|
`mcp chrome/take_screenshot fullPage=true`.
|
|
1094
1116
|
- A tool turn takes a few more steps than when every tool was declared
|
|
1095
1117
|
(the P1 spike: about 1.5 more on a 30-tool server), and each request is
|
|
@@ -1159,8 +1181,9 @@ bundles:
|
|
|
1159
1181
|
session" (or in this repo) allows that tool with those arguments only.
|
|
1160
1182
|
(Approvals stored before 0.6.0, under the old name, don't carry over, nor
|
|
1161
1183
|
ones stored before 0.7.0 under `mcp_call`: each MCP tool is asked about once more.)
|
|
1162
|
-
Two things see `call_tool`, not the tool: hooks (a `before_tool_call`
|
|
1163
|
-
event's `tool:` is `"call_tool"`, the tool in its args
|
|
1184
|
+
Two things see `call_tool`, not the MCP tool: hooks (a `before_tool_call`
|
|
1185
|
+
event's `tool:` is `"call_tool"`, the tool in its args; a built-in reached
|
|
1186
|
+
through `call_tool` is the exception, it fires as that built-in), and loop-guard's
|
|
1164
1187
|
`ignore_tools` (`call_tool` ignores every MCP call; calls to different
|
|
1165
1188
|
tools, or with different args, stay distinct, since the tool is in the
|
|
1166
1189
|
args).
|
data/docs/releasing.md
CHANGED
|
@@ -18,8 +18,14 @@ can run the whole release; the user approves the notes before the tag and the
|
|
|
18
18
|
`chi update` (all of them, with the gem) or `chi bundle upgrade NAME`. So:
|
|
19
19
|
- a change to a bundle's files bumps that bundle's `version:`
|
|
20
20
|
(`rake bundles:check` fails otherwise, once there's a tag to compare with);
|
|
21
|
-
- a bundle that uses something new in chi
|
|
22
|
-
|
|
21
|
+
- a bundle that uses something new in chi marks it in the same change with
|
|
22
|
+
`requires_chi_next: true` (or a short reason) in its `manifest.yml`, and
|
|
23
|
+
leaves `requires_chi` alone: raising it to a chi that isn't released yet
|
|
24
|
+
would make chi on main refuse its own bundle. `release:bump` raises a
|
|
25
|
+
marked bundle's `requires_chi` to `">= X.Y.Z"` and drops the marker;
|
|
26
|
+
`release:check` fails while a marker is left. chi itself ignores the key,
|
|
27
|
+
and `bundles:check` notes it (and fails a marker that isn't `true` or a
|
|
28
|
+
one-line string). `release:bump` touches no other `requires_chi`;
|
|
23
29
|
- a new shipped bundle joins a profile (`includes:` in `core` or `dev`; a
|
|
24
30
|
spec checks every bundle is in exactly one), and that profile's version
|
|
25
31
|
goes up: `chi update` then installs only the new bundle for those who
|
|
@@ -49,11 +55,11 @@ as the GitHub release body.
|
|
|
49
55
|
| Task | What it does |
|
|
50
56
|
| --- | --- |
|
|
51
57
|
| `rake bundles:sha` | Recomputes the sha256 lines of every shipped bundle manifest (`files:`, `hooks:`, `plugin:`). |
|
|
52
|
-
| `rake bundles:check` | Sha lines match; a bundle changed since the last `v*` tag has a higher version (skipped, with a note, before the first tag). Warns (doesn't fail) when such a bundle's `requires_chi` still admits the tagged chi:
|
|
58
|
+
| `rake bundles:check` | Sha lines match; a bundle changed since the last `v*` tag has a higher version (skipped, with a note, before the first tag). Warns (doesn't fail) when such a bundle's `requires_chi` still admits the tagged chi: mark it `requires_chi_next` if the change uses anything new. Notes a bundle marked `requires_chi_next`. The release workflow and `release:check` run it in full. |
|
|
53
59
|
| `rake 'bundles:check[ci]'` | The CI workflow's (every push and PR): the same, except the version check leaves out the system bundle, which is changed and unbumped between releases (`release:bump` moves its version with VERSION). A task argument, not `CI=1`: GitHub sets `CI` in the release workflow too. |
|
|
54
60
|
| `rake release:draft_changelog` | A draft Unreleased section from the commit subjects since the last tag, grouped. Stdout only. |
|
|
55
|
-
| `rake release:bump[X.Y.Z]` | VERSION, the system manifest, Gemfile.lock, CHANGELOG. No commit. |
|
|
56
|
-
| `rake release:check` | Clean tracked tree, VERSION == system bundle, a CHANGELOG section, `bundles:check`, `rake lint` (RuboCop), rspec + npm test, `gem build`, then a clean install into a temp GEM_HOME that runs `chi --version`, `chi self` and `chi bundle list` with a temp HOME. Needs the network (gem dependencies). |
|
|
61
|
+
| `rake release:bump[X.Y.Z]` | VERSION, the system manifest, Gemfile.lock, CHANGELOG, and `requires_chi: ">= X.Y.Z"` for each bundle marked `requires_chi_next` (the marker dropped). No commit. |
|
|
62
|
+
| `rake release:check` | Clean tracked tree, VERSION == system bundle, a CHANGELOG section, no `requires_chi_next` left, `bundles:check`, `rake lint` (RuboCop), rspec + npm test, `gem build`, then a clean install into a temp GEM_HOME that runs `chi --version`, `chi self` and `chi bundle list` with a temp HOME. Needs the network (gem dependencies). |
|
|
57
63
|
| `rake release:notes[X.Y.Z]` | Prints the CHANGELOG section (default: the current VERSION). |
|
|
58
64
|
|
|
59
65
|
## Runbook
|
|
@@ -68,7 +74,9 @@ The agent does each step and stops where the user has to say yes.
|
|
|
68
74
|
the last tag (`git diff vPREV -- lib/samagotchi/bundles/*/manifest.yml`).
|
|
69
75
|
Pick the version: fixes only → patch, anything else → minor.
|
|
70
76
|
3. **The user approves the notes and the version.** Show them the section.
|
|
71
|
-
4. **Bump.** `bundle exec rake "release:bump[X.Y.Z]"`, review `git diff
|
|
77
|
+
4. **Bump.** `bundle exec rake "release:bump[X.Y.Z]"`, review `git diff`: it
|
|
78
|
+
names the bundles whose `requires_chi` it raised (their `requires_chi_next`
|
|
79
|
+
markers are gone).
|
|
72
80
|
5. **Check.** Commit first (the check wants a clean tree), then run it:
|
|
73
81
|
`git commit -am "Release X.Y.Z"` and `bundle exec rake release:check`.
|
|
74
82
|
Fix anything it finds in new commits and run it again.
|
data/docs/sessions.md
CHANGED
|
@@ -74,9 +74,9 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
74
74
|
**Ordering:**
|
|
75
75
|
|
|
76
76
|
- `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.
|
|
77
|
-
- 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, 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; a link whose text is such a ref alone (github-pr's link to the PR diff) becomes a ref too, and its plain click still goes to the PR. A plugin's refs on an answer (an `after_turn` hook's, see [Refs on the answer](hooks.md#refs-on-the-answer-display-only)) are paired with its links and text whatever the rows touched: they can link a file the session didn't touch, or an issue or a commit, and add their own actions to the ref's menu. A plugin tool's row carries the refs its `refs:` gives (see [Refs on a tool's row](plugins.md#refs-on-a-tools-row)): its title opens the first, and its `▾` menu adds the others as `<ref> · <action>` (the URL on hover); their URL actions work on a phone too. A ref with more than one target shows a small `▾` on hover: it opens a menu of them, in order **PR diff** (a link's), **Open in editor**, **Show in turn** and **Copy path**, and a plain click runs the first (a link's own, else the editor, else show in turn). **Show in turn** scrolls to the tool row that touched the file (looked for in the ref's own step, then its own turn, then the rows before it, then the nearest after it; there, the last one showing the ref's line, else the last one), opens the steps, the stage's steps and the row's diff (or the read showing the line) and flashes the row and the line; an answer's or a step's ref and an approval card's path have it, not a row's own title or lines. It needs no editor, so a viewer without one (a phone on the LAN) gets an answer's refs with **Show in turn** as their click; a row's title and diff lines stay plain text there. On a touch screen a tap opens the menu. A ref with a target is a tab stop: Enter runs its first target, ↓ opens the menu (↑/↓ move, Enter picks, Esc closes back to the ref). Diff and read lines have their click only. 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).
|
|
77
|
+
- 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, 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; a link whose text is such a ref alone (github-pr's link to the PR diff) becomes a ref too, and its plain click still goes to the PR. A plugin's refs on an answer (an `after_turn` hook's, see [Refs on the answer](hooks.md#refs-on-the-answer-display-only)) are paired with its links and text whatever the rows touched: they can link a file the session didn't touch, or an issue or a commit, and add their own actions to the ref's menu. A plugin tool's row carries the refs its `refs:` gives (see [Refs on a tool's row](plugins.md#refs-on-a-tools-row)): its title opens the first, and its `▾` menu adds the others as `<ref> · <action>` (the URL on hover); their URL actions work on a phone too. A ref with more than one target shows a small `▾` on hover: it opens a menu of them, in order **PR diff** (a link's), **Open in editor**, **Show in turn** and **Copy path**, and a plain click runs the first (a link's own, else the editor, else show in turn). **Show in turn** scrolls to the tool row that touched the file (looked for in the ref's own step, then its own turn, then the rows before it, then the nearest after it; there, the last one showing the ref's line, else the last one), opens the steps, the stage's steps and the row's diff (or the read showing the line) and flashes the row and the line; an answer's or a step's ref and an approval card's path have it, not a row's own title or lines. It needs no editor, so a viewer without one (a phone on the LAN) gets an answer's refs with **Show in turn** as their click; a row's title and diff lines stay plain text there. On a touch screen a tap opens the menu. A ref with a target is a tab stop: Enter runs its first target, ↓ opens the menu (↑/↓ move, Enter picks, Esc closes back to the ref). Diff and read lines have their click only. 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, and a fresh chain link's (see [Session chains](#session-chains); there a pick shows as a `/model` command bubble in the link); 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).
|
|
78
78
|
- 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).
|
|
79
|
-
- 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; the chip and rows as lit-html templates), `keep_focus.js` (lit reuses a list's nodes by position: a redraw keeps the focus on the same item by its `data-id` / `data-name`), `chains.js` (session chains: the links from `continues`, the cards folded into the latest link's, its `day N` chip and rows as lit-html templates, 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), `bubbles.js` (the history's bubbles between the turns' rows: output chunks, end lines, every client's prompt bubbles by `enqueued_id` with their queued/steered badges, the idle recap, guardrail warnings, hooks' notices, plugins' steers, command and note bubbles; lit-html templates, put in the history with the sticky follow by `createBubbles`), `cards_place.js` (where plugin cards and a snapshot's notices go in the history: a card added or updated in place by its id, a running turn's into its step, a snapshot's each above the first turn after it, a finished turn's notice in its step's rows and its question resolved where it was asked; a card's action buttons), `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), `delivery_line.js` (the composer's row above the text field in a session, always there so the composer keeps its height: the key hint while idle, and the delivery line while a turn runs: where a message typed now goes in, from the step's phase, clock and size, whether "cut in now" can land, and the queue link for a worker with the `delivery` feature, as a pure `deliveryLine`, its lit-html template and `createDeliveryControl`, which ticks it and keeps a choice armed from a link; see docs/cli.md, "Typing during a turn"), `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), `stage_view.js` (the stage view: the running turn pinned above the composer, then handed off into the history; its pure rules and texts in `stage_model.js`, its live slots (headline, now row, trail, ticks) in `stage_slots.js`, its cap and held height in `stage_frame.js`, the in-use watch that times the hand-off in `stage_watch.js`), `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), `info_bar_model.js` (that model and the bar's buttons' states, built from the page's session state, its list and its in-flight continues and restarts as pure functions; `app.js`'s `updateInfoBar` applies them every second while a turn runs), `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, a plugin's ref data (label, http(s) URL actions) bound in a WeakMap by `bindRef`, the targets per kind, show in turn, one delegated set of click, key and hover listeners), `ref_menu.js` (a ref's `▾` and its menu), `ref_scan.js` (the `path:line` refs in an answer's or a step's text that name a file the session's rows touched), `answer_refs.js` (the refs a plugin attached to an answer, its `display_refs`: bound to the answer's bubble, paired with its links and text, bound with `bindRef`). Unit-tested via `npm test` (`spec/web/public/*.test.js`).
|
|
79
|
+
- 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; the chip and rows as lit-html templates), `keep_focus.js` (lit reuses a list's nodes by position: a redraw keeps the focus on the same item by its `data-id` / `data-name`), `chains.js` (session chains: the links from `continues`, the cards folded into the latest link's, its `day N` chip and rows as lit-html templates, the info bar's ← → links, a refused continue, and the fresh-link rule), `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), `bubbles.js` (the history's bubbles between the turns' rows: output chunks, end lines, every client's prompt bubbles by `enqueued_id` with their queued/steered badges, the idle recap, guardrail warnings, hooks' notices, plugins' steers, command and note bubbles; lit-html templates, put in the history with the sticky follow by `createBubbles`), `cards_place.js` (where plugin cards and a snapshot's notices go in the history: a card added or updated in place by its id, a running turn's into its step, a snapshot's each above the first turn after it, a finished turn's notice in its step's rows and its question resolved where it was asked; a card's action buttons), `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), `delivery_line.js` (the composer's row above the text field in a session, always there so the composer keeps its height: the key hint while idle, and the delivery line while a turn runs: where a message typed now goes in, from the step's phase, clock and size, whether "cut in now" can land, and the queue link for a worker with the `delivery` feature, as a pure `deliveryLine`, its lit-html template and `createDeliveryControl`, which ticks it and keeps a choice armed from a link; see docs/cli.md, "Typing during a turn"), `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), `stage_view.js` (the stage view: the running turn pinned above the composer, then handed off into the history; its pure rules and texts in `stage_model.js`, its live slots (headline, now row, trail, ticks) in `stage_slots.js`, its cap and held height in `stage_frame.js`, the in-use watch that times the hand-off in `stage_watch.js`), `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), `info_bar_model.js` (that model and the bar's buttons' states, built from the page's session state, its list and its in-flight continues and restarts as pure functions; `app.js`'s `updateInfoBar` applies them every second while a turn runs), `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, a plugin's ref data (label, http(s) URL actions) bound in a WeakMap by `bindRef`, the targets per kind, show in turn, one delegated set of click, key and hover listeners), `ref_menu.js` (a ref's `▾` and its menu), `ref_scan.js` (the `path:line` refs in an answer's or a step's text that name a file the session's rows touched), `answer_refs.js` (the refs a plugin attached to an answer, its `display_refs`: bound to the answer's bubble, paired with its links and text, bound with `bindRef`). Unit-tested via `npm test` (`spec/web/public/*.test.js`).
|
|
80
80
|
- 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).
|
|
81
81
|
|
|
82
82
|
**Test-session hygiene:**
|
|
@@ -216,7 +216,7 @@ A session can **continue** an earlier one: "the next day of the same routine" (a
|
|
|
216
216
|
- **If the continue fails part-way:** a new link that fails to start gives its moved delegates back before it is deleted (each gets a note saying so; its worker is stopped first, if one started, and a worker that won't stop is reported, the link left), with any report one of them rang it with meanwhile; the previous link, back in the lists, is woken for reports waiting. A continue that dies in the middle leaves a `move.json` in the new link's folder: the new link's next worker finishes that move (only the delegates it names, and without a second note to one already told) as it starts. Until the new link's own worker holds it, a ring from a moved delegate doesn't start another (a `starting` marker in its folder, which that worker removes; a stale one, over 60 s old or from a process that is gone, is ignored). An open delegate below an archived delegate refuses the continue (`under archived …`): unarchive that one, or archive this one.
|
|
217
217
|
- **Refused too:** a link that is continued already (naming the link that continues it; continue that one, or `last:<id>`), a previous link whose folder is gone, and one whose model's host can't run it when no default model is configured to fall back to. A refusal starts nothing and archives nothing; a new link that fails to start puts back what was archived. Every refusal that can be known up front (the archive's ones included) comes before the recap wait. One continue of a session runs at a time (a lock in its folder; other chains don't wait), so a double click finds the first one's link and is refused, while a `last:<id>` continue that waited follows the chain to its new end.
|
|
218
218
|
- **Web:** `POST /api/sessions` takes `continues: "<id, prefix or last:id>"`, with `idle: true` (a new link waiting for its first message, previewed by the previous link's, or `preview`) or a `prompt`, and `model` (or `model_name`) for the new link's model, but not `dir`, `llm_context` or `thinking` (400 `invalid_continues`: the previous link's are taken). 201 is the new session's summary, `continues` set, with `moved`: the ids of the delegates that moved to it (`[]` for none), and `model_warning`: the default-model fallback's warning, then any about the model id, joined by `; ` (`null` for none); 404 `not_found`; 400 `ambiguous_id` for a prefix of several sessions, `invalid_model` for a given model whose host config.yml doesn't have (or a fallback with no default model); 409 `continued` with `next_id` (the link that continues it already, which the page opens instead), `open_children` with `ids` (open delegates that can't move), `folder_gone`, `busy`, `scratch` or `owned_by_tui`. Every session summary carries `continues`.
|
|
219
|
-
- **The page:** the info bar's `continue →` continues the open session (`continues: <id>, idle: true`; it reads `continuing…` through the recap wait) and opens the new link with `Continue where we left off.` in the composer, not sent (the same line for every chain; a draft already there stays instead); the previous link is archived, a toast says so (`Continued 3fa2c1d0 in 4b7e9a01; 3fa2c1d0 is archived; 1 open delegate moved`), and a moved delegate's card folds under the new link. A link continued already has no `continue →`: its `→` link goes to the next link (a stale page's continue answered 409 `continued` opens `next_id`). A continue refused for open delegates that can't move shows a toast that names each one (its preview and what the server says to do: `older chi worker 0.46.1; restart it`, `open in a chi REPL; close it there`), each a link to its page; any other refusal shows the server's words. The info bar of a link carries `← 2026-10-08` (the previous link's day) and, on an earlier link, `2026-10-10 →`, each a link with its preview and id in the tooltip. A link whose title is the opener and nothing else (its first message once sent) shows its chain's first link's title instead, on its card, in the popover and in its info bar's title line, display only (its messages and data keep the opener; its own title when the first link is gone). The lists fold a chain into the card of its latest listed link, whatever the earlier links' archived state (typing in an archived link brings it back, folded there still), their delegates with them: the card's `↩ day N` chip (`day N of M` when later links aren't listed) opens a popover of the other links, newest first (`day N`, its date, its recap's first sentence or its preview, `archived`), a click opens one; the chip shows a live dot or `waiting` for a link that has a worker or waits on the user, and a waiting link puts its chain's card first. All sessions folds nothing while a search is typed or "include archived" is on: every link is a card of its own then, its chip `day N of M`, with its own delegates folded in, so a search finds an earlier link and its delegates.
|
|
219
|
+
- **The page:** the info bar's `continue →` continues the open session (`continues: <id>, idle: true`; it reads `continuing…` through the recap wait) and opens the new link with `Continue where we left off.` in the composer, not sent (the same line for every chain; a draft already there stays instead); the previous link is archived, a toast says so (`Continued 3fa2c1d0 in 4b7e9a01; 3fa2c1d0 is archived; 1 open delegate moved`), and a moved delegate's card folds under the new link. When the previous link's model's host is gone the link starts on the default model and the toast carries the server's `model_warning` too, and then stays until closed. A fresh link (one with no turn yet, however it was made: `continue →`, `chi send --new --continues`, a reload) shows the model picker in its composer with the link's model, until its first turn starts (a failed or canceled first turn ends it too); a pick runs `/model <name>` in the link (a command bubble; the info bar follows) and changes neither the start page's remembered model nor its Recent list, and a Send right after it waits for the `/model` to be taken. A link a chi REPL owns, or one continued already, shows none. A link continued already has no `continue →`: its `→` link goes to the next link (a stale page's continue answered 409 `continued` opens `next_id`). A continue refused for open delegates that can't move shows a toast that names each one (its preview and what the server says to do: `older chi worker 0.46.1; restart it`, `open in a chi REPL; close it there`), each a link to its page; any other refusal shows the server's words. The info bar of a link carries `← 2026-10-08` (the previous link's day) and, on an earlier link, `2026-10-10 →`, each a link with its preview and id in the tooltip. A link whose title is the opener and nothing else (its first message once sent) shows its chain's first link's title instead, on its card, in the popover and in its info bar's title line, display only (its messages and data keep the opener; its own title when the first link is gone). The lists fold a chain into the card of its latest listed link, whatever the earlier links' archived state (typing in an archived link brings it back, folded there still), their delegates with them: the card's `↩ day N` chip (`day N of M` when later links aren't listed) opens a popover of the other links, newest first (`day N`, its date, its recap's first sentence or its preview, `archived`), a click opens one; the chip shows a live dot or `waiting` for a link that has a worker or waits on the user, and a waiting link puts its chain's card first. All sessions folds nothing while a search is typed or "include archived" is on: every link is a card of its own then, its chip `day N of M`, with its own delegates folded in, so a search finds an earlier link and its delegates.
|
|
220
220
|
- **CLI:** `chi send --new --continues (ID|PREFIX|last:ID) [--model M] [-m TEXT]` (see *Starting a session*).
|
|
221
221
|
- **Which link:** an id, a unique prefix, or `last:<id or prefix>`, the latest link of the chain that session is in. It walks the links that still exist: a deleted link in the middle (`chi sessions delete`, the retention sweep of an unarchived one) ends the walk before it, so `last:` of an earlier link then names that earlier link, and continuing it starts a second line beside the links after the gap; name a link after the gap instead. A trigger names the chain this way: `chi send` to an archived link would bring it back (a human's input), not continue the chain.
|
|
222
222
|
|