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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// The working set popover's peek (scene C of the working-set preview): a
|
|
2
|
+
// row's ▸ opens, under the row, what chi has of the item now: its latest
|
|
3
|
+
// edit's diff (diff_view.js), else its newest read's first lines
|
|
4
|
+
// (ws_timeline.js peekOf), with "Open the timeline · N reads, M edits"
|
|
5
|
+
// (the reader, ws_reader.js) and "go to the call" (the popover's step jump).
|
|
6
|
+
// One row at a time. The owner's only: working_set_view.js gets none for a
|
|
7
|
+
// participant (the null-control idiom) and draws today's rows.
|
|
8
|
+
//
|
|
9
|
+
// The item's timeline comes from the item route (+getItem+); an answer for
|
|
10
|
+
// a row no longer open, or another session, is dropped (latest.js). While a
|
|
11
|
+
// row is open, each new server snapshot asks again (refresh): the route
|
|
12
|
+
// builds from the session's messages, which lag a running turn.
|
|
13
|
+
|
|
14
|
+
import { html, nothing } from "./vendor/lit-html.js";
|
|
15
|
+
import { createLatest } from "./latest.js";
|
|
16
|
+
import { diffCounts, diffTemplate } from "./diff_view.js";
|
|
17
|
+
import { callTemplate, linesTemplate, textTemplate } from "./ws_cards.js";
|
|
18
|
+
import { countsText, eventTag, eventWords, peekOf } from "./ws_timeline.js";
|
|
19
|
+
|
|
20
|
+
// The popover's width while a row is peeked (it is 420 otherwise).
|
|
21
|
+
export const PEEK_WIDTH = 520;
|
|
22
|
+
|
|
23
|
+
// +session()+: the open session's id; +getItem(id, kind, key)+: the item
|
|
24
|
+
// route's answer; +onChange()+: the peek's content changed (the popover
|
|
25
|
+
// redraws and places itself again).
|
|
26
|
+
export function createPeek({ session, getItem, onChange = () => {} }) {
|
|
27
|
+
let openId = null;
|
|
28
|
+
let item = null;
|
|
29
|
+
let data = null;
|
|
30
|
+
let failed = false;
|
|
31
|
+
const latest = createLatest(() => `${session()}|${openId}`);
|
|
32
|
+
|
|
33
|
+
function load() {
|
|
34
|
+
const id = session();
|
|
35
|
+
if (!id || !item) return;
|
|
36
|
+
const fresh = latest.begin();
|
|
37
|
+
const { kind, key } = item;
|
|
38
|
+
Promise.resolve()
|
|
39
|
+
.then(() => getItem(id, kind, key))
|
|
40
|
+
.then((answer) => {
|
|
41
|
+
if (!fresh()) return;
|
|
42
|
+
data = answer;
|
|
43
|
+
failed = false;
|
|
44
|
+
onChange();
|
|
45
|
+
})
|
|
46
|
+
.catch(() => {
|
|
47
|
+
if (!fresh()) return;
|
|
48
|
+
failed = true;
|
|
49
|
+
onChange();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function close() {
|
|
54
|
+
openId = null;
|
|
55
|
+
item = null;
|
|
56
|
+
data = null;
|
|
57
|
+
failed = false;
|
|
58
|
+
latest.drop();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
// +id+'s row (working_set.js steerId) opened, or closed when it was.
|
|
63
|
+
toggle(id, row) {
|
|
64
|
+
if (openId === id) close();
|
|
65
|
+
else {
|
|
66
|
+
openId = id;
|
|
67
|
+
item = row;
|
|
68
|
+
data = null;
|
|
69
|
+
failed = false;
|
|
70
|
+
load();
|
|
71
|
+
}
|
|
72
|
+
onChange();
|
|
73
|
+
},
|
|
74
|
+
isOpen: (id) => openId === id,
|
|
75
|
+
any: () => openId !== null,
|
|
76
|
+
close,
|
|
77
|
+
// A new server snapshot: the open row's timeline asked again (its
|
|
78
|
+
// drawn one stays until the answer).
|
|
79
|
+
refresh(row = item) {
|
|
80
|
+
if (!openId) return;
|
|
81
|
+
item = row || item;
|
|
82
|
+
load();
|
|
83
|
+
},
|
|
84
|
+
// The peek under +row+ (the row's item, overlaid: its runs for the
|
|
85
|
+
// step tags).
|
|
86
|
+
template(row) {
|
|
87
|
+
if (failed) return html`<div class="ws-peek" role="region" aria-label="What chi has"><div class="ws-peek-note">Couldn't load what chi has of it.</div></div>`;
|
|
88
|
+
if (!data) return html`<div class="ws-peek" role="region" aria-label="What chi has"><div class="ws-peek-note">Loading…</div></div>`;
|
|
89
|
+
const events = data.events || [];
|
|
90
|
+
const peek = peekOf(events);
|
|
91
|
+
if (!peek) return html`<div class="ws-peek" role="region" aria-label="What chi has"><div class="ws-peek-note">Nothing of it in the conversation yet.</div></div>`;
|
|
92
|
+
const { event } = peek;
|
|
93
|
+
const counts = peek.kind === "diff" && event.diff?.text && !event.diff.error && !event.diff.skipped ? diffCounts(event.diff) : "";
|
|
94
|
+
const after = peek.after ? html`<span class="ws-peek-after">then ${eventWords(peek.after)} at ${eventTag(peek.after, row)}</span>` : nothing;
|
|
95
|
+
const gone = event.sent === false ? html`<span class="wsr-pill gone">chi no longer has this</span>` : nothing;
|
|
96
|
+
const head = html`<div class="ws-peek-h"><span class="ws-peek-t">latest · ${eventWords(event)} at ${eventTag(event, row)}</span>${counts ? html`<span class="ws-peek-c">${counts}</span>` : nothing}${gone}${after}</div>`;
|
|
97
|
+
let body;
|
|
98
|
+
if (peek.kind === "diff") body = diffTemplate(event.diff, { fold: 12 });
|
|
99
|
+
else if (peek.kind === "lines") body = linesTemplate(peek.rows, { fold: Infinity });
|
|
100
|
+
else body = textTemplate(peek.rows.map((r) => r.text).join("\n"), { fold: Infinity });
|
|
101
|
+
const words = countsText(events);
|
|
102
|
+
const foot = html`<div class="ws-peek-f"><button type="button" class="ws-peek-open" data-ws="timeline" data-ws-id=${openId}>Open the timeline${words ? html`<span class="ws-peek-n"> · ${words}</span>` : nothing}</button>${callTemplate(event, row)}</div>`;
|
|
103
|
+
return html`<div class="ws-peek" role="region" aria-label="What chi has">${head}<div class="ws-peek-b">${body}</div>${foot}</div>`;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/* What chi has of a working-set item (ws_reader.js, ws_peek.js, ws_cards.js):
|
|
2
|
+
the popover's peek under a row and the reader over the stage. Colours are
|
|
3
|
+
tokens.css's. */
|
|
4
|
+
|
|
5
|
+
/* The popover's ▸: a row's peek toggle, before its glyph. */
|
|
6
|
+
.ws-peek-toggle{flex:none;width:16px;height:22px;margin:0 -4px 0 -2px;padding:0;border:0;border-radius:4px;background:transparent;color:var(--ws-faint);font-size:10px;line-height:22px;cursor:pointer}
|
|
7
|
+
.ws-peek-toggle:hover:not(:disabled){filter:none}@media(hover:hover){.ws-peek-toggle:hover{color:var(--accent);background:var(--accent-bg)}}
|
|
8
|
+
.ws-row.peeked{background:var(--bg-hover)}
|
|
9
|
+
.ws-row.peeked .ws-peek-toggle{color:var(--text-2)}
|
|
10
|
+
.ws-row.member .ws-peek-toggle{margin-left:-20px}
|
|
11
|
+
.ws-popover.sheet .ws-peek-toggle{width:28px;height:30px;margin-left:-8px}
|
|
12
|
+
|
|
13
|
+
/* The peek: the latest event, its footer. */
|
|
14
|
+
.ws-peek{flex:none;margin:4px 0 8px 6px;border:1px solid var(--border-strong);border-radius:8px;background:var(--bg-inset);overflow:hidden;font-family:ui-sans-serif,system-ui,sans-serif}
|
|
15
|
+
.ws-peek-h{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:5px 10px;border-bottom:1px solid var(--border);font-size:12px;color:var(--ws-muted)}
|
|
16
|
+
.ws-peek-t{color:var(--text-2)}
|
|
17
|
+
.ws-peek-c{font-variant-numeric:tabular-nums}
|
|
18
|
+
.ws-peek-after{margin-left:auto;color:var(--ws-faint)}
|
|
19
|
+
.ws-peek-note{padding:8px 10px;font-size:12px;color:var(--ws-faint)}
|
|
20
|
+
.ws-peek-b .diff,.ws-peek-b .read-lines,.ws-peek-b .wsr-text{margin:0;border:0;border-radius:0;max-height:220px;font-size:11.5px}
|
|
21
|
+
.ws-peek-b .diff-note{padding:6px 10px}
|
|
22
|
+
.ws-peek-f{display:flex;align-items:center;gap:16px;padding:6px 10px;border-top:1px solid var(--border);font-size:12.5px}
|
|
23
|
+
.ws-peek-open,.wsr-call{padding:0;border:0;background:transparent;color:var(--accent);font:inherit;font-size:12.5px;cursor:pointer;text-align:left}
|
|
24
|
+
.ws-peek-open:hover:not(:disabled),.wsr-call:hover:not(:disabled){filter:none}@media(hover:hover){.ws-peek-open:hover,.wsr-call:hover{text-decoration:underline}}
|
|
25
|
+
.ws-popover.sheet .ws-peek-f{padding:0;gap:0}
|
|
26
|
+
.ws-popover.sheet .ws-peek-n{display:none}
|
|
27
|
+
.ws-popover.sheet .ws-peek-f>button{flex:1;height:44px;text-align:center}
|
|
28
|
+
.ws-popover.sheet .ws-peek-f>button+button{border-left:1px solid var(--border)}
|
|
29
|
+
|
|
30
|
+
/* A tool row's way in. */
|
|
31
|
+
.activity-ws{flex:none;padding:0 6px;border:1px solid var(--ws-act-border);border-radius:4px;background:transparent;font-size:11px;line-height:16px;color:var(--ws-muted);cursor:pointer;opacity:0}
|
|
32
|
+
.activity-row:hover .activity-ws,.activity-row:focus-within .activity-ws{opacity:1}
|
|
33
|
+
@media (hover:none){.activity-ws{opacity:1}}
|
|
34
|
+
.activity-ws:hover:not(:disabled){filter:none}@media(hover:hover){.activity-ws:hover{color:var(--accent);border-color:var(--accent);background:var(--accent-bg)}}
|
|
35
|
+
|
|
36
|
+
/* The reader: over the stage (#center: the history and the composer stay under it, inert). */
|
|
37
|
+
.ws-reader{position:absolute;inset:0;z-index:6;display:flex;background:var(--bg);border-radius:inherit;overflow:hidden}
|
|
38
|
+
.ws-reader[hidden]{display:none}
|
|
39
|
+
.wsr-main{flex:1;min-width:0;display:flex;flex-direction:column;border-right:1px solid var(--border)}
|
|
40
|
+
.wsr-head{flex:none;display:flex;align-items:center;gap:12px;padding:10px 20px;border-bottom:1px solid var(--border);background:var(--bg-panel)}
|
|
41
|
+
.wsr-back{flex:none;padding:4px 10px;border:1px solid var(--border-strong);border-radius:6px;background:transparent;color:var(--text-2);font-size:12px;cursor:pointer}
|
|
42
|
+
.wsr-title{min-width:0;display:flex;align-items:baseline;gap:12px}
|
|
43
|
+
.wsr-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:13px;color:var(--text)}
|
|
44
|
+
.wsr-meta{flex:none;font-size:12px;color:var(--ws-faint)}
|
|
45
|
+
.wsr-head-pill{flex:none;margin-left:auto;padding:1px 8px;border:1px solid var(--border-strong);border-radius:999px;font-size:11.5px;color:var(--ws-muted);white-space:nowrap}
|
|
46
|
+
.wsr-head-pill.warn{border-color:var(--warn-border);background:var(--warn-bg);color:var(--warn-text)}
|
|
47
|
+
.wsr-narrow{display:none}
|
|
48
|
+
.wsr-nav button{width:44px;height:44px;border:0;background:transparent;color:var(--text-2);font-size:18px;cursor:pointer}
|
|
49
|
+
.wsr-nav button:disabled{opacity:.35;cursor:default}
|
|
50
|
+
|
|
51
|
+
/* The file strip: the reads over the file's length. */
|
|
52
|
+
.wsr-strip{flex:none;display:flex;flex-direction:column;gap:6px;padding:10px 20px 8px;border-bottom:1px solid var(--border)}
|
|
53
|
+
.wsr-strip-k{display:flex;justify-content:space-between;gap:8px;font-size:11px;color:var(--ws-faint);font-variant-numeric:tabular-nums}
|
|
54
|
+
.wsr-bar{position:relative;height:10px;border-radius:3px;background:var(--bg-inset)}
|
|
55
|
+
.wsr-band{position:absolute;top:0;bottom:0;padding:0;border:0;border-radius:2px;cursor:pointer;background:color-mix(in srgb,var(--accent) 55%,transparent)}
|
|
56
|
+
.wsr-band.dropped,.wsr-band.forgotten{background:color-mix(in srgb,var(--text-faint) 75%,transparent)}
|
|
57
|
+
.wsr-band.latest.sent{background:var(--accent)}
|
|
58
|
+
.wsr-band.latest:not(.sent){background:var(--text-muted)}
|
|
59
|
+
.wsr-chips{display:flex;flex-wrap:wrap;gap:6px}
|
|
60
|
+
.wsr-chip{padding:2px 9px;border:0;border-radius:999px;background:var(--bg-inset);color:var(--text-2);font-size:11.5px;font-variant-numeric:tabular-nums;cursor:pointer}
|
|
61
|
+
.wsr-chip.dropped,.wsr-chip.forgotten{color:var(--text-faint);text-decoration:line-through}
|
|
62
|
+
|
|
63
|
+
/* The cards, newest first. */
|
|
64
|
+
.wsr-body{flex:1;min-height:0;overflow:auto;padding:14px 20px;display:flex;flex-direction:column;gap:14px;outline:none}
|
|
65
|
+
.wsr-note{color:var(--ws-faint);font-size:13px}
|
|
66
|
+
.wsr-card{flex:none;border:1px solid var(--border);border-radius:8px;background:var(--bg-panel);overflow:hidden}
|
|
67
|
+
.wsr-card.latest{border-color:var(--border-strong)}
|
|
68
|
+
.wsr-card.gone{opacity:.55}
|
|
69
|
+
.wsr-card-h{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:6px 12px;border-bottom:1px solid var(--border);background:var(--bg-raised);font-size:12px}
|
|
70
|
+
.wsr-card-t{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--text)}
|
|
71
|
+
.wsr-card-m{color:var(--ws-faint)}
|
|
72
|
+
.wsr-card-h .wsr-call{margin-left:auto;font-size:12px}
|
|
73
|
+
.wsr-pill{padding:0 6px;border-radius:4px;font-size:11px}
|
|
74
|
+
.wsr-pill.latest{background:var(--accent-bg);color:var(--accent)}
|
|
75
|
+
.wsr-pill.gone{background:var(--badge-bg);color:var(--text-muted)}
|
|
76
|
+
.wsr-card .read-lines,.wsr-card .diff,.wsr-card .wsr-text{margin:0;border:0;border-radius:0;max-height:none;background:transparent}
|
|
77
|
+
.wsr-lines{font-size:12.5px;line-height:19px}
|
|
78
|
+
.wsr-text{margin:0;padding:8px 12px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;line-height:17px;white-space:pre-wrap;word-break:break-word;color:var(--text-2)}
|
|
79
|
+
.wsr-gone{padding:8px 12px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;color:var(--text-muted)}
|
|
80
|
+
.wsr-had{padding:0 12px 8px;font-size:12px;color:var(--ws-faint)}
|
|
81
|
+
.wsr-had>summary{cursor:pointer}
|
|
82
|
+
.wsr-overlay{margin:0 10px 10px;padding:6px 0 0;border:1px dashed var(--border-strong);border-radius:6px}
|
|
83
|
+
.wsr-overlay-h{padding:0 10px;font-size:11.5px;color:var(--ws-muted)}
|
|
84
|
+
.wsr-banner{flex:none;margin:10px 20px 0;padding:8px 10px;border:1px solid var(--warn-border);border-radius:8px;background:var(--warn-bg);color:var(--warn-text);font-size:12.5px;line-height:18px}
|
|
85
|
+
.wsr-tabs{flex:none;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));margin:10px 20px 0;padding:2px;border-radius:8px;background:var(--bg-inset);max-width:420px}
|
|
86
|
+
.wsr-tabs button{height:32px;border:0;border-radius:6px;background:transparent;color:var(--text-muted);font-size:13px;cursor:pointer}
|
|
87
|
+
.wsr-tabs button.on{background:var(--bg-raised);color:var(--text)}
|
|
88
|
+
.wsr-from{flex:none;padding:8px 20px;font-size:12px;color:var(--ws-faint);overflow-wrap:anywhere}
|
|
89
|
+
|
|
90
|
+
/* The set beside it, the open item marked. */
|
|
91
|
+
.wsr-set{flex:none;width:300px;display:flex;flex-direction:column;background:var(--bg-panel);min-height:0}
|
|
92
|
+
.wsr-set-h{display:flex;align-items:center;gap:8px;padding:14px 14px 4px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:14px}
|
|
93
|
+
.wsr-set-m{font-family:ui-sans-serif,system-ui,sans-serif;font-size:12px;color:var(--ws-muted)}
|
|
94
|
+
.wsr-set-n{padding:0 14px 8px;font-size:12px;color:var(--ws-muted)}
|
|
95
|
+
.wsr-set-rows{flex:1;min-height:0;overflow:auto;padding:0 8px;display:flex;flex-direction:column;gap:1px}
|
|
96
|
+
.wsr-item{cursor:pointer}
|
|
97
|
+
.wsr-item.on{background:var(--accent-bg);color:var(--text);box-shadow:inset 0 0 0 1px var(--accent-border)}
|
|
98
|
+
.wsr-set-hint{padding:12px 14px;font-size:11.5px;line-height:17px;color:var(--ws-faint);border-top:1px solid var(--border)}
|
|
99
|
+
|
|
100
|
+
/* A phone: full screen, ‹ Set and ‹ ›, no set beside it. */
|
|
101
|
+
@media (max-width:599px){
|
|
102
|
+
.ws-reader{position:fixed;z-index:60;border-radius:0}
|
|
103
|
+
.wsr-main{border-right:0}
|
|
104
|
+
.wsr-set{display:none}
|
|
105
|
+
.wsr-wide{display:none}
|
|
106
|
+
.wsr-narrow{display:inline}
|
|
107
|
+
.wsr-head{gap:8px;padding:calc(8px + var(--safe-t,0px)) 8px 6px}
|
|
108
|
+
.wsr-back{min-width:44px;height:44px;border:0;padding:0 6px;color:var(--accent);font-size:15px;text-align:left}
|
|
109
|
+
.wsr-title{flex:1;flex-direction:column;align-items:center;gap:0;text-align:center}
|
|
110
|
+
.wsr-name{max-width:100%;font-size:14px}
|
|
111
|
+
.wsr-meta{font-size:11.5px}
|
|
112
|
+
.wsr-head-pill{display:none}
|
|
113
|
+
.wsr-nav{display:flex}
|
|
114
|
+
.wsr-strip{padding:10px 14px}
|
|
115
|
+
.wsr-strip-k{display:none}
|
|
116
|
+
.wsr-bar{height:8px}
|
|
117
|
+
.wsr-body{padding:10px 0;gap:10px}
|
|
118
|
+
.wsr-card{border-left:0;border-right:0;border-radius:0}
|
|
119
|
+
.wsr-lines{font-size:11.5px;line-height:18px}
|
|
120
|
+
.wsr-card .read-lines code{min-width:max-content}
|
|
121
|
+
.wsr-banner,.wsr-tabs{margin:10px 12px 0}
|
|
122
|
+
.wsr-tabs{max-width:none}
|
|
123
|
+
.wsr-from{padding:8px 14px}
|
|
124
|
+
.wsr-foot{display:block;flex:none;padding:8px 14px calc(10px + var(--safe-b,0px));border-top:1px solid var(--border);background:var(--bg-panel);font-size:12px;color:var(--ws-faint);text-align:center}
|
|
125
|
+
}
|
|
126
|
+
@media (min-width:600px){.wsr-chips{display:none}}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// The working set's reader (scene A of the working-set preview): what chi
|
|
2
|
+
// has of one item, as its timeline, newest first (ws_timeline.js cards,
|
|
3
|
+
// ws_cards.js templates): a file's reads as merged line slices over a strip
|
|
4
|
+
// of the whole file, its edits as diffs, a memory's reads with their
|
|
5
|
+
// overlay and, for a changed one, "Now · diff"; a slice chi no longer has
|
|
6
|
+
// greyed. It replaces the stage (#center: the history and the composer,
|
|
7
|
+
// kept under it, inert, so their scroll place stays) until "← Stage" or
|
|
8
|
+
// Esc; the session's set stays beside it with the open item marked, ↑↓
|
|
9
|
+
// step through it. On a phone it is full screen: ‹ Set back to the list's
|
|
10
|
+
// sheet, ‹ › the other items.
|
|
11
|
+
//
|
|
12
|
+
// Ways in: the popover peek's "Open the timeline" (ws_peek.js), a tool
|
|
13
|
+
// row's "timeline" (ws_way_in.js), the ref ▾ menu's "What chi has" on a
|
|
14
|
+
// file in the set (refs.js REF_ACTIONS.file, its env's +whatChiHas+). All
|
|
15
|
+
// the owner's: app.js makes this only for a viewer with working_set_items.
|
|
16
|
+
//
|
|
17
|
+
// The timeline comes from the item route (getWorkingSetItem); an answer for
|
|
18
|
+
// an item no longer open, or another session, is dropped (latest.js). While
|
|
19
|
+
// open, each new server snapshot asks again (the route builds from the
|
|
20
|
+
// session's messages, which lag a running turn's events). Leaving the
|
|
21
|
+
// session (another one, the start page) resets it: session_view.js
|
|
22
|
+
// forgetSession calls reset(), so #center is never left inert under it.
|
|
23
|
+
|
|
24
|
+
import { html, nothing, render } from "./vendor/lit-html.js";
|
|
25
|
+
import { api } from "./data.js";
|
|
26
|
+
import { createLatest } from "./latest.js";
|
|
27
|
+
import { diffTemplate } from "./diff_view.js";
|
|
28
|
+
import { createPeek } from "./ws_peek.js";
|
|
29
|
+
import { setTimelineWayIn } from "./ws_way_in.js";
|
|
30
|
+
import { cardTemplate } from "./ws_cards.js";
|
|
31
|
+
import { bandBox, countsText, eventTag, fileStrip, itemPath, linesText, timelineCards } from "./ws_timeline.js";
|
|
32
|
+
import { GLYPHS, leafText, opsText, steerId, steerLine, tokensText } from "./working_set.js";
|
|
33
|
+
|
|
34
|
+
// The item route's answer for session +id+ (+now+: a memory's text now).
|
|
35
|
+
export function getWorkingSetItem(id, kind, key, { now = false } = {}) {
|
|
36
|
+
return api(itemPath(id, kind, key, { now }));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const PHONE_MAX = 600;
|
|
40
|
+
|
|
41
|
+
// The head's pill: what is true of the item as a whole.
|
|
42
|
+
function itemPill(item, events) {
|
|
43
|
+
if (item.state === "stale") return { text: item.kind === "memory" ? "changed since chi read it" : "the file changed since chi saw it", warn: true };
|
|
44
|
+
if (item.state === "dropped") return { text: "dropped by you: chi no longer has it", warn: false };
|
|
45
|
+
if (item.state === "forgotten") return { text: "chi no longer has it", warn: false };
|
|
46
|
+
const edits = events.filter((e) => e.op === "edit" || e.op === "write").length;
|
|
47
|
+
return edits ? { text: `chi edited it ${edits}× · newest first`, warn: true } : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// What an item is called in the head: a file by its path in the session's
|
|
51
|
+
// folder, a memory by its name.
|
|
52
|
+
function itemName(item) {
|
|
53
|
+
if (item.kind === "file") return item.path || item.key;
|
|
54
|
+
if (item.kind === "url") return item.url || item.key;
|
|
55
|
+
return `${GLYPHS.memory} ${item.key}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// +centerEl+: what the reader covers (#center); +session()+, +state()+: the
|
|
59
|
+
// open session's id and fields (its folder: the undrop line); +getItem+: the
|
|
60
|
+
// item route (tests pass a stand-in); +sendLine(line)+: a steer line
|
|
61
|
+
// (undrop; null: none).
|
|
62
|
+
export function createWorkingSetPreview({ centerEl, session, state = () => ({}), getItem = getWorkingSetItem, sendLine = null,
|
|
63
|
+
doc = document, win = window }) {
|
|
64
|
+
let workingSet = null;
|
|
65
|
+
// The open item ({kind, key}), its answer, the memory's now, the tab.
|
|
66
|
+
let open = null;
|
|
67
|
+
let data = null;
|
|
68
|
+
let failed = false;
|
|
69
|
+
let tab = "has";
|
|
70
|
+
let openFor = null;
|
|
71
|
+
const latest = createLatest(() => `${session()}|${open ? `${open.kind}:${open.key}` : ""}`);
|
|
72
|
+
const peek = createPeek({ session, getItem: (id, kind, key) => getItem(id, kind, key), onChange: () => workingSet?.peekChanged() });
|
|
73
|
+
|
|
74
|
+
const el = doc.createElement("section");
|
|
75
|
+
el.className = "ws-reader";
|
|
76
|
+
el.id = "wsReader";
|
|
77
|
+
el.setAttribute("aria-label", "What chi has");
|
|
78
|
+
el.hidden = true;
|
|
79
|
+
centerEl?.appendChild(el);
|
|
80
|
+
const covered = () => [...(centerEl?.children || [])].filter((child) => child !== el);
|
|
81
|
+
|
|
82
|
+
const items = () => workingSet?.items() || [];
|
|
83
|
+
// The rows the set beside it draws (and ↑↓, ‹ › step over): not the muted.
|
|
84
|
+
const shown = () => items().filter((it) => !it.muted);
|
|
85
|
+
// Where focus was when it opened: it goes back there on close.
|
|
86
|
+
let returnTo = null;
|
|
87
|
+
const idOf = (it) => steerId(it);
|
|
88
|
+
// The open item as the set has it (its runs, state, tokens); a stand-in
|
|
89
|
+
// when the set doesn't hold it (yet).
|
|
90
|
+
const current = () => items().find((it) => it.kind === open?.kind && it.key === open?.key)
|
|
91
|
+
|| (open ? { kind: open.kind, key: open.key, label: open.key, ops: [], state: "live", runs: [] } : null);
|
|
92
|
+
|
|
93
|
+
function load() {
|
|
94
|
+
const id = session();
|
|
95
|
+
if (!id || !open) return;
|
|
96
|
+
const fresh = latest.begin();
|
|
97
|
+
const { kind, key } = open;
|
|
98
|
+
Promise.resolve()
|
|
99
|
+
.then(() => getItem(id, kind, key, { now: kind === "memory" }))
|
|
100
|
+
.then((answer) => {
|
|
101
|
+
if (!fresh()) return;
|
|
102
|
+
data = answer;
|
|
103
|
+
failed = false;
|
|
104
|
+
draw();
|
|
105
|
+
})
|
|
106
|
+
.catch(() => {
|
|
107
|
+
if (!fresh()) return;
|
|
108
|
+
failed = true;
|
|
109
|
+
draw();
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function stripTemplate(events) {
|
|
114
|
+
const strip = fileStrip(events);
|
|
115
|
+
if (!strip) return nothing;
|
|
116
|
+
const merged = strip.bands.filter((b) => !b.latest).sort((a, b) => a.first - b.first);
|
|
117
|
+
const ranges = merged.map((b) => `${b.first}–${b.last}`).join(", ");
|
|
118
|
+
const bands = strip.bands.map((band) => {
|
|
119
|
+
const box = bandBox(band, strip.length);
|
|
120
|
+
return html`<button type="button" class=${`wsr-band ${band.state}${band.latest ? " latest" : ""}`} data-wsr="band" data-first=${band.first} style=${`left:${box.left};width:${box.width}`} title=${`${linesText(band)}${band.state === "sent" ? "" : ` (${band.state})`}: go to its lines`}></button>`;
|
|
121
|
+
});
|
|
122
|
+
const chips = merged.map((band) => html`<button type="button" class=${`wsr-chip ${band.state}`} data-wsr="band" data-first=${band.first}>${band.first}–${band.last}</button>`);
|
|
123
|
+
return html`<div class="wsr-strip"><div class="wsr-strip-k"><span>1</span><span>read: ${ranges} of ${strip.length} lines known · tap a band to jump</span><span>${strip.length}</span></div><div class="wsr-bar" aria-label=${`read ${ranges} of ${strip.length} lines`}>${bands}</div><div class="wsr-chips">${chips}</div></div>`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function memoryTemplate(item, events) {
|
|
127
|
+
const now = data?.now;
|
|
128
|
+
const changed = item.state === "stale" && now;
|
|
129
|
+
const lastRead = events.filter((e) => e.op === "memory_read").at(-1);
|
|
130
|
+
const memory = lastRead?.memory;
|
|
131
|
+
const banner = changed ? html`<div class="wsr-banner">Changed since chi's last read${lastRead ? ` (${eventTag(lastRead, item)})` : ""}: what chi has is not what the memory says now.</div>` : nothing;
|
|
132
|
+
const tabs = changed ? html`<div class="wsr-tabs" role="tablist"><button type="button" role="tab" aria-selected=${String(tab === "has")} class=${tab === "has" ? "on" : ""} data-wsr="tab" data-tab="has">What chi has</button><button type="button" role="tab" aria-selected=${String(tab === "now")} class=${tab === "now" ? "on" : ""} data-wsr="tab" data-tab="now">Now · diff</button></div>` : nothing;
|
|
133
|
+
const from = memory?.path ? html`<div class="wsr-from">${memory.scope} memory · from ${memory.path.replace(/[^/]*$/, "")}</div>` : nothing;
|
|
134
|
+
return { banner, tabs, from, nowBody: changed && tab === "now" ? (now.gone ? html`<div class="diff-note warn">the memory's file is gone</div>` : html`<article class="wsr-card now"><header class="wsr-card-h"><span class="wsr-card-t">what chi has → now</span></header>${diffTemplate(now.diff)}</article>`) : null };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function setTemplate(item) {
|
|
138
|
+
const rows = shown().map((it) => {
|
|
139
|
+
const on = it.kind === item.kind && it.key === item.key;
|
|
140
|
+
const state = it.state && it.state !== "live" ? ` ${it.state}` : "";
|
|
141
|
+
return html`<button type="button" class=${`ws-row wsr-item ${it.kind}${state}${on ? " on" : ""}`} data-wsr="item" data-ws-id=${idOf(it)} aria-current=${on ? "true" : "false"}><span class="k">${GLYPHS[it.kind] || ""}</span><span class="t">${leafText(it)}</span><span class="st">${opsText(it)}</span></button>`;
|
|
142
|
+
});
|
|
143
|
+
const files = items().filter((it) => it.kind === "file").length;
|
|
144
|
+
const memories = items().filter((it) => it.kind === "memory").length;
|
|
145
|
+
const pct = Number.isFinite(state().ctxPct) ? ` · ctx ${Math.round(state().ctxPct)} %` : "";
|
|
146
|
+
return html`<aside class="wsr-set" aria-label="Working set"><div class="wsr-set-h"><strong>working set</strong><span class="wsr-set-m">session</span></div><div class="wsr-set-n">${items().length} items${pct} · files · ${files} · memories · ${memories}</div><div class="wsr-set-rows">${rows}</div><div class="wsr-set-hint">↑↓ steps through the set · Esc back to the stage (same scroll place)</div></aside>`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function draw() {
|
|
150
|
+
if (!open) return;
|
|
151
|
+
const item = current();
|
|
152
|
+
const events = data?.events || [];
|
|
153
|
+
const cards = timelineCards(events);
|
|
154
|
+
const tokens = tokensText(item.tokens);
|
|
155
|
+
const counts = countsText(events);
|
|
156
|
+
const pill = data ? itemPill(item, events) : null;
|
|
157
|
+
const memory = item.kind === "memory" ? memoryTemplate(item, events) : null;
|
|
158
|
+
const scope = item.kind === "memory" ? events.find((e) => e.memory)?.memory?.scope : null;
|
|
159
|
+
const meta = [scope ? `${scope} memory` : "", "timeline, newest first", counts, tokens ? `${tokens} tokens` : ""].filter(Boolean).join(" · ");
|
|
160
|
+
const phoneMeta = [scope ? `${scope} memory` : "", counts, tokens ? `${tokens} tokens` : ""].filter(Boolean).join(" · ");
|
|
161
|
+
const undrop = sendLine && (item.state === "dropped" || item.hasDrop) ? html`<button type="button" class="ws-act-b" data-wsr="undrop">undrop</button>` : nothing;
|
|
162
|
+
let body;
|
|
163
|
+
if (failed) body = html`<div class="wsr-note">Couldn't load what chi has of it.</div>`;
|
|
164
|
+
else if (!data) body = html`<div class="wsr-note">Loading…</div>`;
|
|
165
|
+
else if (!cards.length) body = html`<div class="wsr-note">Nothing of it in the conversation yet: a running turn's reads show at its next step.</div>`;
|
|
166
|
+
else if (memory?.nowBody) body = memory.nowBody;
|
|
167
|
+
else body = cards.map((card) => cardTemplate(card, { item, undrop }));
|
|
168
|
+
const list = shown();
|
|
169
|
+
const at = list.findIndex((it) => it.kind === item.kind && it.key === item.key);
|
|
170
|
+
const tpl = html`<div class="wsr-main">
|
|
171
|
+
<div class="wsr-head">
|
|
172
|
+
<button type="button" class="wsr-back" data-wsr="back"><span class="wsr-wide">← Stage</span><span class="wsr-narrow">‹ Set</span></button>
|
|
173
|
+
<span class="wsr-title"><span class="wsr-name" title=${item.key}>${itemName(item)}</span><span class="wsr-meta wsr-wide">${meta}</span><span class="wsr-meta wsr-narrow">${phoneMeta}</span></span>
|
|
174
|
+
${pill ? html`<span class=${`wsr-head-pill${pill.warn ? " warn" : ""}`}>${pill.text}</span>` : nothing}
|
|
175
|
+
<span class="wsr-nav wsr-narrow"><button type="button" data-wsr="prev" aria-label="Previous item" ?disabled=${at <= 0}>‹</button><button type="button" data-wsr="next" aria-label="Next item" ?disabled=${at < 0 || at >= list.length - 1}>›</button></span>
|
|
176
|
+
</div>
|
|
177
|
+
${memory ? memory.banner : nothing}${memory ? memory.tabs : nothing}
|
|
178
|
+
${item.kind === "file" ? stripTemplate(events) : nothing}
|
|
179
|
+
<div class="wsr-body" tabindex="-1">${body}</div>
|
|
180
|
+
${memory ? memory.from : nothing}
|
|
181
|
+
<div class="wsr-foot wsr-narrow">‹ › the next item · lines don't wrap, scroll sideways in the code</div>
|
|
182
|
+
</div>${setTemplate(item)}`;
|
|
183
|
+
render(tpl, el);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Opens +target+ ({kind, key}): the stage stays under it, inert.
|
|
187
|
+
function openItem(target) {
|
|
188
|
+
if (!target?.kind || !target.key) return;
|
|
189
|
+
const again = open && open.kind === target.kind && open.key === target.key;
|
|
190
|
+
open = { kind: target.kind, key: target.key };
|
|
191
|
+
openFor = session();
|
|
192
|
+
if (!again) {
|
|
193
|
+
data = null;
|
|
194
|
+
failed = false;
|
|
195
|
+
tab = "has";
|
|
196
|
+
}
|
|
197
|
+
if (el.hidden) {
|
|
198
|
+
const active = doc.activeElement;
|
|
199
|
+
returnTo = active && active !== doc.body && !el.contains(active) ? active : null;
|
|
200
|
+
for (const child of covered()) child.inert = true;
|
|
201
|
+
el.hidden = false;
|
|
202
|
+
doc.body.classList.add("ws-reading");
|
|
203
|
+
}
|
|
204
|
+
draw();
|
|
205
|
+
el.querySelector(".wsr-body")?.scrollTo?.(0, 0);
|
|
206
|
+
el.querySelector(".wsr-back")?.focus({ preventScroll: true });
|
|
207
|
+
load();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// +refocus+: focus goes back where it was at the open (not for a jump,
|
|
211
|
+
// which scrolls to its row, nor a reset).
|
|
212
|
+
function close({ refocus = true } = {}) {
|
|
213
|
+
if (el.hidden) return;
|
|
214
|
+
open = null;
|
|
215
|
+
data = null;
|
|
216
|
+
latest.drop();
|
|
217
|
+
el.hidden = true;
|
|
218
|
+
for (const child of covered()) child.inert = false;
|
|
219
|
+
doc.body.classList.remove("ws-reading");
|
|
220
|
+
render(nothing, el);
|
|
221
|
+
const back = returnTo;
|
|
222
|
+
returnTo = null;
|
|
223
|
+
if (refocus && back?.isConnected && !back.closest?.("[inert]")) back.focus?.({ preventScroll: true });
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// The item +step+ places from the open one in the set.
|
|
227
|
+
function stepItem(step) {
|
|
228
|
+
const list = shown();
|
|
229
|
+
const at = list.findIndex((it) => it.kind === open?.kind && it.key === open?.key);
|
|
230
|
+
const next = list[at + step];
|
|
231
|
+
if (next) openItem(next);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const phone = () => win.innerWidth < PHONE_MAX;
|
|
235
|
+
|
|
236
|
+
el.addEventListener("click", (e) => {
|
|
237
|
+
const act = e.target.closest("[data-wsr], [data-ws='jump']");
|
|
238
|
+
if (!act) return;
|
|
239
|
+
if (act.dataset.ws === "jump") {
|
|
240
|
+
const [turn, step, row] = String(act.dataset.at).split(".").map(Number);
|
|
241
|
+
close({ refocus: false });
|
|
242
|
+
workingSet?.jump({ turn, step, row });
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const what = act.dataset.wsr;
|
|
246
|
+
if (what === "back") {
|
|
247
|
+
close();
|
|
248
|
+
// After this click has passed the list's outside-click close.
|
|
249
|
+
if (phone()) setTimeout(() => workingSet?.openList(), 0);
|
|
250
|
+
} else if (what === "item") {
|
|
251
|
+
const found = items().find((it) => idOf(it) === act.dataset.wsId);
|
|
252
|
+
if (found) openItem(found);
|
|
253
|
+
} else if (what === "prev") stepItem(-1);
|
|
254
|
+
else if (what === "next") stepItem(1);
|
|
255
|
+
else if (what === "tab") {
|
|
256
|
+
tab = act.dataset.tab === "now" ? "now" : "has";
|
|
257
|
+
draw();
|
|
258
|
+
} else if (what === "band") {
|
|
259
|
+
const first = Number(act.dataset.first);
|
|
260
|
+
const card = [...el.querySelectorAll(".wsr-card.slice")].find((c) => c.querySelector(`.read-line[data-line="${first}"]`));
|
|
261
|
+
card?.scrollIntoView?.({ block: "start" });
|
|
262
|
+
} else if (what === "undrop" && sendLine) {
|
|
263
|
+
const item = current();
|
|
264
|
+
Promise.resolve(sendLine(steerLine("undrop", [item], state().dir))).catch(() => {});
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
doc.addEventListener("keydown", (e) => {
|
|
269
|
+
if (el.hidden || e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
270
|
+
if (e.target?.closest?.("input, textarea, [contenteditable]")) return;
|
|
271
|
+
// A popover over the reader takes its own Esc.
|
|
272
|
+
if (doc.querySelector(".ctx-popover:not([hidden])")) return;
|
|
273
|
+
if (e.key === "Escape") {
|
|
274
|
+
e.preventDefault();
|
|
275
|
+
close();
|
|
276
|
+
} else if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
277
|
+
e.preventDefault();
|
|
278
|
+
stepItem(e.key === "ArrowDown" ? 1 : -1);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// A tool row's "timeline" (ws_way_in.js).
|
|
283
|
+
doc.addEventListener("click", (e) => {
|
|
284
|
+
const button = e.target.closest?.(".activity-ws[data-ws-kind]");
|
|
285
|
+
if (!button) return;
|
|
286
|
+
e.preventDefault();
|
|
287
|
+
openItem({ kind: button.dataset.wsKind, key: button.dataset.wsKey });
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
peek,
|
|
292
|
+
// The working set's view (working_set_view.js), once made: the set,
|
|
293
|
+
// its jumps and its list; rows get their way in from now on.
|
|
294
|
+
attach(view) {
|
|
295
|
+
workingSet = view;
|
|
296
|
+
if (!view) return;
|
|
297
|
+
setTimelineWayIn(true);
|
|
298
|
+
// A new snapshot: asked again (a snapshot of another session: closed,
|
|
299
|
+
// though forgetSession's reset has done it already).
|
|
300
|
+
view.onServer(() => {
|
|
301
|
+
if (el.hidden) return;
|
|
302
|
+
if (session() !== openFor) close({ refocus: false });
|
|
303
|
+
else load();
|
|
304
|
+
});
|
|
305
|
+
},
|
|
306
|
+
open: openItem,
|
|
307
|
+
close,
|
|
308
|
+
isOpen: () => !el.hidden,
|
|
309
|
+
// The ref ▾ menu's "What chi has" (refs.js): a file ref whose path is
|
|
310
|
+
// an item of the set.
|
|
311
|
+
whatChiHas: {
|
|
312
|
+
has: (path) => items().some((it) => it.kind === "file" && it.key === path),
|
|
313
|
+
open: (path) => openItem({ kind: "file", key: path }),
|
|
314
|
+
},
|
|
315
|
+
// The session forgotten (another one, the start page: session_view.js
|
|
316
|
+
// forgetSession): closed, the stage no longer inert.
|
|
317
|
+
reset() { close({ refocus: false }); peek.close(); },
|
|
318
|
+
};
|
|
319
|
+
}
|