openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 5.46 kB
JavaScript
import{p as CLI_PARENT_BOUND_PRELOAD,r as getWindowsNativeRedirectStartup}from"./cli-invocation-Covx3kvQ.mjs";import{n as resolveRuntimeWorkerArgv}from"./runtime-worker-url-Dqf-I1cs.mjs";import{o as resolveRuntimeProcessEntrypointUrl}from"./runtime-process-url-DJ272Tuo.mjs";import{t as createSubsystemLogger}from"./subsystem-DLCDFvCH.mjs";import{n as quotePowerShellArg,t as quoteCliArg}from"./quote-cli-arg-BUHoGELl.mjs";import{a as resolveConfiguredGitHubHost,n as GITHUB_PUBLIC_HOST}from"./github-host-BIyVIYLv.mjs";import{realpathSync}from"node:fs";import{fileURLToPath,pathToFileURL}from"node:url";import path from"node:path";
//!src/agents/github-exec-launch.ts
const log=createSubsystemLogger(`agents/github-exec`);function skipNativeRedirect(e){log.debug(`Managed GitHub resolver startup`,{stage:e})}function resolveWindowsNativeRedirect(e){if(process.platform!==`win32`||e.protocol!==`file:`)return;const t=fileURLToPath(e);if(path.basename(t)!==`github-exec-launcher.js`)return;const n=getWindowsNativeRedirectStartup();if(!n||!n.appRoot&&!n.stagedRoot)return;const{appRoot:r,stagedRoot:i,execArgv:a}=n;if(!r||!i||!path.isAbsolute(r)||!path.isAbsolute(i))return skipNativeRedirect(`native-roots`);const o=path.resolve(t,`..`,`..`,`..`);if(t!==path.join(o,`dist`,`agents`,`github-exec-launcher.js`))return skipNativeRedirect(`native-layout`);const preloadPath=e=>path.join(e,`..`,`node`,`native-redirect.mjs`);try{const e=realpathSync.native(o);if(path.basename(e).toLowerCase()!==`app`||realpathSync.native(r)!==e)return skipNativeRedirect(`native-roots`);let t=a[0]===`--import`&&a[1]===`data:text/javascript,%0A%20%20globalThis%5BSymbol.for(%22openclaw.cliRespawnParent%22)%5D%20%3D%20%7B%20pid%3A%20process.ppid%20%7D%3B%0A%20%20process.execArgv%20%3D%20process.execArgv.filter((arg%2C%20index%2C%20args)%20%3D%3E%0A%20%20%20%20arg%20!%3D%3D%20import.meta.url%20%26%26%20!(arg%20%3D%3D%3D%20%22--import%22%20%26%26%20args%5Bindex%20%2B%201%5D%20%3D%3D%3D%20import.meta.url))%3B%0A`?2:0;if(/^--stack[-_]size=\d+$/u.test(a[t]??``))t++;if(a[t]===`--import`&&a[t+1]===`data:text/javascript,%0A%20%20globalThis%5BSymbol.for(%22openclaw.cliRespawnParent%22)%5D%20%3D%20%7B%20pid%3A%20process.ppid%20%7D%3B%0A%20%20process.execArgv%20%3D%20process.execArgv.filter((arg%2C%20index%2C%20args)%20%3D%3E%0A%20%20%20%20arg%20!%3D%3D%20import.meta.url%20%26%26%20!(arg%20%3D%3D%3D%20%22--import%22%20%26%26%20args%5Bindex%20%2B%201%5D%20%3D%3D%3D%20import.meta.url))%3B%0A`)t+=2;const n=a[t];const s=n===`--import`?a[t+1]:n?.match(/^--import=(.+)$/u)?.[1];const c=preloadPath(e);if(!s||s.includes(`?`)||s.includes(`#`))return skipNativeRedirect(`native-startup-import`);const l=fileURLToPath(s);if(![preloadPath(r),c].some(e=>path.resolve(e).toLowerCase()===l.toLowerCase()))return skipNativeRedirect(`native-startup-import`);if(realpathSync.native(l)!==c)return skipNativeRedirect(`native-layout`);return{preload:pathToFileURL(c).href,appRoot:r,stagedRoot:i}}catch{return skipNativeRedirect(`native-layout`)}}function buildGitHubExecLaunchArgv(e,t,n){const r=resolveRuntimeProcessEntrypointUrl(`githubExec`);const i=resolveConfiguredGitHubHost({gateway:{github:{host:n?.githubHost}}});const a=resolveWindowsNativeRedirect(r);const o=[process.execPath,...a?[`--import`,a.preload]:[],...resolveRuntimeWorkerArgv(r),t,i];const s=i===`github.com`||i.endsWith(`.ghe.com`);if(process.platform===`win32`){const t=n?.externalCommandShell;const c=t?[t.shell,...t.args,`$ErrorActionPreference = 'Stop'; & ${e.map(quotePowerShellArg).join(` `)}; exit $LASTEXITCODE`]:e;const l=c.at(-1);if(l===void 0)throw new Error(`Managed GitHub execution requires a shell command.`);const u=quotePowerShellArg(fileURLToPath(new URL(`.`,r)));const d=`& ${o.map(quotePowerShellArg).join(` `)}`;const f=a?[`$openclawPriorApp = $env:OPENCLAW_NATIVE_APP_ROOT;`,`$openclawPriorStage = $env:OPENCLAW_NATIVE_STAGED_ROOT;`,`try {`,`$env:OPENCLAW_NATIVE_APP_ROOT = ${quotePowerShellArg(a.appRoot)};`,`$env:OPENCLAW_NATIVE_STAGED_ROOT = ${quotePowerShellArg(a.stagedRoot)};`,`$env:GH_TOKEN = ${d};`,`if (-not $? -or $LASTEXITCODE -ne 0 -or [string]::IsNullOrEmpty($env:GH_TOKEN)) { exit 1 }`,`} finally {`,`$env:OPENCLAW_NATIVE_APP_ROOT = $openclawPriorApp;`,`$env:OPENCLAW_NATIVE_STAGED_ROOT = $openclawPriorStage;`,`Remove-Variable openclawPriorApp, openclawPriorStage`,`}`].join(` `):`$env:GH_TOKEN = ${d}; if (-not $? -or $LASTEXITCODE -ne 0 -or [string]::IsNullOrEmpty($env:GH_TOKEN)) { exit 1 }`;const p=[`Push-Location -LiteralPath ${u} -ErrorAction Stop;`,`try { ${f}`,`} finally { Pop-Location };`,`$env:GH_HOST = ${quotePowerShellArg(i)};`,s?`$env:GH_ENTERPRISE_TOKEN = '';`:`$env:GH_ENTERPRISE_TOKEN = $env:GH_TOKEN; $env:GH_TOKEN = '';`,`$env:GITHUB_TOKEN = ''; $env:GITHUB_ENTERPRISE_TOKEN = ''; $LASTEXITCODE = $null;`,`& ([scriptblock]::Create(${quotePowerShellArg(l)}))`].join(` `);return[...c.slice(0,-1),p]}return[`/bin/sh`,`-c`,`set +x; GH_TOKEN="$(${`cd ${quoteCliArg(fileURLToPath(new URL(`.`,r)))} 2>/dev/null || { printf '%s\\n' 'GitHub Identity launcher is unavailable. Restart OpenClaw, then retry.' >&2; exit 1; }`}; exec ${o.map(quoteCliArg).join(` `)})" || exit $?; GH_HOST=${quoteCliArg(i)}; ${s?`GH_ENTERPRISE_TOKEN=;`:`GH_ENTERPRISE_TOKEN=$GH_TOKEN; GH_TOKEN=;`} GITHUB_TOKEN=; GITHUB_ENTERPRISE_TOKEN=; export GH_HOST GH_TOKEN GH_ENTERPRISE_TOKEN GITHUB_TOKEN GITHUB_ENTERPRISE_TOKEN; exec "$@"`,`openclaw-github-exec`,...e]}export{buildGitHubExecLaunchArgv as t};