typebulb 0.15.7 → 0.15.9
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/agents/claude/client.js +131 -131
- package/dist/index.js +3 -3
- package/dist/render.js +44 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -872,8 +872,8 @@ globalThis.__tbEntryRan = true; /* load-failure backstop \u2014 see embedProtoco
|
|
|
872
872
|
});
|
|
873
873
|
})();
|
|
874
874
|
</script>`;function Cb(r){let e={};for(let[t,n]of Object.entries(r))e[t]=n.startsWith("https://")?"/proxy/"+n:n;return e}import*as ts from"fs/promises";import*as es from"path";import{existsSync as mf,readFileSync as Rb}from"fs";import{execFile as Ib}from"child_process";import{promisify as _b}from"util";import{satisfies as Lb}from"semver";var $b=_b(Ib);async function rs(r,e,t){let s=r.map(o=>Mb(o,t)).filter(o=>!Db(o,e));if(s.length===0)return;await ts.mkdir(e,{recursive:!0});let i=es.join(e,"package.json");mf(i)||await ts.writeFile(i,JSON.stringify({name:"typebulb-server",private:!0})),console.log(` Installing: ${s.join(", ")}`),await $b("npm",["install","--no-audit","--no-fund",...s],{cwd:e,shell:!0})}function Mb(r,e){if(!e||yf(r))return r;let t=e[r];return t?`${r}@${t}`:r}function Db(r,e){let t=es.join(e,"node_modules",gf(r));if(!mf(t))return!1;let n=yf(r);if(!n)return!0;try{let s=JSON.parse(Rb(es.join(t,"package.json"),"utf-8")).version;return Lb(s,n)}catch{return!1}}function ns(r){let e=new Set,t=/\bimport\s+(?:[\s\S]*?\s+from\s+)?['"]([^./][^'"]*)['"]/g,n;for(;n=t.exec(r);){let s=n[1];if(s.includes(":"))continue;let i=s.startsWith("@")?s.split("/").slice(0,2).join("/"):s.split("/")[0];e.add(i)}return[...e]}function gf(r){if(r.startsWith("@")){let t=r.indexOf("/");if(t<0)return r;let n=r.indexOf("@",t+1);return n<0?r:r.slice(0,n)}let e=r.indexOf("@");return e<0?r:r.slice(0,e)}function yf(r){let e=gf(r);return r.length>e.length?r.slice(e.length+1):""}async function bf(r){let t=(await _e.readdir(r)).find(n=>n.endsWith(".bulb.md"));return t?ss.join(r,t):null}async function ne(r){let e=await _e.readFile(r,"utf-8"),t=Ct(e);if(!t)throw new Error("Invalid .bulb.md file format");let n=jn(t);return{bulb:n,config:Ja(n.config),warnings:qa(e)}}async function Tr(r,e,t,n){let s=No(r,{serverOnly:!0});if(s.error)throw new Error(`Server compilation error: ${s.error}`);let i=s.code;t&&(i=await _a(i,t));let o=ss.join(e,".typebulb");await _e.mkdir(o,{recursive:!0});let a=ns(i);a.length>0&&await rs(a,o,n);let c=ss.join(o,"server.mjs");return await _e.writeFile(c,i,"utf-8"),await import(`${Bb(c).href}?t=${Date.now()}`)}async function Jo(r,e,t,n,s){let{bulb:i,config:o}=await ne(r),a=Po(i.data),c=No(i.code,{jsxImportSource:o.ts?.jsxImportSource});c.error&&console.error("Compilation error:",c.error);let{importMap:l}=await zn.buildImportMap(c.code,o.dependencies??{},n?new Set([n.name]):void 0);n&&(l.imports[n.name]=n.entryUrl);let f=hf({name:i.name,code:c.code,css:i.css,html:i.html,data:a,insight:i.insight,importMap:l,watch:e}),u=null;return i.server&&t&&(u=await Tr(i.server,s,n,o.dependencies)),{html:f,bulb:i,serverExports:u}}Pr();import Yb from"open";async function vt(r){await Yb(r)}var Sf=new Set(["claude"]);function xf(r){return Sf.has(r)}function Or(){return[...Sf]}import*as Le from"path";import{spawn as uw,execSync as fw}from"child_process";import{createRequire as dw}from"module";import{existsSync as pw}from"fs";import*as J from"fs/promises";import*as U from"path";import*as St from"path";var Hb=St.join(Vn,"pkg"),Gb=St.join(Vn,"files"),zb=St.join(Vn,"negative.json"),as=class{pkgMem=new Map;fileMem=new Map;negativeCache=new Je(new yt(zb));async getCachedDts(e){if(this.pkgMem.has(e))return this.pkgMem.get(e);await I();let t=await Ke(kf(e));return this.pkgMem.set(e,t),t}async setCachedDts(e,t,n){let s={content:t,url:n};this.pkgMem.set(e,s),await os(async()=>{await I(),await G(kf(e),JSON.stringify(s))})}async getCachedFile(e){if(this.fileMem.has(e))return this.fileMem.get(e);await I();let t=await Wn(Ef(e));return this.fileMem.set(e,t),t}async setCachedFile(e,t){this.fileMem.set(e,t),await os(async()=>{await I(),await G(Ef(e),t)})}isNegative(e){return this.negativeCache.isNegative(e)}async recordNegative(e){await os(async()=>{await I(),await this.negativeCache.recordNegative(e)})}clearNegative(e){return os(()=>this.negativeCache.clearNegative(e))}};async function os(r){try{await r()}catch{}}function kf(r){return St.join(Hb,te(r)+".json")}function Ef(r){return St.join(Gb,te(r)+".txt")}var Yo;function Qb(){return Yo||(Yo=qo({cache:new as,cdnClient:df,packageService:zn,versionResolver:ff})),Yo}var Tf="file:///node_modules/";async function Af(r){let e=Yn(r.emitKey,"typecheck");await I(),await J.rm(e,{recursive:!0,force:!0}),await J.mkdir(e,{recursive:!0});let t=tw(r.jsxImportSource,r.dependencies),n=await Qb().resolve(r.code,r.dependencies,t),s=r.local?.name,i=s?n.filter(f=>f.pkg!==s):n,o=new Set;for(let f of i)for(let u of f.files){let d=cs(u.path);if(!d||o.has(d))continue;o.add(d);let p=U.join(e,"node_modules",d);await J.mkdir(U.dirname(p),{recursive:!0}),await J.writeFile(p,u.content,"utf8")}let a={};for(let f of i)for(let u of f.shims){let d=cs(u.path);d&&(a[u.module]=[`./node_modules/${d}`])}for(let f of i){if(f.ambient)continue;let u=cs(f.mainPath);u&&(a[f.pkg]=[`./node_modules/${u}`])}let c=new Set;for(let f of i)for(let u of f.files){if(!u.ambient)continue;let d=cs(u.path);d&&c.add(`node_modules/${d}`)}if(r.local){delete a[r.local.name];let f=await rw(r.local,e);f?a[r.local.name]=[`./node_modules/${r.local.name}/${f}`]:console.warn(` local: '${r.local.name}' ships no type defs; check cannot type against it.`)}let l=Xb(r.jsxImportSource,a,[...c]);return await J.writeFile(U.join(e,"tsconfig.json"),JSON.stringify(l,null,2)+`
|
|
875
|
-
`,"utf8"),await J.writeFile(U.join(e,"code.tsx"),r.code,"utf8"),await J.writeFile(U.join(e,"tb.d.ts"),$o,"utf8"),{dir:e}}function Xb(r,e,t=[]){return{compilerOptions:{target:"es2023",module:"esnext",moduleResolution:"bundler",lib:Zb([..._o,...Lo]),jsx:"react-jsx",jsxImportSource:r??"react",strict:!0,noEmit:!0,skipLibCheck:!0,esModuleInterop:!0,allowSyntheticDefaultImports:!0,forceConsistentCasingInFileNames:!0,
|
|
876
|
-
`,"utf8"),{dir:e}}function ow(r){let e={target:"es2023",module:"esnext",moduleResolution:"bundler",lib:["ES2023"],types:["node"],strict:!0,noEmit:!0,skipLibCheck:!0,esModuleInterop:!0,allowSyntheticDefaultImports:!0,forceConsistentCasingInFileNames:!0};if(r?.typesAbs){let t=i=>i.replace(/\\/g,"/"),n=t(ye.dirname(r.typesAbs)),s=t(r.typesAbs).replace(/\.d\.ts$/,"");e.
|
|
875
|
+
`,"utf8"),await J.writeFile(U.join(e,"code.tsx"),r.code,"utf8"),await J.writeFile(U.join(e,"tb.d.ts"),$o,"utf8"),{dir:e}}function Xb(r,e,t=[]){return{compilerOptions:{target:"es2023",module:"esnext",moduleResolution:"bundler",lib:Zb([..._o,...Lo]),jsx:"react-jsx",jsxImportSource:r??"react",strict:!0,noEmit:!0,skipLibCheck:!0,esModuleInterop:!0,allowSyntheticDefaultImports:!0,forceConsistentCasingInFileNames:!0,paths:e},include:["code.tsx","tb.d.ts",...t]}}function Zb(r){return r.filter(e=>!e.since).map(e=>ew(e.name))}function ew(r){return r.split(".").map(e=>/^es\d+$/i.test(e)?e.toUpperCase():e==="dom"?"DOM":e==="esnext"?"ESNext":e.charAt(0).toUpperCase()+e.slice(1)).join(".")}function tw(r,e){let t=r??("react"in e?"react":void 0);return t?[`${t}/jsx-runtime`,`${t}/jsx-dev-runtime`]:[]}function cs(r){if(!r.startsWith(Tf))return;let e=r.slice(Tf.length),t=e.indexOf("/");if(!(t<0))return e.slice(t+1)}async function rw(r,e){if(!r.typesAbs)return;let t=U.dirname(r.typesAbs),n=U.join(e,"node_modules",r.name);for(let s of await nw(t)){let i=U.join(n,U.relative(t,s));await J.mkdir(U.dirname(i),{recursive:!0}),await J.copyFile(s,i)}return U.basename(r.typesAbs)}async function nw(r){let e=[];async function t(n){let s=await J.readdir(n,{withFileTypes:!0});for(let i of s){let o=U.join(n,i.name);i.isDirectory()?await t(o):/\.d\.ts(\.map)?$/.test(i.name)&&e.push(o)}}return await t(r),e}import*as z from"fs/promises";import*as ye from"path";import{existsSync as sw}from"fs";var iw="^22";async function Pf(r){let e=Yn(r.emitKey,"typecheck-server");await I(),await z.rm(e,{recursive:!0,force:!0}),await z.mkdir(e,{recursive:!0});let t=ye.join(r.bulbDir,".typebulb"),n=ns(r.server).filter(o=>o!==r.local?.name);await rs([`@types/node@${iw}`,...n],t,r.dependencies);let s=ye.join(t,"node_modules"),i=ye.join(e,"node_modules");return await aw(s,i),await z.writeFile(ye.join(e,"server.ts"),r.server,"utf8"),await z.writeFile(ye.join(e,"tb.d.ts"),Mo,"utf8"),await z.writeFile(ye.join(e,"tsconfig.json"),JSON.stringify(ow(r.local),null,2)+`
|
|
876
|
+
`,"utf8"),{dir:e}}function ow(r){let e={target:"es2023",module:"esnext",moduleResolution:"bundler",lib:["ES2023"],types:["node"],strict:!0,noEmit:!0,skipLibCheck:!0,esModuleInterop:!0,allowSyntheticDefaultImports:!0,forceConsistentCasingInFileNames:!0};if(r?.typesAbs){let t=i=>i.replace(/\\/g,"/"),n=t(ye.dirname(r.typesAbs)),s=t(r.typesAbs).replace(/\.d\.ts$/,"");e.paths={[r.name]:[s],[`${r.name}/*`]:[`${n}/*`]}}return{compilerOptions:e,include:["server.ts","tb.d.ts"]}}async function aw(r,e){if(!sw(r)){await z.mkdir(e,{recursive:!0});return}await z.rm(e,{recursive:!0,force:!0});let t=process.platform==="win32"?"junction":"dir";await z.symlink(r,e,t)}var Ve=["client"],Ye=["client","server"],cw=[{type:"DYNAMIC_IMPORT",pattern:/\bimport\s*\(\s*['"`]/,targets:Ve},{type:"COMMONJS_REQUIRE",pattern:/\brequire\s*\(\s*['"`]/,targets:Ye},{type:"JS_EXTENSION_IMPORT",pattern:/from\s+['"][^'"]*\/[^'"]*\.js['"]/,targets:Ve},{type:"URL_IMPORT",pattern:/from\s+['"]https?:\/\//,targets:Ve},{type:"VERSION_SPECIFIER_IMPORT",pattern:/from\s+['"][^'"]*@[\d^~]/,targets:Ve},{type:"REDUNDANT_TB_DECLARATION",pattern:/declare\s+(const|var|let)\s+tb\b/,targets:Ye},{type:"CONST_ENUM",pattern:/\bconst\s+enum\b/,targets:Ye},{type:"NAMESPACE_DECLARATION",pattern:/\bnamespace\s+\w+/,targets:Ye},{type:"COMMONJS_EXPORT_EQUALS",pattern:/\bexport\s*=/,targets:Ye},{type:"COMMONJS_IMPORT_EQUALS",pattern:/\bimport\s+\w+\s*=/,targets:Ye},{type:"MODULE_DECLARATION",pattern:/\bmodule\s+\w+\s*\{/,targets:Ye},{type:"CSS_FILE_IMPORT",pattern:/(?:from|import)\s+['"][^'"]*\.css['"]/,targets:Ve},{type:"NAVIGATION",pattern:/window\.(location\.(reload|assign|replace)\s*\(|open\s*\()/,targets:Ve},{type:"NAVIGATION",pattern:/window\.location(\.href)?\s*=[^=]/,targets:Ve}];function Ho(r,e){if(!r)return[];let{target:t}=e,n=[],s=r.split(`
|
|
877
877
|
`);for(let i=0;i<s.length;i++){let o=s[i],a=i+1;for(let c of cw)c.targets.includes(t)&&c.pattern.test(o)&&n.push({type:c.type,severity:"error",message:lw(c.type,a),lineNumber:a,lineContent:o})}return n}function lw(r,e){return r==="URL_IMPORT"?`Direct URL imports are not supported! Found on line ${e}.
|
|
878
878
|
|
|
879
879
|
**CRITICAL**: Import packages by name only. Do NOT use CDN URLs:
|
|
@@ -1138,6 +1138,6 @@ ${ev}
|
|
|
1138
1138
|
Shutting down...`),p.close(),y?.(),t(),await Cr(process.pid),process.exit(0)};process.on("SIGINT",E),process.on("SIGTERM",E)}import*as Qd from"path";import{EventEmitter as rS}from"events";async function Xd(r,e,t,n,s){let i=de(t),o=!1,a=async()=>{let{bulb:c,config:l}=await ne(r);o||($e(i,r,c.server),o=!0),await Tr(c.server,s,n,l.dependencies)};if(console.log(`Running ${Qd.basename(r)}...`),await a(),e){console.log(`Watching for changes...
|
|
1139
1139
|
`);let c=new rS;c.on("reload",async()=>{try{console.log("Re-running..."),await a()}catch(l){console.error("Error:",l)}}),Ps({bulbPath:r,emitter:c})}}import{Console as nS}from"node:console";fe();Ar();async function Zd(r,e,t,n,s){lS();try{let p=L(r),m=(await $()).find(h=>L(h.file)===p);m&&ds(m.pid,ue(m.pid).offset)}catch{}let i=de(t),{bulb:o,config:a}=await ne(r);o.server||$s("This bulb has no **server.ts** block; nothing to call."),$e(i,r,o.server);let c;try{c=await Tr(o.server,s,n,a.dependencies)}catch(p){$s(p instanceof Error?p.message:String(p))}let l=Es(c,e.fn);if(!l){let p=[...Object.keys(c).filter(m=>typeof c[m]=="function"),...Object.keys(ua)];$s(`Function '${e.fn}' not found. Available: ${p.length?p.join(", "):"(none)"}.`)}let f=await sS(e),u;try{u=await l(...f)}catch(p){$s(p instanceof Error?p.stack??p.message:String(p))}let d=aS(u);d!==void 0&&await uS(d+`
|
|
1140
1140
|
`),process.exit(0)}async function sS(r){if(r.hasArgsFlag){let e=r.argsJson??"";return e==="-"&&(e=await fS()),oS(e)}return iS(r.positional)}function iS(r){return r.map(e=>{try{return JSON.parse(e)}catch{return e}})}function oS(r){let e;try{e=JSON.parse(r)}catch(t){throw new Error(`--args must be a JSON array: ${t instanceof Error?t.message:String(t)}`)}if(!Array.isArray(e))throw new Error(`--args must be a JSON array, got ${e===null?"null":typeof e}`);return e}function aS(r){if(r!==void 0)return JSON.stringify(r,cS,2)}function cS(r,e){return typeof e=="bigint"?e.toString():e}function $s(r){process.stderr.write(r+`
|
|
1141
|
-
`),process.exit(1)}function lS(){let r=new nS(process.stderr,process.stderr);console.log=r.log.bind(r),console.info=r.info.bind(r),console.debug=r.debug.bind(r),console.dir=r.dir.bind(r)}function uS(r){return new Promise((e,t)=>{process.stdout.write(r,n=>n?t(n):e())})}async function fS(){let r=[];for await(let e of process.stdin)r.push(e);return Buffer.concat(r).toString("utf-8")}var Ta="0.15.
|
|
1141
|
+
`),process.exit(1)}function lS(){let r=new nS(process.stderr,process.stderr);console.log=r.log.bind(r),console.info=r.info.bind(r),console.debug=r.debug.bind(r),console.dir=r.dir.bind(r)}function uS(r){return new Promise((e,t)=>{process.stdout.write(r,n=>n?t(n):e())})}async function fS(){let r=[];for await(let e of process.stdin)r.push(e);return Buffer.concat(r).toString("utf-8")}var Ta="0.15.9";function ep(r,e){r||(console.error(`This bulb runs server-side Node code (server.ts), which --trust must authorize:
|
|
1142
1142
|
${e}`),process.exit(1))}async function dS(){let r=La(process.argv.slice(2));if(r.version&&(console.log(`typebulb ${Ta}`),process.exit(0)),r.help&&($a(),process.exit(0)),r.subcommand==="logs"){await td(r.file||void 0,{follow:r.follow,clear:r.clear,run:r.run,lines:r.lines});return}if(r.subcommand==="wait"){await rd(r.file||void 0,{match:r.match,timeoutSec:r.timeoutSec??1800});return}if(r.subcommand==="stop"){r.stopScope?await sd(r.stopScope):await nd(r.file||void 0);return}if(r.subcommand==="send"){await od(r.file,r.sendMessage);return}if(r.subcommand==="skill"){await Xf(Ta);return}if(r.subcommand==="models"){await zf(r.mode);return}if(r.subcommand==="agent"){if(!r.agentTarget){await Vf(Ta);return}xf(r.agentTarget)||(console.error(`Unknown agent '${r.agentTarget}'. Known: ${Or().join(", ")}.`),process.exit(1));let l=await ea(process.cwd(),r.agentTarget);if(l){console.log(`Mirror '${r.agentTarget}' is already running for this project:
|
|
1143
1143
|
${l.url}`),r.open&&await vt(l.url);return}await zd(r);return}if(r.subcommand==="trust"||r.subcommand==="untrust"){await Rf(r.file||void 0,r.subcommand==="trust");return}let e;if(!r.file||r.file==="."){let l=await bf(process.cwd());l||(console.error("No .bulb.md file found in current directory"),process.exit(1)),e=l}else e=we.resolve(r.file);await tp.access(e).then(()=>!0,()=>!1)||(Or().includes(r.file)&&(console.error(`To open the ${r.file} agent mirror, run: npx typebulb agent:${r.file}`),process.exit(1)),console.error(`File not found: ${e}`),process.exit(1)),e.endsWith(".bulb.md")||(console.error("File must have .bulb.md extension"),process.exit(1));let n=r.file&&r.file!=="."?r.file:we.relative(process.cwd(),e)||we.basename(e),s=`npx typebulb --trust ${n.includes(" ")?`"${n}"`:n}`;if(r.subcommand==="predict"){await Cf(e,s);return}let i=!r.noTrust&&We(e);i&&!r.trust&&console.log("trust: granted from memory (run `typebulb untrust` to revoke)"),r.trust=r.noTrust?!1:r.trust||i;let o;try{o=await ne(e)}catch{}let a;if(r.local){o&&!(r.local.name in(o.config.dependencies??{}))&&(console.error(`--replace: '${r.local.name}' is not a dependency in this bulb's config.json; nothing to replace.`),process.exit(1)),o&&r.subcommand!=="call"&&(!o.bulb.code||r.server)&&console.warn("warning: --replace has no effect in server mode (the override is client-only).");try{a=await Ia(r.local)}catch(l){console.error(l instanceof Error?l.message:String(l)),process.exit(1)}console.log(`replace: ${a.name} \u2192 ${we.relative(process.cwd(),a.dir)||"."}`)}if(r.subcommand==="check"){await Nf(e,a);return}let c=we.dirname(e);if(r.subcommand==="call"){ep(r.trust,s),await Zd(e,{fn:r.fn,positional:r.callArgs,argsJson:r.argsJson,hasArgsFlag:r.hasArgsFlag},r.mode,a,c);return}if(o&&o.bulb.server&&(!o.bulb.code||r.server)){ep(r.trust,s),await Xd(e,r.watch,r.mode,a,c);return}await md(e,r,s,a,c)}dS().catch(r=>{console.error("Error:",r.message),process.exit(1)});
|