mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-27 11:24:43 +00:00
feat(runner): replace server-side bash sandbox with remote runner (#530)
* feat(runner): replace server-side bash sandbox with remote runner * fix(runner): address review findings for output bounds, key rotation, defaults, and generated uploads * chore(docker): remove sandbox privileges and env vars from remaining compose files * feat(cli): add runner start with bundled SRT sandboxing (#535) * refactor(agent): expose runner bash without skill gating * feat(cli): add runner start with optional SRT sandboxing * refactor(cli): remove runner Python dependency * feat(cli): bundle SRT and use platform-native runner shells * refactor(cli): delegate runner processes to Execa * chore(cli): upgrade @anthropic-ai/sandbox-runtime to 0.0.83 * feat(cli): discover Bash for Windows runners Use Pi-style Bash discovery and launch behavior, exercise the packaged CLI shell, and wait for pending ZIP metadata reads before closing cancelled downloads. * fix(runner): enforce ownership and safe reconnects Gate dispatch on reconciliation, retain cancellations across disconnects, and stop replaced clients. Guard the single-server runner topology with a database lease. Restage missing generated inputs, report signal exits, and bound generated-file cleanup. * feat(webui): add Korean translations for agent runners * feat(cli): add runner event logging and --verbose flag (#536) * feat(cli): add runner event logging and --verbose flag * fix(cli): log runner capacity rejections accurately and use monotonic duration
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { accessSync, constants } from 'node:fs'
|
||||
import { win32 } from 'node:path'
|
||||
|
||||
export interface RunnerShellConfig {
|
||||
executable: string
|
||||
commandTransport: 'shell' | 'argv' | 'stdin'
|
||||
}
|
||||
|
||||
// Windows Bash discovery and legacy WSL detection adapted from pi-mono.
|
||||
// See apps/cli/THIRD-PARTY-NOTICES.txt.
|
||||
function isLegacyWslBashPath(executable: string, systemRoot: string | undefined): boolean {
|
||||
const normalized = win32.normalize(executable).toLowerCase()
|
||||
if (systemRoot) {
|
||||
if (!/^[a-z]:[\\/]/i.test(systemRoot)) return false
|
||||
return ['System32', 'Sysnative'].some(
|
||||
(directory) => normalized === win32.join(systemRoot, directory, 'bash.exe').toLowerCase(),
|
||||
)
|
||||
}
|
||||
return /^[a-z]:\\windows\\(?:system32|sysnative)\\bash\.exe$/.test(normalized)
|
||||
}
|
||||
|
||||
function shellPathExists(executable: string): boolean {
|
||||
// access(F_OK) accepts runnable Windows Store aliases that fail an extra stat check.
|
||||
try {
|
||||
accessSync(executable, constants.F_OK)
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function findWindowsBash(system32: string): string | undefined {
|
||||
for (const directory of [process.env.ProgramFiles, process.env['ProgramFiles(x86)']]) {
|
||||
if (!directory || !win32.isAbsolute(directory)) continue
|
||||
const executable = win32.join(directory, 'Git', 'bin', 'bash.exe')
|
||||
if (shellPathExists(executable)) return executable
|
||||
}
|
||||
|
||||
// Use the system tool and limit its search to PATH. The workspace may contain a bash.exe.
|
||||
const found = spawnSync(win32.join(system32, 'where.exe'), ['$PATH:bash.exe'], {
|
||||
encoding: 'utf8',
|
||||
timeout: 5000,
|
||||
windowsHide: true,
|
||||
})
|
||||
if (found.status !== 0 || !found.stdout) return
|
||||
return found.stdout
|
||||
.trim()
|
||||
.split(/\r?\n/)
|
||||
.find((executable) => win32.isAbsolute(executable) && shellPathExists(executable))
|
||||
}
|
||||
|
||||
export function resolveRunnerShell(platform = process.platform): RunnerShellConfig {
|
||||
if (platform !== 'win32') return { executable: '/bin/sh', commandTransport: 'shell' }
|
||||
|
||||
const systemRoot = process.env.SystemRoot
|
||||
const system32 = win32.join(systemRoot ?? 'C:\\Windows', 'System32')
|
||||
const executable = findWindowsBash(system32)
|
||||
if (!executable) return { executable: win32.join(system32, 'cmd.exe'), commandTransport: 'shell' }
|
||||
return {
|
||||
executable,
|
||||
commandTransport: isLegacyWslBashPath(executable, systemRoot) ? 'stdin' : 'argv',
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user