typebulb 0.10.0 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/{dist/bulbs → bulbs}/claude.bulb.md +3262 -3269
- package/dist/index.js +65 -60
- package/dist/servers.d.ts +4 -2
- package/dist/servers.js +3 -3
- package/package.json +3 -2
package/dist/servers.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface BulbServer {
|
|
|
7
7
|
url: string
|
|
8
8
|
/** Absolute path to the .bulb.md being served. */
|
|
9
9
|
file: string
|
|
10
|
+
/** The cwd the server was launched in (the project it belongs to). */
|
|
11
|
+
cwd?: string
|
|
10
12
|
/** Epoch ms the server began listening. */
|
|
11
13
|
startedAt: number
|
|
12
14
|
/** Launched with --trust (filesystem / AI / server.ts enabled)? */
|
|
@@ -72,6 +74,6 @@ export declare function setBulbTrusted(file: string, trust: boolean): void
|
|
|
72
74
|
/** Every remembered-trusted bulb path (absolute, normalized). */
|
|
73
75
|
export declare function listTrustedBulbs(): string[]
|
|
74
76
|
|
|
75
|
-
/** Open `filePath` (optionally at `line`) in the user's editor, detached.
|
|
76
|
-
*
|
|
77
|
+
/** Open `filePath` (optionally at `line`) in the user's editor, detached. Defaults to VS Code
|
|
78
|
+
* (`code`); override with `TYPEBULB_EDITOR`. Fire-and-forget. */
|
|
77
79
|
export declare function openInEditor(filePath: string, line?: number): void
|
package/dist/servers.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{spawn as
|
|
2
|
-
`),
|
|
3
|
-
`))}else
|
|
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.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "Local bulb runner CLI for Typebulb",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": { "node": ">=18" },
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
|
-
"dist"
|
|
26
|
+
"dist",
|
|
27
|
+
"bulbs/*.bulb.md"
|
|
27
28
|
],
|
|
28
29
|
"scripts": {
|
|
29
30
|
"typecheck": "tsc --build",
|