samagotchi 0.161.0 → 0.162.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 +25 -1
- data/docs/architecture.md +1 -1
- data/docs/internals/block-renderers.md +3 -2
- data/docs/internals/bridge.md +61 -11
- data/docs/internals/inline-widgets.md +6 -3
- data/docs/internals/web-frontend.md +1 -1
- data/docs/sessions.md +1 -1
- data/docs/testing.md +7 -1
- data/lib/samagotchi/bridge/card_store.rb +23 -13
- data/lib/samagotchi/bridge/turn_accumulator.rb +7 -1
- data/lib/samagotchi/bridge/turn_drawings/synth.rb +555 -0
- data/lib/samagotchi/bridge/turn_drawings.rb +103 -7
- data/lib/samagotchi/bridge/turn_ranges.rb +175 -0
- data/lib/samagotchi/bridge.rb +35 -12
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/plugin/sessions.rb +8 -1
- data/lib/samagotchi/project_id_clash.rb +1 -1
- data/lib/samagotchi/terminal_ui/join_replay.rb +34 -128
- data/lib/samagotchi/terminal_ui.rb +12 -1
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/message_display.rb +5 -1
- data/lib/samagotchi/web/public/block_frame.js +5 -1
- data/lib/samagotchi/web/public/timing.js +17 -6
- data/lib/samagotchi/web/public/turn_block.js +6 -2
- data/lib/samagotchi/web/public/widget_walk.js +4 -2
- data/lib/samagotchi/web/session_show.rb +22 -11
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66e023d71f974fccd3b2767f7a45d876663217d787f4c38b177e7074732fdf6b
|
|
4
|
+
data.tar.gz: 32dd57df62fa6b818b2b801b678ad253ae93d1adf5a0821c4eed0ce61b39830a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c6cec4ce646d2759235f417e6bea5cb818c4dac96f1395c9a2fd79476ca1ca6428921f02ef61345339cb8b4c7fe51d17fd4d3a5affbc1e4a30dd2448680c597c
|
|
7
|
+
data.tar.gz: 1d2b52160476da47449b1e72112a97cbbfd0888fdaa7203834776afaf914b149c8b11b3915b566f0e9542c996c074a81c09959ad37ce2ce08a8943924b51327f
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,29 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.162.0] - 2026-11-10
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- chi web draws every finished turn the way it was drawn live; turns from before drawings (and past the newest 100)
|
|
16
|
+
are drawn from a drawing rebuilt from their messages, with small differences (no hook notices or durations that were
|
|
17
|
+
never kept).
|
|
18
|
+
- chi --attach draws the last turn the same way for every session.
|
|
19
|
+
- A forked session and a one-shot run keep their turns' drawings.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- The copied-folder notice (two folders sharing a chi project id) no longer tells the original to take a new id: it
|
|
24
|
+
names both folders and says to run `chi project init --new-id` in the copy.
|
|
25
|
+
- chi --attach draws the last turn as live even when a note came after it.
|
|
26
|
+
- chi web no longer leaves a language's diagrams as source for the whole session when a renderer file's download
|
|
27
|
+
stalls (behind a proxy or a tunnel): the download is bounded at 15 s like the rest of the load.
|
|
28
|
+
- A chi-ui walk's case that goes back to its own step (a retry) is drawn disabled as "this step" instead of a button
|
|
29
|
+
that did nothing.
|
|
30
|
+
|
|
31
|
+
Update with `chi update`, then restart chi web and running sessions (`chi sessions restart`): workers from 0.161.0
|
|
32
|
+
keep working (N-1); the turn drawing changes apply to workers started by 0.162.0.
|
|
33
|
+
|
|
11
34
|
## [0.161.0] - 2026-11-10
|
|
12
35
|
|
|
13
36
|
### Added
|
|
@@ -6006,7 +6029,8 @@ and long-lived sessions.
|
|
|
6006
6029
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6007
6030
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6008
6031
|
|
|
6009
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.
|
|
6032
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.162.0...HEAD
|
|
6033
|
+
[0.162.0]: https://github.com/dm1try/samagotchi/compare/v0.161.0...v0.162.0
|
|
6010
6034
|
[0.161.0]: https://github.com/dm1try/samagotchi/compare/v0.160.0...v0.161.0
|
|
6011
6035
|
[0.160.0]: https://github.com/dm1try/samagotchi/compare/v0.159.0...v0.160.0
|
|
6012
6036
|
[0.159.0]: https://github.com/dm1try/samagotchi/compare/v0.158.0...v0.159.0
|
data/docs/architecture.md
CHANGED
|
@@ -194,7 +194,7 @@ log's last 4 MB). Rows: [configuration.md](configuration.md#checking-it-chi-home
|
|
|
194
194
|
## Session retention & ordering
|
|
195
195
|
|
|
196
196
|
- **Files:** `~/.local/state/samagotchi/sessions/<uuid>.json` + `<uuid>/input|output|owner.lock|bridge.json` (XDG-aware), and the `<uuid>/stopped`, `<uuid>/starting` and `<uuid>/archived` marker files. Durable schedules belong to the machine, not a session: `~/.local/state/samagotchi/schedules.json` and its `schedules.lock`, next to `sessions/` ([Scheduling](scheduling.md)).
|
|
197
|
-
- **Single owner:** the process running a session's Engine (its worker, or a `--non-interactive` one-shot) holds a flock on `owner.lock` (`OwnerLock`); a second owner backs off, and the web answers 409 for a session a one-shot owns.
|
|
197
|
+
- **Single owner:** the process running a session's Engine (its worker, or a `--non-interactive` one-shot) holds a flock on `owner.lock` (`OwnerLock`); a second owner backs off, and the web answers 409 for a session a one-shot owns. That owner is also the one writer of the session's `turn_drawings.jsonl` (a worker's Bridge, a one-shot's own accumulator); a fork's copy of its parent's lines is written before the child's worker spawns.
|
|
198
198
|
- **Status:** `status` is turn state (`idle`/`running`); liveness is the lock. A stop is the `<uuid>/stopped` marker (`Session.mark_stopped`; a resume removes it), which `Session.load` and `.summary_from_file` read as status `stopped`, so no other process rewrites a worker's session file. A resume writes nothing else: the worker, holding the lock, turns a status from before it idle (`Worker#settle_stale_status`: `stopped` with no marker, `error`, a `running` no turn is behind; not a new session's `running` whose first prompt waits), and saves at start whatever the status, which stamps `updated_at` as the resume's save did (a session woken with no turn stays young for the sweep). N-1: a newer spawner starting an older worker (a checkout's chi spawning the installed one) loses that reset; a restart covers it.
|
|
199
199
|
- **Starting:** every spawn marks the session starting (`<uuid>/starting`, `{pid, at}`, `StartingMarker`) until its worker holds the lock: `spawn_worker_for_session` writes it with its own pid before `Process.spawn` and the starter's after (the starter lives until the worker holds the lock, at most `WORKER_START_GRACE`; a spawn that raises or whose starter is gone leaves none), `spawn_session` before the new file is saved, and `Worker#start` removes it. It holds for 60 s at most, and only while the pid it names runs. A resume claims it (`StartingMarker.claim`, a link(2): of resumes racing from any processes one wins), then reads the owner again. A stop marker cancels the hold-off (`start_pending?` = starting and not stop-marked) for a start marked before the stop only: of two sends after a stop, the claim lets one spawn. The stop marker carries its own `at` (`{"at"}`, on the starting marker's clock; `Session.stopped_at`), an older chi's empty one its mtime. The sweep, archive (`:starting`) and delete (refused as an owned session) honour it. N-1: an older spawner writes none for a resume (the owner checks stay); an older worker never leaves one it was given (every worker clears it at start); a leftover one is stale by age or pid (a claim's temp files a kill left, `starting.*`, count as skeleton); a 0.160 spawner or chi web still holds off on a fresh marker under a stop (it reads `starting?` before the stop), until the start ends or 60 s. `SessionManager` keeps only its starters' pids, for chi web's restart to adopt (`live_spawn_pids`), and decides nothing from them.
|
|
200
200
|
- **Deleting:** `delete_session`, the retention sweep and a failed continue's cleanup use `remove_files` for the session JSON, sidecar dir, plugin state, attached context, participant grants, System 1 runs and context-candidate records. The JSON and dir go through `remove_session_files`, holding the owner lock (kind `deleting`, which `stop_session` never signals; not waited for: a worker that took it since the check keeps the session) and reading the starting marker again under it (a resume that claimed the start just before keeps the session; one after it sees the lock held). N-1: an older chi's stop reading the owner then would TERM the deleter (chi web, the CLI) in that moment; an older reader shows the kind as unknown. `Session#save` of a session read from its file (or saved once) skips a file that is gone (log `save_skipped_deleted`) rather than recreate it; only a new session's first save creates one.
|
|
@@ -30,7 +30,8 @@ model. The TUI is untouched: it shows a fence as source.
|
|
|
30
30
|
move isn't over when it is seen:** a block waiting to come near is watched by its scroller's observer, so one that moves
|
|
31
31
|
to another scroller (the stage's `.ts-scroll` hands a long answer to `#history`) is watched there, or it never draws.
|
|
32
32
|
4. `block_frame.js` (`createBlockFrame`): one hidden frame per language, made on first need, one render at a time, 15 s per
|
|
33
|
-
call
|
|
33
|
+
call, the renderer files' fetch included (browser `fetch` has no timeout; a fetch past it is a failed load). A timeout, a
|
|
34
|
+
dead frame or a session switch drops it, and a drop rejects whatever is pending, the load too. Handshake `loaded` → `code {files}` → `ready | failed`,
|
|
34
35
|
then `render {id, source, theme}` → `done {id, svg} | error {id, message}`.
|
|
35
36
|
5. On success a `<figure class="block-drawn">` goes right before the `<pre>`, which stays in the DOM, `hidden`, so whatever
|
|
36
37
|
reads text (copy, a claim's walk, fold thresholds) sees what it did. **The DOM is the state** (`block_source.js`): a Revise
|
|
@@ -77,7 +78,7 @@ is model-written**, so a renderer bug or an injected diagram must not reach a pa
|
|
|
77
78
|
has origin `null` and can't read chi's API; WebKit may still attach a same-host cookie to a request it makes (seen with a
|
|
78
79
|
test cookie to another port), so what holds is that the answer stays unreadable, not that no cookie is ever sent.
|
|
79
80
|
3. The page accepts messages only where `e.source === frame.contentWindow`, of known types, and treats them as data
|
|
80
|
-
(`frameMessage`). No other window `message` listener exists on the page.
|
|
81
|
+
(`frameMessage`). No other window `message` listener exists on the page (`spec/web/public/message_listeners.test.js` keeps it so).
|
|
81
82
|
4. Code enters the frame by postMessage from the page's own authenticated fetch (the frame's CSP closes its network but for
|
|
82
83
|
WebRTC, the residual risk below, and it has no cookie),
|
|
83
84
|
then as `script.text = code`. `eval` doesn't work: a library's `"use strict"` keeps its global local. A syntax error doesn't
|
data/docs/internals/bridge.md
CHANGED
|
@@ -77,28 +77,78 @@ accumulator's final fold of the turn (its parts in order, in-turn cards included
|
|
|
77
77
|
"enqueue-only" note, as CardStore's save does: one append per turn end. It writes `"\n"` first when the file's last
|
|
78
78
|
byte isn't one (a torn line from a crash), then the line in one write; a failure is logged (`turn_drawing_failed`).
|
|
79
79
|
A part's output is the accumulator's cut (`WEB_PREVIEW_CHARS`); a diff is the one the saved `tool_diffs` have
|
|
80
|
-
(`TextDiff`'s cut); images are refs.
|
|
80
|
+
(`TextDiff`'s cut); images are refs. The writer is the session's owner under `OwnerLock`: its worker's Bridge, or a
|
|
81
|
+
`-p X --non-interactive` one-shot, whose `TerminalUI#run_one_shot_turn` tees its events to an accumulator with the
|
|
82
|
+
same hook. A fork's child starts with its parent's lines that hold against its seed (`TurnDrawings.carry`, in
|
|
83
|
+
`Plugin::Sessions#fork`'s `before_spawn`, before the child's worker exists: same indices, same digests; a range
|
|
84
|
+
whose end the image copy changed is dropped and made from its messages at read). A seed without the system head (a
|
|
85
|
+
plugin's `ctx.messages`) is checked as the child's messages will be once its first turn puts the head back: the
|
|
86
|
+
lines keep the parent's indices, so until that turn they don't hold and their turns are made from the messages.
|
|
81
87
|
- **Reading.** `TurnDrawings.read(dir)` skips an unknown `v`, a torn or broken line and one missing a field, and is
|
|
82
88
|
cached by the file's path, size and mtime. `#last` is the newest line this worker wrote or started from.
|
|
89
|
+
`TurnDrawings.cover(lines, messages, timing:, entries:, skip_turn_id:, session_id:, cwd:)` is what a show draws
|
|
90
|
+
finished turns from (pure): `valid`'s lines, and for each `TurnRanges` range none overlaps (the running turn's
|
|
91
|
+
left out), a line `Synth.memoized` makes from its messages, the timing's records and CardStore's entries. A made
|
|
92
|
+
range whose id a kept line has (a failed turn's kept steps, then its re-run under that id) is renamed `<id>~<from>`,
|
|
93
|
+
so no two lines share an id. `TurnRanges.of(messages)` (`bridge/turn_ranges.rb`) reads a session's turns
|
|
94
|
+
back from its messages as the Engine cuts them (`kept_from…kept_to`: the reminders before an opening start a turn; a
|
|
95
|
+
note after it, a `!cmd`'s record and a wake's note stay outside), with a display id for a turn with none
|
|
96
|
+
(`m<from>-<digest8>`) or a repeated one (`<id>~<from>`); `TurnRanges.records` pairs each with its turn record by id,
|
|
97
|
+
else by place among the openings, as `timing.js turnGroups` does (`spec/shared/turn_ranges.json` holds the cases both
|
|
98
|
+
suites read).
|
|
99
|
+
- **Made from the messages.** `TurnDrawings::Synth` (`bridge/turn_drawings/synth.rb`; chi web's show, `cover`) makes
|
|
100
|
+
a turn's line from its saved messages, for a `TurnRanges` range no live line covers: the events live would have
|
|
101
|
+
emitted (`turn_started`, the reminders, each step's thinking, text and calls with `MessageParts`' fields and the
|
|
102
|
+
output as `preview:`, steers and merged lines, the end from the turn record), folded by a fresh `TurnAccumulator`,
|
|
103
|
+
so every drawing comes from the one fold. The turn's tool records give each row's status and duration (by tool, in
|
|
104
|
+
call order), and CardStore's entries of the turn (`of_turn`) go in at the step they name (`iteration`, `calls`; an
|
|
105
|
+
in-turn card keeps them too): its cards, hook notices, retries (a retried step is drawn empty), steer cuts, ✂ rows
|
|
106
|
+
and questions. A made-up id (`m…`, `…~<from>`) stays off the end's `turn_id` (no Revise); the end carries the
|
|
107
|
+
record's `record_id`. `Synth::LOSSES` lists what it can't have (a prompt's origin, a merged line's senders, a
|
|
108
|
+
retried step's thinking, evicted CardStore entries, untimed rows, …; `events_drift_spec` makes each `:row` event
|
|
109
|
+
synthesized or listed; a repeated id's later range and a Continue's steps read as its turn's are declared too).
|
|
110
|
+
The fold raises what it can't fold (`TurnAccumulator.new(raise_errors: true)`), and `safe_line` never raises: a
|
|
111
|
+
minimal line (opening, end kind, no parts, `turn_synth_failed`, once), else a constant one (`constant`: the range and
|
|
112
|
+
a completed end); `memoized` keeps lines per range (key: session, range, every message's digest in it, the turn's
|
|
113
|
+
records and its entries without CardStore's listing fields) in a process-wide LRU of `MEMO_BYTES`.
|
|
83
114
|
- **The snapshot.** `Bridge#snapshot` (the snapshot and reset frames, `GET /snapshot`) adds `last_turn_drawing:
|
|
84
|
-
{drawing, end}
|
|
85
|
-
|
|
86
|
-
|
|
115
|
+
{drawing, end}`: the line of the last prompt's turn (the last user message that opens a turn, the one the TUI draws),
|
|
116
|
+
the newest for that turn id that holds against the snapshot's messages (`#last`, else the file's, `TurnDrawings.read`),
|
|
117
|
+
not unfolded, when that turn is the last one (`TurnRanges`: a note after it doesn't hide it). It is absent otherwise:
|
|
118
|
+
a later turn with no prompt (a reminder's, a Continue's: a join would draw the prompt's rows, then the later turn's
|
|
119
|
+
answer without its rows), no prompt with a turn id, a rollback, a line of another version, one over the 1 MB a
|
|
120
|
+
restart reads back (`TurnDrawings.sendable?`). An attaching TUI unfolds it (`TerminalUI::JoinReplay`, `TurnAccumulator.replay_events`) and draws
|
|
87
121
|
that turn's rows through its `EventRenderer`, as a running turn's join does, then the end event's cancel or failure
|
|
88
|
-
line, else the saved answer
|
|
89
|
-
|
|
122
|
+
line, else the saved answer. Without it (an older worker, a line over 1 MB, a turn from before drawings) the TUI
|
|
123
|
+
makes that turn's line itself: `TurnRanges.of` over the snapshot's messages finds the prompt's range, and
|
|
124
|
+
`Synth.safe_line` draws it with the link's saved records (`LocalLink`, or `RemoteLink#saved_turn_record` /
|
|
125
|
+
`#saved_tool_records` through chi web for `--remote`) and the snapshot's cards, through the same renderer. Nothing
|
|
126
|
+
rebuilds rows from the messages any more. `chi --remote` attaches through chi web's stream proxy,
|
|
90
127
|
which relays an owner's frames byte for byte, the field included. A participant never gets it: its stream's snapshot
|
|
91
128
|
is bare (`ParticipantView`). An older TUI ignores the field; an older worker sends none.
|
|
92
|
-
- **The show.** chi web's full read with `?parts=1&drawings=1` (the page's)
|
|
93
|
-
|
|
129
|
+
- **The show.** chi web's full read with `?parts=1&drawings=1` (the page's) draws every finished turn from a line:
|
|
130
|
+
`SessionShow#drawn_lines` is `TurnDrawings.cover` over the file, the show's timing records and its cards (CardStore's
|
|
131
|
+
list, live or saved), the running turn (`current_turn`'s id) left out. A file that can't be read gives no lines, so
|
|
132
|
+
every turn is made from its messages; should the cover itself fail (`turn_drawings_uncovered`), the turns draw as
|
|
133
|
+
before. It stamps each display item of a kind a
|
|
134
|
+
drawing draws (the opening, steps, steers, merged lines, the empty answer) in a line's range with `drawn: <turn_id>`
|
|
94
135
|
and drops its `parts` (its ✂ marks stay as `marks: {tool_id => edit}`), and sends `turn_drawings: {turn_id =>
|
|
95
136
|
{events, end}}`: `TurnAccumulator.replay_events(drawing, cards: true)`, the one unfold, in Ruby. A context note in
|
|
96
137
|
a range and a `!cmd`'s record are not stamped. Without `drawings=1` (an older page) the read is what it was.
|
|
97
138
|
CardStore lists an in-turn entry's turn as `of_turn`, so the page leaves a drawn turn's own rows and cards to its
|
|
98
139
|
drawing (`cards_place.js`). A live worker whose sidecar features lack `turn_drawings` (`TurnDrawings::FEATURE`:
|
|
99
|
-
an older one lists no `of_turn`) gets no drawings in the show: its turns all draw as before.
|
|
100
|
-
|
|
101
|
-
|
|
140
|
+
an older one lists no `of_turn`) gets no drawings in the show: its turns all draw as before. The stamps walk the
|
|
141
|
+
lines with one cursor and the unfold reads a Set of stamped ids, so a long session's show is linear in its turns;
|
|
142
|
+
a made-up line is memoized per range (`Synth.memoized`), so a show after a turn end makes no old turn again.
|
|
143
|
+
- **Compat.** An older worker writes nothing, a continue (a note, no turns) and a review fork copy no drawings, and
|
|
144
|
+
an older chi's fork or one-shot wrote none: their turns are made from their messages. The lines a fork carries and a
|
|
145
|
+
one-shot writes are plain `v: 1` lines, which an older chi web draws as any. An older chi web never opens the file and draws them as it
|
|
146
|
+
did. A made-up line's end has no `turn_id` for a made-up id and names its record (`record_id`), which a 0.157+ page
|
|
147
|
+
reads as any drawn turn's (an older page ignores `record_id` and finds no record for such a turn: no timing line;
|
|
148
|
+
it also keys such a turn's answer by the made id, `data-answer-turn`, until a reload: only a turn saved before turn
|
|
149
|
+
ids or a repeated id's, never a wake turn, which has its own id).
|
|
150
|
+
`release:bump`'s compat corpus has a session with a line (`compat-drawn`) and one without; `readers_spec` checks
|
|
151
|
+
every turn of both is stamped.
|
|
102
152
|
|
|
103
153
|
## CardStore
|
|
104
154
|
|
|
@@ -24,7 +24,10 @@ its spec holds to a strict parse. Without it nothing here changes, and blocks al
|
|
|
24
24
|
drawers for one block.
|
|
25
25
|
|
|
26
26
|
**Safety.** The JSON is an attribute value: Nokogiri escapes its quotes, and `<`, `>` and `&` in it are `\u` escapes
|
|
27
|
-
(`JSON_MARKUP`), so
|
|
27
|
+
(`JSON_MARKUP`), so `data-widget`'s JSON holds no model markup even as attribute text. `data-widget-error` is not
|
|
28
|
+
escaped that way: a refusal quotes model values (`recommended "<b>z</b>" isn't one of its options`), so it can hold a raw
|
|
29
|
+
`<` or `>` inside its quoted value. The page reads it only as data (`failBlock`'s dataset, CSS, `aria-label`), never as
|
|
30
|
+
markup, and no consumer should treat rendered HTML with a regex. The page draws all strings as text.
|
|
28
31
|
|
|
29
32
|
## The parse (`Samagotchi::InlineWidgets`)
|
|
30
33
|
|
|
@@ -52,7 +55,7 @@ Pure Ruby, no web, no Engine. `parse(source)` returns a `Result`: `ok?`, `type`,
|
|
|
52
55
|
the key to the value's end when both sit on one line, else `key: value`. The Result is then `lenient?`. A mapping
|
|
53
56
|
of several pairs, or one holding a list or a mapping, stays an error, and so does one where an id, an actor, a
|
|
54
57
|
`next` or a `goto` goes. This is a mend, not a second lenient pass (`Tree#folds`, `Schema#text`).
|
|
55
|
-
- **Normalised.** Ids are strings, unknown keys are dropped, optional values are absent rather than null, and text is
|
|
58
|
+
- **Normalised.** Ids are strings, unknown keys are dropped, a repeated key is last-wins (`Tree#mapping`), optional values are absent rather than null, and text is
|
|
56
59
|
stripped. The page never sees model junk.
|
|
57
60
|
|
|
58
61
|
### The schemas
|
|
@@ -60,7 +63,7 @@ Pure Ruby, no web, no Engine. `parse(source)` returns a `Result`: `ok?`, `type`,
|
|
|
60
63
|
| | Required | Optional | Rules |
|
|
61
64
|
|---|---|---|---|
|
|
62
65
|
| picks | `rows`: rows of `id`, `text`, `options` (2-4 texts) | `title`; on a row `recommended`, `why` | ids unique; a row's options unique; `recommended` is one of the options |
|
|
63
|
-
| walk | `title`, `actors` (2-5 texts), `steps`: steps of `id`, `actor`, `does` or `sees` | on a step `behind`, `next`, `cases` (each `when` + `goto`) | ids unique, none of them `end`; actors unique; `actor` is one of the actors; `next` names a step or is `end`, and not the step itself; every `goto` names a step |
|
|
66
|
+
| walk | `title`, `actors` (2-5 texts), `steps`: steps of `id`, `actor`, `does` or `sees` | on a step `behind`, `next`, `cases` (each `when` + `goto`) | ids unique, none of them `end`; actors unique; `actor` is one of the actors; `next` names a step or is `end`, and not the step itself; every `goto` names a step, its own included (a retry, as models write it: the page draws that case disabled, "this step") |
|
|
64
67
|
|
|
65
68
|
Eval round 1's `branches:` (the same shape as `cases:`) is read as `cases`.
|
|
66
69
|
|
|
@@ -52,7 +52,7 @@ change.
|
|
|
52
52
|
| **`store.sessions`** (the hub's projection) | every card | `store.update({sessions})` from app.js: `openSessionEvents` (`applySessionEvent`), `refresh` (the list fallback), `addCreatedSession`, `applyView` (re-sorted), `replaceSelectedCard` (`setLiveStatus` through `setStatus`, `readTurnEnd`, `setUsedMemories`), the stream's close (`withoutWorker`); `session_actions.js` (`setSessions`) | the store: `lists` and `infoBar`. **Always a new array**; an entry is replaced, never changed in place. `followSelectedSession` copies the open one's owner and worker (`fieldsFromCard`) and, when not streaming, its status (`setStatus(…, "hub")`) into `store.current` |
|
|
53
53
|
| **Factory closures**: the `create*` factories (popovers, panels, views) | each component's own state: open-for, busy, error, its own fetched list | the factory | an `onChange` hook back into app.js, or a getter the factory reads at draw time |
|
|
54
54
|
| **The history DOM** | the conversation as drawn: which turn a bubble belongs to (`data-turn-id`, `data-answer-turn`), what opens a turn (`TURN_PROMPT`, `bubbles.js`: a prompt or a wake's note, the same turns `Steer.turn_opening?` counts for a card's `turns_since`), an opening's id for a card's and the saved recap's stamp (`data-turn-id` on a prompt, `data-opening-id` on a wake's note or `/continue no`'s reason line; `card_stamps.js` places a snapshot's card after the stamped opening, `recap_stamp.js` the saved recap after the last turn it covers, each by its count (`turns_since`) only without one), kept command bubbles, which texts were shown, unnamed badges, folded answers and long prompts (`.folded`), Revise stamps (`data-revises` on a prompt; a Verify turn's `data-verify`) and the stacks' folded versions (`.stack-hidden`, `.stack-stub.open`); the switcher's version on view is `revise_stack.js`'s own (a copy `.stack-view` before the top answer, the top `.stack-swapped`; never stored) | `bubbles.js`, `cards_place.js`, `question_cards.js`, `turn_block.js`/`stage_view.js`, `answer_fold.js`, `revise_stack.js`, `stream_handlers.js` (a live `turn_completed`'s `revises` and `verify` onto its prompt) | read back as state: `turn_range.js turnElements` (one walker for a turn's elements), `keptCommandBubbles`, `seedSeenFromDom`, `nameUnnamedBadges`/`nameVerdictCards`, `answer_fold.js` and `revise_stack.js` (their observers decorate every path that fills `#history`; the stacks are `stacks()` of the stamps, read again on each change, never a store field), `history_reveal.js revealInHistory` (the one way a jump unfolds what hides its target) |
|
|
55
|
-
| **A drawn turn** (`turn_drawings` of the full read, `?parts=1&drawings=1`) | a finished turn as live drew it: `turnGroups` makes its stamped items (`drawn: <turn_id>`) one group, and `turnHistoryNodes` draws it by feeding its drawing's events to a live turn block offscreen (`turn_block.js drawnTurnNodes`: the block's own handlers, as the stage's), the stage's extras (a reminder, merged lines, a card that asks or warns) and end as live, then the answer, the merged lines and the steps' texts from their saved items (markdown, refs). Each of its top-level elements carries `data-drawn`: `cards_place.js` leaves that turn's in-turn CardStore entries (`of_turn`) to it, and a kept reminder bubble of that turn (`data-turn-id`) stays out after a resync.
|
|
55
|
+
| **A drawn turn** (`turn_drawings` of the full read, `?parts=1&drawings=1`) | a finished turn as live drew it: `turnGroups` makes its stamped items (`drawn: <turn_id>`) one group, and `turnHistoryNodes` draws it by feeding its drawing's events to a live turn block offscreen (`turn_block.js drawnTurnNodes`: the block's own handlers, as the stage's), the stage's extras (a reminder, merged lines, a card that asks or warns) and end as live, then the answer, the merged lines and the steps' texts from their saved items (markdown, refs). Each of its top-level elements carries `data-drawn`: `cards_place.js` leaves that turn's in-turn CardStore entries (`of_turn`) to it, and a kept reminder bubble of that turn (`data-turn-id`) stays out after a resync. chi web sends a drawing for every finished turn (one made from its messages where live wrote none): `drawnGroup` pairs the record the end names (`end.record_id`, by place for a turn saved before turn ids), else by the turn's id, and the answer's `data-answer-turn` is the end's own `turn_id` only (a made-up id, `m…` or `…~N`, keys none: no Revise). An item that comes unstamped (an older chi web, a miss) is still rebuilt from its messages | chi web (the show) | `renderHistory`, the reload check's render |
|
|
56
56
|
| **localStorage** (`storage.js` `readStored`/`writeStored`, guarded) | per-browser choices only | the module that owns the choice | read at start (see Storage keys) |
|
|
57
57
|
| **SSE** | see Streams | the server | owner page: events go into the DOM directly; participant page: an event marks the data stale |
|
|
58
58
|
|
data/docs/sessions.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Sessions
|
|
2
2
|
|
|
3
|
-
Sessions are plain files — no DB. Each session is `~/.local/state/samagotchi/sessions/<uuid>.json` (XDG-aware via `XDG_STATE_HOME`) plus a sidecar dir `<uuid>/` with `input/`/`notes/`/`output/`/`owner.lock`/`bridge.json` (`Session.session_dir`), `turn_drawings.jsonl` once a turn ended with a Bridge (each finished turn as live drew it, which the web's reload draws: [bridge.md](internals/bridge.md#turndrawings)), and `tool_output/` once a long `execute` result was cut: its whole output, which the cut result names (`ToolOutputFiles`, the newest 50 kept; see [Tool output guardrails](internals/tool-output-limits.md#the-runners-cut-max_tool_output_chars)). Its keys are in [the Session file table](#session-file). A file from before `used_memory_names`, `preloaded_memory_names`, `muted_memory_names`, `parent_id` or `continues` reads those as empty lists, no parent and no previous link.
|
|
3
|
+
Sessions are plain files — no DB. Each session is `~/.local/state/samagotchi/sessions/<uuid>.json` (XDG-aware via `XDG_STATE_HOME`) plus a sidecar dir `<uuid>/` with `input/`/`notes/`/`output/`/`owner.lock`/`bridge.json` (`Session.session_dir`), `turn_drawings.jsonl` once a turn ended with a Bridge or in a one-shot run (each finished turn as live drew it, which the web's reload draws: [bridge.md](internals/bridge.md#turndrawings); a fork starts with its parent's lines for the turns its seed keeps unchanged, a continue with none: its turns, and any without a line, are drawn from their messages), and `tool_output/` once a long `execute` result was cut: its whole output, which the cut result names (`ToolOutputFiles`, the newest 50 kept; see [Tool output guardrails](internals/tool-output-limits.md#the-runners-cut-max_tool_output_chars)). Its keys are in [the Session file table](#session-file). A file from before `used_memory_names`, `preloaded_memory_names`, `muted_memory_names`, `parent_id` or `continues` reads those as empty lists, no parent and no previous link.
|
|
4
4
|
|
|
5
5
|
**Message times:** an entry of `messages` may carry `at`, when it happened: a local-offset ISO time with milliseconds (`2026-10-24T14:32:05.120+02:00`). User prompts, lines merged into a turn and steers, reminders, context and task notes, and the model's replies have one (a note's is its `created_at`); tool results, `!cmd` messages and chi's own turn notes don't, nor does anything saved before chi stamped messages (no backfill). It is for the UIs only (the gap dividers, a bubble's time): it never goes to the model, so it changes nothing in the requests or their prompt cache. The one time the model reads is the reminders': due reminders go into a turn as a system message headed `[SYSTEM: REMINDERS DUE 2026-10-24 14:32 local]` (the turn's local time; `ReminderQueue#inject!`), written into the saved content then, so a later request sends the same text.
|
|
6
6
|
|
data/docs/testing.md
CHANGED
|
@@ -180,7 +180,13 @@ Each level owns its own share; a detail is asserted once, at the lowest level th
|
|
|
180
180
|
scenarios in `spec/shared/turn_drawings/` (written from `spec/support/turn_drawing_scenarios.rb`;
|
|
181
181
|
`UPDATE_TURN_DRAWINGS=1 bundle exec rspec spec/bridge/turn_drawings_spec.rb spec/web/session_show_drawings_spec.rb`
|
|
182
182
|
rewrites their lines and show after an intended change) feed `turn_drawing_parity.test.js`, which draws each one
|
|
183
|
-
live (the real stream handlers and stage) and from its drawing and compares the shapes with no allow list.
|
|
183
|
+
live (the real stream handlers and stage) and from its drawing and compares the shapes with no allow list.
|
|
184
|
+
`spec/shared/turn_ranges.json` (`UPDATE_TURN_RANGES=1 bundle exec rspec spec/bridge/turn_ranges_spec.rb`) pins
|
|
185
|
+
`Bridge::TurnRanges`' turns and record pairing against `timing.js turnGroups` (timing.test.js). Each scenario's
|
|
186
|
+
fixture also holds `synth`, the show drawn from `TurnDrawings::Synth`'s lines (written by
|
|
187
|
+
`spec/bridge/turn_drawings_synth_spec.rb`, which also compares each synth line with the live one minus
|
|
188
|
+
`Synth::LOSSES`); the parity test's synth arm draws it against live, each scenario naming the losses that change its
|
|
189
|
+
shape (`SYNTH_LOSSES_OF`). The
|
|
184
190
|
`lan` project's chi web is on the LAN only
|
|
185
191
|
when the machine has a private IPv4: without one its LAN tests skip and the participant review journey runs on
|
|
186
192
|
loopback.
|
|
@@ -6,6 +6,7 @@ require_relative "../atomic_file"
|
|
|
6
6
|
require_relative "../events"
|
|
7
7
|
require_relative "../state_format"
|
|
8
8
|
require_relative "card_places"
|
|
9
|
+
require_relative "turn_notice"
|
|
9
10
|
|
|
10
11
|
module Samagotchi
|
|
11
12
|
class Bridge
|
|
@@ -68,15 +69,18 @@ module Samagotchi
|
|
|
68
69
|
version: FORMAT_VERSION,
|
|
69
70
|
members: [StateFormat.required(:type), StateFormat.extra(:extra, in_version: FORMAT_VERSION)]
|
|
70
71
|
)
|
|
71
|
-
|
|
72
|
+
# A question's events (TurnNotice's too): one :question entry, never
|
|
73
|
+
# pushed out while open.
|
|
74
|
+
QUESTION_EVENTS = %i[question_requested question_answered question_cancelled].freeze
|
|
72
75
|
# Capped apart from the notices.
|
|
73
76
|
LLM_CONTEXT_TYPES = %i[llm_context_edited].freeze
|
|
74
|
-
|
|
77
|
+
# A turn's rows (TurnNotice::FIELDS, the fields a join replays them
|
|
78
|
+
# with) other than questions and ✂ rows, plus the load warnings.
|
|
79
|
+
NOTICE_TYPES = (TurnNotice::FIELDS.keys - QUESTION_EVENTS - LLM_CONTEXT_TYPES + %i[guardrail_warning]).freeze
|
|
75
80
|
FILE = "cards.json"
|
|
76
81
|
# The events after which the file is written again: the ones that
|
|
77
82
|
# change an entry or the turn log.
|
|
78
|
-
SAVED_ON = (%i[turn_started card
|
|
79
|
-
question_cancelled question_relay] + Events::TURN_END).freeze
|
|
83
|
+
SAVED_ON = (%i[turn_started card question_relay] + TurnNotice::FIELDS.keys + Events::TURN_END).uniq.freeze
|
|
80
84
|
# What only the store reads: never listed.
|
|
81
85
|
INTERNAL_FIELDS = %i[turn_id continued base_since past_idless after_opening during after_failed command].freeze
|
|
82
86
|
|
|
@@ -320,11 +324,8 @@ module Samagotchi
|
|
|
320
324
|
# that turn: it anchors before the turn.
|
|
321
325
|
when :guardrail_warning then push({ type: :guardrail_warning, message: event[:message], label: event[:label] }
|
|
322
326
|
.compact.merge(in_turn: false, turn_id: @running_turn ? @turn_log[-2] : @turn_log.last))
|
|
323
|
-
when :empty_answer_retry
|
|
324
|
-
when :
|
|
325
|
-
when :llm_context_edited then add_turn_row(Marshal.load(Marshal.dump(event.slice(*LLM_CONTEXT_FIELDS)))) if @running_turn
|
|
326
|
-
when :question_requested
|
|
327
|
-
add_turn_row({ type: :question, pending_question: Marshal.load(Marshal.dump(event[:pending_question])) }) if @running_turn
|
|
327
|
+
when :empty_answer_retry, :steer_cut, :llm_context_edited then add_turn_row(notice_row(event)) if @running_turn
|
|
328
|
+
when :question_requested then add_turn_row(notice_row(event).merge(type: :question)) if @running_turn
|
|
328
329
|
when :question_answered then resolve_question(event[:id], answer: event[:answer])
|
|
329
330
|
when :question_cancelled then resolve_question(event[:id], cancelled: true, reason: event[:reason])
|
|
330
331
|
when :question_relay then mark_relay(event[:id], event[:relayed_to])
|
|
@@ -366,18 +367,27 @@ module Samagotchi
|
|
|
366
367
|
# (a command's answer from another thread; a turn's proposal its own
|
|
367
368
|
# button's command replaced, which nobody typed).
|
|
368
369
|
old = @entries[index]
|
|
369
|
-
|
|
370
|
-
|
|
370
|
+
# Its step too (iteration, calls): the first one's place, as live.
|
|
371
|
+
@entries[index] = card.except(:command).merge(updated: true, **old.slice(:in_turn, :turn_id, :iteration, :calls, :during, :continued,
|
|
372
|
+
:base_since, :past_idless, :after_opening, :after_failed,
|
|
373
|
+
:command))
|
|
371
374
|
else
|
|
372
375
|
entry = card.merge(in_turn: event[:in_turn] ? true : false, turn_id: anchor)
|
|
376
|
+
# The step it came in (a turn's row's place): where a drawing made
|
|
377
|
+
# from the turn's messages draws it (TurnDrawings::Synth).
|
|
378
|
+
entry.merge!({ iteration: @iteration, calls: @calls }.compact) if @running_turn && event[:in_turn]
|
|
373
379
|
entry[:during] = true if @running_turn && !event[:in_turn]
|
|
374
380
|
entry[:continued] = true if @running_turn && event[:in_turn] && @continuing
|
|
375
381
|
push(entry)
|
|
376
382
|
end
|
|
377
383
|
end
|
|
378
384
|
|
|
385
|
+
# A TurnNotice event as the store keeps it: its FIELDS, deep-copied,
|
|
386
|
+
# and its type as a Symbol.
|
|
387
|
+
def notice_row(event) = TurnNotice.slice(event).merge(type: event[:type])
|
|
388
|
+
|
|
379
389
|
def add_notice(event)
|
|
380
|
-
notice = event
|
|
390
|
+
notice = notice_row(event)
|
|
381
391
|
if event[:between_turns] || !@running_turn
|
|
382
392
|
push(notice.merge(in_turn: false, turn_id: anchor))
|
|
383
393
|
else
|
|
@@ -387,7 +397,7 @@ module Samagotchi
|
|
|
387
397
|
|
|
388
398
|
# A row of the running turn's current step.
|
|
389
399
|
def add_turn_row(row)
|
|
390
|
-
entry = row.merge(in_turn: true, turn_id: @running_turn, iteration: @iteration, calls: @calls).compact
|
|
400
|
+
entry = row.merge(in_turn: true, turn_id: @running_turn, iteration: @iteration || row[:iteration], calls: @calls).compact
|
|
391
401
|
entry[:continued] = true if @continuing
|
|
392
402
|
push(entry)
|
|
393
403
|
end
|
|
@@ -30,8 +30,12 @@ module Samagotchi
|
|
|
30
30
|
# TurnDrawings#append). It runs under this accumulator's mutex and the
|
|
31
31
|
# SessionObserver's lock: it must never call back in here. An error is
|
|
32
32
|
# logged and the fold goes on.
|
|
33
|
+
# @param raise_errors [Boolean] a fold that raises raises out of #call
|
|
34
|
+
# (a drawing made from messages: TurnDrawings::Synth), never for a
|
|
35
|
+
# live turn's observer
|
|
33
36
|
def initialize(max_output_chars: ToolOutputCut::WEB_PREVIEW_CHARS,
|
|
34
|
-
clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }, on_turn_end: nil)
|
|
37
|
+
clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }, on_turn_end: nil, raise_errors: false)
|
|
38
|
+
@raise_errors = raise_errors
|
|
35
39
|
@max_output_chars = max_output_chars
|
|
36
40
|
@clock = clock
|
|
37
41
|
@on_turn_end = on_turn_end
|
|
@@ -50,6 +54,8 @@ module Samagotchi
|
|
|
50
54
|
def call(event)
|
|
51
55
|
@mutex.synchronize { fold(event) }
|
|
52
56
|
rescue StandardError
|
|
57
|
+
raise if @raise_errors
|
|
58
|
+
|
|
53
59
|
nil # never break the running turn
|
|
54
60
|
end
|
|
55
61
|
|