litepaseo 0.4.2 → 0.5.1

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 (89) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +4 -2
  3. package/dist/server/cli.mjs +2 -2
  4. package/dist/server/{worker-BxtQnBVZ.mjs → worker-Cig3TfcO.mjs} +436 -9
  5. package/dist/web/assets/{CodeBlockNode-Dg9n5ezc.js → CodeBlockNode-_x7pmRec.js} +1 -1
  6. package/dist/web/assets/CodeBlockNode-_x7pmRec.js.br +0 -0
  7. package/dist/web/assets/CodeBlockNode-_x7pmRec.js.gz +0 -0
  8. package/dist/web/assets/{FileViewer-BqAUo_AP.js → FileViewer-B3OHD2lY.js} +1 -1
  9. package/dist/web/assets/FileViewer-B3OHD2lY.js.br +0 -0
  10. package/dist/web/assets/FileViewer-B3OHD2lY.js.gz +0 -0
  11. package/dist/web/assets/{FilesPanel-Bl65Hz3k.js → FilesPanel-CXGp_iej.js} +1 -1
  12. package/dist/web/assets/FilesPanel-CXGp_iej.js.br +0 -0
  13. package/dist/web/assets/FilesPanel-CXGp_iej.js.gz +0 -0
  14. package/dist/web/assets/{MarkdownMessage-j-M1z3-u.js → MarkdownMessage-C1WAZAoK.js} +5 -5
  15. package/dist/web/assets/MarkdownMessage-C1WAZAoK.js.br +0 -0
  16. package/dist/web/assets/MarkdownMessage-C1WAZAoK.js.gz +0 -0
  17. package/dist/web/assets/{PreCodeBlock-B8fBuBdP.js → PreCodeBlock-B8ilPuwC.js} +1 -1
  18. package/dist/web/assets/{PreCodeBlock.vue_vue_type_style_index_0_lang-Cj9vGyzE.js → PreCodeBlock.vue_vue_type_style_index_0_lang-B9n3v4Td.js} +1 -1
  19. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-B9n3v4Td.js.br +0 -0
  20. package/dist/web/assets/{PreCodeBlock.vue_vue_type_style_index_0_lang-Cj9vGyzE.js.gz → PreCodeBlock.vue_vue_type_style_index_0_lang-B9n3v4Td.js.gz} +0 -0
  21. package/dist/web/assets/{TerminalPanel-ZkVJFLM1.js → TerminalPanel-CNNWUGNL.js} +1 -1
  22. package/dist/web/assets/TerminalPanel-CNNWUGNL.js.br +0 -0
  23. package/dist/web/assets/TerminalPanel-CNNWUGNL.js.gz +0 -0
  24. package/dist/web/assets/{Tooltip-Jdp8zjwT.js → Tooltip-Bn4MxBG1.js} +1 -1
  25. package/dist/web/assets/Tooltip-Bn4MxBG1.js.br +0 -0
  26. package/dist/web/assets/Tooltip-Bn4MxBG1.js.gz +0 -0
  27. package/dist/web/assets/index-CqexjrEd.css +1 -0
  28. package/dist/web/assets/index-CqexjrEd.css.br +0 -0
  29. package/dist/web/assets/index-CqexjrEd.css.gz +0 -0
  30. package/dist/web/assets/index-zPMH5LDK.js +34 -0
  31. package/dist/web/assets/index-zPMH5LDK.js.br +0 -0
  32. package/dist/web/assets/index-zPMH5LDK.js.gz +0 -0
  33. package/dist/web/assets/{index10-EuskhiaE.js → index10-BQ3hctN9.js} +1 -1
  34. package/dist/web/assets/index10-BQ3hctN9.js.br +0 -0
  35. package/dist/web/assets/index10-BQ3hctN9.js.gz +0 -0
  36. package/dist/web/assets/index3-CDLJc42-.js +1 -0
  37. package/dist/web/assets/index4-CmlPafgi.js +1 -0
  38. package/dist/web/assets/{index5-CIMd5e5U.js → index5-Cn_neOEH.js} +1 -1
  39. package/dist/web/assets/index5-Cn_neOEH.js.br +0 -0
  40. package/dist/web/assets/index5-Cn_neOEH.js.gz +0 -0
  41. package/dist/web/assets/{index6-DrnWk0rr.js → index6-DyQA9KO0.js} +1 -1
  42. package/dist/web/assets/index6-DyQA9KO0.js.br +0 -0
  43. package/dist/web/assets/index6-DyQA9KO0.js.gz +0 -0
  44. package/dist/web/assets/{index7-BCl4u4Ci.js → index7-C1CcYWix.js} +1 -1
  45. package/dist/web/assets/index7-C1CcYWix.js.br +0 -0
  46. package/dist/web/assets/index7-C1CcYWix.js.gz +0 -0
  47. package/dist/web/assets/{index8-tfhmdpKZ.js → index8-B-qx9WIe.js} +1 -1
  48. package/dist/web/assets/index8-B-qx9WIe.js.br +0 -0
  49. package/dist/web/assets/index8-B-qx9WIe.js.gz +0 -0
  50. package/dist/web/assets/{index9-Co0BXJFT.js → index9-Bi0iPNSv.js} +1 -1
  51. package/dist/web/assets/index9-Bi0iPNSv.js.br +0 -0
  52. package/dist/web/assets/index9-Bi0iPNSv.js.gz +0 -0
  53. package/dist/web/index.html +2 -2
  54. package/dist/web/index.html.br +0 -0
  55. package/dist/web/index.html.gz +0 -0
  56. package/package.json +1 -1
  57. package/dist/web/assets/CodeBlockNode-Dg9n5ezc.js.br +0 -0
  58. package/dist/web/assets/CodeBlockNode-Dg9n5ezc.js.gz +0 -0
  59. package/dist/web/assets/FileViewer-BqAUo_AP.js.br +0 -0
  60. package/dist/web/assets/FileViewer-BqAUo_AP.js.gz +0 -0
  61. package/dist/web/assets/FilesPanel-Bl65Hz3k.js.br +0 -0
  62. package/dist/web/assets/FilesPanel-Bl65Hz3k.js.gz +0 -0
  63. package/dist/web/assets/MarkdownMessage-j-M1z3-u.js.br +0 -0
  64. package/dist/web/assets/MarkdownMessage-j-M1z3-u.js.gz +0 -0
  65. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-Cj9vGyzE.js.br +0 -0
  66. package/dist/web/assets/TerminalPanel-ZkVJFLM1.js.br +0 -0
  67. package/dist/web/assets/TerminalPanel-ZkVJFLM1.js.gz +0 -0
  68. package/dist/web/assets/Tooltip-Jdp8zjwT.js.br +0 -0
  69. package/dist/web/assets/Tooltip-Jdp8zjwT.js.gz +0 -0
  70. package/dist/web/assets/index-Cf1QB007.js +0 -32
  71. package/dist/web/assets/index-Cf1QB007.js.br +0 -0
  72. package/dist/web/assets/index-Cf1QB007.js.gz +0 -0
  73. package/dist/web/assets/index-Dzid_5f9.css +0 -1
  74. package/dist/web/assets/index-Dzid_5f9.css.br +0 -0
  75. package/dist/web/assets/index-Dzid_5f9.css.gz +0 -0
  76. package/dist/web/assets/index10-EuskhiaE.js.br +0 -0
  77. package/dist/web/assets/index10-EuskhiaE.js.gz +0 -0
  78. package/dist/web/assets/index3-bqHD_tAN.js +0 -1
  79. package/dist/web/assets/index4-CnpLIN0Y.js +0 -1
  80. package/dist/web/assets/index5-CIMd5e5U.js.br +0 -0
  81. package/dist/web/assets/index5-CIMd5e5U.js.gz +0 -0
  82. package/dist/web/assets/index6-DrnWk0rr.js.br +0 -0
  83. package/dist/web/assets/index6-DrnWk0rr.js.gz +0 -0
  84. package/dist/web/assets/index7-BCl4u4Ci.js.br +0 -0
  85. package/dist/web/assets/index7-BCl4u4Ci.js.gz +0 -0
  86. package/dist/web/assets/index8-tfhmdpKZ.js.br +0 -0
  87. package/dist/web/assets/index8-tfhmdpKZ.js.gz +0 -0
  88. package/dist/web/assets/index9-Co0BXJFT.js.br +0 -0
  89. package/dist/web/assets/index9-Co0BXJFT.js.gz +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.1
