@rulemetric/cli 0.7.35 → 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 (62) hide show
  1. package/dist/chunk-47YDQYTD.js +14 -0
  2. package/dist/chunk-6NML7IVJ.js +1 -0
  3. package/dist/chunk-BL4BN6RU.js +1 -0
  4. package/dist/{chunk-W2MOTOQE.js → chunk-BUWWFHGO.js} +1 -1
  5. package/dist/{chunk-OPYGOXZM.js → chunk-C5PSIJ7S.js} +1 -1
  6. package/dist/{chunk-TG6TKU4Y.js → chunk-CRIFP3QP.js} +1 -1
  7. package/dist/chunk-DKGKOSW3.js +1 -0
  8. package/dist/chunk-G5BXZT6F.js +1 -0
  9. package/dist/{chunk-QRPNGXLN.js → chunk-HUADECKZ.js} +1 -1
  10. package/dist/{chunk-7A4UVQ7U.js → chunk-IQTSUAGM.js} +1 -1
  11. package/dist/chunk-JGLVVIEM.js +1 -0
  12. package/dist/{chunk-HV45MQSU.js → chunk-JIJKIPE6.js} +1 -1
  13. package/dist/{chunk-6QKI756T.js → chunk-MDPN46EY.js} +1 -1
  14. package/dist/{chunk-QH7PCQHM.js → chunk-MQ47NLPC.js} +1 -1
  15. package/dist/chunk-QWCEZEDO.js +4 -0
  16. package/dist/{chunk-LETTPEG4.js → chunk-VSUL3MNG.js} +1 -1
  17. package/dist/chunk-VTA6HDVW.js +11 -0
  18. package/dist/{chunk-G6XGDHGC.js → chunk-XA4KSQEC.js} +1 -1
  19. package/dist/chunk-ZYI66XKV.js +1 -0
  20. package/dist/commands/diagnostics.js +1 -1
  21. package/dist/commands/evals/agent.js +1 -1
  22. package/dist/commands/evals/benchmark.js +1 -1
  23. package/dist/commands/evals/optimize.js +1 -1
  24. package/dist/commands/gateway/ensure.js +1 -1
  25. package/dist/commands/hooks/install.js +1 -1
  26. package/dist/commands/hooks/uninstall.js +2 -2
  27. package/dist/commands/proxy/env.js +1 -1
  28. package/dist/commands/proxy/status.js +1 -1
  29. package/dist/commands/sessions/list.js +1 -1
  30. package/dist/commands/setup.js +1 -1
  31. package/dist/dashboard/Dashboard.js +1 -1
  32. package/dist/dashboard/data.js +1 -1
  33. package/dist/{dist-FAVALJ5C.js → dist-BC6GMBXV.js} +1 -1
  34. package/dist/lib/agent-loop.js +1 -1
  35. package/dist/lib/eval-benchmark.js +1 -1
  36. package/dist/lib/evolution-cost.js +1 -0
  37. package/dist/lib/gateway-entry.js +1 -1
  38. package/dist/lib/gateway-lifecycle.js +1 -1
  39. package/dist/lib/gateway.js +1 -1
  40. package/dist/lib/handlers/cron-instruction-evolution.js +1 -1
  41. package/dist/lib/handlers/cron-suggest-instructions.js +1 -1
  42. package/dist/lib/handlers/process-announcement.js +1 -1
  43. package/dist/lib/handlers/process-changelog.js +1 -1
  44. package/dist/lib/handlers/process-eval.js +1 -1
  45. package/dist/lib/handlers/process-launch.js +1 -1
  46. package/dist/lib/handlers/process-memory-ab.js +1 -1
  47. package/dist/lib/handlers/process-run-cleanup.js +1 -1
  48. package/dist/lib/manual-tasks.js +1 -1
  49. package/dist/lib/optimize-compare.js +1 -1
  50. package/dist/lib/setup-steps.js +1 -1
  51. package/dist/lib/worktree.js +1 -1
  52. package/oclif.manifest.json +358 -330
  53. package/package.json +6 -6
  54. package/dist/chunk-3DLVY7LD.js +0 -1
  55. package/dist/chunk-6IVMG65E.js +0 -11
  56. package/dist/chunk-DNF4HDI6.js +0 -14
  57. package/dist/chunk-MLXQCK7V.js +0 -1
  58. package/dist/chunk-MVM6OGAF.js +0 -4
  59. package/dist/chunk-PHALR5JB.js +0 -1
  60. package/dist/chunk-PMWVDXTP.js +0 -1
  61. package/dist/chunk-WKXTY5AM.js +0 -1
  62. /package/dist/{chunk-7DFNBRLY.js → chunk-5DIOZDDZ.js} +0 -0
