teapot-coding-agent 0.36.5 → 0.36.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.
@@ -5,6 +5,7 @@ import { Hono } from "hono";
5
5
  import { serve, upgradeWebSocket } from "@hono/node-server";
6
6
  import { WebSocketServer } from "ws";
7
7
  import { existsSync, readFileSync } from "node:fs";
8
+ import { createHash } from "node:crypto";
8
9
  import { currentSkills } from "../agent/tools.js";
9
10
  import { readSkillFile } from "../agent/skills.js";
10
11
  import { detectImageTools, downscaleImage, widthName, MAX_EDGE } from "./image-resize.js";
@@ -1720,6 +1721,28 @@ export function buildApp(master) {
1720
1721
  // ---- web ui (built by vite into ./public; no bundler needed to serve) ----
1721
1722
  // works both from dist/server/api.js and src/server/api.ts: ../../public
1722
1723
  const webRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../public");
1724
+ /**
1725
+ * CACHE POLICY FOR THE APP SHELL — the two halves must be OPPOSITE.
1726
+ *
1727
+ * MEASURED against a running server: neither `index.html` nor `/assets/*` sent a `cache-control`
1728
+ * header at all. With no header a browser falls back to HEURISTIC freshness (typically
1729
+ * `10% × (now − Last-Modified)`), and the shell is the one file that must never be stale: it is
1730
+ * what names the hashed bundle. A cached `index.html` keeps pointing at the PREVIOUS
1731
+ * `index-<hash>.js`, so an update is installed, the server serves the new build, and the browser
1732
+ * silently keeps running the old frontend — reported as "もしかしてブラウザのキャッシュが効いてて
1733
+ * アップデートされたフロントエンドが完全に適用されてない?" after two rounds of UI fixes that did
1734
+ * not appear.
1735
+ *
1736
+ * `no-cache` does NOT mean "do not cache": it means "revalidate before use", so the shell costs
1737
+ * one conditional request (answered 304 from ETag/Last-Modified, which `c.body`/`c.html` supply)
1738
+ * and can never be the stale one.
1739
+ *
1740
+ * The hashed assets are the opposite case: their NAME changes with their content, so a year of
1741
+ * `immutable` is correct and free. This mirrors what the theme-image route already does above,
1742
+ * for the same reason.
1743
+ */
1744
+ const SHELL_CACHE = "no-cache";
1745
+ const ASSET_CACHE = "public, max-age=31536000, immutable";
1723
1746
  const mime = {
1724
1747
  ".html": "text/html",
1725
1748
  ".js": "text/javascript",
@@ -1735,14 +1758,44 @@ export function buildApp(master) {
1735
1758
  return null;
1736
1759
  }
1737
1760
  };
1738
- app.get("/", (c) => {
1761
+ /**
1762
+ * The shell's ETag, derived from its own bytes.
1763
+ *
1764
+ * `cache-control: no-cache` says "revalidate", and revalidation is only cheap if there is
1765
+ * something to revalidate AGAINST. MEASURED without one: the response carried neither `ETag` nor
1766
+ * `Last-Modified`, so every load re-downloaded the whole shell instead of getting a 304 — correct
1767
+ * but wasteful, and the shell is served on every page load and every deep link.
1768
+ *
1769
+ * Hashing the content (rather than a mtime) means a rebuilt-but-identical shell keeps its ETag,
1770
+ * so the 304 survives restarts, and any real change flips it. Computed once per process: the
1771
+ * build cannot change while a server is running, and a restart is what picks up a new build.
1772
+ */
1773
+ let shellEtag;
1774
+ const shellTag = (html) => {
1775
+ if (shellEtag === undefined || shellEtag === null)
1776
+ shellEtag = `"${createHash("sha256").update(html).digest("base64url").slice(0, 27)}"`;
1777
+ return shellEtag;
1778
+ };
1779
+ /** answer a shell request, honouring `If-None-Match` */
1780
+ const serveShell = (c) => {
1739
1781
  const html = indexHtml();
1740
- return html ? c.html(html) : c.text("web UI not built — run: pnpm build-web", 404);
1782
+ if (!html)
1783
+ return c.text("web UI not built — run: pnpm build-web", 404);
1784
+ const etag = shellTag(html);
1785
+ if (c.req.header("if-none-match") === etag)
1786
+ return new Response(null, { status: 304, headers: { etag } });
1787
+ return c.body(html, 200, {
1788
+ "content-type": "text/html; charset=UTF-8",
1789
+ "cache-control": SHELL_CACHE,
1790
+ etag,
1791
+ });
1792
+ };
1793
+ app.get("/", (c) => {
1794
+ return serveShell(c);
1741
1795
  });
1742
1796
  // SPA deep links: /session/<agentId> serves the app; the client routes it
1743
1797
  app.get("/session/*", (c) => {
1744
- const html = indexHtml();
1745
- return html ? c.html(html) : c.text("web UI not built — run: pnpm build-web", 404);
1798
+ return serveShell(c);
1746
1799
  });
1747
1800
  app.get("/assets/*", (c) => {
1748
1801
  const rel = c.req.path.replace("/assets/", "");
@@ -1750,6 +1803,7 @@ export function buildApp(master) {
1750
1803
  try {
1751
1804
  return c.body(readFileSync(file), 200, {
1752
1805
  "content-type": mime[path.extname(file)] ?? "application/octet-stream",
1806
+ "cache-control": ASSET_CACHE,
1753
1807
  });
1754
1808
  }
1755
1809
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.36.5",
3
+ "version": "0.36.6",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",