pi-web-ui 0.114.1 → 0.114.2

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 (117) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +187 -187
  3. package/README.zh-CN.md +227 -227
  4. package/README.zh-TW.md +227 -227
  5. package/bin/device-hub-cli.mjs +577 -577
  6. package/bin/frp-manager.mjs +1573 -1573
  7. package/bin/pi-device-hub.mjs +9 -9
  8. package/bin/pi-web-ui.mjs +4081 -4081
  9. package/deploy/nginx-subpath.conf +100 -100
  10. package/deploy/pi-web-ui.service +36 -36
  11. package/dist/server/agent-service.js +59 -10
  12. package/dist/server/attachments.js +6 -6
  13. package/dist/server/canvas/canvas-orchestrator.js +3 -3
  14. package/dist/server/communicate-tool.js +37 -11
  15. package/dist/server/compaction-instructions.js +8 -8
  16. package/dist/server/device-center/desktop-page.js +228 -228
  17. package/dist/server/device-center/hub-page.js +64 -64
  18. package/dist/server/device-center/native-desktop/macos.js +190 -190
  19. package/dist/server/device-center/native-desktop/windows.js +116 -116
  20. package/dist/server/dsh/runtime/cordis.yml +1 -1
  21. package/dist/server/dsh/runtime/custom-prompt.mjs +33 -33
  22. package/dist/server/dsh/runtime/goal-rpc.mjs +1309 -1309
  23. package/dist/server/dsh/runtime/launcher.mjs +235 -235
  24. package/dist/server/dsh/runtime/override.patch.yml +89 -89
  25. package/dist/server/dsh/runtime/runtime-root.mjs +405 -405
  26. package/dist/server/durable/durable-event-projector.js +19 -3
  27. package/dist/server/durable/durable-models.js +134 -65
  28. package/dist/server/eval-tool.js +135 -135
  29. package/dist/server/model-resolver.js +4 -1
  30. package/dist/server/patch-bash-process.js +89 -89
  31. package/dist/server/patch-tool.js +9 -9
  32. package/dist/server/patch-turn-end-boundary.js +3 -3
  33. package/dist/server/persona-chain.js +8 -8
  34. package/dist/server/remote-ssh-service.js +39 -39
  35. package/dist/server/schedule-agent-tool.js +11 -6
  36. package/dist/server/scheduler-tasks.js +84 -2
  37. package/dist/server/scm-commitmsg.js +10 -10
  38. package/dist/server/setup-page.js +620 -620
  39. package/dist/server/universal/universal-session.js +19 -18
  40. package/dist/server/vision-bridge.js +18 -18
  41. package/docs/device-center.md +148 -148
  42. package/docs/device-desktop.md +48 -48
  43. package/docs/dsh-engine.md +493 -493
  44. package/extensions/webui.ts +335 -335
  45. package/package.json +1 -1
  46. package/plugin-sdk/README.md +174 -174
  47. package/plugin-sdk/client-utils.mjs +279 -279
  48. package/plugin-sdk/import-check.mjs +210 -210
  49. package/plugin-sdk/index.d.ts +698 -698
  50. package/plugin-sdk/index.mjs +696 -696
  51. package/plugin-sdk/package.json +13 -13
  52. package/plugin-sdk/ssh-host-trust.mjs +225 -225
  53. package/themes/aetheris.css +501 -501
  54. package/themes/ayu-light.css +116 -116
  55. package/themes/bases/flow-base.css +1357 -1357
  56. package/themes/bases/obsidian-base.css +895 -895
  57. package/themes/bases/statusbar-flat-base.css +112 -112
  58. package/themes/bases/zhujian-base.css +688 -688
  59. package/themes/bases/zhupi-base.css +660 -660
  60. package/themes/catppuccin-latte.css +119 -119
  61. package/themes/catppuccin.css +116 -116
  62. package/themes/claude-code-dark.css +147 -147
  63. package/themes/codex.css +114 -114
  64. package/themes/cyberpunk.css +50 -50
  65. package/themes/dark-teal.css +264 -264
  66. package/themes/dazzle.css +38 -38
  67. package/themes/everforest-light.css +115 -115
  68. package/themes/flow-light.css +164 -164
  69. package/themes/flow.css +161 -161
  70. package/themes/geist.css +114 -114
  71. package/themes/gruvbox-light.css +115 -115
  72. package/themes/kanagawa-lotus.css +115 -115
  73. package/themes/md-preview.css +24 -24
  74. package/themes/mist.css +166 -166
  75. package/themes/nord.css +107 -107
  76. package/themes/one-dark.css +106 -106
  77. package/themes/paper.css +174 -174
  78. package/themes/rose-pine-dawn.css +114 -114
  79. package/themes/sakura.css +166 -166
  80. package/themes/solarized-light.css +114 -114
  81. package/themes/tokyo-night.css +115 -115
  82. package/themes/translucent.css +85 -85
  83. package/themes/transparent.css +116 -116
  84. package/themes/vs-code-dark.css +147 -147
  85. package/themes/wallpaper-flow.css +382 -382
  86. package/themes/wallpaper-obsidian.css +74 -74
  87. package/themes/white.css +164 -164
  88. package/themes/zhujian-dark.css +115 -115
  89. package/themes/zhujian.css +114 -114
  90. package/themes/zhupi-dark.css +115 -115
  91. package/themes/zhupi.css +114 -114
  92. package/web/dist/.build-assets.json +1 -1
  93. package/web/dist/assets/{BgTasksModal-BcXJ20RO.js → BgTasksModal-BIlQ89vr.js} +1 -1
  94. package/web/dist/assets/{BgTasksModal-DjQmiKnE.js → BgTasksModal-Ck2sjlPM.js} +1 -1
  95. package/web/dist/assets/{CanvasStudio-PI9pid0Y.js → CanvasStudio-B3W6b_rA.js} +1 -1
  96. package/web/dist/assets/{CanvasStudio-nf5-HxLM.js → CanvasStudio-Csv1Sj1-.js} +1 -1
  97. package/web/dist/assets/{DeviceCenter-CYttJw2a.js → DeviceCenter-BQdDcO8A.js} +1 -1
  98. package/web/dist/assets/{DeviceCenter-DPe4sz74.js → DeviceCenter-CHRKL0Vy.js} +1 -1
  99. package/web/dist/assets/{FilePreview-C9Ut4Lq6.js → FilePreview-B9xoU6ON.js} +1 -1
  100. package/web/dist/assets/{FilePreview-CvK3ZzX5.js → FilePreview-DUQpVZkH.js} +1 -1
  101. package/web/dist/assets/{GlobalSearchModal-C5e-OCw2.js → GlobalSearchModal-BXEGvUZq.js} +1 -1
  102. package/web/dist/assets/{GlobalSearchModal-H7pFK2UC.js → GlobalSearchModal-CnVPmfOI.js} +1 -1
  103. package/web/dist/assets/{GroupConversation-C2wNM0dQ.js → GroupConversation-CyIpQzDd.js} +1 -1
  104. package/web/dist/assets/{GroupConversation-ChN3TWQK.js → GroupConversation-DgYV3uYS.js} +1 -1
  105. package/web/dist/assets/{SCMPanel-buTGziDB.js → SCMPanel-imYI2Ecw.js} +1 -1
  106. package/web/dist/assets/{SCMPanel-kx-SCL2s.js → SCMPanel-sVZcV7dR.js} +1 -1
  107. package/web/dist/assets/{SettingsModal-BsUF8jqr.js → SettingsModal-Xw1Yoi3_.js} +1 -1
  108. package/web/dist/assets/{SettingsModal-D357Ky7P.js → SettingsModal-mb4e34-0.js} +1 -1
  109. package/web/dist/assets/{TerminalPanel-BBuM_Sez.js → TerminalPanel-CLkJJvxg.js} +1 -1
  110. package/web/dist/assets/{TerminalPanel-D6x6xz8Q.js → TerminalPanel-DpcIellm.js} +1 -1
  111. package/web/dist/assets/{TuiOverlayModal-CdbGV3Za.js → TuiOverlayModal-4-fFAZe7.js} +1 -1
  112. package/web/dist/assets/{TuiOverlayModal-d6x9u25n.js → TuiOverlayModal-DCu01lks.js} +1 -1
  113. package/web/dist/assets/{index-D6u8xH0o.js → index-Cdh3sibd.js} +4 -4
  114. package/web/dist/assets/{index-BPvpea8t.js → index-DWw_SxRq.js} +4 -4
  115. package/web/dist/index.html +29 -29
  116. package/web/dist/sw.js +179 -179
  117. package/web/public/sw.js +179 -179
