samagotchi 0.136.1 → 0.137.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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -1
  3. data/docs/architecture.md +2 -2
  4. data/docs/cli.md +12 -4
  5. data/docs/guardrails.md +12 -5
  6. data/docs/internals/engine.md +4 -4
  7. data/docs/internals/web-frontend.md +19 -9
  8. data/docs/sessions.md +1 -1
  9. data/docs/testing.md +2 -1
  10. data/lib/samagotchi/bridge.rb +4 -0
  11. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  12. data/lib/samagotchi/desktop/macos.rb +3 -2
  13. data/lib/samagotchi/engine.rb +6 -1
  14. data/lib/samagotchi/guardrail_wiring.rb +3 -1
  15. data/lib/samagotchi/guardrails/chi_dirs.rb +2 -2
  16. data/lib/samagotchi/guardrails/outside.rb +5 -5
  17. data/lib/samagotchi/guardrails/pair_boundary.rb +11 -4
  18. data/lib/samagotchi/guardrails/pair_command.rb +3 -19
  19. data/lib/samagotchi/guardrails/protected_paths.rb +5 -2
  20. data/lib/samagotchi/guardrails/review_paths.rb +32 -2
  21. data/lib/samagotchi/guardrails/shell_paths.rb +0 -4
  22. data/lib/samagotchi/guardrails/verdict.rb +1 -1
  23. data/lib/samagotchi/version.rb +1 -1
  24. data/lib/samagotchi/web/message_display.rb +6 -3
  25. data/lib/samagotchi/web/participant_review.rb +2 -1
  26. data/lib/samagotchi/web/public/answer_fold.js +24 -6
  27. data/lib/samagotchi/web/public/app.js +7 -1
  28. data/lib/samagotchi/web/public/chip_popover.js +20 -42
  29. data/lib/samagotchi/web/public/context_chips.js +16 -6
  30. data/lib/samagotchi/web/public/copy.js +8 -5
  31. data/lib/samagotchi/web/public/families_view.js +15 -6
  32. data/lib/samagotchi/web/public/index.html +55 -35
  33. data/lib/samagotchi/web/public/info_bar.js +1 -1
  34. data/lib/samagotchi/web/public/lists_view.js +1 -0
  35. data/lib/samagotchi/web/public/participants_panel.js +1 -1
  36. data/lib/samagotchi/web/public/popover_modal.js +57 -0
  37. data/lib/samagotchi/web/public/revise_stack.js +76 -6
  38. data/lib/samagotchi/web/public/revise_switch.js +55 -0
  39. data/lib/samagotchi/web/public/scope.js +3 -3
  40. data/lib/samagotchi/web/public/send_turn.js +4 -2
  41. data/lib/samagotchi/web/public/settings_chip.js +2 -2
  42. data/lib/samagotchi/web/public/stale_params.js +26 -0
  43. data/lib/samagotchi/web/public/start_settings.js +1 -1
  44. data/lib/samagotchi/web/public/start_toolkit.js +1 -1
  45. data/lib/samagotchi/web/public/stream_handlers.js +10 -5
  46. data/lib/samagotchi/web/public/working_set_rail.js +2 -0
  47. data/lib/samagotchi/web/public/working_set_view.js +2 -2
  48. metadata +4 -1
@@ -69,10 +69,10 @@ main{flex:1;display:flex;flex-direction:column;gap:16px;padding:16px;overflow:au
69
69
  .answer-fold:not(.folded){margin-bottom:-12px;padding-bottom:0;border-bottom:0;border-bottom-left-radius:0;border-bottom-right-radius:0}
70
70
  .answer-fold:not(.folded)+.bubble{border-top:0;border-top-left-radius:0;border-top-right-radius:0;padding-top:8px}
71
71
  /* A delegate report's row: the report's box (right, its tint, the user accent; dashed when merged mid-turn), closed or
72
- its top edge. */
73
- .answer-fold.report{align-self:flex-end;width:85%;background:var(--accent-bg);border-left-color:var(--accent)}
72
+ its top edge; a long prompt's (answer_fold.js PROMPTS, open by default) the same box. */
73
+ .answer-fold:is(.report,.prompt){align-self:flex-end;width:85%;background:var(--accent-bg);border-left-color:var(--accent)}
74
74
  .answer-fold.report.steered{border-left-style:dashed}
75
- .answer-fold.report:not(.folded)+.bubble.user{width:85%}
75
+ .answer-fold:is(.report,.prompt):not(.folded)+.bubble.user{width:85%;align-items:flex-start}
76
76
  .answer-fold-label{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text-2);font-size:13px}
77
77
  .answer-fold-label:empty{display:none}
78
78
  .answer-fold-size{flex:none;white-space:nowrap;font-variant-numeric:tabular-nums;transition:color .12s ease}
