samagotchi 0.164.0 → 0.166.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 (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -1
  3. data/docs/architecture.md +7 -5
  4. data/docs/cli.md +23 -12
  5. data/docs/configuration.md +8 -2
  6. data/docs/guardrails.md +19 -18
  7. data/docs/internals/block-renderers.md +1 -1
  8. data/docs/internals/bridge.md +10 -3
  9. data/docs/internals/bundles.md +4 -2
  10. data/docs/internals/inline-widgets.md +8 -1
  11. data/docs/internals/remote-sessions.md +1 -1
  12. data/docs/internals/web-frontend.md +73 -13
  13. data/docs/memory.md +12 -7
  14. data/docs/plugins.md +6 -4
  15. data/docs/releasing.md +17 -4
  16. data/docs/scheduling.md +25 -3
  17. data/docs/sessions.md +12 -10
  18. data/docs/testing.md +37 -4
  19. data/lib/samagotchi/block_renderers.rb +3 -6
  20. data/lib/samagotchi/bridge/card_store.rb +2 -1
  21. data/lib/samagotchi/bridge/turn_accumulator.rb +7 -8
  22. data/lib/samagotchi/bridge.rb +45 -3
  23. data/lib/samagotchi/bundle_command/installed_check.rb +2 -1
  24. data/lib/samagotchi/bundles/system/manifest.yml +1 -1
  25. data/lib/samagotchi/chi_home.rb +44 -2
  26. data/lib/samagotchi/client_id.rb +34 -3
  27. data/lib/samagotchi/compat.rb +34 -0
  28. data/lib/samagotchi/context_command.rb +3 -0
  29. data/lib/samagotchi/context_providers.rb +5 -6
  30. data/lib/samagotchi/context_sources.rb +2 -2
  31. data/lib/samagotchi/continue_intent.rb +50 -5
  32. data/lib/samagotchi/events.rb +4 -4
  33. data/lib/samagotchi/extension_load.rb +2 -1
  34. data/lib/samagotchi/guardrails/approvals.rb +36 -9
  35. data/lib/samagotchi/guardrails/child_boundary.rb +7 -27
  36. data/lib/samagotchi/guardrails/rules.rb +11 -9
  37. data/lib/samagotchi/guardrails/targets.rb +3 -4
  38. data/lib/samagotchi/inline_widgets.rb +16 -1
  39. data/lib/samagotchi/memory_bundle/provenance.rb +46 -4
  40. data/lib/samagotchi/memory_bundle/status.rb +2 -1
  41. data/lib/samagotchi/memory_command.rb +3 -0
  42. data/lib/samagotchi/memory_orphans.rb +4 -7
  43. data/lib/samagotchi/memory_paths.rb +64 -7
  44. data/lib/samagotchi/memory_usage.rb +1 -1
  45. data/lib/samagotchi/plugin/sessions.rb +8 -3
  46. data/lib/samagotchi/project_command.rb +4 -1
  47. data/lib/samagotchi/project_id_clash.rb +37 -26
  48. data/lib/samagotchi/project_init.rb +24 -7
  49. data/lib/samagotchi/reply_wait/poll.rb +4 -14
  50. data/lib/samagotchi/reply_wait.rb +0 -23
  51. data/lib/samagotchi/run_options.rb +1 -1
  52. data/lib/samagotchi/schedules.rb +124 -106
  53. data/lib/samagotchi/send_command.rb +71 -18
  54. data/lib/samagotchi/session.rb +3 -2
  55. data/lib/samagotchi/session_access/local.rb +19 -2
  56. data/lib/samagotchi/session_access/remote.rb +13 -17
  57. data/lib/samagotchi/session_chain/links.rb +109 -0
  58. data/lib/samagotchi/session_chain.rb +7 -19
  59. data/lib/samagotchi/session_continue.rb +138 -54
  60. data/lib/samagotchi/session_inbox.rb +1 -1
  61. data/lib/samagotchi/session_inbox_delivery.rb +57 -38
  62. data/lib/samagotchi/session_manager/delivery.rb +104 -18
  63. data/lib/samagotchi/session_manager/removal.rb +13 -7
  64. data/lib/samagotchi/session_manager.rb +1 -0
  65. data/lib/samagotchi/session_retention.rb +20 -10
  66. data/lib/samagotchi/session_setup.rb +31 -1
  67. data/lib/samagotchi/state_format.rb +12 -8
  68. data/lib/samagotchi/terminal_ui/attach_launcher.rb +6 -7
  69. data/lib/samagotchi/terminal_ui.rb +20 -9
  70. data/lib/samagotchi/tools/delegate.rb +2 -3
  71. data/lib/samagotchi/verify_fresh.rb +4 -1
  72. data/lib/samagotchi/version.rb +1 -1
  73. data/lib/samagotchi/web/public/activity.js +2 -2
  74. data/lib/samagotchi/web/public/app.js +28 -21
  75. data/lib/samagotchi/web/public/auth_lost.js +3 -1
  76. data/lib/samagotchi/web/public/bar_fold.js +293 -0
  77. data/lib/samagotchi/web/public/card.js +1 -1
  78. data/lib/samagotchi/web/public/chip_popover.js +5 -1
  79. data/lib/samagotchi/web/public/composer_mode.js +5 -7
  80. data/lib/samagotchi/web/public/delivery_line.js +19 -4
  81. data/lib/samagotchi/web/public/index.html +242 -94
  82. data/lib/samagotchi/web/public/info_bar.js +28 -16
  83. data/lib/samagotchi/web/public/info_bar_model.js +76 -2
  84. data/lib/samagotchi/web/public/live_timing.js +3 -0
  85. data/lib/samagotchi/web/public/more_sheet.js +98 -40
  86. data/lib/samagotchi/web/public/resync_reach.js +59 -0
  87. data/lib/samagotchi/web/public/session_fields.js +1 -0
  88. data/lib/samagotchi/web/public/session_state.js +5 -0
  89. data/lib/samagotchi/web/public/stage_frame.js +4 -2
  90. data/lib/samagotchi/web/public/stage_stall.js +134 -0
  91. data/lib/samagotchi/web/public/stage_view.js +78 -7
  92. data/lib/samagotchi/web/public/stream_handlers.js +1 -1
  93. data/lib/samagotchi/web/public/turn_events.js +0 -122
  94. data/lib/samagotchi/web/public/turn_model.js +1 -1
  95. data/lib/samagotchi/web/public/widget_picks.js +18 -3
  96. data/lib/samagotchi/web/session_control.rb +15 -2
  97. data/lib/samagotchi/web/session_create.rb +4 -2
  98. data/lib/samagotchi/web/token.rb +2 -2
  99. data/lib/samagotchi/web/update_check.rb +27 -8
  100. metadata +5 -1
@@ -1,10 +1,11 @@
1
- // The session bar's info line (#infoText), three groups with hairlines
2
- // between them: the setup (the open session's id, a button that copies the
3
- // full id; status, model, the ⚙ settings chip (thinking, reasoning history,
4
- // LLM context), the 🧰 toolkit chip, model notes, memories or the working
5
- // set), the relations (chain links, the parent, delegates, participants)
6
- // and the telemetry (folder, ctx, speed, the session clock, the worker's
7
- // version badge). A lit-html template over a
1
+ // The session bar's info line (#infoText), four groups with hairlines
2
+ // between them: the identity (the open session's id, a button that copies
3
+ // the full id; status, ctx, speed, the session clock), the setup (the ⚙
4
+ // settings chip: thinking, reasoning history, LLM context; the model, the
5
+ // 🧰 toolkit chip, model notes, memories or the working set), the relations
6
+ // (chain links, the parent, delegates, participants) and the trail (folder,
7
+ // the worker's version badge). One row at every width: what doesn't fit
8
+ // folds into ⋯ (bar_fold.js, by BAR_ITEMS' ranks). A lit-html template over a
8
9
  // plain model (info_bar_model.js, applied by app.js's updateInfoBar), so the markup lives here and
9
10
  // runs under node --test (spec/web/public/info_bar.test.js).
10
11
  //
@@ -27,13 +28,15 @@ export const CLOCK_NONE = "–";
27
28
  export const NEXT = "→";
28
29
 
29
30
  // A chain's ← / → link (chains.js chainNeighbours): its date or time (else
30
- // its short id), its id, full start and preview in the tooltip. +link+:
31
+ // its short id), its id, full start and preview in the tooltip; classed
32
+ // chain-prev or chain-next by its side (info_bar_model.js BAR_ITEMS). +link+:
31
33
  // {id, date, stamp, preview, archived} (info_bar_model.js chainLinkView).
32
34
  export function chainLinkTemplate(link, arrow, what) {
33
35
  const short = String(link.id).slice(0, 8);
34
36
  const title = `${what}: ${short}${link.stamp ? ` · ${link.stamp}` : ""}${link.preview ? ` · ${link.preview}` : ""}${link.archived ? " (archived)" : ""}`;
35
37
  const text = arrow === PREV ? `${arrow} ${link.date || short}` : `${link.date || short} ${arrow}`;
36
- return html`<a class="model chain-link" href=${sessionHash(link.id)} title=${title}>${text}</a>`;
38
+ const side = arrow === PREV ? "chain-prev" : "chain-next";
39
+ return html`<a class=${`model chain-link ${side}`} href=${sessionHash(link.id)} title=${title}>${text}</a>`;
37
40
  }
38
41
 
39
42
  // `memories: a, b · preloaded: c · muted: d`: the used memories always,
@@ -92,20 +95,29 @@ export function workingSetChipTemplate(chip) {
92
95
  // first generation; null: no chip), clock (the session time's text, "" for
93
96
  // none: the muted CLOCK_NONE), worker ({badge, busy} or null), participants (the
94
97
  // participants chip: participants_panel.js chipModel, or null).
95
- // Three span.bar-group (setup, relations, telemetry), a span.bar-sep
96
- // between two drawn ones; the relations only when it has a part.
98
+ // Four span.bar-group, left to right: identity (the id, status, ctx, speed,
99
+ // the session clock), setup (⚙, the model, 🧰, model notes, memories or the
100
+ // working set), relations (the pruned note, chain links, the parent,
101
+ // delegates, participants; drawn only when it has a part) and trail (the
102
+ // folder, the worker's badge). A span.bar-sep before each group but the
103
+ // first, classed by the group it precedes (sep-setup…): the fold
104
+ // (bar_fold.js) names a group left with nothing on the row in #infoBar's
105
+ // data-empty-groups, and index.html's CSS hides it and its hairline.
97
106
  export function infoBarHtml(bar) {
98
107
  if (!bar) return nothing;
99
108
  const memories = bar.memories || [];
100
- const setup = html`<button type="button" class="id" title=${`Session id ${bar.id}: click to copy it`}>${String(bar.id).slice(0, 8)}</button><span class=${bar.status ? `status ${bar.status}` : "status"}><span>${bar.status || ""}</span></span><span class=${`model${bar.model.mismatch ? " served-mismatch" : ""}`} title=${bar.model.title}>${bar.model.text}</span>${settingsChip(bar.settings)}${toolkitChip(bar.toolkit)}${bar.notes ? html`<span class="model notes-chip" title=${bar.notes.title}>${bar.notes.text}</span>` : nothing}${bar.workingSet ? workingSetChipTemplate(bar.workingSet.chip) : memories.length ? html`<span class="model mem-chip" title=${memChipTitle(memories)}>${memChipText(memories)}</span>` : nothing}`;
101
- const related = !!(bar.chain?.prev || bar.chain?.next || bar.chain?.pruned || bar.parent || bar.kids || bar.participants);
109
+ const sep = (group) => html`<span class=${`bar-sep sep-${group}`} aria-hidden="true"></span>`;
110
+ const identity = html`<button type="button" class="id" title=${`Session id ${bar.id}: click to copy it`}>${String(bar.id).slice(0, 8)}</button><span class=${bar.status ? `status ${bar.status}` : "status"} title=${bar.statusTip || nothing}><span>${bar.statusText || bar.status || ""}</span></span><span class="model ctx" title=${bar.ctx.tip}>${bar.ctx.text}</span>${bar.speed ? html`<span class=${`model speed${bar.speed.empty ? " empty" : ""}`} title=${bar.speed.tip}>${bar.speed.text}</span>` : nothing}<span class=${`model session-time${bar.clock ? "" : " empty"}`} title=${bar.clock ? "This session's time: its turns, and the running one" : "This session's time: no turn yet"}>${bar.clock || CLOCK_NONE}</span>`;
111
+ const setup = html`${settingsChip(bar.settings)}<span class=${`model model-name${bar.model.mismatch ? " served-mismatch" : ""}`} title=${bar.model.title}>${bar.model.text}</span>${toolkitChip(bar.toolkit)}${bar.notes ? html`<span class="model notes-chip" title=${bar.notes.title}>${bar.notes.text}</span>` : nothing}${bar.workingSet ? workingSetChipTemplate(bar.workingSet.chip) : memories.length ? html`<span class="model mem-chip" title=${memChipTitle(memories)}>${memChipText(memories)}</span>` : nothing}`;
112
+ const pruned = !!bar.chain?.pruned && !bar.chain?.prev;
113
+ const related = !!(bar.chain?.prev || bar.chain?.next || pruned || bar.parent || bar.kids || bar.participants);
102
114
  // A chain pruned by a schedule (docs/scheduling.md): the link before this one
103
115
  // is gone, so there is nothing to link to — the bar says so instead.
104
116
  const relations = related
105
- ? html`<span class="bar-sep" aria-hidden="true"></span><span class="bar-group relations">${bar.chain?.prev ? chainLinkTemplate(bar.chain.prev, PREV, "The previous link of this chain") : nothing}${bar.chain?.pruned && !bar.chain?.prev ? html`<span class="model chain-pruned" title="The links before this one were pruned by a schedule">↩ earlier links pruned</span>` : nothing}${bar.chain?.next ? chainLinkTemplate(bar.chain.next, NEXT, "The next link of this chain") : nothing}${bar.parent ? html`<a class="model parent" href=${sessionHash(bar.parent.id)} title=${bar.parent.title}>↑ ${String(bar.parent.id).slice(0, 8)}</a>` : nothing}${kidsTemplate(bar.kids)}${participantsChip(bar.participants)}</span>`
117
+ ? html`${sep("relations")}<span class="bar-group relations">${pruned ? html`<span class="model chain-pruned" title="The links before this one were pruned by a schedule">↩ earlier links pruned</span>` : nothing}${bar.chain?.prev ? chainLinkTemplate(bar.chain.prev, PREV, "The previous link of this chain") : nothing}${bar.chain?.next ? chainLinkTemplate(bar.chain.next, NEXT, "The next link of this chain") : nothing}${bar.parent ? html`<a class="model parent" href=${sessionHash(bar.parent.id)} title=${bar.parent.title}>↑ ${String(bar.parent.id).slice(0, 8)}</a>` : nothing}${kidsTemplate(bar.kids)}${participantsChip(bar.participants)}</span>`
106
118
  : nothing;
107
- const telemetry = html`<span class="dir" title=${bar.dir || ""}><bdi>${bar.dir || ""}</bdi></span><span class="model ctx" title=${bar.ctx.tip}>${bar.ctx.text}</span>${bar.speed ? html`<span class=${`model speed${bar.speed.empty ? " empty" : ""}`} title=${bar.speed.tip}>${bar.speed.text}</span>` : nothing}<span class=${`model session-time${bar.clock ? "" : " empty"}`} title=${bar.clock ? "This session's time: its turns, and the running one" : "This session's time: no turn yet"}>${bar.clock || CLOCK_NONE}</span>${workerBadgeTemplate(bar.worker)}`;
108
- return html`<div class="meta"><span class="bar-group setup">${setup}</span>${relations}<span class="bar-sep" aria-hidden="true"></span><span class="bar-group telemetry">${telemetry}</span></div>`;
119
+ const trail = html`<span class="dir" title=${bar.dir || ""}><bdi>${bar.dir || ""}</bdi></span>${workerBadgeTemplate(bar.worker)}`;
120
+ return html`<div class="meta"><span class="bar-group identity">${identity}</span>${sep("setup")}<span class="bar-group setup">${setup}</span>${relations}${sep("trail")}<span class="bar-group trail">${trail}</span></div>`;
109
121
  }
110
122
 
111
123
  // Draws +bar+ into +el+ (#infoText), with the memories in its tooltip
@@ -8,6 +8,74 @@ import { chainClock, chainDate, chainNeighbours } from "./chains.js";
8
8
  import { ctxBarText, ctxBarTip, lastSpeedText, speedText } from "./ctx.js";
9
9
  import { formatDuration, sessionDurationNow } from "./timing.js";
10
10
  import { workerBadge } from "./update_notice.js";
11
+ import { chipModel as settingsChipModel } from "./settings_chip.js";
12
+ import { REACH } from "./resync_reach.js";
13
+
14
+ // Every chip and button of the session bar (#infoBar), one item per key:
15
+ // {key, selector (its element in #infoBar), group (the .meta's identity,
16
+ // setup, relations, trail as info_bar.js draws them; actions: #infoActions
17
+ // and ⋯), rank, phone, compact, menuOrder}.
18
+ // rank: the desktop fold order, a higher rank stays longer; "pinned"
19
+ // never folds, "menu" is never on the row. Items of one rank fold together.
20
+ // phone: "row" (a row candidate at the phone width) or "menu".
21
+ // compact: a smaller row form tried before the item folds (⚙ alone).
22
+ // menuOrder: its place in ⋯ (more_sheet.js ROW_KEYS, ACTION_KEYS: the
23
+ // actions group's are the actions, the others rows); null: no row (status,
24
+ // ⋯ itself; ctx, speed, time and the folder are its telemetry line).
25
+ // Data for the fold (docs/internals/web-frontend.md): shaped so a bundle or
26
+ // the user can add an item with a rank later.
27
+ export const BAR_ITEMS = Object.freeze([
28
+ { key: "status", selector: ".status", group: "identity", rank: "pinned", phone: "row", menuOrder: null },
29
+ { key: "ctx", selector: ".ctx", group: "identity", rank: "pinned", phone: "row", menuOrder: null },
30
+ { key: "more", selector: "#infoMoreBtn", group: "actions", rank: "pinned", phone: "row", menuOrder: null },
31
+ { key: "id", selector: ".id", group: "identity", rank: 12, phone: "menu", menuOrder: 1 },
32
+ { key: "continue", selector: "#infoContinueBtn", group: "actions", rank: 11, phone: "menu", menuOrder: 1 },
33
+ { key: "settings", selector: ".settings-chip", group: "setup", rank: 10, phone: "row", compact: true, menuOrder: 3 },
34
+ { key: "worker", selector: ".worker-badge", group: "trail", rank: 9, phone: "menu", menuOrder: 14 },
35
+ { key: "speed", selector: ".speed", group: "identity", rank: 8, phone: "row", menuOrder: null },
36
+ { key: "stop", selector: "#infoStopBtn", group: "actions", rank: 7, phone: "menu", menuOrder: 3 },
37
+ { key: "prev", selector: ".chain-prev", group: "relations", rank: 6, phone: "menu", menuOrder: 9 },
38
+ { key: "next", selector: ".chain-next", group: "relations", rank: 6, phone: "menu", menuOrder: 10 },
39
+ { key: "pruned", selector: ".chain-pruned", group: "relations", rank: 6, phone: "menu", menuOrder: 8 },
40
+ { key: "parent", selector: ".parent", group: "relations", rank: 6, phone: "menu", menuOrder: 11 },
41
+ { key: "time", selector: ".session-time", group: "identity", rank: 5, phone: "menu", menuOrder: null },
42
+ { key: "model", selector: ".model-name", group: "setup", rank: 4, phone: "menu", menuOrder: 2 },
43
+ { key: "delegates", selector: ".children-chip", group: "relations", rank: 3, phone: "menu", menuOrder: 12 },
44
+ { key: "participants", selector: ".participants-chip", group: "relations", rank: 3, phone: "menu", menuOrder: 7 },
45
+ { key: "workingSet", selector: ".ws-chip", group: "setup", rank: 2, phone: "menu", menuOrder: 5 },
46
+ { key: "memories", selector: ".mem-chip", group: "setup", rank: 2, phone: "menu", menuOrder: 6 },
47
+ { key: "notes", selector: ".notes-chip", group: "setup", rank: 2, phone: "menu", menuOrder: 13 },
48
+ { key: "toolkit", selector: ".tools-chip", group: "setup", rank: 1, phone: "menu", menuOrder: 4 },
49
+ { key: "dir", selector: ".dir", group: "trail", rank: 1, phone: "menu", menuOrder: null },
50
+ { key: "archive", selector: "#infoArchiveBtn", group: "actions", rank: "menu", phone: "menu", menuOrder: 2 },
51
+ { key: "delete", selector: "#infoDeleteBtn", group: "actions", rank: "menu", phone: "menu", menuOrder: 4 },
52
+ ].map((item) => Object.freeze({ compact: false, ...item })));
53
+
54
+ // The BAR_ITEMS keys the open session's bar draws (info_bar.js infoBarHtml
55
+ // for +bar+, the buttons app.js shows from +buttons+), in BAR_ITEMS' order;
56
+ // [] without a session.
57
+ export function barItemKeys(bar, buttons) {
58
+ if (!bar) return [];
59
+ const has = {
60
+ status: true, ctx: true, more: true, id: true, time: true, model: true, dir: true,
61
+ continue: !!buttons?.continue?.shown, stop: !!buttons?.stop?.shown,
62
+ archive: !!buttons?.archive?.shown, delete: !!buttons?.delete?.shown,
63
+ settings: !!(bar.settings && settingsChipModel(bar.settings)),
64
+ worker: !!bar.worker?.badge,
65
+ speed: !!bar.speed,
66
+ prev: !!bar.chain?.prev,
67
+ next: !!bar.chain?.next,
68
+ pruned: !!bar.chain?.pruned && !bar.chain?.prev,
69
+ parent: !!bar.parent,
70
+ delegates: !!bar.kids,
71
+ participants: !!bar.participants,
72
+ workingSet: !!bar.workingSet?.chip,
73
+ memories: !bar.workingSet && (bar.memories || []).length > 0,
74
+ notes: !!bar.notes,
75
+ toolkit: !!bar.toolkit,
76
+ };
77
+ return BAR_ITEMS.filter((item) => has[item.key]).map((item) => item.key);
78
+ }
11
79
 
12
80
  // The speed chip's placeholder before the session's first generation.
13
81
  export const SPEED_NONE = "– tok/s";
@@ -84,14 +152,20 @@ export function infoBarModel({ id, state, sessions, chain, cardTitle, badge, res
84
152
  // link may not be listed yet: then neither, and its links show dates).
85
153
  const selfIso = state.createdAt || sessions.find((x) => x.id === id)?.created_at || null;
86
154
  const parentChip = delegatedBy(state.parentId, sessions.find((x) => x.id === state.parentId) || null);
155
+ const reach = REACH[state.reach] || null;
87
156
  return {
88
157
  id,
89
158
  // Its turn runs but a card blocks it: the word `chi sessions list` has for it.
90
- status: running && waiting ? "waiting" : state.status,
159
+ // A re-read that can't reach chi web says so in its place
160
+ // (resync_reach.js): +statusText+ and +statusTip+ then.
161
+ status: reach ? reach.status : running && waiting ? "waiting" : state.status,
162
+ ...(reach ? { statusText: reach.text, statusTip: reach.tip } : {}),
91
163
  model: modelLabel(state.model, ...(state.served || [])),
92
164
  // A link of a session chain: ← the previous link, → the next one (each
93
165
  // only while the list holds it).
94
- chain: { prev: chainLinkView(chain.prev, cardTitle, selfIso), next: chainLinkView(chain.next, cardTitle, selfIso) },
166
+ // +pruned+: the link before this one is gone (a schedule pruned it).
167
+ chain: { prev: chainLinkView(chain.prev, cardTitle, selfIso), next: chainLinkView(chain.next, cardTitle, selfIso),
168
+ pruned: !!chain.pruned },
95
169
  parent: parentChip ? { id: state.parentId, title: parentChip.title } : null,
96
170
  // A parent names its delegates; the link opens all sessions.
97
171
  kids: childrenSummary({ id }, sessions),
@@ -102,6 +102,9 @@ export function createLiveTiming({
102
102
  get ended() { return ended; },
103
103
  set ended(n) { ended = n; },
104
104
  get ticking() { return ticker !== null; },
105
+ // What the running turn waits on ("": nothing; the stage's quiet signal
106
+ // says nothing while it waits on something named).
107
+ get note() { return note; },
105
108
 
106
109
  start(startedAt = new Date(now()).toISOString(), id = null) {
107
110
  stopTicker();
@@ -1,8 +1,18 @@
1
- // The phone's session bar keeps id, status, model and ⚙ on its row; the rest
2
- // sits behind ⋯ (#infoMoreBtn, index.html's CSS shows it at the page's phone
3
- // width only). This is its bottom sheet, on chip_popover.js' shell as the ⚙
4
- // panel is: a row for each chip the row folded away, one telemetry line, and
5
- // the bar's four actions.
1
+ // The session bar's ⋯ (#infoBar's #infoMoreBtn, on the row at every width):
2
+ // what the row folded away (bar_fold.js), as a popover above the phone's
3
+ // width and a bottom sheet under it, on chip_popover.js' shell as the ⚙ panel
4
+ // is. A row per folded chip, a telemetry line for the folded ones of speed,
5
+ // the clock and the folder, and the bar's actions; which rows and actions
6
+ // exist, and in what order, is info_bar_model.js BAR_ITEMS (menuOrder), the
7
+ // bar's one list of its items.
8
+ //
9
+ // +folded+ (a Set of BAR_ITEMS keys: the items folded off the row) narrows
10
+ // the menu to them: a row only for a folded chip (the id, ⚙ when folded, not
11
+ // when compact, and "earlier links pruned" included), Continue and Stop only
12
+ // when folded (Archive and Delete always: they are never on the row), ⋯'s
13
+ // dot from folded rows alone and its count (moreCount: shown on a desktop
14
+ // only). Without it (null) the menu has its fixed set: every chip's row but
15
+ // those three, the whole telemetry line and all four actions.
6
16
  //
7
17
  // The chips and the buttons stay where they are, display:none: a row or an
8
18
  // action clicks the real one (`go:`), so its handlers, confirmations and state
@@ -10,22 +20,26 @@
10
20
  // the same way). What a chip then opens places itself and gives focus back at
11
21
  // ⋯, chip_popover.js' stand-in for an anchor with no box ([data-anchor-stand-in]).
12
22
  // A chip with a tooltip and no popover (🧰, memories, model notes) unfolds its
13
- // tooltip under the row (`info:`): a phone has no tooltips. The model has a row
14
- // too: its chip stays on the bar but is the first to give way, cut short.
23
+ // tooltip under the row (`info:`): a phone has no tooltips.
15
24
  //
16
25
  // app.js's updateInfoBar calls update() on every redraw (every second while a
17
- // turn runs): lit writes only what changed, into slots that keep their place,
18
- // so an open sheet stays current and keeps its focus. A module of its own: the
19
- // page's modules are cached at unversioned URLs (docs/internals/web-frontend.md).
26
+ // turn runs), after the fold's: lit writes only what changed, into slots that
27
+ // keep their place, so an open menu stays current and keeps its focus. A
28
+ // module of its own: the page's modules are cached at unversioned URLs
29
+ // (docs/internals/web-frontend.md).
20
30
 
21
31
  import { createChipPopover, SHEET_TALL } from "./chip_popover.js";
22
32
  import { memChipText } from "./format.js";
23
33
  import { CLOCK_NONE, memoriesTooltip, NEXT, PREV } from "./info_bar.js";
34
+ import { BAR_ITEMS } from "./info_bar_model.js";
35
+ import { chipModel as settingsChip } from "./settings_chip.js";
24
36
  import { chipModel as toolkitChip } from "./toolkit_chip.js";
25
37
  import { html, nothing, render } from "./vendor/lit-html.js";
26
38
 
27
39
  // The real element each `go:` act clicks.
28
40
  const TARGETS = {
41
+ id: "#infoText .id",
42
+ settings: "#infoText .settings-chip",
29
43
  workingSet: "#infoText .ws-chip",
30
44
  participants: "#infoText .participants-chip",
31
45
  delegates: "#infoText .children-chip",
@@ -36,9 +50,16 @@ const TARGETS = {
36
50
  delete: "#infoDeleteBtn",
37
51
  };
38
52
 
39
- // Every row, in the sheet's order; each draws into a slot of its own.
40
- const ROW_KEYS = ["model", "toolkit", "workingSet", "memories", "participants", "prev", "next", "parent", "delegates", "notes", "worker"];
41
- const ACTION_KEYS = ["continue", "archive", "stop", "delete"];
53
+ // Every row and every action, in the sheet's order (BAR_ITEMS' menuOrder);
54
+ // each draws into a slot of its own.
55
+ const inMenu = (actions) => BAR_ITEMS
56
+ .filter((item) => item.menuOrder !== null && (item.group === "actions") === actions)
57
+ .sort((a, b) => a.menuOrder - b.menuOrder)
58
+ .map((item) => item.key);
59
+ export const ROW_KEYS = Object.freeze(inMenu(false));
60
+ export const ACTION_KEYS = Object.freeze(inMenu(true));
61
+ // The actions every sheet has; the others only when folded.
62
+ const ALWAYS_ACTIONS = new Set(["archive", "delete"]);
42
63
 
43
64
  const short = (id) => String(id).slice(0, 8);
44
65
  const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
@@ -79,16 +100,20 @@ function workerRow({ badge, busy }) {
79
100
  // session has its chip: {key, label, value, and how a tap acts: go (a TARGETS
80
101
  // key), href, info (the text it unfolds), restart ({busy}); attention: "accent"
81
102
  // or "warn" when the chip asks for a look; icon: a chip icon's class}.
82
- export function moreRows(bar) {
103
+ export function moreRows(bar, folded = null) {
83
104
  if (!bar) return [];
84
105
  const memories = bar.memories || [];
85
- return [
106
+ const gear = folded?.has("settings") && bar.settings && settingsChip(bar.settings);
107
+ const rows = [
108
+ folded?.has("id") && { key: "id", label: "Session id", value: short(bar.id), go: "id" },
86
109
  bar.model && modelRow(bar.model),
110
+ gear && { key: "settings", label: "Settings", value: gear.text || "follows the model", go: "settings" },
87
111
  bar.toolkit && toolkitRow(bar.toolkit),
88
112
  bar.workingSet?.chip && workingSetRow(bar.workingSet.chip),
89
113
  !bar.workingSet && memories.length > 0
90
114
  && { key: "memories", label: "Memories", value: memChipText(memories), info: memoriesTooltip(memories, bar.preloaded, bar.muted) },
91
115
  bar.participants && participantsRow(bar.participants),
116
+ folded?.has("pruned") && bar.chain?.pruned && !bar.chain?.prev && { key: "pruned", label: "Earlier links pruned", value: "by a schedule" },
92
117
  bar.chain?.prev && { key: "prev", label: "Previous link", value: `${PREV} ${bar.chain.prev.date || short(bar.chain.prev.id)}`, href: bar.chain.prev.id },
93
118
  bar.chain?.next && { key: "next", label: "Next link", value: `${bar.chain.next.date || short(bar.chain.next.id)} ${NEXT}`, href: bar.chain.next.id },
94
119
  bar.parent && { key: "parent", label: "Delegated by", value: `↑ ${short(bar.parent.id)}`, href: bar.parent.id },
@@ -96,13 +121,15 @@ export function moreRows(bar) {
96
121
  bar.notes && { key: "notes", label: "Model notes", value: bar.notes.text.replace(/^notes: /, ""), info: bar.notes.title },
97
122
  bar.worker?.badge && workerRow(bar.worker),
98
123
  ].filter(Boolean);
124
+ return folded ? rows.filter((row) => folded.has(row.key)) : rows;
99
125
  }
100
126
 
101
127
  // ⋯'s dot: what behind it asks for a look. {kind} is the strongest ("warn":
102
128
  // a delegate waiting, an older worker; "accent": the working set changed, a
103
129
  // participant here; null: none), {label} ⋯'s accessible name, which says why.
104
- export function moreAttention(bar) {
105
- const rows = moreRows(bar).filter((row) => row.attention);
130
+ // With +folded+, only the folded rows count: a chip on the row shows its own.
131
+ export function moreAttention(bar, folded = null) {
132
+ const rows = moreRows(bar, folded).filter((row) => row.attention);
106
133
  const kind = rows.some((row) => row.attention === "warn") ? "warn" : rows.length ? "accent" : null;
107
134
  const why = rows.map((row) => `${row.label}: ${row.value}`).join(", ");
108
135
  return { kind, label: why ? `More: ${why}` : "More" };
@@ -110,15 +137,16 @@ export function moreAttention(bar) {
110
137
 
111
138
  // The four actions as the sheet draws them from +buttons+ (info_bar_model.js
112
139
  // infoButtons), each with the rule its button has; Continue takes the accent
113
- // on an archived session, where it is the thing to do.
114
- export function moreActions(buttons) {
140
+ // on an archived session, where it is the thing to do. With +folded+,
141
+ // Continue and Stop only when folded (on the row they are their own buttons).
142
+ export function moreActions(buttons, folded = null) {
115
143
  const all = [
116
144
  buttons.continue.shown && { key: "continue", text: capital(buttons.continue.text.replace(/ →$/, "")), disabled: buttons.continue.disabled, accent: !!buttons.archive.archived },
117
145
  buttons.archive.shown && { key: "archive", text: capital(buttons.archive.text), title: buttons.archive.title },
118
146
  buttons.stop.shown && { key: "stop", text: "Stop" },
119
147
  buttons.delete.shown && { key: "delete", text: "Delete" },
120
- ];
121
- return all.filter(Boolean);
148
+ ].filter(Boolean);
149
+ return folded ? all.filter((act) => ALWAYS_ACTIONS.has(act.key) || folded.has(act.key)) : all;
122
150
  }
123
151
 
124
152
  function rowBody(row) {
@@ -129,32 +157,57 @@ function rowBody(row) {
129
157
 
130
158
  function rowTemplate(row, { shownInfo, hash }) {
131
159
  const cls = `more-row${row.attention ? ` ${row.attention}` : ""}`;
132
- if (row.href) return html`<a class=${cls} href=${hash(row.href)} data-act="link">${rowBody(row)}</a>`;
133
- if (row.go) return html`<button type="button" class=${cls} data-act=${`go:${row.go}`}>${rowBody(row)}</button>`;
160
+ if (row.href) return html`<a class=${cls} href=${hash(row.href)} data-act="link" data-row=${row.key}>${rowBody(row)}</a>`;
161
+ if (row.go) return html`<button type="button" class=${cls} data-act=${`go:${row.go}`} data-row=${row.key}>${rowBody(row)}</button>`;
134
162
  if (row.restart) {
135
- return html`<div class=${cls}>${rowBody(row)}<button type="button" class="more-restart" data-act="go:restart" ?disabled=${row.restart.busy}>${row.restart.busy ? "restarting…" : "Restart"}</button></div>`;
163
+ return html`<div class=${cls} data-row=${row.key}>${rowBody(row)}<button type="button" class="more-restart" data-act="go:restart" ?disabled=${row.restart.busy}>${row.restart.busy ? "restarting…" : "Restart"}</button></div>`;
136
164
  }
137
- if (!row.info) return html`<div class=${cls}>${rowBody(row)}</div>`;
165
+ if (!row.info) return html`<div class=${cls} data-row=${row.key}>${rowBody(row)}</div>`;
138
166
  const open = shownInfo === row.key;
139
- return html`<button type="button" class=${cls} data-act=${`info:${row.key}`} aria-expanded=${open ? "true" : "false"}>${rowBody(row)}</button>${open ? html`<div class="more-info">${row.info}</div>` : nothing}`;
167
+ return html`<button type="button" class=${cls} data-act=${`info:${row.key}`} data-row=${row.key} aria-expanded=${open ? "true" : "false"}>${rowBody(row)}</button>${open ? html`<div class="more-info">${row.info}</div>` : nothing}`;
168
+ }
169
+
170
+ // The sheet for +bar+ and +buttons+ (each row carries data-row, its key: the
171
+ // e2e's way to it) (+folded+: moreRows'). +shownInfo+: the
172
+ // key of the row whose tooltip is unfolded; +hash+: a session's id to its link.
173
+ // The telemetry line's parts for +bar+: ctx, speed, the clock, the folder;
174
+ // with +folded+ only the folded ones of speed, the clock and the folder (ctx
175
+ // is pinned on the row).
176
+ export function moreTelemetry(bar, folded = null) {
177
+ if (!bar) return [];
178
+ const parts = [
179
+ { key: "ctx", show: true },
180
+ { key: "speed", show: !!bar.speed },
181
+ { key: "time", show: true },
182
+ { key: "dir", show: true },
183
+ ];
184
+ return parts.filter((p) => p.show && (!folded || (p.key !== "ctx" && folded.has(p.key)))).map((p) => p.key);
185
+ }
186
+
187
+ // The count on ⋯ (a desktop's; none at 0): the entries the menu has for
188
+ // folded items: their rows, telemetry and actions (Archive and Delete, never
189
+ // on the row, don't count). 0 without a fold.
190
+ export function moreCount(bar, buttons, folded) {
191
+ if (!bar || !folded) return 0;
192
+ const acts = buttons ? moreActions(buttons, folded).filter((act) => !ALWAYS_ACTIONS.has(act.key)).length : 0;
193
+ return moreRows(bar, folded).length + moreTelemetry(bar, folded).length + acts;
140
194
  }
141
195
 
142
- // The sheet for +bar+ and +buttons+. +shownInfo+: the key of the row whose
143
- // tooltip is unfolded; +hash+: a session's id to its link.
144
- export function moreSheetTemplate({ bar, buttons, shownInfo = null, hash }) {
145
- const rows = moreRows(bar);
146
- const actions = moreActions(buttons);
196
+ export function moreSheetTemplate({ bar, buttons, folded = null, shownInfo = null, hash }) {
197
+ const rows = moreRows(bar, folded);
198
+ const actions = moreActions(buttons, folded);
199
+ const tele = new Set(moreTelemetry(bar, folded));
147
200
  const speed = bar.speed;
148
201
  return html`<div class="more-grip" aria-hidden="true"></div
149
202
  ><div class="more-rows">${ROW_KEYS.map((key) => {
150
203
  const row = rows.find((r) => r.key === key);
151
204
  return row ? rowTemplate(row, { shownInfo, hash }) : nothing;
152
205
  })}</div
153
- ><div class="more-telemetry"><span class="more-ctx" title=${bar.ctx.tip}>${bar.ctx.text}</span
154
- >${speed ? html`<span class="more-speed" title=${speed.tip}>${speed.text}</span>` : nothing
155
- }<span class="more-clock">${bar.clock || CLOCK_NONE}</span
156
- ><span class="more-dir" title=${bar.dir || ""}><bdi>${bar.dir || ""}</bdi></span></div
157
- ><div class="more-actions">${ACTION_KEYS.map((key) => {
206
+ >${tele.size ? html`<div class="more-telemetry">${tele.has("ctx") ? html`<span class="more-ctx" title=${bar.ctx.tip}>${bar.ctx.text}</span>` : nothing
207
+ }${tele.has("speed") ? html`<span class="more-speed" title=${speed.tip}>${speed.text}</span>` : nothing
208
+ }${tele.has("time") ? html`<span class="more-clock">${bar.clock || CLOCK_NONE}</span>` : nothing
209
+ }${tele.has("dir") ? html`<span class="more-dir" title=${bar.dir || ""}><bdi>${bar.dir || ""}</bdi></span>` : nothing}</div>` : nothing
210
+ }<div class="more-actions">${ACTION_KEYS.map((key) => {
158
211
  const act = actions.find((a) => a.key === key);
159
212
  if (!act) return nothing;
160
213
  return html`<button type="button" class=${`more-act ${key}${act.accent ? " accent" : ""}`} data-act=${`go:${key}`}
@@ -164,14 +217,15 @@ export function moreSheetTemplate({ bar, buttons, shownInfo = null, hash }) {
164
217
 
165
218
  // ⋯'s sheet. el: where ⋯ is drawn (#infoBar); button: ⋯ itself; session(): the
166
219
  // open session's id; hash: a session's id to its link (route.js sessionHash).
167
- // @return {update({bar, buttons}), close, isOpen, pop}
220
+ // @return {update({bar, buttons, folded}), close, isOpen, pop}
168
221
  export function createMoreSheet({ el, button, session = () => null, hash, doc = document, win = window }) {
169
222
  let bar = null;
170
223
  let buttons = null;
224
+ let folded = null;
171
225
  let shownInfo = null;
172
226
 
173
227
  function draw() {
174
- render(moreSheetTemplate({ bar, buttons, shownInfo, hash }), shell.pop);
228
+ render(moreSheetTemplate({ bar, buttons, folded, shownInfo, hash }), shell.pop);
175
229
  }
176
230
 
177
231
  const shell = createChipPopover({
@@ -199,10 +253,14 @@ export function createMoreSheet({ el, button, session = () => null, hash, doc =
199
253
  function update(next) {
200
254
  bar = next.bar;
201
255
  buttons = next.buttons;
202
- const { kind, label } = moreAttention(bar);
256
+ folded = next.folded || null;
257
+ const { kind, label } = moreAttention(bar, folded);
203
258
  if (kind) button.dataset.attention = kind;
204
259
  else delete button.dataset.attention;
205
- button.setAttribute("aria-label", label);
260
+ const count = moreCount(bar, buttons, folded);
261
+ const countEl = button.querySelector(".more-count");
262
+ if (countEl) countEl.textContent = count ? String(count) : "";
263
+ button.setAttribute("aria-label", count ? `${label} (${count} folded)` : label);
206
264
  button.title = label;
207
265
  // Another session, or none, closes it; else the open sheet follows.
208
266
  shell.refresh();
@@ -0,0 +1,59 @@
1
+ // A re-read of the open session (app.js resync) that could not reach chi web:
2
+ // the one rule for what the page does then. The history already drawn for
3
+ // this session stays as it is (the conversation is still right, only newer
4
+ // events are missing) and the info bar's status chip says the page is
5
+ // reconnecting, then, once the retries ran out, that it can't reach chi web;
6
+ // the next re-read that succeeds clears it (the hub's next event re-reads a
7
+ // session left in that state: needsReread). Only a first load (select()'s
8
+ // "Loading…", nothing of the session drawn yet) shows the error in the
9
+ // history, as there is nothing to keep.
10
+ // Its own module: new exports go in new modules (web-frontend.md).
11
+
12
+ // The status chip's word (its class), text and tooltip per state.
13
+ export const REACH = Object.freeze({
14
+ reconnecting: Object.freeze({
15
+ status: "reconnecting", text: "reconnecting…",
16
+ tip: "Can't reach chi web: trying again. The conversation shown is as it was; newer events show once it's back.",
17
+ }),
18
+ offline: Object.freeze({
19
+ status: "offline", text: "can't reach chi web",
20
+ tip: "Can't reach chi web. The conversation shown is as it was; the page reads it again once chi web is back.",
21
+ }),
22
+ });
23
+
24
+ // What a failed re-read does. +drawn+: the history shows this session's
25
+ // conversation; +retrying+: another try is scheduled.
26
+ // @return {{hint: boolean, reach: "reconnecting"|"offline"|null}}
27
+ // hint: replace the history with the error; reach: the store's field.
28
+ export function readFailed({ drawn, retrying }) {
29
+ if (!drawn) return { hint: true, reach: null };
30
+ return { hint: false, reach: retrying ? "reconnecting" : "offline" };
31
+ }
32
+
33
+ // The page side. +store+: the session store (its current.reach); +historyEl+,
34
+ // +errorHint+(message): the node a first load's failure shows.
35
+ export function createResyncReach({ store, historyEl, errorHint }) {
36
+ // The session whose conversation the history shows (null: a "Loading…"
37
+ // or error hint, the start page).
38
+ let drawnId = null;
39
+ return {
40
+ // select() put its "Loading…" hint in.
41
+ loading() {
42
+ drawnId = null;
43
+ },
44
+ // A re-read of +id+ drew it: the indicator goes.
45
+ drawn(id) {
46
+ drawnId = id;
47
+ if (store.current.reach) store.update({ current: { reach: null } });
48
+ },
49
+ // A re-read of +id+ (the open session) failed with +message+.
50
+ failed(id, message, { retrying }) {
51
+ const { hint, reach } = readFailed({ drawn: drawnId === id, retrying });
52
+ if (hint) historyEl.replaceChildren(errorHint(message));
53
+ if (reach !== store.current.reach) store.update({ current: { reach } });
54
+ },
55
+ // The session still shows a failed re-read: any sign of chi web (a hub
56
+ // event) is worth a re-read, not only a worker's bridge_up.
57
+ needsReread: () => !!store.current.reach,
58
+ };
59
+ }
@@ -110,6 +110,7 @@ export const FIELDS = {
110
110
  turnStarted: { redraws: ["composer", "infoBar"], writers: "setTurnRunning" },
111
111
  streamSeq: { redraws: [], writers: "resync" },
112
112
  streamFromGuess: { redraws: [], writers: "followWokenWorker, startStream, the stream's takeGuess" },
113
+ reach: { redraws: ["infoBar"], writers: "resync (resync_reach.js)" },
113
114
  };
114
115
 
115
116
  // The fields a hub card brings for the open session (followSelectedSession):
@@ -80,6 +80,11 @@ export function emptySessionState() {
80
80
  // The stream was opened from 0 (a wake with no cursor to go on) and no
81
81
  // new turn has started on it yet (app.js followWokenWorker).
82
82
  streamFromGuess: false,
83
+ // A re-read that couldn't reach chi web kept the drawn history
84
+ // (resync_reach.js): "reconnecting" while it retries, "offline" once
85
+ // the tries ran out; null otherwise. Never from a payload: the next
86
+ // re-read that draws the session clears it.
87
+ reach: null,
83
88
  };
84
89
  }
85
90
 
@@ -125,9 +125,11 @@ export function createStageFrame({ stage, scroller, status, cloud, queuedSlot, h
125
125
  function fitCap() {
126
126
  if (stage.hidden) return;
127
127
  // The composer card and the gap above it (the stage floats over them,
128
- // out of the dock's flow).
128
+ // out of the dock's flow), the card's offset from the panel's bottom
129
+ // (index.html --dock-bottom: 16 px, a phone's home indicator's line)
130
+ // and 16 px over the stage.
129
131
  const rest = dockEl.offsetHeight + STAGE_GAP;
130
- const room = centerEl.clientHeight - rest - 32;
132
+ const room = centerEl.clientHeight - rest - 16 - (parseFloat(getComputedStyle(dockEl).bottom) || 16);
131
133
  const share = window.innerHeight * (isRoomCap() ? ROOM_SHARE : isCloudOpen() ? CLOUD_SHARE : SHARE);
132
134
  const cap = Math.max(96, Math.round(Math.min(share, room)));
133
135
  const was = capPx();