4
+
5
+ - Turn-finished push notifications preview the latest agent reply instead of the thread
6
+ title (usually the first prompt). Failed turns show their error when available.
7
+
8
+ - Queued messages and attachments are saved by the BFF and sent when the agent finishes,
9
+ even after the browser closes or the device sleeps. Pending messages survive BFF restarts
10
+ and are visible across signed-in devices. Edit text, remove, or interrupt from the queue.
11
+ - Uncertain deliveries pause the queue for review instead of automatically retrying.
12
+
13
+ ## 0.5.0
14
+
15
+ ### Sidebar
16
+
17
+ - Project rows follow Paseo: the fold chevron takes the project icon's place on hover
18
+ (down when open, right when collapsed), and the actions on the right show only on hover.
19
+ - A project's ⋮ menu (or right-click) offers **Project settings…** and **Remove project…**.
20
+ Removing archives the project's threads and removes it from the host's projects; files
21
+ on disk are not touched.
22
+ - Project settings is Paseo's form for the project's `paseo.json` on its host: worktree
23
+ setup and teardown commands, scripts (each edited in its own dialog, optionally run as a
24
+ service) and metadata-generation instructions for branch names, commit messages and
25
+ pull requests. Fields the form does not show are kept as they are, and saving never
26
+ overwrites a `paseo.json` that changed on the host in the meantime.
27
+ - The pencil next to the project's name opens **Edit project**: rename it (blank returns to
28
+ the derived name) and set its icon from an image file or an image or website URL, or go
29
+ back to the automatic icon. The LitePaseo server downloads URL icons, since a browser
30
+ cannot. Sidebar icons now show custom icons and refresh when one changes.
31
+
3
32
  ## 0.4.2
4
33
 
5
34
  ### Terminal
package/README.md CHANGED
@@ -45,7 +45,8 @@ package, with no separate database service to deploy.
45
45
  - Manage conversations across multiple Paseo hosts in one place.
46
46
  - Create sessions, choose a provider/model, send messages, stop turns, and answer
47
47
  permission requests or structured questions.
48
- - Queue messages while an agent works, then edit, drop or send one at once as an
48
+ - Queue messages on the server while an agent works; they continue after you close the browser
49
+ and survive server restarts. Edit, drop or send one at once as an
49
50
  interrupt; rewind a conversation (and, where the provider supports it, its files)
50
51
  to an earlier message.
51
52
  - Read long conversations without clicking through pages: history loads as you
@@ -167,7 +168,8 @@ field, LitePaseo retries once with the other format.
167
168
  | `litepaseo token set` | Choose your own token (at least 16 characters; typed without echo or read from stdin) |
