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,66 @@
|
|
|
1
|
+
// Revise on a participant's page: the answers to their own messages only,
|
|
2
|
+
// as chi web and the worker decide it (ParticipantRevise, from the author
|
|
3
|
+
// the server stamped; this is the page's mirror, so it shows a button only
|
|
4
|
+
// where a send would be taken). revise_stack.js draws the stacks for every
|
|
5
|
+
// viewer; this module answers its mayRevise, and app.js wires it for a
|
|
6
|
+
// participant (viewer.can("revise_own_turn")).
|
|
7
|
+
//
|
|
8
|
+
// A module of its own: static JS is cached at unversioned URLs, and a new
|
|
9
|
+
// export on an old module would blank the page.
|
|
10
|
+
import { viewerSelf } from "./viewer_self.js";
|
|
11
|
+
import { workerPredates } from "./worker_features.js";
|
|
12
|
+
|
|
13
|
+
// The worker feature their Revise needs (ReviseAnchor::PARTICIPANT_FEATURE):
|
|
14
|
+
// a worker that checks it at the stamp.
|
|
15
|
+
export const PARTICIPANT_REVISE_FEATURE = "participant_revise";
|
|
16
|
+
|
|
17
|
+
// The button's title and the chip's words while a live worker lacks it.
|
|
18
|
+
// The copy of ParticipantMessages::REVISE_UNAVAILABLE (its Ruby owner), the
|
|
19
|
+
// only one on the page: a refused send shows the server's own detail.
|
|
20
|
+
export const PARTICIPANT_REVISE_UNAVAILABLE = "this session's worker is too old for you to revise an answer: ask the session's owner to restart it";
|
|
21
|
+
|
|
22
|
+
// The pre-send gate (worker_features.js's rule): a live worker without it.
|
|
23
|
+
export function participantReviseUnavailable(workerFeatures, bridgeUp) {
|
|
24
|
+
return workerPredates(workerFeatures, bridgeUp, PARTICIPANT_REVISE_FEATURE);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Whether a prompt bubble is +author+'s: its data-author (a reload's, a live
|
|
28
|
+
// echo's), or this tab's own echo.
|
|
29
|
+
function ownPrompt(prompt, author) {
|
|
30
|
+
return !!prompt && (prompt.dataset?.author === author || prompt.dataset?.own === "1");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Rules 1–2 on historyTurns' list (+turns+, revise_stack.js), in one
|
|
34
|
+
// backward pass: the turns +author+ may revise, each opening with their
|
|
35
|
+
// prompt, answered, not a Verify turn, and with only their own turns after
|
|
36
|
+
// it (none of the owner's, another participant's or a wake turn's). The
|
|
37
|
+
// owner's `!` lines never reach their page, so they count for nothing here
|
|
38
|
+
// either. @return Set of turns
|
|
39
|
+
export function revisableOwn(turns, author) {
|
|
40
|
+
const ok = new Set();
|
|
41
|
+
if (!author || !Array.isArray(turns)) return ok;
|
|
42
|
+
for (let i = turns.length - 1; i >= 0; i--) {
|
|
43
|
+
const t = turns[i];
|
|
44
|
+
const own = !t.wake && ownPrompt(t.prompt, author);
|
|
45
|
+
if (!own) break;
|
|
46
|
+
if (t.answer && !t.prompt.hasAttribute?.("data-verify")) ok.add(t);
|
|
47
|
+
}
|
|
48
|
+
return ok;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Whether the turn at +index+ is one of revisableOwn's.
|
|
52
|
+
export function mayReviseOwn(turns, index, author) {
|
|
53
|
+
return Array.isArray(turns) && revisableOwn(turns, author).has(turns[index]);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// revise_stack.js's mayRevise for the viewer looking (viewer_self.js), false
|
|
57
|
+
// while their composer is closed (+closed+(): cap reached, link ended,
|
|
58
|
+
// session stopped). One pass per decorate: its +turns+ list is read once.
|
|
59
|
+
export function participantMayRevise(closed = () => false) {
|
|
60
|
+
let last = null;
|
|
61
|
+
return (turn, turns) => {
|
|
62
|
+
if (closed()) return false;
|
|
63
|
+
if (last?.turns !== turns) last = { turns, ok: revisableOwn(turns, viewerSelf()?.author) };
|
|
64
|
+
return last.ok.has(turn);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
// expiry, cap, and behind an auth proxy that names the signed-in user their
|
|
6
6
|
// email, which binds the link to that account) gives the link once, to
|
|
7
7
|
// copy, share (a phone's share sheet)
|
|
8
|
-
// or scan (its QR)
|
|
9
|
-
// participant sees this session (through the server's filter), in a new
|
|
10
|
-
// tab. The panel reads GET /api/sessions/:id/participants, again after
|
|
8
|
+
// or scan (its QR). The panel reads GET /api/sessions/:id/participants, again after
|
|
11
9
|
// every change and on a participants_changed event.
|
|
12
10
|
//
|
|
13
11
|
// The names it learns feed the author badges on participants' prompts
|
|
@@ -63,13 +61,13 @@ export function rowModel(grant, now) {
|
|
|
63
61
|
return {
|
|
64
62
|
id: grant.id,
|
|
65
63
|
name: grant.name,
|
|
66
|
-
kind: grant.kind,
|
|
67
64
|
identity: typeof grant.identity === "string" ? grant.identity : null,
|
|
68
65
|
active,
|
|
69
66
|
present,
|
|
70
67
|
color: authorColor(participantAuthor(grant.id)),
|
|
71
68
|
state: active ? (present ? "here now" : `seen ${agoText(grant.last_used_at, now)}`)
|
|
72
|
-
: grant.state === "expired" ? "expired"
|
|
69
|
+
: grant.state === "expired" ? "expired"
|
|
70
|
+
: grant.state === "outdated" ? "ended (older link)" : `revoked${grant.revoked_by ? ` (${grant.revoked_by})` : ""}`,
|
|
73
71
|
expires: active ? `expires ${untilText(grant.expires_at, now)}` : "",
|
|
74
72
|
spend: `${money(spend)} of ${money(cap)}`,
|
|
75
73
|
capReached: active && cap > 0 && spend >= cap,
|
|
@@ -84,7 +82,7 @@ export function chipModel(grants, now) {
|
|
|
84
82
|
if (!Array.isArray(grants)) return null;
|
|
85
83
|
const active = grants.map((g) => rowModel(g, now)).filter((row) => row.active);
|
|
86
84
|
if (active.length === 0) {
|
|
87
|
-
return { text: "participants · invite", count: 0, present: false, title: "Invite
|
|
85
|
+
return { text: "participants · invite", count: 0, present: false, title: "Invite someone into this session" };
|
|
88
86
|
}
|
|
89
87
|
const present = active.filter((row) => row.present).map((row) => row.name);
|
|
90
88
|
const names = active.map((row) => row.name).join(", ");
|
|
@@ -123,12 +121,12 @@ const EMAIL_RE = /^[^@\s,<>"\\]+@[^@\s,<>"\\]+$/;
|
|
|
123
121
|
// (behind a proxy that names the user): their email, which binds the link;
|
|
124
122
|
// the name defaults to its local part.
|
|
125
123
|
// @return {{body}|{error}}
|
|
126
|
-
export function inviteBody({ name,
|
|
124
|
+
export function inviteBody({ name, days, cap, identity }) {
|
|
127
125
|
const email = String(identity || "").trim().toLowerCase();
|
|
128
126
|
if (email && !EMAIL_RE.test(email)) return { error: "An email is one address: name@domain." };
|
|
129
127
|
const clean = String(name || "").trim() || email.split("@")[0];
|
|
130
128
|
if (!clean) return { error: "Give them a name: it is what the model and the thread show." };
|
|
131
|
-
const body = { name: clean
|
|
129
|
+
const body = { name: clean };
|
|
132
130
|
if (email) body.identity = email;
|
|
133
131
|
const d = Number(days);
|
|
134
132
|
body.ttl = Math.round((EXPIRY_DAYS.includes(d) ? d : DEFAULT_EXPIRY_DAYS) * 24 * 60 * 60);
|
|
@@ -140,7 +138,7 @@ export function inviteBody({ name, kind, days, cap, identity }) {
|
|
|
140
138
|
|
|
141
139
|
// The toast for an invite whose panel closed before its answer came.
|
|
142
140
|
export function lateInviteText(name, sessionId) {
|
|
143
|
-
return `${name}'s
|
|
141
|
+
return `${name}'s link for ${String(sessionId).slice(0, 8)} is ready (the panel closed before it came); it shows only once.`;
|
|
144
142
|
}
|
|
145
143
|
|
|
146
144
|
// What Revoke asks first: it can't be undone (chi keeps only the link's
|
|
@@ -149,11 +147,6 @@ export function revokeConfirmText(name) {
|
|
|
149
147
|
return `Revoke ${name}'s link? Their page and stream stop and their queued comments are dropped. This can't be undone: a new invite gives a new link.`;
|
|
150
148
|
}
|
|
151
149
|
|
|
152
|
-
// The participant view's address: the participant page as the owner sees it.
|
|
153
|
-
export function viewURL(sessionId) {
|
|
154
|
-
return `/?as=participant#s=${encodeURIComponent(sessionId)}`;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
150
|
function rowTemplate(row, { capFor }) {
|
|
158
151
|
const actions = row.active ? html`<span class="pp-actions">${capFor === row.id
|
|
159
152
|
? html`<form class="pp-cap-form" data-id=${row.id}><input name="cap" type="text" inputmode="decimal" autocomplete="off"
|
|
@@ -163,8 +156,7 @@ function rowTemplate(row, { capFor }) {
|
|
|
163
156
|
title=${`End ${row.name}'s link: their page and stream stop, their queued comments are dropped`}>Revoke</button></span>`
|
|
164
157
|
: nothing;
|
|
165
158
|
return html`<li class=${`pp-row${row.active ? "" : " ended"}`} style=${`--author-color:${row.color}`}>
|
|
166
|
-
<div class="pp-who"><span class=${`pp-dot${row.present ? " present" : ""}`} aria-hidden="true"></span><b>${row.name}</b>${
|
|
167
|
-
row.kind === "agent" ? html`<span class="pp-tag">agent</span>` : nothing}<span class="pp-state">${row.state}</span></div>
|
|
159
|
+
<div class="pp-who"><span class=${`pp-dot${row.present ? " present" : ""}`} aria-hidden="true"></span><b>${row.name}</b><span class="pp-state">${row.state}</span></div>
|
|
168
160
|
<div class="pp-meta"><span class=${row.capReached ? "pp-capped" : ""}>${row.spend}</span> · ${row.turns}${
|
|
169
161
|
row.expires ? html` · ${row.expires}` : nothing}${row.identity ? html` · <span class="pp-bound">bound to ${row.identity}</span>` : nothing}</div>${actions}</li>`;
|
|
170
162
|
}
|
|
@@ -173,7 +165,7 @@ function rowTemplate(row, { capFor }) {
|
|
|
173
165
|
// have no contact word in them (no_contact_fill.js): iOS Safari's AutoFill
|
|
174
166
|
// Contact bar, offered on a "name" or an email field, then stays on the
|
|
175
167
|
// page's later fields, the composer's too.
|
|
176
|
-
export const INVITE_FIELDS = { name: "chi-invitee",
|
|
168
|
+
export const INVITE_FIELDS = { name: "chi-invitee", days: "days", cap: "cap", identity: "chi-invitee-account" };
|
|
177
169
|
|
|
178
170
|
function inviteTemplate(invite, { canShare }) {
|
|
179
171
|
if (!invite) return nothing;
|
|
@@ -182,44 +174,39 @@ function inviteTemplate(invite, { canShare }) {
|
|
|
182
174
|
invite.identity ? `, for ${invite.identity} only` : ""}.${
|
|
183
175
|
invite.lan ? nothing : " This chi web has no LAN address: the link opens on this machine only."}</div>
|
|
184
176
|
${invite.warning ? html`<div class="pp-warning" role="note">${invite.warning}</div>` : nothing}
|
|
185
|
-
<div class="pp-link"><input readonly .value=${invite.link} aria-label="The
|
|
177
|
+
<div class="pp-link"><input readonly .value=${invite.link} aria-label="The invite link" @focus=${(e) => e.target.select()}><button
|
|
186
178
|
type="button" data-act="copy">${invite.copied ? "Copied ✓" : "Copy"}</button>${canShare
|
|
187
179
|
? html`<button type="button" data-act="share">Share…</button>` : nothing}</div>
|
|
188
180
|
${invite.qr_svg ? html`<div class="pp-qr" .innerHTML=${invite.qr_svg}></div>` : nothing}</div>`;
|
|
189
181
|
}
|
|
190
182
|
|
|
191
|
-
// The empty list's line
|
|
192
|
-
export const
|
|
193
|
-
export const EMPTY_PAIR = "Nobody yet. Invite a person (or an agent) to work with you here: their turns act with this session's tools under your guardrails, and their asks come to you.";
|
|
183
|
+
// The empty list's line.
|
|
184
|
+
export const EMPTY = "Nobody yet. Invite someone to work with you here: their turns act with this session's tools under your guardrails, and their asks come to you.";
|
|
194
185
|
|
|
195
186
|
// The popover's content: the participants, the Invite form (or the link it
|
|
196
|
-
// gave)
|
|
197
|
-
// +working+: the server's warning
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
// working session on a worker with pair turns): the empty list says their
|
|
201
|
-
// turns act; otherwise (a review session, an older worker) that they read.
|
|
187
|
+
// gave).
|
|
188
|
+
// +working+: the server's warning (GET …/participants: what a participant's
|
|
189
|
+
// turns do here, or why nobody can be invited until the session restarts),
|
|
190
|
+
// shown before the Invite.
|
|
202
191
|
// +identityHeader+: the header chi web's auth proxy names the signed-in
|
|
203
192
|
// user in (the list's identity_header), null without one: then the Invite
|
|
204
193
|
// has no account field (a bound link could never open).
|
|
205
194
|
export function panelTemplate(grants, { now, sessionId, invite = null, error = null, capFor = null, canShare = false,
|
|
206
|
-
busy = false, working = null,
|
|
207
|
-
pair = false } = {}) {
|
|
195
|
+
busy = false, working = null, identityHeader = null } = {}) {
|
|
208
196
|
const rows = (grants || []).map((g) => rowModel(g, now));
|
|
209
197
|
const active = rows.filter((row) => row.active);
|
|
210
198
|
const ended = rows.filter((row) => !row.active);
|
|
211
199
|
return html`<div class="ctx-pop-head"><strong>Participants</strong><span class="ctx-pop-kind">this session</span
|
|
212
200
|
><button type="button" class="ctx-pop-close" data-act="close" aria-label="Close">×</button></div>
|
|
213
201
|
${active.length ? html`<ul class="pp-list">${active.map((row) => rowTemplate(row, { capFor }))}</ul>`
|
|
214
|
-
: html`<div class="ctx-pop-meta">${
|
|
202
|
+
: html`<div class="ctx-pop-meta">${EMPTY}</div>`}
|
|
215
203
|
${ended.length ? html`<details class="pp-ended"><summary>Ended (${ended.length})</summary><ul class="pp-list">${
|
|
216
204
|
ended.map((row) => rowTemplate(row, { capFor }))}</ul></details>` : nothing}
|
|
217
205
|
<div class="ctx-pop-error" role="alert" ?hidden=${!error}>${error || ""}</div>
|
|
218
|
-
${working && !invite ? html`<div class="pp-warning pp-working" role="note">${working}
|
|
219
|
-
data-act="start-review" ?disabled=${reviewing}>${reviewing ? "Starting…" : "Start a review of it"}</button></div>` : nothing}
|
|
206
|
+
${working && !invite ? html`<div class="pp-warning pp-working" role="note">${working}</div>` : nothing}
|
|
220
207
|
${invite ? inviteTemplate(invite, { canShare }) : html`<form class="pp-invite">
|
|
221
208
|
<div class="pp-invite-row"><input name="chi-invitee" type="text" placeholder="Who (Alex)" autocomplete="off" aria-label="Who the link is for" maxlength="64"
|
|
222
|
-
|
|
209
|
+
></div>
|
|
223
210
|
${identityHeader ? html`<div class="pp-invite-row"><input name="chi-invitee-account" type="text" inputmode="email"
|
|
224
211
|
placeholder="Their account (alex@example.com)" autocomplete="off" autocapitalize="off" spellcheck="false"
|
|
225
212
|
aria-label="Their sign-in account: the link opens only for it"></div>
|
|
@@ -229,9 +216,7 @@ export function panelTemplate(grants, { now, sessionId, invite = null, error = n
|
|
|
229
216
|
?selected=${d === DEFAULT_EXPIRY_DAYS}>${d === 1 ? "1 day" : `${d} days`}</option>`)}</select></span></label
|
|
230
217
|
><label>Cap $<input name="cap" type="text" inputmode="decimal" placeholder="2" autocomplete="off" aria-label="Spending cap, dollars"></label
|
|
231
218
|
><button type="submit" class="pp-invite-btn" ?disabled=${busy}>Invite</button></div></form>`}
|
|
232
|
-
|
|
233
|
-
class="pp-view" href=${viewURL(sessionId)} target="_blank" rel="noopener"
|
|
234
|
-
title="The participant page for this session, as a participant sees it: through the same filter">Participant view ↗</a></div>`;
|
|
219
|
+
${invite ? html`<div class="ctx-pop-actions pp-foot"><button type="button" data-act="another">Invite another</button></div>` : nothing}`;
|
|
235
220
|
}
|
|
236
221
|
|
|
237
222
|
// The control: el (#infoText, where the chip is drawn), session() the open
|
|
@@ -239,19 +224,11 @@ export function panelTemplate(grants, { now, sessionId, invite = null, error = n
|
|
|
239
224
|
// pid, cap)}, onChange() (the chip's count or presence changed: redraw the
|
|
240
225
|
// bar), toast(text, action, {sticky}) (app.js showToast), onNames() (the participants' names changed: name the
|
|
241
226
|
// badges drawn before them, participant_names.js nameUnnamedBadges).
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
// when the panel showed it); reviewing(): one is under way for the open
|
|
245
|
-
// session (session_actions.js keeps the one-per-session guard).
|
|
246
|
-
export function createParticipantsControl({ el, session, api, onChange = () => {}, toast = () => {}, startReview = null,
|
|
247
|
-
reviewing = () => false, onNames = () => {}, clock = () => Date.now(), doc = document, win = window }) {
|
|
227
|
+
export function createParticipantsControl({ el, session, api, onChange = () => {}, toast = () => {},
|
|
228
|
+
onNames = () => {}, clock = () => Date.now(), doc = document, win = window }) {
|
|
248
229
|
let grants = null;
|
|
249
|
-
// The open session's share warning (GET …/participants), null
|
|
250
|
-
// review session.
|
|
230
|
+
// The open session's share warning (GET …/participants), null until read.
|
|
251
231
|
let working = null;
|
|
252
|
-
// What a participant invited now gets (GET …/participants mode: "pair" or
|
|
253
|
-
// "review", the server's ReviewStart.share_terms), never guessed from the warning.
|
|
254
|
-
let inviteMode = null;
|
|
255
232
|
// The header chi web's proxy names the user in (GET …/participants), null
|
|
256
233
|
// without one: the Invite's account field.
|
|
257
234
|
let identityHeader = null;
|
|
@@ -290,7 +267,7 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
|
|
|
290
267
|
|
|
291
268
|
function draw() {
|
|
292
269
|
render(panelTemplate(grants, { now: clock(), sessionId: session(), invite, error, capFor, busy,
|
|
293
|
-
working
|
|
270
|
+
working, identityHeader,
|
|
294
271
|
canShare: typeof win.navigator?.share === "function" }), shell.pop);
|
|
295
272
|
shell.replace();
|
|
296
273
|
}
|
|
@@ -299,7 +276,6 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
|
|
|
299
276
|
if (!id) {
|
|
300
277
|
grants = null;
|
|
301
278
|
working = null;
|
|
302
|
-
inviteMode = null;
|
|
303
279
|
linkBase = null;
|
|
304
280
|
loadedFor = null;
|
|
305
281
|
setParticipantNames([]);
|
|
@@ -312,7 +288,6 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
|
|
|
312
288
|
if (!still()) return;
|
|
313
289
|
grants = Array.isArray(body.participants) ? body.participants : [];
|
|
314
290
|
working = typeof body.warning === "string" ? body.warning : null;
|
|
315
|
-
inviteMode = typeof body.mode === "string" ? body.mode : null;
|
|
316
291
|
identityHeader = typeof body.identity_header === "string" && body.identity_header ? body.identity_header : null;
|
|
317
292
|
linkBase = typeof body.link_base === "string" && body.link_base ? body.link_base : null;
|
|
318
293
|
loadedFor = id;
|
|
@@ -323,8 +298,7 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
|
|
|
323
298
|
if (loadedFor !== id) {
|
|
324
299
|
grants = [];
|
|
325
300
|
working = null;
|
|
326
|
-
|
|
327
|
-
linkBase = null;
|
|
301
|
+
linkBase = null;
|
|
328
302
|
setParticipantNames([]);
|
|
329
303
|
}
|
|
330
304
|
}
|
|
@@ -369,9 +343,9 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
|
|
|
369
343
|
const copy = async () => {
|
|
370
344
|
try {
|
|
371
345
|
await win.navigator.clipboard.writeText(link);
|
|
372
|
-
toast(`${name}'s
|
|
346
|
+
toast(`${name}'s link copied`);
|
|
373
347
|
} catch {
|
|
374
|
-
toast(`${name}'s
|
|
348
|
+
toast(`${name}'s link: ${link}`, null, { sticky: true });
|
|
375
349
|
}
|
|
376
350
|
};
|
|
377
351
|
toast(lateInviteText(name, asked.id), { label: "Copy link", run: copy }, { sticky: true });
|
|
@@ -419,21 +393,6 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
|
|
|
419
393
|
}
|
|
420
394
|
return load();
|
|
421
395
|
}
|
|
422
|
-
// Closed once the review is made; a refusal stays in the panel.
|
|
423
|
-
if (name === "start-review" && startReview) {
|
|
424
|
-
const asked = ask();
|
|
425
|
-
const showError = (text) => {
|
|
426
|
-
if (!stillOpen(asked) || !shell.isOpen()) return false;
|
|
427
|
-
error = text;
|
|
428
|
-
return true;
|
|
429
|
-
};
|
|
430
|
-
const started = startReview({ onError: showError });
|
|
431
|
-
draw();
|
|
432
|
-
const created = await started;
|
|
433
|
-
if (created) shell.close();
|
|
434
|
-
else if (stillOpen(asked) && shell.isOpen()) draw();
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
396
|
if (name === "another") {
|
|
438
397
|
invite = null;
|
|
439
398
|
return draw();
|
|
@@ -449,7 +408,7 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
|
|
|
449
408
|
}
|
|
450
409
|
if (name === "share" && invite) {
|
|
451
410
|
try {
|
|
452
|
-
await win.navigator.share({ title: "chi
|
|
411
|
+
await win.navigator.share({ title: "chi invite", text: `${invite.name}'s link`, url: invite.link });
|
|
453
412
|
} catch {
|
|
454
413
|
// dismissed
|
|
455
414
|
}
|
|
@@ -462,12 +421,11 @@ export function createParticipantsControl({ el, session, api, onChange = () => {
|
|
|
462
421
|
reload: () => load(),
|
|
463
422
|
chip: () => (session() && loadedFor === session() ? chipModel(grants, clock()) : null),
|
|
464
423
|
// A claim link's target (claim_link.js): {base, names} the open
|
|
465
|
-
// session's participant link base and its active
|
|
466
|
-
//
|
|
467
|
-
// chi web, no person invited).
|
|
424
|
+
// session's participant link base and its active participants' names;
|
|
425
|
+
// null without either (an older chi web, nobody invited).
|
|
468
426
|
claimTarget: () => {
|
|
469
427
|
if (!session() || loadedFor !== session() || !linkBase) return null;
|
|
470
|
-
const names = (grants || []).filter((g) => g.state === "active"
|
|
428
|
+
const names = (grants || []).filter((g) => g.state === "active").map((g) => g.name);
|
|
471
429
|
return names.length ? { base: linkBase, names } : null;
|
|
472
430
|
},
|
|
473
431
|
close: () => shell.close(),
|
|
@@ -24,7 +24,8 @@ import { clientLabel, isOwn } from "./turn_events.js";
|
|
|
24
24
|
import { continueLine } from "./commands.js";
|
|
25
25
|
import { plainText } from "./plain_line.js";
|
|
26
26
|
import { noContactFill } from "./no_contact_fill.js";
|
|
27
|
-
import {
|
|
27
|
+
import { removeSession } from "./storage.js";
|
|
28
|
+
import { CONTINUE_KEY, foldKey, questionKey } from "./stage_waiting.js";
|
|
28
29
|
|
|
29
30
|
// A card's text fields' name: not a contact field (no_contact_fill.js).
|
|
30
31
|
const CARD_NOTE = "chi-card-note";
|
|
@@ -50,6 +51,8 @@ const CARD_NOTE = "chi-card-note";
|
|
|
50
51
|
// @param onPending (pending|null) called whenever the open question changes:
|
|
51
52
|
// the page touches the redraws that read pendingQuestion() (the session
|
|
52
53
|
// bar's waiting chip, docs/internals/web-frontend.md write -> redraw)
|
|
54
|
+
// @param answers false for a viewer who may not answer (viewer.js
|
|
55
|
+
// answer_cards): no question or continue card is drawn at all
|
|
53
56
|
// @param onSettled (key) a card stopped waiting (answered, cancelled,
|
|
54
57
|
// replaced or removed; the continue card resolved or dropped), by its
|
|
55
58
|
// stage_waiting.js key: the stage's waiting cards as data
|
|
@@ -61,7 +64,7 @@ export function createQuestionCards({
|
|
|
61
64
|
sessionId, clientId, place, isNearBottom, scrollToEnd, removeHintIfEmpty, askingText = () => "",
|
|
62
65
|
renderMarkdown = () => Promise.resolve(null), linkRefs = () => {}, pairRefs = () => {},
|
|
63
66
|
api = { sendAnswer, dismissQuestion, sendCommand }, doc = globalThis.document,
|
|
64
|
-
onPending = () => {}, onSettled = () => {},
|
|
67
|
+
onPending = () => {}, onSettled = () => {}, answers = true,
|
|
65
68
|
}) {
|
|
66
69
|
// Live ask_user_question card, keyed by pending question id. Re-rendered from
|
|
67
70
|
// pending_question on session select so a reload mid-question restores it.
|
|
@@ -85,6 +88,7 @@ export function createQuestionCards({
|
|
|
85
88
|
// +said+: the asking reply when the caller knows it (a reloaded card: its
|
|
86
89
|
// step's text, "" for none); else the running turn's (askingText).
|
|
87
90
|
function renderQuestionCard(pq, { said = null } = {}) {
|
|
91
|
+
if (!answers) return;
|
|
88
92
|
const action = nextCardAction({ cardId: questionEl?.dataset.qid ?? null, pendingId: pending?.id ?? null }, pq);
|
|
89
93
|
if (action === "same") return;
|
|
90
94
|
// A resolved card stays where it was; only a pending one is replaced.
|
|
@@ -520,6 +524,11 @@ export function createQuestionCards({
|
|
|
520
524
|
// After the collapse: a card left open by hand renders at once.
|
|
521
525
|
if (full) renderSaidOnOpen(questionEl, full, asked, refs);
|
|
522
526
|
resolvedId = pending.id;
|
|
527
|
+
// Answered or cancelled for good: the fold this tab kept for it is gone
|
|
528
|
+
// (stage_waiting.js). No session id, no key: foldKey(null) is null, and a
|
|
529
|
+
// removeItem(null) would delete the key "null".
|
|
530
|
+
const fold = foldKey(sessionId());
|
|
531
|
+
if (fold) removeSession(fold);
|
|
523
532
|
onSettled(questionKey(questionEl.dataset.qid));
|
|
524
533
|
setPending(null);
|
|
525
534
|
}
|
|
@@ -614,7 +623,7 @@ export function createQuestionCards({
|
|
|
614
623
|
}
|
|
615
624
|
|
|
616
625
|
function renderContinueCard(offer) {
|
|
617
|
-
if (continueEl?.isConnected) return;
|
|
626
|
+
if (!answers || continueEl?.isConnected) return;
|
|
618
627
|
// A step-limit question is up: it is the card (an older worker has none).
|
|
619
628
|
if (isContinue(pending)) return;
|
|
620
629
|
removeHintIfEmpty();
|
|
@@ -678,6 +687,8 @@ export function createQuestionCards({
|
|
|
678
687
|
continueEl = null;
|
|
679
688
|
if (!card) return;
|
|
680
689
|
card.classList.add("resolved");
|
|
690
|
+
const fold = foldKey(sessionId());
|
|
691
|
+
if (fold) removeSession(fold);
|
|
681
692
|
onSettled(CONTINUE_KEY);
|
|
682
693
|
card.querySelectorAll("button, input").forEach((el) => { el.disabled = true; });
|
|
683
694
|
const note = doc.createElement("div");
|
|
@@ -169,8 +169,9 @@ export function editorUrl(template, path, line) {
|
|
|
169
169
|
|
|
170
170
|
// A ref's targets, per kind, in order: the first available one is a plain
|
|
171
171
|
// click's (the main target), all of them are the menu's. Each says when
|
|
172
|
-
// it's available for +
|
|
173
|
-
// editorUrl}, the server's capabilities.editor and editor_url
|
|
172
|
+
// it's available for +refEditor+ (where this page can open a ref: {editor,
|
|
173
|
+
// editorUrl}, the server's capabilities.editor and editor_url; not
|
|
174
|
+
// viewer.js's viewer, which says what the viewer may do at all) and
|
|
174
175
|
// +target+ (refTarget's). A secondary one (copy) joins a ref that has
|
|
175
176
|
// another, never alone. A line (a diff or read line) has its click only.
|
|
176
177
|
// A link whose text is the ref (github-pr's PR diff): its href stays the
|
|
@@ -181,8 +182,8 @@ const LINK = Object.freeze({
|
|
|
181
182
|
id: "link",
|
|
182
183
|
label: (target) => target.actions?.find((action) => sameUrl(action.url, target.href))?.label ||
|
|
183
184
|
(/\/pull\/\d+\/files\b/.test(target.href) ? "PR diff" : "Open link"),
|
|
184
|
-
available: (
|
|
185
|
-
run: (target,
|
|
185
|
+
available: (_refEditor, target) => !!target.href,
|
|
186
|
+
run: (target, _refEditor, env) => env.openLink(target.href),
|
|
186
187
|
});
|
|
187
188
|
|
|
188
189
|
// The ref's own actions (a plugin's, bindRef), one target each, for every
|
|
@@ -196,8 +197,8 @@ const URL_ACTIONS = Object.freeze({
|
|
|
196
197
|
.map((action) => Object.freeze({
|
|
197
198
|
id: `url:${action.id}`,
|
|
198
199
|
label: () => action.label,
|
|
199
|
-
available: (
|
|
200
|
-
run: (_target,
|
|
200
|
+
available: (_refEditor, target) => !target.isLine,
|
|
201
|
+
run: (_target, _refEditor, env) => env.openLink(action.url),
|
|
201
202
|
hint: () => action.url,
|
|
202
203
|
})),
|
|
203
204
|
});
|
|
@@ -226,8 +227,8 @@ const MORE_REFS = Object.freeze({
|
|
|
226
227
|
items.push(Object.freeze({
|
|
227
228
|
id: `more:${at}:editor`,
|
|
228
229
|
label: () => `${name} · Open in editor`,
|
|
229
|
-
available: (
|
|
230
|
-
run: (_target,
|
|
230
|
+
available: (refEditor, target) => !target.isLine && refEditor?.editor === true && !!refEditor.editorUrl,
|
|
231
|
+
run: (_target, refEditor, env) => env.open(editorUrl(refEditor.editorUrl, ref.target.path, ref.target.line)),
|
|
231
232
|
hint: () => `Open the current file in your editor${ref.target.line ? ` at line ${ref.target.line}` : ""}`,
|
|
232
233
|
}));
|
|
233
234
|
}
|
|
@@ -237,8 +238,8 @@ const MORE_REFS = Object.freeze({
|
|
|
237
238
|
items.push(Object.freeze({
|
|
238
239
|
id: `more:${at}:${action.id}`,
|
|
239
240
|
label: () => `${name} · ${action.label}`,
|
|
240
|
-
available: (
|
|
241
|
-
run: (_target,
|
|
241
|
+
available: (_refEditor, target) => !target.isLine,
|
|
242
|
+
run: (_target, _refEditor, env) => env.openLink(action.url),
|
|
242
243
|
hint: () => action.url,
|
|
243
244
|
}));
|
|
244
245
|
}
|
|
@@ -253,10 +254,10 @@ export const REF_ACTIONS = Object.freeze({
|
|
|
253
254
|
Object.freeze({
|
|
254
255
|
id: "editor",
|
|
255
256
|
label: () => "Open in editor",
|
|
256
|
-
available: (
|
|
257
|
-
url: (target,
|
|
258
|
-
run(target,
|
|
259
|
-
const url = this.url(target,
|
|
257
|
+
available: (refEditor) => refEditor?.editor === true && !!refEditor.editorUrl,
|
|
258
|
+
url: (target, refEditor) => editorUrl(refEditor.editorUrl, target.path, target.line),
|
|
259
|
+
run(target, refEditor, env) {
|
|
260
|
+
const url = this.url(target, refEditor);
|
|
260
261
|
if (url) env.open(url);
|
|
261
262
|
},
|
|
262
263
|
// The hover hint: it opens the file as it is now.
|
|
@@ -268,17 +269,29 @@ export const REF_ACTIONS = Object.freeze({
|
|
|
268
269
|
Object.freeze({
|
|
269
270
|
id: "show",
|
|
270
271
|
label: () => "Show in turn",
|
|
271
|
-
available: (
|
|
272
|
-
run: (target,
|
|
272
|
+
available: (_refEditor, target) => !target.isLine && !target.owner?.matches?.(".activity-row") && !!turnRowFor(target),
|
|
273
|
+
run: (target, _refEditor, env) => env.show(target),
|
|
273
274
|
hint: () => "Show the row that touched it in the turn",
|
|
274
275
|
}),
|
|
275
276
|
MORE_REFS,
|
|
277
|
+
// What chi has of the file (the working set's reader, ws_reader.js):
|
|
278
|
+
// an owner's page with the reader, for a file of the set (env's
|
|
279
|
+
// whatChiHas). Secondary and after a row's other refs: never a ref's main
|
|
280
|
+
// target, so a click does what it did; it is in the ▾ menu.
|
|
281
|
+
Object.freeze({
|
|
282
|
+
id: "has",
|
|
283
|
+
label: () => "What chi has",
|
|
284
|
+
secondary: true,
|
|
285
|
+
available: (_refEditor, target, env) => !target.isLine && !!target.path && !!env?.whatChiHas?.has(target.path),
|
|
286
|
+
run: (target, _refEditor, env) => env.whatChiHas.open(target.path),
|
|
287
|
+
hint: () => "What chi has of it: its reads and edits, newest first",
|
|
288
|
+
}),
|
|
276
289
|
Object.freeze({
|
|
277
290
|
id: "copy",
|
|
278
291
|
label: () => "Copy path",
|
|
279
292
|
secondary: true,
|
|
280
|
-
available: (
|
|
281
|
-
run: (target,
|
|
293
|
+
available: (_refEditor, target) => !target.isLine && !!target.path,
|
|
294
|
+
run: (target, _refEditor, env) => env.copy(target.path),
|
|
282
295
|
}),
|
|
283
296
|
]),
|
|
284
297
|
// Any other kind (a plugin's issue, commit, …): its link, then its
|
|
@@ -286,14 +299,15 @@ export const REF_ACTIONS = Object.freeze({
|
|
|
286
299
|
"*": Object.freeze([LINK, URL_ACTIONS, MORE_REFS]),
|
|
287
300
|
});
|
|
288
301
|
|
|
289
|
-
// The targets +
|
|
290
|
-
// when only a secondary one is.
|
|
291
|
-
|
|
302
|
+
// The targets +refEditor+ has for +target+ (refTarget's), in order; none
|
|
303
|
+
// when only a secondary one is. +env+: installRefClicks' (an action's
|
|
304
|
+
// availability may ask it: whatChiHas).
|
|
305
|
+
export function refActions(target, refEditor, actions = REF_ACTIONS, env = null) {
|
|
292
306
|
if (!target) return [];
|
|
293
307
|
// Own keys only: a kind named like an Object property ("constructor") is
|
|
294
308
|
// any other kind.
|
|
295
309
|
const table = (Object.hasOwn(actions, target.kind) ? actions[target.kind] : actions["*"]) || [];
|
|
296
|
-
const found = table.flatMap((action) => (action.expand ? action.expand(target) : [action])).filter((action) => action.available(
|
|
310
|
+
const found = table.flatMap((action) => (action.expand ? action.expand(target) : [action])).filter((action) => action.available(refEditor, target, env));
|
|
297
311
|
return found.some((action) => !action.secondary) ? found : [];
|
|
298
312
|
}
|
|
299
313
|
|
|
@@ -475,16 +489,19 @@ function defaultOpenLink(href) {
|
|
|
475
489
|
}
|
|
476
490
|
|
|
477
491
|
// One delegated listener set on +root+ for every ref on the page.
|
|
478
|
-
// +
|
|
492
|
+
// +refEditor+() is read per click, key and hover, so a capabilities change
|
|
479
493
|
// (another session, a reload) is seen. The targets run through: +open+(url)
|
|
480
494
|
// (the editor's URL), +openLink+(href), +show+(target) and +copy+(text).
|
|
481
|
-
// +menu+ is the ▾ and its menu (ref_menu.js).
|
|
482
|
-
|
|
495
|
+
// +menu+ is the ▾ and its menu (ref_menu.js). +whatChiHas+: the working
|
|
496
|
+
// set's reader ({has(path), open(path)}; null: none, the "What chi has"
|
|
497
|
+
// target never shows).
|
|
498
|
+
export function installRefClicks(root, refEditor, {
|
|
483
499
|
open = defaultOpen, openLink = defaultOpenLink, show = (target) => showInTurn(target), copy = copyText,
|
|
484
|
-
selection = () => window.getSelection?.(), menu = createRefMenu(root.ownerDocument),
|
|
500
|
+
selection = () => window.getSelection?.(), menu = createRefMenu(root.ownerDocument), whatChiHas = null,
|
|
485
501
|
} = {}) {
|
|
486
|
-
const env = { open, openLink, show, copy };
|
|
487
|
-
const
|
|
502
|
+
const env = { open, openLink, show, copy, whatChiHas };
|
|
503
|
+
const actionsOf = (target) => refActions(target, refEditor(), REF_ACTIONS, env);
|
|
504
|
+
const run = (action, target) => action.run(target, refEditor(), env);
|
|
488
505
|
const items = (actions, target) => actions.map((action) => ({
|
|
489
506
|
id: action.id, label: action.label(target), hint: action.hint?.(target) || "", run: () => run(action, target),
|
|
490
507
|
}));
|
|
@@ -497,14 +514,14 @@ export function installRefClicks(root, viewer, {
|
|
|
497
514
|
// the link's own click); Tab works out the tab stops before it moves.
|
|
498
515
|
root.addEventListener("keydown", (e) => {
|
|
499
516
|
pointer = "keyboard";
|
|
500
|
-
if (e.key === "Tab") syncRefTabs(root,
|
|
517
|
+
if (e.key === "Tab") syncRefTabs(root, refEditor());
|
|
501
518
|
}, true);
|
|
502
519
|
|
|
503
520
|
root.addEventListener("click", (e) => {
|
|
504
521
|
if (e.button !== 0 || e.defaultPrevented) return;
|
|
505
522
|
const target = refTarget(e.target);
|
|
506
523
|
if (!target) return;
|
|
507
|
-
const actions =
|
|
524
|
+
const actions = actionsOf(target);
|
|
508
525
|
if (!actions.length) return;
|
|
509
526
|
if (selectingIn(target.owner, selection())) return;
|
|
510
527
|
if (pointer === "touch" && !target.isLine && actions.length > 1) {
|
|
@@ -529,7 +546,7 @@ export function installRefClicks(root, viewer, {
|
|
|
529
546
|
if (e.key === "Escape") menu.hideMore();
|
|
530
547
|
if (e.key !== "Enter" && e.key !== "ArrowDown") return;
|
|
531
548
|
const target = refTarget(el);
|
|
532
|
-
const actions =
|
|
549
|
+
const actions = actionsOf(target);
|
|
533
550
|
if (!actions.length) return;
|
|
534
551
|
if (e.key === "Enter") {
|
|
535
552
|
if (actions[0].id === "link") return;
|
|
@@ -547,13 +564,13 @@ export function installRefClicks(root, viewer, {
|
|
|
547
564
|
const mark = (e) => {
|
|
548
565
|
const target = refTarget(e.target);
|
|
549
566
|
if (!target) return;
|
|
550
|
-
const actions =
|
|
567
|
+
const actions = actionsOf(target);
|
|
551
568
|
const el = target.el;
|
|
552
569
|
if (actions.length) el.dataset.refMain = actions[0].id;
|
|
553
570
|
else delete el.dataset.refMain;
|
|
554
571
|
if (!target.isLine) setRefRole(el, actions);
|
|
555
572
|
hint(el, target, actions[0]);
|
|
556
|
-
if (!target.isLine && actions.length > 1 && pointer !== "touch") menu.showMore(el, () => openMenu(refTarget(el),
|
|
573
|
+
if (!target.isLine && actions.length > 1 && pointer !== "touch") menu.showMore(el, () => openMenu(refTarget(el), actionsOf(refTarget(el)), { focus: true }));
|
|
557
574
|
};
|
|
558
575
|
root.addEventListener("mouseover", mark);
|
|
559
576
|
root.addEventListener("focusin", mark);
|
|
@@ -565,12 +582,12 @@ export function installRefClicks(root, viewer, {
|
|
|
565
582
|
root.addEventListener("focusout", leave);
|
|
566
583
|
}
|
|
567
584
|
|
|
568
|
-
// The tab stops under +root+ for +
|
|
585
|
+
// The tab stops under +root+ for +refEditor+: a ref is one (a button, with
|
|
569
586
|
// aria-haspopup when it has a menu) only while it has a target, so a
|
|
570
587
|
// phone's or an editorless viewer's row titles aren't. Worked out before a
|
|
571
588
|
// Tab moves the focus and on a ref's hover or focus; a line never is one.
|
|
572
|
-
export function syncRefTabs(root,
|
|
573
|
-
for (const el of root.querySelectorAll("[data-ref-kind]")) setRefRole(el, refActions(refTarget(el),
|
|
589
|
+
export function syncRefTabs(root, refEditor) {
|
|
590
|
+
for (const el of root.querySelectorAll("[data-ref-kind]")) setRefRole(el, refActions(refTarget(el), refEditor));
|
|
574
591
|
}
|
|
575
592
|
|
|
576
593
|
function setRefRole(el, actions) {
|