pi-durable-bot 0.8.5 → 0.8.6

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.
package/kit/pots.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /*
2
- * Pots page kit: sends the answers of a page's forms to Pots, shows data from JSON files as text, and reloads a page
3
- * that opts in when it changes. No build step, no dependencies, and nothing kept in the browser: every page of a Pots
4
- * host shares one browser origin, so storage would be shared with every other page.
2
+ * Pots page kit: sends the answers of a page's forms to Pots, shows data from JSON files as text, reloads a page
3
+ * that opts in when it changes, and gives the page a light / dark switch. No build step, no dependencies, and nothing
4
+ * kept in the browser but the reader's light or dark choice: every page of a Pots host shares one browser origin, so
5
+ * storage would be shared with every other page.
5
6
  *
6
7
  * <link rel="stylesheet" href="../../__pots/kit/pots.css">
7
8
  * <script src="../../__pots/kit/pots.js" defer></script>
@@ -607,7 +608,64 @@
607
608
  document.addEventListener("visibilitychange", tick);
608
609
  }
609
610
 
611
+ // Light or dark: the reader's choice, from a switch at the page's top corner. It is kept in the browser for every
612
+ // page of this host, as it is not private; a choice that is the system's own is forgotten, so the page follows the
613
+ // system again. pots-ui.js has the same switch; the first of the two makes it.
614
+ function themeSwitch() {
615
+ if (root.PotsTheme) return;
616
+ var html = document.documentElement, KEY = "pots-theme", button = null;
617
+ var system = window.matchMedia ? matchMedia("(prefers-color-scheme: dark)") : { matches: false };
618
+ var read = function () {
619
+ try {
620
+ var v = localStorage.getItem(KEY);
621
+ return v === "light" || v === "dark" ? v : null;
622
+ } catch (e) {
623
+ return null;
624
+ }
625
+ };
626
+ var shown = function () { return read() || (system.matches ? "dark" : "light"); };
627
+ var apply = function () {
628
+ var v = read();
629
+ if (v) html.setAttribute("data-pots-theme", v);
630
+ else html.removeAttribute("data-pots-theme");
631
+ if (!button) return;
632
+ var dark = shown() === "dark";
633
+ button.setAttribute("data-icon", dark ? "sun" : "moon");
634
+ button.setAttribute("aria-pressed", String(dark));
635
+ };
636
+ var set = function (v) {
637
+ try {
638
+ if (v === (system.matches ? "dark" : "light")) localStorage.removeItem(KEY);
639
+ else localStorage.setItem(KEY, v);
640
+ } catch (e) {}
641
+ apply();
642
+ };
643
+ apply();
644
+ root.PotsTheme = {
645
+ get: shown,
646
+ set: set,
647
+ // The button, once the body is there, and only on a page that uses pots.css.
648
+ button: function () {
649
+ if (button || !document.body || !getComputedStyle(html).getPropertyValue("--pots-bg")) return;
650
+ var zh = /^zh/i.test(html.lang || "");
651
+ button = document.createElement("button");
652
+ button.className = "pots-theme";
653
+ button.type = "button";
654
+ button.setAttribute("aria-label", zh ? "深色模式" : "Dark mode");
655
+ button.title = zh ? "切换浅色或深色" : "Switch light or dark";
656
+ button.addEventListener("click", function () { set(shown() === "dark" ? "light" : "dark"); });
657
+ document.body.insertBefore(button, document.body.firstChild);
658
+ apply();
659
+ },
660
+ };
661
+ if (system.addEventListener) system.addEventListener("change", apply);
662
+ window.addEventListener("storage", function (event) { if (event.key === KEY) apply(); });
663
+ }
664
+
610
665
  function start() {
666
+ try {
667
+ root.PotsTheme.button();
668
+ } catch (e) {}
611
669
  document.addEventListener("submit", onSubmit);
612
670
  document.addEventListener("input", function (event) {
613
671
  if (event.target && event.target.closest && event.target.closest("form")) dirty = true;
@@ -620,6 +678,10 @@
620
678
  if (refresh !== null) watch(Number(refresh) || 5);
621
679
  }
622
680
 
681
+ // At once, before the page is shown when the script is not deferred, so the reader's choice does not flash.
682
+ try {
683
+ themeSwitch();
684
+ } catch (e) {}
623
685
  // The version of the page on screen, for answers sent later: now, not when the document is ready, which can be later.
624
686
  loadVersion();
625
687
  if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-durable-bot",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "Open-source AI coworkers that read every channel, decide what matters, and act on their own computer. Self-hosted, any model.",
5
5
  "license": "MIT AND MPL-2.0",
6
6
  "type": "module",
@@ -27,7 +27,7 @@ Never ask for a secret in a chat message, and never write your own page for one.
27
27
 
28
28
  | Kind | Example | Who writes it |
29
29
  |---|---|---|
30
- | Display page | A report, a plan, tables, charts. Only to read | You, freely. The kit's style saves time |
30
+ | Display page | A report, a plan, tables, charts, a calculator. To read and explore | You, freely, in the best form for each piece of information. The kit saves time |
31
31
  | Answer page | Feedback, choices, text, a comment on a section, approve or reject | You, with the kit's components, or fully your own. Change the style and layout as you like: the components are a start, not a limit |
32
32
  | Password page | A token for an app | Pots. You choose only the text on it, the keys and the file |
33
33
 
@@ -54,9 +54,194 @@ pots page list # your pages, their links, whe
54
54
  - Turn link previews off when you post a link (the channel skills say how). A platform's preview opens the link from its own servers.
55
55
  - With a Quick Tunnel, the address changes each time the gateway starts, so links sent before stop working; `pots page link` again gives a new link to the same page.
56
56
 
57
- ## Write a page quickly with the kit
57
+ ## The kit
58
58
 
59
- Pots serves a kit for pages: `pots.css`, a clean look for phones and computers, light and dark, and `pots.js`, which sends a form's answers to Pots. Link them relative to the page's link, not its folder on disk: from a page's `index.html`, also in `keep/`, use `../../__pots/kit/`, and add one `../` for each subfolder of the page. A complete answer page:
59
+ Pots serves a kit for pages, all optional:
60
+
61
+ - `pots.css`: a calm look for reading, light and dark, with Inter for Latin text (in `fonts/`). One column on a phone; on a computer, the contents at the side and blocks that use the width.
62
+ - `pots-ui.js`: charts from tables, tabs, sorting, filtering, contents that follow the reader, and a light and dark switch. Offline, and it works under the private-page CSP (see Content-Security-Policy).
63
+ - `pots.js`: sends a form's answers to Pots, and gives the same light and dark switch.
64
+
65
+ Link them relative to the page's link, not its folder on disk: from a page's `index.html`, also in `keep/`, use `../../__pots/kit/`, and add one `../` for each subfolder of the page. The source is in [../../kit/](../../kit/pots.css).
66
+
67
+ ## Display pages
68
+
69
+ **The goal.** A display page exists to get information across better than plain text in a chat can. That is its only job. For each piece of information, ask what lets the reader take it in fastest. When a better form fits the information, use it: a chart for amounts, a timeline for dates, two options side by side, a table to sort and search, a calculator for "what if". When a sentence says it faster, write the sentence. Never put in a chart, a card or a widget for show: a special form that does not help the reader is noise. A page of clear text with one good chart is better than a page full of components.
70
+
71
+ All that follows serves this goal: plain words make the text fast to read, the right form makes the shape of the information visible, and the layout puts more of it in view at once.
72
+
73
+ **The text.** Always write in ASD-STE100 Simplified Technical <the reader's language>, and use the reader's ubiquitous language. Put the answer first.
74
+
75
+ **The form.** A guide, not a rule. Use a row only when the information has that shape:
76
+
77
+ | Information | A good form | With the kit |
78
+ |---|---|---|
79
+ | The answer, the conclusion | One sentence under the title, and key numbers if they help | `<header>`, `pots-stats` |
80
+ | How much each of a few things is | A sorted bar chart, with a line for the limit or the target | `<table data-pots-chart="bar" data-marks="10000 Budget">` |
81
+ | Parts of a whole | One bar in parts, with percentages | `data-pots-chart="stack"` |
82
+ | Change over time | A line chart | `data-pots-chart="line"` |
83
+ | Many records to look up | A table; past a dozen rows, sorting and a search box | `data-pots-sort`, `data-pots-filter` |
84
+ | Many items × many properties, on a phone | One property at a time, or one card per row | `data-pots-tabs`, `table.pots-stack` |
85
+ | A plan by day or week | A calendar: side by side on a computer, one day at a time on a phone | `pots-grid` or `pots-cols` with `data-pots-tabs="phone"` |
86
+ | Steps in order | Numbered steps; a timeline for things at the same time | `ol.pots-steps`, `ul.pots-steps` |
87
+ | A list to work through | A checklist that counts what is left | Your own script |
88
+ | "What if…" | A slider or a field, and the result changes at once | Your own script |
89
+ | A structure, a flow, how something works | An inline SVG drawing, with words on the arrows | Your own SVG |
90
+ | A choice between options | Side by side, the differences marked, then an answer form | `pots-cols`, an answer form |
91
+ | Details that only some readers need | Folded away | `<details>` |
92
+
93
+ **The layout.** Use the device. On a computer, put text next to its chart, cards in columns and calendars side by side; on a phone, one column. Text keeps a comfortable line length; `pots-wide` lets a block, also a table or a bar chart, use the full width. The page itself never scrolls sideways; a wide table scrolls inside itself.
94
+
95
+ **The look.** A page is an information page that the reader reads and answers, not a landing page. The kit draws it clean and calm: near-black text on a plain background, hairlines instead of boxes, and one accent colour for what the reader acts on or looks for: links, numbers, the chosen and the recommended choice, focus.
96
+
97
+ - **Icons.** `data-icon="name"` puts a small line icon before an element's text; notes and questions get theirs from the kit. The names: check, x, info, warn, question, ban, arrow, up, down, clock, calendar, user, users, bot, chat, mail, link, lock, key, shield, eye, search, chart, file, code, terminal, settings, money, place, globe, star, bolt, flag, bell, list.
98
+ - **Colour.** Choose an accent for each page that fits its content, with one line in its CSS: `:root { --pots-accent: light-dark(#305a88, #8bb0db); }` (the light and the dark colour; this one is a muted slate blue). The kit's muted teal is only the fallback for a page that sets none. Choose a muted, darker, low-saturation colour; bright, common colours (bright blue, purple, violet) look cheap. `pots-good`, `pots-warn` and `pots-bad` mark a status.
99
+
100
+ In your own CSS, use the kit's parts so yours match: `--pots-line`, `--pots-soft` (a quiet surface), `--pots-accent-soft` (a light accent tint), `--pots-radius`.
101
+
102
+ ### What the kit gives
103
+
104
+ - Plain HTML already looks right: headings, lists, tables, code, quotes, images, `<details>`.
105
+ - Layout: `pots-cols` (side by side on a computer, one under the other on a phone), `pots-grid` (cards in as many columns as fit), `pots-row` (boxes that wrap), `pots-wide`. `<nav class="pots-toc">` after the header: links to the sections, at the side on a computer and a row at the top on a phone.
106
+ - The opening: `<header>` first in `<main>`, with `pots-eyebrow`, `<h1>`, one sentence, and `pots-meta` (the facts about the page in one line, a `<span>` for each).
107
+ - Blocks:
108
+ - `pots-stats` with `pots-stat` (`<div class="pots-stat"><b>€8,400</b><span>total</span></div>`); a change in a stat: `<small class="pots-delta pots-good" data-icon="up">12% on May</small>`.
109
+ - `pots-points`, key points: `ul.pots-points` with dots, `ol.pots-points` with numbers.
110
+ - `pots-card`, in `pots-grid` or `pots-cols`: a hairline over it, and its first `<h3>` is its title.
111
+ - `pots-note`: a `<b>` at its start is its title.
112
+ - `pots-steps`: `ol.pots-steps` with numbers, `ul.pots-steps` with dots (a timeline); a `<time>` first in an item shows a date over it.
113
+ - `pots-flow`: `pots-node` boxes joined by arrows; a fork goes in `pots-lanes`, one `pots-lane` for each way.
114
+ - `dl.pots-terms`: each `<div><dt>…</dt><dd>…</dd></div>` is a term and its meaning.
115
+ - `blockquote.pots-quote`, with a `<footer>` for who said it.
116
+ - `pots-kv` (a `<dl>` of names and values), `pots-badge`, `pots-no` (a section number in a heading: `<h2><span class="pots-no">2</span>Costs</h2>`).
117
+ - Icons: `data-icon="name"` on any element; `<i data-icon="name"></i>` is the icon alone. They are CSS masks from `data:` URLs, so a page's CSP must allow `img-src data:`, as the one under Content-Security-Policy does. In your own CSS, `var(--pots-i-lock)` is the lock as a mask image.
118
+ - Colours with a meaning: `pots-good`, `pots-warn`, `pots-bad` on a note, a card, a badge, a stat, a chart row or a `<span>` in `pots-meta`; `pots-info` on a badge, and on a card to mark the one you recommend (a fine accent border and tint). Text: `pots-muted`, `pots-num` (a right-aligned number cell). `pots-hl` highlights anything your script points at.
119
+ - Light and dark: the page follows the system, and a small switch at its top corner (from `pots-ui.js` or `pots.js`) lets the reader choose; the choice is kept for all pages. A colour of your own must follow it: write `light-dark(<light>, <dark>)`, never `@media (prefers-color-scheme: dark)`, which does not follow the switch.
120
+ - In your own CSS, use the kit's colours so dark mode works: `--pots-bg`, `--pots-soft`, `--pots-text`, `--pots-muted`, `--pots-faint`, `--pots-line`, `--pots-accent`, `--pots-accent-soft`, `--pots-accent-line`, `--pots-good`, `--pots-warn`, `--pots-bad` (each also `-soft`), and the chart colours `--pots-c1` (the accent) to `--pots-c7`; and its shapes: `--pots-radius-s`, `--pots-radius`, `--pots-radius-l`.
121
+ - With `pots-ui.js`:
122
+ - `<table data-pots-chart="bar|stack|line">` becomes a chart. Bar and stack: the first column names the rows, the second gives the values. Line: each row is a point on the x axis, each number column a line. `data-marks="380 You; 300 Her"` draws reference lines on bars, `data-max` or `data-min` fixes the scale (a line chart starts at zero unless its values sit far from zero; `data-min="0"` keeps zero), a `<caption>` becomes the title, and `data-pots-show="…"` names the button that shows the numbers. The table stays on the page, folded, so the numbers are one tap away.
123
+ - `<div data-pots-tabs>` with `<section data-tab="Name">` children shows one at a time; `data-pots-tabs="phone"` does so only on a phone and shows all of them on a computer. `data-current` on a section opens it first; `box.potsSelect(i)` opens one from your script, and the box sends a `pots-tab` event.
124
+ - Every table goes in a `<div class="pots-scroll">`, so it can take the full width and a wide one scrolls inside it.
125
+ - Numbers in charts and sorting: a cell is read as a number only when all of it is one, written as in the page's `lang` (`€1,234.50` in English, `1.234,50 €` in German, `−3`), with at most a short unit. Give a cell `data-value="1234.5"` when its text is not a plain number, such as "about two weeks" or "high"; that value is used first. Other columns sort as text.
126
+ - `<table data-pots-sort>`: a click on a column header sorts it. `<input type="search" data-pots-filter="#list">` hides the rows of that table, or its `[data-pots-item]` elements, that do not contain the text, and sends a `pots-filter` event.
127
+
128
+ ### Your own components
129
+
130
+ When a form in the table above has no kit part, write it: a calendar, a checklist, a calculator, a diagram. Do it when it lets the reader see or try something that text cannot show; else write the sentence.
131
+
132
+ - Write the full content in the HTML first, so the page reads well without your script, for example in a phone's reader mode or when the script fails. The script adds the interaction.
133
+ - Put the script in a file of the page, such as `cost.js`, loaded with `defer`. Then the page works under the private-page CSP.
134
+ - A library (maps, formulas, diagrams, a chart library) loads under the private-page CSP only from the page itself: download it into the page's folder and load it from there.
135
+ - Set text with `textContent`, never `innerHTML`, and keep nothing in `localStorage` (see One browser origin).
136
+ - Use the kit's colour variables, and test it with the mouse, a finger and the keyboard.
137
+
138
+ ### An example
139
+
140
+ A page that compares three cities for a team trip, in `pages/offsite/`:
141
+
142
+ ```html
143
+ <!doctype html>
144
+ <html lang="en">
145
+ <head>
146
+ <meta charset="utf-8">
147
+ <meta name="viewport" content="width=device-width, initial-scale=1">
148
+ <meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; base-uri 'none'; form-action 'self'">
149
+ <title>Team offsite: where and what it costs</title>
150
+ <link rel="stylesheet" href="../../__pots/kit/pots.css">
151
+ <script src="../../__pots/kit/pots-ui.js" defer></script>
152
+ <script src="cost.js" defer></script>
153
+ </head>
154
+ <body>
155
+ <main>
156
+ <header>
157
+ <p class="pots-eyebrow" data-icon="place">Team offsite · Proposal</p>
158
+ <h1>Team offsite: where and what it costs</h1>
159
+ <p>Lisbon is the best choice. It costs €8,400 for 12 people, €1,600 under the budget.</p>
160
+ <p class="pots-meta"><span data-icon="calendar">Prices from 16 November</span><span data-icon="users">For the team leads</span><span class="pots-warn" data-icon="warn">Flight prices change each day</span></p>
161
+ <div class="pots-stats">
162
+ <div class="pots-stat" data-icon="money"><b>€8,400</b><span>total</span><small class="pots-delta pots-good" data-icon="down">€900 on 2025</small></div>
163
+ <div class="pots-stat pots-good" data-icon="check"><b>€1,600</b><span>under the budget</span></div>
164
+ <div class="pots-stat" data-icon="users"><b>12</b><span>people</span></div>
165
+ </div>
166
+ </header>
167
+ <nav class="pots-toc"><a href="#cities">Cities</a> <a href="#days">The three days</a> <a href="#size">Group size</a></nav>
168
+
169
+ <h2 id="cities" data-icon="place">Three cities compared</h2>
170
+ <div class="pots-cols pots-wide">
171
+ <table data-pots-chart="bar" data-marks="10000 Budget">
172
+ <caption>Total cost for 12 people</caption>
173
+ <thead><tr><th>City</th><th class="pots-num">Cost</th></tr></thead>
174
+ <tbody>
175
+ <tr><td>Lisbon</td><td class="pots-num">€8,400</td></tr>
176
+ <tr><td>Porto</td><td class="pots-num">€7,900</td></tr>
177
+ <tr class="pots-bad"><td>Berlin</td><td class="pots-num">€11,200</td></tr>
178
+ </tbody>
179
+ </table>
180
+ <ul class="pots-points">
181
+ <li><b>Lisbon:</b> direct flights from all three offices.</li>
182
+ <li><b>Porto</b> costs less. But two of our offices have no direct flights to Porto.</li>
183
+ <li><b>Berlin</b> is over the budget. Hotels in Berlin cost more in March.</li>
184
+ </ul>
185
+ </div>
186
+
187
+ <h2 id="days" data-icon="calendar">The three days</h2>
188
+ <div class="pots-grid pots-wide" data-pots-tabs="phone">
189
+ <section class="pots-card" data-tab="Thursday"><h3 data-icon="calendar">Thursday</h3>
190
+ <ul class="pots-steps"><li><time>by 14:00</time>Flights arrive</li><li><time>19:30</time>Dinner together</li></ul></section>
191
+ <section class="pots-card pots-info" data-tab="Friday"><h3 data-icon="star">Friday</h3>
192
+ <ul class="pots-steps"><li><time>9:00–12:30</time>Planning for next year</li><li><time>afternoon</time>Free</li></ul></section>
193
+ <section class="pots-card" data-tab="Saturday"><h3 data-icon="calendar">Saturday</h3>
194
+ <ul class="pots-steps"><li><time>by 11:00</time>Check out</li><li><time>from 13:00</time>Flights leave</li></ul></section>
195
+ </div>
196
+ <p class="pots-note pots-warn"><b>Book by 30 November</b> The hotel holds the 12 rooms until then.</p>
197
+
198
+ <h2 id="size" data-icon="users">If more people come</h2>
199
+ <p id="cost-text">Each extra person adds about €700. With 14 people, the total is €9,800. This is still under the budget.</p>
200
+ <div id="cost" hidden>
201
+ <label>People <input type="range" id="people" min="8" max="16" value="12"></label>
202
+ <p class="pots-note" id="cost-result" aria-live="polite"></p>
203
+ </div>
204
+ </main>
205
+ </body>
206
+ </html>
207
+ ```
208
+
209
+ `cost.js`, a small calculator. Without it, the sentence above it says the same:
210
+
211
+ ```js
212
+ const people = document.getElementById("people");
213
+ const result = document.getElementById("cost-result");
214
+ function show() {
215
+ const total = 8400 + (people.value - 12) * 700;
216
+ const left = 10000 - total;
217
+ result.textContent = `${people.value} people: €${total.toLocaleString("en")}. ` +
218
+ (left >= 0 ? `€${left.toLocaleString("en")} under the budget.` : `€${(-left).toLocaleString("en")} over the budget.`);
219
+ result.classList.toggle("pots-warn", left < 0);
220
+ }
221
+ people.addEventListener("input", show);
222
+ show();
223
+ document.getElementById("cost-text").hidden = true;
224
+ document.getElementById("cost").hidden = false;
225
+ ```
226
+
227
+ ### Look at it before you send it
228
+
229
+ Take screenshots of the page as a phone, as a computer and in dark mode, and look at them. Check that nothing overflows or overlaps, the page does not scroll sideways, the charts and your components drew, and the text is easy to read. Fix what is wrong, then send the link.
230
+
231
+ A headless browser needs no screen, so use `bash`. Open the page through Pots on this computer, at `http://127.0.0.1:<pagePort>` (`pagePort` in `~/.pots/settings.json`) plus the path of its link (`/p/<token>/`), so the kit loads. [shot.mjs](shot.mjs), next to this file, takes a shot with Chrome or Chromium (`google-chrome`, `chromium`; install one if neither is there, or name it in `$CHROME`), in a new temporary profile each time:
232
+
233
+ ```sh
234
+ url="http://127.0.0.1:<pagePort>/p/<token>/"
235
+ node <this skill's folder>/shot.mjs "$url" 390 /tmp/page-phone.png
236
+ node <this skill's folder>/shot.mjs "$url" 1440 /tmp/page-computer.png
237
+ node <this skill's folder>/shot.mjs "$url" 390 /tmp/page-dark.png dark
238
+ ```
239
+
240
+ It sets the page's width as a phone does (`--window-size` can not make a window narrower than about 500 pixels, so it would crop a wider layout), takes the whole page, and prints what it measured: `innerWidth`, `scrollsSideways`, and the script errors. It fails when `innerWidth` is not the width you asked for, for example when the page has no viewport tag. A page taller than 16000 pixels goes in several files that join up, `/tmp/page-phone.png`, `/tmp/page-phone-2.png` and so on, and the output names them all in `files`. Then read every image. If the page is long, look at it in parts.
241
+
242
+ ## Answer pages
243
+
244
+ The kit's components make an answer page quickly. A complete one:
60
245
 
61
246
  ```html
62
247
  <!doctype html>
@@ -70,8 +255,12 @@ Pots serves a kit for pages: `pots.css`, a clean look for phones and computers,
70
255
  </head>
71
256
  <body>
72
257
  <main>
73
- <h1>Deploy plan 4.2</h1>
74
- <p class="pots-muted">Please answer by Friday.</p>
258
+ <header>
259
+ <p class="pots-eyebrow">Needs your answer</p>
260
+ <h1>Deploy plan 4.2</h1>
261
+ <p>Five questions. I start the deploy when I have your answers.</p>
262
+ <p class="pots-meta"><span class="pots-warn">Answer by Friday</span><span>About 2 minutes</span></p>
263
+ </header>
75
264
  <form data-pots data-pots-done="Thanks, I have your answers.">
76
265
  <fieldset data-pots-question="target">
77
266
  <legend>Where should I deploy first?</legend>
@@ -135,7 +324,7 @@ How pots.js sends: it takes the page's version that Pots sent with the HTML file
135
324
 
136
325
  ### Other classes and attributes
137
326
 
138
- - Plain HTML already looks right: headings, lists, tables (they scroll sideways on a phone), code, quotes, images. Classes: `pots-card` (a box), `pots-note` (a highlighted note; with `pots-warn`, a warning), `pots-row` (boxes side by side that wrap on a phone), `pots-badge` (with `pots-good` or `pots-bad`), `pots-muted`, `pots-num` (a right-aligned table cell for numbers), `pots-secondary` (a quieter button).
327
+ - Everything in "What the kit gives" works on an answer page too. A choice can have an explanation on a line of its own: `<label><input type="radio" name="target" value="test"> Test <small>Nobody outside the team sees it</small></label>`. `pots-secondary` is a quieter button.
139
328
  - `<body data-pots-refresh="5">`: every 5 seconds the page asks Pots whether any of its files changed, and reloads when one did; when the person has started to fill a form, it shows "This page has changed" with a Reload button instead. Use it for progress pages. A Quick Tunnel cannot push to the browser (no Server-Sent Events), so pages poll.
140
329
  - Text that other people wrote (comments, names, messages) must never become HTML: someone's `<script>` would run on the page. Write it into a JSON file next to the page and let the kit show it as text:
141
330
  ```html
@@ -145,7 +334,7 @@ How pots.js sends: it takes the page's version that Pots sent with the HTML file
145
334
  </div>
146
335
  ```
147
336
  With `comments.json` = `{"updated": "10:02", "items": [{"who": "Alice", "text": "Looks good"}]}`, the first child of a `data-pots-list` repeats for each item. pots.js sets only `textContent`, never `innerHTML`. If you write such text into HTML yourself, escape `&`, `<`, `>` and `"`.
148
- - `window.PotsKit.submit(answers)` sends answers your own script built, with the same version, submission ID and retries; it resolves `{ok: true}` or `{ok: false, status, message}`. `PotsKit.collect(form)` gives a kit form's answers without sending them. The kit's source is [../../kit/pots.js](../../kit/pots.js) and [../../kit/pots.css](../../kit/pots.css).
337
+ - `window.PotsKit.submit(answers)` sends answers your own script built, with the same version, submission ID and retries; it resolves `{ok: true}` or `{ok: false, status, message}`. `PotsKit.collect(form)` gives a kit form's answers without sending them. The kit's source is [../../kit/pots.js](../../kit/pots.js), [../../kit/pots-ui.js](../../kit/pots-ui.js) and [../../kit/pots.css](../../kit/pots.css).
149
338
 
150
339
  ### Fully custom pages
151
340
 
@@ -233,7 +422,7 @@ What a Quick Tunnel means, from Cloudflare's docs and how it works:
233
422
  - Cloudflare ends the HTTPS connection on its servers, so Cloudflare can see the pages and what people type into them.
234
423
  - Cloudflare says Quick Tunnels are for testing and development, with no uptime guarantee; at most 200 requests at a time, and no Server-Sent Events.
235
424
 
236
- **When to tell the person.** The first time you send a page link over a Quick Tunnel, tell the people you work with these facts in a sentence or two, and save in your memory that you did. For example: "This link goes through Cloudflare's free Quick Tunnel, which needs no account. Three things to know: the link changes when Pots restarts, Cloudflare can see the page, and Cloudflare says the service is for testing. For a fixed address that Cloudflare cannot read, I can set up Tailscale Funnel; you would sign in once." And every time you send a password page over a Quick Tunnel, say that Cloudflare can see what is typed into it.
425
+ **When to tell the person.** The first time you send a page link over a Quick Tunnel, tell the people you work with what it means for them, and offer Tailscale Funnel for a fixed address that Cloudflare cannot read. When you send a password page over a Quick Tunnel, tell them that Cloudflare can see what is typed into it.
237
426
 
238
427
  ## Set up Tailscale Funnel with the person
239
428
 
@@ -260,7 +449,7 @@ Pots puts no browser restrictions on your pages, so they can use any outside scr
260
449
 
261
450
  ## One browser origin
262
451
 
263
- All pages of this computer, of every bot, are under one address, so the browser treats them as one site. A script on one page can read what another page keeps in the browser. So never keep private data in `localStorage`, `sessionStorage`, IndexedDB or cookies; the kit keeps nothing there.
452
+ All pages of this computer, of every bot, are under one address, so the browser treats them as one site. A script on one page can read what another page keeps in the browser. So never keep private data in `localStorage`, `sessionStorage`, IndexedDB or cookies; the kit keeps only the reader's light or dark choice there.
264
453
 
265
454
  ## Website projects
266
455
 
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ // A screenshot of a page at a real viewport width, in headless Chrome or Chromium, for the pages skill.
3
+ // node shot.mjs <url> <width> <out.png> [dark]
4
+ // It emulates the width (a window can not be made narrower than about 500px, so --window-size crops a wider layout),
5
+ // takes the whole page, and prints what it measured: the page's innerWidth, whether it scrolls sideways, and script
6
+ // errors. A page taller than 16000px goes in several files, out.png, out-2.png, ..., each up to 16000px, named in "files". It fails when innerWidth is not the width asked for. $CHROME names the browser when it is not on PATH.
7
+ import { spawn, spawnSync } from "node:child_process";
8
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+ import { setTimeout as sleep } from "node:timers/promises";
12
+
13
+ const [url, widthArg, out, scheme] = process.argv.slice(2);
14
+ const width = Number(widthArg);
15
+ if (!url || !(width > 0) || !out) {
16
+ console.error("usage: node shot.mjs <url> <width> <out.png> [dark]");
17
+ process.exit(2);
18
+ }
19
+ const names = ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser", "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"];
20
+ const chrome = process.env.CHROME || names.find((n) => (n.startsWith("/") ? existsSync(n) : spawnSync("which", [n]).status === 0));
21
+ if (!chrome) {
22
+ console.error("no Chrome or Chromium found; install one, or set CHROME");
23
+ process.exit(2);
24
+ }
25
+ const profile = mkdtempSync(join(tmpdir(), "shot-"));
26
+ // --use-mock-keychain: Chrome on macOS does not wait for the keychain, which can hold back the page for good.
27
+ const browser = spawn(chrome, ["--headless=new", "--remote-debugging-port=0", `--user-data-dir=${profile}`, "--no-first-run", "--no-default-browser-check", "--hide-scrollbars", "--use-mock-keychain", "about:blank"], { stdio: "ignore" });
28
+ let status = 1;
29
+ let port;
30
+ try {
31
+ // A file that is empty or not yet complete is read again after a wait.
32
+ for (let i = 0; i < 100 && !port; i++) {
33
+ try {
34
+ const [p, path] = readFileSync(join(profile, "DevToolsActivePort"), "utf8").split("\n");
35
+ if (path) port = p;
36
+ } catch {}
37
+ if (!port) await sleep(100);
38
+ }
39
+ const page = (await (await fetch(`http://127.0.0.1:${port}/json/list`)).json()).find((t) => t.type === "page");
40
+ const ws = new WebSocket(page.webSocketDebuggerUrl);
41
+ await new Promise((resolve, reject) => ((ws.onopen = resolve), (ws.onerror = reject)));
42
+ let id = 0;
43
+ const waiting = new Map();
44
+ const errors = [];
45
+ ws.onmessage = (m) => {
46
+ const msg = JSON.parse(m.data);
47
+ if (waiting.has(msg.id)) waiting.get(msg.id)(msg);
48
+ else if (msg.method === "Runtime.exceptionThrown") errors.push(msg.params.exceptionDetails.exception?.description || msg.params.exceptionDetails.text);
49
+ else if (msg.method === "Runtime.consoleAPICalled" && msg.params.type === "error") errors.push(msg.params.args.map((a) => a.value ?? a.description).join(" "));
50
+ else if (msg.method === "Page.loadEventFired") waiting.get("load")?.();
51
+ };
52
+ const send = (method, params = {}) =>
53
+ new Promise((resolve, reject) => {
54
+ const n = ++id;
55
+ waiting.set(n, (msg) => (waiting.delete(n), msg.error ? reject(new Error(`${method}: ${msg.error.message}`)) : resolve(msg.result)));
56
+ ws.send(JSON.stringify({ id: n, method, params }));
57
+ });
58
+ await send("Page.enable");
59
+ await send("Runtime.enable");
60
+ // mobile: as a phone lays out the page, with its viewport meta tag.
61
+ await send("Emulation.setDeviceMetricsOverride", { width, height: 900, deviceScaleFactor: 1, mobile: width < 600 });
62
+ await send("Emulation.setEmulatedMedia", { features: [{ name: "prefers-color-scheme", value: scheme === "dark" ? "dark" : "light" }] });
63
+ const loaded = new Promise((resolve) => waiting.set("load", resolve));
64
+ await send("Page.navigate", { url });
65
+ await Promise.race([loaded, sleep(15000)]);
66
+ await sleep(500);
67
+ const { result } = await send("Runtime.evaluate", {
68
+ expression: "JSON.stringify({ innerWidth, scrollWidth: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight })",
69
+ returnByValue: true,
70
+ });
71
+ const seen = JSON.parse(result.value);
72
+ // Chrome can not take one image much taller than 16000px, so a longer page is taken in parts that join up.
73
+ const limit = 16000;
74
+ const files = [];
75
+ for (let y = 0; y === 0 || y < seen.height; y += limit) {
76
+ const file = y === 0 ? out : out.replace(/(\.png)?$/i, (ext) => `-${y / limit + 1}${ext}`);
77
+ const clip = { x: 0, y, width, height: Math.max(1, Math.min(limit, seen.height - y)), scale: 1 };
78
+ const shot = await send("Page.captureScreenshot", { format: "png", captureBeyondViewport: true, clip });
79
+ writeFileSync(file, Buffer.from(shot.data, "base64"));
80
+ files.push(file);
81
+ }
82
+ const report = { file: out, width, innerWidth: seen.innerWidth, height: seen.height, scrollsSideways: seen.scrollWidth > seen.innerWidth, errors };
83
+ if (files.length > 1) report.files = files;
84
+ console.log(JSON.stringify(report));
85
+ if (seen.innerWidth !== width) console.error(`innerWidth is ${seen.innerWidth}, not ${width}`);
86
+ else status = 0;
87
+ ws.close();
88
+ } finally {
89
+ await close(browser, port);
90
+ rmSync(profile, { recursive: true, force: true, maxRetries: 10, retryDelay: 200 });
91
+ }
92
+ process.exit(status);
93
+
94
+ // Closes the browser as a person would (Browser.close), so its helper processes end before the profile is removed.
95
+ async function close(browser, port) {
96
+ const exited = new Promise((resolve) => (browser.exitCode !== null ? resolve() : browser.once("exit", resolve)));
97
+ try {
98
+ const { webSocketDebuggerUrl } = await (await fetch(`http://127.0.0.1:${port}/json/version`)).json();
99
+ const ws = new WebSocket(webSocketDebuggerUrl);
100
+ await new Promise((resolve, reject) => ((ws.onopen = resolve), (ws.onerror = reject)));
101
+ ws.send(JSON.stringify({ id: 1, method: "Browser.close" }));
102
+ } catch {}
103
+ await Promise.race([exited, sleep(5000)]);
104
+ if (browser.exitCode === null) browser.kill("SIGKILL");
105
+ await exited;
106
+ }