@@ -0,0 +1,14 @@
1
+ import{c as I}from"./chunk-VUGRXM7R.js";import{e as v}from"./chunk-QWCEZEDO.js";import{a as y,b as R}from"./chunk-KKDHD4XA.js";import{a}from"./chunk-ZLLER3HP.js";import{spawn as O}from"node:child_process";import*as T from"node:fs";import*as h from"node:http";import*as m from"node:net";import*as E from"node:os";import*as w from"node:path";var S=8788,b=3e3,N=500,$=6e4,B=w.join(E.homedir(),".config","rulemetric","proxy-addon.version"),P=w.join(E.homedir(),".config","rulemetric","proxy.pid"),u=!1;var H=null,_=0,C="unknown",f=null;function c(e){let t=new Date().toISOString();console.log(`[${t}] ${e}`)}a(c,"log");function D(){try{return T.readFileSync(B,"utf-8").trim()||null}catch{return null}}a(D,"readAddonVersion");function L(e,t){if(e==="unknown"||!t)return;let n=D();if(!n||n==="unknown"||n===H)return;if(H=n,n===e){c(`addon version matches gateway (${e})`);return}let o=Date.now()-_;if(o<$){c(`addon version drift (gateway=${e}, addon=${n}); restart cooldown active (${Math.round(($-o)/1e3)}s left)`);return}c(`addon version drift detected (gateway=${e}, addon=${n}). Restarting proxy to pick up latest code.`),_=Date.now(),M(t)}a(L,"maybeRestartOnDrift");function M(e){if(!e)return c("cannot restart proxy: no CLI entry recorded (RULEMETRIC_CLI_ENTRY unset)"),!1;try{return O(process.execPath,[e,"proxy","restart"],{detached:!0,stdio:"ignore"}).unref(),!0}catch(t){return c(`restart spawn failed: ${t.message}`),!1}}a(M,"spawnProxyRestart");function Y(){try{let e=T.readFileSync(P,"utf-8").trim();return/^\d+$/.test(e)}catch{return!1}}a(Y,"proxyCrashEvidence");function x(e){let t=m.connect({port:e,timeout:N});t.on("connect",()=>{t.destroy(),u||(u=!0,c(`mitmproxy up on :${e}, routing through proxy`)),f?.onHealthCheck(!0)}),t.on("error",()=>{u&&(u=!1,c(`mitmproxy down on :${e}, routing direct`)),f?.onHealthCheck(!1)}),t.on("timeout",()=>{t.destroy(),u&&(u=!1,c(`mitmproxy timeout on :${e}, routing direct`)),f?.onHealthCheck(!1)})}a(x,"checkProxyHealth");function U(e,t,n,o){let[i,s]=(e.url??"").split(":"),d=parseInt(s,10)||443;if(u){let r=m.connect({port:o,host:"127.0.0.1"});r.on("connect",()=>{r.write(`CONNECT ${e.url} HTTP/1.1\r
2
+ Host: ${e.url}\r
3
+ \r
4
+ `)});let l=Buffer.alloc(0),p=a(g=>{l=Buffer.concat([l,g]),l.toString().includes(`\r
5
+ \r
6
+ `)&&(r.removeListener("data",p),t.write(`HTTP/1.1 200 Connection Established\r
7
+ \r
8
+ `),n.length>0&&r.write(n),t.pipe(r),r.pipe(t))},"onData");r.on("data",p),r.on("error",g=>{c(`proxy socket error for ${e.url}: ${g.message}, falling back to direct`),A(e,t,n,i,d)}),t.on("error",()=>{r.destroy()})}else A(e,t,n,i,d)}a(U,"handleConnect");function A(e,t,n,o,i){let s=m.connect({port:i,host:o});s.on("connect",()=>{t.write(`HTTP/1.1 200 Connection Established\r
9
+ \r
10
+ `),n.length>0&&s.write(n),t.pipe(s),s.pipe(t)}),s.on("error",d=>{c(`upstream error for ${e.url}: ${d.message}`),t.end(`HTTP/1.1 502 Bad Gateway\r
11
+ \r
12
+ `)}),t.on("error",()=>{s.destroy()})}a(A,"connectDirect");function V(e,t,n){if(e.url===y){t.writeHead(200,{"content-type":"application/json"}),t.end(JSON.stringify({service:R,version:C,pid:process.pid,mitmproxyAlive:u}));return}let o=e.url??"",i;try{i=new URL(o)}catch{t.writeHead(400),t.end("Bad Request");return}let s={hostname:u?"127.0.0.1":i.hostname,port:u?n:parseInt(i.port,10)||80,path:u?o:i.pathname+i.search,method:e.method,headers:e.headers},d=h.request(s,r=>{t.writeHead(r.statusCode??502,r.headers),r.pipe(t)});d.on("error",r=>{c(`HTTP proxy error for ${o}: ${r.message}`),t.writeHead(502),t.end("Bad Gateway")}),e.pipe(d)}a(V,"handleRequest");function J(e=v,t=S,n={}){let o=n.cliVersion??process.env.RULEMETRIC_CLI_VERSION??"unknown",i=n.cliEntry??process.env.RULEMETRIC_CLI_ENTRY??null;C=o,f=new I({hasCrashEvidence:Y,respawn:a(()=>M(i),"respawn"),log:c});let s=h.createServer((r,l)=>{V(r,l,t)});s.on("connect",(r,l,p)=>{U(r,l,p,t)}),s.on("clientError",(r,l)=>{l.writable&&l.end(`HTTP/1.1 400 Bad Request\r
13
+ \r
14
+ `)});let d=setInterval(()=>{x(t),L(o,i)},b);return x(t),L(o,i),s.listen(e,"127.0.0.1",()=>{c(`gateway listening on 127.0.0.1:${e} (mitmproxy target: :${t}, cli version: ${o})`)}),{server:s,healthInterval:d}}a(J,"startGateway");export{S as a,J as b};
@@ -0,0 +1 @@
1
+ import{c as C}from"./chunk-TIOKY2IA.js";import{a as H}from"./chunk-ZYVWALMS.js";import{a as A}from"./chunk-NKPLTT7J.js";import{a as E}from"./chunk-HUADECKZ.js";import{a as I}from"./chunk-TVHT6H42.js";import{a as x}from"./chunk-H7J27U4P.js";import{b as S}from"./chunk-BUWWFHGO.js";import{a as M}from"./chunk-IQTSUAGM.js";import{a as L}from"./chunk-CRIFP3QP.js";import{a as y}from"./chunk-RSKQRVPJ.js";import{a as P}from"./chunk-SWSGNEVO.js";import{a as N}from"./chunk-BPQ66YTY.js";import{a as k}from"./chunk-UF6US7VU.js";import{a as _}from"./chunk-DKGKOSW3.js";import{b as R}from"./chunk-IXLDCX7M.js";import{a as T}from"./chunk-JIJKIPE6.js";import{b as h}from"./chunk-5RBLIVBF.js";import{j as b}from"./chunk-ZYI66XKV.js";import{d as w}from"./chunk-NTKO4H2K.js";import{b as f,e as v,f as p}from"./chunk-H2ORWIEY.js";import{a as s}from"./chunk-ZLLER3HP.js";var W={process_eval:E,process_insights:I,process_launch:S,process_send_message:y,process_conversation:A,process_session_goal:H,distill_memories:R,memory_ab:M,process_announcement:T,process_run_cleanup:L,cron_suggest_instructions:_,cron_refresh_skills:k,cron_refresh_pricing:N,cron_eval_autorun:P,cron_instruction_evolution:b,process_judge_review:x},D=Object.keys(W),F=new Set(["process_announcement","process_run_cleanup","memory_ab"]);function J(e=process.env){return e.DATABASE_URL?D:D.filter(n=>!F.has(n))}s(J,"availableCapabilities");var U=3e4,K=3e4,G=3e4,V=250,B=5e3,q=`thin-agent-${process.pid}`,g=null;function Q(e,n,r,l){let c;try{let d=w();c={claude:d.claudeBin!=null,codex:d.codexBin!=null,codexModel:d.codexConfiguredModel}}catch{}let i=s(d=>{p("/api/workers/heartbeat",{workerType:"cli-worker",clientName:q,clientVersion:l,workerVersion:"0.1.0",currentJobId:null,inFlightCount:0,lastError:null,status:d,metadata:{capabilities:e,mode:"thin-agent",llmEngines:c}}).then(u=>{let t=u?.advisory;t&&t.message!==g?(g=t.message,a(r,{event:"worker_advisory",code:t.code,message:t.message})):t||(g=null)}).catch(u=>{a(r,{event:"presence_heartbeat_error",error:u instanceof Error?u.message:String(u)})})},"send");i("alive");let o=setInterval(()=>i("alive"),G);n.addEventListener("abort",()=>{clearInterval(o),i("shutting_down")},{once:!0})}s(Q,"startPresenceHeartbeat");function a(e,n){try{e(JSON.stringify({ts:new Date().toISOString(),...n}))}catch{e(`[agent-loop] log_error event=${n.event}`)}}s(a,"structuredLog");function O(e,n){return n.aborted?Promise.resolve(!1):e<=0?Promise.resolve(!0):new Promise(r=>{let l=setTimeout(()=>{n.removeEventListener("abort",c),r(!0)},e),c=s(()=>{clearTimeout(l),n.removeEventListener("abort",c),r(!1)},"onAbort");n.addEventListener("abort",c,{once:!0})})}s(O,"abortableSleep");async function X(e,n){let r=`capabilities=${encodeURIComponent(e.join(","))}&waitMs=${n}`,l=await v(`/api/work/next?${r}`);return l==null||typeof l=="string"?null:l}s(X,"pollForWork");function z(e,n){return{logger:{info:s(r=>n(r),"info"),warn:s(r=>n(r),"warn"),error:s(r=>n(r),"error")},job:{attempts:e}}}s(z,"makeHelpers");async function Y(e,n,r){let l=W[e.kind],c=Date.now();if(a(r,{event:"claim",jobId:e.id,kind:e.kind,attempts:e.attempts}),!l){let o=`unknown kind: ${e.kind}`;a(r,{event:"fail",jobId:e.id,kind:e.kind,terminal:!0,error:o}),await p(`/api/work/${e.id}/fail`,{leaseToken:e.leaseToken,error:o,terminal:!0}).catch(()=>{});return}let i=setInterval(()=>{a(r,{event:"heartbeat",jobId:e.id}),p(`/api/work/${e.id}/heartbeat`,{leaseToken:e.leaseToken}).catch(o=>{a(r,{event:"heartbeat_error",jobId:e.id,error:o instanceof Error?o.message:String(o)})})},n);try{let o=z(e.attempts,r),d=await l(e.payload,o)??{};clearInterval(i),a(r,{event:"complete",jobId:e.id,kind:e.kind,durationMs:Date.now()-c}),await p(`/api/work/${e.id}/complete`,{leaseToken:e.leaseToken,result:d})}catch(o){clearInterval(i);let d=h(o),u=o instanceof Error?o.message:String(o);a(r,{event:"fail",jobId:e.id,kind:e.kind,durationMs:Date.now()-c,terminal:d,error:u}),await p(`/api/work/${e.id}/fail`,{leaseToken:e.leaseToken,error:u,terminal:d}).catch(t=>{a(r,{event:"fail_post_error",jobId:e.id,error:t instanceof Error?t.message:String(t)})})}}s(Y,"runOne");async function we(e){let n=e.log??(()=>{}),r=e.pollWaitMs??U,l=e.heartbeatIntervalMs??K,c=e.capabilities??J(),i=V;a(n,{event:"agent_start",capabilities:c,pollWaitMs:r,heartbeatIntervalMs:l}),Q(c,e.signal,n,e.version),C({signal:e.signal,log:n}).catch(t=>{a(n,{event:"tt_heartbeat_fatal",error:t instanceof Error?t.message:String(t)})});let o=5*6e4,d=0,u=s(()=>{if(!e.readInstalledVersion||!e.version)return!1;let t=Date.now();if(t-d<o)return!1;d=t;let m=e.readInstalledVersion();return!!(m&&m!==e.version)},"versionDrifted");for(;!e.signal.aborted;){if(u()){a(n,{event:"agent_version_drift",bootVersion:e.version,installedVersion:e.readInstalledVersion?.()??null}),e.onVersionDrift?.();break}let t=null;try{t=await X(c,r)}catch(m){let $=m instanceof f?m.statusCode:void 0;if(a(n,{event:"poll_error",status:$,error:m instanceof Error?m.message:String(m)}),!await O(i,e.signal))break;i=Math.min(i*2,B);continue}if(!t){if(a(n,{event:"poll_204"}),!await O(i,e.signal))break;i=Math.min(i*2,B);continue}i=V,await Y(t,l,n)}a(n,{event:"agent_stop"})}s(we,"runAgentLoop");export{W as a,D as b,J as c,X as d,we as e};
@@ -0,0 +1 @@
1
+ import{a as m,c as d}from"./chunk-G5BXZT6F.js";import{a as s}from"./chunk-ZLLER3HP.js";var h=4,i=1,_=2,f=.0641;function x(e,r=f){return!(e>0)||!(r>=0)?null:Math.sqrt((m+d)**2*r/e)}s(x,"mdeForPairs");function w(e,r=f){if(!(e>0))throw new Error("pairsForMde: mde must be > 0");if(!(r>=0))throw new Error("pairsForMde: variance must be >= 0");return Math.max(1,Math.ceil((m+d)**2*r/e**2))}s(w,"pairsForMde");var p=10,c=128;function R(e){let r=e.autoEvolvePairs;if(r==null)return{minPairs:p,configured:!1};let a=typeof r=="number"?r:typeof r=="string"?Number(r):NaN;if(!Number.isFinite(a)||a<1)return{minPairs:p,configured:!1,note:`metadata.autoEvolvePairs=${JSON.stringify(r)} is not a positive number \u2014 using the default ${p}`};let n=Math.floor(a);return{minPairs:Math.min(c,Math.max(10,n)),configured:!0,...n>c?{note:`metadata.autoEvolvePairs=${n} clamped to the ${c}-pair ceiling`}:n<10?{note:`metadata.autoEvolvePairs=${n} raised to ${10} \u2014 a controlled verdict is refused below ${10} pairs, so a smaller batch buys a certain refusal. Use metadata.autoEvolvePaused to stop the spend instead.`}:{}}}s(R,"readPairBudget");function $(e){let r=e.autoEvolvePaused;return r===!0||r==="true"}s($,"isEvolutionPaused");function O(e){let{liveCases:r,passes:a,variance:n}=e,t=Math.max(0,r)*Math.max(0,a),o=t*2,l=t*2;return{liveCases:r,passes:a,plannedPairs:t,proposalCalls:i,executorCalls:o,graderCalls:l,totalCalls:i+o+l,maxCalls:i+o+l*_,mde:x(t,n)}}s(O,"estimateEvolutionCost");function L(e){let{runs:r,plannedPairs:a,usablePairs:n,passes:t,liveCases:o,wallMs:l,variance:g}=e,b=e.proposalCalls??i,v=e.verdictPairs??n,C=r.length,E=r.filter(P=>P.status==="completed"&&P.grading?.judge_model!=null).length;return{proposalCalls:b,executorCalls:C,graderCalls:E,modelCalls:b+C+E,plannedPairs:a,usablePairs:n,verdictPairs:v,passes:t,liveCases:o,mde:x(v,g),wallMs:l}}s(L,"observedEvolutionCost");function A(e){return e==null?"n/a":`${(e*100).toFixed(1)}pp`}s(A,"pp");function D(e){return`${e.liveCases} case(s) x ${e.passes} pass(es) = ${e.plannedPairs} planned pair(s), ~${e.totalCalls} model calls (up to ${e.maxCalls}) \u2014 resolves an effect of +/-${A(e.mde)} at 80% power`}s(D,"describeEvolutionCost");export{h as a,i as b,_ as c,f as d,x as e,w as f,p as g,c as h,R as i,$ as j,O as k,L as l,A as m,D as n};
@@ -1 +1 @@
1
- import{b as l}from"./chunk-6QKI756T.js";import{a as p}from"./chunk-5RBLIVBF.js";import{h}from"./chunk-H2ORWIEY.js";import{a as c}from"./chunk-ZLLER3HP.js";async function g(t){if(!t.worktree?.create)return t;let{branch:e,baseRef:s}=t.worktree,n=await l({repoRoot:t.projectPath,branch:e,baseRef:s});return{...t,projectPath:n.path,gitBranch:n.branch}}c(g,"resolveWorktreeForLaunch");async function L(t,e){let{mirrorId:s,tool:n}=t,{config:r}=t,a=c(o=>e.logger.info(o),"log");if(e.job.attempts>1)throw new p(`process_launch is not safe to retry (attempt ${e.job.attempts}). Re-launch manually.`);r=await g(r),r.worktree?.create&&a(`Worktree resolved: ${r.projectPath} (branch ${r.gitBranch})`),a(`Launching ${n}...`);let{getLauncher:f}=await import("./dist-FAVALJ5C.js"),i=await f(n).launch(r);a(`Launch completed: sessionId=${i.sessionId}`);let u={...i,worktreePath:r.worktree?.create?r.projectPath:void 0,runId:r.runId};return await h(`/api/launch-jobs/${s}/state`,{result:u}).catch(o=>{a(`result persist failed: ${o instanceof Error?o.message:String(o)}`)}),u}c(L,"processLaunch");export{g as a,L as b};
1
+ import{b as l}from"./chunk-MDPN46EY.js";import{a as p}from"./chunk-5RBLIVBF.js";import{h}from"./chunk-H2ORWIEY.js";import{a as c}from"./chunk-ZLLER3HP.js";async function g(t){if(!t.worktree?.create)return t;let{branch:e,baseRef:s}=t.worktree,n=await l({repoRoot:t.projectPath,branch:e,baseRef:s});return{...t,projectPath:n.path,gitBranch:n.branch}}c(g,"resolveWorktreeForLaunch");async function L(t,e){let{mirrorId:s,tool:n}=t,{config:r}=t,a=c(o=>e.logger.info(o),"log");if(e.job.attempts>1)throw new p(`process_launch is not safe to retry (attempt ${e.job.attempts}). Re-launch manually.`);r=await g(r),r.worktree?.create&&a(`Worktree resolved: ${r.projectPath} (branch ${r.gitBranch})`),a(`Launching ${n}...`);let{getLauncher:f}=await import("./dist-BC6GMBXV.js"),i=await f(n).launch(r);a(`Launch completed: sessionId=${i.sessionId}`);let u={...i,worktreePath:r.worktree?.create?r.projectPath:void 0,runId:r.runId};return await h(`/api/launch-jobs/${s}/state`,{result:u}).catch(o=>{a(`result persist failed: ${o instanceof Error?o.message:String(o)}`)}),u}c(L,"processLaunch");export{g as a,L as b};
@@ -1 +1 @@
1
- import{c as m,d as p}from"./chunk-ZL4MZMUK.js";import{a as C}from"./chunk-N7TGRFVZ.js";import{f as c,i as f}from"./chunk-3DLVY7LD.js";import{a as r}from"./chunk-ZLLER3HP.js";import*as a from"node:fs/promises";import*as g from"node:path";import{eq as b}from"drizzle-orm";async function v(e){let n=e;for(let t=0;t<50;t++){try{return await a.stat(g.join(n,"pnpm-workspace.yaml")),n}catch{}let i=g.dirname(n);if(i===n)return null;n=i}return null}r(v,"findRepoRoot");async function k(e){if(e)try{return await a.readFile(e,"utf-8")}catch{return null}let n=await v(process.cwd())??process.cwd(),t=g.join(n,"CHANGELOG.md");try{return await a.readFile(t,"utf-8")}catch{return null}}r(k,"readChangelog");var _="https://rulemetric.com";function D(e){let n=e.date??new Date().toISOString().slice(0,10),t=C({version:e.version,date:n,sections:e.sections,unsubscribeUrl:"{{unsubscribe_url}}",recipientName:"{{recipient_name}}",productUrl:_});return{version:e.version,releaseDate:n,subject:t.subject,htmlBody:t.html,textBody:t.text,sections:e.sections}}r(D,"renderRow");async function R(e={}){let n=e.db??f(),t=e.logger??{info:r(s=>console.log(s),"info"),warn:r(s=>console.warn(s),"warn")},i=await k(e.changelogPath);if(i===null)return t.info("[cron_check_changelog] CHANGELOG.md not found; nothing to do"),{createdCount:0,skippedCount:0};let y=m(i),h=p(y);if(h.length===0)return t.info("[cron_check_changelog] No announceable entries; nothing to do"),{createdCount:0,skippedCount:0};let d=0,l=0;for(let s of h){if((await n.select({id:c.id}).from(c).where(b(c.version,s.version)).limit(1)).length>0){l++;continue}let o=D(s);try{await n.insert(c).values({version:o.version,releaseDate:o.releaseDate,subject:o.subject,htmlBody:o.htmlBody,textBody:o.textBody,sections:o.sections,status:"draft"}),d++,t.info(`[cron_check_changelog] Created draft announcement for ${o.version}`)}catch(u){let w=u instanceof Error?u.message:String(u);if(/duplicate key|unique/i.test(w)){l++;continue}throw u}}return t.info(`[cron_check_changelog] Done: created ${d}, skipped ${l}`),{createdCount:d,skippedCount:l}}r(R,"processChangelog");export{R as a};
1
+ import{c as m,d as p}from"./chunk-ZL4MZMUK.js";import{a as C}from"./chunk-N7TGRFVZ.js";import{f as c,i as f}from"./chunk-JGLVVIEM.js";import{a as r}from"./chunk-ZLLER3HP.js";import*as a from"node:fs/promises";import*as g from"node:path";import{eq as b}from"drizzle-orm";async function v(e){let n=e;for(let t=0;t<50;t++){try{return await a.stat(g.join(n,"pnpm-workspace.yaml")),n}catch{}let i=g.dirname(n);if(i===n)return null;n=i}return null}r(v,"findRepoRoot");async function k(e){if(e)try{return await a.readFile(e,"utf-8")}catch{return null}let n=await v(process.cwd())??process.cwd(),t=g.join(n,"CHANGELOG.md");try{return await a.readFile(t,"utf-8")}catch{return null}}r(k,"readChangelog");var _="https://rulemetric.com";function D(e){let n=e.date??new Date().toISOString().slice(0,10),t=C({version:e.version,date:n,sections:e.sections,unsubscribeUrl:"{{unsubscribe_url}}",recipientName:"{{recipient_name}}",productUrl:_});return{version:e.version,releaseDate:n,subject:t.subject,htmlBody:t.html,textBody:t.text,sections:e.sections}}r(D,"renderRow");async function R(e={}){let n=e.db??f(),t=e.logger??{info:r(s=>console.log(s),"info"),warn:r(s=>console.warn(s),"warn")},i=await k(e.changelogPath);if(i===null)return t.info("[cron_check_changelog] CHANGELOG.md not found; nothing to do"),{createdCount:0,skippedCount:0};let y=m(i),h=p(y);if(h.length===0)return t.info("[cron_check_changelog] No announceable entries; nothing to do"),{createdCount:0,skippedCount:0};let d=0,l=0;for(let s of h){if((await n.select({id:c.id}).from(c).where(b(c.version,s.version)).limit(1)).length>0){l++;continue}let o=D(s);try{await n.insert(c).values({version:o.version,releaseDate:o.releaseDate,subject:o.subject,htmlBody:o.htmlBody,textBody:o.textBody,sections:o.sections,status:"draft"}),d++,t.info(`[cron_check_changelog] Created draft announcement for ${o.version}`)}catch(u){let w=u instanceof Error?u.message:String(u);if(/duplicate key|unique/i.test(w)){l++;continue}throw u}}return t.info(`[cron_check_changelog] Done: created ${d}, skipped ${l}`),{createdCount:d,skippedCount:l}}r(R,"processChangelog");export{R as a};
@@ -1,2 +1,2 @@
1
- import{c as R}from"./chunk-6QKI756T.js";import{a as P}from"./chunk-5RBLIVBF.js";import{b as s,c as r,i as j}from"./chunk-3DLVY7LD.js";import{a as g}from"./chunk-ZLLER3HP.js";import{and as y,eq as l,isNotNull as I}from"drizzle-orm";async function O($,p={}){let k=p.db??j(),b=p.removeWorktreeFn??R,n=p.log??(e=>process.stderr.write(`[process_run_cleanup] ${e}
1
+ import{c as R}from"./chunk-MDPN46EY.js";import{a as P}from"./chunk-5RBLIVBF.js";import{b as s,c as r,i as j}from"./chunk-JGLVVIEM.js";import{a as g}from"./chunk-ZLLER3HP.js";import{and as y,eq as l,isNotNull as I}from"drizzle-orm";async function O($,p={}){let k=p.db??j(),b=p.removeWorktreeFn??R,n=p.log??(e=>process.stderr.write(`[process_run_cleanup] ${e}
2
2
  `)),{runId:t}=$,[i]=await k.select({id:s.id,userId:s.userId,projectPath:s.projectPath}).from(s).where(l(s.id,t)).limit(1);if(!i)throw new P(`Run ${t} not found`);if(!i.projectPath)throw new P(`Run ${t} has no projectPath; cannot resolve a repo root for worktree cleanup`);let c=i.projectPath,v=await k.select({id:r.id,projectPath:r.projectPath}).from(r).where(y(l(r.runId,t),l(r.userId,i.userId),I(r.endedAt))),a=[],u=0,d=0,h=0,m=0,w=new Set;for(let e of v)if(!(!e.projectPath||e.projectPath===c)&&!w.has(e.projectPath)){w.add(e.projectPath);try{let o=await b({repoRoot:c,worktreePath:e.projectPath});o.removed?(u++,a.push({sessionId:e.id,worktreePath:e.projectPath,status:"removed"}),n(`removed worktree ${e.projectPath} (session ${e.id})`)):o.reason==="dirty"?(d++,a.push({sessionId:e.id,worktreePath:e.projectPath,status:"skipped-dirty"}),n(`skipped dirty worktree ${e.projectPath} (session ${e.id}) \u2014 uncommitted changes`)):(h++,a.push({sessionId:e.id,worktreePath:e.projectPath,status:"absent"}),n(`worktree absent ${e.projectPath} (session ${e.id})`))}catch(o){let f=o instanceof Error?o.message:String(o);m++,a.push({sessionId:e.id,worktreePath:e.projectPath,status:"error",error:f.slice(0,1e3)}),n(`error removing worktree ${e.projectPath} (session ${e.id}): ${f}`)}}return n(`run ${t} cleanup: removed=${u} skippedDirty=${d} absent=${h} errored=${m}`),{runId:t,repoRoot:c,removed:u,skippedDirty:d,absent:h,errored:m,worktrees:a}}g(O,"processRunCleanup");export{O as a};
@@ -0,0 +1 @@
1
+ import{b as j}from"./chunk-ZL4MZMUK.js";import{a as k}from"./chunk-TDD7IOV2.js";import{a as p}from"./chunk-MODXEGCU.js";import{d as y,f as S}from"./chunk-B3BHB26P.js";import{e as i,f as l}from"./chunk-H2ORWIEY.js";import{a as g}from"./chunk-ZLLER3HP.js";import{readFileSync as b}from"node:fs";import E from"node:path";import $ from"node:os";var N=5,L=Number(process.env.RULEMETRIC_MAX_SUGGESTION_PROJECTS??10),T=48,M=.5,d=400;async function O(){let m=E.join($.homedir(),".config","rulemetric","skills-registry.json");try{let o=b(m,"utf-8"),s=JSON.parse(o);return Date.now()-new Date(s.generatedAt).getTime()>T*60*60*1e3}catch{return!0}}g(O,"checkSkillsRegistryStale");var X=g(async(m,o)=>{let s=y();if(s==="none"){o.logger.warn("No LLM backend available (claude CLI missing and ANTHROPIC_API_KEY unset); skipping suggestion compute");return}o.logger.info(`Scoring backend: ${s}`);let r;try{r=(await i("/api/sessions/project-paths?limit="+L)).projectPaths}catch(e){o.logger.warn(`Failed to fetch project paths: ${e instanceof Error?e.message:String(e)}`);return}if(r.length===0){o.logger.info("No recent project paths; nothing to score");return}let u=new Map;try{let e=await i("/api/projects?limit=200");for(let t of e.projects??[])t.primaryCheckoutPath&&u.set(p(t.primaryCheckoutPath),t.id)}catch(e){o.logger.warn(`Failed to fetch projects for id resolution: ${e instanceof Error?e.message:String(e)}`)}let a=new Map;try{let e=await i(`/api/catalog?limit=200&contentPreview=${d}`);for(let t of e)a.set(t.id,{id:t.id,name:t.name,description:t.description??"",tags:t.tags??[],contentPreview:(t.contentPreview??"").slice(0,d)})}catch(e){o.logger.warn(`Failed to fetch catalog: ${e instanceof Error?e.message:String(e)}`)}try{let e=await i("/api/instructions?limit=100");for(let t of e.instructions??[])a.has(t.id)||a.set(t.id,{id:t.id,name:t.name,description:t.description??"",tags:t.tags??[],contentPreview:(t.content??"").slice(0,d)})}catch(e){o.logger.warn(`Failed to fetch personal instructions: ${e instanceof Error?e.message:String(e)}`)}let c=[...a.values()];if(c.length===0){o.logger.info("No candidate instructions; nothing to score");return}o.logger.info(`Scoring ${c.length} candidates across ${r.length} project(s)`);let f=0;for(let e of r)try{let t=p(e),w=k(t);if(w.length===0){o.logger.info(`Skipping ${t}: insufficient language signals`);continue}let C={name:E.basename(t),description:null,languages:w,topics:[],dependencies:[]},I=j(C,c),P=await S(I,"",4096);if(!P){o.logger.warn(`LLM returned null for ${t} (backend ${s})`);continue}let h=(P.recommendations??[]).filter(n=>typeof n.instructionId=="string"&&typeof n.score=="number"&&typeof n.reason=="string").map(n=>({instructionId:n.instructionId,score:n.score,reason:n.reason})).filter(n=>n.score>=M).sort((n,_)=>_.score-n.score).slice(0,N);if(h.length===0){o.logger.info(`No suggestions over threshold for ${t}`);continue}let R=u.get(t);await l("/api/instruction-suggestions/batch-upsert",{projectPath:t,...R?{projectId:R}:{},suggestions:h.map(n=>({instructionId:n.instructionId,score:n.score,reason:n.reason}))}),f++}catch(t){o.logger.warn(`Failed to score ${e}: ${t instanceof Error?t.message:String(t)}`)}if(await O())try{await l("/api/instruction-suggestions/mark-stale",{}),o.logger.warn("Skills registry is stale (>48h); marked all suggestions stale")}catch{}o.logger.info(`Done: scored ${f}/${r.length} projects`)},"cronSuggestInstructions");export{X as a};
@@ -0,0 +1 @@
1
+ import{a as i}from"./chunk-ZLLER3HP.js";var _=1.959963984540054;function F(n,t,e=_){if(t===0)return{lower:0,upper:1};let o=n/t,r=e*e,c=1+r/t,l=(o+r/(2*t))/c,u=e/c*Math.sqrt(o*(1-o)/t+r/(4*t*t));return{lower:Math.max(0,l-u),upper:Math.min(1,l+u)}}i(F,"wilsonInterval");function O(n,t){let e=n,o=t,r=e+o;if(r===0)return{pValue:1,nDiscordant:0};let c=Math.min(e,o),l=Math.pow(.5,r),u=l;for(let s=1;s<=c;s++)l*=(r-s+1)/s,u+=l;return{pValue:Math.min(1,2*u),nDiscordant:r}}i(O,"mcnemarExact");function k(n,t,e=10){return{sufficient:n>=e&&t>=e,minN:e,nWith:n,nWithout:t,shortfall:{with:Math.max(0,e-n),without:Math.max(0,e-t)}}}i(k,"assessSufficiency");function M(n){let t=n>>>0;return()=>{t=t+1831565813|0;let e=Math.imul(t^t>>>15,1|t);return e=e+Math.imul(e^e>>>7,61|e)^e,((e^e>>>14)>>>0)/4294967296}}i(M,"seededRandom");function T(n,t){let e=n.length;if(e===1)return n[0];let o=(e-1)*t,r=Math.floor(o),c=Math.ceil(o);return r===c?n[r]:n[r]+(o-r)*(n[c]-n[r])}i(T,"sortedQuantile");function L(n,t={}){let e=n.length;if(e===0)return{estimate:0,lower:0,upper:0,iterations:0};let o=t.iterations??1e4,r=t.ciLevel??.95,c=M(t.seed??1),l=n.reduce((a,m)=>a+m,0)/e,u=new Array(o);for(let a=0;a<o;a++){let m=0;for(let h=0;h<e;h++)m+=n[c()*e|0];u[a]=m/e}u.sort((a,m)=>a-m);let s=(1-r)/2;return{estimate:l,lower:T(u,s),upper:T(u,1-s),iterations:o}}i(L,"pairedBootstrapCI");function U(n,t={}){let e=n.filter(d=>d.withScores.length>0&&d.withoutScores.length>0);if(e.length===0)return{estimate:0,lower:0,upper:0,pValue:1,iterations:0};let o=i(d=>d.reduce((p,g)=>p+g,0)/d.length,"mean"),r=e.map(d=>d.withScores.length*d.withoutScores.length/(d.withScores.length+d.withoutScores.length)),c=r.reduce((d,p)=>d+p,0),l=i(d=>d.reduce((p,g,w)=>p+r[w]*g,0)/c,"combine"),u=l(e.map(d=>o(d.withScores)-o(d.withoutScores))),s=t.iterations??1e4,a=t.ciLevel??.95,m=M(t.seed??1),h=new Array(s),S=0,A=0;for(let d=0;d<s;d++){let p=e.map(w=>{let $=0;for(let v=0;v<w.withScores.length;v++)$+=w.withScores[m()*w.withScores.length|0];let y=0;for(let v=0;v<w.withoutScores.length;v++)y+=w.withoutScores[m()*w.withoutScores.length|0];return $/w.withScores.length-y/w.withoutScores.length}),g=l(p);h[d]=g,g<=0&&S++,g>=0&&A++}h.sort((d,p)=>d-p);let b=(1-a)/2;return{estimate:u,lower:T(h,b),upper:T(h,1-b),pValue:Math.min(1,2*Math.min(S,A)/s),iterations:s}}i(U,"stratifiedBootstrapCI");function H(n,t){let e=n.length,o=t.length;if(e===0||o===0)return 0;let r=[...n.map(a=>({t:a,exposed:!0})),...t.map(a=>({t:a,exposed:!1}))].sort((a,m)=>a.t-m.t),c=0,l=0;for(;l<r.length;){let a=l;for(;a+1<r.length&&r[a+1].t===r[l].t;)a++;let m=(l+1+a+1)/2;for(let h=l;h<=a;h++)r[h].exposed&&(c+=m);l=a+1}let s=(c-e*(e+1)/2)/(e*o);return Math.abs(s-.5)}i(H,"cohortTimeSeparation");var C=.35,N=900*1e3;function j(n,t,e=C,o=N){if(n.length===0||t.length===0)return!1;let r=[...n,...t];return Math.max(...r)-Math.min(...r)<o?!1:H(n,t)>e}i(j,"isTimeSeparated");var G=i(n=>n===0||n===1,"isBinary");function J(n,t,e){return n.every(r=>r[t]!=null&&r[e]!=null)?n.reduce((r,c)=>r+(c[t]-c[e]),0)/n.length:null}i(J,"meanPairDelta");function W(n,t={}){let e=t.baseline??"no-rule",o=t.minN??10,r=n.length,c=n.map(d=>d.withScore-d.withoutScore),l=r===0?0:c.reduce((d,p)=>d+p,0)/r,u=L(c,{seed:t.seed,iterations:t.iterations}),s={lower:u.lower,upper:u.upper},a=n.every(d=>G(d.withScore)&&G(d.withoutScore)),m=null;if(a&&r>0){let d=0,p=0;for(let g of n)g.withScore===1&&g.withoutScore===0?d++:g.withScore===0&&g.withoutScore===1&&p++;m=O(d,p).pValue}let{sufficient:h}=k(r,r,o),S=s.lower>0||s.upper<0,b={mode:"controlled",baseline:e,delta:l,ci:s,pValue:m,significant:h&&S,sufficient:h,nWith:r,nWithout:r,costDelta:J(n,"withCost","withoutCost"),latencyDelta:J(n,"withLatency","withoutLatency"),confounded:!1};return h||(b.insufficientReason=`insufficient data: need >= ${o} paired tasks per cohort, have ${r}`),b}i(W,"buildControlledVerdict");var de=2;function z(n,t={}){let e=t.minN??10,o=t.minPerStratum??de,r=t.maxTimeSeparation??C,c=t.minStratumSpanMs??N,l=n.filter(f=>f.withScores.length>=o&&f.withoutScores.length>=o),u=l.filter(f=>f.withTimes!=null&&f.withoutTimes!=null&&j(f.withTimes,f.withoutTimes,r,c)),s=new Set(u.map(f=>f.key)),a=l.filter(f=>!s.has(f.key)),m=n.filter(f=>f.withScores.length>0&&f.withoutScores.length>0&&(f.withScores.length<o||f.withoutScores.length<o)).length,h=a.reduce((f,x)=>f+x.withScores.length,0),S=a.reduce((f,x)=>f+x.withoutScores.length,0),A=U(a,{seed:t.seed,iterations:t.iterations}),b={lower:A.lower,upper:A.upper},d=A.estimate,p=a.length>0&&h>=e&&S>=e,g=a.length>0?A.pValue:null,w=p&&(b.lower>0||b.upper<0),$=n.reduce((f,x)=>f+x.withScores.length+x.withoutScores.length,0),y=$>0?(h+S)/$:0,v={mode:"observational",baseline:t.baseline??"no-rule",delta:d,ci:b,pValue:g,significant:w,sufficient:p,nWith:h,nWithout:S,costDelta:null,latencyDelta:null,confounded:!0,strata:a.length,strataDroppedForTimeSeparation:u.length,coverage:y};if(!p){let f=m>0?` (${m} project(s) had both cohorts but fewer than ${o} sessions in one of them)`:"",x=u.length>0?` ${u.length} project-month(s) held both cohorts but their sessions are separated in time (exposure predicts when a session ran), so the difference within them is a calendar difference, not a treatment effect`:"";v.insufficientReason=a.length===0?u.length>0?`insufficient data: no comparable cohort.${x}${f}`:`insufficient data: no project has >= ${o} exposed AND >= ${o} unexposed sessions to compare within${f}`:`insufficient data: need >= ${e} sessions per cohort across comparable projects, have ${h} exposed / ${S} unexposed${f}${x?`.${x}`:""}`}return v}i(z,"buildStratifiedVerdict");function Q(n){let t=new Map;for(let e of n){let o=t.get(e.stratum);o||(o={key:e.stratum,withScores:[],withoutScores:[],withTimes:[],withoutTimes:[]},t.set(e.stratum,o)),(e.exposed?o.withScores:o.withoutScores).push(e.score),e.time!=null&&(e.exposed?o.withTimes:o.withoutTimes).push(e.time)}for(let e of t.values())(e.withTimes.length!==e.withScores.length||e.withoutTimes.length!==e.withoutScores.length)&&(delete e.withTimes,delete e.withoutTimes);return[...t.values()]}i(Q,"toStrata");var R=.05;function K(n,t={}){let e=t.trialIndex??0,o=t.seed??1,r=t.exposedFraction??.5,c=t.effect??0,l=M(o+e*2),u=n.map(s=>{let a=l()<r;return{stratum:s.stratum,score:a?s.score+c:s.score,exposed:a,time:s.time}});return z(Q(u),{seed:o+e*2+1,iterations:t.iterations??500,minN:t.minN,minPerStratum:t.minPerStratum})}i(K,"runCalibrationTrial");function q(n,t={}){let e=t.trials??200,o=[];for(let r=0;r<e;r++)o.push(K(n,{...t,trialIndex:r}));return D(o,t.effect??0)}i(q,"calibrate");function D(n,t){let e=0,o=0,r=0,c=0;for(let s of n)s.sufficient&&(e++,s.significant&&o++,r+=s.delta,c=Math.max(c,Math.abs(s.delta)));let l=e>0?o/e:0,u=F(o,e,_);return{trials:n.length,evaluated:e,insufficient:n.length-e,significantTrials:o,significantRate:l,significantRateCi:u,meanDelta:e>0?r/e:0,maxAbsDelta:c,alpha:R,effect:t,calibrated:t===0&&e>0&&u.lower<=R&&R<=u.upper}}i(D,"summarizeTrials");function I(n,t={}){return q(n,{...t,effect:0})}i(I,"aaCalibration");function Y(n,t,e={}){return q(n,{...e,effect:t})}i(Y,"powerCheck");var he=.8416212335729143;var te=[{ym:"2026-03",n:122,mean:.287},{ym:"2026-04",n:50,mean:.07},{ym:"2026-05",n:267,mean:.089},{ym:"2026-06",n:61,mean:.201},{ym:"2026-07",n:162,mean:.071}],B=662;function Z(n=2){let t=[];for(let e of te){let o=Math.round(e.n*e.mean);for(let r=0;r<e.n;r++)t.push({stratum:`proj-${r%n}|${e.ym}`,score:r<o?1:0})}if(n===2&&t.length!==B)throw new Error(`realisticCanaryCorpus: expected ${B} sessions, built ${t.length}`);return t}i(Z,"realisticCanaryCorpus");function ne(n=600){return Array.from({length:n},(t,e)=>({stratum:"only",score:e%4===0?1:0}))}i(ne,"flatCanaryCorpus");var oe=50,re=4,P={min:.2,max:.7};function me(n,t){let e=M(t),o=P.max-P.min;return Array.from({length:n},()=>P.min+e()*o)}i(me,"caseDifficulties");function ee(n,t,e){let o=0;for(let r=0;r<t;r++)e()<n&&o++;return o/t}i(ee,"passRate");function ie(n={}){let t=n.trialIndex??0,e=n.seed??1,o=n.cases??oe,r=n.assertions??re,c=n.effect??0,l=me(o,e),u=M(e+t*2),s=l.map(a=>({withScore:ee(a+c,r,u),withoutScore:ee(a,r,u)}));return W(s,{baseline:"prior-version",seed:e+t*2+1,iterations:n.iterations??500,minN:n.minN})}i(ie,"runControlledCalibrationTrial");function X(n={}){let t=n.trials??200,e=[];for(let o=0;o<t;o++)e.push(ie({...n,trialIndex:o}));return D(e,n.effect??0)}i(X,"controlledCalibration");function ae(n={}){return X({...n,effect:0})}i(ae,"controlledAaCalibration");function se(n,t={}){return X({...t,effect:n})}i(se,"controlledPowerCheck");var ce={maxSignificantRate:.15,maxMeanAbsDelta:.02,maxWorstCaseDelta:.15,powerProbeEffect:.2,minPower:.9,minPowerMeanDelta:.15};function E(n,t,e){let o=e.filter(r=>!r.ok).map(r=>r.why);return{name:n,passed:o.length===0,detail:o.length===0?`${n}: ok (rate=${t.significantRate.toFixed(3)}, meanDelta=${t.meanDelta.toFixed(4)}, evaluated=${t.evaluated}/${t.trials})`:`${n}: ${o.join("; ")}`,result:t}}i(E,"check");function pe(n={}){let t=n.trials??200,e=n.powerTrials??200,o=ce,r=[],c=I(ne(),{trials:t,seed:11});r.push(E("aa-flat",c,[{ok:c.calibrated,why:`\u03B1=${R} outside rate CI [${c.significantRateCi.lower.toFixed(3)}, ${c.significantRateCi.upper.toFixed(3)}]`},{ok:c.significantRate<o.maxSignificantRate,why:`false-positive rate ${c.significantRate.toFixed(3)} \u2265 ${o.maxSignificantRate}`},{ok:Math.abs(c.meanDelta)<o.maxMeanAbsDelta,why:`mean delta ${c.meanDelta.toFixed(4)} not centred on zero`}]));let l=I(Z(),{trials:t,seed:23});r.push(E("aa-realistic",l,[{ok:l.calibrated,why:`\u03B1=${R} outside rate CI [${l.significantRateCi.lower.toFixed(3)}, ${l.significantRateCi.upper.toFixed(3)}]`},{ok:l.significantRate<o.maxSignificantRate,why:`false-positive rate ${l.significantRate.toFixed(3)} \u2265 ${o.maxSignificantRate}`},{ok:Math.abs(l.meanDelta)<o.maxMeanAbsDelta,why:`mean delta ${l.meanDelta.toFixed(4)} not centred on zero`},{ok:l.maxAbsDelta<o.maxWorstCaseDelta,why:`worst single-trial delta ${l.maxAbsDelta.toFixed(3)} \u2265 ${o.maxWorstCaseDelta}`}]));let u=Y(Z(),o.powerProbeEffect,{trials:e,seed:5});r.push(E("power-observational",u,[{ok:u.significantRate>o.minPower,why:`detects +${o.powerProbeEffect} only ${u.significantRate.toFixed(3)} of the time`},{ok:u.meanDelta>o.minPowerMeanDelta,why:`measured mean delta ${u.meanDelta.toFixed(3)} understates the injected +${o.powerProbeEffect}`}]));let s=ae({trials:t,seed:31});r.push(E("aa-controlled",s,[{ok:s.calibrated,why:`\u03B1=${R} outside rate CI [${s.significantRateCi.lower.toFixed(3)}, ${s.significantRateCi.upper.toFixed(3)}]`},{ok:s.significantRate<o.maxSignificantRate,why:`false-positive rate ${s.significantRate.toFixed(3)} \u2265 ${o.maxSignificantRate}`},{ok:Math.abs(s.meanDelta)<o.maxMeanAbsDelta,why:`mean delta ${s.meanDelta.toFixed(4)} not centred on zero`}]));let a=se(o.powerProbeEffect,{trials:e,seed:37});r.push(E("power-controlled",a,[{ok:a.significantRate>o.minPower,why:`detects +${o.powerProbeEffect} only ${a.significantRate.toFixed(3)} of the time`}]));let m=r.filter(h=>!h.passed).map(h=>h.detail);return{green:m.length===0,checks:r,failures:m}}i(pe,"runPromotionCanary");var we=3,xe=7;export{_ as a,W as b,he as c,pe as d,we as e,xe as f};
@@ -1 +1 @@
1
- import{a as M}from"./chunk-5RBLIVBF.js";import{a as T}from"./chunk-YQ56FQEO.js";import{b as A}from"./chunk-CNOD6HWU.js";import{e as S}from"./chunk-L2CFSMBC.js";import{a as x}from"./chunk-4L2ZEIRE.js";import{c as C}from"./chunk-HMMO27U4.js";import{e as k,f as E,h as p}from"./chunk-H2ORWIEY.js";import{a as w}from"./chunk-ZLLER3HP.js";async function W(v,f){let{mirrorId:i,evalTargetId:g,config:o}=v,a=w(e=>f.logger.info(e),"log"),s=await k(`/api/eval-targets/${g}`),$=await k(`/api/eval-targets/${g}/evals`);if($.length===0&&o.generateIfEmpty){a("No eval cases on target \u2014 generating from content via local LLM...");let e=await A({content:s.content,name:s.name});if(e===null)throw new Error("Case generation requires an LLM backend (claude CLI on PATH or ANTHROPIC_API_KEY) \u2014 none available on this worker.");let n=[];for(let t of e)n.push(await E(`/api/eval-targets/${g}/evals`,t));$=n,a(`Generated ${n.length} eval case(s)`)}if($.length===0)throw new M("No evals defined for target");let G=o.runsPerEval??1,R=o.timeout??12e4,j=o.iteration??1,y=new Set;if(f.job.attempts>1)for(let n=0;;n+=100){let t=await k(`/api/eval-targets/${g}/runs?jobId=${i}&limit=100&offset=${n}`);for(let r of t)y.add(`${r.evalId}|${r.configuration}|${r.runNumber}|${r.iteration}`);if(t.length<100)break}let _=[{name:"with_target",content:s.content}];o.skipBaseline||_.push({name:"without_target"});let d=[];for(let e of $)for(let n of _)for(let t=1;t<=G;t++)y.has(`${e.id}|${n.name}|${t}|${j}`)||d.push({eval_:e,configuration:n.name,targetContent:n.content,runNumber:t});y.size>0&&a(`Resuming attempt ${f.job.attempts}: ${y.size} run(s) already persisted, ${d.length} remaining`);let l=d.length,u=0,m=Math.min(o.parallel??1,4);await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:0,current:null,message:`Starting ${l} eval runs (concurrency: ${m})...`}});let b=[];async function I(e){let n=`${e.configuration} \xB7 ${e.eval_.name} \xB7 run#${e.runNumber}`;a(`[${u+1}/${l}] ${n}`);let t=S({targetType:s.type,targetContent:e.targetContent,targetName:s.name});t.leakedFiles.length&&a(`\u26A0 CONTAMINATED ${n}: ${t.leakedFiles.join(", ")} survived the strip`);try{let r=await C({prompt:e.eval_.prompt,targetContent:t.systemPrompt,workDir:t.workDir,timeout:R,model:o.model}),c={};return!o.skipGrading&&e.eval_.expectations.length>0&&!r.error&&(c=await x({prompt:e.eval_.prompt,output:r.output,expectations:e.eval_.expectations,model:o.graderModel??o.model,timeout:R})),{jobId:i,evalId:e.eval_.id,evalTargetId:s.id,evalTargetVersion:s.version,configuration:e.configuration,runNumber:e.runNumber,iteration:j,status:r.error?"failed":"completed",outputs:{...r.error?{error:r.error}:{transcript:r.output,...r.model?{model:r.model}:{}},methodology:t.methodology,delivery:t.delivery,isolated:t.isWorktree,...t.leakedFiles.length?{leakedFiles:t.leakedFiles}:{}},timing:{duration_ms:r.durationMs,total_tokens:r.totalTokens},grading:c,worktree:t.isWorktree?!0:void 0}}finally{t.cleanup()}}if(w(I,"processItem"),m<=1)for(let e of d){let n=`${e.configuration} \xB7 ${e.eval_.name} \xB7 run#${e.runNumber}`;await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:u,current:n,message:`Executing ${n}...`}});let t=await I(e);await E("/api/eval-runs",t),b.push(t),u++,await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:u,current:n,message:`Completed ${n}`}})}else{a(`Running ${l} evals with concurrency=${m} (worktree isolation)`);for(let e=0;e<d.length;e+=m){let n=d.slice(e,e+m),t=`batch ${Math.floor(e/m)+1}/${Math.ceil(d.length/m)}`;await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:u,current:t,message:`Executing ${t} (${n.length} parallel)...`}});let r=await Promise.all(n.map(I));for(let c of r)await E("/api/eval-runs",c),b.push(c),u++;await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:u,current:t,message:`Completed ${t}`}})}}let P=J(b),h;if(!o.skipGrading&&b.some(e=>e.grading&&Object.keys(e.grading).length>0))try{a(`Running meta-judge for job ${i}...`);let e=$.map(n=>{let r=b.filter(c=>c.evalId===n.id&&c.configuration==="with_target")[0];return{evalName:n.name,prompt:n.prompt,expectations:n.expectations,grading:r?.grading?r.grading:null,output:r?.outputs?.transcript?.slice(0,500)}});h=await T({targetName:s.name,evalResults:e,model:o.graderModel??o.model,timeout:6e4}),a(`Meta-judge: quality=${h.quality_score}/5, issues=${h.issues.length}`)}catch(e){a(`Meta-judge failed (non-fatal): ${e instanceof Error?e.message:String(e)}`)}let N=h?{...P,meta_judgement:h}:P;return a(`Job ${i} completed: ${u}/${l} runs`),await p(`/api/eval-jobs/${i}/state`,{result:N}).catch(e=>{a(`result persist failed: ${e instanceof Error?e.message:String(e)}`)}),N}w(W,"processEval");function J(v){let f=v.filter(a=>a.status==="completed"),i=v.filter(a=>a.status==="failed"),g=f.filter(a=>{let s=a.grading;return s&&Object.keys(s).length>0}),o=g.length>0?g.reduce((a,s)=>a+(s.grading?.summary?.pass_rate??0),0)/g.length:null;return{total:v.length,completed:f.length,failed:i.length,avgPassRate:o}}w(J,"buildSummary");export{W as a};
1
+ import{a as T}from"./chunk-5RBLIVBF.js";import{a as S}from"./chunk-YQ56FQEO.js";import{b as A}from"./chunk-CNOD6HWU.js";import{e as x}from"./chunk-L2CFSMBC.js";import{a as C}from"./chunk-4L2ZEIRE.js";import{c as M}from"./chunk-HMMO27U4.js";import{e as k,f as E,h as p}from"./chunk-H2ORWIEY.js";import{a as w}from"./chunk-ZLLER3HP.js";async function W(v,f){let{mirrorId:i,evalTargetId:g,config:o}=v,a=w(e=>f.logger.info(e),"log"),s=await k(`/api/eval-targets/${g}`),$=await k(`/api/eval-targets/${g}/evals`);if($.length===0&&o.generateIfEmpty){a("No eval cases on target \u2014 generating from content via local LLM...");let e=await A({content:s.content,name:s.name});if(e===null)throw new Error("Case generation requires an LLM backend (claude CLI on PATH or ANTHROPIC_API_KEY) \u2014 none available on this worker.");let n=[];for(let t of e)n.push(await E(`/api/eval-targets/${g}/evals`,t));$=n,a(`Generated ${n.length} eval case(s)`)}if($.length===0)throw new T("No evals defined for target");let G=o.runsPerEval??1,R=o.timeout??12e4,j=o.iteration??1,y=new Set;if(f.job.attempts>1)for(let n=0;;n+=100){let t=await k(`/api/eval-targets/${g}/runs?jobId=${i}&limit=100&offset=${n}`);for(let r of t)y.add(`${r.evalId}|${r.configuration}|${r.runNumber}|${r.iteration}`);if(t.length<100)break}let _=[{name:"with_target",content:s.content}];o.skipBaseline||_.push({name:"without_target"});let d=[];for(let e of $)for(let n of _)for(let t=1;t<=G;t++)y.has(`${e.id}|${n.name}|${t}|${j}`)||d.push({eval_:e,configuration:n.name,targetContent:n.content,runNumber:t});y.size>0&&a(`Resuming attempt ${f.job.attempts}: ${y.size} run(s) already persisted, ${d.length} remaining`);let l=d.length,u=0,m=Math.min(o.parallel??1,4);await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:0,current:null,message:`Starting ${l} eval runs (concurrency: ${m})...`}});let b=[];async function I(e){let n=`${e.configuration} \xB7 ${e.eval_.name} \xB7 run#${e.runNumber}`;a(`[${u+1}/${l}] ${n}`);let t=x({targetType:s.type,targetContent:e.targetContent,targetName:s.name});t.leakedFiles.length&&a(`\u26A0 CONTAMINATED ${n}: ${t.leakedFiles.join(", ")} survived the strip`);try{let r=await M({prompt:e.eval_.prompt,targetContent:t.systemPrompt,workDir:t.workDir,timeout:R,model:o.model}),c={};return!o.skipGrading&&e.eval_.expectations.length>0&&!r.error&&(c=await C({prompt:e.eval_.prompt,output:r.output,expectations:e.eval_.expectations,model:o.graderModel??o.model,timeout:R})),{jobId:i,evalId:e.eval_.id,evalTargetId:s.id,evalTargetVersion:s.version,configuration:e.configuration,runNumber:e.runNumber,iteration:j,status:r.error?"failed":"completed",outputs:{...r.error?{error:r.error}:{transcript:r.output,...r.model?{model:r.model}:{}},methodology:t.methodology,delivery:t.delivery,isolated:t.isWorktree,...t.leakedFiles.length?{leakedFiles:t.leakedFiles}:{}},timing:{duration_ms:r.durationMs,total_tokens:r.totalTokens},grading:c,worktree:t.isWorktree?!0:void 0}}finally{t.cleanup()}}if(w(I,"processItem"),m<=1)for(let e of d){let n=`${e.configuration} \xB7 ${e.eval_.name} \xB7 run#${e.runNumber}`;await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:u,current:n,message:`Executing ${n}...`}});let t=await I(e);await E("/api/eval-runs",t),b.push(t),u++,await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:u,current:n,message:`Completed ${n}`}})}else{a(`Running ${l} evals with concurrency=${m} (worktree isolation)`);for(let e=0;e<d.length;e+=m){let n=d.slice(e,e+m),t=`batch ${Math.floor(e/m)+1}/${Math.ceil(d.length/m)}`;await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:u,current:t,message:`Executing ${t} (${n.length} parallel)...`}});let r=await Promise.all(n.map(I));for(let c of r)await E("/api/eval-runs",c),b.push(c),u++;await p(`/api/eval-jobs/${i}/progress`,{status:"running",progress:{total:l,completed:u,current:t,message:`Completed ${t}`}})}}let P=J(b),h;if(!o.skipGrading&&b.some(e=>e.grading&&Object.keys(e.grading).length>0))try{a(`Running meta-judge for job ${i}...`);let e=$.map(n=>{let r=b.filter(c=>c.evalId===n.id&&c.configuration==="with_target")[0];return{evalName:n.name,prompt:n.prompt,expectations:n.expectations,grading:r?.grading?r.grading:null,output:r?.outputs?.transcript?.slice(0,500)}});h=await S({targetName:s.name,evalResults:e,model:o.graderModel??o.model,timeout:6e4}),a(`Meta-judge: quality=${h.quality_score}/5, issues=${h.issues.length}`)}catch(e){a(`Meta-judge failed (non-fatal): ${e instanceof Error?e.message:String(e)}`)}let N=h?{...P,meta_judgement:h}:P;return a(`Job ${i} completed: ${u}/${l} runs`),await p(`/api/eval-jobs/${i}/state`,{result:N}).catch(e=>{a(`result persist failed: ${e instanceof Error?e.message:String(e)}`)}),N}w(W,"processEval");function J(v){let f=v.filter(a=>a.status==="completed"),i=v.filter(a=>a.status==="failed"),g=f.filter(a=>{let s=a.grading;return s&&Object.keys(s).length>0}),o=g.length>0?g.reduce((a,s)=>a+(s.grading?.summary?.pass_rate??0),0)/g.length:null;return{total:v.length,completed:f.length,failed:i.length,avgPassRate:o}}w(J,"buildSummary");export{W as a};
@@ -1 +1 @@
1
- import{d as u,e as t,i as x}from"./chunk-3DLVY7LD.js";import{a as E}from"./chunk-4L2ZEIRE.js";import{a as A}from"./chunk-WKXTY5AM.js";import{c as P}from"./chunk-HMMO27U4.js";import{a as f}from"./chunk-ZLLER3HP.js";import{eq as s}from"drizzle-orm";var v=f(m=>(m.summary.pass_rate??0)>=1?1:0,"fullPassScore");async function q(m,d={}){let r=d.db??x(),w=d.executeEval??P,y=d.grade??E,n=d.now??Date.now,[e]=await r.select().from(t).where(s(t.id,m.experimentId)).limit(1);if(!e)return{skipped:"not_found"};if(e.status==="completed"||e.status==="failed")return{skipped:"already_terminal",status:e.status};let[g]=await r.select({body:u.body}).from(u).where(s(u.id,e.memoryId)).limit(1);if(!g)return await r.update(t).set({status:"failed",error:"memory no longer exists",completedAt:new Date(n())}).where(s(t.id,e.id)),{skipped:"memory_gone",status:"failed"};await r.update(t).set({status:"running",startedAt:new Date(n())}).where(s(t.id,e.id));let b=e.expectations??[],l=e.model??void 0,a=[],h=0;try{for(let i=0;i<e.trials;i++){let c=await w({prompt:e.taskPrompt,targetContent:g.body,model:l}),p=await w({prompt:e.taskPrompt,model:l});if(c.error||p.error){h++;continue}let[D,M]=await Promise.all([y({prompt:e.taskPrompt,output:c.output,expectations:b,model:l}),y({prompt:e.taskPrompt,output:p.output,expectations:b,model:l})]);a.push({withScore:v(D),withoutScore:v(M),withLatency:c.durationMs/1e3,withoutLatency:p.durationMs/1e3})}if(a.length===0){let i=`no trials completed (${h}/${e.trials} runs errored \u2014 is the claude CLI available?)`;return await r.update(t).set({status:"failed",error:i,completedAt:new Date(n())}).where(s(t.id,e.id)),{status:"failed",requestedTrials:e.trials,completedTrials:0}}let o=A(a);return await r.update(t).set({status:"completed",result:{verdict:o,pairs:a,completedTrials:a.length,model:l??null},completedAt:new Date(n())}).where(s(t.id,e.id)),{status:"completed",requestedTrials:e.trials,completedTrials:a.length,significant:o.significant,delta:o.delta}}catch(o){let i=o instanceof Error?o.message:String(o);return await r.update(t).set({status:"failed",error:i.slice(0,500),completedAt:new Date(n())}).where(s(t.id,e.id)),{status:"failed",requestedTrials:e.trials,completedTrials:a.length}}}f(q,"processMemoryAb");export{q as a};
1
+ import{d as u,e as t,i as x}from"./chunk-JGLVVIEM.js";import{a as A}from"./chunk-4L2ZEIRE.js";import{b as P}from"./chunk-G5BXZT6F.js";import{c as E}from"./chunk-HMMO27U4.js";import{a as f}from"./chunk-ZLLER3HP.js";import{eq as s}from"drizzle-orm";var v=f(m=>(m.summary.pass_rate??0)>=1?1:0,"fullPassScore");async function q(m,d={}){let r=d.db??x(),w=d.executeEval??E,y=d.grade??A,n=d.now??Date.now,[e]=await r.select().from(t).where(s(t.id,m.experimentId)).limit(1);if(!e)return{skipped:"not_found"};if(e.status==="completed"||e.status==="failed")return{skipped:"already_terminal",status:e.status};let[g]=await r.select({body:u.body}).from(u).where(s(u.id,e.memoryId)).limit(1);if(!g)return await r.update(t).set({status:"failed",error:"memory no longer exists",completedAt:new Date(n())}).where(s(t.id,e.id)),{skipped:"memory_gone",status:"failed"};await r.update(t).set({status:"running",startedAt:new Date(n())}).where(s(t.id,e.id));let b=e.expectations??[],l=e.model??void 0,a=[],h=0;try{for(let i=0;i<e.trials;i++){let c=await w({prompt:e.taskPrompt,targetContent:g.body,model:l}),p=await w({prompt:e.taskPrompt,model:l});if(c.error||p.error){h++;continue}let[D,M]=await Promise.all([y({prompt:e.taskPrompt,output:c.output,expectations:b,model:l}),y({prompt:e.taskPrompt,output:p.output,expectations:b,model:l})]);a.push({withScore:v(D),withoutScore:v(M),withLatency:c.durationMs/1e3,withoutLatency:p.durationMs/1e3})}if(a.length===0){let i=`no trials completed (${h}/${e.trials} runs errored \u2014 is the claude CLI available?)`;return await r.update(t).set({status:"failed",error:i,completedAt:new Date(n())}).where(s(t.id,e.id)),{status:"failed",requestedTrials:e.trials,completedTrials:0}}let o=P(a);return await r.update(t).set({status:"completed",result:{verdict:o,pairs:a,completedTrials:a.length,model:l??null},completedAt:new Date(n())}).where(s(t.id,e.id)),{status:"completed",requestedTrials:e.trials,completedTrials:a.length,significant:o.significant,delta:o.delta}}catch(o){let i=o instanceof Error?o.message:String(o);return await r.update(t).set({status:"failed",error:i.slice(0,500),completedAt:new Date(n())}).where(s(t.id,e.id)),{status:"failed",requestedTrials:e.trials,completedTrials:a.length}}}f(q,"processMemoryAb");export{q as a};
@@ -0,0 +1 @@
1
+ import{a as p,c as Cr}from"./chunk-ZLLER3HP.js";import{boolean as So,pgTable as Or,text as Ze,timestamp as Ct,uuid as Ko}from"drizzle-orm/pg-core";import{pgTable as Xe,text as re,timestamp as Re,jsonb as Eo,uuid as $,primaryKey as bo}from"drizzle-orm/pg-core";var u=Xe("organizations",{id:$("id").primaryKey().defaultRandom(),name:re("name").unique().notNull(),slug:re("slug").unique().notNull(),metadata:Eo("metadata"),createdAt:Re("created_at",{withTimezone:!0}).defaultNow(),updatedAt:Re("updated_at",{withTimezone:!0}).defaultNow()}),h=Xe("teams",{id:$("id").primaryKey().defaultRandom(),orgId:$("org_id").references(()=>u.id,{onDelete:"cascade"}),name:re("name").notNull(),slug:re("slug").notNull(),metadata:Eo("metadata"),createdAt:Re("created_at",{withTimezone:!0}).defaultNow()}),se=Xe("user_organizations",{userId:$("user_id").notNull(),orgId:$("org_id").references(()=>u.id,{onDelete:"cascade"}).notNull(),role:re("role").notNull().default("member"),createdAt:Re("created_at",{withTimezone:!0}).defaultNow()},e=>[bo({columns:[e.userId,e.orgId]})]),ie=Xe("user_teams",{userId:$("user_id").notNull(),teamId:$("team_id").references(()=>h.id,{onDelete:"cascade"}).notNull(),role:re("role").notNull().default("member"),createdAt:Re("created_at",{withTimezone:!0}).defaultNow()},e=>[bo({columns:[e.userId,e.teamId]})]);var o=Or("profiles",{id:Ko("id").primaryKey(),email:Ze("email"),displayName:Ze("display_name"),activeOrgId:Ko("active_org_id").references(()=>u.id,{onDelete:"set null"}),isSuperadmin:So("is_superadmin").notNull().default(!1),claudeCodePlan:Ze("claude_code_plan"),planSource:Ze("plan_source").notNull().default("detected"),setupCompletedAt:Ct("setup_completed_at",{withTimezone:!0}),liveSendSkipped:So("live_send_skipped").notNull().default(!1),createdAt:Ct("created_at",{withTimezone:!0}).defaultNow(),updatedAt:Ct("updated_at",{withTimezone:!0}).defaultNow()});import{pgTable as Hr,text as de,timestamp as Lt,jsonb as qo,uuid as nt,integer as Ur,boolean as Vr,index as Bt}from"drizzle-orm/pg-core";import{boolean as Mr,jsonb as Lr,pgTable as Mt,primaryKey as Co,text as Q,timestamp as je,uniqueIndex as qt,uuid as W}from"drizzle-orm/pg-core";import{sql as Br}from"drizzle-orm";import{pgTable as Ot,text as x,timestamp as L,jsonb as et,uuid as R,integer as tt,boolean as qr,uniqueIndex as ot,index as De}from"drizzle-orm/pg-core";var r=Ot("instructions",{id:R("id").primaryKey().defaultRandom(),name:x("name").notNull(),description:x("description").notNull(),type:x("type").notNull().default("instruction"),scope:x("scope").notNull(),scopeRef:R("scope_ref"),version:x("version").notNull(),content:x("content").notNull(),frontmatter:et("frontmatter").notNull(),slots:et("slots"),tags:x("tags").array(),compatibility:x("compatibility").array(),createdBy:R("created_by"),createdAt:L("created_at",{withTimezone:!0}).defaultNow(),updatedAt:L("updated_at",{withTimezone:!0}).defaultNow(),archived:qr("archived").default(!1),archivedAt:L("archived_at",{withTimezone:!0}),archivedBy:R("archived_by"),forkedFromId:R("forked_from_id").references(()=>r.id,{onDelete:"set null"}),upstreamVersion:x("upstream_version"),badge:x("badge"),contentHash:x("content_hash"),contextIdentity:x("context_identity"),scanScore:tt("scan_score"),scanFindings:et("scan_findings"),popularityScore:tt("popularity_score"),sourceUpdatedAt:L("source_updated_at",{withTimezone:!0})},e=>[ot("instructions_name_scope_ref_idx").on(e.name,e.scope,e.scopeRef),De("idx_instructions_scope").on(e.scope,e.scopeRef),De("idx_instructions_created_by").on(e.createdBy),De("idx_instructions_context_identity").on(e.createdBy,e.contextIdentity),De("idx_instructions_public_recency").on(e.scope,e.sourceUpdatedAt.desc())]),Po=Ot("instruction_version_identities",{id:R("id").primaryKey().defaultRandom(),instructionId:R("instruction_id").notNull().references(()=>r.id,{onDelete:"cascade"}),contentHash:x("content_hash").notNull(),versionOrdinal:tt("version_ordinal").notNull(),content:x("content"),firstSeenAt:L("first_seen_at",{withTimezone:!0}).notNull().defaultNow(),lastSeenAt:L("last_seen_at",{withTimezone:!0}).notNull().defaultNow(),createdAt:L("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[ot("instruction_version_identities_hash_unique").on(e.instructionId,e.contentHash),ot("instruction_version_identities_ordinal_unique").on(e.instructionId,e.versionOrdinal),De("idx_ivi_instruction").on(e.instructionId)]),ae=Ot("instruction_versions",{id:R("id").primaryKey().defaultRandom(),instructionId:R("instruction_id").references(()=>r.id,{onDelete:"cascade"}),versionNumber:tt("version_number").notNull(),content:x("content").notNull(),frontmatter:et("frontmatter").notNull(),changeSummary:x("change_summary"),createdBy:R("created_by"),createdAt:L("created_at",{withTimezone:!0}).defaultNow()},e=>[ot("instruction_versions_instruction_version_idx").on(e.instructionId,e.versionNumber)]);var s=Mt("projects",{id:W("id").primaryKey().defaultRandom(),orgId:W("org_id").references(()=>u.id,{onDelete:"cascade"}),name:Q("name").notNull(),description:Q("description"),githubRepo:Q("github_repo"),gitRemoteUrl:Q("git_remote_url"),gitRootCommit:Q("git_root_commit"),gitRemoteAliases:Q("git_remote_aliases").array().notNull().default([]),metadata:Lr("metadata"),createdBy:W("created_by"),createdAt:je("created_at",{withTimezone:!0}).defaultNow(),updatedAt:je("updated_at",{withTimezone:!0}).defaultNow()},e=>[qt("projects_org_name_idx").on(e.orgId,e.name),qt("projects_git_remote_url_unique").on(e.gitRemoteUrl).where(Br`${e.gitRemoteUrl} IS NOT NULL`)]),B=Mt("project_instructions",{projectId:W("project_id").references(()=>s.id,{onDelete:"cascade"}).notNull(),instructionId:W("instruction_id").references(()=>r.id,{onDelete:"cascade"}).notNull(),addedAt:je("added_at",{withTimezone:!0}).defaultNow(),addedBy:W("added_by")},e=>[Co({columns:[e.projectId,e.instructionId]})]),Oo=Mt("project_checkouts",{projectId:W("project_id").references(()=>s.id,{onDelete:"cascade"}).notNull(),path:Q("path").notNull(),isWorktree:Mr("is_worktree").notNull().default(!1),firstSeen:je("first_seen",{withTimezone:!0}).notNull().defaultNow(),lastSeen:je("last_seen",{withTimezone:!0}).notNull().defaultNow()},e=>[Co({columns:[e.projectId,e.path]}),qt("project_checkouts_path_unique").on(e.path)]);var g=Hr("agent_runs",{id:nt("id").primaryKey().defaultRandom(),userId:nt("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),orgId:nt("org_id").references(()=>u.id,{onDelete:"set null"}),projectId:nt("project_id").references(()=>s.id,{onDelete:"set null"}),projectPath:de("project_path"),gitRemote:de("git_remote"),baseBranch:de("base_branch"),title:de("title"),prompt:de("prompt"),toolSpec:qo("tool_spec").notNull().default([]),autoWorktree:Vr("auto_worktree").notNull().default(!0),status:de("status").notNull().default("pending"),sessionCount:Ur("session_count").notNull().default(0),metadata:qo("metadata").notNull().default({}),createdAt:Lt("created_at",{withTimezone:!0}).notNull().defaultNow(),updatedAt:Lt("updated_at",{withTimezone:!0}).notNull().defaultNow(),completedAt:Lt("completed_at",{withTimezone:!0})},e=>[Bt("idx_agent_runs_user").on(e.userId),Bt("idx_agent_runs_org_created").on(e.orgId,e.createdAt),Bt("idx_agent_runs_project").on(e.projectId)]);import{pgTable as Ht,text as I,timestamp as ke,jsonb as X,uuid as E,integer as rt,uniqueIndex as Mo,index as D}from"drizzle-orm/pg-core";var d=Ht("sessions",{id:E("id").primaryKey().defaultRandom(),userId:E("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),externalSessionId:I("external_session_id"),projectId:E("project_id").references(()=>s.id,{onDelete:"set null"}),orgId:E("org_id").references(()=>u.id,{onDelete:"set null"}),tool:I("tool").notNull(),projectPath:I("project_path"),gitBranch:I("git_branch"),startedAt:ke("started_at",{withTimezone:!0}).notNull(),endedAt:ke("ended_at",{withTimezone:!0}),eventCount:rt("event_count").default(0),tokenUsage:X("token_usage"),analysis:X("analysis"),analyzedAt:ke("analyzed_at",{withTimezone:!0}),analyzedEventCount:rt("analyzed_event_count"),analyzedTurnCount:rt("analyzed_turn_count"),metadata:X("metadata").default({}),origin:I("origin").notNull().default("unknown"),runId:E("run_id").references(()=>g.id,{onDelete:"set null"}),model:I("model"),harnessVersion:I("harness_version"),createdAt:ke("created_at",{withTimezone:!0}).defaultNow()},e=>[D("idx_sessions_user").on(e.userId),D("idx_sessions_tool").on(e.tool),D("idx_sessions_started_at").on(e.startedAt),D("idx_sessions_project").on(e.projectId),D("idx_sessions_org_started_at").on(e.orgId,e.startedAt),D("idx_sessions_run").on(e.runId),Mo("idx_sessions_user_external").on(e.userId,e.externalSessionId)]),ue=Ht("session_events",{id:E("id").primaryKey().defaultRandom(),sessionId:E("session_id").notNull().references(()=>d.id,{onDelete:"cascade"}),sequence:rt("sequence").notNull(),eventType:I("event_type").notNull(),content:I("content"),toolName:I("tool_name"),toolInput:X("tool_input"),toolOutput:X("tool_output"),tokenUsage:X("token_usage"),model:I("model"),timestamp:ke("timestamp",{withTimezone:!0}).notNull(),metadata:X("metadata").default({})},e=>[Mo("session_events_session_sequence_idx").on(e.sessionId,e.sequence),D("idx_session_events_session_id").on(e.sessionId),D("idx_session_events_event_type").on(e.eventType),D("idx_session_events_model").on(e.model)]),H=Ht("session_instructions",{sessionId:E("session_id").notNull().references(()=>d.id,{onDelete:"cascade"}),instructionId:E("instruction_id").notNull().references(()=>r.id,{onDelete:"cascade"}),linkMethod:I("link_method").notNull(),contentHash:I("content_hash")},e=>[D("idx_session_instructions_instruction_id").on(e.instructionId)]);import{pgTable as Fr,text as le,timestamp as Ut,uuid as Ee,integer as Lo,index as st}from"drizzle-orm/pg-core";var T=Fr("memories",{id:Ee("id").primaryKey().defaultRandom(),userId:Ee("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),orgId:Ee("org_id"),projectId:Ee("project_id").references(()=>s.id,{onDelete:"set null"}),version:Lo("version").notNull().default(1),parentId:Ee("parent_id").references(()=>T.id,{onDelete:"set null"}),kind:le("kind").notNull(),title:le("title").notNull(),body:le("body").notNull(),source:le("source").notNull(),status:le("status").notNull().default("active"),trustClass:le("trust_class"),trustVersion:Lo("trust_version"),trustComputedAt:Ut("trust_computed_at",{withTimezone:!0}),createdAt:Ut("created_at",{withTimezone:!0}).notNull().defaultNow(),updatedAt:Ut("updated_at",{withTimezone:!0}).notNull().defaultNow()},e=>[st("idx_memories_user").on(e.userId),st("idx_memories_project").on(e.projectId),st("idx_memories_parent").on(e.parentId),st("idx_memories_user_status").on(e.userId,e.status)]);import{pgTable as Gr,text as be,timestamp as Vt,uuid as Ft,integer as Bo,jsonb as Jr,index as Ho}from"drizzle-orm/pg-core";var Uo=Gr("memory_experiments",{id:Ft("id").primaryKey().defaultRandom(),memoryId:Ft("memory_id").notNull().references(()=>T.id,{onDelete:"cascade"}),userId:Ft("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),memoryVersion:Bo("memory_version").notNull().default(1),taskPrompt:be("task_prompt").notNull(),expectations:be("expectations").array().notNull().default([]),trials:Bo("trials").notNull().default(10),model:be("model"),status:be("status").notNull().default("pending"),result:Jr("result").$type(),error:be("error"),createdAt:Vt("created_at",{withTimezone:!0}).notNull().defaultNow(),startedAt:Vt("started_at",{withTimezone:!0}),completedAt:Vt("completed_at",{withTimezone:!0})},e=>[Ho("idx_memory_experiments_memory").on(e.memoryId),Ho("idx_memory_experiments_user").on(e.userId)]);import{boolean as Yr,date as $r,index as Gt,integer as Qr,jsonb as Wr,pgTable as Jt,text as A,timestamp as U,uniqueIndex as Xr,uuid as ce}from"drizzle-orm/pg-core";var Vo=Jt("announcements",{id:ce("id").primaryKey().defaultRandom(),version:A("version").notNull().unique(),releaseDate:$r("release_date").notNull(),subject:A("subject").notNull(),htmlBody:A("html_body").notNull(),textBody:A("text_body").notNull(),sections:Wr("sections").notNull().default({}),status:A("status").notNull().default("draft"),recipientCount:Qr("recipient_count"),sentAt:U("sent_at",{withTimezone:!0}),sentBy:ce("sent_by"),error:A("error"),createdAt:U("created_at",{withTimezone:!0}).notNull().defaultNow(),updatedAt:U("updated_at",{withTimezone:!0}).notNull().defaultNow()},e=>[Gt("idx_announcements_status").on(e.status),Gt("idx_announcements_created").on(e.createdAt)]),Fo=Jt("announcement_deliveries",{id:ce("id").primaryKey().defaultRandom(),announcementId:ce("announcement_id").notNull(),userId:ce("user_id").notNull(),email:A("email").notNull(),status:A("status").notNull().default("pending"),providerId:A("provider_id"),error:A("error"),sentAt:U("sent_at",{withTimezone:!0}),createdAt:U("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[Xr("uniq_announcement_deliveries_announcement_user").on(e.announcementId,e.userId),Gt("idx_announcement_deliveries_user").on(e.userId,e.createdAt)]),Go=Jt("notification_preferences",{userId:ce("user_id").primaryKey(),productAnnouncements:Yr("product_announcements").notNull().default(!0),unsubscribeToken:A("unsubscribe_token").notNull().unique(),unsubscribedAt:U("unsubscribed_at",{withTimezone:!0}),createdAt:U("created_at",{withTimezone:!0}).notNull().defaultNow(),updatedAt:U("updated_at",{withTimezone:!0}).notNull().defaultNow()});import{pgTable as Zr,text as Yt,timestamp as it,uuid as at,index as Jo}from"drizzle-orm/pg-core";var b=Zr("org_invitations",{id:at("id").primaryKey().defaultRandom(),orgId:at("org_id").notNull().references(()=>u.id,{onDelete:"cascade"}),email:Yt("email").notNull(),role:Yt("role").notNull().default("member"),teamId:at("team_id").references(()=>h.id,{onDelete:"set null"}),invitedBy:at("invited_by").notNull().references(()=>o.id),token:Yt("token").notNull().unique(),expiresAt:it("expires_at",{withTimezone:!0}).notNull(),acceptedAt:it("accepted_at",{withTimezone:!0}),revokedAt:it("revoked_at",{withTimezone:!0}),createdAt:it("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[Jo("idx_org_invitations_token").on(e.token),Jo("idx_org_invitations_org").on(e.orgId)]);import{pgTable as es,text as ts,timestamp as os,jsonb as ns,uuid as $t,index as Yo}from"drizzle-orm/pg-core";var _e=es("instruction_events",{id:$t("id").primaryKey().defaultRandom(),instructionId:$t("instruction_id").notNull().references(()=>r.id,{onDelete:"cascade"}),eventType:ts("event_type").notNull(),actorId:$t("actor_id").notNull(),metadata:ns("metadata"),createdAt:os("created_at",{withTimezone:!0}).defaultNow()},e=>[Yo("idx_instruction_events_instruction").on(e.instructionId),Yo("idx_instruction_events_type").on(e.eventType)]);import{pgTable as $o,text as dt,timestamp as Qo,uuid as j,integer as Wo,index as me,unique as rs}from"drizzle-orm/pg-core";var S=$o("treatment_assignments",{id:j("id").primaryKey().defaultRandom(),userId:j("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),treatmentType:dt("treatment_type").notNull(),treatmentId:j("treatment_id").notNull(),treatmentVersion:Wo("treatment_version").notNull().default(1),projectId:j("project_id").references(()=>s.id,{onDelete:"set null"}),assignedBy:j("assigned_by").references(()=>o.id,{onDelete:"set null"}),method:dt("method").notNull(),assignedAt:Qo("assigned_at",{withTimezone:!0}).notNull().defaultNow()},e=>[me("idx_treatment_assignments_user").on(e.userId),me("idx_treatment_assignments_treatment").on(e.treatmentType,e.treatmentId),me("idx_treatment_assignments_project").on(e.projectId)]),K=$o("treatment_exposures",{id:j("id").primaryKey().defaultRandom(),sessionId:j("session_id").notNull().references(()=>d.id,{onDelete:"cascade"}),userId:j("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),treatmentType:dt("treatment_type").notNull(),treatmentId:j("treatment_id").notNull(),treatmentVersion:Wo("treatment_version").notNull().default(1),assignmentId:j("assignment_id").references(()=>S.id,{onDelete:"set null"}),method:dt("method").notNull(),exposedAt:Qo("exposed_at",{withTimezone:!0}).notNull().defaultNow()},e=>[rs("treatment_exposures_unique").on(e.sessionId,e.treatmentType,e.treatmentId,e.treatmentVersion),me("idx_treatment_exposures_treatment").on(e.treatmentType,e.treatmentId),me("idx_treatment_exposures_user").on(e.userId),me("idx_treatment_exposures_session").on(e.sessionId)]);import{pgTable as ss,text as Qt,timestamp as is,uuid as ut,integer as as,index as Xo,uniqueIndex as ds}from"drizzle-orm/pg-core";var Zo=ss("pending_treatment_exposures",{id:ut("id").primaryKey().defaultRandom(),userId:ut("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),externalSessionId:Qt("external_session_id").notNull(),treatmentType:Qt("treatment_type").notNull(),treatmentId:ut("treatment_id").notNull(),treatmentVersion:as("treatment_version").notNull().default(1),method:Qt("method").notNull().default("injected"),projectId:ut("project_id").references(()=>s.id,{onDelete:"set null"}),createdAt:is("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[ds("pending_treatment_exposures_unique").on(e.externalSessionId,e.treatmentType,e.treatmentId,e.treatmentVersion),Xo("idx_pending_treatment_exposures_ext").on(e.externalSessionId),Xo("idx_pending_treatment_exposures_user").on(e.userId)]);import{pgTable as us,text as pe,timestamp as Wt,uuid as Xt,jsonb as ls,uniqueIndex as cs,index as en}from"drizzle-orm/pg-core";var lt=us("session_terminal_targets",{id:Xt("id").primaryKey().defaultRandom(),userId:Xt("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),sessionId:Xt("session_id").references(()=>d.id,{onDelete:"set null"}),externalSessionId:pe("external_session_id"),kind:pe("kind").notNull(),target:pe("target").notNull(),status:pe("status").notNull().default("active"),attachCommand:pe("attach_command").notNull(),projectPath:pe("project_path"),metadata:ls("metadata").notNull().default({}),lastSeenAt:Wt("last_seen_at",{withTimezone:!0}).defaultNow(),createdAt:Wt("created_at",{withTimezone:!0}).defaultNow(),updatedAt:Wt("updated_at",{withTimezone:!0}).defaultNow()},e=>[cs("idx_session_terminal_targets_user_target").on(e.userId,e.target),en("idx_session_terminal_targets_session").on(e.sessionId),en("idx_session_terminal_targets_user_status").on(e.userId,e.status)]);import{boolean as _s,index as ct,jsonb as tn,pgTable as ms,text as Z,timestamp as Se,uuid as _t,integer as on}from"drizzle-orm/pg-core";var nn=ms("session_send_jobs",{id:_t("id").primaryKey().defaultRandom(),userId:_t("user_id").notNull(),sessionId:_t("session_id").notNull().references(()=>d.id,{onDelete:"cascade"}),terminalTargetId:_t("terminal_target_id").references(()=>lt.id,{onDelete:"set null"}),target:Z("target").notNull(),message:Z("message").notNull(),submit:_s("submit").notNull().default(!0),delivery:Z("delivery").notNull().default("live"),status:Z("status").notNull().default("pending"),result:tn("result"),error:Z("error"),attempts:on("attempts").notNull().default(0),taskKind:Z("task_kind"),payload:tn("payload"),claimedBy:Z("claimed_by"),claimedAt:Se("claimed_at",{withTimezone:!0}),leaseExpiresAt:Se("lease_expires_at",{withTimezone:!0}),leaseRecoveries:on("lease_recoveries").notNull().default(0),createdAt:Se("created_at",{withTimezone:!0}).defaultNow(),updatedAt:Se("updated_at",{withTimezone:!0}).defaultNow(),completedAt:Se("completed_at",{withTimezone:!0})},e=>[ct("idx_session_send_jobs_user").on(e.userId),ct("idx_session_send_jobs_session").on(e.sessionId),ct("idx_session_send_jobs_status").on(e.status),ct("idx_session_send_jobs_pending").on(e.userId,e.status)]);import{pgTable as sn,text as ee,timestamp as mt,jsonb as an,uuid as V,integer as ps,boolean as fs,uniqueIndex as xs,index as rn,primaryKey as Ns}from"drizzle-orm/pg-core";var z=sn("packs",{id:V("id").primaryKey().defaultRandom(),name:ee("name").notNull(),description:ee("description").notNull(),scope:ee("scope").notNull(),scopeRef:V("scope_ref"),version:ee("version").notNull().default("1.0.0"),tags:ee("tags").array(),badge:ee("badge"),metadata:an("metadata"),createdBy:V("created_by"),createdAt:mt("created_at",{withTimezone:!0}).defaultNow(),updatedAt:mt("updated_at",{withTimezone:!0}).defaultNow(),archived:fs("archived").default(!1),archivedAt:mt("archived_at",{withTimezone:!0}),archivedBy:V("archived_by"),forkedFromId:V("forked_from_id").references(()=>z.id,{onDelete:"set null"}),upstreamVersion:ee("upstream_version")},e=>[xs("packs_name_scope_ref_idx").on(e.name,e.scope,e.scopeRef),rn("idx_packs_scope").on(e.scope,e.scopeRef),rn("idx_packs_created_by").on(e.createdBy)]),F=sn("pack_instructions",{packId:V("pack_id").references(()=>z.id,{onDelete:"cascade"}).notNull(),instructionId:V("instruction_id").references(()=>r.id,{onDelete:"cascade"}).notNull(),position:ps("position").notNull().default(0),slotOverrides:an("slot_overrides"),addedAt:mt("added_at",{withTimezone:!0}).defaultNow(),addedBy:V("added_by")},e=>[Ns({columns:[e.packId,e.instructionId]})]);import{pgTable as gs,text as Zt,timestamp as vs,jsonb as hs,uuid as eo,index as fe}from"drizzle-orm/pg-core";var xe=gs("instruction_usage_events",{id:eo("id").primaryKey().defaultRandom(),instructionId:eo("instruction_id").references(()=>r.id,{onDelete:"set null"}),userId:eo("user_id").notNull(),surface:Zt("surface").notNull(),action:Zt("action").notNull(),metadata:hs("metadata"),traceId:Zt("trace_id"),createdAt:vs("created_at",{withTimezone:!0}).defaultNow()},e=>[fe("idx_usage_events_instruction").on(e.instructionId),fe("idx_usage_events_user").on(e.userId),fe("idx_usage_events_surface").on(e.surface),fe("idx_usage_events_action").on(e.action),fe("idx_usage_events_created_at").on(e.createdAt),fe("idx_usage_events_user_created").on(e.userId,e.createdAt)]);import{pgTable as Is,text as pt,timestamp as dn,jsonb as ys,uuid as un,index as to}from"drizzle-orm/pg-core";var ln=Is("worker_connections",{id:un("id").primaryKey().defaultRandom(),userId:un("user_id").notNull(),workerType:pt("worker_type").notNull().default("mcp"),clientName:pt("client_name").notNull(),clientVersion:pt("client_version"),workerVersion:pt("worker_version"),lastHeartbeat:dn("last_heartbeat",{withTimezone:!0}).notNull().defaultNow(),connectedAt:dn("connected_at",{withTimezone:!0}).notNull().defaultNow(),metadata:ys("metadata")},e=>[to("idx_worker_connections_user").on(e.userId),to("idx_worker_connections_heartbeat").on(e.userId,e.lastHeartbeat),to("idx_worker_connections_type").on(e.userId,e.workerType)]);import{pgTable as Ts,text as ft,timestamp as ws,jsonb as As,uuid as cn,index as _n}from"drizzle-orm/pg-core";var mn=Ts("cli_setup_events",{id:cn("id").primaryKey().defaultRandom(),userId:cn("user_id").notNull(),deviceId:ft("device_id").notNull(),event:ft("event").notNull(),cliVersion:ft("cli_version"),os:ft("os"),props:As("props").notNull().default({}),createdAt:ws("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[_n("idx_cli_setup_events_user").on(e.userId,e.createdAt),_n("idx_cli_setup_events_device").on(e.deviceId,e.createdAt)]);import{pgTable as zs,text as te,integer as Rs,boolean as Ds,timestamp as js,jsonb as ks,uuid as Es,index as pn}from"drizzle-orm/pg-core";var fn=zs("cli_error_events",{id:Es("id").primaryKey().defaultRandom(),deviceId:te("device_id"),event:te("event").notNull(),command:te("command"),statusCode:Rs("status_code"),message:te("message"),cliVersion:te("cli_version"),os:te("os"),nodeVersion:te("node_version"),proxied:Ds("proxied"),props:ks("props").notNull().default({}),createdAt:js("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[pn("idx_cli_error_events_created").on(e.createdAt),pn("idx_cli_error_events_device").on(e.deviceId,e.createdAt)]);import{sql as bs}from"drizzle-orm";import{pgTable as oe,text as _,timestamp as v,jsonb as w,uuid as c,integer as P,boolean as Ke,index as N,unique as xn}from"drizzle-orm/pg-core";var n=oe("eval_targets",{id:c("id").primaryKey().defaultRandom(),userId:c("user_id").notNull(),name:_("name").notNull(),type:_("type").notNull(),content:_("content").notNull(),description:_("description").notNull().default(""),metadata:w("metadata").notNull().default({}),version:P("version").notNull().default(1),parentId:c("parent_id").references(()=>n.id,{onDelete:"set null"}),createdAt:v("created_at",{withTimezone:!0}).defaultNow(),updatedAt:v("updated_at",{withTimezone:!0}).defaultNow()},e=>[N("eval_targets_name_user_idx").on(e.name,e.userId),N("idx_eval_targets_user").on(e.userId),N("idx_eval_targets_type").on(e.type),N("idx_eval_targets_parent").on(e.parentId)]),C=oe("evals",{id:c("id").primaryKey().defaultRandom(),evalTargetId:c("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),name:_("name").notNull(),prompt:_("prompt").notNull(),expectedOutput:_("expected_output").notNull().default(""),files:w("files").notNull().default([]),expectations:w("expectations").notNull().default([]),retiredAt:v("retired_at",{withTimezone:!0}),retiredReason:_("retired_reason"),createdAt:v("created_at",{withTimezone:!0}).defaultNow(),updatedAt:v("updated_at",{withTimezone:!0}).defaultNow(),contentUpdatedAt:v("content_updated_at",{withTimezone:!0}).notNull().defaultNow()},e=>[N("idx_evals_target").on(e.evalTargetId),N("idx_evals_target_active").on(e.evalTargetId).where(bs`${e.retiredAt} IS NULL`)]),k=oe("eval_runs",{id:c("id").primaryKey().defaultRandom(),jobId:c("job_id"),evalId:c("eval_id").notNull().references(()=>C.id,{onDelete:"cascade"}),evalTargetId:c("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),evalTargetVersion:P("eval_target_version").notNull(),configuration:_("configuration").notNull(),runNumber:P("run_number").notNull().default(1),iteration:P("iteration").notNull().default(1),status:_("status").notNull().default("completed"),outputs:w("outputs").notNull().default({}),timing:w("timing").notNull().default({}),grading:w("grading").notNull().default({}),comparison:w("comparison"),createdAt:v("created_at",{withTimezone:!0}).defaultNow()},e=>[N("idx_eval_runs_eval").on(e.evalId),N("idx_eval_runs_target").on(e.evalTargetId),N("idx_eval_runs_iteration").on(e.evalTargetId,e.iteration)]),Nn=oe("eval_comparisons",{id:c("id").primaryKey().defaultRandom(),userId:c("user_id").notNull(),targetAId:c("target_a_id").notNull().references(()=>n.id,{onDelete:"cascade"}),targetBId:c("target_b_id").notNull().references(()=>n.id,{onDelete:"cascade"}),targetAVersion:P("target_a_version").notNull(),targetBVersion:P("target_b_version").notNull(),isSwapped:Ke("is_swapped").notNull().default(!1),winnerTargetId:c("winner_target_id").references(()=>n.id,{onDelete:"set null"}),perEval:w("per_eval").notNull().default([]),overall:w("overall").notNull().default({}),rawOutput:_("raw_output"),model:_("model"),status:_("status").notNull().default("completed"),createdAt:v("created_at",{withTimezone:!0}).defaultNow()},e=>[N("idx_eval_comparisons_target_a").on(e.targetAId),N("idx_eval_comparisons_target_b").on(e.targetBId),N("idx_eval_comparisons_user").on(e.userId)]),gn=oe("eval_grade_annotations",{id:c("id").primaryKey().defaultRandom(),userId:c("user_id").notNull(),evalRunId:c("eval_run_id").notNull().references(()=>k.id,{onDelete:"cascade"}),evalTargetId:c("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),expectationIndex:P("expectation_index").notNull(),expectationText:_("expectation_text").notNull(),judgePassed:Ke("judge_passed").notNull(),judgeMethod:_("judge_method").notNull(),judgeModel:_("judge_model"),verdict:_("verdict").notNull(),flag:_("flag"),note:_("note"),createdAt:v("created_at",{withTimezone:!0}).defaultNow(),updatedAt:v("updated_at",{withTimezone:!0}).defaultNow()},e=>[N("idx_eval_grade_annotations_target").on(e.evalTargetId),N("idx_eval_grade_annotations_run").on(e.evalRunId),xn("eval_grade_annotations_eval_run_id_expectation_index_key").on(e.evalRunId,e.expectationIndex)]),vn=oe("judge_reviewer_verdicts",{id:c("id").primaryKey().defaultRandom(),userId:c("user_id").notNull(),evalTargetId:c("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),evalRunId:c("eval_run_id").notNull().references(()=>k.id,{onDelete:"cascade"}),expectationIndex:P("expectation_index").notNull(),expectationText:_("expectation_text").notNull(),judgePassed:Ke("judge_passed").notNull(),humanPassed:Ke("human_passed").notNull(),reviewerEngine:_("reviewer_engine").notNull(),reviewerModel:_("reviewer_model").notNull(),reviewerPassed:Ke("reviewer_passed").notNull(),resolvedAt:v("resolved_at",{withTimezone:!0}),resolution:_("resolution"),createdAt:v("created_at",{withTimezone:!0}).defaultNow(),updatedAt:v("updated_at",{withTimezone:!0}).defaultNow()},e=>[N("idx_jrv_target").on(e.evalTargetId),xn("judge_reviewer_verdicts_eval_run_id_expectation_index_review_key").on(e.evalRunId,e.expectationIndex,e.reviewerModel)]),Ne=oe("benchmarks",{id:c("id").primaryKey().defaultRandom(),evalTargetId:c("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),iteration:P("iteration").notNull().default(1),runSummary:w("run_summary").notNull().default({}),notes:w("notes").notNull().default([]),feedback:w("feedback"),createdAt:v("created_at",{withTimezone:!0}).defaultNow()},e=>[N("idx_benchmarks_target").on(e.evalTargetId)]);import{sql as oo}from"drizzle-orm";import{pgTable as Ss,text as O,timestamp as Ks,jsonb as xt,uuid as Nt,boolean as Ps,index as Pe,uniqueIndex as Cs}from"drizzle-orm/pg-core";var hn=Ss("instruction_promotions",{id:Nt("id").primaryKey().defaultRandom(),userId:Nt("user_id").notNull(),evalTargetId:Nt("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),instructionId:Nt("instruction_id").references(()=>r.id,{onDelete:"set null"}),fromContentHash:O("from_content_hash").notNull(),toContentHash:O("to_content_hash").notNull(),fromContent:O("from_content").notNull(),toContent:O("to_content").notNull(),proposalSource:O("proposal_source").notNull(),proposalRationale:O("proposal_rationale").notNull().default(""),decision:O("decision").notNull(),applied:Ps("applied").notNull().default(!1),refusals:xt("refusals").notNull().default([]),rationale:O("rationale").notNull().default(""),effectClass:O("effect_class").notNull(),verdict:xt("verdict").notNull().default({}),gates:xt("gates").notNull().default({}),touchedSections:xt("touched_sections").notNull().default([]),createdAt:Ks("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[Pe("idx_instruction_promotions_budget").on(e.evalTargetId,e.createdAt.desc()).where(oo`${e.applied}`),Pe("idx_instruction_promotions_target").on(e.evalTargetId,e.createdAt.desc()),Pe("idx_instruction_promotions_user").on(e.userId,e.createdAt.desc()),Pe("idx_instruction_promotions_to_hash").on(e.toContentHash),Cs("uq_instruction_promotions_applied").on(e.evalTargetId,e.fromContentHash,e.toContentHash).where(oo`${e.applied}`),Pe("idx_instruction_promotions_applied_hash").on(e.toContentHash,e.createdAt.desc()).where(oo`${e.applied}`)]);import{pgTable as yn,text as no,timestamp as ro,jsonb as Tn,uuid as ge,integer as Ce,index as gt,real as In}from"drizzle-orm/pg-core";var ve=yn("trigger_evals",{id:ge("id").primaryKey().defaultRandom(),evalTargetId:ge("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),userId:ge("user_id").notNull(),queries:Tn("queries").notNull().default([]),status:no("status").notNull().default("pending_review"),trainIndices:Ce("train_indices").array().default([]),testIndices:Ce("test_indices").array().default([]),createdAt:ro("created_at",{withTimezone:!0}).defaultNow(),updatedAt:ro("updated_at",{withTimezone:!0}).defaultNow()},e=>[gt("idx_trigger_evals_target").on(e.evalTargetId),gt("idx_trigger_evals_user").on(e.userId)]),he=yn("optimization_runs",{id:ge("id").primaryKey().defaultRandom(),evalTargetId:ge("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),userId:ge("user_id").notNull(),type:no("type").notNull(),iteration:Ce("iteration").notNull(),inputVersion:Ce("input_version").notNull(),outputVersion:Ce("output_version"),trainScore:In("train_score"),testScore:In("test_score"),analysis:Tn("analysis").notNull().default({}),status:no("status").notNull().default("running"),createdAt:ro("created_at",{withTimezone:!0}).defaultNow()},e=>[gt("idx_optimization_runs_target").on(e.evalTargetId),gt("idx_optimization_runs_user").on(e.userId)]);import{pgTable as Os,text as G,timestamp as qs,jsonb as Oe,uuid as so,integer as io,real as Ms,index as qe,uniqueIndex as wn}from"drizzle-orm/pg-core";var J=Os("context_snapshots",{id:so("id").primaryKey().defaultRandom(),sessionId:so("session_id").references(()=>d.id,{onDelete:"cascade"}),userId:so("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),sequence:io("sequence").notNull().default(0),provider:G("provider").notNull(),model:G("model").notNull(),systemPrompt:G("system_prompt").notNull(),injectedInstructions:Oe("injected_instructions").notNull().default([]),messagesSummary:Oe("messages_summary").notNull(),tools:Oe("tools").notNull().default([]),systemHash:G("system_hash").notNull(),requestHash:G("request_hash").notNull().default(""),toolsHash:G("tools_hash"),injectedHash:G("injected_hash"),messagesDelta:Oe("messages_delta").default([]),messagesDeltaRef:G("messages_delta_ref"),maxTokens:io("max_tokens"),temperature:Ms("temperature"),estimatedTokens:io("estimated_tokens"),capturedAt:qs("captured_at",{withTimezone:!0}).notNull().defaultNow(),metadata:Oe("metadata").default({})},e=>[qe("idx_context_snapshots_session").on(e.sessionId),qe("idx_context_snapshots_user").on(e.userId),qe("idx_context_snapshots_hash").on(e.systemHash),qe("idx_context_snapshots_request_hash").on(e.requestHash),wn("idx_snapshots_session_request").on(e.sessionId,e.requestHash),wn("idx_snapshots_session_sequence").on(e.sessionId,e.sequence),qe("idx_context_snapshots_user_session_captured").on(e.userId,e.sessionId,e.capturedAt.desc())]);import{pgTable as Ls,text as An,timestamp as Bs,jsonb as Hs,integer as Us,index as Vs}from"drizzle-orm/pg-core";var zn=Ls("content_blobs",{hash:An("hash").primaryKey(),contentType:An("content_type").notNull(),content:Hs("content").notNull(),sizeBytes:Us("size_bytes").notNull().default(0),createdAt:Bs("created_at",{withTimezone:!0}).defaultNow()},e=>[Vs("idx_content_blobs_type").on(e.contentType)]);import{pgTable as Fs,text as vt,timestamp as Me,jsonb as ht,uuid as ao,index as It,integer as Rn}from"drizzle-orm/pg-core";var Ie=Fs("eval_jobs",{id:ao("id").primaryKey().defaultRandom(),userId:ao("user_id").notNull(),evalTargetId:ao("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),status:vt("status").notNull().default("pending"),config:ht("config").notNull().default({}),progress:ht("progress").notNull().default({}),result:ht("result"),error:vt("error"),attempts:Rn("attempts").notNull().default(0),taskKind:vt("task_kind"),payload:ht("payload"),claimedBy:vt("claimed_by"),claimedAt:Me("claimed_at",{withTimezone:!0}),leaseExpiresAt:Me("lease_expires_at",{withTimezone:!0}),leaseRecoveries:Rn("lease_recoveries").notNull().default(0),createdAt:Me("created_at",{withTimezone:!0}).defaultNow(),updatedAt:Me("updated_at",{withTimezone:!0}).defaultNow(),completedAt:Me("completed_at",{withTimezone:!0})},e=>[It("idx_eval_jobs_user").on(e.userId),It("idx_eval_jobs_target").on(e.evalTargetId),It("idx_eval_jobs_status").on(e.status),It("idx_eval_jobs_pending").on(e.userId,e.status)]);import{pgTable as Gs,text as Le,timestamp as Be,jsonb as Dn,uuid as jn,integer as kn,index as En}from"drizzle-orm/pg-core";var bn=Gs("agent_jobs",{id:jn("id").primaryKey().defaultRandom(),userId:jn("user_id").notNull(),taskKind:Le("task_kind").notNull(),status:Le("status").notNull().default("pending"),payload:Dn("payload").notNull(),dedupeKey:Le("dedupe_key"),result:Dn("result"),error:Le("error"),attempts:kn("attempts").notNull().default(0),claimedBy:Le("claimed_by"),claimedAt:Be("claimed_at",{withTimezone:!0}),leaseExpiresAt:Be("lease_expires_at",{withTimezone:!0}),leaseRecoveries:kn("lease_recoveries").notNull().default(0),createdAt:Be("created_at",{withTimezone:!0}).notNull().defaultNow(),updatedAt:Be("updated_at",{withTimezone:!0}).notNull().defaultNow(),completedAt:Be("completed_at",{withTimezone:!0})},e=>[En("idx_agent_jobs_claim").on(e.userId,e.status,e.taskKind,e.createdAt),En("idx_agent_jobs_dedupe").on(e.userId,e.taskKind,e.dedupeKey)]);import{pgTable as Js,text as He,timestamp as Ue,jsonb as yt,uuid as uo,index as Tt,integer as Sn}from"drizzle-orm/pg-core";var Kn=Js("insights_jobs",{id:uo("id").primaryKey().defaultRandom(),userId:uo("user_id").notNull(),status:He("status").notNull().default("pending"),projectPath:He("project_path"),projectId:uo("project_id").references(()=>s.id,{onDelete:"set null"}),config:yt("config").notNull().default({}),progress:yt("progress").notNull().default({}),result:yt("result"),error:He("error"),attempts:Sn("attempts").notNull().default(0),taskKind:He("task_kind"),payload:yt("payload"),claimedBy:He("claimed_by"),claimedAt:Ue("claimed_at",{withTimezone:!0}),leaseExpiresAt:Ue("lease_expires_at",{withTimezone:!0}),leaseRecoveries:Sn("lease_recoveries").notNull().default(0),createdAt:Ue("created_at",{withTimezone:!0}).defaultNow(),updatedAt:Ue("updated_at",{withTimezone:!0}).defaultNow(),completedAt:Ue("completed_at",{withTimezone:!0})},e=>[Tt("idx_insights_jobs_user").on(e.userId),Tt("idx_insights_jobs_status").on(e.status),Tt("idx_insights_jobs_pending").on(e.userId,e.status),Tt("idx_insights_jobs_project").on(e.projectId)]);import{pgTable as Ys,text as lo,timestamp as wt,uuid as Pn,index as $s,uniqueIndex as Qs}from"drizzle-orm/pg-core";var ye=Ys("api_keys",{id:Pn("id").primaryKey().defaultRandom(),userId:Pn("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),name:lo("name").notNull(),keyHash:lo("key_hash").notNull(),keyPrefix:lo("key_prefix").notNull(),lastUsedAt:wt("last_used_at",{withTimezone:!0}),expiresAt:wt("expires_at",{withTimezone:!0}),revokedAt:wt("revoked_at",{withTimezone:!0}),createdAt:wt("created_at",{withTimezone:!0}).defaultNow()},e=>[$s("idx_api_keys_user").on(e.userId),Qs("idx_api_keys_hash").on(e.keyHash)]);import{pgTable as Ws,text as co,timestamp as Cn,uuid as Xs,index as Zs}from"drizzle-orm/pg-core";var On=Ws("extension_auth_codes",{code:co("code").primaryKey(),userId:Xs("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),editor:co("editor"),email:co("email"),expiresAt:Cn("expires_at",{withTimezone:!0}).notNull(),createdAt:Cn("created_at",{withTimezone:!0}).defaultNow()},e=>[Zs("idx_ext_auth_codes_expiry").on(e.expiresAt)]);import{pgTable as ei,text as ti,timestamp as qn,jsonb as oi,uuid as _o,index as Mn}from"drizzle-orm/pg-core";var Te=ei("eval_conversations",{id:_o("id").primaryKey().defaultRandom(),evalTargetId:_o("eval_target_id").notNull().references(()=>n.id,{onDelete:"cascade"}),userId:_o("user_id").notNull(),messages:oi("messages").notNull().default([]),status:ti("status").notNull().default("active"),createdAt:qn("created_at",{withTimezone:!0}).defaultNow(),updatedAt:qn("updated_at",{withTimezone:!0}).defaultNow()},e=>[Mn("idx_eval_conversations_target").on(e.evalTargetId),Mn("idx_eval_conversations_user").on(e.userId)]);import{pgTable as ni,text as q,timestamp as Ln,jsonb as ri,uuid as mo}from"drizzle-orm/pg-core";var Bn=ni("skill_submissions",{id:mo("id").primaryKey().defaultRandom(),skillId:q("skill_id").notNull(),name:q("name").notNull(),description:q("description").notNull(),category:q("category").notNull(),tools:q("tools").array().notNull(),tags:q("tags").array().default([]),content:q("content").notNull(),status:q("status").notNull().default("pending"),submittedBy:mo("submitted_by").notNull(),reviewedBy:mo("reviewed_by"),reviewNote:q("review_note"),metadata:ri("metadata"),createdAt:Ln("created_at",{withTimezone:!0}).defaultNow(),updatedAt:Ln("updated_at",{withTimezone:!0}).defaultNow()});import{pgTable as si,text as Ve,timestamp as Hn,jsonb as ii,uuid as ai,uniqueIndex as di,index as Un}from"drizzle-orm/pg-core";var Vn=si("harness_releases",{id:ai("id").primaryKey().defaultRandom(),harness:Ve("harness").notNull(),version:Ve("version").notNull(),publishedAt:Hn("published_at",{withTimezone:!0}).notNull(),title:Ve("title"),body:Ve("body"),categories:ii("categories").default({}),url:Ve("url"),createdAt:Hn("created_at",{withTimezone:!0}).defaultNow()},e=>[di("idx_harness_releases_unique").on(e.harness,e.version),Un("idx_harness_releases_harness").on(e.harness),Un("idx_harness_releases_published").on(e.publishedAt)]);import{pgTable as ui,text as we,timestamp as Fn,jsonb as li,uuid as Gn,index as Jn,uniqueIndex as ci}from"drizzle-orm/pg-core";var po=ui("notifications",{id:Gn("id").primaryKey().defaultRandom(),userId:Gn("user_id").notNull(),type:we("type").notNull(),title:we("title").notNull(),body:we("body"),url:we("url"),sourceTable:we("source_table"),sourceId:we("source_id"),metadata:li("metadata").notNull().default({}),readAt:Fn("read_at",{withTimezone:!0}),createdAt:Fn("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[Jn("idx_notifications_user_created").on(e.userId,e.createdAt),Jn("idx_notifications_user_unread").on(e.userId),ci("idx_notifications_source_dedup").on(e.userId,e.sourceTable,e.sourceId)]);import{pgTable as _i,text as Fe,timestamp as Ge,jsonb as fo,uuid as xo,index as At,integer as Yn}from"drizzle-orm/pg-core";var Ae=_i("launch_jobs",{id:xo("id").primaryKey().defaultRandom(),userId:xo("user_id").notNull(),tool:Fe("tool").notNull(),status:Fe("status").notNull().default("pending"),config:fo("config").notNull().default({}),result:fo("result"),error:Fe("error"),attempts:Yn("attempts").notNull().default(0),taskKind:Fe("task_kind"),payload:fo("payload"),claimedBy:Fe("claimed_by"),claimedAt:Ge("claimed_at",{withTimezone:!0}),leaseExpiresAt:Ge("lease_expires_at",{withTimezone:!0}),leaseRecoveries:Yn("lease_recoveries").notNull().default(0),createdAt:Ge("created_at",{withTimezone:!0}).defaultNow(),updatedAt:Ge("updated_at",{withTimezone:!0}).defaultNow(),completedAt:Ge("completed_at",{withTimezone:!0}),runId:xo("run_id").references(()=>g.id,{onDelete:"set null"})},e=>[At("idx_launch_jobs_user").on(e.userId),At("idx_launch_jobs_status").on(e.status),At("idx_launch_jobs_pending").on(e.userId,e.status),At("idx_launch_jobs_run").on(e.runId)]);import{pgTable as $n,uuid as M,text as Je,real as mi,timestamp as zt,boolean as pi,uniqueIndex as fi,index as Ye}from"drizzle-orm/pg-core";var No=$n("instruction_suggestions",{id:M("id").primaryKey().defaultRandom(),userId:M("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),instructionId:M("instruction_id").notNull().references(()=>r.id,{onDelete:"cascade"}),projectPath:Je("project_path").notNull(),projectId:M("project_id").references(()=>s.id,{onDelete:"set null"}),score:mi("score").notNull(),reason:Je("reason").notNull(),generatedAt:zt("generated_at",{withTimezone:!0}).notNull().defaultNow(),isStale:pi("is_stale").notNull().default(!1),dismissedAt:zt("dismissed_at",{withTimezone:!0}),acceptedAt:zt("accepted_at",{withTimezone:!0}),promotedToInstructionId:M("promoted_to_instruction_id").references(()=>r.id,{onDelete:"set null"})},e=>[fi("idx_instruction_suggestions_user_project_instruction").on(e.userId,e.projectPath,e.instructionId),Ye("idx_instruction_suggestions_user_project").on(e.userId,e.projectPath),Ye("idx_instruction_suggestions_user_proj_id").on(e.userId,e.projectId),Ye("idx_instruction_suggestions_generated_at").on(e.generatedAt)]),Qn=$n("instruction_suggestion_events",{id:M("id").primaryKey().defaultRandom(),suggestionId:M("suggestion_id").notNull().references(()=>No.id,{onDelete:"cascade"}),userId:M("user_id").notNull().references(()=>o.id,{onDelete:"cascade"}),eventType:Je("event_type").notNull(),tool:Je("tool"),sessionId:M("session_id"),projectPath:Je("project_path").notNull(),createdAt:zt("created_at",{withTimezone:!0}).notNull().defaultNow()},e=>[Ye("idx_instruction_suggestion_events_suggestion_id").on(e.suggestionId),Ye("idx_instruction_suggestion_events_user_id").on(e.userId)]);import{pgTable as xi,text as go,integer as Ni,numeric as $e,timestamp as vo,index as gi,primaryKey as vi}from"drizzle-orm/pg-core";var Wn=xi("model_pricing",{provider:go("provider").notNull(),modelId:go("model_id").notNull(),inputPerM:$e("input_per_m").notNull(),outputPerM:$e("output_per_m").notNull(),cacheReadPerM:$e("cache_read_per_m").notNull(),cacheWrite5mPerM:$e("cache_write_5m_per_m").notNull(),cacheWrite1hPerM:$e("cache_write_1h_per_m").notNull(),contextWindow:Ni("context_window"),effectiveFrom:vo("effective_from",{withTimezone:!0}).notNull(),effectiveUntil:vo("effective_until",{withTimezone:!0}),source:go("source").notNull(),verifiedAt:vo("verified_at",{withTimezone:!0})},e=>[vi({columns:[e.provider,e.modelId,e.effectiveFrom]}),gi("idx_model_pricing_active").on(e.provider,e.modelId,e.effectiveFrom.desc())]);import{pgTable as hi,text as ne,numeric as Xn,timestamp as Zn,uuid as er,jsonb as Ii,index as tr}from"drizzle-orm/pg-core";var or=hi("limit_observations",{id:er("id").primaryKey().defaultRandom(),observedAt:Zn("observed_at",{withTimezone:!0}).notNull().defaultNow(),provider:ne("provider").notNull(),plan:ne("plan").notNull(),limitType:ne("limit_type").notNull(),value:Xn("value").notNull(),unit:ne("unit").notNull(),comparator:ne("comparator").notNull().default("="),resetsAt:Zn("resets_at",{withTimezone:!0}),sourceType:ne("source_type").notNull(),sourceUrl:ne("source_url"),sourceEvidence:Ii("source_evidence"),confidence:Xn("confidence").notNull(),userId:er("user_id")},e=>[tr("idx_limit_obs_lookup").on(e.provider,e.plan,e.limitType,e.observedAt.desc()),tr("idx_limit_obs_user").on(e.userId,e.observedAt.desc())]);import{pgTable as yi,text as Rt,timestamp as Ti,uuid as wi,jsonb as Ai,boolean as zi,uniqueIndex as Ri}from"drizzle-orm/pg-core";var nr=yi("provider_docs_snapshots",{id:wi("id").primaryKey().defaultRandom(),fetchedAt:Ti("fetched_at",{withTimezone:!0}).notNull().defaultNow(),provider:Rt("provider").notNull(),docUrl:Rt("doc_url").notNull(),contentHash:Rt("content_hash").notNull(),content:Rt("content").notNull(),parseSuccess:zi("parse_success").notNull(),parseErrors:Ai("parse_errors")},e=>[Ri("idx_docs_dedup").on(e.provider,e.docUrl,e.contentHash)]);import{pgTable as Di,text as Dt,numeric as rr,timestamp as sr,uuid as ji,primaryKey as ki,index as Ei}from"drizzle-orm/pg-core";var ir=Di("plan_limits_active",{provider:Dt("provider").notNull(),plan:Dt("plan").notNull(),limitType:Dt("limit_type").notNull(),value:rr("value").notNull(),unit:Dt("unit").notNull(),effectiveFrom:sr("effective_from",{withTimezone:!0}).notNull(),effectiveUntil:sr("effective_until",{withTimezone:!0}),confidence:rr("confidence").notNull(),sourceObservationIds:ji("source_observation_ids").array().notNull()},e=>[ki({columns:[e.provider,e.plan,e.limitType,e.effectiveFrom]}),Ei("idx_plan_limits_lookup").on(e.provider,e.plan,e.limitType,e.effectiveFrom.desc())]);import{pgTable as bi,text as ho,timestamp as Si,uuid as ar,jsonb as Ki,index as Pi}from"drizzle-orm/pg-core";var dr=bi("alert_dispatches",{id:ar("id").primaryKey().defaultRandom(),userId:ar("user_id").notNull(),alertKey:ho("alert_key").notNull(),severity:ho("severity").notNull(),lastDispatchedAt:Si("last_dispatched_at",{withTimezone:!0}).notNull().defaultNow(),lastState:Ki("last_state").notNull(),channel:ho("channel").notNull()},e=>[Pi("idx_alert_user_key").on(e.userId,e.alertKey,e.lastDispatchedAt.desc())]);import{pgTable as Ci,text as Io,timestamp as ur,uuid as yo,integer as Oi,index as qi,unique as Mi}from"drizzle-orm/pg-core";var lr=Ci("scaffolding_fingerprints",{id:yo("id").primaryKey().defaultRandom(),userId:yo("user_id").notNull(),harness:Io("harness").notNull(),model:Io("model").notNull(),toolsHash:Io("tools_hash").notNull(),firstSeenAt:ur("first_seen_at",{withTimezone:!0}).notNull().defaultNow(),lastSeenAt:ur("last_seen_at",{withTimezone:!0}).notNull().defaultNow(),snapshotCount:Oi("snapshot_count").notNull().default(1),firstSessionId:yo("first_session_id")},e=>[Mi("scaffolding_fingerprints_user_id_harness_model_tools_hash_key").on(e.userId,e.harness,e.model,e.toolsHash),qi("idx_scaffolding_fp_segment").on(e.userId,e.harness,e.model)]);import{pgTable as Li,text as To,timestamp as Bi,jsonb as Hi,uuid as cr,integer as Ui,unique as Vi}from"drizzle-orm/pg-core";var _r=Li("scaffolding_segments",{id:cr("id").primaryKey().defaultRandom(),userId:cr("user_id").notNull(),harness:To("harness").notNull(),model:To("model").notNull(),coreNames:Hi("core_names").notNull(),coreHash:To("core_hash").notNull(),activeFingerprints:Ui("active_fingerprints").notNull(),computedAt:Bi("computed_at",{withTimezone:!0}).notNull().defaultNow()},e=>[Vi("scaffolding_segments_user_id_harness_model_key").on(e.userId,e.harness,e.model)]);import{drizzle as Nr}from"drizzle-orm/postgres-js";import gr from"postgres";var jt={};Cr(jt,{agentJobs:()=>bn,agentRuns:()=>g,agentRunsRelations:()=>sa,alertDispatches:()=>dr,announcementDeliveries:()=>Fo,announcements:()=>Vo,apiKeys:()=>ye,apiKeysRelations:()=>Gi,benchmarks:()=>Ne,benchmarksRelations:()=>Na,cliErrorEvents:()=>fn,cliSetupEvents:()=>mn,contentBlobs:()=>zn,contextSnapshots:()=>J,contextSnapshotsRelations:()=>ya,evalComparisons:()=>Nn,evalConversations:()=>Te,evalConversationsRelations:()=>Ia,evalGradeAnnotations:()=>gn,evalJobs:()=>Ie,evalJobsRelations:()=>ha,evalRuns:()=>k,evalRunsRelations:()=>xa,evalTargets:()=>n,evalTargetsRelations:()=>pa,evals:()=>C,evalsRelations:()=>fa,extensionAuthCodes:()=>On,harnessReleases:()=>Vn,insightsJobs:()=>Kn,instructionEvents:()=>_e,instructionEventsRelations:()=>Zi,instructionPromotions:()=>hn,instructionSuggestionEvents:()=>Qn,instructionSuggestions:()=>No,instructionUsageEvents:()=>xe,instructionUsageEventsRelations:()=>ma,instructionVersionIdentities:()=>Po,instructionVersions:()=>ae,instructionVersionsRelations:()=>ta,instructions:()=>r,instructionsRelations:()=>Xi,judgeReviewerVerdicts:()=>vn,launchJobs:()=>Ae,launchJobsRelations:()=>ia,limitObservations:()=>or,memories:()=>T,memoriesRelations:()=>ea,memoryExperiments:()=>Uo,modelPricing:()=>Wn,notificationPreferences:()=>Go,notifications:()=>po,optimizationRuns:()=>he,optimizationRunsRelations:()=>va,orgInvitations:()=>b,orgInvitationsRelations:()=>$i,organizations:()=>u,organizationsRelations:()=>Ji,packInstructions:()=>F,packInstructionsRelations:()=>_a,packs:()=>z,packsRelations:()=>ca,pendingTreatmentExposures:()=>Zo,planLimitsActive:()=>ir,profiles:()=>o,profilesRelations:()=>Fi,projectCheckouts:()=>Oo,projectInstructions:()=>B,projectInstructionsRelations:()=>na,projects:()=>s,projectsRelations:()=>oa,providerDocsSnapshots:()=>nr,scaffoldingFingerprints:()=>lr,scaffoldingSegments:()=>_r,sessionEvents:()=>ue,sessionEventsRelations:()=>aa,sessionInstructions:()=>H,sessionInstructionsRelations:()=>da,sessionSendJobs:()=>nn,sessionTerminalTargets:()=>lt,sessions:()=>d,sessionsRelations:()=>ra,skillSubmissions:()=>Bn,teams:()=>h,teamsRelations:()=>Yi,treatmentAssignments:()=>S,treatmentAssignmentsRelations:()=>ua,treatmentExposures:()=>K,treatmentExposuresRelations:()=>la,triggerEvals:()=>ve,triggerEvalsRelations:()=>ga,userOrganizations:()=>se,userOrganizationsRelations:()=>Qi,userTeams:()=>ie,userTeamsRelations:()=>Wi,workerConnections:()=>ln});import{relations as i}from"drizzle-orm";var Fi=i(o,({many:e})=>({sessions:e(d),contextSnapshots:e(J),apiKeys:e(ye)})),Gi=i(ye,({one:e})=>({profile:e(o,{fields:[ye.userId],references:[o.id]})})),Ji=i(u,({many:e})=>({teams:e(h),userOrganizations:e(se),projects:e(s),invitations:e(b)})),Yi=i(h,({one:e,many:t})=>({organization:e(u,{fields:[h.orgId],references:[u.id]}),userTeams:t(ie),invitations:t(b)})),$i=i(b,({one:e})=>({organization:e(u,{fields:[b.orgId],references:[u.id]}),team:e(h,{fields:[b.teamId],references:[h.id]}),inviter:e(o,{fields:[b.invitedBy],references:[o.id]})})),Qi=i(se,({one:e})=>({organization:e(u,{fields:[se.orgId],references:[u.id]})})),Wi=i(ie,({one:e})=>({team:e(h,{fields:[ie.teamId],references:[h.id]})})),Xi=i(r,({one:e,many:t})=>({versions:t(ae),projectInstructions:t(B),events:t(_e),usageEvents:t(xe),sessionInstructions:t(H),packInstructions:t(F),forkedFrom:e(r,{fields:[r.forkedFromId],references:[r.id]})})),Zi=i(_e,({one:e})=>({instruction:e(r,{fields:[_e.instructionId],references:[r.id]})})),ea=i(T,({one:e,many:t})=>({project:e(s,{fields:[T.projectId],references:[s.id]}),parent:e(T,{fields:[T.parentId],references:[T.id]}),versions:t(T)})),ta=i(ae,({one:e})=>({instruction:e(r,{fields:[ae.instructionId],references:[r.id]})})),oa=i(s,({one:e,many:t})=>({organization:e(u,{fields:[s.orgId],references:[u.id]}),projectInstructions:t(B),sessions:t(d)})),na=i(B,({one:e})=>({project:e(s,{fields:[B.projectId],references:[s.id]}),instruction:e(r,{fields:[B.instructionId],references:[r.id]})})),ra=i(d,({one:e,many:t})=>({profile:e(o,{fields:[d.userId],references:[o.id]}),project:e(s,{fields:[d.projectId],references:[s.id]}),run:e(g,{fields:[d.runId],references:[g.id]}),events:t(ue),sessionInstructions:t(H),treatmentExposures:t(K),contextSnapshots:t(J)})),sa=i(g,({one:e,many:t})=>({profile:e(o,{fields:[g.userId],references:[o.id]}),organization:e(u,{fields:[g.orgId],references:[u.id]}),project:e(s,{fields:[g.projectId],references:[s.id]}),sessions:t(d),launchJobs:t(Ae)})),ia=i(Ae,({one:e})=>({run:e(g,{fields:[Ae.runId],references:[g.id]})})),aa=i(ue,({one:e})=>({session:e(d,{fields:[ue.sessionId],references:[d.id]})})),da=i(H,({one:e})=>({session:e(d,{fields:[H.sessionId],references:[d.id]}),instruction:e(r,{fields:[H.instructionId],references:[r.id]})})),ua=i(S,({one:e,many:t})=>({owner:e(o,{fields:[S.userId],references:[o.id]}),project:e(s,{fields:[S.projectId],references:[s.id]}),exposures:t(K)})),la=i(K,({one:e})=>({session:e(d,{fields:[K.sessionId],references:[d.id]}),owner:e(o,{fields:[K.userId],references:[o.id]}),assignment:e(S,{fields:[K.assignmentId],references:[S.id]})})),ca=i(z,({one:e,many:t})=>({packInstructions:t(F),forkedFrom:e(z,{fields:[z.forkedFromId],references:[z.id]})})),_a=i(F,({one:e})=>({pack:e(z,{fields:[F.packId],references:[z.id]}),instruction:e(r,{fields:[F.instructionId],references:[r.id]})})),ma=i(xe,({one:e})=>({instruction:e(r,{fields:[xe.instructionId],references:[r.id]})})),pa=i(n,({one:e,many:t})=>({parent:e(n,{fields:[n.parentId],references:[n.id]}),evals:t(C),evalRuns:t(k),benchmarks:t(Ne),triggerEvals:t(ve),optimizationRuns:t(he),evalJobs:t(Ie),evalConversations:t(Te)})),fa=i(C,({one:e,many:t})=>({evalTarget:e(n,{fields:[C.evalTargetId],references:[n.id]}),runs:t(k)})),xa=i(k,({one:e})=>({eval:e(C,{fields:[k.evalId],references:[C.id]}),evalTarget:e(n,{fields:[k.evalTargetId],references:[n.id]})})),Na=i(Ne,({one:e})=>({evalTarget:e(n,{fields:[Ne.evalTargetId],references:[n.id]})})),ga=i(ve,({one:e})=>({evalTarget:e(n,{fields:[ve.evalTargetId],references:[n.id]})})),va=i(he,({one:e})=>({evalTarget:e(n,{fields:[he.evalTargetId],references:[n.id]})})),ha=i(Ie,({one:e})=>({evalTarget:e(n,{fields:[Ie.evalTargetId],references:[n.id]})})),Ia=i(Te,({one:e})=>({evalTarget:e(n,{fields:[Te.evalTargetId],references:[n.id]})})),ya=i(J,({one:e})=>({session:e(d,{fields:[J.sessionId],references:[d.id]}),profile:e(o,{fields:[J.userId],references:[o.id]})}));var Qe=0,mr=0,We=0,pr=0;var Ta=0;function wo(){Qe++,Qe>mr&&(mr=Qe)}p(wo,"trackDbOpStart");function Ao(){Qe>0&&Qe--}p(Ao,"trackDbOpEnd");function zo(){We++,We>pr&&(pr=We)}p(zo,"trackHeavyDbOpStart");function Ro(){We>0&&We--}p(Ro,"trackHeavyDbOpEnd");function fr(){Ta++}p(fr,"recordQueryDeadline");var Et,St,Do=!1,kt;var xr,Kt,bt;function vr(e){let t=process.env[e];if(!t)throw new Error(`Missing required env var: ${e}`);return t}p(vr,"getEnv");function hr(){if(Do)throw new Error("getDb() called after closeDb(): the connection pool is closed for shutdown. Stop issuing queries (timers/requests) before draining the pool.");if(!Et){let e=process.env.PG_APPLICATION_NAME||"rulemetric",t=Number(process.env.PG_POOL_MAX)||3,a=Number(process.env.PG_CONNECT_TIMEOUT_S)||10,l=Number(process.env.PG_STATEMENT_TIMEOUT_MS)||0,m=Number(process.env.PG_IDLE_TIMEOUT)||5,f=Number(process.env.PG_KEEP_ALIVE_S)||60;St=gr(vr("DATABASE_URL"),{prepare:!1,max:t,connect_timeout:a,idle_timeout:m,keep_alive:f,max_lifetime:300,connection:{application_name:e,...l>0?{statement_timeout:l}:{}}}),Et=Nr(St,{schema:jt})}return Et}p(hr,"getDb");function Ir(){if(Do)throw new Error("getHeavyDb() called after closeDb(): the connection pool is closed for shutdown. Stop issuing queries (timers/requests) before draining the pool.");if(!bt){let e=(process.env.PG_APPLICATION_NAME||"rulemetric")+":heavy",t=Number(process.env.PG_HEAVY_POOL_MAX)||2;Kt=gr(vr("DATABASE_URL"),{prepare:!1,max:t,connect_timeout:Number(process.env.PG_CONNECT_TIMEOUT_S)||10,idle_timeout:Number(process.env.PG_IDLE_TIMEOUT)||5,keep_alive:Number(process.env.PG_KEEP_ALIVE_S)||60,max_lifetime:300,connection:{application_name:e}}),bt=Nr(Kt,{schema:jt})}return bt}p(Ir,"getHeavyDb");async function wa(){if(kt)return kt;Do=!0;let e=St,t=xr,a=Kt;return St=void 0,Et=void 0,xr=void 0,Kt=void 0,bt=void 0,kt=Promise.allSettled([e?e.end({timeout:5}):Promise.resolve(),t?t.end({timeout:5}):Promise.resolve(),a?a.end({timeout:5}):Promise.resolve()]).then(()=>{}),kt}p(wa,"closeDb");var Aa=new Set(["CONNECT_TIMEOUT","ETIMEDOUT","ENOTFOUND","ECONNREFUSED","EAI_AGAIN"]);function yr(e){let t=e,a=t?.code??t?.cause?.code??t?.errno;return a!==void 0&&Aa.has(a)}p(yr,"isRetryableConnectError");var za=new Set(["CONNECTION_CLOSED","ECONNRESET","EPIPE"]);function Tr(e){let t=e,a=t?.code??t?.cause?.code??t?.errno;return a!==void 0&&za.has(a)}p(Tr,"isRetryableResetError");async function wr(e,t={}){let a=t.attempts??3,l=t.baseMs??100,m;for(let f=0;f<a;f++)try{return await e()}catch(y){m=y;let ze=yr(y)||t.retryResets===!0&&Tr(y);if(f===a-1||!ze)throw y;await new Promise(Y=>setTimeout(Y,l*2**f))}throw m}p(wr,"withDbRetry");var Pt=class extends Error{static{p(this,"QueryDeadlineError")}code="QUERY_DEADLINE";constructor(t){super(`Query exceeded the client-side deadline of ${t}ms \u2014 the DB pool is likely saturated (acquire-wait) or holding a dead socket; failing fast to avoid pinning the caller. See client.ts.`),this.name="QueryDeadlineError"}};function Ar(){let e=Number(process.env.PG_QUERY_DEADLINE_MS);return Number.isFinite(e)&&e>=0?e:2e4}p(Ar,"queryDeadlineMs");function Ra(e,t){let a,l=new Promise((m,f)=>{a=setTimeout(()=>{fr(),f(new Pt(t))},t);let y=a;typeof y.unref=="function"&&y.unref()});return Promise.race([e,l]).finally(()=>clearTimeout(a))}p(Ra,"raceWithDeadline");var zr=new Set(["select","selectDistinct","selectDistinctOn","insert","update","delete","execute","with","$count","refreshMaterializedView"]),Rr=new Set(["select","selectDistinct","selectDistinctOn","$count"]);function jo(e,t=!1,a=0,l=!1){return e===null||typeof e!="object"&&typeof e!="function"?e:new Proxy(e,{get(m,f,y){if(f==="then"){let Y=Reflect.get(m,f,y);return typeof Y!="function"?Y:(kr,Er)=>{let br=l?zo:wo,Sr=l?Ro:Ao;br();let ko=wr(()=>new Promise((Kr,Pr)=>Y.call(m,Kr,Pr)),{retryResets:t});return(a>0?Ra(ko,a):ko).finally(Sr).then(kr,Er)}}let ze=Reflect.get(m,f,y);return typeof ze=="function"?(...Y)=>jo(ze.apply(m,Y),t,a,l):ze}})}p(jo,"wrapBuilder");function Dr(e,t=!1){let a=t?zo:wo,l=t?Ro:Ao;a();try{return Promise.resolve(e()).finally(l)}catch(m){throw l(),m}}p(Dr,"gaugeTransaction");var jr=new Proxy({},{get(e,t){let a=hr(),l=a[t];if(typeof t=="string"&&zr.has(t)&&typeof l=="function"){let m=Rr.has(t),f=Ar();return(...y)=>jo(l.apply(a,y),m,f)}return t==="transaction"&&typeof l=="function"?(...m)=>Dr(()=>l.apply(a,m)):l}}),Da=new Proxy({},{get(e,t){let a=Ir(),l=a[t];if(typeof t=="string"&&zr.has(t)&&typeof l=="function"){let m=Rr.has(t);return(...f)=>jo(l.apply(a,f),m,0,!0)}return t==="transaction"&&typeof l=="function"?(...m)=>Dr(()=>l.apply(a,m),!0):l}});export{o as a,g as b,d as c,T as d,Uo as e,Vo as f,Fo as g,Go as h,hr as i,wa as j};
@@ -1,2 +1,2 @@
1
- import{a as R}from"./chunk-5RBLIVBF.js";import{b as B}from"./chunk-N7TGRFVZ.js";import{a as v,f as d,g as n,h as m,i as U}from"./chunk-3DLVY7LD.js";import{a as $}from"./chunk-ZLLER3HP.js";import{and as L,asc as j,eq as l,gt as q,isNotNull as F,sql as O}from"drizzle-orm";var _=100,C=10;async function G(I,s={}){let t=s.db??U(),D=s.sendEmail??B,p=s.log??(o=>process.stderr.write(`[process_announcement] ${o}
1
+ import{a as R}from"./chunk-5RBLIVBF.js";import{b as B}from"./chunk-N7TGRFVZ.js";import{a as v,f as d,g as n,h as m,i as U}from"./chunk-JGLVVIEM.js";import{a as $}from"./chunk-ZLLER3HP.js";import{and as L,asc as j,eq as l,gt as q,isNotNull as F,sql as O}from"drizzle-orm";var _=100,C=10;async function G(I,s={}){let t=s.db??U(),D=s.sendEmail??B,p=s.log??(o=>process.stderr.write(`[process_announcement] ${o}
2
2
  `)),b=s.webBaseUrl??process.env.RULEMETRIC_WEB_URL??process.env.WEB_URL??"https://rulemetric.com",{announcementId:r}=I,[i]=await t.select().from(d).where(l(d.id,r)).limit(1);if(!i)throw new R(`Announcement ${r} not found`);if(i.status!=="queued"&&i.status!=="sending")throw new R(`Announcement ${r} is in status='${i.status}'; expected 'queued' or 'sending'.`);await t.update(d).set({status:"sending",updatedAt:new Date}).where(l(d.id,r)),p(`Sending announcement ${r} (${i.subject??""})`);let w=0,f=0,h=0,y=0,k=null;try{for(;;){let c=await t.select({userId:m.userId,email:v.email,displayName:v.displayName,unsubscribeToken:m.unsubscribeToken}).from(m).innerJoin(v,l(v.id,m.userId)).where(L(l(m.productAnnouncements,!0),F(v.email),k?q(m.userId,k):void 0)).orderBy(j(m.userId)).limit(_);if(c.length===0)break;k=c[c.length-1].userId;for(let A=0;A<c.length;A+=C){let P=c.slice(A,A+C),S=await Promise.allSettled(P.map(g=>W({recipient:g,announcement:i,webBaseUrl:b,sendEmail:D,db:t})));for(let g=0;g<S.length;g++){let u=S[g];if(u.status==="fulfilled")u.value.ok==="sent"?w++:u.value.ok==="skipped"?h++:(f++,u.value.provider==="noop"&&y++,p(` recipient ${P[g].userId}: send failed \u2014 ${u.value.error}`));else{f++;let T=u.reason instanceof Error?u.reason.message:String(u.reason);p(` recipient ${P[g].userId}: send failed \u2014 ${T}`)}}}if(c.length<_)break}y>0&&p(`WARNING: ${y} recipient(s) hit the noop email provider and were recorded as FAILED \u2014 no email provider is configured on this worker (set RESEND_API_KEY in ~/.config/rulemetric/env and reinstall the service)`);let o=await t.select({status:n.status,count:O`count(*)::int`}).from(n).where(l(n.announcementId,r)).groupBy(n.status),e={};for(let c of o)e[c.status]=c.count;let a=e.sent??0,E=e.failed??0,N=a===0&&E>0?"failed":"sent",x=E>0?`${E} of ${a+E} recipient(s) failed; see announcement_deliveries`:null;return await t.update(d).set({status:N,recipientCount:a,...N==="sent"?{sentAt:new Date}:{},error:x,updatedAt:new Date}).where(l(d.id,r)),p(`Done: status=${N} sent=${a} failed=${E} (this attempt: sent=${w} failed=${f} skipped=${h})`),{sent:w,failed:f,skipped:h}}catch(o){let e=o instanceof Error?o.message:String(o);throw await t.update(d).set({status:"failed",error:e.slice(0,1e3),updatedAt:new Date}).where(l(d.id,r)).catch(()=>{}),o}}$(G,"processAnnouncement");function K(I){return I.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}$(K,"escapeHtml");async function W(I){let{recipient:s,announcement:t,webBaseUrl:D,sendEmail:p,db:b}=I;if(!s.email)return{ok:"skipped",reason:"no-email"};let r=await b.insert(n).values({announcementId:t.id,userId:s.userId,email:s.email,status:"pending"}).onConflictDoNothing({target:[n.announcementId,n.userId]}).returning({id:n.id});if(r.length===0)return{ok:"skipped",reason:"already-claimed"};let i=r[0].id,w=D.replace(/\/$/,""),f=encodeURIComponent(s.unsubscribeToken),h=`${w}/unsubscribe/${f}`,y=s.displayName?.trim().split(/\s+/)[0]||"there",k=t.htmlBody.replaceAll("{{unsubscribe_url}}",h).replaceAll("{{recipient_name}}",K(y)),o=t.textBody.replaceAll("{{unsubscribe_url}}",h).replaceAll("{{recipient_name}}",y);try{let e=await p({to:s.email,subject:t.subject,html:k,text:o,fromName:"RuleMetric",idempotencyKey:i,headers:{"List-Unsubscribe":`<${w}/api/unsubscribe/${f}>`,"List-Unsubscribe-Post":"List-Unsubscribe=One-Click"}});if(e.provider==="noop"){let a="no email provider configured (RESEND_API_KEY unset on the worker)";return await b.update(n).set({status:"failed",error:a}).where(l(n.id,i)),{ok:"failed",error:a,provider:e.provider}}return await b.update(n).set({status:"sent",providerId:e.id,sentAt:new Date}).where(l(n.id,i)),{ok:"sent",providerId:e.id,provider:e.provider}}catch(e){let a=e instanceof Error?e.message:String(e);return await b.update(n).set({status:"failed",error:a.slice(0,1e3)}).where(l(n.id,i)).catch(()=>{}),{ok:"failed",error:a}}}$(W,"sendOne");export{G as a};
@@ -1,2 +1,2 @@
1
- import{y as w}from"./chunk-7DFNBRLY.js";import{a as m}from"./chunk-N7ODX6PO.js";import{a as s}from"./chunk-ZLLER3HP.js";import{spawn as g}from"node:child_process";import d from"node:fs";import b from"node:path";function c(e,t){return new Promise((r,n)=>{let o=g("git",e,{cwd:t,stdio:["ignore","pipe","pipe"],env:m()}),i="",f="";o.stdout.on("data",a=>{i+=a.toString()}),o.stderr.on("data",a=>{f+=a.toString()}),o.on("error",a=>n(new Error(`git ${e.join(" ")} failed to spawn: ${a.message}`))),o.on("close",a=>{a===0?r({code:a,stdout:i,stderr:f}):n(new Error(`git ${e.join(" ")} exited ${a}: ${f.trim()||i.trim()}`))})})}s(c,"runGit");async function k(e,t){if(!t||!t.trim())throw new Error('invalid branch name "": branch must be a non-empty git refname');if(t.startsWith("-"))throw new Error(`invalid branch name "${t}": must not start with "-" (git would parse it as an option)`);if(/\s/.test(t))throw new Error(`invalid branch name "${t}": must not contain whitespace`);try{await c(["check-ref-format","--branch",t],e)}catch{throw new Error(`invalid branch name "${t}": not a valid git refname`)}}s(k,"assertValidBranch");function h(e){let t=b.resolve(e);try{return d.realpathSync(t)}catch{return t}}s(h,"canonical");function y(e){let t=[],r=null;for(let n of e.split(`
1
+ import{y as w}from"./chunk-5DIOZDDZ.js";import{a as m}from"./chunk-N7ODX6PO.js";import{a as s}from"./chunk-ZLLER3HP.js";import{spawn as g}from"node:child_process";import d from"node:fs";import b from"node:path";function c(e,t){return new Promise((r,n)=>{let o=g("git",e,{cwd:t,stdio:["ignore","pipe","pipe"],env:m()}),i="",f="";o.stdout.on("data",a=>{i+=a.toString()}),o.stderr.on("data",a=>{f+=a.toString()}),o.on("error",a=>n(new Error(`git ${e.join(" ")} failed to spawn: ${a.message}`))),o.on("close",a=>{a===0?r({code:a,stdout:i,stderr:f}):n(new Error(`git ${e.join(" ")} exited ${a}: ${f.trim()||i.trim()}`))})})}s(c,"runGit");async function k(e,t){if(!t||!t.trim())throw new Error('invalid branch name "": branch must be a non-empty git refname');if(t.startsWith("-"))throw new Error(`invalid branch name "${t}": must not start with "-" (git would parse it as an option)`);if(/\s/.test(t))throw new Error(`invalid branch name "${t}": must not contain whitespace`);try{await c(["check-ref-format","--branch",t],e)}catch{throw new Error(`invalid branch name "${t}": not a valid git refname`)}}s(k,"assertValidBranch");function h(e){let t=b.resolve(e);try{return d.realpathSync(t)}catch{return t}}s(h,"canonical");function y(e){let t=[],r=null;for(let n of e.split(`
2
2
  `))n.startsWith("worktree ")?(r&&t.push(r),r={path:n.slice(9).trim()}):n.startsWith("branch ")&&r&&(r.branch=n.slice(7).trim().replace(/^refs\/heads\//,""));return r&&t.push(r),t}s(y,"parseWorktreeList");async function v(e,t){try{return await c(["show-ref","--verify","--quiet",`refs/heads/${t}`],e),!0}catch{return!1}}s(v,"branchExists");async function B(e){let{repoRoot:t,branch:r,baseRef:n,allowExistingBranch:o=!1}=e;await k(t,r);let i=w({repoRoot:t,branch:r,basePath:e.basePath}),f=await c(["worktree","list","--porcelain"],t),a=y(f.stdout),p=a.find(u=>u.branch===r);if(p)return{path:h(p.path),branch:r,created:!1};let l=a.find(u=>h(u.path)===i);if(l)return{path:h(l.path),branch:l.branch??r,created:!1};if(await v(t,r)){if(!o)throw new Error(`branch "${r}" already exists with no worktree; refusing to clobber (pass allowExistingBranch:true to attach a worktree onto it)`);return await c(["worktree","add",i,r],t),{path:h(i),branch:r,created:!0}}return await c(["worktree","add",i,"-b",r,n],t),{path:h(i),branch:r,created:!0}}s(B,"ensureWorktree");async function S(e){let{repoRoot:t,worktreePath:r}=e;if(!d.existsSync(r))return{removed:!1,reason:"absent"};let n=!1;try{n=(await c(["status","--porcelain"],r)).stdout.trim().length>0}catch{n=!1}if(n)return{removed:!1,reason:"dirty"};try{return await c(["worktree","remove",r],t),{removed:!0}}catch(o){let i=o instanceof Error?o.message:String(o);if(/not a working tree|No such file or directory|not a valid path|is not a working tree/i.test(i))return{removed:!1,reason:"absent"};throw o}}s(S,"removeWorktree");export{c as a,B as b,S as c};
@@ -1 +1 @@
1
- import{a as l}from"./chunk-WKXTY5AM.js";import{a as r}from"./chunk-ZLLER3HP.js";var u=r(n=>{let t=n.grading.summary?.pass_rate;return typeof t=="number"?t:null},"passRateOf"),a=r(n=>(u(n)??0)>=1,"fullPass");function f(n,t){let i=new Map(n.filter(e=>u(e)!=null).map(e=>[e.evalName,e])),o=[];for(let e of t){if(u(e)==null)continue;let s=i.get(e.evalName);s&&o.push({withScore:a(e)?1:0,withoutScore:a(s)?1:0})}return o}r(f,"pairVersionResults");function d(n,t){let i=f(n,t);return i.length===0?null:l(i,{baseline:"prior-version"})}r(d,"buildVersionVerdict");function m(n,t,i){let o=`v${i} vs v${t}`;if(!n.sufficient)return`${o}: ${n.insufficientReason??"insufficient data"} \u2014 no effect claimed`;let e=n.delta>=0?"+":"",s=`95% CI ${(n.ci.lower*100).toFixed(0)}\u2013${(n.ci.upper*100).toFixed(0)}%`,c=n.significant?"significant":"not significant";return`${o}: ${e}${(n.delta*100).toFixed(0)}% pass rate (${s}, n=${n.nWith} paired, ${c})`}r(m,"formatVersionVerdict");export{f as a,d as b,m as c};
1
+ import{b as l}from"./chunk-G5BXZT6F.js";import{a as r}from"./chunk-ZLLER3HP.js";var u=r(n=>{let t=n.grading.summary?.pass_rate;return typeof t=="number"?t:null},"passRateOf"),a=r(n=>(u(n)??0)>=1,"fullPass");function f(n,t){let i=new Map(n.filter(e=>u(e)!=null).map(e=>[e.evalName,e])),o=[];for(let e of t){if(u(e)==null)continue;let s=i.get(e.evalName);s&&o.push({withScore:a(e)?1:0,withoutScore:a(s)?1:0})}return o}r(f,"pairVersionResults");function d(n,t){let i=f(n,t);return i.length===0?null:l(i,{baseline:"prior-version"})}r(d,"buildVersionVerdict");function m(n,t,i){let o=`v${i} vs v${t}`;if(!n.sufficient)return`${o}: ${n.insufficientReason??"insufficient data"} \u2014 no effect claimed`;let e=n.delta>=0?"+":"",s=`95% CI ${(n.ci.lower*100).toFixed(0)}\u2013${(n.ci.upper*100).toFixed(0)}%`,c=n.significant?"significant":"not significant";return`${o}: ${e}${(n.delta*100).toFixed(0)}% pass rate (${s}, n=${n.nWith} paired, ${c})`}r(m,"formatVersionVerdict");export{f as a,d as b,m as c};
@@ -0,0 +1,4 @@
1
+ import{c as l,d as w}from"./chunk-KKDHD4XA.js";import{a as m,d as p}from"./chunk-SZ62CP55.js";import{a as r}from"./chunk-ZLLER3HP.js";import{spawn as b}from"node:child_process";import{createConnection as g}from"node:net";import{existsSync as E,mkdirSync as P,openSync as T,readFileSync as R,unlinkSync as _,writeFileSync as h}from"node:fs";import{homedir as x}from"node:os";import{dirname as A,join as y,resolve as a}from"node:path";import{fileURLToPath as L}from"node:url";var s=A(L(import.meta.url)),f=y(x(),".config","rulemetric"),c=y(f,"gateway.pid"),M=y(f,"gateway.log"),I=8787;function O(e=process.env){let t=e.RULEMETRIC_GATEWAY_PORT;if(t===void 0||t.trim()==="")return I;let o=Number(t);return!Number.isInteger(o)||o<1024||o>65535?I:o}r(O,"resolveGatewayPort");var u=O(),J=8788;function v(e=u,t=1500){return new Promise(o=>{let n=g({host:"127.0.0.1",port:e}),i=r(G=>{n.destroy(),o(G)},"finish");n.setTimeout(t),n.once("connect",()=>i(!0)),n.once("timeout",()=>i(!1)),n.once("error",()=>i(!1))})}r(v,"isGatewayListening");async function V(e=u,{timeoutMs:t=3e3,intervalMs:o=150}={}){let n=Date.now()+t;for(;;){if(await v(e,Math.min(1500,t)))return!0;if(Date.now()>=n)return!1;await new Promise(i=>setTimeout(i,o))}}r(V,"waitForGatewayListening");function X(e=u,t=1500){return l(e,t)}r(X,"isRulemetricGatewayListening");function $(e=u,t={}){return w(e,t)}r($,"waitForRulemetricGateway");function F(e={}){let t=d();return t===null?!1:p(t,m,e)}r(F,"isGatewayRunning");function d(){if(!E(c))return null;let e=R(c,"utf-8").trim(),t=parseInt(e,10);return isNaN(t)?null:t}r(d,"getGatewayPid");function N(){let e=[a(s,"./gateway-entry.js"),a(s,"./lib/gateway-entry.js"),a(s,"../lib/gateway-entry.js"),a(s,"../../lib/gateway-entry.js")];for(let t of e)if(E(t))return t;throw new Error(`Could not find gateway-entry.js. Is the CLI built?
2
+ Searched:
3
+ `+e.map(t=>` ${t}`).join(`
4
+ `))}r(N,"findGatewayEntry");function q(e){if(F()){let i=d();if(i)return i}P(f,{recursive:!0});let t=N(),o=T(M,"a"),n=b(process.execPath,[t],{detached:!0,stdio:["ignore",o,o],env:{...process.env,RULEMETRIC_CLI_VERSION:e??"unknown",RULEMETRIC_CLI_ENTRY:process.argv[1]??""}});if(n.unref(),!n.pid)throw new Error("Failed to spawn gateway process");return h(c,String(n.pid)),n.pid}r(q,"spawnGateway");function z(e={}){let t=d();if(t===null)return!1;if(p(t,m,e))try{process.kill(t,"SIGTERM")}catch{}try{_(c)}catch{}return!0}r(z,"stopGateway");export{c as a,M as b,I as c,O as d,u as e,J as f,v as g,V as h,X as i,$ as j,F as k,d as l,q as m,z as n};
@@ -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,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};
@@ -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 +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{d as U}from"../chunk-NTKO4H2K.js";import"../chunk-B3BHB26P.js";import"../chunk-N7ODX6PO.js";import"../chunk-PJ3WHQ67.js";import{a as E,b as H,d as X}from"../chunk-VX2GJCQ4.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};