@xenosystem/agent-sdk 0.8.12 → 0.8.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/artifacts/index.cjs +1 -1
- package/dist/artifacts/index.js +1 -1
- package/dist/artifacts/metafile-cjs.json +1 -1
- package/dist/artifacts/metafile-esm.json +1 -1
- package/dist/control-plane/index.cjs +1 -1
- package/dist/control-plane/index.js +1 -1
- package/dist/control-plane/metafile-cjs.json +1 -1
- package/dist/control-plane/metafile-esm.json +1 -1
- package/dist/electron/index.cjs +102 -102
- package/dist/electron/index.d.cts +2 -0
- package/dist/electron/index.d.ts +2 -0
- package/dist/electron/index.js +104 -104
- package/dist/electron/metafile-cjs.json +1 -1
- package/dist/electron/metafile-esm.json +1 -1
- package/dist/index.cjs +236 -236
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +251 -251
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/recipes/metafile-cjs.json +1 -1
- package/dist/recipes/metafile-esm.json +1 -1
- package/dist/research/metafile-cjs.json +1 -1
- package/dist/research/metafile-esm.json +1 -1
- package/dist/session/index.cjs +1 -1
- package/dist/session/index.js +1 -1
- package/dist/session/metafile-cjs.json +1 -1
- package/dist/session/metafile-esm.json +1 -1
- package/ownership/ownership-policy.json +273 -232
- package/package.json +209 -209
package/dist/artifacts/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";var _e=Object.defineProperty;var Gt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Yt=Object.prototype.hasOwnProperty;var Zt=(e,t)=>{for(var i in t)_e(e,i,{get:t[i],enumerable:!0})},Qt=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Kt(t))!Yt.call(e,o)&&o!==i&&_e(e,o,{get:()=>t[o],enumerable:!(n=Gt(t,o))||n.enumerable});return e};var ei=e=>Qt(_e({},"__esModule",{value:!0}),e);var In={};Zt(In,{FileXenoArtifactRepository:()=>Pe,InMemoryXenoArtifactRepository:()=>J,XENO_ARTIFACT_FILE_REPOSITORY_SCHEMA_VERSION:()=>Le,XENO_ARTIFACT_SCHEMA_VERSION:()=>h,XENO_EVIDENCE_GRAPH_SCHEMA_VERSION:()=>pe,XENO_REVIEW_REPORT_SCHEMA_VERSION:()=>Ye,XENO_SPEC_EXECUTION_SCHEMA_VERSION:()=>oe,XENO_SPEC_SCHEMA_VERSION:()=>z,XenoArtifactRepositoryError:()=>u,XenoArtifactReviewService:()=>B,XenoArtifactStateTransitionError:()=>ue,XenoArtifactValidationError:()=>L,XenoDiffParseError:()=>E,XenoEvidenceGraphBuilder:()=>Ce,XenoEvidenceGraphValidationError:()=>he,XenoMultiAgentReviewCoordinator:()=>Ke,XenoReviewValidationError:()=>R,XenoSpecLifecycleService:()=>Be,XenoSpecValidationError:()=>w,assertValidXenoArtifact:()=>I,assertValidXenoEvidenceGraph:()=>q,assertValidXenoReviewPack:()=>Ze,assertValidXenoReviewReport:()=>ae,assertValidXenoReviewTarget:()=>Qe,assertValidXenoSpecDocument:()=>Xe,assertValidXenoSpecExecution:()=>Ge,assertXenoArtifactStateTransition:()=>ee,buildXenoArtifactReviewAnchor:()=>Je,canTransitionXenoArtifactState:()=>pt,canonicalizeArtifactJson:()=>b,defaultXenoReviewPack:()=>Yi,detectXenoSpecDrift:()=>Bi,legacyAgentArtifactToXenoArtifact:()=>fn,normalizeRepositoryRelativePath:()=>Tt,parseUnifiedDiff:()=>He,sha256ArtifactBytes:()=>k,sha256ArtifactJson:()=>x,summarizeXenoArtifactReview:()=>me,toolEvidenceToXenoArtifact:()=>un,turnDiffSummaryToXenoArtifact:()=>mn,unifiedDiffToXenoArtifact:()=>je,validateXenoArtifact:()=>ft,validateXenoArtifactReviewEvent:()=>le,validateXenoEvidenceGraph:()=>lt,validateXenoSpecDocument:()=>Nt,xenoArtifactToDiffDocument:()=>qe,xenoArtifactToLegacyAgentArtifact:()=>pn,xenoArtifactToReviewReport:()=>Qi,xenoArtifactToSpecDocument:()=>ze,xenoArtifactToSpecExecution:()=>$t,xenoArtifactToToolEvidence:()=>ln,xenoArtifactToTurnDiffSummary:()=>vn,xenoReviewReportToArtifact:()=>Zi,xenoReviewReportToGitHubComments:()=>en,xenoSpecArtifactIds:()=>U,xenoSpecExecutionToArtifact:()=>We,xenoSpecToArtifactBundle:()=>Ue});module.exports=ei(In);var h=1,pe=1;var xe=require("node:buffer");var at=require("node:crypto");function k(e){return{algorithm:"sha256",value:(0,at.createHash)("sha256").update(e).digest("hex")}}function b(e){return JSON.stringify(ke(e,new Set))}function x(e){return k(b(e))}function ke(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(o=>ke(o,t));return t.delete(e),n}let i={};for(let n of Object.keys(e).sort((o,r)=>o.localeCompare(r))){let o=e[n];if(o===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);i[n]=ke(o,t)}return t.delete(e),i}var L=class extends Error{code="ARTIFACT_INVALID";issues;constructor(t,i){super(t),this.name="XenoArtifactValidationError",this.issues=i.map(n=>({...n}))}},ue=class extends Error{constructor(i,n){super(`Artifact state cannot transition from ${i} to ${n}`);this.fromState=i;this.toState=n;this.name="XenoArtifactStateTransitionError"}fromState;toState;code="ARTIFACT_STATE_TRANSITION_INVALID"},ti={draft:["pending_review","superseded","archived"],pending_review:["approved","rejected","superseded","archived"],approved:["superseded","archived"],rejected:["superseded","archived"],superseded:["archived"],archived:[]},ii=/^[a-z0-9][a-z0-9._/-]{0,127}$/,ni="[\\u0000-\\u001f\\u007f]",ri=new RegExp(ni),ct=/^[a-f0-9]{64}$/,oi=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,si=new Set(["draft","pending_review","approved","rejected","superseded","archived"]),ai=new Set(["public","internal","confidential","restricted"]),ci=new Set(["agent","tool","user","system","integration"]),di=new Set(["plan","requirements","design","task-graph","patch","diff","file","document","diagram","screenshot","recording","browser-snapshot","test-report","review-report","security-report","performance-report","release-report","sbom","provenance","attestation"]),fi=new Set(["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"]),pi=new Set(["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"]);function p(e,t,i,n){e.push({path:t,code:i,message:n})}function l(e,t,i,n=1024){return typeof e!="string"||e.trim().length===0?(p(i,t,"required_string","Value must be a non-empty string"),!1):(e.length>n&&p(i,t,"string_too_long",`Value must not exceed ${n} characters`),ri.test(e)&&p(i,t,"control_character","Value must not contain control characters"),!0)}function Z(e,t,i){e!==void 0&&(!Number.isFinite(Date.parse(e))||!e.includes("T"))&&p(i,t,"invalid_timestamp","Value must be an ISO 8601 timestamp")}function F(e,t,i,n){if(typeof e!="string"||!e.startsWith(t))return;let o=e.slice(t.length);ii.test(o)||p(n,i,"invalid_custom_name",`Custom name after ${t} is invalid`)}function dt(e,t,i){if(!e||typeof e!="object"){p(i,t,"missing_actor","Actor is required");return}l(e.kind,`${t}.kind`,i,64),ci.has(e.kind)||p(i,`${t}.kind`,"unknown_actor_kind","Actor kind is not supported"),l(e.id,`${t}.id`,i,512),e?.displayName!==void 0&&l(e.displayName,`${t}.displayName`,i,512),e?.profileFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(e.profileFingerprint)&&p(i,`${t}.profileFingerprint`,"invalid_fingerprint","Profile fingerprint must be 64 lowercase hexadecimal characters")}function Te(e,t,i){if(!e||typeof e!="object"){p(i,t,"invalid_anchor","Anchor must be an object");return}switch(e.kind){case"file":l(e.path,`${t}.path`,i,4096);break;case"source-line":l(e.path,`${t}.path`,i,4096),(!Number.isInteger(e.startLine)||e.startLine<1)&&p(i,`${t}.startLine`,"invalid_line","startLine must be a positive integer"),e.endLine!==void 0&&(!Number.isInteger(e.endLine)||e.endLine<e.startLine)&&p(i,`${t}.endLine`,"invalid_line_range","endLine must be greater than or equal to startLine");break;case"diff-hunk":l(e.path,`${t}.path`,i,4096),l(e.hunkId,`${t}.hunkId`,i,512);break;case"symbol":l(e.path,`${t}.path`,i,4096),l(e.symbol,`${t}.symbol`,i,1024);break;case"dom-node":l(e.pageId,`${t}.pageId`,i,512),!e.selector&&!e.accessibilityId&&!e.snapshotArtifactId&&p(i,t,"missing_dom_locator","DOM anchors require a selector, accessibility ID, or snapshot artifact ID");break;case"timeline":l(e.recordingArtifactId,`${t}.recordingArtifactId`,i,512),(!Number.isFinite(e.startMs)||e.startMs<0)&&p(i,`${t}.startMs`,"invalid_time","startMs must be a non-negative finite number"),e.endMs!==void 0&&(!Number.isFinite(e.endMs)||e.endMs<e.startMs)&&p(i,`${t}.endMs`,"invalid_time_range","endMs must be greater than or equal to startMs");break;case"region":l(e.mediaArtifactId,`${t}.mediaArtifactId`,i,512),[e.x,e.y,e.width,e.height].every(Number.isFinite)?(e.width<=0||e.height<=0)&&p(i,t,"invalid_region_size","Region width and height must be positive"):p(i,t,"invalid_region","Region coordinates must be finite numbers");break;case"artifact":l(e.artifactId,`${t}.artifactId`,i,512);break;default:typeof e.kind!="string"||!e.kind.startsWith("custom:")?p(i,`${t}.kind`,"unknown_anchor","Anchor kind is not supported"):F(e.kind,"custom:",`${t}.kind`,i)}}function Q(e,t,i,n){if(!(e===null||typeof e=="string"||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||p(i,t,"non_finite_number","JSON numbers must be finite");return}if(typeof e!="object"){p(i,t,"non_json_value","Value must be JSON-serializable");return}if(n.has(e)){p(i,t,"cyclic_value","Value must not contain cycles");return}if(n.add(e),Array.isArray(e))e.forEach((o,r)=>Q(o,`${t}[${r}]`,i,n));else for(let[o,r]of Object.entries(e))r===void 0?p(i,`${t}.${o}`,"undefined_value","Undefined is not valid JSON"):Q(r,`${t}.${o}`,i,n);n.delete(e)}}function ft(e){let t=[];if(!e||typeof e!="object")return[{path:"$",code:"invalid_artifact",message:"Artifact must be an object"}];if(e.schemaVersion!==1&&p(t,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),l(e.artifactId,"artifactId",t,512),(!Number.isInteger(e.revision)||e.revision<1)&&p(t,"revision","invalid_revision","revision must be a positive integer"),l(e.kind,"kind",t,160),typeof e.kind=="string"&&!di.has(e.kind)&&!e.kind.startsWith("custom:")&&p(t,"kind","unknown_artifact_kind","Artifact kind is not supported"),F(e.kind,"custom:","kind",t),l(e.title,"title",t,1024),e.description!==void 0&&l(e.description,"description",t,32768),l(e.state,"state",t,64),si.has(e.state)||p(t,"state","unknown_state","Artifact state is not supported"),l(e.createdAt,"createdAt",t,128),Z(e.createdAt,"createdAt",t),Z(e.updatedAt,"updatedAt",t),e.updatedAt&&Number.isFinite(Date.parse(e.createdAt))&&Date.parse(e.updatedAt)<Date.parse(e.createdAt)&&p(t,"updatedAt","timestamp_order","updatedAt must not precede createdAt"),l(e.mediaType,"mediaType",t,255),l(e.sensitivity,"sensitivity",t,64),ai.has(e.sensitivity)||p(t,"sensitivity","unknown_sensitivity","Sensitivity is not supported"),e.identity)for(let[n,o]of Object.entries(e.identity))o!==void 0&&l(o,`identity.${n}`,t,512);if(!e.content||typeof e.content!="object")p(t,"content","missing_content","content descriptor is required");else{!e.content.hash||typeof e.content.hash!="object"?p(t,"content.hash","missing_hash","content hash is required"):(l(e.content.hash.algorithm,"content.hash.algorithm",t,128),F(e.content.hash.algorithm,"custom:","content.hash.algorithm",t),typeof e.content.hash.algorithm=="string"&&e.content.hash.algorithm!=="sha256"&&!e.content.hash.algorithm.startsWith("custom:")&&p(t,"content.hash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported"),l(e.content.hash.value,"content.hash.value",t,512),e.content.hash.algorithm==="sha256"&&!ct.test(e.content.hash.value)&&p(t,"content.hash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters")),(!Number.isSafeInteger(e.content.sizeBytes)||e.content.sizeBytes<0)&&p(t,"content.sizeBytes","invalid_size","sizeBytes must be a non-negative safe integer");let n=e.content.storage;if(!n||typeof n!="object")p(t,"content.storage","missing_storage","storage reference is required");else if(n.type==="inline")if(n.text===void 0==(n.base64===void 0))p(t,"content.storage","invalid_inline_storage","Inline storage requires exactly one of text or base64");else{let o;n.text!==void 0?o=xe.Buffer.from(n.text,"utf8"):n.base64!==void 0&&(oi.test(n.base64)?o=xe.Buffer.from(n.base64,"base64"):p(t,"content.storage.base64","invalid_base64","Inline base64 content is malformed")),o&&e.content.sizeBytes!==o.byteLength&&p(t,"content.sizeBytes","content_size_mismatch","sizeBytes does not match inline content"),o&&e.content.hash.algorithm==="sha256"&&k(o).value!==e.content.hash.value&&p(t,"content.hash.value","content_hash_mismatch","Hash does not match inline content")}else n.type==="file"?l(n.path,"content.storage.path",t,4096):n.type==="blob"?l(n.uri,"content.storage.uri",t,8192):n.type==="git"?(l(n.commit,"content.storage.commit",t,512),l(n.path,"content.storage.path",t,4096)):n.type==="url"?(l(n.url,"content.storage.url",t,8192),Z(n.expiresAt,"content.storage.expiresAt",t)):n.type==="external"?(l(n.provider,"content.storage.provider",t,255),l(n.locator,"content.storage.locator",t,8192)):p(t,"content.storage.type","unknown_storage","Storage type is not supported");e.content.encoding!==void 0&&(typeof e.content.encoding!="string"||e.content.encoding!=="utf8"&&e.content.encoding!=="base64"&&e.content.encoding!=="binary"&&!e.content.encoding.startsWith("custom:"))&&p(t,"content.encoding","unknown_encoding","Content encoding is not supported"),F(e.content.encoding,"custom:","content.encoding",t)}!e.provenance||typeof e.provenance!="object"?p(t,"provenance","missing_provenance","provenance is required"):(dt(e.provenance.producer,"provenance.producer",t),e.provenance.capabilityLeaseIds?.forEach((n,o)=>l(n,`provenance.capabilityLeaseIds[${o}]`,t,512)),e.provenance.sourceArtifactIds?.forEach((n,o)=>l(n,`provenance.sourceArtifactIds[${o}]`,t,512)),e.provenance.attributes&&Q(e.provenance.attributes,"provenance.attributes",t,new Set));let i=new Set;return e.relationships?.forEach((n,o)=>{let r=`relationships[${o}]`;l(n.relation,`${r}.relation`,t,160),typeof n.relation=="string"&&!pi.has(n.relation)&&!n.relation.startsWith("custom:")&&p(t,`${r}.relation`,"unknown_relationship","Relationship type is not supported"),F(n.relation,"custom:",`${r}.relation`,t),l(n.target?.type,`${r}.target.type`,t,160),typeof n.target?.type=="string"&&!fi.has(n.target.type)&&!n.target.type.startsWith("custom:")&&p(t,`${r}.target.type`,"unknown_reference_type","Evidence reference type is not supported"),F(n.target?.type,"custom:",`${r}.target.type`,t),l(n.target?.id,`${r}.target.id`,t,512);let a=`${n.relation}:${n.target?.type}:${n.target?.id}:${n.target?.revision??""}`;i.has(a)&&p(t,r,"duplicate_relationship","Duplicate relationship"),i.add(a),n.attributes&&Q(n.attributes,`${r}.attributes`,t,new Set)}),e.anchors?.forEach((n,o)=>Te(n,`anchors[${o}]`,t)),e.revision===1&&e.predecessorRevision!==void 0&&p(t,"predecessorRevision","unexpected_predecessor","First revision cannot have a predecessor"),e.revision>1&&(!Number.isInteger(e.predecessorRevision)||(e.predecessorRevision??0)>=e.revision)&&p(t,"predecessorRevision","invalid_predecessor","Later revisions require an earlier predecessor revision"),Z(e.retention?.retainUntil,"retention.retainUntil",t),e.retention?.legalHold!==void 0&&typeof e.retention.legalHold!="boolean"&&p(t,"retention.legalHold","invalid_boolean","legalHold must be a boolean"),e.extensions&&Q(e.extensions,"extensions",t,new Set),t}function I(e){let t=ft(e);if(t.length>0)throw new L("XENO artifact validation failed",t)}function pt(e,t){return ti[e].includes(t)}function ee(e,t){if(!pt(e,t))throw new ue(e,t)}function le(e,t){let i=[];return e.schemaVersion!==1&&p(i,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),l(e.eventId,"eventId",i,512),l(e.artifactId,"artifactId",i,512),(!Number.isInteger(e.artifactRevision)||e.artifactRevision<1)&&p(i,"artifactRevision","invalid_revision","artifactRevision must be a positive integer"),(!Number.isInteger(e.sequence)||e.sequence<1)&&p(i,"sequence","invalid_sequence","sequence must be a positive integer"),l(e.recordedAt,"recordedAt",i,128),Z(e.recordedAt,"recordedAt",i),dt(e.actor,"actor",i),!e.artifactHash||typeof e.artifactHash!="object"?p(i,"artifactHash","missing_hash","Artifact hash is required"):(l(e.artifactHash.algorithm,"artifactHash.algorithm",i,128),F(e.artifactHash.algorithm,"custom:","artifactHash.algorithm",i),l(e.artifactHash.value,"artifactHash.value",i,512),e.artifactHash.algorithm==="sha256"&&!ct.test(e.artifactHash.value)&&p(i,"artifactHash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters"),typeof e.artifactHash.algorithm=="string"&&e.artifactHash.algorithm!=="sha256"&&!e.artifactHash.algorithm.startsWith("custom:")&&p(i,"artifactHash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported")),["review-requested","comment-added","comment-resolved","comment-reopened","decision-recorded","review-withdrawn"].includes(e.type)||p(i,"type","unknown_review_event","Review event type is not supported"),e.type==="comment-added"?(l(e.commentId,"commentId",i,512),l(e.body,"body",i,65536),e.anchor&&Te(e.anchor,"anchor",i)):e.type==="comment-resolved"||e.type==="comment-reopened"?l(e.commentId,"commentId",i,512):e.type==="decision-recorded"&&(["approved","rejected","changes_requested"].includes(e.decision)||p(i,"decision","unknown_review_decision","Review decision is not supported"),e.scope&&Te(e.scope,"scope",i)),t&&(e.artifactId!==t.artifactId&&p(i,"artifactId","artifact_mismatch","Review event targets a different artifact"),e.artifactRevision!==t.revision&&p(i,"artifactRevision","revision_mismatch","Review event targets a different revision"),e.artifactHash&&(e.artifactHash.algorithm!==t.content.hash.algorithm||e.artifactHash.value!==t.content.hash.value)&&p(i,"artifactHash","hash_mismatch","Review event hash does not match the artifact revision")),i}function me(e){let t="not_requested",i,n,o,r=0,a=new Set,c=new Set;for(let s of[...e].sort((d,f)=>d.sequence-f.sequence))o=s.recordedAt,s.type==="review-requested"?t="pending":s.type==="review-withdrawn"?t="withdrawn":s.type==="comment-added"?(a.add(s.commentId),c.delete(s.commentId),t==="not_requested"&&(t="pending")):s.type==="comment-resolved"?c.add(s.commentId):s.type==="comment-reopened"?c.delete(s.commentId):s.type==="decision-recorded"&&(s.scope?r+=1:(i=s.decision,n=s.eventId,t=s.decision));return{status:t,totalComments:a.size,unresolvedComments:[...a].filter(s=>!c.has(s)).length,...i?{latestDecision:i}:{},...n?{latestDecisionEventId:n}:{},...r>0?{scopedDecisionCount:r}:{},...o?{lastReviewedAt:o}:{}}}var he=class extends Error{code="EVIDENCE_GRAPH_INVALID";issues;constructor(t){super("XENO evidence graph validation failed"),this.name="XenoEvidenceGraphValidationError",this.issues=t.map(i=>({...i}))}},ui=new Set(["depends_on","decomposes","supersedes"]),li=/^[a-z0-9][a-z0-9._/-]{0,127}$/,mi=new Set(["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"]),vi=new Set(["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"]);function y(e,t,i,n){e.push({path:t,code:i,message:n})}function te(e){return e.includes("T")&&Number.isFinite(Date.parse(e))}function ut(e,t){return e.startsWith("custom:")?li.test(e.slice(7)):t.has(e)}function lt(e){let t=[];if(!e||typeof e!="object")return[{path:"$",code:"invalid_graph",message:"Evidence graph must be an object"}];e.schemaVersion!==1&&y(t,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),(typeof e.graphId!="string"||e.graphId.trim().length===0)&&y(t,"graphId","required_string","graphId must be a non-empty string"),(!Number.isInteger(e.version)||e.version<1)&&y(t,"version","invalid_version","version must be a positive integer"),te(e.createdAt)||y(t,"createdAt","invalid_timestamp","createdAt must be an ISO 8601 timestamp"),te(e.updatedAt)||y(t,"updatedAt","invalid_timestamp","updatedAt must be an ISO 8601 timestamp"),te(e.createdAt)&&te(e.updatedAt)&&Date.parse(e.updatedAt)<Date.parse(e.createdAt)&&y(t,"updatedAt","timestamp_order","updatedAt must not precede createdAt");let i=new Map;Array.isArray(e.nodes)||y(t,"nodes","invalid_nodes","nodes must be an array"),(Array.isArray(e.nodes)?e.nodes:[]).forEach((f,g)=>{let X=`nodes[${g}]`;typeof f.id!="string"||f.id.trim().length===0?y(t,`${X}.id`,"required_string","Node ID must be a non-empty string"):i.has(f.id)?y(t,`${X}.id`,"duplicate_node",`Node ID ${f.id} is duplicated`):i.set(f.id,f),(typeof f.type!="string"||!ut(f.type,mi))&&y(t,`${X}.type`,"invalid_node_type","Node type is invalid"),f.artifactRevision!==void 0&&(!Number.isInteger(f.artifactRevision)||f.artifactRevision<1)&&y(t,`${X}.artifactRevision`,"invalid_revision","artifactRevision must be a positive integer")});let n=new Set,o=new Set;Array.isArray(e.edges)||y(t,"edges","invalid_edges","edges must be an array"),(Array.isArray(e.edges)?e.edges:[]).forEach((f,g)=>{let X=`edges[${g}]`;typeof f.id!="string"||f.id.trim().length===0?y(t,`${X}.id`,"required_string","Edge ID must be a non-empty string"):n.has(f.id)&&y(t,`${X}.id`,"duplicate_edge",`Edge ID ${f.id} is duplicated`),n.add(f.id),(typeof f.type!="string"||!ut(f.type,vi))&&y(t,`${X}.type`,"invalid_edge_type","Edge type is invalid");let D=`${f.type}:${f.from}:${f.to}`;o.has(D)&&y(t,X,"duplicate_edge_identity","Equivalent evidence edge is duplicated"),o.add(D),i.has(f.from)||y(t,`${X}.from`,"dangling_reference",`Source node ${f.from} does not exist`),i.has(f.to)||y(t,`${X}.to`,"dangling_reference",`Target node ${f.to} does not exist`),f.from===f.to&&y(t,X,"self_edge","Evidence edges cannot point to the same node"),te(f.createdAt)||y(t,`${X}.createdAt`,"invalid_timestamp","createdAt must be an ISO 8601 timestamp")});let r=(Array.isArray(e.edges)?e.edges:[]).filter(f=>ui.has(f.type)),a=new Map;for(let f of r){let g=a.get(f.from)??[];g.push(f.to),a.set(f.from,g)}let c=new Set,s=new Set,d=f=>{if(c.has(f))return!0;if(s.has(f))return!1;c.add(f);for(let g of a.get(f)??[])if(d(g))return!0;return c.delete(f),s.add(f),!1};for(let f of i.keys())if(d(f)){y(t,"edges","cyclic_graph","Dependency, decomposition, and supersession edges must be acyclic");break}return t}function q(e){let t=lt(e);if(t.length>0)throw new he(t)}var Ce=class{now;graph;constructor(t){if("schemaVersion"in t)q(t),this.now=()=>new Date().toISOString(),this.graph=ve(t);else{this.now=t.now??(()=>new Date().toISOString());let i=this.now();this.graph={schemaVersion:1,graphId:t.graphId,version:1,createdAt:i,updatedAt:i,nodes:[],edges:[]},q(this.graph)}}addNode(t){let i=ve(this.graph);return i.nodes.push(mt(t)),this.touch(i),q(i),this.graph=i,this}addEdge(t){let i=ve(this.graph);return i.edges.push(vt(t)),this.touch(i),q(i),this.graph=i,this}build(){return q(this.graph),ve(this.graph)}touch(t){t.version+=1,t.updatedAt=this.now()}};function mt(e){return{...e,...e.attributes?{attributes:structuredClone(e.attributes)}:{}}}function vt(e){return{...e,...e.producer?{producer:{...e.producer}}:{},...e.attributes?{attributes:structuredClone(e.attributes)}:{}}}function ve(e){return{...e,nodes:e.nodes.map(mt),edges:e.edges.map(vt)}}var u=class extends Error{constructor(i,n,o,r){super(n,r);this.code=i;this.detail=o;this.name="XenoArtifactRepositoryError"}code;detail},J=class{records=new Map;currentRevisions=new Map;now;idFactory;eventIds=new Set;idCounter=0;constructor(t={}){this.now=t.now??(()=>new Date().toISOString()),this.idFactory=t.idFactory??(i=>(this.idCounter+=1,`${i}_${Date.now().toString(36)}_${this.idCounter.toString(36)}`)),t.initialState&&this.hydrate(t.initialState)}exportState(){let t=[...this.records.values()].flatMap(i=>[...i.values()]).sort(ht).map(i=>({artifact:ie(i.artifact),recordVersion:i.recordVersion,lifecycleEvents:structuredClone(i.lifecycleEvents),reviewEvents:structuredClone(i.reviewEvents)}));return{schemaVersion:1,records:t}}async create(t){if(I(t),this.assertInitialState(t),t.revision!==1)throw new u("ARTIFACT_REVISION_INVALID","A new artifact must begin at revision 1",{artifactId:t.artifactId,revision:t.revision});if(this.records.has(t.artifactId))throw new u("ARTIFACT_ALREADY_EXISTS",`Artifact ${t.artifactId} already exists`,{artifactId:t.artifactId});let i=ie(t),n=this.createLifecycleEvent({artifact:i,sequence:1,actor:i.provenance.producer,fromState:null,toState:i.state,reason:"artifact-created"}),o={artifact:i,recordVersion:1,lifecycleEvents:[n],reviewEvents:[]};return this.records.set(i.artifactId,new Map([[i.revision,o]])),this.currentRevisions.set(i.artifactId,i.revision),M(o)}async createRevision(t,i={}){I(t),this.assertInitialState(t);let n=this.getMutable(t.artifactId);this.assertVersion(n,i.expectedRecordVersion);let o=n.artifact.revision+1;if(t.revision!==o||t.predecessorRevision!==n.artifact.revision)throw new u("ARTIFACT_REVISION_INVALID",`Revision ${t.revision} does not follow current revision ${n.artifact.revision}`,{artifactId:t.artifactId,currentRevision:n.artifact.revision,requestedRevision:t.revision});if(gi(t,n.artifact))throw new u("ARTIFACT_CONTENT_UNCHANGED","A new artifact revision must have a different content hash",{artifactId:t.artifactId,revision:t.revision});if(n.artifact.state==="archived")throw new u("ARTIFACT_REVISION_INVALID","Archived artifacts cannot receive new revisions",{artifactId:t.artifactId,revision:n.artifact.revision});if(n.artifact.state!=="superseded"){ee(n.artifact.state,"superseded");let s=this.now(),d=this.createLifecycleEvent({artifact:n.artifact,sequence:n.lifecycleEvents.length+1,actor:i.actor??t.provenance.producer,fromState:n.artifact.state,toState:"superseded",reason:i.reason??`superseded-by-revision-${t.revision}`,recordedAt:s});n.artifact.state="superseded",n.artifact.updatedAt=s,n.lifecycleEvents.push(d),n.recordVersion+=1}let r=ie(t),a=this.createLifecycleEvent({artifact:r,sequence:1,actor:i.actor??r.provenance.producer,fromState:null,toState:r.state,reason:i.reason??`revision-created-from-${n.artifact.revision}`}),c={artifact:r,recordVersion:1,lifecycleEvents:[a],reviewEvents:[]};return this.records.get(r.artifactId)?.set(r.revision,c),this.currentRevisions.set(r.artifactId,r.revision),M(c)}async get(t,i){let n=this.records.get(t);if(!n)return;let o=i??this.currentRevisions.get(t);if(o===void 0)return;let r=n.get(o);return r?M(r):void 0}async require(t,i){let n=await this.get(t,i);if(!n)throw new u("ARTIFACT_NOT_FOUND",`Artifact ${t}${i===void 0?"":` revision ${i}`} was not found`,{artifactId:t,...i===void 0?{}:{revision:i}});return n}async list(t={}){let i=[];for(let[n,o]of this.records)if(!(t.artifactIds&&!t.artifactIds.includes(n)))if(t.includeSuperseded)i.push(...o.values());else{let r=this.currentRevisions.get(n);if(r!==void 0){let a=o.get(r);a&&i.push(a)}}return i.filter(n=>yi(n.artifact,t)).sort(ht).map(M)}async listRevisions(t){let i=this.records.get(t);return i?[...i.values()].sort((n,o)=>n.artifact.revision-o.artifact.revision).map(M):[]}async transition(t){let i=this.getMutable(t.artifactId,t.revision);if(this.assertVersion(i,t.expectedRecordVersion),ee(i.artifact.state,t.toState),t.toState==="approved"||t.toState==="rejected"){let a=t.reviewEventId?i.reviewEvents.find(s=>s.eventId===t.reviewEventId&&s.type==="decision-recorded"):void 0,c=me(i.reviewEvents);if(!a||a.decision!==t.toState||c.latestDecisionEventId!==a.eventId)throw new u("ARTIFACT_REVIEW_DECISION_REQUIRED",`Transition to ${t.toState} requires a matching decision event`,{artifactId:t.artifactId,revision:i.artifact.revision});if(t.toState==="approved"&&c.unresolvedComments>0)throw new u("ARTIFACT_UNRESOLVED_COMMENTS",`Artifact has ${c.unresolvedComments} unresolved review comment(s)`,{artifactId:t.artifactId,revision:i.artifact.revision,unresolvedComments:c.unresolvedComments})}let n=this.now(),o=i.artifact.state,r=this.createLifecycleEvent({artifact:i.artifact,sequence:i.lifecycleEvents.length+1,actor:t.actor,fromState:o,toState:t.toState,reason:t.reason,reviewEventId:t.reviewEventId,recordedAt:n});return i.artifact.state=t.toState,i.artifact.updatedAt=n,i.lifecycleEvents.push(r),i.recordVersion+=1,M(i)}async appendReviewEvent(t){let i=t.event,n=this.getMutable(i.artifactId,i.artifactRevision);if(this.assertVersion(n,t.expectedRecordVersion),n.artifact.state==="archived"||n.artifact.state==="superseded")throw new u("ARTIFACT_REVIEW_INVALID",`Cannot append review events to a ${n.artifact.state} artifact revision`,{artifactId:i.artifactId,revision:i.artifactRevision});if(this.assertReviewCommentState(n,i),(i.type==="review-requested"||i.type==="review-withdrawn"||i.type==="decision-recorded")&&n.artifact.state!=="pending_review")throw new u("ARTIFACT_REVIEW_INVALID",`${i.type} requires an artifact in pending_review state`,{artifactId:i.artifactId,revision:i.artifactRevision});let o={...structuredClone(i),schemaVersion:1,eventId:this.nextEventId("review_event"),sequence:n.reviewEvents.length+1,recordedAt:this.now()},r=le(o,n.artifact);if(r.length>0)throw new L("XENO artifact review event validation failed",r);return n.reviewEvents.push(o),n.recordVersion+=1,M(n)}getMutable(t,i){let n=this.records.get(t),o=i??this.currentRevisions.get(t),r=o===void 0?void 0:n?.get(o);if(!r)throw new u("ARTIFACT_NOT_FOUND",`Artifact ${t}${i===void 0?"":` revision ${i}`} was not found`,{artifactId:t,...i===void 0?{}:{revision:i}});return r}assertVersion(t,i){if(i!==void 0&&i!==t.recordVersion)throw new u("ARTIFACT_CONFLICT",`Expected record version ${i}, found ${t.recordVersion}`,{artifactId:t.artifact.artifactId,revision:t.artifact.revision,expectedRecordVersion:i,actualRecordVersion:t.recordVersion})}assertInitialState(t){if(t.state!=="draft"&&t.state!=="pending_review")throw new u("ARTIFACT_REVISION_INVALID","New artifact revisions must begin in draft or pending_review state",{artifactId:t.artifactId,revision:t.revision})}assertReviewCommentState(t,i){if(i.type==="comment-added"){if(t.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===i.commentId))throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${i.commentId} already exists`);if(i.parentCommentId&&!t.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===i.parentCommentId))throw new u("ARTIFACT_REVIEW_INVALID",`Parent comment ${i.parentCommentId} does not exist`);return}if(i.type!=="comment-resolved"&&i.type!=="comment-reopened")return;if(!t.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===i.commentId))throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${i.commentId} does not exist`);let o=Ai(t.reviewEvents,i.commentId);if(i.type==="comment-resolved"&&o.resolved)throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${i.commentId} is already resolved`);if(i.type==="comment-reopened"&&!o.resolved)throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${i.commentId} is not resolved`)}createLifecycleEvent(t){return{schemaVersion:1,eventId:this.nextEventId("artifact_event"),artifactId:t.artifact.artifactId,revision:t.artifact.revision,sequence:t.sequence,recordedAt:t.recordedAt??this.now(),actor:{...t.actor},fromState:t.fromState,toState:t.toState,...t.reason?{reason:t.reason}:{},...t.reviewEventId?{reviewEventId:t.reviewEventId}:{}}}nextEventId(t){let i=this.idFactory(t);if(typeof i!="string"||i.trim().length===0||this.eventIds.has(i))throw new u("ARTIFACT_CONFLICT",`Event ID factory produced an invalid or duplicate ${t} ID`);return this.eventIds.add(i),i}hydrate(t){if(t.schemaVersion!==1||!Array.isArray(t.records))throw new u("ARTIFACT_REVISION_INVALID","Artifact repository state has an unsupported schema or record collection");let i=[...t.records].sort((n,o)=>n.artifact.artifactId.localeCompare(o.artifact.artifactId)||n.artifact.revision-o.artifact.revision);for(let n of i){let o=hi(n,this.eventIds),r=this.records.get(o.artifact.artifactId);if(r||(r=new Map,this.records.set(o.artifact.artifactId,r)),r.has(o.artifact.revision))throw new u("ARTIFACT_REVISION_INVALID",`Duplicate persisted revision ${o.artifact.artifactId}:${o.artifact.revision}`);r.set(o.artifact.revision,o),this.currentRevisions.set(o.artifact.artifactId,o.artifact.revision)}for(let[n,o]of this.records){let r=[...o.values()].sort((a,c)=>a.artifact.revision-c.artifact.revision);for(let a=0;a<r.length;a+=1){let c=r[a],s=a+1;if(c.artifact.revision!==s)throw new u("ARTIFACT_REVISION_INVALID",`Persisted artifact ${n} is missing revision ${s}`);if(a===0&&c.artifact.predecessorRevision!==void 0)throw new u("ARTIFACT_REVISION_INVALID",`Initial revision for ${n} cannot declare a predecessor`);if(a>0&&c.artifact.predecessorRevision!==s-1)throw new u("ARTIFACT_REVISION_INVALID",`Persisted revision ${n}:${s} has an invalid predecessor`);if(a<r.length-1&&c.artifact.state!=="superseded")throw new u("ARTIFACT_REVISION_INVALID",`Non-current revision ${n}:${s} must be superseded`)}}}};function hi(e,t){if(I(e.artifact),!Number.isInteger(e.recordVersion)||e.recordVersion<1)throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact recordVersion must be a positive integer",{artifactId:e.artifact.artifactId,revision:e.artifact.revision});if(!Array.isArray(e.lifecycleEvents)||e.lifecycleEvents.length===0||!Array.isArray(e.reviewEvents))throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact records require lifecycle and review event arrays",{artifactId:e.artifact.artifactId,revision:e.artifact.revision});let i=e.lifecycleEvents.length+e.reviewEvents.length;if(e.recordVersion!==i)throw new u("ARTIFACT_REVISION_INVALID",`Persisted record version ${e.recordVersion} does not match ${i} mutations`,{artifactId:e.artifact.artifactId,revision:e.artifact.revision});let n=null;for(let r=0;r<e.lifecycleEvents.length;r+=1){let a=e.lifecycleEvents[r];if(a.schemaVersion!==1||a.artifactId!==e.artifact.artifactId||a.revision!==e.artifact.revision||a.sequence!==r+1||a.fromState!==n||typeof a.eventId!="string"||a.eventId.length===0||t.has(a.eventId)||!Number.isFinite(Date.parse(a.recordedAt)))throw new u("ARTIFACT_REVISION_INVALID",`Persisted lifecycle event ${r+1} is invalid`,{artifactId:e.artifact.artifactId,revision:e.artifact.revision});if(n===null){if(a.toState!=="draft"&&a.toState!=="pending_review")throw new u("ARTIFACT_REVISION_INVALID","A persisted artifact must begin in draft or pending_review state",{artifactId:e.artifact.artifactId,revision:e.artifact.revision})}else ee(n,a.toState);t.add(a.eventId),n=a.toState}if(n!==e.artifact.state)throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact state does not match its lifecycle tail",{artifactId:e.artifact.artifactId,revision:e.artifact.revision});let o=new Map;for(let r=0;r<e.reviewEvents.length;r+=1){let a=e.reviewEvents[r];if(a.sequence!==r+1||t.has(a.eventId))throw new u("ARTIFACT_REVIEW_INVALID",`Persisted review event ${r+1} has an invalid sequence or duplicate ID`,{artifactId:e.artifact.artifactId,revision:e.artifact.revision});let c=le(a,e.artifact);if(c.length>0)throw new L("Persisted XENO artifact review event validation failed",c);if(a.type==="comment-added"){if(o.has(a.commentId)||a.parentCommentId!==void 0&&!o.has(a.parentCommentId))throw new u("ARTIFACT_REVIEW_INVALID",`Persisted comment ${a.commentId} has an invalid identity or parent`);o.set(a.commentId,!1)}else if(a.type==="comment-resolved"||a.type==="comment-reopened"){let s=o.get(a.commentId);if(s===void 0||a.type==="comment-resolved"&&s||a.type==="comment-reopened"&&!s)throw new u("ARTIFACT_REVIEW_INVALID",`Persisted comment transition for ${a.commentId} is invalid`);o.set(a.commentId,a.type==="comment-resolved")}t.add(a.eventId)}return{artifact:ie(e.artifact),recordVersion:e.recordVersion,lifecycleEvents:structuredClone(e.lifecycleEvents),reviewEvents:structuredClone(e.reviewEvents)}}function gi(e,t){return e.content.hash.algorithm===t.content.hash.algorithm&&e.content.hash.value===t.content.hash.value}function yi(e,t){return!(t.kinds&&!t.kinds.includes(e.kind)||t.states&&!t.states.includes(e.state)||t.runId&&e.identity?.runId!==t.runId||t.sessionId&&e.identity?.sessionId!==t.sessionId||t.turnId&&e.identity?.turnId!==t.turnId||t.taskId&&e.identity?.taskId!==t.taskId||t.workspaceId&&e.identity?.workspaceId!==t.workspaceId||t.repositoryId&&e.identity?.repositoryId!==t.repositoryId||t.producerId&&e.provenance.producer.id!==t.producerId||t.sensitivity&&!t.sensitivity.includes(e.sensitivity))}function ht(e,t){return e.artifact.createdAt.localeCompare(t.artifact.createdAt)||e.artifact.artifactId.localeCompare(t.artifact.artifactId)||e.artifact.revision-t.artifact.revision}function Ai(e,t){let i=!1;for(let n of e)(n.type==="comment-resolved"||n.type==="comment-reopened")&&n.commentId===t&&(i=n.type==="comment-resolved");return{resolved:i}}function ie(e){return structuredClone(e)}function M(e){return{artifact:ie(e.artifact),recordVersion:e.recordVersion,etag:`${e.artifact.artifactId}:${e.artifact.revision}:${e.recordVersion}`,lifecycleEvents:structuredClone(e.lifecycleEvents),reviewEvents:structuredClone(e.reviewEvents),reviewSummary:me(e.reviewEvents)}}var Fe=require("node:crypto"),S=require("node:fs/promises"),N=require("node:path");var $=require("node:fs"),Ne=require("node:os"),yt=require("node:path");function Ii(){return new Date().toISOString()}function wi(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function At(e){try{return JSON.parse((0,$.readFileSync)(e,"utf8"))}catch{return null}}function Ri(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function Xi(e){return e.hostname!==(0,Ne.hostname)()?!0:Ri(e.pid)}function gt(e,t){(0,$.mkdirSync)((0,yt.dirname)(e),{recursive:!0}),(0,$.writeFileSync)(e,JSON.stringify(t,null,2)+`
|
|
2
|
-
`,{encoding:"utf8",flag:"wx"})}function Ei(e,t){let i=At(e);i?.pid!==t.pid||i.hostname!==t.hostname||(0,$.rmSync)(e,{force:!0})}function It(e,t,i){let n=Ii(),o={schemaVersion:1,name:t,pid:process.pid,hostname:(0,Ne.hostname)(),processStartedAt:wi(),version:i,acquiredAt:n,updatedAt:n};try{gt(e,o)}catch(r){if(r.code!=="EEXIST")throw r;let c=At(e);if(c&&Xi(c))throw new Error(`${t} is already locked by PID ${c.pid} on ${c.hostname}.`);(0,$.rmSync)(e,{force:!0}),gt(e,o)}return{record:o,release:()=>{Ei(e,o)}}}var wt="0.8.
|
|
2
|
+
`,{encoding:"utf8",flag:"wx"})}function Ei(e,t){let i=At(e);i?.pid!==t.pid||i.hostname!==t.hostname||(0,$.rmSync)(e,{force:!0})}function It(e,t,i){let n=Ii(),o={schemaVersion:1,name:t,pid:process.pid,hostname:(0,Ne.hostname)(),processStartedAt:wi(),version:i,acquiredAt:n,updatedAt:n};try{gt(e,o)}catch(r){if(r.code!=="EEXIST")throw r;let c=At(e);if(c&&Xi(c))throw new Error(`${t} is already locked by PID ${c.pid} on ${c.hostname}.`);(0,$.rmSync)(e,{force:!0}),gt(e,o)}return{record:o,release:()=>{Ei(e,o)}}}var wt="0.8.13";var Le=1,bi="repository.v1.json",Si=5e3,_i=20,ki=64*1024*1024,Pe=class{directory;snapshotPath;backupPath;lockPath;now;lockTimeoutMs;lockRetryMs;maxSnapshotBytes;onRecovery;mutationTail=Promise.resolve();constructor(t){if(!t||typeof t.directory!="string"||t.directory.trim().length===0)throw new TypeError("Artifact repository directory is required");let i=t.snapshotFileName??bi;if((0,N.basename)(i)!==i||!/^[A-Za-z0-9_.-]+$/.test(i))throw new TypeError("Artifact snapshot filename must be a safe basename");this.directory=(0,N.resolve)(t.directory),this.snapshotPath=(0,N.join)(this.directory,i),this.backupPath=`${this.snapshotPath}.bak`,this.lockPath=`${this.snapshotPath}.lock`,this.now=t.now??(()=>new Date().toISOString()),this.lockTimeoutMs=$e(t.lockTimeoutMs,Si,100,6e4,"lockTimeoutMs"),this.lockRetryMs=$e(t.lockRetryMs,_i,1,1e3,"lockRetryMs"),this.maxSnapshotBytes=$e(t.maxSnapshotBytes,ki,1024,1024*1024*1024,"maxSnapshotBytes"),this.onRecovery=t.onRecovery}async create(t){return this.mutate(i=>i.create(t))}async createRevision(t,i){return this.mutate(n=>n.createRevision(t,i))}async get(t,i){return(await this.load()).repository.get(t,i)}async require(t,i){return(await this.load()).repository.require(t,i)}async list(t){return(await this.load()).repository.list(t)}async listRevisions(t){return(await this.load()).repository.listRevisions(t)}async transition(t){return this.mutate(i=>i.transition(t))}async appendReviewEvent(t){return this.mutate(i=>i.appendReviewEvent(t))}async inspectSnapshot(){return this.readSnapshot(this.snapshotPath,!0)}async mutate(t){return this.enqueueMutation(async()=>{let i=await this.acquireLock();try{let n=await this.load(),o=await t(n.repository);return await this.persist(n),o}finally{i.release()}})}async enqueueMutation(t){let i=this.mutationTail.then(t,t);return this.mutationTail=i.then(()=>{},()=>{}),i}async acquireLock(){let t=Date.now(),i;for(;Date.now()-t<=this.lockTimeoutMs;)try{return It(this.lockPath,`artifact-repository:${(0,N.basename)(this.snapshotPath)}`,wt)}catch(n){if(!(n instanceof Error)||!/already locked by PID/.test(n.message))throw n;i=n,await $i(this.lockRetryMs)}throw new u("ARTIFACT_PERSISTENCE_LOCKED",`Artifact repository remained locked for ${this.lockTimeoutMs}ms`,{snapshotPath:this.snapshotPath},{cause:i})}async load(){let t,i,n=!1;try{i=await this.readSnapshot(this.snapshotPath,!1)}catch(r){t=ge(r)}if(!i&&(t||await Ni(this.backupPath)))try{let r=await this.readSnapshot(this.backupPath,!0);r&&(this.onRecovery?.({snapshotPath:this.snapshotPath,backupPath:this.backupPath,reason:t?.message??"primary snapshot missing"}),i=r,n=!0)}catch(r){throw t?new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository primary and backup snapshots are unreadable",{snapshotPath:this.snapshotPath,backupPath:this.backupPath},{cause:new AggregateError([t,ge(r)])}):r}if(!i&&t)throw t;let o=i?.state??{schemaVersion:1,records:[]};return{repository:new J({now:this.now,idFactory:r=>`${r}_${(0,Fe.randomUUID)()}`,initialState:o}),generation:i?.generation??0,createdAt:i?.createdAt??this.now(),hasSnapshot:i!==void 0,recoveredFromBackup:n,...i?{sourceSnapshot:i}:{}}}async persist(t){let i=this.now(),o={...{schemaVersion:Le,generation:t.generation,createdAt:t.createdAt,updatedAt:i,state:t.repository.exportState()},generation:t.generation+1},r=Ti(o),a=`${JSON.stringify(r,null,2)}
|
|
3
3
|
`;if(Buffer.byteLength(a,"utf8")>this.maxSnapshotBytes)throw new u("ARTIFACT_PERSISTENCE_IO",`Artifact repository snapshot exceeds ${this.maxSnapshotBytes} bytes`,{snapshotPath:this.snapshotPath,maxSnapshotBytes:this.maxSnapshotBytes});await(0,S.mkdir)(this.directory,{recursive:!0,mode:448}),t.hasSnapshot&&!t.recoveredFromBackup&&t.sourceSnapshot&&await Rt(this.backupPath,`${JSON.stringify(t.sourceSnapshot,null,2)}
|
|
4
4
|
`),await Rt(this.snapshotPath,a)}async readSnapshot(t,i){let n;try{n=await(0,S.stat)(t)}catch(o){if(!i&&De(o,"ENOENT")||i&&De(o,"ENOENT"))return;throw Oe("Unable to inspect artifact repository snapshot",t,o)}if(!n.isFile()||n.size>this.maxSnapshotBytes)throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot is not a bounded regular file",{snapshotPath:t,sizeBytes:n.size,maxSnapshotBytes:this.maxSnapshotBytes});try{let o=await(0,S.readFile)(t);if(o.byteLength>this.maxSnapshotBytes)throw new Error("snapshot grew beyond the configured size limit while reading");return xi(JSON.parse(o.toString("utf8")),t)}catch(o){throw o instanceof u?o:Oe("Unable to parse artifact repository snapshot",t,o,!0)}}};function xi(e,t){if(!Ve(e)||e.schemaVersion!==Le||!Number.isInteger(e.generation)||e.generation<0||typeof e.createdAt!="string"||!Number.isFinite(Date.parse(e.createdAt))||typeof e.updatedAt!="string"||!Number.isFinite(Date.parse(e.updatedAt))||!Ve(e.state)||e.state.schemaVersion!==1||!Array.isArray(e.state.records)||!Ve(e.checksum)||e.checksum.algorithm!=="sha256"||typeof e.checksum.value!="string")throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot envelope is invalid",{snapshotPath:t});let i=e,n=Ci(i),o=Xt(n);if(i.checksum.value!==o)throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot checksum does not match its payload",{snapshotPath:t});return new J({initialState:i.state}),structuredClone(i)}function Ti(e){return{...structuredClone(e),checksum:{algorithm:"sha256",value:Xt(e)}}}function Ci(e){return{schemaVersion:e.schemaVersion,generation:e.generation,createdAt:e.createdAt,updatedAt:e.updatedAt,state:e.state}}function Xt(e){return k(JSON.stringify(e)).value}async function Rt(e,t){await(0,S.mkdir)((0,N.dirname)(e),{recursive:!0,mode:448});let i=`${e}.tmp.${process.pid}.${(0,Fe.randomUUID)()}`,n;try{n=await(0,S.open)(i,"wx",384),await n.writeFile(t,{encoding:"utf8"}),await n.sync(),await n.close(),n=void 0,await(0,S.rename)(i,e);try{let o=await(0,S.open)((0,N.dirname)(e),"r");try{await o.sync()}finally{await o.close()}}catch{}}finally{n&&await n.close().catch(()=>{}),await(0,S.unlink)(i).catch(()=>{})}}function $e(e,t,i,n,o){if(e===void 0)return t;if(!Number.isInteger(e)||e<i||e>n)throw new TypeError(`${o} must be an integer between ${i} and ${n}`);return e}function Ve(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function De(e,t){return e instanceof Error&&e.code===t}async function Ni(e){try{return(await(0,S.stat)(e)).isFile()}catch(t){if(De(t,"ENOENT"))return!1;throw Oe("Unable to inspect artifact repository backup",e,t)}}function ge(e){return e instanceof Error?e:new Error(String(e))}function Oe(e,t,i,n=!1){return new u(n?"ARTIFACT_PERSISTENCE_CORRUPT":"ARTIFACT_PERSISTENCE_IO",`${e}: ${ge(i).message}`,{snapshotPath:t},{cause:ge(i)})}function $i(e){return new Promise(t=>setTimeout(t,e))}var Me=require("node:buffer");var Vi=16*1024*1024,Pi=5e3,Di=1e5,Oi=1e6,Fi=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?:\s?(.*))?$/,E=class extends Error{constructor(i,n){super(n===void 0?i:`${i} at diff line ${n}`);this.line=n;this.name="XenoDiffParseError"}line;code="XENO_DIFF_INVALID"};function He(e,t={}){if(typeof e!="string")throw new TypeError("Unified diff must be a string");let i=ye(t.maxBytes,Vi,1024,256*1024*1024,"maxBytes"),n=ye(t.maxFiles,Pi,1,1e5,"maxFiles"),o=ye(t.maxHunks,Di,1,1e6,"maxHunks"),r=ye(t.maxLines,Oi,1,5e6,"maxLines");if(Me.Buffer.byteLength(e,"utf8")>i)throw new E(`Unified diff exceeds ${i} bytes`);let a=e.replace(/\r\n/g,`
|
|
5
5
|
`).replace(/\r/g,`
|
package/dist/artifacts/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var h=1,re=1;import{Buffer as Oe}from"node:buffer";import{createHash as Mt}from"node:crypto";function _(e){return{algorithm:"sha256",value:Mt("sha256").update(e).digest("hex")}}function b(e){return JSON.stringify(Ae(e,new Set))}function k(e){return _(b(e))}function Ae(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(o=>Ae(o,t));return t.delete(e),n}let i={};for(let n of Object.keys(e).sort((o,r)=>o.localeCompare(r))){let o=e[n];if(o===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);i[n]=Ae(o,t)}return t.delete(e),i}var L=class extends Error{code="ARTIFACT_INVALID";issues;constructor(t,i){super(t),this.name="XenoArtifactValidationError",this.issues=i.map(n=>({...n}))}},Ie=class extends Error{constructor(i,n){super(`Artifact state cannot transition from ${i} to ${n}`);this.fromState=i;this.toState=n;this.name="XenoArtifactStateTransitionError"}fromState;toState;code="ARTIFACT_STATE_TRANSITION_INVALID"},Ht={draft:["pending_review","superseded","archived"],pending_review:["approved","rejected","superseded","archived"],approved:["superseded","archived"],rejected:["superseded","archived"],superseded:["archived"],archived:[]},jt=/^[a-z0-9][a-z0-9._/-]{0,127}$/,qt="[\\u0000-\\u001f\\u007f]",Jt=new RegExp(qt),Fe=/^[a-f0-9]{64}$/,Bt=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Ut=new Set(["draft","pending_review","approved","rejected","superseded","archived"]),zt=new Set(["public","internal","confidential","restricted"]),Wt=new Set(["agent","tool","user","system","integration"]),Gt=new Set(["plan","requirements","design","task-graph","patch","diff","file","document","diagram","screenshot","recording","browser-snapshot","test-report","review-report","security-report","performance-report","release-report","sbom","provenance","attestation"]),Kt=new Set(["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"]),Yt=new Set(["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"]);function p(e,t,i,n){e.push({path:t,code:i,message:n})}function l(e,t,i,n=1024){return typeof e!="string"||e.trim().length===0?(p(i,t,"required_string","Value must be a non-empty string"),!1):(e.length>n&&p(i,t,"string_too_long",`Value must not exceed ${n} characters`),Jt.test(e)&&p(i,t,"control_character","Value must not contain control characters"),!0)}function J(e,t,i){e!==void 0&&(!Number.isFinite(Date.parse(e))||!e.includes("T"))&&p(i,t,"invalid_timestamp","Value must be an ISO 8601 timestamp")}function P(e,t,i,n){if(typeof e!="string"||!e.startsWith(t))return;let o=e.slice(t.length);jt.test(o)||p(n,i,"invalid_custom_name",`Custom name after ${t} is invalid`)}function Le(e,t,i){if(!e||typeof e!="object"){p(i,t,"missing_actor","Actor is required");return}l(e.kind,`${t}.kind`,i,64),Wt.has(e.kind)||p(i,`${t}.kind`,"unknown_actor_kind","Actor kind is not supported"),l(e.id,`${t}.id`,i,512),e?.displayName!==void 0&&l(e.displayName,`${t}.displayName`,i,512),e?.profileFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(e.profileFingerprint)&&p(i,`${t}.profileFingerprint`,"invalid_fingerprint","Profile fingerprint must be 64 lowercase hexadecimal characters")}function we(e,t,i){if(!e||typeof e!="object"){p(i,t,"invalid_anchor","Anchor must be an object");return}switch(e.kind){case"file":l(e.path,`${t}.path`,i,4096);break;case"source-line":l(e.path,`${t}.path`,i,4096),(!Number.isInteger(e.startLine)||e.startLine<1)&&p(i,`${t}.startLine`,"invalid_line","startLine must be a positive integer"),e.endLine!==void 0&&(!Number.isInteger(e.endLine)||e.endLine<e.startLine)&&p(i,`${t}.endLine`,"invalid_line_range","endLine must be greater than or equal to startLine");break;case"diff-hunk":l(e.path,`${t}.path`,i,4096),l(e.hunkId,`${t}.hunkId`,i,512);break;case"symbol":l(e.path,`${t}.path`,i,4096),l(e.symbol,`${t}.symbol`,i,1024);break;case"dom-node":l(e.pageId,`${t}.pageId`,i,512),!e.selector&&!e.accessibilityId&&!e.snapshotArtifactId&&p(i,t,"missing_dom_locator","DOM anchors require a selector, accessibility ID, or snapshot artifact ID");break;case"timeline":l(e.recordingArtifactId,`${t}.recordingArtifactId`,i,512),(!Number.isFinite(e.startMs)||e.startMs<0)&&p(i,`${t}.startMs`,"invalid_time","startMs must be a non-negative finite number"),e.endMs!==void 0&&(!Number.isFinite(e.endMs)||e.endMs<e.startMs)&&p(i,`${t}.endMs`,"invalid_time_range","endMs must be greater than or equal to startMs");break;case"region":l(e.mediaArtifactId,`${t}.mediaArtifactId`,i,512),[e.x,e.y,e.width,e.height].every(Number.isFinite)?(e.width<=0||e.height<=0)&&p(i,t,"invalid_region_size","Region width and height must be positive"):p(i,t,"invalid_region","Region coordinates must be finite numbers");break;case"artifact":l(e.artifactId,`${t}.artifactId`,i,512);break;default:typeof e.kind!="string"||!e.kind.startsWith("custom:")?p(i,`${t}.kind`,"unknown_anchor","Anchor kind is not supported"):P(e.kind,"custom:",`${t}.kind`,i)}}function B(e,t,i,n){if(!(e===null||typeof e=="string"||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||p(i,t,"non_finite_number","JSON numbers must be finite");return}if(typeof e!="object"){p(i,t,"non_json_value","Value must be JSON-serializable");return}if(n.has(e)){p(i,t,"cyclic_value","Value must not contain cycles");return}if(n.add(e),Array.isArray(e))e.forEach((o,r)=>B(o,`${t}[${r}]`,i,n));else for(let[o,r]of Object.entries(e))r===void 0?p(i,`${t}.${o}`,"undefined_value","Undefined is not valid JSON"):B(r,`${t}.${o}`,i,n);n.delete(e)}}function Zt(e){let t=[];if(!e||typeof e!="object")return[{path:"$",code:"invalid_artifact",message:"Artifact must be an object"}];if(e.schemaVersion!==1&&p(t,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),l(e.artifactId,"artifactId",t,512),(!Number.isInteger(e.revision)||e.revision<1)&&p(t,"revision","invalid_revision","revision must be a positive integer"),l(e.kind,"kind",t,160),typeof e.kind=="string"&&!Gt.has(e.kind)&&!e.kind.startsWith("custom:")&&p(t,"kind","unknown_artifact_kind","Artifact kind is not supported"),P(e.kind,"custom:","kind",t),l(e.title,"title",t,1024),e.description!==void 0&&l(e.description,"description",t,32768),l(e.state,"state",t,64),Ut.has(e.state)||p(t,"state","unknown_state","Artifact state is not supported"),l(e.createdAt,"createdAt",t,128),J(e.createdAt,"createdAt",t),J(e.updatedAt,"updatedAt",t),e.updatedAt&&Number.isFinite(Date.parse(e.createdAt))&&Date.parse(e.updatedAt)<Date.parse(e.createdAt)&&p(t,"updatedAt","timestamp_order","updatedAt must not precede createdAt"),l(e.mediaType,"mediaType",t,255),l(e.sensitivity,"sensitivity",t,64),zt.has(e.sensitivity)||p(t,"sensitivity","unknown_sensitivity","Sensitivity is not supported"),e.identity)for(let[n,o]of Object.entries(e.identity))o!==void 0&&l(o,`identity.${n}`,t,512);if(!e.content||typeof e.content!="object")p(t,"content","missing_content","content descriptor is required");else{!e.content.hash||typeof e.content.hash!="object"?p(t,"content.hash","missing_hash","content hash is required"):(l(e.content.hash.algorithm,"content.hash.algorithm",t,128),P(e.content.hash.algorithm,"custom:","content.hash.algorithm",t),typeof e.content.hash.algorithm=="string"&&e.content.hash.algorithm!=="sha256"&&!e.content.hash.algorithm.startsWith("custom:")&&p(t,"content.hash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported"),l(e.content.hash.value,"content.hash.value",t,512),e.content.hash.algorithm==="sha256"&&!Fe.test(e.content.hash.value)&&p(t,"content.hash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters")),(!Number.isSafeInteger(e.content.sizeBytes)||e.content.sizeBytes<0)&&p(t,"content.sizeBytes","invalid_size","sizeBytes must be a non-negative safe integer");let n=e.content.storage;if(!n||typeof n!="object")p(t,"content.storage","missing_storage","storage reference is required");else if(n.type==="inline")if(n.text===void 0==(n.base64===void 0))p(t,"content.storage","invalid_inline_storage","Inline storage requires exactly one of text or base64");else{let o;n.text!==void 0?o=Oe.from(n.text,"utf8"):n.base64!==void 0&&(Bt.test(n.base64)?o=Oe.from(n.base64,"base64"):p(t,"content.storage.base64","invalid_base64","Inline base64 content is malformed")),o&&e.content.sizeBytes!==o.byteLength&&p(t,"content.sizeBytes","content_size_mismatch","sizeBytes does not match inline content"),o&&e.content.hash.algorithm==="sha256"&&_(o).value!==e.content.hash.value&&p(t,"content.hash.value","content_hash_mismatch","Hash does not match inline content")}else n.type==="file"?l(n.path,"content.storage.path",t,4096):n.type==="blob"?l(n.uri,"content.storage.uri",t,8192):n.type==="git"?(l(n.commit,"content.storage.commit",t,512),l(n.path,"content.storage.path",t,4096)):n.type==="url"?(l(n.url,"content.storage.url",t,8192),J(n.expiresAt,"content.storage.expiresAt",t)):n.type==="external"?(l(n.provider,"content.storage.provider",t,255),l(n.locator,"content.storage.locator",t,8192)):p(t,"content.storage.type","unknown_storage","Storage type is not supported");e.content.encoding!==void 0&&(typeof e.content.encoding!="string"||e.content.encoding!=="utf8"&&e.content.encoding!=="base64"&&e.content.encoding!=="binary"&&!e.content.encoding.startsWith("custom:"))&&p(t,"content.encoding","unknown_encoding","Content encoding is not supported"),P(e.content.encoding,"custom:","content.encoding",t)}!e.provenance||typeof e.provenance!="object"?p(t,"provenance","missing_provenance","provenance is required"):(Le(e.provenance.producer,"provenance.producer",t),e.provenance.capabilityLeaseIds?.forEach((n,o)=>l(n,`provenance.capabilityLeaseIds[${o}]`,t,512)),e.provenance.sourceArtifactIds?.forEach((n,o)=>l(n,`provenance.sourceArtifactIds[${o}]`,t,512)),e.provenance.attributes&&B(e.provenance.attributes,"provenance.attributes",t,new Set));let i=new Set;return e.relationships?.forEach((n,o)=>{let r=`relationships[${o}]`;l(n.relation,`${r}.relation`,t,160),typeof n.relation=="string"&&!Yt.has(n.relation)&&!n.relation.startsWith("custom:")&&p(t,`${r}.relation`,"unknown_relationship","Relationship type is not supported"),P(n.relation,"custom:",`${r}.relation`,t),l(n.target?.type,`${r}.target.type`,t,160),typeof n.target?.type=="string"&&!Kt.has(n.target.type)&&!n.target.type.startsWith("custom:")&&p(t,`${r}.target.type`,"unknown_reference_type","Evidence reference type is not supported"),P(n.target?.type,"custom:",`${r}.target.type`,t),l(n.target?.id,`${r}.target.id`,t,512);let a=`${n.relation}:${n.target?.type}:${n.target?.id}:${n.target?.revision??""}`;i.has(a)&&p(t,r,"duplicate_relationship","Duplicate relationship"),i.add(a),n.attributes&&B(n.attributes,`${r}.attributes`,t,new Set)}),e.anchors?.forEach((n,o)=>we(n,`anchors[${o}]`,t)),e.revision===1&&e.predecessorRevision!==void 0&&p(t,"predecessorRevision","unexpected_predecessor","First revision cannot have a predecessor"),e.revision>1&&(!Number.isInteger(e.predecessorRevision)||(e.predecessorRevision??0)>=e.revision)&&p(t,"predecessorRevision","invalid_predecessor","Later revisions require an earlier predecessor revision"),J(e.retention?.retainUntil,"retention.retainUntil",t),e.retention?.legalHold!==void 0&&typeof e.retention.legalHold!="boolean"&&p(t,"retention.legalHold","invalid_boolean","legalHold must be a boolean"),e.extensions&&B(e.extensions,"extensions",t,new Set),t}function w(e){let t=Zt(e);if(t.length>0)throw new L("XENO artifact validation failed",t)}function Qt(e,t){return Ht[e].includes(t)}function oe(e,t){if(!Qt(e,t))throw new Ie(e,t)}function Re(e,t){let i=[];return e.schemaVersion!==1&&p(i,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),l(e.eventId,"eventId",i,512),l(e.artifactId,"artifactId",i,512),(!Number.isInteger(e.artifactRevision)||e.artifactRevision<1)&&p(i,"artifactRevision","invalid_revision","artifactRevision must be a positive integer"),(!Number.isInteger(e.sequence)||e.sequence<1)&&p(i,"sequence","invalid_sequence","sequence must be a positive integer"),l(e.recordedAt,"recordedAt",i,128),J(e.recordedAt,"recordedAt",i),Le(e.actor,"actor",i),!e.artifactHash||typeof e.artifactHash!="object"?p(i,"artifactHash","missing_hash","Artifact hash is required"):(l(e.artifactHash.algorithm,"artifactHash.algorithm",i,128),P(e.artifactHash.algorithm,"custom:","artifactHash.algorithm",i),l(e.artifactHash.value,"artifactHash.value",i,512),e.artifactHash.algorithm==="sha256"&&!Fe.test(e.artifactHash.value)&&p(i,"artifactHash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters"),typeof e.artifactHash.algorithm=="string"&&e.artifactHash.algorithm!=="sha256"&&!e.artifactHash.algorithm.startsWith("custom:")&&p(i,"artifactHash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported")),["review-requested","comment-added","comment-resolved","comment-reopened","decision-recorded","review-withdrawn"].includes(e.type)||p(i,"type","unknown_review_event","Review event type is not supported"),e.type==="comment-added"?(l(e.commentId,"commentId",i,512),l(e.body,"body",i,65536),e.anchor&&we(e.anchor,"anchor",i)):e.type==="comment-resolved"||e.type==="comment-reopened"?l(e.commentId,"commentId",i,512):e.type==="decision-recorded"&&(["approved","rejected","changes_requested"].includes(e.decision)||p(i,"decision","unknown_review_decision","Review decision is not supported"),e.scope&&we(e.scope,"scope",i)),t&&(e.artifactId!==t.artifactId&&p(i,"artifactId","artifact_mismatch","Review event targets a different artifact"),e.artifactRevision!==t.revision&&p(i,"artifactRevision","revision_mismatch","Review event targets a different revision"),e.artifactHash&&(e.artifactHash.algorithm!==t.content.hash.algorithm||e.artifactHash.value!==t.content.hash.value)&&p(i,"artifactHash","hash_mismatch","Review event hash does not match the artifact revision")),i}function Xe(e){let t="not_requested",i,n,o,r=0,a=new Set,c=new Set;for(let s of[...e].sort((d,f)=>d.sequence-f.sequence))o=s.recordedAt,s.type==="review-requested"?t="pending":s.type==="review-withdrawn"?t="withdrawn":s.type==="comment-added"?(a.add(s.commentId),c.delete(s.commentId),t==="not_requested"&&(t="pending")):s.type==="comment-resolved"?c.add(s.commentId):s.type==="comment-reopened"?c.delete(s.commentId):s.type==="decision-recorded"&&(s.scope?r+=1:(i=s.decision,n=s.eventId,t=s.decision));return{status:t,totalComments:a.size,unresolvedComments:[...a].filter(s=>!c.has(s)).length,...i?{latestDecision:i}:{},...n?{latestDecisionEventId:n}:{},...r>0?{scopedDecisionCount:r}:{},...o?{lastReviewedAt:o}:{}}}var Ee=class extends Error{code="EVIDENCE_GRAPH_INVALID";issues;constructor(t){super("XENO evidence graph validation failed"),this.name="XenoEvidenceGraphValidationError",this.issues=t.map(i=>({...i}))}},ei=new Set(["depends_on","decomposes","supersedes"]),ti=/^[a-z0-9][a-z0-9._/-]{0,127}$/,ii=new Set(["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"]),ni=new Set(["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"]);function y(e,t,i,n){e.push({path:t,code:i,message:n})}function U(e){return e.includes("T")&&Number.isFinite(Date.parse(e))}function Me(e,t){return e.startsWith("custom:")?ti.test(e.slice(7)):t.has(e)}function ri(e){let t=[];if(!e||typeof e!="object")return[{path:"$",code:"invalid_graph",message:"Evidence graph must be an object"}];e.schemaVersion!==1&&y(t,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),(typeof e.graphId!="string"||e.graphId.trim().length===0)&&y(t,"graphId","required_string","graphId must be a non-empty string"),(!Number.isInteger(e.version)||e.version<1)&&y(t,"version","invalid_version","version must be a positive integer"),U(e.createdAt)||y(t,"createdAt","invalid_timestamp","createdAt must be an ISO 8601 timestamp"),U(e.updatedAt)||y(t,"updatedAt","invalid_timestamp","updatedAt must be an ISO 8601 timestamp"),U(e.createdAt)&&U(e.updatedAt)&&Date.parse(e.updatedAt)<Date.parse(e.createdAt)&&y(t,"updatedAt","timestamp_order","updatedAt must not precede createdAt");let i=new Map;Array.isArray(e.nodes)||y(t,"nodes","invalid_nodes","nodes must be an array"),(Array.isArray(e.nodes)?e.nodes:[]).forEach((f,g)=>{let I=`nodes[${g}]`;typeof f.id!="string"||f.id.trim().length===0?y(t,`${I}.id`,"required_string","Node ID must be a non-empty string"):i.has(f.id)?y(t,`${I}.id`,"duplicate_node",`Node ID ${f.id} is duplicated`):i.set(f.id,f),(typeof f.type!="string"||!Me(f.type,ii))&&y(t,`${I}.type`,"invalid_node_type","Node type is invalid"),f.artifactRevision!==void 0&&(!Number.isInteger(f.artifactRevision)||f.artifactRevision<1)&&y(t,`${I}.artifactRevision`,"invalid_revision","artifactRevision must be a positive integer")});let n=new Set,o=new Set;Array.isArray(e.edges)||y(t,"edges","invalid_edges","edges must be an array"),(Array.isArray(e.edges)?e.edges:[]).forEach((f,g)=>{let I=`edges[${g}]`;typeof f.id!="string"||f.id.trim().length===0?y(t,`${I}.id`,"required_string","Edge ID must be a non-empty string"):n.has(f.id)&&y(t,`${I}.id`,"duplicate_edge",`Edge ID ${f.id} is duplicated`),n.add(f.id),(typeof f.type!="string"||!Me(f.type,ni))&&y(t,`${I}.type`,"invalid_edge_type","Edge type is invalid");let $=`${f.type}:${f.from}:${f.to}`;o.has($)&&y(t,I,"duplicate_edge_identity","Equivalent evidence edge is duplicated"),o.add($),i.has(f.from)||y(t,`${I}.from`,"dangling_reference",`Source node ${f.from} does not exist`),i.has(f.to)||y(t,`${I}.to`,"dangling_reference",`Target node ${f.to} does not exist`),f.from===f.to&&y(t,I,"self_edge","Evidence edges cannot point to the same node"),U(f.createdAt)||y(t,`${I}.createdAt`,"invalid_timestamp","createdAt must be an ISO 8601 timestamp")});let r=(Array.isArray(e.edges)?e.edges:[]).filter(f=>ei.has(f.type)),a=new Map;for(let f of r){let g=a.get(f.from)??[];g.push(f.to),a.set(f.from,g)}let c=new Set,s=new Set,d=f=>{if(c.has(f))return!0;if(s.has(f))return!1;c.add(f);for(let g of a.get(f)??[])if(d(g))return!0;return c.delete(f),s.add(f),!1};for(let f of i.keys())if(d(f)){y(t,"edges","cyclic_graph","Dependency, decomposition, and supersession edges must be acyclic");break}return t}function z(e){let t=ri(e);if(t.length>0)throw new Ee(t)}var He=class{now;graph;constructor(t){if("schemaVersion"in t)z(t),this.now=()=>new Date().toISOString(),this.graph=se(t);else{this.now=t.now??(()=>new Date().toISOString());let i=this.now();this.graph={schemaVersion:1,graphId:t.graphId,version:1,createdAt:i,updatedAt:i,nodes:[],edges:[]},z(this.graph)}}addNode(t){let i=se(this.graph);return i.nodes.push(je(t)),this.touch(i),z(i),this.graph=i,this}addEdge(t){let i=se(this.graph);return i.edges.push(qe(t)),this.touch(i),z(i),this.graph=i,this}build(){return z(this.graph),se(this.graph)}touch(t){t.version+=1,t.updatedAt=this.now()}};function je(e){return{...e,...e.attributes?{attributes:structuredClone(e.attributes)}:{}}}function qe(e){return{...e,...e.producer?{producer:{...e.producer}}:{},...e.attributes?{attributes:structuredClone(e.attributes)}:{}}}function se(e){return{...e,nodes:e.nodes.map(je),edges:e.edges.map(qe)}}var u=class extends Error{constructor(i,n,o,r){super(n,r);this.code=i;this.detail=o;this.name="XenoArtifactRepositoryError"}code;detail},G=class{records=new Map;currentRevisions=new Map;now;idFactory;eventIds=new Set;idCounter=0;constructor(t={}){this.now=t.now??(()=>new Date().toISOString()),this.idFactory=t.idFactory??(i=>(this.idCounter+=1,`${i}_${Date.now().toString(36)}_${this.idCounter.toString(36)}`)),t.initialState&&this.hydrate(t.initialState)}exportState(){let t=[...this.records.values()].flatMap(i=>[...i.values()]).sort(Je).map(i=>({artifact:W(i.artifact),recordVersion:i.recordVersion,lifecycleEvents:structuredClone(i.lifecycleEvents),reviewEvents:structuredClone(i.reviewEvents)}));return{schemaVersion:1,records:t}}async create(t){if(w(t),this.assertInitialState(t),t.revision!==1)throw new u("ARTIFACT_REVISION_INVALID","A new artifact must begin at revision 1",{artifactId:t.artifactId,revision:t.revision});if(this.records.has(t.artifactId))throw new u("ARTIFACT_ALREADY_EXISTS",`Artifact ${t.artifactId} already exists`,{artifactId:t.artifactId});let i=W(t),n=this.createLifecycleEvent({artifact:i,sequence:1,actor:i.provenance.producer,fromState:null,toState:i.state,reason:"artifact-created"}),o={artifact:i,recordVersion:1,lifecycleEvents:[n],reviewEvents:[]};return this.records.set(i.artifactId,new Map([[i.revision,o]])),this.currentRevisions.set(i.artifactId,i.revision),D(o)}async createRevision(t,i={}){w(t),this.assertInitialState(t);let n=this.getMutable(t.artifactId);this.assertVersion(n,i.expectedRecordVersion);let o=n.artifact.revision+1;if(t.revision!==o||t.predecessorRevision!==n.artifact.revision)throw new u("ARTIFACT_REVISION_INVALID",`Revision ${t.revision} does not follow current revision ${n.artifact.revision}`,{artifactId:t.artifactId,currentRevision:n.artifact.revision,requestedRevision:t.revision});if(si(t,n.artifact))throw new u("ARTIFACT_CONTENT_UNCHANGED","A new artifact revision must have a different content hash",{artifactId:t.artifactId,revision:t.revision});if(n.artifact.state==="archived")throw new u("ARTIFACT_REVISION_INVALID","Archived artifacts cannot receive new revisions",{artifactId:t.artifactId,revision:n.artifact.revision});if(n.artifact.state!=="superseded"){oe(n.artifact.state,"superseded");let s=this.now(),d=this.createLifecycleEvent({artifact:n.artifact,sequence:n.lifecycleEvents.length+1,actor:i.actor??t.provenance.producer,fromState:n.artifact.state,toState:"superseded",reason:i.reason??`superseded-by-revision-${t.revision}`,recordedAt:s});n.artifact.state="superseded",n.artifact.updatedAt=s,n.lifecycleEvents.push(d),n.recordVersion+=1}let r=W(t),a=this.createLifecycleEvent({artifact:r,sequence:1,actor:i.actor??r.provenance.producer,fromState:null,toState:r.state,reason:i.reason??`revision-created-from-${n.artifact.revision}`}),c={artifact:r,recordVersion:1,lifecycleEvents:[a],reviewEvents:[]};return this.records.get(r.artifactId)?.set(r.revision,c),this.currentRevisions.set(r.artifactId,r.revision),D(c)}async get(t,i){let n=this.records.get(t);if(!n)return;let o=i??this.currentRevisions.get(t);if(o===void 0)return;let r=n.get(o);return r?D(r):void 0}async require(t,i){let n=await this.get(t,i);if(!n)throw new u("ARTIFACT_NOT_FOUND",`Artifact ${t}${i===void 0?"":` revision ${i}`} was not found`,{artifactId:t,...i===void 0?{}:{revision:i}});return n}async list(t={}){let i=[];for(let[n,o]of this.records)if(!(t.artifactIds&&!t.artifactIds.includes(n)))if(t.includeSuperseded)i.push(...o.values());else{let r=this.currentRevisions.get(n);if(r!==void 0){let a=o.get(r);a&&i.push(a)}}return i.filter(n=>ai(n.artifact,t)).sort(Je).map(D)}async listRevisions(t){let i=this.records.get(t);return i?[...i.values()].sort((n,o)=>n.artifact.revision-o.artifact.revision).map(D):[]}async transition(t){let i=this.getMutable(t.artifactId,t.revision);if(this.assertVersion(i,t.expectedRecordVersion),oe(i.artifact.state,t.toState),t.toState==="approved"||t.toState==="rejected"){let a=t.reviewEventId?i.reviewEvents.find(s=>s.eventId===t.reviewEventId&&s.type==="decision-recorded"):void 0,c=Xe(i.reviewEvents);if(!a||a.decision!==t.toState||c.latestDecisionEventId!==a.eventId)throw new u("ARTIFACT_REVIEW_DECISION_REQUIRED",`Transition to ${t.toState} requires a matching decision event`,{artifactId:t.artifactId,revision:i.artifact.revision});if(t.toState==="approved"&&c.unresolvedComments>0)throw new u("ARTIFACT_UNRESOLVED_COMMENTS",`Artifact has ${c.unresolvedComments} unresolved review comment(s)`,{artifactId:t.artifactId,revision:i.artifact.revision,unresolvedComments:c.unresolvedComments})}let n=this.now(),o=i.artifact.state,r=this.createLifecycleEvent({artifact:i.artifact,sequence:i.lifecycleEvents.length+1,actor:t.actor,fromState:o,toState:t.toState,reason:t.reason,reviewEventId:t.reviewEventId,recordedAt:n});return i.artifact.state=t.toState,i.artifact.updatedAt=n,i.lifecycleEvents.push(r),i.recordVersion+=1,D(i)}async appendReviewEvent(t){let i=t.event,n=this.getMutable(i.artifactId,i.artifactRevision);if(this.assertVersion(n,t.expectedRecordVersion),n.artifact.state==="archived"||n.artifact.state==="superseded")throw new u("ARTIFACT_REVIEW_INVALID",`Cannot append review events to a ${n.artifact.state} artifact revision`,{artifactId:i.artifactId,revision:i.artifactRevision});if(this.assertReviewCommentState(n,i),(i.type==="review-requested"||i.type==="review-withdrawn"||i.type==="decision-recorded")&&n.artifact.state!=="pending_review")throw new u("ARTIFACT_REVIEW_INVALID",`${i.type} requires an artifact in pending_review state`,{artifactId:i.artifactId,revision:i.artifactRevision});let o={...structuredClone(i),schemaVersion:1,eventId:this.nextEventId("review_event"),sequence:n.reviewEvents.length+1,recordedAt:this.now()},r=Re(o,n.artifact);if(r.length>0)throw new L("XENO artifact review event validation failed",r);return n.reviewEvents.push(o),n.recordVersion+=1,D(n)}getMutable(t,i){let n=this.records.get(t),o=i??this.currentRevisions.get(t),r=o===void 0?void 0:n?.get(o);if(!r)throw new u("ARTIFACT_NOT_FOUND",`Artifact ${t}${i===void 0?"":` revision ${i}`} was not found`,{artifactId:t,...i===void 0?{}:{revision:i}});return r}assertVersion(t,i){if(i!==void 0&&i!==t.recordVersion)throw new u("ARTIFACT_CONFLICT",`Expected record version ${i}, found ${t.recordVersion}`,{artifactId:t.artifact.artifactId,revision:t.artifact.revision,expectedRecordVersion:i,actualRecordVersion:t.recordVersion})}assertInitialState(t){if(t.state!=="draft"&&t.state!=="pending_review")throw new u("ARTIFACT_REVISION_INVALID","New artifact revisions must begin in draft or pending_review state",{artifactId:t.artifactId,revision:t.revision})}assertReviewCommentState(t,i){if(i.type==="comment-added"){if(t.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===i.commentId))throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${i.commentId} already exists`);if(i.parentCommentId&&!t.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===i.parentCommentId))throw new u("ARTIFACT_REVIEW_INVALID",`Parent comment ${i.parentCommentId} does not exist`);return}if(i.type!=="comment-resolved"&&i.type!=="comment-reopened")return;if(!t.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===i.commentId))throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${i.commentId} does not exist`);let o=ci(t.reviewEvents,i.commentId);if(i.type==="comment-resolved"&&o.resolved)throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${i.commentId} is already resolved`);if(i.type==="comment-reopened"&&!o.resolved)throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${i.commentId} is not resolved`)}createLifecycleEvent(t){return{schemaVersion:1,eventId:this.nextEventId("artifact_event"),artifactId:t.artifact.artifactId,revision:t.artifact.revision,sequence:t.sequence,recordedAt:t.recordedAt??this.now(),actor:{...t.actor},fromState:t.fromState,toState:t.toState,...t.reason?{reason:t.reason}:{},...t.reviewEventId?{reviewEventId:t.reviewEventId}:{}}}nextEventId(t){let i=this.idFactory(t);if(typeof i!="string"||i.trim().length===0||this.eventIds.has(i))throw new u("ARTIFACT_CONFLICT",`Event ID factory produced an invalid or duplicate ${t} ID`);return this.eventIds.add(i),i}hydrate(t){if(t.schemaVersion!==1||!Array.isArray(t.records))throw new u("ARTIFACT_REVISION_INVALID","Artifact repository state has an unsupported schema or record collection");let i=[...t.records].sort((n,o)=>n.artifact.artifactId.localeCompare(o.artifact.artifactId)||n.artifact.revision-o.artifact.revision);for(let n of i){let o=oi(n,this.eventIds),r=this.records.get(o.artifact.artifactId);if(r||(r=new Map,this.records.set(o.artifact.artifactId,r)),r.has(o.artifact.revision))throw new u("ARTIFACT_REVISION_INVALID",`Duplicate persisted revision ${o.artifact.artifactId}:${o.artifact.revision}`);r.set(o.artifact.revision,o),this.currentRevisions.set(o.artifact.artifactId,o.artifact.revision)}for(let[n,o]of this.records){let r=[...o.values()].sort((a,c)=>a.artifact.revision-c.artifact.revision);for(let a=0;a<r.length;a+=1){let c=r[a],s=a+1;if(c.artifact.revision!==s)throw new u("ARTIFACT_REVISION_INVALID",`Persisted artifact ${n} is missing revision ${s}`);if(a===0&&c.artifact.predecessorRevision!==void 0)throw new u("ARTIFACT_REVISION_INVALID",`Initial revision for ${n} cannot declare a predecessor`);if(a>0&&c.artifact.predecessorRevision!==s-1)throw new u("ARTIFACT_REVISION_INVALID",`Persisted revision ${n}:${s} has an invalid predecessor`);if(a<r.length-1&&c.artifact.state!=="superseded")throw new u("ARTIFACT_REVISION_INVALID",`Non-current revision ${n}:${s} must be superseded`)}}}};function oi(e,t){if(w(e.artifact),!Number.isInteger(e.recordVersion)||e.recordVersion<1)throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact recordVersion must be a positive integer",{artifactId:e.artifact.artifactId,revision:e.artifact.revision});if(!Array.isArray(e.lifecycleEvents)||e.lifecycleEvents.length===0||!Array.isArray(e.reviewEvents))throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact records require lifecycle and review event arrays",{artifactId:e.artifact.artifactId,revision:e.artifact.revision});let i=e.lifecycleEvents.length+e.reviewEvents.length;if(e.recordVersion!==i)throw new u("ARTIFACT_REVISION_INVALID",`Persisted record version ${e.recordVersion} does not match ${i} mutations`,{artifactId:e.artifact.artifactId,revision:e.artifact.revision});let n=null;for(let r=0;r<e.lifecycleEvents.length;r+=1){let a=e.lifecycleEvents[r];if(a.schemaVersion!==1||a.artifactId!==e.artifact.artifactId||a.revision!==e.artifact.revision||a.sequence!==r+1||a.fromState!==n||typeof a.eventId!="string"||a.eventId.length===0||t.has(a.eventId)||!Number.isFinite(Date.parse(a.recordedAt)))throw new u("ARTIFACT_REVISION_INVALID",`Persisted lifecycle event ${r+1} is invalid`,{artifactId:e.artifact.artifactId,revision:e.artifact.revision});if(n===null){if(a.toState!=="draft"&&a.toState!=="pending_review")throw new u("ARTIFACT_REVISION_INVALID","A persisted artifact must begin in draft or pending_review state",{artifactId:e.artifact.artifactId,revision:e.artifact.revision})}else oe(n,a.toState);t.add(a.eventId),n=a.toState}if(n!==e.artifact.state)throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact state does not match its lifecycle tail",{artifactId:e.artifact.artifactId,revision:e.artifact.revision});let o=new Map;for(let r=0;r<e.reviewEvents.length;r+=1){let a=e.reviewEvents[r];if(a.sequence!==r+1||t.has(a.eventId))throw new u("ARTIFACT_REVIEW_INVALID",`Persisted review event ${r+1} has an invalid sequence or duplicate ID`,{artifactId:e.artifact.artifactId,revision:e.artifact.revision});let c=Re(a,e.artifact);if(c.length>0)throw new L("Persisted XENO artifact review event validation failed",c);if(a.type==="comment-added"){if(o.has(a.commentId)||a.parentCommentId!==void 0&&!o.has(a.parentCommentId))throw new u("ARTIFACT_REVIEW_INVALID",`Persisted comment ${a.commentId} has an invalid identity or parent`);o.set(a.commentId,!1)}else if(a.type==="comment-resolved"||a.type==="comment-reopened"){let s=o.get(a.commentId);if(s===void 0||a.type==="comment-resolved"&&s||a.type==="comment-reopened"&&!s)throw new u("ARTIFACT_REVIEW_INVALID",`Persisted comment transition for ${a.commentId} is invalid`);o.set(a.commentId,a.type==="comment-resolved")}t.add(a.eventId)}return{artifact:W(e.artifact),recordVersion:e.recordVersion,lifecycleEvents:structuredClone(e.lifecycleEvents),reviewEvents:structuredClone(e.reviewEvents)}}function si(e,t){return e.content.hash.algorithm===t.content.hash.algorithm&&e.content.hash.value===t.content.hash.value}function ai(e,t){return!(t.kinds&&!t.kinds.includes(e.kind)||t.states&&!t.states.includes(e.state)||t.runId&&e.identity?.runId!==t.runId||t.sessionId&&e.identity?.sessionId!==t.sessionId||t.turnId&&e.identity?.turnId!==t.turnId||t.taskId&&e.identity?.taskId!==t.taskId||t.workspaceId&&e.identity?.workspaceId!==t.workspaceId||t.repositoryId&&e.identity?.repositoryId!==t.repositoryId||t.producerId&&e.provenance.producer.id!==t.producerId||t.sensitivity&&!t.sensitivity.includes(e.sensitivity))}function Je(e,t){return e.artifact.createdAt.localeCompare(t.artifact.createdAt)||e.artifact.artifactId.localeCompare(t.artifact.artifactId)||e.artifact.revision-t.artifact.revision}function ci(e,t){let i=!1;for(let n of e)(n.type==="comment-resolved"||n.type==="comment-reopened")&&n.commentId===t&&(i=n.type==="comment-resolved");return{resolved:i}}function W(e){return structuredClone(e)}function D(e){return{artifact:W(e.artifact),recordVersion:e.recordVersion,etag:`${e.artifact.artifactId}:${e.artifact.revision}:${e.recordVersion}`,lifecycleEvents:structuredClone(e.lifecycleEvents),reviewEvents:structuredClone(e.reviewEvents),reviewSummary:Xe(e.reviewEvents)}}import{randomUUID as it}from"node:crypto";import{mkdir as nt,open as Ye,readFile as yi,rename as Ai,stat as rt,unlink as Ii}from"node:fs/promises";import{basename as Ze,dirname as Qe,join as wi,resolve as Ri}from"node:path";import{mkdirSync as di,readFileSync as fi,rmSync as Ue,writeFileSync as pi}from"node:fs";import{hostname as ze}from"node:os";import{dirname as ui}from"node:path";function li(){return new Date().toISOString()}function mi(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function We(e){try{return JSON.parse(fi(e,"utf8"))}catch{return null}}function vi(e){if(!e||e<=0)return!1;try{return process.kill(e,0),!0}catch{return!1}}function hi(e){return e.hostname!==ze()?!0:vi(e.pid)}function Be(e,t){di(ui(e),{recursive:!0}),pi(e,JSON.stringify(t,null,2)+`
|
|
2
|
-
`,{encoding:"utf8",flag:"wx"})}function gi(e,t){let i=We(e);i?.pid!==t.pid||i.hostname!==t.hostname||Ue(e,{force:!0})}function Ge(e,t,i){let n=li(),o={schemaVersion:1,name:t,pid:process.pid,hostname:ze(),processStartedAt:mi(),version:i,acquiredAt:n,updatedAt:n};try{Be(e,o)}catch(r){if(r.code!=="EEXIST")throw r;let c=We(e);if(c&&hi(c))throw new Error(`${t} is already locked by PID ${c.pid} on ${c.hostname}.`);Ue(e,{force:!0}),Be(e,o)}return{record:o,release:()=>{gi(e,o)}}}var Ke="0.8.
|
|
2
|
+
`,{encoding:"utf8",flag:"wx"})}function gi(e,t){let i=We(e);i?.pid!==t.pid||i.hostname!==t.hostname||Ue(e,{force:!0})}function Ge(e,t,i){let n=li(),o={schemaVersion:1,name:t,pid:process.pid,hostname:ze(),processStartedAt:mi(),version:i,acquiredAt:n,updatedAt:n};try{Be(e,o)}catch(r){if(r.code!=="EEXIST")throw r;let c=We(e);if(c&&hi(c))throw new Error(`${t} is already locked by PID ${c.pid} on ${c.hostname}.`);Ue(e,{force:!0}),Be(e,o)}return{record:o,release:()=>{gi(e,o)}}}var Ke="0.8.13";var ot=1,Xi="repository.v1.json",Ei=5e3,bi=20,Si=64*1024*1024,et=class{directory;snapshotPath;backupPath;lockPath;now;lockTimeoutMs;lockRetryMs;maxSnapshotBytes;onRecovery;mutationTail=Promise.resolve();constructor(t){if(!t||typeof t.directory!="string"||t.directory.trim().length===0)throw new TypeError("Artifact repository directory is required");let i=t.snapshotFileName??Xi;if(Ze(i)!==i||!/^[A-Za-z0-9_.-]+$/.test(i))throw new TypeError("Artifact snapshot filename must be a safe basename");this.directory=Ri(t.directory),this.snapshotPath=wi(this.directory,i),this.backupPath=`${this.snapshotPath}.bak`,this.lockPath=`${this.snapshotPath}.lock`,this.now=t.now??(()=>new Date().toISOString()),this.lockTimeoutMs=be(t.lockTimeoutMs,Ei,100,6e4,"lockTimeoutMs"),this.lockRetryMs=be(t.lockRetryMs,bi,1,1e3,"lockRetryMs"),this.maxSnapshotBytes=be(t.maxSnapshotBytes,Si,1024,1024*1024*1024,"maxSnapshotBytes"),this.onRecovery=t.onRecovery}async create(t){return this.mutate(i=>i.create(t))}async createRevision(t,i){return this.mutate(n=>n.createRevision(t,i))}async get(t,i){return(await this.load()).repository.get(t,i)}async require(t,i){return(await this.load()).repository.require(t,i)}async list(t){return(await this.load()).repository.list(t)}async listRevisions(t){return(await this.load()).repository.listRevisions(t)}async transition(t){return this.mutate(i=>i.transition(t))}async appendReviewEvent(t){return this.mutate(i=>i.appendReviewEvent(t))}async inspectSnapshot(){return this.readSnapshot(this.snapshotPath,!0)}async mutate(t){return this.enqueueMutation(async()=>{let i=await this.acquireLock();try{let n=await this.load(),o=await t(n.repository);return await this.persist(n),o}finally{i.release()}})}async enqueueMutation(t){let i=this.mutationTail.then(t,t);return this.mutationTail=i.then(()=>{},()=>{}),i}async acquireLock(){let t=Date.now(),i;for(;Date.now()-t<=this.lockTimeoutMs;)try{return Ge(this.lockPath,`artifact-repository:${Ze(this.snapshotPath)}`,Ke)}catch(n){if(!(n instanceof Error)||!/already locked by PID/.test(n.message))throw n;i=n,await Ci(this.lockRetryMs)}throw new u("ARTIFACT_PERSISTENCE_LOCKED",`Artifact repository remained locked for ${this.lockTimeoutMs}ms`,{snapshotPath:this.snapshotPath},{cause:i})}async load(){let t,i,n=!1;try{i=await this.readSnapshot(this.snapshotPath,!1)}catch(r){t=ae(r)}if(!i&&(t||await Ti(this.backupPath)))try{let r=await this.readSnapshot(this.backupPath,!0);r&&(this.onRecovery?.({snapshotPath:this.snapshotPath,backupPath:this.backupPath,reason:t?.message??"primary snapshot missing"}),i=r,n=!0)}catch(r){throw t?new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository primary and backup snapshots are unreadable",{snapshotPath:this.snapshotPath,backupPath:this.backupPath},{cause:new AggregateError([t,ae(r)])}):r}if(!i&&t)throw t;let o=i?.state??{schemaVersion:1,records:[]};return{repository:new G({now:this.now,idFactory:r=>`${r}_${it()}`,initialState:o}),generation:i?.generation??0,createdAt:i?.createdAt??this.now(),hasSnapshot:i!==void 0,recoveredFromBackup:n,...i?{sourceSnapshot:i}:{}}}async persist(t){let i=this.now(),o={...{schemaVersion:ot,generation:t.generation,createdAt:t.createdAt,updatedAt:i,state:t.repository.exportState()},generation:t.generation+1},r=ki(o),a=`${JSON.stringify(r,null,2)}
|
|
3
3
|
`;if(Buffer.byteLength(a,"utf8")>this.maxSnapshotBytes)throw new u("ARTIFACT_PERSISTENCE_IO",`Artifact repository snapshot exceeds ${this.maxSnapshotBytes} bytes`,{snapshotPath:this.snapshotPath,maxSnapshotBytes:this.maxSnapshotBytes});await nt(this.directory,{recursive:!0,mode:448}),t.hasSnapshot&&!t.recoveredFromBackup&&t.sourceSnapshot&&await tt(this.backupPath,`${JSON.stringify(t.sourceSnapshot,null,2)}
|
|
4
4
|
`),await tt(this.snapshotPath,a)}async readSnapshot(t,i){let n;try{n=await rt(t)}catch(o){if(!i&&_e(o,"ENOENT")||i&&_e(o,"ENOENT"))return;throw ke("Unable to inspect artifact repository snapshot",t,o)}if(!n.isFile()||n.size>this.maxSnapshotBytes)throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot is not a bounded regular file",{snapshotPath:t,sizeBytes:n.size,maxSnapshotBytes:this.maxSnapshotBytes});try{let o=await yi(t);if(o.byteLength>this.maxSnapshotBytes)throw new Error("snapshot grew beyond the configured size limit while reading");return _i(JSON.parse(o.toString("utf8")),t)}catch(o){throw o instanceof u?o:ke("Unable to parse artifact repository snapshot",t,o,!0)}}};function _i(e,t){if(!Se(e)||e.schemaVersion!==ot||!Number.isInteger(e.generation)||e.generation<0||typeof e.createdAt!="string"||!Number.isFinite(Date.parse(e.createdAt))||typeof e.updatedAt!="string"||!Number.isFinite(Date.parse(e.updatedAt))||!Se(e.state)||e.state.schemaVersion!==1||!Array.isArray(e.state.records)||!Se(e.checksum)||e.checksum.algorithm!=="sha256"||typeof e.checksum.value!="string")throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot envelope is invalid",{snapshotPath:t});let i=e,n=xi(i),o=st(n);if(i.checksum.value!==o)throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot checksum does not match its payload",{snapshotPath:t});return new G({initialState:i.state}),structuredClone(i)}function ki(e){return{...structuredClone(e),checksum:{algorithm:"sha256",value:st(e)}}}function xi(e){return{schemaVersion:e.schemaVersion,generation:e.generation,createdAt:e.createdAt,updatedAt:e.updatedAt,state:e.state}}function st(e){return _(JSON.stringify(e)).value}async function tt(e,t){await nt(Qe(e),{recursive:!0,mode:448});let i=`${e}.tmp.${process.pid}.${it()}`,n;try{n=await Ye(i,"wx",384),await n.writeFile(t,{encoding:"utf8"}),await n.sync(),await n.close(),n=void 0,await Ai(i,e);try{let o=await Ye(Qe(e),"r");try{await o.sync()}finally{await o.close()}}catch{}}finally{n&&await n.close().catch(()=>{}),await Ii(i).catch(()=>{})}}function be(e,t,i,n,o){if(e===void 0)return t;if(!Number.isInteger(e)||e<i||e>n)throw new TypeError(`${o} must be an integer between ${i} and ${n}`);return e}function Se(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function _e(e,t){return e instanceof Error&&e.code===t}async function Ti(e){try{return(await rt(e)).isFile()}catch(t){if(_e(t,"ENOENT"))return!1;throw ke("Unable to inspect artifact repository backup",e,t)}}function ae(e){return e instanceof Error?e:new Error(String(e))}function ke(e,t,i,n=!1){return new u(n?"ARTIFACT_PERSISTENCE_CORRUPT":"ARTIFACT_PERSISTENCE_IO",`${e}: ${ae(i).message}`,{snapshotPath:t},{cause:ae(i)})}function Ci(e){return new Promise(t=>setTimeout(t,e))}import{Buffer as ft}from"node:buffer";var Ni=16*1024*1024,$i=5e3,Vi=1e5,Pi=1e6,Di=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?:\s?(.*))?$/,E=class extends Error{constructor(i,n){super(n===void 0?i:`${i} at diff line ${n}`);this.line=n;this.name="XenoDiffParseError"}line;code="XENO_DIFF_INVALID"};function pt(e,t={}){if(typeof e!="string")throw new TypeError("Unified diff must be a string");let i=ce(t.maxBytes,Ni,1024,256*1024*1024,"maxBytes"),n=ce(t.maxFiles,$i,1,1e5,"maxFiles"),o=ce(t.maxHunks,Vi,1,1e6,"maxHunks"),r=ce(t.maxLines,Pi,1,5e6,"maxLines");if(ft.byteLength(e,"utf8")>i)throw new E(`Unified diff exceeds ${i} bytes`);let a=e.replace(/\r\n/g,`
|
|
5
5
|
`).replace(/\r/g,`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/artifacts/types.ts":{"bytes":9397,"imports":[],"format":"esm"},"src/artifacts/browser-diff.ts":{"bytes":8954,"imports":[],"format":"esm"},"src/artifacts/browser.ts":{"bytes":243,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/browser-diff.ts","kind":"import-statement","original":"./browser-diff.js"}],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1530,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/artifacts/validation.ts":{"bytes":25931,"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/evidence-graph.ts":{"bytes":9299,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/repository.ts":{"bytes":30001,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"}],"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/version.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/artifacts/types.ts":{"bytes":9397,"imports":[],"format":"esm"},"src/artifacts/browser-diff.ts":{"bytes":8954,"imports":[],"format":"esm"},"src/artifacts/browser.ts":{"bytes":243,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/browser-diff.ts","kind":"import-statement","original":"./browser-diff.js"}],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1530,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/artifacts/validation.ts":{"bytes":25931,"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/evidence-graph.ts":{"bytes":9299,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/repository.ts":{"bytes":30001,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"}],"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/version.ts":{"bytes":37,"imports":[],"format":"esm"},"src/artifacts/file-repository.ts":{"bytes":16811,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"../control-plane/lock.js"},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/repository.ts","kind":"import-statement","original":"./repository.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/diff-artifact.ts":{"bytes":18491,"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"}],"format":"esm"},"src/artifacts/review-service.ts":{"bytes":8903,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/diff-artifact.ts","kind":"import-statement","original":"./diff-artifact.js"},{"path":"src/artifacts/repository.ts","kind":"import-statement","original":"./repository.js"}],"format":"esm"},"src/artifacts/spec-lifecycle.ts":{"bytes":31787,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/review-service.ts","kind":"import-statement","original":"./review-service.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/multi-agent-review.ts":{"bytes":30924,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"}],"format":"esm"},"src/artifacts/legacy-adapters.ts":{"bytes":11181,"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"},{"path":"src/artifacts/diff-artifact.ts","kind":"import-statement","original":"./diff-artifact.js"}],"format":"esm"},"src/artifacts/index.ts":{"bytes":396,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/evidence-graph.ts","kind":"import-statement","original":"./evidence-graph.js"},{"path":"src/artifacts/repository.ts","kind":"import-statement","original":"./repository.js"},{"path":"src/artifacts/file-repository.ts","kind":"import-statement","original":"./file-repository.js"},{"path":"src/artifacts/diff-artifact.ts","kind":"import-statement","original":"./diff-artifact.js"},{"path":"src/artifacts/review-service.ts","kind":"import-statement","original":"./review-service.js"},{"path":"src/artifacts/spec-lifecycle.ts","kind":"import-statement","original":"./spec-lifecycle.js"},{"path":"src/artifacts/multi-agent-review.ts","kind":"import-statement","original":"./multi-agent-review.js"},{"path":"src/artifacts/legacy-adapters.ts","kind":"import-statement","original":"./legacy-adapters.js"}],"format":"esm"}},"outputs":{"dist/artifacts/browser.cjs":{"imports":[],"exports":[],"entryPoint":"src/artifacts/browser.ts","inputs":{"src/artifacts/browser.ts":{"bytesInOutput":172},"src/artifacts/types.ts":{"bytesInOutput":12},"src/artifacts/browser-diff.ts":{"bytesInOutput":4291}},"bytes":5035},"dist/artifacts/index.cjs":{"imports":[{"path":"node:buffer","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:fs/promises","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:buffer","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:buffer","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/artifacts/index.ts","inputs":{"src/artifacts/index.ts":{"bytesInOutput":2009},"src/artifacts/types.ts":{"bytesInOutput":13},"src/artifacts/validation.ts":{"bytesInOutput":14209},"src/artifacts/hash.ts":{"bytesInOutput":721},"src/artifacts/evidence-graph.ts":{"bytesInOutput":4726},"src/artifacts/repository.ts":{"bytesInOutput":13747},"src/artifacts/file-repository.ts":{"bytesInOutput":6758},"src/control-plane/lock.ts":{"bytesInOutput":1067},"src/version.ts":{"bytesInOutput":16},"src/artifacts/diff-artifact.ts":{"bytesInOutput":7846},"src/artifacts/review-service.ts":{"bytesInOutput":3921},"src/artifacts/spec-lifecycle.ts":{"bytesInOutput":14029},"src/artifacts/multi-agent-review.ts":{"bytesInOutput":14190},"src/artifacts/legacy-adapters.ts":{"bytesInOutput":5009}},"bytes":90307}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/artifacts/types.ts":{"bytes":9397,"imports":[],"format":"esm"},"src/artifacts/browser-diff.ts":{"bytes":8954,"imports":[],"format":"esm"},"src/artifacts/browser.ts":{"bytes":243,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/browser-diff.ts","kind":"import-statement","original":"./browser-diff.js"}],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1530,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/artifacts/validation.ts":{"bytes":25931,"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/evidence-graph.ts":{"bytes":9299,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/repository.ts":{"bytes":30001,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"}],"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/version.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/artifacts/types.ts":{"bytes":9397,"imports":[],"format":"esm"},"src/artifacts/browser-diff.ts":{"bytes":8954,"imports":[],"format":"esm"},"src/artifacts/browser.ts":{"bytes":243,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/browser-diff.ts","kind":"import-statement","original":"./browser-diff.js"}],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1530,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/artifacts/validation.ts":{"bytes":25931,"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/evidence-graph.ts":{"bytes":9299,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/repository.ts":{"bytes":30001,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"}],"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/version.ts":{"bytes":37,"imports":[],"format":"esm"},"src/artifacts/file-repository.ts":{"bytes":16811,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"src/control-plane/lock.ts","kind":"import-statement","original":"../control-plane/lock.js"},{"path":"src/version.ts","kind":"import-statement","original":"../version.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/repository.ts","kind":"import-statement","original":"./repository.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/diff-artifact.ts":{"bytes":18491,"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"}],"format":"esm"},"src/artifacts/review-service.ts":{"bytes":8903,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/diff-artifact.ts","kind":"import-statement","original":"./diff-artifact.js"},{"path":"src/artifacts/repository.ts","kind":"import-statement","original":"./repository.js"}],"format":"esm"},"src/artifacts/spec-lifecycle.ts":{"bytes":31787,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/review-service.ts","kind":"import-statement","original":"./review-service.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/artifacts/multi-agent-review.ts":{"bytes":30924,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"}],"format":"esm"},"src/artifacts/legacy-adapters.ts":{"bytes":11181,"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"},{"path":"src/artifacts/diff-artifact.ts","kind":"import-statement","original":"./diff-artifact.js"}],"format":"esm"},"src/artifacts/index.ts":{"bytes":396,"imports":[{"path":"src/artifacts/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/artifacts/validation.ts","kind":"import-statement","original":"./validation.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"./hash.js"},{"path":"src/artifacts/evidence-graph.ts","kind":"import-statement","original":"./evidence-graph.js"},{"path":"src/artifacts/repository.ts","kind":"import-statement","original":"./repository.js"},{"path":"src/artifacts/file-repository.ts","kind":"import-statement","original":"./file-repository.js"},{"path":"src/artifacts/diff-artifact.ts","kind":"import-statement","original":"./diff-artifact.js"},{"path":"src/artifacts/review-service.ts","kind":"import-statement","original":"./review-service.js"},{"path":"src/artifacts/spec-lifecycle.ts","kind":"import-statement","original":"./spec-lifecycle.js"},{"path":"src/artifacts/multi-agent-review.ts","kind":"import-statement","original":"./multi-agent-review.js"},{"path":"src/artifacts/legacy-adapters.ts","kind":"import-statement","original":"./legacy-adapters.js"}],"format":"esm"}},"outputs":{"dist/artifacts/browser.js":{"imports":[],"exports":["XENO_ARTIFACT_SCHEMA_VERSION","XENO_EVIDENCE_GRAPH_SCHEMA_VERSION","XenoBrowserDiffError","xenoArtifactToDiffDocument"],"entryPoint":"src/artifacts/browser.ts","inputs":{"src/artifacts/types.ts":{"bytesInOutput":12},"src/artifacts/browser.ts":{"bytesInOutput":0},"src/artifacts/browser-diff.ts":{"bytesInOutput":4291}},"bytes":4444},"dist/artifacts/index.js":{"imports":[{"path":"node:buffer","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:fs/promises","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:buffer","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:buffer","kind":"import-statement","external":true}],"exports":["FileXenoArtifactRepository","InMemoryXenoArtifactRepository","XENO_ARTIFACT_FILE_REPOSITORY_SCHEMA_VERSION","XENO_ARTIFACT_SCHEMA_VERSION","XENO_EVIDENCE_GRAPH_SCHEMA_VERSION","XENO_REVIEW_REPORT_SCHEMA_VERSION","XENO_SPEC_EXECUTION_SCHEMA_VERSION","XENO_SPEC_SCHEMA_VERSION","XenoArtifactRepositoryError","XenoArtifactReviewService","XenoArtifactStateTransitionError","XenoArtifactValidationError","XenoDiffParseError","XenoEvidenceGraphBuilder","XenoEvidenceGraphValidationError","XenoMultiAgentReviewCoordinator","XenoReviewValidationError","XenoSpecLifecycleService","XenoSpecValidationError","assertValidXenoArtifact","assertValidXenoEvidenceGraph","assertValidXenoReviewPack","assertValidXenoReviewReport","assertValidXenoReviewTarget","assertValidXenoSpecDocument","assertValidXenoSpecExecution","assertXenoArtifactStateTransition","buildXenoArtifactReviewAnchor","canTransitionXenoArtifactState","canonicalizeArtifactJson","defaultXenoReviewPack","detectXenoSpecDrift","legacyAgentArtifactToXenoArtifact","normalizeRepositoryRelativePath","parseUnifiedDiff","sha256ArtifactBytes","sha256ArtifactJson","summarizeXenoArtifactReview","toolEvidenceToXenoArtifact","turnDiffSummaryToXenoArtifact","unifiedDiffToXenoArtifact","validateXenoArtifact","validateXenoArtifactReviewEvent","validateXenoEvidenceGraph","validateXenoSpecDocument","xenoArtifactToDiffDocument","xenoArtifactToLegacyAgentArtifact","xenoArtifactToReviewReport","xenoArtifactToSpecDocument","xenoArtifactToSpecExecution","xenoArtifactToToolEvidence","xenoArtifactToTurnDiffSummary","xenoReviewReportToArtifact","xenoReviewReportToGitHubComments","xenoSpecArtifactIds","xenoSpecExecutionToArtifact","xenoSpecToArtifactBundle"],"entryPoint":"src/artifacts/index.ts","inputs":{"src/artifacts/types.ts":{"bytesInOutput":13},"src/artifacts/index.ts":{"bytesInOutput":0},"src/artifacts/validation.ts":{"bytesInOutput":14203},"src/artifacts/hash.ts":{"bytesInOutput":718},"src/artifacts/evidence-graph.ts":{"bytesInOutput":4720},"src/artifacts/repository.ts":{"bytesInOutput":13741},"src/artifacts/file-repository.ts":{"bytesInOutput":6731},"src/control-plane/lock.ts":{"bytesInOutput":1054},"src/version.ts":{"bytesInOutput":16},"src/artifacts/diff-artifact.ts":{"bytesInOutput":7840},"src/artifacts/review-service.ts":{"bytesInOutput":3918},"src/artifacts/spec-lifecycle.ts":{"bytesInOutput":14020},"src/artifacts/multi-agent-review.ts":{"bytesInOutput":14187},"src/artifacts/legacy-adapters.ts":{"bytesInOutput":4989}},"bytes":88070}}}
|
|
@@ -1,4 +1,4 @@
|
|
|
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.8.
|
|
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.8.13";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
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
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
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)}
|
|
@@ -1,4 +1,4 @@
|
|
|
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.8.
|
|
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.8.13";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
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
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
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)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/control-plane/types.ts":{"bytes":2467,"imports":[],"format":"esm"},"src/version.ts":{"bytes":
|
|
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 +1 @@
|
|
|
1
|
-
{"inputs":{"src/control-plane/types.ts":{"bytes":2467,"imports":[],"format":"esm"},"src/version.ts":{"bytes":
|
|
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}}}
|