168
169
  | `litepaseo token rotate` | Replace the token with a new random one |
169
170
  | `litepaseo serve` | Run in the foreground |
170
- | `litepaseo version` | Show the installed and running versions (`-v` prints just the number) |
171
+ | `litepaseo version` | Show the installed and running versions (`--json` for scripts) |
172
+ | `litepaseo -v` | Print just the installed version number (also `--version`) |
171
173
  | `litepaseo --help` | List commands; `litepaseo help <command>` explains one |
172
174
 
173
175
  For automatic startup, install a systemd user service on Linux or a LaunchAgent
@@ -8,7 +8,7 @@ import { DatabaseSync } from "node:sqlite";
8
8
  import { homedir } from "node:os";
9
9
  import { fileURLToPath } from "node:url";
10
10
  // src/server/version.ts
11
- const VERSION = "0.4.2";
11
+ const VERSION = "0.5.1";
12
12
  // src/server/rotating-log.ts
13
13
  /** One writer (the supervisor); bounded active file plus numbered archives. */
14
14
  var RotatingLog = class {
@@ -1715,7 +1715,7 @@ async function run() {
1715
1715
  if (name === "--help" || name === "-h") return console.log(mainHelp(VERSION, displayDirectory(), out));
1716
1716
  if (name === "worker") {
1717
1717
  const paths = await dataDirectory();
1718
- const { runWorker } = await import("./worker-BxtQnBVZ.mjs");
1718
+ const { runWorker } = await import("./worker-Cig3TfcO.mjs");
1719
1719
  return runWorker(paths.directory, fileURLToPath(new URL("../web/", import.meta.url)));
1720
1720
  }
1721
1721
  const command = findCommand(name);
@@ -509,6 +509,9 @@ function summarizeWorkspace(hostId, ws, activity) {
509
509
  title: ws.title ?? null,
510
510
  project: ws.project?.projectName || ws.projectDisplayName || basename$1(ws.projectRootPath) || "Other",
511
511
  projectKey: ws.project?.projectKey ?? ws.projectId,
512
+ projectId: ws.projectId,
513
+ projectCustomName: ws.projectCustomName ?? null,
514
+ projectIconRevision: ws.projectCustomIconRevision ?? null,
512
515
  rootPath: ws.projectRootPath,
513
516
  directory: ws.workspaceDirectory ?? ws.projectRootPath,
514
517
  kind: ws.workspaceKind,
@@ -1165,6 +1168,220 @@ var Hosts = class {
1165
1168
  for (const listener of listeners) listener();
1166
1169
  }
1167
1170
  };
1171
+ // src/server/project-icon-import.ts
1172
+ /**
1173
+ * Turns an "image or website URL" into icon bytes, as Paseo's project edit sheet does
1174
+ * (packages/app import-project-icon, Apache-2.0). Paseo fetches from the app; a browser cannot
1175
+ * (CORS), so LitePaseo fetches here and hands the daemon the same upload payload a picked file
1176
+ * produces. The daemon still validates the bytes (format, square, size).
1177
+ */
1178
+ const MAX_ICON_BYTES = 524288;
1179
+ const MAX_HTML_BYTES = 524288;
1180
+ const MAX_CANDIDATES = 8;
1181
+ const FETCH_TIMEOUT_MS = 1e4;
1182
+ function parseHttpUrl(value) {
1183
+ let url;
1184
+ try {
1185
+ url = new URL(value);
1186
+ } catch {
1187
+ throw new Error("Enter a valid website or image URL");
1188
+ }
1189
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) throw new Error("URL must use HTTP or HTTPS without credentials");
1190
+ return url;
1191
+ }
1192
+ async function fetchOk(fetchIcon, url) {
1193
+ let response;
1194
+ try {
1195
+ response = await fetchIcon(url, {
1196
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
1197
+ headers: { accept: "image/*,text/html;q=0.9,*/*;q=0.5" }
1198
+ });
1199
+ } catch (error) {
1200
+ throw new Error(error.name === "TimeoutError" ? "Download timed out" : "Download failed");
1201
+ }
1202
+ if (!response.ok) throw new Error(`Download failed (${response.status})`);
1203
+ return response;
1204
+ }
1205
+ /** Reads at most maxBytes, stopping the download as soon as it is exceeded. */
1206
+ async function readBytes(response, maxBytes) {
1207
+ const declared = Number(response.headers.get("content-length"));
1208
+ if (Number.isFinite(declared) && declared > maxBytes) throw new Error("Icon must be 512 KB or smaller");
1209
+ if (!response.body) return Buffer.alloc(0);
1210
+ const chunks = [];
1211
+ let size = 0;
1212
+ const reader = response.body.getReader();
1213
+ for (;;) {
1214
+ const { done, value } = await reader.read();
1215
+ if (done) break;
1216
+ size += value.byteLength;
1217
+ if (size > maxBytes) {
1218
+ await reader.cancel().catch(() => {});
1219
+ throw new Error("Icon must be 512 KB or smaller");
1220
+ }
1221
+ chunks.push(value);
1222
+ }
1223
+ return Buffer.concat(chunks);
1224
+ }
1225
+ function attribute(tag, name) {
1226
+ return tag.match(new RegExp(`\\b${name}\\s*=\\s*["']([^"']+)["']`, "i"))?.[1]?.trim() || null;
1227
+ }
1228
+ /** The page's declared raster icons, then /favicon.ico. SVG is not a supported icon format. */
1229
+ function iconCandidates(html, page) {
1230
+ const candidates = [];
1231
+ for (const tag of html.match(/<link\b[^>]*>/gi) ?? []) {
1232
+ const rel = attribute(tag, "rel")?.toLowerCase() ?? "";
1233
+ const href = attribute(tag, "href");
1234
+ const type = attribute(tag, "type")?.toLowerCase() ?? "";
1235
+ if (!href || !rel.includes("icon") || type.includes("svg") || href.endsWith(".svg")) continue;
1236
+ try {
1237
+ candidates.push(new URL(href, page));
1238
+ } catch {}
1239
+ }
1240
+ candidates.push(new URL("/favicon.ico", page));
1241
+ return candidates.filter((u) => u.protocol === "http:" || u.protocol === "https:").slice(0, MAX_CANDIDATES);
1242
+ }
1243
+ /** Base64 icon bytes from an image URL, or from the icons a web page declares. */
1244
+ async function importProjectIcon(value, fetchIcon = fetch) {
1245
+ const url = parseHttpUrl(value.trim());
1246
+ const response = await fetchOk(fetchIcon, url);
1247
+ if (!(response.headers.get("content-type")?.toLowerCase() ?? "").includes("text/html")) return (await readBytes(response, MAX_ICON_BYTES)).toString("base64");
1248
+ const html = (await readBytes(response, MAX_HTML_BYTES)).toString("utf8");
1249
+ let lastError = /* @__PURE__ */ new Error("Website does not expose a supported icon");
1250
+ for (const candidate of iconCandidates(html, new URL(response.url || url.href))) try {
1251
+ return (await readBytes(await fetchOk(fetchIcon, candidate), MAX_ICON_BYTES)).toString("base64");
1252
+ } catch (error) {
1253
+ lastError = error;
1254
+ }
1255
+ throw lastError;
1256
+ }
1257
+ // src/server/send-queue.ts
1258
+ /** Durable ownership transfers to the BFF before enqueue is acknowledged. */
1259
+ var ServerSendQueue = class {
1260
+ entries;
1261
+ inflight = /* @__PURE__ */ new Set();
1262
+ awaitingTurn = /* @__PURE__ */ new Map();
1263
+ stops;
1264
+ closed = false;
1265
+ store;
1266
+ hosts;
1267
+ constructor(store, hosts) {
1268
+ this.store = store;
1269
+ this.hosts = hosts;
1270
+ this.entries = JSON.parse(store.setting("send-queue") ?? "[]");
1271
+ for (const entry of this.entries) if (entry.sending) {
1272
+ entry.sending = false;
1273
+ entry.error = "Delivery outcome unknown after restart. Check the conversation before sending again.";
1274
+ }
1275
+ this.save();
1276
+ this.stops = [
1277
+ hosts.onAgentsChanged(() => this.tick()),
1278
+ hosts.onHostsChanged(() => this.tick()),
1279
+ hosts.onTransition((_previous, next) => {
1280
+ if (next && (next.turnActive === true || next.status === "running" || next.status === "initializing")) this.awaitingTurn.delete(next.key);
1281
+ this.tick();
1282
+ })
1283
+ ];
1284
+ this.tick();
1285
+ }
1286
+ key(e) {
1287
+ return `${e.host}:${e.agent}`;
1288
+ }
1289
+ save() {
1290
+ this.store.setSetting("send-queue", JSON.stringify(this.entries));
1291
+ }
1292
+ list(host, agent) {
1293
+ return this.entries.filter((e) => e.host === host && e.agent === agent).map(({ prepared, ...entry }) => ({ ...entry }));
1294
+ }
1295
+ accepted(host, agent, id) {
1296
+ return this.store.setting(`queued-message:${id}`) === JSON.stringify([host, agent]);
1297
+ }
1298
+ add(entry) {
1299
+ if (this.entries.some((e) => e.id === entry.id)) throw new Error("Message ID already queued");
1300
+ if (this.entries.length >= 100 || JSON.stringify(this.entries).length + JSON.stringify(entry).length > 94371840) throw new Error("Queue is full. Remove queued messages first.");
1301
+ this.entries.push(entry);
1302
+ this.store.db.exec("BEGIN IMMEDIATE");
1303
+ try {
1304
+ this.save();
1305
+ this.store.setSetting(`queued-message:${entry.id}`, JSON.stringify([entry.host, entry.agent]));
1306
+ this.store.db.exec("COMMIT");
1307
+ } catch (error) {
1308
+ this.store.db.exec("ROLLBACK");
1309
+ this.entries.pop();
1310
+ throw error;
1311
+ }
1312
+ this.tick();
1313
+ }
1314
+ get(host, agent, id) {
1315
+ const e = this.entries.find((e) => e.host === host && e.agent === agent && e.id === id);
1316
+ if (!e) throw new Error("Queued message no longer available");
1317
+ if (e.sending || this.inflight.has(this.key(e))) throw new Error("Message is being sent. Refresh the queue.");
1318
+ return e;
1319
+ }
1320
+ remove(host, agent, id) {
1321
+ const e = this.get(host, agent, id);
1322
+ this.entries = this.entries.filter((item) => item !== e);
1323
+ this.save();
1324
+ this.tick();
1325
+ }
1326
+ edit(host, agent, id, text) {
1327
+ const e = this.get(host, agent, id);
1328
+ if (!text.trim() && !e.attachmentNames.length) throw new Error("Message cannot be empty");
1329
+ e.text = text;
1330
+ this.save();
1331
+ }
1332
+ async interrupt(host, agent, id) {
1333
+ await this.dispatch(this.get(host, agent, id), "interrupt");
1334
+ }
1335
+ tick() {
1336
+ if (this.closed) return;
1337
+ const seen = /* @__PURE__ */ new Set();
1338
+ for (const e of this.entries) {
1339
+ const key = this.key(e);
1340
+ if (seen.has(key)) continue;
1341
+ seen.add(key);
1342
+ const a = this.hosts.agents.get(key);
1343
+ const client = this.hosts.clients.get(e.host);
1344
+ if (!a || client?.driver.getConnectionState().status !== "connected") continue;
1345
+ if (!(a.turnActive === false || a.turnActive === void 0 && a.status !== "running" && a.status !== "initializing")) {
1346
+ this.awaitingTurn.delete(key);
1347
+ continue;
1348
+ }
1349
+ if (this.awaitingTurn.has(key) && (a.activityAt ?? 0) !== this.awaitingTurn.get(key)) this.awaitingTurn.delete(key);
1350
+ if (e.error || e.sending || this.inflight.has(key) || this.awaitingTurn.has(key)) continue;
1351
+ this.dispatch(e, "steer");
1352
+ }
1353
+ }
1354
+ async dispatch(e, behavior) {
1355
+ const key = this.key(e);
1356
+ this.inflight.add(key);
1357
+ this.awaitingTurn.set(key, this.hosts.agents.get(key)?.activityAt ?? 0);
1358
+ e.sending = true;
1359
+ delete e.error;
1360
+ this.save();
1361
+ try {
1362
+ await this.hosts.get(e.host).api.agents.ref(e.agent).send(e.text, {
1363
+ messageId: e.id,
1364
+ activeTurnBehavior: behavior,
1365
+ ...e.prepared
1366
+ });
1367
+ this.entries = this.entries.filter((item) => item !== e);
1368
+ } catch {
1369
+ this.awaitingTurn.delete(key);
1370
+ e.error = "Delivery outcome unknown. Check the conversation before sending again.";
1371
+ } finally {
1372
+ e.sending = false;
1373
+ this.inflight.delete(key);
1374
+ if (!this.closed) {
1375
+ this.save();
1376
+ this.tick();
1377
+ }
1378
+ }
1379
+ }
1380
+ close() {
1381
+ this.closed = true;
1382
+ for (const stop of this.stops) stop();
1383
+ }
1384
+ };
1168
1385
  // src/server/sse.ts
1169
1386
  const HEARTBEAT_MS = 2e4;
1170
1387
  /** Server-sent events over a plain fetch response, so the bearer header still authenticates. */
@@ -1731,6 +1948,26 @@ var Attachments = class {
1731
1948
  for (const id of ids) this.delete(id);
1732
1949
  }
1733
1950
  };
