samagotchi 0.169.0 → 0.170.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 329ec9300af5c8d50782f89e0b422192dde8893d14c1cebe1a096e5512095e4c
4
- data.tar.gz: 138fde389b9f7776b24db545b27c5550cc47a0565cf93141320fc7ba13ddb997
3
+ metadata.gz: a13b61890c6a215efb8f13715a30637a12324d560eec91f1f827a849156453c9
4
+ data.tar.gz: d839197f63a218e01cd48ee326f17f25c7b9027c906ccdf5cd78b855e31b05f8
5
5
  SHA512:
6
- metadata.gz: 743ca2eb1a501a506de420953b0d955ad9894b2fedc89880c767f53881afd8feae04468e44309b7883c2623354de87716d3d133602ff90a574da5d0cb3a3b0c7
7
- data.tar.gz: becf43bf35201c4c78e946fec1356153a43199c863a99ab341f2406541d02e20e18236f8475ea3e30db5f13bc47342c6b30e6187e413d6fec7c6add57a48a073
6
+ metadata.gz: fcef2226618d6d543b180c536a24cb8b2e669a1c5a309a424b7c64acede977ade18593a36af9da5cf0e15a1e5781502f8dae3b2f7c78d61b7193905dc4538c86
7
+ data.tar.gz: f66ae46d4079588380f56a7fe6ffd7f222fc7eea442545f1200ce5598a8897681a9e3924ad3933189320870f6cf0e9ad18e389b763cf5f55db863c625a7433ab
data/CHANGELOG.md CHANGED
@@ -8,6 +8,20 @@ and commands may change between minor versions. How releases are made:
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.170.0] - 2026-11-13
12
+
13
+ ### Fixed
14
+
15
+ - chi web: the working set between turns now matches the running session's next-turn view, including pending adds.
16
+ - chi web: when two cards wait, answering the front card fits the box to the card left (no gap under check-in).
17
+ - chi web: the session cards' "question" / "approval" / "out of steps" badge goes as soon as it is answered.
18
+ - chi web: a question replaced before it was answered no longer leaves its old message saying "asking you".
19
+
20
+ ### Changed
21
+
22
+ - chi web: an answered approval shows chi's line first, then the command and the answer.
23
+ - chi web: while check-in waits during a tool call, the box's top row shows that call's time.
24
+
11
25
  ## [0.169.0] - 2026-11-12
12
26
 
13
27
  ### Changed
@@ -6275,7 +6289,8 @@ and long-lived sessions.
6275
6289
  - A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
6276
6290
  hotkey panel that send selected text or the clipboard to your sessions.
6277
6291
 
