llmd 0.4.5 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/llmd +10 -9
  2. package/package.json +1 -1
package/dist/llmd CHANGED
@@ -692,10 +692,10 @@ ${s.notes}
692
692
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
693
693
  .main { padding: 20px; }
694
694
  }
695
- `},__=(e)=>{let n=[],t=new Map;for(let a of e){let i=a.path.split("/"),s=n,r="";for(let c=0;c<i.length-1;c++){let o=i[c];if(!o)continue;r=r.length>0?`${r}/${o}`:o;let u=t.get(r);if(u)s=u.children;else{let m={type:"directory",name:o,path:r,depth:c,children:[]};t.set(r,m),s.push(m),s=m.children}}s.push({type:"file",name:a.name,path:a.path,depth:a.depth,children:[]})}return n},Um=(e)=>{if(e.type==="file")return!0;return e.children.some((n)=>Um(n))},$_='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/></svg>',j_='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/></svg>',w_='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3v18h18"/><path d="M18 17l-4-4-4 4-4-4"/></svg>',x_='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 11-6 6v3h9l3-3"/><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"/></svg>',Om=(e,n)=>e.filter((t)=>Um(t)).map((t)=>{if(t.type==="directory"){let s=t.children.length>0?Om(t.children,n):"";if(!s)return"";return`<li class="dir-item">
696
- <div class="nav-link-dir dir-label depth-${t.depth}">${$_}<span>${t.name}/</span></div>
697
- <ul>${s}</ul>
698
- </li>`}let i=n===t.path?"active":"";return`<li><a href="/view/${t.path}" class="nav-link-file depth-${t.depth} ${i}" data-file-path="${t.path}">${j_}<span>${t.name}</span></a></li>`}).join(`
695
+ `},__=(e)=>{let n=[],t=new Map;for(let a of e){let i=a.path.split("/"),s=n,r="";for(let c=0;c<i.length-1;c++){let o=i[c];if(!o)continue;r=r.length>0?`${r}/${o}`:o;let u=t.get(r);if(u)s=u.children;else{let m={type:"directory",name:o,path:r,depth:c,children:[]};t.set(r,m),s.push(m),s=m.children}}s.push({type:"file",name:a.name,path:a.path,depth:a.depth,children:[]})}return n},Um=(e)=>{if(e.type==="file")return!0;return e.children.some((n)=>Um(n))},$_='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/></svg>',j_='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"/><path d="M14 2v5a1 1 0 0 0 1 1h5"/></svg>',w_='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3v18h18"/><path d="M18 17l-4-4-4 4-4-4"/></svg>',x_='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 11-6 6v3h9l3-3"/><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"/></svg>',Om=(e,n,t=0)=>e.filter((a)=>Um(a)).map((a)=>{if(a.type==="directory"){let r=a.children.length>0?Om(a.children,n,t+1):"";if(!r)return"";return`<li class="dir-item">
696
+ <div class="nav-link-dir dir-label depth-0">${$_}<span>${a.name}/</span></div>
697
+ <ul>${r}</ul>
698
+ </li>`}let s=n===a.path?"active":"";return`<li><a href="/view/${a.path}" class="nav-link-file depth-0 ${s}" data-file-path="${a.path}">${j_}<span>${a.name}</span></a></li>`}).join(`
699
699
  `),k_=()=>`
700
700
  <div class="admin-section" style="padding: 12px 12px 8px 12px; border-bottom: 1px solid var(--border);">
701
701
  <div class="admin-header" style="display: flex; align-items: center; justify-content: space-between; cursor: pointer; padding: 4px 6px; border-radius: 6px; transition: background 0.15s; user-select: none;">
@@ -1182,7 +1182,7 @@ ${s.notes}
1182
1182
 
1183
1183
  ---
1184
1184
 
