@sourcegraph/amp 0.0.1755820914-g2445db → 0.0.1755835333-gf95ef0
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/main.js +4 -4
- package/package.json +1 -1
package/dist/main.js
CHANGED
@@ -130,7 +130,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
130
130
|
`){this.advance();continue}if(this.current()==="#"){let Q=this.readComment();this.tokens.push({type:"COMMENT",value:Q,...A});continue}if(this.current()==="-"&&this.peek()==="-"){let Q=this.readFlag();this.tokens.push({type:"FLAG",value:Q,...A});continue}if(/[a-zA-Z0-9_*.-]/.test(this.current())||this.current()==="-"&&/\d/.test(this.peek())){let Q=this.readIdentifier();this.tokens.push({type:"IDENTIFIER",value:Q,...A});continue}throw new Error(`Unexpected character '${this.current()}' at line ${this.line}, column ${this.column}`)}return this.tokens.push({type:"EOF",value:"",position:this.position,line:this.line,column:this.column}),this.tokens}}class i90{tokens;current=0;constructor(A){this.tokens=A}currentToken(){return this.tokens[this.current]||this.tokens[this.tokens.length-1]}check(A){return this.currentToken().type===A}advance(){if(!this.isAtEnd())this.current++;return this.previous()}isAtEnd(){return this.currentToken().type==="EOF"}previous(){return this.tokens[this.current-1]}consume(A,Q){if(this.check(A))return this.advance();let B=this.currentToken();throw new Error(`${Q} at line ${B.line}, column ${B.column}`)}parseActionArgs(){let A={};while(this.check("FLAG")){let Q=this.advance().value;if(this.check("IDENTIFIER")||this.check("STRING"))A[Q]=this.advance().value;else{let B=this.currentToken();throw new Error(`Expected value after --${Q} at line ${B.line}, column ${B.column}`)}}return A}parseValue(A,Q){if(Q)return A;if(A==="true")return!0;if(A==="false")return!1;if(A==="null")return null;if(this.isNumeric(A)){let B=Number(A);if(!isNaN(B)&&isFinite(B))return B}return A}isNumeric(A){return/^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(A)}setNestedValue(A,Q,B){let J=Q.split("."),D=A;for(let G=0;G<J.length-1;G++){let X=J[G];if(!(X in D))D[X]={};D=D[X]}let z=J[J.length-1];D[z]=B}parseMatches(){let A=[],Q={};while(this.check("FLAG")){let J=this.advance().value,D=J.split(":"),z=D[0],G=D[1];if(!this.check("IDENTIFIER")&&!this.check("STRING")){let U=this.currentToken();throw new Error(`Expected value after --${J} at line ${U.line}, column ${U.column}`)}let X=this.advance(),K=X.value,Y=X.type==="STRING",q=this.parseValue(K,Y),Z;if(G)throw new Error(`Unknown operator '${G}' in --${J}`);else{if(z.includes(".")){A.push({key:z,parsedValue:q,rawValue:K});continue}Z=q}if(z in Q){let U=Q[z];if(Array.isArray(U))U.push(K);else Q[z]=[U,K]}else Q[z]=Z}let B=new Map;for(let J of A){let D=J.key.split(".")[0];if(!B.has(D))B.set(D,[]);B.get(D).push(J)}for(let[J,D]of B)if(this.shouldConvertToNestedStructure(D))for(let G of D)this.setNestedValue(Q,G.key,G.parsedValue);else for(let G of D)Q[G.key]=G.parsedValue;return Q}shouldConvertToNestedStructure(A){return!0}validateActionArgs(A,Q,B){let J=new Set;switch(A){case"delegate":J.add("to");break;case"reject":case"allow":case"ask":break}J.add("context");for(let D of Object.keys(Q))if(!J.has(D)){let z=Array.from(J).filter((G)=>G!=="context");if(z.length===0)throw new Error(`${A} action does not support any specific arguments (only --context is allowed) at line ${B.line}, column ${B.column}`);else throw new Error(`${A} action only supports --${z.join(", --")} at line ${B.line}, column ${B.column}`)}}parseEntry(){while(this.check("COMMENT"))this.advance();if(this.isAtEnd())throw new Error("Unexpected end of input");let A=this.consume("IDENTIFIER","Expected action (allow, reject, ask, delegate)"),Q=A.value;if(!["allow","reject","ask","delegate"].includes(Q))throw new Error(`Invalid action '${Q}' at line ${A.line}, column ${A.column}`);let B=this.parseActionArgs();if(this.validateActionArgs(Q,B,A),!this.check("IDENTIFIER")&&!this.check("STRING")){let X=this.currentToken();throw new Error(`Expected tool name at line ${X.line}, column ${X.column}`)}let D=this.advance().value,z=this.parseMatches(),G={tool:D,action:Q};if(Object.keys(z).length>0)G.matches=z;if(Q==="delegate"){if(!B.to)throw new Error(`Delegate action requires --to argument at line ${A.line}, column ${A.column}`);G.to=B.to}if(B.context){if(!["thread","subagent"].includes(B.context))throw new Error(`Invalid context '${B.context}'`);G.context=B.context}return G}}function SfA(A){try{let B=new l90(A.trim()).tokenize();return{success:!0,data:new i90(B).parseEntry()}}catch(Q){let B=Q instanceof Error?Q.message:String(Q),J=B.match(/line (\d+)/),D=B.match(/column (\d+)/);return{success:!1,error:{message:B,position:0,line:J?parseInt(J[1]):1,column:D?parseInt(D[1]):1}}}}function vfA(A){let Q=[],B="",J=!1,D="",z=1,G=1;for(let K=0;K<A.length;K++){let Y=A[K];if(!J&&(Y==='"'||Y==="'"))J=!0,D=Y,B+=Y;else if(J&&Y===D){let q=0,Z=K-1;while(Z>=0&&A[Z]==="\\")q++,Z--;if(q%2===0)J=!1,D="";B+=Y}else if(!J&&Y===`
|
131
131
|
`){let q=B.trim();if(q)Q.push({content:q,lineNumber:G});B="",z++,G=z}else if(Y===`
|
132
132
|
`)B+=Y,z++;else B+=Y}let X=B.trim();if(X)Q.push({content:X,lineNumber:G});return Q}function re(A){let Q=vfA(A),B=[];for(let J=0;J<Q.length;J++){let D=Q[J];if(D.content.startsWith("#"))continue;let z=SfA(D.content);if(!z.success)return z.error.line=D.lineNumber,z;B.push(z.data)}return{success:!0,data:B}}function kfA(A){if(typeof A!=="string")return!1;if(/[\s*"'\\]/.test(A)||A.includes("/")||A===""||!/^[a-zA-Z0-9_*.-]+$/.test(A))return!0;if(ffA(A))return!0;return!1}function ffA(A){return/^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(A)}function QO(A){if(typeof A!=="string")return String(A);if(!kfA(A))return A;return`'${A.replace(/'/g,"\\'")}'`}function ae(A,Q=""){let B=[];for(let[J,D]of Object.entries(A)){let z=Q?`${Q}.${J}`:J;if(Array.isArray(D))for(let G=0;G<D.length;G++){let X=`${z}.${G}`;if(typeof D[G]==="object"&&D[G]!==null)B.push(...ae(D[G],X));else B.push({path:X,value:D[G]})}else if(typeof D==="object"&&D!==null)B.push(...ae(D,z));else B.push({path:z,value:D})}return B}function yfA(A,Q){let B=[];if(typeof Q==="string"||typeof Q==="boolean"||typeof Q==="number"||Q===null)B.push(`--${A} ${QO(Q)}`);else if(Array.isArray(Q)){let J=Q.every((z)=>typeof z==="string"||typeof z==="boolean"||typeof z==="number"||z===null);if(!A.includes(".")&&J)for(let z of Q)B.push(`--${A} ${QO(z)}`);else for(let z=0;z<Q.length;z++)if(typeof Q[z]==="object"&&Q[z]!==null){let G=ae({[`${A}.${z}`]:Q[z]});for(let{path:X,value:K}of G)B.push(`--${X} ${QO(K)}`)}else B.push(`--${A}.${z} ${QO(Q[z])}`)}else if(typeof Q==="object"&&Q!==null){let J=ae({[A]:Q});for(let{path:D,value:z}of J)B.push(`--${D} ${QO(z)}`)}return B}function ne(A){let Q=[];if(Q.push(A.action),A.action==="delegate"&&A.to)Q.push(`--to ${QO(A.to)}`);if(A.context)Q.push(`--context ${A.context}`);if(Q.push(QO(A.tool)),A.matches)for(let[B,J]of Object.entries(A.matches)){let D=yfA(B,J);Q.push(...D)}return Q.join(" ")}function se(A){return A.map(ne).join(`
|
133
|
-
`)}var hx=()=>{};async function a90(A,Q,B="thread",J){let D=await W2(bfA);try{let z=await N$(A,Q,D,B,gx,J,"user");if(!z.matchedEntry)z=await N$(A,Q,C$,B,void 0,J,"built-in");if(!z.matchedEntry)return{permitted:!1,action:null,reason:"No matching entry found, denying by default"};let X=z.matchedEntry?.action==="delegate"&&z.action!=="reject"?"delegate":z.action;switch(z.action){case"allow":return{permitted:!0,action:X,matchedEntry:z.matchedEntry,error:z.error,source:z.source};case"reject":return{permitted:!1,action:X,matchedEntry:z.matchedEntry,reason:`Rejected by ${z.source==="built-in"?"built-in":z.source||"unknown"} permissions rule ${z.matchIndex}: ${ne(z.matchedEntry)}`,error:z.error,source:z.source};case"ask":return{permitted:!1,action:X,matchedEntry:z.matchedEntry,reason:`
|
133
|
+
`)}var hx=()=>{};async function a90(A,Q,B="thread",J){let D=await W2(bfA);try{let z=await N$(A,Q,D,B,gx,J,"user");if(!z.matchedEntry)z=await N$(A,Q,C$,B,void 0,J,"built-in");if(!z.matchedEntry)return{permitted:!1,action:null,reason:"No matching entry found, denying by default"};let X=z.matchedEntry?.action==="delegate"&&z.action!=="reject"?"delegate":z.action;switch(z.action){case"allow":return{permitted:!0,action:X,matchedEntry:z.matchedEntry,error:z.error,source:z.source};case"reject":return{permitted:!1,action:X,matchedEntry:z.matchedEntry,reason:`Rejected by ${z.source==="built-in"?"built-in":z.source||"unknown"} permissions rule ${z.matchIndex}: ${ne(z.matchedEntry)}`,error:z.error,source:z.source};case"ask":return{permitted:!1,action:X,matchedEntry:z.matchedEntry,reason:`Matches ${z.source==="built-in"?"built-in":z.source||"unknown"} permissions rule ${z.matchIndex}: ${ne(z.matchedEntry)}`,error:z.error,source:z.source};case null:if(z.error)return{permitted:!1,action:null,reason:z.error,error:z.error};return{permitted:!0,action:null};default:return{permitted:!1,action:null,reason:"Unknown permission result"}}}catch(z){return{permitted:!1,action:null,reason:z instanceof Error?z.message:"Permission evaluation failed",error:z instanceof Error?z.message:"Permission evaluation failed"}}}var bfA;var r90=P1(()=>{f6();uQ();ie();xe();hx();U3();bfA=fD.pipe(Z2((A)=>{if(A.settings?.dangerouslyAllowAll===!0)return[{tool:"*",action:"allow"}];return Fs(A.settings?.permissions)}),X7())});function oe(A){return{registerTool:A.registerTool.bind(A),tools:A.tools,preprocessArgs:A.preprocessArgs?.bind(A),invokeTool(Q,B,J){return new KA((D)=>{let z=null,G=!1,X=()=>{if(G)return;z=A.invokeTool(Q,B,J).subscribe(D)};if(B.userInput?.accepted===!0)return M1.debug(`Tool ${String(Q)} already approved by user - bypassing permission check`),X(),()=>{G=!0,z?.unsubscribe()};if(B.userInput?.accepted===!1)return M1.debug(`Tool ${String(Q)} rejected by user`),D.next({status:"rejected-by-user",reason:"Tool execution rejected by user"}),D.complete(),()=>{G=!0};return o8().then((K)=>{if(G)return;M1.debug(`Tool ${String(Q)} - checking permissions`);let Y=J.thread.mainThreadID?"subagent":"thread";return a90(Q,B.args,Y,J.thread.id)}).then((K)=>{if(G||!K)return;let{permitted:Y,reason:q,action:Z,error:U}=K;if(!Y){if(M1.debug(`Tool ${String(Q)} not permitted - action: ${Z}, reason: ${q}`),Z==="ask"){D.next({status:"blocked-on-user",reason:q||"Tool requires user approval due to permissions"}),D.complete();return}if(Z==="reject"&&U)D.next({status:"error",error:{message:U}});else D.next({status:"rejected-by-user",reason:q||"Tool execution denied by permissions"});D.complete();return}M1.debug(`Tool ${String(Q)} permitted - action: ${Z}`),X()}).catch((K)=>{if(G)return;M1.error(`Permission check failed for tool ${String(Q)}:`,K),D.next({status:"error",error:{message:K.message||"Permission check failed"}}),D.complete()}),()=>{G=!0,z?.unsubscribe()}})},dispose(){A.dispose()}}}var UI1=P1(()=>{f6();yA();uQ();r90()});function n90(A){let Q=[],B=!1;return async(...D)=>{return new Promise((z,G)=>{Q.push({args:D,resolve:z,reject:G}),J()})};async function J(){if(B||Q.length===0)return;B=!0;let{args:D,resolve:z,reject:G}=Q.shift();try{let X=await A(...D);z(X)}catch(X){G(X)}finally{B=!1,J()}}}var o90={};r6(o90,{ripgrepExecutable:()=>ux});import{exec as gfA}from"node:child_process";import{createHash as xfA}from"node:crypto";import{createWriteStream as hfA,existsSync as mfA}from"node:fs";import{chmod as ufA,mkdir as pfA,readFile as cfA,rename as dfA,unlink as lfA}from"node:fs/promises";import HI1,{homedir as Eg2}from"node:os";import FI1,{join as Wg2}from"node:path";import{Readable as ifA}from"node:stream";import{pipeline as afA}from"node:stream/promises";import s90 from"node:util";async function ux(){if(process.env.AMP_RIPGREP_PATH)return M1.info("ripgrepExecutable: Using AMP_RIPGREP_PATH",{path:process.env.AMP_RIPGREP_PATH}),process.env.AMP_RIPGREP_PATH;if(!await efA()){M1.info("ripgrepExecutable: System ripgrep not installed, downloading binary");let Q=await nfA();if(Q)return M1.info("ripgrepExecutable: Using downloaded ripgrep binary",{path:Q}),Q;M1.warn("ripgrepExecutable: ensureRipgrepBinary failed to return binary path")}return"rg"}async function nfA(){let A=(await o8()).settings.cacheDirectory;if(!A){M1.warn("ripgrepExecutable: No cache directory configured, cannot download binary");return}let Q=process.platform==="win32"?"rg.exe":"rg",B=FI1.join(A,"bin",Q);return rfA(B)}async function sfA(A){let Q=FI1.basename(A),J=`https://storage.googleapis.com/amp-public-assets-prod-0/ripgrep/ripgrep-binaries/${tfA()}`,D=`${J}/${Q}`,z=`${J}/${Q}.sha256`,G=await fetch(z);if(!G.ok)throw new Error(`failed to download ripgrep checksum: ${G.status} ${G.statusText}`);let X=(await G.text()).trim().split(/\s+/)[0],K=await fetch(D);if(!K.ok||!K.body){let q=await K.text();throw new Error(`failed to download ripgrep binary: ${K.status} ${K.statusText}
|
134
134
|
${q}`)}let Y=`${A}.${process.pid}.${Date.now()}.tmp`;try{await pfA(FI1.dirname(A),{recursive:!0});let q=hfA(Y),Z=ifA.fromWeb(K.body);await afA(Z,q);let U=await ofA(Y);if(U!==X)throw new Error(`ripgrep checksum validation failed: expected ${X}, got ${U}`);if(process.platform!=="win32")await ufA(Y,493);try{await dfA(Y,A)}catch(F){if(F instanceof Error&&"code"in F&&F.code==="EEXIST")return;throw F}}finally{await lfA(Y).catch(()=>{})}}async function ofA(A){let Q=xfA("sha256"),B=await cfA(A);return Q.update(B),Q.digest("hex")}function tfA(){let A=process.env.npm_config_arch||HI1.arch();switch(HI1.platform()){case"darwin":return A==="arm64"?"aarch64-apple-darwin":"x86_64-apple-darwin";case"win32":return A==="x64"?"x86_64-pc-windows-msvc":A==="arm64"?"aarch64-pc-windows-msvc":"i686-pc-windows-msvc";case"linux":return A==="x64"?"x86_64-unknown-linux-musl":A==="arm"?"arm-unknown-linux-gnueabihf":A==="armv7l"?"arm-unknown-linux-gnueabihf":A==="arm64"?"aarch64-unknown-linux-musl":A==="ppc64"?"powerpc64le-unknown-linux-gnu":A==="riscv64"?"riscv64gc-unknown-linux-gnu":A==="s390x"?"s390x-unknown-linux-gnu":"i686-unknown-linux-musl";default:throw new Error("Unknown platform: "+HI1.platform())}}async function efA(){if(mx!==void 0)return mx;try{return mx=(await s90.promisify(gfA)("rg --version")).stdout.includes("ripgrep"),mx}catch{return mx=!1,!1}}var rfA,mx;var te=P1(()=>{yA();uQ();rfA=n90(async(A)=>{if(mfA(A))return A;let Q=3;for(let B=1;B<=Q;B++)try{return await sfA(A),M1.info("ripgrep binary downloaded successfully",{path:A}),A}catch(J){let D=J instanceof Error?J.message:String(J);if(B===Q){M1.error("ripgrep download failed after all attempts",{error:D});return}M1.warn(`ripgrep download attempt ${B}/${Q} failed: ${D}`),await new Promise((z)=>setTimeout(z,500*Math.pow(2,B-1)))}return})});var A40={};r6(A40,{ripgrepFiles:()=>ee,nodeGlobTool:()=>QyA,globFilesWithRipgrep:()=>e90});import{spawn as AyA}from"node:child_process";function e90(A,Q,B){return $5(...A.map((J)=>ByA(J,Q,B))).pipe(Z2((J)=>{let D=[];for(let X of J)if(X.status==="in-progress")D.push(...X?.progress??[]);else if(X.status==="done")D.push(...X.result);else if(X.status==="error")D.push(...X.progress??[]);else if(X.status==="cancelled")D.push(...X.progress??[]);let z=J.filter((X)=>X.status==="error");if(z.length>0)return{status:"error",progress:D,error:{message:z.map((X)=>X?.error?.message??"").join(`
|
135
135
|
`)}};return{status:J.every((X)=>X.status==="done")?"done":J.some((X)=>X.status==="cancelled")?"cancelled":"in-progress",progress:D,result:D}}))}function ByA(A,Q,B){return new KA((J)=>{J.next({status:"in-progress",progress:[]}),ee(A,Q?{pattern:Q,caseInsensitive:!0}:null,B??{}).then(({files:D,remaining:z})=>{if(z>0)D.push(`--- ${z} more files not shown ---`);J.next({status:"done",progress:D,result:D})}).catch((D)=>{let z=D instanceof Error?D.message:String(D);J.next({status:"error",progress:[],error:{message:z}})}).finally(()=>J.complete())})}async function ee(A,Q,B){let J=B.limit??EI1,D=["--files","--color","never","--no-require-git","--hidden","--glob","!\\.git/","--glob","!\\.jj/"];if(B.maxDepth!==void 0)D.push("--max-depth",B.maxDepth.toString());let z;if(B.basePath)be(B.basePath),z=S3(B.basePath)?B.basePath:O6.joinPath(A,B.basePath).fsPath;else z=A.fsPath;if(D.push(z),Q?.pattern&&Q.pattern==="*")Q.pattern="**";let G=Q?.pattern?t90.default(Q.pattern,{nocase:Q.caseInsensitive,dot:!0}):void 0,X=AyA(await ux(),D,{stdio:["ignore","pipe","pipe"],detached:process.platform!=="win32",env:{...process.env,NONINTERACTIVE:"1",DEBIAN_FRONTEND:"noninteractive"}});return new Promise((K,Y)=>{let q=[],Z="",U="",F=B.offset??0,E=!1,M=()=>{if(E)return;if(!U)return;let W=U.startsWith(z)?U.slice(z.length+1):U;if(G&&!G(W))return;let I=U;if(U="",F>0){F--;return}if(q.push(I),q.length>=EI1)M1.warn("Glob limit reached. Returning partial results.",{glob:Q?.pattern,limit:EI1,dir:A}),X.kill(),E=!0,K({files:q,remaining:0,aborted:!0})};X.stdout?.on("data",(W)=>{for(let I of String(W)){if(I==="\r")continue;if(I===`
|
136
136
|
`)M(),U="";else U+=I}}),X?.stderr?.on("data",(W)=>{Z+=String(W)}),X.on("exit",(W)=>{if(W&&W>=2){Y(new Error(`ripgrep exited with code ${W}:
|
@@ -5055,7 +5055,7 @@ allow ${z}${G?` ${G}`:""}`}let J={stdin:process.stdin,stdout:process.stdout,stde
|
|
5055
5055
|
${U}`;if(B==="pnpm"&&U.includes("Unable to find the global bin directory"))F+=`
|
5056
5056
|
|
5057
5057
|
Hint: Try running "pnpm setup" to configure pnpm global directory, or use npm instead:
|
5058
|
-
npm install -g @sourcegraph/amp`;G(new Error(F))}},error:(Z)=>{if(!Y)Y=!0,G(new Error(`Failed to spawn ${B}: ${Z.message}`))},complete:()=>{if(!Y)Y=!0,z()}})})}var Yi1=Xi1.join(o10||Xi1.join(process.env.HOME||process.cwd(),".local","state"),"amp","last-thread-id");function Xr8(A,Q){let B={};if(A.getOptionValueSourceWithGlobals("dangerouslyAllowAll")==="cli")B.dangerouslyAllowAll=Q.dangerouslyAllowAll;if(A.getOptionValueSourceWithGlobals("tryGpt5")==="cli")B.gpt5=Q.tryGpt5;return B}function Aj(A,Q){if(A.getOptionValueSourceWithGlobals("dangerouslyAllowAll")==="cli")nZ("dangerouslyAllowAll",Q.dangerouslyAllowAll);if(A.getOptionValueSourceWithGlobals("tryGpt5")==="cli")nZ("gpt5",Q.tryGpt5)}var NO2=j6.union([j6.object({command:j6.string(),args:j6.array(j6.string()).optional(),env:j6.record(j6.string(),j6.string()).optional()}).strict(),j6.object({url:j6.string()}).strict()]),VO2=j6.record(j6.string(),NO2);async function qi1(A){try{await WO2(Xi1.dirname(Yi1),{recursive:!0}),await IO2(Yi1,A,"utf-8")}catch(Q){M1.debug("Failed to save last thread ID",Q)}}async function OO2(){try{return(await swA(Yi1,"utf-8")).trim()}catch(A){return null}}async function CO2(A){let Q;try{Q=JSON.parse(A)}catch(B){throw new Error(`Failed to parse --mcp-config as JSON: ${B instanceof Error?B.message:String(B)}`)}try{return VO2.parse(Q)}catch(B){if(B instanceof j6.ZodError){let J=B.issues.map((D)=>`${D.path.join(".")}: ${D.message}`).join(", ");throw new Error(`Invalid MCP server configuration: ${J}`)}throw new Error(`Failed to validate MCP server configuration: ${String(B)}`)}}function LO2(A,Q){return{...A,async get(B){if(B==="mcpServers"){let J=await A.get(B)||{},D={};if(typeof J==="object")for(let[z,G]of Object.entries(J))D[z]={...G,_target:"global"};for(let[z,G]of Object.entries(Q))D[z]={...G,_target:"workspace"};return D}return A.get(B)},async keys(){let B=await A.keys();if(!B.includes("mcpServers"))B.push("mcpServers");return B},[Symbol.dispose](){A[Symbol.dispose]()}}}async function RO2(A){let Q=await cz(`/api/threads/${A}`);if(!Q.ok){let B=await Q.text();if(Q.status===404||B.includes("not found"))throw new cB(bX.threadNotFound(A));throw new cB(`Failed to load thread ${A}`,1,`Use 'amp threads share ${A} --support' to share this with the Amp team if this persists.`)}return await Q.json()}var iwA=[{name:"notifications",long:"notifications",type:"flag",description:(A)=>`${A?"Enable":"Disable"} sound notifications (enabled by default when not in execute mode)`},{name:"color",long:"color",type:"flag",description:(A)=>`${A?"Enable":"Disable"} color output (enabled by default if stdout and stderr are sent to a TTY)`,deprecated:!0},{name:"settingsFile",long:"settings-file",type:"option",default:process.env.AMP_SETTINGS_FILE??xX,description:`Custom settings file path (overrides the default location ${xX})`},{name:"logLevel",long:"log-level",type:"option",description:`Set log level (${Object.keys(M1).join(", ")})`},{name:"logFile",long:"log-file",type:"option",description:"Set log file location"},{name:"format",long:"format",type:"option",description:"output using the standard or new-ui. Options: `ui`, `new-ui`",choices:["ui","jsonl","new-ui"],hidden:!0,deprecated:!0},{name:"dangerouslyAllowAll",long:"dangerously-allow-all",type:"switch",default:!1,description:"Disable all command confirmation prompts (agent will execute all commands without asking)"},{name:"jetbrains",long:"jetbrains",type:"flag",default:yR(),description:(A)=>A?"Enable JetBrains integration. You must start Amp in the same directory as your JetBrains project. When enabled, Amp automatically includes your open JetBrains file and text selection with every message.":"Disable JetBrains integration.",hidden:!0},{name:"interactive",long:"interactive",type:"flag",description:(A)=>A?"Enable interactive mode. This will enable the interactive UI.":"Disable interactive mode. This will disable the interactive UI.",hidden:!0,deprecated:!0},{name:"mcpConfig",long:"mcp-config",type:"option",description:"JSON configuration or file path for MCP servers to merge with existing settings"},{name:"tryGpt5",long:"try-gpt5",type:"switch",default:!1,description:"Try GPT-5 as the primary agent model (limited time; see https://ampcode.com/news/gpt-5)"}],awA=(A)=>("deprecated"in A)&&A.deprecated===!0,jO2=(A)=>("hidden"in A)&&A.hidden===!0,TO2=(A)=>("default"in A),$O2=(A)=>("default"in A)?A.default:void 0;function _O2(A,Q){let B=Q.args[0],J=Q.commands.map((z)=>z.name());if(B&&!B.includes(" ")&&B.length<30&&!/[./\\]/.test(B)){let z=J.filter((X)=>B.includes(X)||X.includes(B)),G="Run amp --help for a list of available commands.";if(z.length>0)G=`Did you mean: ${z.join(", ")}? Or run amp --help for all commands.`;throw new cB(bX.unknownCommand(B),1,G)}}function LX1(A){return{...A,getThreadEnvironment:CBA,createFileSystem:()=>cx,createFileChangeTrackerForThread:(Q)=>{let B=new dx(cx);return L40(B,cx,Q)},generateThreadTitle:u01,internalAPIClient:ZK}}var Zi1=V6.file(wO2.homedir()),owA=process.env.XDG_CONFIG_HOME?V6.file(process.env.XDG_CONFIG_HOME):O6.joinPath(Zi1,".config");async function Qj(A,Q,B=!1){Lo1("0.0.
|
5058
|
+
npm install -g @sourcegraph/amp`;G(new Error(F))}},error:(Z)=>{if(!Y)Y=!0,G(new Error(`Failed to spawn ${B}: ${Z.message}`))},complete:()=>{if(!Y)Y=!0,z()}})})}var Yi1=Xi1.join(o10||Xi1.join(process.env.HOME||process.cwd(),".local","state"),"amp","last-thread-id");function Xr8(A,Q){let B={};if(A.getOptionValueSourceWithGlobals("dangerouslyAllowAll")==="cli")B.dangerouslyAllowAll=Q.dangerouslyAllowAll;if(A.getOptionValueSourceWithGlobals("tryGpt5")==="cli")B.gpt5=Q.tryGpt5;return B}function Aj(A,Q){if(A.getOptionValueSourceWithGlobals("dangerouslyAllowAll")==="cli")nZ("dangerouslyAllowAll",Q.dangerouslyAllowAll);if(A.getOptionValueSourceWithGlobals("tryGpt5")==="cli")nZ("gpt5",Q.tryGpt5)}var NO2=j6.union([j6.object({command:j6.string(),args:j6.array(j6.string()).optional(),env:j6.record(j6.string(),j6.string()).optional()}).strict(),j6.object({url:j6.string()}).strict()]),VO2=j6.record(j6.string(),NO2);async function qi1(A){try{await WO2(Xi1.dirname(Yi1),{recursive:!0}),await IO2(Yi1,A,"utf-8")}catch(Q){M1.debug("Failed to save last thread ID",Q)}}async function OO2(){try{return(await swA(Yi1,"utf-8")).trim()}catch(A){return null}}async function CO2(A){let Q;try{Q=JSON.parse(A)}catch(B){throw new Error(`Failed to parse --mcp-config as JSON: ${B instanceof Error?B.message:String(B)}`)}try{return VO2.parse(Q)}catch(B){if(B instanceof j6.ZodError){let J=B.issues.map((D)=>`${D.path.join(".")}: ${D.message}`).join(", ");throw new Error(`Invalid MCP server configuration: ${J}`)}throw new Error(`Failed to validate MCP server configuration: ${String(B)}`)}}function LO2(A,Q){return{...A,async get(B){if(B==="mcpServers"){let J=await A.get(B)||{},D={};if(typeof J==="object")for(let[z,G]of Object.entries(J))D[z]={...G,_target:"global"};for(let[z,G]of Object.entries(Q))D[z]={...G,_target:"workspace"};return D}return A.get(B)},async keys(){let B=await A.keys();if(!B.includes("mcpServers"))B.push("mcpServers");return B},[Symbol.dispose](){A[Symbol.dispose]()}}}async function RO2(A){let Q=await cz(`/api/threads/${A}`);if(!Q.ok){let B=await Q.text();if(Q.status===404||B.includes("not found"))throw new cB(bX.threadNotFound(A));throw new cB(`Failed to load thread ${A}`,1,`Use 'amp threads share ${A} --support' to share this with the Amp team if this persists.`)}return await Q.json()}var iwA=[{name:"notifications",long:"notifications",type:"flag",description:(A)=>`${A?"Enable":"Disable"} sound notifications (enabled by default when not in execute mode)`},{name:"color",long:"color",type:"flag",description:(A)=>`${A?"Enable":"Disable"} color output (enabled by default if stdout and stderr are sent to a TTY)`,deprecated:!0},{name:"settingsFile",long:"settings-file",type:"option",default:process.env.AMP_SETTINGS_FILE??xX,description:`Custom settings file path (overrides the default location ${xX})`},{name:"logLevel",long:"log-level",type:"option",description:`Set log level (${Object.keys(M1).join(", ")})`},{name:"logFile",long:"log-file",type:"option",description:"Set log file location"},{name:"format",long:"format",type:"option",description:"output using the standard or new-ui. Options: `ui`, `new-ui`",choices:["ui","jsonl","new-ui"],hidden:!0,deprecated:!0},{name:"dangerouslyAllowAll",long:"dangerously-allow-all",type:"switch",default:!1,description:"Disable all command confirmation prompts (agent will execute all commands without asking)"},{name:"jetbrains",long:"jetbrains",type:"flag",default:yR(),description:(A)=>A?"Enable JetBrains integration. You must start Amp in the same directory as your JetBrains project. When enabled, Amp automatically includes your open JetBrains file and text selection with every message.":"Disable JetBrains integration.",hidden:!0},{name:"interactive",long:"interactive",type:"flag",description:(A)=>A?"Enable interactive mode. This will enable the interactive UI.":"Disable interactive mode. This will disable the interactive UI.",hidden:!0,deprecated:!0},{name:"mcpConfig",long:"mcp-config",type:"option",description:"JSON configuration or file path for MCP servers to merge with existing settings"},{name:"tryGpt5",long:"try-gpt5",type:"switch",default:!1,description:"Try GPT-5 as the primary agent model (limited time; see https://ampcode.com/news/gpt-5)"}],awA=(A)=>("deprecated"in A)&&A.deprecated===!0,jO2=(A)=>("hidden"in A)&&A.hidden===!0,TO2=(A)=>("default"in A),$O2=(A)=>("default"in A)?A.default:void 0;function _O2(A,Q){let B=Q.args[0],J=Q.commands.map((z)=>z.name());if(B&&!B.includes(" ")&&B.length<30&&!/[./\\]/.test(B)){let z=J.filter((X)=>B.includes(X)||X.includes(B)),G="Run amp --help for a list of available commands.";if(z.length>0)G=`Did you mean: ${z.join(", ")}? Or run amp --help for all commands.`;throw new cB(bX.unknownCommand(B),1,G)}}function LX1(A){return{...A,getThreadEnvironment:CBA,createFileSystem:()=>cx,createFileChangeTrackerForThread:(Q)=>{let B=new dx(cx);return L40(B,cx,Q)},generateThreadTitle:u01,internalAPIClient:ZK}}var Zi1=V6.file(wO2.homedir()),owA=process.env.XDG_CONFIG_HOME?V6.file(process.env.XDG_CONFIG_HOME):O6.joinPath(Zi1,".config");async function Qj(A,Q,B=!1){Lo1("0.0.1755835333-gf95ef0"),Ro1(Q.jetbrains);let J=VZ1({storage:A.settings,secretStorage:A.secrets,workspaceRoots:KA.of([V6.file(process.cwd())]),defaultAmpURL:A.ampURL,defaultCacheDirectory:Xp1,homeDir:Zi1,userConfigDir:owA}),D=await o8();M1.debug("Global configuration initialized",{hasCacheDirectory:!!D.settings.cacheDirectory,settingsKeys:Object.keys(D.settings)});let z=oe(js()),G=$90({configService:J,toolService:z});if(process.env.AMP_TOOLBOX)g30(z,cx,Q81);try{await G.initialized}catch(w){M1.warn("Failed to wait for MCP servers, continuing anyway:",w)}if(Q.jetbrains)try{M1.debug("ide-client",{terminalEmulator:process.env.TERMINAL_EMULATOR}),await GK.start()}catch(w){let N=w instanceof Error?w.message:String(w);VD(`Failed to connect to JetBrains IDE: ${N}`)}let X=D.settings["experimental.reviewTool"]??!1,K=D.settings["experimental.tools"]??[];I2A(z,!1,X,K,Q.jetbrains);let Y;if(!A.executeMode)Y=new xz1(process.cwd(),{},!0);else Y=new class extends xz1{async start(){}async query(){return[]}getStats(){return{state:"unstarted",stats:[]}}dispose(){}};if(!await A.secrets.get("apiKey",A.ampURL)){if(k4.write(`No API key found. Starting login flow...
|
5059
5059
|
`),!await PO2(A))process.exit(1)}let q=z40(),Z=new uI1(q),U=new xI1(q),F=new A31(Z),E=Q.notifications!==void 0?Q.notifications:!A.executeMode,M=N2A({playNotificationSound:async(w)=>{if(E){if(w2A(w),!(B?Wd1():LWA())&&D.settings["notifications.system.enabled"]!==!1){if(w==="idle")process.stdout.write("\x1B]777;notify;Amp;Agent is ready\x1B\\");else if(w==="requires-user-input")process.stdout.write("\x1B]777;notify;Amp;Waiting for approval\x1B\\")}}},windowFocused:()=>Promise.resolve(!1),threadService:Z});M1.info("Starting Amp background services");let W=$K0({threadService:Z,threadHistoryService:U,isExtensionDevelopment:!1}),I={configService:J,toolService:z,mcpService:G,threadService:Z,threadHistoryService:U,threadSummaryService:F,threadSyncService:W,threadStorage:q,secretStorage:A.secrets,settingsStorage:A.settings,fuzzyServer:Y,notificationService:M};return{...I,async dispose(){await I.mcpService.dispose(),I.configService.unsubscribe(),I.toolService.dispose(),I.fuzzyServer.dispose(),I.threadSyncService.dispose(),I.settingsStorage[Symbol.dispose]()}}}async function PO2(A){if(!A.executeMode){if(await iz1("Would you like to log in to Amp?",["(y)es","(n)o"])!="y")return k4.write(`Login cancelled. Run the command again to retry.
|
5060
5060
|
`),!1}return await twA(A)}async function twA(A){let Q=MO2(32).toString("hex"),B=await JEA(A.ampURL,Q);k4.write(`If your browser doesn't open automatically, visit:
|
5061
5061
|
|
@@ -5069,7 +5069,7 @@ ${J0.blue.bold(B)}
|
|
5069
5069
|
Login successful! You can now use the Amp CLI.
|
5070
5070
|
`),!0}catch(J){return B7.write(`
|
5071
5071
|
Login failed: ${J instanceof Error?J.message:String(J)}
|
5072
|
-
`),!1}}function SO2(A){let Q=A.outputHelp.bind(A);A.outputHelp=function(B){let J="",D=this.configureOutput();if(this.configureOutput({writeOut:(z)=>{J+=z},writeErr:(z)=>{J+=z}}),typeof B==="function")B(J);else Q(B);this.configureOutput(D),XEA(J)}}function ewA(A){SO2(A);for(let Q of A.commands)ewA(Q)}function vO2(){let A=new WJ1().name("amp").description("AI-powered coding assistant").option("--visibility <visibility>","Set thread visibility (private, public, team)").configureOutput({writeErr:()=>{}});A.exitOverride((X)=>{if(X.code==="commander.help"||X.code==="commander.version"||X.exitCode===0)Xf(),process.exit(0);let K=X.originalError??X;Ea(K)}),A.option("-V, --version","output the version number",()=>{k4.write(`0.0.
|
5072
|
+
`),!1}}function SO2(A){let Q=A.outputHelp.bind(A);A.outputHelp=function(B){let J="",D=this.configureOutput();if(this.configureOutput({writeOut:(z)=>{J+=z},writeErr:(z)=>{J+=z}}),typeof B==="function")B(J);else Q(B);this.configureOutput(D),XEA(J)}}function ewA(A){SO2(A);for(let Q of A.commands)ewA(Q)}function vO2(){let A=new WJ1().name("amp").description("AI-powered coding assistant").option("--visibility <visibility>","Set thread visibility (private, public, team)").configureOutput({writeErr:()=>{}});A.exitOverride((X)=>{if(X.code==="commander.help"||X.code==="commander.version"||X.exitCode===0)Xf(),process.exit(0);let K=X.originalError??X;Ea(K)}),A.option("-V, --version","output the version number",()=>{k4.write(`0.0.1755835333-gf95ef0 (released 2025-08-22T04:07:27.731Z)
|
5073
5073
|
`),process.exit(0)}),A.addHelpText("after",eFA()),A.configureHelp({formatHelp:AEA}),A.command("logout").description("Log out by removing stored API key").action(async(X,K)=>{let Y=K.optsWithGlobals(),q=await $Z(Y);await bO2(q)}),A.command("login").description("Log in to Amp").addHelpText("after","If AMP_URL is set during login, it will be persisted to global settings for future CLI invocations, though AMP_URL will continue to take precedence.").action(async(X,K)=>{let Y=K.optsWithGlobals(),q=await $Z(Y);await yO2(q)});let Q=A.command("threads").alias("t").summary("Manage threads").description("Thread management commands. When no subcommand is provided, defaults to listing threads.").action(async(X,K)=>{let Y=K.optsWithGlobals(),q=await $Z(Y);await nwA(Y,q,K)});Q.command("new").alias("n").summary("Create a new thread").description("Create a new thread and print its ID. The thread will be empty. You can set the visibility using the --visibility option.").option("--visibility <visibility>","Set thread visibility (private, public, team)").action(async(X,K)=>{let Y=K.optsWithGlobals(),q=await $Z(Y);await pO2(Y,q,K)}),Q.command("continue [threadId]").alias("c").summary("Continue an existing thread").description("Continue an existing thread by resuming the conversation. If no thread ID is provided, the most recently used thread will be continued.").option("--pick","Pick a thread interactively from a list").action(async(X,K,Y)=>{let q=Y.optsWithGlobals(),Z=await $Z(q);if(K.pick){VZ1({storage:Z.settings,secretStorage:Z.secrets,workspaceRoots:KA.of([V6.file(process.cwd())]),defaultAmpURL:Z.ampURL,homeDir:Zi1,userConfigDir:owA});let U=await cO2();if(U)await rwA(q,Z,U,Y);else process.exit(0)}else await rwA(q,Z,X,Y)}),Q.command("fork [threadId]").alias("f").summary("Fork an existing thread").description("Create a new thread by forking an existing one. This copies the conversation history up to the current point and creates a new thread where you can explore different directions. If no thread ID is provided, the most recently used thread will be forked.").action(async(X,K,Y)=>{let q=Y.optsWithGlobals(),Z=await $Z(q);await uO2(q,Z,X,Y)}),Q.command("list").alias("l").summary("List all threads").description("List all your threads with their IDs, names, and last modified times.").action(async(X,K)=>{let Y=K.optsWithGlobals(),q=await $Z(Y);await nwA(Y,q,K)}),Q.command("share <threadId>").summary("Share a thread").description("Change thread visibility (private, public, team) or share with Amp support for debugging. Use --visibility to change who can access the thread, or --support to share with the Amp team for troubleshooting.").alias("s").option("--visibility <visibility>","Set thread visibility (private, public, team)").option("--support","Share thread with Amp support for debugging").action(async(X,K,Y)=>{let q=Y.optsWithGlobals(),Z=await $Z(q);await mO2(q,Z,X,Y,K.support)}),Q.command("compact <threadId>").alias("co").summary("Compact a thread").description("Compact a thread by creating a summary of the conversation history. This reduces the thread size while preserving the key information and context, making it more token efficient for future use.").action(async(X,K,Y)=>{let q=Y.optsWithGlobals(),Z=await $Z(q);await hO2(q,Z,X,Y)}),VEA(A,async(X,K)=>{let Y=await $Z(K);Aj(X,K);let q=await Qj(Y,K,!1);return{context:Y,mcpService:q.mcpService,toolService:q.toolService,cleanupTerminal:Xf,dispose:q.dispose.bind(q)}}),FEA(A);function B(X,K,Y){let Z=typeof X.description==="string"?X.description:Y===void 0?X.description(!0):X.description(Y),U=new IJ1(K,Z),F=$O2(X);if(F)U.default(F);return U.hidden=jO2(X)||awA(X),U}for(let X of iwA)switch(X.type){case"flag":{A.addOption(B(X,`--${X.long}`)),A.addOption(B(X,`--no-${X.long}`,!1));break}case"switch":{A.addOption(B(X,`--${X.long}`,!0));break}default:{A.addOption(B(X,`--${X.long} <value>`));break}}let J=new IJ1("-x, --execute [message]","Use execute mode, optionally with user message. In execute mode, agent will execute provided prompt (either as argument, or via stdin). Only last assistant message is printed. Enabled automatically when redirecting stdout.").default(!1);A.addOption(J);let D=new IJ1("--tui","Launch experimental TUI interface").hideHelp();A.addOption(D),A.action(async(X,K)=>{let Y=X,q=await $Z(Y);if(Object.keys(Y).forEach((Z)=>{if(Z==="format"&&X.format==="jsonl"){B7.write(J0.yellow(`jsonl format is deprecated. Version "0.0.1753194394-g45962a" is required to use jsonl format.
|
5074
5074
|
`));return}let U=iwA.find((F)=>F.name===Z);if(U&&awA(U)&&!TO2(U))B7.write(J0.yellow(`Warning: '--${Z}' flag is deprecated
|
5075
5075
|
`))}),K.args.length>0)_O2(q,K);await ANA(q,Y,K)});let z=new WJ1("doctor").summary("Generate support bundle").description("Generate a support bundle for troubleshooting issues. This collects logs, configuration, and system information into a file that can be shared with Amp support for debugging.").option("--output-dir <path>","Directory to save the support bundle",process.cwd()).option("--include-full-logs","Include full log history",!1).allowUnknownOption(!1).action(async(X)=>{await xO2(X.outputDir,X.includeFullLogs)});A.addCommand(z);let G=new WJ1("update").summary("Update Amp CLI").description("Update Amp CLI to the latest version. You can specify a particular version to install, or leave blank to get the latest stable release.").option("--version <version>","Update to a specific version").allowUnknownOption(!1).action(async(X)=>{await gO2(X.version)});return A.addCommand(G),ewA(A),A}async function CX1(A,Q,B){let{thread:J,visibility:D}=B,z=J?.id??jF(),G=LX1(Q);if(J)await Q.threadStorage.set(z,J);let X=await lD.getOrCreateForThread(G,z);if(D)await Q.threadSyncService.updateThreadMeta(z,cz1(D));let K=Q.threadService.observe(z).subscribe(async(Y)=>{if(NQ(Y,"assistant"))await qi1(z),K.unsubscribe()});return await X.resume(),X}async function ANA(A,Q,B){let J=process.stdin,D=pz1(Q);if(D instanceof Error)VD(D.message);let z,G=null;if(typeof Q.execute==="string"){z=Q.execute;let M=(await sc1()).trimEnd();if(M)G=M}else z=(await sc1()).trimEnd();if(A.executeMode&&z==="")throw new cB("User message must be provided through stdin or as argument when using execute mode",1,`Either pass a message as an argument: amp -x "your message"
|
@@ -5089,7 +5089,7 @@ Or pipe via stdin: echo "your message" | amp -x`);if(z!==""&&!A.executeMode&&typ
|
|
5089
5089
|
`);process.exit(0)}async function gO2(A){try{if(A)B7.write(J0.blue(`Updating to version ${A}...
|
5090
5090
|
`)),await Gi1(A),B7.write(J0.green(`✓ Successfully updated to version ${A}
|
5091
5091
|
`));else{B7.write(J0.blue(`Checking for updates...
|
5092
|
-
`));let Q=await J11("0.0.
|
5092
|
+
`));let Q=await J11("0.0.1755835333-gf95ef0");if(!Q.hasUpdate)B7.write(J0.green(`✓ Amp CLI is already up to date.
|
5093
5093
|
`)),process.exit(0);B7.write(J0.blue(`Updating to version ${Q.latestVersion}...
|
5094
5094
|
`)),await Gi1(Q.latestVersion),B7.write(J0.green(`✓ Successfully updated to version ${Q.latestVersion}
|
5095
5095
|
`))}process.exit(0)}catch(Q){VD(Q instanceof Error?Q.message:String(Q))}}async function xO2(A,Q){try{B7.write(J0.green("Generating Amp support bundle...")+`
|
package/package.json
CHANGED