@vladar107/claudescope 0.4.0 → 0.4.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.
package/README.md CHANGED
@@ -118,7 +118,8 @@ npx @vladar107/claudescope
118
118
 
119
119
  ```bash
120
120
  # Homebrew (macOS / Linux)
121
- brew install vladar107/tap/claudescope
121
+ brew tap vladar107/tap
122
+ brew install claudescope
122
123
 
123
124
  # Nix (any platform) — run without installing, or add to a profile
124
125
  nix run github:vladar107/claudescope
package/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __cr } from 'node:module';
3
3
  const require = __cr(import.meta.url);
4
- import{spawn as T,spawnSync as b}from"node:child_process";import{existsSync as D,mkdirSync as $,openSync as F,readFileSync as I,realpathSync as J,rmSync as y,writeFileSync as U}from"node:fs";import{dirname as V,join as h}from"node:path";import{createInterface as G}from"node:readline/promises";import{parseArgs as W}from"node:util";import{fileURLToPath as K}from"node:url";import{copyFileSync as ie,existsSync as H,mkdirSync as ae}from"node:fs";import{homedir as l}from"node:os";import{dirname as M,join as s}from"node:path";import{fileURLToPath as B}from"node:url";var v=M(B(import.meta.url));function x(e,o){return e.find(t=>H(t))??o}var E=Number(process.env.PORT??4317),f=s(v,"..");function m(e){return e==="~"?l():e.startsWith("~/")?s(l(),e.slice(2)):e}var w=m(process.env.CLAUDE_PROJECTS_DIR??s(l(),".claude","projects")),ue=m(process.env.CODEX_SESSIONS_DIR??s(l(),".codex","sessions")),de=m(process.env.JUNIE_SESSIONS_DIR??s(l(),".junie","sessions")),fe=process.env.OPEN_BROWSER==="1",me=Number(process.env.REINDEX_INTERVAL_MS??15e3),a=m(process.env.CLAUDESCOPE_HOME??s(l(),".claudescope")),ge=process.env.DUCKDB_PATH??s(a,"index.duckdb"),he=x([s(v,"pricing.default.json"),s(f,"pricing.json")],s(f,"pricing.json")),Se=process.env.PRICING_PATH??s(a,"pricing.json"),ve=process.env.WEB_DIST_DIR??x([s(v,"web"),s(f,"..","web","dist")],s(f,"..","web","dist")),i="0.4.0";var P=V(K(import.meta.url)),X=h(P,"server.js"),p=h(a,"daemon.json"),g=h(a,"daemon.log"),_=h(a,"update-check.json"),u="@vladar107/claudescope",q=24*60*60*1e3;function S(){if(!D(p))return null;try{return JSON.parse(I(p,"utf8"))}catch{return null}}function d(e){try{return process.kill(e,0),!0}catch{return!1}}async function C(e){try{return(await fetch(`http://127.0.0.1:${e}/api/health`,{signal:AbortSignal.timeout(1500)})).ok}catch{return!1}}async function Y(e,o){let t=Date.now()+o;for(;Date.now()<t;){if(await C(e))return!0;process.stdout.write("."),await new Promise(r=>setTimeout(r,500))}return!1}function R(e){let o=process.platform==="darwin"?"open":process.platform==="win32"?"start":"xdg-open";try{T(o,[e],{stdio:"ignore",detached:!0,shell:process.platform==="win32"}).unref()}catch{}}async function N(e,o){$(a,{recursive:!0});let t=S();if(t&&d(t.pid)&&await C(t.port)){console.log(`\u2713 claudescope is already running \u2192 ${t.url}`),o&&R(t.url);return}t&&!d(t.pid)&&y(p,{force:!0});let r=`http://localhost:${e}`,n=F(g,"a"),c=T(process.execPath,[X],{detached:!0,stdio:["ignore",n,n],env:{...process.env,PORT:String(e),OPEN_BROWSER:"0"}});if(c.unref(),U(p,JSON.stringify({pid:c.pid,port:e,url:r,version:i,startedAt:new Date().toISOString()},null,2)),process.stdout.write("\u203A Starting claudescope"),!await Y(e,2e4)){console.error(`
4
+ import{spawn as T,spawnSync as b}from"node:child_process";import{existsSync as D,mkdirSync as $,openSync as F,readFileSync as I,realpathSync as J,rmSync as y,writeFileSync as U}from"node:fs";import{dirname as V,join as h}from"node:path";import{createInterface as G}from"node:readline/promises";import{parseArgs as W}from"node:util";import{fileURLToPath as K}from"node:url";import{copyFileSync as ie,existsSync as H,mkdirSync as ae}from"node:fs";import{homedir as l}from"node:os";import{dirname as M,join as s}from"node:path";import{fileURLToPath as B}from"node:url";var v=M(B(import.meta.url));function x(e,o){return e.find(t=>H(t))??o}var E=Number(process.env.PORT??4317),f=s(v,"..");function m(e){return e==="~"?l():e.startsWith("~/")?s(l(),e.slice(2)):e}var w=m(process.env.CLAUDE_PROJECTS_DIR??s(l(),".claude","projects")),ue=m(process.env.CODEX_SESSIONS_DIR??s(l(),".codex","sessions")),de=m(process.env.JUNIE_SESSIONS_DIR??s(l(),".junie","sessions")),fe=process.env.OPEN_BROWSER==="1",me=Number(process.env.REINDEX_INTERVAL_MS??15e3),a=m(process.env.CLAUDESCOPE_HOME??s(l(),".claudescope")),ge=process.env.DUCKDB_PATH??s(a,"index.duckdb"),he=x([s(v,"pricing.default.json"),s(f,"pricing.json")],s(f,"pricing.json")),Se=process.env.PRICING_PATH??s(a,"pricing.json"),ve=process.env.WEB_DIST_DIR??x([s(v,"web"),s(f,"..","web","dist")],s(f,"..","web","dist")),i="0.4.1";var P=V(K(import.meta.url)),X=h(P,"server.js"),p=h(a,"daemon.json"),g=h(a,"daemon.log"),_=h(a,"update-check.json"),u="@vladar107/claudescope",q=24*60*60*1e3;function S(){if(!D(p))return null;try{return JSON.parse(I(p,"utf8"))}catch{return null}}function d(e){try{return process.kill(e,0),!0}catch{return!1}}async function C(e){try{return(await fetch(`http://127.0.0.1:${e}/api/health`,{signal:AbortSignal.timeout(1500)})).ok}catch{return!1}}async function Y(e,o){let t=Date.now()+o;for(;Date.now()<t;){if(await C(e))return!0;process.stdout.write("."),await new Promise(r=>setTimeout(r,500))}return!1}function R(e){let o=process.platform==="darwin"?"open":process.platform==="win32"?"start":"xdg-open";try{T(o,[e],{stdio:"ignore",detached:!0,shell:process.platform==="win32"}).unref()}catch{}}async function N(e,o){$(a,{recursive:!0});let t=S();if(t&&d(t.pid)&&await C(t.port)){console.log(`\u2713 claudescope is already running \u2192 ${t.url}`),o&&R(t.url);return}t&&!d(t.pid)&&y(p,{force:!0});let r=`http://localhost:${e}`,n=F(g,"a"),c=T(process.execPath,[X],{detached:!0,stdio:["ignore",n,n],env:{...process.env,PORT:String(e),OPEN_BROWSER:"0"}});if(c.unref(),U(p,JSON.stringify({pid:c.pid,port:e,url:r,version:i,startedAt:new Date().toISOString()},null,2)),process.stdout.write("\u203A Starting claudescope"),!await Y(e,2e4)){console.error(`
5
5
  \u2717 Server did not become healthy in time. Inspect: claudescope logs`),process.exitCode=1;return}console.log(`
6
6
  \u2713 claudescope running \u2192 ${r}`),console.log(` Sessions: ${w} (read-only)`),o&&R(r),await j(!1)}function O(){let e=S();if(!e||!d(e.pid)){console.log("claudescope is not running."),y(p,{force:!0});return}try{process.kill(e.pid,"SIGTERM")}catch{}y(p,{force:!0}),console.log(`\u2713 Stopped claudescope (pid ${e.pid}).`)}async function z(){let e=S();e&&d(e.pid)&&await C(e.port)?console.log(`\u25CF running ${e.url} (pid ${e.pid}, v${e.version})`):console.log(`\u25CB stopped (installed v${i})`),await j(!0)}function Q(){let e=S();e&&d(e.pid)?R(e.url):console.log("claudescope is not running. Start it with: claudescope start")}function Z(e){if(!D(g)){console.log("No logs yet.");return}e&&process.platform!=="win32"?b("tail",["-f",g],{stdio:"inherit"}):process.stdout.write(I(g,"utf8"))}async function ee(e,o){if(!process.stdin.isTTY)return o;let t=G({input:process.stdin,output:process.stdout});try{let r=(await t.question(`${e} ${o?"[Y/n]":"[y/N]"} `)).trim().toLowerCase();return r?r==="y"||r==="yes":o}finally{t.close()}}function oe(){let e=P;try{e=J(P)}catch{}return e.includes("/nix/store/")?"nix":/[\\/]Cellar[\\/]claudescope[\\/]/.test(e)?"brew":"npm"}async function te(e){let o=await L(!0);if(o&&!k(o,i)){console.log(`\u2713 Already on the latest version (v${i}).`);return}let t=oe();if(t==="brew"){console.log("claudescope was installed via Homebrew."),console.log(" Run: brew upgrade vladar107/tap/claudescope");return}if(t==="nix"){console.log("claudescope was installed via Nix."),console.log(" Run: nix profile upgrade claudescope"),console.log(" (flake users: re-run `nix run --refresh github:vladar107/claudescope`)");return}o||console.log("\u26A0 Could not reach the npm registry to confirm the latest version.");let r=o?`v${i} \u2192 v${o}`:`v${i} \u2192 latest`;if(console.log(`\u203A Will run: npm install -g ${u}@latest (${r})`),!e&&!await ee("Proceed?",!0)){console.log("Aborted.");return}console.log(`\u203A Updating ${u}\u2026`);let n=process.platform==="win32"?"npm.cmd":"npm";if(b(n,["install","-g",`${u}@latest`],{stdio:"inherit"}).status!==0){console.error(`\u2717 Update failed. If you run via npx, just re-run \`npx ${u}\` to get the latest.`),process.exitCode=1;return}O(),console.log("\u2713 Updated. Restarting\u2026"),b("claudescope",["start"],{stdio:"inherit",shell:process.platform==="win32"})}function k(e,o){let t=e.split(".").map(n=>Number.parseInt(n,10)||0),r=o.split(".").map(n=>Number.parseInt(n,10)||0);for(let n=0;n<3;n++){if((t[n]??0)>(r[n]??0))return!0;if((t[n]??0)<(r[n]??0))return!1}return!1}async function L(e){let o=Date.now();if(!e&&D(_))try{let c=JSON.parse(I(_,"utf8"));if(o-c.lastCheck<q)return c.latest}catch{}let t=`https://registry.npmjs.org/${u.replace("/","%2f")}/latest`,r=await fetch(t,{signal:AbortSignal.timeout(2500)});if(!r.ok)return null;let n=await r.json();return n.version?($(a,{recursive:!0}),U(_,JSON.stringify({lastCheck:o,latest:n.version})),n.version):null}async function j(e){try{let o=await L(e);o&&k(o,i)&&console.log(`
7
7
  \u2B06 Update available: v${i} \u2192 v${o}. Run: claudescope update`)}catch{}}function A(){console.log(`claudescope v${i} \u2014 local viewer for Claude Code transcripts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vladar107/claudescope",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Local, read-only web app to browse, read, search, and analyze your AI coding-agent transcripts — Claude Code, OpenAI Codex, and JetBrains Junie.",
5
5
  "keywords": [
6
6
  "claude",
package/server.js CHANGED
@@ -389,7 +389,7 @@ globstar while`,O,X,N,re,fe),this.matchOne(O.slice(X),N.slice(re),L))return this
389
389
  \x1B[36mat `+r[i].toString()+"\x1B[39m";return n}return t&&(n+=" \x1B[36m"+ny(t)+"\x1B[39m"),n}function ny(e){return oX(aX,e[0])+":"+e[1]+":"+e[2]}function Eu(){var e=Error.stackTraceLimit,t={},r=Error.prepareStackTrace;Error.prepareStackTrace=yX,Error.stackTraceLimit=Math.max(10,e),Error.captureStackTrace(t);var n=t.stack.slice(1);return Error.prepareStackTrace=r,Error.stackTraceLimit=e,n}function yX(e,t){return t}function _X(e,t){if(typeof e!="function")throw new TypeError("argument fn must be a function");var r=cX(e.length),n=Eu(),i=_s(n[1]);i.name=e.name;var s=new Function("fn","log","deprecate","message","site",`"use strict"
390
390
  return function (`+r+`) {log.call(deprecate, message, site)
391
391
  return fn.apply(this, arguments)
392
- }`)(e,bu,this,t,i);return s}function vX(e,t,r){if(!e||typeof e!="object"&&typeof e!="function")throw new TypeError("argument obj must be object");var n=Object.getOwnPropertyDescriptor(e,t);if(!n)throw new TypeError("must call property on owner object");if(!n.configurable)throw new TypeError("property must be configurable");var i=this,s=Eu(),o=_s(s[1]);o.name=t,"value"in n&&(n=lX(e,t,r));var a=n.get,l=n.set;typeof a=="function"&&(n.get=function(){return bu.call(i,r,o),a.apply(this,arguments)}),typeof l=="function"&&(n.set=function(){return bu.call(i,r,o),l.apply(this,arguments)}),Object.defineProperty(e,t,n)}function r1(e,t,r){var n=new Error,i;return Object.defineProperty(n,"constructor",{value:r1}),Object.defineProperty(n,"message",{configurable:!0,enumerable:!1,value:t,writable:!0}),Object.defineProperty(n,"name",{enumerable:!1,configurable:!0,value:"DeprecationError",writable:!0}),Object.defineProperty(n,"namespace",{configurable:!0,enumerable:!1,value:e,writable:!0}),Object.defineProperty(n,"stack",{configurable:!0,enumerable:!1,get:function(){return i!==void 0?i:i=uX.call(this,r)},set:function(o){i=o}}),n}});var o1=R((foe,s1)=>{"use strict";s1.exports=Object.setPrototypeOf||({__proto__:[]}instanceof Array?SX:wX);function SX(e,t){return e.__proto__=t,e}function wX(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=t[r]);return e}});var a1=R((doe,bX)=>{bX.exports={"100":"Continue","101":"Switching Protocols","102":"Processing","103":"Early Hints","200":"OK","201":"Created","202":"Accepted","203":"Non-Authoritative Information","204":"No Content","205":"Reset Content","206":"Partial Content","207":"Multi-Status","208":"Already Reported","226":"IM Used","300":"Multiple Choices","301":"Moved Permanently","302":"Found","303":"See Other","304":"Not Modified","305":"Use Proxy","307":"Temporary Redirect","308":"Permanent Redirect","400":"Bad Request","401":"Unauthorized","402":"Payment Required","403":"Forbidden","404":"Not Found","405":"Method Not Allowed","406":"Not Acceptable","407":"Proxy Authentication Required","408":"Request Timeout","409":"Conflict","410":"Gone","411":"Length Required","412":"Precondition Failed","413":"Payload Too Large","414":"URI Too Long","415":"Unsupported Media Type","416":"Range Not Satisfiable","417":"Expectation Failed","418":"I'm a Teapot","421":"Misdirected Request","422":"Unprocessable Entity","423":"Locked","424":"Failed Dependency","425":"Too Early","426":"Upgrade Required","428":"Precondition Required","429":"Too Many Requests","431":"Request Header Fields Too Large","451":"Unavailable For Legal Reasons","500":"Internal Server Error","501":"Not Implemented","502":"Bad Gateway","503":"Service Unavailable","504":"Gateway Timeout","505":"HTTP Version Not Supported","506":"Variant Also Negotiates","507":"Insufficient Storage","508":"Loop Detected","509":"Bandwidth Limit Exceeded","510":"Not Extended","511":"Network Authentication Required"}});var u1=R((hoe,c1)=>{"use strict";var iy=a1();c1.exports=vr;vr.message=iy;vr.code=EX(iy);vr.codes=RX(iy);vr.redirect={300:!0,301:!0,302:!0,303:!0,305:!0,307:!0,308:!0};vr.empty={204:!0,205:!0,304:!0};vr.retry={502:!0,503:!0,504:!0};function EX(e){var t={};return Object.keys(e).forEach(function(n){var i=e[n],s=Number(n);t[i.toLowerCase()]=s}),t}function RX(e){return Object.keys(e).map(function(r){return Number(r)})}function TX(e){var t=e.toLowerCase();if(!Object.prototype.hasOwnProperty.call(vr.code,t))throw new Error('invalid status message: "'+e+'"');return vr.code[t]}function l1(e){if(!Object.prototype.hasOwnProperty.call(vr.message,e))throw new Error("invalid status code: "+e);return vr.message[e]}function vr(e){if(typeof e=="number")return l1(e);if(typeof e!="string")throw new TypeError("code must be a number or string");var t=parseInt(e,10);return isNaN(t)?TX(e):l1(t)}});var f1=R((poe,sy)=>{typeof Object.create=="function"?sy.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:sy.exports=function(t,r){if(r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}}});var d1=R((moe,ay)=>{try{if(oy=ee("util"),typeof oy.inherits!="function")throw"";ay.exports=oy.inherits}catch{ay.exports=f1()}var oy});var p1=R((goe,h1)=>{"use strict";h1.exports=OX;function OX(e){return e.split(" ").map(function(t){return t.slice(0,1).toUpperCase()+t.slice(1)}).join("").replace(/[^ _0-9a-z]/gi,"")}});var v1=R((yoe,ci)=>{"use strict";var xX=i1()("http-errors"),m1=o1(),vs=u1(),ly=d1(),PX=p1();ci.exports=Ru;ci.exports.HttpError=AX();ci.exports.isHttpError=CX(ci.exports.HttpError);IX(ci.exports,vs.codes,ci.exports.HttpError);function g1(e){return+(String(e).charAt(0)+"00")}function Ru(){for(var e,t,r=500,n={},i=0;i<arguments.length;i++){var s=arguments[i],o=typeof s;if(o==="object"&&s instanceof Error)e=s,r=e.status||e.statusCode||r;else if(o==="number"&&i===0)r=s;else if(o==="string")t=s;else if(o==="object")n=s;else throw new TypeError("argument #"+(i+1)+" unsupported type "+o)}typeof r=="number"&&(r<400||r>=600)&&xX("non-error status code; use only 4xx or 5xx status codes"),(typeof r!="number"||!vs.message[r]&&(r<400||r>=600))&&(r=500);var a=Ru[r]||Ru[g1(r)];e||(e=a?new a(t):new Error(t||vs.message[r]),Error.captureStackTrace(e,Ru)),(!a||!(e instanceof a)||e.status!==r)&&(e.expose=r<500,e.status=e.statusCode=r);for(var l in n)l!=="status"&&l!=="statusCode"&&(e[l]=n[l]);return e}function AX(){function e(){throw new TypeError("cannot construct abstract class")}return ly(e,Error),e}function kX(e,t,r){var n=_1(t);function i(s){var o=s??vs.message[r],a=new Error(o);return Error.captureStackTrace(a,i),m1(a,i.prototype),Object.defineProperty(a,"message",{enumerable:!0,configurable:!0,value:o,writable:!0}),Object.defineProperty(a,"name",{enumerable:!1,configurable:!0,value:n,writable:!0}),a}return ly(i,e),y1(i,n),i.prototype.status=r,i.prototype.statusCode=r,i.prototype.expose=!0,i}function CX(e){return function(r){return!r||typeof r!="object"?!1:r instanceof e?!0:r instanceof Error&&typeof r.expose=="boolean"&&typeof r.statusCode=="number"&&r.status===r.statusCode}}function $X(e,t,r){var n=_1(t);function i(s){var o=s??vs.message[r],a=new Error(o);return Error.captureStackTrace(a,i),m1(a,i.prototype),Object.defineProperty(a,"message",{enumerable:!0,configurable:!0,value:o,writable:!0}),Object.defineProperty(a,"name",{enumerable:!1,configurable:!0,value:n,writable:!0}),a}return ly(i,e),y1(i,n),i.prototype.status=r,i.prototype.statusCode=r,i.prototype.expose=!1,i}function y1(e,t){var r=Object.getOwnPropertyDescriptor(e,"name");r&&r.configurable&&(r.value=t,Object.defineProperty(e,"name",r))}function IX(e,t,r){t.forEach(function(i){var s,o=PX(vs.message[i]);switch(g1(i)){case 400:s=kX(r,o,i);break;case 500:s=$X(r,o,i);break}s&&(e[i]=s,e[o]=s)})}function _1(e){return e.slice(-5)==="Error"?e:e+"Error"}});var w1=R((_oe,S1)=>{"use strict";var cy=v1();function NX(e,t){return t?t instanceof Error?cy(e,t,{expose:!1}):cy(e,t):cy(e)}S1.exports.createHttpError=NX});var $1=R((voe,C1)=>{"use strict";var O1=ee("node:fs"),fa=ee("node:path"),LX=ee("node:stream"),kt=ee("node:util").debuglog("send"),jX=Qm(),DX=DC(),b1=ey(),qX=qC(),{collapseLeadingSlashes:FX}=MC(),{containsDotFile:MX}=zC(),{contentRange:E1}=BC(),{createHtmlDocument:ui}=GC(),{isUtf8MimeType:HX}=Zg(),{normalizeList:R1}=JC(),{parseBytesRange:zX}=YC(),{parseTokenList:x1}=ZC(),{createHttpError:UX}=w1(),BX=fa.extname,P1=fa.join,uy=fa.normalize,A1=fa.resolve,Tu=fa.sep,Ou=LX.Readable,VX=/^ *bytes=/,GX=60*60*24*365*1e3,T1=/(?:^|[\\/])\.\.(?:[\\/]|$)/,WX={400:ui("Error","Bad Request"),403:ui("Error","Forbidden"),404:ui("Error","Not Found"),412:ui("Error","Precondition Failed"),416:ui("Error","Range Not Satisfiable"),500:ui("Error","Internal Server Error")},JX=["allow","ignore","deny"];function KX(e){let t;return typeof e=="string"?t=qX.parse(e):t=Number(e),t!==t?0:Math.min(Math.max(0,t),GX)}function YX(e){e=e??{};let t=e.acceptRanges!==void 0?!!e.acceptRanges:!0,r=e.cacheControl!==void 0?!!e.cacheControl:!0,n=e.contentType!==void 0?!!e.contentType:!0,i=e.etag!==void 0?!!e.etag:!0,s=e.dotfiles!==void 0?JX.indexOf(e.dotfiles):1;if(s===-1)throw new TypeError('dotfiles option must be "allow", "deny", or "ignore"');let o=e.extensions!==void 0?R1(e.extensions,"extensions option"):[],a=e.immutable!==void 0?!!e.immutable:!1,l=e.index!==void 0?R1(e.index,"index option"):["index.html"],c=e.lastModified!==void 0?!!e.lastModified:!0,u=KX(e.maxAge??e.maxage),d=e.maxContentRangeChunkSize!==void 0?Number(e.maxContentRangeChunkSize):null,m=e.root?A1(e.root):null,h=Number.isSafeInteger(e.highWaterMark)&&e.highWaterMark>0?e.highWaterMark:null;return{acceptRanges:t,cacheControl:r,contentType:n,etag:i,dotfiles:s,extensions:o,immutable:a,index:l,lastModified:c,maxage:u,maxContentRangeChunkSize:d,root:m,highWaterMark:h,start:e.start,end:e.end}}function XX(e,t){let r=jX(e);if(r==null)return{statusCode:400};if(~r.indexOf("\0"))return{statusCode:400};let n;if(t!==null){if(r&&(r=uy("."+Tu+r)),T1.test(r))return kt('malicious path "%s"',r),{statusCode:403};n=r.split(Tu),r=uy(P1(t,r))}else{if(T1.test(r))return kt('malicious path "%s"',r),{statusCode:403};n=uy(r).split(Tu),r=A1(r)}return{path:r,parts:n}}function k1(e){return e[e.length-1]==="/"}function QX(e){return e.headers["if-match"]||e.headers["if-unmodified-since"]||e.headers["if-none-match"]||e.headers["if-modified-since"]}function ZX(e,t){if("cache-control"in e.headers&&e.headers["cache-control"].indexOf("no-cache")!==-1)return!1;if("if-none-match"in e.headers){let r=e.headers["if-none-match"];if(r==="*")return!0;let n=t.ETag;if(typeof n!="string")return!1;let i=n.length;return!!x1(r,function(o){let a=o.length;if(i===a&&o===n||i>a&&"W/"+o===n)return!0})}if("if-modified-since"in e.headers){let r=e.headers["if-modified-since"],n=t["Last-Modified"];if(!n||Date.parse(n)<=Date.parse(r))return!0}return!1}function eQ(e,t){let r=e.headers["if-match"];if(r){let n=t.ETag;if(r!=="*"&&(x1(r,function(s){if(s===n||"W/"+s===n)return!0})||!1)!==!0)return!0}if("if-unmodified-since"in e.headers){let n=e.headers["if-unmodified-since"],i=Date.parse(n);if(i===i){let s=Date.parse(t["Last-Modified"]);if(s!==s||s>i)return!0}}return!1}function tQ(e,t){if(!("if-range"in e.headers))return!0;let r=e.headers["if-range"];if(r.indexOf('"')!==-1){let s=t.ETag;return s&&r.indexOf(s)!==-1||!1}let n=Date.parse(r);if(n!==n)return!1;let i=Date.parse(t["Last-Modified"]);return i!==i||i<=n}function fy(e){return new Promise(t=>{O1.stat(e,function(n,i){t({error:n,stat:i})})})}function Lr(e,t){let r={};if(t&&t.headers)for(let i in t.headers)r[i]=t.headers[i];let n=WX[e];return r["Content-Type"]="text/html; charset=utf-8",r["Content-Length"]=n[1],r["Content-Security-Policy"]="default-src 'none'",r["X-Content-Type-Options"]="nosniff",{statusCode:e,headers:r,stream:Ou.from(n[0]),type:"error",metadata:{error:UX(e,t)}}}function dy(e){switch(e.code){case"ENAMETOOLONG":case"ENOTDIR":case"ENOENT":return Lr(404,e);default:return Lr(500,e)}}function rQ(e,t,r){return kt("not modified"),delete e["Content-Encoding"],delete e["Content-Language"],delete e["Content-Length"],delete e["Content-Range"],delete e["Content-Type"],{statusCode:304,headers:e,stream:Ou.from(""),type:"file",metadata:{path:t,stat:r}}}function hy(e,t,r,n){let i=r.size,s=n.start??0,o=200,a={};if(kt('send "%s"',t),n.acceptRanges&&(kt("accept ranges"),a["Accept-Ranges"]="bytes"),n.cacheControl){let c="public, max-age="+Math.floor(n.maxage/1e3);n.immutable&&(c+=", immutable"),kt("cache-control %s",c),a["Cache-Control"]=c}if(n.lastModified){let c=r.mtime.toUTCString();kt("modified %s",c),a["Last-Modified"]=c}if(n.etag){let c='W/"'+r.size.toString(16)+"-"+r.mtime.getTime().toString(16)+'"';kt("etag %s",c),a.ETag=c}if(n.contentType){let c=b1.getType(t)||b1.default_type;kt("content-type %s",c),c&&HX(c)&&(c+="; charset=utf-8"),c&&(a["Content-Type"]=c)}if(QX(e)){if(eQ(e,a))return Lr(412);if(ZX(e,a))return rQ(a,t,r)}if(i=Math.max(0,i-s),n.end!==void 0){let c=n.end-s+1;i>c&&(i=c)}if(n.acceptRanges){let c=e.headers.range;if(c!==void 0&&VX.test(c))if(tQ(e,a)){let u=zX(i,c);if(u.length===0)return kt("range unsatisfiable"),a["Content-Range"]=E1("bytes",i),Lr(416,{headers:{"Content-Range":a["Content-Range"]}});u.length===1&&(kt("range %j",u),o=206,n.maxContentRangeChunkSize&&(u[0].end=Math.min(u[0].end,u[0].start+n.maxContentRangeChunkSize-1)),a["Content-Range"]=E1("bytes",i,u[0]),s+=u[0].start,i=u[0].end-u[0].start+1)}else kt("range stale")}if(a["Content-Length"]=i,e.method==="HEAD")return{statusCode:o,headers:a,stream:Ou.from(""),type:"file",metadata:{path:t,stat:r}};let l=O1.createReadStream(t,{highWaterMark:n.highWaterMark,start:s,end:Math.max(s,s+i-1)});return{statusCode:o,headers:a,stream:l,type:"file",metadata:{path:t,stat:r}}}function nQ(e,t){if(k1(t.path))return Lr(403);let r=encodeURI(FX(t.path+"/")),n=ui("Redirecting","Redirecting to "+DX(r)),i={};return i["Content-Type"]="text/html; charset=utf-8",i["Content-Length"]=n[1],i["Content-Security-Policy"]="default-src 'none'",i["X-Content-Type-Options"]="nosniff",i.Location=r,{statusCode:301,headers:i,stream:Ou.from(n[0]),type:"directory",metadata:{requestPath:t.path,path:e}}}async function iQ(e,t,r){let n;for(let i=0;i<r.index.length;i++){let s=r.index[i],o=P1(t,s),{error:a,stat:l}=await fy(o);if(a){n=a;continue}if(!l.isDirectory())return hy(e,o,l,r)}return n?dy(n):Lr(404)}async function sQ(e,t,r){let{error:n,stat:i}=await fy(t);if(n&&n.code==="ENOENT"&&!BX(t)&&t[t.length-1]!==Tu){let s=n;for(let o=0;o<r.extensions.length;o++){let a=r.extensions[o],l=t+"."+a,{error:c,stat:u}=await fy(l);if(c){s=c;continue}if(u.isDirectory()){s=null;continue}return hy(e,l,u,r)}return s?dy(s):Lr(404)}return n?dy(n):i.isDirectory()?nQ(t,r):hy(e,t,i,r)}async function oQ(e,t,r){let n=YX(r);n.path=t;let i=XX(t,n.root),{path:s,parts:o}=i;if(i.statusCode!==void 0)return Lr(i.statusCode);if((kt.enabled||n.dotfiles!==0)&&MX(o))switch(n.dotfiles){case 0:kt('allow dotfile "%s"',s);break;case 2:return kt('deny dotfile "%s"',s),Lr(403);case 1:default:return kt('ignore dotfile "%s"',s),Lr(404)}return n.index.length&&k1(t)?iQ(e,s,n):sQ(e,s,n)}C1.exports.send=oQ});var I1=R((Soe,Ss)=>{"use strict";var aQ=Zg().isUtf8MimeType,lQ=ey(),py=$1().send;Ss.exports=py;Ss.exports.default=py;Ss.exports.send=py;Ss.exports.isUtf8MimeType=aQ;Ss.exports.mime=lQ});var N1=R((woe,ma)=>{"use strict";function gy(e){if(!new.target)return new gy(e);let{supportedValues:t=[],cache:r}=e&&typeof e=="object"&&e||{};this.supportedValues=t,this.cache=r}gy.prototype.negotiate=function(e){return typeof e!="string"?null:this.cache?(this.cache.has(e)||this.cache.set(e,pa(e,this.supportedValues)),this.cache.get(e)):pa(e,this.supportedValues)};function pa(e,t){if(!e||!Array.isArray(t)||t.length===0)return null;if(e==="*")return t[0];let r=null,n=1/0,i=0;function s(o,a){if(a===0||i>a)return!1;let l=o==="*"&&t[0]||o,c=t.indexOf(l);return c===-1?!1:c===0&&a===1?(r=l,!0):((i<a||n>c)&&(r=l,n=c,i=a),!1)}return cQ(e,s),r}var da=0,ha=1,xu=2,my=3;function cQ(e,t){let r="",n,i=da;for(let s=0,o=e.length;s<o;++s){let a=e[s];if(!(a===" "||a===" ")){if(a===";"){i===ha&&(i=xu,n="");continue}else if(a===","){if(i===ha){if(t(r,1)){i=my;break}i=da,r=""}else if(i===xu){if(t(r,parseFloat(n)||0)){i=my;break}i=da,r="",n=""}continue}else if(i===xu){if(a==="q"||a==="=")continue;if(a==="."||a==="1"||a==="0"||a==="2"||a==="3"||a==="4"||a==="5"||a==="6"||a==="7"||a==="8"||a==="9"){n+=a;continue}}else if(i===da){i=ha,r+=a;continue}if(i===ha){let l=e[s-1];(l===" "||l===" ")&&(r=""),r+=a;continue}if(t(r,parseFloat(n)||0)){i=my;break}i=da,r=a,n=""}}i===ha?t(r,1):i===xu&&t(r,parseFloat(n)||0)}ma.exports=pa;ma.exports.default=pa;ma.exports.negotiate=pa;ma.exports.Negotiator=gy});var H1=R((boe,yy)=>{"use strict";yy.exports=_Q;yy.exports.parse=bQ;var uQ=new TextDecoder("utf-8"),fQ=/[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g,q1=/[^\x20-\x7e\xa0-\xff]/g,dQ=/\\([\u0000-\u007f])/g,hQ=/([\\"])/g,L1=/;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g,pQ=/^[\x20-\x7e\x80-\xff]+$/,mQ=/^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/,gQ=/^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/,yQ=/^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/;function _Q(e,t){var r=t||{},n=r.type||"attachment",i=vQ(e,r.fallback);return SQ(new M1(n,i))}function vQ(e,t){if(e!==void 0){var r={};if(typeof e!="string")throw new TypeError("filename must be a string");if(t===void 0&&(t=!0),typeof t!="string"&&typeof t!="boolean")throw new TypeError("fallback must be a string or boolean");if(typeof t=="string"&&q1.test(t))throw new TypeError("fallback must be ISO-8859-1 string");var n=j1(e),i=pQ.test(n),s=typeof t!="string"?t&&F1(n):j1(t),o=typeof s=="string"&&s!==n;return(o||!i||OQ(n))&&(r["filename*"]=n),(i||o)&&(r.filename=o?s:n),r}}function SQ(e){var t=e.parameters,r=e.type;if(!r||typeof r!="string"||!mQ.test(r))throw new TypeError("invalid type");var n=String(r).toLowerCase();if(t&&typeof t=="object")for(var i,s=Object.keys(t).sort(),o=0;o<s.length;o++){i=s[o];var a=i.slice(-1)==="*"?TQ(t[i]):RQ(t[i]);n+="; "+i+"="+a}return n}function wQ(e){let t=gQ.exec(e);if(!t)throw new TypeError("invalid extended field value");let r=t[1].toLowerCase(),n=t[2];switch(r){case"iso-8859-1":{let i=D1(n);return F1(i)}case"utf-8":case"utf8":try{return decodeURIComponent(n)}catch{let i=D1(n),s=new Uint8Array(i.length);for(let o=0;o<i.length;o++)s[o]=i.charCodeAt(o);return uQ.decode(s)}}throw new TypeError("unsupported charset in extended field")}function F1(e){return String(e).replace(q1,"?")}function bQ(e){if(!e||typeof e!="string")throw new TypeError("argument string is required");var t=yQ.exec(e);if(!t)throw new TypeError("invalid type format");var r=t[0].length,n=t[1].toLowerCase(),i,s=[],o={},a;for(r=L1.lastIndex=t[0].slice(-1)===";"?r-1:r;t=L1.exec(e);){if(t.index!==r)throw new TypeError("invalid parameter format");if(r+=t[0].length,i=t[1].toLowerCase(),a=t[2],s.indexOf(i)!==-1)throw new TypeError("invalid duplicate parameter");if(s.push(i),i.indexOf("*")+1===i.length){i=i.slice(0,-1),a=wQ(a),o[i]=a;continue}typeof o[i]!="string"&&(a[0]==='"'&&(a=a.slice(1,-1).replace(dQ,"$1")),o[i]=a)}if(r!==-1&&r!==e.length)throw new TypeError("invalid parameter format");return new M1(n,o)}function EQ(e){return"%"+String(e).charCodeAt(0).toString(16).toUpperCase()}function RQ(e){var t=String(e);return'"'+t.replace(hQ,"\\$1")+'"'}function TQ(e){var t=String(e),r=encodeURIComponent(t).replace(fQ,EQ);return"UTF-8''"+r}function M1(e,t){this.type=e,this.parameters=t}function j1(e){let t=e.replaceAll("\\","/"),r=t.length;for(;r>0&&t[r-1]==="/";)r--;if(r===0)return"";let n=r-1;for(;n>=0&&t[n]!=="/";)n--;return t.slice(n+1,r)}function Pu(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function OQ(e){let t=e.length-3,r=-1;for(;(r=e.indexOf("%",r+1))!==-1&&r<=t;)if(Pu(e[r+1])&&Pu(e[r+2]))return!0;return!1}function D1(e){let t=e.indexOf("%");if(t===-1)return e;let r=e.slice(0,t);for(let n=t;n<e.length;n++)e[n]==="%"&&n+2<e.length&&Pu(e[n+1])&&Pu(e[n+2])?(r+=String.fromCharCode(Number.parseInt(e[n+1]+e[n+2],16)),n+=2):r+=e[n];return r}});var V1=R((Eoe,B1)=>{"use strict";var xQ=ee("node:os"),bt=ee("node:path"),Au=ee("node:fs/promises"),z1=Uu(),U1=Math.max(1,xQ.cpus().length-1);function PQ(e,t){let r=bt.relative(e,t);return r===""||r!==".."&&!r.startsWith(`..${bt.sep}`)&&!bt.isAbsolute(r)}var fi={_getExtendedInfo:async function(e,t){let r=e.split(bt.sep).length,n=await Au.readdir(e),i=async o=>{let a=bt.join(e,o),l;try{l=await Au.stat(a)}catch{return}l.isDirectory()?(t.totalFolderCount++,a.split(bt.sep).length===r+1&&t.folderCount++,await fi._getExtendedInfo(a,t)):(t.totalSize+=l.size,t.totalFileCount++,a.split(bt.sep).length===r+1&&t.fileCount++,t.lastModified=Math.max(t.lastModified,l.mtimeMs))},s=z1.promise(i,U1);await Promise.all(n.map(o=>s.push(o)))},getExtendedInfo:async function(e){let t={totalSize:0,fileCount:0,totalFileCount:0,folderCount:0,totalFolderCount:0,lastModified:0};return await fi._getExtendedInfo(e,t),t},list:async function(e,t,r){let n={dirs:[],files:[]},i=await Au.readdir(e);if((r==="deny"||r==="ignore")&&(i=i.filter(a=>a.charAt(0)!==".")),i.length<1)return n;let s=async a=>{let l;try{l=await Au.stat(bt.join(e,a))}catch{return}let c={name:a,stats:l};l.isDirectory()?(t.extendedFolderInfo&&(c.extendedInfo=await fi.getExtendedInfo(bt.join(e,a))),n.dirs.push(c)):n.files.push(c)},o=z1.promise(s,U1);return await Promise.all(i.map(a=>o.push(a))),n.dirs.sort((a,l)=>a.name.localeCompare(l.name)),n.files.sort((a,l)=>a.name.localeCompare(l.name)),n},send:async function({reply:e,dir:t,options:r,route:n,prefix:i,dotfiles:s}){if(e.request.query.format==="html"&&typeof r.render!="function")throw new TypeError("The `list.render` option must be a function and is required with the URL parameter `format=html`");let o;try{o=await fi.list(t,r,s)}catch{return e.callNotFound()}if((e.request.query.format||r.format)!=="html"){if(r.jsonFormat!=="extended"){let c={dirs:[],files:[]};o.dirs.forEach(u=>c.dirs.push(u.name)),o.files.forEach(u=>c.files.push(u.name)),await e.send(c)}else await e.send(o);return}let l=r.render(o.dirs.map(c=>fi.htmlInfo(c,n,i,r)),o.files.map(c=>fi.htmlInfo(c,n,i,r)));await e.type("text/html").send(l)},htmlInfo:function(e,t,r,n){return n.names?.includes(bt.basename(t))&&(t=bt.posix.normalize(bt.posix.join(t,".."))),{href:encodeURI(bt.posix.join(r,t,e.name)),name:e.name,stats:e.stats,extendedInfo:e.extendedInfo}},handle:function(e,t){return t.names?.includes(bt.basename(e))||((t.names?.includes("/")&&e[e.length-1]==="/")??!1)},path:function(e,t){let r=t[t.length-1]==="/"?"."+t+"none":"."+t,n=bt.resolve(e),i=bt.dirname(bt.resolve(n,r));return PQ(n,i)?i:null},validateOptions:function(e){if(e.list){if(Array.isArray(e.root))return new TypeError("multi-root with list option is not supported");if(e.list.format&&e.list.format!=="json"&&e.list.format!=="html")return new TypeError("The `list.format` option must be json or html");if(e.list.names&&!Array.isArray(e.list.names))return new TypeError("The `list.names` option must be an array");if(e.list.jsonFormat!=null&&e.list.jsonFormat!=="names"&&e.list.jsonFormat!=="extended")return new TypeError("The `list.jsonFormat` option must be name or extended");if(e.list.format==="html"&&typeof e.list.render!="function")return new TypeError("The `list.render` option must be a function and is required with html format")}}};B1.exports=fi});var Q1=R((Roe,ku)=>{"use strict";var en=ee("node:path"),{fileURLToPath:G1}=ee("node:url"),{statSync:X1}=ee("node:fs"),{glob:AQ}=bC(),kQ=xC(),ya=I1(),CQ=N1(),$Q=H1(),ga=V1(),W1=/\/$/u,IQ=/\*/gu,NQ=["br","gzip","deflate"];ya.mime.default_type="application/octet-stream";var J1={br:".br",gzip:".gz"};async function vy(e,t){(t.serve!==!1||t.root!==void 0)&&(t.root=LQ(t.root),jQ(e,t.root));let r=t.setHeaders;if(r!==void 0&&typeof r!="function")throw new TypeError("The `setHeaders` option must be a function");let n=ga.validateOptions(t);if(n)throw n;t.dotfiles??="allow";let i={root:t.root,acceptRanges:t.acceptRanges,contentType:t.contentType,cacheControl:t.cacheControl,dotfiles:t.dotfiles,etag:t.etag,extensions:t.extensions,immutable:t.immutable,index:t.index,lastModified:t.lastModified,maxAge:t.maxAge},s=t.prefix??="/";t.prefixAvoidTrailingSlash||(s=s[s.length-1]==="/"?s:s+"/");let o={constraints:t.constraints,schema:{hide:t.schemaHide??!0},logLevel:t.logLevel,errorHandler(m,h,f){if(m?.code==="ERR_STREAM_PREMATURE_CLOSE"){f.request.raw.destroy();return}e.errorHandler(m,h,f)}};if(t.decorateReply!==!1&&(e.decorateReply("sendFile",function(m,h,f){let p=typeof h=="object"?h:f,g=typeof h=="string"?h:p?.root;return c(this.request,this,m,g||i.root,0,p),this}),e.decorateReply("download",function(m,h,f={}){let{root:p,...g}=typeof h=="object"?h:f;return h=typeof h=="string"?h:m,this.header("content-disposition",$Q(h)),c(this.request,this,m,p,0,g),this})),t.serve!==!1){if(t.wildcard&&typeof t.wildcard!="boolean")throw new TypeError('"wildcard" option must be a boolean');if(t.wildcard===void 0||t.wildcard===!0){let m;e.route({...o,method:["HEAD","GET"],path:s+"*",handler(h,f){m??=HQ(h.routeOptions.url);let p=zQ(h.raw.url,m);if(!p)return f.callNotFound();c(h,f,p,i.root)}}),t.redirect===!0&&s!==t.prefix&&e.get(t.prefix,o,(h,f)=>{f.redirect(Y1(h.raw.url),301)})}else{let m=new Set(t.index===void 0?["index.html"]:[].concat(t.index)),h=new Map,f=new Set,p=Array.isArray(i.root)?i.root:[i.root];for(let g of p){g=g.split(en.win32.sep).join(en.posix.sep),!g.endsWith("/")&&(g+="/");let _=await AQ("**/**",{cwd:g,absolute:!1,follow:!0,nodir:!0,dot:t.serveDotFiles,ignore:t.globIgnore});for(let w of _){w=w.split(en.win32.sep).join(en.posix.sep);let S=s+w;if(f.has(S))continue;f.add(S),u(o,S,`/${w}`,g);let v=en.posix.basename(S);m.has(v)&&!h.has(v)&&h.set(en.posix.dirname(S),g)}}for(let[g,_]of h.entries()){let w=g+(g.endsWith("/")?"":"/"),S="/"+w.replace(s,"");u(o,w,S,_),t.redirect===!0&&u(o,w.replace(W1,""),S.replace(W1,""),_)}}}let a=t.allowedPath;async function l(m,h){let f=ga.path(t.root,h);return f?(await ga.send({reply:m,dir:f,options:t.list,route:h,prefix:s,dotfiles:t.dotfiles}).catch(p=>m.send(p)),!0):!1}async function c(m,h,f,p,g=0,_,w){let S=f,v=Object.assign({},i,_);if(p)Array.isArray(p)?v.root=p[g]:v.root=p;else if(en.isAbsolute(f)===!1)return h.callNotFound();if(a&&!a(f,v.root,m))return h.callNotFound();let E,A=f;if(t.preCompressed&&(w??=new Set,E=qQ(m.headers,w),E))if(f.endsWith("/")){if(f=_y(f,v.root,v.index),!f)return h.callNotFound();A=A+f+J1[E]}else A=f+J1[E];let{statusCode:P,headers:T,stream:$,type:x,metadata:C}=await ya(m.raw,encodeURI(A),v);switch(x){case"directory":{let I=C.path;if(t.list&&await ga.send({reply:h,dir:I,options:t.list,route:f,prefix:s,dotfiles:t.dotfiles}).catch(j=>h.send(j)),t.redirect===!0)try{h.redirect(Y1(m.raw.url),301)}catch(j){await h.send(j)}else{if(!f.endsWith("/")&&_y(f,v.root,v.index))return c(m,h,f+"/",p,void 0,_,w);h.callNotFound()}break}case"error":{if(P===403&&(!v.index||!v.index.length)&&A[A.length-1]==="/"&&t.list&&await l(h,f))return;if(C.error.code==="ENOENT")return t.preCompressed&&E&&t.redirect!==!0&&_y(f,v.root,v.index)?c(m,h,f+"/",p,void 0,_,w):t.list&&ga.handle(f,t.list)&&await l(h,f)?void 0:Array.isArray(p)&&g<p.length-1?c(m,h,f,p,g+1,_,void 0):t.preCompressed&&!w.has(E)?(w.add(E),c(m,h,S,p,g,_,w)):h.callNotFound();if(C.error.status===404)return h.callNotFound();await h.send(C.error);break}case"file":{let I=h.statusCode!==200?h.statusCode:P;h.code(I),r?.(h.raw,C.path,C.stat),h.headers(T),E&&(h.header("content-type",DQ(f)),h.header("content-encoding",E)),await h.send($);break}}}function u(m,h,f,p){let g=Object.assign({},m,{method:["HEAD","GET"],url:h,handler:d});g.config??={},g.config.file=f,g.config.rootPath=p,e.route(g)}async function d(m,h){let f=m.routeOptions?.config;return c(m,h,f.file,f.rootPath)}}function LQ(e){if(e===void 0)return e;if(e instanceof URL&&e.protocol==="file:")return G1(e);if(Array.isArray(e)){let t=[];for(let r=0,n=e.length;r<n;++r)e[r]instanceof URL&&e[r].protocol==="file:"?t.push(G1(e[r])):t.push(e[r]);return t}return e}function jQ(e,t){if(t===void 0)throw new Error('"root" option is required');if(Array.isArray(t)){if(!t.length)throw new Error('"root" option array requires one or more paths');if(new Set(t).size!==t.length)throw new Error('"root" option array contains one or more duplicate paths');t.map(r=>K1(e,r));return}if(typeof t=="string")return K1(e,t);throw new Error('"root" option must be a string or array of strings')}function K1(e,t){if(typeof t!="string")throw new TypeError('"root" option must be a string');if(en.isAbsolute(t)===!1)throw new Error('"root" option must be an absolute path');let r;try{r=X1(t)}catch(n){if(n.code==="ENOENT"){e.log.warn(`"root" path "${t}" must exist`);return}throw n}if(r.isDirectory()===!1)throw new Error('"root" option must point to a directory')}function DQ(e){let t=ya.mime.getType(e)||ya.mime.default_type;return ya.isUtf8MimeType(t)?`${t}; charset=utf-8`:t}function _y(e,t,r=["index.html"]){return Array.isArray(r)?r.find(n=>{let i=en.join(t,e,n);try{return!X1(i).isDirectory()}catch{return!1}}):!1}function qQ(e,t){if(!("accept-encoding"in e))return;let r=e["accept-encoding"].toLowerCase().replace(IQ,"gzip");return CQ.negotiate(r,NQ.filter(n=>!t.has(n)))}function FQ(e){let t=[],r=0,n=0;for(;r<e.length;){if(e[r]!==":"){r++;continue}for(n!==r&&t.push(e.slice(n,r)),r++;r<e.length&&e[r]!=="/";)r++;t.push(void 0),n=r}return n!==e.length&&t.push(e.slice(n)),t}function MQ(e,t,r){let n=0;for(let i of r){if(i===void 0){let o=n,a=e.indexOf("/",n);if(n=a===-1||a>t?t:a,n===o)return;continue}let s=n+i.length;if(s>t||!e.startsWith(i,n))return;n=s}return n}function HQ(e){let t=e.replace(/\*$/u,""),r=t.length;if(t==="/")return()=>0;if(t.includes(":")===!1)return(i,s)=>r<=s&&i.startsWith(t)?r:void 0;let n=FQ(t);return(i,s)=>MQ(i,s,n)}function zQ(e,t){let r=e.indexOf("?"),n=r===-1?e.length:r,i=t(e,n);if(i===void 0)return;let s=e.slice(i,n);s===""?s="/":s.startsWith("/")||(s="/"+s);try{return decodeURI(s)}catch{}}function Y1(e){let t=0;for(let r=e.length;t<r&&!(e[t]!=="/"&&e[t]!=="\\");++t);e="/"+e.slice(t);try{let r=new URL(e,"http://localhost.com/"),n=r.pathname;return n+(n[n.length-1]!=="/"?"/":"")+(r.search||"")}catch{let r=new Error(`Invalid redirect URL: ${e}`);throw r.statusCode=400,r}}ku.exports=kQ(vy,{fastify:"5.x",name:"@fastify/static"});ku.exports.default=vy;ku.exports.fastifyStatic=vy});var F$=qy(sC(),1),M$=qy(Q1(),1);import{existsSync as jy}from"node:fs";import{spawn as pee}from"node:child_process";import{copyFileSync as UQ,existsSync as Sy,mkdirSync as BQ}from"node:fs";import{homedir as ws}from"node:os";import{dirname as VQ,join as Bt}from"node:path";import{fileURLToPath as GQ}from"node:url";var wy=VQ(GQ(import.meta.url));function Z1(e,t){return e.find(r=>Sy(r))??t}var by=Number(process.env.PORT??4317),Cu=Bt(wy,"..");function Iu(e){return e==="~"?ws():e.startsWith("~/")?Bt(ws(),e.slice(2)):e}var di=Iu(process.env.CLAUDE_PROJECTS_DIR??Bt(ws(),".claude","projects")),Ey=Iu(process.env.CODEX_SESSIONS_DIR??Bt(ws(),".codex","sessions")),Nu=Iu(process.env.JUNIE_SESSIONS_DIR??Bt(ws(),".junie","sessions")),e$=process.env.OPEN_BROWSER==="1",Ry=Number(process.env.REINDEX_INTERVAL_MS??15e3),hi=Iu(process.env.CLAUDESCOPE_HOME??Bt(ws(),".claudescope")),va=process.env.DUCKDB_PATH??Bt(hi,"index.duckdb"),$u=Z1([Bt(wy,"pricing.default.json"),Bt(Cu,"pricing.json")],Bt(Cu,"pricing.json")),_a=process.env.PRICING_PATH??Bt(hi,"pricing.json"),Lu=process.env.WEB_DIST_DIR??Z1([Bt(wy,"web"),Bt(Cu,"..","web","dist")],Bt(Cu,"..","web","dist")),ju="0.4.0";function t$(){BQ(hi,{recursive:!0}),!Sy(_a)&&Sy($u)&&UQ($u,_a)}import{createHash as WQ}from"node:crypto";import{mkdirSync as JQ,rmSync as KQ}from"node:fs";import{dirname as YQ}from"node:path";import{DuckDBInstance as XQ}from"@duckdb/node-api";var Ty=["CREATE TABLE IF NOT EXISTS meta (key VARCHAR PRIMARY KEY, value VARCHAR)",`CREATE TABLE IF NOT EXISTS files (
392
+ }`)(e,bu,this,t,i);return s}function vX(e,t,r){if(!e||typeof e!="object"&&typeof e!="function")throw new TypeError("argument obj must be object");var n=Object.getOwnPropertyDescriptor(e,t);if(!n)throw new TypeError("must call property on owner object");if(!n.configurable)throw new TypeError("property must be configurable");var i=this,s=Eu(),o=_s(s[1]);o.name=t,"value"in n&&(n=lX(e,t,r));var a=n.get,l=n.set;typeof a=="function"&&(n.get=function(){return bu.call(i,r,o),a.apply(this,arguments)}),typeof l=="function"&&(n.set=function(){return bu.call(i,r,o),l.apply(this,arguments)}),Object.defineProperty(e,t,n)}function r1(e,t,r){var n=new Error,i;return Object.defineProperty(n,"constructor",{value:r1}),Object.defineProperty(n,"message",{configurable:!0,enumerable:!1,value:t,writable:!0}),Object.defineProperty(n,"name",{enumerable:!1,configurable:!0,value:"DeprecationError",writable:!0}),Object.defineProperty(n,"namespace",{configurable:!0,enumerable:!1,value:e,writable:!0}),Object.defineProperty(n,"stack",{configurable:!0,enumerable:!1,get:function(){return i!==void 0?i:i=uX.call(this,r)},set:function(o){i=o}}),n}});var o1=R((foe,s1)=>{"use strict";s1.exports=Object.setPrototypeOf||({__proto__:[]}instanceof Array?SX:wX);function SX(e,t){return e.__proto__=t,e}function wX(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=t[r]);return e}});var a1=R((doe,bX)=>{bX.exports={"100":"Continue","101":"Switching Protocols","102":"Processing","103":"Early Hints","200":"OK","201":"Created","202":"Accepted","203":"Non-Authoritative Information","204":"No Content","205":"Reset Content","206":"Partial Content","207":"Multi-Status","208":"Already Reported","226":"IM Used","300":"Multiple Choices","301":"Moved Permanently","302":"Found","303":"See Other","304":"Not Modified","305":"Use Proxy","307":"Temporary Redirect","308":"Permanent Redirect","400":"Bad Request","401":"Unauthorized","402":"Payment Required","403":"Forbidden","404":"Not Found","405":"Method Not Allowed","406":"Not Acceptable","407":"Proxy Authentication Required","408":"Request Timeout","409":"Conflict","410":"Gone","411":"Length Required","412":"Precondition Failed","413":"Payload Too Large","414":"URI Too Long","415":"Unsupported Media Type","416":"Range Not Satisfiable","417":"Expectation Failed","418":"I'm a Teapot","421":"Misdirected Request","422":"Unprocessable Entity","423":"Locked","424":"Failed Dependency","425":"Too Early","426":"Upgrade Required","428":"Precondition Required","429":"Too Many Requests","431":"Request Header Fields Too Large","451":"Unavailable For Legal Reasons","500":"Internal Server Error","501":"Not Implemented","502":"Bad Gateway","503":"Service Unavailable","504":"Gateway Timeout","505":"HTTP Version Not Supported","506":"Variant Also Negotiates","507":"Insufficient Storage","508":"Loop Detected","509":"Bandwidth Limit Exceeded","510":"Not Extended","511":"Network Authentication Required"}});var u1=R((hoe,c1)=>{"use strict";var iy=a1();c1.exports=vr;vr.message=iy;vr.code=EX(iy);vr.codes=RX(iy);vr.redirect={300:!0,301:!0,302:!0,303:!0,305:!0,307:!0,308:!0};vr.empty={204:!0,205:!0,304:!0};vr.retry={502:!0,503:!0,504:!0};function EX(e){var t={};return Object.keys(e).forEach(function(n){var i=e[n],s=Number(n);t[i.toLowerCase()]=s}),t}function RX(e){return Object.keys(e).map(function(r){return Number(r)})}function TX(e){var t=e.toLowerCase();if(!Object.prototype.hasOwnProperty.call(vr.code,t))throw new Error('invalid status message: "'+e+'"');return vr.code[t]}function l1(e){if(!Object.prototype.hasOwnProperty.call(vr.message,e))throw new Error("invalid status code: "+e);return vr.message[e]}function vr(e){if(typeof e=="number")return l1(e);if(typeof e!="string")throw new TypeError("code must be a number or string");var t=parseInt(e,10);return isNaN(t)?TX(e):l1(t)}});var f1=R((poe,sy)=>{typeof Object.create=="function"?sy.exports=function(t,r){r&&(t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:sy.exports=function(t,r){if(r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}}});var d1=R((moe,ay)=>{try{if(oy=ee("util"),typeof oy.inherits!="function")throw"";ay.exports=oy.inherits}catch{ay.exports=f1()}var oy});var p1=R((goe,h1)=>{"use strict";h1.exports=OX;function OX(e){return e.split(" ").map(function(t){return t.slice(0,1).toUpperCase()+t.slice(1)}).join("").replace(/[^ _0-9a-z]/gi,"")}});var v1=R((yoe,ci)=>{"use strict";var xX=i1()("http-errors"),m1=o1(),vs=u1(),ly=d1(),PX=p1();ci.exports=Ru;ci.exports.HttpError=AX();ci.exports.isHttpError=CX(ci.exports.HttpError);IX(ci.exports,vs.codes,ci.exports.HttpError);function g1(e){return+(String(e).charAt(0)+"00")}function Ru(){for(var e,t,r=500,n={},i=0;i<arguments.length;i++){var s=arguments[i],o=typeof s;if(o==="object"&&s instanceof Error)e=s,r=e.status||e.statusCode||r;else if(o==="number"&&i===0)r=s;else if(o==="string")t=s;else if(o==="object")n=s;else throw new TypeError("argument #"+(i+1)+" unsupported type "+o)}typeof r=="number"&&(r<400||r>=600)&&xX("non-error status code; use only 4xx or 5xx status codes"),(typeof r!="number"||!vs.message[r]&&(r<400||r>=600))&&(r=500);var a=Ru[r]||Ru[g1(r)];e||(e=a?new a(t):new Error(t||vs.message[r]),Error.captureStackTrace(e,Ru)),(!a||!(e instanceof a)||e.status!==r)&&(e.expose=r<500,e.status=e.statusCode=r);for(var l in n)l!=="status"&&l!=="statusCode"&&(e[l]=n[l]);return e}function AX(){function e(){throw new TypeError("cannot construct abstract class")}return ly(e,Error),e}function kX(e,t,r){var n=_1(t);function i(s){var o=s??vs.message[r],a=new Error(o);return Error.captureStackTrace(a,i),m1(a,i.prototype),Object.defineProperty(a,"message",{enumerable:!0,configurable:!0,value:o,writable:!0}),Object.defineProperty(a,"name",{enumerable:!1,configurable:!0,value:n,writable:!0}),a}return ly(i,e),y1(i,n),i.prototype.status=r,i.prototype.statusCode=r,i.prototype.expose=!0,i}function CX(e){return function(r){return!r||typeof r!="object"?!1:r instanceof e?!0:r instanceof Error&&typeof r.expose=="boolean"&&typeof r.statusCode=="number"&&r.status===r.statusCode}}function $X(e,t,r){var n=_1(t);function i(s){var o=s??vs.message[r],a=new Error(o);return Error.captureStackTrace(a,i),m1(a,i.prototype),Object.defineProperty(a,"message",{enumerable:!0,configurable:!0,value:o,writable:!0}),Object.defineProperty(a,"name",{enumerable:!1,configurable:!0,value:n,writable:!0}),a}return ly(i,e),y1(i,n),i.prototype.status=r,i.prototype.statusCode=r,i.prototype.expose=!1,i}function y1(e,t){var r=Object.getOwnPropertyDescriptor(e,"name");r&&r.configurable&&(r.value=t,Object.defineProperty(e,"name",r))}function IX(e,t,r){t.forEach(function(i){var s,o=PX(vs.message[i]);switch(g1(i)){case 400:s=kX(r,o,i);break;case 500:s=$X(r,o,i);break}s&&(e[i]=s,e[o]=s)})}function _1(e){return e.slice(-5)==="Error"?e:e+"Error"}});var w1=R((_oe,S1)=>{"use strict";var cy=v1();function NX(e,t){return t?t instanceof Error?cy(e,t,{expose:!1}):cy(e,t):cy(e)}S1.exports.createHttpError=NX});var $1=R((voe,C1)=>{"use strict";var O1=ee("node:fs"),fa=ee("node:path"),LX=ee("node:stream"),kt=ee("node:util").debuglog("send"),jX=Qm(),DX=DC(),b1=ey(),qX=qC(),{collapseLeadingSlashes:FX}=MC(),{containsDotFile:MX}=zC(),{contentRange:E1}=BC(),{createHtmlDocument:ui}=GC(),{isUtf8MimeType:HX}=Zg(),{normalizeList:R1}=JC(),{parseBytesRange:zX}=YC(),{parseTokenList:x1}=ZC(),{createHttpError:UX}=w1(),BX=fa.extname,P1=fa.join,uy=fa.normalize,A1=fa.resolve,Tu=fa.sep,Ou=LX.Readable,VX=/^ *bytes=/,GX=60*60*24*365*1e3,T1=/(?:^|[\\/])\.\.(?:[\\/]|$)/,WX={400:ui("Error","Bad Request"),403:ui("Error","Forbidden"),404:ui("Error","Not Found"),412:ui("Error","Precondition Failed"),416:ui("Error","Range Not Satisfiable"),500:ui("Error","Internal Server Error")},JX=["allow","ignore","deny"];function KX(e){let t;return typeof e=="string"?t=qX.parse(e):t=Number(e),t!==t?0:Math.min(Math.max(0,t),GX)}function YX(e){e=e??{};let t=e.acceptRanges!==void 0?!!e.acceptRanges:!0,r=e.cacheControl!==void 0?!!e.cacheControl:!0,n=e.contentType!==void 0?!!e.contentType:!0,i=e.etag!==void 0?!!e.etag:!0,s=e.dotfiles!==void 0?JX.indexOf(e.dotfiles):1;if(s===-1)throw new TypeError('dotfiles option must be "allow", "deny", or "ignore"');let o=e.extensions!==void 0?R1(e.extensions,"extensions option"):[],a=e.immutable!==void 0?!!e.immutable:!1,l=e.index!==void 0?R1(e.index,"index option"):["index.html"],c=e.lastModified!==void 0?!!e.lastModified:!0,u=KX(e.maxAge??e.maxage),d=e.maxContentRangeChunkSize!==void 0?Number(e.maxContentRangeChunkSize):null,m=e.root?A1(e.root):null,h=Number.isSafeInteger(e.highWaterMark)&&e.highWaterMark>0?e.highWaterMark:null;return{acceptRanges:t,cacheControl:r,contentType:n,etag:i,dotfiles:s,extensions:o,immutable:a,index:l,lastModified:c,maxage:u,maxContentRangeChunkSize:d,root:m,highWaterMark:h,start:e.start,end:e.end}}function XX(e,t){let r=jX(e);if(r==null)return{statusCode:400};if(~r.indexOf("\0"))return{statusCode:400};let n;if(t!==null){if(r&&(r=uy("."+Tu+r)),T1.test(r))return kt('malicious path "%s"',r),{statusCode:403};n=r.split(Tu),r=uy(P1(t,r))}else{if(T1.test(r))return kt('malicious path "%s"',r),{statusCode:403};n=uy(r).split(Tu),r=A1(r)}return{path:r,parts:n}}function k1(e){return e[e.length-1]==="/"}function QX(e){return e.headers["if-match"]||e.headers["if-unmodified-since"]||e.headers["if-none-match"]||e.headers["if-modified-since"]}function ZX(e,t){if("cache-control"in e.headers&&e.headers["cache-control"].indexOf("no-cache")!==-1)return!1;if("if-none-match"in e.headers){let r=e.headers["if-none-match"];if(r==="*")return!0;let n=t.ETag;if(typeof n!="string")return!1;let i=n.length;return!!x1(r,function(o){let a=o.length;if(i===a&&o===n||i>a&&"W/"+o===n)return!0})}if("if-modified-since"in e.headers){let r=e.headers["if-modified-since"],n=t["Last-Modified"];if(!n||Date.parse(n)<=Date.parse(r))return!0}return!1}function eQ(e,t){let r=e.headers["if-match"];if(r){let n=t.ETag;if(r!=="*"&&(x1(r,function(s){if(s===n||"W/"+s===n)return!0})||!1)!==!0)return!0}if("if-unmodified-since"in e.headers){let n=e.headers["if-unmodified-since"],i=Date.parse(n);if(i===i){let s=Date.parse(t["Last-Modified"]);if(s!==s||s>i)return!0}}return!1}function tQ(e,t){if(!("if-range"in e.headers))return!0;let r=e.headers["if-range"];if(r.indexOf('"')!==-1){let s=t.ETag;return s&&r.indexOf(s)!==-1||!1}let n=Date.parse(r);if(n!==n)return!1;let i=Date.parse(t["Last-Modified"]);return i!==i||i<=n}function fy(e){return new Promise(t=>{O1.stat(e,function(n,i){t({error:n,stat:i})})})}function Lr(e,t){let r={};if(t&&t.headers)for(let i in t.headers)r[i]=t.headers[i];let n=WX[e];return r["Content-Type"]="text/html; charset=utf-8",r["Content-Length"]=n[1],r["Content-Security-Policy"]="default-src 'none'",r["X-Content-Type-Options"]="nosniff",{statusCode:e,headers:r,stream:Ou.from(n[0]),type:"error",metadata:{error:UX(e,t)}}}function dy(e){switch(e.code){case"ENAMETOOLONG":case"ENOTDIR":case"ENOENT":return Lr(404,e);default:return Lr(500,e)}}function rQ(e,t,r){return kt("not modified"),delete e["Content-Encoding"],delete e["Content-Language"],delete e["Content-Length"],delete e["Content-Range"],delete e["Content-Type"],{statusCode:304,headers:e,stream:Ou.from(""),type:"file",metadata:{path:t,stat:r}}}function hy(e,t,r,n){let i=r.size,s=n.start??0,o=200,a={};if(kt('send "%s"',t),n.acceptRanges&&(kt("accept ranges"),a["Accept-Ranges"]="bytes"),n.cacheControl){let c="public, max-age="+Math.floor(n.maxage/1e3);n.immutable&&(c+=", immutable"),kt("cache-control %s",c),a["Cache-Control"]=c}if(n.lastModified){let c=r.mtime.toUTCString();kt("modified %s",c),a["Last-Modified"]=c}if(n.etag){let c='W/"'+r.size.toString(16)+"-"+r.mtime.getTime().toString(16)+'"';kt("etag %s",c),a.ETag=c}if(n.contentType){let c=b1.getType(t)||b1.default_type;kt("content-type %s",c),c&&HX(c)&&(c+="; charset=utf-8"),c&&(a["Content-Type"]=c)}if(QX(e)){if(eQ(e,a))return Lr(412);if(ZX(e,a))return rQ(a,t,r)}if(i=Math.max(0,i-s),n.end!==void 0){let c=n.end-s+1;i>c&&(i=c)}if(n.acceptRanges){let c=e.headers.range;if(c!==void 0&&VX.test(c))if(tQ(e,a)){let u=zX(i,c);if(u.length===0)return kt("range unsatisfiable"),a["Content-Range"]=E1("bytes",i),Lr(416,{headers:{"Content-Range":a["Content-Range"]}});u.length===1&&(kt("range %j",u),o=206,n.maxContentRangeChunkSize&&(u[0].end=Math.min(u[0].end,u[0].start+n.maxContentRangeChunkSize-1)),a["Content-Range"]=E1("bytes",i,u[0]),s+=u[0].start,i=u[0].end-u[0].start+1)}else kt("range stale")}if(a["Content-Length"]=i,e.method==="HEAD")return{statusCode:o,headers:a,stream:Ou.from(""),type:"file",metadata:{path:t,stat:r}};let l=O1.createReadStream(t,{highWaterMark:n.highWaterMark,start:s,end:Math.max(s,s+i-1)});return{statusCode:o,headers:a,stream:l,type:"file",metadata:{path:t,stat:r}}}function nQ(e,t){if(k1(t.path))return Lr(403);let r=encodeURI(FX(t.path+"/")),n=ui("Redirecting","Redirecting to "+DX(r)),i={};return i["Content-Type"]="text/html; charset=utf-8",i["Content-Length"]=n[1],i["Content-Security-Policy"]="default-src 'none'",i["X-Content-Type-Options"]="nosniff",i.Location=r,{statusCode:301,headers:i,stream:Ou.from(n[0]),type:"directory",metadata:{requestPath:t.path,path:e}}}async function iQ(e,t,r){let n;for(let i=0;i<r.index.length;i++){let s=r.index[i],o=P1(t,s),{error:a,stat:l}=await fy(o);if(a){n=a;continue}if(!l.isDirectory())return hy(e,o,l,r)}return n?dy(n):Lr(404)}async function sQ(e,t,r){let{error:n,stat:i}=await fy(t);if(n&&n.code==="ENOENT"&&!BX(t)&&t[t.length-1]!==Tu){let s=n;for(let o=0;o<r.extensions.length;o++){let a=r.extensions[o],l=t+"."+a,{error:c,stat:u}=await fy(l);if(c){s=c;continue}if(u.isDirectory()){s=null;continue}return hy(e,l,u,r)}return s?dy(s):Lr(404)}return n?dy(n):i.isDirectory()?nQ(t,r):hy(e,t,i,r)}async function oQ(e,t,r){let n=YX(r);n.path=t;let i=XX(t,n.root),{path:s,parts:o}=i;if(i.statusCode!==void 0)return Lr(i.statusCode);if((kt.enabled||n.dotfiles!==0)&&MX(o))switch(n.dotfiles){case 0:kt('allow dotfile "%s"',s);break;case 2:return kt('deny dotfile "%s"',s),Lr(403);case 1:default:return kt('ignore dotfile "%s"',s),Lr(404)}return n.index.length&&k1(t)?iQ(e,s,n):sQ(e,s,n)}C1.exports.send=oQ});var I1=R((Soe,Ss)=>{"use strict";var aQ=Zg().isUtf8MimeType,lQ=ey(),py=$1().send;Ss.exports=py;Ss.exports.default=py;Ss.exports.send=py;Ss.exports.isUtf8MimeType=aQ;Ss.exports.mime=lQ});var N1=R((woe,ma)=>{"use strict";function gy(e){if(!new.target)return new gy(e);let{supportedValues:t=[],cache:r}=e&&typeof e=="object"&&e||{};this.supportedValues=t,this.cache=r}gy.prototype.negotiate=function(e){return typeof e!="string"?null:this.cache?(this.cache.has(e)||this.cache.set(e,pa(e,this.supportedValues)),this.cache.get(e)):pa(e,this.supportedValues)};function pa(e,t){if(!e||!Array.isArray(t)||t.length===0)return null;if(e==="*")return t[0];let r=null,n=1/0,i=0;function s(o,a){if(a===0||i>a)return!1;let l=o==="*"&&t[0]||o,c=t.indexOf(l);return c===-1?!1:c===0&&a===1?(r=l,!0):((i<a||n>c)&&(r=l,n=c,i=a),!1)}return cQ(e,s),r}var da=0,ha=1,xu=2,my=3;function cQ(e,t){let r="",n,i=da;for(let s=0,o=e.length;s<o;++s){let a=e[s];if(!(a===" "||a===" ")){if(a===";"){i===ha&&(i=xu,n="");continue}else if(a===","){if(i===ha){if(t(r,1)){i=my;break}i=da,r=""}else if(i===xu){if(t(r,parseFloat(n)||0)){i=my;break}i=da,r="",n=""}continue}else if(i===xu){if(a==="q"||a==="=")continue;if(a==="."||a==="1"||a==="0"||a==="2"||a==="3"||a==="4"||a==="5"||a==="6"||a==="7"||a==="8"||a==="9"){n+=a;continue}}else if(i===da){i=ha,r+=a;continue}if(i===ha){let l=e[s-1];(l===" "||l===" ")&&(r=""),r+=a;continue}if(t(r,parseFloat(n)||0)){i=my;break}i=da,r=a,n=""}}i===ha?t(r,1):i===xu&&t(r,parseFloat(n)||0)}ma.exports=pa;ma.exports.default=pa;ma.exports.negotiate=pa;ma.exports.Negotiator=gy});var H1=R((boe,yy)=>{"use strict";yy.exports=_Q;yy.exports.parse=bQ;var uQ=new TextDecoder("utf-8"),fQ=/[\x00-\x20"'()*,/:;<=>?@[\\\]{}\x7f]/g,q1=/[^\x20-\x7e\xa0-\xff]/g,dQ=/\\([\u0000-\u007f])/g,hQ=/([\\"])/g,L1=/;[\x09\x20]*([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*=[\x09\x20]*("(?:[\x20!\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*/g,pQ=/^[\x20-\x7e\x80-\xff]+$/,mQ=/^[!#$%&'*+.0-9A-Z^_`a-z|~-]+$/,gQ=/^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+.^_`|~-])+)$/,yQ=/^([!#$%&'*+.0-9A-Z^_`a-z|~-]+)[\x09\x20]*(?:$|;)/;function _Q(e,t){var r=t||{},n=r.type||"attachment",i=vQ(e,r.fallback);return SQ(new M1(n,i))}function vQ(e,t){if(e!==void 0){var r={};if(typeof e!="string")throw new TypeError("filename must be a string");if(t===void 0&&(t=!0),typeof t!="string"&&typeof t!="boolean")throw new TypeError("fallback must be a string or boolean");if(typeof t=="string"&&q1.test(t))throw new TypeError("fallback must be ISO-8859-1 string");var n=j1(e),i=pQ.test(n),s=typeof t!="string"?t&&F1(n):j1(t),o=typeof s=="string"&&s!==n;return(o||!i||OQ(n))&&(r["filename*"]=n),(i||o)&&(r.filename=o?s:n),r}}function SQ(e){var t=e.parameters,r=e.type;if(!r||typeof r!="string"||!mQ.test(r))throw new TypeError("invalid type");var n=String(r).toLowerCase();if(t&&typeof t=="object")for(var i,s=Object.keys(t).sort(),o=0;o<s.length;o++){i=s[o];var a=i.slice(-1)==="*"?TQ(t[i]):RQ(t[i]);n+="; "+i+"="+a}return n}function wQ(e){let t=gQ.exec(e);if(!t)throw new TypeError("invalid extended field value");let r=t[1].toLowerCase(),n=t[2];switch(r){case"iso-8859-1":{let i=D1(n);return F1(i)}case"utf-8":case"utf8":try{return decodeURIComponent(n)}catch{let i=D1(n),s=new Uint8Array(i.length);for(let o=0;o<i.length;o++)s[o]=i.charCodeAt(o);return uQ.decode(s)}}throw new TypeError("unsupported charset in extended field")}function F1(e){return String(e).replace(q1,"?")}function bQ(e){if(!e||typeof e!="string")throw new TypeError("argument string is required");var t=yQ.exec(e);if(!t)throw new TypeError("invalid type format");var r=t[0].length,n=t[1].toLowerCase(),i,s=[],o={},a;for(r=L1.lastIndex=t[0].slice(-1)===";"?r-1:r;t=L1.exec(e);){if(t.index!==r)throw new TypeError("invalid parameter format");if(r+=t[0].length,i=t[1].toLowerCase(),a=t[2],s.indexOf(i)!==-1)throw new TypeError("invalid duplicate parameter");if(s.push(i),i.indexOf("*")+1===i.length){i=i.slice(0,-1),a=wQ(a),o[i]=a;continue}typeof o[i]!="string"&&(a[0]==='"'&&(a=a.slice(1,-1).replace(dQ,"$1")),o[i]=a)}if(r!==-1&&r!==e.length)throw new TypeError("invalid parameter format");return new M1(n,o)}function EQ(e){return"%"+String(e).charCodeAt(0).toString(16).toUpperCase()}function RQ(e){var t=String(e);return'"'+t.replace(hQ,"\\$1")+'"'}function TQ(e){var t=String(e),r=encodeURIComponent(t).replace(fQ,EQ);return"UTF-8''"+r}function M1(e,t){this.type=e,this.parameters=t}function j1(e){let t=e.replaceAll("\\","/"),r=t.length;for(;r>0&&t[r-1]==="/";)r--;if(r===0)return"";let n=r-1;for(;n>=0&&t[n]!=="/";)n--;return t.slice(n+1,r)}function Pu(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102}function OQ(e){let t=e.length-3,r=-1;for(;(r=e.indexOf("%",r+1))!==-1&&r<=t;)if(Pu(e[r+1])&&Pu(e[r+2]))return!0;return!1}function D1(e){let t=e.indexOf("%");if(t===-1)return e;let r=e.slice(0,t);for(let n=t;n<e.length;n++)e[n]==="%"&&n+2<e.length&&Pu(e[n+1])&&Pu(e[n+2])?(r+=String.fromCharCode(Number.parseInt(e[n+1]+e[n+2],16)),n+=2):r+=e[n];return r}});var V1=R((Eoe,B1)=>{"use strict";var xQ=ee("node:os"),bt=ee("node:path"),Au=ee("node:fs/promises"),z1=Uu(),U1=Math.max(1,xQ.cpus().length-1);function PQ(e,t){let r=bt.relative(e,t);return r===""||r!==".."&&!r.startsWith(`..${bt.sep}`)&&!bt.isAbsolute(r)}var fi={_getExtendedInfo:async function(e,t){let r=e.split(bt.sep).length,n=await Au.readdir(e),i=async o=>{let a=bt.join(e,o),l;try{l=await Au.stat(a)}catch{return}l.isDirectory()?(t.totalFolderCount++,a.split(bt.sep).length===r+1&&t.folderCount++,await fi._getExtendedInfo(a,t)):(t.totalSize+=l.size,t.totalFileCount++,a.split(bt.sep).length===r+1&&t.fileCount++,t.lastModified=Math.max(t.lastModified,l.mtimeMs))},s=z1.promise(i,U1);await Promise.all(n.map(o=>s.push(o)))},getExtendedInfo:async function(e){let t={totalSize:0,fileCount:0,totalFileCount:0,folderCount:0,totalFolderCount:0,lastModified:0};return await fi._getExtendedInfo(e,t),t},list:async function(e,t,r){let n={dirs:[],files:[]},i=await Au.readdir(e);if((r==="deny"||r==="ignore")&&(i=i.filter(a=>a.charAt(0)!==".")),i.length<1)return n;let s=async a=>{let l;try{l=await Au.stat(bt.join(e,a))}catch{return}let c={name:a,stats:l};l.isDirectory()?(t.extendedFolderInfo&&(c.extendedInfo=await fi.getExtendedInfo(bt.join(e,a))),n.dirs.push(c)):n.files.push(c)},o=z1.promise(s,U1);return await Promise.all(i.map(a=>o.push(a))),n.dirs.sort((a,l)=>a.name.localeCompare(l.name)),n.files.sort((a,l)=>a.name.localeCompare(l.name)),n},send:async function({reply:e,dir:t,options:r,route:n,prefix:i,dotfiles:s}){if(e.request.query.format==="html"&&typeof r.render!="function")throw new TypeError("The `list.render` option must be a function and is required with the URL parameter `format=html`");let o;try{o=await fi.list(t,r,s)}catch{return e.callNotFound()}if((e.request.query.format||r.format)!=="html"){if(r.jsonFormat!=="extended"){let c={dirs:[],files:[]};o.dirs.forEach(u=>c.dirs.push(u.name)),o.files.forEach(u=>c.files.push(u.name)),await e.send(c)}else await e.send(o);return}let l=r.render(o.dirs.map(c=>fi.htmlInfo(c,n,i,r)),o.files.map(c=>fi.htmlInfo(c,n,i,r)));await e.type("text/html").send(l)},htmlInfo:function(e,t,r,n){return n.names?.includes(bt.basename(t))&&(t=bt.posix.normalize(bt.posix.join(t,".."))),{href:encodeURI(bt.posix.join(r,t,e.name)),name:e.name,stats:e.stats,extendedInfo:e.extendedInfo}},handle:function(e,t){return t.names?.includes(bt.basename(e))||((t.names?.includes("/")&&e[e.length-1]==="/")??!1)},path:function(e,t){let r=t[t.length-1]==="/"?"."+t+"none":"."+t,n=bt.resolve(e),i=bt.dirname(bt.resolve(n,r));return PQ(n,i)?i:null},validateOptions:function(e){if(e.list){if(Array.isArray(e.root))return new TypeError("multi-root with list option is not supported");if(e.list.format&&e.list.format!=="json"&&e.list.format!=="html")return new TypeError("The `list.format` option must be json or html");if(e.list.names&&!Array.isArray(e.list.names))return new TypeError("The `list.names` option must be an array");if(e.list.jsonFormat!=null&&e.list.jsonFormat!=="names"&&e.list.jsonFormat!=="extended")return new TypeError("The `list.jsonFormat` option must be name or extended");if(e.list.format==="html"&&typeof e.list.render!="function")return new TypeError("The `list.render` option must be a function and is required with html format")}}};B1.exports=fi});var Q1=R((Roe,ku)=>{"use strict";var en=ee("node:path"),{fileURLToPath:G1}=ee("node:url"),{statSync:X1}=ee("node:fs"),{glob:AQ}=bC(),kQ=xC(),ya=I1(),CQ=N1(),$Q=H1(),ga=V1(),W1=/\/$/u,IQ=/\*/gu,NQ=["br","gzip","deflate"];ya.mime.default_type="application/octet-stream";var J1={br:".br",gzip:".gz"};async function vy(e,t){(t.serve!==!1||t.root!==void 0)&&(t.root=LQ(t.root),jQ(e,t.root));let r=t.setHeaders;if(r!==void 0&&typeof r!="function")throw new TypeError("The `setHeaders` option must be a function");let n=ga.validateOptions(t);if(n)throw n;t.dotfiles??="allow";let i={root:t.root,acceptRanges:t.acceptRanges,contentType:t.contentType,cacheControl:t.cacheControl,dotfiles:t.dotfiles,etag:t.etag,extensions:t.extensions,immutable:t.immutable,index:t.index,lastModified:t.lastModified,maxAge:t.maxAge},s=t.prefix??="/";t.prefixAvoidTrailingSlash||(s=s[s.length-1]==="/"?s:s+"/");let o={constraints:t.constraints,schema:{hide:t.schemaHide??!0},logLevel:t.logLevel,errorHandler(m,h,f){if(m?.code==="ERR_STREAM_PREMATURE_CLOSE"){f.request.raw.destroy();return}e.errorHandler(m,h,f)}};if(t.decorateReply!==!1&&(e.decorateReply("sendFile",function(m,h,f){let p=typeof h=="object"?h:f,g=typeof h=="string"?h:p?.root;return c(this.request,this,m,g||i.root,0,p),this}),e.decorateReply("download",function(m,h,f={}){let{root:p,...g}=typeof h=="object"?h:f;return h=typeof h=="string"?h:m,this.header("content-disposition",$Q(h)),c(this.request,this,m,p,0,g),this})),t.serve!==!1){if(t.wildcard&&typeof t.wildcard!="boolean")throw new TypeError('"wildcard" option must be a boolean');if(t.wildcard===void 0||t.wildcard===!0){let m;e.route({...o,method:["HEAD","GET"],path:s+"*",handler(h,f){m??=HQ(h.routeOptions.url);let p=zQ(h.raw.url,m);if(!p)return f.callNotFound();c(h,f,p,i.root)}}),t.redirect===!0&&s!==t.prefix&&e.get(t.prefix,o,(h,f)=>{f.redirect(Y1(h.raw.url),301)})}else{let m=new Set(t.index===void 0?["index.html"]:[].concat(t.index)),h=new Map,f=new Set,p=Array.isArray(i.root)?i.root:[i.root];for(let g of p){g=g.split(en.win32.sep).join(en.posix.sep),!g.endsWith("/")&&(g+="/");let _=await AQ("**/**",{cwd:g,absolute:!1,follow:!0,nodir:!0,dot:t.serveDotFiles,ignore:t.globIgnore});for(let w of _){w=w.split(en.win32.sep).join(en.posix.sep);let S=s+w;if(f.has(S))continue;f.add(S),u(o,S,`/${w}`,g);let v=en.posix.basename(S);m.has(v)&&!h.has(v)&&h.set(en.posix.dirname(S),g)}}for(let[g,_]of h.entries()){let w=g+(g.endsWith("/")?"":"/"),S="/"+w.replace(s,"");u(o,w,S,_),t.redirect===!0&&u(o,w.replace(W1,""),S.replace(W1,""),_)}}}let a=t.allowedPath;async function l(m,h){let f=ga.path(t.root,h);return f?(await ga.send({reply:m,dir:f,options:t.list,route:h,prefix:s,dotfiles:t.dotfiles}).catch(p=>m.send(p)),!0):!1}async function c(m,h,f,p,g=0,_,w){let S=f,v=Object.assign({},i,_);if(p)Array.isArray(p)?v.root=p[g]:v.root=p;else if(en.isAbsolute(f)===!1)return h.callNotFound();if(a&&!a(f,v.root,m))return h.callNotFound();let E,A=f;if(t.preCompressed&&(w??=new Set,E=qQ(m.headers,w),E))if(f.endsWith("/")){if(f=_y(f,v.root,v.index),!f)return h.callNotFound();A=A+f+J1[E]}else A=f+J1[E];let{statusCode:P,headers:T,stream:$,type:x,metadata:C}=await ya(m.raw,encodeURI(A),v);switch(x){case"directory":{let I=C.path;if(t.list&&await ga.send({reply:h,dir:I,options:t.list,route:f,prefix:s,dotfiles:t.dotfiles}).catch(j=>h.send(j)),t.redirect===!0)try{h.redirect(Y1(m.raw.url),301)}catch(j){await h.send(j)}else{if(!f.endsWith("/")&&_y(f,v.root,v.index))return c(m,h,f+"/",p,void 0,_,w);h.callNotFound()}break}case"error":{if(P===403&&(!v.index||!v.index.length)&&A[A.length-1]==="/"&&t.list&&await l(h,f))return;if(C.error.code==="ENOENT")return t.preCompressed&&E&&t.redirect!==!0&&_y(f,v.root,v.index)?c(m,h,f+"/",p,void 0,_,w):t.list&&ga.handle(f,t.list)&&await l(h,f)?void 0:Array.isArray(p)&&g<p.length-1?c(m,h,f,p,g+1,_,void 0):t.preCompressed&&!w.has(E)?(w.add(E),c(m,h,S,p,g,_,w)):h.callNotFound();if(C.error.status===404)return h.callNotFound();await h.send(C.error);break}case"file":{let I=h.statusCode!==200?h.statusCode:P;h.code(I),r?.(h.raw,C.path,C.stat),h.headers(T),E&&(h.header("content-type",DQ(f)),h.header("content-encoding",E)),await h.send($);break}}}function u(m,h,f,p){let g=Object.assign({},m,{method:["HEAD","GET"],url:h,handler:d});g.config??={},g.config.file=f,g.config.rootPath=p,e.route(g)}async function d(m,h){let f=m.routeOptions?.config;return c(m,h,f.file,f.rootPath)}}function LQ(e){if(e===void 0)return e;if(e instanceof URL&&e.protocol==="file:")return G1(e);if(Array.isArray(e)){let t=[];for(let r=0,n=e.length;r<n;++r)e[r]instanceof URL&&e[r].protocol==="file:"?t.push(G1(e[r])):t.push(e[r]);return t}return e}function jQ(e,t){if(t===void 0)throw new Error('"root" option is required');if(Array.isArray(t)){if(!t.length)throw new Error('"root" option array requires one or more paths');if(new Set(t).size!==t.length)throw new Error('"root" option array contains one or more duplicate paths');t.map(r=>K1(e,r));return}if(typeof t=="string")return K1(e,t);throw new Error('"root" option must be a string or array of strings')}function K1(e,t){if(typeof t!="string")throw new TypeError('"root" option must be a string');if(en.isAbsolute(t)===!1)throw new Error('"root" option must be an absolute path');let r;try{r=X1(t)}catch(n){if(n.code==="ENOENT"){e.log.warn(`"root" path "${t}" must exist`);return}throw n}if(r.isDirectory()===!1)throw new Error('"root" option must point to a directory')}function DQ(e){let t=ya.mime.getType(e)||ya.mime.default_type;return ya.isUtf8MimeType(t)?`${t}; charset=utf-8`:t}function _y(e,t,r=["index.html"]){return Array.isArray(r)?r.find(n=>{let i=en.join(t,e,n);try{return!X1(i).isDirectory()}catch{return!1}}):!1}function qQ(e,t){if(!("accept-encoding"in e))return;let r=e["accept-encoding"].toLowerCase().replace(IQ,"gzip");return CQ.negotiate(r,NQ.filter(n=>!t.has(n)))}function FQ(e){let t=[],r=0,n=0;for(;r<e.length;){if(e[r]!==":"){r++;continue}for(n!==r&&t.push(e.slice(n,r)),r++;r<e.length&&e[r]!=="/";)r++;t.push(void 0),n=r}return n!==e.length&&t.push(e.slice(n)),t}function MQ(e,t,r){let n=0;for(let i of r){if(i===void 0){let o=n,a=e.indexOf("/",n);if(n=a===-1||a>t?t:a,n===o)return;continue}let s=n+i.length;if(s>t||!e.startsWith(i,n))return;n=s}return n}function HQ(e){let t=e.replace(/\*$/u,""),r=t.length;if(t==="/")return()=>0;if(t.includes(":")===!1)return(i,s)=>r<=s&&i.startsWith(t)?r:void 0;let n=FQ(t);return(i,s)=>MQ(i,s,n)}function zQ(e,t){let r=e.indexOf("?"),n=r===-1?e.length:r,i=t(e,n);if(i===void 0)return;let s=e.slice(i,n);s===""?s="/":s.startsWith("/")||(s="/"+s);try{return decodeURI(s)}catch{}}function Y1(e){let t=0;for(let r=e.length;t<r&&!(e[t]!=="/"&&e[t]!=="\\");++t);e="/"+e.slice(t);try{let r=new URL(e,"http://localhost.com/"),n=r.pathname;return n+(n[n.length-1]!=="/"?"/":"")+(r.search||"")}catch{let r=new Error(`Invalid redirect URL: ${e}`);throw r.statusCode=400,r}}ku.exports=kQ(vy,{fastify:"5.x",name:"@fastify/static"});ku.exports.default=vy;ku.exports.fastifyStatic=vy});var F$=qy(sC(),1),M$=qy(Q1(),1);import{existsSync as jy}from"node:fs";import{spawn as pee}from"node:child_process";import{copyFileSync as UQ,existsSync as Sy,mkdirSync as BQ}from"node:fs";import{homedir as ws}from"node:os";import{dirname as VQ,join as Bt}from"node:path";import{fileURLToPath as GQ}from"node:url";var wy=VQ(GQ(import.meta.url));function Z1(e,t){return e.find(r=>Sy(r))??t}var by=Number(process.env.PORT??4317),Cu=Bt(wy,"..");function Iu(e){return e==="~"?ws():e.startsWith("~/")?Bt(ws(),e.slice(2)):e}var di=Iu(process.env.CLAUDE_PROJECTS_DIR??Bt(ws(),".claude","projects")),Ey=Iu(process.env.CODEX_SESSIONS_DIR??Bt(ws(),".codex","sessions")),Nu=Iu(process.env.JUNIE_SESSIONS_DIR??Bt(ws(),".junie","sessions")),e$=process.env.OPEN_BROWSER==="1",Ry=Number(process.env.REINDEX_INTERVAL_MS??15e3),hi=Iu(process.env.CLAUDESCOPE_HOME??Bt(ws(),".claudescope")),va=process.env.DUCKDB_PATH??Bt(hi,"index.duckdb"),$u=Z1([Bt(wy,"pricing.default.json"),Bt(Cu,"pricing.json")],Bt(Cu,"pricing.json")),_a=process.env.PRICING_PATH??Bt(hi,"pricing.json"),Lu=process.env.WEB_DIST_DIR??Z1([Bt(wy,"web"),Bt(Cu,"..","web","dist")],Bt(Cu,"..","web","dist")),ju="0.4.1";function t$(){BQ(hi,{recursive:!0}),!Sy(_a)&&Sy($u)&&UQ($u,_a)}import{createHash as WQ}from"node:crypto";import{mkdirSync as JQ,rmSync as KQ}from"node:fs";import{dirname as YQ}from"node:path";import{DuckDBInstance as XQ}from"@duckdb/node-api";var Ty=["CREATE TABLE IF NOT EXISTS meta (key VARCHAR PRIMARY KEY, value VARCHAR)",`CREATE TABLE IF NOT EXISTS files (
393
393
  path VARCHAR PRIMARY KEY,
394
394
  mtime_ms BIGINT NOT NULL,
395
395
  size_bytes BIGINT NOT NULL,