typebulb 0.10.1 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/servers.js CHANGED
@@ -1,3 +1,3 @@
1
- import{spawn as P}from"child_process";import{readdir as O,readFile as R,writeFile as Et,unlink as f,mkdir as jt}from"fs/promises";import{mkdirSync as Tt,writeFileSync as _t,appendFileSync as Dt,readFileSync as $}from"fs";import*as a from"path";import{fileURLToPath as C}from"url";import{join as w,resolve as N}from"path";import{homedir as I}from"os";function d(){let e=process.env.TYPEBULB_SERVERS_DIR;return e?w(e,".."):w(I(),".typebulb")}function l(){return process.env.TYPEBULB_SERVERS_DIR||w(d(),"servers")}function c(e){let t=N(e);return(process.platform==="win32"?t.toLowerCase():t).replace(/\\/g,"/")}function S(e,t){let r=c(e),n=c(t);return r.startsWith(n.endsWith("/")?n:n+"/")?!r.includes("/node_modules/"):!1}function A(e){return a.join(l(),`${e}.json`)}function p(e){return a.join(l(),`${e}.log`)}function k(e,t=0){try{let r=$(p(e)),n=t>=0&&t<=r.length?t:0;return{text:r.subarray(n).toString("utf8"),offset:r.length}}catch{return{text:"",offset:0}}}function U(e){try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}}async function W(e){await f(A(e)).catch(()=>{}),await f(p(e)).catch(()=>{})}async function y(e){let t;try{t=await O(l())}catch{return[]}let r=[];return await Promise.all(t.map(async i=>{if(!i.endsWith(".json"))return;let s=a.join(l(),i),o;try{o=JSON.parse(await R(s,"utf8"))}catch{await f(s).catch(()=>{});return}o&&typeof o.pid=="number"&&U(o.pid)?r.push(o):(await f(s).catch(()=>{}),o?.pid&&await f(p(o.pid)).catch(()=>{}))})),(e?r.filter(i=>S(i.file,e)):r).sort((i,s)=>i.startedAt-s.startedAt)}async function J(e){try{process.kill(e,"SIGTERM")}catch{}await W(e)}var M=e=>new Promise(t=>setTimeout(t,e));function Y(){return a.join(a.dirname(C(import.meta.url)),"index.js")}function K(e,t={}){return{command:process.execPath,args:[Y(),...t.trust?["--trust"]:[],e,...t.open===!1?["--no-open"]:[]]}}async function z(e,t={}){let r=t.cwd??process.cwd(),n=a.resolve(r,e),i=(await y()).find(u=>u.file===n);if(i)return i;let{command:s,args:o}=K(e,t);(process.platform==="win32"?P("cmd",["/c","start","","/b",s,...o],{cwd:r,stdio:"ignore",windowsHide:!0}):P(s,o,{cwd:r,detached:!0,stdio:"ignore"})).unref();let h=Date.now()+2e4;for(;Date.now()<h;){await M(150);let u=(await y()).find(v=>v.file===n);if(u)return u}throw new Error(`Launched ${a.basename(e)} but it did not register within 20s.`)}import{readdirSync as q,readFileSync as Q,statSync as X}from"fs";import{join as E,basename as Z}from"path";function g(e){let t=/^---[^\n]*\n([\s\S]*?)\n---/.exec(e),r=t?/^\s*name:\s*(.+?)\s*$/m.exec(t[1]):null;return r?r[1].replace(/^["']|["']$/g,""):void 0}function H(e){return(g(e)??"bulb").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"bulb"}function V(e){return e.replace(/^---[^\n]*\r?\n[\s\S]*?\r?\n---[^\n]*\r?\n?/,"").replace(/^\r?\n+/,"")}import*as m from"path";var G={claude:{file:"claude.bulb.md",srcEnv:"TYPEBULB_CLAUDE_SRC",viewer:!0}};function F(e){let t=m.basename(e).toLowerCase();return Object.values(G).some(r=>r.file.toLowerCase()===t)}function j(e,t,r){if(t>8)return r;let n;try{n=q(e,{withFileTypes:!0})}catch{return r}for(let i of n)if(i.isDirectory()){if(i.name.startsWith(".")||i.name==="node_modules")continue;j(E(e,i.name),t+1,r)}else if(i.isFile()&&i.name.endsWith(".bulb.md")){if(F(i.name))continue;r.push(E(e,i.name))}return r}function tt(e){return j(e,0,[]).map(t=>{let r=0;try{r=X(t).mtimeMs}catch{}let n;try{n=g(Q(t,"utf8").slice(0,1024))}catch{}return{path:t,name:n??Z(t).replace(/\.bulb\.md$/,""),mtime:r}})}import{readFile as it}from"fs/promises";var et={code:{path:"code.tsx",language:"typescript"},css:{path:"styles.css",language:"css"},html:{path:"index.html",language:"html"},config:{path:"config.json",language:"json"},notes:{path:"notes.md",language:"markdown"},data:{path:"data.txt",language:"text"},infer:{path:"infer.md",language:"markdown"},insight:{path:"insight.json",language:"json"},server:{path:"server.ts",language:"typescript"}};function L(e){try{let t=e.split(`
2
- `),r=0;if(t[r]?.trim()!=="---")return null;r++;let n=[];for(;r<t.length&&t[r]?.trim()!=="---";)n.push(t[r]),r++;if(t[r]?.trim()!=="---")return null;r++;let i=rt(n);if(!i)return null;let s=new Map;for(;r<t.length;){let b=t[r]?.trim()?.match(/^\*\*(.+)\*\*$/);if(b){let h=b[1].trim();for(r++;r<t.length&&t[r]?.trim()==="";)r++;let u=t[r]?.match(/^(`{3,})(\w*)\s*$/);if(!u){r++;continue}let v=u[1];r++;let B=[];for(;r<t.length&&!t[r]?.match(new RegExp(`^${v}\\s*$`));)B.push(t[r]),r++;r++,s.set(h,B.join(`
3
- `))}else r++}return{frontmatter:i,files:s}}catch{return null}}function rt(e){let t={};for(let r of e){let n=r.indexOf(":");if(n===-1)continue;let i=r.slice(0,n).trim(),s=r.slice(n+1).trim();switch(i){case"format":t.format=s;break;case"name":t.name=nt(s);break}}return!t.format?.startsWith("typebulb")||!t.name?null:t}function nt(e){return e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1).replace(/\\"/g,'"'):e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1):e}function T(e){let t=r=>e.files.get(et[r].path)||"";return{name:e.frontmatter.name,code:t("code"),css:t("css"),html:t("html"),config:t("config"),notes:t("notes"),data:t("data"),infer:t("infer"),insight:t("insight"),server:t("server")}}function _(e){if(e.server.trim())return"server-side code (server.ts)";let t=e.code;if(/\btb\s*\.\s*fs\b/.test(t)||t.includes("/__fs"))return"the filesystem";if(/\btb\s*\.\s*ai\b/.test(t)||t.includes("/__ai"))return"AI (your API keys)";if(/\btb\s*\.\s*server\s*\.\s*(?!log\b)\w/.test(t)||t.includes("/__api"))return"server-side code (server.ts)"}async function st(e){try{let t=L(await it(e,"utf-8"));return t?_(T(t)):void 0}catch{return}}import{spawn as ot}from"child_process";import{basename as at}from"path";function ut(){return process.env.TYPEBULB_EDITOR||"code"}var ct=/^(code|code-insiders|codium|vscodium|cursor|windsurf)(\.cmd|\.exe)?$/i;function lt(e,t,r){return r==null?[t]:ct.test(at(e))?["-g",`${t}:${r}`]:[`+${r}`,t]}function ft(e,t){let r=ut();return{command:r,args:lt(r,e,t)}}function mt(e,t){let{command:r,args:n}=ft(e,t),i=ot(r,n,{shell:!0,detached:!0,stdio:"ignore"});i.on("error",s=>console.error("[typebulb] editor launch failed:",s?.message??s)),i.unref()}import{readFileSync as dt,writeFileSync as pt,mkdirSync as gt}from"fs";import{join as bt}from"path";function D(){return bt(d(),"trust.json")}function x(){try{let e=JSON.parse(dt(D(),"utf8"));return new Set(Array.isArray(e)?e:[])}catch{return new Set}}function ht(e){gt(d(),{recursive:!0}),pt(D(),JSON.stringify([...e]))}function vt(e){return x().has(c(e))}function wt(e,t){let r=x(),n=c(e);(t?r.has(n):!r.has(n))||(t?r.add(n):r.delete(n),ht(r))}function yt(){return[...x()]}export{g as bulbName,vt as isBulbTrusted,z as launchBulbServer,tt as listBulbFiles,y as listBulbServers,yt as listTrustedBulbs,mt as openInEditor,st as predictBulbTrust,k as readServerLog,p as serverLogPath,wt as setBulbTrusted,H as slugifyBulbName,J as stopBulbServer,V as stripFrontmatter};
1
+ import{spawn as P}from"child_process";import{readdir as R,readFile as $,writeFile as jt,unlink as m,mkdir as Lt}from"fs/promises";import{mkdirSync as _t,writeFileSync as Dt,appendFileSync as Nt,readFileSync as C}from"fs";import*as a from"path";import{fileURLToPath as A}from"url";import{join as y,resolve as N}from"path";import{homedir as I}from"os";function d(){let e=process.env.TYPEBULB_SERVERS_DIR;return e?y(e,".."):y(I(),".typebulb")}function l(){return process.env.TYPEBULB_SERVERS_DIR||y(d(),"servers")}function c(e){let t=N(e);return(process.platform==="win32"?t.toLowerCase():t).replace(/\\/g,"/")}function F(e,t){let r=c(e),n=c(t);return r.startsWith(n.endsWith("/")?n:n+"/")?!r.includes("/node_modules/"):!1}import*as f from"path";var O={claude:{file:"claude.bulb.md",srcEnv:"TYPEBULB_CLAUDE_SRC",viewer:!0}};function p(e){let t=f.basename(e).toLowerCase();return Object.values(O).some(r=>r.file.toLowerCase()===t)}function k(e){return a.join(l(),`${e}.json`)}function g(e){return a.join(l(),`${e}.log`)}function U(e,t=0){try{let r=C(g(e)),n=t>=0&&t<=r.length?t:0;return{text:r.subarray(n).toString("utf8"),offset:r.length}}catch{return{text:"",offset:0}}}function W(e){try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}}async function J(e){await m(k(e)).catch(()=>{}),await m(g(e)).catch(()=>{})}async function x(e){let t;try{t=await R(l())}catch{return[]}let r=[];return await Promise.all(t.map(async i=>{if(!i.endsWith(".json"))return;let s=a.join(l(),i),o;try{o=JSON.parse(await $(s,"utf8"))}catch{await m(s).catch(()=>{});return}o&&typeof o.pid=="number"&&W(o.pid)?r.push(o):(await m(s).catch(()=>{}),o?.pid&&await m(g(o.pid)).catch(()=>{}))})),(e?r.filter(i=>F(i.file,e)&&!p(i.file)):r).sort((i,s)=>i.startedAt-s.startedAt)}async function M(e){try{process.kill(e,"SIGTERM")}catch{}await J(e)}var Y=e=>new Promise(t=>setTimeout(t,e));function K(){return a.join(a.dirname(A(import.meta.url)),"index.js")}function z(e,t={}){return{command:process.execPath,args:[K(),...t.trust?["--trust"]:[],e,...t.open===!1?["--no-open"]:[]]}}async function H(e,t={}){let r=t.cwd??process.cwd(),n=a.resolve(r,e),i=(await x()).find(u=>u.file===n);if(i)return i;let{command:s,args:o}=z(e,t);(process.platform==="win32"?P("cmd",["/c","start","","/b",s,...o],{cwd:r,stdio:"ignore",windowsHide:!0}):P(s,o,{cwd:r,detached:!0,stdio:"ignore"})).unref();let v=Date.now()+2e4;for(;Date.now()<v;){await Y(150);let u=(await x()).find(w=>w.file===n);if(u)return u}throw new Error(`Launched ${a.basename(e)} but it did not register within 20s.`)}import{readdirSync as q,readFileSync as Q,statSync as X}from"fs";import{join as E,basename as Z}from"path";function b(e){let t=/^---[^\n]*\n([\s\S]*?)\n---/.exec(e),r=t?/^\s*name:\s*(.+?)\s*$/m.exec(t[1]):null;return r?r[1].replace(/^["']|["']$/g,""):void 0}function V(e){return(b(e)??"bulb").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"bulb"}function G(e){return e.replace(/^---[^\n]*\r?\n[\s\S]*?\r?\n---[^\n]*\r?\n?/,"").replace(/^\r?\n+/,"")}function j(e,t,r){if(t>8)return r;let n;try{n=q(e,{withFileTypes:!0})}catch{return r}for(let i of n)if(i.isDirectory()){if(i.name.startsWith(".")||i.name==="node_modules")continue;j(E(e,i.name),t+1,r)}else if(i.isFile()&&i.name.endsWith(".bulb.md")){if(p(i.name))continue;r.push(E(e,i.name))}return r}function tt(e){return j(e,0,[]).map(t=>{let r=0;try{r=X(t).mtimeMs}catch{}let n;try{n=b(Q(t,"utf8").slice(0,1024))}catch{}return{path:t,name:n??Z(t).replace(/\.bulb\.md$/,""),mtime:r}})}import{readFile as it}from"fs/promises";var et={code:{path:"code.tsx",language:"typescript"},css:{path:"styles.css",language:"css"},html:{path:"index.html",language:"html"},config:{path:"config.json",language:"json"},notes:{path:"notes.md",language:"markdown"},data:{path:"data.txt",language:"text"},infer:{path:"infer.md",language:"markdown"},insight:{path:"insight.json",language:"json"},server:{path:"server.ts",language:"typescript"}};function L(e){try{let t=e.split(`
2
+ `),r=0;if(t[r]?.trim()!=="---")return null;r++;let n=[];for(;r<t.length&&t[r]?.trim()!=="---";)n.push(t[r]),r++;if(t[r]?.trim()!=="---")return null;r++;let i=rt(n);if(!i)return null;let s=new Map;for(;r<t.length;){let h=t[r]?.trim()?.match(/^\*\*(.+)\*\*$/);if(h){let v=h[1].trim();for(r++;r<t.length&&t[r]?.trim()==="";)r++;let u=t[r]?.match(/^(`{3,})(\w*)\s*$/);if(!u){r++;continue}let w=u[1];r++;let S=[];for(;r<t.length&&!t[r]?.match(new RegExp(`^${w}\\s*$`));)S.push(t[r]),r++;r++,s.set(v,S.join(`
3
+ `))}else r++}return{frontmatter:i,files:s}}catch{return null}}function rt(e){let t={};for(let r of e){let n=r.indexOf(":");if(n===-1)continue;let i=r.slice(0,n).trim(),s=r.slice(n+1).trim();switch(i){case"format":t.format=s;break;case"name":t.name=nt(s);break}}return!t.format?.startsWith("typebulb")||!t.name?null:t}function nt(e){return e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1).replace(/\\"/g,'"'):e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1):e}function T(e){let t=r=>e.files.get(et[r].path)||"";return{name:e.frontmatter.name,code:t("code"),css:t("css"),html:t("html"),config:t("config"),notes:t("notes"),data:t("data"),infer:t("infer"),insight:t("insight"),server:t("server")}}function _(e){if(e.server.trim())return"server-side code (server.ts)";let t=e.code;if(/\btb\s*\.\s*fs\b/.test(t)||t.includes("/__fs"))return"the filesystem";if(/\btb\s*\.\s*ai\b/.test(t)||t.includes("/__ai"))return"AI (your API keys)";if(/\btb\s*\.\s*server\s*\.\s*(?!log\b)\w/.test(t)||t.includes("/__api"))return"server-side code (server.ts)"}async function st(e){try{let t=L(await it(e,"utf-8"));return t?_(T(t)):void 0}catch{return}}import{spawn as ot}from"child_process";import{basename as at}from"path";function ut(){return process.env.TYPEBULB_EDITOR||"code"}var ct=/^(code|code-insiders|codium|vscodium|cursor|windsurf)(\.cmd|\.exe)?$/i;function lt(e,t,r){return r==null?[t]:ct.test(at(e))?["-g",`${t}:${r}`]:[`+${r}`,t]}function ft(e,t){let r=ut();return{command:r,args:lt(r,e,t)}}function mt(e,t){let{command:r,args:n}=ft(e,t),i=ot(r,n,{shell:!0,detached:!0,stdio:"ignore"});i.on("error",s=>console.error("[typebulb] editor launch failed:",s?.message??s)),i.unref()}import{readFileSync as dt,writeFileSync as pt,mkdirSync as gt}from"fs";import{join as bt}from"path";function D(){return bt(d(),"trust.json")}function B(){try{let e=JSON.parse(dt(D(),"utf8"));return new Set(Array.isArray(e)?e:[])}catch{return new Set}}function ht(e){gt(d(),{recursive:!0}),pt(D(),JSON.stringify([...e]))}function vt(e){return B().has(c(e))}function wt(e,t){let r=B(),n=c(e);(t?r.has(n):!r.has(n))||(t?r.add(n):r.delete(n),ht(r))}function yt(){return[...B()]}export{b as bulbName,vt as isBulbTrusted,H as launchBulbServer,tt as listBulbFiles,x as listBulbServers,yt as listTrustedBulbs,mt as openInEditor,st as predictBulbTrust,U as readServerLog,g as serverLogPath,wt as setBulbTrusted,V as slugifyBulbName,M as stopBulbServer,G as stripFrontmatter};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typebulb",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "Local bulb runner CLI for Typebulb",
5
5
  "license": "MIT",
6
6
  "engines": { "node": ">=18" },