6278
- [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.169.0...HEAD
6292
+ [Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.170.0...HEAD
6293
+ [0.170.0]: https://github.com/dm1try/samagotchi/compare/v0.169.0...v0.170.0
6279
6294
  [0.169.0]: https://github.com/dm1try/samagotchi/compare/v0.168.0...v0.169.0
6280
6295
  [0.168.0]: https://github.com/dm1try/samagotchi/compare/v0.167.0...v0.168.0
6281
6296
  [0.167.0]: https://github.com/dm1try/samagotchi/compare/v0.166.0...v0.167.0
@@ -48,6 +48,8 @@ The turn is cleared on its terminal event (`Events::TURN_END`), the same event t
48
48
  session, so a snapshot shows a turn in exactly one of the two places. Beside the turn it keeps what a snapshot also
49
49
  needs and the messages lag: `queued` turns (`:turn_enqueued` until started, merged or dequeued), `queued_commands`,
50
50
  the idle `recap` (until a turn starts), a pending `continue_offer`, and the running turn's `working_set`.
51
+ Between turns it also carries `idle_working_set`, built as the worker's next-turn announcement would be (including
52
+ pending `adds`); it is absent while a turn runs or if the build fails.
51
53
 
52
54
  Three other users: `replay_events(turn)` turns a `current_turn` back into the live events that would have drawn it
53
55
  (the attached TUI's join); `join_events` is the page's unfold of the same turn plus the queue behind it (its
@@ -466,7 +468,8 @@ The Bridge exposes:
466
468
  (`GET /api/sessions/:id`) and `ctx.sessions.read` (`Plugin::Sessions#read`), which unwraps
467
469
  `snapshot`; the Bridge reply is `{snapshot:, session_state_snapshot:}`. `snapshot.objectives` is the worker's
468
470
  objectives view, including the running conversation; it is present as `nil` when the worker has no list and omitted
469
- if reading the view fails so chi web can use its file view.
471
+ if reading the view fails so chi web can use its file view. `snapshot.idle_working_set` is the worker's next-turn
472
+ working set between turns (including pending adds), omitted while a turn runs or if building it fails.
470
473
  - `GET /session/:id/tail` — the page's light re-read (`Bridge#tail_frame`): `session_state_snapshot`,
471
474
  `working_directory` (the session's folder, which the web checks the answer's file refs against),
472
475
  `answer` (the last message a UI shows as an answer, `AnswerTail`: the one message, copied alone),
@@ -281,15 +281,18 @@ In a session, the dock (composer card) shares the history's centered column, at
281
281
  `stage_frame.js` is the one writer. The cap is a ceiling: 60% of the page, 80% with the cloud open, 85% with a raised
282
282
  cap, and never above the session panel (less the card, its offset from the panel's bottom as computed: index.html
283
283
  `--dock-bottom`, and 16px). The frame is grow-only while a turn runs, so a change inside the stage never moves its top
284
- edge, with **two allowed shrinks, once per question and once per answer** (`forgetContent`):
284
+ edge, with **a shrink for each asking form and after an answer** (`forgetContent`):
285
285
  - **the asking form**: each card that docks (it opens, or finds opened, the turn in the history, below): the stage shows
286
286
  that card alone (`stage_view.js place`, in the card's task);
287
- - **the next step after a blocking card's answer** (`stage_view.js releaseHeldWait`, from `generationStarted`). The
287
+ - **an answer that leaves another docked card**: it fits the card now in front once the answered card leaves the
288
+ stage. Paging between cards does not change the height. When no card remains, the shrink is at **the next step after
289
+ a blocking card's answer** (`stage_view.js releaseHeldWait`, from `generationStarted`). The
288
290
  `held-wait` class says it is due: set with `waiting`, cleared there, so a later step, which calls it again, does
289
- nothing. What goes together: the live slots' waiting height, a raised cap, the tallest content seen. At the tap nothing
290
- moves: the card collapses to its line inside the held frame and the stage's scroll stays, unless the line would be above
291
- the view (a reader who scrolled down a card taller than the stage), when it comes back to the view's top
292
- (`settleAnsweredCard`).
291
+ nothing. What goes together: the live slots' waiting height, a raised cap, the tallest content seen. With one card,
292
+ at the tap nothing moves: it collapses to its line inside the held frame and the stage's scroll stays, unless the line
293
+ would be above the view (a reader who scrolled down a card taller than the stage), when it comes back to the view's
294
+ top (`settleAnsweredCard`). With two cards, answering the one in front fits the frame to the one left; paging alone
295
+ never changes it.
293
296
 
294
297
  **The stage's fold** (`stage_model.js stageCollapsed`, `stage_asking.js`): collapsed to its status row the stage holds no
295
298
  frame (`frameTarget` returns null) and an unfold refits to what shows. Three things decide it, kept apart: the user's
@@ -126,7 +126,8 @@ the Bridge (`ClientEvent.project`) passes it on unchanged, and the attached TUI
126
126
  and `running`. With a live worker it builds from the worker's snapshot messages (as `handle_show` (`Web::SessionShow`) reads them, keys
127
127
  symbolized) and the worker's `llm_context` summary. Without one it builds from the session file and its saved chip
128
128
  (`SessionSetting::LLM_CONTEXT`). The folder is the session's `working_directory`. `running` is true when the
129
- snapshot has a turn in progress (`current_turn`).
129
+ snapshot has a turn in progress (`current_turn`). Between turns, a newer worker's `idle_working_set` is used directly;
130
+ an older worker without that key still gets the file-build fallback.
130
131
 
131
132
  **The GET while a turn runs.** A worker's snapshot messages are the session's, not the running turn's, so they lag
132
133
  its events. The snapshot also carries `working_set`: the running turn's last `:working_set_updated` (`{items, at}`),
data/docs/releasing.md CHANGED
@@ -76,7 +76,7 @@ as the GitHub release body.
76
76
  | `rake lint` / `rake lint:fix` | RuboCop over the repo (must report no offenses; CI runs it) / its safe autocorrect (`rubocop -a`). |
77
77
  | `rake gem:validate`, `gem:build`, `gem:install`, `gem:clean` | Check the gemspec; build the gem into `pkg/`; build and install it locally; remove the built gems. |
78
78
  | `rake release:draft_changelog` | A draft Unreleased section from the commit subjects since the last tag, grouped. Stdout only. |
79
- | `rake release:bump[X.Y.Z]` | VERSION, the system manifest, Gemfile.lock, CHANGELOG, a compatibility corpus at `spec/compat/X.Y.Z/` written through the current state writers (with `wire/`: a real Engine and Bridge's replies, recorded twice and refused if the two differ), and `requires_chi: ">= X.Y.Z"` for each bundle marked `requires_chi_next` (the marker dropped), then a profile left below a member's `requires_chi` raised to it, with a patch bump of its version (none when it moved since the last tag) and named in the CHANGELOG's "Update with `chi update`" line, and each entry an `# Unreleased` comment in `Plugin::Api::SINCE` or `Manifest::SINCE` names moved into the table at X.Y.Z (the comment dropped). No commit; commit the corpus with the release. |
79
+ | `rake release:bump[X.Y.Z]` | VERSION, the system manifest, Gemfile.lock, CHANGELOG, a compatibility corpus at `spec/compat/X.Y.Z/` written through the current state writers (with `wire/`: a real Engine and Bridge's replies, recorded twice and refused if the two differ), refreshed `spec/shared/compat_wire/*.json` fixtures, and `requires_chi: ">= X.Y.Z"` for each bundle marked `requires_chi_next` (the marker dropped), then a profile left below a member's `requires_chi` raised to it, with a patch bump of its version (none when it moved since the last tag) and named in the CHANGELOG's "Update with `chi update`" line, and each entry an `# Unreleased` comment in `Plugin::Api::SINCE` or `Manifest::SINCE` names moved into the table at X.Y.Z (the comment dropped). No commit; commit the corpus and fixtures with the release. |
80
80
  | `rake release:check` | Clean tracked tree, VERSION == system bundle, a CHANGELOG section, no `requires_chi_next` left, no `# Unreleased` comment left in `Plugin::Api::SINCE` or `Manifest::SINCE`, `bundles:check`, `rake lint` (RuboCop) + `npm run lint` (the web frontend's ESLint), rspec (both roots: `spec` and the bundles' own `spec/`) + `rake bundles:specs` + 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). |
81
81
  | `rake release:notes[X.Y.Z]` | Prints the CHANGELOG section (default: the current VERSION). |
82
82
 
@@ -117,7 +117,9 @@ The agent does each step and stops where the user has to say yes.
117
117
  VERSION may pass a compat shim's `remove_after` (`Compat::SHIMS`): once the
118
118
  shim is also at least 14 days old (`added_on`, `Compat::MIN_AGE_DAYS`),
119
119
  `spec/compat_spec.rb` names it, and the shim goes (or its date moves)
120
- before the release.
120
+ before the release. The bump also refreshes `spec/shared/compat_wire/*.json`
121
+ by running `UPDATE_COMPAT_WIRE=1 bundle exec rspec spec/compat/wire_readers_spec.rb`;
122
+ commit those fixtures with the release corpus.
121
123
  5. **Check.** Add all release files, including the new compatibility corpus, then run it:
122
124
  `git add -A && git commit -m "Release X.Y.Z"` and `bundle exec rake release:check`.
123
125
  Fix anything it finds in new commits and run it again.
data/docs/testing.md CHANGED
@@ -166,14 +166,19 @@ pending cards, reminders and parent overrides. The starting marker is the
166
166
  documented stale-file exception.
167
167
  A corpus recorded after 0.165.0 also holds `wire/`: a worker's replies to `GET state`, `snapshot` (after a turn, and
168
168
  mid-turn with a prompt queued behind it) and `tail`, each `{route, status, body}`, and the session file it saved,
169
- recorded from a real Engine and Bridge (`script/release/compat_wire.rb`, `CompatWire`: a scripted kernel, read over the
170
- Bridge's HTTP with its secret). `spec/compat/wire_readers_spec.rb` serves them as recorded through a `BridgeClient`
169
+ plus `events.json`, the page's parsed `{type, data}` SSE replay from sequence 0, recorded from a real Engine and Bridge
170
+ (`script/release/compat_wire.rb`, `CompatWire`: a scripted kernel, read over the Bridge's HTTP with its secret).
171
+ `spec/compat/wire_readers_spec.rb` serves the replies as recorded through a `BridgeClient`
171
172
  (an unrecorded route is an older worker's 404) to today's clients: chi web's show and its `?tail=1`, `?cards=1`,
172
173
  `?timing=1` reads, the working set read, `BridgeClient#event_seq`, the attached terminal's `/stats` fallback and
173
174
  `ctx.sessions.read`; like `readers_spec`, one example reads the newest previous release's (skipped while that has no
174
- `wire/`), one a recording made now. SSE frames aren't recorded (the stream's own specs pin them); the JS page's reads of
175
- these replies are a follow-up. `spec/release/compat_wire_spec.rb` checks the recorder (what `normalise` pins, and the
176
- two-recordings guard).
175
+ `wire/`), one a recording made now. `spec/web/public/compat_wire_parity.test.js` runs the recorded SSE events through
176
+ today's page handlers and compares the resulting history with the `messages` and `turn_drawings` from chi web's actual
177
+ show. `spec/compat/wire_readers_spec.rb` serves the recorded replies to today's `Web::SessionShow` and writes/checks
178
+ `spec/shared/compat_wire/recording.json` (current) and, when available, `previous.json` (the newest previous release
179
+ with events); `UPDATE_COMPAT_WIRE=1` rewrites them. `release:bump` runs that spec to refresh the fixtures; commit
180
+ `spec/shared/compat_wire/*.json` with the release. `spec/release/compat_wire_spec.rb` checks the recorder (what
181
+ `normalise` pins, and the two-recordings guard).
177
182
  A second example reads a corpus the writer records now, so a writer change that
178
183
  today's readers can't read goes red before the release. `rake
179
184
  release:bump[X.Y.Z]` writes `spec/compat/X.Y.Z/` using the current writers
@@ -90,6 +90,7 @@ module Samagotchi
90
90
  relay_desk: "relay-store reference; status is monitor-protected",
91
91
  request_recap: "idle-recap monitor",
92
92
  reserve_enqueued_id: "turn-state monitor",
93
+ working_set_snapshot: "idle working-set snapshot under event lock",
93
94
  "running_turn_messages=": "callback writer; Bridge lifecycle",
94
95
  saved_recap: "recap mutex; replace-only session messages",
95
96
  session: "session reference; messages are replace-only",
@@ -367,6 +368,9 @@ module Samagotchi
367
368
  # working_set: the running turn's last :working_set_updated ({items:,
368
369
  # at:}, TurnAccumulator#working_set), which the messages lag; nil
369
370
  # between turns and before the turn emitted one.
371
+ # idle_working_set: what the worker would announce between turns
372
+ # ({items:, at:}, with adds: when present), built under the next turn's
373
+ # strategy; absent while a turn runs or if the build fails.
370
374
  # last_turn_drawing: the last prompt's turn as live drew it ({drawing:,
371
375
  # end:}, the file's line for that turn id, not unfolded: an attaching
372
376
  # TUI unfolds it, TurnAccumulator.replay_events), only while it holds
@@ -377,12 +381,20 @@ module Samagotchi
377
381
  # conversation too; nil when there is no list, absent if reading it fails.
378
382
  # @return [Hash] {messages:, current_turn:, working_set:, queued:, queued_commands:, recap:, saved_recap:, continue_offer:, pending_question:,
379
383
  # guardrail_warning:, plugin_warning:, init_tasks:, cards:, commands:, chi_version:, event_seq:, event_id:, last_turn_drawing:,
380
- # objectives:}
384
+ # objectives:, idle_working_set:}
381
385
  def snapshot
382
386
  @engine.synchronize_events do
383
387
  seq = @engine.event_count
384
388
  messages = @engine.messages_checkpoint
385
389
  drawing = last_turn_drawing(messages)
390
+ idle_working_set_unavailable = Object.new
391
+ idle_working_set = if @engine.turn_running?
392
+ idle_working_set_unavailable
393
+ else
394
+ Degrade.call(:bridge, "working_set_snapshot_failed", fallback: idle_working_set_unavailable) do
395
+ @engine.working_set_snapshot&.to_h || idle_working_set_unavailable
396
+ end
397
+ end
386
398
  objectives_unavailable = Object.new
387
399
  objectives = Degrade.call(:bridge, "objectives_snapshot_failed", fallback: objectives_unavailable) do
388
400
  @engine.objectives_view(@session_id, messages, state_dir: @state_dir)
@@ -407,6 +419,7 @@ module Samagotchi
407
419
  event_id: event_id(seq)
408
420
  }.merge(drawing ? { last_turn_drawing: drawing } : {})
409
421
  snapshot[:objectives] = objectives unless objectives.equal?(objectives_unavailable)
422
+ snapshot[:idle_working_set] = idle_working_set unless idle_working_set.equal?(idle_working_set_unavailable)
410
423
  snapshot
411
424
  end
412
425
  end
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: samagotchi-system
3
- version: 0.169.0
3
+ version: 0.170.0
4
4
  scope: system
5
5
  description: Default system memories — identity, self map, config modification protocol, memory guide and the delegated-session rules
6
6
  files:
@@ -73,6 +73,15 @@ module Samagotchi
73
73
  synchronize_events { emit_working_set(nil, session, session.messages) }
74
74
  end
75
75
 
76
+ # The working set the session would announce for +conversation+ under
77
+ # the next turn's strategy.
78
+ def working_set_snapshot(session = @session, conversation = session&.messages)
79
+ return unless session && conversation
80
+
81
+ WorkingSet.build(conversation, cwd: session.working_directory, strategy: working_set_strategy,
82
+ pins: session.working_set_pins)
83
+ end
84
+
76
85
  # ── Load events ───────────────────────────────────────────────────────
77
86
 
78
87
  # Announce what failed to load and what plugins showed while loading,
@@ -526,7 +526,7 @@ module Samagotchi
526
526
  live_conversation: -> { live_conversation },
527
527
  used_memory_names: -> { used_memory_names },
528
528
  served_expected_by: ->(served) { served_expected_by(served) },
529
- working_set_strategy: -> { working_set_strategy },
529
+ working_set_snapshot: ->(session, conversation) { working_set_snapshot(session, conversation) },
530
530
  turn_running: -> { turn_running? },
531
531
  announce_or_hold: ->(event) { announce_or_hold(event) }
532
532
  )
@@ -3,7 +3,6 @@
3
3
  require_relative "hooks"
4
4
  require_relative "log"
5
5
  require_relative "steer_cut"
6
- require_relative "working_set"
7
6
 
8
7
  module Samagotchi
9
8
  # How one of an Engine's events reaches the turn's sink and the persistent
@@ -33,12 +32,12 @@ module Samagotchi
33
32
  # @param live_conversation [#call] → Array<Hash>, the running turn's conversation
34
33
  # @param used_memory_names [#call] → Array<String>
35
34
  # @param served_expected_by [#call] (served) → the host expecting the served model
36
- # @param working_set_strategy [#call] → the strategy the working set is built under
35
+ # @param working_set_snapshot [#call] (session, conversation) → WorkingSet::Snapshot
37
36
  # @param turn_running [#call] → Boolean
38
37
  # @param announce_or_hold [#call] (event) → announces the event, or holds it
39
38
  def initialize(observer:, used_memories:, muted:, steer_cut:, thinking_notices:, metrics:, hooks:, turn_context:,
40
39
  last_turn_context:, model_settings:, session:, live_conversation:, used_memory_names:, served_expected_by:,
41
- working_set_strategy:, turn_running:, announce_or_hold:)
40
+ working_set_snapshot:, turn_running:, announce_or_hold:)
42
41
  @observer = observer
