pi-durable-bot 0.6.0 → 0.7.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 (70) hide show
  1. package/CHANGELOG.md +33 -3
  2. package/dist/agent/resources.js +12 -1
  3. package/dist/agent/resources.js.map +1 -1
  4. package/dist/bot/bot.js +54 -5
  5. package/dist/bot/bot.js.map +1 -1
  6. package/dist/bot/prompt.js +13 -3
  7. package/dist/bot/prompt.js.map +1 -1
  8. package/dist/channels/discord/index.js +202 -20
  9. package/dist/channels/discord/index.js.map +1 -1
  10. package/dist/channels/slack/index.js +314 -16
  11. package/dist/channels/slack/index.js.map +1 -1
  12. package/dist/channels/telegram/index.js +21 -2
  13. package/dist/channels/telegram/index.js.map +1 -1
  14. package/dist/cli/agent.js +20 -1
  15. package/dist/cli/agent.js.map +1 -1
  16. package/dist/cli/commands.js +28 -4
  17. package/dist/cli/commands.js.map +1 -1
  18. package/dist/cli/mcp.js +27 -1
  19. package/dist/cli/mcp.js.map +1 -1
  20. package/dist/cli/pages.js +44 -0
  21. package/dist/cli/pages.js.map +1 -0
  22. package/dist/cli/service.js +107 -49
  23. package/dist/cli/service.js.map +1 -1
  24. package/dist/core/channel.js +4 -1
  25. package/dist/core/channel.js.map +1 -1
  26. package/dist/core/env-file.js +23 -6
  27. package/dist/core/env-file.js.map +1 -1
  28. package/dist/core/forms.js +16 -0
  29. package/dist/core/forms.js.map +1 -0
  30. package/dist/core/home.js +10 -2
  31. package/dist/core/home.js.map +1 -1
  32. package/dist/gateway/errors.js +3 -0
  33. package/dist/gateway/errors.js.map +1 -1
  34. package/dist/gateway/forms.js +99 -0
  35. package/dist/gateway/forms.js.map +1 -0
  36. package/dist/gateway/gateway.js +23 -1
  37. package/dist/gateway/gateway.js.map +1 -1
  38. package/dist/gateway/log.js +7 -5
  39. package/dist/gateway/log.js.map +1 -1
  40. package/dist/gateway/waker.js +23 -8
  41. package/dist/gateway/waker.js.map +1 -1
  42. package/dist/main.js +23 -4
  43. package/dist/main.js.map +1 -1
  44. package/dist/pages/cloudflared.js +149 -0
  45. package/dist/pages/cloudflared.js.map +1 -0
  46. package/dist/pages/files.js +244 -0
  47. package/dist/pages/files.js.map +1 -0
  48. package/dist/pages/host.js +268 -0
  49. package/dist/pages/host.js.map +1 -0
  50. package/dist/pages/secret-page.js +71 -0
  51. package/dist/pages/secret-page.js.map +1 -0
  52. package/dist/pages/server.js +305 -0
  53. package/dist/pages/server.js.map +1 -0
  54. package/dist/pages/settings.js +71 -0
  55. package/dist/pages/settings.js.map +1 -0
  56. package/dist/pages/store.js +492 -0
  57. package/dist/pages/store.js.map +1 -0
  58. package/dist/pages/tunnel.js +271 -0
  59. package/dist/pages/tunnel.js.map +1 -0
  60. package/docs/for-agents.md +10 -8
  61. package/kit/pots.css +473 -0
  62. package/kit/pots.js +627 -0
  63. package/package.json +4 -3
  64. package/{docs/channels/discord.md → skills/discord-channel/SKILL.md} +55 -2
  65. package/skills/pages/SKILL.md +242 -0
  66. package/skills/slack-channel/SKILL.md +126 -0
  67. package/skills/telegram-channel/SKILL.md +89 -0
  68. package/docs/channels/slack.md +0 -70
  69. package/docs/channels/telegram.md +0 -50
  70. /package/{docs/channels → skills/slack-channel}/slack-app-manifest.yaml +0 -0
