MCPcopy
hub / github.com/garrytan/gstack / extractGlobalFlags

Function extractGlobalFlags

browse/src/cli.ts:786–836  ·  view source on GitHub ↗
(rawArgs: string[], env: NodeJS.ProcessEnv)

Source from the content-addressed store, hash-verified

784 * Exported for unit tests.
785 */
786export function extractGlobalFlags(rawArgs: string[], env: NodeJS.ProcessEnv): GlobalFlags {
787 const out: string[] = [];
788 let proxyUrl: string | null = null;
789 let headed = false;
790
791 for (let i = 0; i < rawArgs.length; i++) {
792 const arg = rawArgs[i];
793 if (arg === '--proxy') {
794 const value = rawArgs[i + 1];
795 if (!value) {
796 throw new ProxyConfigError(
797 'usage: --proxy <scheme://[user:pass@]host:port>',
798 '--proxy requires a URL value',
799 );
800 }
801 proxyUrl = value;
802 i++;
803 continue;
804 }
805 if (arg.startsWith('--proxy=')) {
806 proxyUrl = arg.slice('--proxy='.length);
807 continue;
808 }
809 if (arg === '--headed') { headed = true; continue; }
810 out.push(arg);
811 }
812
813 // Compose the canonical proxyUrl with creds resolved from argv+env.
814 let canonicalProxyUrl: string | null = null;
815 if (proxyUrl) {
816 const parsed = parseProxyConfig({
817 proxyUrl,
818 envUser: env.BROWSE_PROXY_USER,
819 envPass: env.BROWSE_PROXY_PASS,
820 });
821 // Re-encode with resolved creds embedded (server reads BROWSE_PROXY_URL
822 // from env — env passes to child process safely without ps-aux exposure).
823 const rebuilt = new URL(proxyUrl);
824 rebuilt.username = parsed.userId ? encodeURIComponent(parsed.userId) : '';
825 rebuilt.password = parsed.password ? encodeURIComponent(parsed.password) : '';
826 canonicalProxyUrl = rebuilt.toString();
827 }
828
829 return {
830 args: out,
831 proxyUrl: canonicalProxyUrl,
832 headed,
833 configHash: computeConfigHash({ proxyUrl: canonicalProxyUrl, headed }),
834 redactedProxyUrl: redactProxyUrl(canonicalProxyUrl),
835 };
836}
837
838async function handlePairAgent(state: ServerState, args: string[]): Promise<void> {
839 const clientName = parseFlag(args, '--client') || `remote-${Date.now()}`;

Callers 2

mainFunction · 0.85

Calls 4

parseProxyConfigFunction · 0.90
computeConfigHashFunction · 0.90
redactProxyUrlFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected