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
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// stay thin and the logic runs under `node --test`.
|
|
3
3
|
|
|
4
4
|
import { authorBadge } from "./participant_names.js";
|
|
5
|
+
import { isViewerClient } from "./viewer_self.js";
|
|
5
6
|
|
|
6
7
|
// Read turn_summary.output; Bridge::ClientEvent omits result for clients.
|
|
7
8
|
export function turnOutput(data) {
|
|
@@ -107,18 +108,27 @@ function writeClientId(storage, id) {
|
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
// This tab's own (+myId+), or the participant viewer's (viewer_self.js:
|
|
112
|
+
// chi web gives their turns one client id, whichever tab sent them).
|
|
110
113
|
export function isOwn(clientId, myId) {
|
|
111
|
-
return clientId != null && clientId === myId;
|
|
114
|
+
return clientId != null && (clientId === myId || isViewerClient(clientId));
|
|
112
115
|
}
|
|
113
116
|
|
|
114
|
-
// As the TUI labels them (Formatting::CLIENT_LABELS);
|
|
115
|
-
// helpers and the TUI's agree per
|
|
116
|
-
// By the whole id or its prefix (up to and
|
|
117
|
-
// chi doesn't know is "automatic", not the user
|
|
117
|
+
// As the TUI labels them (ClientId::ROWS' labels, Formatting::CLIENT_LABELS);
|
|
118
|
+
// this file's label helpers and the TUI's agree per
|
|
119
|
+
// spec/shared/labels_matrix.json. By the whole id or its prefix (up to and
|
|
120
|
+
// with its first ":"); an id chi doesn't know is "automatic", not the user
|
|
121
|
+
// (ClientId.human?). null: labelled as no sender is (no label): a worker's
|
|
122
|
+
// own first prompt (ClientId::FIRST_PROMPT) and a person's card answer
|
|
123
|
+
// (ClientId::CARD_ANSWER).
|
|
118
124
|
const CLIENT_LABELS = Object.freeze({
|
|
119
125
|
"tui:": "tui", "web:": "web", "system:": "reminder", "delegate:": "delegate", "child:": "delegate report",
|
|
120
|
-
"cli:send": "chi send", "cli:answer": "chi answer", plugin: "plugin", "
|
|
126
|
+
"cli:send": "chi send", "cli:answer": "chi answer", plugin: "plugin", "participant:": "invited",
|
|
127
|
+
"spawn:first": null, "card:answer": null,
|
|
128
|
+
// compat shim review_client_id: a participant's id from before participant:.
|
|
129
|
+
"review:": "invited",
|
|
121
130
|
});
|
|
131
|
+
const labelFor = (key) => (Object.hasOwn(CLIENT_LABELS, key) ? CLIENT_LABELS[key] : undefined);
|
|
122
132
|
const AUTOMATIC_LABEL = "automatic";
|
|
123
133
|
|
|
124
134
|
// A delegate child's report comes in as client child:<id8> (ChildReports).
|
|
@@ -153,7 +163,9 @@ export function clientLabel(clientId) {
|
|
|
153
163
|
if (id.startsWith(TASK_CLIENT) && id.length > TASK_CLIENT.length) return `task ${shortTaskId(id.slice(TASK_CLIENT.length))} finished`;
|
|
154
164
|
if (id.startsWith(SCHEDULE_CLIENT)) return "schedule";
|
|
155
165
|
const colon = id.indexOf(":");
|
|
156
|
-
|
|
166
|
+
let label = labelFor(id);
|
|
167
|
+
if (label === undefined && colon >= 0) label = labelFor(id.slice(0, colon + 1));
|
|
168
|
+
return label === undefined ? AUTOMATIC_LABEL : label;
|
|
157
169
|
}
|
|
158
170
|
|
|
159
171
|
// The note for reminders a turn got (a reminder turn has no prompt).
|
|
@@ -302,6 +314,9 @@ export function promptOps(event, { myId, known, unmatchedMerge = false, wakeStar
|
|
|
302
314
|
switch (event.type) {
|
|
303
315
|
case "turn_enqueued": {
|
|
304
316
|
const id = event.enqueued_id;
|
|
317
|
+
// Someone else's queued turn as a participant gets it (bare: chi web
|
|
318
|
+
// sends no prompt or id of it): nothing to draw.
|
|
319
|
+
if (!id && !event.prompt) return [];
|
|
305
320
|
// Queued for after the running turn (delivery queue): its bubble says so.
|
|
306
321
|
const delivery = event.delivery ? { delivery: event.delivery } : {};
|
|
307
322
|
if (isOwn(event.client_id, myId)) return [withImages({ op: "tag", enqueuedId: id, prompt: event.prompt, ...delivery }, event.images)];
|
|
@@ -312,10 +327,12 @@ export function promptOps(event, { myId, known, unmatchedMerge = false, wakeStar
|
|
|
312
327
|
if (event.continue || !event.prompt) return [];
|
|
313
328
|
const origin = event.origin || {};
|
|
314
329
|
const id = origin.enqueued_id || null;
|
|
315
|
-
|
|
330
|
+
// A participant's own turn (+mine+: chi web names no origin to them)
|
|
331
|
+
// starts their queued bubble, matched by its text.
|
|
332
|
+
if ((id && known(id)) || isOwn(origin.client_id, myId) || event.mine) {
|
|
316
333
|
// Images too: a resync can have wiped the own echo, and the page then
|
|
317
334
|
// draws the bubble from this.
|
|
318
|
-
return [withImages({ op: "start", enqueuedId: id, prompt: event.prompt }, event.images)];
|
|
335
|
+
return [withImages({ op: "start", enqueuedId: id, prompt: event.prompt, ...(event.mine ? { mine: true } : {}) }, event.images)];
|
|
319
336
|
}
|
|
320
337
|
return [withImages({ op: "add", enqueuedId: id, prompt: event.prompt, state: "started", label: clientLabel(origin.client_id), ...authorOf(event.author || origin.author, event.author_name, event.participant_mode) }, event.images)];
|
|
321
338
|
}
|
|
@@ -349,8 +366,9 @@ export function replaysDrawnTurn(event, turnRecords = []) {
|
|
|
349
366
|
return turnRecords.some((record) => record.id === event.turn_id);
|
|
350
367
|
}
|
|
351
368
|
|
|
352
|
-
// +object+ with `images` when there are any
|
|
353
|
-
// for a turn
|
|
369
|
+
// +object+ with `images` when there are any, refs or a count (another
|
|
370
|
+
// participant's, ParticipantView). The shapes stay as they were for a turn
|
|
371
|
+
// without.
|
|
354
372
|
export function withImages(object, images) {
|
|
355
|
-
return images?.length ? { ...object, images } : object;
|
|
373
|
+
return images?.length || images > 0 ? { ...object, images } : object;
|
|
356
374
|
}
|
|
@@ -13,10 +13,12 @@ import { activityDiffTemplate } from "./diff_view.js";
|
|
|
13
13
|
import { clip, fullTime, steerSender } from "./format.js";
|
|
14
14
|
import { rowTitleRef } from "./refs.js";
|
|
15
15
|
import { readLinesTemplate } from "./read_view.js";
|
|
16
|
+
import { wayInTemplate } from "./ws_way_in.js";
|
|
16
17
|
import { handedOverId } from "./task_stop.js";
|
|
17
18
|
import { STOPPED_LINE_CLASS, cancelLineText, formatDuration } from "./timing.js";
|
|
18
19
|
import { emptyAnswerLine } from "./turn_events.js";
|
|
19
|
-
import { authorBadgeText, authorBadgeTitle } from "./participant_names.js";
|
|
20
|
+
import { authorBadge, authorBadgeText, authorBadgeTitle } from "./participant_names.js";
|
|
21
|
+
import { ownerLabel, viewerSelf } from "./viewer_self.js";
|
|
20
22
|
|
|
21
23
|
// A row's status (live, or a saved tool record's on reload): running,
|
|
22
24
|
// error, stopped (a task_wait the user's Stop ended), blocked (a guardrail
|
|
@@ -183,7 +185,7 @@ export function toolRowInnerTemplate(row, { thumbs = () => nothing, stop = nothi
|
|
|
183
185
|
? html`<div class=${tailMode(row.tool, full) ? "activity-output tail" : "activity-output"} title=${full}>${inlineOutput(row.tool, full)}</div>`
|
|
184
186
|
: nothing;
|
|
185
187
|
const status = statusParts(row.status, { noMatch: !!row.no_match });
|
|
186
|
-
return html`${statusMarkTemplate(status)}<span class="activity-tool">${toolName(row)}</span>${params}${stop}${alias}${statusWordTemplate(status)}${auto}${wrong}${duration ? html`<span class="activity-duration">${duration}</span>` : nothing}${commandBlockTemplate(row.view, row.title)}${llmEditTemplate(row)}${output}${full ? readLinesTemplate(row) : nothing}${row.images?.length ? thumbs(row.images) : nothing}${row.diff ? activityDiffTemplate(row.diff) : nothing}`;
|
|
188
|
+
return html`${statusMarkTemplate(status)}<span class="activity-tool">${toolName(row)}</span>${params}${stop}${alias}${statusWordTemplate(status)}${row.status === "ok" ? wayInTemplate(row) : nothing}${auto}${wrong}${duration ? html`<span class="activity-duration">${duration}</span>` : nothing}${commandBlockTemplate(row.view, row.title)}${llmEditTemplate(row)}${output}${full ? readLinesTemplate(row) : nothing}${row.images?.length ? thumbs(row.images) : nothing}${row.diff ? activityDiffTemplate(row.diff) : nothing}`;
|
|
187
189
|
}
|
|
188
190
|
|
|
189
191
|
// A prompt bubble's states and their badges: queued (waiting for its
|
|
@@ -320,7 +322,12 @@ export function steerRowTemplate({ source, text } = {}, { bubble = false } = {})
|
|
|
320
322
|
// +message.source+ (a delegate report's "delegate_report") is its
|
|
321
323
|
// data-source; +lineKey+, a merged line's fold key (answer_fold.js:
|
|
322
324
|
// data-line-key, the reload's "<turn id>:input:<place>").
|
|
325
|
+
// For a participant looking (viewer_self.js) their own echo carries their
|
|
326
|
+
// badge, and a prompt with neither badge nor label is the owner's ("owner").
|
|
323
327
|
export function userBubbleTemplate(message, { label = null, state = null, step = null, thumbs = nothing, own = false, enqueuedId = null, key = null, delivery = null, author = null, lineKey = null } = {}) {
|
|
328
|
+
const self = viewerSelf();
|
|
329
|
+
if (own && !author && self) author = authorBadge(self.author, self.name, self.mode);
|
|
330
|
+
if (!author && !label) label = ownerLabel();
|
|
324
331
|
const named = BADGES[state] ? state : null;
|
|
325
332
|
const from = author
|
|
326
333
|
? html`<span class="origin-label author-badge" title=${authorBadgeTitle(author.name, author.mode)} data-unnamed=${author.unnamed ? "1" : nothing}>${authorBadgeText(author.name, author.mode)}</span>`
|
|
@@ -8,12 +8,11 @@
|
|
|
8
8
|
// The turn's pieces in order: its prompt (none for a reminder turn), its
|
|
9
9
|
// block of steps, the steers no step holds, the lines merged into it in
|
|
10
10
|
// arrival order (live: every extra, cards too), the answer's pieces or the
|
|
11
|
-
// notice of a turn with none, the timing line,
|
|
12
|
-
// the end line (cancel, failure), the kept cards, then the lines queued for
|
|
11
|
+
// notice of a turn with none, the timing line, the end line (cancel, failure), the kept cards, then the lines queued for
|
|
13
12
|
// after the turn (they run next).
|
|
14
13
|
export function turnPieces({ prompt = null, block = null, steers = [], merged = [], answer = [], emptyNote = null, timing = null,
|
|
15
|
-
|
|
16
|
-
return [prompt, block, ...steers, ...merged, ...answer, emptyNote, timing,
|
|
14
|
+
end = null, kept = [], queued = [] } = {}) {
|
|
15
|
+
return [prompt, block, ...steers, ...merged, ...answer, emptyNote, timing, end, ...kept, ...queued].filter(Boolean);
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
// The generation whose text is +turn+'s answer when it ended as +kind+
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
// its own: static JS is cached at unversioned URLs, and a new export on an
|
|
10
10
|
// old module would blank the page.
|
|
11
11
|
|
|
12
|
-
//
|
|
13
|
-
// none (its rule passes null).
|
|
12
|
+
// A context note ends a turn.
|
|
14
13
|
export const NOTE_BOUNDARY = ".bubble.note";
|
|
15
14
|
|
|
16
15
|
// The elements of the turn +opening+ starts (the [data-turn-id] element, or
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Where the Verify preset is offered (verify_preset.js)
|
|
1
|
+
// Where the Verify preset is offered (verify_preset.js): only
|
|
2
2
|
// on text in an ended turn's final answer, the one place the server takes a
|
|
3
3
|
// claim from. TurnStages::VerifyAnchors#verified records a Verify turn's card only when
|
|
4
4
|
// its quote is in the last answer of the source turn (AnswerTail.answer?:
|
|
@@ -25,8 +25,6 @@ const PRECEDING = 2;
|
|
|
25
25
|
// a turn shows before its answer); a context note ends a turn's elements
|
|
26
26
|
// (a wake turn starts with one, and its bubble carries no turn id).
|
|
27
27
|
export const OWNER_FINAL = Object.freeze({ answers: ".bubble.output:not(.report-reply)", boundary: NOTE_BOUNDARY });
|
|
28
|
-
// The participant page: a reply's bubble.
|
|
29
|
-
export const PARTICIPANT_FINAL = Object.freeze({ answers: ".p-msg.reply > .p-bubble", boundary: null });
|
|
30
28
|
|
|
31
29
|
// The turn opening +node+ is in (the last [data-turn-id] at or before it in
|
|
32
30
|
// +container+) and whether it is the newest one: {anchor, last}, or null.
|
|
@@ -55,7 +53,7 @@ function finalAnswer(container, anchor, { answers, boundary }) {
|
|
|
55
53
|
// The turn id Verify anchors to for a selection in +root+ (the annotate
|
|
56
54
|
// source's root) in +container+, or null where Verify isn't offered: not in
|
|
57
55
|
// a turn, not in its final answer, or in the running turn. +rule+:
|
|
58
|
-
// OWNER_FINAL
|
|
56
|
+
// OWNER_FINAL. +running+: null when no turn runs, else
|
|
59
57
|
// {turnId} (the running turn's id; null when unknown, then the newest turn
|
|
60
58
|
// counts as the running one) — a running turn's answer isn't final yet.
|
|
61
59
|
export function verifyTurnOf(container, root, rule, { running = null } = {}) {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The viewer: who looks at this page and what they may do on it (chi web's
|
|
2
|
+
// Web::Viewer). chi web stamps it on <body> (data-viewer-kind, and
|
|
3
|
+
// data-viewer-can: the capability names, space-separated), read once here at
|
|
4
|
+
// boot; a session's show carries it as `viewer` too. The page draws a
|
|
5
|
+
// control, and makes a call, only when viewer.can(name) says so: a control
|
|
6
|
+
// the viewer may not use is not created and not wired (the null-control
|
|
7
|
+
// idiom), and its static element stays hidden (control(): hidden and
|
|
8
|
+
// data-withheld, which index.html's CSS never shows). No 403 is a way
|
|
9
|
+
// of gating. See docs/internals/web-frontend.md (The viewer).
|
|
10
|
+
//
|
|
11
|
+
// Not app.js's refEditor() (where this page can open a ref: the editor) nor
|
|
12
|
+
// the show's capabilities (what the page renders): those are per request.
|
|
13
|
+
//
|
|
14
|
+
// A show's viewer narrows the stamp, never widens it: the boot's controls
|
|
15
|
+
// were made from the stamp. Leaving a session (forgetSession) goes back to
|
|
16
|
+
// the stamp. A page with no stamp may do nothing (it fails closed).
|
|
17
|
+
|
|
18
|
+
// The names in a stamp's or a show's list, as a Set.
|
|
19
|
+
function namesOf(list) {
|
|
20
|
+
const names = Array.isArray(list) ? list : String(list || "").split(/\s+/);
|
|
21
|
+
return new Set(names.filter((name) => typeof name === "string" && name));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// @param body the page's <body> (its data-viewer-kind, data-viewer-can)
|
|
25
|
+
// @return {can(name), kind(), update(viewer), reset(), control(el, name), controls(els, name)}
|
|
26
|
+
export function createViewer(body) {
|
|
27
|
+
const data = body?.dataset || {};
|
|
28
|
+
const stamped = { kind: data.viewerKind || null, can: namesOf(data.viewerCan) };
|
|
29
|
+
let current = stamped;
|
|
30
|
+
|
|
31
|
+
const can = (name) => current.can.has(name);
|
|
32
|
+
return {
|
|
33
|
+
can,
|
|
34
|
+
kind: () => current.kind,
|
|
35
|
+
// A show's +viewer+ ({kind, can}); anything else keeps what is there.
|
|
36
|
+
update(viewer) {
|
|
37
|
+
if (!viewer || typeof viewer !== "object" || !Array.isArray(viewer.can)) return;
|
|
38
|
+
const shown = namesOf(viewer.can);
|
|
39
|
+
current = { kind: stamped.kind, can: new Set([...stamped.can].filter((name) => shown.has(name))) };
|
|
40
|
+
},
|
|
41
|
+
reset() {
|
|
42
|
+
current = stamped;
|
|
43
|
+
},
|
|
44
|
+
// +el+ when the viewer may use +name+; else +el+ hidden, and null (the
|
|
45
|
+
// page wires nothing to it). data-withheld keeps it hidden whatever its
|
|
46
|
+
// own CSS display says (index.html's [data-withheld] rule).
|
|
47
|
+
control(el, name) {
|
|
48
|
+
if (can(name)) return el;
|
|
49
|
+
if (el) {
|
|
50
|
+
el.hidden = true;
|
|
51
|
+
el.dataset.withheld = "";
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
},
|
|
55
|
+
controls(els, name) {
|
|
56
|
+
return els.map((el) => this.control(el, name));
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Who the viewer is in the conversation, for drawing it: a participant's
|
|
2
|
+
// own turns and prompts, and the owner's as "owner" (the participant main
|
|
3
|
+
// page). Not viewer.js: that one says what the viewer may do; this one who
|
|
4
|
+
// they are, read from a show's `viewer` (kind, id, name, client_id, mode),
|
|
5
|
+
// since <body> names no ids. The owner's page never sets it: every helper
|
|
6
|
+
// then answers as before (nothing is "mine" but the tab's own client id,
|
|
7
|
+
// no owner label).
|
|
8
|
+
//
|
|
9
|
+
// Module state, as participant_names.js keeps the names: turn_events.js
|
|
10
|
+
// isOwn, turn_html.js and bubbles.js read it where they draw.
|
|
11
|
+
import { participantAuthor } from "./participant_model.js";
|
|
12
|
+
|
|
13
|
+
let self = null;
|
|
14
|
+
|
|
15
|
+
// +viewer+: a show's viewer ({kind: "participant", id, name, client_id,
|
|
16
|
+
// mode}); anything else (the owner's, none) clears it.
|
|
17
|
+
export function setViewerSelf(viewer) {
|
|
18
|
+
if (!viewer || viewer.kind !== "participant" || !viewer.id) {
|
|
19
|
+
self = null;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
self = {
|
|
23
|
+
clientId: typeof viewer.client_id === "string" && viewer.client_id ? viewer.client_id : null,
|
|
24
|
+
author: participantAuthor(viewer.id),
|
|
25
|
+
name: String(viewer.name || ""),
|
|
26
|
+
mode: viewer.mode || null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// The participant looking, or null (the owner's page).
|
|
31
|
+
export function viewerSelf() {
|
|
32
|
+
return self;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Whether +clientId+ is the viewer's own (chi web gives a participant's
|
|
36
|
+
// turns participant:<grant id>, whichever tab or device sent them).
|
|
37
|
+
const PARTICIPANT_CLIENT = "participant:";
|
|
38
|
+
// compat shim review_client_id: the same id as an older chi gave it.
|
|
39
|
+
const LEGACY_PARTICIPANT_CLIENT = "review:";
|
|
40
|
+
export function isViewerClient(clientId) {
|
|
41
|
+
if (!self?.clientId) return false;
|
|
42
|
+
if (clientId === self.clientId) return true;
|
|
43
|
+
const own = String(self.clientId);
|
|
44
|
+
return own.startsWith(PARTICIPANT_CLIENT) && clientId === LEGACY_PARTICIPANT_CLIENT + own.slice(PARTICIPANT_CLIENT.length);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Whether +author+ ("p:<id>") is the viewer's.
|
|
48
|
+
export function isViewerAuthor(author) {
|
|
49
|
+
return !!self && author === self.author;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// The label a participant sees on the owner's prompts.
|
|
53
|
+
export const OWNER_LABEL = "owner";
|
|
54
|
+
|
|
55
|
+
// The label on a prompt with no participant author, for this viewer: "owner"
|
|
56
|
+
// for a participant, none on the owner's page.
|
|
57
|
+
export function ownerLabel() {
|
|
58
|
+
return self ? OWNER_LABEL : null;
|
|
59
|
+
}
|
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
// working_set_view.js draw them.
|
|
6
6
|
//
|
|
7
7
|
// An item is {kind, key, label, ops, at, count, state, path?, url?, ref?,
|
|
8
|
-
// preloaded?, muted?}: kind file|memory|url, key what it is (a file's full
|
|
8
|
+
// preloaded?, muted?, runs?}: kind file|memory|url, key what it is (a file's full
|
|
9
9
|
// path, a memory's name, a URL), ops the operations on it (read, edit,
|
|
10
10
|
// write: a write of a file is an edit), at the first row that brought it in
|
|
11
11
|
// as ordinals ({turn, step, row}: the turn's place in the page's turns, the
|
|
12
12
|
// generation's in the turn, the row's in the generation; never a row key,
|
|
13
|
-
// which differs live and reloaded), count the rows that touched it
|
|
13
|
+
// which differs live and reloaded), count the rows that touched it, runs
|
|
14
|
+
// each row's tool id with its at ([{id, at}], rows with an id only). A later
|
|
14
15
|
// touch unions its ops and bumps its count, never its at: within a turn
|
|
15
16
|
// the set is append-only, which keeps the fold stable. state is "live" from
|
|
16
17
|
// the rows; the server's projection (GET working_set, :working_set_updated:
|
|
@@ -134,15 +135,19 @@ export function itemsOfTurn(turn, turnOrdinal) {
|
|
|
134
135
|
const byKey = new Map();
|
|
135
136
|
(turn?.gens || []).forEach((gen, step) => {
|
|
136
137
|
(gen?.tools || []).forEach((row, rowIndex) => {
|
|
138
|
+
const at = { turn: turnOrdinal, step, row: rowIndex };
|
|
137
139
|
for (const entry of rowEntries(row)) {
|
|
138
140
|
const id = `${entry.kind}:${entry.key}`;
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
+
let item = byKey.get(id);
|
|
142
|
+
if (item) touch(item, entry.op);
|
|
141
143
|
else {
|
|
142
|
-
|
|
144
|
+
item = newItem(entry, at);
|
|
143
145
|
byKey.set(id, item);
|
|
144
146
|
items.push(item);
|
|
145
147
|
}
|
|
148
|
+
// The row's tool id and place: the timeline's step tags and "go to
|
|
149
|
+
// the call" (ws_timeline.js placeOf); a legacy row has none.
|
|
150
|
+
if (row.tool_id) item.runs = [...(item.runs || []), { id: row.tool_id, at }];
|
|
146
151
|
}
|
|
147
152
|
});
|
|
148
153
|
});
|
|
@@ -175,6 +180,7 @@ export function sessionItems({ turns = [], live = [], preloaded = [], muted = []
|
|
|
175
180
|
} else {
|
|
176
181
|
for (const op of it.ops) if (!found.ops.includes(op)) found.ops = [...found.ops, op];
|
|
177
182
|
found.count += it.count;
|
|
183
|
+
if (it.runs) found.runs = [...(found.runs || []), ...it.runs];
|
|
178
184
|
if (!found.at) found.at = it.at;
|
|
179
185
|
}
|
|
180
186
|
}
|
|
@@ -38,9 +38,10 @@
|
|
|
38
38
|
// on its tool rows, live (stampRows) and reloaded (stampHistory); a jump
|
|
39
39
|
// finds the row by them, never by a row key.
|
|
40
40
|
import { html, nothing, render, svg } from "./vendor/lit-html.js";
|
|
41
|
-
import { createChipPopover } from "./chip_popover.js";
|
|
41
|
+
import { createChipPopover, SHEET_SHARE, SHEET_TALL } from "./chip_popover.js";
|
|
42
42
|
import { stillOn } from "./latest.js";
|
|
43
43
|
import { showRow } from "./refs.js";
|
|
44
|
+
import { PEEK_WIDTH } from "./ws_peek.js";
|
|
44
45
|
import {
|
|
45
46
|
addedItems, addLine, BUDGETS, dropRefusal, fold, footprint, footprintText, forgetOn, GLYPHS, INVERSE, isFresh, itemsOfTurn, labelText,
|
|
46
47
|
labelTitle, newerSnapshot, opsText, overlay, parseSteerLine, pendingSteers, pinnable, refreshable, serverAddIds, sessionItems, STEER_OPS,
|
|
@@ -51,6 +52,12 @@ import {
|
|
|
51
52
|
// a time), its memories past this many to one group.
|
|
52
53
|
const POP_BUDGET = 6;
|
|
53
54
|
|
|
55
|
+
// A row a peek opens on: one the session's runs touched (not an add, a
|
|
56
|
+
// muted or a preloaded-only memory).
|
|
57
|
+
function peekable(item) {
|
|
58
|
+
return !item.added && !item.muted && item.ops.length > 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
54
61
|
// A reloaded turn's items: its steps (timing.js turnGroups) as gens.
|
|
55
62
|
export function groupItems(group, ordinal) {
|
|
56
63
|
return itemsOfTurn({ gens: (group.steps || []).map((step) => ({ tools: step.tools || [] })) }, ordinal);
|
|
@@ -147,8 +154,11 @@ function memberName(item, group) {
|
|
|
147
154
|
// +getWorkingSet(id)+: the server's projection (data.js; null: none asked).
|
|
148
155
|
// +sendLine(line)+: posts a steer line as the session's command (null: no
|
|
149
156
|
// steering, the list reads only).
|
|
157
|
+
// +peek+: the rows' peek (ws_peek.js createPeek; null: none, a participant's
|
|
158
|
+
// list); +onTimeline(item)+: opens the item's reader (ws_reader.js; null:
|
|
159
|
+
// none).
|
|
150
160
|
export function createWorkingSet({ historyEl, stageRoot = () => null, state, session = () => null, infoEl, onChange = () => {}, getWorkingSet = null,
|
|
151
|
-
sendLine = null, doc = document }) {
|
|
161
|
+
sendLine = null, peek = null, onTimeline = null, doc = document }) {
|
|
152
162
|
// The finished turns' sets ({items, prompt}), the running turn's (null:
|
|
153
163
|
// none), the rail's first-sight times (its fresh cue), the session count
|
|
154
164
|
// at the last open (the chip's dot).
|
|
@@ -186,8 +196,8 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
|
|
|
186
196
|
const promptOf = (t) => (live && t === live.ordinal ? live.prompt : turns[t]?.prompt || "");
|
|
187
197
|
|
|
188
198
|
const popover = createChipPopover({
|
|
189
|
-
id: "workingSetPopover", className: "ctx-popover ws-popover", width: 420, el: infoEl, anchor: ".ws-chip",
|
|
190
|
-
openers: ".ws-chip, .ts-ws, .ws-foot", sheet: true, label: "Working set",
|
|
199
|
+
id: "workingSetPopover", className: "ctx-popover ws-popover", width: () => (peek?.any() ? PEEK_WIDTH : 420), el: infoEl, anchor: ".ws-chip",
|
|
200
|
+
openers: ".ws-chip, .ts-ws, .ws-foot", sheet: true, label: "Working set", sheetShare: () => (peek?.any() ? SHEET_TALL : SHEET_SHARE),
|
|
191
201
|
// The chip opens the session's scope; the rail and a footprint set
|
|
192
202
|
// theirs before they open it.
|
|
193
203
|
summary: (anchor) => {
|
|
@@ -205,7 +215,7 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
|
|
|
205
215
|
draw();
|
|
206
216
|
if (opening) fetchServer();
|
|
207
217
|
},
|
|
208
|
-
onClose: () => { openGroup = null; onChange(); },
|
|
218
|
+
onClose: () => { openGroup = null; peek?.close(); onChange(); },
|
|
209
219
|
// The foot's + add (the popover's submit): one KEY as typed (quoted
|
|
210
220
|
// when it has spaces).
|
|
211
221
|
onSubmit: (form) => {
|
|
@@ -296,10 +306,14 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
|
|
|
296
306
|
const isPending = pill !== nothing;
|
|
297
307
|
const strip = stripOpen === id && buttons !== nothing;
|
|
298
308
|
const open = item.kind === "file" ? html`<button type="button" class="ws-act-b open ref" data-ref-kind="file" data-ref-path=${item.ref?.path || full}>open</button>` : nothing;
|
|
299
|
-
|
|
309
|
+
// The ▸ that peeks at what chi has of it (the owner's: +peek+).
|
|
310
|
+
const canPeek = peek && peekable(item);
|
|
311
|
+
const peeked = canPeek && peek.isOpen(id);
|
|
312
|
+
const toggle = canPeek ? html`<button type="button" class="ws-peek-toggle" data-ws="peek" data-ws-id=${id} aria-expanded=${String(peeked)} aria-label=${`What chi has of ${name}`} title="What chi has of it">${peeked ? "▾" : "▸"}</button>` : nothing;
|
|
313
|
+
const row = html`<div class=${`ws-row ${item.kind}${item.added ? " added" : ""}${fresh ? " fresh" : ""}${item.muted ? " muted" : ""}${group ? " member" : ""}${state}${isPending ? " pending" : ""}${strip ? " strip-open" : ""}${peeked ? " peeked" : ""}${canPeek ? " peekable" : ""}`} data-ws-id=${id}>${toggle}<span class="k">${glyph}</span>${nameEl}${pin}${edited ? html`<span class="e">✎</span>` : nothing}<span class="st">${words}</span>${pill}${tokens ? html`<span class="tk" title=${`about ${item.tokens} tokens of it are sent`}>${tokens}</span>` : nothing}${tagEl}${buttons !== nothing ? html`<span class="ws-act">${buttons}</span>` : nothing}</div>`;
|
|
300
314
|
// One template either way, so the tapped row stays the same node (a
|
|
301
315
|
// click outside the popover closes it).
|
|
302
|
-
return html`${row}${strip ? html`<div class="ws-strip">${buttons}${open}</div>` : nothing}`;
|
|
316
|
+
return html`${row}${strip ? html`<div class="ws-strip">${buttons}${open}</div>` : nothing}${peeked ? peek.template(item) : nothing}`;
|
|
303
317
|
}
|
|
304
318
|
|
|
305
319
|
// A section's labels: leaves as rows, groups as an opener row and, open,
|
|
@@ -345,7 +359,7 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
|
|
|
345
359
|
${added.length ? html`<div class="ctx-pop-meta">adding · ${added.length}</div>${added.map((it) => rowTemplate(it, opts))}` : nothing}
|
|
346
360
|
${pend.size ? html`<div class="ws-pending" role="status"><span class="ws-pending-t">${pend.size} change${pend.size === 1 ? "" : "s"} pending<span class="ws-pending-when"> · apply at the next turn's start</span></span><button type="button" class="ws-act-b" data-ws="undo-all">undo all</button></div>` : nothing}
|
|
347
361
|
${sendLine ? html`<form class="ws-add" data-ws="add-form"><input class="ws-add-in" type="text" name="key" placeholder="+ path, memory:ENTRY or URL" aria-label="Add to the working set: a path, memory:ENTRY or a URL" autocomplete="off" autocapitalize="off" spellcheck="false" enterkeyhint="go"><button type="submit" class="ws-act-b">add</button></form>` : nothing}
|
|
348
|
-
<div class="ctx-pop-meta ws-hint"
|
|
362
|
+
<div class="ctx-pop-meta ws-hint">${peek ? "A row's ▸ peeks at what chi has of it; the name still opens its ref" : "A file opens its ref"}; a step tag goes to the call.${sendLine ? " Drop sends stubs instead of an item's reads from the next turn; add asks the model to read one first." : ""}${sendLine && forget ? " Pin keeps an item from the model's forget." : ""} Esc closes.</div>`;
|
|
349
363
|
render(tpl, popover.pop);
|
|
350
364
|
}
|
|
351
365
|
|
|
@@ -374,6 +388,12 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
|
|
|
374
388
|
return [turn, step, row].every(Number.isInteger) ? { turn, step, row } : null;
|
|
375
389
|
};
|
|
376
390
|
|
|
391
|
+
// The item of the list's row +id+ (its steerId): the session's set, the
|
|
392
|
+
// shown turn's.
|
|
393
|
+
function rowItem(id) {
|
|
394
|
+
return [...sessionSet().items, ...turnItems(view.turn)].find((it) => steerId(it) === id) || null;
|
|
395
|
+
}
|
|
396
|
+
|
|
377
397
|
// Posts +op+ for the ids (the items' steer words, from the set).
|
|
378
398
|
function steer(op, ids) {
|
|
379
399
|
if (!sendLine || !ids.length) return;
|
|
@@ -404,6 +424,13 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
|
|
|
404
424
|
const ids = [...pend].filter(([, o]) => o === op).map(([id]) => id);
|
|
405
425
|
steer(INVERSE[op], ids);
|
|
406
426
|
}
|
|
427
|
+
} else if (act.dataset.ws === "peek" && peek) {
|
|
428
|
+
const item = rowItem(act.dataset.wsId);
|
|
429
|
+
if (item) peek.toggle(act.dataset.wsId, item);
|
|
430
|
+
} else if (act.dataset.ws === "timeline" && onTimeline) {
|
|
431
|
+
const item = rowItem(act.dataset.wsId);
|
|
432
|
+
if (popover.isOpen()) popover.close();
|
|
433
|
+
if (item) onTimeline(item);
|
|
407
434
|
} else if (act.dataset.ws === "jump") {
|
|
408
435
|
const at = parseAt(act.dataset.at);
|
|
409
436
|
if (at) jump(at);
|
|
@@ -483,6 +510,9 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
|
|
|
483
510
|
changed();
|
|
484
511
|
refreshFootprints();
|
|
485
512
|
for (const fn of listeners) fn();
|
|
513
|
+
// An open peek asks again on an event (a GET answers the open itself):
|
|
514
|
+
// the route builds from the messages.
|
|
515
|
+
if (how?.event && popover.isOpen()) peek?.refresh();
|
|
486
516
|
}
|
|
487
517
|
|
|
488
518
|
// The server's set for the open session, asked again; an answer for a
|
|
@@ -596,7 +626,22 @@ export function createWorkingSet({ historyEl, stageRoot = () => null, state, ses
|
|
|
596
626
|
if (popover.isOpen()) openedCount = n;
|
|
597
627
|
return { n, changed: n !== openedCount };
|
|
598
628
|
},
|
|
629
|
+
// The peek's content changed: the open list redraws and places itself.
|
|
630
|
+
peekChanged() {
|
|
631
|
+
if (!popover.isOpen()) return;
|
|
632
|
+
draw();
|
|
633
|
+
popover.replace();
|
|
634
|
+
},
|
|
599
635
|
jump,
|
|
636
|
+
// The session's set as the list shows it (overlaid), for the reader.
|
|
637
|
+
items: () => sessionSet().items,
|
|
638
|
+
// The list opened at the session bar's chip (the reader's ‹ Set).
|
|
639
|
+
openList() {
|
|
640
|
+
const chip = infoEl.querySelector(".ws-chip");
|
|
641
|
+
if (!chip) return;
|
|
642
|
+
view = { scope: "session", turn: live ? live.ordinal : turns.length - 1 };
|
|
643
|
+
popover.open(chip);
|
|
644
|
+
},
|
|
600
645
|
ctxPct: () => state().ctxPct,
|
|
601
646
|
isOpen: () => popover.isOpen(),
|
|
602
647
|
popover,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The timeline's cards as lit templates (ws_timeline.js makes them): the
|
|
2
|
+
// reader's (ws_reader.js) and the popover peek's (ws_peek.js) one look. A
|
|
3
|
+
// read's lines draw as a read row's do (.read-line, numbered); an edit's
|
|
4
|
+
// diff with diff_view.js, the same renderer as the tool row's and the
|
|
5
|
+
// approval card's. A card chi no longer has is greyed, its text folded.
|
|
6
|
+
|
|
7
|
+
import { html, nothing } from "./vendor/lit-html.js";
|
|
8
|
+
import { diffCounts, diffTemplate } from "./diff_view.js";
|
|
9
|
+
import { eventTag, goneText, linesText, placeOf, SLICE_FOLD_LINES, tagsText } from "./ws_timeline.js";
|
|
10
|
+
|
|
11
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
12
|
+
|
|
13
|
+
// Numbered lines (+rows+ [{n, text}]); past +fold+ the rest behind a
|
|
14
|
+
// "show all" toggle (lit never binds its open).
|
|
15
|
+
export function linesTemplate(rows, { fold = SLICE_FOLD_LINES } = {}) {
|
|
16
|
+
const span = ({ n, text }) => html`<span class="read-line" data-line=${n}>${text || html`<br>`}</span>`;
|
|
17
|
+
const head = html`<pre class="read-lines wsr-lines"><code>${rows.slice(0, fold).map(span)}</code></pre>`;
|
|
18
|
+
if (rows.length <= fold) return head;
|
|
19
|
+
return html`${head}<details class="diff-more"><summary>show all ${rows.length} lines</summary><pre class="read-lines wsr-lines"><code>${rows.slice(fold).map(span)}</code></pre></details>`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// A text as it was sent (a memory's, a fetch's, a partial read's), wrapped.
|
|
23
|
+
export function textTemplate(text, { fold = SLICE_FOLD_LINES } = {}) {
|
|
24
|
+
const lines = String(text ?? "").split("\n");
|
|
25
|
+
if (lines.length <= fold) return html`<pre class="wsr-text">${text}</pre>`;
|
|
26
|
+
return html`<pre class="wsr-text">${lines.slice(0, fold).join("\n")}</pre><details class="diff-more"><summary>show all ${lines.length} lines</summary><pre class="wsr-text">${lines.slice(fold).join("\n")}</pre></details>`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// "go to the call": the event's row (+item+'s runs), none when it isn't
|
|
30
|
+
// drawn.
|
|
31
|
+
export function callTemplate(event, item, label = "go to the call") {
|
|
32
|
+
const at = placeOf(event, item);
|
|
33
|
+
if (!at) return nothing;
|
|
34
|
+
return html`<button type="button" class="wsr-call" data-ws="jump" data-at=${`${at.turn}.${at.step}.${at.row}`}>${label}</button>`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function goneBody(card, rows, undrop) {
|
|
38
|
+
const words = goneText(card.state);
|
|
39
|
+
const what = card.type === "slice" ? plural(rows.length, "line") : "its text";
|
|
40
|
+
const offer = card.state === "dropped" && undrop !== nothing ? html` · ${undrop}` : nothing;
|
|
41
|
+
return html`<div class="wsr-gone">${what} · ${words}${offer}</div><details class="wsr-had"><summary>what it was</summary>${card.type === "slice" ? linesTemplate(rows) : textTemplate(card.event.text)}</details>`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// A memory read's overlay part (ws_timeline: event.memory.overlay).
|
|
45
|
+
function overlayTemplate(memory) {
|
|
46
|
+
if (!memory?.overlay) return nothing;
|
|
47
|
+
const name = String(memory.overlay_path || "").split("/").pop();
|
|
48
|
+
return html`<div class="wsr-overlay"><div class="wsr-overlay-h">+ overlay for this model${name ? ` · ${name}` : ""}</div>${textTemplate(memory.overlay)}</div>`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// One card. +item+: the open item (its runs: the step tags); +undrop+: the
|
|
52
|
+
// greyed card's undrop button (a template), or nothing.
|
|
53
|
+
export function cardTemplate(card, { item, undrop = nothing } = {}) {
|
|
54
|
+
const gone = card.state && card.state !== "sent";
|
|
55
|
+
const pill = gone ? html`<span class="wsr-pill gone">chi no longer has this</span>`
|
|
56
|
+
: card.latest ? html`<span class="wsr-pill latest">latest</span>` : nothing;
|
|
57
|
+
let title;
|
|
58
|
+
let meta = "";
|
|
59
|
+
let body;
|
|
60
|
+
let call;
|
|
61
|
+
if (card.type === "slice") {
|
|
62
|
+
title = linesText(card);
|
|
63
|
+
meta = `${plural(card.reads.length, "read")} · ${tagsText(card.reads, item)}`;
|
|
64
|
+
body = gone ? goneBody(card, card.rows, undrop) : linesTemplate(card.rows);
|
|
65
|
+
call = callTemplate(card.reads[0], item);
|
|
66
|
+
} else {
|
|
67
|
+
const { event } = card;
|
|
68
|
+
const tag = eventTag(event, item);
|
|
69
|
+
call = callTemplate(event, item);
|
|
70
|
+
if (card.type === "edit") {
|
|
71
|
+
title = `${event.op} · ${tag}`;
|
|
72
|
+
const diff = event.diff;
|
|
73
|
+
meta = diff && !diff.error && !diff.skipped && diff.text ? diffCounts(diff) : "";
|
|
74
|
+
body = diff ? diffTemplate(diff) : html`<div class="diff-note">no diff saved (no change, or the file couldn't be read)</div>`;
|
|
75
|
+
} else if (card.type === "partial") {
|
|
76
|
+
title = `${linesText(event.lines)} · ${tag}`;
|
|
77
|
+
meta = "shown as chi got it";
|
|
78
|
+
body = gone ? goneBody(card, [], undrop) : textTemplate(event.text);
|
|
79
|
+
} else {
|
|
80
|
+
const words = { memory: "read", written: "memory write", fetch: "fetch" }[card.type];
|
|
81
|
+
title = `${words} · ${tag}`;
|
|
82
|
+
const shared = event.shared_with?.length ? `read with ${event.shared_with.join(", ")}` : "";
|
|
83
|
+
meta = shared;
|
|
84
|
+
body = gone ? goneBody(card, [], undrop) : html`${textTemplate(event.text)}${card.type === "memory" ? overlayTemplate(event.memory) : nothing}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const classes = `wsr-card ${card.type}${gone ? ` gone ${card.state}` : ""}${card.latest ? " latest" : ""}`;
|
|
88
|
+
return html`<article class=${classes} data-newest=${card.newest}><header class="wsr-card-h"><span class="wsr-card-t">${title}</span>${meta ? html`<span class="wsr-card-m">${meta}</span>` : nothing}${pill}${call}</header>${body}</article>`;
|
|
89
|
+
}
|