@xenosystem/agent-sdk 0.10.38 → 0.10.40
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 +9 -9
- package/dist/artifacts/index.js +9 -9
- package/dist/artifacts/metafile-cjs.json +1 -1
- package/dist/artifacts/metafile-esm.json +1 -1
- package/dist/automation/index.cjs +8 -8
- package/dist/automation/index.d.cts +10 -0
- package/dist/automation/index.d.ts +10 -0
- package/dist/automation/index.js +9 -9
- package/dist/automation/metafile-cjs.json +1 -1
- package/dist/automation/metafile-esm.json +1 -1
- package/dist/control-plane/index.cjs +1 -1
- package/dist/control-plane/index.js +1 -1
- package/dist/electron/index.cjs +221 -200
- package/dist/electron/index.d.cts +91 -1
- package/dist/electron/index.d.ts +91 -1
- package/dist/electron/index.js +221 -200
- package/dist/electron/metafile-cjs.json +1 -1
- package/dist/electron/metafile-esm.json +1 -1
- package/dist/index.cjs +396 -371
- package/dist/index.d.cts +134 -4
- package/dist/index.d.ts +134 -4
- package/dist/index.js +397 -372
- package/dist/intelligence/index.cjs +9 -9
- package/dist/intelligence/index.js +9 -9
- package/dist/intelligence/metafile-cjs.json +1 -1
- package/dist/intelligence/metafile-esm.json +1 -1
- package/dist/mcp/index.d.cts +10 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/providers/index.cjs +9 -9
- package/dist/providers/index.js +9 -9
- package/dist/providers/metafile-cjs.json +1 -1
- package/dist/providers/metafile-esm.json +1 -1
- package/dist/recipes/index.cjs +2 -2
- package/dist/recipes/index.js +2 -2
- package/dist/recipes/metafile-cjs.json +1 -1
- package/dist/recipes/metafile-esm.json +1 -1
- package/dist/research/index.cjs +3 -3
- package/dist/research/index.js +3 -3
- package/dist/research/metafile-cjs.json +1 -1
- package/dist/research/metafile-esm.json +1 -1
- package/dist/session/index.cjs +25 -25
- package/dist/session/index.js +25 -25
- package/dist/session/metafile-cjs.json +1 -1
- package/dist/session/metafile-esm.json +1 -1
- package/dist/sharing/index.cjs +4 -4
- package/dist/sharing/index.js +4 -4
- package/dist/sharing/metafile-cjs.json +1 -1
- package/dist/sharing/metafile-esm.json +1 -1
- package/dist/utils/index.cjs +23 -23
- package/dist/utils/index.d.cts +15 -1
- package/dist/utils/index.d.ts +15 -1
- package/dist/utils/index.js +23 -23
- package/dist/utils/metafile-cjs.json +1 -1
- package/dist/utils/metafile-esm.json +1 -1
- package/package.json +3 -3
package/dist/artifacts/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var v=1,pe=1,Ye=["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","page"],Ze=["draft","pending_review","approved","rejected","superseded","archived"],Qe=["public","internal","confidential","restricted"],et=["agent","tool","user","system","integration"],ue=["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"],le=["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"];import{Buffer as tt}from"node:buffer";import{createHash as pn}from"node:crypto";function x(t){return{algorithm:"sha256",value:pn("sha256").update(t).digest("hex")}}function T(t){return JSON.stringify(xe(t,new Set))}function k(t){return x(T(t))}function xe(t,e){if(t===null||typeof t!="object"){if(typeof t=="number"&&!Number.isFinite(t))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return t}if(e.has(t))throw new TypeError("Artifact JSON cannot contain cycles");if(e.add(t),Array.isArray(t)){let i=t.map(o=>xe(o,e));return e.delete(t),i}let n={};for(let i of Object.keys(t).sort((o,r)=>o.localeCompare(r))){let o=t[i];if(o===void 0)throw new TypeError(`Artifact JSON property ${i} is undefined`);n[i]=xe(o,e)}return e.delete(t),n}var un=/^[a-z0-9][a-z0-9._/-]{0,127}$/,Te="custom:";function B(t,e=Te){return t.startsWith(e)?un.test(t.slice(e.length)):!1}var K=class extends Error{code="ARTIFACT_INVALID";issues;constructor(e,n){super(e),this.name="XenoArtifactValidationError",this.issues=n.map(i=>({...i}))}},ke=class extends Error{constructor(n,i){super(`Artifact state cannot transition from ${n} to ${i}`);this.fromState=n;this.toState=i;this.name="XenoArtifactStateTransitionError"}fromState;toState;code="ARTIFACT_STATE_TRANSITION_INVALID"},ln={draft:["pending_review","superseded","archived"],pending_review:["approved","rejected","superseded","archived"],approved:["superseded","archived"],rejected:["superseded","archived"],superseded:["archived"],archived:[]},mn="[\\u0000-\\u001f\\u007f]",hn=new RegExp(mn),nt=/^[a-f0-9]{64}$/,gn=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,vn=new Set(Ze),yn=new Set(Qe),An=new Set(et),In=new Set(Ye),wn=new Set(ue),En=new Set(le);function p(t,e,n,i){t.push({path:e,code:n,message:i})}function l(t,e,n,i=1024){return typeof t!="string"||t.trim().length===0?(p(n,e,"required_string","Value must be a non-empty string"),!1):(t.length>i&&p(n,e,"string_too_long",`Value must not exceed ${i} characters`),hn.test(t)&&p(n,e,"control_character","Value must not contain control characters"),!0)}function Z(t,e,n){t!==void 0&&(!Number.isFinite(Date.parse(t))||!t.includes("T"))&&p(n,e,"invalid_timestamp","Value must be an ISO 8601 timestamp")}function q(t,e,n,i){typeof t=="string"&&t.startsWith(e)&&(B(t,e)||p(i,n,"invalid_custom_name",`Custom name after ${e} is invalid`))}function it(t,e,n){if(!t||typeof t!="object"){p(n,e,"missing_actor","Actor is required");return}l(t.kind,`${e}.kind`,n,64),An.has(t.kind)||p(n,`${e}.kind`,"unknown_actor_kind","Actor kind is not supported"),l(t.id,`${e}.id`,n,512),t?.displayName!==void 0&&l(t.displayName,`${e}.displayName`,n,512),t?.profileFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(t.profileFingerprint)&&p(n,`${e}.profileFingerprint`,"invalid_fingerprint","Profile fingerprint must be 64 lowercase hexadecimal characters")}function Ce(t,e,n){if(!t||typeof t!="object"){p(n,e,"invalid_anchor","Anchor must be an object");return}switch(t.kind){case"file":l(t.path,`${e}.path`,n,4096);break;case"source-line":l(t.path,`${e}.path`,n,4096),(!Number.isInteger(t.startLine)||t.startLine<1)&&p(n,`${e}.startLine`,"invalid_line","startLine must be a positive integer"),t.endLine!==void 0&&(!Number.isInteger(t.endLine)||t.endLine<t.startLine)&&p(n,`${e}.endLine`,"invalid_line_range","endLine must be greater than or equal to startLine");break;case"diff-hunk":l(t.path,`${e}.path`,n,4096),l(t.hunkId,`${e}.hunkId`,n,512);break;case"symbol":l(t.path,`${e}.path`,n,4096),l(t.symbol,`${e}.symbol`,n,1024);break;case"dom-node":l(t.pageId,`${e}.pageId`,n,512),!t.selector&&!t.accessibilityId&&!t.snapshotArtifactId&&p(n,e,"missing_dom_locator","DOM anchors require a selector, accessibility ID, or snapshot artifact ID");break;case"timeline":l(t.recordingArtifactId,`${e}.recordingArtifactId`,n,512),(!Number.isFinite(t.startMs)||t.startMs<0)&&p(n,`${e}.startMs`,"invalid_time","startMs must be a non-negative finite number"),t.endMs!==void 0&&(!Number.isFinite(t.endMs)||t.endMs<t.startMs)&&p(n,`${e}.endMs`,"invalid_time_range","endMs must be greater than or equal to startMs");break;case"region":l(t.mediaArtifactId,`${e}.mediaArtifactId`,n,512),[t.x,t.y,t.width,t.height].every(Number.isFinite)?(t.width<=0||t.height<=0)&&p(n,e,"invalid_region_size","Region width and height must be positive"):p(n,e,"invalid_region","Region coordinates must be finite numbers");break;case"artifact":l(t.artifactId,`${e}.artifactId`,n,512);break;default:typeof t.kind!="string"||!t.kind.startsWith("custom:")?p(n,`${e}.kind`,"unknown_anchor","Anchor kind is not supported"):q(t.kind,"custom:",`${e}.kind`,n)}}function Q(t,e,n,i){if(!(t===null||typeof t=="string"||typeof t=="boolean")){if(typeof t=="number"){Number.isFinite(t)||p(n,e,"non_finite_number","JSON numbers must be finite");return}if(typeof t!="object"){p(n,e,"non_json_value","Value must be JSON-serializable");return}if(i.has(t)){p(n,e,"cyclic_value","Value must not contain cycles");return}if(i.add(t),Array.isArray(t))t.forEach((o,r)=>Q(o,`${e}[${r}]`,n,i));else for(let[o,r]of Object.entries(t))r===void 0?p(n,`${e}.${o}`,"undefined_value","Undefined is not valid JSON"):Q(r,`${e}.${o}`,n,i);i.delete(t)}}function Xn(t){let e=[];if(!t||typeof t!="object")return[{path:"$",code:"invalid_artifact",message:"Artifact must be an object"}];if(t.schemaVersion!==1&&p(e,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),l(t.artifactId,"artifactId",e,512),(!Number.isInteger(t.revision)||t.revision<1)&&p(e,"revision","invalid_revision","revision must be a positive integer"),l(t.kind,"kind",e,160),typeof t.kind=="string"&&!In.has(t.kind)&&!t.kind.startsWith("custom:")&&p(e,"kind","unknown_artifact_kind","Artifact kind is not supported"),q(t.kind,"custom:","kind",e),l(t.title,"title",e,1024),t.description!==void 0&&l(t.description,"description",e,32768),l(t.state,"state",e,64),vn.has(t.state)||p(e,"state","unknown_state","Artifact state is not supported"),l(t.createdAt,"createdAt",e,128),Z(t.createdAt,"createdAt",e),Z(t.updatedAt,"updatedAt",e),t.updatedAt&&Number.isFinite(Date.parse(t.createdAt))&&Date.parse(t.updatedAt)<Date.parse(t.createdAt)&&p(e,"updatedAt","timestamp_order","updatedAt must not precede createdAt"),l(t.mediaType,"mediaType",e,255),l(t.sensitivity,"sensitivity",e,64),yn.has(t.sensitivity)||p(e,"sensitivity","unknown_sensitivity","Sensitivity is not supported"),t.identity)for(let[i,o]of Object.entries(t.identity))o!==void 0&&l(o,`identity.${i}`,e,512);if(!t.content||typeof t.content!="object")p(e,"content","missing_content","content descriptor is required");else{!t.content.hash||typeof t.content.hash!="object"?p(e,"content.hash","missing_hash","content hash is required"):(l(t.content.hash.algorithm,"content.hash.algorithm",e,128),q(t.content.hash.algorithm,"custom:","content.hash.algorithm",e),typeof t.content.hash.algorithm=="string"&&t.content.hash.algorithm!=="sha256"&&!t.content.hash.algorithm.startsWith("custom:")&&p(e,"content.hash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported"),l(t.content.hash.value,"content.hash.value",e,512),t.content.hash.algorithm==="sha256"&&!nt.test(t.content.hash.value)&&p(e,"content.hash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters")),(!Number.isSafeInteger(t.content.sizeBytes)||t.content.sizeBytes<0)&&p(e,"content.sizeBytes","invalid_size","sizeBytes must be a non-negative safe integer");let i=t.content.storage;if(!i||typeof i!="object")p(e,"content.storage","missing_storage","storage reference is required");else if(i.type==="inline")if(i.text===void 0==(i.base64===void 0))p(e,"content.storage","invalid_inline_storage","Inline storage requires exactly one of text or base64");else{let o;i.text!==void 0?o=tt.from(i.text,"utf8"):i.base64!==void 0&&(gn.test(i.base64)?o=tt.from(i.base64,"base64"):p(e,"content.storage.base64","invalid_base64","Inline base64 content is malformed")),o&&t.content.sizeBytes!==o.byteLength&&p(e,"content.sizeBytes","content_size_mismatch","sizeBytes does not match inline content"),o&&t.content.hash.algorithm==="sha256"&&x(o).value!==t.content.hash.value&&p(e,"content.hash.value","content_hash_mismatch","Hash does not match inline content")}else i.type==="file"?l(i.path,"content.storage.path",e,4096):i.type==="blob"?l(i.uri,"content.storage.uri",e,8192):i.type==="git"?(l(i.commit,"content.storage.commit",e,512),l(i.path,"content.storage.path",e,4096)):i.type==="url"?(l(i.url,"content.storage.url",e,8192),Z(i.expiresAt,"content.storage.expiresAt",e)):i.type==="external"?(l(i.provider,"content.storage.provider",e,255),l(i.locator,"content.storage.locator",e,8192)):p(e,"content.storage.type","unknown_storage","Storage type is not supported");t.content.encoding!==void 0&&(typeof t.content.encoding!="string"||t.content.encoding!=="utf8"&&t.content.encoding!=="base64"&&t.content.encoding!=="binary"&&!t.content.encoding.startsWith("custom:"))&&p(e,"content.encoding","unknown_encoding","Content encoding is not supported"),q(t.content.encoding,"custom:","content.encoding",e)}!t.provenance||typeof t.provenance!="object"?p(e,"provenance","missing_provenance","provenance is required"):(it(t.provenance.producer,"provenance.producer",e),t.provenance.capabilityLeaseIds?.forEach((i,o)=>l(i,`provenance.capabilityLeaseIds[${o}]`,e,512)),t.provenance.sourceArtifactIds?.forEach((i,o)=>l(i,`provenance.sourceArtifactIds[${o}]`,e,512)),t.provenance.attributes&&Q(t.provenance.attributes,"provenance.attributes",e,new Set));let n=new Set;return t.relationships?.forEach((i,o)=>{let r=`relationships[${o}]`;l(i.relation,`${r}.relation`,e,160),typeof i.relation=="string"&&!En.has(i.relation)&&!i.relation.startsWith("custom:")&&p(e,`${r}.relation`,"unknown_relationship","Relationship type is not supported"),q(i.relation,"custom:",`${r}.relation`,e),l(i.target?.type,`${r}.target.type`,e,160),typeof i.target?.type=="string"&&!wn.has(i.target.type)&&!i.target.type.startsWith("custom:")&&p(e,`${r}.target.type`,"unknown_reference_type","Evidence reference type is not supported"),q(i.target?.type,"custom:",`${r}.target.type`,e),l(i.target?.id,`${r}.target.id`,e,512);let s=`${i.relation}:${i.target?.type}:${i.target?.id}:${i.target?.revision??""}`;n.has(s)&&p(e,r,"duplicate_relationship","Duplicate relationship"),n.add(s),i.attributes&&Q(i.attributes,`${r}.attributes`,e,new Set)}),t.anchors?.forEach((i,o)=>Ce(i,`anchors[${o}]`,e)),t.revision===1&&t.predecessorRevision!==void 0&&p(e,"predecessorRevision","unexpected_predecessor","First revision cannot have a predecessor"),t.revision>1&&(!Number.isInteger(t.predecessorRevision)||(t.predecessorRevision??0)>=t.revision)&&p(e,"predecessorRevision","invalid_predecessor","Later revisions require an earlier predecessor revision"),Z(t.retention?.retainUntil,"retention.retainUntil",e),t.retention?.legalHold!==void 0&&typeof t.retention.legalHold!="boolean"&&p(e,"retention.legalHold","invalid_boolean","legalHold must be a boolean"),t.extensions&&Q(t.extensions,"extensions",e,new Set),e}function R(t){let e=Xn(t);if(e.length>0)throw new K("XENO artifact validation failed",e)}function Rn(t,e){return ln[t].includes(e)}function me(t,e){if(!Rn(t,e))throw new ke(t,e)}function Ne(t,e){let n=[];return t.schemaVersion!==1&&p(n,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),l(t.eventId,"eventId",n,512),l(t.artifactId,"artifactId",n,512),(!Number.isInteger(t.artifactRevision)||t.artifactRevision<1)&&p(n,"artifactRevision","invalid_revision","artifactRevision must be a positive integer"),(!Number.isInteger(t.sequence)||t.sequence<1)&&p(n,"sequence","invalid_sequence","sequence must be a positive integer"),l(t.recordedAt,"recordedAt",n,128),Z(t.recordedAt,"recordedAt",n),it(t.actor,"actor",n),!t.artifactHash||typeof t.artifactHash!="object"?p(n,"artifactHash","missing_hash","Artifact hash is required"):(l(t.artifactHash.algorithm,"artifactHash.algorithm",n,128),q(t.artifactHash.algorithm,"custom:","artifactHash.algorithm",n),l(t.artifactHash.value,"artifactHash.value",n,512),t.artifactHash.algorithm==="sha256"&&!nt.test(t.artifactHash.value)&&p(n,"artifactHash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters"),typeof t.artifactHash.algorithm=="string"&&t.artifactHash.algorithm!=="sha256"&&!t.artifactHash.algorithm.startsWith("custom:")&&p(n,"artifactHash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported")),["review-requested","comment-added","comment-resolved","comment-reopened","decision-recorded","review-withdrawn"].includes(t.type)||p(n,"type","unknown_review_event","Review event type is not supported"),t.type==="comment-added"?(l(t.commentId,"commentId",n,512),l(t.body,"body",n,65536),t.anchor&&Ce(t.anchor,"anchor",n)):t.type==="comment-resolved"||t.type==="comment-reopened"?l(t.commentId,"commentId",n,512):t.type==="decision-recorded"&&(["approved","rejected","changes_requested"].includes(t.decision)||p(n,"decision","unknown_review_decision","Review decision is not supported"),t.scope&&Ce(t.scope,"scope",n)),e&&(t.artifactId!==e.artifactId&&p(n,"artifactId","artifact_mismatch","Review event targets a different artifact"),t.artifactRevision!==e.revision&&p(n,"artifactRevision","revision_mismatch","Review event targets a different revision"),t.artifactHash&&(t.artifactHash.algorithm!==e.content.hash.algorithm||t.artifactHash.value!==e.content.hash.value)&&p(n,"artifactHash","hash_mismatch","Review event hash does not match the artifact revision")),n}function Pe(t){let e="not_requested",n,i,o,r=0,s=new Set,d=new Set;for(let a of[...t].sort((c,f)=>c.sequence-f.sequence))o=a.recordedAt,a.type==="review-requested"?e="pending":a.type==="review-withdrawn"?e="withdrawn":a.type==="comment-added"?(s.add(a.commentId),d.delete(a.commentId),e==="not_requested"&&(e="pending")):a.type==="comment-resolved"?d.add(a.commentId):a.type==="comment-reopened"?d.delete(a.commentId):a.type==="decision-recorded"&&(a.scope?r+=1:(n=a.decision,i=a.eventId,e=a.decision));return{status:e,totalComments:s.size,unresolvedComments:[...s].filter(a=>!d.has(a)).length,...n?{latestDecision:n}:{},...i?{latestDecisionEventId:i}:{},...r>0?{scopedDecisionCount:r}:{},...o?{lastReviewedAt:o}:{}}}var $e=class extends Error{code="EVIDENCE_GRAPH_INVALID";issues;constructor(e){super("XENO evidence graph validation failed"),this.name="XenoEvidenceGraphValidationError",this.issues=e.map(n=>({...n}))}},bn=new Set(["depends_on","decomposes","supersedes"]),Sn=new Set(ue),_n=new Set(le);function A(t,e,n,i){t.push({path:e,code:n,message:i})}function ee(t){return t.includes("T")&&Number.isFinite(Date.parse(t))}function rt(t,e){return t.startsWith(Te)?B(t):e.has(t)}function xn(t){let e=[];if(!t||typeof t!="object")return[{path:"$",code:"invalid_graph",message:"Evidence graph must be an object"}];t.schemaVersion!==1&&A(e,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),(typeof t.graphId!="string"||t.graphId.trim().length===0)&&A(e,"graphId","required_string","graphId must be a non-empty string"),(!Number.isInteger(t.version)||t.version<1)&&A(e,"version","invalid_version","version must be a positive integer"),ee(t.createdAt)||A(e,"createdAt","invalid_timestamp","createdAt must be an ISO 8601 timestamp"),ee(t.updatedAt)||A(e,"updatedAt","invalid_timestamp","updatedAt must be an ISO 8601 timestamp"),ee(t.createdAt)&&ee(t.updatedAt)&&Date.parse(t.updatedAt)<Date.parse(t.createdAt)&&A(e,"updatedAt","timestamp_order","updatedAt must not precede createdAt");let n=new Map;Array.isArray(t.nodes)||A(e,"nodes","invalid_nodes","nodes must be an array"),(Array.isArray(t.nodes)?t.nodes:[]).forEach((f,g)=>{let y=`nodes[${g}]`;typeof f.id!="string"||f.id.trim().length===0?A(e,`${y}.id`,"required_string","Node ID must be a non-empty string"):n.has(f.id)?A(e,`${y}.id`,"duplicate_node",`Node ID ${f.id} is duplicated`):n.set(f.id,f),(typeof f.type!="string"||!rt(f.type,Sn))&&A(e,`${y}.type`,"invalid_node_type","Node type is invalid"),f.artifactRevision!==void 0&&(!Number.isInteger(f.artifactRevision)||f.artifactRevision<1)&&A(e,`${y}.artifactRevision`,"invalid_revision","artifactRevision must be a positive integer")});let i=new Set,o=new Set;Array.isArray(t.edges)||A(e,"edges","invalid_edges","edges must be an array"),(Array.isArray(t.edges)?t.edges:[]).forEach((f,g)=>{let y=`edges[${g}]`;typeof f.id!="string"||f.id.trim().length===0?A(e,`${y}.id`,"required_string","Edge ID must be a non-empty string"):i.has(f.id)&&A(e,`${y}.id`,"duplicate_edge",`Edge ID ${f.id} is duplicated`),i.add(f.id),(typeof f.type!="string"||!rt(f.type,_n))&&A(e,`${y}.type`,"invalid_edge_type","Edge type is invalid");let P=`${f.type}:${f.from}:${f.to}`;o.has(P)&&A(e,y,"duplicate_edge_identity","Equivalent evidence edge is duplicated"),o.add(P),n.has(f.from)||A(e,`${y}.from`,"dangling_reference",`Source node ${f.from} does not exist`),n.has(f.to)||A(e,`${y}.to`,"dangling_reference",`Target node ${f.to} does not exist`),f.from===f.to&&A(e,y,"self_edge","Evidence edges cannot point to the same node"),ee(f.createdAt)||A(e,`${y}.createdAt`,"invalid_timestamp","createdAt must be an ISO 8601 timestamp")});let r=(Array.isArray(t.edges)?t.edges:[]).filter(f=>bn.has(f.type)),s=new Map;for(let f of r){let g=s.get(f.from)??[];g.push(f.to),s.set(f.from,g)}let d=new Set,a=new Set,c=f=>{if(d.has(f))return!0;if(a.has(f))return!1;d.add(f);for(let g of s.get(f)??[])if(c(g))return!0;return d.delete(f),a.add(f),!1};for(let f of n.keys())if(c(f)){A(e,"edges","cyclic_graph","Dependency, decomposition, and supersession edges must be acyclic");break}return e}function te(t){let e=xn(t);if(e.length>0)throw new $e(e)}var ot=class{now;graph;constructor(e){if("schemaVersion"in e)te(e),this.now=()=>new Date().toISOString(),this.graph=he(e);else{this.now=e.now??(()=>new Date().toISOString());let n=this.now();this.graph={schemaVersion:1,graphId:e.graphId,version:1,createdAt:n,updatedAt:n,nodes:[],edges:[]},te(this.graph)}}addNode(e){let n=he(this.graph);return n.nodes.push(st(e)),this.touch(n),te(n),this.graph=n,this}addEdge(e){let n=he(this.graph);return n.edges.push(at(e)),this.touch(n),te(n),this.graph=n,this}build(){return te(this.graph),he(this.graph)}touch(e){e.version+=1,e.updatedAt=this.now()}};function st(t){return{...t,...t.attributes?{attributes:structuredClone(t.attributes)}:{}}}function at(t){return{...t,...t.producer?{producer:{...t.producer}}:{},...t.attributes?{attributes:structuredClone(t.attributes)}:{}}}function he(t){return{...t,nodes:t.nodes.map(st),edges:t.edges.map(at)}}var u=class extends Error{constructor(n,i,o,r){super(i,r);this.code=n;this.detail=o;this.name="XenoArtifactRepositoryError"}code;detail},ie=class{records=new Map;currentRevisions=new Map;now;idFactory;eventIds=new Set;idCounter=0;constructor(e={}){this.now=e.now??(()=>new Date().toISOString()),this.idFactory=e.idFactory??(n=>(this.idCounter+=1,`${n}_${Date.now().toString(36)}_${this.idCounter.toString(36)}`)),e.initialState&&this.hydrate(e.initialState)}exportState(){let e=[...this.records.values()].flatMap(n=>[...n.values()]).sort(ct).map(n=>({artifact:ne(n.artifact),recordVersion:n.recordVersion,lifecycleEvents:structuredClone(n.lifecycleEvents),reviewEvents:structuredClone(n.reviewEvents)}));return{schemaVersion:1,records:e}}async create(e){if(R(e),this.assertInitialState(e),e.revision!==1)throw new u("ARTIFACT_REVISION_INVALID","A new artifact must begin at revision 1",{artifactId:e.artifactId,revision:e.revision});if(this.records.has(e.artifactId))throw new u("ARTIFACT_ALREADY_EXISTS",`Artifact ${e.artifactId} already exists`,{artifactId:e.artifactId});let n=ne(e),i=this.createLifecycleEvent({artifact:n,sequence:1,actor:n.provenance.producer,fromState:null,toState:n.state,reason:"artifact-created"}),o={artifact:n,recordVersion:1,lifecycleEvents:[i],reviewEvents:[]};return this.records.set(n.artifactId,new Map([[n.revision,o]])),this.currentRevisions.set(n.artifactId,n.revision),J(o)}async createRevision(e,n={}){R(e),this.assertInitialState(e);let i=this.getMutable(e.artifactId);this.assertVersion(i,n.expectedRecordVersion);let o=i.artifact.revision+1;if(e.revision!==o||e.predecessorRevision!==i.artifact.revision)throw new u("ARTIFACT_REVISION_INVALID",`Revision ${e.revision} does not follow current revision ${i.artifact.revision}`,{artifactId:e.artifactId,currentRevision:i.artifact.revision,requestedRevision:e.revision});if(kn(e,i.artifact))throw new u("ARTIFACT_CONTENT_UNCHANGED","A new artifact revision must have a different content hash",{artifactId:e.artifactId,revision:e.revision});if(i.artifact.state==="archived")throw new u("ARTIFACT_REVISION_INVALID","Archived artifacts cannot receive new revisions",{artifactId:e.artifactId,revision:i.artifact.revision});if(i.artifact.state!=="superseded"){me(i.artifact.state,"superseded");let a=this.now(),c=this.createLifecycleEvent({artifact:i.artifact,sequence:i.lifecycleEvents.length+1,actor:n.actor??e.provenance.producer,fromState:i.artifact.state,toState:"superseded",reason:n.reason??`superseded-by-revision-${e.revision}`,recordedAt:a});i.artifact.state="superseded",i.artifact.updatedAt=a,i.lifecycleEvents.push(c),i.recordVersion+=1}let r=ne(e),s=this.createLifecycleEvent({artifact:r,sequence:1,actor:n.actor??r.provenance.producer,fromState:null,toState:r.state,reason:n.reason??`revision-created-from-${i.artifact.revision}`}),d={artifact:r,recordVersion:1,lifecycleEvents:[s],reviewEvents:[]};return this.records.get(r.artifactId)?.set(r.revision,d),this.currentRevisions.set(r.artifactId,r.revision),J(d)}async get(e,n){let i=this.records.get(e);if(!i)return;let o=n??this.currentRevisions.get(e);if(o===void 0)return;let r=i.get(o);return r?J(r):void 0}async require(e,n){let i=await this.get(e,n);if(!i)throw new u("ARTIFACT_NOT_FOUND",`Artifact ${e}${n===void 0?"":` revision ${n}`} was not found`,{artifactId:e,...n===void 0?{}:{revision:n}});return i}async list(e={}){let n=[];for(let[i,o]of this.records)if(!(e.artifactIds&&!e.artifactIds.includes(i)))if(e.includeSuperseded)n.push(...o.values());else{let r=this.currentRevisions.get(i);if(r!==void 0){let s=o.get(r);s&&n.push(s)}}return n.filter(i=>Cn(i.artifact,e)).sort(ct).map(J)}async listRevisions(e){let n=this.records.get(e);return n?[...n.values()].sort((i,o)=>i.artifact.revision-o.artifact.revision).map(J):[]}async transition(e){let n=this.getMutable(e.artifactId,e.revision);if(this.assertVersion(n,e.expectedRecordVersion),me(n.artifact.state,e.toState),e.toState==="approved"||e.toState==="rejected"){let s=e.reviewEventId?n.reviewEvents.find(a=>a.eventId===e.reviewEventId&&a.type==="decision-recorded"):void 0,d=Pe(n.reviewEvents);if(!s||s.decision!==e.toState||d.latestDecisionEventId!==s.eventId)throw new u("ARTIFACT_REVIEW_DECISION_REQUIRED",`Transition to ${e.toState} requires a matching decision event`,{artifactId:e.artifactId,revision:n.artifact.revision});if(e.toState==="approved"&&d.unresolvedComments>0)throw new u("ARTIFACT_UNRESOLVED_COMMENTS",`Artifact has ${d.unresolvedComments} unresolved review comment(s)`,{artifactId:e.artifactId,revision:n.artifact.revision,unresolvedComments:d.unresolvedComments})}let i=this.now(),o=n.artifact.state,r=this.createLifecycleEvent({artifact:n.artifact,sequence:n.lifecycleEvents.length+1,actor:e.actor,fromState:o,toState:e.toState,reason:e.reason,reviewEventId:e.reviewEventId,recordedAt:i});return n.artifact.state=e.toState,n.artifact.updatedAt=i,n.lifecycleEvents.push(r),n.recordVersion+=1,J(n)}async appendReviewEvent(e){let n=e.event,i=this.getMutable(n.artifactId,n.artifactRevision);if(this.assertVersion(i,e.expectedRecordVersion),i.artifact.state==="archived"||i.artifact.state==="superseded")throw new u("ARTIFACT_REVIEW_INVALID",`Cannot append review events to a ${i.artifact.state} artifact revision`,{artifactId:n.artifactId,revision:n.artifactRevision});if(this.assertReviewCommentState(i,n),(n.type==="review-requested"||n.type==="review-withdrawn"||n.type==="decision-recorded")&&i.artifact.state!=="pending_review")throw new u("ARTIFACT_REVIEW_INVALID",`${n.type} requires an artifact in pending_review state`,{artifactId:n.artifactId,revision:n.artifactRevision});let o={...structuredClone(n),schemaVersion:1,eventId:this.nextEventId("review_event"),sequence:i.reviewEvents.length+1,recordedAt:this.now()},r=Ne(o,i.artifact);if(r.length>0)throw new K("XENO artifact review event validation failed",r);return i.reviewEvents.push(o),i.recordVersion+=1,J(i)}getMutable(e,n){let i=this.records.get(e),o=n??this.currentRevisions.get(e),r=o===void 0?void 0:i?.get(o);if(!r)throw new u("ARTIFACT_NOT_FOUND",`Artifact ${e}${n===void 0?"":` revision ${n}`} was not found`,{artifactId:e,...n===void 0?{}:{revision:n}});return r}assertVersion(e,n){if(n!==void 0&&n!==e.recordVersion)throw new u("ARTIFACT_CONFLICT",`Expected record version ${n}, found ${e.recordVersion}`,{artifactId:e.artifact.artifactId,revision:e.artifact.revision,expectedRecordVersion:n,actualRecordVersion:e.recordVersion})}assertInitialState(e){if(e.state!=="draft"&&e.state!=="pending_review")throw new u("ARTIFACT_REVISION_INVALID","New artifact revisions must begin in draft or pending_review state",{artifactId:e.artifactId,revision:e.revision})}assertReviewCommentState(e,n){if(n.type==="comment-added"){if(e.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===n.commentId))throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${n.commentId} already exists`);if(n.parentCommentId&&!e.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===n.parentCommentId))throw new u("ARTIFACT_REVIEW_INVALID",`Parent comment ${n.parentCommentId} does not exist`);return}if(n.type!=="comment-resolved"&&n.type!=="comment-reopened")return;if(!e.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===n.commentId))throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${n.commentId} does not exist`);let o=Nn(e.reviewEvents,n.commentId);if(n.type==="comment-resolved"&&o.resolved)throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${n.commentId} is already resolved`);if(n.type==="comment-reopened"&&!o.resolved)throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${n.commentId} is not resolved`)}createLifecycleEvent(e){return{schemaVersion:1,eventId:this.nextEventId("artifact_event"),artifactId:e.artifact.artifactId,revision:e.artifact.revision,sequence:e.sequence,recordedAt:e.recordedAt??this.now(),actor:{...e.actor},fromState:e.fromState,toState:e.toState,...e.reason?{reason:e.reason}:{},...e.reviewEventId?{reviewEventId:e.reviewEventId}:{}}}nextEventId(e){let n=this.idFactory(e);if(typeof n!="string"||n.trim().length===0||this.eventIds.has(n))throw new u("ARTIFACT_CONFLICT",`Event ID factory produced an invalid or duplicate ${e} ID`);return this.eventIds.add(n),n}hydrate(e){if(e.schemaVersion!==1||!Array.isArray(e.records))throw new u("ARTIFACT_REVISION_INVALID","Artifact repository state has an unsupported schema or record collection");let n=[...e.records].sort((i,o)=>i.artifact.artifactId.localeCompare(o.artifact.artifactId)||i.artifact.revision-o.artifact.revision);for(let i of n){let o=Tn(i,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[i,o]of this.records){let r=[...o.values()].sort((s,d)=>s.artifact.revision-d.artifact.revision);for(let s=0;s<r.length;s+=1){let d=r[s],a=s+1;if(d.artifact.revision!==a)throw new u("ARTIFACT_REVISION_INVALID",`Persisted artifact ${i} is missing revision ${a}`);if(s===0&&d.artifact.predecessorRevision!==void 0)throw new u("ARTIFACT_REVISION_INVALID",`Initial revision for ${i} cannot declare a predecessor`);if(s>0&&d.artifact.predecessorRevision!==a-1)throw new u("ARTIFACT_REVISION_INVALID",`Persisted revision ${i}:${a} has an invalid predecessor`);if(s<r.length-1&&d.artifact.state!=="superseded")throw new u("ARTIFACT_REVISION_INVALID",`Non-current revision ${i}:${a} must be superseded`)}}}};function Tn(t,e){if(R(t.artifact),!Number.isInteger(t.recordVersion)||t.recordVersion<1)throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact recordVersion must be a positive integer",{artifactId:t.artifact.artifactId,revision:t.artifact.revision});if(!Array.isArray(t.lifecycleEvents)||t.lifecycleEvents.length===0||!Array.isArray(t.reviewEvents))throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact records require lifecycle and review event arrays",{artifactId:t.artifact.artifactId,revision:t.artifact.revision});let n=t.lifecycleEvents.length+t.reviewEvents.length;if(t.recordVersion!==n)throw new u("ARTIFACT_REVISION_INVALID",`Persisted record version ${t.recordVersion} does not match ${n} mutations`,{artifactId:t.artifact.artifactId,revision:t.artifact.revision});let i=null;for(let r=0;r<t.lifecycleEvents.length;r+=1){let s=t.lifecycleEvents[r];if(s.schemaVersion!==1||s.artifactId!==t.artifact.artifactId||s.revision!==t.artifact.revision||s.sequence!==r+1||s.fromState!==i||typeof s.eventId!="string"||s.eventId.length===0||e.has(s.eventId)||!Number.isFinite(Date.parse(s.recordedAt)))throw new u("ARTIFACT_REVISION_INVALID",`Persisted lifecycle event ${r+1} is invalid`,{artifactId:t.artifact.artifactId,revision:t.artifact.revision});if(i===null){if(s.toState!=="draft"&&s.toState!=="pending_review")throw new u("ARTIFACT_REVISION_INVALID","A persisted artifact must begin in draft or pending_review state",{artifactId:t.artifact.artifactId,revision:t.artifact.revision})}else me(i,s.toState);e.add(s.eventId),i=s.toState}if(i!==t.artifact.state)throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact state does not match its lifecycle tail",{artifactId:t.artifact.artifactId,revision:t.artifact.revision});let o=new Map;for(let r=0;r<t.reviewEvents.length;r+=1){let s=t.reviewEvents[r];if(s.sequence!==r+1||e.has(s.eventId))throw new u("ARTIFACT_REVIEW_INVALID",`Persisted review event ${r+1} has an invalid sequence or duplicate ID`,{artifactId:t.artifact.artifactId,revision:t.artifact.revision});let d=Ne(s,t.artifact);if(d.length>0)throw new K("Persisted XENO artifact review event validation failed",d);if(s.type==="comment-added"){if(o.has(s.commentId)||s.parentCommentId!==void 0&&!o.has(s.parentCommentId))throw new u("ARTIFACT_REVIEW_INVALID",`Persisted comment ${s.commentId} has an invalid identity or parent`);o.set(s.commentId,!1)}else if(s.type==="comment-resolved"||s.type==="comment-reopened"){let a=o.get(s.commentId);if(a===void 0||s.type==="comment-resolved"&&a||s.type==="comment-reopened"&&!a)throw new u("ARTIFACT_REVIEW_INVALID",`Persisted comment transition for ${s.commentId} is invalid`);o.set(s.commentId,s.type==="comment-resolved")}e.add(s.eventId)}return{artifact:ne(t.artifact),recordVersion:t.recordVersion,lifecycleEvents:structuredClone(t.lifecycleEvents),reviewEvents:structuredClone(t.reviewEvents)}}function kn(t,e){return t.content.hash.algorithm===e.content.hash.algorithm&&t.content.hash.value===e.content.hash.value}function Cn(t,e){return!(e.kinds&&!e.kinds.includes(t.kind)||e.states&&!e.states.includes(t.state)||e.runId&&t.identity?.runId!==e.runId||e.sessionId&&t.identity?.sessionId!==e.sessionId||e.turnId&&t.identity?.turnId!==e.turnId||e.taskId&&t.identity?.taskId!==e.taskId||e.workspaceId&&t.identity?.workspaceId!==e.workspaceId||e.repositoryId&&t.identity?.repositoryId!==e.repositoryId||e.producerId&&t.provenance.producer.id!==e.producerId||e.sensitivity&&!e.sensitivity.includes(t.sensitivity))}function ct(t,e){return t.artifact.createdAt.localeCompare(e.artifact.createdAt)||t.artifact.artifactId.localeCompare(e.artifact.artifactId)||t.artifact.revision-e.artifact.revision}function Nn(t,e){let n=!1;for(let i of t)(i.type==="comment-resolved"||i.type==="comment-reopened")&&i.commentId===e&&(n=i.type==="comment-resolved");return{resolved:n}}function ne(t){return structuredClone(t)}function J(t){return{artifact:ne(t.artifact),recordVersion:t.recordVersion,etag:`${t.artifact.artifactId}:${t.artifact.revision}:${t.recordVersion}`,lifecycleEvents:structuredClone(t.lifecycleEvents),reviewEvents:structuredClone(t.reviewEvents),reviewSummary:Pe(t.reviewEvents)}}import{randomUUID as wt}from"node:crypto";import{mkdir as Et,open as gt,readFile as qn,stat as Xt,unlink as Jn}from"node:fs/promises";import{basename as vt,dirname as yt,join as Un,resolve as Wn}from"node:path";import*as V from"node:fs/promises";var Pn=new Set(["EACCES","EBUSY","EPERM"]),$n=[10,20,40,80,160,320,640];async function dt(t,e){for(let n=0;;n+=1)try{await V.rename(t,e);return}catch(i){let o=i.code,r=$n[n];if(process.platform!=="win32"||!o||!Pn.has(o)||r===void 0)throw i;await new Promise(s=>setTimeout(s,r))}}import{mkdirSync as Vn,readFileSync as On,rmSync as pt,writeFileSync as Dn}from"node:fs";import{hostname as ut}from"node:os";import{dirname as Fn}from"node:path";function Ln(){return new Date().toISOString()}function Mn(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function lt(t){try{return JSON.parse(On(t,"utf8"))}catch{return null}}function Hn(t){if(!t||t<=0)return!1;try{return process.kill(t,0),!0}catch{return!1}}function jn(t){return t.hostname!==ut()?!0:Hn(t.pid)}function ft(t,e){Vn(Fn(t),{recursive:!0}),Dn(t,JSON.stringify(e,null,2)+`
|
|
2
|
-
`,{encoding:"utf8",flag:"wx"})}function
|
|
3
|
-
`;if(Buffer.byteLength(s,"utf8")>this.maxSnapshotBytes)throw new u("ARTIFACT_PERSISTENCE_IO",`Artifact repository snapshot exceeds ${this.maxSnapshotBytes} bytes`,{snapshotPath:this.snapshotPath,maxSnapshotBytes:this.maxSnapshotBytes});await
|
|
4
|
-
`),await
|
|
1
|
+
var v=1,pe=1,Ze=["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","page"],Qe=["draft","pending_review","approved","rejected","superseded","archived"],et=["public","internal","confidential","restricted"],tt=["agent","tool","user","system","integration"],ue=["requirement","design-decision","risk","task","agent","run","tool-call","edit","commit","test-case","test-run","finding","approval","artifact","release","claim"],le=["decomposes","depends_on","implements","changes","tests","verifies","finds","fixes","reviews","approves","rejects","supersedes","derived_from","produced_by","supports_claim","contradicts_claim","released_as"];import{Buffer as nt}from"node:buffer";import{createHash as mn}from"node:crypto";function x(t){return{algorithm:"sha256",value:mn("sha256").update(t).digest("hex")}}function T(t){return JSON.stringify(xe(t,new Set))}function k(t){return x(T(t))}function xe(t,e){if(t===null||typeof t!="object"){if(typeof t=="number"&&!Number.isFinite(t))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return t}if(e.has(t))throw new TypeError("Artifact JSON cannot contain cycles");if(e.add(t),Array.isArray(t)){let i=t.map(o=>xe(o,e));return e.delete(t),i}let n={};for(let i of Object.keys(t).sort((o,r)=>o.localeCompare(r))){let o=t[i];if(o===void 0)throw new TypeError(`Artifact JSON property ${i} is undefined`);n[i]=xe(o,e)}return e.delete(t),n}var hn=/^[a-z0-9][a-z0-9._/-]{0,127}$/,Te="custom:";function B(t,e=Te){return t.startsWith(e)?hn.test(t.slice(e.length)):!1}var G=class extends Error{code="ARTIFACT_INVALID";issues;constructor(e,n){super(e),this.name="XenoArtifactValidationError",this.issues=n.map(i=>({...i}))}},ke=class extends Error{constructor(n,i){super(`Artifact state cannot transition from ${n} to ${i}`);this.fromState=n;this.toState=i;this.name="XenoArtifactStateTransitionError"}fromState;toState;code="ARTIFACT_STATE_TRANSITION_INVALID"},gn={draft:["pending_review","superseded","archived"],pending_review:["approved","rejected","superseded","archived"],approved:["superseded","archived"],rejected:["superseded","archived"],superseded:["archived"],archived:[]},vn="[\\u0000-\\u001f\\u007f]",yn=new RegExp(vn),it=/^[a-f0-9]{64}$/,An=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,In=new Set(Qe),wn=new Set(et),En=new Set(tt),Xn=new Set(Ze),Rn=new Set(ue),bn=new Set(le);function p(t,e,n,i){t.push({path:e,code:n,message:i})}function l(t,e,n,i=1024){return typeof t!="string"||t.trim().length===0?(p(n,e,"required_string","Value must be a non-empty string"),!1):(t.length>i&&p(n,e,"string_too_long",`Value must not exceed ${i} characters`),yn.test(t)&&p(n,e,"control_character","Value must not contain control characters"),!0)}function Z(t,e,n){t!==void 0&&(!Number.isFinite(Date.parse(t))||!t.includes("T"))&&p(n,e,"invalid_timestamp","Value must be an ISO 8601 timestamp")}function q(t,e,n,i){typeof t=="string"&&t.startsWith(e)&&(B(t,e)||p(i,n,"invalid_custom_name",`Custom name after ${e} is invalid`))}function rt(t,e,n){if(!t||typeof t!="object"){p(n,e,"missing_actor","Actor is required");return}l(t.kind,`${e}.kind`,n,64),En.has(t.kind)||p(n,`${e}.kind`,"unknown_actor_kind","Actor kind is not supported"),l(t.id,`${e}.id`,n,512),t?.displayName!==void 0&&l(t.displayName,`${e}.displayName`,n,512),t?.profileFingerprint!==void 0&&!/^[a-f0-9]{64}$/.test(t.profileFingerprint)&&p(n,`${e}.profileFingerprint`,"invalid_fingerprint","Profile fingerprint must be 64 lowercase hexadecimal characters")}function Ce(t,e,n){if(!t||typeof t!="object"){p(n,e,"invalid_anchor","Anchor must be an object");return}switch(t.kind){case"file":l(t.path,`${e}.path`,n,4096);break;case"source-line":l(t.path,`${e}.path`,n,4096),(!Number.isInteger(t.startLine)||t.startLine<1)&&p(n,`${e}.startLine`,"invalid_line","startLine must be a positive integer"),t.endLine!==void 0&&(!Number.isInteger(t.endLine)||t.endLine<t.startLine)&&p(n,`${e}.endLine`,"invalid_line_range","endLine must be greater than or equal to startLine");break;case"diff-hunk":l(t.path,`${e}.path`,n,4096),l(t.hunkId,`${e}.hunkId`,n,512);break;case"symbol":l(t.path,`${e}.path`,n,4096),l(t.symbol,`${e}.symbol`,n,1024);break;case"dom-node":l(t.pageId,`${e}.pageId`,n,512),!t.selector&&!t.accessibilityId&&!t.snapshotArtifactId&&p(n,e,"missing_dom_locator","DOM anchors require a selector, accessibility ID, or snapshot artifact ID");break;case"timeline":l(t.recordingArtifactId,`${e}.recordingArtifactId`,n,512),(!Number.isFinite(t.startMs)||t.startMs<0)&&p(n,`${e}.startMs`,"invalid_time","startMs must be a non-negative finite number"),t.endMs!==void 0&&(!Number.isFinite(t.endMs)||t.endMs<t.startMs)&&p(n,`${e}.endMs`,"invalid_time_range","endMs must be greater than or equal to startMs");break;case"region":l(t.mediaArtifactId,`${e}.mediaArtifactId`,n,512),[t.x,t.y,t.width,t.height].every(Number.isFinite)?(t.width<=0||t.height<=0)&&p(n,e,"invalid_region_size","Region width and height must be positive"):p(n,e,"invalid_region","Region coordinates must be finite numbers");break;case"artifact":l(t.artifactId,`${e}.artifactId`,n,512);break;default:typeof t.kind!="string"||!t.kind.startsWith("custom:")?p(n,`${e}.kind`,"unknown_anchor","Anchor kind is not supported"):q(t.kind,"custom:",`${e}.kind`,n)}}function Q(t,e,n,i){if(!(t===null||typeof t=="string"||typeof t=="boolean")){if(typeof t=="number"){Number.isFinite(t)||p(n,e,"non_finite_number","JSON numbers must be finite");return}if(typeof t!="object"){p(n,e,"non_json_value","Value must be JSON-serializable");return}if(i.has(t)){p(n,e,"cyclic_value","Value must not contain cycles");return}if(i.add(t),Array.isArray(t))t.forEach((o,r)=>Q(o,`${e}[${r}]`,n,i));else for(let[o,r]of Object.entries(t))r===void 0?p(n,`${e}.${o}`,"undefined_value","Undefined is not valid JSON"):Q(r,`${e}.${o}`,n,i);i.delete(t)}}function Sn(t){let e=[];if(!t||typeof t!="object")return[{path:"$",code:"invalid_artifact",message:"Artifact must be an object"}];if(t.schemaVersion!==1&&p(e,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),l(t.artifactId,"artifactId",e,512),(!Number.isInteger(t.revision)||t.revision<1)&&p(e,"revision","invalid_revision","revision must be a positive integer"),l(t.kind,"kind",e,160),typeof t.kind=="string"&&!Xn.has(t.kind)&&!t.kind.startsWith("custom:")&&p(e,"kind","unknown_artifact_kind","Artifact kind is not supported"),q(t.kind,"custom:","kind",e),l(t.title,"title",e,1024),t.description!==void 0&&l(t.description,"description",e,32768),l(t.state,"state",e,64),In.has(t.state)||p(e,"state","unknown_state","Artifact state is not supported"),l(t.createdAt,"createdAt",e,128),Z(t.createdAt,"createdAt",e),Z(t.updatedAt,"updatedAt",e),t.updatedAt&&Number.isFinite(Date.parse(t.createdAt))&&Date.parse(t.updatedAt)<Date.parse(t.createdAt)&&p(e,"updatedAt","timestamp_order","updatedAt must not precede createdAt"),l(t.mediaType,"mediaType",e,255),l(t.sensitivity,"sensitivity",e,64),wn.has(t.sensitivity)||p(e,"sensitivity","unknown_sensitivity","Sensitivity is not supported"),t.identity)for(let[i,o]of Object.entries(t.identity))o!==void 0&&l(o,`identity.${i}`,e,512);if(!t.content||typeof t.content!="object")p(e,"content","missing_content","content descriptor is required");else{!t.content.hash||typeof t.content.hash!="object"?p(e,"content.hash","missing_hash","content hash is required"):(l(t.content.hash.algorithm,"content.hash.algorithm",e,128),q(t.content.hash.algorithm,"custom:","content.hash.algorithm",e),typeof t.content.hash.algorithm=="string"&&t.content.hash.algorithm!=="sha256"&&!t.content.hash.algorithm.startsWith("custom:")&&p(e,"content.hash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported"),l(t.content.hash.value,"content.hash.value",e,512),t.content.hash.algorithm==="sha256"&&!it.test(t.content.hash.value)&&p(e,"content.hash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters")),(!Number.isSafeInteger(t.content.sizeBytes)||t.content.sizeBytes<0)&&p(e,"content.sizeBytes","invalid_size","sizeBytes must be a non-negative safe integer");let i=t.content.storage;if(!i||typeof i!="object")p(e,"content.storage","missing_storage","storage reference is required");else if(i.type==="inline")if(i.text===void 0==(i.base64===void 0))p(e,"content.storage","invalid_inline_storage","Inline storage requires exactly one of text or base64");else{let o;i.text!==void 0?o=nt.from(i.text,"utf8"):i.base64!==void 0&&(An.test(i.base64)?o=nt.from(i.base64,"base64"):p(e,"content.storage.base64","invalid_base64","Inline base64 content is malformed")),o&&t.content.sizeBytes!==o.byteLength&&p(e,"content.sizeBytes","content_size_mismatch","sizeBytes does not match inline content"),o&&t.content.hash.algorithm==="sha256"&&x(o).value!==t.content.hash.value&&p(e,"content.hash.value","content_hash_mismatch","Hash does not match inline content")}else i.type==="file"?l(i.path,"content.storage.path",e,4096):i.type==="blob"?l(i.uri,"content.storage.uri",e,8192):i.type==="git"?(l(i.commit,"content.storage.commit",e,512),l(i.path,"content.storage.path",e,4096)):i.type==="url"?(l(i.url,"content.storage.url",e,8192),Z(i.expiresAt,"content.storage.expiresAt",e)):i.type==="external"?(l(i.provider,"content.storage.provider",e,255),l(i.locator,"content.storage.locator",e,8192)):p(e,"content.storage.type","unknown_storage","Storage type is not supported");t.content.encoding!==void 0&&(typeof t.content.encoding!="string"||t.content.encoding!=="utf8"&&t.content.encoding!=="base64"&&t.content.encoding!=="binary"&&!t.content.encoding.startsWith("custom:"))&&p(e,"content.encoding","unknown_encoding","Content encoding is not supported"),q(t.content.encoding,"custom:","content.encoding",e)}!t.provenance||typeof t.provenance!="object"?p(e,"provenance","missing_provenance","provenance is required"):(rt(t.provenance.producer,"provenance.producer",e),t.provenance.capabilityLeaseIds?.forEach((i,o)=>l(i,`provenance.capabilityLeaseIds[${o}]`,e,512)),t.provenance.sourceArtifactIds?.forEach((i,o)=>l(i,`provenance.sourceArtifactIds[${o}]`,e,512)),t.provenance.attributes&&Q(t.provenance.attributes,"provenance.attributes",e,new Set));let n=new Set;return t.relationships?.forEach((i,o)=>{let r=`relationships[${o}]`;l(i.relation,`${r}.relation`,e,160),typeof i.relation=="string"&&!bn.has(i.relation)&&!i.relation.startsWith("custom:")&&p(e,`${r}.relation`,"unknown_relationship","Relationship type is not supported"),q(i.relation,"custom:",`${r}.relation`,e),l(i.target?.type,`${r}.target.type`,e,160),typeof i.target?.type=="string"&&!Rn.has(i.target.type)&&!i.target.type.startsWith("custom:")&&p(e,`${r}.target.type`,"unknown_reference_type","Evidence reference type is not supported"),q(i.target?.type,"custom:",`${r}.target.type`,e),l(i.target?.id,`${r}.target.id`,e,512);let s=`${i.relation}:${i.target?.type}:${i.target?.id}:${i.target?.revision??""}`;n.has(s)&&p(e,r,"duplicate_relationship","Duplicate relationship"),n.add(s),i.attributes&&Q(i.attributes,`${r}.attributes`,e,new Set)}),t.anchors?.forEach((i,o)=>Ce(i,`anchors[${o}]`,e)),t.revision===1&&t.predecessorRevision!==void 0&&p(e,"predecessorRevision","unexpected_predecessor","First revision cannot have a predecessor"),t.revision>1&&(!Number.isInteger(t.predecessorRevision)||(t.predecessorRevision??0)>=t.revision)&&p(e,"predecessorRevision","invalid_predecessor","Later revisions require an earlier predecessor revision"),Z(t.retention?.retainUntil,"retention.retainUntil",e),t.retention?.legalHold!==void 0&&typeof t.retention.legalHold!="boolean"&&p(e,"retention.legalHold","invalid_boolean","legalHold must be a boolean"),t.extensions&&Q(t.extensions,"extensions",e,new Set),e}function R(t){let e=Sn(t);if(e.length>0)throw new G("XENO artifact validation failed",e)}function _n(t,e){return gn[t].includes(e)}function me(t,e){if(!_n(t,e))throw new ke(t,e)}function Ne(t,e){let n=[];return t.schemaVersion!==1&&p(n,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),l(t.eventId,"eventId",n,512),l(t.artifactId,"artifactId",n,512),(!Number.isInteger(t.artifactRevision)||t.artifactRevision<1)&&p(n,"artifactRevision","invalid_revision","artifactRevision must be a positive integer"),(!Number.isInteger(t.sequence)||t.sequence<1)&&p(n,"sequence","invalid_sequence","sequence must be a positive integer"),l(t.recordedAt,"recordedAt",n,128),Z(t.recordedAt,"recordedAt",n),rt(t.actor,"actor",n),!t.artifactHash||typeof t.artifactHash!="object"?p(n,"artifactHash","missing_hash","Artifact hash is required"):(l(t.artifactHash.algorithm,"artifactHash.algorithm",n,128),q(t.artifactHash.algorithm,"custom:","artifactHash.algorithm",n),l(t.artifactHash.value,"artifactHash.value",n,512),t.artifactHash.algorithm==="sha256"&&!it.test(t.artifactHash.value)&&p(n,"artifactHash.value","invalid_sha256","SHA-256 hash must be 64 lowercase hexadecimal characters"),typeof t.artifactHash.algorithm=="string"&&t.artifactHash.algorithm!=="sha256"&&!t.artifactHash.algorithm.startsWith("custom:")&&p(n,"artifactHash.algorithm","unknown_hash_algorithm","Hash algorithm is not supported")),["review-requested","comment-added","comment-resolved","comment-reopened","decision-recorded","review-withdrawn"].includes(t.type)||p(n,"type","unknown_review_event","Review event type is not supported"),t.type==="comment-added"?(l(t.commentId,"commentId",n,512),l(t.body,"body",n,65536),t.anchor&&Ce(t.anchor,"anchor",n)):t.type==="comment-resolved"||t.type==="comment-reopened"?l(t.commentId,"commentId",n,512):t.type==="decision-recorded"&&(["approved","rejected","changes_requested"].includes(t.decision)||p(n,"decision","unknown_review_decision","Review decision is not supported"),t.scope&&Ce(t.scope,"scope",n)),e&&(t.artifactId!==e.artifactId&&p(n,"artifactId","artifact_mismatch","Review event targets a different artifact"),t.artifactRevision!==e.revision&&p(n,"artifactRevision","revision_mismatch","Review event targets a different revision"),t.artifactHash&&(t.artifactHash.algorithm!==e.content.hash.algorithm||t.artifactHash.value!==e.content.hash.value)&&p(n,"artifactHash","hash_mismatch","Review event hash does not match the artifact revision")),n}function Pe(t){let e="not_requested",n,i,o,r=0,s=new Set,d=new Set;for(let a of[...t].sort((c,f)=>c.sequence-f.sequence))o=a.recordedAt,a.type==="review-requested"?e="pending":a.type==="review-withdrawn"?e="withdrawn":a.type==="comment-added"?(s.add(a.commentId),d.delete(a.commentId),e==="not_requested"&&(e="pending")):a.type==="comment-resolved"?d.add(a.commentId):a.type==="comment-reopened"?d.delete(a.commentId):a.type==="decision-recorded"&&(a.scope?r+=1:(n=a.decision,i=a.eventId,e=a.decision));return{status:e,totalComments:s.size,unresolvedComments:[...s].filter(a=>!d.has(a)).length,...n?{latestDecision:n}:{},...i?{latestDecisionEventId:i}:{},...r>0?{scopedDecisionCount:r}:{},...o?{lastReviewedAt:o}:{}}}var $e=class extends Error{code="EVIDENCE_GRAPH_INVALID";issues;constructor(e){super("XENO evidence graph validation failed"),this.name="XenoEvidenceGraphValidationError",this.issues=e.map(n=>({...n}))}},xn=new Set(["depends_on","decomposes","supersedes"]),Tn=new Set(ue),kn=new Set(le);function A(t,e,n,i){t.push({path:e,code:n,message:i})}function ee(t){return t.includes("T")&&Number.isFinite(Date.parse(t))}function ot(t,e){return t.startsWith(Te)?B(t):e.has(t)}function Cn(t){let e=[];if(!t||typeof t!="object")return[{path:"$",code:"invalid_graph",message:"Evidence graph must be an object"}];t.schemaVersion!==1&&A(e,"schemaVersion","unsupported_schema",`schemaVersion must be ${1}`),(typeof t.graphId!="string"||t.graphId.trim().length===0)&&A(e,"graphId","required_string","graphId must be a non-empty string"),(!Number.isInteger(t.version)||t.version<1)&&A(e,"version","invalid_version","version must be a positive integer"),ee(t.createdAt)||A(e,"createdAt","invalid_timestamp","createdAt must be an ISO 8601 timestamp"),ee(t.updatedAt)||A(e,"updatedAt","invalid_timestamp","updatedAt must be an ISO 8601 timestamp"),ee(t.createdAt)&&ee(t.updatedAt)&&Date.parse(t.updatedAt)<Date.parse(t.createdAt)&&A(e,"updatedAt","timestamp_order","updatedAt must not precede createdAt");let n=new Map;Array.isArray(t.nodes)||A(e,"nodes","invalid_nodes","nodes must be an array"),(Array.isArray(t.nodes)?t.nodes:[]).forEach((f,g)=>{let y=`nodes[${g}]`;typeof f.id!="string"||f.id.trim().length===0?A(e,`${y}.id`,"required_string","Node ID must be a non-empty string"):n.has(f.id)?A(e,`${y}.id`,"duplicate_node",`Node ID ${f.id} is duplicated`):n.set(f.id,f),(typeof f.type!="string"||!ot(f.type,Tn))&&A(e,`${y}.type`,"invalid_node_type","Node type is invalid"),f.artifactRevision!==void 0&&(!Number.isInteger(f.artifactRevision)||f.artifactRevision<1)&&A(e,`${y}.artifactRevision`,"invalid_revision","artifactRevision must be a positive integer")});let i=new Set,o=new Set;Array.isArray(t.edges)||A(e,"edges","invalid_edges","edges must be an array"),(Array.isArray(t.edges)?t.edges:[]).forEach((f,g)=>{let y=`edges[${g}]`;typeof f.id!="string"||f.id.trim().length===0?A(e,`${y}.id`,"required_string","Edge ID must be a non-empty string"):i.has(f.id)&&A(e,`${y}.id`,"duplicate_edge",`Edge ID ${f.id} is duplicated`),i.add(f.id),(typeof f.type!="string"||!ot(f.type,kn))&&A(e,`${y}.type`,"invalid_edge_type","Edge type is invalid");let P=`${f.type}:${f.from}:${f.to}`;o.has(P)&&A(e,y,"duplicate_edge_identity","Equivalent evidence edge is duplicated"),o.add(P),n.has(f.from)||A(e,`${y}.from`,"dangling_reference",`Source node ${f.from} does not exist`),n.has(f.to)||A(e,`${y}.to`,"dangling_reference",`Target node ${f.to} does not exist`),f.from===f.to&&A(e,y,"self_edge","Evidence edges cannot point to the same node"),ee(f.createdAt)||A(e,`${y}.createdAt`,"invalid_timestamp","createdAt must be an ISO 8601 timestamp")});let r=(Array.isArray(t.edges)?t.edges:[]).filter(f=>xn.has(f.type)),s=new Map;for(let f of r){let g=s.get(f.from)??[];g.push(f.to),s.set(f.from,g)}let d=new Set,a=new Set,c=f=>{if(d.has(f))return!0;if(a.has(f))return!1;d.add(f);for(let g of s.get(f)??[])if(c(g))return!0;return d.delete(f),a.add(f),!1};for(let f of n.keys())if(c(f)){A(e,"edges","cyclic_graph","Dependency, decomposition, and supersession edges must be acyclic");break}return e}function te(t){let e=Cn(t);if(e.length>0)throw new $e(e)}var st=class{now;graph;constructor(e){if("schemaVersion"in e)te(e),this.now=()=>new Date().toISOString(),this.graph=he(e);else{this.now=e.now??(()=>new Date().toISOString());let n=this.now();this.graph={schemaVersion:1,graphId:e.graphId,version:1,createdAt:n,updatedAt:n,nodes:[],edges:[]},te(this.graph)}}addNode(e){let n=he(this.graph);return n.nodes.push(at(e)),this.touch(n),te(n),this.graph=n,this}addEdge(e){let n=he(this.graph);return n.edges.push(ct(e)),this.touch(n),te(n),this.graph=n,this}build(){return te(this.graph),he(this.graph)}touch(e){e.version+=1,e.updatedAt=this.now()}};function at(t){return{...t,...t.attributes?{attributes:structuredClone(t.attributes)}:{}}}function ct(t){return{...t,...t.producer?{producer:{...t.producer}}:{},...t.attributes?{attributes:structuredClone(t.attributes)}:{}}}function he(t){return{...t,nodes:t.nodes.map(at),edges:t.edges.map(ct)}}var u=class extends Error{constructor(n,i,o,r){super(i,r);this.code=n;this.detail=o;this.name="XenoArtifactRepositoryError"}code;detail},ie=class{records=new Map;currentRevisions=new Map;now;idFactory;eventIds=new Set;idCounter=0;constructor(e={}){this.now=e.now??(()=>new Date().toISOString()),this.idFactory=e.idFactory??(n=>(this.idCounter+=1,`${n}_${Date.now().toString(36)}_${this.idCounter.toString(36)}`)),e.initialState&&this.hydrate(e.initialState)}exportState(){let e=[...this.records.values()].flatMap(n=>[...n.values()]).sort(dt).map(n=>({artifact:ne(n.artifact),recordVersion:n.recordVersion,lifecycleEvents:structuredClone(n.lifecycleEvents),reviewEvents:structuredClone(n.reviewEvents)}));return{schemaVersion:1,records:e}}async create(e){if(R(e),this.assertInitialState(e),e.revision!==1)throw new u("ARTIFACT_REVISION_INVALID","A new artifact must begin at revision 1",{artifactId:e.artifactId,revision:e.revision});if(this.records.has(e.artifactId))throw new u("ARTIFACT_ALREADY_EXISTS",`Artifact ${e.artifactId} already exists`,{artifactId:e.artifactId});let n=ne(e),i=this.createLifecycleEvent({artifact:n,sequence:1,actor:n.provenance.producer,fromState:null,toState:n.state,reason:"artifact-created"}),o={artifact:n,recordVersion:1,lifecycleEvents:[i],reviewEvents:[]};return this.records.set(n.artifactId,new Map([[n.revision,o]])),this.currentRevisions.set(n.artifactId,n.revision),J(o)}async createRevision(e,n={}){R(e),this.assertInitialState(e);let i=this.getMutable(e.artifactId);this.assertVersion(i,n.expectedRecordVersion);let o=i.artifact.revision+1;if(e.revision!==o||e.predecessorRevision!==i.artifact.revision)throw new u("ARTIFACT_REVISION_INVALID",`Revision ${e.revision} does not follow current revision ${i.artifact.revision}`,{artifactId:e.artifactId,currentRevision:i.artifact.revision,requestedRevision:e.revision});if(Pn(e,i.artifact))throw new u("ARTIFACT_CONTENT_UNCHANGED","A new artifact revision must have a different content hash",{artifactId:e.artifactId,revision:e.revision});if(i.artifact.state==="archived")throw new u("ARTIFACT_REVISION_INVALID","Archived artifacts cannot receive new revisions",{artifactId:e.artifactId,revision:i.artifact.revision});if(i.artifact.state!=="superseded"){me(i.artifact.state,"superseded");let a=this.now(),c=this.createLifecycleEvent({artifact:i.artifact,sequence:i.lifecycleEvents.length+1,actor:n.actor??e.provenance.producer,fromState:i.artifact.state,toState:"superseded",reason:n.reason??`superseded-by-revision-${e.revision}`,recordedAt:a});i.artifact.state="superseded",i.artifact.updatedAt=a,i.lifecycleEvents.push(c),i.recordVersion+=1}let r=ne(e),s=this.createLifecycleEvent({artifact:r,sequence:1,actor:n.actor??r.provenance.producer,fromState:null,toState:r.state,reason:n.reason??`revision-created-from-${i.artifact.revision}`}),d={artifact:r,recordVersion:1,lifecycleEvents:[s],reviewEvents:[]};return this.records.get(r.artifactId)?.set(r.revision,d),this.currentRevisions.set(r.artifactId,r.revision),J(d)}async get(e,n){let i=this.records.get(e);if(!i)return;let o=n??this.currentRevisions.get(e);if(o===void 0)return;let r=i.get(o);return r?J(r):void 0}async require(e,n){let i=await this.get(e,n);if(!i)throw new u("ARTIFACT_NOT_FOUND",`Artifact ${e}${n===void 0?"":` revision ${n}`} was not found`,{artifactId:e,...n===void 0?{}:{revision:n}});return i}async list(e={}){let n=[];for(let[i,o]of this.records)if(!(e.artifactIds&&!e.artifactIds.includes(i)))if(e.includeSuperseded)n.push(...o.values());else{let r=this.currentRevisions.get(i);if(r!==void 0){let s=o.get(r);s&&n.push(s)}}return n.filter(i=>$n(i.artifact,e)).sort(dt).map(J)}async listRevisions(e){let n=this.records.get(e);return n?[...n.values()].sort((i,o)=>i.artifact.revision-o.artifact.revision).map(J):[]}async transition(e){let n=this.getMutable(e.artifactId,e.revision);if(this.assertVersion(n,e.expectedRecordVersion),me(n.artifact.state,e.toState),e.toState==="approved"||e.toState==="rejected"){let s=e.reviewEventId?n.reviewEvents.find(a=>a.eventId===e.reviewEventId&&a.type==="decision-recorded"):void 0,d=Pe(n.reviewEvents);if(!s||s.decision!==e.toState||d.latestDecisionEventId!==s.eventId)throw new u("ARTIFACT_REVIEW_DECISION_REQUIRED",`Transition to ${e.toState} requires a matching decision event`,{artifactId:e.artifactId,revision:n.artifact.revision});if(e.toState==="approved"&&d.unresolvedComments>0)throw new u("ARTIFACT_UNRESOLVED_COMMENTS",`Artifact has ${d.unresolvedComments} unresolved review comment(s)`,{artifactId:e.artifactId,revision:n.artifact.revision,unresolvedComments:d.unresolvedComments})}let i=this.now(),o=n.artifact.state,r=this.createLifecycleEvent({artifact:n.artifact,sequence:n.lifecycleEvents.length+1,actor:e.actor,fromState:o,toState:e.toState,reason:e.reason,reviewEventId:e.reviewEventId,recordedAt:i});return n.artifact.state=e.toState,n.artifact.updatedAt=i,n.lifecycleEvents.push(r),n.recordVersion+=1,J(n)}async appendReviewEvent(e){let n=e.event,i=this.getMutable(n.artifactId,n.artifactRevision);if(this.assertVersion(i,e.expectedRecordVersion),i.artifact.state==="archived"||i.artifact.state==="superseded")throw new u("ARTIFACT_REVIEW_INVALID",`Cannot append review events to a ${i.artifact.state} artifact revision`,{artifactId:n.artifactId,revision:n.artifactRevision});if(this.assertReviewCommentState(i,n),(n.type==="review-requested"||n.type==="review-withdrawn"||n.type==="decision-recorded")&&i.artifact.state!=="pending_review")throw new u("ARTIFACT_REVIEW_INVALID",`${n.type} requires an artifact in pending_review state`,{artifactId:n.artifactId,revision:n.artifactRevision});let o={...structuredClone(n),schemaVersion:1,eventId:this.nextEventId("review_event"),sequence:i.reviewEvents.length+1,recordedAt:this.now()},r=Ne(o,i.artifact);if(r.length>0)throw new G("XENO artifact review event validation failed",r);return i.reviewEvents.push(o),i.recordVersion+=1,J(i)}getMutable(e,n){let i=this.records.get(e),o=n??this.currentRevisions.get(e),r=o===void 0?void 0:i?.get(o);if(!r)throw new u("ARTIFACT_NOT_FOUND",`Artifact ${e}${n===void 0?"":` revision ${n}`} was not found`,{artifactId:e,...n===void 0?{}:{revision:n}});return r}assertVersion(e,n){if(n!==void 0&&n!==e.recordVersion)throw new u("ARTIFACT_CONFLICT",`Expected record version ${n}, found ${e.recordVersion}`,{artifactId:e.artifact.artifactId,revision:e.artifact.revision,expectedRecordVersion:n,actualRecordVersion:e.recordVersion})}assertInitialState(e){if(e.state!=="draft"&&e.state!=="pending_review")throw new u("ARTIFACT_REVISION_INVALID","New artifact revisions must begin in draft or pending_review state",{artifactId:e.artifactId,revision:e.revision})}assertReviewCommentState(e,n){if(n.type==="comment-added"){if(e.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===n.commentId))throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${n.commentId} already exists`);if(n.parentCommentId&&!e.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===n.parentCommentId))throw new u("ARTIFACT_REVIEW_INVALID",`Parent comment ${n.parentCommentId} does not exist`);return}if(n.type!=="comment-resolved"&&n.type!=="comment-reopened")return;if(!e.reviewEvents.some(r=>r.type==="comment-added"&&r.commentId===n.commentId))throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${n.commentId} does not exist`);let o=On(e.reviewEvents,n.commentId);if(n.type==="comment-resolved"&&o.resolved)throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${n.commentId} is already resolved`);if(n.type==="comment-reopened"&&!o.resolved)throw new u("ARTIFACT_REVIEW_INVALID",`Comment ${n.commentId} is not resolved`)}createLifecycleEvent(e){return{schemaVersion:1,eventId:this.nextEventId("artifact_event"),artifactId:e.artifact.artifactId,revision:e.artifact.revision,sequence:e.sequence,recordedAt:e.recordedAt??this.now(),actor:{...e.actor},fromState:e.fromState,toState:e.toState,...e.reason?{reason:e.reason}:{},...e.reviewEventId?{reviewEventId:e.reviewEventId}:{}}}nextEventId(e){let n=this.idFactory(e);if(typeof n!="string"||n.trim().length===0||this.eventIds.has(n))throw new u("ARTIFACT_CONFLICT",`Event ID factory produced an invalid or duplicate ${e} ID`);return this.eventIds.add(n),n}hydrate(e){if(e.schemaVersion!==1||!Array.isArray(e.records))throw new u("ARTIFACT_REVISION_INVALID","Artifact repository state has an unsupported schema or record collection");let n=[...e.records].sort((i,o)=>i.artifact.artifactId.localeCompare(o.artifact.artifactId)||i.artifact.revision-o.artifact.revision);for(let i of n){let o=Nn(i,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[i,o]of this.records){let r=[...o.values()].sort((s,d)=>s.artifact.revision-d.artifact.revision);for(let s=0;s<r.length;s+=1){let d=r[s],a=s+1;if(d.artifact.revision!==a)throw new u("ARTIFACT_REVISION_INVALID",`Persisted artifact ${i} is missing revision ${a}`);if(s===0&&d.artifact.predecessorRevision!==void 0)throw new u("ARTIFACT_REVISION_INVALID",`Initial revision for ${i} cannot declare a predecessor`);if(s>0&&d.artifact.predecessorRevision!==a-1)throw new u("ARTIFACT_REVISION_INVALID",`Persisted revision ${i}:${a} has an invalid predecessor`);if(s<r.length-1&&d.artifact.state!=="superseded")throw new u("ARTIFACT_REVISION_INVALID",`Non-current revision ${i}:${a} must be superseded`)}}}};function Nn(t,e){if(R(t.artifact),!Number.isInteger(t.recordVersion)||t.recordVersion<1)throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact recordVersion must be a positive integer",{artifactId:t.artifact.artifactId,revision:t.artifact.revision});if(!Array.isArray(t.lifecycleEvents)||t.lifecycleEvents.length===0||!Array.isArray(t.reviewEvents))throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact records require lifecycle and review event arrays",{artifactId:t.artifact.artifactId,revision:t.artifact.revision});let n=t.lifecycleEvents.length+t.reviewEvents.length;if(t.recordVersion!==n)throw new u("ARTIFACT_REVISION_INVALID",`Persisted record version ${t.recordVersion} does not match ${n} mutations`,{artifactId:t.artifact.artifactId,revision:t.artifact.revision});let i=null;for(let r=0;r<t.lifecycleEvents.length;r+=1){let s=t.lifecycleEvents[r];if(s.schemaVersion!==1||s.artifactId!==t.artifact.artifactId||s.revision!==t.artifact.revision||s.sequence!==r+1||s.fromState!==i||typeof s.eventId!="string"||s.eventId.length===0||e.has(s.eventId)||!Number.isFinite(Date.parse(s.recordedAt)))throw new u("ARTIFACT_REVISION_INVALID",`Persisted lifecycle event ${r+1} is invalid`,{artifactId:t.artifact.artifactId,revision:t.artifact.revision});if(i===null){if(s.toState!=="draft"&&s.toState!=="pending_review")throw new u("ARTIFACT_REVISION_INVALID","A persisted artifact must begin in draft or pending_review state",{artifactId:t.artifact.artifactId,revision:t.artifact.revision})}else me(i,s.toState);e.add(s.eventId),i=s.toState}if(i!==t.artifact.state)throw new u("ARTIFACT_REVISION_INVALID","Persisted artifact state does not match its lifecycle tail",{artifactId:t.artifact.artifactId,revision:t.artifact.revision});let o=new Map;for(let r=0;r<t.reviewEvents.length;r+=1){let s=t.reviewEvents[r];if(s.sequence!==r+1||e.has(s.eventId))throw new u("ARTIFACT_REVIEW_INVALID",`Persisted review event ${r+1} has an invalid sequence or duplicate ID`,{artifactId:t.artifact.artifactId,revision:t.artifact.revision});let d=Ne(s,t.artifact);if(d.length>0)throw new G("Persisted XENO artifact review event validation failed",d);if(s.type==="comment-added"){if(o.has(s.commentId)||s.parentCommentId!==void 0&&!o.has(s.parentCommentId))throw new u("ARTIFACT_REVIEW_INVALID",`Persisted comment ${s.commentId} has an invalid identity or parent`);o.set(s.commentId,!1)}else if(s.type==="comment-resolved"||s.type==="comment-reopened"){let a=o.get(s.commentId);if(a===void 0||s.type==="comment-resolved"&&a||s.type==="comment-reopened"&&!a)throw new u("ARTIFACT_REVIEW_INVALID",`Persisted comment transition for ${s.commentId} is invalid`);o.set(s.commentId,s.type==="comment-resolved")}e.add(s.eventId)}return{artifact:ne(t.artifact),recordVersion:t.recordVersion,lifecycleEvents:structuredClone(t.lifecycleEvents),reviewEvents:structuredClone(t.reviewEvents)}}function Pn(t,e){return t.content.hash.algorithm===e.content.hash.algorithm&&t.content.hash.value===e.content.hash.value}function $n(t,e){return!(e.kinds&&!e.kinds.includes(t.kind)||e.states&&!e.states.includes(t.state)||e.runId&&t.identity?.runId!==e.runId||e.sessionId&&t.identity?.sessionId!==e.sessionId||e.turnId&&t.identity?.turnId!==e.turnId||e.taskId&&t.identity?.taskId!==e.taskId||e.workspaceId&&t.identity?.workspaceId!==e.workspaceId||e.repositoryId&&t.identity?.repositoryId!==e.repositoryId||e.producerId&&t.provenance.producer.id!==e.producerId||e.sensitivity&&!e.sensitivity.includes(t.sensitivity))}function dt(t,e){return t.artifact.createdAt.localeCompare(e.artifact.createdAt)||t.artifact.artifactId.localeCompare(e.artifact.artifactId)||t.artifact.revision-e.artifact.revision}function On(t,e){let n=!1;for(let i of t)(i.type==="comment-resolved"||i.type==="comment-reopened")&&i.commentId===e&&(n=i.type==="comment-resolved");return{resolved:n}}function ne(t){return structuredClone(t)}function J(t){return{artifact:ne(t.artifact),recordVersion:t.recordVersion,etag:`${t.artifact.artifactId}:${t.artifact.revision}:${t.recordVersion}`,lifecycleEvents:structuredClone(t.lifecycleEvents),reviewEvents:structuredClone(t.reviewEvents),reviewSummary:Pe(t.reviewEvents)}}import{randomUUID as Rt}from"node:crypto";import{mkdir as bt,open as At,readFile as Un,stat as St,unlink as Wn}from"node:fs/promises";import{basename as It,dirname as wt,join as Kn,resolve as Gn}from"node:path";import*as O from"node:fs/promises";var ft=Symbol.for("@xenosystem/agent-sdk/file-cache"),pt=globalThis,Oe=pt[ft]??{entries:new Map,counters:{reads:0,hits:0}};pt[ft]=Oe;var gr=Oe.entries,vr=Oe.counters;var Vn=new Set(["EACCES","EBUSY","EPERM"]),Dn=[10,20,40,80,160,320,640];async function ut(t,e){for(let n=0;;n+=1)try{await O.rename(t,e);return}catch(i){let o=i.code,r=Dn[n];if(process.platform!=="win32"||!o||!Vn.has(o)||r===void 0)throw i;await new Promise(s=>setTimeout(s,r))}}import{mkdirSync as Fn,readFileSync as Ln,rmSync as mt,writeFileSync as Mn}from"node:fs";import{hostname as ht}from"node:os";import{dirname as Hn}from"node:path";function jn(){return new Date().toISOString()}function Bn(){return new Date(Date.now()-Math.floor(process.uptime()*1e3)).toISOString()}function gt(t){try{return JSON.parse(Ln(t,"utf8"))}catch{return null}}function qn(t){if(!t||t<=0)return!1;try{return process.kill(t,0),!0}catch{return!1}}function Jn(t){return t.hostname!==ht()?!0:qn(t.pid)}function lt(t,e){Fn(Hn(t),{recursive:!0}),Mn(t,JSON.stringify(e,null,2)+`
|
|
2
|
+
`,{encoding:"utf8",flag:"wx"})}function zn(t,e){let n=gt(t);n?.pid!==e.pid||n.hostname!==e.hostname||mt(t,{force:!0})}function vt(t,e,n){let i=jn(),o={schemaVersion:1,name:e,pid:process.pid,hostname:ht(),processStartedAt:Bn(),version:n,acquiredAt:i,updatedAt:i};try{lt(t,o)}catch(r){if(r.code!=="EEXIST")throw r;let d=gt(t);if(d&&Jn(d))throw new Error(`${e} is already locked by PID ${d.pid} on ${d.hostname}.`);mt(t,{force:!0}),lt(t,o)}return{record:o,release:()=>{zn(t,o)}}}var yt="0.10.40";var _t=1,Yn="repository.v1.json",Zn=5e3,Qn=20,ei=64*1024*1024,Et=class{directory;snapshotPath;backupPath;lockPath;now;lockTimeoutMs;lockRetryMs;maxSnapshotBytes;onRecovery;mutationTail=Promise.resolve();constructor(e){if(!e||typeof e.directory!="string"||e.directory.trim().length===0)throw new TypeError("Artifact repository directory is required");let n=e.snapshotFileName??Yn;if(It(n)!==n||!/^[A-Za-z0-9_.-]+$/.test(n))throw new TypeError("Artifact snapshot filename must be a safe basename");this.directory=Gn(e.directory),this.snapshotPath=Kn(this.directory,n),this.backupPath=`${this.snapshotPath}.bak`,this.lockPath=`${this.snapshotPath}.lock`,this.now=e.now??(()=>new Date().toISOString()),this.lockTimeoutMs=Ve(e.lockTimeoutMs,Zn,100,6e4,"lockTimeoutMs"),this.lockRetryMs=Ve(e.lockRetryMs,Qn,1,1e3,"lockRetryMs"),this.maxSnapshotBytes=Ve(e.maxSnapshotBytes,ei,1024,1024*1024*1024,"maxSnapshotBytes"),this.onRecovery=e.onRecovery}async create(e){return this.mutate(n=>n.create(e))}async createRevision(e,n){return this.mutate(i=>i.createRevision(e,n))}async get(e,n){return(await this.load()).repository.get(e,n)}async require(e,n){return(await this.load()).repository.require(e,n)}async list(e){return(await this.load()).repository.list(e)}async listRevisions(e){return(await this.load()).repository.listRevisions(e)}async transition(e){return this.mutate(n=>n.transition(e))}async appendReviewEvent(e){return this.mutate(n=>n.appendReviewEvent(e))}async inspectSnapshot(){return this.readSnapshot(this.snapshotPath,!0)}async mutate(e){return this.enqueueMutation(async()=>{let n=await this.acquireLock();try{let i=await this.load(),o=await e(i.repository);return await this.persist(i),o}finally{n.release()}})}async enqueueMutation(e){let n=this.mutationTail.then(e,e);return this.mutationTail=n.then(()=>{},()=>{}),n}async acquireLock(){let e=Date.now(),n;for(;Date.now()-e<=this.lockTimeoutMs;)try{return vt(this.lockPath,`artifact-repository:${It(this.snapshotPath)}`,yt)}catch(i){if(!(i instanceof Error)||!/already locked by PID/.test(i.message))throw i;n=i,await oi(this.lockRetryMs)}throw new u("ARTIFACT_PERSISTENCE_LOCKED",`Artifact repository remained locked for ${this.lockTimeoutMs}ms`,{snapshotPath:this.snapshotPath},{cause:n})}async load(){let e,n,i=!1;try{n=await this.readSnapshot(this.snapshotPath,!1)}catch(r){e=ge(r)}if(!n&&(e||await ri(this.backupPath)))try{let r=await this.readSnapshot(this.backupPath,!0);r&&(this.onRecovery?.({snapshotPath:this.snapshotPath,backupPath:this.backupPath,reason:e?.message??"primary snapshot missing"}),n=r,i=!0)}catch(r){throw e?new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository primary and backup snapshots are unreadable",{snapshotPath:this.snapshotPath,backupPath:this.backupPath},{cause:new AggregateError([e,ge(r)])}):r}if(!n&&e)throw e;let o=n?.state??{schemaVersion:1,records:[]};return{repository:new ie({now:this.now,idFactory:r=>`${r}_${Rt()}`,initialState:o}),generation:n?.generation??0,createdAt:n?.createdAt??this.now(),hasSnapshot:n!==void 0,recoveredFromBackup:i,...n?{sourceSnapshot:n}:{}}}async persist(e){let n=this.now(),o={...{schemaVersion:_t,generation:e.generation,createdAt:e.createdAt,updatedAt:n,state:e.repository.exportState()},generation:e.generation+1},r=ni(o),s=`${JSON.stringify(r,null,2)}
|
|
3
|
+
`;if(Buffer.byteLength(s,"utf8")>this.maxSnapshotBytes)throw new u("ARTIFACT_PERSISTENCE_IO",`Artifact repository snapshot exceeds ${this.maxSnapshotBytes} bytes`,{snapshotPath:this.snapshotPath,maxSnapshotBytes:this.maxSnapshotBytes});await bt(this.directory,{recursive:!0,mode:448}),e.hasSnapshot&&!e.recoveredFromBackup&&e.sourceSnapshot&&await Xt(this.backupPath,`${JSON.stringify(e.sourceSnapshot,null,2)}
|
|
4
|
+
`),await Xt(this.snapshotPath,s)}async readSnapshot(e,n){let i;try{i=await St(e)}catch(o){if(!n&&Fe(o,"ENOENT")||n&&Fe(o,"ENOENT"))return;throw Le("Unable to inspect artifact repository snapshot",e,o)}if(!i.isFile()||i.size>this.maxSnapshotBytes)throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot is not a bounded regular file",{snapshotPath:e,sizeBytes:i.size,maxSnapshotBytes:this.maxSnapshotBytes});try{let o=await Un(e);if(o.byteLength>this.maxSnapshotBytes)throw new Error("snapshot grew beyond the configured size limit while reading");return ti(JSON.parse(o.toString("utf8")),e)}catch(o){throw o instanceof u?o:Le("Unable to parse artifact repository snapshot",e,o,!0)}}};function ti(t,e){if(!De(t)||t.schemaVersion!==_t||!Number.isInteger(t.generation)||t.generation<0||typeof t.createdAt!="string"||!Number.isFinite(Date.parse(t.createdAt))||typeof t.updatedAt!="string"||!Number.isFinite(Date.parse(t.updatedAt))||!De(t.state)||t.state.schemaVersion!==1||!Array.isArray(t.state.records)||!De(t.checksum)||t.checksum.algorithm!=="sha256"||typeof t.checksum.value!="string")throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot envelope is invalid",{snapshotPath:e});let n=t,i=ii(n),o=xt(i);if(n.checksum.value!==o)throw new u("ARTIFACT_PERSISTENCE_CORRUPT","Artifact repository snapshot checksum does not match its payload",{snapshotPath:e});return new ie({initialState:n.state}),structuredClone(n)}function ni(t){return{...structuredClone(t),checksum:{algorithm:"sha256",value:xt(t)}}}function ii(t){return{schemaVersion:t.schemaVersion,generation:t.generation,createdAt:t.createdAt,updatedAt:t.updatedAt,state:t.state}}function xt(t){return x(JSON.stringify(t)).value}async function Xt(t,e){await bt(wt(t),{recursive:!0,mode:448});let n=`${t}.tmp.${process.pid}.${Rt()}`,i;try{i=await At(n,"wx",384),await i.writeFile(e,{encoding:"utf8"}),await i.sync(),await i.close(),i=void 0,await ut(n,t);try{let o=await At(wt(t),"r");try{await o.sync()}finally{await o.close()}}catch{}}finally{i&&await i.close().catch(()=>{}),await Wn(n).catch(()=>{})}}function Ve(t,e,n,i,o){if(t===void 0)return e;if(!Number.isInteger(t)||t<n||t>i)throw new TypeError(`${o} must be an integer between ${n} and ${i}`);return t}function De(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Fe(t,e){return t instanceof Error&&t.code===e}async function ri(t){try{return(await St(t)).isFile()}catch(e){if(Fe(e,"ENOENT"))return!1;throw Le("Unable to inspect artifact repository backup",t,e)}}function ge(t){return t instanceof Error?t:new Error(String(t))}function Le(t,e,n,i=!1){return new u(i?"ARTIFACT_PERSISTENCE_CORRUPT":"ARTIFACT_PERSISTENCE_IO",`${t}: ${ge(n).message}`,{snapshotPath:e},{cause:ge(n)})}function oi(t){return new Promise(e=>setTimeout(e,t))}import{Buffer as Nt}from"node:buffer";var si=16*1024*1024,ai=5e3,ci=1e5,di=1e6,fi=/^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?:\s?(.*))?$/,_=class extends Error{constructor(n,i){super(i===void 0?n:`${n} at diff line ${i}`);this.line=i;this.name="XenoDiffParseError"}line;code="XENO_DIFF_INVALID"};function Pt(t,e={}){if(typeof t!="string")throw new TypeError("Unified diff must be a string");let n=ve(e.maxBytes,si,1024,256*1024*1024,"maxBytes"),i=ve(e.maxFiles,ai,1,1e5,"maxFiles"),o=ve(e.maxHunks,ci,1,1e6,"maxHunks"),r=ve(e.maxLines,di,1,5e6,"maxLines");if(Nt.byteLength(t,"utf8")>n)throw new _(`Unified diff exceeds ${n} bytes`);let s=t.replace(/\r\n/g,`
|
|
5
5
|
`).replace(/\r/g,`
|
|
6
6
|
`),d=s.length===0?[]:s.split(`
|
|
7
|
-
`);if(d.length>r)throw new _(`Unified diff exceeds ${r} lines`);let a=[],c,f=0,g=(m,h)=>{if(c&&
|
|
8
|
-
`:i==="r"?"\r":i==="\\"?"\\":i==='"'?'"':String.fromCharCode(Number.parseInt(i,8)))}function _t(t){let e=t.split(" ",1)[0].trim();if(e!=="/dev/null")return U(Pt(e))}function U(t){let e=t.replace(/\\/g,"/");return e.startsWith("a/")||e.startsWith("b/")?e.slice(2):e}function fi(t){return!xt(t)||t.schemaVersion!==1||!["working-tree","staged","turn","commit","preview"].includes(String(t.mode))||!Array.isArray(t.files)||!Number.isSafeInteger(t.additions)||!Number.isSafeInteger(t.deletions)||typeof t.rawDiff!="string"?!1:t.files.every(e=>xt(e)&&typeof e.displayPath=="string"&&Array.isArray(e.headerLines)&&Array.isArray(e.hunks))}function xt(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function ve(t,e,n,i,o){if(t===void 0)return e;if(!Number.isInteger(t)||t<n||t>i)throw new TypeError(`${o} must be an integer between ${n} and ${i}`);return t}function pi(t){return t.split("-").map(e=>e[0].toUpperCase()+e.slice(1)).join(" ")}function ui(t){return t instanceof Error?t:new Error(String(t))}import{randomUUID as li}from"node:crypto";var re=class{repository;actor;idFactory;constructor(e){if(!e?.repository)throw new TypeError("Artifact repository is required");if(!e.actor?.kind||!e.actor.id?.trim())throw new TypeError("Review actor is required");this.repository=e.repository,this.actor=structuredClone(e.actor),this.idFactory=e.idFactory??(()=>`comment_${li()}`)}async addComment(e){let n=Ae(e.body,"Review comment body",65536),i=await this.repository.require(e.artifactId,e.revision),o=$t(i,e),r=ye(this.idFactory(),"Comment ID"),s=hi(e.parentCommentId,"Parent comment ID");return this.repository.appendReviewEvent({expectedRecordVersion:i.recordVersion,event:{type:"comment-added",artifactId:i.artifact.artifactId,artifactRevision:i.artifact.revision,artifactHash:i.artifact.content.hash,actor:this.actor,commentId:r,body:n,...o?{anchor:o}:{},...s?{parentCommentId:s}:{}}})}async setCommentResolution(e){let n=ye(e.commentId,"Review comment ID"),i=Vt(e.reason,"Resolution reason",16*1024),o=await this.repository.require(e.artifactId,e.revision);return this.repository.appendReviewEvent({expectedRecordVersion:o.recordVersion,event:{type:e.resolved?"comment-resolved":"comment-reopened",artifactId:o.artifact.artifactId,artifactRevision:o.artifact.revision,artifactHash:o.artifact.content.hash,actor:this.actor,commentId:n,...i?{reason:i}:{}}})}async decide(e){let n=await this.repository.require(e.artifactId,e.revision);if(n.artifact.state!=="pending_review")throw new u("ARTIFACT_REVIEW_INVALID",`Artifact must be pending_review, found ${n.artifact.state}`);let i=$t(n,e),o=Vt(e.rationale,"Decision rationale",64*1024),r=await this.repository.appendReviewEvent({expectedRecordVersion:n.recordVersion,event:{type:"decision-recorded",artifactId:n.artifact.artifactId,artifactRevision:n.artifact.revision,artifactHash:n.artifact.content.hash,actor:this.actor,decision:e.decision,...o?{rationale:o}:{},...i?{scope:i}:{}}});if(i||e.decision==="changes_requested")return r;let s=r.reviewEvents.at(-1);if(!s||s.type!=="decision-recorded")throw new u("ARTIFACT_REVIEW_INVALID","Artifact decision event was not recorded");return this.repository.transition({artifactId:r.artifact.artifactId,revision:r.artifact.revision,expectedRecordVersion:r.recordVersion,toState:e.decision,actor:this.actor,reviewEventId:s.eventId,...o?{reason:o}:{}})}};function $t(t,e){if((e.line!==void 0||e.hunkId!==void 0)&&!e.file)throw F("Line and hunk anchors require a file");if(e.line!==void 0&&e.hunkId!==void 0)throw F("Line and hunk anchors cannot be combined");if(!e.file)return;let n=mi(e.file);if(e.line!==void 0&&(!Number.isInteger(e.line)||e.line<1))throw F("Review line must be a positive integer");if(t.artifact.kind==="diff"||t.artifact.kind==="patch"){let o=Nt(t.artifact).files.find(r=>r.displayPath===n);if(!o)throw F(`File ${n} is not present in this artifact`);if(e.hunkId&&!o.hunks.some(r=>r.hunkId===e.hunkId))throw F(`Hunk ${e.hunkId} is not present in ${n}`)}return e.hunkId?{kind:"diff-hunk",path:n,hunkId:ye(e.hunkId,"Hunk ID"),artifactId:t.artifact.artifactId,revision:t.artifact.revision}:e.line!==void 0?{kind:"source-line",path:n,startLine:e.line}:{kind:"file",path:n}}function mi(t){let e=Ae(t,"Artifact review file",4096).replace(/\\/g,"/").replace(/^\.\//,"");if(e.startsWith("../")||e.startsWith("/")||/^[A-Za-z]:\//.test(e)||e.split("/").some(n=>n===".."||n.length===0))throw F("Artifact review file anchors must be repository-relative paths");return e}function Ae(t,e,n){let i=typeof t=="string"?t.trim():"";if(!i)throw F(`${e} cannot be empty`);if(i.length>n)throw F(`${e} exceeds ${n} characters`);return i}function Vt(t,e,n){if(t!==void 0)return Ae(t,e,n)}function ye(t,e){let n=Ae(t,e,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(n))throw F(`${e} contains unsupported characters`);return n}function hi(t,e){return t===void 0?void 0:ye(t,e)}function F(t){return new u("ARTIFACT_REVIEW_INVALID",t)}import{randomUUID as gi}from"node:crypto";var ae="xeno.spec.v1",we="xeno.spec-execution.v1",b=class extends Error{constructor(n){super(`XENO spec is invalid: ${n.join("; ")}`);this.issues=n;this.name="XenoSpecValidationError"}issues;code="XENO_SPEC_INVALID"},Ot=class{repository;now;idFactory;constructor(e){if(!e?.repository)throw new TypeError("Artifact repository is required");this.repository=e.repository,this.now=e.now??(()=>new Date().toISOString()),this.idFactory=e.idFactory??(()=>gi())}async create(e,n){if(e.revision!==1||e.predecessorRevision!==void 0)throw new b(["A new spec must begin at revision 1 without a predecessor"]);let i=Dt(e,n);return await this.repository.create(i.requirements),await this.repository.create(i.design),await this.repository.create(i.taskGraph),await this.repository.create(i.plan),i}async revise(e,n){let i=oe(e.specId),o=await this.repository.require(i.plan);if(e.revision!==o.artifact.revision+1||e.predecessorRevision!==o.artifact.revision)throw new b([`Revision ${e.revision} must follow approved or reviewed revision ${o.artifact.revision}`]);let r=Dt(e,n);return await this.repository.createRevision(r.requirements,{actor:n.producer,reason:"spec-revised"}),await this.repository.createRevision(r.design,{actor:n.producer,reason:"spec-revised"}),await this.repository.createRevision(r.taskGraph,{actor:n.producer,reason:"spec-revised"}),await this.repository.createRevision(r.plan,{actor:n.producer,reason:"spec-revised"}),r}async approve(e,n,i){return new re({repository:this.repository,actor:n}).decide({artifactId:oe(e).plan,decision:"approved",...i?{rationale:i}:{}})}async reject(e,n,i){return new re({repository:this.repository,actor:n}).decide({artifactId:oe(e).plan,decision:"rejected",rationale:i})}async startExecution(e,n){let i=await this.repository.require(oe(e).plan);if(i.artifact.state!=="approved")throw new b([`Spec ${e} must be approved before execution`]);let o=Ft(i.artifact),r=this.now(),s={schemaVersion:we,executionId:`spec_execution_${this.idFactory()}`,specId:o.specId,specRevision:o.revision,planArtifactId:i.artifact.artifactId,planHash:{...i.artifact.content.hash},state:"ready",createdAt:r,updatedAt:r,observedPaths:[],tasks:o.tasks.map(d=>({taskId:d.id,status:"pending",evidence:[],acceptanceEvidence:Object.fromEntries(d.acceptanceCriterionIds.map(a=>[a,[]]))}))};return this.repository.create(Lt(s,{producer:n,identity:i.artifact.identity,sensitivity:i.artifact.sensitivity,accessPolicyId:i.artifact.accessPolicyId}))}async updateExecution(e,n,i){let o=await this.repository.require(e),r=yi(o.artifact),s=await this.repository.require(r.planArtifactId,r.specRevision);if(s.artifact.state!=="approved"||!de(s.artifact.content.hash,r.planHash))throw new b(["Execution is no longer bound to the approved plan revision"]);let d=n(structuredClone(r));d.schemaVersion=we,d.executionId=r.executionId,d.specId=r.specId,d.specRevision=r.specRevision,d.planArtifactId=r.planArtifactId,d.planHash={...r.planHash},d.createdAt=r.createdAt,d.updatedAt=this.now(),Mt(d,Ft(s.artifact));let a=Lt(d,{producer:i,identity:o.artifact.identity,sensitivity:o.artifact.sensitivity,accessPolicyId:o.artifact.accessPolicyId},o.artifact.revision+1,o.artifact.revision);return this.repository.createRevision(a,{actor:i,reason:"spec-execution-updated"})}};function oe(t){let e=Ii(t,"specId");return{plan:`spec_${e}_plan`,requirements:`spec_${e}_requirements`,design:`spec_${e}_design`,taskGraph:`spec_${e}_task_graph`}}function vi(t){let e=[];t?.schemaVersion!==ae&&e.push(`schemaVersion must be ${ae}`),ce(t?.specId,"specId",e),(!Number.isInteger(t?.revision)||t.revision<1)&&e.push("revision must be a positive integer"),C(t?.title,"title",e),C(t?.problem,"problem",e),Ee(t?.createdAt,"createdAt",e),Ee(t?.updatedAt,"updatedAt",e),t?.predecessorRevision!==void 0&&(!Number.isInteger(t.predecessorRevision)||t.predecessorRevision!==t.revision-1)&&e.push("predecessorRevision must be the immediately preceding revision");let n=Ie(t?.requirements,"requirement",e),i=Ie(t?.tasks,"task",e),o=new Set,r=[...Array.isArray(t?.acceptanceCriteria)?t.acceptanceCriteria:[],...Array.isArray(t?.requirements)?t.requirements.flatMap(a=>Array.isArray(a.acceptanceCriteria)?a.acceptanceCriteria:[]):[]];for(let a of r){ce(a?.id,"acceptance criterion id",e),C(a?.text,`acceptance criterion ${a?.id??"?"}`,e),o.has(a?.id)&&e.push(`Duplicate acceptance criterion: ${a?.id}`),o.add(a?.id);for(let c of a?.requiredEvidenceKinds??[])ce(c,"required evidence kind",e)}for(let a of t?.requirements??[])C(a?.text,`requirement ${a?.id??"?"}`,e),["must","should","could"].includes(a?.priority)||e.push(`Requirement ${a?.id??"?"} has invalid priority`),(!Array.isArray(a?.acceptanceCriteria)||a.acceptanceCriteria.length===0)&&e.push(`Requirement ${a?.id??"?"} needs at least one acceptance criterion`);C(t?.design?.summary,"design summary",e);let s=Ie(t?.design?.decisions,"design decision",e),d=Ie(t?.design?.risks,"risk",e);for(let a of t?.design?.decisions??[]){C(a?.decision,`design decision ${a?.id??"?"}`,e),C(a?.rationale,`design rationale ${a?.id??"?"}`,e);for(let c of a?.requirementIds??[])n.has(c)||e.push(`Design decision ${a.id} references unknown requirement ${c}`)}for(let a of t?.design?.risks??[])C(a?.description,`risk ${a?.id??"?"}`,e),C(a?.mitigation,`risk mitigation ${a?.id??"?"}`,e),["low","medium","high","critical"].includes(a?.impact)||e.push(`Risk ${a?.id??"?"} has invalid impact`);for(let a of t?.tasks??[]){C(a?.title,`task title ${a?.id??"?"}`,e),C(a?.description,`task description ${a?.id??"?"}`,e);for(let c of a?.dependsOn??[])i.has(c)||e.push(`Task ${a.id} depends on unknown task ${c}`),c===a.id&&e.push(`Task ${a.id} cannot depend on itself`);for(let c of a?.requirementIds??[])n.has(c)||e.push(`Task ${a.id} references unknown requirement ${c}`);for(let c of a?.acceptanceCriterionIds??[])o.has(c)||e.push(`Task ${a.id} references unknown acceptance criterion ${c}`);for(let c of a?.expectedPaths??[])jt(c)||e.push(`Task ${a.id} has unsafe expected path ${c}`)}return wi(t?.tasks??[])&&e.push("Task dependency graph contains a cycle"),[...new Set(e)]}function Le(t){let e=vi(t);if(e.length>0)throw new b(e)}function Dt(t,e){Le(t);let n=oe(t.specId),i=t.revision,o={...e,createdAt:t.updatedAt,state:"draft"},r=se({artifactId:n.requirements,revision:i,predecessorRevision:t.predecessorRevision,kind:"requirements",title:`${t.title} - requirements`,value:{schemaVersion:ae,specId:t.specId,revision:i,problem:t.problem,requirements:t.requirements,acceptanceCriteria:t.acceptanceCriteria},context:o}),s=se({artifactId:n.design,revision:i,predecessorRevision:t.predecessorRevision,kind:"design",title:`${t.title} - design`,value:{schemaVersion:ae,specId:t.specId,revision:i,design:t.design,...t.sourceBaseline?{sourceBaseline:t.sourceBaseline}:{}},context:o}),d=se({artifactId:n.taskGraph,revision:i,predecessorRevision:t.predecessorRevision,kind:"task-graph",title:`${t.title} - task graph`,value:{schemaVersion:ae,specId:t.specId,revision:i,tasks:t.tasks},context:o}),a=[r,s,d].map(f=>({relation:"decomposes",target:{type:"artifact",id:f.artifactId,revision:f.revision}})),c=se({artifactId:n.plan,revision:i,predecessorRevision:t.predecessorRevision,kind:"plan",title:t.title,description:t.problem,value:t,context:{...e,createdAt:t.updatedAt,state:"pending_review"},relationships:a,extensions:{"xeno.spec.id":t.specId,"xeno.spec.revision":t.revision,"xeno.spec.requirements_hash":r.content.hash.value,"xeno.spec.design_hash":s.content.hash.value,"xeno.spec.task_graph_hash":d.content.hash.value}});return{document:structuredClone(t),plan:c,requirements:r,design:s,taskGraph:d}}function Ft(t){if(t.kind!=="plan"||t.mediaType!=="application/vnd.xeno.spec+json")throw new b([`Artifact ${t.artifactId} is not a XENO spec plan`]);let e=Ht(t);if(Le(e),e.revision!==t.revision)throw new b(["Spec and artifact revisions differ"]);if(!de(k(e),t.content.hash))throw new b(["Spec artifact content hash is invalid"]);return structuredClone(e)}function Lt(t,e,n=1,i){let o=structuredClone(t);return se({artifactId:t.executionId,revision:n,predecessorRevision:i,kind:"custom:xeno.spec-execution",title:`Execution of ${t.specId} revision ${t.specRevision}`,description:`Execution state: ${t.state}`,value:o,context:{...e,createdAt:t.updatedAt,state:t.state==="completed"?"pending_review":"draft"},relationships:[{relation:"implements",target:{type:"artifact",id:t.planArtifactId,revision:t.specRevision}}],extensions:{"xeno.spec.execution_state":t.state,"xeno.spec.plan_hash":t.planHash.value}})}function yi(t){if(t.kind!=="custom:xeno.spec-execution")throw new b([`Artifact ${t.artifactId} is not a spec execution`]);let e=Ht(t);if(e.schemaVersion!==we||e.executionId!==t.artifactId)throw new b(["Spec execution identity or schema is invalid"]);if(!de(k(e),t.content.hash))throw new b(["Spec execution content hash is invalid"]);return structuredClone(e)}function Mt(t,e){let n=[];t.schemaVersion!==we&&n.push("Execution schema is invalid"),(t.specId!==e.specId||t.specRevision!==e.revision)&&n.push("Execution is bound to the wrong spec revision");let i=new Map(e.tasks.map(r=>[r.id,r])),o=new Set;for(let r of t.tasks){o.has(r.taskId)&&n.push(`Duplicate execution task ${r.taskId}`),o.add(r.taskId);let s=i.get(r.taskId);if(!s){n.push(`Unknown execution task ${r.taskId}`);continue}for(let d of s.acceptanceCriterionIds)Array.isArray(r.acceptanceEvidence?.[d])||n.push(`Task ${r.taskId} is missing acceptance evidence slot ${d}`)}for(let r of i.keys())o.has(r)||n.push(`Execution is missing task ${r}`);for(let r of t.observedPaths)Ei(r)||n.push(`Unsafe observed path ${r}`);if(Ee(t.createdAt,"execution createdAt",n),Ee(t.updatedAt,"execution updatedAt",n),n.length>0)throw new b([...new Set(n)])}function jr(t,e,n,i,o=new Date().toISOString()){Le(t),Mt(n,t);let r=[];(!de(e,i)||!de(n.planHash,i))&&r.push({code:"PLAN_HASH_MISMATCH",severity:"error",message:"Execution is not bound to the approved plan content hash"});let s=new Map(t.tasks.map(c=>[c.id,c])),d=new Map(n.tasks.map(c=>[c.taskId,c]));for(let c of n.tasks){let f=s.get(c.taskId);if(!f){r.push({code:"UNKNOWN_TASK",severity:"error",taskId:c.taskId,message:`Unknown task ${c.taskId}`});continue}if(c.status==="completed"){c.evidence.length===0&&r.push({code:"MISSING_TASK_EVIDENCE",severity:"error",taskId:f.id,message:`Completed task ${f.id} has no evidence`});for(let g of f.dependsOn??[])d.get(g)?.status!=="completed"&&r.push({code:"DEPENDENCY_INCOMPLETE",severity:"error",taskId:f.id,message:`Task ${f.id} completed before dependency ${g}`});for(let g of f.acceptanceCriterionIds)(c.acceptanceEvidence[g]??[]).length===0&&r.push({code:"MISSING_ACCEPTANCE_EVIDENCE",severity:"error",taskId:f.id,criterionId:g,message:`Completed task ${f.id} has no evidence for ${g}`})}}let a=t.tasks.flatMap(c=>c.expectedPaths??[]);for(let c of n.observedPaths)a.some(f=>Xi(c,f))||r.push({code:"UNKNOWN_PATH",severity:"warning",path:c,message:`Observed path ${c} is outside the approved task plan`});return{schemaVersion:"xeno.spec-drift.v1",specId:t.specId,specRevision:t.revision,executionId:n.executionId,checkedAt:o,drifted:r.length>0,findings:r}}function se(t){let e=t.value,n=T(e);return{schemaVersion:1,artifactId:t.artifactId,revision:t.revision,kind:t.kind,title:t.title,...t.description?{description:t.description}:{},state:t.context.state,createdAt:t.context.createdAt??new Date().toISOString(),mediaType:Ai(t.kind),sensitivity:t.context.sensitivity??"internal",...t.context.identity?{identity:structuredClone(t.context.identity)}:{},content:{hash:k(e),sizeBytes:Buffer.byteLength(n,"utf8"),encoding:"utf8",storage:{type:"inline",text:n},redactedPreview:t.title},provenance:{producer:structuredClone(t.context.producer)},...t.relationships?.length?{relationships:structuredClone(t.relationships)}:{},...t.predecessorRevision!==void 0?{predecessorRevision:t.predecessorRevision}:{},...t.context.accessPolicyId?{accessPolicyId:t.context.accessPolicyId}:{},...t.extensions?{extensions:structuredClone(t.extensions)}:{}}}function Ai(t){return t==="plan"?"application/vnd.xeno.spec+json":t==="custom:xeno.spec-execution"?"application/vnd.xeno.spec-execution+json":`application/vnd.xeno.spec-${t}+json`}function Ht(t){let e=t.content.storage;if(e.type!=="inline"||typeof e.text!="string")throw new b(["Spec artifacts require inline JSON content"]);try{return JSON.parse(e.text)}catch(n){throw new b([`Spec artifact JSON is invalid: ${n instanceof Error?n.message:String(n)}`])}}function Ie(t,e,n){let i=new Set;(!Array.isArray(t)||t.length===0)&&n.push(`${e} list cannot be empty`);for(let o of t??[])ce(o?.id,`${e} id`,n),i.has(o?.id??"")&&n.push(`Duplicate ${e}: ${o?.id}`),o?.id&&i.add(o.id);return i}function ce(t,e,n){(typeof t!="string"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(t))&&n.push(`${e} must match [A-Za-z0-9][A-Za-z0-9._-]{0,127}`)}function C(t,e,n){(typeof t!="string"||t.trim().length===0||t.length>64*1024)&&n.push(`${e} must be non-empty and no longer than 65536 characters`)}function Ee(t,e,n){(typeof t!="string"||!t.includes("T")||!Number.isFinite(Date.parse(t)))&&n.push(`${e} must be an ISO 8601 timestamp`)}function Ii(t,e){let n=[];if(ce(t,e,n),n.length>0)throw new b(n);return t}function wi(t){let e=new Map(t.map(r=>[r.id,r])),n=new Set,i=new Set,o=r=>{if(n.has(r))return!0;if(i.has(r))return!1;n.add(r);for(let s of e.get(r)?.dependsOn??[])if(o(s))return!0;return n.delete(r),i.add(r),!1};return t.some(r=>o(r.id))}function jt(t){let e=t.replace(/\\/gu,"/");return e.length>0&&e.length<=4096&&!e.startsWith("/")&&!/^[A-Za-z]:/u.test(e)&&!e.split("/").includes("..")}function Ei(t){return jt(t)&&!t.includes("*")}function Xi(t,e){let n=t.replace(/\\/gu,"/"),i=e.replace(/\\/gu,"/");if(i.endsWith("/**")){let o=i.slice(0,-3).replace(/\/$/u,"");return n===o||n.startsWith(`${o}/`)}if(i.endsWith("/*")){let o=i.slice(0,-2).replace(/\/$/u,""),r=n.startsWith(`${o}/`)?n.slice(o.length+1):"";return r.length>0&&!r.includes("/")}return n===i}function de(t,e){return t.algorithm===e.algorithm&&t.value===e.value}import{randomUUID as Ri}from"node:crypto";var qt="xeno.review-report.v1",bi=["correctness","security","performance","api","tests","documentation"],Si=["source","test","trace","artifact","reproduction","benchmark"],S=class extends Error{constructor(n){super(`XENO review is invalid: ${n.join("; ")}`);this.issues=n;this.name="XenoReviewValidationError"}issues;code="XENO_REVIEW_INVALID"},Bt=class{reviewer;verifier;now;idFactory;constructor(e){if(typeof e?.reviewer!="function")throw new TypeError("Review agent executor is required");this.reviewer=e.reviewer,this.verifier=e.verifier,this.now=e.now??(()=>new Date().toISOString()),this.idFactory=e.idFactory??(n=>`${n}_${Ri()}`)}async run(e){Jt(e.pack),Ut(e.target),Xe(e.runId,"runId");let n=this.now(),i=await Promise.all(e.pack.dimensions.map(async(a,c)=>{let f=await this.reviewer({...e,dimension:a,reviewerSlot:c});return Ti(f,a,e.pack.maxFindings),structuredClone(f)})),o=i.flatMap(a=>a.findings.map(c=>({finding:c,reviewerAgentId:a.reviewerAgentId})));if(o.length>e.pack.maxFindings)throw new S([`Reviewers returned ${o.length} findings, exceeding maxFindings ${e.pack.maxFindings}`]);let r=_i(o,this.idFactory);for(let a of r){let c=this.verifier?await Promise.all(Array.from({length:e.pack.verifierCount},async(m,h)=>{let E=await this.verifier({...e,finding:structuredClone(a),verifierSlot:h});return ki(E),structuredClone(E)})):[];a.verifications=Ci(c),a.evidence=zt([...a.evidence,...a.verifications.flatMap(m=>m.evidence)]);let f=new Set(a.verifications.filter(m=>m.outcome==="reproduced").map(m=>m.verifierAgentId)).size,g=a.verifications.length>0&&a.verifications.every(m=>m.outcome==="rejected"),y=new Set(a.evidence.map(m=>m.producerId)).size;f>=e.pack.minimumVerifierReproductions?(a.state="verified",a.verificationBasis="verifier"):e.pack.allowIndependentEvidenceVerification&&y>=e.pack.minimumIndependentEvidenceProducers?(a.state="verified",a.verificationBasis="independent-evidence"):g?(a.state="rejected",a.verificationBasis="verifier"):(a.state="unverified",a.verificationBasis="none");let P=a.verifications.map(m=>m.confidence).filter(m=>m!==void 0);P.length>0&&(a.confidence=en(Math.min(a.confidence,...P)))}r.sort(Ni);let s=this.now(),d={schemaVersion:qt,reportId:Xe(this.idFactory("report"),"reportId"),runId:e.runId,pack:structuredClone(e.pack),target:structuredClone(e.target),startedAt:n,completedAt:s,reviewers:i.map(a=>({agentId:a.reviewerAgentId,dimension:a.dimension,findingCount:a.findings.length})),findings:r,summary:Yt(r)};return be(d),d}};function Gr(t="xeno-production-review"){return{schemaVersion:"xeno.review-pack.v1",packId:t,version:"1.0.0",dimensions:["correctness","security","performance","api","tests","documentation"],verifierCount:1,minimumVerifierReproductions:1,allowIndependentEvidenceVerification:!1,minimumIndependentEvidenceProducers:2,maxFindings:256}}function Jt(t){let e=[];t?.schemaVersion!=="xeno.review-pack.v1"&&e.push("Review pack schemaVersion must be xeno.review-pack.v1"),N(t?.packId,"packId",e),(typeof t?.version!="string"||!/^\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?$/u.test(t.version))&&e.push("Review pack version must be semantic version text"),(!Array.isArray(t?.dimensions)||t.dimensions.length===0)&&e.push("Review pack needs at least one dimension"),new Set(t?.dimensions??[]).size!==(t?.dimensions??[]).length&&e.push("Review pack dimensions must be unique");for(let n of t?.dimensions??[])Qt(n)||e.push(`Invalid review dimension ${n}`);if((!Number.isInteger(t?.verifierCount)||t.verifierCount<0||t.verifierCount>8)&&e.push("verifierCount must be 0 through 8"),(!Number.isInteger(t?.minimumVerifierReproductions)||t.minimumVerifierReproductions<1||t.minimumVerifierReproductions>Math.max(1,t.verifierCount))&&e.push("minimumVerifierReproductions must be positive and no greater than verifierCount"),(!Number.isInteger(t?.minimumIndependentEvidenceProducers)||t.minimumIndependentEvidenceProducers<2)&&e.push("minimumIndependentEvidenceProducers must be at least 2"),(!Number.isInteger(t?.maxFindings)||t.maxFindings<1||t.maxFindings>2048)&&e.push("maxFindings must be 1 through 2048"),e.length>0)throw new S(e)}function Ut(t){let e=[];if(N(t?.artifactId,"target artifactId",e),(!Number.isInteger(t?.revision)||t.revision<1)&&e.push("Target revision must be positive"),W(t?.title,"target title",e),(t?.contentHash?.algorithm!=="sha256"||!/^[a-f0-9]{64}$/u.test(t?.contentHash?.value??""))&&e.push("Target contentHash must be lowercase sha256"),e.length>0)throw new S(e)}function be(t){let e=[];t?.schemaVersion!==qt&&e.push("Review report schemaVersion is invalid"),N(t?.reportId,"reportId",e),N(t?.runId,"runId",e),Re(t?.startedAt,"startedAt",e),Re(t?.completedAt,"completedAt",e),Date.parse(t?.completedAt)<Date.parse(t?.startedAt)&&e.push("completedAt cannot precede startedAt");try{Jt(t.pack)}catch(r){e.push(r instanceof Error?r.message:String(r))}try{Ut(t.target)}catch(r){e.push(r instanceof Error?r.message:String(r))}let n=new Set,i=new Set;for(let r of t?.findings??[])N(r?.findingId,"findingId",e),n.has(r.findingId)&&e.push(`Duplicate findingId ${r.findingId}`),n.add(r.findingId),/^[a-f0-9]{64}$/u.test(r?.fingerprint??"")||e.push(`Finding ${r.findingId} has invalid fingerprint`),i.has(r.fingerprint)&&e.push(`Duplicate finding fingerprint ${r.fingerprint}`),i.add(r.fingerprint),W(r?.title,`finding ${r.findingId} title`,e),W(r?.summary,`finding ${r.findingId} summary`,e),Zt(r?.severity)||e.push(`Finding ${r.findingId} has invalid severity`),(!Number.isFinite(r?.confidence)||r.confidence<0||r.confidence>1)&&e.push(`Finding ${r.findingId} has invalid confidence`),r?.state==="verified"&&r.verificationBasis==="none"&&e.push(`Finding ${r.findingId} cannot be verified without a basis`),r?.state!=="verified"&&r.verificationBasis==="independent-evidence"&&e.push(`Finding ${r.findingId} has inconsistent evidence verification`);let o=Yt(t?.findings??[]);if((o.total!==t?.summary?.total||o.verified!==t?.summary?.verified||o.unverified!==t?.summary?.unverified||o.rejected!==t?.summary?.rejected||Object.keys(o.bySeverity).some(r=>o.bySeverity[r]!==t?.summary?.bySeverity?.[r]))&&e.push("Review report summary is inconsistent"),e.length>0)throw new S([...new Set(e)])}function Kr(t,e){be(t);let n=t,i=T(n),o=e.artifactId??`review_${x(`${t.runId}:${t.target.artifactId}:${t.target.contentHash.value}`).value.slice(0,24)}`,r={schemaVersion:1,artifactId:o,revision:1,kind:"review-report",title:`Review of ${t.target.title}`,description:`${t.summary.verified} verified, ${t.summary.unverified} unverified, ${t.summary.rejected} rejected findings`,state:"pending_review",createdAt:e.createdAt??t.completedAt,mediaType:"application/vnd.xeno.review-report+json",sensitivity:e.sensitivity??"internal",...e.identity?{identity:structuredClone(e.identity)}:{},content:{hash:k(n),sizeBytes:Buffer.byteLength(i,"utf8"),encoding:"utf8",storage:{type:"inline",text:i},redactedPreview:`${t.summary.total} findings; ${t.summary.verified} verified`},provenance:{producer:structuredClone(e.producer),sourceArtifactIds:[t.target.artifactId],attributes:{reviewPackId:t.pack.packId,reviewPackVersion:t.pack.version}},relationships:[{relation:"reviews",target:{type:"artifact",id:t.target.artifactId,revision:t.target.revision}}],anchors:Gt(t.findings.flatMap(s=>s.anchors)),...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},extensions:{"xeno.review.pack":t.pack.packId,"xeno.review.verified":t.summary.verified,"xeno.review.unverified":t.summary.unverified,"xeno.review.rejected":t.summary.rejected}};return R(r),r}function Yr(t){if(t.kind!=="review-report"||t.mediaType!=="application/vnd.xeno.review-report+json")throw new S([`Artifact ${t.artifactId} is not a XENO review report`]);if(t.content.storage.type!=="inline"||typeof t.content.storage.text!="string")throw new S(["Review report requires inline JSON content"]);let e;try{e=JSON.parse(t.content.storage.text)}catch(n){throw new S([`Review report JSON is invalid: ${n instanceof Error?n.message:String(n)}`])}if(be(e),!$i(k(e),t.content.hash))throw new S(["Review report content hash is invalid"]);return structuredClone(e)}function Zr(t,e={}){be(t);let n=[];for(let i of t.findings){if(e.verifiedOnly!==!1&&i.state!=="verified")continue;let o=i.anchors.find(r=>r.kind==="source-line"||r.kind==="file"||r.kind==="diff-hunk");!o||!("path"in o)||n.push({findingId:i.findingId,path:o.path,...o.kind==="source-line"?{line:o.startLine}:{},severity:i.severity,verified:i.state==="verified",body:[`**${i.severity.toUpperCase()} - ${i.title}**`,"",i.summary,"",`Evidence: ${i.evidence.map(r=>r.summary).join("; ")||"none"}`,i.remediation?`Suggested remediation: ${i.remediation}`:"",`XENO finding: ${i.findingId} (${i.state}, confidence ${i.confidence.toFixed(2)})`].filter(Boolean).join(`
|
|
9
|
-
`)})}return n}function
|
|
10
|
-
`),{artifactId:e.artifactId??`turn_diff_${t.turnId}`,revision:e.revision??1,createdAt:e.createdAt??t.completedAt,title:`Turn ${t.turnId} changes`,producer:e.producer,identity:{...e.identity?structuredClone(e.identity):{},turnId:e.identity?.turnId??t.turnId},sensitivity:e.sensitivity??"internal",...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},mode:"turn"}),d={...s,state:e.state??s.state,extensions:{...s.extensions??{},"xeno.legacy.turnDiffSummary":n}};return R(d),d}catch{}let o=T(n),r={schemaVersion:1,artifactId:e.artifactId??`turn_diff_${t.turnId}`,revision:e.revision??1,kind:"diff",title:`Turn ${t.turnId} changes`,state:e.state??"pending_review",createdAt:e.createdAt??t.completedAt,mediaType:"application/vnd.xeno.turn-diff+json",sensitivity:e.sensitivity??"internal",identity:{...e.identity?structuredClone(e.identity):{},turnId:e.identity?.turnId??t.turnId},content:{hash:k(n),sizeBytes:Se.byteLength(o,"utf8"),encoding:"utf8",storage:{type:"inline",text:o}},provenance:{producer:{...e.producer}},anchors:t.files.map(s=>({kind:"custom:source-file",data:{path:s.path}})),...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},extensions:{"xeno.legacy.turnDiffSummary":n}};return R(r),r}function
|
|
11
|
-
`))}readSidecar(e){try{let n=JSON.parse(_e(this.sidecarPath(e),"utf8"));return Array.isArray(n.publications)?n.publications:[]}catch{return[]}}async get(e,n){let i=await this.repository.get(e,n);if(!(!i||i.artifact.kind!=="page"))return this.toPublished(i)}async list(){let e=await this.repository.list({kinds:["page"]});return(await Promise.all(e.map(i=>this.toPublished(i)))).sort((i,o)=>(o.updatedAt??o.createdAt).localeCompare(i.updatedAt??i.createdAt))}resolveFile(e,n,i){let o=i===D||i===""?{path:D}:
|
|
7
|
+
`);if(d.length>r)throw new _(`Unified diff exceeds ${r} lines`);let a=[],c,f=0,g=(m,h)=>{if(c&&Tt(c,a),a.length>=i)throw new _(`Unified diff exceeds ${i} files`);return c={oldPath:m,newPath:h,status:"modified",binary:!1,headerLines:[],hunks:[]},c};for(let m=0;m<d.length;m+=1){let h=d[m];if(h.startsWith("diff --git ")){let[E,L]=pi(h.slice(11),m+1);g(E,L).headerLines.push(h);continue}if(h.startsWith("--- ")){(!c||c.hunks.length>0)&&(c=g()),c.oldPath=kt(h.slice(4)),c.headerLines.push(h);continue}if(h.startsWith("+++ ")){c||(c=g()),c.newPath=kt(h.slice(4)),c.headerLines.push(h);continue}if(h.startsWith("@@ ")){if(!c)throw new _("Hunk appears before a file header",m+1);if(f>=o)throw new _(`Unified diff exceeds ${o} hunks`,m+1);let E=fi.exec(h);if(!E)throw new _("Malformed unified diff hunk header",m+1);let L=Number(E[1]),W=E[2]===void 0?1:Number(E[2]),K=Number(E[3]),M=E[4]===void 0?1:Number(E[4]),$=[],X=L,I=K,H=0,fe=0,j=m+1;for(;j<d.length;j+=1){let w=d[j],un=X-L===W,ln=I-K===M;if(un&&ln&&w.length===0||w.startsWith("diff --git ")||w.startsWith("@@ ")||w.startsWith("--- ")&&d[j+1]?.startsWith("+++ "))break;if(w.startsWith("+"))$.push({kind:"addition",text:w.slice(1),newLine:I}),I+=1,H+=1;else if(w.startsWith("-"))$.push({kind:"deletion",text:w.slice(1),oldLine:X}),X+=1,fe+=1;else if(w.startsWith(" "))$.push({kind:"context",text:w.slice(1),oldLine:X,newLine:I}),X+=1,I+=1;else if(w==="\")$.push({kind:"no-newline",text:w});else{if(w.length===0&&j===d.length-1)break;throw new _("Unexpected line inside unified diff hunk",j+1)}}let Ke=$.filter(w=>w.kind==="context"||w.kind==="deletion").length,Ge=$.filter(w=>w.kind==="context"||w.kind==="addition").length;if(Ke!==W||Ge!==M)throw new _(`Hunk line counts do not match header (expected -${W}/+${M}, observed -${Ke}/+${Ge})`,m+1);let Ye=h,pn=x(JSON.stringify({oldPath:c.oldPath??null,newPath:c.newPath??null,header:Ye,lines:$})).value.slice(0,32);c.hunks.push({hunkId:pn,header:Ye,...E[5]?{section:E[5]}:{},oldStart:L,oldLines:W,newStart:K,newLines:M,additions:H,deletions:fe,lines:$}),f+=1,m=j-1;continue}if(!c){if(h.trim().length===0)continue;throw new _("Content appears before the first diff file header",m+1)}c.headerLines.push(h),h.startsWith("new file mode ")?c.status="added":h.startsWith("deleted file mode ")?c.status="deleted":h.startsWith("rename from ")?(c.status="renamed",c.oldPath=z(h.slice(12))):h.startsWith("rename to ")?(c.status="renamed",c.newPath=z(h.slice(10))):h.startsWith("copy from ")?(c.status="copied",c.oldPath=z(h.slice(10))):h.startsWith("copy to ")?(c.status="copied",c.newPath=z(h.slice(8))):(h.startsWith("Binary files ")||h==="GIT binary patch")&&(c.binary=!0,c.status="binary")}c&&Tt(c,a);let y=a.reduce((m,h)=>m+h.additions,0),P=a.reduce((m,h)=>m+h.deletions,0);return{schemaVersion:1,mode:e.mode??"working-tree",...e.repositoryId?{repositoryId:e.repositoryId}:{},...e.baseRef?{baseRef:e.baseRef}:{},...e.headRef?{headRef:e.headRef}:{},files:a,additions:y,deletions:P,rawDiff:s}}function $t(t,e){let n=Pt(t,{mode:e.mode,repositoryId:e.repositoryId,baseRef:e.baseRef,headRef:e.headRef}),i=n,o=T(i),r=[e.identity?.runId,e.identity?.turnId,e.identity?.taskId,e.repositoryId,e.mode].filter(Boolean).join(":"),s=e.kind??"diff",d=e.artifactId??`${s}_${x(`${r}:${n.rawDiff}`).value.slice(0,24)}`,a=e.revision??1,c={schemaVersion:1,artifactId:d,revision:a,kind:s,title:e.title??`${mi(n.mode)} diff (${n.files.length} files)`,...e.description?{description:e.description}:{},state:"pending_review",createdAt:e.createdAt??new Date().toISOString(),mediaType:`application/vnd.xeno.${s}+json`,sensitivity:e.sensitivity??"internal",...e.identity?{identity:structuredClone(e.identity)}:{},content:{hash:k(i),sizeBytes:Nt.byteLength(o,"utf8"),encoding:"utf8",storage:{type:"inline",text:o},redactedPreview:`${n.files.length} files, +${n.additions}/-${n.deletions}`},provenance:{producer:{...e.producer}},anchors:n.files.flatMap(f=>[{kind:"file",path:f.displayPath,...e.repositoryId?{repositoryId:e.repositoryId}:{}},...f.hunks.map(g=>({kind:"diff-hunk",path:f.displayPath,hunkId:g.hunkId,artifactId:d,revision:a}))]),...a>1?{predecessorRevision:e.predecessorRevision??a-1}:{},...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},extensions:{"xeno.diff.mode":n.mode,"xeno.diff.files":n.files.length,"xeno.diff.additions":n.additions,"xeno.diff.deletions":n.deletions}};return R(c),c}function Ot(t){if(R(t),t.kind!=="diff"&&t.kind!=="patch")throw new TypeError("Artifact is not a diff or patch");if(t.content.storage.type!=="inline"||typeof t.content.storage.text!="string")throw new TypeError("Diff artifact content is not available inline");let e;try{e=JSON.parse(t.content.storage.text)}catch(i){throw new _(`Diff artifact JSON is malformed: ${hi(i).message}`)}if(!li(e))throw new _("Diff artifact document is invalid");let n=Pt(e.rawDiff,{mode:e.mode,repositoryId:e.repositoryId,baseRef:e.baseRef,headRef:e.headRef});if(T(n)!==T(e))throw new _("Diff artifact document does not match its raw diff");return n}function Tt(t,e){if(!t.oldPath&&!t.newPath)throw new _("Diff file has no path");t.oldPath||(t.status="added"),t.newPath||(t.status="deleted"),t.binary&&(t.status="binary");let n=t.hunks.reduce((o,r)=>o+r.additions,0),i=t.hunks.reduce((o,r)=>o+r.deletions,0);e.push({...t.oldPath?{oldPath:t.oldPath}:{},...t.newPath?{newPath:t.newPath}:{},displayPath:t.newPath??t.oldPath,status:t.status,additions:n,deletions:i,binary:t.binary,headerLines:[...t.headerLines],hunks:structuredClone(t.hunks)})}function pi(t,e){let n=ui(t);if(n.length!==2)throw new _("Malformed diff --git path pair",e);return[z(n[0]),z(n[1])]}function ui(t){let e=[],n=0;for(;n<t.length;){for(;t[n]===" ";)n+=1;if(n>=t.length)break;if(t[n]==='"'){let i='"';n+=1;let o=!1;for(;n<t.length;){let r=t[n];if(i+=r,n+=1,!o&&r==='"')break;o=!o&&r==="\\",r!=="\\"&&(o=!1)}e.push(Vt(i))}else{let i=t.indexOf(" ",n);if(i===-1){e.push(t.slice(n));break}e.push(t.slice(n,i)),n=i+1}}return e}function Vt(t){return!t.startsWith('"')||!t.endsWith('"')?t:t.slice(1,-1).replace(/\\([\\"tnr]|[0-7]{1,3})/g,(n,i)=>i==="t"?" ":i==="n"?`
|
|
8
|
+
`:i==="r"?"\r":i==="\\"?"\\":i==='"'?'"':String.fromCharCode(Number.parseInt(i,8)))}function kt(t){let e=t.split(" ",1)[0].trim();if(e!=="/dev/null")return z(Vt(e))}function z(t){let e=t.replace(/\\/g,"/");return e.startsWith("a/")||e.startsWith("b/")?e.slice(2):e}function li(t){return!Ct(t)||t.schemaVersion!==1||!["working-tree","staged","turn","commit","preview"].includes(String(t.mode))||!Array.isArray(t.files)||!Number.isSafeInteger(t.additions)||!Number.isSafeInteger(t.deletions)||typeof t.rawDiff!="string"?!1:t.files.every(e=>Ct(e)&&typeof e.displayPath=="string"&&Array.isArray(e.headerLines)&&Array.isArray(e.hunks))}function Ct(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function ve(t,e,n,i,o){if(t===void 0)return e;if(!Number.isInteger(t)||t<n||t>i)throw new TypeError(`${o} must be an integer between ${n} and ${i}`);return t}function mi(t){return t.split("-").map(e=>e[0].toUpperCase()+e.slice(1)).join(" ")}function hi(t){return t instanceof Error?t:new Error(String(t))}import{randomUUID as gi}from"node:crypto";var re=class{repository;actor;idFactory;constructor(e){if(!e?.repository)throw new TypeError("Artifact repository is required");if(!e.actor?.kind||!e.actor.id?.trim())throw new TypeError("Review actor is required");this.repository=e.repository,this.actor=structuredClone(e.actor),this.idFactory=e.idFactory??(()=>`comment_${gi()}`)}async addComment(e){let n=Ae(e.body,"Review comment body",65536),i=await this.repository.require(e.artifactId,e.revision),o=Dt(i,e),r=ye(this.idFactory(),"Comment ID"),s=yi(e.parentCommentId,"Parent comment ID");return this.repository.appendReviewEvent({expectedRecordVersion:i.recordVersion,event:{type:"comment-added",artifactId:i.artifact.artifactId,artifactRevision:i.artifact.revision,artifactHash:i.artifact.content.hash,actor:this.actor,commentId:r,body:n,...o?{anchor:o}:{},...s?{parentCommentId:s}:{}}})}async setCommentResolution(e){let n=ye(e.commentId,"Review comment ID"),i=Ft(e.reason,"Resolution reason",16*1024),o=await this.repository.require(e.artifactId,e.revision);return this.repository.appendReviewEvent({expectedRecordVersion:o.recordVersion,event:{type:e.resolved?"comment-resolved":"comment-reopened",artifactId:o.artifact.artifactId,artifactRevision:o.artifact.revision,artifactHash:o.artifact.content.hash,actor:this.actor,commentId:n,...i?{reason:i}:{}}})}async decide(e){let n=await this.repository.require(e.artifactId,e.revision);if(n.artifact.state!=="pending_review")throw new u("ARTIFACT_REVIEW_INVALID",`Artifact must be pending_review, found ${n.artifact.state}`);let i=Dt(n,e),o=Ft(e.rationale,"Decision rationale",64*1024),r=await this.repository.appendReviewEvent({expectedRecordVersion:n.recordVersion,event:{type:"decision-recorded",artifactId:n.artifact.artifactId,artifactRevision:n.artifact.revision,artifactHash:n.artifact.content.hash,actor:this.actor,decision:e.decision,...o?{rationale:o}:{},...i?{scope:i}:{}}});if(i||e.decision==="changes_requested")return r;let s=r.reviewEvents.at(-1);if(!s||s.type!=="decision-recorded")throw new u("ARTIFACT_REVIEW_INVALID","Artifact decision event was not recorded");return this.repository.transition({artifactId:r.artifact.artifactId,revision:r.artifact.revision,expectedRecordVersion:r.recordVersion,toState:e.decision,actor:this.actor,reviewEventId:s.eventId,...o?{reason:o}:{}})}};function Dt(t,e){if((e.line!==void 0||e.hunkId!==void 0)&&!e.file)throw F("Line and hunk anchors require a file");if(e.line!==void 0&&e.hunkId!==void 0)throw F("Line and hunk anchors cannot be combined");if(!e.file)return;let n=vi(e.file);if(e.line!==void 0&&(!Number.isInteger(e.line)||e.line<1))throw F("Review line must be a positive integer");if(t.artifact.kind==="diff"||t.artifact.kind==="patch"){let o=Ot(t.artifact).files.find(r=>r.displayPath===n);if(!o)throw F(`File ${n} is not present in this artifact`);if(e.hunkId&&!o.hunks.some(r=>r.hunkId===e.hunkId))throw F(`Hunk ${e.hunkId} is not present in ${n}`)}return e.hunkId?{kind:"diff-hunk",path:n,hunkId:ye(e.hunkId,"Hunk ID"),artifactId:t.artifact.artifactId,revision:t.artifact.revision}:e.line!==void 0?{kind:"source-line",path:n,startLine:e.line}:{kind:"file",path:n}}function vi(t){let e=Ae(t,"Artifact review file",4096).replace(/\\/g,"/").replace(/^\.\//,"");if(e.startsWith("../")||e.startsWith("/")||/^[A-Za-z]:\//.test(e)||e.split("/").some(n=>n===".."||n.length===0))throw F("Artifact review file anchors must be repository-relative paths");return e}function Ae(t,e,n){let i=typeof t=="string"?t.trim():"";if(!i)throw F(`${e} cannot be empty`);if(i.length>n)throw F(`${e} exceeds ${n} characters`);return i}function Ft(t,e,n){if(t!==void 0)return Ae(t,e,n)}function ye(t,e){let n=Ae(t,e,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(n))throw F(`${e} contains unsupported characters`);return n}function yi(t,e){return t===void 0?void 0:ye(t,e)}function F(t){return new u("ARTIFACT_REVIEW_INVALID",t)}import{randomUUID as Ai}from"node:crypto";var ae="xeno.spec.v1",we="xeno.spec-execution.v1",b=class extends Error{constructor(n){super(`XENO spec is invalid: ${n.join("; ")}`);this.issues=n;this.name="XenoSpecValidationError"}issues;code="XENO_SPEC_INVALID"},Lt=class{repository;now;idFactory;constructor(e){if(!e?.repository)throw new TypeError("Artifact repository is required");this.repository=e.repository,this.now=e.now??(()=>new Date().toISOString()),this.idFactory=e.idFactory??(()=>Ai())}async create(e,n){if(e.revision!==1||e.predecessorRevision!==void 0)throw new b(["A new spec must begin at revision 1 without a predecessor"]);let i=Mt(e,n);return await this.repository.create(i.requirements),await this.repository.create(i.design),await this.repository.create(i.taskGraph),await this.repository.create(i.plan),i}async revise(e,n){let i=oe(e.specId),o=await this.repository.require(i.plan);if(e.revision!==o.artifact.revision+1||e.predecessorRevision!==o.artifact.revision)throw new b([`Revision ${e.revision} must follow approved or reviewed revision ${o.artifact.revision}`]);let r=Mt(e,n);return await this.repository.createRevision(r.requirements,{actor:n.producer,reason:"spec-revised"}),await this.repository.createRevision(r.design,{actor:n.producer,reason:"spec-revised"}),await this.repository.createRevision(r.taskGraph,{actor:n.producer,reason:"spec-revised"}),await this.repository.createRevision(r.plan,{actor:n.producer,reason:"spec-revised"}),r}async approve(e,n,i){return new re({repository:this.repository,actor:n}).decide({artifactId:oe(e).plan,decision:"approved",...i?{rationale:i}:{}})}async reject(e,n,i){return new re({repository:this.repository,actor:n}).decide({artifactId:oe(e).plan,decision:"rejected",rationale:i})}async startExecution(e,n){let i=await this.repository.require(oe(e).plan);if(i.artifact.state!=="approved")throw new b([`Spec ${e} must be approved before execution`]);let o=Ht(i.artifact),r=this.now(),s={schemaVersion:we,executionId:`spec_execution_${this.idFactory()}`,specId:o.specId,specRevision:o.revision,planArtifactId:i.artifact.artifactId,planHash:{...i.artifact.content.hash},state:"ready",createdAt:r,updatedAt:r,observedPaths:[],tasks:o.tasks.map(d=>({taskId:d.id,status:"pending",evidence:[],acceptanceEvidence:Object.fromEntries(d.acceptanceCriterionIds.map(a=>[a,[]]))}))};return this.repository.create(jt(s,{producer:n,identity:i.artifact.identity,sensitivity:i.artifact.sensitivity,accessPolicyId:i.artifact.accessPolicyId}))}async updateExecution(e,n,i){let o=await this.repository.require(e),r=wi(o.artifact),s=await this.repository.require(r.planArtifactId,r.specRevision);if(s.artifact.state!=="approved"||!de(s.artifact.content.hash,r.planHash))throw new b(["Execution is no longer bound to the approved plan revision"]);let d=n(structuredClone(r));d.schemaVersion=we,d.executionId=r.executionId,d.specId=r.specId,d.specRevision=r.specRevision,d.planArtifactId=r.planArtifactId,d.planHash={...r.planHash},d.createdAt=r.createdAt,d.updatedAt=this.now(),Bt(d,Ht(s.artifact));let a=jt(d,{producer:i,identity:o.artifact.identity,sensitivity:o.artifact.sensitivity,accessPolicyId:o.artifact.accessPolicyId},o.artifact.revision+1,o.artifact.revision);return this.repository.createRevision(a,{actor:i,reason:"spec-execution-updated"})}};function oe(t){let e=Xi(t,"specId");return{plan:`spec_${e}_plan`,requirements:`spec_${e}_requirements`,design:`spec_${e}_design`,taskGraph:`spec_${e}_task_graph`}}function Ii(t){let e=[];t?.schemaVersion!==ae&&e.push(`schemaVersion must be ${ae}`),ce(t?.specId,"specId",e),(!Number.isInteger(t?.revision)||t.revision<1)&&e.push("revision must be a positive integer"),C(t?.title,"title",e),C(t?.problem,"problem",e),Ee(t?.createdAt,"createdAt",e),Ee(t?.updatedAt,"updatedAt",e),t?.predecessorRevision!==void 0&&(!Number.isInteger(t.predecessorRevision)||t.predecessorRevision!==t.revision-1)&&e.push("predecessorRevision must be the immediately preceding revision");let n=Ie(t?.requirements,"requirement",e),i=Ie(t?.tasks,"task",e),o=new Set,r=[...Array.isArray(t?.acceptanceCriteria)?t.acceptanceCriteria:[],...Array.isArray(t?.requirements)?t.requirements.flatMap(a=>Array.isArray(a.acceptanceCriteria)?a.acceptanceCriteria:[]):[]];for(let a of r){ce(a?.id,"acceptance criterion id",e),C(a?.text,`acceptance criterion ${a?.id??"?"}`,e),o.has(a?.id)&&e.push(`Duplicate acceptance criterion: ${a?.id}`),o.add(a?.id);for(let c of a?.requiredEvidenceKinds??[])ce(c,"required evidence kind",e)}for(let a of t?.requirements??[])C(a?.text,`requirement ${a?.id??"?"}`,e),["must","should","could"].includes(a?.priority)||e.push(`Requirement ${a?.id??"?"} has invalid priority`),(!Array.isArray(a?.acceptanceCriteria)||a.acceptanceCriteria.length===0)&&e.push(`Requirement ${a?.id??"?"} needs at least one acceptance criterion`);C(t?.design?.summary,"design summary",e);let s=Ie(t?.design?.decisions,"design decision",e),d=Ie(t?.design?.risks,"risk",e);for(let a of t?.design?.decisions??[]){C(a?.decision,`design decision ${a?.id??"?"}`,e),C(a?.rationale,`design rationale ${a?.id??"?"}`,e);for(let c of a?.requirementIds??[])n.has(c)||e.push(`Design decision ${a.id} references unknown requirement ${c}`)}for(let a of t?.design?.risks??[])C(a?.description,`risk ${a?.id??"?"}`,e),C(a?.mitigation,`risk mitigation ${a?.id??"?"}`,e),["low","medium","high","critical"].includes(a?.impact)||e.push(`Risk ${a?.id??"?"} has invalid impact`);for(let a of t?.tasks??[]){C(a?.title,`task title ${a?.id??"?"}`,e),C(a?.description,`task description ${a?.id??"?"}`,e);for(let c of a?.dependsOn??[])i.has(c)||e.push(`Task ${a.id} depends on unknown task ${c}`),c===a.id&&e.push(`Task ${a.id} cannot depend on itself`);for(let c of a?.requirementIds??[])n.has(c)||e.push(`Task ${a.id} references unknown requirement ${c}`);for(let c of a?.acceptanceCriterionIds??[])o.has(c)||e.push(`Task ${a.id} references unknown acceptance criterion ${c}`);for(let c of a?.expectedPaths??[])Jt(c)||e.push(`Task ${a.id} has unsafe expected path ${c}`)}return Ri(t?.tasks??[])&&e.push("Task dependency graph contains a cycle"),[...new Set(e)]}function Me(t){let e=Ii(t);if(e.length>0)throw new b(e)}function Mt(t,e){Me(t);let n=oe(t.specId),i=t.revision,o={...e,createdAt:t.updatedAt,state:"draft"},r=se({artifactId:n.requirements,revision:i,predecessorRevision:t.predecessorRevision,kind:"requirements",title:`${t.title} - requirements`,value:{schemaVersion:ae,specId:t.specId,revision:i,problem:t.problem,requirements:t.requirements,acceptanceCriteria:t.acceptanceCriteria},context:o}),s=se({artifactId:n.design,revision:i,predecessorRevision:t.predecessorRevision,kind:"design",title:`${t.title} - design`,value:{schemaVersion:ae,specId:t.specId,revision:i,design:t.design,...t.sourceBaseline?{sourceBaseline:t.sourceBaseline}:{}},context:o}),d=se({artifactId:n.taskGraph,revision:i,predecessorRevision:t.predecessorRevision,kind:"task-graph",title:`${t.title} - task graph`,value:{schemaVersion:ae,specId:t.specId,revision:i,tasks:t.tasks},context:o}),a=[r,s,d].map(f=>({relation:"decomposes",target:{type:"artifact",id:f.artifactId,revision:f.revision}})),c=se({artifactId:n.plan,revision:i,predecessorRevision:t.predecessorRevision,kind:"plan",title:t.title,description:t.problem,value:t,context:{...e,createdAt:t.updatedAt,state:"pending_review"},relationships:a,extensions:{"xeno.spec.id":t.specId,"xeno.spec.revision":t.revision,"xeno.spec.requirements_hash":r.content.hash.value,"xeno.spec.design_hash":s.content.hash.value,"xeno.spec.task_graph_hash":d.content.hash.value}});return{document:structuredClone(t),plan:c,requirements:r,design:s,taskGraph:d}}function Ht(t){if(t.kind!=="plan"||t.mediaType!=="application/vnd.xeno.spec+json")throw new b([`Artifact ${t.artifactId} is not a XENO spec plan`]);let e=qt(t);if(Me(e),e.revision!==t.revision)throw new b(["Spec and artifact revisions differ"]);if(!de(k(e),t.content.hash))throw new b(["Spec artifact content hash is invalid"]);return structuredClone(e)}function jt(t,e,n=1,i){let o=structuredClone(t);return se({artifactId:t.executionId,revision:n,predecessorRevision:i,kind:"custom:xeno.spec-execution",title:`Execution of ${t.specId} revision ${t.specRevision}`,description:`Execution state: ${t.state}`,value:o,context:{...e,createdAt:t.updatedAt,state:t.state==="completed"?"pending_review":"draft"},relationships:[{relation:"implements",target:{type:"artifact",id:t.planArtifactId,revision:t.specRevision}}],extensions:{"xeno.spec.execution_state":t.state,"xeno.spec.plan_hash":t.planHash.value}})}function wi(t){if(t.kind!=="custom:xeno.spec-execution")throw new b([`Artifact ${t.artifactId} is not a spec execution`]);let e=qt(t);if(e.schemaVersion!==we||e.executionId!==t.artifactId)throw new b(["Spec execution identity or schema is invalid"]);if(!de(k(e),t.content.hash))throw new b(["Spec execution content hash is invalid"]);return structuredClone(e)}function Bt(t,e){let n=[];t.schemaVersion!==we&&n.push("Execution schema is invalid"),(t.specId!==e.specId||t.specRevision!==e.revision)&&n.push("Execution is bound to the wrong spec revision");let i=new Map(e.tasks.map(r=>[r.id,r])),o=new Set;for(let r of t.tasks){o.has(r.taskId)&&n.push(`Duplicate execution task ${r.taskId}`),o.add(r.taskId);let s=i.get(r.taskId);if(!s){n.push(`Unknown execution task ${r.taskId}`);continue}for(let d of s.acceptanceCriterionIds)Array.isArray(r.acceptanceEvidence?.[d])||n.push(`Task ${r.taskId} is missing acceptance evidence slot ${d}`)}for(let r of i.keys())o.has(r)||n.push(`Execution is missing task ${r}`);for(let r of t.observedPaths)bi(r)||n.push(`Unsafe observed path ${r}`);if(Ee(t.createdAt,"execution createdAt",n),Ee(t.updatedAt,"execution updatedAt",n),n.length>0)throw new b([...new Set(n)])}function Gr(t,e,n,i,o=new Date().toISOString()){Me(t),Bt(n,t);let r=[];(!de(e,i)||!de(n.planHash,i))&&r.push({code:"PLAN_HASH_MISMATCH",severity:"error",message:"Execution is not bound to the approved plan content hash"});let s=new Map(t.tasks.map(c=>[c.id,c])),d=new Map(n.tasks.map(c=>[c.taskId,c]));for(let c of n.tasks){let f=s.get(c.taskId);if(!f){r.push({code:"UNKNOWN_TASK",severity:"error",taskId:c.taskId,message:`Unknown task ${c.taskId}`});continue}if(c.status==="completed"){c.evidence.length===0&&r.push({code:"MISSING_TASK_EVIDENCE",severity:"error",taskId:f.id,message:`Completed task ${f.id} has no evidence`});for(let g of f.dependsOn??[])d.get(g)?.status!=="completed"&&r.push({code:"DEPENDENCY_INCOMPLETE",severity:"error",taskId:f.id,message:`Task ${f.id} completed before dependency ${g}`});for(let g of f.acceptanceCriterionIds)(c.acceptanceEvidence[g]??[]).length===0&&r.push({code:"MISSING_ACCEPTANCE_EVIDENCE",severity:"error",taskId:f.id,criterionId:g,message:`Completed task ${f.id} has no evidence for ${g}`})}}let a=t.tasks.flatMap(c=>c.expectedPaths??[]);for(let c of n.observedPaths)a.some(f=>Si(c,f))||r.push({code:"UNKNOWN_PATH",severity:"warning",path:c,message:`Observed path ${c} is outside the approved task plan`});return{schemaVersion:"xeno.spec-drift.v1",specId:t.specId,specRevision:t.revision,executionId:n.executionId,checkedAt:o,drifted:r.length>0,findings:r}}function se(t){let e=t.value,n=T(e);return{schemaVersion:1,artifactId:t.artifactId,revision:t.revision,kind:t.kind,title:t.title,...t.description?{description:t.description}:{},state:t.context.state,createdAt:t.context.createdAt??new Date().toISOString(),mediaType:Ei(t.kind),sensitivity:t.context.sensitivity??"internal",...t.context.identity?{identity:structuredClone(t.context.identity)}:{},content:{hash:k(e),sizeBytes:Buffer.byteLength(n,"utf8"),encoding:"utf8",storage:{type:"inline",text:n},redactedPreview:t.title},provenance:{producer:structuredClone(t.context.producer)},...t.relationships?.length?{relationships:structuredClone(t.relationships)}:{},...t.predecessorRevision!==void 0?{predecessorRevision:t.predecessorRevision}:{},...t.context.accessPolicyId?{accessPolicyId:t.context.accessPolicyId}:{},...t.extensions?{extensions:structuredClone(t.extensions)}:{}}}function Ei(t){return t==="plan"?"application/vnd.xeno.spec+json":t==="custom:xeno.spec-execution"?"application/vnd.xeno.spec-execution+json":`application/vnd.xeno.spec-${t}+json`}function qt(t){let e=t.content.storage;if(e.type!=="inline"||typeof e.text!="string")throw new b(["Spec artifacts require inline JSON content"]);try{return JSON.parse(e.text)}catch(n){throw new b([`Spec artifact JSON is invalid: ${n instanceof Error?n.message:String(n)}`])}}function Ie(t,e,n){let i=new Set;(!Array.isArray(t)||t.length===0)&&n.push(`${e} list cannot be empty`);for(let o of t??[])ce(o?.id,`${e} id`,n),i.has(o?.id??"")&&n.push(`Duplicate ${e}: ${o?.id}`),o?.id&&i.add(o.id);return i}function ce(t,e,n){(typeof t!="string"||!/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/u.test(t))&&n.push(`${e} must match [A-Za-z0-9][A-Za-z0-9._-]{0,127}`)}function C(t,e,n){(typeof t!="string"||t.trim().length===0||t.length>64*1024)&&n.push(`${e} must be non-empty and no longer than 65536 characters`)}function Ee(t,e,n){(typeof t!="string"||!t.includes("T")||!Number.isFinite(Date.parse(t)))&&n.push(`${e} must be an ISO 8601 timestamp`)}function Xi(t,e){let n=[];if(ce(t,e,n),n.length>0)throw new b(n);return t}function Ri(t){let e=new Map(t.map(r=>[r.id,r])),n=new Set,i=new Set,o=r=>{if(n.has(r))return!0;if(i.has(r))return!1;n.add(r);for(let s of e.get(r)?.dependsOn??[])if(o(s))return!0;return n.delete(r),i.add(r),!1};return t.some(r=>o(r.id))}function Jt(t){let e=t.replace(/\\/gu,"/");return e.length>0&&e.length<=4096&&!e.startsWith("/")&&!/^[A-Za-z]:/u.test(e)&&!e.split("/").includes("..")}function bi(t){return Jt(t)&&!t.includes("*")}function Si(t,e){let n=t.replace(/\\/gu,"/"),i=e.replace(/\\/gu,"/");if(i.endsWith("/**")){let o=i.slice(0,-3).replace(/\/$/u,"");return n===o||n.startsWith(`${o}/`)}if(i.endsWith("/*")){let o=i.slice(0,-2).replace(/\/$/u,""),r=n.startsWith(`${o}/`)?n.slice(o.length+1):"";return r.length>0&&!r.includes("/")}return n===i}function de(t,e){return t.algorithm===e.algorithm&&t.value===e.value}import{randomUUID as _i}from"node:crypto";var Ut="xeno.review-report.v1",xi=["correctness","security","performance","api","tests","documentation"],Ti=["source","test","trace","artifact","reproduction","benchmark"],S=class extends Error{constructor(n){super(`XENO review is invalid: ${n.join("; ")}`);this.issues=n;this.name="XenoReviewValidationError"}issues;code="XENO_REVIEW_INVALID"},zt=class{reviewer;verifier;now;idFactory;constructor(e){if(typeof e?.reviewer!="function")throw new TypeError("Review agent executor is required");this.reviewer=e.reviewer,this.verifier=e.verifier,this.now=e.now??(()=>new Date().toISOString()),this.idFactory=e.idFactory??(n=>`${n}_${_i()}`)}async run(e){Wt(e.pack),Kt(e.target),Xe(e.runId,"runId");let n=this.now(),i=await Promise.all(e.pack.dimensions.map(async(a,c)=>{let f=await this.reviewer({...e,dimension:a,reviewerSlot:c});return Ni(f,a,e.pack.maxFindings),structuredClone(f)})),o=i.flatMap(a=>a.findings.map(c=>({finding:c,reviewerAgentId:a.reviewerAgentId})));if(o.length>e.pack.maxFindings)throw new S([`Reviewers returned ${o.length} findings, exceeding maxFindings ${e.pack.maxFindings}`]);let r=ki(o,this.idFactory);for(let a of r){let c=this.verifier?await Promise.all(Array.from({length:e.pack.verifierCount},async(m,h)=>{let E=await this.verifier({...e,finding:structuredClone(a),verifierSlot:h});return Pi(E),structuredClone(E)})):[];a.verifications=$i(c),a.evidence=Yt([...a.evidence,...a.verifications.flatMap(m=>m.evidence)]);let f=new Set(a.verifications.filter(m=>m.outcome==="reproduced").map(m=>m.verifierAgentId)).size,g=a.verifications.length>0&&a.verifications.every(m=>m.outcome==="rejected"),y=new Set(a.evidence.map(m=>m.producerId)).size;f>=e.pack.minimumVerifierReproductions?(a.state="verified",a.verificationBasis="verifier"):e.pack.allowIndependentEvidenceVerification&&y>=e.pack.minimumIndependentEvidenceProducers?(a.state="verified",a.verificationBasis="independent-evidence"):g?(a.state="rejected",a.verificationBasis="verifier"):(a.state="unverified",a.verificationBasis="none");let P=a.verifications.map(m=>m.confidence).filter(m=>m!==void 0);P.length>0&&(a.confidence=rn(Math.min(a.confidence,...P)))}r.sort(Oi);let s=this.now(),d={schemaVersion:Ut,reportId:Xe(this.idFactory("report"),"reportId"),runId:e.runId,pack:structuredClone(e.pack),target:structuredClone(e.target),startedAt:n,completedAt:s,reviewers:i.map(a=>({agentId:a.reviewerAgentId,dimension:a.dimension,findingCount:a.findings.length})),findings:r,summary:en(r)};return be(d),d}};function io(t="xeno-production-review"){return{schemaVersion:"xeno.review-pack.v1",packId:t,version:"1.0.0",dimensions:["correctness","security","performance","api","tests","documentation"],verifierCount:1,minimumVerifierReproductions:1,allowIndependentEvidenceVerification:!1,minimumIndependentEvidenceProducers:2,maxFindings:256}}function Wt(t){let e=[];t?.schemaVersion!=="xeno.review-pack.v1"&&e.push("Review pack schemaVersion must be xeno.review-pack.v1"),N(t?.packId,"packId",e),(typeof t?.version!="string"||!/^\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?$/u.test(t.version))&&e.push("Review pack version must be semantic version text"),(!Array.isArray(t?.dimensions)||t.dimensions.length===0)&&e.push("Review pack needs at least one dimension"),new Set(t?.dimensions??[]).size!==(t?.dimensions??[]).length&&e.push("Review pack dimensions must be unique");for(let n of t?.dimensions??[])nn(n)||e.push(`Invalid review dimension ${n}`);if((!Number.isInteger(t?.verifierCount)||t.verifierCount<0||t.verifierCount>8)&&e.push("verifierCount must be 0 through 8"),(!Number.isInteger(t?.minimumVerifierReproductions)||t.minimumVerifierReproductions<1||t.minimumVerifierReproductions>Math.max(1,t.verifierCount))&&e.push("minimumVerifierReproductions must be positive and no greater than verifierCount"),(!Number.isInteger(t?.minimumIndependentEvidenceProducers)||t.minimumIndependentEvidenceProducers<2)&&e.push("minimumIndependentEvidenceProducers must be at least 2"),(!Number.isInteger(t?.maxFindings)||t.maxFindings<1||t.maxFindings>2048)&&e.push("maxFindings must be 1 through 2048"),e.length>0)throw new S(e)}function Kt(t){let e=[];if(N(t?.artifactId,"target artifactId",e),(!Number.isInteger(t?.revision)||t.revision<1)&&e.push("Target revision must be positive"),U(t?.title,"target title",e),(t?.contentHash?.algorithm!=="sha256"||!/^[a-f0-9]{64}$/u.test(t?.contentHash?.value??""))&&e.push("Target contentHash must be lowercase sha256"),e.length>0)throw new S(e)}function be(t){let e=[];t?.schemaVersion!==Ut&&e.push("Review report schemaVersion is invalid"),N(t?.reportId,"reportId",e),N(t?.runId,"runId",e),Re(t?.startedAt,"startedAt",e),Re(t?.completedAt,"completedAt",e),Date.parse(t?.completedAt)<Date.parse(t?.startedAt)&&e.push("completedAt cannot precede startedAt");try{Wt(t.pack)}catch(r){e.push(r instanceof Error?r.message:String(r))}try{Kt(t.target)}catch(r){e.push(r instanceof Error?r.message:String(r))}let n=new Set,i=new Set;for(let r of t?.findings??[])N(r?.findingId,"findingId",e),n.has(r.findingId)&&e.push(`Duplicate findingId ${r.findingId}`),n.add(r.findingId),/^[a-f0-9]{64}$/u.test(r?.fingerprint??"")||e.push(`Finding ${r.findingId} has invalid fingerprint`),i.has(r.fingerprint)&&e.push(`Duplicate finding fingerprint ${r.fingerprint}`),i.add(r.fingerprint),U(r?.title,`finding ${r.findingId} title`,e),U(r?.summary,`finding ${r.findingId} summary`,e),tn(r?.severity)||e.push(`Finding ${r.findingId} has invalid severity`),(!Number.isFinite(r?.confidence)||r.confidence<0||r.confidence>1)&&e.push(`Finding ${r.findingId} has invalid confidence`),r?.state==="verified"&&r.verificationBasis==="none"&&e.push(`Finding ${r.findingId} cannot be verified without a basis`),r?.state!=="verified"&&r.verificationBasis==="independent-evidence"&&e.push(`Finding ${r.findingId} has inconsistent evidence verification`);let o=en(t?.findings??[]);if((o.total!==t?.summary?.total||o.verified!==t?.summary?.verified||o.unverified!==t?.summary?.unverified||o.rejected!==t?.summary?.rejected||Object.keys(o.bySeverity).some(r=>o.bySeverity[r]!==t?.summary?.bySeverity?.[r]))&&e.push("Review report summary is inconsistent"),e.length>0)throw new S([...new Set(e)])}function ro(t,e){be(t);let n=t,i=T(n),o=e.artifactId??`review_${x(`${t.runId}:${t.target.artifactId}:${t.target.contentHash.value}`).value.slice(0,24)}`,r={schemaVersion:1,artifactId:o,revision:1,kind:"review-report",title:`Review of ${t.target.title}`,description:`${t.summary.verified} verified, ${t.summary.unverified} unverified, ${t.summary.rejected} rejected findings`,state:"pending_review",createdAt:e.createdAt??t.completedAt,mediaType:"application/vnd.xeno.review-report+json",sensitivity:e.sensitivity??"internal",...e.identity?{identity:structuredClone(e.identity)}:{},content:{hash:k(n),sizeBytes:Buffer.byteLength(i,"utf8"),encoding:"utf8",storage:{type:"inline",text:i},redactedPreview:`${t.summary.total} findings; ${t.summary.verified} verified`},provenance:{producer:structuredClone(e.producer),sourceArtifactIds:[t.target.artifactId],attributes:{reviewPackId:t.pack.packId,reviewPackVersion:t.pack.version}},relationships:[{relation:"reviews",target:{type:"artifact",id:t.target.artifactId,revision:t.target.revision}}],anchors:Zt(t.findings.flatMap(s=>s.anchors)),...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},extensions:{"xeno.review.pack":t.pack.packId,"xeno.review.verified":t.summary.verified,"xeno.review.unverified":t.summary.unverified,"xeno.review.rejected":t.summary.rejected}};return R(r),r}function oo(t){if(t.kind!=="review-report"||t.mediaType!=="application/vnd.xeno.review-report+json")throw new S([`Artifact ${t.artifactId} is not a XENO review report`]);if(t.content.storage.type!=="inline"||typeof t.content.storage.text!="string")throw new S(["Review report requires inline JSON content"]);let e;try{e=JSON.parse(t.content.storage.text)}catch(n){throw new S([`Review report JSON is invalid: ${n instanceof Error?n.message:String(n)}`])}if(be(e),!Di(k(e),t.content.hash))throw new S(["Review report content hash is invalid"]);return structuredClone(e)}function so(t,e={}){be(t);let n=[];for(let i of t.findings){if(e.verifiedOnly!==!1&&i.state!=="verified")continue;let o=i.anchors.find(r=>r.kind==="source-line"||r.kind==="file"||r.kind==="diff-hunk");!o||!("path"in o)||n.push({findingId:i.findingId,path:o.path,...o.kind==="source-line"?{line:o.startLine}:{},severity:i.severity,verified:i.state==="verified",body:[`**${i.severity.toUpperCase()} - ${i.title}**`,"",i.summary,"",`Evidence: ${i.evidence.map(r=>r.summary).join("; ")||"none"}`,i.remediation?`Suggested remediation: ${i.remediation}`:"",`XENO finding: ${i.findingId} (${i.state}, confidence ${i.confidence.toFixed(2)})`].filter(Boolean).join(`
|
|
9
|
+
`)})}return n}function ki(t,e){let n=new Map;for(let i of t){Gt(i.finding),Xe(i.reviewerAgentId,"reviewerAgentId");let o=Ci(i.finding),r=n.get(o)??[];r.push(structuredClone(i)),n.set(o,r)}return[...n.entries()].map(([i,o])=>{let r=[...o].sort((d,a)=>Y(a.finding.severity)-Y(d.finding.severity))[0],s=Yt(o.flatMap(d=>d.finding.evidence));return{findingId:Xe(e("finding"),"findingId"),fingerprint:i,ruleIds:[...new Set(o.flatMap(d=>d.finding.ruleId?[d.finding.ruleId]:[]))].sort(),dimensions:[...new Set(o.map(d=>d.finding.dimension))].sort(),reviewerAgentIds:[...new Set(o.map(d=>d.reviewerAgentId))].sort(),title:r.finding.title,summary:r.finding.summary,severity:o.reduce((d,a)=>Y(a.finding.severity)>Y(d)?a.finding.severity:d,r.finding.severity),confidence:rn(Math.max(...o.map(d=>d.finding.confidence))),state:"unverified",verificationBasis:"none",anchors:Zt(o.flatMap(d=>d.finding.anchors)),evidence:s,verifications:[],...r.finding.remediation?{remediation:r.finding.remediation}:{},duplicateProposalCount:o.length}})}function Ci(t){let e=t.anchors.map(Qt).sort();return k({ruleId:t.ruleId??"",title:Vi(t.title),anchors:e}).value}function Ni(t,e,n){let i=[];N(t?.reviewerAgentId,"reviewerAgentId",i),t?.dimension!==e&&i.push(`Reviewer returned dimension ${t?.dimension} for requested ${e}`),Re(t?.completedAt,"reviewer completedAt",i),(!Array.isArray(t?.findings)||t.findings.length>n)&&i.push("Reviewer finding list is invalid or exceeds maxFindings");for(let o of t?.findings??[]){try{Gt(o)}catch(r){i.push(r instanceof Error?r.message:String(r))}o.dimension!==e&&i.push(`Finding dimension ${o.dimension} differs from reviewer dimension ${e}`)}if(i.length>0)throw new S([...new Set(i)])}function Gt(t){let e=[];nn(t?.dimension)||e.push(`Invalid finding dimension ${t?.dimension}`),U(t?.title,"finding title",e),U(t?.summary,"finding summary",e),tn(t?.severity)||e.push(`Invalid finding severity ${t?.severity}`),(!Number.isFinite(t?.confidence)||t.confidence<0||t.confidence>1)&&e.push("Finding confidence must be 0 through 1"),(!Array.isArray(t?.anchors)||t.anchors.length===0)&&e.push("Finding needs at least one source or artifact anchor"),Array.isArray(t?.evidence)||e.push("Finding evidence must be an array");for(let n of t?.evidence??[])He(n,e);if(t?.ruleId!==void 0&&N(t.ruleId,"ruleId",e),e.length>0)throw new S([...new Set(e)])}function Pi(t){let e=[];N(t?.verifierAgentId,"verifierAgentId",e),["reproduced","rejected","inconclusive"].includes(t?.outcome)||e.push("Verifier outcome is invalid"),U(t?.rationale,"verifier rationale",e),Re(t?.completedAt,"verifier completedAt",e),Array.isArray(t?.evidence)||e.push("Verifier evidence must be an array");for(let n of t?.evidence??[])He(n,e);if(t?.outcome==="reproduced"&&(t?.evidence?.length??0)===0&&e.push("A reproduced finding requires verifier evidence"),t?.confidence!==void 0&&(!Number.isFinite(t.confidence)||t.confidence<0||t.confidence>1)&&e.push("Verifier confidence must be 0 through 1"),e.length>0)throw new S([...new Set(e)])}function He(t,e){N(t?.evidenceId,"evidenceId",e),N(t?.producerId,"evidence producerId",e),U(t?.summary,"evidence summary",e),(typeof t?.kind!="string"||!(Ti.includes(t.kind)||B(t.kind)))&&e.push(`Invalid evidence kind ${t?.kind}`)}function Yt(t){let e=new Map;for(let n of t){let i=[];if(He(n,i),i.length>0)throw new S(i);let o=e.get(n.evidenceId);if(o&&T(o)!==T(n))throw new S([`Conflicting evidence ID ${n.evidenceId}`]);e.set(n.evidenceId,structuredClone(n))}return[...e.values()].sort((n,i)=>n.evidenceId.localeCompare(i.evidenceId))}function $i(t){let e=new Map;for(let n of t){if(e.has(n.verifierAgentId))throw new S([`Verifier ${n.verifierAgentId} returned more than one result for a finding`]);e.set(n.verifierAgentId,structuredClone(n))}return[...e.values()].sort((n,i)=>n.verifierAgentId.localeCompare(i.verifierAgentId))}function Zt(t){let e=new Map;for(let n of t)e.set(Qt(n),structuredClone(n));return[...e.entries()].sort(([n],[i])=>n.localeCompare(i)).map(([,n])=>n)}function Qt(t){return T(t)}function en(t){let e={info:0,low:0,medium:0,high:0,critical:0};for(let n of t)e[n.severity]+=1;return{total:t.length,verified:t.filter(n=>n.state==="verified").length,unverified:t.filter(n=>n.state==="unverified").length,rejected:t.filter(n=>n.state==="rejected").length,bySeverity:e}}function Oi(t,e){return Y(e.severity)-Y(t.severity)||+(e.state==="verified")-+(t.state==="verified")||t.fingerprint.localeCompare(e.fingerprint)}function Y(t){return{info:0,low:1,medium:2,high:3,critical:4}[t]}function tn(t){return typeof t=="string"&&["info","low","medium","high","critical"].includes(t)}function nn(t){return typeof t=="string"&&(xi.includes(t)||B(t))}function Vi(t){return t.trim().toLowerCase().replace(/\s+/gu," ")}function rn(t){return Math.max(0,Math.min(1,Number(t.toFixed(6))))}function N(t,e,n){(typeof t!="string"||!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u.test(t))&&n.push(`${e} has an invalid identifier`)}function Xe(t,e){let n=[];if(N(t,e,n),n.length>0)throw new S(n);return t}function U(t,e,n){(typeof t!="string"||t.trim().length===0||t.length>64*1024)&&n.push(`${e} must be non-empty and no longer than 65536 characters`)}function Re(t,e,n){(typeof t!="string"||!t.includes("T")||!Number.isFinite(Date.parse(t)))&&n.push(`${e} must be an ISO 8601 timestamp`)}function Di(t,e){return t.algorithm===e.algorithm&&t.value===e.value}import{Buffer as Se}from"node:buffer";function mo(t,e){let n=e.contentEncoding??"utf8",i=n==="base64"?Se.from(t.content,"base64"):Se.from(t.content,"utf8"),o=[e.identity?.runId,e.identity?.taskId,e.identity?.turnId].filter(Boolean).join(":"),r=x(`${o}:${t.name}:${t.mimeType??""}:${t.content}`).value.slice(0,24),s={schemaVersion:1,artifactId:e.artifactId??`legacy_agent_artifact_${r}`,revision:e.revision??1,kind:e.kind??Fi(t),title:t.name,state:e.state??"draft",createdAt:e.createdAt??new Date().toISOString(),mediaType:t.mimeType??"text/plain",sensitivity:e.sensitivity??"internal",...e.identity?{identity:structuredClone(e.identity)}:{},content:{hash:x(i),sizeBytes:i.byteLength,encoding:n,storage:n==="base64"?{type:"inline",base64:t.content}:{type:"inline",text:t.content}},provenance:{producer:{...e.producer}},...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},extensions:{"xeno.legacy.agentArtifact":{name:t.name,...t.mimeType?{mimeType:t.mimeType}:{},content:t.content,encoding:n}}};return R(s),s}function ho(t){R(t);let e=t.extensions?.["xeno.legacy.agentArtifact"];if(je(e)&&typeof e.name=="string"&&typeof e.content=="string")return{name:e.name,...typeof e.mimeType=="string"?{mimeType:e.mimeType}:{},content:e.content};if(t.content.storage.type!=="inline")throw new TypeError("Only inline XENO artifacts can be converted to legacy AgentArtifact values");return{name:t.title,mimeType:t.mediaType,content:t.content.storage.text??t.content.storage.base64??""}}function go(t,e){let n=on(t),i=T(n),o={schemaVersion:1,artifactId:e.artifactId??t.id,revision:e.revision??1,kind:Li(t),title:t.path?`Evidence for ${t.path}`:`Tool evidence ${t.id}`,state:e.state??"draft",createdAt:e.createdAt??t.observedAt,mediaType:"application/vnd.xeno.tool-evidence+json",sensitivity:e.sensitivity??"internal",...e.identity?{identity:structuredClone(e.identity)}:{},content:{hash:k(n),sizeBytes:Se.byteLength(i,"utf8"),encoding:"utf8",storage:{type:"inline",text:i}},provenance:{producer:{...e.producer},operationId:t.operationId,attributes:{legacyEvidenceId:t.id,legacyEvidenceKind:t.kind,legacyEvidenceStatus:t.status}},...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},extensions:{"xeno.legacy.toolEvidence":n}};return R(o),o}function vo(t){R(t);let e=t.extensions?.["xeno.legacy.toolEvidence"];if(Mi(e))return structuredClone(e);throw new TypeError("XENO artifact does not contain lossless legacy ToolEvidence data")}function yo(t,e){let n=on(t),i=t.files.map(s=>s.patch).filter(s=>!!s);if(t.files.length>0&&i.length===t.files.length&&i.every(s=>s.startsWith("diff --git ")))try{let s=$t(i.join(`
|
|
10
|
+
`),{artifactId:e.artifactId??`turn_diff_${t.turnId}`,revision:e.revision??1,createdAt:e.createdAt??t.completedAt,title:`Turn ${t.turnId} changes`,producer:e.producer,identity:{...e.identity?structuredClone(e.identity):{},turnId:e.identity?.turnId??t.turnId},sensitivity:e.sensitivity??"internal",...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},mode:"turn"}),d={...s,state:e.state??s.state,extensions:{...s.extensions??{},"xeno.legacy.turnDiffSummary":n}};return R(d),d}catch{}let o=T(n),r={schemaVersion:1,artifactId:e.artifactId??`turn_diff_${t.turnId}`,revision:e.revision??1,kind:"diff",title:`Turn ${t.turnId} changes`,state:e.state??"pending_review",createdAt:e.createdAt??t.completedAt,mediaType:"application/vnd.xeno.turn-diff+json",sensitivity:e.sensitivity??"internal",identity:{...e.identity?structuredClone(e.identity):{},turnId:e.identity?.turnId??t.turnId},content:{hash:k(n),sizeBytes:Se.byteLength(o,"utf8"),encoding:"utf8",storage:{type:"inline",text:o}},provenance:{producer:{...e.producer}},anchors:t.files.map(s=>({kind:"custom:source-file",data:{path:s.path}})),...e.accessPolicyId?{accessPolicyId:e.accessPolicyId}:{},extensions:{"xeno.legacy.turnDiffSummary":n}};return R(r),r}function Ao(t){R(t);let e=t.extensions?.["xeno.legacy.turnDiffSummary"];if(Hi(e))return structuredClone(e);throw new TypeError("XENO artifact does not contain lossless TurnDiffSummary data")}function Fi(t){let e=t.name.toLowerCase(),n=t.mimeType?.toLowerCase()??"";return e.endsWith(".patch")||n.includes("patch")?"patch":e.endsWith(".diff")||n.includes("diff")?"diff":n.startsWith("image/")?"screenshot":n.startsWith("video/")?"recording":n.includes("json")&&e.includes("report")?"test-report":"file"}function Li(t){return t.kind==="artifact"?t.path?"file":"custom:tool-artifact-evidence":t.kind==="verification"?"test-report":"custom:tool-process-evidence"}function on(t){return JSON.parse(JSON.stringify(t))}function je(t){return t!==null&&typeof t=="object"&&!Array.isArray(t)}function Mi(t){return je(t)?typeof t.id=="string"&&(t.kind==="artifact"||t.kind==="process"||t.kind==="verification")&&(t.status==="pending"||t.status==="verified"||t.status==="failed")&&typeof t.observedAt=="string"&&typeof t.operationId=="string":!1}function Hi(t){return je(t)?typeof t.turnId=="string"&&typeof t.startedAt=="string"&&typeof t.completedAt=="string"&&Array.isArray(t.files):!1}import{createHash as fn}from"node:crypto";import{existsSync as ji,mkdirSync as Be,readFileSync as _e,readdirSync as Bi,statSync as qi,writeFileSync as Ji,renameSync as zi,rmSync as Ui}from"node:fs";import{extname as Wi,join as V,resolve as sn,sep as Ki}from"node:path";import{randomUUID as We}from"node:crypto";var D="index.html",Gi=16*1024*1024,an=255,Yi={".html":"text/html; charset=utf-8",".htm":"text/html; charset=utf-8",".css":"text/css; charset=utf-8",".js":"text/javascript; charset=utf-8",".mjs":"text/javascript; charset=utf-8",".json":"application/json; charset=utf-8",".md":"text/markdown; charset=utf-8",".txt":"text/plain; charset=utf-8",".csv":"text/csv; charset=utf-8",".svg":"image/svg+xml",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp",".ico":"image/x-icon",".woff":"font/woff",".woff2":"font/woff2",".ttf":"font/ttf",".otf":"font/otf",".mp4":"video/mp4",".webm":"video/webm",".mp3":"audio/mpeg",".wav":"audio/wav",".pdf":"application/pdf",".wasm":"application/wasm"};function qe(t){return Yi[Wi(t).toLowerCase()]??"application/octet-stream"}function Zi(t){let e=t.slice(0,8192),i=/<title[^>]*>([\s\S]*?)<\/title>/iu.exec(e)?.[1]?.replace(/\s+/gu," ").trim();return i?i.slice(0,200):void 0}function cn(t){let e=t.trim().replace(/\\/gu,"/");if(!e)return{error:"A file path is required."};if(e.startsWith("/")||/^[a-zA-Z]:/u.test(e))return{error:`File path must be relative: ${t}`};let n=e.split("/");return n.some(i=>i===""||i==="."||i==="..")?{error:`File path must not contain empty, "." or ".." segments: ${t}`}:n.some(i=>/[<>:"|?*\u0000-\u001f]/u.test(i))?{error:`File path contains characters a filesystem refuses: ${t}`}:n.join("/")===D?{error:`${D} is the page itself; supporting files need another path.`}:{path:n.join("/")}}function Qi(t){return fn("sha256").update(t).digest("hex")}function Je(t){return typeof t=="string"?new TextEncoder().encode(t):t}function ze(t,e){let n=`${t}.${process.pid}.${We().slice(0,8)}.tmp`;Ji(n,e);try{zi(n,t)}catch(i){throw Ui(n,{force:!0}),i}}function Ue(t){let e=t.artifact.extensions?.page;return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}var dn=class{repository;directory;now;maxBytes;constructor(e){if(!e?.repository)throw new TypeError("XenoPageStore requires an artifact repository");if(typeof e.directory!="string"||!e.directory.trim())throw new TypeError("XenoPageStore requires a directory");this.repository=e.repository,this.directory=sn(e.directory),this.now=e.now??(()=>new Date().toISOString()),this.maxBytes=e.maxBytes??Gi}revisionDirectory(e,n){if(!/^[A-Za-z0-9_-]+$/u.test(e))throw new TypeError(`Unsafe artifact id: ${e}`);return V(this.directory,e,`r${n}`)}async publish(e){let n=typeof e.html=="string"?e.html:"";if(!n.trim())throw new TypeError("A page needs HTML content.");let i=new Map;for(let X of e.files??[]){let I=cn(X.path);if("error"in I)throw new TypeError(I.error);if(i.has(I.path))throw new TypeError(`Duplicate file path: ${I.path}`);i.set(I.path,{bytes:Je(X.bytes),contentType:X.contentType??qe(I.path)})}if(i.size>an)throw new TypeError(`A page may carry at most ${an} files.`);let o=Je(n),r=o.byteLength+[...i.values()].reduce((X,I)=>X+I.bytes.byteLength,0);if(r>this.maxBytes)throw new TypeError(`Page revision is ${r} bytes; the limit is ${this.maxBytes}.`);let s=fn("sha256").update(o),d={};for(let[X,I]of[...i.entries()].sort(([H],[fe])=>H.localeCompare(fe)))d[X]={sha256:Qi(I.bytes),sizeBytes:I.bytes.byteLength,contentType:I.contentType},s.update(`\0${X}\0${d[X].sha256}`);let a=s.digest("hex"),c=e.artifactId?await this.repository.get(e.artifactId):void 0;if(e.artifactId&&!c)throw new TypeError(`Unknown page artifact ${e.artifactId}.`);if(c&&c.artifact.kind!=="page")throw new TypeError(`Artifact ${e.artifactId} is a ${c.artifact.kind}, not a page.`);if(c&&c.artifact.content.hash.value===a)return{...await this.toPublished(c),unchanged:!0};let f=c?.artifact.artifactId??`page_${We().replaceAll("-","").slice(0,20)}`,g=c?c.artifact.revision+1:1,y=this.revisionDirectory(f,g);Be(y,{recursive:!0});let P=V(y,D);ze(P,o);for(let[X,I]of i){let H=V(y,...X.split("/"));Be(V(H,".."),{recursive:!0}),ze(H,I.bytes)}let m=c?Ue(c):{},h=e.title?.trim()||Zi(n)||(typeof m.title=="string"?m.title:void 0)||"Untitled page",E=e.icon?.trim()||(typeof m.icon=="string"?m.icon:void 0),L=e.description?.trim()||c?.artifact.description,W=Array.isArray(m.publications)?m.publications:[],K=this.now(),M={schemaVersion:1,artifactId:f,revision:g,kind:"page",title:h,...L?{description:L}:{},state:"draft",createdAt:c?.artifact.createdAt??K,updatedAt:K,mediaType:"text/html",sensitivity:c?.artifact.sensitivity??"internal",...e.identity??c?.artifact.identity?{identity:e.identity??c.artifact.identity}:{},content:{hash:{algorithm:"sha256",value:a},sizeBytes:r,storage:{type:"file",path:P},encoding:"utf8",redactedPreview:n.slice(0,200)},provenance:{producer:e.producer},...c?{predecessorRevision:c.artifact.revision}:{},extensions:{page:{entry:D,htmlSha256:x(o).value,files:d,...E?{icon:E}:{},title:h,publications:W,...e.home?{requestedHome:e.home}:{}}}},$=c?await this.repository.createRevision(M,{actor:e.producer,reason:"page republished"}):await this.repository.create(M);return this.toPublished($)}async recordPublication(e,n){let i=await this.repository.require(e),o=Ue(i),s=(await this.toPublished(i)).publications.filter(a=>a.home!==n.home);s.push(n);let d={...i.artifact,revision:i.artifact.revision,extensions:{...i.artifact.extensions,page:{...o,publications:s}}};return this.writeSidecar(e,{publications:s}),this.toPublished({...i,artifact:d})}sidecarPath(e){return V(this.directory,e,"publications.json")}writeSidecar(e,n){Be(V(this.directory,e),{recursive:!0}),ze(this.sidecarPath(e),Je(`${JSON.stringify(n,null,2)}
|
|
11
|
+
`))}readSidecar(e){try{let n=JSON.parse(_e(this.sidecarPath(e),"utf8"));return Array.isArray(n.publications)?n.publications:[]}catch{return[]}}async get(e,n){let i=await this.repository.get(e,n);if(!(!i||i.artifact.kind!=="page"))return this.toPublished(i)}async list(){let e=await this.repository.list({kinds:["page"]});return(await Promise.all(e.map(i=>this.toPublished(i)))).sort((i,o)=>(o.updatedAt??o.createdAt).localeCompare(i.updatedAt??i.createdAt))}resolveFile(e,n,i){let o=i===D||i===""?{path:D}:cn(i);if("error"in o)return;let r=this.revisionDirectory(e,n),s=sn(r,...o.path.split("/"));if(!(s!==r&&!s.startsWith(r+Ki))&&!(!ji(s)||!qi(s).isFile()))return{path:s,contentType:qe(s)}}readEntry(e,n){let i=this.resolveFile(e,n,D);return i?_e(i.path,"utf8"):void 0}readRevision(e,n){let i=this.revisionDirectory(e,n),o=_e(V(i,D),"utf8"),r=[],s=(d,a)=>{for(let c of Bi(d,{withFileTypes:!0})){let f=a?`${a}/${c.name}`:c.name;c.isDirectory()?s(V(d,c.name),f):f!==D&&r.push({path:f,bytes:_e(V(d,c.name)),contentType:qe(f)})}};return s(i,""),{html:o,files:r}}async addComment(e,n,i,o){let r=await this.repository.require(e);if(r.artifact.kind!=="page")throw new TypeError(`Artifact ${e} is a ${r.artifact.kind}, not a page.`);let s=n.trim();if(!s)throw new TypeError("A comment needs text.");let a=(await this.repository.appendReviewEvent({event:{type:"comment-added",artifactId:e,artifactRevision:r.artifact.revision,artifactHash:r.artifact.content.hash,actor:i,commentId:`cmt_${We().replaceAll("-","").slice(0,16)}`,body:s.slice(0,2e4),...o?{anchor:o}:{}}})).reviewEvents.at(-1);if(!a||a.type!=="comment-added")throw new Error("Comment was not recorded.");return a}async listComments(e){await this.repository.require(e);let n=await this.repository.listRevisions(e),i=new Set,o=[];for(let r of n)for(let s of r.reviewEvents)s.type!=="comment-added"||i.has(s.commentId)||(i.add(s.commentId),o.push(s));return o.sort((r,s)=>r.recordedAt.localeCompare(s.recordedAt)||r.sequence-s.sequence)}async toPublished(e){let n=Ue(e),i=n.files&&typeof n.files=="object"&&!Array.isArray(n.files)?n.files:{},o=this.readSidecar(e.artifact.artifactId),s=[...(Array.isArray(n.publications)?n.publications:[]).filter(d=>!o.some(a=>a.home===d.home)),...o];return{artifactId:e.artifact.artifactId,revision:e.artifact.revision,title:e.artifact.title,...e.artifact.description?{description:e.artifact.description}:{},...typeof n.icon=="string"?{icon:n.icon}:{},hash:e.artifact.content.hash.value,sizeBytes:e.artifact.content.sizeBytes,files:i,directory:this.revisionDirectory(e.artifact.artifactId,e.artifact.revision),entryPath:V(this.revisionDirectory(e.artifact.artifactId,e.artifact.revision),D),publications:s,createdAt:e.artifact.createdAt,...e.artifact.updatedAt?{updatedAt:e.artifact.updatedAt}:{}}}};export{Et as FileXenoArtifactRepository,ie as InMemoryXenoArtifactRepository,tt as XENO_ARTIFACT_ACTOR_KINDS,_t as XENO_ARTIFACT_FILE_REPOSITORY_SCHEMA_VERSION,v as XENO_ARTIFACT_SCHEMA_VERSION,et as XENO_ARTIFACT_SENSITIVITIES,Qe as XENO_ARTIFACT_STATES,Ze as XENO_BUILTIN_ARTIFACT_KINDS,le as XENO_EVIDENCE_EDGE_TYPES,pe as XENO_EVIDENCE_GRAPH_SCHEMA_VERSION,ue as XENO_EVIDENCE_NODE_TYPES,D as XENO_PAGE_ENTRY,Gi as XENO_PAGE_MAX_BYTES,an as XENO_PAGE_MAX_FILES,xi as XENO_REVIEW_DIMENSIONS,Ti as XENO_REVIEW_EVIDENCE_KINDS,Ut as XENO_REVIEW_REPORT_SCHEMA_VERSION,we as XENO_SPEC_EXECUTION_SCHEMA_VERSION,ae as XENO_SPEC_SCHEMA_VERSION,u as XenoArtifactRepositoryError,re as XenoArtifactReviewService,ke as XenoArtifactStateTransitionError,G as XenoArtifactValidationError,_ as XenoDiffParseError,st as XenoEvidenceGraphBuilder,$e as XenoEvidenceGraphValidationError,zt as XenoMultiAgentReviewCoordinator,dn as XenoPageStore,S as XenoReviewValidationError,Lt as XenoSpecLifecycleService,b as XenoSpecValidationError,R as assertValidXenoArtifact,te as assertValidXenoEvidenceGraph,Wt as assertValidXenoReviewPack,be as assertValidXenoReviewReport,Kt as assertValidXenoReviewTarget,Me as assertValidXenoSpecDocument,Bt as assertValidXenoSpecExecution,me as assertXenoArtifactStateTransition,Dt as buildXenoArtifactReviewAnchor,_n as canTransitionXenoArtifactState,T as canonicalizeArtifactJson,io as defaultXenoReviewPack,Gr as detectXenoSpecDrift,Zi as extractPageTitle,mo as legacyAgentArtifactToXenoArtifact,cn as normalizePagePath,vi as normalizeRepositoryRelativePath,qe as pageContentType,Pt as parseUnifiedDiff,x as sha256ArtifactBytes,k as sha256ArtifactJson,Pe as summarizeXenoArtifactReview,go as toolEvidenceToXenoArtifact,yo as turnDiffSummaryToXenoArtifact,$t as unifiedDiffToXenoArtifact,Sn as validateXenoArtifact,Ne as validateXenoArtifactReviewEvent,Cn as validateXenoEvidenceGraph,Ii as validateXenoSpecDocument,Ot as xenoArtifactToDiffDocument,ho as xenoArtifactToLegacyAgentArtifact,oo as xenoArtifactToReviewReport,Ht as xenoArtifactToSpecDocument,wi as xenoArtifactToSpecExecution,vo as xenoArtifactToToolEvidence,Ao as xenoArtifactToTurnDiffSummary,ro as xenoReviewReportToArtifact,so as xenoReviewReportToGitHubComments,oe as xenoSpecArtifactIds,jt as xenoSpecExecutionToArtifact,Mt as xenoSpecToArtifactBundle};
|