@@ -1,27 +1,27 @@
1
- <!doctype html>
2
- <html lang="zh-CN">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <meta name="color-scheme" content="dark" />
7
- <link rel="icon" type="image/svg+xml" href="./favicon.svg" />
8
- <!-- PWA manifest: relative so nginx sub-path deployments (/pi/) resolve correctly -->
9
- <link rel="manifest" href="./manifest.webmanifest" crossorigin="use-credentials" />
10
- <meta name="theme-color" content="#0f172a" />
11
- <link rel="apple-touch-icon" href="./icons/icon-192.png" />
12
- <meta name="mobile-web-app-capable" content="yes" />
13
- <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
14
- <title>pi-web-ui — pi 编码智能体</title>
15
- <!-- 插件公共依赖 Import Maps(支持子路径反代部署) -->
16
-
17
- <script type="importmap">
18
- {
19
- "imports": {
20
- "@pi-web-ui/plugin-sdk/client": "./plugins-shared/client-utils.mjs"
21
- }
22
- }
1
+ <!doctype html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <meta name="color-scheme" content="dark" />
7
+ <link rel="icon" type="image/svg+xml" href="./favicon.svg" />
8
+ <!-- PWA manifest: relative so nginx sub-path deployments (/pi/) resolve correctly -->
9
+ <link rel="manifest" href="./manifest.webmanifest" crossorigin="use-credentials" />
10
+ <meta name="theme-color" content="#0f172a" />
11
+ <link rel="apple-touch-icon" href="./icons/icon-192.png" />
12
+ <meta name="mobile-web-app-capable" content="yes" />
13
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
14
+ <title>pi-web-ui — pi 编码智能体</title>
15
+ <!-- 插件公共依赖 Import Maps(支持子路径反代部署) -->
16
+
17
+ <script type="importmap">
18
+ {
19
+ "imports": {
20
+ "@pi-web-ui/plugin-sdk/client": "./plugins-shared/client-utils.mjs"
21
+ }
22
+ }
23
23
  </script>