1951
+ // src/server/notification-preview.ts
1952
+ /** A bounded timeline read; never use the user's prompt or a previous turn as the preview. */
1953
+ async function notificationPreview(driver, agent, startedAt, endedAt) {
1954
+ const page = await driver.fetchAgentTimeline(agent, {
1955
+ direction: "tail",
1956
+ limit: 200,
1957
+ projection: "projected"
1958
+ });
1959
+ for (let i = page.entries.length - 1; i >= 0; i--) {
1960
+ const entry = page.entries[i];
1961
+ const at = Date.parse(entry.timestamp);
1962
+ if (endedAt && at > endedAt) continue;
1963
+ if (startedAt && at < startedAt) return null;
1964
+ if (entry.item.type === "user_message") return null;
1965
+ if (entry.item.type !== "assistant_message") continue;
1966
+ const text = entry.item.text?.replace(/\s+/g, " ").trim();
1967
+ if (text) return text.slice(0, 240);
1968
+ }
1969
+ return null;
1970
+ }
1734
1971
  // src/server/message-status.ts
1735
1972
  /** Positive evidence only. Missing, rewound, or out-of-window messages remain uncertain. */
1736
1973
  async function confirmedMessages(driver, agentId, ids, maxPages = 5) {
@@ -1807,12 +2044,14 @@ var Notifier = class {
1807
2044
  waiting = /* @__PURE__ */ new Set();
1808
2045
  recent = /* @__PURE__ */ new Map();
1809
2046
  now;
2047
+ replyPreview;
1810
2048
  constructor(options) {
1811
2049
  this.store = options.store;
1812
2050
  this.sender = options.sender;
1813
2051
  this.isViewing = options.isViewing;
1814
2052
  this.hostLabel = options.hostLabel;
1815
2053
  this.now = options.now ?? Date.now;
2054
+ this.replyPreview = options.replyPreview;
1816
2055
  }
1817
2056
  get waitingCount() {
1818
2057
  return this.waiting.size;
@@ -1827,11 +2066,11 @@ var Notifier = class {
1827
2066
  if (next.attention && !previous.attention || newPermission) {
1828
2067
  const permission = next.pendingPermissions[0];
1829
2068
  const what = permission ? permission.kind === "question" ? `asks: ${permission.title || permission.name}` : `wants to ${midSentence(permission.title || permission.name)}` : "is waiting for you";
1830
- this.emit("attention", next, `${next.project} · needs your input`, `${next.title || "Session"} ${what}`);
2069
+ this.emit("attention", next, `${next.project} · needs your input`, permission ? `The agent ${what}` : "The agent is waiting for your input.", permission ? void 0 : previous);
1831
2070
  } else if (previous.status === "running" && next.status !== "running") {
1832
2071
  if (this.now() - next.activityAt > STALE_MS) return;
1833
2072
  const failed = next.status === "error";
1834
- this.emit(failed ? "turn-failed" : "turn-done", next, `${next.project} · ${failed ? "turn failed" : "turn finished"}`, next.title || "Session");
2073
+ this.emit(failed ? "turn-failed" : "turn-done", next, `${next.project} · ${failed ? "turn failed" : "turn finished"}`, failed ? next.lastError || "The agent could not finish this turn." : "The agent finished this turn.", failed ? void 0 : previous);
1835
2074
  }
1836
2075
  }
1837
2076
  async test(sessionId) {
@@ -1846,12 +2085,27 @@ var Notifier = class {
1846
2085
  })));
1847
2086
  return subs.length;
1848
2087
  }
