samagotchi 0.186.0 → 0.188.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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +68 -1
  3. data/bin/chi +4 -0
  4. data/docs/architecture.md +8 -4
  5. data/docs/bundles.md +124 -120
  6. data/docs/cli.md +26 -5
  7. data/docs/configuration.md +4 -4
  8. data/docs/context.md +18 -162
  9. data/docs/guardrails.md +3 -1
  10. data/docs/hooks.md +2 -1
  11. data/docs/internals/attached-context.md +19 -37
  12. data/docs/internals/bridge.md +1 -0
  13. data/docs/internals/engine.md +2 -2
  14. data/docs/internals/inline-widgets.md +18 -0
  15. data/docs/internals/llm-context-forget.md +5 -6
  16. data/docs/internals/objectives.md +1 -0
  17. data/docs/internals/pages.md +175 -0
  18. data/docs/internals/peers.md +149 -0
  19. data/docs/internals/remote-sessions.md +7 -4
  20. data/docs/internals/web-frontend.md +65 -40
  21. data/docs/internals/web-push.md +1 -1
  22. data/docs/memory.md +8 -1
  23. data/docs/pages.md +151 -0
  24. data/docs/peers.md +141 -0
  25. data/docs/plugins.md +52 -27
  26. data/docs/sessions.md +8 -4
  27. data/docs/sub-agent.md +5 -5
  28. data/lib/samagotchi/bridge.rb +3 -3
  29. data/lib/samagotchi/bundle_command/api_calls.rb +2 -1
  30. data/lib/samagotchi/bundle_command/check.rb +1 -1
  31. data/lib/samagotchi/bundles/claude-peer/manifest.yml +11 -18
  32. data/lib/samagotchi/bundles/claude-peer/plugin.rb +22 -16
  33. data/lib/samagotchi/bundles/claude-peer/scripts/chi-peer-SKILL.md +48 -39
  34. data/lib/samagotchi/bundles/claude-peer/scripts/pair +15 -73
  35. data/lib/samagotchi/bundles/claude-peer/skill_claude_peer.md +16 -16
  36. data/lib/samagotchi/bundles/codex-peer/manifest.yml +11 -15
  37. data/lib/samagotchi/bundles/codex-peer/plugin.rb +35 -24
  38. data/lib/samagotchi/bundles/codex-peer/scripts/chi-peer-SKILL.md +51 -40
  39. data/lib/samagotchi/bundles/codex-peer/scripts/pair +18 -54
  40. data/lib/samagotchi/bundles/codex-peer/skill_codex_peer.md +16 -16
  41. data/lib/samagotchi/bundles/dev/manifest.yml +2 -2
  42. data/lib/samagotchi/bundles/skills/manifest.yml +2 -2
  43. data/lib/samagotchi/bundles/skills/plugin.rb +14 -8
  44. data/lib/samagotchi/bundles/system/manifest.yml +5 -2
  45. data/lib/samagotchi/bundles/system/self_map.md +5 -1
  46. data/lib/samagotchi/bundles/system/skill_pages.md +93 -0
  47. data/lib/samagotchi/client_id.rb +15 -1
  48. data/lib/samagotchi/config.rb +8 -7
  49. data/lib/samagotchi/context_absorber.rb +23 -277
  50. data/lib/samagotchi/context_sources.rb +17 -69
  51. data/lib/samagotchi/engine/messages.rb +12 -1
  52. data/lib/samagotchi/engine/plugins.rb +1 -1
  53. data/lib/samagotchi/engine.rb +7 -6
  54. data/lib/samagotchi/engine_peers.rb +0 -3
  55. data/lib/samagotchi/guardrail_wiring.rb +2 -0
  56. data/lib/samagotchi/guardrails/chi_dirs.rb +4 -3
  57. data/lib/samagotchi/guardrails/parent_approvals.rb +6 -5
  58. data/lib/samagotchi/guardrails/protected_paths.rb +6 -3
  59. data/lib/samagotchi/inline_widgets.rb +73 -0
  60. data/lib/samagotchi/log_line.rb +1 -1
  61. data/lib/samagotchi/note_move.rb +3 -1
  62. data/lib/samagotchi/page_command.rb +243 -0
  63. data/lib/samagotchi/pages/builder.rb +186 -0
  64. data/lib/samagotchi/pages/launch.rb +193 -0
  65. data/lib/samagotchi/pages/runner.rb +154 -0
  66. data/lib/samagotchi/pages/store.rb +152 -0
  67. data/lib/samagotchi/pages.rb +119 -0
  68. data/lib/samagotchi/peer_command.rb +192 -0
  69. data/lib/samagotchi/peer_continue.rb +99 -0
  70. data/lib/samagotchi/peer_exchanges.rb +3 -3
  71. data/lib/samagotchi/peer_mailbox.rb +360 -0
  72. data/lib/samagotchi/peer_note.rb +208 -0
  73. data/lib/samagotchi/peer_receipts.rb +247 -0
  74. data/lib/samagotchi/peer_registry.rb +44 -0
  75. data/lib/samagotchi/peer_roster.rb +79 -0
  76. data/lib/samagotchi/peer_say.rb +168 -0
  77. data/lib/samagotchi/plugin/api.rb +29 -21
  78. data/lib/samagotchi/plugin/context.rb +7 -0
  79. data/lib/samagotchi/plugin/loader.rb +3 -3
  80. data/lib/samagotchi/plugin/peer.rb +175 -64
  81. data/lib/samagotchi/plugin/peers.rb +70 -0
  82. data/lib/samagotchi/run_options.rb +3 -1
  83. data/lib/samagotchi/schedule_command.rb +10 -3
  84. data/lib/samagotchi/schedule_display.rb +32 -0
  85. data/lib/samagotchi/session_access/contract.rb +19 -2
  86. data/lib/samagotchi/session_access/local.rb +132 -14
  87. data/lib/samagotchi/session_access/remote.rb +4 -2
  88. data/lib/samagotchi/session_access/remote_peers.rb +75 -0
  89. data/lib/samagotchi/session_continue.rb +12 -0
  90. data/lib/samagotchi/session_inbox_delivery.rb +5 -2
  91. data/lib/samagotchi/session_manager/delivery.rb +5 -3
  92. data/lib/samagotchi/session_manager/removal.rb +2 -0
  93. data/lib/samagotchi/session_manager/spawn.rb +2 -1
  94. data/lib/samagotchi/session_manager.rb +1 -0
  95. data/lib/samagotchi/session_stores.rb +17 -0
  96. data/lib/samagotchi/steer.rb +1 -1
  97. data/lib/samagotchi/system_prompt.rb +1 -1
  98. data/lib/samagotchi/terminal_ui/attached_loop.rb +1 -1
  99. data/lib/samagotchi/terminal_ui/formatting.rb +4 -1
  100. data/lib/samagotchi/testing/boundary.rb +4 -13
  101. data/lib/samagotchi/testing/bundle.rb +40 -5
  102. data/lib/samagotchi/testing/install.rb +4 -4
  103. data/lib/samagotchi/testing/recording_api.rb +2 -1
  104. data/lib/samagotchi/tools/context_read.rb +0 -14
  105. data/lib/samagotchi/tools/list_schedules.rb +8 -3
  106. data/lib/samagotchi/version.rb +1 -1
  107. data/lib/samagotchi/web/app.rb +7 -18
  108. data/lib/samagotchi/web/message_display.rb +4 -2
  109. data/lib/samagotchi/web/page_routes.rb +116 -0
  110. data/lib/samagotchi/web/peer_routes.rb +133 -0
  111. data/lib/samagotchi/web/public/app.js +35 -95
  112. data/lib/samagotchi/web/public/bubbles.js +2 -2
  113. data/lib/samagotchi/web/public/cards_place.js +20 -1
  114. data/lib/samagotchi/web/public/context_chips.js +45 -46
  115. data/lib/samagotchi/web/public/history_reveal.js +4 -1
  116. data/lib/samagotchi/web/public/history_shape.js +3 -2
  117. data/lib/samagotchi/web/public/index.html +16 -0
  118. data/lib/samagotchi/web/public/notify.js +1 -1
  119. data/lib/samagotchi/web/public/page_blocks.js +58 -0
  120. data/lib/samagotchi/web/public/page_links.js +33 -0
  121. data/lib/samagotchi/web/public/page_model.js +68 -0
  122. data/lib/samagotchi/web/public/page_route.js +24 -0
  123. data/lib/samagotchi/web/public/page_table.js +74 -0
  124. data/lib/samagotchi/web/public/page_table_model.js +76 -0
  125. data/lib/samagotchi/web/public/page_view.js +219 -0
  126. data/lib/samagotchi/web/public/pages.css +77 -0
  127. data/lib/samagotchi/web/public/pages_group.js +65 -0
  128. data/lib/samagotchi/web/public/peer_chip.js +60 -74
  129. data/lib/samagotchi/web/public/peer_data.js +13 -11
  130. data/lib/samagotchi/web/public/peer_links.js +12 -7
  131. data/lib/samagotchi/web/public/peer_mailbox_api.js +20 -0
  132. data/lib/samagotchi/web/public/peer_note.js +7 -3
  133. data/lib/samagotchi/web/public/peer_text.js +4 -4
  134. data/lib/samagotchi/web/public/quiet_notes.js +199 -0
  135. data/lib/samagotchi/web/public/revise_stack.js +4 -3
  136. data/lib/samagotchi/web/public/session_view.js +2 -2
  137. data/lib/samagotchi/web/public/stream_handlers.js +3 -2
  138. data/lib/samagotchi/web/public/turn_block.js +7 -3
  139. data/lib/samagotchi/web/public/turn_events.js +6 -0
  140. data/lib/samagotchi/web/public/views.js +161 -0
  141. data/lib/samagotchi/web/push/attention.rb +3 -2
  142. data/lib/samagotchi/web/session_access_routes.rb +3 -20
  143. data/lib/samagotchi/web/viewer.rb +1 -1
  144. data/lib/samagotchi/worker/leave.rb +3 -0
  145. data/lib/samagotchi/worker/mail.rb +73 -0
  146. data/lib/samagotchi/worker/startup.rb +3 -0
  147. data/lib/samagotchi/worker/wake_turns.rb +20 -5
  148. data/lib/samagotchi/worker.rb +12 -6
  149. data/lib/samagotchi/worker_inbound/mail.rb +214 -0
  150. data/lib/samagotchi/worker_inbound.rb +43 -46
  151. data/lib/samagotchi/worker_wakes.rb +26 -21
  152. metadata +39 -2
  153. data/lib/samagotchi/peer_sources.rb +0 -58