43
42
  @used_memories = used_memories
44
43
  @muted = muted
@@ -53,7 +52,7 @@ module Samagotchi
53
52
  @live_conversation = live_conversation
54
53
  @used_memory_names = used_memory_names
55
54
  @served_expected_by = served_expected_by
56
- @working_set_strategy = working_set_strategy
55
+ @working_set_snapshot = working_set_snapshot
57
56
  @turn_running = turn_running
58
57
  @announce_or_hold = announce_or_hold
59
58
  @working_set_emitted = nil
@@ -132,8 +131,7 @@ module Samagotchi
132
131
  def emit_working_set(on_event, session, conversation)
133
132
  return unless session && conversation
134
133
 
135
- snapshot = WorkingSet.build(conversation, cwd: session.working_directory, strategy: working_set_strategy,
136
- pins: session.working_set_pins)
134
+ snapshot = @working_set_snapshot.call(session, conversation)
137
135
 
138
136
  shown = snapshot.to_h.except(:at)
139
137
  last = @working_set_emitted
@@ -234,7 +232,6 @@ module Samagotchi
234
232
  def live_conversation = @live_conversation.call
235
233
  def used_memory_names = @used_memory_names.call
236
234
  def served_expected_by(served) = @served_expected_by.call(served)
237
- def working_set_strategy = @working_set_strategy.call
238
235
  def turn_running? = @turn_running.call
