@withgauge/cli 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -3
- package/dist/batchWorker.js +1 -1
- package/dist/chatApi-KHPW7ED5.js +1 -0
- package/dist/chunk-DEX43SUK.js +1 -0
- package/dist/chunk-EVT234WT.js +69 -0
- package/dist/chunk-KRHTXL5O.js +1 -0
- package/dist/chunk-OIGVDK3F.js +2 -0
- package/dist/chunk-QV7MOO3M.js +2 -0
- package/dist/{chunk-KLWQOTEK.js → chunk-WYYRMPRX.js} +1 -1
- package/dist/chunk-XHPA33OA.js +2 -0
- package/dist/index.js +60 -27
- package/dist/orgDirectory-V3RCKGLA.js +1 -0
- package/dist/telemetryWorker.js +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-FCK3MQPV.js +0 -2
- package/dist/chunk-RB7Q72OV.js +0 -1
- package/dist/chunk-RI75U3EB.js +0 -70
package/dist/index.js
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{ANALYSIS_SCHEMA_VERSION,ApiClient,CLI_VERSION,CliError,LOCAL_AGENTS,LOCAL_MCP_HINT,LOCAL_TARGETS,USER_AGENT,agentConfigInputSchema,agentConfigSchema,agentSchema,analysisNext,analysisSubmissionSchema,assertLocalCapabilities,assetRefListSchema,batteries_exports,brands_exports,cancelLocal,cleanupLocal,clearToken,createClient,credentialsPath,detachLocal,errorEnvelopeSchema,exitCodeFor,feedback_exports,inspectLocalCredential,inspectLocalRuntime,keys_exports,listResponseSchema,localBatchStatus,localStatus,openLocalStore,planLocal,pullLocalRuntime,readProfiles,requireProfile,resolveBaseUrl,resolveToken,runConfig_exports,runCreditsChargedSchema,runEventSchema,runLocal,runTriggeredBySchema,saveToken,setProfile,writeProfiles}from"./chunk-RI75U3EB.js";import{setTelemetryEnabled,telemetryStatus}from"./chunk-KLWQOTEK.js";import{CONFIG_KEYS,configPath,readConfig,updateConfig}from"./chunk-FCK3MQPV.js";import"./chunk-RB7Q72OV.js";import{__export}from"./chunk-PSBF4TEK.js";import{Command,CommanderError as CommanderError2,Option as Option4}from"commander";import{fileURLToPath}from"url";var actions_exports={};__export(actions_exports,{register:()=>register});import{existsSync,readFileSync}from"fs";import{dirname,join,resolve}from"path";function findWorkspace(cwd=process.cwd()){let directory=resolve(cwd);while(true){if(existsSync(join(directory,"gauge.json")))return directory;const parent=dirname(directory);if(parent===directory)return void 0;directory=parent}}function gaugeState(command,cwd=process.cwd()){return readGaugeState(command.optsWithGlobals(),cwd)}function backend(value,location){if(value===void 0)return void 0;if(value==="local"||value==="hosted")return value;throw new CliError("usage",`Invalid backend in ${location}: expected local or hosted`)}function readGaugeState(flags,cwd=process.cwd(),account={signedIn:resolveToken()!==null,...readConfig()}){const root=findWorkspace(cwd);let config;let workspaceBackend;if(root){try{const parsed=JSON.parse(readFileSync(join(root,"gauge.json"),"utf8"));config=parsed&&typeof parsed==="object"&&!Array.isArray(parsed)?parsed:null}catch{config=null}if(config&&"mode"in config)throw new CliError("usage","gauge.json does not accept mode. Set backend in private .gauge/config.json; keep the project manifest backend-independent.");const path=join(root,".gauge","config.json");if(existsSync(path)){let value;try{value=JSON.parse(readFileSync(path,"utf8"))}catch{throw new CliError("usage",`${path} is not valid JSON`)}if(!value||value.version!==1)throw new CliError("usage",`Unsupported workspace configuration version in ${path}`);workspaceBackend=backend(value.backend,path)}}const userBackend=backend(account.backend,"user configuration");const[mode,source]=flags.local?["local","flag"]:flags.hosted?["hosted","flag"]:workspaceBackend?[workspaceBackend,"workspace"]:userBackend?[userBackend,"user"]:["local","default"];return{mode,source,root,inRepo:root!==void 0,config,signedIn:account.signedIn,defaultOrg:account.defaultOrg}}function instructionMode(state){const why={flag:"from the flag",workspace:"from .gauge/config.json",user:"from user configuration",default:"the default"};return{mode:state.mode,why:why[state.source]}}function header(state,topic,brief=false){const{mode,why}=instructionMode(state);const lines=[`Mode: ${mode} (${why}). Pass --${mode==="local"?"hosted":"local"} to switch for this command.`];if(mode==="local"&&topic&&!topic.local&&!topic.shared)lines.push("This topic is hosted only. Local guidance: `gauge instructions --local`.");if(state.config===null)lines.push("gauge.json is not valid JSON. Fix it before using this workspace.");else if(!state.root&&!brief)lines.push("Run `gauge init` to initialize this directory. It writes gauge.json and private .gauge/ state. Add --cases only to scaffold shared gauge-cases/ files.");else if(!brief&&(!topic||topic.key==="root"))lines.push("Next: `gauge instructions eval` or `gauge instructions preference` to create a saved measurement; `gauge instructions run` to launch it.");return lines}function resolveOrg(command,fileOrg){const{org}=command.optsWithGlobals();if(org)return org;if(fileOrg)return fileOrg;const projectOrg=gaugeState(command).config?.org;if(typeof projectOrg==="string"&&projectOrg)return projectOrg;const{defaultOrg}=readConfig();if(defaultOrg)return defaultOrg;throw new CliError("usage","No organization selected. Pass --org <org> or set a default with `gauge orgs use <slug>`.",{needsAccount:true})}function resolveOutput(command){const{output}=command.optsWithGlobals();return output==="json"?"json":"table"}function requireHosted(command,{account=false,hint}={}){const{mode,source}=gaugeState(command);if(mode==="local"&&(source==="flag"||!account))throw new CliError("usage","This command needs hosted Gauge.",{needsAccount:true,hint})}function hostedOnly(command,options={}){return command.hook("preAction",(_command,action)=>requireHosted(action,options))}var OUTPUT_FORMATS=["table","json"];function colorEnabled(stream){if(process.env.FORCE_COLOR)return process.env.FORCE_COLOR!=="0";return stream.isTTY===true&&!process.env.NO_COLOR&&process.env.TERM!=="dumb"}function style(code,stream=process.stdout){const on=colorEnabled(stream);return text=>on?`\x1B[${code}m${text}\x1B[0m`:text}function printJson(value){console.log(JSON.stringify(value,null,2))}function printItems(items,format,columns){if(format==="json"){printJson(items);return}if(items.length===0){console.log("(no results)");return}const cols=columns??Object.keys(items[0]).map(key=>({key}));const headers=cols.map(col=>col.header??col.key);const rows=items.map(item=>cols.map(col=>cell(item[col.key])));const widths=headers.map((header2,i)=>Math.max(header2.length,...rows.map(row2=>row2[i].length)));const line=values=>values.map((value,i)=>value.padEnd(widths[i])).join(" ").trimEnd();console.log(line(headers));for(const row2 of rows)console.log(line(row2))}function cell(value){if(value===null||value===void 0||value==="")return"\u2014";if(value instanceof Date)return value.toISOString();if(typeof value==="object")return JSON.stringify(value);return String(value)}function actionsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/actions`}var STATUS_CHOICES=["open","resolved","dismissed"];function parseStatus(raw){const upper=raw.trim().toUpperCase();if(!["OPEN","RESOLVED","DISMISSED"].includes(upper))throw new CliError("usage",`invalid status "${raw}" (expected: ${STATUS_CHOICES.join(" | ")})`);return upper}function register(program2){const group=hostedOnly(program2.command("actions")).description("The action center: recommended follow-ups");group.command("list").description("List actions, highest-leverage first").option("--status <status>","filter: open | resolved | dismissed (csv)").action(async(opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(actionsPath(org),{status:opts.status===void 0?void 0:opts.status.split(",").map(s=>parseStatus(s)).join(",")});if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(a=>({id:a.id,priority:a.priority,status:a.status,title:a.title,evidence:a.evidenceCount,surface:a.sourceType})),"table")});group.command("status <id> <status>").description("Transition an action: open | resolved | dismissed").option("--note <text>","resolution note (recorded when closing)").action(async(id,status,opts,cmd)=>{const org=resolveOrg(cmd);const updated=await createClient().patch(`${actionsPath(org)}/${encodeURIComponent(id)}`,{status:parseStatus(status),note:opts.note});if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Action ${updated.id} is now ${updated.status}`)})}var auth_exports={};__export(auth_exports,{deviceLogin:()=>deviceLogin,parseLoopbackCallback:()=>parseLoopbackCallback,readStdin:()=>readStdin,register:()=>register2,useOnlyOrg:()=>useOnlyOrg});import{spawn}from"child_process";import{createHash,randomBytes}from"crypto";import{createServer}from"http";import{hostname}from"os";import{createInterface}from"readline";import{setTimeout as sleep}from"timers/promises";import{z}from"zod";var PKCE_VERIFIER_PATTERN=/^[A-Za-z0-9._~-]{43,128}$/;var cliAuthorizationTokenRequestSchema=z.object({code:z.string().min(1).max(512),codeVerifier:z.string().regex(PKCE_VERIFIER_PATTERN)});var cliAuthorizationTokenResponseSchema=z.object({accessToken:z.string(),tokenType:z.literal("bearer"),expiresAt:z.string().nullable()});import{z as z2}from"zod";var deviceAuthorizeRequestSchema=z2.object({deviceName:z2.string().trim().max(64).optional(),email:z2.string().trim().email().max(320).optional()});var deviceAuthorizeResponseSchema=z2.object({deviceCode:z2.string(),userCode:z2.string(),verificationUri:z2.string(),verificationUriComplete:z2.string(),interval:z2.number().int().positive(),expiresIn:z2.number().int().positive(),emailSent:z2.boolean()});var deviceTokenRequestSchema=z2.object({deviceCode:z2.string().min(1)});var deviceTokenApprovedSchema=z2.object({status:z2.literal("approved"),accessToken:z2.string(),tokenType:z2.literal("bearer"),expiresAt:z2.string().nullable()});var deviceTokenResultSchema=z2.discriminatedUnion("status",[z2.object({status:z2.literal("pending")}),z2.object({status:z2.literal("slow_down"),interval:z2.number().int()}),z2.object({status:z2.literal("denied")}),z2.object({status:z2.literal("expired")}),deviceTokenApprovedSchema]);async function fetchAllPages(client,path,query={}){const items=[];let cursor;do{const page=await client.get(path,{limit:200,...query,cursor});items.push(...page.items);cursor=page.nextCursor}while(cursor);return items}var LOGIN_TIMEOUT_MS=2*60*1e3;var TOKEN_PREFIX="gauge_";function tokenSource(){if(process.env.GAUGE_API_TOKEN?.trim())return"env";return resolveToken()?"file":"none"}async function fetchMe(client){return client.get("/api/v1/me")}function parseLoopbackCallback(rawUrl,expectedState){const url=new URL(rawUrl??"/","http://127.0.0.1");if(url.pathname!=="/callback")return null;const code=url.searchParams.get("code");if(url.searchParams.get("state")!==expectedState||!code)return null;return code}function printIdentity(me){const orgs=me.orgs.map(o=>o.slug).join(", ")||"(none)";console.log(`Logged in as ${me.user.email??me.user.id}`);console.log(`Orgs: ${orgs}`);console.log(`API URL: ${resolveBaseUrl()}`)}function useOnlyOrg(me){const only=me.orgs.length===1?me.orgs[0].slug:void 0;if(!only||readConfig().defaultOrg)return;updateConfig({defaultOrg:only});console.log(`Default org set to ${only}.`)}function openBrowser(url){const[cmd,args]=process.platform==="darwin"?["open",[url]]:process.platform==="win32"?["cmd",["/c","start","",url]]:["xdg-open",[url]];try{const child=spawn(cmd,args,{stdio:"ignore",detached:true});child.on("error",()=>{});child.unref()}catch{}}async function browserLogin(){const state=randomBytes(16).toString("base64url");const codeVerifier=randomBytes(32).toString("base64url");const codeChallenge=createHash("sha256").update(codeVerifier).digest("base64url");const server=createServer();const codePromise=new Promise((resolve6,reject)=>{server.on("request",(req,res)=>{const url=new URL(req.url??"/","http://127.0.0.1");if(url.pathname!=="/callback"){res.writeHead(404).end();return}if(req.method!=="GET"){res.writeHead(405,{allow:"GET"}).end();return}const code=parseLoopbackCallback(req.url,state);if(!code){res.writeHead(400,{"content-type":"text/plain; charset=utf-8"});res.end("Invalid callback. Retry gauge auth login.");return}res.writeHead(200,{"content-type":"text/plain; charset=utf-8"});res.end("Authorized. Return to your terminal.");resolve6(code)});server.on("error",e=>reject(new CliError("network",`Loopback listener failed: ${e.message}`)))});await new Promise(resolve6=>{server.listen(0,"127.0.0.1",resolve6)});const address=server.address();if(!address||typeof address==="string"){server.close();throw new CliError("internal","Could not determine the listener port")}const base=resolveBaseUrl().replace(/\/+$/,"");const authorizeUrl=new URL(`${base}/cli/authorize`);authorizeUrl.searchParams.set("port",String(address.port));authorizeUrl.searchParams.set("state",state);authorizeUrl.searchParams.set("name",hostname()||"this device");authorizeUrl.searchParams.set("code_challenge",codeChallenge);authorizeUrl.searchParams.set("code_challenge_method","S256");console.log("Opening your browser to authorize the Gauge CLI\u2026");console.log(`If it doesn't open, visit:
|
|
2
|
+
import{LOCAL_AGENTS,LOCAL_MCP_HINT,LOCAL_TARGETS,analysisNext,assertLocalCapabilities,cancelLocal,cleanupLocal,commentSourceSchema,deploymentSourceSchema,detachLocal,freezeWebFixtures,inspectLocalCredential,inspectLocalGateway,inspectLocalRuntime,localBatchStatus,localStatus,mergeWebFixtures,openLocalStore,parseWebFixtureInput,planLocal,pullLocalGateway,pullLocalRuntime,readProfiles,readWebFixtureArchive,requireProfile,runLocal,setProfile,websiteSourceSchema,websiteUseSchema,writeProfiles}from"./chunk-EVT234WT.js";import{setTelemetryEnabled,telemetryStatus}from"./chunk-WYYRMPRX.js";import"./chunk-QV7MOO3M.js";import{CHAT_BATCH_SIZE,ChatApiClient,OUTPUT_FORMATS,addPageOptions,categoryScope,chatPath,chatScope,chunks,createChatApiClient,csv,describeScopes,fetchPages,findWorkspace,gaugeState,header,hostedOnly,instructionMode,printItems,printJson,printPage,readGaugeState,requireHosted,resolveChatCategory,resolveOrg,resolveOutput,resolveTagIds,resolveTopicId,style,truncate,withCategory}from"./chunk-KRHTXL5O.js";import{createdOrganization,credentialKind,fetchDirectory,findOrganization,isUuid,legacySelection,productsLabel,resolveOrgValue}from"./chunk-DEX43SUK.js";import{ANALYSIS_SCHEMA_VERSION,ApiClient,CliError,agentConfigInputSchema,agentConfigSchema,agentSchema,analysisSubmissionSchema,assetRefListSchema,batteries_exports,brands_exports,clearToken,createClient,createdBySchema,credentialsPath,errorEnvelopeSchema,exitCodeFor,feedback_exports,keys_exports,listResponseSchema,readCredentials,resolveAuthUrl,resolveBaseUrl,resolveToken,runConfig_exports,runCreditsChargedSchema,runEventSchema,runTriggeredBySchema,saveCredentials,saveToken,sharedTokenSchema,storedSharedCredentials,withCredentialLock}from"./chunk-XHPA33OA.js";import{CLI_VERSION,CONFIG_KEYS,USER_AGENT,configPath,readConfig,updateConfig}from"./chunk-OIGVDK3F.js";import{__export}from"./chunk-PSBF4TEK.js";import{Command,CommanderError as CommanderError2,Option as Option5}from"commander";import{fileURLToPath}from"url";var actions_exports={};__export(actions_exports,{register:()=>register});function actionsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/actions`}var STATUS_CHOICES=["open","resolved","dismissed"];function parseStatus(raw){const upper=raw.trim().toUpperCase();if(!["OPEN","RESOLVED","DISMISSED"].includes(upper))throw new CliError("usage",`invalid status "${raw}" (expected: ${STATUS_CHOICES.join(" | ")})`);return upper}function register(program2){const group=hostedOnly(program2.command("actions")).description("The action center: recommended follow-ups");group.command("list").description("List actions, highest-leverage first").option("--status <status>","filter: open | resolved | dismissed (csv)").action(async(opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(actionsPath(org),{status:opts.status===void 0?void 0:opts.status.split(",").map(s=>parseStatus(s)).join(",")});if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(a=>({id:a.id,priority:a.priority,status:a.status,title:a.title,evidence:a.evidenceCount,surface:a.sourceType})),"table")});group.command("status <id> <status>").description("Transition an action: open | resolved | dismissed").option("--note <text>","resolution note (recorded when closing)").action(async(id,status,opts,cmd)=>{const org=await resolveOrg(cmd);const updated=await createClient().patch(`${actionsPath(org)}/${encodeURIComponent(id)}`,{status:parseStatus(status),note:opts.note});if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Action ${updated.id} is now ${updated.status}`)})}var auth_exports={};__export(auth_exports,{browserLogin:()=>browserLogin,deviceLogin:()=>deviceLogin,logout:()=>logout,parseLoopbackCallback:()=>parseLoopbackCallback,readStdin:()=>readStdin,register:()=>register2,useOnlyOrg:()=>useOnlyOrg});import{spawn}from"child_process";import{createHash,randomBytes,randomUUID}from"crypto";import{createServer}from"http";import{hostname}from"os";import{createInterface}from"readline";import{setTimeout as sleep}from"timers/promises";import{z}from"zod";var deviceAuthorizeRequestSchema=z.object({deviceName:z.string().trim().max(64).optional(),email:z.string().trim().email().max(320).optional()});var deviceAuthorizeResponseSchema=z.object({deviceCode:z.string(),userCode:z.string(),verificationUri:z.string(),verificationUriComplete:z.string(),interval:z.number().int().positive(),expiresIn:z.number().int().positive(),emailSent:z.boolean()});var deviceTokenRequestSchema=z.object({deviceCode:z.string().min(1)});var deviceTokenApprovedSchema=z.object({status:z.literal("approved"),accessToken:z.string(),tokenType:z.literal("bearer"),expiresAt:z.string().nullable()});var deviceTokenResultSchema=z.discriminatedUnion("status",[z.object({status:z.literal("pending")}),z.object({status:z.literal("slow_down"),interval:z.number().int()}),z.object({status:z.literal("denied")}),z.object({status:z.literal("expired")}),deviceTokenApprovedSchema]);async function credentialIdentity(){if(credentialKind()==="legacy"){const{user}=await createClient().get("/api/v1/me");return{user,apiKey:null,token:{kind:"legacy",scopes:null,expiresAt:null}}}return createChatApiClient().me()}async function principalIdentity(){const{user,apiKey,token}=await credentialIdentity();const orgs=token.kind==="legacy"?null:apiKey?.organization?[apiKey.organization]:await fetchDirectory();return{user,apiKey,orgs}}function printPrincipal(identity){const{user,apiKey,orgs}=identity;if(apiKey)console.log(`Org API key "${apiKey.name}" (${apiKey.prefix}\u2026)`);else if(user)console.log(`Signed in as ${user.email||user.id}${user.name?` (${user.name})`:""}`);if(orgs)console.log(`Organizations: ${orgs.map(org=>`${org.name} (${org.slug})`).join(", ")||"(none)"}`);else if(orgs===null)console.log("Use `gauge auth login` to list your Gauge organizations.")}async function fetchAllPages(client,path,query={}){const items=[];let cursor;do{const page=await client.get(path,{limit:200,...query,cursor});items.push(...page.items);cursor=page.nextCursor}while(cursor);return items}var LOGIN_TIMEOUT_MS=2*60*1e3;function tokenSource(){if(process.env.GAUGE_API_TOKEN?.trim())return"env";return resolveToken()?"file":"none"}async function fetchMe(client,shared=false){return shared?client.get("/api/cli/me"):client.get("/api/v1/me")}function sessionCredentials(raw){return{version:1,sessionId:randomUUID(),...sharedTokenSchema.parse(raw),authUrl:resolveAuthUrl(),apiUrl:resolveBaseUrl()}}async function verifyIssuedToken(token){const shared=token.startsWith("gauge_cli_");return fetchMe(new ApiClient({token,baseUrl:shared?resolveAuthUrl():resolveBaseUrl()}),shared)}function parseLoopbackCallback(rawUrl,expectedState){const url=new URL(rawUrl??"/","http://127.0.0.1");if(url.pathname!=="/callback")return null;if(url.searchParams.get("state")===expectedState&&url.searchParams.get("error")==="access_denied"){throw new CliError("unauthorized","Authorization was denied in the browser.")}const code=url.searchParams.get("code");if(url.searchParams.get("state")!==expectedState||!code)return null;return code}function printIdentity(me){const orgs=me.orgs.map(o=>o.slug).join(", ")||"(none)";console.log(`Logged in as ${me.user.email??me.user.id}`);console.log(`Orgs: ${orgs}`);console.log(`API URL: ${resolveBaseUrl()}`)}function useOnlyOrg(me,shared=false,log=console.log){const org=me.orgs.length===1?me.orgs[0]:void 0;const only=!org?void 0:shared&&"id"in org?org.id:"canonicalGaugeOrganizationId"in org?org.canonicalGaugeOrganizationId:void 0;if(!only||readConfig().orgId)return;updateConfig({orgId:only,defaultOrg:void 0});log(`Default organization set to ${org?.name??only}.`)}function openBrowser(url){const[cmd,args]=process.platform==="darwin"?["open",[url]]:process.platform==="win32"?["cmd",["/c","start","",url]]:["xdg-open",[url]];try{const child=spawn(cmd,args,{stdio:"ignore",detached:true});child.on("error",()=>{});child.unref()}catch{}}async function browserLogin(){const state=randomBytes(16).toString("base64url");const codeVerifier=randomBytes(32).toString("base64url");const codeChallenge=createHash("sha256").update(codeVerifier).digest("base64url");const server=createServer();const codePromise=new Promise((resolve5,reject)=>{server.on("request",(req,res)=>{const url=new URL(req.url??"/","http://127.0.0.1");if(url.pathname!=="/callback"){res.writeHead(404).end();return}if(req.method!=="GET"){res.writeHead(405,{allow:"GET"}).end();return}let code;try{code=parseLoopbackCallback(req.url,state)}catch(error){res.writeHead(200,{"content-type":"text/plain"}).end("Authorization denied. Return to your terminal.");reject(error);return}if(!code){res.writeHead(400,{"content-type":"text/plain; charset=utf-8"});res.end("Could not complete sign-in. Run gauge auth login again.");return}res.writeHead(200,{"content-type":"text/plain; charset=utf-8"});res.end("Authorized. Return to your terminal.");resolve5(code)});server.on("error",e=>reject(new CliError("network",`Could not receive browser sign-in on this computer: ${e.message}`,{hint:"Try `gauge auth login --device` to sign in using a browser on another device."})))});await new Promise(resolve5=>{server.listen(0,"127.0.0.1",resolve5)});const address=server.address();if(!address||typeof address==="string"){server.close();throw new CliError("internal","Could not start browser sign-in on this computer.",{hint:"Try `gauge auth login --device` instead."})}const base=resolveAuthUrl();const authorizeUrl=new URL(`${base}/cli/authorize`);authorizeUrl.searchParams.set("port",String(address.port));authorizeUrl.searchParams.set("state",state);authorizeUrl.searchParams.set("name",hostname()||"this device");authorizeUrl.searchParams.set("code_challenge",codeChallenge);authorizeUrl.searchParams.set("code_challenge_method","S256");console.log("Opening your browser to authorize the Gauge CLI\u2026");console.log(`If it doesn't open, visit:
|
|
3
3
|
|
|
4
4
|
${authorizeUrl}
|
|
5
|
-
`);console.log("Waiting for browser authorization\u2026");console.log("No local network access or using SSH? Re-run with gauge auth login --device.");openBrowser(authorizeUrl.toString());let timer;try{const code=await Promise.race([codePromise,new Promise((_,reject)=>{timer=setTimeout(()=>{reject(new CliError("network","Timed out waiting for browser authorization (2 minutes). Retry, or use gauge auth login --device. New to Gauge? Sign-up needs a work email."))},LOGIN_TIMEOUT_MS)})]);const raw=await bootstrapPost("/api/
|
|
5
|
+
`);console.log("Waiting for browser authorization\u2026");console.log("No local network access or using SSH? Re-run with gauge auth login --device.");openBrowser(authorizeUrl.toString());let timer;try{const code=await Promise.race([codePromise,new Promise((_,reject)=>{timer=setTimeout(()=>{reject(new CliError("network","Timed out waiting for browser authorization (2 minutes). Retry, or use gauge auth login --device. New to Gauge? Sign-up needs a work email."))},LOGIN_TIMEOUT_MS)})]);const raw=await bootstrapPost("/api/cli/token",{code,codeVerifier});const parsed=sharedTokenSchema.safeParse(raw);if(!parsed.success){throw new CliError("internal","Gauge returned a sign-in response the CLI could not read. Try `gauge auth login` again.")}const exchange=parsed.data;const token=exchange.accessToken;const me=await verifyIssuedToken(token);await withCredentialLock(async()=>{saveCredentials(sessionCredentials(raw))});console.log(`Token saved to ${credentialsPath()}`);printIdentity(me);useOnlyOrg(me,token.startsWith("gauge_cli_"))}finally{if(timer)clearTimeout(timer);server.close();server.closeAllConnections()}}async function bootstrapPost(path,body){const base=resolveAuthUrl();let res;try{res=await fetch(`${base}${path}`,{method:"POST",redirect:"error",signal:AbortSignal.timeout(15e3),headers:{"Content-Type":"application/json",Accept:"application/json","User-Agent":USER_AGENT},body:JSON.stringify(body)})}catch(e){throw new CliError("network",`Request to ${base} failed: ${e instanceof Error?e.message:String(e)}`)}const text=await res.text();if(!res.ok){try{const parsed=errorEnvelopeSchema.safeParse(JSON.parse(text));if(parsed.success){throw new CliError(parsed.data.error.code,parsed.data.error.message)}}catch(e){if(e instanceof CliError)throw e}throw new CliError("internal",`Authentication request failed: HTTP ${res.status} ${res.statusText}`.trim())}return JSON.parse(text)}async function deviceLogin(opts){const start=await bootstrapPost("/api/cli/device/authorize",{deviceName:hostname()||"this device",email:opts.email});console.log("To sign in, open this URL in a browser:\n");console.log(` ${start.verificationUriComplete}
|
|
6
6
|
`);console.log(`and confirm this code: ${start.userCode}
|
|
7
|
-
`);if(start.emailSent&&opts.email){console.log(`We also emailed a sign-in link to ${opts.email}.`)}console.log("Waiting for you to approve in the browser\u2026");openBrowser(start.verificationUriComplete);const deadline=Date.now()+start.expiresIn*1e3;const MAX_TRANSIENT=5;let interval=start.interval;let transient=0;while(Date.now()<deadline){await sleep(interval*1e3);let raw;try{raw=await bootstrapPost(
|
|
7
|
+
`);if(start.emailSent&&opts.email){console.log(`We also emailed a sign-in link to ${opts.email}.`)}console.log("Waiting for you to approve in the browser\u2026");openBrowser(start.verificationUriComplete);const deadline=Date.now()+start.expiresIn*1e3;const MAX_TRANSIENT=5;let interval=start.interval;let transient=0;while(Date.now()<deadline){await sleep(interval*1e3);let raw;try{raw=await bootstrapPost("/api/cli/device/token",{deviceCode:start.deviceCode})}catch(e){if(e instanceof CliError&&(e.code==="network"||e.code==="internal")&&++transient<=MAX_TRANSIENT){continue}throw e}transient=0;const parsed=deviceTokenResultSchema.safeParse(raw);if(!parsed.success){throw new CliError("internal","Gauge returned a sign-in response the CLI could not read. Try `gauge auth login --device` again.")}const result=parsed.data;switch(result.status){case"pending":continue;case"slow_down":interval=result.interval;continue;case"denied":throw new CliError("unauthorized","Authorization was denied in the browser.");case"expired":throw new CliError("unauthorized","The sign-in request expired before it was approved. Re-run it to try again.");case"approved":{const token=result.accessToken;try{const credentials=sessionCredentials(raw);const me=await verifyIssuedToken(token);return{token,me,credentials}}catch(e){throw new CliError("network",`You approved sign-in, but the CLI could not confirm access to your account (${e instanceof Error?e.message:String(e)}). Run \`gauge auth login --device\` again. Your saved login has not changed.`)}}default:throw new CliError("internal","Gauge could not complete sign-in. Try `gauge auth login --device` again.")}}throw new CliError("network","Timed out waiting for browser approval. Re-run to try again. New to Gauge? Sign-up needs a work email.")}async function readStdin(input=process.stdin){if(input.isTTY){const lines=createInterface({input,crlfDelay:Infinity});for await(const line of lines){lines.close();return line}return""}let data="";for await(const chunk of input)data+=chunk;return data}async function withTokenLogin(){if(process.stdin.isTTY){console.error("Paste your API token, then press Enter:")}const token=(await readStdin()).trim();if(!token)throw new CliError("usage","Expected a token on stdin");if(credentialKind(token)==="api_key"){const me2=await new ChatApiClient({token,baseUrl:resolveAuthUrl()}).me();await withCredentialLock(async()=>{saveToken(token)});console.log(`Token saved to ${credentialsPath()}`);printPrincipal({...me2,orgs:me2.apiKey?.organization?[me2.apiKey.organization]:void 0});return}const me=await verifyIssuedToken(token);await withCredentialLock(async()=>{if(token.startsWith("gauge_cli_"))saveCredentials({version:1,sessionId:randomUUID(),accessToken:token,authUrl:resolveAuthUrl(),apiUrl:resolveBaseUrl()});else saveToken(token)});console.log(`Token saved to ${credentialsPath()}`);printIdentity(me);useOnlyOrg(me,token.startsWith("gauge_cli_"))}var TOKENS_PATH="/api/v1/tokens";async function fetchAllTokens(client){return fetchAllPages(client,TOKENS_PATH)}function tokenStatus(t){if(t.revokedAt)return"revoked";if(t.expiresAt&&Date.parse(t.expiresAt)<=Date.now())return"expired";return"active"}function tokenRow(t){return{id:t.id,name:t.name,token:`\u2026${t.last4}`,status:tokenStatus(t),created:t.createdAt.slice(0,10),lastUsed:t.lastUsedAt?t.lastUsedAt.slice(0,10):"never",expires:t.expiresAt?t.expiresAt.slice(0,10):"never"}}function parseExpiresIn(raw){if(raw==="never")return void 0;const match=raw.match(/^(\d+)([dh])$/);if(!match){throw new CliError("usage",`Invalid --expires-in "${raw}" (expected e.g. 90d, 12h, or never)`)}const n=Number(match[1]);const ms=match[2]==="d"?n*24*60*60*1e3:n*60*60*1e3;if(ms<=0){throw new CliError("usage","--expires-in must be a positive duration")}return new Date(Date.now()+ms).toISOString()}async function whoami(output){const identity=await principalIdentity();if(output==="json")return printJson(identity);printPrincipal(identity)}async function logout(){await withCredentialLock(async()=>{const stored=readCredentials();try{if(stored&&typeof stored!=="string"&&stored.refreshToken){const response=await fetch(`${stored.authUrl}/api/cli/revoke`,{method:"POST",redirect:"error",signal:AbortSignal.timeout(15e3),headers:{"Content-Type":"application/json"},body:JSON.stringify({refreshToken:stored.refreshToken})});if(!response.ok)throw new Error(`HTTP ${response.status}`)}}catch(error){console.error(`Warning: your saved login was removed from this computer, but Gauge could not end it on the server (${error instanceof Error?error.message:String(error)}). That login may still allow access. Contact Gauge support if you need to confirm it has been ended.`)}finally{clearToken()}})}function register2(program2){const auth=hostedOnly(program2.command("auth"),{account:true}).description("Authenticate the CLI");auth.command("login").description("Sign in to Gauge using your browser").option("--with-token","read a token from stdin (headless machines)").option("--device","use a device code instead (no local network access required)").option("--email <email>","with --device: also email a sign-in link to this address").action(async opts=>{if(opts.withToken&&opts.device){throw new CliError("usage","Choose only one of --with-token or --device.")}if(opts.email&&!opts.device){throw new CliError("usage","--email requires --device.")}if(opts.device){const{token,me,credentials}=await deviceLogin({email:opts.email});await withCredentialLock(async()=>{saveCredentials(credentials)});console.log(`Token saved to ${credentialsPath()}`);printIdentity(me);useOnlyOrg(me,token.startsWith("gauge_cli_"))}else if(opts.withToken){await withTokenLogin()}else{await browserLogin()}});auth.command("logout").description("Sign out of this CLI installation").action(async()=>{await logout();console.log(`Removed ${credentialsPath()}`);if(process.env.GAUGE_API_TOKEN?.trim()){console.error("warning: GAUGE_API_TOKEN is still set. Commands will continue using it; unset it to fully sign out.")}});auth.command("status").description("Check your login or API key, permissions, and expiration").action(async(_opts,command)=>{const output=resolveOutput(command);const source=tokenSource();if(source==="none"){throw new CliError("unauthorized","Not logged in. Run `gauge auth login` or set GAUGE_API_TOKEN.")}let me;try{me=await credentialIdentity()}catch(e){if(e instanceof CliError&&e.code==="unauthorized"){throw new CliError("unauthorized",source==="env"?"The API key or token in GAUGE_API_TOKEN was rejected. It may have expired or been revoked.":"Your saved login or API key was rejected. It may have expired or been revoked.",{hint:source==="env"?"Replace GAUGE_API_TOKEN with a valid key, or unset it and run `gauge auth login`.":"Run `gauge auth login` to sign in again, or import a replacement API key with `gauge auth login --with-token`."})}throw e}if(output==="json"){printJson({authenticated:true,source,apiUrl:resolveBaseUrl(),authUrl:storedSharedCredentials()?.authUrl??resolveAuthUrl(),credential:me.token});return}const label=me.token.kind==="session"?"Login":me.token.kind==="api_key"?"API key":"Agents token";console.log(`${label}: valid`);console.log(`Permissions: ${me.token.scopes?describeScopes(me.token.scopes):"not available for this token"}`);console.log(`Expires: ${me.token.expiresAt??(me.token.kind==="legacy"?"not available for this token":"never")}`);console.log(`Auth URL: ${storedSharedCredentials()?.authUrl??resolveAuthUrl()}`);console.log(`Agents API URL: ${resolveBaseUrl()}`);console.log(`Using: ${source==="env"?"GAUGE_API_TOKEN environment variable":credentialsPath()}`)});const tokens=auth.command("tokens").description("Manage tokens created by older versions of Gauge Agents");tokens.command("list").description("List your API tokens").action(async(_opts,command)=>{const output=resolveOutput(command);const items=await fetchAllTokens(createClient());if(output==="json"){printJson(items);return}printItems(items.map(tokenRow),"table")});tokens.command("create <name>").description("Create an API token (the secret is shown exactly once)").option("--expires-in <duration>","e.g. 90d, 12h, or never","never").action(async(name,opts,command)=>{const output=resolveOutput(command);if(resolveToken()?.startsWith("gauge_cli_"))throw new CliError("forbidden","You can't create this older type of Agents token with your current login.",{hint:"For scripts and CI, create an organization API key in Settings \u2192 API Keys and set GAUGE_API_TOKEN."});const expiresAt=parseExpiresIn(opts.expiresIn);const created=await createClient().post(TOKENS_PATH,{name,...expiresAt?{expiresAt}:{}});if(output==="json"){printJson(created);return}console.log(`Created token "${created.name}" (id ${created.id}, expires ${created.expiresAt??"never"})`);console.log(`
|
|
8
8
|
${created.token}
|
|
9
|
-
`);console.log("Store it now \u2014 it won't be shown again.")});tokens.command("revoke <id>").description("Revoke an API token").action(async(id,_opts,command)=>{await createClient().delete(`${TOKENS_PATH}/${encodeURIComponent(id)}`);if(resolveOutput(command)!=="json")console.log(`Revoked ${id}`)});program2.command("whoami").description("Show the authenticated user and their orgs").action(async(_opts,command)=>{await whoami(resolveOutput(command))})}var billing_exports={};__export(billing_exports,{fmtOverage:()=>fmtOverage,register:()=>register3});function fmtDate(iso){return iso?iso.slice(0,10):"\u2014"}function fmtOverage(s){const line=s.creditLine;if(!line)return s.paymentType==="card"?"n/a (card)":"\u2014";if(line.limitUsd<=0)return"off (credit line limit $0)";return`$${line.usedUsd.toFixed(2)} of $${line.limitUsd.toFixed(2)} credit line`}function statusLines(s){return[["Plan",s.plan??"free"],["Subscription",s.subscriptionStatus??"\u2014"],["Payment",s.paymentType??"\u2014"],["Balance",`${s.balance} credits`],["Allowance / cycle",s.allowance===null?"\u2014":`${s.allowance} credits`],["Period",s.currentPeriodStart||s.currentPeriodEnd?`${fmtDate(s.currentPeriodStart)} \u2192 ${fmtDate(s.currentPeriodEnd)}`:"\u2014"],["Used this period",`${s.creditsUsedThisPeriod} credits`],["Runs this period",String(s.runsThisPeriod)],["Overage",fmtOverage(s)],["Can run eval",s.canRunByWorkload.eval?"yes":"no"],["Can run preference",s.canRunByWorkload.visibility?"yes":"no"],["Can run generic",s.canRunByWorkload.generic?"yes":"no"],["Billing enforced",s.enforced?"yes":"no"]]}function register3(program2){const group=hostedOnly(program2.command("billing")).description("Billing & credits");group.command("status").description("Show credit balance, plan, payment, and overage").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const status=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/billing`);if(resolveOutput(cmd)==="json"){printJson(status);return}const lines=statusLines(status);const width=Math.max(...lines.map(([label])=>label.length));for(const[label,value]of lines){console.log(`${label.padEnd(width)} ${value}`)}})}var brands_exports2={};__export(brands_exports2,{register:()=>register4});import{Option}from"commander";var KINDS=brands_exports.BRAND_KINDS.map(k=>k.toLowerCase());var ECOSYSTEMS=brands_exports.BRAND_PACKAGE_ECOSYSTEMS;function brandsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/brands`}function collect(value,previous){return previous?[...previous,value]:[value]}function splitList(raw){return raw.split(",").map(v=>v.trim()).filter(Boolean)}function parsePackage(raw){const sep4=raw.lastIndexOf(":");if(sep4===-1)return{name:raw.trim(),ecosystem:null};const name=raw.slice(0,sep4).trim();const ecosystem=raw.slice(sep4+1).trim();if(!name)throw new CliError("usage",`Invalid package "${raw}"`);if(!ECOSYSTEMS.includes(ecosystem)){throw new CliError("usage",`Invalid ecosystem "${ecosystem}" (expected ${ECOSYSTEMS.join("|")})`)}return{name,ecosystem}}function toRow(brand){return{id:brand.id,name:brand.name,kind:brand.kind.toLowerCase(),aliases:brand.aliases.join(", "),websites:brand.websites.join(", "),packages:brand.packages.map(p=>p.name).join(", ")}}function register4(program2){const group=hostedOnly(program2.command("brands")).description("Manage org brands");group.command("list").description("List brands").addOption(new Option("--kind <kind>","filter by kind").choices(KINDS)).action(async(opts,cmd)=>{const org=resolveOrg(cmd);const items=await fetchAllPages(createClient(),brandsPath(org),{kind:opts.kind?.toUpperCase()});if(resolveOutput(cmd)==="json"){printJson(items);return}printItems(items.map(toRow),"table")});group.command("add <name>").description("Add a brand").addOption(new Option("--kind <kind>","brand kind").choices(KINDS).makeOptionMandatory()).option("--aliases <list>","comma-separated alias spellings").option("--websites <list>","comma-separated docs/marketing URLs").option("--package <name[:ecosystem]>","package identifier, repeatable (ecosystem: npm|pypi|cargo|go|rubygems|other)",collect).action(async(name,opts,cmd)=>{const org=resolveOrg(cmd);const row2=await createClient().post(brandsPath(org),{name,kind:opts.kind.toUpperCase(),aliases:opts.aliases===void 0?[]:splitList(opts.aliases),websites:opts.websites===void 0?[]:splitList(opts.websites),packages:(opts.package??[]).map(parsePackage)});if(resolveOutput(cmd)==="json")printJson(row2);else console.log(`Created brand ${row2.id} (${row2.name})`)});group.command("edit <id>").description("Update a brand (only the provided fields change)").option("--name <name>","new canonical name").addOption(new Option("--kind <kind>","new kind").choices(KINDS)).option("--aliases <list>","replace aliases (comma-separated; pass '' to clear)").option("--websites <list>","replace websites (comma-separated; pass '' to clear)").option("--package <name[:ecosystem]>","replace packages, repeatable",collect).option("--clear-packages","remove all packages").action(async(id,opts,cmd)=>{const patch={};if(opts.name!==void 0)patch.name=opts.name;if(opts.kind!==void 0)patch.kind=opts.kind.toUpperCase();if(opts.aliases!==void 0)patch.aliases=splitList(opts.aliases);if(opts.websites!==void 0)patch.websites=splitList(opts.websites);if(opts.clearPackages)patch.packages=[];else if(opts.package!==void 0)patch.packages=opts.package.map(parsePackage);if(Object.keys(patch).length===0){throw new CliError("usage","Nothing to update \u2014 pass at least one of --name/--kind/--aliases/--websites/--package/--clear-packages.")}const org=resolveOrg(cmd);const row2=await createClient().patch(`${brandsPath(org)}/${encodeURIComponent(id)}`,patch);if(resolveOutput(cmd)==="json")printJson(row2);else console.log(`Updated brand ${row2.id} (${row2.name})`)});group.command("rm <id>").description("Delete a brand").action(async(id,_opts,cmd)=>{const org=resolveOrg(cmd);await createClient().delete(`${brandsPath(org)}/${encodeURIComponent(id)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted brand ${id}`)})}var cleanup_exports={};__export(cleanup_exports,{register:()=>register5});import{join as join2}from"path";function register5(program2){program2.command("cleanup").description("Clean interrupted Gauge sessions in this repository (local only); preserve results and images").action(async(_opts,command)=>{const state=gaugeState(command);if(state.mode!=="local"||!state.root)throw new CliError("usage","Use --local inside the batch's Git repository");const results=await cleanupLocal(join2(state.root,".gauge"));if(results.some(r=>r.status==="error"))process.exitCode=1;if(resolveOutput(command)==="json")printJson({sessions:results});else{if(!results.length)console.log("No interrupted sessions need cleanup.");for(const result of results)console.log(`${result.id}: ${result.status}${result.detail?` (${result.detail})`:""}`)}})}var config_exports={};__export(config_exports,{register:()=>register6});function assertKey(key){if(CONFIG_KEYS.includes(key)){return key}throw new CliError("usage",`Unknown config key '${key}'. Valid keys: ${CONFIG_KEYS.join(", ")}`)}function register6(program2){const config=program2.command("config").description("Local client config (~/.config/gauge/config.json)");config.command("get [key]").description("Print the whole config, or a single key's value").action(key=>{const current=readConfig();if(key===void 0){printJson(current);return}console.log(current[assertKey(key)]??"")});config.command("set <key> <value>").description(`Set a config key (${CONFIG_KEYS.join(", ")})`).action((key,value)=>{const configKey=assertKey(key);if(configKey==="backend"&&value!=="local"&&value!=="hosted")throw new CliError("usage","backend must be local or hosted");updateConfig({[configKey]:value});console.log(`${configKey} = ${value} (${configPath()})`)});config.command("unset <key>").description("Remove a config key").action(key=>{const configKey=assertKey(key);updateConfig({[configKey]:void 0});console.log(`${configKey} unset (${configPath()})`)})}var connections_exports={};__export(connections_exports,{register:()=>register7});function connectionsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/connections`}function register7(program2){const group=hostedOnly(program2.command("connections")).description("Inspect the org's stored credentials (no secrets)");group.command("list").description("List credentials with the ids --connection accepts").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(connectionsPath(org));if(resolveOutput(cmd)==="json"){printJson(res.items);return}printItems(res.items.map(c=>({id:c.id,name:c.handle,vendor:c.profileLabel,placeholder:[c.credentialKey,c.basicPasswordKey].filter(Boolean).join(", "),domains:c.allowedHosts.join(", "),kind:c.kind,value:c.last4?`\xB7\xB7\xB7\xB7${c.last4}`:""})),"table")})}var dashboards_exports={};__export(dashboards_exports,{register:()=>register8});import{readFileSync as readFileSync2}from"fs";function dashboardsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/dashboards`}function register8(program2){const group=hostedOnly(program2.command("dashboards")).description("Saved dashboards (CRUD + view filters; layout is UI-only)");group.command("list").description("List your dashboard library").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(dashboardsPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(d=>({key:d.key,name:d.name,source:d.source,default:d.isUserDefault?"you":d.isOrgDefault?"org":""})),"table")});group.command("get <key>").description("Show one resolved dashboard (widgets + saved filters)").action(async(key,_opts,cmd)=>{const org=resolveOrg(cmd);const dashboard=await createClient().get(`${dashboardsPath(org)}/${encodeURIComponent(key)}`);if(resolveOutput(cmd)==="json"){printJson(dashboard);return}console.log(`key: ${dashboard.key}`);console.log(`name: ${dashboard.name}`);console.log(`filters: ${JSON.stringify(dashboard.defaultFilters)}`);console.log("widgets:");for(const w of dashboard.widgets)console.log(` [${w.id}] ${w.title} (${w.viz})`)});group.command("create <name>").description("Create an empty personal dashboard").action(async(name,_opts,cmd)=>{const org=resolveOrg(cmd);const created=await createClient().post(dashboardsPath(org),{name});if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created dashboard ${created.key}`)});group.command("rename <key> <name>").description("Rename a dashboard (in your overlay)").action(async(key,name,_opts,cmd)=>{const org=resolveOrg(cmd);const updated=await createClient().patch(`${dashboardsPath(org)}/${encodeURIComponent(key)}`,{name});if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Renamed to ${updated.name}`)});group.command("rm <key>").description("Delete a dashboard (built-in templates refuse)").action(async(key,_opts,cmd)=>{const org=resolveOrg(cmd);await createClient().delete(`${dashboardsPath(org)}/${encodeURIComponent(key)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted dashboard ${key}`)});group.command("filters <key>").description("Replace a dashboard's saved view-level filters").option("--json <json>","the filters object inline").option("--file <path>",'the filters object from a file ("-" for stdin)').option("--clear","remove all saved filters").action(async(key,opts,cmd)=>{const org=resolveOrg(cmd);const provided=[opts.json,opts.file,opts.clear].filter(v=>v!==void 0&&v!==false).length;if(provided!==1)throw new CliError("usage","pass exactly one of --json, --file, or --clear");let filters={};if(!opts.clear){const raw=opts.json??readFileSync2(opts.file==="-"?0:opts.file,"utf8");try{filters=JSON.parse(raw)}catch(e){throw new CliError("usage",`filters are not valid JSON: ${e instanceof Error?e.message:e}`)}}const updated=await createClient().put(`${dashboardsPath(org)}/${encodeURIComponent(key)}/filters`,filters);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Saved filters: ${JSON.stringify(updated.defaultFilters)}`)})}var eval_exports={};__export(eval_exports,{register:()=>register9});import{randomUUID as randomUUID2}from"crypto";import{join as join4}from"path";import{z as z4}from"zod";import{z as z3}from"zod";var sampleCountSchema=z3.number().int().min(1).max(50);var nextRunAtInputSchema=z3.string().regex(/^\d{4}-\d{2}-\d{2}/,"Next run must be a calendar date").nullable();var ownedCadenceSchema=z3.enum(["NONE","DAILY","WEEKLY","MONTHLY"]);var ownedConfigurationInputShape={repoUrl:z3.string().nullish(),repoRef:z3.string().nullish(),profileId:z3.string().nullish(),agents:z3.array(agentConfigInputSchema).min(1,"Select at least one agent"),skillRefs:assetRefListSchema.optional().default([]),mcpRefs:assetRefListSchema.optional().default([]),connectionIds:z3.array(z3.string().min(1)).max(32).optional().default([]),cadence:ownedCadenceSchema.optional().default("NONE"),nextRunAt:nextRunAtInputSchema.optional(),sampleCount:sampleCountSchema.optional().default(1)};var ownedConfigurationInputSchema=z3.object(ownedConfigurationInputShape).strict();var ownedConfigurationPatchShape={repoUrl:z3.string().nullish(),repoRef:z3.string().nullish(),profileId:z3.string().nullish(),agents:z3.array(agentConfigInputSchema).min(1,"Select at least one agent").optional(),skillRefs:assetRefListSchema.optional(),mcpRefs:assetRefListSchema.optional(),connectionIds:z3.array(z3.string().min(1)).max(32).optional(),cadence:ownedCadenceSchema.optional(),nextRunAt:nextRunAtInputSchema.optional(),sampleCount:sampleCountSchema.optional()};var ownedConfigurationSchema=z3.object({repoUrl:z3.string().nullable(),repoRef:z3.string().nullable(),profile:z3.object({id:z3.string(),name:z3.string()}).nullable(),agents:z3.array(agentConfigSchema),skillRefs:z3.array(z3.string()),mcpRefs:z3.array(z3.string()),connectionIds:z3.array(z3.string()),cadence:ownedCadenceSchema,sampleCount:sampleCountSchema,lastScheduledAt:z3.string().nullable(),nextRunAt:z3.string().nullable()});var visibilityScenarioSchema=z3.object({id:z3.string(),repoUrl:z3.string().nullable(),repoRef:z3.string().nullable(),profile:z3.object({id:z3.string(),name:z3.string()}).nullable()});var visibilityScenarioInputSchema=z3.object({repoUrl:z3.string().nullish(),repoRef:z3.string().nullish(),profileId:z3.string().nullish()}).strict();var visibilityPromptSettingsInputShape={agents:ownedConfigurationInputShape.agents,skillRefs:ownedConfigurationInputShape.skillRefs,mcpRefs:ownedConfigurationInputShape.mcpRefs,connectionIds:ownedConfigurationInputShape.connectionIds,cadence:ownedConfigurationInputShape.cadence,nextRunAt:ownedConfigurationInputShape.nextRunAt,sampleCount:ownedConfigurationInputShape.sampleCount};var visibilityPromptSettingsPatchShape={agents:ownedConfigurationPatchShape.agents,skillRefs:ownedConfigurationPatchShape.skillRefs,mcpRefs:ownedConfigurationPatchShape.mcpRefs,connectionIds:ownedConfigurationPatchShape.connectionIds,cadence:ownedConfigurationPatchShape.cadence,nextRunAt:ownedConfigurationPatchShape.nextRunAt,sampleCount:ownedConfigurationPatchShape.sampleCount};var visibilityPromptSettingsSchema=z3.object({agents:z3.array(agentConfigSchema),skillRefs:z3.array(z3.string()),mcpRefs:z3.array(z3.string()),connectionIds:z3.array(z3.string()),cadence:ownedCadenceSchema,sampleCount:sampleCountSchema,lastScheduledAt:z3.string().nullable(),nextRunAt:z3.string().nullable()});var runAgentsOverrideSchema=z3.array(agentConfigInputSchema).min(1,"Select at least one agent");var runSampleCountOverrideSchema=sampleCountSchema;var runEvalBodySchema=z3.object({agents:runAgentsOverrideSchema.optional(),sampleCount:runSampleCountOverrideSchema.optional()}).strict();var runVisibilityBodySchema=z3.object({agents:runAgentsOverrideSchema.optional(),sampleCount:runSampleCountOverrideSchema.optional(),visibilityScenarioIds:z3.array(z3.string().min(1)).min(1).optional()}).strict();var criterionSchema=z4.object({id:z4.string(),name:z4.string(),rubric:z4.string(),position:z4.number().int()});var criterionInputSchema=z4.object({id:z4.string().optional(),name:z4.string().min(1).optional(),rubric:z4.string().min(1)});var evalSetSchema=z4.object({id:z4.string(),suiteId:z4.string().nullable(),name:z4.string(),promptText:z4.string(),createdAt:z4.string(),criteria:z4.array(criterionSchema),tags:z4.array(z4.string())}).extend(ownedConfigurationSchema.shape);var agentPassRateSchema=z4.object({agent:agentSchema,model:z4.string(),runId:z4.string(),finishedAt:z4.string().nullable(),passed:z4.number().int(),total:z4.number().int()});var evalSetStatSchema=z4.object({passRates:z4.array(agentPassRateSchema),runCount:z4.number().int(),judgedRuns:z4.number().int(),passedRuns:z4.number().int()});var csv=z4.string().transform(s=>s.split(",").map(x=>x.trim()).filter(Boolean));var listEvalSetsQuerySchema=z4.object({agents:csv.pipe(z4.array(agentSchema)).optional(),models:csv.optional(),since:z4.coerce.date().optional()});var evalSetListItemSchema=evalSetSchema.extend({stats:evalSetStatSchema});var listEvalSetsResponseSchema=z4.object({items:z4.array(evalSetListItemSchema)});var createEvalSetBodySchema=z4.object({name:z4.string().min(1),promptText:z4.string().min(1),criteria:z4.array(criterionInputSchema).min(1),tags:z4.array(z4.string()).optional()}).extend(ownedConfigurationInputSchema.shape).strict();var updateEvalSetBodySchema=z4.object({name:z4.string().min(1).optional(),promptText:z4.string().min(1).optional(),criteria:z4.array(criterionInputSchema).min(1).optional(),tags:z4.array(z4.string()).optional()}).extend(ownedConfigurationPatchShape).strict();var runEvalSetResponseSchema=z4.object({batchIds:z4.array(z4.string()),runIds:z4.array(z4.string()),runRequestId:z4.string().optional()});var evalSetRunSchema=z4.object({id:z4.string(),status:z4.string(),agent:agentSchema,model:z4.string().nullable(),resolvedModel:z4.string().nullable(),createdAt:z4.string(),startedAt:z4.string().nullable(),finishedAt:z4.string().nullable(),failureReason:z4.string().nullable(),creditsCharged:runCreditsChargedSchema.optional(),triggeredBy:runTriggeredBySchema.optional(),evalRevision:z4.string().optional(),judge:z4.object({status:z4.string(),error:z4.string().nullable()}).nullable(),criterionResults:z4.array(z4.object({criterionId:z4.string().nullable(),name:z4.string(),passed:z4.boolean().nullable(),reasoning:z4.string().nullable()}))});var listEvalSetRunsResponseSchema=listResponseSchema(evalSetRunSchema);import{z as z5}from"zod";var VISIBILITY_PROMPT_KINDS=["HEAD_TO_HEAD","RECOMMEND"];var visibilityPromptKindSchema=z5.enum(VISIBILITY_PROMPT_KINDS);var visibilityPromptSchema=visibilityPromptSettingsSchema.extend({id:z5.string(),name:z5.string(),kind:visibilityPromptKindSchema,promptText:z5.string(),branded:z5.boolean(),brandA:z5.string().nullable(),brandB:z5.string().nullable(),market:z5.object({id:z5.string(),slug:z5.string(),name:z5.string()}).nullable(),position:z5.number().int(),createdAt:z5.string(),tags:z5.array(z5.string()),runCount:z5.number().int(),lastRunAt:z5.string().nullable(),scenarios:z5.array(visibilityScenarioSchema)});var listVisibilityPromptsResponseSchema=z5.object({items:z5.array(visibilityPromptSchema)});var createVisibilityPromptBodySchema=z5.object({name:z5.string().min(1),promptText:z5.string().min(1),kind:visibilityPromptKindSchema,branded:z5.boolean().optional(),brandA:z5.string().nullish(),brandB:z5.string().nullish(),marketId:z5.string().nullish(),tags:z5.array(z5.string()).optional(),agents:visibilityPromptSettingsInputShape.agents.optional(),skillRefs:visibilityPromptSettingsInputShape.skillRefs,mcpRefs:visibilityPromptSettingsInputShape.mcpRefs,connectionIds:visibilityPromptSettingsInputShape.connectionIds,cadence:visibilityPromptSettingsInputShape.cadence,sampleCount:visibilityPromptSettingsInputShape.sampleCount,scenarios:z5.array(visibilityScenarioInputSchema).optional().default([])}).strict();var updateVisibilityPromptBodySchema=z5.object({name:z5.string().min(1).optional(),promptText:z5.string().min(1).optional(),branded:z5.boolean().optional(),brandA:z5.string().nullish(),brandB:z5.string().nullish(),marketId:z5.string().nullish(),tags:z5.array(z5.string()).optional(),...visibilityPromptSettingsPatchShape,scenarios:z5.array(visibilityScenarioInputSchema).optional()}).strict();var runVisibilityPromptResponseSchema=z5.object({batchIds:z5.array(z5.string()),runIds:z5.array(z5.string())});var visibilityPromptRunSchema=z5.object({id:z5.string(),status:z5.string(),agent:agentSchema,model:z5.string().nullable(),resolvedModel:z5.string().nullable(),createdAt:z5.string(),startedAt:z5.string().nullable(),finishedAt:z5.string().nullable(),failureReason:z5.string().nullable(),creditsCharged:runCreditsChargedSchema.optional(),triggeredBy:runTriggeredBySchema.optional(),verdict:z5.object({status:z5.string(),error:z5.string().nullable(),payload:z5.unknown().nullable()}).nullable()});var listVisibilityPromptRunsResponseSchema=listResponseSchema(visibilityPromptRunSchema);var orgMarketSchema=z5.object({marketId:z5.string(),slug:z5.string(),name:z5.string(),capability:z5.string(),source:z5.string()});var addableMarketSchema=orgMarketSchema.omit({source:true});var listMarketsResponseSchema=z5.object({tracked:z5.array(orgMarketSchema),addable:z5.array(addableMarketSchema)});var addMarketBodySchema=z5.object({marketId:z5.string().min(1)});import{readFileSync as readFileSync3}from"fs";function parseLimit(raw){const limit=Number(raw);if(!Number.isInteger(limit)||limit<1||limit>200){throw new CliError("usage","--limit must be an integer between 1 and 200")}return limit}function collect2(value,previous){return[...previous,value]}function once(flag){return(value,previous)=>{if(previous!==void 0)throw new CliError("usage",`${flag} takes one id; start one run per id`);return value}}var AGENT_ALIASES={"claude-code":"CLAUDE_CODE",claude_code:"CLAUDE_CODE",claude:"CLAUDE_CODE",codex:"CODEX_CLI","codex-cli":"CODEX_CLI",codex_cli:"CODEX_CLI",cursor:"CURSOR",pi:"PI",opencode:"OPENCODE","open-code":"OPENCODE",open_code:"OPENCODE",antigravity:"ANTIGRAVITY"};function parseAgents(raw){const out=[];for(const part of raw.split(",")){const name=part.trim();if(!name)continue;const agent=AGENT_ALIASES[name.toLowerCase()];if(!agent){throw new CliError("usage",`unknown agent "${name}" (expected: claude-code, codex, cursor, pi, opencode, antigravity)`)}out.push(agent)}if(out.length===0)throw new CliError("usage","no agents given");return[...new Set(out)]}function parseAgentSpec(raw){const colon=raw.indexOf(":");const name=(colon<0?raw:raw.slice(0,colon)).trim();const agent=AGENT_ALIASES[name.toLowerCase()];if(!agent){throw new CliError("usage",`unknown agent "${name}" in --agent "${raw}" (expected: claude-code, codex, pi, opencode, or antigravity, optionally ":model1,model2")`)}if(agent==="CURSOR"){throw new CliError("usage","cursor is not schedulable \u2014 presets may roster claude-code, codex, pi, opencode, and hosted antigravity")}const models=colon<0?[]:raw.slice(colon+1).split(",").map(m=>m.trim()).filter(Boolean);if(colon>=0&&models.length===0){throw new CliError("usage",`--agent "${raw}" has a ":" but no models \u2014 drop the colon for the agent default`)}return{agent,models:[...new Set(models)]}}function buildAgentRoster(specs){const byAgent=new Map;for(const raw of specs){const{agent,models}=parseAgentSpec(raw);const set=byAgent.get(agent)??new Set;for(const m of models)set.add(m);byAgent.set(agent,set)}return[...byAgent.entries()].map(([agent,models])=>({agent,models:[...models]}))}function validateAssetRefs(kind,refs){const parsed=runConfig_exports.assetRefListSchema.safeParse(refs);if(!parsed.success){const first=parsed.error.issues[0];throw new CliError("usage",`invalid --${kind} reference: ${first?.message??"expected name@label"}`)}return refs}function readPromptText(opts){if(opts.text===void 0===(opts.file===void 0)){throw new CliError("usage","pass exactly one of --text or --file")}if(opts.text!==void 0)return opts.text;const text=readFileSync3(opts.file==="-"?0:opts.file,"utf8").trim();if(!text)throw new CliError("usage","prompt file is empty");return text}function parseCadence(raw){const cadence=(raw??"NONE").trim().toUpperCase();if(!["NONE","DAILY","WEEKLY","MONTHLY"].includes(cadence))throw new CliError("usage",`invalid cadence "${raw}" (expected none, daily, weekly, or monthly)`);return cadence}function parseSampleCount(raw){const value=Number(raw??"1");if(!Number.isSafeInteger(value)||value<1||value>50)throw new CliError("usage","--samples must be an integer from 1 to 50");return value}function ownedConfigFromOpts(opts){if(opts.ref!==void 0&&opts.repo===void 0)throw new CliError("usage","--ref requires --repo");if(opts.agent.length===0)throw new CliError("usage","at least one --agent is required");return{repoUrl:opts.repo??null,repoRef:opts.ref??null,profileId:opts.persona??null,agents:buildAgentRoster(opts.agent),skillRefs:validateAssetRefs("skill",opts.skill),mcpRefs:validateAssetRefs("mcp",opts.mcp),connectionIds:opts.connection,cadence:parseCadence(opts.cadence),sampleCount:parseSampleCount(opts.samples)}}function ownedConfigPatchFromOpts(opts){const patch={};if((opts.repo!==void 0||opts.ref!==void 0)&&opts.clearRepo)throw new CliError("usage","--repo/--ref and --clear-repo conflict");if(opts.ref!==void 0&&opts.clearRef)throw new CliError("usage","--ref and --clear-ref conflict");if(opts.clearRepo){patch.repoUrl=null;patch.repoRef=null}else{if(opts.repo!==void 0)patch.repoUrl=opts.repo;if(opts.clearRef)patch.repoRef=null;else if(opts.ref!==void 0)patch.repoRef=opts.ref}if(opts.persona!==void 0&&opts.clearPersona)throw new CliError("usage","--persona and --clear-persona conflict");if(opts.clearPersona)patch.profileId=null;else if(opts.persona!==void 0)patch.profileId=opts.persona;if(opts.agent.length>0)patch.agents=buildAgentRoster(opts.agent);if(opts.skill.length>0&&opts.clearSkills)throw new CliError("usage","--skill and --clear-skills conflict");if(opts.clearSkills)patch.skillRefs=[];else if(opts.skill.length>0)patch.skillRefs=validateAssetRefs("skill",opts.skill);if(opts.mcp.length>0&&opts.clearMcp)throw new CliError("usage","--mcp and --clear-mcp conflict");if(opts.clearMcp)patch.mcpRefs=[];else if(opts.mcp.length>0)patch.mcpRefs=validateAssetRefs("mcp",opts.mcp);if(opts.connection.length>0&&opts.clearConnections)throw new CliError("usage","--connection and --clear-connections conflict");if(opts.clearConnections)patch.connectionIds=[];else if(opts.connection.length>0)patch.connectionIds=opts.connection;if(opts.cadence!==void 0)patch.cadence=parseCadence(opts.cadence);if(opts.samples!==void 0)patch.sampleCount=parseSampleCount(opts.samples);return patch}function addRunSettingsCreateOptions(command){return command.option("--agent <agent[:m1,m2]>","agent and optional model pins (repeatable)",collect2,[]).option("--skill <name@label>","staged skill (repeatable)",collect2,[]).option("--mcp <name@label>","MCP server (repeatable)",collect2,[]).option("--connection <id>","connection id (repeatable)",collect2,[]).option("--cadence <cadence>","none | daily | weekly | monthly","none").option("--samples <n>","sample count from 1 to 50","1")}function addRunSettingsEditOptions(command){return command.option("--agent <agent[:m1,m2]>","replace agents and model pins (repeatable)",collect2,[]).option("--skill <name@label>","replace skills (repeatable)",collect2,[]).option("--clear-skills","remove all skills").option("--mcp <name@label>","replace MCP servers (repeatable)",collect2,[]).option("--clear-mcp","remove all MCP servers").option("--connection <id>","replace connections (repeatable)",collect2,[]).option("--clear-connections","remove all connections").option("--cadence <cadence>","none | daily | weekly | monthly").option("--samples <n>","sample count from 1 to 50")}function hasRunSettingsFlags(opts){return opts.agent.length>0||opts.skill.length>0||opts.mcp.length>0||opts.connection.length>0||opts.cadence.toUpperCase()!=="NONE"||opts.samples!=="1"}function runSettingsFromOpts(opts){return{...opts.agent.length>0?{agents:buildAgentRoster(opts.agent)}:{},skillRefs:validateAssetRefs("skill",opts.skill),mcpRefs:validateAssetRefs("mcp",opts.mcp),connectionIds:opts.connection,cadence:parseCadence(opts.cadence),sampleCount:parseSampleCount(opts.samples)}}function runSettingsPatchFromOpts(opts){return ownedConfigPatchFromOpts(opts)}function runOverridesFromOpts(opts){return{...opts.agent.length>0?{agents:buildAgentRoster(opts.agent)}:{},...opts.samples!==void 0?{sampleCount:parseSampleCount(opts.samples)}:{}}}function cadenceLabel(cadence){return cadence==="NONE"?"manual":cadence.toLowerCase()}import{createHash as createHash2,randomUUID}from"crypto";import{existsSync as existsSync2,readFileSync as readFileSync4,realpathSync,statSync}from"fs";import{isAbsolute,join as join3,relative,resolve as resolve2}from"path";function saveLocalAnalysis(gaugeDir,runId,value){if(typeof value==="object"&&value!==null&&"schemaVersion"in value&&value.schemaVersion!==ANALYSIS_SCHEMA_VERSION){throw new CliError("usage",`Analysis schema version ${String(value.schemaVersion)} is not supported. This CLI accepts version ${ANALYSIS_SCHEMA_VERSION}; upgrade Gauge for newer analyses. No data was changed.`)}const parsed=analysisSubmissionSchema.safeParse(value);if(!parsed.success)throw new CliError("usage",`Invalid analysis: ${parsed.error.issues.map(issue=>`${issue.path.join(".")||"analysis"}: ${issue.message}`).join("; ")}`,{hint:"Use gauge run analysis schema for the analysis submission contract."});const submission=parsed.data;const store=openLocalStore(gaugeDir);try{const session=store.getSession(runId);if(!session)throw new CliError("usage",`Local run ${runId} was not found.`,{hint:"Use gauge run list --local, or repair session summaries if its artifacts exist."});if(!["completed","failed","canceled","interrupted"].includes(session.outcome))throw new CliError("usage",`Run ${runId} is ${session.outcome}. Wait until it finishes before publishing analysis.`);if(session.attempt!==submission.attempt)throw new CliError("usage",`Run ${runId} is on attempt ${session.attempt}; the submitted analysis targets attempt ${submission.attempt}.`);validateCriteria(session,submission);const attemptDirectory=safeAttemptDirectory(gaugeDir,runId,submission.attempt);const files=new Map;const refs=[...submission.findings.flatMap(finding=>finding.evidence),...submission.products.flatMap(product=>Object.values(product.evidence).flat()),...submission.criteria.flatMap(criterion=>criterion.evidence)];for(const ref of refs)validateEvidence(attemptDirectory,submission.attempt,ref,files);const hash=createHash2("sha256");for(const[path,contents]of[...files].sort(([a],[b])=>a.localeCompare(b)))hash.update(path).update("\0").update(contents).update("\0");const evidenceDigest=`sha256:${hash.digest("hex")}`;return store.transaction(()=>{const currentSession=store.getSession(runId);if(currentSession.attempt!==submission.attempt)throw new CliError("usage","The run advanced to another attempt while validating analysis. Read its new evidence before publishing.");const latest=store.db.prepare("SELECT MAX(revision) AS revision FROM session_analyses WHERE run_id = ?").get(runId);const analysis={...submission,id:`a_${randomUUID()}`,runId,revision:Number(latest?.revision??0)+1,createdAt:new Date().toISOString(),evidenceDigest,findings:submission.findings.map(finding=>({...finding,id:`f_${randomUUID()}`}))};store.db.prepare("INSERT INTO session_analyses VALUES (?,?,?,?,?,?,?,?,?)").run(analysis.id,runId,analysis.attempt,analysis.revision,analysis.schemaVersion,analysis.instructionsVersion,evidenceDigest,JSON.stringify(analysis),analysis.createdAt);const findingStatement=store.db.prepare("INSERT INTO session_findings VALUES (?,?,?,?,?,?,?,?,?,?,?)");for(const finding of analysis.findings)findingStatement.run(finding.id,analysis.id,finding.kind,finding.subject,finding.label,finding.detail,finding.basis,finding.effect,finding.cause,JSON.stringify(finding.tags),JSON.stringify(finding.evidence));const productStatement=store.db.prepare("INSERT INTO session_products VALUES (?,?,?,?)");analysis.products.forEach((product,position)=>productStatement.run(analysis.id,position,product.name,JSON.stringify(product)));const criterionStatement=store.db.prepare("INSERT INTO criterion_results VALUES (?,?,?,?,?)");for(const criterion of analysis.criteria)criterionStatement.run(analysis.id,criterion.criterionId,criterion.outcome,criterion.label,JSON.stringify(criterion.evidence));store.db.prepare("UPDATE sessions SET current_analysis_id = ? WHERE id = ?").run(analysis.id,runId);return analysis})}finally{store.close()}}function getLocalAnalysis(gaugeDir,runId){const store=openLocalStore(gaugeDir);try{return readCurrentAnalysis(store,runId)}finally{store.close()}}function readCurrentAnalysis(store,runId){const row2=store.db.prepare("SELECT a.schema_version,a.payload FROM session_analyses a JOIN sessions s ON s.current_analysis_id = a.id WHERE s.id = ?").get(runId);if(!row2)return null;if(row2.schema_version!==ANALYSIS_SCHEMA_VERSION)throw new CliError("usage",`Stored analysis uses schema version ${row2.schema_version}; upgrade Gauge to read it. Your data is intact.`);return JSON.parse(String(row2.payload))}function validateCriteria(session,submission){const configuration=session.configuration??{};const item=configuration.case;const criteria=item?.criteria??configuration.criteria??[];if(!Array.isArray(criteria))throw new CliError("usage","This run's frozen criteria are invalid; repair its session summary before analysis.");const expected=criteria.map(criterion=>{if(!criterion||typeof criterion.id!=="string"||!criterion.id)throw new CliError("usage","This run has a frozen criterion without an ID. Criterion IDs must be assigned before execution.");return criterion.id});const supplied=new Set(submission.criteria.map(criterion=>criterion.criterionId));const missing=expected.filter(id=>!supplied.has(id));const extra=[...supplied].filter(id=>!expected.includes(id));if(missing.length||extra.length)throw new CliError("usage",`Analysis must cover exactly the run's frozen criteria.${missing.length?` Missing: ${missing.join(", ")}.`:""}${extra.length?` Unknown: ${extra.join(", ")}.`:""} Use UNASSESSABLE with an explanation when evidence is insufficient.`)}function safeAttemptDirectory(gaugeDir,runId,attempt){if(!/^[A-Za-z0-9_-]+$/.test(runId))throw new CliError("usage","Invalid local run ID.");const directory=join3(gaugeDir,"runs",runId,"attempts",String(attempt));if(!existsSync2(directory))throw new CliError("usage",`Run evidence is missing: ${directory}`);return realpathSync(directory)}function readEvidence(directory,path,files){const fullPath=resolve2(directory,path);if(!isInside(directory,fullPath))throw new CliError("usage",`Evidence path ${path} leaves the run's attempt directory.`);if(!existsSync2(fullPath)||!statSync(fullPath).isFile())throw new CliError("usage",`Evidence artifact ${path} does not exist in this attempt.`);if(!isInside(directory,realpathSync(fullPath)))throw new CliError("usage",`Evidence artifact ${path} resolves outside this attempt.`);const contents=files.get(path)??readFileSync4(fullPath,"utf8");files.set(path,contents);return contents}function isInside(directory,path){const rel=relative(directory,path);return rel!==".."&&!rel.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!isAbsolute(rel)}function validateEvidence(directory,attempt,ref,files){if(ref.kind==="diff"){const diff2=readEvidence(directory,"session/diff.patch",files);const paths=new Set(diff2.split("\n").flatMap(line=>{const match=/^(?:\+\+\+|---) [ab]\/(.*)$/.exec(line);return match?[match[1].split(" ")[0]]:[]}));if(!paths.has(ref.path))throw new CliError("usage",`Diff evidence path ${ref.path} does not appear in this attempt's diff.patch.`);return}if(ref.kind==="artifact"&&ref.attempt!==void 0&&ref.attempt!==attempt)throw new CliError("usage",`Evidence references attempt ${ref.attempt}, but this analysis targets attempt ${attempt}.`);const artifact=ref.kind==="trace"?"session/events.ndjson":ref.artifact;const contents=readEvidence(directory,artifact,files);const lines=contents.split(/\r?\n/);if(lines.at(-1)==="")lines.pop();if(ref.kind==="artifact"&&ref.line!==void 0&&(ref.line>lines.length||(ref.endLine??ref.line)>lines.length))throw new CliError("usage",`Evidence ${artifact}:${ref.line}${ref.endLine?`-${ref.endLine}`:""} exceeds the artifact's ${lines.length} lines.`);if(ref.seq!==void 0){const hasSequence=lines.some(line=>{try{return JSON.parse(line).seq===ref.seq}catch{return false}});if(!hasSequence)throw new CliError("usage",`Evidence sequence ${ref.seq} does not exist in ${artifact}. Copy an event's recorded seq; do not use its array index or turn.`,{hint:`For evidence without seq, cite an original artifact line, for example ${JSON.stringify({kind:"artifact",artifact,attempt,line:1})}. Line numbers start at 1; choose the line containing your evidence.`})}}function renderLocalAnalysisMarkdown(analysis){const lines=[`# Session analysis: ${analysis.runId}`,"",`Analysis ${analysis.id}, revision ${analysis.revision}; attempt ${analysis.attempt}.`,`Assessment: ${analysis.assessability}.`,""];if(analysis.limitation)lines.push(`Limitation: ${analysis.limitation}`,"");for(const finding of analysis.findings)lines.push(`## ${finding.kind}: ${finding.label}`,"",`${finding.subject} \xB7 ${finding.effect} \xB7 ${finding.basis}`,"",finding.detail,"",`Evidence: ${finding.evidence.map(formatEvidence).join(", ")}`,"");if(!analysis.findings.length)lines.push("No findings were reported in this analysis.","");if(analysis.criteria.length){lines.push("## Criteria","");for(const criterion of analysis.criteria)lines.push(`- ${criterion.criterionId}: ${criterion.outcome} \u2014 ${criterion.label}`);lines.push("")}if(analysis.products.length){lines.push("## Products","");for(const product of analysis.products)lines.push(`- ${product.name}: ${product.chosen?"chosen":product.rejected?"rejected":product.considered?"considered":"mentioned"} \u2014 ${product.reason}`);lines.push("")}return lines.join("\n")}function formatEvidence(ref){if(ref.kind==="trace")return`trace ${ref.seq}`;if(ref.kind==="diff")return`diff ${ref.path}`;return`${ref.artifact}${ref.line!==void 0?`:${ref.line}${ref.endLine!==void 0?`-${ref.endLine}`:""}`:` seq ${ref.seq}`}`}function localDirectory(command){const state=gaugeState(command);if(!state.root)throw new CliError("usage","No Gauge workspace found. Run `gauge init` in this directory first.");if(state.config===null)throw new CliError("usage","gauge.json is not valid JSON");return join4(state.root,".gauge")}function isLocal(command){return gaugeState(command).mode==="local"}function withLocalStore(command,fn){const store=openLocalStore(localDirectory(command));try{return fn(store)}finally{store.close()}}function normalize(kind,raw,previous){const{inputs:_inputs,...definition}=raw;const scenarioInputs=Array.isArray(definition.scenarios)?definition.scenarios:void 0;if(scenarioInputs)definition.scenarios=scenarioInputs.map(({id:_id,...scenario})=>scenario);const parsed=(kind==="eval"?createEvalSetBodySchema:createVisibilityPromptBodySchema).safeParse(definition);if(!parsed.success)throw new CliError("usage",`Invalid ${kind}: ${parsed.error.issues.map(i=>`${i.path.join(".")}: ${i.message}`).join("; ")}`);const value=parsed.data;value.name=value.name.trim();value.promptText=value.promptText.trim();if(!value.name||!value.promptText)throw new CliError("usage","A measurement needs a nonempty name and prompt.");if(value.cadence&&value.cadence!=="NONE")throw new CliError("usage","Local measurements do not support managed schedules. Use --cadence none or --hosted.");if(value.nextRunAt)throw new CliError("usage","Local measurements do not support scheduled start times. Use --hosted.");assertLocalCapabilities(value);value.tags=[...new Set((value.tags??[]).map(tag=>tag.trim()).filter(Boolean))];if(kind==="eval"){if(value.repoRef&&!value.repoUrl)throw new CliError("usage","A repository ref requires a repository URL.");const ids=new Set;const existing=new Set(previous?.criteria?.map(criterion=>criterion.id));value.criteria=value.criteria.map(c=>{const rubric=c.rubric.trim();if(!rubric)throw new CliError("usage","Every criterion needs a nonempty rubric.");if(c.id&&previous&&!existing.has(c.id))throw new CliError("usage",`Unknown criterion ID: ${c.id}. Omit id to add a new criterion.`);const id=c.id??`cr_${randomUUID2()}`;if(!id||ids.has(id))throw new CliError("usage",`Duplicate or empty criterion ID: ${id}`);ids.add(id);return{id,name:c.name?.trim()||deriveCriterionName(rubric),rubric}})}else{value.brandA=typeof value.brandA==="string"?value.brandA.trim()||null:null;value.brandB=typeof value.brandB==="string"?value.brandB.trim()||null:null;if(value.kind==="HEAD_TO_HEAD"){if(!value.brandA||!value.brandB||String(value.brandA).toLowerCase()===String(value.brandB).toLowerCase())throw new CliError("usage","Head-to-head preference needs two different --brand-a and --brand-b values");[value.brandA,value.brandB]=[String(value.brandA),String(value.brandB)].sort((a,b)=>a.toLowerCase().localeCompare(b.toLowerCase()))}value.branded=value.kind==="HEAD_TO_HEAD"||Boolean(value.branded);value.agents??=[{agent:"CLAUDE_CODE",models:[]},{agent:"CODEX_CLI",models:[]}];const scenarios=value.scenarios;if(!previous&&scenarios.length===0)scenarios.push({repoUrl:null,repoRef:null,profileId:null});if(scenarios.some(s=>s.profileId))throw new CliError("usage","Local scenarios do not support hosted personas");const seen=new Set;const ids=new Set;const existing=new Set(previous?.scenarios?.map(scenario=>scenario.id));value.scenarios=scenarios.map((scenario,index)=>{const repoUrl=typeof scenario.repoUrl==="string"?scenario.repoUrl.trim()||null:null;const repoRef=typeof scenario.repoRef==="string"?scenario.repoRef.trim()||null:null;if(repoRef&&!repoUrl)throw new CliError("usage","A scenario ref requires a repository URL.");const key=JSON.stringify([repoUrl,repoRef]);if(seen.has(key))throw new CliError("usage","This prompt already has the same scenario.");seen.add(key);const suppliedId=scenarioInputs?.[index]?.id;if(suppliedId!==void 0&&(typeof suppliedId!=="string"||!previous||!existing.has(suppliedId)))throw new CliError("usage",`Unknown scenario ID: ${suppliedId}. Omit id to add a scenario.`);const id=typeof suppliedId==="string"?suppliedId:`sc_${randomUUID2()}`;if(ids.has(id))throw new CliError("usage",`Duplicate scenario ID: ${id}`);ids.add(id);return{id,repoUrl,repoRef,profileId:null}})}return value}function editable(row2){const{id,revision,measurementKind,createdAt,updatedAt,...definition}=row2;return definition}function createLocalMeasurement(command,kind,definition){return withLocalStore(command,store=>store.createMeasurement(kind,normalize(kind,definition)))}function editLocalMeasurement(command,kind,id,patch){return withLocalStore(command,store=>{const current=store.requireMeasurement(id,kind);const value=normalize(kind,{...editable(current),...patch},current);if(!("criteria"in patch)&¤t.criteria)value.criteria=current.criteria;if(!("scenarios"in patch)&¤t.scenarios)value.scenarios=current.scenarios;return store.updateMeasurement(id,value)})}function getLocalMeasurement(command,kind,id){return withLocalStore(command,store=>measurementWithStats(store,store.requireMeasurement(id,kind)))}function removeLocalMeasurement(command,kind,id){withLocalStore(command,store=>{store.requireMeasurement(id,kind);store.deleteMeasurement(id)})}function localMeasurementView(row2){return{profile:null,suiteId:null,market:null,position:0,runCount:0,lastRunAt:null,cadence:"NONE",sampleCount:1,repoUrl:null,repoRef:null,agents:[],skillRefs:[],mcpRefs:[],connectionIds:[],stats:{passRates:[],runCount:0,judgedRuns:0,passedRuns:0},...row2,scenarios:Array.isArray(row2.scenarios)?row2.scenarios.map(s=>({...s,profile:null})):[]}}function listLocalMeasurements(command,kind){return withLocalStore(command,store=>store.listMeasurements(kind).map(row2=>localMeasurementView(measurementWithStats(store,row2))))}function measurementWithStats(store,row2){const sessions=store.listSessions({measurementId:row2.id});const stats={runCount:sessions.length,judgedRuns:0,passedRuns:0,passRates:[]};for(const session of sessions){const analysis=readCurrentAnalysis(store,session.id);if(!analysis)continue;const outcomes=analysis.criteria.map(criterion=>criterion.outcome);const verdict=outcomes.includes("FAIL")?false:!outcomes.length||outcomes.includes("UNASSESSABLE")?null:true;if(verdict===null)continue;stats.judgedRuns++;if(verdict)stats.passedRuns++;if(!stats.passRates.some(rate=>rate.agent===session.agent))stats.passRates.push({agent:session.agent,model:session.model,runId:session.id,finishedAt:session.endedAt,passed:outcomes.filter(outcome=>outcome==="PASS").length,total:outcomes.length})}return{...row2,runCount:sessions.length,lastRunAt:sessions.map(session=>session.createdAt).sort().at(-1)??null,stats}}function deriveCriterionName(rubric){const trimmed=rubric.replace(/^\s*(?:[-*•]|\(?\d+[.)])\s+/,"").trim();const first=trimmed.split(/(?<=[.!?])\s|\n/)[0]?.trim()??"";return(new RegExp("\\p{L}","u").test(first)?first:trimmed.replace(/\s+/g," ")).replace(/[.!?]+$/,"").trim()}function localMeasurementSpec(command,kind,id,opts){const row2=getLocalMeasurement(command,kind,id);const stored=row2.inputs;if(stored?.length&&!opts.inputs.length)console.error(`note: saved inputs are no longer attached (${stored.join(", ")}). Pass --input <name> at launch.`);const settings={...row2,...runOverridesFromOpts(opts)};const agents=settings.agents;if(!agents?.length)throw new CliError("usage","Choose at least one agent with --agent before launching this local measurement");let scenarios=kind==="preference"?settings.scenarios:[{repoUrl:settings.repoUrl??null,repoRef:settings.repoRef??null}];if(!scenarios.length)throw new CliError("usage","This preference prompt has no scenarios. Add one with gauge preference scenarios add <id> before running it.");if(opts.scenario?.length){for(const selected of opts.scenario)if(!scenarios.some(s=>s.id===selected))throw new CliError("usage",`Unknown local scenario: ${selected}`);scenarios=scenarios.filter(s=>s.id!==void 0&&opts.scenario.includes(s.id))}const cases=scenarios.map((scenario,index)=>({key:`${kind}-${index+1}`,prompt:String(settings.promptText),...kind==="eval"?{criteria:settings.criteria.map(c=>({name:c.name,rubric:c.rubric}))}:{preference:settings.kind==="HEAD_TO_HEAD"?{kind:"head-to-head",brandA:String(settings.brandA),brandB:String(settings.brandB)}:{kind:"open-ended",branded:Boolean(settings.branded)}},config:{agents,sampleCount:Number(settings.sampleCount??1),repoUrl:scenario.repoUrl,repoRef:scenario.repoRef,inputs:opts.inputs}}));return{spec:{version:2,cases},measurement:{id,kind,revision:row2.revision,...kind==="eval"?{criterionIds:row2.criteria.map(c=>c.id)}:{}}}}import{readFileSync as readFileSync5}from"fs";import{createInterface as createInterface2}from"readline";async function confirmOrAbort(question,yes){if(yes)return;if(!process.stdin.isTTY){throw new CliError("usage","refusing to proceed without confirmation on a non-interactive stdin \u2014 pass --yes")}const rl=createInterface2({input:process.stdin,output:process.stderr});const answer=await new Promise(resolve6=>rl.question(`${question} [y/N] `,resolve6));rl.close();if(!/^y(es)?$/i.test(answer.trim())){throw new CliError("usage","aborted")}}function evalSetsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/eval-sets`}function evalSetPath(org,id){return`${evalSetsPath(org)}/${encodeURIComponent(id)}`}function parseCriterion(raw){const idx=raw.indexOf(":");if(idx<=0||!raw.slice(idx+1).trim()){throw new CliError("usage",`invalid --criterion "${raw}" (expected "Name: rubric text")`)}return{name:raw.slice(0,idx).trim(),rubric:raw.slice(idx+1).trim()}}function readCriteriaFile(path){let parsed;try{parsed=JSON.parse(readFileSync5(path==="-"?0:path,"utf8"))}catch(e){throw new CliError("usage",`could not read --criteria-file: ${e instanceof Error?e.message:e}`)}if(!Array.isArray(parsed)||parsed.length===0)throw new CliError("usage","--criteria-file must be a non-empty JSON array of {id?, name, rubric}");return parsed}function criteriaFromOpts(opts){if(opts.criterion.length>0&&opts.criteriaFile!==void 0)throw new CliError("usage","--criterion and --criteria-file conflict");if(opts.criteriaFile!==void 0)return readCriteriaFile(opts.criteriaFile);if(opts.criterion.length>0)return opts.criterion.map(parseCriterion);return void 0}function repoLabel(e){if(!e.repoUrl)return"(default scaffold)";return e.repoRef?`${e.repoUrl}@${e.repoRef}`:e.repoUrl}function passRateLabel(stats){if(stats.judgedRuns===0)return"-";return`${Math.round(stats.passedRuns/stats.judgedRuns*100)}% (${stats.passedRuns}/${stats.judgedRuns})`}function evalSetRow(e){return{id:e.id,name:e.name,repo:repoLabel(e),criteria:e.criteria.length,tags:e.tags.join(", "),"pass rate":passRateLabel(e.stats),runs:e.stats.runCount}}function printDetail(e){console.log(`id: ${e.id}`);console.log(`name: ${e.name}`);console.log(`repo: ${repoLabel(e)}`);console.log(`persona: ${e.profile?e.profile.name:"(default persona)"}`);console.log(`tags: ${e.tags.join(", ")||"(none)"}`);console.log(`cadence: ${cadenceLabel(e.cadence)}`);console.log(`samples: ${e.sampleCount}`);console.log(`agents: ${e.agents.map(agent=>`${agent.agent}${agent.models.length>0?`:${agent.models.join(",")}`:""}`).join("; ")}`);console.log(`skills: ${e.skillRefs.join(", ")||"(none)"}`);console.log(`mcp: ${e.mcpRefs.join(", ")||"(none)"}`);console.log(`conns: ${e.connectionIds.join(", ")||"(none)"}`);console.log(`prompt: ${e.promptText}`);console.log("criteria:");for(const c of e.criteria)console.log(` [${c.id}] ${c.name}: ${c.rubric}`)}async function listEvalSets(cmd,opts){if(isLocal(cmd)){if(opts.agents||opts.models||opts.since)throw new CliError("usage","Local eval list does not support stats filters yet; use gauge query --local.");return listLocalMeasurements(cmd,"eval")}const res=await createClient().get(evalSetsPath(resolveOrg(cmd)),{agents:opts.agents===void 0?void 0:parseAgents(opts.agents).join(","),models:opts.models,since:opts.since});return res.items}async function getEvalSet(cmd,id){const evalSet=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"eval",id)):await createClient().get(evalSetPath(resolveOrg(cmd),id));if(resolveOutput(cmd)==="json")printJson(evalSet);else printDetail(evalSet)}async function createEvalSet(cmd,opts){const criteria=criteriaFromOpts(opts);if(!criteria)throw new CliError("usage","at least one --criterion (or --criteria-file) is required");const body={name:opts.name,promptText:readPromptText(opts),...ownedConfigFromOpts(opts),criteria,tags:opts.tag.length>0?opts.tag:void 0};if(!isLocal(cmd)&&opts.repo===void 0)console.error("note: no --repo \u2014 this eval set will run against the default Gauge scaffold, NOT your repository. Use `gauge eval edit <id> --repo <url>` to retarget.");const created=isLocal(cmd)?createLocalMeasurement(cmd,"eval",body):await createClient().post(evalSetsPath(resolveOrg(cmd)),body);if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created eval set ${created.id}`)}async function editEvalSet(cmd,id,opts){const body=ownedConfigPatchFromOpts(opts);if(opts.name!==void 0)body.name=opts.name;if(opts.text!==void 0||opts.file!==void 0)body.promptText=readPromptText(opts);const criteria=criteriaFromOpts(opts);if(criteria)body.criteria=criteria;if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");if(opts.clearTags)body.tags=[];else if(opts.tag.length>0)body.tags=opts.tag;if(Object.keys(body).length===0)throw new CliError("usage","nothing to change");const updated=isLocal(cmd)?editLocalMeasurement(cmd,"eval",id,body):await createClient().patch(evalSetPath(resolveOrg(cmd),id),body);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated eval set ${updated.id}`)}async function removeEvalSet(cmd,id){if(isLocal(cmd))removeLocalMeasurement(cmd,"eval",id);else await createClient().delete(evalSetPath(resolveOrg(cmd),id));if(resolveOutput(cmd)!=="json")console.log(`Deleted eval set ${id}`)}async function runEvalSet(cmd,id,opts){const org=resolveOrg(cmd);const overrides=runOverridesFromOpts(opts);await confirmOrAbort(Object.keys(overrides).length>0?"Run this eval now with these overrides? The stored configuration stays unchanged.":"Run this eval's stored configuration now?",opts.yes);const result=await createClient().post(`${evalSetPath(org,id)}/run`,overrides);if(resolveOutput(cmd)==="json")printJson(result);else{console.log(`Started ${result.runIds.length} run${result.runIds.length===1?"":"s"} in batch ${result.batchIds[0]??""}`);for(const batch of result.batchIds)console.log(`Runs: gauge run list --batch ${batch}`);if(result.runRequestId)console.log(`Wait: gauge --org ${org} run wait ${result.runRequestId}`)}}function register9(program2){const evals=program2.command("eval").description("Manage eval sets: saved prompts with judged criteria. Launch one with `gauge run --eval <id>`");evals.command("list").description("List eval sets").option("--agents <agents>","stats for these agents only (csv)").option("--models <models>","stats for these model slugs only (csv)").option("--since <date>","stats for runs since this ISO date only").action(async(opts,cmd)=>{const items=await listEvalSets(cmd,opts);if(resolveOutput(cmd)==="json")printJson(items);else printItems(items.map(evalSetRow),"table")});evals.command("get <id>").description("Show one eval set").action(async(id,_opts,cmd)=>{await getEvalSet(cmd,id)});addRunSettingsCreateOptions(evals.command("create").description("Create an eval set").requiredOption("--name <name>","name").option("--text <text>","prompt text inline").option("--file <path>",'prompt text from a file ("-" for stdin)').option("--repo <url>","consumer repository (default: empty locally, Gauge scaffold hosted)").option("--ref <ref>","branch, tag, or commit (with --repo)").option("--persona <profileId>","persona profile id")).option("--criterion <spec>",'judged criterion as "Name: rubric text" (repeatable)',collect2,[]).option("--criteria-file <path>",'JSON array of {name, rubric} ("-" for stdin)').option("--tag <name>","user tag name, create-on-type (repeatable)",collect2,[]).action(async(opts,cmd)=>{await createEvalSet(cmd,opts)});addRunSettingsEditOptions(evals.command("edit <id>").description("Update an eval set. Omitted flags keep their value. A criteria list REPLACES the whole set (use --criteria-file with ids to edit in place).").option("--name <name>","rename it").option("--text <text>","replace the prompt text inline").option("--file <path>",'replace the prompt text from a file ("-" stdin)').option("--repo <url>","set the repository (keeps a ref pin)").option("--ref <ref>","set the branch, tag, or commit pin").option("--clear-ref","drop the ref pin").option("--clear-repo","use an empty workspace locally or the default scaffold hosted").option("--persona <profileId>","set the persona profile id").option("--clear-persona","use the default persona")).option("--criterion <spec>",'criterion as "Name: rubric", replaces the whole set (repeatable)',collect2,[]).option("--criteria-file <path>","JSON array of {id?, name, rubric}; entries with id update in place").option("--tag <name>","replace the user tag set (repeatable)",collect2,[]).option("--clear-tags","remove all user tags").action(async(id,opts,cmd)=>{await editEvalSet(cmd,id,opts)});evals.command("rm <id>").description("Delete an eval set (run history stays)").action(async(id,_opts,cmd)=>{await removeEvalSet(cmd,id)})}var feedback_exports2={};__export(feedback_exports2,{register:()=>register10});import{Option as Option2}from"commander";function register10(program2){program2.command("feedback").description("Send feedback about this CLI to the Gauge team: friction you hit, missing commands or flags, bugs").requiredOption("-m, --message <text>","what happened").addOption(new Option2("--kind <kind>","feedback type").choices([...feedback_exports.FEEDBACK_KINDS]).default("other")).option("--command <command>","the gauge command the feedback is about").action(async(opts,cmd)=>{const{org}=cmd.optsWithGlobals();const client=createClient({authOptional:true});const body={message:opts.message,kind:opts.kind,command:opts.command,org:client.signedIn?org??readConfig().defaultOrg:void 0};const res=await client.post("/api/v1/feedback",body);if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Feedback sent (${res.id}${client.signedIn?"":", anonymous"}). Thank you.`)})}var instructions_exports={};__export(instructions_exports,{register:()=>register11});var EVAL=`---
|
|
9
|
+
`);console.log("Store it now \u2014 it won't be shown again.")});tokens.command("revoke <id>").description("Revoke an API token").action(async(id,_opts,command)=>{await createClient().delete(`${TOKENS_PATH}/${encodeURIComponent(id)}`);if(resolveOutput(command)!=="json")console.log(`Revoked ${id}`)});program2.command("whoami").description("Show the user or organization API key you are acting as").action(async(_opts,command)=>{await whoami(resolveOutput(command))})}var billing_exports={};__export(billing_exports,{fmtOverage:()=>fmtOverage,register:()=>register3});function fmtDate(iso){return iso?iso.slice(0,10):"\u2014"}function fmtOverage(s){const line=s.creditLine;if(!line)return s.paymentType==="card"?"n/a (card)":"\u2014";if(line.limitUsd<=0)return"off (credit line limit $0)";return`$${line.usedUsd.toFixed(2)} of $${line.limitUsd.toFixed(2)} credit line`}function statusLines(s){return[["Plan",s.plan??"free"],["Subscription",s.subscriptionStatus??"\u2014"],["Payment",s.paymentType??"\u2014"],["Balance",`${s.balance} credits`],["Allowance / cycle",s.allowance===null?"\u2014":`${s.allowance} credits`],["Period",s.currentPeriodStart||s.currentPeriodEnd?`${fmtDate(s.currentPeriodStart)} \u2192 ${fmtDate(s.currentPeriodEnd)}`:"\u2014"],["Used this period",`${s.creditsUsedThisPeriod} credits`],["Runs this period",String(s.runsThisPeriod)],["Overage",fmtOverage(s)],["Can run eval",s.canRunByWorkload.eval?"yes":"no"],["Can run preference",s.canRunByWorkload.visibility?"yes":"no"],["Can run generic",s.canRunByWorkload.generic?"yes":"no"],["Billing enforced",s.enforced?"yes":"no"]]}function register3(program2){const group=hostedOnly(program2.command("billing")).description("Billing & credits");group.command("status").description("Show credit balance, plan, payment, and overage").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const status=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/billing`);if(resolveOutput(cmd)==="json"){printJson(status);return}const lines=statusLines(status);const width=Math.max(...lines.map(([label])=>label.length));for(const[label,value]of lines){console.log(`${label.padEnd(width)} ${value}`)}})}var brands_exports2={};__export(brands_exports2,{register:()=>register4});import{Option}from"commander";var KINDS=brands_exports.BRAND_KINDS.map(k=>k.toLowerCase());var ECOSYSTEMS=brands_exports.BRAND_PACKAGE_ECOSYSTEMS;function brandsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/brands`}function collect(value,previous){return previous?[...previous,value]:[value]}function splitList(raw){return raw.split(",").map(v=>v.trim()).filter(Boolean)}function parsePackage(raw){const sep4=raw.lastIndexOf(":");if(sep4===-1)return{name:raw.trim(),ecosystem:null};const name=raw.slice(0,sep4).trim();const ecosystem=raw.slice(sep4+1).trim();if(!name)throw new CliError("usage",`Invalid package "${raw}"`);if(!ECOSYSTEMS.includes(ecosystem)){throw new CliError("usage",`Invalid ecosystem "${ecosystem}" (expected ${ECOSYSTEMS.join("|")})`)}return{name,ecosystem}}function toRow(brand){return{id:brand.id,name:brand.name,kind:brand.kind.toLowerCase(),aliases:brand.aliases.join(", "),websites:brand.websites.join(", "),packages:brand.packages.map(p=>p.name).join(", ")}}function register4(program2){const group=hostedOnly(program2.command("brands")).description("Manage org brands");group.command("list").description("List brands").addOption(new Option("--kind <kind>","filter by kind").choices(KINDS)).action(async(opts,cmd)=>{const org=await resolveOrg(cmd);const items=await fetchAllPages(createClient(),brandsPath(org),{kind:opts.kind?.toUpperCase()});if(resolveOutput(cmd)==="json"){printJson(items);return}printItems(items.map(toRow),"table")});group.command("add <name>").description("Add a brand").addOption(new Option("--kind <kind>","brand kind").choices(KINDS).makeOptionMandatory()).option("--aliases <list>","comma-separated alias spellings").option("--websites <list>","comma-separated docs/marketing URLs").option("--package <name[:ecosystem]>","package identifier, repeatable (ecosystem: npm|pypi|cargo|go|rubygems|other)",collect).action(async(name,opts,cmd)=>{const org=await resolveOrg(cmd);const row2=await createClient().post(brandsPath(org),{name,kind:opts.kind.toUpperCase(),aliases:opts.aliases===void 0?[]:splitList(opts.aliases),websites:opts.websites===void 0?[]:splitList(opts.websites),packages:(opts.package??[]).map(parsePackage)});if(resolveOutput(cmd)==="json")printJson(row2);else console.log(`Created brand ${row2.id} (${row2.name})`)});group.command("edit <id>").description("Update a brand (only the provided fields change)").option("--name <name>","new canonical name").addOption(new Option("--kind <kind>","new kind").choices(KINDS)).option("--aliases <list>","replace aliases (comma-separated; pass '' to clear)").option("--websites <list>","replace websites (comma-separated; pass '' to clear)").option("--package <name[:ecosystem]>","replace packages, repeatable",collect).option("--clear-packages","remove all packages").action(async(id,opts,cmd)=>{const patch={};if(opts.name!==void 0)patch.name=opts.name;if(opts.kind!==void 0)patch.kind=opts.kind.toUpperCase();if(opts.aliases!==void 0)patch.aliases=splitList(opts.aliases);if(opts.websites!==void 0)patch.websites=splitList(opts.websites);if(opts.clearPackages)patch.packages=[];else if(opts.package!==void 0)patch.packages=opts.package.map(parsePackage);if(Object.keys(patch).length===0){throw new CliError("usage","Nothing to update \u2014 pass at least one of --name/--kind/--aliases/--websites/--package/--clear-packages.")}const org=await resolveOrg(cmd);const row2=await createClient().patch(`${brandsPath(org)}/${encodeURIComponent(id)}`,patch);if(resolveOutput(cmd)==="json")printJson(row2);else console.log(`Updated brand ${row2.id} (${row2.name})`)});group.command("rm <id>").description("Delete a brand").action(async(id,_opts,cmd)=>{const org=await resolveOrg(cmd);await createClient().delete(`${brandsPath(org)}/${encodeURIComponent(id)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted brand ${id}`)})}var chat_exports={};__export(chat_exports,{register:()=>register6});import{Help}from"commander";var MAX_ANSWER_LIMIT=100;var list=raw=>raw?csv(raw):void 0;function rowFilters(command){return command.option("--since <date>","YYYY-MM-DD (default 7 days ago; ranges \u2264 92 days)").option("--until <date>","YYYY-MM-DD (default today)").option("--model <models>","comma-separated models").option("--prompt <ids>","comma-separated prm_ ids").option("--topic <ids>","comma-separated top_ ids").option("--tag <ids>","comma-separated tag_ ids").option("--tracking-type <type>","visibility (default) | branded_own | all")}function rowQuery(opts){return{since:opts.since,until:opts.until,model:list(opts.model),prompt:list(opts.prompt),topic:list(opts.topic),tag:list(opts.tag),trackingType:opts.trackingType}}function registerData(chat){const answers=chat.command("answers").description("Sampled AI answers in a category");addPageOptions(rowFilters(withCategory(answers.command("list",{isDefault:true})).description("List answers, newest first").option("--brand <ids>","only answers mentioning any of these brd_ ids").option("--brand-absent <ids>","only answers mentioning none of these brd_ ids")),MAX_ANSWER_LIMIT).action(async(opts,cmd)=>{const scope=await categoryScope(cmd);const page=await fetchPages(scope.client,chatPath(...scope.base,"answers"),{...rowQuery(opts),brand:list(opts.brand),brandAbsent:list(opts.brandAbsent)},opts,MAX_ANSWER_LIMIT);printPage(page,resolveOutput(cmd),a=>({id:a.id,day:a.day,model:a.model,prompt:a.promptId,brands:a.brandIds.length,text:truncate(a.text,60)}))});withCategory(answers.command("get <answer>")).description("Show an answer with its mentions, citations and search queries").action(async(id,_opts,cmd)=>{const scope=await categoryScope(cmd);const answer=await scope.client.get(chatPath(...scope.base,"answers",id));if(resolveOutput(cmd)==="json")return printJson(answer);console.log(`${answer.id} ${answer.model} ${answer.day}`);console.log(`Prompt (${answer.promptId}): ${answer.promptText}
|
|
10
|
+
`);console.log(`${answer.text}
|
|
11
|
+
`);printItems(answer.mentions.map(m=>({brand:m.brandId,name:m.name,count:m.count,types:m.mentionTypes.join(",")})),"table");console.log("");printItems(answer.citations.map(c=>({page:c.pageId,domain:c.domain,url:c.url})),"table");if(answer.searchQueries.length)console.log(`
|
|
12
|
+
Search queries: ${answer.searchQueries.join(" | ")}`)});const citations=chat.command("citations").description("Pages cited by AI answers in a category");addPageOptions(rowFilters(withCategory(citations.command("list",{isDefault:true})).description("List citations").option("--domain <domains>","comma-separated cited domains").option("--page <ids>","comma-separated pag_ ids"))).action(async(opts,cmd)=>{const scope=await categoryScope(cmd);const page=await fetchPages(scope.client,chatPath(...scope.base,"citations"),{...rowQuery(opts),domain:list(opts.domain),page:list(opts.page)},opts);printPage(page,resolveOutput(cmd),c=>({answer:c.answerId,day:c.day,model:c.model,domain:c.domain,url:c.url}))})}import{readFileSync}from"fs";var TRACKING_TYPES=["visibility","branded_own"];var collect2=(value,prev=[])=>[...prev,...csv(value)];function readSource(file){return readFileSync(file==="-"?0:file,"utf8")}function fromJson(value,where){if(typeof value==="string")return{text:value};if(!value||typeof value!=="object"||Array.isArray(value))throw new CliError("usage",`${where}: expected a prompt string or an object with "text"`);const item=value;if(typeof item.text!=="string")throw new CliError("usage",`${where}: "text" must be a string`);const topic=item.topicId??item.topic;const tags=item.tagIds??item.tags;if(topic!==void 0&&typeof topic!=="string")throw new CliError("usage",`${where}: "topicId" must be a string`);if(tags!==void 0&&!(Array.isArray(tags)&&tags.every(t=>typeof t==="string")))throw new CliError("usage",`${where}: "tagIds" must be a string array`);if(item.trackingType!==void 0&&typeof item.trackingType!=="string")throw new CliError("usage",`${where}: "trackingType" must be a string`);return{text:item.text,topic,trackingType:item.trackingType,tags}}function parsePromptInput(content){const trimmed=content.trim();if(trimmed.startsWith("[")){let parsed;try{parsed=JSON.parse(trimmed)}catch(error){throw new CliError("usage",`prompt file is not valid JSON: ${error.message}`)}return parsed.map((item,i)=>fromJson(item,`item ${i}`))}return content.split(/\r?\n/).map((line,i)=>({line:line.trim(),number:i+1})).filter(({line})=>line).map(({line,number})=>{if(!line.startsWith("{"))return{text:line};try{return fromJson(JSON.parse(line),`line ${number}`)}catch(error){if(error instanceof CliError)throw error;throw new CliError("usage",`line ${number} is not valid JSON: ${error.message}`)}})}function trackingType(value){if(value===void 0)return void 0;if(TRACKING_TYPES.includes(value))return value;throw new CliError("usage",`trackingType must be one of ${TRACKING_TYPES.join(", ")} (got "${value}")`)}async function resolvePrompts(scope,raw,defaults){const topics=new Map;for(const[i,item]of raw.entries()){const topic=item.topic??defaults.topic;if(!topic)throw new CliError("usage",`prompt ${i} has no topic. Pass --topic <id|slug|title> or set "topicId" per item.`);if(!topics.has(topic))topics.set(topic,await resolveTopicId(scope,topic))}const tagNames=[...new Set([...defaults.tags,...raw.flatMap(item=>item.tags??[])])];const tagIds=new Map;const resolved=await resolveTagIds(scope,tagNames);tagNames.forEach((name,i)=>tagIds.set(name,resolved[i]));return raw.map(item=>{const tags=[...new Set([...defaults.tags,...item.tags??[]])];const type=trackingType(item.trackingType??defaults.trackingType);return{text:item.text,topicId:topics.get(item.topic??defaults.topic),...type?{trackingType:type}:{},...tags.length?{tagIds:tags.map(t=>tagIds.get(t))}:{}}})}var normalized=text=>text.trim().toLowerCase().replace(/\s+/g," ");function outcome(prompts,responses,dryRun){const results=responses.flatMap((response,chunk)=>response.results.map(r=>{const index=chunk*CHAT_BATCH_SIZE+r.index;return{index,status:r.status,id:r.prompt?.id??null,text:prompts[index].text,prompt:r.prompt??null}}));const summary={created:0,already_exists:0,would_create:0};for(const r of results)summary[r.status]++;return{results,dryRun,remaining:responses.at(-1)?.remaining??null,summary}}function printOutcome(result,cmd){if(resolveOutput(cmd)==="json")return printJson(result);printItems(result.results.map(r=>({index:r.index,status:r.status,id:r.id,text:truncate(r.text,70)})),"table");const{created,already_exists,would_create}=result.summary;console.error(`${result.dryRun?"dry run: ":""}${result.dryRun?`${would_create} would be created`:`${created} created`}, ${already_exists} already existed${result.remaining===null?"":`; plan allows ${result.remaining} more`}.`)}async function addPrompts(scope,prompts,dryRun,onPartial){const path=chatPath(...scope.base,"prompts");const batches=chunks(prompts);const send=(batch,dry)=>scope.client.post(path,{prompts:batch},{dryRun:dry||void 0});if(!dryRun&&batches.length>1){const preview=[];for(const batch of batches)preview.push(await send(batch,true));const fresh=new Set;preview.forEach((response,chunk)=>{for(const r of response.results)if(r.status==="would_create")fresh.add(normalized(prompts[chunk*CHAT_BATCH_SIZE+r.index].text))});const first=preview[0];const remaining=first?.remaining===null||first?.remaining===void 0?null:first.remaining+first.results.filter(r=>r.status==="would_create").length;if(remaining!==null&&fresh.size>remaining)throw new CliError("insufficient_credits",`limit_exceeded: ${fresh.size} new prompts exceed the ${remaining} your plan allows; nothing was created.`,{apiCode:"limit_exceeded",details:{remaining,wouldCreate:fresh.size}})}const responses=[];for(const batch of batches){try{responses.push(await send(batch,dryRun))}catch(error){if(responses.length&&onPartial)onPartial(outcome(prompts,responses,dryRun));if(responses.length&&error instanceof CliError)throw new CliError(error.code,`${error.message} \u2014 the first ${responses.length*CHAT_BATCH_SIZE} prompts were already submitted; rerunning is safe (existing prompts report already_exists).`,{apiCode:error.apiCode,details:error.details,hint:error.hint});throw error}}return outcome(prompts,responses,dryRun)}function readIds(args,file){const ids=[...args,...file?readSource(file).split(/[\s,]+/).filter(Boolean):[]];if(!ids.length)throw new CliError("usage","pass prompt ids as arguments or with --file");return[...new Set(ids)]}function registerPrompts(chat){const prompts=chat.command("prompts").description("Tracked prompts in a category");addPageOptions(withCategory(prompts.command("list",{isDefault:true})).description("List prompts").option("--topic <topic>","only this topic (id, slug, or title)").option("--tag <tags>","only prompts with any of these tags (ids or names)",collect2).option("--tracking-type <type>","visibility | branded_own | all (default all)")).action(async(opts,cmd)=>{const scope=await categoryScope(cmd);const page=await fetchPages(scope.client,chatPath(...scope.base,"prompts"),{topic:opts.topic?await resolveTopicId(scope,opts.topic):void 0,tag:opts.tag?.length?await resolveTagIds(scope,opts.tag):void 0,trackingType:opts.trackingType},opts);printPage(page,resolveOutput(cmd),p=>({id:p.id,topic:p.topicId,type:p.trackingType,tags:p.tagIds.join(","),firstAnswer:p.firstAnswerDay,text:truncate(p.text,70)}))});withCategory(prompts.command("add [texts...]")).description("Add prompts from arguments or --file (one per line, JSON Lines, or a JSON array); existing texts report already_exists").option("--topic <topic>","topic for items without their own (id, slug, or title)").option("-f, --file <path>","read prompts from a file ('-' for stdin)").option("--tag <tags>","tags for every prompt (ids or names; repeatable)",collect2).option("--tracking-type <type>","visibility (default) | branded_own, for items without their own").option("--dry-run","report what would be created without creating").addHelpText("after",`
|
|
13
|
+
Items in a file may be strings or objects:
|
|
14
|
+
{"text": "...", "topicId": "top_1\u2026", "trackingType": "visibility", "tagIds": ["tag_1\u2026"]}
|
|
15
|
+
Inputs over ${CHAT_BATCH_SIZE} prompts are sent in chunks after a dry run of every chunk.
|
|
16
|
+
Each item reports created, already_exists, or would_create (with --dry-run).`).action(async(texts,opts,cmd)=>{const raw=[...texts.map(text=>({text})),...opts.file?parsePromptInput(readSource(opts.file)):[]];if(!raw.length)throw new CliError("usage","no prompts given; pass them as arguments or with --file");const scope=await categoryScope(cmd);const resolved=await resolvePrompts(scope,raw,{topic:opts.topic,trackingType:opts.trackingType,tags:opts.tag??[]});const result=await addPrompts(scope,resolved,opts.dryRun??false,partial=>printOutcome(partial,cmd));printOutcome(result,cmd)});withCategory(prompts.command("move [prompts...]")).description("Move prompts to another topic (ids as arguments or --file), in batches of 500").requiredOption("--topic <topic>","destination topic (id, slug, or title)").option("-f, --file <path>","read prompt ids from a file ('-' for stdin)").action(async(args,opts,cmd)=>{const ids=readIds(args,opts.file);const scope=await categoryScope(cmd);const topicId=await resolveTopicId(scope,opts.topic);const updated=[];const notFound=[];for(const batch of chunks(ids)){const res=await scope.client.patch(chatPath(...scope.base,"prompts"),{ids:batch,topicId});updated.push(...res.updated);notFound.push(...res.notFound)}if(resolveOutput(cmd)==="json")return printJson({updated,notFound,topicId});console.log(`Moved ${updated.length} prompt(s) to ${topicId}${notFound.length?`; not found: ${notFound.join(", ")}`:""}`)});for(const[name,method,verb]of[["tag","post","Tagged"],["untag","delete","Untagged"]])withCategory(prompts.command(`${name} [prompts...]`)).description(`${name==="tag"?"Apply":"Remove"} tags ${name==="tag"?"to":"from"} prompts (ids as arguments or --file)`).requiredOption("--tag <tags>","tag ids or names (comma-separated or repeatable)",collect2).option("-f, --file <path>","read prompt ids from a file ('-' for stdin)").action(async(args,opts,cmd)=>{const ids=readIds(args,opts.file);const scope=await categoryScope(cmd);const tagIds=await resolveTagIds(scope,opts.tag);const path=chatPath(...scope.base,"prompts","tags");const promptIds=[];for(const batch of chunks(ids)){const body={promptIds:batch,tagIds};const res=method==="post"?await scope.client.post(path,body):await scope.client.delete(path,void 0,body);promptIds.push(...res.promptIds)}if(resolveOutput(cmd)==="json")return printJson({promptIds,tagIds});console.log(`${verb} ${promptIds.length} prompt(s) with ${tagIds.join(", ")}`)})}import{Option as Option2}from"commander";var query_exports={};__export(query_exports,{noteFreshness:()=>noteFreshness,parseOrderBy:()=>parseOrderBy,pct:()=>pct,readStdin:()=>readStdin2,register:()=>register5});import{join as join4}from"path";var dimension=(sql,description,type="string")=>({sql,description,type});var metric=(sql,description,type="number")=>({sql,description,type});var common={run:dimension("s.id","Session ID"),batch:dimension("s.batch_id","Launch batch ID"),eval:dimension("CASE WHEN s.measurement_kind = 'eval' THEN s.measurement_id END","Saved eval ID"),preference:dimension("CASE WHEN s.measurement_kind = 'preference' THEN s.measurement_id END","Saved preference prompt ID"),measurement_revision:dimension("s.measurement_revision","Frozen measurement revision","number"),agent:dimension("s.agent","Coding agent"),model:dimension("s.model","Agent model"),date:dimension("date(s.created_at)","Session creation date (UTC)","date")};var catalogs=[{name:"runs",grain:"One local session (current attempt)",from:"sessions s",dimensions:{...common,case:dimension("s.case_path","File-based case path, when applicable"),outcome:dimension("s.outcome","Execution outcome; this is not an eval verdict"),analyzed:dimension("s.current_analysis_id IS NOT NULL","Whether this attempt has published analysis","boolean"),analysis_id:dimension("s.current_analysis_id","Current published analysis ID")},metrics:{run_count:metric("COUNT(*)","Number of sessions"),analyzed_runs:metric("COALESCE(SUM(CASE WHEN s.current_analysis_id IS NOT NULL THEN 1 ELSE 0 END),0)","Sessions with published analysis"),avg_turns:metric("AVG(s.turns)","Average recorded turns; unknown values excluded"),avg_duration_ms:metric("AVG(s.duration_ms)","Average recorded duration in milliseconds; unknown values excluded"),input_tokens:metric("SUM(s.input_tokens)","Recorded input tokens; null when none have been recorded"),output_tokens:metric("SUM(s.output_tokens)","Recorded output tokens; null when none have been recorded")}},{name:"findings",grain:"One finding in a session's current published analysis",from:"sessions s JOIN session_analyses a ON a.id = s.current_analysis_id JOIN session_findings f ON f.analysis_id = a.id",dimensions:{...common,analysis_id:dimension("a.id","Current published analysis ID"),kind:dimension("f.kind","FRICTION, OBJECTION, or OPPORTUNITY"),subject:dimension("f.subject","Product or surface discussed"),label:dimension("f.label","Finding title; matching labels do not imply a shared theme"),basis:dimension("f.basis","OBSERVED, AGENT_CLAIM, or INFERRED"),effect:dimension("f.effect","Effect on the session"),cause:dimension("f.cause","Attributed cause")},metrics:{finding_count:metric("COUNT(*)","Findings in current published analyses"),affected_runs:metric("COUNT(DISTINCT s.id)","Distinct sessions with matching findings")}}];function localQueryMetadata(){return{datasets:catalogs.map(catalog=>({name:catalog.name,grain:catalog.grain,dimensions:Object.entries(catalog.dimensions).map(([name,field])=>({name,type:field.type,description:field.description})),metrics:Object.entries(catalog.metrics).map(([name,field])=>({name,type:field.type,description:field.description}))}))}}function queryLocal(gaugeDir,input){const compiled=compileLocalQuery(input);const store=openLocalStore(gaugeDir);store.db.exec("BEGIN");try{if(compiled.catalog.name==="findings"){const versions=store.db.prepare(compiled.findingVersionsSql).all(...compiled.coverageParams);const unsupported=versions.find(row2=>row2.schema_version!==ANALYSIS_SCHEMA_VERSION);if(unsupported)throw new CliError("usage",`A selected session's analysis uses schema version ${unsupported.schema_version}; this CLI supports ${ANALYSIS_SCHEMA_VERSION}. Upgrade Gauge before querying these findings. Your data is intact.`)}const rows=store.db.prepare(compiled.sql).all(...compiled.params);for(const row2 of rows)for(const name of compiled.dimensions){if(compiled.catalog.dimensions[name].type==="boolean"&&row2[name]!==null)row2[name]=Boolean(row2[name])}const coverage=store.db.prepare(compiled.coverageSql).get(...compiled.coverageParams);const response={columns:[...compiled.dimensions.map(key=>({key,kind:"dimension"})),...compiled.metrics.map(key=>({key,kind:"metric"}))],rows,...input.explain?{sql:compiled.sql}:{},freshness:{available:true,pending:0,watermark:coverage.watermark},analysisCoverage:{sessions:Number(coverage.total),analyzedSessions:Number(coverage.analyzed),unanalyzedSessions:Number(coverage.total)-Number(coverage.analyzed)}};store.db.exec("COMMIT");return response}catch(error){store.db.exec("ROLLBACK");throw error}finally{store.close()}}function compileLocalQuery(input){if(!input||typeof input!=="object"||Array.isArray(input))throw new CliError("usage","A query must be a JSON object.");const topKeys=new Set(["dataset","dimensions","metrics","filters","where","dateRange","orderBy","limit","granularity","explain"]);for(const key of Object.keys(input))if(!topKeys.has(key))throw new CliError("usage",`Unknown local query option "${key}". See gauge query fields --local --dataset runs.`);const name=input.dataset??"runs";const catalog=catalogs.find(item=>item.name===name);if(!catalog)throw new CliError("usage",`Dataset "${name}" is not available for local runs. Available: runs, findings.`,{hint:"Run `gauge query datasets --local` to see available datasets, or use --hosted to query runs on Gauge."});const dimensions=input.dimensions??[];const metrics=input.metrics;if(!Array.isArray(dimensions)||dimensions.some(key=>typeof key!=="string"))throw new CliError("usage","Query dimensions must be an array of field names.");if(!Array.isArray(metrics)||metrics.length===0||metrics.some(key=>typeof key!=="string"))throw new CliError("usage","At least one metric is required.");if(new Set([...dimensions,...metrics]).size!==dimensions.length+metrics.length)throw new CliError("usage","Select each query field only once.");const unsupported=(kind,field)=>{throw new CliError("usage",`${kind} "${field}" is not supported by the local ${name} dataset.`,{hint:`Run \`gauge query fields --dataset ${name} --local\` to see which fields you can query for local runs.`})};const granularity=input.granularity??"day";if(!["day","week","month"].includes(granularity))throw new CliError("usage","Granularity must be day, week, or month.");const dateSql=granularity==="month"?"date(s.created_at,'start of month')":granularity==="week"?"date(s.created_at,'-' || ((CAST(strftime('%w',s.created_at) AS INTEGER) + 6) % 7) || ' days')":"date(s.created_at)";const expr=key=>key==="date"?dateSql:Object.hasOwn(catalog.dimensions,key)?catalog.dimensions[key].sql:unsupported("Dimension",key);for(const key of dimensions)expr(key);for(const key of metrics)if(!Object.hasOwn(catalog.metrics,key))unsupported("Metric",key);const limit=input.limit??50;if(!Number.isInteger(limit)||limit<1||limit>1e3)throw new CliError("usage","Query limit must be an integer from 1 to 1000.");const params=[];const predicates=[];const coveragePredicates=[];const coverageParams=[];const bind=value=>{if(typeof value!=="string"&&typeof value!=="boolean"&&(typeof value!=="number"||!Number.isFinite(value)))throw new CliError("usage","Query filter values must be strings, booleans, or finite numbers.");params.push(typeof value==="boolean"?Number(value):value);return"?"};const where=input.where??[];if(!Array.isArray(where))throw new CliError("usage","Query where must be an array of predicates.");for(const clause of where){const paramStart=params.length;const predicateStart=predicates.length;if(!clause||typeof clause!=="object"||Object.keys(clause).some(key=>!["dimension","op","value"].includes(key)))throw new CliError("usage","Each where predicate requires dimension, op, and value.");const sql2=expr(clause.dimension);if(clause.op==="in"||clause.op==="notIn"){if(!Array.isArray(clause.value)||clause.value.length===0)throw new CliError("usage",`${clause.op} requires a nonempty value array.`);predicates.push(`${sql2} ${clause.op==="in"?"IN":"NOT IN"} (${clause.value.map(bind).join(",")})`)}else{if(Array.isArray(clause.value))throw new CliError("usage",`${clause.op} requires a scalar value.`);if(clause.op==="contains"){if(typeof clause.value!=="string")throw new CliError("usage","contains requires a string value.");predicates.push(`instr(lower(CAST(${sql2} AS TEXT)),lower(${bind(clause.value)})) > 0`)}else{const operators={eq:"=",neq:"!=",gt:">",gte:">=",lt:"<",lte:"<="};const op=operators[clause.op];if(!op)throw new CliError("usage",`Unsupported filter operator "${clause.op}".`);let value=clause.value;if(catalog.dimensions[clause.dimension].type==="number"&&typeof value==="string"&&value.trim()&&Number.isFinite(Number(value)))value=Number(value);if(catalog.dimensions[clause.dimension].type==="boolean"&&typeof value==="string"&&["true","false"].includes(value))value=value==="true";predicates.push(`${sql2} ${op} ${bind(value)}`)}}if(Object.hasOwn(common,clause.dimension)||name==="runs"){coveragePredicates.push(...predicates.slice(predicateStart));coverageParams.push(...params.slice(paramStart))}}const filterParamStart=params.length;const filterPredicateStart=predicates.length;const filters=input.filters??{};if(!filters||typeof filters!=="object"||Array.isArray(filters))throw new CliError("usage","Query filters must be an object.");const supportedFilters={agent:"s.agent",model:"s.model",prompt:"s.measurement_id",eval:"CASE WHEN s.measurement_kind = 'eval' THEN s.measurement_id END",visibilityPrompt:"CASE WHEN s.measurement_kind = 'preference' THEN s.measurement_id END"};for(const[key,value]of Object.entries(filters)){if(value===void 0)continue;if(!Object.hasOwn(supportedFilters,key))unsupported("Filter",key);const values=key==="prompt"?[value]:value;if(!Array.isArray(values)||values.length===0||values.some(item=>typeof item!=="string"))throw new CliError("usage",`Filter ${key} requires ${key==="prompt"?"a string":"a nonempty array of strings"}.`);predicates.push(`${supportedFilters[key]} IN (${values.map(bind).join(",")})`)}const range=input.dateRange;if(range!==void 0){if(!range||typeof range!=="object"||Array.isArray(range))throw new CliError("usage","Query dateRange must be an object.");for(const key of Object.keys(range))if(!["since","until","lastDays"].includes(key))throw new CliError("usage",`Unknown dateRange field ${key}.`);if(range.since!==void 0&&range.lastDays!==void 0)throw new CliError("usage","Use dateRange.since or dateRange.lastDays, not both.");if(range.lastDays!==void 0&&(!Number.isInteger(range.lastDays)||range.lastDays<=0))throw new CliError("usage","lastDays must be a positive integer.");const since=range.since!==void 0?dateValue(range.since):range.lastDays!==void 0?new Date(Date.now()-range.lastDays*864e5).toISOString():null;const until=range.until!==void 0?dateValue(range.until):null;if(since&&until&&since>until)throw new CliError("usage","Query since must be before until.");if(since)predicates.push(`julianday(s.created_at) >= julianday(${bind(since)})`);if(until)predicates.push(`julianday(s.created_at) <= julianday(${bind(until)})`)}coveragePredicates.push(...predicates.slice(filterPredicateStart));coverageParams.push(...params.slice(filterParamStart));const selected=new Set([...dimensions,...metrics]);const order=input.orderBy??[];if(!Array.isArray(order))throw new CliError("usage","Query orderBy must be an array.");for(const item of order){if(!item||!selected.has(item.key))throw new CliError("usage",`Order field "${item?.key}" must be one of the selected dimensions or metrics.`);if(item.dir!==void 0&&item.dir!=="asc"&&item.dir!=="desc")throw new CliError("usage","Order direction must be asc or desc.")}const columns=[...dimensions.map(key=>`${expr(key)} AS "${key}"`),...metrics.map(key=>`${catalog.metrics[key].sql} AS "${key}"`)];const sql=`SELECT ${columns.join(", ")} FROM ${catalog.from}${predicates.length?` WHERE ${predicates.map(predicate=>`(${predicate})`).join(" AND ")}`:""}${dimensions.length?` GROUP BY ${dimensions.map(expr).join(", ")}`:""}${order.length?` ORDER BY ${order.map(item=>`"${item.key}" ${(item.dir??"desc").toUpperCase()}`).join(", ")}`:""} LIMIT ${limit}`;const coverageWhere=coveragePredicates.length?` WHERE ${coveragePredicates.map(predicate=>`(${predicate})`).join(" AND ")}`:"";const coverageSql=`SELECT COUNT(*) AS total,COUNT(current_analysis_id) AS analyzed,MAX(COALESCE(ended_at,created_at)) AS watermark FROM sessions s${coverageWhere}`;const findingVersionsSql=`SELECT DISTINCT a.schema_version FROM sessions s JOIN session_analyses a ON a.id = s.current_analysis_id${coverageWhere}`;return{sql,params,coverageSql,coverageParams,findingVersionsSql,catalog,dimensions,metrics}}function dateValue(value){if(typeof value!=="string")throw new CliError("usage","Date bounds must be ISO dates or relative windows such as 24h or 7d.");const match=/^(\d+)([mhd])$/.exec(value.trim());const date=match?new Date(Date.now()-Number(match[1])*({m:6e4,h:36e5,d:864e5}[match[2]]??0)):new Date(value);if(!Number.isFinite(date.getTime()))throw new CliError("usage",`Invalid date bound "${value}".`);return date.toISOString()}import{createReadStream,existsSync,realpathSync}from"fs";import{isAbsolute,join,relative}from"path";import{createInterface as createInterface2}from"readline";async function searchLocalTranscripts(gaugeDir,text,options={}){if(!text.trim())throw new CliError("usage","Transcript search requires nonempty text.");if(options.eval&&options.preference)throw new CliError("usage","Select either --eval or --preference for transcript search.");const limit=options.limit??50;if(!Number.isInteger(limit)||limit<1||limit>1e3)throw new CliError("usage","Search limit must be an integer from 1 to 1000.");const store=openLocalStore(gaugeDir);const sessions=(()=>{try{return store.listSessions({measurementId:options.eval??options.preference,measurementKind:options.eval?"eval":options.preference?"preference":void 0,batchId:options.batch}).filter(session=>!options.since||Date.parse(session.createdAt)>=options.since.getTime())}finally{store.close()}})();const result={matches:[],selectedSessions:sessions.length,scannedSessions:0,missingArtifacts:[],truncated:false};const needle=text.toLowerCase();for(const session of sessions){if(!/^[A-Za-z0-9_-]+$/.test(session.id))throw new CliError("usage",`Invalid local run ID: ${session.id}`);const attemptDir=join(gaugeDir,"runs",session.id,"attempts",String(session.attempt));const path=join(attemptDir,"session","events.ndjson");if(!existsSync(path)){result.missingArtifacts.push(session.id);continue}const rel=relative(realpathSync(attemptDir),realpathSync(path));if(isAbsolute(rel)||rel===".."||rel.startsWith("../")||rel.startsWith("..\\"))throw new CliError("usage",`Run ${session.id} transcript resolves outside its attempt.`);result.scannedSessions++;const stream=createReadStream(path,{encoding:"utf8"});const lines=createInterface2({input:stream,crlfDelay:Infinity});let lineNumber=0;try{for await(const line of lines){lineNumber++;let event;try{event=JSON.parse(line)}catch{continue}if(!event||typeof event!=="object")continue;const content=typeof event.payload==="string"?event.payload:JSON.stringify(event.payload??event);const index=content.toLowerCase().indexOf(needle);if(index<0)continue;if(result.matches.length===limit){result.truncated=true;return result}const start=Math.max(0,index-100);const end=Math.min(content.length,Math.max(index+needle.length+200,start+400));result.matches.push({run:session.id,attempt:session.attempt,turn:typeof event.turn==="number"?event.turn:null,artifact:"session/events.ndjson",line:lineNumber,snippet:`${start?"\u2026":""}${content.slice(start,end)}${end<content.length?"\u2026":""}`})}}finally{lines.close();stream.destroy()}}return result}import{createHash as createHash2,randomUUID as randomUUID2}from"crypto";import{existsSync as existsSync2,readFileSync as readFileSync2,realpathSync as realpathSync2,statSync}from"fs";import{isAbsolute as isAbsolute2,join as join2,relative as relative2,resolve}from"path";function saveLocalAnalysis(gaugeDir,runId,value){if(typeof value==="object"&&value!==null&&"schemaVersion"in value&&value.schemaVersion!==ANALYSIS_SCHEMA_VERSION){throw new CliError("usage",`Analysis schema version ${String(value.schemaVersion)} is not supported. This CLI accepts version ${ANALYSIS_SCHEMA_VERSION}; upgrade Gauge for newer analyses. No data was changed.`)}const parsed=analysisSubmissionSchema.safeParse(value);if(!parsed.success)throw new CliError("usage",`Invalid analysis: ${parsed.error.issues.map(issue=>`${issue.path.join(".")||"analysis"}: ${issue.message}`).join("; ")}`,{hint:"Use gauge run analysis schema for the analysis submission contract."});const submission=parsed.data;const store=openLocalStore(gaugeDir);try{const session=store.getSession(runId);if(!session)throw new CliError("usage",`Local run ${runId} was not found.`,{hint:"Use gauge run list --local, or repair session summaries if its artifacts exist."});if(!["completed","failed","canceled","interrupted"].includes(session.outcome))throw new CliError("usage",`Run ${runId} is ${session.outcome}. Wait until it finishes before publishing analysis.`);if(session.attempt!==submission.attempt)throw new CliError("usage",`Run ${runId} is on attempt ${session.attempt}; the submitted analysis targets attempt ${submission.attempt}.`);validateCriteria(session,submission);const attemptDirectory=safeAttemptDirectory(gaugeDir,runId,submission.attempt);const files=new Map;const refs=[...submission.findings.flatMap(finding=>finding.evidence),...submission.products.flatMap(product=>Object.values(product.evidence).flat()),...submission.criteria.flatMap(criterion=>criterion.evidence)];for(const ref of refs)validateEvidence(attemptDirectory,submission.attempt,ref,files);const hash=createHash2("sha256");for(const[path,contents]of[...files].sort(([a],[b])=>a.localeCompare(b)))hash.update(path).update("\0").update(contents).update("\0");const evidenceDigest=`sha256:${hash.digest("hex")}`;return store.transaction(()=>{const currentSession=store.getSession(runId);if(currentSession.attempt!==submission.attempt)throw new CliError("usage","The run advanced to another attempt while validating analysis. Read its new evidence before publishing.");const latest=store.db.prepare("SELECT MAX(revision) AS revision FROM session_analyses WHERE run_id = ?").get(runId);const analysis={...submission,id:`a_${randomUUID2()}`,runId,revision:Number(latest?.revision??0)+1,createdAt:new Date().toISOString(),evidenceDigest,findings:submission.findings.map(finding=>({...finding,id:`f_${randomUUID2()}`}))};store.db.prepare("INSERT INTO session_analyses VALUES (?,?,?,?,?,?,?,?,?)").run(analysis.id,runId,analysis.attempt,analysis.revision,analysis.schemaVersion,analysis.instructionsVersion,evidenceDigest,JSON.stringify(analysis),analysis.createdAt);const findingStatement=store.db.prepare("INSERT INTO session_findings VALUES (?,?,?,?,?,?,?,?,?,?,?)");for(const finding of analysis.findings)findingStatement.run(finding.id,analysis.id,finding.kind,finding.subject,finding.label,finding.detail,finding.basis,finding.effect,finding.cause,JSON.stringify(finding.tags),JSON.stringify(finding.evidence));const productStatement=store.db.prepare("INSERT INTO session_products VALUES (?,?,?,?)");analysis.products.forEach((product,position)=>productStatement.run(analysis.id,position,product.name,JSON.stringify(product)));const criterionStatement=store.db.prepare("INSERT INTO criterion_results VALUES (?,?,?,?,?)");for(const criterion of analysis.criteria)criterionStatement.run(analysis.id,criterion.criterionId,criterion.outcome,criterion.label,JSON.stringify(criterion.evidence));store.db.prepare("UPDATE sessions SET current_analysis_id = ? WHERE id = ?").run(analysis.id,runId);return analysis})}finally{store.close()}}function getLocalAnalysis(gaugeDir,runId){const store=openLocalStore(gaugeDir);try{return readCurrentAnalysis(store,runId)}finally{store.close()}}function readCurrentAnalysis(store,runId){const row2=store.db.prepare("SELECT a.schema_version,a.payload FROM session_analyses a JOIN sessions s ON s.current_analysis_id = a.id WHERE s.id = ?").get(runId);if(!row2)return null;if(row2.schema_version!==ANALYSIS_SCHEMA_VERSION)throw new CliError("usage",`Stored analysis uses schema version ${row2.schema_version}; upgrade Gauge to read it. Your data is intact.`);return JSON.parse(String(row2.payload))}function validateCriteria(session,submission){const configuration=session.configuration??{};const item=configuration.case;const criteria=item?.criteria??configuration.criteria??[];if(!Array.isArray(criteria))throw new CliError("usage","This run's frozen criteria are invalid; repair its session summary before analysis.");const expected=criteria.map(criterion=>{if(!criterion||typeof criterion.id!=="string"||!criterion.id)throw new CliError("usage","This run has a frozen criterion without an ID. Criterion IDs must be assigned before execution.");return criterion.id});const supplied=new Set(submission.criteria.map(criterion=>criterion.criterionId));const missing=expected.filter(id=>!supplied.has(id));const extra=[...supplied].filter(id=>!expected.includes(id));if(missing.length||extra.length)throw new CliError("usage",`Analysis must cover exactly the run's frozen criteria.${missing.length?` Missing: ${missing.join(", ")}.`:""}${extra.length?` Unknown: ${extra.join(", ")}.`:""} Use UNASSESSABLE with an explanation when evidence is insufficient.`)}function safeAttemptDirectory(gaugeDir,runId,attempt){if(!/^[A-Za-z0-9_-]+$/.test(runId))throw new CliError("usage","Invalid local run ID.");const directory=join2(gaugeDir,"runs",runId,"attempts",String(attempt));if(!existsSync2(directory))throw new CliError("usage",`Run evidence is missing: ${directory}`);return realpathSync2(directory)}function readEvidence(directory,path,files){const fullPath=resolve(directory,path);if(!isInside(directory,fullPath))throw new CliError("usage",`Evidence path ${path} leaves the run's attempt directory.`);if(!existsSync2(fullPath)||!statSync(fullPath).isFile())throw new CliError("usage",`Evidence artifact ${path} does not exist in this attempt.`);if(!isInside(directory,realpathSync2(fullPath)))throw new CliError("usage",`Evidence artifact ${path} resolves outside this attempt.`);const contents=files.get(path)??readFileSync2(fullPath,"utf8");files.set(path,contents);return contents}function isInside(directory,path){const rel=relative2(directory,path);return rel!==".."&&!rel.startsWith(`..${process.platform==="win32"?"\\":"/"}`)&&!isAbsolute2(rel)}function validateEvidence(directory,attempt,ref,files){if(ref.kind==="diff"){const diff2=readEvidence(directory,"session/diff.patch",files);const paths=new Set(diff2.split("\n").flatMap(line=>{const match=/^(?:\+\+\+|---) [ab]\/(.*)$/.exec(line);return match?[match[1].split(" ")[0]]:[]}));if(!paths.has(ref.path))throw new CliError("usage",`Diff evidence path ${ref.path} does not appear in this attempt's diff.patch.`);return}if(ref.kind==="artifact"&&ref.attempt!==void 0&&ref.attempt!==attempt)throw new CliError("usage",`Evidence references attempt ${ref.attempt}, but this analysis targets attempt ${attempt}.`);const artifact=ref.kind==="trace"?"session/events.ndjson":ref.artifact;const contents=readEvidence(directory,artifact,files);const lines=contents.split(/\r?\n/);if(lines.at(-1)==="")lines.pop();if(ref.kind==="artifact"&&ref.line!==void 0&&(ref.line>lines.length||(ref.endLine??ref.line)>lines.length))throw new CliError("usage",`Evidence ${artifact}:${ref.line}${ref.endLine?`-${ref.endLine}`:""} exceeds the artifact's ${lines.length} lines.`);if(ref.seq!==void 0){const hasSequence=lines.some(line=>{try{return JSON.parse(line).seq===ref.seq}catch{return false}});if(!hasSequence)throw new CliError("usage",`Evidence sequence ${ref.seq} does not exist in ${artifact}. Copy an event's recorded seq; do not use its array index or turn.`,{hint:`For evidence without seq, cite an original artifact line, for example ${JSON.stringify({kind:"artifact",artifact,attempt,line:1})}. Line numbers start at 1; choose the line containing your evidence.`})}}function renderLocalAnalysisMarkdown(analysis){const lines=[`# Session analysis: ${analysis.runId}`,"",`Analysis ${analysis.id}, revision ${analysis.revision}; attempt ${analysis.attempt}.`,`Assessment: ${analysis.assessability}.`,""];if(analysis.limitation)lines.push(`Limitation: ${analysis.limitation}`,"");for(const finding of analysis.findings)lines.push(`## ${finding.kind}: ${finding.label}`,"",`${finding.subject} \xB7 ${finding.effect} \xB7 ${finding.basis}`,"",finding.detail,"",`Evidence: ${finding.evidence.map(formatEvidence).join(", ")}`,"");if(!analysis.findings.length)lines.push("No findings were reported in this analysis.","");if(analysis.criteria.length){lines.push("## Criteria","");for(const criterion of analysis.criteria)lines.push(`- ${criterion.criterionId}: ${criterion.outcome} \u2014 ${criterion.label}`);lines.push("")}if(analysis.products.length){lines.push("## Products","");for(const product of analysis.products)lines.push(`- ${product.name}: ${product.chosen?"chosen":product.rejected?"rejected":product.considered?"considered":"mentioned"} \u2014 ${product.reason}`);lines.push("")}return lines.join("\n")}function formatEvidence(ref){if(ref.kind==="trace")return`trace ${ref.seq}`;if(ref.kind==="diff")return`diff ${ref.path}`;return`${ref.artifact}${ref.line!==void 0?`:${ref.line}${ref.endLine!==void 0?`-${ref.endLine}`:""}`:` seq ${ref.seq}`}`}import{join as join3}from"path";function listLocalRuns(gaugeDir,filter={}){const store=openLocalStore(gaugeDir);try{return store.listSessions().map(session=>({...session,evalId:session.measurementKind==="eval"?session.measurementId??null:null,preferenceId:session.measurementKind==="preference"?session.measurementId??null:null,endedBy:session.endedBy??"",endedAt:session.endedAt??"",attemptDir:join3(gaugeDir,"runs",session.id,"attempts",String(session.attempt)),resultsDir:join3(gaugeDir,"runs",session.id,"results")})).filter(run=>matches(run,filter)).map(run=>{const analysis=readCurrentAnalysis(store,run.id);if(!analysis)return run;const session=store.getSession(run.id);const item=session.configuration?.case;const names=new Map((item?.criteria??[]).map(criterion=>[criterion.id,criterion.name]));return{...run,criterionResults:analysis.criteria.map(criterion=>({id:criterion.criterionId,name:names.get(criterion.criterionId)??criterion.criterionId,outcome:criterion.outcome}))}})}finally{store.close()}}function matches(run,filter){return(!filter.ids?.length||filter.ids.includes(run.id))&&(!filter.batch||run.batchId===filter.batch)&&(!filter.evalId||run.evalId===filter.evalId)&&(!filter.preferenceId||run.preferenceId===filter.preferenceId)&&(filter.measurementRevision===void 0||run.measurementRevision===filter.measurementRevision)&&(!filter.agent||run.agent===filter.agent)&&(!filter.model||run.model===filter.model)&&(!filter.outcome||filter.outcome.split(",").includes(run.outcome))&&(!filter.since||Date.parse(run.createdAt??run.endedAt)>=filter.since.getTime())&&(!filter.until||Date.parse(run.createdAt??run.endedAt)<=filter.until.getTime())&&(!filter.case||run.case===filter.case)&&(filter.analyzed===void 0||run.analyzed===filter.analyzed)}var UNIT_MS={m:6e4,h:36e5,d:864e5};function parseSince(window,now=Date.now(),flag="--since"){const relative7=/^(\d+)([mhd])$/.exec(window.trim());if(relative7)return new Date(now-Number(relative7[1])*UNIT_MS[relative7[2]]);const at=Date.parse(window);if(Number.isNaN(at))throw new CliError("usage",`invalid ${flag} "${window}" (expected 24h, 7d, or an ISO date)`);return new Date(at)}var collect3=(value,prev=[])=>[...prev,value];var csv2=raw=>raw.split(",").map(s=>s.trim()).filter(Boolean);function parseWhere(expr){const inMatch=expr.match(/^\s*(\w+)\s+(in|contains)\s+(.*)$/i);if(inMatch){const[,dimension3,opRaw,rest2]=inMatch;const op=opRaw.toLowerCase();if(op==="in"){return{dimension:dimension3,op:"in",value:csv2(rest2)}}return{dimension:dimension3,op:"contains",value:rest2.trim()}}const opMatch=expr.match(/^\s*(\w+)\s*(!=|>=|<=|=|>|<)\s*(.*)$/);if(!opMatch){throw new CliError("usage",`Could not parse --where "${expr}". Use e.g. "action=install", "ecosystem in npm,pypi", or "name contains supa".`)}const[,dimension2,sym,rest]=opMatch;const opFor={"=":"eq","!=":"neq",">":"gt",">=":"gte","<":"lt","<=":"lte"};return{dimension:dimension2,op:opFor[sym],value:rest.trim()}}function parseOrderBy(raw){const[key,dir]=raw.split(":");if(!key.trim()||dir!==void 0&&!["asc","desc"].includes(dir.trim())||raw.split(":").length>2)throw new CliError("usage",`Invalid --order-by "${raw}". Use a selected field followed by :asc or :desc.`);return{key:key.trim(),dir:dir?.trim()==="asc"?"asc":"desc"}}async function readStdin2(){const chunks2=[];for await(const chunk of process.stdin)chunks2.push(chunk);return Buffer.concat(chunks2).toString("utf8")}async function buildSpec(opts){let spec={metrics:[]};if(opts.json){const raw=opts.json==="-"?await readStdin2():opts.json;try{spec=JSON.parse(raw)}catch(e){throw new CliError("usage",`--json is not valid JSON: ${e.message}`)}}if(!spec||typeof spec!=="object"||Array.isArray(spec))throw new CliError("usage","--json must contain a query object.");if(opts.dataset)spec.dataset=opts.dataset;if(opts.dimensions!==void 0)spec.dimensions=csv2(opts.dimensions);if(opts.metrics!==void 0)spec.metrics=csv2(opts.metrics);if(opts.where?.length)spec.where=opts.where.map(parseWhere);if(opts.orderBy?.length)spec.orderBy=opts.orderBy.map(parseOrderBy);if(opts.limit!==void 0)spec.limit=Number(opts.limit);if(opts.granularity)spec.granularity=opts.granularity;if(opts.explain)spec.explain=true;const date={...spec.dateRange??{}};if(opts.since){date.since=opts.since;delete date.lastDays}else if(opts.lastDays){date.lastDays=Number(opts.lastDays);delete date.since}if(opts.until)date.until=opts.until;if(Object.keys(date).length)spec.dateRange=date;if(opts.branded&&opts.unbranded){throw new CliError("usage","Pass at most one of --branded / --unbranded.")}const filters={...spec.filters??{}};if(opts.prompt)filters.prompt=opts.prompt;if(opts.eval)filters.eval=csv2(opts.eval);if(opts.preference)filters.visibilityPrompt=csv2(opts.preference);if(opts.tag)filters.tag=csv2(opts.tag);if(opts.repo)filters.repo=csv2(opts.repo);if(opts.language)filters.language=csv2(opts.language);if(opts.framework)filters.framework=csv2(opts.framework);if(opts.size)filters.size=csv2(opts.size);if(opts.agent)filters.agent=csv2(opts.agent);if(opts.model)filters.model=csv2(opts.model);if(opts.scenario)filters.scenario=csv2(opts.scenario);if(opts.experiment)filters.experiment=csv2(opts.experiment);if(opts.branded)filters.branded=true;if(opts.unbranded)filters.branded=false;if(Object.keys(filters).length)spec.filters=filters;if(!spec.metrics||spec.metrics.length===0){throw new CliError("usage","At least one metric is required. Pass --metrics <a,b> (or a `metrics` array in --json). See `gauge query fields --dataset <name>`.")}return spec}var pct=n=>`${(n*100).toFixed(1)}%`;function noteFreshness(f){if(!f.available){console.error("warning: analytics store is temporarily unavailable; results may be incomplete.")}else if(f.pending>0){console.error(`note: ${f.pending} recent run(s) still ingesting; results may not reflect them yet.`)}}async function runQuery(command,opts){const output=resolveOutput(command);const spec=await buildSpec(opts);const state=gaugeState(command);const res=state.mode==="local"?queryLocal(localDirectory(command),spec):await createClient().post(`/api/v1/orgs/${encodeURIComponent(await resolveOrg(command))}/query`,spec);if(output==="json"){printJson(res);return}if(res.sql)console.error(`
|
|
17
|
+
${res.sql}
|
|
18
|
+
`);const rateKeys=new Set(res.columns.filter(c=>c.kind==="metric"&&c.key.endsWith("_rate")).map(c=>c.key));const rows=res.rows.map(row2=>{const out={};for(const col of res.columns){const v=row2[col.key];out[col.key]=rateKeys.has(col.key)&&typeof v==="number"?pct(v):v}return out});printItems(rows,"table",res.columns.map(c=>({key:c.key})));noteFreshness(res.freshness);if("analysisCoverage"in res&&res.analysisCoverage){const coverage=res.analysisCoverage;console.error(`Analysis coverage: ${coverage.analyzedSessions}/${coverage.sessions} selected sessions analyzed; ${coverage.unanalyzedSessions} unanalyzed.`)}}async function showMetadata(command,mode,dataset){const output=resolveOutput(command);const meta=gaugeState(command).mode==="local"?localQueryMetadata():await createClient().get(`/api/v1/orgs/${encodeURIComponent(await resolveOrg(command))}/query/metadata`);if(mode==="datasets"){if(output==="json")return printJson(meta.datasets.map(d=>({name:d.name,grain:d.grain})));printItems(meta.datasets.map(d=>({dataset:d.name,grain:d.grain})),"table");return}const ds=meta.datasets.find(d=>d.name===dataset);if(!ds){throw new CliError("usage",`Unknown dataset "${dataset}". Valid: ${meta.datasets.map(d=>d.name).join(", ")}.`)}if(output==="json")return printJson(ds);const rows=[...ds.dimensions.map(f=>({field:f.name,kind:"dimension",type:f.type,about:f.description??""})),...ds.metrics.map(f=>({field:f.name,kind:"metric",type:f.type,about:f.description??""}))];console.error(`dataset: ${ds.name} \u2014 ${ds.grain}`);printItems(rows,"table")}function register5(program2){const group=program2.command("query").description("Query local runs and findings or hosted analytics; discover backend capabilities");group.command("run",{isDefault:true}).description("Run a report; use query fields --dataset <name> with --local or --hosted to discover supported fields").option("--json <spec>","full query spec as JSON (or '-' to read stdin); flags override its keys").option("--dataset <name>","dataset name (local: runs | findings; use query datasets for hosted capabilities)").option("-d, --dimensions <names>","comma-separated GROUP BY dimensions").option("-m, --metrics <names>","comma-separated metrics (at least one)").option("--where <expr>",'predicate, e.g. "action=install" (repeatable)',collect3).option("--since <val>","date range start \u2014 ISO date or window (30d, 24h)").option("--until <val>","date range end \u2014 ISO date or window").option("--last-days <n>","shorthand for --since <n> days ago").option("--order-by <key:dir>","sort by a selected key, e.g. installs:desc (repeatable)",collect3).option("--limit <n>","max rows (default 50, max 1000)").option("--granularity <g>","date bucket: day | week | month (default day)").option("--explain","print the compiled SQL to stderr").option("--prompt <id>","filter to a single prompt").option("--eval <ids>","comma-separated saved eval IDs").option("--preference <ids>","comma-separated saved preference prompt IDs").option("--tag <ids>","comma-separated tag ids (hosted only)").option("--repo <urls>","comma-separated base repo urls (hosted only)").option("--language <langs>","comma-separated repo languages (hosted only)").option("--framework <names>","comma-separated repo frameworks (hosted only)").option("--size <buckets>","comma-separated codebase-size buckets (hosted only)").option("--agent <names>","comma-separated agent names").option("--model <models>","comma-separated models").option("--scenario <types>","comma-separated scenario types (greenfield|migration; hosted only)").option("--experiment <labels>","comma-separated experiment labels (hosted only)").option("--branded","only branded prompts (hosted only)").option("--unbranded","only non-branded prompts (hosted only)").action((opts,command)=>runQuery(command,opts));group.command("datasets").description("List the datasets you can query").action((_opts,command)=>showMetadata(command,"datasets"));group.command("fields").description("List the dimensions and metrics for a dataset").requiredOption("--dataset <name>","dataset to describe").action((opts,command)=>showMetadata(command,"fields",opts.dataset));group.command("search <text>").description("Search local transcript evidence without building an index").option("--eval <id>","filter to a saved eval").option("--preference <id>","filter to a saved preference prompt").option("--batch <id>","filter to one launch batch").option("--since <value>","session creation date or relative window, such as 7d").option("--limit <n>","maximum matching passages (default 50, maximum 1000)").action(async(text,opts,command)=>{if(gaugeState(command).mode!=="local")throw new CliError("usage","Transcript search is not supported by the hosted query backend. Use gauge run get <id> --logs --hosted to read a hosted transcript, or query search --local for local sessions.");const result=await searchLocalTranscripts(localDirectory(command),text,{...opts,since:opts.since?parseSince(opts.since):void 0,limit:opts.limit===void 0?void 0:Number(opts.limit)});if(resolveOutput(command)==="json"){printJson(result);return}printItems(result.matches.map(match=>({run:match.run,attempt:match.attempt,turn:match.turn,evidence:`${match.artifact}:${match.line}`,snippet:match.snippet})),"table");console.error(`Searched ${result.scannedSessions}/${result.selectedSessions} selected sessions.${result.truncated?" More matches exist; narrow the cohort or increase --limit.":""}${result.missingArtifacts.length?` Missing transcripts: ${result.missingArtifacts.join(", ")}.`:""}`)})}function localDirectory(command){const state=gaugeState(command);if(!state.root)throw new CliError("usage","No Gauge workspace found. Run gauge init --local in this directory first.");return join4(state.root,".gauge")}var CHAT_DATASETS=["answers","citations","searchQueries","aiTraffic"];var ORG_LEVEL_DATASETS=new Set(["aiTraffic"]);function parseChatWhere(expr){const list2=expr.match(/^\s*(\w+)\s+(not\s+in|in|contains)\s+(.*)$/i);if(list2){const[,dimension3,rawOp,rest2]=list2;const op=rawOp.toLowerCase().replace(/\s+/," ");if(op==="contains")return{dimension:dimension3,op:"contains",value:rest2.trim()};return{dimension:dimension3,op:op==="in"?"in":"notIn",value:csv(rest2)}}const cmp=expr.match(/^\s*(\w+)\s*(!=|=)\s*(.*)$/);if(!cmp)throw new CliError("usage",`Could not parse --where "${expr}". Use e.g. "domain=example.com", "model in gpt-5,claude", "domain not in a.com,b.com", or "query contains pricing".`);const[,dimension2,sym,rest]=cmp;return{dimension:dimension2,op:sym==="="?"eq":"neq",value:rest.trim()}}var collect4=(value,prev=[])=>[...prev,value];async function buildChatSpec(opts){let spec={};if(opts.json){const raw=opts.json==="-"?await readStdin2():opts.json;try{spec=JSON.parse(raw)}catch(e){throw new CliError("usage",`--json is not valid JSON: ${e.message}`)}if(!spec||typeof spec!=="object"||Array.isArray(spec))throw new CliError("usage","--json must contain a query object.")}if(opts.dataset)spec.dataset=opts.dataset;if(opts.dimensions!==void 0)spec.dimensions=csv(opts.dimensions);if(opts.metrics!==void 0)spec.metrics=csv(opts.metrics);if(opts.where?.length)spec.where=opts.where.map(parseChatWhere);if(opts.orderBy?.length)spec.orderBy=opts.orderBy.map(parseOrderBy);if(opts.limit!==void 0)spec.limit=Number(opts.limit);if(opts.granularity)spec.granularity=opts.granularity;if(opts.explain)spec.explain=true;const date={...spec.dateRange??{}};if(opts.since){date.since=opts.since;delete date.lastDays}else if(opts.lastDays){date.lastDays=Number(opts.lastDays);delete date.since}if(opts.until)date.until=opts.until;if(Object.keys(date).length)spec.dateRange=date;const filters={...spec.filters??{}};for(const key of["brand","model","topic","tag","prompt","domain","page"])if(opts[key])filters[key]=csv(opts[key]);if(opts.tagMode)filters.tagMode=opts.tagMode;if(opts.trackingType)filters.trackingType=opts.trackingType;if(Object.keys(filters).length)spec.filters=filters;if(!spec.dataset)throw new CliError("usage",`--dataset is required (${CHAT_DATASETS.join(", ")}). See \`gauge chat query datasets\`.`);if(!spec.metrics?.length)throw new CliError("usage",`At least one metric is required. Pass --metrics <a,b> (or a \`metrics\` array in --json). See \`gauge chat query fields --dataset ${spec.dataset}\`.`);return spec}function labelFor(labels,type,value){if(!type.startsWith("id:")||typeof value!=="string")return value;const label=labels[type.slice(3)]?.[value];const text=label?.name??label?.title??label?.text??label?.url;return typeof text==="string"?truncate(text,60):value}async function runQuery2(command,opts){const spec=await buildChatSpec(opts);const{client,org,chatOrg}=await chatScope(command);const{category}=command.optsWithGlobals();if(category)spec.filters={...spec.filters??{},category};else if(!ORG_LEVEL_DATASETS.has(spec.dataset)&&!spec.filters?.category)spec.filters={...spec.filters??{},category:await resolveChatCategory(command,client,chatOrg)};const res=await client.post(chatPath("orgs",org,"query"),spec);if(resolveOutput(command)==="json")return printJson(res);if(res.sql)console.error(`
|
|
19
|
+
${res.sql}
|
|
20
|
+
`);printItems(res.rows.map(row2=>{const out={};for(const col of res.columns){const v=row2[col.key];out[col.key]=col.kind==="dimension"?labelFor(res.labels,col.type,v):col.type==="rate"&&typeof v==="number"?pct(v):v}return out}),"table",res.columns.map(c=>({key:c.key})));console.error(`dateRange: ${res.dateRange.since} to ${res.dateRange.until}`);if(res.truncated)console.error("note: more rows exist; raise --limit or narrow the query.");noteFreshness(res.freshness)}async function metadata(command,dataset){const{client,org,chatOrg}=await chatScope(command);return client.get(chatPath("orgs",org,"query","metadata"),{dataset})}function registerQuery(chat){const group=chat.command("query").description("Query AI visibility data (answers, citations, searchQueries, aiTraffic)");withCategory(group.command("run",{isDefault:true})).description("Run a query; discover fields with `gauge chat query fields --dataset <name>`").option("--json <spec>","full query spec as JSON (or '-' to read stdin); flags override its keys").option("--dataset <name>",CHAT_DATASETS.join(" | ")).option("-d, --dimensions <names>","comma-separated GROUP BY dimensions").option("-m, --metrics <names>","comma-separated metrics (at least one)").option("--where <expr>",'predicate, e.g. "domain=example.com" or "model not in a,b" (repeatable)',collect4).option("--since <val>","date range start \u2014 YYYY-MM-DD or window (30d)").option("--until <val>","date range end \u2014 YYYY-MM-DD (inclusive)").option("--last-days <n>","shorthand for the last n days").option("--order-by <key:dir>","sort by a selected key, e.g. visibility:desc (repeatable)",collect4).option("--limit <n>","max rows (default 50, max 1000)").option("--granularity <g>","date bucket: hour (aiTraffic only, \u2264 14 days) | day | week | month (default day)").addOption(new Option2("--explain","print the compiled SQL to stderr").hideHelp()).option("--brand <ids>","comma-separated brd_ ids").option("--model <models>","comma-separated models").option("--topic <ids>","comma-separated top_ ids").option("--tag <ids>","comma-separated tag_ ids").option("--tag-mode <mode>","any (default) | all").option("--prompt <ids>","comma-separated prm_ ids").option("--tracking-type <type>","visibility (default) | branded_own | all").option("--domain <domains>","comma-separated cited domains").option("--page <ids>","comma-separated pag_ ids").addHelpText("after",`
|
|
21
|
+
Answer datasets (answers, citations, searchQueries) are scoped to a category:
|
|
22
|
+
--category, else the chatCategory default, else the org's only category.
|
|
23
|
+
aiTraffic is organization-level; with --granularity hour its date column holds
|
|
24
|
+
UTC timestamps (YYYY-MM-DDTHH:MM:SSZ) instead of days. Rate metrics are 0-1
|
|
25
|
+
fractions (shown as percentages in tables).`).action((opts,command)=>runQuery2(command,opts));group.command("datasets").description("List the datasets you can query").action(async(_opts,command)=>{const meta=await metadata(command);const rows=meta.datasets.map(d=>({name:d.name,grain:d.grain,requiresCategory:d.requiresCategory,description:d.description}));if(resolveOutput(command)==="json")return printJson(rows);printItems(rows.map(r=>({...r,description:truncate(r.description,70)})),"table")});group.command("fields").description("List the dimensions, metrics, filters and where columns for a dataset").requiredOption("--dataset <name>","dataset to describe").action(async(opts,command)=>{const meta=await metadata(command,opts.dataset);const ds=meta.datasets.find(d=>d.name===opts.dataset);if(!ds)throw new CliError("usage",`Unknown dataset "${opts.dataset}". Valid: ${CHAT_DATASETS.join(", ")}.`);if(resolveOutput(command)==="json")return printJson(ds);console.error(`dataset: ${ds.name} \u2014 ${ds.grain}. ${ds.description}`);printItems([...ds.dimensions.map(f=>({field:f.name,kind:"dimension",type:f.type,about:f.description??""})),...ds.metrics.map(f=>({field:f.name,kind:"metric",type:`${f.type}${f.unit?` (${f.unit})`:""}`,about:`${f.description??""}${f.requires?.length?` Needs ${f.requires.join(" or ")}.`:""}`})),...ds.where.map(w=>({field:w.name,kind:"where",type:w.ops.join("|"),about:w.description}))],"table");console.error(`filters: ${ds.filters.join(", ")||"(none)"}; granularities: ${ds.granularities.join(", ")}`)});group.command("metadata").description("Print the full query catalog with limits and this org's valid values (JSON)").option("--dataset <name>","only this dataset").action(async(opts,command)=>{printJson(await metadata(command,opts.dataset))})}function done(cmd,value,text){if(resolveOutput(cmd)==="json")printJson(value);else console.log(text)}function registerCategories(chat){const categories=chat.command("categories").description("Categories (markets) your organization tracks");categories.command("list",{isDefault:true}).description("List categories (* marks the chatCategory default)").action(async(_opts,cmd)=>{const{client,org,chatOrg}=await chatScope(cmd);const{data}=await client.get(chatPath("orgs",org,"categories"));const{chatCategory,chatCategoryOrg}=readConfig();const applies=chatCategoryOrg?chatCategoryOrg===org:chatOrg.source==="config";const isDefault=c=>applies&&(chatCategory===c.slug||chatCategory===c.id);if(resolveOutput(cmd)==="json")return printJson({data:data.map(c=>({...c,isDefault:isDefault(c)}))});printItems(data.map(c=>({default:isDefault(c)?"*":"",id:c.id,slug:c.slug,name:c.name})),"table")});categories.command("use <category>").description("Set the default category (slug or id) for the selected organization").action(async(category,_opts,cmd)=>{const{client,org,chatOrg}=await chatScope(cmd);const found=await client.get(chatPath("orgs",org,"categories",category));updateConfig({chatCategory:found.slug,chatCategoryOrg:org});done(cmd,{org,chatCategory:found.slug},`Default Chat category: ${found.slug} (org ${chatOrg.name??org})`)})}function registerTopics(chat){const topics=chat.command("topics").description("Topics group a category's prompts");addPageOptions(withCategory(topics.command("list",{isDefault:true}).description("List topics"))).action(async(opts,cmd)=>{const scope=await categoryScope(cmd);const page=await fetchPages(scope.client,chatPath(...scope.base,"topics"),{},opts);printPage(page,resolveOutput(cmd),t=>({id:t.id,title:t.title,slug:t.slug,prompts:t.promptCount}))});withCategory(topics.command("create <title>")).description("Create a topic; exits 0 with the existing topic when the title already exists (--if-exists)").option("--if-exists","return the existing topic instead of failing").action(async(title,opts,cmd)=>{const scope=await categoryScope(cmd);try{const topic=await scope.client.post(chatPath(...scope.base,"topics"),{title});done(cmd,topic,`Created topic ${topic.id} (${topic.title})`)}catch(error){const id=error instanceof CliError&&error.apiCode==="already_exists"?error.details?.id:void 0;if(!opts.ifExists||typeof id!=="string")throw error;const topic=await scope.client.get(chatPath(...scope.base,"topics",id));done(cmd,topic,`Topic already exists: ${topic.id} (${topic.title})`)}});withCategory(topics.command("rename <topic> <title>")).description("Rename a topic (id, slug, or title); its slug follows").action(async(topic,title,_opts,cmd)=>{const scope=await categoryScope(cmd);const id=await resolveTopicId(scope,topic);const updated=await scope.client.patch(chatPath(...scope.base,"topics",id),{title});done(cmd,updated,`Renamed topic ${updated.id} to ${updated.title}`)})}function registerTags(chat){const tags=chat.command("tags").description("Organization prompt tags");tags.command("list",{isDefault:true}).description("List tags").action(async(_opts,cmd)=>{const{client,org}=await chatScope(cmd);const page=await client.get(chatPath("orgs",org,"tags"));printPage(page,resolveOutput(cmd),t=>({id:t.id,name:t.name,color:t.color,prompts:t.promptCount}))});tags.command("create <name>").alias("add").description("Create a tag").option("--color <color>","tag color").action(async(name,opts,cmd)=>{const{client,org}=await chatScope(cmd);const tag=await client.post(chatPath("orgs",org,"tags"),{name,...opts.color?{color:opts.color}:{}});done(cmd,tag,`Created tag ${tag.id} (${tag.name})`)});tags.command("rename <tag> <name>").description("Rename a tag (id or current name)").option("--color <color>","also change the color").action(async(tag,name,opts,cmd)=>{const scope=await chatScope(cmd);const[id]=await resolveTagIds(scope,[tag]);const updated=await scope.client.patch(chatPath("orgs",scope.org,"tags",id),{name,...opts.color?{color:opts.color}:{}});done(cmd,updated,`Renamed tag ${updated.id} to ${updated.name}`)});tags.command("delete <tag>").alias("rm").description("Delete a tag (id or name); prompts are kept").action(async(tag,_opts,cmd)=>{const scope=await chatScope(cmd);const[id]=await resolveTagIds(scope,[tag]);await scope.client.delete(chatPath("orgs",scope.org,"tags",id));done(cmd,{id,deleted:true},`Deleted tag ${id}`)})}function registerBrands(chat){withCategory(chat.command("brands")).description("Owned and competitor brands tracked in the category").action(async(_opts,cmd)=>{const scope=await categoryScope(cmd);const page=await scope.client.get(chatPath(...scope.base,"brands"));printPage(page,resolveOutput(cmd),b=>({id:b.id,role:b.role,name:b.name,website:b.website}))})}var CHAT_ORG_HELP="organization slug or id (default: gauge.json orgId, then your saved default, else your only Chat org; an org API key implies its org)";function scopeGlobalOptions(program2,chat){const isAgentsOnly=option=>option.long==="--local"||option.long==="--hosted";chat.configureHelp({...program2.configureHelp(),visibleGlobalOptions(cmd){return Help.prototype.visibleGlobalOptions.call(this,cmd).filter(option=>!isAgentsOnly(option))},optionDescription(option){return option.long==="--org"&&program2.options.includes(option)?CHAT_ORG_HELP:Help.prototype.optionDescription.call(this,option)}});chat.hook("preAction",()=>{const flag=program2.options.find(option=>isAgentsOnly(option)&&program2.getOptionValueSource(option.attributeName())==="cli");if(flag)throw new CliError("usage",`${flag.long} applies only to Agents commands; gauge chat always uses the hosted Chat API. Remove ${flag.long}.`)})}function register6(program2){const chat=program2.command("chat").description("Gauge Chat AI visibility: prompts, topics, tags, answers, citations, queries").addHelpText("after",`
|
|
26
|
+
Category-scoped commands take --category (slug or cat_ id; default: chatCategory
|
|
27
|
+
config, else the org's only category). Authenticate with \`gauge auth login\`,
|
|
28
|
+
or for scripts set GAUGE_API_TOKEN to an org API key (gauge_sk_\u2026, created in
|
|
29
|
+
Settings \u2192 API Keys); GAUGE_API_TOKEN takes precedence over a login. --org takes
|
|
30
|
+
a slug or id and selects the same organization as Agents commands (default:
|
|
31
|
+
gauge.json orgId, then your saved default from \`gauge orgs use\`, else your only Chat org);
|
|
32
|
+
an org API key implies its own org, and --org may pick one of an agency key's
|
|
33
|
+
clients. Pass -o json for
|
|
34
|
+
machine-readable output; errors carry the API error code. Exit codes: 0 ok,
|
|
35
|
+
1 error, 2 invalid request, 3 plan limit.
|
|
36
|
+
Rate limits per token and organization: 600 requests/min, 60 queries/min.`);scopeGlobalOptions(program2,chat);registerCategories(chat);registerTopics(chat);registerPrompts(chat);registerTags(chat);registerBrands(chat);registerQuery(chat);registerData(chat)}var cleanup_exports={};__export(cleanup_exports,{register:()=>register7});import{join as join5}from"path";function register7(program2){program2.command("cleanup").description("Clean interrupted Gauge sessions in this repository (local only); preserve results and images").action(async(_opts,command)=>{const state=gaugeState(command);if(state.mode!=="local"||!state.root)throw new CliError("usage","Use --local inside the batch's Git repository");const results=await cleanupLocal(join5(state.root,".gauge"));if(results.some(r=>r.status==="error"))process.exitCode=1;if(resolveOutput(command)==="json")printJson({sessions:results});else{if(!results.length)console.log("No interrupted sessions need cleanup.");for(const result of results)console.log(`${result.id}: ${result.status}${result.detail?` (${result.detail})`:""}`)}})}var config_exports={};__export(config_exports,{register:()=>register8});function assertKey(key){if(CONFIG_KEYS.includes(key)){return key}throw new CliError("usage",`Unknown config key '${key}'. Valid keys: ${CONFIG_KEYS.join(", ")}`)}function register8(program2){const config=program2.command("config").description("Local client config (~/.config/gauge/config.json)");config.command("get [key]").description("Print the whole config, or a single key's value").action(key=>{const current=readConfig();if(key===void 0){printJson(current);return}console.log(current[assertKey(key)]??"")});config.command("set <key> <value>").description(`Set a config key (${CONFIG_KEYS.join(", ")})`).action((key,value)=>{const configKey=assertKey(key);if(configKey==="defaultOrg"||configKey==="orgId"&&!isUuid(value))throw new CliError("usage","Select an organization with `gauge orgs use <slug>`.");if(configKey==="backend"&&value!=="local"&&value!=="hosted")throw new CliError("usage","backend must be local or hosted");updateConfig({[configKey]:value});console.log(`${configKey} = ${value} (${configPath()})`)});config.command("unset <key>").description("Remove a config key").action(key=>{const configKey=assertKey(key);updateConfig({[configKey]:void 0});console.log(`${configKey} unset (${configPath()})`)})}var connections_exports={};__export(connections_exports,{register:()=>register9});function connectionsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/connections`}function register9(program2){const group=hostedOnly(program2.command("connections")).description("Inspect the org's stored credentials (no secrets)");group.command("list").description("List credentials with the ids --connection accepts").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(connectionsPath(org));if(resolveOutput(cmd)==="json"){printJson(res.items);return}printItems(res.items.map(c=>({id:c.id,name:c.handle,vendor:c.profileLabel,placeholder:[c.credentialKey,c.basicPasswordKey].filter(Boolean).join(", "),domains:c.allowedHosts.join(", "),kind:c.kind,value:c.last4?`\xB7\xB7\xB7\xB7${c.last4}`:""})),"table")})}var dashboards_exports={};__export(dashboards_exports,{register:()=>register10});import{readFileSync as readFileSync3}from"fs";function dashboardsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/dashboards`}function register10(program2){const group=hostedOnly(program2.command("dashboards")).description("Saved dashboards (CRUD + view filters; layout is UI-only)");group.command("list").description("List your dashboard library").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(dashboardsPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(d=>({key:d.key,name:d.name,source:d.source,default:d.isUserDefault?"you":d.isOrgDefault?"org":""})),"table")});group.command("get <key>").description("Show one resolved dashboard (widgets + saved filters)").action(async(key,_opts,cmd)=>{const org=await resolveOrg(cmd);const dashboard=await createClient().get(`${dashboardsPath(org)}/${encodeURIComponent(key)}`);if(resolveOutput(cmd)==="json"){printJson(dashboard);return}console.log(`key: ${dashboard.key}`);console.log(`name: ${dashboard.name}`);console.log(`filters: ${JSON.stringify(dashboard.defaultFilters)}`);console.log("widgets:");for(const w of dashboard.widgets)console.log(` [${w.id}] ${w.title} (${w.viz})`)});group.command("create <name>").description("Create an empty personal dashboard").action(async(name,_opts,cmd)=>{const org=await resolveOrg(cmd);const created=await createClient().post(dashboardsPath(org),{name});if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created dashboard ${created.key}`)});group.command("rename <key> <name>").description("Rename a dashboard (in your overlay)").action(async(key,name,_opts,cmd)=>{const org=await resolveOrg(cmd);const updated=await createClient().patch(`${dashboardsPath(org)}/${encodeURIComponent(key)}`,{name});if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Renamed to ${updated.name}`)});group.command("rm <key>").description("Delete a dashboard (built-in templates refuse)").action(async(key,_opts,cmd)=>{const org=await resolveOrg(cmd);await createClient().delete(`${dashboardsPath(org)}/${encodeURIComponent(key)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted dashboard ${key}`)});group.command("filters <key>").description("Replace a dashboard's saved view-level filters").option("--json <json>","the filters object inline").option("--file <path>",'the filters object from a file ("-" for stdin)').option("--clear","remove all saved filters").action(async(key,opts,cmd)=>{const org=await resolveOrg(cmd);const provided=[opts.json,opts.file,opts.clear].filter(v=>v!==void 0&&v!==false).length;if(provided!==1)throw new CliError("usage","pass exactly one of --json, --file, or --clear");let filters={};if(!opts.clear){const raw=opts.json??readFileSync3(opts.file==="-"?0:opts.file,"utf8");try{filters=JSON.parse(raw)}catch(e){throw new CliError("usage",`filters are not valid JSON: ${e instanceof Error?e.message:e}`)}}const updated=await createClient().put(`${dashboardsPath(org)}/${encodeURIComponent(key)}/filters`,filters);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Saved filters: ${JSON.stringify(updated.defaultFilters)}`)})}var eval_exports={};__export(eval_exports,{register:()=>register11});import{randomUUID as randomUUID3}from"crypto";import{join as join6}from"path";import{z as z3}from"zod";import{z as z2}from"zod";var sampleCountSchema=z2.number().int().min(1).max(50);var nextRunAtInputSchema=z2.string().regex(/^\d{4}-\d{2}-\d{2}/,"Next run must be a calendar date").nullable();var ownedCadenceSchema=z2.enum(["NONE","DAILY","WEEKLY","MONTHLY"]);var ownedConfigurationInputShape={repoUrl:z2.string().nullish(),repoRef:z2.string().nullish(),profileId:z2.string().nullish(),agents:z2.array(agentConfigInputSchema).min(1,"Select at least one agent"),skillRefs:assetRefListSchema.optional().default([]),mcpRefs:assetRefListSchema.optional().default([]),connectionIds:z2.array(z2.string().min(1)).max(32).optional().default([]),cadence:ownedCadenceSchema.optional().default("NONE"),nextRunAt:nextRunAtInputSchema.optional(),sampleCount:sampleCountSchema.optional().default(1)};var ownedConfigurationInputSchema=z2.object(ownedConfigurationInputShape).strict();var ownedConfigurationPatchShape={repoUrl:z2.string().nullish(),repoRef:z2.string().nullish(),profileId:z2.string().nullish(),agents:z2.array(agentConfigInputSchema).min(1,"Select at least one agent").optional(),skillRefs:assetRefListSchema.optional(),mcpRefs:assetRefListSchema.optional(),connectionIds:z2.array(z2.string().min(1)).max(32).optional(),cadence:ownedCadenceSchema.optional(),nextRunAt:nextRunAtInputSchema.optional(),sampleCount:sampleCountSchema.optional()};var ownedConfigurationSchema=z2.object({repoUrl:z2.string().nullable(),repoRef:z2.string().nullable(),profile:z2.object({id:z2.string(),name:z2.string()}).nullable(),agents:z2.array(agentConfigSchema),skillRefs:z2.array(z2.string()),mcpRefs:z2.array(z2.string()),connectionIds:z2.array(z2.string()),cadence:ownedCadenceSchema,sampleCount:sampleCountSchema,lastScheduledAt:z2.string().nullable(),nextRunAt:z2.string().nullable()});var visibilityScenarioSchema=z2.object({id:z2.string(),repoUrl:z2.string().nullable(),repoRef:z2.string().nullable(),profile:z2.object({id:z2.string(),name:z2.string()}).nullable()});var visibilityScenarioInputSchema=z2.object({repoUrl:z2.string().nullish(),repoRef:z2.string().nullish(),profileId:z2.string().nullish()}).strict();var visibilityPromptSettingsInputShape={agents:ownedConfigurationInputShape.agents,skillRefs:ownedConfigurationInputShape.skillRefs,mcpRefs:ownedConfigurationInputShape.mcpRefs,connectionIds:ownedConfigurationInputShape.connectionIds,cadence:ownedConfigurationInputShape.cadence,nextRunAt:ownedConfigurationInputShape.nextRunAt,sampleCount:ownedConfigurationInputShape.sampleCount};var visibilityPromptSettingsPatchShape={agents:ownedConfigurationPatchShape.agents,skillRefs:ownedConfigurationPatchShape.skillRefs,mcpRefs:ownedConfigurationPatchShape.mcpRefs,connectionIds:ownedConfigurationPatchShape.connectionIds,cadence:ownedConfigurationPatchShape.cadence,nextRunAt:ownedConfigurationPatchShape.nextRunAt,sampleCount:ownedConfigurationPatchShape.sampleCount};var visibilityPromptSettingsSchema=z2.object({agents:z2.array(agentConfigSchema),skillRefs:z2.array(z2.string()),mcpRefs:z2.array(z2.string()),connectionIds:z2.array(z2.string()),cadence:ownedCadenceSchema,sampleCount:sampleCountSchema,lastScheduledAt:z2.string().nullable(),nextRunAt:z2.string().nullable()});var runAgentsOverrideSchema=z2.array(agentConfigInputSchema).min(1,"Select at least one agent");var runSampleCountOverrideSchema=sampleCountSchema;var runEvalBodySchema=z2.object({agents:runAgentsOverrideSchema.optional(),sampleCount:runSampleCountOverrideSchema.optional()}).strict();var runVisibilityBodySchema=z2.object({agents:runAgentsOverrideSchema.optional(),sampleCount:runSampleCountOverrideSchema.optional(),visibilityScenarioIds:z2.array(z2.string().min(1)).min(1).optional()}).strict();var criterionSchema=z3.object({id:z3.string(),name:z3.string(),rubric:z3.string(),position:z3.number().int()});var criterionInputSchema=z3.object({id:z3.string().optional(),name:z3.string().min(1).optional(),rubric:z3.string().min(1)});var evalSetSchema=z3.object({id:z3.string(),suiteId:z3.string().nullable(),name:z3.string(),promptText:z3.string(),createdAt:z3.string(),createdBy:createdBySchema,criteria:z3.array(criterionSchema),tags:z3.array(z3.string())}).extend(ownedConfigurationSchema.shape);var agentPassRateSchema=z3.object({agent:agentSchema,model:z3.string(),runId:z3.string(),finishedAt:z3.string().nullable(),passed:z3.number().int(),total:z3.number().int()});var evalSetStatSchema=z3.object({passRates:z3.array(agentPassRateSchema),runCount:z3.number().int(),judgedRuns:z3.number().int(),passedRuns:z3.number().int()});var csv3=z3.string().transform(s=>s.split(",").map(x=>x.trim()).filter(Boolean));var listEvalSetsQuerySchema=z3.object({agents:csv3.pipe(z3.array(agentSchema)).optional(),models:csv3.optional(),since:z3.coerce.date().optional()});var evalSetListItemSchema=evalSetSchema.extend({stats:evalSetStatSchema});var listEvalSetsResponseSchema=z3.object({items:z3.array(evalSetListItemSchema)});var createEvalSetBodySchema=z3.object({name:z3.string().min(1),promptText:z3.string().min(1),criteria:z3.array(criterionInputSchema).min(1),tags:z3.array(z3.string()).optional()}).extend(ownedConfigurationInputSchema.shape).strict();var updateEvalSetBodySchema=z3.object({name:z3.string().min(1).optional(),promptText:z3.string().min(1).optional(),criteria:z3.array(criterionInputSchema).min(1).optional(),tags:z3.array(z3.string()).optional()}).extend(ownedConfigurationPatchShape).strict();var runEvalSetResponseSchema=z3.object({batchIds:z3.array(z3.string()),runIds:z3.array(z3.string()),runRequestId:z3.string().optional()});var evalSetRunSchema=z3.object({id:z3.string(),status:z3.string(),agent:agentSchema,model:z3.string().nullable(),resolvedModel:z3.string().nullable(),createdAt:z3.string(),startedAt:z3.string().nullable(),finishedAt:z3.string().nullable(),failureReason:z3.string().nullable(),creditsCharged:runCreditsChargedSchema.optional(),triggeredBy:runTriggeredBySchema.optional(),evalRevision:z3.string().optional(),judge:z3.object({status:z3.string(),error:z3.string().nullable()}).nullable(),criterionResults:z3.array(z3.object({criterionId:z3.string().nullable(),name:z3.string(),passed:z3.boolean().nullable(),reasoning:z3.string().nullable()}))});var listEvalSetRunsResponseSchema=listResponseSchema(evalSetRunSchema);import{z as z4}from"zod";var VISIBILITY_PROMPT_KINDS=["HEAD_TO_HEAD","RECOMMEND"];var visibilityPromptKindSchema=z4.enum(VISIBILITY_PROMPT_KINDS);var visibilityPromptSchema=visibilityPromptSettingsSchema.extend({id:z4.string(),name:z4.string(),kind:visibilityPromptKindSchema,promptText:z4.string(),branded:z4.boolean(),brandA:z4.string().nullable(),brandB:z4.string().nullable(),market:z4.object({id:z4.string(),slug:z4.string(),name:z4.string()}).nullable(),position:z4.number().int(),createdAt:z4.string(),createdBy:createdBySchema,tags:z4.array(z4.string()),runCount:z4.number().int(),lastRunAt:z4.string().nullable(),scenarios:z4.array(visibilityScenarioSchema)});var listVisibilityPromptsResponseSchema=z4.object({items:z4.array(visibilityPromptSchema)});var createVisibilityPromptBodySchema=z4.object({name:z4.string().min(1),promptText:z4.string().min(1),kind:visibilityPromptKindSchema,branded:z4.boolean().optional(),brandA:z4.string().nullish(),brandB:z4.string().nullish(),marketId:z4.string().nullish(),tags:z4.array(z4.string()).optional(),agents:visibilityPromptSettingsInputShape.agents.optional(),skillRefs:visibilityPromptSettingsInputShape.skillRefs,mcpRefs:visibilityPromptSettingsInputShape.mcpRefs,connectionIds:visibilityPromptSettingsInputShape.connectionIds,cadence:visibilityPromptSettingsInputShape.cadence,sampleCount:visibilityPromptSettingsInputShape.sampleCount,scenarios:z4.array(visibilityScenarioInputSchema).optional().default([])}).strict();var updateVisibilityPromptBodySchema=z4.object({name:z4.string().min(1).optional(),promptText:z4.string().min(1).optional(),branded:z4.boolean().optional(),brandA:z4.string().nullish(),brandB:z4.string().nullish(),marketId:z4.string().nullish(),tags:z4.array(z4.string()).optional(),...visibilityPromptSettingsPatchShape,scenarios:z4.array(visibilityScenarioInputSchema).optional()}).strict();var runVisibilityPromptResponseSchema=z4.object({batchIds:z4.array(z4.string()),runIds:z4.array(z4.string())});var visibilityPromptRunSchema=z4.object({id:z4.string(),status:z4.string(),agent:agentSchema,model:z4.string().nullable(),resolvedModel:z4.string().nullable(),createdAt:z4.string(),startedAt:z4.string().nullable(),finishedAt:z4.string().nullable(),failureReason:z4.string().nullable(),creditsCharged:runCreditsChargedSchema.optional(),triggeredBy:runTriggeredBySchema.optional(),verdict:z4.object({status:z4.string(),error:z4.string().nullable(),payload:z4.unknown().nullable()}).nullable()});var listVisibilityPromptRunsResponseSchema=listResponseSchema(visibilityPromptRunSchema);var orgMarketSchema=z4.object({marketId:z4.string(),slug:z4.string(),name:z4.string(),capability:z4.string(),source:z4.string()});var addableMarketSchema=orgMarketSchema.omit({source:true});var listMarketsResponseSchema=z4.object({tracked:z4.array(orgMarketSchema),addable:z4.array(addableMarketSchema)});var addMarketBodySchema=z4.object({marketId:z4.string().min(1)});import{readFileSync as readFileSync4}from"fs";function parseLimit(raw){const limit=Number(raw);if(!Number.isInteger(limit)||limit<1||limit>200){throw new CliError("usage","--limit must be an integer between 1 and 200")}return limit}function collect5(value,previous){return[...previous,value]}function once(flag){return(value,previous)=>{if(previous!==void 0)throw new CliError("usage",`${flag} takes one id; start one run per id`);return value}}var AGENT_ALIASES={"claude-code":"CLAUDE_CODE",claude_code:"CLAUDE_CODE",claude:"CLAUDE_CODE",codex:"CODEX_CLI","codex-cli":"CODEX_CLI",codex_cli:"CODEX_CLI",cursor:"CURSOR",pi:"PI",opencode:"OPENCODE","open-code":"OPENCODE",open_code:"OPENCODE",antigravity:"ANTIGRAVITY"};function parseAgents(raw){const out=[];for(const part of raw.split(",")){const name=part.trim();if(!name)continue;const agent=AGENT_ALIASES[name.toLowerCase()];if(!agent){throw new CliError("usage",`unknown agent "${name}" (expected: claude-code, codex, cursor, pi, opencode, antigravity)`)}out.push(agent)}if(out.length===0)throw new CliError("usage","no agents given");return[...new Set(out)]}function parseAgentSpec(raw){const colon=raw.indexOf(":");const name=(colon<0?raw:raw.slice(0,colon)).trim();const agent=AGENT_ALIASES[name.toLowerCase()];if(!agent){throw new CliError("usage",`unknown agent "${name}" in --agent "${raw}" (expected: claude-code, codex, pi, opencode, or antigravity, optionally ":model1,model2")`)}if(agent==="CURSOR"){throw new CliError("usage","cursor is not schedulable \u2014 presets may roster claude-code, codex, pi, opencode, and hosted antigravity")}const models=colon<0?[]:raw.slice(colon+1).split(",").map(m=>m.trim()).filter(Boolean);if(colon>=0&&models.length===0){throw new CliError("usage",`--agent "${raw}" has a ":" but no models \u2014 drop the colon for the agent default`)}return{agent,models:[...new Set(models)]}}function buildAgentRoster(specs){const byAgent=new Map;for(const raw of specs){const{agent,models}=parseAgentSpec(raw);const set=byAgent.get(agent)??new Set;for(const m of models)set.add(m);byAgent.set(agent,set)}return[...byAgent.entries()].map(([agent,models])=>({agent,models:[...models]}))}function validateAssetRefs(kind,refs){const parsed=runConfig_exports.assetRefListSchema.safeParse(refs);if(!parsed.success){const first=parsed.error.issues[0];throw new CliError("usage",`invalid --${kind} reference: ${first?.message??"expected name@label"}`)}return refs}function readPromptText(opts){if(opts.text===void 0===(opts.file===void 0)){throw new CliError("usage","pass exactly one of --text or --file")}if(opts.text!==void 0)return opts.text;const text=readFileSync4(opts.file==="-"?0:opts.file,"utf8").trim();if(!text)throw new CliError("usage","prompt file is empty");return text}function parseCadence(raw){const cadence=(raw??"NONE").trim().toUpperCase();if(!["NONE","DAILY","WEEKLY","MONTHLY"].includes(cadence))throw new CliError("usage",`invalid cadence "${raw}" (expected none, daily, weekly, or monthly)`);return cadence}function parseSampleCount(raw){const value=Number(raw??"1");if(!Number.isSafeInteger(value)||value<1||value>50)throw new CliError("usage","--samples must be an integer from 1 to 50");return value}function ownedConfigFromOpts(opts){if(opts.ref!==void 0&&opts.repo===void 0)throw new CliError("usage","--ref requires --repo");if(opts.agent.length===0)throw new CliError("usage","at least one --agent is required");return{repoUrl:opts.repo??null,repoRef:opts.ref??null,profileId:opts.persona??null,agents:buildAgentRoster(opts.agent),skillRefs:validateAssetRefs("skill",opts.skill),mcpRefs:validateAssetRefs("mcp",opts.mcp),connectionIds:opts.connection,cadence:parseCadence(opts.cadence),sampleCount:parseSampleCount(opts.samples)}}function ownedConfigPatchFromOpts(opts){const patch={};if((opts.repo!==void 0||opts.ref!==void 0)&&opts.clearRepo)throw new CliError("usage","--repo/--ref and --clear-repo conflict");if(opts.ref!==void 0&&opts.clearRef)throw new CliError("usage","--ref and --clear-ref conflict");if(opts.clearRepo){patch.repoUrl=null;patch.repoRef=null}else{if(opts.repo!==void 0)patch.repoUrl=opts.repo;if(opts.clearRef)patch.repoRef=null;else if(opts.ref!==void 0)patch.repoRef=opts.ref}if(opts.persona!==void 0&&opts.clearPersona)throw new CliError("usage","--persona and --clear-persona conflict");if(opts.clearPersona)patch.profileId=null;else if(opts.persona!==void 0)patch.profileId=opts.persona;if(opts.agent.length>0)patch.agents=buildAgentRoster(opts.agent);if(opts.skill.length>0&&opts.clearSkills)throw new CliError("usage","--skill and --clear-skills conflict");if(opts.clearSkills)patch.skillRefs=[];else if(opts.skill.length>0)patch.skillRefs=validateAssetRefs("skill",opts.skill);if(opts.mcp.length>0&&opts.clearMcp)throw new CliError("usage","--mcp and --clear-mcp conflict");if(opts.clearMcp)patch.mcpRefs=[];else if(opts.mcp.length>0)patch.mcpRefs=validateAssetRefs("mcp",opts.mcp);if(opts.connection.length>0&&opts.clearConnections)throw new CliError("usage","--connection and --clear-connections conflict");if(opts.clearConnections)patch.connectionIds=[];else if(opts.connection.length>0)patch.connectionIds=opts.connection;if(opts.cadence!==void 0)patch.cadence=parseCadence(opts.cadence);if(opts.samples!==void 0)patch.sampleCount=parseSampleCount(opts.samples);return patch}function addRunSettingsCreateOptions(command){return command.option("--agent <agent[:m1,m2]>","agent and optional model pins (repeatable)",collect5,[]).option("--skill <name@label>","staged skill (repeatable)",collect5,[]).option("--mcp <name@label>","MCP server (repeatable)",collect5,[]).option("--connection <id>","connection id (repeatable)",collect5,[]).option("--cadence <cadence>","none | daily | weekly | monthly","none").option("--samples <n>","sample count from 1 to 50","1")}function addRunSettingsEditOptions(command){return command.option("--agent <agent[:m1,m2]>","replace agents and model pins (repeatable)",collect5,[]).option("--skill <name@label>","replace skills (repeatable)",collect5,[]).option("--clear-skills","remove all skills").option("--mcp <name@label>","replace MCP servers (repeatable)",collect5,[]).option("--clear-mcp","remove all MCP servers").option("--connection <id>","replace connections (repeatable)",collect5,[]).option("--clear-connections","remove all connections").option("--cadence <cadence>","none | daily | weekly | monthly").option("--samples <n>","sample count from 1 to 50")}function hasRunSettingsFlags(opts){return opts.agent.length>0||opts.skill.length>0||opts.mcp.length>0||opts.connection.length>0||opts.cadence.toUpperCase()!=="NONE"||opts.samples!=="1"}function runSettingsFromOpts(opts){return{...opts.agent.length>0?{agents:buildAgentRoster(opts.agent)}:{},skillRefs:validateAssetRefs("skill",opts.skill),mcpRefs:validateAssetRefs("mcp",opts.mcp),connectionIds:opts.connection,cadence:parseCadence(opts.cadence),sampleCount:parseSampleCount(opts.samples)}}function runSettingsPatchFromOpts(opts){return ownedConfigPatchFromOpts(opts)}function runOverridesFromOpts(opts){return{...opts.agent.length>0?{agents:buildAgentRoster(opts.agent)}:{},...opts.samples!==void 0?{sampleCount:parseSampleCount(opts.samples)}:{}}}function cadenceLabel(cadence){return cadence==="NONE"?"manual":cadence.toLowerCase()}function localDirectory2(command){const state=gaugeState(command);if(!state.root)throw new CliError("usage","No Gauge workspace found. Run `gauge init` in this directory first.");if(state.config===null)throw new CliError("usage","gauge.json is not valid JSON");return join6(state.root,".gauge")}function isLocal(command){return gaugeState(command).mode==="local"}function withLocalStore(command,fn){const store=openLocalStore(localDirectory2(command));try{return fn(store)}finally{store.close()}}function normalize(kind,raw,previous){const{inputs:_inputs,...definition}=raw;const scenarioInputs=Array.isArray(definition.scenarios)?definition.scenarios:void 0;if(scenarioInputs)definition.scenarios=scenarioInputs.map(({id:_id,...scenario})=>scenario);const parsed=(kind==="eval"?createEvalSetBodySchema:createVisibilityPromptBodySchema).safeParse(definition);if(!parsed.success)throw new CliError("usage",`Invalid ${kind}: ${parsed.error.issues.map(i=>`${i.path.join(".")}: ${i.message}`).join("; ")}`);const value=parsed.data;value.name=value.name.trim();value.promptText=value.promptText.trim();if(!value.name||!value.promptText)throw new CliError("usage","A measurement needs a nonempty name and prompt.");if(value.cadence&&value.cadence!=="NONE")throw new CliError("usage","Local measurements do not support managed schedules. Use --cadence none or --hosted.");if(value.nextRunAt)throw new CliError("usage","Local measurements do not support scheduled start times. Use --hosted.");assertLocalCapabilities(value);value.tags=[...new Set((value.tags??[]).map(tag=>tag.trim()).filter(Boolean))];if(kind==="eval"){if(value.repoRef&&!value.repoUrl)throw new CliError("usage","A repository ref requires a repository URL.");const ids=new Set;const existing=new Set(previous?.criteria?.map(criterion=>criterion.id));value.criteria=value.criteria.map(c=>{const rubric=c.rubric.trim();if(!rubric)throw new CliError("usage","Every criterion needs a nonempty rubric.");if(c.id&&previous&&!existing.has(c.id))throw new CliError("usage",`Unknown criterion ID: ${c.id}. Omit id to add a new criterion.`);const id=c.id??`cr_${randomUUID3()}`;if(!id||ids.has(id))throw new CliError("usage",`Duplicate or empty criterion ID: ${id}`);ids.add(id);return{id,name:c.name?.trim()||deriveCriterionName(rubric),rubric}})}else{value.brandA=typeof value.brandA==="string"?value.brandA.trim()||null:null;value.brandB=typeof value.brandB==="string"?value.brandB.trim()||null:null;if(value.kind==="HEAD_TO_HEAD"){if(!value.brandA||!value.brandB||String(value.brandA).toLowerCase()===String(value.brandB).toLowerCase())throw new CliError("usage","Head-to-head preference needs two different --brand-a and --brand-b values");[value.brandA,value.brandB]=[String(value.brandA),String(value.brandB)].sort((a,b)=>a.toLowerCase().localeCompare(b.toLowerCase()))}value.branded=value.kind==="HEAD_TO_HEAD"||Boolean(value.branded);value.agents??=[{agent:"CLAUDE_CODE",models:[]},{agent:"CODEX_CLI",models:[]}];const scenarios=value.scenarios;if(!previous&&scenarios.length===0)scenarios.push({repoUrl:null,repoRef:null,profileId:null});if(scenarios.some(s=>s.profileId))throw new CliError("usage","Local scenarios do not support hosted personas");const seen=new Set;const ids=new Set;const existing=new Set(previous?.scenarios?.map(scenario=>scenario.id));value.scenarios=scenarios.map((scenario,index)=>{const repoUrl=typeof scenario.repoUrl==="string"?scenario.repoUrl.trim()||null:null;const repoRef=typeof scenario.repoRef==="string"?scenario.repoRef.trim()||null:null;if(repoRef&&!repoUrl)throw new CliError("usage","A scenario ref requires a repository URL.");const key=JSON.stringify([repoUrl,repoRef]);if(seen.has(key))throw new CliError("usage","This prompt already has the same scenario.");seen.add(key);const suppliedId=scenarioInputs?.[index]?.id;if(suppliedId!==void 0&&(typeof suppliedId!=="string"||!previous||!existing.has(suppliedId)))throw new CliError("usage",`Unknown scenario ID: ${suppliedId}. Omit id to add a scenario.`);const id=typeof suppliedId==="string"?suppliedId:`sc_${randomUUID3()}`;if(ids.has(id))throw new CliError("usage",`Duplicate scenario ID: ${id}`);ids.add(id);return{id,repoUrl,repoRef,profileId:null}})}return value}function editable(row2){const{id,revision,measurementKind,createdAt,updatedAt,...definition}=row2;return definition}function createLocalMeasurement(command,kind,definition){return withLocalStore(command,store=>store.createMeasurement(kind,normalize(kind,definition)))}function editLocalMeasurement(command,kind,id,patch){return withLocalStore(command,store=>{const current=store.requireMeasurement(id,kind);const value=normalize(kind,{...editable(current),...patch},current);if(!("criteria"in patch)&¤t.criteria)value.criteria=current.criteria;if(!("scenarios"in patch)&¤t.scenarios)value.scenarios=current.scenarios;return store.updateMeasurement(id,value)})}function getLocalMeasurement(command,kind,id){return withLocalStore(command,store=>measurementWithStats(store,store.requireMeasurement(id,kind)))}function removeLocalMeasurement(command,kind,id){withLocalStore(command,store=>{store.requireMeasurement(id,kind);store.deleteMeasurement(id)})}function localMeasurementView(row2){return{profile:null,suiteId:null,market:null,position:0,runCount:0,lastRunAt:null,cadence:"NONE",sampleCount:1,repoUrl:null,repoRef:null,agents:[],skillRefs:[],mcpRefs:[],connectionIds:[],stats:{passRates:[],runCount:0,judgedRuns:0,passedRuns:0},...row2,scenarios:Array.isArray(row2.scenarios)?row2.scenarios.map(s=>({...s,profile:null})):[]}}function listLocalMeasurements(command,kind){return withLocalStore(command,store=>store.listMeasurements(kind).map(row2=>localMeasurementView(measurementWithStats(store,row2))))}function measurementWithStats(store,row2){const sessions=store.listSessions({measurementId:row2.id});const stats={runCount:sessions.length,judgedRuns:0,passedRuns:0,passRates:[]};for(const session of sessions){const analysis=readCurrentAnalysis(store,session.id);if(!analysis)continue;const outcomes=analysis.criteria.map(criterion=>criterion.outcome);const verdict=outcomes.includes("FAIL")?false:!outcomes.length||outcomes.includes("UNASSESSABLE")?null:true;if(verdict===null)continue;stats.judgedRuns++;if(verdict)stats.passedRuns++;if(!stats.passRates.some(rate=>rate.agent===session.agent))stats.passRates.push({agent:session.agent,model:session.model,runId:session.id,finishedAt:session.endedAt,passed:outcomes.filter(outcome2=>outcome2==="PASS").length,total:outcomes.length})}return{...row2,runCount:sessions.length,lastRunAt:sessions.map(session=>session.createdAt).sort().at(-1)??null,stats}}function deriveCriterionName(rubric){const trimmed=rubric.replace(/^\s*(?:[-*•]|\(?\d+[.)])\s+/,"").trim();const first=trimmed.split(/(?<=[.!?])\s|\n/)[0]?.trim()??"";return(new RegExp("\\p{L}","u").test(first)?first:trimmed.replace(/\s+/g," ")).replace(/[.!?]+$/,"").trim()}function localMeasurementSpec(command,kind,id,opts){const row2=getLocalMeasurement(command,kind,id);const stored=row2.inputs;if(stored?.length&&!opts.inputs.length)console.error(`note: saved inputs are no longer attached (${stored.join(", ")}). Pass --input <name> at launch.`);const settings={...row2,...runOverridesFromOpts(opts)};const agents=settings.agents;if(!agents?.length)throw new CliError("usage","Choose at least one agent with --agent before launching this local measurement");let scenarios=kind==="preference"?settings.scenarios:[{repoUrl:settings.repoUrl??null,repoRef:settings.repoRef??null}];if(!scenarios.length)throw new CliError("usage","This preference prompt has no scenarios. Add one with gauge preference scenarios add <id> before running it.");if(opts.scenario?.length){for(const selected of opts.scenario)if(!scenarios.some(s=>s.id===selected))throw new CliError("usage",`Unknown local scenario: ${selected}`);scenarios=scenarios.filter(s=>s.id!==void 0&&opts.scenario.includes(s.id))}const cases=scenarios.map((scenario,index)=>({key:`${kind}-${index+1}`,prompt:String(settings.promptText),...kind==="eval"?{criteria:settings.criteria.map(c=>({name:c.name,rubric:c.rubric}))}:{preference:settings.kind==="HEAD_TO_HEAD"?{kind:"head-to-head",brandA:String(settings.brandA),brandB:String(settings.brandB)}:{kind:"open-ended",branded:Boolean(settings.branded)}},config:{agents,sampleCount:Number(settings.sampleCount??1),repoUrl:scenario.repoUrl,repoRef:scenario.repoRef,inputs:opts.inputs}}));return{spec:{version:2,cases},measurement:{id,kind,revision:row2.revision,...kind==="eval"?{criterionIds:row2.criteria.map(c=>c.id)}:{}}}}import{readFileSync as readFileSync5}from"fs";import{createInterface as createInterface3}from"readline";async function confirmOrAbort(question,yes){if(yes)return;if(!process.stdin.isTTY){throw new CliError("usage","refusing to proceed without confirmation on a non-interactive stdin \u2014 pass --yes")}const rl=createInterface3({input:process.stdin,output:process.stderr});const answer=await new Promise(resolve5=>rl.question(`${question} [y/N] `,resolve5));rl.close();if(!/^y(es)?$/i.test(answer.trim())){throw new CliError("usage","aborted")}}function creatorLabel(createdBy){return createdBy?.name||createdBy?.email||"--"}function triggeredByLabel(t){if(!t)return"";return t.email?`${t.source} (${t.email})`:t.source}async function filterByCreator(items,createdBy){if(createdBy===void 0)return items;const wanted=createdBy.trim().toLowerCase();if(wanted==="me"){const{user}=await createClient().get("/api/v1/me");const email=user.email?.toLowerCase();return items.filter(item=>item.createdBy?.userId===user.id||email!==void 0&&item.createdBy?.email?.toLowerCase()===email)}return items.filter(item=>item.createdBy?.email?.toLowerCase()===wanted)}function evalSetsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/eval-sets`}function evalSetPath(org,id){return`${evalSetsPath(org)}/${encodeURIComponent(id)}`}function parseCriterion(raw){const idx=raw.indexOf(":");if(idx<=0||!raw.slice(idx+1).trim()){throw new CliError("usage",`invalid --criterion "${raw}" (expected "Name: rubric text")`)}return{name:raw.slice(0,idx).trim(),rubric:raw.slice(idx+1).trim()}}function readCriteriaFile(path){let parsed;try{parsed=JSON.parse(readFileSync5(path==="-"?0:path,"utf8"))}catch(e){throw new CliError("usage",`could not read --criteria-file: ${e instanceof Error?e.message:e}`)}if(!Array.isArray(parsed)||parsed.length===0)throw new CliError("usage","--criteria-file must be a non-empty JSON array of {id?, name, rubric}");return parsed}function criteriaFromOpts(opts){if(opts.criterion.length>0&&opts.criteriaFile!==void 0)throw new CliError("usage","--criterion and --criteria-file conflict");if(opts.criteriaFile!==void 0)return readCriteriaFile(opts.criteriaFile);if(opts.criterion.length>0)return opts.criterion.map(parseCriterion);return void 0}function repoLabel(e){if(!e.repoUrl)return"(default scaffold)";return e.repoRef?`${e.repoUrl}@${e.repoRef}`:e.repoUrl}function passRateLabel(stats){if(stats.judgedRuns===0)return"-";return`${Math.round(stats.passedRuns/stats.judgedRuns*100)}% (${stats.passedRuns}/${stats.judgedRuns})`}function evalSetRow(e){return{id:e.id,name:e.name,repo:repoLabel(e),criteria:e.criteria.length,tags:e.tags.join(", "),"pass rate":passRateLabel(e.stats),runs:e.stats.runCount,"created by":creatorLabel(e.createdBy)}}function printDetail(e){console.log(`id: ${e.id}`);console.log(`name: ${e.name}`);console.log(`repo: ${repoLabel(e)}`);console.log(`persona: ${e.profile?e.profile.name:"(default persona)"}`);console.log(`tags: ${e.tags.join(", ")||"(none)"}`);console.log(`cadence: ${cadenceLabel(e.cadence)}`);console.log(`samples: ${e.sampleCount}`);console.log(`agents: ${e.agents.map(agent=>`${agent.agent}${agent.models.length>0?`:${agent.models.join(",")}`:""}`).join("; ")}`);console.log(`skills: ${e.skillRefs.join(", ")||"(none)"}`);console.log(`mcp: ${e.mcpRefs.join(", ")||"(none)"}`);console.log(`conns: ${e.connectionIds.join(", ")||"(none)"}`);console.log(`creator: ${creatorLabel(e.createdBy)}`);console.log(`prompt: ${e.promptText}`);console.log("criteria:");for(const c of e.criteria)console.log(` [${c.id}] ${c.name}: ${c.rubric}`)}async function listEvalSets(cmd,opts){if(isLocal(cmd)){if(opts.agents||opts.models||opts.since)throw new CliError("usage","Local eval list does not support stats filters yet; use gauge query --local.");return listLocalMeasurements(cmd,"eval")}const res=await createClient().get(evalSetsPath(await resolveOrg(cmd)),{agents:opts.agents===void 0?void 0:parseAgents(opts.agents).join(","),models:opts.models,since:opts.since});return res.items}async function getEvalSet(cmd,id){const evalSet=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"eval",id)):await createClient().get(evalSetPath(await resolveOrg(cmd),id));if(resolveOutput(cmd)==="json")printJson(evalSet);else printDetail(evalSet)}async function createEvalSet(cmd,opts){const criteria=criteriaFromOpts(opts);if(!criteria)throw new CliError("usage","at least one --criterion (or --criteria-file) is required");const body={name:opts.name,promptText:readPromptText(opts),...ownedConfigFromOpts(opts),criteria,tags:opts.tag.length>0?opts.tag:void 0};if(!isLocal(cmd)&&opts.repo===void 0)console.error("note: no --repo \u2014 this eval set will run against the default Gauge scaffold, NOT your repository. Use `gauge eval edit <id> --repo <url>` to retarget.");const created=isLocal(cmd)?createLocalMeasurement(cmd,"eval",body):await createClient().post(evalSetsPath(await resolveOrg(cmd)),body);if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created eval set ${created.id}`)}async function editEvalSet(cmd,id,opts){const body=ownedConfigPatchFromOpts(opts);if(opts.name!==void 0)body.name=opts.name;if(opts.text!==void 0||opts.file!==void 0)body.promptText=readPromptText(opts);const criteria=criteriaFromOpts(opts);if(criteria)body.criteria=criteria;if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");if(opts.clearTags)body.tags=[];else if(opts.tag.length>0)body.tags=opts.tag;if(Object.keys(body).length===0)throw new CliError("usage","nothing to change");const updated=isLocal(cmd)?editLocalMeasurement(cmd,"eval",id,body):await createClient().patch(evalSetPath(await resolveOrg(cmd),id),body);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated eval set ${updated.id}`)}async function removeEvalSet(cmd,id){if(isLocal(cmd))removeLocalMeasurement(cmd,"eval",id);else await createClient().delete(evalSetPath(await resolveOrg(cmd),id));if(resolveOutput(cmd)!=="json")console.log(`Deleted eval set ${id}`)}async function runEvalSet(cmd,id,opts){const org=await resolveOrg(cmd);const overrides=runOverridesFromOpts(opts);await confirmOrAbort(Object.keys(overrides).length>0?"Run this eval now with these overrides? The stored configuration stays unchanged.":"Run this eval's stored configuration now?",opts.yes);const result=await createClient().post(`${evalSetPath(org,id)}/run`,overrides);if(resolveOutput(cmd)==="json")printJson(result);else{console.log(`Started ${result.runIds.length} run${result.runIds.length===1?"":"s"} in batch ${result.batchIds[0]??""}`);for(const batch of result.batchIds)console.log(`Runs: gauge run list --batch ${batch}`);if(result.runRequestId)console.log(`Wait: gauge --org ${org} run wait ${result.runRequestId}`)}}function register11(program2){const evals=program2.command("eval").description("Manage eval sets: saved prompts with judged criteria. Launch one with `gauge run --eval <id>`");evals.command("list").description("List eval sets").option("--agents <agents>","stats for these agents only (csv)").option("--models <models>","stats for these model slugs only (csv)").option("--since <date>","stats for runs since this ISO date only").option("--created-by <email|me>","only evals created by this user").action(async(opts,cmd)=>{const items=await filterByCreator(await listEvalSets(cmd,opts),opts.createdBy);if(resolveOutput(cmd)==="json")printJson(items);else printItems(items.map(evalSetRow),"table")});evals.command("get <id>").description("Show one eval set").action(async(id,_opts,cmd)=>{await getEvalSet(cmd,id)});addRunSettingsCreateOptions(evals.command("create").description("Create an eval set").requiredOption("--name <name>","name").option("--text <text>","prompt text inline").option("--file <path>",'prompt text from a file ("-" for stdin)').option("--repo <url>","consumer repository (default: empty locally, Gauge scaffold hosted)").option("--ref <ref>","branch, tag, or commit (with --repo)").option("--persona <profileId>","persona profile id")).option("--criterion <spec>",'judged criterion as "Name: rubric text" (repeatable)',collect5,[]).option("--criteria-file <path>",'JSON array of {name, rubric} ("-" for stdin)').option("--tag <name>","user tag name, create-on-type (repeatable)",collect5,[]).action(async(opts,cmd)=>{await createEvalSet(cmd,opts)});addRunSettingsEditOptions(evals.command("edit <id>").description("Update an eval set. Omitted flags keep their value. A criteria list REPLACES the whole set (use --criteria-file with ids to edit in place).").option("--name <name>","rename it").option("--text <text>","replace the prompt text inline").option("--file <path>",'replace the prompt text from a file ("-" stdin)').option("--repo <url>","set the repository (keeps a ref pin)").option("--ref <ref>","set the branch, tag, or commit pin").option("--clear-ref","drop the ref pin").option("--clear-repo","use an empty workspace locally or the default scaffold hosted").option("--persona <profileId>","set the persona profile id").option("--clear-persona","use the default persona")).option("--criterion <spec>",'criterion as "Name: rubric", replaces the whole set (repeatable)',collect5,[]).option("--criteria-file <path>","JSON array of {id?, name, rubric}; entries with id update in place").option("--tag <name>","replace the user tag set (repeatable)",collect5,[]).option("--clear-tags","remove all user tags").action(async(id,opts,cmd)=>{await editEvalSet(cmd,id,opts)});evals.command("rm <id>").description("Delete an eval set (run history stays)").action(async(id,_opts,cmd)=>{await removeEvalSet(cmd,id)})}var feedback_exports2={};__export(feedback_exports2,{register:()=>register12});import{Option as Option3}from"commander";function register12(program2){program2.command("feedback").description("Send feedback about this CLI to the Gauge team: friction you hit, missing commands or flags, bugs").requiredOption("-m, --message <text>","what happened").addOption(new Option3("--kind <kind>","feedback type").choices([...feedback_exports.FEEDBACK_KINDS]).default("other")).option("--command <command>","the gauge command the feedback is about").action(async(opts,cmd)=>{const{org}=cmd.optsWithGlobals();const client=createClient({authOptional:true});const body={message:opts.message,kind:opts.kind,command:opts.command,org:client.signedIn?org?(await resolveOrgValue(org)).id:readConfig().orgId:void 0};const res=await client.post("/api/v1/feedback",body);if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Feedback sent (${res.id}${client.signedIn?"":", anonymous"}). Thank you.`)})}var instructions_exports={};__export(instructions_exports,{register:()=>register13});var EVAL=`---
|
|
10
37
|
name: gauge-eval
|
|
11
38
|
description: Save, edit, and schedule eval sets that gauge run launches. Read
|
|
12
39
|
before creating or changing a saved eval set.
|
|
@@ -191,6 +218,11 @@ description: Write Gauge eval cases, choose models and judging criteria, and
|
|
|
191
218
|
|
|
192
219
|
## Definition and input snapshots
|
|
193
220
|
|
|
221
|
+
For web interventions, declare \`type: "web-fixture", path: "fixtures/docs.json"\` in gauge.json; select with \`config.inputs\` or override with \`--input docs=path.json\` locally or hosted.
|
|
222
|
+
The version 1 JSON file supports \`pages\` (exact HTTPS url/body, optional status/contentType), \`scopes\` (block missing pages under HTTPS path prefixes), and \`origins\` (origin/upstream HTTPS mappings preserving paths and queries).
|
|
223
|
+
Select either pages/scopes or an origin mapping for each origin. Conflicts, search mocks, unknown fields, and body transformations are rejected; the combined fixture is limited to 1 MB.
|
|
224
|
+
Local runs use a separate TLS gateway: \`gauge local runtime pull\` obtains both images, and \`--dry-run -o json\` reports routes and digests. Original hostnames must resolve. GitHub-resolved \`website\` inputs remain hosted-only.
|
|
225
|
+
|
|
194
226
|
Interactive CLI runs read working-tree case definitions in both backends, including
|
|
195
227
|
uncommitted edits and new files. Selected filesystem inputs are packaged for local
|
|
196
228
|
execution or hosted upload. Explicit remote artifacts retain their declared sources.
|
|
@@ -280,8 +312,9 @@ It does not see this repo, this conversation, or the user. Write each prompt for
|
|
|
280
312
|
| CLI | \`npm-package\`, \`install: environment\` | greenfield dir, pack of this checkout | yes |
|
|
281
313
|
| SDK | \`npm-package\`, \`install: workspace\` | greenfield app in the SDK's language | yes |
|
|
282
314
|
| Docs | \`files\`, \`paths\` globs | docs given to the agent as files | yes |
|
|
315
|
+
| Web fixture | \`web-fixture\`, \`path\` to JSON | exact HTTPS pages or origin mappings through the gateway | yes |
|
|
283
316
|
|
|
284
|
-
Binary, website
|
|
317
|
+
Binary, GitHub-resolved \`website\`, and MCP inputs are hosted only. Local \`web-fixture\` JSON supports version 1 \`pages\` (exact HTTPS url/body), \`scopes\` (block missing pages), and \`origins\` (origin/upstream HTTPS mappings). Select with \`config.inputs\`; override with \`--input name=path.json\`. Original hostnames must resolve. Fixtures are limited to 1 MB; overlapping routes, search mocks, and body transformations are rejected. Supplied docs files do not replace a canonical site. Inputs never include \`.gauge/\`.
|
|
285
318
|
|
|
286
319
|
Add one \`inputs\` entry in gauge.json per surface or skill; keep every other key. An \`npm-package\` \`path\` is a glob that must match one packed .tgz. \`gauge run\` does not pack it: run \`npm pack\` after every change, and delete old .tgz files.
|
|
287
320
|
|
|
@@ -458,7 +491,7 @@ Open the final answer with a compact findings list: **Friction:** what slowed or
|
|
|
458
491
|
Include every supported category, even when an Opportunity addresses the same incident as a Friction finding; omit empty categories. Give evidence and a practical next step for each, with uncertainty that changes its interpretation alongside it.
|
|
459
492
|
Put run counts, setup, command recaps, and general limitations afterward. Include contradictory sessions.
|
|
460
493
|
Fix product issues within the user's authorized scope, rerun the same measurement, publish the new analyses, and compare before/after evidence.
|
|
461
|
-
`;function hillclimbSteps(hosted){return[{title:"Identify inputs and propose a pilot",command:"gauge instructions hillclimb",details:["Inspect this project and the user's goal. Suggest representative tasks, including a mistake or boundary case; explain what they measure.","Choose inputs and the execution backend deliberately.
|
|
494
|
+
`;function hillclimbSteps(hosted){return[{title:"Identify inputs and propose a pilot",command:"gauge instructions hillclimb",details:["Inspect this project and the user's goal. Suggest representative tasks, including a mistake or boundary case; explain what they measure.","Choose inputs and the execution backend deliberately. Web fixture JSON supports HTTPS page replacement and origin mapping locally or hosted. GitHub-resolved website previews need hosted execution; supplied docs files do not replace the canonical site."]},{title:"Prepare and run",command:"gauge instructions run",details:["Save ongoing measurements with eval/preference; use gauge-cases/ for shared or automated cases. Build/pack inputs, verify cases, and preview.",hosted?"State the session count and credit budget; launch with --hosted within the user's authorization. Otherwise ask before spending credits.":"Check Docker, the runtime image, and agent credentials. Launch the agreed cases within the user's authorization; do not repeat approval already given."]},{title:"Analyze evidence",command:`gauge instructions session-analysis --${hosted?"hosted":"local"}`,details:[hosted?"Inspect transcripts and hosted analysis. Separate product friction from environment failures and report findings, affected sessions, and coverage.":"Read transcripts, judge outcomes, and publish structured analysis. Report findings, affected sessions, and coverage; an empty findings list can be a successful analyzed session."]},{title:"Improve, rerun, and compare",details:["Implement a focused change, rebuild/repack, and rerun affected measurements. Keep tasks, criteria, and models fixed; disclose comparison limits.",hosted?"Use gauge run compare --hosted with baseline/candidate request or batch selectors, then inspect whether the original friction disappeared.":"Use gauge run compare --local with baseline/candidate batch selectors after publishing analysis; inspect whether the original friction disappeared.","Repeat within the agreed budget. Report before/after evidence, new friction, and anything still unvalidated."]}]}var LOCAL_STEPS=hillclimbSteps(false);var HOSTED_STEPS=hillclimbSteps(true);function stepsMarkdown(steps=LOCAL_STEPS){return steps.map((step,i)=>[`${i+1}. **${step.title}**${step.command?`: \`${step.command}\``:""}`,...step.details.map(detail=>` - ${detail}`)].join("\n")).join("\n")}var HILLCLIMB=`---
|
|
462
495
|
name: gauge-hillclimb
|
|
463
496
|
description: Plan and carry out an evidence-driven improvement loop for a product,
|
|
464
497
|
CLI, SDK, Skill, or documentation. Use for open-ended setup and usability testing.
|
|
@@ -518,10 +551,10 @@ Reuse authorization for agreed setup; do not ask permission at every step. See \
|
|
|
518
551
|
|
|
519
552
|
| Workflow | Local | Hosted |
|
|
520
553
|
|---|---|---|
|
|
521
|
-
| Skill, npm package (CLI or SDK),
|
|
554
|
+
| Skill, npm package (CLI or SDK), docs-as-files, and web fixture inputs | yes | yes |
|
|
522
555
|
| Eval and preference cases in gauge-cases/ | yes, your coding agent analyzes | yes, judged |
|
|
523
556
|
| \`run\`, \`run list\`, \`run compare\`, \`models list\`, \`cleanup\`, \`feedback\` | yes | yes |
|
|
524
|
-
| Binary, website
|
|
557
|
+
| Binary, GitHub-resolved website, and MCP inputs | no | yes |
|
|
525
558
|
| Saved eval sets and preference prompts | yes | yes |
|
|
526
559
|
| Project inputs and previews on saved measurement launches | yes | use case files/specs |
|
|
527
560
|
| Structured findings and queries | yes, supported fields | yes |
|
|
@@ -707,8 +740,8 @@ Neither deploys. Single-trial retries: trials add --idempotency-key. Optional: g
|
|
|
707
740
|
Run \`gauge ${found.command} -h\` for usage and flag options.
|
|
708
741
|
`:"";return`${markdown.slice(0,end)}
|
|
709
742
|
${quoted}
|
|
710
|
-
${markdown.slice(end)}${footer}`}function normalize2(topic){const
|
|
711
|
-
${command.helpInformation()}`);return}process.stdout.write(instructions(topic,gaugeState(cmd)))})}var init_exports={};__export(init_exports,{register:()=>
|
|
743
|
+
${markdown.slice(end)}${footer}`}function normalize2(topic){const normalized2=topic.trim().toLowerCase();return normalized2==="optimizations"?"optimization":normalized2}function isTopic(topic){return TOPICS[normalize2(topic)]!==void 0}function topicForCommand(command){return TOPIC_NAMES.find(key=>TOPICS[key].command===command)}function topicKey(topic){const key=normalize2(topic);if(!TOPICS[key])throw new CliError("usage",`unknown topic "${topic}" (expected ${TOPIC_NAMES.join(", ")})`,{hint:"Topics are workflow guidance. Run `gauge --help` to list commands, and `gauge <command> -h` for flags."});return key}function register13(program2){program2.command("instructions [topic]").description(`Instructions for a coding agent using this CLI. Run before your first gauge command; a topic loads the full workflow guidance: ${TOPIC_NAMES.join(", ")}. Topics are workflows, not a page per command: run \`gauge <command> -h\` for flags`).option("--list","print the topic names only").action((requested,opts,cmd)=>{if(opts.list){for(const name2 of TOPIC_NAMES)console.log(name2);return}const name=requested?.trim().toLowerCase();const command=name&&!isTopic(name)?cmd.parent?.commands.find(c=>c.name()===name||c.aliases().includes(name)):void 0;const topic=(command&&topicForCommand(command.name()))??requested;if(command&&topic===requested){const help=`gauge ${command.name()} -h`;process.stdout.write(`"${command.name()}" is a command, not an instructions topic. Topics: ${TOPIC_NAMES.join(", ")}. Its help (\`${help}\`):
|
|
744
|
+
${command.helpInformation()}`);return}process.stdout.write(instructions(topic,gaugeState(cmd)))})}var init_exports={};__export(init_exports,{register:()=>register14,summarize:()=>summarize});import{setTimeout as delay}from"timers/promises";var SKILL_AGENTS={CLAUDECODE:"claude-code",CODEX_SANDBOX:"codex",CODEX_THREAD_ID:"codex",CODEX_CI:"codex",CURSOR_AGENT:"cursor",GEMINI_CLI:"gemini-cli",CLINE_ACTIVE:"cline",OPENCODE:"opencode"};var AGENT_MARKERS=[...Object.keys(SKILL_AGENTS),"AI_AGENT"];function detectAgent(env,stdoutIsTTY){if(AGENT_MARKERS.some(name=>env[name]))return"agent";return stdoutIsTTY?"human":"agent"}function detectSkillAgent(env){return Object.entries(SKILL_AGENTS).find(([name])=>env[name])?.[1]}var DOCS_URL="https://docs.withgauge.com/agents";function noCasesError(){return new CliError("not_found","No case files found in this workspace.",{hint:"Plain `gauge init` creates no measurements. Save an eval or preference with `gauge eval create` or `gauge preference create`, then use `gauge run --eval <id>` or `--preference <id>`. For shared case files, read `gauge instructions run`. Start with `gauge instructions hillclimb`."})}import{resolve as resolve2}from"path";import{existsSync as existsSync3,mkdirSync,readFileSync as readFileSync6,writeFileSync}from"fs";import{join as join7}from"path";var START="<!-- gauge:start -->";var END="<!-- gauge:end -->";var AGENTS_BLOCK=`${START}
|
|
712
745
|
Gauge project inputs and optional shared cases are configured in gauge.json.
|
|
713
746
|
Saved evals and preference prompts, sessions, and analyses live in private .gauge/
|
|
714
747
|
state locally or the hosted organization. Shared cases use gauge-cases/.
|
|
@@ -717,7 +750,7 @@ For product improvement or a first pilot, use \`gauge instructions hillclimb\`:
|
|
|
717
750
|
identify inputs, run representative sessions, analyze, improve, rerun, compare.
|
|
718
751
|
After local runs, follow \`gauge instructions session-analysis\` to publish
|
|
719
752
|
structured findings. Add \`-o json\` for machine-readable output.
|
|
720
|
-
${END}`;function scaffoldWorkspace(root,
|
|
753
|
+
${END}`;function scaffoldWorkspace(root,backend,cases=false){mkdirSync(root,{recursive:true});const manifest=join7(root,"gauge.json");const casesPath=join7(root,"gauge-cases");const gaugeDir=join7(root,".gauge");const result={root,backend,gaugeJson:existsSync3(manifest)?"kept":"created",casesDir:cases?existsSync3(casesPath)?"kept":"created":"not-requested",agentsMd:writeAgentsBlock(join7(root,"AGENTS.md"))};if(result.gaugeJson==="created")writeFileSync(manifest,JSON.stringify({version:2,inputs:{}},null,2)+"\n");mkdirSync(gaugeDir,{recursive:true,mode:448});writeFileSync(join7(gaugeDir,".gitignore"),"*\n");writeFileSync(join7(gaugeDir,"config.json"),JSON.stringify({version:1,backend},null,2)+"\n",{mode:384});const store=openLocalStore(gaugeDir);store.close();if(result.casesDir==="created"){mkdirSync(casesPath);writeFileSync(join7(casesPath,".gitkeep"),"")}return result}function writeAgentsBlock(path){if(!existsSync3(path)){writeFileSync(path,`${AGENTS_BLOCK}
|
|
721
754
|
`);return"created"}const text=readFileSync6(path,"utf8");const start=text.indexOf(START);const end=start===-1?-1:text.indexOf(END,start);if(end===-1){const separator=text===""?"":text.endsWith("\n")?"\n":"\n\n";writeFileSync(path,`${text}${separator}${AGENTS_BLOCK}
|
|
722
755
|
`);return"added"}const next=text.slice(0,start)+AGENTS_BLOCK+text.slice(end+END.length);if(next===text)return"unchanged";writeFileSync(path,next);return"updated"}var LOGO=String.raw`
|
|
723
756
|
|
|
@@ -738,30 +771,30 @@ ${END}`;function scaffoldWorkspace(root,backend2,cases=false){mkdirSync(root,{re
|
|
|
738
771
|
⠉⠛⠛⠛⠛⠁⠘⠛⠃⠈⠙⠛⠛⠋⠘⠛⠃ ⠙⠛⠛⠋⠘⠛⠃⢀⣈⣙⠛⠋⠁⣿⣿ ⠉⠛⠛⠛⠛⠁ ⠈⠻⣿⣿⣿⣿⡿⠿⠛⠛⠛⠋
|
|
739
772
|
⠻⢿⣷⣶⣿⠿⠋ ⠈⠿⠟⠁
|
|
740
773
|
`;var SMALL_LOGO=String.raw`█▀▀ ▄▀█ █ █ █▀▀ █▀▀
|
|
741
|
-
█▄█ █▀█ █▄█ █▄█ ██▄`;async function printLogo(){const out=process.stdout;if(detectAgent(process.env,out.isTTY)==="agent"){console.log(SMALL_LOGO);return}if(process.env.CI||process.env.TERM==="dumb"){console.log(LOGO.replace(/^\n+/,""));return}out.write("\x1B[?25l");try{out.write(LOGO);const up=`\x1B[${LOGO.split("\n").length-1}A`;for(const[frame,wait]of[[BARK,220],[LOGO,150],[BARK,220],[LOGO,150],[BARK,220],[LOGO,150]]){await delay(wait);out.write(up+frame.replace(/\n/g,"\x1B[K\n"))}out.write("\n")}finally{out.write("\x1B[?25h")}}function nextSteps(mode){const bold=style("1");const cyan=style("36");const dim=style("2");const lines=[];lines.push(` ${bold("1. Install the Gauge agent skill")}`);lines.push(` ${cyan("$ gauge install-skill")}`);lines.push(` ${dim("\xB7")} Recommended. It teaches your coding agent the Gauge workflows.`);if(detectAgent(process.env,process.stdout.isTTY)==="agent")lines.push(` ${dim("\xB7")} Ask the user whether to install it, unless already installed or declined.`);lines.push("");(mode==="hosted"?HOSTED_STEPS:LOCAL_STEPS).forEach((step,i)=>{lines.push(` ${bold(`${i+2}. ${step.title}`)}`);if(step.command)lines.push(` ${cyan(`$ ${step.command}`)}`);for(const detail of step.details)lines.push(` ${dim("\xB7")} ${detail}`);lines.push("")});lines.push(`Agents: add ${cyan("-o json")} to any gauge command for JSON output.`);lines.push(`Docs: ${cyan(DOCS_URL)}`);return lines.join("\n")}function summarize(result){return`${result.gaugeJson==="created"?"Created":"Kept"} gauge.json. Backend: ${result.backend} (.gauge/config.json). Local state: .gauge/gauge.sqlite.${result.casesDir==="not-requested"?"":` Shared cases: gauge-cases/ (${result.casesDir}).`}`}function
|
|
742
|
-
${result.problem.hint}`)}if(!result.ready)process.exitCode=1}function register15(program2){const local=program2.commands.find(command=>command.name()==="local")??program2.command("local").description("Configure local execution (no Gauge account needed)");const runtime=local.command("runtime").description("Inspect or download the supported Docker runtime");runtime.command("inspect").description("Report local runtime availability and compatibility without downloading").action((_options,command)=>print(inspectLocalRuntime(),command));runtime.command("pull").description("Download the CLI's supported public runtime image").action(async(_options,command)=>print(await pullLocalRuntime(),command))}var mcp_exports={};__export(mcp_exports,{register:()=>register16});import{readFileSync as readFileSync7}from"fs";function mcpPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/mcp-servers`}function serverPath(org,ref){return`${mcpPath(org)}/${encodeURIComponent(ref)}`}function specLabel(spec){return spec.transport==="stdio"?[spec.command,...spec.args??[]].join(" "):spec.url??""}function specFromOpts(opts){if(opts.specFile!==void 0){if(opts.command!==void 0||opts.url!==void 0)throw new CliError("usage","--spec-file conflicts with --command/--url");try{return JSON.parse(readFileSync7(opts.specFile==="-"?0:opts.specFile,"utf8"))}catch(e){throw new CliError("usage",`could not read --spec-file: ${e instanceof Error?e.message:e}`)}}if(opts.command!==void 0===(opts.url!==void 0))throw new CliError("usage","pass exactly one of --command (stdio) or --url (http), or --spec-file");const tools=opts.tool.map(line=>{const colon=line.indexOf(":");return colon>0?{name:line.slice(0,colon).trim(),description:line.slice(colon+1).trim()}:{name:line.trim()}});return{transport:opts.command!==void 0?"stdio":"http",...opts.command!==void 0?{command:opts.command,args:opts.arg,envNames:opts.env}:{url:opts.url,headerNames:opts.header},...opts.serverName?{serverName:opts.serverName}:{},...opts.description?{description:opts.description}:{},...tools.length?{tools}:{}}}function register16(program2){const group=hostedOnly(program2.command("mcp"),{hint:LOCAL_MCP_HINT}).description("Manage MCP servers used by hosted eval and preference runs");group.command("list").description("List the org's MCP servers with their newest version").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(mcpPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(s=>({name:s.name,latest:s.latestVersion?.label??"",versions:s.versionCount,transport:s.latestVersion?.spec.transport??"",invocation:s.latestVersion?specLabel(s.latestVersion.spec):"",note:s.note??""})),"table")});group.command("get <ref>").description("Show one MCP server: note and every version").action(async(ref,_opts,cmd)=>{const org=resolveOrg(cmd);const server=await createClient().get(serverPath(org,ref));if(resolveOutput(cmd)==="json"){printJson(server);return}console.log(`name: ${server.name}`);console.log(`id: ${server.id}`);console.log(`note: ${server.note??"(none)"}`);console.log("versions:");for(const v of server.versions){console.log(` ${server.name}@${v.label} [${v.spec.transport}] ${specLabel(v.spec)} ${v.createdAt}`);for(const w of v.warnings)console.log(` warning: ${w.message}`)}});group.command("add").description("Add a server, or append a version to an existing --name (versions are immutable)").requiredOption("--name <handle>","the handle (the agent config key)").option("--command <cmd>","stdio launch command, e.g. npx").option("--arg <arg>","stdio argument (repeatable)",collect2,[]).option("--env <NAME>","required env-var NAME \u2014 never a value (repeatable)",collect2,[]).option("--url <url>","http endpoint").option("--header <NAME>","required header NAME \u2014 never a value (repeatable)",collect2,[]).option("--server-name <name>","agent-visible server name (default: handle)").option("--description <text>","agent-visible description").option("--tool <name[: description]>","declared tool (repeatable)",collect2,[]).option("--spec-file <path>",'whole spec as JSON ("-" for stdin)').option("--label <label>","version label (a typed label always mints; omitted dedups by spec digest)").option("--note <text>","note shown on the index").action(async(opts,cmd)=>{const org=resolveOrg(cmd);const result=await createClient().post(mcpPath(org),{name:opts.name,spec:specFromOpts(opts),label:opts.label,note:opts.note});if(resolveOutput(cmd)==="json"){printJson(result);return}console.log(result.unchanged?`Already current: ${result.handle}@${result.label} carries this spec`:`Saved ${result.handle}@${result.label} \u2014 ${result.invocation}`);for(const w of result.warnings)console.error(`warning: ${w.message}`);console.error(`Attach it to an eval: gauge eval edit <id> --mcp ${result.handle}@${result.label}`)});group.command("edit <ref>").description("Rename or note a server (append versions with `gauge mcp add --name <handle>`)").option("--rename <handle>","new handle (name@label refs must be updated)").option("--note <text>","replace the note").option("--clear-note","remove the note").action(async(ref,opts,cmd)=>{const org=resolveOrg(cmd);if(opts.note!==void 0&&opts.clearNote)throw new CliError("usage","--note and --clear-note conflict");const body={};if(opts.rename!==void 0)body.name=opts.rename;if(opts.clearNote)body.note=null;else if(opts.note!==void 0)body.note=opts.note;if(Object.keys(body).length===0)throw new CliError("usage","nothing to change");const updated=await createClient().patch(serverPath(org,ref),body);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated MCP server ${updated.name}`)});group.command("rm <ref>").description("Remove a server; the handle stays reserved and finished runs keep their snapshot").action(async(ref,_opts,cmd)=>{const org=resolveOrg(cmd);const result=await createClient().delete(serverPath(org,ref));if(resolveOutput(cmd)==="json")printJson(result);else console.log(`Deleted MCP server ${ref} (${result.referencedRuns} finished run(s) referenced it)`)})}var members_exports={};__export(members_exports,{register:()=>register17});function register17(program2){const group=hostedOnly(program2.command("members")).description("Team members and pending invites (read-only)");group.command("list").description("List members and pending invites").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const client=createClient();const base=`/api/v1/orgs/${encodeURIComponent(org)}`;const[members,pending]=await Promise.all([client.get(`${base}/members`),client.get(`${base}/invites`)]);if(resolveOutput(cmd)==="json"){printJson({members:members.items,invites:pending.items});return}printItems(members.items.map(m=>({email:m.email??"",name:m.name??"",joined:m.joinedAt})),"table");if(pending.items.length>0){console.log("\npending invites:");printItems(pending.items.map(i=>({id:i.id,email:i.email,"invited by":i.invitedBy.email??i.invitedBy.name??"",expires:i.expiresAt})),"table")}})}var models_exports={};__export(models_exports,{capabilityLabel:()=>capabilityLabel,executionTargetsPath:()=>executionTargetsPath,register:()=>register18});function executionTargetsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/execution-targets`}function capabilityLabel(capabilities){return Object.entries(capabilities).filter(([,supported])=>supported).map(([name])=>name==="agentContext"?"context":name).join(", ")}function register18(program2){const group=program2.command("models").description("Discover supported models, harnesses, and providers");group.command("list",{isDefault:true}).description("List execution targets available to the organization. Local: the agents local runs support, with default models").action(async(_opts,cmd)=>{if(gaugeState(cmd).mode==="local"){const agents=Object.entries(LOCAL_AGENTS).map(([agent,target])=>({agent,harness:target.kind,defaultModel:target.model}));if(resolveOutput(cmd)==="json")printJson(agents);else printItems(agents,"table");return}const org=resolveOrg(cmd);const response=await createClient().get(executionTargetsPath(org));if(resolveOutput(cmd)==="json"){printJson(response.items);return}printItems(response.items.map(target=>({model:target.model,name:target.modelLabel,harness:target.harnessSlug,provider:target.providerSlug,capabilities:capabilityLabel(target.capabilities)})),"table")})}var localProfiles_exports={};__export(localProfiles_exports,{register:()=>register19});function register19(program2){const local=program2.commands.find(command=>command.name()==="local")??program2.command("local").description("Configure local execution");const profiles=local.command("profiles").description("Manage local agent credentials (references only; separate from Gauge account login)");profiles.command("list").description("List profiles and per-harness defaults; never print secrets").action((_opts,cmd)=>{const store=readProfiles();printItems(Object.entries(store.profiles).map(([name,p])=>({name,...p,active:store.defaults[p.agent]===name})),resolveOutput(cmd))});profiles.command("set <profile>").description("Create a profile or update it with --replace; --env takes a variable name, never a secret").requiredOption("--agent <agent>","CLAUDE_CODE, CODEX_CLI, PI, or OPENCODE").requiredOption("--provider <provider>","anthropic, openai, openai-codex, fireworks, or openrouter").requiredOption("--auth <mode>","access_token (native login), api_key, or setup_token (Claude only)").option("--env <variable>","environment variable holding the key/token (defaults to the provider's standard variable)").option("--replace","replace an existing profile").action((name,opts,cmd)=>{const{replace,...profile}=opts;const store=setProfile(name,profile,replace);const result={name,...store.profiles[name],active:store.defaults[profile.agent]===name};if(resolveOutput(cmd)==="json")printJson(result);else console.log(`Saved profile ${name}. Select with gauge local profiles use ${name}, or gauge run --local --profile ${name}.`)});profiles.command("use <profile>").description("Set the default for this profile's harness").action((name,_opts,cmd)=>{const store=readProfiles();const profile=requireProfile(store,name);store.defaults[profile.agent]=name;writeProfiles(store);if(resolveOutput(cmd)==="json")printJson({agent:profile.agent,profile:name});else console.log(`${profile.agent} now uses ${name}.`)});profiles.command("remove <profile>").description("Remove a reference and its default selection; keep native logins and environment variables").action((name,_opts,cmd)=>{const store=readProfiles();requireProfile(store,name);delete store.profiles[name];const cleared=Object.keys(store.defaults).filter(agent=>store.defaults[agent]===name);for(const agent of cleared)delete store.defaults[agent];writeProfiles(store);if(resolveOutput(cmd)==="json")printJson({removed:name,clearedDefaults:cleared});else console.log(`Removed ${name}.${cleared.length?` ${cleared.join(", ")} now uses automatic credential discovery.`:""}`)});profiles.command("inspect <profile>").description("Check local compatibility, credential availability and expiry; does not call the provider").option("--model <model>","check this model (default: the harness's default model)").action(async(name,opts,cmd)=>{const store=readProfiles();const p=requireProfile(store,name);if(!opts.model&&(p.agent==="PI"||p.agent==="OPENCODE")&&!LOCAL_TARGETS[p.agent].model.startsWith(`${p.provider}/`)){throw new CliError("usage",`Specify --model ${p.provider}/<model> to inspect this profile.`,{hint:`The ${p.agent} default model uses a different provider. Choose a model available through ${p.provider}.`})}const result=await inspectLocalCredential(p.agent,opts.model??LOCAL_TARGETS[p.agent].model,{profile:name},store);if(resolveOutput(cmd)==="json")printJson(result);else{console.log(`${name}: ${result.ready?"ready locally":"not ready"} for ${result.agent} ${result.model}`);if(result.profile)console.log(`Source: ${result.profile.source}; auth: ${result.profile.auth}`);if(result.expiresAt)console.log(`Expires: ${result.expiresAt}`);if(result.problem)console.log(result.problem);console.log("Local checks do not verify provider acceptance or model access.")}if(!result.ready)process.exitCode=1})}var onboard_exports={};__export(onboard_exports,{register:()=>register20});var PERSONAL_DOMAINS=new Set(["gmail.com","googlemail.com","yahoo.com","hotmail.com","outlook.com","live.com","icloud.com","me.com","aol.com","proton.me","protonmail.com"]);function emailDomain(email){const domain=email?.split("@")[1]?.toLowerCase();return domain&&!PERSONAL_DOMAINS.has(domain)?domain:void 0}function orgNameFromEmail(email){const base=emailDomain(email)?.split(".")[0]??"";if(!base)return"My Workspace";return base.charAt(0).toUpperCase()+base.slice(1)}function websiteFromEmail(email){const domain=emailDomain(email);return domain?`https://${domain}`:void 0}async function ensureAccount(opts={}){const log=opts.log??console.log;let client;let me;if(resolveToken()){client=new ApiClient;me=await client.get("/api/v1/me");log(`Already signed in as ${me.user.email??me.user.id}.`)}else{const login=await deviceLogin({email:opts.email});saveToken(login.token);me=login.me;client=new ApiClient({token:login.token});log(`
|
|
743
|
-
Signed in as ${me.user.email??me.user.id} \u2014 token saved to ${credentialsPath()}.`)}const wantNewOrg=opts.new===true||opts.orgName!==void 0||me.orgs.length===0;let org;let createdOrg=null;const website=opts.website??websiteFromEmail(me.user.email);if(wantNewOrg){const name=opts.orgName?.trim()||orgNameFromEmail(me.user.email);createdOrg=await client.post("/api/v1/orgs",{name,website});org=createdOrg.slug}else{org=readConfig().defaultOrg??me.orgs[0]?.slug??"";if(!org)throw new CliError("internal","No workspace available; re-run with --org-name to create one.")}updateConfig({defaultOrg:org});log(createdOrg?`Created workspace ${createdOrg.name} (${org}).`:`Using workspace ${org}.`);let seeded=null;if(opts.seed!==false&&createdOrg){log("Seeding starter measurements (scanning your site)\u2026");try{seeded=await client.post(`/api/v1/orgs/${encodeURIComponent(org)}/onboarding/seed`,website?{website}:{});log(`Seeded ${seeded.evalSets} eval set(s) and ${seeded.visibilityPrompts} preference prompt(s)`+(seeded.markets?` across ${seeded.markets} market(s).`:"."))}catch(e){console.error(`warning: seeding skipped \u2014 ${e instanceof Error?e.message:e}`)}}return{user:me.user,org,createdOrg,seeded}}function register20(program2){hostedOnly(program2.command("onboard"),{account:true}).description("Sign in to hosted Gauge and set up your workspace. Then run `gauge init --hosted` in a repo to connect it").option("--email <email>","email a sign-in link (device-flow convenience)").option("--org-name <name>","workspace name (default: from your email)").option("--website <url>","company site, scanned to seed the workspace (default: from your email)").option("--new","create a new workspace even if you already belong to one").option("--no-seed","skip seeding starter eval sets and the Agent Preference portfolio").action(async(opts,command)=>{const output=resolveOutput(command);const account=await ensureAccount({...opts,log:output==="json"?()=>{}:console.log});if(output==="json"){printJson({user:account.user,org:account.createdOrg??{slug:account.org},defaultOrg:account.org,seeded:account.seeded});return}console.log(`
|
|
744
|
-
Default org set to ${account.org}. You're ready:`);console.log(" gauge status # the org at a glance");console.log(" gauge eval list # eval sets"," gauge preference list # preference prompts");console.log(" gauge run --eval <id> # launch one now");let inRepo=false;try{inRepo=gaugeState(command).inRepo}catch{}console.log(inRepo?" gauge init --hosted # connect this repo":" gauge init --hosted # connect a repo (run it inside the repo)")})}var optimizations_exports={};__export(optimizations_exports,{NEEDS_INPUT_EXIT:()=>NEEDS_INPUT_EXIT,awaitingInput:()=>awaitingInput,parseStatuses:()=>parseStatuses,parseSubject:()=>parseSubject,parseTarget:()=>parseTarget,readSkillDir:()=>readSkillDir,register:()=>register21,trialBodyFromOpts:()=>trialBodyFromOpts,trialTemplate:()=>trialTemplate,trialWarnings:()=>trialWarnings,watchStops:()=>watchStops});import{readdirSync,readFileSync as readFileSync8,statSync as statSync2}from"fs";import{join as join6,relative as relative2,sep}from"path";var TERMINAL=new Set(["DONE","ARCHIVED"]);function basePath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/optimizations`}function itemPath(org,id){return`${basePath(org)}/${encodeURIComponent(id)}`}function trialPath(org,id,trialId){return`${itemPath(org,id)}/trials/${encodeURIComponent(trialId)}`}var FAILED_RUN=new Set(["FAILED","TIMED_OUT"]);function readText(path){return readFileSync8(path==="-"?0:path,"utf8")}function sleep2(ms){return new Promise(resolve6=>setTimeout(resolve6,ms))}function parseSubject(opts){if(opts.eval&&opts.preference)throw new CliError("usage","pass --eval or --preference, not both");if(opts.eval)return{subjectKind:"EVAL_SET",subjectId:opts.eval};if(opts.preference)return{subjectKind:"VISIBILITY_PROMPT",subjectId:opts.preference};throw new CliError("usage","pass --eval <id> or --preference <id>")}function parseTarget(raw){const spec=parseAgentSpec(raw);if(spec.models.length>1)throw new CliError("usage",`--target "${raw}" names several models; an optimization pins exactly one`);return spec.models.length?{agent:spec.agent,model:spec.models[0]}:{agent:spec.agent}}function parseCount(raw,flag,max=100){if(raw===void 0)return void 0;const n=Number(raw);if(!Number.isInteger(n)||n<1||n>max)throw new CliError("usage",`${flag} must be a positive integer no greater than ${max}`);return n}var NEEDS_INPUT_EXIT=4;var NEXT_ACTION_HINT={START:"start the draft: `gauge optimizations start-draft <id>`",WAIT:"sessions are running; nothing to do",AUTHOR_TRIAL:"author the next trial: `gauge optimizations trials add <id>`",LAUNCH_ROUND:"launch the saved round: `gauge optimizations launch <id>`",ADOPT:"adopt the winning trial: `gauge optimizations adopt <id> <trial>`",RESUME:"resume it in the web app, or `gauge optimizations cancel <id>`",NONE:"nothing to do in Gauge"};function awaitingInput(detail){return detail.nextAction!=="WAIT"&&detail.nextAction!=="NONE"}function watchStops(detail,follow){return TERMINAL.has(detail.status)||detail.nextAction==="NONE"||!follow&&awaitingInput(detail)}function readObject(path){let value;try{value=JSON.parse(readText(path))}catch{throw new CliError("usage","the file must contain valid JSON")}if(!value||typeof value!=="object"||Array.isArray(value))throw new CliError("usage","the file must contain a JSON object");return value}function targetFromOpts(opts){return opts.target?{target:parseTarget(opts.target)}:{}}function parseStatuses(raw){if(!raw)return void 0;const parts=raw.split(",").map(part=>part.trim().toUpperCase()).filter(Boolean);for(const part of parts)if(!["DRAFT","ACTIVE","PAUSED","DONE","ARCHIVED"].includes(part))throw new CliError("usage",`unknown status "${part}" (expected DRAFT, ACTIVE, PAUSED, DONE, ARCHIVED)`);return parts.join(",")}function readSkillDir(dir,read2=readText,walk=listFiles){const paths=walk(dir).sort();if(!paths.length)throw new CliError("usage",`no files under ${dir} to send`);const files=paths.map(path=>({path:relative2(dir,path).split(sep).join("/"),body:read2(path)}));if(!files.some(file=>file.path==="SKILL.md"))throw new CliError("usage",`${dir} has no SKILL.md; a skill bundle must carry one`);return files}function listFiles(dir){let entries;try{entries=readdirSync(dir).map(String)}catch{throw new CliError("usage",`cannot read the directory ${dir}`)}return entries.flatMap(entry=>{const path=join6(dir,entry);return statSync2(path).isDirectory()?listFiles(path):[path]})}function trialBodyFromOpts(opts,read2=readText,walk){const launch2=opts.launch===true;const idempotencyKey=opts.idempotencyKey;if(opts.file){let parsed;try{parsed=JSON.parse(read2(opts.file))}catch{throw new CliError("usage","the trial file must contain valid JSON")}const pick=parseCount(opts.pick,"--pick")??1;let chosen;if(Array.isArray(parsed)){if(pick>parsed.length)throw new CliError("usage",`--pick ${pick} but the file holds ${parsed.length} proposal${parsed.length===1?"":"s"}`);chosen=parsed[pick-1]}else{if(opts.pick!==void 0)throw new CliError("usage","--pick applies to a proposals array");chosen=parsed}if(!chosen||typeof chosen!=="object"||Array.isArray(chosen))throw new CliError("usage","the trial file must contain an object or a non-empty array of objects");const record2=chosen;const body="trial"in record2?record2:{trial:record2};return{...body,...idempotencyKey?{idempotencyKey}:{},launch:launch2}}if(!opts.title)throw new CliError("usage","--title is required");const lever=opts.lever?.toUpperCase();let intervention;let files;if(opts.page||opts.bodyFile){if(!opts.page||!opts.bodyFile)throw new CliError("usage","--page and --body-file go together");intervention={kind:"REWRITE_DOCS",after:{pages:[{url:opts.page,body:read2(opts.bodyFile)}]}}}else if(opts.editSkill){if(!opts.skillDir)throw new CliError("usage","--edit-skill needs --skill-dir <path>: an edit sends the complete bundle");intervention={kind:"EDIT_SKILL",before:{skillVersionId:opts.editSkill},after:{skillVersionId:opts.editSkill}};files=readSkillDir(opts.skillDir,read2,walk)}else{throw new CliError("usage","describe the change: --edit-skill <id> --skill-dir <path>, --page <url> --body-file <path>, or --file <trial.json>")}const trial={title:opts.title,hypothesis:opts.hypothesis,lever:lever??(intervention.kind==="REWRITE_DOCS"?"DOCS":"SKILL"),intervention,authorMode:"MANUAL"};return{trial,...files?{files}:{},...idempotencyKey?{idempotencyKey}:{},launch:launch2}}var TRIAL_TEMPLATES={EDIT_SKILL:{trial:{title:"Name the env var in the first line",hypothesis:"The agent reads only the opening paragraph",lever:"SKILL",intervention:{kind:"EDIT_SKILL",before:{skillVersionId:"sv_REPLACE_ME"},after:{skillVersionId:"sv_REPLACE_ME"}},authorMode:"MANUAL"},files:[{path:"SKILL.md",body:"# Skill\n\nThe complete rewritten file.\n"}]},REWRITE_DOCS:{trial:{title:"Move the auth note above the example",hypothesis:"The agent copies the example before reading the note",lever:"DOCS",intervention:{kind:"REWRITE_DOCS",after:{pages:[{url:"https://example.com/docs/quickstart",body:"The complete rewritten page body."}]}},authorMode:"MANUAL"}}};function trialTemplate(kind){const template=TRIAL_TEMPLATES[kind.trim().toUpperCase()];if(!template)throw new CliError("usage",`--kind must be one of ${Object.keys(TRIAL_TEMPLATES).join(", ")} (got "${kind}")`);return template}function pct(value){return value===null||value===void 0?"\u2014":`${Math.round(value*100)}%`}function subjectLabel(kind){return kind==="EVAL_SET"?"eval":"preference"}function toRow2(o){return{id:o.id,name:o.name.length>40?`${o.name.slice(0,37)}...`:o.name,status:o.status,subject:`${subjectLabel(o.subjectKind)} ${o.subjectName}`,round:o.round,baseline:pct(o.before),now:pct(o.after),delta:o.delta===null?"\u2014":`${o.delta>0?"+":""}${o.delta}pt`,credits:o.creditsSpent,updated:o.updatedAt}}function trialRow(t){return{key:t.key,round:t.roundNumber,title:t.title.length>48?`${t.title.slice(0,45)}...`:t.title,surface:t.lever??"",change:t.kind,status:t.status,score:pct(t.score),result:t.verdict??"",sessions:t.sessions,failed:t.failedSessions||"",winner:t.adopted?"yes":"",id:t.id}}function printDetail2(o){console.log(`id: ${o.id}`);console.log(`name: ${o.name}`);console.log(`status: ${o.status}${o.stopReason?` (${o.stopReason})`:""}`);console.log(`mode: ${o.autonomous?"autonomous (legacy)":"interactive; launch each saved round explicitly"}`);console.log(`subject: ${subjectLabel(o.subjectKind)} ${o.subjectName} (${o.subjectId})`);console.log(`target: ${o.settings.pinnedAgent??"(subject roster)"}${o.settings.pinnedModel?`:${o.settings.pinnedModel}`:""}`);console.log(`sessions: ${o.settings.sampleCount} per trial`);console.log(`credits: ${o.creditsSpent} spent`);console.log(`score: ${pct(o.before)} \u2192 ${pct(o.after)}${o.delta===null?"":` (${o.delta>0?"+":""}${o.delta}pt)`}`);if(o.summary)console.log(`summary: ${o.summary}`);console.log(`next: ${o.nextAction} \u2014 ${NEXT_ACTION_HINT[o.nextAction]??""}`);console.log("trials:");const trials=o.rounds.flatMap(round=>round.trials);printItems(trials.map(trialRow),"table");for(const round of o.rounds)if(round.narrative)console.log(`round ${round.number}: ${round.narrative}`);for(const line of trials.flatMap(trialWarnings))console.error(line)}function runDetails(id){return`(details: \`gauge run get ${id}\`, \`gauge run get ${id} --logs\`)`}function trialWarnings(t){const total=`${t.runs.length} session${t.runs.length===1?"":"s"}`;const failed=t.runs.filter(run=>FAILED_RUN.has(run.status));const unproven=t.runs.filter(run=>!FAILED_RUN.has(run.status)&&run.cliCoverage?.instrumentationFailed);const lines=[];if(failed.length)lines.push(`WARNING ${t.key}: ${failed.length} of ${total} failed; the score and verdict leave them out. Tell the user before you trust this result.`,...failed.map(run=>` ${run.id}: ${run.status}: ${run.failureReason??run.exitReason??"no reason recorded"} ${runDetails(run.id)}`));if(unproven.length)lines.push(`WARNING ${t.key}: ${unproven.length} of ${total} have incomplete command evidence; the score counts them, but the CLI change may not have applied. Tell the user.`,...unproven.map(run=>` ${run.id}: ${runDetails(run.id)}`));return lines}function printTrial(t){console.log(`key: ${t.key} (round ${t.roundNumber}) \u2014 ${t.id}`);console.log(`title: ${t.title}`);if(t.hypothesis)console.log(`hypothesis: ${t.hypothesis}`);console.log(`change: ${t.kind}${t.lever?` on ${t.lever}`:""}`);console.log(`status: ${t.status}${t.verdict?` \xB7 ${t.verdict}`:""}${t.adopted?" \xB7 winner":""}`);console.log(`score: ${pct(t.baselineScore)} \u2192 ${pct(t.score)} over ${t.sessions} session${t.sessions===1?"":"s"}`);if(t.outcome)console.log(`outcome: ${t.outcome}`);if(t.runs.length){console.log("sessions:");for(const run of t.runs){const verdict=run.passed===null?"not assessed":run.passed?"pass":"fail";console.log(` ${run.id}: ${run.status} \xB7 ${verdict}`);if(FAILED_RUN.has(run.status))console.log(` error: ${run.failureReason??run.exitReason??"no reason recorded"}`);else if(run.cliCoverage?.instrumentationFailed)console.log(" warning: command evidence is incomplete");for(const criterion of run.criteria)console.log(` ${criterion.passed===null?"?":criterion.passed?"\u2713":"\u2717"} ${criterion.name}`)}}for(const line of trialWarnings(t))console.error(line)}function printChange(content){for(const doc of content.documents){console.log(`=== ${doc.path}`);console.log("--- before");console.log(doc.before||"(empty)");console.log("+++ after");console.log(doc.after||"(empty)")}}function printRoundPreview(preview){for(const trial of preview.trials){console.log(trial.title);for(const change of trial.changes??[]){console.log(`=== ${change.path}`);console.log(change.hunks)}for(const path of trial.droppedFiles??[])console.log(` ${path}: dropped`)}console.log(`previewDigest ${preview.previewDigest}`)}function printDiagnosis(d){console.log(`id: ${d.id}`);console.log(`status: ${d.status} over ${d.runCount} sessions`);console.log(`summary: ${d.summary??"(none)"}`);console.log(`recommended: ${d.recommendedLever??"no single lever"}`);if(d.unsupportedLevers.length)console.log(`not yet supported: ${d.unsupportedLevers.join(", ")}`);if(d.clusters.length){console.log("opportunities:");for(const cluster of d.clusters)console.log(` - ${cluster.title} [${cluster.lever??"?"} \xB7 ${Math.round(cluster.confidence*100)}%] ${cluster.failureMode}`)}}function addSubjectOptions(command){return command.option("--eval <id>","an Agent Experience eval").option("--preference <id>","an Agent Preference prompt")}function addTargetOption(command){return command.option("--target <agent[:model]>","the one harness/model every session runs on, e.g. claude-code:claude-opus-4-8")}function register21(program2){const group=hostedOnly(program2.command("optimizations")).description("Start, steer, and read optimizations: Gauge changes one owned surface per trial and reports the best measured change against the baseline");group.command("list").description("List the org's optimizations, newest activity first").option("--status <statuses>","comma-separated: DRAFT,ACTIVE,PAUSED,DONE,ARCHIVED").option("--no-drafts","leave out draft workspaces").option("--eval <id>","only optimizations on this eval").option("--preference <id>","only optimizations on this preference prompt").option("--limit <n>","max rows (default 50)").action(async(opts,cmd)=>{const org=resolveOrg(cmd);const subject=opts.eval||opts.preference?parseSubject(opts):void 0;const res=await createClient().get(basePath(org),{status:parseStatuses(opts.status),subjectKind:subject?.subjectKind,subjectId:subject?.subjectId,limit:parseCount(opts.limit,"--limit",200),includeDrafts:opts.drafts});if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(toRow2),"table")});addSubjectOptions(group.command("baselines").description("Discover which ordinary runs exposed which owned surfaces, and whether they can seed an optimization")).option("--limit <n>","page size (1\u2013100)","50").option("--cursor <cursor>","nextCursor from the previous page").action(async(opts,cmd)=>{const response=await createClient().get(`${basePath(resolveOrg(cmd))}/baselines`,{...parseSubject(opts),limit:parseCount(opts.limit,"--limit"),cursor:opts.cursor});if(resolveOutput(cmd)==="json")printJson(response);else{printItems(response.items.flatMap(run=>(run.surfaces.length?run.surfaces:[{lever:"\u2014",label:"No recorded surface evidence"}]).map(surface=>({run:run.runId,model:run.model||run.resolvedModel||run.agent,date:run.createdAt.slice(0,10),criteria:run.outcome.totalCriteria?`${run.outcome.passedCriteria}/${run.outcome.totalCriteria}`:"\u2014",status:run.status,surface:surface.lever,target:surface.label,eligible:run.eligibility.eligible?"yes":"no"}))),"table");for(const run of response.items)if(run.eligibility.reason)console.log(`${run.runId}: ${run.eligibility.reason}`);console.log(response.note);if(response.nextCursor)console.log(`More: --cursor ${response.nextCursor}`)}});group.command("get <id>").description("One optimization: settings, score, and its trial ladder").action(async(id,_opts,cmd)=>{const org=resolveOrg(cmd);const detail=await createClient().get(itemPath(org,id));if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});addSubjectOptions(group.command("diagnose").description("Improvement opportunities for an eval or preference prompt from its judged sessions")).action(async(opts,cmd)=>{const org=resolveOrg(cmd);const diagnosis=await createClient().post(`${basePath(org)}/diagnoses`,parseSubject(opts));if(resolveOutput(cmd)==="json")printJson(diagnosis);else printDiagnosis(diagnosis)});addTargetOption(addSubjectOptions(group.command("start").description("Reuse a selected baseline with --from-run, or establish one with --target"))).option("--from-run <runId>","reuse the eligible baseline containing this run; inherits its model").option("--name <name>","optimization name (default: from the subject)").option("--yes","skip the confirmation").action(async(opts,cmd)=>{const org=resolveOrg(cmd);if(!!opts.target===!!opts.fromRun)throw new CliError("usage","pass --from-run <runId> or --target <agent[:model]>, not both; discover runs with `gauge optimizations baselines`");const subject=parseSubject(opts);await confirmOrAbort(opts.fromRun?`Start an optimization from the baseline containing ${opts.fromRun}?`:`Start an optimization on ${subjectLabel(subject.subjectKind)} ${subject.subjectId}? A new baseline may spend credits.`,opts.yes);const detail=await createClient().post(basePath(org),{...subject,...targetFromOpts(opts),...opts.fromRun?{fromRun:opts.fromRun}:{},name:opts.name});if(resolveOutput(cmd)==="json")printJson(detail);else{console.log(`Started ${detail.id} "${detail.name}". Each round waits for you to launch it. Follow the baseline with \`gauge optimizations watch ${detail.id}\`.`)}});group.command("cancel <id>").description("Cancel an optimization and stop its in-flight sessions").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{const org=resolveOrg(cmd);await confirmOrAbort(`Cancel optimization ${id}? In-flight sessions stop; completed usage remains billed.`,opts.yes);const detail=await createClient().post(`${itemPath(org,id)}/cancel`,{});if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`${detail.id}: ${detail.status}${detail.stopReason?` (${detail.stopReason})`:""}`)});addTargetOption(addSubjectOptions(group.command("create").description("Create a draft workspace without running sessions"))).option("--name <name>","optimization name").action(async(opts,cmd)=>{const detail=await createClient().post(`${basePath(resolveOrg(cmd))}/drafts`,{...parseSubject(opts),...targetFromOpts(opts),name:opts.name});if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});addTargetOption(group.command("edit <id>").description("Edit name/direction, or a draft's target")).option("--name <name>","optimization name").option("--file <path>","PATCH body JSON (name, direction, target); '-' for stdin").action(async(id,opts,cmd)=>{const body={...opts.file?readObject(opts.file):{},...targetFromOpts(opts),...opts.name?{name:opts.name}:{}};if(!Object.keys(body).length)throw new CliError("usage","pass --target, --name, or --file");const detail=await createClient().patch(itemPath(resolveOrg(cmd),id),body);if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});addTargetOption(group.command("start-draft <id>").description("Start an existing draft's baseline (spends credits)")).option("--name <name>","optimization name").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{const org=resolveOrg(cmd);const client=createClient();const plan=targetFromOpts(opts);const current=await client.get(itemPath(org,id));if(current.status!=="DRAFT")throw new CliError("usage","only a draft can start; use continue instead");if(!plan.target&&!current.settings.pinnedAgent)throw new CliError("usage","--target is required until the draft has an agent/model");await confirmOrAbort(`Start the baseline for ${id}? It spends credits now.`,opts.yes);const detail=await client.post(`${itemPath(org,id)}/start`,{...plan,name:opts.name});if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});group.command("launch <id>").description("Launch all saved trials in the current round (spends credits)").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{await confirmOrAbort(`Launch the current round of ${id}? Spends credits.`,opts.yes);const result=await createClient().post(`${itemPath(resolveOrg(cmd),id)}/rounds/current/launch`,{});if(resolveOutput(cmd)==="json")printJson(result);else console.log(result.alreadyLaunched?"Round already launched.":`Launched ${result.launched.length} trials in round ${result.roundNumber}.`)});group.command("continue <id>").description("Reopen a finished optimization for another round against its fixed baseline").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{await confirmOrAbort(`Reopen ${id} for another round? Saved trials still require launch.`,opts.yes);const detail=await createClient().post(`${itemPath(resolveOrg(cmd),id)}/continue`,{});if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});group.command("activity <id>").description("Read the optimization's decision log").option("--after <timestamp>","entries after this ISO timestamp").option("--limit <n>","maximum entries (1\u2013500)").action(async(id,opts,cmd)=>{const res=await createClient().get(`${itemPath(resolveOrg(cmd),id)}/activity`,{after:opts.after,limit:parseCount(opts.limit,"--limit",500)});if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(row2=>({at:row2.createdAt,kind:row2.kind,actor:row2.actorName??"Worker",summary:row2.summary})),"table")});group.command("chat <id>").description("Resolve your optimization chat and print its URL path").action(async(id,_opts,cmd)=>{const res=await createClient().post(`${itemPath(resolveOrg(cmd),id)}/chat`,{});if(resolveOutput(cmd)==="json")printJson(res);else console.log(res.href)});group.command("rm <id>").description("Delete an optimization, retaining billed session history").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{await confirmOrAbort(`Delete optimization ${id}, its rounds, trials, and activity? Session history is kept.`,opts.yes);await createClient().delete(itemPath(resolveOrg(cmd),id));if(resolveOutput(cmd)==="json")printJson({deleted:id});else console.log(`Deleted ${id}.`)});group.command("complete <id>").description("Complete an optimization: it reads as Finished, not canceled").option("--adopt <trialId>","mark this settled trial as the winner").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{const org=resolveOrg(cmd);await confirmOrAbort(`Complete optimization ${id}? No further rounds run; unspent credits are released.`,opts.yes);const detail=await createClient().post(`${itemPath(org,id)}/complete`,opts.adopt?{adoptTrialId:opts.adopt}:{});if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`${detail.id}: ${detail.status} (${detail.stopReason})`)});group.command("watch <id>").description(`Follow until finished or awaiting input (exit ${NEEDS_INPUT_EXIT} when it needs you); --follow keeps waiting`).option("--interval <seconds>","poll interval (default 15)").option("--follow","keep polling while awaiting authoring or launch").action(async(id,opts,cmd)=>{const org=resolveOrg(cmd);const client=createClient();const interval=Number(opts.interval??15);if(!Number.isFinite(interval)||interval<=0)throw new CliError("usage","--interval must be a positive finite number");const intervalMs=Math.max(interval*1e3,2e3);let last="";for(;;){const detail=await client.get(itemPath(org,id));const trials2=detail.rounds.flatMap(round2=>round2.trials);const failed=trials2.reduce((sum,trial)=>sum+trial.failedSessions,0);const line=`${detail.status}${detail.stopReason?` (${detail.stopReason})`:""} \xB7 round ${detail.round} \xB7 ${pct(detail.before)} \u2192 ${pct(detail.after)} \xB7 ${detail.creditsSpent} credits spent${failed?` \xB7 ${failed} failed session${failed===1?"":"s"}`:""} \xB7 ${trials2.filter(t=>t.status==="RUNNING").map(t=>t.key).join(",")||"idle"}`;if(line!==last){last=line;console.error(line)}const needsInput=awaitingInput(detail);if(watchStops(detail,!!opts.follow)){if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail);if(needsInput)process.exitCode=NEEDS_INPUT_EXIT;return}await sleep2(intervalMs)}});group.command("authoring <id>").description("What the next round may change: exposed surfaces, CLI targets, baseline run evidence, revision").action(async(id,_opts,cmd)=>{printJson(await createClient().get(`${itemPath(resolveOrg(cmd),id)}/authoring`))});group.command("cli-change <id>").description("Validate and seal v3 {schemaVersion:3, target, rules, shippingIntent}; use the output as intervention.after in a round file. Saves nothing").requiredOption("--file <path>","the change JSON; '-' for stdin").action(async(id,opts,cmd)=>{printJson(await createClient().post(`${itemPath(resolveOrg(cmd),id)}/cli-changes`,readObject(opts.file)))});const round=group.command("round").description("Preview and save the round waiting to launch. A round file is {revision, trials: [{trial: {title, hypothesis, lever, intervention}, files?}]}; revision comes from `authoring`");round.command("preview <id>").description("Validate a round file and print its diff and previewDigest").requiredOption("--file <path>","the round JSON; '-' for stdin").action(async(id,opts,cmd)=>{const preview=await createClient().post(`${itemPath(resolveOrg(cmd),id)}/rounds/current/preview`,readObject(opts.file));if(resolveOutput(cmd)==="json")printJson(preview);else printRoundPreview(preview)});round.command("save <id>").description("Save a previewed round as drafts, replacing every pending draft. Never launches").requiredOption("--file <path>","the round JSON you previewed").requiredOption("--digest <digest>","previewDigest from `round preview`").action(async(id,opts,cmd)=>{const result=await createClient().put(`${itemPath(resolveOrg(cmd),id)}/rounds/current`,{...readObject(opts.file),previewDigest:opts.digest});if(resolveOutput(cmd)==="json")printJson(result);else for(const trial of result.trials)console.log(`Saved ${trial.key} "${trial.title}"`)});const trials=group.command("trials").description("List, author, and run trials");trials.command("list <id>").description("Every trial of an optimization with score and verdict").action(async(id,_opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(`${itemPath(org,id)}/trials`);if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(trialRow),"table")});trials.command("add <id>").description("Save an authored draft trial; --launch also runs it (spends credits)").option("--file <path>","authored trial JSON, as `trials template` prints it: one {trial, files?} or an array; '-' for stdin").option("--pick <n>","which trial to take from an array (default 1)").option("--title <text>","what the change is").option("--hypothesis <text>","why it should help").option("--lever <lever>","DOCS, MARKETING_SITE, SKILL, SDK, CLI").option("--edit-skill <id>","skill version to rewrite (with --skill-dir); see `gauge optimizations skill-files <id>`").option("--skill-dir <path>","local directory holding the complete edited bundle, SKILL.md included").option("--page <url>","docs page to rewrite (with --body-file)").option("--body-file <path>","the rewritten page body; '-' for stdin").option("--launch","run the trial after saving (spends credits); otherwise save a draft").option("--idempotency-key <key>","a retry with this key returns the first call's trial instead of a second one").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{const org=resolveOrg(cmd);const body=trialBodyFromOpts(opts);if(body.launch!==false)await confirmOrAbort(`Run trial "${body.trial.title}" on ${id} now? Spends credits.`,opts.yes);const result=await createClient().post(`${itemPath(org,id)}/trials`,body);if(resolveOutput(cmd)==="json")printJson(result);else if(result.replayed)console.log(`Replayed ${result.trial.key} "${result.trial.title}" (${result.trial.status}) \u2014 this key already authored it`);else console.log(`${result.launch?"Running":"Saved"} ${result.trial.key} "${result.trial.title}"${result.launch?` \u2014 ${result.launch.runIds.length} session${result.launch.runIds.length===1?"":"s"}`:""}`)});trials.command("template").description("Print a trial JSON skeleton for `trials add --file`").requiredOption("--kind <kind>","EDIT_SKILL or REWRITE_DOCS").action(opts=>{printJson(trialTemplate(opts.kind))});trials.command("run <id> <trialId>").description("Run a draft trial now (spends credits)").option("--yes","skip the confirmation").action(async(id,trialId,opts,cmd)=>{const org=resolveOrg(cmd);await confirmOrAbort(`Run trial ${trialId} now? Spends credits.`,opts.yes);const result=await createClient().post(`${trialPath(org,id,trialId)}/launch`,{});if(resolveOutput(cmd)==="json")printJson(result);else console.log(`Started ${result.runIds.length} session${result.runIds.length===1?"":"s"} for ${trialId}`)});trials.command("rm <id> <trialId>").description("Drop one draft trial from the round waiting to launch").option("--yes","skip the confirmation").action(async(id,trialId,opts,cmd)=>{await confirmOrAbort(`Remove draft ${trialId} from ${id}?`,opts.yes);const detail=await createClient().delete(trialPath(resolveOrg(cmd),id,trialId));if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`Removed ${trialId}.`)});group.command("trial <id> <trialId>").description("One trial by id or key (B0, R1.1, \u2026) with its sessions").action(async(id,trialId,_opts,cmd)=>{const org=resolveOrg(cmd);const trial=await createClient().get(trialPath(org,id,trialId));if(resolveOutput(cmd)==="json")printJson(trial);else printTrial(trial)});group.command("change <id> <trialId>").description("The change a trial made: before and after text per document").option("--body","print only the pasteable page body of a docs rewrite").action(async(id,trialId,opts,cmd)=>{const org=resolveOrg(cmd);const content=await createClient().get(`${trialPath(org,id,trialId)}/content`);if(resolveOutput(cmd)==="json")printJson(content);else if(opts.body){if(content.copyableBody===null)throw new CliError("usage","this trial is not a docs rewrite; drop --body");console.log(content.copyableBody)}else printChange(content)});group.command("adopt <id> <trialId>").description("Mark a settled trial as the winner without changing the baseline").option("--yes","skip the confirmation").action(async(id,trialId,opts,cmd)=>{const org=resolveOrg(cmd);await confirmOrAbort(`Mark ${trialId} as the winner on ${id}?`,opts.yes);const detail=await createClient().post(`${trialPath(org,id,trialId)}/adopt`,{});if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`Marked ${trialId} as the winner.`)});group.command("handoff <id>").description("The instructions a coding agent follows to land the winning trial in your source, as the web app's Copy instructions for agent").action(async(id,_opts,cmd)=>{const handoff=await createClient().get(`${itemPath(resolveOrg(cmd),id)}/handoff`);if(resolveOutput(cmd)==="json")printJson(handoff);else process.stdout.write(handoff.prompt)});group.command("skill-files <versionId>").description("The text files of a skill version, the base a skill-edit trial edits").action(async(versionId,_opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(`${basePath(org)}/skill-versions/${encodeURIComponent(versionId)}`);if(resolveOutput(cmd)==="json")printJson(res);else for(const file of res.files){console.log(`=== ${file.path}`);console.log(file.body)}});group.command("page <id>").description("The baseline body of a docs page, the base a docs-rewrite trial edits").requiredOption("--url <url>","the page URL").action(async(id,opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(`${itemPath(org,id)}/page`,{url:opts.url});if(resolveOutput(cmd)==="json")printJson(res);else{if(res.source==="scrape")console.error("Source: fresh scrape; this is not the captured baseline response.");else if(res.source==="none")console.error("No page body is available.");console.log(res.body)}})}var org_exports={};__export(org_exports,{register:()=>register22});function printSettings(s,billingStatus){console.log(`slug: ${s.slug}`);console.log(`name: ${s.name}`);console.log(`website: ${s.website??"(none)"}`);console.log(`max spend/run: ${s.maxSpendUsd==null?"(server default)":`$${s.maxSpendUsd}`}`);console.log(`overage: ${fmtOverage(billingStatus)}`);console.log(`auto-join: ${s.autoJoinDomain??"off"}`)}function register22(program2){const group=hostedOnly(program2.command("org")).description("This org's settings, read-only (see `gauge orgs` for the org list)");group.command("get").description("Show the org's settings (edit them in the web app)").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const client=createClient();const base=`/api/v1/orgs/${encodeURIComponent(org)}`;const[settings,billingStatus]=await Promise.all([client.get(base),client.get(`${base}/billing`)]);if(resolveOutput(cmd)==="json")printJson({...settings,paymentType:billingStatus.paymentType??null,creditLine:billingStatus.creditLine??null});else printSettings(settings,billingStatus)})}var orgs_exports={};__export(orgs_exports,{register:()=>register23});function isDefault(org,defaultOrg){return defaultOrg!==void 0&&(org.slug===defaultOrg||org.publicId===defaultOrg)}function register23(program2){const orgs=hostedOnly(program2.command("orgs"),{account:true}).description("Organizations");orgs.command("list").description("List orgs you belong to").action(async(_opts,command)=>{const output=resolveOutput(command);const me=await createClient().get("/api/v1/me");const{defaultOrg}=readConfig();if(output==="json"){printJson(me.orgs.map(org=>({...org,isDefault:isDefault(org,defaultOrg)})));return}printItems(me.orgs.map(org=>({slug:org.slug,name:org.name,publicId:org.publicId??"",default:isDefault(org,defaultOrg)?"*":""})),"table")});orgs.command("create <name>").description("Create a new LOCAL workspace and set it as the default org").option("--website <url>","company site (used as the logo source)").option("--no-use","don't set the new org as the default").action(async(name,opts,command)=>{const created=await createClient().post("/api/v1/orgs",{name,website:opts.website});if(opts.use!==false)updateConfig({defaultOrg:created.slug});if(resolveOutput(command)==="json"){printJson(created);return}console.log(`Created workspace ${created.name} (${created.slug})`);if(opts.use!==false){console.log(`Default org set to ${created.slug}`)}});orgs.command("use <org>").description("Set the default org (slug or public id) in local config").action(async(org,_opts,command)=>{const resolved=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}`).catch(e=>{if(e instanceof CliError&&e.code==="not_found")throw new CliError("not_found",`Organization "${org}" was not found. Run \`gauge orgs list\`.`);throw e});updateConfig({defaultOrg:resolved.slug});if(resolveOutput(command)==="json"){printJson({defaultOrg:resolved.slug});return}console.log(`Default org set to ${resolved.slug} (${resolved.name})`)})}var personas_exports={};__export(personas_exports,{register:()=>register24});function personasPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/personas`}function register24(program2){const group=hostedOnly(program2.command("personas")).description("Manage simulated-user personas for eval and preference runs");group.command("list").description("List the org's personas").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(personasPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(p=>({id:p.id,name:p.name,description:p.description.length>60?`${p.description.slice(0,57)}...`:p.description})),"table")});group.command("get <id>").description("Show one persona").action(async(id,_opts,cmd)=>{const org=resolveOrg(cmd);const persona=await createClient().get(`${personasPath(org)}/${encodeURIComponent(id)}`);if(resolveOutput(cmd)==="json"){printJson(persona);return}console.log(`id: ${persona.id}`);console.log(`name: ${persona.name}`);console.log(`model: ${persona.model}`);console.log(`description: ${persona.description}`)});group.command("add").description("Create a persona").requiredOption("--name <name>","persona name").requiredOption("--description <text>",'memory-style notes ("The user is a solo founder\u2026")').action(async(opts,cmd)=>{const org=resolveOrg(cmd);const created=await createClient().post(personasPath(org),{name:opts.name,description:opts.description});if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created persona ${created.id} (${created.name})`)});group.command("edit <id>").description("Update a persona").option("--name <name>","rename the persona").option("--description <text>","replace the notes").action(async(id,opts,cmd)=>{const org=resolveOrg(cmd);if(opts.name===void 0&&opts.description===void 0)throw new CliError("usage","nothing to change");const updated=await createClient().patch(`${personasPath(org)}/${encodeURIComponent(id)}`,{name:opts.name,description:opts.description});if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated persona ${updated.id}`)});group.command("rm <id>").description("Delete a persona (run configurations fall back to the default persona)").action(async(id,_opts,cmd)=>{const org=resolveOrg(cmd);await createClient().delete(`${personasPath(org)}/${encodeURIComponent(id)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted persona ${id}`)})}var preference_exports={};__export(preference_exports,{register:()=>register25});function visibilityPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/visibility-prompts`}function promptPath(org,id){return`${visibilityPath(org)}/${encodeURIComponent(id)}`}function scenariosPath(org,id){return`${promptPath(org,id)}/scenarios`}function scenarioRow(scenario){return{id:scenario.id,repo:scenario.repoUrl??"(empty project)",ref:scenario.repoRef??"",persona:scenario.profile?.name??"(default)"}}var KIND_CHOICES=["head-to-head","open-ended"];function parseKind(raw){const upper=raw==="open-ended"?"RECOMMEND":raw.trim().toUpperCase().replace(/-/g,"_");if(upper!=="HEAD_TO_HEAD"&&upper!=="RECOMMEND")throw new CliError("usage",`invalid --kind "${raw}" (expected: ${KIND_CHOICES.join(" | ")})`);return upper}function brandsLabel(v){if(v.kind==="HEAD_TO_HEAD")return`${v.brandA} vs ${v.brandB}`;return v.branded?v.brandA??"branded":"organic"}function preferencePromptRow(v){return{id:v.id,name:v.name,kind:v.kind==="RECOMMEND"?"open-ended":"head-to-head",brands:brandsLabel(v),market:v.market?.slug??"",tags:v.tags.join(", "),runs:v.runCount,"last run":v.lastRunAt??"-"}}function printDetail3(v){console.log(`id: ${v.id}`);console.log(`name: ${v.name}`);console.log(`kind: ${v.kind==="RECOMMEND"?"open-ended":"head-to-head"}`);console.log(`brands: ${brandsLabel(v)}`);console.log(`market: ${v.market?`${v.market.name} (${v.market.slug})`:"(none)"}`);console.log(`tags: ${v.tags.join(", ")||"(none)"}`);console.log(`runs: ${v.runCount} (last: ${v.lastRunAt??"never"})`);console.log(`prompt: ${v.promptText}`);console.log(`cadence: ${cadenceLabel(v.cadence)} \u2014 ${v.sampleCount} sample(s)`);console.log(`agents: ${v.agents.map(a=>a.models.length?`${a.agent}:${a.models.join(",")}`:a.agent).join(", ")}`);console.log(`skills: ${v.skillRefs.join(", ")||"(none)"}`);console.log(`mcp: ${v.mcpRefs.join(", ")||"(none)"}`);console.log(`conns: ${v.connectionIds.join(", ")||"(none)"}`);console.log(`scenarios: ${v.scenarios.length}`);for(const scenario of v.scenarios)console.log(` [${scenario.id}] ${scenario.repoUrl??"(empty project)"}${scenario.repoRef?`@${scenario.repoRef}`:""} \u2014 ${scenario.profile?.name??"default persona"}`)}async function listPreferencePrompts(cmd){if(isLocal(cmd))return listLocalMeasurements(cmd,"preference");const res=await createClient().get(visibilityPath(resolveOrg(cmd)));return res.items}async function getPreferencePrompt(cmd,id){const vp=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"preference",id)):await createClient().get(promptPath(resolveOrg(cmd),id));if(resolveOutput(cmd)==="json")printJson(vp);else printDetail3(vp)}async function createPreferencePrompt(cmd,opts){if(opts.kind===void 0)throw new CliError("usage",`--kind is required with --preference (${KIND_CHOICES.join(" | ")})`);if(opts.ref!==void 0&&opts.repo===void 0)throw new CliError("usage","--ref requires --repo");const hasScenario=opts.repo!==void 0||opts.persona!==void 0;const body={name:opts.name,promptText:readPromptText(opts),kind:parseKind(opts.kind),branded:opts.branded,brandA:opts.brandA??null,brandB:opts.brandB??null,marketId:opts.market??null,tags:opts.tag.length>0?opts.tag:void 0,...hasRunSettingsFlags(opts)?runSettingsFromOpts(opts):{},scenarios:hasScenario?[{repoUrl:opts.repo??null,repoRef:opts.ref??null,profileId:opts.persona??null}]:[]};const created=isLocal(cmd)?createLocalMeasurement(cmd,"preference",body):await createClient().post(visibilityPath(resolveOrg(cmd)),body);if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created preference prompt ${created.id}`)}async function editPreferencePrompt(cmd,id,opts){const body={...runSettingsPatchFromOpts(opts)};if(opts.name!==void 0)body.name=opts.name;if(opts.text!==void 0||opts.file!==void 0)body.promptText=readPromptText(opts);if(opts.brandA!==void 0)body.brandA=opts.brandA;if(opts.brandB!==void 0)body.brandB=opts.brandB;if(opts.branded&&opts.organic)throw new CliError("usage","--branded and --organic conflict");if(opts.branded)body.branded=true;else if(opts.organic)body.branded=false;if(opts.market!==void 0&&opts.clearMarket)throw new CliError("usage","--market and --clear-market conflict");if(opts.clearMarket)body.marketId=null;else if(opts.market!==void 0)body.marketId=opts.market;if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");if(opts.clearTags)body.tags=[];else if(opts.tag.length>0)body.tags=opts.tag;if(Object.keys(body).length===0)throw new CliError("usage","nothing to change");const updated=isLocal(cmd)?editLocalMeasurement(cmd,"preference",id,body):await createClient().patch(promptPath(resolveOrg(cmd),id),body);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated preference prompt ${updated.id}`)}async function removePreferencePrompt(cmd,id){if(isLocal(cmd))removeLocalMeasurement(cmd,"preference",id);else await createClient().delete(promptPath(resolveOrg(cmd),id));if(resolveOutput(cmd)!=="json")console.log(`Deleted preference prompt ${id}`)}async function listScenarios(cmd,id){const vp=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"preference",id)):await createClient().get(promptPath(resolveOrg(cmd),id));if(resolveOutput(cmd)==="json")printJson(vp.scenarios);else printItems(vp.scenarios.map(scenarioRow),"table")}async function addScenario(cmd,id,opts){if(opts.ref!==void 0&&opts.repo===void 0)throw new CliError("usage","--ref requires --repo");if(isLocal(cmd)){if(opts.persona)throw new CliError("usage","Personas require hosted Gauge");const row2=getLocalMeasurement(cmd,"preference",id);const updated=editLocalMeasurement(cmd,"preference",id,{scenarios:[...row2.scenarios,{repoUrl:opts.repo??null,repoRef:opts.ref??null,profileId:null}]});const scenario=updated.scenarios.at(-1);if(resolveOutput(cmd)==="json")printJson(scenario);else console.log(`Added scenario ${scenario.id}`);return}const created=await createClient().post(scenariosPath(resolveOrg(cmd),id),{repoUrl:opts.repo??null,repoRef:opts.ref??null,profileId:opts.persona??null});if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Added scenario ${created.id}`)}async function removeScenario(cmd,id,scenarioId){if(isLocal(cmd)){const row2=getLocalMeasurement(cmd,"preference",id);const scenarios=row2.scenarios;if(!scenarios.some(s=>s.id===scenarioId))throw new CliError("usage",`Unknown scenario: ${scenarioId}`);editLocalMeasurement(cmd,"preference",id,{scenarios:scenarios.filter(s=>s.id!==scenarioId)});if(resolveOutput(cmd)!=="json")console.log(`Removed scenario ${scenarioId}`);return}await createClient().delete(`${scenariosPath(resolveOrg(cmd),id)}/${encodeURIComponent(scenarioId)}`);if(resolveOutput(cmd)!=="json")console.log(`Removed scenario ${scenarioId}`)}async function runPreferencePrompt(cmd,id,opts){const org=resolveOrg(cmd);const overrides=runOverridesFromOpts(opts);const settings=Object.keys(overrides).length>0?"these overrides (stored settings stay unchanged)":"the stored settings";await confirmOrAbort(opts.scenario.length>0?`Run ${opts.scenario.length} selected scenario${opts.scenario.length===1?"":"s"} with ${settings} now?`:`Run every scenario of this prompt with ${settings} now?`,opts.yes);const result=await createClient().post(`${promptPath(org,id)}/run`,{visibilityScenarioIds:opts.scenario.length>0?opts.scenario:void 0,...overrides});if(resolveOutput(cmd)==="json")printJson(result);else{console.log(`Started ${result.runIds.length} run${result.runIds.length===1?"":"s"} across ${result.batchIds.length} scenario${result.batchIds.length===1?"":"s"}`);for(const batch of result.batchIds)console.log(`Runs: gauge run list --batch ${batch}`)}}async function listPreferencePromptRuns(cmd,id,opts){const res=await createClient().get(`${promptPath(resolveOrg(cmd),id)}/runs`,{limit:opts.limit,cursor:opts.cursor});if(resolveOutput(cmd)==="json"){printJson(res);return}printItems(res.items.map(r=>({id:r.id,status:r.status,agent:r.agent,model:r.resolvedModel??r.model??"",source:r.triggeredBy?.source??"",credits:r.creditsCharged??"",created:r.createdAt,verdict:r.verdict?.status??"-"})),"table");if(res.nextCursor)console.error(`(more results \u2014 rerun with --cursor ${res.nextCursor})`)}async function markets(cmd,opts){if(isLocal(cmd))throw new CliError("usage","Markets require hosted Gauge. Pass --hosted.");const client=createClient();const base=`/api/v1/orgs/${encodeURIComponent(resolveOrg(cmd))}/markets`;if(opts.add!==void 0){const market=await client.post(base,{marketId:opts.add});if(resolveOutput(cmd)==="json")printJson(market);else console.log(`Tracking market ${market.name} (${market.slug})`);return}const res=await client.get(base);if(resolveOutput(cmd)==="json"){printJson(res);return}printItems([...res.tracked.map(m=>({id:m.marketId,slug:m.slug,name:m.name,tracked:"yes",source:m.source})),...res.addable.map(m=>({id:m.marketId,slug:m.slug,name:m.name,tracked:"no",source:""}))],"table")}function register25(program2){const preference=program2.command("preference").description("Manage preference prompts: which product agents choose. Launch one with `gauge run --preference <id>`");preference.command("list").description("List preference prompts").action(async(_opts,cmd)=>{const items=await listPreferencePrompts(cmd);if(resolveOutput(cmd)==="json")printJson(items);else printItems(items.map(preferencePromptRow),"table")});preference.command("get <id>").description("Show one preference prompt").action(async(id,_opts,cmd)=>{await getPreferencePrompt(cmd,id)});addRunSettingsCreateOptions(preference.command("create").description("Create a preference prompt").requiredOption("--name <name>","name").option("--text <text>","prompt text inline").option("--file <path>",'prompt text from a file ("-" for stdin)').option("--repo <url>","the first scenario's repository (default: empty project)").option("--ref <ref>","branch, tag, or commit (with --repo)").option("--persona <profileId>","persona profile id")).option("--kind <kind>",KIND_CHOICES.join(" | ")).option("--brand-a <name>","first brand (head-to-head)").option("--brand-b <name>","second brand (head-to-head)").option("--branded","an open-ended prompt that names a brand").option("--market <marketId>","tracked market id (see `gauge preference markets`)").option("--tag <name>","user tag name, create-on-type (repeatable)",collect2,[]).action(async(opts,cmd)=>{await createPreferencePrompt(cmd,opts)});addRunSettingsEditOptions(preference.command("edit <id>").description("Update a preference prompt. Omitted flags keep their value.").option("--name <name>","rename it").option("--text <text>","replace the prompt text inline").option("--file <path>",'replace the prompt text from a file ("-" stdin)')).option("--brand-a <name>","first brand").option("--brand-b <name>","second brand").option("--branded","mark branded (open-ended only)").option("--organic","mark organic (open-ended only)").option("--market <marketId>","set the measured market").option("--clear-market","unscope from any market").option("--tag <name>","replace the user tag set (repeatable)",collect2,[]).option("--clear-tags","remove all user tags").action(async(id,opts,cmd)=>{await editPreferencePrompt(cmd,id,opts)});preference.command("rm <id>").description("Delete a preference prompt (run history stays)").action(async(id,_opts,cmd)=>{await removePreferencePrompt(cmd,id)});const scenarios=preference.command("scenarios").description("The repo \xD7 persona scenarios a preference prompt runs in");scenarios.command("list <id>").description("List a preference prompt's scenarios").action(async(id,_opts,cmd)=>{await listScenarios(cmd,id)});scenarios.command("add <id>").description("Add one repo \xD7 persona scenario").option("--repo <url>","repository URL (default: empty project)").option("--ref <ref>","branch, tag, or commit (with --repo)").option("--persona <profileId>","persona profile id (default persona if omitted)").action(async(id,opts,cmd)=>{await addScenario(cmd,id,opts)});scenarios.command("rm <id>").description("Remove one scenario").requiredOption("--scenario <scenarioId>","scenario id to remove").action(async(id,opts,cmd)=>{await removeScenario(cmd,id,opts.scenario)});preference.command("markets").description("List tracked and addable markets for preference prompts, or track one with --add").option("--add <marketId>","track a published market").action(async(opts,cmd)=>{await markets(cmd,opts)})}var query_exports={};__export(query_exports,{register:()=>register26});import{join as join9}from"path";var dimension=(sql,description,type="string")=>({sql,description,type});var metric=(sql,description,type="number")=>({sql,description,type});var common={run:dimension("s.id","Session ID"),batch:dimension("s.batch_id","Launch batch ID"),eval:dimension("CASE WHEN s.measurement_kind = 'eval' THEN s.measurement_id END","Saved eval ID"),preference:dimension("CASE WHEN s.measurement_kind = 'preference' THEN s.measurement_id END","Saved preference prompt ID"),measurement_revision:dimension("s.measurement_revision","Frozen measurement revision","number"),agent:dimension("s.agent","Coding agent"),model:dimension("s.model","Agent model"),date:dimension("date(s.created_at)","Session creation date (UTC)","date")};var catalogs=[{name:"runs",grain:"One local session (current attempt)",from:"sessions s",dimensions:{...common,case:dimension("s.case_path","File-based case path, when applicable"),outcome:dimension("s.outcome","Execution outcome; this is not an eval verdict"),analyzed:dimension("s.current_analysis_id IS NOT NULL","Whether this attempt has published analysis","boolean"),analysis_id:dimension("s.current_analysis_id","Current published analysis ID")},metrics:{run_count:metric("COUNT(*)","Number of sessions"),analyzed_runs:metric("COALESCE(SUM(CASE WHEN s.current_analysis_id IS NOT NULL THEN 1 ELSE 0 END),0)","Sessions with published analysis"),avg_turns:metric("AVG(s.turns)","Average recorded turns; unknown values excluded"),avg_duration_ms:metric("AVG(s.duration_ms)","Average recorded duration in milliseconds; unknown values excluded"),input_tokens:metric("SUM(s.input_tokens)","Recorded input tokens; null when none have been recorded"),output_tokens:metric("SUM(s.output_tokens)","Recorded output tokens; null when none have been recorded")}},{name:"findings",grain:"One finding in a session's current published analysis",from:"sessions s JOIN session_analyses a ON a.id = s.current_analysis_id JOIN session_findings f ON f.analysis_id = a.id",dimensions:{...common,analysis_id:dimension("a.id","Current published analysis ID"),kind:dimension("f.kind","FRICTION, OBJECTION, or OPPORTUNITY"),subject:dimension("f.subject","Product or surface discussed"),label:dimension("f.label","Finding title; matching labels do not imply a shared theme"),basis:dimension("f.basis","OBSERVED, AGENT_CLAIM, or INFERRED"),effect:dimension("f.effect","Effect on the session"),cause:dimension("f.cause","Attributed cause")},metrics:{finding_count:metric("COUNT(*)","Findings in current published analyses"),affected_runs:metric("COUNT(DISTINCT s.id)","Distinct sessions with matching findings")}}];function localQueryMetadata(){return{datasets:catalogs.map(catalog=>({name:catalog.name,grain:catalog.grain,dimensions:Object.entries(catalog.dimensions).map(([name,field])=>({name,type:field.type,description:field.description})),metrics:Object.entries(catalog.metrics).map(([name,field])=>({name,type:field.type,description:field.description}))}))}}function queryLocal(gaugeDir,input){const compiled=compileLocalQuery(input);const store=openLocalStore(gaugeDir);store.db.exec("BEGIN");try{if(compiled.catalog.name==="findings"){const versions=store.db.prepare(compiled.findingVersionsSql).all(...compiled.coverageParams);const unsupported=versions.find(row2=>row2.schema_version!==ANALYSIS_SCHEMA_VERSION);if(unsupported)throw new CliError("usage",`A selected session's analysis uses schema version ${unsupported.schema_version}; this CLI supports ${ANALYSIS_SCHEMA_VERSION}. Upgrade Gauge before querying these findings. Your data is intact.`)}const rows=store.db.prepare(compiled.sql).all(...compiled.params);for(const row2 of rows)for(const name of compiled.dimensions){if(compiled.catalog.dimensions[name].type==="boolean"&&row2[name]!==null)row2[name]=Boolean(row2[name])}const coverage=store.db.prepare(compiled.coverageSql).get(...compiled.coverageParams);const response={columns:[...compiled.dimensions.map(key=>({key,kind:"dimension"})),...compiled.metrics.map(key=>({key,kind:"metric"}))],rows,...input.explain?{sql:compiled.sql}:{},freshness:{available:true,pending:0,watermark:coverage.watermark},analysisCoverage:{sessions:Number(coverage.total),analyzedSessions:Number(coverage.analyzed),unanalyzedSessions:Number(coverage.total)-Number(coverage.analyzed)}};store.db.exec("COMMIT");return response}catch(error){store.db.exec("ROLLBACK");throw error}finally{store.close()}}function compileLocalQuery(input){if(!input||typeof input!=="object"||Array.isArray(input))throw new CliError("usage","A query must be a JSON object.");const topKeys=new Set(["dataset","dimensions","metrics","filters","where","dateRange","orderBy","limit","granularity","explain"]);for(const key of Object.keys(input))if(!topKeys.has(key))throw new CliError("usage",`Unknown local query option "${key}". See gauge query fields --local --dataset runs.`);const name=input.dataset??"runs";const catalog=catalogs.find(item=>item.name===name);if(!catalog)throw new CliError("usage",`Dataset "${name}" is not supported by the local backend. Available: runs, findings.`,{hint:"Run gauge query datasets --local to discover local capabilities, or use --hosted for hosted datasets."});const dimensions=input.dimensions??[];const metrics=input.metrics;if(!Array.isArray(dimensions)||dimensions.some(key=>typeof key!=="string"))throw new CliError("usage","Query dimensions must be an array of field names.");if(!Array.isArray(metrics)||metrics.length===0||metrics.some(key=>typeof key!=="string"))throw new CliError("usage","At least one metric is required.");if(new Set([...dimensions,...metrics]).size!==dimensions.length+metrics.length)throw new CliError("usage","Select each query field only once.");const unsupported=(kind,field)=>{throw new CliError("usage",`${kind} "${field}" is not supported by the local ${name} dataset.`,{hint:`Run gauge query fields --dataset ${name} --local to discover supported fields; hosted capabilities may differ.`})};const granularity=input.granularity??"day";if(!["day","week","month"].includes(granularity))throw new CliError("usage","Granularity must be day, week, or month.");const dateSql=granularity==="month"?"date(s.created_at,'start of month')":granularity==="week"?"date(s.created_at,'-' || ((CAST(strftime('%w',s.created_at) AS INTEGER) + 6) % 7) || ' days')":"date(s.created_at)";const expr=key=>key==="date"?dateSql:Object.hasOwn(catalog.dimensions,key)?catalog.dimensions[key].sql:unsupported("Dimension",key);for(const key of dimensions)expr(key);for(const key of metrics)if(!Object.hasOwn(catalog.metrics,key))unsupported("Metric",key);const limit=input.limit??50;if(!Number.isInteger(limit)||limit<1||limit>1e3)throw new CliError("usage","Query limit must be an integer from 1 to 1000.");const params=[];const predicates=[];const coveragePredicates=[];const coverageParams=[];const bind=value=>{if(typeof value!=="string"&&typeof value!=="boolean"&&(typeof value!=="number"||!Number.isFinite(value)))throw new CliError("usage","Query filter values must be strings, booleans, or finite numbers.");params.push(typeof value==="boolean"?Number(value):value);return"?"};const where=input.where??[];if(!Array.isArray(where))throw new CliError("usage","Query where must be an array of predicates.");for(const clause of where){const paramStart=params.length;const predicateStart=predicates.length;if(!clause||typeof clause!=="object"||Object.keys(clause).some(key=>!["dimension","op","value"].includes(key)))throw new CliError("usage","Each where predicate requires dimension, op, and value.");const sql2=expr(clause.dimension);if(clause.op==="in"||clause.op==="notIn"){if(!Array.isArray(clause.value)||clause.value.length===0)throw new CliError("usage",`${clause.op} requires a nonempty value array.`);predicates.push(`${sql2} ${clause.op==="in"?"IN":"NOT IN"} (${clause.value.map(bind).join(",")})`)}else{if(Array.isArray(clause.value))throw new CliError("usage",`${clause.op} requires a scalar value.`);if(clause.op==="contains"){if(typeof clause.value!=="string")throw new CliError("usage","contains requires a string value.");predicates.push(`instr(lower(CAST(${sql2} AS TEXT)),lower(${bind(clause.value)})) > 0`)}else{const operators={eq:"=",neq:"!=",gt:">",gte:">=",lt:"<",lte:"<="};const op=operators[clause.op];if(!op)throw new CliError("usage",`Unsupported filter operator "${clause.op}".`);let value=clause.value;if(catalog.dimensions[clause.dimension].type==="number"&&typeof value==="string"&&value.trim()&&Number.isFinite(Number(value)))value=Number(value);if(catalog.dimensions[clause.dimension].type==="boolean"&&typeof value==="string"&&["true","false"].includes(value))value=value==="true";predicates.push(`${sql2} ${op} ${bind(value)}`)}}if(Object.hasOwn(common,clause.dimension)||name==="runs"){coveragePredicates.push(...predicates.slice(predicateStart));coverageParams.push(...params.slice(paramStart))}}const filterParamStart=params.length;const filterPredicateStart=predicates.length;const filters=input.filters??{};if(!filters||typeof filters!=="object"||Array.isArray(filters))throw new CliError("usage","Query filters must be an object.");const supportedFilters={agent:"s.agent",model:"s.model",prompt:"s.measurement_id",eval:"CASE WHEN s.measurement_kind = 'eval' THEN s.measurement_id END",visibilityPrompt:"CASE WHEN s.measurement_kind = 'preference' THEN s.measurement_id END"};for(const[key,value]of Object.entries(filters)){if(value===void 0)continue;if(!Object.hasOwn(supportedFilters,key))unsupported("Filter",key);const values=key==="prompt"?[value]:value;if(!Array.isArray(values)||values.length===0||values.some(item=>typeof item!=="string"))throw new CliError("usage",`Filter ${key} requires ${key==="prompt"?"a string":"a nonempty array of strings"}.`);predicates.push(`${supportedFilters[key]} IN (${values.map(bind).join(",")})`)}const range=input.dateRange;if(range!==void 0){if(!range||typeof range!=="object"||Array.isArray(range))throw new CliError("usage","Query dateRange must be an object.");for(const key of Object.keys(range))if(!["since","until","lastDays"].includes(key))throw new CliError("usage",`Unknown dateRange field ${key}.`);if(range.since!==void 0&&range.lastDays!==void 0)throw new CliError("usage","Use dateRange.since or dateRange.lastDays, not both.");if(range.lastDays!==void 0&&(!Number.isInteger(range.lastDays)||range.lastDays<=0))throw new CliError("usage","lastDays must be a positive integer.");const since=range.since!==void 0?dateValue(range.since):range.lastDays!==void 0?new Date(Date.now()-range.lastDays*864e5).toISOString():null;const until=range.until!==void 0?dateValue(range.until):null;if(since&&until&&since>until)throw new CliError("usage","Query since must be before until.");if(since)predicates.push(`julianday(s.created_at) >= julianday(${bind(since)})`);if(until)predicates.push(`julianday(s.created_at) <= julianday(${bind(until)})`)}coveragePredicates.push(...predicates.slice(filterPredicateStart));coverageParams.push(...params.slice(filterParamStart));const selected=new Set([...dimensions,...metrics]);const order=input.orderBy??[];if(!Array.isArray(order))throw new CliError("usage","Query orderBy must be an array.");for(const item of order){if(!item||!selected.has(item.key))throw new CliError("usage",`Order field "${item?.key}" must be one of the selected dimensions or metrics.`);if(item.dir!==void 0&&item.dir!=="asc"&&item.dir!=="desc")throw new CliError("usage","Order direction must be asc or desc.")}const columns=[...dimensions.map(key=>`${expr(key)} AS "${key}"`),...metrics.map(key=>`${catalog.metrics[key].sql} AS "${key}"`)];const sql=`SELECT ${columns.join(", ")} FROM ${catalog.from}${predicates.length?` WHERE ${predicates.map(predicate=>`(${predicate})`).join(" AND ")}`:""}${dimensions.length?` GROUP BY ${dimensions.map(expr).join(", ")}`:""}${order.length?` ORDER BY ${order.map(item=>`"${item.key}" ${(item.dir??"desc").toUpperCase()}`).join(", ")}`:""} LIMIT ${limit}`;const coverageWhere=coveragePredicates.length?` WHERE ${coveragePredicates.map(predicate=>`(${predicate})`).join(" AND ")}`:"";const coverageSql=`SELECT COUNT(*) AS total,COUNT(current_analysis_id) AS analyzed,MAX(COALESCE(ended_at,created_at)) AS watermark FROM sessions s${coverageWhere}`;const findingVersionsSql=`SELECT DISTINCT a.schema_version FROM sessions s JOIN session_analyses a ON a.id = s.current_analysis_id${coverageWhere}`;return{sql,params,coverageSql,coverageParams,findingVersionsSql,catalog,dimensions,metrics}}function dateValue(value){if(typeof value!=="string")throw new CliError("usage","Date bounds must be ISO dates or relative windows such as 24h or 7d.");const match=/^(\d+)([mhd])$/.exec(value.trim());const date=match?new Date(Date.now()-Number(match[1])*({m:6e4,h:36e5,d:864e5}[match[2]]??0)):new Date(value);if(!Number.isFinite(date.getTime()))throw new CliError("usage",`Invalid date bound "${value}".`);return date.toISOString()}import{createReadStream,existsSync as existsSync4,realpathSync as realpathSync2}from"fs";import{isAbsolute as isAbsolute2,join as join7,relative as relative3}from"path";import{createInterface as createInterface3}from"readline";async function searchLocalTranscripts(gaugeDir,text,options={}){if(!text.trim())throw new CliError("usage","Transcript search requires nonempty text.");if(options.eval&&options.preference)throw new CliError("usage","Select either --eval or --preference for transcript search.");const limit=options.limit??50;if(!Number.isInteger(limit)||limit<1||limit>1e3)throw new CliError("usage","Search limit must be an integer from 1 to 1000.");const store=openLocalStore(gaugeDir);const sessions=(()=>{try{return store.listSessions({measurementId:options.eval??options.preference,measurementKind:options.eval?"eval":options.preference?"preference":void 0,batchId:options.batch}).filter(session=>!options.since||Date.parse(session.createdAt)>=options.since.getTime())}finally{store.close()}})();const result={matches:[],selectedSessions:sessions.length,scannedSessions:0,missingArtifacts:[],truncated:false};const needle=text.toLowerCase();for(const session of sessions){if(!/^[A-Za-z0-9_-]+$/.test(session.id))throw new CliError("usage",`Invalid local run ID: ${session.id}`);const attemptDir=join7(gaugeDir,"runs",session.id,"attempts",String(session.attempt));const path=join7(attemptDir,"session","events.ndjson");if(!existsSync4(path)){result.missingArtifacts.push(session.id);continue}const rel=relative3(realpathSync2(attemptDir),realpathSync2(path));if(isAbsolute2(rel)||rel===".."||rel.startsWith("../")||rel.startsWith("..\\"))throw new CliError("usage",`Run ${session.id} transcript resolves outside its attempt.`);result.scannedSessions++;const stream=createReadStream(path,{encoding:"utf8"});const lines=createInterface3({input:stream,crlfDelay:Infinity});let lineNumber=0;try{for await(const line of lines){lineNumber++;let event;try{event=JSON.parse(line)}catch{continue}if(!event||typeof event!=="object")continue;const content=typeof event.payload==="string"?event.payload:JSON.stringify(event.payload??event);const index=content.toLowerCase().indexOf(needle);if(index<0)continue;if(result.matches.length===limit){result.truncated=true;return result}const start=Math.max(0,index-100);const end=Math.min(content.length,Math.max(index+needle.length+200,start+400));result.matches.push({run:session.id,attempt:session.attempt,turn:typeof event.turn==="number"?event.turn:null,artifact:"session/events.ndjson",line:lineNumber,snippet:`${start?"\u2026":""}${content.slice(start,end)}${end<content.length?"\u2026":""}`})}}finally{lines.close();stream.destroy()}}return result}import{join as join8}from"path";function listLocalRuns(gaugeDir,filter={}){const store=openLocalStore(gaugeDir);try{return store.listSessions().map(session=>({...session,evalId:session.measurementKind==="eval"?session.measurementId??null:null,preferenceId:session.measurementKind==="preference"?session.measurementId??null:null,endedBy:session.endedBy??"",endedAt:session.endedAt??"",attemptDir:join8(gaugeDir,"runs",session.id,"attempts",String(session.attempt)),resultsDir:join8(gaugeDir,"runs",session.id,"results")})).filter(run=>matches(run,filter)).map(run=>{const analysis=readCurrentAnalysis(store,run.id);if(!analysis)return run;const session=store.getSession(run.id);const item=session.configuration?.case;const names=new Map((item?.criteria??[]).map(criterion=>[criterion.id,criterion.name]));return{...run,criterionResults:analysis.criteria.map(criterion=>({id:criterion.criterionId,name:names.get(criterion.criterionId)??criterion.criterionId,outcome:criterion.outcome}))}})}finally{store.close()}}function matches(run,filter){return(!filter.ids?.length||filter.ids.includes(run.id))&&(!filter.batch||run.batchId===filter.batch)&&(!filter.evalId||run.evalId===filter.evalId)&&(!filter.preferenceId||run.preferenceId===filter.preferenceId)&&(filter.measurementRevision===void 0||run.measurementRevision===filter.measurementRevision)&&(!filter.agent||run.agent===filter.agent)&&(!filter.model||run.model===filter.model)&&(!filter.outcome||filter.outcome.split(",").includes(run.outcome))&&(!filter.since||Date.parse(run.createdAt??run.endedAt)>=filter.since.getTime())&&(!filter.until||Date.parse(run.createdAt??run.endedAt)<=filter.until.getTime())&&(!filter.case||run.case===filter.case)&&(filter.analyzed===void 0||run.analyzed===filter.analyzed)}var UNIT_MS={m:6e4,h:36e5,d:864e5};function parseSince(window,now=Date.now(),flag="--since"){const relative7=/^(\d+)([mhd])$/.exec(window.trim());if(relative7)return new Date(now-Number(relative7[1])*UNIT_MS[relative7[2]]);const at=Date.parse(window);if(Number.isNaN(at))throw new CliError("usage",`invalid ${flag} "${window}" (expected 24h, 7d, or an ISO date)`);return new Date(at)}var collect3=(value,prev=[])=>[...prev,value];var csv2=raw=>raw.split(",").map(s=>s.trim()).filter(Boolean);function parseWhere(expr){const inMatch=expr.match(/^\s*(\w+)\s+(in|contains)\s+(.*)$/i);if(inMatch){const[,dimension3,opRaw,rest2]=inMatch;const op=opRaw.toLowerCase();if(op==="in"){return{dimension:dimension3,op:"in",value:csv2(rest2)}}return{dimension:dimension3,op:"contains",value:rest2.trim()}}const opMatch=expr.match(/^\s*(\w+)\s*(!=|>=|<=|=|>|<)\s*(.*)$/);if(!opMatch){throw new CliError("usage",`Could not parse --where "${expr}". Use e.g. "action=install", "ecosystem in npm,pypi", or "name contains supa".`)}const[,dimension2,sym,rest]=opMatch;const opFor={"=":"eq","!=":"neq",">":"gt",">=":"gte","<":"lt","<=":"lte"};return{dimension:dimension2,op:opFor[sym],value:rest.trim()}}function parseOrderBy(raw){const[key,dir]=raw.split(":");if(!key.trim()||dir!==void 0&&!["asc","desc"].includes(dir.trim())||raw.split(":").length>2)throw new CliError("usage",`Invalid --order-by "${raw}". Use a selected field followed by :asc or :desc.`);return{key:key.trim(),dir:dir?.trim()==="asc"?"asc":"desc"}}async function readStdin2(){const chunks=[];for await(const chunk of process.stdin)chunks.push(chunk);return Buffer.concat(chunks).toString("utf8")}async function buildSpec(opts){let spec={metrics:[]};if(opts.json){const raw=opts.json==="-"?await readStdin2():opts.json;try{spec=JSON.parse(raw)}catch(e){throw new CliError("usage",`--json is not valid JSON: ${e.message}`)}}if(!spec||typeof spec!=="object"||Array.isArray(spec))throw new CliError("usage","--json must contain a query object.");if(opts.dataset)spec.dataset=opts.dataset;if(opts.dimensions!==void 0)spec.dimensions=csv2(opts.dimensions);if(opts.metrics!==void 0)spec.metrics=csv2(opts.metrics);if(opts.where?.length)spec.where=opts.where.map(parseWhere);if(opts.orderBy?.length)spec.orderBy=opts.orderBy.map(parseOrderBy);if(opts.limit!==void 0)spec.limit=Number(opts.limit);if(opts.granularity)spec.granularity=opts.granularity;if(opts.explain)spec.explain=true;const date={...spec.dateRange??{}};if(opts.since){date.since=opts.since;delete date.lastDays}else if(opts.lastDays){date.lastDays=Number(opts.lastDays);delete date.since}if(opts.until)date.until=opts.until;if(Object.keys(date).length)spec.dateRange=date;if(opts.branded&&opts.unbranded){throw new CliError("usage","Pass at most one of --branded / --unbranded.")}const filters={...spec.filters??{}};if(opts.prompt)filters.prompt=opts.prompt;if(opts.eval)filters.eval=csv2(opts.eval);if(opts.preference)filters.visibilityPrompt=csv2(opts.preference);if(opts.tag)filters.tag=csv2(opts.tag);if(opts.repo)filters.repo=csv2(opts.repo);if(opts.language)filters.language=csv2(opts.language);if(opts.framework)filters.framework=csv2(opts.framework);if(opts.size)filters.size=csv2(opts.size);if(opts.agent)filters.agent=csv2(opts.agent);if(opts.model)filters.model=csv2(opts.model);if(opts.scenario)filters.scenario=csv2(opts.scenario);if(opts.experiment)filters.experiment=csv2(opts.experiment);if(opts.branded)filters.branded=true;if(opts.unbranded)filters.branded=false;if(Object.keys(filters).length)spec.filters=filters;if(!spec.metrics||spec.metrics.length===0){throw new CliError("usage","At least one metric is required. Pass --metrics <a,b> (or a `metrics` array in --json). See `gauge query fields --dataset <name>`.")}return spec}var pct2=n=>`${(n*100).toFixed(1)}%`;function noteFreshness(f){if(!f.available){console.error("warning: analytics store is temporarily unavailable; results may be incomplete.")}else if(f.pending>0){console.error(`note: ${f.pending} recent run(s) still ingesting; results may not reflect them yet.`)}}async function runQuery(command,opts){const output=resolveOutput(command);const spec=await buildSpec(opts);const state=gaugeState(command);const res=state.mode==="local"?queryLocal(localDirectory2(command),spec):await createClient().post(`/api/v1/orgs/${encodeURIComponent(resolveOrg(command))}/query`,spec);if(output==="json"){printJson(res);return}if(res.sql)console.error(`
|
|
745
|
-
${res.sql}
|
|
746
|
-
`);const rateKeys=new Set(res.columns.filter(c=>c.kind==="metric"&&c.key.endsWith("_rate")).map(c=>c.key));const rows=res.rows.map(row2=>{const out={};for(const col of res.columns){const v=row2[col.key];out[col.key]=rateKeys.has(col.key)&&typeof v==="number"?pct2(v):v}return out});printItems(rows,"table",res.columns.map(c=>({key:c.key})));noteFreshness(res.freshness);if("analysisCoverage"in res&&res.analysisCoverage){const coverage=res.analysisCoverage;console.error(`Analysis coverage: ${coverage.analyzedSessions}/${coverage.sessions} selected sessions analyzed; ${coverage.unanalyzedSessions} unanalyzed.`)}}async function showMetadata(command,mode,dataset){const output=resolveOutput(command);const meta=gaugeState(command).mode==="local"?localQueryMetadata():await createClient().get(`/api/v1/orgs/${encodeURIComponent(resolveOrg(command))}/query/metadata`);if(mode==="datasets"){if(output==="json")return printJson(meta.datasets.map(d=>({name:d.name,grain:d.grain})));printItems(meta.datasets.map(d=>({dataset:d.name,grain:d.grain})),"table");return}const ds=meta.datasets.find(d=>d.name===dataset);if(!ds){throw new CliError("usage",`Unknown dataset "${dataset}". Valid: ${meta.datasets.map(d=>d.name).join(", ")}.`)}if(output==="json")return printJson(ds);const rows=[...ds.dimensions.map(f=>({field:f.name,kind:"dimension",type:f.type,about:f.description??""})),...ds.metrics.map(f=>({field:f.name,kind:"metric",type:f.type,about:f.description??""}))];console.error(`dataset: ${ds.name} \u2014 ${ds.grain}`);printItems(rows,"table")}function register26(program2){const group=program2.command("query").description("Query local runs and findings or hosted analytics; discover backend capabilities");group.command("run",{isDefault:true}).description("Run a report; use query fields --dataset <name> with --local or --hosted to discover supported fields").option("--json <spec>","full query spec as JSON (or '-' to read stdin); flags override its keys").option("--dataset <name>","dataset name (local: runs | findings; use query datasets for hosted capabilities)").option("-d, --dimensions <names>","comma-separated GROUP BY dimensions").option("-m, --metrics <names>","comma-separated metrics (at least one)").option("--where <expr>",'predicate, e.g. "action=install" (repeatable)',collect3).option("--since <val>","date range start \u2014 ISO date or window (30d, 24h)").option("--until <val>","date range end \u2014 ISO date or window").option("--last-days <n>","shorthand for --since <n> days ago").option("--order-by <key:dir>","sort by a selected key, e.g. installs:desc (repeatable)",collect3).option("--limit <n>","max rows (default 50, max 1000)").option("--granularity <g>","date bucket: day | week | month (default day)").option("--explain","print the compiled SQL to stderr").option("--prompt <id>","filter to a single prompt").option("--eval <ids>","comma-separated saved eval IDs").option("--preference <ids>","comma-separated saved preference prompt IDs").option("--tag <ids>","comma-separated tag ids (hosted only)").option("--repo <urls>","comma-separated base repo urls (hosted only)").option("--language <langs>","comma-separated repo languages (hosted only)").option("--framework <names>","comma-separated repo frameworks (hosted only)").option("--size <buckets>","comma-separated codebase-size buckets (hosted only)").option("--agent <names>","comma-separated agent names").option("--model <models>","comma-separated models").option("--scenario <types>","comma-separated scenario types (greenfield|migration; hosted only)").option("--experiment <labels>","comma-separated experiment labels (hosted only)").option("--branded","only branded prompts (hosted only)").option("--unbranded","only non-branded prompts (hosted only)").action((opts,command)=>runQuery(command,opts));group.command("datasets").description("List the datasets you can query").action((_opts,command)=>showMetadata(command,"datasets"));group.command("fields").description("List the dimensions and metrics for a dataset").requiredOption("--dataset <name>","dataset to describe").action((opts,command)=>showMetadata(command,"fields",opts.dataset));group.command("search <text>").description("Search local transcript evidence without building an index").option("--eval <id>","filter to a saved eval").option("--preference <id>","filter to a saved preference prompt").option("--batch <id>","filter to one launch batch").option("--since <value>","session creation date or relative window, such as 7d").option("--limit <n>","maximum matching passages (default 50, maximum 1000)").action(async(text,opts,command)=>{if(gaugeState(command).mode!=="local")throw new CliError("usage","Transcript search is not supported by the hosted query backend. Use gauge run get <id> --logs --hosted to read a hosted transcript, or query search --local for local sessions.");const result=await searchLocalTranscripts(localDirectory2(command),text,{...opts,since:opts.since?parseSince(opts.since):void 0,limit:opts.limit===void 0?void 0:Number(opts.limit)});if(resolveOutput(command)==="json"){printJson(result);return}printItems(result.matches.map(match=>({run:match.run,attempt:match.attempt,turn:match.turn,evidence:`${match.artifact}:${match.line}`,snippet:match.snippet})),"table");console.error(`Searched ${result.scannedSessions}/${result.selectedSessions} selected sessions.${result.truncated?" More matches exist; narrow the cohort or increase --limit.":""}${result.missingArtifacts.length?` Missing transcripts: ${result.missingArtifacts.join(", ")}.`:""}`)})}function localDirectory2(command){const state=gaugeState(command);if(!state.root)throw new CliError("usage","No Gauge workspace found. Run gauge init --local in this directory first.");return join9(state.root,".gauge")}var repos_exports={};__export(repos_exports,{register:()=>register27});function reposPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/repos`}async function fetchAllRepos(client,org){return fetchAllPages(client,reposPath(org))}function toRow3(repo){return{name:repo.name,url:repo.url,languages:repo.languages.join(", "),frameworks:repo.frameworks.join(", "),tags:repo.tags.join(", "),size:repo.sizeBucket??"",stars:repo.stars,system:repo.isSystem?"yes":""}}function syncWarning(repo){return`warning: GitHub metadata sync failed; retry with \`gauge repos resync ${repo.url}\``}function register27(program2){const repos=hostedOnly(program2.command("repos")).description("Manage repositories");repos.command("list").description("List repositories (yours + read-only Gauge-provided ones)").action(async(_opts,command)=>{const org=resolveOrg(command);const output=resolveOutput(command);const items=await fetchAllRepos(createClient(),org);if(output==="json"){printJson(items);return}printItems(items.map(toRow3),"table")});repos.command("add <url>").description("Add a repository (pulls languages/size/stars from GitHub)").action(async(url,_opts,command)=>{const org=resolveOrg(command);const output=resolveOutput(command);const result=await createClient().post(reposPath(org),{url});if(output==="json"){printJson(result);return}console.log(`Added ${result.repo.name} (${result.repo.url})`);if(!result.synced)console.error(syncWarning(result.repo))});repos.command("edit <url>").description("Update a repository's display name, frameworks, or tags").option("--name <name>","display name").option("--framework <name>","REPLACE the framework list (repeatable)",collect2,[]).option("--tag <name>","REPLACE the tag list (repeatable)",collect2,[]).option("--clear-frameworks","remove all frameworks").option("--clear-tags","remove all tags").action(async(url,opts,command)=>{const org=resolveOrg(command);if(opts.framework.length>0&&opts.clearFrameworks)throw new CliError("usage","--framework and --clear-frameworks conflict");if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");const body={url};if(opts.name!==void 0)body.name=opts.name;if(opts.clearFrameworks)body.frameworks=[];else if(opts.framework.length>0)body.frameworks=opts.framework;if(opts.clearTags)body.tags=[];else if(opts.tag.length>0)body.tags=opts.tag;if(Object.keys(body).length===1)throw new CliError("usage","nothing to change");const repo=await createClient().patch(reposPath(org),body);if(resolveOutput(command)==="json")printJson(repo);else console.log(`Updated ${repo.name} (${repo.url})`)});repos.command("resync <url>").description("Re-fetch a repository's GitHub metadata").action(async(url,_opts,command)=>{const org=resolveOrg(command);const output=resolveOutput(command);const result=await createClient().post(`${reposPath(org)}/resync`,{url});if(output==="json"){printJson(result);return}if(!result.synced){throw new CliError("internal","GitHub metadata sync failed (is the URL a public GitHub repository?)")}console.log(`Re-synced ${result.repo.name} (${result.repo.url})`)});repos.command("rm <url>").description("Remove a repository from the catalog").action(async(url,_opts,command)=>{const org=resolveOrg(command);const output=resolveOutput(command);await createClient().delete(reposPath(org),{url});if(output!=="json")console.log(`Removed ${url}`)})}var run_exports={};__export(run_exports,{register:()=>register28});import{readFileSync as readFileSync11,existsSync as existsSync5,mkdirSync as mkdirSync2,writeFileSync as writeFileSync2}from"fs";import{z as z14}from"zod";import{join as join12,relative as relative6}from"path";import{z as z6}from"zod";var preferenceDefinitionSchema=z6.discriminatedUnion("kind",[z6.object({kind:z6.literal("open-ended"),branded:z6.boolean().default(false)}).strict(),z6.object({kind:z6.literal("head-to-head"),brandA:z6.string().trim().min(1),brandB:z6.string().trim().min(1)}).strict().refine(p=>p.brandA.toLowerCase()!==p.brandB.toLowerCase(),"A head-to-head needs two different brands")]);var preferenceSnapshotSchema=z6.object({version:z6.literal(1),preference:preferenceDefinitionSchema}).strict();var headToHeadSchema=z6.object({kind:z6.literal("HEAD_TO_HEAD"),assessability:z6.enum(["assessed","partial","unassessable"]).optional(),selectionStatus:z6.enum(["measured","not_measured","unassessable"]).optional(),winner:z6.enum(["A","B","both","neither"]),brandA:z6.string(),brandB:z6.string(),rationale:z6.string(),brandAReasoning:z6.string(),brandBReasoning:z6.string(),brandAWhyRaised:z6.string().optional(),brandBWhyRaised:z6.string().optional()});var recommendPickSchema=z6.object({brand:z6.string(),rank:z6.number().int(),adopted:z6.boolean(),reasoning:z6.string().optional(),whyRaised:z6.string().optional()});var recommendSchema=z6.object({kind:z6.literal("RECOMMEND"),selectedBrands:z6.array(z6.string()).optional(),assessability:z6.enum(["assessed","partial","unassessable"]).optional(),selectionStatus:z6.enum(["measured","not_measured","unassessable"]).optional(),picks:z6.array(recommendPickSchema).default([]),singlePick:z6.boolean(),complianceNote:z6.string()});var visibilityVerdictSchema=z6.discriminatedUnion("kind",[headToHeadSchema,recommendSchema]);function preferenceSelectionLabel(verdict){if(verdict.assessability==="unassessable"||verdict.selectionStatus==="unassessable")return"Not assessable";if(verdict.kind==="HEAD_TO_HEAD")return verdict.winner==="A"?verdict.brandA:verdict.winner==="B"?verdict.brandB:verdict.winner==="both"?`${verdict.brandA} and ${verdict.brandB}`:"Neither";if(verdict.selectedBrands!==void 0)return verdict.selectedBrands.length?verdict.selectedBrands.join(", "):"No selection";if(!verdict.singlePick)return verdict.picks.length?"No clear selection":"No selection";return verdict.picks.find(pick=>pick.rank===1)?.brand??"No selection"}import{Option as Option3}from"commander";import{readFileSync as readFileSync9}from"fs";import{z as z7}from"zod";function assertRequiredExperiment(spec,required){if(required.length===0){throw new CliError("invalid_request","--require-experiment requires a nonempty label")}const mismatches=[];for(const[promptIndex,prompt]of spec.prompts.entries()){const promptExperiment=prompt.experiment??spec.experiment;const schedules=prompt.schedules??[{}];if(schedules.length===0){mismatches.push(`prompts.${promptIndex}.schedules`)}for(const[scheduleIndex,schedule]of schedules.entries()){if((schedule.experiment??promptExperiment)!==required){mismatches.push(`prompts.${promptIndex}.schedules.${scheduleIndex}`)}}}if(mismatches.length>0){throw new CliError("invalid_request",`--require-experiment expected every target to resolve to ${JSON.stringify(required)}; mismatched: ${mismatches.join(", ")}`)}}var EXAMPLE_SPEC={version:1,expand:true,experiment:"my-experiment",defaults:{agents:["CLAUDE_CODE"],samplesPerCycle:3},prompts:[{key:"add-healthcheck",text:"Add a /health endpoint that returns 200 OK."},{key:"migrate-to-vitest",text:"Migrate the test suite from Jest to Vitest.",schedules:[{repoUrl:"https://github.com/acme/api",repoRef:"main",model:"claude-opus-4-8"}]}]};async function readSpecJson(source){let raw;if(source==="-"){if(process.stdin.isTTY)throw new CliError("usage","--apply - needs a run spec piped to stdin");const chunks=[];for await(const chunk of process.stdin)chunks.push(chunk);raw=Buffer.concat(chunks).toString("utf8")}else{try{raw=readFileSync9(source,"utf8")}catch(e){throw new CliError("usage",`cannot read spec file ${source}: ${e instanceof Error?e.message:String(e)}`)}}try{return JSON.parse(raw)}catch(e){throw new CliError("invalid_request",`spec is not valid JSON: ${e instanceof Error?e.message:String(e)}`)}}function parseSpec(parsed){const result=batteries_exports.batterySpecSchema.safeParse(parsed);if(!result.success){const details=result.error.issues.map(i=>` ${i.path.join(".")||"(spec)"}: ${i.message}`).join("\n");throw new CliError("invalid_request",`not a valid battery spec:
|
|
747
|
-
${details}`,{hint:"Run `gauge run --schema --hosted` for the full schema, or `gauge run --example --hosted` for a starter."})}return result.data}function resolveApplyOrg(command,spec){const{org}=command.optsWithGlobals();if(org)return org;if(typeof spec.org==="string"&&spec.org)return spec.org;const{defaultOrg}=readConfig();if(defaultOrg)return defaultOrg;throw new CliError("usage","No organization selected. Pass --org <org>, set `org` in the spec, or run `gauge orgs use <slug>`.")}function repoLabel2(repoUrl,repoRef){if(!repoUrl)return"greenfield";return repoRef?`${repoUrl}@${repoRef}`:repoUrl}function printPlan(plan){console.log(`Plan for org ${plan.org}`+(plan.experiment?` (experiment: ${plan.experiment})`:""));for(const prompt of plan.prompts){console.log(` ${prompt.action} prompt "${prompt.key}"`);for(const s of prompt.schedules){console.log(` ${s.action} schedule ${repoLabel2(s.repoUrl,s.repoRef)}`+(plan.expand?` \u2192 ${s.runs} run(s)`:""))}}const sum=plan.summary;console.log(`Prompts: ${sum.promptsToCreate} to create, ${sum.promptsToUpdate} to update; schedules: ${sum.schedulesToCreate} to create, ${sum.schedulesToUpdate} to update`);if(plan.expand){const byAgent=Object.entries(sum.runsByAgent).map(([agent,n])=>`${agent}: ${n}`).join(", ");console.log(`Runs to enqueue: ${sum.runsToEnqueue}${byAgent?` (${byAgent})`:""} \u2014 estimated ${sum.estimatedCredits} credits`)}else{console.log('No runs will be enqueued (config only \u2014 set "expand": true to run).')}console.log("Dry run \u2014 nothing was applied.")}function printApplied(res){console.log(`Applied${res.experiment?` (experiment: ${res.experiment})`:""} \u2014 ${res.batchIds.length} batch(es), ${res.runIds.length} run(s) enqueued`);for(const id of res.runIds)console.log(` run ${id}`);if(res.runIds.length>0){console.error(`(watch one live: gauge run watch ${res.runIds[0]})`)}if(res.blocked){console.error(`warning: some schedules were not expanded (${res.blocked}) \u2014 re-apply after resolving to enqueue the rest`)}}var BATTERY_SCHEMA=()=>z7.toJSONSchema(batteries_exports.batterySpecSchema);async function applySpec(command,spec,opts){if(opts.requireExperiment!==void 0)assertRequiredExperiment(spec,opts.requireExperiment);const org=resolveApplyOrg(command,spec);const result=await createClient().post(`/api/v1/orgs/${encodeURIComponent(org)}/batteries`,spec,opts.dryRun?{dryRun:1}:void 0);if(resolveOutput(command)==="json")printJson(result);else if(opts.dryRun)printPlan(result);else printApplied(result)}import{createHash as createHash3}from"crypto";import{z as z12}from"zod";import{z as z8}from"zod";var runAddonsSchema=z8.object({browser:z8.object({session:z8.string().min(1),projectId:z8.number().int().positive(),region:z8.literal("us").default("us")}).strict().optional()}).strict();import{z as z11}from"zod";import{z as z10}from"zod";import{z as z9}from"zod";var websiteUrlSchema=z9.url().refine(raw=>{const u=new URL(raw);return u.protocol==="https:"&&!u.username&&!u.password&&!u.port&&!u.search&&!u.hash},"Expected an HTTPS documentation URL without credentials, port, query or fragment");var websiteUseSchema=z9.object({type:z9.literal("website"),url:websiteUrlSchema.refine(url=>new URL(url).pathname==="/","Website inputs require an origin without a path")}).strict();var deploymentSourceSchema=z9.object({type:z9.literal("github-deployment"),environment:z9.string().min(1).max(128)}).strict();var commentSourceSchema=z9.object({type:z9.literal("github-pr-comment"),author:z9.string().min(1).max(100).regex(/^[a-zA-Z0-9-]+(?:\[bot\])?$/),bodyIncludes:z9.string().min(1).max(256).describe("Literal marker identifying the provider's preview comment."),pattern:z9.string().min(1).max(2048).refine(pattern=>{try{new RegExp(pattern,"gm");return pattern.includes("(?<url>")&&pattern.includes("(?<sha>")}catch{return false}},"Use a valid regex with named url and sha captures; match only a ready preview").describe("JavaScript regex (gm flags) matching readiness and capturing url and sha (7\u201340 hex characters). Execution is time limited."),failureIncludes:z9.string().min(1).max(256).optional().describe("Literal failure marker in the selected comment; failure never falls back to older comments.")}).strict();var websiteSourceSchema=z9.discriminatedUnion("type",[deploymentSourceSchema,commentSourceSchema]);var inputPathSchema=z10.string().min(1).max(256).regex(/^(?![!/])(?!.*[\\\x00-\x1f\x7f])(?!.*(?:^|\/)\.{1,2}(?:\/|$))(?!.*\/\/)(?!.*\/$).+$/,"Expected a repository-relative path or glob without traversal");var reservedBinaryCommands=["bash","sh","zsh","env","node","nodejs","npm","npx","bun","python","python3","git","tar","curl","cp","chmod","mkdir","rm","ln","test","sha256sum","printenv","uname","claude","codex","opencode","pi","wizard"];var binaryCommandSchema=z10.string().max(128).regex(/^[A-Za-z0-9_][A-Za-z0-9_.+-]*$/,"Expected a command name without paths or shell syntax").refine(name=>!reservedBinaryCommands.includes(name),"Command is reserved for Gauge workspace setup or the agent harness; choose another command name");var binaryUseSchema=z10.object({type:z10.literal("binary"),paths:z10.array(inputPathSchema).min(1).max(32),platform:z10.literal("linux-x64").describe("Linux x86-64 ELF executables compatible with the consumer sandbox. No system packages are installed."),commands:z10.record(binaryCommandSchema,inputPathSchema.regex(/^[^*?{}[\]]+$/,"Command targets must be explicit relative file paths")).refine(commands=>Object.keys(commands).length>=1&&Object.keys(commands).length<=32,"Declare between 1 and 32 commands").meta({minProperties:1,maxProperties:32})}).strict();var inputUseSchema=z10.discriminatedUnion("type",[binaryUseSchema,websiteUseSchema,z10.object({type:z10.literal("files"),paths:z10.array(inputPathSchema).min(1).max(32).optional()}).strict(),z10.object({type:z10.literal("npm-cli"),package:inputPathSchema,install:z10.enum(["environment","workspace"]).optional()}).strict(),z10.object({type:z10.literal("npm-package"),package:inputPathSchema,install:z10.enum(["environment","workspace"]).optional()}).strict(),z10.object({type:z10.literal("skill"),root:z10.union([z10.literal("."),inputPathSchema]).refine(path=>!/[*?{}[\]]/.test(path),"Skill root must be an explicit directory")}).strict()]);var inputSourceSchema=z10.discriminatedUnion("type",[z10.object({type:z10.literal("git"),paths:z10.array(inputPathSchema).min(1).max(32)}).strict(),z10.object({type:z10.literal("github-actions"),artifact:z10.string().min(1).max(256).optional()}).strict()]);var runPlanResourceSchema=z10.object({name:z10.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64),type:z10.literal("input"),source:z10.discriminatedUnion("type",[z10.object({type:z10.literal("upload"),sha256:z10.string().regex(/^sha256:[a-f0-9]{64}$/),bytes:z10.number().int().positive().max(512*1024*1024),repoUrl:z10.string().nullable(),commit:z10.string().regex(/^[a-f0-9]{40}$/i).nullable()}).strict(),commentSourceSchema.extend({repoUrl:z10.string(),commit:z10.string().regex(/^[a-f0-9]{40}$/i)}).strict(),deploymentSourceSchema.extend({repoUrl:z10.string(),commit:z10.string().regex(/^[a-f0-9]{40}$/i)}).strict(),inputSourceSchema.options[0].extend({repoUrl:z10.string(),commit:z10.string().regex(/^[a-f0-9]{40}$/i)}).strict(),inputSourceSchema.options[1].extend({repoUrl:z10.string(),commit:z10.string().regex(/^[a-f0-9]{40}$/i),workflow:inputPathSchema}).strict()]),use:inputUseSchema}).strict().refine(r=>r.use.type==="website"===(r.source.type==="github-deployment"||r.source.type==="github-pr-comment"),"Website inputs require a deployment or PR comment source; file inputs require Git, Actions, or an upload");var definitionInputSourceSchema=z11.discriminatedUnion("type",[z11.object({type:z11.literal("git")}).strict(),z11.object({type:z11.literal("github-actions"),workflow:inputPathSchema.regex(/^\.github\/workflows\/[^/*?{}[\]]+\.ya?ml$/).describe("Workflow file in this repository, for example .github/workflows/build.yml."),artifact:z11.string().min(1).max(256).optional().describe("Upload name or pattern. Omit only when the workflow produces exactly one artifact.")}).strict()]);var skillInputPathSchema=z11.union([z11.literal("."),inputPathSchema.regex(/^[^*?{}[\]]+$/)]).describe("Explicit Skill directory or ZIP/tar.gz file containing SKILL.md at its root.");var runDefinitionInputSchema=z11.discriminatedUnion("type",[binaryUseSchema.extend({source:definitionInputSourceSchema.default({type:"git"})}).strict(),websiteUseSchema.extend({source:websiteSourceSchema}).strict(),z11.object({type:z11.literal("npm-package"),source:definitionInputSourceSchema.default({type:"git"}),path:inputPathSchema.describe("Path or glob selecting exactly one packed npm .tgz file."),install:z11.enum(["environment","workspace"]).default("environment").describe("environment exposes the package's commands on PATH; workspace adds a consumer application dependency.")}).strict(),z11.object({type:z11.literal("skill"),source:definitionInputSourceSchema.default({type:"git"}),path:skillInputPathSchema}).strict(),z11.object({type:z11.literal("files"),source:definitionInputSourceSchema.default({type:"git"}),paths:z11.array(inputPathSchema).min(1).max(32).describe("Files or globs selected from the committed Git tree or the uploaded artifact.")}).strict()]);function isSkillArchive(path){return/\.(?:zip|tar\.gz|tgz)$/i.test(path)}function compileDefinitionInput(name,input,repoUrl,commit){if(input.type==="website")return{name,type:"input",source:{...input.source,repoUrl,commit},use:{type:"website",url:input.url}};const paths=input.type==="files"||input.type==="binary"?input.paths:input.type==="skill"&&!isSkillArchive(input.path)?[input.path==="."?"**":`${input.path}/**`]:[input.path];return{name,type:"input",source:input.source.type==="git"?{type:"git",paths,repoUrl,commit}:{...input.source,repoUrl,commit},use:input.type==="binary"?{type:"binary",paths:input.paths,platform:input.platform,commands:input.commands}:input.type==="npm-package"?{type:"npm-package",package:input.path,install:input.install}:input.type==="skill"?{type:"skill",root:input.path}:{type:"files",paths:input.paths}}}var inputUploadSpecSchema=z12.object({sha256:z12.string().regex(/^sha256:[a-f0-9]{64}$/),bytes:z12.number().int().positive().max(512*1024*1024)}).strict();var uncredentialedRepoUrlSchema=z12.string().min(1).refine(raw=>{if(!/^[a-z][a-z0-9+.-]*:\/\//i.test(raw))return true;try{const url=new URL(raw);return(url.protocol==="ssh:"||!url.username)&&!url.password&&!url.search&&!url.hash}catch{return false}},"Repository URL must not contain embedded credentials or query parameters");var runDefinitionChecksSchema=z12.object({paths:z12.array(inputPathSchema).min(1).max(32)}).strict();var runDefinitionConfigSchema=z12.object({agents:z12.array(agentConfigInputSchema).min(1),sampleCount:z12.number().int().min(1).max(50).optional(),repoUrl:uncredentialedRepoUrlSchema.nullable().optional(),repoRef:z12.string().min(1).nullable().optional(),profileId:z12.string().min(1).nullable().optional(),skillRefs:assetRefListSchema.optional(),mcpRefs:assetRefListSchema.optional(),connectionIds:z12.array(z12.string().min(1)).max(32).optional(),addons:runAddonsSchema.optional(),inputs:z12.array(z12.string()).optional(),checks:runDefinitionChecksSchema.optional()}).strict();var runDefinitionFileConfigSchema=z12.object({version:z12.literal(2).default(2),org:z12.string().min(1).optional(),checks:runDefinitionChecksSchema.optional(),cases:z12.array(inputPathSchema).min(1).max(32).default(["gauge-cases/**/*.md"]),inputs:z12.record(z12.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64),runDefinitionInputSchema).refine(inputs=>Object.keys(inputs).length<=32,"At most 32 inputs are allowed").meta({maxProperties:32}).default({})}).strict();var runDefinitionCriterionSchema=z12.object({name:z12.string().min(1),rubric:z12.string().min(1)}).strict();var caseMeasurement={criteria:z12.array(runDefinitionCriterionSchema).min(1).optional(),preference:preferenceDefinitionSchema.optional()};function exactlyOneMeasurement(item){return item.criteria!==void 0!==(item.preference!==void 0)}var runDefinitionFrontmatterSchema=z12.object({...caseMeasurement,config:runDefinitionConfigSchema}).strict().refine(exactlyOneMeasurement,"Specify exactly one of criteria or preference");var runDefinitionCaseSchema=z12.object({path:z12.string().min(1),prompt:z12.string().min(1),...caseMeasurement,config:runDefinitionConfigSchema}).strict().refine(exactlyOneMeasurement,"Specify exactly one of criteria or preference");var runDefinitionSubmissionSchema=z12.object({version:z12.literal(2),source:z12.object({repoUrl:uncredentialedRepoUrlSchema.nullable(),commit:z12.string().regex(/^[a-f0-9]{40}$/i).nullable(),digest:z12.string().regex(/^sha256:[a-f0-9]{64}$/),verification:z12.enum(["SUBMITTED_UNVERIFIED","GITHUB_VERIFIED","LOCAL"])}).strict(),resources:z12.array(runPlanResourceSchema).max(32).default([]),cases:z12.array(runDefinitionCaseSchema).min(1).max(20)}).strict().superRefine((definition,ctx)=>{if(definition.source.verification!=="LOCAL"&&(!definition.source.repoUrl||!definition.source.commit))ctx.addIssue({code:"custom",path:["source"],message:"Committed definitions require a repository and commit"});if(definition.source.verification==="GITHUB_VERIFIED"&&definition.resources.some(r=>r.source.type==="upload"))ctx.addIssue({code:"custom",path:["resources"],message:"GitHub definitions cannot contain uploaded inputs"});const paths=new Set;for(const[index,item]of definition.cases.entries()){if(paths.has(item.path))ctx.addIssue({code:"custom",path:["cases",index,"path"],message:"Case paths must be unique"});paths.add(item.path)}const names=definition.resources.map(resource=>resource.name);if(new Set(names).size!==names.length)ctx.addIssue({code:"custom",path:["resources"],message:"Input names must be unique"});for(const[index,item]of definition.cases.entries())for(const name of item.config.inputs??names)if(!names.includes(name))ctx.addIssue({code:"custom",path:["cases",index,"config","inputs"],message:`Unknown input: ${name}`});for(const[index,resource]of definition.resources.entries()){if(resource.source.repoUrl!==definition.source.repoUrl||resource.source.commit!==definition.source.commit)ctx.addIssue({code:"custom",path:["resources",index,"source"],message:"Project preparation must use the definition repository and commit"})}});var runDefinitionPublicSubmissionSchema=runDefinitionSubmissionSchema.refine(definition=>definition.source.verification!=="GITHUB_VERIFIED",{path:["source","verification"],message:"Only the GitHub App may verify committed bytes"});var runDefinitionPlanResponseSchema=z12.object({source:runDefinitionSubmissionSchema.shape.source,measurementMode:z12.enum(["AGENT_EXPERIENCE","AGENT_PREFERENCE","MIXED"]),cases:z12.array(z12.object({path:z12.string(),agents:z12.array(agentConfigSchema),samples:z12.number().int().nonnegative(),expectedRuns:z12.number().int().nonnegative(),workspace:z12.object({repoUrl:z12.string().nullable(),repoRef:z12.string().nullable()}),criteriaCount:z12.number().int().nonnegative(),preference:preferenceDefinitionSchema.optional(),inputs:z12.array(z12.string())})),resources:z12.array(z12.object({name:z12.string(),type:z12.literal("input"),source:z12.enum(["git","github-actions","github-deployment","github-pr-comment","upload"]),use:inputUseSchema,readiness:z12.enum(["READY","WAITING","FAILED"]),detail:z12.string().optional(),commands:z12.array(z12.string()).optional()})),expectedRuns:z12.number().int().nonnegative(),canRun:z12.boolean()});var runDefinitionRunResponseSchema=z12.object({runRequestId:z12.string(),batchIds:z12.array(z12.string()),runIds:z12.array(z12.string()),requestedRuns:z12.number().int().nonnegative(),createdRuns:z12.number().int().nonnegative(),aggregateUrl:z12.string()});import{z as z13}from"zod";var caseSpecSchema=z13.object({version:z13.literal(2),cases:z13.array(z13.object({key:z13.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64).describe("Unique case id, lowercase-kebab"),prompt:z13.string().trim().min(1).describe("The user's request"),criteria:z13.array(runDefinitionCriterionSchema).min(1).optional().describe("Optional for local runs; hosted needs criteria or preference"),preference:preferenceDefinitionSchema.optional(),config:runDefinitionConfigSchema}).strict().refine(item=>!(item.criteria&&item.preference),"Specify criteria or preference, not both")).min(1).max(20)}).strict().refine(spec=>new Set(spec.cases.map(item=>item.key)).size===spec.cases.length,"Case keys must be unique");var EXAMPLE_CASE_SPEC={version:2,cases:[{key:"release-notes",prompt:"Write the release notes for version 1.2.0. We added dark mode and fixed a login crash.",criteria:[{name:"Team format",rubric:"RELEASE-NOTES.md lists both changes in the team's format."}],config:{agents:[{agent:"CODEX_CLI"}],inputs:["release-notes"]}}]};var CASE_SPEC_SCHEMA=()=>z13.toJSONSchema(caseSpecSchema);function isCaseSpec(value){return value!==null&&typeof value==="object"&&"cases"in value&&!("prompts"in value)}function parseCaseSpec(value){const result=caseSpecSchema.safeParse(value);if(!result.success)throw new CliError("usage",`not a valid case spec:
|
|
748
|
-
${result.error.issues.map(i=>` ${i.path.join(".")||"(spec)"}: ${i.message}`).join("\n")}`,{hint:"Run `gauge run --schema --local` for the full schema, or `gauge run --example --local` for a starter."});return result.data}function caseSpecCases(spec){return spec.cases.map(({key,...item})=>({path:key,...item}))}function caseSpecDigest(spec){return`sha256:${createHash3("sha256").update("gauge-case-spec-v2\0").update(JSON.stringify(spec)).digest("hex")}`}import{execFileSync as execFileSync2}from"child_process";import{createHash as createHash5}from"crypto";import{createReadStream as createReadStream2,globSync as globSync2}from"fs";import{lstat,mkdtemp,readdir,rm,stat}from"fs/promises";import{tmpdir}from"os";import{basename,dirname
|
|
749
|
-
`;const red=style("31",process.stderr);const dim=style("2",process.stderr);return`${[`${red("error:")} ${report.message}`,...report.hint?[report.hint]:[]
|
|
750
|
-
`}function commandPath(program2,argv){const names=[];let command=program2;for(const token of argv){if(token.startsWith("-"))continue;const next=command.commands.find(sub=>sub.name()===token||sub.aliases().includes(token));if(next){names.push(token);command=next}else if(command.commands.length===0)break}return names.join(" ")}function wantsJson(argv){return argv.some((token,i)=>token==="--output=json"||token==="-ojson"||(token==="-o"||token==="--output")&&argv[i+1]==="json")}var record=value=>value!==null&&typeof value==="object"&&!Array.isArray(value)?value:{};var message=error=>oneLine(error instanceof CliError&&error.hint?`${error.message} ${error.hint}`:error instanceof Error?error.message:String(error));var oneLine=text=>readable(text).trim().replace(/\n\s*/g,"; ");var check=(id,state,detail)=>({id,state,detail});var dynamic=value=>typeof value!=="string"||value.includes("${{");var condition=value=>{if(value===void 0||value===true)return true;if(value===false)return false;if(typeof value==="string"){const compact2=value.replace(/\s/g,"");if(compact2==="true"||compact2===`\${{true}}`)return true;if(compact2==="false"||compact2===`\${{false}}`)return false}return void 0};function git(cwd,args){return execFileSync("git",args,{cwd,encoding:"utf8",stdio:["ignore","pipe","pipe"],maxBuffer:16*1024*1024})}function rootDirectory(cwd){return findWorkspace(cwd)??resolve4(cwd)}function regularFile(root,path){const full=join10(root,path);try{const rel=relative4(realpathSync3(root),realpathSync3(full));return rel!==".."&&!rel.startsWith(`..${sep2}`)&&!isAbsolute3(rel)&&lstatSync(full).isFile()}catch{return false}}function read(root,path){if(!regularFile(root,path))throw new Error(`${path}: missing regular file inside the working tree`);if(lstatSync(join10(root,path)).size>1024*1024)throw new Error(`${path}: exceeds the 1 MiB static inspection limit`);return readFileSync10(join10(root,path))}function ignoredByGit(root){try{git(root,["check-ignore","-q","."]);return true}catch{return false}}function workingFiles(root){let paths;try{if(ignoredByGit(root))throw new Error("workspace is ignored by Git");paths=git(root,["ls-files","--cached","--others","--exclude-standard","-z"]).split("\0").filter(Boolean)}catch{paths=[];const walk=directory=>{for(const entry of readdirSync2(join10(root,directory),{withFileTypes:true})){if([".git",".gauge","node_modules",".next",".venv","venv"].includes(entry.name))continue;const path=directory?`${directory}/${entry.name}`:entry.name;if(entry.isDirectory())walk(path);else if(entry.isFile())paths.push(path);if(paths.length>5e4)throw new Error("Working tree exceeds 50,000 files; initialize Git and ignore generated files before verifying")}};walk("")}return[...new Set(paths)].filter(path=>regularFile(root,path)).sort()}var skippedInputEntry=name=>[".git",".gauge","node_modules",".aws",".ssh",".npmrc",".pypirc"].includes(name)||name===".env"||name.startsWith(".env.");function diskFiles(root,base){const paths=[];const walk=directory=>{for(const entry of readdirSync2(join10(root,directory),{withFileTypes:true})){if(skippedInputEntry(entry.name))continue;const path=directory?`${directory}/${entry.name}`:entry.name;if(entry.isDirectory())walk(path);else if(entry.isFile())paths.push(path);if(paths.length>2e4)throw new Error("Input exceeds 20,000 files")}};walk(base==="."?"":base);return paths.sort()}function workflowChecks(root,input){if(input.source.type!=="github-actions")return[];const source=input.source;const checks=[];let workflow;try{const document=parseDocument2(read(root,source.workflow).toString("utf8"),{uniqueKeys:true});if(document.errors.length)throw new Error(document.errors.map(message).join("; "));workflow=record(document.toJS());if(!Object.keys(record(workflow.jobs)).length)throw new Error("Expected a workflow jobs mapping");checks.push(check("workflow","yes",`${source.workflow} exists with a parseable YAML jobs mapping`))}catch(error){return[check("workflow","no",message(error))]}const jobs=Object.entries(record(workflow.jobs)).map(([name,value])=>({name,job:record(value)})).filter(({job})=>condition(job.if)!==false);const steps=jobs.flatMap(({name,job})=>Array.isArray(job.steps)?job.steps.map(value=>({job:name,jobCondition:condition(job.if),step:record(value)})).filter(({step})=>condition(step.if)!==false):[]);const opaque=jobs.some(({job})=>typeof job.uses==="string")||steps.some(({step})=>typeof step.uses==="string"&&!/^actions\/(checkout|upload-artifact|setup-[^@]+)@/.test(step.uses));const uploads=steps.filter(({step})=>typeof step.uses==="string"&&step.uses.startsWith("actions/upload-artifact@"));const candidates=uploads.filter(({step})=>{const name=record(step.with).name??"artifact";return!source.artifact||dynamic(name)||minimatch2(String(name),source.artifact,{nonegate:true})});const recognizedUpload=candidates.length===1&&!dynamic(record(candidates[0].step.with).name??"artifact");checks.push(check("artifact-upload",recognizedUpload?"yes":"unknown",recognizedUpload?`One direct upload step declares the matching artifact ${String(record(candidates[0].step.with).name??"artifact")}`:candidates.length?`Found ${candidates.length} potentially matching upload step(s); resolve dynamic artifact names or overlapping uploads to establish a unique selection`:`No direct upload step matches ${source.artifact??"the configured artifact"}; ${opaque?"inspect the referenced reusable workflows or custom actions":"inspect build scripts or declare a matching actions/upload-artifact step"}`));for(const[index,{job,jobCondition,step}]of candidates.entries()){const options=record(step.with);const version=/^actions\/upload-artifact@v(\d+)(?:\.\d+){0,2}$/.exec(String(step.uses));const major=version?Number(version[1]):void 0;let state=source.artifact&&dynamic(options.name??"artifact")?"unknown":major===7?options.archive===true||options.archive==="true"?"yes":options.archive===void 0||options.archive===false||options.archive==="false"?"no":"unknown":major!==void 0&&major>=4&&major<=6?"yes":"unknown";const conditional=jobCondition===void 0||condition(step.if)===void 0;if(state==="no"&&conditional)state="unknown";const detail=source.artifact&&dynamic(options.name??"artifact")?"Resolve the artifact name expression to determine whether this upload is selected":major===7?options.archive===true||options.archive==="true"?"archive: true declares a ZIP artifact":options.archive===void 0||options.archive===false||options.archive==="false"?`archive: true is required for Gauge's ZIP download${conditional?"; resolve the upload condition to determine whether this incompatible upload is selected":""}`:"Resolve the archive expression; Gauge requires archive: true":major!==void 0&&major>=4&&major<=6?"This action version produces ZIP artifacts":"Resolve the pinned action version; ZIP format is recognized for upload-artifact v4\u2013v7 (v7 requires archive: true)";checks.push(check(`artifact-format.${index}`,state,`${job}: ${String(step.uses)}; ${detail}`))}const checkouts=steps.filter(({step})=>typeof step.uses==="string"&&step.uses.startsWith("actions/checkout@"));const events=typeof workflow.on==="string"?[workflow.on]:Array.isArray(workflow.on)?workflow.on:Object.keys(record(workflow.on));const pr=events.includes("pull_request");const recognizedCheckout=step=>{const options=record(step.with);if(options.repository!==void 0)return false;if(!events.length||options.ref!==void 0&&typeof options.ref!=="string")return false;const ref=typeof options.ref==="string"?options.ref.replace(/\s/g,""):"";return events.every(event=>["pull_request","push","workflow_dispatch"].includes(event))&&(!ref||ref===`\${{github.sha}}`)||ref===`\${{github.event.pull_request.head.sha||github.sha}}`||pr&&events.every(event=>event==="pull_request")&&ref===`\${{github.event.pull_request.head.sha}}`};const checkoutState=checkouts.length>0&&checkouts.every(({step})=>recognizedCheckout(step))?"yes":"unknown";checks.push(check("candidate-checkout",checkoutState,checkoutState==="yes"?"Workflow checkout recognized, including the default PR merge checkout":"Could not inspect checkout settings; check that your workflow builds the intended code"));const filtered=Object.values(record(workflow.on)).some(value=>["paths","paths-ignore","branches","branches-ignore","types"].some(key=>record(value)[key]!==void 0));const eligible=events.filter(event=>["pull_request","push","workflow_dispatch"].includes(String(event)));const knownEvents=events.length>0&&events.every(event=>!dynamic(event));checks.push(check("workflow-trigger",eligible.length?"yes":knownEvents?"no":"unknown",eligible.length?`Eligible trigger(s) declared: ${eligible.join(", ")}${filtered?"; event filters are present":""}`:knownEvents?`Declared event(s) ${events.join(", ")} are not eligible artifact sources; declare push, pull_request, or workflow_dispatch`:"Could not read workflow events; declare push, pull_request, or workflow_dispatch"));return checks}function inputChecks(root,files,input,local){const checks=[check("configuration","yes",`Supported ${input.type} input from ${input.source.type==="git"?"project files":input.source.type}`)];if(input.type==="website")return checks;if(input.type==="binary"){const excluded=Object.entries(input.commands).filter(([,target])=>!input.paths.some(pattern=>minimatch2(target,pattern,{dot:true,nocase:false,nonegate:true})));checks.push(check("command-selection",excluded.length?"no":"yes",excluded.length?`Declared command targets are excluded by paths: ${excluded.map(([name,target])=>`${name}: ${target}`).join(", ")}`:"Declared command targets match selected paths"))}if(input.source.type==="github-actions"&&!local)checks.push(...workflowChecks(root,input));else{try{const patterns=input.type==="files"||input.type==="binary"?input.paths:input.type==="skill"&&!isSkillArchive(input.path)?[input.path==="."?"**":`${input.path}/**`]:[input.path];const selected=local&&input.type==="npm-package"?globSync(input.path,{cwd:root}):matchInputPaths(local?diskFiles(root,input.type==="skill"&&!isSkillArchive(input.path)?input.path:""):files,patterns);if(input.type==="binary"){for(const[command,target]of Object.entries(input.commands)){if(!selected.includes(target))throw new Error(`Binary command ${command} target is missing or excluded by paths: ${target}`)}}if(input.type==="npm-package"&&(selected.length!==1||!selected[0].endsWith(".tgz")))throw new Error("npm-package must select exactly one .tgz file");if(input.type==="skill"&&!isSkillArchive(input.path)&&!selected.includes(input.path==="."?"SKILL.md":`${input.path}/SKILL.md`))throw new Error("Skill directory must contain SKILL.md at its root");checks.push(check("local-paths","yes",`${selected.length} ${local?"local":"working-tree"} file(s) selected`))}catch(error){checks.push(check("local-paths","no",message(error).replace("committed files",local?"local files":"working-tree files")))}}return checks}function verifyEvals(cwd=process.cwd(),{local=false}={}){const root=rootDirectory(cwd);const result={version:1,mode:"local-static",root,status:"passed",summary:{yes:0,no:0,unknown:0},facts:{configFilePresent:null,caseCount:null},info:[],notChecked:["github-app-activation","account-settings","mcp-server-access","mcp-server-reachability","live-input-delivery","artifact-contents","sandbox-installation","workflow-execution"],global:[],inputs:[]};const finish=()=>{for(const item of[...result.global,...result.inputs.flatMap(input=>input.checks)])result.summary[item.state]++;result.status=result.summary.no>0?"failed":result.summary.unknown>0?"incomplete":"passed";return result};let raw={};let files;try{files=workingFiles(root)}catch(error){result.global.push(check("working-tree","no",message(error)));return finish()}try{result.facts.configFilePresent=files.includes("gauge.json")||regularFile(root,"gauge.json");if(result.facts.configFilePresent)raw=JSON.parse(read(root,"gauge.json").toString("utf8"));else result.info.push({id:"config-file-absent",detail:"Optional gauge.json is absent; using default case discovery and no inputs"})}catch(error){result.global.push(check("configuration","no",message(error)));return finish()}const config=runDefinitionFileConfigSchema.safeParse(raw);result.global.push(check("configuration",config.success?"yes":"no",config.success?"Configuration matches the supported gauge.json schema":oneLine(config.error.message)));const rawInputs=record(record(raw).inputs);for(const[name,value]of Object.entries(rawInputs).sort(([a],[b])=>a.localeCompare(b))){const parsed=runDefinitionInputSchema.safeParse(value);result.inputs.push({name,checks:parsed.success?inputChecks(root,files,parsed.data,local):[check("configuration","no",oneLine(parsed.error.message))]})}if(config.success){try{const paths=matchInputPaths(files,config.data.cases,{allowEmptySelection:true});if(paths.length>20||paths.some(path=>!path.endsWith(".md")))throw new Error("Expected at most 20 Markdown cases");result.facts.caseCount=paths.length;if(paths.length)result.global.push(check("case-discovery","yes",`${paths.length} working-tree case(s) selected`));else result.info.push({id:"no-cases",detail:"No eval cases found; input-only setup is valid, but no evaluations will run"});for(const path of paths){try{const item=parseRunDefinitionCase(path,read(root,path));if(local)assertLocalCapabilities(item.config,`${path}: config.`);const missing=(item.config.inputs??[]).filter(name=>!Object.hasOwn(config.data.inputs,name));if(missing.length)throw new Error(`${path}: Unknown input(s): ${missing.join(", ")}`);const commandOwners=new Map;for(const name of new Set(item.config.inputs??Object.keys(config.data.inputs))){const input=config.data.inputs[name];if(input.type!=="binary")continue;for(const command of Object.keys(input.commands)){const owner=commandOwners.get(command);if(owner)throw new Error(`${path}: Inputs ${owner} and ${name} both expose command ${command}; choose distinct commands or separate cases`);commandOwners.set(command,name)}}result.global.push(check(`case.${path}`,"yes","Case syntax, input references, and declared command names are valid"))}catch(error){result.global.push(check(`case.${path}`,"no",message(error)))}}}catch(error){result.global.push(check("case-discovery","no",message(error).replace("committed files","working-tree files")))}}else result.info.push({id:"case-validation-skipped",detail:"Fix gauge.json before validating cases and input references"});return finish()}function printEvalVerification(result){console.log(`Local static verification: ${result.root}`);const print2=checks=>{for(const item of checks)console.log(` [${item.state}] ${item.id}: ${item.detail}`)};console.log("Global");print2(result.global);for(const input of result.inputs){console.log(`Input: ${input.name}`);print2(input.checks)}for(const item of result.info)console.log(`[info] ${item.id}: ${item.detail}`);console.log(`Static verification ${result.status}: ${result.summary.yes} yes, ${result.summary.no} no, ${result.summary.unknown} unknown.`);console.log("Scope: repository setup only. Live delivery, account settings, and sandbox execution were not tested; no sessions were launched.")}var LIMIT=512*1024*1024;var SNAPSHOT_FILES=100;function parseInputBindings(values){const bindings=new Map;for(const value of values){const split=value.indexOf("=");const name=split<0?value:value.slice(0,split);const path=split<0?void 0:value.slice(split+1);if(!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name)||path==="")throw new CliError("usage","--input expects name or name=path");if(bindings.has(name))throw new CliError("usage",`Duplicate --input: ${name}`);bindings.set(name,path)}return bindings}var isGlob=path=>/[*?[\]{}]/.test(path);function rejectSkippedPatterns(name,patterns){for(const pattern of patterns){const skipped=pattern.split("/").find(skippedInputEntry);if(skipped===".gauge")throw new CliError("usage",`Input ${name}: ${pattern} is inside .gauge/. Inputs never include .gauge/, because it holds run results and local config.`,{hint:"Move the files outside .gauge/ and update the glob."});if(skipped)throw new CliError("usage",`Input ${name}: ${pattern} is inside ${skipped}, which inputs never include`,{hint:`Move the files outside ${skipped} and update the glob.`})}}async function walkInput(root,depth=Infinity){const paths=[];const walk=async(directory,level)=>{for(const entry of await readdir(join11(root,directory),{withFileTypes:true})){if(skippedInputEntry(entry.name)||!entry.isFile()&&!entry.isDirectory())continue;const next=directory?`${directory}/${entry.name}`:entry.name;if(entry.isDirectory()){if(level<depth)await walk(next,level+1)}else paths.push(next);if(paths.length>2e4)throw new CliError("usage","Input exceeds 20,000 files")}};await walk("",1);return paths.sort()}function selectPaths(name,paths,patterns){rejectSkippedPatterns(name,patterns);try{return matchInputPaths(paths,patterns)}catch(error){throw new CliError("usage",`Input ${name}: ${message(error).replace("committed files","files")}`)}}async function expandOverrideGlob(name,glob){const segments=glob.split(sep3);const first=segments.findIndex(isGlob);const root=segments.slice(0,first).join(sep3)||sep3;const pattern=segments.slice(first).join("/");const info=await stat(root).catch(()=>void 0);if(!info?.isDirectory())throw new CliError("usage",`Input ${name}: ${root} is not a directory`);const depth=pattern.includes("**")?Infinity:pattern.split("/").length;return{root,pattern,files:selectPaths(name,await walkInput(root,depth),[pattern])}}async function selectLocalInput(resource,supplied,override){let path=resolve5(supplied);let info=await lstat(path).catch(()=>void 0);if(!info&&override&&isGlob(path)){if(resource.use.type==="skill")throw new CliError("usage",`Input ${resource.name}: Skill inputs take an explicit directory or archive, not a glob`);const{root:root2,pattern,files}=await expandOverrideGlob(resource.name,path);if(resource.use.type==="files")return{use:{type:"files"},root:root2,files,skillDirectory:false};if(resource.use.type==="binary")return{use:{...resource.use,paths:[pattern]},root:root2,files,skillDirectory:false};if(files.length!==1)throw new CliError("usage",`Input ${resource.name}: ${supplied} matches ${files.length} files; keep one`);path=join11(root2,files[0]);info=await lstat(path)}if(!info)throw new CliError("usage",`Input path does not exist: ${supplied}`,{hint:"Pass --input <name>=<path>, or fix the input's path in gauge.json."});if(!info.isFile()&&!info.isDirectory())throw new CliError("usage",`Input must be an ordinary file or directory: ${supplied}`);let use=resource.use;if(use.type==="skill"){if(info.isFile()&&!isSkillArchive(path))throw new CliError("usage","Supply a Skill directory, .zip, or .tar.gz archive");use={...use,root:info.isDirectory()?".":basename(path)}}else if(use.type==="npm-package"||use.type==="npm-cli"){if(!info.isFile()||!path.endsWith(".tgz"))throw new CliError("usage","Supply the packed npm .tgz file");use={...use,package:basename(path)}}else if(override&&use.type==="files")use={type:"files"};else if(override&&use.type==="binary")use={...use,paths:[info.isDirectory()?"**":basename(path)]};const root=info.isDirectory()?path:dirname2(path);const paths=info.isDirectory()?await walkInput(root):[basename(path)];const patterns=!override&&(use.type==="files"||use.type==="binary")?use.paths:void 0;return{use,root,files:patterns?selectPaths(resource.name,paths,patterns):paths,skillDirectory:use.type==="skill"&&info.isDirectory()}}async function packLocalInput(resource,supplied,output,{override=false}={}){if(resource.use.type==="website")throw new CliError("usage",`Input ${resource.name}: website inputs cannot be supplied through --input.`,{hint:"Use the configured public preview with --hosted. For content-only alternatives and their discovery limits, read `gauge instructions hillclimb`."});const{use,root,files,skillDirectory}=await selectLocalInput(resource,supplied,override);if(!files.length)throw new CliError("usage","Input contains no selected files");if(use.type==="binary"){for(const[command,target]of Object.entries(use.commands))if(!files.includes(target))throw new CliError("usage",`Input ${resource.name}: binary command ${command} target is missing: ${target}`,override?{hint:"Command targets are relative to the supplied path."}:void 0)}if(skillDirectory&&!files.includes("SKILL.md"))throw new CliError("usage","Skill directory must contain SKILL.md at its root");let total=0;for(const file of files){inputPathSchema.parse(file);const entry=await lstat(join11(root,file));if(!entry.isFile())throw new CliError("usage",`Input file changed or is not an ordinary file: ${file}`);total+=entry.size;if(total>LIMIT)throw new CliError("usage","Input exceeds 512 MiB")}await tar({cwd:root,file:output,gzip:true,portable:true,noMtime:true,follow:false,noDirRecurse:true},files.map(file=>`./${file}`));const bytes=(await stat(output)).size;if(bytes>LIMIT)throw new CliError("usage","Input archive exceeds 512 MiB");const hash=createHash5("sha256");for await(const chunk of createReadStream2(output))hash.update(chunk);return{use,upload:{path:output,bytes,sha256:`sha256:${hash.digest("hex")}`},files}}async function loadLocalRunDefinition(files,values,cwd=process.cwd(),{local=false,spec}={}){const directory=await mkdtemp(join11(tmpdir(),"gauge-inputs-"));const cleanup=()=>rm(directory,{recursive:true,force:true});try{const root=rootDirectory(cwd);const paths=workingFiles(root);const blobs=new Map;if(paths.includes("gauge.json"))blobs.set("gauge.json",read(root,"gauge.json"));const configBytes=blobs.get("gauge.json");let config;try{config=runDefinitionFileConfigSchema.parse(configBytes?JSON.parse(configBytes.toString("utf8")):{})}catch(error){throw new CliError("usage",`gauge.json is not valid: ${error instanceof Error?error.message:error}`,{hint:"Run `gauge run --verify` for each problem."})}const patterns=spec?[]:files.length?files.map(file=>{const path=relative5(root,resolve5(cwd,file));if(!path||path===".."||path.startsWith(`..${sep3}`)||isAbsolute4(path))throw new CliError("usage","Case paths must be inside the definition directory");return path.split(sep3).join("/")}):config.cases;const cases=spec?[]:files.length?matchInputPaths(paths,patterns):matchInputPaths(paths,patterns,{allowEmptySelection:true});if(!spec&&cases.length===0)throw noCasesError();if(cases.length>20||cases.some(path=>!path.endsWith(".md")))throw new CliError("usage","Expected 1\u201320 Markdown cases");for(const path of cases)blobs.set(path,read(root,path));const parsed=spec?caseSpecCases(spec):cases.map(path=>parseRunDefinitionCase(path,blobs.get(path)??Buffer.alloc(0)));const unmeasured=parsed.filter(item=>!item.criteria&&!item.preference);if(!local&&unmeasured.length)throw new CliError("usage",`Hosted cases need criteria or preference: ${unmeasured.map(item=>item.path).join(", ")}`,{hint:"Add criteria, or run locally with --local."});const bindings=parseInputBindings(values);for(const name of bindings.keys())if(!(name in config.inputs))throw new CliError("usage",`Unknown input: ${name}`,{hint:`gauge.json defines: ${Object.keys(config.inputs).join(", ")||"none"}`});for(const item of parsed)for(const name of item.config.inputs??[])if(!(name in config.inputs))throw new CliError("usage",`${item.path}: unknown input "${name}". gauge.json defines: ${Object.keys(config.inputs).join(", ")||"none"}`);const selected=new Set(parsed.flatMap(item=>item.config.inputs??Object.keys(config.inputs)));for(const[name,override]of bindings){if(!selected.has(name))throw new CliError("usage",`Input is not used by the selected cases: ${name}`);if(override!==void 0)rejectSkippedPatterns(name,[relative5(root,resolve5(cwd,override)).split(sep3).join("/")])}const git2=args=>{try{return execFileSync2("git",args,{cwd:root,encoding:"utf8",stdio:["ignore","pipe","pipe"]}).trim()}catch{return null}};const commit=git2(["rev-parse","--verify","HEAD^{commit}"]);const origin=git2(["remote","get-url","origin"]);const repoUrl=origin&&uncredentialedRepoUrlSchema.safeParse(origin).success?origin:null;const unattachedInputs=Object.keys(config.inputs).filter(name=>!selected.has(name));const resources=[];const uploads=[];const inputSnapshots=[];for(const[name,input]of Object.entries(config.inputs)){if(!selected.has(name))continue;if(local&&input.type==="website")throw new CliError("usage",`Input ${name} is a website; canonical-site preview routing requires hosted Gauge.`,{hint:"Use --hosted with a public preview. Locally, supply docs as files or put a reachable preview URL in the prompt; these test supplied content, not discovery of the canonical site. See `gauge instructions hillclimb`."});const original=compileDefinitionInput(name,input,repoUrl??"",commit??"");const override=bindings.get(name);const supplied=override??(original.source.type==="git"?workingTreeInput(root,name,input):void 0);if(supplied!==void 0){const{use,upload,files:files2}=await packLocalInput(original,resolve5(cwd,supplied),join11(directory,`${name}.tar.gz`),{override:override!==void 0});uploads.push(upload);inputSnapshots.push({name,source:override!==void 0?"override":"working-tree",path:resolve5(cwd,supplied),gaugeArchive:{sha256:upload.sha256,bytes:upload.bytes},files:files2.slice(0,SNAPSHOT_FILES),fileCount:files2.length});resources.push({...original,use,source:{type:"upload",sha256:upload.sha256,bytes:upload.bytes,repoUrl,commit}})}else{if(local)throw new CliError("usage",`Input ${name} has a remote source. Supply --input ${name}=<path> for local execution, or use --hosted.`);if(!repoUrl||!commit)throw new CliError("usage",`Input ${name}'s configured ${original.source.type} source requires a Git checkout with an origin.`,{hint:input.type==="website"?"Configure the repository origin and publish a matching public preview through the declared source. Website inputs cannot use --input; see `gauge instructions hillclimb` for content-only alternatives.":`Supply --input ${name}=<path> to use local files.`});resources.push(original)}}if(!spec)return{...compileRunDefinitionFromBlobs({repoUrl,commit,resources,blobs,casePaths:cases,verification:"LOCAL"}),uploads,inputSnapshots,unattachedInputs,cleanup};const definition={version:2,source:{repoUrl,commit,digest:caseSpecDigest(spec),verification:"LOCAL"},resources,cases:parsed};if(!local)runDefinitionSubmissionSchema.parse(definition);return{definition,org:config.org,uploads,inputSnapshots,unattachedInputs,cleanup}}catch(error){await cleanup();if(error instanceof CliError||!(error instanceof Error))throw error;throw new CliError("usage",error.message,{hint:"Check the case format in `gauge instructions run`, then run `gauge run --verify`."})}}function workingTreeInput(root,name,input){switch(input.type){case"website":throw new CliError("usage",`Input ${name} is a website; website inputs run on hosted Gauge only`);case"files":case"binary":return root;case"skill":return join11(root,input.path);case"npm-package":{const matches2=globSync2(input.path,{cwd:root});if(matches2.length!==1)throw new CliError("usage",matches2.length?`Input ${name}: ${input.path} matches ${matches2.length} files; keep one`:`Input ${name}: no file matches ${input.path}. Run \`npm pack\` first`);return join11(root,matches2[0])}}}async function uploadLocalInputs(client,org,uploads){for(const input of uploads){const signed2=await client.post(`/api/v1/orgs/${encodeURIComponent(org)}/run-definitions/uploads`,{sha256:input.sha256,bytes:input.bytes});const signal=AbortSignal.timeout(10*60*1e3);for(let attempt=0;attempt<3;attempt++){const body=createReadStream2(input.path);let response;try{response=await fetch(signed2.url,{method:"PUT",headers:signed2.headers,body,duplex:"half",redirect:"error",signal})}finally{body.destroy()}await response.body?.cancel();if(response.ok||response.status===412)break;if(response.status!==409||attempt===2)throw new CliError("network",`Input upload failed (${response.status})`);await delay2(100*2**attempt,void 0,{signal})}}}var SIDE_KEYS=["request","batch","eval","revision","experiment","trial","agent","model","since","until"];var SELECTING_KEYS=new Set(["request","batch","eval","experiment","trial"]);function csv3(value){return value.split(",").map(part=>part.trim()).filter(Boolean)}function parseCompareSide(flag,pairs){const side={};const seen=new Set;for(const pair2 of pairs){const eq=pair2.indexOf("=");const key=eq<0?"":pair2.slice(0,eq).trim();const value=eq<0?"":pair2.slice(eq+1).trim();if(!SIDE_KEYS.includes(key)||!value)throw new CliError("usage",`invalid ${flag} "${pair2}" (expected key=value with key one of ${SIDE_KEYS.join(", ")})`);if(seen.has(key)&&key!=="batch")throw new CliError("usage",`${flag} ${key}= given twice`);seen.add(key);if(key==="request")side.runRequest=value;else if(key==="batch")side.batch=[...side.batch??[],...csv3(value)];else if(key==="eval")side.evalSet=value;else if(key==="revision")side.evalRevision=value;else if(key==="experiment")side.experiment=value;else if(key==="trial")side.trial=value;else if(key==="agent")side.agent=parseAgents(value);else if(key==="model")side.model=csv3(value);else if(key==="since")side.since=value;else side.until=value}if(![...seen].some(key=>SELECTING_KEYS.has(key)))throw new CliError("usage",`${flag} needs request=, batch=, eval=, experiment=, or trial= to select runs`);return side}function pct3(rate){return rate===null?"":`${Math.round(rate*100)}%`}function passCell(stats){return stats.judged===0?"":`${pct3(stats.passRate)} (${stats.passed}/${stats.judged})`}function signed(value,format){if(value===null)return"";return`${value>0?"+":value<0?"-":"\xB1"}${format(Math.abs(value))}`}var points=rate=>`${Math.round(rate*100)}pp`;var turns=n=>String(Math.round(n*10)/10);var usd=n=>`$${n.toFixed(2)}`;var secs=ms=>`${Math.round(ms/1e3)}s`;function pair(before,after,delta3,format){if(before===null&&after===null)return"";const side=v=>v===null?"\u2014":format(v);return`${side(before)} \u2192 ${side(after)}${delta3===null?"":` (${signed(delta3,format)})`}`}function row(target,item){const{baseline:a,candidate:b,delta:delta3}=item;return{target,runs:`${a.runs} \u2192 ${b.runs}`,completed:`${a.succeeded}/${a.runs} \u2192 ${b.succeeded}/${b.runs}`,baseline:passCell(a),candidate:passCell(b),"\u0394 pass":signed(delta3.passRate,points),turns:pair(a.medianTurns,b.medianTurns,delta3.medianTurns,turns),cost:pair(a.medianUsdCost,b.medianUsdCost,delta3.medianUsdCost,usd),duration:pair(a.medianDurationMs,b.medianDurationMs,delta3.medianDurationMs,secs)}}function compareWarnings(result){const warnings=[];for(const name of["baseline","candidate"]){const side=result.sides[name];const stats=result.overall[name];if(stats.runs===0)warnings.push(`${name} matched no runs. Check its selectors; optimization trial runs need trial=<trialId>.`);else if(stats.finished<stats.runs)warnings.push(`${name} has ${stats.runs-stats.finished} of ${stats.runs} runs still in progress, so its numbers are partial. Run \`gauge run wait <request-id>\` first.`);if(stats.judged<stats.finished)warnings.push(`${name} has ${stats.finished-stats.judged} finished runs without a verdict (not judged yet, or no criteria). Its pass rate covers judged runs only.`);for(const mixed of side.mixedRevisions??[])warnings.push(`${name}: ${mixed.evalSetId?`eval ${mixed.evalSetId}`:`case prompt ${mixed.promptId}`} ran under ${mixed.revisions.length} revisions (${mixed.revisions.join(", ")}): it was edited between runs. Add --${name} revision=<hash> to pick one.`);if(side.truncated)warnings.push(`${name} matched too many runs; only the newest were compared. Narrow it with since=, until=, or batch=.`)}return warnings}function printComparison(result){const revisions=name=>result.sides[name].evalRevisions.join(", ")||"\u2014";console.log(`Baseline revision: ${revisions("baseline")}. Candidate revision: ${revisions("candidate")}.`);for(const name of["baseline","candidate"]){for(const trial of result.sides[name].trials??[])console.log(`${name}: ${trial.runs} run${trial.runs===1?"":"s"} from optimization trial ${trial.key} "${trial.title}" (${trial.kind}). Inspect: gauge optimizations trial ${trial.optimizationId} ${trial.trialId}`)}console.log("Medians are baseline \u2192 candidate (difference).");console.log("");printItems([row("all",result.overall),...result.targets.map(target=>row(`${target.agent} ${target.model||"(default)"}`,target))],"table");const before=new Map(result.overall.baseline.criteria.map(c=>[c.name,c]));const after=new Map(result.overall.candidate.criteria.map(c=>[c.name,c]));if(result.overall.delta.criteria.length>0){console.log("");printItems(result.overall.delta.criteria.map(c=>{const a=before.get(c.name);const b=after.get(c.name);return{criterion:c.name,baseline:a&&a.judged>0?`${pct3(a.passRate)} (${a.passed}/${a.judged})`:"",candidate:b&&b.judged>0?`${pct3(b.passRate)} (${b.passed}/${b.judged})`:"","\u0394 pass":signed(c.passRate,points)}}),"table")}}var LOCAL_AGENTS2=new Set(["CLAUDE_CODE","CODEX_CLI","CURSOR","PI","OPENCODE"]);var LOCAL_TERMINAL_STATES=new Set(["completed","failed","canceled","interrupted"]);function localCompareFilter(flag,side){const hostedOnly2=[side.runRequest!==void 0&&"request=",side.experiment!==void 0&&"experiment=",side.trial!==void 0&&"trial="].filter(Boolean);if(hostedOnly2.length>0)throw new CliError("usage",`${flag} ${hostedOnly2.join(", ")} select hosted runs; local sides take batch=, eval=<saved id>, revision=<number>, agent=, model=, since=, until=`);if((side.batch?.length??0)>1)throw new CliError("usage",`${flag} takes one batch= locally`);if((side.agent?.length??0)>1||(side.model?.length??0)>1)throw new CliError("usage",`${flag} takes one agent= and one model= locally`);if(side.evalRevision!==void 0&&!/^[1-9]\d*$/.test(side.evalRevision))throw new CliError("usage",`${flag} local revision= must be a positive integer`);return{batch:side.batch?.[0],evalId:side.evalSet,measurementRevision:side.evalRevision===void 0?void 0:Number(side.evalRevision),agent:side.agent?.[0],model:side.model?.[0],since:side.since?parseSince(side.since,Date.now(),"since="):void 0,until:side.until?parseSince(side.until,Date.now(),"until="):void 0}}function median(values){if(values.length===0)return null;const sorted=[...values].sort((a,b)=>a-b);const mid=sorted.length>>1;return sorted.length%2?sorted[mid]:(sorted[mid-1]+sorted[mid])/2}function localStats(runs){const judged=runs.filter(run=>run.criterionResults?.length&&run.criterionResults.every(criterion=>criterion.outcome!=="UNASSESSABLE"));const passed=judged.filter(run=>run.criterionResults.every(criterion=>criterion.outcome==="PASS")).length;const byCriterion=new Map;for(const run of runs)for(const criterion of run.criterionResults??[]){const current=byCriterion.get(criterion.name)??{name:criterion.name,judged:0,passed:0};if(criterion.outcome!=="UNASSESSABLE"){current.judged++;if(criterion.outcome==="PASS")current.passed++}byCriterion.set(criterion.name,current)}const recorded=values=>values.filter(value=>typeof value==="number"&&Number.isFinite(value));return{runs:runs.length,finished:runs.filter(run=>LOCAL_TERMINAL_STATES.has(run.outcome)).length,succeeded:runs.filter(run=>run.outcome==="completed").length,judged:judged.length,passed,passRate:judged.length?passed/judged.length:null,medianTurns:median(recorded(runs.map(run=>run.turns))),medianUsdCost:null,medianDurationMs:median(recorded(runs.map(run=>run.durationMs))),criteria:[...byCriterion.values()].map(criterion=>({...criterion,passRate:criterion.judged?criterion.passed/criterion.judged:null}))}}function diff(a,b){return a===null||b===null?null:b-a}function localRow(baseline,candidate){const a=localStats(baseline);const b=localStats(candidate);return{baseline:a,candidate:b,delta:{passRate:diff(a.passRate,b.passRate),medianTurns:diff(a.medianTurns,b.medianTurns),medianUsdCost:null,medianDurationMs:diff(a.medianDurationMs,b.medianDurationMs),criteria:[...new Set([...a.criteria,...b.criteria].map(criterion=>criterion.name))].map(name=>({name,passRate:diff(a.criteria.find(criterion=>criterion.name===name)?.passRate??null,b.criteria.find(criterion=>criterion.name===name)?.passRate??null)}))}}}function compareLocalRuns(baseline,candidate){const targets=new Map;for(const run of[...baseline,...candidate]){const agent=LOCAL_AGENTS2.has(run.agent)?run.agent:void 0;if(agent)targets.set(`${run.agent} ${run.model}`,{agent,model:run.model})}const forTarget=(runs,key)=>runs.filter(run=>`${run.agent} ${run.model}`===key);return{overall:localRow(baseline,candidate),targets:[...targets].map(([key,target])=>({...target,...localRow(forTarget(baseline,key),forTarget(candidate,key))})),sides:{baseline:localRevisionMetadata(baseline),candidate:localRevisionMetadata(candidate)}}}function localRevisionMetadata(runs){const byMeasurement=new Map;const allRevisions=new Set;for(const run of runs){if(run.measurementRevision===void 0||run.measurementRevision===null)continue;const revision=String(run.measurementRevision);allRevisions.add(revision);if(run.evalId){const revisions=byMeasurement.get(run.evalId)??new Set;revisions.add(revision);byMeasurement.set(run.evalId,revisions)}}return{evalRevisions:[...allRevisions].sort((a,b)=>Number(a)-Number(b)),mixedRevisions:[...byMeasurement].filter(([,revisions])=>revisions.size>1).map(([evalSetId,revisions])=>({evalSetId,promptId:null,revisions:[...revisions]})),truncated:false}}function localCompareWarnings(result){const warnings=compareWarnings(result).filter(warning=>!warning.includes("matched no runs")).map(warning=>warning.replace("gauge run wait <request-id>","gauge run wait --batch <batch-id> --local").replace("revision=<hash>","revision=<number>").replace("not judged yet, or no criteria","analysis missing, unassessable criteria, or no criteria"));for(const name of["baseline","candidate"])if(result.overall[name].runs===0)warnings.unshift(`${name} matched no local runs. Check its selectors: batch=, eval=<saved id>, revision=<number>, agent=, model=, since=, until=. \`gauge run list --local\` shows the values.`);return warnings}function runPath(id){return`/api/v1/runs/${encodeURIComponent(id)}`}function streamPath(id){return`/api/runs/${encodeURIComponent(id)}/stream`}function fmtDuration(ms){if(ms==null)return"";const s=Math.round(ms/1e3);return s>=60?`${Math.floor(s/60)}m${s%60}s`:`${s}s`}function fmtUsd(v){return v==null?"":`$${v.toFixed(2)}`}function fmtTriggeredBy(t){if(!t)return"";return t.email?`${t.source} (${t.email})`:t.source}function compact(value,max=140){const s=typeof value==="string"?value:JSON.stringify(value)??"null";const one=s.replace(/\s+/g," ").trim();return one.length>max?`${one.slice(0,max-1)}\u2026`:one}function toRow4(run){const selected=run.selectedProvider?.slug??"";const observed=run.observedProvider?.slug;return{id:run.id,status:run.status,agent:run.agent,model:run.modelDisplayName??run.resolvedModel??run.model,provider:observed&&observed!==selected?`${selected||"?"} \u2192 ${observed}`:selected||observed||"",experiment:run.experiment??"",revision:run.evalRevision??"",trial:run.optimizationTrial?`${run.optimizationTrial.key} ${run.optimizationTrial.trialId}`:"",source:run.triggeredBy?.source??"",turns:run.turns??"",cost:fmtUsd(run.usdCost),credits:run.creditsCharged??"",duration:fmtDuration(run.durationMs),created:run.createdAt,prompt:compact(run.promptSnippet,48)}}function toLocalRow(run){return{id:run.id,status:run.outcome,agent:run.agent,model:run.model,batch:run.batchId,eval:run.evalId??"",turns:run.turns,analyzed:run.analyzed?"yes":"",ended:run.endedAt}}function detailLines(run){return[["Id",run.id],["Status",run.status],["Agent",run.agent],["Model",run.modelDisplayName||run.resolvedModel||run.model||"(platform default)"],["Requested model",run.model||"(platform default)"],["Selected provider",run.selectedProvider?`${run.selectedProvider.displayName} (${run.selectedProvider.slug})`:"\u2014"],["Observed provider",run.observedProvider?`${run.observedProvider.slug} (${run.observedProvider.source.toLowerCase().replaceAll("_"," ")})`:"\u2014"],["Prompt",compact(run.promptText,120)],["Prompt id",run.promptId],["Batch",run.batchId],["Experiment",run.experiment??"\u2014"],["Eval set",run.evalSetId??"\u2014"],["Eval revision",run.evalRevision??"\u2014"],["Optimization trial",run.optimizationTrial?`${run.optimizationTrial.key} "${run.optimizationTrial.title}" (${run.optimizationTrial.kind}), trial ${run.optimizationTrial.trialId} in optimization ${run.optimizationTrial.optimizationId}`:"\u2014"],["Scenario",run.scenario],["Funding",run.funding],["Repo",run.repoUrl?`${run.repoUrl}${run.repoRef?` @ ${run.repoRef}`:""}`:"\u2014"],["Attempt",String(run.attempt)],["Turns",run.turns==null?"\u2014":String(run.turns)],["Triggered by",fmtTriggeredBy(run.triggeredBy)||"\u2014"],["Cost",fmtUsd(run.usdCost)||"\u2014"],["Credits",run.creditsCharged==null?"\u2014":String(run.creditsCharged)],["Duration",fmtDuration(run.durationMs)||"\u2014"],["Exit reason",run.exitReason??"\u2014"],["Failure reason",run.failureReason??"\u2014"],["Cancel requested",run.cancelRequested?"yes":"no"],["Diff",run.hasDiff?`yes (gauge run diff ${run.id})`:"no"],...run.criterionResults.map(c=>[`Criterion ${c.name}`,c.passed===null?"not assessed":c.passed?"passed":"failed"]),["Created",run.createdAt],["Started",run.startedAt??"\u2014"],["Finished",run.finishedAt??"\u2014"]]}function passLine(label,pass){const bits=[pass.status];if(pass.model)bits.push(pass.model);const cost=fmtUsd(pass.usdCost);if(cost)bits.push(cost);if(pass.error)bits.push(`error: ${compact(pass.error,60)}`);return`${label.padEnd(20)} ${bits.join(" ")}`}var PASS_LABELS={ANALYSIS:"Session analysis",CLI_DISCOVERY:"CLI discovery",LEVER:"Improvement levers",EXPERIMENT_DELTA:"Experiment delta"};var INSTALLED={NONE:"",ATTEMPTED:"attempted",CONFIGURED:"configured",EXERCISED:"exercised"};var check2=value=>value?"yes":"";function printInsight(insight){for(const pass of insight.passes){console.log(passLine(PASS_LABELS[pass.kind]??pass.kind,pass))}const analysis=insight.analysis;if(!analysis){console.log(insight.decision.status==="SKIPPED"?"\n(skipped)":"\n(no analysis yet)");return}if(analysis.limitation)console.log(`
|
|
774
|
+
█▄█ █▀█ █▄█ █▄█ ██▄`;async function printLogo(){const out=process.stdout;if(detectAgent(process.env,out.isTTY)==="agent"){console.log(SMALL_LOGO);return}if(process.env.CI||process.env.TERM==="dumb"){console.log(LOGO.replace(/^\n+/,""));return}out.write("\x1B[?25l");try{out.write(LOGO);const up=`\x1B[${LOGO.split("\n").length-1}A`;for(const[frame,wait]of[[BARK,220],[LOGO,150],[BARK,220],[LOGO,150],[BARK,220],[LOGO,150]]){await delay(wait);out.write(up+frame.replace(/\n/g,"\x1B[K\n"))}out.write("\n")}finally{out.write("\x1B[?25h")}}function nextSteps(mode){const bold=style("1");const cyan=style("36");const dim=style("2");const lines=[];lines.push(` ${bold("1. Install the Gauge agent skill")}`);lines.push(` ${cyan("$ gauge install-skill")}`);lines.push(` ${dim("\xB7")} Recommended. It teaches your coding agent the Gauge workflows.`);if(detectAgent(process.env,process.stdout.isTTY)==="agent")lines.push(` ${dim("\xB7")} Ask the user whether to install it, unless already installed or declined.`);lines.push("");(mode==="hosted"?HOSTED_STEPS:LOCAL_STEPS).forEach((step,i)=>{lines.push(` ${bold(`${i+2}. ${step.title}`)}`);if(step.command)lines.push(` ${cyan(`$ ${step.command}`)}`);for(const detail of step.details)lines.push(` ${dim("\xB7")} ${detail}`);lines.push("")});lines.push(`Agents: add ${cyan("-o json")} to any gauge command for JSON output.`);lines.push(`Docs: ${cyan(DOCS_URL)}`);return lines.join("\n")}function summarize(result){return`${result.gaugeJson==="created"?"Created":"Kept"} gauge.json. Backend: ${result.backend} (.gauge/config.json). Local state: .gauge/gauge.sqlite.${result.casesDir==="not-requested"?"":` Shared cases: gauge-cases/ (${result.casesDir}).`}`}function register14(program2,{cwd=process.cwd()}={}){program2.command("init").description("Initialize a Gauge workspace: shared gauge.json and private .gauge/ state. No Git or account required. Backend defaults to local independently of login.").option("--cases","also scaffold shared gauge-cases/ files").action(async(opts,cmd)=>{const state=readGaugeState(cmd.optsWithGlobals(),cwd);if(state.config===null)throw new CliError("usage","gauge.json is not valid JSON. Fix it before initializing.");const result=scaffoldWorkspace(state.root??resolve2(cwd),state.mode,opts.cases);if(resolveOutput(cmd)==="json"){printJson(result);return}await printLogo();console.log(`${style("32")("\u2713")} gauge init complete`);console.log(summarize(result));console.log(nextSteps(state.mode))})}var installSkill_exports={};__export(installSkill_exports,{register:()=>register15,summarizeInstaller:()=>summarizeInstaller});import{spawnSync}from"child_process";var ANSI=/\x1b\[[0-9;?]*[A-Za-z]/g;function summarizeInstaller(output){const lines=output.replace(ANSI,"").split("\n").map(line=>line.replace(/^\s*│/,"").replace(/│\s*$/,"").trim());const paths=[...new Set(lines.flatMap(line=>line.match(/^→ (\S+)$/)?.[1]??[]))];const audits={};const row2=lines.findIndex(line=>/^gauge-agents\s{2,}/.test(line));if(row2>0){const names=lines[row2-1].split(/\s{2,}/);const values=lines[row2].split(/\s{2,}/).slice(1);names.forEach((name,i)=>{if(values[i])audits[name]=values[i]})}const details=lines.flatMap(line=>line.match(/^Details: (\S+)$/)?.[1]??[])[0];return{paths,audits,details}}function register15(program2,{run=spawnSync,platform=process.platform,env=process.env,isTTY=process.stdout.isTTY}={}){program2.command("install-skill").description("Install Gauge's gauge-agents skill from gauge-sh/gauge-skills on GitHub using npx. People pick agents and scope in the installer; coding agents install for themselves in this project without prompts. No Gauge account needed").option("-a, --agent <name>","target an agent (e.g. claude-code or codex); repeat for multiple agents. Coding agents default to themselves",(value,previous)=>[...previous,value],[]).option("-g, --global","install across projects instead of in this repo").option("-y, --yes","skip installer prompts (requires --agent; defaults to project scope). Always on for coding agents").option("--copy","copy skill files instead of creating symlinks").action((opts,cmd)=>{const quiet=detectAgent(env,isTTY)==="agent";const self=quiet?detectSkillAgent(env):void 0;const agents=opts.agent.length||!self?opts.agent:[self];if(quiet&&!agents.length)throw new CliError("usage","Cannot detect the coding agent, and the installer cannot prompt here.",{hint:"Pass the agent, e.g. gauge install-skill --agent claude-code"});if(opts.yes&&!agents.length)throw new CliError("usage","--yes requires --agent to avoid installing for unrelated agents.",{hint:"For Claude Code: gauge install-skill --agent claude-code --yes"});if(agents.some(agent=>!/^[a-z0-9-]+$/.test(agent)))throw new CliError("usage","Agent names must contain only lowercase letters, digits, and hyphens.");const args=["--yes","skills@1.5.0","add","gauge-sh/gauge-skills","--skill","gauge-agents"];for(const agent of agents)args.push("--agent",agent);if(opts.global)args.push("--global");if(opts.yes||quiet)args.push("--yes");if(opts.copy)args.push("--copy");const json=resolveOutput(cmd)==="json";console.error("Installing gauge-agents from gauge-sh/gauge-skills...");const result=run(platform==="win32"?"npx.cmd":"npx",args,{shell:platform==="win32",stdio:quiet?["ignore","pipe","pipe"]:["inherit",json?2:"inherit","inherit"]});const output=quiet?`${result.stdout??""}${result.stderr??""}`:"";if(result.error||result.status!==0){if(output)process.stderr.write(output.replace(ANSI,""));const reason=result.error?.message??(result.signal?`installer interrupted by ${result.signal}`:`installer exited with code ${result.status}`);throw new CliError("internal",`Skill installation failed: ${reason}.`,{hint:"Run gauge install-skill again. Node.js and network access are required."})}if(!quiet){if(json)printJson({completed:true,skill:"gauge-agents"});else console.log("Gauge skill installer completed.");return}const summary=summarizeInstaller(output);if(json){printJson({completed:true,skill:"gauge-agents",agents,...summary});return}console.log(`Installed gauge-agents for ${agents.join(", ")}${summary.paths.length?`: ${summary.paths.join(", ")}`:"."}`);const audits=Object.entries(summary.audits).map(([name,value])=>`${name} ${value}`);if(audits.length)console.log(`skills.sh audits: ${audits.join(", ")}.${summary.details?` Details: ${summary.details}`:""}`)})}var keys_exports2={};__export(keys_exports2,{register:()=>register16});function keysPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/provider-keys`}function providerArg(raw){const provider=raw.toLowerCase();if(!keys_exports.PROVIDER_TYPES.includes(provider)){throw new CliError("usage",`Unknown provider "${raw}" (expected ${keys_exports.PROVIDER_TYPES.join("|")})`)}return provider}async function readKeyInput(opts){if(!opts.stdin){const env=process.env.GAUGE_PROVIDER_KEY?.trim();if(env)return env}if(process.stdin.isTTY){process.stderr.write("Paste the API key, press Enter, then Ctrl-D:\n")}process.stdin.setEncoding("utf8");let data="";for await(const chunk of process.stdin)data+=chunk;const key=data.trim();if(!key){throw new CliError("usage","No key provided. Pipe it to stdin (e.g. `gauge keys set anthropic < key.txt`) or set GAUGE_PROVIDER_KEY.")}return key}function register16(program2){const group=hostedOnly(program2.command("keys")).description("Manage BYOK provider keys (write-only; reads show last4)");group.command("set <provider>").description("Set a provider key (anthropic|openai); reads it from stdin or GAUGE_PROVIDER_KEY").option("--stdin","read the key from stdin (ignores GAUGE_PROVIDER_KEY)").action(async(provider,opts,cmd)=>{const type=providerArg(provider);const org=await resolveOrg(cmd);const key=await readKeyInput(opts);const res=await createClient().put(`${keysPath(org)}/${type}`,{key});if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Saved ${res.providerType} key (\u2026${res.last4})`)});group.command("list").description("List configured provider keys").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(keysPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(k=>({providerType:k.providerType,last4:`\u2026${k.last4}`,createdAt:k.createdAt,updatedAt:k.updatedAt})),"table")});group.command("rm <provider>").description("Remove a provider key").action(async(provider,_opts,cmd)=>{const type=providerArg(provider);const org=await resolveOrg(cmd);await createClient().delete(`${keysPath(org)}/${type}`);if(resolveOutput(cmd)!=="json")console.log(`Removed ${type} key`)});group.command("disable-byok").description("Switch back to Gauge-managed metered billing (remove provider keys first)").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);await createClient().delete(keysPath(org));if(resolveOutput(cmd)!=="json")console.log("BYOK disabled \u2014 runs are Gauge-managed and metered again")})}var localRuntime_exports={};__export(localRuntime_exports,{register:()=>register17});function print(result,command){if(resolveOutput(command)==="json")printJson(result);else{console.log(`Runtime: ${result.reference}`);if(result.imageId)console.log(`Image ID: ${result.imageId}`);if(result.repoDigest)console.log(`Registry digest: ${result.repoDigest}`);console.log(`Status: ${result.ready?"ready":result.problem?.code}`);if(result.platform)console.log(`Platform: ${result.platform}`);if(result.problem)console.log(`${result.problem.message}
|
|
775
|
+
${result.problem.hint}`);console.log(`Gateway: ${result.gateway.reference} (${result.gateway.ready?"ready":result.gateway.problem?.code})`);if(result.gateway.problem)console.log(`${result.gateway.problem.message}
|
|
776
|
+
${result.gateway.problem.hint}`)}if(!result.ready||!result.gateway.ready)process.exitCode=1}function register17(program2){const local=program2.commands.find(command=>command.name()==="local")??program2.command("local").description("Configure local execution (no Gauge account needed)");const runtime=local.command("runtime").description("Inspect or download the supported Docker runtime");runtime.command("inspect").description("Report local runtime availability and compatibility without downloading").action((_options,command)=>print({...inspectLocalRuntime(),gateway:inspectLocalGateway()},command));runtime.command("pull").description("Download the CLI's supported public runtime image").action(async(_options,command)=>print({...await pullLocalRuntime(),gateway:await pullLocalGateway()},command))}var mcp_exports={};__export(mcp_exports,{register:()=>register18});import{readFileSync as readFileSync7}from"fs";function mcpPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/mcp-servers`}function serverPath(org,ref){return`${mcpPath(org)}/${encodeURIComponent(ref)}`}function specLabel(spec){return spec.transport==="stdio"?[spec.command,...spec.args??[]].join(" "):spec.url??""}function specFromOpts(opts){if(opts.specFile!==void 0){if(opts.command!==void 0||opts.url!==void 0)throw new CliError("usage","--spec-file conflicts with --command/--url");try{return JSON.parse(readFileSync7(opts.specFile==="-"?0:opts.specFile,"utf8"))}catch(e){throw new CliError("usage",`could not read --spec-file: ${e instanceof Error?e.message:e}`)}}if(opts.command!==void 0===(opts.url!==void 0))throw new CliError("usage","pass exactly one of --command (stdio) or --url (http), or --spec-file");const tools=opts.tool.map(line=>{const colon=line.indexOf(":");return colon>0?{name:line.slice(0,colon).trim(),description:line.slice(colon+1).trim()}:{name:line.trim()}});return{transport:opts.command!==void 0?"stdio":"http",...opts.command!==void 0?{command:opts.command,args:opts.arg,envNames:opts.env}:{url:opts.url,headerNames:opts.header},...opts.serverName?{serverName:opts.serverName}:{},...opts.description?{description:opts.description}:{},...tools.length?{tools}:{}}}function register18(program2){const group=hostedOnly(program2.command("mcp"),{hint:LOCAL_MCP_HINT}).description("Manage MCP servers used by hosted eval and preference runs");group.command("list").description("List the org's MCP servers with their newest version").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(mcpPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(s=>({name:s.name,latest:s.latestVersion?.label??"",versions:s.versionCount,transport:s.latestVersion?.spec.transport??"",invocation:s.latestVersion?specLabel(s.latestVersion.spec):"",note:s.note??""})),"table")});group.command("get <ref>").description("Show one MCP server: note and every version").action(async(ref,_opts,cmd)=>{const org=await resolveOrg(cmd);const server=await createClient().get(serverPath(org,ref));if(resolveOutput(cmd)==="json"){printJson(server);return}console.log(`name: ${server.name}`);console.log(`id: ${server.id}`);console.log(`note: ${server.note??"(none)"}`);console.log("versions:");for(const v of server.versions){console.log(` ${server.name}@${v.label} [${v.spec.transport}] ${specLabel(v.spec)} ${v.createdAt}`);for(const w of v.warnings)console.log(` warning: ${w.message}`)}});group.command("add").description("Add a server, or append a version to an existing --name (versions are immutable)").requiredOption("--name <handle>","the handle (the agent config key)").option("--command <cmd>","stdio launch command, e.g. npx").option("--arg <arg>","stdio argument (repeatable)",collect5,[]).option("--env <NAME>","required env-var NAME \u2014 never a value (repeatable)",collect5,[]).option("--url <url>","http endpoint").option("--header <NAME>","required header NAME \u2014 never a value (repeatable)",collect5,[]).option("--server-name <name>","agent-visible server name (default: handle)").option("--description <text>","agent-visible description").option("--tool <name[: description]>","declared tool (repeatable)",collect5,[]).option("--spec-file <path>",'whole spec as JSON ("-" for stdin)').option("--label <label>","version label (a typed label always mints; omitted dedups by spec digest)").option("--note <text>","note shown on the index").action(async(opts,cmd)=>{const org=await resolveOrg(cmd);const result=await createClient().post(mcpPath(org),{name:opts.name,spec:specFromOpts(opts),label:opts.label,note:opts.note});if(resolveOutput(cmd)==="json"){printJson(result);return}console.log(result.unchanged?`Already current: ${result.handle}@${result.label} carries this spec`:`Saved ${result.handle}@${result.label} \u2014 ${result.invocation}`);for(const w of result.warnings)console.error(`warning: ${w.message}`);console.error(`Attach it to an eval: gauge eval edit <id> --mcp ${result.handle}@${result.label}`)});group.command("edit <ref>").description("Rename or note a server (append versions with `gauge mcp add --name <handle>`)").option("--rename <handle>","new handle (name@label refs must be updated)").option("--note <text>","replace the note").option("--clear-note","remove the note").action(async(ref,opts,cmd)=>{const org=await resolveOrg(cmd);if(opts.note!==void 0&&opts.clearNote)throw new CliError("usage","--note and --clear-note conflict");const body={};if(opts.rename!==void 0)body.name=opts.rename;if(opts.clearNote)body.note=null;else if(opts.note!==void 0)body.note=opts.note;if(Object.keys(body).length===0)throw new CliError("usage","nothing to change");const updated=await createClient().patch(serverPath(org,ref),body);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated MCP server ${updated.name}`)});group.command("rm <ref>").description("Remove a server; the handle stays reserved and finished runs keep their snapshot").action(async(ref,_opts,cmd)=>{const org=await resolveOrg(cmd);const result=await createClient().delete(serverPath(org,ref));if(resolveOutput(cmd)==="json")printJson(result);else console.log(`Deleted MCP server ${ref} (${result.referencedRuns} finished run(s) referenced it)`)})}var members_exports={};__export(members_exports,{register:()=>register19});function register19(program2){const group=hostedOnly(program2.command("members")).description("Team members and pending invites (read-only)");group.command("list").description("List members and pending invites").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const client=createClient();const base=`/api/v1/orgs/${encodeURIComponent(org)}`;const[members,pending]=await Promise.all([client.get(`${base}/members`),client.get(`${base}/invites`)]);if(resolveOutput(cmd)==="json"){printJson({members:members.items,invites:pending.items});return}printItems(members.items.map(m=>({email:m.email??"",name:m.name??"",joined:m.joinedAt})),"table");if(pending.items.length>0){console.log("\npending invites:");printItems(pending.items.map(i=>({id:i.id,email:i.email,"invited by":i.invitedBy.email??i.invitedBy.name??"",expires:i.expiresAt})),"table")}})}var models_exports={};__export(models_exports,{capabilityLabel:()=>capabilityLabel,executionTargetsPath:()=>executionTargetsPath,register:()=>register20});function executionTargetsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/execution-targets`}function capabilityLabel(capabilities){return Object.entries(capabilities).filter(([,supported])=>supported).map(([name])=>name==="agentContext"?"context":name).join(", ")}function register20(program2){const group=program2.command("models").description("Discover supported models, harnesses, and providers");group.command("list",{isDefault:true}).description("List execution targets available to the organization. Local: the agents local runs support, with default models").action(async(_opts,cmd)=>{if(gaugeState(cmd).mode==="local"){const agents=Object.entries(LOCAL_AGENTS).map(([agent,target])=>({agent,harness:target.kind,defaultModel:target.model}));if(resolveOutput(cmd)==="json")printJson(agents);else printItems(agents,"table");return}const org=await resolveOrg(cmd);const response=await createClient().get(executionTargetsPath(org));if(resolveOutput(cmd)==="json"){printJson(response.items);return}printItems(response.items.map(target=>({model:target.model,name:target.modelLabel,harness:target.harnessSlug,provider:target.providerSlug,capabilities:capabilityLabel(target.capabilities)})),"table")})}var localProfiles_exports={};__export(localProfiles_exports,{register:()=>register21});function register21(program2){const local=program2.commands.find(command=>command.name()==="local")??program2.command("local").description("Configure local execution");const profiles=local.command("profiles").description("Manage local agent credentials (references only; separate from Gauge account login)");profiles.command("list").description("List profiles and per-harness defaults; never print secrets").action((_opts,cmd)=>{const store=readProfiles();printItems(Object.entries(store.profiles).map(([name,p])=>({name,...p,active:store.defaults[p.agent]===name})),resolveOutput(cmd))});profiles.command("set <profile>").description("Create a profile or update it with --replace; --env takes a variable name, never a secret").requiredOption("--agent <agent>","CLAUDE_CODE, CODEX_CLI, PI, or OPENCODE").requiredOption("--provider <provider>","anthropic, openai, openai-codex, fireworks, or openrouter").requiredOption("--auth <mode>","access_token (native login), api_key, or setup_token (Claude only)").option("--env <variable>","environment variable holding the key/token (defaults to the provider's standard variable)").option("--replace","replace an existing profile").action((name,opts,cmd)=>{const{replace,...profile}=opts;const store=setProfile(name,profile,replace);const result={name,...store.profiles[name],active:store.defaults[profile.agent]===name};if(resolveOutput(cmd)==="json")printJson(result);else console.log(`Saved profile ${name}. Select with gauge local profiles use ${name}, or gauge run --local --profile ${name}.`)});profiles.command("use <profile>").description("Set the default for this profile's harness").action((name,_opts,cmd)=>{const store=readProfiles();const profile=requireProfile(store,name);store.defaults[profile.agent]=name;writeProfiles(store);if(resolveOutput(cmd)==="json")printJson({agent:profile.agent,profile:name});else console.log(`${profile.agent} now uses ${name}.`)});profiles.command("remove <profile>").description("Remove a reference and its default selection; keep native logins and environment variables").action((name,_opts,cmd)=>{const store=readProfiles();requireProfile(store,name);delete store.profiles[name];const cleared=Object.keys(store.defaults).filter(agent=>store.defaults[agent]===name);for(const agent of cleared)delete store.defaults[agent];writeProfiles(store);if(resolveOutput(cmd)==="json")printJson({removed:name,clearedDefaults:cleared});else console.log(`Removed ${name}.${cleared.length?` ${cleared.join(", ")} now uses automatic credential discovery.`:""}`)});profiles.command("inspect <profile>").description("Check local compatibility, credential availability and expiry; does not call the provider").option("--model <model>","check this model (default: the harness's default model)").action(async(name,opts,cmd)=>{const store=readProfiles();const p=requireProfile(store,name);if(!opts.model&&(p.agent==="PI"||p.agent==="OPENCODE")&&!LOCAL_TARGETS[p.agent].model.startsWith(`${p.provider}/`)){throw new CliError("usage",`Specify --model ${p.provider}/<model> to inspect this profile.`,{hint:`The ${p.agent} default model uses a different provider. Choose a model available through ${p.provider}.`})}const result=await inspectLocalCredential(p.agent,opts.model??LOCAL_TARGETS[p.agent].model,{profile:name},store);if(resolveOutput(cmd)==="json")printJson(result);else{console.log(`${name}: ${result.ready?"ready locally":"not ready"} for ${result.agent} ${result.model}`);if(result.profile)console.log(`Source: ${result.profile.source}; auth: ${result.profile.auth}`);if(result.expiresAt)console.log(`Expires: ${result.expiresAt}`);if(result.problem)console.log(result.problem);console.log("Local checks do not verify provider acceptance or model access.")}if(!result.ready)process.exitCode=1})}var onboard_exports={};__export(onboard_exports,{register:()=>register22});var PERSONAL_DOMAINS=new Set(["gmail.com","googlemail.com","yahoo.com","hotmail.com","outlook.com","live.com","icloud.com","me.com","aol.com","proton.me","protonmail.com"]);function emailDomain(email){const domain=email?.split("@")[1]?.toLowerCase();return domain&&!PERSONAL_DOMAINS.has(domain)?domain:void 0}function orgNameFromEmail(email){const base=emailDomain(email)?.split(".")[0]??"";if(!base)return"My Workspace";return base.charAt(0).toUpperCase()+base.slice(1)}function websiteFromEmail(email){const domain=emailDomain(email);return domain?`https://${domain}`:void 0}async function ensureAccount(opts={}){const log=opts.log??console.log;let client;let me;if(resolveToken()){client=new ApiClient;me=await client.get("/api/v1/me");log(`Already signed in as ${me.user.email??me.user.id}.`)}else{const login=await deviceLogin({email:opts.email});await withCredentialLock(async()=>{if(login.credentials)saveCredentials(login.credentials);else saveToken(login.token)});useOnlyOrg(login.me,login.token.startsWith("gauge_cli_"),log);client=new ApiClient;me=await client.get("/api/v1/me");log(`
|
|
777
|
+
Signed in as ${me.user.email??me.user.id} \u2014 token saved to ${credentialsPath()}.`)}const directory=await fetchDirectory();const wantNewOrg=opts.new===true||opts.orgName!==void 0||me.orgs.length===0;let organization;let createdOrg=null;const website=opts.website??websiteFromEmail(me.user.email);if(wantNewOrg){const name=opts.orgName?.trim()||orgNameFromEmail(me.user.email);createdOrg=await client.post("/api/v1/orgs",{name,website});organization=await createdOrganization(createdOrg.slug)}else{const config=readConfig();if(!config.orgId&&config.defaultOrg)legacySelection("config");const linkedIds=new Set(me.orgs.map(org2=>org2.canonicalGaugeOrganizationId).filter(Boolean));const available=directory.filter(org2=>linkedIds.has(org2.id));const selected=config.orgId?available.find(org2=>org2.id===config.orgId):available.length===1?available[0]:void 0;if(selected)organization=selected;else throw new CliError("usage","Select a Gauge Agents organization before onboarding.",{hint:"Run `gauge orgs`, then `gauge orgs use <slug>`."})}const org=organization.id;updateConfig({orgId:org,defaultOrg:void 0});log(createdOrg?`Created workspace ${organization.name} (${organization.slug}).`:`Using workspace ${organization.name} (${organization.slug}).`);let seeded=null;if(opts.seed!==false&&createdOrg){log("Seeding starter measurements (scanning your site)\u2026");try{seeded=await client.post(`/api/v1/orgs/${encodeURIComponent(org)}/onboarding/seed`,website?{website}:{});log(`Seeded ${seeded.evalSets} eval set(s) and ${seeded.visibilityPrompts} preference prompt(s)`+(seeded.markets?` across ${seeded.markets} market(s).`:"."))}catch(e){console.error(`warning: seeding skipped \u2014 ${e instanceof Error?e.message:e}`)}}return{user:me.user,org,organization,createdOrg,seeded}}function register22(program2){hostedOnly(program2.command("onboard"),{account:true}).description("Sign in to hosted Gauge and set up your workspace. Then run `gauge init --hosted` in a repo to connect it").option("--email <email>","email a sign-in link (device-flow convenience)").option("--org-name <name>","workspace name (default: from your email)").option("--website <url>","company site, scanned to seed the workspace (default: from your email)").option("--new","create a new workspace even if you already belong to one").option("--no-seed","skip seeding starter eval sets and the Agent Preference portfolio").action(async(opts,command)=>{const output=resolveOutput(command);const account=await ensureAccount({...opts,log:output==="json"?()=>{}:console.log});if(output==="json"){printJson({user:account.user,org:account.organization,orgId:account.org,seeded:account.seeded});return}console.log(`
|
|
778
|
+
Default org set to ${account.organization.slug}. You're ready:`);console.log(" gauge status # the org at a glance");console.log(" gauge eval list # eval sets"," gauge preference list # preference prompts");console.log(" gauge run --eval <id> # launch one now");let inRepo=false;try{inRepo=gaugeState(command).inRepo}catch{}console.log(inRepo?" gauge init --hosted # connect this repo":" gauge init --hosted # connect a repo (run it inside the repo)")})}var optimizations_exports={};__export(optimizations_exports,{NEEDS_INPUT_EXIT:()=>NEEDS_INPUT_EXIT,awaitingInput:()=>awaitingInput,parseStatuses:()=>parseStatuses,parseSubject:()=>parseSubject,parseTarget:()=>parseTarget,readSkillDir:()=>readSkillDir,register:()=>register23,trialBodyFromOpts:()=>trialBodyFromOpts,trialTemplate:()=>trialTemplate,trialWarnings:()=>trialWarnings,watchStops:()=>watchStops});import{readdirSync,readFileSync as readFileSync8,statSync as statSync2}from"fs";import{join as join8,relative as relative3,sep}from"path";var TERMINAL=new Set(["DONE","ARCHIVED"]);function basePath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/optimizations`}function itemPath(org,id){return`${basePath(org)}/${encodeURIComponent(id)}`}function trialPath(org,id,trialId){return`${itemPath(org,id)}/trials/${encodeURIComponent(trialId)}`}var FAILED_RUN=new Set(["FAILED","TIMED_OUT"]);function readText(path){return readFileSync8(path==="-"?0:path,"utf8")}function sleep2(ms){return new Promise(resolve5=>setTimeout(resolve5,ms))}function parseSubject(opts){if(opts.eval&&opts.preference)throw new CliError("usage","pass --eval or --preference, not both");if(opts.eval)return{subjectKind:"EVAL_SET",subjectId:opts.eval};if(opts.preference)return{subjectKind:"VISIBILITY_PROMPT",subjectId:opts.preference};throw new CliError("usage","pass --eval <id> or --preference <id>")}function parseTarget(raw){const spec=parseAgentSpec(raw);if(spec.models.length>1)throw new CliError("usage",`--target "${raw}" names several models; an optimization pins exactly one`);return spec.models.length?{agent:spec.agent,model:spec.models[0]}:{agent:spec.agent}}function parseCount(raw,flag,max=100){if(raw===void 0)return void 0;const n=Number(raw);if(!Number.isInteger(n)||n<1||n>max)throw new CliError("usage",`${flag} must be a positive integer no greater than ${max}`);return n}var NEEDS_INPUT_EXIT=4;var NEXT_ACTION_HINT={START:"start the draft: `gauge optimizations start-draft <id>`",WAIT:"sessions are running; nothing to do",AUTHOR_TRIAL:"author the next trial: `gauge optimizations trials add <id>`",LAUNCH_ROUND:"launch the saved round: `gauge optimizations launch <id>`",ADOPT:"adopt the winning trial: `gauge optimizations adopt <id> <trial>`",RESUME:"resume it in the web app, or `gauge optimizations cancel <id>`",NONE:"nothing to do in Gauge"};function awaitingInput(detail){return detail.nextAction!=="WAIT"&&detail.nextAction!=="NONE"}function watchStops(detail,follow){return TERMINAL.has(detail.status)||detail.nextAction==="NONE"||!follow&&awaitingInput(detail)}function readObject(path){let value;try{value=JSON.parse(readText(path))}catch{throw new CliError("usage","the file must contain valid JSON")}if(!value||typeof value!=="object"||Array.isArray(value))throw new CliError("usage","the file must contain a JSON object");return value}function targetFromOpts(opts){return opts.target?{target:parseTarget(opts.target)}:{}}function parseStatuses(raw){if(!raw)return void 0;const parts=raw.split(",").map(part=>part.trim().toUpperCase()).filter(Boolean);for(const part of parts)if(!["DRAFT","ACTIVE","PAUSED","DONE","ARCHIVED"].includes(part))throw new CliError("usage",`unknown status "${part}" (expected DRAFT, ACTIVE, PAUSED, DONE, ARCHIVED)`);return parts.join(",")}function readSkillDir(dir,read2=readText,walk=listFiles){const paths=walk(dir).sort();if(!paths.length)throw new CliError("usage",`no files under ${dir} to send`);const files=paths.map(path=>({path:relative3(dir,path).split(sep).join("/"),body:read2(path)}));if(!files.some(file=>file.path==="SKILL.md"))throw new CliError("usage",`${dir} has no SKILL.md; a skill bundle must carry one`);return files}function listFiles(dir){let entries;try{entries=readdirSync(dir).map(String)}catch{throw new CliError("usage",`cannot read the directory ${dir}`)}return entries.flatMap(entry=>{const path=join8(dir,entry);return statSync2(path).isDirectory()?listFiles(path):[path]})}function trialBodyFromOpts(opts,read2=readText,walk){const launch2=opts.launch===true;const idempotencyKey=opts.idempotencyKey;if(opts.file){let parsed;try{parsed=JSON.parse(read2(opts.file))}catch{throw new CliError("usage","the trial file must contain valid JSON")}const pick=parseCount(opts.pick,"--pick")??1;let chosen;if(Array.isArray(parsed)){if(pick>parsed.length)throw new CliError("usage",`--pick ${pick} but the file holds ${parsed.length} proposal${parsed.length===1?"":"s"}`);chosen=parsed[pick-1]}else{if(opts.pick!==void 0)throw new CliError("usage","--pick applies to a proposals array");chosen=parsed}if(!chosen||typeof chosen!=="object"||Array.isArray(chosen))throw new CliError("usage","the trial file must contain an object or a non-empty array of objects");const record2=chosen;const body="trial"in record2?record2:{trial:record2};return{...body,...idempotencyKey?{idempotencyKey}:{},launch:launch2}}if(!opts.title)throw new CliError("usage","--title is required");const lever=opts.lever?.toUpperCase();let intervention;let files;if(opts.page||opts.bodyFile){if(!opts.page||!opts.bodyFile)throw new CliError("usage","--page and --body-file go together");intervention={kind:"REWRITE_DOCS",after:{pages:[{url:opts.page,body:read2(opts.bodyFile)}]}}}else if(opts.editSkill){if(!opts.skillDir)throw new CliError("usage","--edit-skill needs --skill-dir <path>: an edit sends the complete bundle");intervention={kind:"EDIT_SKILL",before:{skillVersionId:opts.editSkill},after:{skillVersionId:opts.editSkill}};files=readSkillDir(opts.skillDir,read2,walk)}else{throw new CliError("usage","describe the change: --edit-skill <id> --skill-dir <path>, --page <url> --body-file <path>, or --file <trial.json>")}const trial={title:opts.title,hypothesis:opts.hypothesis,lever:lever??(intervention.kind==="REWRITE_DOCS"?"DOCS":"SKILL"),intervention,authorMode:"MANUAL"};return{trial,...files?{files}:{},...idempotencyKey?{idempotencyKey}:{},launch:launch2}}var TRIAL_TEMPLATES={EDIT_SKILL:{trial:{title:"Name the env var in the first line",hypothesis:"The agent reads only the opening paragraph",lever:"SKILL",intervention:{kind:"EDIT_SKILL",before:{skillVersionId:"sv_REPLACE_ME"},after:{skillVersionId:"sv_REPLACE_ME"}},authorMode:"MANUAL"},files:[{path:"SKILL.md",body:"# Skill\n\nThe complete rewritten file.\n"}]},REWRITE_DOCS:{trial:{title:"Move the auth note above the example",hypothesis:"The agent copies the example before reading the note",lever:"DOCS",intervention:{kind:"REWRITE_DOCS",after:{pages:[{url:"https://example.com/docs/quickstart",body:"The complete rewritten page body."}]}},authorMode:"MANUAL"}}};function trialTemplate(kind){const template=TRIAL_TEMPLATES[kind.trim().toUpperCase()];if(!template)throw new CliError("usage",`--kind must be one of ${Object.keys(TRIAL_TEMPLATES).join(", ")} (got "${kind}")`);return template}function pct2(value){return value===null||value===void 0?"\u2014":`${Math.round(value*100)}%`}function subjectLabel(kind){return kind==="EVAL_SET"?"eval":"preference"}function toRow2(o){return{id:o.id,name:o.name.length>40?`${o.name.slice(0,37)}...`:o.name,status:o.status,subject:`${subjectLabel(o.subjectKind)} ${o.subjectName}`,round:o.round,baseline:pct2(o.before),now:pct2(o.after),delta:o.delta===null?"\u2014":`${o.delta>0?"+":""}${o.delta}pt`,credits:o.creditsSpent,updated:o.updatedAt}}function trialRow(t){return{key:t.key,round:t.roundNumber,title:t.title.length>48?`${t.title.slice(0,45)}...`:t.title,surface:t.lever??"",change:t.kind,status:t.status,score:pct2(t.score),result:t.verdict??"",sessions:t.sessions,failed:t.failedSessions||"",winner:t.adopted?"yes":"",id:t.id}}function printDetail2(o){console.log(`id: ${o.id}`);console.log(`name: ${o.name}`);console.log(`status: ${o.status}${o.stopReason?` (${o.stopReason})`:""}`);console.log(`mode: ${o.autonomous?"autonomous (legacy)":"interactive; launch each saved round explicitly"}`);console.log(`subject: ${subjectLabel(o.subjectKind)} ${o.subjectName} (${o.subjectId})`);console.log(`target: ${o.settings.pinnedAgent??"(subject roster)"}${o.settings.pinnedModel?`:${o.settings.pinnedModel}`:""}`);console.log(`sessions: ${o.settings.sampleCount} per trial`);console.log(`credits: ${o.creditsSpent} spent`);console.log(`score: ${pct2(o.before)} \u2192 ${pct2(o.after)}${o.delta===null?"":` (${o.delta>0?"+":""}${o.delta}pt)`}`);if(o.summary)console.log(`summary: ${o.summary}`);console.log(`next: ${o.nextAction} \u2014 ${NEXT_ACTION_HINT[o.nextAction]??""}`);console.log("trials:");const trials=o.rounds.flatMap(round=>round.trials);printItems(trials.map(trialRow),"table");for(const round of o.rounds)if(round.narrative)console.log(`round ${round.number}: ${round.narrative}`);for(const line of trials.flatMap(trialWarnings))console.error(line)}function runDetails(id){return`(details: \`gauge run get ${id}\`, \`gauge run get ${id} --logs\`)`}function trialWarnings(t){const total=`${t.runs.length} session${t.runs.length===1?"":"s"}`;const failed=t.runs.filter(run=>FAILED_RUN.has(run.status));const unproven=t.runs.filter(run=>!FAILED_RUN.has(run.status)&&run.cliCoverage?.instrumentationFailed);const lines=[];if(failed.length)lines.push(`WARNING ${t.key}: ${failed.length} of ${total} failed; the score and verdict leave them out. Tell the user before you trust this result.`,...failed.map(run=>` ${run.id}: ${run.status}: ${run.failureReason??run.exitReason??"no reason recorded"} ${runDetails(run.id)}`));if(unproven.length)lines.push(`WARNING ${t.key}: ${unproven.length} of ${total} have incomplete command evidence; the score counts them, but the CLI change may not have applied. Tell the user.`,...unproven.map(run=>` ${run.id}: ${runDetails(run.id)}`));return lines}function printTrial(t){console.log(`key: ${t.key} (round ${t.roundNumber}) \u2014 ${t.id}`);console.log(`title: ${t.title}`);if(t.hypothesis)console.log(`hypothesis: ${t.hypothesis}`);console.log(`change: ${t.kind}${t.lever?` on ${t.lever}`:""}`);console.log(`status: ${t.status}${t.verdict?` \xB7 ${t.verdict}`:""}${t.adopted?" \xB7 winner":""}`);console.log(`score: ${pct2(t.baselineScore)} \u2192 ${pct2(t.score)} over ${t.sessions} session${t.sessions===1?"":"s"}`);if(t.outcome)console.log(`outcome: ${t.outcome}`);if(t.runs.length){console.log("sessions:");for(const run of t.runs){const verdict=run.passed===null?"not assessed":run.passed?"pass":"fail";console.log(` ${run.id}: ${run.status} \xB7 ${verdict}`);if(FAILED_RUN.has(run.status))console.log(` error: ${run.failureReason??run.exitReason??"no reason recorded"}`);else if(run.cliCoverage?.instrumentationFailed)console.log(" warning: command evidence is incomplete");for(const criterion of run.criteria)console.log(` ${criterion.passed===null?"?":criterion.passed?"\u2713":"\u2717"} ${criterion.name}`)}}for(const line of trialWarnings(t))console.error(line)}function printChange(content){for(const doc of content.documents){console.log(`=== ${doc.path}`);console.log("--- before");console.log(doc.before||"(empty)");console.log("+++ after");console.log(doc.after||"(empty)")}}function printRoundPreview(preview){for(const trial of preview.trials){console.log(trial.title);for(const change of trial.changes??[]){console.log(`=== ${change.path}`);console.log(change.hunks)}for(const path of trial.droppedFiles??[])console.log(` ${path}: dropped`)}console.log(`previewDigest ${preview.previewDigest}`)}function printDiagnosis(d){console.log(`id: ${d.id}`);console.log(`status: ${d.status} over ${d.runCount} sessions`);console.log(`summary: ${d.summary??"(none)"}`);console.log(`recommended: ${d.recommendedLever??"no single lever"}`);if(d.unsupportedLevers.length)console.log(`not yet supported: ${d.unsupportedLevers.join(", ")}`);if(d.clusters.length){console.log("opportunities:");for(const cluster of d.clusters)console.log(` - ${cluster.title} [${cluster.lever??"?"} \xB7 ${Math.round(cluster.confidence*100)}%] ${cluster.failureMode}`)}}function addSubjectOptions(command){return command.option("--eval <id>","an Agent Experience eval").option("--preference <id>","an Agent Preference prompt")}function addTargetOption(command){return command.option("--target <agent[:model]>","the one harness/model every session runs on, e.g. claude-code:claude-opus-4-8")}function register23(program2){const group=hostedOnly(program2.command("optimizations")).description("Start, steer, and read optimizations: Gauge changes one owned surface per trial and reports the best measured change against the baseline");group.command("list").description("List the org's optimizations, newest activity first").option("--status <statuses>","comma-separated: DRAFT,ACTIVE,PAUSED,DONE,ARCHIVED").option("--no-drafts","leave out draft workspaces").option("--eval <id>","only optimizations on this eval").option("--preference <id>","only optimizations on this preference prompt").option("--limit <n>","max rows (default 50)").action(async(opts,cmd)=>{const org=await resolveOrg(cmd);const subject=opts.eval||opts.preference?parseSubject(opts):void 0;const res=await createClient().get(basePath(org),{status:parseStatuses(opts.status),subjectKind:subject?.subjectKind,subjectId:subject?.subjectId,limit:parseCount(opts.limit,"--limit",200),includeDrafts:opts.drafts});if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(toRow2),"table")});addSubjectOptions(group.command("baselines").description("Discover which ordinary runs exposed which owned surfaces, and whether they can seed an optimization")).option("--limit <n>","page size (1\u2013100)","50").option("--cursor <cursor>","nextCursor from the previous page").action(async(opts,cmd)=>{const response=await createClient().get(`${basePath(await resolveOrg(cmd))}/baselines`,{...parseSubject(opts),limit:parseCount(opts.limit,"--limit"),cursor:opts.cursor});if(resolveOutput(cmd)==="json")printJson(response);else{printItems(response.items.flatMap(run=>(run.surfaces.length?run.surfaces:[{lever:"\u2014",label:"No recorded surface evidence"}]).map(surface=>({run:run.runId,model:run.model||run.resolvedModel||run.agent,date:run.createdAt.slice(0,10),criteria:run.outcome.totalCriteria?`${run.outcome.passedCriteria}/${run.outcome.totalCriteria}`:"\u2014",status:run.status,surface:surface.lever,target:surface.label,eligible:run.eligibility.eligible?"yes":"no"}))),"table");for(const run of response.items)if(run.eligibility.reason)console.log(`${run.runId}: ${run.eligibility.reason}`);console.log(response.note);if(response.nextCursor)console.log(`More: --cursor ${response.nextCursor}`)}});group.command("get <id>").description("One optimization: settings, score, and its trial ladder").action(async(id,_opts,cmd)=>{const org=await resolveOrg(cmd);const detail=await createClient().get(itemPath(org,id));if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});addSubjectOptions(group.command("diagnose").description("Improvement opportunities for an eval or preference prompt from its judged sessions")).action(async(opts,cmd)=>{const org=await resolveOrg(cmd);const diagnosis=await createClient().post(`${basePath(org)}/diagnoses`,parseSubject(opts));if(resolveOutput(cmd)==="json")printJson(diagnosis);else printDiagnosis(diagnosis)});addTargetOption(addSubjectOptions(group.command("start").description("Reuse a selected baseline with --from-run, or establish one with --target"))).option("--from-run <runId>","reuse the eligible baseline containing this run; inherits its model").option("--name <name>","optimization name (default: from the subject)").option("--yes","skip the confirmation").action(async(opts,cmd)=>{const org=await resolveOrg(cmd);if(!!opts.target===!!opts.fromRun)throw new CliError("usage","pass --from-run <runId> or --target <agent[:model]>, not both; discover runs with `gauge optimizations baselines`");const subject=parseSubject(opts);await confirmOrAbort(opts.fromRun?`Start an optimization from the baseline containing ${opts.fromRun}?`:`Start an optimization on ${subjectLabel(subject.subjectKind)} ${subject.subjectId}? A new baseline may spend credits.`,opts.yes);const detail=await createClient().post(basePath(org),{...subject,...targetFromOpts(opts),...opts.fromRun?{fromRun:opts.fromRun}:{},name:opts.name});if(resolveOutput(cmd)==="json")printJson(detail);else{console.log(`Started ${detail.id} "${detail.name}". Each round waits for you to launch it. Follow the baseline with \`gauge optimizations watch ${detail.id}\`.`)}});group.command("cancel <id>").description("Cancel an optimization and stop its in-flight sessions").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{const org=await resolveOrg(cmd);await confirmOrAbort(`Cancel optimization ${id}? In-flight sessions stop; completed usage remains billed.`,opts.yes);const detail=await createClient().post(`${itemPath(org,id)}/cancel`,{});if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`${detail.id}: ${detail.status}${detail.stopReason?` (${detail.stopReason})`:""}`)});addTargetOption(addSubjectOptions(group.command("create").description("Create a draft workspace without running sessions"))).option("--name <name>","optimization name").action(async(opts,cmd)=>{const detail=await createClient().post(`${basePath(await resolveOrg(cmd))}/drafts`,{...parseSubject(opts),...targetFromOpts(opts),name:opts.name});if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});addTargetOption(group.command("edit <id>").description("Edit name/direction, or a draft's target")).option("--name <name>","optimization name").option("--file <path>","PATCH body JSON (name, direction, target); '-' for stdin").action(async(id,opts,cmd)=>{const body={...opts.file?readObject(opts.file):{},...targetFromOpts(opts),...opts.name?{name:opts.name}:{}};if(!Object.keys(body).length)throw new CliError("usage","pass --target, --name, or --file");const detail=await createClient().patch(itemPath(await resolveOrg(cmd),id),body);if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});addTargetOption(group.command("start-draft <id>").description("Start an existing draft's baseline (spends credits)")).option("--name <name>","optimization name").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{const org=await resolveOrg(cmd);const client=createClient();const plan=targetFromOpts(opts);const current=await client.get(itemPath(org,id));if(current.status!=="DRAFT")throw new CliError("usage","only a draft can start; use continue instead");if(!plan.target&&!current.settings.pinnedAgent)throw new CliError("usage","--target is required until the draft has an agent/model");await confirmOrAbort(`Start the baseline for ${id}? It spends credits now.`,opts.yes);const detail=await client.post(`${itemPath(org,id)}/start`,{...plan,name:opts.name});if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});group.command("launch <id>").description("Launch all saved trials in the current round (spends credits)").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{await confirmOrAbort(`Launch the current round of ${id}? Spends credits.`,opts.yes);const result=await createClient().post(`${itemPath(await resolveOrg(cmd),id)}/rounds/current/launch`,{});if(resolveOutput(cmd)==="json")printJson(result);else console.log(result.alreadyLaunched?"Round already launched.":`Launched ${result.launched.length} trials in round ${result.roundNumber}.`)});group.command("continue <id>").description("Reopen a finished optimization for another round against its fixed baseline").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{await confirmOrAbort(`Reopen ${id} for another round? Saved trials still require launch.`,opts.yes);const detail=await createClient().post(`${itemPath(await resolveOrg(cmd),id)}/continue`,{});if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});group.command("activity <id>").description("Read the optimization's decision log").option("--after <timestamp>","entries after this ISO timestamp").option("--limit <n>","maximum entries (1\u2013500)").action(async(id,opts,cmd)=>{const res=await createClient().get(`${itemPath(await resolveOrg(cmd),id)}/activity`,{after:opts.after,limit:parseCount(opts.limit,"--limit",500)});if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(row2=>({at:row2.createdAt,kind:row2.kind,actor:row2.actorName??"Worker",summary:row2.summary})),"table")});group.command("chat <id>").description("Resolve your optimization chat and print its URL path").action(async(id,_opts,cmd)=>{const res=await createClient().post(`${itemPath(await resolveOrg(cmd),id)}/chat`,{});if(resolveOutput(cmd)==="json")printJson(res);else console.log(res.href)});group.command("rm <id>").description("Delete an optimization, retaining billed session history").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{await confirmOrAbort(`Delete optimization ${id}, its rounds, trials, and activity? Session history is kept.`,opts.yes);await createClient().delete(itemPath(await resolveOrg(cmd),id));if(resolveOutput(cmd)==="json")printJson({deleted:id});else console.log(`Deleted ${id}.`)});group.command("complete <id>").description("Complete an optimization: it reads as Finished, not canceled").option("--adopt <trialId>","mark this settled trial as the winner").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{const org=await resolveOrg(cmd);await confirmOrAbort(`Complete optimization ${id}? No further rounds run; unspent credits are released.`,opts.yes);const detail=await createClient().post(`${itemPath(org,id)}/complete`,opts.adopt?{adoptTrialId:opts.adopt}:{});if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`${detail.id}: ${detail.status} (${detail.stopReason})`)});group.command("watch <id>").description(`Follow until finished or awaiting input (exit ${NEEDS_INPUT_EXIT} when it needs you); --follow keeps waiting`).option("--interval <seconds>","poll interval (default 15)").option("--follow","keep polling while awaiting authoring or launch").action(async(id,opts,cmd)=>{const org=await resolveOrg(cmd);const client=createClient();const interval=Number(opts.interval??15);if(!Number.isFinite(interval)||interval<=0)throw new CliError("usage","--interval must be a positive finite number");const intervalMs=Math.max(interval*1e3,2e3);let last="";for(;;){const detail=await client.get(itemPath(org,id));const trials2=detail.rounds.flatMap(round2=>round2.trials);const failed=trials2.reduce((sum,trial)=>sum+trial.failedSessions,0);const line=`${detail.status}${detail.stopReason?` (${detail.stopReason})`:""} \xB7 round ${detail.round} \xB7 ${pct2(detail.before)} \u2192 ${pct2(detail.after)} \xB7 ${detail.creditsSpent} credits spent${failed?` \xB7 ${failed} failed session${failed===1?"":"s"}`:""} \xB7 ${trials2.filter(t=>t.status==="RUNNING").map(t=>t.key).join(",")||"idle"}`;if(line!==last){last=line;console.error(line)}const needsInput=awaitingInput(detail);if(watchStops(detail,!!opts.follow)){if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail);if(needsInput)process.exitCode=NEEDS_INPUT_EXIT;return}await sleep2(intervalMs)}});group.command("authoring <id>").description("What the next round may change: exposed surfaces, CLI targets, baseline run evidence, revision").action(async(id,_opts,cmd)=>{printJson(await createClient().get(`${itemPath(await resolveOrg(cmd),id)}/authoring`))});group.command("cli-change <id>").description("Validate and seal v3 {schemaVersion:3, target, rules, shippingIntent}; use the output as intervention.after in a round file. Saves nothing").requiredOption("--file <path>","the change JSON; '-' for stdin").action(async(id,opts,cmd)=>{printJson(await createClient().post(`${itemPath(await resolveOrg(cmd),id)}/cli-changes`,readObject(opts.file)))});const round=group.command("round").description("Preview and save the round waiting to launch. A round file is {revision, trials: [{trial: {title, hypothesis, lever, intervention}, files?}]}; revision comes from `authoring`");round.command("preview <id>").description("Validate a round file and print its diff and previewDigest").requiredOption("--file <path>","the round JSON; '-' for stdin").action(async(id,opts,cmd)=>{const preview=await createClient().post(`${itemPath(await resolveOrg(cmd),id)}/rounds/current/preview`,readObject(opts.file));if(resolveOutput(cmd)==="json")printJson(preview);else printRoundPreview(preview)});round.command("save <id>").description("Save a previewed round as drafts, replacing every pending draft. Never launches").requiredOption("--file <path>","the round JSON you previewed").requiredOption("--digest <digest>","previewDigest from `round preview`").action(async(id,opts,cmd)=>{const result=await createClient().put(`${itemPath(await resolveOrg(cmd),id)}/rounds/current`,{...readObject(opts.file),previewDigest:opts.digest});if(resolveOutput(cmd)==="json")printJson(result);else for(const trial of result.trials)console.log(`Saved ${trial.key} "${trial.title}"`)});const trials=group.command("trials").description("List, author, and run trials");trials.command("list <id>").description("Every trial of an optimization with score and verdict").action(async(id,_opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(`${itemPath(org,id)}/trials`);if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(trialRow),"table")});trials.command("add <id>").description("Save an authored draft trial; --launch also runs it (spends credits)").option("--file <path>","authored trial JSON, as `trials template` prints it: one {trial, files?} or an array; '-' for stdin").option("--pick <n>","which trial to take from an array (default 1)").option("--title <text>","what the change is").option("--hypothesis <text>","why it should help").option("--lever <lever>","DOCS, MARKETING_SITE, SKILL, SDK, CLI").option("--edit-skill <id>","skill version to rewrite (with --skill-dir); see `gauge optimizations skill-files <id>`").option("--skill-dir <path>","local directory holding the complete edited bundle, SKILL.md included").option("--page <url>","docs page to rewrite (with --body-file)").option("--body-file <path>","the rewritten page body; '-' for stdin").option("--launch","run the trial after saving (spends credits); otherwise save a draft").option("--idempotency-key <key>","a retry with this key returns the first call's trial instead of a second one").option("--yes","skip the confirmation").action(async(id,opts,cmd)=>{const org=await resolveOrg(cmd);const body=trialBodyFromOpts(opts);if(body.launch!==false)await confirmOrAbort(`Run trial "${body.trial.title}" on ${id} now? Spends credits.`,opts.yes);const result=await createClient().post(`${itemPath(org,id)}/trials`,body);if(resolveOutput(cmd)==="json")printJson(result);else if(result.replayed)console.log(`Replayed ${result.trial.key} "${result.trial.title}" (${result.trial.status}) \u2014 this key already authored it`);else console.log(`${result.launch?"Running":"Saved"} ${result.trial.key} "${result.trial.title}"${result.launch?` \u2014 ${result.launch.runIds.length} session${result.launch.runIds.length===1?"":"s"}`:""}`)});trials.command("template").description("Print a trial JSON skeleton for `trials add --file`").requiredOption("--kind <kind>","EDIT_SKILL or REWRITE_DOCS").action(opts=>{printJson(trialTemplate(opts.kind))});trials.command("run <id> <trialId>").description("Run a draft trial now (spends credits)").option("--yes","skip the confirmation").action(async(id,trialId,opts,cmd)=>{const org=await resolveOrg(cmd);await confirmOrAbort(`Run trial ${trialId} now? Spends credits.`,opts.yes);const result=await createClient().post(`${trialPath(org,id,trialId)}/launch`,{});if(resolveOutput(cmd)==="json")printJson(result);else console.log(`Started ${result.runIds.length} session${result.runIds.length===1?"":"s"} for ${trialId}`)});trials.command("rm <id> <trialId>").description("Drop one draft trial from the round waiting to launch").option("--yes","skip the confirmation").action(async(id,trialId,opts,cmd)=>{await confirmOrAbort(`Remove draft ${trialId} from ${id}?`,opts.yes);const detail=await createClient().delete(trialPath(await resolveOrg(cmd),id,trialId));if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`Removed ${trialId}.`)});group.command("trial <id> <trialId>").description("One trial by id or key (B0, R1.1, \u2026) with its sessions").action(async(id,trialId,_opts,cmd)=>{const org=await resolveOrg(cmd);const trial=await createClient().get(trialPath(org,id,trialId));if(resolveOutput(cmd)==="json")printJson(trial);else printTrial(trial)});group.command("change <id> <trialId>").description("The change a trial made: before and after text per document").option("--body","print only the pasteable page body of a docs rewrite").action(async(id,trialId,opts,cmd)=>{const org=await resolveOrg(cmd);const content=await createClient().get(`${trialPath(org,id,trialId)}/content`);if(resolveOutput(cmd)==="json")printJson(content);else if(opts.body){if(content.copyableBody===null)throw new CliError("usage","this trial is not a docs rewrite; drop --body");console.log(content.copyableBody)}else printChange(content)});group.command("adopt <id> <trialId>").description("Mark a settled trial as the winner without changing the baseline").option("--yes","skip the confirmation").action(async(id,trialId,opts,cmd)=>{const org=await resolveOrg(cmd);await confirmOrAbort(`Mark ${trialId} as the winner on ${id}?`,opts.yes);const detail=await createClient().post(`${trialPath(org,id,trialId)}/adopt`,{});if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`Marked ${trialId} as the winner.`)});group.command("handoff <id>").description("The instructions a coding agent follows to land the winning trial in your source, as the web app's Copy instructions for agent").action(async(id,_opts,cmd)=>{const handoff=await createClient().get(`${itemPath(await resolveOrg(cmd),id)}/handoff`);if(resolveOutput(cmd)==="json")printJson(handoff);else process.stdout.write(handoff.prompt)});group.command("skill-files <versionId>").description("The text files of a skill version, the base a skill-edit trial edits").action(async(versionId,_opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(`${basePath(org)}/skill-versions/${encodeURIComponent(versionId)}`);if(resolveOutput(cmd)==="json")printJson(res);else for(const file of res.files){console.log(`=== ${file.path}`);console.log(file.body)}});group.command("page <id>").description("The baseline body of a docs page, the base a docs-rewrite trial edits").requiredOption("--url <url>","the page URL").action(async(id,opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(`${itemPath(org,id)}/page`,{url:opts.url});if(resolveOutput(cmd)==="json")printJson(res);else{if(res.source==="scrape")console.error("Source: fresh scrape; this is not the captured baseline response.");else if(res.source==="none")console.error("No page body is available.");console.log(res.body)}})}var org_exports={};__export(org_exports,{register:()=>register24});function printSettings(s,billingStatus){console.log(`slug: ${s.slug}`);console.log(`name: ${s.name}`);console.log(`website: ${s.website??"(none)"}`);console.log(`max spend/run: ${s.maxSpendUsd==null?"(server default)":`$${s.maxSpendUsd}`}`);console.log(`overage: ${fmtOverage(billingStatus)}`);console.log(`auto-join: ${s.autoJoinDomain??"off"}`)}function register24(program2){const group=hostedOnly(program2.command("org")).description("This org's settings, read-only (see `gauge orgs` for the org list)");group.command("get").description("Show the org's settings (edit them in the web app)").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const client=createClient();const base=`/api/v1/orgs/${encodeURIComponent(org)}`;const[settings,billingStatus]=await Promise.all([client.get(base),client.get(`${base}/billing`)]);if(resolveOutput(cmd)==="json")printJson({...settings,paymentType:billingStatus.paymentType??null,creditLine:billingStatus.creditLine??null});else printSettings(settings,billingStatus)})}var orgs_exports={};__export(orgs_exports,{register:()=>register25});import{writeFileSync as writeFileSync2}from"fs";import{join as join9}from"path";function register25(program2){const orgs=hostedOnly(program2.command("orgs"),{account:true}).description("Organizations, and which Gauge products each one uses");orgs.command("list",{isDefault:true}).description("List your Gauge organizations (* marks the saved default)").action(async(_opts,command)=>{const rows=await fetchDirectory();const{orgId}=readConfig();if(resolveOutput(command)==="json"){printJson(rows.map(row2=>({...row2,isDefault:row2.id===orgId})));return}printItems(rows.map(row2=>({default:row2.id===orgId?"*":"",slug:row2.slug,name:row2.name,products:productsLabel(row2.products)})),"table")});orgs.command("create <name>").description("Create a Gauge Agents workspace and set its organization as the default").option("--website <url>","company site (used as the logo source)").option("--no-use","don't set the new org as the default").action(async(name,opts,command)=>{await fetchDirectory();const created=await createClient().post("/api/v1/orgs",{name,website:opts.website});const org=await createdOrganization(created.slug);if(opts.use!==false)updateConfig({orgId:org.id,defaultOrg:void 0});if(resolveOutput(command)==="json")return printJson(org);console.log(`Created workspace ${org.name} (${org.slug})`);if(opts.use!==false)console.log(`Default org set to ${org.slug}`)});orgs.command("use <org>").description("Select a Gauge organization by its public slug").option("--project","save the selection in this project's gauge.json").action(async(value,opts,command)=>{const org=await findOrganization(value);if(opts.project){const state=gaugeState(command);if(!state.root||!state.config)throw new CliError("usage","No valid gauge.json found. Run `gauge init` first.");const{org:_legacyOrg,...config}=state.config;writeFileSync2(join9(state.root,"gauge.json"),`${JSON.stringify({...config,orgId:org.id},null,2)}
|
|
779
|
+
`)}else updateConfig({orgId:org.id,defaultOrg:void 0});if(resolveOutput(command)==="json")return printJson({orgId:org.id,slug:org.slug,name:org.name});console.log(`${opts.project?"Project":"Default"} org set to ${org.name} (${org.slug})`)})}var personas_exports={};__export(personas_exports,{register:()=>register26});function personasPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/personas`}function register26(program2){const group=hostedOnly(program2.command("personas")).description("Manage simulated-user personas for eval and preference runs");group.command("list").description("List the org's personas").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(personasPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(p=>({id:p.id,name:p.name,description:p.description.length>60?`${p.description.slice(0,57)}...`:p.description})),"table")});group.command("get <id>").description("Show one persona").action(async(id,_opts,cmd)=>{const org=await resolveOrg(cmd);const persona=await createClient().get(`${personasPath(org)}/${encodeURIComponent(id)}`);if(resolveOutput(cmd)==="json"){printJson(persona);return}console.log(`id: ${persona.id}`);console.log(`name: ${persona.name}`);console.log(`model: ${persona.model}`);console.log(`description: ${persona.description}`)});group.command("add").description("Create a persona").requiredOption("--name <name>","persona name").requiredOption("--description <text>",'memory-style notes ("The user is a solo founder\u2026")').action(async(opts,cmd)=>{const org=await resolveOrg(cmd);const created=await createClient().post(personasPath(org),{name:opts.name,description:opts.description});if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created persona ${created.id} (${created.name})`)});group.command("edit <id>").description("Update a persona").option("--name <name>","rename the persona").option("--description <text>","replace the notes").action(async(id,opts,cmd)=>{const org=await resolveOrg(cmd);if(opts.name===void 0&&opts.description===void 0)throw new CliError("usage","nothing to change");const updated=await createClient().patch(`${personasPath(org)}/${encodeURIComponent(id)}`,{name:opts.name,description:opts.description});if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated persona ${updated.id}`)});group.command("rm <id>").description("Delete a persona (run configurations fall back to the default persona)").action(async(id,_opts,cmd)=>{const org=await resolveOrg(cmd);await createClient().delete(`${personasPath(org)}/${encodeURIComponent(id)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted persona ${id}`)})}var preference_exports={};__export(preference_exports,{register:()=>register27});function visibilityPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/visibility-prompts`}function promptPath(org,id){return`${visibilityPath(org)}/${encodeURIComponent(id)}`}function scenariosPath(org,id){return`${promptPath(org,id)}/scenarios`}function scenarioRow(scenario){return{id:scenario.id,repo:scenario.repoUrl??"(empty project)",ref:scenario.repoRef??"",persona:scenario.profile?.name??"(default)"}}var KIND_CHOICES=["head-to-head","open-ended"];function parseKind(raw){const upper=raw==="open-ended"?"RECOMMEND":raw.trim().toUpperCase().replace(/-/g,"_");if(upper!=="HEAD_TO_HEAD"&&upper!=="RECOMMEND")throw new CliError("usage",`invalid --kind "${raw}" (expected: ${KIND_CHOICES.join(" | ")})`);return upper}function brandsLabel(v){if(v.kind==="HEAD_TO_HEAD")return`${v.brandA} vs ${v.brandB}`;return v.branded?v.brandA??"branded":"organic"}function preferencePromptRow(v){return{id:v.id,name:v.name,kind:v.kind==="RECOMMEND"?"open-ended":"head-to-head",brands:brandsLabel(v),market:v.market?.slug??"",tags:v.tags.join(", "),runs:v.runCount,"last run":v.lastRunAt??"-","created by":creatorLabel(v.createdBy)}}function printDetail3(v){console.log(`id: ${v.id}`);console.log(`name: ${v.name}`);console.log(`kind: ${v.kind==="RECOMMEND"?"open-ended":"head-to-head"}`);console.log(`brands: ${brandsLabel(v)}`);console.log(`market: ${v.market?`${v.market.name} (${v.market.slug})`:"(none)"}`);console.log(`tags: ${v.tags.join(", ")||"(none)"}`);console.log(`runs: ${v.runCount} (last: ${v.lastRunAt??"never"})`);console.log(`creator: ${creatorLabel(v.createdBy)}`);console.log(`prompt: ${v.promptText}`);console.log(`cadence: ${cadenceLabel(v.cadence)} \u2014 ${v.sampleCount} sample(s)`);console.log(`agents: ${v.agents.map(a=>a.models.length?`${a.agent}:${a.models.join(",")}`:a.agent).join(", ")}`);console.log(`skills: ${v.skillRefs.join(", ")||"(none)"}`);console.log(`mcp: ${v.mcpRefs.join(", ")||"(none)"}`);console.log(`conns: ${v.connectionIds.join(", ")||"(none)"}`);console.log(`scenarios: ${v.scenarios.length}`);for(const scenario of v.scenarios)console.log(` [${scenario.id}] ${scenario.repoUrl??"(empty project)"}${scenario.repoRef?`@${scenario.repoRef}`:""} \u2014 ${scenario.profile?.name??"default persona"}`)}async function listPreferencePrompts(cmd){if(isLocal(cmd))return listLocalMeasurements(cmd,"preference");const res=await createClient().get(visibilityPath(await resolveOrg(cmd)));return res.items}async function getPreferencePrompt(cmd,id){const vp=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"preference",id)):await createClient().get(promptPath(await resolveOrg(cmd),id));if(resolveOutput(cmd)==="json")printJson(vp);else printDetail3(vp)}async function createPreferencePrompt(cmd,opts){if(opts.kind===void 0)throw new CliError("usage",`--kind is required with --preference (${KIND_CHOICES.join(" | ")})`);if(opts.ref!==void 0&&opts.repo===void 0)throw new CliError("usage","--ref requires --repo");const hasScenario=opts.repo!==void 0||opts.persona!==void 0;const body={name:opts.name,promptText:readPromptText(opts),kind:parseKind(opts.kind),branded:opts.branded,brandA:opts.brandA??null,brandB:opts.brandB??null,marketId:opts.market??null,tags:opts.tag.length>0?opts.tag:void 0,...hasRunSettingsFlags(opts)?runSettingsFromOpts(opts):{},scenarios:hasScenario?[{repoUrl:opts.repo??null,repoRef:opts.ref??null,profileId:opts.persona??null}]:[]};const created=isLocal(cmd)?createLocalMeasurement(cmd,"preference",body):await createClient().post(visibilityPath(await resolveOrg(cmd)),body);if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created preference prompt ${created.id}`)}async function editPreferencePrompt(cmd,id,opts){const body={...runSettingsPatchFromOpts(opts)};if(opts.name!==void 0)body.name=opts.name;if(opts.text!==void 0||opts.file!==void 0)body.promptText=readPromptText(opts);if(opts.brandA!==void 0)body.brandA=opts.brandA;if(opts.brandB!==void 0)body.brandB=opts.brandB;if(opts.branded&&opts.organic)throw new CliError("usage","--branded and --organic conflict");if(opts.branded)body.branded=true;else if(opts.organic)body.branded=false;if(opts.market!==void 0&&opts.clearMarket)throw new CliError("usage","--market and --clear-market conflict");if(opts.clearMarket)body.marketId=null;else if(opts.market!==void 0)body.marketId=opts.market;if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");if(opts.clearTags)body.tags=[];else if(opts.tag.length>0)body.tags=opts.tag;if(Object.keys(body).length===0)throw new CliError("usage","nothing to change");const updated=isLocal(cmd)?editLocalMeasurement(cmd,"preference",id,body):await createClient().patch(promptPath(await resolveOrg(cmd),id),body);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated preference prompt ${updated.id}`)}async function removePreferencePrompt(cmd,id){if(isLocal(cmd))removeLocalMeasurement(cmd,"preference",id);else await createClient().delete(promptPath(await resolveOrg(cmd),id));if(resolveOutput(cmd)!=="json")console.log(`Deleted preference prompt ${id}`)}async function listScenarios(cmd,id){const vp=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"preference",id)):await createClient().get(promptPath(await resolveOrg(cmd),id));if(resolveOutput(cmd)==="json")printJson(vp.scenarios);else printItems(vp.scenarios.map(scenarioRow),"table")}async function addScenario(cmd,id,opts){if(opts.ref!==void 0&&opts.repo===void 0)throw new CliError("usage","--ref requires --repo");if(isLocal(cmd)){if(opts.persona)throw new CliError("usage","Personas require hosted Gauge");const row2=getLocalMeasurement(cmd,"preference",id);const updated=editLocalMeasurement(cmd,"preference",id,{scenarios:[...row2.scenarios,{repoUrl:opts.repo??null,repoRef:opts.ref??null,profileId:null}]});const scenario=updated.scenarios.at(-1);if(resolveOutput(cmd)==="json")printJson(scenario);else console.log(`Added scenario ${scenario.id}`);return}const created=await createClient().post(scenariosPath(await resolveOrg(cmd),id),{repoUrl:opts.repo??null,repoRef:opts.ref??null,profileId:opts.persona??null});if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Added scenario ${created.id}`)}async function removeScenario(cmd,id,scenarioId){if(isLocal(cmd)){const row2=getLocalMeasurement(cmd,"preference",id);const scenarios=row2.scenarios;if(!scenarios.some(s=>s.id===scenarioId))throw new CliError("usage",`Unknown scenario: ${scenarioId}`);editLocalMeasurement(cmd,"preference",id,{scenarios:scenarios.filter(s=>s.id!==scenarioId)});if(resolveOutput(cmd)!=="json")console.log(`Removed scenario ${scenarioId}`);return}await createClient().delete(`${scenariosPath(await resolveOrg(cmd),id)}/${encodeURIComponent(scenarioId)}`);if(resolveOutput(cmd)!=="json")console.log(`Removed scenario ${scenarioId}`)}async function runPreferencePrompt(cmd,id,opts){const org=await resolveOrg(cmd);const overrides=runOverridesFromOpts(opts);const settings=Object.keys(overrides).length>0?"these overrides (stored settings stay unchanged)":"the stored settings";await confirmOrAbort(opts.scenario.length>0?`Run ${opts.scenario.length} selected scenario${opts.scenario.length===1?"":"s"} with ${settings} now?`:`Run every scenario of this prompt with ${settings} now?`,opts.yes);const result=await createClient().post(`${promptPath(org,id)}/run`,{visibilityScenarioIds:opts.scenario.length>0?opts.scenario:void 0,...overrides});if(resolveOutput(cmd)==="json")printJson(result);else{console.log(`Started ${result.runIds.length} run${result.runIds.length===1?"":"s"} across ${result.batchIds.length} scenario${result.batchIds.length===1?"":"s"}`);for(const batch of result.batchIds)console.log(`Runs: gauge run list --batch ${batch}`)}}async function listPreferencePromptRuns(cmd,id,opts){const res=await createClient().get(`${promptPath(await resolveOrg(cmd),id)}/runs`,{limit:opts.limit,cursor:opts.cursor});if(resolveOutput(cmd)==="json"){printJson(res);return}printItems(res.items.map(r=>({id:r.id,status:r.status,agent:r.agent,model:r.resolvedModel??r.model??"",source:r.triggeredBy?.source??"",credits:r.creditsCharged??"",created:r.createdAt,verdict:r.verdict?.status??"-"})),"table");if(res.nextCursor)console.error(`(more results \u2014 rerun with --cursor ${res.nextCursor})`)}async function markets(cmd,opts){if(isLocal(cmd))throw new CliError("usage","Markets require hosted Gauge. Pass --hosted.");const client=createClient();const base=`/api/v1/orgs/${encodeURIComponent(await resolveOrg(cmd))}/markets`;if(opts.add!==void 0){const market=await client.post(base,{marketId:opts.add});if(resolveOutput(cmd)==="json")printJson(market);else console.log(`Tracking market ${market.name} (${market.slug})`);return}const res=await client.get(base);if(resolveOutput(cmd)==="json"){printJson(res);return}printItems([...res.tracked.map(m=>({id:m.marketId,slug:m.slug,name:m.name,tracked:"yes",source:m.source})),...res.addable.map(m=>({id:m.marketId,slug:m.slug,name:m.name,tracked:"no",source:""}))],"table")}function register27(program2){const preference=program2.command("preference").description("Manage preference prompts: which product agents choose. Launch one with `gauge run --preference <id>`");preference.command("list").description("List preference prompts").option("--created-by <email|me>","only prompts created by this user").action(async(opts,cmd)=>{const items=await filterByCreator(await listPreferencePrompts(cmd),opts.createdBy);if(resolveOutput(cmd)==="json")printJson(items);else printItems(items.map(preferencePromptRow),"table")});preference.command("get <id>").description("Show one preference prompt").action(async(id,_opts,cmd)=>{await getPreferencePrompt(cmd,id)});addRunSettingsCreateOptions(preference.command("create").description("Create a preference prompt").requiredOption("--name <name>","name").option("--text <text>","prompt text inline").option("--file <path>",'prompt text from a file ("-" for stdin)').option("--repo <url>","the first scenario's repository (default: empty project)").option("--ref <ref>","branch, tag, or commit (with --repo)").option("--persona <profileId>","persona profile id")).option("--kind <kind>",KIND_CHOICES.join(" | ")).option("--brand-a <name>","first brand (head-to-head)").option("--brand-b <name>","second brand (head-to-head)").option("--branded","an open-ended prompt that names a brand").option("--market <marketId>","tracked market id (see `gauge preference markets`)").option("--tag <name>","user tag name, create-on-type (repeatable)",collect5,[]).action(async(opts,cmd)=>{await createPreferencePrompt(cmd,opts)});addRunSettingsEditOptions(preference.command("edit <id>").description("Update a preference prompt. Omitted flags keep their value.").option("--name <name>","rename it").option("--text <text>","replace the prompt text inline").option("--file <path>",'replace the prompt text from a file ("-" stdin)')).option("--brand-a <name>","first brand").option("--brand-b <name>","second brand").option("--branded","mark branded (open-ended only)").option("--organic","mark organic (open-ended only)").option("--market <marketId>","set the measured market").option("--clear-market","unscope from any market").option("--tag <name>","replace the user tag set (repeatable)",collect5,[]).option("--clear-tags","remove all user tags").action(async(id,opts,cmd)=>{await editPreferencePrompt(cmd,id,opts)});preference.command("rm <id>").description("Delete a preference prompt (run history stays)").action(async(id,_opts,cmd)=>{await removePreferencePrompt(cmd,id)});const scenarios=preference.command("scenarios").description("The repo \xD7 persona scenarios a preference prompt runs in");scenarios.command("list <id>").description("List a preference prompt's scenarios").action(async(id,_opts,cmd)=>{await listScenarios(cmd,id)});scenarios.command("add <id>").description("Add one repo \xD7 persona scenario").option("--repo <url>","repository URL (default: empty project)").option("--ref <ref>","branch, tag, or commit (with --repo)").option("--persona <profileId>","persona profile id (default persona if omitted)").action(async(id,opts,cmd)=>{await addScenario(cmd,id,opts)});scenarios.command("rm <id>").description("Remove one scenario").requiredOption("--scenario <scenarioId>","scenario id to remove").action(async(id,opts,cmd)=>{await removeScenario(cmd,id,opts.scenario)});preference.command("markets").description("List tracked and addable markets for preference prompts, or track one with --add").option("--add <marketId>","track a published market").action(async(opts,cmd)=>{await markets(cmd,opts)})}var repos_exports={};__export(repos_exports,{register:()=>register28});function reposPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/repos`}async function fetchAllRepos(client,org){return fetchAllPages(client,reposPath(org))}function toRow3(repo){return{name:repo.name,url:repo.url,languages:repo.languages.join(", "),frameworks:repo.frameworks.join(", "),tags:repo.tags.join(", "),size:repo.sizeBucket??"",stars:repo.stars,system:repo.isSystem?"yes":""}}function syncWarning(repo){return`warning: GitHub metadata sync failed; retry with \`gauge repos resync ${repo.url}\``}function register28(program2){const repos=hostedOnly(program2.command("repos")).description("Manage repositories");repos.command("list").description("List repositories (yours + read-only Gauge-provided ones)").action(async(_opts,command)=>{const org=await resolveOrg(command);const output=resolveOutput(command);const items=await fetchAllRepos(createClient(),org);if(output==="json"){printJson(items);return}printItems(items.map(toRow3),"table")});repos.command("add <url>").description("Add a repository (pulls languages/size/stars from GitHub)").action(async(url,_opts,command)=>{const org=await resolveOrg(command);const output=resolveOutput(command);const result=await createClient().post(reposPath(org),{url});if(output==="json"){printJson(result);return}console.log(`Added ${result.repo.name} (${result.repo.url})`);if(!result.synced)console.error(syncWarning(result.repo))});repos.command("edit <url>").description("Update a repository's display name, frameworks, or tags").option("--name <name>","display name").option("--framework <name>","REPLACE the framework list (repeatable)",collect5,[]).option("--tag <name>","REPLACE the tag list (repeatable)",collect5,[]).option("--clear-frameworks","remove all frameworks").option("--clear-tags","remove all tags").action(async(url,opts,command)=>{const org=await resolveOrg(command);if(opts.framework.length>0&&opts.clearFrameworks)throw new CliError("usage","--framework and --clear-frameworks conflict");if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");const body={url};if(opts.name!==void 0)body.name=opts.name;if(opts.clearFrameworks)body.frameworks=[];else if(opts.framework.length>0)body.frameworks=opts.framework;if(opts.clearTags)body.tags=[];else if(opts.tag.length>0)body.tags=opts.tag;if(Object.keys(body).length===1)throw new CliError("usage","nothing to change");const repo=await createClient().patch(reposPath(org),body);if(resolveOutput(command)==="json")printJson(repo);else console.log(`Updated ${repo.name} (${repo.url})`)});repos.command("resync <url>").description("Re-fetch a repository's GitHub metadata").action(async(url,_opts,command)=>{const org=await resolveOrg(command);const output=resolveOutput(command);const result=await createClient().post(`${reposPath(org)}/resync`,{url});if(output==="json"){printJson(result);return}if(!result.synced){throw new CliError("internal","GitHub metadata sync failed (is the URL a public GitHub repository?)")}console.log(`Re-synced ${result.repo.name} (${result.repo.url})`)});repos.command("rm <url>").description("Remove a repository from the catalog").action(async(url,_opts,command)=>{const org=await resolveOrg(command);const output=resolveOutput(command);await createClient().delete(reposPath(org),{url});if(output!=="json")console.log(`Removed ${url}`)})}var run_exports={};__export(run_exports,{register:()=>register29});import{readFileSync as readFileSync11,existsSync as existsSync4,mkdirSync as mkdirSync2,writeFileSync as writeFileSync3}from"fs";import{z as z12}from"zod";import{join as join12,relative as relative6}from"path";import{z as z5}from"zod";var preferenceDefinitionSchema=z5.discriminatedUnion("kind",[z5.object({kind:z5.literal("open-ended"),branded:z5.boolean().default(false)}).strict(),z5.object({kind:z5.literal("head-to-head"),brandA:z5.string().trim().min(1),brandB:z5.string().trim().min(1)}).strict().refine(p=>p.brandA.toLowerCase()!==p.brandB.toLowerCase(),"A head-to-head needs two different brands")]);var preferenceSnapshotSchema=z5.object({version:z5.literal(1),preference:preferenceDefinitionSchema}).strict();var headToHeadSchema=z5.object({kind:z5.literal("HEAD_TO_HEAD"),assessability:z5.enum(["assessed","partial","unassessable"]).optional(),selectionStatus:z5.enum(["measured","not_measured","unassessable"]).optional(),winner:z5.enum(["A","B","both","neither"]),brandA:z5.string(),brandB:z5.string(),rationale:z5.string(),brandAReasoning:z5.string(),brandBReasoning:z5.string(),brandAWhyRaised:z5.string().optional(),brandBWhyRaised:z5.string().optional()});var recommendPickSchema=z5.object({brand:z5.string(),rank:z5.number().int(),adopted:z5.boolean(),reasoning:z5.string().optional(),whyRaised:z5.string().optional()});var recommendSchema=z5.object({kind:z5.literal("RECOMMEND"),selectedBrands:z5.array(z5.string()).optional(),assessability:z5.enum(["assessed","partial","unassessable"]).optional(),selectionStatus:z5.enum(["measured","not_measured","unassessable"]).optional(),picks:z5.array(recommendPickSchema).default([]),singlePick:z5.boolean(),complianceNote:z5.string()});var visibilityVerdictSchema=z5.discriminatedUnion("kind",[headToHeadSchema,recommendSchema]);function preferenceSelectionLabel(verdict){if(verdict.assessability==="unassessable"||verdict.selectionStatus==="unassessable")return"Not assessable";if(verdict.kind==="HEAD_TO_HEAD")return verdict.winner==="A"?verdict.brandA:verdict.winner==="B"?verdict.brandB:verdict.winner==="both"?`${verdict.brandA} and ${verdict.brandB}`:"Neither";if(verdict.selectedBrands!==void 0)return verdict.selectedBrands.length?verdict.selectedBrands.join(", "):"No selection";if(!verdict.singlePick)return verdict.picks.length?"No clear selection":"No selection";return verdict.picks.find(pick=>pick.rank===1)?.brand??"No selection"}import{Option as Option4}from"commander";import{readFileSync as readFileSync9}from"fs";import{z as z6}from"zod";function assertRequiredExperiment(spec,required){if(required.length===0){throw new CliError("invalid_request","--require-experiment requires a nonempty label")}const mismatches=[];for(const[promptIndex,prompt]of spec.prompts.entries()){const promptExperiment=prompt.experiment??spec.experiment;const schedules=prompt.schedules??[{}];if(schedules.length===0){mismatches.push(`prompts.${promptIndex}.schedules`)}for(const[scheduleIndex,schedule]of schedules.entries()){if((schedule.experiment??promptExperiment)!==required){mismatches.push(`prompts.${promptIndex}.schedules.${scheduleIndex}`)}}}if(mismatches.length>0){throw new CliError("invalid_request",`--require-experiment expected every target to resolve to ${JSON.stringify(required)}; mismatched: ${mismatches.join(", ")}`)}}var EXAMPLE_SPEC={version:1,expand:true,experiment:"my-experiment",defaults:{agents:["CLAUDE_CODE"],samplesPerCycle:3},prompts:[{key:"add-healthcheck",text:"Add a /health endpoint that returns 200 OK."},{key:"migrate-to-vitest",text:"Migrate the test suite from Jest to Vitest.",schedules:[{repoUrl:"https://github.com/acme/api",repoRef:"main",model:"claude-opus-4-8"}]}]};async function readSpecJson(source){let raw;if(source==="-"){if(process.stdin.isTTY)throw new CliError("usage","--apply - needs a run spec piped to stdin");const chunks2=[];for await(const chunk of process.stdin)chunks2.push(chunk);raw=Buffer.concat(chunks2).toString("utf8")}else{try{raw=readFileSync9(source,"utf8")}catch(e){throw new CliError("usage",`cannot read spec file ${source}: ${e instanceof Error?e.message:String(e)}`)}}try{return JSON.parse(raw)}catch(e){throw new CliError("invalid_request",`spec is not valid JSON: ${e instanceof Error?e.message:String(e)}`)}}function parseSpec(parsed){const result=batteries_exports.batterySpecSchema.safeParse(parsed);if(!result.success){const details=result.error.issues.map(i=>` ${i.path.join(".")||"(spec)"}: ${i.message}`).join("\n");throw new CliError("invalid_request",`not a valid battery spec:
|
|
780
|
+
${details}`,{hint:"Run `gauge run --schema --hosted` for the full schema, or `gauge run --example --hosted` for a starter."})}return result.data}async function resolveApplyOrg(command,spec){return resolveOrg(command,spec.org)}function repoLabel2(repoUrl,repoRef){if(!repoUrl)return"greenfield";return repoRef?`${repoUrl}@${repoRef}`:repoUrl}function printPlan(plan){console.log(`Plan for org ${plan.org}`+(plan.experiment?` (experiment: ${plan.experiment})`:""));for(const prompt of plan.prompts){console.log(` ${prompt.action} prompt "${prompt.key}"`);for(const s of prompt.schedules){console.log(` ${s.action} schedule ${repoLabel2(s.repoUrl,s.repoRef)}`+(plan.expand?` \u2192 ${s.runs} run(s)`:""))}}const sum=plan.summary;console.log(`Prompts: ${sum.promptsToCreate} to create, ${sum.promptsToUpdate} to update; schedules: ${sum.schedulesToCreate} to create, ${sum.schedulesToUpdate} to update`);if(plan.expand){const byAgent=Object.entries(sum.runsByAgent).map(([agent,n])=>`${agent}: ${n}`).join(", ");console.log(`Runs to enqueue: ${sum.runsToEnqueue}${byAgent?` (${byAgent})`:""} \u2014 estimated ${sum.estimatedCredits} credits`)}else{console.log('No runs will be enqueued (config only \u2014 set "expand": true to run).')}console.log("Dry run \u2014 nothing was applied.")}function printApplied(res){console.log(`Applied${res.experiment?` (experiment: ${res.experiment})`:""} \u2014 ${res.batchIds.length} batch(es), ${res.runIds.length} run(s) enqueued`);for(const id of res.runIds)console.log(` run ${id}`);if(res.runIds.length>0){console.error(`(watch one live: gauge run watch ${res.runIds[0]})`)}if(res.blocked){console.error(`warning: some schedules were not expanded (${res.blocked}) \u2014 re-apply after resolving to enqueue the rest`)}}var BATTERY_SCHEMA=()=>z6.toJSONSchema(batteries_exports.batterySpecSchema);async function applySpec(command,spec,opts){if(opts.requireExperiment!==void 0)assertRequiredExperiment(spec,opts.requireExperiment);const org=await resolveApplyOrg(command,spec);const result=await createClient().post(`/api/v1/orgs/${encodeURIComponent(org)}/batteries`,spec,opts.dryRun?{dryRun:1}:void 0);if(resolveOutput(command)==="json")printJson(result);else if(opts.dryRun)printPlan(result);else printApplied(result)}import{createHash as createHash3}from"crypto";import{z as z10}from"zod";import{z as z7}from"zod";var runAddonsSchema=z7.object({browser:z7.object({session:z7.string().min(1),projectId:z7.number().int().positive(),region:z7.literal("us").default("us")}).strict().optional()}).strict();import{z as z9}from"zod";import{z as z8}from"zod";var inputPathSchema=z8.string().min(1).max(256).regex(/^(?![!/])(?!.*[\\\x00-\x1f\x7f])(?!.*(?:^|\/)\.{1,2}(?:\/|$))(?!.*\/\/)(?!.*\/$).+$/,"Expected a repository-relative path or glob without traversal");var reservedBinaryCommands=["bash","sh","zsh","env","node","nodejs","npm","npx","bun","python","python3","git","tar","curl","cp","chmod","mkdir","rm","ln","test","sha256sum","printenv","uname","claude","codex","opencode","pi","wizard"];var binaryCommandSchema=z8.string().max(128).regex(/^[A-Za-z0-9_][A-Za-z0-9_.+-]*$/,"Expected a command name without paths or shell syntax").refine(name=>!reservedBinaryCommands.includes(name),"Command is reserved for Gauge workspace setup or the agent harness; choose another command name");var binaryUseSchema=z8.object({type:z8.literal("binary"),paths:z8.array(inputPathSchema).min(1).max(32),platform:z8.literal("linux-x64").describe("Linux x86-64 ELF executables compatible with the consumer sandbox. No system packages are installed."),commands:z8.record(binaryCommandSchema,inputPathSchema.regex(/^[^*?{}[\]]+$/,"Command targets must be explicit relative file paths")).refine(commands=>Object.keys(commands).length>=1&&Object.keys(commands).length<=32,"Declare between 1 and 32 commands").meta({minProperties:1,maxProperties:32})}).strict();var inputUseSchema=z8.discriminatedUnion("type",[binaryUseSchema,websiteUseSchema,z8.object({type:z8.literal("web-fixture"),path:inputPathSchema.regex(/^[^*?{}[\]]+$/)}).strict(),z8.object({type:z8.literal("files"),paths:z8.array(inputPathSchema).min(1).max(32).optional()}).strict(),z8.object({type:z8.literal("npm-cli"),package:inputPathSchema,install:z8.enum(["environment","workspace"]).optional()}).strict(),z8.object({type:z8.literal("npm-package"),package:inputPathSchema,install:z8.enum(["environment","workspace"]).optional()}).strict(),z8.object({type:z8.literal("skill"),root:z8.union([z8.literal("."),inputPathSchema]).refine(path=>!/[*?{}[\]]/.test(path),"Skill root must be an explicit directory")}).strict()]);var inputSourceSchema=z8.discriminatedUnion("type",[z8.object({type:z8.literal("git"),paths:z8.array(inputPathSchema).min(1).max(32)}).strict(),z8.object({type:z8.literal("github-actions"),artifact:z8.string().min(1).max(256).optional()}).strict()]);var runPlanResourceSchema=z8.object({name:z8.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64),type:z8.literal("input"),source:z8.discriminatedUnion("type",[z8.object({type:z8.literal("upload"),sha256:z8.string().regex(/^sha256:[a-f0-9]{64}$/),bytes:z8.number().int().positive().max(512*1024*1024),repoUrl:z8.string().nullable(),commit:z8.string().regex(/^[a-f0-9]{40}$/i).nullable()}).strict(),commentSourceSchema.extend({repoUrl:z8.string(),commit:z8.string().regex(/^[a-f0-9]{40}$/i)}).strict(),deploymentSourceSchema.extend({repoUrl:z8.string(),commit:z8.string().regex(/^[a-f0-9]{40}$/i)}).strict(),inputSourceSchema.options[0].extend({repoUrl:z8.string(),commit:z8.string().regex(/^[a-f0-9]{40}$/i)}).strict(),inputSourceSchema.options[1].extend({repoUrl:z8.string(),commit:z8.string().regex(/^[a-f0-9]{40}$/i),workflow:inputPathSchema}).strict()]),use:inputUseSchema}).strict().refine(r=>r.use.type==="website"===(r.source.type==="github-deployment"||r.source.type==="github-pr-comment"),"Website inputs require a deployment or PR comment source; file inputs require Git, Actions, or an upload");var definitionInputSourceSchema=z9.discriminatedUnion("type",[z9.object({type:z9.literal("git")}).strict(),z9.object({type:z9.literal("github-actions"),workflow:inputPathSchema.regex(/^\.github\/workflows\/[^/*?{}[\]]+\.ya?ml$/).describe("Workflow file in this repository, for example .github/workflows/build.yml."),artifact:z9.string().min(1).max(256).optional().describe("Upload name or pattern. Omit only when the workflow produces exactly one artifact.")}).strict()]);var skillInputPathSchema=z9.union([z9.literal("."),inputPathSchema.regex(/^[^*?{}[\]]+$/)]).describe("Explicit Skill directory or ZIP/tar.gz file containing SKILL.md at its root.");var runDefinitionInputSchema=z9.discriminatedUnion("type",[binaryUseSchema.extend({source:definitionInputSourceSchema.default({type:"git"})}).strict(),websiteUseSchema.extend({source:websiteSourceSchema}).strict(),z9.object({type:z9.literal("web-fixture"),source:definitionInputSourceSchema.default({type:"git"}),path:inputPathSchema.regex(/^[^*?{}[\]]+$/).describe("Explicit path to a version 1 web fixture JSON file.")}).strict(),z9.object({type:z9.literal("npm-package"),source:definitionInputSourceSchema.default({type:"git"}),path:inputPathSchema.describe("Path or glob selecting exactly one packed npm .tgz file."),install:z9.enum(["environment","workspace"]).default("environment").describe("environment exposes the package's commands on PATH; workspace adds a consumer application dependency.")}).strict(),z9.object({type:z9.literal("skill"),source:definitionInputSourceSchema.default({type:"git"}),path:skillInputPathSchema}).strict(),z9.object({type:z9.literal("files"),source:definitionInputSourceSchema.default({type:"git"}),paths:z9.array(inputPathSchema).min(1).max(32).describe("Files or globs selected from the committed Git tree or the uploaded artifact.")}).strict()]);function isSkillArchive(path){return/\.(?:zip|tar\.gz|tgz)$/i.test(path)}function compileDefinitionInput(name,input,repoUrl,commit){if(input.type==="website")return{name,type:"input",source:{...input.source,repoUrl,commit},use:{type:"website",url:input.url}};const paths=input.type==="files"||input.type==="binary"?input.paths:input.type==="skill"&&!isSkillArchive(input.path)?[input.path==="."?"**":`${input.path}/**`]:[input.path];return{name,type:"input",source:input.source.type==="git"?{type:"git",paths,repoUrl,commit}:{...input.source,repoUrl,commit},use:input.type==="binary"?{type:"binary",paths:input.paths,platform:input.platform,commands:input.commands}:input.type==="npm-package"?{type:"npm-package",package:input.path,install:input.install}:input.type==="web-fixture"?{type:"web-fixture",path:input.path}:input.type==="skill"?{type:"skill",root:input.path}:{type:"files",paths:input.paths}}}var inputUploadSpecSchema=z10.object({sha256:z10.string().regex(/^sha256:[a-f0-9]{64}$/),bytes:z10.number().int().positive().max(512*1024*1024)}).strict();var uncredentialedRepoUrlSchema=z10.string().min(1).refine(raw=>{if(!/^[a-z][a-z0-9+.-]*:\/\//i.test(raw))return true;try{const url=new URL(raw);return(url.protocol==="ssh:"||!url.username)&&!url.password&&!url.search&&!url.hash}catch{return false}},"Repository URL must not contain embedded credentials or query parameters");var runDefinitionChecksSchema=z10.object({paths:z10.array(inputPathSchema).min(1).max(32)}).strict();var runDefinitionConfigSchema=z10.object({agents:z10.array(agentConfigInputSchema).min(1),sampleCount:z10.number().int().min(1).max(50).optional(),repoUrl:uncredentialedRepoUrlSchema.nullable().optional(),repoRef:z10.string().min(1).nullable().optional(),profileId:z10.string().min(1).nullable().optional(),skillRefs:assetRefListSchema.optional(),mcpRefs:assetRefListSchema.optional(),connectionIds:z10.array(z10.string().min(1)).max(32).optional(),addons:runAddonsSchema.optional(),inputs:z10.array(z10.string()).optional(),checks:runDefinitionChecksSchema.optional()}).strict();var runDefinitionFileConfigSchema=z10.object({version:z10.literal(2).default(2),org:z10.string().min(1).optional(),orgId:z10.string().uuid().optional(),checks:runDefinitionChecksSchema.optional(),cases:z10.array(inputPathSchema).min(1).max(32).default(["gauge-cases/**/*.md"]),inputs:z10.record(z10.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64),runDefinitionInputSchema).refine(inputs=>Object.keys(inputs).length<=32,"At most 32 inputs are allowed").meta({maxProperties:32}).default({})}).strict();var runDefinitionCriterionSchema=z10.object({name:z10.string().min(1),rubric:z10.string().min(1)}).strict();var caseMeasurement={criteria:z10.array(runDefinitionCriterionSchema).min(1).optional(),preference:preferenceDefinitionSchema.optional()};function exactlyOneMeasurement(item){return item.criteria!==void 0!==(item.preference!==void 0)}var runDefinitionFrontmatterSchema=z10.object({...caseMeasurement,config:runDefinitionConfigSchema}).strict().refine(exactlyOneMeasurement,"Specify exactly one of criteria or preference");var runDefinitionCaseSchema=z10.object({path:z10.string().min(1),prompt:z10.string().min(1),...caseMeasurement,config:runDefinitionConfigSchema}).strict().refine(exactlyOneMeasurement,"Specify exactly one of criteria or preference");var runDefinitionSubmissionSchema=z10.object({version:z10.literal(2),source:z10.object({repoUrl:uncredentialedRepoUrlSchema.nullable(),commit:z10.string().regex(/^[a-f0-9]{40}$/i).nullable(),digest:z10.string().regex(/^sha256:[a-f0-9]{64}$/),verification:z10.enum(["SUBMITTED_UNVERIFIED","GITHUB_VERIFIED","LOCAL"])}).strict(),resources:z10.array(runPlanResourceSchema).max(32).default([]),cases:z10.array(runDefinitionCaseSchema).min(1).max(20)}).strict().superRefine((definition,ctx)=>{if(definition.source.verification!=="LOCAL"&&(!definition.source.repoUrl||!definition.source.commit))ctx.addIssue({code:"custom",path:["source"],message:"Committed definitions require a repository and commit"});if(definition.source.verification==="GITHUB_VERIFIED"&&definition.resources.some(r=>r.source.type==="upload"))ctx.addIssue({code:"custom",path:["resources"],message:"GitHub definitions cannot contain uploaded inputs"});const paths=new Set;for(const[index,item]of definition.cases.entries()){if(paths.has(item.path))ctx.addIssue({code:"custom",path:["cases",index,"path"],message:"Case paths must be unique"});paths.add(item.path)}const names=definition.resources.map(resource=>resource.name);if(new Set(names).size!==names.length)ctx.addIssue({code:"custom",path:["resources"],message:"Input names must be unique"});for(const[index,item]of definition.cases.entries())for(const name of item.config.inputs??names)if(!names.includes(name))ctx.addIssue({code:"custom",path:["cases",index,"config","inputs"],message:`Unknown input: ${name}`});for(const[index,resource]of definition.resources.entries()){if(resource.source.repoUrl!==definition.source.repoUrl||resource.source.commit!==definition.source.commit)ctx.addIssue({code:"custom",path:["resources",index,"source"],message:"Project preparation must use the definition repository and commit"})}});var runDefinitionPublicSubmissionSchema=runDefinitionSubmissionSchema.refine(definition=>definition.source.verification!=="GITHUB_VERIFIED",{path:["source","verification"],message:"Only the GitHub App may verify committed bytes"});var runDefinitionPlanResponseSchema=z10.object({source:runDefinitionSubmissionSchema.shape.source,measurementMode:z10.enum(["AGENT_EXPERIENCE","AGENT_PREFERENCE","MIXED"]),cases:z10.array(z10.object({path:z10.string(),agents:z10.array(agentConfigSchema),samples:z10.number().int().nonnegative(),expectedRuns:z10.number().int().nonnegative(),workspace:z10.object({repoUrl:z10.string().nullable(),repoRef:z10.string().nullable()}),criteriaCount:z10.number().int().nonnegative(),preference:preferenceDefinitionSchema.optional(),inputs:z10.array(z10.string())})),resources:z10.array(z10.object({name:z10.string(),type:z10.literal("input"),source:z10.enum(["git","github-actions","github-deployment","github-pr-comment","upload"]),use:inputUseSchema,readiness:z10.enum(["READY","WAITING","FAILED"]),detail:z10.string().optional(),commands:z10.array(z10.string()).optional()})),expectedRuns:z10.number().int().nonnegative(),canRun:z10.boolean()});var runDefinitionRunResponseSchema=z10.object({runRequestId:z10.string(),batchIds:z10.array(z10.string()),runIds:z10.array(z10.string()),requestedRuns:z10.number().int().nonnegative(),createdRuns:z10.number().int().nonnegative(),aggregateUrl:z10.string()});import{z as z11}from"zod";var caseSpecSchema=z11.object({version:z11.literal(2),cases:z11.array(z11.object({key:z11.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64).describe("Unique case id, lowercase-kebab"),prompt:z11.string().trim().min(1).describe("The user's request"),criteria:z11.array(runDefinitionCriterionSchema).min(1).optional().describe("Optional for local runs; hosted needs criteria or preference"),preference:preferenceDefinitionSchema.optional(),config:runDefinitionConfigSchema}).strict().refine(item=>!(item.criteria&&item.preference),"Specify criteria or preference, not both")).min(1).max(20)}).strict().refine(spec=>new Set(spec.cases.map(item=>item.key)).size===spec.cases.length,"Case keys must be unique");var EXAMPLE_CASE_SPEC={version:2,cases:[{key:"release-notes",prompt:"Write the release notes for version 1.2.0. We added dark mode and fixed a login crash.",criteria:[{name:"Team format",rubric:"RELEASE-NOTES.md lists both changes in the team's format."}],config:{agents:[{agent:"CODEX_CLI"}],inputs:["release-notes"]}}]};var CASE_SPEC_SCHEMA=()=>z11.toJSONSchema(caseSpecSchema);function isCaseSpec(value){return value!==null&&typeof value==="object"&&"cases"in value&&!("prompts"in value)}function parseCaseSpec(value){const result=caseSpecSchema.safeParse(value);if(!result.success)throw new CliError("usage",`not a valid case spec:
|
|
781
|
+
${result.error.issues.map(i=>` ${i.path.join(".")||"(spec)"}: ${i.message}`).join("\n")}`,{hint:"Run `gauge run --schema --local` for the full schema, or `gauge run --example --local` for a starter."});return result.data}function caseSpecCases(spec){return spec.cases.map(({key,...item})=>({path:key,...item}))}function caseSpecDigest(spec){return`sha256:${createHash3("sha256").update("gauge-case-spec-v2\0").update(JSON.stringify(spec)).digest("hex")}`}import{execFileSync as execFileSync2}from"child_process";import{createHash as createHash5}from"crypto";import{createReadStream as createReadStream2,globSync as globSync2}from"fs";import{lstat,mkdtemp,readdir,rm,stat}from"fs/promises";import{tmpdir}from"os";import{basename,dirname,isAbsolute as isAbsolute4,join as join11,relative as relative5,resolve as resolve4,sep as sep3}from"path";import{setTimeout as delay2}from"timers/promises";import{createHash as createHash4}from"crypto";import{parseDocument}from"yaml";function utf8(bytes,path){try{return new TextDecoder("utf-8",{fatal:true}).decode(bytes)}catch{throw new Error(`${path} is not UTF-8 text`)}}function parseRunDefinitionCase(path,bytes){const source=utf8(bytes,path);const match=/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/.exec(source);if(!match)throw new Error(`${path}: expected YAML frontmatter between --- lines`);const document=parseDocument(match[1],{uniqueKeys:true});if(document.errors.length)throw new Error(`${path}: ${document.errors.map(error=>error.message).join("; ")}`);const parsed=runDefinitionFrontmatterSchema.safeParse(document.toJS());if(!parsed.success)throw new Error(`${path}: ${parsed.error.message}`);const prompt=match[2].trim();if(!prompt)throw new Error(`${path}: Markdown body is empty`);return{path,prompt,...parsed.data}}function compileRunDefinitionFromBlobs(input){if(input.repoUrl!==null&&!uncredentialedRepoUrlSchema.safeParse(input.repoUrl).success)throw new Error("Git origin must not contain embedded credentials");if(input.commit!==null&&!/^[a-f0-9]{40}$/i.test(input.commit))throw new Error("Expected a full Git commit SHA");if(input.casePaths.length===0)throw new Error("At least one Markdown case is required");if(new Set(input.casePaths).size!==input.casePaths.length)throw new Error("Case paths must be unique");const configBytes=input.blobs.get("gauge.json");let config;if(configBytes){try{config=runDefinitionFileConfigSchema.parse(JSON.parse(utf8(configBytes,"gauge.json")))}catch(error){throw new Error(`gauge.json: ${error instanceof Error?error.message:error}`)}}const cases=input.casePaths.map(path=>{const bytes=input.blobs.get(path);if(!path.endsWith(".md")||!bytes)throw new Error(`Missing Markdown case: ${path}`);return parseRunDefinitionCase(path,bytes)});const hash=createHash4("sha256");hash.update("gauge-run-definition-v2\0");for(const[path,bytes]of[...input.blobs.entries()].sort(([a],[b])=>a<b?-1:a>b?1:0)){hash.update(path);hash.update("\0");hash.update(String(bytes.length));hash.update("\0");hash.update(bytes);hash.update("\0")}const submission=runDefinitionSubmissionSchema.parse({version:2,source:{repoUrl:input.repoUrl,commit:input.commit,digest:`sha256:${hash.digest("hex")}`,verification:input.verification},resources:input.resources??Object.entries(config?.inputs??{}).map(([name,item])=>{if(!input.repoUrl||!input.commit)throw new Error(`Supply --input ${name}=<path> outside a Git checkout with an origin`);return compileDefinitionInput(name,item,input.repoUrl,input.commit)}),cases});return{definition:submission,org:config?.orgId??config?.org}}import{minimatch}from"minimatch";function matchInputPaths(paths,patterns,options={}){for(const pattern of patterns)inputPathSchema.parse(pattern);const selections=patterns.map(pattern=>({pattern,matches:paths.filter(path=>minimatch(path,pattern,{dot:true,nocase:false,nonegate:true}))}));if(options.allowEmptySelection&&selections.every(({matches:matches2})=>matches2.length===0))return[];const selected=new Set;for(const{pattern,matches:matches2}of selections){if(!matches2.length)throw new Error(`No committed files match ${pattern}`);for(const path of matches2)selected.add(path)}return[...selected].sort()}import{create as tar}from"tar";import{execFileSync}from"child_process";import{globSync,lstatSync,readdirSync as readdirSync2,readFileSync as readFileSync10,realpathSync as realpathSync3}from"fs";import{isAbsolute as isAbsolute3,join as join10,relative as relative4,resolve as resolve3,sep as sep2}from"path";import{minimatch as minimatch2}from"minimatch";import{parseDocument as parseDocument2}from"yaml";import{CommanderError}from"commander";import{ZodError}from"zod";function errorReport(error,command,context={}){const base=error instanceof CliError&&error.needsAccount&&context.local?localModeError(command,context.local,error.hint):describe(error);const quiet=base.message==="aborted"||command==="feedback";const isChat=command==="chat"||command.startsWith("chat ");const docs=base.docs??(isChat?void 0:DOCS_URL);return{...base,...docs?{docs}:{},...quiet?{}:{feedback:`gauge feedback -m "<what happened>" --kind friction${command?` --command "${command}"`:""}`}}}function localModeError(command,source,hint){return{code:"usage",message:`\`gauge ${command}\` requires hosted Gauge, but ${source==="flag"?"you passed --local":source==="workspace"?"this project is set to run locally":source==="user"?"your saved setting is local":"the CLI is using local mode"}.`,hint:hint??"Pass --hosted for this command, or run `gauge init --hosted` to use hosted Gauge in this project. Sign in with `gauge auth login` if needed.",exitCode:exitCodeFor("usage")}}function describe(error){if(error instanceof CliError)return{code:error.apiCode??error.code,message:readable(error.message),...error.details?{details:error.details}:{},hint:error.hint,docs:error.docs,exitCode:error.exitCode};if(error instanceof CommanderError)return{code:"usage",message:error.message.replace(/^error: /,""),hint:"Run the command with --help for its usage.",exitCode:exitCodeFor("usage")};if(error instanceof ZodError)return{code:"usage",message:issueLines("Invalid input",error.issues),exitCode:exitCodeFor("usage")};const node=error;if(node?.code==="ENOENT"&&node.path)return{code:"usage",message:`File not found: ${node.path}`,exitCode:exitCodeFor("usage")};if(node?.code==="EACCES"&&node.path)return{code:"usage",message:`Permission denied: ${node.path}`,exitCode:exitCodeFor("usage")};return{code:"internal",message:`Unexpected error: ${error instanceof Error?readable(error.message):String(error)}`,hint:process.env.GAUGE_DEBUG?void 0:"Set GAUGE_DEBUG=1 to print the stack trace.",exitCode:1}}function readable(message2){const start=message2.search(/\[\s*\{/);if(start<0)return message2;try{const issues=JSON.parse(message2.slice(start));if(!Array.isArray(issues)||!issues.every(issue=>typeof issue?.message==="string"))return message2;return issueLines(message2.slice(0,start).replace(/[:\s]+$/,""),issues)}catch{return message2}}function issueLines(prefix,issues){return[prefix,...issues.map(issue=>` ${issue.path?.length?`${issue.path.map(String).join(".")}: `:""}${issue.message}`)].filter(Boolean).join("\n")}function renderError(report,json){if(json)return`${JSON.stringify({error:report},null,2)}
|
|
782
|
+
`;const red=style("31",process.stderr);const dim=style("2",process.stderr);return`${[`${red("error:")} ${report.message}`,...report.hint?[report.hint]:[],...report.docs?[dim(`Docs: ${report.docs}`)]:[],...report.feedback?[dim(`Hit friction? ${report.feedback}`)]:[]].join("\n")}
|
|
783
|
+
`}function commandPath(program2,argv){const names=[];let command=program2;for(const token of argv){if(token.startsWith("-"))continue;const next=command.commands.find(sub=>sub.name()===token||sub.aliases().includes(token));if(next){names.push(token);command=next}else if(command.commands.length===0)break}return names.join(" ")}function wantsJson(argv){return argv.some((token,i)=>token==="--output=json"||token==="-ojson"||(token==="-o"||token==="--output")&&argv[i+1]==="json")}var record=value=>value!==null&&typeof value==="object"&&!Array.isArray(value)?value:{};var message=error=>oneLine(error instanceof CliError&&error.hint?`${error.message} ${error.hint}`:error instanceof Error?error.message:String(error));var oneLine=text=>readable(text).trim().replace(/\n\s*/g,"; ");var check=(id,state,detail)=>({id,state,detail});var dynamic=value=>typeof value!=="string"||value.includes("${{");var condition=value=>{if(value===void 0||value===true)return true;if(value===false)return false;if(typeof value==="string"){const compact2=value.replace(/\s/g,"");if(compact2==="true"||compact2===`\${{true}}`)return true;if(compact2==="false"||compact2===`\${{false}}`)return false}return void 0};function git(cwd,args){return execFileSync("git",args,{cwd,encoding:"utf8",stdio:["ignore","pipe","pipe"],maxBuffer:16*1024*1024})}function rootDirectory(cwd){return findWorkspace(cwd)??resolve3(cwd)}function regularFile(root,path){const full=join10(root,path);try{const rel=relative4(realpathSync3(root),realpathSync3(full));return rel!==".."&&!rel.startsWith(`..${sep2}`)&&!isAbsolute3(rel)&&lstatSync(full).isFile()}catch{return false}}function read(root,path){if(!regularFile(root,path))throw new Error(`${path}: missing regular file inside the working tree`);if(lstatSync(join10(root,path)).size>1024*1024)throw new Error(`${path}: exceeds the 1 MiB static inspection limit`);return readFileSync10(join10(root,path))}function ignoredByGit(root){try{git(root,["check-ignore","-q","."]);return true}catch{return false}}function workingFiles(root){let paths;try{if(ignoredByGit(root))throw new Error("workspace is ignored by Git");paths=git(root,["ls-files","--cached","--others","--exclude-standard","-z"]).split("\0").filter(Boolean)}catch{paths=[];const walk=directory=>{for(const entry of readdirSync2(join10(root,directory),{withFileTypes:true})){if([".git",".gauge","node_modules",".next",".venv","venv"].includes(entry.name))continue;const path=directory?`${directory}/${entry.name}`:entry.name;if(entry.isDirectory())walk(path);else if(entry.isFile())paths.push(path);if(paths.length>5e4)throw new Error("Working tree exceeds 50,000 files; initialize Git and ignore generated files before verifying")}};walk("")}return[...new Set(paths)].filter(path=>regularFile(root,path)).sort()}var skippedInputEntry=name=>[".git",".gauge","node_modules",".aws",".ssh",".npmrc",".pypirc"].includes(name)||name===".env"||name.startsWith(".env.");function diskFiles(root,base){const paths=[];const walk=directory=>{for(const entry of readdirSync2(join10(root,directory),{withFileTypes:true})){if(skippedInputEntry(entry.name))continue;const path=directory?`${directory}/${entry.name}`:entry.name;if(entry.isDirectory())walk(path);else if(entry.isFile())paths.push(path);if(paths.length>2e4)throw new Error("Input exceeds 20,000 files")}};walk(base==="."?"":base);return paths.sort()}function workflowChecks(root,input){if(input.source.type!=="github-actions")return[];const source=input.source;const checks=[];let workflow;try{const document=parseDocument2(read(root,source.workflow).toString("utf8"),{uniqueKeys:true});if(document.errors.length)throw new Error(document.errors.map(message).join("; "));workflow=record(document.toJS());if(!Object.keys(record(workflow.jobs)).length)throw new Error("Expected a workflow jobs mapping");checks.push(check("workflow","yes",`${source.workflow} exists with a parseable YAML jobs mapping`))}catch(error){return[check("workflow","no",message(error))]}const jobs=Object.entries(record(workflow.jobs)).map(([name,value])=>({name,job:record(value)})).filter(({job})=>condition(job.if)!==false);const steps=jobs.flatMap(({name,job})=>Array.isArray(job.steps)?job.steps.map(value=>({job:name,jobCondition:condition(job.if),step:record(value)})).filter(({step})=>condition(step.if)!==false):[]);const opaque=jobs.some(({job})=>typeof job.uses==="string")||steps.some(({step})=>typeof step.uses==="string"&&!/^actions\/(checkout|upload-artifact|setup-[^@]+)@/.test(step.uses));const uploads=steps.filter(({step})=>typeof step.uses==="string"&&step.uses.startsWith("actions/upload-artifact@"));const candidates=uploads.filter(({step})=>{const name=record(step.with).name??"artifact";return!source.artifact||dynamic(name)||minimatch2(String(name),source.artifact,{nonegate:true})});const recognizedUpload=candidates.length===1&&!dynamic(record(candidates[0].step.with).name??"artifact");checks.push(check("artifact-upload",recognizedUpload?"yes":"unknown",recognizedUpload?`One direct upload step declares the matching artifact ${String(record(candidates[0].step.with).name??"artifact")}`:candidates.length?`Found ${candidates.length} potentially matching upload step(s); resolve dynamic artifact names or overlapping uploads to establish a unique selection`:`No direct upload step matches ${source.artifact??"the configured artifact"}; ${opaque?"inspect the referenced reusable workflows or custom actions":"inspect build scripts or declare a matching actions/upload-artifact step"}`));for(const[index,{job,jobCondition,step}]of candidates.entries()){const options=record(step.with);const version=/^actions\/upload-artifact@v(\d+)(?:\.\d+){0,2}$/.exec(String(step.uses));const major=version?Number(version[1]):void 0;let state=source.artifact&&dynamic(options.name??"artifact")?"unknown":major===7?options.archive===true||options.archive==="true"?"yes":options.archive===void 0||options.archive===false||options.archive==="false"?"no":"unknown":major!==void 0&&major>=4&&major<=6?"yes":"unknown";const conditional=jobCondition===void 0||condition(step.if)===void 0;if(state==="no"&&conditional)state="unknown";const detail=source.artifact&&dynamic(options.name??"artifact")?"Resolve the artifact name expression to determine whether this upload is selected":major===7?options.archive===true||options.archive==="true"?"archive: true declares a ZIP artifact":options.archive===void 0||options.archive===false||options.archive==="false"?`archive: true is required for Gauge's ZIP download${conditional?"; resolve the upload condition to determine whether this incompatible upload is selected":""}`:"Resolve the archive expression; Gauge requires archive: true":major!==void 0&&major>=4&&major<=6?"This action version produces ZIP artifacts":"Resolve the pinned action version; ZIP format is recognized for upload-artifact v4\u2013v7 (v7 requires archive: true)";checks.push(check(`artifact-format.${index}`,state,`${job}: ${String(step.uses)}; ${detail}`))}const checkouts=steps.filter(({step})=>typeof step.uses==="string"&&step.uses.startsWith("actions/checkout@"));const events=typeof workflow.on==="string"?[workflow.on]:Array.isArray(workflow.on)?workflow.on:Object.keys(record(workflow.on));const pr=events.includes("pull_request");const recognizedCheckout=step=>{const options=record(step.with);if(options.repository!==void 0)return false;if(!events.length||options.ref!==void 0&&typeof options.ref!=="string")return false;const ref=typeof options.ref==="string"?options.ref.replace(/\s/g,""):"";return events.every(event=>["pull_request","push","workflow_dispatch"].includes(event))&&(!ref||ref===`\${{github.sha}}`)||ref===`\${{github.event.pull_request.head.sha||github.sha}}`||pr&&events.every(event=>event==="pull_request")&&ref===`\${{github.event.pull_request.head.sha}}`};const checkoutState=checkouts.length>0&&checkouts.every(({step})=>recognizedCheckout(step))?"yes":"unknown";checks.push(check("candidate-checkout",checkoutState,checkoutState==="yes"?"Workflow checkout recognized, including the default PR merge checkout":"Could not inspect checkout settings; check that your workflow builds the intended code"));const filtered=Object.values(record(workflow.on)).some(value=>["paths","paths-ignore","branches","branches-ignore","types"].some(key=>record(value)[key]!==void 0));const eligible=events.filter(event=>["pull_request","push","workflow_dispatch"].includes(String(event)));const knownEvents=events.length>0&&events.every(event=>!dynamic(event));checks.push(check("workflow-trigger",eligible.length?"yes":knownEvents?"no":"unknown",eligible.length?`Eligible trigger(s) declared: ${eligible.join(", ")}${filtered?"; event filters are present":""}`:knownEvents?`Declared event(s) ${events.join(", ")} are not eligible artifact sources; declare push, pull_request, or workflow_dispatch`:"Could not read workflow events; declare push, pull_request, or workflow_dispatch"));return checks}function inputChecks(root,files,input,local){const checks=[check("configuration","yes",`Supported ${input.type} input from ${input.source.type==="git"?"project files":input.source.type}`)];if(input.type==="website")return checks;if(input.type==="binary"){const excluded=Object.entries(input.commands).filter(([,target])=>!input.paths.some(pattern=>minimatch2(target,pattern,{dot:true,nocase:false,nonegate:true})));checks.push(check("command-selection",excluded.length?"no":"yes",excluded.length?`Declared command targets are excluded by paths: ${excluded.map(([name,target])=>`${name}: ${target}`).join(", ")}`:"Declared command targets match selected paths"))}if(input.source.type==="github-actions"&&!local)checks.push(...workflowChecks(root,input));else{try{const patterns=input.type==="files"||input.type==="binary"?input.paths:input.type==="skill"&&!isSkillArchive(input.path)?[input.path==="."?"**":`${input.path}/**`]:[input.path];const selected=local&&input.type==="npm-package"?globSync(input.path,{cwd:root}):matchInputPaths(local?diskFiles(root,input.type==="skill"&&!isSkillArchive(input.path)?input.path:""):files,patterns);if(input.type==="binary"){for(const[command,target]of Object.entries(input.commands)){if(!selected.includes(target))throw new Error(`Binary command ${command} target is missing or excluded by paths: ${target}`)}}if(input.type==="web-fixture")parseWebFixtureInput(read(root,input.path).toString("utf8"));if(input.type==="npm-package"&&(selected.length!==1||!selected[0].endsWith(".tgz")))throw new Error("npm-package must select exactly one .tgz file");if(input.type==="skill"&&!isSkillArchive(input.path)&&!selected.includes(input.path==="."?"SKILL.md":`${input.path}/SKILL.md`))throw new Error("Skill directory must contain SKILL.md at its root");checks.push(check("local-paths","yes",`${selected.length} ${local?"local":"working-tree"} file(s) selected`))}catch(error){checks.push(check("local-paths","no",message(error).replace("committed files",local?"local files":"working-tree files")))}}return checks}function verifyEvals(cwd=process.cwd(),{local=false}={}){const root=rootDirectory(cwd);const result={version:1,mode:"local-static",root,status:"passed",summary:{yes:0,no:0,unknown:0},facts:{configFilePresent:null,caseCount:null},info:[],notChecked:["github-app-activation","account-settings","mcp-server-access","mcp-server-reachability","live-input-delivery","artifact-contents","sandbox-installation","workflow-execution"],global:[],inputs:[]};const finish=()=>{for(const item of[...result.global,...result.inputs.flatMap(input=>input.checks)])result.summary[item.state]++;result.status=result.summary.no>0?"failed":result.summary.unknown>0?"incomplete":"passed";return result};let raw={};let files;try{files=workingFiles(root)}catch(error){result.global.push(check("working-tree","no",message(error)));return finish()}try{result.facts.configFilePresent=files.includes("gauge.json")||regularFile(root,"gauge.json");if(result.facts.configFilePresent)raw=JSON.parse(read(root,"gauge.json").toString("utf8"));else result.info.push({id:"config-file-absent",detail:"Optional gauge.json is absent; using default case discovery and no inputs"})}catch(error){result.global.push(check("configuration","no",message(error)));return finish()}const config=runDefinitionFileConfigSchema.safeParse(raw);result.global.push(check("configuration",config.success?"yes":"no",config.success?"Configuration matches the supported gauge.json schema":oneLine(config.error.message)));const rawInputs=record(record(raw).inputs);for(const[name,value]of Object.entries(rawInputs).sort(([a],[b])=>a.localeCompare(b))){const parsed=runDefinitionInputSchema.safeParse(value);result.inputs.push({name,checks:parsed.success?inputChecks(root,files,parsed.data,local):[check("configuration","no",oneLine(parsed.error.message))]})}if(config.success){try{const paths=matchInputPaths(files,config.data.cases,{allowEmptySelection:true});if(paths.length>20||paths.some(path=>!path.endsWith(".md")))throw new Error("Expected at most 20 Markdown cases");result.facts.caseCount=paths.length;if(paths.length)result.global.push(check("case-discovery","yes",`${paths.length} working-tree case(s) selected`));else result.info.push({id:"no-cases",detail:"No eval cases found; input-only setup is valid, but no evaluations will run"});for(const path of paths){try{const item=parseRunDefinitionCase(path,read(root,path));if(local)assertLocalCapabilities(item.config,`${path}: config.`);const missing=(item.config.inputs??[]).filter(name=>!Object.hasOwn(config.data.inputs,name));if(missing.length)throw new Error(`${path}: Unknown input(s): ${missing.join(", ")}`);const commandOwners=new Map;mergeWebFixtures((item.config.inputs??Object.keys(config.data.inputs)).flatMap(name=>{const input=config.data.inputs[name];return input.type==="web-fixture"&&(local||input.source.type==="git")?[parseWebFixtureInput(read(root,input.path).toString("utf8"))]:[]}));for(const name of new Set(item.config.inputs??Object.keys(config.data.inputs))){const input=config.data.inputs[name];if(input.type!=="binary")continue;for(const command of Object.keys(input.commands)){const owner=commandOwners.get(command);if(owner)throw new Error(`${path}: Inputs ${owner} and ${name} both expose command ${command}; choose distinct commands or separate cases`);commandOwners.set(command,name)}}result.global.push(check(`case.${path}`,"yes","Case syntax, input references, and declared command names are valid"))}catch(error){result.global.push(check(`case.${path}`,"no",message(error)))}}}catch(error){result.global.push(check("case-discovery","no",message(error).replace("committed files","working-tree files")))}}else result.info.push({id:"case-validation-skipped",detail:"Fix gauge.json before validating cases and input references"});return finish()}function printEvalVerification(result){console.log(`Local static verification: ${result.root}`);const print2=checks=>{for(const item of checks)console.log(` [${item.state}] ${item.id}: ${item.detail}`)};console.log("Global");print2(result.global);for(const input of result.inputs){console.log(`Input: ${input.name}`);print2(input.checks)}for(const item of result.info)console.log(`[info] ${item.id}: ${item.detail}`);console.log(`Static verification ${result.status}: ${result.summary.yes} yes, ${result.summary.no} no, ${result.summary.unknown} unknown.`);console.log("Scope: repository setup only. Live delivery, account settings, and sandbox execution were not tested; no sessions were launched.")}var LIMIT=512*1024*1024;var SNAPSHOT_FILES=100;function parseInputBindings(values){const bindings=new Map;for(const value of values){const split=value.indexOf("=");const name=split<0?value:value.slice(0,split);const path=split<0?void 0:value.slice(split+1);if(!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(name)||path==="")throw new CliError("usage","--input expects name or name=path");if(bindings.has(name))throw new CliError("usage",`Duplicate --input: ${name}`);bindings.set(name,path)}return bindings}var isGlob=path=>/[*?[\]{}]/.test(path);function rejectSkippedPatterns(name,patterns){for(const pattern of patterns){const skipped=pattern.split("/").find(skippedInputEntry);if(skipped===".gauge")throw new CliError("usage",`Input ${name}: ${pattern} is inside .gauge/. Inputs never include .gauge/, because it holds run results and local config.`,{hint:"Move the files outside .gauge/ and update the glob."});if(skipped)throw new CliError("usage",`Input ${name}: ${pattern} is inside ${skipped}, which inputs never include`,{hint:`Move the files outside ${skipped} and update the glob.`})}}async function walkInput(root,depth=Infinity){const paths=[];const walk=async(directory,level)=>{for(const entry of await readdir(join11(root,directory),{withFileTypes:true})){if(skippedInputEntry(entry.name)||!entry.isFile()&&!entry.isDirectory())continue;const next=directory?`${directory}/${entry.name}`:entry.name;if(entry.isDirectory()){if(level<depth)await walk(next,level+1)}else paths.push(next);if(paths.length>2e4)throw new CliError("usage","Input exceeds 20,000 files")}};await walk("",1);return paths.sort()}function selectPaths(name,paths,patterns){rejectSkippedPatterns(name,patterns);try{return matchInputPaths(paths,patterns)}catch(error){throw new CliError("usage",`Input ${name}: ${message(error).replace("committed files","files")}`)}}async function expandOverrideGlob(name,glob){const segments=glob.split(sep3);const first=segments.findIndex(isGlob);const root=segments.slice(0,first).join(sep3)||sep3;const pattern=segments.slice(first).join("/");const info=await stat(root).catch(()=>void 0);if(!info?.isDirectory())throw new CliError("usage",`Input ${name}: ${root} is not a directory`);const depth=pattern.includes("**")?Infinity:pattern.split("/").length;return{root,pattern,files:selectPaths(name,await walkInput(root,depth),[pattern])}}async function selectLocalInput(resource,supplied,override){let path=resolve4(supplied);let info=await lstat(path).catch(()=>void 0);if(!info&&override&&isGlob(path)){if(resource.use.type==="skill")throw new CliError("usage",`Input ${resource.name}: Skill inputs take an explicit directory or archive, not a glob`);const{root:root2,pattern,files}=await expandOverrideGlob(resource.name,path);if(resource.use.type==="files")return{use:{type:"files"},root:root2,files,skillDirectory:false};if(resource.use.type==="binary")return{use:{...resource.use,paths:[pattern]},root:root2,files,skillDirectory:false};if(files.length!==1)throw new CliError("usage",`Input ${resource.name}: ${supplied} matches ${files.length} files; keep one`);path=join11(root2,files[0]);info=await lstat(path)}if(!info)throw new CliError("usage",`Input path does not exist: ${supplied}`,{hint:"Pass --input <name>=<path>, or fix the input's path in gauge.json."});if(!info.isFile()&&!info.isDirectory())throw new CliError("usage",`Input must be an ordinary file or directory: ${supplied}`);let use=resource.use;if(use.type==="web-fixture"){if(!info.isFile())throw new CliError("usage","Supply a web fixture JSON file");use={type:"web-fixture",path:basename(path)}}else if(use.type==="skill"){if(info.isFile()&&!isSkillArchive(path))throw new CliError("usage","Supply a Skill directory, .zip, or .tar.gz archive");use={...use,root:info.isDirectory()?".":basename(path)}}else if(use.type==="npm-package"||use.type==="npm-cli"){if(!info.isFile()||!path.endsWith(".tgz"))throw new CliError("usage","Supply the packed npm .tgz file");use={...use,package:basename(path)}}else if(override&&use.type==="files")use={type:"files"};else if(override&&use.type==="binary")use={...use,paths:[info.isDirectory()?"**":basename(path)]};const root=info.isDirectory()?path:dirname(path);const paths=info.isDirectory()?await walkInput(root):[basename(path)];const patterns=!override&&(use.type==="files"||use.type==="binary")?use.paths:void 0;return{use,root,files:patterns?selectPaths(resource.name,paths,patterns):paths,skillDirectory:use.type==="skill"&&info.isDirectory()}}async function packLocalInput(resource,supplied,output,{override=false}={}){if(resource.use.type==="website")throw new CliError("usage",`Input ${resource.name}: website inputs cannot be supplied through --input.`,{hint:"Use the configured public preview with --hosted. For content-only alternatives and their discovery limits, read `gauge instructions hillclimb`."});const{use,root,files,skillDirectory}=await selectLocalInput(resource,supplied,override);if(!files.length)throw new CliError("usage","Input contains no selected files");if(use.type==="binary"){for(const[command,target]of Object.entries(use.commands))if(!files.includes(target))throw new CliError("usage",`Input ${resource.name}: binary command ${command} target is missing: ${target}`,override?{hint:"Command targets are relative to the supplied path."}:void 0)}if(skillDirectory&&!files.includes("SKILL.md"))throw new CliError("usage","Skill directory must contain SKILL.md at its root");let total=0;for(const file of files){inputPathSchema.parse(file);const entry=await lstat(join11(root,file));if(!entry.isFile())throw new CliError("usage",`Input file changed or is not an ordinary file: ${file}`);total+=entry.size;if(total>LIMIT)throw new CliError("usage","Input exceeds 512 MiB")}await tar({cwd:root,file:output,gzip:true,portable:true,noMtime:true,follow:false,noDirRecurse:true},files.map(file=>`./${file}`));const bytes=(await stat(output)).size;if(bytes>LIMIT)throw new CliError("usage","Input archive exceeds 512 MiB");const hash=createHash5("sha256");for await(const chunk of createReadStream2(output))hash.update(chunk);const sha256=`sha256:${hash.digest("hex")}`;if(use.type==="web-fixture")await readWebFixtureArchive(output,use.path,sha256);return{use,upload:{path:output,bytes,sha256},files}}async function loadLocalRunDefinition(files,values,cwd=process.cwd(),{local=false,spec}={}){const directory=await mkdtemp(join11(tmpdir(),"gauge-inputs-"));const cleanup=()=>rm(directory,{recursive:true,force:true});try{const root=rootDirectory(cwd);const paths=workingFiles(root);const blobs=new Map;if(paths.includes("gauge.json"))blobs.set("gauge.json",read(root,"gauge.json"));const configBytes=blobs.get("gauge.json");let config;try{config=runDefinitionFileConfigSchema.parse(configBytes?JSON.parse(configBytes.toString("utf8")):{})}catch(error){throw new CliError("usage",`gauge.json is not valid: ${error instanceof Error?error.message:error}`,{hint:"Run `gauge run --verify` for each problem."})}const patterns=spec?[]:files.length?files.map(file=>{const path=relative5(root,resolve4(cwd,file));if(!path||path===".."||path.startsWith(`..${sep3}`)||isAbsolute4(path))throw new CliError("usage","Case paths must be inside the definition directory");return path.split(sep3).join("/")}):config.cases;const cases=spec?[]:files.length?matchInputPaths(paths,patterns):matchInputPaths(paths,patterns,{allowEmptySelection:true});if(!spec&&cases.length===0)throw noCasesError();if(cases.length>20||cases.some(path=>!path.endsWith(".md")))throw new CliError("usage","Expected 1\u201320 Markdown cases");for(const path of cases)blobs.set(path,read(root,path));const parsed=spec?caseSpecCases(spec):cases.map(path=>parseRunDefinitionCase(path,blobs.get(path)??Buffer.alloc(0)));const unmeasured=parsed.filter(item=>!item.criteria&&!item.preference);if(!local&&unmeasured.length)throw new CliError("usage",`Hosted cases need criteria or preference: ${unmeasured.map(item=>item.path).join(", ")}`,{hint:"Add criteria, or run locally with --local."});const bindings=parseInputBindings(values);for(const name of bindings.keys())if(!(name in config.inputs))throw new CliError("usage",`Unknown input: ${name}`,{hint:`gauge.json defines: ${Object.keys(config.inputs).join(", ")||"none"}`});for(const item of parsed)for(const name of item.config.inputs??[])if(!(name in config.inputs))throw new CliError("usage",`${item.path}: unknown input "${name}". gauge.json defines: ${Object.keys(config.inputs).join(", ")||"none"}`);const selected=new Set(parsed.flatMap(item=>item.config.inputs??Object.keys(config.inputs)));for(const[name,override]of bindings){if(!selected.has(name))throw new CliError("usage",`Input is not used by the selected cases: ${name}`);if(override!==void 0)rejectSkippedPatterns(name,[relative5(root,resolve4(cwd,override)).split(sep3).join("/")])}const git2=args=>{try{return execFileSync2("git",args,{cwd:root,encoding:"utf8",stdio:["ignore","pipe","pipe"]}).trim()}catch{return null}};const commit=git2(["rev-parse","--verify","HEAD^{commit}"]);const origin=git2(["remote","get-url","origin"]);const repoUrl=origin&&uncredentialedRepoUrlSchema.safeParse(origin).success?origin:null;const unattachedInputs=Object.keys(config.inputs).filter(name=>!selected.has(name));const resources=[];const uploads=[];const inputSnapshots=[];for(const[name,input]of Object.entries(config.inputs)){if(!selected.has(name))continue;if(local&&input.type==="website")throw new CliError("usage",`Website input "${name}" requires hosted Gauge to replace the original site with your preview.`,{hint:"Use --hosted with a public preview. For local runs, supply documentation files or a preview URL in the prompt. These give the agent your content directly rather than testing whether it finds your site. See `gauge instructions hillclimb`."});const original=compileDefinitionInput(name,input,repoUrl??"",commit??"");const override=bindings.get(name);const supplied=override??(original.source.type==="git"?workingTreeInput(root,name,input):void 0);if(supplied!==void 0){const{use,upload,files:files2}=await packLocalInput(original,resolve4(cwd,supplied),join11(directory,`${name}.tar.gz`),{override:override!==void 0});uploads.push(upload);inputSnapshots.push({name,source:override!==void 0?"override":"working-tree",path:resolve4(cwd,supplied),gaugeArchive:{sha256:upload.sha256,bytes:upload.bytes},files:files2.slice(0,SNAPSHOT_FILES),fileCount:files2.length});resources.push({...original,use,source:{type:"upload",sha256:upload.sha256,bytes:upload.bytes,repoUrl,commit}})}else{if(local)throw new CliError("usage",`Input ${name} has a remote source. Supply --input ${name}=<path> for local execution, or use --hosted.`);if(!repoUrl||!commit)throw new CliError("usage",`Input ${name}'s configured ${original.source.type} source requires a Git checkout with an origin.`,{hint:input.type==="website"?"Configure the repository origin and publish a matching public preview through the declared source. Website inputs cannot use --input; see `gauge instructions hillclimb` for content-only alternatives.":`Supply --input ${name}=<path> to use local files.`});resources.push(original)}}if(!spec){const compiled=compileRunDefinitionFromBlobs({repoUrl,commit,resources,blobs,casePaths:cases,verification:"LOCAL"});const webFixtures=await freezeWebFixtures({...compiled.definition,resources:resources.filter(r=>r.source.type==="upload")},uploads);return{...compiled,webFixtures,uploads,inputSnapshots,unattachedInputs,cleanup}}const definition={version:2,source:{repoUrl,commit,digest:caseSpecDigest(spec),verification:"LOCAL"},resources,cases:parsed};if(!local)runDefinitionSubmissionSchema.parse(definition);return{definition,webFixtures:await freezeWebFixtures({...definition,resources:resources.filter(r=>r.source.type==="upload")},uploads),org:config.orgId??config.org,uploads,inputSnapshots,unattachedInputs,cleanup}}catch(error){await cleanup();if(error instanceof CliError||!(error instanceof Error))throw error;throw new CliError("usage",error.message,{hint:"Check the case format in `gauge instructions run`, then run `gauge run --verify`."})}}function workingTreeInput(root,name,input){switch(input.type){case"website":throw new CliError("usage",`Input ${name} is a website; website inputs run on hosted Gauge only`);case"files":case"binary":return root;case"web-fixture":case"skill":return join11(root,input.path);case"npm-package":{const matches2=globSync2(input.path,{cwd:root});if(matches2.length!==1)throw new CliError("usage",matches2.length?`Input ${name}: ${input.path} matches ${matches2.length} files; keep one`:`Input ${name}: no file matches ${input.path}. Run \`npm pack\` first`);return join11(root,matches2[0])}}}async function uploadLocalInputs(client,org,uploads){for(const input of uploads){const signed2=await client.post(`/api/v1/orgs/${encodeURIComponent(org)}/run-definitions/uploads`,{sha256:input.sha256,bytes:input.bytes});const signal=AbortSignal.timeout(10*60*1e3);for(let attempt=0;attempt<3;attempt++){const body=createReadStream2(input.path);let response;try{response=await fetch(signed2.url,{method:"PUT",headers:signed2.headers,body,duplex:"half",redirect:"error",signal})}finally{body.destroy()}await response.body?.cancel();if(response.ok||response.status===412)break;if(response.status!==409||attempt===2)throw new CliError("network",`Input upload failed (${response.status})`);await delay2(100*2**attempt,void 0,{signal})}}}var SIDE_KEYS=["request","batch","eval","revision","experiment","trial","agent","model","since","until"];var SELECTING_KEYS=new Set(["request","batch","eval","experiment","trial"]);function csv4(value){return value.split(",").map(part=>part.trim()).filter(Boolean)}function parseCompareSide(flag,pairs){const side={};const seen=new Set;for(const pair2 of pairs){const eq=pair2.indexOf("=");const key=eq<0?"":pair2.slice(0,eq).trim();const value=eq<0?"":pair2.slice(eq+1).trim();if(!SIDE_KEYS.includes(key)||!value)throw new CliError("usage",`invalid ${flag} "${pair2}" (expected key=value with key one of ${SIDE_KEYS.join(", ")})`);if(seen.has(key)&&key!=="batch")throw new CliError("usage",`${flag} ${key}= given twice`);seen.add(key);if(key==="request")side.runRequest=value;else if(key==="batch")side.batch=[...side.batch??[],...csv4(value)];else if(key==="eval")side.evalSet=value;else if(key==="revision")side.evalRevision=value;else if(key==="experiment")side.experiment=value;else if(key==="trial")side.trial=value;else if(key==="agent")side.agent=parseAgents(value);else if(key==="model")side.model=csv4(value);else if(key==="since")side.since=value;else side.until=value}if(![...seen].some(key=>SELECTING_KEYS.has(key)))throw new CliError("usage",`${flag} needs request=, batch=, eval=, experiment=, or trial= to select runs`);return side}function pct3(rate){return rate===null?"":`${Math.round(rate*100)}%`}function passCell(stats){return stats.judged===0?"":`${pct3(stats.passRate)} (${stats.passed}/${stats.judged})`}function signed(value,format){if(value===null)return"";return`${value>0?"+":value<0?"-":"\xB1"}${format(Math.abs(value))}`}var points=rate=>`${Math.round(rate*100)}pp`;var turns=n=>String(Math.round(n*10)/10);var usd=n=>`$${n.toFixed(2)}`;var secs=ms=>`${Math.round(ms/1e3)}s`;function pair(before,after,delta3,format){if(before===null&&after===null)return"";const side=v=>v===null?"\u2014":format(v);return`${side(before)} \u2192 ${side(after)}${delta3===null?"":` (${signed(delta3,format)})`}`}function row(target,item){const{baseline:a,candidate:b,delta:delta3}=item;return{target,runs:`${a.runs} \u2192 ${b.runs}`,completed:`${a.succeeded}/${a.runs} \u2192 ${b.succeeded}/${b.runs}`,baseline:passCell(a),candidate:passCell(b),"\u0394 pass":signed(delta3.passRate,points),turns:pair(a.medianTurns,b.medianTurns,delta3.medianTurns,turns),cost:pair(a.medianUsdCost,b.medianUsdCost,delta3.medianUsdCost,usd),duration:pair(a.medianDurationMs,b.medianDurationMs,delta3.medianDurationMs,secs)}}function compareWarnings(result){const warnings=[];for(const name of["baseline","candidate"]){const side=result.sides[name];const stats=result.overall[name];if(stats.runs===0)warnings.push(`${name} matched no runs. Check its selectors; optimization trial runs need trial=<trialId>.`);else if(stats.finished<stats.runs)warnings.push(`${name} has ${stats.runs-stats.finished} of ${stats.runs} runs still in progress, so its numbers are partial. Run \`gauge run wait <request-id>\` first.`);if(stats.judged<stats.finished)warnings.push(`${name} has ${stats.finished-stats.judged} finished runs without a verdict (not judged yet, or no criteria). Its pass rate covers judged runs only.`);for(const mixed of side.mixedRevisions??[])warnings.push(`${name}: ${mixed.evalSetId?`eval ${mixed.evalSetId}`:`case prompt ${mixed.promptId}`} ran under ${mixed.revisions.length} revisions (${mixed.revisions.join(", ")}): it was edited between runs. Add --${name} revision=<hash> to pick one.`);if(side.truncated)warnings.push(`${name} matched too many runs; only the newest were compared. Narrow it with since=, until=, or batch=.`)}return warnings}function printComparison(result){const revisions=name=>result.sides[name].evalRevisions.join(", ")||"\u2014";console.log(`Baseline revision: ${revisions("baseline")}. Candidate revision: ${revisions("candidate")}.`);for(const name of["baseline","candidate"]){for(const trial of result.sides[name].trials??[])console.log(`${name}: ${trial.runs} run${trial.runs===1?"":"s"} from optimization trial ${trial.key} "${trial.title}" (${trial.kind}). Inspect: gauge optimizations trial ${trial.optimizationId} ${trial.trialId}`)}console.log("Medians are baseline \u2192 candidate (difference).");console.log("");printItems([row("all",result.overall),...result.targets.map(target=>row(`${target.agent} ${target.model||"(default)"}`,target))],"table");const before=new Map(result.overall.baseline.criteria.map(c=>[c.name,c]));const after=new Map(result.overall.candidate.criteria.map(c=>[c.name,c]));if(result.overall.delta.criteria.length>0){console.log("");printItems(result.overall.delta.criteria.map(c=>{const a=before.get(c.name);const b=after.get(c.name);return{criterion:c.name,baseline:a&&a.judged>0?`${pct3(a.passRate)} (${a.passed}/${a.judged})`:"",candidate:b&&b.judged>0?`${pct3(b.passRate)} (${b.passed}/${b.judged})`:"","\u0394 pass":signed(c.passRate,points)}}),"table")}}var LOCAL_AGENTS2=new Set(["CLAUDE_CODE","CODEX_CLI","CURSOR","PI","OPENCODE"]);var LOCAL_TERMINAL_STATES=new Set(["completed","failed","canceled","interrupted"]);function localCompareFilter(flag,side){const hostedOnly2=[side.runRequest!==void 0&&"request=",side.experiment!==void 0&&"experiment=",side.trial!==void 0&&"trial="].filter(Boolean);if(hostedOnly2.length>0)throw new CliError("usage",`${flag} ${hostedOnly2.join(", ")} select hosted runs; local sides take batch=, eval=<saved id>, revision=<number>, agent=, model=, since=, until=`);if((side.batch?.length??0)>1)throw new CliError("usage",`${flag} takes one batch= locally`);if((side.agent?.length??0)>1||(side.model?.length??0)>1)throw new CliError("usage",`${flag} takes one agent= and one model= locally`);if(side.evalRevision!==void 0&&!/^[1-9]\d*$/.test(side.evalRevision))throw new CliError("usage",`${flag} local revision= must be a positive integer`);return{batch:side.batch?.[0],evalId:side.evalSet,measurementRevision:side.evalRevision===void 0?void 0:Number(side.evalRevision),agent:side.agent?.[0],model:side.model?.[0],since:side.since?parseSince(side.since,Date.now(),"since="):void 0,until:side.until?parseSince(side.until,Date.now(),"until="):void 0}}function median(values){if(values.length===0)return null;const sorted=[...values].sort((a,b)=>a-b);const mid=sorted.length>>1;return sorted.length%2?sorted[mid]:(sorted[mid-1]+sorted[mid])/2}function localStats(runs){const judged=runs.filter(run=>run.criterionResults?.length&&run.criterionResults.every(criterion=>criterion.outcome!=="UNASSESSABLE"));const passed=judged.filter(run=>run.criterionResults.every(criterion=>criterion.outcome==="PASS")).length;const byCriterion=new Map;for(const run of runs)for(const criterion of run.criterionResults??[]){const current=byCriterion.get(criterion.name)??{name:criterion.name,judged:0,passed:0};if(criterion.outcome!=="UNASSESSABLE"){current.judged++;if(criterion.outcome==="PASS")current.passed++}byCriterion.set(criterion.name,current)}const recorded=values=>values.filter(value=>typeof value==="number"&&Number.isFinite(value));return{runs:runs.length,finished:runs.filter(run=>LOCAL_TERMINAL_STATES.has(run.outcome)).length,succeeded:runs.filter(run=>run.outcome==="completed").length,judged:judged.length,passed,passRate:judged.length?passed/judged.length:null,medianTurns:median(recorded(runs.map(run=>run.turns))),medianUsdCost:null,medianDurationMs:median(recorded(runs.map(run=>run.durationMs))),criteria:[...byCriterion.values()].map(criterion=>({...criterion,passRate:criterion.judged?criterion.passed/criterion.judged:null}))}}function diff(a,b){return a===null||b===null?null:b-a}function localRow(baseline,candidate){const a=localStats(baseline);const b=localStats(candidate);return{baseline:a,candidate:b,delta:{passRate:diff(a.passRate,b.passRate),medianTurns:diff(a.medianTurns,b.medianTurns),medianUsdCost:null,medianDurationMs:diff(a.medianDurationMs,b.medianDurationMs),criteria:[...new Set([...a.criteria,...b.criteria].map(criterion=>criterion.name))].map(name=>({name,passRate:diff(a.criteria.find(criterion=>criterion.name===name)?.passRate??null,b.criteria.find(criterion=>criterion.name===name)?.passRate??null)}))}}}function compareLocalRuns(baseline,candidate){const targets=new Map;for(const run of[...baseline,...candidate]){const agent=LOCAL_AGENTS2.has(run.agent)?run.agent:void 0;if(agent)targets.set(`${run.agent} ${run.model}`,{agent,model:run.model})}const forTarget=(runs,key)=>runs.filter(run=>`${run.agent} ${run.model}`===key);return{overall:localRow(baseline,candidate),targets:[...targets].map(([key,target])=>({...target,...localRow(forTarget(baseline,key),forTarget(candidate,key))})),sides:{baseline:localRevisionMetadata(baseline),candidate:localRevisionMetadata(candidate)}}}function localRevisionMetadata(runs){const byMeasurement=new Map;const allRevisions=new Set;for(const run of runs){if(run.measurementRevision===void 0||run.measurementRevision===null)continue;const revision=String(run.measurementRevision);allRevisions.add(revision);if(run.evalId){const revisions=byMeasurement.get(run.evalId)??new Set;revisions.add(revision);byMeasurement.set(run.evalId,revisions)}}return{evalRevisions:[...allRevisions].sort((a,b)=>Number(a)-Number(b)),mixedRevisions:[...byMeasurement].filter(([,revisions])=>revisions.size>1).map(([evalSetId,revisions])=>({evalSetId,promptId:null,revisions:[...revisions]})),truncated:false}}function localCompareWarnings(result){const warnings=compareWarnings(result).filter(warning=>!warning.includes("matched no runs")).map(warning=>warning.replace("gauge run wait <request-id>","gauge run wait --batch <batch-id> --local").replace("revision=<hash>","revision=<number>").replace("not judged yet, or no criteria","analysis missing, unassessable criteria, or no criteria"));for(const name of["baseline","candidate"])if(result.overall[name].runs===0)warnings.unshift(`${name} matched no local runs. Check its selectors: batch=, eval=<saved id>, revision=<number>, agent=, model=, since=, until=. \`gauge run list --local\` shows the values.`);return warnings}function runPath(id){return`/api/v1/runs/${encodeURIComponent(id)}`}function streamPath(id){return`/api/runs/${encodeURIComponent(id)}/stream`}function fmtDuration(ms){if(ms==null)return"";const s=Math.round(ms/1e3);return s>=60?`${Math.floor(s/60)}m${s%60}s`:`${s}s`}function fmtUsd(v){return v==null?"":`$${v.toFixed(2)}`}function compact(value,max=140){const s=typeof value==="string"?value:JSON.stringify(value)??"null";const one=s.replace(/\s+/g," ").trim();return one.length>max?`${one.slice(0,max-1)}\u2026`:one}function toRow4(run){const selected=run.selectedProvider?.slug??"";const observed=run.observedProvider?.slug;return{id:run.id,status:run.status,agent:run.agent,model:run.modelDisplayName??run.resolvedModel??run.model,provider:observed&&observed!==selected?`${selected||"?"} \u2192 ${observed}`:selected||observed||"",experiment:run.experiment??"",revision:run.evalRevision??"",trial:run.optimizationTrial?`${run.optimizationTrial.key} ${run.optimizationTrial.trialId}`:"",source:run.triggeredBy?.source??"",turns:run.turns??"",cost:fmtUsd(run.usdCost),credits:run.creditsCharged??"",duration:fmtDuration(run.durationMs),created:run.createdAt,prompt:compact(run.promptSnippet,48)}}function toLocalRow(run){return{id:run.id,status:run.outcome,agent:run.agent,model:run.model,batch:run.batchId,eval:run.evalId??"",turns:run.turns,analyzed:run.analyzed?"yes":"",ended:run.endedAt}}function detailLines(run){return[["Id",run.id],["Status",run.status],["Agent",run.agent],["Model",run.modelDisplayName||run.resolvedModel||run.model||"(platform default)"],["Requested model",run.model||"(platform default)"],["Selected provider",run.selectedProvider?`${run.selectedProvider.displayName} (${run.selectedProvider.slug})`:"\u2014"],["Observed provider",run.observedProvider?`${run.observedProvider.slug} (${run.observedProvider.source.toLowerCase().replaceAll("_"," ")})`:"\u2014"],["Prompt",compact(run.promptText,120)],["Prompt id",run.promptId],["Batch",run.batchId],["Experiment",run.experiment??"\u2014"],["Eval set",run.evalSetId??"\u2014"],["Eval revision",run.evalRevision??"\u2014"],["Optimization trial",run.optimizationTrial?`${run.optimizationTrial.key} "${run.optimizationTrial.title}" (${run.optimizationTrial.kind}), trial ${run.optimizationTrial.trialId} in optimization ${run.optimizationTrial.optimizationId}`:"\u2014"],["Scenario",run.scenario],["Funding",run.funding],["Repo",run.repoUrl?`${run.repoUrl}${run.repoRef?` @ ${run.repoRef}`:""}`:"\u2014"],["Attempt",String(run.attempt)],["Turns",run.turns==null?"\u2014":String(run.turns)],["Triggered by",triggeredByLabel(run.triggeredBy)||"\u2014"],["Cost",fmtUsd(run.usdCost)||"\u2014"],["Credits",run.creditsCharged==null?"\u2014":String(run.creditsCharged)],["Duration",fmtDuration(run.durationMs)||"\u2014"],["Exit reason",run.exitReason??"\u2014"],["Failure reason",run.failureReason??"\u2014"],["Cancel requested",run.cancelRequested?"yes":"no"],["Diff",run.hasDiff?`yes (gauge run diff ${run.id})`:"no"],...run.criterionResults.map(c=>[`Criterion ${c.name}`,c.passed===null?"not assessed":c.passed?"passed":"failed"]),["Created",run.createdAt],["Started",run.startedAt??"\u2014"],["Finished",run.finishedAt??"\u2014"]]}function passLine(label,pass){const bits=[pass.status];if(pass.model)bits.push(pass.model);const cost=fmtUsd(pass.usdCost);if(cost)bits.push(cost);if(pass.error)bits.push(`error: ${compact(pass.error,60)}`);return`${label.padEnd(20)} ${bits.join(" ")}`}var PASS_LABELS={ANALYSIS:"Session analysis",CLI_DISCOVERY:"CLI discovery",LEVER:"Improvement levers",EXPERIMENT_DELTA:"Experiment delta"};var INSTALLED={NONE:"",ATTEMPTED:"attempted",CONFIGURED:"configured",EXERCISED:"exercised"};var check2=value=>value?"yes":"";function printInsight(insight){for(const pass of insight.passes){console.log(passLine(PASS_LABELS[pass.kind]??pass.kind,pass))}const analysis=insight.analysis;if(!analysis){console.log(insight.decision.status==="SKIPPED"?"\n(skipped)":"\n(no analysis yet)");return}if(analysis.limitation)console.log(`
|
|
751
784
|
${compact(analysis.limitation,200)}`);console.log(`
|
|
752
785
|
Findings (${analysis.observations.length})`);for(const finding of analysis.observations){console.log(` ${finding.kind}: ${finding.label}`);console.log(` ${finding.detail}`);console.log(` Evidence: ${JSON.stringify(finding.evidence)}`)}console.log(`
|
|
753
|
-
Products (${analysis.products.length})`);if(analysis.products.length>0)printItems(analysis.products.map(p=>({product:p.name,considered:check2(p.considered),chosen:check2(p.chosen),rejected:check2(p.rejected),installed:INSTALLED[p.installPhase]??p.installPhase,rank:p.rank??"",source:p.source.toLowerCase()})),"table");const delta3=insight.experimentDelta;if(delta3&&typeof delta3==="object"){console.log("\nExperiment delta");console.log([delta3.changed==null?"":delta3.changed?"changed":"no change",delta3.hypothesisSupported??""].filter(Boolean).join(" "));if(delta3.summary)console.log(compact(delta3.summary,300))}console.error("\n(full detail: rerun with -o json)")}function parseEvent(data){try{const parsed=runEventSchema.safeParse(JSON.parse(data));return parsed.success?parsed.data:null}catch{return null}}function formatEventLine(e){const rec=e;const head=`[t${e.turn}#${e.seq}]`;switch(e.type){case"run_meta":{const agent=rec.agent;const model=agent?.model?` model=${agent.model}`:"";return`${head} run_meta agent=${agent?.name??"?"}${model}`}case"agent_message":return`${head} agent: ${compact(rec.text)}`;case"reasoning":return`${head} reasoning: ${compact(rec.text)}`;case"tool_call":return`${head} tool_call ${String(rec.name)}: ${compact(rec.input)}`;case"tool_result":return`${head} tool_result${rec.is_error?" ERROR":""}: ${compact(rec.output,100)}`;case"run_result":return`${head} run_result ${String(rec.exit_reason)} turns=${String(rec.turns)} cost=${fmtUsd(rec.cost_usd)} duration=${fmtDuration(rec.duration_ms)}`;default:{const{run_id:_runId,seq:_seq,turn:_turn,ts:_ts,type:_type,...payload}=rec;return`${head} ${e.type} ${compact(payload)}`}}}var TERMINAL_STATUSES=new Set(["SUCCEEDED","FAILED","TIMED_OUT","CANCELED"]);var STATUS_POLL_MS=5e3;var TERMINAL_DRAIN_MS=2e3;async function streamRun(id,json,opts){const client=createClient();const controller=new AbortController;let timer;let poller;let drainTimer;let gotResult=false;let sawData=false;const arm=ms=>{if(timer)clearTimeout(timer);if(ms>0)timer=setTimeout(()=>controller.abort(),ms)};arm(opts.idleMs>0?opts.firstEventMs:0);if(opts.pollStatus){let inFlight=false;poller=setInterval(()=>{if(inFlight||drainTimer)return;inFlight=true;client.get(runPath(id)).then(run=>{if(drainTimer||!TERMINAL_STATUSES.has(run.status))return;if(poller)clearInterval(poller);drainTimer=setTimeout(()=>{if(!gotResult){console.error(`Run is ${run.status}; no more events.`)}controller.abort()},TERMINAL_DRAIN_MS)}).catch(()=>{}).finally(()=>{inFlight=false})},STATUS_POLL_MS)}try{await client.sse(streamPath(id),frame=>{const event=parseEvent(frame.data);if(!event)return;sawData=true;if(json)console.log(frame.data);else console.log(formatEventLine(event));if(event.type==="run_result"){gotResult=true;controller.abort()}else if(opts.stopAtLiveMs!==void 0&&Date.parse(event.ts)>=opts.stopAtLiveMs){gotResult=true;controller.abort()}else arm(opts.idleMs)},{signal:controller.signal,onComment:()=>{if(!sawData&&opts.idleMs>0)arm(opts.firstEventMs)}})}finally{if(timer)clearTimeout(timer);if(poller)clearInterval(poller);if(drainTimer)clearTimeout(drainTimer)}}async function loadWorkingTree(cmd,opts,upload,spec){const loaded=await loadLocalRunDefinition(opts.files??[],opts.input,void 0,{spec});try{const org=resolveOrg(cmd,loaded.org);if(upload)await confirmOrAbort("Run these cases now?",opts.yes);await uploadLocalInputs(createClient(),org,loaded.uploads);return{definition:loaded.definition,org,inputSnapshots:loaded.inputSnapshots,unattachedInputs:loaded.unattachedInputs}}finally{await loaded.cleanup()}}function printPlan2(result){console.log(`Definition: ${result.source.verification==="LOCAL"?"current files":result.source.commit}`);console.log(`Expected sessions: ${result.expectedRuns}`);for(const item of result.cases)console.log(` ${item.path}: ${item.expectedRuns} sessions, ${item.preference?`${item.preference.kind} preference (advisory)`:`${item.criteriaCount} criteria`}`);for(const resource of result.resources){const use=resource.use;if(use.type==="npm-package"||use.type==="npm-cli"){const install=use.install??"environment";console.log(` ${resource.name}: npm package \u2192 ${install}`);const label=install==="environment"?"Commands on PATH":"Package commands";console.log(` ${label}: ${resource.commands===void 0?"determined when the input is prepared":resource.commands.join(", ")||"none (library)"}`)}else if(use.type==="binary"){console.log(` ${resource.name}: native executable \u2192 ${use.platform}`);console.log(` Commands on PATH: ${Object.keys(use.commands).join(", ")}`);console.log(" Requires compatible system libraries; Gauge does not install OS packages.")}else console.log(` ${resource.name}: ${use.type}`);if(resource.detail)console.log(` ${resource.detail}`)}if(result.resources.length){console.log(`Inputs: ${result.resources.map(r=>`${r.name} (${r.source}, ${r.readiness})`).join(", ")}`);if(!result.canRun)console.log("Resolve the input errors before launching.")}printInputSnapshots(result.inputSnapshots);printUnattachedInputs(result.unattachedInputs,false)}function printInputSnapshots(snapshots){for(const input of snapshots){console.log(` ${input.name}: ${input.source==="working-tree"?"working-tree snapshot":"local path override snapshot"}`);console.log(` Source path: ${input.path}`);const shown=input.files.slice(0,10);console.log(` Files (${input.fileCount}): ${shown.join(", ")}${input.fileCount>shown.length?`, and ${input.fileCount-shown.length} more`:""}`);console.log(` Gauge archive digest: ${input.gaugeArchive.sha256}`);console.log(` Gauge archive bytes: ${input.gaugeArchive.bytes}`)}if(snapshots.length)console.log("Gauge archive hashes identify delivery archives containing the selected files. For npm inputs, the archive contains the .tgz; its hash and size differ from the .tgz itself. Launching again snapshots current files.")}function unattachedNote(names,saved){return`Not attached: ${names.join(", ")}. ${saved?`Saved measurements attach only inputs passed at launch; add ${names.map(name=>`--input ${name}`).join(" ")} to attach.`:`The selected cases do not use ${names.length===1?"it":"them"}.`}`}function printUnattachedInputs(names,saved){if(names.length)console.log(unattachedNote(names,saved))}async function launch(cmd,opts){if(opts.profile&&gaugeState(cmd).mode!=="local")throw new CliError("usage","--profile applies only to local runs. Pass --local.");const sources=[opts.eval!==void 0&&"--eval",opts.preference!==void 0&&"--preference",opts.apply!==void 0&&"--apply"].filter(flag=>Boolean(flag));const source=sources[0];if(opts.schema||opts.example){const flag=opts.schema?"--schema":"--example";if(source||opts.schema&&opts.example)throw new CliError("usage",`${flag} prints and exits; pass it alone`);const cases=opts.format!=="battery";if(opts.schema)printJson(cases?CASE_SPEC_SCHEMA():BATTERY_SCHEMA());else{printJson(cases?EXAMPLE_CASE_SPEC:EXAMPLE_SPEC);console.error(cases?"\n# Case spec: eval cases as JSON. Save to cases.json, edit, then: gauge run --apply cases.json":"\n# Battery spec: saved prompts and schedules. Save to battery.json, edit, then: gauge run --apply battery.json\n# For eval cases as JSON (criteria, inputs): gauge run --example --format case")}return}if(opts.format)throw new CliError("usage","--format applies with --schema or --example");if(sources.length>1)throw new CliError("usage",`pass only one of ${sources.join(", ")}`);if(opts.verify){const extra=[source,opts.dryRun&&"--dry-run",opts.files!==void 0&&"--files",opts.input.length>0&&"--input"].filter(Boolean);if(extra.length>0)throw new CliError("usage",`--verify checks the eval files in this repo; drop ${extra.join(", ")}`);const result2=verifyEvals(void 0,{local:gaugeState(cmd).mode==="local"});if(resolveOutput(cmd)==="json")printJson(result2);else printEvalVerification(result2);if(result2.summary.no>0)process.exitCode=1;return}if(opts.scenario.length>0&&source!=="--preference")throw new CliError("usage","--scenario applies with --preference only");if((opts.agent.length>0||opts.samples!==void 0)&&source!=="--eval"&&source!=="--preference")throw new CliError("usage","--agent and --samples apply with --eval or --preference; eval case files set them in their front matter");if(opts.files!==void 0&&source)throw new CliError("usage",`--files applies to this repo's eval cases; drop ${source}`);if(opts.input.length>0&&(opts.eval!==void 0||opts.preference!==void 0)&&gaugeState(cmd).mode!=="local")throw new CliError("usage",`Hosted saved measurements do not take project inputs; drop --input or pass --local`,{hint:"For hosted project inputs, use eval case files or a case spec."});if(opts.requireExperiment!==void 0&&!opts.apply)throw new CliError("usage","--require-experiment applies with --apply");let spec;if(opts.apply!==void 0){const json=await readSpecJson(opts.apply);if(!isCaseSpec(json)){if(gaugeState(cmd).mode==="local")throw new CliError("usage","Battery specs (with `prompts`) run on hosted Gauge only.",{hint:"For local runs, pass a case spec (with `cases`): `gauge run --example --format case`. Or pass --hosted."});if(opts.input.length>0)throw new CliError("usage","--input applies to case specs, not battery specs");await applySpec(cmd,parseSpec(json),{dryRun:opts.dryRun,requireExperiment:opts.requireExperiment});return}if(opts.requireExperiment!==void 0)throw new CliError("usage","--require-experiment applies to battery specs, not case specs");spec=parseCaseSpec(json)}if(gaugeState(cmd).mode==="local"&&(opts.eval||opts.preference)){const saved=localMeasurementSpec(cmd,opts.eval?"eval":"preference",opts.eval??opts.preference,{...opts,inputs:[...parseInputBindings(opts.input).keys()]});await runLocalCases(cmd,opts,saved.spec,saved.measurement);return}if(opts.dryRun&&source&&!spec)throw new CliError("usage",`--dry-run previews this repo's eval cases or an --apply spec; drop ${source}`);if(opts.eval!==void 0||opts.preference!==void 0)requireHosted(cmd);if(opts.eval!==void 0){await runEvalSet(cmd,opts.eval,opts);return}if(opts.preference!==void 0){await runPreferencePrompt(cmd,opts.preference,opts);return}if(gaugeState(cmd).mode==="local"){await runLocalCases(cmd,opts,spec);return}const{definition,org,inputSnapshots,unattachedInputs}=await loadWorkingTree(cmd,opts,!opts.dryRun,spec);const orgPath=`/api/v1/orgs/${encodeURIComponent(org)}/run-definitions`;if(opts.dryRun){const result2=await createClient().post(`${orgPath}/plan`,definition);const preview={...result2,inputSnapshots,unattachedInputs};if(resolveOutput(cmd)==="json")printJson(preview);else printPlan2(preview);return}const result=await createClient().post(`${orgPath}/run`,definition);if(resolveOutput(cmd)==="json")printJson(result);else{console.log(`Started ${result.createdRuns}/${result.requestedRuns} sessions in request ${result.runRequestId}`);console.log(`Wait: gauge --org ${org} run wait ${result.runRequestId}`)}}async function runLocalCases(cmd,opts,spec,measurement){const{root}=gaugeState(cmd);if(!root)throw new CliError("usage","Local runs need a Gauge workspace. Run `gauge init` in this directory first.");const local=await loadLocalRunDefinition(opts.files??[],opts.input,process.cwd(),{local:true,spec});const json=resolveOutput(cmd)==="json";if(measurement&&local.unattachedInputs.length&&!opts.dryRun)console.error(`note: ${unattachedNote(local.unattachedInputs,true)}`);if(opts.dryRun){try{const plan={...await planLocal(local.definition,{profile:opts.profile,runtimeImage:opts.runtimeImage}),inputSnapshots:local.inputSnapshots,unattachedInputs:local.unattachedInputs};if(json)printJson(plan);else printLocalPlan(plan,measurement!==void 0)}finally{await local.cleanup()}return}if(opts.detach){try{const detached=await detachLocal(local.definition,local.uploads,join12(root,".gauge"),{profile:opts.profile,runtimeImage:opts.runtimeImage,measurement});if(json)printJson(detached);else console.log(`Batch ${detached.batchId} detached.
|
|
786
|
+
Products (${analysis.products.length})`);if(analysis.products.length>0)printItems(analysis.products.map(p=>({product:p.name,considered:check2(p.considered),chosen:check2(p.chosen),rejected:check2(p.rejected),installed:INSTALLED[p.installPhase]??p.installPhase,rank:p.rank??"",source:p.source.toLowerCase()})),"table");const delta3=insight.experimentDelta;if(delta3&&typeof delta3==="object"){console.log("\nExperiment delta");console.log([delta3.changed==null?"":delta3.changed?"changed":"no change",delta3.hypothesisSupported??""].filter(Boolean).join(" "));if(delta3.summary)console.log(compact(delta3.summary,300))}console.error("\n(full detail: rerun with -o json)")}function parseEvent(data){try{const parsed=runEventSchema.safeParse(JSON.parse(data));return parsed.success?parsed.data:null}catch{return null}}function formatEventLine(e){const rec=e;const head=`[t${e.turn}#${e.seq}]`;switch(e.type){case"run_meta":{const agent=rec.agent;const model=agent?.model?` model=${agent.model}`:"";return`${head} run_meta agent=${agent?.name??"?"}${model}`}case"agent_message":return`${head} agent: ${compact(rec.text)}`;case"reasoning":return`${head} reasoning: ${compact(rec.text)}`;case"tool_call":return`${head} tool_call ${String(rec.name)}: ${compact(rec.input)}`;case"tool_result":return`${head} tool_result${rec.is_error?" ERROR":""}: ${compact(rec.output,100)}`;case"run_result":return`${head} run_result ${String(rec.exit_reason)} turns=${String(rec.turns)} cost=${fmtUsd(rec.cost_usd)} duration=${fmtDuration(rec.duration_ms)}`;default:{const{run_id:_runId,seq:_seq,turn:_turn,ts:_ts,type:_type,...payload}=rec;return`${head} ${e.type} ${compact(payload)}`}}}var TERMINAL_STATUSES=new Set(["SUCCEEDED","FAILED","TIMED_OUT","CANCELED"]);var STATUS_POLL_MS=5e3;var TERMINAL_DRAIN_MS=2e3;async function streamRun(id,json,opts){const client=createClient();const controller=new AbortController;let timer;let poller;let drainTimer;let gotResult=false;let sawData=false;const arm=ms=>{if(timer)clearTimeout(timer);if(ms>0)timer=setTimeout(()=>controller.abort(),ms)};arm(opts.idleMs>0?opts.firstEventMs:0);if(opts.pollStatus){let inFlight=false;poller=setInterval(()=>{if(inFlight||drainTimer)return;inFlight=true;client.get(runPath(id)).then(run=>{if(drainTimer||!TERMINAL_STATUSES.has(run.status))return;if(poller)clearInterval(poller);drainTimer=setTimeout(()=>{if(!gotResult){console.error(`Run is ${run.status}; no more events.`)}controller.abort()},TERMINAL_DRAIN_MS)}).catch(()=>{}).finally(()=>{inFlight=false})},STATUS_POLL_MS)}try{await client.sse(streamPath(id),frame=>{const event=parseEvent(frame.data);if(!event)return;sawData=true;if(json)console.log(frame.data);else console.log(formatEventLine(event));if(event.type==="run_result"){gotResult=true;controller.abort()}else if(opts.stopAtLiveMs!==void 0&&Date.parse(event.ts)>=opts.stopAtLiveMs){gotResult=true;controller.abort()}else arm(opts.idleMs)},{signal:controller.signal,onComment:()=>{if(!sawData&&opts.idleMs>0)arm(opts.firstEventMs)}})}finally{if(timer)clearTimeout(timer);if(poller)clearInterval(poller);if(drainTimer)clearTimeout(drainTimer)}}async function loadWorkingTree(cmd,opts,upload,spec){const loaded=await loadLocalRunDefinition(opts.files??[],opts.input,void 0,{spec});try{const org=await resolveOrg(cmd,loaded.org);if(upload)await confirmOrAbort("Run these cases now?",opts.yes);await uploadLocalInputs(createClient(),org,loaded.uploads);return{definition:loaded.definition,org,inputSnapshots:loaded.inputSnapshots,unattachedInputs:loaded.unattachedInputs}}finally{await loaded.cleanup()}}function printPlan2(result){console.log(`Definition: ${result.source.verification==="LOCAL"?"current files":result.source.commit}`);console.log(`Expected sessions: ${result.expectedRuns}`);for(const item of result.cases)console.log(` ${item.path}: ${item.expectedRuns} sessions, ${item.preference?`${item.preference.kind} preference (advisory)`:`${item.criteriaCount} criteria`}`);for(const resource of result.resources){const use=resource.use;if(use.type==="npm-package"||use.type==="npm-cli"){const install=use.install??"environment";console.log(` ${resource.name}: npm package \u2192 ${install}`);const label=install==="environment"?"Commands on PATH":"Package commands";console.log(` ${label}: ${resource.commands===void 0?"determined when the input is prepared":resource.commands.join(", ")||"none (library)"}`)}else if(use.type==="binary"){console.log(` ${resource.name}: native executable \u2192 ${use.platform}`);console.log(` Commands on PATH: ${Object.keys(use.commands).join(", ")}`);console.log(" Requires compatible system libraries; Gauge does not install OS packages.")}else console.log(` ${resource.name}: ${use.type}`);if(resource.detail)console.log(` ${resource.detail}`)}if(result.resources.length){console.log(`Inputs: ${result.resources.map(r=>`${r.name} (${r.source}, ${r.readiness})`).join(", ")}`);if(!result.canRun)console.log("Resolve the input errors before launching.")}printInputSnapshots(result.inputSnapshots);printUnattachedInputs(result.unattachedInputs,false)}function printInputSnapshots(snapshots){for(const input of snapshots){console.log(` ${input.name}: ${input.source==="working-tree"?"working-tree snapshot":"local path override snapshot"}`);console.log(` Source path: ${input.path}`);const shown=input.files.slice(0,10);console.log(` Files (${input.fileCount}): ${shown.join(", ")}${input.fileCount>shown.length?`, and ${input.fileCount-shown.length} more`:""}`);console.log(` Gauge archive digest: ${input.gaugeArchive.sha256}`);console.log(` Gauge archive bytes: ${input.gaugeArchive.bytes}`)}if(snapshots.length)console.log("Gauge archive hashes identify delivery archives containing the selected files. For npm inputs, the archive contains the .tgz; its hash and size differ from the .tgz itself. Launching again snapshots current files.")}function unattachedNote(names,saved){return`Not attached: ${names.join(", ")}. ${saved?`Saved measurements attach only inputs passed at launch; add ${names.map(name=>`--input ${name}`).join(" ")} to attach.`:`The selected cases do not use ${names.length===1?"it":"them"}.`}`}function printUnattachedInputs(names,saved){if(names.length)console.log(unattachedNote(names,saved))}async function launch(cmd,opts){if(opts.profile&&gaugeState(cmd).mode!=="local")throw new CliError("usage","--profile applies only to local runs. Pass --local.");const sources=[opts.eval!==void 0&&"--eval",opts.preference!==void 0&&"--preference",opts.apply!==void 0&&"--apply"].filter(flag=>Boolean(flag));const source=sources[0];if(opts.schema||opts.example){const flag=opts.schema?"--schema":"--example";if(source||opts.schema&&opts.example)throw new CliError("usage",`${flag} prints and exits; pass it alone`);const cases=opts.format!=="battery";if(opts.schema)printJson(cases?CASE_SPEC_SCHEMA():BATTERY_SCHEMA());else{printJson(cases?EXAMPLE_CASE_SPEC:EXAMPLE_SPEC);console.error(cases?"\n# Case spec: eval cases as JSON. Save to cases.json, edit, then: gauge run --apply cases.json":"\n# Battery spec: saved prompts and schedules. Save to battery.json, edit, then: gauge run --apply battery.json\n# For eval cases as JSON (criteria, inputs): gauge run --example --format case")}return}if(opts.format)throw new CliError("usage","--format applies with --schema or --example");if(sources.length>1)throw new CliError("usage",`pass only one of ${sources.join(", ")}`);if(opts.verify){const extra=[source,opts.dryRun&&"--dry-run",opts.files!==void 0&&"--files",opts.input.length>0&&"--input"].filter(Boolean);if(extra.length>0)throw new CliError("usage",`--verify checks the eval files in this repo; drop ${extra.join(", ")}`);const result2=verifyEvals(void 0,{local:gaugeState(cmd).mode==="local"});if(resolveOutput(cmd)==="json")printJson(result2);else printEvalVerification(result2);if(result2.summary.no>0)process.exitCode=1;return}if(opts.scenario.length>0&&source!=="--preference")throw new CliError("usage","--scenario applies with --preference only");if((opts.agent.length>0||opts.samples!==void 0)&&source!=="--eval"&&source!=="--preference")throw new CliError("usage","--agent and --samples apply with --eval or --preference; eval case files set them in their front matter");if(opts.files!==void 0&&source)throw new CliError("usage",`--files applies to this repo's eval cases; drop ${source}`);if(opts.input.length>0&&(opts.eval!==void 0||opts.preference!==void 0)&&gaugeState(cmd).mode!=="local")throw new CliError("usage",`Hosted saved measurements do not take project inputs; drop --input or pass --local`,{hint:"For hosted project inputs, use eval case files or a case spec."});if(opts.requireExperiment!==void 0&&!opts.apply)throw new CliError("usage","--require-experiment applies with --apply");let spec;if(opts.apply!==void 0){const json=await readSpecJson(opts.apply);if(!isCaseSpec(json)){if(gaugeState(cmd).mode==="local")throw new CliError("usage","Battery specs (with `prompts`) run on hosted Gauge only.",{hint:"For local runs, pass a case spec (with `cases`): `gauge run --example --format case`. Or pass --hosted."});if(opts.input.length>0)throw new CliError("usage","--input applies to case specs, not battery specs");await applySpec(cmd,parseSpec(json),{dryRun:opts.dryRun,requireExperiment:opts.requireExperiment});return}if(opts.requireExperiment!==void 0)throw new CliError("usage","--require-experiment applies to battery specs, not case specs");spec=parseCaseSpec(json)}if(gaugeState(cmd).mode==="local"&&(opts.eval||opts.preference)){const saved=localMeasurementSpec(cmd,opts.eval?"eval":"preference",opts.eval??opts.preference,{...opts,inputs:[...parseInputBindings(opts.input).keys()]});await runLocalCases(cmd,opts,saved.spec,saved.measurement);return}if(opts.dryRun&&source&&!spec)throw new CliError("usage",`--dry-run previews this repo's eval cases or an --apply spec; drop ${source}`);if(opts.eval!==void 0||opts.preference!==void 0)requireHosted(cmd);if(opts.eval!==void 0){await runEvalSet(cmd,opts.eval,opts);return}if(opts.preference!==void 0){await runPreferencePrompt(cmd,opts.preference,opts);return}if(gaugeState(cmd).mode==="local"){await runLocalCases(cmd,opts,spec);return}const{definition,org,inputSnapshots,unattachedInputs}=await loadWorkingTree(cmd,opts,!opts.dryRun,spec);const orgPath=`/api/v1/orgs/${encodeURIComponent(org)}/run-definitions`;if(opts.dryRun){const result2=await createClient().post(`${orgPath}/plan`,definition);const preview={...result2,inputSnapshots,unattachedInputs};if(resolveOutput(cmd)==="json")printJson(preview);else printPlan2(preview);return}const result=await createClient().post(`${orgPath}/run`,definition);if(resolveOutput(cmd)==="json")printJson(result);else{console.log(`Started ${result.createdRuns}/${result.requestedRuns} sessions in request ${result.runRequestId}`);console.log(`Wait: gauge --org ${org} run wait ${result.runRequestId}`)}}async function runLocalCases(cmd,opts,spec,measurement){const{root}=gaugeState(cmd);if(!root)throw new CliError("usage","Local runs need a Gauge workspace. Run `gauge init` in this directory first.");const local=await loadLocalRunDefinition(opts.files??[],opts.input,process.cwd(),{local:true,spec});const json=resolveOutput(cmd)==="json";if(measurement&&local.unattachedInputs.length&&!opts.dryRun)console.error(`note: ${unattachedNote(local.unattachedInputs,true)}`);if(opts.dryRun){try{const plan={...await planLocal(local.definition,{profile:opts.profile,runtimeImage:opts.runtimeImage,gatewayImage:opts.gatewayImage}),inputSnapshots:local.inputSnapshots,webFixtures:Object.fromEntries(Object.entries(local.webFixtures).map(([path,{fixture,digest}])=>[path,{digest,pages:fixture.pages.map(p=>p.url),scopes:fixture.scopes??[],origins:fixture.origins??[]}])),unattachedInputs:local.unattachedInputs};if(json)printJson(plan);else printLocalPlan(plan,measurement!==void 0)}finally{await local.cleanup()}return}if(opts.detach){try{const detached=await detachLocal(local.definition,local.uploads,join12(root,".gauge"),{profile:opts.profile,runtimeImage:opts.runtimeImage,gatewayImage:opts.gatewayImage,measurement});if(json)printJson(detached);else console.log(`Batch ${detached.batchId} detached.
|
|
754
787
|
Status: ${detached.status}
|
|
755
788
|
Wait: ${detached.wait}
|
|
756
|
-
Stop: ${detached.stop}`)}finally{await local.cleanup()}return}let batch;try{batch=await runLocal(local.definition,local.uploads,join12(root,".gauge"),run=>{if(!json)console.error(`${run.id} ${run.agent} ${run.model} ${run.case}: ${run.outcome}${run.detail?` (${run.detail})`:""}`)},{measurement,profile:opts.profile,runtimeImage:opts.runtimeImage,onStart:batchId=>console.error(`Batch ${batchId}
|
|
789
|
+
Stop: ${detached.stop}`)}finally{await local.cleanup()}return}let batch;try{batch=await runLocal(local.definition,local.uploads,join12(root,".gauge"),run=>{if(!json)console.error(`${run.id} ${run.agent} ${run.model} ${run.case}: ${run.outcome}${run.detail?` (${run.detail})`:""}`)},{measurement,profile:opts.profile,runtimeImage:opts.runtimeImage,gatewayImage:opts.gatewayImage,onStart:batchId=>console.error(`Batch ${batchId}
|
|
757
790
|
Status: gauge run status --batch ${batchId} --local
|
|
758
791
|
Wait: gauge run wait --batch ${batchId} --local
|
|
759
|
-
Stop: gauge run cancel --batch ${batchId} --local`)})}finally{await local.cleanup()}if(batch.canceled&&!process.exitCode)process.exitCode=130;if(!process.exitCode&&batch.runs.some(run=>run.outcome!=="completed"))process.exitCode=1;if(json){printJson(batch);return}const counts=new Map;for(const run of batch.runs)counts.set(run.outcome,(counts.get(run.outcome)??0)+1);console.log(`Batch ${batch.batchId}: ${batch.runs.length} runs. ${[...counts].map(([outcome,n])=>`${n} ${outcome}`).join(", ")}.`);console.log(`Results: .gauge/runs (gauge run list --local --batch ${batch.batchId})`);console.log("");console.log(batch.next)}function printLocalPlan(plan,saved){console.log(`Local plan: ${plan.expectedSessions} session${plan.expectedSessions===1?"":"s"} in local Docker. Nothing started.`);console.log(`Runtime: ${plan.runtime.reference}${plan.runtime.imageId?` (${plan.runtime.imageId})`:""}. Compatibility probe runs at launch.`);for(const item of plan.cases)console.log(` ${item.path}: ${item.sessions.map(s=>`${s.agent} ${s.model} \xD7${s.samples}`).join(", ")}; ${item.criteria} criteria`);console.log(`Inputs: ${plan.inputs.map(i=>`${i.name} (${i.use})`).join(", ")||"none"}`);printInputSnapshots(plan.inputSnapshots);printUnattachedInputs(plan.unattachedInputs,saved);for(const warning of plan.warnings)console.log(`Warning: ${warning}`);console.log("Run it: the same command without --dry-run.")}var WAIT_POLL_MS=5e3;var LOCAL_WAIT_POLL_MS=2e3;function runRequestPath(cmd,id){return`/api/v1/orgs/${encodeURIComponent(resolveOrg(cmd))}/run-requests/${encodeURIComponent(id)}`}function printRunRequest(result){const{counts}=result;const measured=counts.measuredRuns??0;if(!result.settled)console.log(`${result.status}: ${counts.terminalRuns}/${counts.createdRuns} sessions finished, ${counts.judgedRuns} judged, ${counts.pendingRuns} pending`);else console.log(measured>0?`${result.result}: ${measured} preference sessions measured${counts.passedRuns?`; ${counts.passedRuns} experience sessions passed`:""}`:`${result.result}: ${counts.passedRuns}/${counts.createdRuns} passed sessions (${counts.judgedRuns} judged)`);for(const batch of result.batches)for(const run of batch.runs)console.log(` ${run.id} ${run.agent} ${run.model||"(default)"}: ${run.preference?`${preferenceSelectionLabel(run.preference)} (advisory)`:run.result}`);console.log(`Request: ${result.id}`)}function failsCheck(result){return result.result!=="PASSED"&&result.result!=="MEASURED"}async function waitForRequest(cmd,id,opts){const path=runRequestPath(cmd,id);const client=createClient();const json=resolveOutput(cmd)==="json";let lastStatus="";while(true){const result=await client.get(path);if(!json&&result.status!==lastStatus){console.error(`Run request ${id}: ${result.status}`);lastStatus=result.status}if(result.settled){if(json)printJson(result);else printRunRequest(result);if(opts.check&&failsCheck(result))process.exitCode=1;return}await new Promise(resolve6=>setTimeout(resolve6,WAIT_POLL_MS))}}async function waitForLocalBatch(cmd,gaugeDir,batchId,opts){const json=resolveOutput(cmd)==="json";let lastFinished=-1;while(true){let batch;try{batch=await localBatchStatus(gaugeDir,batchId)}catch(error){if(error.code==="ENOENT")throw new CliError("not_found","Local batch not found");throw error}const settled=batch.state!=="queued"&&batch.state!=="running";if(!json&&!settled&&batch.finishedSessions!==lastFinished){console.error(`Batch ${batchId}: ${batch.finishedSessions??0}/${batch.expectedSessions} finished`);lastFinished=batch.finishedSessions}if(settled){const runs=await localStatus(gaugeDir,{batch:batchId});if(json)printJson({batch,runs,next:analysisNext(batchId)});else{printLocalStatus(batch,runs);console.log(analysisNext(batchId))}if(opts.check&&(batch.state!=="completed"||runs.some(run=>run.state!=="completed")))process.exitCode=1;return}await new Promise(resolve6=>setTimeout(resolve6,LOCAL_WAIT_POLL_MS))}}function printLocalStatus(batch,runs){if(batch)console.log(`Batch ${batch.batchId}: ${batch.state}; ${batch.finishedSessions??0}/${batch.expectedSessions} finished`);for(const run of runs){console.log(`${run.id}: ${run.state}${run.cleanupPending?" (cleanup pending)":""}${run.detail?` (${run.detail})`:""}`);if(run.stderrLog)console.log(` agent stderr: ${relative6(process.cwd(),run.stderrLog)}`)}}function register28(program2){const run=program2.command("run").description("Start runs and read them. With no flag: run this repo's eval cases (gauge-cases/) (local: in local Docker)").argument("[command]").usage("[options] [command]").option("--eval <id>","run a saved eval set (see `gauge eval`)",once("--eval")).option("--preference <id>","run a saved preference prompt",once("--preference")).option("--scenario <scenarioId>","with --preference: run only this scenario (repeatable)",collect2,[]).option("--agent <agent[:m1,m2]>","with --eval/--preference: run these agents and model pins for this launch only; the stored roster stays (repeatable)",collect2,[]).option("--samples <n>","with --eval/--preference: sessions per agent and model for this launch only (1-50)").option("--apply <file>",'run a JSON spec ("-" for stdin): a case spec (`cases`, both modes) or a battery spec (`prompts`, hosted). See --example').option("--files <paths...>","eval case Markdown paths or globs (default gauge-cases/**/*.md)").option("--input <name[=path]>","attach a gauge.json input; =path or =glob replaces its configured files (repeatable)",collect2,[]).option("--detach","run a local batch in the background; print status and stop commands").option("--profile <profile>","local credential profile; overrides the default for every target").option("--runtime-image <image>","use a compatible custom Docker image for local runs (tag, digest, or image ID)").option("--verify","check this repo's eval files; start no sessions").option("--dry-run","preview this repo's eval cases or an --apply spec; start no sessions").option("--require-experiment <label>","with --apply: fail unless every target resolves to this experiment label").option("--schema","print the JSON Schema of an --apply spec and exit").option("--example","print an example --apply spec and exit").addOption(new Option3("--format <format>","schema/example format (default: case)").choices(["case","battery"])).option("--yes","skip the confirmation").action(async(arg,opts,cmd)=>{if(arg!==void 0)throw new CliError("usage",`unknown run command "${arg}". Launch a saved eval set or preference prompt with \`gauge run --eval <id>\` or \`--preference <id>\`; read runs with \`gauge run list\` or \`gauge run get <id> [--logs]\`.`);if(opts.detach&&(gaugeState(cmd).mode!=="local"||opts.dryRun||opts.verify||opts.schema||opts.example))throw new CliError("usage","--detach requires a local run");if(opts.runtimeImage&&gaugeState(cmd).mode!=="local")throw new CliError("usage","--runtime-image works only on local runs; pass --local");await launch(cmd,opts)});run.hook("preAction",(parent,action)=>{if(action===parent)return;const allowed=action.name()==="list"?["eval","preference","agent"]:[];const stray=Object.entries(parent.opts()).filter(([key,value])=>!allowed.includes(key)&&value!==void 0&&!(Array.isArray(value)&&value.length===0)).map(([key])=>`--${key.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`)}`);if(stray.length>0)throw new CliError("usage",`${stray.join(", ")} ${stray.length===1?"is a launch flag":"are launch flags"}; \`gauge run ${action.name()}\` does not take ${stray.length===1?"it":"them"}`)});run.command("list").description("List runs (newest first). Filters combine. --preference <id> lists one prompt's runs with verdicts and takes no other filter. Local: runs in .gauge/").option("--eval <id>","filter by eval set (local: by eval)").option("--preference <id>","one preference prompt's runs with verdicts (no other filter)").option("--status <status>","filter by status, e.g. running,queued (local: completed,failed)").option("--batch <id>","filter by batch").option("--prompt <id>","filter by prompt").option("--experiment <experiment>","filter by experiment label").option("--since <window>","e.g. 24h, 7d, or an ISO date").option("--agent <agent>","filter by agent (local only)").option("--model <model>","filter by model (local only)").option("--unanalyzed","only runs without a published analysis (local only)").option("--limit <n>","page size (1-200)","50").option("--cursor <cursor>","resume from a previous page's nextCursor").action(async(_opts,command)=>{const opts=command.optsWithGlobals();const agents=[opts.agent??[]].flat();if(agents.length>1)throw new CliError("usage","pass one --agent to filter by");const agent=agents[0];const output=resolveOutput(command);const state=gaugeState(command);if(state.mode==="local"){if(opts.prompt||opts.experiment||opts.cursor)throw new CliError("usage","Local run list does not support --prompt, --experiment, or --cursor. Use --eval or --preference to select a saved measurement.");const items=state.root?listLocalRuns(join12(state.root,".gauge"),{batch:opts.batch,evalId:opts.eval,preferenceId:opts.preference,agent:agent?parseAgents(agent)[0]:void 0,model:opts.model,outcome:opts.status,since:opts.since?parseSince(opts.since):void 0,analyzed:opts.unanalyzed?false:void 0}).slice(0,Number(opts.limit)):[];if(output==="json")printJson({items});else printItems(items.map(toLocalRow),"table");return}const localOnly=[agent!==void 0&&"--agent",opts.model!==void 0&&"--model",opts.unanalyzed&&"--unanalyzed"].filter(Boolean);if(localOnly.length>0)throw new CliError("usage",`${localOnly.join(", ")} ${localOnly.length===1?"works":"work"} only on local runs; pass --local`);if(opts.preference!==void 0){const filters=[opts.eval!==void 0&&"--eval",opts.status!==void 0&&"--status",opts.batch!==void 0&&"--batch",opts.prompt!==void 0&&"--prompt",opts.experiment!==void 0&&"--experiment",opts.since!==void 0&&"--since"].filter(Boolean);if(filters.length>0)throw new CliError("usage",`--preference lists one prompt's runs and takes no other filter; drop ${filters.join(", ")}`);await listPreferencePromptRuns(command,opts.preference,opts);return}const org=resolveOrg(command);const page=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/runs`,{status:opts.status,batch:opts.batch,prompt:opts.prompt,experiment:opts.experiment,evalSet:opts.eval,since:opts.since,limit:opts.limit,cursor:opts.cursor});if(output==="json"){printJson(page);return}printItems(page.items.map(toRow4),"table");if(page.nextCursor){console.error(`(more results \u2014 rerun with --cursor ${page.nextCursor})`)}});run.command("get <id>").description("Show a run (status, trigger source, cost, credits, turns, exit reason). --logs prints its trace events instead").option("--logs","print the trace events so far, then exit").action(async(id,opts,command)=>{if(gaugeState(command).mode==="local"){const dir=localDirectory(command);const session=withLocalStore(command,store=>store.getSession(id));if(!session)throw new CliError("usage",`Local run ${id} was not found. Use gauge run repair --local if its artifacts exist.`);if(opts.logs){const path=join12(dir,"runs",session.id,"attempts",String(session.attempt),"session","events.ndjson");if(!existsSync5(path))throw new CliError("usage","This run has no transcript artifact yet.");process.stdout.write(readFileSync11(path,"utf8"))}else printJson({...session,analysis:getLocalAnalysis(dir,id)});return}if(opts.logs){await streamRun(id,resolveOutput(command)==="json",{idleMs:2e3,firstEventMs:15e3,stopAtLiveMs:Date.now()-2e3});return}const run2=await createClient().get(runPath(id));if(resolveOutput(command)==="json"){printJson(run2);return}const lines=detailLines(run2);const width=Math.max(...lines.map(([label])=>label.length));for(const[label,value]of lines){console.log(`${label.padEnd(width)} ${value}`)}});run.command("insight <id>").description("Show the run's findings, criteria, and product decisions").action(async(id,_opts,command)=>{if(gaugeState(command).mode==="local"){const dir=localDirectory(command);if(!withLocalStore(command,store=>store.getSession(id)))throw new CliError("usage",`Local run ${id} was not found.`);const analysis2=getLocalAnalysis(dir,id);if(resolveOutput(command)==="json")printJson({runId:id,analysis:analysis2});else console.log(analysis2?renderLocalAnalysisMarkdown(analysis2):"No analysis published. Follow gauge instructions session-analysis --local.");return}const insight=await createClient().get(`${runPath(id)}/insight`);if(resolveOutput(command)==="json"){printJson(insight);return}printInsight(insight)});const analysis=run.command("analysis").description("Publish structured analysis from your coding agent");analysis.command("schema").description("Print the versioned analysis submission schema").action(()=>printJson(z14.toJSONSchema(analysisSubmissionSchema)));analysis.command("save <id>").description("Validate and publish analysis for a local session attempt").requiredOption("--file <path>","analysis JSON file").action((id,opts,command)=>{if(gaugeState(command).mode!=="local")throw new CliError("usage","Analysis submission is available locally; hosted Gauge publishes its own analysis. Use --local.");let input;try{input=JSON.parse(readFileSync11(opts.file,"utf8"))}catch(error){throw new CliError("usage",`Cannot read analysis JSON: ${String(error)}`)}const dir=localDirectory(command);const saved=saveLocalAnalysis(dir,id,input);const results=join12(dir,"runs",saved.runId,"results");try{mkdirSync2(results,{recursive:true});writeFileSync2(join12(results,"session-analysis.md"),renderLocalAnalysisMarkdown(saved))}catch(error){console.error(`Analysis ${saved.id} was published in SQLite, but its Markdown report could not be written: ${String(error)}. Read it with gauge run insight ${id} --local.`)}if(resolveOutput(command)==="json")printJson(saved);else console.log(`Published analysis ${saved.id} (revision ${saved.revision}); ${saved.findings.length} findings. Read with gauge run insight ${id} --local.`)});run.command("repair").description("Rebuild local session summaries from artifacts; preserve saved measurements and analysis").action((_opts,command)=>{if(gaugeState(command).mode!=="local")throw new CliError("usage","Session repair is local only; pass --local.");printJson(withLocalStore(command,store=>store.repairSessionSummaries()))});hostedOnly(run.command("regrade <id>")).description("Re-judge using current eval criteria or the run's criteria snapshot (no new session)").action(async(id,_opts,command)=>{const result=await createClient().post(`${runPath(id)}/regrade`);if(resolveOutput(command)==="json"){printJson(result);return}console.log(`Re-judging run ${result.runId} against ${result.criteria} ${result.criteria===1?"criterion":"criteria"} ${result.evalSetId?`of eval ${result.evalSetId}`:"from its launch-time snapshot"}.`);console.log("Verdicts land on the run; `gauge run get <id>` to check.")});hostedOnly(run.command("watch <id>")).description("Stream normalized trace events live (SSE; exits when the run finishes)").action(async(id,_opts,command)=>{await streamRun(id,resolveOutput(command)==="json",{idleMs:0,firstEventMs:0,pollStatus:true})});run.command("diff <id>").description("Print the run's working-tree diff to stdout").action(async(id,_opts,command)=>{if(gaugeState(command).mode==="local"){const session=withLocalStore(command,store=>store.getSession(id));if(!session)throw new CliError("usage",`Local run ${id} was not found.`);const path=join12(localDirectory(command),"runs",session.id,"attempts",String(session.attempt),"session","diff.patch");if(existsSync5(path))process.stdout.write(readFileSync11(path,"utf8"));else console.error("(no diff)");return}const diff2=await createClient().get(`${runPath(id)}/diff`);if(!diff2){console.error("(no diff)");return}process.stdout.write(diff2)});run.command("status [id]").description("Print a launch request's progress once, without waiting; local: live session status and batch progress").option("--batch <batch-id>","show this local batch").action(async(id,opts,command)=>{const state=gaugeState(command);if(state.mode!=="local"){if(!id||opts.batch)throw new CliError("usage","Hosted status requires a request ID; --batch is local only");const result=await createClient().get(runRequestPath(command,id));if(resolveOutput(command)==="json")printJson(result);else printRunRequest(result);return}if(!state.root)throw new CliError("usage","Run this command inside the batch's Gauge workspace");if(id&&opts.batch)throw new CliError("usage","Pass a run ID or --batch, not both");const gaugeDir=join12(state.root,".gauge");const runs=await localStatus(gaugeDir,{id,batch:opts.batch});let batch;if(opts.batch){try{batch=await localBatchStatus(gaugeDir,opts.batch)}catch(error){if(error.code!=="ENOENT")throw error}}if((id||opts.batch)&&!runs.length&&!batch)throw new CliError("not_found","Local run or batch not found");if(resolveOutput(command)==="json")printJson({batch,runs});else printLocalStatus(batch,runs)});run.command("cancel [id]").option("--batch <batch-id>","cancel an entire local batch, including queued sessions").description("Request cancellation of a run").action(async(id,opts,command)=>{const state=gaugeState(command);if(state.mode==="local"){if(!state.root)throw new CliError("usage","Run this command inside the batch's Gauge workspace");const results=await cancelLocal(join12(state.root,".gauge"),{id,batch:opts.batch});if(results.some(r=>r.status==="pending"))process.exitCode=1;if(resolveOutput(command)==="json")printJson({cancelRequested:true,runs:results});else{console.log(`Cancellation requested for ${opts.batch??id}.`);for(const result2 of results)console.log(`${result2.id}: ${result2.status}${"detail"in result2?` (${result2.detail})`:""}`)}return}if(!id||opts.batch)throw new CliError("usage","Hosted cancellation requires a run ID; --batch is local only");const result=await createClient().post(`${runPath(id)}/cancel`);if(resolveOutput(command)==="json"){printJson(result);return}console.log(`Run ${result.id}: ${result.status}${result.cancelRequested?" (cancel requested)":""}`);if(result.note)console.error(result.note)});run.command("compare").description("Compare two sets of runs: pass rate, criteria, and median turns, cost, and duration, per agent and model. Local: completed runs and median turns").requiredOption("--baseline <key=value>","baseline runs (repeatable): request=, batch=, eval=, revision=, experiment=, trial=, agent=, model=, since=, until= (local: batch=, eval=<saved id>, revision=<number>, agent=, model=, since=, until=)",collect2,[]).requiredOption("--candidate <key=value>","candidate runs (repeatable), same keys as --baseline",collect2,[]).addHelpText("after",`
|
|
792
|
+
Stop: gauge run cancel --batch ${batchId} --local`)})}finally{await local.cleanup()}if(batch.canceled&&!process.exitCode)process.exitCode=130;if(!process.exitCode&&batch.runs.some(run=>run.outcome!=="completed"))process.exitCode=1;if(json){printJson(batch);return}const counts=new Map;for(const run of batch.runs)counts.set(run.outcome,(counts.get(run.outcome)??0)+1);console.log(`Batch ${batch.batchId}: ${batch.runs.length} runs. ${[...counts].map(([outcome2,n])=>`${n} ${outcome2}`).join(", ")}.`);console.log(`Results: .gauge/runs (gauge run list --local --batch ${batch.batchId})`);console.log("");console.log(batch.next)}function printLocalPlan(plan,saved){console.log(`Local plan: ${plan.expectedSessions} session${plan.expectedSessions===1?"":"s"} in local Docker. Nothing started.`);console.log(`Runtime: ${plan.runtime.reference}${plan.runtime.imageId?` (${plan.runtime.imageId})`:""}. Compatibility probe runs at launch.`);if(plan.gateway)console.log(`Gateway: ${plan.gateway.reference}${plan.gateway.imageId?` (${plan.gateway.imageId})`:""}`);for(const item of plan.cases)console.log(` ${item.path}: ${item.sessions.map(s=>`${s.agent} ${s.model} \xD7${s.samples}`).join(", ")}; ${item.criteria} criteria`);console.log(`Inputs: ${plan.inputs.map(i=>`${i.name} (${i.use})`).join(", ")||"none"}`);printInputSnapshots(plan.inputSnapshots);printUnattachedInputs(plan.unattachedInputs,saved);for(const warning of plan.warnings)console.log(`Warning: ${warning}`);console.log("Run it: the same command without --dry-run.")}var WAIT_POLL_MS=5e3;var LOCAL_WAIT_POLL_MS=2e3;async function runRequestPath(cmd,id){return`/api/v1/orgs/${encodeURIComponent(await resolveOrg(cmd))}/run-requests/${encodeURIComponent(id)}`}function printRunRequest(result){const{counts}=result;const measured=counts.measuredRuns??0;if(!result.settled)console.log(`${result.status}: ${counts.terminalRuns}/${counts.createdRuns} sessions finished, ${counts.judgedRuns} judged, ${counts.pendingRuns} pending`);else console.log(measured>0?`${result.result}: ${measured} preference sessions measured${counts.passedRuns?`; ${counts.passedRuns} experience sessions passed`:""}`:`${result.result}: ${counts.passedRuns}/${counts.createdRuns} passed sessions (${counts.judgedRuns} judged)`);for(const batch of result.batches)for(const run of batch.runs)console.log(` ${run.id} ${run.agent} ${run.model||"(default)"}: ${run.preference?`${preferenceSelectionLabel(run.preference)} (advisory)`:run.result}`);console.log(`Request: ${result.id}`)}function failsCheck(result){return result.result!=="PASSED"&&result.result!=="MEASURED"}async function waitForRequest(cmd,id,opts){const path=await runRequestPath(cmd,id);const client=createClient();const json=resolveOutput(cmd)==="json";let lastStatus="";while(true){const result=await client.get(path);if(!json&&result.status!==lastStatus){console.error(`Run request ${id}: ${result.status}`);lastStatus=result.status}if(result.settled){if(json)printJson(result);else printRunRequest(result);if(opts.check&&failsCheck(result))process.exitCode=1;return}await new Promise(resolve5=>setTimeout(resolve5,WAIT_POLL_MS))}}async function waitForLocalBatch(cmd,gaugeDir,batchId,opts){const json=resolveOutput(cmd)==="json";let lastFinished=-1;while(true){let batch;try{batch=await localBatchStatus(gaugeDir,batchId)}catch(error){if(error.code==="ENOENT")throw new CliError("not_found","Local batch not found");throw error}const settled=batch.state!=="queued"&&batch.state!=="running";if(!json&&!settled&&batch.finishedSessions!==lastFinished){console.error(`Batch ${batchId}: ${batch.finishedSessions??0}/${batch.expectedSessions} finished`);lastFinished=batch.finishedSessions}if(settled){const runs=await localStatus(gaugeDir,{batch:batchId});if(json)printJson({batch,runs,next:analysisNext(batchId)});else{printLocalStatus(batch,runs);console.log(analysisNext(batchId))}if(opts.check&&(batch.state!=="completed"||runs.some(run=>run.state!=="completed")))process.exitCode=1;return}await new Promise(resolve5=>setTimeout(resolve5,LOCAL_WAIT_POLL_MS))}}function printLocalStatus(batch,runs){if(batch)console.log(`Batch ${batch.batchId}: ${batch.state}; ${batch.finishedSessions??0}/${batch.expectedSessions} finished`);for(const run of runs){console.log(`${run.id}: ${run.state}${run.cleanupPending?" (cleanup pending)":""}${run.detail?` (${run.detail})`:""}`);if(run.stderrLog)console.log(` agent stderr: ${relative6(process.cwd(),run.stderrLog)}`)}}function register29(program2){const run=program2.command("run").description("Start runs and read them. With no flag: run this repo's eval cases (gauge-cases/) (local: in local Docker)").argument("[command]").usage("[options] [command]").option("--eval <id>","run a saved eval set (see `gauge eval`)",once("--eval")).option("--preference <id>","run a saved preference prompt",once("--preference")).option("--scenario <scenarioId>","with --preference: run only this scenario (repeatable)",collect5,[]).option("--agent <agent[:m1,m2]>","with --eval/--preference: run these agents and model pins for this launch only; the stored roster stays (repeatable)",collect5,[]).option("--samples <n>","with --eval/--preference: sessions per agent and model for this launch only (1-50)").option("--apply <file>",'run a JSON spec ("-" for stdin): a case spec (`cases`, both modes) or a battery spec (`prompts`, hosted). See --example').option("--files <paths...>","eval case Markdown paths or globs (default gauge-cases/**/*.md)").option("--input <name[=path]>","attach a gauge.json input; =path or =glob replaces its configured files (repeatable)",collect5,[]).option("--detach","run a local batch in the background; print status and stop commands").option("--profile <profile>","local credential profile; overrides the default for every target").option("--runtime-image <image>","use a compatible custom Docker image for local runs (tag, digest, or image ID)").option("--gateway-image <image>","use a compatible custom gateway image for local web fixtures").option("--verify","check this repo's eval files; start no sessions").option("--dry-run","preview this repo's eval cases or an --apply spec; start no sessions").option("--require-experiment <label>","with --apply: fail unless every target resolves to this experiment label").option("--schema","print the JSON Schema of an --apply spec and exit").option("--example","print an example --apply spec and exit").addOption(new Option4("--format <format>","schema/example format (default: case)").choices(["case","battery"])).option("--yes","skip the confirmation").action(async(arg,opts,cmd)=>{if(arg!==void 0)throw new CliError("usage",`unknown run command "${arg}". Launch a saved eval set or preference prompt with \`gauge run --eval <id>\` or \`--preference <id>\`; read runs with \`gauge run list\` or \`gauge run get <id> [--logs]\`.`);if(opts.detach&&(gaugeState(cmd).mode!=="local"||opts.dryRun||opts.verify||opts.schema||opts.example))throw new CliError("usage","--detach requires a local run");if((opts.runtimeImage||opts.gatewayImage)&&gaugeState(cmd).mode!=="local")throw new CliError("usage","--runtime-image and --gateway-image work only on local runs; pass --local");await launch(cmd,opts)});run.hook("preAction",(parent,action)=>{if(action===parent)return;const allowed=action.name()==="list"?["eval","preference","agent"]:[];const stray=Object.entries(parent.opts()).filter(([key,value])=>!allowed.includes(key)&&value!==void 0&&!(Array.isArray(value)&&value.length===0)).map(([key])=>`--${key.replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`)}`);if(stray.length>0)throw new CliError("usage",`${stray.join(", ")} ${stray.length===1?"is a launch flag":"are launch flags"}; \`gauge run ${action.name()}\` does not take ${stray.length===1?"it":"them"}`)});run.command("list").description("List runs (newest first). Filters combine. --preference <id> lists one prompt's runs with verdicts and takes no other filter. Local: runs in .gauge/").option("--eval <id>","filter by eval set (local: by eval)").option("--preference <id>","one preference prompt's runs with verdicts (no other filter)").option("--status <status>","filter by status, e.g. running,queued (local: completed,failed)").option("--batch <id>","filter by batch").option("--prompt <id>","filter by prompt").option("--experiment <experiment>","filter by experiment label").option("--since <window>","e.g. 24h, 7d, or an ISO date").option("--agent <agent>","filter by agent (local only)").option("--model <model>","filter by model (local only)").option("--unanalyzed","only runs without a published analysis (local only)").option("--limit <n>","page size (1-200)","50").option("--cursor <cursor>","resume from a previous page's nextCursor").action(async(_opts,command)=>{const opts=command.optsWithGlobals();const agents=[opts.agent??[]].flat();if(agents.length>1)throw new CliError("usage","pass one --agent to filter by");const agent=agents[0];const output=resolveOutput(command);const state=gaugeState(command);if(state.mode==="local"){if(opts.prompt||opts.experiment||opts.cursor)throw new CliError("usage","Local run list does not support --prompt, --experiment, or --cursor. Use --eval or --preference to select a saved measurement.");const items=state.root?listLocalRuns(join12(state.root,".gauge"),{batch:opts.batch,evalId:opts.eval,preferenceId:opts.preference,agent:agent?parseAgents(agent)[0]:void 0,model:opts.model,outcome:opts.status,since:opts.since?parseSince(opts.since):void 0,analyzed:opts.unanalyzed?false:void 0}).slice(0,Number(opts.limit)):[];if(output==="json")printJson({items});else printItems(items.map(toLocalRow),"table");return}const localOnly=[agent!==void 0&&"--agent",opts.model!==void 0&&"--model",opts.unanalyzed&&"--unanalyzed"].filter(Boolean);if(localOnly.length>0)throw new CliError("usage",`${localOnly.join(", ")} ${localOnly.length===1?"works":"work"} only on local runs; pass --local`);if(opts.preference!==void 0){const filters=[opts.eval!==void 0&&"--eval",opts.status!==void 0&&"--status",opts.batch!==void 0&&"--batch",opts.prompt!==void 0&&"--prompt",opts.experiment!==void 0&&"--experiment",opts.since!==void 0&&"--since"].filter(Boolean);if(filters.length>0)throw new CliError("usage",`--preference lists one prompt's runs and takes no other filter; drop ${filters.join(", ")}`);await listPreferencePromptRuns(command,opts.preference,opts);return}const org=await resolveOrg(command);const page=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/runs`,{status:opts.status,batch:opts.batch,prompt:opts.prompt,experiment:opts.experiment,evalSet:opts.eval,since:opts.since,limit:opts.limit,cursor:opts.cursor});if(output==="json"){printJson(page);return}printItems(page.items.map(toRow4),"table");if(page.nextCursor){console.error(`(more results \u2014 rerun with --cursor ${page.nextCursor})`)}});run.command("get <id>").description("Show a run (status, trigger source, cost, credits, turns, exit reason). --logs prints its trace events instead").option("--logs","print the trace events so far, then exit").action(async(id,opts,command)=>{if(gaugeState(command).mode==="local"){const dir=localDirectory2(command);const session=withLocalStore(command,store=>store.getSession(id));if(!session)throw new CliError("usage",`Local run ${id} was not found. If its files are still in .gauge/runs, run \`gauge run repair --local\` to restore it to the run list.`);if(opts.logs){const path=join12(dir,"runs",session.id,"attempts",String(session.attempt),"session","events.ndjson");if(!existsSync4(path))throw new CliError("usage","This run has no saved transcript yet.");process.stdout.write(readFileSync11(path,"utf8"))}else printJson({...session,analysis:getLocalAnalysis(dir,id)});return}if(opts.logs){await streamRun(id,resolveOutput(command)==="json",{idleMs:2e3,firstEventMs:15e3,stopAtLiveMs:Date.now()-2e3});return}const run2=await createClient().get(runPath(id));if(resolveOutput(command)==="json"){printJson(run2);return}const lines=detailLines(run2);const width=Math.max(...lines.map(([label])=>label.length));for(const[label,value]of lines){console.log(`${label.padEnd(width)} ${value}`)}});run.command("insight <id>").description("Show the run's findings, criteria, and product decisions").action(async(id,_opts,command)=>{if(gaugeState(command).mode==="local"){const dir=localDirectory2(command);if(!withLocalStore(command,store=>store.getSession(id)))throw new CliError("usage",`Local run ${id} was not found.`);const analysis2=getLocalAnalysis(dir,id);if(resolveOutput(command)==="json")printJson({runId:id,analysis:analysis2});else console.log(analysis2?renderLocalAnalysisMarkdown(analysis2):"No analysis published. Follow gauge instructions session-analysis --local.");return}const insight=await createClient().get(`${runPath(id)}/insight`);if(resolveOutput(command)==="json"){printJson(insight);return}printInsight(insight)});const analysis=run.command("analysis").description("Publish structured analysis from your coding agent");analysis.command("schema").description("Print the versioned analysis submission schema").action(()=>printJson(z12.toJSONSchema(analysisSubmissionSchema)));analysis.command("save <id>").description("Validate and publish analysis for a local session attempt").requiredOption("--file <path>","analysis JSON file").action((id,opts,command)=>{if(gaugeState(command).mode!=="local")throw new CliError("usage","Analysis submission is available locally; hosted Gauge publishes its own analysis. Use --local.");let input;try{input=JSON.parse(readFileSync11(opts.file,"utf8"))}catch(error){throw new CliError("usage",`Cannot read analysis JSON: ${String(error)}`)}const dir=localDirectory2(command);const saved=saveLocalAnalysis(dir,id,input);const results=join12(dir,"runs",saved.runId,"results");try{mkdirSync2(results,{recursive:true});writeFileSync3(join12(results,"session-analysis.md"),renderLocalAnalysisMarkdown(saved))}catch(error){console.error(`Analysis ${saved.id} was published in SQLite, but its Markdown report could not be written: ${String(error)}. Read it with gauge run insight ${id} --local.`)}if(resolveOutput(command)==="json")printJson(saved);else console.log(`Published analysis ${saved.id} (revision ${saved.revision}); ${saved.findings.length} findings. Read with gauge run insight ${id} --local.`)});run.command("repair").description("Restore local runs to the run list from their saved files, keeping measurements and analysis").action((_opts,command)=>{if(gaugeState(command).mode!=="local")throw new CliError("usage","Session repair is local only; pass --local.");printJson(withLocalStore(command,store=>store.repairSessionSummaries()))});hostedOnly(run.command("regrade <id>")).description("Re-judge using current eval criteria or the run's criteria snapshot (no new session)").action(async(id,_opts,command)=>{const result=await createClient().post(`${runPath(id)}/regrade`);if(resolveOutput(command)==="json"){printJson(result);return}console.log(`Re-judging run ${result.runId} against ${result.criteria} ${result.criteria===1?"criterion":"criteria"} ${result.evalSetId?`of eval ${result.evalSetId}`:"from its launch-time snapshot"}.`);console.log("Verdicts land on the run; `gauge run get <id>` to check.")});hostedOnly(run.command("watch <id>")).description("Stream normalized trace events live (SSE; exits when the run finishes)").action(async(id,_opts,command)=>{await streamRun(id,resolveOutput(command)==="json",{idleMs:0,firstEventMs:0,pollStatus:true})});run.command("diff <id>").description("Print the run's working-tree diff to stdout").action(async(id,_opts,command)=>{if(gaugeState(command).mode==="local"){const session=withLocalStore(command,store=>store.getSession(id));if(!session)throw new CliError("usage",`Local run ${id} was not found.`);const path=join12(localDirectory2(command),"runs",session.id,"attempts",String(session.attempt),"session","diff.patch");if(existsSync4(path))process.stdout.write(readFileSync11(path,"utf8"));else console.error("(no diff)");return}const diff2=await createClient().get(`${runPath(id)}/diff`);if(!diff2){console.error("(no diff)");return}process.stdout.write(diff2)});run.command("status [id]").description("Print a launch request's progress once, without waiting; local: live session status and batch progress").option("--batch <batch-id>","show this local batch").action(async(id,opts,command)=>{const state=gaugeState(command);if(state.mode!=="local"){if(!id||opts.batch)throw new CliError("usage","Hosted status requires a request ID; --batch is local only");const result=await createClient().get(await runRequestPath(command,id));if(resolveOutput(command)==="json")printJson(result);else printRunRequest(result);return}if(!state.root)throw new CliError("usage","Run this command inside the batch's Gauge workspace");if(id&&opts.batch)throw new CliError("usage","Pass a run ID or --batch, not both");const gaugeDir=join12(state.root,".gauge");const runs=await localStatus(gaugeDir,{id,batch:opts.batch});let batch;if(opts.batch){try{batch=await localBatchStatus(gaugeDir,opts.batch)}catch(error){if(error.code!=="ENOENT")throw error}}if((id||opts.batch)&&!runs.length&&!batch)throw new CliError("not_found","Local run or batch not found");if(resolveOutput(command)==="json")printJson({batch,runs});else printLocalStatus(batch,runs)});run.command("cancel [id]").option("--batch <batch-id>","cancel an entire local batch, including queued sessions").description("Request cancellation of a run").action(async(id,opts,command)=>{const state=gaugeState(command);if(state.mode==="local"){if(!state.root)throw new CliError("usage","Run this command inside the batch's Gauge workspace");const results=await cancelLocal(join12(state.root,".gauge"),{id,batch:opts.batch});if(results.some(r=>r.status==="pending"))process.exitCode=1;if(resolveOutput(command)==="json")printJson({cancelRequested:true,runs:results});else{console.log(`Cancellation requested for ${opts.batch??id}.`);for(const result2 of results)console.log(`${result2.id}: ${result2.status}${"detail"in result2?` (${result2.detail})`:""}`)}return}if(!id||opts.batch)throw new CliError("usage","Hosted cancellation requires a run ID; --batch is local only");const result=await createClient().post(`${runPath(id)}/cancel`);if(resolveOutput(command)==="json"){printJson(result);return}console.log(`Run ${result.id}: ${result.status}${result.cancelRequested?" (cancel requested)":""}`);if(result.note)console.error(result.note)});run.command("compare").description("Compare two sets of runs: pass rate, criteria, and median turns, cost, and duration, per agent and model. Local: completed runs and median turns").requiredOption("--baseline <key=value>","baseline runs (repeatable): request=, batch=, eval=, revision=, experiment=, trial=, agent=, model=, since=, until= (local: batch=, eval=<saved id>, revision=<number>, agent=, model=, since=, until=)",collect5,[]).requiredOption("--candidate <key=value>","candidate runs (repeatable), same keys as --baseline",collect5,[]).addHelpText("after",`
|
|
760
793
|
${style("1")(" EXAMPLES")}
|
|
761
794
|
gauge run compare --baseline request=<id> --candidate request=<id>
|
|
762
795
|
gauge run compare --baseline eval=<id> --candidate trial=<trialId>
|
|
763
796
|
gauge run compare --baseline eval=<id> --baseline revision=<hash> \\
|
|
764
797
|
--candidate eval=<id> --candidate since=2h
|
|
765
|
-
gauge run compare --local --baseline batch=<id> --candidate batch=<id>`).action(async(opts,cmd)=>{const body={baseline:parseCompareSide("--baseline",opts.baseline),candidate:parseCompareSide("--candidate",opts.candidate)};const state=gaugeState(cmd);let result;let warnings;if(state.mode==="local"){const baseline=localCompareFilter("--baseline",body.baseline);const candidate=localCompareFilter("--candidate",body.candidate);const root=state.root;if(!root)throw new CliError("usage","Local runs need a Gauge workspace. Run `gauge init` in this directory first.");const gaugeDir=join12(root,".gauge");result=compareLocalRuns(listLocalRuns(gaugeDir,baseline),listLocalRuns(gaugeDir,candidate));warnings=localCompareWarnings}else{result=await createClient().post(`/api/v1/orgs/${encodeURIComponent(resolveOrg(cmd))}/runs/compare`,body);warnings=compareWarnings}if(resolveOutput(cmd)==="json"){printJson(result);return}for(const warning of warnings(result))console.error(`Warning: ${warning}`);printComparison(result)});run.command("wait [request-id]").description("Wait for every session and judge in a launch request, then print the verdict. Exits 0 once settled, whatever the verdict. Local: wait for a batch with --batch").option("--batch <batch-id>","wait for this local batch").option("--check","exit 1 unless the verdict is PASSED or MEASURED (for CI gates); local: unless every session completed").action(async(id,opts,cmd)=>{const state=gaugeState(cmd);if(state.mode==="local"){if(!opts.batch||id)throw new CliError("usage","Local wait takes --batch <batch-id>, not a request ID");if(!state.root)throw new CliError("usage","Run this command inside the batch's Gauge workspace");return waitForLocalBatch(cmd,join12(state.root,".gauge"),opts.batch,opts)}if(!id||opts.batch)throw new CliError("usage","Hosted wait requires a request ID; --batch is local only");return waitForRequest(cmd,id,opts)})}var skills_exports={};__export(skills_exports,{buildSkillEditBody:()=>buildSkillEditBody,register:()=>register29});function skillsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/skills`}function skillPath(org,ref){return`${skillsPath(org)}/${encodeURIComponent(ref)}`}function sourceLabel(s){if(!s)return"";const path=s.subpath?`/${s.subpath}`:"";return`${s.repoFullName}${path}#${s.ref}${s.autoIngest?" (auto)":""}`}async function buildSkillEditBody(opts,fetchCurrentSource){if(opts.note!==void 0&&opts.clearNote)throw new CliError("usage","--note and --clear-note conflict");if(opts.source!==void 0&&opts.clearSource)throw new CliError("usage","--source and --clear-source conflict");if(opts.autoIngest!==void 0&&opts.clearSource)throw new CliError("usage","--auto-ingest and --clear-source conflict");let autoIngest;if(opts.autoIngest!==void 0){if(opts.autoIngest!=="true"&&opts.autoIngest!=="false")throw new CliError("usage","--auto-ingest expects true or false");autoIngest=opts.autoIngest==="true"}const body={};if(opts.rename!==void 0)body.name=opts.rename;if(opts.clearNote)body.note=null;else if(opts.note!==void 0)body.note=opts.note;if(opts.clearSource)body.source=null;else if(opts.source!==void 0){const m=opts.source.match(/^([^#]+\/[^#/]+)#([^/]+)(?:\/(.+))?$/);if(!m)throw new CliError("usage",'invalid --source (expected "owner/repo#branch" or "owner/repo#branch/subpath")');body.source={repoFullName:m[1],ref:m[2],subpath:m[3],autoIngest}}else if(autoIngest!==void 0){const current=await fetchCurrentSource();if(!current)throw new CliError("usage","this skill has no tracked source \u2014 set one first with --source owner/repo#branch");body.source={repoFullName:current.repoFullName,ref:current.ref,subpath:current.subpath||void 0,autoIngest}}if(Object.keys(body).length===0)throw new CliError("usage","nothing to change");return body}function register29(program2){const group=hostedOnly(program2.command("skills")).description("Manage agent skills used by eval and preference runs");group.command("list").description("List the org's skills with their newest version").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(skillsPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(s=>({name:s.name,latest:s.latestVersion?.label??"",versions:s.versionCount,source:sourceLabel(s.source),note:s.note??""})),"table")});group.command("get <ref>").description("Show one skill: source, note, every version").action(async(ref,_opts,cmd)=>{const org=resolveOrg(cmd);const skill=await createClient().get(skillPath(org,ref));if(resolveOutput(cmd)==="json"){printJson(skill);return}console.log(`name: ${skill.name}`);console.log(`id: ${skill.id}`);console.log(`note: ${skill.note??"(none)"}`);console.log(`source: ${sourceLabel(skill.source)||"(untracked)"}`);console.log("versions:");for(const v of skill.versions)console.log(` ${skill.name}@${v.label} ${v.contentDigest.slice(0,19)} ${v.createdAt}`)});group.command("add <reference>").description("Ingest a skill from owner/repo[/skill][#ref] or a GitHub URL").option("--as <handle>","the handle (default: the directory basename)").option("--label <label>","version label (a typed label always mints; omitted dedups by digest)").option("--skill <name>","select one skill from a source holding several").option("--note <text>","note shown on the index").option("--track","track the source branch for auto re-ingest (reference must name a branch)").action(async(reference,opts,cmd)=>{const org=resolveOrg(cmd);const result=await createClient().post(skillsPath(org),{reference,handle:opts.as,label:opts.label,skill:opts.skill,note:opts.note,trackSource:opts.track});if(resolveOutput(cmd)==="json"){printJson(result);return}console.log(result.unchanged?`Already current: ${result.handle}@${result.label} carries this content`:`Ingested ${result.handle}@${result.label}`);console.error(`Attach it to an eval: gauge eval edit <id> --skill ${result.handle}@${result.label}`)});group.command("edit <ref>").description("Rename, note, or repoint a skill's tracked source").option("--rename <handle>","new handle (name@label refs must be updated)").option("--note <text>","replace the note").option("--clear-note","remove the note").option("--source <owner/repo#branch[/subpath]>","set the tracked source branch").option("--clear-source","stop tracking the source").option("--auto-ingest <bool>","true|false \u2014 auto re-ingest on new commits").action(async(ref,opts,cmd)=>{const org=resolveOrg(cmd);const client=createClient();const body=await buildSkillEditBody(opts,async()=>{const skill=await client.get(skillPath(org,ref));return skill.source});const updated=await client.patch(skillPath(org,ref),body);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated skill ${updated.name}`)});group.command("reingest <ref>").description("Pull the tracked source now (no-op when already current)").action(async(ref,_opts,cmd)=>{const org=resolveOrg(cmd);const result=await createClient().post(`${skillPath(org,ref)}/reingest`,{});if(resolveOutput(cmd)==="json")printJson(result);else console.log(result.unchanged?"Already current \u2014 nothing new upstream":`Ingested new version ${ref}@${result.label}`)});group.command("rm <ref>").description("Remove a skill; the handle stays reserved and finished runs keep their snapshot").action(async(ref,_opts,cmd)=>{const org=resolveOrg(cmd);const result=await createClient().delete(skillPath(org,ref));if(resolveOutput(cmd)==="json")printJson(result);else console.log(`Deleted skill ${ref} (${result.referencedRuns} finished run(s) referenced it)`)});group.command("runs <ref>").description("Recent sessions that staged this skill").option("--limit <n>","max runs (default 10, cap 50)").action(async(ref,opts,cmd)=>{const org=resolveOrg(cmd);const res=await createClient().get(`${skillPath(org,ref)}/runs`,{limit:opts.limit});if(resolveOutput(cmd)==="json"){printJson(res.items);return}printItems(res.items.map(r=>({id:r.runId,agent:r.agent,version:r.versionLabel??"",turns:r.turns??"",cost:r.costUsd==null?"":`$${r.costUsd.toFixed(2)}`,finished:r.finishedAt??"(running)"})),"table")})}var stats_exports={};__export(stats_exports,{register:()=>register30});function addFilterOptions(cmd){return cmd.option("--prompt <id>","filter to a single prompt").option("--tag <ids>","comma-separated tag ids").option("--repo <urls>","comma-separated base repo urls").option("--language <langs>","comma-separated repo languages").option("--framework <names>","comma-separated repo frameworks").option("--size <buckets>","comma-separated codebase-size buckets").option("--branded","only branded prompts").option("--unbranded","only non-branded prompts").option("--limit <n>","max rows (default 50)").option("--full","return all rows (up to 1000)")}function filterQuery(opts){if(opts.branded&&opts.unbranded){throw new CliError("usage","Pass at most one of --branded / --unbranded.")}return{prompt:opts.prompt,tag:opts.tag,repo:opts.repo,language:opts.language,framework:opts.framework,size:opts.size,branded:opts.branded?"true":opts.unbranded?"false":void 0,limit:opts.full?"1000":opts.limit}}var pct4=rate=>`${(rate*100).toFixed(1)}%`;var delta=d=>d===null||d===0?"\u2014":d>0?`+${d}`:String(d);function noteFreshness2(f){if(!f.available){console.error("warning: analytics store is temporarily unavailable; results may be incomplete.")}else if(f.pending>0){console.error(`note: ${f.pending} recent run(s) still ingesting; results may not reflect them yet.`)}}async function runStats(command,resource,opts,toRow5){const org=resolveOrg(command);const output=resolveOutput(command);const res=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/stats/${resource}`,filterQuery(opts));if(output==="json"){printJson(res);return}printItems(res.items.map(toRow5),"table");noteFreshness2(res.freshness)}var rankingRow=r=>({rank:r.rank,brand:r.brandName,kind:r.kind,installs:r.installs,"install%":pct4(r.installRate),"mention%":pct4(r.mentionRate),delta:delta(r.deltaRank)});var packageRow=r=>({package:r.name,ecosystem:r.ecosystem,brand:r.brandName,kind:r.kind,installs:r.installs,rate:pct4(r.rate)});var brandRow=r=>({brand:r.brandName,kind:r.kind,installs:r.installs,rate:pct4(r.rate)});var funnelRow=r=>({brand:r.brandName,kind:r.kind,"mention%":pct4(r.mentionRate),"install%":pct4(r.installRate)});var domainRow=r=>({domain:r.domain,brand:r.brandName,runs:r.runs,rate:pct4(r.rate),requests:r.requests});function register30(program2){const group=hostedOnly(program2.command("stats")).description("Read-only analytics over your runs");addFilterOptions(group.command("rankings").description("Brands ranked by install rate")).action((opts,command)=>runStats(command,"rankings",opts,rankingRow));addFilterOptions(group.command("installs").description("Package install rates (share of voice)")).action((opts,command)=>runStats(command,"installs",opts,packageRow));addFilterOptions(group.command("brands").description("Per-brand (company-level) install rates")).action((opts,command)=>runStats(command,"brands",opts,brandRow));addFilterOptions(group.command("funnel").description("Per-brand mention rate beside install rate")).action((opts,command)=>runStats(command,"funnel",opts,funnelRow));addFilterOptions(group.command("domains").description("Outbound fetch rates by registrable domain")).action((opts,command)=>runStats(command,"domains",opts,domainRow))}var status_exports={};__export(status_exports,{register:()=>register31});function pct5(rate){return rate==null?"\u2014":`${Math.round(rate*100)}%`}function delta2(pp){if(pp==null)return"";const rounded=Math.round(pp);return rounded===0?"":` (${rounded>0?"+":""}${rounded}pp)`}function register31(program2){hostedOnly(program2.command("status")).description("One-shot org summary: actions, Agent Preference, agent experience").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const s=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/summary`);if(resolveOutput(cmd)==="json"){printJson(s);return}if(!s.hasAnyRuns){console.log("No runs yet. Create an eval (`gauge eval create`) or run one (`gauge run --eval <id>`).");return}console.log(`last synthesis: ${s.lastSynthesisAt??"never"}`);console.log("\nagent experience:");if(!s.agentExperience.ok){console.log(` (unavailable: ${s.agentExperience.error})`)}else if(s.agentExperience.data.cards.length===0){console.log(" (no judged runs in the last 30 days)")}else{for(const card of s.agentExperience.data.cards){console.log(` ${card.name}: ${pct5(card.passRate)}${delta2(card.deltaPP)} over ${card.judgedRuns} judged run(s)`)}const extra=s.agentExperience.data.setCount-s.agentExperience.data.cards.length;if(extra>0)console.log(` (+${extra} more \u2014 see the dashboard)`)}console.log("\nAgent Preference:");if(!s.visibility.ok){console.log(` (unavailable: ${s.visibility.error})`)}else if(s.visibility.data.cards.length===0){console.log(" (no preference runs in the last 30 days)")}else{for(const card of s.visibility.data.cards){const owned=card.owned?`${card.owned.name} #${card.owned.rank}, chosen ${pct5(card.owned.chosenRate)}${delta2(card.chosenDeltaPP)}`:"no owned brand ranked";console.log(` ${card.name}: ${owned}`)}}console.log("\nopen actions:");if(!s.actions.ok){console.log(` (unavailable: ${s.actions.error})`)}else if(s.actions.data.length===0){console.log(" (none)")}else{for(const a of s.actions.data.slice(0,5)){console.log(` [${a.priority}] ${a.title} (${a.id})`)}if(s.actions.data.length>5)console.log(` (+${s.actions.data.length-5} more \u2014 \`gauge actions list\`)`)}})}var tags_exports={};__export(tags_exports,{register:()=>register32});function tagsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/tags`}function register32(program2){const group=hostedOnly(program2.command("tags")).description("Manage org tags");group.command("list").description("List tags").action(async(_opts,cmd)=>{const org=resolveOrg(cmd);const items=await fetchAllPages(createClient(),tagsPath(org));if(resolveOutput(cmd)==="json")printJson(items);else printItems(items,"table")});group.command("add <name>").description("Add a tag").option("--color <color>","palette color (e.g. blue, grape; default gray)").action(async(name,opts,cmd)=>{const org=resolveOrg(cmd);const tag=await createClient().post(tagsPath(org),{name,color:opts.color});if(resolveOutput(cmd)==="json")printJson(tag);else console.log(`Created tag ${tag.id} (${tag.name}, ${tag.color})`)});group.command("rename <tag> <new-name>").description("Rename a tag (by id or current name)").option("--color <color>","also change the color").action(async(tag,newName,opts,cmd)=>{const org=resolveOrg(cmd);const updated=await createClient().patch(`${tagsPath(org)}/${encodeURIComponent(tag)}`,{name:newName,color:opts.color});if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Renamed tag ${updated.id} to ${updated.name} (${updated.color})`)});group.command("rm <tag>").description("Delete a tag (by id or name)").action(async(tag,_opts,cmd)=>{const org=resolveOrg(cmd);await createClient().delete(`${tagsPath(org)}/${encodeURIComponent(tag)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted tag ${tag}`)})}var telemetry_exports={};__export(telemetry_exports,{register:()=>register33});async function printStatus(command){const status=await telemetryStatus();if(command.optsWithGlobals().output==="json"){printJson(status);return}console.log(`CLI telemetry is ${status.enabled?"enabled":"disabled"} (${status.source}).`);if(status.source==="environment")console.log("GAUGE_TELEMETRY_DISABLED=1 overrides the saved preference.");if(status.source==="unavailable")console.log("Preferences could not be read. Collection is disabled until repaired with gauge telemetry enable or disable.")}function register33(program2){const telemetry=program2.command("telemetry").description("Control anonymous CLI usage telemetry (enabled by default)");telemetry.command("status").description("Show whether CLI telemetry is enabled").action(async(_options,command)=>printStatus(command));for(const enabled of[true,false]){telemetry.command(enabled?"enable":"disable").description(`${enabled?"Enable":"Disable"} CLI telemetry for this user`).action(async(_options,command)=>{await setTelemetryEnabled(enabled);await printStatus(command)})}}var update_exports={};__export(update_exports,{register:()=>register34});import{spawnSync as spawnSync2}from"child_process";function register34(program2,{run=spawnSync2,platform=process.platform}={}){program2.command("update").description("Update the globally installed Gauge CLI to the latest version").action((_opts,command)=>{const output=resolveOutput(command);console.error("Updating Gauge CLI to the latest published version...");const result=run(platform==="win32"?"npm.cmd":"npm",["install","--global","@withgauge/cli@latest"],{shell:platform==="win32",stdio:["inherit",output==="json"?2:"inherit","inherit"]});if(result.error||result.status!==0){const reason=result.error?result.error.message:result.signal?`npm was interrupted by ${result.signal}`:`npm exited with code ${result.status}`;throw new CliError("internal",`CLI update failed: ${reason}.
|
|
766
|
-
Retry with: npm install --global @withgauge/cli@latest`)}if(output==="json"){printJson({updated:true,package:"@withgauge/cli",tag:"latest"})}else{console.log("Updated Gauge CLI. Run `gauge --version` to see the installed version.")}})}var usage_exports={};__export(usage_exports,{register:()=>
|
|
767
|
-
`)}})}var EXAMPLES=[["gauge init --local","Initialize a workspace; creates no measurements"],["gauge instructions hillclimb","Choose inputs and prepare a first pilot"],["gauge eval create --help","Save a task and success criteria"],["gauge run --eval <id> --local","Run a saved eval; rerun after input changes"]];var GROUPS=[["Get started",{instructions:"Instructions for coding agents",init:"Initialize a Gauge workspace",local:"Configure local execution","install-skill":"Install the Gauge agent skill",onboard:"Sign in and set up your workspace",status:"One-shot org summary (Gauge account)"}],["Evals (local or hosted)",{eval:"Manage saved evals",preference:"Manage saved preference prompts",run:"Start runs and read them",query:"Query local runs and findings or hosted analytics",cleanup:"Clean interrupted local sessions",models:"List models, harnesses, and providers"}],["Hosted tools (Gauge account)",{personas:"Manage simulated-user personas",skills:"Manage agent skills",mcp:"Manage MCP servers",optimizations:"Find the best change to an owned surface"}],["Insights (Gauge account)",{stats:"Analytics over your runs",dashboards:"Saved dashboards",actions:"Recommended follow-ups"}],["Organization (Gauge account)",{orgs:"List and switch organizations",org:"This org's settings",members:"Team members and invites",repos:"Manage repositories",connections:"Stored credentials (no secrets)",keys:"Manage BYOK provider keys",brands:"Manage org brands",tags:"Manage org tags",billing:"Billing and credits",usage:"Credit ledger entries"}],["Account",{auth:"Sign in, sign out, and tokens",whoami:"Show the signed-in user"}],["CLI",{config:"Manage local CLI config",telemetry:"Enable or disable anonymous CLI usage telemetry",update:"Update to the latest version",feedback:"Send feedback to the Gauge team"}]];function formatIntro(lines,helper,width,code,spaced=false){return lines.flatMap((line,i)=>{const bullet=line.startsWith("- ");const indent=bullet?" ":"";const gap=spaced&&i>0&&!bullet&&!lines[i-1].startsWith("- ")?[""]:[];const text=(bullet?line.slice(2):line).replace(/`([^`]+)`/g,(span,inner)=>{const styled=code(inner);return(styled===inner?span:styled).replaceAll(" ","\0")});return[...gap,...helper.boxWrap(text,width-indent.length).replaceAll("\0"," ").split("\n").map((row2,j)=>(j===0&&bullet?"- ":indent)+row2)]})}function padFor(rows){return Math.max(...rows.map(([term])=>term.length))+2}function formatTable(rows,indent,helper,width,color,pad=padFor(rows)){return rows.flatMap(([term,text])=>{const[first,...rest]=helper.boxWrap(text,width-indent.length-pad).split("\n");const head=`${indent}${color(term.padEnd(pad))}${first}`;if(term.length>=pad)return[`${indent}${color(term)}`,...[first,...rest].map(row2=>indent+" ".repeat(pad)+row2)];return[head,...rest.map(row2=>indent+" ".repeat(pad)+row2)]})}function firstClause(text){return text.split(/[.:;(]| — /)[0].trim()}function formatRootHelp(program2,helper){const bold=style("1");const dim=style("2");const green=style("32");const width=helper.helpWidth??80;const state=readGaugeState(program2.opts());const visible=new Map(helper.visibleCommands(program2).filter(cmd=>cmd.name()!=="help").map(cmd=>[cmd.name(),cmd]));const sections=GROUPS.map(([title,summaries])=>[title,Object.entries(summaries).filter(([name])=>visible.delete(name))]);if(visible.size)sections.push(["Other",[...visible.values()].map(cmd=>[cmd.name(),firstClause(cmd.summary()||cmd.description())])]);const options=helper.visibleOptions(program2).map(option=>[helper.optionTerm(option),firstClause(option.description)]);const table=(rows,indent,pad)=>formatTable(rows,indent,helper,width,green,pad);const commandPad=padFor(sections.flatMap(([,rows])=>rows));const lines=["",`${bold("Gauge CLI")} ${dim(`v${CLI_VERSION}`)}`,"",...formatIntro(program2.description().split(/(?<=\.) /),helper,width,green),"",...formatIntro(["Gauge strongly recommends the gauge-agents skill for coding agents: `gauge install-skill`. It makes Gauge workflow guidance discoverable in future sessions.",...header(state,void 0,true)],helper,width,green,true),"",bold(" EXAMPLES"),...table(EXAMPLES," "),"",bold(" COMMANDS")];for(const[title,rows]of sections){if(!rows.length)continue;lines.push("",bold(` ${title}`),...table(rows," ",commandPad))}lines.push("",bold(" OPTIONS"),...table(options," "),"",` Run ${green("gauge <command> --help")} for details on any command.`,"");return lines.join("\n")}function formatCommandHelp(cmd,helper){const bold=style("1");const green=style("32");const width=helper.helpWidth??80;const path=[];for(let c=cmd;c;c=c.parent)path.unshift(c.name());const name=path.join(" ");const usage=[name,cmd.usage()].join(" ");let root=cmd;while(root.parent)root=root.parent;const rows={ARGUMENTS:helper.visibleArguments(cmd).map(arg=>[helper.argumentTerm(arg),helper.argumentDescription(arg)]),COMMANDS:helper.visibleCommands(cmd).filter(sub=>sub.name()!=="help").map(sub=>[helper.subcommandTerm(sub),helper.subcommandDescription(sub)]),OPTIONS:helper.visibleOptions(cmd).map(option=>[helper.optionTerm(option),helper.optionDescription(option)]),"GLOBAL OPTIONS":helper.visibleGlobalOptions(cmd).filter(option=>root.options.includes(option)&&option.long!=="--version").map(option=>[helper.optionTerm(option),helper.optionDescription(option)])};const pad=Math.min(padFor(Object.values(rows).flat().concat([["",""]])),Math.floor(width/3));const lines=["",bold(name)+(cmd.aliases().length?` (${cmd.aliases().join(", ")})`:"")];const description=helper.commandDescription(cmd);if(description)lines.push("",...formatIntro(description.split("\n"),helper,width-1,green).map(row2=>` ${row2}`));lines.push("",bold(" USAGE"),` ${usage}`);for(const[title,items]of Object.entries(rows)){if(!items.length)continue;lines.push("",bold(` ${title}`),...formatTable(items," ",helper,width,green,pad))}if(rows.COMMANDS.length)lines.push("",` Run ${green(`${name} <command> --help`)} for details on any command.`);const topic=path[1]&&topicForCommand(path[1]);if(topic)lines.push("",` Run ${green(`gauge instructions ${topic}`)} for explicit guidance.`);lines.push("");return lines.join("\n")}function rejectUnknownCommandHelp(program2){program2.on("beforeAllHelp",({command})=>{const[name]=command.args;if(name===void 0||name.startsWith("-")||command.commands.length===0||command.registeredArguments.length>0||command.commands.some(sub=>sub.name()===name||sub.aliases().includes(name)))return;command.unknownCommand()})}import childProcess from"child_process";function registerTelemetry(program2,workerPath){program2.hook("preAction",(_program,command)=>{try{if(process.env.GAUGE_TELEMETRY_DISABLED==="1")return;const names=[];for(let current=command;current?.parent;current=current.parent)names.unshift(current.name());if(!names.length||names[0]==="telemetry")return;const event={command:names.join(" "),timestamp:new Date().toISOString(),cliVersion:CLI_VERSION};const child=childProcess.spawn(process.execPath,[workerPath,JSON.stringify(event)],{detached:true,stdio:"ignore",windowsHide:true});child.on("error",()=>{});child.unref()}catch{}})}var program=new Command;program.name("gauge").description("Hillclimb Agent Experience: run coding agents against your product, analyze friction, improve, and retest. Run locally with Docker and your agent credentials, or use hosted Gauge. Agents: start with `gauge instructions`.").configureHelp({showGlobalOptions:true,formatHelp:(cmd,helper)=>cmd===program?formatRootHelp(cmd,helper):formatCommandHelp(cmd,helper)}).version(CLI_VERSION).option("--org <org>","organization slug or
|
|
798
|
+
gauge run compare --local --baseline batch=<id> --candidate batch=<id>`).action(async(opts,cmd)=>{const body={baseline:parseCompareSide("--baseline",opts.baseline),candidate:parseCompareSide("--candidate",opts.candidate)};const state=gaugeState(cmd);let result;let warnings;if(state.mode==="local"){const baseline=localCompareFilter("--baseline",body.baseline);const candidate=localCompareFilter("--candidate",body.candidate);const root=state.root;if(!root)throw new CliError("usage","Local runs need a Gauge workspace. Run `gauge init` in this directory first.");const gaugeDir=join12(root,".gauge");result=compareLocalRuns(listLocalRuns(gaugeDir,baseline),listLocalRuns(gaugeDir,candidate));warnings=localCompareWarnings}else{result=await createClient().post(`/api/v1/orgs/${encodeURIComponent(await resolveOrg(cmd))}/runs/compare`,body);warnings=compareWarnings}if(resolveOutput(cmd)==="json"){printJson(result);return}for(const warning of warnings(result))console.error(`Warning: ${warning}`);printComparison(result)});run.command("wait [request-id]").description("Wait for every session and judge in a launch request, then print the verdict. Exits 0 once settled, whatever the verdict. Local: wait for a batch with --batch").option("--batch <batch-id>","wait for this local batch").option("--check","exit 1 unless the verdict is PASSED or MEASURED (for CI gates); local: unless every session completed").action(async(id,opts,cmd)=>{const state=gaugeState(cmd);if(state.mode==="local"){if(!opts.batch||id)throw new CliError("usage","Local wait takes --batch <batch-id>, not a request ID");if(!state.root)throw new CliError("usage","Run this command inside the batch's Gauge workspace");return waitForLocalBatch(cmd,join12(state.root,".gauge"),opts.batch,opts)}if(!id||opts.batch)throw new CliError("usage","Hosted wait requires a request ID; --batch is local only");return waitForRequest(cmd,id,opts)})}var skills_exports={};__export(skills_exports,{buildSkillEditBody:()=>buildSkillEditBody,register:()=>register30});function skillsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/skills`}function skillPath(org,ref){return`${skillsPath(org)}/${encodeURIComponent(ref)}`}function sourceLabel(s){if(!s)return"";const path=s.subpath?`/${s.subpath}`:"";return`${s.repoFullName}${path}#${s.ref}${s.autoIngest?" (auto)":""}`}async function buildSkillEditBody(opts,fetchCurrentSource){if(opts.note!==void 0&&opts.clearNote)throw new CliError("usage","--note and --clear-note conflict");if(opts.source!==void 0&&opts.clearSource)throw new CliError("usage","--source and --clear-source conflict");if(opts.autoIngest!==void 0&&opts.clearSource)throw new CliError("usage","--auto-ingest and --clear-source conflict");let autoIngest;if(opts.autoIngest!==void 0){if(opts.autoIngest!=="true"&&opts.autoIngest!=="false")throw new CliError("usage","--auto-ingest expects true or false");autoIngest=opts.autoIngest==="true"}const body={};if(opts.rename!==void 0)body.name=opts.rename;if(opts.clearNote)body.note=null;else if(opts.note!==void 0)body.note=opts.note;if(opts.clearSource)body.source=null;else if(opts.source!==void 0){const m=opts.source.match(/^([^#]+\/[^#/]+)#([^/]+)(?:\/(.+))?$/);if(!m)throw new CliError("usage",'invalid --source (expected "owner/repo#branch" or "owner/repo#branch/subpath")');body.source={repoFullName:m[1],ref:m[2],subpath:m[3],autoIngest}}else if(autoIngest!==void 0){const current=await fetchCurrentSource();if(!current)throw new CliError("usage","this skill has no tracked source \u2014 set one first with --source owner/repo#branch");body.source={repoFullName:current.repoFullName,ref:current.ref,subpath:current.subpath||void 0,autoIngest}}if(Object.keys(body).length===0)throw new CliError("usage","nothing to change");return body}function register30(program2){const group=hostedOnly(program2.command("skills")).description("Manage agent skills used by eval and preference runs");group.command("list").description("List the org's skills with their newest version").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(skillsPath(org));if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(s=>({name:s.name,latest:s.latestVersion?.label??"",versions:s.versionCount,source:sourceLabel(s.source),note:s.note??""})),"table")});group.command("get <ref>").description("Show one skill: source, note, every version").action(async(ref,_opts,cmd)=>{const org=await resolveOrg(cmd);const skill=await createClient().get(skillPath(org,ref));if(resolveOutput(cmd)==="json"){printJson(skill);return}console.log(`name: ${skill.name}`);console.log(`id: ${skill.id}`);console.log(`note: ${skill.note??"(none)"}`);console.log(`source: ${sourceLabel(skill.source)||"(untracked)"}`);console.log("versions:");for(const v of skill.versions)console.log(` ${skill.name}@${v.label} ${v.contentDigest.slice(0,19)} ${v.createdAt}`)});group.command("add <reference>").description("Ingest a skill from owner/repo[/skill][#ref] or a GitHub URL").option("--as <handle>","the handle (default: the directory basename)").option("--label <label>","version label (a typed label always mints; omitted dedups by digest)").option("--skill <name>","select one skill from a source holding several").option("--note <text>","note shown on the index").option("--track","track the source branch for auto re-ingest (reference must name a branch)").action(async(reference,opts,cmd)=>{const org=await resolveOrg(cmd);const result=await createClient().post(skillsPath(org),{reference,handle:opts.as,label:opts.label,skill:opts.skill,note:opts.note,trackSource:opts.track});if(resolveOutput(cmd)==="json"){printJson(result);return}console.log(result.unchanged?`Already current: ${result.handle}@${result.label} carries this content`:`Ingested ${result.handle}@${result.label}`);console.error(`Attach it to an eval: gauge eval edit <id> --skill ${result.handle}@${result.label}`)});group.command("edit <ref>").description("Rename, note, or repoint a skill's tracked source").option("--rename <handle>","new handle (name@label refs must be updated)").option("--note <text>","replace the note").option("--clear-note","remove the note").option("--source <owner/repo#branch[/subpath]>","set the tracked source branch").option("--clear-source","stop tracking the source").option("--auto-ingest <bool>","true|false \u2014 auto re-ingest on new commits").action(async(ref,opts,cmd)=>{const org=await resolveOrg(cmd);const client=createClient();const body=await buildSkillEditBody(opts,async()=>{const skill=await client.get(skillPath(org,ref));return skill.source});const updated=await client.patch(skillPath(org,ref),body);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated skill ${updated.name}`)});group.command("reingest <ref>").description("Pull the tracked source now (no-op when already current)").action(async(ref,_opts,cmd)=>{const org=await resolveOrg(cmd);const result=await createClient().post(`${skillPath(org,ref)}/reingest`,{});if(resolveOutput(cmd)==="json")printJson(result);else console.log(result.unchanged?"Already current \u2014 nothing new upstream":`Ingested new version ${ref}@${result.label}`)});group.command("rm <ref>").description("Remove a skill; the handle stays reserved and finished runs keep their snapshot").action(async(ref,_opts,cmd)=>{const org=await resolveOrg(cmd);const result=await createClient().delete(skillPath(org,ref));if(resolveOutput(cmd)==="json")printJson(result);else console.log(`Deleted skill ${ref} (${result.referencedRuns} finished run(s) referenced it)`)});group.command("runs <ref>").description("Recent sessions that staged this skill").option("--limit <n>","max runs (default 10, cap 50)").action(async(ref,opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(`${skillPath(org,ref)}/runs`,{limit:opts.limit});if(resolveOutput(cmd)==="json"){printJson(res.items);return}printItems(res.items.map(r=>({id:r.runId,agent:r.agent,version:r.versionLabel??"",turns:r.turns??"",cost:r.costUsd==null?"":`$${r.costUsd.toFixed(2)}`,finished:r.finishedAt??"(running)"})),"table")})}var stats_exports={};__export(stats_exports,{register:()=>register31});function addFilterOptions(cmd){return cmd.option("--prompt <id>","filter to a single prompt").option("--tag <ids>","comma-separated tag ids").option("--repo <urls>","comma-separated base repo urls").option("--language <langs>","comma-separated repo languages").option("--framework <names>","comma-separated repo frameworks").option("--size <buckets>","comma-separated codebase-size buckets").option("--branded","only branded prompts").option("--unbranded","only non-branded prompts").option("--limit <n>","max rows (default 50)").option("--full","return all rows (up to 1000)")}function filterQuery(opts){if(opts.branded&&opts.unbranded){throw new CliError("usage","Pass at most one of --branded / --unbranded.")}return{prompt:opts.prompt,tag:opts.tag,repo:opts.repo,language:opts.language,framework:opts.framework,size:opts.size,branded:opts.branded?"true":opts.unbranded?"false":void 0,limit:opts.full?"1000":opts.limit}}var pct4=rate=>`${(rate*100).toFixed(1)}%`;var delta=d=>d===null||d===0?"\u2014":d>0?`+${d}`:String(d);function noteFreshness2(f){if(!f.available){console.error("warning: analytics store is temporarily unavailable; results may be incomplete.")}else if(f.pending>0){console.error(`note: ${f.pending} recent run(s) still ingesting; results may not reflect them yet.`)}}async function runStats(command,resource,opts,toRow5){const org=await resolveOrg(command);const output=resolveOutput(command);const res=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/stats/${resource}`,filterQuery(opts));if(output==="json"){printJson(res);return}printItems(res.items.map(toRow5),"table");noteFreshness2(res.freshness)}var rankingRow=r=>({rank:r.rank,brand:r.brandName,kind:r.kind,installs:r.installs,"install%":pct4(r.installRate),"mention%":pct4(r.mentionRate),delta:delta(r.deltaRank)});var packageRow=r=>({package:r.name,ecosystem:r.ecosystem,brand:r.brandName,kind:r.kind,installs:r.installs,rate:pct4(r.rate)});var brandRow=r=>({brand:r.brandName,kind:r.kind,installs:r.installs,rate:pct4(r.rate)});var funnelRow=r=>({brand:r.brandName,kind:r.kind,"mention%":pct4(r.mentionRate),"install%":pct4(r.installRate)});var domainRow=r=>({domain:r.domain,brand:r.brandName,runs:r.runs,rate:pct4(r.rate),requests:r.requests});function register31(program2){const group=hostedOnly(program2.command("stats")).description("Read-only analytics over your runs");addFilterOptions(group.command("rankings").description("Brands ranked by install rate")).action((opts,command)=>runStats(command,"rankings",opts,rankingRow));addFilterOptions(group.command("installs").description("Package install rates (share of voice)")).action((opts,command)=>runStats(command,"installs",opts,packageRow));addFilterOptions(group.command("brands").description("Per-brand (company-level) install rates")).action((opts,command)=>runStats(command,"brands",opts,brandRow));addFilterOptions(group.command("funnel").description("Per-brand mention rate beside install rate")).action((opts,command)=>runStats(command,"funnel",opts,funnelRow));addFilterOptions(group.command("domains").description("Outbound fetch rates by registrable domain")).action((opts,command)=>runStats(command,"domains",opts,domainRow))}var status_exports={};__export(status_exports,{register:()=>register32});function pct5(rate){return rate==null?"\u2014":`${Math.round(rate*100)}%`}function delta2(pp){if(pp==null)return"";const rounded=Math.round(pp);return rounded===0?"":` (${rounded>0?"+":""}${rounded}pp)`}function register32(program2){hostedOnly(program2.command("status")).description("One-shot org summary: actions, Agent Preference, agent experience").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const s=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/summary`);if(resolveOutput(cmd)==="json"){printJson(s);return}if(!s.hasAnyRuns){console.log("No runs yet. Create an eval (`gauge eval create`) or run one (`gauge run --eval <id>`).");return}console.log(`last synthesis: ${s.lastSynthesisAt??"never"}`);console.log("\nagent experience:");if(!s.agentExperience.ok){console.log(` (unavailable: ${s.agentExperience.error})`)}else if(s.agentExperience.data.cards.length===0){console.log(" (no judged runs in the last 30 days)")}else{for(const card of s.agentExperience.data.cards){console.log(` ${card.name}: ${pct5(card.passRate)}${delta2(card.deltaPP)} over ${card.judgedRuns} judged run(s)`)}const extra=s.agentExperience.data.setCount-s.agentExperience.data.cards.length;if(extra>0)console.log(` (+${extra} more \u2014 see the dashboard)`)}console.log("\nAgent Preference:");if(!s.visibility.ok){console.log(` (unavailable: ${s.visibility.error})`)}else if(s.visibility.data.cards.length===0){console.log(" (no preference runs in the last 30 days)")}else{for(const card of s.visibility.data.cards){const owned=card.owned?`${card.owned.name} #${card.owned.rank}, chosen ${pct5(card.owned.chosenRate)}${delta2(card.chosenDeltaPP)}`:"no owned brand ranked";console.log(` ${card.name}: ${owned}`)}}console.log("\nopen actions:");if(!s.actions.ok){console.log(` (unavailable: ${s.actions.error})`)}else if(s.actions.data.length===0){console.log(" (none)")}else{for(const a of s.actions.data.slice(0,5)){console.log(` [${a.priority}] ${a.title} (${a.id})`)}if(s.actions.data.length>5)console.log(` (+${s.actions.data.length-5} more \u2014 \`gauge actions list\`)`)}})}var tags_exports={};__export(tags_exports,{register:()=>register33});function tagsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/tags`}function register33(program2){const group=hostedOnly(program2.command("tags")).description("Manage org tags");group.command("list").description("List tags").action(async(_opts,cmd)=>{const org=await resolveOrg(cmd);const items=await fetchAllPages(createClient(),tagsPath(org));if(resolveOutput(cmd)==="json")printJson(items);else printItems(items,"table")});group.command("add <name>").description("Add a tag").option("--color <color>","palette color (e.g. blue, grape; default gray)").action(async(name,opts,cmd)=>{const org=await resolveOrg(cmd);const tag=await createClient().post(tagsPath(org),{name,color:opts.color});if(resolveOutput(cmd)==="json")printJson(tag);else console.log(`Created tag ${tag.id} (${tag.name}, ${tag.color})`)});group.command("rename <tag> <new-name>").description("Rename a tag (by id or current name)").option("--color <color>","also change the color").action(async(tag,newName,opts,cmd)=>{const org=await resolveOrg(cmd);const updated=await createClient().patch(`${tagsPath(org)}/${encodeURIComponent(tag)}`,{name:newName,color:opts.color});if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Renamed tag ${updated.id} to ${updated.name} (${updated.color})`)});group.command("rm <tag>").description("Delete a tag (by id or name)").action(async(tag,_opts,cmd)=>{const org=await resolveOrg(cmd);await createClient().delete(`${tagsPath(org)}/${encodeURIComponent(tag)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted tag ${tag}`)})}var telemetry_exports={};__export(telemetry_exports,{register:()=>register34});async function printStatus(command){const status=await telemetryStatus();if(command.optsWithGlobals().output==="json"){printJson(status);return}console.log(`CLI telemetry is ${status.enabled?"enabled":"disabled"} (${status.source}).`);if(status.source==="environment")console.log("GAUGE_TELEMETRY_DISABLED=1 overrides the saved preference.");if(status.source==="unavailable")console.log("Preferences could not be read. Collection is disabled until repaired with gauge telemetry enable or disable.")}function register34(program2){const telemetry=program2.command("telemetry").description("Control anonymous CLI usage telemetry (enabled by default)");telemetry.command("status").description("Show whether CLI telemetry is enabled").action(async(_options,command)=>printStatus(command));for(const enabled of[true,false]){telemetry.command(enabled?"enable":"disable").description(`${enabled?"Enable":"Disable"} CLI telemetry for this user`).action(async(_options,command)=>{await setTelemetryEnabled(enabled);await printStatus(command)})}}var update_exports={};__export(update_exports,{register:()=>register35});import{spawnSync as spawnSync2}from"child_process";function register35(program2,{run=spawnSync2,platform=process.platform}={}){program2.command("update").description("Update the globally installed Gauge CLI to the latest version").action((_opts,command)=>{const output=resolveOutput(command);console.error("Updating Gauge CLI to the latest published version...");const result=run(platform==="win32"?"npm.cmd":"npm",["install","--global","@withgauge/cli@latest"],{shell:platform==="win32",stdio:["inherit",output==="json"?2:"inherit","inherit"]});if(result.error||result.status!==0){const reason=result.error?result.error.message:result.signal?`npm was interrupted by ${result.signal}`:`npm exited with code ${result.status}`;throw new CliError("internal",`CLI update failed: ${reason}.
|
|
799
|
+
Retry with: npm install --global @withgauge/cli@latest`)}if(output==="json"){printJson({updated:true,package:"@withgauge/cli",tag:"latest"})}else{console.log("Updated Gauge CLI. Run `gauge --version` to see the installed version.")}})}var usage_exports={};__export(usage_exports,{register:()=>register36,usageRow:()=>usageRow});function usageRow(e){return{createdAt:e.createdAt,kind:e.kind,delta:e.delta,"started by":triggeredByLabel(e.triggeredBy),runId:e.runId??""}}function register36(program2){hostedOnly(program2.command("usage")).description("List credit ledger entries").option("--since <window>",'e.g. "30d", "24h", or an ISO date').option("--limit <n>","page size (1-200)",parseLimit,50).option("--cursor <cursor>","resume from a previous page's nextCursor").action(async(opts,cmd)=>{const org=await resolveOrg(cmd);const res=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/usage`,{since:opts.since,limit:opts.limit,cursor:opts.cursor});if(resolveOutput(cmd)==="json"){printJson(res);return}printItems(res.items.map(usageRow),"table");if(res.items.length===0&&!opts.cursor){try{const status=await createClient().get(`/api/v1/orgs/${encodeURIComponent(org)}/billing`);if(!status.enforced){process.stderr.write("Billing is not enforced for this org, so runs don't create ledger entries.\n")}}catch{}}if(res.nextCursor){process.stderr.write(`(more results \u2014 rerun with --cursor ${res.nextCursor})
|
|
800
|
+
`)}})}var EXAMPLES=[["gauge init --local","Initialize a workspace; creates no measurements"],["gauge instructions hillclimb","Choose inputs and prepare a first pilot"],["gauge eval create --help","Save a task and success criteria"],["gauge run --eval <id> --local","Run a saved eval; rerun after input changes"]];var GROUPS=[["Get started",{instructions:"Instructions for coding agents",init:"Initialize a Gauge workspace",local:"Configure local execution","install-skill":"Install the Gauge agent skill",onboard:"Sign in and set up your workspace",status:"One-shot org summary (Gauge account)"}],["Evals (local or hosted)",{eval:"Manage saved evals",preference:"Manage saved preference prompts",run:"Start runs and read them",query:"Query local runs and findings or hosted analytics",cleanup:"Clean interrupted local sessions",models:"List models, harnesses, and providers"}],["Hosted tools (Gauge account)",{personas:"Manage simulated-user personas",skills:"Manage agent skills",mcp:"Manage MCP servers",optimizations:"Find the best change to an owned surface"}],["Insights (Gauge account)",{stats:"Analytics over your runs",dashboards:"Saved dashboards",actions:"Recommended follow-ups"}],["Gauge Chat (AI visibility)",{chat:"Prompts, topics, answers, citations, queries"}],["Organization (Gauge account)",{orgs:"List and switch organizations",org:"This org's settings",members:"Team members and invites",repos:"Manage repositories",connections:"Stored credentials (no secrets)",keys:"Manage BYOK provider keys",brands:"Manage org brands",tags:"Manage org tags",billing:"Billing and credits",usage:"Credit ledger entries"}],["Account",{auth:"Sign in, sign out, and tokens",whoami:"Show the signed-in user"}],["CLI",{config:"Manage local CLI config",telemetry:"Enable or disable anonymous CLI usage telemetry",update:"Update to the latest version",feedback:"Send feedback to the Gauge team"}]];function formatIntro(lines,helper,width,code,spaced=false){return lines.flatMap((line,i)=>{const bullet=line.startsWith("- ");const indent=bullet?" ":"";const gap=spaced&&i>0&&!bullet&&!lines[i-1].startsWith("- ")?[""]:[];const text=(bullet?line.slice(2):line).replace(/`([^`]+)`/g,(span,inner)=>{const styled=code(inner);return(styled===inner?span:styled).replaceAll(" ","\0")});return[...gap,...helper.boxWrap(text,width-indent.length).replaceAll("\0"," ").split("\n").map((row2,j)=>(j===0&&bullet?"- ":indent)+row2)]})}function padFor(rows){return Math.max(...rows.map(([term])=>term.length))+2}function formatTable(rows,indent,helper,width,color,pad=padFor(rows)){return rows.flatMap(([term,text])=>{const[first,...rest]=helper.boxWrap(text,width-indent.length-pad).split("\n");const head=`${indent}${color(term.padEnd(pad))}${first}`;if(term.length>=pad)return[`${indent}${color(term)}`,...[first,...rest].map(row2=>indent+" ".repeat(pad)+row2)];return[head,...rest.map(row2=>indent+" ".repeat(pad)+row2)]})}function firstClause(text){return text.split(/[.:;(]| — /)[0].trim()}function formatRootHelp(program2,helper){const bold=style("1");const dim=style("2");const green=style("32");const width=helper.helpWidth??80;const state=readGaugeState(program2.opts());const visible=new Map(helper.visibleCommands(program2).filter(cmd=>cmd.name()!=="help").map(cmd=>[cmd.name(),cmd]));const sections=GROUPS.map(([title,summaries])=>[title,Object.entries(summaries).filter(([name])=>visible.delete(name))]);if(visible.size)sections.push(["Other",[...visible.values()].map(cmd=>[cmd.name(),firstClause(cmd.summary()||cmd.description())])]);const options=helper.visibleOptions(program2).map(option=>[helper.optionTerm(option),firstClause(option.description)]);const table=(rows,indent,pad)=>formatTable(rows,indent,helper,width,green,pad);const commandPad=padFor(sections.flatMap(([,rows])=>rows));const lines=["",`${bold("Gauge CLI")} ${dim(`v${CLI_VERSION}`)}`,"",...formatIntro(program2.description().split(/(?<=\.) /),helper,width,green),"",...formatIntro(["Gauge strongly recommends the gauge-agents skill for coding agents: `gauge install-skill`. It makes Gauge workflow guidance discoverable in future sessions.",...header(state,void 0,true)],helper,width,green,true),"",bold(" EXAMPLES"),...table(EXAMPLES," "),"",bold(" COMMANDS")];for(const[title,rows]of sections){if(!rows.length)continue;lines.push("",bold(` ${title}`),...table(rows," ",commandPad))}lines.push("",bold(" OPTIONS"),...table(options," "),"",` Run ${green("gauge <command> --help")} for details on any command.`,"");return lines.join("\n")}function formatCommandHelp(cmd,helper){const bold=style("1");const green=style("32");const width=helper.helpWidth??80;const path=[];for(let c=cmd;c;c=c.parent)path.unshift(c.name());const name=path.join(" ");const usage=[name,cmd.usage()].join(" ");let root=cmd;while(root.parent)root=root.parent;const rows={ARGUMENTS:helper.visibleArguments(cmd).map(arg=>[helper.argumentTerm(arg),helper.argumentDescription(arg)]),COMMANDS:helper.visibleCommands(cmd).filter(sub=>sub.name()!=="help").map(sub=>[helper.subcommandTerm(sub),helper.subcommandDescription(sub)]),OPTIONS:helper.visibleOptions(cmd).map(option=>[helper.optionTerm(option),helper.optionDescription(option)]),"GLOBAL OPTIONS":helper.visibleGlobalOptions(cmd).filter(option=>root.options.includes(option)&&option.long!=="--version").map(option=>[helper.optionTerm(option),helper.optionDescription(option)])};const pad=Math.min(padFor(Object.values(rows).flat().concat([["",""]])),Math.floor(width/3));const lines=["",bold(name)+(cmd.aliases().length?` (${cmd.aliases().join(", ")})`:"")];const description=helper.commandDescription(cmd);if(description)lines.push("",...formatIntro(description.split("\n"),helper,width-1,green).map(row2=>` ${row2}`));lines.push("",bold(" USAGE"),` ${usage}`);for(const[title,items]of Object.entries(rows)){if(!items.length)continue;lines.push("",bold(` ${title}`),...formatTable(items," ",helper,width,green,pad))}if(rows.COMMANDS.length)lines.push("",` Run ${green(`${name} <command> --help`)} for details on any command.`);const topic=path[1]&&topicForCommand(path[1]);if(topic)lines.push("",` Run ${green(`gauge instructions ${topic}`)} for explicit guidance.`);lines.push("");return lines.join("\n")}function rejectUnknownCommandHelp(program2){program2.on("beforeAllHelp",({command})=>{const[name]=command.args;if(name===void 0||name.startsWith("-")||command.commands.length===0||command.registeredArguments.length>0||command.commands.some(sub=>sub.name()===name||sub.aliases().includes(name)))return;command.unknownCommand()})}import childProcess from"child_process";function registerTelemetry(program2,workerPath){program2.hook("preAction",(_program,command)=>{try{if(process.env.GAUGE_TELEMETRY_DISABLED==="1")return;const names=[];for(let current=command;current?.parent;current=current.parent)names.unshift(current.name());if(!names.length||names[0]==="telemetry")return;const event={command:names.join(" "),timestamp:new Date().toISOString(),cliVersion:CLI_VERSION};const child=childProcess.spawn(process.execPath,[workerPath,JSON.stringify(event)],{detached:true,stdio:"ignore",windowsHide:true});child.on("error",()=>{});child.unref()}catch{}})}var program=new Command;program.name("gauge").description("Hillclimb Agent Experience: run coding agents against your product, analyze friction, improve, and retest. Run locally with Docker and your agent credentials, or use hosted Gauge. Agents: start with `gauge instructions`.").configureHelp({showGlobalOptions:true,formatHelp:(cmd,helper)=>cmd===program?formatRootHelp(cmd,helper):formatCommandHelp(cmd,helper)}).version(CLI_VERSION).option("--org <org>","organization slug or id, for Gauge Chat and Gauge Agents (default: gauge.json orgId, then your saved default)").addOption(new Option5("-o, --output <format>","output format").choices([...OUTPUT_FORMATS]).default("table")).addOption(new Option5("--local","run on this machine, no account needed").conflicts("hosted")).option("--hosted","run on hosted Gauge (needs an account). Default: workspace preference, then user preference, else local");program.exitOverride();rejectUnknownCommandHelp(program);program.configureOutput({outputError:()=>{}});for(const group of[instructions_exports,localRuntime_exports,cleanup_exports,update_exports,auth_exports,init_exports,installSkill_exports,onboard_exports,status_exports,orgs_exports,org_exports,members_exports,models_exports,localProfiles_exports,run_exports,eval_exports,preference_exports,personas_exports,skills_exports,mcp_exports,connections_exports,repos_exports,optimizations_exports,brands_exports2,tags_exports,actions_exports,dashboards_exports,keys_exports2,billing_exports,usage_exports,stats_exports,query_exports,chat_exports,config_exports,telemetry_exports,feedback_exports2]){group.register(program)}if(!import.meta.url.endsWith(".ts"))registerTelemetry(program,fileURLToPath(new URL("./telemetryWorker.js",import.meta.url)));function errorContext(){try{const state=readGaugeState(program.opts());return{local:state.mode==="local"?state.source:void 0}}catch{return{}}}try{await program.parseAsync(process.argv)}catch(error){if(error instanceof CommanderError2&&(error.exitCode===0||error.code==="commander.help"||error.code==="commander.helpDisplayed"))process.exit(error.exitCode===0?0:2);const argv=process.argv.slice(2);const report=errorReport(error,commandPath(program,argv),errorContext());if(report.code==="upgrade_required"&&!/npm install/i.test(report.message))report.hint="Run: npm install -g @withgauge/cli";if(report.code==="not_found"&&/organization/i.test(report.message)&&!program.opts().org)report.hint="That is your configured default organization. Run `gauge orgs list` to see yours, then `gauge orgs use <org>` to update it.";process.stderr.write(renderError(report,wantsJson(argv)));process.exit(report.exitCode)}
|