samagotchi 0.42.0 → 0.44.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 +47 -1
- data/docs/configuration.md +26 -0
- data/docs/context.md +46 -0
- data/docs/internals/context-telemetry.md +4 -1
- data/docs/internals/engine.md +1 -0
- data/docs/plugins.md +27 -5
- data/docs/sessions.md +1 -1
- data/lib/samagotchi/bridge/card_store.rb +20 -9
- data/lib/samagotchi/bridge/turn_notice.rb +3 -1
- data/lib/samagotchi/bundles/github-pr/manifest.yml +4 -4
- data/lib/samagotchi/bundles/github-pr/plugin.rb +177 -1
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/context_sources.rb +40 -0
- data/lib/samagotchi/context_status.rb +18 -5
- data/lib/samagotchi/kernel_loop.rb +24 -9
- data/lib/samagotchi/llm/chat_loop.rb +4 -3
- data/lib/samagotchi/llm_context_forget.rb +6 -2
- data/lib/samagotchi/llm_context_notice.rb +96 -0
- data/lib/samagotchi/plugin/attached_context.rb +75 -11
- data/lib/samagotchi/terminal_ui/attached_loop.rb +2 -1
- data/lib/samagotchi/terminal_ui/event_renderer.rb +3 -0
- data/lib/samagotchi/terminal_ui/formatting.rb +7 -0
- data/lib/samagotchi/terminal_ui/one_shot_sink.rb +1 -0
- data/lib/samagotchi/tool_declarations.rb +2 -1
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +47 -7
- data/lib/samagotchi/web/message_parts.rb +90 -11
- data/lib/samagotchi/web/public/app.js +80 -13
- data/lib/samagotchi/web/public/ctx.js +27 -2
- data/lib/samagotchi/web/public/data.js +6 -3
- data/lib/samagotchi/web/public/index.html +12 -0
- data/lib/samagotchi/web/public/llm_context_chip.js +151 -21
- data/lib/samagotchi/web/public/model_pick.js +3 -1
- data/lib/samagotchi/web/public/model_picker.js +2 -0
- data/lib/samagotchi/web/public/session_state.js +2 -0
- data/lib/samagotchi/web/public/turn_events.js +34 -0
- data/lib/samagotchi/web/public/turn_html.js +33 -2
- data/lib/samagotchi/web/public/turn_view.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: 684d8e5c169b4ce5df4cd21c4c46d0ef8524230e530d3e90ec2076f5b674e905
|
|
4
|
+
data.tar.gz: 54dbaf8bd2ad38b78e16aca155414748491912bdaebe1069f128e6182df7bfe5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de459298c279f571db785d374e1752a58060d26a13c4f7a6d22f8c4e4a5c82acbcffecd5784712eda405908cc3a8fd7bf1526952878b3791017088ebb62f120e
|
|
7
|
+
data.tar.gz: a99cf35d53b0a9fb7b3ed568a73d3383252ba334e4c8efd50efd9d97ded3cb716432fd51ee069e066ce3d21d137f1fadf49e20f2b99e9a769e430c8274278a64
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,50 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.44.0] - 2026-10-08
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- LLM context edits are visible: each batch of stubs that reaches the prompt gets a ✂ row in its step, in the web
|
|
16
|
+
and the terminal (`✂ forgot 2 outputs, stubbed 1 stale read · frees ~4.1k tokens (paid off)`), whose web hover
|
|
17
|
+
lists the outputs, a stale stub's reason, a forget's note and kept lines, and the cost. After a reload a stubbed
|
|
18
|
+
output's tool row carries a ✂ mark (`✂ stubbed: superseded by a later read · ~1.0k tokens`, `✂ forgotten: <note>`,
|
|
19
|
+
`✂ forget staged`). The stream has a new event, `llm_context_edited`. See
|
|
20
|
+
[docs/configuration.md](docs/configuration.md) ("LLM context: what you see (✂)").
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- Under an `llm_context.budget_tokens` budget without the forget layer (strategy `none` or `stale`), the model's
|
|
25
|
+
`[CONTEXT: …]` line said "of the context window" for a percentage of the budget; it now reads "about 62% of the
|
|
26
|
+
context budget (64k tokens) is in use", and its top bucket no longer asks the model to "summarize aggressively"
|
|
27
|
+
("context budget critical — avoid large outputs and re-reads, delegate broad work to subagents").
|
|
28
|
+
|
|
29
|
+
## [0.43.0] - 2026-10-08
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- A new web chat can start under its own LLM context: the start page has an `llm ctx` chip beside the model
|
|
34
|
+
picker that shows the picked model's strategy, and its form (as the info bar's, titled "new chat") sets a
|
|
35
|
+
strategy, apply rule and budget for that chat's first turn on (`llm ctx stale · new chat`). The choice is not
|
|
36
|
+
remembered: it resets after a create, on a reload and when you open a session, and an untouched chip sends
|
|
37
|
+
nothing. `POST /api/sessions` takes
|
|
38
|
+
`llm_context` (`{strategy, apply, budget}` as `/llm-context` words them; anything else answers
|
|
39
|
+
`400 invalid_llm_context`), and `GET /api/models` rows carry each model's `llm_context`. See
|
|
40
|
+
[docs/configuration.md](docs/configuration.md) ("LLM context: a session's own strategy").
|
|
41
|
+
- The web's `ctx` chip shows the context window and where it came from: its tooltip gains `context: ~41.0k of
|
|
42
|
+
128.0k tokens (server)`, and the chip reads `ctx ~12%` when the window is chi's 256k default, a guess no server,
|
|
43
|
+
model list or setting gave (the tooltip says to set `window_tokens` for the model).
|
|
44
|
+
- github-pr 0.3.0: `bundles: github-pr: auto_attach:` says what happens to the branch's open PR when a worker
|
|
45
|
+
starts: `attach` (the default, as before), `offer` (a card, "PR #42 for branch feat/x", with **Attach** and **Not
|
|
46
|
+
here**, shown once per session; `/pr-attach 42` and `/pr-decline 42`) or `off` (nothing). In `offer` mode the
|
|
47
|
+
offers, what you clicked and each session's first prompt go to a local log, `plugins/github-pr/offers.ndjson` in
|
|
48
|
+
the state dir. See [docs/context.md](docs/context.md) ("Attach, offer or off").
|
|
49
|
+
- For plugins: `ctx.context.decline(url:|name:)`, `declined?(name, url:)`, `attach(…, force: true)` (the user's
|
|
50
|
+
explicit choice, past a decline) and `mark_offered(name, hint)` / `offered(name)`, a per-session record that a
|
|
51
|
+
plugin offered a source. See [docs/plugins.md](docs/plugins.md) ("Attached context").
|
|
52
|
+
|
|
53
|
+
Update with `chi update`: it updates github-pr (0.3.0: `auto_attach`; needs chi 0.43.0).
|
|
54
|
+
|
|
11
55
|
## [0.42.0] - 2026-10-08
|
|
12
56
|
|
|
13
57
|
### Added
|
|
@@ -1982,7 +2026,9 @@ and long-lived sessions.
|
|
|
1982
2026
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
1983
2027
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
1984
2028
|
|
|
1985
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
2029
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.44.0...HEAD
|
|
2030
|
+
[0.44.0]: https://github.com/dm1try/samagotchi/compare/v0.43.0...v0.44.0
|
|
2031
|
+
[0.43.0]: https://github.com/dm1try/samagotchi/compare/v0.42.0...v0.43.0
|
|
1986
2032
|
[0.42.0]: https://github.com/dm1try/samagotchi/compare/v0.41.0...v0.42.0
|
|
1987
2033
|
[0.41.0]: https://github.com/dm1try/samagotchi/compare/v0.40.0...v0.41.0
|
|
1988
2034
|
[0.40.0]: https://github.com/dm1try/samagotchi/compare/v0.39.0...v0.40.0
|
data/docs/configuration.md
CHANGED
|
@@ -900,6 +900,24 @@ models:
|
|
|
900
900
|
- `/stats` counts the re-prefilled tokens each applied batch costs; `script/llm_context_bench.rb --strategy
|
|
901
901
|
forget_outputs` replays the offer on stored sessions (docs/internals/llm-context-bench.md).
|
|
902
902
|
|
|
903
|
+
## LLM context: what you see (✂)
|
|
904
|
+
|
|
905
|
+
Every edit is shown; the session keeps the originals.
|
|
906
|
+
|
|
907
|
+
- **A ✂ row** for each batch of stubs that reaches the prompt (`stale`'s, a `forget_outputs` call's, or the ones
|
|
908
|
+
staged until a turn's end), in the step it came in, in the web and the terminal alike:
|
|
909
|
+
`✂ forgot 2 outputs, stubbed 1 stale read · frees ~4.1k tokens (paid off)`. It says why it went now (`paid off`,
|
|
910
|
+
`the context is nearly full`, `at turn end`; nothing under `next_request`) and how many stubs stay staged. In the
|
|
911
|
+
web, its hover lists each output (its id, tool and path or command), a stale stub's reason, a forget's note once
|
|
912
|
+
with the lines it keeps, the tokens it frees and the tail the server reads again. A batch held back, the warm-up's
|
|
913
|
+
own copy and a restore show no row (the `forget_outputs` row says what a restore did). A reload puts the rows back
|
|
914
|
+
where they were (`cards.json`, its own cap of 20, apart from hook notices).
|
|
915
|
+
- **A ✂ mark** on a tool row after a reload, above its output, when the model is sent a stub for it:
|
|
916
|
+
`✂ stubbed: superseded by a later read · ~1.0k tokens`, `✂ forgotten: <note>`, `✂ forgotten with t41` (the
|
|
917
|
+
other outputs of the call whose row carries the note), `✂ forget staged`, and `· lines 12-40 kept`.
|
|
918
|
+
The running turn's rows get theirs on the next reload.
|
|
919
|
+
- Tokens are estimates (chars/4), hence the `~`.
|
|
920
|
+
|
|
903
921
|
## LLM context: a session's own strategy
|
|
904
922
|
|
|
905
923
|
A session can set its own `llm_context` strategy, apply rule and budget, which come before the model's, its host's
|
|
@@ -909,6 +927,14 @@ its own). The first target is a long session such as a day-long coordinator, whe
|
|
|
909
927
|
- **Set it** at start with `chi --llm-context stale,forget --llm-context-apply turn_end --llm-context-budget 64k`
|
|
910
928
|
(the same flags on `chi send --new`), in the session with `/llm-context strategy … apply … budget …`
|
|
911
929
|
(docs/cli.md, "Session commands"), or from the web's `llm ctx` chip in the info bar.
|
|
930
|
+
- **A new web chat:** the start page's `llm ctx` chip, beside the model picker, shows the picked model's values
|
|
931
|
+
and follows a model pick. Its form (titled "new chat") sets a choice for that one chat: the chip reads
|
|
932
|
+
`llm ctx stale · new chat` in the accent colour, and the create sends it as `POST /api/sessions`'s
|
|
933
|
+
`llm_context` (`{"strategy": "stale,forget", "apply": "turn_end", "budget": "64k"}`, each a word as
|
|
934
|
+
`/llm-context` takes it, `default` for unset; anything else answers `400 invalid_llm_context` and starts
|
|
935
|
+
nothing), so the session file holds it before the first turn runs. It is not remembered: it resets after a
|
|
936
|
+
create, on a reload and when you open a session (a failed create keeps it), and an untouched chip sends nothing
|
|
937
|
+
(the model's values apply, as without the chip).
|
|
912
938
|
- **Values:** `none` and a budget of `off` are values the session sets on purpose (they win over the model's);
|
|
913
939
|
`default` (or `/llm-context reset` for all three) unsets one, back to following the model. A budget is 4k to
|
|
914
940
|
10M tokens (`4000`–`10000000`, or `4k`–`10000k`). The layers are kept in chi's order (`stale`, then `forget`).
|
data/docs/context.md
CHANGED
|
@@ -175,6 +175,7 @@ It needs [`gh`](https://cli.github.com), logged in (`gh auth login`).
|
|
|
175
175
|
the next start doesn't bring it back; `chi context add <PR URL>` or "+ URL"
|
|
176
176
|
does.
|
|
177
177
|
- `chi context add <PR URL>` and the web's "+ URL" attach any PR.
|
|
178
|
+
- `auto_attach` (below) can make it ask first, or attach nothing.
|
|
178
179
|
- The text: title, state, branch, description, reviews, comments (oldest
|
|
179
180
|
first) and checks, every 5 minutes.
|
|
180
181
|
- The summary says what changed in **counts, authors and states only**
|
|
@@ -184,6 +185,50 @@ It needs [`gh`](https://cli.github.com), logged in (`gh auth login`).
|
|
|
184
185
|
- It wakes for a review requesting changes, checks turning red, and the PR
|
|
185
186
|
merged or closed. Comments alone never wake.
|
|
186
187
|
|
|
188
|
+
### Attach, offer or off
|
|
189
|
+
|
|
190
|
+
```yaml
|
|
191
|
+
bundles:
|
|
192
|
+
github-pr:
|
|
193
|
+
auto_attach: offer # attach (the default) | offer | off
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
- `attach`: the branch's open PR is attached when the worker starts, as
|
|
197
|
+
above.
|
|
198
|
+
- `offer`: nothing is attached; a card asks instead, once per session per
|
|
199
|
+
PR: **PR #42 for branch feat/x**, the PR's title and "Not attached: the
|
|
200
|
+
agent gets nothing until you attach it.", with **Attach** and **Not
|
|
201
|
+
here**. The terminal shows them as `→ /pr-attach 42` and
|
|
202
|
+
`→ /pr-decline 42`, to type. Attach attaches it as auto-attach would
|
|
203
|
+
(even after Not here: a click is your choice); Not here marks it removed
|
|
204
|
+
from the session, so `attach` mode won't attach it there either. Either
|
|
205
|
+
turns the card into a one-line notice. Not here on a PR that is attached
|
|
206
|
+
already changes nothing and says so: `chi context rm pr-42` removes it. A worker restart (idle exit,
|
|
207
|
+
resume) doesn't ask again; once the card has scrolled out of the last 20,
|
|
208
|
+
`/pr-attach 42` or "+ URL" still attaches it. `/pr-attach` and
|
|
209
|
+
`/pr-decline` act only on a PR offered in that session.
|
|
210
|
+
- `off`: nothing is attached or offered. "+ URL", `chi context add <PR URL>`
|
|
211
|
+
and line links work as before.
|
|
212
|
+
|
|
213
|
+
`true` and `false` (YAML reads a bare `on`/`off` as those) mean `attach` and
|
|
214
|
+
`off`; an unknown value is `attach`, with a warning in the log. The setting
|
|
215
|
+
is read when a worker starts.
|
|
216
|
+
|
|
217
|
+
A web chat is created with its first message, so in `offer` mode the card
|
|
218
|
+
arrives while that first turn runs: the first answer comes without the PR,
|
|
219
|
+
and Attach delivers it before the next turn. An offered PR that isn't
|
|
220
|
+
attached gets no line links (unless your message names its URL).
|
|
221
|
+
|
|
222
|
+
In `offer` mode the bundle keeps a local log,
|
|
223
|
+
`$XDG_STATE_HOME/samagotchi/plugins/github-pr/offers.ndjson`, to find out
|
|
224
|
+
later when an offer is wanted: one JSON line per event, `offered` (session,
|
|
225
|
+
project root, working directory, branch, PR URL, main checkout or worktree,
|
|
226
|
+
model), `attached` and `declined` (with the seconds since the offer), and
|
|
227
|
+
`first_prompt` (the first 160 characters of every session's first message,
|
|
228
|
+
offered or not; not scratch sessions or delegate children). Over 1 MB it is
|
|
229
|
+
renamed to `offers.ndjson.1` (one old file is kept). Only you can read it
|
|
230
|
+
(0600), and nothing leaves your machine.
|
|
231
|
+
|
|
187
232
|
### Line links
|
|
188
233
|
|
|
189
234
|
In the web, a file reference in an answer links to that line of the pull
|
|
@@ -256,6 +301,7 @@ sessions/<id>/<name>.json, …snapshot.json a session's own
|
|
|
256
301
|
sessions/<id>/subscriptions.json what the session has seen and read (its worker writes it)
|
|
257
302
|
sessions/<id>/muted/<name> a project source this session mutes
|
|
258
303
|
sessions/<id>/declined/<name> a source you removed (its hint inside): auto-attach skips it
|
|
304
|
+
sessions/<id>/offered/<name> a source a plugin offered here ({hint, why, at}): it isn't offered again
|
|
259
305
|
```
|
|
260
306
|
|
|
261
307
|
Deleting a session deletes its folder. A source and its snapshot go with
|
|
@@ -36,7 +36,10 @@ both loops):
|
|
|
36
36
|
|
|
37
37
|
- `llm_context.budget_tokens` (or a model's or host's `llm_context_budget_tokens`): the buckets count against the
|
|
38
38
|
budget instead of the window, the smaller of the two. The event's `window_tokens` and the status line's percentage
|
|
39
|
-
are of it too, and so is `payoff`'s top bucket.
|
|
39
|
+
are of it too, and so is `payoff`'s top bucket. Without the forget layer the model's line names it, `[CONTEXT:
|
|
40
|
+
about 62% of the context budget (64k tokens) is in use (…)]` (the window when that is the smaller), and its top
|
|
41
|
+
bucket reads "context budget critical — avoid large outputs and re-reads, delegate broad work to subagents": no
|
|
42
|
+
"summarize", as nothing in the model's hands shrinks the context.
|
|
40
43
|
- The forget layer replaces the guidance with tiered offers of `forget_outputs`, each line a readout,
|
|
41
44
|
`[CONTEXT: ~52k/64k tokens in use (bucket=60plus). …]`: the readout alone in the guided buckets below the top two
|
|
42
45
|
(CLM: how-to at low pressure makes a model wipe everything); "Finish the unit of work in flight, then tidy once
|
data/docs/internals/engine.md
CHANGED
|
@@ -298,6 +298,7 @@ Turn events (the main ones; `Events` in `events.rb` keeps the shared sets):
|
|
|
298
298
|
| `:generation_cancelled` | the turn was cancelled mid-loop | `{iteration, reason, stopped_by}` |
|
|
299
299
|
| `:empty_answer_retry` | an empty, cut or malformed answer is asked again | `{iteration, attempt, of, finish_reason, thinking_chars, stopped_by?, malformed?}` |
|
|
300
300
|
| `:steer_cut` | a steer cut the generation | `{iteration, source}` |
|
|
301
|
+
| `: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`) |
|
|
301
302
|
| `:pending_input_merged` | queued input joined the conversation | `{iteration, count, content, steers?, answer}` |
|
|
302
303
|
| `:tool_dispatch_started` / `:tool_dispatch_completed` | around a batch | `{iteration, call_count}` |
|
|
303
304
|
| `:tool_call_started` | before a call runs | see ToolRunner |
|
data/docs/plugins.md
CHANGED
|
@@ -679,6 +679,9 @@ ctx.sessions.stop(id) # one of this session's own children
|
|
|
679
679
|
ctx.context.attach(url: "https://github.com/acme/app/pull/42", why: "branch feat/x has open PR #42")
|
|
680
680
|
ctx.context.attach(name: "ci", cmd: "bin/ci-status", why: "this branch's CI", every_seconds: 120)
|
|
681
681
|
ctx.context.list # => [{name:, scope:, why:, hint:, fetched_at:, error:, provider:}]
|
|
682
|
+
ctx.context.decline(url: "https://github.com/acme/app/pull/42") # => "pr-42"
|
|
683
|
+
ctx.context.mark_offered("pr-42", "https://github.com/acme/app/pull/42", why: "branch feat/x has open PR #42")
|
|
684
|
+
ctx.context.offered("pr-42") # => #<data Offer name="pr-42", hint="https://…", why="branch…", at="2026-10-08T…Z">, or nil
|
|
682
685
|
```
|
|
683
686
|
|
|
684
687
|
[Attached context](context.md) for the session the plugin runs in: chi runs
|
|
@@ -691,13 +694,30 @@ gets a note when its text changes.
|
|
|
691
694
|
command of the plugin's own. A source of that name already attached stays
|
|
692
695
|
as it is. It returns the name, or nil when the user removed that name (or
|
|
693
696
|
that URL) from the session: a plugin doesn't attach it again until the
|
|
694
|
-
user adds it (`ctx.context.declined?(name)` says so
|
|
697
|
+
user adds it (`ctx.context.declined?(name, url: nil)` says so, by the
|
|
698
|
+
name or by the URL). `force: true` is for the user's own explicit choice
|
|
699
|
+
(a click on the plugin's card): it attaches anyway and clears the
|
|
700
|
+
declined marker, by the name and by the URL.
|
|
701
|
+
- `decline(url:)` or `decline(name:)` marks the source declined in this
|
|
702
|
+
session, as the user's removal does: `attach` skips it from then on. With
|
|
703
|
+
`url:`, the name and hint come from the bundle's provider (`name:`
|
|
704
|
+
replaces the name). It returns the name. A source attached already stays
|
|
705
|
+
attached (`chi context rm` removes it).
|
|
706
|
+
- `mark_offered(name, hint, why: nil)` records that the plugin offered a
|
|
707
|
+
source here (the hint is usually its URL; `why:` is kept for the attach
|
|
708
|
+
that may follow); `offered(name)` returns that record
|
|
709
|
+
(`ContextSources::Offer`: `name`, `hint`, `why`, `at`) or nil. A plugin that asks
|
|
710
|
+
before it attaches uses it so a worker restart doesn't ask again. Neither
|
|
711
|
+
an attach nor a decline clears it; deleting the session does.
|
|
695
712
|
- The source is the session's (not the project's), marked
|
|
696
713
|
`added_by: plugin:<bundle>`. It is plugin code, so it isn't asked about as
|
|
697
714
|
the agent's `chi context add --cmd` is.
|
|
698
715
|
- `list` gives the session's sources, its own then its project's.
|
|
699
|
-
-
|
|
700
|
-
|
|
716
|
+
- Two attaches of one source at once (a double click) both return its
|
|
717
|
+
name.
|
|
718
|
+
- `attach`, `decline` and `mark_offered` raise
|
|
719
|
+
`Samagotchi::Plugin::AttachedContext::Error` with the reason (no session
|
|
720
|
+
yet, no provider for the URL, a bad name).
|
|
701
721
|
|
|
702
722
|
The [github-pr bundle](#the-github-pr-bundle) attaches the branch's PR from
|
|
703
723
|
a quiet `chi.init` task.
|
|
@@ -1219,8 +1239,10 @@ nothing without `gh`, a repository or an open PR), and resolves PR URLs for
|
|
|
1219
1239
|
and a summary of what changed in counts, authors and states only; it wakes
|
|
1220
1240
|
the session for a review requesting changes, checks turning red, or the PR
|
|
1221
1241
|
merged or closed. In the web, a `path:line` in an answer links to that line
|
|
1222
|
-
of the session's PR ([Line links](context.md#line-links)).
|
|
1223
|
-
|
|
1242
|
+
of the session's PR ([Line links](context.md#line-links)). `auto_attach:
|
|
1243
|
+
offer` asks with a card first (`/pr-attach N`, `/pr-decline N`), `off`
|
|
1244
|
+
attaches nothing ([Attach, offer or off](context.md#attach-offer-or-off)).
|
|
1245
|
+
See [Attached context](context.md#github-prs-the-github-pr-bundle).
|
|
1224
1246
|
|
|
1225
1247
|
## The coordinator bundle
|
|
1226
1248
|
|
data/docs/sessions.md
CHANGED
|
@@ -65,7 +65,7 @@ chi sessions clean --dry-run --days 7 # test sessions older than 7 da
|
|
|
65
65
|
**Ordering:**
|
|
66
66
|
|
|
67
67
|
- `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.
|
|
68
|
-
- 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). 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, 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; 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, sampling?}], warning?}`; `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). 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
|
|
68
|
+
- 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). 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, 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; 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, sampling?, llm_context?}], warning?}`; `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).
|
|
69
69
|
- 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).
|
|
70
70
|
- 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), `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). Unit-tested via `npm test` (`node --test spec/web/public/*.test.js`).
|
|
71
71
|
- 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).
|
|
@@ -16,7 +16,8 @@ module Samagotchi
|
|
|
16
16
|
# iteration started before it (a before_tool_call hook's notice comes
|
|
17
17
|
# before its call's row, so the web puts it above row calls + 1). The
|
|
18
18
|
# loop's "asking again" row (:empty_answer_retry, after an empty or cut
|
|
19
|
-
# answer)
|
|
19
|
+
# answer), a steer's cut row (:steer_cut) and a ✂ row (:llm_context_edited,
|
|
20
|
+
# LLMContextNotice) are kept the same way, and so is a question the turn asked
|
|
20
21
|
# (:question_requested), with how it was answered or cancelled, so a
|
|
21
22
|
# reload draws the resolved card where it was.
|
|
22
23
|
#
|
|
@@ -28,9 +29,10 @@ module Samagotchi
|
|
|
28
29
|
# as /btw) goes after that turn: its prompt is already in the history.
|
|
29
30
|
# A failed turn leaves no prompt, so its cards stay before the next one.
|
|
30
31
|
#
|
|
31
|
-
# Notices (hook notices, load warnings, "asking again" rows)
|
|
32
|
-
# (with questions) are capped apart, +capacity+ each, so a
|
|
33
|
-
# notices can't push out a card
|
|
32
|
+
# Notices (hook notices, load warnings, "asking again" rows), ✂ rows
|
|
33
|
+
# and cards (with questions) are capped apart, +capacity+ each, so a
|
|
34
|
+
# burst of notices can't push out a card, nor a long turn's ✂ rows a
|
|
35
|
+
# hook's notice. An open question (an approval too) is
|
|
34
36
|
# never pushed out: the oldest other card or answered question goes.
|
|
35
37
|
#
|
|
36
38
|
# With a +path+ (the Bridge's: FILE in the session's folder) the store
|
|
@@ -47,11 +49,14 @@ module Samagotchi
|
|
|
47
49
|
class CardStore
|
|
48
50
|
CAPACITY = 20
|
|
49
51
|
NOTICE_TYPES = %i[hook_notice guardrail_warning empty_answer_retry steer_cut].freeze
|
|
52
|
+
# Capped apart from the notices.
|
|
53
|
+
LLM_CONTEXT_TYPES = %i[llm_context_edited].freeze
|
|
54
|
+
LLM_CONTEXT_FIELDS = %i[type moment why freed_tokens tail_tokens staged text groups].freeze
|
|
50
55
|
FILE = "cards.json"
|
|
51
56
|
# The events after which the file is written again: the ones that
|
|
52
57
|
# change an entry or the turn count.
|
|
53
|
-
SAVED_ON = (%i[card hook_notice empty_answer_retry steer_cut question_requested question_answered
|
|
54
|
-
question_relay turn_failed] + Events::TURN_KEPT).freeze
|
|
58
|
+
SAVED_ON = (%i[card hook_notice empty_answer_retry steer_cut llm_context_edited question_requested question_answered
|
|
59
|
+
question_cancelled question_relay turn_failed] + Events::TURN_KEPT).freeze
|
|
55
60
|
|
|
56
61
|
# What a session's saved file lists, as a store started from it lists
|
|
57
62
|
# (no turn running): the web's cards for a session no worker runs.
|
|
@@ -167,6 +172,7 @@ module Samagotchi
|
|
|
167
172
|
.compact.merge(in_turn: false, turns: @turns_done))
|
|
168
173
|
when :empty_answer_retry then add_turn_row(event.slice(:type, :attempt, :of, :stopped_by, :malformed)) if @running
|
|
169
174
|
when :steer_cut then add_turn_row(event.slice(:type, :source)) if @running
|
|
175
|
+
when :llm_context_edited then add_turn_row(Marshal.load(Marshal.dump(event.slice(*LLM_CONTEXT_FIELDS)))) if @running
|
|
170
176
|
when :question_requested
|
|
171
177
|
add_turn_row({ type: :question, pending_question: Marshal.load(Marshal.dump(event[:pending_question])) }) if @running
|
|
172
178
|
when :question_answered then resolve_question(event[:id], answer: event[:answer])
|
|
@@ -236,15 +242,20 @@ module Samagotchi
|
|
|
236
242
|
|
|
237
243
|
def push(entry)
|
|
238
244
|
@entries << entry
|
|
239
|
-
|
|
240
|
-
kind = @entries.select { |e|
|
|
245
|
+
cap = cap_class(entry)
|
|
246
|
+
kind = @entries.select { |e| cap_class(e) == cap }
|
|
241
247
|
return if kind.size <= @capacity
|
|
242
248
|
|
|
243
249
|
evict = kind.find { |e| !open_question?(e) }
|
|
244
250
|
@entries.delete_at(@entries.index { |e| e.equal?(evict) }) if evict
|
|
245
251
|
end
|
|
246
252
|
|
|
247
|
-
|
|
253
|
+
# Which cap +entry+ counts against: :notice, :llm_context or :card.
|
|
254
|
+
def cap_class(entry)
|
|
255
|
+
return :llm_context if LLM_CONTEXT_TYPES.include?(entry[:type])
|
|
256
|
+
|
|
257
|
+
NOTICE_TYPES.include?(entry[:type]) ? :notice : :card
|
|
258
|
+
end
|
|
248
259
|
|
|
249
260
|
def open_question?(entry)
|
|
250
261
|
entry[:type] == :question && !entry.key?(:answer) && !entry[:cancelled]
|
|
@@ -4,7 +4,8 @@ module Samagotchi
|
|
|
4
4
|
class Bridge
|
|
5
5
|
# The events a running turn shows as rows of its own (not text, thinking
|
|
6
6
|
# or a tool call): a hook's notice, the loop asking again after an empty
|
|
7
|
-
# or cut answer, a
|
|
7
|
+
# or cut answer, a batch of LLM context edits (✂), a question and how it
|
|
8
|
+
# was answered. A UI that joins the
|
|
8
9
|
# turn mid-way (TurnAccumulator's "notice" part) and one that reloads a
|
|
9
10
|
# finished turn (CardStore) get the event back with the fields listed
|
|
10
11
|
# here, and draw it with the handler that drew it live, where it was.
|
|
@@ -13,6 +14,7 @@ module Samagotchi
|
|
|
13
14
|
hook_notice: %i[hook text level fallback_for],
|
|
14
15
|
empty_answer_retry: %i[iteration attempt of stopped_by malformed],
|
|
15
16
|
steer_cut: %i[iteration source],
|
|
17
|
+
llm_context_edited: %i[moment why freed_tokens tail_tokens staged text groups],
|
|
16
18
|
question_requested: %i[pending_question],
|
|
17
19
|
question_answered: %i[id answer],
|
|
18
20
|
question_cancelled: %i[id reason]
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: github-pr
|
|
3
|
-
version: 0.
|
|
3
|
+
version: 0.3.0
|
|
4
4
|
scope: system
|
|
5
|
-
description: Attaches the branch's open GitHub pull request to a session as context (and any PR URL with chi context add or the web's "+ URL"); the agent gets a note when reviews, comments, checks or its state change; in the web, a path:line in an answer links to that line of the PR
|
|
5
|
+
description: Attaches the branch's open GitHub pull request to a session as context (and any PR URL with chi context add or the web's "+ URL"); the agent gets a note when reviews, comments, checks or its state change; in the web, a path:line in an answer links to that line of the PR; the auto_attach setting can offer the PR with a card first, or attach nothing
|
|
6
6
|
trust_level: reviewed
|
|
7
|
-
requires_chi: ">= 0.
|
|
7
|
+
requires_chi: ">= 0.43.0"
|
|
8
8
|
needs:
|
|
9
9
|
- command: gh
|
|
10
10
|
why: reads the pull request
|
|
11
11
|
hint: brew install gh, then gh auth login
|
|
12
12
|
plugin:
|
|
13
13
|
file: plugin.rb
|
|
14
|
-
sha256: sha256:
|
|
14
|
+
sha256: sha256:8c3b1b2de9112320d95d42d19b924a2a6bb0418715d3c78a24ac695c7b825487
|
|
15
15
|
scripts:
|
|
16
16
|
pr_context.rb: sha256:a883d2780e89c68c0d7b6d5e0fcb22c273f17bb167e79064e0e99db6bd2ee6f0
|
|
17
17
|
context_providers:
|