@@ -0,0 +1,76 @@
1
+ // A page's table as data (docs/pages.md): a cell's shown text, the sort and
2
+ // the phone's key columns. Pure: page_table.js draws them. The cells stay
3
+ // raw in the stored page (a number is a number), so the sort compares
4
+ // numbers as numbers; the words follow `chi page run`'s summary
5
+ // (PageCommand.cell): money $0.0000, count 1.2k / 3.4M, nil —.
6
+
7
+ export const BLANK = "—";
8
+
9
+ // 1.2k / 3.4M; under 1000 as it is (PageCommand.count).
10
+ export function countText(value) {
11
+ if (Math.abs(value) < 1000) return String(value);
12
+ const [n, unit] = Math.abs(value) < 1_000_000 ? [value / 1000, "k"] : [value / 1_000_000, "M"];
13
+ return `${n.toFixed(1).replace(/\.0$/, "")}${unit}`;
14
+ }
15
+
16
+ // A cell as the page shows it.
17
+ export function cellText(value, format) {
18
+ if (value === null || value === undefined) return BLANK;
19
+ if (typeof value !== "number") return String(value);
20
+ if (format === "money") return `$${value.toFixed(4)}`;
21
+ if (format === "count") return countText(value);
22
+ return String(value);
23
+ }
24
+
25
+ // Whether column +index+ holds numbers (a format, or every cell that isn't
26
+ // blank a number): right-aligned, sorted high first.
27
+ export function numericColumn(block, index) {
28
+ const column = block.columns[index] || {};
29
+ if (column.format) return true;
30
+ const cells = (block.rows || []).map((row) => row[index]).filter((v) => v !== null && v !== undefined);
31
+ return cells.length > 0 && cells.every((v) => typeof v === "number");
32
+ }
33
+
34
+ // The rows sorted by column +index+, +dir+ "asc" or "desc": numbers before
35
+ // text (numbers as numbers, text by locale), blanks last either way, rows
36
+ // that compare equal in their order (stable). The total is no row: it stays
37
+ // at the bottom. A null +index+ keeps the script's order.
38
+ export function sortRows(rows, index, dir = "asc") {
39
+ if (index === null || index === undefined) return rows.slice();
40
+ const sign = dir === "desc" ? -1 : 1;
41
+ const rank = (v) => {
42
+ if (v === null || v === undefined || v === "") return 2;
43
+ return typeof v === "number" ? 0 : 1;
44
+ };
45
+ return rows.map((row, at) => ({ row, at })).sort((a, b) => {
46
+ const x = a.row[index];
47
+ const y = b.row[index];
48
+ const rx = rank(x);
49
+ const ry = rank(y);
50
+ if (rx !== ry) return rx - ry;
51
+ let order = 0;
52
+ if (rx === 0) order = x - y;
53
+ else if (rx === 1) order = String(x).localeCompare(String(y));
54
+ return order === 0 ? a.at - b.at : sign * order;
55
+ }).map(({ row }) => row);
56
+ }
57
+
58
+ // The next sort after a click on column +index+: a new column starts high
59
+ // first for numbers and A to Z for text; the same column flips.
60
+ export function nextSort(sort, index, numeric) {
61
+ if (sort && sort.index === index) return { index, dir: sort.dir === "desc" ? "asc" : "desc" };
62
+ return { index, dir: numeric ? "desc" : "asc" };
63
+ }
64
+
65
+ // The columns a phone's row shows besides the first: those the script (or
66
+ // the builder's default) marked key_column; the rest open on a tap.
67
+ // @return {keys: [index], rest: [index]}
68
+ export function phoneColumns(block) {
69
+ const keys = [];
70
+ const rest = [];
71
+ (block.columns || []).forEach((column, i) => {
72
+ if (i === 0) return;
73
+ (column.key_column ? keys : rest).push(i);
74
+ });
75
+ return { keys, rest };
76
+ }
@@ -0,0 +1,219 @@
1
+ // The page view, #/p/NAME (docs/pages.md, docs/internals/pages.md): in
2
+ // place of the session area, a page's header (Back, the title, when it ran
3
+ // and how long it took, Refresh, ⋯ with Delete) and its blocks. Opening
4
+ // reads the stored page (GET /api/pages/NAME) and runs nothing; Refresh
5
+ // runs the script (POST …/run, answered when the run ended) and redraws
6
+ // from its answer. A failed run keeps the last result, dimmed, under the
7
+ // failure line; a script changed since the result says so. Nothing is
8
+ // live: a run from a terminal shows after the next open.
9
+ //
10
+ // Made only with the pages capability (app.js; the null-control rule).
11
+ // +root+: #pageView. +api+: data.js api. +toast(text)+, +copyText(text)+:
12
+ // the page's. +back()+: Back (views.js closePage). +gone()+: the page was
13
+ // removed (a Delete, or a Refresh answered "no such page"): views.js leaves
14
+ // for All sessions. +backLabel()+: what Back says ("Sessions" or "Back").
15
+ // +phone()+: the page's phone width now (the table's phone form). The view
16
+ // keeps each table's sort and opened rows (page_table.js) until another
17
+ // page opens.
18
+ import { html, nothing, render } from "./vendor/lit-html.js";
19
+ import { createLatest } from "./latest.js";
20
+ import { cantText } from "./format.js";
21
+ import { blocksTemplate, drawWalks } from "./page_blocks.js";
22
+ import { tableTemplate } from "./page_table.js";
23
+ import { nextSort } from "./page_table_model.js";
24
+ import { changedText, errorCopy, failureParts, keptAfterFailure, metaText } from "./page_model.js";
25
+
26
+ // Mirrors Pages::NAME (lib/samagotchi/pages.rb).
27
+ const PAGE_NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
28
+
29
+ export function createPageView({
30
+ root, api, toast = () => {}, copyText = async () => false, back = () => {}, gone = () => {},
31
+ backLabel = () => "Sessions", phone = () => false, doc = document, win = window, now = () => Date.now(),
32
+ }) {
33
+ // The page open now: {name, status: "loading" | "ready" | "missing" |
34
+ // "error", page, error, running, stderr, menu: "closed" | "open" |
35
+ // "confirm", deleting, sorts: {block index: {index, dir}}, opened: {block
36
+ // index: Set of rows}}; null while closed.
37
+ let view = null;
38
+ const runs = new Map();
39
+ const latest = createLatest(() => view?.name ?? null);
40
+ const path = (name) => `/api/pages/${encodeURIComponent(name)}`;
41
+
42
+ function draw() {
43
+ if (!view) {
44
+ render(nothing, root);
45
+ return;
46
+ }
47
+ render(template(view), root);
48
+ drawWalks(root, { doc, win });
49
+ }
50
+
51
+ function set(fields) {
52
+ view = { ...view, ...fields };
53
+ draw();
54
+ }
55
+
56
+ async function open(name) {
57
+ if (view?.name === name) return;
58
+ const run = runs.get(name);
59
+ const valid = PAGE_NAME.test(name);
60
+ view = { name, status: valid ? "loading" : "missing", page: null, error: null, running: !!run, stderr: "", menu: "closed", deleting: false,
61
+ sorts: {}, opened: {} };
62
+ draw();
63
+ if (!valid) return;
64
+ const fresh = latest.begin();
65
+ try {
66
+ const page = await api(path(name));
67
+ if (!fresh() || run?.answered) return;
68
+ set({ status: "ready", page });
69
+ } catch (error) {
70
+ if (!fresh()) return;
71
+ set(error.code === "page_missing" ? { status: "missing" } : { status: "error", error });
72
+ }
73
+ }
74
+
75
+ function close() {
76
+ latest.drop();
77
+ view = null;
78
+ draw();
79
+ }
80
+
81
+ async function refresh() {
82
+ if (!view || view.running || view.status !== "ready") return;
83
+ const name = view.name;
84
+ const run = { answered: false };
85
+ runs.set(name, run);
86
+ set({ running: true, menu: "closed" });
87
+ const still = () => view?.name === name;
88
+ try {
89
+ const page = await api(`${path(name)}/run`, { method: "POST" });
90
+ run.answered = true;
91
+ if (runs.get(name) === run) runs.delete(name);
92
+ if (!still()) return;
93
+ const sorts = Object.fromEntries(Object.entries(view.sorts).filter(([index]) => {
94
+ const before = view.page?.blocks?.[index]?.columns;
95
+ const after = page.blocks?.[index]?.columns;
96
+ return Array.isArray(before) && Array.isArray(after) && before.length === after.length;
97
+ }));
98
+ set({ status: "ready", running: false, page, stderr: page.stderr || "", sorts, opened: {} });
99
+ } catch (error) {
100
+ if (runs.get(name) === run) runs.delete(name);
101
+ if (!still()) return;
102
+ set({ running: false });
103
+ if (error.code === "page_missing") {
104
+ toast(error.message);
105
+ gone();
106
+ } else if (error.code === "page_busy" || error.code === "server_stopping") {
107
+ toast(error.message);
108
+ } else {
109
+ toast(cantText("refresh the page", error));
110
+ }
111
+ }
112
+ }
113
+
114
+ async function remove() {
115
+ if (!view || view.deleting) return;
116
+ const name = view.name;
117
+ const title = view.page?.title || name;
118
+ set({ deleting: true });
119
+ try {
120
+ await api(path(name), { method: "DELETE" });
121
+ if (view?.name !== name) return;
122
+ toast(`Deleted the page ${title}`);
123
+ gone();
124
+ } catch (error) {
125
+ if (view?.name !== name) return;
126
+ set({ deleting: false, menu: "closed" });
127
+ if (error.code === "page_missing") gone();
128
+ toast(error.code === "page_busy" ? error.message : cantText("delete the page", error));
129
+ }
130
+ }
131
+
132
+ async function copyError() {
133
+ const ok = await copyText(errorCopy(view.page, view.stderr));
134
+ toast(ok ? "Copied the error" : "Can't copy here");
135
+ }
136
+
137
+ function menuTemplate(v) {
138
+ if (v.menu === "closed") return nothing;
139
+ if (v.menu === "confirm") {
140
+ return html`<div class="pg-menu" role="menu">
141
+ <span class="pg-confirm">Delete this page?</span>
142
+ <button type="button" class="pg-delete danger" role="menuitem" ?disabled=${v.deleting} @click=${remove}>${v.deleting ? "Deleting…" : "Delete"}</button>
143
+ <button type="button" class="ghost" role="menuitem" @click=${() => set({ menu: "closed" })}>Cancel</button>
144
+ </div>`;
145
+ }
146
+ return html`<div class="pg-menu" role="menu">
147
+ <button type="button" class="pg-delete-ask" role="menuitem" @click=${() => set({ menu: "confirm" })}>Delete</button>
148
+ </div>`;
149
+ }
150
+
151
+ function headTemplate(v, page) {
152
+ const meta = page ? metaText(page, now()) : null;
153
+ const title = page?.title || v.name;
154
+ const ready = v.status === "ready";
155
+ return html`<div class="pg-head">
156
+ <button type="button" class="pg-back ghost" @click=${back}>← ${backLabel()}</button>
157
+ <h1 class="pg-title">${title}</h1>
158
+ ${meta ? html`<span class="pg-meta">${meta}</span>` : nothing}
159
+ ${ready ? html`<span class="pg-actions">
160
+ <button type="button" class="pg-refresh primary" ?disabled=${v.running} @click=${refresh}>${v.running ? "Running…" : "Refresh"}</button>
161
+ <span class="pg-more">
162
+ <button type="button" class="pg-menu-btn ghost" aria-label="More" title="More" aria-haspopup="menu"
163
+ aria-expanded=${v.menu === "closed" ? "false" : "true"}
164
+ @click=${() => set({ menu: v.menu === "closed" ? "open" : "closed" })}>⋯</button>
165
+ ${menuTemplate(v)}
166
+ </span>
167
+ </span>` : nothing}
168
+ </div>`;
169
+ }
170
+
171
+ function linesTemplate(page) {
172
+ const failed = failureParts(page);
173
+ const changed = changedText(page, now());
174
+ return html`${failed ? html`<div class="pg-line pg-failed" role="status">
175
+ ${failed.lead}<code>${failed.message}</code>.${failed.tail}
176
+ <button type="button" class="pg-copy ghost" @click=${copyError}>Copy the error</button>
177
+ </div>` : nothing}
178
+ ${changed ? html`<div class="pg-line pg-changed" role="status">${changed}</div>` : nothing}`;
179
+ }
180
+
181
+ function bodyTemplate(v) {
182
+ if (v.status === "loading") return html`<div class="pg-note">Loading…</div>`;
183
+ if (v.status === "missing") return html`<div class="pg-note">There is no page called ${v.name}.</div>`;
184
+ if (v.status === "error") return html`<div class="pg-note">${cantText("read the page", v.error)}</div>`;
185
+ const page = v.page;
186
+ const kept = keptAfterFailure(page);
187
+ const table = (block, index) => tableTemplate(block, {
188
+ phone: phone(),
189
+ sort: v.sorts[index] || null,
190
+ onSort: (column, numeric) => set({ sorts: { ...v.sorts, [index]: nextSort(v.sorts[index], column, numeric) } }),
191
+ opened: v.opened[index] || new Set(),
192
+ onToggle: (row) => {
193
+ const opened = new Set(view.opened[index] || []);
194
+ if (opened.has(row)) opened.delete(row);
195
+ else opened.add(row);
196
+ set({ opened: { ...view.opened, [index]: opened } });
197
+ },
198
+ });
199
+ const blocks = page.ran_at ? blocksTemplate(page.blocks, { table }) : nothing;
200
+ return html`${linesTemplate(page)}
201
+ ${page.ran_at ? html`<div class="pg-blocks ${kept ? "pg-kept" : ""}">${blocks}</div>`
202
+ : html`<div class="pg-note">No result yet${page.state === "failed" ? "" : ": Refresh runs the script"}.</div>`}`;
203
+ }
204
+
205
+ function template(v) {
206
+ return html`${headTemplate(v, v.status === "ready" ? v.page : null)}${bodyTemplate(v)}`;
207
+ }
208
+
209
+ // A click outside the open menu closes it (one inside it that redrew it
210
+ // has a target no longer in the page: not outside).
211
+ doc.addEventListener("click", (e) => {
212
+ if (!view || view.menu === "closed" || !e.target?.isConnected || e.target.closest?.(".pg-more")) return;
213
+ set({ menu: "closed" });
214
+ });
215
+ // The phone's table form follows the width.
216
+ win.matchMedia?.("(max-width: 600px)")?.addEventListener?.("change", () => view && draw());
217
+
218
+ return { open, close, refresh, name: () => view?.name ?? null };
219
+ }
@@ -0,0 +1,77 @@
1
+ /* A page, #/p/NAME (page_view.js): in place of the session area, the strip and All sessions while body.page-view.
2
+ The view scrolls down inside itself; it never scrolls sideways: a wide table or a walk's lanes scroll in their own box.
3
+ Colours are the :root tokens only (tokens.css). */
4
+ #pageView{display:none;flex:1;min-height:0;min-width:0;flex-direction:column;gap:12px;overflow-y:auto;overflow-x:hidden;padding:2px 2px 24px}
5
+ body.page-view #pageView{display:flex}
6
+ body.page-view :is(#center,#topStrip,#stripGrip,#allView,#sessionTitleRow){display:none}
7
+ .pg-head{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px}
8
+ .pg-back{flex:none;padding:5px 10px;font-size:13px;color:var(--accent);background:transparent;border:1px solid transparent}
9
+ @media(hover:hover){.pg-back:hover{filter:none;border-color:var(--border-strong)}}
10
+ .pg-title{flex:1 1 160px;min-width:0;margin:0;font-size:17px;font-weight:650;line-height:1.3;color:var(--text);overflow-wrap:anywhere}
11
+ .pg-meta{font-size:12px;color:var(--text-muted);white-space:nowrap}
12
+ .pg-actions{display:flex;align-items:center;gap:8px;flex:none}
13
+ .pg-actions button{padding:6px 12px;font-size:12px;font-weight:600;border-radius:8px}
14
+ .pg-refresh:disabled{opacity:.7;cursor:default}
15
+ .pg-menu-btn{border:1px solid var(--border-strong)}
16
+ .pg-more{position:relative}
17
+ .pg-menu{position:absolute;right:0;top:calc(100% + 6px);z-index:20;display:flex;align-items:center;gap:8px;padding:8px;white-space:nowrap;background:var(--bg-panel);border:1px solid var(--border-strong);border-radius:10px;box-shadow:var(--shadow-strong)}
18
+ .pg-menu .pg-delete-ask{background:transparent;color:var(--danger-text);border:1px solid transparent}
19
+ .pg-menu .pg-delete{background:var(--danger-bg-dim);color:var(--danger-text);border:1px solid var(--danger)}
20
+ .pg-confirm{font-size:12.5px;color:var(--text-2)}
21
+ .pg-line{border:1px solid var(--warn-border);background:var(--warn-bg);color:var(--warn-text);border-radius:8px;padding:8px 10px;font-size:12.5px;line-height:1.5;overflow-wrap:anywhere}
22
+ .pg-line code{font:12px ui-monospace,SFMono-Regular,Menlo,monospace}
23
+ .pg-line .pg-copy{margin-left:6px;padding:3px 9px;font-size:12px;border:1px solid var(--border-strong)}
24
+ .pg-blocks{display:flex;flex-direction:column;gap:12px;min-width:0}
25
+ .pg-kept{opacity:.62}
26
+ .pg-text{color:var(--text-2);font-size:13.5px;line-height:1.5;min-width:0;overflow-wrap:anywhere}
27
+ .pg-plain{white-space:pre-wrap}
28
+ .pg-text.markdown pre{overflow:auto;padding:10px;border-radius:8px;background:var(--bg-inset);border:1px solid var(--border)}
29
+ .pg-text.markdown :not(pre)>code{background:var(--bg-inset);border:1px solid var(--border);border-radius:4px;padding:1px 3px}
30
+ .pg-text.markdown a{color:var(--accent)}
31
+ .pg-walk{display:block;min-width:0;max-width:100%;overflow-x:auto}
32
+ .pg-note,.pg-unknown{font-size:12.5px;color:var(--text-muted)}
33
+ /* A table (page_table.js): desktop's real table in a box of its own that scrolls sideways; the phone's rows that open. */
34
+ .pg-table{display:flex;flex-direction:column;gap:6px;min-width:0}
35
+ .pg-scroll{overflow-x:auto;border:1px solid var(--border);border-radius:10px;background:var(--bg-panel)}
36
+ .pg-scroll table{border-collapse:collapse;width:100%;font-size:12.5px;font-variant-numeric:tabular-nums}
37
+ .pg-scroll th,.pg-scroll td{padding:7px 10px;text-align:left;white-space:nowrap;border-bottom:1px solid var(--border)}
38
+ .pg-scroll :is(th,td).pg-num{text-align:right}
39
+ .pg-scroll th{font-weight:600;color:var(--text-muted);background:var(--bg-inset);padding:0}
40
+ .pg-scroll th[aria-sort]{color:var(--accent)}
41
+ .pg-sort{all:unset;box-sizing:border-box;display:block;width:100%;padding:7px 10px;cursor:pointer;text-align:inherit;font:inherit;color:inherit}
42
+ .pg-sort:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
43
+ @media(hover:hover){.pg-sort:hover{color:var(--text-2)}}
44
+ .pg-scroll tfoot td{font-weight:650;border-bottom:0;border-top:1px solid var(--border-strong);color:var(--text)}
45
+ .pg-scroll tbody tr:last-child td{border-bottom:0}
46
+ .pg-blank{color:var(--text-faint)}
47
+ .pg-rows{border:1px solid var(--border);border-radius:10px;background:var(--bg-panel);font-variant-numeric:tabular-nums}
48
+ .pg-row{border-bottom:1px solid var(--border)}
49
+ .pg-row:last-child{border-bottom:0}
50
+ .pg-row.open{background:var(--bg-hover)}
51
+ .pg-row-main{all:unset;box-sizing:border-box;display:grid;grid-template-columns:minmax(0,1fr) repeat(var(--pg-keys,0),auto);gap:4px 14px;align-items:baseline;width:100%;padding:9px 12px;font-size:13px;color:var(--text)}
52
+ button.pg-row-main{cursor:pointer}
53
+ button.pg-row-main:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
54
+ .pg-k{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
55
+ .pg-kv{text-align:right;white-space:nowrap}
56
+ .pg-lab{display:block;font-size:10.5px;color:var(--text-faint)}
57
+ .pg-total .pg-row-main{font-weight:650}
58
+ .pg-cells{display:grid;grid-template-columns:1fr 1fr;gap:2px 16px;padding:0 12px 9px;font-size:12px;color:var(--text-2)}
59
+ .pg-cells span{display:flex;justify-content:space-between;gap:8px;min-width:0}
60
+ .pg-cells em{font-style:normal;color:var(--text-muted)}
61
+ @media(max-width:600px){
62
+ .pg-head{gap:6px 8px}
63
+ .pg-title{flex:1 1 0}
64
+ /* The meta wraps under the title, on a line of its own. */
65
+ .pg-meta{order:5;flex-basis:100%;white-space:normal}
66
+ }
67
+ /* All sessions' Pages group (pages_group.js): one row of cards that scrolls sideways, over a "Sessions" heading. Its own
68
+ card rules: the session cards' are scoped to #allList .card. */
69
+ #pagesGroup{display:flex;flex-direction:column;gap:8px;flex:none;min-width:0}
70
+ #pagesGroup[hidden]{display:none}
71
+ .pg-group-label{font-size:11px;font-weight:600;line-height:1;letter-spacing:.06em;text-transform:uppercase;color:var(--text-faint)}
72
+ .pg-cards{display:flex;gap:8px;overflow-x:auto;padding-bottom:2px;scrollbar-width:thin}
73
+ .pg-card{all:unset;box-sizing:border-box;flex:0 0 190px;display:flex;flex-direction:column;gap:2px;min-width:0;padding:9px 11px;border:1px solid var(--accent-border);border-radius:10px;background:var(--bg-panel);font-size:12.5px;color:var(--text-muted);cursor:pointer}
74
+ .pg-card b{display:block;font-size:13px;color:var(--text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
75
+ .pg-card:focus-visible{outline:2px solid var(--accent);outline-offset:1px}
76
+ @media(hover:hover){.pg-card:hover{border-color:var(--accent);background:var(--bg-hover)}}
77
+ @media(max-width:600px){.pg-card{flex-basis:160px}}
@@ -0,0 +1,65 @@
1
+ // All sessions' Pages group (decision D1 A, docs/pages.md): above the
2
+ // session cards, one row of page cards that scrolls sideways (it never takes
3
+ // more than a row of a phone's first screen), each with its title and "ran 2
4
+ // min ago", "failed 1 h ago" or "never ran"; a tap opens the page. A
5
+ // "Sessions" heading sits over the session cards while the group shows. It
6
+ // is read when All sessions opens (GET /api/pages) and filtered by the
7
+ // search field (#filter) by name and title; with no page, or none the search
8
+ // matches, the group and its heading are not there. Not live: a page made
9
+ // meanwhile shows the next time All sessions opens.
10
+ //
11
+ // Made only with the pages capability (app.js). +root+: #pagesGroup.
12
+ // +filterEl+: #filter. +api+: data.js api. +open(name)+: views.js openPage.
13
+ import { html, nothing, render } from "./vendor/lit-html.js";
14
+ import { createLatest } from "./latest.js";
15
+ import { relativeTime } from "./format.js";
16
+
17
+ // A card's second line.
18
+ export function pageCardMeta(page, now = Date.now()) {
19
+ if (page.state === "failed" && page.failed_at) return `failed ${relativeTime(page.failed_at, now)}`;
20
+ if (page.ran_at) return `ran ${relativeTime(page.ran_at, now)}`;
21
+ return "never ran";
22
+ }
23
+
24
+ // The pages the search shows: +query+ in the name or the title, any case.
25
+ export function filterPages(pages, query = "") {
26
+ const q = query.trim().toLowerCase();
27
+ if (!q) return pages;
28
+ return pages.filter((page) => page.name.toLowerCase().includes(q) || String(page.title || "").toLowerCase().includes(q));
29
+ }
30
+
31
+ export function pagesGroupTemplate(pages, { open, now = Date.now() }) {
32
+ if (!pages.length) return nothing;
33
+ return html`<div class="pg-group-label">Pages</div>
34
+ <div class="pg-cards" role="list">${pages.map((page) => html`<button type="button" class="pg-card" role="listitem"
35
+ data-page=${page.name} @click=${() => open(page.name)}><b>${page.title || page.name}</b><span class="pg-card-meta">${pageCardMeta(page, now)}</span></button>`)}</div>
36
+ <div class="pg-group-label">Sessions</div>`;
37
+ }
38
+
39
+ export function createPagesGroup({ root, filterEl, api, open, now = () => Date.now() }) {
40
+ let pages = [];
41
+ const latest = createLatest();
42
+
43
+ function draw() {
44
+ const shown = filterPages(pages, filterEl?.value || "");
45
+ root.hidden = !shown.length;
46
+ render(pagesGroupTemplate(shown, { open, now: now() }), root);
47
+ }
48
+
49
+ async function load() {
50
+ const fresh = latest.begin();
51
+ try {
52
+ const answer = await api("/api/pages");
53
+ if (!fresh()) return;
54
+ pages = Array.isArray(answer?.pages) ? answer.pages : [];
55
+ } catch (_) {
56
+ if (!fresh()) return;
57
+ pages = []; // the group is a way in, not a place for errors: the page itself says them
58
+ }
59
+ draw();
60
+ }
61
+
62
+ filterEl?.addEventListener("input", draw);
63
+ draw();
64
+ return { load, redraw: draw };
65
+ }