samagotchi 0.170.0 → 0.172.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -1
- data/bin/chi +6 -4
- data/docs/architecture.md +26 -9
- data/docs/bundles.md +4 -21
- data/docs/cli.md +81 -97
- data/docs/configuration.md +12 -14
- data/docs/context.md +5 -6
- data/docs/guardrails.md +57 -96
- data/docs/hooks.md +3 -4
- data/docs/internals/attached-context.md +6 -7
- data/docs/internals/background-tasks.md +4 -3
- data/docs/internals/block-renderers.md +2 -2
- data/docs/internals/bridge.md +34 -7
- data/docs/internals/context-telemetry.md +13 -1
- data/docs/internals/engine.md +25 -13
- data/docs/internals/inline-widgets.md +1 -1
- data/docs/internals/objectives.md +4 -6
- data/docs/internals/participants.md +340 -249
- data/docs/internals/prompt-caching.md +4 -5
- data/docs/internals/web-frontend.md +185 -35
- data/docs/internals/working-set.md +71 -5
- data/docs/memory.md +1 -1
- data/docs/plugins.md +2 -16
- data/docs/releasing.md +2 -1
- data/docs/scheduling.md +1 -1
- data/docs/sessions.md +17 -48
- data/docs/sub-agent.md +2 -2
- data/docs/system-one.md +2 -2
- data/docs/testing.md +56 -7
- data/lib/samagotchi/bridge/card_store.rb +1 -0
- data/lib/samagotchi/bridge/sse_writer.rb +1 -0
- data/lib/samagotchi/bridge/turn_accumulator.rb +8 -5
- data/lib/samagotchi/bridge.rb +64 -20
- data/lib/samagotchi/bridge_client/event_stream.rb +2 -0
- data/lib/samagotchi/bundle_command/test_run.rb +1 -0
- data/lib/samagotchi/bundle_command/try/run.rb +1 -0
- data/lib/samagotchi/bundles/coordinator/manifest.yml +4 -5
- data/lib/samagotchi/bundles/coordinator/plugin.rb +6 -79
- data/lib/samagotchi/bundles/coordinator/skill_coordinator.md +1 -16
- data/lib/samagotchi/bundles/github-pr/manifest.yml +2 -2
- data/lib/samagotchi/bundles/github-pr/plugin.rb +0 -1
- data/lib/samagotchi/bundles/inline-widgets/manifest.yml +2 -2
- data/lib/samagotchi/bundles/inline-widgets/plugin.rb +4 -5
- data/lib/samagotchi/bundles/system/manifest.yml +1 -1
- data/lib/samagotchi/client_id.rb +126 -67
- data/lib/samagotchi/command_intake.rb +15 -3
- data/lib/samagotchi/compat.rb +6 -1
- data/lib/samagotchi/context_candidate_choice.rb +1 -3
- data/lib/samagotchi/context_candidates.rb +3 -4
- data/lib/samagotchi/continue_offer.rb +9 -2
- data/lib/samagotchi/delivery.rb +36 -12
- data/lib/samagotchi/empty_answer_error.rb +5 -0
- data/lib/samagotchi/engine/cards.rb +3 -0
- data/lib/samagotchi/engine/context_judge.rb +5 -3
- data/lib/samagotchi/engine/events.rb +4 -0
- data/lib/samagotchi/engine/hooks.rb +3 -0
- data/lib/samagotchi/engine/messages.rb +5 -0
- data/lib/samagotchi/engine/model_settings.rb +2 -0
- data/lib/samagotchi/engine/models.rb +10 -0
- data/lib/samagotchi/engine/objectives.rb +6 -0
- data/lib/samagotchi/engine/participants.rb +18 -14
- data/lib/samagotchi/engine/plugins.rb +8 -0
- data/lib/samagotchi/engine/questions.rb +3 -0
- data/lib/samagotchi/engine/recap.rb +1 -0
- data/lib/samagotchi/engine/session.rb +4 -0
- data/lib/samagotchi/engine/side_requests.rb +9 -0
- data/lib/samagotchi/engine/steering.rb +2 -0
- data/lib/samagotchi/engine/toolkit.rb +5 -0
- data/lib/samagotchi/engine/turn_end.rb +7 -0
- data/lib/samagotchi/engine/turn_helpers.rb +8 -0
- data/lib/samagotchi/engine/verify.rb +2 -0
- data/lib/samagotchi/engine.rb +8 -3
- data/lib/samagotchi/event_fanout.rb +22 -1
- data/lib/samagotchi/grants.rb +33 -22
- data/lib/samagotchi/guardrail_wiring.rb +23 -18
- data/lib/samagotchi/guardrails/approval_use.rb +59 -0
- data/lib/samagotchi/guardrails/approvals.rb +9 -11
- data/lib/samagotchi/guardrails/child_boundary.rb +1 -0
- data/lib/samagotchi/guardrails/gate.rb +10 -5
- data/lib/samagotchi/guardrails/implicit_writers.rb +1 -0
- data/lib/samagotchi/guardrails/pair_boundary.rb +6 -6
- data/lib/samagotchi/guardrails/participant_refusal.rb +33 -0
- data/lib/samagotchi/guardrails/review_paths.rb +2 -3
- data/lib/samagotchi/guardrails.rb +1 -1
- data/lib/samagotchi/image_store.rb +51 -12
- data/lib/samagotchi/kernel_loop.rb +7 -1
- data/lib/samagotchi/llm/stray_tool_call.rb +7 -4
- data/lib/samagotchi/llm_context_stale.rb +4 -1
- data/lib/samagotchi/llm_context_strategy.rb +2 -0
- data/lib/samagotchi/objectives.rb +1 -4
- data/lib/samagotchi/objectives_audit.rb +1 -1
- data/lib/samagotchi/objectives_track.rb +1 -1
- data/lib/samagotchi/owner_prompt.rb +3 -6
- data/lib/samagotchi/parent_report.rb +1 -0
- data/lib/samagotchi/participant_messages.rb +48 -4
- data/lib/samagotchi/participant_revise.rb +61 -0
- data/lib/samagotchi/participant_turn_mode.rb +50 -0
- data/lib/samagotchi/participant_uploads.rb +98 -0
- data/lib/samagotchi/participants.rb +21 -12
- data/lib/samagotchi/participants_watch.rb +2 -2
- data/lib/samagotchi/plugin/api.rb +2 -2
- data/lib/samagotchi/plugin/attached_context.rb +1 -1
- data/lib/samagotchi/plugin/context.rb +0 -4
- data/lib/samagotchi/plugin/sessions.rb +1 -25
- data/lib/samagotchi/reply_wait/poll.rb +5 -1
- data/lib/samagotchi/revise_anchor.rb +9 -0
- data/lib/samagotchi/run_options.rb +2 -3
- data/lib/samagotchi/send_command.rb +15 -10
- data/lib/samagotchi/session.rb +0 -3
- data/lib/samagotchi/session_access/contract.rb +1 -10
- data/lib/samagotchi/session_access/local.rb +10 -23
- data/lib/samagotchi/session_access/remote.rb +9 -20
- data/lib/samagotchi/session_access.rb +12 -16
- data/lib/samagotchi/session_chain.rb +4 -6
- data/lib/samagotchi/session_commands.rb +6 -3
- data/lib/samagotchi/session_continue.rb +1 -2
- data/lib/samagotchi/session_inbox.rb +20 -12
- data/lib/samagotchi/session_manager/delivery.rb +32 -5
- data/lib/samagotchi/session_manager/lifecycle.rb +12 -0
- data/lib/samagotchi/session_manager/listing.rb +5 -0
- data/lib/samagotchi/session_manager/spawn.rb +2 -2
- data/lib/samagotchi/session_manager/worker_command.rb +9 -0
- data/lib/samagotchi/session_participants.rb +12 -8
- data/lib/samagotchi/session_review.rb +5 -7
- data/lib/samagotchi/session_stores.rb +3 -1
- data/lib/samagotchi/share_command.rb +10 -12
- data/lib/samagotchi/share_terms.rb +41 -0
- data/lib/samagotchi/steer.rb +8 -14
- data/lib/samagotchi/system_prompt.rb +16 -25
- data/lib/samagotchi/terminal_ui/attach_launcher.rb +2 -1
- data/lib/samagotchi/terminal_ui/attached_loop/exit_commands.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/queueing.rb +1 -0
- data/lib/samagotchi/terminal_ui/attached_loop/sending.rb +2 -0
- data/lib/samagotchi/terminal_ui/formatting.rb +15 -17
- data/lib/samagotchi/terminal_ui/participant_commands.rb +2 -2
- data/lib/samagotchi/terminal_ui/status_row.rb +2 -2
- data/lib/samagotchi/terminal_ui.rb +1 -2
- data/lib/samagotchi/testing/sessions.rb +2 -10
- data/lib/samagotchi/tool_runner.rb +42 -9
- data/lib/samagotchi/toolkit.rb +4 -22
- data/lib/samagotchi/toolkit_suggest.rb +3 -3
- data/lib/samagotchi/tools/deferred_tools.rb +1 -0
- data/lib/samagotchi/tools/execute.rb +11 -45
- data/lib/samagotchi/tools/leftovers.rb +122 -0
- data/lib/samagotchi/tools/memory.rb +88 -25
- data/lib/samagotchi/tools/task_get.rb +1 -0
- data/lib/samagotchi/tools/task_list.rb +3 -2
- data/lib/samagotchi/tools/task_record.rb +6 -4
- data/lib/samagotchi/tools/task_runtime.rb +199 -20
- data/lib/samagotchi/tools/task_wait.rb +4 -3
- data/lib/samagotchi/turn_anchors.rb +0 -3
- data/lib/samagotchi/turn_context.rb +1 -1
- data/lib/samagotchi/turn_origin.rb +1 -1
- data/lib/samagotchi/turn_stages/context_judge.rb +4 -4
- data/lib/samagotchi/turn_stages/objectives.rb +2 -2
- data/lib/samagotchi/turn_stages/toolkit_suggestion.rb +2 -2
- data/lib/samagotchi/turn_stages/verify_anchors.rb +13 -1
- data/lib/samagotchi/update_hint.rb +3 -1
- data/lib/samagotchi/verify_anchor.rb +6 -0
- data/lib/samagotchi/verify_fresh.rb +1 -1
- data/lib/samagotchi/verify_fresh_origin.rb +13 -11
- data/lib/samagotchi/version.rb +1 -1
- data/lib/samagotchi/web/app.rb +45 -82
- data/lib/samagotchi/web/participant_access.rb +139 -40
- data/lib/samagotchi/web/participant_images.rb +185 -0
- data/lib/samagotchi/web/participant_review.rb +22 -142
- data/lib/samagotchi/web/participant_show.rb +241 -0
- data/lib/samagotchi/web/participant_stream_filter.rb +25 -2
- data/lib/samagotchi/web/participant_view.rb +334 -27
- data/lib/samagotchi/web/participants_admin.rb +21 -40
- data/lib/samagotchi/web/public/annotate_bar.css +1 -2
- data/lib/samagotchi/web/public/annotate_bar.js +1 -2
- data/lib/samagotchi/web/public/app.js +126 -132
- data/lib/samagotchi/web/public/block_host.js +7 -4
- data/lib/samagotchi/web/public/bubbles.js +9 -1
- data/lib/samagotchi/web/public/cards_offscreen.js +69 -0
- data/lib/samagotchi/web/public/chip_popover.js +5 -4
- data/lib/samagotchi/web/public/claim_link.js +4 -4
- data/lib/samagotchi/web/public/composer.css +4 -6
- data/lib/samagotchi/web/public/composer_mode.js +11 -6
- data/lib/samagotchi/web/public/composer_mount.js +4 -4
- data/lib/samagotchi/web/public/ctx.js +12 -3
- data/lib/samagotchi/web/public/data.js +2 -10
- data/lib/samagotchi/web/public/delivery_line.js +49 -63
- data/lib/samagotchi/web/public/history_shape.js +5 -1
- data/lib/samagotchi/web/public/images.js +7 -1
- data/lib/samagotchi/web/public/index.html +50 -34
- data/lib/samagotchi/web/public/info_bar_model.js +2 -1
- data/lib/samagotchi/web/public/live_turn.js +1 -1
- data/lib/samagotchi/web/public/markdown_place.js +5 -4
- data/lib/samagotchi/web/public/owner_claim.js +5 -5
- data/lib/samagotchi/web/public/owner_verify.js +0 -2
- data/lib/samagotchi/web/public/participant_bar.js +107 -0
- data/lib/samagotchi/web/public/participant_main.js +289 -0
- data/lib/samagotchi/web/public/participant_model.js +5 -292
- data/lib/samagotchi/web/public/participant_names.js +17 -8
- data/lib/samagotchi/web/public/participant_revise.js +66 -0
- data/lib/samagotchi/web/public/participants_panel.js +32 -74
- data/lib/samagotchi/web/public/question_cards.js +14 -3
- data/lib/samagotchi/web/public/refs.js +53 -36
- data/lib/samagotchi/web/public/reload_check.js +70 -14
- data/lib/samagotchi/web/public/revise_stack.js +21 -10
- data/lib/samagotchi/web/public/send_turn.js +28 -29
- data/lib/samagotchi/web/public/session_actions.js +4 -45
- data/lib/samagotchi/web/public/session_fields.js +1 -2
- data/lib/samagotchi/web/public/session_state.js +12 -7
- data/lib/samagotchi/web/public/session_sync.js +9 -2
- data/lib/samagotchi/web/public/session_view.js +14 -5
- data/lib/samagotchi/web/public/settings_panel.js +4 -18
- data/lib/samagotchi/web/public/stage_answer.js +56 -0
- data/lib/samagotchi/web/public/stage_asking.js +7 -5
- data/lib/samagotchi/web/public/stage_cloud.js +93 -0
- data/lib/samagotchi/web/public/stage_dom.js +100 -0
- data/lib/samagotchi/web/public/stage_handoff.js +154 -0
- data/lib/samagotchi/web/public/stage_owner_wait.js +35 -0
- data/lib/samagotchi/web/public/stage_pager.js +59 -0
- data/lib/samagotchi/web/public/stage_quiet_clock.js +52 -0
- data/lib/samagotchi/web/public/stage_view.js +103 -410
- data/lib/samagotchi/web/public/stage_waiting.js +74 -6
- data/lib/samagotchi/web/public/start_page.js +12 -33
- data/lib/samagotchi/web/public/start_settings.js +24 -78
- data/lib/samagotchi/web/public/start_toolkit.js +6 -10
- data/lib/samagotchi/web/public/storage.js +22 -0
- data/lib/samagotchi/web/public/stream_handlers.js +3 -10
- data/lib/samagotchi/web/public/tokens.css +1 -1
- data/lib/samagotchi/web/public/turn_block.js +2 -5
- data/lib/samagotchi/web/public/turn_events.js +30 -12
- data/lib/samagotchi/web/public/turn_html.js +9 -2
- data/lib/samagotchi/web/public/turn_pieces.js +3 -4
- data/lib/samagotchi/web/public/turn_range.js +1 -2
- data/lib/samagotchi/web/public/verify_target.js +2 -4
- data/lib/samagotchi/web/public/viewer.js +59 -0
- data/lib/samagotchi/web/public/viewer_self.js +59 -0
- data/lib/samagotchi/web/public/working_set.js +11 -5
- data/lib/samagotchi/web/public/working_set_view.js +53 -8
- data/lib/samagotchi/web/public/ws_cards.js +89 -0
- data/lib/samagotchi/web/public/ws_peek.js +106 -0
- data/lib/samagotchi/web/public/ws_preview.css +126 -0
- data/lib/samagotchi/web/public/ws_reader.js +319 -0
- data/lib/samagotchi/web/public/ws_timeline.js +200 -0
- data/lib/samagotchi/web/public/ws_way_in.js +25 -0
- data/lib/samagotchi/web/qr.rb +1 -1
- data/lib/samagotchi/web/session_control.rb +42 -15
- data/lib/samagotchi/web/session_create.rb +6 -72
- data/lib/samagotchi/web/session_show.rb +75 -28
- data/lib/samagotchi/web/session_summary.rb +1 -4
- data/lib/samagotchi/web/verify_fresh_routes.rb +8 -7
- data/lib/samagotchi/web/viewer.rb +70 -0
- data/lib/samagotchi/web/working_set_routes.rb +132 -0
- data/lib/samagotchi/worker.rb +35 -28
- data/lib/samagotchi/worker_inbound.rb +4 -3
- data/lib/samagotchi/worker_link.rb +17 -0
- data/lib/samagotchi/working_set.rb +322 -11
- metadata +32 -13
- data/lib/samagotchi/guardrails/review_boundary.rb +0 -99
- data/lib/samagotchi/participant_mode.rb +0 -86
- data/lib/samagotchi/review_apply.rb +0 -131
- data/lib/samagotchi/review_command.rb +0 -123
- data/lib/samagotchi/review_start.rb +0 -196
- data/lib/samagotchi/web/public/participant.html +0 -218
- data/lib/samagotchi/web/public/participant.js +0 -719
- data/lib/samagotchi/web/public/participant_annotate.js +0 -76
- data/lib/samagotchi/web/public/review_apply.js +0 -34
- data/lib/samagotchi/web/public/review_history.js +0 -72
- data/lib/samagotchi/web/public/review_start.js +0 -55
- data/lib/samagotchi/web/public/tools_overview.js +0 -42
|
@@ -13,15 +13,23 @@
|
|
|
13
13
|
// fallback, data-undrawn): 0 unless chi web missed one. Fire-and-forget: no toast, no
|
|
14
14
|
// store write, a failure is dropped.
|
|
15
15
|
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
16
|
+
// Compared: the turn's own cards and questions too. A drawn turn already
|
|
17
|
+
// renders its plugin cards (turn_block.js), and the snapshot's questions and
|
|
18
|
+
// an undrawn turn's entries are placed into the offscreen holder by
|
|
19
|
+
// cards_offscreen.js, the same placer the page uses with inert hooks. Only
|
|
20
|
+
// entries CardStore attributes to this turn (of_turn) are compared; a card
|
|
21
|
+
// the turn doesn't own (another turn's, a between-turn notice) is dropped on
|
|
22
|
+
// both sides, and a question the read attributes to no turn and stamps to no
|
|
23
|
+
// opening (an older worker) is dropped as well, since nothing places it.
|
|
24
|
+
// What a card's equality means: its id and title, or a question's summary line
|
|
25
|
+
// — not its body, its buttons, its fold or the tag it is drawn in.
|
|
26
|
+
// Between-turn cards and notices are out of scope (the e2e reload checks
|
|
27
|
+
// cover them).
|
|
20
28
|
import { compareShapes, historyShape } from "./history_shape.js";
|
|
29
|
+
import { isCard, splitSnapshotCards } from "./card.js";
|
|
21
30
|
import { turnElements } from "./turn_range.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const OPENING = "[data-turn-id], [data-opening-id]";
|
|
31
|
+
// The opening of a turn (the stage's hand-off reads it too).
|
|
32
|
+
import { OPENING } from "./stage_handoff.js";
|
|
25
33
|
// Not the turn's: the lines queued for after it (they open the next turns).
|
|
26
34
|
const NOT_THE_TURNS = ".bubble.user.queued, .bubble.command.queued";
|
|
27
35
|
|
|
@@ -29,8 +37,42 @@ function openingId(el) {
|
|
|
29
37
|
return el?.dataset?.turnId || el?.dataset?.openingId || null;
|
|
30
38
|
}
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
// The snapshot entries this turn owns (CardStore's of_turn): a drawn turn
|
|
41
|
+
// already renders its cards, so only its questions come from the placer; an
|
|
42
|
+
// undrawn turn has all of them placed, as a reload places them. Entries the
|
|
43
|
+
// page shows elsewhere, the running turn's and the ones that came during it
|
|
44
|
+
// are out (splitSnapshotCards), as in session_view.js.
|
|
45
|
+
function turnEntries(cards, capabilities, turnId, drawn) {
|
|
46
|
+
const placed = splitSnapshotCards(cards, capabilities).placed.filter((entry) => entry?.of_turn === turnId);
|
|
47
|
+
return drawn ? placed.filter((entry) => entry?.type === "question") : placed;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// A question the read attributes to no turn (an older worker: no of_turn, and
|
|
51
|
+
// no opening it came after, or one stamped to this very turn) has nothing to
|
|
52
|
+
// place it from, so its card is left out of the compare. Only entries that
|
|
53
|
+
// could belong to this turn count: one stamped to another turn does not
|
|
54
|
+
// silence questions here.
|
|
55
|
+
function looseQuestions(cards, turnId) {
|
|
56
|
+
return (Array.isArray(cards) ? cards : []).some((entry) => entry?.type === "question"
|
|
57
|
+
&& entry?.of_turn == null && (entry?.opening_id == null || String(entry.opening_id) === String(turnId)));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The ids of the snapshot's cards that are not this turn's.
|
|
61
|
+
function foreignIds(cards, turnId) {
|
|
62
|
+
return new Set((Array.isArray(cards) ? cards : [])
|
|
63
|
+
.filter((entry) => isCard(entry) && entry?.of_turn !== turnId)
|
|
64
|
+
.map((entry) => String(entry.id ?? "")));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// This turn's items only: a card of another turn or between turns is dropped
|
|
68
|
+
// by id; a question the worker didn't attribute to a turn (an older worker)
|
|
69
|
+
// has nothing to place it from, so questions are dropped on both sides.
|
|
70
|
+
function turnOnly(shape, foreign, questions) {
|
|
71
|
+
return shape.filter((item) => {
|
|
72
|
+
if (item.kind === "card") return !foreign.has(item.id);
|
|
73
|
+
if (item.kind === "question") return questions;
|
|
74
|
+
return true;
|
|
75
|
+
});
|
|
34
76
|
}
|
|
35
77
|
|
|
36
78
|
// @param enabled () => whether the check is on (the body's attribute)
|
|
@@ -39,8 +81,13 @@ function withoutCards(shape) {
|
|
|
39
81
|
// turn started streaming)
|
|
40
82
|
// @param read (id) => the session as a reload reads it (the full GET)
|
|
41
83
|
// @param render (data) => that read drawn as a reload draws it (a fragment)
|
|
84
|
+
// @param place (holder, entries) puts the turn's snapshot entries into that
|
|
85
|
+
// holder as a reload's placement would (cards_offscreen.js); without it,
|
|
86
|
+
// cards and questions are dropped from both sides
|
|
87
|
+
// @param capabilities () => the page's capabilities (which notices it shows
|
|
88
|
+
// elsewhere)
|
|
42
89
|
// @param post (id, body) => the counts to chi web
|
|
43
|
-
export function createReloadCheck({ enabled, sessionId, running, read, render, post }) {
|
|
90
|
+
export function createReloadCheck({ enabled, sessionId, running, read, render, place = null, capabilities = () => null, post }) {
|
|
44
91
|
// The hand-off's pieces (stage_view.js onHandedOff), in their order;
|
|
45
92
|
// +immediate+: another turn took the stage at once.
|
|
46
93
|
async function handedOff({ pieces = [], immediate = false } = {}) {
|
|
@@ -56,15 +103,24 @@ export function createReloadCheck({ enabled, sessionId, running, read, render, p
|
|
|
56
103
|
// failed turn hands off at once, and its timing line takes the turn
|
|
57
104
|
// record's figure when its own re-read lands (refreshTimingFromSession),
|
|
58
105
|
// which started at the turn's end, before this one.
|
|
59
|
-
|
|
106
|
+
// Whether the read had a drawing for the turn (turn drawings, P2): a
|
|
107
|
+
// drawn one already renders its own cards, an undrawn one has them
|
|
108
|
+
// placed after the render.
|
|
109
|
+
const drawn = !!data?.turn_drawings?.[turnId];
|
|
110
|
+
const entries = place ? turnEntries(data.cards, capabilities(), turnId, drawn) : [];
|
|
111
|
+
// A question the read can't place for this turn (see looseQuestions) is
|
|
112
|
+
// left out of the compare on both sides.
|
|
113
|
+
const questions = !!place && !looseQuestions(data.cards, turnId);
|
|
114
|
+
const shapeOf = (shape) => turnOnly(shape, foreignIds(data.cards, turnId), questions);
|
|
115
|
+
const live = shapeOf(historyShape(rest.filter((el) => !el.matches?.(NOT_THE_TURNS))));
|
|
60
116
|
const holder = document.createElement("div");
|
|
61
117
|
holder.append(render(data));
|
|
118
|
+
// The turn's own cards and questions, where a reload would put them.
|
|
119
|
+
if (place) place(holder, entries);
|
|
62
120
|
const reopened = [...holder.querySelectorAll(OPENING)].find((el) => openingId(el) === turnId);
|
|
63
|
-
const reloaded = reopened ?
|
|
121
|
+
const reloaded = reopened ? shapeOf(historyShape(turnElements(reopened, { container: holder }))) : [];
|
|
64
122
|
const { same, kinds, excused, explained } = reopened ? compareShapes(live, reloaded)
|
|
65
123
|
: { same: false, kinds: ["prompt"], excused: [], explained: false };
|
|
66
|
-
// Whether the read had a drawing for the turn (turn drawings, P2).
|
|
67
|
-
const drawn = !!data?.turn_drawings?.[turnId];
|
|
68
124
|
const undrawn = holder.querySelectorAll("[data-undrawn]").length;
|
|
69
125
|
await post(id, { turn_id: turnId, same, kinds, excused, explained, drawn, undrawn });
|
|
70
126
|
} catch (_) {
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
// answer's place (revise_switch.js; view only, not stored);
|
|
17
17
|
// - the final answer of an ended turn (verify_target.js's rule, a delegate
|
|
18
18
|
// report's reply excluded), unstacked or a stack's top, and not a Verify
|
|
19
|
-
// turn's, gets a Revise button: it arms the composer (app.js).
|
|
19
|
+
// turn's, gets a Revise button: it arms the composer (app.js). A
|
|
20
|
+
// participant's page asks mayRevise too (participant_revise.js: their own
|
|
21
|
+
// answers only); the stubs, the chip and the switcher are everyone's.
|
|
20
22
|
//
|
|
21
23
|
// The stamps live on the history's prompt bubbles (data-revises: a reload's
|
|
22
24
|
// render, a live turn_completed's revises), so the stacks are read from the
|
|
@@ -111,7 +113,8 @@ export function versionChipText(count, at = count - 1) {
|
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
// The composer's chip: "Revising: ‹label›", or the refusal (+unavailable+:
|
|
114
|
-
// the worker predates Revise turns
|
|
116
|
+
// the worker predates Revise turns; +text+ its words, a participant's page
|
|
117
|
+
// gives its own: participant_revise.js).
|
|
115
118
|
export const REVISE_UNAVAILABLE = "restart this session to use Revise";
|
|
116
119
|
|
|
117
120
|
// The feature gate (app.js featureGates): a live worker without the "revise"
|
|
@@ -121,16 +124,16 @@ export const REVISE_UNAVAILABLE = "restart this session to use Revise";
|
|
|
121
124
|
export function reviseWorkerUnavailable(workerFeatures, bridgeUp) {
|
|
122
125
|
return workerPredates(workerFeatures, bridgeUp, "revise");
|
|
123
126
|
}
|
|
124
|
-
export function reviseChipText(label, { unavailable = false } = {}) {
|
|
125
|
-
if (unavailable) return `Revise: ${
|
|
127
|
+
export function reviseChipText(label, { unavailable = false, text = REVISE_UNAVAILABLE } = {}) {
|
|
128
|
+
if (unavailable) return `Revise: ${text}`;
|
|
126
129
|
return label ? `Revising: ${label}` : "Revising the answer";
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
// The composer's chip (app.js renders it into its own element): the armed
|
|
130
133
|
// Revise's words and ✕ (+onClear+), or nothing when +anchor+ is null.
|
|
131
|
-
export function reviseChipTemplate(anchor, { unavailable = false, onClear } = {}) {
|
|
134
|
+
export function reviseChipTemplate(anchor, { unavailable = false, text = REVISE_UNAVAILABLE, onClear } = {}) {
|
|
132
135
|
if (!anchor) return nothing;
|
|
133
|
-
return html`<span class=${unavailable ? "revise-chip refused" : "revise-chip"} title=${unavailable ?
|
|
136
|
+
return html`<span class=${unavailable ? "revise-chip refused" : "revise-chip"} title=${unavailable ? text : `This message rewrites that answer: ${anchor.label || ""}`}><span class="revise-chip-text">${reviseChipText(anchor.label, { unavailable, text })}</span><button type="button" class="revise-chip-clear" aria-label="Don't revise" title="Don't revise (send as a plain message)" @click=${onClear}>✕</button></span>`;
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
// An answer's label (the stub's, the chip's): its first line.
|
|
@@ -190,12 +193,18 @@ export function historyTurns(historyEl) {
|
|
|
190
193
|
// @param verifyTurn (turnId) => whether that turn was a Verify turn (beyond
|
|
191
194
|
// its prompt's data-verify: a verdict's check_turn_id)
|
|
192
195
|
// @param unavailable () => the worker predates Revise (the feature gate)
|
|
196
|
+
// @param unavailableText the button's title while +unavailable+ (a
|
|
197
|
+
// participant's page: its own words, participant_revise.js)
|
|
193
198
|
// @param armed () => the turn id the composer's Revise is armed with, or null
|
|
194
199
|
// @param onRevise ({turn_id, label}) the Revise button
|
|
200
|
+
// @param mayRevise (turn, turns) => whether this viewer may revise +turn+
|
|
201
|
+
// (one of historyTurns' +turns+): false draws no button, the stack's
|
|
202
|
+
// switcher and chip stay
|
|
195
203
|
// @return {decorate()} (the observer runs it; app.js after a change it reads)
|
|
196
204
|
export function installReviseStacks({
|
|
197
205
|
historyEl, sessionId, projectRoot = () => null, running = () => null, verifyTurn = () => false,
|
|
198
|
-
unavailable = () => false, armed = () => null, onRevise = () => {},
|
|
206
|
+
unavailable = () => false, unavailableText = REVISE_UNAVAILABLE, armed = () => null, onRevise = () => {},
|
|
207
|
+
mayRevise = () => true,
|
|
199
208
|
}) {
|
|
200
209
|
const stubs = new Map();
|
|
201
210
|
const rows = new Map();
|
|
@@ -244,14 +253,14 @@ export function installReviseStacks({
|
|
|
244
253
|
return row;
|
|
245
254
|
}
|
|
246
255
|
|
|
247
|
-
function drawRow(row, { id, answer, chain, openings }) {
|
|
256
|
+
function drawRow(row, { id, answer, chain, openings, may }) {
|
|
248
257
|
const off = unavailable();
|
|
249
258
|
const isArmed = armed() === id;
|
|
250
259
|
const at = chain ? (shown.get(id) ?? chain.length - 1) : 0;
|
|
251
260
|
const versions = chain
|
|
252
261
|
? html`<details class="stack-versions"><summary>${versionChipText(chain.length, at)}</summary><div class="stack-versions-list" role="list">${chain.map((vid, k) => html`<button type="button" role="listitem" class=${vid === id ? "stack-version current" : "stack-version"} data-stack-pick=${vid} ?disabled=${vid === id}><span class="stack-version-n">v${k + 1}</span> ${promptLabel(openings.get(vid))}</button>`)}</div></details>`
|
|
253
262
|
: nothing;
|
|
254
|
-
const button = html`<button type="button" class=${isArmed ? "revise-btn armed" : "revise-btn"} data-revise=${id} ?disabled=${off} title=${off ?
|
|
263
|
+
const button = may ? html`<button type="button" class=${isArmed ? "revise-btn armed" : "revise-btn"} data-revise=${id} ?disabled=${off} title=${off ? unavailableText : "Rewrite this answer: your next message revises it, and the earlier version folds away"}>${isArmed ? "Revising…" : "Revise"}</button>` : nothing;
|
|
255
264
|
row.classList.toggle("stacked", !!chain);
|
|
256
265
|
render(html`${chain ? switcherTemplate(id, at, chain.length) : nothing}${versions}${button}`, row);
|
|
257
266
|
rowAnswer.set(row, answer);
|
|
@@ -302,9 +311,11 @@ export function installReviseStacks({
|
|
|
302
311
|
if (!turn.id || turn.wake || !answer || answer.matches(UNFINISHED) || turn.stopped) continue;
|
|
303
312
|
if (turn.prompt?.hasAttribute("data-verify") || verifyTurn(turn.id)) continue;
|
|
304
313
|
if (run && (turn === lastOpening || (run.turnId && run.turnId === turn.id))) continue;
|
|
314
|
+
const may = !!mayRevise(turn, turns);
|
|
315
|
+
if (!may && !tops.has(turn.id)) continue;
|
|
305
316
|
const row = rowFor(turn.id, answer);
|
|
306
317
|
keepRows.add(turn.id);
|
|
307
|
-
drawRow(row, { id: turn.id, answer, chain: tops.get(turn.id) || null, openings });
|
|
318
|
+
drawRow(row, { id: turn.id, answer, chain: tops.get(turn.id) || null, openings, may });
|
|
308
319
|
}
|
|
309
320
|
syncViews(tops, keepRows, new Map(turns.filter((t) => t.id).map((t) => [t.id, t.answer])));
|
|
310
321
|
// A divider between two folded stubs folds into the later one.
|
|
@@ -26,44 +26,39 @@ import { composerAfterAck, dropEarlyRestores, restoreOnAck } from "./restore.js"
|
|
|
26
26
|
// +addCommandBubble(view)+; +addCreatedSession(created)+, +select(id)+,
|
|
27
27
|
// +showNotice(text)+,
|
|
28
28
|
// +followWokenWorker()+, +refreshHistory()+, +leaveGoneSession(id, why)+,
|
|
29
|
-
// +runCommand(command)+ (composer.js send), +toast(text, action, options)+;
|
|
29
|
+
// +runCommand(command)+ (composer.js send; null: a viewer without session commands, the line goes as a turn), +toast(text, action, options)+;
|
|
30
|
+
// +closesOn(error)+: a participant's page takes a refusal that closes its
|
|
31
|
+
// composer (participant_main.js; true: taken, the line stays typed); null else;
|
|
30
32
|
// +alert+: the browser's.
|
|
33
|
+
// The refused Revise sends whose text and chip stay (a failed line says why):
|
|
34
|
+
// a worker from before Revise turns, and a participant's of an answer that
|
|
35
|
+
// isn't theirs or that someone else's turn came after.
|
|
36
|
+
const REVISE_REFUSALS = ["revise_unavailable", "revise_not_own", "revise_overtaken"];
|
|
37
|
+
|
|
31
38
|
export function createSendTurn({
|
|
32
39
|
session, store, running, clientId, sentIds, earlyRestores, api, dir, startPage, takeDelivery, composer,
|
|
33
40
|
verify = () => null, clearVerify = () => {}, restoreVerify = () => {},
|
|
34
41
|
revise = () => null, clearRevise = () => {}, restoreRevise = () => {},
|
|
35
42
|
historyEl, turnDom, makeUserBubble, bubbleById, addCommandBubble,
|
|
36
43
|
addCreatedSession, select, showNotice, followWokenWorker, refreshHistory,
|
|
37
|
-
leaveGoneSession, runCommand, toast, alert = (text) => globalThis.alert(text),
|
|
44
|
+
leaveGoneSession, runCommand, toast, closesOn = null, alert = (text) => globalThis.alert(text),
|
|
38
45
|
}) {
|
|
39
46
|
const promptEl = composer.el;
|
|
40
47
|
const actionBtn = composer.button;
|
|
41
48
|
|
|
42
|
-
//
|
|
43
|
-
// a delivery-line link: cut or queue); else the armed one; a typed /cut or
|
|
44
|
-
// /queue wins over both.
|
|
45
|
-
async function createReviewOnly() {
|
|
46
|
-
actionBtn.disabled = true;
|
|
47
|
-
try {
|
|
48
|
-
const s = await api.createIdleSession({ dir, model: startPage.chosenModel(), ...startPage.newChoices() });
|
|
49
|
-
startPage.clearChoices();
|
|
50
|
-
addCreatedSession(s);
|
|
51
|
-
await select(s.id);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
refused(e);
|
|
54
|
-
} finally {
|
|
55
|
-
actionBtn.disabled = false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// A create's refusal: the review files' in the ⚙ panel's review view, a
|
|
60
|
-
// picked kit's in the 🧰 list, else an alert.
|
|
49
|
+
// A create's refusal: a picked kit's in the 🧰 list, else an alert.
|
|
61
50
|
function refused(e) {
|
|
62
|
-
if (e?.code === "invalid_review" && startPage.reviewRefused?.(e.message)) return;
|
|
63
51
|
if (e?.code === "toolkit_refused" && startPage.toolkitRefused?.(e.message)) return;
|
|
64
52
|
alert(e.message);
|
|
65
53
|
}
|
|
66
54
|
|
|
55
|
+
// The line being sent ({to, line}) until its /turn answers: a second
|
|
56
|
+
// Enter on a slow link (the text still in the box) doesn't send it again.
|
|
57
|
+
let inFlight = null;
|
|
58
|
+
|
|
59
|
+
// +delivery+: the composer's choice for a running turn (Alt+Enter: queue;
|
|
60
|
+
// a delivery-line link: cut or queue); else the armed one; a typed /cut or
|
|
61
|
+
// /queue wins over both.
|
|
67
62
|
async function send({ delivery: chosen = null } = {}) {
|
|
68
63
|
if (store.current.owner === "tui") return;
|
|
69
64
|
// A fresh link's pick first: its /model is queued in the worker once
|
|
@@ -71,9 +66,6 @@ export function createSendTurn({
|
|
|
71
66
|
const pick = startPage.pendingPick();
|
|
72
67
|
if (pick) await pick;
|
|
73
68
|
let prompt = turnText(promptEl.value, composer.chips());
|
|
74
|
-
// The start page's review files with nothing typed: the review session
|
|
75
|
-
// alone, idle.
|
|
76
|
-
if (!prompt && !session() && startPage.reviewSubjects?.().length) return createReviewOnly();
|
|
77
69
|
if (!prompt) return;
|
|
78
70
|
const armed = takeDelivery();
|
|
79
71
|
// An image-only send's text is its placeholders: not for ↑.
|
|
@@ -110,8 +102,10 @@ export function createSendTurn({
|
|
|
110
102
|
composer.clear();
|
|
111
103
|
return;
|
|
112
104
|
}
|
|
113
|
-
if (route.command) return runCommand(route.command);
|
|
114
|
-
|
|
105
|
+
if (route.command && runCommand) return runCommand(route.command);
|
|
106
|
+
// A viewer without session commands (viewer.js): the line goes as a turn, and the worker decides.
|
|
107
|
+
prompt = route.command ?? route.send;
|
|
108
|
+
if (inFlight && inFlight.to === session() && inFlight.line === line) return;
|
|
115
109
|
const isRunning = running() && !!session();
|
|
116
110
|
const delivery = route.delivery || (isRunning ? chosen || armed : null);
|
|
117
111
|
const hint = historyEl.querySelector(".hint");
|
|
@@ -134,6 +128,8 @@ export function createSendTurn({
|
|
|
134
128
|
// The session the line goes to: the page may switch to another while an
|
|
135
129
|
// image uploads or the turn is sent, and what follows stays with this one.
|
|
136
130
|
const sentTo = session();
|
|
131
|
+
const flight = { to: sentTo, line };
|
|
132
|
+
inFlight = flight;
|
|
137
133
|
try {
|
|
138
134
|
await uploadChips(sending, sentTo, { upload: api.uploadImage });
|
|
139
135
|
const verifyAnchor = verify();
|
|
@@ -208,13 +204,16 @@ export function createSendTurn({
|
|
|
208
204
|
// A stale tab sent into a session deleted meanwhile: the start page
|
|
209
205
|
// says so, and the line stays in the composer.
|
|
210
206
|
if (e.code === "not_found") return leaveGoneSession(sentTo, "not_found");
|
|
207
|
+
if (sentTo === session() && closesOn?.(e)) return;
|
|
211
208
|
// A /queue to a worker that can't queue (it would steer): its words, the text kept.
|
|
212
209
|
if (e.code === "delivery_unavailable" && sentTo === session()) return addCommandBubble({ label: null, line, text: e.body?.detail || e.message, failed: true });
|
|
213
210
|
// A Revise to a worker from before Revise turns (the page's gate saw
|
|
214
|
-
// none yet)
|
|
215
|
-
|
|
211
|
+
// none yet), or a participant's of an answer not theirs or overtaken
|
|
212
|
+
// since the tap: the server's words, the text and the chip kept.
|
|
213
|
+
if (REVISE_REFUSALS.includes(e.code) && sentTo === session()) return addCommandBubble({ label: null, line, text: e.body?.detail || e.message, failed: true });
|
|
216
214
|
toast(cantText("send", e), null, { sticky: true });
|
|
217
215
|
} finally {
|
|
216
|
+
if (inFlight === flight) inFlight = null;
|
|
218
217
|
actionBtn.disabled = store.current.owner === "tui";
|
|
219
218
|
composer.focus();
|
|
220
219
|
}
|
|
@@ -9,10 +9,10 @@ import { inTree } from "./sessions_list.js";
|
|
|
9
9
|
//
|
|
10
10
|
// Hooks: +selected()+ the open session's id or null; +store+ the page's
|
|
11
11
|
// session store (session_store.js: Stop's status; touch("infoBar") for the
|
|
12
|
-
// continue
|
|
12
|
+
// continue in-flight set, which it doesn't hold); +sessions()+ /
|
|
13
13
|
// +setSessions(list)+ the page's list (the store's: a new list redraws the
|
|
14
14
|
// lists and the bar);
|
|
15
|
-
// +api+: {continueSession,
|
|
15
|
+
// +api+: {continueSession, archiveSession, unarchiveSession,
|
|
16
16
|
// deleteSession, stopSession, sessionHolds, stopSessionHolds} (data.js);
|
|
17
17
|
// +eventsLive()+ the hub's stream is open (else
|
|
18
18
|
// +refresh()+ fetches the list);
|
|
@@ -23,13 +23,6 @@ import { inTree } from "./sessions_list.js";
|
|
|
23
23
|
// (that draft back, never over newer text), +closeLiveStream()+ (the live
|
|
24
24
|
// stream's close, the stream left as it is) and +workerGone(id)+ the page's.
|
|
25
25
|
// +alert+ / +confirm+: the browser's.
|
|
26
|
-
// The toast after Start review: the new session, where it starts from, and
|
|
27
|
-
// the model warning when there is one.
|
|
28
|
-
export function reviewStartedText(id, created) {
|
|
29
|
-
const warning = created.model_warning ? ` (${created.model_warning})` : "";
|
|
30
|
-
return `Review ${created.id.slice(0, 8)} started from ${id.slice(0, 8)}'s recap; ${id.slice(0, 8)} keeps running${warning}. Invite someone to it.`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
26
|
export function createSessionActions({
|
|
34
27
|
selected, store, sessions, setSessions, api, eventsLive, refresh,
|
|
35
28
|
select, clearSelection, showNotice, toast, addCreatedSession, fillOpener, restoreDraft, closeLiveStream, workerGone,
|
|
@@ -78,7 +71,7 @@ export function createSessionActions({
|
|
|
78
71
|
// +stopHolds+ is the sheet's "Stop all": the worker's stop-all step, then
|
|
79
72
|
// the stop. A delegate or a background task outlives the worker either way
|
|
80
73
|
// (docs/sessions.md, "Stopping a worker"), which is why the sheet says so.
|
|
81
|
-
// One Stop per session at a time (as
|
|
74
|
+
// One Stop per session at a time (as continuingIds): a second tap while the
|
|
82
75
|
// holds read (or the stop) is under way would be a second confirm.
|
|
83
76
|
const stopAsks = new Set();
|
|
84
77
|
|
|
@@ -182,40 +175,6 @@ export function createSessionActions({
|
|
|
182
175
|
}
|
|
183
176
|
}
|
|
184
177
|
|
|
185
|
-
// Start review: a review fork of the open session (its recap, not its
|
|
186
|
-
// transcript; it keeps running), opened, with Invite in the toast (the new
|
|
187
|
-
// session's participants chip). One per session at a time.
|
|
188
|
-
// +onError(text)+: says a refusal where it was asked (the participants
|
|
189
|
-
// panel), true when it did; else the toast says it.
|
|
190
|
-
// @return the created session, or null (none open, one under way, refused)
|
|
191
|
-
const reviewingIds = new Set();
|
|
192
|
-
|
|
193
|
-
async function reviewSelected({ onError = null } = {}) {
|
|
194
|
-
if (!selected() || reviewingIds.has(selected())) return null;
|
|
195
|
-
const id = selected();
|
|
196
|
-
reviewingIds.add(id);
|
|
197
|
-
store.touch("infoBar");
|
|
198
|
-
try {
|
|
199
|
-
const created = await api.startReview(id);
|
|
200
|
-
addCreatedSession(created);
|
|
201
|
-
if (selected() === id) await select(created.id);
|
|
202
|
-
// After the toast's own click is done: the panel would take it as a
|
|
203
|
-
// click outside and close.
|
|
204
|
-
const openPanel = () => globalThis.document?.querySelector("#infoText .participants-chip")?.click();
|
|
205
|
-
const invite = { label: "Invite", run: () => setTimeout(openPanel, 0) };
|
|
206
|
-
toast(reviewStartedText(id, created), selected() === created.id ? invite : { label: "Open", run: () => select(created.id) },
|
|
207
|
-
{ sticky: !!created.model_warning });
|
|
208
|
-
return created;
|
|
209
|
-
} catch (e) {
|
|
210
|
-
const text = `Can't start a review of ${id.slice(0, 8)}: ${e.message}`;
|
|
211
|
-
if (!onError?.(text)) toast(text, null, { sticky: true });
|
|
212
|
-
return null;
|
|
213
|
-
} finally {
|
|
214
|
-
reviewingIds.delete(id);
|
|
215
|
-
store.touch("infoBar");
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
178
|
// ── Archive ───────────────────────────────────────────────────────────────
|
|
220
179
|
// Archive hides a session (and its delegates) from the strip and the list,
|
|
221
180
|
// kept for good; "include archived" in all sessions finds it. No confirm:
|
|
@@ -286,7 +245,7 @@ export function createSessionActions({
|
|
|
286
245
|
}
|
|
287
246
|
|
|
288
247
|
return {
|
|
289
|
-
confirmDelete, leaveGoneSession, stopSelected, continueSelected,
|
|
248
|
+
confirmDelete, leaveGoneSession, stopSelected, continueSelected, archiveOne, setArchived, toggleArchiveSelected,
|
|
290
249
|
// The sessions whose Continue is under way (the info bar's button).
|
|
291
250
|
continuing: continuingIds,
|
|
292
251
|
// The session this tab is stopping, or null.
|
|
@@ -42,7 +42,6 @@ export const FIELDS = {
|
|
|
42
42
|
promptNotes: { source: (d) => list(d.session?.prompt_notes), redraws: ["infoBar"], writers: "readTurnEnd" },
|
|
43
43
|
parentId: { redraws: ["infoBar"], writers: "the payload" },
|
|
44
44
|
continues: { redraws: ["infoBar"], writers: "the payload" },
|
|
45
|
-
review: { redraws: ["infoBar"], writers: "the payload" },
|
|
46
45
|
verdicts: {
|
|
47
46
|
source: (d) => list(d.session?.verdicts),
|
|
48
47
|
redraws: [],
|
|
@@ -54,7 +53,7 @@ export const FIELDS = {
|
|
|
54
53
|
writers: "owner_verify.js placeVerdict (settleRunning); verdict_fresh.js startFresh pushes in place (D8)",
|
|
55
54
|
},
|
|
56
55
|
createdAt: { redraws: ["infoBar"], writers: "the payload" },
|
|
57
|
-
ctxPct: { redraws: ["infoBar"], writers: "stream_handlers.js (generation_chunk, context_status)" },
|
|
56
|
+
ctxPct: { redraws: ["infoBar"], writers: "session_state.js sessionStateFrom (the payload's context_status, else the saved fill), stream_handlers.js (generation_chunk, context_status)" },
|
|
58
57
|
ctxWindow: { redraws: ["infoBar"], writers: "stream_handlers.js (generation_started, context_status)" },
|
|
59
58
|
ctxWindowSource: { redraws: ["infoBar"], writers: "stream_handlers.js (generation_started, context_status)" },
|
|
60
59
|
ctxUnknownAfterSwitch: { redraws: ["infoBar"], writers: "stream_handlers.js (generation_started, context_status)" },
|
|
@@ -23,8 +23,6 @@ export function emptySessionState() {
|
|
|
23
23
|
parentId: null,
|
|
24
24
|
// The previous link of its chain (its `continues`), or null.
|
|
25
25
|
continues: null,
|
|
26
|
-
// A review session's {subjects, from} (its `review`), or null.
|
|
27
|
-
review: null,
|
|
28
26
|
verdicts: [],
|
|
29
27
|
// The Verify fresh checks running ({of, child_id}; the summary's verify_fresh).
|
|
30
28
|
verifyFresh: [],
|
|
@@ -109,10 +107,18 @@ export function sessionStateFrom(data) {
|
|
|
109
107
|
bridgeUp: s.bridge_up === true,
|
|
110
108
|
timing: normalizeTiming(data.timing),
|
|
111
109
|
};
|
|
112
|
-
// The
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
110
|
+
// The ctx fill: the live worker's newest estimate (shown in the session
|
|
111
|
+
// JSON as context_status, kept per request by the Engine) beats the saved
|
|
112
|
+
// fill, which is only the last counted turn's; without it, the saved fill.
|
|
113
|
+
const livePct = s.context_status?.est_pct;
|
|
114
|
+
if (typeof livePct === "number" && Number.isFinite(livePct)) {
|
|
115
|
+
state.ctxPct = livePct;
|
|
116
|
+
} else {
|
|
117
|
+
// The saved fill, so a reloaded or stopped session shows it before its
|
|
118
|
+
// next turn.
|
|
119
|
+
const savedPct = savedCtxPct(data.timing?.context, s.llm_context?.budget_tokens);
|
|
120
|
+
if (savedPct !== null) state.ctxPct = savedPct;
|
|
121
|
+
}
|
|
116
122
|
if (data.timing?.context?.window_tokens) {
|
|
117
123
|
state.ctxWindow = data.timing.context.window_tokens;
|
|
118
124
|
state.ctxWindowSource = data.timing.context.window_source || null;
|
|
@@ -131,7 +137,6 @@ export function sessionStateFrom(data) {
|
|
|
131
137
|
state.toolkitDefault = s.toolkit_default || null;
|
|
132
138
|
state.parentId = s.parent_id || null;
|
|
133
139
|
state.continues = s.continues || null;
|
|
134
|
-
state.review = s.review || null;
|
|
135
140
|
state.verdicts = Array.isArray(s.verdicts) ? s.verdicts : [];
|
|
136
141
|
state.verifyFresh = Array.isArray(s.verify_fresh) ? s.verify_fresh : [];
|
|
137
142
|
state.createdAt = s.created_at || null;
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// historyEl, emptyEl the history and the start page's empty box
|
|
17
17
|
// getSession(id, opts), openStream(id, fromSeq, handlers, opts) data.js
|
|
18
18
|
// liveTurn, turnDom, questionCards, contextChips, participantsControl the page's views
|
|
19
|
+
// (contextChips, participantsControl: null for a viewer without them, viewer.js)
|
|
19
20
|
// view: {forgetSession(opts), renderSessionView(data, opts), endTurnView(kind, endText, opts)}
|
|
20
21
|
// the session view (session_view.js)
|
|
21
22
|
// page: {clearNotice(), setSessionHash(id), setTurnRunning(running), setLiveStatus(status),
|
|
@@ -37,6 +38,8 @@ import { withoutWorker } from "./format.js";
|
|
|
37
38
|
import { resyncRetry, streamDropEnd } from "./turn_events.js";
|
|
38
39
|
import { createResyncReach } from "./resync_reach.js";
|
|
39
40
|
import { keptCommandBubbles } from "./commands.js";
|
|
41
|
+
import { foldKey } from "./stage_waiting.js";
|
|
42
|
+
import { removeSession } from "./storage.js";
|
|
40
43
|
|
|
41
44
|
// +opened+ false: the stream never delivered a frame (the proxy answered
|
|
42
45
|
// 503, or the bridge refused it), so a retry waits a moment rather than
|
|
@@ -83,6 +86,10 @@ export function createSessionSync(deps) {
|
|
|
83
86
|
async function select(id) {
|
|
84
87
|
page.clearNotice();
|
|
85
88
|
const same = store.selected === id;
|
|
89
|
+
// Leaving for another session: the fold this tab kept for the one left
|
|
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
|
+
if (!same) removeSession(foldKey(store.selected));
|
|
86
93
|
// Its synchronous part in one batch: the active card, the composer and
|
|
87
94
|
// the bar redraw once, at its end (never across the await).
|
|
88
95
|
store.batch(() => {
|
|
@@ -93,8 +100,8 @@ export function createSessionSync(deps) {
|
|
|
93
100
|
emptyEl.classList.add("hidden");
|
|
94
101
|
resyncAttempts = 0; // this session has its own re-read budget
|
|
95
102
|
deps.view.forgetSession({ keepVerify: same });
|
|
96
|
-
contextChips
|
|
97
|
-
participantsControl
|
|
103
|
+
contextChips?.load(id);
|
|
104
|
+
participantsControl?.load(id);
|
|
98
105
|
});
|
|
99
106
|
await resync();
|
|
100
107
|
// A folded composer stays folded: typing on the page opens it.
|
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
// liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip
|
|
17
17
|
// the page's views
|
|
18
18
|
// workingSet the stage view's working set (web.working_set), null when off
|
|
19
|
+
// wsPreview its reader and peek (ws_reader.js), null without them: reset with the session
|
|
19
20
|
// gapClock the page's last activity (time_gaps.js createGapClock)
|
|
20
21
|
// bubbles, cards bubbles.js, cards_place.js
|
|
21
22
|
// markdown markdown_place.js (linkTextRefs, applyFinalMarkdown)
|
|
22
23
|
// capabilities() the page's capabilities (card.js shownElsewhere, the history's cards)
|
|
23
24
|
// page: {setReviseAnchor(anchor), renderInitRow(), setMarkdownWarning(warning),
|
|
24
|
-
// setCapabilities(capabilities, editorUrl), findInTurnRoots(selector), appendToHistory(el),
|
|
25
|
+
// setCapabilities(capabilities, editorUrl, viewer), findInTurnRoots(selector), appendToHistory(el),
|
|
25
26
|
// setTurnRunning(running), mergeTurnTiming(id, timing), applySessionPayload(data, opts),
|
|
26
27
|
// turnEndStatus(data), replaceSelectedCard(change)} the page's hooks
|
|
27
28
|
// later: {handlers(), composer(), ownerVerify(), commandList(), initTasks(), resetTurnView()}
|
|
@@ -35,7 +36,7 @@ import { seedInitTasks } from "./init_row.js";
|
|
|
35
36
|
import { restoreCommandBubbles } from "./commands.js";
|
|
36
37
|
import { failedTurnText, normalize } from "./format.js";
|
|
37
38
|
import { splitSnapshotCards } from "./card.js";
|
|
38
|
-
import { turnGroups } from "./timing.js";
|
|
39
|
+
import { turnGroups, normalizeTiming } from "./timing.js";
|
|
39
40
|
import { groupItems } from "./working_set_view.js";
|
|
40
41
|
import { thumbsTemplate } from "./images.js";
|
|
41
42
|
import { hintEl, outputBubbleTemplate } from "./bubbles.js";
|
|
@@ -47,7 +48,7 @@ import { stillOn } from "./latest.js";
|
|
|
47
48
|
export function createSessionView(deps) {
|
|
48
49
|
const {
|
|
49
50
|
store, historyEl, getSession,
|
|
50
|
-
liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet = null, gapClock,
|
|
51
|
+
liveTurn, turnDom, questionCards, shownTexts, objectives, featureGates, markdownTip, workingSet = null, wsPreview = null, gapClock,
|
|
51
52
|
bubbles, cards, markdown, capabilities, page, later,
|
|
52
53
|
} = deps;
|
|
53
54
|
const { makeUserBubble, addEndBubble, showGuardrailWarning, showRecap } = bubbles;
|
|
@@ -84,6 +85,9 @@ export function createSessionView(deps) {
|
|
|
84
85
|
markdownTip.show(null);
|
|
85
86
|
setCapabilities(null, null);
|
|
86
87
|
later.composer().newVisit();
|
|
88
|
+
// The reader and the peek are the session's: another one (or none, the
|
|
89
|
+
// start page) never finds them over #center, the composer inert under it.
|
|
90
|
+
if (!keepVerify) wsPreview?.reset();
|
|
87
91
|
}
|
|
88
92
|
|
|
89
93
|
// A session view: its messages, then the turn in progress and the queued
|
|
@@ -92,7 +96,7 @@ export function createSessionView(deps) {
|
|
|
92
96
|
function renderSessionView(data, { kept = [] } = {}) {
|
|
93
97
|
setMarkdownWarning(data.markdown_warning);
|
|
94
98
|
markdownTip.show(data.markdown_tip);
|
|
95
|
-
setCapabilities(data.capabilities, data.editor_url);
|
|
99
|
+
setCapabilities(data.capabilities, data.editor_url, data.viewer);
|
|
96
100
|
// The saved fill (when there is one) goes in here too, so a reloaded or
|
|
97
101
|
// stopped session shows it before its next turn (a running turn's replay
|
|
98
102
|
// below streams over it).
|
|
@@ -197,6 +201,11 @@ export function createSessionView(deps) {
|
|
|
197
201
|
drawings: data.turn_drawings || null, cards: data.cards || null, capabilities: capabilities(),
|
|
198
202
|
runningTurnId: data.current_turn?.turn_id || null });
|
|
199
203
|
|
|
204
|
+
// A read drawn the way a reload draws it: the turn blocks only, nothing
|
|
205
|
+
// placed after them (the opt-in reload check, reload_check.js, compares
|
|
206
|
+
// this with what the page has, offscreen).
|
|
207
|
+
const reloadRender = (data = {}) => turnHistoryNodes(data.messages || [], normalizeTiming(data.timing), historyOpts(data));
|
|
208
|
+
|
|
200
209
|
function renderHistory(items, data = {}) {
|
|
201
210
|
gapClock.seed(null);
|
|
202
211
|
if (!items.length) {
|
|
@@ -275,5 +284,5 @@ export function createSessionView(deps) {
|
|
|
275
284
|
if (questionCards.pendingQuestion()) questionCards.resolveQuestion(questionCards.pendingQuestion().id, { cancelled: true, reason: "turn ended" });
|
|
276
285
|
}
|
|
277
286
|
|
|
278
|
-
return { forgetSession, renderSessionView, historyOpts, readTurnEnd, endTurnView };
|
|
287
|
+
return { forgetSession, renderSessionView, historyOpts, reloadRender, readTurnEnd, endTurnView };
|
|
279
288
|
}
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
// (start_settings.js) over a new session's choices and by the session bar's
|
|
3
3
|
// (settings_chip.js) over the open session's own: rows of segments
|
|
4
4
|
// (Thinking, Context), the Context row's Apply and budget disclosure, a
|
|
5
|
-
// line for a choice whose row is hidden
|
|
5
|
+
// line for a choice whose row is hidden. The caller
|
|
6
6
|
// passes the rows it draws (settingsPanelTemplate's +rows+) and applies the
|
|
7
7
|
// picks itself; the segments' data-act ("think:low", "ctx:stale",
|
|
8
8
|
// "ctx-more") is the same for every caller.
|
|
9
9
|
|
|
10
10
|
import { APPLIES, choiceWords, ownValues, strategyValue } from "./llm_context_chip.js";
|
|
11
11
|
import { DEFAULT, followSegment, segments } from "./level_chip.js";
|
|
12
|
-
import { reviewChipModel } from "./review_start.js";
|
|
13
12
|
import { CONFIG as THINKING } from "./thinking_chip.js";
|
|
14
13
|
import { html, nothing } from "./vendor/lit-html.js";
|
|
15
14
|
|
|
@@ -99,23 +98,10 @@ function rowTemplate(row) {
|
|
|
99
98
|
: nothing}`;
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
// The review files' line: the files set (Edit, Remove), else Review files….
|
|
103
|
-
function reviewTemplate(review, ruled) {
|
|
104
|
-
const chip = review.length ? reviewChipModel(review) : null;
|
|
105
|
-
return html`${ruled ? html`<hr class="sset-rule">` : nothing}<div class="sset-review">${chip
|
|
106
|
-
? html`<span class="sset-review-set" title=${chip.title}>Review: ${chip.text.replace(/^review: /, "")}</span
|
|
107
|
-
><button type="button" class="sset-link" data-act="review">Edit</button><button type="button" class="sset-link"
|
|
108
|
-
data-act="review-clear">Remove</button>`
|
|
109
|
-
: html`<button type="button" class="sset-link" data-act="review" title=${reviewChipModel([]).title}>Review files…</button>`}</div>`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
101
|
// The panel: its heading (+kind+ beside it, or none) and close button, the
|
|
113
|
-
// +rows+ (rowTemplate's)
|
|
114
|
-
|
|
115
|
-
// and the +note+.
|
|
116
|
-
export function settingsPanelTemplate({ heading, kind = null, rows = [], review = null, note }) {
|
|
117
|
-
const segmented = rows.some((row) => row?.segments);
|
|
102
|
+
// +rows+ (rowTemplate's) and the +note+.
|
|
103
|
+
export function settingsPanelTemplate({ heading, kind = null, rows = [], note }) {
|
|
118
104
|
return html`<div class="ctx-pop-head"><strong>${heading}</strong>${kind ? html`<span class="ctx-pop-kind">${kind}</span>` : nothing
|
|
119
105
|
}<button type="button" class="ctx-pop-close" data-act="close" aria-label="Close">×</button></div
|
|
120
|
-
>${rows.map(rowTemplate)}
|
|
106
|
+
>${rows.map(rowTemplate)}<div class="ctx-pop-meta">${note}</div>`;
|
|
121
107
|
}
|