1185
- `);return a+i},y$=(e,n)=>{let{ensureExportsDirectory:t}=(va(),He(ka)),{writeFileSync:a}=x("node:fs"),i=t(),s=xn(i,n);return a(s,e,"utf-8"),s},Us=()=>{let{readdirSync:e,statSync:n}=x("node:fs"),t=Ks();if(!ja(t))return[];return e(t).filter((i)=>i.endsWith(".md")).map((i)=>{let s=xn(t,i),r=n(s),c=i.split("_"),o=c[0]||"",u=Number.parseInt(c[1]||"0",10),m=c.slice(2).join("_");return{path:s,size:r.size,mtime:r.mtimeMs,resourceId:o,timestamp:u,originalName:m}}).sort((i,s)=>s.mtime-i.mtime)},h$=(e)=>{let{readFileSync:n}=x("node:fs"),a=Us().find((s)=>s.originalName===e||s.resourceId===e||s.path===e);if(!a)return null;let i=n(a.path,"utf-8");return{...a,content:i}},_$=()=>{let{rmSync:e}=x("node:fs"),n=Us(),t=n.reduce((i,s)=>i+s.size,0),a=n.length;for(let i of n)e(i.path);return{deletedCount:a,freedBytes:t}};var pt=G(()=>{P_=/\.md$/,i$=/\s+/g});import{execSync as ul}from"child_process";import{existsSync as $$}from"fs";import{homedir as j$}from"os";import{join as ml}from"path";import{spawn as gl}from"node:child_process";var xa=(e)=>{let n=process.platform;try{let t,a;if(n==="darwin")t="open",a=[e];else if(n==="win32")t="cmd",a=["/c","start",e];else t="xdg-open",a=[e];gl(t,a,{detached:!0,stdio:"ignore"}).unref()}catch(t){console.error("Failed to open browser:",t)}};import{existsSync as id}from"node:fs";import{dirname as sd,isAbsolute as rd,resolve as od}from"node:path";var Ms={name:"llmd",version:"0.4.5",description:"Local markdown server for LLM-generated docs",author:"Phil Zona <phil.b.zona@gmail.com>",license:"MIT",repository:{type:"git",url:"https://github.com/pbzona/llmd.git"},homepage:"https://github.com/pbzona/llmd#readme",bugs:{url:"https://github.com/pbzona/llmd/issues"},type:"module",bin:{llmd:"./dist/llmd"},files:["dist/llmd","dist/client.js","LICENSE","README.md"],engines:{node:">=22",bun:">=1.2.2"},publishConfig:{access:"public"},scripts:{dev:"bun --hot index.ts",test:"bun test",build:"bash scripts/build.sh",prepublishOnly:"bun test && bun run build","check-contrast":"bun scripts/check-contrast.ts",format:"biome format --write .","format:check":"biome format .",lint:"biome lint .","lint:fix":"biome lint --write .",check:"biome check --write .",prepare:"husky"},keywords:["markdown","server","documentation","html","llm"],dependencies:{"@types/ws":"^8.18.1","fast-glob":"^3.3.3",figlet:"^1.9.4",libsql:"^0.5.22",marked:"^17.0.1",shiki:"^3.20.0",ws:"^8.18.3"},devDependencies:{"@biomejs/biome":"2.3.8","@types/bun":"latest","@types/figlet":"^1.7.0",husky:"^9.1.7",ultracite:"6.4.1"},peerDependencies:{typescript:"^5"}};import{randomUUID as Dl}from"node:crypto";import{existsSync as Wl,mkdirSync as Ml}from"node:fs";import{homedir as Ll}from"node:os";import{basename as rr,dirname as or,join as yt}from"node:path";var Rl=["node_modules",".git","dist","build","test-fixtures"],cr=(e)=>{if(typeof Bun<"u"&&globalThis.Bun){let{Database:t}=x("bun:sqlite");return new t(e)}return new(x("libsql"))(e)},ur=()=>{let n=process.env.XDG_DATA_HOME||yt(Ll(),".local","share"),t=yt(n,"llmd");if(!Wl(t))Ml(t,{recursive:!0});return yt(t,"llmd.db")},Ja=(e,n)=>{if(e===n)return!1;return(e.startsWith(n)?e.slice(n.length+1):e).split("/").filter(Boolean).some((i)=>Rl.includes(i))},Fn=()=>Dl(),mr=(e)=>{e.exec("PRAGMA foreign_keys = ON"),e.exec(`
1185
+ `);return a+i},y$=(e,n)=>{let{ensureExportsDirectory:t}=(va(),He(ka)),{writeFileSync:a}=x("node:fs"),i=t(),s=xn(i,n);return a(s,e,"utf-8"),s},Us=()=>{let{readdirSync:e,statSync:n}=x("node:fs"),t=Ks();if(!ja(t))return[];return e(t).filter((i)=>i.endsWith(".md")).map((i)=>{let s=xn(t,i),r=n(s),c=i.split("_"),o=c[0]||"",u=Number.parseInt(c[1]||"0",10),m=c.slice(2).join("_");return{path:s,size:r.size,mtime:r.mtimeMs,resourceId:o,timestamp:u,originalName:m}}).sort((i,s)=>s.mtime-i.mtime)},h$=(e)=>{let{readFileSync:n}=x("node:fs"),a=Us().find((s)=>s.originalName===e||s.resourceId===e||s.path===e);if(!a)return null;let i=n(a.path,"utf-8");return{...a,content:i}},_$=()=>{let{rmSync:e}=x("node:fs"),n=Us(),t=n.reduce((i,s)=>i+s.size,0),a=n.length;for(let i of n)e(i.path);return{deletedCount:a,freedBytes:t}};var pt=G(()=>{P_=/\.md$/,i$=/\s+/g});import{execSync as ul}from"child_process";import{existsSync as $$}from"fs";import{homedir as j$}from"os";import{join as ml}from"path";import{spawn as gl}from"node:child_process";var xa=(e)=>{let n=process.platform;try{let t,a;if(n==="darwin")t="open",a=[e];else if(n==="win32")t="cmd",a=["/c","start",e];else t="xdg-open",a=[e];gl(t,a,{detached:!0,stdio:"ignore"}).unref()}catch(t){console.error("Failed to open browser:",t)}};import{existsSync as id}from"node:fs";import{dirname as sd,isAbsolute as rd,resolve as od}from"node:path";var Ms={name:"llmd",version:"0.4.7",description:"Local markdown server for LLM-generated docs",author:"Phil Zona <phil.b.zona@gmail.com>",license:"MIT",repository:{type:"git",url:"https://github.com/pbzona/llmd.git"},homepage:"https://github.com/pbzona/llmd#readme",bugs:{url:"https://github.com/pbzona/llmd/issues"},type:"module",bin:{llmd:"./dist/llmd"},files:["dist/llmd","dist/client.js","LICENSE","README.md"],engines:{node:">=22",bun:">=1.2.2"},publishConfig:{access:"public"},scripts:{dev:"bun --hot index.ts",test:"bun test",build:"bash scripts/build.sh",prepublishOnly:"bun test && bun run build","check-contrast":"bun scripts/check-contrast.ts",format:"biome format --write .","format:check":"biome format .",lint:"biome lint .","lint:fix":"biome lint --write .",check:"biome check --write .",prepare:"husky"},keywords:["markdown","server","documentation","html","llm"],dependencies:{"@types/ws":"^8.18.1","fast-glob":"^3.3.3",figlet:"^1.9.4",libsql:"^0.5.22",marked:"^17.0.1",shiki:"^3.20.0",ws:"^8.18.3"},devDependencies:{"@biomejs/biome":"2.3.8","@types/bun":"latest","@types/figlet":"^1.7.0",husky:"^9.1.7",ultracite:"6.4.1"},peerDependencies:{typescript:"^5"}};import{randomUUID as Dl}from"node:crypto";import{existsSync as Wl,mkdirSync as Ml}from"node:fs";import{homedir as Ll}from"node:os";import{basename as rr,dirname as or,join as yt}from"node:path";var Rl=["node_modules",".git","dist","build","test-fixtures"],cr=(e)=>{if(typeof Bun<"u"&&globalThis.Bun){let{Database:t}=x("bun:sqlite");return new t(e)}return new(x("libsql"))(e)},ur=()=>{let n=process.env.XDG_DATA_HOME||yt(Ll(),".local","share"),t=yt(n,"llmd");if(!Wl(t))Ml(t,{recursive:!0});return yt(t,"llmd.db")},Ja=(e,n)=>{if(e===n)return!1;return(e.startsWith(n)?e.slice(n.length+1):e).split("/").filter(Boolean).some((i)=>Rl.includes(i))},Fn=()=>Dl(),mr=(e)=>{e.exec("PRAGMA foreign_keys = ON"),e.exec(`
1186
1186
  CREATE TABLE IF NOT EXISTS resources (
1187
1187
  id TEXT PRIMARY KEY,
1188
1188
  path TEXT UNIQUE NOT NULL,
@@ -1261,6 +1261,7 @@ Commands:
1261
1261
  Options:
1262
1262
  -p, --port <number> Port to bind to (default: random)
1263
1263
  -t, --theme <name> Color theme (default: dark)
1264
+ -d, --tree-depth <num> Maximum tree depth to display (default: 5)
1264
1265
  -o, --open Auto-open browser (default)
1265
1266
  -n, --no-open Don't auto-open browser
1266
1267
  -w, --watch Reload on file changes
@@ -1268,7 +1269,7 @@ Options:
1268
1269
  -h, --help Show this help
1269
1270
 
1270
1271
  For more information, visit: https://github.com/pbzona/llmd
1271
- `,md=(e,n)=>{let t=e[n+1];if(t==="enable"||t==="disable"||t==="view")return{subcommand:t,nextIndex:n+1};return{subcommand:"view",nextIndex:n}},ld=(e,n)=>{let t=e[n+1];if(t==="check"||t==="cleanup"||t==="clear")return{subcommand:t,nextIndex:n+1};return{subcommand:"check",nextIndex:n}},dd=(e,n)=>{let t=e[n+1];if(t==="enable"||t==="disable")return{subcommand:t,nextIndex:n+1};return{subcommand:"enable",nextIndex:n}},pd=(e,n)=>{let t=e[n+1];if(t==="list"||t==="clear")return{subcommand:t,nextIndex:n+1};if(t==="show"){let a=e[n+2];return{subcommand:"show",nextIndex:n+2,path:a}}return{subcommand:"list",nextIndex:n}},bd=(e,n)=>{if(e==="-h"||e==="--help")return n.help=!0,!0;if(e==="-v"||e==="--version")return n.version=!0,!0;if(e==="docs")return n.docs=!0,!0;if(e==="-o"||e==="--open")return n.open=!0,!0;if(e==="-n"||e==="--no-open")return n.open=!1,!0;if(e==="-w"||e==="--watch")return n.watch=!0,!0;if(e==="--no-watch")return n.watch=!1,!0;return!1},gd=(e,n,t,a)=>{if(e==="-p"||e==="--port")return a.port=Number.parseInt(n[t+1]??"0",10),t+1;if(e==="-t"||e==="--theme")return a.theme=n[t+1],t+1;if(e==="analytics"){a.analytics=!0;let{subcommand:i,nextIndex:s}=md(n,t);return a.analyticsSubcommand=i,s}if(e==="highlights"){a.highlights=!0;let{subcommand:i,nextIndex:s}=dd(n,t);return a.highlightsSubcommand=i,s}if(e==="db"){a.db=!0;let{subcommand:i,nextIndex:s}=ld(n,t);return a.dbSubcommand=i,s}if(e==="archive"){a.archive=!0;let{subcommand:i,nextIndex:s,path:r}=pd(n,t);return a.archiveSubcommand=i,a.archivePath=r,s}if(e==="export"){a.export=!0;let i=n[t+1];if(i&&!i.startsWith("--"))return a.exportPath=i,t+1;return t}if(e==="--days"){let i=Number.parseInt(n[t+1]??"30",10);return a.days=Number.isNaN(i)?30:i,t+1}return t},fd=(e)=>{let n={},t;for(let a=0;a<e.length;a+=1){let i=e[a];if(!i)continue;if(bd(i,n))continue;let s=gd(i,e,a,n);if(s!==a){a=s;continue}if(!i.startsWith("-"))t=i}return{path:t,flags:n}},yd=(e)=>{let n=rd(e)?e:od(process.cwd(),e);if(n.endsWith(".md"))return{directory:sd(n),initialFile:n};return{directory:n}},hd=(e)=>{let{path:n=".",flags:t}=e,{directory:a,initialFile:i}=yd(n),s=pr();return{directory:a,initialFile:i,port:t.port??0,theme:t.theme??s.theme??"dark",open:t.open??!0,watch:t.watch??!1,openToAnalytics:t.analytics??!1}},_d=(e)=>{if(!id(e.directory))throw Error(`Directory not found: ${e.directory}`);if(!gr(e.theme)){let n=br();throw Error(`Theme "${e.theme}" not found. Available themes: ${n.join(", ")}`)}if(e.port<0||e.port>65535)throw Error(`Invalid port: ${e.port}. Must be 0-65535`)},$d=()=>{console.log(ud)},jd=()=>{console.log(`llmd v${cd}`)},wd=(e)=>{if(e==="enable")return{type:"analytics-enable"};if(e==="disable")return{type:"analytics-disable"};return null},xd=(e,n)=>{if(e==="check")return{type:"db-check"};if(e==="cleanup")return{type:"db-cleanup",days:n??30};return{type:"db-clear"}},kd=(e)=>{if(e==="enable")return{type:"highlights-enable"};return{type:"highlights-disable"}},vd=(e,n)=>{if(e==="list")return{type:"archive-list"};if(e==="show"){if(!n)throw Error("archive show requires a path argument");return{type:"archive-show",path:n}}return{type:"archive-clear"}},Oa=(e)=>{let n=fd(e);if(n.flags.help)return $d(),{type:"exit"};if(n.flags.version)return jd(),{type:"exit"};if(n.flags.docs)return{type:"docs"};if(n.flags.analytics&&n.flags.analyticsSubcommand){let a=wd(n.flags.analyticsSubcommand);if(a)return a}if(n.flags.highlights&&n.flags.highlightsSubcommand)return kd(n.flags.highlightsSubcommand);if(n.flags.db&&n.flags.dbSubcommand)return xd(n.flags.dbSubcommand,n.flags.days);if(n.flags.archive&&n.flags.archiveSubcommand)return vd(n.flags.archiveSubcommand,n.flags.archivePath);if(n.flags.export)return{type:"export",path:n.flags.exportPath||process.cwd()};let t=hd(n);return _d(t),{type:"config",config:t}};import{existsSync as Cd,mkdirSync as Bd}from"node:fs";import{homedir as Fd}from"node:os";import{basename as u0,dirname as m0,join as Na}from"node:path";var xe=(e)=>{if(typeof Bun<"u"&&globalThis.Bun){let{Database:t}=x("bun:sqlite");return new t(e)}return new(x("libsql"))(e)},ke=()=>{let n=process.env.XDG_DATA_HOME||Na(Fd(),".local","share"),t=Na(n,"llmd");if(!Cd(t))Bd(t,{recursive:!0});return Na(t,"llmd.db")};var ve=(e)=>{e.exec("PRAGMA foreign_keys = ON"),e.exec(`
1272
+ `,md=(e,n)=>{let t=e[n+1];if(t==="enable"||t==="disable"||t==="view")return{subcommand:t,nextIndex:n+1};return{subcommand:"view",nextIndex:n}},ld=(e,n)=>{let t=e[n+1];if(t==="check"||t==="cleanup"||t==="clear")return{subcommand:t,nextIndex:n+1};return{subcommand:"check",nextIndex:n}},dd=(e,n)=>{let t=e[n+1];if(t==="enable"||t==="disable")return{subcommand:t,nextIndex:n+1};return{subcommand:"enable",nextIndex:n}},pd=(e,n)=>{let t=e[n+1];if(t==="list"||t==="clear")return{subcommand:t,nextIndex:n+1};if(t==="show"){let a=e[n+2];return{subcommand:"show",nextIndex:n+2,path:a}}return{subcommand:"list",nextIndex:n}},bd=(e,n)=>{if(e==="-h"||e==="--help")return n.help=!0,!0;if(e==="-v"||e==="--version")return n.version=!0,!0;if(e==="docs")return n.docs=!0,!0;if(e==="-o"||e==="--open")return n.open=!0,!0;if(e==="-n"||e==="--no-open")return n.open=!1,!0;if(e==="-w"||e==="--watch")return n.watch=!0,!0;if(e==="--no-watch")return n.watch=!1,!0;return!1},gd=(e,n,t,a)=>{if(e==="-p"||e==="--port")return a.port=Number.parseInt(n[t+1]??"0",10),t+1;if(e==="-t"||e==="--theme")return a.theme=n[t+1],t+1;if(e==="-d"||e==="--tree-depth")return a.treeDepth=Number.parseInt(n[t+1]??"5",10),t+1;if(e==="analytics"){a.analytics=!0;let{subcommand:i,nextIndex:s}=md(n,t);return a.analyticsSubcommand=i,s}if(e==="highlights"){a.highlights=!0;let{subcommand:i,nextIndex:s}=dd(n,t);return a.highlightsSubcommand=i,s}if(e==="db"){a.db=!0;let{subcommand:i,nextIndex:s}=ld(n,t);return a.dbSubcommand=i,s}if(e==="archive"){a.archive=!0;let{subcommand:i,nextIndex:s,path:r}=pd(n,t);return a.archiveSubcommand=i,a.archivePath=r,s}if(e==="export"){a.export=!0;let i=n[t+1];if(i&&!i.startsWith("--"))return a.exportPath=i,t+1;return t}if(e==="--days"){let i=Number.parseInt(n[t+1]??"30",10);return a.days=Number.isNaN(i)?30:i,t+1}return t},fd=(e)=>{let n={},t;for(let a=0;a<e.length;a+=1){let i=e[a];if(!i)continue;if(bd(i,n))continue;let s=gd(i,e,a,n);if(s!==a){a=s;continue}if(!i.startsWith("-"))t=i}return{path:t,flags:n}},yd=(e)=>{let n=rd(e)?e:od(process.cwd(),e);if(n.endsWith(".md"))return{directory:sd(n),initialFile:n};return{directory:n}},hd=(e)=>{let{path:n=".",flags:t}=e,{directory:a,initialFile:i}=yd(n),s=pr();return{directory:a,initialFile:i,port:t.port??0,theme:t.theme??s.theme??"dark",open:t.open??!0,watch:t.watch??!1,openToAnalytics:t.analytics??!1,treeDepth:t.treeDepth??5}},_d=(e)=>{if(!id(e.directory))throw Error(`Directory not found: ${e.directory}`);if(!gr(e.theme)){let n=br();throw Error(`Theme "${e.theme}" not found. Available themes: ${n.join(", ")}`)}if(e.port<0||e.port>65535)throw Error(`Invalid port: ${e.port}. Must be 0-65535`);if(e.treeDepth<1||e.treeDepth>20)throw Error(`Invalid tree depth: ${e.treeDepth}. Must be 1-20`)},$d=()=>{console.log(ud)},jd=()=>{console.log(`llmd v${cd}`)},wd=(e)=>{if(e==="enable")return{type:"analytics-enable"};if(e==="disable")return{type:"analytics-disable"};return null},xd=(e,n)=>{if(e==="check")return{type:"db-check"};if(e==="cleanup")return{type:"db-cleanup",days:n??30};return{type:"db-clear"}},kd=(e)=>{if(e==="enable")return{type:"highlights-enable"};return{type:"highlights-disable"}},vd=(e,n)=>{if(e==="list")return{type:"archive-list"};if(e==="show"){if(!n)throw Error("archive show requires a path argument");return{type:"archive-show",path:n}}return{type:"archive-clear"}},Oa=(e)=>{let n=fd(e);if(n.flags.help)return $d(),{type:"exit"};if(n.flags.version)return jd(),{type:"exit"};if(n.flags.docs)return{type:"docs"};if(n.flags.analytics&&n.flags.analyticsSubcommand){let a=wd(n.flags.analyticsSubcommand);if(a)return a}if(n.flags.highlights&&n.flags.highlightsSubcommand)return kd(n.flags.highlightsSubcommand);if(n.flags.db&&n.flags.dbSubcommand)return xd(n.flags.dbSubcommand,n.flags.days);if(n.flags.archive&&n.flags.archiveSubcommand)return vd(n.flags.archiveSubcommand,n.flags.archivePath);if(n.flags.export)return{type:"export",path:n.flags.exportPath||process.cwd()};let t=hd(n);return _d(t),{type:"config",config:t}};import{existsSync as Cd,mkdirSync as Bd}from"node:fs";import{homedir as Fd}from"node:os";import{basename as u0,dirname as m0,join as Na}from"node:path";var xe=(e)=>{if(typeof Bun<"u"&&globalThis.Bun){let{Database:t}=x("bun:sqlite");return new t(e)}return new(x("libsql"))(e)},ke=()=>{let n=process.env.XDG_DATA_HOME||Na(Fd(),".local","share"),t=Na(n,"llmd");if(!Cd(t))Bd(t,{recursive:!0});return Na(t,"llmd.db")};var ve=(e)=>{e.exec("PRAGMA foreign_keys = ON"),e.exec(`
1272
1273
  CREATE TABLE IF NOT EXISTS resources (
1273
1274
  id TEXT PRIMARY KEY,
1274
1275
  path TEXT UNIQUE NOT NULL,
@@ -1514,7 +1515,7 @@ ${M_.map((n,t)=>`${L_[t]}${n}\x1B[0m`).join(`
1514
1515
  `),$$(a)){console.log(`\u2192 Updating cached documentation at ${a}...`);try{ul("git pull --rebase",{cwd:a,stdio:"inherit"}),console.log(`\u2713 Documentation updated
1515
1516
  `)}catch(m){console.log(` Warning: Could not update docs, using cached version
1516
1517
  `)}}else{console.log(`\u2192 Cloning llmd repository to ${a}...`);try{ul(`git clone https://github.com/pbzona/llmd "${a}"`,{stdio:"inherit"}),console.log(`\u2713 Repository cloned successfully
1517
- `)}catch(m){throw Error(`Failed to clone repository: ${m instanceof Error?m.message:String(m)}`)}}let i=Oa([a,"--open"]);if(i.type!=="config")throw Error("Unexpected result from parseCli");let s=i.config,r=await Da(s.directory),c=await Ys(s,r),o=Hs(c),u=o;if(s.initialFile){let m=_t(s.initialFile,s.directory);u=`${o}/view/${m}`}if(console.log(`\u25B8 Server running at ${o}`),console.log(` Theme: ${s.theme}`),console.log(`
1518
+ `)}catch(m){throw Error(`Failed to clone repository: ${m instanceof Error?m.message:String(m)}`)}}let i=Oa([a,"--open"]);if(i.type!=="config")throw Error("Unexpected result from parseCli");let s=i.config,r=await Da(s.directory,s.treeDepth),c=await Ys(s,r),o=Hs(c),u=o;if(s.initialFile){let m=_t(s.initialFile,s.directory);u=`${o}/view/${m}`}if(console.log(`\u25B8 Server running at ${o}`),console.log(` Theme: ${s.theme}`),console.log(`
1518
1519
  Press Ctrl+C to stop
1519
1520
  `),s.open)await new Promise((m)=>setTimeout(m,300)),xa(u);process.on("SIGINT",()=>{console.log(`
1520
1521
 
@@ -1544,7 +1545,7 @@ Content Preview (first 500 characters):
1544
1545
  `)},q$=async(e)=>{let{getHighlightsByDirectory:n,generateMarkdownExport:t,writeMarkdownExport:a}=await Promise.resolve().then(() => (pt(),dt)),{basename:i,resolve:s,join:r}=await import("path"),{homedir:c}=await import("os"),o=s(e);console.log(`\u2192 Exporting highlights from ${o}...
1545
1546
  `);let m=process.env.XDG_DATA_HOME||r(c(),".local","share"),l=r(m,"llmd","llmd.db"),b=((p)=>{if(typeof Bun<"u"&&globalThis.Bun){let{Database:y}=x("bun:sqlite");return new y(p)}return new(x("libsql"))(p)})(l);try{let p=n(b,o);if(p.length===0){console.log(`\u2717 No highlights found in this directory
1546
1547
  `),b.close();return}let g=new Date().toISOString().replace(/[:.]/g,"-").split("T")[0],f=`${i(o)}-${g}.md`,h=t(p,o),_=a(h,f);console.log(`\u2713 Exported ${p.length} highlight${p.length===1?"":"s"}`),console.log(` File: ${_}
1547
- `)}finally{b.close()}},z$=async()=>{try{Sm(),console.log();let e=Oa(process.argv.slice(2));if(e.type==="exit")process.exit(0);if(e.type==="analytics-enable")fr(),process.exit(0);if(e.type==="analytics-disable")yr(),process.exit(0);if(e.type==="highlights-enable")_r(),process.exit(0);if(e.type==="highlights-disable")$r(),process.exit(0);if(e.type==="db-check")await x$(),process.exit(0);if(e.type==="db-cleanup")await k$(e.days),process.exit(0);if(e.type==="db-clear")await v$(),process.exit(0);if(e.type==="docs"){await w$();return}if(e.type==="archive-list")C$(),process.exit(0);if(e.type==="archive-show")B$(e.path),process.exit(0);if(e.type==="archive-clear")await F$(),process.exit(0);if(e.type==="export")await q$(e.path),process.exit(0);let n=e.config;hr(n.theme),console.log(`\u2192 Scanning ${n.directory}...`);let t=await Da(n.directory);console.log(`\u2713 Found ${t.length} markdown file${t.length===1?"":"s"}
1548
+ `)}finally{b.close()}},z$=async()=>{try{Sm(),console.log();let e=Oa(process.argv.slice(2));if(e.type==="exit")process.exit(0);if(e.type==="analytics-enable")fr(),process.exit(0);if(e.type==="analytics-disable")yr(),process.exit(0);if(e.type==="highlights-enable")_r(),process.exit(0);if(e.type==="highlights-disable")$r(),process.exit(0);if(e.type==="db-check")await x$(),process.exit(0);if(e.type==="db-cleanup")await k$(e.days),process.exit(0);if(e.type==="db-clear")await v$(),process.exit(0);if(e.type==="docs"){await w$();return}if(e.type==="archive-list")C$(),process.exit(0);if(e.type==="archive-show")B$(e.path),process.exit(0);if(e.type==="archive-clear")await F$(),process.exit(0);if(e.type==="export")await q$(e.path),process.exit(0);let n=e.config;hr(n.theme),console.log(`\u2192 Scanning ${n.directory}...`);let t=await Da(n.directory,n.treeDepth);console.log(`\u2713 Found ${t.length} markdown file${t.length===1?"":"s"}
1548
1549
  `);let a=await Ys(n,t),i=Hs(a),s=i;if(n.openToAnalytics)s=`${i}/analytics`;else if(n.initialFile){let r=_t(n.initialFile,n.directory);s=`${i}/view/${r}`}if(console.log(`\u25B8 Server running at ${i}`),console.log(` Theme: ${n.theme}`),n.openToAnalytics)console.log(" Opening: Analytics");else if(n.initialFile){let r=_t(n.initialFile,n.directory);console.log(` Opening: ${r}`)}if(console.log(`
1549
1550
  Press Ctrl+C to stop
1550
1551
  `),n.open)await new Promise((r)=>setTimeout(r,300)),xa(s);process.on("SIGINT",()=>{console.log(`
@@ -1555,5 +1556,5 @@ Content Preview (first 500 characters):
1555
1556
  \u2717 Unknown error occurred
1556
1557
  `);process.exit(1)}};z$();
1557
1558
 
1558
- //# debugId=C36C6046939A1AC564756E2164756E21
1559
+ //# debugId=EA821E1C2B34CE6064756E2164756E21
1559
1560
  //# sourceMappingURL=llmd.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llmd",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Local markdown server for LLM-generated docs",
5
5
  "author": "Phil Zona <phil.b.zona@gmail.com>",
6
6
  "license": "MIT",