@xenosystem/agent-sdk 0.9.10 → 0.9.11

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.
Files changed (87) hide show
  1. package/dist/agents/index.cjs +9 -9
  2. package/dist/agents/index.d.cts +12 -2
  3. package/dist/agents/index.d.ts +12 -2
  4. package/dist/agents/index.js +16 -16
  5. package/dist/agents/metafile-cjs.json +1 -1
  6. package/dist/agents/metafile-esm.json +1 -1
  7. package/dist/artifacts/browser.cjs +1 -1
  8. package/dist/artifacts/browser.d.cts +2 -2
  9. package/dist/artifacts/browser.d.ts +2 -2
  10. package/dist/artifacts/browser.js +1 -1
  11. package/dist/artifacts/{diff-artifact-C2tQZWcs.d.cts → diff-artifact-CmhmeSu5.d.cts} +87 -7
  12. package/dist/artifacts/{diff-artifact-C2tQZWcs.d.ts → diff-artifact-CmhmeSu5.d.ts} +87 -7
  13. package/dist/artifacts/index.cjs +8 -8
  14. package/dist/artifacts/index.d.cts +22 -5
  15. package/dist/artifacts/index.d.ts +22 -5
  16. package/dist/artifacts/index.js +8 -8
  17. package/dist/artifacts/metafile-cjs.json +1 -1
  18. package/dist/artifacts/metafile-esm.json +1 -1
  19. package/dist/automation/index.cjs +2 -2
  20. package/dist/automation/index.d.cts +97 -7
  21. package/dist/automation/index.d.ts +97 -7
  22. package/dist/automation/index.js +2 -2
  23. package/dist/automation/metafile-cjs.json +1 -1
  24. package/dist/automation/metafile-esm.json +1 -1
  25. package/dist/control-plane/index.cjs +7 -7
  26. package/dist/control-plane/index.d.cts +19 -2
  27. package/dist/control-plane/index.d.ts +19 -2
  28. package/dist/control-plane/index.js +7 -7
  29. package/dist/control-plane/metafile-cjs.json +1 -1
  30. package/dist/control-plane/metafile-esm.json +1 -1
  31. package/dist/electron/index.cjs +142 -142
  32. package/dist/electron/index.d.cts +24 -4
  33. package/dist/electron/index.d.ts +24 -4
  34. package/dist/electron/index.js +140 -140
  35. package/dist/electron/metafile-cjs.json +1 -1
  36. package/dist/electron/metafile-esm.json +1 -1
  37. package/dist/hooks/index.d.cts +10 -1
  38. package/dist/hooks/index.d.ts +10 -1
  39. package/dist/hosted/index.cjs +1 -1
  40. package/dist/hosted/index.js +1 -1
  41. package/dist/hosted/metafile-cjs.json +1 -1
  42. package/dist/hosted/metafile-esm.json +1 -1
  43. package/dist/index.cjs +327 -327
  44. package/dist/index.d.cts +192 -24
  45. package/dist/index.d.ts +192 -24
  46. package/dist/index.js +328 -328
  47. package/dist/mcp/index.cjs +17 -17
  48. package/dist/mcp/index.js +17 -17
  49. package/dist/mcp/metafile-cjs.json +1 -1
  50. package/dist/mcp/metafile-esm.json +1 -1
  51. package/dist/metafile-cjs.json +1 -1
  52. package/dist/metafile-esm.json +1 -1
  53. package/dist/oracle/index.cjs +1 -1
  54. package/dist/oracle/index.d.cts +86 -6
  55. package/dist/oracle/index.d.ts +86 -6
  56. package/dist/oracle/index.js +1 -1
  57. package/dist/oracle/metafile-cjs.json +1 -1
  58. package/dist/oracle/metafile-esm.json +1 -1
  59. package/dist/providers/index.cjs +10 -10
  60. package/dist/providers/index.d.cts +1 -0
  61. package/dist/providers/index.d.ts +1 -0
  62. package/dist/providers/index.js +10 -10
  63. package/dist/providers/metafile-cjs.json +1 -1
  64. package/dist/providers/metafile-esm.json +1 -1
  65. package/dist/recipes/index.cjs +2 -2
  66. package/dist/recipes/index.d.cts +10 -1
  67. package/dist/recipes/index.d.ts +10 -1
  68. package/dist/recipes/index.js +2 -2
  69. package/dist/recipes/metafile-cjs.json +1 -1
  70. package/dist/recipes/metafile-esm.json +1 -1
  71. package/dist/research/index.cjs +3 -3
  72. package/dist/research/index.d.cts +86 -6
  73. package/dist/research/index.d.ts +86 -6
  74. package/dist/research/index.js +3 -3
  75. package/dist/research/metafile-cjs.json +1 -1
  76. package/dist/research/metafile-esm.json +1 -1
  77. package/dist/session/index.cjs +20 -20
  78. package/dist/session/index.js +21 -21
  79. package/dist/session/metafile-cjs.json +1 -1
  80. package/dist/session/metafile-esm.json +1 -1
  81. package/dist/utils/index.cjs +20 -20
  82. package/dist/utils/index.d.cts +3 -1
  83. package/dist/utils/index.d.ts +3 -1
  84. package/dist/utils/index.js +17 -17
  85. package/dist/utils/metafile-cjs.json +1 -1
  86. package/dist/utils/metafile-esm.json +1 -1
  87. package/package.json +23 -22