@@ -107,6 +107,17 @@ main{flex:1;display:flex;flex-direction:column;gap:16px;padding:16px;overflow:au
107
107
  .stack-version:hover:not(:disabled){background:var(--bg-hover);filter:none}
108
108
  .stack-version.current{color:var(--text-muted);cursor:default}
109
109
  .stack-version-n{font-weight:600;color:var(--accent);font-variant-numeric:tabular-nums}
110
+ /* The ‹ N/M › switcher (revise_switch.js): an earlier version's answer read in the top one's place; its copy dashed, the top hidden. */
111
+ .stack-switch{display:inline-flex;align-items:center;gap:2px;font-size:12px;color:var(--text-2);font-variant-numeric:tabular-nums}
112
+ .stack-switch-btn{min-height:0;height:22px;min-width:24px;padding:0 6px;border-radius:6px;border:1px solid var(--border-strong);background:var(--bg-raised);color:var(--text-2);font:inherit;font-size:14px;line-height:20px;cursor:pointer}
113
+ .stack-switch-btn:hover:not([aria-disabled="true"]){color:var(--text-bright);filter:none}
114
+ .stack-switch-btn:focus-visible{outline:2px solid var(--accent-ring);outline-offset:1px}
115
+ .stack-switch-btn[aria-disabled="true"]{opacity:.4;cursor:default}
116
+ .stack-switch-n{min-width:2.6em;text-align:center}
117
+ .stack-switch-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
118
+ @media (pointer:coarse){.stack-switch-btn{height:30px;min-width:34px;line-height:28px}}
119
+ .bubble.output.stack-view{border-left-style:dashed}
120
+ .stack-swapped{display:none!important}
110
121
  /* A gap divider (time_gaps.js): one centred dim line where a quiet stretch passed, never wrapped (a phone at 360 px keeps it on one line). Not a .bubble. */
111
122
  .time-gap{align-self:stretch;text-align:center;color:var(--time-gap);font-size:12px;line-height:1.4;font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin:2px 0;user-select:none}
112
123
  .turn-timing{margin-top:8px;color:var(--text-muted);font-size:11px;font-variant-numeric:tabular-nums}
@@ -619,6 +630,8 @@ button.system-one-wrong:hover:not(:disabled){background:var(--bg-hover);color:va
619
630
  .bubble.output.markdown .code-wrap>pre,.bubble.user>.user-message.markdown .code-wrap>pre{margin:0}
620
631
  .code-wrap>.copy-btn{top:5px;right:5px}
621
632
  @media (hover:none){.copy-btn{opacity:.55}}
633
+ /* Where the code button always shows (touch) or a phone's narrow block, the code starts under it: a strip above the first line holds the button (a line as wide as the block, or one that scrolls, would run under it). */
634
+ @media (max-width:600px),(hover:none){.bubble.output.markdown .code-wrap>pre,.bubble.user>.user-message.markdown .code-wrap>pre{padding-top:32px}}
622
635
  /* The dock is the composer card (composer.css .composer-card): the text field, a toolbar row, the info bar as its footer. */
623
636
  #dock{flex-shrink:0;margin:0 12px 12px}
624
637
  /* In a session the card floats over the history, so the glass blurs it; the history's bottom padding follows the card (--dock-h, set from dock_reserve.js). */
@@ -664,7 +677,7 @@ body.has-session #history{padding-bottom:calc(var(--dock-h,160px) + 32px)}
664
677
  body:not(.has-session) #composer .actions-col{flex-wrap:nowrap}
665
678
  body:not(.has-session) #composer .actions-col .model-pick{flex:0 100000 auto;min-width:min(84px,20vw)}
666
679
  body:not(.has-session) #composer .actions-col .llmctx-new{flex:0 1 auto;min-width:40px}
667
- #composer .actions-col .model-pick:hover,#composer .actions-col .model-pick[aria-expanded="true"]{filter:none;background:color-mix(in srgb,var(--bg-hover) 75%,transparent);color:var(--text-2)}
680
+ #composer .actions-col .model-pick:hover{filter:none}#composer .actions-col .model-pick[aria-expanded="true"]{background:color-mix(in srgb,var(--bg-hover) 75%,transparent);color:var(--text-2)}@media(hover:hover){#composer .actions-col .model-pick:hover{background:color-mix(in srgb,var(--bg-hover) 75%,transparent);color:var(--text-2)}}
668
681
  #composer .actions-col .model-pick[hidden],body.has-session #composer .actions-col .model-pick{display:none}
669
682
  .model-pick-name{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
670
683
  #composer .actions-col .model-pick.unavailable .model-pick-name{color:var(--text-faint)}
@@ -675,7 +688,7 @@ body.has-session.fresh-link #composer .actions-col .model-pick:not([hidden]){dis
675
688
  @media(max-width:600px){body.has-session.fresh-link #composer .actions-col .model-pick:not([hidden]){max-width:100px}}
676
689
  /* The new session's override chips (start_page.js: what the ⚙ panel has set, only then), right of the key hint next to ⚙: accent; a click opens the panel. A phone has ⚙'s dot instead (below). */
677
690
  #composer .actions-col .llmctx-new{order:1;flex:0 1 auto;min-width:0;max-width:min(30%,220px);height:24px;min-height:24px;line-height:22px;padding:0 6px;border-radius:6px;border:1px solid var(--accent-border);background:transparent;color:var(--accent);font-size:11px;font-weight:400;overflow:hidden;text-overflow:ellipsis}
678
- #composer .actions-col .llmctx-new:hover{filter:none;color:var(--accent);background:var(--accent-bg)}
691
+ #composer .actions-col .llmctx-new:hover{filter:none}#composer .actions-col .llmctx-new[aria-expanded="true"]{color:var(--accent);background:var(--accent-bg)}@media(hover:hover){#composer .actions-col .llmctx-new:hover{color:var(--accent);background:var(--accent-bg)}}
679
692
  #composer .actions-col .llmctx-new[hidden],body.has-session #composer .actions-col .llmctx-new{display:none}
680
693
  /* Phones (the key hint is gone there): still one row, with tighter gaps; the override chips go (⚙'s dot and label say what is set). */
681
694
  @media(max-width:600px){#composer .actions-col .model-pick{flex:0 1 auto;min-width:0;max-width:100%}body:not(.has-session) #composer .actions-col{gap:4px}body:not(.has-session) #composer .actions-col .model-pick{flex-shrink:20;min-width:min(84px,20vw)}#composer .actions-col .llmctx-new{display:none}}
@@ -825,6 +838,11 @@ body.stage-view .turn-stage{position:absolute;left:0;right:0;bottom:100%;margin-
825
838
  .ts-extras>.bubble.user{max-width:none;margin:0;padding:4px 10px;font-size:13px;line-height:1.45;background:transparent;color:var(--text-2)}
826
839
  .ts-extras>.bubble.user>.copy-btn{display:none}
827
840
  .ts-extras>.bubble.user .user-message{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;overflow:hidden;white-space:normal}
841
+ /* A line's markdown (a delegate report's) reads as a plain row in the clamped rows: its blocks run inline at the
842
+ row's own size, a space between them, rules and copy buttons gone. The prompt line shown whole keeps it. */
843
+ :is(.ts-extras>.bubble.user,.ts-prompt:not(.full)>.bubble.user)>.user-message.markdown :is(p,h1,h2,h3,h4,h5,h6,ul,ol,li,blockquote,pre,table,thead,tbody,tr,th,td,.code-wrap){display:inline;margin:0;padding:0;border:0;border-radius:0;background:transparent;font-size:inherit;font-weight:inherit;line-height:inherit;color:inherit;white-space:normal}
844
+ :is(.ts-extras>.bubble.user,.ts-prompt:not(.full)>.bubble.user)>.user-message.markdown :is(p,h1,h2,h3,h4,h5,h6,li,blockquote,pre,td,th)::after{content:" "}
845
+ :is(.ts-extras>.bubble.user,.ts-prompt:not(.full)>.bubble.user)>.user-message.markdown :is(hr,img,.copy-btn){display:none}
828
846
  /* Inside the dock's own blur a second backdrop-filter sees nothing: the cards are opaque here (as #commandList is). */
829
847
  .turn-stage .bubble.question,.turn-stage .bubble.plugin-card{-webkit-backdrop-filter:none;backdrop-filter:none;box-shadow:none}
830
848
  .turn-stage .bubble.question{background:color-mix(in srgb,var(--warn) 7%,var(--bg-panel))}
@@ -880,7 +898,7 @@ body.stage-view .turn-stage{position:absolute;left:0;right:0;bottom:100%;margin-
880
898
  body.working-set .turn-stage{container-type:inline-size}
881
899
  body.working-set .ts-live{position:relative;padding-right:264px}
882
900
  .ts-ws{--ws-line:18px;position:absolute;top:0;right:0;bottom:0;width:248px;box-sizing:border-box;padding:0 4px 0 12px;border-left:1px solid var(--ws-rule);border-radius:0 6px 6px 0;display:flex;flex-direction:column;overflow:hidden;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;line-height:var(--ws-line);color:var(--text-2);cursor:pointer}
883
- .ts-ws:hover{background:var(--bg-hover)}
901
+ @media(hover:hover){.ts-ws:hover{background:var(--bg-hover)}}
884
902
  .ts-ws:focus-visible{outline:2px solid var(--accent-ring);outline-offset:1px}
885
903
  .ws-head{flex:none;display:flex;align-items:center;gap:6px;min-width:0;height:var(--ws-line);font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,sans-serif;font-size:11px;font-weight:600;letter-spacing:.04em;text-transform:uppercase;color:var(--ws-muted);white-space:nowrap}
886
904
  .ws-count{margin-right:auto;font-weight:400;letter-spacing:0;color:var(--ws-faint);font-variant-numeric:tabular-nums}
@@ -947,7 +965,7 @@ body.working-set .turn-stage.waiting .ts-live{min-height:calc(var(--ts-live-h) +
947
965
  body.working-set .turn-stage.held-wait:not(.waiting) .ts-live{min-height:max(calc(var(--ts-live-h) + var(--ws-row-h,0px)),var(--live-held,0px))}
948
966
  /* A finished turn's footprint, under its closed block (working_set_view.js): one faint line; a click opens its list. */
949
967
  .ws-foot{display:block;width:fit-content;max-width:calc(100% - 13px);box-sizing:border-box;margin:-4px 0 0 13px;padding:0 6px;border-radius:6px;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;line-height:18px;color:var(--text-faint);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;cursor:pointer}
950
- .ws-foot:hover{color:var(--text-muted);background:var(--bg-hover)}
968
+ @media(hover:hover){.ws-foot:hover{color:var(--text-muted);background:var(--bg-hover)}}
951
969
  .ws-foot:focus-visible{outline:2px solid var(--accent-ring);outline-offset:1px}
952
970
  .ws-foot .w{font-family:ui-sans-serif,system-ui,sans-serif}
953
971
  .ws-foot .sep{color:var(--border-strong)}
@@ -959,25 +977,25 @@ body.working-set .turn-stage.held-wait:not(.waiting) .ts-live{min-height:max(cal
959
977
  .ws-step{display:inline-block;padding:0 4px;border:0;border-radius:4px;background:var(--badge-bg);font-family:ui-sans-serif,system-ui,sans-serif;font-size:10.5px;line-height:14px;font-weight:400;color:var(--ws-faint);font-variant-numeric:tabular-nums;vertical-align:1px}
960
978
  .ws-step.p{color:var(--think-text)}
961
979
  button.ws-step{cursor:pointer}
962
- button.ws-step:hover:not(:disabled){filter:none;background:var(--accent-bg);color:var(--accent)}
980
+ button.ws-step:hover:not(:disabled){filter:none}@media(hover:hover){button.ws-step:hover:not(:disabled){background:var(--accent-bg);color:var(--accent)}}
963
981
  /* The expanded view (a chip popover; a bottom sheet on a phone). */
964
982
  .ws-popover{gap:0}
965
983
  .ws-popover .ctx-pop-head{align-items:center;flex-wrap:wrap;margin-bottom:4px}
966
984
  .ws-scope{display:inline-flex;gap:2px}
967
985
  .ws-scope button{padding:1px 8px;border:1px solid transparent;border-radius:999px;background:transparent;color:var(--text-muted);font-size:11px;line-height:16px}
968
986
  .ws-scope button.on{color:var(--text-2);border-color:var(--border-strong);background:var(--bg-raised)}
969
- .ws-scope button:hover:not(:disabled){filter:none;color:var(--text)}
987
+ .ws-scope button:hover:not(:disabled){filter:none}@media(hover:hover){.ws-scope button:hover:not(:disabled){color:var(--text)}}
970
988
  .ws-popover .ctx-pop-meta{margin-top:6px;color:var(--ws-muted)}
971
989
  .ws-popover .ws-hint{margin-top:10px;color:var(--ws-faint)}
972
990
  .ws-row{display:flex;align-items:center;gap:8px;width:100%;min-width:0;height:28px;box-sizing:border-box;padding:0 6px;border:0;border-radius:6px;background:transparent;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12.5px;line-height:28px;color:var(--text-2);text-align:left}
973
- .ws-row:hover{background:var(--bg-hover)}
974
- button.ws-row:hover:not(:disabled){filter:none;background:var(--bg-hover)}
991
+ @media(hover:hover){.ws-row:hover{background:var(--bg-hover)}}
992
+ button.ws-row:hover:not(:disabled){filter:none}@media(hover:hover){button.ws-row:hover:not(:disabled){background:var(--bg-hover)}}
975
993
  .ws-row .k{flex:none;width:12px;text-align:center;color:var(--ws-faint)}
976
994
  .ws-row.memory .k{color:var(--think-text)}
977
995
  .ws-row.url .k{color:var(--accent)}
978
996
  .ws-row .t{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:inherit}
979
997
  .ws-row a.t{text-decoration:none}
980
- .ws-row a.t:hover{text-decoration:underline}
998
+ @media(hover:hover){.ws-row a.t:hover{text-decoration:underline}}
981
999
  .ws-row .e{flex:none;color:var(--accent);font-weight:600}
982
1000
  .ws-row .n{flex:none;color:var(--ws-faint)}
983
1001
  .ws-row .st{flex:0 4 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-left:auto;font-family:ui-sans-serif,system-ui,sans-serif;font-size:11px;color:var(--ws-faint)}
@@ -994,12 +1012,12 @@ button.ws-row:hover:not(:disabled){filter:none;background:var(--bg-hover)}
994
1012
  .ws-row:hover .ws-act,.ws-row:focus-within .ws-act,.ws-ghead:hover .ws-act,.ws-ghead:focus-within .ws-act,.ws-row.pending .ws-act{opacity:1}
995
1013
  @media (hover:none){.ws-act{opacity:1}}
996
1014
  .ws-act-b{flex:none;padding:0 6px;border:1px solid var(--ws-act-border);border-radius:4px;background:transparent;font-family:ui-sans-serif,system-ui,sans-serif;font-size:11px;font-weight:400;line-height:16px;color:var(--ws-muted);cursor:pointer}
997
- .ws-act-b:hover:not(:disabled){filter:none;color:var(--accent);border-color:var(--accent);background:var(--accent-bg)}
1015
+ .ws-act-b:hover:not(:disabled){filter:none}@media(hover:hover){.ws-act-b:hover:not(:disabled){color:var(--accent);border-color:var(--accent);background:var(--accent-bg)}}
998
1016
  .ws-act-b:disabled{opacity:.5;cursor:default}
999
1017
  .ws-ghead{display:flex;align-items:center;gap:4px}
1000
1018
  .ws-ghead>.ws-group-head{flex:1;min-width:0}
1001
1019
  .ws-row.pending{border:1px dashed var(--warn-border);background:var(--warn-bg)}
1002
- .ws-row.pending:hover{background:var(--warn-bg)}
1020
+ @media(hover:hover){.ws-row.pending:hover{background:var(--warn-bg)}}
1003
1021
  /* A pending row: its pill and undo take the tokens' and the step tag's room, so the name stays readable. */
1004
1022
  .ws-row.pending .tk,.ws-row.pending .ws-step{display:none}
1005
1023
  .ws-pend{flex:none;padding:0 6px;border:1px solid var(--warn-border);border-radius:999px;background:var(--warn-bg);color:var(--warn-text);font-family:ui-sans-serif,system-ui,sans-serif;font-size:10.5px;line-height:15px;white-space:nowrap}
@@ -1028,7 +1046,7 @@ button.ws-row:hover:not(:disabled){filter:none;background:var(--bg-hover)}
1028
1046
  .ws-popover.sheet .ws-add .ws-act-b{line-height:32px;padding:0 14px;font-size:12.5px;border-radius:6px}
1029
1047
  /* The session bar's chip, in the mem chip's place: a dot (the accent: changed since its list was last opened) and the count. */
1030
1048
  #infoBar .meta .ws-chip{display:inline-flex;align-items:center;gap:5px;padding:2px 7px;border:1px solid transparent;cursor:pointer;font-family:inherit;font-weight:400;white-space:nowrap;font-variant-numeric:tabular-nums}
1031
- #infoBar .meta .ws-chip:hover:not(:disabled){filter:none;color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}
1049
+ #infoBar .meta .ws-chip:hover:not(:disabled){filter:none}#infoBar .meta .ws-chip[aria-expanded="true"]{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}@media(hover:hover){#infoBar .meta .ws-chip:hover:not(:disabled){color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}}
1032
1050
  .ws-dot{width:6px;height:6px;border-radius:50%;background:var(--text-faint);opacity:.6}
1033
1051
  #infoBar .meta .ws-chip.empty{color:var(--text-muted);background:transparent;border-color:var(--border)}
1034
1052
  .ws-chip.changed .ws-dot{background:var(--accent);opacity:1;box-shadow:0 0 0 2px var(--accent-ring)}
@@ -1094,7 +1112,7 @@ button.ws-row:hover:not(:disabled){filter:none;background:var(--bg-hover)}
1094
1112
  #infoBar .meta .worker-restart:disabled{opacity:.7;cursor:default}
1095
1113
  #infoBar button{padding:4px 12px;border-radius:8px;font-size:12px;font-weight:600}
1096
1114
  #infoBar #infoStopBtn{background:var(--bg-raised);color:var(--warn-text);border:1px solid var(--border-strong)}
1097
- #infoBar #infoStopBtn:hover{background:var(--warn-bg);border-color:var(--warn-border)}
1115
+ @media(hover:hover){#infoBar #infoStopBtn:hover{background:var(--warn-bg);border-color:var(--warn-border)}}
1098
1116
  #infoBar #infoArchiveBtn{background:transparent;color:var(--text-muted);border:1px solid var(--border-strong)}
1099
1117
  #infoBar #infoArchiveBtn:hover{color:var(--text);background:var(--bg-hover)}
1100
1118
  #infoBar #infoDeleteBtn{background:transparent;color:var(--text-muted);border:1px solid transparent}
@@ -1107,7 +1125,7 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1107
1125
  #infoBar #infoCancelBtn:hover:not(:disabled){color:var(--on-solid);background:var(--danger-bg);border-color:var(--danger-bg)}
1108
1126
  /* The ⚙ chip (settings_chip.js): a model-like chip that opens the session's settings panel; accent when the session set its own (capped like the model chip in the min-width:601px rule above, the full text in its tooltip; a phone shows ⚙ with a dot). */
1109
1127
  #infoBar .meta .settings-chip{position:relative;padding:2px 6px;border-radius:6px;font-size:11px;font-weight:400;border:1px solid transparent;cursor:pointer;font-family:inherit;white-space:nowrap}
1110
- #infoBar .meta .settings-chip:hover{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}
1128
+ #infoBar .meta .settings-chip[aria-expanded="true"]{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}@media(hover:hover){#infoBar .meta .settings-chip:hover{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}}
1111
1129
  #infoBar .meta .settings-chip.own{color:var(--accent);border-color:var(--accent-border)}
1112
1130
  /* A chip's icon (⚙ here, the start page's own SVG from composer.css): the glyph stays the text, the mask draws it. */
1113
1131
  #infoBar .meta :is(.settings-chip,.tools-chip){display:inline-flex;align-items:center;gap:4px}
@@ -1132,7 +1150,7 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1132
1150
  .ctx-add-input{width:100%;box-sizing:border-box;padding:6px 8px;border-radius:7px;border:1px solid var(--border-strong);background:var(--bg-inset);color:var(--text);font:inherit;font-size:13px;line-height:1.4}
1133
1151
  .ctx-add-input:focus{outline:none;border-color:var(--accent-border)}
1134
1152
  #infoBar .ctx-chip{display:inline-flex;align-items:center;gap:5px;padding:2px 9px;border-radius:999px;font:600 11px/1.5 ui-monospace,monospace;background:color-mix(in srgb,var(--bg-hover) 55%,transparent);color:var(--text-3);border:1px solid var(--border-strong);white-space:nowrap}
1135
- #infoBar .ctx-chip:hover,#infoBar .ctx-chip.open{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}
1153
+ #infoBar .ctx-chip.open{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}@media(hover:hover){#infoBar .ctx-chip:hover{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}}
1136
1154
  #infoBar .ctx-chip.empty{color:var(--text-faint);border-style:dashed}
1137
1155
  #infoBar .ctx-chip.error{color:var(--danger-text);border-color:color-mix(in srgb,var(--danger) 55%,transparent);background:var(--danger-bg-dim)}
1138
1156
  .ctx-dot{width:7px;height:7px;border-radius:50%;background:var(--accent);box-shadow:0 0 0 2px var(--accent-ring)}
@@ -1140,7 +1158,7 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1140
1158
  .ctx-popover[hidden]{display:none}
1141
1159
  /* The participants chip (info bar) and its panel (participants_panel.js). */
1142
1160
  #infoBar .meta .participants-chip{display:inline-flex;align-items:center;gap:5px;padding:2px 7px;border:1px solid transparent;cursor:pointer;font-family:inherit;font-weight:400;white-space:nowrap}
1143
- #infoBar .meta .participants-chip:hover{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}
1161
+ #infoBar .meta .participants-chip[aria-expanded="true"]{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}@media(hover:hover){#infoBar .meta .participants-chip:hover{color:var(--text);border-color:var(--accent-border);background:var(--accent-bg)}}
1144
1162
  #infoBar .meta .participants-chip.none{color:var(--text-muted);background:transparent;border-color:var(--border)}
1145
1163
  #infoBar .meta .participants-chip.none .pc-dot{display:none}
1146
1164
  .participants-chip .pc-dot{width:7px;height:7px;border-radius:50%;background:var(--text-faint)}
@@ -1159,7 +1177,7 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1159
1177
  .pp-capped{color:var(--warn-text);font-weight:600}
1160
1178
  .pp-actions{grid-column:2;grid-row:1/3;display:flex;align-items:center;gap:4px}
1161
1179
  .pp-actions button,.pp-invite button,.pp-link button,.pp-foot button{padding:3px 9px;border-radius:6px;font-size:12px;background:var(--bg-raised);color:var(--text-2);border:1px solid var(--border-strong);cursor:pointer}
1162
- .pp-actions button:hover,.pp-invite button:hover,.pp-link button:hover,.pp-foot button:hover{color:var(--text-hover)}
1180
+ @media(hover:hover){.pp-actions button:hover,.pp-invite button:hover,.pp-link button:hover,.pp-foot button:hover{color:var(--text-hover)}}
1163
1181
  .pp-actions .pp-revoke{color:var(--danger-text)}
1164
1182
  .pp-cap-form{display:flex;gap:4px}
1165
1183
  .pp-cap-form input{width:58px}
@@ -1201,8 +1219,8 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1201
1219
  .sset-back{margin:0 2px 0 -6px;padding:0 6px;border:0;border-radius:5px;background:transparent;color:var(--text-muted);font-size:18px;line-height:1}
1202
1220
  .sset-back:hover{filter:none}
1203
1221
  .start-settings.sheet{border-radius:14px;padding:14px 16px}
1204
- /* Tints only where a pointer hovers: on a touch screen a tapped control would keep it (the ⚙/🧰 panels' rows and links;
1205
- older popovers' :hover rules aren't gated yet). */
1222
+ /* Tints only where a pointer hovers: on a touch screen a tapped control would keep it. Every popover's (chip_popover.js)
1223
+ controls and its opener's :hover tint sit in @media(hover:hover); an open opener shows it by aria-expanded instead. */
1206
1224
  @media(hover:hover){.sset-seg button:hover{color:var(--text);border-color:var(--accent-border)}.sset-link:hover{background:var(--accent-bg)}.sset-back:hover{color:var(--text);background:var(--bg-hover)}.st-row:hover{color:var(--text);background:var(--bg-hover)}}
1207
1225
  @media(max-width:400px){.sset-row{flex-direction:column;gap:4px}.sset-label{flex:none;line-height:1.4}.sset-ctx-more,.sset-ctx-form{margin-left:0}}
1208
1226
  @media(pointer:coarse){.sset-seg button{height:36px;min-height:36px;line-height:34px;padding:0 12px;font-size:13px}.sset-link,.sset-back{min-height:36px}.sset-label{line-height:36px}}
@@ -1230,7 +1248,7 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1230
1248
  .participants-popover.sheet .pp-qr{display:none}
1231
1249
  .pp-foot{display:flex;align-items:center;gap:8px;justify-content:flex-end;padding-top:4px}
1232
1250
  .pp-view{font-size:12px;color:var(--accent);text-decoration:none}
1233
- .pp-view:hover{text-decoration:underline}
1251
+ @media(hover:hover){.pp-view:hover{text-decoration:underline}}
1234
1252
  /* The Home Screen app's notifications sheet (push_devices.js): the bell opens it; a bottom sheet on a phone. */
1235
1253
  .push-devices .ctx-pop-head strong{font-family:inherit}
1236
1254
  .push-devices.sheet{border-radius:14px;padding:14px 16px;font-size:14px}
@@ -1244,7 +1262,7 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1244
1262
  .pd-error{color:var(--danger-text)}
1245
1263
  .pd-done{grid-column:1/3;display:flex;align-items:center;justify-content:space-between;gap:8px;margin-top:4px;padding-top:6px;border-top:1px solid var(--border);font-size:12px;color:var(--text-3)}
1246
1264
  .pd-remove{padding:3px 10px;border-radius:7px;font-size:12px;background:var(--bg-raised);color:var(--danger-text);border:1px solid var(--border-strong);cursor:pointer}
1247
- .pd-remove:hover{color:var(--text-hover)}
1265
+ @media(hover:hover){.pd-remove:hover{color:var(--text-hover)}}
1248
1266
  .pd-switch{appearance:none;-webkit-appearance:none;position:relative;flex-shrink:0;width:34px;height:20px;margin:0;border-radius:999px;background:var(--bg-raised);border:1px solid var(--border-strong);cursor:pointer;transition:background .15s}
1249
1267
  .pd-switch::after{content:"";position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:var(--text-muted);transition:transform .15s,background .15s}
1250
1268
  .pd-switch:checked{background:var(--accent-strong);border-color:var(--accent-strong)}
@@ -1272,9 +1290,9 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1272
1290
  .ss-note,.ss-more{font-size:11.5px;color:var(--text-muted)}
1273
1291
  .ss-acts{display:flex;gap:8px;flex-wrap:wrap}
1274
1292
  .ss-acts button{padding:8px 12px;border-radius:8px;font-size:13px;cursor:pointer;border:1px solid var(--border-strong);background:var(--bg-raised);color:var(--text-2)}
1275
- .ss-acts button:hover{background:var(--bg-hover);color:var(--text-hover)}
1293
+ @media(hover:hover){.ss-acts button:hover{background:var(--bg-hover);color:var(--text-hover)}}
1276
1294
  .ss-stop-all{background:var(--warn-bg);border-color:var(--warn-border);color:var(--warn-text)}
1277
- .ss-stop-all:hover{background:var(--warn-border);color:var(--text-hover)}
1295
+ @media(hover:hover){.ss-stop-all:hover{background:var(--warn-border);color:var(--text-hover)}}
1278
1296
  .ss-cancel{background:transparent}
1279
1297
  .stop-sheet.sheet .ss-acts button{flex:1 1 auto;font-size:14px;padding:10px 12px}
1280
1298
  .ss-foot{font-size:11.5px;color:var(--text-muted);margin-top:6px}
@@ -1299,7 +1317,7 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1299
1317
  @media(max-width:600px){#updateSheet{position:fixed;inset:auto 8px 8px;width:auto;max-width:none;max-height:min(80dvh,calc(100dvh - 16px));margin:0}}
1300
1318
  .ctx-pop-kind{font-size:11px;color:var(--text-muted)}
1301
1319
  .ctx-pop-close{margin-left:auto;padding:0 6px;border:none;background:transparent;color:var(--text-muted);font-size:16px;line-height:1}
1302
- .ctx-pop-close:hover{color:var(--text)}
1320
+ @media(hover:hover){.ctx-pop-close:hover{color:var(--text)}}
1303
1321
  /* A finger's × (the other sheet controls are 36-40 px): the negative margins keep the head's height. */
1304
1322
  @media(pointer:coarse){.ctx-pop-close{min-width:36px;min-height:36px;margin:-10px -10px -10px auto;font-size:18px}}
1305
1323
  .ctx-pop-why{color:var(--text)}
@@ -1310,9 +1328,9 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1310
1328
  .ctx-pop-text{margin:0;max-height:240px;overflow:auto;padding:8px;border-radius:8px;background:var(--bg-inset);font:12px/1.45 ui-monospace,monospace;white-space:pre-wrap;word-break:break-word;color:var(--text-2)}
1311
1329
  .ctx-pop-actions{display:flex;gap:8px;justify-content:flex-end}
1312
1330
  .ctx-pop-actions button{padding:3px 10px;border-radius:7px;font-size:12px;font-weight:600;background:var(--bg-raised);color:var(--text-2);border:1px solid var(--border-strong)}
1313
- .ctx-pop-actions button:hover{color:var(--text-hover)}
1331
+ @media(hover:hover){.ctx-pop-actions button:hover{color:var(--text-hover)}}
1314
1332
  .ctx-pop-actions .ctx-pop-detach{color:var(--text-muted);background:transparent}
1315
- .ctx-pop-actions .ctx-pop-detach:hover{color:var(--danger-text);border-color:color-mix(in srgb,var(--danger) 55%,transparent)}
1333
+ @media(hover:hover){.ctx-pop-actions .ctx-pop-detach:hover{color:var(--danger-text);border-color:color-mix(in srgb,var(--danger) 55%,transparent)}}
1316
1334
  /* Phones: the footer is one line; its meta scrolls sideways (all of it stays reachable). */
1317
1335
  @media(max-width:600px){
1318
1336
  #infoBar{flex-wrap:nowrap;align-items:center;gap:6px;padding:6px 10px 8px}
@@ -1331,6 +1349,8 @@ body.has-session.composer-folded #infoBar{border-top-color:transparent}
1331
1349
  #infoBar .meta .children-chip{order:-1}
1332
1350
  /* A chain's ← → links too: the way to the other days. */
1333
1351
  #infoBar .meta .chain-link{order:-1}
1352
+ /* ⚙ too (an icon here): after the model chip a long model name would push it out of sight. */
1353
+ #infoBar .meta .settings-chip{order:-1}
1334
1354
  /* The chips get a second line of their own (only when there are some), scrolling sideways. */
1335
1355
  #infoBar:has(#contextChips:not([hidden])){flex-wrap:wrap;row-gap:4px}
1336
1356
  #contextChips{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none}
@@ -1383,7 +1403,7 @@ body.has-session #newBtn .brand-new{display:inline}
1383
1403
  .project-picker .ctx-pop-head strong{font-family:inherit}
1384
1404
  .project-list{display:flex;flex-direction:column;gap:6px;margin:2px 0;padding:0}
1385
1405
  .project-row{display:flex;align-items:center;gap:12px;padding:8px 10px;border:1px solid transparent;border-radius:9px;background:var(--bg-inset);color:var(--text);text-decoration:none}
1386
- .project-row:hover{background:var(--bg-hover);color:var(--text-hover)}
1406
+ @media(hover:hover){.project-row:hover{background:var(--bg-hover);color:var(--text-hover)}}
1387
1407
  .project-row:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
1388
1408
  .project-row[aria-current="page"]{border-color:var(--accent-border);background:var(--accent-bg)}
1389
1409
  .project-main{display:flex;flex:1;align-items:center;gap:7px;min-width:0;flex-wrap:wrap}
@@ -1445,7 +1465,7 @@ body.has-session #scope .scope-where{display:none}
1445
1465
  }
1446
1466
  #notifyBtn{margin-left:auto;flex-shrink:0;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;padding:0;min-height:0;background:transparent;border:1px solid transparent;border-radius:999px;color:var(--text-muted)}
1447
1467
  #notifyBtn[hidden]{display:none}
1448
- #notifyBtn:hover{color:var(--text-2);border-color:var(--border)}
1468
+ @media(hover:hover){#notifyBtn:hover{color:var(--text-2);border-color:var(--border)}}
1449
1469
  #notifyBtn svg{fill:none;stroke:currentColor;stroke-width:1.3;stroke-linejoin:round;stroke-linecap:round}
1450
1470
  #notifyBtn .slash{display:none}
1451
1471
  #notifyBtn[data-state="on"]{color:var(--accent)}
@@ -1466,7 +1486,7 @@ body.no-glass :is(#familyPop,#chainPop){background:var(--bg-panel);-webkit-backd
1466
1486
  /* A chain's chip (chains.js): the card is the latest link of a session chain; a click lists the other links in a popover. */
1467
1487
  .card .meta:has(.chain-chip){flex-wrap:wrap;row-gap:4px}
1468
1488
  .card .chain-chip{font-family:ui-monospace,monospace;font-size:11px;line-height:1.4;white-space:nowrap;flex-shrink:0;padding:1px 7px;border-radius:999px;border:1px solid var(--accent-border);background:var(--accent-tint);color:var(--accent);cursor:pointer}
1469
- .card .chain-chip:hover:not(:disabled){filter:none;border-color:var(--accent);background:var(--accent-bg)}
1489
+ .card .chain-chip:hover:not(:disabled){filter:none}@media(hover:hover){.card .chain-chip:hover:not(:disabled){border-color:var(--accent);background:var(--accent-bg)}}
1470
1490
  .card .chain-chip[aria-expanded="true"]{background:var(--accent-bg);border-color:var(--accent)}
1471
1491
  .card .chain-chip.waiting{color:var(--warn-text);background:var(--warn-bg);border-color:var(--warn-border)}
1472
1492
  .chain-chip .cc-arrow{display:inline-block;margin-right:4px}
@@ -1489,9 +1509,9 @@ body.no-glass :is(#familyPop,#chainPop){background:var(--bg-panel);-webkit-backd
1489
1509
  /* A card with a family chip lets its meta row wrap: the chip goes to a line of its own when the card is narrow. */
1490
1510
  .card .meta:has(.family-chip){flex-wrap:wrap;row-gap:4px}
1491
1511
  .card .family-chip{font-family:ui-monospace,monospace;font-size:11px;line-height:1.4;white-space:nowrap;flex-shrink:0;padding:1px 7px;border-radius:999px;border:1px solid var(--border-strong);background:transparent;color:var(--text-3);cursor:pointer}
1492
- .card .family-chip:hover:not(:disabled){filter:none;color:var(--accent);border-color:var(--accent-border);background:var(--accent-bg)}
1512
+ .card .family-chip:hover:not(:disabled){filter:none}@media(hover:hover){.card .family-chip:hover:not(:disabled){color:var(--accent);border-color:var(--accent-border);background:var(--accent-bg)}}
1493
1513
  .card .family-chip.waiting{color:var(--warn-text);background:var(--warn-bg);border-color:var(--warn-border)}
1494
- .card .family-chip.waiting:hover:not(:disabled){color:var(--warn-bright);border-color:var(--warn);background:var(--warn-bg)}
1514
+ @media(hover:hover){.card .family-chip.waiting:hover:not(:disabled){color:var(--warn-bright);border-color:var(--warn);background:var(--warn-bg)}}
1495
1515
  .family-chip .fc-arrow{display:inline-block;margin-right:4px;transition:transform .15s ease}
1496
1516
  .family-chip[aria-expanded="true"] .fc-arrow{transform:rotate(90deg)}
1497
1517
  .family-chip .live-dot{display:inline-block;width:6px;height:6px;border-radius:50%;background:var(--ok);margin-right:3px;vertical-align:1px}
@@ -1499,7 +1519,7 @@ body.no-glass :is(#familyPop,#chainPop){background:var(--bg-panel);-webkit-backd
1499
1519
  /* The family's list: one compact row per delegate, indented per depth. */
1500
1520
  .family-rows{display:flex;flex-direction:column;gap:1px;border-top:1px solid var(--border);margin:2px -6px 0;padding-top:4px;cursor:default}
1501
1521
  .family-row{display:flex;align-items:center;border-radius:6px;padding-left:calc((var(--depth,1) - 1) * 14px)}
1502
- .family-row:hover{background:var(--bg-hover)}
1522
+ @media(hover:hover){.family-row:hover{background:var(--bg-hover)}}
1503
1523
  .family-row .fr-open{flex:1;min-width:0;display:flex;align-items:center;gap:6px;padding:6px;background:transparent;color:var(--text-2);border-radius:6px;font-size:12px;line-height:1.3;text-align:left}
1504
1524
  .family-row .fr-open:hover:not(:disabled){filter:none}
1505
1525
  .family-row .fr-preview{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
@@ -71,7 +71,7 @@ export function workingSetChipTemplate(chip) {
71
71
  const what = chip.n ? `${chip.n} item${chip.n === 1 ? "" : "s"} this session brought into context` : "nothing this session brought into context yet";
72
72
  const title = `Working set: ${what} (files, memories, URLs)${chip.changed ? ", changed since you last looked" : ""}. Open the list.`;
73
73
  const cls = `model ws-chip${chip.changed ? " changed" : ""}${chip.n ? "" : " empty"}`;
74
- return html`<button type="button" class=${cls} title=${title} aria-label=${title} aria-haspopup="dialog"><span class="ws-dot" aria-hidden="true"></span>set ${chip.n}</button>`;
74
+ return html`<button type="button" class=${cls} title=${title} aria-label=${title} aria-haspopup="dialog" aria-expanded="false"><span class="ws-dot" aria-hidden="true"></span>set ${chip.n}</button>`;
75
75
  }
76
76
 
77
77
  // The info line for +bar+, nothing without a session (the start page hides
@@ -373,6 +373,7 @@ export function createListsView(deps) {
373
373
  let chainFrom = null; // the list element the open popover's chip is in
374
374
  const chainPop = createFamilyPop({
375
375
  id: "chainPop",
376
+ label: "Chain links",
376
377
  doc,
377
378
  win,
378
379
  rowsFor: (id) => {
@@ -99,7 +99,7 @@ export function chipModel(grants, now) {
99
99
  export function chipTemplate(chip) {
100
100
  if (!chip) return nothing;
101
101
  return html`<button type="button" class=${`model participants-chip${chip.count ? "" : " none"}${chip.present ? " present" : ""}`}
102
- title=${chip.title} aria-label=${chip.title} aria-haspopup="dialog"><span class="pc-dot" aria-hidden="true"></span>${chip.text}</button>`;
102
+ title=${chip.title} aria-label=${chip.title} aria-haspopup="dialog" aria-expanded="false"><span class="pc-dot" aria-hidden="true"></span>${chip.text}</button>`;
103
103
  }
104
104
 
105
105
  // A cap field's dollars (a leading $ allowed): {value}, {value: null} when
@@ -0,0 +1,57 @@
1
+ // What every popover does alike (chip_popover.js' shell, and the ones that
2
+ // place themselves: context_chips.js, families_view.js' family and chain
3
+ // lists): a modal dialog (modalDialog: aria-modal, Tab and Shift+Tab wrap
4
+ // inside it, a Tab from outside goes in), its opener's aria-expanded, Esc
5
+ // closes it and focus goes back to the opener (focusBack). Their :hover
6
+ // tints are gated on (hover:hover) in index.html, so a tap on a phone
7
+ // leaves none behind. A module of its own: its exports are new (see
8
+ // docs/internals/web-frontend.md, "New exports go in new modules").
9
+ //
10
+ // Not popovers in this sense, so not modal: model_picker.js and
11
+ // command_list.js (a combobox's listbox: the focus stays in its input),
12
+ // ref_menu.js (a menu: arrow keys, Tab leaves it), update_sheet.js (a
13
+ // native <dialog> shown modal: the browser holds the focus).
14
+
15
+ const FOCUSABLE = "button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])";
16
+
17
+ // The elements Tab reaches in +root+, in order (none hidden or disabled).
18
+ export function tabStops(root) {
19
+ return [...root.querySelectorAll(FOCUSABLE)].filter((e) => !e.disabled && !e.closest("[hidden]") && e.tabIndex >= 0);
20
+ }
21
+
22
+ // Tab past +root+'s last stop goes to its first, Shift+Tab before the first
23
+ // to the last; a Tab from outside (the opener kept the focus, or a redraw
24
+ // dropped it) goes in. +e+: the Tab's keydown.
25
+ export function holdFocus(e, root, doc = document) {
26
+ const stops = tabStops(root);
27
+ if (!stops.length) return;
28
+ const first = stops[0];
29
+ const last = stops[stops.length - 1];
30
+ const at = doc.activeElement;
31
+ let to = null;
32
+ if (!root.contains(at)) to = e.shiftKey ? last : first;
33
+ else if (e.shiftKey && at === first) to = last;
34
+ else if (!e.shiftKey && at === last) to = first;
35
+ if (!to) return;
36
+ e.preventDefault();
37
+ to.focus();
38
+ }
39
+
40
+ // +pop+ as every popover is: a dialog (named +label+) that holds the focus
41
+ // while +isOpen()+ and on the page (aria-modal; Tab and Shift+Tab wrap inside it).
42
+ export function modalDialog(pop, { label = null, isOpen, doc = document }) {
43
+ pop.setAttribute("role", "dialog");
44
+ pop.setAttribute("aria-modal", "true");
45
+ if (label) pop.setAttribute("aria-label", label);
46
+ doc.addEventListener("keydown", (e) => {
47
+ if (e.key === "Tab" && isOpen() && pop.isConnected) holdFocus(e, pop, doc);
48
+ });
49
+ }
50
+
51
+ // Called before +pop+ closes: whether the focus was in it (or +refocus+:
52
+ // an Esc), and so goes back(to) its opener once it has closed.
53
+ // @return (to) => focuses +to+ when it should and still can
54
+ export function focusBack(pop, { refocus = false, doc = document } = {}) {
55
+ const had = refocus || pop.contains(doc.activeElement);
56
+ return (to) => { if (had && to?.isConnected) to.focus?.(); };
57
+ }
@@ -11,7 +11,9 @@
11
11
  // verdict cards, the recap. A time-gap divider between two folded stubs
12
12
  // folds into the later stub (it shows the divider's words);
13
13
  // - the top answer gets a version chip, "v3 · 2 earlier ▾", listing the
14
- // versions by their prompts; picking one reveals its stub;
14
+ // versions by their prompts; picking one reveals its stub; and a ‹ 3/3 ›
15
+ // switcher before it shows an earlier version's answer in the top
16
+ // answer's place (revise_switch.js; view only, not stored);
15
17
  // - the final answer of an ended turn (verify_target.js's rule, a delegate
16
18
  // report's reply excluded), unstacked or a stack's top, and not a Verify
17
19
  // turn's, gets a Revise button: it arms the composer (app.js).
@@ -28,6 +30,7 @@ import { bubbleCopyText } from "./copy.js";
28
30
  import { foldLabel, keepRowInView, lineCount, readFolded, writeFold } from "./answer_fold.js";
29
31
  import { clip } from "./format.js";
30
32
  import { NOTE_BOUNDARY } from "./turn_range.js";
33
+ import { SWAPPED_CLASS, VIEW_CLASS, stepVersion, switcherTemplate, viewOf } from "./revise_switch.js";
31
34
 
32
35
  // The classes and attributes this module puts on the history.
33
36
  export const HIDDEN_CLASS = "stack-hidden";
@@ -146,7 +149,7 @@ export function historyTurns(historyEl) {
146
149
  while (turn.els.at(-1)?.classList.contains("time-gap")) turn.els.pop();
147
150
  };
148
151
  for (const el of historyEl.children) {
149
- if (el.classList.contains(STUB_CLASS) || el.classList.contains(ROW_CLASS)) continue;
152
+ if (el.classList.contains(STUB_CLASS) || el.classList.contains(ROW_CLASS) || el.classList.contains(VIEW_CLASS)) continue;
150
153
  if (el.classList.contains(FOLD_ROW) && el.nextElementSibling?.matches(OPENING)) continue;
151
154
  const opening = el.matches(OPENING) ? el : el.querySelector(OPENING);
152
155
  if (opening || el.matches(NOTE_BOUNDARY)) {
@@ -187,6 +190,10 @@ export function installReviseStacks({
187
190
  const rows = new Map();
188
191
  // Each row's answer bubble (its label at a click).
189
192
  const rowAnswer = new WeakMap();
193
+ // The switcher: each stack's version on view (0-based, by its top's id;
194
+ // none: the latest), and the copy shown for it ({el, source, hidden}).
195
+ const shown = new Map();
196
+ const views = new Map();
190
197
  let observer = null;
191
198
 
192
199
  function stubFor(id, opening, stored) {
@@ -234,7 +241,8 @@ export function installReviseStacks({
234
241
  : nothing;
235
242
  const button = html`<button type="button" class=${isArmed ? "revise-btn armed" : "revise-btn"} data-revise=${id} ?disabled=${off} title=${off ? REVISE_UNAVAILABLE : "Rewrite this answer: your next message revises it, and the earlier version folds away"}>${isArmed ? "Revising…" : "Revise"}</button>`;
236
243
  row.classList.toggle("stacked", !!chain);
237
- render(html`${versions}${button}`, row);
244
+ const at = chain ? (shown.get(id) ?? chain.length - 1) : 0;
245
+ render(html`${chain ? switcherTemplate(id, at, chain.length) : nothing}${versions}${button}`, row);
238
246
  rowAnswer.set(row, answer);
239
247
  }
240
248
 
@@ -287,6 +295,7 @@ export function installReviseStacks({
287
295
  keepRows.add(turn.id);
288
296
  drawRow(row, { id: turn.id, answer, chain: tops.get(turn.id) || null, openings });
289
297
  }
298
+ syncViews(tops, keepRows, new Map(turns.filter((t) => t.id).map((t) => [t.id, t.answer])));
290
299
  // A divider between two folded stubs folds into the later one.
291
300
  for (const turn of turns) {
292
301
  if (!turn.stub) continue;
@@ -307,13 +316,67 @@ export function installReviseStacks({
307
316
  for (const [id, stub] of stubs) if (!keepStubs.has(id) || stub.parentElement !== historyEl) { stub.remove(); stubs.delete(id); }
308
317
  for (const [id, row] of rows) if (!keepRows.has(id) || row.parentElement !== historyEl) { row.remove(); rows.delete(id); }
309
318
  // A stale row left by a re-render (its map entry gone with the nodes).
310
- for (const el of historyEl.querySelectorAll(`:scope > .${STUB_CLASS}, :scope > .${ROW_CLASS}`)) {
311
- if (stubs.get(el.dataset.stackStub) !== el && rows.get(el.dataset.reviseFor) !== el) el.remove();
319
+ const viewEls = new Set([...views.values()].map((v) => v.el));
320
+ for (const el of historyEl.querySelectorAll(`:scope > .${STUB_CLASS}, :scope > .${ROW_CLASS}, :scope > .${VIEW_CLASS}`)) {
321
+ if (stubs.get(el.dataset.stackStub) !== el && rows.get(el.dataset.reviseFor) !== el && !viewEls.has(el)) el.remove();
312
322
  }
313
323
  // What we changed isn't news.
314
324
  observer?.takeRecords();
315
325
  }
316
326
 
327
+ // The switcher's copies: a stack on an earlier version (its top's row
328
+ // drawn, that version's answer there) shows a copy of that answer just
329
+ // before the top answer and its fold row, which hide; any other stack's
330
+ // copy goes and its top shows again.
331
+ function syncViews(tops, keepRows, answers) {
332
+ const wanted = (id) => {
333
+ const chain = tops.get(id);
334
+ const k = shown.get(id);
335
+ if (!chain || k === undefined || k >= chain.length - 1 || !keepRows.has(id)) return null;
336
+ const source = answers.get(chain[k]);
337
+ const top = answers.get(id);
338
+ return source && top ? { source, top, version: k + 1 } : null;
339
+ };
340
+ for (const [id, view] of views) {
341
+ const want = wanted(id);
342
+ if (want && view.source === want.source && view.top === want.top && view.el.isConnected) continue;
343
+ view.el.remove();
344
+ for (const el of view.hidden) el.classList.remove(SWAPPED_CLASS);
345
+ views.delete(id);
346
+ }
347
+ for (const id of [...shown.keys()]) {
348
+ const want = wanted(id);
349
+ if (!want) {
350
+ shown.delete(id);
351
+ continue;
352
+ }
353
+ let view = views.get(id);
354
+ if (!view) {
355
+ view = { el: viewOf(want.source, want.version), source: want.source, top: want.top, hidden: [] };
356
+ views.set(id, view);
357
+ }
358
+ const head = want.top.previousElementSibling?.classList.contains(FOLD_ROW) ? want.top.previousElementSibling : null;
359
+ for (const el of view.hidden) if (el !== want.top && el !== head) el.classList.remove(SWAPPED_CLASS);
360
+ view.hidden = head ? [want.top, head] : [want.top];
361
+ for (const el of view.hidden) el.classList.add(SWAPPED_CLASS);
362
+ const before = head || want.top;
363
+ if (before.previousElementSibling !== view.el) historyEl.insertBefore(view.el, before);
364
+ }
365
+ }
366
+
367
+ // The switcher's ‹ or › on its row's stack.
368
+ function step(row, delta) {
369
+ const id = row.dataset.reviseFor;
370
+ const count = row.querySelectorAll("[data-stack-pick]").length;
371
+ if (!id || count < 2) return;
372
+ const was = shown.get(id) ?? count - 1;
373
+ const k = stepVersion(was, count, delta);
374
+ if (k === was) return;
375
+ if (k === count - 1) shown.delete(id);
376
+ else shown.set(id, k);
377
+ keepRowInView(historyEl, row, decorate);
378
+ }
379
+
317
380
  function setOpen(stub, open, { save }) {
318
381
  keepRowInView(historyEl, stub, () => {
319
382
  stub.classList.toggle("open", open);
@@ -326,7 +389,7 @@ export function installReviseStacks({
326
389
  // answer's key or its end (its class).
327
390
  observer = new MutationObserver((records) => {
328
391
  const news = records.some((r) => (r.type === "childList" ? r.target === historyEl
329
- && [...r.addedNodes, ...r.removedNodes].some((n) => n.nodeType === 1 && !n.classList.contains(STUB_CLASS) && !n.classList.contains(ROW_CLASS))
392
+ && [...r.addedNodes, ...r.removedNodes].some((n) => n.nodeType === 1 && ![STUB_CLASS, ROW_CLASS, VIEW_CLASS].some((c) => n.classList.contains(c)))
330
393
  : r.attributeName !== "class" || r.target.matches?.(`.bubble.output, .${STUB_CLASS}`)));
331
394
  if (news) decorate();
332
395
  });
@@ -340,6 +403,13 @@ export function installReviseStacks({
340
403
  setOpen(stub, !stub.classList.contains("open"), { save: true });
341
404
  return;
342
405
  }
406
+ const stepper = e.target.closest?.("[data-stack-step]");
407
+ if (stepper) {
408
+ e.preventDefault();
409
+ const row = stepper.closest(`.${ROW_CLASS}`);
410
+ if (row && stepper.getAttribute("aria-disabled") !== "true") step(row, Number(stepper.dataset.stackStep));
411
+ return;
412
+ }
343
413
  const pick = e.target.closest?.("[data-stack-pick]");
344
414
  if (pick) {
345
415
  e.preventDefault();
@@ -0,0 +1,55 @@
1
+ // The ‹ N/M › switcher on a Revise stack's top answer (revise_stack.js draws
2
+ // it in the top answer's row, before the version chip): the owner reads an
3
+ // earlier version's answer in place of the top one. View only: no server
4
+ // call, nothing stored (a reload shows the latest again).
5
+ //
6
+ // An earlier version is shown as a copy of its answer bubble (the bubble
7
+ // itself stays hidden in its superseded turn): the copy goes just before the
8
+ // top answer (its fold row, answer_fold.js, kept with it), and the top answer
9
+ // and its fold row are hidden by a class while it shows. The copy keeps its
10
+ // kept source (data-copy-source) and its copy buttons, so Copy copies the
11
+ // version on view; it has no answer key (data-answer-turn), so no fold row,
12
+ // claim key or Revise row is drawn for it, and the top answer stays its
13
+ // turn's last answer (verify_target.js, cards_place.js).
14
+ //
15
+ // A module of its own: static JS is cached at unversioned URLs, and a new
16
+ // export on an old module would blank the page.
17
+ import { html } from "./vendor/lit-html.js";
18
+
19
+ // The copy of an earlier answer on view, and what hides the top one.
20
+ export const VIEW_CLASS = "stack-view";
21
+ export const SWAPPED_CLASS = "stack-swapped";
22
+
23
+ // The switcher's words for version +k+ (0-based) of +count+: the counter
24
+ // ("2/3") and its spoken label ("version 2 of 3").
25
+ export function switchText(k, count) {
26
+ return { text: `${k + 1}/${count}`, label: `version ${k + 1} of ${count}` };
27
+ }
28
+
29
+ // Version +k+ moved by +delta+, kept in 0…count-1.
30
+ export function stepVersion(k, count, delta) {
31
+ return Math.min(Math.max(k + delta, 0), Math.max(count - 1, 0));
32
+ }
33
+
34
+ // The switcher for the stack +id+ (its top turn's id) showing version +k+
35
+ // of +count+. The buttons stay focusable at either end (aria-disabled, not
36
+ // disabled: a press there keeps the focus where it is).
37
+ export function switcherTemplate(id, k, count) {
38
+ const { text, label } = switchText(k, count);
39
+ const first = k <= 0;
40
+ const last = k >= count - 1;
41
+ return html`<span class="stack-switch" role="group" aria-label="Answer versions" data-stack-switch=${id}><button type="button" class="stack-switch-btn" data-stack-step="-1" aria-label="Previous version" title="Read the previous version" aria-disabled=${first ? "true" : "false"}>‹</button><span class="stack-switch-n" title=${label}><span aria-hidden="true">${text}</span><span class="stack-switch-sr" aria-live="polite">${label}</span></span><button type="button" class="stack-switch-btn" data-stack-step="1" aria-label="Next version" title="Read the next version" aria-disabled=${last ? "true" : "false"}>›</button></span>`;
42
+ }
43
+
44
+ // A copy of +answer+ (an earlier version's answer bubble) to show in the top
45
+ // answer's place, titled as version +version+: no answer key,
46
+ // none of the history's state classes.
47
+ export function viewOf(answer, version) {
48
+ const view = answer.cloneNode(true);
49
+ for (const attr of ["id", "data-answer-turn", "data-reply-key", "data-stack-of", "data-line-key"]) view.removeAttribute(attr);
50
+ view.classList.remove("stack-hidden", "folded", SWAPPED_CLASS);
51
+ view.classList.add(VIEW_CLASS);
52
+ view.dataset.stackView = String(version);
53
+ for (const btn of view.querySelectorAll(".copy-btn[data-copied]")) delete btn.dataset.copied;
54
+ return view;
55
+ }