@withgauge/cli 0.30.0 → 0.32.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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{LOCAL_AGENTS,LOCAL_MCP_HINT,LOCAL_TARGETS,analysisNext,assertLocalCapabilities,commentSourceSchema,deploymentSourceSchema,detachLocal,freezeWebFixtures,inspectLocalCredential,inspectLocalGateway,inspectLocalRuntime,mergeWebFixtures,parseWebFixtureInput,planLocal,pullLocalGateway,pullLocalRuntime,readProfiles,readWebFixtureArchive,requireProfile,runLocal,setProfile,websiteSourceSchema,websiteUseSchema,writeProfiles}from"./chunk-4SZPSHNF.js";import{setTelemetryEnabled,telemetryStatus}from"./chunk-WYYRMPRX.js";import{readJson}from"./chunk-MKC7K5NV.js";import{cancelLocal,cleanupLocal,localBatchStatus,localStatus,openLocalStore}from"./chunk-ZZK6V3ZF.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,selectedOrg,style,truncate,withCategory}from"./chunk-VHV7YMN5.js";import{createdOrganization,credentialKind,fetchDirectory,findOrganization,isUuid,legacySelection,productsLabel,resolveOrgValue}from"./chunk-ZXRPUGCO.js";import{ANALYSIS_SCHEMA_VERSION,ApiClient,CliError,DEFAULT_LIFECYCLE_TIMEOUT_SECONDS,MAX_LIFECYCLE_SOURCE_LENGTH,MAX_LIFECYCLE_TIMEOUT_SECONDS,agentConfigInputSchema,agentConfigSchema,agentSchema,analysisSubmissionSchema,assetRefListSchema,batteries_exports,brands_exports,clearToken,createClient,createdBySchema,credentialsPath,errorEnvelopeSchema,exitCodeFor,feedback_exports,keys_exports,lifecycleSchema,listResponseSchema,readCredentials,resolveAuthUrl,resolveBaseUrl,resolveToken,runConfig_exports,runCreditsChargedSchema,runEventSchema,runTriggeredBySchema,saveCredentials,saveToken,sharedTokenSchema,storedSharedCredentials,withCredentialLock}from"./chunk-QJ2UAX2V.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 Option6}from"commander";import{fileURLToPath as fileURLToPath2}from"url";var auth_exports={};__export(auth_exports,{browserLogin:()=>browserLogin,deviceLogin:()=>deviceLogin,logout:()=>logout,parseLoopbackCallback:()=>parseLoopbackCallback,readStdin:()=>readStdin,register:()=>register,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:
2
+ import{LOCAL_AGENTS,LOCAL_MCP_HINT,LOCAL_TARGETS,analysisNext,assertLocalCapabilities,commentSourceSchema,deploymentSourceSchema,detachLocal,freezeWebFixtures,inspectLocalCredential,inspectLocalGateway,inspectLocalRuntime,mergeWebFixtures,parseWebFixtureInput,planLocal,pullLocalGateway,pullLocalRuntime,readProfiles,readWebFixtureArchive,requireProfile,runLocal,setProfile,websiteSourceSchema,websiteUseSchema,writeProfiles}from"./chunk-EUIOGLV7.js";import{setTelemetryEnabled,telemetryStatus}from"./chunk-WYYRMPRX.js";import{readJson}from"./chunk-MKC7K5NV.js";import{cancelLocal,cleanupLocal,localBatchStatus,localStatus,openLocalStore}from"./chunk-ZZK6V3ZF.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,selectedOrg,style,truncate,withCategory}from"./chunk-VHV7YMN5.js";import{createdOrganization,credentialKind,fetchDirectory,findOrganization,isUuid,legacySelection,productsLabel,resolveOrgValue}from"./chunk-ZXRPUGCO.js";import{ANALYSIS_SCHEMA_VERSION,ApiClient,CliError,DEFAULT_LIFECYCLE_TIMEOUT_SECONDS,MAX_LIFECYCLE_SOURCE_LENGTH,MAX_LIFECYCLE_TIMEOUT_SECONDS,agentConfigInputSchema,agentConfigSchema,agentSchema,analysisSubmissionSchema,assetRefListSchema,batteries_exports,brands_exports,clearToken,createClient,createdBySchema,credentialsPath,errorEnvelopeSchema,exitCodeFor,feedback_exports,keys_exports,lifecycleSchema,listResponseSchema,readCredentials,resolveAuthUrl,resolveBaseUrl,resolveToken,runConfig_exports,runCreditsChargedSchema,runEventSchema,runTriggeredBySchema,saveCredentials,saveToken,sharedTokenSchema,storedSharedCredentials,withCredentialLock}from"./chunk-QJ2UAX2V.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 Option7}from"commander";import{fileURLToPath as fileURLToPath2}from"url";var auth_exports={};__export(auth_exports,{browserLogin:()=>browserLogin,deviceLogin:()=>deviceLogin,logout:()=>logout,parseLoopbackCallback:()=>parseLoopbackCallback,readStdin:()=>readStdin,register:()=>register,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
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,body2){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(body2)})}catch(e){throw new CliError("network",`Request to ${base} failed: ${e instanceof Error?e.message:String(e)}`)}const text2=await res.text();if(!res.ok){try{const parsed=errorEnvelopeSchema.safeParse(JSON.parse(text2));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(text2)}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}
@@ -33,7 +33,7 @@ an org API key implies its own org, and --org may pick one of an agency key's
33
33
  clients. Pass -o json for
34
34
  machine-readable output; errors carry the API error code. Exit codes: 0 ok,