@@ -1,7 +1,7 @@
1
- "use strict";var W=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var ke=(n,e)=>{for(var t in e)W(n,t,{get:e[t],enumerable:!0})},Ae=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of we(e))!ve.call(n,o)&&o!==t&&W(n,o,{get:()=>e[o],enumerable:!(r=Re(e,o))||r.enumerable});return n};var ye=n=>Ae(W({},"__esModule",{value:!0}),n);var qe={};ke(qe,{AGENT_DAEMON_PROTOCOL_VERSION:()=>A,AgentDaemonClient:()=>H,AgentDaemonServer:()=>q,AgentEventStore:()=>x,AgentRunController:()=>J,AgentRunStore:()=>I,MonitorManager:()=>Q,MonitorStopTool:()=>Z,MonitorTool:()=>X,OtelExporter:()=>Y,UsageAccumulator:()=>M,UsageLedger:()=>K,WorkflowPlanner:()=>y,WorkflowRuntime:()=>G,WorkflowStore:()=>U,acquireControlPlaneLock:()=>D,createAgentRunId:()=>ce,getAgentRunDir:()=>Fe,getAgentRunStoreDir:()=>Le});module.exports=ye(qe);var ue=require("node:crypto"),d=require("node:fs"),de=require("node:os"),u=require("node:path");var E="0.9.10";var h=require("node:fs"),$=require("node:os"),re=require("node:path");function Se(){return new Date().toISOString()}function Ee(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function ne(n){try{return JSON.parse((0,h.readFileSync)(n,"utf8"))}catch{return null}}function De(n){if(!n||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function xe(n){return n.hostname!==(0,$.hostname)()?!0:De(n.pid)}function te(n,e){(0,h.mkdirSync)((0,re.dirname)(n),{recursive:!0}),(0,h.writeFileSync)(n,JSON.stringify(e,null,2)+`
2
- `,{encoding:"utf8",flag:"wx"})}function Ie(n,e){let t=ne(n);t?.pid!==e.pid||t.hostname!==e.hostname||(0,h.rmSync)(n,{force:!0})}function D(n,e,t){let r=Se(),o={schemaVersion:1,name:e,pid:process.pid,hostname:(0,$.hostname)(),processStartedAt:Ee(),version:t,acquiredAt:r,updatedAt:r};try{te(n,o)}catch(i){if(i.code!=="EEXIST")throw i;let a=ne(n);if(a&&xe(a))throw new Error(`${e} is already locked by PID ${a.pid} on ${a.hostname}.`);(0,h.rmSync)(n,{force:!0}),te(n,o)}return{record:o,release:()=>{Ie(n,o)}}}var ie=require("node:crypto"),R=require("node:fs"),k=require("node:path");function oe(n){return(0,k.basename)(n).replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,96)}function se(n){return(0,R.existsSync)(n)?(0,R.readFileSync)(n,"utf8").split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{try{return JSON.parse(e)}catch{return null}}).filter(e=>e!==null):[]}var x=class{constructor(e){this.runsDir=e;(0,R.mkdirSync)(this.runsDir,{recursive:!0})}runsDir;pathFor(e){return(0,k.join)(this.runsDir,oe(e),"events.jsonl")}append(e,t,r={},o=new Date().toISOString()){let i=this.pathFor(e);(0,R.mkdirSync)((0,k.dirname)(i),{recursive:!0});let s=D(`${i}.lock`,`events:${oe(e)}`,E);try{let a=se(i).reduce((N,m,P)=>Math.max(N,m.sequence??P),-1)+1,f={schemaVersion:1,eventId:`event_${(0,ie.randomUUID)()}`,sequence:a,runId:e,type:t,timestamp:o,payload:r};return(0,R.appendFileSync)(i,`${JSON.stringify(f)}
3
- `,"utf8"),f}finally{s.release()}}read(e){return se(this.pathFor(e))}tail(e,t=100){let r=Math.max(0,Math.min(1e4,Math.trunc(t)));return r===0?[]:this.read(e).slice(-r)}};var Te=1,Pe=(0,u.join)((0,de.homedir)(),".xeno-agent"),be=(0,u.join)(process.env.XENO_AGENT_HOME??Pe,"daemon"),F=(0,u.join)(be,"runs");function p(){return new Date().toISOString()}function Oe(n=new Date){return n.toISOString().replace(/[^0-9]/g,"").slice(0,14)}function L(n){return n.replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,80)}function j(n){return(0,u.resolve)(n)}function O(n){return j(n).toLowerCase()}function ae(n,e){let t=O(n),r=O(e);return t===r||t.startsWith(`${r}\\`)||t.startsWith(`${r}/`)}function _e(n,e){return!!(O(n.cwd)===O(e)||n.git?.root&&ae(e,n.git.root)||n.git?.worktree&&ae(e,n.git.worktree))}function Ce(n){return L(Buffer.from(j(n)).toString("base64url"))}function Ue(){return{input:0,output:0,total:0}}function b(n){try{return JSON.parse((0,d.readFileSync)(n,"utf8"))}catch{return null}}function Me(n){return n instanceof Error&&/\balready locked by PID\b/.test(n.message)}function Ne(n,e){(0,d.mkdirSync)((0,u.dirname)(n),{recursive:!0});let t=`${n}.${process.pid}.${Date.now()}.tmp`;(0,d.writeFileSync)(t,JSON.stringify(e,null,2)+`
4
- `,"utf8"),(0,d.renameSync)(t,n)}function Ve(n){if(!n||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function We(n){return n==="completed"||n==="failed"||n==="cancelled"||n==="interrupted"}function $e(n,e){return n.pinned!==e.pinned?n.pinned?-1:1:Date.parse(e.updatedAt)-Date.parse(n.updatedAt)}function Le(){return F}function Fe(n){return(0,u.join)(F,n)}function ce(n=new Date){return`run_${Oe(n)}_${(0,ue.randomUUID)().slice(0,8)}`}var I=class{constructor(e=F){this.runsDir=e;(0,d.mkdirSync)(this.runsDir,{recursive:!0}),this.eventStore=new x(this.runsDir)}runsDir;eventStore;create(e){let t=ce(),r=(0,u.join)(this.runsDir,t);(0,d.mkdirSync)(r,{recursive:!0});let o=p(),i=(0,u.join)(r,"events.jsonl"),s={schemaVersion:Te,runId:t,sessionId:t,rootRunId:t,cwd:j(e.cwd),workspaceId:Ce(e.cwd),prompt:e.prompt,...e.title?{title:e.title}:{},status:"starting",model:e.model,...e.effort?{effort:e.effort}:{},...e.agent?{agent:e.agent}:{},...e.git?{git:e.git}:{},permissionMode:e.permissionMode,...e.cliVersion?{createdByCliVersion:e.cliVersion}:{},createdBySdkVersion:e.sdkVersion??E,createdAt:o,updatedAt:o,lastActivityAt:o,pinned:!!e.pinned,attachedClients:0,...e.cliVersion?{cliVersion:e.cliVersion}:{},...e.sdkVersion?{sdkVersion:e.sdkVersion}:{},stdoutPath:(0,u.join)(r,"stdout.log"),stderrPath:(0,u.join)(r,"stderr.log"),eventsPath:i,usage:Ue(),children:[],tags:[]};return(0,d.writeFileSync)(s.stdoutPath,"","utf8"),(0,d.writeFileSync)(s.stderrPath,"","utf8"),(0,d.writeFileSync)(s.eventsPath,"","utf8"),this.write(s),this.appendEvent(t,"run_created",{cwd:s.cwd,model:s.model,...s.agent?{agent:s.agent}:{},...s.git?{git:s.git}:{},permissionMode:s.permissionMode,pinned:s.pinned}),s}get(e){let t=b(this.recordPath(e));return t?this.refreshRecordStatus(t):null}list(e={}){if(!(0,d.existsSync)(this.runsDir))return[];let t=(0,d.readdirSync)(this.runsDir,{withFileTypes:!0}).filter(r=>r.isDirectory()).map(r=>{try{return this.get(r.name)}catch(o){if(Me(o))return b(this.recordPath(r.name));throw o}}).filter(r=>r!==null).filter(r=>e.all||!e.cwd||_e(r,e.cwd)).filter(r=>!e.status||e.status.includes(r.status)).sort($e);return typeof e.limit=="number"&&e.limit>0?t.slice(0,e.limit):t}markSpawned(e,t,r){return this.update(e,o=>({...o,status:"running",workerPid:t,...r?{workerVersion:r}:{},startedAt:o.startedAt??p(),lastActivityAt:p()}))}markStarted(e,t){return this.update(e,r=>({...r,status:"running",workerPid:t.pid,...t.workerVersion?{workerVersion:t.workerVersion}:{},...t.model?{model:t.model}:{},...t.effort?{effort:t.effort}:{},startedAt:r.startedAt??p(),lastActivityAt:p()}))}markCompleted(e,t){return this.update(e,r=>({...r,status:t.status,...t.statusReason?{statusReason:t.statusReason}:{},exitCode:t.exitCode??null,usage:t.usage??r.usage,endedAt:p(),lastActivityAt:p()}))}markCancelled(e,t){return this.update(e,r=>({...r,status:"cancelled",statusReason:t,endedAt:p(),lastActivityAt:p()}))}markPaused(e,t="Paused by user."){let r=this.update(e,o=>({...o,status:"paused",statusReason:t,lastActivityAt:p()}));return r&&this.appendEvent(e,"run_paused",{reason:t}),r}markResumed(e,t="Resumed by user."){let r=this.update(e,o=>{let i={...o,status:"running",statusReason:t,lastActivityAt:p()};return delete i.endedAt,delete i.exitCode,i});return r&&this.appendEvent(e,"run_resumed",{reason:t}),r}setPinned(e,t){let r=this.update(e,o=>({...o,pinned:t,lastActivityAt:p()}));return r&&this.appendEvent(e,t?"run_pinned":"run_unpinned",{pinned:t}),r}appendEvent(e,t,r={}){let o=b(this.recordPath(e)),i=this.eventStore.append(e,t,r);o&&this.update(e,s=>({...s,lastActivityAt:i.timestamp}))}readEvents(e){return this.get(e)?this.eventStore.read(e):[]}delete(e){(0,d.rmSync)((0,u.join)(this.runsDir,e),{recursive:!0,force:!0})}refreshRecordStatus(e){if(We(e.status))return e;if(e.workerPid&&!Ve(e.workerPid)){let t={...e,status:"failed",statusReason:"Worker process is no longer running and did not record a terminal status.",endedAt:e.endedAt??p(),updatedAt:p()};return this.write(t),t}return e}update(e,t){let r=b(this.recordPath(e));if(!r)return null;let o=t(r);return o.updatedAt=p(),this.write(o),o}write(e){let t=D((0,u.join)(this.runDir(e.runId),"run.lock"),`run:${e.runId}`,E);try{Ne(this.recordPath(e.runId),e)}finally{t.release()}}recordPath(e){return(0,u.join)(this.runsDir,L((0,u.basename)(e)),"run.json")}runDir(e){return(0,u.join)(this.runsDir,L((0,u.basename)(e)))}};function le(n){return n==="completed"||n==="failed"||n==="cancelled"||n==="interrupted"}var J=class{constructor(e={}){this.options=e;this.store=e.store??new I}options;store;create(e){return this.store.create(e)}async start(e){let t=this.create(e);if(!this.options.spawn)return t;try{let r=await this.options.spawn(t),o=this.store.markSpawned(t.runId,r.pid,r.workerVersion);if(!o)throw new Error(`Run disappeared during spawn: ${t.runId}`);return this.store.appendEvent(t.runId,"run_started",{pid:r.pid}),o}catch(r){let o=r instanceof Error?r.message:String(r);throw this.store.markCompleted(t.runId,{status:"failed",statusReason:o,exitCode:null}),this.store.appendEvent(t.runId,"run_start_failed",{reason:o}),r}}get(e){return this.store.get(e)}list(e={}){return this.store.list(e)}events(e,t){let r=this.store.readEvents(e);return t===void 0?r:r.slice(-Math.max(0,Math.trunc(t)))}async stop(e,t="Stopped by user."){let r=this.store.get(e);if(!r||le(r.status))return r;await this.options.stop?.(r,t);let o=this.store.markCancelled(e,t);return o&&this.store.appendEvent(e,"run_cancelled",{reason:t}),o}async pause(e,t="Paused by user."){let r=this.store.get(e);return!r||le(r.status)||r.status==="paused"?r:(await this.options.pause?.(r,t),this.store.markPaused(e,t))}async resume(e,t="Resumed by user."){let r=this.store.get(e);return!r||r.status!=="paused"?r:(await this.options.resume?.(r,t),this.store.markResumed(e,t))}complete(e,t,r={}){let o=this.store.markCompleted(e,{status:t,...r.reason?{statusReason:r.reason}:{},...r.exitCode!==void 0?{exitCode:r.exitCode}:{},...r.usage?{usage:r.usage}:{}});return o&&this.store.appendEvent(e,`run_${t}`,{...r.reason?{reason:r.reason}:{}}),o}};var _=require("node:crypto"),A=1;function je(n,e){if(!n)return!1;let t=Buffer.from(n),r=Buffer.from(e);return t.length===r.length&&(0,_.timingSafeEqual)(t,r)}var q=class{constructor(e={}){this.options=e}options;handlers=new Map;register(e,t){let r=e.trim();if(!r)throw new Error("Daemon method name cannot be empty.");if(this.handlers.has(r))throw new Error(`Daemon method already registered: ${r}`);return this.handlers.set(r,t),this}registerController(e){return this.register("runs.start",t=>e.start(t)).register("runs.get",t=>e.get(t.runId)).register("runs.list",t=>e.list(t??{})).register("runs.events",t=>{let r=t;return e.events(r.runId,r.limit)}).register("runs.stop",t=>{let r=t;return e.stop(r.runId,r.reason)}).register("runs.pause",t=>{let r=t;return e.pause(r.runId,r.reason)}).register("runs.resume",t=>{let r=t;return e.resume(r.runId,r.reason)})}async handle(e){if(e.protocolVersion!==A)return this.error(e.id,"PROTOCOL_MISMATCH",`Unsupported protocol version: ${e.protocolVersion}`);if(this.options.authToken&&!je(e.authToken,this.options.authToken))return this.error(e.id,"UNAUTHORIZED","Daemon authentication failed.");let t=this.handlers.get(e.method);if(!t)return this.error(e.id,"METHOD_NOT_FOUND",`Unknown daemon method: ${e.method}`);try{return{protocolVersion:A,id:e.id,result:await t(e.params,e)}}catch(r){return this.error(e.id,"INTERNAL_ERROR",r instanceof Error?r.message:String(r))}}error(e,t,r){return{protocolVersion:A,id:e,error:{code:t,message:r}}}},H=class{constructor(e,t={}){this.transport=e;this.options=t}transport;options;async request(e,t){let r={protocolVersion:A,id:`request_${(0,_.randomUUID)()}`,method:e,params:t,...this.options.authToken?{authToken:this.options.authToken}:{}},o=await this.transport(r);if(o.protocolVersion!==A||o.id!==r.id)throw new Error("Invalid daemon response identity.");if("error"in o){let i=new Error(o.error.message);throw i.code=o.error.code,i}return o.result}};var B=require("node:crypto"),c=require("node:fs"),ge=require("node:os"),g=require("node:path");function C(n){return(0,g.basename)(n).replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,96)}function z(n){try{return JSON.parse((0,c.readFileSync)(n,"utf8"))}catch{return null}}function pe(n,e){(0,c.mkdirSync)((0,g.dirname)(n),{recursive:!0});let t=`${n}.${process.pid}.${Date.now()}.tmp`;(0,c.writeFileSync)(t,`${JSON.stringify(e,null,2)}
5
- `,"utf8"),(0,c.renameSync)(t,n)}var y=class{plan(e){if(e.schemaVersion!==1)throw new Error("Unsupported workflow schema version.");if(!e.id.trim()||!e.name.trim())throw new Error("Workflow id and name are required.");let t=new Map;for(let s of e.nodes){if(!s.id.trim())throw new Error("Workflow node id cannot be empty.");if(t.has(s.id))throw new Error(`Duplicate workflow node: ${s.id}`);t.set(s.id,s)}for(let s of e.nodes)for(let a of s.dependsOn??[]){if(!t.has(a))throw new Error(`Workflow node ${s.id} depends on unknown node ${a}.`);if(a===s.id)throw new Error(`Workflow node ${s.id} cannot depend on itself.`)}let r=new Set(t.keys()),o=new Set,i=[];for(;r.size>0;){let s=[...r].filter(a=>(t.get(a)?.dependsOn??[]).every(f=>o.has(f))).sort();if(s.length===0)throw new Error("Workflow dependency graph contains a cycle.");i.push(s);for(let a of s)r.delete(a),o.add(a)}return{workflowId:e.id,waves:i}}},U=class{constructor(e=(0,g.join)(process.env.XENO_AGENT_HOME??(0,g.join)((0,ge.homedir)(),".xeno-agent"),"workflows")){this.rootDir=e;(0,c.mkdirSync)(this.definitionsDir(),{recursive:!0}),(0,c.mkdirSync)(this.runsDir(),{recursive:!0})}rootDir;saveDefinition(e){return new y().plan(e),pe((0,g.join)(this.definitionsDir(),`${C(e.id)}.json`),e),e}getDefinition(e){return z((0,g.join)(this.definitionsDir(),`${C(e)}.json`))}listDefinitions(){return(0,c.readdirSync)(this.definitionsDir(),{withFileTypes:!0}).filter(e=>e.isFile()&&e.name.endsWith(".json")).map(e=>z((0,g.join)(this.definitionsDir(),e.name))).filter(e=>e!==null)}createRun(e){new y().plan(e);let t=new Date().toISOString(),r={schemaVersion:1,runId:`workflow_run_${(0,B.randomUUID)()}`,workflowId:e.id,status:"queued",createdAt:t,updatedAt:t,nodes:Object.fromEntries(e.nodes.map(o=>[o.id,{status:"pending"}]))};return this.writeRun(r),this.appendEvent(r.runId,"workflow_created",{}),r}getRun(e){return z(this.runPath(e))}updateRun(e,t){let r=this.getRun(e);if(!r)throw new Error(`Workflow run not found: ${e}`);let o=t(r);return o.updatedAt=new Date().toISOString(),this.writeRun(o),o}appendEvent(e,t,r,o){let i={schemaVersion:1,eventId:`workflow_event_${(0,B.randomUUID)()}`,runId:e,type:t,timestamp:new Date().toISOString(),...o?{nodeId:o}:{},payload:r},s=this.eventsPath(e);return(0,c.mkdirSync)((0,g.dirname)(s),{recursive:!0}),(0,c.appendFileSync)(s,`${JSON.stringify(i)}
6
- `,"utf8"),i}readEvents(e){let t=this.eventsPath(e);return(0,c.existsSync)(t)?(0,c.readFileSync)(t,"utf8").split(/\r?\n/).filter(Boolean).flatMap(r=>{try{return[JSON.parse(r)]}catch{return[]}}):[]}writeRun(e){pe(this.runPath(e.runId),e)}definitionsDir(){return(0,g.join)(this.rootDir,"definitions")}runsDir(){return(0,g.join)(this.rootDir,"runs")}runPath(e){return(0,g.join)(this.runsDir(),C(e),"run.json")}eventsPath(e){return(0,g.join)(this.runsDir(),C(e),"events.jsonl")}},G=class{constructor(e=new U,t=new y){this.store=e;this.planner=t}store;planner;async run(e,t){let r=this.planner.plan(e),o=this.store.createRun(e);o=this.store.updateRun(o.runId,a=>({...a,status:"running"})),this.store.appendEvent(o.runId,"workflow_started",{waves:r.waves.length});let i=Math.max(1,Math.trunc(e.maxConcurrency??4)),s=!1;for(let a of r.waves)for(let f=0;f<a.length;f+=i){let N=a.slice(f,f+i);await Promise.all(N.map(async m=>{let P=e.nodes.find(l=>l.id===m);if((P.dependsOn??[]).some(l=>this.store.getRun(o.runId)?.nodes[l]?.status!=="completed")||s&&e.failFast!==!1){this.store.updateRun(o.runId,l=>({...l,nodes:{...l.nodes,[m]:{status:"skipped",completedAt:new Date().toISOString()}}})),this.store.appendEvent(o.runId,"node_skipped",{},m);return}let V=new Date().toISOString();o=this.store.updateRun(o.runId,l=>({...l,nodes:{...l.nodes,[m]:{status:"running",startedAt:V}}})),this.store.appendEvent(o.runId,"node_started",{},m);try{let l=await t(P,{run:o,definition:e});this.store.updateRun(o.runId,S=>({...S,nodes:{...S.nodes,[m]:{status:"completed",startedAt:V,completedAt:new Date().toISOString(),output:l}}})),this.store.appendEvent(o.runId,"node_completed",{},m)}catch(l){s=!0;let S=l instanceof Error?l.message:String(l);this.store.updateRun(o.runId,ee=>({...ee,nodes:{...ee.nodes,[m]:{status:"failed",startedAt:V,completedAt:new Date().toISOString(),error:S}}})),this.store.appendEvent(o.runId,"node_failed",{error:S},m)}}))}return o=this.store.updateRun(o.runId,a=>({...a,status:s?"failed":"completed",completedAt:new Date().toISOString()})),this.store.appendEvent(o.runId,s?"workflow_failed":"workflow_completed",{}),o}};var me=require("node:crypto"),Q=class{constructor(e=1e4){this.maxEvents=e;if(!Number.isInteger(e)||e<1)throw new Error("maxEvents must be a positive integer.")}maxEvents;sources=new Map;events=[];register(e){if(!e.id.trim())throw new Error("Monitor source id cannot be empty.");if(this.sources.has(e.id))throw new Error(`Monitor source already registered: ${e.id}`);return this.sources.set(e.id,{source:e,running:!1}),this}async start(e,t=1e3){let r=this.require(e);if(r.running)return this.snapshot(e);await r.source.start?.(),r.running=!0,await this.poll(e);let o=Math.max(25,Math.trunc(t));return r.timer=setInterval(()=>{this.poll(e).catch(()=>{})},o),r.timer.unref?.(),this.snapshot(e)}async poll(e){let o=(await this.require(e).source.poll()).map(i=>({schemaVersion:1,eventId:`monitor_event_${(0,me.randomUUID)()}`,sourceId:e,type:i.type,timestamp:i.timestamp??new Date().toISOString(),payload:i.payload}));return this.events.push(...o),this.events.length>this.maxEvents&&this.events.splice(0,this.events.length-this.maxEvents),o}async stop(e){let t=this.require(e);return t.timer&&clearInterval(t.timer),t.timer=void 0,t.running&&await t.source.stop?.(),t.running=!1,this.snapshot(e)}async stopAll(){await Promise.all([...this.sources.keys()].map(e=>this.stop(e)))}snapshot(e,t=100){let r=this.require(e);return{sourceId:e,running:r.running,events:this.events.filter(o=>o.sourceId===e).slice(-Math.max(0,Math.trunc(t)))}}list(){return[...this.sources].map(([e,t])=>({sourceId:e,running:t.running}))}require(e){let t=this.sources.get(e);if(!t)throw new Error(`Monitor source not found: ${e}`);return t}},X=class{constructor(e){this.manager=e}manager;execute(e){return this.manager.start(e.sourceId,e.intervalMs)}},Z=class{constructor(e){this.manager=e}manager;execute(e){return this.manager.stop(e.sourceId)}};var fe=require("node:crypto"),v=require("node:fs"),he=require("node:os"),T=require("node:path");function w(n){return Number.isFinite(n)?Math.max(0,n??0):0}var M=class{totalsValue={inputTokens:0,outputTokens:0,totalTokens:0,cachedInputTokens:0,estimatedCostUsd:0,events:0};add(e){let t=w(e.inputTokens),r=w(e.outputTokens);return this.totalsValue.inputTokens+=t,this.totalsValue.outputTokens+=r,this.totalsValue.totalTokens+=t+r,this.totalsValue.cachedInputTokens+=w(e.cachedInputTokens),this.totalsValue.estimatedCostUsd+=w(e.estimatedCostUsd),this.totalsValue.events+=1,this}snapshot(){return{...this.totalsValue}}};function Je(n,e){if(["runId","sessionId","workflowRunId","agentId","provider","model"].some(o=>e[o]!==void 0&&n[o]!==e[o]))return!1;let r=Date.parse(n.timestamp);return!(e.from&&r<Date.parse(e.from)||e.to&&r>Date.parse(e.to))}var K=class{path;constructor(e=(0,T.join)(process.env.XENO_AGENT_HOME??(0,T.join)((0,he.homedir)(),".xeno-agent"),"usage","events.jsonl")){this.path=e,(0,v.mkdirSync)((0,T.dirname)(e),{recursive:!0})}append(e){let t={...e,schemaVersion:1,eventId:`usage_${(0,fe.randomUUID)()}`,timestamp:e.timestamp??new Date().toISOString(),inputTokens:w(e.inputTokens),outputTokens:w(e.outputTokens),...e.cachedInputTokens!==void 0?{cachedInputTokens:w(e.cachedInputTokens)}:{},...e.estimatedCostUsd!==void 0?{estimatedCostUsd:w(e.estimatedCostUsd)}:{}};return(0,v.appendFileSync)(this.path,`${JSON.stringify(t)}
7
- `,"utf8"),t}query(e={}){return(0,v.existsSync)(this.path)?(0,v.readFileSync)(this.path,"utf8").split(/\r?\n/).filter(Boolean).flatMap(t=>{try{let r=JSON.parse(t);return Je(r,e)?[r]:[]}catch{return[]}}):[]}summarize(e={}){let t=new M;for(let r of this.query(e))t.add(r);return t.snapshot()}},Y=class{constructor(e){this.adapter=e}adapter;export(e){for(let t of e){let r={...t.provider?{provider:t.provider}:{},...t.model?{model:t.model}:{}};this.adapter.addCounter("xeno.usage.input_tokens",t.inputTokens,r),this.adapter.addCounter("xeno.usage.output_tokens",t.outputTokens,r),t.cachedInputTokens&&this.adapter.addCounter("xeno.usage.cached_input_tokens",t.cachedInputTokens,r),t.estimatedCostUsd&&this.adapter.addCounter("xeno.usage.estimated_cost_usd",t.estimatedCostUsd,r),this.adapter.recordEvent?.("xeno.usage.recorded",r)}}};0&&(module.exports={AGENT_DAEMON_PROTOCOL_VERSION,AgentDaemonClient,AgentDaemonServer,AgentEventStore,AgentRunController,AgentRunStore,MonitorManager,MonitorStopTool,MonitorTool,OtelExporter,UsageAccumulator,UsageLedger,WorkflowPlanner,WorkflowRuntime,WorkflowStore,acquireControlPlaneLock,createAgentRunId,getAgentRunDir,getAgentRunStoreDir});
1
+ "use strict";var L=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var ve=Object.prototype.hasOwnProperty;var ke=(n,e)=>{for(var t in e)L(n,t,{get:e[t],enumerable:!0})},Ae=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of we(e))!ve.call(n,o)&&o!==t&&L(n,o,{get:()=>e[o],enumerable:!(r=Re(e,o))||r.enumerable});return n};var ye=n=>Ae(L({},"__esModule",{value:!0}),n);var Je={};ke(Je,{AGENT_DAEMON_PROTOCOL_VERSION:()=>S,AgentDaemonClient:()=>G,AgentDaemonServer:()=>B,AgentEventStore:()=>P,AgentRunController:()=>z,AgentRunStore:()=>T,MonitorManager:()=>K,MonitorStopTool:()=>ee,MonitorTool:()=>Y,OtelExporter:()=>re,UsageAccumulator:()=>N,UsageLedger:()=>te,WorkflowPlanner:()=>E,WorkflowRuntime:()=>Z,WorkflowStore:()=>M,acquireControlPlaneLock:()=>I,createAgentRunId:()=>pe,getAgentRunDir:()=>Le,getAgentRunStoreDir:()=>$e});module.exports=ye(Je);var le=require("node:crypto"),d=require("node:fs"),u=require("node:path");var x="0.9.10";var h=require("node:fs"),F=require("node:os"),se=require("node:path");function Se(){return new Date().toISOString()}function Ee(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function ie(n){try{return JSON.parse((0,h.readFileSync)(n,"utf8"))}catch{return null}}function De(n){if(!n||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function xe(n){return n.hostname!==(0,F.hostname)()?!0:De(n.pid)}function oe(n,e){(0,h.mkdirSync)((0,se.dirname)(n),{recursive:!0}),(0,h.writeFileSync)(n,JSON.stringify(e,null,2)+`
2
+ `,{encoding:"utf8",flag:"wx"})}function Ie(n,e){let t=ie(n);t?.pid!==e.pid||t.hostname!==e.hostname||(0,h.rmSync)(n,{force:!0})}function I(n,e,t){let r=Se(),o={schemaVersion:1,name:e,pid:process.pid,hostname:(0,F.hostname)(),processStartedAt:Ee(),version:t,acquiredAt:r,updatedAt:r};try{oe(n,o)}catch(i){if(i.code!=="EEXIST")throw i;let a=ie(n);if(a&&xe(a))throw new Error(`${e} is already locked by PID ${a.pid} on ${a.hostname}.`);(0,h.rmSync)(n,{force:!0}),oe(n,o)}return{record:o,release:()=>{Ie(n,o)}}}var de=require("node:crypto"),R=require("node:fs"),A=require("node:path");function ae(n){return(0,A.basename)(n).replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,96)}function ue(n){return(0,R.existsSync)(n)?(0,R.readFileSync)(n,"utf8").split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{try{return JSON.parse(e)}catch{return null}}).filter(e=>e!==null):[]}var P=class{constructor(e){this.runsDir=e;(0,R.mkdirSync)(this.runsDir,{recursive:!0})}runsDir;pathFor(e){return(0,A.join)(this.runsDir,ae(e),"events.jsonl")}append(e,t,r={},o=new Date().toISOString()){let i=this.pathFor(e);(0,R.mkdirSync)((0,A.dirname)(i),{recursive:!0});let s=I(`${i}.lock`,`events:${ae(e)}`,x);try{let a=ue(i).reduce((W,m,b)=>Math.max(W,m.sequence??b),-1)+1,f={schemaVersion:1,eventId:`event_${(0,de.randomUUID)()}`,sequence:a,runId:e,type:t,timestamp:o,payload:r};return(0,R.appendFileSync)(i,`${JSON.stringify(f)}
3
+ `,"utf8"),f}finally{s.release()}}read(e){return ue(this.pathFor(e))}tail(e,t=100){let r=Math.max(0,Math.min(1e4,Math.trunc(t)));return r===0?[]:this.read(e).slice(-r)}};var k=require("node:os");var j=require("node:path"),Ze=(0,k.platform)();var Ke=(0,k.release)(),Ye=(0,k.homedir)();function y(){let n=process.env.XENO_AGENT_HOME?.trim();return n?(0,j.resolve)(n):(0,j.resolve)((0,k.homedir)(),".xeno-agent")}var Pe=1,Te=(0,u.join)(y(),"daemon"),H=(0,u.join)(Te,"runs");function p(){return new Date().toISOString()}function be(n=new Date){return n.toISOString().replace(/[^0-9]/g,"").slice(0,14)}function J(n){return n.replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,80)}function q(n){return(0,u.resolve)(n)}function C(n){return q(n).toLowerCase()}function ce(n,e){let t=C(n),r=C(e);return t===r||t.startsWith(`${r}\\`)||t.startsWith(`${r}/`)}function Oe(n,e){return!!(C(n.cwd)===C(e)||n.git?.root&&ce(e,n.git.root)||n.git?.worktree&&ce(e,n.git.worktree))}function Ce(n){return J(Buffer.from(q(n)).toString("base64url"))}function _e(){return{input:0,output:0,total:0}}function O(n){try{return JSON.parse((0,d.readFileSync)(n,"utf8"))}catch{return null}}function Ue(n){return n instanceof Error&&/\balready locked by PID\b/.test(n.message)}function Me(n,e){(0,d.mkdirSync)((0,u.dirname)(n),{recursive:!0});let t=`${n}.${process.pid}.${Date.now()}.tmp`;(0,d.writeFileSync)(t,JSON.stringify(e,null,2)+`
4
+ `,"utf8"),(0,d.renameSync)(t,n)}function Ne(n){if(!n||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function Ve(n){return n==="completed"||n==="failed"||n==="cancelled"||n==="interrupted"}function We(n,e){return n.pinned!==e.pinned?n.pinned?-1:1:Date.parse(e.updatedAt)-Date.parse(n.updatedAt)}function $e(){return H}function Le(n){return(0,u.join)(H,n)}function pe(n=new Date){return`run_${be(n)}_${(0,le.randomUUID)().slice(0,8)}`}var T=class{constructor(e=H){this.runsDir=e;(0,d.mkdirSync)(this.runsDir,{recursive:!0}),this.eventStore=new P(this.runsDir)}runsDir;eventStore;create(e){let t=pe(),r=(0,u.join)(this.runsDir,t);(0,d.mkdirSync)(r,{recursive:!0});let o=p(),i=(0,u.join)(r,"events.jsonl"),s={schemaVersion:Pe,runId:t,sessionId:t,rootRunId:t,cwd:q(e.cwd),workspaceId:Ce(e.cwd),prompt:e.prompt,...e.title?{title:e.title}:{},status:"starting",model:e.model,...e.effort?{effort:e.effort}:{},...e.agent?{agent:e.agent}:{},...e.git?{git:e.git}:{},permissionMode:e.permissionMode,...e.cliVersion?{createdByCliVersion:e.cliVersion}:{},createdBySdkVersion:e.sdkVersion??x,createdAt:o,updatedAt:o,lastActivityAt:o,pinned:!!e.pinned,attachedClients:0,...e.cliVersion?{cliVersion:e.cliVersion}:{},...e.sdkVersion?{sdkVersion:e.sdkVersion}:{},stdoutPath:(0,u.join)(r,"stdout.log"),stderrPath:(0,u.join)(r,"stderr.log"),eventsPath:i,usage:_e(),children:[],tags:[]};return(0,d.writeFileSync)(s.stdoutPath,"","utf8"),(0,d.writeFileSync)(s.stderrPath,"","utf8"),(0,d.writeFileSync)(s.eventsPath,"","utf8"),this.write(s),this.appendEvent(t,"run_created",{cwd:s.cwd,model:s.model,...s.agent?{agent:s.agent}:{},...s.git?{git:s.git}:{},permissionMode:s.permissionMode,pinned:s.pinned}),s}get(e){let t=O(this.recordPath(e));return t?this.refreshRecordStatus(t):null}list(e={}){if(!(0,d.existsSync)(this.runsDir))return[];let t=(0,d.readdirSync)(this.runsDir,{withFileTypes:!0}).filter(r=>r.isDirectory()).map(r=>{try{return this.get(r.name)}catch(o){if(Ue(o))return O(this.recordPath(r.name));throw o}}).filter(r=>r!==null).filter(r=>e.all||!e.cwd||Oe(r,e.cwd)).filter(r=>!e.status||e.status.includes(r.status)).sort(We);return typeof e.limit=="number"&&e.limit>0?t.slice(0,e.limit):t}markSpawned(e,t,r){return this.update(e,o=>({...o,status:"running",workerPid:t,...r?{workerVersion:r}:{},startedAt:o.startedAt??p(),lastActivityAt:p()}))}markStarted(e,t){return this.update(e,r=>({...r,status:"running",workerPid:t.pid,...t.workerVersion?{workerVersion:t.workerVersion}:{},...t.model?{model:t.model}:{},...t.effort?{effort:t.effort}:{},startedAt:r.startedAt??p(),lastActivityAt:p()}))}markCompleted(e,t){return this.update(e,r=>({...r,status:t.status,...t.statusReason?{statusReason:t.statusReason}:{},exitCode:t.exitCode??null,usage:t.usage??r.usage,endedAt:p(),lastActivityAt:p()}))}markCancelled(e,t){return this.update(e,r=>({...r,status:"cancelled",statusReason:t,endedAt:p(),lastActivityAt:p()}))}markPaused(e,t="Paused by user."){let r=this.update(e,o=>({...o,status:"paused",statusReason:t,lastActivityAt:p()}));return r&&this.appendEvent(e,"run_paused",{reason:t}),r}markResumed(e,t="Resumed by user."){let r=this.update(e,o=>{let i={...o,status:"running",statusReason:t,lastActivityAt:p()};return delete i.endedAt,delete i.exitCode,i});return r&&this.appendEvent(e,"run_resumed",{reason:t}),r}setPinned(e,t){let r=this.update(e,o=>({...o,pinned:t,lastActivityAt:p()}));return r&&this.appendEvent(e,t?"run_pinned":"run_unpinned",{pinned:t}),r}appendEvent(e,t,r={}){let o=O(this.recordPath(e)),i=this.eventStore.append(e,t,r);o&&this.update(e,s=>({...s,lastActivityAt:i.timestamp}))}readEvents(e){return this.get(e)?this.eventStore.read(e):[]}delete(e){(0,d.rmSync)((0,u.join)(this.runsDir,e),{recursive:!0,force:!0})}refreshRecordStatus(e){if(Ve(e.status))return e;if(e.workerPid&&!Ne(e.workerPid)){let t={...e,status:"failed",statusReason:"Worker process is no longer running and did not record a terminal status.",endedAt:e.endedAt??p(),updatedAt:p()};return this.write(t),t}return e}update(e,t){let r=O(this.recordPath(e));if(!r)return null;let o=t(r);return o.updatedAt=p(),this.write(o),o}write(e){let t=I((0,u.join)(this.runDir(e.runId),"run.lock"),`run:${e.runId}`,x);try{Me(this.recordPath(e.runId),e)}finally{t.release()}}recordPath(e){return(0,u.join)(this.runsDir,J((0,u.basename)(e)),"run.json")}runDir(e){return(0,u.join)(this.runsDir,J((0,u.basename)(e)))}};function ge(n){return n==="completed"||n==="failed"||n==="cancelled"||n==="interrupted"}var z=class{constructor(e={}){this.options=e;this.store=e.store??new T}options;store;create(e){return this.store.create(e)}async start(e){let t=this.create(e);if(!this.options.spawn)return t;try{let r=await this.options.spawn(t),o=this.store.markSpawned(t.runId,r.pid,r.workerVersion);if(!o)throw new Error(`Run disappeared during spawn: ${t.runId}`);return this.store.appendEvent(t.runId,"run_started",{pid:r.pid}),o}catch(r){let o=r instanceof Error?r.message:String(r);throw this.store.markCompleted(t.runId,{status:"failed",statusReason:o,exitCode:null}),this.store.appendEvent(t.runId,"run_start_failed",{reason:o}),r}}get(e){return this.store.get(e)}list(e={}){return this.store.list(e)}events(e,t){let r=this.store.readEvents(e);return t===void 0?r:r.slice(-Math.max(0,Math.trunc(t)))}async stop(e,t="Stopped by user."){let r=this.store.get(e);if(!r||ge(r.status))return r;await this.options.stop?.(r,t);let o=this.store.markCancelled(e,t);return o&&this.store.appendEvent(e,"run_cancelled",{reason:t}),o}async pause(e,t="Paused by user."){let r=this.store.get(e);return!r||ge(r.status)||r.status==="paused"?r:(await this.options.pause?.(r,t),this.store.markPaused(e,t))}async resume(e,t="Resumed by user."){let r=this.store.get(e);return!r||r.status!=="paused"?r:(await this.options.resume?.(r,t),this.store.markResumed(e,t))}complete(e,t,r={}){let o=this.store.markCompleted(e,{status:t,...r.reason?{statusReason:r.reason}:{},...r.exitCode!==void 0?{exitCode:r.exitCode}:{},...r.usage?{usage:r.usage}:{}});return o&&this.store.appendEvent(e,`run_${t}`,{...r.reason?{reason:r.reason}:{}}),o}};var _=require("node:crypto"),S=1;function Fe(n,e){if(!n)return!1;let t=Buffer.from(n),r=Buffer.from(e);return t.length===r.length&&(0,_.timingSafeEqual)(t,r)}var B=class{constructor(e={}){this.options=e}options;handlers=new Map;register(e,t){let r=e.trim();if(!r)throw new Error("Daemon method name cannot be empty.");if(this.handlers.has(r))throw new Error(`Daemon method already registered: ${r}`);return this.handlers.set(r,t),this}registerController(e){return this.register("runs.start",t=>e.start(t)).register("runs.get",t=>e.get(t.runId)).register("runs.list",t=>e.list(t??{})).register("runs.events",t=>{let r=t;return e.events(r.runId,r.limit)}).register("runs.stop",t=>{let r=t;return e.stop(r.runId,r.reason)}).register("runs.pause",t=>{let r=t;return e.pause(r.runId,r.reason)}).register("runs.resume",t=>{let r=t;return e.resume(r.runId,r.reason)})}async handle(e){if(e.protocolVersion!==S)return this.error(e.id,"PROTOCOL_MISMATCH",`Unsupported protocol version: ${e.protocolVersion}`);if(this.options.authToken&&!Fe(e.authToken,this.options.authToken))return this.error(e.id,"UNAUTHORIZED","Daemon authentication failed.");let t=this.handlers.get(e.method);if(!t)return this.error(e.id,"METHOD_NOT_FOUND",`Unknown daemon method: ${e.method}`);try{return{protocolVersion:S,id:e.id,result:await t(e.params,e)}}catch(r){return this.error(e.id,"INTERNAL_ERROR",r instanceof Error?r.message:String(r))}}error(e,t,r){return{protocolVersion:S,id:e,error:{code:t,message:r}}}},G=class{constructor(e,t={}){this.transport=e;this.options=t}transport;options;async request(e,t){let r={protocolVersion:S,id:`request_${(0,_.randomUUID)()}`,method:e,params:t,...this.options.authToken?{authToken:this.options.authToken}:{}},o=await this.transport(r);if(o.protocolVersion!==S||o.id!==r.id)throw new Error("Invalid daemon response identity.");if("error"in o){let i=new Error(o.error.message);throw i.code=o.error.code,i}return o.result}};var X=require("node:crypto"),c=require("node:fs"),g=require("node:path");function U(n){return(0,g.basename)(n).replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,96)}function Q(n){try{return JSON.parse((0,c.readFileSync)(n,"utf8"))}catch{return null}}function me(n,e){(0,c.mkdirSync)((0,g.dirname)(n),{recursive:!0});let t=`${n}.${process.pid}.${Date.now()}.tmp`;(0,c.writeFileSync)(t,`${JSON.stringify(e,null,2)}
5
+ `,"utf8"),(0,c.renameSync)(t,n)}var E=class{plan(e){if(e.schemaVersion!==1)throw new Error("Unsupported workflow schema version.");if(!e.id.trim()||!e.name.trim())throw new Error("Workflow id and name are required.");let t=new Map;for(let s of e.nodes){if(!s.id.trim())throw new Error("Workflow node id cannot be empty.");if(t.has(s.id))throw new Error(`Duplicate workflow node: ${s.id}`);t.set(s.id,s)}for(let s of e.nodes)for(let a of s.dependsOn??[]){if(!t.has(a))throw new Error(`Workflow node ${s.id} depends on unknown node ${a}.`);if(a===s.id)throw new Error(`Workflow node ${s.id} cannot depend on itself.`)}let r=new Set(t.keys()),o=new Set,i=[];for(;r.size>0;){let s=[...r].filter(a=>(t.get(a)?.dependsOn??[]).every(f=>o.has(f))).sort();if(s.length===0)throw new Error("Workflow dependency graph contains a cycle.");i.push(s);for(let a of s)r.delete(a),o.add(a)}return{workflowId:e.id,waves:i}}},M=class{constructor(e=(0,g.join)(y(),"workflows")){this.rootDir=e;(0,c.mkdirSync)(this.definitionsDir(),{recursive:!0}),(0,c.mkdirSync)(this.runsDir(),{recursive:!0})}rootDir;saveDefinition(e){return new E().plan(e),me((0,g.join)(this.definitionsDir(),`${U(e.id)}.json`),e),e}getDefinition(e){return Q((0,g.join)(this.definitionsDir(),`${U(e)}.json`))}listDefinitions(){return(0,c.readdirSync)(this.definitionsDir(),{withFileTypes:!0}).filter(e=>e.isFile()&&e.name.endsWith(".json")).map(e=>Q((0,g.join)(this.definitionsDir(),e.name))).filter(e=>e!==null)}createRun(e){new E().plan(e);let t=new Date().toISOString(),r={schemaVersion:1,runId:`workflow_run_${(0,X.randomUUID)()}`,workflowId:e.id,status:"queued",createdAt:t,updatedAt:t,nodes:Object.fromEntries(e.nodes.map(o=>[o.id,{status:"pending"}]))};return this.writeRun(r),this.appendEvent(r.runId,"workflow_created",{}),r}getRun(e){return Q(this.runPath(e))}updateRun(e,t){let r=this.getRun(e);if(!r)throw new Error(`Workflow run not found: ${e}`);let o=t(r);return o.updatedAt=new Date().toISOString(),this.writeRun(o),o}appendEvent(e,t,r,o){let i={schemaVersion:1,eventId:`workflow_event_${(0,X.randomUUID)()}`,runId:e,type:t,timestamp:new Date().toISOString(),...o?{nodeId:o}:{},payload:r},s=this.eventsPath(e);return(0,c.mkdirSync)((0,g.dirname)(s),{recursive:!0}),(0,c.appendFileSync)(s,`${JSON.stringify(i)}
6
+ `,"utf8"),i}readEvents(e){let t=this.eventsPath(e);return(0,c.existsSync)(t)?(0,c.readFileSync)(t,"utf8").split(/\r?\n/).filter(Boolean).flatMap(r=>{try{return[JSON.parse(r)]}catch{return[]}}):[]}writeRun(e){me(this.runPath(e.runId),e)}definitionsDir(){return(0,g.join)(this.rootDir,"definitions")}runsDir(){return(0,g.join)(this.rootDir,"runs")}runPath(e){return(0,g.join)(this.runsDir(),U(e),"run.json")}eventsPath(e){return(0,g.join)(this.runsDir(),U(e),"events.jsonl")}},Z=class{constructor(e=new M,t=new E){this.store=e;this.planner=t}store;planner;async run(e,t){let r=this.planner.plan(e),o=this.store.createRun(e);o=this.store.updateRun(o.runId,a=>({...a,status:"running"})),this.store.appendEvent(o.runId,"workflow_started",{waves:r.waves.length});let i=Math.max(1,Math.trunc(e.maxConcurrency??4)),s=!1;for(let a of r.waves)for(let f=0;f<a.length;f+=i){let W=a.slice(f,f+i);await Promise.all(W.map(async m=>{let b=e.nodes.find(l=>l.id===m);if((b.dependsOn??[]).some(l=>this.store.getRun(o.runId)?.nodes[l]?.status!=="completed")||s&&e.failFast!==!1){this.store.updateRun(o.runId,l=>({...l,nodes:{...l.nodes,[m]:{status:"skipped",completedAt:new Date().toISOString()}}})),this.store.appendEvent(o.runId,"node_skipped",{},m);return}let $=new Date().toISOString();o=this.store.updateRun(o.runId,l=>({...l,nodes:{...l.nodes,[m]:{status:"running",startedAt:$}}})),this.store.appendEvent(o.runId,"node_started",{},m);try{let l=await t(b,{run:o,definition:e});this.store.updateRun(o.runId,D=>({...D,nodes:{...D.nodes,[m]:{status:"completed",startedAt:$,completedAt:new Date().toISOString(),output:l}}})),this.store.appendEvent(o.runId,"node_completed",{},m)}catch(l){s=!0;let D=l instanceof Error?l.message:String(l);this.store.updateRun(o.runId,ne=>({...ne,nodes:{...ne.nodes,[m]:{status:"failed",startedAt:$,completedAt:new Date().toISOString(),error:D}}})),this.store.appendEvent(o.runId,"node_failed",{error:D},m)}}))}return o=this.store.updateRun(o.runId,a=>({...a,status:s?"failed":"completed",completedAt:new Date().toISOString()})),this.store.appendEvent(o.runId,s?"workflow_failed":"workflow_completed",{}),o}};var fe=require("node:crypto"),K=class{constructor(e=1e4){this.maxEvents=e;if(!Number.isInteger(e)||e<1)throw new Error("maxEvents must be a positive integer.")}maxEvents;sources=new Map;events=[];register(e){if(!e.id.trim())throw new Error("Monitor source id cannot be empty.");if(this.sources.has(e.id))throw new Error(`Monitor source already registered: ${e.id}`);return this.sources.set(e.id,{source:e,running:!1}),this}async start(e,t=1e3){let r=this.require(e);if(r.running)return this.snapshot(e);await r.source.start?.(),r.running=!0,await this.poll(e);let o=Math.max(25,Math.trunc(t));return r.timer=setInterval(()=>{this.poll(e).catch(()=>{})},o),r.timer.unref?.(),this.snapshot(e)}async poll(e){let o=(await this.require(e).source.poll()).map(i=>({schemaVersion:1,eventId:`monitor_event_${(0,fe.randomUUID)()}`,sourceId:e,type:i.type,timestamp:i.timestamp??new Date().toISOString(),payload:i.payload}));return this.events.push(...o),this.events.length>this.maxEvents&&this.events.splice(0,this.events.length-this.maxEvents),o}async stop(e){let t=this.require(e);return t.timer&&clearInterval(t.timer),t.timer=void 0,t.running&&await t.source.stop?.(),t.running=!1,this.snapshot(e)}async stopAll(){await Promise.all([...this.sources.keys()].map(e=>this.stop(e)))}snapshot(e,t=100){let r=this.require(e);return{sourceId:e,running:r.running,events:this.events.filter(o=>o.sourceId===e).slice(-Math.max(0,Math.trunc(t)))}}list(){return[...this.sources].map(([e,t])=>({sourceId:e,running:t.running}))}require(e){let t=this.sources.get(e);if(!t)throw new Error(`Monitor source not found: ${e}`);return t}},Y=class{constructor(e){this.manager=e}manager;execute(e){return this.manager.start(e.sourceId,e.intervalMs)}},ee=class{constructor(e){this.manager=e}manager;execute(e){return this.manager.stop(e.sourceId)}};var he=require("node:crypto"),v=require("node:fs"),V=require("node:path");function w(n){return Number.isFinite(n)?Math.max(0,n??0):0}var N=class{totalsValue={inputTokens:0,outputTokens:0,totalTokens:0,cachedInputTokens:0,estimatedCostUsd:0,events:0};add(e){let t=w(e.inputTokens),r=w(e.outputTokens);return this.totalsValue.inputTokens+=t,this.totalsValue.outputTokens+=r,this.totalsValue.totalTokens+=t+r,this.totalsValue.cachedInputTokens+=w(e.cachedInputTokens),this.totalsValue.estimatedCostUsd+=w(e.estimatedCostUsd),this.totalsValue.events+=1,this}snapshot(){return{...this.totalsValue}}};function je(n,e){if(["runId","sessionId","workflowRunId","agentId","provider","model"].some(o=>e[o]!==void 0&&n[o]!==e[o]))return!1;let r=Date.parse(n.timestamp);return!(e.from&&r<Date.parse(e.from)||e.to&&r>Date.parse(e.to))}var te=class{path;constructor(e=(0,V.join)(y(),"usage","events.jsonl")){this.path=e,(0,v.mkdirSync)((0,V.dirname)(e),{recursive:!0})}append(e){let t={...e,schemaVersion:1,eventId:`usage_${(0,he.randomUUID)()}`,timestamp:e.timestamp??new Date().toISOString(),inputTokens:w(e.inputTokens),outputTokens:w(e.outputTokens),...e.cachedInputTokens!==void 0?{cachedInputTokens:w(e.cachedInputTokens)}:{},...e.estimatedCostUsd!==void 0?{estimatedCostUsd:w(e.estimatedCostUsd)}:{}};return(0,v.appendFileSync)(this.path,`${JSON.stringify(t)}
7
+ `,"utf8"),t}query(e={}){return(0,v.existsSync)(this.path)?(0,v.readFileSync)(this.path,"utf8").split(/\r?\n/).filter(Boolean).flatMap(t=>{try{let r=JSON.parse(t);return je(r,e)?[r]:[]}catch{return[]}}):[]}summarize(e={}){let t=new N;for(let r of this.query(e))t.add(r);return t.snapshot()}},re=class{constructor(e){this.adapter=e}adapter;export(e){for(let t of e){let r={...t.provider?{provider:t.provider}:{},...t.model?{model:t.model}:{}};this.adapter.addCounter("xeno.usage.input_tokens",t.inputTokens,r),this.adapter.addCounter("xeno.usage.output_tokens",t.outputTokens,r),t.cachedInputTokens&&this.adapter.addCounter("xeno.usage.cached_input_tokens",t.cachedInputTokens,r),t.estimatedCostUsd&&this.adapter.addCounter("xeno.usage.estimated_cost_usd",t.estimatedCostUsd,r),this.adapter.recordEvent?.("xeno.usage.recorded",r)}}};0&&(module.exports={AGENT_DAEMON_PROTOCOL_VERSION,AgentDaemonClient,AgentDaemonServer,AgentEventStore,AgentRunController,AgentRunStore,MonitorManager,MonitorStopTool,MonitorTool,OtelExporter,UsageAccumulator,UsageLedger,WorkflowPlanner,WorkflowRuntime,WorkflowStore,acquireControlPlaneLock,createAgentRunId,getAgentRunDir,getAgentRunStoreDir});
@@ -1,3 +1,20 @@
1
+ declare const AGENT_EFFORT_LEVELS: readonly [
2
+ "low",
3
+ "medium",
4
+ "high",
5
+ "xhigh",
6
+ "max"
7
+ ];
8
+ declare const AGENT_PERMISSION_MODES: readonly [
9
+ "default",
10
+ "plan",
11
+ "acceptEdits",
12
+ "auto",
13
+ "dontAsk",
14
+ "bypassPermissions"
15
+ ];
16
+ type AgentPermissionMode = (typeof AGENT_PERMISSION_MODES)[number];
17
+ type AgentEffortLevel = (typeof AGENT_EFFORT_LEVELS)[number];
1
18
  type AgentRunStatus = "queued" | "starting" | "running" | "blocked" | "waiting_for_user" | "waiting_for_tool" | "waiting_for_hook" | "waiting_for_permission" | "paused" | "completed" | "failed" | "cancelled" | "interrupted" | "detached";
2
19
  interface AgentRunUsage {
3
20
  input: number;
@@ -26,9 +43,9 @@ interface AgentRunRecord {
26
43
  statusReason?: string;
27
44
  blockedReason?: string;
28
45
  model: string;
29
- effort?: "low" | "medium" | "high" | "xhigh" | "max";
46
+ effort?: AgentEffortLevel;
30
47
  agent?: AgentRunAgentDefinitionRef;
31
- permissionMode: "default" | "plan" | "acceptEdits" | "auto" | "dontAsk" | "bypassPermissions";
48
+ permissionMode: AgentPermissionMode;
32
49
  createdByCliVersion?: string;
33
50
  createdBySdkVersion?: string;
34
51
  createdAt: string;
@@ -1,3 +1,20 @@
1
+ declare const AGENT_EFFORT_LEVELS: readonly [
2
+ "low",
3
+ "medium",
4
+ "high",
5
+ "xhigh",
6
+ "max"
7
+ ];
8
+ declare const AGENT_PERMISSION_MODES: readonly [
9
+ "default",
10
+ "plan",
11
+ "acceptEdits",
12
+ "auto",
13
+ "dontAsk",
14
+ "bypassPermissions"
15
+ ];
16
+ type AgentPermissionMode = (typeof AGENT_PERMISSION_MODES)[number];
17
+ type AgentEffortLevel = (typeof AGENT_EFFORT_LEVELS)[number];
1
18
  type AgentRunStatus = "queued" | "starting" | "running" | "blocked" | "waiting_for_user" | "waiting_for_tool" | "waiting_for_hook" | "waiting_for_permission" | "paused" | "completed" | "failed" | "cancelled" | "interrupted" | "detached";
2
19
  interface AgentRunUsage {
3
20
  input: number;
@@ -26,9 +43,9 @@ interface AgentRunRecord {
26
43
  statusReason?: string;
27
44
  blockedReason?: string;
28
45
  model: string;
29
- effort?: "low" | "medium" | "high" | "xhigh" | "max";
46
+ effort?: AgentEffortLevel;
30
47
  agent?: AgentRunAgentDefinitionRef;
31
- permissionMode: "default" | "plan" | "acceptEdits" | "auto" | "dontAsk" | "bypassPermissions";
48
+ permissionMode: AgentPermissionMode;
32
49
  createdByCliVersion?: string;
33
50
  createdBySdkVersion?: string;
34
51
  createdAt: string;
@@ -1,7 +1,7 @@
1
- import{randomUUID as Ee}from"node:crypto";import{existsSync as De,mkdirSync as b,readFileSync as xe,readdirSync as Ie,renameSync as Te,rmSync as Pe,writeFileSync as S}from"node:fs";import{homedir as be}from"node:os";import{basename as H,dirname as Oe,join as c,resolve as _e}from"node:path";var h="0.9.10";import{mkdirSync as ue,readFileSync as de,rmSync as $,writeFileSync as ce}from"node:fs";import{hostname as L}from"node:os";import{dirname as le}from"node:path";function pe(){return new Date().toISOString()}function ge(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function F(n){try{return JSON.parse(de(n,"utf8"))}catch{return null}}function me(n){if(!n||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function fe(n){return n.hostname!==L()?!0:me(n.pid)}function W(n,e){ue(le(n),{recursive:!0}),ce(n,JSON.stringify(e,null,2)+`
2
- `,{encoding:"utf8",flag:"wx"})}function he(n,e){let t=F(n);t?.pid!==e.pid||t.hostname!==e.hostname||$(n,{force:!0})}function k(n,e,t){let r=pe(),o={schemaVersion:1,name:e,pid:process.pid,hostname:L(),processStartedAt:ge(),version:t,acquiredAt:r,updatedAt:r};try{W(n,o)}catch(i){if(i.code!=="EEXIST")throw i;let a=F(n);if(a&&fe(a))throw new Error(`${e} is already locked by PID ${a.pid} on ${a.hostname}.`);$(n,{force:!0}),W(n,o)}return{record:o,release:()=>{he(n,o)}}}import{randomUUID as Re}from"node:crypto";import{appendFileSync as we,existsSync as ve,mkdirSync as j,readFileSync as ke}from"node:fs";import{basename as Ae,dirname as ye,join as Se}from"node:path";function J(n){return Ae(n).replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,96)}function q(n){return ve(n)?ke(n,"utf8").split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{try{return JSON.parse(e)}catch{return null}}).filter(e=>e!==null):[]}var A=class{constructor(e){this.runsDir=e;j(this.runsDir,{recursive:!0})}runsDir;pathFor(e){return Se(this.runsDir,J(e),"events.jsonl")}append(e,t,r={},o=new Date().toISOString()){let i=this.pathFor(e);j(ye(i),{recursive:!0});let s=k(`${i}.lock`,`events:${J(e)}`,h);try{let a=q(i).reduce((T,l,v)=>Math.max(T,l.sequence??v),-1)+1,p={schemaVersion:1,eventId:`event_${Re()}`,sequence:a,runId:e,type:t,timestamp:o,payload:r};return we(i,`${JSON.stringify(p)}
3
- `,"utf8"),p}finally{s.release()}}read(e){return q(this.pathFor(e))}tail(e,t=100){let r=Math.max(0,Math.min(1e4,Math.trunc(t)));return r===0?[]:this.read(e).slice(-r)}};var Ce=1,Ue=c(be(),".xeno-agent"),Me=c(process.env.XENO_AGENT_HOME??Ue,"daemon"),_=c(Me,"runs");function d(){return new Date().toISOString()}function Ne(n=new Date){return n.toISOString().replace(/[^0-9]/g,"").slice(0,14)}function O(n){return n.replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,80)}function C(n){return _e(n)}function E(n){return C(n).toLowerCase()}function z(n,e){let t=E(n),r=E(e);return t===r||t.startsWith(`${r}\\`)||t.startsWith(`${r}/`)}function Ve(n,e){return!!(E(n.cwd)===E(e)||n.git?.root&&z(e,n.git.root)||n.git?.worktree&&z(e,n.git.worktree))}function We(n){return O(Buffer.from(C(n)).toString("base64url"))}function $e(){return{input:0,output:0,total:0}}function y(n){try{return JSON.parse(xe(n,"utf8"))}catch{return null}}function Le(n){return n instanceof Error&&/\balready locked by PID\b/.test(n.message)}function Fe(n,e){b(Oe(n),{recursive:!0});let t=`${n}.${process.pid}.${Date.now()}.tmp`;S(t,JSON.stringify(e,null,2)+`
4
- `,"utf8"),Te(t,n)}function je(n){if(!n||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function Je(n){return n==="completed"||n==="failed"||n==="cancelled"||n==="interrupted"}function qe(n,e){return n.pinned!==e.pinned?n.pinned?-1:1:Date.parse(e.updatedAt)-Date.parse(n.updatedAt)}function bt(){return _}function Ot(n){return c(_,n)}function He(n=new Date){return`run_${Ne(n)}_${Ee().slice(0,8)}`}var D=class{constructor(e=_){this.runsDir=e;b(this.runsDir,{recursive:!0}),this.eventStore=new A(this.runsDir)}runsDir;eventStore;create(e){let t=He(),r=c(this.runsDir,t);b(r,{recursive:!0});let o=d(),i=c(r,"events.jsonl"),s={schemaVersion:Ce,runId:t,sessionId:t,rootRunId:t,cwd:C(e.cwd),workspaceId:We(e.cwd),prompt:e.prompt,...e.title?{title:e.title}:{},status:"starting",model:e.model,...e.effort?{effort:e.effort}:{},...e.agent?{agent:e.agent}:{},...e.git?{git:e.git}:{},permissionMode:e.permissionMode,...e.cliVersion?{createdByCliVersion:e.cliVersion}:{},createdBySdkVersion:e.sdkVersion??h,createdAt:o,updatedAt:o,lastActivityAt:o,pinned:!!e.pinned,attachedClients:0,...e.cliVersion?{cliVersion:e.cliVersion}:{},...e.sdkVersion?{sdkVersion:e.sdkVersion}:{},stdoutPath:c(r,"stdout.log"),stderrPath:c(r,"stderr.log"),eventsPath:i,usage:$e(),children:[],tags:[]};return S(s.stdoutPath,"","utf8"),S(s.stderrPath,"","utf8"),S(s.eventsPath,"","utf8"),this.write(s),this.appendEvent(t,"run_created",{cwd:s.cwd,model:s.model,...s.agent?{agent:s.agent}:{},...s.git?{git:s.git}:{},permissionMode:s.permissionMode,pinned:s.pinned}),s}get(e){let t=y(this.recordPath(e));return t?this.refreshRecordStatus(t):null}list(e={}){if(!De(this.runsDir))return[];let t=Ie(this.runsDir,{withFileTypes:!0}).filter(r=>r.isDirectory()).map(r=>{try{return this.get(r.name)}catch(o){if(Le(o))return y(this.recordPath(r.name));throw o}}).filter(r=>r!==null).filter(r=>e.all||!e.cwd||Ve(r,e.cwd)).filter(r=>!e.status||e.status.includes(r.status)).sort(qe);return typeof e.limit=="number"&&e.limit>0?t.slice(0,e.limit):t}markSpawned(e,t,r){return this.update(e,o=>({...o,status:"running",workerPid:t,...r?{workerVersion:r}:{},startedAt:o.startedAt??d(),lastActivityAt:d()}))}markStarted(e,t){return this.update(e,r=>({...r,status:"running",workerPid:t.pid,...t.workerVersion?{workerVersion:t.workerVersion}:{},...t.model?{model:t.model}:{},...t.effort?{effort:t.effort}:{},startedAt:r.startedAt??d(),lastActivityAt:d()}))}markCompleted(e,t){return this.update(e,r=>({...r,status:t.status,...t.statusReason?{statusReason:t.statusReason}:{},exitCode:t.exitCode??null,usage:t.usage??r.usage,endedAt:d(),lastActivityAt:d()}))}markCancelled(e,t){return this.update(e,r=>({...r,status:"cancelled",statusReason:t,endedAt:d(),lastActivityAt:d()}))}markPaused(e,t="Paused by user."){let r=this.update(e,o=>({...o,status:"paused",statusReason:t,lastActivityAt:d()}));return r&&this.appendEvent(e,"run_paused",{reason:t}),r}markResumed(e,t="Resumed by user."){let r=this.update(e,o=>{let i={...o,status:"running",statusReason:t,lastActivityAt:d()};return delete i.endedAt,delete i.exitCode,i});return r&&this.appendEvent(e,"run_resumed",{reason:t}),r}setPinned(e,t){let r=this.update(e,o=>({...o,pinned:t,lastActivityAt:d()}));return r&&this.appendEvent(e,t?"run_pinned":"run_unpinned",{pinned:t}),r}appendEvent(e,t,r={}){let o=y(this.recordPath(e)),i=this.eventStore.append(e,t,r);o&&this.update(e,s=>({...s,lastActivityAt:i.timestamp}))}readEvents(e){return this.get(e)?this.eventStore.read(e):[]}delete(e){Pe(c(this.runsDir,e),{recursive:!0,force:!0})}refreshRecordStatus(e){if(Je(e.status))return e;if(e.workerPid&&!je(e.workerPid)){let t={...e,status:"failed",statusReason:"Worker process is no longer running and did not record a terminal status.",endedAt:e.endedAt??d(),updatedAt:d()};return this.write(t),t}return e}update(e,t){let r=y(this.recordPath(e));if(!r)return null;let o=t(r);return o.updatedAt=d(),this.write(o),o}write(e){let t=k(c(this.runDir(e.runId),"run.lock"),`run:${e.runId}`,h);try{Fe(this.recordPath(e.runId),e)}finally{t.release()}}recordPath(e){return c(this.runsDir,O(H(e)),"run.json")}runDir(e){return c(this.runsDir,O(H(e)))}};function B(n){return n==="completed"||n==="failed"||n==="cancelled"||n==="interrupted"}var G=class{constructor(e={}){this.options=e;this.store=e.store??new D}options;store;create(e){return this.store.create(e)}async start(e){let t=this.create(e);if(!this.options.spawn)return t;try{let r=await this.options.spawn(t),o=this.store.markSpawned(t.runId,r.pid,r.workerVersion);if(!o)throw new Error(`Run disappeared during spawn: ${t.runId}`);return this.store.appendEvent(t.runId,"run_started",{pid:r.pid}),o}catch(r){let o=r instanceof Error?r.message:String(r);throw this.store.markCompleted(t.runId,{status:"failed",statusReason:o,exitCode:null}),this.store.appendEvent(t.runId,"run_start_failed",{reason:o}),r}}get(e){return this.store.get(e)}list(e={}){return this.store.list(e)}events(e,t){let r=this.store.readEvents(e);return t===void 0?r:r.slice(-Math.max(0,Math.trunc(t)))}async stop(e,t="Stopped by user."){let r=this.store.get(e);if(!r||B(r.status))return r;await this.options.stop?.(r,t);let o=this.store.markCancelled(e,t);return o&&this.store.appendEvent(e,"run_cancelled",{reason:t}),o}async pause(e,t="Paused by user."){let r=this.store.get(e);return!r||B(r.status)||r.status==="paused"?r:(await this.options.pause?.(r,t),this.store.markPaused(e,t))}async resume(e,t="Resumed by user."){let r=this.store.get(e);return!r||r.status!=="paused"?r:(await this.options.resume?.(r,t),this.store.markResumed(e,t))}complete(e,t,r={}){let o=this.store.markCompleted(e,{status:t,...r.reason?{statusReason:r.reason}:{},...r.exitCode!==void 0?{exitCode:r.exitCode}:{},...r.usage?{usage:r.usage}:{}});return o&&this.store.appendEvent(e,`run_${t}`,{...r.reason?{reason:r.reason}:{}}),o}};import{randomUUID as ze,timingSafeEqual as Be}from"node:crypto";var R=1;function Ge(n,e){if(!n)return!1;let t=Buffer.from(n),r=Buffer.from(e);return t.length===r.length&&Be(t,r)}var Q=class{constructor(e={}){this.options=e}options;handlers=new Map;register(e,t){let r=e.trim();if(!r)throw new Error("Daemon method name cannot be empty.");if(this.handlers.has(r))throw new Error(`Daemon method already registered: ${r}`);return this.handlers.set(r,t),this}registerController(e){return this.register("runs.start",t=>e.start(t)).register("runs.get",t=>e.get(t.runId)).register("runs.list",t=>e.list(t??{})).register("runs.events",t=>{let r=t;return e.events(r.runId,r.limit)}).register("runs.stop",t=>{let r=t;return e.stop(r.runId,r.reason)}).register("runs.pause",t=>{let r=t;return e.pause(r.runId,r.reason)}).register("runs.resume",t=>{let r=t;return e.resume(r.runId,r.reason)})}async handle(e){if(e.protocolVersion!==R)return this.error(e.id,"PROTOCOL_MISMATCH",`Unsupported protocol version: ${e.protocolVersion}`);if(this.options.authToken&&!Ge(e.authToken,this.options.authToken))return this.error(e.id,"UNAUTHORIZED","Daemon authentication failed.");let t=this.handlers.get(e.method);if(!t)return this.error(e.id,"METHOD_NOT_FOUND",`Unknown daemon method: ${e.method}`);try{return{protocolVersion:R,id:e.id,result:await t(e.params,e)}}catch(r){return this.error(e.id,"INTERNAL_ERROR",r instanceof Error?r.message:String(r))}}error(e,t,r){return{protocolVersion:R,id:e,error:{code:t,message:r}}}},X=class{constructor(e,t={}){this.transport=e;this.options=t}transport;options;async request(e,t){let r={protocolVersion:R,id:`request_${ze()}`,method:e,params:t,...this.options.authToken?{authToken:this.options.authToken}:{}},o=await this.transport(r);if(o.protocolVersion!==R||o.id!==r.id)throw new Error("Invalid daemon response identity.");if("error"in o){let i=new Error(o.error.message);throw i.code=o.error.code,i}return o.result}};import{randomUUID as Z}from"node:crypto";import{appendFileSync as Qe,existsSync as Xe,mkdirSync as I,readFileSync as ee,readdirSync as Ze,renameSync as Ke,writeFileSync as Ye}from"node:fs";import{homedir as et}from"node:os";import{basename as tt,dirname as te,join as g}from"node:path";function x(n){return tt(n).replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,96)}function U(n){try{return JSON.parse(ee(n,"utf8"))}catch{return null}}function K(n,e){I(te(n),{recursive:!0});let t=`${n}.${process.pid}.${Date.now()}.tmp`;Ye(t,`${JSON.stringify(e,null,2)}
5
- `,"utf8"),Ke(t,n)}var w=class{plan(e){if(e.schemaVersion!==1)throw new Error("Unsupported workflow schema version.");if(!e.id.trim()||!e.name.trim())throw new Error("Workflow id and name are required.");let t=new Map;for(let s of e.nodes){if(!s.id.trim())throw new Error("Workflow node id cannot be empty.");if(t.has(s.id))throw new Error(`Duplicate workflow node: ${s.id}`);t.set(s.id,s)}for(let s of e.nodes)for(let a of s.dependsOn??[]){if(!t.has(a))throw new Error(`Workflow node ${s.id} depends on unknown node ${a}.`);if(a===s.id)throw new Error(`Workflow node ${s.id} cannot depend on itself.`)}let r=new Set(t.keys()),o=new Set,i=[];for(;r.size>0;){let s=[...r].filter(a=>(t.get(a)?.dependsOn??[]).every(p=>o.has(p))).sort();if(s.length===0)throw new Error("Workflow dependency graph contains a cycle.");i.push(s);for(let a of s)r.delete(a),o.add(a)}return{workflowId:e.id,waves:i}}},M=class{constructor(e=g(process.env.XENO_AGENT_HOME??g(et(),".xeno-agent"),"workflows")){this.rootDir=e;I(this.definitionsDir(),{recursive:!0}),I(this.runsDir(),{recursive:!0})}rootDir;saveDefinition(e){return new w().plan(e),K(g(this.definitionsDir(),`${x(e.id)}.json`),e),e}getDefinition(e){return U(g(this.definitionsDir(),`${x(e)}.json`))}listDefinitions(){return Ze(this.definitionsDir(),{withFileTypes:!0}).filter(e=>e.isFile()&&e.name.endsWith(".json")).map(e=>U(g(this.definitionsDir(),e.name))).filter(e=>e!==null)}createRun(e){new w().plan(e);let t=new Date().toISOString(),r={schemaVersion:1,runId:`workflow_run_${Z()}`,workflowId:e.id,status:"queued",createdAt:t,updatedAt:t,nodes:Object.fromEntries(e.nodes.map(o=>[o.id,{status:"pending"}]))};return this.writeRun(r),this.appendEvent(r.runId,"workflow_created",{}),r}getRun(e){return U(this.runPath(e))}updateRun(e,t){let r=this.getRun(e);if(!r)throw new Error(`Workflow run not found: ${e}`);let o=t(r);return o.updatedAt=new Date().toISOString(),this.writeRun(o),o}appendEvent(e,t,r,o){let i={schemaVersion:1,eventId:`workflow_event_${Z()}`,runId:e,type:t,timestamp:new Date().toISOString(),...o?{nodeId:o}:{},payload:r},s=this.eventsPath(e);return I(te(s),{recursive:!0}),Qe(s,`${JSON.stringify(i)}
6
- `,"utf8"),i}readEvents(e){let t=this.eventsPath(e);return Xe(t)?ee(t,"utf8").split(/\r?\n/).filter(Boolean).flatMap(r=>{try{return[JSON.parse(r)]}catch{return[]}}):[]}writeRun(e){K(this.runPath(e.runId),e)}definitionsDir(){return g(this.rootDir,"definitions")}runsDir(){return g(this.rootDir,"runs")}runPath(e){return g(this.runsDir(),x(e),"run.json")}eventsPath(e){return g(this.runsDir(),x(e),"events.jsonl")}},Y=class{constructor(e=new M,t=new w){this.store=e;this.planner=t}store;planner;async run(e,t){let r=this.planner.plan(e),o=this.store.createRun(e);o=this.store.updateRun(o.runId,a=>({...a,status:"running"})),this.store.appendEvent(o.runId,"workflow_started",{waves:r.waves.length});let i=Math.max(1,Math.trunc(e.maxConcurrency??4)),s=!1;for(let a of r.waves)for(let p=0;p<a.length;p+=i){let T=a.slice(p,p+i);await Promise.all(T.map(async l=>{let v=e.nodes.find(u=>u.id===l);if((v.dependsOn??[]).some(u=>this.store.getRun(o.runId)?.nodes[u]?.status!=="completed")||s&&e.failFast!==!1){this.store.updateRun(o.runId,u=>({...u,nodes:{...u.nodes,[l]:{status:"skipped",completedAt:new Date().toISOString()}}})),this.store.appendEvent(o.runId,"node_skipped",{},l);return}let P=new Date().toISOString();o=this.store.updateRun(o.runId,u=>({...u,nodes:{...u.nodes,[l]:{status:"running",startedAt:P}}})),this.store.appendEvent(o.runId,"node_started",{},l);try{let u=await t(v,{run:o,definition:e});this.store.updateRun(o.runId,f=>({...f,nodes:{...f.nodes,[l]:{status:"completed",startedAt:P,completedAt:new Date().toISOString(),output:u}}})),this.store.appendEvent(o.runId,"node_completed",{},l)}catch(u){s=!0;let f=u instanceof Error?u.message:String(u);this.store.updateRun(o.runId,V=>({...V,nodes:{...V.nodes,[l]:{status:"failed",startedAt:P,completedAt:new Date().toISOString(),error:f}}})),this.store.appendEvent(o.runId,"node_failed",{error:f},l)}}))}return o=this.store.updateRun(o.runId,a=>({...a,status:s?"failed":"completed",completedAt:new Date().toISOString()})),this.store.appendEvent(o.runId,s?"workflow_failed":"workflow_completed",{}),o}};import{randomUUID as rt}from"node:crypto";var re=class{constructor(e=1e4){this.maxEvents=e;if(!Number.isInteger(e)||e<1)throw new Error("maxEvents must be a positive integer.")}maxEvents;sources=new Map;events=[];register(e){if(!e.id.trim())throw new Error("Monitor source id cannot be empty.");if(this.sources.has(e.id))throw new Error(`Monitor source already registered: ${e.id}`);return this.sources.set(e.id,{source:e,running:!1}),this}async start(e,t=1e3){let r=this.require(e);if(r.running)return this.snapshot(e);await r.source.start?.(),r.running=!0,await this.poll(e);let o=Math.max(25,Math.trunc(t));return r.timer=setInterval(()=>{this.poll(e).catch(()=>{})},o),r.timer.unref?.(),this.snapshot(e)}async poll(e){let o=(await this.require(e).source.poll()).map(i=>({schemaVersion:1,eventId:`monitor_event_${rt()}`,sourceId:e,type:i.type,timestamp:i.timestamp??new Date().toISOString(),payload:i.payload}));return this.events.push(...o),this.events.length>this.maxEvents&&this.events.splice(0,this.events.length-this.maxEvents),o}async stop(e){let t=this.require(e);return t.timer&&clearInterval(t.timer),t.timer=void 0,t.running&&await t.source.stop?.(),t.running=!1,this.snapshot(e)}async stopAll(){await Promise.all([...this.sources.keys()].map(e=>this.stop(e)))}snapshot(e,t=100){let r=this.require(e);return{sourceId:e,running:r.running,events:this.events.filter(o=>o.sourceId===e).slice(-Math.max(0,Math.trunc(t)))}}list(){return[...this.sources].map(([e,t])=>({sourceId:e,running:t.running}))}require(e){let t=this.sources.get(e);if(!t)throw new Error(`Monitor source not found: ${e}`);return t}},ne=class{constructor(e){this.manager=e}manager;execute(e){return this.manager.start(e.sourceId,e.intervalMs)}},oe=class{constructor(e){this.manager=e}manager;execute(e){return this.manager.stop(e.sourceId)}};import{randomUUID as nt}from"node:crypto";import{appendFileSync as ot,existsSync as st,mkdirSync as it,readFileSync as at}from"node:fs";import{homedir as ut}from"node:os";import{dirname as dt,join as se}from"node:path";function m(n){return Number.isFinite(n)?Math.max(0,n??0):0}var N=class{totalsValue={inputTokens:0,outputTokens:0,totalTokens:0,cachedInputTokens:0,estimatedCostUsd:0,events:0};add(e){let t=m(e.inputTokens),r=m(e.outputTokens);return this.totalsValue.inputTokens+=t,this.totalsValue.outputTokens+=r,this.totalsValue.totalTokens+=t+r,this.totalsValue.cachedInputTokens+=m(e.cachedInputTokens),this.totalsValue.estimatedCostUsd+=m(e.estimatedCostUsd),this.totalsValue.events+=1,this}snapshot(){return{...this.totalsValue}}};function ct(n,e){if(["runId","sessionId","workflowRunId","agentId","provider","model"].some(o=>e[o]!==void 0&&n[o]!==e[o]))return!1;let r=Date.parse(n.timestamp);return!(e.from&&r<Date.parse(e.from)||e.to&&r>Date.parse(e.to))}var ie=class{path;constructor(e=se(process.env.XENO_AGENT_HOME??se(ut(),".xeno-agent"),"usage","events.jsonl")){this.path=e,it(dt(e),{recursive:!0})}append(e){let t={...e,schemaVersion:1,eventId:`usage_${nt()}`,timestamp:e.timestamp??new Date().toISOString(),inputTokens:m(e.inputTokens),outputTokens:m(e.outputTokens),...e.cachedInputTokens!==void 0?{cachedInputTokens:m(e.cachedInputTokens)}:{},...e.estimatedCostUsd!==void 0?{estimatedCostUsd:m(e.estimatedCostUsd)}:{}};return ot(this.path,`${JSON.stringify(t)}
7
- `,"utf8"),t}query(e={}){return st(this.path)?at(this.path,"utf8").split(/\r?\n/).filter(Boolean).flatMap(t=>{try{let r=JSON.parse(t);return ct(r,e)?[r]:[]}catch{return[]}}):[]}summarize(e={}){let t=new N;for(let r of this.query(e))t.add(r);return t.snapshot()}},ae=class{constructor(e){this.adapter=e}adapter;export(e){for(let t of e){let r={...t.provider?{provider:t.provider}:{},...t.model?{model:t.model}:{}};this.adapter.addCounter("xeno.usage.input_tokens",t.inputTokens,r),this.adapter.addCounter("xeno.usage.output_tokens",t.outputTokens,r),t.cachedInputTokens&&this.adapter.addCounter("xeno.usage.cached_input_tokens",t.cachedInputTokens,r),t.estimatedCostUsd&&this.adapter.addCounter("xeno.usage.estimated_cost_usd",t.estimatedCostUsd,r),this.adapter.recordEvent?.("xeno.usage.recorded",r)}}};export{R as AGENT_DAEMON_PROTOCOL_VERSION,X as AgentDaemonClient,Q as AgentDaemonServer,A as AgentEventStore,G as AgentRunController,D as AgentRunStore,re as MonitorManager,oe as MonitorStopTool,ne as MonitorTool,ae as OtelExporter,N as UsageAccumulator,ie as UsageLedger,w as WorkflowPlanner,Y as WorkflowRuntime,M as WorkflowStore,k as acquireControlPlaneLock,He as createAgentRunId,Ot as getAgentRunDir,bt as getAgentRunStoreDir};
1
+ import{randomUUID as Pe}from"node:crypto";import{existsSync as Te,mkdirSync as O,readFileSync as be,readdirSync as Oe,renameSync as Ce,rmSync as _e,writeFileSync as E}from"node:fs";import{basename as G,dirname as Ue,join as l,resolve as Me}from"node:path";var R="0.9.10";import{mkdirSync as ce,readFileSync as le,rmSync as L,writeFileSync as pe}from"node:fs";import{hostname as F}from"node:os";import{dirname as ge}from"node:path";function me(){return new Date().toISOString()}function fe(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function j(n){try{return JSON.parse(le(n,"utf8"))}catch{return null}}function he(n){if(!n||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function Re(n){return n.hostname!==F()?!0:he(n.pid)}function $(n,e){ce(ge(n),{recursive:!0}),pe(n,JSON.stringify(e,null,2)+`
2
+ `,{encoding:"utf8",flag:"wx"})}function we(n,e){let t=j(n);t?.pid!==e.pid||t.hostname!==e.hostname||L(n,{force:!0})}function A(n,e,t){let r=me(),o={schemaVersion:1,name:e,pid:process.pid,hostname:F(),processStartedAt:fe(),version:t,acquiredAt:r,updatedAt:r};try{$(n,o)}catch(i){if(i.code!=="EEXIST")throw i;let a=j(n);if(a&&Re(a))throw new Error(`${e} is already locked by PID ${a.pid} on ${a.hostname}.`);L(n,{force:!0}),$(n,o)}return{record:o,release:()=>{we(n,o)}}}import{randomUUID as ve}from"node:crypto";import{appendFileSync as ke,existsSync as Ae,mkdirSync as J,readFileSync as ye}from"node:fs";import{basename as Se,dirname as Ee,join as De}from"node:path";function H(n){return Se(n).replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,96)}function q(n){return Ae(n)?ye(n,"utf8").split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{try{return JSON.parse(e)}catch{return null}}).filter(e=>e!==null):[]}var y=class{constructor(e){this.runsDir=e;J(this.runsDir,{recursive:!0})}runsDir;pathFor(e){return De(this.runsDir,H(e),"events.jsonl")}append(e,t,r={},o=new Date().toISOString()){let i=this.pathFor(e);J(Ee(i),{recursive:!0});let s=A(`${i}.lock`,`events:${H(e)}`,R);try{let a=q(i).reduce((T,c,k)=>Math.max(T,c.sequence??k),-1)+1,p={schemaVersion:1,eventId:`event_${ve()}`,sequence:a,runId:e,type:t,timestamp:o,payload:r};return ke(i,`${JSON.stringify(p)}
3
+ `,"utf8"),p}finally{s.release()}}read(e){return q(this.pathFor(e))}tail(e,t=100){let r=Math.max(0,Math.min(1e4,Math.trunc(t)));return r===0?[]:this.read(e).slice(-r)}};import{homedir as B,platform as xe,release as Ie}from"node:os";import{resolve as z}from"node:path";var xt=xe();var It=Ie(),Pt=B();function f(){let n=process.env.XENO_AGENT_HOME?.trim();return n?z(n):z(B(),".xeno-agent")}var Ne=1,Ve=l(f(),"daemon"),_=l(Ve,"runs");function d(){return new Date().toISOString()}function We(n=new Date){return n.toISOString().replace(/[^0-9]/g,"").slice(0,14)}function C(n){return n.replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,80)}function U(n){return Me(n)}function D(n){return U(n).toLowerCase()}function Q(n,e){let t=D(n),r=D(e);return t===r||t.startsWith(`${r}\\`)||t.startsWith(`${r}/`)}function $e(n,e){return!!(D(n.cwd)===D(e)||n.git?.root&&Q(e,n.git.root)||n.git?.worktree&&Q(e,n.git.worktree))}function Le(n){return C(Buffer.from(U(n)).toString("base64url"))}function Fe(){return{input:0,output:0,total:0}}function S(n){try{return JSON.parse(be(n,"utf8"))}catch{return null}}function je(n){return n instanceof Error&&/\balready locked by PID\b/.test(n.message)}function Je(n,e){O(Ue(n),{recursive:!0});let t=`${n}.${process.pid}.${Date.now()}.tmp`;E(t,JSON.stringify(e,null,2)+`
4
+ `,"utf8"),Ce(t,n)}function He(n){if(!n||n<=0)return!1;try{return process.kill(n,0),!0}catch{return!1}}function qe(n){return n==="completed"||n==="failed"||n==="cancelled"||n==="interrupted"}function ze(n,e){return n.pinned!==e.pinned?n.pinned?-1:1:Date.parse(e.updatedAt)-Date.parse(n.updatedAt)}function Vt(){return _}function Wt(n){return l(_,n)}function Be(n=new Date){return`run_${We(n)}_${Pe().slice(0,8)}`}var x=class{constructor(e=_){this.runsDir=e;O(this.runsDir,{recursive:!0}),this.eventStore=new y(this.runsDir)}runsDir;eventStore;create(e){let t=Be(),r=l(this.runsDir,t);O(r,{recursive:!0});let o=d(),i=l(r,"events.jsonl"),s={schemaVersion:Ne,runId:t,sessionId:t,rootRunId:t,cwd:U(e.cwd),workspaceId:Le(e.cwd),prompt:e.prompt,...e.title?{title:e.title}:{},status:"starting",model:e.model,...e.effort?{effort:e.effort}:{},...e.agent?{agent:e.agent}:{},...e.git?{git:e.git}:{},permissionMode:e.permissionMode,...e.cliVersion?{createdByCliVersion:e.cliVersion}:{},createdBySdkVersion:e.sdkVersion??R,createdAt:o,updatedAt:o,lastActivityAt:o,pinned:!!e.pinned,attachedClients:0,...e.cliVersion?{cliVersion:e.cliVersion}:{},...e.sdkVersion?{sdkVersion:e.sdkVersion}:{},stdoutPath:l(r,"stdout.log"),stderrPath:l(r,"stderr.log"),eventsPath:i,usage:Fe(),children:[],tags:[]};return E(s.stdoutPath,"","utf8"),E(s.stderrPath,"","utf8"),E(s.eventsPath,"","utf8"),this.write(s),this.appendEvent(t,"run_created",{cwd:s.cwd,model:s.model,...s.agent?{agent:s.agent}:{},...s.git?{git:s.git}:{},permissionMode:s.permissionMode,pinned:s.pinned}),s}get(e){let t=S(this.recordPath(e));return t?this.refreshRecordStatus(t):null}list(e={}){if(!Te(this.runsDir))return[];let t=Oe(this.runsDir,{withFileTypes:!0}).filter(r=>r.isDirectory()).map(r=>{try{return this.get(r.name)}catch(o){if(je(o))return S(this.recordPath(r.name));throw o}}).filter(r=>r!==null).filter(r=>e.all||!e.cwd||$e(r,e.cwd)).filter(r=>!e.status||e.status.includes(r.status)).sort(ze);return typeof e.limit=="number"&&e.limit>0?t.slice(0,e.limit):t}markSpawned(e,t,r){return this.update(e,o=>({...o,status:"running",workerPid:t,...r?{workerVersion:r}:{},startedAt:o.startedAt??d(),lastActivityAt:d()}))}markStarted(e,t){return this.update(e,r=>({...r,status:"running",workerPid:t.pid,...t.workerVersion?{workerVersion:t.workerVersion}:{},...t.model?{model:t.model}:{},...t.effort?{effort:t.effort}:{},startedAt:r.startedAt??d(),lastActivityAt:d()}))}markCompleted(e,t){return this.update(e,r=>({...r,status:t.status,...t.statusReason?{statusReason:t.statusReason}:{},exitCode:t.exitCode??null,usage:t.usage??r.usage,endedAt:d(),lastActivityAt:d()}))}markCancelled(e,t){return this.update(e,r=>({...r,status:"cancelled",statusReason:t,endedAt:d(),lastActivityAt:d()}))}markPaused(e,t="Paused by user."){let r=this.update(e,o=>({...o,status:"paused",statusReason:t,lastActivityAt:d()}));return r&&this.appendEvent(e,"run_paused",{reason:t}),r}markResumed(e,t="Resumed by user."){let r=this.update(e,o=>{let i={...o,status:"running",statusReason:t,lastActivityAt:d()};return delete i.endedAt,delete i.exitCode,i});return r&&this.appendEvent(e,"run_resumed",{reason:t}),r}setPinned(e,t){let r=this.update(e,o=>({...o,pinned:t,lastActivityAt:d()}));return r&&this.appendEvent(e,t?"run_pinned":"run_unpinned",{pinned:t}),r}appendEvent(e,t,r={}){let o=S(this.recordPath(e)),i=this.eventStore.append(e,t,r);o&&this.update(e,s=>({...s,lastActivityAt:i.timestamp}))}readEvents(e){return this.get(e)?this.eventStore.read(e):[]}delete(e){_e(l(this.runsDir,e),{recursive:!0,force:!0})}refreshRecordStatus(e){if(qe(e.status))return e;if(e.workerPid&&!He(e.workerPid)){let t={...e,status:"failed",statusReason:"Worker process is no longer running and did not record a terminal status.",endedAt:e.endedAt??d(),updatedAt:d()};return this.write(t),t}return e}update(e,t){let r=S(this.recordPath(e));if(!r)return null;let o=t(r);return o.updatedAt=d(),this.write(o),o}write(e){let t=A(l(this.runDir(e.runId),"run.lock"),`run:${e.runId}`,R);try{Je(this.recordPath(e.runId),e)}finally{t.release()}}recordPath(e){return l(this.runsDir,C(G(e)),"run.json")}runDir(e){return l(this.runsDir,C(G(e)))}};function X(n){return n==="completed"||n==="failed"||n==="cancelled"||n==="interrupted"}var Z=class{constructor(e={}){this.options=e;this.store=e.store??new x}options;store;create(e){return this.store.create(e)}async start(e){let t=this.create(e);if(!this.options.spawn)return t;try{let r=await this.options.spawn(t),o=this.store.markSpawned(t.runId,r.pid,r.workerVersion);if(!o)throw new Error(`Run disappeared during spawn: ${t.runId}`);return this.store.appendEvent(t.runId,"run_started",{pid:r.pid}),o}catch(r){let o=r instanceof Error?r.message:String(r);throw this.store.markCompleted(t.runId,{status:"failed",statusReason:o,exitCode:null}),this.store.appendEvent(t.runId,"run_start_failed",{reason:o}),r}}get(e){return this.store.get(e)}list(e={}){return this.store.list(e)}events(e,t){let r=this.store.readEvents(e);return t===void 0?r:r.slice(-Math.max(0,Math.trunc(t)))}async stop(e,t="Stopped by user."){let r=this.store.get(e);if(!r||X(r.status))return r;await this.options.stop?.(r,t);let o=this.store.markCancelled(e,t);return o&&this.store.appendEvent(e,"run_cancelled",{reason:t}),o}async pause(e,t="Paused by user."){let r=this.store.get(e);return!r||X(r.status)||r.status==="paused"?r:(await this.options.pause?.(r,t),this.store.markPaused(e,t))}async resume(e,t="Resumed by user."){let r=this.store.get(e);return!r||r.status!=="paused"?r:(await this.options.resume?.(r,t),this.store.markResumed(e,t))}complete(e,t,r={}){let o=this.store.markCompleted(e,{status:t,...r.reason?{statusReason:r.reason}:{},...r.exitCode!==void 0?{exitCode:r.exitCode}:{},...r.usage?{usage:r.usage}:{}});return o&&this.store.appendEvent(e,`run_${t}`,{...r.reason?{reason:r.reason}:{}}),o}};import{randomUUID as Ge,timingSafeEqual as Qe}from"node:crypto";var w=1;function Xe(n,e){if(!n)return!1;let t=Buffer.from(n),r=Buffer.from(e);return t.length===r.length&&Qe(t,r)}var K=class{constructor(e={}){this.options=e}options;handlers=new Map;register(e,t){let r=e.trim();if(!r)throw new Error("Daemon method name cannot be empty.");if(this.handlers.has(r))throw new Error(`Daemon method already registered: ${r}`);return this.handlers.set(r,t),this}registerController(e){return this.register("runs.start",t=>e.start(t)).register("runs.get",t=>e.get(t.runId)).register("runs.list",t=>e.list(t??{})).register("runs.events",t=>{let r=t;return e.events(r.runId,r.limit)}).register("runs.stop",t=>{let r=t;return e.stop(r.runId,r.reason)}).register("runs.pause",t=>{let r=t;return e.pause(r.runId,r.reason)}).register("runs.resume",t=>{let r=t;return e.resume(r.runId,r.reason)})}async handle(e){if(e.protocolVersion!==w)return this.error(e.id,"PROTOCOL_MISMATCH",`Unsupported protocol version: ${e.protocolVersion}`);if(this.options.authToken&&!Xe(e.authToken,this.options.authToken))return this.error(e.id,"UNAUTHORIZED","Daemon authentication failed.");let t=this.handlers.get(e.method);if(!t)return this.error(e.id,"METHOD_NOT_FOUND",`Unknown daemon method: ${e.method}`);try{return{protocolVersion:w,id:e.id,result:await t(e.params,e)}}catch(r){return this.error(e.id,"INTERNAL_ERROR",r instanceof Error?r.message:String(r))}}error(e,t,r){return{protocolVersion:w,id:e,error:{code:t,message:r}}}},Y=class{constructor(e,t={}){this.transport=e;this.options=t}transport;options;async request(e,t){let r={protocolVersion:w,id:`request_${Ge()}`,method:e,params:t,...this.options.authToken?{authToken:this.options.authToken}:{}},o=await this.transport(r);if(o.protocolVersion!==w||o.id!==r.id)throw new Error("Invalid daemon response identity.");if("error"in o){let i=new Error(o.error.message);throw i.code=o.error.code,i}return o.result}};import{randomUUID as ee}from"node:crypto";import{appendFileSync as Ze,existsSync as Ke,mkdirSync as P,readFileSync as ne,readdirSync as Ye,renameSync as et,writeFileSync as tt}from"node:fs";import{basename as rt,dirname as oe,join as g}from"node:path";function I(n){return rt(n).replace(/[^A-Za-z0-9_.-]/g,"_").slice(0,96)}function M(n){try{return JSON.parse(ne(n,"utf8"))}catch{return null}}function te(n,e){P(oe(n),{recursive:!0});let t=`${n}.${process.pid}.${Date.now()}.tmp`;tt(t,`${JSON.stringify(e,null,2)}
5
+ `,"utf8"),et(t,n)}var v=class{plan(e){if(e.schemaVersion!==1)throw new Error("Unsupported workflow schema version.");if(!e.id.trim()||!e.name.trim())throw new Error("Workflow id and name are required.");let t=new Map;for(let s of e.nodes){if(!s.id.trim())throw new Error("Workflow node id cannot be empty.");if(t.has(s.id))throw new Error(`Duplicate workflow node: ${s.id}`);t.set(s.id,s)}for(let s of e.nodes)for(let a of s.dependsOn??[]){if(!t.has(a))throw new Error(`Workflow node ${s.id} depends on unknown node ${a}.`);if(a===s.id)throw new Error(`Workflow node ${s.id} cannot depend on itself.`)}let r=new Set(t.keys()),o=new Set,i=[];for(;r.size>0;){let s=[...r].filter(a=>(t.get(a)?.dependsOn??[]).every(p=>o.has(p))).sort();if(s.length===0)throw new Error("Workflow dependency graph contains a cycle.");i.push(s);for(let a of s)r.delete(a),o.add(a)}return{workflowId:e.id,waves:i}}},N=class{constructor(e=g(f(),"workflows")){this.rootDir=e;P(this.definitionsDir(),{recursive:!0}),P(this.runsDir(),{recursive:!0})}rootDir;saveDefinition(e){return new v().plan(e),te(g(this.definitionsDir(),`${I(e.id)}.json`),e),e}getDefinition(e){return M(g(this.definitionsDir(),`${I(e)}.json`))}listDefinitions(){return Ye(this.definitionsDir(),{withFileTypes:!0}).filter(e=>e.isFile()&&e.name.endsWith(".json")).map(e=>M(g(this.definitionsDir(),e.name))).filter(e=>e!==null)}createRun(e){new v().plan(e);let t=new Date().toISOString(),r={schemaVersion:1,runId:`workflow_run_${ee()}`,workflowId:e.id,status:"queued",createdAt:t,updatedAt:t,nodes:Object.fromEntries(e.nodes.map(o=>[o.id,{status:"pending"}]))};return this.writeRun(r),this.appendEvent(r.runId,"workflow_created",{}),r}getRun(e){return M(this.runPath(e))}updateRun(e,t){let r=this.getRun(e);if(!r)throw new Error(`Workflow run not found: ${e}`);let o=t(r);return o.updatedAt=new Date().toISOString(),this.writeRun(o),o}appendEvent(e,t,r,o){let i={schemaVersion:1,eventId:`workflow_event_${ee()}`,runId:e,type:t,timestamp:new Date().toISOString(),...o?{nodeId:o}:{},payload:r},s=this.eventsPath(e);return P(oe(s),{recursive:!0}),Ze(s,`${JSON.stringify(i)}
6
+ `,"utf8"),i}readEvents(e){let t=this.eventsPath(e);return Ke(t)?ne(t,"utf8").split(/\r?\n/).filter(Boolean).flatMap(r=>{try{return[JSON.parse(r)]}catch{return[]}}):[]}writeRun(e){te(this.runPath(e.runId),e)}definitionsDir(){return g(this.rootDir,"definitions")}runsDir(){return g(this.rootDir,"runs")}runPath(e){return g(this.runsDir(),I(e),"run.json")}eventsPath(e){return g(this.runsDir(),I(e),"events.jsonl")}},re=class{constructor(e=new N,t=new v){this.store=e;this.planner=t}store;planner;async run(e,t){let r=this.planner.plan(e),o=this.store.createRun(e);o=this.store.updateRun(o.runId,a=>({...a,status:"running"})),this.store.appendEvent(o.runId,"workflow_started",{waves:r.waves.length});let i=Math.max(1,Math.trunc(e.maxConcurrency??4)),s=!1;for(let a of r.waves)for(let p=0;p<a.length;p+=i){let T=a.slice(p,p+i);await Promise.all(T.map(async c=>{let k=e.nodes.find(u=>u.id===c);if((k.dependsOn??[]).some(u=>this.store.getRun(o.runId)?.nodes[u]?.status!=="completed")||s&&e.failFast!==!1){this.store.updateRun(o.runId,u=>({...u,nodes:{...u.nodes,[c]:{status:"skipped",completedAt:new Date().toISOString()}}})),this.store.appendEvent(o.runId,"node_skipped",{},c);return}let b=new Date().toISOString();o=this.store.updateRun(o.runId,u=>({...u,nodes:{...u.nodes,[c]:{status:"running",startedAt:b}}})),this.store.appendEvent(o.runId,"node_started",{},c);try{let u=await t(k,{run:o,definition:e});this.store.updateRun(o.runId,h=>({...h,nodes:{...h.nodes,[c]:{status:"completed",startedAt:b,completedAt:new Date().toISOString(),output:u}}})),this.store.appendEvent(o.runId,"node_completed",{},c)}catch(u){s=!0;let h=u instanceof Error?u.message:String(u);this.store.updateRun(o.runId,W=>({...W,nodes:{...W.nodes,[c]:{status:"failed",startedAt:b,completedAt:new Date().toISOString(),error:h}}})),this.store.appendEvent(o.runId,"node_failed",{error:h},c)}}))}return o=this.store.updateRun(o.runId,a=>({...a,status:s?"failed":"completed",completedAt:new Date().toISOString()})),this.store.appendEvent(o.runId,s?"workflow_failed":"workflow_completed",{}),o}};import{randomUUID as nt}from"node:crypto";var se=class{constructor(e=1e4){this.maxEvents=e;if(!Number.isInteger(e)||e<1)throw new Error("maxEvents must be a positive integer.")}maxEvents;sources=new Map;events=[];register(e){if(!e.id.trim())throw new Error("Monitor source id cannot be empty.");if(this.sources.has(e.id))throw new Error(`Monitor source already registered: ${e.id}`);return this.sources.set(e.id,{source:e,running:!1}),this}async start(e,t=1e3){let r=this.require(e);if(r.running)return this.snapshot(e);await r.source.start?.(),r.running=!0,await this.poll(e);let o=Math.max(25,Math.trunc(t));return r.timer=setInterval(()=>{this.poll(e).catch(()=>{})},o),r.timer.unref?.(),this.snapshot(e)}async poll(e){let o=(await this.require(e).source.poll()).map(i=>({schemaVersion:1,eventId:`monitor_event_${nt()}`,sourceId:e,type:i.type,timestamp:i.timestamp??new Date().toISOString(),payload:i.payload}));return this.events.push(...o),this.events.length>this.maxEvents&&this.events.splice(0,this.events.length-this.maxEvents),o}async stop(e){let t=this.require(e);return t.timer&&clearInterval(t.timer),t.timer=void 0,t.running&&await t.source.stop?.(),t.running=!1,this.snapshot(e)}async stopAll(){await Promise.all([...this.sources.keys()].map(e=>this.stop(e)))}snapshot(e,t=100){let r=this.require(e);return{sourceId:e,running:r.running,events:this.events.filter(o=>o.sourceId===e).slice(-Math.max(0,Math.trunc(t)))}}list(){return[...this.sources].map(([e,t])=>({sourceId:e,running:t.running}))}require(e){let t=this.sources.get(e);if(!t)throw new Error(`Monitor source not found: ${e}`);return t}},ie=class{constructor(e){this.manager=e}manager;execute(e){return this.manager.start(e.sourceId,e.intervalMs)}},ae=class{constructor(e){this.manager=e}manager;execute(e){return this.manager.stop(e.sourceId)}};import{randomUUID as ot}from"node:crypto";import{appendFileSync as st,existsSync as it,mkdirSync as at,readFileSync as ut}from"node:fs";import{dirname as dt,join as ct}from"node:path";function m(n){return Number.isFinite(n)?Math.max(0,n??0):0}var V=class{totalsValue={inputTokens:0,outputTokens:0,totalTokens:0,cachedInputTokens:0,estimatedCostUsd:0,events:0};add(e){let t=m(e.inputTokens),r=m(e.outputTokens);return this.totalsValue.inputTokens+=t,this.totalsValue.outputTokens+=r,this.totalsValue.totalTokens+=t+r,this.totalsValue.cachedInputTokens+=m(e.cachedInputTokens),this.totalsValue.estimatedCostUsd+=m(e.estimatedCostUsd),this.totalsValue.events+=1,this}snapshot(){return{...this.totalsValue}}};function lt(n,e){if(["runId","sessionId","workflowRunId","agentId","provider","model"].some(o=>e[o]!==void 0&&n[o]!==e[o]))return!1;let r=Date.parse(n.timestamp);return!(e.from&&r<Date.parse(e.from)||e.to&&r>Date.parse(e.to))}var ue=class{path;constructor(e=ct(f(),"usage","events.jsonl")){this.path=e,at(dt(e),{recursive:!0})}append(e){let t={...e,schemaVersion:1,eventId:`usage_${ot()}`,timestamp:e.timestamp??new Date().toISOString(),inputTokens:m(e.inputTokens),outputTokens:m(e.outputTokens),...e.cachedInputTokens!==void 0?{cachedInputTokens:m(e.cachedInputTokens)}:{},...e.estimatedCostUsd!==void 0?{estimatedCostUsd:m(e.estimatedCostUsd)}:{}};return st(this.path,`${JSON.stringify(t)}
7
+ `,"utf8"),t}query(e={}){return it(this.path)?ut(this.path,"utf8").split(/\r?\n/).filter(Boolean).flatMap(t=>{try{let r=JSON.parse(t);return lt(r,e)?[r]:[]}catch{return[]}}):[]}summarize(e={}){let t=new V;for(let r of this.query(e))t.add(r);return t.snapshot()}},de=class{constructor(e){this.adapter=e}adapter;export(e){for(let t of e){let r={...t.provider?{provider:t.provider}:{},...t.model?{model:t.model}:{}};this.adapter.addCounter("xeno.usage.input_tokens",t.inputTokens,r),this.adapter.addCounter("xeno.usage.output_tokens",t.outputTokens,r),t.cachedInputTokens&&this.adapter.addCounter("xeno.usage.cached_input_tokens",t.cachedInputTokens,r),t.estimatedCostUsd&&this.adapter.addCounter("xeno.usage.estimated_cost_usd",t.estimatedCostUsd,r),this.adapter.recordEvent?.("xeno.usage.recorded",r)}}};export{w as AGENT_DAEMON_PROTOCOL_VERSION,Y as AgentDaemonClient,K as AgentDaemonServer,y as AgentEventStore,Z as AgentRunController,x as AgentRunStore,se as MonitorManager,ae as MonitorStopTool,ie as MonitorTool,de as OtelExporter,V as UsageAccumulator,ue as UsageLedger,v as WorkflowPlanner,re as WorkflowRuntime,N as WorkflowStore,A as acquireControlPlaneLock,Be as createAgentRunId,Wt as getAgentRunDir,Vt as getAgentRunStoreDir};
@@ -1 +1 @@
1
- {"inputs":{"src/control-plane/types.ts":{"bytes":2467,"imports":[],"format":"esm"},"src/version.ts":{"bytes":37,"imports":[],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2591,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/event-store.ts":{"bytes":2379,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"}],"format":"esm"},"src/control-plane/run-store.ts":{"bytes":12025,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"},{"path":"src/control-plane/event-store.ts","kind":"import-statement","original":"./event-store.js"}],"format":"esm"},"src/control-plane/controller.ts":{"bytes":4220,"imports":[{"path":"src/control-plane/run-store.ts","kind":"import-statement","original":"./run-store.js"}],"format":"esm"},"src/control-plane/daemon.ts":{"bytes":5047,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/workflow.ts":{"bytes":10410,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/monitor.ts":{"bytes":4128,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/usage.ts":{"bytes":5185,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/index.ts":{"bytes":281,"imports":[{"path":"src/control-plane/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/control-plane/run-store.ts","kind":"import-statement","original":"./run-store.js"},{"path":"src/control-plane/event-store.ts","kind":"import-statement","original":"./event-store.js"},{"path":"src/control-plane/controller.ts","kind":"import-statement","original":"./controller.js"},{"path":"src/control-plane/daemon.ts","kind":"import-statement","original":"./daemon.js"},{"path":"src/control-plane/workflow.ts","kind":"import-statement","original":"./workflow.js"},{"path":"src/control-plane/monitor.ts","kind":"import-statement","original":"./monitor.js"},{"path":"src/control-plane/usage.ts","kind":"import-statement","original":"./usage.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"}],"format":"esm"}},"outputs":{"dist/control-plane/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/control-plane/index.ts","inputs":{"src/control-plane/index.ts":{"bytesInOutput":480},"src/control-plane/run-store.ts":{"bytesInOutput":5542},"src/version.ts":{"bytesInOutput":15},"src/control-plane/lock.ts":{"bytesInOutput":1063},"src/control-plane/event-store.ts":{"bytesInOutput":1057},"src/control-plane/controller.ts":{"bytesInOutput":1689},"src/control-plane/daemon.ts":{"bytesInOutput":1935},"src/control-plane/workflow.ts":{"bytesInOutput":4890},"src/control-plane/monitor.ts":{"bytesInOutput":1816},"src/control-plane/usage.ts":{"bytesInOutput":2271}},"bytes":21538}}}
1
+ {"inputs":{"src/control-plane/types.ts":{"bytes":2578,"imports":[],"format":"esm"},"src/version.ts":{"bytes":37,"imports":[],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2591,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/event-store.ts":{"bytes":2379,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"}],"format":"esm"},"src/utils/platform.ts":{"bytes":5600,"imports":[{"path":"node:os","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/run-store.ts":{"bytes":11948,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"},{"path":"src/control-plane/event-store.ts","kind":"import-statement","original":"./event-store.js"},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"}],"format":"esm"},"src/control-plane/controller.ts":{"bytes":4220,"imports":[{"path":"src/control-plane/run-store.ts","kind":"import-statement","original":"./run-store.js"}],"format":"esm"},"src/control-plane/daemon.ts":{"bytes":5047,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/workflow.ts":{"bytes":10381,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"}],"format":"esm"},"src/control-plane/monitor.ts":{"bytes":4128,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/usage.ts":{"bytes":5156,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"}],"format":"esm"},"src/control-plane/index.ts":{"bytes":281,"imports":[{"path":"src/control-plane/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/control-plane/run-store.ts","kind":"import-statement","original":"./run-store.js"},{"path":"src/control-plane/event-store.ts","kind":"import-statement","original":"./event-store.js"},{"path":"src/control-plane/controller.ts","kind":"import-statement","original":"./controller.js"},{"path":"src/control-plane/daemon.ts","kind":"import-statement","original":"./daemon.js"},{"path":"src/control-plane/workflow.ts","kind":"import-statement","original":"./workflow.js"},{"path":"src/control-plane/monitor.ts","kind":"import-statement","original":"./monitor.js"},{"path":"src/control-plane/usage.ts","kind":"import-statement","original":"./usage.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"}],"format":"esm"}},"outputs":{"dist/control-plane/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:os","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs","kind":"require-call","external":true},{"path":"node:path","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/control-plane/index.ts","inputs":{"src/control-plane/index.ts":{"bytesInOutput":483},"src/control-plane/run-store.ts":{"bytesInOutput":5446},"src/version.ts":{"bytesInOutput":15},"src/control-plane/lock.ts":{"bytesInOutput":1063},"src/control-plane/event-store.ts":{"bytesInOutput":1057},"src/utils/platform.ts":{"bytesInOutput":240},"src/control-plane/controller.ts":{"bytesInOutput":1689},"src/control-plane/daemon.ts":{"bytesInOutput":1935},"src/control-plane/workflow.ts":{"bytesInOutput":4800},"src/control-plane/monitor.ts":{"bytesInOutput":1817},"src/control-plane/usage.ts":{"bytesInOutput":2183}},"bytes":21508}}}
@@ -1 +1 @@
1
- {"inputs":{"src/control-plane/types.ts":{"bytes":2467,"imports":[],"format":"esm"},"src/version.ts":{"bytes":37,"imports":[],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2591,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/event-store.ts":{"bytes":2379,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"}],"format":"esm"},"src/control-plane/run-store.ts":{"bytes":12025,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"},{"path":"src/control-plane/event-store.ts","kind":"import-statement","original":"./event-store.js"}],"format":"esm"},"src/control-plane/controller.ts":{"bytes":4220,"imports":[{"path":"src/control-plane/run-store.ts","kind":"import-statement","original":"./run-store.js"}],"format":"esm"},"src/control-plane/daemon.ts":{"bytes":5047,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/workflow.ts":{"bytes":10410,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/monitor.ts":{"bytes":4128,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/usage.ts":{"bytes":5185,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/index.ts":{"bytes":281,"imports":[{"path":"src/control-plane/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/control-plane/run-store.ts","kind":"import-statement","original":"./run-store.js"},{"path":"src/control-plane/event-store.ts","kind":"import-statement","original":"./event-store.js"},{"path":"src/control-plane/controller.ts","kind":"import-statement","original":"./controller.js"},{"path":"src/control-plane/daemon.ts","kind":"import-statement","original":"./daemon.js"},{"path":"src/control-plane/workflow.ts","kind":"import-statement","original":"./workflow.js"},{"path":"src/control-plane/monitor.ts","kind":"import-statement","original":"./monitor.js"},{"path":"src/control-plane/usage.ts","kind":"import-statement","original":"./usage.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"}],"format":"esm"}},"outputs":{"dist/control-plane/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"exports":["AGENT_DAEMON_PROTOCOL_VERSION","AgentDaemonClient","AgentDaemonServer","AgentEventStore","AgentRunController","AgentRunStore","MonitorManager","MonitorStopTool","MonitorTool","OtelExporter","UsageAccumulator","UsageLedger","WorkflowPlanner","WorkflowRuntime","WorkflowStore","acquireControlPlaneLock","createAgentRunId","getAgentRunDir","getAgentRunStoreDir"],"entryPoint":"src/control-plane/index.ts","inputs":{"src/control-plane/index.ts":{"bytesInOutput":0},"src/control-plane/run-store.ts":{"bytesInOutput":5373},"src/version.ts":{"bytesInOutput":15},"src/control-plane/lock.ts":{"bytesInOutput":1041},"src/control-plane/event-store.ts":{"bytesInOutput":1057},"src/control-plane/controller.ts":{"bytesInOutput":1686},"src/control-plane/daemon.ts":{"bytesInOutput":1941},"src/control-plane/workflow.ts":{"bytesInOutput":4760},"src/control-plane/monitor.ts":{"bytesInOutput":1820},"src/control-plane/usage.ts":{"bytesInOutput":2283}},"bytes":20410}}}
1
+ {"inputs":{"src/control-plane/types.ts":{"bytes":2578,"imports":[],"format":"esm"},"src/version.ts":{"bytes":37,"imports":[],"format":"esm"},"src/control-plane/lock.ts":{"bytes":2591,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/event-store.ts":{"bytes":2379,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"}],"format":"esm"},"src/utils/platform.ts":{"bytes":5600,"imports":[{"path":"node:os","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/run-store.ts":{"bytes":11948,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"},{"path":"src/control-plane/event-store.ts","kind":"import-statement","original":"./event-store.js"},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"}],"format":"esm"},"src/control-plane/controller.ts":{"bytes":4220,"imports":[{"path":"src/control-plane/run-store.ts","kind":"import-statement","original":"./run-store.js"}],"format":"esm"},"src/control-plane/daemon.ts":{"bytes":5047,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/workflow.ts":{"bytes":10381,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"}],"format":"esm"},"src/control-plane/monitor.ts":{"bytes":4128,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/control-plane/usage.ts":{"bytes":5156,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/utils/platform.ts","kind":"import-statement","original":"../utils/platform.js"}],"format":"esm"},"src/control-plane/index.ts":{"bytes":281,"imports":[{"path":"src/control-plane/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/control-plane/run-store.ts","kind":"import-statement","original":"./run-store.js"},{"path":"src/control-plane/event-store.ts","kind":"import-statement","original":"./event-store.js"},{"path":"src/control-plane/controller.ts","kind":"import-statement","original":"./controller.js"},{"path":"src/control-plane/daemon.ts","kind":"import-statement","original":"./daemon.js"},{"path":"src/control-plane/workflow.ts","kind":"import-statement","original":"./workflow.js"},{"path":"src/control-plane/monitor.ts","kind":"import-statement","original":"./monitor.js"},{"path":"src/control-plane/usage.ts","kind":"import-statement","original":"./usage.js"},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"./lock.js"}],"format":"esm"}},"outputs":{"dist/control-plane/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:os","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true}],"exports":["AGENT_DAEMON_PROTOCOL_VERSION","AgentDaemonClient","AgentDaemonServer","AgentEventStore","AgentRunController","AgentRunStore","MonitorManager","MonitorStopTool","MonitorTool","OtelExporter","UsageAccumulator","UsageLedger","WorkflowPlanner","WorkflowRuntime","WorkflowStore","acquireControlPlaneLock","createAgentRunId","getAgentRunDir","getAgentRunStoreDir"],"entryPoint":"src/control-plane/index.ts","inputs":{"src/control-plane/index.ts":{"bytesInOutput":0},"src/control-plane/run-store.ts":{"bytesInOutput":5285},"src/version.ts":{"bytesInOutput":15},"src/control-plane/lock.ts":{"bytesInOutput":1041},"src/control-plane/event-store.ts":{"bytesInOutput":1057},"src/utils/platform.ts":{"bytesInOutput":220},"src/control-plane/controller.ts":{"bytesInOutput":1686},"src/control-plane/daemon.ts":{"bytesInOutput":1941},"src/control-plane/workflow.ts":{"bytesInOutput":4685},"src/control-plane/monitor.ts":{"bytesInOutput":1820},"src/control-plane/usage.ts":{"bytesInOutput":2200}},"bytes":20385}}}