samagotchi 0.172.0 → 0.172.1
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 +14 -1
- data/docs/internals/background-tasks.md +1 -1
- data/docs/internals/web-frontend.md +38 -14
- data/docs/testing.md +25 -1
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/tools/leftovers.rb +8 -4
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/public/app.js +2 -1
- data/lib/samagotchi/web/public/card_kinds.js +51 -0
- data/lib/samagotchi/web/public/cards_place.js +13 -2
- data/lib/samagotchi/web/public/question_cards.js +29 -14
- data/lib/samagotchi/web/public/session_sync.js +4 -2
- data/lib/samagotchi/web/public/stage_asking.js +29 -10
- data/lib/samagotchi/web/public/stage_place.js +144 -0
- data/lib/samagotchi/web/public/stage_probe.js +64 -0
- data/lib/samagotchi/web/public/stage_view.js +52 -104
- data/lib/samagotchi/web/public/stage_waiting.js +30 -13
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 373feecab32762e6d14c5740f3989bc31d93722133f1f956783e4203a977a44b
|
|
4
|
+
data.tar.gz: b7bb34bbfa66dcb9ea47f464856d4eb7cbf9ed696bf3ab59f72cc34bee69bcc9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20c1e7acc7574a0cd8c216a76faacc12de4466ce8728900374b459bc99ea7875093c51a8f56cf2ca685d7463937cc378a7f868e0502f80025fd0ec98d39d0e91
|
|
7
|
+
data.tar.gz: b63932bda384afa0d83f966e988f18945728b62a1af362452c3fcb4d2f5d6d89cda359ec1c74624b5b3119242de3a62f99100bd7d4a0f7c654d9d2f56d4d5374
|
data/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,18 @@ and commands may change between minor versions. How releases are made:
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [0.172.1] - 2026-11-14
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- `execute`: the hint for a background process that left the command's process group and is still running now says chi
|
|
16
|
+
can't stop it and to kill it if it shouldn't run, instead of advising how to keep it running.
|
|
17
|
+
- Web: a card you folded while the turn waits stays folded after a reload or a reconnect when the session has an answered
|
|
18
|
+
question (in its history, or earlier in the same turn); it used to come back unfolded. Answering one card no longer
|
|
19
|
+
unfolds another you folded.
|
|
20
|
+
|
|
21
|
+
Update with `chi update`.
|
|
22
|
+
|
|
11
23
|
## [0.172.0] - 2026-11-14
|
|
12
24
|
|
|
13
25
|
### Changed
|
|
@@ -6347,7 +6359,8 @@ and long-lived sessions.
|
|
|
6347
6359
|
- A macOS desktop helper (`chi desktop install`): a "Send to chi" Service and a
|
|
6348
6360
|
hotkey panel that send selected text or the clipboard to your sessions.
|
|
6349
6361
|
|
|
6350
|
-
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.172.
|
|
6362
|
+
[Unreleased]: https://github.com/dm1try/samagotchi/compare/v0.172.1...HEAD
|
|
6363
|
+
[0.172.1]: https://github.com/dm1try/samagotchi/compare/v0.172.0...v0.172.1
|
|
6351
6364
|
[0.172.0]: https://github.com/dm1try/samagotchi/compare/v0.171.0...v0.172.0
|
|
6352
6365
|
[0.171.0]: https://github.com/dm1try/samagotchi/compare/v0.170.0...v0.171.0
|
|
6353
6366
|
[0.170.0]: https://github.com/dm1try/samagotchi/compare/v0.169.0...v0.170.0
|
|
@@ -22,7 +22,7 @@ Behavior:
|
|
|
22
22
|
- A task record keeps its process's pid and start time (`pid_started`). Before `task_stop` signals, the pid must still lead its own process group and must not have started at another time; otherwise the pid was reused by another process, nothing is signalled and the task ends as failed. A start time that can't be read at that moment (a failed `ps`) falls back to the group check, as does a record without `pid_started` (from an older chi). `task_get`, `task_list`, `task_wait`'s polls and the running-task lists (a cancelled turn's note, a worker's restart hold, the finish wake's watch) make the same check, so a task whose pid was reused reads as exited (failed) at once, not as running until a `task_stop`; on macOS that is one `ps` per running task per check (~5 ms).
|
|
23
23
|
- A stop (`task_stop`, the user's Stop of an `execute`, the execute limit in kill mode) TERMs the task's process group, then KILLs it after a grace. The groups its processes started are stopped too: a GNU `timeout N cmd` (without `--foreground`) moves itself and its command to a group of its own. `ProcessGroup.stop` finds them with one `ps -A -o pid=,ppid=,pgid=` (~40 ms on macOS) before the TERM and again before the KILL, walking down from the group's members. A process whose parent already exited (reparented to init, e.g. a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` after its shell exited) is not found by that walk; one still in the task's group is stopped by the leftover rule below, so only one outside the group runs on: a setsid'd `cmd &`, or a backgrounded `timeout N cmd &` (GNU `timeout` moves to a group of its own). Holding the task's log, it is reported detached.
|
|
24
24
|
- Task listing is workspace-scoped (current project only).
|
|
25
|
-
- `execute` runs its command with stdout and stderr in two logs under `$XDG_STATE_HOME/samagotchi/execute/<id>/` (always an absolute path: a relative `XDG_STATE_HOME` is taken from the directory chi started in; outside the workspace: `git status` and `rm -rf tmp` never see them), stdin `/dev/null` and the same `exit_code` wrapper as a task. Its own copies of the logs hold a shared `flock` across the spawn: while a fresh exclusive `flock` fails, some process the command started still has them open. When the shell exits, a background child still holding them (`server &`) gets 1.5 s, then its group is stopped (the result's hint says to start a long job with `task_create` in the foreground, no `&`: a `cmd &` left behind there is stopped too); one holding none (`nohup server >log 2>&1 &`) is left alone. A holder that left the group (setsid) is out of the stop's reach: it runs on, the result ends with the "left running" hint, and its dir stays for it to write to (the sweep removes it once no one holds the logs). Otherwise a finished command's dir is removed. Known gap on Linux: a command that writes through `/dev/stdout` or `/dev/stderr` (`echo b >/dev/stdout`) reopens the log file itself with `O_TRUNC`, so the output before it is lost (macOS dups the descriptor; the fix would be a relay pipe). The check needs the state dir on a local file system: over NFS, `flock` is emulated with `fcntl` locks, which children don't inherit.
|
|
25
|
+
- `execute` runs its command with stdout and stderr in two logs under `$XDG_STATE_HOME/samagotchi/execute/<id>/` (always an absolute path: a relative `XDG_STATE_HOME` is taken from the directory chi started in; outside the workspace: `git status` and `rm -rf tmp` never see them), stdin `/dev/null` and the same `exit_code` wrapper as a task. Its own copies of the logs hold a shared `flock` across the spawn: while a fresh exclusive `flock` fails, some process the command started still has them open. When the shell exits, a background child still holding them (`server &`) gets 1.5 s, then its group is stopped (the result's hint says to start a long job with `task_create` in the foreground, no `&`: a `cmd &` left behind there is stopped too); one holding none (`nohup server >log 2>&1 &`) is left alone. A holder that left the group (setsid) is out of the stop's reach: it runs on, the result ends with the "left running" hint, which says chi can't stop it and to kill it if it shouldn't run, and its dir stays for it to write to (the sweep removes it once no one holds the logs). Otherwise a finished command's dir is removed. Known gap on Linux: a command that writes through `/dev/stdout` or `/dev/stderr` (`echo b >/dev/stdout`) reopens the log file itself with `O_TRUNC`, so the output before it is lost (macOS dups the descriptor; the fix would be a relay pipe). The check needs the state dir on a local file system: over NFS, `flock` is emulated with `fcntl` locks, which children don't inherit.
|
|
26
26
|
- The exit code: the command runs after an EXIT trap that writes the shell's status to the `exit_code` file (`TaskRuntime.wrapped_shell_command`, shared with `task_create`), so `exit N`, a `set -e` failure and a trailing `\` or `|` in the command all record what the shell exited with. The trap runs wherever the shell is when it exits (a `task_create` `cwd`, or a `cd` in the command), so `task_create`'s `exit_code_path` is absolute; its `output_path` stays relative (`tmp/tasks/<id>/output.log`, opened by chi in the worker's cwd before the spawn). A command that sets its own EXIT trap replaces it, and a shell killed by a signal skips it (zsh's sh mode, on TERM, INT and KILL): `execute` still reports the shell's status, and a `task_create` task or a handed-over execute gets its code from chi's waiter while the chi that started it runs (`TaskRuntime.record_exit_status`): the exit status, or `128 + the signal` (TERM → 143), with no new `stop_reason`. A record a refresh already finished without a code in between (`failed`, `process_ended_without_exit_code` or the not-chi's-process reason) is corrected, its `finished_at` kept; a stopped task (its stop flag on disk) is never touched. `process_ended_without_exit_code` is left only when the shell wrote nothing and the chi that started it was gone too.
|
|
27
27
|
- `task_create` applies `execute`'s leftover rule (`Tools::Leftovers`, one implementation: `held?`, the grace, the group stop, the hint wording): `create_task` holds `output.log` with a shared `flock` across the spawn, and a handed-over execute's two logs are already held. When the task's shell exits and a process it started still holds the log (`yes >/dev/null &` with no `wait`), the task stays `running` (so the finish wake's watch and `task_wait` keep waiting) while the waiter of the chi that started it (`TaskRuntime.record_exit_status`) gives it 1.5 s (`LEFTOVER_GRACE_SEC`), then stops the group (TERM, 1 s, KILL; `Leftovers.stop_group`, only while the group still has members: a pgid isn't reused while it has any) and finishes the record in one write: the shell's status and exit code (the leftovers don't make it a failure) and `leftovers: "stopped"`. A holder outside the group with the group empty (a setsid'd `cmd &`, or a backgrounded `timeout N cmd &`: GNU `timeout` without `--foreground` moves itself and its command to a group of its own) is signalled nothing: `leftovers: "detached"`, left running, and the hint says so (`task_stop` can't reach it: kill it if it shouldn't run). A process holding no log (`nohup cmd >f 2>&1 &`) is left alone. `task_get`, `task_wait` (so the finish note too) and `task_list` add the hint line (`Leftovers.task_hint`), ``(a background process kept the task's log open and was stopped; to keep one running, run it in the foreground or end the command with `wait`)`` (or `was left running`), built from the same `Leftovers.hint` as execute's. One settler per task: while that waiter thread lives (`TaskRuntime.waiter_for`, in memory, this process only), a refresh here only reads a held record. With no waiter here (the chi that started it is gone, a worker that exited mid-grace, or another process reading), the next refresh that finds the shell dead and the log held settles it itself: a second look after 0.05 s (two `held?` probes at once read each other as holders), then the stop with a 0.5 s TERM grace and 0.5 s KILL wait (only of a group that still had members at the first look; one gone by the stop with nothing holding the log records no `leftovers`), so that read blocks up to ~1 s plus a `ps`. With no later reader of that cwd's tasks the leftovers run on; records already finished (an older chi's) are never revisited, and an older chi's record (its log never `flock`'d) reads as not held and settles as before. A `task_stop` during the grace stops the group (`Leftovers.stop_group`) and the record ends `stopped` (its stop flag wins over the waiter's write; in one process the two writes share a lock). Cost: one non-blocking `flock` try per log at shell exit (~0.2 ms), the grace only when something holds the log; a refresh of a running record whose shell is dead adds one `flock` try, and one `ps` only when the log is held.
|
|
28
28
|
- A stop of an `execute` (the user's Stop, the limit in kill mode) is done once the shell is reaped and nothing holds the logs: a child that ignores TERM after its shell died gets the KILL.
|
|
@@ -29,7 +29,7 @@ page. A factory dep a new version stops passing is the same hazard the other way
|
|
|
29
29
|
out of `send_turn.js`, `session_actions.js` and `lists_view.js`); a page loaded before keeps all its old modules
|
|
30
30
|
until a reload, so the risk is a mixed cache, not an open tab. `answer_fold.js`, `details_motion.js`,
|
|
31
31
|
`turn_range.js`, `history_reveal.js`, `latest.js`, `session_payload.js`, `method_api.js`, `session_store.js`,
|
|
32
|
-
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; it compares the turn's own cards and questions, dropping every entry CardStore attributes to another turn), `cards_offscreen.js` (the reload check's placer: `createCardsPlace`, `createBubbles` and `createQuestionCards` over a detached holder, every page hook inert - no stage, no scroll, no session id, no api, no storage - so a snapshot's cards land where a reload would put them without touching the page), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js` (the stage's features: below, The stage's modules), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
|
|
32
|
+
`session_fields.js`, `feature_gates.js`, `revise_stack.js`, `revise_switch.js`, `shell_command.js`, `stale_params.js`, `popover_modal.js`, `more_sheet.js`, `hash_intent.js` (what the hash asks for: session, all, start or keep), `worker_features.js`, `version_notices.js`, `owner_claim.js`, `owner_verify.js`, `composer_mode.js`, `strip_hidden.js`, `block_open.js`, `text_roots.js`, `block_source.js`, `block_frame.js`, `block_host.js`, `block_watch.js`, `card_stamps.js`, `recap_stamp.js` (a saved recap's place by its `opening_id` stamp, else its count), `inline_widgets.js`, `widget_walk.js`, `widget_picks.js`, `history_shape.js` (the history's shape, live against a reload: the e2e reload checks and the opt-in reload check share its normalizer and its `ACCEPTED` allowlist), `turn_pieces.js` (a finished turn's one order and its answer rule: the live hand-off's `handOffOrder` and `turnEnded`, and a reload's `turnHistoryNodes`), `reload_check.js` (the opt-in `web.reload_check`: after the stage's hand-off, the turn against a reload of it, the counts posted; it compares the turn's own cards and questions, dropping every entry CardStore attributes to another turn), `cards_offscreen.js` (the reload check's placer: `createCardsPlace`, `createBubbles` and `createQuestionCards` over a detached holder, every page hook inert - no stage, no scroll, no session id, no api, no storage - so a snapshot's cards land where a reload would put them without touching the page), `turn_drawing.js` (a finished turn's drawing, `turn_drawings` in the show: its fold into steps and its end kind; `turn_block.js` draws it), `stage_stall.js` (the stage's quiet signal), `stage_quiet_clock.js`, `stage_dom.js`, `stage_answer.js`, `stage_pager.js`, `stage_cloud.js`, `stage_handoff.js`, `stage_place.js`, `stage_probe.js` (the stage's features: below, The stage's modules), `card_kinds.js` (what a card waits as, from its data: the kind, approval and folded-row text the stage's registry takes; the node's read is its cross-check), `history_end.js` (the stage's one move of pieces to the history's end), `stage_opened.js` (a running turn opened in the history while a card waits: the lead-in bubble, the moves, the end fold), `stage_asking.js` (the stage's docked card and its fold: the docking and lead-in rules, the opening, a waiting card's own toggle, the folded row's text per kind, the fold's choice, reveal and the docked card's fold; `stage_view.js` wires it), `stage_waiting.js` (the stage's waiting cards as data, keyed by `data-qid` / `data-card-id`: kind, docked, approval, the stage's order, the shown card and its pager, the docked card's fold, kept for this tab in `chi_asking_fold:<session>`; `front`, `count`, `shown`, `blocking`), `stage_cards.js` (the cards that wait in the stage: `PENDING`, `ASKS`, `waitsInStage`, read by `stage_model.js placeKind`), `resync_reach.js` (a re-read that can't reach chi web keeps the drawn history; the status chip says retrying / offline, outside a turn), `session_sync.js` (the open session's sync: `select`, `resync` and its retries, the stream's life; the stream handle and the re-read bookkeeping are its own), `session_view.js` (the open session's view: `renderSessionView` draws a read, `forgetSession` resets the page for another session, `readTurnEnd`, `endTurnView`; app.js makes both right after the cards, each reaching the other and the later views through getters), `participant_main.js`, `participant_bar.js`, `viewer_self.js`, `stage_owner_wait.js`, `participant_revise.js` (a participant's page: The participant's page, below), `ws_timeline.js`, `ws_cards.js`, `ws_peek.js`, `ws_reader.js`, `ws_way_in.js` (what chi has of a working-set item: below, The working set's reader), `no_contact_fill.js` (a text field that isn't a contact form: autocomplete off and a name with no contact word, against iOS Safari's AutoFill Contact bar; a template's fields carry the same attributes, and its spec checks the page's markup for them) and the `objectives_*.js` modules are new modules for that reason. The last four `block_*` draw fenced blocks (`block_watch.js` finds and watches them, `block_host.js` is its frame drawer for a bundle's renderers): [block-renderers.md](block-renderers.md). `inline_widgets.js` is its core drawer for `chi-ui` blocks, drawing `widget_walk.js`'s and `widget_picks.js`'s widgets in a shadow root styled by `widgets.css`: [inline-widgets.md](inline-widgets.md).
|
|
33
33
|
|
|
34
34
|
## One page, every viewer
|
|
35
35
|
|
|
@@ -398,6 +398,12 @@ from `emptySlots`.** `npm run lint` holds it (`samagotchi/stage-size`: every `st
|
|
|
398
398
|
`stage_view.js` re-exports for `dock_reserve.js`) and `OPENING`, what opens a turn in the history (`reload_check.js`
|
|
399
399
|
reads it). Its state, the turn sliding away, outlives `emptySlots` on purpose: the fold runs after the turn's release
|
|
400
400
|
and ends by clearing the stage; the view's `reset` drops it.
|
|
401
|
+
- `stage_place.js`: where a row or a card goes while the stage holds a turn (`place`: the hand-off settled first, the
|
|
402
|
+
late recap above an opened turn, the queued slot, an opened turn's row, the docking, the lead-in, the slot order, the
|
|
403
|
+
step limit's hand-off); `stage_view.js`'s event API delegates to it.
|
|
404
|
+
- `stage_probe.js`: the perf probe (`?stage_probe=1`, kept for the tab, or `<body data-stage-probe="1">`: `measured`,
|
|
405
|
+
`chiStageProbe.report()`), around
|
|
406
|
+
`refresh`; `script/stage-perf-probe` drives it ([testing.md](../testing.md)).
|
|
401
407
|
|
|
402
408
|
## The stage's height
|
|
403
409
|
|
|
@@ -423,15 +429,17 @@ frame (`frameTarget` returns null) and an unfold refits to what shows. Three thi
|
|
|
423
429
|
another tab's write doesn't apply live), **revealed** (a ref's "show in turn" opened it for this turn; the choice stays)
|
|
424
430
|
and **the docked card's fold** (the waiting card the user folded, by its key, held in `chi_asking_fold:<session>`
|
|
425
431
|
in sessionStorage: this tab's own, so a reload or a resync mid-turn draws it folded as it was — `stage_waiting.js`
|
|
426
|
-
writes it on the fold and reads it back in `trackFold` once the replay has drawn the card; it goes when
|
|
427
|
-
answered or
|
|
428
|
-
|
|
432
|
+
writes it on the fold and reads it back in `trackFold` once the replay has drawn the card; it goes when that card is
|
|
433
|
+
answered, cancelled or resolved (`stage_waiting.js settle` with `done`, from `question_cards.js onSettled`: only the
|
|
434
|
+
fold that names that card, so a replay or a history question answering another card leaves it), when the fold drops,
|
|
435
|
+
when the turn hands off (`clearFold`), and when the page opens another session (`session_sync.js select`, only when a
|
|
436
|
+
session was open); `reset` clears the memory only, so the replay can take the fold back). In the
|
|
429
437
|
asking form only that fold counts: the ▾ and a tap on the folded row set or clear it and write nothing to
|
|
430
438
|
`chi_stage_collapsed` (another blocking card that comes to wait meanwhile
|
|
431
439
|
drops it, so the stage opens on the front card), so a card always arrives open (in the card's task, before
|
|
432
440
|
`question_cards.js focusWhenIdle` focuses it) and a new one never matches an old fold; the same card drawn again with its
|
|
433
|
-
id keeps it. The fold reads the registry
|
|
434
|
-
|
|
441
|
+
id keeps it. The fold reads the registry, which every answer settles in its own task, so a card answered in the same
|
|
442
|
+
task no longer holds a click. When the form ends (an answer, a dismiss, a cancel; `emptySlots` for a reset, a
|
|
435
443
|
session switch, the next turn) the stage is as the choice and revealed say. `refresh` applies it (`drawCollapsed`: only
|
|
436
444
|
when it changed, no refresh of its own). Folded, the status row's `.ts-mini` says what the shown card asks
|
|
437
445
|
(`stage_asking.js foldedText`: a question's `.question-text`, an approval's summary and its command's first line, a
|
|
@@ -473,12 +481,25 @@ included (`wholeTurn`).
|
|
|
473
481
|
|
|
474
482
|
**Where the waiting-card state lives:** `stage_waiting.js`, one registry per stage keyed by a card's id (`q:<qid>`,
|
|
475
483
|
`c:<card id>`, `continue` for the old continue card), never by its node (`card.js drawCard` may swap a plugin card's
|
|
476
|
-
DIV for a DETAILS; a resync draws a question card anew). `place`
|
|
477
|
-
`
|
|
478
|
-
|
|
479
|
-
`
|
|
480
|
-
|
|
481
|
-
|
|
484
|
+
DIV for a DETAILS; a resync draws a question card anew). **Fed from data:** `place` (`stage_place.js`) adds
|
|
485
|
+
(`arrive`: the kind, docked, approval and the folded row's `summary`), taking them from what the card's maker said
|
|
486
|
+
right before placing it: `question_cards.js onArrive` (app.js passes it to `turnDom.expectWaiting`) and
|
|
487
|
+
`cards_place.js upsertCard`'s `expectWaiting`, both from `card_kinds.js` (`questionWait`, `continueWait`, `cardWait`:
|
|
488
|
+
the same rules and text functions the cards are drawn by). The card's node is read too (`waitingKind`,
|
|
489
|
+
`isApprovalCard`, `stage_asking.js foldedText`'s DOM read): a cross-check that warns once per key ("stage: waiting
|
|
490
|
+
kind differs", "… summary differs"), and the fallback for a card that came without data (an older `question_cards.js`
|
|
491
|
+
in a mixed cache, a test's bare card). **Settle is the one way out:** `question_cards.js` settles through its
|
|
492
|
+
`onSettled` hook (answered, cancelled, replaced, removed, the continue card resolved or dropped; `{done: true}` for an
|
|
493
|
+
answer, a cancel or a resolve, which also removes that card's kept fold), `cards_place.js upsertCard` settles a plugin
|
|
494
|
+
card redrawn without its actions (`only: "asks"`) or neither asking nor a warning (`only: "warn"`); one redrawn in
|
|
495
|
+
place that still waits (check-in's new title) patches its entry after those settles (`turnDom.updateWaiting`: kind
|
|
496
|
+
and summary, its order and docking kept; arrived again, not docked, as a warning or when its actions came back; with
|
|
497
|
+
an older `stage_waiting.js` that has no `update`, an arrive in place), `turnEnded` the warn cards
|
|
498
|
+
that leave, `session_view.js endTurnView`'s cancel of a question still pending goes through `onSettled`, and
|
|
499
|
+
`emptySlots` resets it (a resync's and `workerGone`'s reset too). `stage_asking.js reconcileWaiting` settles nothing:
|
|
500
|
+
a debug check at the end of `refresh`, on only with the perf probe or `<body data-stage-check="1">` (the e2e and the
|
|
501
|
+
node tests), that warns "stage: waiting drift" for an entry whose card is gone or waits no more, or a waiting card
|
|
502
|
+
with no entry.
|
|
482
503
|
The registry's order is the stage's: blocking cards before the asking ones, arrival order within each, and `place`
|
|
483
504
|
puts a blocking card before check-in's in the slot, so a live page and a reload agree whatever the replay's order. The
|
|
484
505
|
asking form's card is the shown docked entry, the fold is the folded key (`stageCollapsed` compares keys); `opener`'s
|
|
@@ -632,5 +653,8 @@ reach another device or the server.
|
|
|
632
653
|
sessionStorage (this tab only, `storage.js` `readSession`/`writeSession`/`removeSession`, guarded the same way):
|
|
633
654
|
`chi_client_id` (`turn_events.js`: this tab's client id, kept over a reload mid-turn),
|
|
634
655
|
`chi_asking_fold:<session>` (`stage_waiting.js`: the docked card the user folded and how many cards waited at the
|
|
635
|
-
fold, so a reload or a resync mid-turn draws the asking form as they left it
|
|
636
|
-
`
|
|
656
|
+
fold, so a reload or a resync mid-turn draws the asking form as they left it; removed by `stage_waiting.js` alone:
|
|
657
|
+
`settle` with `done` for that card, the fold dropping, the hand-off's `clearFold`, and `session_sync.js select` leaving
|
|
658
|
+
the session),
|
|
659
|
+
`chi.authReloadAt` (`auth_lost.js`: one automatic reload a minute), and `chi_stage_probe` (`stage_probe.js`: the
|
|
660
|
+
perf probe on for this tab, from `?stage_probe=1`).
|
data/docs/testing.md
CHANGED
|
@@ -235,7 +235,12 @@ Each level owns its own share; a detail is asserted once, at the lowest level th
|
|
|
235
235
|
its cards, the docked ones, the lead-in bubbles, the card in front, the one that shows and the pager, the fold) and
|
|
236
236
|
the history compared; a known difference is listed in its `EXPECTED`, by scenario, cut and field (one gone fails
|
|
237
237
|
too; none today), and on both pages `stage_waiting.js`'s cards agree with the slots, one docked card showing. `STAGE_CUTS_DEBUG=1` prints each cut's differences. Both
|
|
238
|
-
harnesses build their page with `spec/web/public/live_page.js`.
|
|
238
|
+
harnesses build their page with `spec/web/public/live_page.js`. The stage's drift check (`<body
|
|
239
|
+
data-stage-check="1">`, `stage_asking.js reconcileWaiting`) and the data-vs-node cross-check (`card_kinds.js
|
|
240
|
+
warnDiffers`) warn "stage: waiting …": `spec/web/public/waiting_warnings.js` (`failOnWaitingWarnings`, called by
|
|
241
|
+
`stage_view.test.js` and `stage_cuts_parity.test.js`; under `npm test`'s one process it covers the files loaded
|
|
242
|
+
after them too) turns the check on and fails a test that warned, and `stage.spec.js` does the same in the browser
|
|
243
|
+
(`test.use({ stageCheck: true })`, a fixture in `spec/e2e/support/fixtures.js`).
|
|
239
244
|
`spec/shared/turn_ranges.json` (`UPDATE_TURN_RANGES=1 bundle exec rspec spec/bridge/turn_ranges_spec.rb`) pins
|
|
240
245
|
`Bridge::TurnRanges`' turns, their record pairing, the items as the show stamps them and each turn's drawing end;
|
|
241
246
|
timing.test.js checks `turnGroups` (stamps only) against it. Each scenario's
|
|
@@ -545,6 +550,25 @@ runs its code only on small synthetic sessions, never on yours. See
|
|
|
545
550
|
[internals/llm-context-bench.md](internals/llm-context-bench.md). `script/llm_context_live.rb` runs chi itself on
|
|
546
551
|
real tasks under each strategy (needs a model; costs tokens): [internals/llm-context-live.md](internals/llm-context-live.md).
|
|
547
552
|
|
|
553
|
+
## The stage perf probe
|
|
554
|
+
|
|
555
|
+
`script/stage-perf-probe` (`PROBE_MACHINE=<label>` names the machine; `--keep` leaves its folder, `--headed` shows
|
|
556
|
+
the browser) times the web page's stage on a big session: `script/stage_perf_probe/session.rb` writes 300 finished
|
|
557
|
+
turns with 60 plugin cards and 40 answered questions through chi's own writers (TurnAccumulator's drawings, CardStore,
|
|
558
|
+
`Session#save`; CardStore keeps its cap of 20, the rest are in the drawings), then `probe.js` opens it in chi web
|
|
559
|
+
(the e2e fake model, isolated `HOME` and `XDG_*` under `tmp/stage-probe-*`) at `/?stage_probe=1` (`stage_probe.js`:
|
|
560
|
+
the flag is kept for the tab in sessionStorage, `chi_stage_probe`, so a reload or a hash jump keeps it;
|
|
561
|
+
`?stage_probe=0` drops it; `<body data-stage-probe="1">` works too, for that page only), runs one turn that asks a question and an approval, reloads while the question waits and answers
|
|
562
|
+
both. It prints JSON: `stage:refresh` n/p50/p95/max (ms), the session's open (the hash to the last answer drawn),
|
|
563
|
+
tap→settled per card, reload→card drawn and the JS heap after a GC before the open, after it and after the turn. Its
|
|
564
|
+
`session.drawn` counts what the open drew: all 300 answers and 60 cards, but only the answered questions CardStore
|
|
565
|
+
still lists (8: its cap keeps the newest 20 cards and questions together, and a finished turn's question is drawn from
|
|
566
|
+
that list alone). Bounded:
|
|
567
|
+
the session within 60 s, the browser run within 180 s, cut at 300 s; it stops only what it started (chi web and the
|
|
568
|
+
fake by their handles, the worker through chi web's stop route) and says when anything still names its folder. Not
|
|
569
|
+
part of any suite. On an iPhone: open the page once with `?stage_probe=1` (the Home Screen app: in Safari Web
|
|
570
|
+
Inspector's console, `location.search = "?stage_probe=1"`), run a turn, then `chiStageProbe.report()` there.
|
|
571
|
+
|
|
548
572
|
## The model notes report
|
|
549
573
|
|
|
550
574
|
`ruby script/model_notes_report.rb` reads a sessions folder (`--sessions DIR`, else chi's own) and groups the
|
|
@@ -28,9 +28,13 @@ module Samagotchi
|
|
|
28
28
|
WHAT = { stopped: "was stopped", detached: "was left running" }.freeze
|
|
29
29
|
# What each tool's hint tells the model to do instead. Never just
|
|
30
30
|
# "with task_create": a `server &` there is stopped too. The task
|
|
31
|
-
# side never says "use task_create" (that is how it got there)
|
|
32
|
-
# holder left running is told how to end it.
|
|
33
|
-
EXECUTE_ADVICE =
|
|
31
|
+
# side never says "use task_create" (that is how it got there); a
|
|
32
|
+
# holder left running on either side is told how to end it.
|
|
33
|
+
EXECUTE_ADVICE = {
|
|
34
|
+
stopped: "to keep a server or long job running, start it with task_create in the foreground (no `&`)",
|
|
35
|
+
detached: "it left the command's process group, so chi can't stop it: kill it if it shouldn't run; " \
|
|
36
|
+
"next time, start a long job with task_create in the foreground (no `&`)"
|
|
37
|
+
}.freeze
|
|
34
38
|
TASK_ADVICE = {
|
|
35
39
|
stopped: "to keep one running, run it in the foreground or end the command with `wait`",
|
|
36
40
|
detached: "it left the task's process group, so task_stop can't reach it: kill it if it shouldn't run; " \
|
|
@@ -45,7 +49,7 @@ module Samagotchi
|
|
|
45
49
|
def hint(kind, held:, advice:) = "(a background process kept #{held} open and #{WHAT.fetch(kind)}; #{advice})"
|
|
46
50
|
|
|
47
51
|
# execute's hint (Execute::BACKGROUND_HINT, BACKGROUND_DETACHED_HINT).
|
|
48
|
-
def execute_hint(kind) = hint(kind, held: "the output", advice: EXECUTE_ADVICE)
|
|
52
|
+
def execute_hint(kind) = hint(kind, held: "the output", advice: EXECUTE_ADVICE.fetch(kind))
|
|
49
53
|
|
|
50
54
|
# A task's hint (TaskRuntime.leftovers_note: task_get, task_wait, the
|
|
51
55
|
# finish note, task_list).
|
data/lib/samagotchi/version.rb
CHANGED
|
@@ -471,7 +471,8 @@ const questionCards = createQuestionCards({
|
|
|
471
471
|
// The bar's chip reads questionCards.pendingQuestion() (sessionWaits).
|
|
472
472
|
onPending: () => store.touch("infoBar"),
|
|
473
473
|
// The stage's waiting cards as data (stage_waiting.js).
|
|
474
|
-
|
|
474
|
+
onArrive: (key, info) => turnDom.expectWaiting?.(key, info),
|
|
475
|
+
onSettled: (key, opts) => turnDom.settleWaiting?.(key, opts),
|
|
475
476
|
});
|
|
476
477
|
// The history's bubbles (bubbles.js): output, end lines, every client's
|
|
477
478
|
// prompts, the recap, warnings and notices, command and note bubbles.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// What a card waits as, from its data (stage_waiting.js KINDS): the kind,
|
|
2
|
+
// whether it is an approval, and the folded row's text (stage_asking.js
|
|
3
|
+
// foldedText), read from the pending question, the continue offer or the
|
|
4
|
+
// plugin card before its node is drawn. question_cards.js and cards_place.js
|
|
5
|
+
// hand it to the stage (onArrive / expectWaiting) right before the card is
|
|
6
|
+
// placed; the stage still reads the node (waitingKind, foldedText) as a
|
|
7
|
+
// cross-check, and as the fallback for a card that came without it.
|
|
8
|
+
// Pure: no DOM. The same rules question_cards.js and card.js draw by:
|
|
9
|
+
// data-kind, data-relay and the step-limit class; the question text and the
|
|
10
|
+
// approval's summary line; a plugin card's actions and level.
|
|
11
|
+
import { approvalView, isContinue, relayView, summaryText } from "./question_card.js";
|
|
12
|
+
|
|
13
|
+
// The question a card shows (its .question-text): a delegate's relayed
|
|
14
|
+
// question's own words, else the question.
|
|
15
|
+
export function questionText(pq) {
|
|
16
|
+
return String((relayView(pq) && pq.relay.asked) || pq?.question || "");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// A pending question's wait: the step limit is "continue", a delegate's
|
|
20
|
+
// relayed card "relay", else its kind (approval, hook, question).
|
|
21
|
+
export function questionWait(pq) {
|
|
22
|
+
const approval = pq?.kind === "approval";
|
|
23
|
+
const kind = isContinue(pq) ? "continue" : relayView(pq) ? "relay" : ["approval", "hook"].includes(pq?.kind) ? pq.kind : "question";
|
|
24
|
+
if (!approval) return { kind, approval, summary: questionText(pq) };
|
|
25
|
+
// The summary's own words and the command's (or the tool's) first line.
|
|
26
|
+
const view = approvalView(pq);
|
|
27
|
+
const what = String(view.what || view.tool || "").trim().split("\n")[0].trim();
|
|
28
|
+
return { kind, approval, summary: [summaryText(pq).trim(), what].filter(Boolean).join(" ") };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// The old continue card: no question text.
|
|
32
|
+
export function continueWait() {
|
|
33
|
+
return { kind: "continue", approval: false, summary: "" };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// A plugin card's wait: a running turn's card with an action asks (as
|
|
37
|
+
// check-in's), a warning stays in sight; null: it doesn't wait.
|
|
38
|
+
export function cardWait(card) {
|
|
39
|
+
const asks = !!card?.in_turn && (card.actions || []).some((a) => a && a.command);
|
|
40
|
+
return { kind: asks ? "asks" : card?.level === "warn" ? "warn" : null, approval: false, summary: String(card?.title || "") };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The cross-check: the data and the node disagree about +key+'s +what+
|
|
44
|
+
// ("kind", "summary"). Said once per key and field.
|
|
45
|
+
const said = new Set();
|
|
46
|
+
export function warnDiffers(what, key, data, dom) {
|
|
47
|
+
const id = `${what}:${key}`;
|
|
48
|
+
if (said.has(id)) return;
|
|
49
|
+
said.add(id);
|
|
50
|
+
console.warn(`stage: waiting ${what} differs`, key, data, dom);
|
|
51
|
+
}
|
|
@@ -16,6 +16,7 @@ import { llmContextNotice, noticeLine } from "./turn_events.js";
|
|
|
16
16
|
import { hookNoticeTemplate, TURN_PROMPT, turnPromptBubbles } from "./bubbles.js";
|
|
17
17
|
import { stillOn } from "./latest.js";
|
|
18
18
|
import { pluginCardKey } from "./stage_waiting.js";
|
|
19
|
+
import { cardWait } from "./card_kinds.js";
|
|
19
20
|
|
|
20
21
|
// The elements of the reloaded turn that ends before +before+ (the next
|
|
21
22
|
// turn's prompt, or null for the last turn), its prompt first.
|
|
@@ -74,17 +75,27 @@ export function createCardsPlace({
|
|
|
74
75
|
const existing = cardElement(card.id);
|
|
75
76
|
const asks = (card.actions || []).some((a) => a && a.command);
|
|
76
77
|
if (existing) {
|
|
78
|
+
const wasWarn = existing.classList.contains("warn");
|
|
77
79
|
const drawn = drawCard(existing, card);
|
|
78
80
|
drawn.classList.add("card-updated");
|
|
79
81
|
setTimeout(() => drawn.classList.remove("card-updated"), 900);
|
|
80
82
|
// Redrawn without its actions (check-in's card turned into its notice
|
|
81
|
-
// row): it no longer asks
|
|
82
|
-
|
|
83
|
+
// row): it no longer asks; redrawn neither asking nor a warning: it no
|
|
84
|
+
// longer stays in sight. Then, still waiting (check-in's new title, an
|
|
85
|
+
// asking card now a warning: in sight, not docked), the stage's entry
|
|
86
|
+
// says what it waits as now (stage_waiting.js).
|
|
87
|
+
const key = pluginCardKey(card.id);
|
|
88
|
+
const wait = cardWait(card);
|
|
89
|
+
if (!asks) turnDom.settleWaiting?.(key, { only: "asks" });
|
|
90
|
+
if (wasWarn && !asks && card.level !== "warn") turnDom.settleWaiting?.(key, { only: "warn" });
|
|
91
|
+
if (wait.kind) turnDom.updateWaiting?.(key, wait);
|
|
83
92
|
return;
|
|
84
93
|
}
|
|
85
94
|
bubbles.removeHintIfEmpty();
|
|
86
95
|
const el = drawCard(document.createElement(isNoticeCard(card) ? "details" : "div"), card);
|
|
87
96
|
if (card.in_turn && !before && !asks && turnDom.card(el)) return;
|
|
97
|
+
// What it waits as, for the stage's place (stage_place.js).
|
|
98
|
+
if (!before) turnDom.expectWaiting?.(pluginCardKey(card.id), cardWait(card));
|
|
88
99
|
bubbles.placeFollowing(el, before);
|
|
89
100
|
}
|
|
90
101
|
|
|
@@ -24,8 +24,9 @@ import { clientLabel, isOwn } from "./turn_events.js";
|
|
|
24
24
|
import { continueLine } from "./commands.js";
|
|
25
25
|
import { plainText } from "./plain_line.js";
|
|
26
26
|
import { noContactFill } from "./no_contact_fill.js";
|
|
27
|
-
import { removeSession } from "./storage.js";
|
|
28
27
|
import { CONTINUE_KEY, foldKey, questionKey } from "./stage_waiting.js";
|
|
28
|
+
import { readSession, removeSession } from "./storage.js";
|
|
29
|
+
import { continueWait, questionText, questionWait } from "./card_kinds.js";
|
|
29
30
|
|
|
30
31
|
// A card's text fields' name: not a contact field (no_contact_fill.js).
|
|
31
32
|
const CARD_NOTE = "chi-card-note";
|
|
@@ -53,9 +54,12 @@ const CARD_NOTE = "chi-card-note";
|
|
|
53
54
|
// bar's waiting chip, docs/internals/web-frontend.md write -> redraw)
|
|
54
55
|
// @param answers false for a viewer who may not answer (viewer.js
|
|
55
56
|
// answer_cards): no question or continue card is drawn at all
|
|
56
|
-
// @param
|
|
57
|
+
// @param onArrive (key, info) a card that waits is about to be placed: its
|
|
58
|
+
// stage_waiting.js key and what it waits as (card_kinds.js)
|
|
59
|
+
// @param onSettled (key, opts) a card stopped waiting (answered, cancelled,
|
|
57
60
|
// replaced or removed; the continue card resolved or dropped), by its
|
|
58
|
-
// stage_waiting.js key: the stage's waiting cards as data
|
|
61
|
+
// stage_waiting.js key: the stage's waiting cards as data; {done: true}
|
|
62
|
+
// when answered, cancelled or resolved for good (its kept fold goes)
|
|
59
63
|
// @return {renderQuestion(pq, {said}), resolveQuestion(id, opts), removeQuestion(),
|
|
60
64
|
// questionCard() (the live card or null), pendingQuestion() (or null),
|
|
61
65
|
// isResolved(id) (this page already saw that question answered),
|
|
@@ -64,7 +68,7 @@ export function createQuestionCards({
|
|
|
64
68
|
sessionId, clientId, place, isNearBottom, scrollToEnd, removeHintIfEmpty, askingText = () => "",
|
|
65
69
|
renderMarkdown = () => Promise.resolve(null), linkRefs = () => {}, pairRefs = () => {},
|
|
66
70
|
api = { sendAnswer, dismissQuestion, sendCommand }, doc = globalThis.document,
|
|
67
|
-
onPending = () => {}, onSettled = () => {}, answers = true,
|
|
71
|
+
onPending = () => {}, onArrive = () => {}, onSettled = () => {}, answers = true,
|
|
68
72
|
}) {
|
|
69
73
|
// Live ask_user_question card, keyed by pending question id. Re-rendered from
|
|
70
74
|
// pending_question on session select so a reload mid-question restores it.
|
|
@@ -136,7 +140,7 @@ export function createQuestionCards({
|
|
|
136
140
|
if (relay) card.appendChild(renderDelegateLine(relay));
|
|
137
141
|
const q = doc.createElement("div");
|
|
138
142
|
q.className = "question-text";
|
|
139
|
-
q.textContent = (
|
|
143
|
+
q.textContent = questionText(pq);
|
|
140
144
|
// A plugin's refs on the question (its step's: one may name a ticket here too).
|
|
141
145
|
if (!relay) pairRefs(q, questionRefsOf(pq));
|
|
142
146
|
card.appendChild(q);
|
|
@@ -182,6 +186,7 @@ export function createQuestionCards({
|
|
|
182
186
|
|
|
183
187
|
if (stepLimit) {
|
|
184
188
|
const follow = isNearBottom();
|
|
189
|
+
onArrive(questionKey(pq.id), questionWait(pq));
|
|
185
190
|
place(card);
|
|
186
191
|
questionEl = card;
|
|
187
192
|
if (follow) scrollToEnd();
|
|
@@ -266,6 +271,7 @@ export function createQuestionCards({
|
|
|
266
271
|
|
|
267
272
|
// Read before the card makes the history taller.
|
|
268
273
|
const follow = isNearBottom();
|
|
274
|
+
onArrive(questionKey(pq.id), questionWait(pq));
|
|
269
275
|
const staged = place(card) === true;
|
|
270
276
|
questionEl = card;
|
|
271
277
|
if (follow) scrollToEnd();
|
|
@@ -524,12 +530,9 @@ export function createQuestionCards({
|
|
|
524
530
|
// After the collapse: a card left open by hand renders at once.
|
|
525
531
|
if (full) renderSaidOnOpen(questionEl, full, asked, refs);
|
|
526
532
|
resolvedId = pending.id;
|
|
527
|
-
// Answered or cancelled for good: the fold this tab kept
|
|
528
|
-
// (stage_waiting.js).
|
|
529
|
-
|
|
530
|
-
const fold = foldKey(sessionId());
|
|
531
|
-
if (fold) removeSession(fold);
|
|
532
|
-
onSettled(questionKey(questionEl.dataset.qid));
|
|
533
|
+
// Answered or cancelled for good: the stage drops the fold this tab kept
|
|
534
|
+
// for it (stage_waiting.js settle).
|
|
535
|
+
onSettled(questionKey(questionEl.dataset.qid), { done: true });
|
|
533
536
|
setPending(null);
|
|
534
537
|
}
|
|
535
538
|
|
|
@@ -622,6 +625,18 @@ export function createQuestionCards({
|
|
|
622
625
|
continueEl = null;
|
|
623
626
|
}
|
|
624
627
|
|
|
628
|
+
// Mixed cache, for one release (remove in A1 phase 5): the fold kept for the
|
|
629
|
+
// old continue card goes here too, so a stale app.js or stage_waiting.js
|
|
630
|
+
// (no done) can't leave it behind. Only that card's: a question's fold is
|
|
631
|
+
// the stage's (stage_waiting.js settle). No session, no key ("null").
|
|
632
|
+
function dropContinueFold() {
|
|
633
|
+
const fold = foldKey(sessionId());
|
|
634
|
+
if (!fold) return;
|
|
635
|
+
try {
|
|
636
|
+
if (JSON.parse(readSession(fold) || "null")?.key === CONTINUE_KEY) removeSession(fold);
|
|
637
|
+
} catch (_) { /* unreadable: left as it is */ }
|
|
638
|
+
}
|
|
639
|
+
|
|
625
640
|
function renderContinueCard(offer) {
|
|
626
641
|
if (!answers || continueEl?.isConnected) return;
|
|
627
642
|
// A step-limit question is up: it is the card (an older worker has none).
|
|
@@ -677,6 +692,7 @@ export function createQuestionCards({
|
|
|
677
692
|
card.appendChild(row);
|
|
678
693
|
card.appendChild(err);
|
|
679
694
|
const follow = isNearBottom();
|
|
695
|
+
onArrive(CONTINUE_KEY, continueWait(offer));
|
|
680
696
|
place(card);
|
|
681
697
|
continueEl = card;
|
|
682
698
|
if (follow) scrollToEnd();
|
|
@@ -687,9 +703,8 @@ export function createQuestionCards({
|
|
|
687
703
|
continueEl = null;
|
|
688
704
|
if (!card) return;
|
|
689
705
|
card.classList.add("resolved");
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
onSettled(CONTINUE_KEY);
|
|
706
|
+
dropContinueFold();
|
|
707
|
+
onSettled(CONTINUE_KEY, { done: true });
|
|
693
708
|
card.querySelectorAll("button, input").forEach((el) => { el.disabled = true; });
|
|
694
709
|
const note = doc.createElement("div");
|
|
695
710
|
note.className = "question-result";
|
|
@@ -88,8 +88,10 @@ export function createSessionSync(deps) {
|
|
|
88
88
|
const same = store.selected === id;
|
|
89
89
|
// Leaving for another session: the fold this tab kept for the one left
|
|
90
90
|
// has no page to come back to (stage_waiting.js). A reselect of the same
|
|
91
|
-
// session keeps it: the page is redrawn, not left.
|
|
92
|
-
|
|
91
|
+
// session keeps it: the page is redrawn, not left. No session open (the
|
|
92
|
+
// first select): no key, and a removeItem(null) would delete "null".
|
|
93
|
+
const leftFold = same ? null : foldKey(store.selected);
|
|
94
|
+
if (leftFold) removeSession(leftFold);
|
|
93
95
|
// Its synchronous part in one batch: the active card, the composer and
|
|
94
96
|
// the bar redraw once, at its end (never across the await).
|
|
95
97
|
store.batch(() => {
|
|
@@ -9,6 +9,8 @@ import { handOffOrder, stageCollapsed } from "./stage_model.js";
|
|
|
9
9
|
import { readStored, writeStored } from "./storage.js";
|
|
10
10
|
import { ASKS, PENDING, waitsInStage } from "./stage_cards.js";
|
|
11
11
|
import { cardIn, waitingKey, waitingKind } from "./stage_waiting.js";
|
|
12
|
+
import { warnDiffers } from "./card_kinds.js";
|
|
13
|
+
import { probing } from "./stage_probe.js";
|
|
12
14
|
|
|
13
15
|
const COLLAPSE_KEY = "chi_stage_collapsed";
|
|
14
16
|
// The cards that get a lead-in bubble when their step wrote text: chi's own
|
|
@@ -123,12 +125,23 @@ export function createStageAsking({
|
|
|
123
125
|
opener.open(handOffOrder({ prompt: promptEl(), block: blockEl, extras: rows }), { follow });
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
// The waiting cards as data
|
|
127
|
-
//
|
|
128
|
-
// extras and the tail
|
|
129
|
-
//
|
|
128
|
+
// The waiting cards as data against the slots, a debug check only (the
|
|
129
|
+
// perf probe, or <body data-stage-check="1">: the e2e and the tests): an
|
|
130
|
+
// entry whose card is gone from the extras and the tail or waits no more,
|
|
131
|
+
// or a card in them that waits with no entry, warns "stage: waiting drift".
|
|
132
|
+
// It settles nothing: every way a card stops waiting settles through a
|
|
133
|
+
// hook (stage_waiting.js). Off, it returns at once.
|
|
130
134
|
function reconcileWaiting() {
|
|
131
|
-
|
|
135
|
+
if (!probing() && globalThis.document?.body?.dataset?.stageCheck !== "1") return;
|
|
136
|
+
const keys = new Set();
|
|
137
|
+
for (const { key } of waiting.list()) {
|
|
138
|
+
keys.add(key);
|
|
139
|
+
if (!waitingKind(cardIn(extras, key) || cardIn(tail, key))) console.warn("stage: waiting drift", key);
|
|
140
|
+
}
|
|
141
|
+
for (const el of [...(extras?.children || []), ...(tail?.children || [])]) {
|
|
142
|
+
const key = waitingKey(el);
|
|
143
|
+
if (key && waitingKind(el) && !keys.has(key)) console.warn("stage: waiting drift", key);
|
|
144
|
+
}
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
// An opened turn's cards that stopped waiting go into the history: one
|
|
@@ -158,9 +171,19 @@ export function createStageAsking({
|
|
|
158
171
|
|
|
159
172
|
// The folded row's text for the docked +card+ (stage_model.js
|
|
160
173
|
// foldedRowText): a question's text, an approval's summary and its
|
|
161
|
-
// command's first line, a plugin card's title; "" for none.
|
|
174
|
+
// command's first line, a plugin card's title; "" for none. From the
|
|
175
|
+
// shown entry's data (stage_waiting.js summary), the card's own read the
|
|
176
|
+
// cross-check, and the fallback for an entry without one.
|
|
162
177
|
function foldedText(card) {
|
|
163
178
|
if (!card) return "";
|
|
179
|
+
const key = waitingKey(card);
|
|
180
|
+
const summary = waiting.get(key)?.summary;
|
|
181
|
+
const dom = foldedTextOf(card);
|
|
182
|
+
if (summary == null) return dom;
|
|
183
|
+
if (summary !== dom) warnDiffers("summary", key, summary, dom);
|
|
184
|
+
return summary;
|
|
185
|
+
}
|
|
186
|
+
function foldedTextOf(card) {
|
|
164
187
|
if (card.matches(".plugin-card")) return card.querySelector(".card-title")?.textContent || "";
|
|
165
188
|
if (card.dataset.kind !== "approval") return card.querySelector(".question-text")?.textContent || "";
|
|
166
189
|
// The summary's own words, not its "↑ its reason" link.
|
|
@@ -213,10 +236,7 @@ export function createStageAsking({
|
|
|
213
236
|
// ── the fold ─────────────────────────────────────────────────────────────
|
|
214
237
|
|
|
215
238
|
// Whether the stage is collapsed now (stage_model.js stageCollapsed).
|
|
216
|
-
// The registry is checked against the slots first: a card answered since
|
|
217
|
-
// the last refresh no longer holds the fold.
|
|
218
239
|
function isCollapsed() {
|
|
219
|
-
reconcileWaiting();
|
|
220
240
|
return stageCollapsed({ choice, revealed, asking: askingKey(), askingFold: waiting.folded() });
|
|
221
241
|
}
|
|
222
242
|
|
|
@@ -252,7 +272,6 @@ export function createStageAsking({
|
|
|
252
272
|
// asking form it folds that question only and writes nothing; else it is
|
|
253
273
|
// the user's choice, kept.
|
|
254
274
|
function setCollapsed(value) {
|
|
255
|
-
reconcileWaiting();
|
|
256
275
|
const asking = askingKey();
|
|
257
276
|
if (asking) {
|
|
258
277
|
waiting.fold(value ? asking : null);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Where a row or a card goes while the stage holds a turn (stage_view.js's
|
|
2
|
+
// place, wired there): the stage's extras or its tail, its queued slot, the
|
|
3
|
+
// history's end of a turn opened there, or the history itself (false). A card
|
|
4
|
+
// that waits for the user docks: the turn opens in the history (stage_asking.js
|
|
5
|
+
// openTurn), its lead-in lands there in the card's task (stage_opened.js), the
|
|
6
|
+
// card waits in the stage (stage_waiting.js arrive). The step limit's card
|
|
7
|
+
// hands the turn off at once (stage_handoff.js). What a card waits as comes
|
|
8
|
+
// from its data (card_kinds.js, +expect+ right before its place); the node's
|
|
9
|
+
// own read (waitingKind) is the cross-check, and the fallback for a card
|
|
10
|
+
// that came without it (an older question_cards.js, a test's bare card).
|
|
11
|
+
import { placeFor, placeKind } from "./stage_model.js";
|
|
12
|
+
import { askingRefs } from "./turn_model.js";
|
|
13
|
+
import { ASKS, PENDING } from "./stage_cards.js";
|
|
14
|
+
import { isApprovalCard, isBlocking, waitingKey, waitingKind } from "./stage_waiting.js";
|
|
15
|
+
import { warnDiffers } from "./card_kinds.js";
|
|
16
|
+
|
|
17
|
+
// +historyEl+, +extras+, +tail+, +queuedSlot+: the history and the stage's
|
|
18
|
+
// slots; +ensureQueuedSlot()+ puts the queued slot back in the stage.
|
|
19
|
+
// +handoff+ (stage_handoff.js), +quiet+ (stage_quiet_clock.js), +view+ (the
|
|
20
|
+
// turn block), +opener+ (stage_opened.js), +waiting+ (stage_waiting.js) and
|
|
21
|
+
// +ask+ (stage_asking.js, whole: the docking, the lead-in, the opened row).
|
|
22
|
+
// +frame()+: the stage's frame (stage_frame.js); +refresh()+ and
|
|
23
|
+
// +scheduleRefresh()+ the stage's; +holding()+, +opened()+, +endKind()+ and
|
|
24
|
+
// +promptEl()+ the stage's turn; +historyNearBottom()+ the history's follow
|
|
25
|
+
// check.
|
|
26
|
+
export function createStagePlace({
|
|
27
|
+
historyEl, extras, tail, queuedSlot, ensureQueuedSlot, handoff, quiet, view, opener, waiting, ask, frame, refresh,
|
|
28
|
+
scheduleRefresh, holding, opened, endKind, promptEl, historyNearBottom,
|
|
29
|
+
}) {
|
|
30
|
+
// key → what the card about to be placed waits as ({kind, approval,
|
|
31
|
+
// summary}): taken by its place, whatever the outcome (a history card's
|
|
32
|
+
// too), cleared with the stage's slots (reset).
|
|
33
|
+
const expected = new Map();
|
|
34
|
+
|
|
35
|
+
// The card's wait: its data, else the node's read; the two checked
|
|
36
|
+
// against each other.
|
|
37
|
+
function waitOf(el, key) {
|
|
38
|
+
const data = key ? expected.get(key) : undefined;
|
|
39
|
+
if (key) expected.delete(key);
|
|
40
|
+
const dom = { kind: waitingKind(el), approval: isApprovalCard(el) };
|
|
41
|
+
if (!data) return { ...dom, summary: null };
|
|
42
|
+
if ((data.kind ?? null) !== dom.kind || !!data.approval !== dom.approval) warnDiffers("kind", key, data, dom);
|
|
43
|
+
return { kind: data.kind ?? null, approval: !!data.approval, summary: data.summary ?? null };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The stage's extras while it holds a turn (a card, a prompt for its
|
|
47
|
+
// next step, a command, a note, the end line), its queued slot for a
|
|
48
|
+
// line queued for after it; false: the history takes it.
|
|
49
|
+
function place(el) {
|
|
50
|
+
// A turn still sliding away goes into the history first: what comes
|
|
51
|
+
// now comes after it.
|
|
52
|
+
handoff.settle();
|
|
53
|
+
const key = waitingKey(el);
|
|
54
|
+
const wait = waitOf(el, key);
|
|
55
|
+
const waits = !!(el.matches?.(PENDING) || el.querySelector?.(ASKS));
|
|
56
|
+
const kind = placeKind(el);
|
|
57
|
+
const isOpened = opened();
|
|
58
|
+
const ended = endKind();
|
|
59
|
+
const where = placeFor({ live: holding(), handingOff: false, kind, opened: isOpened && !ended });
|
|
60
|
+
// A late recap (idle-only, it describes the chat before this turn)
|
|
61
|
+
// goes above an opened turn, not inside it.
|
|
62
|
+
const above = kind === "recap" && isOpened ? [promptEl(), view.current().blockEl].find((x) => x?.parentElement === historyEl) : null;
|
|
63
|
+
if (above) {
|
|
64
|
+
historyEl.insertBefore(el, above);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if (where === "history") return false;
|
|
68
|
+
quiet.alive();
|
|
69
|
+
if (where === "queued") {
|
|
70
|
+
ensureQueuedSlot();
|
|
71
|
+
queuedSlot.appendChild(el);
|
|
72
|
+
scheduleRefresh();
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
// An opened turn's row: the history's end, in arrival order; a card
|
|
76
|
+
// that stopped waiting before it (a replay answers it and steers in
|
|
77
|
+
// one task, before the refresh) goes there first.
|
|
78
|
+
if (where === "opened") {
|
|
79
|
+
ask.settleCards();
|
|
80
|
+
opener.add(el);
|
|
81
|
+
scheduleRefresh();
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
// A card that waits for the user docks: the turn opens in the
|
|
85
|
+
// history, a lead-in lands there in this task, the card stays here.
|
|
86
|
+
const docked = ask.docks(el);
|
|
87
|
+
// A card drawn again with its key (the same question) keeps its lead-in.
|
|
88
|
+
const kept = docked && opener.has(key);
|
|
89
|
+
const reason = docked && !kept ? ask.leadInText(el) : "";
|
|
90
|
+
// Read before the turn's pieces make the history taller: with no
|
|
91
|
+
// lead-in to read, a reader at the end follows the turn's move.
|
|
92
|
+
const atEnd = docked ? historyNearBottom() : false;
|
|
93
|
+
if (docked) ask.openTurn({ follow: atEnd && !reason });
|
|
94
|
+
const slot = ended ? tail : extras;
|
|
95
|
+
const stick = slot.scrollHeight - slot.scrollTop - slot.clientHeight < 24;
|
|
96
|
+
// The stage's order (stage_waiting.js): a card that blocks goes before
|
|
97
|
+
// the asking ones, as a reload places them.
|
|
98
|
+
const behind = isBlocking(wait.kind) ? [...slot.children].find((x) => waiting.get(waitingKey(x))?.kind === "asks") : null;
|
|
99
|
+
slot.insertBefore(el, behind || null);
|
|
100
|
+
slot.hidden = false;
|
|
101
|
+
// The card is the stage's to keep (stage_waiting.js): docked when it
|
|
102
|
+
// waits for the user (its lead-in is the opener's, by the same key).
|
|
103
|
+
const waitKind = wait.kind;
|
|
104
|
+
if (waitKind) waiting.arrive(key, { kind: waitKind, docked, approval: wait.approval, summary: wait.summary });
|
|
105
|
+
if (stick || waits) slot.scrollTop = slot.scrollHeight;
|
|
106
|
+
if (kept) opener.relink(key, el);
|
|
107
|
+
if (reason) {
|
|
108
|
+
const { turn } = view.current();
|
|
109
|
+
opener.ask({
|
|
110
|
+
card: el, key, text: reason, refs: askingRefs(turn) || ask.askingGen(ask.asksOf(el))?.refs || null, step: turn?.gens.length || 0,
|
|
111
|
+
turnId: promptEl()?.dataset.turnId || null, questionId: el.dataset.qid ?? null, follow: atEnd,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// The step limit: its card goes under its ended turn in the
|
|
115
|
+
// conversation at once, as a reload draws it (the hand-off: its fold,
|
|
116
|
+
// the history's follow and the reload check as for any finished turn;
|
|
117
|
+
// the in-use watch and the end read don't hold it).
|
|
118
|
+
if (ended && waitKind === "continue") {
|
|
119
|
+
handoff.handOff();
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
// A waiting card and the asking form (refresh) land in one task.
|
|
123
|
+
if (waits) refresh();
|
|
124
|
+
else scheduleRefresh();
|
|
125
|
+
// The asking form: the stage shrinks to the card; an answer can also
|
|
126
|
+
// shrink it to a remaining card, or release it at the next step.
|
|
127
|
+
if (docked) frame().forgetContent();
|
|
128
|
+
if (waits && el.matches?.(".bubble.question")) ask.askedFor(el);
|
|
129
|
+
// A card that waits for the user is brought into the stage's view: in
|
|
130
|
+
// a short window the prompt and headline fill it and the card sat
|
|
131
|
+
// below, out of sight (once the stage has grown for it).
|
|
132
|
+
if (waits) frame().afterGrowth(() => frame().reveal(slot));
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
place,
|
|
138
|
+
// +key+'s card is placed next; +info+: card_kinds.js's wait.
|
|
139
|
+
expect(key, info) {
|
|
140
|
+
if (key && info) expected.set(key, info);
|
|
141
|
+
},
|
|
142
|
+
reset: () => expected.clear(),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// The stage's perf probe (script/stage-perf-probe, docs/testing.md): off
|
|
2
|
+
// unless the page was opened with ?stage_probe=1 (kept for the tab in
|
|
3
|
+
// sessionStorage, chi_stage_probe, so a reload or a hash jump keeps it;
|
|
4
|
+
// ?stage_probe=0 drops it) or <body data-stage-probe="1"> (read at each call:
|
|
5
|
+
// Web Inspector can set it after the page loaded). Probing, +measured+
|
|
6
|
+
// times its function as a performance measure, and the page gets
|
|
7
|
+
// globalThis.chiStageProbe.report(): each name's {n, p50, p95, max} in ms,
|
|
8
|
+
// the measures cleared after. Off, +measured+ only runs the function.
|
|
9
|
+
const KEY = "chi_stage_probe";
|
|
10
|
+
let kept = null;
|
|
11
|
+
|
|
12
|
+
// The tab's flag, read once per page load (storage can throw: off then).
|
|
13
|
+
function keptOn() {
|
|
14
|
+
if (kept !== null) return kept;
|
|
15
|
+
kept = false;
|
|
16
|
+
try {
|
|
17
|
+
const asked = new URLSearchParams(globalThis.location?.search || "").get("stage_probe");
|
|
18
|
+
if (asked === "1") sessionStorage.setItem(KEY, "1");
|
|
19
|
+
else if (asked === "0") sessionStorage.removeItem(KEY);
|
|
20
|
+
kept = sessionStorage.getItem(KEY) === "1";
|
|
21
|
+
} catch (_) {
|
|
22
|
+
kept = false;
|
|
23
|
+
}
|
|
24
|
+
return kept;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const probing = () => globalThis.document?.body?.dataset?.stageProbe === "1" || keptOn();
|
|
28
|
+
|
|
29
|
+
const at = (sorted, q) => sorted[Math.min(sorted.length - 1, Math.floor(q * sorted.length))];
|
|
30
|
+
const round = (ms) => Math.round(ms * 1000) / 1000;
|
|
31
|
+
|
|
32
|
+
// Each name's measures since the last report or clear: past MAX_MEASURES the
|
|
33
|
+
// name's measures are cleared (a page left probing for hours stays small).
|
|
34
|
+
const MAX_MEASURES = 10_000;
|
|
35
|
+
const counts = new Map();
|
|
36
|
+
|
|
37
|
+
export function report() {
|
|
38
|
+
counts.clear();
|
|
39
|
+
const byName = {};
|
|
40
|
+
for (const m of performance.getEntriesByType("measure")) (byName[m.name] ||= []).push(m.duration);
|
|
41
|
+
performance.clearMeasures();
|
|
42
|
+
performance.clearMarks();
|
|
43
|
+
return Object.fromEntries(Object.entries(byName).map(([name, list]) => {
|
|
44
|
+
const sorted = list.sort((a, b) => a - b);
|
|
45
|
+
return [name, { n: sorted.length, p50: round(at(sorted, 0.5)), p95: round(at(sorted, 0.95)), max: round(sorted[sorted.length - 1]) }];
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function measured(name, fn) {
|
|
50
|
+
if (!probing()) return fn();
|
|
51
|
+
globalThis.chiStageProbe ||= { report };
|
|
52
|
+
const start = performance.now();
|
|
53
|
+
try {
|
|
54
|
+
return fn();
|
|
55
|
+
} finally {
|
|
56
|
+
// The probe never breaks the page: a measure the browser refuses is lost.
|
|
57
|
+
try {
|
|
58
|
+
const n = (counts.get(name) || 0) + 1;
|
|
59
|
+
if (n > MAX_MEASURES) performance.clearMeasures(name);
|
|
60
|
+
counts.set(name, n > MAX_MEASURES ? 1 : n);
|
|
61
|
+
performance.measure(name, { start, end: performance.now() });
|
|
62
|
+
} catch (_) { /* not measured */ }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -21,14 +21,15 @@
|
|
|
21
21
|
// (web-frontend.md, The stage's modules): the nodes are stage_dom.js's, the
|
|
22
22
|
// live slots stage_slots.js's, the cap and the held height stage_frame.js's,
|
|
23
23
|
// the in-use watch that times the hand-off stage_watch.js's, the hand-off
|
|
24
|
-
// itself stage_handoff.js's,
|
|
25
|
-
// the
|
|
26
|
-
//
|
|
27
|
-
//
|
|
24
|
+
// itself stage_handoff.js's, where a row or a card goes stage_place.js's,
|
|
25
|
+
// the cloud stage_cloud.js's, the docked card and the fold stage_asking.js's,
|
|
26
|
+
// its pager stage_pager.js's, the waiting cards as data stage_waiting.js's,
|
|
27
|
+
// the answer's reading stage_answer.js's, the quiet signal stage_stall.js's
|
|
28
|
+
// and its clocks stage_quiet_clock.js's, the perf probe stage_probe.js's. A new
|
|
28
29
|
// stage feature goes into its own stage_<feature>.js, wired here in a few
|
|
29
30
|
// lines; each module resets itself from emptySlots.
|
|
30
31
|
import { createTurnBlock } from "./turn_block.js";
|
|
31
|
-
import { chipLabelText, flashOf, handOffDue, headlineOf, isPlain, liveSlots, MARKS, foldedRowText, phaseLabel,
|
|
32
|
+
import { chipLabelText, flashOf, handOffDue, headlineOf, isPlain, liveSlots, MARKS, foldedRowText, phaseLabel, QUEUED_CHILDREN, stepSlotText } from "./stage_model.js";
|
|
32
33
|
import { createStageSlots, node } from "./stage_slots.js";
|
|
33
34
|
import { createStageDom } from "./stage_dom.js";
|
|
34
35
|
import { createStageAnswer } from "./stage_answer.js";
|
|
@@ -45,12 +46,12 @@ import { createStageQuietClock } from "./stage_quiet_clock.js";
|
|
|
45
46
|
import { formatDuration } from "./timing.js";
|
|
46
47
|
import { createWorkingSetRail } from "./working_set_rail.js";
|
|
47
48
|
import { createOpenedTurn } from "./stage_opened.js";
|
|
48
|
-
import { askingRefs } from "./turn_model.js";
|
|
49
|
-
import { ASKS, PENDING } from "./stage_cards.js";
|
|
50
49
|
import { createStageAsking } from "./stage_asking.js";
|
|
51
|
-
import { cardIn, createStageWaiting,
|
|
50
|
+
import { cardIn, createStageWaiting, waitingKey } from "./stage_waiting.js";
|
|
52
51
|
import { stampRows } from "./working_set_view.js";
|
|
53
52
|
import { createOwnerWait } from "./stage_owner_wait.js";
|
|
53
|
+
import { measured } from "./stage_probe.js";
|
|
54
|
+
import { createStagePlace } from "./stage_place.js";
|
|
54
55
|
|
|
55
56
|
// The turn-end read (markdown, answer_display) settles within this, or the
|
|
56
57
|
// hand-off stops waiting for it.
|
|
@@ -73,12 +74,13 @@ const FLASH_MS = 4000;
|
|
|
73
74
|
// waits on (live_timing.js note), +serverGen+() a joiner's generation.
|
|
74
75
|
// +canCancel+() whether this turn's Stop turn shows (a participant's own
|
|
75
76
|
// turn only); +ownerWait+() the kind a participant's view waits for the
|
|
76
|
-
// owner on, or null (stage_owner_wait.js).
|
|
77
|
+
// owner on, or null (stage_owner_wait.js). +createWaiting+: the registry's
|
|
78
|
+
// factory (stage_waiting.js; a test passes an older one's shape).
|
|
77
79
|
export function createStageView({
|
|
78
80
|
historyEl, isNearBottom: historyNearBottom, sawText, sessionId, dockEl, centerEl, taskStop = null,
|
|
79
81
|
renderMarkdown, linkRefs, workingSet = null, onCancel = null, onHandedOff = null,
|
|
80
82
|
clock = () => Date.now(), streamLive = () => true, timingNote = () => "", serverGen = () => null,
|
|
81
|
-
canCancel = () => true, ownerWait = () => null,
|
|
83
|
+
canCancel = () => true, ownerWait = () => null, createWaiting = createStageWaiting,
|
|
82
84
|
}) {
|
|
83
85
|
// The stage's nodes (stage_dom.js), then their behaviour here and in the
|
|
84
86
|
// stage's modules.
|
|
@@ -196,7 +198,7 @@ export function createStageView({
|
|
|
196
198
|
// The cards that wait in the stage, as data (stage_waiting.js): the
|
|
197
199
|
// docked card, its fold, what blocks, the approval's cap read them. The
|
|
198
200
|
// fold of the asking card is this tab's own, kept per session.
|
|
199
|
-
const waiting =
|
|
201
|
+
const waiting = createWaiting({ sessionId });
|
|
200
202
|
let dockedAtLastRefresh = [];
|
|
201
203
|
// The asking form and the stage's fold (stage_asking.js).
|
|
202
204
|
const ask = createStageAsking({
|
|
@@ -204,7 +206,7 @@ export function createStageView({
|
|
|
204
206
|
isEnded: () => !!endKind, promptEl: () => promptEl, setCloud: (open) => cloudView.setCloud(open), scheduleRefresh, pendingCard, waiting,
|
|
205
207
|
});
|
|
206
208
|
const {
|
|
207
|
-
|
|
209
|
+
askedText, settleCards, askingCard, cardOf, foldedText, markOwnToggles,
|
|
208
210
|
isCollapsed, drawCollapsed, applyCollapsed, setCollapsed,
|
|
209
211
|
} = ask;
|
|
210
212
|
|
|
@@ -227,11 +229,10 @@ export function createStageView({
|
|
|
227
229
|
requestAnimationFrame(refresh);
|
|
228
230
|
}
|
|
229
231
|
|
|
230
|
-
// A card that blocks the turn waits (stage_waiting.js
|
|
231
|
-
//
|
|
232
|
-
// task, before the refresh).
|
|
232
|
+
// A card that blocks the turn waits (stage_waiting.js: every way a card
|
|
233
|
+
// stops waiting settles it at once, also a replay's answer and next step
|
|
234
|
+
// in one task, before the refresh).
|
|
233
235
|
function pendingCard() {
|
|
234
|
-
ask.reconcileWaiting();
|
|
235
236
|
return waiting.count() > 0;
|
|
236
237
|
}
|
|
237
238
|
|
|
@@ -263,7 +264,12 @@ export function createStageView({
|
|
|
263
264
|
// the card's own task, never a frame apart.
|
|
264
265
|
new MutationObserver(() => refresh()).observe(extras, { childList: true, subtree: true });
|
|
265
266
|
|
|
267
|
+
// Timed when the perf probe is on (stage_probe.js).
|
|
266
268
|
function refresh() {
|
|
269
|
+
measured("stage:refresh", drawRefresh);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function drawRefresh() {
|
|
267
273
|
rafPending = false;
|
|
268
274
|
const { turn, blockEl } = view.current();
|
|
269
275
|
if (!holding || !turn) return;
|
|
@@ -283,7 +289,6 @@ export function createStageView({
|
|
|
283
289
|
const thinking = thinkingLine && thinkingLine.step === turn.gens.length ? thinkingLine.text : "";
|
|
284
290
|
// A question blocks the turn: its card takes the live slots' room. An
|
|
285
291
|
// asking card's turn goes on: the status waits, the slots stay.
|
|
286
|
-
ask.reconcileWaiting();
|
|
287
292
|
settleCards();
|
|
288
293
|
markOwnToggles();
|
|
289
294
|
const blocked = pendingCard();
|
|
@@ -374,6 +379,8 @@ export function createStageView({
|
|
|
374
379
|
extras.hidden = !extras.firstChild;
|
|
375
380
|
answer.hidden = !answer.firstChild;
|
|
376
381
|
tail.hidden = !tail.firstChild;
|
|
382
|
+
// The registry against the slots: a debug check only (stage_asking.js).
|
|
383
|
+
ask.reconcileWaiting();
|
|
377
384
|
}
|
|
378
385
|
|
|
379
386
|
// The next step after a blocking card's answer, or an answer that leaves
|
|
@@ -490,6 +497,7 @@ export function createStageView({
|
|
|
490
497
|
markOwnToggles();
|
|
491
498
|
opener.reset();
|
|
492
499
|
waiting.reset();
|
|
500
|
+
placer.reset();
|
|
493
501
|
dockedAtLastRefresh = [];
|
|
494
502
|
miniTool.classList.remove("ts-mini-question");
|
|
495
503
|
cloudView.reset();
|
|
@@ -536,6 +544,12 @@ export function createStageView({
|
|
|
536
544
|
blockPlace, promptWords, isCollapsed, releaseTurn, clearStage, onHandedOff,
|
|
537
545
|
});
|
|
538
546
|
|
|
547
|
+
// Where a row or a card goes while the stage holds a turn (stage_place.js).
|
|
548
|
+
const placer = createStagePlace({
|
|
549
|
+
historyEl, extras, tail, queuedSlot, ensureQueuedSlot, handoff, quiet, view, opener, waiting, ask, frame: () => frame, refresh,
|
|
550
|
+
scheduleRefresh, holding: () => holding, opened: () => opened, endKind: () => endKind, promptEl: () => promptEl, historyNearBottom,
|
|
551
|
+
});
|
|
552
|
+
|
|
539
553
|
function dropBare() {
|
|
540
554
|
if (!bare) return;
|
|
541
555
|
bare = false;
|
|
@@ -680,93 +694,11 @@ export function createStageView({
|
|
|
680
694
|
handoff.reset();
|
|
681
695
|
release();
|
|
682
696
|
},
|
|
683
|
-
// The stage's extras while it holds a turn
|
|
684
|
-
//
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
// now comes after it.
|
|
689
|
-
handoff.settle();
|
|
690
|
-
const waits = !!(el.matches?.(PENDING) || el.querySelector?.(ASKS));
|
|
691
|
-
const kind = placeKind(el);
|
|
692
|
-
const where = placeFor({ live: holding, handingOff: false, kind, opened: opened && !endKind });
|
|
693
|
-
// A late recap (idle-only, it describes the chat before this turn)
|
|
694
|
-
// goes above an opened turn, not inside it.
|
|
695
|
-
const above = kind === "recap" && opened ? [promptEl, view.current().blockEl].find((x) => x?.parentElement === historyEl) : null;
|
|
696
|
-
if (above) {
|
|
697
|
-
historyEl.insertBefore(el, above);
|
|
698
|
-
return true;
|
|
699
|
-
}
|
|
700
|
-
if (where === "history") return false;
|
|
701
|
-
quiet.alive();
|
|
702
|
-
if (where === "queued") {
|
|
703
|
-
ensureQueuedSlot();
|
|
704
|
-
queuedSlot.appendChild(el);
|
|
705
|
-
scheduleRefresh();
|
|
706
|
-
return true;
|
|
707
|
-
}
|
|
708
|
-
// An opened turn's row: the history's end, in arrival order; a card
|
|
709
|
-
// that stopped waiting before it (a replay answers it and steers in
|
|
710
|
-
// one task, before the refresh) goes there first.
|
|
711
|
-
if (where === "opened") {
|
|
712
|
-
ask.reconcileWaiting();
|
|
713
|
-
settleCards();
|
|
714
|
-
opener.add(el);
|
|
715
|
-
scheduleRefresh();
|
|
716
|
-
return true;
|
|
717
|
-
}
|
|
718
|
-
// A card that waits for the user docks: the turn opens in the
|
|
719
|
-
// history, a lead-in lands there in this task, the card stays here.
|
|
720
|
-
const docked = docks(el);
|
|
721
|
-
const key = waitingKey(el);
|
|
722
|
-
// A card drawn again with its key (the same question) keeps its lead-in.
|
|
723
|
-
const kept = docked && opener.has(key);
|
|
724
|
-
const reason = docked && !kept ? leadInText(el) : "";
|
|
725
|
-
// Read before the turn's pieces make the history taller: with no
|
|
726
|
-
// lead-in to read, a reader at the end follows the turn's move.
|
|
727
|
-
const atEnd = docked ? historyNearBottom() : false;
|
|
728
|
-
if (docked) openTurn({ follow: atEnd && !reason });
|
|
729
|
-
const slot = endKind ? tail : extras;
|
|
730
|
-
const stick = slot.scrollHeight - slot.scrollTop - slot.clientHeight < 24;
|
|
731
|
-
// The stage's order (stage_waiting.js): a card that blocks goes before
|
|
732
|
-
// the asking ones, as a reload places them.
|
|
733
|
-
const behind = isBlocking(waitingKind(el)) ? [...slot.children].find((x) => waitingKind(x) === "asks") : null;
|
|
734
|
-
slot.insertBefore(el, behind || null);
|
|
735
|
-
slot.hidden = false;
|
|
736
|
-
// The card is the stage's to keep (stage_waiting.js): docked when it
|
|
737
|
-
// waits for the user (its lead-in is the opener's, by the same key).
|
|
738
|
-
const waitKind = waitingKind(el);
|
|
739
|
-
if (waitKind) waiting.arrive(key, { kind: waitKind, docked, approval: isApprovalCard(el) });
|
|
740
|
-
if (stick || waits) slot.scrollTop = slot.scrollHeight;
|
|
741
|
-
if (kept) opener.relink(key, el);
|
|
742
|
-
if (reason) {
|
|
743
|
-
const { turn } = view.current();
|
|
744
|
-
opener.ask({
|
|
745
|
-
card: el, key, text: reason, refs: askingRefs(turn) || askingGen(asksOf(el))?.refs || null, step: turn?.gens.length || 0,
|
|
746
|
-
turnId: promptEl?.dataset.turnId || null, questionId: el.dataset.qid ?? null, follow: atEnd,
|
|
747
|
-
});
|
|
748
|
-
}
|
|
749
|
-
// The step limit: its card goes under its ended turn in the
|
|
750
|
-
// conversation at once, as a reload draws it (the hand-off: its fold,
|
|
751
|
-
// the history's follow and the reload check as for any finished turn;
|
|
752
|
-
// the in-use watch and the end read don't hold it).
|
|
753
|
-
if (endKind && waitKind === "continue") {
|
|
754
|
-
handoff.handOff();
|
|
755
|
-
return true;
|
|
756
|
-
}
|
|
757
|
-
// A waiting card and the asking form (refresh) land in one task.
|
|
758
|
-
if (waits) refresh();
|
|
759
|
-
else scheduleRefresh();
|
|
760
|
-
// The asking form: the stage shrinks to the card; an answer can also
|
|
761
|
-
// shrink it to a remaining card, or release it at the next step.
|
|
762
|
-
if (docked) frame.forgetContent();
|
|
763
|
-
if (waits && el.matches?.(".bubble.question")) askedFor(el);
|
|
764
|
-
// A card that waits for the user is brought into the stage's view: in
|
|
765
|
-
// a short window the prompt and headline fill it and the card sat
|
|
766
|
-
// below, out of sight (once the stage has grown for it).
|
|
767
|
-
if (waits) frame.afterGrowth(() => frame.reveal(slot));
|
|
768
|
-
return true;
|
|
769
|
-
},
|
|
697
|
+
// The stage's extras while it holds a turn, its queued slot, an opened
|
|
698
|
+
// turn's history end; false: the history takes it (stage_place.js).
|
|
699
|
+
place: (el) => placer.place(el),
|
|
700
|
+
// What a card about to be placed waits as (card_kinds.js; stage_place.js).
|
|
701
|
+
expectWaiting: (key, info) => placer.expect(key, info),
|
|
770
702
|
// Where the live timing line goes (the status row), null: the history.
|
|
771
703
|
timingHost: () => {
|
|
772
704
|
handoff.settle();
|
|
@@ -815,6 +747,22 @@ export function createStageView({
|
|
|
815
747
|
opener.settle(key, card);
|
|
816
748
|
return true;
|
|
817
749
|
},
|
|
750
|
+
// A plugin card redrawn in place that still waits (cards_place.js
|
|
751
|
+
// upsertCard; +info+: card_kinds.js cardWait): its entry patched, or, for
|
|
752
|
+
// a card in the stage that waits again (its actions back), arrived anew;
|
|
753
|
+
// the stage redrawn at once (a new title changes no child: the extras'
|
|
754
|
+
// observer doesn't see it).
|
|
755
|
+
// An older stage_waiting.js (a mixed cache) has no update: arrive again,
|
|
756
|
+
// which keeps an entry's order.
|
|
757
|
+
updateWaiting: (key, info) => {
|
|
758
|
+
const was = waiting.get(key);
|
|
759
|
+
if (!waiting.update?.(key, info)) {
|
|
760
|
+
const card = cardIn(extras, key) || cardIn(tail, key);
|
|
761
|
+
if (!info?.kind || (!was && !card)) return;
|
|
762
|
+
waiting.arrive(key, { kind: info.kind, docked: was ? was.docked : ask.docks(card), approval: !!was?.approval, summary: info.summary });
|
|
763
|
+
}
|
|
764
|
+
refresh();
|
|
765
|
+
},
|
|
818
766
|
// The waiting cards as data (the tests' and the harness's read).
|
|
819
767
|
waiting: { list: () => waiting.list(), front: () => waiting.front(), docked: () => waiting.docked(), folded: () => waiting.folded(), count: (o) => waiting.count(o) },
|
|
820
768
|
root: stage,
|
|
@@ -6,15 +6,16 @@
|
|
|
6
6
|
//
|
|
7
7
|
// Its feed: +arrive+ from stage_view.js place (a card the stage keeps),
|
|
8
8
|
// +settle+ from question_cards.js's resolve path (onSettled: answered,
|
|
9
|
-
// cancelled, replaced, removed; the continue card resolved or dropped
|
|
9
|
+
// cancelled, replaced, removed; the continue card resolved or dropped; done:
|
|
10
|
+
// answered, cancelled or resolved for good, which removes its stored fold), from
|
|
10
11
|
// cards_place.js upsertCard for a plugin card redrawn without its actions,
|
|
11
12
|
// and from stage_view.js turnEnded for the warn cards leaving with the
|
|
12
|
-
// block; +reset+ from stage_view.js emptySlots.
|
|
13
|
-
// +reconcile+ (
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
13
|
+
// block; +reset+ from stage_view.js emptySlots. Settle is the one way out:
|
|
14
|
+
// +reconcile+ (the old second feed, which dropped an entry whose card was
|
|
15
|
+
// gone or waited no more) is called by nobody now and stays one release
|
|
16
|
+
// for a mixed cache (an older stage_asking.js calls it); stage_asking.js
|
|
17
|
+
// reconcileWaiting only compares and warns (a debug check). Arrive is the
|
|
18
|
+
// one way in.
|
|
18
19
|
//
|
|
19
20
|
// A card's entry: its kind (KINDS), docked (it shows alone in the box above
|
|
20
21
|
// the composer, its turn opened in the history: stage_asking.js docks; its
|
|
@@ -27,8 +28,9 @@
|
|
|
27
28
|
// fold (the docked card's own, stage_asking.js) is the folded card's key and
|
|
28
29
|
// how many cards waited when it was folded. That fold is this tab's own: it
|
|
29
30
|
// is kept in sessionStorage (one entry per session) so a reload or a resync
|
|
30
|
-
// mid-turn draws the card as the user left it, and it goes when
|
|
31
|
-
// answered or cancelled
|
|
31
|
+
// mid-turn draws the card as the user left it, and it goes when that card is
|
|
32
|
+
// answered or cancelled (settle with done: no other card's answer touches
|
|
33
|
+
// it), when the fold drops, and when the turn hands off.
|
|
32
34
|
import { ASKS, PENDING, WARN_CARD } from "./stage_cards.js";
|
|
33
35
|
import { readSession, removeSession, writeSession } from "./storage.js";
|
|
34
36
|
|
|
@@ -147,17 +149,32 @@ export function createStageWaiting({ sessionId = null, storage = tabStorage } =
|
|
|
147
149
|
return {
|
|
148
150
|
// +key+ came to the stage (again: its kind and flags change, its place in
|
|
149
151
|
// the order stays).
|
|
150
|
-
|
|
152
|
+
// +summary+: the folded row's text from its data (card_kinds.js), null:
|
|
153
|
+
// none (stage_asking.js foldedText reads the card then).
|
|
154
|
+
arrive(key, { kind, docked = false, approval = false, summary = null } = {}) {
|
|
151
155
|
if (!key || !KINDS.includes(kind)) return;
|
|
152
156
|
const was = cards.get(key);
|
|
153
157
|
// A new card goes in front of what the pager was on.
|
|
154
158
|
if (!was) paged = null;
|
|
155
159
|
cards.set(key, {
|
|
156
|
-
kind, docked: !!docked, approval: !!approval, order: was ? was.order : seq++,
|
|
160
|
+
kind, docked: !!docked, approval: !!approval, summary: typeof summary === "string" ? summary : null, order: was ? was.order : seq++,
|
|
157
161
|
});
|
|
158
162
|
},
|
|
159
|
-
// +key+
|
|
160
|
-
|
|
163
|
+
// +key+'s card was redrawn in place, still waiting (cards_place.js
|
|
164
|
+
// upsertCard): its kind and summary as its data says now, its order and
|
|
165
|
+
// docking as they were. Whether there was an entry to patch.
|
|
166
|
+
update(key, { kind, summary = null } = {}) {
|
|
167
|
+
const was = cards.get(key);
|
|
168
|
+
if (!was) return false;
|
|
169
|
+
cards.set(key, { ...was, kind: KINDS.includes(kind) ? kind : was.kind, summary: typeof summary === "string" ? summary : was.summary });
|
|
170
|
+
return true;
|
|
171
|
+
},
|
|
172
|
+
// +key+ stopped waiting (+only+: when it is that kind). +done+: for
|
|
173
|
+
// good (answered, cancelled, the continue card resolved): the fold this
|
|
174
|
+
// tab kept goes when it names this card, also when the stage holds no
|
|
175
|
+
// entry for it (a replay's earlier card, a history question).
|
|
176
|
+
settle(key, { only = null, done = false } = {}) {
|
|
177
|
+
if (done && key && storedFold()?.key === key) storage.remove(at());
|
|
161
178
|
const was = cards.get(key);
|
|
162
179
|
if (!was || (only && was.kind !== only)) return false;
|
|
163
180
|
cards.delete(key);
|
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.172.
|
|
4
|
+
version: 0.172.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Dedov
|
|
@@ -931,6 +931,7 @@ files:
|
|
|
931
931
|
- lib/samagotchi/web/public/block_watch.js
|
|
932
932
|
- lib/samagotchi/web/public/bubbles.js
|
|
933
933
|
- lib/samagotchi/web/public/card.js
|
|
934
|
+
- lib/samagotchi/web/public/card_kinds.js
|
|
934
935
|
- lib/samagotchi/web/public/card_stamps.js
|
|
935
936
|
- lib/samagotchi/web/public/cards_offscreen.js
|
|
936
937
|
- lib/samagotchi/web/public/cards_place.js
|
|
@@ -1059,6 +1060,8 @@ files:
|
|
|
1059
1060
|
- lib/samagotchi/web/public/stage_opened.js
|
|
1060
1061
|
- lib/samagotchi/web/public/stage_owner_wait.js
|
|
1061
1062
|
- lib/samagotchi/web/public/stage_pager.js
|
|
1063
|
+
- lib/samagotchi/web/public/stage_place.js
|
|
1064
|
+
- lib/samagotchi/web/public/stage_probe.js
|
|
1062
1065
|
- lib/samagotchi/web/public/stage_quiet_clock.js
|
|
1063
1066
|
- lib/samagotchi/web/public/stage_slots.js
|
|
1064
1067
|
- lib/samagotchi/web/public/stage_stall.js
|