35
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:()=>register6});import{join as join5}from"path";function register6(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:()=>register7});function assertKey(key){if(CONFIG_KEYS.includes(key)){return key}throw new CliError("usage",`Unknown config key '${key}'. Valid keys: ${CONFIG_KEYS.join(", ")}`)}function register7(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:()=>register8});function connectionsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/connections`}function register8(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:()=>register9});import{readFileSync as readFileSync3}from"fs";function dashboardsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/dashboards`}function register9(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:()=>register10});import{randomUUID as randomUUID3}from"crypto";import{join as join6}from"path";import{z as z4}from"zod";import{z as z2}from"zod";function parseCliRuleArguments(argv,arity){const value={positionals:[],options:new Map,endOptions:argv.length};for(let i=0;i<argv.length;i++){const token=argv[i];if(token==="--"){value.endOptions=i;value.positionals.push(...argv.slice(i+1));break}if(!token.startsWith("-")||token==="-"){value.positionals.push(token);continue}const equal=token.indexOf("=");const flag2=equal<0?token:token.slice(0,equal);if(!Object.hasOwn(arity,flag2)||!flag2.startsWith("--")&&flag2.length!==2)return{kind:"ambiguous",reason:"unknown_option"};if(arity[flag2]===0){if(equal>=0)return{kind:"ambiguous",reason:"unexpected_value"};value.options.set(flag2,{index:i,width:1})}else if(equal>=0){value.options.set(flag2,{index:i,width:1,value:token.slice(equal+1)})}else{if(i+1===argv.length||argv[i+1]==="--")return{kind:"ambiguous",reason:"missing_value"};value.options.set(flag2,{index:i,width:2,value:argv[i+1]});i++}}return{kind:"parsed",value}}var CLI_RULE_LIMITS={bundleBytes:2*1024*1024,jsonTokens:4e4,rules:50,operations:50,arguments:256,argumentBytes:4095,literalBytes:8192,bufferBytes:2*1024*1024,bufferWaitMs:5e3,maxBufferWaitMs:12e4,expansionBytes:64*1024*1024,excerptBytes:4096,attemptExcerptBytes:256*1024,journalBytes:4*1024*1024,supervisorTasks:4096};var encoder=new TextEncoder;var cliUtf8Bytes=value=>encoder.encode(value).length;var text=(max,nonempty=false)=>z2.string().superRefine((value,ctx)=>{if(nonempty&&!value.length||cliUtf8Bytes(value)>max||/\0|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(value))ctx.addIssue({code:"custom",message:`Use valid non-NUL UTF-8 text of at most ${max} bytes${nonempty?", not empty":""}`})});var id=z2.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/);var flag=z2.string().regex(/^(?:-[A-Za-z0-9]|--[A-Za-z0-9][A-Za-z0-9-]{0,125})$/);var envKey=z2.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,126}$/);var arg=text(CLI_RULE_LIMITS.argumentBytes);var literal=text(CLI_RULE_LIMITS.literalBytes);var stream=z2.enum(["stdout","stderr","combined"]);var exit=z2.discriminatedUnion("kind",[z2.object({kind:z2.literal("any")}).strict(),z2.object({kind:z2.literal("code"),value:z2.number().int().min(0).max(255)}).strict()]);var buffer={maxBufferBytes:z2.number().int().min(1).max(CLI_RULE_LIMITS.bufferBytes).default(CLI_RULE_LIMITS.bufferBytes),maxWaitMs:z2.number().int().min(1).max(CLI_RULE_LIMITS.maxBufferWaitMs).default(CLI_RULE_LIMITS.bufferWaitMs)};var source=value=>z2.discriminatedUnion("source",[z2.object({source:z2.literal("literal"),value}).strict(),z2.object({source:z2.literal("localFact"),key:envKey}).strict()]);function cliBoundedPattern(pattern){let at=pattern.startsWith("^")?1:0;const end=pattern.endsWith("$")&&pattern.length>at?pattern.length-1:pattern.length;let stars=0;let literals=0;while(at<end){const char=pattern[at];if(char==="\\"){if(++at>=end||!"\\.^$*+?[]{}()|".includes(pattern[at]))return false;literals++}else if(char==="."&&pattern[at+1]==="*"){if(++stars>1)return false;at++}else if(".^$*+?[]{}()|\n\r".includes(char))return false;else literals++;at++}return literals>0}var cliRuleTargetSchema=z2.discriminatedUnion("kind",[z2.object({kind:z2.literal("npmBin"),packageName:z2.string().max(214).regex(/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/),program:z2.string().max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/)}).strict(),z2.object({kind:z2.literal("path"),path:text(1024,true).refine(value=>!value.includes("\\")&&!value.split("/").includes(".."),"Use a sandbox path without traversal")}).strict()]);var cliRuleSelectorSchema=z2.discriminatedUnion("kind",[z2.object({kind:z2.literal("prefix"),argv:z2.array(arg).max(CLI_RULE_LIMITS.arguments-1)}).strict(),z2.object({kind:z2.literal("exact"),argv:z2.array(arg).max(CLI_RULE_LIMITS.arguments-1)}).strict(),z2.object({kind:z2.literal("command"),positionals:z2.object({mode:z2.enum(["exact","prefix"]),tokens:z2.array(arg).max(CLI_RULE_LIMITS.arguments-1)}).strict(),optionsPresent:z2.array(flag).max(100).default([]),optionsAbsent:z2.array(flag).max(100).default([]),optionValues:z2.record(flag,arg).default({})}).strict()]);var cliRuleOperationSchema=z2.discriminatedUnion("kind",[z2.object({id,kind:z2.literal("stub"),stdout:literal,stderr:literal,exitCode:z2.number().int().min(0).max(255)}).strict(),z2.object({id,kind:z2.literal("exec"),argv:z2.array(arg).min(1).max(CLI_RULE_LIMITS.arguments).refine(argv=>argv[0]?.startsWith("/")&&!argv[0].split("/").includes(".."),"Use an absolute executable path without traversal")}).strict(),z2.object({id,kind:z2.literal("replaceOutput"),stream,exit,replacement:literal,...buffer}).strict(),z2.object({id,kind:z2.literal("streamOutput"),stream,edit:z2.object({find:text(8192,true),replace:literal}).strict()}).strict(),z2.object({id,kind:z2.literal("completeOutput"),stream,exit,replace:literal,...buffer,matcher:z2.discriminatedUnion("kind",[z2.object({kind:z2.literal("literal"),text:text(8192,true)}).strict(),z2.object({kind:z2.literal("re2"),pattern:text(2048,true).refine(cliBoundedPattern,"Use literals, optional anchors, and at most one greedy .*")}).strict()])}).strict(),z2.object({id,kind:z2.literal("ensureOption"),option:flag,value:source(arg).optional()}).strict(),z2.object({id,kind:z2.literal("replaceOption"),option:flag,value:source(arg)}).strict(),z2.object({id,kind:z2.literal("setEnv"),key:envKey,value:source(arg),whenAbsent:z2.boolean()}).strict(),z2.object({id,kind:z2.literal("structuredStdin"),format:z2.enum(["text","json","jsonl"]),payload:source(literal),timing:z2.literal("onLaunch"),callerInput:z2.literal("replace"),eof:z2.literal("close")}).strict()]);function cliStructuredInputValid(format,payload){if(format==="text")return true;const records=format==="json"?[payload]:payload.replace(/\r?\n$/,"").split("\n");try{return records.every(record2=>{if(!record2.trim())return false;JSON.parse(record2);return true})}catch{return false}}var cliRuleSchema=z2.object({id,selector:cliRuleSelectorSchema,optionArity:z2.record(flag,z2.union([z2.literal(0),z2.literal(1)])).default({}),operations:z2.array(cliRuleOperationSchema).min(1).max(CLI_RULE_LIMITS.operations)}).strict().superRefine((rule,ctx)=>{const fail=(path,message2)=>ctx.addIssue({code:"custom",path,message:message2});if(Object.keys(rule.optionArity).length>100)fail(["optionArity"],"At most 100 option arities per rule");const arity=(key,expected)=>Object.hasOwn(rule.optionArity,key)&&(expected===void 0||rule.optionArity[key]===expected);if(rule.selector.kind==="command"){const selector=rule.selector;for(const[field,flags]of[["optionsPresent",selector.optionsPresent],["optionsAbsent",selector.optionsAbsent],["optionValues",Object.keys(selector.optionValues)]]){if(new Set(flags).size!==flags.length)fail(["selector",field],"Duplicate option predicate");for(const key of flags)if(!arity(key,field==="optionValues"?1:void 0))fail(["selector",field],`Declare ${key}'s option arity`)}if(selector.optionsAbsent.some(key=>selector.optionsPresent.includes(key)||Object.hasOwn(selector.optionValues,key)))fail(["selector"],"An absent option cannot also be required")}if((rule.selector.kind==="exact"||rule.selector.kind==="prefix")&&rule.operations.some(op=>op.kind==="ensureOption"||op.kind==="replaceOption")){const parsed=parseCliRuleArguments(rule.selector.argv,rule.optionArity);if(parsed.kind==="ambiguous"&&!(rule.selector.kind==="prefix"&&parsed.reason==="missing_value"&&rule.selector.argv.length<CLI_RULE_LIMITS.arguments-1&&parseCliRuleArguments([...rule.selector.argv,""],rule.optionArity).kind==="parsed"))fail(["optionArity"],`Literal rules with argument edits must parse their argv (${parsed.reason}); declare each option's arity and supply its required value`)}if(rule.operations.some(op=>op.kind==="stub"||op.kind==="exec")&&rule.operations.length!==1)fail(["operations"],"A stub or exec must be the only operation in its rule");const ids=new Set;const outputs=new Map;let stdin=false;for(const[index,op]of rule.operations.entries()){const path=["operations",index];if(ids.has(op.id))fail([...path,"id"],"Duplicate operation ID within rule");ids.add(op.id);if(op.kind==="ensureOption"||op.kind==="replaceOption"){if(!arity(op.option,op.value===void 0?0:1))fail(path,"Argument operation value must agree with declared option arity")}else if(op.kind==="structuredStdin"){if(stdin)fail(path,"Only one structured stdin operation per rule");stdin=true;if(op.payload.source==="literal"&&!cliStructuredInputValid(op.format,op.payload.value))fail(path,"Payload does not match its declared JSON/JSONL format")}else if("stream"in op){const previous=outputs.get(op.stream);if(previous&&(previous.kind!==op.kind||op.kind==="replaceOutput"))fail(path,"Use one whole replacement or a chain of one output kind per stream");if(previous&&op.kind==="completeOutput"&&(previous.bytes!==op.maxBufferBytes||previous.wait!==op.maxWaitMs))fail(path,"Completed operations on one stream must share buffer bounds");outputs.set(op.stream,{kind:op.kind,..."maxBufferBytes"in op?{bytes:op.maxBufferBytes,wait:op.maxWaitMs}:{}})}}if(outputs.has("combined")&&outputs.size>1)fail(["operations"],"Combined output cannot be mixed with separate-stream output")});var body={schemaVersion:z2.union([z2.literal(3),z2.literal(4)]),target:cliRuleTargetSchema,rules:z2.array(cliRuleSchema).min(1).max(CLI_RULE_LIMITS.rules),shippingIntent:z2.enum(["default","message","interaction","invocation-guidance","template"])};function jsonTokenCount(value){if(Array.isArray(value))return 1+value.reduce((sum,item)=>sum+jsonTokenCount(item),0);if(value&&typeof value==="object")return 1+Object.values(value).reduce((sum,item)=>sum+1+jsonTokenCount(item),0);return 1}function validateBundle(value,ctx){if(value.schemaVersion===3&&value.rules.some(rule=>rule.operations.some(op=>op.kind==="stub"||op.kind==="exec")))ctx.addIssue({code:"custom",path:["schemaVersion"],message:"Command replacements require schemaVersion 4"});if(new Set(value.rules.map(rule=>rule.id)).size!==value.rules.length)ctx.addIssue({code:"custom",path:["rules"],message:"Duplicate rule ID"});if(value.rules.reduce((count,rule)=>count+rule.operations.length,0)>CLI_RULE_LIMITS.operations)ctx.addIssue({code:"custom",path:["rules"],message:"At most 50 operations across the bundle"});if(cliUtf8Bytes(JSON.stringify(value))>CLI_RULE_LIMITS.bundleBytes)ctx.addIssue({code:"custom",message:"CLI bundle exceeds 2 MiB"});if(jsonTokenCount(value)>CLI_RULE_LIMITS.jsonTokens)ctx.addIssue({code:"custom",message:"CLI bundle exceeds the native JSON token bound"})}var cliRuleAuthorInputSchema=z2.object(body).strict().superRefine(validateBundle);var normalizedLimits=z2.object({expansionBytes:z2.literal(CLI_RULE_LIMITS.expansionBytes),excerptBytes:z2.literal(CLI_RULE_LIMITS.excerptBytes),attemptExcerptBytes:z2.literal(CLI_RULE_LIMITS.attemptExcerptBytes),journalBytes:z2.literal(CLI_RULE_LIMITS.journalBytes),supervisorTasks:z2.literal(CLI_RULE_LIMITS.supervisorTasks)}).strict().default({expansionBytes:CLI_RULE_LIMITS.expansionBytes,excerptBytes:CLI_RULE_LIMITS.excerptBytes,attemptExcerptBytes:CLI_RULE_LIMITS.attemptExcerptBytes,journalBytes:CLI_RULE_LIMITS.journalBytes,supervisorTasks:CLI_RULE_LIMITS.supervisorTasks});var cliRuleBundleSchema=z2.object({...body,limits:normalizedLimits,bundleSha256:z2.string().regex(/^[a-f0-9]{64}$/)}).strict().superRefine(validateBundle);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([]),lifecycle:lifecycleSchema.nullish(),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(),lifecycle:lifecycleSchema.nullish(),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()),lifecycle:lifecycleSchema.nullish(),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,lifecycle:ownedConfigurationInputShape.lifecycle,cadence:ownedConfigurationInputShape.cadence,nextRunAt:ownedConfigurationInputShape.nextRunAt,sampleCount:ownedConfigurationInputShape.sampleCount};var visibilityPromptSettingsPatchShape={agents:ownedConfigurationPatchShape.agents,skillRefs:ownedConfigurationPatchShape.skillRefs,mcpRefs:ownedConfigurationPatchShape.mcpRefs,connectionIds:ownedConfigurationPatchShape.connectionIds,lifecycle:ownedConfigurationPatchShape.lifecycle,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()),lifecycle:lifecycleSchema.nullish(),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({cliRules:cliRuleAuthorInputSchema.optional(),agents:runAgentsOverrideSchema.optional(),sampleCount:runSampleCountOverrideSchema.optional(),lifecycle:lifecycleSchema.nullish()}).strict();var runVisibilityBodySchema=z3.object({cliRules:cliRuleAuthorInputSchema.optional(),agents:runAgentsOverrideSchema.optional(),sampleCount:runSampleCountOverrideSchema.optional(),lifecycle:lifecycleSchema.nullish(),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(),createdBy:createdBySchema,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 csv3=z4.string().transform(s=>s.split(",").map(x=>x.trim()).filter(Boolean));var listEvalSetsQuerySchema=z4.object({agents:csv3.pipe(z4.array(agentSchema)).optional(),models:csv3.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(),createdBy:createdBySchema,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,lifecycle:visibilityPromptSettingsInputShape.lifecycle,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 readFileSync4,statSync as statSync2}from"fs";function hasLifecycleFlags(opts){return opts.setupFile!==void 0||opts.teardownFile!==void 0||opts.setupTimeout!==void 0||opts.teardownTimeout!==void 0||opts.lifecycleParams!==void 0||Boolean(opts.clearSetup||opts.clearTeardown||opts.clearLifecycle)}function addLifecycleOptions(command){return command.option("--setup-file <path>","upload a UTF-8 setup script for hosted sessions (JavaScript/TypeScript)").option("--teardown-file <path>","upload a UTF-8 teardown script for hosted sessions (JavaScript/TypeScript)").option("--setup-timeout <seconds>","setup deadline, 1\u2013600 seconds (new scripts default to 120)").option("--teardown-timeout <seconds>","teardown deadline, 1\u2013600 seconds (new scripts default to 120)").option("--lifecycle-params <json>","replace the scripts' JSON parameter object (maximum 64 KiB)")}function addLifecycleEditOptions(command){return addLifecycleOptions(command).option("--clear-setup","remove setup, preserving teardown and parameters").option("--clear-teardown","remove teardown, preserving setup and parameters").option("--clear-lifecycle","remove both scripts and their parameters")}function readScript(path,phase){const flag2=`--${phase}-file`;if(path==="-")throw new CliError("usage",`${flag2} requires a file path; stdin is not supported`);let bytes;try{const stat2=statSync2(path);if(!stat2.isFile())throw new Error("expected a regular file");if(stat2.size>MAX_LIFECYCLE_SOURCE_LENGTH)throw new Error("script must fit within 128 KiB");bytes=readFileSync4(path)}catch(error){throw new CliError("usage",`could not read ${flag2} ${JSON.stringify(path)}: ${error instanceof Error?error.message:String(error)}`)}if(bytes.byteLength>MAX_LIFECYCLE_SOURCE_LENGTH)throw new CliError("usage",`${flag2} script must fit within 128 KiB`);let source2;try{source2=new TextDecoder("utf-8",{fatal:true,ignoreBOM:true}).decode(bytes)}catch{throw new CliError("usage",`${flag2} must contain valid UTF-8`)}if(!source2.trim()||source2.includes("\0"))throw new CliError("usage",`${flag2} must contain nonempty script text without NUL bytes`);return source2}function timeout(raw,phase){if(raw===void 0)return void 0;const value=Number(raw);if(!Number.isInteger(value)||value<1||value>MAX_LIFECYCLE_TIMEOUT_SECONDS)throw new CliError("usage",`--${phase}-timeout must be an integer from 1 to ${MAX_LIFECYCLE_TIMEOUT_SECONDS}`);return value}function lifecyclePatchFromOpts(opts,existing){if(!hasLifecycleFlags(opts))return{};if(opts.clearLifecycle){if(hasLifecycleFlags({...opts,clearLifecycle:false}))throw new CliError("usage","--clear-lifecycle conflicts with other lifecycle flags");return{lifecycle:null}}const current=existing==null?void 0:lifecycleSchema.safeParse(existing);if(current&&!current.success)throw new CliError("usage","The saved lifecycle configuration is unsupported; update the CLI before editing it");const value=current?.success?{...current.data}:{version:1,params:{}};for(const phase of["setup","teardown"]){const path=phase==="setup"?opts.setupFile:opts.teardownFile;const rawTimeout=phase==="setup"?opts.setupTimeout:opts.teardownTimeout;const clear=phase==="setup"?opts.clearSetup:opts.clearTeardown;if(clear&&(path!==void 0||rawTimeout!==void 0))throw new CliError("usage",`--clear-${phase} conflicts with --${phase}-file/--${phase}-timeout`);if(clear){delete value[phase];continue}const seconds=timeout(rawTimeout,phase);const source2=path===void 0?value[phase]?.source:readScript(path,phase);if(seconds!==void 0&&source2===void 0)throw new CliError("usage",`--${phase}-timeout requires --${phase}-file or a saved ${phase} script`);if(source2!==void 0)value[phase]={source:source2,timeoutSeconds:seconds??value[phase]?.timeoutSeconds??DEFAULT_LIFECYCLE_TIMEOUT_SECONDS}}if(opts.lifecycleParams!==void 0){try{value.params=JSON.parse(opts.lifecycleParams)}catch{throw new CliError("usage","--lifecycle-params must be a JSON object")}}if(!value.setup&&!value.teardown){if(opts.lifecycleParams!==void 0)throw new CliError("usage","--lifecycle-params requires a setup or teardown script");return{lifecycle:null}}const parsed=lifecycleSchema.safeParse(value);if(!parsed.success)throw new CliError("usage",parsed.error.issues[0]?.message??"Invalid lifecycle configuration");return{lifecycle:parsed.data}}import{readFileSync as readFileSync5}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(flag2){return(value,previous)=>{if(previous!==void 0)throw new CliError("usage",`${flag2} 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 text2=readFileSync5(opts.file==="-"?0:opts.file,"utf8").trim();if(!text2)throw new CliError("usage","prompt file is empty");return text2}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{...lifecyclePatchFromOpts(opts),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,lifecycle){const patch=lifecyclePatchFromOpts(opts,lifecycle);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 addLifecycleOptions(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 addLifecycleEditOptions(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 hasLifecycleFlags(opts)||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{...lifecyclePatchFromOpts(opts),...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,lifecycle){return ownedConfigPatchFromOpts(opts,lifecycle)}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 id2=c.id??`cr_${randomUUID3()}`;if(!id2||ids.has(id2))throw new CliError("usage",`Duplicate or empty criterion ID: ${id2}`);ids.add(id2);return{id:id2,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 id2=typeof suppliedId==="string"?suppliedId:`sc_${randomUUID3()}`;if(ids.has(id2))throw new CliError("usage",`Duplicate scenario ID: ${id2}`);ids.add(id2);return{id:id2,repoUrl,repoRef,profileId:null}})}return value}function editable(row2){const{id:id2,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,id2,patch){return withLocalStore(command,store=>{const current=store.requireMeasurement(id2,kind);const value=normalize(kind,{...editable(current),...patch},current);if(!("criteria"in patch)&&current.criteria)value.criteria=current.criteria;if(!("scenarios"in patch)&&current.scenarios)value.scenarios=current.scenarios;return store.updateMeasurement(id2,value)})}function getLocalMeasurement(command,kind,id2){return withLocalStore(command,store=>measurementWithStats(store,store.requireMeasurement(id2,kind)))}function removeLocalMeasurement(command,kind,id2){withLocalStore(command,store=>{store.requireMeasurement(id2,kind);store.deleteMeasurement(id2)})}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,id2,opts){const row2=getLocalMeasurement(command,kind,id2);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:id2,kind,revision:row2.revision,...kind==="eval"?{criterionIds:row2.criteria.map(c=>c.id)}:{}}}}import{readFileSync as readFileSync6}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,id2){return`${evalSetsPath(org)}/${encodeURIComponent(id2)}`}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(readFileSync6(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,id2){const evalSet=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"eval",id2)):await createClient().get(evalSetPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)==="json")printJson(evalSet);else printDetail(evalSet)}async function createEvalSet(cmd,opts){if(hasLifecycleFlags(opts)&&isLocal(cmd))throw new CliError("usage","Lifecycle scripts require hosted execution; pass --hosted");const criteria=criteriaFromOpts(opts);if(!criteria)throw new CliError("usage","at least one --criterion (or --criteria-file) is required");const body2={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",body2):await createClient().post(evalSetsPath(await resolveOrg(cmd)),body2);if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created eval set ${created.id}`)}async function editEvalSet(cmd,id2,opts){if(hasLifecycleFlags(opts)&&isLocal(cmd))throw new CliError("usage","Lifecycle scripts require hosted execution; pass --hosted");const lifecyclePath=hasLifecycleFlags(opts)&&!opts.clearLifecycle?evalSetPath(await resolveOrg(cmd),id2):void 0;const existing=lifecyclePath?await createClient().get(lifecyclePath):void 0;const body2=ownedConfigPatchFromOpts(opts,existing?.lifecycle);if(opts.name!==void 0)body2.name=opts.name;if(opts.text!==void 0||opts.file!==void 0)body2.promptText=readPromptText(opts);const criteria=criteriaFromOpts(opts);if(criteria)body2.criteria=criteria;if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");if(opts.clearTags)body2.tags=[];else if(opts.tag.length>0)body2.tags=opts.tag;if(Object.keys(body2).length===0)throw new CliError("usage","nothing to change");const updated=isLocal(cmd)?editLocalMeasurement(cmd,"eval",id2,body2):await createClient().patch(lifecyclePath??evalSetPath(await resolveOrg(cmd),id2),body2);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated eval set ${updated.id}`)}async function removeEvalSet(cmd,id2){if(isLocal(cmd))removeLocalMeasurement(cmd,"eval",id2);else await createClient().delete(evalSetPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)!=="json")console.log(`Deleted eval set ${id2}`)}async function runEvalSet(cmd,id2,opts){const org=await resolveOrg(cmd);const overrides={...runOverridesFromOpts(opts),...opts.cliRules?{cliRules:opts.cliRules}:{},...hasLifecycleFlags(opts)?lifecyclePatchFromOpts(opts,(await createClient().get(evalSetPath(org,id2))).lifecycle):{}};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,id2)}/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}`)}return result}function register10(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(id2,_opts,cmd)=>{await getEvalSet(cmd,id2)});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(id2,opts,cmd)=>{await editEvalSet(cmd,id2,opts)});evals.command("rm <id>").description("Delete an eval set (run history stays)").action(async(id2,_opts,cmd)=>{await removeEvalSet(cmd,id2)})}var feedback_exports2={};__export(feedback_exports2,{register:()=>register11});import{Option as Option3}from"commander";function register11(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 body2={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",body2);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:()=>register12});var CLI_RULES=`---
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:()=>register6});import{join as join5}from"path";function register6(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:()=>register7});function assertKey(key){if(CONFIG_KEYS.includes(key)){return key}throw new CliError("usage",`Unknown config key '${key}'. Valid keys: ${CONFIG_KEYS.join(", ")}`)}function register7(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:()=>register8});function connectionsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/connections`}function register8(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:()=>register9});import{readFileSync as readFileSync3}from"fs";function dashboardsPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/dashboards`}function register9(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:()=>register10});import{randomUUID as randomUUID3}from"crypto";import{join as join6}from"path";import{z as z4}from"zod";import{z as z2}from"zod";function parseCliRuleArguments(argv,arity){const value={positionals:[],options:new Map,endOptions:argv.length};for(let i=0;i<argv.length;i++){const token=argv[i];if(token==="--"){value.endOptions=i;value.positionals.push(...argv.slice(i+1));break}if(!token.startsWith("-")||token==="-"){value.positionals.push(token);continue}const equal=token.indexOf("=");const flag2=equal<0?token:token.slice(0,equal);if(!Object.hasOwn(arity,flag2)||!flag2.startsWith("--")&&flag2.length!==2)return{kind:"ambiguous",reason:"unknown_option"};if(arity[flag2]===0){if(equal>=0)return{kind:"ambiguous",reason:"unexpected_value"};value.options.set(flag2,{index:i,width:1})}else if(equal>=0){value.options.set(flag2,{index:i,width:1,value:token.slice(equal+1)})}else{if(i+1===argv.length||argv[i+1]==="--")return{kind:"ambiguous",reason:"missing_value"};value.options.set(flag2,{index:i,width:2,value:argv[i+1]});i++}}return{kind:"parsed",value}}var CLI_RULE_LIMITS={bundleBytes:2*1024*1024,jsonTokens:4e4,rules:50,operations:50,arguments:256,argumentBytes:4095,literalBytes:8192,bufferBytes:2*1024*1024,bufferWaitMs:5e3,maxBufferWaitMs:12e4,expansionBytes:64*1024*1024,excerptBytes:4096,attemptExcerptBytes:256*1024,journalBytes:4*1024*1024,supervisorTasks:4096};var encoder=new TextEncoder;var cliUtf8Bytes=value=>encoder.encode(value).length;var text=(max,nonempty=false)=>z2.string().superRefine((value,ctx)=>{if(nonempty&&!value.length||cliUtf8Bytes(value)>max||/\0|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u.test(value))ctx.addIssue({code:"custom",message:`Use valid non-NUL UTF-8 text of at most ${max} bytes${nonempty?", not empty":""}`})});var id=z2.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/);var flag=z2.string().regex(/^(?:-[A-Za-z0-9]|--[A-Za-z0-9][A-Za-z0-9-]{0,125})$/);var envKey=z2.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,126}$/);var arg=text(CLI_RULE_LIMITS.argumentBytes);var literal=text(CLI_RULE_LIMITS.literalBytes);var stream=z2.enum(["stdout","stderr","combined"]);var exit=z2.discriminatedUnion("kind",[z2.object({kind:z2.literal("any")}).strict(),z2.object({kind:z2.literal("code"),value:z2.number().int().min(0).max(255)}).strict()]);var buffer={maxBufferBytes:z2.number().int().min(1).max(CLI_RULE_LIMITS.bufferBytes).default(CLI_RULE_LIMITS.bufferBytes),maxWaitMs:z2.number().int().min(1).max(CLI_RULE_LIMITS.maxBufferWaitMs).default(CLI_RULE_LIMITS.bufferWaitMs)};var source=value=>z2.discriminatedUnion("source",[z2.object({source:z2.literal("literal"),value}).strict(),z2.object({source:z2.literal("localFact"),key:envKey}).strict()]);function cliBoundedPattern(pattern){let at=pattern.startsWith("^")?1:0;const end=pattern.endsWith("$")&&pattern.length>at?pattern.length-1:pattern.length;let stars=0;let literals=0;while(at<end){const char=pattern[at];if(char==="\\"){if(++at>=end||!"\\.^$*+?[]{}()|".includes(pattern[at]))return false;literals++}else if(char==="."&&pattern[at+1]==="*"){if(++stars>1)return false;at++}else if(".^$*+?[]{}()|\n\r".includes(char))return false;else literals++;at++}return literals>0}var cliRuleTargetSchema=z2.discriminatedUnion("kind",[z2.object({kind:z2.literal("npmBin"),packageName:z2.string().max(214).regex(/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/),program:z2.string().max(128).regex(/^[A-Za-z0-9][A-Za-z0-9._-]*$/)}).strict(),z2.object({kind:z2.literal("path"),path:text(1024,true).refine(value=>!value.includes("\\")&&!value.split("/").includes(".."),"Use a sandbox path without traversal")}).strict()]);var cliRuleSelectorSchema=z2.discriminatedUnion("kind",[z2.object({kind:z2.literal("prefix"),argv:z2.array(arg).max(CLI_RULE_LIMITS.arguments-1)}).strict(),z2.object({kind:z2.literal("exact"),argv:z2.array(arg).max(CLI_RULE_LIMITS.arguments-1)}).strict(),z2.object({kind:z2.literal("command"),positionals:z2.object({mode:z2.enum(["exact","prefix"]),tokens:z2.array(arg).max(CLI_RULE_LIMITS.arguments-1)}).strict(),optionsPresent:z2.array(flag).max(100).default([]),optionsAbsent:z2.array(flag).max(100).default([]),optionValues:z2.record(flag,arg).default({})}).strict()]);var cliRuleOperationSchema=z2.discriminatedUnion("kind",[z2.object({id,kind:z2.literal("stub"),stdout:literal,stderr:literal,exitCode:z2.number().int().min(0).max(255)}).strict(),z2.object({id,kind:z2.literal("exec"),argv:z2.array(arg).min(1).max(CLI_RULE_LIMITS.arguments).refine(argv=>argv[0]?.startsWith("/")&&!argv[0].split("/").includes(".."),"Use an absolute executable path without traversal")}).strict(),z2.object({id,kind:z2.literal("replaceOutput"),stream,exit,replacement:literal,...buffer}).strict(),z2.object({id,kind:z2.literal("streamOutput"),stream,edit:z2.object({find:text(8192,true),replace:literal}).strict()}).strict(),z2.object({id,kind:z2.literal("completeOutput"),stream,exit,replace:literal,...buffer,matcher:z2.discriminatedUnion("kind",[z2.object({kind:z2.literal("literal"),text:text(8192,true)}).strict(),z2.object({kind:z2.literal("re2"),pattern:text(2048,true).refine(cliBoundedPattern,"Use literals, optional anchors, and at most one greedy .*")}).strict()])}).strict(),z2.object({id,kind:z2.literal("ensureOption"),option:flag,value:source(arg).optional()}).strict(),z2.object({id,kind:z2.literal("replaceOption"),option:flag,value:source(arg)}).strict(),z2.object({id,kind:z2.literal("setEnv"),key:envKey,value:source(arg),whenAbsent:z2.boolean()}).strict(),z2.object({id,kind:z2.literal("structuredStdin"),format:z2.enum(["text","json","jsonl"]),payload:source(literal),timing:z2.literal("onLaunch"),callerInput:z2.literal("replace"),eof:z2.literal("close")}).strict()]);function cliStructuredInputValid(format,payload){if(format==="text")return true;const records=format==="json"?[payload]:payload.replace(/\r?\n$/,"").split("\n");try{return records.every(record2=>{if(!record2.trim())return false;JSON.parse(record2);return true})}catch{return false}}var cliRuleSchema=z2.object({id,selector:cliRuleSelectorSchema,optionArity:z2.record(flag,z2.union([z2.literal(0),z2.literal(1)])).default({}),operations:z2.array(cliRuleOperationSchema).min(1).max(CLI_RULE_LIMITS.operations)}).strict().superRefine((rule,ctx)=>{const fail=(path,message2)=>ctx.addIssue({code:"custom",path,message:message2});if(Object.keys(rule.optionArity).length>100)fail(["optionArity"],"At most 100 option arities per rule");const arity=(key,expected)=>Object.hasOwn(rule.optionArity,key)&&(expected===void 0||rule.optionArity[key]===expected);if(rule.selector.kind==="command"){const selector=rule.selector;for(const[field,flags]of[["optionsPresent",selector.optionsPresent],["optionsAbsent",selector.optionsAbsent],["optionValues",Object.keys(selector.optionValues)]]){if(new Set(flags).size!==flags.length)fail(["selector",field],"Duplicate option predicate");for(const key of flags)if(!arity(key,field==="optionValues"?1:void 0))fail(["selector",field],`Declare ${key}'s option arity`)}if(selector.optionsAbsent.some(key=>selector.optionsPresent.includes(key)||Object.hasOwn(selector.optionValues,key)))fail(["selector"],"An absent option cannot also be required")}if((rule.selector.kind==="exact"||rule.selector.kind==="prefix")&&rule.operations.some(op=>op.kind==="ensureOption"||op.kind==="replaceOption")){const parsed=parseCliRuleArguments(rule.selector.argv,rule.optionArity);if(parsed.kind==="ambiguous"&&!(rule.selector.kind==="prefix"&&parsed.reason==="missing_value"&&rule.selector.argv.length<CLI_RULE_LIMITS.arguments-1&&parseCliRuleArguments([...rule.selector.argv,""],rule.optionArity).kind==="parsed"))fail(["optionArity"],`Literal rules with argument edits must parse their argv (${parsed.reason}); declare each option's arity and supply its required value`)}if(rule.operations.some(op=>op.kind==="stub"||op.kind==="exec")&&rule.operations.length!==1)fail(["operations"],"A stub or exec must be the only operation in its rule");const ids=new Set;const outputs=new Map;let stdin=false;for(const[index,op]of rule.operations.entries()){const path=["operations",index];if(ids.has(op.id))fail([...path,"id"],"Duplicate operation ID within rule");ids.add(op.id);if(op.kind==="ensureOption"||op.kind==="replaceOption"){if(!arity(op.option,op.value===void 0?0:1))fail(path,"Argument operation value must agree with declared option arity")}else if(op.kind==="structuredStdin"){if(stdin)fail(path,"Only one structured stdin operation per rule");stdin=true;if(op.payload.source==="literal"&&!cliStructuredInputValid(op.format,op.payload.value))fail(path,"Payload does not match its declared JSON/JSONL format")}else if("stream"in op){const previous=outputs.get(op.stream);if(previous&&(previous.kind!==op.kind||op.kind==="replaceOutput"))fail(path,"Use one whole replacement or a chain of one output kind per stream");if(previous&&op.kind==="completeOutput"&&(previous.bytes!==op.maxBufferBytes||previous.wait!==op.maxWaitMs))fail(path,"Completed operations on one stream must share buffer bounds");outputs.set(op.stream,{kind:op.kind,..."maxBufferBytes"in op?{bytes:op.maxBufferBytes,wait:op.maxWaitMs}:{}})}}if(outputs.has("combined")&&outputs.size>1)fail(["operations"],"Combined output cannot be mixed with separate-stream output")});var body={schemaVersion:z2.union([z2.literal(3),z2.literal(4)]),target:cliRuleTargetSchema,rules:z2.array(cliRuleSchema).min(1).max(CLI_RULE_LIMITS.rules),shippingIntent:z2.enum(["default","message","interaction","invocation-guidance","template"])};function jsonTokenCount(value){if(Array.isArray(value))return 1+value.reduce((sum,item)=>sum+jsonTokenCount(item),0);if(value&&typeof value==="object")return 1+Object.values(value).reduce((sum,item)=>sum+1+jsonTokenCount(item),0);return 1}function validateBundle(value,ctx){if(value.schemaVersion===3&&value.rules.some(rule=>rule.operations.some(op=>op.kind==="stub"||op.kind==="exec")))ctx.addIssue({code:"custom",path:["schemaVersion"],message:"Command replacements require schemaVersion 4"});if(new Set(value.rules.map(rule=>rule.id)).size!==value.rules.length)ctx.addIssue({code:"custom",path:["rules"],message:"Duplicate rule ID"});if(value.rules.reduce((count,rule)=>count+rule.operations.length,0)>CLI_RULE_LIMITS.operations)ctx.addIssue({code:"custom",path:["rules"],message:"At most 50 operations across the bundle"});if(cliUtf8Bytes(JSON.stringify(value))>CLI_RULE_LIMITS.bundleBytes)ctx.addIssue({code:"custom",message:"CLI bundle exceeds 2 MiB"});if(jsonTokenCount(value)>CLI_RULE_LIMITS.jsonTokens)ctx.addIssue({code:"custom",message:"CLI bundle exceeds the native JSON token bound"})}var cliRuleAuthorInputSchema=z2.object(body).strict().superRefine(validateBundle);var normalizedLimits=z2.object({expansionBytes:z2.literal(CLI_RULE_LIMITS.expansionBytes),excerptBytes:z2.literal(CLI_RULE_LIMITS.excerptBytes),attemptExcerptBytes:z2.literal(CLI_RULE_LIMITS.attemptExcerptBytes),journalBytes:z2.literal(CLI_RULE_LIMITS.journalBytes),supervisorTasks:z2.literal(CLI_RULE_LIMITS.supervisorTasks)}).strict().default({expansionBytes:CLI_RULE_LIMITS.expansionBytes,excerptBytes:CLI_RULE_LIMITS.excerptBytes,attemptExcerptBytes:CLI_RULE_LIMITS.attemptExcerptBytes,journalBytes:CLI_RULE_LIMITS.journalBytes,supervisorTasks:CLI_RULE_LIMITS.supervisorTasks});var cliRuleBundleSchema=z2.object({...body,limits:normalizedLimits,bundleSha256:z2.string().regex(/^[a-f0-9]{64}$/)}).strict().superRefine(validateBundle);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([]),lifecycle:lifecycleSchema.nullish(),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(),lifecycle:lifecycleSchema.nullish(),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()),lifecycle:lifecycleSchema.nullish(),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={profileId:ownedConfigurationInputShape.profileId,agents:ownedConfigurationInputShape.agents,skillRefs:ownedConfigurationInputShape.skillRefs,mcpRefs:ownedConfigurationInputShape.mcpRefs,connectionIds:ownedConfigurationInputShape.connectionIds,lifecycle:ownedConfigurationInputShape.lifecycle,cadence:ownedConfigurationInputShape.cadence,nextRunAt:ownedConfigurationInputShape.nextRunAt,sampleCount:ownedConfigurationInputShape.sampleCount};var visibilityPromptSettingsPatchShape={profileId:ownedConfigurationPatchShape.profileId,agents:ownedConfigurationPatchShape.agents,skillRefs:ownedConfigurationPatchShape.skillRefs,mcpRefs:ownedConfigurationPatchShape.mcpRefs,connectionIds:ownedConfigurationPatchShape.connectionIds,lifecycle:ownedConfigurationPatchShape.lifecycle,cadence:ownedConfigurationPatchShape.cadence,nextRunAt:ownedConfigurationPatchShape.nextRunAt,sampleCount:ownedConfigurationPatchShape.sampleCount};var visibilityPromptSettingsSchema=z3.object({profile:z3.object({id:z3.string(),name:z3.string()}).nullish(),agents:z3.array(agentConfigSchema),skillRefs:z3.array(z3.string()),mcpRefs:z3.array(z3.string()),connectionIds:z3.array(z3.string()),lifecycle:lifecycleSchema.nullish(),cadence:ownedCadenceSchema,sampleCount:sampleCountSchema,lastScheduledAt:z3.string().nullish(),nextRunAt:z3.string().nullish()});var runAgentsOverrideSchema=z3.array(agentConfigInputSchema).min(1,"Select at least one agent");var runSampleCountOverrideSchema=sampleCountSchema;var runEvalBodySchema=z3.object({cliRules:cliRuleAuthorInputSchema.optional(),agents:runAgentsOverrideSchema.optional(),sampleCount:runSampleCountOverrideSchema.optional(),lifecycle:lifecycleSchema.nullish()}).strict();var runVisibilityBodySchema=z3.object({cliRules:cliRuleAuthorInputSchema.optional(),agents:runAgentsOverrideSchema.optional(),sampleCount:runSampleCountOverrideSchema.optional(),lifecycle:lifecycleSchema.nullish(),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(),createdBy:createdBySchema,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 csv3=z4.string().transform(s=>s.split(",").map(x=>x.trim()).filter(Boolean));var listEvalSetsQuerySchema=z4.object({agents:csv3.pipe(z4.array(agentSchema)).optional(),models:csv3.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(),createdBy:createdBySchema,tags:z5.array(z5.string()),runCount:z5.number().int(),lastRunAt:z5.string().nullable(),scenarios:z5.array(visibilityScenarioSchema),tracked:z5.boolean().optional()});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(),profileId:visibilityPromptSettingsInputShape.profileId,agents:visibilityPromptSettingsInputShape.agents.optional(),skillRefs:visibilityPromptSettingsInputShape.skillRefs,mcpRefs:visibilityPromptSettingsInputShape.mcpRefs,connectionIds:visibilityPromptSettingsInputShape.connectionIds,lifecycle:visibilityPromptSettingsInputShape.lifecycle,cadence:visibilityPromptSettingsInputShape.cadence,sampleCount:visibilityPromptSettingsInputShape.sampleCount,tracked:z5.boolean().optional(),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,tracked:z5.boolean().optional(),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 readFileSync4,statSync as statSync2}from"fs";function hasLifecycleFlags(opts){return opts.setupFile!==void 0||opts.teardownFile!==void 0||opts.setupTimeout!==void 0||opts.teardownTimeout!==void 0||opts.lifecycleParams!==void 0||Boolean(opts.clearSetup||opts.clearTeardown||opts.clearLifecycle)}function addLifecycleOptions(command){return command.option("--setup-file <path>","upload a UTF-8 setup script for hosted sessions (JavaScript/TypeScript)").option("--teardown-file <path>","upload a UTF-8 teardown script for hosted sessions (JavaScript/TypeScript)").option("--setup-timeout <seconds>","setup deadline, 1\u2013600 seconds (new scripts default to 120)").option("--teardown-timeout <seconds>","teardown deadline, 1\u2013600 seconds (new scripts default to 120)").option("--lifecycle-params <json>","replace the scripts' JSON parameter object (maximum 64 KiB)")}function addLifecycleEditOptions(command){return addLifecycleOptions(command).option("--clear-setup","remove setup, preserving teardown and parameters").option("--clear-teardown","remove teardown, preserving setup and parameters").option("--clear-lifecycle","remove both scripts and their parameters")}function readScript(path,phase){const flag2=`--${phase}-file`;if(path==="-")throw new CliError("usage",`${flag2} requires a file path; stdin is not supported`);let bytes;try{const stat2=statSync2(path);if(!stat2.isFile())throw new Error("expected a regular file");if(stat2.size>MAX_LIFECYCLE_SOURCE_LENGTH)throw new Error("script must fit within 128 KiB");bytes=readFileSync4(path)}catch(error){throw new CliError("usage",`could not read ${flag2} ${JSON.stringify(path)}: ${error instanceof Error?error.message:String(error)}`)}if(bytes.byteLength>MAX_LIFECYCLE_SOURCE_LENGTH)throw new CliError("usage",`${flag2} script must fit within 128 KiB`);let source2;try{source2=new TextDecoder("utf-8",{fatal:true,ignoreBOM:true}).decode(bytes)}catch{throw new CliError("usage",`${flag2} must contain valid UTF-8`)}if(!source2.trim()||source2.includes("\0"))throw new CliError("usage",`${flag2} must contain nonempty script text without NUL bytes`);return source2}function timeout(raw,phase){if(raw===void 0)return void 0;const value=Number(raw);if(!Number.isInteger(value)||value<1||value>MAX_LIFECYCLE_TIMEOUT_SECONDS)throw new CliError("usage",`--${phase}-timeout must be an integer from 1 to ${MAX_LIFECYCLE_TIMEOUT_SECONDS}`);return value}function lifecyclePatchFromOpts(opts,existing){if(!hasLifecycleFlags(opts))return{};if(opts.clearLifecycle){if(hasLifecycleFlags({...opts,clearLifecycle:false}))throw new CliError("usage","--clear-lifecycle conflicts with other lifecycle flags");return{lifecycle:null}}const current=existing==null?void 0:lifecycleSchema.safeParse(existing);if(current&&!current.success)throw new CliError("usage","The saved lifecycle configuration is unsupported; update the CLI before editing it");const value=current?.success?{...current.data}:{version:1,params:{}};for(const phase of["setup","teardown"]){const path=phase==="setup"?opts.setupFile:opts.teardownFile;const rawTimeout=phase==="setup"?opts.setupTimeout:opts.teardownTimeout;const clear=phase==="setup"?opts.clearSetup:opts.clearTeardown;if(clear&&(path!==void 0||rawTimeout!==void 0))throw new CliError("usage",`--clear-${phase} conflicts with --${phase}-file/--${phase}-timeout`);if(clear){delete value[phase];continue}const seconds=timeout(rawTimeout,phase);const source2=path===void 0?value[phase]?.source:readScript(path,phase);if(seconds!==void 0&&source2===void 0)throw new CliError("usage",`--${phase}-timeout requires --${phase}-file or a saved ${phase} script`);if(source2!==void 0)value[phase]={source:source2,timeoutSeconds:seconds??value[phase]?.timeoutSeconds??DEFAULT_LIFECYCLE_TIMEOUT_SECONDS}}if(opts.lifecycleParams!==void 0){try{value.params=JSON.parse(opts.lifecycleParams)}catch{throw new CliError("usage","--lifecycle-params must be a JSON object")}}if(!value.setup&&!value.teardown){if(opts.lifecycleParams!==void 0)throw new CliError("usage","--lifecycle-params requires a setup or teardown script");return{lifecycle:null}}const parsed=lifecycleSchema.safeParse(value);if(!parsed.success)throw new CliError("usage",parsed.error.issues[0]?.message??"Invalid lifecycle configuration");return{lifecycle:parsed.data}}import{readFileSync as readFileSync5}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(flag2){return(value,previous)=>{if(previous!==void 0)throw new CliError("usage",`${flag2} 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 text2=readFileSync5(opts.file==="-"?0:opts.file,"utf8").trim();if(!text2)throw new CliError("usage","prompt file is empty");return text2}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{...lifecyclePatchFromOpts(opts),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,lifecycle){const patch=lifecyclePatchFromOpts(opts,lifecycle);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,{cadence=true}={}){addLifecycleOptions(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,[]);if(cadence)command.option("--cadence <cadence>","none | daily | weekly | monthly","none");return command.option("--samples <n>","sample count from 1 to 50","1")}function addRunSettingsEditOptions(command,{cadence=true}={}){addLifecycleEditOptions(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");if(cadence)command.option("--cadence <cadence>","none | daily | weekly | monthly");return command.option("--samples <n>","sample count from 1 to 50")}function hasRunSettingsFlags(opts){return hasLifecycleFlags(opts)||opts.agent.length>0||opts.skill.length>0||opts.mcp.length>0||opts.connection.length>0||(opts.cadence??"none").toUpperCase()!=="NONE"||opts.samples!=="1"}function runSettingsFromOpts(opts){return{...lifecyclePatchFromOpts(opts),...opts.agent.length>0?{agents:buildAgentRoster(opts.agent)}:{},skillRefs:validateAssetRefs("skill",opts.skill),mcpRefs:validateAssetRefs("mcp",opts.mcp),connectionIds:opts.connection,...opts.cadence!==void 0?{cadence:parseCadence(opts.cadence)}:{},sampleCount:parseSampleCount(opts.samples)}}function runSettingsPatchFromOpts(opts,lifecycle){return ownedConfigPatchFromOpts(opts,lifecycle)}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 id2=c.id??`cr_${randomUUID3()}`;if(!id2||ids.has(id2))throw new CliError("usage",`Duplicate or empty criterion ID: ${id2}`);ids.add(id2);return{id:id2,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 id2=typeof suppliedId==="string"?suppliedId:`sc_${randomUUID3()}`;if(ids.has(id2))throw new CliError("usage",`Duplicate scenario ID: ${id2}`);ids.add(id2);return{id:id2,repoUrl,repoRef,profileId:null}})}return value}function editable(row2){const{id:id2,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,id2,patch){return withLocalStore(command,store=>{const current=store.requireMeasurement(id2,kind);const value=normalize(kind,{...editable(current),...patch},current);if(!("criteria"in patch)&&current.criteria)value.criteria=current.criteria;if(!("scenarios"in patch)&&current.scenarios)value.scenarios=current.scenarios;return store.updateMeasurement(id2,value)})}function getLocalMeasurement(command,kind,id2){return withLocalStore(command,store=>measurementWithStats(store,store.requireMeasurement(id2,kind)))}function removeLocalMeasurement(command,kind,id2){withLocalStore(command,store=>{store.requireMeasurement(id2,kind);store.deleteMeasurement(id2)})}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,id2,opts){const row2=getLocalMeasurement(command,kind,id2);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:id2,kind,revision:row2.revision,...kind==="eval"?{criterionIds:row2.criteria.map(c=>c.id)}:{}}}}import{readFileSync as readFileSync6}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,id2){return`${evalSetsPath(org)}/${encodeURIComponent(id2)}`}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(readFileSync6(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,id2){const evalSet=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"eval",id2)):await createClient().get(evalSetPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)==="json")printJson(evalSet);else printDetail(evalSet)}async function createEvalSet(cmd,opts){if(hasLifecycleFlags(opts)&&isLocal(cmd))throw new CliError("usage","Lifecycle scripts require hosted execution; pass --hosted");const criteria=criteriaFromOpts(opts);if(!criteria)throw new CliError("usage","at least one --criterion (or --criteria-file) is required");const body2={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",body2):await createClient().post(evalSetsPath(await resolveOrg(cmd)),body2);if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created eval set ${created.id}`)}async function editEvalSet(cmd,id2,opts){if(hasLifecycleFlags(opts)&&isLocal(cmd))throw new CliError("usage","Lifecycle scripts require hosted execution; pass --hosted");const lifecyclePath=hasLifecycleFlags(opts)&&!opts.clearLifecycle?evalSetPath(await resolveOrg(cmd),id2):void 0;const existing=lifecyclePath?await createClient().get(lifecyclePath):void 0;const body2=ownedConfigPatchFromOpts(opts,existing?.lifecycle);if(opts.name!==void 0)body2.name=opts.name;if(opts.text!==void 0||opts.file!==void 0)body2.promptText=readPromptText(opts);const criteria=criteriaFromOpts(opts);if(criteria)body2.criteria=criteria;if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");if(opts.clearTags)body2.tags=[];else if(opts.tag.length>0)body2.tags=opts.tag;if(Object.keys(body2).length===0)throw new CliError("usage","nothing to change");const updated=isLocal(cmd)?editLocalMeasurement(cmd,"eval",id2,body2):await createClient().patch(lifecyclePath??evalSetPath(await resolveOrg(cmd),id2),body2);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated eval set ${updated.id}`)}async function removeEvalSet(cmd,id2){if(isLocal(cmd))removeLocalMeasurement(cmd,"eval",id2);else await createClient().delete(evalSetPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)!=="json")console.log(`Deleted eval set ${id2}`)}async function runEvalSet(cmd,id2,opts){const org=await resolveOrg(cmd);const overrides={...runOverridesFromOpts(opts),...opts.cliRules?{cliRules:opts.cliRules}:{},...hasLifecycleFlags(opts)?lifecyclePatchFromOpts(opts,(await createClient().get(evalSetPath(org,id2))).lifecycle):{}};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,id2)}/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}`)}return result}function register10(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(id2,_opts,cmd)=>{await getEvalSet(cmd,id2)});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(id2,opts,cmd)=>{await editEvalSet(cmd,id2,opts)});evals.command("rm <id>").description("Delete an eval set (run history stays)").action(async(id2,_opts,cmd)=>{await removeEvalSet(cmd,id2)})}var feedback_exports2={};__export(feedback_exports2,{register:()=>register11});import{Option as Option3}from"commander";function register11(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 body2={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",body2);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:()=>register12});var CLI_RULES=`---
37
37
  name: gauge-cli-rules
