@zibby/core 0.1.43 → 0.1.45

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 CHANGED
@@ -108,7 +108,7 @@ const allIds = listSkillIds();
108
108
  ```
109
109
  @zibby/core
110
110
  ├── src/
111
- │ ├── strategies/ # Concrete agent strategies (extend AgentStrategy from @zibby/workflow)
111
+ │ ├── strategies/ # Concrete agent strategies (extend AgentStrategy from @zibby/agent-workflow)
112
112
  │ │ ├── claude-strategy.js
113
113
  │ │ ├── cursor-strategy.js
114
114
  │ │ ├── codex-strategy.js
@@ -129,7 +129,7 @@ const allIds = listSkillIds();
129
129
  │ └── index.js # Public API
130
130
 
131
131
  │ # Workflow engine itself (WorkflowGraph, Node, registries, AgentStrategy
132
- │ # base, timeline, etc.) lives in @zibby/workflow — core consumes it.
132
+ │ # base, timeline, etc.) lives in @zibby/agent-workflow — core consumes it.
133
133
  ├── templates/ # Built-in workflow templates
134
134
  │ ├── browser-test-automation/
135
135
  │ └── code-analysis/
@@ -1,4 +1,4 @@
1
- import{spawn as G}from"node:child_process";import{mkdirSync as R,existsSync as D,writeFileSync as J}from"node:fs";import{join as C}from"node:path";import{ContextLoader as F,WorkflowGraph as z,Node as H,WorkflowState as U,DEFAULT_OUTPUT_BASE as k,SESSIONS_DIR as B,SESSION_INFO_FILE as V}from"@zibby/workflow";var S=class m{constructor(){this.buffer="",this.extractedResult=null,this.rawText="",this.zodSchema=null,this.lastOutputLength=0,this.onToolCall=null,this._lastToolEmit=null}processChunk(t){if(!t)return null;this.buffer+=t;let r=this.buffer.split(`
1
+ import{spawn as G}from"node:child_process";import{mkdirSync as R,existsSync as D,writeFileSync as J}from"node:fs";import{join as C}from"node:path";import{ContextLoader as F,WorkflowGraph as z,Node as H,WorkflowState as U,DEFAULT_OUTPUT_BASE as k,SESSIONS_DIR as B,SESSION_INFO_FILE as V}from"@zibby/agent-workflow";var S=class m{constructor(){this.buffer="",this.extractedResult=null,this.rawText="",this.zodSchema=null,this.lastOutputLength=0,this.onToolCall=null,this._lastToolEmit=null}processChunk(t){if(!t)return null;this.buffer+=t;let r=this.buffer.split(`
2
2
  `);this.buffer=r.pop()||"";let s="";for(let o of r)if(o.trim())try{let a=JSON.parse(o);this._emitToolCalls(a);let e=this.extractText(a);if(e){if(this.rawText&&e.startsWith(this.rawText)){let n=e.substring(this.rawText.length);this.rawText=e,s+=n}else(!this.rawText.includes(e)||e.length<20)&&(this.rawText+=e,s+=e);this.tryExtractResult(this.rawText)}else this.isValidResult(a)&&(this.rawText+=`${o}
3
3
  `,s+=`${o}
4
4
  `,this.extractedResult=a)}catch{if(o.includes('"text"')||o.includes('"content"')){let e=o.match(/"text"\s*:\s*"([^"]*)/),n=o.match(/"content"\s*:\s*"([^"]*)/),i=e?e[1]:n?n[1]:null;i&&!this.rawText.includes(i)&&(s+=i,this.rawText+=i)}}return s||null}flush(){if(!this.buffer.trim())return null;let t="";try{let r=JSON.parse(this.buffer);this._emitToolCalls(r);let s=this.extractText(r);s&&(this.rawText+=s,t+=s,this.tryExtractResult(s))}catch{this.rawText+=this.buffer,t+=this.buffer,this.tryExtractResult(this.buffer)}return this.buffer="",t||null}_emitToolCalls(t){if(!this.onToolCall)return;let r=(e,n)=>{if(!e)return;let i=`${e}:${JSON.stringify(n??{})}`;this._lastToolEmit!==i&&(this._lastToolEmit=i,this.onToolCall(e,n??void 0))},s=e=>{if(e!=null){if(typeof e=="object"&&!Array.isArray(e))return e;if(typeof e=="string")try{return JSON.parse(e)}catch{return}}};if(t.type==="tool_use"||t.type==="tool_call"){if(t.name){r(t.name,s(t.input??t.arguments));return}let e=t.tool_call;if(e&&typeof e=="object"&&!Array.isArray(e)){let n=Object.keys(e);if(n.length===1){let i=n[0],l=e[i],d=l&&typeof l=="object"?l.args??l.input??l:void 0;r(i,s(d))}return}return}if(Array.isArray(t.tool_calls)){for(let e of t.tool_calls)r(e.name,s(e.input??e.arguments));return}let o=t.message??t;if(Array.isArray(o?.tool_calls)){for(let e of o.tool_calls)r(e.name,s(e.input??e.arguments));return}let a=o?.content??t.content;if(Array.isArray(a))for(let e of a)(e.type==="tool_use"||e.type==="tool_call")&&e.name&&r(e.name,s(e.input??e.arguments))}extractText(t){if(t.type==="assistant"&&t.message?.content){let r=t.message.content;if(Array.isArray(r))return r.filter(s=>s.type==="text"&&s.text).map(s=>s.text).join("")}return t.type==="thinking"&&t.text||t.text?t.text:t.content&&typeof t.content=="string"?t.content:t.delta?t.delta:null}tryExtractResult(t){if(!t||typeof t!="string")return;let r=[],s=/```json\s*\n?([\s\S]*?)\n?```/g,o;for(;(o=s.exec(t))!==null;){let u=o[1].trim();try{JSON.parse(u),r.push({text:u,source:"markdown"})}catch{}}let a=0,e=0;for(;a<t.length&&(a=t.indexOf("{",a),a!==-1);){let u=0,c=a;for(let f=a;f<t.length;f++)if(t[f]==="{")u++;else if(t[f]==="}"&&(u--,u===0)){c=f,r.push({text:t.substring(a,c+1),source:"brace"}),e++;break}a=c+1}let n=this.extractedResult,i=n?JSON.stringify(n).length:0,l=0,d=-1;for(let u=0;u<r.length;u++){let c=r[u];try{let f=c.text.replace(/,(\s*[}\]])/g,"$1"),p=JSON.parse(f);this.isValidResult(p)&&(l++,i=JSON.stringify(p).length,n=p,d=u)}catch{}}n&&(this.extractedResult=n)}isValidResult(t){if(!t||typeof t!="object"||Array.isArray(t)||t.session_id||t.timestamp_ms||t.type||t.call_id||t.tool_call||t.result&&typeof t.result=="object"&&(t.result.success&&typeof t.result.success=="object"||t.result.error&&typeof t.result.error=="object")||t.args&&typeof t.args=="object")return!1;if(this.zodSchema)try{return this.zodSchema.parse(t),!0}catch{return!1}return!0}getResult(){return this.extractedResult}getRawText(){return this.rawText}static extractResult(t,r=null){let s=new m;s.zodSchema=r,s.processChunk(t),s.flush();let o=s.getResult();return!o&&process.env.LOG_LEVEL==="debug"&&console.error("[StreamingParser] No result extracted from",t?.length||0,"chars"),o}};import{exec as P}from"node:child_process";import{promisify as N}from"node:util";import{existsSync as v}from"node:fs";import{join as b}from"node:path";import{homedir as A}from"node:os";var $=N(P);async function E(){try{return await $("cursor-agent --version"),"cursor-agent"}catch{let t=[b(A(),".local","bin","cursor-agent"),b(A(),".cursor","bin","cursor-agent"),b(A(),".cursor-agent","bin","cursor-agent")];for(let r of t)if(v(r))try{return await $(`"${r}" --version`),r}catch{}return null}}var O=class m{constructor(t={}){this.config=t,this.adapter=null,this.paths=t.paths||{specs:"test-specs",generated:"tests"},this.agentCommand=t.agentCommand||"cursor-agent",this.buildArgs=t.buildArgs||((r,s=!0)=>{let o=["-p",r,"--approve-mcps","--force"];return s&&(o.push("--output-format","stream-json"),o.push("--stream-partial-output")),o})}static extractJsonFromStream(t){return S.extractResult(t)}async initialize(t){this.adapter=t,t&&!t.isConnected()&&await t.connect()}buildGraph(){throw new Error("buildGraph() must be implemented by subclass")}async onComplete(t){}async run(t,r={}){let s=this.buildGraph(),o=typeof t=="object"&&!Array.isArray(t)?{input:t,...t,...r}:{input:t,...r};return await s.run(this,o)}async executeNode(t,r){let{prompt:s,outputSchema:o,model:a}=t,e=typeof s=="function"?s(r):s;console.log(`