239
236
  def announce_or_hold(event) = @announce_or_hold.call(event)
240
237
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Samagotchi
4
- VERSION = "0.169.0"
4
+ VERSION = "0.170.0"
5
5
  # Sent as the User-Agent of every HTTP request chi makes.
6
6
  USER_AGENT = "chi/#{VERSION}"
7
7
  end
@@ -1404,11 +1404,15 @@ module Samagotchi
1404
1404
  def handle_working_set(_req, id)
1405
1405
  session = @session_class.load(id, state_dir: default_state_dir)
1406
1406
  live = bridge_get_json(id, "snapshot")
1407
- running = !live&.dig("snapshot", "current_turn").nil?
1407
+ worker_snapshot = live && live["snapshot"]
1408
+ running = !worker_snapshot&.dig("current_turn").nil?
1408
1409
  turn_set = running && running_working_set(live["snapshot"]["working_set"])
1409
1410
  return json_response(200, turn_set.merge(running: true)) if turn_set
1410
1411
 
1411
- messages = live_or_saved(live && live["snapshot"], "messages") { session.messages }
1412
+ idle_set = idle_working_set(worker_snapshot && worker_snapshot["idle_working_set"]) unless running
1413
+ return json_response(200, idle_set.merge(running: false)) if idle_set
1414
+
1415
+ messages = live_or_saved(worker_snapshot, "messages") { session.messages }
1412
1416
  # A snapshot's entries have string keys (paired_runs reads symbols).