@@ -0,0 +1,244 @@
1
+ import { createHash } from "node:crypto";
2
+ import { constants } from "node:fs";
3
+ import { lstat, open, readdir, realpath, stat } from "node:fs/promises";
4
+ import { extname, join, relative, sep } from "node:path";
5
+ // Where pages live and which files a link may serve: only regular files inside the link's own page folder, after the
6
+ // real path is resolved. No "..", no encoded separators, no symbolic link, junction or hard link that leads out.
7
+ /** A page name: "deploy-plan", or "keep/annual-report" for a page that is never deleted by age. */
8
+ const NAME = /^(?:keep\/)?[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
9
+ export function pageNameProblem(name) {
10
+ if (!NAME.test(name) || name === "keep")
11
+ return `bad page name ${JSON.stringify(name)}: use a folder name in pages/ (letters, digits, "-" and "_"), or keep/<name>`;
12
+ return undefined;
13
+ }
14
+ /** The bot's pages folder. */
15
+ export const pagesDir = (botDir) => join(botDir, "pages");
16
+ /**
17
+ * True when path is inside root, or is root itself when allowRoot. Both are canonical paths from the file system
18
+ * (realpath, which is the native one), compared exactly: never by case, since a case-sensitive file system, which macOS
19
+ * and Windows can have too, holds pages/Report and pages/report side by side.
20
+ */
21
+ export function inside(root, path, allowRoot = false) {
22
+ if (path === root)
23
+ return allowRoot;
24
+ return path.startsWith(root.endsWith(sep) ? root : `${root}${sep}`);
25
+ }
26
+ /**
27
+ * A folder's or file's identity on the file system, which a folder of the same name made later does not share: its
28
+ * device and inode, and its birth time, since a file system can give a freed inode to the next folder it makes.
29
+ */
30
+ export async function identity(path) {
31
+ try {
32
+ const info = await stat(path, { bigint: true });
33
+ return `${info.dev}:${info.ino}:${info.birthtimeNs}`;
34
+ }
35
+ catch {
36
+ return undefined;
37
+ }
38
+ }
39
+ /**
40
+ * The real path of a page's folder, when it is a plain folder in the bot's pages/ folder: no symbolic link or junction
41
+ * on the way from the bot folder (pages/, keep/ and the page's own folder). Undefined otherwise.
42
+ */
43
+ export async function pageFolder(botDir, name) {
44
+ if (pageNameProblem(name))
45
+ return undefined;
46
+ try {
47
+ const base = await realpath(botDir);
48
+ const expected = join(base, "pages", ...name.split("/"));
49
+ const folder = await realpath(join(botDir, "pages", ...name.split("/")));
50
+ if (folder !== expected)
51
+ return undefined;
52
+ // realpath already followed any link; lstat says whether the parts themselves are links.
53
+ let path = join(base, "pages");
54
+ for (const part of ["", ...name.split("/")]) {
55
+ if (part)
56
+ path = join(path, part);
57
+ const info = await lstat(path);
58
+ if (info.isSymbolicLink() || !info.isDirectory())
59
+ return undefined;
60
+ }
61
+ return folder;
62
+ }
63
+ catch {
64
+ return undefined;
65
+ }
66
+ }
67
+ /** Windows names that open a device, not a file, also with an extension: CON, NUL, COM1.txt. */
68
+ const WINDOWS_DEVICE = /^(?:con|prn|aux|nul|conin\$|conout\$|com[0-9¹²³]|lpt[0-9¹²³])(?:\..*)?$/i;
69
+ /**
70
+ * The path segments of a URL path below a page or the kit, decoded, or undefined when the path must be refused: an
71
+ * encoded "/" or "\", a backslash, "." or "..", a NUL, an empty segment in the middle, bad percent-encoding, and on
72
+ * Windows a ":" (drive letters and alternate streams), a device name or a name that ends with a dot or a space (Windows
73
+ * drops those, so the name would stand for another one).
74
+ */
75
+ export function pathSegments(raw) {
76
+ if (raw === "")
77
+ return [];
78
+ if (/%(?:2f|5c|00)/i.test(raw) || raw.includes("\\"))
79
+ return undefined;
80
+ const parts = raw.split("/");
81
+ const segments = [];
82
+ for (const [index, part] of parts.entries()) {
83
+ if (part === "") {
84
+ // Only at the end: "dir/" is the folder's index.html.
85
+ if (index === parts.length - 1)
86
+ break;
87
+ return undefined;
88
+ }
89
+ let segment;
90
+ try {
91
+ segment = decodeURIComponent(part);
92
+ }
93
+ catch {
94
+ return undefined;
95
+ }
96
+ if (segment === "." || segment === ".." || /[\\/\0]/.test(segment))
97
+ return undefined;
98
+ if (process.platform === "win32" && (segment.includes(":") || WINDOWS_DEVICE.test(segment) || /[. ]$/.test(segment)))
99
+ return undefined;
100
+ segments.push(segment);
101
+ }
102
+ return segments;
103
+ }
104
+ /** For tests: runs after a file was found and checked, before it is opened, so a test can swap it for a link. */
105
+ export const fileTestHooks = {};
106
+ /**
107
+ * Open the file that segments name inside root (a canonical path), when it is a regular file that stays in root. A
108
+ * folder gives its index.html when trailingSlash. The file is opened once, without following a link in its last part
109
+ * where the system can (O_NOFOLLOW), and then the open descriptor is checked: a regular file, with one name only when
110
+ * refuseHardLinks (a second name may be a file outside the folder), and the same file (device and inode) that its path
111
+ * still leads to, inside root. So a file or a folder above it swapped for a link between the first look and the open is
112
+ * refused, and what is sent is read from that descriptor, never from the path again.
113
+ *
114
+ * Not refused: a folder above the file swapped for a link just before the open, back just after it, and once more
115
+ * before the last stat. Only a process of this same user can do that, and it can read the secrets folder without the
116
+ * page server. To refuse it, the walk would have to start from an open folder (openat2 with RESOLVE_BENEATH), which
117
+ * only Linux has and Node does not expose.
118
+ */
119
+ export async function openFile(root, segments, trailingSlash, refuseHardLinks) {
120
+ let path;
121
+ try {
122
+ path = await realpath(join(root, ...segments));
123
+ if (!inside(root, path, true))
124
+ return undefined;
125
+ const info = await stat(path);
126
+ if (info.isDirectory()) {
127
+ if (!trailingSlash && segments.length > 0)
128
+ return { kind: "folder" };
129
+ path = await realpath(join(path, "index.html"));
130
+ if (!inside(root, path))
131
+ return undefined;
132
+ }
133
+ else if (trailingSlash)
134
+ return undefined;
135
+ await fileTestHooks.beforeOpen?.(path);
136
+ }
137
+ catch {
138
+ return undefined;
139
+ }
140
+ let handle;
141
+ try {
142
+ handle = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
143
+ }
144
+ catch {
145
+ return undefined;
146
+ }
147
+ try {
148
+ const opened = await handle.stat({ bigint: true });
149
+ if (!opened.isFile() || (refuseHardLinks && opened.nlink > 1n))
150
+ throw new Error("not a plain file");
151
+ const again = await realpath(path);
152
+ if (!inside(root, again))
153
+ throw new Error("left the folder");
154
+ const there = await stat(again, { bigint: true });
155
+ if (there.dev !== opened.dev || there.ino !== opened.ino)
156
+ throw new Error("another file");
157
+ return { kind: "file", path: again, handle, size: Number(opened.size), mtimeMs: Number(opened.mtimeMs) };
158
+ }
159
+ catch {
160
+ await handle.close().catch(() => { });
161
+ return undefined;
162
+ }
163
+ }
164
+ const TYPES = {
165
+ ".html": "text/html; charset=utf-8",
166
+ ".htm": "text/html; charset=utf-8",
167
+ ".css": "text/css; charset=utf-8",
168
+ ".js": "text/javascript; charset=utf-8",
169
+ ".mjs": "text/javascript; charset=utf-8",
170
+ ".json": "application/json; charset=utf-8",
171
+ ".map": "application/json; charset=utf-8",
172
+ ".txt": "text/plain; charset=utf-8",
173
+ ".md": "text/plain; charset=utf-8",
174
+ ".csv": "text/csv; charset=utf-8",
175
+ ".xml": "application/xml; charset=utf-8",
176
+ ".svg": "image/svg+xml",
177
+ ".png": "image/png",
178
+ ".jpg": "image/jpeg",
179
+ ".jpeg": "image/jpeg",
180
+ ".gif": "image/gif",
181
+ ".webp": "image/webp",
182
+ ".avif": "image/avif",
183
+ ".ico": "image/x-icon",
184
+ ".pdf": "application/pdf",
185
+ ".wasm": "application/wasm",
186
+ ".woff": "font/woff",
187
+ ".woff2": "font/woff2",
188
+ ".ttf": "font/ttf",
189
+ ".otf": "font/otf",
190
+ ".mp4": "video/mp4",
191
+ ".webm": "video/webm",
192
+ ".mp3": "audio/mpeg",
193
+ ".m4a": "audio/mp4",
194
+ ".wav": "audio/wav",
195
+ ".ogg": "audio/ogg",
196
+ };
197
+ export const contentType = (path) => TYPES[extname(path).toLowerCase()] ?? "application/octet-stream";
198
+ /** At most this many entries count for a page's version; a larger page changes version only within them. */
199
+ const VERSION_ENTRIES = 5_000;
200
+ /**
201
+ * A short string that changes whenever a file of the folder changes, comes or goes: from each entry's path, size,
202
+ * modification and change time. Symbolic links count by where they point. Undefined when the folder is not there.
203
+ */
204
+ export async function folderVersion(folder) {
205
+ const hash = createHash("sha256");
206
+ let count = 0;
207
+ const walk = async (dir) => {
208
+ const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
209
+ for (const entry of entries) {
210
+ if (++count > VERSION_ENTRIES)
211
+ return;
212
+ const path = join(dir, entry.name);
213
+ const info = await lstat(path).catch(() => undefined);
214
+ if (!info)
215
+ continue;
216
+ hash.update(`${relative(folder, path)}\0${info.isDirectory() ? "d" : info.isSymbolicLink() ? "l" : "f"}\0${info.size}\0${info.mtimeMs}\0${info.ctimeMs}\n`);
217
+ if (info.isDirectory())
218
+ await walk(path);
219
+ }
220
+ };
221
+ try {
222
+ await walk(folder);
223
+ }
224
+ catch {
225
+ return undefined;
226
+ }
227
+ return hash.digest("hex").slice(0, 16);
228
+ }
229
+ /** The page folders of a bot: the folders in pages/ but keep/, and those in pages/keep/. Links are left out. */
230
+ export async function listPageNames(botDir) {
231
+ const names = [];
232
+ const folders = async (dir) => (await readdir(dir, { withFileTypes: true }).catch(() => [])).filter((entry) => entry.isDirectory() && !entry.isSymbolicLink()).map((entry) => entry.name);
233
+ for (const name of await folders(pagesDir(botDir))) {
234
+ if (name === "keep") {
235
+ for (const kept of await folders(join(pagesDir(botDir), "keep")))
236
+ if (!pageNameProblem(`keep/${kept}`))
237
+ names.push(`keep/${kept}`);
238
+ }
239
+ else if (!pageNameProblem(name))
240
+ names.push(name);
241
+ }
242
+ return names.sort();
243
+ }
244
+ //# sourceMappingURL=files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/pages/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAmB,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEzD,qHAAqH;AACrH,iHAAiH;AAEjH,mGAAmG;AACnG,MAAM,IAAI,GAAG,6CAA6C,CAAC;AAE3D,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,MAAM;QAAE,OAAO,iBAAiB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,8EAA8E,CAAC;IACpK,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,8BAA8B;AAC9B,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElE;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY,EAAE,IAAY,EAA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D,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,268 @@
1
+ import { createServer } from "node:http";
2
+ import { fileURLToPath } from "node:url";
3
+ import { ensureCloudflared } from "./cloudflared.js";
4
+ import { readSettings, writeSetting } from "./settings.js";
5
+ import { PageRequests } from "./server.js";
6
+ import { PAGE_DAYS } from "./store.js";
7
+ import { QuickTunnel, stopLeftoverTunnel } from "./tunnel.js";
8
+ // The page server of a gateway: one per POTS_HOME, for every bot. Its port is chosen once and kept in settings.json; its
9
+ // public address is settings.json's publicUrl, or else a Cloudflare Quick Tunnel that starts at the first link.
10
+ /** kit/ of this package, next to src/ or dist/. */
11
+ const KIT_DIR = fileURLToPath(new URL("../../kit/", import.meta.url));
12
+ /** How often the server tries its port again while it cannot listen. */
13
+ const RETRY_MS = 30_000;
14
+ const DAY_MS = 86_400_000;
15
+ /** The facts the agent passes on when a link goes through a Quick Tunnel. */
16
+ export const QUICK_TUNNEL_NOTE = "This link goes through a Cloudflare Quick Tunnel: its address changes when Pots restarts, Cloudflare can see the page's content, and Cloudflare says Quick Tunnels are for testing and development.";
17
+ export const QUICK_TUNNEL_SECRET_NOTE = "This link goes through a Cloudflare Quick Tunnel: its address changes when Pots restarts, Cloudflare can see what is typed on the page, and Cloudflare says Quick Tunnels are for testing and development.";
18
+ const iso = (ms) => (ms === null ? null : new Date(ms).toISOString());
19
+ export class PageHost {
20
+ #options;
21
+ #bots = new Map();
22
+ #requests;
23
+ #server;
24
+ #port;
25
+ #problem;
26
+ #retry;
27
+ #tunnel;
28
+ #stopped = false;
29
+ constructor(options) {
30
+ this.#options = options;
31
+ this.#requests = new PageRequests({
32
+ bots: () => this.#bots.values(),
33
+ quickTunnel: () => this.#quickTunnel(),
34
+ kitDir: options.kitDir ?? KIT_DIR,
35
+ print: options.print,
36
+ });
37
+ }
38
+ get port() {
39
+ return this.#port;
40
+ }
41
+ /** Listen on the kept port, or choose one and keep it. A port that is taken is reported, and tried again now and then. */
42
+ async start() {
43
+ // A tunnel a crashed gateway left would make the kept port public again, at its old address.
44
+ stopLeftoverTunnel(this.#options.home, this.#options.print);
45
+ await this.#listen();
46
+ if (!this.#server)
47
+ this.#retry = setInterval(() => void this.#listen(), RETRY_MS).unref();
48
+ }
49
+ async stop() {
50
+ this.#stopped = true;
51
+ clearInterval(this.#retry);
52
+ await this.#tunnel?.stop();
53
+ const server = this.#server;
54
+ this.#server = undefined;
55
+ if (server) {
56
+ server.closeAllConnections();
57
+ await new Promise((resolve) => server.close(() => resolve()));
58
+ }
59
+ }
60
+ register(bot) {
61
+ this.#bots.set(bot.id, bot);
62
+ }
63
+ unregister(id) {
64
+ this.#bots.delete(id);
65
+ this.#requests.forget(id);
66
+ }
67
+ async #listen() {
68
+ if (this.#server || this.#stopped)
69
+ return;
70
+ const file = this.#options.settingsFile;
71
+ let port;
72
+ try {
73
+ port = readSettings(file).pagePort;
74
+ }
75
+ catch (error) {
76
+ return this.#report(error instanceof Error ? error.message : String(error));
77
+ }
78
+ const server = createServer(this.#requests.handle);
79
+ try {
80
+ await new Promise((resolve, reject) => {
81
+ server.once("error", reject);
82
+ server.listen(port ?? 0, "127.0.0.1", () => resolve());
83
+ });
84
+ }
85
+ catch (error) {
86
+ const code = error.code;
87
+ return this.#report(code === "EADDRINUSE" || code === "EACCES"
88
+ ? `port ${port} (pagePort in ${file}) is taken by another program, so pages are not served; free it, or set another pagePort there and restart Pots (a Funnel or proxy that points at the old port must change too)`
89
+ : `the page server could not listen on 127.0.0.1:${port ?? 0}: ${error instanceof Error ? error.message : String(error)}`);
90
+ }
91
+ const chosen = server.address().port;
92
+ if (port === undefined) {
93
+ try {
94
+ await writeSetting("pagePort", chosen, file);
95
+ }
96
+ catch (error) {
97
+ server.close();
98
+ return this.#report(`could not keep the page server's port in ${file}: ${error instanceof Error ? error.message : String(error)}`);
99
+ }
100
+ }
101
+ this.#server = server;
102
+ this.#port = chosen;
103
+ this.#problem = undefined;
104
+ clearInterval(this.#retry);
105
+ this.#options.print("page server started", { port: chosen });
106
+ }
107
+ #report(problem) {
108
+ if (this.#problem !== problem)
109
+ this.#options.print("page server not running", { problem });
110
+ this.#problem = problem;
111
+ }
112
+ #quickTunnel() {
113
+ try {
114
+ return readSettings(this.#options.settingsFile).publicUrl === undefined;
115
+ }
116
+ catch {
117
+ return true;
118
+ }
119
+ }
120
+ /**
121
+ * The public address links use now. With publicUrl in settings.json, that one, and a Quick Tunnel that still runs is
122
+ * stopped. Without it, the Quick Tunnel's address; start: start it if it does not run and wait for its address.
123
+ */
124
+ async #address(start) {
125
+ const settings = readSettings(this.#options.settingsFile);
126
+ if (settings.publicUrl) {
127
+ if (this.#tunnel) {
128
+ const tunnel = this.#tunnel;
129
+ this.#tunnel = undefined;
130
+ await tunnel.stop();
131
+ this.#options.print("quick tunnel stopped: settings.json has a publicUrl");
132
+ }
133
+ return { base: settings.publicUrl, via: "public-url" };
134
+ }
135
+ if (!start)
136
+ return { ...(this.#tunnel?.address ? { base: this.#tunnel.address } : {}), via: "quick-tunnel" };
137
+ if (this.#port === undefined)
138
+ throw new Error(`the page server is not running: ${this.#problem ?? "it is starting"}`);
139
+ this.#tunnel ??= new QuickTunnel({
140
+ target: `http://127.0.0.1:${this.#port}`,
141
+ home: this.#options.home,
142
+ program: this.#options.cloudflared ?? (async () => [await ensureCloudflared(this.#options.binDir, { print: this.#options.print })]),
143
+ print: this.#options.print,
144
+ ...this.#options.tunnel,
145
+ });
146
+ return { base: await this.#tunnel.ensure(), via: "quick-tunnel" };
147
+ }
148
+ #ready() {
149
+ if (this.#port === undefined)
150
+ throw new Error(`the page server is not running: ${this.#problem ?? "it is starting"}`);
151
+ }
152
+ /** pots page link: a new link to a page, written before it is given out. */
153
+ async link(bot, page, person) {
154
+ this.#ready();
155
+ const made = await bot.createLink(page, person);
156
+ let address;
157
+ try {
158
+ address = await this.#address(true);
159
+ }
160
+ catch (error) {
161
+ await bot.revoke(made.id);
162
+ throw error;
163
+ }
164
+ return { link: made.id, url: `${address.base}/p/${made.token}/`, via: address.via, ...(address.via === "quick-tunnel" ? { note: QUICK_TUNNEL_NOTE } : {}) };
165
+ }
166
+ /** pots page secret: a password link for one submission, open for an hour. */
167
+ async secret(bot, input) {
168
+ this.#ready();
169
+ const made = await bot.createSecretLink(input);
170
+ let address;
171
+ try {
172
+ address = await this.#address(true);
173
+ }
174
+ catch (error) {
175
+ await bot.revoke(made.id);
176
+ throw error;
177
+ }
178
+ return {
179
+ link: made.id,
180
+ url: `${address.base}/s/${made.token}`,
181
+ expires: new Date(made.expiresAt).toISOString(),
182
+ via: address.via,
183
+ ...(address.via === "quick-tunnel" ? { note: QUICK_TUNNEL_SECRET_NOTE } : {}),
184
+ };
185
+ }
186
+ /** pots page unlink: by link ID or by URL. */
187
+ async unlink(bot, link) {
188
+ const token = /\/(?:p|s)\/([A-Za-z0-9_-]{16,128})(?:\/|$)/.exec(link)?.[1];
189
+ const revoked = await bot.revoke(token ?? link.trim());
190
+ if (!revoked)
191
+ throw new Error(`there is no link ${JSON.stringify(link)} of this bot (pots page list shows them)`);
192
+ return `Unlinked ${revoked}.`;
193
+ }
194
+ /** pots page list: the bot's pages and links, with their URLs at the address links use now. */
195
+ async list(bot) {
196
+ const listing = await bot.list();
197
+ let address = { via: "quick-tunnel" };
198
+ let problem;
199
+ try {
200
+ address = await this.#address(false);
201
+ }
202
+ catch (error) {
203
+ problem = error instanceof Error ? error.message : String(error);
204
+ }
205
+ const url = (path) => (address.base ? `${address.base}${path}` : null);
206
+ return {
207
+ via: address.via,
208
+ address: address.base ?? null,
209
+ ...(address.base ? {} : { addressNote: problem ?? "no Quick Tunnel runs now; the next pots page link or pots page secret starts one, and these links work again at its address" }),
210
+ pages: listing.pages.map((page) => ({
211
+ page: page.page,
212
+ kept: page.kept,
213
+ version: page.version,
214
+ lastOpened: iso(page.lastOpened),
215
+ lastChanged: iso(page.lastChanged),
216
+ deleteAfter: page.kept || page.lastChanged === null ? null : iso(Math.max(page.lastOpened ?? 0, page.lastChanged) + PAGE_DAYS * DAY_MS),
217
+ links: page.links.map((link) => ({ link: link.link, url: url(`/p/${link.token}/`), for: link.for, created: iso(link.created) })),
218
+ })),
219
+ secretLinks: listing.secretLinks.map((link) => ({
220
+ link: link.link,
221
+ url: url(`/s/${link.token}`),
222
+ file: link.file,
223
+ keys: link.keys,
224
+ for: link.for,
225
+ created: iso(link.created),
226
+ expires: iso(link.expires),
227
+ state: link.state,
228
+ })),
229
+ };
230
+ }
231
+ /** For pots status. */
232
+ status() {
233
+ let via;
234
+ let address;
235
+ let problem = this.#problem;
236
+ try {
237
+ const publicUrl = readSettings(this.#options.settingsFile).publicUrl;
238
+ via = publicUrl ? "public-url" : "quick-tunnel";
239
+ address = publicUrl ?? this.#tunnel?.address;
240
+ }
241
+ catch (error) {
242
+ problem ??= error instanceof Error ? error.message : String(error);
243
+ }
244
+ return {
245
+ ...(this.#port === undefined ? {} : { port: this.#port }),
246
+ listening: this.#server !== undefined,
247
+ ...(problem ? { problem } : {}),
248
+ ...(via ? { via } : {}),
249
+ ...(address ? { address } : {}),
250
+ ...(this.#tunnel ? { tunnel: this.#tunnel.status() } : {}),
251
+ };
252
+ }
253
+ }
254
+ /** One line for pots status. */
255
+ export function describePageServer(status, keptPort) {
256
+ if (!status)
257
+ return `pages: not running${keptPort === undefined ? "" : ` (port ${keptPort})`}`;
258
+ if (!status.listening)
259
+ return `pages: not served: ${status.problem ?? "starting"}`;
260
+ const port = `port ${status.port}`;
261
+ if (status.problem)
262
+ return `pages: ${port}; ${status.problem}`;
263
+ if (status.address)
264
+ return `pages: ${port}, ${status.address} (${status.via})`;
265
+ const tunnel = status.tunnel?.error ? `; ${status.tunnel.error}` : "";
266
+ return `pages: ${port}, no public address yet (quick-tunnel: it starts at the first pots page link${tunnel})`;
267
+ }
268
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/pages/host.ts"],"names":[],"mappings":"AA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AC,CAAC,UAAU,QAAQ,GAAG,EAAE,CAAC;IAC/F,IAAI,CAAC,MAAM,CAAC,SAAS;QAAE,OAAO,sBAAsB,MAAM,CAAC,OAAO,IAAI,UAAU,EAAE,CAAC;IACnF,MAAM,IAAI,GAAG,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;IACnC,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,UAAU,IAAI,KAAK,MAAM,CAAC,OAAO,EAAE,CAAC;IAC/D,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,UAAU,IAAI,KAAK,MAAM,CAAC,OAAO,KAAK,MAAM,CAAC,GAAG,GAAG,CAAC;IAC/E,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,UAAU,IAAI,+EAA+E,MAAM,GAAG,CAAC;AAChH,CAAC"}
@@ -0,0 +1,71 @@
1
+ // The password page: Pots's own HTML, never the bot's. A plain form and no script, so it works in the strictest sandbox.
2
+ /**
3
+ * The headers that keep the password page apart from the bot's pages, which share its address: the browser gives it an
4
+ * origin of its own (sandbox without allow-same-origin), so a bot page's script cannot read what is typed; nothing loads
5
+ * from anywhere, no script runs, and no page can frame it.
6
+ */
7
+ export const SECRET_PAGE_HEADERS = {
8
+ "content-security-policy": "sandbox allow-forms; default-src 'none'; style-src 'unsafe-inline'; frame-ancestors 'none'; base-uri 'none'",
9
+ "x-frame-options": "DENY",
10
+ "cross-origin-opener-policy": "same-origin",
11
+ "cache-control": "no-store",
12
+ };
13
+ const escape = (text) => text.replace(/[&<>"']/g, (char) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[char]);
14
+ const STYLE = `
15
+ :root { color-scheme: light dark; --fg: #1d2321; --muted: #5b6662; --line: #d5dbd8; --bg: #f7f8f7; --card: #fff; --accent: #1f7a70; --warn-bg: #fff6e0; --warn-fg: #6b4a00; }
16
+ @media (prefers-color-scheme: dark) { :root { --fg: #e8ecea; --muted: #a3aeaa; --line: #3a4441; --bg: #141917; --card: #1d2421; --accent: #4fb3a6; --warn-bg: #3a2f12; --warn-fg: #f3d58a; } }
17
+ * { box-sizing: border-box; }
18
+ body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--fg); background: var(--bg); }
19
+ main { max-width: 34rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
20
+ h1 { font-size: 1.3rem; line-height: 1.3; margin: 0 0 1rem; }
21
+ .card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1.25rem; }
22
+ .text { white-space: pre-wrap; margin: 0 0 1rem; }
23
+ label { display: block; font-weight: 600; margin: 1rem 0 0.35rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95rem; word-break: break-all; }
24
+ input { width: 100%; font: inherit; padding: 0.7rem 0.8rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); }
25
+ input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
26
+ button { margin-top: 1.25rem; width: 100%; font: inherit; font-weight: 600; padding: 0.8rem; border: 0; border-radius: 8px; background: var(--accent); color: #fff; }
27
+ .facts { color: var(--muted); font-size: 0.9rem; margin: 1rem 0 0; }
28
+ .warn { background: var(--warn-bg); color: var(--warn-fg); border-radius: 8px; padding: 0.75rem 0.9rem; font-size: 0.9rem; margin: 1rem 0 0; }
29
+ .problem { color: #b3261e; font-weight: 600; margin: 0 0 0.5rem; }
30
+ `;
31
+ function page(title, body) {
32
+ return `<!doctype html>
33
+ <html lang="en">
34
+ <head>
35
+ <meta charset="utf-8">
36
+ <meta name="viewport" content="width=device-width, initial-scale=1">
37
+ <meta name="referrer" content="no-referrer">
38
+ <meta name="robots" content="noindex">
39
+ <title>${escape(title)}</title>
40
+ <style>${STYLE}</style>
41
+ </head>
42
+ <body><main>${body}</main></body>
43
+ </html>
44
+ `;
45
+ }
46
+ /** What the person sees while the link is open: one masked field per key, and the facts about where the values go. */
47
+ export function renderSecretForm(link, botName, options) {
48
+ const minutes = Math.max(1, Math.ceil((link.expiresAt - options.now) / 60_000));
49
+ const fields = link.keys
50
+ .map((key, index) => `<label for="k${index}">${escape(key)}</label><input id="k${index}" name="${escape(key)}" type="password" required autocomplete="off" autocapitalize="off" autocorrect="off" spellcheck="false">`)
51
+ .join("\n");
52
+ const warn = options.quickTunnel
53
+ ? `<p class="warn">This page reaches ${escape(botName)} through a Cloudflare Quick Tunnel, so Cloudflare can see what you type here. For a private connection, ask ${escape(botName)} to set up Tailscale Funnel first.</p>`
54
+ : "";
55
+ return page(`${botName} asks for ${link.keys.length === 1 ? "a secret" : "secrets"}`, `<h1>${escape(botName)} asks for ${link.keys.length === 1 ? "a secret value" : `${link.keys.length} secret values`}</h1>
56
+ <div class="card">
57
+ ${options.problem ? `<p class="problem">${escape(options.problem)}</p>` : ""}${link.text ? `<p class="text">${escape(link.text)}</p>` : ""}
58
+ <form method="post" accept-charset="utf-8" autocomplete="off">
59
+ ${fields}
60
+ <button type="submit">Save (this link works once)</button>
61
+ </form>
62
+ <p class="facts">What you type goes only to the file ${escape(link.file)} in the secrets folder on ${escape(botName)}'s computer. It does not go into the chat. ${escape(botName)} is told which keys came, not their values. This link expires in about ${minutes} minute${minutes === 1 ? "" : "s"}.</p>
63
+ ${warn}
64
+ </div>`);
65
+ }
66
+ export const renderSecretSaved = (link, botName) => page("Saved", `<h1>Saved</h1><div class="card"><p>${escape(link.keys.join(", "))} ${link.keys.length === 1 ? "was" : "were"} written to ${escape(link.file)}. ${escape(botName)} was told which keys came, not their values. You can close this page.</p></div>`);
67
+ export const renderSecretUsed = () => page("Link already used", `<h1>This link was already used</h1><div class="card"><p>Each password link works once. Ask for a new link if you need to change a value.</p></div>`);
68
+ export const renderSecretExpired = () => page("Link expired", `<h1>This link expired</h1><div class="card"><p>A password link works for one hour. Ask for a new link.</p></div>`);
69
+ export const renderNotFound = () => page("Not found", `<h1>Not found</h1><div class="card"><p>This link does not exist, or it was taken back.</p></div>`);
70
+ export const renderFailed = (reason) => page("Not saved", `<h1>Not saved</h1><div class="card"><p>${escape(reason)}</p><p>Try again in a moment.</p></div>`);
71
+ //# sourceMappingURL=secret-page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"secret-page.js","sourceRoot":"","sources":["../../src/pages/secret-page.ts"],"names":[],"mappings":"AAEA,yHAAyH;AAEzH;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,yBAAyB,EAAE,6GAA6G;IACxI,iBAAiB,EAAE,MAAM;IACzB,4BAA4B,EAAE,aAAa;IAC3C,eAAe,EAAE,UAAU;CACnB,CAAC;AAEX,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,CAAE,CAAC,CAAC;AAEtJ,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;CAgBb,CAAC;AAEF,SAAS,IAAI,CAAC,KAAa,EAAE,IAAY;IACvC,OAAO;;;;;;;SAOA,MAAM,CAAC,KAAK,CAAC;SACb,KAAK;;cAEA,IAAI;;CAEjB,CAAC;AACF,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,gBAAgB,CAAC,IAAgB,EAAE,OAAe,EAAE,OAAgE;IAClI,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAChF,MAAM,M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