1849
- emit(kind, agent, title, body) {
2088
+ async emit(kind, agent, title, body, previous) {
1850
2089
  const dedupeKey = `${kind}:${agent.key}`;
1851
2090
  const now = this.now();
1852
2091
  if (now - (this.recent.get(dedupeKey) ?? -Infinity) < DEDUPE_MS) return;
1853
2092
  this.recent.set(dedupeKey, now);
1854
2093
  if (this.recent.size > 5e3) this.recent.clear();
2094
+ const pref = kind === "attention" ? "attention" : "turns";
2095
+ const subscriptions = this.store.pushSubscriptions().filter((s) => s.prefs[pref] && !this.isViewing(agent.key, s.sessionId));
2096
+ if (!subscriptions.length) return;
2097
+ if (previous && this.replyPreview) {
2098
+ let timer;
2099
+ try {
2100
+ const preview = await Promise.race([this.replyPreview(agent, previous), new Promise((resolve) => {
2101
+ timer = setTimeout(() => resolve(null), 5e3);
2102
+ timer.unref();
2103
+ })]);
2104
+ if (preview?.trim()) body = preview.replace(/\s+/g, " ").trim();
2105
+ } catch {} finally {
2106
+ clearTimeout(timer);
2107
+ }
2108
+ }
1855
2109
  const message = {
1856
2110
  title,
1857
2111
  body: `${body} — ${this.hostLabel(agent.hostId)}`.slice(0, 240),
@@ -1860,8 +2114,7 @@ var Notifier = class {
1860
2114
  kind,
1861
2115
  badge: this.waiting.size
1862
2116
  };
1863
- const pref = kind === "attention" ? "attention" : "turns";
1864
- for (const subscription of this.store.pushSubscriptions()) if (subscription.prefs[pref] && !this.isViewing(agent.key, subscription.sessionId)) this.deliver(subscription, message);
2117
+ for (const subscription of subscriptions) if (!this.isViewing(agent.key, subscription.sessionId)) this.deliver(subscription, message);
1865
2118
  }
1866
2119
  async deliver(subscription, message) {
1867
2120
  const session = this.store.sessionById(subscription.sessionId);
@@ -2664,12 +2917,14 @@ function createApp(store, hosts, token, webRoot, options = {}) {
2664
2917
  ...metrics
2665
2918
  })));
