tmux-weblink 3.2.1 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/apple-touch-icon-180.png +0 -0
- package/dist/assets/icon-192.png +0 -0
- package/dist/assets/icon-512.png +0 -0
- package/dist/assets/icon-maskable-192.png +0 -0
- package/dist/assets/icon-maskable-512.png +0 -0
- package/dist/assets/shell-client.js +68 -68
- package/dist/browser/bots-client.js +6 -6
- package/dist/index.js +3 -3
- package/dist/lib/bots/manager.js +4 -4
- package/dist/lib/build-app.js +26 -10
- package/dist/lib/pages/shell.js +16 -9
- package/package.json +3 -3
- package/scripts/generate-icons.mjs +136 -145
package/dist/lib/build-app.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
import{existsSync as P,readdirSync as
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import{existsSync as P,readdirSync as le,statSync as T,unlinkSync as me,writeFileSync as pe,mkdirSync as fe,readFileSync as z}from"node:fs";import{readFile as ge}from"node:fs/promises";import{execSync as C,execFileSync as L}from"node:child_process";import{tmuxEnv as he}from"./tmux-env.js";import h from"node:path";import{fileURLToPath as ye}from"node:url";import{Hono as je}from"hono";import{listSessions as D}from"../sessions.js";import{createRequire as we}from"node:module";import{getBotManager as ve}from"./bots/manager.js";import{registerBotRoutes as ke}from"./bots/routes.js";import{renderLoginPage as qe,renderNotesIndex as be,renderNotesPage as Se,renderSettings as Te,renderThemeSettings as Ae,renderHistoryIndex as xe,renderQuickCommandsPage as Ce,renderFilesIndex as Ie,renderShell as _e}from"../frontend.js";import{renderFederationPage as Ee}from"./pages/federation.js";import{createAgentToken as Oe,removeAgentToken as Ne,listAgentTokens as V}from"./agent-tokens.js";import{hashPassword as Re,verifyPassword as Pe,validatePassword as Le}from"./auth.js";import{atomicWriteFileSync as De}from"./atomicWrite.js";import{resolveFsPath as A,resolveFsRoots as Q,MAX_FILE_BYTES as K,walkRecursive as Fe,fsEntryCmp as X}from"./fs-access.js";import{captureSessionWindowsWithPath as He}from"./tmux-windows.js";import{audit as k}from"./auditLog.js";import{db as b}from"./db.js";import{getSessionAccessMap as Me}from"./session-access.js";import{listWindowHistory as Ue,clearWindowHistory as We}from"./window-history.js";import{saveSecurityConfig as Be}from"./security-config.js";import{ImageUploadError as Ge,saveUploadedImage as $e}from"./image-upload.js";import{readSettings as Z,writeSettings as ze}from"./settings.js";import{readActiveTheme as Ve,setActiveThemeTemplate as Y}from"./theme-store.js";import{isThemeTemplateId as J,THEME_TEMPLATE_IDS as Qe}from"./themes/index.js";import{pinView as Ke,unpinView as Xe,listPinnedViews as Ze}from"./pinned-views.js";import{getStoredWindows as Ye}from"./session-windows.js";import{buildSidebarSessions as Je}from"./sessions-sidebar.js";import{upsertSessionState as ee,removeSessionState as F,renameSessionState as H,computeTombstones as et,getSessionState as tt}from"./session-state.js";import{createQuickCommand as rt,deleteQuickCommand as nt,listQuickCommands as te,updateQuickCommand as st}from"./quick-commands.js";import{getSystemStatus as ot,getTopProcesses as it,killProcess as at}from"./system-monitor.js";import{newTmuxSession as re,renameSession as dt,killSession as ut,sessionExists as ct,TmuxWindowsError as ne}from"./tmux-windows.js";import{registerAgentTunnel as lt}from"./agent-tunnel.js";import{injectScopeScript as mt}from"./scope-script.js";const M="tmux-web-token",pt=365;function ft(x){return x==="127.0.0.1"||x==="::1"||x==="::ffff:127.0.0.1"}const gt=we(import.meta.url),{version:ht}=gt("../../package.json");function tr(x){const{mode:se,securityConfig:y,tokenStore:w,rateLimiter:_,settings:yt,terminalBufferConfig:E,getAgentId:U,state:l,federation:q,hub:f}=x,v=se==="agent";function I(e){if(y.security.trustProxy){const t=(e.req.header("x-forwarded-for")||"").split(",")[0].trim();if(t)return t}return e.env?.incoming?.socket?.remoteAddress||"unknown"}function O(e){const t=e.req.header("authorization");if(t?.startsWith("Bearer "))return t.slice(7);const r=e.req.header("cookie");if(!r)return null;const n=r.match(new RegExp(`(?:^|;\\s*)${M}=([^;]+)`));return n?decodeURIComponent(n[1]):null}function jt(e){const t=O(e);return t?w.validateToken(t):null}function W(e,t){const r=e.req.header("x-forwarded-proto")==="https"||e.req.url.startsWith("https:");e.header("Set-Cookie",`${M}=${encodeURIComponent(t)}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${pt*86400}${r?"; Secure":""}`)}function oe(e){e.header("Set-Cookie",`${M}=; Path=/; HttpOnly; SameSite=Lax; Max-Age=0`)}const i=()=>v?async(e,t)=>t():async(e,t)=>{const r=O(e);return!r||!w.validateToken(r)?(k("http_unauthorized",{ip:I(e)}),e.json({error:"unauthorized"},401)):t()},j=()=>v?async(e,t)=>t():async(e,t)=>{const r=O(e);if(!r||!w.validateToken(r)){const n=encodeURIComponent(e.req.url);return e.redirect(`/login?returnTo=${n}`,302)}return t()};function N(e){const t=D(),r=new Set(t.map(c=>c.name)),n=Je(t,Me(),Ze()),o=[],a=new Map,u=new Map;if(f)for(const c of f.agents.list()){const d=f.agents.get(c.agentId);a.set(c.agentId,new Set((d?d.sessions:[]).map(m=>m.name))),u.set(c.agentId,c.online),o.push({agentId:c.agentId,agentName:c.name,online:c.online,sessions:d?d.sessions:[]})}const g=et(r,a,u);return{...n,currentSession:e??null,agents:o,tombstones:g}}function B(e){const t=typeof e.sessionName=="string"?e.sessionName.trim():"";if(!t)return{error:"sessionName is required"};if(e.windowIndex===void 0)return{sessionName:t};const r=e.windowIndex;return typeof r!="number"||!Number.isInteger(r)||r<0?{error:"windowIndex must be a non-negative integer"}:{sessionName:t,windowIndex:r}}const s=new je;s.use("*",async(e,t)=>{await t(),(e.res.headers.get("content-type")||"").includes("text/html")&&e.header("Cache-Control","no-store"),e.header("X-Content-Type-Options","nosniff"),e.header("X-Frame-Options","DENY"),e.header("Content-Security-Policy",["default-src 'self'","script-src 'self' 'unsafe-inline'","style-src 'self' 'unsafe-inline' https://fonts.googleapis.com","connect-src 'self' ws: wss: http: https:","img-src 'self' data:","font-src 'self' https://fonts.gstatic.com","worker-src 'self' blob:"].join("; ")),e.header("Referrer-Policy","strict-origin-when-cross-origin")}),s.use("*",async(e,t)=>{const r=e.req.method;if(r==="GET"||r==="HEAD"||r==="OPTIONS")return t();const n=e.req.header("sec-fetch-site");return n&&n!=="same-origin"&&n!=="none"?e.text("cross-site request blocked",403):t()}),v||s.use("*",async(e,t)=>{if(await t(),e.req.method!=="GET"||e.req.path==="/login"||!(e.res.headers.get("content-type")??"").includes("text/html"))return;const n=await e.res.text();e.res=new Response(mt(n,{prefix:"",agentId:null}),e.res)});const G=h.dirname(ye(import.meta.url)),ie=[h.join(G,"..","assets"),h.join(G,"assets"),h.join(process.cwd(),"dist","assets")];s.get("/assets/:file",async e=>{const t=e.req.param("file");if(!/^[a-zA-Z0-9._-]+$/.test(t))return e.notFound();for(const r of ie){const n=h.join(r,t);if(!P(n))continue;const o=await ge(n),a=h.extname(t),u={".css":"text/css; charset=utf-8",".js":"application/javascript; charset=utf-8",".map":"application/json; charset=utf-8",".png":"image/png",".svg":"image/svg+xml",".webp":"image/webp",".ico":"image/x-icon"};return e.body(o,200,{"Content-Type":u[a]??"application/octet-stream","Cache-Control":a===".js"||a===".css"?"no-cache":"public, max-age=3600"})}return e.notFound()});const ae=`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
|
|
4
|
+
<stop offset="0" stop-color="#101620"/>
|
|
5
|
+
<stop offset="1" stop-color="#090c11"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<radialGradient id="glow" cx="46%" cy="50%" r="62%">
|
|
8
|
+
<stop offset="0" stop-color="#7dd3fc" stop-opacity="0.16"/>
|
|
9
|
+
<stop offset="1" stop-color="#7dd3fc" stop-opacity="0"/>
|
|
10
|
+
</radialGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
<rect width="64" height="64" rx="14" fill="url(#bg)"/>
|
|
13
|
+
<rect width="64" height="64" rx="14" fill="url(#glow)"/>
|
|
14
|
+
<path d="M19 24.3 29 32 19 39.7" fill="none" stroke="#7dd3fc" stroke-width="4.6" stroke-linecap="round" stroke-linejoin="round"/>
|
|
15
|
+
<line x1="35" y1="39.7" x2="45" y2="39.7" stroke="#7dd3fc" stroke-width="4.6" stroke-linecap="round"/>
|
|
16
|
+
</svg>`,$=e=>e.body(ae,200,{"Content-Type":"image/svg+xml; charset=utf-8","Cache-Control":"public, max-age=86400"});s.get("/favicon.svg",$),s.get("/favicon.ico",$),s.get("/manifest.json",async e=>{const t=await Ve();return e.json({id:"/",name:"tmux-weblink",short_name:"tmux-web",description:"Access your tmux sessions from the browser",start_url:"/",scope:"/",display:"standalone",display_override:["standalone","minimal-ui"],orientation:"any",background_color:t.shell.pageBg,theme_color:t.shell.panelBg,categories:["developer","productivity","utilities"],icons:[{src:"/assets/icon-192.png",sizes:"192x192",type:"image/png",purpose:"any"},{src:"/assets/icon-512.png",sizes:"512x512",type:"image/png",purpose:"any"},{src:"/assets/icon-maskable-192.png",sizes:"192x192",type:"image/png",purpose:"maskable"},{src:"/assets/icon-maskable-512.png",sizes:"512x512",type:"image/png",purpose:"maskable"}]},200,{"Cache-Control":"public, max-age=300"})});const de=`// tmux-weblink Service Worker
|
|
6
17
|
const CACHE = "tmux-weblink-v2";
|
|
7
|
-
const ASSETS = [
|
|
18
|
+
const ASSETS = [
|
|
19
|
+
"/", "/manifest.json", "/favicon.svg",
|
|
20
|
+
"/assets/icon-192.png", "/assets/icon-512.png",
|
|
21
|
+
"/assets/icon-maskable-192.png", "/assets/icon-maskable-512.png",
|
|
22
|
+
"/assets/apple-touch-icon-180.png",
|
|
23
|
+
];
|
|
8
24
|
self.addEventListener("install", (e) => {
|
|
9
25
|
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(ASSETS)));
|
|
10
26
|
self.skipWaiting();
|
|
@@ -18,7 +34,7 @@ self.addEventListener("activate", (e) => {
|
|
|
18
34
|
self.addEventListener("fetch", (e) => {
|
|
19
35
|
e.respondWith(fetch(e.request).catch(() => caches.match(e.request)));
|
|
20
36
|
});
|
|
21
|
-
`;o.get("/sw.js",e=>e.body(ue,200,{"Content-Type":"application/javascript; charset=utf-8"})),o.get("/login",e=>{const r=e.req.query("setup")==="1"?!0:!y.passwordHash,n=e.req.query("error");return e.html(Se({setupMode:r,error:n?decodeURIComponent(n):void 0,theme:l.activeTheme}))}),o.get("/",j(),e=>{const t=Q();return e.html(Ee({theme:l.activeTheme,version:gt,fsRoots:t,terminalCfg:E,scrollback:E.initialLines+2*E.historyChunk,wsBase:k&&U?.()?`/ws/a/${U()}`:void 0}))}),o.get("/notes",j(),e=>e.html(be(S.data.notes,l.activeTheme))),o.get("/notes/:session",j(),e=>{const t=decodeURIComponent(e.req.param("session"));return e.html(Te(t,l.activeTheme))}),o.get("/history",j(),e=>{const t=F(),r=new Set(t.map(n=>n.name));return e.html(Ce(We(),l.activeTheme,r))}),o.get("/quick-commands",j(),e=>e.html(Ie(te(),l.activeTheme))),o.get("/files",j(),e=>{const t=Q();return e.html(_e(l.activeTheme,t))}),o.post("/api/history/clear",i(),async e=>(await Be(),e.json({ok:!0}))),o.get("/api/quick-commands",i(),e=>e.json(te())),o.post("/api/quick-commands",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=await rt(t);return"error"in r?e.json({error:r.error},400):e.json(r,201)}),o.patch("/api/quick-commands/:id",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=await ot(e.req.param("id"),t);return"error"in r?e.json({error:r.error},r.status):e.json(r)}),o.delete("/api/quick-commands/:id",i(),e=>nt(e.req.param("id"))?e.json({ok:!0}):e.json({error:"not found"},404)),o.post("/api/auth/password",async e=>{if(k)return e.json({error:"hub only"},403);const t=I(e),r=_.check(t);if(!r.allowed)return v("rate_limited",{ip:t,retryAfterMs:r.retryAfterMs,permanentLock:r.permanentLock}),r.permanentLock?e.json({error:"Server locked after too many failed attempts",permanentLock:!0},403):e.json({error:"Too many attempts",retryAfterMs:r.retryAfterMs},429);let n;try{n=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const s=typeof n.password=="string"?n.password:"";if(!y.passwordHash){if(!y.security.allowRemoteSetup&&!pt(t))return v("setup_rejected_remote",{ip:t}),e.json({error:"First-run setup must be performed from localhost"},403);if(l.settingUpPassword)return e.json({error:"Password setup in progress"},409);const c=Fe(s);if(c)return e.json({error:c},400);l.settingUpPassword=!0;try{y.passwordHash=await Pe(s),$e(y),v("password_set",{ip:t})}finally{l.settingUpPassword=!1}const{plaintext:d}=w.createAccessToken("setup",y.security.tokenTtlDays);return W(e,d),e.json({ok:!0,token:d,setupMode:!0})}if(!await Le(s,y.passwordHash)){const c=_.recordFailure(t);return v("auth_failed",{ip:t,method:"password",failures:c.failures,permanentLock:c.permanentLock}),c.permanentLock?(w.revokeAll(),v("permanent_lock",{ip:t,failures:c.failures}),e.json({error:"Server locked after too many failed attempts",permanentLock:!0},403)):c.allowed?e.json({error:"Incorrect password"},401):e.json({error:"Too many attempts",retryAfterMs:c.retryAfterMs},429)}_.recordSuccess(t);const u=`browser-${t}`,{plaintext:h}=w.createAccessToken(u,y.security.tokenTtlDays);return W(e,h),v("auth_success",{ip:t,method:"password",tokenName:u}),e.json({ok:!0,token:h})}),o.post("/api/auth/token",i(),async e=>{if(k)return e.json({error:"hub only"},403);const t=I(e);let r;try{r=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const n=typeof r.name=="string"?r.name:`api-${t}`,s=typeof r.ttlDays=="number"?r.ttlDays:y.security.tokenTtlDays,{stored:a,plaintext:u}=w.createAccessToken(n,s);return v("token_created",{ip:t,name:a.name,tokenId:a.id}),e.json({id:a.id,name:a.name,token:u,expiresAt:a.expiresAt})}),o.get("/api/auth/tokens",i(),e=>k?e.json({error:"hub only"},403):e.json(w.list().map(t=>({id:t.id,name:t.name,createdAt:t.createdAt,lastUsedAt:t.lastUsedAt,expiresAt:t.expiresAt})))),o.delete("/api/auth/tokens/:id",i(),e=>k?e.json({error:"hub only"},403):w.revoke(e.req.param("id"))?(v("token_revoked",{ip:I(e),tokenId:e.req.param("id")}),e.json({ok:!0})):e.json({error:"not found"},404)),o.post("/api/auth/logout",i(),e=>(se(e),e.json({ok:!0}))),o.get("/settings",j(),async e=>{const t=await Z();return e.html(Ae({settings:t,theme:l.activeTheme,saved:e.req.query("saved")==="1",error:e.req.query("error")?decodeURIComponent(e.req.query("error")):void 0}))}),o.post("/settings",i(),async e=>{let t;try{t=await e.req.parseBody()}catch{return e.redirect("/settings?error="+encodeURIComponent("invalid form body"),303)}const r=await Z(),n=t.defaultView==="recent"?"recent":"default";return await Ve({...r,defaultView:n}),e.redirect("/settings?saved=1",303)}),o.get("/settings/theme",j(),e=>e.html(xe({theme:l.activeTheme,saved:e.req.query("saved")==="1"}))),o.post("/settings/theme",i(),async e=>{let t;try{t=await e.req.parseBody()}catch{return e.redirect("/settings/theme?error=1",303)}const r=t.template;return typeof r!="string"||!J(r)?e.redirect("/settings/theme",303):(l.activeTheme=await Y(r),e.redirect("/settings/theme?saved=1",303))});const ce={vscode:"VS Code",ghostty:"Ghostty","warm-clay":"Warm Clay","dark-cove":"Dark Cove"};o.get("/api/theme",i(),e=>e.json({active:l.activeTheme.template,templates:Qe.map(t=>({id:t,name:ce[t]}))})),o.post("/api/theme",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=t.template;return typeof r!="string"||!J(r)?e.json({error:"invalid theme template"},400):(l.activeTheme=await Y(r),e.json({ok:!0,active:l.activeTheme.template}))}),o.get("/api/system/status",i(),e=>e.json(st())),o.get("/api/system/processes",i(),e=>e.json(it())),q&&(o.get("/settings/federation",j(),e=>e.redirect("/settings/machines",301)),o.get("/settings/machines",j(),async e=>e.html(Oe({config:q.getConfig(),status:q.status(),tokens:V().map(t=>({id:t.id,name:t.name,createdAt:t.createdAt})),hostname:q.hostname},l.activeTheme))),o.get("/api/machines",i(),e=>e.json({config:q.getConfig(),status:q.status()})),o.post("/api/machines",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=typeof t.hub=="string"?t.hub.trim():"",n=typeof t.token=="string"?t.token.trim():"",s=typeof t.name=="string"?t.name.trim().slice(0,64):"",a=t.enabled===!0;if(a){if(!r)return e.json({error:"hub URL is required"},400);if(!/^wss?:\/\//i.test(r))return e.json({error:"hub URL must start with ws:// or wss://"},400);if(!n)return e.json({error:"registration token is required"},400)}const u={hub:r||void 0,token:n||void 0,name:s||void 0,enabled:a};return await q.setConfig(u),e.json({ok:!0,status:q.status()})}),o.get("/api/agent-tokens",i(),e=>e.json(V().map(t=>({id:t.id,name:t.name,createdAt:t.createdAt})))),o.post("/api/agent-tokens",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=typeof t.name=="string"?t.name.trim().slice(0,64):"";if(!r)return e.json({error:"name is required"},400);const{id:n,token:s}=Ne(r);return e.json({ok:!0,id:n,name:r,token:s})}),o.delete("/api/agent-tokens/:id",i(),e=>{const t=e.req.param("id");return Re(t)?e.json({ok:!0}):e.json({error:"no such token"},404)})),o.post("/api/system/kill",i(),async e=>{const{pid:t}=await e.req.json();if(typeof t!="number"||!Number.isInteger(t)||t<=0)return e.json({error:"invalid pid"},400);const r=at(t);return r.ok?e.json({ok:!0}):e.json({error:r.error},500)}),o.get("/api/agents",i(),e=>p?e.json(p.agents.list()):e.json([])),o.post("/api/sessions/new",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=typeof t.name=="string"?t.name.trim():"";if(!r)return e.json({error:"name is required"},400);if(!/^[a-zA-Z0-9_\-. ]+$/.test(r))return e.json({error:"name contains invalid characters"},400);const n=typeof t.dir=="string"&&t.dir.trim()?t.dir.trim():void 0;if(F().some(a=>a.name===r))return e.json({error:"session already exists"},409);try{return re(r,n),ee(r,{path:n}),e.json({ok:!0})}catch(a){const u=a instanceof ne?a.message:"failed to create session";return e.json({error:u},500)}}),o.post("/api/sessions/rename",i(),async e=>{try{const t=await e.req.json(),{oldName:r,newName:n}=t,s=typeof t.agentId=="string"?t.agentId:void 0;if(!r||!n)return e.json({error:"oldName and newName required"},400);if(!/^[a-zA-Z0-9_\-. ]+$/.test(n))return e.json({error:"invalid characters in name"},400);if(s){if(!p)return e.json({error:"not a hub"},400);const a=p.getChannel(s);return!a||!a.renameSession(r,n)?e.json({error:"agent offline"},409):(H(r,n,s),e.json({ok:!0,async:!0}))}return dt(r,n),H(r,n),e.json({ok:!0})}catch{return e.json({error:"rename failed"},500)}}),o.post("/api/sessions/kill",i(),async e=>{try{const t=await e.req.json(),{name:r}=t,n=typeof t.agentId=="string"?t.agentId:void 0;if(!r)return e.json({error:"name required"},400);if(n){if(!p)return e.json({error:"not a hub"},400);const s=p.getChannel(n);return!s||!s.killSession(r)?e.json({error:"agent offline"},409):(D(r,n),e.json({ok:!0,async:!0}))}return ut(r),D(r),e.json({ok:!0})}catch{return e.json({error:"kill failed"},500)}}),o.post("/api/sessions/rebuild",i(),async e=>{try{const t=await e.req.json(),r=typeof t.name=="string"?t.name.trim():"";if(!r)return e.json({error:"name required"},400);const n=typeof t.agentId=="string"?t.agentId:void 0,a=tt().find(u=>u.name===r&&(u.agentId??null)===(n??null))?.path;if(n){if(!p)return e.json({error:"not a hub"},400);const u=p.getChannel(n);return u?u.rebuildSession(r,a)?e.json({ok:!0,async:!0}):e.json({error:"agent offline"},409):e.json({error:"agent offline"},409)}if(ct(r))return e.json({error:"session already exists"},409);try{re(r,a)}catch(u){const h=u instanceof ne?u.message:"rebuild failed";return e.json({error:h},500)}return ee(r,{path:a}),e.json({ok:!0})}catch{return e.json({error:"rebuild failed"},500)}}),o.post("/api/sessions/dismiss",i(),async e=>{try{const t=await e.req.json(),r=typeof t.name=="string"?t.name.trim():"";if(!r)return e.json({error:"name required"},400);const n=typeof t.agentId=="string"?t.agentId:void 0;return D(r,n),e.json({ok:!0})}catch{return e.json({error:"dismiss failed"},500)}}),o.post("/api/sessions/rename-tombstone",i(),async e=>{try{const t=await e.req.json(),r=typeof t.oldName=="string"?t.oldName.trim():"",n=typeof t.newName=="string"?t.newName.trim():"";if(!r||!n)return e.json({error:"oldName and newName required"},400);if(!/^[a-zA-Z0-9_\-. ]+$/.test(n))return e.json({error:"invalid characters in name"},400);const s=typeof t.agentId=="string"?t.agentId:void 0;return H(r,n,s),e.json({ok:!0})}catch{return e.json({error:"rename failed"},500)}}),o.get("/api/session-program",i(),e=>{const t=e.req.query("session");if(!t)return e.json({program:null});try{const n=L("tmux",["display-message","-p","-t",t,"#{pane_current_command}"],{encoding:"utf-8",timeout:3e3,env:ye()}).trim()||null;return e.json({program:n})}catch{return e.json({program:null})}}),o.post("/api/session/:name/upload",i(),async e=>{try{const r=(await e.req.parseBody()).file;if(!(r instanceof File))return e.json({error:'expected a file field named "file"'},400);const n=Buffer.from(await r.arrayBuffer()),{path:s}=await ze(n,r.type,r.name);return e.json({path:s})}catch(t){return t instanceof Ge?e.json({error:t.message},t.status):e.json({error:"upload failed"},500)}}),o.get("/api/fs/session-path",i(),e=>{const t=e.req.query("session");if(!t)return e.json({path:process.env.HOME??"/"});try{const r=Me(t),s=r.find(a=>a.active)?.path??r[0]?.path??process.env.HOME??"/";return e.json({path:s})}catch{return e.json({path:process.env.HOME??"/"})}}),o.get("/api/fs/list",i(),e=>{const t=process.env.HOME??"/";let r=e.req.query("path")??t;r.startsWith("~")&&(r=t+r.slice(1)),r.startsWith("/")||(r=g.join(t,r));const n=e.req.query("recursive")==="true";let s=r,a="",u=r.endsWith("/");if(!u)try{u=T(r).isDirectory()}catch{}u||(s=g.dirname(r),a=g.basename(r).toLowerCase());try{const h=me(s),c=[],d=[];for(const m of h)if(!(a&&!m.toLowerCase().startsWith(a))){try{const f=g.join(s,m);T(f).isDirectory()?(c.push(f),n&&He(f,c,d,0)):d.push(f)}catch{}if(c.length+d.length>=5e3)break}return c.sort(X),d.sort(X),e.json({dirs:c,files:d,path:s})}catch{return e.json({dirs:[],files:[]})}});function le(e){const t={repoRoot:null,branch:null,files:[],linesAdded:0,linesRemoved:0};try{const r=C("git rev-parse --show-toplevel 2>/dev/null",{cwd:e,encoding:"utf-8",timeout:3e3}).trim();if(!r)return t;let n;try{n=C("git branch --show-current 2>/dev/null",{cwd:r,encoding:"utf-8",timeout:3e3}).trim()}catch{n=C("git rev-parse --short HEAD 2>/dev/null",{cwd:r,encoding:"utf-8",timeout:3e3}).trim()}n||(n="HEAD");let s="";try{s=C("git status --porcelain 2>/dev/null",{cwd:r,encoding:"utf-8",timeout:3e3})}catch{}const a=[];for(const d of s.split(`
|
|
22
|
-
`)){if(!d.trim())continue;const m=d[0],
|
|
23
|
-
`)){if(!m.trim())continue;const
|
|
24
|
-
`).length;d.additions=
|
|
37
|
+
`;s.get("/sw.js",e=>e.body(de,200,{"Content-Type":"application/javascript; charset=utf-8"})),s.get("/login",e=>{const r=e.req.query("setup")==="1"?!0:!y.passwordHash,n=e.req.query("error");return e.html(qe({setupMode:r,error:n?decodeURIComponent(n):void 0,theme:l.activeTheme}))}),s.get("/",j(),e=>{const t=Q();return e.html(_e({theme:l.activeTheme,version:ht,fsRoots:t,terminalCfg:E,scrollback:E.initialLines+2*E.historyChunk,wsBase:v&&U?.()?`/ws/a/${U()}`:void 0}))}),s.get("/notes",j(),e=>e.html(be(b.data.notes,l.activeTheme))),s.get("/notes/:session",j(),e=>{const t=decodeURIComponent(e.req.param("session"));return e.html(Se(t,l.activeTheme))}),s.get("/history",j(),e=>{const t=D(),r=new Set(t.map(n=>n.name));return e.html(xe(Ue(),l.activeTheme,r))}),s.get("/quick-commands",j(),e=>e.html(Ce(te(),l.activeTheme))),s.get("/files",j(),e=>{const t=Q();return e.html(Ie(l.activeTheme,t))}),s.post("/api/history/clear",i(),async e=>(await We(),e.json({ok:!0}))),s.get("/api/quick-commands",i(),e=>e.json(te())),s.post("/api/quick-commands",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=await rt(t);return"error"in r?e.json({error:r.error},400):e.json(r,201)}),s.patch("/api/quick-commands/:id",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=await st(e.req.param("id"),t);return"error"in r?e.json({error:r.error},r.status):e.json(r)}),s.delete("/api/quick-commands/:id",i(),e=>nt(e.req.param("id"))?e.json({ok:!0}):e.json({error:"not found"},404)),s.post("/api/auth/password",async e=>{if(v)return e.json({error:"hub only"},403);const t=I(e),r=_.check(t);if(!r.allowed)return k("rate_limited",{ip:t,retryAfterMs:r.retryAfterMs,permanentLock:r.permanentLock}),r.permanentLock?e.json({error:"Server locked after too many failed attempts",permanentLock:!0},403):e.json({error:"Too many attempts",retryAfterMs:r.retryAfterMs},429);let n;try{n=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const o=typeof n.password=="string"?n.password:"";if(!y.passwordHash){if(!y.security.allowRemoteSetup&&!ft(t))return k("setup_rejected_remote",{ip:t}),e.json({error:"First-run setup must be performed from localhost"},403);if(l.settingUpPassword)return e.json({error:"Password setup in progress"},409);const c=Le(o);if(c)return e.json({error:c},400);l.settingUpPassword=!0;try{y.passwordHash=await Re(o),Be(y),k("password_set",{ip:t})}finally{l.settingUpPassword=!1}const{plaintext:d}=w.createAccessToken("setup",y.security.tokenTtlDays);return W(e,d),e.json({ok:!0,token:d,setupMode:!0})}if(!await Pe(o,y.passwordHash)){const c=_.recordFailure(t);return k("auth_failed",{ip:t,method:"password",failures:c.failures,permanentLock:c.permanentLock}),c.permanentLock?(w.revokeAll(),k("permanent_lock",{ip:t,failures:c.failures}),e.json({error:"Server locked after too many failed attempts",permanentLock:!0},403)):c.allowed?e.json({error:"Incorrect password"},401):e.json({error:"Too many attempts",retryAfterMs:c.retryAfterMs},429)}_.recordSuccess(t);const u=`browser-${t}`,{plaintext:g}=w.createAccessToken(u,y.security.tokenTtlDays);return W(e,g),k("auth_success",{ip:t,method:"password",tokenName:u}),e.json({ok:!0,token:g})}),s.post("/api/auth/token",i(),async e=>{if(v)return e.json({error:"hub only"},403);const t=I(e);let r;try{r=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const n=typeof r.name=="string"?r.name:`api-${t}`,o=typeof r.ttlDays=="number"?r.ttlDays:y.security.tokenTtlDays,{stored:a,plaintext:u}=w.createAccessToken(n,o);return k("token_created",{ip:t,name:a.name,tokenId:a.id}),e.json({id:a.id,name:a.name,token:u,expiresAt:a.expiresAt})}),s.get("/api/auth/tokens",i(),e=>v?e.json({error:"hub only"},403):e.json(w.list().map(t=>({id:t.id,name:t.name,createdAt:t.createdAt,lastUsedAt:t.lastUsedAt,expiresAt:t.expiresAt})))),s.delete("/api/auth/tokens/:id",i(),e=>v?e.json({error:"hub only"},403):w.revoke(e.req.param("id"))?(k("token_revoked",{ip:I(e),tokenId:e.req.param("id")}),e.json({ok:!0})):e.json({error:"not found"},404)),s.post("/api/auth/logout",i(),e=>(oe(e),e.json({ok:!0}))),s.get("/settings",j(),async e=>{const t=await Z();return e.html(Te({settings:t,theme:l.activeTheme,saved:e.req.query("saved")==="1",error:e.req.query("error")?decodeURIComponent(e.req.query("error")):void 0}))}),s.post("/settings",i(),async e=>{let t;try{t=await e.req.parseBody()}catch{return e.redirect("/settings?error="+encodeURIComponent("invalid form body"),303)}const r=await Z(),n=t.defaultView==="recent"?"recent":"default";return await ze({...r,defaultView:n}),e.redirect("/settings?saved=1",303)}),s.get("/settings/theme",j(),e=>e.html(Ae({theme:l.activeTheme,saved:e.req.query("saved")==="1"}))),s.post("/settings/theme",i(),async e=>{let t;try{t=await e.req.parseBody()}catch{return e.redirect("/settings/theme?error=1",303)}const r=t.template;return typeof r!="string"||!J(r)?e.redirect("/settings/theme",303):(l.activeTheme=await Y(r),e.redirect("/settings/theme?saved=1",303))});const ue={vscode:"VS Code",ghostty:"Ghostty","warm-clay":"Warm Clay","dark-cove":"Dark Cove"};s.get("/api/theme",i(),e=>e.json({active:l.activeTheme.template,templates:Qe.map(t=>({id:t,name:ue[t]}))})),s.post("/api/theme",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=t.template;return typeof r!="string"||!J(r)?e.json({error:"invalid theme template"},400):(l.activeTheme=await Y(r),e.json({ok:!0,active:l.activeTheme.template}))}),s.get("/api/system/status",i(),e=>e.json(ot())),s.get("/api/system/processes",i(),e=>e.json(it())),q&&(s.get("/settings/federation",j(),e=>e.redirect("/settings/machines",301)),s.get("/settings/machines",j(),async e=>e.html(Ee({config:q.getConfig(),status:q.status(),tokens:V().map(t=>({id:t.id,name:t.name,createdAt:t.createdAt})),hostname:q.hostname},l.activeTheme))),s.get("/api/machines",i(),e=>e.json({config:q.getConfig(),status:q.status()})),s.post("/api/machines",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=typeof t.hub=="string"?t.hub.trim():"",n=typeof t.token=="string"?t.token.trim():"",o=typeof t.name=="string"?t.name.trim().slice(0,64):"",a=t.enabled===!0;if(a){if(!r)return e.json({error:"hub URL is required"},400);if(!/^wss?:\/\//i.test(r))return e.json({error:"hub URL must start with ws:// or wss://"},400);if(!n)return e.json({error:"registration token is required"},400)}const u={hub:r||void 0,token:n||void 0,name:o||void 0,enabled:a};return await q.setConfig(u),e.json({ok:!0,status:q.status()})}),s.get("/api/agent-tokens",i(),e=>e.json(V().map(t=>({id:t.id,name:t.name,createdAt:t.createdAt})))),s.post("/api/agent-tokens",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=typeof t.name=="string"?t.name.trim().slice(0,64):"";if(!r)return e.json({error:"name is required"},400);const{id:n,token:o}=Oe(r);return e.json({ok:!0,id:n,name:r,token:o})}),s.delete("/api/agent-tokens/:id",i(),e=>{const t=e.req.param("id");return Ne(t)?e.json({ok:!0}):e.json({error:"no such token"},404)})),s.post("/api/system/kill",i(),async e=>{const{pid:t}=await e.req.json();if(typeof t!="number"||!Number.isInteger(t)||t<=0)return e.json({error:"invalid pid"},400);const r=at(t);return r.ok?e.json({ok:!0}):e.json({error:r.error},500)}),s.get("/api/agents",i(),e=>f?e.json(f.agents.list()):e.json([])),s.post("/api/sessions/new",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=typeof t.name=="string"?t.name.trim():"";if(!r)return e.json({error:"name is required"},400);if(!/^[a-zA-Z0-9_\-. ]+$/.test(r))return e.json({error:"name contains invalid characters"},400);const n=typeof t.dir=="string"&&t.dir.trim()?t.dir.trim():void 0;if(D().some(a=>a.name===r))return e.json({error:"session already exists"},409);try{return re(r,n),ee(r,{path:n}),e.json({ok:!0})}catch(a){const u=a instanceof ne?a.message:"failed to create session";return e.json({error:u},500)}}),s.post("/api/sessions/rename",i(),async e=>{try{const t=await e.req.json(),{oldName:r,newName:n}=t,o=typeof t.agentId=="string"?t.agentId:void 0;if(!r||!n)return e.json({error:"oldName and newName required"},400);if(!/^[a-zA-Z0-9_\-. ]+$/.test(n))return e.json({error:"invalid characters in name"},400);if(o){if(!f)return e.json({error:"not a hub"},400);const a=f.getChannel(o);return!a||!a.renameSession(r,n)?e.json({error:"agent offline"},409):(H(r,n,o),e.json({ok:!0,async:!0}))}return dt(r,n),H(r,n),e.json({ok:!0})}catch{return e.json({error:"rename failed"},500)}}),s.post("/api/sessions/kill",i(),async e=>{try{const t=await e.req.json(),{name:r}=t,n=typeof t.agentId=="string"?t.agentId:void 0;if(!r)return e.json({error:"name required"},400);if(n){if(!f)return e.json({error:"not a hub"},400);const o=f.getChannel(n);return!o||!o.killSession(r)?e.json({error:"agent offline"},409):(F(r,n),e.json({ok:!0,async:!0}))}return ut(r),F(r),e.json({ok:!0})}catch{return e.json({error:"kill failed"},500)}}),s.post("/api/sessions/rebuild",i(),async e=>{try{const t=await e.req.json(),r=typeof t.name=="string"?t.name.trim():"";if(!r)return e.json({error:"name required"},400);const n=typeof t.agentId=="string"?t.agentId:void 0,a=tt().find(u=>u.name===r&&(u.agentId??null)===(n??null))?.path;if(n){if(!f)return e.json({error:"not a hub"},400);const u=f.getChannel(n);return u?u.rebuildSession(r,a)?e.json({ok:!0,async:!0}):e.json({error:"agent offline"},409):e.json({error:"agent offline"},409)}if(ct(r))return e.json({error:"session already exists"},409);try{re(r,a)}catch(u){const g=u instanceof ne?u.message:"rebuild failed";return e.json({error:g},500)}return ee(r,{path:a}),e.json({ok:!0})}catch{return e.json({error:"rebuild failed"},500)}}),s.post("/api/sessions/dismiss",i(),async e=>{try{const t=await e.req.json(),r=typeof t.name=="string"?t.name.trim():"";if(!r)return e.json({error:"name required"},400);const n=typeof t.agentId=="string"?t.agentId:void 0;return F(r,n),e.json({ok:!0})}catch{return e.json({error:"dismiss failed"},500)}}),s.post("/api/sessions/rename-tombstone",i(),async e=>{try{const t=await e.req.json(),r=typeof t.oldName=="string"?t.oldName.trim():"",n=typeof t.newName=="string"?t.newName.trim():"";if(!r||!n)return e.json({error:"oldName and newName required"},400);if(!/^[a-zA-Z0-9_\-. ]+$/.test(n))return e.json({error:"invalid characters in name"},400);const o=typeof t.agentId=="string"?t.agentId:void 0;return H(r,n,o),e.json({ok:!0})}catch{return e.json({error:"rename failed"},500)}}),s.get("/api/session-program",i(),e=>{const t=e.req.query("session");if(!t)return e.json({program:null});try{const n=L("tmux",["display-message","-p","-t",t,"#{pane_current_command}"],{encoding:"utf-8",timeout:3e3,env:he()}).trim()||null;return e.json({program:n})}catch{return e.json({program:null})}}),s.post("/api/session/:name/upload",i(),async e=>{try{const r=(await e.req.parseBody()).file;if(!(r instanceof File))return e.json({error:'expected a file field named "file"'},400);const n=Buffer.from(await r.arrayBuffer()),{path:o}=await $e(n,r.type,r.name);return e.json({path:o})}catch(t){return t instanceof Ge?e.json({error:t.message},t.status):e.json({error:"upload failed"},500)}}),s.get("/api/fs/session-path",i(),e=>{const t=e.req.query("session");if(!t)return e.json({path:process.env.HOME??"/"});try{const r=He(t),o=r.find(a=>a.active)?.path??r[0]?.path??process.env.HOME??"/";return e.json({path:o})}catch{return e.json({path:process.env.HOME??"/"})}}),s.get("/api/fs/list",i(),e=>{const t=process.env.HOME??"/";let r=e.req.query("path")??t;r.startsWith("~")&&(r=t+r.slice(1)),r.startsWith("/")||(r=h.join(t,r));const n=e.req.query("recursive")==="true";let o=r,a="",u=r.endsWith("/");if(!u)try{u=T(r).isDirectory()}catch{}u||(o=h.dirname(r),a=h.basename(r).toLowerCase());try{const g=le(o),c=[],d=[];for(const m of g)if(!(a&&!m.toLowerCase().startsWith(a))){try{const p=h.join(o,m);T(p).isDirectory()?(c.push(p),n&&Fe(p,c,d,0)):d.push(p)}catch{}if(c.length+d.length>=5e3)break}return c.sort(X),d.sort(X),e.json({dirs:c,files:d,path:o})}catch{return e.json({dirs:[],files:[]})}});function ce(e){const t={repoRoot:null,branch:null,files:[],linesAdded:0,linesRemoved:0};try{const r=C("git rev-parse --show-toplevel 2>/dev/null",{cwd:e,encoding:"utf-8",timeout:3e3}).trim();if(!r)return t;let n;try{n=C("git branch --show-current 2>/dev/null",{cwd:r,encoding:"utf-8",timeout:3e3}).trim()}catch{n=C("git rev-parse --short HEAD 2>/dev/null",{cwd:r,encoding:"utf-8",timeout:3e3}).trim()}n||(n="HEAD");let o="";try{o=C("git status --porcelain 2>/dev/null",{cwd:r,encoding:"utf-8",timeout:3e3})}catch{}const a=[];for(const d of o.split(`
|
|
38
|
+
`)){if(!d.trim())continue;const m=d[0],p=d[1],S=d.substring(3).trim(),R=p!==" "?p:m;a.push({path:S,status:R,staged:m,unstaged:p,additions:0,deletions:0})}const u=new Map;try{const d=C("git diff --numstat HEAD 2>/dev/null",{cwd:r,encoding:"utf-8",timeout:3e3});for(const m of d.split(`
|
|
39
|
+
`)){if(!m.trim())continue;const p=m.split(" ");if(p.length>=3){const S=parseInt(p[0],10)||0,R=parseInt(p[1],10)||0;u.set(p[2],{added:S,deleted:R})}}}catch{}for(const d of a){const m=u.get(d.path);m&&(d.additions=m.added,d.deletions=m.deleted)}let g=0,c=0;for(const d of a)g+=d.additions,c+=d.deletions;for(const d of a)if(d.status==="?"&&d.additions===0)try{const m=h.join(r,d.path),S=z(m,"utf-8").split(`
|
|
40
|
+
`).length;d.additions=S,g+=S}catch{}return{repoRoot:r,branch:n,files:a,linesAdded:g,linesRemoved:c}}catch{return t}}if(s.get("/api/git/status",i(),e=>{const t=e.req.query("path");if(!t)return e.json({error:"path is required"},400);try{const r=A(t),n=ce(r);return e.json(n)}catch(r){return r.message==="FS_ROOTS_NOT_CONFIGURED"?e.json({error:"file access not configured"},403):r.message==="PATH_NOT_ALLOWED"?e.json({error:"path not allowed"},403):e.json({repoRoot:null,branch:null,files:[],linesAdded:0,linesRemoved:0})}}),s.get("/api/git/diff",i(),e=>{const t=e.req.query("path"),r=e.req.query("file");if(!t||!r)return e.json({error:"path and file are required"},400);try{const n=A(t);if(!P(n)||!T(n).isDirectory())return e.json({error:"invalid repository path: "+n},400);try{const o=L("/usr/bin/git",["diff","HEAD","--",r],{cwd:n,encoding:"utf-8",timeout:5e3}),a=L("/usr/bin/git",["diff","--cached","--",r],{cwd:n,encoding:"utf-8",timeout:5e3});return e.json({diff:o,stagedDiff:a})}catch(o){throw console.error("[git/diff] execFileSync failed:",o?.code,o.message),o}}catch(n){return n.message==="FS_ROOTS_NOT_CONFIGURED"?e.json({error:"file access not configured"},403):n.message==="PATH_NOT_ALLOWED"?e.json({error:"path not allowed"},403):(console.error("[git/diff] exception:",n),e.json({error:String(n)},500))}}),s.get("/api/file",i(),e=>{try{const t=e.req.query("path");if(!t)return e.json({error:"path is required"},400);const r=A(t);if(!T(r).isFile())return e.json({error:"not a file"},400);const n=T(r).size;if(n>K)return e.json({error:"file too large",size:n,maxBytes:K},413);const o=z(r,"utf-8");return e.json({path:r,content:o,size:n})}catch(t){return t.message==="FS_ROOTS_NOT_CONFIGURED"?e.json({error:"file access not configured"},403):t.message==="PATH_NOT_ALLOWED"?e.json({error:"path not allowed"},403):t.code==="ENOENT"?e.json({error:"not found"},404):e.json({error:"internal error"},500)}}),s.put("/api/file",i(),async e=>{try{const t=await e.req.json();if(!t.path||typeof t.content!="string")return e.json({error:"path and content are required"},400);const r=A(t.path);return De(r,t.content),e.json({ok:!0})}catch(t){return t.message==="FS_ROOTS_NOT_CONFIGURED"?e.json({error:"file access not configured"},403):t.message==="PATH_NOT_ALLOWED"?e.json({error:"path not allowed"},403):e.json({error:"write failed"},500)}}),s.post("/api/file/delete",i(),async e=>{try{const t=await e.req.json();if(!t.path)return e.json({error:"path is required"},400);const r=A(t.path);return T(r).isFile()?(me(r),e.json({ok:!0})):e.json({error:"not a file"},400)}catch(t){return t.message==="FS_ROOTS_NOT_CONFIGURED"?e.json({error:"file access not configured"},403):t.message==="PATH_NOT_ALLOWED"?e.json({error:"path not allowed"},403):e.json({error:"delete failed"},500)}}),s.post("/api/file/touch",i(),async e=>{try{const t=await e.req.json();if(!t.path)return e.json({error:"path is required"},400);const r=A(t.path);return P(r)?e.json({error:"file already exists"},409):(fe(h.dirname(r),{recursive:!0}),pe(r,"","utf-8"),e.json({ok:!0,path:r}))}catch(t){return t.message==="FS_ROOTS_NOT_CONFIGURED"?e.json({error:"file access not configured"},403):t.message==="PATH_NOT_ALLOWED"?e.json({error:"path not allowed"},403):e.json({error:"touch failed"},500)}}),s.get("/api/sidebar/sessions",i(),e=>{const t=e.req.query("currentSession");return e.json(N(typeof t=="string"&&t?t:void 0))}),s.get("/api/sidebar/session-windows/:session",i(),e=>{const t=decodeURIComponent(e.req.param("session"));return e.json(Ye(t))}),s.post("/api/pinned-views",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=B(t);return"error"in r?e.json({error:r.error},400):(await Ke(r.sessionName,r.windowIndex),e.json(N()))}),s.delete("/api/pinned-views",i(),async e=>{let t;try{t=await e.req.json()}catch{return e.json({error:"invalid json"},400)}const r=B(t);return"error"in r?e.json({error:r.error},400):(await Xe(r.sessionName,r.windowIndex),e.json(N()))}),s.get("/api/notes",i(),e=>{const t=[...b.data.notes].sort((r,n)=>(n.updatedAt??0)-(r.updatedAt??0));return e.json(t)}),s.get("/api/notes/:scope",i(),e=>{const t=decodeURIComponent(e.req.param("scope")),r=b.data.notes.find(n=>n.scope===t);return r?e.json(r):e.json(null,404)}),s.put("/api/notes/:scope",i(),async e=>{const t=decodeURIComponent(e.req.param("scope"));let r;try{r=await e.req.json()}catch{return e.json({error:"invalid json"},400)}if(typeof r.content!="string")return e.json({error:"content must be string"},400);const n={scope:t,content:r.content,updatedAt:Date.now()},o=b.data.notes.findIndex(a=>a.scope===t);return o>=0?b.data.notes[o]=n:b.data.notes.push(n),await b.write(),e.json({ok:!0})}),f&&(s.use("/a/:agentId/*",i()),lt(s,{getChannel:f.getChannel})),!v)try{ke(s,{manager:ve(),userAuth:i})}catch(e){console.error("[bots] failed to register routes:",e)}return s}export{tr as buildApp};
|
package/dist/lib/pages/shell.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSessionModalHTML as x,newSessionModalScript as g,reducedMotion as f}from"../shared-layout.js";import{icon as o}from"../icons.js";function m(
|
|
1
|
+
import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSessionModalHTML as x,newSessionModalScript as g,reducedMotion as f}from"../shared-layout.js";import{icon as o}from"../icons.js";function m(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function a(t="var(--panel-accent)"){return`box-shadow: 0 0 0 2px ${t}; outline: none;`}function y(t){const{theme:e,fsRoots:r,terminalCfg:i,scrollback:p,wsBase:s}=t,n=t.version?m(t.version):"",l=`
|
|
2
2
|
*, *::before, *::after { box-sizing: border-box; }
|
|
3
3
|
html, body {
|
|
4
4
|
background: var(--page-bg); color: var(--page-fg);
|
|
@@ -822,6 +822,10 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
822
822
|
}
|
|
823
823
|
.bv-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }
|
|
824
824
|
.bv-inbox-count { margin-left: 5px; font-size: 10.5px; color: var(--panel-accent); }
|
|
825
|
+
/* Paused after a restart: bring the bot back in one tap. */
|
|
826
|
+
.bv-resume { color: var(--panel-accent); border-color: color-mix(in srgb, var(--panel-accent) 45%, var(--panel-border)); }
|
|
827
|
+
.bv-resume:hover { background: color-mix(in srgb, var(--panel-accent) 10%, transparent); }
|
|
828
|
+
.bv-resume:disabled { opacity: 0.5; }
|
|
825
829
|
.bv-inbox-count:empty { display: none; }
|
|
826
830
|
.bots-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; background: var(--panel-muted); }
|
|
827
831
|
|
|
@@ -1192,7 +1196,7 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
1192
1196
|
display: flex; flex-wrap: nowrap; gap: 4px;
|
|
1193
1197
|
overflow-x: auto; overscroll-behavior-x: contain;
|
|
1194
1198
|
}
|
|
1195
|
-
`,v=JSON.stringify(
|
|
1199
|
+
`,v=JSON.stringify(e.terminal).replace(/</g,"\\u003c"),d=JSON.stringify({terminal:i,scrollback:p,theme:e.terminal,fsRoots:r,wsBase:s||""}).replace(/</g,"\\u003c");return`<!DOCTYPE html>
|
|
1196
1200
|
<html lang="en">
|
|
1197
1201
|
<head>
|
|
1198
1202
|
<meta charset="UTF-8" />
|
|
@@ -1201,12 +1205,15 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
1201
1205
|
<meta name="apple-mobile-web-app-capable" content="yes" />
|
|
1202
1206
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
|
1203
1207
|
<meta name="apple-mobile-web-app-title" content="tmux-web" />
|
|
1204
|
-
|
|
1205
|
-
<link rel="
|
|
1208
|
+
<!-- iOS reads the apple-touch-icon (opaque, square); everything else uses the manifest. -->
|
|
1209
|
+
<link rel="apple-touch-icon" sizes="180x180" href="/assets/apple-touch-icon-180.png" />
|
|
1206
1210
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
1211
|
+
<link rel="icon" type="image/png" sizes="192x192" href="/assets/icon-192.png" />
|
|
1212
|
+
<link rel="manifest" href="/manifest.json" />
|
|
1213
|
+
<meta name="theme-color" content="${e.shell.pageBg}" />
|
|
1207
1214
|
<title>tmux-weblink</title>
|
|
1208
1215
|
<style>
|
|
1209
|
-
${c(
|
|
1216
|
+
${c(e.shell)}
|
|
1210
1217
|
${l}
|
|
1211
1218
|
</style>
|
|
1212
1219
|
</head>
|
|
@@ -1308,10 +1315,10 @@ import{cssVarsStyle as c}from"../theme.js";import{newSessionModalCSS as b,newSes
|
|
|
1308
1315
|
<div class="settings-popover" id="settings-popover">
|
|
1309
1316
|
<div style="padding:1px 2px 6px;font-size:10px;color:var(--panel-muted);opacity:.8;font-family:var(--font-mono)">tmux-weblink v${n}</div>
|
|
1310
1317
|
<div style="padding:4px 0">
|
|
1311
|
-
<button class="theme-option" data-theme="vscode" title="VS Code"><span class="theme-dot" style="background:#007acc"></span>VS Code${
|
|
1312
|
-
<button class="theme-option" data-theme="ghostty" title="Ghostty"><span class="theme-dot" style="background:#ff5f00"></span>Ghostty${
|
|
1313
|
-
<button class="theme-option" data-theme="warm-clay" title="Warm Clay"><span class="theme-dot" style="background:#b86b52"></span>Warm Clay${
|
|
1314
|
-
<button class="theme-option" data-theme="dark-cove" title="Dark Cove"><span class="theme-dot" style="background:#7aa2f7"></span>Dark Cove${
|
|
1318
|
+
<button class="theme-option" data-theme="vscode" title="VS Code"><span class="theme-dot" style="background:#007acc"></span>VS Code${e.template==="vscode"?'<span class="theme-check">\u2713</span>':""}</button>
|
|
1319
|
+
<button class="theme-option" data-theme="ghostty" title="Ghostty"><span class="theme-dot" style="background:#ff5f00"></span>Ghostty${e.template==="ghostty"?'<span class="theme-check">\u2713</span>':""}</button>
|
|
1320
|
+
<button class="theme-option" data-theme="warm-clay" title="Warm Clay"><span class="theme-dot" style="background:#b86b52"></span>Warm Clay${e.template==="warm-clay"?'<span class="theme-check">\u2713</span>':""}</button>
|
|
1321
|
+
<button class="theme-option" data-theme="dark-cove" title="Dark Cove"><span class="theme-dot" style="background:#7aa2f7"></span>Dark Cove${e.template==="dark-cove"?'<span class="theme-check">\u2713</span>':""}</button>
|
|
1315
1322
|
</div>
|
|
1316
1323
|
<label class="force-narrow-row" title="\u7A84\u5C4F\u65F6\u4FA7\u8FB9\u680F\u6298\u53E0\u4E3A\u9876\u680F\u3001\u7EC8\u7AEF\u5360\u6EE1\u3001\u5E95\u90E8\u663E\u793A\u865A\u62DF\u952E\u76D8\u5DE5\u5177\u680F\uFF08\u4EC5\u5F71\u54CD\u672C\u6D4F\u89C8\u5668\uFF09">
|
|
1317
1324
|
<span>\u5F3A\u5236\u7A84\u5C4F\uFF08\u79FB\u52A8\u5E03\u5C40\uFF09</span>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tmux-weblink",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.3",
|
|
4
4
|
"description": "Access your tmux sessions from the browser. A continuation of tmux-web and persalink.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"postinstall": "node scripts/fix-pty-perms.mjs",
|
|
17
17
|
"prepublishOnly": "npm run build",
|
|
18
|
-
"build": "tsc && npm run check:drawer-scripts && npm run
|
|
18
|
+
"build": "tsc && npm run check:drawer-scripts && npm run build:client && npm run generate-icons && npm run build:exts && npm run minify:dist",
|
|
19
19
|
"generate-icons": "node scripts/generate-icons.mjs",
|
|
20
20
|
"check:drawer-scripts": "tsx scripts/check-drawer-scripts.ts",
|
|
21
21
|
"build:client": "node scripts/build-client.mjs",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"build:exts": "node scripts/build-exts.mjs --force",
|
|
27
27
|
"minify:dist": "node scripts/minify-dist.mjs",
|
|
28
28
|
"start": "node dist/index.js",
|
|
29
|
-
"predev": "node scripts/build-client.mjs && node scripts/build-exts.mjs",
|
|
29
|
+
"predev": "node scripts/build-client.mjs && node scripts/generate-icons.mjs && node scripts/build-exts.mjs --force",
|
|
30
30
|
"dev": "TMUX_WEB_DEV=1 npx tsx src/index.ts"
|
|
31
31
|
},
|
|
32
32
|
"keywords": [
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
// Generates PWA icons (
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
// Generates the PWA icons with pure Node (zlib only) — no build tooling needed.
|
|
2
|
+
//
|
|
3
|
+
// Design: a full-bleed square (the OS applies its own mask, so no inner rounded
|
|
4
|
+
// rectangle), a quiet vertical gradient, a soft accent glow behind the glyph and
|
|
5
|
+
// a bold ">_" prompt. The maskable variant keeps the glyph inside the safe zone
|
|
6
|
+
// (80% circle) so Android never crops it.
|
|
7
|
+
import { deflateSync } from "node:zlib";
|
|
4
8
|
import { writeFileSync, mkdirSync } from "node:fs";
|
|
5
9
|
import { join, dirname } from "node:path";
|
|
6
10
|
import { fileURLToPath } from "node:url";
|
|
@@ -8,160 +12,147 @@ import { fileURLToPath } from "node:url";
|
|
|
8
12
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
9
13
|
const ICONS_DIR = join(__dirname, "..", "dist", "assets");
|
|
10
14
|
|
|
15
|
+
const BG_TOP = [16, 22, 31];
|
|
16
|
+
const BG_BOTTOM = [9, 12, 17];
|
|
17
|
+
const ACCENT = [125, 211, 252];
|
|
18
|
+
const SUPERSAMPLE = 4;
|
|
19
|
+
|
|
11
20
|
function crc32(buf) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
let crc = 0xffffffff;
|
|
22
|
+
for (let i = 0; i < buf.length; i++) {
|
|
23
|
+
crc ^= buf[i];
|
|
24
|
+
for (let j = 0; j < 8; j++) crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
|
|
25
|
+
}
|
|
26
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
function pngChunk(type, data) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
const len = Buffer.alloc(4);
|
|
31
|
+
len.writeUInt32BE(data.length);
|
|
32
|
+
const typeB = Buffer.from(type, "ascii");
|
|
33
|
+
const crc = Buffer.alloc(4);
|
|
34
|
+
crc.writeUInt32BE(crc32(Buffer.concat([typeB, data])));
|
|
35
|
+
return Buffer.concat([len, typeB, data, crc]);
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
function createPNG(width, height, getPixel) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
39
|
+
const stride = 1 + width * 4;
|
|
40
|
+
const raw = Buffer.alloc(height * stride);
|
|
41
|
+
for (let y = 0; y < height; y++) {
|
|
42
|
+
raw[y * stride] = 0;
|
|
43
|
+
for (let x = 0; x < width; x++) {
|
|
44
|
+
const [r, g, b, a] = getPixel(x, y);
|
|
45
|
+
const p = y * stride + 1 + x * 4;
|
|
46
|
+
raw[p] = Math.max(0, Math.min(255, Math.round(r)));
|
|
47
|
+
raw[p + 1] = Math.max(0, Math.min(255, Math.round(g)));
|
|
48
|
+
raw[p + 2] = Math.max(0, Math.min(255, Math.round(b)));
|
|
49
|
+
raw[p + 3] = Math.max(0, Math.min(255, Math.round(a)));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// PNG IDAT must be a zlib stream (raw deflate decodes as a corrupt PNG).
|
|
53
|
+
const compressed = deflateSync(raw, { level: 9 });
|
|
54
|
+
const ihdr = Buffer.alloc(13);
|
|
55
|
+
ihdr.writeUInt32BE(width, 0);
|
|
56
|
+
ihdr.writeUInt32BE(height, 4);
|
|
57
|
+
ihdr[8] = 8;
|
|
58
|
+
ihdr[9] = 6;
|
|
59
|
+
const signature = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
60
|
+
return Buffer.concat([
|
|
61
|
+
signature,
|
|
62
|
+
pngChunk("IHDR", ihdr),
|
|
63
|
+
pngChunk("IDAT", compressed),
|
|
64
|
+
pngChunk("IEND", Buffer.alloc(0)),
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Distance from a point to a line segment with round caps. */
|
|
69
|
+
function segmentDistance(px, py, x1, y1, x2, y2) {
|
|
70
|
+
const dx = x2 - x1;
|
|
71
|
+
const dy = y2 - y1;
|
|
72
|
+
const length2 = dx * dx + dy * dy;
|
|
73
|
+
const t = length2 === 0 ? 0 : Math.max(0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / length2));
|
|
74
|
+
return Math.hypot(px - (x1 + t * dx), py - (y1 + t * dy));
|
|
52
75
|
}
|
|
53
76
|
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
const t = Math.max(0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / (dx * dx + dy * dy)));
|
|
57
|
-
return Math.sqrt((px - (x1 + t * dx)) ** 2 + (py - (y1 + t * dy)) ** 2);
|
|
77
|
+
function mix(a, b, t) {
|
|
78
|
+
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
58
79
|
}
|
|
59
80
|
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (d1 < strokeW + strokeGlow || d2 < strokeW + strokeGlow) {
|
|
122
|
-
const t = Math.min(1, Math.max(0, 1 - (Math.min(d1, d2) - strokeW) / strokeGlow));
|
|
123
|
-
r = Math.round(r + (accent[0] - r) * t);
|
|
124
|
-
g = Math.round(g + (accent[1] - g) * t);
|
|
125
|
-
b = Math.round(b + (accent[2] - b) * t);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// "_" cursor to the right
|
|
129
|
-
const cu = 0.32, cv = 0.18;
|
|
130
|
-
const dc = Math.abs(y - cv);
|
|
131
|
-
const hc = Math.abs(x - cu);
|
|
132
|
-
const cw = 0.12, ch = 0.03;
|
|
133
|
-
if (hc < cw && dc < ch) {
|
|
134
|
-
const t = Math.min(1, 1 - (dc - ch * 0.6) / (ch * 0.4));
|
|
135
|
-
const t2 = Math.min(1, 1 - Math.max(0, x - (cu - cw * 0.6)) / (cw * 0.4));
|
|
136
|
-
const t3 = Math.min(1, 1 - Math.max(0, (cu + cw * 0.6) - x) / (cw * 0.4));
|
|
137
|
-
const final = Math.min(t, Math.max(t2, t3));
|
|
138
|
-
r = Math.round(r + (accent[0] - r) * final);
|
|
139
|
-
g = Math.round(g + (accent[1] - g) * final);
|
|
140
|
-
b = Math.round(b + (accent[2] - b) * final);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Accumulate into output
|
|
144
|
-
const oi = (Math.floor(sy / ss) * size + Math.floor(sx / ss)) * 4;
|
|
145
|
-
accum[oi] += r * alpha;
|
|
146
|
-
accum[oi+1] += g * alpha;
|
|
147
|
-
accum[oi+2] += b * alpha;
|
|
148
|
-
accum[oi+3] += alpha;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return createPNG(size, size, (x, y) => {
|
|
153
|
-
const i = (y * size + x) * 4;
|
|
154
|
-
const a = accum[i+3];
|
|
155
|
-
if (a === 0) return [0, 0, 0, 0];
|
|
156
|
-
const inv = 1 / (ss * ss);
|
|
157
|
-
return [accum[i] / a, accum[i+1] / a, accum[i+2] / a, Math.round(a * inv * 255)];
|
|
158
|
-
});
|
|
81
|
+
function renderIcon(size, { maskable = false } = {}) {
|
|
82
|
+
// Glyph geometry in unit coordinates; maskable art shrinks toward the centre.
|
|
83
|
+
const scale = maskable ? 0.72 : 1;
|
|
84
|
+
const chevron = [
|
|
85
|
+
[0.30, 0.38, 0.44, 0.5],
|
|
86
|
+
[0.44, 0.5, 0.30, 0.62],
|
|
87
|
+
];
|
|
88
|
+
const cursor = [0.51, 0.62, 0.68, 0.62];
|
|
89
|
+
const stroke = 0.042 * scale;
|
|
90
|
+
const point = ([x1, y1, x2, y2]) => [
|
|
91
|
+
0.5 + (x1 - 0.5) * scale,
|
|
92
|
+
0.5 + (y1 - 0.5) * scale,
|
|
93
|
+
0.5 + (x2 - 0.5) * scale,
|
|
94
|
+
0.5 + (y2 - 0.5) * scale,
|
|
95
|
+
];
|
|
96
|
+
const strokes = [...chevron.map(point), point(cursor)];
|
|
97
|
+
|
|
98
|
+
const ss = SUPERSAMPLE;
|
|
99
|
+
const large = size * ss;
|
|
100
|
+
const accum = new Float64Array(size * size * 4);
|
|
101
|
+
|
|
102
|
+
for (let sy = 0; sy < large; sy++) {
|
|
103
|
+
for (let sx = 0; sx < large; sx++) {
|
|
104
|
+
const x = (sx + 0.5) / large;
|
|
105
|
+
const y = (sy + 0.5) / large;
|
|
106
|
+
|
|
107
|
+
// Background: vertical gradient plus a soft glow behind the glyph.
|
|
108
|
+
let [r, g, b] = mix(BG_TOP, BG_BOTTOM, y);
|
|
109
|
+
const glow = Math.max(0, 1 - Math.hypot(x - 0.46, y - 0.5) / 0.62);
|
|
110
|
+
const glowAmount = glow * glow * 0.16;
|
|
111
|
+
r += (ACCENT[0] - r) * glowAmount;
|
|
112
|
+
g += (ACCENT[1] - g) * glowAmount;
|
|
113
|
+
b += (ACCENT[2] - b) * glowAmount;
|
|
114
|
+
|
|
115
|
+
// Glyph: distance to the nearest stroke, anti-aliased at the edge.
|
|
116
|
+
let distance = Infinity;
|
|
117
|
+
for (const [x1, y1, x2, y2] of strokes) {
|
|
118
|
+
distance = Math.min(distance, segmentDistance(x, y, x1, y1, x2, y2));
|
|
119
|
+
}
|
|
120
|
+
const edge = 1.4 / large;
|
|
121
|
+
const coverage = Math.max(0, Math.min(1, (stroke - distance) / edge + 0.5));
|
|
122
|
+
if (coverage > 0) {
|
|
123
|
+
r += (ACCENT[0] - r) * coverage;
|
|
124
|
+
g += (ACCENT[1] - g) * coverage;
|
|
125
|
+
b += (ACCENT[2] - b) * coverage;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const oi = (Math.floor(sy / ss) * size + Math.floor(sx / ss)) * 4;
|
|
129
|
+
accum[oi] += r;
|
|
130
|
+
accum[oi + 1] += g;
|
|
131
|
+
accum[oi + 2] += b;
|
|
132
|
+
accum[oi + 3] += 255;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const samples = ss * ss;
|
|
137
|
+
return createPNG(size, size, (x, y) => {
|
|
138
|
+
const i = (y * size + x) * 4;
|
|
139
|
+
return [accum[i] / samples, accum[i + 1] / samples, accum[i + 2] / samples, 255];
|
|
140
|
+
});
|
|
159
141
|
}
|
|
160
142
|
|
|
143
|
+
const OUTPUTS = [
|
|
144
|
+
["icon-192.png", 192, {}],
|
|
145
|
+
["icon-512.png", 512, {}],
|
|
146
|
+
["icon-maskable-192.png", 192, { maskable: true }],
|
|
147
|
+
["icon-maskable-512.png", 512, { maskable: true }],
|
|
148
|
+
// iOS ignores the manifest and wants a square, opaque apple-touch-icon.
|
|
149
|
+
["apple-touch-icon-180.png", 180, {}],
|
|
150
|
+
];
|
|
151
|
+
|
|
161
152
|
mkdirSync(ICONS_DIR, { recursive: true });
|
|
162
|
-
for (const size of
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
153
|
+
for (const [name, size, options] of OUTPUTS) {
|
|
154
|
+
const png = renderIcon(size, options);
|
|
155
|
+
const outPath = join(ICONS_DIR, name);
|
|
156
|
+
writeFileSync(outPath, png);
|
|
157
|
+
console.log(`[generate-icons] wrote ${outPath} (${png.length} bytes)`);
|
|
167
158
|
}
|