typebulb 0.15.4 → 0.15.5
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 +104 -104
- package/dist/agents/claude/styles.css +6 -3
- package/dist/index.js +4 -2
- package/package.json +1 -1
|
@@ -333,9 +333,12 @@ body {
|
|
|
333
333
|
color: var(--accent); text-decoration: none; cursor: pointer;
|
|
334
334
|
}
|
|
335
335
|
.server-name:hover { text-decoration: underline; }
|
|
336
|
-
/* Port links to the running server (localhost:<port>) —
|
|
337
|
-
|
|
338
|
-
|
|
336
|
+
/* Port links to the running server (localhost:<port>) — painted the bright fold-marker green
|
|
337
|
+
(lime in dark, deep green in light), not the name's blue accent: the :port sits at the row's
|
|
338
|
+
far right, away from the play button, so making it the most prominent thing in the row lets the
|
|
339
|
+
eye snap to it the moment a just-launched row lands. The green also distinguishes "open the live
|
|
340
|
+
app" (port) from "open the source" (the blue name), and echoes the fold-marker on collapsed bulbs. */
|
|
341
|
+
.server-port { color: var(--fold-marker); font-size: .76rem; font-variant-numeric: tabular-nums; text-decoration: none; text-align: right; margin-right: .4rem; }
|
|
339
342
|
a.server-port:hover { text-decoration: underline; }
|
|
340
343
|
/* Logs reads like a link (flips to this server's console), not a button. */
|
|
341
344
|
.server-logs { color: var(--muted); font-size: .76rem; text-decoration: none; cursor: pointer; margin-left: .5rem; }
|
package/dist/index.js
CHANGED
|
@@ -156,7 +156,7 @@ ${t.comment}`:t.comment}this.doc.range[2]=t.offset;break}default:this.errors.pus
|
|
|
156
156
|
`)){if(!p.includes(`"${f}"`))continue;let m;try{m=JSON.parse(p)}catch{continue}let h=m?.[u];m?.type===f&&typeof h=="string"&&h&&(d=h)}return d},o=s(0,Math.min(65536,n)),a=n>65536?s(n-65536,65536):"",c=i(a,"custom-title","customTitle")||i(o,"custom-title","customTitle")||i(a,"ai-title","aiTitle")||i(o,"ai-title","aiTitle");if(c)return c.replace(/\s+/g," ").trim().slice(0,200);for(let l of o.split(`
|
|
157
157
|
`)){if(!l.trim())continue;let f;try{f=JSON.parse(l)}catch{continue}if(!f||_s(f)||f.type!=="user")continue;let u=f.message?.content,d="";typeof u=="string"?d=At(u):Array.isArray(u)&&(d=u.map(ka).filter(Boolean).join(" "));let p=d.replace(/\s+/g," ").trim();if(p)return(p.replace(/^Continuing from a prior session\. Here is the summary of our work so far:\s*/i,"").trim()||p).slice(0,200)}return""}finally{_d(e)}}async function Iv(){return Sa(F.cwd).sort((r,e)=>e.mtime-r.mtime).map(({sessionId:r,file:e,mtime:t})=>({sessionId:r,mtime:t,preview:Wd(e)}))}function _v(r,e){let t=Nd.get(r);if(t&&t.mtime===e)return t.turns;let n=[],s="";try{s=Pt(r,"utf8")}catch{return[]}for(let i of s.split(`
|
|
158
158
|
`)){if(!i)continue;let o;try{o=JSON.parse(i)}catch{continue}if(!o||_s(o)||o.type!=="user"&&o.type!=="assistant")continue;let a=o.message?.content,c="";if(typeof a=="string")c=At(a);else if(Array.isArray(a)){let l=a;c=o.type==="user"?l.map(ka).filter(Boolean).join(" "):l.filter(f=>f.type==="text"&&typeof f.text=="string").map(f=>f.text).join(" ")}c=c.replace(/\s+/g," ").trim(),c&&n.push({text:c,lower:c.toLowerCase()})}return Nd.set(r,{mtime:e,turns:n}),n}function Vd(r,e){let t=0,n="";for(let s of r){let i=s.lower.indexOf(e);if(!(i<0)&&(t++,!n)){let o=Math.max(0,i-Cd),a=Math.min(s.text.length,i+e.length+Cd);n=(o>0?"\u2026":"")+s.text.slice(o,a)+(a<s.text.length?"\u2026":"")}}return{hitCount:t,snippet:n}}async function $v(r){let e=r.toLowerCase(),t=[];for(let{sessionId:n,file:s,mtime:i}of Sa(F.cwd).sort((o,a)=>a.mtime-o.mtime)){let{hitCount:o,snippet:a}=Vd(_v(s,i),e);if(o&&(t.push({sessionId:n,mtime:i,preview:Wd(s),hitCount:o,snippet:a}),t.length>=Lv))break}return t}async function Mv(r){let e=F,t=q(va(e.cwd),`${r}.jsonl`);return Xe(t)?t===e.file?{ok:!0}:(Jd({sessionId:r,file:t}),{ok:!0}):{ok:!1,error:"session not found"}}async function Dv(r,e){let t=lv(r)?r:q(F.cwd,r);return Xe(t)?(ya(t,e),{ok:!0}):{ok:!1,error:"file not found"}}async function Bv(r){let e=F.cwd,t=q(e,"typebulbs");Ld(t,{recursive:!0});let n=ha(r),s=`${n}.bulb.md`;for(let c=2;Xe(q(t,s))&&Pt(q(t,s),"utf8")!==r;c++)s=`${n}-${c}.bulb.md`;let i=q(t,s);Xe(i)||$d(i,r);let o=q("typebulbs",s),a=await ms(o,{cwd:e,open:!0});return{ok:!0,file:o,pid:a.pid,url:a.url}}async function qv(){return $(F.cwd)}async function jv(r){return await He(r),{ok:!0}}async function Fv(){return Ns(F.cwd).map(r=>({...r,trusted:Ke(r.path)}))}async function Uv(r){let e=r.toLowerCase(),t=[];for(let n of Ns(F.cwd).sort((s,i)=>i.mtime-s.mtime)){let s="";try{s=Pt(n.path,"utf8")}catch{continue}let i=[];for(let c of s.split(`
|
|
159
|
-
`)){let l=c.replace(/\s+/g," ").trim();l&&i.push({text:l,lower:l.toLowerCase()})}let{hitCount:o,snippet:a}=Vd(i,e);o&&t.push({path:n.path,hitCount:o,snippet:a})}return t}async function Jv(r,e){let t=F.cwd;e!=null&&bt(r,e);let n=await ms(r,{cwd:t,open:!0,trust:e});return{ok:!0,file:n.file,pid:n.pid,url:n.url,trust:!!n.trust}}async function Kv(r){return{cap:await ga(r)}}async function Wv(r,e){return bt(r,e),{ok:!0}}async function Vv(r,e){return ue(r,e)}var fv,dv,va,pv,Bd,hv,ba,F,Sv,xv,Ov,Od,Nd,Lv,Cd,Hd=O(()=>{kd();Ed();fv=".typebulb",dv=q(Md(),".claude","projects"),va=r=>q(dv,uv(r));pv=`${fv}/locks`,Bd=5e3,hv=6e4;ba=5e4;F={cwd:process.cwd(),sessionId:"",sessionStartMs:Date.now(),buffer:[],partial:"",offset:0,latest:{in:0,out:0,cached:0,cacheCreate:0},everAttached:!1,entries:new Map};Sv=[/\[Request interrupted by user\b/i,/\[Tool use was interrupted\]/i,/Claude Code returned an error/i,/\[ede_diagnostic\]/i,/^No response requested\.?$/i,/^<task-notification\b/i,/^<system-reminder\b/i,/^<local-command-stdout\b/i,/^<local-command-stderr\b/i];xv=/<ide_[a-z_]+>[\s\S]*?<\/ide_[a-z_]+>/gi;Ov=new Cs;Od=q(Md(),".claude","sessions");Nd=new Map;Lv=50,Cd=110;gv(F.cwd);yv(F.cwd);Ud()});import*as tp from"fs/promises";import*as we from"path";import*as Aa from"fs/promises";import{existsSync as et,readFileSync as up}from"fs";import*as D from"path";import{pathToFileURL as fp}from"url";import{resolve as Ds}from"resolve.exports";import{init as Pa,parse as Oa}from"es-module-lexer";function Na(r,e){let t=D.join(r,"package.json");try{return JSON.parse(up(t,"utf8"))}catch{throw new Error(`--replace package '${e}' has no readable package.json at ${t}`)}}var Ms=["browser","import","default"],Ta=["node","import","default"];function Ca(r){let e=r.indexOf("=");if(e===-1)throw new Error(`--replace must be <name>=<path> (got '${r}')`);let t=r.slice(0,e).trim(),n=r.slice(e+1).trim();if(!t)throw new Error(`--replace missing package name (got '${r}')`);if(!n)throw new Error(`--replace missing path for '${t}'`);if(t.startsWith("@"))throw new Error(`--replace does not support scoped names yet; '${t}' is scoped`);return{name:t,dir:D.resolve(n)}}async function Ra(r){let{name:e,dir:t}=r;if(!et(t))throw new Error(`--replace path for '${e}' does not exist: ${t}`);let n=Na(t,e),s=dp(n,e),i=D.resolve(t,s);if(!et(i))throw new Error(`--replace package '${e}' entry not found on disk: ${i} \u2014 did you build it (e.g. \`pnpm run build\`)?`);let o=D.dirname(i),a=`/local/${e}/${D.basename(i)}`,c=pp(n,t);return await hp(e,i,o),{name:e,dir:t,entryAbs:i,serveDir:o,entryUrl:a,typesAbs:c}}function dp(r,e){if(r.exports!==void 0){let n;try{n=Ds(r,".",{browser:!0,conditions:Ms})}catch(i){throw new Error(`--replace package '${e}' "exports" does not resolve a browser entry (conditions: ${Ms.join(", ")}): ${i instanceof Error?i.message:i}`)}let s=Bs(n);if(!s)throw new Error(`--replace package '${e}' "exports" did not resolve "." to a single file (conditions: ${Ms.join(", ")}); too complex to override.`);return s}let t=r.module??r.main;if(!t)throw new Error(`--replace package '${e}' has no "exports", "module", or "main" entry to resolve.`);return t}function pp(r,e){if(r.exports!==void 0)try{let n=Ds(r,".",{conditions:["types"]}),s=Bs(n);if(s){let i=D.resolve(e,s);if(et(i))return i}}catch{}let t=r.types??r.typings;if(t){let n=D.resolve(e,t);if(et(n))return n}}function Bs(r){if(typeof r=="string")return r;if(Array.isArray(r))return r.find(e=>typeof e=="string")}async function hp(r,e,t){await Pa;let n=D.normalize(t),s=new Set,i=[e];for(;i.length;){let o=i.shift();if(s.has(o))continue;s.add(o);let a;try{a=await Aa.readFile(o,"utf8")}catch{continue}let c,l;try{[c,,,l]=Oa(a,o)}catch{continue}if(o===e&&!l)throw new Error(`override package '${r}' entry is not an ES module (no import/export syntax); CommonJS or non-module entries aren't supported (esm.sh would have to transform it).`);for(let f of c){if(f.d===-2)continue;let u=f.n;if(u&&!u.startsWith("node:")){if(u.startsWith("./")||u.startsWith("../")||u.startsWith("/")){let d=mp(o,u,n);d&&!s.has(d)&&i.push(d);continue}throw new Error(`override package must ship self-contained (bundle its dependencies); ${r} externalizes '${u}'`)}}}}function mp(r,e,t){let n=e.replace(/[?#].*$/,""),s=D.resolve(D.dirname(r),n),i=[s,s+".js",s+".mjs",D.join(s,"index.js"),D.join(s,"index.mjs")];for(let o of i)if(D.normalize(o).startsWith(t)&&et(o))return o}function gp(r,e,t){let n=Na(r,e),s;if(n.exports!==void 0)try{s=Bs(Ds(n,t,{conditions:Ta}))}catch(o){throw new Error(`--replace package '${e}' "exports" does not resolve a node entry for '${t}' (conditions: ${Ta.join(", ")}): ${o instanceof Error?o.message:o}`)}else t==="."&&(s=n.main??n.module);if(!s)throw new Error(`--replace package '${e}' has no node export for '${t}'.`);let i=D.resolve(r,s);if(!et(i))throw new Error(`--replace package '${e}' built file not found: ${i} \u2014 did you build it (e.g. \`pnpm run build\`)?`);return fp(i).href}async function Ia(r,e){await Pa;let t;try{[t]=Oa(r)}catch{return r}let n="",s=0;for(let i of t){if(i.d!==-1)continue;let o=i.n;if(!o||o!==e.name&&!o.startsWith(e.name+"/"))continue;let a=o===e.name?".":"."+o.slice(e.name.length),c=gp(e.dir,e.name,a);n+=r.slice(s,i.s)+c,s=i.e}return n+r.slice(s)}function _a(r){let
|
|
159
|
+
`)){let l=c.replace(/\s+/g," ").trim();l&&i.push({text:l,lower:l.toLowerCase()})}let{hitCount:o,snippet:a}=Vd(i,e);o&&t.push({path:n.path,hitCount:o,snippet:a})}return t}async function Jv(r,e){let t=F.cwd;e!=null&&bt(r,e);let n=await ms(r,{cwd:t,open:!0,trust:e});return{ok:!0,file:n.file,pid:n.pid,url:n.url,trust:!!n.trust}}async function Kv(r){return{cap:await ga(r)}}async function Wv(r,e){return bt(r,e),{ok:!0}}async function Vv(r,e){return ue(r,e)}var fv,dv,va,pv,Bd,hv,ba,F,Sv,xv,Ov,Od,Nd,Lv,Cd,Hd=O(()=>{kd();Ed();fv=".typebulb",dv=q(Md(),".claude","projects"),va=r=>q(dv,uv(r));pv=`${fv}/locks`,Bd=5e3,hv=6e4;ba=5e4;F={cwd:process.cwd(),sessionId:"",sessionStartMs:Date.now(),buffer:[],partial:"",offset:0,latest:{in:0,out:0,cached:0,cacheCreate:0},everAttached:!1,entries:new Map};Sv=[/\[Request interrupted by user\b/i,/\[Tool use was interrupted\]/i,/Claude Code returned an error/i,/\[ede_diagnostic\]/i,/^No response requested\.?$/i,/^<task-notification\b/i,/^<system-reminder\b/i,/^<local-command-stdout\b/i,/^<local-command-stderr\b/i];xv=/<ide_[a-z_]+>[\s\S]*?<\/ide_[a-z_]+>/gi;Ov=new Cs;Od=q(Md(),".claude","sessions");Nd=new Map;Lv=50,Cd=110;gv(F.cwd);yv(F.cwd);Ud()});import*as tp from"fs/promises";import*as we from"path";import*as Aa from"fs/promises";import{existsSync as et,readFileSync as up}from"fs";import*as D from"path";import{pathToFileURL as fp}from"url";import{resolve as Ds}from"resolve.exports";import{init as Pa,parse as Oa}from"es-module-lexer";function Na(r,e){let t=D.join(r,"package.json");try{return JSON.parse(up(t,"utf8"))}catch{throw new Error(`--replace package '${e}' has no readable package.json at ${t}`)}}var Ms=["browser","import","default"],Ta=["node","import","default"];function Ca(r){let e=r.indexOf("=");if(e===-1)throw new Error(`--replace must be <name>=<path> (got '${r}')`);let t=r.slice(0,e).trim(),n=r.slice(e+1).trim();if(!t)throw new Error(`--replace missing package name (got '${r}')`);if(!n)throw new Error(`--replace missing path for '${t}'`);if(t.startsWith("@"))throw new Error(`--replace does not support scoped names yet; '${t}' is scoped`);return{name:t,dir:D.resolve(n)}}async function Ra(r){let{name:e,dir:t}=r;if(!et(t))throw new Error(`--replace path for '${e}' does not exist: ${t}`);let n=Na(t,e),s=dp(n,e),i=D.resolve(t,s);if(!et(i))throw new Error(`--replace package '${e}' entry not found on disk: ${i} \u2014 did you build it (e.g. \`pnpm run build\`)?`);let o=D.dirname(i),a=`/local/${e}/${D.basename(i)}`,c=pp(n,t);return await hp(e,i,o),{name:e,dir:t,entryAbs:i,serveDir:o,entryUrl:a,typesAbs:c}}function dp(r,e){if(r.exports!==void 0){let n;try{n=Ds(r,".",{browser:!0,conditions:Ms})}catch(i){throw new Error(`--replace package '${e}' "exports" does not resolve a browser entry (conditions: ${Ms.join(", ")}): ${i instanceof Error?i.message:i}`)}let s=Bs(n);if(!s)throw new Error(`--replace package '${e}' "exports" did not resolve "." to a single file (conditions: ${Ms.join(", ")}); too complex to override.`);return s}let t=r.module??r.main;if(!t)throw new Error(`--replace package '${e}' has no "exports", "module", or "main" entry to resolve.`);return t}function pp(r,e){if(r.exports!==void 0)try{let n=Ds(r,".",{conditions:["types"]}),s=Bs(n);if(s){let i=D.resolve(e,s);if(et(i))return i}}catch{}let t=r.types??r.typings;if(t){let n=D.resolve(e,t);if(et(n))return n}}function Bs(r){if(typeof r=="string")return r;if(Array.isArray(r))return r.find(e=>typeof e=="string")}async function hp(r,e,t){await Pa;let n=D.normalize(t),s=new Set,i=[e];for(;i.length;){let o=i.shift();if(s.has(o))continue;s.add(o);let a;try{a=await Aa.readFile(o,"utf8")}catch{continue}let c,l;try{[c,,,l]=Oa(a,o)}catch{continue}if(o===e&&!l)throw new Error(`override package '${r}' entry is not an ES module (no import/export syntax); CommonJS or non-module entries aren't supported (esm.sh would have to transform it).`);for(let f of c){if(f.d===-2)continue;let u=f.n;if(u&&!u.startsWith("node:")){if(u.startsWith("./")||u.startsWith("../")||u.startsWith("/")){let d=mp(o,u,n);d&&!s.has(d)&&i.push(d);continue}throw new Error(`override package must ship self-contained (bundle its dependencies); ${r} externalizes '${u}'`)}}}}function mp(r,e,t){let n=e.replace(/[?#].*$/,""),s=D.resolve(D.dirname(r),n),i=[s,s+".js",s+".mjs",D.join(s,"index.js"),D.join(s,"index.mjs")];for(let o of i)if(D.normalize(o).startsWith(t)&&et(o))return o}function gp(r,e,t){let n=Na(r,e),s;if(n.exports!==void 0)try{s=Bs(Ds(n,t,{conditions:Ta}))}catch(o){throw new Error(`--replace package '${e}' "exports" does not resolve a node entry for '${t}' (conditions: ${Ta.join(", ")}): ${o instanceof Error?o.message:o}`)}else t==="."&&(s=n.main??n.module);if(!s)throw new Error(`--replace package '${e}' has no node export for '${t}'.`);let i=D.resolve(r,s);if(!et(i))throw new Error(`--replace package '${e}' built file not found: ${i} \u2014 did you build it (e.g. \`pnpm run build\`)?`);return fp(i).href}async function Ia(r,e){await Pa;let t;try{[t]=Oa(r)}catch{return r}let n="",s=0;for(let i of t){if(i.d!==-1)continue;let o=i.n;if(!o||o!==e.name&&!o.startsWith(e.name+"/"))continue;let a=o===e.name?".":"."+o.slice(e.name.length),c=gp(e.dir,e.name,a);n+=r.slice(s,i.s)+c,s=i.e}return n+r.slice(s)}function _a(r){let t={subcommand:"run",file:"",port:3e3,watch:!0,open:!(process.env.TERM_PROGRAM==="vscode"),server:!1,trust:!1,noTrust:!1,follow:!1,clear:!1,help:!1,version:!1,callArgs:[],hasArgsFlag:!1},n=["call","check","predict","logs","wait","stop","trust","untrust","skill","models","send"],s=r[0];if(s==="agent"||s?.startsWith("agent:")){t.subcommand="agent";let o=s.indexOf(":");if(o!==-1){let a=s.slice(o+1);a&&(t.agentTarget=a)}r=r.slice(1)}else s&&n.includes(s)&&(t.subcommand=s,r=r.slice(1));let i=[];for(let o=0;o<r.length;o++){let a=r[o];if(a==="--help"||a==="-h")t.help=!0;else if(a==="--version"||a==="-V")t.version=!0;else if(a==="--no-watch")t.watch=!1;else if(a==="--open")t.open=!0;else if(a==="--no-open")t.open=!1;else if(a==="--server")t.server=!0;else if(a==="--trust")t.trust=!0;else if(a==="--no-trust")t.noTrust=!0;else if(a==="--mode"){let c=r[++o];(!c||c.startsWith("-"))&&(console.error("Missing value for --mode (e.g. --mode staging)"),process.exit(1)),t.mode=c}else if(a==="--follow"||a==="-f")t.follow=!0;else if(a==="--clear")t.clear=!0;else if(a==="--run"){let c=r[++o];if(c==="latest")t.run="latest";else{let l=parseInt(c,10);(isNaN(l)||l<1)&&(console.error(`Invalid --run value: ${c} (a run number, or 'latest')`),process.exit(1)),t.run=l}}else if(a==="--bulbs")t.stopScope="bulbs";else if(a==="--agent")t.stopScope="agent";else if(a==="--global")t.stopScope="global";else if(a==="--match"){let c=r[++o];c===void 0&&(console.error("Missing value for --match (a substring new log lines must contain)"),process.exit(1)),t.match=c}else if(a==="--timeout"){let c=parseInt(r[++o],10);(isNaN(c)||c<=0)&&(console.error(`Invalid --timeout value: ${r[o]} (seconds)`),process.exit(1)),t.timeoutSec=c}else if(a==="--lines"||a==="-n"){let c=parseInt(r[++o],10);(isNaN(c)||c<0)&&(console.error(`Invalid --lines value: ${r[o]}`),process.exit(1)),t.lines=c}else if(a==="--port"||a==="-p"){let c=r[++o],l=parseInt(c,10);isNaN(l)&&(console.error(`Invalid port: ${c}`),process.exit(1)),t.port=l}else if(a==="--replace"||a.startsWith("--replace=")){let c=a.startsWith("--replace=")?a.slice(10):r[++o]??"";try{let l=Ca(c);if(t.local)throw new Error(`--replace can only be used once (got '${t.local.name}' and '${l.name}')`);t.local=l}catch(l){console.error(l instanceof Error?l.message:String(l)),process.exit(1)}}else if(a==="--args"||a.startsWith("--args=")){t.hasArgsFlag=!0;let c=a.startsWith("--args=")?a.slice(7):r[++o];c===void 0&&(console.error("Missing value for --args (a JSON array, or - to read it from stdin)"),process.exit(1)),t.argsJson=c}else a.startsWith("-")||(t.subcommand==="call"||t.subcommand==="send"?i.push(a):t.file=a)}return t.subcommand==="call"&&(i.length<2&&(console.error("Usage: typebulb call <file> <fn> [arg\u2026]"),process.exit(1)),t.file=i[0],t.fn=i[1],t.callArgs=i.slice(2)),t.subcommand==="send"&&(i.length<1&&(console.error("Usage: typebulb send <file> [message]"),process.exit(1)),t.file=i[0],t.sendMessage=i[1]),t}function La(){console.log(`
|
|
160
160
|
typebulb - Local bulb runner for Typebulb
|
|
161
161
|
|
|
162
162
|
Usage:
|
|
@@ -218,6 +218,8 @@ Options:
|
|
|
218
218
|
default 1800)
|
|
219
219
|
--no-watch Disable hot reload (watch is on by default)
|
|
220
220
|
-p, --port <port> Use a specific port (default: 3000)
|
|
221
|
+
--open Force-open the external browser (default off
|
|
222
|
+
inside VS Code's integrated terminal)
|
|
221
223
|
--no-open Don't auto-open browser
|
|
222
224
|
--trust Grant privileged capabilities (filesystem, AI,
|
|
223
225
|
and server.ts) for this run. Without it a bulb runs
|
|
@@ -1136,6 +1138,6 @@ ${Gw}
|
|
|
1136
1138
|
Shutting down...`),p.close(),y?.(),t(),await Nr(process.pid),process.exit(0)};process.on("SIGINT",E),process.on("SIGTERM",E)}import*as Qd from"path";import{EventEmitter as Qv}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||(Le(i,r,c.server),o=!0),await Er(c.server,s,n,l.dependencies)};if(console.log(`Running ${Qd.basename(r)}...`),await a(),e){console.log(`Watching for changes...
|
|
1137
1139
|
`);let c=new Qv;c.on("reload",async()=>{try{console.log("Re-running..."),await a()}catch(l){console.error("Error:",l)}}),As({bulbPath:r,emitter:c})}}import{Console as Xv}from"node:console";fe();Tr();async function Zd(r,e,t,n,s){sS();try{let p=L(r),m=(await $()).find(h=>L(h.file)===p);m&&fs(m.pid,ue(m.pid).offset)}catch{}let i=de(t),{bulb:o,config:a}=await ne(r);o.server||Ls("This bulb has no **server.ts** block; nothing to call."),Le(i,r,o.server);let c;try{c=await Er(o.server,s,n,a.dependencies)}catch(p){Ls(p instanceof Error?p.message:String(p))}let l=ks(c,e.fn);if(!l){let p=[...Object.keys(c).filter(m=>typeof c[m]=="function"),...Object.keys(la)];Ls(`Function '${e.fn}' not found. Available: ${p.length?p.join(", "):"(none)"}.`)}let f=await Zv(e),u;try{u=await l(...f)}catch(p){Ls(p instanceof Error?p.stack??p.message:String(p))}let d=rS(u);d!==void 0&&await iS(d+`
|
|
1138
1140
|
`),process.exit(0)}async function Zv(r){if(r.hasArgsFlag){let e=r.argsJson??"";return e==="-"&&(e=await oS()),tS(e)}return eS(r.positional)}function eS(r){return r.map(e=>{try{return JSON.parse(e)}catch{return e}})}function tS(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 rS(r){if(r!==void 0)return JSON.stringify(r,nS,2)}function nS(r,e){return typeof e=="bigint"?e.toString():e}function Ls(r){process.stderr.write(r+`
|
|
1139
|
-
`),process.exit(1)}function sS(){let r=new Xv(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 iS(r){return new Promise((e,t)=>{process.stdout.write(r,n=>n?t(n):e())})}async function oS(){let r=[];for await(let e of process.stdin)r.push(e);return Buffer.concat(r).toString("utf-8")}var Ea="0.15.
|
|
1141
|
+
`),process.exit(1)}function sS(){let r=new Xv(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 iS(r){return new Promise((e,t)=>{process.stdout.write(r,n=>n?t(n):e())})}async function oS(){let r=[];for await(let e of process.stdin)r.push(e);return Buffer.concat(r).toString("utf-8")}var Ea="0.15.5";function ep(r,e){r||(console.error(`This bulb runs server-side Node code (server.ts), which --trust must authorize:
|
|
1140
1142
|
${e}`),process.exit(1))}async function aS(){let r=_a(process.argv.slice(2));if(r.version&&(console.log(`typebulb ${Ea}`),process.exit(0)),r.help&&(La(),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(Ea);return}if(r.subcommand==="models"){await zf(r.mode);return}if(r.subcommand==="agent"){if(!r.agentTarget){await Vf(Ea);return}Sf(r.agentTarget)||(console.error(`Unknown agent '${r.agentTarget}'. Known: ${Pr().join(", ")}.`),process.exit(1));let l=await Zo(process.cwd(),r.agentTarget);if(l){console.log(`Mirror '${r.agentTarget}' is already running for this project:
|
|
1141
1143
|
${l.url}`),r.open&&await wt(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 yf(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)||(Pr().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&&Ke(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 Ra(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)}aS().catch(r=>{console.error("Error:",r.message),process.exit(1)});
|
package/package.json
CHANGED