2666
2919
  const attachments = new Attachments();
2920
+ const sendQueue = new ServerSendQueue(store, hosts);
2667
2921
  const projectIcons = new IconCache();
2668
2922
  const viewers = /* @__PURE__ */ new Map();
2669
2923
  const notifier = new Notifier({
2670
2924
  store,
2671
2925
  sender: options.pushSender ?? webPushSender(store, options.pushSubject ?? "mailto:litepaseo@example.com"),
2672
2926
  isViewing: (key, sessionId) => (viewers.get(key)?.get(sessionId) ?? 0) > 0,
2927
+ replyPreview: (agent, previous) => notificationPreview(hosts.get(agent.hostId).driver, agent.id, previous.turnStartedAt, agent.attention ? void 0 : agent.activityAt),
2673
2928
  hostLabel: (id) => hosts.label(id) || store.hosts().find((h) => h.id === id)?.label || ""
2674
2929
  });
2675
2930
  hosts.onTransition((previous, next) => notifier.transition(previous, next));
@@ -2878,11 +3133,14 @@ function createApp(store, hosts, token, webRoot, options = {}) {
2878
3133
  version: VERSION,
2879
3134
  waiting: notifier.waitingCount
2880
3135
  }));
3136
+ /** The daemon stores custom project icons (Paseo's projectCustomIcon feature). */
3137
+ const customIcons = (hostId) => (hosts.clients.get(hostId)?.driver.getLastServerInfoMessage())?.features?.projectCustomIcon === true;
2881
3138
  const hostStates = () => store.hosts().map((h) => ({
2882
3139
  id: h.id,
2883
3140
  label: h.label,
2884
3141
  state: hosts.state(h.id),
2885
- diagnostic: hosts.diagnostic(h.id)
3142
+ diagnostic: hosts.diagnostic(h.id),
3143
+ ...customIcons(h.id) ? { customIcons: true } : {}
2886
3144
  }));
2887
3145
  app.get("/api/hosts", (c) => c.json(hostStates()));
2888
3146
  const directoryStreams = /* @__PURE__ */ new Set();
@@ -3197,15 +3455,22 @@ function createApp(store, hosts, token, webRoot, options = {}) {
3197
3455
  "Content-Disposition": "inline"
3198
3456
  });
3199
3457
  });