24
- <script type="module" crossorigin src="./assets/index-D6u8xH0o.js"></script>
24
+ <script type="module" crossorigin src="./assets/index-Cdh3sibd.js"></script>
25
25
  <link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-hePW80VL.js">
26
26
  <link rel="modulepreload" crossorigin href="./assets/react-CR5VJ85Q.js">
27
27
  <link rel="modulepreload" crossorigin href="./assets/fi-DaSO0Q-m.js">
@@ -35,9 +35,9 @@
35
35
  <link rel="modulepreload" crossorigin href="./assets/markdown-BggnuQ4H.js">
36
36
  <link rel="stylesheet" crossorigin href="./assets/markdown-C8LL_u4z.css">
37
37
  <link rel="stylesheet" crossorigin href="./assets/index-DDZMv6LO.css">
38
- <meta name="pi-web-build-id" content="20261031T02480">
39
- </head>
40
- <body>
41
- <div id="root"></div>
42
- </body>
43
- </html>
38
+ <meta name="pi-web-build-id" content="20261031T04501">
39
+ </head>
40
+ <body>
41
+ <div id="root"></div>
42
+ </body>
43
+ </html>
package/web/dist/sw.js CHANGED
@@ -1,179 +1,179 @@
1
- /**
2
- * pi-web-ui — Progressive Web App service worker.
3
- *
4
- * Strategy overview
5
- * -----------------
6
- * pi-web-ui is a WebSocket-first app that needs a live backend, so we do NOT
7
- * try to make it fully offline. Instead the SW focuses on what makes it a
8
- * reliable *installable* PWA on mobile/desktop:
9
- *
10
- * - network-first for navigation requests (falls back to the cached app
11
- * shell when the network flaps), and
12
- * - cache-first for hashed static assets, which Vite fingerprints so a cache
13
- * hit is always the right version until a new deploy publishes new hashes.
14
- *
15
- * It also owns notification clicks (`notificationclick`): the desktop / OS
16
- * notifications posted from the page carry the page URL in `data.url`, and a
17
- * click must bring the app back — on Windows (and Linux) the click handler is
18
- * the only thing that can do that, otherwise the toast just disappears.
19
- *
20
- * Real-time / dynamic / credential-bearing routes (/ws, /api, /themes,
21
- * /plugins) are always fetched from the network and never cached, so we never
22
- * risk serving stale theme/plugin code or caching anything sensitive.
23
- */
24
-
25
- const BUILD_ID = "20261031T02480";
26
- const STATIC_CACHE = BUILD_ID.startsWith("__") ? "pi-web-ui-static-dev" : `pi-web-ui-static-${BUILD_ID}`;
27
- const SHELL_CACHE = "pi-web-ui-shell-v1";
28
-
29
- // App root within this origin — "/" for root deployments, "/pi/" behind an
30
- // nginx sub-path reverse proxy. All path checks below are relative to it, so
31
- // the worker behaves identically under either deployment layout.
32
- const SCOPE = new URL("./", self.registration.scope).pathname;
33
-
34
- /** Map a request pathname to an app-relative path ("/pi/ws" → "/ws"), or null
35
- * when the request lies outside the registration scope (shouldn't happen). */
36
- function appPath(pathname) {
37
- if (SCOPE === "/") return pathname;
38
- if (pathname.startsWith(SCOPE)) return "/" + pathname.slice(SCOPE.length);
39
- return null;
40
- }
41
-
42
- self.addEventListener("install", (event) => {
43
- // Take control as soon as this version activates so the current page is
44
- // served by the new worker without requiring a second reload.
45
- self.skipWaiting();
46
- event.waitUntil(caches.open(SHELL_CACHE));
47
- });
48
-
49
- self.addEventListener("activate", (event) => {
50
- event.waitUntil(
51
- caches
52
- .keys()
53
- .then((keys) =>
54
- Promise.all(keys.filter((k) => k !== STATIC_CACHE && k !== SHELL_CACHE).map((k) => caches.delete(k))),
55
- )
56
- // Apply to already-open pages immediately.
57
- .then(() => self.clients.claim()),
58
- );
59
- });
60
-
61
- // Only cache simple, safe GET requests. Everything else goes straight through.
62
- function isCachable(request) {
63
- const method = request.method;
64
- if (method !== "GET") return false;
65
-
66
- const url = new URL(request.url);
67
- if (url.origin !== self.location.origin) return false;
68
-
69
- // Never cache real-time, dynamic or credential/data endpoints.
70
- const path = appPath(url.pathname);
71
- if (
72
- path === null ||
73
- path.startsWith("/ws") ||
74
- path.startsWith("/api") ||
75
- path.startsWith("/themes") ||
76
- path.startsWith("/plugins")
77
- ) {
78
- return false;
79
- }
80
- return true;
81
- }
82
-
83
- function assetContentOk(requestUrl, response) {
84
- const ct = (response.headers.get("content-type") || "").toLowerCase();
85
- const path = requestUrl.pathname.toLowerCase();
86
- if (path.endsWith(".js")) return ct.includes("javascript");
87
- if (path.endsWith(".css")) return ct.includes("css");
88
- if (path.endsWith(".svg")) return ct.includes("svg");
89
- if (path.endsWith(".webmanifest")) return ct.includes("json");
90
- return true;
91
- }
92
-
93
- self.addEventListener("fetch", (event) => {
94
- const { request } = event;
95
- if (!isCachable(request)) {
96
- // Let the browser/backend handle WebSockets, API calls and cross-origin
97
- // requests normally.
98
- return;
99
- }
100
-
101
- const requestUrl = new URL(request.url);
102
-
103
- // Navigation → app shell. Network-first with cached fallback: users get the
104
- // latest build when online but can still reopen the app while flaky.
105
- if (request.mode === "navigate") {
106
- event.respondWith(
107
- fetch(request)
108
- .then((response) => {
109
- const copy = response.clone();
110
- caches.open(SHELL_CACHE).then((cache) => cache.put(request, copy));
111
- return response;
112
- })
113
- .catch(() => caches.match(request).then((cached) => cached || caches.match(SCOPE) || Response.error())),
114
- );
115
- return;
116
- }
117
-
118
- // Static assets (hashed by Vite) → cache-first.
119
- const path = appPath(requestUrl.pathname);
120
- const isStatic =
121
- path !== null &&
122
- (path.startsWith("/assets/") ||
123
- path.startsWith("/icons/") ||
124
- path === "/favicon.svg" ||
125
- path === "/icon.ico" ||
126
- path === "/manifest.webmanifest");
127
-
128
- if (isStatic) {
129
- event.respondWith(
130
- caches.match(request).then((cached) => {
131
- if (cached) return cached;
132
- return fetch(request)
133
- .then((response) => {
134
- // Only cache bytes matching the extension: a missing file falls
135
- // through to the SPA catch-all (index.html, 200) and must never be
136
- // stored under an asset URL, or the page stays black until purged.
137
- if (response && response.ok && assetContentOk(requestUrl, response)) {
138
- const copy = response.clone();
139
- caches.open(STATIC_CACHE).then((cache) => cache.put(request, copy));
140
- }
141
- return response;
142
- })
143
- .catch(() => caches.match(request).then((fallback) => fallback || Response.error()));
144
- }),
145
- );
146
- }
147
- });
148
-
149
- // ---------------------------------------------------------------------------
150
- // Notification clicks.
151
- //
152
- // The page posts desktop / OS notifications (see web/src/notify.ts) with
153
- // `data.url` = the URL that raised them. A click must bring the app back:
154
- // on Windows (and Linux) this handler is the only thing that can do that —
155
- // the toast would otherwise just disappear, which is why "nothing happens when
156
- // I click the reminder" is a platform-level dead end rather than a UI bug.
157
- // Focus the window that is already open (a tab or the installed PWA — a
158
- // minimised window still counts as open) and only open a new one when none
159
- // exists. Windows never restores a window for us, so we match on URL first so
160
- // the session that raised the notification is the one that comes forward.
161
- self.addEventListener("notificationclick", (event) => {
162
- event.notification.close();
163
- const target = (event.notification.data && event.notification.data.url) || new URL(SCOPE, self.location.origin).href;
164
-
165
- event.waitUntil(
166
- self.clients
167
- .matchAll({ type: "window", includeUncontrolled: true })
168
- .then((clients) => {
169
- const inScope = clients.filter((client) => appPath(new URL(client.url).pathname) !== null);
170
- const match = inScope.find((client) => client.url === target) || inScope[0];
171
- // focus() rejects when the browser refuses to raise the window
172
- // (rare); fall back to just returning the client so the click
173
- // never logs an unhandled rejection.
174
- if (match) return match.focus ? match.focus().catch(() => match) : match;
175
- return self.clients.openWindow(target);
176
- })
177
- .catch(() => undefined),
178
- );
179
- });
1
+ /**
2
+ * pi-web-ui — Progressive Web App service worker.
3
+ *
4
+ * Strategy overview
5
+ * -----------------
6
+ * pi-web-ui is a WebSocket-first app that needs a live backend, so we do NOT
7
+ * try to make it fully offline. Instead the SW focuses on what makes it a
8
+ * reliable *installable* PWA on mobile/desktop:
9
+ *
10
+ * - network-first for navigation requests (falls back to the cached app
11
+ * shell when the network flaps), and
12
+ * - cache-first for hashed static assets, which Vite fingerprints so a cache
13
+ * hit is always the right version until a new deploy publishes new hashes.
14
+ *
15
+ * It also owns notification clicks (`notificationclick`): the desktop / OS
16
+ * notifications posted from the page carry the page URL in `data.url`, and a
17
+ * click must bring the app back — on Windows (and Linux) the click handler is
18
+ * the only thing that can do that, otherwise the toast just disappears.
19
+ *
20
+ * Real-time / dynamic / credential-bearing routes (/ws, /api, /themes,
21
+ * /plugins) are always fetched from the network and never cached, so we never
22
+ * risk serving stale theme/plugin code or caching anything sensitive.
23
+ */
24
+
25
+ const BUILD_ID = "20261031T04501";
26
+ const STATIC_CACHE = BUILD_ID.startsWith("__") ? "pi-web-ui-static-dev" : `pi-web-ui-static-${BUILD_ID}`;
27
+ const SHELL_CACHE = "pi-web-ui-shell-v1";
28
+
29
+ // App root within this origin — "/" for root deployments, "/pi/" behind an
30
+ // nginx sub-path reverse proxy. All path checks below are relative to it, so
31
+ // the worker behaves identically under either deployment layout.
32
+ const SCOPE = new URL("./", self.registration.scope).pathname;
33
+
34
+ /** Map a request pathname to an app-relative path ("/pi/ws" → "/ws"), or null
35
+ * when the request lies outside the registration scope (shouldn't happen). */
36
+ function appPath(pathname) {
37
+ if (SCOPE === "/") return pathname;
38
+ if (pathname.startsWith(SCOPE)) return "/" + pathname.slice(SCOPE.length);
39
+ return null;
40
+ }
41
+
42
+ self.addEventListener("install", (event) => {
43
+ // Take control as soon as this version activates so the current page is
44
+ // served by the new worker without requiring a second reload.
45
+ self.skipWaiting();
46
+ event.waitUntil(caches.open(SHELL_CACHE));
47
+ });
48
+
49
+ self.addEventListener("activate", (event) => {
50
+ event.waitUntil(
51
+ caches
52
+ .keys()
53
+ .then((keys) =>
54
+ Promise.all(keys.filter((k) => k !== STATIC_CACHE && k !== SHELL_CACHE).map((k) => caches.delete(k))),
55
+ )
56
+ // Apply to already-open pages immediately.
57
+ .then(() => self.clients.claim()),
58
+ );
59
+ });
60
+
61
+ // Only cache simple, safe GET requests. Everything else goes straight through.
62
+ function isCachable(request) {
63
+ const method = request.method;
64
+ if (method !== "GET") return false;
65
+
66
+ const url = new URL(request.url);
67
+ if (url.origin !== self.location.origin) return false;
68
+
69
+ // Never cache real-time, dynamic or credential/data endpoints.
70
+ const path = appPath(url.pathname);
71
+ if (
72
+ path === null ||
73
+ path.startsWith("/ws") ||
74
+ path.startsWith("/api") ||
75
+ path.startsWith("/themes") ||
76
+ path.startsWith("/plugins")
77
+ ) {
78
+ return false;
79
+ }
80
+ return true;
81
+ }
82
+
83
+ function assetContentOk(requestUrl, response) {
84
+ const ct = (response.headers.get("content-type") || "").toLowerCase();
85
+ const path = requestUrl.pathname.toLowerCase();
86
+ if (path.endsWith(".js")) return ct.includes("javascript");
87
+ if (path.endsWith(".css")) return ct.includes("css");
88
+ if (path.endsWith(".svg")) return ct.includes("svg");
89
+ if (path.endsWith(".webmanifest")) return ct.includes("json");
90
+ return true;
91
+ }
92
+
93
+ self.addEventListener("fetch", (event) => {
94
+ const { request } = event;
95
+ if (!isCachable(request)) {
96
+ // Let the browser/backend handle WebSockets, API calls and cross-origin
97
+ // requests normally.
98
+ return;
99
+ }
100
+
101
+ const requestUrl = new URL(request.url);
102
+
103
+ // Navigation → app shell. Network-first with cached fallback: users get the
104
+ // latest build when online but can still reopen the app while flaky.
105
+ if (request.mode === "navigate") {
106
+ event.respondWith(
107
+ fetch(request)
108
+ .then((response) => {
109
+ const copy = response.clone();
110
+ caches.open(SHELL_CACHE).then((cache) => cache.put(request, copy));
111
+ return response;
112
+ })
113
+ .catch(() => caches.match(request).then((cached) => cached || caches.match(SCOPE) || Response.error())),
114
+ );
115
+ return;
116
+ }
117
+
118
+ // Static assets (hashed by Vite) → cache-first.
119
+ const path = appPath(requestUrl.pathname);
120
+ const isStatic =
121
+ path !== null &&
122
+ (path.startsWith("/assets/") ||
123
+ path.startsWith("/icons/") ||
124
+ path === "/favicon.svg" ||
125
+ path === "/icon.ico" ||
126
+ path === "/manifest.webmanifest");
127
+
128
+ if (isStatic) {
129
+ event.respondWith(
130
+ caches.match(request).then((cached) => {
131
+ if (cached) return cached;
132
+ return fetch(request)
133
+ .then((response) => {
134
+ // Only cache bytes matching the extension: a missing file falls
135
+ // through to the SPA catch-all (index.html, 200) and must never be
136
+ // stored under an asset URL, or the page stays black until purged.
137
+ if (response && response.ok && assetContentOk(requestUrl, response)) {
138
+ const copy = response.clone();
139
+ caches.open(STATIC_CACHE).then((cache) => cache.put(request, copy));
140
+ }
141
+ return response;
142
+ })
143
+ .catch(() => caches.match(request).then((fallback) => fallback || Response.error()));
144
+ }),
145
+ );
146
+ }
147
+ });
148
+
149
+ // ---------------------------------------------------------------------------
150
+ // Notification clicks.
151
+ //
152
+ // The page posts desktop / OS notifications (see web/src/notify.ts) with
153
+ // `data.url` = the URL that raised them. A click must bring the app back:
154
+ // on Windows (and Linux) this handler is the only thing that can do that —
155
+ // the toast would otherwise just disappear, which is why "nothing happens when
156
+ // I click the reminder" is a platform-level dead end rather than a UI bug.
157
+ // Focus the window that is already open (a tab or the installed PWA — a
158
+ // minimised window still counts as open) and only open a new one when none
159
+ // exists. Windows never restores a window for us, so we match on URL first so
160
+ // the session that raised the notification is the one that comes forward.
161
+ self.addEventListener("notificationclick", (event) => {
162
+ event.notification.close();
163
+ const target = (event.notification.data && event.notification.data.url) || new URL(SCOPE, self.location.origin).href;
164
+
165
+ event.waitUntil(
166
+ self.clients
167
+ .matchAll({ type: "window", includeUncontrolled: true })
168
+ .then((clients) => {
169
+ const inScope = clients.filter((client) => appPath(new URL(client.url).pathname) !== null);
170
+ const match = inScope.find((client) => client.url === target) || inScope[0];
171
+ // focus() rejects when the browser refuses to raise the window
172
+ // (rare); fall back to just returning the client so the click
173
+ // never logs an unhandled rejection.
174
+ if (match) return match.focus ? match.focus().catch(() => match) : match;
175
+ return self.clients.openWindow(target);
176
+ })
177
+ .catch(() => undefined),
178
+ );
179
+ });