1#!/usr/bin/env node2var me=Object.defineProperty;var n=(t,e)=>me(t,"name",{value:e,configurable:!0});import{createHash as Ue}from"crypto";import{chmodSync as Ve,closeSync as we,lstatSync as Fe,mkdirSync as Me,openSync as $e,readdirSync
3`)}n(M,"formatCliHelp");import{isIP as Re}from"node:net";var Ne="https://shopify.dev/",Le="https://shopify-dev.shop.dev/";function $(t){return`https://shopify-dev-staging${t}.shopifycloud.com/`}n($,"stagingHost");var De="SHOPIFY_DEV_SUPPORT_CORE_MCP_DOMAIN",T="SHOPIFY_DEV_LOCAL_SERVER_URL";function be(t){let e;try{e=new URL(t)}catch{throw new Error(`${T} must identify a local Shopify.dev origin`)}let r=e.hostname==="localhost"||e.hostname==="[::1]"||Re(e.hostname)===4&&e.hostname.startsWith("127."),i=/^shopify-dev-[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.shop\.dev$/u.test(e.hostname);if(!r&&!i||r&&!e.port||i&&e.protocol!=="https:"||r&&e.protocol!=="http:"&&e.protocol!=="https:"||e.username||e.password||e.pathname!==""&&e.pathname!=="/"||e.search||e.hash)throw new Error(`${T} must identify a local Shopify.dev origin`);return`${e.origin}/`}n(be,"normalizeLocalShopifyDevUrl");function A(t){let e=t?.env??process.env,r=e.SHOPIFY_DEV_STAGING_SERVER_NUMBER?.trim(),i=e[T]?.trim();if(i&&t?.allowLocalServer){if(r||e.DEV&&e.DEV!=="false"||e[De]?.trim())throw new Error(`${T} cannot be combined with staging, DEV, or Support Core routing overrides`);return{url:be(i),headers:{}}}if(r){if(!/^\d+$/.test(r))throw new Error(`SHOPIFY_DEV_STAGING_SERVER_NUMBER must be a positive integer; got: "${r}"`);let o=Number(r);if(!Number.isSafeInteger(o)||o<=0)throw new Error(`SHOPIFY_DEV_STAGING_SERVER_NUMBER must be a positive integer; got: "${r}"`);let a=e.MINERVA_TOKEN;if(!a){let c=$(o).replace(/\/$/,"");throw new Error(`SHOPIFY_DEV_STAGING_SERVER_NUMBER=${o} is set but no Minerva token is available. Staging servers are behind Minerva. Get a token via:
5`));return}await H("/mcp/usage",{method:"POST",headers:p,body:l,instrumentation:{packageVersion:"1.19.0",timestamp:new Date().toISOString()}})}catch{}}n(Y,"reportValidation");var J=".feedback",je=1440*60*1e3;function Xe(){let t=process.getuid?.()??0;return k(Ge(),`shopify-ai-toolkit-telemetry-${t}`)}n(Xe,"markerDir");function Je(t,e){let r=Ue("sha256").update(e).digest("hex").slice(0,32);return k(t,`${r}${J}`)}n(Je,"markerPath");function We(t){try{let e=Date.now()-je;for(let r of He(t)){if(!r.endsWith(J))continue;let i=k(t,r);try{Ke(i).mtimeMs<e&&Be(i,{force:!0})}catch{}}}catch{}}n(We,"pruneStaleMarkers");function ze(t){let e;try{e=Xe(),Me(e,{recursive:!0,mode:448});let r=Fe(e),i=process.getuid?.();if(r.isSymbolicLink()||!r.isDirectory()||i!==void 0&&r.uid!==i)return!0;try{Ve(e,448)}catch{return!0}We(e)}catch{return!0}try{return we($e(Je(e,t),"wx",384)),!0}catch(r){return r?.code!=="EEXIST"}}n(ze,"claimOnceMarker");function _(t,e){return t.includes(e)?e:void 0}n(_,"parseEnum");function W(t){return typeof t=="string"&&t.length>0?t:void 0}n(W,"nonEmptyFlag");function R(t){return{type:"string",choices:f,description:t}}n(R,"verdictOption");var z={overall:{type:"string",choices:C,description:"Overall toolkit verdict for this turn"},"docs-context":R("Verdict for docs/search context"),"schema-validation":R("Verdict for schema/code validation"),"api-version":R("Verdict for API version targeting"),codegen:R("Verdict for generated code"),"comment-base64":{type:"string",valueName:"base64",description:`Base64-encoded rationale, decoded and truncated to ${500} chars (base64 keeps arbitrary text inert in the shell)`},"session-id":g["session-id"],"tool-use-id":g["tool-use-id"],...y,...F},qe=[M(["scripts/log_feedback.mjs --overall <up|down|mixed> --docs-context <verdict>"," --schema-validation <verdict> --api-version <verdict> --codegen <verdict>"," --comment-base64 <base64> [--session-id <id>] [--tool-use-id <id>]"," [--model <name>] [--client-name <name>] [--client-version <version>]"],z),"","Each <verdict> is one of: worked | partial | failed | not_used.","Run once per turn. Without a session id or tool-use id there is no dedupe","key, so nothing is sent."].join(`