MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / runSetupCommands

Function runSetupCommands

services/cloud-agent-next/src/session-service.ts:702–794  ·  view source on GitHub ↗
(
  session: ExecutionSession,
  context: SessionContext,
  setupCommands: string[],
  failFast: boolean = false,
  options: RunSetupCommandsOptions = {}
)

Source from the content-addressed store, hash-verified

700 * @param setupCommands - Array of setup commands to execute
701 * @param failFast - Whether to stop on first failure (default: false)
702 */
703type RunSetupCommandsOptions = {
704 devcontainer?: DevContainerHandle;
705 dockerEnv?: Record<string, string>;
706 runtimeEnv?: Record<string, string | undefined>;
707};
708
709function buildSetupEnvFileContent(env: Record<string, string | undefined>): string {
710 return `${validShellEnvEntries(env)
711 .map(([key, value]) => `export ${key}=${shellQuote(value)}`)
712 .join('\n')}\n`;
713}
714
715function buildDevContainerSetupCommand(
716 devcontainer: DevContainerHandle,
717 command: string,
718 envFilePath: string | undefined
719): string {
720 const workspaceCommand = `cd ${shellQuote(devcontainer.innerWorkspaceFolder)} && ${command}`;
721 const innerCommand = envFilePath
722 ? `. ${shellQuote(envFilePath)} && ${workspaceCommand}`
723 : workspaceCommand;
724 return [
725 'devcontainer exec',
726 `--workspace-folder ${shellQuote(devcontainer.workspacePath)}`,
727 `--config ${shellQuote(devcontainer.overrideConfigPath)}`,
728 `--id-label ${shellQuote(`${KILO_AGENT_SESSION_LABEL}=${devcontainer.agentSessionId}`)}`,
729 '--',
730 'sh -c',
731 shellQuote(innerCommand),
732 ].join(' ');
733}
734
735export async function runSetupCommands(
736 session: ExecutionSession,
737 context: SessionContext,
738 setupCommands: string[],
739 failFast: boolean = false,
740 options: RunSetupCommandsOptions = {}
741): Promise<void> {
742 if (!setupCommands || setupCommands.length === 0) {
743 return;
744 }
745
746 const dockerEnv = options.devcontainer
747 ? (options.dockerEnv ?? dockerSocketEnv(await resolveDockerSocketPath(session)))
748 : undefined;
749 const setupEnvFilePath =
750 options.devcontainer && options.runtimeEnv
751 ? `${context.sessionHome}/tmp/kilo-setup-env-${options.devcontainer.agentSessionId}-${Date.now()}.sh`
752 : undefined;
753
754 if (setupEnvFilePath && options.runtimeEnv) {
755 await session.writeFile(setupEnvFilePath, buildSetupEnvFileContent(options.runtimeEnv));
756 }
757
758 logger.setTags({ setupCommandsCount: setupCommands.length });
759 logger.info('Running setup commands');

Callers 1

prepareWorkspaceMethod · 0.70

Calls 10

shellQuoteFunction · 0.90
dockerSocketEnvFunction · 0.85
resolveDockerSocketPathFunction · 0.85
buildSetupEnvFileContentFunction · 0.85
timedExecFunction · 0.85
infoMethod · 0.65
warnMethod · 0.65
errorMethod · 0.65
writeFileMethod · 0.45

Tested by

no test coverage detected