@rulemetric/cli 0.7.34 → 0.7.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/{chunk-JGYCLDYF.js → chunk-2ZAKZEXW.js} +1 -1
  2. package/dist/{chunk-BMGQFKG6.js → chunk-42XJZBQD.js} +1 -1
  3. package/dist/chunk-47YDQYTD.js +14 -0
  4. package/dist/{chunk-7AZKPX2J.js → chunk-4L2ZEIRE.js} +1 -1
  5. package/dist/chunk-6NML7IVJ.js +1 -0
  6. package/dist/{chunk-MODFTCZY.js → chunk-B3BHB26P.js} +1 -1
  7. package/dist/chunk-BL4BN6RU.js +1 -0
  8. package/dist/{chunk-UR6GZGFK.js → chunk-BPQ66YTY.js} +1 -1
  9. package/dist/{chunk-W2MOTOQE.js → chunk-BUWWFHGO.js} +1 -1
  10. package/dist/{chunk-OVZZUI33.js → chunk-C5PSIJ7S.js} +1 -1
  11. package/dist/{chunk-3VYV6ZYB.js → chunk-CNOD6HWU.js} +1 -1
  12. package/dist/{chunk-DAGDGAPU.js → chunk-CRIFP3QP.js} +1 -1
  13. package/dist/chunk-DKGKOSW3.js +1 -0
  14. package/dist/chunk-G5BXZT6F.js +1 -0
  15. package/dist/{chunk-LEXVC7VH.js → chunk-H7J27U4P.js} +1 -1
  16. package/dist/{chunk-AIEM6VXO.js → chunk-HUADECKZ.js} +1 -1
  17. package/dist/{chunk-3FJT6LL4.js → chunk-IQTSUAGM.js} +1 -1
  18. package/dist/{chunk-E3MQVVH6.js → chunk-IXLDCX7M.js} +1 -1
  19. package/dist/chunk-JGLVVIEM.js +1 -0
  20. package/dist/{chunk-WEF5LPGS.js → chunk-JIJKIPE6.js} +1 -1
  21. package/dist/{chunk-BSJBNOJT.js → chunk-KQCAELPN.js} +1 -1
  22. package/dist/{chunk-6QKI756T.js → chunk-MDPN46EY.js} +1 -1
  23. package/dist/{chunk-QH7PCQHM.js → chunk-MQ47NLPC.js} +1 -1
  24. package/dist/{chunk-ZAWAPLIE.js → chunk-NKPLTT7J.js} +1 -1
  25. package/dist/{chunk-OPUI7CM2.js → chunk-NTKO4H2K.js} +1 -1
  26. package/dist/{chunk-ZWKKFAIX.js → chunk-Q4APAZUC.js} +1 -1
  27. package/dist/chunk-QWCEZEDO.js +4 -0
  28. package/dist/{chunk-ZERPMWRT.js → chunk-RMDLJN4L.js} +1 -1
  29. package/dist/chunk-RUZ36O55.js +2 -0
  30. package/dist/{chunk-5W55CRBJ.js → chunk-SWSGNEVO.js} +1 -1
  31. package/dist/{chunk-BZUIMHHT.js → chunk-TVHT6H42.js} +1 -1
  32. package/dist/{chunk-LETTPEG4.js → chunk-VSUL3MNG.js} +1 -1
  33. package/dist/chunk-VTA6HDVW.js +11 -0
  34. package/dist/{chunk-OZQV5CDT.js → chunk-X64R6JCJ.js} +1 -1
  35. package/dist/{chunk-G6XGDHGC.js → chunk-XA4KSQEC.js} +1 -1
  36. package/dist/{chunk-V5MJ4ICC.js → chunk-XRTZU7IZ.js} +1 -1
  37. package/dist/chunk-ZYI66XKV.js +1 -0
  38. package/dist/{chunk-JEBHSV2M.js → chunk-ZYVWALMS.js} +1 -1
  39. package/dist/commands/capture/scope.js +2 -0
  40. package/dist/commands/diagnostics.js +1 -1
  41. package/dist/commands/evals/agent.js +1 -1
  42. package/dist/commands/evals/auto-run.js +1 -1
  43. package/dist/commands/evals/benchmark.js +1 -1
  44. package/dist/commands/evals/optimize.js +1 -1
  45. package/dist/commands/evals/refine-cases.js +1 -1
  46. package/dist/commands/evals/run.js +1 -1
  47. package/dist/commands/evals/validate-judge.js +1 -1
  48. package/dist/commands/gateway/ensure.js +1 -1
  49. package/dist/commands/hooks/install.js +1 -1
  50. package/dist/commands/hooks/uninstall.js +2 -2
  51. package/dist/commands/proxy/env.js +1 -1
  52. package/dist/commands/proxy/status.js +1 -1
  53. package/dist/commands/sessions/list.js +1 -1
  54. package/dist/commands/setup.js +1 -1
  55. package/dist/dashboard/Dashboard.js +1 -1
  56. package/dist/dashboard/data.js +1 -1
  57. package/dist/dashboard/launcher/LauncherOverlay.js +1 -1
  58. package/dist/{dist-FAVALJ5C.js → dist-BC6GMBXV.js} +1 -1
  59. package/dist/lib/agent-loop.js +1 -1
  60. package/dist/lib/capture-scope-config.js +1 -0
  61. package/dist/lib/codex-exec.js +1 -1
  62. package/dist/lib/eval-benchmark.js +1 -1
  63. package/dist/lib/eval-candidate-run.js +1 -1
  64. package/dist/lib/eval-case-generator.js +1 -1
  65. package/dist/lib/eval-conversation-handler.js +1 -1
  66. package/dist/lib/eval-grader.js +1 -1
  67. package/dist/lib/eval-run-batch.js +1 -1
  68. package/dist/lib/evolution-cost.js +1 -0
  69. package/dist/lib/gateway-entry.js +1 -1
  70. package/dist/lib/gateway-lifecycle.js +1 -1
  71. package/dist/lib/gateway.js +1 -1
  72. package/dist/lib/handlers/cron-eval-autorun.js +1 -1
  73. package/dist/lib/handlers/cron-instruction-evolution.js +1 -1
  74. package/dist/lib/handlers/cron-refresh-pricing.js +1 -1
  75. package/dist/lib/handlers/cron-suggest-instructions.js +1 -1
  76. package/dist/lib/handlers/distill-memories.js +1 -1
  77. package/dist/lib/handlers/process-announcement.js +1 -1
  78. package/dist/lib/handlers/process-changelog.js +1 -1
  79. package/dist/lib/handlers/process-conversation.js +1 -1
  80. package/dist/lib/handlers/process-eval.js +1 -1
  81. package/dist/lib/handlers/process-insights.js +1 -1
  82. package/dist/lib/handlers/process-judge-review.js +1 -1
  83. package/dist/lib/handlers/process-launch.js +1 -1
  84. package/dist/lib/handlers/process-memory-ab.js +1 -1
  85. package/dist/lib/handlers/process-run-cleanup.js +1 -1
  86. package/dist/lib/handlers/process-session-goal.js +1 -1
  87. package/dist/lib/instruction-proposer.js +1 -1
  88. package/dist/lib/judge-review-runner.js +1 -1
  89. package/dist/lib/llm-client.js +1 -1
  90. package/dist/lib/manual-tasks.js +1 -1
  91. package/dist/lib/optimize-compare.js +1 -1
  92. package/dist/lib/reviewer-detect.js +1 -1
  93. package/dist/lib/setup-steps.js +1 -1
  94. package/dist/lib/worktree.js +1 -1
  95. package/oclif.manifest.json +365 -261
  96. package/package.json +9 -6
  97. package/dist/chunk-3DLVY7LD.js +0 -1
  98. package/dist/chunk-7W6KET2A.js +0 -11
  99. package/dist/chunk-DNF4HDI6.js +0 -14
  100. package/dist/chunk-JR4CWY3J.js +0 -1
  101. package/dist/chunk-L5ORQB25.js +0 -1
  102. package/dist/chunk-MVM6OGAF.js +0 -4
  103. package/dist/chunk-VXIRJ7YY.js +0 -1
  104. package/dist/chunk-WKXTY5AM.js +0 -1
  105. /package/dist/{chunk-7DFNBRLY.js → chunk-5DIOZDDZ.js} +0 -0
