agent-contracts-runtime 0.35.3 → 0.35.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.
@@ -4615,7 +4615,7 @@ Focus the audit on the "${e.focus}" layer only.`:"",r=["Audit the LLM command in
4615
4615
  `+"=".repeat(72)+`
4616
4616
 
4617
4617
  `;return{status:"dry_run",exitCode:0,data:{summary:v.join(y),riskLevel:"low",findings:[]}}}let o;try{o=await v7e(e.adapter,n,e.model)}catch(m){return{status:"failed",exitCode:12,error:t.adapterError(m.message)}}console.error(t.auditStarting(e.adapter));let s={workflowRegistry:Sf,taskRegistry:Au,agentRegistry:xu,handoffSchemas:Du},l={workflow:"audit-implementation",user_request:r,runtime:{maxFollowUps:2,maxRetries:1},hooks:{onGate:async()=>!0},context:{cwd:n},progressOutput:e.progressOutput},u=await vo(o,l,s);if(u.status!=="completed"){let m=u.escalation_reason??u.error_message??u.status;return{status:"failed",exitCode:1,error:t.auditFailed(m)}}let p=u.steps[u.steps.length-1]?.outcome?.data??{summary:t.auditSuccess,riskLevel:"low",findings:[]};return{status:"success",exitCode:y7e(p,e.failOn)?10:0,data:p}}var _7e={critical:"\u2717",error:"\u2717",warning:"!",info:"\xB7"};function IS(e){let t=CW();if(e.status==="dry_run")return e.data?.summary??t.dryRunHeader;if(e.status==="failed")return e.error??t.auditFailed("unknown");let n=e.data;if(!n)return t.auditSuccess;let i=[n.summary,""];if(i.push(t.riskLevel(n.riskLevel)),i.push(""),n.findings.length===0)i.push(t.noFindings);else{i.push(t.findingsHeader(n.findings.length));for(let r of n.findings){let a=_7e[r.severity]??"\xB7",o=r.id?`[${r.id}] `:"",s=r.target?` (${r.target})`:"";i.push(` ${a} ${o}${r.severity.toUpperCase()}: ${r.message}${s}`),r.recommendation&&i.push(` \u2192 ${r.recommendation}`)}i.push("")}if(n.recommendedActions&&n.recommendedActions.length>0){i.push(t.recommendedActionsHeader);for(let r of n.recommendedActions){let a=r.command?` \u2014 ${r.command}`:"";i.push(` [${r.kind}] ${r.title}${a}`)}}return i.join(`
4618
- `)}var Cu=No(Ls(),1);k7e();var $7e="0.35.3";async function RS(e){let t=await Aa(e),n=`${t.generatedDir}/index`,i;if(m4(`${n}.js`))i=`${n}.js`;else if(m4(`${n}.ts`))i=`${n}.ts`;else throw new Error(`Generated index file not found at ${n}.{js,ts}. Run \`agent-runtime generate\` first.`);let r=await import(new URL(`file://${i}`).href),a,o=`${t.generatedDir}/hooks/index`,s=m4(`${o}.js`)?`${o}.js`:m4(`${o}.ts`)?`${o}.ts`:null;if(s)try{let l=await import(new URL(`file://${s}`).href);l.guardrailHooks&&(a=l.guardrailHooks)}catch{}return{agentRegistry:r.agentRegistry??r.agents?.agentRegistry??{},taskRegistry:r.taskRegistry??r.tasks?.taskRegistry??{},handoffSchemas:r.handoffSchemas??r.handoffs?.handoffSchemas??{},workflowRegistry:r.workflowRegistry??r.workflows?.workflowRegistry??{},guardrailHooks:a}}async function x7e(e,t,n,i){switch(e){case"mock":{let{MockAdapter:r}=await Promise.resolve().then(()=>(f4(),p4));return new r}case"claude":{let{ClaudeAgentSdkAdapter:r}=await Promise.resolve().then(()=>(l4(),u4));return new r({cwd:n,guardrailHooks:t,...i?{model:i}:{}})}case"gemini":{let{GeminiSdkAdapter:r}=await Promise.resolve().then(()=>(jW(),IW));return new r({guardrailHooks:t,...i?{model:i}:{}})}case"cursor":{let{CursorSdkAdapter:r}=await Promise.resolve().then(()=>(d4(),c4)),a=process.env.CURSOR_API_KEY;if(!a)throw new Error("CURSOR_API_KEY environment variable is required for the cursor adapter");return r.create({apiKey:a,cwd:n,guardrailHooks:t,...i?{model:i}:{}})}case"openai":{let{OpenAIAgentsSdkAdapter:r}=await Promise.resolve().then(()=>(NW(),TW));return new r({...i?{model:i}:{}})}default:throw new Error(`Unknown adapter: ${e}. Available: mock, claude, gemini, cursor, openai`)}}function BS(e,t){let n=e.map((s,l)=>Math.max(s.length,...t.map(u=>(u[l]??"").length))),i=n.map(s=>"-".repeat(s)).join(" "),r=(s,l)=>s.padEnd(l),a=e.map((s,l)=>r(s,n[l])).join(" "),o=t.map(s=>s.map((l,u)=>r(l??"",n[u])).join(" "));return[a,i,...o].join(`
4618
+ `)}var Cu=No(Ls(),1);k7e();var $7e="0.35.4";async function RS(e){let t=await Aa(e),n=`${t.generatedDir}/index`,i;if(m4(`${n}.js`))i=`${n}.js`;else if(m4(`${n}.ts`))i=`${n}.ts`;else throw new Error(`Generated index file not found at ${n}.{js,ts}. Run \`agent-runtime generate\` first.`);let r=await import(new URL(`file://${i}`).href),a,o=`${t.generatedDir}/hooks/index`,s=m4(`${o}.js`)?`${o}.js`:m4(`${o}.ts`)?`${o}.ts`:null;if(s)try{let l=await import(new URL(`file://${s}`).href);l.guardrailHooks&&(a=l.guardrailHooks)}catch{}return{agentRegistry:r.agentRegistry??r.agents?.agentRegistry??{},taskRegistry:r.taskRegistry??r.tasks?.taskRegistry??{},handoffSchemas:r.handoffSchemas??r.handoffs?.handoffSchemas??{},workflowRegistry:r.workflowRegistry??r.workflows?.workflowRegistry??{},guardrailHooks:a}}async function x7e(e,t,n,i){switch(e){case"mock":{let{MockAdapter:r}=await Promise.resolve().then(()=>(f4(),p4));return new r}case"claude":{let{ClaudeAgentSdkAdapter:r}=await Promise.resolve().then(()=>(l4(),u4));return new r({cwd:n,guardrailHooks:t,...i?{model:i}:{}})}case"gemini":{let{GeminiSdkAdapter:r}=await Promise.resolve().then(()=>(jW(),IW));return new r({guardrailHooks:t,...i?{model:i}:{}})}case"cursor":{let{CursorSdkAdapter:r}=await Promise.resolve().then(()=>(d4(),c4)),a=process.env.CURSOR_API_KEY;if(!a)throw new Error("CURSOR_API_KEY environment variable is required for the cursor adapter");return r.create({apiKey:a,cwd:n,guardrailHooks:t,...i?{model:i}:{}})}case"openai":{let{OpenAIAgentsSdkAdapter:r}=await Promise.resolve().then(()=>(NW(),TW));return new r({...i?{model:i}:{}})}default:throw new Error(`Unknown adapter: ${e}. Available: mock, claude, gemini, cursor, openai`)}}function BS(e,t){let n=e.map((s,l)=>Math.max(s.length,...t.map(u=>(u[l]??"").length))),i=n.map(s=>"-".repeat(s)).join(" "),r=(s,l)=>s.padEnd(l),a=e.map((s,l)=>r(s,n[l])).join(" "),o=t.map(s=>s.map((l,u)=>r(l??"",n[u])).join(" "));return[a,i,...o].join(`
4619
4619
  `)}function A7e(e,t,n,i){if(e)return yo({stderr:!n,file:h4(e),naming:"single",label:i});if(t&&t.destination!=="none"){let r=t.destination;return yo({stderr:!n&&(r==="stderr"||r==="both"),file:r==="file"||r==="both"?t.file:void 0,naming:t.naming,label:i})}if(!n)return yo({stderr:!0})}var D7e={async init(e,t){try{let n=h4(e.output??"."),i=await SW({adapter:e.adapter??"mock",outputDir:n,force:e.force??!1});console.log(JSON.stringify(i,null,2))}catch(n){console.error(n.message),process.exit(1)}},async generate(e,t){try{let n=t.config??"./agent-runtime.config.yaml",i=await YG({clean:e.clean,check:e.check,templates:e.templates,configPath:n});i.check_mode?(i.has_differences&&(console.error("Generated files are out of date. Run `agent-runtime generate` to update."),process.exit(1)),console.log(JSON.stringify({...i,status:"up-to-date"},null,2))):console.log(JSON.stringify(i,null,2))}catch(n){console.error("Generate failed:",n.message),process.exit(1)}},async run(e,t,n,i){let r=e,a=t,o;if(n.file)try{let k=S7e(n.file,"utf8"),N=Cu.default.parse(k);r=N.workflow,r||(console.error(`Error: invocation file "${n.file}" must contain a "workflow" field.`),process.exit(3)),o={workflow:r,user_request:N.user_request,handoff:N.handoff,runtime:N.runtime,context:N.context},a=o.user_request??""}catch(k){console.error(`Failed to read invocation file: ${k.message}`),process.exit(3)}r||(console.error("Error: workflow-id is required (provide as argument or via --file)"),process.exit(3)),!o&&!a&&(console.error("Error: user-request is required (provide as argument or via --file)"),process.exit(3));let s=i.config??"./agent-runtime.config.yaml";await Qv(s)||(console.error("Generated files are stale or missing. Run `agent-runtime generate` first."),process.exit(3));let u=await Aa(s),c=await i4({pluginPaths:u.pluginPaths.length>0?u.pluginPaths:void 0,projectDir:u.configDir});c.loaded>0&&!i.quiet&&console.error(`Loaded ${c.loaded} plugin(s) from ${c.files.length} file(s)`);for(let k of c.errors)console.error(`Plugin load error (${k.file}): ${k.error}`);let d;try{d=await RS(s)}catch(k){console.error(`Failed to load generated contracts: ${k.message}`),process.exit(1);return}if(!d.workflowRegistry[r]){console.error(`Unknown workflow: ${r}`),console.error(`Available workflows: ${Object.keys(d.workflowRegistry).join(", ")}`),process.exit(3);return}let p=n.adapter??"mock",f=o?.context?.cwd??process.cwd(),{createModelResolver:m}=await Promise.resolve().then(()=>($S(),dW)),h=m({modelMapping:u.model_mapping,fallbackAdapter:p}),v=new Map,y=async k=>{let N=h.resolve(k),x=`${N.adapter}:${N.model??""}`,j=v.get(x);if(j)return j;let B=await x7e(N.adapter,d.guardrailHooks,f,N.model);return v.set(x,B),B},b;try{b=await y()}catch(k){console.error(k.message),process.exit(12);return}let E=Object.values(u.model_mapping).some(Boolean)||process.env.AGENT_RUNTIME_MODEL||process.env.AGENT_RUNTIME_MODEL_FAST||process.env.AGENT_RUNTIME_MODEL_STANDARD||process.env.AGENT_RUNTIME_MODEL_THINKING?y:b,D=u.recovery,C=n.maxRetries?parseInt(n.maxRetries,10):void 0,S=n.maxFollowUps?parseInt(n.maxFollowUps,10):void 0,A={workflowRegistry:d.workflowRegistry,taskRegistry:d.taskRegistry,agentRegistry:d.agentRegistry,handoffSchemas:d.handoffSchemas},I=n.autoApproveGates?async()=>!0:async(k,N)=>(console.error(`Gate "${k}": ${N}`),console.error("Use --auto-approve-gates to auto-approve. Rejecting by default."),!1),P=A7e(n.logFile,u.resolvedLogging.progressLog,i.quiet,r),$;try{if(o){let k={...o,runtime:{...o.runtime,maxFollowUps:S??o.runtime?.maxFollowUps??D.max_follow_ups,maxRetries:C??o.runtime?.maxRetries??D.max_retries},hooks:{onGate:I},progressOutput:P};$=await vo(E,k,A)}else $=await vo(E,r,{user_request:a,maxRetries:C??D.max_retries,maxFollowUps:S??D.max_follow_ups,onGate:I,progressOutput:P},A)}finally{P?.close()}console.log(JSON.stringify($,null,2)),$.status!=="completed"&&process.exit(1)},async list(e,t,n){e||(console.error("Error: resource is required (workflows, tasks, agents)"),process.exit(1));let i=["workflows","tasks","agents"];if(!i.includes(e)){console.error(`Unknown resource: ${e}`),console.error(`Available resources: ${i.join(", ")}`),process.exit(1);return}let r=n.config??"./agent-runtime.config.yaml",a;try{a=await RS(r)}catch(s){console.error(`Failed to load generated contracts: ${s.message}`),console.error("Run `agent-runtime generate` first."),process.exit(1);return}let o=t.format??"table";if(e==="agents"){let s=Object.values(a.agentRegistry);if(o==="json")console.log(JSON.stringify(s,null,2));else{if(s.length===0){console.log("No agents defined.");return}console.log(BS(["ID","Role","Mode","Purpose"],s.map(l=>[l.id,l.role_name,l.mode,l.purpose])))}}else if(e==="tasks"){let s=Object.values(a.taskRegistry);if(o==="json")console.log(JSON.stringify(s,null,2));else{if(s.length===0){console.log("No tasks defined.");return}console.log(BS(["ID","Agent","Description"],s.map(l=>[l.id,l.target_agent,l.description])))}}else{let s=Object.values(a.workflowRegistry);if(o==="json")console.log(JSON.stringify(s,null,2));else{if(s.length===0){console.log("No workflows defined.");return}console.log(BS(["ID","Steps","Description"],s.map(l=>[l.id,String(l.steps.length),l.description])))}}},async showPrompt(e,t,n){e||(console.error("Error: task-id is required"),process.exit(1));let i=n.config??"./agent-runtime.config.yaml",r;try{r=await RS(i)}catch(d){console.error(`Failed to load generated contracts: ${d.message}`),console.error("Run `agent-runtime generate` first."),process.exit(1);return}let a=r.taskRegistry[e];if(!a){console.error(`Unknown task: ${e}`),console.error(`Available tasks: ${Object.keys(r.taskRegistry).join(", ")}`),process.exit(1);return}let o=r.agentRegistry[a.target_agent];if(!o){console.error(`Unknown agent: ${a.target_agent} (referenced by task ${e})`),process.exit(1);return}let s=t.withPlugins??!1;if(s){let d=await Aa(i);await i4({pluginPaths:d.pluginPaths.length>0?d.pluginPaths:void 0,projectDir:d.configDir})}let l=t.userRequest??"(preview)",u=Ba(o,a,{user_request:l},{handoffSchemas:r.handoffSchemas});s&&(u=bn.applyPromptEnhancers(e,u,{user_request:l}));let c=t.format??"markdown";console.log(c==="json"?JSON.stringify({task_id:e,agent_id:a.target_agent,prompt:u,handoff_schema:a.result_handoff,plugins_applied:s},null,2):u)},async implement(e,t,n){e||(console.error("Error: description is required"),process.exit(3));let i=n.quiet,r=t.logFile?yo({stderr:!i,file:h4(t.logFile),naming:"single"}):i?void 0:yo({stderr:!0}),a;try{a=await AW(e,{adapter:t.adapter??"claude",projectDir:t.projectDir??".",dryRun:t.dryRun??!1,model:t.model,reportFormat:t.reportFormat??"text",progressOutput:r})}finally{r?.close()}a.status==="failed"&&(t.reportFormat==="json"?console.log(JSON.stringify({error:a.error,status:"failed"},null,2)):t.reportFormat==="yaml"?console.log(Cu.default.stringify({error:a.error,status:"failed"})):console.error(OS(a)),process.exit(a.exitCode??1));let o=a.data??{status:a.status},s;t.reportFormat==="json"?s=JSON.stringify(o,null,2):t.reportFormat==="yaml"?s=Cu.default.stringify(o):s=OS(a);let l=t.output;l?RW(l,s+`
4620
4620
  `):console.log(s)},async auditImplementation(e,t,n){let i=n.quiet,r=t.logFile?yo({stderr:!i,file:h4(t.logFile),naming:"single"}):i?void 0:yo({stderr:!0}),a;try{a=await PW({adapter:t.adapter??"claude",projectDir:e??".",focus:t.focus??"all",dryRun:t.dryRun??!1,failOn:t.failOn??"error",model:t.model,reportFormat:t.reportFormat??"text",progressOutput:r})}finally{r?.close()}a.status==="failed"&&(t.reportFormat==="json"?console.log(JSON.stringify({error:a.error,status:"failed"},null,2)):t.reportFormat==="yaml"?console.log(Cu.default.stringify({error:a.error,status:"failed"})):console.error(IS(a)),process.exit(a.exitCode));let o=a.data??{status:a.status},s;t.reportFormat==="json"?s=JSON.stringify(o,null,2):t.reportFormat==="yaml"?s=Cu.default.stringify(o):s=IS(a);let l=t.output;l?RW(l,s+`
4621
4621
  `):console.log(s),a.exitCode!==0&&process.exit(a.exitCode)},async agents(e,t){let n=e.format??"yaml";try{console.log(n==="json"?JSON.stringify(s4,null,2):Cu.default.stringify(s4,{lineWidth:120}))}catch(i){console.error(`Failed to output DSL: ${i.message}`),process.exit(1)}},async doctor(e){let t=e.config??"./agent-runtime.config.yaml",n=await yW(t),i=r=>r==="pass"?"\u2713":r==="warn"?"!":"\u2717";for(let r of n.checks){let a=i(r.status),o=r.message?` ${r.message}`:"";console.log(` ${a} ${r.name.padEnd(20)} ${r.status.toUpperCase()}${o}`)}console.log(""),n.all_passed?console.log("All checks passed."):console.log("Some checks failed."),console.log(JSON.stringify(n)),n.all_passed||(process.exitCode=1)}},C7e=cx(D7e,$7e);await C7e.parseAsync();