38
38
  description: Stub or redirect CLI invocations in a hosted session without changing the fixture repository.
39
39
  ---
@@ -86,9 +86,9 @@ In the session viewer, check CLI rules, command annotations, and the agent's nex
86
86
  actions. For command/output evidence, use
87
87
  \`gauge run commands <run-id> --hosted\` and \`gauge run trace <run-id> --hosted\`.
88
88
  Configuring a rule is not proof it fired.
89
- `;var AUTHORING=`- Measure one meaningful developer outcome. Record the learning goal, reproducible starting state, observable finish line, and execution budget; a coherent migration can span browser and server workflows.
90
- - Write the prompt as a real user's request, in their language. Describe their goal, relevant context, and intended outcome. Preserve constraints they actually supplied; do not assume technical expertise or invent features, UI actions, business rules, commands, filenames, or verification recipes. Leave discovery and implementation choices to the agent.
91
- - Align a small set of independently assessable criteria with the requested outcome and existing application. Accept equivalent supported approaches and execution evidence; remove hidden requirements when revising the prompt.`;var MIGRATION_EXAMPLE=`## Migration prompt and criteria
89
+ `;var AUTHORING=`- Measure one meaningful developer outcome. Record the learning goal, reproducible starting state, observable finish line, and execution budget; a coherent migration can span browser and server workflows. Include verification in the scope: require enough evidence to establish the outcome without adding unrelated features or exhaustive testing. When a pilot times out, inspect where the effort went before extending the budget.
90
+ - Write the prompt as a real user's request, in their language, usually one to three first-person sentences. Describe the goal and necessary context. Preserve the user's constraints; leave discovery and implementation choices to the agent. Do not supply commands, filenames, API calls, or step-by-step plans unless the user requested them. Research docs to establish that the task is feasible, without turning the prompt into a tutorial. Keep credentials and environment setup in supported configuration or fixtures.
91
+ - Use a small set of independently assessable criteria describing observable success. The judge does not share this conversation: each criterion must state what to verify and include any necessary reference facts. Every requirement must follow from the prompt or existing application. Accept equivalent supported approaches and execution evidence. When simplifying a prompt, remove the same requirements from its rubric so they do not survive as hidden tests.`;var MIGRATION_EXAMPLE=`## Migration prompt and criteria
92
92
 
93
93
  This example tests migration of an existing feature-flag application across browser and server workflows. Its starting repository contains the application, while attached connections supply destination credentials. The source account's targeting configuration is unavailable.
94
94
 
@@ -182,11 +182,11 @@ ${MIGRATION_EXAMPLE}
182
182
  ⠉⠛⠛⠛⠛⠁⠘⠛⠃⠈⠙⠛⠛⠋⠘⠛⠃ ⠙⠛⠛⠋⠘⠛⠃⢀⣈⣙⠛⠋⠁⣿⣿ ⠉⠛⠛⠛⠛⠁ ⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋
183
183
  ⠻⢿⣷⣶⣿⠿⠋ ⠈⢿⠿⠋⠉
184
184
  `;var SMALL_LOGO=`\u2588\u2580\u2580 \u2584\u2580\u2588 \u2588 \u2588 \u2588\u2580\u2580 \u2588\u2580\u2580
185
- \u2588\u2584\u2588 \u2588\u2580\u2588 \u2588\u2584\u2588 \u2588\u2584\u2588 \u2588\u2588\u2584`;var SMALL_DOG_LOGO=` \u{1FB4B}\u{1FB4F}
186
- \u{1FB4A}\u{1FB41}\u2588\u{1FB39}\u{1FB51}\u{1FB3C}
187
- \u{1FB48}\u{1FB44}\u2588\u2588\u2588\u{1FB39}\u{1FB3B}\u{1FB4C}\u{1FB39}\u{1FB39}\u{1FB39}
188
- \u{1FB65}\u{1FB52}\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u{1FB5E}\u{1FB5A}
189
- \u{1FB62}\u{1FB55}\u{1FB5E}\u{1FB5C}\u{1FB02}\u{1FB02}\u{1FB02}\u{1FB58}`;var BARK=String.raw`
185
+ \u2588\u2584\u2588 \u2588\u2580\u2588 \u2588\u2584\u2588 \u2588\u2584\u2588 \u2588\u2588\u2584`;var SMALL_DOG_LOGO=` \u28B0\u28E7
186
+ \u28E0\u28FF\u28FF\u2836\u28A4\u2840
187
+ \u2880\u28F4\u28FF\u28FF\u28FF\u28F6\u28FE\u28FF\u28F6\u28F6\u28F6
188
+ \u2819\u28BF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u28FF\u287F\u280B
189
+ \u2808\u283B\u287F\u281F\u2809\u2809\u2809\u2809`;var BARK=String.raw`
190
190
  ⣀
191
191
  ⣠⣶⣿⡿⠿⣿⣿⣦⡀ ⢠⣿⣷⣄
192
192
  ⣰⣿⡿⠁ ⠙⠿⠿⠄ ⢀⣤⣤⣤⣤⡀ ⢠⣤⡄ ⢠⣤⡄ ⢀⣤⣤⣤⡀⣤⣤ ⣀⣤⣤⣤⣄⡀ ⢀⣾⣿⣿⣿⣤⣄⣀ ⣠⡾⠋
@@ -375,7 +375,7 @@ Scripts do not serialize sessions or isolate shared remote state. Prefer disposa
375
375
  Use \`gauge run watch <run-id>\` to follow execution and \`gauge run --help\` for launch flags. Drafting a script or reading these instructions does not start a session.
376
376
  `;var PREFERENCE=`---
377
377
  name: gauge-preference
378
- description: Save, edit, and schedule preference prompts that gauge run
378
+ description: Save, edit, and track preference prompts that gauge run
379
379
  launches. Read before creating or changing a saved preference prompt.
380
380
  ---
381
381
 
@@ -396,33 +396,51 @@ in gauge-cases/ need no preference prompt.
396
396
 
397
397
  Read \`gauge instructions session-analysis\` to analyze the sessions.
398
398
 
399
+ ## Write the prompt
400
+
401
+ - Understand the product, its use cases, and relevant competitors before drafting.
402
+ - Write a short first-person request for a real use case. Include necessary context,
403
+ but avoid invented requirements that steer the agent toward a particular product.
404
+ - Ask the agent to **research**, make one clear recommendation, and stop before
405
+ implementation. Test implementation separately with an experience eval.
406
+ Preserve existing prompts on reruns; omit research when measuring unaided choice.
407
+ - Keep open-ended discovery unbranded. For a head-to-head, name both alternatives
408
+ in the prompt and configuration, and keep the use case consistent across pairs.
409
+ - Let the fixture supply the existing project context. A persona should answer
410
+ from its stated needs without endorsing a vendor or approving implementation.
411
+
412
+ For a supplied project: "I want a hosted documentation site for this project.
413
+ Research the options and recommend one. Don't build anything yet." For a
414
+ head-to-head, replace "the options" with the two products being compared.
415
+
399
416
  ## Create and edit
400
417
 
401
- gauge preference create --kind open-ended --name <name> --text "<prompt>" --agent codex
418
+ gauge preference create --kind open-ended --name <name> --text "<prompt>"
402
419
  gauge preference edit <id> --market <marketId>
403
420
 
404
421
  - A head-to-head prompt needs --brand-a and --brand-b. --branded marks an
405
422
  open-ended prompt that names a brand.
406
- - Preference prompts support repository scenarios in either backend; personas
407
- require hosted execution:
408
- \`gauge preference scenarios add <id> --repo <url>\`.
423
+ - A prompt runs as one persona across all of its repositories. Set it with
424
+ --persona on create or edit (--default-persona clears it); personas require
425
+ hosted execution. Add repositories in either backend:
426
+ \`gauge preference scenarios add <id> --repo <url>\`. To ask the same question
427
+ as another persona, create a second prompt.
409
428
  \`gauge preference markets\` lists the markets a prompt can measure.
410
429
  - Attach gauge.json inputs at launch, not on the prompt: \`gauge run --preference <id> --local
411
430
  --input <name>\` uses the configured files, and \`--input <name>=<path or glob>\` replaces
412
431
  them. Repeat per input; preview with --dry-run. Hosted saved prompts support neither
413
432
  project inputs nor --dry-run; use hosted case files/specs for input snapshots and previews.
414
- - --agent belongs to the prompt. Hosted --skill, --mcp, and --connection
415
- references require hosted execution.
416
- Read \`gauge instructions run\` to choose models.
433
+ - Hosted prompts run on the org's tracked models; local prompts keep their own --agent.
434
+ --skill, --mcp, and --connection require hosted. \`gauge instructions run\` covers models.
417
435
  - Hosted --setup-file/--teardown-file upload UTF-8 JS/TS files; import bindings from "@withgauge/session". For one launch only, pass the same flags to gauge run --hosted --preference <id>; saved configuration stays unchanged.
418
436
  Edits keep the other hook/params; --clear-setup/--clear-teardown/--clear-lifecycle remove hooks (see --help).
419
- - Hosted --cadence daily|weekly|monthly and --samples schedule repeat runs that spend
420
- credits. Confirm the schedule with the user.
421
- - For one launch with other agents or samples, use
422
- \`gauge run --preference <id> --agent ... --samples <n>\`.
437
+ - New prompts are not tracked. \`gauge preference track|untrack <id...>\` (or --tracked) sets it.
438
+ \`gauge preference tracking\` shows the schedule and models; \`tracking set --cadence --day --agent\`
439
+ changes them (--agent replaces the list). Rankings count only tracked scheduled runs; each spends credits, so ask first.
440
+ - One launch on other agents or samples, outside rankings: \`gauge run --preference <id> --agent ... --samples <n>\`.
423
441
 
424
442
  Local prompts run on demand. Repository-only scenarios are supported locally;
425
- hosted personas, markets, recurring schedules, and resource references are not. The user's coding
443
+ hosted personas, markets, tracking, and resource references are not. The user's coding
426
444
  agent analyzes local sessions and publishes choices and findings through
427
445
  \`gauge run analysis save\`; read \`gauge instructions session-analysis --local\`.
428
446
  After an input change, rebuild/repack and rerun the same preference ID. Local launches
@@ -445,7 +463,7 @@ description: Write Gauge eval cases, choose models and judging criteria, and
445
463
  # Run
446
464
 
447
465
  - A self-contained hosted experiment supplies \`product: {repository, revision}\`, \`inputs\`, and \`cases\` in one version-2 JSON file. Start with \`gauge run --example --format experiment\`; use \`--schema --format experiment\` for all fields. Input declarations match gauge.json, but this form never reads local inputs or uploads files. Run \`--hosted --apply experiment.json --dry-run -o json\`, then save the returned \`experiment\` field and launch that copy to retain its resolved commit. Product access uses the organization's GitHub App connection. The product repository is separate from each case's consumer workspace. Preview checks do not prove that input artifacts have been prepared. Npm inputs select existing packed .tgz files; package directories are not built automatically.
448
- - Antigravity is hosted-only and requires organization enrollment. Discover available model identifiers with \`gauge models list --hosted\`. Use \`--agent antigravity:<model>\` when creating or launching saved evals/preferences, or \`agent: ANTIGRAVITY\` with explicit \`models\` in case configuration. Preview case files or JSON case specs with \`--hosted --dry-run\`; launch with \`--hosted\`. The server checks access and model availability. Hosted launches use credits; previews contact Gauge and may upload inputs.
466
+ - Antigravity is hosted-only and requires organization enrollment. Discover available model identifiers with \`gauge models list --hosted\`. Use \`--agent antigravity:<model>\` when creating or launching saved evals, in \`gauge preference tracking set\`, or when launching preferences, or \`agent: ANTIGRAVITY\` with explicit \`models\` in case configuration. Preview case files or JSON case specs with \`--hosted --dry-run\`; launch with \`--hosted\`. The server checks access and model availability. Hosted launches use credits; previews contact Gauge and may upload inputs.
449
467
  - Launch with \`gauge run\` (this repo's gauge-cases/ cases), \`gauge run --eval <id>\` or \`--preference <id>\` (saved: \`gauge instructions eval\` or \`gauge instructions preference\`), or \`gauge run --apply <file>\` (\`-\` for stdin) with JSON: a case spec (\`cases\`: Markdown cases as JSON, each with criteria or preference; \`gauge run --example\`) or a battery spec (\`prompts\`: saved prompts and schedules; \`gauge run --example --format battery\`). Follow a launch with \`gauge run wait <request-id>\` (exits 0 once settled; \`--check\` exits 1 unless PASSED or MEASURED), \`gauge run status <request-id>\` (one snapshot), \`gauge run watch <run-id>\`, or \`gauge run get <run-id> --logs\`. For one launch with other agents or sample counts, pass \`--agent\` and \`--samples\` with \`--eval\` or \`--preference\`; do not edit or copy the eval set or preference prompt for a smoke test.
450
468
  - Fork a finished hosted run to test one change fast. The fork repeats the recorded steps before the fork point, then continues live, and costs only the part after the fork. \`gauge run fork <run-id> --before <seq>\` reruns from that seq; add \`--message <text>\` at a persona message to send a different message. \`--page <url> --edits <file>\` mocks one page the run read, with find text from \`gauge run page <run-id> <url> --query <text>\`. Only runs that \`gauge run get\` marks recorded can fork. When a finding points to one page or message, offer a fork to the user before you propose wider changes. For changes across several sessions, use an optimization.
451
469
  - \`gauge run "<prompt>"\` runs one open-ended preference prompt and saves no measurement. It uses the calling agent if codex or opencode, else claude-code; \`--agent\` overrides.
@@ -482,7 +500,7 @@ Choose a roster for the question and budget. For exploratory testing, start with
482
500
  - **Breadth:** Open models make repetition and coverage across tasks, repositories, personas, skills, and MCP configurations more affordable. Select several available model families rather than treating one model as representative.
483
501
  - **Confirmation:** Use frontier sessions to investigate disagreements and confirm consequential findings. Periodically repeat a subset of open-model cases with frontier targets and investigate meaningful drift.
484
502
  - **Limits:** Gauge's proxy evidence comes from Agent Preference comparisons. Similar product choices do not establish equal coding ability or identical eval pass rates. Calibrate on your own tasks before generalizing.
485
- - **Controls:** Run \`gauge models list -o json\` for the current organization catalog. A target combines a model and harness; select supported pairs in case \`config.agents\`, or with repeated \`--agent pi:<model>\`, \`opencode:<model>\`, \`claude-code:<model>\`, or \`codex:<model>\` on \`gauge eval create|edit\` or \`gauge preference create|edit\`. Pin catalog identifiers explicitly; omitting a model uses the harness default. Treat the harness as part of the comparison.
503
+ - **Controls:** Run \`gauge models list -o json\` for the current organization catalog. A target combines a model and harness; select supported pairs in case \`config.agents\`, or with repeated \`--agent pi:<model>\`, \`opencode:<model>\`, \`claude-code:<model>\`, or \`codex:<model>\` on \`gauge eval create|edit\`, \`gauge preference tracking set\` (hosted, every tracked prompt), or local \`gauge preference create|edit\`. Pin catalog identifiers explicitly; omitting a model uses the harness default. Treat the harness as part of the comparison.
486
504
  - **Comparison:** Keep each case's prompt, fixture, criteria, and other settings fixed when comparing targets. Budget for targets \xD7 samples per case; inspect per-target results and execution evidence rather than only a pooled score. For before/after questions, use \`gauge run compare --baseline <key=value> --candidate <key=value>\` (keys: request, batch, eval, revision, experiment, trial, agent, model, since, until); do not join runs by hand. Each run has an \`evalRevision\`, and each case has its own. When compare warns that one eval or case ran under several revisions, it was edited between runs, so pick one with \`revision=<hash>\`. Run compare after \`gauge run wait\` settles. Optimization trial runs test a changed configuration: selectors other than \`trial=<trialId>\` leave them out, and a run's \`optimizationTrial\` names its trial.
487
505
 
488
506
  Background: [Open models as preference proxies](https://www.withgauge.com/blog/open-models-useful-proxies-data-from-1000-sessions/).
@@ -544,9 +562,8 @@ ${SNAPSHOTS}
544
562
 
545
563
  ## Write good cases
546
564
 
547
- - Measure one meaningful developer outcome. Record the learning goal, reproducible starting state, and observable finish line.
548
- - Write the prompt as a real user's request, in their language. Describe their goal, relevant context, and intended outcome. Preserve constraints they actually supplied; do not assume technical expertise or invent features, UI actions, business rules, commands, filenames, or verification recipes. Leave discovery and implementation choices to the agent. Every file, app, or fact that the prompt names must exist in the starting state, or be in the prompt.
549
- - Align a small set of independently assessable criteria with the requested outcome and existing application. Accept equivalent supported approaches and execution evidence; remove hidden requirements when revising the prompt.
565
+ ${AUTHORING}
566
+ - Every file, app, or fact that the prompt names must exist in the starting state, or be in the prompt.
550
567
  - **CLI:** the package's commands are on PATH. Cover first use, a common workflow, and recovery from a mistake. Judge the result (files, output, state), not the exact commands or flags.
551
568
  - **Skill:** the skill is installed. Ask for a task the skill should help with, but do not name the skill: the eval also shows whether the agent finds it. Judge the result, not whether the agent opened the skill.
552
569
  - **SDK:** the agent starts in a new app that depends on the package. Ask for a feature a user would build with it. Judge that the app runs and makes real SDK calls, not mocks or hardcoded values.
@@ -1007,9 +1024,9 @@ ${url}
1007
1024
  Waiting for consent\u2026`);if(options.browser)deps.openBrowser(url.toString());const deadline=Math.min(expiresAt,deps.now()+options.timeoutSeconds*1e3);while(deps.now()<deadline){const signal=AbortSignal.timeout(Math.max(1,deadline-deps.now()));let status;try{status=await client.get(`${path}/${encodeURIComponent(result.authorizationId)}`,void 0,signal)}catch(error){if(signal.aborted)break;throw error}if(status.status==="connected")return status.connectionId;if(status.status==="failed"||status.status==="expired")throw new CliError("invalid_request",status.message);await deps.sleep(Math.min(2e3,Math.max(0,deadline-deps.now())))}throw new CliError("invalid_request","Timed out waiting for MCP authorization.",{hint:"If consent succeeded, use `gauge connections list --hosted` and retry with --connection <id>. Otherwise retry with --oauth; incomplete saved grants can resume without new consent."})}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(readFileSync8(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}`);if(v.connectionId)console.log(` connection: ${v.connectionId}`);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").option("--connection <id>","bind an existing connection to this HTTP MCP server").option("--oauth","authorize this HTTP MCP in a browser, then save its connection binding").option("--oauth-client-id <id>","pre-registered OAuth client id, when the server requires one").option("--oauth-client-secret-env <NAME>","environment variable holding an optional OAuth client secret").option("--no-browser","print the OAuth URL without opening a browser").option("--oauth-timeout <seconds>","maximum time to wait for OAuth consent (1-600)","600").action(async(opts,cmd)=>{const org=await resolveOrg(cmd);if(opts.oauth&&opts.connection)throw new CliError("usage","--oauth conflicts with --connection; choose new consent or an existing connection.");if(!opts.oauth&&(opts.oauthClientId||opts.oauthClientSecretEnv||opts.browser===false||opts.oauthTimeout!=="600"))throw new CliError("usage","OAuth options require --oauth.");const timeoutSeconds=Number(opts.oauthTimeout);if(!Number.isInteger(timeoutSeconds)||timeoutSeconds<1||timeoutSeconds>600)throw new CliError("usage","--oauth-timeout must be an integer from 1 to 600 seconds.");let spec;let body2;try{const raw=specFromOpts(opts);spec=parseMcpSpec(raw&&typeof raw==="object"&&!Array.isArray(raw)?{specVersion:1,serverName:opts.name,...raw}:raw);body2=saveMcpServerBodySchema.parse({name:opts.name,spec,label:opts.label,note:opts.note,connectionId:opts.connection})}catch(error){if(error instanceof CliError)throw error;throw new CliError("usage",error instanceof Error?error.message:"Invalid MCP configuration.")}if((opts.oauth||opts.connection)&&spec.transport!=="http")throw new CliError("usage","--oauth and --connection require an HTTP MCP server.");const client=createClient();if(opts.oauth){let clientSecret;if(opts.oauthClientSecretEnv){if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(opts.oauthClientSecretEnv))throw new CliError("usage","--oauth-client-secret-env must name an environment variable.");clientSecret=process.env[opts.oauthClientSecretEnv];if(!clientSecret)throw new CliError("usage","The OAuth client secret environment variable is empty or unset.");if(!opts.oauthClientId)throw new CliError("usage","--oauth-client-secret-env requires --oauth-client-id.")}body2.connectionId=await connectMcpOauth(client,org,{name:opts.name,url:spec.url,clientId:opts.oauthClientId,clientSecret},{browser:opts.browser,timeoutSeconds})}let result;try{result=await client.post(mcpPath(org),body2)}catch(error){if(opts.oauth&&body2.connectionId)console.error(`OAuth connected, but saving the MCP version failed. Retry with --connection ${body2.connectionId} instead of --oauth.`);throw error}if(body2.connectionId&&result.connectionId!==body2.connectionId)throw new CliError("internal","The server did not confirm the MCP connection binding.",{hint:`Upgrade the Gauge API before retrying with --connection ${body2.connectionId}.`});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 body2={};if(opts.rename!==void 0)body2.name=opts.rename;if(opts.clearNote)body2.note=null;else if(opts.note!==void 0)body2.note=opts.note;if(Object.keys(body2).length===0)throw new CliError("usage","nothing to change");const updated=await createClient().patch(serverPath(org,ref),body2);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(`
1008
1025
  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(`
1009
1026
  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,{checkForkBefore:()=>checkForkBefore,fileEditFromOpts:()=>fileEditFromOpts,fileSourceFromOpts:()=>fileSourceFromOpts,latestLaunch:()=>latestLaunch,launchSettled:()=>launchSettled,parseEdits:()=>parseEdits,parseForkBefore:()=>parseForkBefore,parsePositiveSeq:()=>parsePositiveSeq,parseRestoreBefore:()=>parseRestoreBefore,parseStatus:()=>parseStatus,parseSubjectRef:()=>parseSubjectRef,printPageView:()=>printPageView,readJson:()=>readJson2,readText:()=>readText,register:()=>register23});import{readFileSync as readFileSync9,writeFileSync as writeFileSync2}from"fs";var STATUSES2=["OPEN","DONE","ARCHIVED"];var TERMINAL_RUN=new Set(["SUCCEEDED","FAILED","TIMED_OUT","CANCELED"]);function basePath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/optimizations`}function itemPath(org,id2){return`${basePath(org)}/${encodeURIComponent(id2)}`}function readText(path){return readFileSync9(path==="-"?0:path,"utf8")}function readJson2(path,read2=readText){try{return JSON.parse(read2(path))}catch{throw new CliError("usage",`${path} must contain valid JSON`)}}function sleep3(ms){return new Promise(resolve5=>setTimeout(resolve5,ms))}function plural(n,noun){return`${n} ${noun}${n===1?"":"s"}`}function parseCount(raw,flag2,max){if(raw===void 0)return void 0;const n=Number(raw);if(!Number.isInteger(n)||n<1||n>max)throw new CliError("usage",`${flag2} must be a positive integer no greater than ${max}`);return n}function parseStatus(raw){if(!raw)return void 0;const status=raw.trim().toUpperCase();if(!STATUSES2.includes(status))throw new CliError("usage",`unknown status "${raw}" (expected ${STATUSES2.join(", ")})`);return status}function parseSubjectRef(opts){if([opts.issue,opts.finding,opts.goal].filter(Boolean).length!==1)throw new CliError("usage","pass one of --issue <id>, --finding <id> --run <runId>, or --goal <text>");if(opts.run&&!opts.finding)throw new CliError("usage","--run only applies with --finding");if(opts.issue)return{kind:"issue",issueId:opts.issue};if(opts.finding){if(!opts.run)throw new CliError("usage","--finding needs --run <runId>");return{kind:"finding",observationId:opts.finding,runId:opts.run}}return{kind:"free",text:opts.goal}}function fileEditFromOpts(opts,read2=readText){if([opts.page,opts.skill,opts.cli].filter(Boolean).length!==1)throw new CliError("usage","pass one of --page <url>, --skill <name> --path <path>, or --cli <package>");if(opts.delete&&!opts.skill)throw new CliError("usage","--delete removes one path from a skill");if(opts.path&&!opts.skill)throw new CliError("usage","--path only applies with --skill");if(opts.contentType&&!opts.page)throw new CliError("usage","--content-type only applies with --page");if(opts.delete&&opts.from)throw new CliError("usage","pass --delete or --from, not both");if(!opts.delete&&!opts.from)throw new CliError("usage","--from <file> is required ('-' for stdin)");const from=opts.from;if(opts.page)return{kind:"page",url:opts.page,body:read2(from),...opts.contentType?{contentType:opts.contentType}:{}};if(opts.skill){if(!opts.path)throw new CliError("usage","--skill needs --path <path inside the skill>");return{kind:"skill",name:opts.skill,path:opts.path,body:opts.delete?null:read2(from)}}let rules;try{rules=JSON.parse(read2(from))}catch{throw new CliError("usage","--from must contain CLI rules as JSON")}return{kind:"cli",package:opts.cli,rules}}function fileSourceFromOpts(opts){if([opts.page,opts.skill,opts.cli].filter(Boolean).length!==1)throw new CliError("usage","pass one of --page <url>, --skill <name>, or --cli");if(opts.page)return{kind:"page",url:opts.page};if(opts.skill)return{kind:"skill",name:opts.skill};return{kind:"cli"}}function latestLaunch(launches){return launches.reduce((latest,launch2)=>!latest||launch2.number>latest.number?launch2:latest,void 0)}function launchSettled(launch2){return launch2.runs.every(run=>TERMINAL_RUN.has(run.status)&&(run.status!=="SUCCEEDED"||run.analyzed))}function subjectLine(subject){switch(subject.kind){case"issue":return`issue "${subject.title}" (${subject.issueId})`;case"finding":return`finding "${subject.label}" on run ${subject.runId}`;case"free":return`goal "${subject.text}"`}}function toRow2(o){return{id:o.id,title:o.title.length>48?`${o.title.slice(0,45)}...`:o.title,status:o.status,subject:o.subject.kind,changed:o.changed,launches:o.launches,updated:o.updatedAt}}function fileRow(key,file,change){return{key,change:change??"",size:file.kind==="page"?`${file.body.length} chars`:file.kind==="skill"?plural(Object.keys(file.files).length,"file"):plural(file.rules.rules.length,"rule")}}function launchProgress(launch2){const done2=launch2.runs.filter(run=>TERMINAL_RUN.has(run.status));const analyzed=launch2.runs.filter(run=>run.analyzed);return`${done2.length}/${launch2.runs.length} finished, ${analyzed.length} analyzed`}function launchRow(launch2){return{id:launch2.id,number:launch2.number,reruns:launchProgress(launch2),changed:launch2.changed.length,note:launch2.note??"",created:launch2.createdAt}}function printDetail2(o){console.log(`id: ${o.id}`);console.log(`title: ${o.title}`);console.log(`status: ${o.status}`);console.log(`subject: ${subjectLine(o.subject)}`);const recorded=o.recordedSourceRunIds?new Set(o.recordedSourceRunIds):null;console.log(`sources: ${o.sourceRunIds.map(id2=>recorded?`${id2} (${recorded.has(id2)?"recorded":"no recording"})`:id2).join(", ")||"(none)"}`);const changes=new Map(o.changes.map(c=>[c.key,c.status]));const files=Object.entries(o.head.files);console.log(`files: ${files.length?"":"(empty tree)"}`);if(files.length)printItems(files.map(([key,file])=>fileRow(key,file,changes.get(key))),"table");for(const[key,change]of changes)if(change==="removed")console.log(` ${key}: removed`);console.log(`launches: ${o.launchList.length?"":"(none)"}`);if(o.launchList.length)printItems(o.launchList.map(launchRow),"table");if(o.result)console.log(`result: ${o.result.summary}`)}function printFile(file,path){if(file.kind==="page")return void console.log(file.body);if(file.kind==="cli")return printJson(file.rules);if(path){const body2=file.files[path];if(body2===void 0)throw new CliError("not_found",`no ${path} in skill ${file.name}`);return void console.log(body2)}for(const[name,body2]of Object.entries(file.files)){console.log(`=== ${name}`);console.log(body2)}}function printLaunch(launch2){console.log(`launch ${launch2.number} (${launch2.id})${launch2.note?`: ${launch2.note}`:""}`);console.log(`changed: ${launch2.changed.join(", ")||"(nothing)"}`);for(const run of launch2.runs){console.log(`
1010
- ${run.id} rerun of ${run.sourceRunId??"?"}: ${run.status}, ${run.agent} ${run.model}`);if(run.forkedAfter!=null)console.log(` forked after seq ${run.forkedAfter}; cost and time cover only the part after the fork`);if(run.restoredFrom)console.log(` restored at seq ${run.restoredFrom.seq} (${run.restoredFrom.checkpointId}); cost and time cover only the part after the restore`);if(!run.findings){console.log(" not analyzed");continue}const now=new Set(run.findings.map(f=>f.label));const before=new Set(run.sourceFindings.map(f=>f.label));for(const f of run.sourceFindings)console.log(` ${now.has(f.label)?"returned":"resolved"} ${f.label}`);for(const f of run.findings)if(!before.has(f.label))console.log(` introduced ${f.label}`)}}function parseEdits(value){const ok=Array.isArray(value)&&value.length>0&&value.every(edit=>edit&&typeof edit==="object"&&typeof edit.find==="string"&&edit.find.length>0&&typeof edit.replace==="string");if(!ok)throw new CliError("usage","--edits must be a JSON array of {find, replace} with non-empty find");return value.map(({find,replace})=>({find,replace}))}function printWrite(res){if(!res.change){console.log(`Wrote ${res.key}`);return}const{linesBefore,linesAfter,retainedPercent,hunks}=res.change;console.log(`Wrote ${res.key}: ${linesBefore} \u2192 ${linesAfter} lines, ${retainedPercent??"\u2014"}% of the original kept`);console.log(hunks)}function printPageView(view){const content=view.text??view.raw;if(content!==void 0){console.log(content);return}console.log(`${view.matches??0} matches for ${JSON.stringify(view.query)}`);for(const excerpt of view.excerpts??[]){console.log(`=== offset ${excerpt.offset}`);console.log(excerpt.raw)}if(view.truncated)console.log("\u2026 more matches; search a longer phrase");if(view.hint)console.log(view.hint)}function parsePositiveSeq(raw){const seq=Number(raw);return/^\d+$/.test(raw)&&seq>=1&&Number.isSafeInteger(seq)?seq:null}function parseForkBefore(raw){const at=raw.lastIndexOf(":");const seq=parsePositiveSeq(raw.slice(at+1));if(at<=0||seq===null)throw new CliError("usage",`--fork-before takes <sourceRunId>:<seq>, e.g. run_1:34 (got ${raw})`);return{runId:raw.slice(0,at),seq}}function checkForkBefore(forkBefore,opts){const seen=new Set;for(const{runId}of forkBefore){if(seen.has(runId))throw new CliError("usage",`--fork-before names ${runId} twice`);seen.add(runId);if(opts.run?.length&&!opts.run.includes(runId))throw new CliError("usage",`--fork-before names ${runId}, but --run leaves it out`);if(opts.fresh===true||opts.fresh?.includes(runId))throw new CliError("usage",`--fork-before and --fresh both name ${runId}; pick one`)}}function parseRestoreBefore(raw){const at=raw.lastIndexOf(":");const rerunId=raw.slice(0,at);const seq=raw.slice(at+1);if(at<=0||!/^-?\d+$/.test(seq))throw new CliError("usage",`--restore-before takes <rerunId>:<seq>, e.g. run_1:140 (got ${raw})`);return{rerunId,seq:Number(seq)}}function checkpointRow(cp){const exposure=[...cp.exposure.surfaces,...cp.exposure.skillChanged?["skill changed"]:[],...cp.exposureIncomplete?["trace incomplete"]:[]];return{checkpoint:cp.checkpointId,source:cp.sourceRunId,rerun:cp.rerunId,seq:`${cp.seq}/${cp.rerunEventCount}`,exposure:exposure.join(", ")||"clean","last step":cp.lastSteps.at(-1)??"",captured:cp.capturedAt}}function printLaunchResult(id2,res){console.log(`Launched ${plural(res.batches.flatMap(b=>b.runIds).length,"rerun")} (${res.launchId}) with ${plural(res.changed.length,"changed file")}:`);for(const key of res.changed)console.log(` ${key}`);for(const batch of res.batches){const from=batch.restoredFrom;console.log(batch.forkedAfter!=null?`${batch.sourceRunId}: forked after seq ${batch.forkedAfter}`:from?`${batch.sourceRunId}: restored at seq ${from.seq} of rerun ${from.rerunId} (${from.checkpointId})`:`${batch.sourceRunId}: fresh`);for(const warning of batch.warnings)console.log(` ! ${warning}`)}console.log(`Follow with \`gauge optimizations watch ${id2}\`.`)}function register23(program2){const group=hostedOnly(program2.command("optimizations")).description("Hill climb your agent surfaces: edit the pages, skills, and CLI rules agent sessions used, rerun those sessions, and compare findings");group.command("list").description("List the org's optimizations, newest activity first").option("--status <status>",STATUSES2.join(", ")).option("--limit <n>","max rows (default 50)").action(async(opts,cmd)=>{const res=await createClient().get(basePath(await resolveOrg(cmd)),{status:parseStatus(opts.status),limit:parseCount(opts.limit,"--limit",200)});if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(toRow2),"table")});group.command("create").description("Open an optimization on an issue, one finding, or a goal; the tree starts empty").option("--issue <id>","an issue id from `gauge issues list`").option("--finding <id>","a finding id from `gauge run insight <run> -o json`; needs --run").option("--run <runId>","the run the finding is on").option("--goal <text>","free text; starts with no sessions, attach them with `sessions add`").option("--title <title>","name (default: from the subject)").action(async(opts,cmd)=>{const detail=await createClient().post(basePath(await resolveOrg(cmd)),{subject:parseSubjectRef(opts),...opts.title?{title:opts.title}:{}});if(resolveOutput(cmd)==="json")printJson(detail);else console.log(detail.sourceRunIds.length?`Opened ${detail.id} "${detail.title}" on ${plural(detail.sourceRunIds.length,"source session")}. Next: \`gauge optimizations authoring ${detail.id}\`.`:`Opened ${detail.id} "${detail.title}" with no sessions. Next: \`gauge optimizations sessions add ${detail.id} <runId...>\`.`)});group.command("get <id>").description("One optimization: subject, source runs, tree, and launches").action(async(id2,_opts,cmd)=>{const detail=await createClient().get(itemPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});group.command("authoring <id>").description("Authoring guidance: the source sessions' findings, the tree, and the editing practices to follow").action(async(id2,_opts,cmd)=>{const res=await createClient().get(`${itemPath(await resolveOrg(cmd),id2)}/authoring`);if(resolveOutput(cmd)==="json")printJson(res);else console.log(res.guidance)});group.command("sessions").description("Attach sessions an optimization can rerun").command("add <id> <runIds...>").description("Attach sessions to rerun, up to 12 in all; a goal starts with none. Optimization reruns cannot be sources").action(async(id2,runIds,_opts,cmd)=>{const res=await createClient().post(`${itemPath(await resolveOrg(cmd),id2)}/sessions`,{runIds});if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Attached ${plural(res.added.length,"session")}; ${id2} has ${plural(res.sourceRunIds.length,"source session")}.`)});const file=group.command("file").description("Read and edit the files in an optimization's tree");file.command("read <id> <key>").description("Print one file by tree key: a page's exact source (--text for readable text, --query for the source around a match), a skill (or one --path in it), or CLI rules").option("--text","page only: readable text instead of the source").option("--query <text>","page only: the exact source around each match, to copy into file edit").option("--path <path>","one file inside a skill").option("--out <file>","save the page source or skill --path to a file").action(async(id2,key,opts,cmd)=>{const path=`${itemPath(await resolveOrg(cmd),id2)}/files`;if(opts.text||opts.query){if(opts.out)throw new CliError("usage","--out saves the stored file only");const view=await createClient().get(path,{key,...opts.query?{query:opts.query}:{view:"text"}});if(resolveOutput(cmd)==="json")printJson(view);else printPageView(view);return}const res=await createClient().get(path,{key});if(opts.out){const body2=res.kind==="page"?res.body:res.kind==="skill"&&opts.path?res.files[opts.path]:void 0;if(body2===void 0)throw new CliError("usage","--out saves a page source or one skill --path");writeFileSync2(opts.out,body2);console.error(`Saved ${opts.out}`)}else if(resolveOutput(cmd)==="json")printJson(res);else printFile(res,opts.path)});file.command("edit <id>").description("Edit a page in the tree with find/replace on its exact source; every byte outside the edits stays. Each find must appear once; all edits apply or none do").requiredOption("--page <url>","the page URL").requiredOption("--edits <file>","JSON [{find, replace}]; copy find text from `file read --query`; '-' for stdin").action(async(id2,opts,cmd)=>{const res=await createClient().patch(`${itemPath(await resolveOrg(cmd),id2)}/files`,{url:opts.page,edits:parseEdits(readJson2(opts.edits))});if(resolveOutput(cmd)==="json")printJson(res);else printWrite(res)});file.command("add <id>").description("Copy an original into the tree before you edit it: a page a source session read (else the live page), a staged skill, or the CLI rules").option("--page <url>","a page by URL").option("--skill <name>","a skill a source session staged").option("--cli","the CLI rules a source session ran with").action(async(id2,opts,cmd)=>{const res=await createClient().post(`${itemPath(await resolveOrg(cmd),id2)}/files`,fileSourceFromOpts(opts));if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Added ${res.key} (from ${res.origin})`)});file.command("write <id>").description("Write a new page or rewrite a whole one, one skill file, or the CLI rules; to change part of a page, use file edit").option("--page <url>","the page URL; --from holds the complete body").option("--content-type <type>","the page content type (default: keep)").option("--skill <name>","the skill; needs --path").option("--path <path>","the file inside the skill, e.g. SKILL.md").option("--delete","remove --path from the skill").option("--cli <package>","the CLI package; --from holds {schemaVersion: 3, target, rules, shippingIntent}").option("--from <file>","the new content; '-' for stdin").action(async(id2,opts,cmd)=>{const res=await createClient().put(`${itemPath(await resolveOrg(cmd),id2)}/files`,fileEditFromOpts(opts));if(resolveOutput(cmd)==="json")printJson(res);else printWrite(res)});file.command("rm <id> <key>").description("Drop a file from the tree; reruns use what the source session had").action(async(id2,key,_opts,cmd)=>{const res=await createClient().delete(`${itemPath(await resolveOrg(cmd),id2)}/files`,{key});if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Removed ${res.removed}`)});group.command("notes <id>").description("Print the working notes, or replace them with --from: markdown the user reads beside the chat").option("--from <file>","the complete notes; '-' for stdin").action(async(id2,opts,cmd)=>{const path=itemPath(await resolveOrg(cmd),id2);const client=createClient();const detail=opts.from?await client.patch(path,{notes:readText(opts.from)}):await client.get(path);if(resolveOutput(cmd)==="json")printJson({notes:detail.notes});else if(opts.from)console.log(`Saved notes (${detail.notes.length} chars)`);else console.log(detail.notes||"(no notes)")});group.command("launch <id>").description("Rerun the source sessions with the tree injected. A recorded run forks: it repeats the source's recorded steps up to its last tool call before the first changed surface, then continues live. Other runs restore from the deepest checkpoint before any changed surface, or start fresh").option("--run <runId...>","rerun only these source runs").option("--note <text>","one line on what this launch tests").option("--fork-before <sourceRunId:seq...>","fork this recorded source run at its last tool call before this seq").option("--restore-before <rerunId:seq...>","restore from the deepest checkpoint at or before this seq of an earlier rerun").option("--checkpoint <checkpointId...>","restore from this checkpoint (see `checkpoints`)").option("--fresh [sourceRunId...]","start from zero, with no fork and no restore: these source runs, or every one").option("--yes","skip the confirmation").action(async(id2,opts,cmd)=>{const restoreAt=[...(opts.checkpoint??[]).map(checkpointId=>({checkpointId})),...(opts.restoreBefore??[]).map(parseRestoreBefore)];const forkBefore=(opts.forkBefore??[]).map(parseForkBefore);checkForkBefore(forkBefore,opts);const path=itemPath(await resolveOrg(cmd),id2);await confirmOrAbort(`Rerun ${opts.run?.length?plural(opts.run.length,"source session"):"every source session"} of ${id2} with the tree?`,opts.yes);const client=createClient();const fresh=opts.fresh===true?opts.run??(await client.get(path)).sourceRunIds:opts.fresh??[];const res=await client.post(`${path}/launch`,{...opts.run?.length?{runIds:opts.run}:{},...opts.note?{note:opts.note}:{},...fresh.length?{restore:Object.fromEntries(fresh.map(runId=>[runId,"none"]))}:{},...restoreAt.length?{restoreAt}:{},...forkBefore.length?{forkBefore}:{}});if(resolveOutput(cmd)==="json")printJson(res);else printLaunchResult(id2,res)});group.command("checkpoints <id>").description("Checkpoints captured on fresh reruns, with how far in each is and whether its prefix saw a changed surface").option("--run <sourceRunId>","only this source run").action(async(id2,opts,cmd)=>{const res=await createClient().get(`${itemPath(await resolveOrg(cmd),id2)}/checkpoints`,{sourceRunId:opts.run});if(resolveOutput(cmd)==="json")printJson(res.items);else if(!res.items.length)console.log("(no checkpoints)");else printItems(res.items.map(checkpointRow),"table")});group.command("launches <id> [launchId]").description("List launches, or one launch's reruns with their findings beside the source findings").action(async(id2,launchId,_opts,cmd)=>{const path=itemPath(await resolveOrg(cmd),id2);const client=createClient();if(!launchId){const detail=await client.get(path);if(resolveOutput(cmd)==="json")printJson(detail.launchList);else printItems(detail.launchList.map(launchRow),"table");return}const launch2=await client.get(`${path}/launches/${encodeURIComponent(launchId)}`);if(resolveOutput(cmd)==="json")printJson(launch2);else printLaunch(launch2)});group.command("watch <id>").description("Wait until the latest launch's reruns finish and are analyzed, then print them").option("--interval <seconds>","poll interval (default 15)").option("--timeout <minutes>","give up after this long (default 60)").action(async(id2,opts,cmd)=>{const path=itemPath(await resolveOrg(cmd),id2);const client=createClient();const interval=(parseCount(opts.interval,"--interval",600)??15)*1e3;const timeoutMinutes=parseCount(opts.timeout,"--timeout",1440)??60;const deadline=Date.now()+timeoutMinutes*6e4;let last="";for(;;){const detail=await client.get(path);const latest=latestLaunch(detail.launchList);if(!latest)throw new CliError("usage",`${id2} has no launches yet`);if(launchSettled(latest)){const launch2=await client.get(`${path}/launches/${encodeURIComponent(latest.id)}`);if(resolveOutput(cmd)==="json")printJson(launch2);else printLaunch(launch2);return}const progress=launchProgress(latest);if(progress!==last)console.error(`launch ${latest.number}: ${progress}`);last=progress;if(Date.now()>=deadline)throw new CliError("network",`Timed out after ${timeoutMinutes} minutes (launch ${latest.number}: ${progress}). Re-run watch, or check \`gauge optimizations launches ${id2} ${latest.id}\`.`);await sleep3(interval)}});group.command("finish <id>").description("Close the optimization with its result: summary, changed keys, and findings resolved, returned, and introduced").requiredOption("--from <file>","result JSON: {summary, changed, resolved, returned, introduced}").option("--yes","skip the confirmation").action(async(id2,opts,cmd)=>{const path=itemPath(await resolveOrg(cmd),id2);const result=readJson2(opts.from);await confirmOrAbort(`Finish ${id2}? Its tree can no longer change.`,opts.yes);const detail=await createClient().post(`${path}/finish`,result);if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`Finished ${detail.id} "${detail.title}"`)})}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 writeFileSync3}from"fs";import{join as join8}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;writeFileSync3(join8(state.root,"gauge.json"),`${JSON.stringify({...config,orgId:org.id},null,2)}
1011
- `)}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(id2,_opts,cmd)=>{const org=await resolveOrg(cmd);const persona=await createClient().get(`${personasPath(org)}/${encodeURIComponent(id2)}`);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(id2,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(id2)}`,{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(id2,_opts,cmd)=>{const org=await resolveOrg(cmd);await createClient().delete(`${personasPath(org)}/${encodeURIComponent(id2)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted persona ${id2}`)})}var preference_exports={};__export(preference_exports,{register:()=>register27});function visibilityPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/visibility-prompts`}function promptPath(org,id2){return`${visibilityPath(org)}/${encodeURIComponent(id2)}`}function scenariosPath(org,id2){return`${promptPath(org,id2)}/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,id2){const vp=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"preference",id2)):await createClient().get(promptPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)==="json")printJson(vp);else printDetail3(vp)}async function createPreferencePrompt(cmd,opts){if(hasLifecycleFlags(opts)&&isLocal(cmd))throw new CliError("usage","Lifecycle scripts require hosted execution; pass --hosted");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 body2={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",body2):await createClient().post(visibilityPath(await resolveOrg(cmd)),body2);if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created preference prompt ${created.id}`)}async function editPreferencePrompt(cmd,id2,opts){if(hasLifecycleFlags(opts)&&isLocal(cmd))throw new CliError("usage","Lifecycle scripts require hosted execution; pass --hosted");const lifecyclePath=hasLifecycleFlags(opts)&&!opts.clearLifecycle?promptPath(await resolveOrg(cmd),id2):void 0;const existing=lifecyclePath?await createClient().get(lifecyclePath):void 0;const body2={...runSettingsPatchFromOpts(opts,existing?.lifecycle)};if(opts.name!==void 0)body2.name=opts.name;if(opts.text!==void 0||opts.file!==void 0)body2.promptText=readPromptText(opts);if(opts.brandA!==void 0)body2.brandA=opts.brandA;if(opts.brandB!==void 0)body2.brandB=opts.brandB;if(opts.branded&&opts.organic)throw new CliError("usage","--branded and --organic conflict");if(opts.branded)body2.branded=true;else if(opts.organic)body2.branded=false;if(opts.market!==void 0&&opts.clearMarket)throw new CliError("usage","--market and --clear-market conflict");if(opts.clearMarket)body2.marketId=null;else if(opts.market!==void 0)body2.marketId=opts.market;if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");if(opts.clearTags)body2.tags=[];else if(opts.tag.length>0)body2.tags=opts.tag;if(Object.keys(body2).length===0)throw new CliError("usage","nothing to change");const updated=isLocal(cmd)?editLocalMeasurement(cmd,"preference",id2,body2):await createClient().patch(lifecyclePath??promptPath(await resolveOrg(cmd),id2),body2);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated preference prompt ${updated.id}`)}async function removePreferencePrompt(cmd,id2){if(isLocal(cmd))removeLocalMeasurement(cmd,"preference",id2);else await createClient().delete(promptPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)!=="json")console.log(`Deleted preference prompt ${id2}`)}async function listScenarios(cmd,id2){const vp=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"preference",id2)):await createClient().get(promptPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)==="json")printJson(vp.scenarios);else printItems(vp.scenarios.map(scenarioRow),"table")}async function addScenario(cmd,id2,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",id2);const updated=editLocalMeasurement(cmd,"preference",id2,{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),id2),{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,id2,scenarioId){if(isLocal(cmd)){const row2=getLocalMeasurement(cmd,"preference",id2);const scenarios=row2.scenarios;if(!scenarios.some(s=>s.id===scenarioId))throw new CliError("usage",`Unknown scenario: ${scenarioId}`);editLocalMeasurement(cmd,"preference",id2,{scenarios:scenarios.filter(s=>s.id!==scenarioId)});if(resolveOutput(cmd)!=="json")console.log(`Removed scenario ${scenarioId}`);return}await createClient().delete(`${scenariosPath(await resolveOrg(cmd),id2)}/${encodeURIComponent(scenarioId)}`);if(resolveOutput(cmd)!=="json")console.log(`Removed scenario ${scenarioId}`)}async function runPreferencePrompt(cmd,id2,opts){const org=await resolveOrg(cmd);const overrides={...runOverridesFromOpts(opts),...opts.cliRules?{cliRules:opts.cliRules}:{},...hasLifecycleFlags(opts)?lifecyclePatchFromOpts(opts,(await createClient().get(promptPath(org,id2))).lifecycle):{}};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,id2)}/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}`)}return result}async function listPreferencePromptRuns(cmd,id2,opts){const res=await createClient().get(`${promptPath(await resolveOrg(cmd),id2)}/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(id2,_opts,cmd)=>{await getPreferencePrompt(cmd,id2)});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(id2,opts,cmd)=>{await editPreferencePrompt(cmd,id2,opts)});preference.command("rm <id>").description("Delete a preference prompt (run history stays)").action(async(id2,_opts,cmd)=>{await removePreferencePrompt(cmd,id2)});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(id2,_opts,cmd)=>{await listScenarios(cmd,id2)});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(id2,opts,cmd)=>{await addScenario(cmd,id2,opts)});scenarios.command("rm <id>").description("Remove one scenario").requiredOption("--scenario <scenarioId>","scenario id to remove").action(async(id2,opts,cmd)=>{await removeScenario(cmd,id2,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 body2={url};if(opts.name!==void 0)body2.name=opts.name;if(opts.clearFrameworks)body2.frameworks=[];else if(opts.framework.length>0)body2.frameworks=opts.framework;if(opts.clearTags)body2.tags=[];else if(opts.tag.length>0)body2.tags=opts.tag;if(Object.keys(body2).length===1)throw new CliError("usage","nothing to change");const repo=await createClient().patch(reposPath(org),body2);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 readFileSync10,statSync as statSync3}from"fs";function readCliRules(path){if(path==="-")throw new CliError("usage","--cli-rules expects a JSON file path, not stdin");try{const info=statSync3(path);if(!info.isFile())throw new Error("Expected a regular JSON file");if(info.size>CLI_RULE_LIMITS.bundleBytes)throw new Error("CLI rules file exceeds 2 MiB");return cliRuleAuthorInputSchema.parse(JSON.parse(readFileSync10(path,"utf8")))}catch(error){throw new CliError("usage",`Invalid --cli-rules file: ${error instanceof Error?error.message:error}`)}}import{readFileSync as readFileSync13,existsSync as existsSync4,mkdirSync as mkdirSync2,writeFileSync as writeFileSync5}from"fs";import{z as z17}from"zod";import{join as join11,relative as relative5}from"path";import{z as z8}from"zod";var preferenceDefinitionSchema=z8.discriminatedUnion("kind",[z8.object({kind:z8.literal("open-ended"),branded:z8.boolean().default(false)}).strict(),z8.object({kind:z8.literal("head-to-head"),brandA:z8.string().trim().min(1),brandB:z8.string().trim().min(1)}).strict().refine(p=>p.brandA.toLowerCase()!==p.brandB.toLowerCase(),"A head-to-head needs two different brands")]);var preferenceSnapshotSchema=z8.object({version:z8.literal(1),preference:preferenceDefinitionSchema}).strict();var headToHeadSchema=z8.object({kind:z8.literal("HEAD_TO_HEAD"),assessability:z8.enum(["assessed","partial","unassessable"]).optional(),selectionStatus:z8.enum(["measured","not_measured","unassessable"]).optional(),winner:z8.enum(["A","B","both","neither"]),brandA:z8.string(),brandB:z8.string(),rationale:z8.string(),brandAReasoning:z8.string(),brandBReasoning:z8.string(),brandAWhyRaised:z8.string().optional(),brandBWhyRaised:z8.string().optional()});var recommendPickSchema=z8.object({brand:z8.string(),rank:z8.number().int(),adopted:z8.boolean(),reasoning:z8.string().optional(),whyRaised:z8.string().optional()});var recommendSchema=z8.object({kind:z8.literal("RECOMMEND"),selectedBrands:z8.array(z8.string()).optional(),assessability:z8.enum(["assessed","partial","unassessable"]).optional(),selectionStatus:z8.enum(["measured","not_measured","unassessable"]).optional(),picks:z8.array(recommendPickSchema).default([]),singlePick:z8.boolean(),complianceNote:z8.string()});var visibilityVerdictSchema=z8.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 Option5}from"commander";import{readFileSync as readFileSync11}from"fs";import{z as z9}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(source2){let raw;if(source2==="-"){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=readFileSync11(source2,"utf8")}catch(e){throw new CliError("usage",`cannot read spec file ${source2}: ${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:
1012
- ${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 id2 of res.runIds)console.log(` run ${id2}`);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=()=>z9.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);return result}import{createHash as createHash3}from"crypto";import{z as z13}from"zod";import{z as z10}from"zod";var runAddonsSchema=z10.object({browser:z10.object({session:z10.string().min(1),projectId:z10.number().int().positive(),region:z10.literal("us").default("us")}).strict().optional()}).strict();import{z as z12}from"zod";import{z as z11}from"zod";var inputPathSchema=z11.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=z11.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=z11.object({type:z11.literal("binary"),paths:z11.array(inputPathSchema).min(1).max(32),platform:z11.literal("linux-x64").describe("Linux x86-64 ELF executables compatible with the consumer sandbox. No system packages are installed."),commands:z11.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=z11.discriminatedUnion("type",[binaryUseSchema,websiteUseSchema,z11.object({type:z11.literal("web-fixture"),path:inputPathSchema.regex(/^[^*?{}[\]]+$/)}).strict(),z11.object({type:z11.literal("files"),paths:z11.array(inputPathSchema).min(1).max(32).optional()}).strict(),z11.object({type:z11.literal("npm-cli"),package:inputPathSchema,install:z11.enum(["environment","workspace"]).optional()}).strict(),z11.object({type:z11.literal("npm-package"),package:inputPathSchema,install:z11.enum(["environment","workspace"]).optional()}).strict(),z11.object({type:z11.literal("skill"),root:z11.union([z11.literal("."),inputPathSchema]).refine(path=>!/[*?{}[\]]/.test(path),"Skill root must be an explicit directory")}).strict()]);var inputSourceSchema=z11.discriminatedUnion("type",[z11.object({type:z11.literal("git"),paths:z11.array(inputPathSchema).min(1).max(32)}).strict(),z11.object({type:z11.literal("github-actions"),artifact:z11.string().min(1).max(256).optional()}).strict()]);var runPlanResourceSchema=z11.object({name:z11.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64),type:z11.literal("input"),source:z11.discriminatedUnion("type",[z11.object({type:z11.literal("upload"),sha256:z11.string().regex(/^sha256:[a-f0-9]{64}$/),bytes:z11.number().int().positive().max(512*1024*1024),repoUrl:z11.string().nullable(),commit:z11.string().regex(/^[a-f0-9]{40}$/i).nullable()}).strict(),commentSourceSchema.extend({repoUrl:z11.string(),commit:z11.string().regex(/^[a-f0-9]{40}$/i)}).strict(),deploymentSourceSchema.extend({repoUrl:z11.string(),commit:z11.string().regex(/^[a-f0-9]{40}$/i)}).strict(),inputSourceSchema.options[0].extend({repoUrl:z11.string(),commit:z11.string().regex(/^[a-f0-9]{40}$/i)}).strict(),inputSourceSchema.options[1].extend({repoUrl:z11.string(),commit:z11.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=z12.discriminatedUnion("type",[z12.object({type:z12.literal("git")}).strict(),z12.object({type:z12.literal("github-actions"),workflow:inputPathSchema.regex(/^\.github\/workflows\/[^/*?{}[\]]+\.ya?ml$/).describe("Workflow file in this repository, for example .github/workflows/build.yml."),artifact:z12.string().min(1).max(256).optional().describe("Upload name or pattern. Omit only when the workflow produces exactly one artifact.")}).strict()]);var skillInputPathSchema=z12.union([z12.literal("."),inputPathSchema.regex(/^[^*?{}[\]]+$/)]).describe("Explicit Skill directory or ZIP/tar.gz file containing SKILL.md at its root.");var runDefinitionInputSchema=z12.discriminatedUnion("type",[binaryUseSchema.extend({source:definitionInputSourceSchema.default({type:"git"})}).strict(),websiteUseSchema.extend({source:websiteSourceSchema}).strict(),z12.object({type:z12.literal("web-fixture"),source:definitionInputSourceSchema.default({type:"git"}),path:inputPathSchema.regex(/^[^*?{}[\]]+$/).describe("Explicit path to a version 1 web fixture JSON file.")}).strict(),z12.object({type:z12.literal("npm-package"),source:definitionInputSourceSchema.default({type:"git"}),path:inputPathSchema.describe("Path or glob selecting exactly one packed npm .tgz file."),install:z12.enum(["environment","workspace"]).default("environment").describe("environment exposes the package's commands on PATH; workspace adds a consumer application dependency.")}).strict(),z12.object({type:z12.literal("skill"),source:definitionInputSourceSchema.default({type:"git"}),path:skillInputPathSchema}).strict(),z12.object({type:z12.literal("files"),source:definitionInputSourceSchema.default({type:"git"}),paths:z12.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=z13.object({sha256:z13.string().regex(/^sha256:[a-f0-9]{64}$/),bytes:z13.number().int().positive().max(512*1024*1024)}).strict();var uncredentialedRepoUrlSchema=z13.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=z13.object({paths:z13.array(inputPathSchema).min(1).max(32)}).strict();var runDefinitionConfigSchema=z13.object({agents:z13.array(agentConfigInputSchema).min(1),sampleCount:z13.number().int().min(1).max(50).optional(),repoUrl:uncredentialedRepoUrlSchema.nullable().optional(),repoRef:z13.string().min(1).nullable().optional(),profileId:z13.string().min(1).nullable().optional(),skillRefs:assetRefListSchema.optional(),mcpRefs:assetRefListSchema.optional(),connectionIds:z13.array(z13.string().min(1)).max(32).optional(),addons:runAddonsSchema.optional(),inputs:z13.array(z13.string()).optional(),checks:runDefinitionChecksSchema.optional()}).strict();var runDefinitionFileConfigSchema=z13.object({version:z13.literal(2).default(2),org:z13.string().min(1).optional(),orgId:z13.string().uuid().optional(),checks:runDefinitionChecksSchema.optional(),cases:z13.array(inputPathSchema).min(1).max(32).default(["gauge-cases/**/*.md"]),inputs:z13.record(z13.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=z13.object({name:z13.string().min(1),rubric:z13.string().min(1)}).strict();var caseMeasurement={criteria:z13.array(runDefinitionCriterionSchema).min(1).optional(),preference:preferenceDefinitionSchema.optional()};function exactlyOneMeasurement(item){return item.criteria!==void 0!==(item.preference!==void 0)}var runDefinitionFrontmatterSchema=z13.object({...caseMeasurement,config:runDefinitionConfigSchema}).strict().refine(exactlyOneMeasurement,"Specify exactly one of criteria or preference");var runDefinitionCaseSchema=z13.object({path:z13.string().min(1),prompt:z13.string().min(1),...caseMeasurement,config:runDefinitionConfigSchema}).strict().refine(exactlyOneMeasurement,"Specify exactly one of criteria or preference");var runDefinitionSubmissionSchema=z13.object({version:z13.literal(2),lifecycle:lifecycleSchema.nullish(),cliRules:cliRuleAuthorInputSchema.optional(),source:z13.object({repoUrl:uncredentialedRepoUrlSchema.nullable(),commit:z13.string().regex(/^[a-f0-9]{40}$/i).nullable(),digest:z13.string().regex(/^sha256:[a-f0-9]{64}$/),verification:z13.enum(["SUBMITTED_UNVERIFIED","GITHUB_VERIFIED","LOCAL"])}).strict(),resources:z13.array(runPlanResourceSchema).max(32).default([]),cases:z13.array(runDefinitionCaseSchema).min(1).max(20)}).strict().superRefine((definition,ctx)=>{if(definition.source.verification==="GITHUB_VERIFIED"&&definition.cliRules!==void 0)ctx.addIssue({code:"custom",path:["cliRules"],message:"GitHub definitions cannot contain launch-only CLI rules"});if(definition.source.verification==="GITHUB_VERIFIED"&&definition.lifecycle!==void 0)ctx.addIssue({code:"custom",path:["lifecycle"],message:"GitHub definitions cannot contain launch-only lifecycle scripts"});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=z13.object({cliRules:z13.object({ruleCount:z13.number().int().positive(),bundleSha256:z13.string().regex(/^[a-f0-9]{64}$/)}).optional(),source:runDefinitionSubmissionSchema.shape.source,lifecycle:z13.object({setupTimeoutSeconds:z13.number().int().min(1).max(600).optional(),teardownTimeoutSeconds:z13.number().int().min(1).max(600).optional()}).optional(),measurementMode:z13.enum(["AGENT_EXPERIENCE","AGENT_PREFERENCE","MIXED"]),cases:z13.array(z13.object({path:z13.string(),agents:z13.array(agentConfigSchema),samples:z13.number().int().nonnegative(),expectedRuns:z13.number().int().nonnegative(),workspace:z13.object({repoUrl:z13.string().nullable(),repoRef:z13.string().nullable()}),criteriaCount:z13.number().int().nonnegative(),preference:preferenceDefinitionSchema.optional(),inputs:z13.array(z13.string())})),resources:z13.array(z13.object({name:z13.string(),type:z13.literal("input"),source:z13.enum(["git","github-actions","github-deployment","github-pr-comment","upload"]),use:inputUseSchema,readiness:z13.enum(["READY","WAITING","FAILED"]),detail:z13.string().optional(),commands:z13.array(z13.string()).optional()})),expectedRuns:z13.number().int().nonnegative(),canRun:z13.boolean()});var runDefinitionRunResponseSchema=z13.object({runRequestId:z13.string(),batchIds:z13.array(z13.string()),runIds:z13.array(z13.string()),requestedRuns:z13.number().int().nonnegative(),createdRuns:z13.number().int().nonnegative(),aggregateUrl:z13.string()});import{z as z14}from"zod";var caseSpecSchema=z14.object({version:z14.literal(2),cases:z14.array(z14.object({key:z14.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64).describe("Unique case id, lowercase-kebab"),prompt:z14.string().trim().min(1).describe("The user's request"),criteria:z14.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=()=>z14.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:
1027
+ ${run.id} rerun of ${run.sourceRunId??"?"}: ${run.status}, ${run.agent} ${run.model}`);if(run.forkedAfter!=null)console.log(` forked after seq ${run.forkedAfter}; cost and time cover only the part after the fork`);if(run.restoredFrom)console.log(` restored at seq ${run.restoredFrom.seq} (${run.restoredFrom.checkpointId}); cost and time cover only the part after the restore`);if(!run.findings){console.log(" not analyzed");continue}const now=new Set(run.findings.map(f=>f.label));const before=new Set(run.sourceFindings.map(f=>f.label));for(const f of run.sourceFindings)console.log(` ${now.has(f.label)?"returned":"resolved"} ${f.label}`);for(const f of run.findings)if(!before.has(f.label))console.log(` introduced ${f.label}`)}}function parseEdits(value){const ok=Array.isArray(value)&&value.length>0&&value.every(edit=>edit&&typeof edit==="object"&&typeof edit.find==="string"&&edit.find.length>0&&typeof edit.replace==="string");if(!ok)throw new CliError("usage","--edits must be a JSON array of {find, replace} with non-empty find");return value.map(({find,replace})=>({find,replace}))}function printWrite(res){if(!res.change){console.log(`Wrote ${res.key}`);return}const{linesBefore,linesAfter,retainedPercent,hunks}=res.change;console.log(`Wrote ${res.key}: ${linesBefore} \u2192 ${linesAfter} lines, ${retainedPercent??"\u2014"}% of the original kept`);console.log(hunks)}function printPageView(view){const content=view.text??view.raw;if(content!==void 0){console.log(content);return}console.log(`${view.matches??0} matches for ${JSON.stringify(view.query)}`);for(const excerpt of view.excerpts??[]){console.log(`=== offset ${excerpt.offset}`);console.log(excerpt.raw)}if(view.truncated)console.log("\u2026 more matches; search a longer phrase");if(view.hint)console.log(view.hint)}function parsePositiveSeq(raw){const seq=Number(raw);return/^\d+$/.test(raw)&&seq>=1&&Number.isSafeInteger(seq)?seq:null}function parseForkBefore(raw){const at=raw.lastIndexOf(":");const seq=parsePositiveSeq(raw.slice(at+1));if(at<=0||seq===null)throw new CliError("usage",`--fork-before takes <sourceRunId>:<seq>, e.g. run_1:34 (got ${raw})`);return{runId:raw.slice(0,at),seq}}function checkForkBefore(forkBefore,opts){const seen=new Set;for(const{runId}of forkBefore){if(seen.has(runId))throw new CliError("usage",`--fork-before names ${runId} twice`);seen.add(runId);if(opts.run?.length&&!opts.run.includes(runId))throw new CliError("usage",`--fork-before names ${runId}, but --run leaves it out`);if(opts.fresh===true||opts.fresh?.includes(runId))throw new CliError("usage",`--fork-before and --fresh both name ${runId}; pick one`)}}function parseRestoreBefore(raw){const at=raw.lastIndexOf(":");const rerunId=raw.slice(0,at);const seq=raw.slice(at+1);if(at<=0||!/^-?\d+$/.test(seq))throw new CliError("usage",`--restore-before takes <rerunId>:<seq>, e.g. run_1:140 (got ${raw})`);return{rerunId,seq:Number(seq)}}function checkpointRow(cp){const exposure=[...cp.exposure.surfaces,...cp.exposure.skillChanged?["skill changed"]:[],...cp.exposureIncomplete?["trace incomplete"]:[]];return{checkpoint:cp.checkpointId,source:cp.sourceRunId,rerun:cp.rerunId,seq:`${cp.seq}/${cp.rerunEventCount}`,exposure:exposure.join(", ")||"clean","last step":cp.lastSteps.at(-1)??"",captured:cp.capturedAt}}function printLaunchResult(id2,res){console.log(`Launched ${plural(res.batches.flatMap(b=>b.runIds).length,"rerun")} (${res.launchId}) with ${plural(res.changed.length,"changed file")}:`);for(const key of res.changed)console.log(` ${key}`);for(const batch of res.batches){const from=batch.restoredFrom;console.log(batch.forkedAfter!=null?`${batch.sourceRunId}: forked after seq ${batch.forkedAfter}`:from?`${batch.sourceRunId}: restored at seq ${from.seq} of rerun ${from.rerunId} (${from.checkpointId})`:`${batch.sourceRunId}: fresh`);for(const warning of batch.warnings)console.log(` ! ${warning}`)}console.log(`Follow with \`gauge optimizations watch ${id2}\`.`)}function register23(program2){const group=hostedOnly(program2.command("optimizations")).description("Hill climb your agent surfaces: edit the pages, skills, and CLI rules agent sessions used, rerun those sessions, and compare findings");group.command("list").description("List the org's optimizations, newest activity first").option("--status <status>",STATUSES2.join(", ")).option("--limit <n>","max rows (default 50)").action(async(opts,cmd)=>{const res=await createClient().get(basePath(await resolveOrg(cmd)),{status:parseStatus(opts.status),limit:parseCount(opts.limit,"--limit",200)});if(resolveOutput(cmd)==="json")printJson(res.items);else printItems(res.items.map(toRow2),"table")});group.command("create").description("Open an optimization on an issue, one finding, or a goal; the tree starts empty").option("--issue <id>","an issue id from `gauge issues list`").option("--finding <id>","a finding id from `gauge run insight <run> -o json`; needs --run").option("--run <runId>","the run the finding is on").option("--goal <text>","free text; starts with no sessions, attach them with `sessions add`").option("--title <title>","name (default: from the subject)").action(async(opts,cmd)=>{const detail=await createClient().post(basePath(await resolveOrg(cmd)),{subject:parseSubjectRef(opts),...opts.title?{title:opts.title}:{}});if(resolveOutput(cmd)==="json")printJson(detail);else console.log(detail.sourceRunIds.length?`Opened ${detail.id} "${detail.title}" on ${plural(detail.sourceRunIds.length,"source session")}. Next: \`gauge optimizations authoring ${detail.id}\`.`:`Opened ${detail.id} "${detail.title}" with no sessions. Next: \`gauge optimizations sessions add ${detail.id} <runId...>\`.`)});group.command("get <id>").description("One optimization: subject, source runs, tree, and launches").action(async(id2,_opts,cmd)=>{const detail=await createClient().get(itemPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)==="json")printJson(detail);else printDetail2(detail)});group.command("authoring <id>").description("Authoring guidance: the source sessions' findings, the tree, and the editing practices to follow").action(async(id2,_opts,cmd)=>{const res=await createClient().get(`${itemPath(await resolveOrg(cmd),id2)}/authoring`);if(resolveOutput(cmd)==="json")printJson(res);else console.log(res.guidance)});group.command("sessions").description("Attach sessions an optimization can rerun").command("add <id> <runIds...>").description("Attach sessions to rerun, up to 12 in all; a goal starts with none. Optimization reruns cannot be sources").action(async(id2,runIds,_opts,cmd)=>{const res=await createClient().post(`${itemPath(await resolveOrg(cmd),id2)}/sessions`,{runIds});if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Attached ${plural(res.added.length,"session")}; ${id2} has ${plural(res.sourceRunIds.length,"source session")}.`)});const file=group.command("file").description("Read and edit the files in an optimization's tree");file.command("read <id> <key>").description("Print one file by tree key: a page's exact source (--text for readable text, --query for the source around a match), a skill (or one --path in it), or CLI rules").option("--text","page only: readable text instead of the source").option("--query <text>","page only: the exact source around each match, to copy into file edit").option("--path <path>","one file inside a skill").option("--out <file>","save the page source or skill --path to a file").action(async(id2,key,opts,cmd)=>{const path=`${itemPath(await resolveOrg(cmd),id2)}/files`;if(opts.text||opts.query){if(opts.out)throw new CliError("usage","--out saves the stored file only");const view=await createClient().get(path,{key,...opts.query?{query:opts.query}:{view:"text"}});if(resolveOutput(cmd)==="json")printJson(view);else printPageView(view);return}const res=await createClient().get(path,{key});if(opts.out){const body2=res.kind==="page"?res.body:res.kind==="skill"&&opts.path?res.files[opts.path]:void 0;if(body2===void 0)throw new CliError("usage","--out saves a page source or one skill --path");writeFileSync2(opts.out,body2);console.error(`Saved ${opts.out}`)}else if(resolveOutput(cmd)==="json")printJson(res);else printFile(res,opts.path)});file.command("edit <id>").description("Edit a page in the tree with find/replace on its exact source; every byte outside the edits stays. Each find must appear once; all edits apply or none do").requiredOption("--page <url>","the page URL").requiredOption("--edits <file>","JSON [{find, replace}]; copy find text from `file read --query`; '-' for stdin").action(async(id2,opts,cmd)=>{const res=await createClient().patch(`${itemPath(await resolveOrg(cmd),id2)}/files`,{url:opts.page,edits:parseEdits(readJson2(opts.edits))});if(resolveOutput(cmd)==="json")printJson(res);else printWrite(res)});file.command("add <id>").description("Copy an original into the tree before you edit it: a page a source session read (else the live page), a staged skill, or the CLI rules").option("--page <url>","a page by URL").option("--skill <name>","a skill a source session staged").option("--cli","the CLI rules a source session ran with").action(async(id2,opts,cmd)=>{const res=await createClient().post(`${itemPath(await resolveOrg(cmd),id2)}/files`,fileSourceFromOpts(opts));if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Added ${res.key} (from ${res.origin})`)});file.command("write <id>").description("Write a new page or rewrite a whole one, one skill file, or the CLI rules; to change part of a page, use file edit").option("--page <url>","the page URL; --from holds the complete body").option("--content-type <type>","the page content type (default: keep)").option("--skill <name>","the skill; needs --path").option("--path <path>","the file inside the skill, e.g. SKILL.md").option("--delete","remove --path from the skill").option("--cli <package>","the CLI package; --from holds {schemaVersion: 3, target, rules, shippingIntent}").option("--from <file>","the new content; '-' for stdin").action(async(id2,opts,cmd)=>{const res=await createClient().put(`${itemPath(await resolveOrg(cmd),id2)}/files`,fileEditFromOpts(opts));if(resolveOutput(cmd)==="json")printJson(res);else printWrite(res)});file.command("rm <id> <key>").description("Drop a file from the tree; reruns use what the source session had").action(async(id2,key,_opts,cmd)=>{const res=await createClient().delete(`${itemPath(await resolveOrg(cmd),id2)}/files`,{key});if(resolveOutput(cmd)==="json")printJson(res);else console.log(`Removed ${res.removed}`)});group.command("notes <id>").description("Print the working notes, or replace them with --from: markdown the user reads beside the chat").option("--from <file>","the complete notes; '-' for stdin").action(async(id2,opts,cmd)=>{const path=itemPath(await resolveOrg(cmd),id2);const client=createClient();const detail=opts.from?await client.patch(path,{notes:readText(opts.from)}):await client.get(path);if(resolveOutput(cmd)==="json")printJson({notes:detail.notes});else if(opts.from)console.log(`Saved notes (${detail.notes.length} chars)`);else console.log(detail.notes||"(no notes)")});group.command("launch <id>").description("Rerun the source sessions with the tree injected. A recorded run forks: it repeats the source's recorded steps up to its last tool call before the first changed surface, then continues live. Other runs restore from the deepest checkpoint before any changed surface, or start fresh").option("--run <runId...>","rerun only these source runs").option("--note <text>","one line on what this launch tests").option("--fork-before <sourceRunId:seq...>","fork this recorded source run at its last tool call before this seq").option("--restore-before <rerunId:seq...>","restore from the deepest checkpoint at or before this seq of an earlier rerun").option("--checkpoint <checkpointId...>","restore from this checkpoint (see `checkpoints`)").option("--fresh [sourceRunId...]","start from zero, with no fork and no restore: these source runs, or every one").option("--yes","skip the confirmation").action(async(id2,opts,cmd)=>{const restoreAt=[...(opts.checkpoint??[]).map(checkpointId=>({checkpointId})),...(opts.restoreBefore??[]).map(parseRestoreBefore)];const forkBefore=(opts.forkBefore??[]).map(parseForkBefore);checkForkBefore(forkBefore,opts);const path=itemPath(await resolveOrg(cmd),id2);await confirmOrAbort(`Rerun ${opts.run?.length?plural(opts.run.length,"source session"):"every source session"} of ${id2} with the tree?`,opts.yes);const client=createClient();const fresh=opts.fresh===true?opts.run??(await client.get(path)).sourceRunIds:opts.fresh??[];const res=await client.post(`${path}/launch`,{...opts.run?.length?{runIds:opts.run}:{},...opts.note?{note:opts.note}:{},...fresh.length?{restore:Object.fromEntries(fresh.map(runId=>[runId,"none"]))}:{},...restoreAt.length?{restoreAt}:{},...forkBefore.length?{forkBefore}:{}});if(resolveOutput(cmd)==="json")printJson(res);else printLaunchResult(id2,res)});group.command("checkpoints <id>").description("Checkpoints captured on fresh reruns, with how far in each is and whether its prefix saw a changed surface").option("--run <sourceRunId>","only this source run").action(async(id2,opts,cmd)=>{const res=await createClient().get(`${itemPath(await resolveOrg(cmd),id2)}/checkpoints`,{sourceRunId:opts.run});if(resolveOutput(cmd)==="json")printJson(res.items);else if(!res.items.length)console.log("(no checkpoints)");else printItems(res.items.map(checkpointRow),"table")});group.command("launches <id> [launchId]").description("List launches, or one launch's reruns with their findings beside the source findings").action(async(id2,launchId,_opts,cmd)=>{const path=itemPath(await resolveOrg(cmd),id2);const client=createClient();if(!launchId){const detail=await client.get(path);if(resolveOutput(cmd)==="json")printJson(detail.launchList);else printItems(detail.launchList.map(launchRow),"table");return}const launch2=await client.get(`${path}/launches/${encodeURIComponent(launchId)}`);if(resolveOutput(cmd)==="json")printJson(launch2);else printLaunch(launch2)});group.command("watch <id>").description("Wait until the latest launch's reruns finish and are analyzed, then print them").option("--interval <seconds>","poll interval (default 15)").option("--timeout <minutes>","give up after this long (default 60)").action(async(id2,opts,cmd)=>{const path=itemPath(await resolveOrg(cmd),id2);const client=createClient();const interval=(parseCount(opts.interval,"--interval",600)??15)*1e3;const timeoutMinutes=parseCount(opts.timeout,"--timeout",1440)??60;const deadline=Date.now()+timeoutMinutes*6e4;let last="";for(;;){const detail=await client.get(path);const latest=latestLaunch(detail.launchList);if(!latest)throw new CliError("usage",`${id2} has no launches yet`);if(launchSettled(latest)){const launch2=await client.get(`${path}/launches/${encodeURIComponent(latest.id)}`);if(resolveOutput(cmd)==="json")printJson(launch2);else printLaunch(launch2);return}const progress=launchProgress(latest);if(progress!==last)console.error(`launch ${latest.number}: ${progress}`);last=progress;if(Date.now()>=deadline)throw new CliError("network",`Timed out after ${timeoutMinutes} minutes (launch ${latest.number}: ${progress}). Re-run watch, or check \`gauge optimizations launches ${id2} ${latest.id}\`.`);await sleep3(interval)}});group.command("finish <id>").description("Close the optimization with its result: summary, changed keys, and findings resolved, returned, and introduced").requiredOption("--from <file>","result JSON: {summary, changed, resolved, returned, introduced}").option("--yes","skip the confirmation").action(async(id2,opts,cmd)=>{const path=itemPath(await resolveOrg(cmd),id2);const result=readJson2(opts.from);await confirmOrAbort(`Finish ${id2}? Its tree can no longer change.`,opts.yes);const detail=await createClient().post(`${path}/finish`,result);if(resolveOutput(cmd)==="json")printJson(detail);else console.log(`Finished ${detail.id} "${detail.title}"`)})}var org_exports={};__export(org_exports,{register:()=>register24});var WEEKDAYS=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];function orgPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}`}function parseWeekday(raw){const value=raw.trim().toLowerCase();const day=/^[0-6]$/.test(value)?Number(value):WEEKDAYS.findIndex(d=>value.length>=3&&d.startsWith(value));if(day<0)throw new CliError("usage",`invalid --day "${raw}" (expected a weekday name, such as monday)`);return day}function parseCadence2(raw){const cadence=raw.trim().toUpperCase();if(cadence!=="DAILY"&&cadence!=="WEEKLY")throw new CliError("usage",`invalid --cadence "${raw}" (expected daily or weekly)`);return cadence}function weekdayLabel(day){const name=WEEKDAYS[day];return name?`${name[0].toUpperCase()}${name.slice(1)}s`:String(day)}function scheduleLabel(s){return s.cadence==="DAILY"?"daily":`weekly on ${weekdayLabel(s.weeklyRunDay)}`}function rosterLabel(agents){if(agents.length===0)return"none (tracked prompts do not run)";return agents.flatMap(({agent,models})=>models.length?models.map(model=>`${model} (${agent.toLowerCase()})`):[`${agent.toLowerCase()} default`]).join(", ")}function printTracking(schedule,counts){console.log(`schedule: ${scheduleLabel(schedule)}`);console.log(`next run: ${schedule.nextRunAt??"not set yet"}`);if(schedule.agents)console.log(`models: ${rosterLabel(schedule.agents)}`);if(counts)console.log(`tracking: ${counts.tracked} of ${counts.total} prompts`)}async function showTracking(cmd){const base=orgPath(await resolveOrg(cmd));const client=createClient();const[settings,prompts]=await Promise.all([client.get(base),client.get(`${base}/visibility-prompts`)]);const schedule=settings.preferenceSchedule;if(!schedule)throw new CliError("upgrade_required","This Gauge server does not support preference tracking yet");const counts={tracked:prompts.items.filter(prompt=>prompt.tracked).length,total:prompts.items.length};if(resolveOutput(cmd)==="json")printJson({...schedule,...counts});else printTracking(schedule,counts)}async function setTracking(cmd,opts){const body2={};if(opts.cadence!==void 0)body2.cadence=parseCadence2(opts.cadence);if(opts.day!==void 0)body2.weeklyRunDay=parseWeekday(opts.day);if(opts.agents===false){if(opts.agent.length>0)throw new CliError("usage","--agent and --no-agents conflict");body2.agents=[]}else if(opts.agent.length>0)body2.agents=buildAgentRoster(opts.agent);if(Object.keys(body2).length===0)throw new CliError("usage","nothing to change (pass --cadence, --day, --agent, or --no-agents)");const schedule=await createClient().patch(`${orgPath(await resolveOrg(cmd))}/preference-schedule`,body2);if(resolveOutput(cmd)==="json")printJson(schedule);else{printTracking(schedule);if(body2.agents?.length===0)console.error("warning: no models are tracked, so tracked prompts stop running")}}async function setPromptsTracked(cmd,ids,tracked){const base=`${orgPath(await resolveOrg(cmd))}/visibility-prompts`;const client=createClient();const updated=await Promise.all([...new Set(ids)].map(id2=>client.patch(`${base}/${encodeURIComponent(id2)}`,{tracked})));if(resolveOutput(cmd)==="json")printJson(updated.map(({id:id2,tracked:tracked2})=>({id:id2,tracked:tracked2})));else console.log(`${tracked?"Tracked":"Untracked"} ${updated.length} preference ${updated.length===1?"prompt":"prompts"}`)}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"}`);if(s.preferenceSchedule)console.log(`preference runs: ${scheduleLabel(s.preferenceSchedule)} (see \`gauge preference tracking\`)`)}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 writeFileSync3}from"fs";import{join as join8}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;writeFileSync3(join8(state.root,"gauge.json"),`${JSON.stringify({...config,orgId:org.id},null,2)}
1028
+ `)}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(id2,_opts,cmd)=>{const org=await resolveOrg(cmd);const persona=await createClient().get(`${personasPath(org)}/${encodeURIComponent(id2)}`);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(id2,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(id2)}`,{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(id2,_opts,cmd)=>{const org=await resolveOrg(cmd);await createClient().delete(`${personasPath(org)}/${encodeURIComponent(id2)}`);if(resolveOutput(cmd)!=="json")console.log(`Deleted persona ${id2}`)})}var preference_exports={};__export(preference_exports,{register:()=>register27});import{Option as Option5}from"commander";function visibilityPath(org){return`/api/v1/orgs/${encodeURIComponent(org)}/visibility-prompts`}function promptPath(org,id2){return`${visibilityPath(org)}/${encodeURIComponent(id2)}`}function scenariosPath(org,id2){return`${promptPath(org,id2)}/scenarios`}function scenarioRow(scenario){return{id:scenario.id,repo:scenario.repoUrl??"(empty project)",ref:scenario.repoRef??""}}function personaName(v){const profile=v.profile===void 0?v.scenarios[0]?.profile:v.profile;return profile?.name??"default persona"}var PERSONA_MOVED="A preference prompt runs as one persona across all its repositories. Set it on the prompt: `gauge preference edit <id> --persona <profileId>`.";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(", "),tracked:v.tracked===void 0?"":v.tracked?"yes":"no",runs:v.runCount,"last run":v.lastRunAt??"-","created by":creatorLabel(v.createdBy)}}function printDetail3(v,local){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)"}`);if(v.tracked!==void 0)console.log(`tracked: ${v.tracked?"yes":"no"}`);console.log(`runs: ${v.runCount} (last: ${v.lastRunAt??"never"})`);console.log(`creator: ${creatorLabel(v.createdBy)}`);console.log(`prompt: ${v.promptText}`);console.log(`persona: ${personaName(v)}`);console.log(`samples: ${v.sampleCount}`);console.log(`${local?"agents: ":"models: "} ${v.agents.map(a=>a.models.length?`${a.agent}:${a.models.join(",")}`:a.agent).join(", ")}${local?"":" (the org's tracked models)"}`);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}`:""}`)}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,id2){const vp=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"preference",id2)):await createClient().get(promptPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)==="json")printJson(vp);else printDetail3(vp,isLocal(cmd))}function rejectPromptCadence(cadence){if(cadence!==void 0&&cadence.trim().toUpperCase()!=="NONE")throw new CliError("usage","Preference prompts no longer have a cadence. Run `gauge preference track <id>` to put a prompt on the org's preference schedule, and set that schedule with `gauge preference tracking set --cadence daily|weekly`.")}function rejectHostedAgents(cmd,agents){if(agents.length>0&&!isLocal(cmd))throw new CliError("usage","Preference prompts no longer store models. Set the models every tracked prompt runs on with `gauge preference tracking set --agent <agent[:models]>`, or run once on other models with `gauge run --preference <id> --agent <agent[:models]>`.")}function rejectLocalTracked(cmd,tracked){if(tracked!==void 0&&isLocal(cmd))throw new CliError("usage","Tracking requires hosted Gauge; local prompts run on demand. Pass --hosted.")}async function createPreferencePrompt(cmd,opts){rejectPromptCadence(opts.cadence);rejectLocalTracked(cmd,opts.tracked);rejectHostedAgents(cmd,opts.agent);opts={...opts,cadence:void 0};if(hasLifecycleFlags(opts)&&isLocal(cmd))throw new CliError("usage","Lifecycle scripts require hosted execution; pass --hosted");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");if(opts.persona!==void 0&&isLocal(cmd))throw new CliError("usage","Personas require hosted Gauge");const body2={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,...opts.tracked!==void 0?{tracked:opts.tracked}:{},...hasRunSettingsFlags(opts)?runSettingsFromOpts(opts):{},...opts.persona!==void 0?{profileId:opts.persona}:{},scenarios:opts.repo!==void 0?[{repoUrl:opts.repo,repoRef:opts.ref??null}]:[]};const created=isLocal(cmd)?createLocalMeasurement(cmd,"preference",body2):await createClient().post(visibilityPath(await resolveOrg(cmd)),body2);if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Created preference prompt ${created.id}`)}async function editPreferencePrompt(cmd,id2,opts){rejectPromptCadence(opts.cadence);rejectLocalTracked(cmd,opts.tracked);rejectHostedAgents(cmd,opts.agent);opts={...opts,cadence:void 0};if(hasLifecycleFlags(opts)&&isLocal(cmd))throw new CliError("usage","Lifecycle scripts require hosted execution; pass --hosted");const lifecyclePath=hasLifecycleFlags(opts)&&!opts.clearLifecycle?promptPath(await resolveOrg(cmd),id2):void 0;const existing=lifecyclePath?await createClient().get(lifecyclePath):void 0;const body2={...runSettingsPatchFromOpts(opts,existing?.lifecycle)};if(opts.name!==void 0)body2.name=opts.name;if(opts.text!==void 0||opts.file!==void 0)body2.promptText=readPromptText(opts);if(opts.brandA!==void 0)body2.brandA=opts.brandA;if(opts.brandB!==void 0)body2.brandB=opts.brandB;if(opts.branded&&opts.organic)throw new CliError("usage","--branded and --organic conflict");if(opts.branded)body2.branded=true;else if(opts.organic)body2.branded=false;if(opts.market!==void 0&&opts.clearMarket)throw new CliError("usage","--market and --clear-market conflict");if(opts.clearMarket)body2.marketId=null;else if(opts.market!==void 0)body2.marketId=opts.market;if(opts.tag.length>0&&opts.clearTags)throw new CliError("usage","--tag and --clear-tags conflict");if(opts.clearTags)body2.tags=[];else if(opts.tag.length>0)body2.tags=opts.tag;if(opts.tracked!==void 0)body2.tracked=opts.tracked;if(opts.persona!==void 0&&opts.defaultPersona)throw new CliError("usage","--persona and --default-persona conflict");if((opts.persona!==void 0||opts.defaultPersona)&&isLocal(cmd))throw new CliError("usage","Personas require hosted Gauge");if(opts.defaultPersona)body2.profileId=null;else if(opts.persona!==void 0)body2.profileId=opts.persona;if(Object.keys(body2).length===0)throw new CliError("usage","nothing to change");const updated=isLocal(cmd)?editLocalMeasurement(cmd,"preference",id2,body2):await createClient().patch(lifecyclePath??promptPath(await resolveOrg(cmd),id2),body2);if(resolveOutput(cmd)==="json")printJson(updated);else console.log(`Updated preference prompt ${updated.id}`)}async function removePreferencePrompt(cmd,id2){if(isLocal(cmd))removeLocalMeasurement(cmd,"preference",id2);else await createClient().delete(promptPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)!=="json")console.log(`Deleted preference prompt ${id2}`)}async function listScenarios(cmd,id2){const vp=isLocal(cmd)?localMeasurementView(getLocalMeasurement(cmd,"preference",id2)):await createClient().get(promptPath(await resolveOrg(cmd),id2));if(resolveOutput(cmd)==="json")printJson(vp.scenarios);else printItems(vp.scenarios.map(scenarioRow),"table")}async function addScenario(cmd,id2,opts){if(opts.persona!==void 0)throw new CliError("usage",PERSONA_MOVED.replace("<id>",id2));if(opts.ref!==void 0&&opts.repo===void 0)throw new CliError("usage","--ref requires --repo");if(isLocal(cmd)){const row2=getLocalMeasurement(cmd,"preference",id2);const updated=editLocalMeasurement(cmd,"preference",id2,{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),id2),{repoUrl:opts.repo??null,repoRef:opts.ref??null});if(resolveOutput(cmd)==="json")printJson(created);else console.log(`Added scenario ${created.id}`)}async function removeScenario(cmd,id2,scenarioId){if(isLocal(cmd)){const row2=getLocalMeasurement(cmd,"preference",id2);const scenarios=row2.scenarios;if(!scenarios.some(s=>s.id===scenarioId))throw new CliError("usage",`Unknown scenario: ${scenarioId}`);editLocalMeasurement(cmd,"preference",id2,{scenarios:scenarios.filter(s=>s.id!==scenarioId)});if(resolveOutput(cmd)!=="json")console.log(`Removed scenario ${scenarioId}`);return}await createClient().delete(`${scenariosPath(await resolveOrg(cmd),id2)}/${encodeURIComponent(scenarioId)}`);if(resolveOutput(cmd)!=="json")console.log(`Removed scenario ${scenarioId}`)}async function runPreferencePrompt(cmd,id2,opts){const org=await resolveOrg(cmd);const overrides={...runOverridesFromOpts(opts),...opts.cliRules?{cliRules:opts.cliRules}:{},...hasLifecycleFlags(opts)?lifecyclePatchFromOpts(opts,(await createClient().get(promptPath(org,id2))).lifecycle):{}};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,id2)}/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}`)}return result}async function listPreferencePromptRuns(cmd,id2,opts){const res=await createClient().get(`${promptPath(await resolveOrg(cmd),id2)}/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").option("--tracked","only prompts on the org's preference schedule").option("--untracked","only prompts that run on demand").action(async(opts,cmd)=>{if(opts.tracked&&opts.untracked)throw new CliError("usage","--tracked and --untracked conflict");const items=(await filterByCreator(await listPreferencePrompts(cmd),opts.createdBy)).filter(item=>opts.tracked?item.tracked===true:opts.untracked?item.tracked!==true:true);if(resolveOutput(cmd)==="json")printJson(items);else printItems(items.map(preferencePromptRow),"table")});const tracking=hostedOnly(preference.command("tracking").description("When tracked preference prompts run and the models they run on. Rankings count only these runs"));tracking.command("show",{isDefault:true}).description("Show the schedule, the tracked models, and how many prompts are tracked").action(async(_opts,cmd)=>{await showTracking(cmd)});tracking.command("set").description("Change the schedule or the tracked models for every tracked prompt. Omitted flags keep their value").option("--cadence <cadence>","daily | weekly").option("--day <weekday>","weekly run day, such as monday").option("--agent <agent[:m1,m2]>","a tracked agent and its models (repeatable; replaces the whole list; see `gauge models`)",collect5,[]).option("--no-agents","track no models, which stops scheduled runs").action(async(opts,cmd)=>{await setTracking(cmd,opts)});hostedOnly(preference.command("track <ids...>").description("Put preference prompts on the org's schedule. Each scheduled run spends credits")).action(async(ids,_opts,cmd)=>{await setPromptsTracked(cmd,ids,true)});hostedOnly(preference.command("untrack <ids...>").description("Take preference prompts off the org's schedule")).action(async(ids,_opts,cmd)=>{await setPromptsTracked(cmd,ids,false)});preference.command("get <id>").description("Show one preference prompt").action(async(id2,_opts,cmd)=>{await getPreferencePrompt(cmd,id2)});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>","the persona every repository runs as (default persona if omitted)"),{cadence:false}).addOption(new Option5("--cadence <cadence>").hideHelp()).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,[]).option("--tracked","run on the org's preference schedule and spend credits (default: not tracked)").option("--no-tracked","run only on demand (the default)").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)'),{cadence:false}).addOption(new Option5("--cadence <cadence>").hideHelp()).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").option("--tracked","run on the org's preference schedule and spend credits").option("--no-tracked","stop scheduled runs; run only on demand").option("--persona <profileId>","the persona every repository runs as").option("--default-persona","run as the default persona").action(async(id2,opts,cmd)=>{await editPreferencePrompt(cmd,id2,opts)});preference.command("rm <id>").description("Delete a preference prompt (run history stays)").action(async(id2,_opts,cmd)=>{await removePreferencePrompt(cmd,id2)});const scenarios=preference.command("scenarios").description("The repositories a preference prompt runs in, all as the prompt's persona");scenarios.command("list <id>").description("List a preference prompt's scenarios").action(async(id2,_opts,cmd)=>{await listScenarios(cmd,id2)});scenarios.command("add <id>").description("Add one repository scenario").option("--repo <url>","repository URL (default: empty project)").option("--ref <ref>","branch, tag, or commit (with --repo)").addOption(new Option5("--persona <profileId>").hideHelp()).action(async(id2,opts,cmd)=>{await addScenario(cmd,id2,opts)});scenarios.command("rm <id>").description("Remove one scenario").requiredOption("--scenario <scenarioId>","scenario id to remove").action(async(id2,opts,cmd)=>{await removeScenario(cmd,id2,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 body2={url};if(opts.name!==void 0)body2.name=opts.name;if(opts.clearFrameworks)body2.frameworks=[];else if(opts.framework.length>0)body2.frameworks=opts.framework;if(opts.clearTags)body2.tags=[];else if(opts.tag.length>0)body2.tags=opts.tag;if(Object.keys(body2).length===1)throw new CliError("usage","nothing to change");const repo=await createClient().patch(reposPath(org),body2);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 readFileSync10,statSync as statSync3}from"fs";function readCliRules(path){if(path==="-")throw new CliError("usage","--cli-rules expects a JSON file path, not stdin");try{const info=statSync3(path);if(!info.isFile())throw new Error("Expected a regular JSON file");if(info.size>CLI_RULE_LIMITS.bundleBytes)throw new Error("CLI rules file exceeds 2 MiB");return cliRuleAuthorInputSchema.parse(JSON.parse(readFileSync10(path,"utf8")))}catch(error){throw new CliError("usage",`Invalid --cli-rules file: ${error instanceof Error?error.message:error}`)}}import{readFileSync as readFileSync13,existsSync as existsSync4,mkdirSync as mkdirSync2,writeFileSync as writeFileSync5}from"fs";import{z as z17}from"zod";import{join as join11,relative as relative5}from"path";import{z as z8}from"zod";var preferenceDefinitionSchema=z8.discriminatedUnion("kind",[z8.object({kind:z8.literal("open-ended"),branded:z8.boolean().default(false)}).strict(),z8.object({kind:z8.literal("head-to-head"),brandA:z8.string().trim().min(1),brandB:z8.string().trim().min(1)}).strict().refine(p=>p.brandA.toLowerCase()!==p.brandB.toLowerCase(),"A head-to-head needs two different brands")]);var preferenceSnapshotSchema=z8.object({version:z8.literal(1),preference:preferenceDefinitionSchema}).strict();var headToHeadSchema=z8.object({kind:z8.literal("HEAD_TO_HEAD"),assessability:z8.enum(["assessed","partial","unassessable"]).optional(),selectionStatus:z8.enum(["measured","not_measured","unassessable"]).optional(),winner:z8.enum(["A","B","both","neither"]),brandA:z8.string(),brandB:z8.string(),rationale:z8.string(),brandAReasoning:z8.string(),brandBReasoning:z8.string(),brandAWhyRaised:z8.string().optional(),brandBWhyRaised:z8.string().optional()});var recommendPickSchema=z8.object({brand:z8.string(),rank:z8.number().int(),adopted:z8.boolean(),reasoning:z8.string().optional(),whyRaised:z8.string().optional()});var recommendSchema=z8.object({kind:z8.literal("RECOMMEND"),selectedBrands:z8.array(z8.string()).optional(),assessability:z8.enum(["assessed","partial","unassessable"]).optional(),selectionStatus:z8.enum(["measured","not_measured","unassessable"]).optional(),picks:z8.array(recommendPickSchema).default([]),singlePick:z8.boolean(),complianceNote:z8.string()});var visibilityVerdictSchema=z8.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 Option6}from"commander";import{readFileSync as readFileSync11}from"fs";import{z as z9}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(source2){let raw;if(source2==="-"){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=readFileSync11(source2,"utf8")}catch(e){throw new CliError("usage",`cannot read spec file ${source2}: ${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:
1029
+ ${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 id2 of res.runIds)console.log(` run ${id2}`);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=()=>z9.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);return result}import{createHash as createHash3}from"crypto";import{z as z13}from"zod";import{z as z10}from"zod";var runAddonsSchema=z10.object({browser:z10.object({session:z10.string().min(1),projectId:z10.number().int().positive(),region:z10.literal("us").default("us")}).strict().optional()}).strict();import{z as z12}from"zod";import{z as z11}from"zod";var inputPathSchema=z11.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=z11.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=z11.object({type:z11.literal("binary"),paths:z11.array(inputPathSchema).min(1).max(32),platform:z11.literal("linux-x64").describe("Linux x86-64 ELF executables compatible with the consumer sandbox. No system packages are installed."),commands:z11.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=z11.discriminatedUnion("type",[binaryUseSchema,websiteUseSchema,z11.object({type:z11.literal("web-fixture"),path:inputPathSchema.regex(/^[^*?{}[\]]+$/)}).strict(),z11.object({type:z11.literal("files"),paths:z11.array(inputPathSchema).min(1).max(32).optional()}).strict(),z11.object({type:z11.literal("npm-cli"),package:inputPathSchema,install:z11.enum(["environment","workspace"]).optional()}).strict(),z11.object({type:z11.literal("npm-package"),package:inputPathSchema,install:z11.enum(["environment","workspace"]).optional()}).strict(),z11.object({type:z11.literal("skill"),root:z11.union([z11.literal("."),inputPathSchema]).refine(path=>!/[*?{}[\]]/.test(path),"Skill root must be an explicit directory")}).strict()]);var inputSourceSchema=z11.discriminatedUnion("type",[z11.object({type:z11.literal("git"),paths:z11.array(inputPathSchema).min(1).max(32)}).strict(),z11.object({type:z11.literal("github-actions"),artifact:z11.string().min(1).max(256).optional()}).strict()]);var runPlanResourceSchema=z11.object({name:z11.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64),type:z11.literal("input"),source:z11.discriminatedUnion("type",[z11.object({type:z11.literal("upload"),sha256:z11.string().regex(/^sha256:[a-f0-9]{64}$/),bytes:z11.number().int().positive().max(512*1024*1024),repoUrl:z11.string().nullable(),commit:z11.string().regex(/^[a-f0-9]{40}$/i).nullable()}).strict(),commentSourceSchema.extend({repoUrl:z11.string(),commit:z11.string().regex(/^[a-f0-9]{40}$/i)}).strict(),deploymentSourceSchema.extend({repoUrl:z11.string(),commit:z11.string().regex(/^[a-f0-9]{40}$/i)}).strict(),inputSourceSchema.options[0].extend({repoUrl:z11.string(),commit:z11.string().regex(/^[a-f0-9]{40}$/i)}).strict(),inputSourceSchema.options[1].extend({repoUrl:z11.string(),commit:z11.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=z12.discriminatedUnion("type",[z12.object({type:z12.literal("git")}).strict(),z12.object({type:z12.literal("github-actions"),workflow:inputPathSchema.regex(/^\.github\/workflows\/[^/*?{}[\]]+\.ya?ml$/).describe("Workflow file in this repository, for example .github/workflows/build.yml."),artifact:z12.string().min(1).max(256).optional().describe("Upload name or pattern. Omit only when the workflow produces exactly one artifact.")}).strict()]);var skillInputPathSchema=z12.union([z12.literal("."),inputPathSchema.regex(/^[^*?{}[\]]+$/)]).describe("Explicit Skill directory or ZIP/tar.gz file containing SKILL.md at its root.");var runDefinitionInputSchema=z12.discriminatedUnion("type",[binaryUseSchema.extend({source:definitionInputSourceSchema.default({type:"git"})}).strict(),websiteUseSchema.extend({source:websiteSourceSchema}).strict(),z12.object({type:z12.literal("web-fixture"),source:definitionInputSourceSchema.default({type:"git"}),path:inputPathSchema.regex(/^[^*?{}[\]]+$/).describe("Explicit path to a version 1 web fixture JSON file.")}).strict(),z12.object({type:z12.literal("npm-package"),source:definitionInputSourceSchema.default({type:"git"}),path:inputPathSchema.describe("Path or glob selecting exactly one packed npm .tgz file."),install:z12.enum(["environment","workspace"]).default("environment").describe("environment exposes the package's commands on PATH; workspace adds a consumer application dependency.")}).strict(),z12.object({type:z12.literal("skill"),source:definitionInputSourceSchema.default({type:"git"}),path:skillInputPathSchema}).strict(),z12.object({type:z12.literal("files"),source:definitionInputSourceSchema.default({type:"git"}),paths:z12.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=z13.object({sha256:z13.string().regex(/^sha256:[a-f0-9]{64}$/),bytes:z13.number().int().positive().max(512*1024*1024)}).strict();var uncredentialedRepoUrlSchema=z13.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=z13.object({paths:z13.array(inputPathSchema).min(1).max(32)}).strict();var inlinePersonaSchema=z13.object({name:z13.string().trim().min(1).max(120),description:z13.string().trim().min(1).max(4e3)}).strict();var runDefinitionConfigSchema=z13.object({agents:z13.array(agentConfigInputSchema).min(1),sampleCount:z13.number().int().min(1).max(50).optional(),repoUrl:uncredentialedRepoUrlSchema.nullable().optional(),repoRef:z13.string().min(1).nullable().optional(),profileId:z13.string().min(1).nullable().optional(),persona:inlinePersonaSchema.optional(),skillRefs:assetRefListSchema.optional(),mcpRefs:assetRefListSchema.optional(),connectionIds:z13.array(z13.string().min(1)).max(32).optional(),addons:runAddonsSchema.optional(),inputs:z13.array(z13.string()).optional(),checks:runDefinitionChecksSchema.optional()}).strict().refine(config=>!(config.profileId&&config.persona),{message:"Use profileId or an inline persona, not both",path:["persona"]});var runDefinitionFileConfigSchema=z13.object({version:z13.literal(2).default(2),org:z13.string().min(1).optional(),orgId:z13.string().uuid().optional(),checks:runDefinitionChecksSchema.optional(),cases:z13.array(inputPathSchema).min(1).max(32).default(["gauge-cases/**/*.md"]),inputs:z13.record(z13.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=z13.object({name:z13.string().min(1),rubric:z13.string().min(1)}).strict();var caseMeasurement={criteria:z13.array(runDefinitionCriterionSchema).min(1).optional(),preference:preferenceDefinitionSchema.optional()};function exactlyOneMeasurement(item){return item.criteria!==void 0!==(item.preference!==void 0)}var runDefinitionFrontmatterSchema=z13.object({...caseMeasurement,config:runDefinitionConfigSchema}).strict().refine(exactlyOneMeasurement,"Specify exactly one of criteria or preference");var runDefinitionCaseSchema=z13.object({path:z13.string().min(1),prompt:z13.string().min(1),...caseMeasurement,config:runDefinitionConfigSchema}).strict().refine(exactlyOneMeasurement,"Specify exactly one of criteria or preference");var runDefinitionSubmissionSchema=z13.object({version:z13.literal(2),lifecycle:lifecycleSchema.nullish(),cliRules:cliRuleAuthorInputSchema.optional(),source:z13.object({repoUrl:uncredentialedRepoUrlSchema.nullable(),commit:z13.string().regex(/^[a-f0-9]{40}$/i).nullable(),digest:z13.string().regex(/^sha256:[a-f0-9]{64}$/),verification:z13.enum(["SUBMITTED_UNVERIFIED","GITHUB_VERIFIED","LOCAL"])}).strict(),resources:z13.array(runPlanResourceSchema).max(32).default([]),cases:z13.array(runDefinitionCaseSchema).min(1).max(20)}).strict().superRefine((definition,ctx)=>{if(definition.source.verification==="GITHUB_VERIFIED"&&definition.cliRules!==void 0)ctx.addIssue({code:"custom",path:["cliRules"],message:"GitHub definitions cannot contain launch-only CLI rules"});if(definition.source.verification==="GITHUB_VERIFIED"&&definition.lifecycle!==void 0)ctx.addIssue({code:"custom",path:["lifecycle"],message:"GitHub definitions cannot contain launch-only lifecycle scripts"});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=z13.object({cliRules:z13.object({ruleCount:z13.number().int().positive(),bundleSha256:z13.string().regex(/^[a-f0-9]{64}$/)}).optional(),source:runDefinitionSubmissionSchema.shape.source,lifecycle:z13.object({setupTimeoutSeconds:z13.number().int().min(1).max(600).optional(),teardownTimeoutSeconds:z13.number().int().min(1).max(600).optional()}).optional(),measurementMode:z13.enum(["AGENT_EXPERIENCE","AGENT_PREFERENCE","MIXED"]),cases:z13.array(z13.object({path:z13.string(),agents:z13.array(agentConfigSchema),samples:z13.number().int().nonnegative(),expectedRuns:z13.number().int().nonnegative(),workspace:z13.object({repoUrl:z13.string().nullable(),repoRef:z13.string().nullable()}),criteriaCount:z13.number().int().nonnegative(),preference:preferenceDefinitionSchema.optional(),inputs:z13.array(z13.string())})),resources:z13.array(z13.object({name:z13.string(),type:z13.literal("input"),source:z13.enum(["git","github-actions","github-deployment","github-pr-comment","upload"]),use:inputUseSchema,readiness:z13.enum(["READY","WAITING","FAILED"]),detail:z13.string().optional(),commands:z13.array(z13.string()).optional()})),expectedRuns:z13.number().int().nonnegative(),canRun:z13.boolean()});var runDefinitionRunResponseSchema=z13.object({runRequestId:z13.string(),batchIds:z13.array(z13.string()),runIds:z13.array(z13.string()),requestedRuns:z13.number().int().nonnegative(),createdRuns:z13.number().int().nonnegative(),aggregateUrl:z13.string()});import{z as z14}from"zod";var caseSpecSchema=z14.object({version:z14.literal(2),cases:z14.array(z14.object({key:z14.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64).describe("Unique case id, lowercase-kebab"),prompt:z14.string().trim().min(1).describe("The user's request"),criteria:z14.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=()=>z14.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:
1013
1030
  ${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{z as z15}from"zod";var experimentProductSchema=z15.object({repository:z15.string().regex(/^(?:https:\/\/github\.com\/)?[A-Za-z0-9_-]+\/[A-Za-z0-9_.-]+$/,"Use owner/repository or an HTTPS GitHub repository URL without credentials").refine(value=>![".",".."].includes(value.split("/").at(-1)??""),"Invalid repository name"),revision:z15.string().trim().min(1).max(255).regex(/^[^\s\x00-\x1f\x7f]+$/,"Use a commit SHA, branch, or tag")}).strict();var experimentInputsSchema=z15.record(z15.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});var experimentCaseSchema=z15.object({key:z15.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).max(64),prompt:z15.string().trim().min(1),criteria:z15.array(runDefinitionCriterionSchema).min(1).optional(),preference:preferenceDefinitionSchema.optional(),config:runDefinitionConfigSchema}).strict().refine(item=>Boolean(item.criteria)!==Boolean(item.preference),"Specify exactly one of criteria or preference");var experimentSchema=z15.object({version:z15.literal(2),product:experimentProductSchema,inputs:experimentInputsSchema,cases:z15.array(experimentCaseSchema).min(1).max(20)}).strict().superRefine((experiment,ctx)=>{const keys=new Set;for(const[index,item]of experiment.cases.entries()){if(keys.has(item.key))ctx.addIssue({code:"custom",path:["cases",index,"key"],message:"Case keys must be unique"});keys.add(item.key);for(const name of item.config.inputs??[]){if(!Object.hasOwn(experiment.inputs,name))ctx.addIssue({code:"custom",path:["cases",index,"config","inputs"],message:`Unknown input: ${name}`})}}});import{z as z16}from"zod";var EXPERIMENT_SCHEMA=()=>z16.toJSONSchema(experimentSchema,{io:"input"});var EXAMPLE_EXPERIMENT={version:2,product:{repository:"example/product",revision:"main"},inputs:{docs:{type:"files",paths:["docs/**"]}},cases:[{key:"first-request",prompt:"Use the supplied documentation to write a minimal API client.",criteria:[{name:"Working example",rubric:"The client follows the documented API contract."}],config:{agents:[{agent:"CODEX_CLI"}],inputs:["docs"]}}]};function isExperimentSpec(value){return value!==null&&typeof value==="object"&&("product"in value||"inputs"in value)}function parseExperimentSpec(value){const result=experimentSchema.safeParse(value);if(!result.success)throw new CliError("usage",`Not a valid experiment specification: ${result.error.message}`,{hint:"Use gauge run --example --format experiment for a self-contained example."});return result.data}async function loadExperiment(command,experiment,options){const org=await resolveOrg(command);const client=createClient();const response=await client.post(`/api/v1/orgs/${encodeURIComponent(org)}/run-definitions/resolve`,experiment);const resolved=z16.object({experiment:experimentSchema,definition:runDefinitionPublicSubmissionSchema}).parse(response);if(!/^[a-f0-9]{40}$/.test(resolved.experiment.product.revision)||resolved.definition.source.commit!==resolved.experiment.product.revision)throw new CliError("internal","Gauge did not return an immutable product revision");if(!options.dryRun){console.error(`Product: ${resolved.experiment.product.repository} @ ${resolved.experiment.product.revision}`);await confirmOrAbort("Run this experiment now?",options.yes)}return{definition:resolved.definition,org,experiment:resolved.experiment,inputSnapshots:[],unattachedInputs:Object.keys(experiment.inputs).filter(name=>!experiment.cases.some(item=>item.config.inputs===void 0||item.config.inputs.includes(name)))}}import{writeFileSync as writeFileSync4}from"fs";function runPath(id2){return`/api/v1/runs/${encodeURIComponent(id2)}`}function parseSeq(raw){const seq=parsePositiveSeq(raw);if(seq===null)throw new CliError("usage",`--before takes a seq, e.g. 34 (got ${raw})`);return seq}function forkBody(opts,read2=readText){if(opts.page){if(opts.before!==void 0||opts.message!==void 0)throw new CliError("usage","--page picks its own fork point; drop --before and --message");if(!opts.edits===!opts.from)throw new CliError("usage","--page needs --edits <file> or --from <file>");if(opts.contentType&&!opts.from)throw new CliError("usage","--content-type only applies with --from");return opts.edits?{kind:"mock_page",url:opts.page,edits:parseEdits(readJson2(opts.edits,read2))}:{kind:"mock_page",url:opts.page,body:read2(opts.from),...opts.contentType?{contentType:opts.contentType}:{}}}if(opts.edits||opts.from||opts.contentType)throw new CliError("usage","--edits, --from and --content-type need --page");if(!opts.before)throw new CliError("usage","pass --before <seq>, or --page <url> with --edits or --from");const beforeSeq=parseSeq(opts.before);if(opts.message===void 0)return{kind:"run_again",beforeSeq};if(!opts.message.trim())throw new CliError("usage","--message is empty");return{kind:"new_message",beforeSeq,message:opts.message}}function printFork(res){console.log(`Forked ${res.sourceRunId} before seq ${res.forkedBefore}: new run ${res.runId}`);if(res.change){const{linesBefore,linesAfter,retainedPercent,hunks}=res.change;console.log(`Mock ${res.mockId}: ${linesBefore} \u2192 ${linesAfter} lines, ${retainedPercent??"\u2014"}% of the original kept`);console.log(hunks)}console.log(`Follow with \`gauge run watch ${res.runId}\`.`)}function registerRunFork(run){hostedOnly(run.command("fork <runId>")).description("Start a new run that repeats a recorded run's steps up to a point, then continues live. Nothing else changes, unless you send a different persona message or mock a page the run read").option("--before <seq>","the first event that can change; the fork repeats every step before it").option("--message <text>","with --before at a persona message: send this message in its place").option("--page <url>","mock a page the run read; the fork starts at the last tool call before the run first read it").option("--edits <file>","with --page: JSON [{find, replace}] on the page's exact source; copy find text from `gauge run page --query`; '-' for stdin").option("--from <file>","with --page: the complete new page; '-' for stdin").option("--content-type <type>","with --from: the page content type (default: keep)").addHelpText("after",`
1014
1031
  Examples:
1015
1032
  gauge run fork <runId> --before 34
@@ -1022,14 +1039,14 @@ Find seqs with \`gauge run trace <runId> --seq <n>\` and the pages a run read wi
1022
1039
  ${compact(analysis.limitation,200)}`);console.log(`
1023
1040
  Findings (${analysis.observations.length})`);for(const finding of analysis.observations){console.log(` ${finding.kind}: ${finding.label}`);console.log(` id ${finding.id}${finding.issueId?`, issue ${finding.issueId}`:""}`);console.log(` ${finding.detail}`);console.log(` Evidence: ${JSON.stringify(finding.evidence)}`)}if(recorded&&analysis.observations.length)console.log(`
1024
1041
  Test one fix on this session: gauge run fork ${insight.runId} --page <url> --edits <file>, or --before <seq> --message <text>. Pages it read: gauge run web ${insight.runId}.`);console.log(`
1025
- 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(id2,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(runPath2(id2)).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(id2),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,cliRules){const lifecycle=opts.prompt!==void 0?lifecyclePatchFromOpts(opts):{};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,...lifecycle,...cliRules?{cliRules}:{}},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}`);if(result.cliRules)console.log(`CLI rules: ${result.cliRules.ruleCount} (this launch only; sha256:${result.cliRules.bundleSha256})`);if(result.lifecycle?.setupTimeoutSeconds!==void 0)console.log(`Setup hook: ${result.lifecycle.setupTimeoutSeconds}s deadline`);if(result.lifecycle?.teardownTimeoutSeconds!==void 0)console.log(`Teardown hook: ${result.lifecycle.teardownTimeoutSeconds}s deadline`);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))}function callerAgent(){const caller=detectSkillAgent(process.env);return caller==="codex"||caller==="opencode"?caller:"claude-code"}function promptSpec(prompt,agents){return parseCaseSpec({version:2,cases:[{key:"prompt",prompt,preference:{kind:"open-ended"},config:{agents:buildAgentRoster(agents)}}]})}async function launch(cmd,opts){if(opts.cliRules!==void 0){if(gaugeState(cmd).mode!=="hosted")throw new CliError("usage","--cli-rules requires hosted Gauge; pass --hosted.");if(opts.schema||opts.example||opts.verify)throw new CliError("usage","--cli-rules applies to a launch or --dry-run, not --schema, --example, or --verify.")}const cliRules=opts.cliRules===void 0?void 0:readCliRules(opts.cliRules);if(opts.profile&&gaugeState(cmd).mode!=="local")throw new CliError("usage","--profile applies only to local runs. Pass --local.");const sources=[opts.prompt!==void 0&&"a prompt",opts.eval!==void 0&&"--eval",opts.preference!==void 0&&"--preference",opts.apply!==void 0&&"--apply"].filter(flag2=>Boolean(flag2));const source2=sources[0];if(hasLifecycleFlags(opts)){if(gaugeState(cmd).mode!=="hosted")throw new CliError("usage","Lifecycle hooks require hosted Gauge; pass --hosted.");if(source2!=="a prompt"&&source2!=="--eval"&&source2!=="--preference"||opts.apply!==void 0||opts.schema||opts.example||opts.verify||opts.dryRun&&source2!=="a prompt")throw new CliError("usage","Lifecycle flags apply only to a hosted prompt, --eval, or --preference launch; they do not apply to case files or --apply. Only prompt launches support --dry-run with hooks.")}if(opts.schema||opts.example){const flag2=opts.schema?"--schema":"--example";if(source2||opts.schema&&opts.example)throw new CliError("usage",`${flag2} prints and exits; pass it alone`);if(opts.format==="experiment"){printJson(opts.schema?EXPERIMENT_SCHEMA():EXAMPLE_EXPERIMENT);if(opts.example)console.error("Save as experiment.json, edit the product and cases, then preview: gauge run --hosted --apply experiment.json --dry-run");return}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=[source2,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&&source2!=="--preference")throw new CliError("usage","--scenario applies with --preference only");if(source2==="a prompt"){if(opts.samples!==void 0||opts.input.length>0)throw new CliError("usage","--samples and --input do not apply to prompt runs; use `gauge preference` or `gauge eval` for more settings")}else if((opts.agent.length>0||opts.samples!==void 0)&&source2!=="--eval"&&source2!=="--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&&source2)throw new CliError("usage",`--files applies to this repo's eval cases; drop ${source2}`);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;let experiment;if(opts.apply!==void 0){const json=await readSpecJson(opts.apply);if(isExperimentSpec(json)){experiment=parseExperimentSpec(json);if(gaugeState(cmd).mode!=="hosted")throw new CliError("usage","Self-contained product experiments require --hosted; remote inputs are prepared by Gauge.");if(opts.input.length||opts.cliRules||opts.requireExperiment)throw new CliError("usage","A self-contained experiment takes its inputs and cases only from the specification; --input, --cli-rules, and --require-experiment are unavailable.")}else if(!isCaseSpec(json)){if(cliRules)throw new CliError("usage","--cli-rules does not apply to battery specs; use a case spec, prompt, --eval, or --preference.");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");const result2=await applySpec(cmd,parseSpec(json),{dryRun:opts.dryRun,requireExperiment:opts.requireExperiment});if(!opts.dryRun&&"runIds"in result2&&result2.runIds.length>0)console.error(RUN_PRESENTATION_REMINDER);return}if(!experiment&&opts.requireExperiment!==void 0)throw new CliError("usage","--require-experiment applies to battery specs, not case specs");if(!experiment)spec=parseCaseSpec(json)}if(opts.prompt!==void 0)spec=promptSpec(opts.prompt,opts.agent.length>0?opts.agent:[callerAgent()]);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&&source2&&!spec&&!experiment)throw new CliError("usage",`--dry-run previews this repo's eval cases or an --apply spec; drop ${source2}`);if(opts.eval!==void 0||opts.preference!==void 0)requireHosted(cmd);if(opts.eval!==void 0){const result2=await runEvalSet(cmd,opts.eval,{...opts,cliRules});if(result2.runIds.length>0||result2.runRequestId)console.error(RUN_PRESENTATION_REMINDER);return}if(opts.preference!==void 0){const result2=await runPreferencePrompt(cmd,opts.preference,{...opts,cliRules});if(result2.runIds.length>0)console.error(RUN_PRESENTATION_REMINDER);return}if(gaugeState(cmd).mode==="local"){await runLocalCases(cmd,opts,spec);return}const loaded=experiment?await loadExperiment(cmd,experiment,opts):await loadWorkingTree(cmd,opts,!opts.dryRun,spec,cliRules);const{definition,org,inputSnapshots,unattachedInputs}=loaded;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,...loaded.experiment?{experiment:loaded.experiment}:{}};if(resolveOutput(cmd)==="json")printJson(preview);else{if(loaded.experiment)console.log(`Product: ${loaded.experiment.product.repository} @ ${loaded.experiment.product.revision}
1026
- Inputs are declared; a preview does not prepare their bytes. Use -o json to save the pinned experiment for launch.`);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}`)}if(result.requestedRuns>0)console.error(RUN_PRESENTATION_REMINDER)}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,join11(root,".gauge"),{profile:opts.profile,runtimeImage:opts.runtimeImage,gatewayImage:opts.gatewayImage,measurement});if(json)printJson(detached);else console.log(`Batch ${detached.batchId} detached.
1042
+ 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(id2,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(runPath2(id2)).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(id2),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,cliRules){const lifecycle=opts.prompt!==void 0?lifecyclePatchFromOpts(opts):{};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,...lifecycle,...cliRules?{cliRules}:{}},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}`);if(result.cliRules)console.log(`CLI rules: ${result.cliRules.ruleCount} (this launch only; sha256:${result.cliRules.bundleSha256})`);if(result.lifecycle?.setupTimeoutSeconds!==void 0)console.log(`Setup hook: ${result.lifecycle.setupTimeoutSeconds}s deadline`);if(result.lifecycle?.teardownTimeoutSeconds!==void 0)console.log(`Teardown hook: ${result.lifecycle.teardownTimeoutSeconds}s deadline`);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))}function callerAgent(){const caller=detectSkillAgent(process.env);return caller==="codex"||caller==="opencode"?caller:"claude-code"}function promptSpec(prompt,agents){return parseCaseSpec({version:2,cases:[{key:"prompt",prompt,preference:{kind:"open-ended"},config:{agents:buildAgentRoster(agents)}}]})}async function launch(cmd,opts){if(opts.cliRules!==void 0){if(gaugeState(cmd).mode!=="hosted")throw new CliError("usage","--cli-rules requires hosted Gauge; pass --hosted.");if(opts.schema||opts.example||opts.verify)throw new CliError("usage","--cli-rules applies to a launch or --dry-run, not --schema, --example, or --verify.")}const cliRules=opts.cliRules===void 0?void 0:readCliRules(opts.cliRules);if(opts.profile&&gaugeState(cmd).mode!=="local")throw new CliError("usage","--profile applies only to local runs. Pass --local.");const sources=[opts.prompt!==void 0&&"a prompt",opts.eval!==void 0&&"--eval",opts.preference!==void 0&&"--preference",opts.apply!==void 0&&"--apply"].filter(flag2=>Boolean(flag2));const source2=sources[0];if(hasLifecycleFlags(opts)){if(gaugeState(cmd).mode!=="hosted")throw new CliError("usage","Lifecycle hooks require hosted Gauge; pass --hosted.");if(source2!=="a prompt"&&source2!=="--eval"&&source2!=="--preference"||opts.apply!==void 0||opts.schema||opts.example||opts.verify||opts.dryRun&&source2!=="a prompt")throw new CliError("usage","Lifecycle flags apply only to a hosted prompt, --eval, or --preference launch; they do not apply to case files or --apply. Only prompt launches support --dry-run with hooks.")}if(opts.schema||opts.example){const flag2=opts.schema?"--schema":"--example";if(source2||opts.schema&&opts.example)throw new CliError("usage",`${flag2} prints and exits; pass it alone`);if(opts.format==="experiment"){printJson(opts.schema?EXPERIMENT_SCHEMA():EXAMPLE_EXPERIMENT);if(opts.example)console.error("Save as experiment.json, edit the product and cases, then preview: gauge run --hosted --apply experiment.json --dry-run");return}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=[source2,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&&source2!=="--preference")throw new CliError("usage","--scenario applies with --preference only");if(source2==="a prompt"){if(opts.samples!==void 0||opts.input.length>0)throw new CliError("usage","--samples and --input do not apply to prompt runs; use `gauge preference` or `gauge eval` for more settings")}else if((opts.agent.length>0||opts.samples!==void 0)&&source2!=="--eval"&&source2!=="--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&&source2)throw new CliError("usage",`--files applies to this repo's eval cases; drop ${source2}`);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;let experiment;if(opts.apply!==void 0){const json=await readSpecJson(opts.apply);if(isExperimentSpec(json)){experiment=parseExperimentSpec(json);if(gaugeState(cmd).mode!=="hosted")throw new CliError("usage","Self-contained product experiments require --hosted; remote inputs are prepared by Gauge.");if(opts.input.length||opts.cliRules||opts.requireExperiment)throw new CliError("usage","A self-contained experiment takes its inputs and cases only from the specification; --input, --cli-rules, and --require-experiment are unavailable.")}else if(!isCaseSpec(json)){if(cliRules)throw new CliError("usage","--cli-rules does not apply to battery specs; use a case spec, prompt, --eval, or --preference.");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");const result2=await applySpec(cmd,parseSpec(json),{dryRun:opts.dryRun,requireExperiment:opts.requireExperiment});if(!opts.dryRun&&"runIds"in result2&&result2.runIds.length>0)console.error(RUN_PRESENTATION_REMINDER);return}if(!experiment&&opts.requireExperiment!==void 0)throw new CliError("usage","--require-experiment applies to battery specs, not case specs");if(!experiment)spec=parseCaseSpec(json)}if(opts.prompt!==void 0)spec=promptSpec(opts.prompt,opts.agent.length>0?opts.agent:[callerAgent()]);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&&source2&&!spec&&!experiment)throw new CliError("usage",`--dry-run previews this repo's eval cases or an --apply spec; drop ${source2}`);if(opts.eval!==void 0||opts.preference!==void 0)requireHosted(cmd);if(opts.eval!==void 0){const result2=await runEvalSet(cmd,opts.eval,{...opts,cliRules});if(result2.runIds.length>0||result2.runRequestId)console.error(RUN_PRESENTATION_REMINDER);return}if(opts.preference!==void 0){const result2=await runPreferencePrompt(cmd,opts.preference,{...opts,cliRules});if(result2.runIds.length>0)console.error(RUN_PRESENTATION_REMINDER);return}if(gaugeState(cmd).mode==="local"){await runLocalCases(cmd,opts,spec);return}const loaded=experiment?await loadExperiment(cmd,experiment,opts):await loadWorkingTree(cmd,opts,!opts.dryRun,spec,cliRules);const{definition,org,inputSnapshots,unattachedInputs}=loaded;const orgPath2=`/api/v1/orgs/${encodeURIComponent(org)}/run-definitions`;if(opts.dryRun){const result2=await createClient().post(`${orgPath2}/plan`,definition);const preview={...result2,inputSnapshots,unattachedInputs,...loaded.experiment?{experiment:loaded.experiment}:{}};if(resolveOutput(cmd)==="json")printJson(preview);else{if(loaded.experiment)console.log(`Product: ${loaded.experiment.product.repository} @ ${loaded.experiment.product.revision}
1043
+ Inputs are declared; a preview does not prepare their bytes. Use -o json to save the pinned experiment for launch.`);printPlan2(preview)}return}const result=await createClient().post(`${orgPath2}/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}`)}if(result.requestedRuns>0)console.error(RUN_PRESENTATION_REMINDER)}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,join11(root,".gauge"),{profile:opts.profile,runtimeImage:opts.runtimeImage,gatewayImage:opts.gatewayImage,measurement});if(json)printJson(detached);else console.log(`Batch ${detached.batchId} detached.
1027
1044
  Status: ${detached.status}
1028
1045
  Wait: ${detached.wait}
1029
1046
  Stop: ${detached.stop}`);console.error(RUN_PRESENTATION_REMINDER)}finally{await local.cleanup()}return}let batch;try{batch=await runLocal(local.definition,local.uploads,join11(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}
1030
1047
  Status: gauge run status --batch ${batchId} --local
1031
1048
  Wait: gauge run wait --batch ${batchId} --local
1032
- Stop: gauge run cancel --batch ${batchId} --local`);console.error(RUN_PRESENTATION_REMINDER)}})}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,id2){return`/api/v1/orgs/${encodeURIComponent(await resolveOrg(cmd))}/run-requests/${encodeURIComponent(id2)}`}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,id2,opts){const path=await runRequestPath(cmd,id2);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 ${id2}: ${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=["completed","canceled","failed","interrupted"].includes(batch.state);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.lastKnownState?` (last known: ${batch.lastKnownState})`:""}; ${batch.finishedSessions??0}/${batch.expectedSessions} finished`);for(const run of runs){console.log(`${run.id}: ${run.state}${"lastKnownState"in run&&run.lastKnownState?` (last known: ${run.lastKnownState})`:""}${run.cleanupPending?" (cleanup pending)":""}${run.detail?` (${run.detail})`:""}`);if(run.stderrLog)console.log(` agent stderr: ${relative5(process.cwd(),run.stderrLog)}`)}}function register29(program2){const run=addLifecycleEditOptions(program2.command("run")).description('Start runs and read them. `gauge run "<prompt>"` runs one open-ended preference prompt and saves no measurement. With no flag: run this repo\'s eval cases (gauge-cases/) (local: in local Docker). Lifecycle flags attach hooks to hosted prompts or override saved --eval/--preference hooks for this launch only.').argument("[prompt]").usage('[options] ["<prompt>"]').option("--cli-rules <file>","JSON CLI rules for this hosted launch only (schema v3/v4)",once("--cli-rules")).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 a prompt or --eval/--preference: run these agents and model pins for this launch only (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): cases, a self-contained product experiment (hosted), or a battery. See --example --format experiment').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 a prompt, 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 Option5("--format <format>","schema/example format (default: case)").choices(["case","battery","experiment"])).option("--yes","skip the confirmation").action(async(arg2,opts,cmd)=>{if(arg2!==void 0&&!/\s/.test(arg2.trim()))throw new CliError("usage",`unknown run command "${arg2}". Run a prompt with \`gauge run "<prompt>"\`. 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,prompt:arg2?.trim()})});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(join11(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(id2,opts,command)=>{if(gaugeState(command).mode==="local"){const dir=localDirectory2(command);const session=withLocalStore(command,store=>store.getSession(id2));if(!session)throw new CliError("usage",`Local run ${id2} 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=join11(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(readFileSync13(path,"utf8"))}else printJson({...session,analysis:getLocalAnalysis(dir,id2)});return}if(opts.logs){await streamRun(id2,resolveOutput(command)==="json",{idleMs:2e3,firstEventMs:15e3,stopAtLiveMs:Date.now()-2e3});return}const run2=await createClient().get(runPath2(id2));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(id2,_opts,command)=>{if(gaugeState(command).mode==="local"){const dir=localDirectory2(command);if(!withLocalStore(command,store=>store.getSession(id2)))throw new CliError("usage",`Local run ${id2} was not found.`);const analysis2=getLocalAnalysis(dir,id2);if(resolveOutput(command)==="json")printJson({runId:id2,analysis:analysis2});else console.log(analysis2?renderLocalAnalysisMarkdown(analysis2):"No analysis published. Follow gauge instructions session-analysis --local.");return}const client=createClient();if(resolveOutput(command)==="json"){printJson(await client.get(`${runPath2(id2)}/insight`));return}const[insight,run2]=await Promise.all([client.get(`${runPath2(id2)}/insight`),client.get(runPath2(id2)).catch(()=>null)]);printInsight(insight,run2?.recorded===true)});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(z17.toJSONSchema(analysisSubmissionSchema)));analysis.command("save <id>").description("Validate and publish analysis for a local session attempt").requiredOption("--file <path>","analysis JSON file").action((id2,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(readFileSync13(opts.file,"utf8"))}catch(error){throw new CliError("usage",`Cannot read analysis JSON: ${String(error)}`)}const dir=localDirectory2(command);const saved=saveLocalAnalysis(dir,id2,input);const results=join11(dir,"runs",saved.runId,"results");try{mkdirSync2(results,{recursive:true});writeFileSync5(join11(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 ${id2} --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 ${id2} --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(id2,_opts,command)=>{const result=await createClient().post(`${runPath2(id2)}/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.")});registerRunFork(run);hostedOnly(run.command("watch <id>")).description("Stream normalized trace events live (SSE; exits when the run finishes)").action(async(id2,_opts,command)=>{await streamRun(id2,resolveOutput(command)==="json",{idleMs:0,firstEventMs:0,pollStatus:true})});hostedOnly(run.command("trace <id>")).description("A window of the run's trace around a seq, one line per event: web fetches, tool calls, results, and messages").requiredOption("--seq <n>","the seq at the center, e.g. a finding's evidence seq").option("--before <n>","events before the seq (default 30)").option("--after <n>","events after the seq (default 10)").action(async(id2,opts,command)=>{const res=await createClient().get(`${runPath2(id2)}/trace`,{seq:opts.seq,before:opts.before,after:opts.after});if(resolveOutput(command)==="json")printJson(res);else for(const line of res.lines)console.log(line)});hostedOnly(run.command("web <id>")).description("Every URL the run's agent fetched, with the seqs, and its searches").action(async(id2,_opts,command)=>{const res=await createClient().get(`${runPath2(id2)}/web`);if(resolveOutput(command)==="json")return printJson(res);for(const page of res.pages)console.log(`${page.seqs.join(",")} ${page.url}`);for(const search of res.searches)console.log(`${search.seq} search: ${search.query}`);if(!res.pages.length&&!res.searches.length)console.log("No web activity recorded.")});hostedOnly(run.command("commands <id>")).description("Shell commands the run's agent executed: without --seq, commands matching --query with their first output; with --seq, that call's full output").option("--query <text>","only commands whose text contains this").option("--seq <n>","one call from the listing").option("--offset <n>","page into a long output").action(async(id2,opts)=>{printJson(await createClient().get(`${runPath2(id2)}/commands`,{query:opts.query,seq:opts.seq,offset:opts.offset}))});run.command("diff <id>").description("Print the run's working-tree diff to stdout").action(async(id2,_opts,command)=>{if(gaugeState(command).mode==="local"){const session=withLocalStore(command,store=>store.getSession(id2));if(!session)throw new CliError("usage",`Local run ${id2} was not found.`);const path=join11(localDirectory2(command),"runs",session.id,"attempts",String(session.attempt),"session","diff.patch");if(existsSync4(path))process.stdout.write(readFileSync13(path,"utf8"));else console.error("(no diff)");return}const diff2=await createClient().get(`${runPath2(id2)}/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(id2,opts,command)=>{const state=gaugeState(command);if(state.mode!=="local"){if(!id2||opts.batch)throw new CliError("usage","Hosted status requires a request ID; --batch is local only");const result=await createClient().get(await runRequestPath(command,id2));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(id2&&opts.batch)throw new CliError("usage","Pass a run ID or --batch, not both");const gaugeDir=join11(state.root,".gauge");const runs=await localStatus(gaugeDir,{id:id2,batch:opts.batch});let batch;if(opts.batch){try{batch=await localBatchStatus(gaugeDir,opts.batch)}catch(error){if(error.code!=="ENOENT")throw error}}if((id2||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(id2,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(join11(state.root,".gauge"),{id:id2,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??id2}.`);for(const result2 of results)console.log(`${result2.id}: ${result2.status}${"detail"in result2?` (${result2.detail})`:""}`)}return}if(!id2||opts.batch)throw new CliError("usage","Hosted cancellation requires a run ID; --batch is local only");const result=await createClient().post(`${runPath2(id2)}/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",`
1049
+ Stop: gauge run cancel --batch ${batchId} --local`);console.error(RUN_PRESENTATION_REMINDER)}})}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,id2){return`/api/v1/orgs/${encodeURIComponent(await resolveOrg(cmd))}/run-requests/${encodeURIComponent(id2)}`}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,id2,opts){const path=await runRequestPath(cmd,id2);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 ${id2}: ${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=["completed","canceled","failed","interrupted"].includes(batch.state);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.lastKnownState?` (last known: ${batch.lastKnownState})`:""}; ${batch.finishedSessions??0}/${batch.expectedSessions} finished`);for(const run of runs){console.log(`${run.id}: ${run.state}${"lastKnownState"in run&&run.lastKnownState?` (last known: ${run.lastKnownState})`:""}${run.cleanupPending?" (cleanup pending)":""}${run.detail?` (${run.detail})`:""}`);if(run.stderrLog)console.log(` agent stderr: ${relative5(process.cwd(),run.stderrLog)}`)}}function register29(program2){const run=addLifecycleEditOptions(program2.command("run")).description('Start runs and read them. `gauge run "<prompt>"` runs one open-ended preference prompt and saves no measurement. With no flag: run this repo\'s eval cases (gauge-cases/) (local: in local Docker). Lifecycle flags attach hooks to hosted prompts or override saved --eval/--preference hooks for this launch only.').argument("[prompt]").usage('[options] ["<prompt>"]').option("--cli-rules <file>","JSON CLI rules for this hosted launch only (schema v3/v4)",once("--cli-rules")).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 a prompt or --eval/--preference: run these agents and model pins for this launch only (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): cases, a self-contained product experiment (hosted), or a battery. See --example --format experiment').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 a prompt, 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 Option6("--format <format>","schema/example format (default: case)").choices(["case","battery","experiment"])).option("--yes","skip the confirmation").action(async(arg2,opts,cmd)=>{if(arg2!==void 0&&!/\s/.test(arg2.trim()))throw new CliError("usage",`unknown run command "${arg2}". Run a prompt with \`gauge run "<prompt>"\`. 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,prompt:arg2?.trim()})});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(join11(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(id2,opts,command)=>{if(gaugeState(command).mode==="local"){const dir=localDirectory2(command);const session=withLocalStore(command,store=>store.getSession(id2));if(!session)throw new CliError("usage",`Local run ${id2} 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=join11(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(readFileSync13(path,"utf8"))}else printJson({...session,analysis:getLocalAnalysis(dir,id2)});return}if(opts.logs){await streamRun(id2,resolveOutput(command)==="json",{idleMs:2e3,firstEventMs:15e3,stopAtLiveMs:Date.now()-2e3});return}const run2=await createClient().get(runPath2(id2));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(id2,_opts,command)=>{if(gaugeState(command).mode==="local"){const dir=localDirectory2(command);if(!withLocalStore(command,store=>store.getSession(id2)))throw new CliError("usage",`Local run ${id2} was not found.`);const analysis2=getLocalAnalysis(dir,id2);if(resolveOutput(command)==="json")printJson({runId:id2,analysis:analysis2});else console.log(analysis2?renderLocalAnalysisMarkdown(analysis2):"No analysis published. Follow gauge instructions session-analysis --local.");return}const client=createClient();if(resolveOutput(command)==="json"){printJson(await client.get(`${runPath2(id2)}/insight`));return}const[insight,run2]=await Promise.all([client.get(`${runPath2(id2)}/insight`),client.get(runPath2(id2)).catch(()=>null)]);printInsight(insight,run2?.recorded===true)});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(z17.toJSONSchema(analysisSubmissionSchema)));analysis.command("save <id>").description("Validate and publish analysis for a local session attempt").requiredOption("--file <path>","analysis JSON file").action((id2,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(readFileSync13(opts.file,"utf8"))}catch(error){throw new CliError("usage",`Cannot read analysis JSON: ${String(error)}`)}const dir=localDirectory2(command);const saved=saveLocalAnalysis(dir,id2,input);const results=join11(dir,"runs",saved.runId,"results");try{mkdirSync2(results,{recursive:true});writeFileSync5(join11(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 ${id2} --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 ${id2} --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(id2,_opts,command)=>{const result=await createClient().post(`${runPath2(id2)}/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.")});registerRunFork(run);hostedOnly(run.command("watch <id>")).description("Stream normalized trace events live (SSE; exits when the run finishes)").action(async(id2,_opts,command)=>{await streamRun(id2,resolveOutput(command)==="json",{idleMs:0,firstEventMs:0,pollStatus:true})});hostedOnly(run.command("trace <id>")).description("A window of the run's trace around a seq, one line per event: web fetches, tool calls, results, and messages").requiredOption("--seq <n>","the seq at the center, e.g. a finding's evidence seq").option("--before <n>","events before the seq (default 30)").option("--after <n>","events after the seq (default 10)").action(async(id2,opts,command)=>{const res=await createClient().get(`${runPath2(id2)}/trace`,{seq:opts.seq,before:opts.before,after:opts.after});if(resolveOutput(command)==="json")printJson(res);else for(const line of res.lines)console.log(line)});hostedOnly(run.command("web <id>")).description("Every URL the run's agent fetched, with the seqs, and its searches").action(async(id2,_opts,command)=>{const res=await createClient().get(`${runPath2(id2)}/web`);if(resolveOutput(command)==="json")return printJson(res);for(const page of res.pages)console.log(`${page.seqs.join(",")} ${page.url}`);for(const search of res.searches)console.log(`${search.seq} search: ${search.query}`);if(!res.pages.length&&!res.searches.length)console.log("No web activity recorded.")});hostedOnly(run.command("commands <id>")).description("Shell commands the run's agent executed: without --seq, commands matching --query with their first output; with --seq, that call's full output").option("--query <text>","only commands whose text contains this").option("--seq <n>","one call from the listing").option("--offset <n>","page into a long output").action(async(id2,opts)=>{printJson(await createClient().get(`${runPath2(id2)}/commands`,{query:opts.query,seq:opts.seq,offset:opts.offset}))});run.command("diff <id>").description("Print the run's working-tree diff to stdout").action(async(id2,_opts,command)=>{if(gaugeState(command).mode==="local"){const session=withLocalStore(command,store=>store.getSession(id2));if(!session)throw new CliError("usage",`Local run ${id2} was not found.`);const path=join11(localDirectory2(command),"runs",session.id,"attempts",String(session.attempt),"session","diff.patch");if(existsSync4(path))process.stdout.write(readFileSync13(path,"utf8"));else console.error("(no diff)");return}const diff2=await createClient().get(`${runPath2(id2)}/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(id2,opts,command)=>{const state=gaugeState(command);if(state.mode!=="local"){if(!id2||opts.batch)throw new CliError("usage","Hosted status requires a request ID; --batch is local only");const result=await createClient().get(await runRequestPath(command,id2));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(id2&&opts.batch)throw new CliError("usage","Pass a run ID or --batch, not both");const gaugeDir=join11(state.root,".gauge");const runs=await localStatus(gaugeDir,{id:id2,batch:opts.batch});let batch;if(opts.batch){try{batch=await localBatchStatus(gaugeDir,opts.batch)}catch(error){if(error.code!=="ENOENT")throw error}}if((id2||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(id2,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(join11(state.root,".gauge"),{id:id2,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??id2}.`);for(const result2 of results)console.log(`${result2.id}: ${result2.status}${"detail"in result2?` (${result2.detail})`:""}`)}return}if(!id2||opts.batch)throw new CliError("usage","Hosted cancellation requires a run ID; --batch is local only");const result=await createClient().post(`${runPath2(id2)}/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",`
1033
1050
  ${style("1")(" EXAMPLES")}
1034
1051
  gauge run compare --baseline request=<id> --candidate request=<id>
1035
1052
  gauge run compare --baseline eval=<id> --candidate trial=<trialId>
@@ -1037,4 +1054,4 @@ ${style("1")(" EXAMPLES")}
1037
1054
  --candidate eval=<id> --candidate since=2h
1038
1055
  gauge run compare --local --baseline batch=<id> --candidate batch=<id>`).action(async(opts,cmd)=>{const body2={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",body2.baseline);const candidate=localCompareFilter("--candidate",body2.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=join11(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`,body2);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(id2,opts,cmd)=>{const state=gaugeState(cmd);if(state.mode==="local"){if(!opts.batch||id2)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,join11(state.root,".gauge"),opts.batch,opts)}if(!id2||opts.batch)throw new CliError("usage","Hosted wait requires a request ID; --batch is local only");return waitForRequest(cmd,id2,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 body2={};if(opts.rename!==void 0)body2.name=opts.rename;if(opts.clearNote)body2.note=null;else if(opts.note!==void 0)body2.note=opts.note;if(opts.clearSource)body2.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")');body2.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");body2.source={repoFullName:current.repoFullName,ref:current.ref,subpath:current.subpath||void 0,autoIngest}}if(Object.keys(body2).length===0)throw new CliError("usage","nothing to change");return body2}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 body2=await buildSkillEditBody(opts,async()=>{const skill=await client.get(skillPath(org,ref));return skill.source});const updated=await client.patch(skillPath(org,ref),body2);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 pct3=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%":pct3(r.installRate),"mention%":pct3(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:pct3(r.rate)});var brandRow=r=>({brand:r.brandName,kind:r.kind,installs:r.installs,rate:pct3(r.rate)});var funnelRow=r=>({brand:r.brandName,kind:r.kind,"mention%":pct3(r.mentionRate),"install%":pct3(r.installRate)});var domainRow=r=>({domain:r.domain,brand:r.brandName,runs:r.runs,rate:pct3(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 pct4(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: Agent Preference and 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}: ${pct4(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 ${pct4(card.owned.chosenRate)}${delta2(card.chosenDeltaPP)}`:"no owned brand ranked";console.log(` ${card.name}: ${owned}`)}}})}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}.
1039
1056
  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})
1040
- `)}})}var watch_exports={};__export(watch_exports,{ensureWatchServer:()=>ensureWatchServer,register:()=>register37,stopWatchServer:()=>stopWatchServer});import{spawn as spawn3}from"child_process";import{existsSync as existsSync5}from"fs";import{mkdir,open,readFile,rm as rm2,writeFile}from"fs/promises";import{join as join12}from"path";import{setTimeout as delay3}from"timers/promises";import{fileURLToPath}from"url";function alive(pid){if(!Number.isSafeInteger(pid)||pid<=0)return false;try{process.kill(pid,0);return true}catch(error){return error.code==="EPERM"}}var readWatchState=gaugeDir=>readJson(join12(gaugeDir,"watch.json"));async function health(state){try{const res=await fetch(`${state.url}/api/health`,{signal:AbortSignal.timeout(5e3)});return await res.json()}catch(error){return error.name==="TimeoutError"?"busy":void 0}}async function ours(state,gaugeDir){if(!alive(state.pid))return void 0;const body2=await health(state);if(body2==="busy")return{};return body2?.gauge==="watch"&&body2.gaugeDir===gaugeDir?body2:void 0}async function withWatchLock(gaugeDir,fn){await mkdir(gaugeDir,{recursive:true});const path=join12(gaugeDir,"watch.lock");const deadline=Date.now()+3e4;while(true){try{await writeFile(path,String(process.pid),{flag:"wx",mode:384});break}catch(error){if(error.code!=="EEXIST")throw error;const holder=Number(await readFile(path,"utf8").catch(()=>""));if(holder&&!alive(holder))await rm2(path,{force:true});else if(Date.now()>=deadline)throw new CliError("internal",`Timed out waiting for ${path}. Remove it if no gauge watch is running.`);else await delay3(50)}}try{return await fn()}finally{await rm2(path,{force:true})}}async function stopLocked(gaugeDir){const state=await readWatchState(gaugeDir);if(!state)return false;const running=Boolean(await ours(state,gaugeDir));if(running){process.kill(state.pid,"SIGTERM");const deadline=Date.now()+5e3;while(alive(state.pid)&&Date.now()<deadline)await delay3(50);if(alive(state.pid))throw new CliError("internal",`The watch server (pid ${state.pid}) did not stop.`)}await rm2(join12(gaugeDir,"watch.json"),{force:true});return running}function stopWatchServer(gaugeDir){return withWatchLock(gaugeDir,()=>stopLocked(gaugeDir))}function ensureWatchServer(gaugeDir){return withWatchLock(gaugeDir,()=>startLocked(gaugeDir))}async function startLocked(gaugeDir){const existing=await readWatchState(gaugeDir);if(existing&&(await ours(existing,gaugeDir))?.version===CLI_VERSION)return{...existing,reused:true};await stopLocked(gaugeDir);const bundled=fileURLToPath(new URL("./watchServer.js",import.meta.url));const args=existsSync5(bundled)?[bundled]:[...process.execArgv,fileURLToPath(new URL("../watchServer.ts",import.meta.url))];const logPath=join12(gaugeDir,"watch.log");const log=await open(logPath,"a",384);try{const child=spawn3(process.execPath,[...args,gaugeDir,CLI_VERSION],{detached:true,stdio:["ignore",log.fd,log.fd]});await new Promise((resolve5,reject)=>{child.once("spawn",resolve5);child.once("error",reject)});let exited=false;child.once("exit",()=>{exited=true});const deadline=Date.now()+1e4;while(true){const state=await readWatchState(gaugeDir);if(state&&state.pid===child.pid){child.unref();return{...state,reused:false}}if(exited||Date.now()>=deadline){child.kill();throw new CliError("internal",`The watch server did not start. See ${logPath}`)}await delay3(50)}}finally{await log.close()}}async function hostedUrl(command){const selection=selectedOrg(command);if(!selection)throw new CliError("usage","No organization selected. Pass --org <org> or set a default with `gauge orgs use <org>`.",{needsAccount:true});const{slug}=await findOrganization(selection.value);const base=resolveBaseUrl().replace(/\/+$/,"");return`${base}/${encodeURIComponent(slug)}/dashboard?liveruns=true`}function register37(program2){const watch=program2.command("watch").description("Print a URL for a live, read-only view of past and running sessions (local: starts a background server)").action(async(_opts,command)=>{const json=resolveOutput(command)==="json";if(gaugeState(command).mode==="hosted"){const url=await hostedUrl(command);if(json)printJson({mode:"hosted",url});else console.log(url);return}const state=await ensureWatchServer(localDirectory2(command));if(json)printJson({mode:"local",...state});else{console.log(state.url);console.error("Stop: gauge watch stop")}});watch.command("stop").description("Stop this workspace's background watch server").action(async(_opts,command)=>{const stopped=await stopWatchServer(localDirectory2(command));if(resolveOutput(command)==="json")printJson({stopped});else console.log(stopped?"Watch server stopped.":"No watch server is running.")})}var EXAMPLES=[["gauge init --local","Initialize a workspace; creates no measurements"],['gauge run "<prompt>"',"Run one prompt now; saves no measurement"],["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",watch:"Live view of past and running sessions",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:"Edit what agents read and rerun their sessions"}],["Insights (Gauge account)",{stats:"Analytics over your runs",dashboards:"Saved dashboards",issues:"The same finding across many sessions (also called findings)"}],["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 text2=(bullet?line.slice(2):line).replace(/`([^`]+)`/g,(span,inner)=>{const styled=code(inner);return(styled===inner?span:styled).replaceAll(" ","\0")});return[...gap,...helper.boxWrap(text2,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,text2])=>{const[first,...rest]=helper.boxWrap(text2,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(text2){return text2.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(arg2=>[helper.argumentTerm(arg2),helper.argumentDescription(arg2)]),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 Option6("-o, --output <format>","output format").choices([...OUTPUT_FORMATS]).default("table")).addOption(new Option6("--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,watch_exports,eval_exports,preference_exports,personas_exports,skills_exports,mcp_exports,connections_exports,repos_exports,optimizations_exports,brands_exports2,tags_exports,issues_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,fileURLToPath2(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)}
1057
+ `)}})}var watch_exports={};__export(watch_exports,{ensureWatchServer:()=>ensureWatchServer,register:()=>register37,stopWatchServer:()=>stopWatchServer});import{spawn as spawn3}from"child_process";import{existsSync as existsSync5}from"fs";import{mkdir,open,readFile,rm as rm2,writeFile}from"fs/promises";import{join as join12}from"path";import{setTimeout as delay3}from"timers/promises";import{fileURLToPath}from"url";function alive(pid){if(!Number.isSafeInteger(pid)||pid<=0)return false;try{process.kill(pid,0);return true}catch(error){return error.code==="EPERM"}}var readWatchState=gaugeDir=>readJson(join12(gaugeDir,"watch.json"));async function health(state){try{const res=await fetch(`${state.url}/api/health`,{signal:AbortSignal.timeout(5e3)});return await res.json()}catch(error){return error.name==="TimeoutError"?"busy":void 0}}async function ours(state,gaugeDir){if(!alive(state.pid))return void 0;const body2=await health(state);if(body2==="busy")return{};return body2?.gauge==="watch"&&body2.gaugeDir===gaugeDir?body2:void 0}async function withWatchLock(gaugeDir,fn){await mkdir(gaugeDir,{recursive:true});const path=join12(gaugeDir,"watch.lock");const deadline=Date.now()+3e4;while(true){try{await writeFile(path,String(process.pid),{flag:"wx",mode:384});break}catch(error){if(error.code!=="EEXIST")throw error;const holder=Number(await readFile(path,"utf8").catch(()=>""));if(holder&&!alive(holder))await rm2(path,{force:true});else if(Date.now()>=deadline)throw new CliError("internal",`Timed out waiting for ${path}. Remove it if no gauge watch is running.`);else await delay3(50)}}try{return await fn()}finally{await rm2(path,{force:true})}}async function stopLocked(gaugeDir){const state=await readWatchState(gaugeDir);if(!state)return false;const running=Boolean(await ours(state,gaugeDir));if(running){process.kill(state.pid,"SIGTERM");const deadline=Date.now()+5e3;while(alive(state.pid)&&Date.now()<deadline)await delay3(50);if(alive(state.pid))throw new CliError("internal",`The watch server (pid ${state.pid}) did not stop.`)}await rm2(join12(gaugeDir,"watch.json"),{force:true});return running}function stopWatchServer(gaugeDir){return withWatchLock(gaugeDir,()=>stopLocked(gaugeDir))}function ensureWatchServer(gaugeDir){return withWatchLock(gaugeDir,()=>startLocked(gaugeDir))}async function startLocked(gaugeDir){const existing=await readWatchState(gaugeDir);if(existing&&(await ours(existing,gaugeDir))?.version===CLI_VERSION)return{...existing,reused:true};await stopLocked(gaugeDir);const bundled=fileURLToPath(new URL("./watchServer.js",import.meta.url));const args=existsSync5(bundled)?[bundled]:[...process.execArgv,fileURLToPath(new URL("../watchServer.ts",import.meta.url))];const logPath=join12(gaugeDir,"watch.log");const log=await open(logPath,"a",384);try{const child=spawn3(process.execPath,[...args,gaugeDir,CLI_VERSION],{detached:true,stdio:["ignore",log.fd,log.fd]});await new Promise((resolve5,reject)=>{child.once("spawn",resolve5);child.once("error",reject)});let exited=false;child.once("exit",()=>{exited=true});const deadline=Date.now()+1e4;while(true){const state=await readWatchState(gaugeDir);if(state&&state.pid===child.pid){child.unref();return{...state,reused:false}}if(exited||Date.now()>=deadline){child.kill();throw new CliError("internal",`The watch server did not start. See ${logPath}`)}await delay3(50)}}finally{await log.close()}}async function hostedUrl(command){const selection=selectedOrg(command);if(!selection)throw new CliError("usage","No organization selected. Pass --org <org> or set a default with `gauge orgs use <org>`.",{needsAccount:true});const{slug}=await findOrganization(selection.value);const base=resolveBaseUrl().replace(/\/+$/,"");return`${base}/${encodeURIComponent(slug)}/dashboard?liveruns=true`}function register37(program2){const watch=program2.command("watch").description("Print a URL for a live, read-only view of past and running sessions (local: starts a background server)").action(async(_opts,command)=>{const json=resolveOutput(command)==="json";if(gaugeState(command).mode==="hosted"){const url=await hostedUrl(command);if(json)printJson({mode:"hosted",url});else console.log(url);return}const state=await ensureWatchServer(localDirectory2(command));if(json)printJson({mode:"local",...state});else{console.log(state.url);console.error("Stop: gauge watch stop")}});watch.command("stop").description("Stop this workspace's background watch server").action(async(_opts,command)=>{const stopped=await stopWatchServer(localDirectory2(command));if(resolveOutput(command)==="json")printJson({stopped});else console.log(stopped?"Watch server stopped.":"No watch server is running.")})}var EXAMPLES=[["gauge init --local","Initialize a workspace; creates no measurements"],['gauge run "<prompt>"',"Run one prompt now; saves no measurement"],["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",watch:"Live view of past and running sessions",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:"Edit what agents read and rerun their sessions"}],["Insights (Gauge account)",{stats:"Analytics over your runs",dashboards:"Saved dashboards",issues:"The same finding across many sessions (also called findings)"}],["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 text2=(bullet?line.slice(2):line).replace(/`([^`]+)`/g,(span,inner)=>{const styled=code(inner);return(styled===inner?span:styled).replaceAll(" ","\0")});return[...gap,...helper.boxWrap(text2,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,text2])=>{const[first,...rest]=helper.boxWrap(text2,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(text2){return text2.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(arg2=>[helper.argumentTerm(arg2),helper.argumentDescription(arg2)]),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 Option7("-o, --output <format>","output format").choices([...OUTPUT_FORMATS]).default("table")).addOption(new Option7("--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,watch_exports,eval_exports,preference_exports,personas_exports,skills_exports,mcp_exports,connections_exports,repos_exports,optimizations_exports,brands_exports2,tags_exports,issues_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,fileURLToPath2(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)}