3200
- /** A project's icon (favicon/logo the daemon found in its root), cached briefly per host. */
3458
+ /**
3459
+ * A project's icon, cached briefly per host. With `project`, the daemon's effective icon (a
3460
+ * custom one if set; `v` is its revision, so a change is a new cache entry); otherwise the
3461
+ * favicon/logo found in `cwd`.
3462
+ */
3201
3463
  app.get("/api/hosts/:host/project-icon", async (c) => {
3202
3464
  const hostId = c.req.param("host");
3203
3465
  const cwd = z.string().min(1).max(4096).parse(c.req.query("cwd"));
3204
- const key = `${hostId}\n${cwd}`;
3466
+ const project = z.string().max(200).optional().parse(c.req.query("project") || void 0);
3467
+ const version = z.string().max(200).optional().parse(c.req.query("v") || void 0) ?? "";
3468
+ const key = project ? `${hostId}\np:${project}\n${version}` : `${hostId}\n${cwd}`;
3205
3469
  let icon = projectIcons.get(key);
3206
3470
  if (icon === void 0) {
3207
3471
  try {
3208
- const result = await hosts.get(hostId).driver.requestProjectIcon(cwd);
3472
+ const { driver } = hosts.get(hostId);
3473
+ const result = project && customIcons(hostId) ? await driver.getProjectIcon(project) : await driver.requestProjectIcon(cwd);
3209
3474
  icon = result.icon && /^image\/(png|jpeg|webp|gif|x-icon|vnd\.microsoft\.icon)$/.test(result.icon.mimeType) ? {
3210
3475
  data: Buffer.from(result.icon.data, "base64"),
3211
3476
  mimeType: result.icon.mimeType
@@ -3346,6 +3611,58 @@ function createApp(store, hosts, token, webRoot, options = {}) {
3346
3611
  }
3347
3612
  return c.json({ ok: true });
3348
3613
  });
3614
+ app.get("/api/hosts/:host/agents/:agent/queue", (c) => c.json(sendQueue.list(c.req.param("host"), c.req.param("agent"))));
3615
+ app.post("/api/hosts/:host/agents/:agent/queue", async (c) => {
3616
+ const input = z.object({
3617
+ id: z.string().uuid(),
3618
+ text: z.string().trim().max(1e5),
3619
+ attachmentIds: z.array(z.string().uuid()).max(4).default([])
3620
+ }).refine((v) => !!v.text || !!v.attachmentIds.length).parse(await c.req.json());
3621
+ const host = c.req.param("host"), agent = c.req.param("agent");
3622
+ hosts.get(host);
3623
+ if (sendQueue.accepted(host, agent, input.id)) return c.json({ ok: true });
3624
+ try {
3625
+ const attachmentNames = input.attachmentIds.map((id) => attachments.get(id, attachmentOwner(c), host, agent).name);
3626
+ const prepared = await attachments.prepare(hosts, attachmentOwner(c), host, agent, input.attachmentIds);
3627
+ sendQueue.add({
3628
+ id: input.id,
3629
+ text: input.text,
3630
+ host,
3631
+ agent,
3632
+ attachmentNames,
3633
+ prepared
3634
+ });
3635
+ attachments.consumed(input.attachmentIds);
3636
+ return c.json({ ok: true }, 201);
3637
+ } catch (error) {
3638
+ return c.json({ error: error.message }, 400);
3639
+ }
3640
+ });
3641
+ app.delete("/api/hosts/:host/agents/:agent/queue/:id", (c) => {
3642
+ try {
3643
+ sendQueue.remove(c.req.param("host"), c.req.param("agent"), c.req.param("id"));
3644
+ } catch (error) {
3645
+ return c.json({ error: error.message }, 409);
3646
+ }
3647
+ return c.json({ ok: true });
3648
+ });
3649
+ app.patch("/api/hosts/:host/agents/:agent/queue/:id", async (c) => {
3650
+ const { text } = z.object({ text: z.string().max(1e5) }).parse(await c.req.json());
3651
+ try {
3652
+ sendQueue.edit(c.req.param("host"), c.req.param("agent"), c.req.param("id"), text);
3653
+ } catch (error) {
3654
+ return c.json({ error: error.message }, 409);
3655
+ }
3656
+ return c.json({ ok: true });
3657
+ });
3658
+ app.post("/api/hosts/:host/agents/:agent/queue/:id/send", async (c) => {
3659
+ try {
3660
+ await sendQueue.interrupt(c.req.param("host"), c.req.param("agent"), c.req.param("id"));
3661
+ } catch (error) {
3662
+ return c.json({ error: error.message }, 409);
3663
+ }
3664
+ return c.json({ ok: true });
3665
+ });
3349
3666
  app.post("/api/hosts/:host/agents/:agent/messages/status", async (c) => {
3350
3667
  const { messageIds } = z.object({ messageIds: z.array(z.string().uuid()).min(1).max(20) }).parse(await c.req.json());
3351
3668
  const { driver } = hosts.get(c.req.param("host"));
@@ -3442,6 +3759,115 @@ function createApp(store, hosts, token, webRoot, options = {}) {
3442
3759
  await driver.archiveWorkspace(id);
3443
3760
  return c.json({ ok: true });
3444
3761
  });
3762
+ /** Removes the project from the daemon; its threads are archived (history stays on the host). */
3763
+ app.delete("/api/hosts/:host/projects/:project", async (c) => {
3764
+ const result = await hosts.get(c.req.param("host")).driver.removeProject(c.req.param("project"));
3765
+ return c.json({
3766
+ ok: true,
3767
+ removedWorkspaceIds: result.removedWorkspaceIds
3768
+ });
3769
+ });
3770
+ /**
3771
+ * Paseo's project edit: name and icon, decided together and saved once. Icon bytes are acquired
3772
+ * first (the step most likely to fail), then rename, then icon; a retry repeats the same calls.
3773
+ * A failure names the field it belongs to.
3774
+ */
3775
+ app.post("/api/hosts/:host/projects/:project/edit", async (c) => {
3776
+ const input = z.object({
3777
+ rename: z.object({ customName: z.string().trim().max(200).nullable() }).nullable(),
3778
+ icon: z.discriminatedUnion("type", [
3779
+ z.object({ type: z.literal("automatic") }),
3780
+ z.object({
3781
+ type: z.literal("upload"),
3782
+ data: z.string().min(1).max(Math.ceil(MAX_ICON_BYTES * 4 / 3) + 4)
3783
+ }),
3784
+ z.object({
3785
+ type: z.literal("url"),
3786
+ url: z.string().trim().min(1).max(4096)
3787
+ })
3788
+ ]).nullable()
3789
+ }).parse(await c.req.json());
3790
+ const hostId = c.req.param("host");
3791
+ const projectId = c.req.param("project");
3792
+ const { driver } = hosts.get(hostId);
3793
+ if (input.icon && !customIcons(hostId)) return c.json({
3794
+ error: "Update Paseo on this host to set project icons.",
3795
+ scope: "icon"
3796
+ }, 409);
3797
+ const failed = (scope, error) => c.json({
3798
+ error: error?.message || "Request failed",
3799
+ scope
3800
+ }, 422);
3801
+ let source = null;
3802
+ if (input.icon) try {
3803
+ source = input.icon.type === "url" ? {
3804
+ type: "upload",
3805
+ data: await importProjectIcon(input.icon.url)
3806
+ } : input.icon;
3807
+ } catch (error) {
3808
+ return failed("icon", error);
3809
+ }
3810
+ if (input.rename) try {
3811
+ await driver.renameProject(projectId, input.rename.customName || null);
3812
+ } catch (error) {
3813
+ return failed("name", error);
3814
+ }
3815
+ if (source) try {
3816
+ await driver.setProjectIcon(projectId, source);
3817
+ } catch (error) {
3818
+ return failed("icon", error);
3819
+ }
3820
+ return c.json({ ok: true });
3821
+ });
3822
+ const configErrors = {
3823
+ project_not_found: ["The selected host has no record of this project.", 404],
3824
+ invalid_project_config: ["paseo.json couldn’t be parsed. Fix the file on disk, then reload.", 422],
3825
+ stale_project_config: ["Config changed on disk. Reload to fetch the latest paseo.json before saving.", 409],
3826
+ write_failed: ["Couldn’t save paseo.json. Try again, or reload the latest version from disk.", 502]
3827
+ };
3828
+ const configState = (payload) => ({
3829
+ rootPath: payload.repoRoot,
3830
+ config: payload.config ?? null,
3831
+ revision: payload.revision,
3832
+ ...payload.hasUncommittedWorktreeSetupChanges ? { uncommittedSetup: true } : {}
3833
+ });
3834
+ /** The project's paseo.json (worktree setup/teardown, scripts, generation prompts). */
3835
+ app.get("/api/hosts/:host/project-config", async (c) => {
3836
+ const root = z.string().min(1).max(4096).parse(c.req.query("root"));
3837
+ const payload = await hosts.get(c.req.param("host")).driver.readProjectConfig(root);
3838
+ if (!payload.ok) {
3839
+ const [error, status] = configErrors[payload.error.code] ?? ["Could not read paseo.json.", 502];
3840
+ return c.json({
3841
+ error,
3842
+ code: payload.error.code
3843
+ }, status);
3844
+ }
3845
+ return c.json(configState(payload));
3846
+ });
3847
+ app.put("/api/hosts/:host/project-config", async (c) => {
3848
+ const input = z.object({
3849
+ root: z.string().min(1).max(4096),
3850
+ config: z.record(z.string(), z.unknown()),
3851
+ revision: z.object({
3852
+ mtimeMs: z.number(),
3853
+ size: z.number()
3854
+ }).nullable()
3855
+ }).parse(await c.req.json());
3856
+ if (JSON.stringify(input.config).length > 256e3) return c.json({ error: "paseo.json is too large." }, 413);
3857
+ const payload = await hosts.get(c.req.param("host")).driver.writeProjectConfig({
3858
+ repoRoot: input.root,
3859
+ config: input.config,
3860
+ expectedRevision: input.revision
3861
+ });
3862
+ if (!payload.ok) {
3863
+ const [error, status] = payload.error.code === "invalid_project_config" ? ["The host rejected this config: it does not match the paseo.json format.", 422] : configErrors[payload.error.code] ?? ["Could not write paseo.json.", 502];
3864
+ return c.json({
3865
+ error,
3866
+ code: payload.error.code
3867
+ }, status);
3868
+ }
3869
+ return c.json(configState(payload));
3870
+ });
3445
3871
  /**
3446
3872
  * next-input: the daemon appends a placeholder row after a completed turn; prediction runs only
3447
3873
  * when a client that shows the row asks. Only this one plugin method is reachable from here.
@@ -3552,6 +3978,7 @@ function createApp(store, hosts, token, webRoot, options = {}) {
3552
3978
  clearTimeout(agentFlush);
3553
3979
  clearTimeout(hostFlush);
3554
3980
  agentFlush = hostFlush = void 0;
3981
+ sendQueue.close();
3555
3982
  attachments.close();
3556
3983
  dictationStreams.close();
3557
3984
  }