@@ -1,4 +1,4 @@
1
- import{a as S,b as z,c as T}from"./chunk-QFVGUZDO.js";import{a as O}from"./chunk-ZL4MZMUK.js";import{a as j}from"./chunk-5RBLIVBF.js";import{c as A,d as C,f as b}from"./chunk-MODFTCZY.js";import{e as _,f as I,h as u}from"./chunk-H2ORWIEY.js";import{a as $}from"./chunk-ZLLER3HP.js";async function D(f,m){let{mirrorId:o,projectPath:s,projectId:i,config:p}=f,e=$(n=>m.logger.info(n),"log");if(p?.sessionId)return M({mirrorId:o,sessionId:p.sessionId},e);e(`Processing insights job ${o}...`),await u(`/api/insights-jobs/${o}/progress`,{status:"running",progress:{step:"reading_data"}});try{let{repaired:n}=await I("/api/sessions/repair-analyzed-at",{});n>0&&e(` Repaired analyzed_at on ${n} orphan session(s).`)}catch(n){e(` Warning: analyzed_at repair failed: ${n instanceof Error?n.message:String(n)}`)}let a=await J(s,i);if(!a)throw new j("No session data found \u2014 ensure sessions are captured and enriched.");e(` Found ${a.stats.sessions} sessions, generating recommendations...`);let w=20,c=200;if(C()!=="none"){let n=0,t=0;try{for(;n<c;){let l=await _(`/api/sessions?hasAnalysis=false&limit=${w}&offset=${t}`);if(l.length===0)break;e(` Generating facets for ${l.length} un-analyzed sessions (drained ${n} so far)...`);for(let g of l){if(n>=c)break;try{let d=await _(`/api/sessions/${g.id}/events?limit=100`);if(d.length<2){n++,t++;continue}let P=d.filter(h=>h.eventType==="user_message"||h.eventType==="human").map(h=>h.content?.slice(0,200)??"").filter(Boolean).join(`
1
+ import{a as S,b as z,c as T}from"./chunk-QFVGUZDO.js";import{a as j}from"./chunk-5RBLIVBF.js";import{a as O}from"./chunk-ZL4MZMUK.js";import{c as A,d as C,f as b}from"./chunk-B3BHB26P.js";import{e as _,f as I,h as u}from"./chunk-H2ORWIEY.js";import{a as $}from"./chunk-ZLLER3HP.js";async function D(f,m){let{mirrorId:o,projectPath:s,projectId:i,config:p}=f,e=$(n=>m.logger.info(n),"log");if(p?.sessionId)return M({mirrorId:o,sessionId:p.sessionId},e);e(`Processing insights job ${o}...`),await u(`/api/insights-jobs/${o}/progress`,{status:"running",progress:{step:"reading_data"}});try{let{repaired:n}=await I("/api/sessions/repair-analyzed-at",{});n>0&&e(` Repaired analyzed_at on ${n} orphan session(s).`)}catch(n){e(` Warning: analyzed_at repair failed: ${n instanceof Error?n.message:String(n)}`)}let a=await J(s,i);if(!a)throw new j("No session data found \u2014 ensure sessions are captured and enriched.");e(` Found ${a.stats.sessions} sessions, generating recommendations...`);let w=20,c=200;if(C()!=="none"){let n=0,t=0;try{for(;n<c;){let l=await _(`/api/sessions?hasAnalysis=false&limit=${w}&offset=${t}`);if(l.length===0)break;e(` Generating facets for ${l.length} un-analyzed sessions (drained ${n} so far)...`);for(let g of l){if(n>=c)break;try{let d=await _(`/api/sessions/${g.id}/events?limit=100`);if(d.length<2){n++,t++;continue}let P=d.filter(h=>h.eventType==="user_message"||h.eventType==="human").map(h=>h.content?.slice(0,200)??"").filter(Boolean).join(`
2
2
  ---
3
3
  `);if(!P){n++,t++;continue}let E=await b(T,P,4096);if(E){let h=d.filter(R=>R.eventType==="user_message"||R.eventType==="human").length;await u(`/api/sessions/${g.id}/enrich`,{analysis:{source:"generated_facets",...E},analyzedEventCount:d.length,analyzedTurnCount:h}),e(` Generated facets for session ${g.id} (${g.tool})`)}else t++;n++}catch(d){e(` Failed to generate facets for session ${g.id}: ${d instanceof Error?d.message:String(d)}`),n++,t++}}if(l.length<w)break}}catch(l){e(` Warning: facet generation failed after ${n} sessions: ${l instanceof Error?l.message:String(l)}`)}}let r={},y=S.length+1;for(let n=0;n<S.length;n++){let t=S[n];e(` [${n+1}/${y}] Generating ${t.name}...`);try{await u(`/api/insights-jobs/${o}/progress`,{status:"running",progress:{step:t.name,current:n+1,total:y,partial:{...r}}})}catch(g){e(` Warning: progress update failed for ${t.name}: ${g instanceof Error?g.message:String(g)}`)}e(` Running LLM prompt for ${t.name}...`);let l=await b(t.prompt,a.summary,t.maxTokens);l?(r[t.name]=l,e(` Got result for ${t.name}`)):e(` No result for ${t.name} (LLM returned null)`)}e(` [${y}/${y}] Generating at_a_glance...`),await u(`/api/insights-jobs/${o}/progress`,{status:"running",progress:{step:"at_a_glance",current:y,total:y,partial:{...r}}});let N=[a.summary,r.what_works?`
4
4
  ## What Works
@@ -1 +1 @@
1
- import{a as $}from"./chunk-WKXTY5AM.js";import{e as w,f as k}from"./chunk-H2ORWIEY.js";import{a as u}from"./chunk-ZLLER3HP.js";function h(e){if(e.length===0)return{mean:0,stddev:0,min:0,max:0};let n=e.reduce((s,a)=>s+a,0)/e.length,o=e.reduce((s,a)=>s+(a-n)**2,0)/e.length;return{mean:Math.round(n*1e3)/1e3,stddev:Math.round(Math.sqrt(o)*1e3)/1e3,min:Math.min(...e),max:Math.max(...e)}}u(h,"computeStats");var x="with_target",E="without_target";function _(e){let n=e.grading.summary?.pass_rate;return typeof n=="number"&&n>=1}u(_,"fullPass");function b(e){return e.grading.summary?.pass_rate!=null}u(b,"hasGrading");function R(e){let n=e.timing.total_tokens;return typeof n=="number"&&n>0?n:void 0}u(R,"tokensOf");function v(e){let n=e.timing.duration_ms;return typeof n=="number"&&!isNaN(n)?n/1e3:void 0}u(v,"secondsOf");function y(e,n){let o={};for(let s of e)(o[n(s)]??=[]).push(s);return o}u(y,"groupBy");function C(e,n){let o=y(e.filter(b),i=>i.evalId),s=y(n.filter(b),i=>i.evalId),a=u((i,l)=>i.runNumber-l.runNumber,"byRun"),t=[];for(let i of Object.keys(o)){let l=o[i].sort(a),d=(s[i]??[]).sort(a);for(let r=0;r<Math.min(l.length,d.length);r++){let c={withScore:_(l[r])?1:0,withoutScore:_(d[r])?1:0},f=R(l[r]),g=R(d[r]);f!=null&&g!=null&&(c.withCost=f,c.withoutCost=g);let p=v(l[r]),m=v(d[r]);p!=null&&m!=null&&(c.withLatency=p,c.withoutLatency=m),t.push(c)}}return t}u(C,"pairRunsByEval");function T(e){let n=e.filter(r=>r.status==="completed");if(n.length===0)return{runSummary:{},verdict:null,notes:["No completed runs found"],totalRuns:0};let o=y(n,r=>r.configuration),s={},a=[];for(let[r,c]of Object.entries(o)){let f=c.filter(b).map(m=>m.grading.summary.pass_rate),g=c.map(v).filter(m=>m!=null),p=c.map(R).filter(m=>m!=null);s[r]={},f.length>0&&(s[r].pass_rate=h(f)),g.length>0&&(s[r].time_seconds=h(g)),p.length>0&&(s[r].tokens=h(p))}let t=null,i=o[x]??[],l=o[E]??[],d=C(i,l);if(d.length>0){if(t=$(d),!t.sufficient)a.push(t.insufficientReason??"Insufficient data for a significance verdict.");else if(t.significant){let r=t.delta>=0?"improves":"reduces",c=t.pValue!=null?`, McNemar p=${t.pValue.toFixed(4)}`:"";a.push(`Target ${r} the pass rate by ${Math.abs(t.delta*100).toFixed(0)}% (95% CI ${(t.ci.lower*100).toFixed(0)}\u2013${(t.ci.upper*100).toFixed(0)}%, n=${t.nWith}${c}).`)}else a.push(`No significant effect on pass rate (95% CI ${(t.ci.lower*100).toFixed(0)}\u2013${(t.ci.upper*100).toFixed(0)}%, n=${t.nWith}).`);t.costDelta!=null&&Math.round(t.costDelta)!==0&&a.push(`Token cost delta: ${t.costDelta>=0?"+":""}${Math.round(t.costDelta)} tokens/task.`),t.latencyDelta!=null&&Math.abs(t.latencyDelta)>1&&a.push(`Target ${t.latencyDelta>0?"adds":"saves"} ${Math.abs(t.latencyDelta).toFixed(1)}s/task.`)}for(let r of Object.values(s))if(r.pass_rate&&r.pass_rate.stddev>.2){a.push(`High pass-rate variance (stddev=${r.pass_rate.stddev.toFixed(2)}) \u2014 results may be unreliable.`);break}return{runSummary:s,verdict:t,notes:a,totalRuns:n.length}}u(T,"summarizeRuns");async function S(e,n){let o=n?`&iteration=${n}`:"",s=100,a=[];for(let t=0;t<1e5;t+=s){let i=await w(`/api/eval-targets/${e}/runs?limit=${s}&offset=${t}&activeCasesOnly=1${o}`);if(a.push(...i),i.length<s)break}return T(a)}u(S,"aggregateBenchmark");async function B(e,n,o){return k(`/api/eval-targets/${e}/benchmarks`,{iteration:n,runSummary:o.runSummary,notes:o.notes})}u(B,"postBenchmark");export{T as a,S as b,B as c};
1
+ import{b as $}from"./chunk-G5BXZT6F.js";import{e as w,f as k}from"./chunk-H2ORWIEY.js";import{a as u}from"./chunk-ZLLER3HP.js";function h(e){if(e.length===0)return{mean:0,stddev:0,min:0,max:0};let n=e.reduce((s,a)=>s+a,0)/e.length,o=e.reduce((s,a)=>s+(a-n)**2,0)/e.length;return{mean:Math.round(n*1e3)/1e3,stddev:Math.round(Math.sqrt(o)*1e3)/1e3,min:Math.min(...e),max:Math.max(...e)}}u(h,"computeStats");var x="with_target",E="without_target";function _(e){let n=e.grading.summary?.pass_rate;return typeof n=="number"&&n>=1}u(_,"fullPass");function b(e){return e.grading.summary?.pass_rate!=null}u(b,"hasGrading");function R(e){let n=e.timing.total_tokens;return typeof n=="number"&&n>0?n:void 0}u(R,"tokensOf");function v(e){let n=e.timing.duration_ms;return typeof n=="number"&&!isNaN(n)?n/1e3:void 0}u(v,"secondsOf");function y(e,n){let o={};for(let s of e)(o[n(s)]??=[]).push(s);return o}u(y,"groupBy");function C(e,n){let o=y(e.filter(b),i=>i.evalId),s=y(n.filter(b),i=>i.evalId),a=u((i,l)=>i.runNumber-l.runNumber,"byRun"),t=[];for(let i of Object.keys(o)){let l=o[i].sort(a),d=(s[i]??[]).sort(a);for(let r=0;r<Math.min(l.length,d.length);r++){let c={withScore:_(l[r])?1:0,withoutScore:_(d[r])?1:0},f=R(l[r]),g=R(d[r]);f!=null&&g!=null&&(c.withCost=f,c.withoutCost=g);let p=v(l[r]),m=v(d[r]);p!=null&&m!=null&&(c.withLatency=p,c.withoutLatency=m),t.push(c)}}return t}u(C,"pairRunsByEval");function T(e){let n=e.filter(r=>r.status==="completed");if(n.length===0)return{runSummary:{},verdict:null,notes:["No completed runs found"],totalRuns:0};let o=y(n,r=>r.configuration),s={},a=[];for(let[r,c]of Object.entries(o)){let f=c.filter(b).map(m=>m.grading.summary.pass_rate),g=c.map(v).filter(m=>m!=null),p=c.map(R).filter(m=>m!=null);s[r]={},f.length>0&&(s[r].pass_rate=h(f)),g.length>0&&(s[r].time_seconds=h(g)),p.length>0&&(s[r].tokens=h(p))}let t=null,i=o[x]??[],l=o[E]??[],d=C(i,l);if(d.length>0){if(t=$(d),!t.sufficient)a.push(t.insufficientReason??"Insufficient data for a significance verdict.");else if(t.significant){let r=t.delta>=0?"improves":"reduces",c=t.pValue!=null?`, McNemar p=${t.pValue.toFixed(4)}`:"";a.push(`Target ${r} the pass rate by ${Math.abs(t.delta*100).toFixed(0)}% (95% CI ${(t.ci.lower*100).toFixed(0)}\u2013${(t.ci.upper*100).toFixed(0)}%, n=${t.nWith}${c}).`)}else a.push(`No significant effect on pass rate (95% CI ${(t.ci.lower*100).toFixed(0)}\u2013${(t.ci.upper*100).toFixed(0)}%, n=${t.nWith}).`);t.costDelta!=null&&Math.round(t.costDelta)!==0&&a.push(`Token cost delta: ${t.costDelta>=0?"+":""}${Math.round(t.costDelta)} tokens/task.`),t.latencyDelta!=null&&Math.abs(t.latencyDelta)>1&&a.push(`Target ${t.latencyDelta>0?"adds":"saves"} ${Math.abs(t.latencyDelta).toFixed(1)}s/task.`)}for(let r of Object.values(s))if(r.pass_rate&&r.pass_rate.stddev>.2){a.push(`High pass-rate variance (stddev=${r.pass_rate.stddev.toFixed(2)}) \u2014 results may be unreliable.`);break}return{runSummary:s,verdict:t,notes:a,totalRuns:n.length}}u(T,"summarizeRuns");async function S(e,n){let o=n?`&iteration=${n}`:"",s=100,a=[];for(let t=0;t<1e5;t+=s){let i=await w(`/api/eval-targets/${e}/runs?limit=${s}&offset=${t}&activeCasesOnly=1${o}`);if(a.push(...i),i.length<s)break}return T(a)}u(S,"aggregateBenchmark");async function B(e,n,o){return k(`/api/eval-targets/${e}/benchmarks`,{iteration:n,runSummary:o.runSummary,notes:o.notes})}u(B,"postBenchmark");export{T as a,S as b,B as c};
@@ -0,0 +1,11 @@
1
+ import{a as R,g as v,h as T,j as I,m as C}from"./chunk-VLXCQ2DC.js";import{e as d}from"./chunk-QWCEZEDO.js";import{d as g}from"./chunk-NTKO4H2K.js";import{e as _}from"./chunk-H2ORWIEY.js";import{g as m,l as k}from"./chunk-O6C2UGBY.js";import{a as i}from"./chunk-ZLLER3HP.js";import{execSync as j}from"node:child_process";import{existsSync as p,readFileSync as y}from"node:fs";import{homedir as f}from"node:os";import{join as a}from"node:path";var P=["install","auth","hooks","worker"],O=["judge"],M=[...P,...O];function $(){return{projectPath:process.cwd(),configDir:k()}}i($,"defaultContext");var A=a(f(),".mitmproxy","mitmproxy-ca-cert.pem");function S(e){if(!e)return"";if(e.length<=8)return"*".repeat(e.length);let t=e.slice(0,4),n=e.slice(-4);return`${t}${"*".repeat(Math.max(4,e.length-8))}${n}`}i(S,"maskToken");function te(e,t){let n=e===null?[]:e.replace(/\n$/,"").split(`
2
+ `),o=t===null?[]:t.replace(/\n$/,"").split(`
3
+ `),s=[],u=Math.max(n.length,o.length);for(let c=0;c<u;c++){let l=n[c],r=o[c];l===r?s.push(` ${l}`):(l!==void 0&&s.push(`-${l}`),r!==void 0&&s.push(`+${r}`))}return s.join(`
4
+ `)}i(te,"renderDiff");function x(e,t){let n=a(e,"env");if(!p(n))return null;try{let s=y(n,"utf-8").match(new RegExp(`^${t}=(.+)$`,"m"));return s?s[1]:null}catch{return null}}i(x,"readEnvValue");async function b(){if(!m())return!1;try{return(await Promise.race([_("/api/setup/status"),new Promise((t,n)=>setTimeout(()=>n(new Error("setup/status timeout")),2500))]))?.workerActive===!0}catch{return!1}}i(b,"workerActive");function E(e,t){let n=a(e,".claude",t),o={},s=null;if(p(n))try{s=y(n,"utf-8").replace(/\n$/,""),o=JSON.parse(s)}catch{o={}}return{settings:o,before:s}}i(E,"readProjectSettings");function D(e){let{settings:t,before:n}=E(e,"settings.local.json");return v(t),{before:n,after:JSON.stringify(t,null,2)}}i(D,"projectHooksSettings");function N(e){let{settings:t,before:n}=E(e,"settings.local.json"),o={...t.env??{}};return o.HTTPS_PROXY=`http://localhost:${d}`,o.NO_PROXY=I,o.NODE_EXTRA_CA_CERTS=A,{before:n,after:JSON.stringify({...t,env:o},null,2)}}i(N,"projectProxyEnvSettings");function U(e){let{settings:t,before:n}=E(e,"settings.json");if(n===null)return null;let{removed:o}=C(t,d);return o?{before:n,after:JSON.stringify(t,null,2)}:null}i(U,"projectSharedSettingsMigration");var Y=a(f(),"Library","LaunchAgents","com.rulemetric.worker.plist"),G=a(f(),".config","systemd","user","rulemetric-worker.service");function h(e){j(e,{stdio:"inherit"})}i(h,"runCommand");var L=[{id:"install",title:"Install the CLI",command:"npm install -g @rulemetric/cli",async detect(){return m()||await b()},async plan(){return{id:"install",title:"Install the CLI",command:"npm install -g @rulemetric/cli",artifacts:[{path:"npm install -g @rulemetric/cli",kind:"command",before:null,after:"rulemetric --version # verifies the binary is on PATH"}]}},async apply(){h("npm install -g @rulemetric/cli")}},{id:"auth",title:"Authenticate",command:"rulemetric auth login",async detect(){return m()},async plan(e){let t=a(e.configDir,"env"),n=null;if(p(t))try{n=X(y(t,"utf-8"))}catch{n="(unreadable)"}let o=x(e.configDir,"RULEMETRIC_ACCESS_TOKEN"),u=[`RULEMETRIC_ACCESS_TOKEN=${S(o||"<token-from-login>")}`],c=x(e.configDir,"RULEMETRIC_API_KEY");c&&u.push(`RULEMETRIC_API_KEY=${S(c)}`);let l=process.env.RULEMETRIC_API_URL;l&&u.push(`RULEMETRIC_API_URL=${l}`);let r=u.join(`
5
+ `);return{id:"auth",title:"Authenticate",command:"rulemetric auth login",artifacts:[{path:t,kind:"file",before:n,after:r,masked:!0},{path:a(e.configDir,"auth.json"),kind:"file",before:p(a(e.configDir,"auth.json"))?"(existing session tokens)":null,after:"{ accessToken, refreshToken, expiresAt, email } \u2014 OAuth session tokens (secret)",masked:!0}]}},async apply(){h("rulemetric auth login")}},{id:"hooks",title:"Install hooks + capture proxy",command:process.env.RULEMETRIC_SETUP_NO_PROXY==="1"||process.env.RULEMETRIC_SETUP_NO_PROXY==="true"?"rulemetric hooks install --no-proxy":"rulemetric hooks install",async detect(e){for(let t of["settings.local.json","settings.json"]){let n=a(e.projectPath,".claude",t);if(p(n))try{let o=JSON.parse(y(n,"utf-8"));if(T(o))return!0}catch{}}return!1},async plan(e){let t=a(e.projectPath,".claude","settings.local.json"),{before:n,after:o}=D(e.projectPath),s=[{path:t,kind:"file",before:n,after:o},{path:"what these hooks capture",kind:"service",before:null,after:"session-end reimports the FULL transcript to the API; post-tool-use records each tool call and snapshots the working tree to a LOCAL shadow git ref (paper-trail, never pushed); user-prompt posts prompt text. All scoped to sessions in this project."},{path:`${t} (proxy env block)`,kind:"file",...N(e.projectPath)},{path:"system keychain \u2014 mitmproxy root CA",kind:"service",before:p(A)?"(CA generated; trust state unchanged)":"(no CA yet)",after:"Installs + trusts the mitmproxy CA (requires sudo). This lets the proxy DECRYPT Claude Code HTTPS request/response bodies \u2014 the capability that powers rendered-system-prompt / instruction linking. Decline the sudo prompt and setup stays hooks-only (still fully onboarded)."},{path:"launchctl setenv HTTPS_PROXY (machine-wide, all GUI apps)",kind:"command",before:null,after:`http://localhost:${d} \u2014 routes every GUI app's HTTPS through the local gateway (only when the CA is trusted AND :${d} is live)`},{path:"VS Code + Cursor user settings (http.proxy)",kind:"file",before:null,after:`http.proxy \u2192 http://localhost:${d} (+ http.proxyStrictSSL=false)`},{path:`gateway process on :${d}`,kind:"service",before:null,after:"started (routes Claude Code \u2192 mitmproxy \u2192 Anthropic; falls back to direct if mitmproxy is down)"}],u=U(e.projectPath);u&&s.push({path:`${a(e.projectPath,".claude","settings.json")} (removes RuleMetric machine-local state left by an older install \u2014 see the local-file artifacts above for where it moves)`,kind:"file",...u});for(let c of R(e.projectPath).filter(l=>l==="cursor"||l==="copilot_agent"))s.push({path:`${e.projectPath} (${c} workspace proxy config)`,kind:"file",before:null,after:`proxy \u2192 http://localhost:${d}`});for(let[c,l,r]of[["Cursor",a(f(),".cursor"),a(f(),".cursor","hooks.json")],["Antigravity/Gemini",a(f(),".gemini"),a(f(),".gemini","config","hooks.json")]])p(l)&&s.push({path:`${r} (${c} user hooks)`,kind:"file",before:p(r)?"(existing config)":null,after:"adds RuleMetric session-capture hooks for this tool"});return{id:"hooks",title:"Install hooks + capture proxy",command:"rulemetric hooks install",artifacts:s}},async apply(){let e=process.env.RULEMETRIC_SETUP_NO_PROXY==="1"||process.env.RULEMETRIC_SETUP_NO_PROXY==="true";h(e?"rulemetric hooks install --no-proxy":"rulemetric hooks install")}},{id:"worker",title:"Run the worker",command:"rulemetric service install --worker-only",async detect(){return b()},async plan(){let e=process.platform==="darwin",t=e?Y:G,n=p(t)?`(service already installed at ${t})`:null,o=e?["Label: com.rulemetric.worker","ProgramArguments: <node> <cli>/bin/run.js evals agent","RunAtLoad: true, KeepAlive: true"].join(`
6
+ `):["[Service]","ExecStart=<node> <cli>/bin/run.js evals agent","Restart=on-failure"].join(`
7
+ `);return{id:"worker",title:"Run the worker",command:"rulemetric service install --worker-only",artifacts:[{path:t,kind:"service",before:n,after:o}]}},async apply(){h("rulemetric service install --worker-only")}},{id:"judge",title:"Second LLM engine for cross-vendor eval grading (optional)",command:"npm install -g @openai/codex",optional:!0,async detect(){let e=g();return e.claudeBin!=null&&e.codexBin!=null},async plan(){let e=g();return{id:"judge",title:"Second LLM engine for cross-vendor eval grading (optional)",command:"npm install -g @openai/codex",artifacts:[{path:"installed LLM engines",kind:"command",before:[`claude CLI: ${e.claudeBin??"not found"}`,`codex CLI: ${e.codexBin??"not found"}`].join(`
8
+ `),after:["claude CLI + codex CLI both installed.","Hand labels + one judge already give calibrated verdicts; a second","engine additionally unlocks cross-vendor judge validation","(`rulemetric evals validate-judge`)."].join(`
9
+ `)}]}},async apply(){let e=g();if(e.claudeBin!=null&&e.codexBin!=null){console.log("[OK] Both engines already installed \u2014 nothing to do.");return}let t=e.codexBin==null?"codex":"claude";console.log(`[..] Second GRADING engine not detected (missing: ${t} CLI).`),t==="codex"?(console.log(" This is about GRADING EVALS with a second vendor, not about capturing"),console.log(" your Codex sessions. Codex capture needs no setup: the worker imports"),console.log(" ~/.codex/sessions automatically. Nothing is missing for that."),console.log(" Optional install: npm install -g @openai/codex")):console.log(" Install it yourself when ready: npm install -g @anthropic-ai/claude-code"),console.log(" Then re-run: rulemetric setup judge --show")}}],H=new Map(L.map(e=>[e.id,e]));function ne(e){let t=H.get(e);if(!t)throw new Error(`Unknown setup step: ${e}`);return t}i(ne,"getStep");function oe(e){return M.includes(e)}i(oe,"isStepId");var K=new Set(["RULEMETRIC_API_URL","RULEMETRIC_USER_ID","RULEMETRIC_CLIENT_NAME","RESEND_FROM_EMAIL","SENTRY_DSN","PG_POOL_MAX","PG_IDLE_TIMEOUT","PG_STATEMENT_TIMEOUT_MS","NODE_ENV"]);function X(e){return e.replace(/\n$/,"").split(`
10
+ `).map(t=>{let n=t.match(/^([A-Z0-9_]+)=(.+)$/);if(!n)return t;let[,o,s]=n;return K.has(o)?t:`${o}=${S(s)}`}).join(`
11
+ `)}i(X,"maskEnvFile");async function re(e=$()){let t=[];for(let r of L){let w=await r.detect(e);t.push({id:r.id,done:w})}let n=new Set(P),o=t.find(r=>r.id==="install");o&&!o.done&&(o.done=t.some(r=>r.id!=="install"&&n.has(r.id)&&r.done));let s=new Set(P),u=t.filter(r=>s.has(r.id)),c=u.find(r=>!r.done)?.id??null,l=u.every(r=>r.done);return{steps:t,coreComplete:l,currentStepId:c}}i(re,"computeStatus");export{P as a,O as b,M as c,$ as d,S as e,te as f,L as g,ne as h,oe as i,re as j};
@@ -1 +1 @@
1
- import{b as D,c as j}from"./chunk-6UEFCMR2.js";import{a as G}from"./chunk-7AZKPX2J.js";import{c as J}from"./chunk-V5MJ4ICC.js";import{b as B,c as R,d as N,e as z}from"./chunk-OPUI7CM2.js";import{e as f,g as T}from"./chunk-H2ORWIEY.js";import{a as p}from"./chunk-ZLLER3HP.js";function W(r,a,s){return s?r.reviewerModel===s||r.reviewerModel===`${a}:${s}`:r.reviewerEngine===a}p(W,"reviewMatchesReviewer");var C=100;function Z(r){let a=new Set;return r.forEach((s,d)=>{s.method!=="deterministic"&&a.add(d)}),a}p(Z,"llmExpectationIndexes");var w=class extends Error{constructor(s,d){super(d);this.reason=s}static{p(this,"JudgeReviewSkip")}};async function oe(r){let a=r.log??(()=>{}),s=r.warn??a,d=r.targetId,K=r.parallel??3,U=r.timeoutMs??12e4,v=await f(`/api/eval-targets/${d}`),u=(await f(`/api/eval-targets/${d}/annotations?limit=500`)).filter(e=>e.judgeMethod==="llm");if(u.length===0)throw new w("no-labels",`No human labels on "${v.name}" yet \u2014 label some runs in the Review tab first.`);let n;try{n=z({engineFlag:r.engineFlag??"auto",modelFlag:r.modelFlag,availability:N(),judgeModels:[...new Set(u.map(e=>e.judgeModel).filter(e=>e!=null))]})}catch(e){throw new w("no-engine",e instanceof Error?e.message:String(e))}a(`Reviewer: ${n.rationale}`);let c=0,b=u;if(r.skipReviewed){let e=await f(`/api/eval-targets/${d}/judge-reviews`),t=new Set(e.filter(i=>W(i,n.engine,r.modelFlag)).map(i=>`${i.evalRunId}:${i.expectationIndex}`));if(b=u.filter(i=>!t.has(`${i.evalRunId}:${i.expectationIndex}`)),c=u.length-b.length,b.length===0)return{targetName:v.name,reviewer:n,judgeModels:[],reviewerModel:n.model??`${n.engine} (CLI default)`,report:j([],0),persisted:0,alreadyReviewed:c,deferredPartialRuns:0}}let y=new Map;for(let e=0;;e+=C){let t=await f(`/api/eval-targets/${d}/runs?limit=${C}&offset=${e}`);for(let i of t)y.set(i.id,i);if(t.length<C)break}let q=await f(`/api/eval-targets/${d}/evals`),X=new Map(q.map(e=>[e.id,e.prompt])),o=new Map;for(let e of b){let t=o.get(e.evalRunId)??[];t.push(e),o.set(e.evalRunId,t)}let P=new Map;for(let e of u){let t=P.get(e.evalRunId)??new Set;t.add(e.expectationIndex),P.set(e.evalRunId,t)}let x=0;for(let[e]of[...o]){let t=y.get(e)?.grading?.expectations;if(!t)continue;let i=Z(t),g=P.get(e)??new Set;[...i].every(h=>g.has(h))||(o.delete(e),x+=1)}if(x>0&&a(`${x} partially-labeled run(s) deferred \u2014 a run is re-graded once, after all its assertions are labeled.`),o.size===0)return{targetName:v.name,reviewer:n,judgeModels:[],reviewerModel:n.model??`${n.engine} (CLI default)`,report:j([],0),persisted:0,alreadyReviewed:c,deferredPartialRuns:x};if(n.engine==="codex"&&n.model){let e=await J({prompt:"Reply with exactly: OK",model:n.model,timeout:6e4});if(e.error&&B(e.error)){if(n.model===R)throw new w("preflight-failed",`Codex fallback model ${R} is also unrunnable: ${e.error}`);s(`Your codex model "${n.model}" can't run on the installed CLI/account \u2014 falling back to ${R}.`),n={...n,model:R}}else if(e.error)throw new w("preflight-failed",`Codex preflight failed: ${e.error}`)}let S=[...o.values()].flat(),Y=[...new Set(S.map(e=>e.judgeModel).filter(e=>e!=null))];a(`Re-grading ${o.size} annotated run(s) / ${S.length} assertion(s) on "${v.name}"`+(c?` (${c} already reviewed \u2014 skipped)`:"")+".");let $=[],I=0,k=new Set,m=r.limit!=null?[...o.entries()].slice(0,Math.max(1,r.limit)):[...o.entries()];m.length<o.size&&a(`Sampling ${m.length} of ${o.size} annotated runs (limit).`);let H=0,Q=p(async()=>{for(;;){let e=H++;if(e>=m.length)return;let[t,i]=m[e],g=y.get(t),h=g?.grading?.expectations,O=g?.outputs?.transcript,F=g?X.get(g.evalId):void 0;if(!g||!h?.length||!O||!F){I+=i.length,s(`run ${t.slice(0,8)}: missing output/expectations/prompt \u2014 skipped`);continue}let M=await G({prompt:F,output:O,expectations:h.map(l=>l.text),model:n.model??void 0,timeout:U,engine:n.engine});M.judge_model&&k.add(M.judge_model);for(let l of i){let L=h[l.expectationIndex],A=M.expectations[l.expectationIndex];if(!L||!A||L.text!==l.expectationText){I+=1;continue}if(M.judge_model==null&&A.method==="llm"){I+=1;continue}$.push({runId:t,expectationIndex:l.expectationIndex,text:l.expectationText,humanPassed:D(l.verdict,l.judgePassed),judgeAPassed:l.judgePassed,judgeBPassed:A.passed})}a(` ${e+1}/${m.length} re-graded`)}},"workerFn");await Promise.all(Array.from({length:Math.max(1,Math.min(K,m.length))},Q));let V=j($,I),_=[...k][0]??n.model??`${n.engine} (CLI default)`,E=0;if($.length>0)try{E=(await T(`/api/eval-targets/${d}/judge-reviews`,{reviewerEngine:n.engine,reviewerModel:_,verdicts:$.map(t=>({evalRunId:t.runId,expectationIndex:t.expectationIndex,expectationText:t.text,judgePassed:t.judgeAPassed,humanPassed:t.humanPassed,reviewerPassed:t.judgeBPassed}))})).upserted,a(`Persisted ${E} reviewer verdict(s) \u2014 disagreements appear on the Review tab.`)}catch(e){s(`Could not persist reviewer verdicts: ${e instanceof Error?e.message:e}`)}return{targetName:v.name,reviewer:n,judgeModels:Y,reviewerModel:_,report:V,persisted:E,alreadyReviewed:c,deferredPartialRuns:x}}p(oe,"runJudgeReviewPass");export{W as a,Z as b,w as c,oe as d};
1
+ import{b as D,c as j}from"./chunk-6UEFCMR2.js";import{b as B,c as R,d as N,e as z}from"./chunk-NTKO4H2K.js";import{a as G}from"./chunk-4L2ZEIRE.js";import{c as J}from"./chunk-XRTZU7IZ.js";import{e as f,g as T}from"./chunk-H2ORWIEY.js";import{a as p}from"./chunk-ZLLER3HP.js";function W(r,a,s){return s?r.reviewerModel===s||r.reviewerModel===`${a}:${s}`:r.reviewerEngine===a}p(W,"reviewMatchesReviewer");var C=100;function Z(r){let a=new Set;return r.forEach((s,d)=>{s.method!=="deterministic"&&a.add(d)}),a}p(Z,"llmExpectationIndexes");var w=class extends Error{constructor(s,d){super(d);this.reason=s}static{p(this,"JudgeReviewSkip")}};async function oe(r){let a=r.log??(()=>{}),s=r.warn??a,d=r.targetId,K=r.parallel??3,U=r.timeoutMs??12e4,v=await f(`/api/eval-targets/${d}`),u=(await f(`/api/eval-targets/${d}/annotations?limit=500`)).filter(e=>e.judgeMethod==="llm");if(u.length===0)throw new w("no-labels",`No human labels on "${v.name}" yet \u2014 label some runs in the Review tab first.`);let n;try{n=z({engineFlag:r.engineFlag??"auto",modelFlag:r.modelFlag,availability:N(),judgeModels:[...new Set(u.map(e=>e.judgeModel).filter(e=>e!=null))]})}catch(e){throw new w("no-engine",e instanceof Error?e.message:String(e))}a(`Reviewer: ${n.rationale}`);let c=0,b=u;if(r.skipReviewed){let e=await f(`/api/eval-targets/${d}/judge-reviews`),t=new Set(e.filter(i=>W(i,n.engine,r.modelFlag)).map(i=>`${i.evalRunId}:${i.expectationIndex}`));if(b=u.filter(i=>!t.has(`${i.evalRunId}:${i.expectationIndex}`)),c=u.length-b.length,b.length===0)return{targetName:v.name,reviewer:n,judgeModels:[],reviewerModel:n.model??`${n.engine} (CLI default)`,report:j([],0),persisted:0,alreadyReviewed:c,deferredPartialRuns:0}}let y=new Map;for(let e=0;;e+=C){let t=await f(`/api/eval-targets/${d}/runs?limit=${C}&offset=${e}`);for(let i of t)y.set(i.id,i);if(t.length<C)break}let q=await f(`/api/eval-targets/${d}/evals`),X=new Map(q.map(e=>[e.id,e.prompt])),o=new Map;for(let e of b){let t=o.get(e.evalRunId)??[];t.push(e),o.set(e.evalRunId,t)}let P=new Map;for(let e of u){let t=P.get(e.evalRunId)??new Set;t.add(e.expectationIndex),P.set(e.evalRunId,t)}let x=0;for(let[e]of[...o]){let t=y.get(e)?.grading?.expectations;if(!t)continue;let i=Z(t),g=P.get(e)??new Set;[...i].every(h=>g.has(h))||(o.delete(e),x+=1)}if(x>0&&a(`${x} partially-labeled run(s) deferred \u2014 a run is re-graded once, after all its assertions are labeled.`),o.size===0)return{targetName:v.name,reviewer:n,judgeModels:[],reviewerModel:n.model??`${n.engine} (CLI default)`,report:j([],0),persisted:0,alreadyReviewed:c,deferredPartialRuns:x};if(n.engine==="codex"&&n.model){let e=await J({prompt:"Reply with exactly: OK",model:n.model,timeout:6e4});if(e.error&&B(e.error)){if(n.model===R)throw new w("preflight-failed",`Codex fallback model ${R} is also unrunnable: ${e.error}`);s(`Your codex model "${n.model}" can't run on the installed CLI/account \u2014 falling back to ${R}.`),n={...n,model:R}}else if(e.error)throw new w("preflight-failed",`Codex preflight failed: ${e.error}`)}let S=[...o.values()].flat(),Y=[...new Set(S.map(e=>e.judgeModel).filter(e=>e!=null))];a(`Re-grading ${o.size} annotated run(s) / ${S.length} assertion(s) on "${v.name}"`+(c?` (${c} already reviewed \u2014 skipped)`:"")+".");let $=[],I=0,k=new Set,m=r.limit!=null?[...o.entries()].slice(0,Math.max(1,r.limit)):[...o.entries()];m.length<o.size&&a(`Sampling ${m.length} of ${o.size} annotated runs (limit).`);let H=0,Q=p(async()=>{for(;;){let e=H++;if(e>=m.length)return;let[t,i]=m[e],g=y.get(t),h=g?.grading?.expectations,O=g?.outputs?.transcript,F=g?X.get(g.evalId):void 0;if(!g||!h?.length||!O||!F){I+=i.length,s(`run ${t.slice(0,8)}: missing output/expectations/prompt \u2014 skipped`);continue}let M=await G({prompt:F,output:O,expectations:h.map(l=>l.text),model:n.model??void 0,timeout:U,engine:n.engine});M.judge_model&&k.add(M.judge_model);for(let l of i){let L=h[l.expectationIndex],A=M.expectations[l.expectationIndex];if(!L||!A||L.text!==l.expectationText){I+=1;continue}if(M.judge_model==null&&A.method==="llm"){I+=1;continue}$.push({runId:t,expectationIndex:l.expectationIndex,text:l.expectationText,humanPassed:D(l.verdict,l.judgePassed),judgeAPassed:l.judgePassed,judgeBPassed:A.passed})}a(` ${e+1}/${m.length} re-graded`)}},"workerFn");await Promise.all(Array.from({length:Math.max(1,Math.min(K,m.length))},Q));let V=j($,I),_=[...k][0]??n.model??`${n.engine} (CLI default)`,E=0;if($.length>0)try{E=(await T(`/api/eval-targets/${d}/judge-reviews`,{reviewerEngine:n.engine,reviewerModel:_,verdicts:$.map(t=>({evalRunId:t.runId,expectationIndex:t.expectationIndex,expectationText:t.text,judgePassed:t.judgeAPassed,humanPassed:t.humanPassed,reviewerPassed:t.judgeBPassed}))})).upserted,a(`Persisted ${E} reviewer verdict(s) \u2014 disagreements appear on the Review tab.`)}catch(e){s(`Could not persist reviewer verdicts: ${e instanceof Error?e.message:e}`)}return{targetName:v.name,reviewer:n,judgeModels:Y,reviewerModel:_,report:V,persisted:E,alreadyReviewed:c,deferredPartialRuns:x}}p(oe,"runJudgeReviewPass");export{W as a,Z as b,w as c,oe as d};
@@ -1,2 +1,2 @@
1
- import{c as E,o as m}from"./chunk-7DFNBRLY.js";import{a as d}from"./chunk-H2ORWIEY.js";import{a as c}from"./chunk-ZLLER3HP.js";import*as p from"node:fs";import*as u from"node:path";import*as _ from"node:os";function T(){if(process.env.RULEMETRIC_API_KEY||process.env.RULEMETRIC_ACCESS_TOKEN)return;let s=u.join(_.homedir(),".config","rulemetric","env");C(s)||C(u.join(process.cwd(),".env.local"))}c(T,"ensureEnv");function C(s){try{let t=p.readFileSync(s,"utf-8");for(let n of t.split(`
1
+ import{c as E,o as m}from"./chunk-5DIOZDDZ.js";import{a as d}from"./chunk-H2ORWIEY.js";import{a as c}from"./chunk-ZLLER3HP.js";import*as p from"node:fs";import*as u from"node:path";import*as _ from"node:os";function T(){if(process.env.RULEMETRIC_API_KEY||process.env.RULEMETRIC_ACCESS_TOKEN)return;let s=u.join(_.homedir(),".config","rulemetric","env");C(s)||C(u.join(process.cwd(),".env.local"))}c(T,"ensureEnv");function C(s){try{let t=p.readFileSync(s,"utf-8");for(let n of t.split(`
2
2
  `)){let e=n.trim();if(!e||e.startsWith("#"))continue;let o=e.indexOf("=");if(o<0)continue;let r=e.slice(0,o).trim(),i=e.slice(o+1).trim();process.env[r]||(process.env[r]=i)}return!!(process.env.RULEMETRIC_API_KEY||process.env.RULEMETRIC_ACCESS_TOKEN)}catch{return!1}}c(C,"loadEnvFile");T();async function I(s){let t={totalSessions:0,totalCalls:0,totalInputTokens:0,totalOutputTokens:0,totalCacheReadTokens:0,totalCacheWriteTokens:0,totalCostUSD:0,providers:{}},n=await m(s);t.providers={};for(let a of n)t.providers[a.provider]=(t.providers[a.provider]||0)+1;let e=new E,o=n.filter(a=>a.provider==="claude");for(let a of o)try{let h=p.readdirSync(a.path).filter(f=>f.endsWith(".jsonl"));t.totalSessions+=h.length;for(let f of h){let v=p.readFileSync(u.join(a.path,f),"utf-8"),R=e.parse(v);for(let l of R.events)l.tokenUsage&&(t.totalCalls++,t.totalInputTokens+=l.tokenUsage.input,t.totalOutputTokens+=l.tokenUsage.output,t.totalCacheReadTokens+=l.tokenUsage.cacheRead??0,t.totalCacheWriteTokens+=l.tokenUsage.cacheWrite??0)}}catch{}let r=15,i=75;return t.totalCostUSD=Math.round((t.totalInputTokens/1e6*r+t.totalOutputTokens/1e6*i+t.totalCacheReadTokens/1e6*(r*.1)+t.totalCacheWriteTokens/1e6*(r*1.25))*100)/100,t}c(I,"loadLocalStats");async function U(s){let t=process.env.RULEMETRIC_API_URL??d,n=process.env.RULEMETRIC_API_KEY,e=process.env.RULEMETRIC_ACCESS_TOKEN,o=n??e;if(!o)return null;let r=new URLSearchParams;s&&r.set("projectPath",s);try{let i=await fetch(`${t}/api/insights/compute?${r}`,{headers:{Authorization:`Bearer ${o}`},signal:AbortSignal.timeout(5e3)});return i.ok?await i.json():null}catch{return null}}c(U,"loadApiInsights");async function g(s){let t=process.env.RULEMETRIC_API_URL??d,n=process.env.RULEMETRIC_API_KEY??process.env.RULEMETRIC_ACCESS_TOKEN;if(!n)return null;let e=new URLSearchParams;s&&e.set("projectPath",s);try{let o=await fetch(`${t}/api/insights/linked-instructions?${e}`,{headers:{Authorization:`Bearer ${n}`},signal:AbortSignal.timeout(5e3)});return o.ok?await o.json():null}catch{return null}}c(g,"loadLinkedInstructions");export{I as a,U as b,g as c};
@@ -1,3 +1,3 @@
1
- import{a as w}from"./chunk-MODFTCZY.js";import{a as r}from"./chunk-ZLLER3HP.js";import{spawn as k}from"node:child_process";import{mkdtempSync as v,readFileSync as M,rmSync as S}from"node:fs";import{tmpdir as $}from"node:os";import{join as P}from"node:path";var D=r(o=>`codex:${o}`,"codexModelId");function R(o,i){return["exec","--sandbox","read-only","--skip-git-repo-check","--ephemeral","--model",o,"--output-last-message",i,"-"]}r(R,"buildCodexArgs");async function j(o){let{prompt:i,systemPrompt:l,model:c,timeout:u=12e4,workDir:b=process.cwd()}=o,T=l?`${l}
1
+ import{a as w}from"./chunk-B3BHB26P.js";import{a as r}from"./chunk-ZLLER3HP.js";import{spawn as k}from"node:child_process";import{mkdtempSync as v,readFileSync as M,rmSync as S}from"node:fs";import{tmpdir as $}from"node:os";import{join as P}from"node:path";var D=r(o=>`codex:${o}`,"codexModelId");function R(o,i){return["exec","--sandbox","read-only","--skip-git-repo-check","--ephemeral","--model",o,"--output-last-message",i,"-"]}r(R,"buildCodexArgs");async function j(o){let{prompt:i,systemPrompt:l,model:c,timeout:u=12e4,workDir:b=process.cwd()}=o,T=l?`${l}
2
2
 
3
3
  ${i}`:i,m=w("codex");if(!m)return{output:"",exitCode:null,durationMs:0,error:"Codex CLI not found on PATH, well-known install dirs, or the node bin dir \u2014 is it installed?"};let p=v(P($(),"rulemetric-codex-")),a=P(p,"last-message.txt"),h=Date.now();return new Promise(E=>{let s={...process.env};delete s.HTTPS_PROXY;let y=["/opt/homebrew/bin","/usr/local/bin"],x=(s.PATH??"").split(":").filter(Boolean),f=y.filter(e=>!x.includes(e));f.length&&(s.PATH=[...x,...f].join(":"));let t=k(m,R(c,a),{cwd:b,env:s,stdio:["pipe","pipe","pipe"]}),g="";t.stdout.on("data",()=>{}),t.stderr.on("data",e=>{g+=e.toString()});let n=r(e=>{S(p,{recursive:!0,force:!0}),E({...e,durationMs:Date.now()-h})},"finish"),C=setTimeout(()=>{t.kill("SIGTERM"),n({output:"",exitCode:null,error:`codex exec timed out after ${u}ms`})},u);t.on("error",e=>{clearTimeout(C),n({output:"",exitCode:null,error:`failed to spawn codex: ${e.message} (is the Codex CLI installed?)`})}),t.on("close",e=>{clearTimeout(C);let d="";try{d=M(a,"utf8").trim()}catch{}if(e!==0||d===""){n({output:d,exitCode:e,error:`codex exec failed (exit ${e}): ${g.trim().slice(-500)||"no last message produced"}`});return}n({output:d,exitCode:e,model:D(c)})}),t.stdin.write(T),t.stdin.end()})}r(j,"executeCodexEval");export{D as a,R as b,j as c};
@@ -0,0 +1 @@
1
+ import{f as Z}from"./chunk-RMDLJN4L.js";import{b as B,i as V,j as X,k as J,l as Y,m as z,n as K}from"./chunk-BL4BN6RU.js";import{e as Q}from"./chunk-2ZAKZEXW.js";import{d as G,e as S,f as W}from"./chunk-G5BXZT6F.js";import{e as $,f as q}from"./chunk-H2ORWIEY.js";import{a as c}from"./chunk-ZLLER3HP.js";import{createHash as ie}from"node:crypto";var _=c(e=>ie("sha256").update(e).digest("hex"),"sha256"),ee=1.3,H=4,le=20;function ue(e,r){if(!e.configured||r<=0)return H;let n=Math.ceil(e.minPairs*ee/r);return Math.min(le,Math.max(H,n))}c(ue,"passCapFor");function ce(e,r=10,n=H){if(e<=0)return{passes:0,expectedPairs:0,feasible:!1,reason:"no live cases"};let s=Math.ceil(r*ee),t=Math.min(n,Math.ceil(s/e)),a=t*e;return a<r?{passes:t,expectedPairs:a,feasible:!1,reason:`${e} live case(s) x ${n} passes = ${e*n} pairs at best, below the ${r} a controlled verdict requires \u2014 add cases rather than replaying these`}:{passes:t,expectedPairs:a,feasible:!0}}c(ce,"planPasses");var pe=60,de=c(e=>typeof e=="object"&&e!==null&&typeof e.withScore=="number"&&typeof e.withoutScore=="number","isPair");function ge(e,r,n){let s=[...e].sort((t,a)=>Date.parse(a.createdAt)-Date.parse(t.createdAt));for(let t of s){if(t.applied)continue;let a=t.gates?.accumulation;if(!a||typeof a!="object"||a.priorContentHash!==r||a.targetPairs!==n||typeof a.candidateContentHash!="string"||!Array.isArray(a.pairs))continue;let p=a.pairs.filter(de);if(p.length===a.pairs.length&&!(p.length>=n))return{promotionId:t.id,candidateContentHash:a.candidateContentHash,pairs:p,runs:typeof a.runs=="number"?a.runs:1}}return null}c(ge,"findOpenAccumulation");function me(e,r){let n=r.accumulate??(e.autoEvolveAccumulate===!0||e.autoEvolveAccumulate==="true"),s=r.accumulateTargetPairs??e.autoEvolveAccumulateTarget,t=typeof s=="string"?Number.parseInt(s,10):s,a=typeof t=="number"&&Number.isInteger(t)&&t>0?t:pe;return{enabled:n,targetPairs:a}}c(me,"readAccumulateConfig");function fe(e){let r=e.accumulateEnabled&&e.pairCount<e.targetPairs;return{apply:e.consented&&!r,peeking:r}}c(fe,"resolveApply");async function Ae(e,r){let n=c(o=>r?.logger?.info?.(o)??console.log(o),"log"),{evalTargetId:s}=e,t=`[cron_instruction_evolution] ${s}`,a=await $(`/api/eval-targets/${s}`),p=a.metadata??{};if(X(p))return n(`${t}: PAUSED (metadata.autoEvolvePaused) \u2014 no model budget spent. Opt-in is intact.`),{skipped:"paused"};let y=be(p);if(y==null)return n(`${t}: refusing \u2014 metadata.immutableSections is unset. Set it (use [] to explicitly protect nothing) before letting the loop edit this target unattended.`),{skipped:"immutable-sections-unset"};let f=(await $(`/api/eval-targets/${s}/evals`)).filter(o=>!o.retiredAt);if(f.length===0)return{skipped:"no-live-cases"};let R=V(p);R.note&&n(`${t}: ${R.note}`);let d=ce(f.length,R.minPairs,ue(R,f.length));if(!d.feasible)return n(`${t}: cannot reach a sufficient verdict \u2014 ${d.reason}`),{skipped:"cannot-reach-min-n",reason:d.reason};let te=J({liveCases:f.length,passes:d.passes});n(`${t}: budget for this run \u2014 ${K(te)}`);let E=await $(`/api/eval-targets/${s}/judge-calibration`);if(!E.powerCheck.adequate){let o=(E.powerCheck.reasons??[]).join("; ");return n(`${t}: not adequately powered, skipping before spending budget \u2014 ${o}`),{skipped:"not-adequate",reason:o}}let M=W,ne=Date.now()-M*24*60*60*1e3,T=await $(`/api/eval-targets/${s}/promotions?limit=200`),O=T.promotions.filter(o=>o.applied&&Date.parse(o.createdAt)>=ne).length;if(O>=S)return n(`${t}: change budget looks exhausted (${O}/${S} applied in ${M}d), skipping before spending budget`),{skipped:"budget-exhausted"};let A=G();if(!A.green)return n(`${t}: A/A canary is RED \u2014 halting. ${A.failures.join(" | ")}`),{skipped:"canary-red",reason:A.failures.join(" | ")};let L=a.content,k=_(L),l=me(p,e),b=l.enabled?ge(T.promotions,k,l.targetPairs):null,v,x,w=[],C=0,N=B;if(b){let o=await $(`/api/promotions/${b.promotionId}`);if(_(o.toContent)!==b.candidateContentHash)return n(`${t}: stored candidate does not match its recorded hash \u2014 refusing to continue`),{skipped:"accumulation-hash-mismatch",reason:b.promotionId};v=o.toContent,x=o.proposalRationale??"",w=b.pairs,C=b.runs,N=0,n(`${t}: continuing accumulation ${b.promotionId} \u2014 ${w.length}/${l.targetPairs} pair(s) carried from ${C} prior run(s)`)}else{let o=E.caseDiscrimination?.cases??[],u=await Z({currentContent:a.content,targetType:a.type,targetName:a.name,immutableSections:y,evidence:{nonDiscriminating:o.filter(i=>!i.discriminating).map(i=>`${i.name??i.assertion??"unnamed"} \u2014 ${i.note}`),weakest:o.filter(i=>i.discriminating&&i.withPassRate<i.withoutPassRate).map(i=>({name:i.name??i.assertion??"unnamed",withPassRate:i.withPassRate,withoutPassRate:i.withoutPassRate})),notes:[]}});if(!u.ok)return n(`${t}: no usable proposal \u2014 ${u.reason}`),{skipped:"no-proposal",reason:u.reason};v=u.proposal.candidateContent,x=u.proposal.rationale}n(`${t}: measuring ${f.length} case(s) x ${d.passes} pass(es) = up to ${d.expectedPairs} pairs, candidate vs prior version`);let h=[],j=[],ae=Date.now(),U=0,I=0;for(let o=1;o<=d.passes;o++){let u=await Q({cases:f,candidateContent:v,priorVersionContent:L,concurrency:e.concurrency??2,runNumber:o,opts:{targetId:s,targetVersion:a.version??1,iteration:1,timeout:e.timeout??24e4,model:e.model,graderModel:e.graderModel,skipGrading:!1,targetType:a.type,targetName:a.name},onLog:n});h.push(...u.pairs),j.push(...u.results),U+=u.completed,I+=u.failed,n(`${t}: pass ${o}/${d.passes} \u2014 ${u.pairs.length} pair(s), running total ${h.length}`)}let P=[...w,...h],D=h.length>0,g=Y({runs:j,plannedPairs:d.expectedPairs,usablePairs:h.length,verdictPairs:D?P.length:h.length,proposalCalls:N,passes:d.passes,liveCases:f.length,wallMs:Date.now()-ae});if(n(`${t}: ${U} completed, ${I} failed, ${h.length} usable pair(s) \u2014 spent ~${g.modelCalls} model calls (${g.proposalCalls} proposal + ${g.executorCalls} executor + >=${g.graderCalls} grader) in ${(g.wallMs/6e4).toFixed(1)} min`+(D?`; the ${g.verdictPairs} pair(s) behind this verdict resolve +/-${z(g.mde)} at 80% power`:"")),!D)return{skipped:"no-pairs",reason:`${I} run(s) failed or were ungradeable`,cost:g};l.enabled&&n(`${t}: accumulated ${P.length}/${l.targetPairs} pair(s) over ${C+1} run(s) on one candidate`);let F=e.apply??(p.autoEvolveApply===!0||p.autoEvolveApply==="true"),{apply:oe,peeking:re}=fe({consented:F,accumulateEnabled:l.enabled,pairCount:P.length,targetPairs:l.targetPairs});F&&re&&n(`${t}: interim readout at ${P.length}/${l.targetPairs} pairs \u2014 recording the decision but not acting until the target is reached`);let m=await q(`/api/eval-targets/${s}/promotions`,{candidateContent:v,proposalSource:"llm",proposalRationale:x,pairs:P,canaryGreen:A.green,measuredAgainstContentHash:k,immutableSections:y,apply:oe,measurementCost:g,...l.enabled?{accumulation:{candidateContentHash:_(v),priorContentHash:k,targetPairs:l.targetPairs,carriedPairs:w.length,runs:C+1}}:{}});return n(`${t}: ${m.decision}${m.applied?" (APPLIED)":""} \u2014 ${m.rationale}`+(m.refusals.length>0?` | refusals: ${m.refusals.join("; ")}`:"")),{decision:m.decision,applied:m.applied,nPairs:P.length,promotionId:m.id,cost:g,...l.enabled?{carriedPairs:w.length,accumulationRuns:C+1}:{}}}c(Ae,"cronInstructionEvolution");function be(e){let r=e.immutableSections;return r==null||!Array.isArray(r)?null:r.filter(n=>typeof n=="string")}c(be,"readImmutableSections");export{ee as a,H as b,le as c,ue as d,ce as e,pe as f,ge as g,me as h,fe as i,Ae as j,be as k};
@@ -1,4 +1,4 @@
1
- import{f}from"./chunk-MODFTCZY.js";import{b as S,e as a,h as y}from"./chunk-H2ORWIEY.js";import{a as p}from"./chunk-ZLLER3HP.js";var _=1800*1e3,G=300*1e3,T=10,h=`Given these messages from an AI coding session, write a 1-2 sentence summary of what the user is trying to accomplish. Focus on the goal, not the steps. No preamble.
1
+ import{f}from"./chunk-B3BHB26P.js";import{b as S,e as a,h as y}from"./chunk-H2ORWIEY.js";import{a as p}from"./chunk-ZLLER3HP.js";var _=1800*1e3,G=300*1e3,T=10,h=`Given these messages from an AI coding session, write a 1-2 sentence summary of what the user is trying to accomplish. Focus on the goal, not the steps. No preamble.
2
2
 
3
3
  Return strict JSON in the form: {"goalSummary": "..."}`;async function k(n,e={}){let d=e.llm??f,o=e.now??Date.now,w=e.getSession??(async s=>{try{return await a(`/api/sessions/${s}`)}catch(t){if(t instanceof S&&t.statusCode===404)return null;throw t}}),m=e.getEvents??((s,t)=>a(`/api/sessions/${s}/events?limit=${t.limit}&sort=${t.sort}`)),v=e.saveGoal??(async(s,t)=>{await y(`/api/sessions/${s}/enrich`,{analysis:t})}),i=await w(n.sessionId);if(!i)return{skipped:"not_found"};let[P]=await m(n.sessionId,{limit:1,sort:"desc"}),A=new Date(P?.timestamp??i.startedAt).getTime();if(o()-A>_)return{skipped:"stale"};let l=i.analysis??{},c=l.goalSummaryAt?new Date(l.goalSummaryAt).getTime():0;if(c&&o()-c<G)return{skipped:"recent"};let g=(await m(n.sessionId,{limit:T*2,sort:"asc"})).filter(s=>s.content&&(s.eventType==="user_message"||s.eventType==="assistant_response")).map(s=>`${s.eventType==="user_message"?"USER":"ASSISTANT"}: ${s.content}`).join(`
4
4
 
@@ -0,0 +1,2 @@
1
+ import{a as l,b as w,c as C,d as b,e as v,f as a,g as x}from"../../chunk-RUZ36O55.js";import{b as m,d as u}from"../../chunk-VX2GJCQ4.js";import{a as g}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import{l as h}from"../../chunk-O6C2UGBY.js";import{a as p}from"../../chunk-ZLLER3HP.js";import{existsSync as S}from"node:fs";import{Flags as s}from"@oclif/core";var c=class y extends g{static{p(this,"CaptureScope")}static description="Show or set which projects the worker sweeps for Codex transcripts";static examples=["<%= config.bin %> <%= command.id %>","<%= config.bin %> <%= command.id %> --add ~/work/client-a --add ~/work/client-b","<%= config.bin %> <%= command.id %> --remove ~/work/client-a","<%= config.bin %> <%= command.id %> --off","<%= config.bin %> <%= command.id %> --all"];static flags={add:s.string({description:"Capture Codex sessions under this path (repeatable). Implies an allowlist.",multiple:!0}),remove:s.string({description:"Stop capturing under this path (repeatable).",multiple:!0}),off:s.boolean({description:"Skip the Codex sweep entirely.",exclusive:["all"]}),all:s.boolean({description:"Capture every project (the default).",exclusive:["off"]}),clear:s.boolean({description:"Remove the codex scope, restoring the default."})};async run(){let{flags:e}=await this.parse(y),i=h(),r=l(i);if(!((e.add?.length??0)>0||(e.remove?.length??0)>0||e.off||e.all||e.clear)){await this.show(i,r);return}for(let t of[...e.add??[],...e.remove??[]])v(t)||this.error(`Not an absolute path: ${t}
2
+ Use an absolute path or ~/\u2026 \u2014 relative paths cannot be matched against a session's cwd.`);for(let t of e.add??[]){let n=b(t);S(n)||this.warn(`${n} does not exist yet \u2014 added anyway, but nothing will match until it does.`)}let o;try{o=w(i)}catch(t){e.clear||this.error(t instanceof Error?t.message:String(t));let n=x(i);this.warn(`${l(i)} was not valid JSON \u2014 saved it to ${n} and starting fresh.`),o={}}let f=!1;if(e.clear&&({config:o}=a(o,{op:"clear"})),e.off&&({config:o}=a(o,{op:"mode",mode:"off"})),e.all&&({config:o}=a(o,{op:"mode",mode:"all"})),e.remove?.length){let t=a(o,{op:"remove",roots:e.remove});o=t.config,f=t.emptiedToOff}e.add?.length&&({config:o}=a(o,{op:"add",roots:e.add})),C(i,o),f&&(this.log("Removed the last root \u2014 Codex capture is now OFF rather than silently capturing everything."),this.log("Use --all to go back to capturing every project.")),await this.show(i,r),this.log(""),this.log("Takes effect on the next sweep (within ~30s). No restart needed.")}async show(e,i){let r=await m({configDir:e});if(this.log(`Codex capture: ${u(r)}`),r.roots.length)for(let d of r.roots)this.log(` \u2022 ${d}`);this.log(`Config: ${i}`),r.error&&(this.log(""),this.log("This scope is FAILING CLOSED \u2014 nothing is being captured from Codex."),this.log("Fix the file, or run `rulemetric capture scope --clear` to start over.")),r.source==="env"&&(this.log(""),this.log("Set by environment variable, which outranks the config file."),this.log("Unset RULEMETRIC_CODEX_CAPTURE / RULEMETRIC_CODEX_ROOTS for the file to apply."))}};export{c as default};
@@ -1 +1 @@
1
- import{b as A,c as I}from"../chunk-V5U3E4BZ.js";import{a as L}from"../chunk-VLXCQ2DC.js";import"../chunk-I2DZGJRR.js";import{c as b,d as x,e as $}from"../chunk-MVM6OGAF.js";import"../chunk-KKDHD4XA.js";import"../chunk-SZ62CP55.js";import{a as E,b as H,d as X}from"../chunk-VX2GJCQ4.js";import{d as U}from"../chunk-OPUI7CM2.js";import"../chunk-MODFTCZY.js";import"../chunk-PJ3WHQ67.js";import"../chunk-N7ODX6PO.js";import{a as C}from"../chunk-PPKPCXJD.js";import"../chunk-IZTIYR5Q.js";import"../chunk-V44SRRYR.js";import"../chunk-U6XEU573.js";import"../chunk-VLOX6KOM.js";import"../chunk-3AV3GTMP.js";import{a as O,e as S}from"../chunk-H2ORWIEY.js";import{a as _,g,l as w}from"../chunk-O6C2UGBY.js";import{a as v}from"../chunk-ZLLER3HP.js";import{spawnSync as B}from"node:child_process";import{existsSync as D,readFileSync as G}from"node:fs";import{join as Y}from"node:path";var R=class u extends C{static{v(this,"Diagnostics")}static description='Diagnose capture / proxy / connectivity problems (e.g. a client-side "502 Bad Gateway")';static examples=["<%= config.bin %> diagnostics"];baseUrl(){return process.env.RULEMETRIC_API_URL??_().apiUrl??O}async checkDirect(){let o=process.env.HTTPS_PROXY,t=process.env.HTTP_PROXY;delete process.env.HTTPS_PROXY,delete process.env.HTTP_PROXY;let i=new AbortController,s=setTimeout(()=>i.abort(),8e3);try{return(await globalThis.fetch(`${this.baseUrl()}/health`,{signal:i.signal})).ok}catch{return!1}finally{clearTimeout(s),o!==void 0&&(process.env.HTTPS_PROXY=o),t!==void 0&&(process.env.HTTP_PROXY=t)}}configuredProxy(){if(process.env.HTTPS_PROXY)return process.env.HTTPS_PROXY;for(let o of["settings.local.json","settings.json"]){let t=Y(process.cwd(),".claude",o);if(D(t))try{let i=JSON.parse(G(t,"utf8"));if(i.env?.HTTPS_PROXY)return i.env.HTTPS_PROXY}catch{}}return null}checkThroughProxy(o){let t=B("curl",["-sS","-x",o,"--max-time","8","-o","/dev/null","-w","%{http_code}",`${this.baseUrl()}/health`],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});return t.error||typeof t.stdout!="string"?null:t.stdout.trim()==="200"}async run(){await this.parse(u);let o=process.version,t=this.configuredProxy(),i=t!=null,[s,p,P]=await Promise.all([this.checkDirect(),$(b),$(x)]),f=i&&t?this.checkThroughProxy(t):null,n=v((e,a,d)=>{let h=a===null?"\u2013":a?"[OK]":"[!!]";this.log(` ${h} ${e.padEnd(22)} ${d}`)},"line");this.log("RuleMetric diagnostics"),this.log(""),n("Node",!A(o),`${o}${A(o)?" (< 20.11 \u2014 breaks the bundled proxy)":""}`),n("API (direct)",s,`${this.baseUrl()}/health ${s?"reachable":"UNREACHABLE"}`),n("Authenticated",g(),g()?"yes":"no \u2014 run `rulemetric auth login`"),n("Proxy configured",i?!0:null,i?t:"no HTTPS_PROXY set"),i&&(n("Gateway :"+b,p,p?"listening":"NOT listening"),n("mitmproxy :"+x,P,P?"listening":"not listening (gateway should route direct)"),n("API (via proxy)",f,f===null?"inconclusive (curl unavailable)":f?"reachable":"FAILED \u2014 502/blocked through your proxy"));let l=U();n("claude CLI",l.claudeBin!=null,l.claudeBin??"not found \u2014 LLM features (grading, distill) will no-op"),n("codex CLI",l.codexBin!=null?!0:null,l.codexBin?`${l.codexBin}${l.codexConfiguredModel?` (model ${l.codexConfiguredModel})`:""}`:"not found \u2014 optional; enables the cross-vendor reviewer (evals validate-judge)");let r=null;if(g()&&s)try{r=await S("/api/workers/health")}catch{r=null}if(r){let e=r.worker;n("Worker",!!e.active,e.present?e.active?`online (last heartbeat ${e.ageSeconds??"?"}s ago${e.clientVersion?`, v${e.clientVersion}`:""})`:`NOT RUNNING \u2014 last heartbeat ${j(e.ageSeconds)} ago`:"never connected \u2014 no worker has ever reported in");let a=r.pending.reduce((d,h)=>d+h.count,0);if(a>0){let d=r.verdict.stuck.reduce((k,T)=>k+T.count,0),h=r.verdict.unclaimable.reduce((k,T)=>k+T.count,0);n("Job queue",d===0,`${a} pending`+(d>0?` \u2014 ${d} waiting on this worker`:"")+(h>0?` \u2014 ${h} need a worker with DATABASE_URL`:""))}else n("Job queue",!0,"empty")}else g()&&s&&n("Worker",null,"could not read /workers/health (older API?)");let y=L(process.cwd()),c=await H({configDir:w()}),M={claude_code:"session hooks (+ proxy for instruction linking)",codex:`worker transcript sync of ~/.codex/sessions \u2014 ${X(c)}`,cursor:"user hooks (~/.cursor/hooks.json)",copilot_agent:"workspace hooks",antigravity:"user hooks (~/.gemini/config/hooks.json)"};this.log(""),this.log(" Capture coverage (agents found on this machine):");for(let e of y)this.log(` \u2022 ${e.padEnd(15)} ${M[e]??"captured"}`);if(y.includes("codex"))if(c.error)this.log(` ! ${c.error}`);else if(c.mode==="allowlist")for(let e of c.roots)this.log(` \u21B3 ${e}`);else c.mode==="all"&&this.log(` \u21B3 scope it with ${Y(w(),E)} ({"codex":{"roots":["/path/to/repo"]}}) or RULEMETRIC_CODEX_CAPTURE=off`);r&&!r.worker.active&&y.includes("codex")&&c.mode!=="off"&&this.log(" ! Codex capture runs INSIDE the worker \u2014 it is stopped while the worker is down.");let m=I({nodeVersion:o,directApiOk:s,httpsProxySet:i,gatewayAlive:p,mitmproxyAlive:P,proxyPathOk:f});this.log("");let N=m.severity==="ok"?"[OK]":m.severity==="warn"?"[!!]":"[XX]";this.log(`${N} ${m.headline}`);for(let e of m.hints)this.log(` \u2022 ${e}`);if(r&&r.verdict.severity!=="ok"){let e=r.verdict.severity==="warn"?"[!!]":"[XX]";this.log(""),this.log(`${e} ${r.verdict.headline}`);for(let a of r.verdict.hints)this.log(` \u2022 ${a}`)}}};function j(u){if(u===null)return"never";if(u<90)return`${Math.round(u)}s`;let o=Math.round(u/60);return o<90?`${o}m`:`${Math.round(o/60)}h`}v(j,"formatAge");export{R as default};
1
+ import{b as A,c as U}from"../chunk-V5U3E4BZ.js";import{a as L}from"../chunk-VLXCQ2DC.js";import"../chunk-I2DZGJRR.js";import{e as T,f as E,g as x}from"../chunk-QWCEZEDO.js";import"../chunk-KKDHD4XA.js";import"../chunk-SZ62CP55.js";import{d as F,e as G}from"../chunk-ZYI66XKV.js";import"../chunk-RMDLJN4L.js";import{i as M,j as N,k as D,m as Y,n as B}from"../chunk-BL4BN6RU.js";import"../chunk-2ZAKZEXW.js";import{d as X}from"../chunk-NTKO4H2K.js";import"../chunk-KQCAELPN.js";import"../chunk-L2CFSMBC.js";import"../chunk-Z72VHGV7.js";import"../chunk-4L2ZEIRE.js";import"../chunk-CDY7TQFZ.js";import"../chunk-XRTZU7IZ.js";import"../chunk-B3BHB26P.js";import"../chunk-N7ODX6PO.js";import"../chunk-PJ3WHQ67.js";import"../chunk-G5BXZT6F.js";import"../chunk-HMMO27U4.js";import{a as O,b as I,d as H}from"../chunk-VX2GJCQ4.js";import{a as _}from"../chunk-PPKPCXJD.js";import"../chunk-IZTIYR5Q.js";import"../chunk-V44SRRYR.js";import"../chunk-U6XEU573.js";import"../chunk-VLOX6KOM.js";import"../chunk-3AV3GTMP.js";import{a as C,e as P}from"../chunk-H2ORWIEY.js";import{a as R,g as v,l as k}from"../chunk-O6C2UGBY.js";import{a as $}from"../chunk-ZLLER3HP.js";import{spawnSync as J}from"node:child_process";import{existsSync as q,readFileSync as K}from"node:fs";import{join as j}from"node:path";var S=class h extends _{static{$(this,"Diagnostics")}static description='Diagnose capture / proxy / connectivity problems (e.g. a client-side "502 Bad Gateway")';static examples=["<%= config.bin %> diagnostics"];baseUrl(){return process.env.RULEMETRIC_API_URL??R().apiUrl??C}async checkDirect(){let o=process.env.HTTPS_PROXY,i=process.env.HTTP_PROXY;delete process.env.HTTPS_PROXY,delete process.env.HTTP_PROXY;let t=new AbortController,a=setTimeout(()=>t.abort(),8e3);try{return(await globalThis.fetch(`${this.baseUrl()}/health`,{signal:t.signal})).ok}catch{return!1}finally{clearTimeout(a),o!==void 0&&(process.env.HTTPS_PROXY=o),i!==void 0&&(process.env.HTTP_PROXY=i)}}configuredProxy(){if(process.env.HTTPS_PROXY)return process.env.HTTPS_PROXY;for(let o of["settings.local.json","settings.json"]){let i=j(process.cwd(),".claude",o);if(q(i))try{let t=JSON.parse(K(i,"utf8"));if(t.env?.HTTPS_PROXY)return t.env.HTTPS_PROXY}catch{}}return null}checkThroughProxy(o){let i=J("curl",["-sS","-x",o,"--max-time","8","-o","/dev/null","-w","%{http_code}",`${this.baseUrl()}/health`],{encoding:"utf8",stdio:["ignore","pipe","ignore"]});return i.error||typeof i.stdout!="string"?null:i.stdout.trim()==="200"}async run(){await this.parse(h);let o=process.version,i=this.configuredProxy(),t=i!=null,[a,m,c]=await Promise.all([this.checkDirect(),x(T),x(E)]),u=t&&i?this.checkThroughProxy(i):null,e=$((n,g,p)=>{let f=g===null?"\u2013":g?"[OK]":"[!!]";this.log(` ${f} ${n.padEnd(22)} ${p}`)},"line");this.log("RuleMetric diagnostics"),this.log(""),e("Node",!A(o),`${o}${A(o)?" (< 20.11 \u2014 breaks the bundled proxy)":""}`),e("API (direct)",a,`${this.baseUrl()}/health ${a?"reachable":"UNREACHABLE"}`),e("Authenticated",v(),v()?"yes":"no \u2014 run `rulemetric auth login`"),e("Proxy configured",t?!0:null,t?i:"no HTTPS_PROXY set"),t&&(e("Gateway :"+T,m,m?"listening":"NOT listening"),e("mitmproxy :"+E,c,c?"listening":"not listening (gateway should route direct)"),e("API (via proxy)",u,u===null?"inconclusive (curl unavailable)":u?"reachable":"FAILED \u2014 502/blocked through your proxy"));let s=X();e("claude CLI",s.claudeBin!=null,s.claudeBin??"not found \u2014 LLM features (grading, distill) will no-op"),e("codex CLI",s.codexBin!=null?!0:null,s.codexBin?`${s.codexBin}${s.codexConfiguredModel?` (model ${s.codexConfiguredModel})`:""}`:"not found \u2014 optional; enables the cross-vendor reviewer (evals validate-judge)");let r=null;if(v()&&a)try{r=await P("/api/workers/health")}catch{r=null}if(r){let n=r.worker;e("Worker",!!n.active,n.present?n.active?`online (last heartbeat ${n.ageSeconds??"?"}s ago${n.clientVersion?`, v${n.clientVersion}`:""})`:`NOT RUNNING \u2014 last heartbeat ${z(n.ageSeconds)} ago`:"never connected \u2014 no worker has ever reported in");let g=r.pending.reduce((p,f)=>p+f.count,0);if(g>0){let p=r.verdict.stuck.reduce((b,w)=>b+w.count,0),f=r.verdict.unclaimable.reduce((b,w)=>b+w.count,0);e("Job queue",p===0,`${g} pending`+(p>0?` \u2014 ${p} waiting on this worker`:"")+(f>0?` \u2014 ${f} need a worker with DATABASE_URL`:""))}else e("Job queue",!0,"empty")}else v()&&a&&e("Worker",null,"could not read /workers/health (older API?)");let l=L(process.cwd()),d=await I({configDir:k()}),W={claude_code:"session hooks (+ proxy for instruction linking)",codex:`worker transcript sync of ~/.codex/sessions \u2014 ${H(d)}`,cursor:"user hooks (~/.cursor/hooks.json)",copilot_agent:"workspace hooks",antigravity:"user hooks (~/.gemini/config/hooks.json)"};this.log(""),this.log(" Capture coverage (agents found on this machine):");for(let n of l)this.log(` \u2022 ${n.padEnd(15)} ${W[n]??"captured"}`);if(l.includes("codex"))if(d.error)this.log(` ! ${d.error}`);else if(d.mode==="allowlist")for(let n of d.roots)this.log(` \u21B3 ${n}`);else d.mode==="all"&&this.log(` \u21B3 scope it with ${j(k(),O)} ({"codex":{"roots":["/path/to/repo"]}}) or RULEMETRIC_CODEX_CAPTURE=off`);r&&!r.worker.active&&l.includes("codex")&&d.mode!=="off"&&this.log(" ! Codex capture runs INSIDE the worker \u2014 it is stopped while the worker is down."),v()&&a&&await this.reportEvolutionSpend();let y=U({nodeVersion:o,directApiOk:a,httpsProxySet:t,gatewayAlive:m,mitmproxyAlive:c,proxyPathOk:u});this.log("");let V=y.severity==="ok"?"[OK]":y.severity==="warn"?"[!!]":"[XX]";this.log(`${V} ${y.headline}`);for(let n of y.hints)this.log(` \u2022 ${n}`);if(r&&r.verdict.severity!=="ok"){let n=r.verdict.severity==="warn"?"[!!]":"[XX]";this.log(""),this.log(`${n} ${r.verdict.headline}`);for(let g of r.verdict.hints)this.log(` \u2022 ${g}`)}}async reportEvolutionSpend(){let o;try{o=await P("/api/eval-targets?type=instruction&limit=200")}catch{return}let i=o.filter(t=>{let a=t.metadata??{};return a.autoEvolveEnabled===!0||a.autoEvolveEnabled==="true"});if(i.length!==0){this.log(""),this.log(" Nightly instruction evolution (cron_instruction_evolution, 07:30 UTC):");for(let t of i){let a=t.metadata??{},m=N(a),c=M(a);if(m){this.log(` \u2022 ${t.name} \u2014 PAUSED (metadata.autoEvolvePaused). Opt-in preserved.`),this.log(" \u21B3 resume: set autoEvolvePaused=false");continue}let u=null;try{u=(await P(`/api/eval-targets/${t.id}/evals`)).filter(s=>!s.retiredAt).length}catch{}if(this.log(` \u2022 ${t.name}`),u!=null){let e=G(u,c.minPairs,F(c,u));if(!e.feasible)this.log(` \u21B3 cannot reach a verdict \u2014 ${e.reason}`);else{let s=D({liveCases:u,passes:e.passes});this.log(` \u21B3 each night: ${B(s)}`)}}this.log(` \u21B3 pairs budget ${c.minPairs}`+(c.configured?" (metadata.autoEvolvePairs)":" (default)")+` \xB7 writes ${a.autoEvolveApply===!0||a.autoEvolveApply==="true"?"ENABLED":"off (dry run)"}`),c.note&&this.log(` ! ${c.note}`);try{let e=await P(`/api/eval-targets/${t.id}/promotions?limit=1`),s=e.promotions[0];if(s){let l=s.gates?.cost,d=l?.modelCalls?`${l.modelCalls} model calls, ${l.usablePairs??"?"} usable pair(s)`+(l.mde!=null?`, resolved +/-${Y(l.mde)}`:"")+(l.wallMs?`, ${(l.wallMs/6e4).toFixed(0)} min`:""):"cost not recorded (decision predates cost tracking)";this.log(` \u21B3 last run ${new Date(s.createdAt).toISOString().slice(0,10)}: ${s.decision}${s.applied?" (APPLIED)":""} \u2014 ${d}`)}let r=e.counts??{};this.log(` \u21B3 lifetime: ${r.promote??0} promote / ${r.revert??0} revert / ${r.refuse??0} refuse`)}catch{}}this.log(" \u21B3 pause the spend: metadata.autoEvolvePaused=true (keeps the opt-in)")}}};function z(h){if(h===null)return"never";if(h<90)return`${Math.round(h)}s`;let o=Math.round(h/60);return o<90?`${o}m`:`${Math.round(o/60)}h`}$(z,"formatAge");export{S as default};
@@ -1,3 +1,3 @@
1
- import{a as C,b as L,c as D}from"../../chunk-3HSEVXMQ.js";import{e as I}from"../../chunk-VXIRJ7YY.js";import"../../chunk-TIOKY2IA.js";import"../../chunk-LEXVC7VH.js";import"../../chunk-W2MOTOQE.js";import"../../chunk-3FJT6LL4.js";import"../../chunk-DAGDGAPU.js";import"../../chunk-6QKI756T.js";import"../../chunk-RSKQRVPJ.js";import"../../chunk-JEBHSV2M.js";import"../../chunk-UF6US7VU.js";import"../../chunk-L5ORQB25.js";import"../../chunk-E3MQVVH6.js";import"../../chunk-WEF5LPGS.js";import"../../chunk-N7TGRFVZ.js";import{j as d}from"../../chunk-3DLVY7LD.js";import"../../chunk-ZAWAPLIE.js";import"../../chunk-AIEM6VXO.js";import"../../chunk-BZUIMHHT.js";import"../../chunk-QFVGUZDO.js";import"../../chunk-ZL4MZMUK.js";import"../../chunk-5RBLIVBF.js";import"../../chunk-5W55CRBJ.js";import"../../chunk-JR4CWY3J.js";import"../../chunk-ZERPMWRT.js";import"../../chunk-UR6GZGFK.js";import"../../chunk-ZWKKFAIX.js";import"../../chunk-YQ56FQEO.js";import"../../chunk-JGYCLDYF.js";import"../../chunk-TDD7IOV2.js";import"../../chunk-MODXEGCU.js";import"../../chunk-7DFNBRLY.js";import"../../chunk-4VZLIGMS.js";import"../../chunk-3VYV6ZYB.js";import"../../chunk-OZQV5CDT.js";import"../../chunk-6UEFCMR2.js";import"../../chunk-CJRYYV76.js";import"../../chunk-BSJBNOJT.js";import"../../chunk-L2CFSMBC.js";import"../../chunk-Z72VHGV7.js";import"../../chunk-7AZKPX2J.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-V5MJ4ICC.js";import"../../chunk-WKXTY5AM.js";import"../../chunk-HMMO27U4.js";import{b as k,d as h,e as A}from"../../chunk-VX2GJCQ4.js";import"../../chunk-OPUI7CM2.js";import"../../chunk-MODFTCZY.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-N7ODX6PO.js";import{a as O}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{f as b}from"../../chunk-H2ORWIEY.js";import{e as P,l as f}from"../../chunk-O6C2UGBY.js";import{a as e}from"../../chunk-ZLLER3HP.js";import{trace as se,context as ie}from"@opentelemetry/api";import{NodeSDK as j}from"@opentelemetry/sdk-node";import{OTLPTraceExporter as q}from"@opentelemetry/exporter-trace-otlp-http";import{BatchSpanProcessor as F,ConsoleSpanExporter as U,SimpleSpanProcessor as X}from"@opentelemetry/sdk-trace-node";import{Resource as B}from"@opentelemetry/resources";import{ATTR_SERVICE_NAME as H,ATTR_SERVICE_VERSION as K}from"@opentelemetry/semantic-conventions";function $(t){if(!t)return{};let r={};for(let n of t.split(",")){let s=n.indexOf("=");if(s===-1)continue;let i=n.slice(0,s).trim(),a=n.slice(s+1).trim();i&&(r[i]=a)}return r}e($,"parseOtlpHeaders");var p=null;function y(){return process.env.TELEMETRY_ENABLED!=="false"}e(y,"isTelemetryEnabled");function S(t){if(!y()||p!==null)return"off";let r=new B({[H]:t.serviceName,[K]:t.serviceVersion??"0.1.0"}),n=process.env.OTEL_EXPORTER_OTLP_ENDPOINT,s,i;if(n){let a=$(process.env.OTEL_EXPORTER_OTLP_HEADERS),l=new q({url:`${n}/v1/traces`,headers:a});i=new F(l),s="otlp"}else if(process.env.OTEL_SPAN_EXPORT==="none")i=void 0,s="silent";else{let a=new U;i=new X(a),s="console"}return p=new j({resource:r,spanProcessors:i?[i]:[]}),p.start(),s}e(S,"initTelemetry");async function m(){p&&(await p.shutdown(),p=null)}e(m,"shutdownTelemetry");import{SpanKind as he,SpanStatusCode as ye}from"@opentelemetry/api";import{trace as ve,context as we}from"@opentelemetry/api";import*as u from"@sentry/node";var E=!1;function T(t){if(E)return!1;let r=process.env.SENTRY_DSN;return r?(u.init({dsn:r,serverName:t.serviceName,environment:process.env.NODE_ENV??"development",tracesSampleRate:0}),E=!0,!0):!1}e(T,"initSentry");async function g(t){E&&await u.flush(t)}e(g,"flushSentry");import{existsSync as J,mkdirSync as W,readFileSync as R,unlinkSync as V,writeFileSync as M}from"node:fs";import{dirname as z,join as v}from"node:path";import{execFileSync as Q}from"node:child_process";var c=v(f(),"evals-agent.lock");function Z(t){try{return process.kill(t,0),!0}catch(r){return r.code==="EPERM"}}e(Z,"pidAlive");function ee(t){if(!Z(t))return!1;try{let r=Q("ps",["-p",String(t),"-o","command="],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]});return/run\.js\s+evals\s+agent|evals\s+agent/.test(r)}catch{return!0}}e(ee,"isLiveAgent");function te(){try{W(z(c),{recursive:!0})}catch{}for(let t=0;t<2;t++)try{return M(c,String(process.pid),{flag:"wx"}),{ok:!0}}catch(r){if(r.code!=="EEXIST")throw r;let n=0;try{n=Number(R(c,"utf-8").trim())}catch{}if(n&&n!==process.pid&&ee(n))return{ok:!1,holder:n};try{V(c)}catch{}}try{M(c,String(process.pid))}catch{}return{ok:!0}}e(te,"acquireAgentLock");function x(){try{J(c)&&Number(R(c,"utf-8").trim())===process.pid&&V(c)}catch{}}e(x,"releaseAgentLock");var w=class t extends O{static{e(this,"EvalAgentCommand")}static description="The worker daemon: long-polls /api/work/next, claims jobs, and runs them locally. Installed as a launchd service by `rulemetric service install`.";static examples=["<%= config.bin %> evals agent"];async run(){await this.parse(t),this.requireAuth();let r=te();if(!r.ok){this.log(`Another rulemetric evals agent is already running (pid ${r.holder}). Refusing to start a second instance.`);return}process.env.PG_APPLICATION_NAME||="rulemetric-agent",T({serviceName:"rulemetric-agent"})&&this.log("[sentry] error capture enabled");let s=S({serviceName:"rulemetric-agent"});s==="otlp"?this.log(`[otel] traces exporting to ${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}`):s==="console"?this.log("[otel] cron spans printing to stdout (set OTEL_EXPORTER_OTLP_ENDPOINT to ship to a backend)"):this.log("[otel] disabled (TELEMETRY_ENABLED=false)"),!P()&&!process.env.RULEMETRIC_API_KEY&&this.error("No auth token found. Run `rulemetric auth login` first."),this.log("Starting thin agent (Phase 4b parallel-run)..."),this.log(`Long-polling /api/work/next. Press Ctrl+C to stop.
1
+ import{a as C,b as L,c as D}from"../../chunk-3HSEVXMQ.js";import{e as I}from"../../chunk-6NML7IVJ.js";import"../../chunk-TIOKY2IA.js";import"../../chunk-ZYVWALMS.js";import"../../chunk-NKPLTT7J.js";import"../../chunk-HUADECKZ.js";import"../../chunk-TVHT6H42.js";import"../../chunk-QFVGUZDO.js";import"../../chunk-H7J27U4P.js";import"../../chunk-BUWWFHGO.js";import"../../chunk-IQTSUAGM.js";import"../../chunk-CRIFP3QP.js";import"../../chunk-MDPN46EY.js";import"../../chunk-RSKQRVPJ.js";import"../../chunk-SWSGNEVO.js";import"../../chunk-BPQ66YTY.js";import"../../chunk-UF6US7VU.js";import"../../chunk-DKGKOSW3.js";import"../../chunk-IXLDCX7M.js";import"../../chunk-JIJKIPE6.js";import"../../chunk-5RBLIVBF.js";import"../../chunk-ZL4MZMUK.js";import"../../chunk-N7TGRFVZ.js";import{j as d}from"../../chunk-JGLVVIEM.js";import"../../chunk-Q4APAZUC.js";import"../../chunk-YQ56FQEO.js";import"../../chunk-TDD7IOV2.js";import"../../chunk-MODXEGCU.js";import"../../chunk-5DIOZDDZ.js";import"../../chunk-4VZLIGMS.js";import"../../chunk-CNOD6HWU.js";import"../../chunk-X64R6JCJ.js";import"../../chunk-6UEFCMR2.js";import"../../chunk-ZYI66XKV.js";import"../../chunk-RMDLJN4L.js";import"../../chunk-BL4BN6RU.js";import"../../chunk-2ZAKZEXW.js";import"../../chunk-NTKO4H2K.js";import"../../chunk-CJRYYV76.js";import"../../chunk-KQCAELPN.js";import"../../chunk-L2CFSMBC.js";import"../../chunk-Z72VHGV7.js";import"../../chunk-4L2ZEIRE.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-XRTZU7IZ.js";import"../../chunk-B3BHB26P.js";import"../../chunk-N7ODX6PO.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-G5BXZT6F.js";import"../../chunk-HMMO27U4.js";import{b as k,d as h,e as A}from"../../chunk-VX2GJCQ4.js";import{a as O}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{f as b}from"../../chunk-H2ORWIEY.js";import{e as P,l as f}from"../../chunk-O6C2UGBY.js";import{a as e}from"../../chunk-ZLLER3HP.js";import{trace as se,context as ie}from"@opentelemetry/api";import{NodeSDK as j}from"@opentelemetry/sdk-node";import{OTLPTraceExporter as q}from"@opentelemetry/exporter-trace-otlp-http";import{BatchSpanProcessor as F,ConsoleSpanExporter as U,SimpleSpanProcessor as X}from"@opentelemetry/sdk-trace-node";import{Resource as B}from"@opentelemetry/resources";import{ATTR_SERVICE_NAME as H,ATTR_SERVICE_VERSION as K}from"@opentelemetry/semantic-conventions";function $(t){if(!t)return{};let r={};for(let n of t.split(",")){let s=n.indexOf("=");if(s===-1)continue;let i=n.slice(0,s).trim(),a=n.slice(s+1).trim();i&&(r[i]=a)}return r}e($,"parseOtlpHeaders");var p=null;function y(){return process.env.TELEMETRY_ENABLED!=="false"}e(y,"isTelemetryEnabled");function S(t){if(!y()||p!==null)return"off";let r=new B({[H]:t.serviceName,[K]:t.serviceVersion??"0.1.0"}),n=process.env.OTEL_EXPORTER_OTLP_ENDPOINT,s,i;if(n){let a=$(process.env.OTEL_EXPORTER_OTLP_HEADERS),l=new q({url:`${n}/v1/traces`,headers:a});i=new F(l),s="otlp"}else if(process.env.OTEL_SPAN_EXPORT==="none")i=void 0,s="silent";else{let a=new U;i=new X(a),s="console"}return p=new j({resource:r,spanProcessors:i?[i]:[]}),p.start(),s}e(S,"initTelemetry");async function m(){p&&(await p.shutdown(),p=null)}e(m,"shutdownTelemetry");import{SpanKind as he,SpanStatusCode as ye}from"@opentelemetry/api";import{trace as ve,context as we}from"@opentelemetry/api";import*as u from"@sentry/node";var E=!1;function T(t){if(E)return!1;let r=process.env.SENTRY_DSN;return r?(u.init({dsn:r,serverName:t.serviceName,environment:process.env.NODE_ENV??"development",tracesSampleRate:0}),E=!0,!0):!1}e(T,"initSentry");async function g(t){E&&await u.flush(t)}e(g,"flushSentry");import{existsSync as J,mkdirSync as W,readFileSync as R,unlinkSync as V,writeFileSync as M}from"node:fs";import{dirname as z,join as v}from"node:path";import{execFileSync as Q}from"node:child_process";var c=v(f(),"evals-agent.lock");function Z(t){try{return process.kill(t,0),!0}catch(r){return r.code==="EPERM"}}e(Z,"pidAlive");function ee(t){if(!Z(t))return!1;try{let r=Q("ps",["-p",String(t),"-o","command="],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]});return/run\.js\s+evals\s+agent|evals\s+agent/.test(r)}catch{return!0}}e(ee,"isLiveAgent");function te(){try{W(z(c),{recursive:!0})}catch{}for(let t=0;t<2;t++)try{return M(c,String(process.pid),{flag:"wx"}),{ok:!0}}catch(r){if(r.code!=="EEXIST")throw r;let n=0;try{n=Number(R(c,"utf-8").trim())}catch{}if(n&&n!==process.pid&&ee(n))return{ok:!1,holder:n};try{V(c)}catch{}}try{M(c,String(process.pid))}catch{}return{ok:!0}}e(te,"acquireAgentLock");function x(){try{J(c)&&Number(R(c,"utf-8").trim())===process.pid&&V(c)}catch{}}e(x,"releaseAgentLock");var w=class t extends O{static{e(this,"EvalAgentCommand")}static description="The worker daemon: long-polls /api/work/next, claims jobs, and runs them locally. Installed as a launchd service by `rulemetric service install`.";static examples=["<%= config.bin %> evals agent"];async run(){await this.parse(t),this.requireAuth();let r=te();if(!r.ok){this.log(`Another rulemetric evals agent is already running (pid ${r.holder}). Refusing to start a second instance.`);return}process.env.PG_APPLICATION_NAME||="rulemetric-agent",T({serviceName:"rulemetric-agent"})&&this.log("[sentry] error capture enabled");let s=S({serviceName:"rulemetric-agent"});s==="otlp"?this.log(`[otel] traces exporting to ${process.env.OTEL_EXPORTER_OTLP_ENDPOINT}`):s==="console"?this.log("[otel] cron spans printing to stdout (set OTEL_EXPORTER_OTLP_ENDPOINT to ship to a backend)"):this.log("[otel] disabled (TELEMETRY_ENABLED=false)"),!P()&&!process.env.RULEMETRIC_API_KEY&&this.error("No auth token found. Run `rulemetric auth login` first."),this.log("Starting thin agent (Phase 4b parallel-run)..."),this.log(`Long-polling /api/work/next. Press Ctrl+C to stop.
2
2
  `);let a=new AbortController,l=await k({configDir:f()});if(this.log(`[transcript-sync] Codex capture: ${h(l)}`),l.error)this.log(`[transcript-sync] WARNING: ${l.error}`);else if(l.mode==="allowlist")for(let o of l.roots)this.log(`[transcript-sync] \u2022 ${o}`);let G=new C({providers:[L(void 0,void 0,A({configDir:f(),onChange:e(o=>this.log(`[transcript-sync] Codex capture changed: ${h(o)}`),"onChange")}))],statePath:v(f(),"transcript-sync-state.json"),importTranscript:e(o=>b("/api/sessions/import",o),"importTranscript"),log:e(o=>this.log(`[transcript-sync] ${o}`),"log")});D(G,{signal:a.signal,log:e(o=>this.log(`[transcript-sync] ${o}`),"log")});let N=e(async o=>{this.log(`
3
3
  [${o}] shutting down agent...`),a.abort(),await Promise.allSettled([g(2e3),m(),d()]),x(),process.exit(0)},"shutdown");process.on("SIGINT",()=>{N("SIGINT")}),process.on("SIGTERM",()=>{N("SIGTERM")});let _=!1;try{await I({signal:a.signal,log:e(o=>this.log(o),"log"),version:this.config.version,readInstalledVersion:e(()=>{try{return JSON.parse(R(v(this.config.root,"package.json"),"utf-8")).version??null}catch{return null}},"readInstalledVersion"),onVersionDrift:e(()=>{_=!0},"onVersionDrift")}),_&&(this.log("[upgrade] Installed CLI version changed \u2014 restarting worker onto the new code."),await Promise.allSettled([g(2e3),m(),d()]),x(),process.exit(1))}finally{x(),await d()}}};export{w as default};
@@ -1,4 +1,4 @@
1
- import{a as k}from"../../chunk-CJRYYV76.js";import{b as $}from"../../chunk-BSJBNOJT.js";import"../../chunk-L2CFSMBC.js";import"../../chunk-Z72VHGV7.js";import"../../chunk-7AZKPX2J.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-V5MJ4ICC.js";import"../../chunk-HMMO27U4.js";import"../../chunk-MODFTCZY.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-N7ODX6PO.js";import{a as w}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as n}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as h}from"../../chunk-ZLLER3HP.js";import{Args as A,Flags as r}from"@oclif/core";var m=class y extends w{static{h(this,"EvalAutoRun")}static description="Run evals in a loop until the effect verdict is statistically powered (\xA76f auto-run-to-power)";static examples=["<%= config.bin %> evals auto-run <target-id> # preview (cost + plan)","<%= config.bin %> evals auto-run <target-id> --yes # run until powered / budget","<%= config.bin %> evals auto-run <target-id> --yes --max-runs 120 --batch-parallel 4"];static args={targetId:A.string({description:"Eval target ID",required:!0})};static flags={yes:r.boolean({char:"y",description:"Actually run. Without this, only previews the plan + cost."}),"max-runs":r.integer({description:"Hard ceiling on completed runs",default:200}),"batch-parallel":r.integer({description:"Concurrent executions within a batch",default:3}),timeout:r.integer({description:"Timeout per eval in ms",default:12e4}),model:r.string({description:"Model for eval execution"}),"grader-model":r.string({description:"Model for grading"}),"skip-baseline":r.boolean({description:"Skip without_target runs (no delta \u2014 not recommended)",default:!1})};async run(){let{args:C,flags:e}=await this.parse(y);this.requireAuth();let i=C.targetId,c=20,a=await n(`/api/eval-targets/${i}`),l=await n(`/api/eval-targets/${i}/evals`);l.length===0&&this.error(`No active cases on "${a.name}". Generate some (\`evals create\` / the web Generate button) or run \`evals refine-cases\` first.`);let b=l.length*(e["skip-baseline"]?1:2),f=Math.ceil(e["max-runs"]/b);if(this.log(`Auto-run "${a.name}" v${a.version} toward a powered \xB1${c}pp verdict.`),this.log(`Plan: up to ${e["max-runs"]} runs (${l.length} active case(s) \xD7 ${e["skip-baseline"]?1:2}/batch = ${b}/batch, \u2264${f} batches). Each run is a synthetic \`claude -p\` execution + grade.`),this.log('Note: this is a controlled synthetic A/B. For a DEPLOYED instruction with real usage, the Insights observational verdict is cheaper and uses real sessions \u2014 auto-run is for pre-deploy, catalog skills, or targets with no real "without" cohort.'),!e.yes){this.log(`
1
+ import{a as k}from"../../chunk-CJRYYV76.js";import{b as $}from"../../chunk-KQCAELPN.js";import"../../chunk-L2CFSMBC.js";import"../../chunk-Z72VHGV7.js";import"../../chunk-4L2ZEIRE.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-XRTZU7IZ.js";import"../../chunk-B3BHB26P.js";import"../../chunk-N7ODX6PO.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-HMMO27U4.js";import{a as w}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as n}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as h}from"../../chunk-ZLLER3HP.js";import{Args as A,Flags as r}from"@oclif/core";var m=class y extends w{static{h(this,"EvalAutoRun")}static description="Run evals in a loop until the effect verdict is statistically powered (\xA76f auto-run-to-power)";static examples=["<%= config.bin %> evals auto-run <target-id> # preview (cost + plan)","<%= config.bin %> evals auto-run <target-id> --yes # run until powered / budget","<%= config.bin %> evals auto-run <target-id> --yes --max-runs 120 --batch-parallel 4"];static args={targetId:A.string({description:"Eval target ID",required:!0})};static flags={yes:r.boolean({char:"y",description:"Actually run. Without this, only previews the plan + cost."}),"max-runs":r.integer({description:"Hard ceiling on completed runs",default:200}),"batch-parallel":r.integer({description:"Concurrent executions within a batch",default:3}),timeout:r.integer({description:"Timeout per eval in ms",default:12e4}),model:r.string({description:"Model for eval execution"}),"grader-model":r.string({description:"Model for grading"}),"skip-baseline":r.boolean({description:"Skip without_target runs (no delta \u2014 not recommended)",default:!1})};async run(){let{args:C,flags:e}=await this.parse(y);this.requireAuth();let i=C.targetId,c=20,a=await n(`/api/eval-targets/${i}`),l=await n(`/api/eval-targets/${i}/evals`);l.length===0&&this.error(`No active cases on "${a.name}". Generate some (\`evals create\` / the web Generate button) or run \`evals refine-cases\` first.`);let b=l.length*(e["skip-baseline"]?1:2),f=Math.ceil(e["max-runs"]/b);if(this.log(`Auto-run "${a.name}" v${a.version} toward a powered \xB1${c}pp verdict.`),this.log(`Plan: up to ${e["max-runs"]} runs (${l.length} active case(s) \xD7 ${e["skip-baseline"]?1:2}/batch = ${b}/batch, \u2264${f} batches). Each run is a synthetic \`claude -p\` execution + grade.`),this.log('Note: this is a controlled synthetic A/B. For a DEPLOYED instruction with real usage, the Insights observational verdict is cheaper and uses real sessions \u2014 auto-run is for pre-deploy, catalog skills, or targets with no real "without" cohort.'),!e.yes){this.log(`
2
2
  Preview only. Re-run with --yes to start.`);return}let t={runsCompleted:0,maxRuns:e["max-runs"],batchesRun:0,maxBatches:f},x={targetId:i,targetVersion:a.version,iteration:1,timeout:e.timeout,model:e.model,graderModel:e["grader-model"],skipGrading:!1,targetType:a.type,targetName:a.name};for(;;){let s;try{s=await n(`/api/eval-targets/${i}/judge-calibration`)}catch(o){this.log(`
3
3
  \u25A0 stopping \u2014 could not read the power check: ${o instanceof Error?o.message:String(o)}`);break}let E={powered:s.powerCheck?.powered??!1,mde:s.powerCheck?.mde==null?1/0:s.powerCheck.mde},B=s.caseDiscrimination??{total:0,discriminating:0,nonDiscriminating:0,unpaired:0},p=k(E,B,t,{targetEffectPp:c});if(this.log(`
4
4
  ${p.action==="stop"?"\u25A0":"\u25B8"} ${p.reason}`),p.action==="stop")break;let v=await n(`/api/eval-targets/${i}/evals`);if(v.length===0){this.log("\u25A0 no active cases left \u2014 stopping.");break}let{completed:g,failed:D}=await $({cases:v,targetContent:a.content,concurrency:e["batch-parallel"],runNumber:t.batchesRun+1,opts:x,skipBaseline:e["skip-baseline"],onLog:h(o=>this.log(o),"onLog")});if(t.runsCompleted+=g,t.batchesRun+=1,this.log(`Batch ${t.batchesRun}: ${g} completed, ${D} failed \u2014 ${t.runsCompleted}/${t.maxRuns} runs, ${t.batchesRun}/${t.maxBatches} batches.`),g===0){this.log("\u25A0 batch produced 0 completed runs \u2014 the executor appears broken (check the model / `claude -p`). Aborting.");break}}let d=await n(`/api/eval-targets/${i}/judge-calibration`),u=d.powerCheck?.mde,R=u==null||!Number.isFinite(u)?"unknown":`\xB1${Math.round(u*100)}pp`;this.log(`
@@ -1,4 +1,4 @@
1
- import{b as h,c as f}from"../../chunk-LETTPEG4.js";import"../../chunk-WKXTY5AM.js";import{a as m}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as c}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as u}from"../../chunk-ZLLER3HP.js";import{Args as p,Flags as v}from"@oclif/core";var d=class b extends m{static{u(this,"EvalBenchmarkCommand")}static description="Aggregate eval runs into a benchmark for a target";static examples=["<%= config.bin %> evals benchmark <target-id>","<%= config.bin %> evals benchmark <target-id> --iteration 2"];static args={targetId:p.string({description:"Eval target ID",required:!0})};static flags={iteration:v.integer({description:"Filter runs by iteration",default:1})};async run(){let{args:o,flags:l}=await this.parse(b);this.requireAuth();let g=await c(`/api/eval-targets/${o.targetId}`);this.log(`Aggregating benchmark for "${g.name}" v${g.version}, iteration ${l.iteration}`);let a=await h(o.targetId,l.iteration);a.totalRuns===0&&this.error("No completed runs found. Run evals first with `rulemetric evals run`."),this.log(`
1
+ import{b as h,c as f}from"../../chunk-VSUL3MNG.js";import"../../chunk-G5BXZT6F.js";import{a as m}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as c}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as u}from"../../chunk-ZLLER3HP.js";import{Args as p,Flags as v}from"@oclif/core";var d=class b extends m{static{u(this,"EvalBenchmarkCommand")}static description="Aggregate eval runs into a benchmark for a target";static examples=["<%= config.bin %> evals benchmark <target-id>","<%= config.bin %> evals benchmark <target-id> --iteration 2"];static args={targetId:p.string({description:"Eval target ID",required:!0})};static flags={iteration:v.integer({description:"Filter runs by iteration",default:1})};async run(){let{args:o,flags:l}=await this.parse(b);this.requireAuth();let g=await c(`/api/eval-targets/${o.targetId}`);this.log(`Aggregating benchmark for "${g.name}" v${g.version}, iteration ${l.iteration}`);let a=await h(o.targetId,l.iteration);a.totalRuns===0&&this.error("No completed runs found. Run evals first with `rulemetric evals run`."),this.log(`
2
2
  Aggregated ${a.totalRuns} runs
3
3
  `);for(let[e,n]of Object.entries(a.runSummary)){this.log(`${e}:`);for(let[r,i]of Object.entries(n)){let s=i;this.log(` ${r}: mean=${s.mean} stddev=${s.stddev} [${s.min}, ${s.max}]`)}}let t=a.verdict;if(t)if(this.log(`
4
4
  Verdict (${t.mode}, baseline=${t.baseline}):`),!t.sufficient)this.log(` ${t.insufficientReason??"insufficient data"} \u2014 no effect claimed`);else{let e=t.delta>=0?"+":"";this.log(` pass-rate delta: ${e}${(t.delta*100).toFixed(0)}% (n=${t.nWith} paired)`),this.log(` 95% CI: ${(t.ci.lower*100).toFixed(0)}\u2013${(t.ci.upper*100).toFixed(0)}%`),t.pValue!=null&&this.log(` McNemar p: ${t.pValue.toFixed(4)}`),this.log(` significant: ${t.significant?"YES":"no"}`)}if(a.notes.length>0){this.log(`
@@ -1,4 +1,4 @@
1
- import{b as P,c as C}from"../../chunk-QH7PCQHM.js";import{a as V}from"../../chunk-4VZLIGMS.js";import{a as N}from"../../chunk-7AZKPX2J.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-V5MJ4ICC.js";import"../../chunk-WKXTY5AM.js";import{c as F}from"../../chunk-HMMO27U4.js";import"../../chunk-MODFTCZY.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-N7ODX6PO.js";import{a as A}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as w,f as m,g as S}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as k}from"../../chunk-ZLLER3HP.js";import{createInterface as _}from"node:readline/promises";import{Args as q,Flags as g}from"@oclif/core";var $=class O extends A{static{k(this,"EvalOptimizeCommand")}static description="Iteratively optimize eval target content using eval results as feedback";static examples=["<%= config.bin %> evals optimize <target-id>","<%= config.bin %> evals optimize <target-id> --auto --max-iterations 3"];static args={targetId:q.string({description:"Eval target ID",required:!0})};static flags={auto:g.boolean({description:"Skip interactive review, apply suggestions automatically",default:!1}),"max-iterations":g.integer({description:"Maximum optimization iterations",default:5}),threshold:g.string({description:"Stop if pass rate reaches this threshold (0-1)",default:"0.95"}),model:g.string({description:"Model for eval execution"}),"analyzer-model":g.string({description:"Model for analysis/suggestions"}),timeout:g.integer({description:"Timeout per eval in ms",default:12e4})};async run(){let{args:n,flags:e}=await this.parse(O);this.requireAuth();let t=await w(`/api/eval-targets/${n.targetId}`),i=await w(`/api/eval-targets/${n.targetId}/evals`);i.length===0&&this.error("No evals found. Create some first with `rulemetric evals create`.");let s=[...i].sort(()=>Math.random()-.5),c=Math.ceil(s.length*.6),u=s.slice(0,c),d=s.slice(c);this.log(`Optimizing "${t.name}" v${t.version}`),this.log(`Evals: ${u.length} train, ${d.length} test`);let h=parseFloat(e.threshold);this.log(`Config: max ${e["max-iterations"]} iterations, threshold ${(h*100).toFixed(0)}%`),e.auto&&this.log("Mode: auto (no interactive review)"),this.log("");let T=t.version,f=0,x=0;for(let l=1;l<=e["max-iterations"];l++){this.log(`
1
+ import{b as P,c as C}from"../../chunk-MQ47NLPC.js";import{a as V}from"../../chunk-4VZLIGMS.js";import{a as N}from"../../chunk-4L2ZEIRE.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-XRTZU7IZ.js";import"../../chunk-B3BHB26P.js";import"../../chunk-N7ODX6PO.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-G5BXZT6F.js";import{c as F}from"../../chunk-HMMO27U4.js";import{a as A}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as w,f as m,g as S}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as k}from"../../chunk-ZLLER3HP.js";import{createInterface as _}from"node:readline/promises";import{Args as q,Flags as g}from"@oclif/core";var $=class O extends A{static{k(this,"EvalOptimizeCommand")}static description="Iteratively optimize eval target content using eval results as feedback";static examples=["<%= config.bin %> evals optimize <target-id>","<%= config.bin %> evals optimize <target-id> --auto --max-iterations 3"];static args={targetId:q.string({description:"Eval target ID",required:!0})};static flags={auto:g.boolean({description:"Skip interactive review, apply suggestions automatically",default:!1}),"max-iterations":g.integer({description:"Maximum optimization iterations",default:5}),threshold:g.string({description:"Stop if pass rate reaches this threshold (0-1)",default:"0.95"}),model:g.string({description:"Model for eval execution"}),"analyzer-model":g.string({description:"Model for analysis/suggestions"}),timeout:g.integer({description:"Timeout per eval in ms",default:12e4})};async run(){let{args:n,flags:e}=await this.parse(O);this.requireAuth();let t=await w(`/api/eval-targets/${n.targetId}`),i=await w(`/api/eval-targets/${n.targetId}/evals`);i.length===0&&this.error("No evals found. Create some first with `rulemetric evals create`.");let s=[...i].sort(()=>Math.random()-.5),c=Math.ceil(s.length*.6),u=s.slice(0,c),d=s.slice(c);this.log(`Optimizing "${t.name}" v${t.version}`),this.log(`Evals: ${u.length} train, ${d.length} test`);let h=parseFloat(e.threshold);this.log(`Config: max ${e["max-iterations"]} iterations, threshold ${(h*100).toFixed(0)}%`),e.auto&&this.log("Mode: auto (no interactive review)"),this.log("");let T=t.version,f=0,x=0;for(let l=1;l<=e["max-iterations"];l++){this.log(`
2
2
  === Iteration ${l} ===`),this.log("Running train evals...");let b=await this.runEvalsOnTarget(t,u,e),p=this.computePassRate(b);if(this.log(`Train pass rate: ${(p*100).toFixed(1)}%`),p>=h){this.log(`Train score ${(p*100).toFixed(1)}% >= threshold ${(h*100).toFixed(0)}%. Stopping.`);let o=await this.runEvalsOnTarget(t,d,e),z=this.computePassRate(o);this.log(`Final test score: ${(z*100).toFixed(1)}%`),await m("/api/optimization-runs",{evalTargetId:t.id,type:"content",iteration:l,inputVersion:t.version,trainScore:p,testScore:z,analysis:{reason:"threshold_reached"},status:"completed"});break}this.log("Analyzing results...");let M=b.map(o=>({evalName:o.evalName,prompt:o.prompt,expectations:o.expectations,grading:o.grading})),a=await V({content:t.content,evalResults:M,model:e["analyzer-model"]??e.model,timeout:e.timeout});this.log(`
3
3
  Assessment: ${a.overallAssessment}`),this.log(`Suggestions: ${a.suggestions.length}`);for(let o of a.suggestions)this.log(` - [${o.section}] ${o.reasoning}`);if(a.proposedContent===t.content){this.log("No changes proposed. Stopping."),await m("/api/optimization-runs",{evalTargetId:t.id,type:"content",iteration:l,inputVersion:t.version,trainScore:p,analysis:{reason:"no_changes"},status:"completed"});break}if(!e.auto&&!await this.confirm(`
4
4
  Apply the proposed changes as a new version? [y/N] `)){this.log("Changes not applied. Stopping."),await m("/api/optimization-runs",{evalTargetId:t.id,type:"content",iteration:l,inputVersion:t.version,trainScore:p,analysis:{reason:"user_declined",suggestions:a.suggestions},status:"completed"});break}let r=await S(`/api/eval-targets/${t.id}`,{content:a.proposedContent});this.log(`Created v${r.version}`),this.log(`Running test evals on v${t.version} (baseline) and v${r.version}...`);let E=await this.runEvalsOnTarget(t,d,e),R=await this.runEvalsOnTarget(r,d,e),v=this.computePassRate(R),I=this.computePassRate(E);this.log(`Test pass rate: v${t.version} ${(I*100).toFixed(1)}% \u2192 v${r.version} ${(v*100).toFixed(1)}%`);let y=P(E,R);if(y&&this.log(C(y,t.version,r.version)),await m("/api/optimization-runs",{evalTargetId:t.id,type:"content",iteration:l,inputVersion:t.version,outputVersion:r.version,trainScore:p,testScore:v,analysis:{suggestions:a.suggestions,overallAssessment:a.overallAssessment,priorTestScore:I,verdict:y},status:"completed"}),v>f)f=v,T=r.version,x=0;else if(x++,x>=2){this.log("No improvement for 2 consecutive iterations. Stopping.");break}t=r}this.log(`
@@ -1,4 +1,4 @@
1
- import{b as w}from"../../chunk-3VYV6ZYB.js";import"../../chunk-MODFTCZY.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-N7ODX6PO.js";import{a as f}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as g,f as p,h as v}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as d}from"../../chunk-ZLLER3HP.js";import{Args as P,Flags as b}from"@oclif/core";var r=d(i=>i==null?"n/a":`${Math.round(i*100)}%`,"pct"),c=class i extends f{static{d(this,"EvalRefineCases")}static description="Retire non-discriminating eval cases and regenerate discriminating replacements (\xA76e)";static examples=["<%= config.bin %> evals refine-cases <target-id> # preview","<%= config.bin %> evals refine-cases <target-id> --yes # apply: retire + regenerate","<%= config.bin %> evals refine-cases <target-id> --yes --no-generate"];static args={targetId:P.string({description:"Eval target ID",required:!0})};static flags={yes:b.boolean({char:"y",description:"Apply (retire + regenerate). Without this, only previews."}),"no-generate":b.boolean({description:"Retire dead cases but do not regenerate replacements."})};async run(){let{args:$,flags:o}=await this.parse(i);this.requireAuth();let n=$.targetId,s=await g(`/api/eval-targets/${n}`),m=await g(`/api/eval-targets/${n}/judge-calibration`),t=m.caseDiscrimination;if(!t||t.cases.length===0&&t.unpairedCases.length===0){this.log("No case-discrimination data yet \u2014 run some evals with AND without the target first (`evals run` / the web Run Evals button), then refine.");return}let u=t.cases.filter(e=>!e.discriminating),a=[...u.map(e=>({evalId:e.evalId,name:e.name,feedback:{name:e.name,withPassRate:e.withPassRate,withoutPassRate:e.withoutPassRate,reason:e.note}})),...t.unpairedCases.map(e=>({evalId:e.evalId,name:e.name,feedback:{name:e.name,withPassRate:e.withPassRate??0,withoutPassRate:e.withoutPassRate,reason:"runs in only one cohort (no with-vs-without comparison possible)"}}))];if(this.log(`Target "${s.name}" v${s.version} \u2014 judge ${m.judge.currentModel??"(unstamped)"}`),this.log(`${t.total} diagnosable case(s): ${t.discriminating} discriminate, ${t.nonDiscriminating} flat/wrong-sign, ${t.unpaired} unpaired.`),a.length===0){this.log("Every case discriminates \u2014 nothing to retire. \u{1F389}");return}this.log(`
1
+ import{b as w}from"../../chunk-CNOD6HWU.js";import"../../chunk-B3BHB26P.js";import"../../chunk-N7ODX6PO.js";import"../../chunk-PJ3WHQ67.js";import{a as f}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as g,f as p,h as v}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as d}from"../../chunk-ZLLER3HP.js";import{Args as P,Flags as b}from"@oclif/core";var r=d(i=>i==null?"n/a":`${Math.round(i*100)}%`,"pct"),c=class i extends f{static{d(this,"EvalRefineCases")}static description="Retire non-discriminating eval cases and regenerate discriminating replacements (\xA76e)";static examples=["<%= config.bin %> evals refine-cases <target-id> # preview","<%= config.bin %> evals refine-cases <target-id> --yes # apply: retire + regenerate","<%= config.bin %> evals refine-cases <target-id> --yes --no-generate"];static args={targetId:P.string({description:"Eval target ID",required:!0})};static flags={yes:b.boolean({char:"y",description:"Apply (retire + regenerate). Without this, only previews."}),"no-generate":b.boolean({description:"Retire dead cases but do not regenerate replacements."})};async run(){let{args:$,flags:o}=await this.parse(i);this.requireAuth();let n=$.targetId,s=await g(`/api/eval-targets/${n}`),m=await g(`/api/eval-targets/${n}/judge-calibration`),t=m.caseDiscrimination;if(!t||t.cases.length===0&&t.unpairedCases.length===0){this.log("No case-discrimination data yet \u2014 run some evals with AND without the target first (`evals run` / the web Run Evals button), then refine.");return}let u=t.cases.filter(e=>!e.discriminating),a=[...u.map(e=>({evalId:e.evalId,name:e.name,feedback:{name:e.name,withPassRate:e.withPassRate,withoutPassRate:e.withoutPassRate,reason:e.note}})),...t.unpairedCases.map(e=>({evalId:e.evalId,name:e.name,feedback:{name:e.name,withPassRate:e.withPassRate??0,withoutPassRate:e.withoutPassRate,reason:"runs in only one cohort (no with-vs-without comparison possible)"}}))];if(this.log(`Target "${s.name}" v${s.version} \u2014 judge ${m.judge.currentModel??"(unstamped)"}`),this.log(`${t.total} diagnosable case(s): ${t.discriminating} discriminate, ${t.nonDiscriminating} flat/wrong-sign, ${t.unpaired} unpaired.`),a.length===0){this.log("Every case discriminates \u2014 nothing to retire. \u{1F389}");return}this.log(`
2
2
  Would retire ${a.length} non-discriminating case(s):`);for(let e of u)this.log(` \u2717 ${e.name} \u2014 ${r(e.withPassRate)} with vs ${r(e.withoutPassRate)} without (\u0394${(e.separation*100).toFixed(0)}pp) \u2014 ${e.note}`);for(let e of t.unpairedCases)this.log(` \u2717 ${e.name} \u2014 ${r(e.withPassRate)} with vs ${r(e.withoutPassRate)} without \u2014 unpaired`);if(!o.yes){this.log(`
3
3
  Preview only. Re-run with --yes to retire ${a.length} case(s)${o["no-generate"]?"":" and generate replacements"}.`);return}for(let e of a)await v(`/api/eval-targets/${n}/evals/${e.evalId}`,{retire:!0,retiredReason:e.feedback.reason}),this.log(` retired ${e.name}`);if(o["no-generate"]){this.log(`
4
4
  Retired ${a.length} case(s). Skipped regeneration (--no-generate).`);return}this.log(`
@@ -1,3 +1,3 @@
1
- import{a as k}from"../../chunk-BSJBNOJT.js";import"../../chunk-L2CFSMBC.js";import"../../chunk-Z72VHGV7.js";import"../../chunk-7AZKPX2J.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-V5MJ4ICC.js";import"../../chunk-HMMO27U4.js";import"../../chunk-MODFTCZY.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-N7ODX6PO.js";import{a as $}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as v,f as h}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as R}from"../../chunk-ZLLER3HP.js";import{Args as I,Flags as g}from"@oclif/core";var b=class _ extends ${static{R(this,"EvalRunCommand")}static description="Run evals against a target, optionally grade results, and post to API";static examples=["<%= config.bin %> evals run <target-id>","<%= config.bin %> evals run <target-id> --parallel 3 --runs-per-eval 2","<%= config.bin %> evals run <target-id> --skip-baseline --skip-grading"];static args={targetId:I.string({description:"Eval target ID",required:!0})};static flags={parallel:g.integer({description:"Number of parallel eval executions",default:1}),"runs-per-eval":g.integer({description:"Number of runs per eval for variance analysis",default:1}),iteration:g.integer({description:"Iteration number for tracking",default:1}),"skip-baseline":g.boolean({description:"Skip baseline (without_target) runs",default:!1}),"skip-grading":g.boolean({description:"Skip LLM grading step",default:!1}),model:g.string({description:"Model for eval execution (default: user configured)"}),"grader-model":g.string({description:"Model for grading (default: same as execution model)"}),timeout:g.integer({description:"Timeout per eval in ms",default:12e4})};async run(){let{args:c,flags:r}=await this.parse(_);this.requireAuth();let i=await v(`/api/eval-targets/${c.targetId}`),l=await v(`/api/eval-targets/${c.targetId}/evals`);l.length===0&&this.error(`No evals found for target "${i.name}". Create some with \`rulemetric evals create\`.`),this.log(`Running ${l.length} eval(s) for "${i.name}" v${i.version}`),this.log(`Config: ${r["runs-per-eval"]} run(s) per eval, parallel=${r.parallel}, iteration=${r.iteration}`),r["skip-baseline"]&&this.log("Skipping baseline runs"),r["skip-grading"]&&this.log("Skipping grading"),this.log("");let m=[{name:"with_target",content:i.content}];r["skip-baseline"]||m.push({name:"without_target"});let p=[];for(let a of l)for(let n of m)for(let t=1;t<=r["runs-per-eval"];t++)p.push({eval_:a,configuration:n.name,targetContent:n.content,runNumber:t});let u=[],y=r.parallel;for(let a=0;a<p.length;a+=y){let n=p.slice(a,a+y),t=await Promise.all(n.map(d=>this.executeAndGrade(d,i,r)));u.push(...t)}this.log(""),this.log("Posting results to API...");for(let a of u)await h("/api/eval-runs",a);try{await h(`/api/eval-targets/${c.targetId}/label-state`,{})}catch{}this.log(""),this.log("=== Results Summary ===");for(let a of m){let n=u.filter(e=>e.configuration===a.name),t=n.filter(e=>e.status==="completed"),d=t.filter(e=>Object.keys(e.grading).length>0);if(this.log(`
1
+ import{a as k}from"../../chunk-KQCAELPN.js";import"../../chunk-L2CFSMBC.js";import"../../chunk-Z72VHGV7.js";import"../../chunk-4L2ZEIRE.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-XRTZU7IZ.js";import"../../chunk-B3BHB26P.js";import"../../chunk-N7ODX6PO.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-HMMO27U4.js";import{a as $}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import{e as v,f as h}from"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as R}from"../../chunk-ZLLER3HP.js";import{Args as I,Flags as g}from"@oclif/core";var b=class _ extends ${static{R(this,"EvalRunCommand")}static description="Run evals against a target, optionally grade results, and post to API";static examples=["<%= config.bin %> evals run <target-id>","<%= config.bin %> evals run <target-id> --parallel 3 --runs-per-eval 2","<%= config.bin %> evals run <target-id> --skip-baseline --skip-grading"];static args={targetId:I.string({description:"Eval target ID",required:!0})};static flags={parallel:g.integer({description:"Number of parallel eval executions",default:1}),"runs-per-eval":g.integer({description:"Number of runs per eval for variance analysis",default:1}),iteration:g.integer({description:"Iteration number for tracking",default:1}),"skip-baseline":g.boolean({description:"Skip baseline (without_target) runs",default:!1}),"skip-grading":g.boolean({description:"Skip LLM grading step",default:!1}),model:g.string({description:"Model for eval execution (default: user configured)"}),"grader-model":g.string({description:"Model for grading (default: same as execution model)"}),timeout:g.integer({description:"Timeout per eval in ms",default:12e4})};async run(){let{args:c,flags:r}=await this.parse(_);this.requireAuth();let i=await v(`/api/eval-targets/${c.targetId}`),l=await v(`/api/eval-targets/${c.targetId}/evals`);l.length===0&&this.error(`No evals found for target "${i.name}". Create some with \`rulemetric evals create\`.`),this.log(`Running ${l.length} eval(s) for "${i.name}" v${i.version}`),this.log(`Config: ${r["runs-per-eval"]} run(s) per eval, parallel=${r.parallel}, iteration=${r.iteration}`),r["skip-baseline"]&&this.log("Skipping baseline runs"),r["skip-grading"]&&this.log("Skipping grading"),this.log("");let m=[{name:"with_target",content:i.content}];r["skip-baseline"]||m.push({name:"without_target"});let p=[];for(let a of l)for(let n of m)for(let t=1;t<=r["runs-per-eval"];t++)p.push({eval_:a,configuration:n.name,targetContent:n.content,runNumber:t});let u=[],y=r.parallel;for(let a=0;a<p.length;a+=y){let n=p.slice(a,a+y),t=await Promise.all(n.map(d=>this.executeAndGrade(d,i,r)));u.push(...t)}this.log(""),this.log("Posting results to API...");for(let a of u)await h("/api/eval-runs",a);try{await h(`/api/eval-targets/${c.targetId}/label-state`,{})}catch{}this.log(""),this.log("=== Results Summary ===");for(let a of m){let n=u.filter(e=>e.configuration===a.name),t=n.filter(e=>e.status==="completed"),d=t.filter(e=>Object.keys(e.grading).length>0);if(this.log(`
2
2
  ${a.name}:`),this.log(` Runs: ${t.length}/${n.length} completed`),d.length>0){let e=d.map(o=>o.grading.summary?.pass_rate??0),s=e.reduce((o,f)=>o+f,0)/e.length;this.log(` Avg pass_rate: ${(s*100).toFixed(1)}%`)}for(let e of n){let s=l.find(x=>x.id===e.evalId)?.name??e.evalId,o=e.grading.summary?.pass_rate,f=o!==void 0?` pass_rate=${(o*100).toFixed(0)}%`:"",w=e.timing.duration_ms?` ${(e.timing.duration_ms/1e3).toFixed(1)}s`:"";this.log(` [${e.status}] ${s} run#${e.runNumber}${f}${w}`)}}if(!r["skip-baseline"]&&u.length>0){let a=u.filter(t=>t.configuration==="with_target"&&Object.keys(t.grading).length>0),n=u.filter(t=>t.configuration==="without_target"&&Object.keys(t.grading).length>0);if(a.length>0&&n.length>0){let t=a.map(s=>s.grading.summary?.pass_rate??0).reduce((s,o)=>s+o,0)/a.length,d=n.map(s=>s.grading.summary?.pass_rate??0).reduce((s,o)=>s+o,0)/n.length,e=t-d;this.log(`
3
3
  Delta: ${e>0?"+":""}${(e*100).toFixed(1)}% (with_target vs without_target)`)}}}async executeAndGrade(c,r,i){return k(c,{targetId:r.id,targetVersion:r.version,iteration:i.iteration,timeout:i.timeout,model:i.model,graderModel:i["grader-model"],skipGrading:i["skip-grading"],targetType:r.type,targetName:r.name},l=>this.log(l))}};export{b as default};
@@ -1 +1 @@
1
- import{c,d as m}from"../../chunk-OZQV5CDT.js";import"../../chunk-6UEFCMR2.js";import"../../chunk-7AZKPX2J.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-V5MJ4ICC.js";import"../../chunk-HMMO27U4.js";import"../../chunk-OPUI7CM2.js";import"../../chunk-MODFTCZY.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-N7ODX6PO.js";import{a as u}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as r}from"../../chunk-ZLLER3HP.js";import{Args as p,Flags as s}from"@oclif/core";var o=r(n=>n==null?"\u2014":`${(n*100).toFixed(0)}%`,"pct"),g=class n extends u{static{r(this,"EvalValidateJudge")}static description="Score a second model against your human judge-review labels (\xA76g validation pass)";static examples=["<%= config.bin %> evals validate-judge <target-id> # auto-detect installed CLIs","<%= config.bin %> evals validate-judge <target-id> --engine codex --model gpt-5.5","<%= config.bin %> evals validate-judge <target-id> --model claude-sonnet-5 --json","<%= config.bin %> evals validate-judge <target-id> --limit 5 # quick sample"];static args={targetId:p.string({description:"Eval target ID",required:!0})};static flags={model:s.string({description:"Second reviewer model. Default: resolved from your installed tooling (codex: your ~/.codex/config.toml model; claude: a tier that differs from the original judge)."}),engine:s.string({description:"CLI that runs the second reviewer. `auto` prefers your installed codex for a cross-vendor reviewer \u2014 two Claude models share a training lineage, so their agreement overstates independence.",options:["auto","claude","codex"],default:"auto"}),limit:s.integer({description:"Sample only the N most-recently-annotated runs (cost control / smoke)"}),"skip-reviewed":s.boolean({description:"Only re-grade assertions this reviewer model has not ruled on yet",default:!1}),parallel:s.integer({description:"Concurrent re-grades",default:3}),timeout:s.integer({description:"Timeout per re-grade in ms",default:12e4}),json:s.boolean({description:"Emit the full report as JSON"})};async run(){let{args:h,flags:i}=await this.parse(n);this.requireAuth();let a;try{a=await m({targetId:h.targetId,engineFlag:i.engine,modelFlag:i.model,limit:i.limit,parallel:i.parallel,timeoutMs:i.timeout,skipReviewed:i["skip-reviewed"],log:r(t=>this.log(t),"log"),warn:r(t=>this.warn(t),"warn")})}catch(t){throw t instanceof c&&this.error(t.message),t}let{report:e,judgeModels:l,reviewerModel:d}=a;if(l.length===1&&l[0]===d&&this.warn(`Second reviewer resolved to the SAME model as the original judge (${l[0]}) \u2014 this measures self-consistency, not independent review.`),i.json){this.log(JSON.stringify({target:a.targetName,judgeA:l,judgeB:d,persisted:a.persisted,alreadyReviewed:a.alreadyReviewed,...e},null,2));return}if(e.pairs===0&&a.alreadyReviewed>0){this.log(`All ${a.alreadyReviewed} labeled assertion(s) already reviewed by ${d} \u2014 nothing new to grade.`);return}if(this.log(""),this.log(`Second reviewer: ${d} \u2014 scored against ${e.pairs} human-labeled assertion(s)`+(e.skipped?` (${e.skipped} skipped)`:"")),this.log(""),this.log(` reviewer vs HUMAN: ${o(e.bVsHuman.overall.rate)} overall \xB7 ${o(e.bVsHuman.onJudgePass.rate)} where judge passed \xB7 ${o(e.bVsHuman.onJudgeFail.rate)} where judge failed`),this.log(` original judge vs human: ${o(e.aVsHuman.overall.rate)} (your approve rate)`),this.log(` reviewer vs judge: ${o(e.bVsA.overall.rate)} (inter-model, not truth)`),this.log(` Cohen's \u03BA (reviewer vs human): ${e.kappaBvsHuman==null?"undefined (degenerate marginals)":e.kappaBvsHuman.toFixed(2)}`),this.log(""),e.suggestedAnchorWeight!=null&&this.log(` suggested \xA76g anchor weight if used as a passive label source: ${e.suggestedAnchorWeight.toFixed(2)} (misclassification attenuation (2\xB7acc\u22121)\xB2; validated:false either way)`),e.disagreements.length>0){this.log(""),this.log(` ${e.disagreements.length} disagreement(s) with your labels \u2014 flagged on the Review tab:`);for(let t of e.disagreements.slice(0,10))this.log(` run ${t.runId.slice(0,8)} #${t.expectationIndex}: human=${t.humanPassed?"pass":"fail"} reviewer=${t.judgeBPassed?"pass":"fail"} \u2014 ${t.text.slice(0,80)}`);e.disagreements.length>10&&this.log(` \u2026 and ${e.disagreements.length-10} more (use --json for all)`)}}};export{g as default};
1
+ import{c,d as m}from"../../chunk-X64R6JCJ.js";import"../../chunk-6UEFCMR2.js";import"../../chunk-NTKO4H2K.js";import"../../chunk-4L2ZEIRE.js";import"../../chunk-CDY7TQFZ.js";import"../../chunk-XRTZU7IZ.js";import"../../chunk-B3BHB26P.js";import"../../chunk-N7ODX6PO.js";import"../../chunk-PJ3WHQ67.js";import"../../chunk-HMMO27U4.js";import{a as u}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as r}from"../../chunk-ZLLER3HP.js";import{Args as p,Flags as s}from"@oclif/core";var o=r(n=>n==null?"\u2014":`${(n*100).toFixed(0)}%`,"pct"),g=class n extends u{static{r(this,"EvalValidateJudge")}static description="Score a second model against your human judge-review labels (\xA76g validation pass)";static examples=["<%= config.bin %> evals validate-judge <target-id> # auto-detect installed CLIs","<%= config.bin %> evals validate-judge <target-id> --engine codex --model gpt-5.5","<%= config.bin %> evals validate-judge <target-id> --model claude-sonnet-5 --json","<%= config.bin %> evals validate-judge <target-id> --limit 5 # quick sample"];static args={targetId:p.string({description:"Eval target ID",required:!0})};static flags={model:s.string({description:"Second reviewer model. Default: resolved from your installed tooling (codex: your ~/.codex/config.toml model; claude: a tier that differs from the original judge)."}),engine:s.string({description:"CLI that runs the second reviewer. `auto` prefers your installed codex for a cross-vendor reviewer \u2014 two Claude models share a training lineage, so their agreement overstates independence.",options:["auto","claude","codex"],default:"auto"}),limit:s.integer({description:"Sample only the N most-recently-annotated runs (cost control / smoke)"}),"skip-reviewed":s.boolean({description:"Only re-grade assertions this reviewer model has not ruled on yet",default:!1}),parallel:s.integer({description:"Concurrent re-grades",default:3}),timeout:s.integer({description:"Timeout per re-grade in ms",default:12e4}),json:s.boolean({description:"Emit the full report as JSON"})};async run(){let{args:h,flags:i}=await this.parse(n);this.requireAuth();let a;try{a=await m({targetId:h.targetId,engineFlag:i.engine,modelFlag:i.model,limit:i.limit,parallel:i.parallel,timeoutMs:i.timeout,skipReviewed:i["skip-reviewed"],log:r(t=>this.log(t),"log"),warn:r(t=>this.warn(t),"warn")})}catch(t){throw t instanceof c&&this.error(t.message),t}let{report:e,judgeModels:l,reviewerModel:d}=a;if(l.length===1&&l[0]===d&&this.warn(`Second reviewer resolved to the SAME model as the original judge (${l[0]}) \u2014 this measures self-consistency, not independent review.`),i.json){this.log(JSON.stringify({target:a.targetName,judgeA:l,judgeB:d,persisted:a.persisted,alreadyReviewed:a.alreadyReviewed,...e},null,2));return}if(e.pairs===0&&a.alreadyReviewed>0){this.log(`All ${a.alreadyReviewed} labeled assertion(s) already reviewed by ${d} \u2014 nothing new to grade.`);return}if(this.log(""),this.log(`Second reviewer: ${d} \u2014 scored against ${e.pairs} human-labeled assertion(s)`+(e.skipped?` (${e.skipped} skipped)`:"")),this.log(""),this.log(` reviewer vs HUMAN: ${o(e.bVsHuman.overall.rate)} overall \xB7 ${o(e.bVsHuman.onJudgePass.rate)} where judge passed \xB7 ${o(e.bVsHuman.onJudgeFail.rate)} where judge failed`),this.log(` original judge vs human: ${o(e.aVsHuman.overall.rate)} (your approve rate)`),this.log(` reviewer vs judge: ${o(e.bVsA.overall.rate)} (inter-model, not truth)`),this.log(` Cohen's \u03BA (reviewer vs human): ${e.kappaBvsHuman==null?"undefined (degenerate marginals)":e.kappaBvsHuman.toFixed(2)}`),this.log(""),e.suggestedAnchorWeight!=null&&this.log(` suggested \xA76g anchor weight if used as a passive label source: ${e.suggestedAnchorWeight.toFixed(2)} (misclassification attenuation (2\xB7acc\u22121)\xB2; validated:false either way)`),e.disagreements.length>0){this.log(""),this.log(` ${e.disagreements.length} disagreement(s) with your labels \u2014 flagged on the Review tab:`);for(let t of e.disagreements.slice(0,10))this.log(` run ${t.runId.slice(0,8)} #${t.expectationIndex}: human=${t.humanPassed?"pass":"fail"} reviewer=${t.judgeBPassed?"pass":"fail"} \u2014 ${t.text.slice(0,80)}`);e.disagreements.length>10&&this.log(` \u2026 and ${e.disagreements.length-10} more (use --json for all)`)}}};export{g as default};
@@ -1 +1 @@
1
- import{b as y,c as h}from"../../chunk-CYKELSHS.js";import{B as l,E as g}from"../../chunk-VLXCQ2DC.js";import"../../chunk-I2DZGJRR.js";import{c as e,g as p,i as m,k as f}from"../../chunk-MVM6OGAF.js";import"../../chunk-KKDHD4XA.js";import{b as d,d as u}from"../../chunk-SZ62CP55.js";import{a as c}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a}from"../../chunk-ZLLER3HP.js";import{spawn as S}from"node:child_process";import{existsSync as v,readFileSync as R,statSync as C,writeFileSync as M}from"node:fs";import{homedir as T}from"node:os";import{join as o}from"node:path";var s=o(T(),".config","rulemetric"),x=o(s,"proxy-addon.version"),_=o(s,"proxy.pid"),w=o(s,"proxy-drift-restart.at"),E=10*6e4,n=class P extends c{static{a(this,"GatewayEnsure")}static description="Ensure the gateway proxy is running (called by hooks, not for direct use)";static hidden=!0;async run(){await this.parse(P),this.maybeRestartStaleProxy();let t=await p(e);if(t.status==="ours-live"){let r=h(i=>{i==="vscode"?l(e):g(e)});r.length>0&&console.error(`[RuleMetric] Gateway healthy again \u2014 restored ${r.join(", ")} proxy settings.`);return}if(t.status==="foreign"){if(m())return;let r=y(e);console.error(`[RuleMetric] A non-RuleMetric process holds :${e} \u2014 cannot start gateway. `+(r.length>0?`Unpinned ${r.join(", ")} proxy settings so editors are not routed through it. `:"")+"Run `rulemetric diagnostics` if Claude Code HTTPS requests fail.");return}try{f(this.config.version)}catch(r){console.error(`[RuleMetric] Could not start gateway: ${r.message}`)}}maybeRestartStaleProxy(){try{if(!v(x))return;let t=R(x,"utf-8").trim();if(!t||t===this.config.version)return;let r=R(_,"utf-8").trim(),i=Number(r);if(!Number.isFinite(i)||!u(i,d))return;try{if(Date.now()-C(w).mtimeMs<E)return}catch{}M(w,new Date().toISOString()),S(process.execPath,[process.argv[1],"proxy","restart"],{detached:!0,stdio:"ignore"}).unref(),console.error(`[RuleMetric] Capture proxy is running CLI ${t} but ${this.config.version} is installed \u2014 restarting it in the background.`)}catch{}}};export{n as default};
1
+ import{b as y,c as h}from"../../chunk-CYKELSHS.js";import{B as l,E as g}from"../../chunk-VLXCQ2DC.js";import"../../chunk-I2DZGJRR.js";import{e,i as p,k as m,m as f}from"../../chunk-QWCEZEDO.js";import"../../chunk-KKDHD4XA.js";import{b as d,d as u}from"../../chunk-SZ62CP55.js";import{a as c}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a}from"../../chunk-ZLLER3HP.js";import{spawn as S}from"node:child_process";import{existsSync as v,readFileSync as R,statSync as C,writeFileSync as M}from"node:fs";import{homedir as T}from"node:os";import{join as o}from"node:path";var s=o(T(),".config","rulemetric"),x=o(s,"proxy-addon.version"),_=o(s,"proxy.pid"),w=o(s,"proxy-drift-restart.at"),E=10*6e4,n=class P extends c{static{a(this,"GatewayEnsure")}static description="Ensure the gateway proxy is running (called by hooks, not for direct use)";static hidden=!0;async run(){await this.parse(P),this.maybeRestartStaleProxy();let t=await p(e);if(t.status==="ours-live"){let r=h(i=>{i==="vscode"?l(e):g(e)});r.length>0&&console.error(`[RuleMetric] Gateway healthy again \u2014 restored ${r.join(", ")} proxy settings.`);return}if(t.status==="foreign"){if(m())return;let r=y(e);console.error(`[RuleMetric] A non-RuleMetric process holds :${e} \u2014 cannot start gateway. `+(r.length>0?`Unpinned ${r.join(", ")} proxy settings so editors are not routed through it. `:"")+"Run `rulemetric diagnostics` if Claude Code HTTPS requests fail.");return}try{f(this.config.version)}catch(r){console.error(`[RuleMetric] Could not start gateway: ${r.message}`)}}maybeRestartStaleProxy(){try{if(!v(x))return;let t=R(x,"utf-8").trim();if(!t||t===this.config.version)return;let r=R(_,"utf-8").trim(),i=Number(r);if(!Number.isFinite(i)||!u(i,d))return;try{if(Date.now()-C(w).mtimeMs<E)return}catch{}M(w,new Date().toISOString()),S(process.execPath,[process.argv[1],"proxy","restart"],{detached:!0,stdio:"ignore"}).unref(),console.error(`[RuleMetric] Capture proxy is running CLI ${t} but ${this.config.version} is installed \u2014 restarting it in the background.`)}catch{}}};export{n as default};
@@ -1 +1 @@
1
- import{b as mt}from"../../chunk-UGIUIZ2V.js";import{a as yt}from"../../chunk-6XEC6474.js";import{B as gt,E as ht,H as pt,I as ft,e as Z,f as tt,g as et,i as st,j as ot,k as it,n as rt,p as at,q as nt,r as lt,u as ct,v as ut,y as dt}from"../../chunk-VLXCQ2DC.js";import{a as J,b as z,c as m,d as Q,g as _}from"../../chunk-I2DZGJRR.js";import{c as s,g as F,h as V,i as q,k as A,l as W}from"../../chunk-MVM6OGAF.js";import{e as D}from"../../chunk-KKDHD4XA.js";import"../../chunk-SZ62CP55.js";import{a as f}from"../../chunk-PJ3WHQ67.js";import"../../chunk-N7ODX6PO.js";import{a as X}from"../../chunk-XICLXXRH.js";import{a as B}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import{c as Y}from"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import{b as M}from"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import{a as L}from"../../chunk-O6C2UGBY.js";import{a as w}from"../../chunk-ZLLER3HP.js";import{Flags as x}from"@oclif/core";import{execFileSync as Ct,spawnSync as l}from"node:child_process";import{existsSync as u}from"node:fs";import{homedir as vt}from"node:os";import{join as R,dirname as xt}from"node:path";function kt(){try{let g=Ct("/bin/sh",["-c","command -v rulemetric"],{encoding:"utf-8"}).trim();if(g&&u(g))return xt(g)}catch{}}w(kt,"resolveHookBinDir");function Pt(){try{return Ct("launchctl",["list","com.rulemetric.gateway"],{stdio:["ignore","pipe","pipe"]}),!0}catch{return!1}}w(Pt,"isGatewayLaunchdManaged");var o=R(vt(),".mitmproxy","mitmproxy-ca-cert.pem"),K=class g extends B{static{w(this,"HooksInstall")}static description="Install session tracking hooks and context capture proxy for Claude Code";static examples=["<%= config.bin %> hooks install","<%= config.bin %> hooks install --global","<%= config.bin %> hooks install --no-proxy"];static flags={"no-proxy":x.boolean({default:!1,description:"Skip proxy/gateway configuration (hooks only)"}),"project-dir":x.string({description:"Project directory to install hooks in (defaults to cwd)"}),global:x.boolean({char:"g",default:!1,description:"Install hooks globally (~/.claude/settings.json) so all projects are tracked"}),"statusline-usage":x.boolean({default:!1,description:"Install the statusline shim so Claude Code pushes live rate_limits on every refresh (makes /usage rings update in real time without needing the proxy)"})};async run(){let{flags:i}=await this.parse(g),r=i.global,a=r?vt():i["project-dir"]??process.cwd(),k=R(a,".claude"),y=it(k,r),$=r?"settings.json":"settings.local.json",P=i["no-proxy"],S=!1,h=P?"no_proxy_flag":void 0,p=!1,T=[];r&&this.log(`Installing hooks globally \u2192 ${y}`);let{settings:n,recoveredBackup:I}=Z(y);if(I&&this.log(`[!!] ${y} was not valid JSON \u2014 backed it up to ${I} and continued with a fresh file.`),!r){let e=rt(R(k,"settings.json"),s);e.migrated&&(this.log("[OK] Moved RuleMetric machine-local state out of the shared .claude/settings.json (it now lives in .claude/settings.local.json)"),e.backupPath&&this.log(` Previous shared settings backed up \u2192 ${e.backupPath}`),e.removedStatusline&&u(J)&&!_(n)&&(n.statusLine=m))}let E=L();(E.accessToken||process.env.RULEMETRIC_ACCESS_TOKEN)&&!E.apiKey&&!process.env.RULEMETRIC_API_KEY&&await X(this.log.bind(this),this.warn.bind(this),this.config.version);let wt=st(n),C=kt();if(et(n,C),this.log(wt?`[OK] Refreshed RuleMetric Claude Code session hooks \u2192 .claude/${$}`:`[OK] Installed RuleMetric Claude Code session hooks \u2192 .claude/${$}`),!P){let e=!!f("mitmdump");if(e||(this.log(""),this.log("[!!] mitmproxy not found \u2014 installing..."),T=["brew","pipx","uv"].filter(t=>!!f(t)),e=this.installMitmproxy(),e||(this.log("[!!] Could not install mitmproxy. Skipping proxy config."),this.log(" Install manually: pipx install mitmproxy"),this.log(" Then re-run: rulemetric hooks install"))),u(o))this.log("[OK] CA certificate found");else{this.log("[..] Generating CA certificate...");let t=f("mitmdump");t&&(l(t,["--set","listen_port=0","-q"],{timeout:5e3,stdio:"ignore"}),u(o)?this.log(`[OK] CA certificate generated at ${o}`):this.log("[!!] Could not generate CA cert"))}let c=u(o);c&&!this.isCACertTrusted()?(this.log("[..] Installing CA certificate into system trust store (requires admin)..."),p=this.trustCACert(),p?this.log("[OK] CA certificate trusted by system"):(this.log("[!!] Could not install CA cert automatically."),process.platform==="darwin"?this.log(` Run manually: sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${o}`):process.platform==="linux"&&this.log(` Run manually: sudo cp ${o} /usr/local/share/ca-certificates/mitmproxy-ca.crt && sudo update-ca-certificates`))):c&&(this.log("[OK] CA certificate already trusted"),p=!0);let d=Pt(),O=await F(s);if(d)this.log("[OK] Gateway managed by launchd (com.rulemetric.gateway)");else if(O.status==="ours-live")this.log("[OK] Gateway already running");else if(O.status==="foreign"&&q()){this.log("[..] Restarting gateway (running build predates the identity handshake)..."),W(),await new Promise(t=>setTimeout(t,500));try{let t=A(this.config.version);this.log(`[OK] Gateway restarted (PID ${t})`)}catch(t){this.log(`[!!] Could not restart gateway: ${t.message}`)}}else if(O.status!=="foreign")try{let t=A(this.config.version);this.log(`[OK] Gateway started (PID ${t})`)}catch(t){this.log(`[!!] Could not start gateway: ${t.message}`)}let G=await V(s,{timeoutMs:4e3});if(!c)h=e?"ca_not_generated":T.length===0?"no_package_manager":"mitmproxy_install_failed",this.log("[!!] No CA certificate \u2014 NOT setting HTTPS_PROXY (capture stays hooks-only)."),this.log(" Install mitmproxy, then re-run: rulemetric hooks install");else if(G.status==="foreign"&&!d){h="gateway_port_foreign";let t=D(s);this.log(`[!!] Port :${s} is held by a process that is NOT the RuleMetric gateway \u2014 NOT setting HTTPS_PROXY.`),this.log(t?` Holding the port: ${t}`:` Could not identify the holder (try: lsof -nP -iTCP:${s} -sTCP:LISTEN)`),this.log(" Capture still works via hooks. Free the port, then re-run: rulemetric hooks install")}else if(G.status==="dead")h="gateway_not_live",this.log(`[!!] Gateway is not answering on :${s} \u2014 NOT setting HTTPS_PROXY.`),this.log(" Capture still works via hooks. To enable deep (proxy) capture later:"),this.log(" rulemetric proxy start && rulemetric hooks install");else{let t=n.env??{};t.HTTPS_PROXY=`http://localhost:${s}`,t.NO_PROXY=ot,u(o)&&(t.NODE_EXTRA_CA_CERTS=o),n.env=t,S=!0,this.log(`[OK] HTTPS_PROXY set to gateway on :${s} (verified live)`),ct(a,s,o)&&this.log("[OK] Cursor proxy configured \u2192 .cursor/settings.json"),ut(a,s,o)&&this.log("[OK] VS Code workspace proxy configured \u2192 .vscode/settings.json"),gt(s)&&this.log("[OK] VS Code user proxy configured \u2192 ~/Library/Application Support/Code/User/settings.json"),ht(s)&&this.log("[OK] Cursor user proxy configured \u2192 ~/Library/Application Support/Cursor/User/settings.json"),p?dt(s,o)&&this.log("[OK] HTTPS_PROXY set for GUI apps (launchctl + LaunchAgent)"):(h="ca_untrusted",this.log("[!!] CA not trusted \u2014 skipping machine-wide GUI proxy (would break native-app TLS)."),this.log(" Claude Code capture is unaffected. Trust the CA + re-run to enable cross-app capture."))}}let v=[];if(!r){let e=at(a,C);e&&(this.log(`[OK] Cursor hooks configured \u2192 ${e}`),v.push(e));let c=lt(a,C);c&&(this.log(`[OK] Copilot Agent hooks configured \u2192 ${c}`),v.push(c));let d=pt(a);d&&(this.log(`[OK] Antigravity workspace hooks configured \u2192 ${d}`),v.push(d))}let H=ft();H&&this.log(`[OK] Antigravity user hooks configured \u2192 ${H}`);let U=nt(C);if(U&&this.log(`[OK] Cursor user hooks configured \u2192 ${U}`),i["statusline-usage"])if(_(n))this.log("[OK] Statusline shim already installed");else{let e=Q(n);z(e),n.statusLine=m,e?this.log(`[OK] Statusline shim installed \u2192 ${m.command} (chains to: ${e})`):this.log(`[OK] Statusline shim installed \u2192 ${m.command}`),this.log(" Rate-limit rings will now update on Claude Code's statusline refresh cadence")}let{backupPath:N}=tt(y,n);N&&this.log(`[OK] Backed up previous settings \u2192 ${N}`),this.log(""),this.log("Setup complete! Next steps:"),r?(this.log(" 1. Install always-on API: rulemetric service install"),this.log(" 2. Start Claude Code in any project \u2014 all sessions tracked automatically"),this.log(""),this.log("The API service starts on login and restarts on crash.")):P?(this.log(" 1. Start Claude Code \u2014 sessions are captured by the hooks just installed"),this.log(""),this.log("No proxy means no mitmproxy / CA cert needed. The hooks capture full"),this.log("sessions on their own; re-run without --no-proxy to also capture system"),this.log("prompts for instruction-effectiveness linking.")):(this.log(" 1. Start Claude Code \u2014 sessions are captured by hooks immediately"),S?this.log(" 2. Full-depth capture is ON \u2014 the proxy is live on :"+s+"."):this.log(" 2. Enable full depth (proxy not yet live): rulemetric proxy start"),this.log(""),this.log("Hooks capture every session (lifecycle + transcript). The proxy adds the"),this.log("rendered system prompt (instruction-effectiveness linking) + cross-tool capture."),this.log(""),this.log("To capture traffic from other clients (Python, curl, etc.):"),this.log(' eval "$(rulemetric proxy env --all)"'));let j=mt(a,v);j&&this.log(j),await M(),Y("hooks_installed",{proxy:S,caTrusted:p,reason:h,installers:T,global:r},this.config.version);let b=await yt();this.log(""),b.available?this.log(`[OK] tmux found${b.version?` (v${b.version})`:""} \u2014 live send enabled`):this.log("[!!] tmux not found \u2014 live send will fall back to opening Terminal. Install with: brew install tmux")}installMitmproxy(){for(let[i,r]of[["pipx",["install","mitmproxy"]],["uv",["tool","install","mitmproxy"]],["brew",["install","mitmproxy"]]]){let a=f(i);if(a&&(this.log(` Installing via ${i}...`),l(a,[...r],{stdio:"inherit"}).status===0))return!0}return!1}isCACertTrusted(){return process.platform==="darwin"?l("security",["verify-cert","-c",o],{stdio:"pipe"}).status===0:process.platform==="linux"?u("/usr/local/share/ca-certificates/mitmproxy-ca.crt"):process.platform==="win32"?l("certutil",["-verify",o],{stdio:"pipe"}).status===0:!1}trustCACert(){return process.platform==="darwin"?l("sudo",["security","add-trusted-cert","-d","-r","trustRoot","-k","/Library/Keychains/System.keychain",o],{stdio:"inherit"}).status===0:process.platform==="linux"?l("sudo",["cp",o,"/usr/local/share/ca-certificates/mitmproxy-ca.crt"],{stdio:"inherit"}).status!==0?!1:l("sudo",["update-ca-certificates"],{stdio:"inherit"}).status===0:process.platform==="win32"?l("certutil",["-addstore","-f","Root",o],{stdio:"inherit"}).status===0:!1}};export{K as default};
1
+ import{b as mt}from"../../chunk-UGIUIZ2V.js";import{a as yt}from"../../chunk-6XEC6474.js";import{B as ht,E as gt,H as pt,I as ft,e as Z,f as tt,g as et,i as st,j as ot,k as it,n as rt,p as at,q as nt,r as lt,u as ct,v as ut,y as dt}from"../../chunk-VLXCQ2DC.js";import{a as J,b as z,c as m,d as Q,g as R}from"../../chunk-I2DZGJRR.js";import{e as s,i as F,j as V,k as q,m as A,n as W}from"../../chunk-QWCEZEDO.js";import{e as D}from"../../chunk-KKDHD4XA.js";import"../../chunk-SZ62CP55.js";import"../../chunk-N7ODX6PO.js";import{a as f}from"../../chunk-PJ3WHQ67.js";import{a as X}from"../../chunk-XICLXXRH.js";import{a as B}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import{c as Y}from"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import{b as M}from"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import{a as L}from"../../chunk-O6C2UGBY.js";import{a as w}from"../../chunk-ZLLER3HP.js";import{Flags as y}from"@oclif/core";import{execFileSync as Ct,spawnSync as l}from"node:child_process";import{existsSync as u}from"node:fs";import{homedir as kt}from"node:os";import{join as _,dirname as wt}from"node:path";function xt(){try{let h=Ct("/bin/sh",["-c","command -v rulemetric"],{encoding:"utf-8"}).trim();if(h&&u(h))return wt(h)}catch{}}w(xt,"resolveHookBinDir");function Pt(){try{return Ct("launchctl",["list","com.rulemetric.gateway"],{stdio:["ignore","pipe","pipe"]}),!0}catch{return!1}}w(Pt,"isGatewayLaunchdManaged");var o=_(kt(),".mitmproxy","mitmproxy-ca-cert.pem"),K=class h extends B{static{w(this,"HooksInstall")}static description="Install session tracking hooks and context capture proxy for Claude Code";static examples=["<%= config.bin %> hooks install","<%= config.bin %> hooks install --global","<%= config.bin %> hooks install --no-proxy"];static flags={"no-proxy":y.boolean({default:!1,description:"Skip proxy/gateway configuration (hooks only)"}),"project-dir":y.string({description:"Project directory to install hooks in (defaults to cwd)"}),"user-hooks":y.boolean({description:"Write user-level Cursor/Antigravity hooks (~/.cursor, ~/.gemini). Required for Cursor capture \u2014 its traffic bypasses the proxy.",default:!0,allowNo:!0}),global:y.boolean({char:"g",default:!1,description:"Install hooks globally (~/.claude/settings.json) so all projects are tracked"}),"statusline-usage":y.boolean({default:!1,description:"Install the statusline shim so Claude Code pushes live rate_limits on every refresh (makes /usage rings update in real time without needing the proxy)"})};async run(){let{flags:i}=await this.parse(h),r=i.global,a=r?kt():i["project-dir"]??process.cwd(),x=_(a,".claude"),C=it(x,r),$=r?"settings.json":"settings.local.json",P=i["no-proxy"],b=!1,g=P?"no_proxy_flag":void 0,p=!1,S=[];r&&this.log(`Installing hooks globally \u2192 ${C}`);let{settings:n,recoveredBackup:I}=Z(C);if(I&&this.log(`[!!] ${C} was not valid JSON \u2014 backed it up to ${I} and continued with a fresh file.`),!r){let e=rt(_(x,"settings.json"),s);e.migrated&&(this.log("[OK] Moved RuleMetric machine-local state out of the shared .claude/settings.json (it now lives in .claude/settings.local.json)"),e.backupPath&&this.log(` Previous shared settings backed up \u2192 ${e.backupPath}`),e.removedStatusline&&u(J)&&!R(n)&&(n.statusLine=m))}let E=L();(E.accessToken||process.env.RULEMETRIC_ACCESS_TOKEN)&&!E.apiKey&&!process.env.RULEMETRIC_API_KEY&&await X(this.log.bind(this),this.warn.bind(this),this.config.version);let vt=st(n),k=xt();if(et(n,k),this.log(vt?`[OK] Refreshed RuleMetric Claude Code session hooks \u2192 .claude/${$}`:`[OK] Installed RuleMetric Claude Code session hooks \u2192 .claude/${$}`),!P){let e=!!f("mitmdump");if(e||(this.log(""),this.log("[!!] mitmproxy not found \u2014 installing..."),S=["brew","pipx","uv"].filter(t=>!!f(t)),e=this.installMitmproxy(),e||(this.log("[!!] Could not install mitmproxy. Skipping proxy config."),this.log(" Install manually: pipx install mitmproxy"),this.log(" Then re-run: rulemetric hooks install"))),u(o))this.log("[OK] CA certificate found");else{this.log("[..] Generating CA certificate...");let t=f("mitmdump");t&&(l(t,["--set","listen_port=0","-q"],{timeout:5e3,stdio:"ignore"}),u(o)?this.log(`[OK] CA certificate generated at ${o}`):this.log("[!!] Could not generate CA cert"))}let c=u(o);c&&!this.isCACertTrusted()?(this.log("[..] Installing CA certificate into system trust store (requires admin)..."),p=this.trustCACert(),p?this.log("[OK] CA certificate trusted by system"):(this.log("[!!] Could not install CA cert automatically."),process.platform==="darwin"?this.log(` Run manually: sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${o}`):process.platform==="linux"&&this.log(` Run manually: sudo cp ${o} /usr/local/share/ca-certificates/mitmproxy-ca.crt && sudo update-ca-certificates`))):c&&(this.log("[OK] CA certificate already trusted"),p=!0);let d=Pt(),O=await F(s);if(d)this.log("[OK] Gateway managed by launchd (com.rulemetric.gateway)");else if(O.status==="ours-live")this.log("[OK] Gateway already running");else if(O.status==="foreign"&&q()){this.log("[..] Restarting gateway (running build predates the identity handshake)..."),W(),await new Promise(t=>setTimeout(t,500));try{let t=A(this.config.version);this.log(`[OK] Gateway restarted (PID ${t})`)}catch(t){this.log(`[!!] Could not restart gateway: ${t.message}`)}}else if(O.status!=="foreign")try{let t=A(this.config.version);this.log(`[OK] Gateway started (PID ${t})`)}catch(t){this.log(`[!!] Could not start gateway: ${t.message}`)}let G=await V(s,{timeoutMs:4e3});if(!c)g=e?"ca_not_generated":S.length===0?"no_package_manager":"mitmproxy_install_failed",this.log("[!!] No CA certificate \u2014 NOT setting HTTPS_PROXY (capture stays hooks-only)."),this.log(" Install mitmproxy, then re-run: rulemetric hooks install");else if(G.status==="foreign"&&!d){g="gateway_port_foreign";let t=D(s);this.log(`[!!] Port :${s} is held by a process that is NOT the RuleMetric gateway \u2014 NOT setting HTTPS_PROXY.`),this.log(t?` Holding the port: ${t}`:` Could not identify the holder (try: lsof -nP -iTCP:${s} -sTCP:LISTEN)`),this.log(" Capture still works via hooks. Free the port, then re-run: rulemetric hooks install")}else if(G.status==="dead")g="gateway_not_live",this.log(`[!!] Gateway is not answering on :${s} \u2014 NOT setting HTTPS_PROXY.`),this.log(" Capture still works via hooks. To enable deep (proxy) capture later:"),this.log(" rulemetric proxy start && rulemetric hooks install");else{let t=n.env??{};t.HTTPS_PROXY=`http://localhost:${s}`,t.NO_PROXY=ot,u(o)&&(t.NODE_EXTRA_CA_CERTS=o),n.env=t,b=!0,this.log(`[OK] HTTPS_PROXY set to gateway on :${s} (verified live)`),ct(a,s,o)&&this.log("[OK] Cursor proxy configured \u2192 .cursor/settings.json"),ut(a,s,o)&&this.log("[OK] VS Code workspace proxy configured \u2192 .vscode/settings.json"),ht(s)&&this.log("[OK] VS Code user proxy configured \u2192 ~/Library/Application Support/Code/User/settings.json"),gt(s)&&this.log("[OK] Cursor user proxy configured \u2192 ~/Library/Application Support/Cursor/User/settings.json"),p?dt(s,o)&&this.log("[OK] HTTPS_PROXY set for GUI apps (launchctl + LaunchAgent)"):(g="ca_untrusted",this.log("[!!] CA not trusted \u2014 skipping machine-wide GUI proxy (would break native-app TLS)."),this.log(" Claude Code capture is unaffected. Trust the CA + re-run to enable cross-app capture."))}}let v=[];if(!r){let e=at(a,k);e&&(this.log(`[OK] Cursor hooks configured \u2192 ${e}`),v.push(e));let c=lt(a,k);c&&(this.log(`[OK] Copilot Agent hooks configured \u2192 ${c}`),v.push(c));let d=pt(a);d&&(this.log(`[OK] Antigravity workspace hooks configured \u2192 ${d}`),v.push(d))}let H=i["user-hooks"]?ft():null;H&&this.log(`[OK] Antigravity user hooks configured \u2192 ${H}`);let U=i["user-hooks"]?nt(k):null;if(U&&this.log(`[OK] Cursor user hooks configured \u2192 ${U}`),i["user-hooks"]||(this.log("[--] Skipped user-level Cursor/Antigravity hooks (--no-user-hooks)."),this.log(" Cursor capture will not work: its chat traffic bypasses the proxy,"),this.log(" so hooks are the only path. Claude Code capture is unaffected.")),i["statusline-usage"])if(R(n))this.log("[OK] Statusline shim already installed");else{let e=Q(n);z(e),n.statusLine=m,e?this.log(`[OK] Statusline shim installed \u2192 ${m.command} (chains to: ${e})`):this.log(`[OK] Statusline shim installed \u2192 ${m.command}`),this.log(" Rate-limit rings will now update on Claude Code's statusline refresh cadence")}let{backupPath:N}=tt(C,n);N&&this.log(`[OK] Backed up previous settings \u2192 ${N}`),this.log(""),this.log("Setup complete! Next steps:"),r?(this.log(" 1. Install always-on API: rulemetric service install"),this.log(" 2. Start Claude Code in any project \u2014 all sessions tracked automatically"),this.log(""),this.log("The API service starts on login and restarts on crash.")):P?(this.log(" 1. Start Claude Code \u2014 sessions are captured by the hooks just installed"),this.log(""),this.log("No proxy means no mitmproxy / CA cert needed. The hooks capture full"),this.log("sessions on their own; re-run without --no-proxy to also capture system"),this.log("prompts for instruction-effectiveness linking.")):(this.log(" 1. Start Claude Code \u2014 sessions are captured by hooks immediately"),b?this.log(" 2. Full-depth capture is ON \u2014 the proxy is live on :"+s+"."):this.log(" 2. Enable full depth (proxy not yet live): rulemetric proxy start"),this.log(""),this.log("Hooks capture every session (lifecycle + transcript). The proxy adds the"),this.log("rendered system prompt (instruction-effectiveness linking) + cross-tool capture."),this.log(""),this.log("To capture traffic from other clients (Python, curl, etc.):"),this.log(' eval "$(rulemetric proxy env --all)"'));let j=mt(a,v);j&&this.log(j),await M(),Y("hooks_installed",{proxy:b,caTrusted:p,reason:g,installers:S,global:r},this.config.version);let T=await yt();this.log(""),T.available?this.log(`[OK] tmux found${T.version?` (v${T.version})`:""} \u2014 live send enabled`):this.log("[!!] tmux not found \u2014 live send will fall back to opening Terminal. Install with: brew install tmux")}installMitmproxy(){for(let[i,r]of[["pipx",["install","mitmproxy"]],["uv",["tool","install","mitmproxy"]],["brew",["install","mitmproxy"]]]){let a=f(i);if(a&&(this.log(` Installing via ${i}...`),l(a,[...r],{stdio:"inherit"}).status===0))return!0}return!1}isCACertTrusted(){return process.platform==="darwin"?l("security",["verify-cert","-c",o],{stdio:"pipe"}).status===0:process.platform==="linux"?u("/usr/local/share/ca-certificates/mitmproxy-ca.crt"):process.platform==="win32"?l("certutil",["-verify",o],{stdio:"pipe"}).status===0:!1}trustCACert(){return process.platform==="darwin"?l("sudo",["security","add-trusted-cert","-d","-r","trustRoot","-k","/Library/Keychains/System.keychain",o],{stdio:"inherit"}).status===0:process.platform==="linux"?l("sudo",["cp",o,"/usr/local/share/ca-certificates/mitmproxy-ca.crt"],{stdio:"inherit"}).status!==0?!1:l("sudo",["update-ca-certificates"],{stdio:"inherit"}).status===0:process.platform==="win32"?l("certutil",["-addstore","-f","Root",o],{stdio:"inherit"}).status===0:!1}};export{K as default};
@@ -1,2 +1,2 @@
1
- import{C as x,F as k,J as C,K as S,o as h,s as p,t as g,w as v,x as y,z as R}from"../../chunk-VLXCQ2DC.js";import"../../chunk-I2DZGJRR.js";import{c as f,l as d}from"../../chunk-MVM6OGAF.js";import"../../chunk-KKDHD4XA.js";import"../../chunk-SZ62CP55.js";import{a}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as i}from"../../chunk-ZLLER3HP.js";import{existsSync as n,readFileSync as A,writeFileSync as j}from"node:fs";import{spawnSync as t}from"node:child_process";import{homedir as O}from"node:os";import{join as c}from"node:path";var r=c(O(),".mitmproxy","mitmproxy-ca-cert.pem");function N(){return n(r)?process.platform==="darwin"?t("sudo",["security","remove-trusted-cert","-d",r],{stdio:"inherit"}).status===0:process.platform==="linux"?t("sudo",["rm","-f","/usr/local/share/ca-certificates/mitmproxy-ca.crt"],{stdio:"inherit"}).status!==0?!1:t("sudo",["update-ca-certificates","--fresh"],{stdio:"inherit"}).status===0:process.platform==="win32"?t("certutil",["-delstore","Root","mitmproxy"],{stdio:"inherit"}).status===0:!1:!1}i(N,"untrustCACert");var u=class extends a{static{i(this,"HooksUninstall")}static description="Remove session tracking hooks from the current project";static examples=["<%= config.bin %> hooks uninstall"];async run(){let w=c(process.cwd(),".claude"),l=h(w,f);if(l.length===0){this.log("No .claude/settings.json or .claude/settings.local.json found \u2014 nothing to uninstall.");return}let e=!1,m=!1;for(let o of l)o.recoveredBackup&&this.log(`[!!] ${o.configPath} was not valid JSON \u2014 backed up to ${o.recoveredBackup}; continuing.`),o.removedHooks&&this.log(`Removed RuleMetric hooks from .claude/${o.fileName}`),o.removedProxyEnv&&(this.log(`Removed HTTPS_PROXY, NO_PROXY and NODE_EXTRA_CA_CERTS from .claude/${o.fileName}`),m=!0),o.removedStatusline&&this.log(`Removed RuleMetric statusline shim from .claude/${o.fileName}`),e=e||o.changed;e||this.log("No hooks or proxy config found \u2014 nothing to uninstall."),p(process.cwd())&&(this.log("Removed RuleMetric hooks from .cursor/hooks.json"),e=!0),g()&&(this.log("Removed RuleMetric hooks from ~/.cursor/hooks.json"),e=!0);let s=c(process.cwd(),".cursor","settings.json");if(n(s))try{let o=JSON.parse(A(s,"utf-8"));o["http.proxy"]?.includes("localhost")&&(delete o["http.proxy"],delete o["http.proxyStrictSSL"],j(s,JSON.stringify(o,null,2)+`
2
- `),this.log("Removed proxy config from .cursor/settings.json"),e=!0)}catch{}y(process.cwd())&&(this.log("Removed RuleMetric hooks from .github/hooks/"),e=!0),C(process.cwd())&&(this.log("Removed RuleMetric block from .agents/hooks.json"),e=!0),S()&&(this.log("Removed RuleMetric block from ~/.gemini/config/hooks.json"),e=!0),v(process.cwd())&&(this.log("Removed proxy config from .vscode/settings.json"),e=!0),x()&&(this.log("Removed proxy config from VS Code user settings"),e=!0),k()&&(this.log("Removed proxy config from Cursor user settings"),e=!0),R()&&(this.log("Removed HTTPS_PROXY LaunchAgent"),e=!0),m&&n(r)&&(this.log("Removing the mitmproxy CA from the system trust store (requires sudo)..."),N()?this.log("[OK] mitmproxy CA untrusted."):(this.log("[!!] Could not untrust the CA automatically. Remove it manually:"),process.platform==="darwin"?this.log(` sudo security remove-trusted-cert -d ${r}`):process.platform==="linux"&&this.log(" sudo rm -f /usr/local/share/ca-certificates/mitmproxy-ca.crt && sudo update-ca-certificates --fresh"))),d()&&this.log("Gateway stopped.")}};export{u as default};
1
+ import{C as j,F as b,J as A,K as w,o as R,s as k,t as x,w as C,x as S,z as P}from"../../chunk-VLXCQ2DC.js";import"../../chunk-I2DZGJRR.js";import{e as v,n as y}from"../../chunk-QWCEZEDO.js";import"../../chunk-KKDHD4XA.js";import"../../chunk-SZ62CP55.js";import{a as p}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as l}from"../../chunk-ZLLER3HP.js";import{existsSync as c,readFileSync as N,writeFileSync as T}from"node:fs";import{spawnSync as s}from"node:child_process";import{homedir as O}from"node:os";import{join as u}from"node:path";import{Flags as a}from"@oclif/core";var i=u(O(),".mitmproxy","mitmproxy-ca-cert.pem");function E(){return c(i)?process.platform==="darwin"?s("sudo",["security","remove-trusted-cert","-d",i],{stdio:"inherit"}).status===0:process.platform==="linux"?s("sudo",["rm","-f","/usr/local/share/ca-certificates/mitmproxy-ca.crt"],{stdio:"inherit"}).status!==0?!1:s("sudo",["update-ca-certificates","--fresh"],{stdio:"inherit"}).status===0:process.platform==="win32"?s("certutil",["-delstore","Root","mitmproxy"],{stdio:"inherit"}).status===0:!1:!1}l(E,"untrustCACert");var m=class f extends p{static{l(this,"HooksUninstall")}static flags={global:a.boolean({description:"Remove the GLOBAL install (~/.claude) rather than this project",default:!1}),"project-dir":a.string({description:"Project directory to clean (defaults to cwd)"}),"user-hooks":a.boolean({description:"Also strip user-level Cursor/Antigravity hooks (~/.cursor, ~/.gemini)",default:!0,allowNo:!0})};static description="Remove session tracking hooks from a project (or the global install)";static examples=["<%= config.bin %> hooks uninstall","<%= config.bin %> hooks uninstall --global","<%= config.bin %> hooks uninstall --project-dir ~/work/repo-a","<%= config.bin %> hooks uninstall --no-user-hooks"];async run(){let{flags:r}=await this.parse(f),t=r.global?O():r["project-dir"]??process.cwd(),d=u(t,".claude");r.global&&this.log(`Removing the GLOBAL install \u2192 ${d}`);let h=R(d,v);if(h.length===0){this.log("No .claude/settings.json or .claude/settings.local.json found \u2014 nothing to uninstall.");return}let e=!1,g=!1;for(let o of h)o.recoveredBackup&&this.log(`[!!] ${o.configPath} was not valid JSON \u2014 backed up to ${o.recoveredBackup}; continuing.`),o.removedHooks&&this.log(`Removed RuleMetric hooks from .claude/${o.fileName}`),o.removedProxyEnv&&(this.log(`Removed HTTPS_PROXY, NO_PROXY and NODE_EXTRA_CA_CERTS from .claude/${o.fileName}`),g=!0),o.removedStatusline&&this.log(`Removed RuleMetric statusline shim from .claude/${o.fileName}`),e=e||o.changed;e||this.log("No hooks or proxy config found \u2014 nothing to uninstall."),k(t)&&(this.log("Removed RuleMetric hooks from .cursor/hooks.json"),e=!0),r["user-hooks"]&&x()&&(this.log("Removed RuleMetric hooks from ~/.cursor/hooks.json"),e=!0);let n=u(t,".cursor","settings.json");if(c(n))try{let o=JSON.parse(N(n,"utf-8"));o["http.proxy"]?.includes("localhost")&&(delete o["http.proxy"],delete o["http.proxyStrictSSL"],T(n,JSON.stringify(o,null,2)+`
2
+ `),this.log("Removed proxy config from .cursor/settings.json"),e=!0)}catch{}S(t)&&(this.log("Removed RuleMetric hooks from .github/hooks/"),e=!0),A(t)&&(this.log("Removed RuleMetric block from .agents/hooks.json"),e=!0),r["user-hooks"]&&w()&&(this.log("Removed RuleMetric block from ~/.gemini/config/hooks.json"),e=!0),C(t)&&(this.log("Removed proxy config from .vscode/settings.json"),e=!0),j()&&(this.log("Removed proxy config from VS Code user settings"),e=!0),b()&&(this.log("Removed proxy config from Cursor user settings"),e=!0),P()&&(this.log("Removed HTTPS_PROXY LaunchAgent"),e=!0),g&&c(i)&&(this.log("Removing the mitmproxy CA from the system trust store (requires sudo)..."),E()?this.log("[OK] mitmproxy CA untrusted."):(this.log("[!!] Could not untrust the CA automatically. Remove it manually:"),process.platform==="darwin"?this.log(` sudo security remove-trusted-cert -d ${i}`):process.platform==="linux"&&this.log(" sudo rm -f /usr/local/share/ca-certificates/mitmproxy-ca.crt && sudo update-ca-certificates --fresh"))),y()&&this.log("Gateway stopped.")}};export{m as default};
@@ -1,3 +1,3 @@
1
- import{c as f}from"../../chunk-MVM6OGAF.js";import"../../chunk-KKDHD4XA.js";import"../../chunk-SZ62CP55.js";import{a as h}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as m}from"../../chunk-ZLLER3HP.js";import{Flags as i}from"@oclif/core";import{existsSync as v}from"node:fs";import{homedir as x}from"node:os";import{join as g}from"node:path";var o=g(x(),".mitmproxy","mitmproxy-ca-cert.pem"),l=class d extends h{static{m(this,"ProxyEnv")}static description="Print shell env vars to route any client through the RuleMetric proxy";static examples=["<%= config.bin %> proxy env","<%= config.bin %> proxy env --shell fish",'eval "$(rulemetric proxy env)"',"rulemetric proxy env --python"];static flags={shell:i.string({char:"s",default:"posix",description:"Shell format (posix, fish, powershell)",options:["posix","fish","powershell"]}),python:i.boolean({default:!1,description:"Include Python-specific env vars (REQUESTS_CA_BUNDLE, SSL_CERT_FILE)"}),node:i.boolean({default:!1,description:"Include Node.js-specific env vars (NODE_EXTRA_CA_CERTS)"}),all:i.boolean({default:!1,description:"Include env vars for all runtimes"}),vscode:i.boolean({default:!1,description:"Output VS Code settings.json snippet for Copilot proxy"})};async run(){let{flags:s}=await this.parse(d),y=s.shell,c=s.all,a=s.python||c,p=s.node||c,u=v(o),n=`http://localhost:${f}`;if(u||(this.warn(`CA certificate not found at ${o}
1
+ import{e as f}from"../../chunk-QWCEZEDO.js";import"../../chunk-KKDHD4XA.js";import"../../chunk-SZ62CP55.js";import{a as h}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a as m}from"../../chunk-ZLLER3HP.js";import{Flags as i}from"@oclif/core";import{existsSync as v}from"node:fs";import{homedir as x}from"node:os";import{join as g}from"node:path";var o=g(x(),".mitmproxy","mitmproxy-ca-cert.pem"),l=class d extends h{static{m(this,"ProxyEnv")}static description="Print shell env vars to route any client through the RuleMetric proxy";static examples=["<%= config.bin %> proxy env","<%= config.bin %> proxy env --shell fish",'eval "$(rulemetric proxy env)"',"rulemetric proxy env --python"];static flags={shell:i.string({char:"s",default:"posix",description:"Shell format (posix, fish, powershell)",options:["posix","fish","powershell"]}),python:i.boolean({default:!1,description:"Include Python-specific env vars (REQUESTS_CA_BUNDLE, SSL_CERT_FILE)"}),node:i.boolean({default:!1,description:"Include Node.js-specific env vars (NODE_EXTRA_CA_CERTS)"}),all:i.boolean({default:!1,description:"Include env vars for all runtimes"}),vscode:i.boolean({default:!1,description:"Output VS Code settings.json snippet for Copilot proxy"})};async run(){let{flags:s}=await this.parse(d),y=s.shell,c=s.all,a=s.python||c,p=s.node||c,u=v(o),n=`http://localhost:${f}`;if(u||(this.warn(`CA certificate not found at ${o}
2
2
  Run 'rulemetric hooks install' or 'rulemetric proxy setup' to generate it.`),this.exit(1)),s.vscode){let e={"http.proxy":n,"http.proxyStrictSSL":u,"github.copilot.advanced":{"debug.overrideProxyUrl":n}};this.log(JSON.stringify(e,null,2));return}let r=[{key:"HTTPS_PROXY",value:n,comment:"Route HTTPS through RuleMetric gateway"},{key:"HTTP_PROXY",value:n,comment:"Route HTTP through RuleMetric gateway"}];r.push({key:"SSL_CERT_FILE",value:o,comment:"Trust mitmproxy CA (generic \u2014 works with most libraries)"}),(p||!a&&!p)&&r.push({key:"NODE_EXTRA_CA_CERTS",value:o,comment:"Trust mitmproxy CA (Node.js)"}),a&&(r.push({key:"REQUESTS_CA_BUNDLE",value:o,comment:"Trust mitmproxy CA (Python requests / httpx)"}),r.push({key:"CURL_CA_BUNDLE",value:o,comment:"Trust mitmproxy CA (curl / libcurl)"}));let t=[];for(let e of r)switch(y){case"fish":e.comment&&t.push(`# ${e.comment}`),t.push(`set -gx ${e.key} "${e.value}"`);break;case"powershell":e.comment&&t.push(`# ${e.comment}`),t.push(`$env:${e.key} = "${e.value}"`);break;default:e.comment&&t.push(`# ${e.comment}`),t.push(`export ${e.key}="${e.value}"`)}this.log(t.join(`
3
3
  `))}};export{l as default};
@@ -1 +1 @@
1
- import{c as m,d as o,i as l,j as d}from"../../chunk-MVM6OGAF.js";import"../../chunk-KKDHD4XA.js";import{b as p,c as u,d as g}from"../../chunk-SZ62CP55.js";import{a as c}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a}from"../../chunk-ZLLER3HP.js";import{spawnSync as x}from"node:child_process";import{existsSync as M,readFileSync as P}from"node:fs";import{homedir as I}from"node:os";import{join as y}from"node:path";var D=y(I(),".config","rulemetric"),f=y(D,"proxy.pid"),e=class h extends c{static{a(this,"ProxyStatus")}static description="Check gateway and context capture proxy status";static examples=["<%= config.bin %> proxy status"];async run(){if(await this.parse(h),l()){let n=d();this.log(`Gateway: running (PID ${n}) on :${m}`)}else this.log("Gateway: not running");if(!M(f)){this.log("Mitmproxy: not running \u2014 routing direct (no capture)");return}let i=P(f,"utf-8").trim();if(i.startsWith("docker:")){let n=i.slice(7),r=x("docker",["container","inspect","-f","{{.State.Status}}",n],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}),s=r.stdout?.trim();r.status===0&&s==="running"?this.log(`Mitmproxy: running in Docker (container: ${n}) on :${o} \u2014 capturing context`):this.log(`Mitmproxy: container ${s||"not running"} (stale)`);return}let t=Number.parseInt(i,10);if(Number.isNaN(t)){this.log("Mitmproxy: not running (invalid PID file)");return}g(t,p)?this.log(`Mitmproxy: running (PID ${t}) on :${o} \u2014 capturing context`):u(t)?this.log(`Mitmproxy: not running (PID ${t} was reused by another process \u2014 stale PID file)`):this.log("Mitmproxy: not running (stale PID file)")}};export{e as default};
1
+ import{e as m,f as o,k as l,l as d}from"../../chunk-QWCEZEDO.js";import"../../chunk-KKDHD4XA.js";import{b as p,c as u,d as g}from"../../chunk-SZ62CP55.js";import{a as c}from"../../chunk-PPKPCXJD.js";import"../../chunk-IZTIYR5Q.js";import"../../chunk-V44SRRYR.js";import"../../chunk-U6XEU573.js";import"../../chunk-VLOX6KOM.js";import"../../chunk-3AV3GTMP.js";import"../../chunk-H2ORWIEY.js";import"../../chunk-O6C2UGBY.js";import{a}from"../../chunk-ZLLER3HP.js";import{spawnSync as x}from"node:child_process";import{existsSync as M,readFileSync as P}from"node:fs";import{homedir as I}from"node:os";import{join as y}from"node:path";var D=y(I(),".config","rulemetric"),f=y(D,"proxy.pid"),e=class h extends c{static{a(this,"ProxyStatus")}static description="Check gateway and context capture proxy status";static examples=["<%= config.bin %> proxy status"];async run(){if(await this.parse(h),l()){let n=d();this.log(`Gateway: running (PID ${n}) on :${m}`)}else this.log("Gateway: not running");if(!M(f)){this.log("Mitmproxy: not running \u2014 routing direct (no capture)");return}let i=P(f,"utf-8").trim();if(i.startsWith("docker:")){let n=i.slice(7),r=x("docker",["container","inspect","-f","{{.State.Status}}",n],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}),s=r.stdout?.trim();r.status===0&&s==="running"?this.log(`Mitmproxy: running in Docker (container: ${n}) on :${o} \u2014 capturing context`):this.log(`Mitmproxy: container ${s||"not running"} (stale)`);return}let t=Number.parseInt(i,10);if(Number.isNaN(t)){this.log("Mitmproxy: not running (invalid PID file)");return}g(t,p)?this.log(`Mitmproxy: running (PID ${t}) on :${o} \u2014 capturing context`):u(t)?this.log(`Mitmproxy: not running (PID ${t} was reused by another process \u2014 stale PID file)`):this.log("Mitmproxy: not running (stale PID file)")}};export{e as default};