typebulb 0.31.3 → 0.31.4
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 +1 -0
- package/dist/agents/claude/client.js +80 -80
- package/dist/agents/pi/client.js +79 -79
- package/dist/agents/pi/matchu-patchu.ts +1 -1
- package/dist/index.js +3 -3
- package/package.json +1 -1
|
@@ -2280,7 +2280,7 @@ var Patcher = class {
|
|
|
2280
2280
|
|
|
2281
2281
|
// cli/agents/pi/server/piPatcherExtension.ts
|
|
2282
2282
|
var DESCRIPTION = true ? "Apply unified diffs to files \u2014 tolerant of form, strict about intent. Repairs sloppy AI-generated diffs (mangled headers, whitespace drift, missing prefixes; line numbers can be wrong or absent \u2014 hunks anchor by fuzzy-matched context lines) and applies all hunks atomically when the intent is unambiguous; fails with a precise, typed error when it isn't. Use for multi-hunk edits in one step, or when exact string-replacement editing fails on whitespace or invisible characters." : "Apply unified diffs to files.";
|
|
2283
|
-
var BUILD_TAG = true ? "matchu-patchu-pi 0.3.1, built 2026-07-19
|
|
2283
|
+
var BUILD_TAG = true ? "matchu-patchu-pi 0.3.1, built 2026-07-19 19:25:11" : "matchu-patchu-pi dev";
|
|
2284
2284
|
var errorBlocks = (errors) => {
|
|
2285
2285
|
const parts = [`Patch failed with ${errors.length} error(s):`];
|
|
2286
2286
|
for (const e of errors) parts.push("", e.toString());
|
package/dist/index.js
CHANGED
|
@@ -544,8 +544,8 @@ export default function (pi) {
|
|
|
544
544
|
`))>=0;){let o=n.slice(0,i);n=n.slice(i+1),o.endsWith("\r")&&(o=o.slice(0,-1)),o&&e(o)}})}var tE,rE,Qm,nE,sE,iE,oE,aE,Yi,Vi,Zm,eh=A(()=>{bt();tE=3e4,rE=5e3,Qm=2e3,nE=2e3,sE=12e4,iE=8e3,oE=15e3,aE=new Set(["get_state","get_commands","get_available_models","set_model","set_thinking_level","cycle_thinking_level","get_session_stats","compact","set_auto_compaction","get_fork_messages","fork","clone","set_session_name","export_html","bash","abort_bash"]),Yi=new Set;process.on("exit",()=>{for(let r of Yi)try{r.kill()}catch{}});Vi=class{#e;#a=!1;#c=0;#i=!1;#l=null;#m=null;#t=null;#n=null;#u=new Map;#r=[];#h=null;#w=null;#g=null;#d;#f;#y="";#A=1;#s=new Map;#v;#b;constructor(e,t,n=(s,i)=>Xm(s,{cwd:i,shell:!0,stdio:["pipe","pipe","pipe"],env:{...process.env,TYPEBULB_MIRROR:"1"}})){if(this.#v=new Promise(o=>{this.#b=o}),t?.includes('"')){this.#f="session path contains a quote \u2014 cannot drive it",this.#b();return}let s=t?`pi --mode rpc --session "${t}"`:"pi --mode rpc",i;try{i=n(s,e)}catch(o){this.#f=`could not start pi: ${U(o)}`,this.#b();return}this.#e=i,this.#d=t,Yi.add(i),i.stdout&&cE(i.stdout,o=>this.#T(o)),i.stderr&&i.stderr.on("data",o=>{this.#y=(this.#y+o.toString()).slice(-nE)}),i.on("error",o=>this.#k(`could not start pi: ${o.message}`)),i.on("exit",o=>{this.#e===i&&this.#k(o?`pi exited (code ${o})${this.#y.trim()?`: ${this.#y.trim()}`:""}`:"pi exited"),Yi.delete(i),this.#b()}),this.#o({type:"get_state"}).then(o=>{let a=o.data?.sessionFile;typeof a=="string"&&a&&(this.#d=a);let c=o.data?.model;c&&typeof c.id=="string"&&c.id&&(this.#g=c.id)}).catch(()=>{}),this.#S()}get streaming(){return this.#a||Date.now()<this.#c}get draft(){return this.#l}get echo(){return this.#m}get queue(){return this.#h}get stats(){return this.#w}get model(){return this.#g}get sessionFile(){return this.#d}get error(){return this.#f}get status(){if(this.#t)return this.#t;if(this.#n){if(Date.now()<this.#n.until)return{text:this.#n.text,kind:this.#n.kind};this.#n=null}return this.#u.size?{text:[...this.#u.values()].join(" \xB7 "),kind:"info"}:null}get dialog(){let e=Date.now();for(;this.#r.length;){let t=this.#r[0];if(e<t.until)return t.req;this.#r.shift(),t.ownTimeout||this.#x({type:"extension_ui_response",id:t.req.id,cancelled:!0})}return null}notice(e,t){this.#p(e,t)}respondUi(e,t){let n=this.#r.findIndex(o=>o.req.id===e);if(n<0)return{ok:!1,error:"dialog expired or already answered"};let[s]=this.#r.splice(n,1),i={type:"extension_ui_response",id:e};return t.cancelled?i.cancelled=!0:s.req.method==="confirm"?i.confirmed=!!t.confirmed:i.value=t.value??"",this.#x(i),{ok:!0}}async rpc(e){if(!aE.has(e.type))return{ok:!1,error:`command not allowed: ${e.type}`};try{let t=await this.#o(e);if(t.success&&e.type==="set_model"){let n=t.data?.id;typeof n=="string"&&n&&(this.#g=n)}if(t.success&&(e.type==="fork"||e.type==="clone")){try{let s=(await this.#o({type:"get_state"})).data?.sessionFile;typeof s=="string"&&s&&(this.#d=s)}catch{}return{ok:!0,data:{...t.data??{},sessionFile:this.#d}}}return t.success?{ok:!0,data:t.data}:{ok:!1,error:t.error??`pi rejected ${e.type}`}}catch(t){return{ok:!1,error:U(t)}}}async send(e,t){let n=this.streaming,s=n?e.trimStart().startsWith("/")?{type:"prompt",message:e,streamingBehavior:t?.followUp?"followUp":"steer"}:{type:t?.followUp?"follow_up":"steer",message:e}:{type:"prompt",message:e},i;try{i=await this.#o(s)}catch(o){return{ok:!1,error:U(o)}}return i.success&&!n&&(this.#c=Date.now()+rE),i.success&&!n&&!e.trimStart().startsWith("/")&&(this.#m=e),i.success?{ok:!0}:{ok:!1,error:i.error??"pi rejected the message"}}async stop(){if(this.#e)try{await this.#o({type:"abort"})}catch{}}clearCompletedDraft(){this.#i||(this.#l=null)}clearEcho(){this.#m=null}async dispose(){let e=this.#e;if(e){if(this.#e=void 0,this.#a){try{e.stdin?.write(JSON.stringify({type:"abort"})+`
|
|
545
545
|
`)}catch{}await Promise.race([this.#v,Zm(Qm)])}try{e.stdin?.end()}catch{}if(await Promise.race([this.#v,Zm(Qm)]),e.exitCode===null&&!e.killed)if(process.platform==="win32"&&e.pid)try{Xm("taskkill",["/pid",String(e.pid),"/T","/F"],{stdio:"ignore"})}catch{}else try{e.kill("SIGKILL")}catch{}Yi.delete(e),this.#r=[],this.#E("pi was shut down")}}#x(e){try{this.#e?.stdin?.write(JSON.stringify(e)+`
|
|
546
546
|
`)}catch{}}#p(e,t){let n=e.length>200?e.slice(0,200)+"\u2026":e;n&&(this.#n={text:n,kind:t,until:Date.now()+(t==="info"?iE:oE)})}#S(){this.#o({type:"get_session_stats"}).then(e=>{if(!e.success||!e.data)return;let t=e.data;this.#w={cost:typeof t.cost=="number"?t.cost:0,contextTokens:typeof t.contextUsage?.tokens=="number"?t.contextUsage.tokens:null,contextPercent:typeof t.contextUsage?.percent=="number"?t.contextUsage.percent:null}}).catch(()=>{})}#o(e){let t=this.#e;if(!t?.stdin?.writable)return Promise.reject(new Error(this.#f??"pi is not running"));let n=`tb-${this.#A++}`;return new Promise((s,i)=>{let o=setTimeout(()=>{this.#s.delete(n),i(new Error("pi did not respond (30s)"))},tE);o.unref?.(),this.#s.set(n,{resolve:s,timer:o});try{t.stdin.write(JSON.stringify({id:n,...e})+`
|
|
547
|
-
`)}catch(a){clearTimeout(o),this.#s.delete(n),i(new Error(U(a)))}})}#T(e){let t;try{t=JSON.parse(e)}catch{return}switch(t.type){case"response":{let n=t,s=n.id?this.#s.get(n.id):void 0;s&&(this.#s.delete(n.id),clearTimeout(s.timer),s.resolve(n));return}case"agent_start":this.#a=!0,this.#c=0;return;case"agent_end":this.#a=!1,this.#c=0,this.#i=!1,this.#t=null,this.#h=null,this.#S();return;case"message_start":{t.message?.role==="assistant"&&(this.#i=!0,this.#l={text:"",thinking:""});return}case"message_update":{if(!this.#i)return;let n=t.message,s=Array.isArray(n?.content)?n.content:[];this.#l={text:s.filter(
|
|
548
|
-
`)};return}case"message_end":this.#i=!1;return;case"auto_retry_start":this.#t={text:`retrying after a transient error (attempt ${Number(t.attempt)||1}/${Number(t.maxAttempts)||"?"})\u2026`,kind:"warning"};return;case"auto_retry_end":this.#t=null,t.success===!1&&this.#p(`retries exhausted: ${String(t.finalError??"unknown error")}`,"error");return;case"compaction_start":this.#t={text:"compacting context\u2026",kind:"info"};return;case"compaction_end":{this.#t=null;let n=t.result;typeof t.errorMessage=="string"&&t.errorMessage?this.#p(`compaction failed: ${t.errorMessage}`,"error"):n?.tokensBefore&&this.#p(`compacted: ~${Math.round(n.tokensBefore/1e3)}k \u2192 ~${Math.round((n.estimatedTokensAfter??0)/1e3)}k tokens`,"info"),this.#S();return}case"queue_update":{let n=Array.isArray(t.steering)?t.steering.map(String):[],s=Array.isArray(t.followUp)?t.followUp.map(String):[];this.#h=n.length||s.length?{steering:n,followUp:s}:null;return}case"extension_ui_request":{let n=String(t.method??"");if(n==="select"||n==="confirm"||n==="input"||n==="editor"){let s=typeof t.timeout=="number"&&t.timeout>0?t.timeout:void 0;this.#r.push({req:{id:String(t.id??""),method:n,title:typeof t.title=="string"?t.title:void 0,message:typeof t.message=="string"?t.message:void 0,options:Array.isArray(t.options)?t.options.map(String):void 0,placeholder:typeof t.placeholder=="string"?t.placeholder:void 0,prefill:typeof t.prefill=="string"?t.prefill:void 0},until:Date.now()+(s??sE),ownTimeout:s!==void 0})}else if(n==="notify"){let s=t.notifyType==="warning"?"warning":t.notifyType==="error"?"error":"info";this.#p(String(t.message??""),s),console.log(`[composer] pi extension: ${String(t.message??"")}`)}else if(n==="setStatus"){let s=String(t.statusKey??"");typeof t.statusText=="string"&&t.statusText?this.#u.set(s,t.statusText):this.#u.delete(s)}return}default:return}}#k(e){this.#f=e,this.#a=!1,this.#c=0,this.#i=!1,this.#l=null,this.#m=null,this.#t=null,this.#n=null,this.#u.clear(),this.#r=[],this.#h=null,this.#w=null,this.#g=null,this.#e=void 0,this.#E(e)}#E(e){for(let[,t]of this.#s)clearTimeout(t.timer),t.resolve({type:"response",success:!1,error:e});this.#s.clear()}},Zm=r=>new Promise(e=>{setTimeout(e,r).unref?.()})});import{existsSync as th,readFileSync as lE,realpathSync as uE}from"fs";import{join as Jt,dirname as ih,resolve as dE}from"path";import{homedir as rh}from"os";function pE(r,e){let t=Jt(r,".pi");if(fE.some(s=>th(Jt(t,s))))return!0;let n=Jt(e,".agents","skills");for(let s=r;;){let i=Jt(s,".agents","skills");if(i!==n&&th(i))return!0;let o=ih(s);if(o===s)return!1;s=o}}function mE(r,e){for(let t=e;;){if(r[t]===!0||r[t]===!1)return!0;let n=ih(t);if(n===t)return!1;t=n}}function oh(r,e){try{let t=e?.agentDir??Jt(rh(),".pi","agent"),n=nh(e?.home??process.env.HOME??rh()),s=nh(dE(r));if(!pE(s,n))return null;let i=sh(Jt(t,"settings.json")).defaultProjectTrust;return i==="always"||i==="never"||mE(sh(Jt(t,"trust.json")),s)?null:"pi has no trust decision for this project \u2014 running untrusted; run `pi` once in a terminal to grant it"}catch{return null}}var fE,nh,sh,ah=A(()=>{fE=["settings.json","extensions","skills","prompts","themes","SYSTEM.md","APPEND_SYSTEM.md"],nh=r=>{try{return uE(r)}catch{return r}},sh=r=>{try{return JSON.parse(lE(r,"utf8"))}catch{return{}}}});import{statSync as hE,openSync as gE,readSync as yE,closeSync as bE,existsSync as lh}from"fs";import{join as Gi}from"path";import{homedir as Sl}from"os";import{execFile as wE}from"child_process";async function SE(r){let e=Gi(Sl(),".pi","agent","bin",process.platform==="win32"?"fd.exe":"fd");for(let t of["fd","fdfind",...lh(e)?[e]:[]]){let n=await new Promise(s=>{wE(t,["--base-directory",r,"--type","f","--follow","--hidden","--exclude",".git"],{maxBuffer:67108864},(i,o)=>s(i?null:o))});if(n!==null)return n.split(`
|
|
547
|
+
`)}catch(a){clearTimeout(o),this.#s.delete(n),i(new Error(U(a)))}})}#T(e){let t;try{t=JSON.parse(e)}catch{return}switch(t.type){case"response":{let n=t,s=n.id?this.#s.get(n.id):void 0;s&&(this.#s.delete(n.id),clearTimeout(s.timer),s.resolve(n));return}case"agent_start":this.#a=!0,this.#c=0;return;case"agent_end":this.#a=!1,this.#c=0,this.#i=!1,this.#t=null,this.#h=null,this.#S();return;case"message_start":{t.message?.role==="assistant"&&(this.#i=!0,this.#l={text:"",thinking:""});return}case"message_update":{if(!this.#i)return;let n=t.message,s=Array.isArray(n?.content)?n.content:[],i=s[s.length-1];this.#l={text:s.filter(o=>o?.type==="text").map(o=>o.text??"").join(""),thinking:s.filter(o=>o?.type==="thinking").map(o=>o.thinking??"").join(`
|
|
548
|
+
`),tool:i?.type==="toolCall"?i.name:void 0};return}case"message_end":this.#i=!1;return;case"auto_retry_start":this.#t={text:`retrying after a transient error (attempt ${Number(t.attempt)||1}/${Number(t.maxAttempts)||"?"})\u2026`,kind:"warning"};return;case"auto_retry_end":this.#t=null,t.success===!1&&this.#p(`retries exhausted: ${String(t.finalError??"unknown error")}`,"error");return;case"compaction_start":this.#t={text:"compacting context\u2026",kind:"info"};return;case"compaction_end":{this.#t=null;let n=t.result;typeof t.errorMessage=="string"&&t.errorMessage?this.#p(`compaction failed: ${t.errorMessage}`,"error"):n?.tokensBefore&&this.#p(`compacted: ~${Math.round(n.tokensBefore/1e3)}k \u2192 ~${Math.round((n.estimatedTokensAfter??0)/1e3)}k tokens`,"info"),this.#S();return}case"queue_update":{let n=Array.isArray(t.steering)?t.steering.map(String):[],s=Array.isArray(t.followUp)?t.followUp.map(String):[];this.#h=n.length||s.length?{steering:n,followUp:s}:null;return}case"extension_ui_request":{let n=String(t.method??"");if(n==="select"||n==="confirm"||n==="input"||n==="editor"){let s=typeof t.timeout=="number"&&t.timeout>0?t.timeout:void 0;this.#r.push({req:{id:String(t.id??""),method:n,title:typeof t.title=="string"?t.title:void 0,message:typeof t.message=="string"?t.message:void 0,options:Array.isArray(t.options)?t.options.map(String):void 0,placeholder:typeof t.placeholder=="string"?t.placeholder:void 0,prefill:typeof t.prefill=="string"?t.prefill:void 0},until:Date.now()+(s??sE),ownTimeout:s!==void 0})}else if(n==="notify"){let s=t.notifyType==="warning"?"warning":t.notifyType==="error"?"error":"info";this.#p(String(t.message??""),s),console.log(`[composer] pi extension: ${String(t.message??"")}`)}else if(n==="setStatus"){let s=String(t.statusKey??"");typeof t.statusText=="string"&&t.statusText?this.#u.set(s,t.statusText):this.#u.delete(s)}return}default:return}}#k(e){this.#f=e,this.#a=!1,this.#c=0,this.#i=!1,this.#l=null,this.#m=null,this.#t=null,this.#n=null,this.#u.clear(),this.#r=[],this.#h=null,this.#w=null,this.#g=null,this.#e=void 0,this.#E(e)}#E(e){for(let[,t]of this.#s)clearTimeout(t.timer),t.resolve({type:"response",success:!1,error:e});this.#s.clear()}},Zm=r=>new Promise(e=>{setTimeout(e,r).unref?.()})});import{existsSync as th,readFileSync as lE,realpathSync as uE}from"fs";import{join as Jt,dirname as ih,resolve as dE}from"path";import{homedir as rh}from"os";function pE(r,e){let t=Jt(r,".pi");if(fE.some(s=>th(Jt(t,s))))return!0;let n=Jt(e,".agents","skills");for(let s=r;;){let i=Jt(s,".agents","skills");if(i!==n&&th(i))return!0;let o=ih(s);if(o===s)return!1;s=o}}function mE(r,e){for(let t=e;;){if(r[t]===!0||r[t]===!1)return!0;let n=ih(t);if(n===t)return!1;t=n}}function oh(r,e){try{let t=e?.agentDir??Jt(rh(),".pi","agent"),n=nh(e?.home??process.env.HOME??rh()),s=nh(dE(r));if(!pE(s,n))return null;let i=sh(Jt(t,"settings.json")).defaultProjectTrust;return i==="always"||i==="never"||mE(sh(Jt(t,"trust.json")),s)?null:"pi has no trust decision for this project \u2014 running untrusted; run `pi` once in a terminal to grant it"}catch{return null}}var fE,nh,sh,ah=A(()=>{fE=["settings.json","extensions","skills","prompts","themes","SYSTEM.md","APPEND_SYSTEM.md"],nh=r=>{try{return uE(r)}catch{return r}},sh=r=>{try{return JSON.parse(lE(r,"utf8"))}catch{return{}}}});import{statSync as hE,openSync as gE,readSync as yE,closeSync as bE,existsSync as lh}from"fs";import{join as Gi}from"path";import{homedir as Sl}from"os";import{execFile as wE}from"child_process";async function SE(r){let e=Gi(Sl(),".pi","agent","bin",process.platform==="win32"?"fd.exe":"fd");for(let t of["fd","fdfind",...lh(e)?[e]:[]]){let n=await new Promise(s=>{wE(t,["--base-directory",r,"--type","f","--follow","--hidden","--exclude",".git"],{maxBuffer:67108864},(i,o)=>s(i?null:o))});if(n!==null)return n.split(`
|
|
549
549
|
`).filter(Boolean).map(s=>s.replace(/\\/g,"/"))}return null}function xE(r){return`--${r.replace(/^[/\\]/,"").replace(/[/\\:]/g,"-")}--`}function ch(r){return r.type==="message"?kE(r.message?.role):r.type==="custom_message"?r.display!==!1:!1}var vE,kE,Pr,xl=A(()=>{Oi();Qc();Zc();zm();eh();ah();vE=Gi(Sl(),".pi","agent","sessions");kE=r=>r==="user"||r==="assistant"||r==="toolResult"||r==="bashExecution";Pr=class extends vr{displayName="Pi Mirror";detectsSelf(){return process.env.PI_CODING_AGENT==="true"}detectsInstalled(){return lh(Gi(Sl(),".pi","agent"))}ensureHarnessSupport(){Gm()}createDriver(e,t){let n=new Vi(e,t),s=oh(e);return s&&n.notice(s,"warning"),n}walkFiles(e){return SE(e)}sessionsDir(e){return Gi(vE,xE(e))}listSessionFiles(e){return _i(this.sessionsDir(e))}parseEntry(e){let t;try{t=JSON.parse(e)}catch{return null}return!t||t.type==="session"||!t.id?null:t}idOf(e){return e.id}parentOf(e){return e.parentId??void 0}timestampOf(e){return e.timestamp}isSidechain(e){return!1}isLeafType(e){return ch(e)}isRecoveryNoise(e){return!1}apply(e,t){let n=[];if(e.type==="custom_message"){if(e.display===!1)return{events:n};let i=this.contentText(e.content).trim();return i&&n.push({type:"user",text:i}),{events:n}}if(e.type!=="message"||!e.message)return{events:n};let s=e.message;if(s.role==="user"){let i=this.contentText(s.content).trim();return i&&n.push({type:"user",text:i}),{events:n}}if(s.role==="toolResult"){let i=this.contentText(s.content);return n.push({type:"tool_result",id:s.toolCallId??"",content:i,isError:!!s.isError,digest:Ge(i)}),{events:n}}if(s.role==="bashExecution")return s.command&&!s.excludeFromContext&&n.push({type:"user",text:`$ ${s.command}`}),{events:n};if(s.role==="assistant"){let i=Array.isArray(s.content)?s.content:[],o=i.filter(d=>d.type==="text").map(d=>d.text??"").join(""),a=i.filter(d=>d.type==="thinking").map(d=>d.thinking??"").join(`
|
|
550
550
|
`),c=i.filter(d=>d.type==="toolCall").map(d=>({id:d.id??"",name:d.name??"",input:d.arguments??{}}));if(o||a||c.length){let d=Date.parse(e.timestamp??""),p=!isNaN(d)&&d>=t;n.push({type:"assistant",text:o,thinking:a,tools:c,live:p})}let l=s.usage,f=l?(l.input??0)+(l.output??0)+(l.cacheRead??0)+(l.cacheWrite??0):0,u=l&&f>0&&s.stopReason!=="aborted"&&s.stopReason!=="error"?{in:l.input??0,out:l.output??0,cached:l.cacheRead??0,cacheCreate:l.cacheWrite??0}:void 0;return{events:n,usage:u,model:s.model,cost:l?.cost?.total}}return{events:n}}chainWorking(e){let t;for(let a of e)ch(a)&&(t=a);if(!t||t.type==="custom_message")return!1;let n=t.message.role;if(n==="user"||n==="toolResult"||n==="bashExecution")return!0;if(n!=="assistant")return!1;let i=(Array.isArray(t.message.content)?t.message.content:[]).filter(a=>a.type==="toolCall").map(a=>a.id);if(!i.length)return!1;let o=new Set;for(let a of e)a.type==="message"&&a.message?.role==="toolResult"&&a.message.toolCallId&&o.add(a.message.toolCallId);return i.some(a=>a&&!o.has(a))}sessionAlive(){}readPreview(e){let t;try{t=gE(e,"r")}catch{return""}try{let s=65536;try{s=hE(e).size}catch{}let i=(u,d)=>{let p=Buffer.alloc(d),y=yE(t,p,0,d,u);return p.subarray(0,y).toString("utf8")},o=i(0,Math.min(65536,s)),a=s>65536?i(s-65536,65536):"",c=u=>{let d="";for(let p of u.split(`
|
|
551
551
|
`))if(p.includes('"session_info"'))try{let y=JSON.parse(p);y?.type==="session_info"&&typeof y.name=="string"&&y.name&&(d=y.name)}catch{}return d},l="";for(let u of o.split(`
|
|
@@ -1993,5 +1993,5 @@ ${pP}
|
|
|
1993
1993
|
`);let c=0,l=Promise.resolve();Vt({target:r,onChange:()=>{let f=++c;l=l.then(async()=>{if(f===c)try{console.log("Re-running..."),await a()}catch(u){console.error("Error:",u)}})}})}}yt();import{Console as bP}from"node:console";Ne();async function wy(r,e,t,n,s){kP();try{let p=xr(await z(),r)[0];p&&(Ii(p.pid,Re(p.pid).offset),console.error(`note: 'call' boots a fresh server.ts instance; the running server (${p.url}) is not contacted \u2014 state shared with it must live on disk.`))}catch{}let i=ge(t),{bulb:o,config:a}=await ke(r);o.server||Vn("This bulb has no **server.ts** block; nothing to call."),gt(i,r,o.server);let c;try{c=await _n(o.server,r,n,a.dependencies,s)}catch(p){Vn(p instanceof Error?p.message:String(p))}let l=To(c,e.fn);if(!l){let p=[...Object.keys(c).filter(y=>typeof c[y]=="function"),...Object.keys(Ao)];Vn(`Function '${e.fn}' not found. Available: ${p.length?p.join(", "):"(none)"}.`)}let f=await wP(e);if(Po(l)){try{for await(let p of l(...f))await by(JSON.stringify(p,vy)+`
|
|
1994
1994
|
`)}catch(p){Vn(p instanceof Error?p.stack??p.message:String(p))}return yy(0)}let u;try{u=await l(...f)}catch(p){Vn(p instanceof Error?p.stack??p.message:String(p))}let d=xP(u);d!==void 0&&await by(d+`
|
|
1995
1995
|
`),yy(0)}function yy(r){process.exitCode=r,setTimeout(()=>process.exit(r),2e3).unref?.()}async function wP(r){if(r.hasArgsFlag){let e=r.argsJson??"";return e==="-"&&(e=await EP()),SP(e)}return vP(r.positional)}function vP(r){return r.map(e=>{try{return JSON.parse(e)}catch{return e}})}function SP(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 xP(r){if(r!==void 0)return JSON.stringify(r,vy,2)}function vy(r,e){return typeof e=="bigint"?e.toString():e}function Vn(r){process.stderr.write(r+`
|
|
1996
|
-
`),process.exit(1)}function kP(){let r=new bP(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 by(r){return new Promise((e,t)=>{process.stdout.write(r,n=>n?t(n):e())})}async function EP(){let r=[];for await(let e of process.stdin)r.push(e);return Buffer.concat(r).toString("utf-8")}var ru="0.31.
|
|
1996
|
+
`),process.exit(1)}function kP(){let r=new bP(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 by(r){return new Promise((e,t)=>{process.stdout.write(r,n=>n?t(n):e())})}async function EP(){let r=[];for await(let e of process.stdin)r.push(e);return Buffer.concat(r).toString("utf-8")}var ru="0.31.4";function Sy(r,e){r||(console.error(`This bulb runs server-side Node code (server.ts), which --trust must authorize:
|
|
1997
1997
|
${e}`),process.exit(1))}async function AP(){let r=bu(process.argv.slice(2));if(r.version&&(console.log(`typebulb ${ru}`),process.exit(0)),r.help&&(wu(),process.exit(0)),jg(),r.subcommand==="logs"){await Gg(r.file||void 0,{follow:r.follow,clear:r.clear,run:r.run,lines:r.lines});return}if(r.subcommand==="wait"){await zg(r.file||void 0,{match:r.match,timeoutSec:r.timeoutSec});return}if(r.subcommand==="stop"){r.stopScope?await Qg(r.stopScope):await Xg(r.file||void 0);return}if(r.subcommand==="send"){await ey(r.file,r.sendMessage,r.sendWaitMs??0);return}if(r.subcommand==="skill"){await Wg(ru);return}if(r.subcommand==="models"){await Kg(r.mode);return}if(r.subcommand==="pull"){await Jm(r.file||void 0,{force:r.force,mode:r.mode});return}if(r.subcommand==="push"){await Wm(r.file||void 0,{force:r.force,mode:r.mode});return}if(r.subcommand==="agent"){await(r.agentTarget?my(r):Jg(ru));return}if(r.subcommand==="trust"||r.subcommand==="untrust"){await Bg(r.file||void 0,r.subcommand==="trust");return}let e;if(!r.file||r.file==="."){let c=await dm(process.cwd());c||(console.error("No .bulb.md file found in current directory"),process.exit(1)),e=c}else e=Gt.resolve(r.file);await xy.access(e).then(()=>!0,()=>!1)||(Rr().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:Gt.relative(process.cwd(),e)||Gt.basename(e),s=`npx typebulb --trust ${n.includes(" ")?`"${n}"`:n}`;if(r.subcommand==="predict"){await Dg(e,s);return}let i=!r.noTrust&&jt(e);i&&!r.trust&&console.error("trust: granted from memory (run `typebulb untrust` to revoke)"),r.trust=r.noTrust?!1:r.trust||i;let o;try{o=await ke(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 hu(r.local)}catch(c){console.error(c instanceof Error?c.message:String(c)),process.exit(1)}console.error(`replace: ${a.name} \u2192 ${Gt.relative(process.cwd(),a.dir)||"."}`)}if(r.subcommand==="check"){await Mg(e,a);return}if(r.subcommand==="call"){Sy(r.trust,s),await wy(e,{fn:r.fn,positional:r.callArgs,argsJson:r.argsJson,hasArgsFlag:r.hasArgsFlag},r.mode,a,r.dir);return}if(o&&o.bulb.server&&(Xs(o.bulb)||r.server)){Sy(r.trust,s),await gy(e,r.watch,r.mode,a,r.dir);return}await uy(e,r,s,a)}AP().catch(r=>{console.error("Error:",r.message),process.exit(1)});
|
package/package.json
CHANGED