1413
1417
  messages = Array(messages).map { |message| message.is_a?(Hash) ? message.transform_keys(&:to_sym) : message }
1414
1418
  llm_context = SessionSetting::LLM_CONTEXT.snapshot_value(live && live["session_state_snapshot"]) do
@@ -1427,6 +1431,17 @@ module Samagotchi
1427
1431
  { items: set["items"], at: set["at"] }
1428
1432
  end
1429
1433
 
1434
+ # The worker's between-turns working set ({"items", "at", optional
1435
+ # "adds"}); nil for an older or malformed snapshot.
1436
+ def idle_working_set(set)
1437
+ return nil unless set.is_a?(Hash) && set["items"].is_a?(Array) && set["at"].is_a?(Integer)
1438
+ return nil if set.key?("adds") && !set["adds"].is_a?(Array)
1439
+
1440
+ { items: set["items"], at: set["at"] }.tap do |snapshot|
1441
+ snapshot[:adds] = set["adds"] if set.key?("adds")
1442
+ end
1443
+ end
1444
+
1430
1445
  # The strategy an llm_context summary names ("none", "stale,forget"), as
1431
1446
  # LLMContextView takes it; none when there is no chip.
1432
1447
  def working_set_strategy(llm_context)
@@ -404,6 +404,7 @@ const liveTurn = createLiveTurn({
404
404
  (stageHost || historyEl).appendChild(el);
405
405
  return !!stageHost;
406
406
  },
407
+ stageToolRunning: () => turnDom.callClockActive?.() ?? false,
407
408
  // The stage's quiet signal and tool clock tick with it (?.: a stage_view.js an open tab loaded before).
408
409
  onTick: () => { store.touch("infoBar"); turnDom.tick?.(); },
409
410
  });
