Lines 35-75javascript
35${s.slice(-i)}`);let l=`Extract and format the following information into structured JSON matching the schema.
40Extract all relevant information and format it according to the schema. If any required fields are missing, do your best to infer them from the content.`,a={model:J.OPENAI_POSTPROCESSING,messages:[{role:"user",content:l}],response_format:{type:"json_schema",json_schema:{name:"extract",schema:o,strict:!0}}};p.info(`\u{1F4E4} Sending to OpenAI proxy: model=${J.OPENAI_POSTPROCESSING}, schema keys=${Object.keys(o.properties||{}).join(", ")}`),p.debug(` Schema size: ${JSON.stringify(o).length} chars`),p.debug(` Prompt size: ${l.length} chars`);try{let u={"Content-Type":"application/json"};proce ...
41 Run \`zibby login\` or set ZIBBY_USER_TOKEN environment variable.
42 Response: ${JSON.stringify(m)}`,{cause:u}):new Error(`Failed to format Cursor output: ${m?.error?.message||"Unknown error"}`,{cause:u})}throw p.error(`\u274C OpenAI proxy request failed: ${u.message}`),new Error(`Failed to format output: ${u.message}`,{cause:u})}}function Y(s
45${b.map(R=>` - ${R}`).join(`
49 curl https://cursor.com/install -fsS | bash
52 echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc
54Test with: agent --version`);let E=new de(e),S=null;if(o){let R=`zibby-result-${Date.now()}.json`;S=W(r,".zibby","tmp",R);let _=W(r,".zibby","tmp");Re(_)||Qt(_,{recursive:!
55\u25C6 Model: ${f||"auto"}${C}
56`);let I=(await import("chalk")).default,T=E.getUserPrompt();console.log(`
57${I.bold("Prompt sent to LLM:")}`),console.log(I.dim("\u2500".repeat(60))),console.log(I.dim(T)),console.log(I.dim("\u2500".repeat(60)));let P=E.
58`)}catch{}let k,$=null;try{let R=c||(process.env.ZIBBY_SESSION_PATH?String(process.env.ZIBBY_SESSION_PATH).trim():null);k=await this._spawnWithStreaming(w,v,r,a,null,R,h,d)}catch(R){$=R}let N=k?.stdout||"";if(o){let R=typeof o.parse==
59`):A.message?.slice(0,400);if(p.error(`\u274C [Agent] Zod validation FAILED - invalid output schema:
60${x}`),p.error(`\u{1F4C4} [Agent] Invalid JSON written to file:
61${JSON.stringify(_,null,2).slice(0,500)}`),!m)throw new Error(`Agent output failed schema validation:
64The agent wrote invalid data that doesn't match the required outputSchema.
65Enable strictMode in .zibby.config.js for automatic repair.`,{cause:A})}else{if(_)return p.info("\u2705 [Agent] File-based output extracted (no Zod parse fn) \u2014 accepting as structured"),m&&p.debug("[Agent] strictMode enabled but not needed \u2014 agent wrote valid file"),{raw:N,structured:_};M&&p.error("\u274C [Agent] Result file exists but produced no in-memory JSON (parse failed earlier)")}if(m&&!$){let A=k.parsedText,x=_?JSON.stringify(_):
66`),r=null;for(let n of t){let o=n.trim();if(o)try{let i=JSON.parse(o);if(i.type==="assistant"&&i.message?.content){let c=i.message.content;if(Array.isArray(c)){let l=c.filter(a=>a.type==="text"&&a.text).map(a=>a.text).join("");l&&(r=l)}else typeof c=="string"&&c&&(r=c)}}catch{}}return r?.trim()||null}_setupMcpConfig(e,t,r,n=null,o=null){let i=r?.headless,c=W(Le(),".cursor"),l=W(c,"mcp.json"),a={};if(Re(l))try{a=JSON.parse(qt(l,"utf-8"))}catch{}let u=a.mcpServers||{},d=r?.paths?.output||Pn,m=W(t||process.cwd(),d,kn),f=Array.isArray(n)?n.map(h=>Zt(h)).filter(Boolean):[...Rn()].map(([,h])=>h),g=n ...
67`;if(Ht(e)){let h=Wt(t||process.cwd()),b=W(h,".cursor","mcp.json");return Xt(b,y,"utf8"),p.debug(`[MCP] Isolated cursor-agent HOME (session-scoped mcp.json): ${h} | servers: ${Object.keys(u).join(", ")}`),{isolatedMcpHome:h}}return Re(c)||Qt(c,{recursive:!0}),Xt(l,y,
68`)){let j=U.replace(`${r}/`,"");k.has(j)||(k.add(j),F.push(j))}}catch{}let A="";F.length>0&&(A=` | \u{1F4C1} new: ${F.map(L=>L.split("/").pop()).join(", ")}`),k.size>0&&(A+=` | \u{1F4E6} total: ${k.size} files`),p.debug(`\u{1F493} [Agent] Running for ${_}s | ${y} lines output${A}`),y===0&&_>=30&&k.size===0&&(_<35&&p.warn(`\u26A0\uFE0F [Agent] No output after ${_}s \u2014 agent may be stuck. Check your CURSOR_API_KEY.`),_>=60&&(h=!0,b=b||"stall",p.error(`\u274C [Agent] No response after ${_}s \u2014 killing. Verify CURSOR_API_KEY is valid and agent CLI works: agent --version`),T.kill("SIGTERM" ...
69${m.slice(-2e3)}`),T.kill("SIGTERM"),setTimeout(()=>{T.killed||T.kill("SIGKILL")},5e3)},n),R=new V;R.onToolCall=(_,M)=>{let F=_,A=M;if(_==="mcpToolCall"&&M?.name)F=M.name.replace(/^mcp_+[^_]+_+/,""),F.includes("-")&&F.split("-")[0]===F.split("-")[1]&&(F=F.split("-")[0]),A=M.args??M.input??M;else{if(_==="readToolCall"||_==="editToolCall"||_==="writeToolCall")return;(_.startsWith("mcp__")||_.includes("ToolCall"))&&(F=_.replace(/^mcp_+[^_]+_+/,"").replace(/ToolCall$/,""))}if(F.includes("memory")?Z.stepMemory(`Tool: ${F}`
70`).filter(x=>x.trim());y+=A.length}),T.stderr.on("data",_=>{let M=_.toString();f+=M,g=Date.now(),w||(w=!0);let F=M.split(`
71`).filter(A=>A.trim());for(let A of F)p.warn(`\u26A0\uFE0F [Agent stderr] ${A}`)}),T.on("close",(_,M)=>{if(E=!0,C(),clearTimeout(B),clearInterval(N),v&&clearInterval(v),P&&clearTimeout(P),l&&!l.aborted)try{l.removeEventListener("abort",D)}catch{}R.flush();let F=Math.round((Date.now()-d)/1e3);if(p.debug(`[Agent] Exited: code=${_}, signal=${M}, elapsed=${F}s, output=${m.length} chars`),h){if(b==="aborted"){let L=new Error("Aborted via signal");L.name="AbortError",u(L);return}u(new Error(`Cursor Agent timed out after ${F}s (limit: ${n/1e3}s). ${y} lines produced. Last output ${Math.round((Date.n ...
72Partial output (last 500 chars):
73${m.slice(-500)}`:"No output captured."}`));return}if(_!==0){u(new Error(`Cursor Agent failed: exit code ${_}, signal ${l}. ${f.trim()?`
74Stderr: ${f.slice(-1e3)}`:""}${m.trim()?`
75Stdout (last 500 chars): ${m.slice(-500)}`:""}`));return}let A=R.getResult(),x=A?JSON.stringify(A,null,2):R.getRawText()||m||"";a({stdout:m||f||"",parsedText:x})}),T.on("error",_
Long lines were clipped for display.