@uibot/evaluation 0.20.0 → 0.22.0

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.
@@ -36,6 +36,14 @@ export interface PromotionDecision {
36
36
  parent?: VisualEvaluationEvidence;
37
37
  proposed?: VisualEvaluationEvidence;
38
38
  }>;
39
+ /** Per-case execution gate receipt; no stdout, code or environment is persisted. */
40
+ executionChecks?: Array<{
41
+ caseId: string;
42
+ requested: number;
43
+ reported: number;
44
+ passed: number;
45
+ status: "passed" | "unmet";
46
+ }>;
39
47
  /** Regression IDs that failed the hard gate (only set when decision is "rejected-regression") */
40
48
  regressionFailures?: string[];
41
49
  /** All regression IDs that were evaluated (diagnostic) */
@@ -0,0 +1,3 @@
1
+ import type { EvalScore } from "./types.js";
2
+ /** Declared candidate checks are a hard gate, independent of score weights. */
3
+ export declare function hasUnmetExecutionChecks(score: EvalScore, expectedCount?: number): boolean;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{createHash as B}from"crypto";function f(e,t){return B("sha256").update(JSON.stringify([e,t])).digest("hex")}function E(e){return typeof e==="number"&&Number.isFinite(e)&&e>=0&&e<=1}var H=new Set(["rule-scan","structural-heuristic","model-text","model-screenshot","legacy-provider","unassessed"]),W=new Set(["empty-input","invalid-score","provider-failed","provider-not-run","invalid-evidence","screenshot-unavailable","timeout"]);async function k(e,t,r){let s=f(t,r),o=(i)=>({status:"unavailable",method:"unassessed",subjectHash:s,reason:i});if(!t.trim())return o("empty-input");try{if(e.evaluate){let n=await e.evaluate(t,r);if(!n||n.subjectHash!==s||!H.has(n.method))return o("invalid-evidence");if(n.status==="scored"&&n.method!=="unassessed"&&E(n.score))return{status:"scored",method:n.method,subjectHash:s,score:n.score};if(n.status==="unavailable"&&n.score===void 0&&W.has(n.reason))return{status:"unavailable",method:n.method,subjectHash:s,reason:n.reason};return o("invalid-evidence")}let i=await e(t,r);return E(i)?{status:"scored",method:"legacy-provider",subjectHash:s,score:i}:o("invalid-score")}catch{return o("provider-failed")}}function m(e){let t=e.visualEvidence;return t!==void 0&&(t.status!=="scored"||!E(t.score)||t.method==="unassessed")}var z=[{label:"_js operator",re:/_js\s*:/g},{label:"_secret operator",re:/_secret\s*:/g},{label:"external URL",re:/https?:\/\/[^\s'"]+/g}];function U(e,t){let r=[];for(let{label:s,re:o}of z){let i=(e.match(o)??[]).length,n=(t.match(o)??[]).length;if(n>i)r.push(`New ${s} introduced (${i} \u2192 ${n})`)}return r}var h={layout:["PageLayout","Card","Box","Tabs","Drawer","Modal"],nav:["PageSiderMenu","Breadcrumb","MenuLink","Link"],data:["Table","List","Stat"],form:["Form","Form.Input","Form.Select","Form.TextArea","Form.Checkbox"],feedback:["Toast","Dialog","Skeleton"],content:["Heading","Paragraph","Markdown","Divider"],action:["Button"]},J=["Form.Submit","Button"];function K(e){let t=Object.values(h).filter((l)=>l.some((j)=>e.includes(j))).length,r=Object.keys(h).length,s=Math.min(1,t/(r*0.7)),o=e.split(`
3
- `).filter((l)=>l.trim().length>0).map((l)=>l.match(/^(\s*)/)?.[1]?.length??0),i=o.length>0?Math.max(...o):0,n=Math.min(1,i/12),a=h.form.some((l)=>e.includes(l)),d=J.some((l)=>e.includes(l)),c=!a?1:d?1:0.4,u=[...h.layout,...h.data].some((l)=>e.includes(l)),g=[...h.content,...h.action].some((l)=>e.includes(l)),y=u&&g?1:u||g?0.6:0.2;return s*0.35+n*0.15+c*0.2+y*0.3}function D(e){let t=/```ya?ml[\s\S]*?```/i.test(e),r=/\bpage\s*:/i.test(e),s=/\bblocks\s*:/i.test(e);if(t)return 1;if(r&&s)return 0.9;if(r||s)return 0.5;return 0}function I(e,t,r){return e*0.4+t*0.35+r*0.25}class p{visualScoreProvider;constructor(e={}){this.visualScoreProvider=e.visualScoreProvider??void 0}async run(e,t){let r=D(t),s=e.expectedBlocks.filter((a)=>t.toLowerCase().includes(a.toLowerCase())),o=e.expectedBlocks.length===0?1:s.length/e.expectedBlocks.length,i=this.visualScoreProvider?await k(this.visualScoreProvider,t,e.intent):this.structuralEvidence(t,e.intent),n=i.status==="scored"?i.score:0;return{renderable:r,schemaValid:o,visualHeuristic:n,visualEvidence:i,overallScore:I(r,o,n),safetyOk:!0}}runSync(e,t){let r=D(t),s=e.expectedBlocks.filter((a)=>t.toLowerCase().includes(a.toLowerCase())),o=e.expectedBlocks.length===0?1:s.length/e.expectedBlocks.length,i=this.visualScoreProvider?{status:"unavailable",method:"unassessed",subjectHash:f(t,e.intent),reason:"provider-not-run"}:this.structuralEvidence(t,e.intent),n=i.status==="scored"?i.score:0;return{renderable:r,schemaValid:o,visualHeuristic:n,visualEvidence:i,overallScore:I(r,o,n),safetyOk:!0}}structuralEvidence(e,t){let r=f(e,t);return e.trim()?{status:"scored",method:"structural-heuristic",subjectHash:r,score:K(e)}:{status:"unavailable",method:"unassessed",subjectHash:r,reason:"empty-input"}}checkSafetyRegressions(e,t){return U(e,t)}}var G=0.3;function q(e){return Math.max(0,Math.min(1,e))}function Y(e,t){return Bun.deepEquals(e,t)}function X(e,t){if(!t.success)return{passed:!1,failureReason:t.errorMessage??t.errorCode??"execution failed"};for(let r of e.expectedStdoutIncludes??[])if(!t.stdout.includes(r))return{passed:!1,failureReason:`stdout missing expected text: ${r}`};for(let r of e.expectedStderrIncludes??[])if(!t.stderr.includes(r))return{passed:!1,failureReason:`stderr missing expected text: ${r}`};if(Object.hasOwn(e,"expectedReturnValue")&&!Y(t.returnValue,e.expectedReturnValue))return{passed:!1,failureReason:"returnValue did not match expected value"};return{passed:!0}}function Z(e,t){return{passed:t.passed,success:e.success,stdout:e.stdout,stderr:e.stderr,durationMs:e.durationMs,...e.errorCode?{errorCode:e.errorCode}:{},...e.errorMessage?{errorMessage:e.errorMessage}:{},...t.failureReason?{failureReason:t.failureReason}:{}}}function ee(){return{passed:!1,success:!1,stdout:"",stderr:"",durationMs:0,errorCode:"runtime-not-configured",errorMessage:"ExecutionRuntime is not configured",failureReason:"runtime not configured"}}function te(e){let t=e instanceof Error?e.message:String(e);return{passed:!1,success:!1,stdout:"",stderr:"",durationMs:0,errorCode:"internal-error",errorMessage:t,failureReason:t}}var re=/\{\{skillBody\}\}(?!Json)/,O="{{skillBodyJson}}";function ne(e,t,r){if(re.test(e))throw Error("EvalExecutionCheck.code contains unsafe `{{skillBody}}` placeholder. "+"Use `{{skillBodyJson}}` (JSON-encoded) instead \u2014 raw substitution lets "+"a malicious candidate body escape the eval template.");if(r==="shell"&&e.includes(O))throw Error('EvalExecutionCheck.code uses `{{skillBodyJson}}` in a shell check, but JSON encoding does not neutralize bash command substitution. Pass the skill body via `check.env` (e.g. SKILL_BODY) and read it inside the shell script with `"$SKILL_BODY"` instead.');return e.replaceAll(O,JSON.stringify(t))}function se(e,t){return{language:e.language,code:ne(e.code,t,e.language),...e.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},fetchAllowed:e.fetchAllowed===!0,...e.env?{env:e.env}:{}}}class x{staticRunner;executionRuntime;executionWeight;constructor(e={}){this.staticRunner=new p(e.visualScoreProvider!==void 0?{visualScoreProvider:e.visualScoreProvider}:{}),this.executionRuntime=e.executionRuntime,this.executionWeight=q(e.executionWeight??G)}async run(e,t){let r=await this.staticRunner.run(e,t),s=e.executionChecks??[];if(s.length===0)return r;let o=[];for(let n of s){if(!this.executionRuntime){o.push(ee());continue}try{let a=await this.executionRuntime.run(se(n,t));o.push(Z(a,X(n,a)))}catch(a){o.push(te(a))}}let i=o.length===0?void 0:o.filter((n)=>n.passed).length/o.length;if(i===void 0)return r;return{...r,executionScore:i,executionResults:o,overallScore:r.overallScore*(1-this.executionWeight)+i*this.executionWeight}}checkSafetyRegressions(e,t){return this.staticRunner.checkSafetyRegressions(e,t)}}function V(e={}){if(e.runner)return e.runner;return new p(e.visualScoreProvider!==void 0?{visualScoreProvider:e.visualScoreProvider}:{})}async function R(e,t,r={}){return V(r).run(e,t)}function oe(e,t,r={}){return new p(r.visualScoreProvider!==void 0?{visualScoreProvider:r.visualScoreProvider}:{}).runSync(e,t)}async function _(e,t,r,s={}){let o=V(s),[i,n]=await Promise.all([o.run(e,t),o.run(e,r)]);if(m(i)||m(n))throw Error("visual-evaluation-unavailable");return n.overallScore-i.overallScore}function ie(e={}){let t=e.makeCase??((r)=>({id:`cand-${r.candidateIndex}`,intent:"tournament",expectedBlocks:[],skillId:r.skillId}));return async(r)=>{let s=t(r);if(!s)return 0;return _(s,r.currentBody,r.candidateBody,e)}}class L{runner;hasExecutionRuntime;staticRunner;constructor(e={}){this.staticRunner=new p(e),this.hasExecutionRuntime=e.executionRuntime!==void 0,this.runner=e.executionRuntime?new x({executionRuntime:e.executionRuntime,...e.visualScoreProvider!==void 0?{visualScoreProvider:e.visualScoreProvider}:{},...e.executionWeight!==void 0?{executionWeight:e.executionWeight}:{}}):new p(e.visualScoreProvider!==void 0?{visualScoreProvider:e.visualScoreProvider}:{})}async compare(e,t,r,s,o){let i=this.runner.checkSafetyRegressions(r,s),n=await Promise.all(o.map(async(c)=>{let u=await R(c,r,{runner:this.runner}),g=await R(c,s,{runner:this.runner}),y=g.overallScore-u.overallScore;return{caseId:c.id,parentScore:u,proposedScore:g,deltaScore:y,safetyRegression:i}})),a=n.length===0?0:n.reduce((c,u)=>c+u.deltaScore,0)/n.length,d=a>=0.05&&i.length===0&&!n.some((c)=>m(c.parentScore)||m(c.proposedScore))?"promoted":i.length>0?"rejected":"pending";return{skillId:e,proposalId:t,cases:n,meanDeltaScore:a,safetyRegressions:i,decision:d}}compareSync(e,t,r,s,o){if(this.hasExecutionRuntime)console.warn("[ShadowRunner] compareSync() ignores the injected executionRuntime; use compare() (async) to fold execution checks into the score.");let i=this.runner.checkSafetyRegressions(r,s),n=o.map((c)=>{let u=this.staticRunner,g=u.runSync(c,r),y=u.runSync(c,s),l=y.overallScore-g.overallScore;return{caseId:c.id,parentScore:g,proposedScore:y,deltaScore:l,safetyRegression:i}}),a=n.length===0?0:n.reduce((c,u)=>c+u.deltaScore,0)/n.length,d=a>=0.05&&i.length===0&&!n.some((c)=>m(c.parentScore)||m(c.proposedScore))?"promoted":i.length>0?"rejected":"pending";return{skillId:e,proposalId:t,cases:n,meanDeltaScore:a,safetyRegressions:i,decision:d}}}import{existsSync as ae,mkdirSync as w,readFileSync as ce,writeFileSync as b}from"fs";import{join as S}from"path";function ue(e){let t=e.split(".").map(Number);if(t.length!==3||t.some(Number.isNaN))return`${e}-promoted`;return`${t[0]}.${t[1]}.${(t[2]??0)+1}`}class A{options;constructor(e){this.options=e}async tryPromote(e,t){if(e.decision!=="promoted")return this.writeDecision(e,e.decision,"unknown","unknown"),e.decision;if(e.cases.some((r)=>m(r.parentScore)||m(r.proposedScore)))return this.writeDecision(e,"pending","unknown","unknown"),"pending";if(this.options.regressionCheck){let r;try{r=await this.options.regressionCheck(t)}catch(s){console.warn(`[auto-promoter] regression check threw; conservative reject: ${s instanceof Error?s.message:String(s)}`),r={passed:!1,failures:["__error__"],checkedCaseIds:[]}}if(!r.passed)return this.writeDecision(e,"rejected-regression","unknown","unknown",r),"rejected-regression";return this.performPromote(e,t,r)}return this.performPromote(e,t)}performPromote(e,t,r){let s=S(this.options.rootDir,".uibot","skills",e.skillId),o=S(s,"SKILL.md");if(!ae(o))return w(s,{recursive:!0}),b(o,t,"utf-8"),this.writeDecision(e,"promoted","0.0.0","1.0.0",r),"promoted";let i=ce(o,"utf-8"),n=i.match(/^version:\s*["']?([^"'\n]+)["']?\s*$/m),a=n?(n[1]??"1.0.0").trim():"1.0.0",d=ue(a),c=S(s,"versions",a);w(c,{recursive:!0}),b(S(c,"SKILL.md"),i,"utf-8");let u=t.replace(/^(version:\s*["']?)([^"'\n]+)(["']?\s*)$/m,`$1${d}$3`);return b(o,u,"utf-8"),this.writeDecision(e,"promoted",a,d,r),"promoted"}writeDecision(e,t,r,s,o){let i=S(this.options.rootDir,".uibot","skills",e.skillId);w(i,{recursive:!0});let n={skillId:e.skillId,proposalId:e.proposalId,fromVersion:r,toVersion:s,decision:t,meanDeltaScore:e.meanDeltaScore,safetyRegressions:e.safetyRegressions,caseCount:e.cases.length,timestamp:new Date().toISOString(),visualEvidence:e.cases.map((a)=>({caseId:a.caseId,...a.parentScore.visualEvidence?{parent:a.parentScore.visualEvidence}:{},...a.proposedScore.visualEvidence?{proposed:a.proposedScore.visualEvidence}:{}})),...o?{regressionChecked:o.checkedCaseIds,...o.failures.length>0?{regressionFailures:o.failures}:{}}:{}};b(S(i,"decision.json"),`${JSON.stringify(n,null,2)}
4
- `,"utf-8")}}function le(e){return e==="quality"?"blocking":"advisory"}var de=["streamline your","empower your","supercharge your","unlock the power","best-in-class","enterprise-grade","next-generation","cutting-edge","revolutionize","game-changer","game changer","future-proof","seamless experience","drive growth","harness the power","take it to the next level","world-class","state-of-the-art","robust solution","powerful platform","effortlessly","seamlessly integrate","elevate your","transform your"],ge=["Inter","Roboto","Geist","Fraunces","Plus Jakarta","Space Grotesk"];function v(e,t){let r=e.match(t);return r?r.length:0}var me=[{id:"marketing-buzzword",category:"slop",severity:"P2",message:"Marketing buzzwords read as AI filler \u2014 prefer concrete, specific copy.",detect:(e)=>{let t=e.toLowerCase();return de.reduce((r,s)=>r+(t.includes(s)?1:0),0)}},{id:"em-dash-overuse",category:"slop",severity:"P3",message:"Em-dash overuse (\u22655) is a strong AI-writing tell.",detect:(e)=>{let t=v(e,/[\u2014]|--(?=\S)/g);return t>=5?t-4:0}},{id:"aphoristic-cadence",category:"slop",severity:"P2",message:'Manufactured-contrast cadence ("Not an X. Just Y.") is a recognizable AI pattern.',detect:(e)=>{let t=v(e,/\bNot\s+(?:an?|just)\b[^.?!]*[.?!]/gi),r=v(e,/\b[A-Z][^.?!]*\.\s+(?:No|Just)\s+[a-z]/g),s=t+r;return s>=3?s:0}},{id:"numbered-section-markers",category:"slop",severity:"P3",message:"Numbered section scaffolding (01 / 02 / 03) is an overused AI layout tell.",detect:(e)=>{let t=e.match(/\b(0[1-9]|1[0-2])\b/g)??[],r=new Set(t);if(r.size<3)return 0;let s=[...r].map(Number).sort((i,n)=>i-n);return s.some((i,n)=>n>0&&i-s[n-1]===1)?r.size:0}}],pe=[{id:"gradient-text",category:"slop",severity:"P2",message:"Gradient text (bg-clip-text + transparent) is a classic AI hero tell.",detect:(e)=>v(e,/bg-clip-text[^"']*text-transparent|text-transparent[^"']*bg-clip-text|-webkit-background-clip\s*:\s*text/gi)},{id:"ai-color-palette",category:"slop",severity:"P2",message:"Purple/violet gradient palette is the most recognizable AI color tell.",detect:(e)=>v(e,/(from|via|to)-(purple|violet|fuchsia|indigo)-\d{3}|linear-gradient\([^)]*(?:#(?:8b5cf6|a855f7|7c3aed|6366f1))/gi)},{id:"side-tab",category:"slop",severity:"P2",message:"Thick colored side-border on a card (border-l-4 + accent) is the single most recognizable AI card tell.",detect:(e)=>v(e,/border-l-(4|8)\s+border-(purple|violet|indigo|blue|primary)/gi)},{id:"overused-font",category:"slop",severity:"P3",message:"Over-represented font (Inter/Geist/\u2026) without a brand reason reads as default AI styling.",detect:(e)=>ge.reduce((t,r)=>t+(new RegExp(`font-family[^;"']*${r}`,"i").test(e)?1:0),0)},{id:"emoji-icon",category:"slop",severity:"P2",message:"Emoji used as a heading/list/button icon is a stock AI tell \u2014 use a real icon or nothing.",detect:(e)=>v(e,/<(?:h[1-6]|li|button|summary|th)\b[^>]*>\s*(?:<[^>]+>\s*)*\p{Extended_Pictographic}/giu)},{id:"github-dark-glow",category:"slop",severity:"P3",message:"Flat #0D1117 background with a neon cyan/violet glow is the default AI dark-mode look.",detect:(e)=>/#0d1117/i.test(e)&&/(?:box-shadow|drop-shadow|text-shadow)[^;"']*(?:#06b6d4|#22d3ee|#00f0ff|#a78bfa|#8b5cf6|cyan|violet)/i.test(e)?1:0},{id:"tiny-text",category:"quality",severity:"P1",message:"Body text below ~14px (text-[10px]/[11px]/[12px]) harms readability and accessibility.",detect:(e)=>v(e,/text-\[(?:8|9|10|11|12)px\]|font-size\s*:\s*(?:8|9|10|11|12)px/gi)},{id:"gray-on-color",category:"quality",severity:"P1",message:"Gray text on a colored fill commonly fails WCAG contrast.",detect:(e)=>v(e,/bg-(?:primary|blue|indigo|violet|purple)-\d{3}[^"']*text-(?:gray|slate|zinc|neutral)-\d{3}/gi)}],Q={P0:0.3,P1:0.15,P2:0.08,P3:0.04};function ve(e){if(e>=0.9)return"A";if(e>=0.8)return"B";if(e>=0.65)return"C";if(e>=0.5)return"D";return"F"}var T=8,fe=/<\/?[a-z][^>]*>/i,he=/<(img|svg|canvas|video|picture|iframe|input|textarea|select|button)\b/i,F="title|text|label|content|description|heading|subtitle|placeholder|body|caption|name",ye=new RegExp(`["']?\\b(?:${F})["']?\\s*:\\s*["']([^"'\\n]*)["']`,"gi"),Se=new RegExp(`^\\s*-?\\s*(?:${F})\\s*:\\s*([^\\s"'{\\[][^\\n]*)$`,"gim"),Ee=/["']?\btype["']?\s*:/gi,xe=2;function M(e){return(e.match(/[\p{L}\p{N}]/gu)??[]).length}function C(e){if(!e.trim())return!0;if(fe.test(e)){if(he.test(e))return!1;let s=e.replace(/<(script|style)\b[\s\S]*?<\/\1>/gi," ").replace(/<!--[\s\S]*?-->/g," ").replace(/<[^>]*>/g," ");return M(s)<T}if((e.match(Ee)?.length??0)>=xe)return!1;let r=0;for(let s of[ye,Se])for(let o of e.matchAll(s))r+=M(o[1]??"");return r<T}function N(e){let t=e.text??e.html??"",r=e.html??e.text??"",s=new Set(e.exempt??[]),o=[],i=(a,d)=>{for(let c of a){let u=le(c.category);if(u==="advisory"&&s.has(c.id))continue;let g=c.detect(d);if(g>0)o.push({ruleId:c.id,category:c.category,severity:c.severity,level:u,message:c.message,count:g})}};i(me,t),i(pe,r);let n=1;for(let a of o){let d=Math.min(Q[a.severity]*(1+(a.count-1)/3),Q[a.severity]*2);n-=d}return n=Math.max(0,Math.min(1,n)),{score:n,grade:ve(n),findings:o,blocked:o.some((a)=>a.level==="blocking")}}function P(e){return N(e).score}function Re(){let e=async(t)=>P({text:t,html:t});return e.evaluate=async(t,r)=>{let s=f(t,r);return!C(t)?{status:"scored",method:"rule-scan",subjectHash:s,score:P({text:t,html:t})}:{status:"unavailable",method:"unassessed",subjectHash:s,reason:"empty-input"}},e}export{A as AutoPromoter,p as EvalRunner,x as EvalRunnerWithExecution,L as ShadowRunner,N as analyzeDesignQuality,Re as createDesignQualityVisualScoreProvider,ie as createEvaluateCandidate,C as isEmptyDesignShell,E as isVisualScore,R as scoreCandidate,_ as scoreCandidateDelta,oe as scoreCandidateSync,P as scoreDesignQuality,f as visualSubjectHash};
2
+ import{createHash as H}from"crypto";function f(e,t){return H("sha256").update(JSON.stringify([e,t])).digest("hex")}function E(e){return typeof e==="number"&&Number.isFinite(e)&&e>=0&&e<=1}var W=new Set(["rule-scan","structural-heuristic","model-text","model-screenshot","legacy-provider","unassessed"]),U=new Set(["empty-input","invalid-score","provider-failed","provider-not-run","invalid-evidence","screenshot-unavailable","timeout"]);async function D(e,t,r){let n=f(t,r),o=(i)=>({status:"unavailable",method:"unassessed",subjectHash:n,reason:i});if(!t.trim())return o("empty-input");try{if(e.evaluate){let s=await e.evaluate(t,r);if(!s||s.subjectHash!==n||!W.has(s.method))return o("invalid-evidence");if(s.status==="scored"&&s.method!=="unassessed"&&E(s.score))return{status:"scored",method:s.method,subjectHash:n,score:s.score};if(s.status==="unavailable"&&s.score===void 0&&U.has(s.reason))return{status:"unavailable",method:s.method,subjectHash:n,reason:s.reason};return o("invalid-evidence")}let i=await e(t,r);return E(i)?{status:"scored",method:"legacy-provider",subjectHash:n,score:i}:o("invalid-score")}catch{return o("provider-failed")}}function g(e){let t=e.visualEvidence;return t!==void 0&&(t.status!=="scored"||!E(t.score)||t.method==="unassessed")}var q=[{label:"_js operator",re:/_js\s*:/g},{label:"_secret operator",re:/_secret\s*:/g},{label:"external URL",re:/https?:\/\/[^\s'"]+/g}];function z(e,t){let r=[];for(let{label:n,re:o}of q){let i=(e.match(o)??[]).length,s=(t.match(o)??[]).length;if(s>i)r.push(`New ${n} introduced (${i} \u2192 ${s})`)}return r}var y={layout:["PageLayout","Card","Box","Tabs","Drawer","Modal"],nav:["PageSiderMenu","Breadcrumb","MenuLink","Link"],data:["Table","List","Stat"],form:["Form","Form.Input","Form.Select","Form.TextArea","Form.Checkbox"],feedback:["Toast","Dialog","Skeleton"],content:["Heading","Paragraph","Markdown","Divider"],action:["Button"]},J=["Form.Submit","Button"];function K(e){let t=Object.values(y).filter((d)=>d.some((B)=>e.includes(B))).length,r=Object.keys(y).length,n=Math.min(1,t/(r*0.7)),o=e.split(`
3
+ `).filter((d)=>d.trim().length>0).map((d)=>d.match(/^(\s*)/)?.[1]?.length??0),i=o.length>0?Math.max(...o):0,s=Math.min(1,i/12),a=y.form.some((d)=>e.includes(d)),l=J.some((d)=>e.includes(d)),c=!a?1:l?1:0.4,u=[...y.layout,...y.data].some((d)=>e.includes(d)),p=[...y.content,...y.action].some((d)=>e.includes(d)),S=u&&p?1:u||p?0.6:0.2;return n*0.35+s*0.15+c*0.2+S*0.3}function I(e){let t=/```ya?ml[\s\S]*?```/i.test(e),r=/\bpage\s*:/i.test(e),n=/\bblocks\s*:/i.test(e);if(t)return 1;if(r&&n)return 0.9;if(r||n)return 0.5;return 0}function O(e,t,r){return e*0.4+t*0.35+r*0.25}class m{visualScoreProvider;constructor(e={}){this.visualScoreProvider=e.visualScoreProvider??void 0}async run(e,t){let r=I(t),n=e.expectedBlocks.filter((a)=>t.toLowerCase().includes(a.toLowerCase())),o=e.expectedBlocks.length===0?1:n.length/e.expectedBlocks.length,i=this.visualScoreProvider?await D(this.visualScoreProvider,t,e.intent):this.structuralEvidence(t,e.intent),s=i.status==="scored"?i.score:0;return{renderable:r,schemaValid:o,visualHeuristic:s,visualEvidence:i,overallScore:O(r,o,s),safetyOk:!0,...e.executionChecks?.length?{requestedExecutionChecks:e.executionChecks.length}:{}}}runSync(e,t){let r=I(t),n=e.expectedBlocks.filter((a)=>t.toLowerCase().includes(a.toLowerCase())),o=e.expectedBlocks.length===0?1:n.length/e.expectedBlocks.length,i=this.visualScoreProvider?{status:"unavailable",method:"unassessed",subjectHash:f(t,e.intent),reason:"provider-not-run"}:this.structuralEvidence(t,e.intent),s=i.status==="scored"?i.score:0;return{renderable:r,schemaValid:o,visualHeuristic:s,visualEvidence:i,overallScore:O(r,o,s),safetyOk:!0,...e.executionChecks?.length?{requestedExecutionChecks:e.executionChecks.length}:{}}}structuralEvidence(e,t){let r=f(e,t);return e.trim()?{status:"scored",method:"structural-heuristic",subjectHash:r,score:K(e)}:{status:"unavailable",method:"unassessed",subjectHash:r,reason:"empty-input"}}checkSafetyRegressions(e,t){return z(e,t)}}var G=0.3;function Y(e){return Math.max(0,Math.min(1,e))}function X(e,t){return Bun.deepEquals(e,t)}function Z(e,t){if(!t.success)return{passed:!1,failureReason:t.errorMessage??t.errorCode??"execution failed"};for(let r of e.expectedStdoutIncludes??[])if(!t.stdout.includes(r))return{passed:!1,failureReason:`stdout missing expected text: ${r}`};for(let r of e.expectedStderrIncludes??[])if(!t.stderr.includes(r))return{passed:!1,failureReason:`stderr missing expected text: ${r}`};if(Object.hasOwn(e,"expectedReturnValue")&&!X(t.returnValue,e.expectedReturnValue))return{passed:!1,failureReason:"returnValue did not match expected value"};return{passed:!0}}function ee(e,t){return{passed:t.passed,success:e.success,stdout:e.stdout,stderr:e.stderr,durationMs:e.durationMs,...e.errorCode?{errorCode:e.errorCode}:{},...e.errorMessage?{errorMessage:e.errorMessage}:{},...t.failureReason?{failureReason:t.failureReason}:{}}}function te(){return{passed:!1,success:!1,stdout:"",stderr:"",durationMs:0,errorCode:"runtime-not-configured",errorMessage:"ExecutionRuntime is not configured",failureReason:"runtime not configured"}}function re(e){let t=e instanceof Error?e.message:String(e);return{passed:!1,success:!1,stdout:"",stderr:"",durationMs:0,errorCode:"internal-error",errorMessage:t,failureReason:t}}var ne=/\{\{skillBody\}\}(?!Json)/,V="{{skillBodyJson}}";function se(e,t,r){if(ne.test(e))throw Error("EvalExecutionCheck.code contains unsafe `{{skillBody}}` placeholder. "+"Use `{{skillBodyJson}}` (JSON-encoded) instead \u2014 raw substitution lets "+"a malicious candidate body escape the eval template.");if(r==="shell"&&e.includes(V))throw Error('EvalExecutionCheck.code uses `{{skillBodyJson}}` in a shell check, but JSON encoding does not neutralize bash command substitution. Pass the skill body via `check.env` (e.g. SKILL_BODY) and read it inside the shell script with `"$SKILL_BODY"` instead.');return e.replaceAll(V,JSON.stringify(t))}function oe(e,t){return{language:e.language,code:se(e.code,t,e.language),...e.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},fetchAllowed:e.fetchAllowed===!0,...e.env?{env:e.env}:{}}}class R{staticRunner;executionRuntime;executionWeight;constructor(e={}){this.staticRunner=new m(e.visualScoreProvider!==void 0?{visualScoreProvider:e.visualScoreProvider}:{}),this.executionRuntime=e.executionRuntime,this.executionWeight=Y(e.executionWeight??G)}async run(e,t){let r=await this.staticRunner.run(e,t),n=e.executionChecks??[];if(n.length===0)return r;let o=[];for(let s of n){if(!this.executionRuntime){o.push(te());continue}try{let a=await this.executionRuntime.run(oe(s,t));o.push(ee(a,Z(s,a)))}catch(a){o.push(re(a))}}let i=o.length===0?void 0:o.filter((s)=>s.passed).length/o.length;if(i===void 0)return r;return{...r,executionScore:i,executionResults:o,overallScore:r.overallScore*(1-this.executionWeight)+i*this.executionWeight}}checkSafetyRegressions(e,t){return this.staticRunner.checkSafetyRegressions(e,t)}}function h(e,t){let r=t??e.requestedExecutionChecks??e.executionResults?.length??0;if(!Number.isSafeInteger(r)||r<0)return!0;let n=e.executionResults;if(r===0)return(n?.length??0)>0;return!n||n.length!==r||n.some((o)=>o.success!==!0||o.passed!==!0)}function _(e={}){if(e.runner)return e.runner;return new m(e.visualScoreProvider!==void 0?{visualScoreProvider:e.visualScoreProvider}:{})}async function b(e,t,r={}){let n=await _(r).run(e,t);return e.executionChecks?.length?{...n,requestedExecutionChecks:e.executionChecks.length}:n}function ie(e,t,r={}){return new m(r.visualScoreProvider!==void 0?{visualScoreProvider:r.visualScoreProvider}:{}).runSync(e,t)}async function L(e,t,r,n={}){let o=_(n),[i,s]=await Promise.all([o.run(e,t),o.run(e,r)]);if(g(i)||g(s))throw Error("visual-evaluation-unavailable");if(h(s,e.executionChecks?.length))throw Error("execution-checks-unmet");return s.overallScore-i.overallScore}function ae(e={}){let t=e.makeCase??((r)=>({id:`cand-${r.candidateIndex}`,intent:"tournament",expectedBlocks:[],skillId:r.skillId}));return async(r)=>{let n=t(r);if(!n)return 0;return L(n,r.currentBody,r.candidateBody,e)}}class A{runner;hasExecutionRuntime;staticRunner;constructor(e={}){this.staticRunner=new m(e),this.hasExecutionRuntime=e.executionRuntime!==void 0,this.runner=e.executionRuntime?new R({executionRuntime:e.executionRuntime,...e.visualScoreProvider!==void 0?{visualScoreProvider:e.visualScoreProvider}:{},...e.executionWeight!==void 0?{executionWeight:e.executionWeight}:{}}):new m(e.visualScoreProvider!==void 0?{visualScoreProvider:e.visualScoreProvider}:{})}async compare(e,t,r,n,o){let i=this.runner.checkSafetyRegressions(r,n),s=await Promise.all(o.map(async(c)=>{let u=await b(c,r,{runner:this.runner}),p=await b(c,n,{runner:this.runner}),S=p.overallScore-u.overallScore;return{caseId:c.id,parentScore:u,proposedScore:p,deltaScore:S,safetyRegression:i}})),a=s.length===0?0:s.reduce((c,u)=>c+u.deltaScore,0)/s.length,l=a>=0.05&&i.length===0&&!s.some((c)=>g(c.parentScore)||g(c.proposedScore)||h(c.proposedScore))?"promoted":i.length>0?"rejected":"pending";return{skillId:e,proposalId:t,cases:s,meanDeltaScore:a,safetyRegressions:i,decision:l}}compareSync(e,t,r,n,o){if(this.hasExecutionRuntime)console.warn("[ShadowRunner] compareSync() ignores the injected executionRuntime; use compare() (async) to fold execution checks into the score.");let i=this.runner.checkSafetyRegressions(r,n),s=o.map((c)=>{let u=this.staticRunner,p=u.runSync(c,r),S=u.runSync(c,n),d=S.overallScore-p.overallScore;return{caseId:c.id,parentScore:p,proposedScore:S,deltaScore:d,safetyRegression:i}}),a=s.length===0?0:s.reduce((c,u)=>c+u.deltaScore,0)/s.length,l=a>=0.05&&i.length===0&&!s.some((c)=>g(c.parentScore)||g(c.proposedScore)||h(c.proposedScore))?"promoted":i.length>0?"rejected":"pending";return{skillId:e,proposalId:t,cases:s,meanDeltaScore:a,safetyRegressions:i,decision:l}}}import{existsSync as ce,mkdirSync as C,readFileSync as ue,writeFileSync as k}from"fs";import{join as x}from"path";function le(e){let t=e.split(".").map(Number);if(t.length!==3||t.some(Number.isNaN))return`${e}-promoted`;return`${t[0]}.${t[1]}.${(t[2]??0)+1}`}class Q{options;constructor(e){this.options=e}async tryPromote(e,t){if(e.decision!=="promoted")return this.writeDecision(e,e.decision,"unknown","unknown"),e.decision;if(e.cases.some((r)=>g(r.parentScore)||g(r.proposedScore)||h(r.proposedScore)))return this.writeDecision(e,"pending","unknown","unknown"),"pending";if(this.options.regressionCheck){let r;try{r=await this.options.regressionCheck(t)}catch(n){console.warn(`[auto-promoter] regression check threw; conservative reject: ${n instanceof Error?n.message:String(n)}`),r={passed:!1,failures:["__error__"],checkedCaseIds:[]}}if(!r.passed)return this.writeDecision(e,"rejected-regression","unknown","unknown",r),"rejected-regression";return this.performPromote(e,t,r)}return this.performPromote(e,t)}performPromote(e,t,r){let n=x(this.options.rootDir,".uibot","skills",e.skillId),o=x(n,"SKILL.md");if(!ce(o))return C(n,{recursive:!0}),k(o,t,"utf-8"),this.writeDecision(e,"promoted","0.0.0","1.0.0",r),"promoted";let i=ue(o,"utf-8"),s=i.match(/^version:\s*["']?([^"'\n]+)["']?\s*$/m),a=s?(s[1]??"1.0.0").trim():"1.0.0",l=le(a),c=x(n,"versions",a);C(c,{recursive:!0}),k(x(c,"SKILL.md"),i,"utf-8");let u=t.replace(/^(version:\s*["']?)([^"'\n]+)(["']?\s*)$/m,`$1${l}$3`);return k(o,u,"utf-8"),this.writeDecision(e,"promoted",a,l,r),"promoted"}writeDecision(e,t,r,n,o){let i=x(this.options.rootDir,".uibot","skills",e.skillId);C(i,{recursive:!0});let s={skillId:e.skillId,proposalId:e.proposalId,fromVersion:r,toVersion:n,decision:t,meanDeltaScore:e.meanDeltaScore,safetyRegressions:e.safetyRegressions,caseCount:e.cases.length,timestamp:new Date().toISOString(),visualEvidence:e.cases.map((a)=>({caseId:a.caseId,...a.parentScore.visualEvidence?{parent:a.parentScore.visualEvidence}:{},...a.proposedScore.visualEvidence?{proposed:a.proposedScore.visualEvidence}:{}})),executionChecks:e.cases.filter((a)=>a.proposedScore.requestedExecutionChecks||a.proposedScore.executionResults?.length).map((a)=>({caseId:a.caseId,requested:a.proposedScore.requestedExecutionChecks??a.proposedScore.executionResults?.length??0,reported:a.proposedScore.executionResults?.length??0,passed:a.proposedScore.executionResults?.filter((l)=>l.success&&l.passed).length??0,status:h(a.proposedScore)?"unmet":"passed"})),...o?{regressionChecked:o.checkedCaseIds,...o.failures.length>0?{regressionFailures:o.failures}:{}}:{}};k(x(i,"decision.json"),`${JSON.stringify(s,null,2)}
4
+ `,"utf-8")}}function de(e){return e==="quality"?"blocking":"advisory"}var pe=["streamline your","empower your","supercharge your","unlock the power","best-in-class","enterprise-grade","next-generation","cutting-edge","revolutionize","game-changer","game changer","future-proof","seamless experience","drive growth","harness the power","take it to the next level","world-class","state-of-the-art","robust solution","powerful platform","effortlessly","seamlessly integrate","elevate your","transform your"],ge=["Inter","Roboto","Geist","Fraunces","Plus Jakarta","Space Grotesk"];function v(e,t){let r=e.match(t);return r?r.length:0}var me=[{id:"marketing-buzzword",category:"slop",severity:"P2",message:"Marketing buzzwords read as AI filler \u2014 prefer concrete, specific copy.",detect:(e)=>{let t=e.toLowerCase();return pe.reduce((r,n)=>r+(t.includes(n)?1:0),0)}},{id:"em-dash-overuse",category:"slop",severity:"P3",message:"Em-dash overuse (\u22655) is a strong AI-writing tell.",detect:(e)=>{let t=v(e,/[\u2014]|--(?=\S)/g);return t>=5?t-4:0}},{id:"aphoristic-cadence",category:"slop",severity:"P2",message:'Manufactured-contrast cadence ("Not an X. Just Y.") is a recognizable AI pattern.',detect:(e)=>{let t=v(e,/\bNot\s+(?:an?|just)\b[^.?!]*[.?!]/gi),r=v(e,/\b[A-Z][^.?!]*\.\s+(?:No|Just)\s+[a-z]/g),n=t+r;return n>=3?n:0}},{id:"numbered-section-markers",category:"slop",severity:"P3",message:"Numbered section scaffolding (01 / 02 / 03) is an overused AI layout tell.",detect:(e)=>{let t=e.match(/\b(0[1-9]|1[0-2])\b/g)??[],r=new Set(t);if(r.size<3)return 0;let n=[...r].map(Number).sort((i,s)=>i-s);return n.some((i,s)=>s>0&&i-n[s-1]===1)?r.size:0}}],ve=[{id:"gradient-text",category:"slop",severity:"P2",message:"Gradient text (bg-clip-text + transparent) is a classic AI hero tell.",detect:(e)=>v(e,/bg-clip-text[^"']*text-transparent|text-transparent[^"']*bg-clip-text|-webkit-background-clip\s*:\s*text/gi)},{id:"ai-color-palette",category:"slop",severity:"P2",message:"Purple/violet gradient palette is the most recognizable AI color tell.",detect:(e)=>v(e,/(from|via|to)-(purple|violet|fuchsia|indigo)-\d{3}|linear-gradient\([^)]*(?:#(?:8b5cf6|a855f7|7c3aed|6366f1))/gi)},{id:"side-tab",category:"slop",severity:"P2",message:"Thick colored side-border on a card (border-l-4 + accent) is the single most recognizable AI card tell.",detect:(e)=>v(e,/border-l-(4|8)\s+border-(purple|violet|indigo|blue|primary)/gi)},{id:"overused-font",category:"slop",severity:"P3",message:"Over-represented font (Inter/Geist/\u2026) without a brand reason reads as default AI styling.",detect:(e)=>ge.reduce((t,r)=>t+(new RegExp(`font-family[^;"']*${r}`,"i").test(e)?1:0),0)},{id:"emoji-icon",category:"slop",severity:"P2",message:"Emoji used as a heading/list/button icon is a stock AI tell \u2014 use a real icon or nothing.",detect:(e)=>v(e,/<(?:h[1-6]|li|button|summary|th)\b[^>]*>\s*(?:<[^>]+>\s*)*\p{Extended_Pictographic}/giu)},{id:"github-dark-glow",category:"slop",severity:"P3",message:"Flat #0D1117 background with a neon cyan/violet glow is the default AI dark-mode look.",detect:(e)=>/#0d1117/i.test(e)&&/(?:box-shadow|drop-shadow|text-shadow)[^;"']*(?:#06b6d4|#22d3ee|#00f0ff|#a78bfa|#8b5cf6|cyan|violet)/i.test(e)?1:0},{id:"tiny-text",category:"quality",severity:"P1",message:"Body text below ~14px (text-[10px]/[11px]/[12px]) harms readability and accessibility.",detect:(e)=>v(e,/text-\[(?:8|9|10|11|12)px\]|font-size\s*:\s*(?:8|9|10|11|12)px/gi)},{id:"gray-on-color",category:"quality",severity:"P1",message:"Gray text on a colored fill commonly fails WCAG contrast.",detect:(e)=>v(e,/bg-(?:primary|blue|indigo|violet|purple)-\d{3}[^"']*text-(?:gray|slate|zinc|neutral)-\d{3}/gi)}],T={P0:0.3,P1:0.15,P2:0.08,P3:0.04};function he(e){if(e>=0.9)return"A";if(e>=0.8)return"B";if(e>=0.65)return"C";if(e>=0.5)return"D";return"F"}var M=8,fe=/<\/?[a-z][^>]*>/i,ye=/<(img|svg|canvas|video|picture|iframe|input|textarea|select|button)\b/i,N="title|text|label|content|description|heading|subtitle|placeholder|body|caption|name",Se=new RegExp(`["']?\\b(?:${N})["']?\\s*:\\s*["']([^"'\\n]*)["']`,"gi"),xe=new RegExp(`^\\s*-?\\s*(?:${N})\\s*:\\s*([^\\s"'{\\[][^\\n]*)$`,"gim"),Ee=/["']?\btype["']?\s*:/gi,Re=2;function F(e){return(e.match(/[\p{L}\p{N}]/gu)??[]).length}function w(e){if(!e.trim())return!0;if(fe.test(e)){if(ye.test(e))return!1;let n=e.replace(/<(script|style)\b[\s\S]*?<\/\1>/gi," ").replace(/<!--[\s\S]*?-->/g," ").replace(/<[^>]*>/g," ");return F(n)<M}if((e.match(Ee)?.length??0)>=Re)return!1;let r=0;for(let n of[Se,xe])for(let o of e.matchAll(n))r+=F(o[1]??"");return r<M}function j(e){let t=e.text??e.html??"",r=e.html??e.text??"",n=new Set(e.exempt??[]),o=[],i=(a,l)=>{for(let c of a){let u=de(c.category);if(u==="advisory"&&n.has(c.id))continue;let p=c.detect(l);if(p>0)o.push({ruleId:c.id,category:c.category,severity:c.severity,level:u,message:c.message,count:p})}};i(me,t),i(ve,r);let s=1;for(let a of o){let l=Math.min(T[a.severity]*(1+(a.count-1)/3),T[a.severity]*2);s-=l}return s=Math.max(0,Math.min(1,s)),{score:s,grade:he(s),findings:o,blocked:o.some((a)=>a.level==="blocking")}}function P(e){return j(e).score}function be(){let e=async(t)=>P({text:t,html:t});return e.evaluate=async(t,r)=>{let n=f(t,r);return!w(t)?{status:"scored",method:"rule-scan",subjectHash:n,score:P({text:t,html:t})}:{status:"unavailable",method:"unassessed",subjectHash:n,reason:"empty-input"}},e}export{Q as AutoPromoter,m as EvalRunner,R as EvalRunnerWithExecution,A as ShadowRunner,j as analyzeDesignQuality,be as createDesignQualityVisualScoreProvider,ae as createEvaluateCandidate,w as isEmptyDesignShell,E as isVisualScore,b as scoreCandidate,L as scoreCandidateDelta,ie as scoreCandidateSync,P as scoreDesignQuality,f as visualSubjectHash};
@@ -26,7 +26,8 @@ export declare class ShadowRunner {
26
26
  * Compare `parentBody` vs `proposedBody` across all provided cases.
27
27
  * Returns a ShadowEvalResult with mean delta score and safety regression list.
28
28
  *
29
- * Promotion requires delta >= +0.05, no safety regressions, and no unavailable visual assessment.
29
+ * Promotion also requires every declared candidate execution check to pass.
30
+ * A failing parent can still be repaired by a passing candidate.
30
31
  */
31
32
  compare(skillId: string, proposalId: string, parentBody: string, proposedBody: string, cases: EvalCase[]): Promise<ShadowEvalResult>;
32
33
  /**
package/dist/types.d.ts CHANGED
@@ -62,9 +62,11 @@ export interface EvalScore {
62
62
  overallScore: number;
63
63
  /** True when no new `_js`, `_secret`, or external URLs appeared in the diff */
64
64
  safetyOk: boolean;
65
- /** Optional execution-backed score in [0, 1], present only when execution checks ran. */
65
+ /** Declared check count, retained even when this runner cannot execute them. */
66
+ requestedExecutionChecks?: number;
67
+ /** Optional execution-backed score in [0, 1]; missing runtime projects to zero. */
66
68
  executionScore?: number;
67
- /** Per-check execution results, present only when execution checks ran. */
69
+ /** Per-check outcomes, including structured missing-runtime failures. */
68
70
  executionResults?: EvalExecutionResult[];
69
71
  }
70
72
  /** Callable compatibility interface; runners prefer evidence-aware evaluate when supplied. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uibot/evaluation",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@uibot/contracts": "^0.20.0"
34
+ "@uibot/contracts": "^0.22.0"
35
35
  },
36
36
  "scripts": {
37
37
  "build": "rm -rf dist && bun build --minify ./src/index.ts ./src/design-quality-rules.ts --outdir ./dist --format esm --target bun && bun x tsc -p tsconfig.json",