@@ -452,6 +452,9 @@ button.system-one-wrong,.system-one-wrong.marked{flex:none;padding:1px 6px;borde
452
452
  selectable. */
453
453
  .bubble.question>summary .question-said{max-width:72ch;margin:2px 0 1px 1.05em;font-size:12.5px;font-weight:400;line-height:1.5;color:var(--text-muted);white-space:normal;overflow-wrap:anywhere;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;overflow:hidden}
454
454
  .bubble.question[open]>summary .question-said{display:none}
455
+ .bubble.question.approval>summary.approval-said{display:grid;grid-template-columns:1.05em minmax(0,1fr)}
456
+ .bubble.question.approval>summary.approval-said .question-said{grid-column:2;grid-row:1;max-width:none;margin:0}
457
+ .bubble.question.approval>summary.approval-said .question-summary-text{grid-column:2;grid-row:2}
455
458
  /* A turn opened in the history (stage_opened.js): while the turn runs, a card answered under its reason doesn't repeat it;
456
459
  the reason goes at the hand-off and the card's clamp says it then. The card's way back to its reason sits at the right of its
457
460
  title line while it waits. */
@@ -867,6 +870,9 @@ body.stage-view .turn-stage{position:absolute;left:0;right:0;bottom:100%;margin-
867
870
  .ts-timing{min-width:0;overflow:hidden;text-overflow:ellipsis}
868
871
  .ts-timing .turn-timing{margin:0;font-size:12px;color:var(--text-muted);display:inline}
869
872
  .ts-mini{min-width:0;overflow:hidden;text-overflow:ellipsis;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--text-2)}
873
+ .ts-mini.ts-mini-timed{display:flex}
874
+ .ts-mini-label{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis}
875
+ .ts-mini-clock{flex:none}
870
876
  .ts-defer{color:var(--text-faint);font-style:italic;opacity:0;transition:opacity .2s}
871
877
  .turn-stage.ended.in-use .ts-defer{opacity:1}
872
878
  /* Stop turn (stage_view.js): a ghost in the danger colour at the row's right edge, beside the fold; the fold keeps the edge when it is hidden. */
@@ -1214,6 +1220,9 @@ button.ws-row:hover:not(:disabled){filter:none}@media(hover:hover){button.ws-row
1214
1220
  .turn-stage.asking-form.collapsed .ts-status{flex-wrap:wrap;row-gap:4px}
1215
1221
  .turn-stage.asking-form.collapsed :is(.ts-step,.ts-timing){display:none}
1216
1222
  .ts-mini.ts-mini-question{order:3;flex-basis:100%}
1223
+ .turn-stage.asks-live .ts-status{flex-wrap:wrap;row-gap:4px}
1224
+ .turn-stage.asks-live .ts-timing{display:none}
1225
+ .turn-stage.asks-live .ts-mini.ts-mini-timed{flex-basis:100%}
1217
1226
  /* An approval's Submit in sight on a phone: its folder, reason and rows a little tighter. */
1218
1227
  .approval-where,.approval-why{line-height:1.35}
1219
1228
  .bubble.question.approval .question-option{padding:5px 8px}
@@ -10,11 +10,12 @@ import { elapsedSince, liveDurationText, turnTimingText } from "./timing.js";
10
10
  // the stage's status row already says the turn runs, so the line drops its
11
11
  // own "running" there. The duration is the live one (never "0ms": under a
12
12
  // second it shows tenths).
13
- export function liveLineText({ number, startedAt, note = "", inStage = false }, now = Date.now()) {
13
+ export function liveLineText({ number, startedAt, note = "", inStage = false, toolRunning = false }, now = Date.now()) {
14
14
  const duration = elapsedSince(startedAt, now);
15
15
  if (duration === null) return null;
16
16
  const turn = Number.isInteger(number) && number > 0 ? `turn ${number}` : "turn";
17
- return `${turn}${!inStage ? " running" : ""} · ${liveDurationText(duration)}${note ? ` · ${note}` : ""}`;
17
+ const elapsed = inStage && toolRunning ? "" : ` · ${liveDurationText(duration)}`;
18
+ return `${turn}${!inStage ? " running" : ""}${elapsed}${note ? ` · ${note}` : ""}`;
18
19
  }
19
20
 
20
21
  // The live ticker's interval at +elapsedMs+ into the turn: 200 ms during the
@@ -39,6 +40,7 @@ export function lineRecord(records, turnId) {
39
40
  export function createLiveTiming({
40
41
  timing,
41
42
  place,
43
+ stageToolRunning = () => false,
42
44
  makeLine = () => document.createElement("div"),
43
45
  onTick = () => {},
44
46
  now = () => Date.now(),
@@ -81,7 +83,7 @@ export function createLiveTiming({
81
83
 
82
84
  function tick() {
83
85
  const startedAt = timing().activeTurn?.started_at;
84
- const text = liveLineText({ number, startedAt, note, inStage }, now());
86
+ const text = liveLineText({ number, startedAt, note, inStage, toolRunning: stageToolRunning() }, now());
85
87
  if (el && text !== null) el.textContent = text;
86
88
  onTick();
87
89
  // The interval follows the elapsed time: 200 ms while the line counts
@@ -490,11 +490,20 @@ export function createQuestionCards({
490
490
  const refs = questionRefsOf(pending);
491
491
  let full = null;
492
492
  if (summary && asked) {
493
+ if (allowed !== null) {
494
+ const answerLine = doc.createElement("span");
495
+ answerLine.className = "question-summary-text";
496
+ answerLine.textContent = summary.textContent;
497
+ summary.textContent = "";
498
+ summary.appendChild(answerLine);
499
+ summary.classList.add("approval-said");
500
+ }
493
501
  const line = doc.createElement("div");
494
502
  line.className = "question-said";
495
503
  line.setAttribute("aria-hidden", "true");
496
504
  line.textContent = plainText(asked);
497
- summary.appendChild(line);
505
+ if (allowed !== null) summary.insertBefore(line, summary.children[0] || null);
506
+ else summary.appendChild(line);
498
507
  full = doc.createElement("div");
499
508
  full.className = "question-said-full";
500
509
  full.textContent = asked;
@@ -3,9 +3,9 @@
3
3
  // ~60% of the page (~80% with the cloud open, 85% from a tall approval
4
4
  // until the next step), and never above the session panel. The frame: held
5
5
  // and grow-only while the stage holds a turn (stage_model.js frameTarget),
6
- // its growth eased; it lets go in two places only (forgetContent): the
7
- // asking form (a card docked, its turn opened in the history: the card
8
- // alone, stage_view.js place) and the next step after an answered card (releaseHeldWait). The stage's state comes
6
+ // its growth eased; it lets go when a card docks (stage_view.js place), or
7
+ // after an answer leaves a card in front or at the next step
8
+ // (stage_view.js releaseHeldWait). The stage's state comes
9
9
  // in as getters (+isHolding+, +isCollapsed+, +isCloudOpen+, +isRoomCap+);
10
10
  // what the stage changes of the frame's goes through resetHeld and
11
11
  // forgetContent. +waitingCard+: the card blocking the turn, or null.
@@ -9,6 +9,7 @@ import { hookNoticeLabel } from "./turn_events.js";
9
9
  import { plainLine } from "./plain_line.js";
10
10
  import { turnPieces } from "./turn_pieces.js";
11
11
  import { waitsInStage } from "./stage_cards.js";
12
+ import { clockText } from "./delivery_line.js";
12
13
 
13
14
  const READ_LIKE = new Set(["read", "memory_read", "web_fetch", "task_get", "task_list", "list_sessions"]);
14
15
  const EDITS = new Set(["edit", "write", "memory_write"]);
@@ -146,10 +147,12 @@ export function miniToolText({ collapsed, tool }) {
146
147
  // the hover, in the UI font: +question+ true), else miniToolText's running
147
148
  // call: folded, or with +running+ (check-in docked while nothing blocks:
148
149
  // the row says what chi runs now).
149
- export function foldedRowText({ collapsed, question = "", tool = null, running = false }) {
150
+ export function foldedRowText({ collapsed, question = "", tool = null, running = false, now = Date.now() }) {
150
151
  const whole = String(question || "").trim();
151
152
  if (collapsed && whole) return { text: whole.split("\n")[0].trim(), title: whole, question: true };
152
- return { ...miniToolText({ collapsed: collapsed || running, tool }), question: false };
153
+ const row = miniToolText({ collapsed: collapsed || running, tool });
154
+ const clock = running && tool?.startedAt != null ? clockText((now - tool.startedAt) / 1000) : "";
155
+ return { ...row, ...(clock ? { clock } : {}), question: false };
153
156
  }
154
157
 
155
158
  // The status row's word while check-in's card is docked and nothing blocks
@@ -218,7 +221,10 @@ export function liveSlots(turn, { narration = "", thinking = "", pending = false
218
221
  step: ended ? gens.filter((g) => !g.answer || g.thinking || g.tools.length).length : gens.length,
219
222
  headline,
220
223
  quiet: ended ? "" : current?.text && !current.textDone ? "writing…" : "thinking…",
221
- tool: running ? withTask(withCommand({ name: toolName(running), title: rowTitle(running), kind: toolKind(running.tool) }, running), running) : null,
224
+ tool: running ? withTask(withCommand({
225
+ name: toolName(running), title: rowTitle(running), kind: toolKind(running.tool),
226
+ ...(running.startedAt != null ? { startedAt: running.startedAt } : {}),
227
+ }, running), running) : null,
222
228
  trail,
223
229
  ticks: rows.map(({ row, step }) => ({ kind: toolKind(row.tool), status: row.status, step })),
224
230
  };
@@ -226,8 +232,9 @@ export function liveSlots(turn, { narration = "", thinking = "", pending = false
226
232
 
227
233
  // The stage's frame height (px) while it holds a turn: grow-only, so a
228
234
  // content change inside it (the plain flip, an answered card, a short
229
- // answer) never moves its top edge. (Its one shrink forgets +held+: the next
230
- // step after an answered card, stage_view.js releaseHeldWait.) +natural+: its content's own height;
235
+ // answer) never moves its top edge. The answer shrink forgets +held+ when
236
+ // another docked card remains, or at the next step after an answered card
237
+ // (stage_view.js releaseHeldWait). +natural+: its content's own height;
231
238
  // +held+: the height it holds (null: none yet); +cap+: --stage-max. A lower
232
239
  // cap (a phone's keyboard) clamps it at once and the clamp is the new held
233
240
  // height: a cap that rises again doesn't bring the old one back, only new
@@ -186,14 +186,17 @@ export function createOpenedTurn({
186
186
  if (bubble && !card.querySelector(":scope > summary > .question-reason-link")) reasonLink(card, bubble);
187
187
  },
188
188
  // +card+ (its +key+) no longer waits (answered, cancelled): it goes right
189
- // under its reason, which stops saying "asking you"; another card of the
190
- // turn to the history's end. A reader at the end follows.
191
- settle(key, card) {
189
+ // under its reason, which stops saying "asking you"; if it was replaced
190
+ // and removed, only the reason is settled. A reader at the end follows.
191
+ settle(key, card = null) {
192
192
  const bubble = reasons.get(key);
193
- if (!bubble?.isConnected) return add([card]);
193
+ if (!bubble?.isConnected) {
194
+ if (card) add([card]);
195
+ return;
196
+ }
194
197
  const follow = atHistoryEnd();
195
198
  bubble.classList.remove("pending");
196
- bubble.after(card);
199
+ if (card?.isConnected) bubble.after(card);
197
200
  if (follow) scrollTo();
198
201
  },
199
202
  // The turn's steps block (or one of its steps, +el+) in the history:
@@ -37,7 +37,7 @@ import { createOpenedTurn } from "./stage_opened.js";
37
37
  import { askingRefs } from "./turn_model.js";
38
38
  import { ASKS, PENDING } from "./stage_cards.js";
39
39
  import { createStageAsking } from "./stage_asking.js";
40
- import { createStageWaiting, isApprovalCard, isBlocking, waitingKey, waitingKind } from "./stage_waiting.js";
40
+ import { cardIn, createStageWaiting, isApprovalCard, isBlocking, waitingKey, waitingKind } from "./stage_waiting.js";
41
41
  import { stampRows } from "./working_set_view.js";
42
42
 
43
43
  // The turn-end read (markdown, answer_display) settles within this, or the
@@ -261,6 +261,7 @@ export function createStageView({
261
261
  // The cards that wait in the stage, as data (stage_waiting.js): the
262
262
  // docked card, its fold, what blocks, the approval's cap read them.
263
263
  const waiting = createStageWaiting();
264
+ let dockedAtLastRefresh = [];
264
265
  // The asking form and the stage's fold (stage_asking.js).
265
266
  const ask = createStageAsking({
266
267
  stage, extras, tail, scroller, fold, view, opener, frame: () => frame, isOpened: () => opened, setOpened,
@@ -402,9 +403,12 @@ export function createStageView({
402
403
  const slots = liveSlots(turn, { narration, thinking, pending: blocked || asksCard(), ended: endKind, emptyAnswer });
403
404
 
404
405
  // The live slots keep their height while the turn waits and until its
405
- // next step (held-wait, set with waiting): the card under them never
406
- // moves at the answer. The waiting height is measured before the swap.
406
+ // next step, unless answering leaves another docked card to fit. The
407
+ // waiting height is measured before the swap.
407
408
  const wasWaiting = stage.classList.contains("waiting");
409
+ const docked = waiting.docked();
410
+ const answeredWithCardLeft = dockedAtLastRefresh.some((key) => !docked.includes(key)) && docked.length > 0;
411
+ dockedAtLastRefresh = docked;
408
412
  if (blocked && !wasWaiting) {
409
413
  stage.classList.add("held-wait");
410
414
  }
@@ -414,6 +418,7 @@ export function createStageView({
414
418
  cancel.hidden = !onCancel || !!endKind;
415
419
  stage.classList.toggle("waiting", blocked);
416
420
  if (!blocked && wasWaiting) settleAnsweredCard();
421
+ if (answeredWithCardLeft && !blocked) releaseHeldWait();
417
422
  stage.dataset.phase = slots.phase;
418
423
  mark.textContent = MARKS[slots.phase] || "";
419
424
  // check-in docked, nothing blocking: the row says what chi does now (the
@@ -445,8 +450,16 @@ export function createStageView({
445
450
  chipLabel.textContent = chipLabelText({ steps: slots.step, calls, elapsed });
446
451
  // Folded, the row says what the docked card asks (live and after a
447
452
  // reload alike: from the card), else the running call.
448
- const mini = foldedRowText({ collapsed, question: foldedText(asking), tool: slots.tool, running: asksFront });
449
- miniTool.textContent = mini.text;
453
+ const mini = foldedRowText({ collapsed, question: foldedText(asking), tool: slots.tool, running: asksFront, now: clock() });
454
+ if (mini.clock) {
455
+ miniTool.replaceChildren();
456
+ node("span", "ts-mini-label", miniTool).textContent = mini.text;
457
+ node("span", "ts-mini-clock", miniTool).textContent = ` · ${mini.clock}`;
458
+ miniTool.classList.add("ts-mini-timed");
459
+ } else {
460
+ miniTool.classList.remove("ts-mini-timed");
461
+ miniTool.textContent = mini.text;
462
+ }
450
463
  miniTool.title = mini.title;
451
464
  miniTool.classList.toggle("ts-mini-question", mini.question);
452
465
 
@@ -488,11 +501,11 @@ export function createStageView({
488
501
  return text.length > 60 ? `${text.slice(0, 59)}\u2026` : text;
489
502
  }
490
503
 
491
- // The next step after a blocking card's answer: the one time a turn's
492
- // frame shrinks (stage_frame.js forgetContent; grow-only otherwise). What
493
- // the wait held goes together: the live slots' waiting height, a raised
494
- // cap, the tallest content seen. +held-wait+ says it is due, so a later
495
- // step, or a generation with the card still waiting, changes nothing.
504
+ // The next step after a blocking card's answer, or an answer that leaves
505
+ // another docked card in front: the frame shrinks (stage_frame.js
506
+ // forgetContent; grow-only otherwise). What the wait held goes together:
507
+ // the live slots' waiting height, a raised cap, the tallest content seen.
508
+ // +held-wait+ says it is due, so later steps change nothing.
496
509
  // A card still pending is read from the slots, not the waiting class: a
497
510
  // replay (a reload, a resync) runs its answer and the next step in one
498
511
  // task, before the refresh that drops the class.
@@ -707,6 +720,7 @@ export function createStageView({
707
720
  markOwnToggles();
708
721
  opener.reset();
709
722
  waiting.reset();
723
+ dockedAtLastRefresh = [];
710
724
  miniTool.classList.remove("ts-mini-question");
711
725
  setCloud(false);
712
726
  stage.classList.remove("plain", "ended", "waiting", "held-wait", "in-use", "asking-form", "asks-live");
@@ -1052,8 +1066,8 @@ export function createStageView({
1052
1066
  // A waiting card and the asking form (refresh) land in one task.
1053
1067
  if (waits) refresh();
1054
1068
  else scheduleRefresh();
1055
- // The asking form: the stage shrinks to the card (one of its two
1056
- // allowed shrinks, stage_frame.js; the other is releaseHeldWait).
1069
+ // The asking form: the stage shrinks to the card; an answer can also
1070
+ // shrink it to a remaining card, or release it at the next step.
1057
1071
  if (docked) frame.forgetContent();
1058
1072
  if (waits && el.matches?.(".bubble.question")) askedFor(el);
1059
1073
  // A card that waits for the user is brought into the stage's view: in
@@ -1093,12 +1107,21 @@ export function createStageView({
1093
1107
  // quiet signal and the running call's clock.
1094
1108
  tick(nowMs = clock()) {
1095
1109
  drawStall(nowMs);
1110
+ if (holding && asksCard() && liveSlots(view.current().turn).tool?.startedAt != null) scheduleRefresh();
1096
1111
  },
1112
+ callClockActive: () => holding && asksCard() && !!liveSlots(view.current().turn).tool,
1097
1113
  handOff,
1098
1114
  // A card stopped waiting (stage_waiting.js keys; +only+: when it is that
1099
1115
  // kind): question_cards.js's resolve path, cards_place.js upsertCard.
1100
1116
  // The stage's redraw comes from the card's own change.
1101
- settleWaiting: (key, opts) => waiting.settle(key, opts),
1117
+ settleWaiting: (key, opts) => {
1118
+ const settled = waiting.settle(key, opts);
1119
+ if (!settled || !opener.has(key)) return settled;
1120
+ const card = cardIn(extras, key) || cardIn(tail, key);
1121
+ card?.classList.remove("ts-behind");
1122
+ opener.settle(key, card);
1123
+ return true;
1124
+ },
1102
1125
  // The waiting cards as data (the tests' and the harness's read).
1103
1126
  waiting: { list: () => waiting.list(), front: () => waiting.front(), docked: () => waiting.docked(), folded: () => waiting.folded(), count: (o) => waiting.count(o) },
1104
1127
  root: stage,
@@ -65,7 +65,9 @@ module Samagotchi
65
65
  end
66
66
  relay(id, bridge_client(id), request, what: "the answer was not sent", cant: "answer questions") do |reply|
67
67
  case reply.status
68
- when 200 then json_response(200, { status: "answered", session_id: id, id: qid })
68
+ when 200
69
+ @hub&.resolve_question(id, question_id: qid)
70
+ json_response(200, { status: "answered", session_id: id, id: qid })
69
71
  # Another client answered first (or the question was cancelled).
70
72
  when 409 then error_response(409, "question_not_pending", reply_detail(reply, "question not pending"))
71
73
  when 400 then error_response(400, "invalid_answer", reply_detail(reply, "answer rejected"))
@@ -177,6 +177,22 @@ module Samagotchi
177
177
  end
178
178
  end
179
179
 
180
+ # An accepted answer ends the wait before the worker has saved its
181
+ # resumed session. Clear that question from the projection now.
182
+ def resolve_question(id, question_id:)
183
+ return nil unless Session.valid_id?(id)
184
+
185
+ @monitor.synchronize do
186
+ entry = @sessions[id]
187
+ pending = entry&.summary&.dig(:pending_question)
188
+ next unless pending && pending[:id].to_s == question_id.to_s
189
+
190
+ entry.summary = entry.summary.merge(pending_question: nil)
191
+ emit("session", session: entry.summary)
192
+ end
193
+ nil
194
+ end
195
+
180
196
  # The complete chi version state used by event snapshots and info routes.
181
197
  def chi_state
182
198
  @monitor.synchronize do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samagotchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.169.0
4
+ version: 0.170.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Dedov